How to use gdk_device_get_position()?

允我心安 提交于 2020-08-04 05:40:05

问题


I am trying to get the pointer position on screen in Gdk and found gdk_display_get_pointer(), which works fine, but it's marked as deprecated and refers to gdk_device_get_position() now.

But how do I use this function? I cannot get a GdkDevice, since there is no factory, nor is there a constructor.


回答1:


use Gdk.DeviceManager.

.....
.....
GdkDisplay *display = gdk_display_get_default ();
GdkDeviceManager *device_manager = gdk_display_get_device_manager (display);
GdkDevice *device = gdk_device_manager_get_client_pointer (device_manager);

// do whatever with Gdk.Device, i.e:
int x, y;
gdk_device_get_position (device, NULL, &x, &y);
printf ("x= %d, y=%d", x,y);



回答2:


Since GTK+ 3.20+, luciomrx's answer becomes:

GdkDisplay* display = gdk_display_get_default();
GdkSeat* seat = gdk_display_get_default_seat(display);
GdkDevice* pointer = gdk_seat_get_pointer(seat);


来源:https://stackoverflow.com/questions/24844489/how-to-use-gdk-device-get-position

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