How to use gdk_device_get_position()?

后端 未结 2 599
被撕碎了的回忆
被撕碎了的回忆 2021-01-12 22:36

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

2条回答
  •  鱼传尺愫
    2021-01-12 23:29

    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);
    

提交回复
热议问题