[Xcb] [PATCH 11/19] Xephyr: use xcb for event handling
Julien Cristau
jcristau at debian.org
Wed Oct 20 10:11:53 PDT 2010
No event compression though.
Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>
Signed-off-by: Julien Cristau <jcristau at debian.org>
---
hw/kdrive/ephyr/hostx.c | 83 ++++++++++++++++++++++++++++------------------
1 files changed, 50 insertions(+), 33 deletions(-)
diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index 98a0a11..f6f7b9a 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -989,26 +989,23 @@ out:
int
hostx_get_event(EphyrHostXEvent *ev)
{
- XEvent xev;
+ xcb_generic_event_t *xev;
static int grabbed_screen = -1;
static xcb_key_symbols_t *keysyms;
if (!keysyms)
keysyms = xcb_key_symbols_alloc(HostX.conn);
- if (XPending(HostX.dpy))
+ xev = xcb_poll_for_event(HostX.conn);
+ if (xev)
{
- XNextEvent(HostX.dpy, &xev);
-
- switch (xev.type)
+ switch (xev->response_type)
{
- case Expose:
- /* Not so great event compression, but works ok */
- while (XCheckTypedWindowEvent(HostX.dpy, xev.xexpose.window,
- Expose, &xev));
+ case XCB_EXPOSE:
{
+ xcb_expose_event_t *expose = (xcb_expose_event_t *)xev;
struct EphyrHostScreen *host_screen =
- host_screen_from_window (xev.xexpose.window);
+ host_screen_from_window (expose->window);
if (host_screen)
{
hostx_paint_rect (host_screen->info, 0, 0, 0, 0,
@@ -1019,56 +1016,71 @@ hostx_get_event(EphyrHostXEvent *ev)
{
EPHYR_LOG_ERROR ("failed to get host screen\n");
ev->type = EPHYR_EV_EXPOSE;
- ev->data.expose.window = xev.xexpose.window;
+ ev->data.expose.window = expose->window;
+ free(xev);
return 1;
}
}
+ free(xev);
return 0;
- case MotionNotify:
+ case XCB_MOTION_NOTIFY:
{
+ xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *)xev;
struct EphyrHostScreen *host_screen =
- host_screen_from_window (xev.xmotion.window);
+ host_screen_from_window (motion->event);
ev->type = EPHYR_EV_MOUSE_MOTION;
- ev->data.mouse_motion.x = xev.xmotion.x;
- ev->data.mouse_motion.y = xev.xmotion.y;
- ev->data.mouse_motion.window = xev.xmotion.window;
+ ev->data.mouse_motion.x = motion->event_x;
+ ev->data.mouse_motion.y = motion->event_y;
+ ev->data.mouse_motion.window = motion->event;
ev->data.mouse_motion.screen = (host_screen ? host_screen->mynum : -1);
}
+ free(xev);
return 1;
- case ButtonPress:
+ case XCB_BUTTON_PRESS:
+ {
+ xcb_button_press_event_t *button = (xcb_button_press_event_t *)xev;
ev->type = EPHYR_EV_MOUSE_PRESS;
- ev->key_state = xev.xkey.state;
+ ev->key_state = button->state;
/*
* This is a bit hacky. will break for button 5 ( defined as 0x10 )
* Check KD_BUTTON defines in kdrive.h
*/
- ev->data.mouse_down.button_num = 1<<(xev.xbutton.button-1);
+ ev->data.mouse_down.button_num = 1<<(button->detail-1);
+ free(xev);
return 1;
+ }
- case ButtonRelease:
+ case XCB_BUTTON_RELEASE:
+ {
+ xcb_button_release_event_t *button = (xcb_button_release_event_t *)xev;
ev->type = EPHYR_EV_MOUSE_RELEASE;
- ev->key_state = xev.xkey.state;
- ev->data.mouse_up.button_num = 1<<(xev.xbutton.button-1);
+ ev->key_state = button->state;
+ ev->data.mouse_up.button_num = 1<<(button->detail-1);
+ free(xev);
return 1;
+ }
- case KeyPress:
+ case XCB_KEY_PRESS:
{
+ xcb_key_press_event_t *key = (xcb_key_press_event_t *)xev;
ev->type = EPHYR_EV_KEY_PRESS;
- ev->key_state = xev.xkey.state;
- ev->data.key_down.scancode = xev.xkey.keycode;
+ ev->key_state = key->state;
+ ev->data.key_down.scancode = key->detail;
+ free(xev);
return 1;
}
- case KeyRelease:
-
- if ((xcb_key_symbols_get_keysym(keysyms,xev.xkey.keycode,0) == XK_Shift_L
- || xcb_key_symbols_get_keysym(keysyms,xev.xkey.keycode,0) == XK_Shift_R)
- && (xev.xkey.state & XCB_MOD_MASK_CONTROL))
+ case XCB_KEY_RELEASE:
+ {
+ xcb_key_release_event_t *key = (xcb_key_release_event_t *)xev;
+ if ((xcb_key_symbols_get_keysym(keysyms,key->detail,0) == XK_Shift_L
+ || xcb_key_symbols_get_keysym(keysyms,key->detail,0) == XK_Shift_R)
+ && (key->state & XCB_MOD_MASK_CONTROL))
{
struct EphyrHostScreen *host_screen =
- host_screen_from_window (xev.xexpose.window);
+ host_screen_from_window (key->event);
if (grabbed_screen != -1)
{
@@ -1126,15 +1138,20 @@ hostx_get_event(EphyrHostXEvent *ev)
* kdrive all togeather.
*/
ev->type = EPHYR_EV_KEY_RELEASE;
- ev->key_state = xev.xkey.state;
- ev->data.key_up.scancode = xev.xkey.keycode;
+ ev->key_state = key->state;
+ ev->data.key_up.scancode = key->detail;
+ free(xev);
return 1;
+ }
default:
break;
}
+ } else {
+ xcb_flush(HostX.conn);
}
+ free(xev);
return 0;
}
--
1.7.1
More information about the Xcb
mailing list