Merge lp:~3v1n0/bamf/trap-x-errors into lp:~unity-team/bamf/0.5

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Christopher Townsend
Approved revision: 588
Merged at revision: 589
Proposed branch: lp:~3v1n0/bamf/trap-x-errors
Merge into: lp:~unity-team/bamf/0.5
Diff against target: 96 lines (+42/-7)
1 file modified
src/bamf-xutils.c (+42/-7)
To merge this branch: bzr merge lp:~3v1n0/bamf/trap-x-errors
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Christopher Townsend Approve
Review via email: mp+192983@code.launchpad.net

Commit message

BamfXutils: trap the X errors when doing async X calls

Description of the change

To post a comment you must log in.
Revision history for this message
Christopher Townsend (townsend) wrote :

+1

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/bamf-xutils.c'
2--- src/bamf-xutils.c 2012-11-15 17:45:29 +0000
3+++ src/bamf-xutils.c 2013-10-29 00:40:18 +0000
4@@ -44,6 +44,26 @@
5 return xdisplay;
6 }
7
8+static gboolean
9+gdk_error_trap_pop_and_print (Display *dpy)
10+{
11+ gdk_flush ();
12+ gint error_code = gdk_error_trap_pop ();
13+
14+ if (error_code)
15+ {
16+ gchar tmp[1024];
17+ XGetErrorText (dpy, error_code, tmp, sizeof (tmp) - 1);
18+ tmp[sizeof (tmp) - 1] = '\0';
19+
20+ g_warning("Got an X error: %s\n", tmp);
21+
22+ return TRUE;
23+ }
24+
25+ return FALSE;
26+}
27+
28 static void
29 bamf_xutils_get_string_window_hint_and_type (Window xid, const char *atom_name,
30 gchar** return_hint, Atom* return_type)
31@@ -74,6 +94,8 @@
32 return;
33 }
34
35+ gdk_error_trap_push ();
36+
37 int result = XGetWindowProperty (XDisplay, xid,
38 gdk_x11_get_xatom_by_name (atom_name),
39 0, G_MAXINT, False, AnyPropertyType,
40@@ -83,7 +105,7 @@
41 if (close_display)
42 XCloseDisplay (XDisplay);
43
44- if (result == Success && numItems > 0)
45+ if (result == Success && numItems > 0 && !gdk_error_trap_pop_and_print (XDisplay))
46 {
47 if (return_type)
48 *return_type = type;
49@@ -135,12 +157,20 @@
50 else if (type != XA_STRING && type != gdk_x11_get_xatom_by_name("UTF8_STRING"))
51 {
52 g_error ("Impossible to set the atom %s on Window %lu", atom_name, xid);
53+
54+ if (close_display)
55+ XCloseDisplay (XDisplay);
56+
57 return;
58 }
59
60+ gdk_error_trap_push ();
61+
62 XChangeProperty (XDisplay, xid, gdk_x11_get_xatom_by_name (atom_name),
63 type, 8, PropModeReplace, (unsigned char *) value, strlen (value));
64
65+ gdk_error_trap_pop_and_print (XDisplay);
66+
67 if (close_display)
68 XCloseDisplay (XDisplay);
69 }
70@@ -163,15 +193,20 @@
71 class_hint.res_name = NULL;
72 class_hint.res_class = NULL;
73
74+ gdk_error_trap_push ();
75+
76 XGetClassHint(xdisplay, xid, &class_hint);
77
78- if (class_name && class_hint.res_class && class_hint.res_class[0] != 0)
79- *class_name = g_convert (class_hint.res_class, -1, "utf-8", "iso-8859-1",
80- NULL, NULL, NULL);
81+ if (!gdk_error_trap_pop_and_print (xdisplay))
82+ {
83+ if (class_name && class_hint.res_class && class_hint.res_class[0] != 0)
84+ *class_name = g_convert (class_hint.res_class, -1, "utf-8", "iso-8859-1",
85+ NULL, NULL, NULL);
86
87- if (class_instance_name && class_hint.res_name && class_hint.res_name[0] != 0)
88- *class_instance_name = g_convert (class_hint.res_name, -1, "utf-8", "iso-8859-1",
89- NULL, NULL, NULL);
90+ if (class_instance_name && class_hint.res_name && class_hint.res_name[0] != 0)
91+ *class_instance_name = g_convert (class_hint.res_name, -1, "utf-8", "iso-8859-1",
92+ NULL, NULL, NULL);
93+ }
94
95 XFree (class_hint.res_class);
96 XFree (class_hint.res_name);

Subscribers

People subscribed via source and target branches