1
0
Fork 0

wayland/surface-role: Keep track of the surface main monitor

Toplevels get the main monitor from their MetaWindow and have no main
monitor when the toplevel is not mapped.

Subsurfaces get the main monitor from their parent surface.

DnD and cursors get the main monitor from the current cursor position no
matter if the cursor is actually being shown or not.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3941>
This commit is contained in:
Sebastian Wick 2024-08-12 21:32:02 +02:00
parent fe17e717c3
commit 757f8b6d69
5 changed files with 50 additions and 9 deletions

View file

@ -223,6 +223,7 @@ enum
PROP_EFFECT, PROP_EFFECT,
PROP_SUSPEND_STATE, PROP_SUSPEND_STATE,
PROP_MAPPED, PROP_MAPPED,
PROP_MAIN_MONITOR,
PROP_LAST, PROP_LAST,
}; };
@ -444,6 +445,9 @@ meta_window_get_property(GObject *object,
case PROP_MAPPED: case PROP_MAPPED:
g_value_set_boolean (value, win->mapped); g_value_set_boolean (value, win->mapped);
break; break;
case PROP_MAIN_MONITOR:
g_value_set_object (value, win->monitor);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -614,6 +618,11 @@ meta_window_class_init (MetaWindowClass *klass)
FALSE, FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_MAIN_MONITOR] =
g_param_spec_object ("main-monitor", NULL, NULL,
META_TYPE_LOGICAL_MONITOR,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, PROP_LAST, obj_props); g_object_class_install_properties (object_class, PROP_LAST, obj_props);
window_signals[WORKSPACE_CHANGED] = window_signals[WORKSPACE_CHANGED] =
@ -965,6 +974,8 @@ meta_window_main_monitor_changed (MetaWindow *window,
if (window->monitor) if (window->monitor)
g_signal_emit_by_name (window->display, "window-entered-monitor", g_signal_emit_by_name (window->display, "window-entered-monitor",
window->monitor->number, window); window->monitor->number, window);
g_object_notify_by_pspec (G_OBJECT (window), obj_props[PROP_MAIN_MONITOR]);
} }
MetaLogicalMonitor * MetaLogicalMonitor *

View file

@ -92,9 +92,6 @@ cursor_sprite_prepare_at (MetaCursorSprite *cursor_sprite,
{ {
MetaWaylandSurfaceRole *role = META_WAYLAND_SURFACE_ROLE (cursor_surface); MetaWaylandSurfaceRole *role = META_WAYLAND_SURFACE_ROLE (cursor_surface);
MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (role); MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (role);
if (!meta_wayland_surface_is_xwayland (surface))
{
MetaContext *context = MetaContext *context =
meta_wayland_compositor_get_context (surface->compositor); meta_wayland_compositor_get_context (surface->compositor);
MetaBackend *backend = meta_context_get_backend (context); MetaBackend *backend = meta_context_get_backend (context);
@ -104,6 +101,9 @@ cursor_sprite_prepare_at (MetaCursorSprite *cursor_sprite,
logical_monitor = logical_monitor =
meta_monitor_manager_get_logical_monitor_at (monitor_manager, x, y); meta_monitor_manager_get_logical_monitor_at (monitor_manager, x, y);
if (!meta_wayland_surface_is_xwayland (surface))
{
if (logical_monitor) if (logical_monitor)
{ {
int surface_scale = surface->applied_state.scale; int surface_scale = surface->applied_state.scale;
@ -121,6 +121,7 @@ cursor_sprite_prepare_at (MetaCursorSprite *cursor_sprite,
} }
} }
meta_wayland_surface_set_main_monitor (surface, logical_monitor);
meta_wayland_surface_update_outputs (surface); meta_wayland_surface_update_outputs (surface);
} }

View file

@ -483,13 +483,24 @@ static void
data_device_update_position (MetaWaylandDragGrab *drag_grab, data_device_update_position (MetaWaylandDragGrab *drag_grab,
graphene_point_t *point) graphene_point_t *point)
{ {
MetaWaylandCompositor *compositor =
meta_wayland_seat_get_compositor (drag_grab->seat);
MetaContext *context = meta_wayland_compositor_get_context (compositor);
MetaBackend *backend = meta_context_get_backend (context);
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
MetaFeedbackActor *feedback_actor = MetaFeedbackActor *feedback_actor =
META_FEEDBACK_ACTOR (drag_grab->feedback_actor); META_FEEDBACK_ACTOR (drag_grab->feedback_actor);
MetaLogicalMonitor *monitor;
if (!drag_grab->drag_surface) if (!drag_grab->drag_surface)
return; return;
meta_feedback_actor_set_position (feedback_actor, point->x, point->y); meta_feedback_actor_set_position (feedback_actor, point->x, point->y);
monitor = meta_monitor_manager_get_logical_monitor_at (monitor_manager,
point->x, point->y);
meta_wayland_surface_set_main_monitor (drag_grab->drag_surface, monitor);
} }
static gboolean static gboolean

View file

@ -36,6 +36,7 @@ typedef struct _MetaWaylandShellSurfacePrivate
gulong unmanaging_handler_id; gulong unmanaging_handler_id;
gulong highest_scale_monitor_handler_id; gulong highest_scale_monitor_handler_id;
GBinding *main_monitor_binding;
} MetaWaylandShellSurfacePrivate; } MetaWaylandShellSurfacePrivate;
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaWaylandShellSurface, G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaWaylandShellSurface,
@ -114,6 +115,9 @@ clear_window (MetaWaylandShellSurface *shell_surface)
clutter_actor_set_reactive (CLUTTER_ACTOR (surface_actor), FALSE); clutter_actor_set_reactive (CLUTTER_ACTOR (surface_actor), FALSE);
meta_wayland_surface_notify_unmapped (surface); meta_wayland_surface_notify_unmapped (surface);
meta_wayland_surface_set_main_monitor (surface, NULL);
g_clear_object (&priv->main_monitor_binding);
} }
static void static void
@ -151,6 +155,11 @@ meta_wayland_shell_surface_set_window (MetaWaylandShellSurface *shell_surface,
meta_window_update_monitor (window, META_WINDOW_UPDATE_MONITOR_FLAGS_NONE); meta_window_update_monitor (window, META_WINDOW_UPDATE_MONITOR_FLAGS_NONE);
priv->main_monitor_binding =
g_object_bind_property (G_OBJECT (window), "main-monitor",
G_OBJECT (surface), "main-monitor",
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
priv->highest_scale_monitor_handler_id = priv->highest_scale_monitor_handler_id =
g_signal_connect_swapped (window, "highest-scale-monitor-changed", g_signal_connect_swapped (window, "highest-scale-monitor-changed",
G_CALLBACK (meta_wayland_surface_notify_highest_scale_monitor), G_CALLBACK (meta_wayland_surface_notify_highest_scale_monitor),

View file

@ -707,6 +707,7 @@ meta_wayland_surface_apply_placement_ops (MetaWaylandSurface *parent,
if (!op->sibling) if (!op->sibling)
{ {
surface->applied_state.parent = NULL; surface->applied_state.parent = NULL;
meta_wayland_surface_set_main_monitor (surface, NULL);
continue; continue;
} }
@ -732,6 +733,8 @@ meta_wayland_surface_apply_placement_ops (MetaWaylandSurface *parent,
surface->applied_state.subsurface_branch_node); surface->applied_state.subsurface_branch_node);
break; break;
} }
meta_wayland_surface_set_main_monitor (surface, parent->main_monitor);
} }
} }
@ -2559,6 +2562,8 @@ meta_wayland_surface_set_main_monitor_internal (MetaWaylandSurface *surface,
MetaLogicalMonitor *logical_monitor, MetaLogicalMonitor *logical_monitor,
gconstpointer not_this_monitor) gconstpointer not_this_monitor)
{ {
MetaWaylandSurface *subsurface_surface;
if (surface->main_monitor == logical_monitor) if (surface->main_monitor == logical_monitor)
return; return;
@ -2579,6 +2584,10 @@ meta_wayland_surface_set_main_monitor_internal (MetaWaylandSurface *surface,
surface->main_monitor = logical_monitor; surface->main_monitor = logical_monitor;
g_object_notify_by_pspec (G_OBJECT (surface), obj_props[PROP_MAIN_MONITOR]); g_object_notify_by_pspec (G_OBJECT (surface), obj_props[PROP_MAIN_MONITOR]);
META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (&surface->committed_state,
subsurface_surface)
meta_wayland_surface_set_main_monitor (subsurface_surface, logical_monitor);
} }
static void static void