Created
October 28, 2016 01:51
-
-
Save mafrasi2/4ee01e0ba4dad20cf7a80ae463f32fca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Compile with -lxcb -lxcb-randr | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <xcb/xcb.h> | |
#include <xcb/randr.h> | |
int main() { | |
xcb_connection_t* conn; | |
xcb_screen_t* screen; | |
xcb_window_t window; | |
xcb_generic_event_t* evt; | |
xcb_randr_screen_change_notify_event_t* randr_evt; | |
xcb_timestamp_t last_time; | |
int monitor_connected = 1; | |
conn = xcb_connect(NULL, NULL); | |
screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data; | |
window = screen->root; | |
xcb_randr_select_input(conn, window, XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE); | |
xcb_flush(conn); | |
while ((evt = xcb_wait_for_event(conn)) != NULL) { | |
if (evt->response_type & XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE) { | |
randr_evt = (xcb_randr_screen_change_notify_event_t*) evt; | |
if (last_time != randr_evt->timestamp) { | |
last_time = randr_evt->timestamp; | |
monitor_connected = !monitor_connected; | |
if (monitor_connected) { | |
printf("Monitor connected\n"); | |
} else { | |
printf("Monitor disconnected\n"); | |
} | |
} | |
} | |
free(evt); | |
} | |
xcb_disconnect(conn); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hmm, have you linked with libxcb? For example like this:
On Ubuntu, you'll need to install
libxcb-randr0-dev
,libxcb1
andlibxcb1-dev
before.