menus: Fix menus on non-default displays

Currently, we sometimes emit display-changed
when the display changed, and sometimes we don't
since the display is changed via gtk_widget_root.

Listen for notify::root as well and update our
display. This is a temporary fix - all display
changes should go through gtk_widget_root,
eventually.
This commit is contained in:
Matthias Clasen 2019-05-01 20:41:59 +00:00
parent 737400ddbc
commit 377ec33069

View File

@ -1054,6 +1054,15 @@ attach_widget_display_changed (GtkWidget *attach_widget,
menu_change_display (menu, gtk_widget_get_display (attach_widget)); menu_change_display (menu, gtk_widget_get_display (attach_widget));
} }
static void
attach_widget_root_changed (GObject *attach_widget,
GParamSpec *pspec,
gpointer menu)
{
if (!g_object_get_data (G_OBJECT (menu), "gtk-menu-explicit-display"))
menu_change_display (menu, gtk_widget_get_display (GTK_WIDGET (attach_widget)));
}
static void static void
menu_toplevel_attached_to (GtkWindow *toplevel, GParamSpec *pspec, GtkMenu *menu) menu_toplevel_attached_to (GtkWindow *toplevel, GParamSpec *pspec, GtkMenu *menu)
{ {
@ -1109,6 +1118,8 @@ gtk_menu_attach_to_widget (GtkMenu *menu,
g_signal_connect (attach_widget, "display-changed", g_signal_connect (attach_widget, "display-changed",
G_CALLBACK (attach_widget_display_changed), menu); G_CALLBACK (attach_widget_display_changed), menu);
g_signal_connect (attach_widget, "notify::root",
G_CALLBACK (attach_widget_root_changed), menu);
attach_widget_display_changed (attach_widget, NULL, menu); attach_widget_display_changed (attach_widget, NULL, menu);
data->detacher = detacher; data->detacher = detacher;
@ -1191,6 +1202,9 @@ gtk_menu_detach (GtkMenu *menu)
g_signal_handlers_disconnect_by_func (data->attach_widget, g_signal_handlers_disconnect_by_func (data->attach_widget,
(gpointer) attach_widget_display_changed, (gpointer) attach_widget_display_changed,
menu); menu);
g_signal_handlers_disconnect_by_func (data->attach_widget,
(gpointer) attach_widget_root_changed,
menu);
if (data->detacher) if (data->detacher)
data->detacher (data->attach_widget, menu); data->detacher (data->attach_widget, menu);
@ -1266,6 +1280,8 @@ popup_grab_on_surface (GdkSurface *surface,
GdkGrabStatus status; GdkGrabStatus status;
GdkSeat *seat; GdkSeat *seat;
g_return_val_if_fail (gdk_surface_get_display (surface) == gdk_device_get_display (pointer), FALSE);
seat = gdk_device_get_seat (pointer); seat = gdk_device_get_seat (pointer);
status = gdk_seat_grab (seat, surface, status = gdk_seat_grab (seat, surface,
GDK_SEAT_CAPABILITY_ALL, TRUE, GDK_SEAT_CAPABILITY_ALL, TRUE,
@ -1321,7 +1337,11 @@ gtk_menu_popup_internal (GtkMenu *menu,
device = NULL; device = NULL;
if (device == NULL) if (device == NULL)
device = gdk_seat_get_pointer (gdk_display_get_default_seat (display)); {
device = gdk_seat_get_pointer (gdk_display_get_default_seat (display));
g_return_if_fail (gdk_device_get_display (device) == display);
}
widget = GTK_WIDGET (menu); widget = GTK_WIDGET (menu);
menu_shell = GTK_MENU_SHELL (menu); menu_shell = GTK_MENU_SHELL (menu);
@ -1331,6 +1351,8 @@ gtk_menu_popup_internal (GtkMenu *menu,
else else
pointer = device; pointer = device;
g_return_if_fail (gdk_device_get_display (pointer) == display);
menu_shell->priv->parent_menu_shell = parent_menu_shell; menu_shell->priv->parent_menu_shell = parent_menu_shell;
/* Find the last viewable ancestor, and make an X grab on it /* Find the last viewable ancestor, and make an X grab on it