30#define G_LOG_DOMAIN "X11Helper"
34#include <xcb-imdkit/encoding.h>
35#include <xcb/xcb_keysyms.h>
48#include <xcb/xcb_aux.h>
49#include <xcb/xcb_cursor.h>
50#include <xcb/xcb_ewmh.h>
51#include <xcb/xinerama.h>
53#include <xcb/xproto.h>
54#include <xkbcommon/xkbcommon-x11.h>
55#include <xkbcommon/xkbcommon.h>
57#define SN_API_NOT_YET_FROZEN
60#define sn_launcher_context_set_application_id sn_launcher_set_application_id
77#define RANDR_PREF_MAJOR_VERSION 1
79#define RANDR_PREF_MINOR_VERSION 5
82#define INTERSECT(x, y, x1, y1, w1, h1) \
83 ((((x) >= (x1)) && ((x) < (x1 + w1))) && (((y) >= (y1)) && ((y) < (y1 + h1))))
108xcb_colormap_t
map = XCB_COLORMAP_NONE;
129 {
"default",
"left_ptr"}, {
"pointer",
"hand"}, {
"text",
"xterm"}};
131static xcb_visualtype_t *
lookup_visual(xcb_screen_t *s, xcb_visualid_t vis) {
132 xcb_depth_iterator_t d;
133 d = xcb_screen_allowed_depths_iterator(s);
134 for (; d.rem; xcb_depth_next(&d)) {
135 xcb_visualtype_iterator_t v = xcb_depth_visuals_iterator(d.data);
136 for (; v.rem; xcb_visualtype_next(&v)) {
137 if (v.data->visual_id == vis) {
149static uint32_t *
create_kernel(
int radius,
double deviation, uint32_t *sum2) {
150 int size = 2 * (radius) + 1;
151 uint32_t *kernel = (uint32_t *)(g_malloc(
sizeof(uint32_t) * (size + 1)));
152 double radiusf = abs(radius) + 1.0;
153 double value = -radius;
157 if (deviation == 0.0) {
158 deviation = sqrt(-(radiusf * radiusf) / (2.0 * log(1.0 / 255.0)));
163 for (i = 0; i < size; i++) {
164 kernel[1 + i] = INT16_MAX / (2.506628275 * deviation) *
165 exp(-((value * value) / (2.0 * (deviation * deviation))));
167 sum += kernel[1 + i];
179 uint32_t *kernel = 0;
180 cairo_format_t format;
181 unsigned int channels;
183 if (cairo_surface_status(surface)) {
187 uint8_t *data = cairo_image_surface_get_data(surface);
188 format = cairo_image_surface_get_format(surface);
189 const int width = cairo_image_surface_get_width(surface);
190 const int height = cairo_image_surface_get_height(surface);
191 const int stride = cairo_image_surface_get_stride(surface);
193 if (format == CAIRO_FORMAT_ARGB32) {
199 horzBlur = (uint32_t *)(g_malloc(
sizeof(uint32_t) * height * stride));
206 uint32_t *horzBlur_ptr = horzBlur;
207 for (
int iY = 0; iY < height; iY++) {
208 const int iYs = iY * stride;
209 for (
int iX = 0; iX < width; iX++) {
214 int offset = (int)(kernel[0]) / -2;
216 for (
int i = 0; i < (int)(kernel[0]); i++) {
219 if (x < 0 || x >= width) {
224 uint8_t *dataPtr = &data[iYs + x * channels];
225 const uint32_t kernip1 = kernel[i + 1];
227 blue += kernip1 * dataPtr[0];
228 green += kernip1 * dataPtr[1];
229 red += kernip1 * dataPtr[2];
230 alpha += kernip1 * dataPtr[3];
234 *horzBlur_ptr++ = blue / sum;
235 *horzBlur_ptr++ = green / sum;
236 *horzBlur_ptr++ = red / sum;
237 *horzBlur_ptr++ = alpha / sum;
243 for (
int iY = 0; iY < height; iY++) {
244 for (
int iX = 0; iX < width; iX++) {
249 int offset = (int)(kernel[0]) / -2;
251 const int iXs = iX * channels;
252 for (
int i = 0; i < (int)(kernel[0]); i++) {
255 if (y < 0 || y >= height) {
260 uint32_t *dataPtr = &horzBlur[y * stride + iXs];
261 const uint32_t kernip1 = kernel[i + 1];
263 blue += kernip1 * dataPtr[0];
264 green += kernip1 * dataPtr[1];
265 red += kernip1 * dataPtr[2];
266 alpha += kernip1 * dataPtr[3];
271 *data++ = blue / sum;
272 *data++ = green / sum;
274 *data++ = alpha / sum;
287 xcb_get_geometry_cookie_t cookie;
288 xcb_get_geometry_reply_t *reply;
290 cookie = xcb_get_geometry(
xcb->connection, window);
291 reply = xcb_get_geometry_reply(
xcb->connection, cookie, NULL);
296 xcb_get_window_attributes_cookie_t attributesCookie =
297 xcb_get_window_attributes(
xcb->connection, window);
298 xcb_get_window_attributes_reply_t *attributes =
299 xcb_get_window_attributes_reply(
xcb->connection, attributesCookie, NULL);
300 if (attributes == NULL || (attributes->map_state != XCB_MAP_STATE_VIEWABLE)) {
311 cairo_surface_t *t = cairo_xcb_surface_create(
xcb->connection, window, vt,
312 reply->width, reply->height);
314 if (cairo_surface_status(t) != CAIRO_STATUS_SUCCESS) {
315 cairo_surface_destroy(t);
321 int max = MAX(reply->width, reply->height);
322 double scale = (double)size / max;
324 cairo_surface_t *s2 = cairo_surface_create_similar_image(
325 t, CAIRO_FORMAT_ARGB32, reply->width * scale, reply->height * scale);
328 if (cairo_surface_status(s2) != CAIRO_STATUS_SUCCESS) {
329 cairo_surface_destroy(t);
333 cairo_t *d = cairo_create(s2);
334 cairo_scale(d, scale, scale);
335 cairo_set_source_surface(d, t, 0, 0);
339 cairo_surface_destroy(t);
349 xcb->screen->height_in_pixels);
354 xcb_get_property_cookie_t cookie;
355 xcb_get_property_reply_t *reply;
356 xcb_pixmap_t rootpixmap = XCB_NONE;
358 cookie = xcb_get_property(c, 0, screen->root, atom, XCB_ATOM_PIXMAP, 0, 1);
360 reply = xcb_get_property_reply(c, cookie, NULL);
363 if (xcb_get_property_value_length(reply) ==
sizeof(xcb_pixmap_t)) {
364 memcpy(&rootpixmap, xcb_get_property_value(reply),
sizeof(xcb_pixmap_t));
375 if (pm == XCB_NONE) {
379 xcb->screen->width_in_pixels,
380 xcb->screen->height_in_pixels);
387 xcb_get_property_cookie_t c = xcb_get_property(
388 xcb->connection, 0, w, atom, XCB_GET_PROPERTY_TYPE_ANY, 0, UINT_MAX);
389 xcb_get_property_reply_t *r =
390 xcb_get_property_reply(
xcb->connection, c, NULL);
392 if (xcb_get_property_value_length(r) > 0) {
394 if (r->type ==
netatoms[UTF8_STRING]) {
395 str = g_strndup(xcb_get_property_value(r),
396 xcb_get_property_value_length(r));
397 }
else if (r->type ==
netatoms[STRING]) {
399 xcb_get_property_value_length(r));
401 str = g_strdup(
"Invalid encoding.");
414 xcb_change_property(
xcb->connection, XCB_PROP_MODE_REPLACE, w, prop,
415 XCB_ATOM_ATOM, 32,
count, atoms);
431 while (
xcb->monitors != NULL) {
444 double ratio_res = w->
w / (double)w->
h;
445 double ratio_size = w->
mw / (double)w->
mh;
447 if ((ratio_res < 1.0 && ratio_size > 1.0) ||
448 (ratio_res > 1.0 && ratio_size < 1.0)) {
459 xcb_randr_get_output_info_reply_t *op_reply;
460 xcb_randr_get_crtc_info_reply_t *crtc_reply;
461 xcb_randr_get_output_info_cookie_t it =
462 xcb_randr_get_output_info(
xcb->connection, out, XCB_CURRENT_TIME);
463 op_reply = xcb_randr_get_output_info_reply(
xcb->connection, it, NULL);
464 if (op_reply->crtc == XCB_NONE) {
468 xcb_randr_get_crtc_info_cookie_t ct = xcb_randr_get_crtc_info(
469 xcb->connection, op_reply->crtc, XCB_CURRENT_TIME);
470 crtc_reply = xcb_randr_get_crtc_info_reply(
xcb->connection, ct, NULL);
476 retv->
x = crtc_reply->x;
477 retv->
y = crtc_reply->y;
478 retv->
w = crtc_reply->width;
479 retv->
h = crtc_reply->height;
481 retv->
mw = op_reply->mm_width;
482 retv->
mh = op_reply->mm_height;
485 char *tname = (
char *)xcb_randr_get_output_info_name(op_reply);
486 int tname_len = xcb_randr_get_output_info_name_length(op_reply);
488 retv->
name = g_malloc0((tname_len + 1) *
sizeof(
char));
489 memcpy(retv->
name, tname, tname_len);
496#if (((XCB_RANDR_MAJOR_VERSION >= RANDR_PREF_MAJOR_VERSION) && \
497 (XCB_RANDR_MINOR_VERSION >= RANDR_PREF_MINOR_VERSION)) || \
498 XCB_RANDR_MAJOR_VERSION > RANDR_PREF_MAJOR_VERSION)
507x11_get_monitor_from_randr_monitor(xcb_randr_monitor_info_t *
mon) {
509 xcb_generic_error_t *err;
510 xcb_get_atom_name_cookie_t anc =
511 xcb_get_atom_name(
xcb->connection,
mon->name);
512 xcb_get_atom_name_reply_t *atom_reply =
513 xcb_get_atom_name_reply(
xcb->connection, anc, &err);
515 g_warning(
"Could not get RandR monitor name: X11 error code %d\n",
528 retv->
w =
mon->width;
529 retv->
h =
mon->height;
532 retv->
mw =
mon->width_in_millimeters;
533 retv->
mh =
mon->height_in_millimeters;
538 g_strdup_printf(
"%.*s", xcb_get_atom_name_name_length(atom_reply),
539 xcb_get_atom_name_name(atom_reply));
549 xcb_query_extension_cookie_t randr_cookie =
550 xcb_query_extension(
xcb->connection, strlen(extension), extension);
552 xcb_query_extension_reply_t *randr_reply =
553 xcb_query_extension_reply(
xcb->connection, randr_cookie, NULL);
555 int present = randr_reply->present;
563 xcb_xinerama_query_screens_cookie_t screens_cookie =
564 xcb_xinerama_query_screens_unchecked(
xcb->connection);
566 xcb_xinerama_query_screens_reply_t *screens_reply =
567 xcb_xinerama_query_screens_reply(
xcb->connection, screens_cookie, NULL);
569 xcb_xinerama_screen_info_iterator_t screens_iterator =
570 xcb_xinerama_query_screens_screen_info_iterator(screens_reply);
572 for (; screens_iterator.rem > 0;
573 xcb_xinerama_screen_info_next(&screens_iterator)) {
576 w->
x = screens_iterator.data->x_org;
577 w->
y = screens_iterator.data->y_org;
578 w->
w = screens_iterator.data->width;
579 w->
h = screens_iterator.data->height;
586 for (
workarea *iter =
xcb->monitors; iter; iter = iter->next) {
587 iter->monitor_id = index++;
601 g_debug(
"Query XINERAMA for monitor layout.");
605 g_debug(
"No RANDR or Xinerama available for getting monitor layout.");
608 g_debug(
"Query RANDR for monitor layout.");
610 g_debug(
"Randr XCB api version: %d.%d.", XCB_RANDR_MAJOR_VERSION,
611 XCB_RANDR_MINOR_VERSION);
612#if (((XCB_RANDR_MAJOR_VERSION == RANDR_PREF_MAJOR_VERSION) && \
613 (XCB_RANDR_MINOR_VERSION >= RANDR_PREF_MINOR_VERSION)) || \
614 XCB_RANDR_MAJOR_VERSION > RANDR_PREF_MAJOR_VERSION)
615 xcb_randr_query_version_cookie_t cversion = xcb_randr_query_version(
617 xcb_randr_query_version_reply_t *rversion =
618 xcb_randr_query_version_reply(
xcb->connection, cversion, NULL);
620 g_debug(
"Found randr version: %d.%d", rversion->major_version,
621 rversion->minor_version);
626 xcb_randr_get_monitors_cookie_t t =
627 xcb_randr_get_monitors(
xcb->connection,
xcb->screen->root, 1);
628 xcb_randr_get_monitors_reply_t *mreply =
629 xcb_randr_get_monitors_reply(
xcb->connection, t, NULL);
631 xcb_randr_monitor_info_iterator_t iter =
632 xcb_randr_get_monitors_monitors_iterator(mreply);
633 while (iter.rem > 0) {
634 workarea *w = x11_get_monitor_from_randr_monitor(iter.data);
639 xcb_randr_monitor_info_next(&iter);
649 if (
xcb->monitors == NULL) {
650 xcb_randr_get_screen_resources_current_reply_t *res_reply;
651 xcb_randr_get_screen_resources_current_cookie_t src;
652 src = xcb_randr_get_screen_resources_current(
xcb->connection,
654 res_reply = xcb_randr_get_screen_resources_current_reply(
xcb->connection,
660 xcb_randr_get_screen_resources_current_outputs_length(res_reply);
661 xcb_randr_output_t *ops =
662 xcb_randr_get_screen_resources_current_outputs(res_reply);
665 xcb_randr_get_output_primary_cookie_t pc =
666 xcb_randr_get_output_primary(
xcb->connection,
xcb->screen->root);
667 xcb_randr_get_output_primary_reply_t *pc_rep =
668 xcb_randr_get_output_primary_reply(
xcb->connection, pc, NULL);
670 for (
int i = mon_num - 1; i >= 0; i--) {
675 if (pc_rep && pc_rep->output == ops[i]) {
689 for (
workarea *iter =
xcb->monitors; iter; iter = iter->next) {
690 iter->monitor_id = index++;
695 int is_term = isatty(fileno(stdout));
696 printf(
"Monitor layout:\n");
697 for (
workarea *iter =
xcb->monitors; iter; iter = iter->next) {
698 printf(
"%s ID%s: %d", (is_term) ?
color_bold :
"",
701 printf(
" (primary)");
704 printf(
"%s name%s: %s\n", (is_term) ?
color_bold :
"",
706 printf(
"%s position%s: %d,%d\n", (is_term) ?
color_bold :
"",
708 printf(
"%s size%s: %d,%d\n", (is_term) ?
color_bold :
"",
710 if (iter->mw > 0 && iter->mh > 0) {
711 printf(
"%s size%s: %dmm,%dmm dpi: %.0f,%.0f\n",
713 iter->mh, iter->w * 25.4 / (
double)iter->mw,
714 iter->h * 25.4 / (
double)iter->mh);
721 GSpawnChildSetupFunc *child_setup,
722 gpointer *user_data) {
723 if (context == NULL) {
727 SnLauncherContext *sncontext;
729 sncontext = sn_launcher_context_new(
xcb->sndisplay,
xcb->screen_nbr);
731 sn_launcher_context_set_name(sncontext, context->
name);
732 sn_launcher_context_set_description(sncontext, context->
description);
733 if (context->
binary != NULL) {
734 sn_launcher_context_set_binary_name(sncontext, context->
binary);
736 if (context->
icon != NULL) {
737 sn_launcher_context_set_icon_name(sncontext, context->
icon);
739 if (context->
app_id != NULL) {
742 if (context->
wmclass != NULL) {
743 sn_launcher_context_set_wmclass(sncontext, context->
wmclass);
746 xcb_get_property_cookie_t c;
747 unsigned int current_desktop = 0;
749 c = xcb_ewmh_get_current_desktop(&
xcb->ewmh,
xcb->screen_nbr);
750 if (xcb_ewmh_get_current_desktop_reply(&
xcb->ewmh, c, ¤t_desktop,
752 sn_launcher_context_set_workspace(sncontext, current_desktop);
755 sn_launcher_context_initiate(sncontext,
"rofi", context->
command,
756 xcb->last_timestamp);
758 *child_setup = (GSpawnChildSetupFunc)sn_launcher_context_setup_child_process;
759 *user_data = sncontext;
764 mon->w =
xcb->screen->width_in_pixels;
765 mon->h =
xcb->screen->height_in_pixels;
768 for (iter =
xcb->monitors; iter; iter = iter->
next) {
779 g_error(
"%s: mon == NULL", __func__);
783 mon->w =
xcb->screen->width_in_pixels;
784 mon->h =
xcb->screen->height_in_pixels;
786 for (
workarea *iter =
xcb->monitors; iter; iter = iter->next) {
787 if (
INTERSECT(x, y, iter->x, iter->y, iter->w, iter->h)) {
807 xcb_query_pointer_cookie_t c = xcb_query_pointer(
xcb->connection, root);
808 xcb_query_pointer_reply_t *r =
809 xcb_query_pointer_reply(
xcb->connection, c, NULL);
822 g_error(
"%s: mon == NULL", __func__);
825 xcb_window_t root =
xcb->screen->root;
826 xcb_get_geometry_cookie_t c = xcb_get_geometry(
xcb->connection,
id);
827 xcb_get_geometry_reply_t *r =
828 xcb_get_geometry_reply(
xcb->connection, c, NULL);
830 xcb_translate_coordinates_cookie_t ct =
831 xcb_translate_coordinates(
xcb->connection,
id, root, r->x, r->y);
832 xcb_translate_coordinates_reply_t *t =
833 xcb_translate_coordinates_reply(
xcb->connection, ct, NULL);
838 mon->x = t->dst_x - r->x;
839 mon->y = t->dst_y - r->y;
852 xcb_window_t active_window;
853 xcb_get_property_cookie_t awc;
855 g_error(
"%s: mon == NULL", __func__);
858 awc = xcb_ewmh_get_active_window(&
xcb->ewmh,
xcb->screen_nbr);
859 if (!xcb_ewmh_get_active_window_reply(&
xcb->ewmh, awc, &active_window,
862 "Failed to get active window, falling back to mouse location (-5).");
865 xcb_query_tree_cookie_t tree_cookie =
866 xcb_query_tree(
xcb->connection, active_window);
867 xcb_query_tree_reply_t *tree_reply =
868 xcb_query_tree_reply(
xcb->connection, tree_cookie, NULL);
871 "Failed to get parent window, falling back to mouse location (-5).");
875 xcb_get_geometry_cookie_t c =
876 xcb_get_geometry(
xcb->connection, active_window);
877 xcb_get_geometry_reply_t *r =
878 xcb_get_geometry_reply(
xcb->connection, c, NULL);
880 g_debug(
"Failed to get geometry of active window, falling back to mouse "
885 if (tree_reply->parent != r->root) {
886 xcb_translate_coordinates_cookie_t ct = xcb_translate_coordinates(
887 xcb->connection, tree_reply->parent, r->root, r->x, r->y);
888 xcb_translate_coordinates_reply_t *t =
889 xcb_translate_coordinates_reply(
xcb->connection, ct, NULL);
895 g_debug(
"Failed to get translate position of active window, falling back "
896 "to mouse location (-5).");
906 mon->x = r->x + r->border_width;
907 mon->y = r->y + r->border_width;
911 }
else if (mon_id == -4) {
912 g_debug(
"Find monitor at location: %d %d", r->x, r->y);
916 g_debug(
"mon pos: %d %d %d-%d",
mon->x,
mon->y,
mon->w,
mon->h);
922 xcb_window_t root =
xcb->screen->root;
925 g_error(
"%s: mon == NULL", __func__);
928 g_debug(
"Monitor id: %d", mon_id);
939 else if (mon_id == -1) {
940 g_debug(
"rofi on current monitor");
942 unsigned int current_desktop = 0;
943 xcb_get_property_cookie_t gcdc;
944 gcdc = xcb_ewmh_get_current_desktop(&
xcb->ewmh,
xcb->screen_nbr);
945 if (xcb_ewmh_get_current_desktop_reply(&
xcb->ewmh, gcdc, ¤t_desktop,
947 g_debug(
"Found current desktop: %u", current_desktop);
948 xcb_get_property_cookie_t c =
949 xcb_ewmh_get_desktop_viewport(&
xcb->ewmh,
xcb->screen_nbr);
950 xcb_ewmh_get_desktop_viewport_reply_t vp;
951 if (xcb_ewmh_get_desktop_viewport_reply(&
xcb->ewmh, c, &vp, NULL)) {
952 g_debug(
"Found %d number of desktops", vp.desktop_viewport_len);
953 if (current_desktop < vp.desktop_viewport_len) {
954 g_debug(
"Found viewport for desktop: %d %d",
955 vp.desktop_viewport[current_desktop].x,
956 vp.desktop_viewport[current_desktop].y);
958 vp.desktop_viewport[current_desktop].y,
mon);
959 g_debug(
"Found monitor @: %d %d %dx%d",
mon->x,
mon->y,
mon->w,
961 xcb_ewmh_get_desktop_viewport_reply_wipe(&vp);
964 g_debug(
"Viewport does not exist for current desktop: %d, falling "
965 "back to mouse location (-5)",
967 xcb_ewmh_get_desktop_viewport_reply_wipe(&vp);
969 g_debug(
"Failed to get viewport for current desktop: %d, falling back "
970 "to mouse location (-5).",
974 g_debug(
"Failed to get current desktop, falling back to mouse location "
977 }
else if (mon_id == -2 || mon_id == -4) {
983 else if (mon_id == -5) {
991 g_debug(
"Failed to find monitor, fall back to monitor showing mouse.");
1005 g_error(
"%s: mon == NULL", __func__);
1008 g_debug(
"Monitor active");
1013 if (
config.monitor != NULL) {
1014 g_debug(
"Monitor lookup by name : %s",
config.monitor);
1015 for (
workarea *iter =
xcb->monitors; iter; iter = iter->next) {
1016 if (g_strcmp0(
config.monitor, iter->name) == 0) {
1024 g_debug(
"Monitor lookup by name failed: %s",
config.monitor);
1026 if (g_strcmp0(
config.monitor,
"primary") == 0) {
1027 for (
workarea *iter =
xcb->monitors; iter; iter = iter->next) {
1028 if (iter->primary) {
1036 if (g_str_has_prefix(
config.monitor,
"wid:")) {
1038 xcb_drawable_t win = g_ascii_strtoll(
config.monitor + 4, &end, 0);
1039 if (end !=
config.monitor) {
1050 gint64 mon_id = g_ascii_strtoll(
config.monitor, &end, 0);
1051 if (end !=
config.monitor) {
1058 g_warning(
"Failed to find selected monitor.");
1075 xcb_get_atom_name_cookie_t cookie;
1076 xcb_get_atom_name_reply_t *reply;
1085 cookie = xcb_get_atom_name(conn, atom);
1086 reply = xcb_get_atom_name_reply(conn, cookie, NULL);
1090 length = xcb_get_atom_name_name_length(reply);
1091 name = xcb_get_atom_name_name(reply);
1093 (*out) = g_strndup(name, length);
1110 xcb_selection_notify_event_t *xse) {
1111 if (xse->property == XCB_ATOM_NONE) {
1112 g_debug(
"Failed to convert selection");
1113 }
else if (xse->property ==
xcb->ewmh.UTF8_STRING) {
1115 if (text != NULL && text[0] !=
'\0') {
1116 unsigned int dl = strlen(text);
1118 for (
unsigned int i = 0; i < dl; i++) {
1119 if (text[i] ==
'\n') {
1129 g_debug(
"rofi_view_paste: Got unknown atom: %s", out);
1132 g_debug(
"rofi_view_paste: Got unknown, unnamed: %s", out);
1139 NkBindingsMouseButton *button) {
1140 switch (x11_button) {
1142 *button = NK_BINDINGS_MOUSE_BUTTON_PRIMARY;
1145 *button = NK_BINDINGS_MOUSE_BUTTON_SECONDARY;
1148 *button = NK_BINDINGS_MOUSE_BUTTON_MIDDLE;
1151 *button = NK_BINDINGS_MOUSE_BUTTON_BACK;
1154 *button = NK_BINDINGS_MOUSE_BUTTON_FORWARD;
1162 *button = NK_BINDINGS_MOUSE_BUTTON_EXTRA + x11_button;
1168 NkBindingsScrollAxis *axis,
1171 switch (x11_button) {
1176 *axis = NK_BINDINGS_SCROLL_AXIS_VERTICAL;
1182 *axis = NK_BINDINGS_SCROLL_AXIS_HORIZONTAL;
1193 g_log(
"IMDKit", G_LOG_LEVEL_DEBUG,
"press handler %d", xkpe->detail);
1195 xcb->last_timestamp = xkpe->time;
1196 if (
config.xserver_i300_workaround) {
1197 text = nk_bindings_seat_handle_key_with_modmask(
1198 xcb->bindings_seat, NULL, xkpe->state, xkpe->detail,
1199 NK_BINDINGS_KEY_STATE_PRESS);
1201 text = nk_bindings_seat_handle_key(
xcb->bindings_seat, NULL, xkpe->detail,
1202 NK_BINDINGS_KEY_STATE_PRESS);
1212 g_log(
"IMDKit", G_LOG_LEVEL_DEBUG,
"release handler %d", xkre->detail);
1213 xcb->last_timestamp = xkre->time;
1214 nk_bindings_seat_handle_key(
xcb->bindings_seat, NULL, xkre->detail,
1215 NK_BINDINGS_KEY_STATE_RELEASE);
1223 if (state == NULL) {
1227 switch (event->response_type & ~0x80) {
1228 case XCB_CLIENT_MESSAGE: {
1229 xcb_client_message_event_t *cme = (xcb_client_message_event_t *)event;
1230 xcb_atom_t atom = cme->data.data32[0];
1231 xcb_timestamp_t
time = cme->data.data32[1];
1232 if (atom ==
netatoms[WM_TAKE_FOCUS]) {
1233 xcb_set_input_focus(
xcb->connection, XCB_INPUT_FOCUS_NONE, cme->window,
1235 xcb_flush(
xcb->connection);
1239 case XCB_DESTROY_NOTIFY: {
1240 xcb_window_t win = ((xcb_destroy_notify_event_t *)event)->window;
1243 window_client_handle_signal(win, FALSE);
1246 g_main_loop_quit(
xcb->main_loop);
1250 case XCB_CREATE_NOTIFY: {
1251 xcb_window_t win = ((xcb_create_notify_event_t *)event)->window;
1254 window_client_handle_signal(win, TRUE);
1262 case XCB_CONFIGURE_NOTIFY: {
1263 xcb_configure_notify_event_t *xce = (xcb_configure_notify_event_t *)event;
1267 case XCB_MOTION_NOTIFY: {
1268 xcb_motion_notify_event_t *xme = (xcb_motion_notify_event_t *)event;
1269 gboolean button_mask = xme->state & XCB_EVENT_MASK_BUTTON_1_MOTION;
1271 !button_mask &&
config.hover_select);
1274 case XCB_BUTTON_PRESS: {
1275 xcb_button_press_event_t *bpe = (xcb_button_press_event_t *)event;
1276 NkBindingsMouseButton button;
1277 NkBindingsScrollAxis axis;
1280 xcb->last_timestamp = bpe->time;
1283 nk_bindings_seat_handle_button(
xcb->bindings_seat, NULL, button,
1284 NK_BINDINGS_BUTTON_STATE_PRESS, bpe->time);
1286 nk_bindings_seat_handle_scroll(
xcb->bindings_seat, NULL, axis, steps);
1291 case XCB_SELECTION_CLEAR: {
1292 g_debug(
"Selection Clear.");
1295 case XCB_SELECTION_REQUEST: {
1296 g_debug(
"Selection Request.");
1297 xcb_selection_request_event_t *req = (xcb_selection_request_event_t *)event;
1298 if (req->selection ==
netatoms[CLIPBOARD]) {
1299 xcb_atom_t targets[2];
1300 xcb_selection_notify_event_t selection_notify = {
1301 .response_type = XCB_SELECTION_NOTIFY,
1304 .requestor = req->requestor,
1305 .selection = req->selection,
1306 .target = req->target,
1307 .property = XCB_ATOM_NONE,
1310 if (
xcb->clipboard) {
1312 if (req->target ==
netatoms[UTF8_STRING]) {
1313 g_debug(
"Selection Request UTF-8.");
1314 xcb_change_property(
xcb->connection, XCB_PROP_MODE_REPLACE,
1315 req->requestor, req->property,
1317 strlen(
xcb->clipboard) + 1,
xcb->clipboard);
1318 selection_notify.property = req->property;
1319 }
else if (req->target ==
netatoms[TARGETS]) {
1320 g_debug(
"Selection Request Targets.");
1322 targets[0] =
netatoms[UTF8_STRING];
1323 xcb_change_property(
xcb->connection, XCB_PROP_MODE_REPLACE,
1324 req->requestor, req->property, XCB_ATOM_ATOM, 32,
1326 selection_notify.property = req->property;
1330 xcb_send_event(
xcb->connection,
1332 req->requestor, XCB_EVENT_MASK_NO_EVENT,
1333 (
const char *)&selection_notify);
1334 xcb_flush(
xcb->connection);
1337 case XCB_BUTTON_RELEASE: {
1338 xcb_button_release_event_t *bre = (xcb_button_release_event_t *)event;
1339 NkBindingsMouseButton button;
1341 xcb->last_timestamp = bre->time;
1343 nk_bindings_seat_handle_button(
xcb->bindings_seat, NULL, button,
1344 NK_BINDINGS_BUTTON_STATE_RELEASE,
1347 if (
config.click_to_exit == TRUE) {
1348 if (!
xcb->mouse_seen) {
1356 case XCB_SELECTION_NOTIFY:
1359 case XCB_KEYMAP_NOTIFY: {
1360 xcb_keymap_notify_event_t *kne = (xcb_keymap_notify_event_t *)event;
1361 for (gint32 by = 0; by < 31; ++by) {
1362 for (gint8 bi = 0; bi < 7; ++bi) {
1363 if (kne->keys[by] & (1 << bi)) {
1365 nk_bindings_seat_handle_key(
xcb->bindings_seat, NULL,
1367 NK_BINDINGS_KEY_STATE_PRESSED);
1373 case XCB_KEY_PRESS: {
1374 xcb_key_press_event_t *xkpe = (xcb_key_press_event_t *)event;
1377 g_log(
"IMDKit", G_LOG_LEVEL_DEBUG,
"press key %d to xim", xkpe->detail);
1378 xcb_xim_forward_event(
xcb->im,
xcb->ic, xkpe);
1387 case XCB_KEY_RELEASE: {
1388 xcb_key_release_event_t *xkre = (xcb_key_release_event_t *)event;
1391 g_log(
"IMDKit", G_LOG_LEVEL_DEBUG,
"release key %d to xim", xkre->detail);
1397 xcb_keysym_t sym = xcb_key_press_lookup_keysym(
xcb->syms, xkre, 0);
1398 if (xcb_is_modifier_key(sym)) {
1399 struct timespec five_millis = {.tv_sec = 0, .tv_nsec = 5000000};
1400 nanosleep(&five_millis, NULL);
1402 xcb_xim_forward_event(
xcb->im,
xcb->ic, xkre);
1418void x11_event_handler_fowarding(G_GNUC_UNUSED xcb_xim_t *im,
1419 G_GNUC_UNUSED xcb_xic_t ic,
1420 xcb_key_press_event_t *event,
1421 G_GNUC_UNUSED
void *user_data) {
1423 if (state == NULL) {
1427 uint8_t type =
event->response_type & ~0x80;
1428 if (type == XCB_KEY_PRESS) {
1430 }
else if (type == XCB_KEY_RELEASE) {
1431 xcb_key_release_event_t *xkre = (xcb_key_release_event_t *)event;
1439 G_GNUC_UNUSED gpointer user_data) {
1441 int status = xcb_connection_has_error(
xcb->connection);
1443 g_warning(
"The XCB connection to X server had a fatal error: %d", status);
1444 g_main_loop_quit(
xcb->main_loop);
1445 return G_SOURCE_REMOVE;
1451 return G_SOURCE_CONTINUE;
1455 if (
config.enable_imdkit &&
xcb->im && xcb_xim_filter_event(
xcb->im, ev))
1456 return G_SOURCE_CONTINUE;
1459 uint8_t type = ev->response_type & ~0x80;
1460 if (type ==
xcb->xkb.first_event) {
1462 case XCB_XKB_MAP_NOTIFY: {
1463 struct xkb_keymap *keymap = xkb_x11_keymap_new_from_device(
1464 nk_bindings_seat_get_context(
xcb->bindings_seat),
xcb->connection,
1465 xcb->xkb.device_id, 0);
1466 struct xkb_state *state = xkb_x11_state_new_from_device(
1467 keymap,
xcb->connection,
xcb->xkb.device_id);
1468 nk_bindings_seat_update_keymap(
xcb->bindings_seat, keymap, state);
1469 xkb_keymap_unref(keymap);
1470 xkb_state_unref(state);
1473 case XCB_XKB_STATE_NOTIFY: {
1474 xcb_xkb_state_notify_event_t *ksne = (xcb_xkb_state_notify_event_t *)ev;
1475 nk_bindings_seat_update_mask(
xcb->bindings_seat, NULL, ksne->baseMods,
1476 ksne->latchedMods, ksne->lockedMods,
1477 ksne->baseGroup, ksne->latchedGroup,
1483 return G_SOURCE_CONTINUE;
1485 if (
xcb->sndisplay != NULL) {
1486 sn_xcb_display_process_event(
xcb->sndisplay, ev);
1490 return G_SOURCE_CONTINUE;
1494 if (
config.steal_focus != TRUE) {
1495 xcb->focus_revert = 0;
1498 xcb_generic_error_t *error;
1499 xcb_get_input_focus_reply_t *freply;
1500 xcb_get_input_focus_cookie_t fcookie = xcb_get_input_focus(
xcb->connection);
1501 freply = xcb_get_input_focus_reply(
xcb->connection, fcookie, &error);
1502 if (error != NULL) {
1503 g_warning(
"Could not get input focus (error %d), will revert focus to best "
1507 xcb->focus_revert = 0;
1509 xcb->focus_revert = freply->focus;
1511 xcb_set_input_focus(
xcb->connection, XCB_INPUT_FOCUS_POINTER_ROOT, w,
1513 xcb_flush(
xcb->connection);
1517 if (
xcb->focus_revert == 0) {
1521 xcb_set_input_focus(
xcb->connection, XCB_INPUT_FOCUS_POINTER_ROOT,
1522 xcb->focus_revert, XCB_CURRENT_TIME);
1523 xcb_flush(
xcb->connection);
1529 if (xcb_connection_has_error(
xcb->connection)) {
1530 g_warning(
"Connection has error");
1533 xcb_grab_pointer_cookie_t cc =
1534 xcb_grab_pointer(
xcb->connection, 1, w, XCB_EVENT_MASK_BUTTON_RELEASE,
1535 XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, w, XCB_NONE,
1537 xcb_grab_pointer_reply_t *r =
1538 xcb_grab_pointer_reply(
xcb->connection, cc, NULL);
1540 if (r->status == XCB_GRAB_STATUS_SUCCESS) {
1546 if ((++i) > iters) {
1549 struct timespec del = {.tv_sec = 0, .tv_nsec = 1000000};
1550 nanosleep(&del, NULL);
1558 if (xcb_connection_has_error(
xcb->connection)) {
1559 g_warning(
"Connection has error");
1562 xcb_grab_keyboard_cookie_t cc =
1563 xcb_grab_keyboard(
xcb->connection, 1, w, XCB_CURRENT_TIME,
1564 XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
1565 xcb_grab_keyboard_reply_t *r =
1566 xcb_grab_keyboard_reply(
xcb->connection, cc, NULL);
1568 if (r->status == XCB_GRAB_STATUS_SUCCESS) {
1574 if ((++i) > iters) {
1577 struct timespec del = {.tv_sec = 0, .tv_nsec = 1000000};
1578 nanosleep(&del, NULL);
1584 xcb_ungrab_keyboard(
xcb->connection, XCB_CURRENT_TIME);
1587 xcb_ungrab_pointer(
xcb->connection, XCB_CURRENT_TIME);
1593 G_GNUC_UNUSED xcb_connection_t *xdisplay) {
1598 xcb_connection_t *xdisplay) {
1600 g_warning(
"Error trap underflow!");
1604 xcb_flush(xdisplay);
1614 xcb_intern_atom_cookie_t cc = xcb_intern_atom(
1616 xcb_intern_atom_reply_t *r =
1617 xcb_intern_atom_reply(
xcb->connection, cc, NULL);
1627 xcb_window_t wm_win = 0;
1628 xcb_get_property_cookie_t cc = xcb_ewmh_get_supporting_wm_check_unchecked(
1631 if (xcb_ewmh_get_supporting_wm_check_reply(&
xcb->ewmh, cc, &wm_win, NULL)) {
1632 xcb_ewmh_get_utf8_strings_reply_t wtitle;
1633 xcb_get_property_cookie_t cookie =
1634 xcb_ewmh_get_wm_name_unchecked(&(
xcb->ewmh), wm_win);
1635 if (xcb_ewmh_get_wm_name_reply(&(
xcb->ewmh), cookie, &wtitle, (
void *)0)) {
1636 if (wtitle.strings_len > 0) {
1637 retv = g_strndup(wtitle.strings, wtitle.strings_len);
1639 xcb_ewmh_get_utf8_strings_reply_wipe(&wtitle);
1646 xcb_window_t wm_win = 0;
1647 xcb_get_property_cookie_t cc = xcb_ewmh_get_supporting_wm_check_unchecked(
1650 if (xcb_ewmh_get_supporting_wm_check_reply(&
xcb->ewmh, cc, &wm_win, NULL)) {
1651 xcb_ewmh_get_utf8_strings_reply_t wtitle;
1652 xcb_get_property_cookie_t cookie =
1653 xcb_ewmh_get_wm_name_unchecked(&(
xcb->ewmh), wm_win);
1654 if (xcb_ewmh_get_wm_name_reply(&(
xcb->ewmh), cookie, &wtitle, (
void *)0)) {
1655 if (wtitle.strings_len > 0) {
1657 char *str = g_strndup(wtitle.strings, wtitle.strings_len);
1658 g_debug(
"Found window manager: |%s|", str);
1659 if (g_strcmp0(str,
"i3") == 0) {
1665 xcb_ewmh_get_utf8_strings_reply_wipe(&wtitle);
1673 char *display_str = (
char *)g_getenv(
"DISPLAY");
1678 if (
config.enable_imdkit) {
1679 xcb_compound_text_init();
1682 xcb->source = g_water_xcb_source_new(g_main_loop_get_context(
xcb->main_loop),
1683 display_str, &
xcb->screen_nbr,
1685 if (
xcb->source == NULL) {
1686 g_warning(
"Failed to open display: %s", display_str);
1689 xcb->connection = g_water_xcb_source_get_connection(
xcb->source);
1691 if (
config.enable_imdkit) {
1692 xcb->im = xcb_xim_create(
xcb->connection,
xcb->screen_nbr, NULL);
1693 xcb->syms = xcb_key_symbols_alloc(
xcb->connection);
1701#ifndef XCB_IMDKIT_1_0_3_LOWER
1702 if (
config.enable_imdkit) {
1703 xcb_xim_set_use_compound_text(
xcb->im,
true);
1704 xcb_xim_set_use_utf8_string(
xcb->im,
true);
1711 xcb->screen = xcb_aux_get_screen(
xcb->connection,
xcb->screen_nbr);
1715 xcb_intern_atom_cookie_t *ac =
1716 xcb_ewmh_init_atoms(
xcb->connection, &
xcb->ewmh);
1717 xcb_generic_error_t *errors = NULL;
1718 xcb_ewmh_init_atoms_replies(&
xcb->ewmh, ac, &errors);
1720 g_warning(
"Failed to create EWMH atoms");
1727 if (xkb_x11_setup_xkb_extension(
1728 xcb->connection, XKB_X11_MIN_MAJOR_XKB_VERSION,
1729 XKB_X11_MIN_MINOR_XKB_VERSION, XKB_X11_SETUP_XKB_EXTENSION_NO_FLAGS,
1730 NULL, NULL, &
xcb->xkb.first_event, NULL) < 0) {
1731 g_warning(
"cannot setup XKB extension!");
1735 xcb->xkb.device_id = xkb_x11_get_core_keyboard_device_id(
xcb->connection);
1739 (XCB_XKB_EVENT_TYPE_NEW_KEYBOARD_NOTIFY |
1740 XCB_XKB_EVENT_TYPE_MAP_NOTIFY | XCB_XKB_EVENT_TYPE_STATE_NOTIFY),
1742 required_nkn_details = (XCB_XKB_NKN_DETAIL_KEYCODES),
1744 required_map_parts =
1745 (XCB_XKB_MAP_PART_KEY_TYPES | XCB_XKB_MAP_PART_KEY_SYMS |
1746 XCB_XKB_MAP_PART_MODIFIER_MAP | XCB_XKB_MAP_PART_EXPLICIT_COMPONENTS |
1747 XCB_XKB_MAP_PART_KEY_ACTIONS | XCB_XKB_MAP_PART_VIRTUAL_MODS |
1748 XCB_XKB_MAP_PART_VIRTUAL_MOD_MAP),
1750 required_state_details =
1751 (XCB_XKB_STATE_PART_MODIFIER_BASE | XCB_XKB_STATE_PART_MODIFIER_LATCH |
1752 XCB_XKB_STATE_PART_MODIFIER_LOCK | XCB_XKB_STATE_PART_GROUP_BASE |
1753 XCB_XKB_STATE_PART_GROUP_LATCH | XCB_XKB_STATE_PART_GROUP_LOCK),
1756 static const xcb_xkb_select_events_details_t details = {
1757 .affectNewKeyboard = required_nkn_details,
1758 .newKeyboardDetails = required_nkn_details,
1759 .affectState = required_state_details,
1760 .stateDetails = required_state_details,
1762 xcb_xkb_select_events(
xcb->connection,
xcb->xkb.device_id,
1770 xcb->bindings_seat = nk_bindings_seat_new(
bindings, XKB_CONTEXT_NO_FLAGS);
1771 struct xkb_keymap *keymap = xkb_x11_keymap_new_from_device(
1772 nk_bindings_seat_get_context(
xcb->bindings_seat),
xcb->connection,
1773 xcb->xkb.device_id, XKB_KEYMAP_COMPILE_NO_FLAGS);
1774 if (keymap == NULL) {
1775 g_warning(
"Failed to get Keymap for current keyboard device.");
1778 struct xkb_state *state = xkb_x11_state_new_from_device(
1779 keymap,
xcb->connection,
xcb->xkb.device_id);
1780 if (state == NULL) {
1781 g_warning(
"Failed to get state object for current keyboard device.");
1785 nk_bindings_seat_update_keymap(
xcb->bindings_seat, keymap, state);
1786 xkb_state_unref(state);
1787 xkb_keymap_unref(keymap);
1792 if (xcb_connection_has_error(
xcb->connection)) {
1793 g_warning(
"Connection has error");
1797 uint32_t val[] = {XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY};
1800 XCB_CW_EVENT_MASK, val);
1805 if (xcb_connection_has_error(
xcb->connection)) {
1806 g_warning(
"Connection has error");
1810 if (
xcb->sndisplay != NULL) {
1811 xcb->sncontext = sn_launchee_context_new_from_environment(
xcb->sndisplay,
1814 if (xcb_connection_has_error(
xcb->connection)) {
1815 g_warning(
"Connection has error");
1823 xcb_depth_t *root_depth = NULL;
1824 xcb_depth_iterator_t depth_iter;
1825 for (depth_iter = xcb_screen_allowed_depths_iterator(
xcb->screen);
1826 depth_iter.rem; xcb_depth_next(&depth_iter)) {
1827 xcb_depth_t *d = depth_iter.data;
1829 xcb_visualtype_iterator_t visual_iter;
1830 for (visual_iter = xcb_depth_visuals_iterator(d); visual_iter.rem;
1831 xcb_visualtype_next(&visual_iter)) {
1832 xcb_visualtype_t *v = visual_iter.data;
1833 if ((v->bits_per_rgb_value == 8) && (d->depth == 32) &&
1834 (v->_class == XCB_VISUAL_CLASS_TRUE_COLOR)) {
1838 if (
xcb->screen->root_visual == v->visual_id) {
1845 xcb_void_cookie_t c;
1846 xcb_generic_error_t *e;
1847 map = xcb_generate_id(
xcb->connection);
1848 c = xcb_create_colormap_checked(
xcb->connection, XCB_COLORMAP_ALLOC_NONE,
1850 e = xcb_request_check(
xcb->connection, c);
1861 map =
xcb->screen->default_colormap;
1866 xcb_cursor_context_t *ctx;
1868 if (xcb_cursor_context_new(
xcb->connection,
xcb->screen, &ctx) < 0) {
1875 if (
cursors[i] == XCB_CURSOR_NONE) {
1881 xcb_cursor_context_free(ctx);
1891 g_warning(
"Failed to grab pointer after %u times. Giving up.",
1893 return G_SOURCE_REMOVE;
1896 return G_SOURCE_REMOVE;
1899 return G_SOURCE_CONTINUE;
1904 g_warning(
"Failed to grab keyboard after %u times. Giving up.",
1906 g_main_loop_quit(
xcb->main_loop);
1907 return G_SOURCE_REMOVE;
1910 return G_SOURCE_REMOVE;
1913 return G_SOURCE_CONTINUE;
1927 if (
find_arg(
"-normal-window") >= 0 ||
find_arg(
"-transient-window") >= 0) {
1930 if (
find_arg(
"-no-lazy-grab") >= 0) {
1932 g_warning(
"Failed to grab keyboard, even after %d uS.", 500 * 1000);
1936 g_warning(
"Failed to grab mouse pointer, even after %d uS.", 100 * 1000);
1954 xcb_flush(
xcb->connection);
1958 if (
xcb->connection == NULL) {
1962 g_debug(
"Cleaning up XCB and XKB");
1964 nk_bindings_seat_free(
xcb->bindings_seat);
1965 if (
xcb->sncontext != NULL) {
1966 sn_launchee_context_unref(
xcb->sncontext);
1967 xcb->sncontext = NULL;
1969 if (
xcb->sndisplay != NULL) {
1970 sn_display_unref(
xcb->sndisplay);
1971 xcb->sndisplay = NULL;
1974 xcb_ewmh_connection_wipe(&(
xcb->ewmh));
1975 xcb_flush(
xcb->connection);
1976 xcb_aux_sync(
xcb->connection);
1978 if (
config.enable_imdkit) {
1979 xcb_xim_close(
xcb->im);
1980 xcb_xim_destroy(
xcb->im);
1984 g_water_xcb_source_free(
xcb->source);
1986 xcb->connection = NULL;
1988 xcb->screen_nbr = 0;
1993 const uint32_t MWM_HINTS_DECORATIONS = (1 << 1);
1995 struct MotifWMHints {
1998 uint32_t decorations;
2003 struct MotifWMHints hints;
2004 hints.flags = MWM_HINTS_DECORATIONS;
2005 hints.decorations = 0;
2006 hints.functions = 0;
2007 hints.inputMode = 0;
2010 xcb_atom_t ha =
netatoms[_MOTIF_WM_HINTS];
2011 xcb_change_property(
xcb->connection, XCB_PROP_MODE_REPLACE, window, ha, ha,
2020 if (
cursors[type] == XCB_CURSOR_NONE) {
2024 xcb_change_window_attributes(
xcb->connection, window, XCB_CW_CURSOR,
2028 g_free(
xcb->clipboard);
2029 xcb->clipboard = data;
char * rofi_latin_to_utf8_strdup(const char *input, gssize length)
int find_arg_str(const char *const key, char **val)
int find_arg(const char *const key)
xcb_window_t rofi_view_get_window(void)
RofiViewState * rofi_view_get_active(void)
void rofi_view_handle_text(RofiViewState *state, char *text)
void rofi_view_handle_mouse_motion(RofiViewState *state, gint x, gint y, gboolean find_mouse_target)
void rofi_view_temp_click_to_exit(RofiViewState *state, xcb_window_t target)
void rofi_view_temp_configure_notify(RofiViewState *state, xcb_configure_notify_event_t *xce)
void rofi_view_frame_callback(void)
void rofi_view_maybe_update(RofiViewState *state)
const gchar * description
gboolean display_late_setup(void)
static int take_pointer(xcb_window_t w, int iters)
int monitor_active(workarea *mon)
const struct @254216062057302043141351367375126251201145221037 cursor_names[]
#define RANDR_PREF_MAJOR_VERSION
const char * traditional_name
void display_early_cleanup(void)
static int x11_is_extension_present(const char *extension)
static gboolean lazy_grab_pointer(G_GNUC_UNUSED gpointer data)
static void x11_workarea_fix_rotation(workarea *w)
void display_startup_notification(RofiHelperExecuteContext *context, GSpawnChildSetupFunc *child_setup, gpointer *user_data)
cairo_surface_t * x11_helper_get_screenshot_surface(void)
static void x11_build_monitor_layout(void)
char * window_get_text_prop(xcb_window_t w, xcb_atom_t atom)
void display_cleanup(void)
static xcb_pixmap_t get_root_pixmap(xcb_connection_t *c, xcb_screen_t *screen, xcb_atom_t atom)
static void release_pointer(void)
static bool get_atom_name(xcb_connection_t *conn, xcb_atom_t atom, char **out)
struct _xcb_stuff xcb_int
static int monitor_active_from_winid(xcb_drawable_t id, workarea *mon)
static void x11_create_visual_and_colormap(void)
static gboolean x11_button_to_nk_bindings_scroll(guint32 x11_button, NkBindingsScrollAxis *axis, gint32 *steps)
static void monitor_dimensions(int x, int y, workarea *mon)
void rofi_xcb_revert_input_focus(void)
cairo_surface_t * x11_helper_get_bg_surface(void)
static void x11_lookup_cursors(void)
void rofi_xcb_set_input_focus(xcb_window_t w)
static gboolean lazy_grab_keyboard(G_GNUC_UNUSED gpointer data)
#define INTERSECT(x, y, x1, y1, w1, h1)
static workarea * x11_get_monitor_from_output(xcb_randr_output_t out)
static void error_trap_pop(G_GNUC_UNUSED SnDisplay *display, xcb_connection_t *xdisplay)
void x11_set_cursor(xcb_window_t window, X11CursorType type)
static void x11_build_monitor_layout_xinerama(void)
static xcb_visualtype_t * lookup_visual(xcb_screen_t *s, xcb_visualid_t vis)
unsigned int lazy_grab_retry_count_pt
static xcb_visualtype_t * root_visual
static uint32_t * create_kernel(int radius, double deviation, uint32_t *sum2)
char * x11_helper_get_window_manager(void)
static void x11_create_frequently_used_atoms(void)
static int monitor_active_from_id_focused(int mon_id, workarea *mon)
void cairo_image_surface_blur(cairo_surface_t *surface, int radius, double deviation)
static gboolean x11_button_to_nk_bindings_button(guint32 x11_button, NkBindingsMouseButton *button)
xcb_cursor_t cursors[NUM_CURSORS]
static void x11_monitor_free(workarea *m)
static void x11_helper_discover_window_manager(void)
static int monitor_get_dimension(int monitor_id, workarea *mon)
static int take_keyboard(xcb_window_t w, int iters)
xcb_window_t xcb_stuff_get_root_window(void)
unsigned int lazy_grab_retry_count_kb
static void rofi_view_paste(RofiViewState *state, xcb_selection_notify_event_t *xse)
void window_set_atom_prop(xcb_window_t w, xcb_atom_t prop, xcb_atom_t *atoms, int count)
const char * netatom_names[]
static int monitor_active_from_id(int mon_id, workarea *mon)
static void x11_monitors_free(void)
gboolean display_setup(GMainLoop *main_loop, NkBindings *bindings)
void display_dump_monitor_layout(void)
static void error_trap_push(G_GNUC_UNUSED SnDisplay *display, G_GNUC_UNUSED xcb_connection_t *xdisplay)
WindowManagerQuirk current_window_manager
static int pointer_get(xcb_window_t root, int *x, int *y)
#define RANDR_PREF_MINOR_VERSION
#define sn_launcher_context_set_application_id
static void rofi_key_press_event_handler(xcb_key_press_event_t *xkpe, RofiViewState *state)
static void rofi_key_release_event_handler(xcb_key_release_event_t *xkre, G_GNUC_UNUSED RofiViewState *state)
void xcb_stuff_set_clipboard(char *data)
static int error_trap_depth
static void release_keyboard(void)
static gboolean main_loop_x11_event_handler(xcb_generic_event_t *ev, G_GNUC_UNUSED gpointer user_data)
void x11_disable_decoration(xcb_window_t window)
static void main_loop_x11_event_handler_view(xcb_generic_event_t *event)
xcb_atom_t netatoms[NUM_NETATOMS]
xcb_visualtype_t * visual
cairo_surface_t * x11_helper_get_screenshot_surface_window(xcb_window_t window, int size)
struct _xcb_stuff xcb_stuff
@ WM_PANGO_WORKSPACE_NAMES
@ WM_DO_NOT_CHANGE_CURRENT_DESKTOP
struct _workarea workarea