Commit 825fb2ad authored by Alexander Larsson's avatar Alexander Larsson

Do runtime checks for X11 specific calls

This means gedit doesn't break when using e.g. the broadway backend.
parent 3f5edf9b
......@@ -22,6 +22,10 @@
#include "gedit-app-x11.h"
#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
#endif
#define GEDIT_APP_X11_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GEDIT_TYPE_APP_X11, GeditAppX11Private))
G_DEFINE_TYPE (GeditAppX11, gedit_app_x11, GEDIT_TYPE_APP)
......@@ -69,7 +73,8 @@ gedit_app_add_platform_data (GApplication *app,
* "_NET_WM_USER_TIME_WINDOW" one since that's what we're doing
* here...
*/
if (!g_getenv ("DESKTOP_STARTUP_ID") && g_getenv ("DISPLAY"))
if (!g_getenv ("DESKTOP_STARTUP_ID") && g_getenv ("DISPLAY") &&
GDK_IS_X11_DISPLAY (gdk_display_get_default ()))
{
gchar *startup_id;
Display *display;
......
......@@ -843,21 +843,24 @@ gedit_utils_get_window_workspace (GtkWindow *gtkwindow)
window = gtk_widget_get_window (GTK_WIDGET (gtkwindow));
display = gdk_window_get_display (window);
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 (GDK_IS_X11_DISPLAY (display))
{
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];
if (type == XA_CARDINAL && format == 32 && nitems > 0)
ret = workspace[0];
XFree (workspace);
return ret;
XFree (workspace);
return ret;
}
#else
/* FIXME: on mac etc proably there are native APIs
* to get the current workspace etc */
......@@ -900,25 +903,28 @@ gedit_utils_get_current_viewport (GdkScreen *screen,
root_win = gdk_screen_get_root_window (screen);
display = gdk_screen_get_display (screen);
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 (GDK_IS_X11_DISPLAY (display))
{
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 (err != Success || result != Success)
return;
if (err != Success || result != Success)
return;
if (type != XA_CARDINAL || format != 32 || nitems < 2)
{
if (type != XA_CARDINAL || format != 32 || nitems < 2)
{
XFree (coordinates);
return;
}
*x = coordinates[0];
*y = coordinates[1];
XFree (coordinates);
return;
}
*x = coordinates[0];
*y = coordinates[1];
XFree (coordinates);
#else
/* FIXME: on mac etc proably there are native APIs
* to get the current workspace etc */
......
Markdown is supported
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