liberty-xdg: don't crash on missing X11 atoms
All checks were successful
Alpine 3.21 Success
OpenBSD 7.6 Success

They can be missing in bare configurations, such as Sway + XWayland.
This commit is contained in:
Přemysl Eric Janouch 2025-06-04 21:53:11 +02:00
parent 31ae400852
commit d8f785eae5
Signed by: p
GPG Key ID: A0420B94F92B9493

View File

@ -86,24 +86,30 @@ xdg_xsettings_update (struct xdg_xsettings *self, Display *dpy)
// TODO: We're supposed to lock the server. // TODO: We're supposed to lock the server.
// TODO: We're supposed to trap X errors. // TODO: We're supposed to trap X errors.
char *selection = xstrdup_printf ("_XSETTINGS_S%d", DefaultScreen (dpy)); char *selection = xstrdup_printf ("_XSETTINGS_S%d", DefaultScreen (dpy));
Window owner Atom selection_atom = XInternAtom (dpy, selection, True);
= XGetSelectionOwner (dpy, XInternAtom (dpy, selection, True));
free (selection); free (selection);
if (!selection_atom)
return;
Window owner = XGetSelectionOwner (dpy, selection_atom);
if (!owner) if (!owner)
return; return;
Atom xsettings_atom = XInternAtom (dpy, "_XSETTINGS_SETTINGS", True);
if (!xsettings_atom)
return;
Atom actual_type = None; Atom actual_type = None;
int actual_format = 0; int actual_format = 0;
unsigned long nitems = 0, bytes_after = 0; unsigned long nitems = 0, bytes_after = 0;
unsigned char *buffer = NULL; unsigned char *buffer = NULL;
Atom xsettings = XInternAtom (dpy, "_XSETTINGS_SETTINGS", True);
int status = XGetWindowProperty (dpy, int status = XGetWindowProperty (dpy,
owner, owner,
xsettings, xsettings_atom,
0L, 0L,
LONG_MAX, LONG_MAX,
False, False,
xsettings, xsettings_atom,
&actual_type, &actual_type,
&actual_format, &actual_format,
&nitems, &nitems,
@ -112,7 +118,7 @@ xdg_xsettings_update (struct xdg_xsettings *self, Display *dpy)
if (status != Success || !buffer) if (status != Success || !buffer)
return; return;
if (actual_type != xsettings if (actual_type != xsettings_atom
|| actual_format != 8 || actual_format != 8
|| nitems < 12) || nitems < 12)
goto fail; goto fail;