[Xcb] is it possible to monitor events in other windows?
Patrick
patrick at spellingbeewinnars.org
Mon Oct 20 07:00:31 PDT 2014
Hi Everyone
So this is a bit of a long story and to keep it suitable for the mailing
list, I am basically trying to monitor mouse clicks in a terminal under
X as opposed to using gpm through ncurses.
I have chopped down an example from freedsktop.org and I have it pasted
at the end of this email.
This is the part I am confused about:
xcb_wait_for_event (c)
This is responding to events in the window created but is the windows ID
passed implicitly ? Is there a way to pass another windows ID ? I am
basically planning on creating a small xcb program that will take the
window ID of the terminal that the program is running in, I don't want
to create another window.
Thanks for reading my post-Patrick
code-->---------------------------->
#include <stdlib.h>
#include <stdio.h>
#include <xcb/xcb.h>
int main (int argc, int * argv[])
{
xcb_connection_t *c;
xcb_screen_t *screen;
xcb_window_t win;
xcb_generic_event_t *e;
uint32_t mask = 0;
uint32_t values[2];
/* Open the connection to the X server */
c = xcb_connect (NULL, NULL);
/* Get the first screen */
screen = xcb_setup_roots_iterator (xcb_get_setup (c)).data;
/* Ask for our window's Id */
win = xcb_generate_id (c);
// win = 65574484 ;
/* Create the window */
mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
values[0] = screen->white_pixel;
values[1] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS
| XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_KEY_PRESS |
XCB_EVENT_MASK_KEY_RELEASE;
xcb_create_window (c, /*
Connection */
0, /*
depth */
win, /* window
Id */
screen->root, /* parent
window */
0, 0, /* x,
y */
150, 150, /* width,
height */
10, /*
border_width */
XCB_WINDOW_CLASS_INPUT_OUTPUT, /*
class */
screen->root_visual, /*
visual */
mask, values); /* masks */
/* Map the window on the screen */
xcb_map_window (c, win);
xcb_flush (c);
//CONFUSED HERE
while ( (e = xcb_wait_for_event (c) ) ) {
switch (e->response_type & ~0x80) {
case XCB_BUTTON_RELEASE: {
xcb_button_release_event_t *ev =
(xcb_button_release_event_t *)e;
printf ("Button %d released in window %ld, at
coordinates (%d,%d)\n", ev->detail, ev->event, ev->event_x, ev->event_y);
break;
}
case XCB_KEY_PRESS: {
xcb_key_press_event_t *ev = (xcb_key_press_event_t *)e;
printf ("Key pressed in window %ld\n", ev->event);
break;
}
case XCB_KEY_RELEASE: {
xcb_key_release_event_t *ev = (xcb_key_release_event_t *)e;
printf ("Key released in window %ld\n", ev->event);
break;
}
default:
;
break;
}
/* Free the Generic Event */
free (e);
}
return 0;
}
More information about the Xcb
mailing list