summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2013-04-09 14:46:26 +0200
committerHans de Goede <hdegoede@redhat.com>2013-04-09 14:46:26 +0200
commit515944aa50cd67f2ff906233ffddf9515335f436 (patch)
tree5c7ba61e6a43ae97c84a412c8a7a130d7dfb4ca6 /src
parent15d33799ee5e73316db2ff278ed6b29faa4d4424 (diff)
downloadvd_agent-515944aa50cd67f2ff906233ffddf9515335f436.tar.gz
vd_agent-515944aa50cd67f2ff906233ffddf9515335f436.tar.xz
vd_agent-515944aa50cd67f2ff906233ffddf9515335f436.zip
vdagent-x11: Unify / share error handling between vdagent-x11 and randr code
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Diffstat (limited to 'src')
-rw-r--r--src/vdagent-x11-priv.h7
-rw-r--r--src/vdagent-x11-randr.c36
-rw-r--r--src/vdagent-x11.c20
3 files changed, 29 insertions, 34 deletions
diff --git a/src/vdagent-x11-priv.h b/src/vdagent-x11-priv.h
index d161f64..ee04b04 100644
--- a/src/vdagent-x11-priv.h
+++ b/src/vdagent-x11-priv.h
@@ -135,10 +135,17 @@ struct vdagent_x11 {
int dont_send_guest_xorg_res;
};
+extern int (*vdagent_x11_prev_error_handler)(Display *, XErrorEvent *);
+extern int vdagent_x11_caught_error;
+
void vdagent_x11_randr_init(struct vdagent_x11 *x11);
void vdagent_x11_send_daemon_guest_xorg_res(struct vdagent_x11 *x11,
int update);
void vdagent_x11_randr_handle_root_size_change(struct vdagent_x11 *x11,
int width, int height);
+void vdagent_x11_set_error_handler(struct vdagent_x11 *x11,
+ int (*handler)(Display *, XErrorEvent *));
+int vdagent_x11_restore_error_handler(struct vdagent_x11 *x11);
+
#endif // VDAGENT_X11_PRIV
diff --git a/src/vdagent-x11-randr.c b/src/vdagent-x11-randr.c
index 7738851..5a299d1 100644
--- a/src/vdagent-x11-randr.c
+++ b/src/vdagent-x11-randr.c
@@ -32,34 +32,12 @@
#include "vdagent-x11.h"
#include "vdagent-x11-priv.h"
-static int caught_error;
-static int (*old_error_handler)(Display *, XErrorEvent *);
-
static int error_handler(Display *display, XErrorEvent *error)
{
- caught_error = 1;
+ vdagent_x11_caught_error = 1;
return 0;
}
-static void arm_error_handler(struct vdagent_x11 *x11)
-{
- caught_error = 0;
- XSync(x11->display, False);
- old_error_handler = XSetErrorHandler(error_handler);
-}
-
-static int check_error_handler(struct vdagent_x11 *x11)
-{
- int error;
-
- XSync(x11->display, False);
- XSetErrorHandler(old_error_handler);
- error = caught_error;
- caught_error = 0;
-
- return error;
-}
-
static XRRModeInfo *mode_from_id(struct vdagent_x11 *x11, int id)
{
int i;
@@ -237,12 +215,12 @@ static void delete_mode(struct vdagent_x11 *x11, int output_index,
break;
}
if (m < x11->randr.res->nmode) {
- arm_error_handler(x11);
+ vdagent_x11_set_error_handler(x11, error_handler);
XRRDeleteOutputMode (x11->display, x11->randr.res->outputs[output_index],
mode->id);
XRRDestroyMode (x11->display, mode->id);
// ignore race error, if mode is created by others
- check_error_handler(x11);
+ vdagent_x11_restore_error_handler(x11);
}
/* silly to update everytime for more then one monitor */
@@ -337,10 +315,10 @@ static XRRModeInfo *create_new_mode(struct vdagent_x11 *x11, int output_index,
set_reduced_cvt_mode(&mode, width, height);
mode.modeFlags = 0;
mode.id = 0;
- arm_error_handler(x11);
+ vdagent_x11_set_error_handler(x11, error_handler);
XRRCreateMode (x11->display, x11->root_window, &mode);
// ignore race error, if mode is created by others
- check_error_handler(x11);
+ vdagent_x11_restore_error_handler(x11);
/* silly to update everytime for more then one monitor */
update_randr_res(x11, 0);
@@ -786,11 +764,11 @@ void vdagent_x11_set_monitor_config(struct vdagent_x11 *x11,
if (x11->debug)
syslog(LOG_DEBUG, "Changing screen size to %dx%d",
primary_w, primary_h);
- arm_error_handler(x11);
+ vdagent_x11_set_error_handler(x11, error_handler);
XRRSetScreenSize(x11->display, x11->root_window, primary_w, primary_h,
DisplayWidthMM(x11->display, x11->screen),
DisplayHeightMM(x11->display, x11->screen));
- if (check_error_handler(x11)) {
+ if (vdagent_x11_restore_error_handler(x11)) {
syslog(LOG_ERR, "XRRSetScreenSize failed, not enough mem?");
if (!fallback && curr) {
syslog(LOG_WARNING, "Restoring previous config");
diff --git a/src/vdagent-x11.c b/src/vdagent-x11.c
index 5e1cbb6..2cfbeab 100644
--- a/src/vdagent-x11.c
+++ b/src/vdagent-x11.c
@@ -46,7 +46,8 @@
#include "vdagent-x11-priv.h"
/* Stupid X11 API, there goes our encapsulate all data in a struct design */
-static int (*vdagent_x11_prev_error_handler)(Display *, XErrorEvent *);
+int (*vdagent_x11_prev_error_handler)(Display *, XErrorEvent *);
+int vdagent_x11_caught_error;
static void vdagent_x11_handle_selection_notify(struct vdagent_x11 *x11,
XEvent *event, int incr);
@@ -88,15 +89,24 @@ static int vdagent_x11_ignore_bad_window_handler(
return vdagent_x11_prev_error_handler(display, error);
}
-static void vdagent_x11_set_error_handler(
+void vdagent_x11_set_error_handler(struct vdagent_x11 *x11,
int (*handler)(Display *, XErrorEvent *))
{
+ XSync(x11->display, False);
+ vdagent_x11_caught_error = 0;
vdagent_x11_prev_error_handler = XSetErrorHandler(handler);
}
-static void vdagent_x11_restore_error_handler(void)
+int vdagent_x11_restore_error_handler(struct vdagent_x11 *x11)
{
+ int error;
+
+ XSync(x11->display, False);
XSetErrorHandler(vdagent_x11_prev_error_handler);
+ error = vdagent_x11_caught_error;
+ vdagent_x11_caught_error = 0;
+
+ return error;
}
static void vdagent_x11_get_wm_name(struct vdagent_x11 *x11)
@@ -112,7 +122,7 @@ static void vdagent_x11_get_wm_name(struct vdagent_x11 *x11)
_NET_SUPPORTING_WM_CHECK property, and the window manager running in
the user session has not yet updated it to point to its window, so its
pointing to a non existing window. */
- vdagent_x11_set_error_handler(vdagent_x11_ignore_bad_window_handler);
+ vdagent_x11_set_error_handler(x11, vdagent_x11_ignore_bad_window_handler);
/* Get the window manager SUPPORTING_WM_CHECK window */
if (XGetWindowProperty(x11->display, x11->root_window,
@@ -158,7 +168,7 @@ static void vdagent_x11_get_wm_name(struct vdagent_x11 *x11)
}
}
- vdagent_x11_restore_error_handler();
+ vdagent_x11_restore_error_handler(x11);
}
struct vdagent_x11 *vdagent_x11_create(struct udscs_connection *vdagentd,