Commit 010f8281 authored by Olivier Fourdan's avatar Olivier Fourdan 🛠
Browse files

display: Add support for XRes X11 extension



The X-Resource extension client library (XRes) allows a client to query
the Xserver for various resources associated with an X11 client,
including its PID.

Add (optional) support for XRes in xfwm4 and use it for getting the
client's PID instead of relying on _NET_WM_PID.

Signed-off-by: Olivier Fourdan's avatarOlivier Fourdan <fourdan@xfce.org>
parent 15afdcd3
......@@ -25,7 +25,7 @@ m4_define([xpresent_minimum_version], [1.0])
m4_define([presentproto_minimum_version], [1.1])
dnl init autoconf
AC_COPYRIGHT([Copyright (c) 2002-2015
AC_COPYRIGHT([Copyright (c) 2002-2020
The Xfce development team. All rights reserved.
Written for Xfce by Olivier Fourdan <fourdan@xfce.org>.])
......@@ -100,6 +100,15 @@ AC_CHECK_LIB([Xi], [XISelectEvents],
fi
], [], [$LIBX11_CFLAGS $LIBX11_LDFLAGS $LIBX11_LIBS])
dnl Check for XRes library
AC_CHECK_LIB([XRes], [XResQueryClients],
[
if ! echo $LIBX11_LIBS | grep -q -- '-lXRes'; then
LIBX11_LIBS="$LIBX11_LIBS -lXRes"
AC_DEFINE([HAVE_XRES], [1], [Define to enable XRes])
fi
], [], [$LIBX11_CFLAGS $LIBX11_LDFLAGS $LIBX11_LIBS])
XDT_CHECK_PACKAGE([GTK], [gtk+-3.0], [gtk_minimum_version])
XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [xfce_minimum_version])
XDT_CHECK_PACKAGE([LIBXFCE4UI], libxfce4ui-2, [libxfce4ui_minimum_version])
......
......@@ -16,7 +16,7 @@
MA 02110-1301, USA.
xfwm4 - (c) 2002-2015 Olivier Fourdan
xfwm4 - (c) 2002-2020 Olivier Fourdan
*/
......@@ -38,7 +38,9 @@
#ifdef HAVE_RENDER
#include <X11/extensions/Xrender.h>
#endif
#ifdef HAVE_XRES
#include <X11/extensions/XRes.h>
#endif
#include "spinning_cursor.h"
#include "display.h"
#include "screen.h"
......@@ -324,6 +326,24 @@ myDisplayInit (GdkDisplay *gdisplay)
display->have_xrandr = FALSE;
#endif /* HAVE_RANDR */
#ifdef HAVE_XRES
if (XResQueryExtension (display->dpy,
&display->xres_event_base,
&display->xres_error_base))
{
display->have_xres = TRUE;
}
else
{
g_warning ("The display does not support the XRes extension.");
display->have_xres = FALSE;
display->xres_event_base = 0;
display->xres_error_base = 0;
}
#else /* HAVE_XRES */
display->have_xres = FALSE;
#endif /* HAVE_XRES */
myDisplayCreateCursor (display);
myDisplayCreateTimestampWin (display);
......
......@@ -16,7 +16,7 @@
MA 02110-1301, USA.
xfwm4 - (c) 2002-2015 Olivier Fourdan
xfwm4 - (c) 2002-2020 Olivier Fourdan
*/
......@@ -308,6 +308,7 @@ struct _DisplayInfo
gboolean have_render;
gboolean have_xrandr;
gboolean have_xsync;
gboolean have_xres;
gint shape_version;
gint shape_event_base;
gint double_click_time;
......@@ -333,6 +334,10 @@ struct _DisplayInfo
gint xsync_event_base;
gint xsync_error_base;
#endif /* HAVE_XSYNC */
#ifdef HAVE_XRES
gint xres_event_base;
gint xres_error_base;
#endif /* HAVE_XRES */
#ifdef HAVE_COMPOSITOR
gint composite_error_base;
gint composite_event_base;
......
......@@ -18,7 +18,7 @@
oroborus - (c) 2001 Ken Lynch
Metacity - (c) 2001 Havoc Pennington
xfwm4 - (c) 2002-2015 Olivier Fourdan
xfwm4 - (c) 2002-2020 Olivier Fourdan
*/
......@@ -30,6 +30,9 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xmd.h>
#ifdef HAVE_XRES
#include <X11/extensions/XRes.h>
#endif
#include <glib.h>
#include <gdk/gdk.h>
......@@ -1443,3 +1446,52 @@ getWindowStartupId (DisplayInfo *display_info, Window w, gchar **startup_id)
return (*startup_id != NULL);
}
#endif
GPid
getWindowPID (DisplayInfo *display_info, Window w)
{
GPid pid = 0;
#ifdef HAVE_XRES
XResClientIdSpec client_specs;
XResClientIdValue *client_ids = NULL;
int i;
int result;
long num_ids;
if (display_info->have_xres)
{
client_specs.client = w;
client_specs.mask = XRES_CLIENT_ID_PID_MASK;
myDisplayErrorTrapPush (display_info);
XResQueryClientIds (display_info->dpy, 1, &client_specs, &num_ids, &client_ids);
result = myDisplayErrorTrapPop (display_info);
if (result == Success)
{
for (i = 0; i < num_ids; i++)
{
if (client_ids[i].spec.mask == XRES_CLIENT_ID_PID_MASK)
{
CARD32 *value = client_ids[i].value;
pid = (GPid) *value;
break;
}
}
XFree(client_ids);
if (pid > 0)
{
return pid;
}
}
}
#endif /* HAVE_XRES */
getHint (display_info, w, NET_WM_PID, (long *) &pid);
return pid;
}
......@@ -18,7 +18,7 @@
oroborus - (c) 2001 Ken Lynch
Metacity - (c) 2001 Havoc Pennington
xfwm4 - (c) 2002-2015 Olivier Fourdan
xfwm4 - (c) 2002-2020 Olivier Fourdan
*/
......@@ -298,4 +298,7 @@ gboolean getWindowStartupId (DisplayInfo *,
char **);
#endif
GPid getWindowPID (DisplayInfo *,
Window);
#endif /* INC_HINTS_H */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment