-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmousegrab.c
More file actions
41 lines (26 loc) · 854 Bytes
/
mousegrab.c
File metadata and controls
41 lines (26 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "xutil.h"
#include <stdio.h>
#include <xcb/xcb.h>
void main ( int argc, char *argv[] ) {
// use of extern decl: Links to "display" variable defined in xutil.c
extern xcb_connection_t * display;
int windowId, lx, ly;
initialize ( );
grabMouse( ); // Initiate an active mouse grab
xcb_generic_event_t * event;
// Event loop
// Wait for button event. Print mouse position on button release and print ouch on button pres
while (event = xcb_wait_for_event (display)) {
switch (event->response_type & ~0x80) {
case XCB_BUTTON_PRESS:
printf ("Ouch\n"); // Illustration of different processing for different events
break;
case XCB_BUTTON_RELEASE:
getMouseLocation (&windowId, &lx, &ly);
printf ("Inside window %d at (%d, %d)\n", windowId, lx, ly);
break;
default:
break;
}
}
}