35 xcb_connection_t *c = xcb_connect(
nullptr, &screenNumber);
37 auto getScreen = [=]() {
38 const xcb_setup_t *setup = xcb_get_setup(c);
39 auto it = xcb_setup_roots_iterator(setup);
40 for (
int i = 0; i < screenNumber; ++i) {
45 xcb_screen_t *screen = getScreen();
47 xcb_window_t w = xcb_generate_id(c);
48 const uint32_t values[2] = {
50 XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_STRUCTURE_NOTIFY};
52 xcb_create_window(c, 0, w, screen->root, 0, 0, 365, 104, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT,
53 screen->root_visual, XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK, values);
56 xcb_size_hints_t hints;
57 hints.flags = XCB_ICCCM_SIZE_HINT_P_MIN_SIZE | XCB_ICCCM_SIZE_HINT_BASE_SIZE | XCB_ICCCM_SIZE_HINT_P_RESIZE_INC;
58 hints.min_width = 365;
59 hints.min_height = 104;
60 hints.base_width = 15;
61 hints.base_height = 64;
63 hints.height_inc = 18;
64 xcb_icccm_set_wm_normal_hints(c, w, &hints);
71 while (xcb_generic_event_t *event = xcb_wait_for_event(c)) {
73 if ((event->response_type & ~0x80) == XCB_BUTTON_RELEASE) {
75 }
else if ((event->response_type & ~0x80) == XCB_CONFIGURE_NOTIFY) {
76 auto *ce =
reinterpret_cast<xcb_configure_notify_event_t *
>(event);
77 const double i = (ce->width - hints.base_width) / (
double)hints.width_inc;
78 const double j = (ce->height - hints.base_height) / (
double)hints.height_inc;
83 if (hints.base_width + (
int(i) * hints.width_inc) != ce->width) {
84 std::cerr <<
"Incorrect width - i factor is " << i << std::endl;
88 if (hints.base_height + (
int(j) * hints.height_inc) != ce->height) {
89 std::cerr <<
"Incorrect height - j factor is " << i << std::endl;
101 return error ? 1 : 0;