Merge branch 'wip/matthiasc/monitor-signals' into 'master'

Add enter/leave signals for monitors

See merge request GNOME/gtk!1680
This commit is contained in:
Matthias Clasen 2020-04-13 23:25:55 +00:00
commit d802b35578
7 changed files with 94 additions and 7 deletions

View File

@ -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

View File

@ -76,6 +76,8 @@ enum {
SIZE_CHANGED,
RENDER,
EVENT,
ENTER_MONITOR,
LEAVE_MONITOR,
LAST_SIGNAL
};
@ -471,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"),
@ -532,6 +537,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
@ -1941,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
*/
@ -1961,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
*/
@ -3035,3 +3076,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);
}

View File

@ -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 *

View File

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

View File

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

View File

@ -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 = {

View File

@ -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),