简体   繁体   English

GTK4 - 如何获取移动 window 的坐标

[英]GTK4 - how to get coordinates of a moving window

In previous versions of GTK, we added a necessary event mask, attached to a configure-event .在以前的 GTK 版本中,我们添加了一个必要的事件掩码,附加到一个configure-event

gtk_widget_add_events(GTK_WIDGET(window), GDK_CONFIGURE);

g_signal_connect(G_OBJECT(window), "configure-event",
      G_CALLBACK(configure_callback), NULL);

We got the corresponding x,y coordinates from the handler.我们从处理程序中获得了相应的 x,y 坐标。

void configure_callback(GtkWindow *window, 
      GdkEvent *event, gpointer data) {
          
   int x, y;
   x = event->configure.x;
   y = event->configure.y;
   ...
}

The closest thing that resembles this is GtkEventControllerMotion , but it is for mouse pointer, not for window move events.与此最接近的是GtkEventControllerMotion ,但它适用于鼠标指针,而不适用于 window 移动事件。

How to do it in GTK4?如何在 GTK4 中做到这一点?

You can't.你不能。 This is because not all window managers/compositors provide this information, for privacy and/or technical reasons.这是因为出于隐私和/或技术原因,并非所有 window 管理器/合成器都提供此信息。

Wayland, for example, does not provide window coordinates, because not every Wayland compositor is even a 2D rectangle - for example, kiosk compositors like cage or gamescope , or VR compositors like wxrd .例如,Wayland 不提供 window 坐标,因为并非每个 Wayland 合成器都是 2D 矩形 - 例如,像笼子gamescope这样的信息亭合成器,或者像wxrd这样的 VR 合成器。

Because of this, the functionality was removed from GTK4.因此,该功能已从 GTK4 中删除。 You will need to use an X11-specific API to get this information, but note that you would need to force your application to use X11 (over XWayland on Wayland compositors)您将需要使用特定于 X11 的 API 来获取此信息,但请注意,您需要强制您的应用程序使用 X11(通过 Wayland 合成器上的 XWayland)

https://docs.gtk.org/gtk4/migrating-3to4.html#adapt-to-gtkwindow-api-changes https://docs.gtk.org/gtk4/migrating-3to4.html#adapt-to-gtkwindow-api-changes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM