From 3ee18b88b947198a3f86e363be445e5dbb68fbca Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 28 Nov 2017 22:36:17 -0500 Subject: [PATCH 1/4] gdk: Add ::enter/leave-monitor signals These are useful to keep track of what monitors a window is on. --- gdk/gdkinternals.h | 6 ++++++ gdk/gdksurface.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/gdk/gdkinternals.h b/gdk/gdkinternals.h index 30715af56e..096b89aec5 100644 --- a/gdk/gdkinternals.h +++ b/gdk/gdkinternals.h @@ -185,6 +185,11 @@ gboolean gdk_surface_handle_event (GdkEvent *event); GdkSeat * gdk_surface_get_seat_from_event (GdkSurface *surface, GdkEvent *event); +void gdk_surface_enter_monitor (GdkSurface *surface, + GdkMonitor *monitor); +void gdk_surface_leave_monitor (GdkSurface *surface, + GdkMonitor *monitor); + /***************************************** * Interfaces provided by windowing code * *****************************************/ @@ -296,6 +301,7 @@ void gdk_surface_get_geometry (GdkSurface *surface, GdkGLContext *gdk_surface_get_shared_data_gl_context (GdkSurface *surface); + /* * GdkSeatGrabPrepareFunc: * @seat: the #GdkSeat being grabbed diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c index 9dae9a93b5..c02c66b66b 100644 --- a/gdk/gdksurface.c +++ b/gdk/gdksurface.c @@ -76,6 +76,8 @@ enum { SIZE_CHANGED, RENDER, EVENT, + ENTER_MONITOR, + LEAVE_MONITOR, LAST_SIGNAL }; @@ -532,6 +534,44 @@ gdk_surface_class_init (GdkSurfaceClass *klass) g_signal_set_va_marshaller (signals[EVENT], G_OBJECT_CLASS_TYPE (object_class), _gdk_marshal_BOOLEAN__BOXEDv); + + /** + * GdkSurface::enter-montor: + * @surface: the #GdkSurface + * @monitor: the monitor + * + * Emitted when @surface starts being present on the monitor. + */ + signals[ENTER_MONITOR] = + g_signal_new (g_intern_static_string ("enter-monitor"), + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + 0, + NULL, + NULL, + NULL, + G_TYPE_NONE, + 1, + GDK_TYPE_MONITOR); + + /** + * GdkSurface::leave-montor: + * @surface: the #GdkSurface + * @monitor: the monitor + * + * Emitted when @surface stops being present on the monitor. + */ + signals[LEAVE_MONITOR] = + g_signal_new (g_intern_static_string ("leave-monitor"), + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + 0, + NULL, + NULL, + NULL, + G_TYPE_NONE, + 1, + GDK_TYPE_MONITOR); } static void @@ -3035,3 +3075,17 @@ gdk_surface_get_seat_from_event (GdkSurface *surface, } return gdk_display_get_default_seat (surface->display); } + +void +gdk_surface_enter_monitor (GdkSurface *surface, + GdkMonitor *monitor) +{ + g_signal_emit (surface, signals[ENTER_MONITOR], 0, monitor); +} + +void +gdk_surface_leave_monitor (GdkSurface *surface, + GdkMonitor *monitor) +{ + g_signal_emit (surface, signals[LEAVE_MONITOR], 0, monitor); +} From 209398d736cc3a9af79b2f236453079fcc24dff4 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 28 Nov 2017 22:37:42 -0500 Subject: [PATCH 2/4] wayland: emit ::enter/leave-monitor These signals directly mirror the surface_enter/leave events of the Wayland protocol, so this is very staightforward. --- gdk/wayland/gdkdisplay-wayland.c | 7 +++++++ gdk/wayland/gdkprivate-wayland.h | 2 ++ gdk/wayland/gdksurface-wayland.c | 10 ++++++++++ 3 files changed, 19 insertions(+) diff --git a/gdk/wayland/gdkdisplay-wayland.c b/gdk/wayland/gdkdisplay-wayland.c index dc8c52f305..e30acdad1b 100644 --- a/gdk/wayland/gdkdisplay-wayland.c +++ b/gdk/wayland/gdkdisplay-wayland.c @@ -2539,6 +2539,13 @@ get_monitor_for_output (GdkWaylandDisplay *display_wayland, return NULL; } +GdkMonitor * +gdk_wayland_display_get_monitor_for_output (GdkDisplay *display, + struct wl_output *output) +{ + return (GdkMonitor *)get_monitor_for_output (GDK_WAYLAND_DISPLAY (display), output); +} + static void gdk_wayland_display_remove_output (GdkWaylandDisplay *display_wayland, guint32 id) diff --git a/gdk/wayland/gdkprivate-wayland.h b/gdk/wayland/gdkprivate-wayland.h index 13dbd221e0..99fa9b5d4b 100644 --- a/gdk/wayland/gdkprivate-wayland.h +++ b/gdk/wayland/gdkprivate-wayland.h @@ -163,6 +163,8 @@ guint32 gdk_wayland_display_get_output_scale (GdkWaylandDisplay *display_wayland struct wl_output *output); struct wl_output *gdk_wayland_display_get_wl_output (GdkDisplay *display, int monitor_num); +GdkMonitor *gdk_wayland_display_get_monitor_for_output (GdkDisplay *display, + struct wl_output *output); void _gdk_wayland_surface_set_grab_seat (GdkSurface *surface, GdkSeat *seat); diff --git a/gdk/wayland/gdksurface-wayland.c b/gdk/wayland/gdksurface-wayland.c index 06de4fa500..82fae79e8e 100644 --- a/gdk/wayland/gdksurface-wayland.c +++ b/gdk/wayland/gdksurface-wayland.c @@ -1201,6 +1201,8 @@ surface_enter (void *data, { GdkSurface *surface = GDK_SURFACE (data); GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (surface); + GdkDisplay *display = gdk_surface_get_display (surface); + GdkMonitor *monitor; GDK_DISPLAY_NOTE (gdk_surface_get_display (surface), EVENTS, g_message ("surface enter, surface %p output %p", surface, output)); @@ -1208,6 +1210,9 @@ surface_enter (void *data, impl->display_server.outputs = g_slist_prepend (impl->display_server.outputs, output); gdk_wayland_surface_update_scale (surface); + + monitor = gdk_wayland_display_get_monitor_for_output (display, output); + gdk_surface_enter_monitor (surface, monitor); } static void @@ -1217,6 +1222,8 @@ surface_leave (void *data, { GdkSurface *surface = GDK_SURFACE (data); GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (surface); + GdkDisplay *display = gdk_surface_get_display (surface); + GdkMonitor *monitor; GDK_DISPLAY_NOTE (gdk_surface_get_display (surface), EVENTS, g_message ("surface leave, surface %p output %p", surface, output)); @@ -1225,6 +1232,9 @@ surface_leave (void *data, if (impl->display_server.outputs) gdk_wayland_surface_update_scale (surface); + + monitor = gdk_wayland_display_get_monitor_for_output (display, output); + gdk_surface_leave_monitor (surface, monitor); } static const struct wl_surface_listener surface_listener = { From f97180beeee1c78267343f88a83db60aae70f027 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 13 Apr 2020 09:17:46 -0400 Subject: [PATCH 3/4] inspector: Show scales other than 2 We were hardcoding that monitor scales can only be 1 or 2. Not true. --- gtk/inspector/general.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gtk/inspector/general.c b/gtk/inspector/general.c index 2d3e0ef001..1f50020bfc 100644 --- a/gtk/inspector/general.c +++ b/gtk/inspector/general.c @@ -549,6 +549,7 @@ populate_display (GdkDisplay *display, GtkInspectorGeneral *gen) gchar *value; GdkRectangle rect; gint scale; + char *scale_str = NULL; const char *manufacturer; const char *model; GdkMonitor *monitor; @@ -568,13 +569,16 @@ populate_display (GdkDisplay *display, GtkInspectorGeneral *gen) gdk_monitor_get_geometry (monitor, &rect); scale = gdk_monitor_get_scale_factor (monitor); + if (scale != 1) + scale_str = g_strdup_printf (" @ %d", scale); value = g_strdup_printf ("%d × %d%s at %d, %d", rect.width, rect.height, - scale == 2 ? " @ 2" : "", + scale_str ? scale_str : "", rect.x, rect.y); add_label_row (gen, list, "Geometry", value, 10); g_free (value); + g_free (scale_str); value = g_strdup_printf ("%d × %d mm²", gdk_monitor_get_width_mm (monitor), From d27adb10a0a10e2eecee4c1a60df8309cbd7e2ab Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 13 Apr 2020 09:29:11 -0400 Subject: [PATCH 4/4] surface: Document coordinate systems a bit Mention that sizes are in application pixels. Also, remove some X11-specific docs. --- gdk/gdksurface.c | 13 +++++++------ gdk/gdktoplevellayout.c | 3 +++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c index c02c66b66b..f01a77978c 100644 --- a/gdk/gdksurface.c +++ b/gdk/gdksurface.c @@ -473,6 +473,9 @@ gdk_surface_class_init (GdkSurfaceClass *klass) * @height: the new height * * Emitted when the size of @surface is changed. + * + * Surface size is reported in ”application pixels”, not + * ”device pixels” (see gdk_surface_get_scale_factor()). */ signals[SIZE_CHANGED] = g_signal_new (g_intern_static_string ("size-changed"), @@ -1981,9 +1984,8 @@ gdk_surface_get_geometry (GdkSurface *surface, * * Returns the width of the given @surface. * - * On the X11 platform the returned size is the size reported in the - * most-recently-processed configure event, rather than the current - * size on the X server. + * Surface size is reported in ”application pixels”, not + * ”device pixels” (see gdk_surface_get_scale_factor()). * * Returns: The width of @surface */ @@ -2001,9 +2003,8 @@ gdk_surface_get_width (GdkSurface *surface) * * Returns the height of the given @surface. * - * On the X11 platform the returned size is the size reported in the - * most-recently-processed configure event, rather than the current - * size on the X server. + * Surface size is reported in ”application pixels”, not + * ”device pixels” (see gdk_surface_get_scale_factor()). * * Returns: The height of @surface */ diff --git a/gdk/gdktoplevellayout.c b/gdk/gdktoplevellayout.c index c68d9c2eeb..8f4a6b56aa 100644 --- a/gdk/gdktoplevellayout.c +++ b/gdk/gdktoplevellayout.c @@ -61,6 +61,9 @@ G_DEFINE_BOXED_TYPE (GdkToplevelLayout, gdk_toplevel_layout, * Used together with gdk_toplevel_present() to describe * how a toplevel surface should be placed and behave on-screen. * + * The size is in ”application pixels”, not + * ”device pixels” (see gdk_surface_get_scale_factor()). + * * Returns: (transfer full): newly created instance of #GdkToplevelLayout */ GdkToplevelLayout *