xed-utils: Add runtime checks for x11 specific functions
This should prevent some crashes under wayland.
This commit is contained in:
parent
3341c0a260
commit
c6ca2a03da
120
xed/xed-utils.c
120
xed/xed-utils.c
|
@ -54,8 +54,6 @@
|
||||||
/* For the workspace/viewport stuff */
|
/* For the workspace/viewport stuff */
|
||||||
#ifdef GDK_WINDOWING_X11
|
#ifdef GDK_WINDOWING_X11
|
||||||
#include <gdk/gdkx.h>
|
#include <gdk/gdkx.h>
|
||||||
#include <X11/Xlib.h>
|
|
||||||
#include <X11/Xutil.h>
|
|
||||||
#include <X11/Xatom.h>
|
#include <X11/Xatom.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -655,12 +653,6 @@ xed_utils_get_current_workspace (GdkScreen *screen)
|
||||||
#ifdef GDK_WINDOWING_X11
|
#ifdef GDK_WINDOWING_X11
|
||||||
GdkWindow *root_win;
|
GdkWindow *root_win;
|
||||||
GdkDisplay *display;
|
GdkDisplay *display;
|
||||||
Atom type;
|
|
||||||
gint format;
|
|
||||||
gulong nitems;
|
|
||||||
gulong bytes_after;
|
|
||||||
guint *current_desktop;
|
|
||||||
gint err, result;
|
|
||||||
guint ret = 0;
|
guint ret = 0;
|
||||||
|
|
||||||
g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
|
g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
|
||||||
|
@ -668,24 +660,35 @@ xed_utils_get_current_workspace (GdkScreen *screen)
|
||||||
root_win = gdk_screen_get_root_window (screen);
|
root_win = gdk_screen_get_root_window (screen);
|
||||||
display = gdk_screen_get_display (screen);
|
display = gdk_screen_get_display (screen);
|
||||||
|
|
||||||
gdk_error_trap_push ();
|
if (GDK_IS_X11_DISPLAY (display))
|
||||||
result = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (root_win),
|
|
||||||
gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"),
|
|
||||||
0, G_MAXLONG, False, XA_CARDINAL, &type, &format, &nitems,
|
|
||||||
&bytes_after, (gpointer) ¤t_desktop);
|
|
||||||
err = gdk_error_trap_pop ();
|
|
||||||
|
|
||||||
if (err != Success || result != Success)
|
|
||||||
{
|
{
|
||||||
return ret;
|
Atom type;
|
||||||
|
gint format;
|
||||||
|
gulong nitems;
|
||||||
|
gulong bytes_after;
|
||||||
|
guint *current_desktop;
|
||||||
|
gint err, result;
|
||||||
|
|
||||||
|
gdk_error_trap_push ();
|
||||||
|
result = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (root_win),
|
||||||
|
gdk_x11_get_xatom_by_name_for_display (display, "_NET_CURRENT_DESKTOP"),
|
||||||
|
0, G_MAXLONG, False, XA_CARDINAL, &type, &format, &nitems,
|
||||||
|
&bytes_after, (gpointer) ¤t_desktop);
|
||||||
|
err = gdk_error_trap_pop ();
|
||||||
|
|
||||||
|
if (err != Success || result != Success)
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == XA_CARDINAL && format == 32 && nitems > 0)
|
||||||
|
{
|
||||||
|
ret = current_desktop[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
XFree (current_desktop);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == XA_CARDINAL && format == 32 && nitems > 0)
|
|
||||||
{
|
|
||||||
ret = current_desktop[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
XFree (current_desktop);
|
|
||||||
return ret;
|
return ret;
|
||||||
#else
|
#else
|
||||||
/* FIXME: on mac etc proably there are native APIs
|
/* FIXME: on mac etc proably there are native APIs
|
||||||
|
@ -723,24 +726,28 @@ xed_utils_get_window_workspace (GtkWindow *gtkwindow)
|
||||||
window = gtk_widget_get_window (GTK_WIDGET (gtkwindow));
|
window = gtk_widget_get_window (GTK_WIDGET (gtkwindow));
|
||||||
display = gdk_window_get_display (window);
|
display = gdk_window_get_display (window);
|
||||||
|
|
||||||
gdk_error_trap_push ();
|
if (GDK_IS_X11_DISPLAY (display))
|
||||||
result = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
|
|
||||||
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
|
|
||||||
0, G_MAXLONG, False, XA_CARDINAL, &type, &format, &nitems,
|
|
||||||
&bytes_after, (gpointer) &workspace);
|
|
||||||
err = gdk_error_trap_pop ();
|
|
||||||
|
|
||||||
if (err != Success || result != Success)
|
|
||||||
{
|
{
|
||||||
return ret;
|
gdk_error_trap_push ();
|
||||||
|
result = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
|
||||||
|
gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
|
||||||
|
0, G_MAXLONG, False, XA_CARDINAL, &type, &format, &nitems,
|
||||||
|
&bytes_after, (gpointer) &workspace);
|
||||||
|
err = gdk_error_trap_pop ();
|
||||||
|
|
||||||
|
if (err != Success || result != Success)
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == XA_CARDINAL && format == 32 && nitems > 0)
|
||||||
|
{
|
||||||
|
ret = workspace[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
XFree (workspace);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == XA_CARDINAL && format == 32 && nitems > 0)
|
|
||||||
{
|
|
||||||
ret = workspace[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
XFree (workspace);
|
|
||||||
return ret;
|
return ret;
|
||||||
#else
|
#else
|
||||||
/* FIXME: on mac etc proably there are native APIs
|
/* FIXME: on mac etc proably there are native APIs
|
||||||
|
@ -783,27 +790,30 @@ xed_utils_get_current_viewport (GdkScreen *screen,
|
||||||
root_win = gdk_screen_get_root_window (screen);
|
root_win = gdk_screen_get_root_window (screen);
|
||||||
display = gdk_screen_get_display (screen);
|
display = gdk_screen_get_display (screen);
|
||||||
|
|
||||||
gdk_error_trap_push ();
|
if (GDK_IS_X11_DISPLAY (display))
|
||||||
result = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (root_win),
|
|
||||||
gdk_x11_get_xatom_by_name_for_display (display, "_NET_DESKTOP_VIEWPORT"),
|
|
||||||
0, G_MAXLONG, False, XA_CARDINAL, &type, &format, &nitems,
|
|
||||||
&bytes_after, (void*) &coordinates);
|
|
||||||
err = gdk_error_trap_pop ();
|
|
||||||
|
|
||||||
if (err != Success || result != Success)
|
|
||||||
{
|
{
|
||||||
return;
|
gdk_error_trap_push ();
|
||||||
}
|
result = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (root_win),
|
||||||
|
gdk_x11_get_xatom_by_name_for_display (display, "_NET_DESKTOP_VIEWPORT"),
|
||||||
|
0, G_MAXLONG, False, XA_CARDINAL, &type, &format, &nitems,
|
||||||
|
&bytes_after, (void*) &coordinates);
|
||||||
|
err = gdk_error_trap_pop ();
|
||||||
|
|
||||||
if (type != XA_CARDINAL || format != 32 || nitems < 2)
|
if (err != Success || result != Success)
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type != XA_CARDINAL || format != 32 || nitems < 2)
|
||||||
|
{
|
||||||
|
XFree (coordinates);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
*x = coordinates[0];
|
||||||
|
*y = coordinates[1];
|
||||||
XFree (coordinates);
|
XFree (coordinates);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*x = coordinates[0];
|
|
||||||
*y = coordinates[1];
|
|
||||||
XFree (coordinates);
|
|
||||||
#else
|
#else
|
||||||
/* FIXME: on mac etc proably there are native APIs
|
/* FIXME: on mac etc proably there are native APIs
|
||||||
* to get the current workspace etc */
|
* to get the current workspace etc */
|
||||||
|
|
Loading…
Reference in New Issue