How to hide mouse pointer in GTK C

假装没事ソ 提交于 2019-12-11 02:29:27

问题


I have an application which I have made using gtk and c. It runs on full screen mode and displays data on a label. I need to hide the mouse pointer as soon as the application starts and then unhide it when the application stops.

How to do it.

This is my main window:

GtkWidget *window = NULL;

window = gtk_window_new (GTK_WINDOW_TOPLEVEL);  
gtk_widget_set_size_request((window),640,480);  
gtk_widget_realize (window);
gtk_window_fullscreen((GtkWindow*)window);      

回答1:


Phew, that was a rabbit hole of deprecation!

It seems, from a quick skim of the docs, that the current best bet is the gdk_seat_grab() function. It has a bunch of arguments, one of them is a GdkCursor *. The cursor is set while the grab is active.

You should be able to use gdk_cursor_new_for_display() with GDK_BLANK_CURSOR to get a blank cursor to use.

You can get the default display using the gdk_display_get_default() function. This is usually enough unless you need to think about multi-display support; anyway this should get you started with the APIs.




回答2:


You actually don't need gdk_seat_grab(); what you really want is gdk_window_set_cursor(). And for using an invisible cursor, you can use gdk_cursor_new_from_name() to load the "none" cursor, which is typically handled explicitly by GDK backend implementations to return a blank cursor. The Cursors example in gtk3-demo gives you an example of how to use it.

Noote that this means if GTK+ ever unrealizes your window for any reason, you'll ahve to reset your cursor. So you may want to connect to the two realization signals to do the assignment.




回答3:


This is how I have done it:

GdkCursor* Cursor = gdk_cursor_new(GDK_BLANK_CURSOR);
GdkWindow* win = gtk_widget_get_window((window));
gdk_window_set_cursor((win),Cursor);


来源:https://stackoverflow.com/questions/44453139/how-to-hide-mouse-pointer-in-gtk-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!