startup-notification/x11: Let the libsn user handle API annoyances

The API has no concept of user data, and requires the user to some how
get an instance without context, i.e. via static globals. Limit this to
the file where this is needed.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
This commit is contained in:
Jonas Ådahl 2022-05-31 12:50:48 +02:00 committed by Robert Mader
parent 5e67e35ec5
commit e5908f5752
3 changed files with 44 additions and 30 deletions

View File

@ -298,8 +298,6 @@ META_EXPORT_TEST
GSList* meta_display_list_windows (MetaDisplay *display, GSList* meta_display_list_windows (MetaDisplay *display,
MetaListWindowsFlags flags); MetaListWindowsFlags flags);
MetaDisplay* meta_display_for_x_display (Display *xdisplay);
META_EXPORT_TEST META_EXPORT_TEST
MetaDisplay* meta_get_display (void); MetaDisplay* meta_get_display (void);

View File

@ -1205,31 +1205,6 @@ meta_display_close (MetaDisplay *display,
the_display = NULL; the_display = NULL;
} }
/**
* meta_display_for_x_display:
* @xdisplay: An X display
*
* Returns the singleton MetaDisplay if @xdisplay matches the X display it's
* managing; otherwise gives a warning and returns %NULL. When we were claiming
* to be able to manage multiple displays, this was supposed to find the
* display out of the list which matched that display. Now it's merely an
* extra sanity check.
*
* Returns: The singleton X display, or %NULL if @xdisplay isn't the one
* we're managing.
*/
MetaDisplay*
meta_display_for_x_display (Display *xdisplay)
{
if (the_display->x11_display->xdisplay == xdisplay)
return the_display;
meta_warning ("Could not find display for X display %p, probably going to crash",
xdisplay);
return NULL;
}
/** /**
* meta_get_display: * meta_get_display:
* *

View File

@ -51,6 +51,8 @@ struct _MetaX11StartupNotification
static GParamSpec *seq_x11_props[N_SEQ_X11_PROPS]; static GParamSpec *seq_x11_props[N_SEQ_X11_PROPS];
static GList *displays;
G_DEFINE_TYPE (MetaStartupSequenceX11, G_DEFINE_TYPE (MetaStartupSequenceX11,
meta_startup_sequence_x11, meta_startup_sequence_x11,
META_TYPE_STARTUP_SEQUENCE) META_TYPE_STARTUP_SEQUENCE)
@ -168,13 +170,36 @@ meta_startup_sequence_x11_new (MetaDisplay *display,
NULL); NULL);
} }
static MetaDisplay *
find_display (Display *xdisplay)
{
GList *l;
for (l = displays; l; l = l->next)
{
MetaDisplay *display = l->data;
MetaX11Display *x11_display;
x11_display = display->x11_display;
if (!x11_display)
continue;
if (x11_display->xdisplay != xdisplay)
continue;
return display;
}
return NULL;
}
static void static void
sn_error_trap_push (SnDisplay *sn_display, sn_error_trap_push (SnDisplay *sn_display,
Display *xdisplay) Display *xdisplay)
{ {
MetaDisplay *display; MetaDisplay *display;
display = meta_display_for_x_display (xdisplay); display = find_display (xdisplay);
if (display != NULL) if (display != NULL)
meta_x11_error_trap_push (display->x11_display); meta_x11_error_trap_push (display->x11_display);
} }
@ -185,7 +210,7 @@ sn_error_trap_pop (SnDisplay *sn_display,
{ {
MetaDisplay *display; MetaDisplay *display;
display = meta_display_for_x_display (xdisplay); display = find_display (xdisplay);
if (display != NULL) if (display != NULL)
meta_x11_error_trap_pop (display->x11_display); meta_x11_error_trap_pop (display->x11_display);
} }
@ -253,13 +278,21 @@ meta_startup_notification_sn_event (SnMonitorEvent *event,
sn_startup_sequence_unref (sequence); sn_startup_sequence_unref (sequence);
} }
#endif
static void
on_x11_display_closing (MetaDisplay *display)
{
g_signal_handlers_disconnect_by_func (display, on_x11_display_closing, NULL);
displays = g_list_remove (displays, display);
}
#endif /* HAVE_STARTUP_NOTIFICATION */
void void
meta_x11_startup_notification_init (MetaX11Display *x11_display) meta_x11_startup_notification_init (MetaX11Display *x11_display)
{ {
#ifdef HAVE_STARTUP_NOTIFICATION #ifdef HAVE_STARTUP_NOTIFICATION
MetaX11StartupNotification *x11_sn; MetaX11StartupNotification *x11_sn;
MetaDisplay *display;
x11_sn = g_new0 (MetaX11StartupNotification, 1); x11_sn = g_new0 (MetaX11StartupNotification, 1);
x11_sn->sn_display = sn_display_new (x11_display->xdisplay, x11_sn->sn_display = sn_display_new (x11_display->xdisplay,
@ -273,6 +306,14 @@ meta_x11_startup_notification_init (MetaX11Display *x11_display)
NULL); NULL);
x11_display->startup_notification = x11_sn; x11_display->startup_notification = x11_sn;
display = meta_x11_display_get_display (x11_display);
if (!g_list_find (displays, display))
{
displays = g_list_prepend (displays, display);
g_signal_connect (display, "x11-display-closing",
G_CALLBACK (on_x11_display_closing), NULL);
}
#endif #endif
} }