rofi  1.7.3
xcb.c
Go to the documentation of this file.
1 /*
2  * rofi
3  *
4  * MIT/X11 License
5  * Copyright © 2012 Sean Pringle <sean.pringle@gmail.com>
6  * Copyright © 2013-2021 Qball Cow <qball@gmpclient.org>
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  *
27  */
28 
30 #define G_LOG_DOMAIN "X11Helper"
31 
32 #include "config.h"
33 #include <cairo-xcb.h>
34 #include <cairo.h>
35 #include <glib.h>
36 #include <math.h>
37 #include <stdint.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #include <unistd.h>
42 #include <xcb/randr.h>
43 #include <xcb/xcb.h>
44 #include <xcb/xcb_aux.h>
45 #include <xcb/xcb_cursor.h>
46 #include <xcb/xcb_ewmh.h>
47 #include <xcb/xinerama.h>
48 #include <xcb/xkb.h>
49 #include <xcb/xproto.h>
50 #include <xkbcommon/xkbcommon-x11.h>
51 #include <xkbcommon/xkbcommon.h>
53 #define SN_API_NOT_YET_FROZEN
56 #define sn_launcher_context_set_application_id sn_launcher_set_application_id
57 #include "display.h"
58 #include "helper.h"
59 #include "rofi-types.h"
60 #include "settings.h"
61 #include "timings.h"
62 #include "xcb-internal.h"
63 #include "xcb.h"
64 #include <libsn/sn.h>
65 
66 #include "dialogs/window.h"
67 #include "mode.h"
68 
69 #include <rofi.h>
70 
72 #define RANDR_PREF_MAJOR_VERSION 1
74 #define RANDR_PREF_MINOR_VERSION 5
75 
77 #define INTERSECT(x, y, x1, y1, w1, h1) \
78  ((((x) >= (x1)) && ((x) < (x1 + w1))) && (((y) >= (y1)) && ((y) < (y1 + h1))))
79 
81 
85 struct _xcb_stuff xcb_int = {.connection = NULL,
86  .screen = NULL,
87  .screen_nbr = -1,
88  .sndisplay = NULL,
89  .sncontext = NULL,
90  .monitors = NULL};
92 
96 xcb_depth_t *depth = NULL;
97 xcb_visualtype_t *visual = NULL;
98 xcb_colormap_t map = XCB_COLORMAP_NONE;
102 static xcb_visualtype_t *root_visual = NULL;
103 xcb_atom_t netatoms[NUM_NETATOMS];
104 const char *netatom_names[] = {EWMH_ATOMS(ATOM_CHAR)};
105 
109 xcb_cursor_t cursors[NUM_CURSORS] = {XCB_CURSOR_NONE, XCB_CURSOR_NONE,
110  XCB_CURSOR_NONE};
111 
113 const struct {
115  const char *css_name;
117  const char *traditional_name;
118 } cursor_names[] = {
119  {"default", "left_ptr"}, {"pointer", "hand"}, {"text", "xterm"}};
120 
121 static xcb_visualtype_t *lookup_visual(xcb_screen_t *s, xcb_visualid_t visual) {
122  xcb_depth_iterator_t d;
123  d = xcb_screen_allowed_depths_iterator(s);
124  for (; d.rem; xcb_depth_next(&d)) {
125  xcb_visualtype_iterator_t v = xcb_depth_visuals_iterator(d.data);
126  for (; v.rem; xcb_visualtype_next(&v)) {
127  if (v.data->visual_id == visual) {
128  return v.data;
129  }
130  }
131  }
132  return 0;
133 }
134 
135 /* This blur function was originally created my MacSlow and published on his
136  * website: http://macslow.thepimp.net. I'm not entirely sure he's proud of it,
137  * but it has proved immeasurably useful for me. */
138 
139 static uint32_t *create_kernel(double radius, double deviation,
140  uint32_t *sum2) {
141  int size = 2 * (int)(radius) + 1;
142  uint32_t *kernel = (uint32_t *)(g_malloc(sizeof(uint32_t) * (size + 1)));
143  double radiusf = fabs(radius) + 1.0;
144  double value = -radius;
145  double sum = 0.0;
146  int i;
147 
148  if (deviation == 0.0) {
149  deviation = sqrt(-(radiusf * radiusf) / (2.0 * log(1.0 / 255.0)));
150  }
151 
152  kernel[0] = size;
153 
154  for (i = 0; i < size; i++) {
155  kernel[1 + i] = INT16_MAX / (2.506628275 * deviation) *
156  exp(-((value * value) / (2.0 * (deviation * deviation))));
157 
158  sum += kernel[1 + i];
159  value += 1.0;
160  }
161 
162  *sum2 = sum;
163 
164  return kernel;
165 }
166 
167 void cairo_image_surface_blur(cairo_surface_t *surface, double radius,
168  double deviation) {
169  uint32_t *horzBlur;
170  uint32_t *kernel = 0;
171  cairo_format_t format;
172  unsigned int channels;
173 
174  if (cairo_surface_status(surface)) {
175  return;
176  }
177 
178  uint8_t *data = cairo_image_surface_get_data(surface);
179  format = cairo_image_surface_get_format(surface);
180  const int width = cairo_image_surface_get_width(surface);
181  const int height = cairo_image_surface_get_height(surface);
182  const int stride = cairo_image_surface_get_stride(surface);
183 
184  if (format == CAIRO_FORMAT_ARGB32) {
185  channels = 4;
186  } else {
187  return;
188  }
189 
190  horzBlur = (uint32_t *)(g_malloc(sizeof(uint32_t) * height * stride));
191  TICK();
192  uint32_t sum = 0;
193  kernel = create_kernel(radius, deviation, &sum);
194  TICK_N("BLUR: kernel");
195 
196  /* Horizontal pass. */
197  uint32_t *horzBlur_ptr = horzBlur;
198  for (int iY = 0; iY < height; iY++) {
199  const int iYs = iY * stride;
200  for (int iX = 0; iX < width; iX++) {
201  uint32_t red = 0;
202  uint32_t green = 0;
203  uint32_t blue = 0;
204  uint32_t alpha = 0;
205  int offset = (int)(kernel[0]) / -2;
206 
207  for (int i = 0; i < (int)(kernel[0]); i++) {
208  int x = iX + offset;
209 
210  if (x < 0 || x >= width) {
211  offset++;
212  continue;
213  }
214 
215  uint8_t *dataPtr = &data[iYs + x * channels];
216  const uint32_t kernip1 = kernel[i + 1];
217 
218  blue += kernip1 * dataPtr[0];
219  green += kernip1 * dataPtr[1];
220  red += kernip1 * dataPtr[2];
221  alpha += kernip1 * dataPtr[3];
222  offset++;
223  }
224 
225  *horzBlur_ptr++ = blue / sum;
226  *horzBlur_ptr++ = green / sum;
227  *horzBlur_ptr++ = red / sum;
228  *horzBlur_ptr++ = alpha / sum;
229  }
230  }
231  TICK_N("BLUR: hori");
232 
233  /* Vertical pass. */
234  for (int iY = 0; iY < height; iY++) {
235  for (int iX = 0; iX < width; iX++) {
236  uint32_t red = 0;
237  uint32_t green = 0;
238  uint32_t blue = 0;
239  uint32_t alpha = 0;
240  int offset = (int)(kernel[0]) / -2;
241 
242  const int iXs = iX * channels;
243  for (int i = 0; i < (int)(kernel[0]); i++) {
244  int y = iY + offset;
245 
246  if (y < 0 || y >= height) {
247  offset++;
248  continue;
249  }
250 
251  uint32_t *dataPtr = &horzBlur[y * stride + iXs];
252  const uint32_t kernip1 = kernel[i + 1];
253 
254  blue += kernip1 * dataPtr[0];
255  green += kernip1 * dataPtr[1];
256  red += kernip1 * dataPtr[2];
257  alpha += kernip1 * dataPtr[3];
258 
259  offset++;
260  }
261 
262  *data++ = blue / sum;
263  *data++ = green / sum;
264  *data++ = red / sum;
265  *data++ = alpha / sum;
266  }
267  }
268  TICK_N("BLUR: vert");
269 
270  free(kernel);
271  free(horzBlur);
272 
273  return;
274 }
275 
276 cairo_surface_t *x11_helper_get_screenshot_surface_window(xcb_window_t window,
277  int size) {
278  xcb_get_geometry_cookie_t cookie;
279  xcb_get_geometry_reply_t *reply;
280 
281  cookie = xcb_get_geometry(xcb->connection, window);
282  reply = xcb_get_geometry_reply(xcb->connection, cookie, NULL);
283  if (reply == NULL) {
284  return NULL;
285  }
286 
287  xcb_get_window_attributes_cookie_t attributesCookie =
288  xcb_get_window_attributes(xcb->connection, window);
289  xcb_get_window_attributes_reply_t *attributes =
290  xcb_get_window_attributes_reply(xcb->connection, attributesCookie, NULL);
291  if (attributes == NULL || (attributes->map_state != XCB_MAP_STATE_VIEWABLE)) {
292  free(reply);
293  if (attributes) {
294  free(attributes);
295  }
296  return NULL;
297  }
298  // Create a cairo surface for the window.
299  xcb_visualtype_t *vt = lookup_visual(xcb->screen, attributes->visual);
300  free(attributes);
301 
302  cairo_surface_t *t = cairo_xcb_surface_create(xcb->connection, window, vt,
303  reply->width, reply->height);
304 
305  if (cairo_surface_status(t) != CAIRO_STATUS_SUCCESS) {
306  cairo_surface_destroy(t);
307  free(reply);
308  return NULL;
309  }
310 
311  // Scale the image, as we don't want to keep large one around.
312  int max = MAX(reply->width, reply->height);
313  double scale = (double)size / max;
314 
315  cairo_surface_t *s2 = cairo_surface_create_similar_image(
316  t, CAIRO_FORMAT_ARGB32, reply->width * scale, reply->height * scale);
317  free(reply);
318 
319  if (cairo_surface_status(s2) != CAIRO_STATUS_SUCCESS) {
320  cairo_surface_destroy(t);
321  return NULL;
322  }
323  // Paint it in.
324  cairo_t *d = cairo_create(s2);
325  cairo_scale(d, scale, scale);
326  cairo_set_source_surface(d, t, 0, 0);
327  cairo_paint(d);
328  cairo_destroy(d);
329 
330  cairo_surface_destroy(t);
331  return s2;
332 }
337 cairo_surface_t *x11_helper_get_screenshot_surface(void) {
338  return cairo_xcb_surface_create(xcb->connection, xcb_stuff_get_root_window(),
339  root_visual, xcb->screen->width_in_pixels,
340  xcb->screen->height_in_pixels);
341 }
342 
343 static xcb_pixmap_t get_root_pixmap(xcb_connection_t *c, xcb_screen_t *screen,
344  xcb_atom_t atom) {
345  xcb_get_property_cookie_t cookie;
346  xcb_get_property_reply_t *reply;
347  xcb_pixmap_t rootpixmap = XCB_NONE;
348 
349  cookie = xcb_get_property(c, 0, screen->root, atom, XCB_ATOM_PIXMAP, 0, 1);
350 
351  reply = xcb_get_property_reply(c, cookie, NULL);
352 
353  if (reply) {
354  if (xcb_get_property_value_length(reply) == sizeof(xcb_pixmap_t)) {
355  memcpy(&rootpixmap, xcb_get_property_value(reply), sizeof(xcb_pixmap_t));
356  }
357  free(reply);
358  }
359 
360  return rootpixmap;
361 }
362 
363 cairo_surface_t *x11_helper_get_bg_surface(void) {
364  xcb_pixmap_t pm =
365  get_root_pixmap(xcb->connection, xcb->screen, netatoms[ESETROOT_PMAP_ID]);
366  if (pm == XCB_NONE) {
367  return NULL;
368  }
369  return cairo_xcb_surface_create(xcb->connection, pm, root_visual,
370  xcb->screen->width_in_pixels,
371  xcb->screen->height_in_pixels);
372 }
373 
374 // retrieve a text property from a window
375 // technically we could use window_get_prop(), but this is better for character
376 // set support
377 char *window_get_text_prop(xcb_window_t w, xcb_atom_t atom) {
378  xcb_get_property_cookie_t c = xcb_get_property(
379  xcb->connection, 0, w, atom, XCB_GET_PROPERTY_TYPE_ANY, 0, UINT_MAX);
380  xcb_get_property_reply_t *r =
381  xcb_get_property_reply(xcb->connection, c, NULL);
382  if (r) {
383  if (xcb_get_property_value_length(r) > 0) {
384  char *str = NULL;
385  if (r->type == netatoms[UTF8_STRING]) {
386  str = g_strndup(xcb_get_property_value(r),
387  xcb_get_property_value_length(r));
388  } else if (r->type == netatoms[STRING]) {
389  str = rofi_latin_to_utf8_strdup(xcb_get_property_value(r),
390  xcb_get_property_value_length(r));
391  } else {
392  str = g_strdup("Invalid encoding.");
393  }
394 
395  free(r);
396  return str;
397  }
398  free(r);
399  }
400  return NULL;
401 }
402 
403 void window_set_atom_prop(xcb_window_t w, xcb_atom_t prop, xcb_atom_t *atoms,
404  int count) {
405  xcb_change_property(xcb->connection, XCB_PROP_MODE_REPLACE, w, prop,
406  XCB_ATOM_ATOM, 32, count, atoms);
407 }
408 
409 /****
410  * Code used to get monitor layout.
411  */
412 
416 static void x11_monitor_free(workarea *m) {
417  g_free(m->name);
418  g_free(m);
419 }
420 
421 static void x11_monitors_free(void) {
422  while (xcb->monitors != NULL) {
423  workarea *m = xcb->monitors;
424  xcb->monitors = m->next;
425  x11_monitor_free(m);
426  }
427 }
428 
432 static workarea *x11_get_monitor_from_output(xcb_randr_output_t out) {
433  xcb_randr_get_output_info_reply_t *op_reply;
434  xcb_randr_get_crtc_info_reply_t *crtc_reply;
435  xcb_randr_get_output_info_cookie_t it =
436  xcb_randr_get_output_info(xcb->connection, out, XCB_CURRENT_TIME);
437  op_reply = xcb_randr_get_output_info_reply(xcb->connection, it, NULL);
438  if (op_reply->crtc == XCB_NONE) {
439  free(op_reply);
440  return NULL;
441  }
442  xcb_randr_get_crtc_info_cookie_t ct = xcb_randr_get_crtc_info(
443  xcb->connection, op_reply->crtc, XCB_CURRENT_TIME);
444  crtc_reply = xcb_randr_get_crtc_info_reply(xcb->connection, ct, NULL);
445  if (!crtc_reply) {
446  free(op_reply);
447  return NULL;
448  }
449  workarea *retv = g_malloc0(sizeof(workarea));
450  retv->x = crtc_reply->x;
451  retv->y = crtc_reply->y;
452  retv->w = crtc_reply->width;
453  retv->h = crtc_reply->height;
454 
455  retv->mw = op_reply->mm_width;
456  retv->mh = op_reply->mm_height;
457 
458  char *tname = (char *)xcb_randr_get_output_info_name(op_reply);
459  int tname_len = xcb_randr_get_output_info_name_length(op_reply);
460 
461  retv->name = g_malloc0((tname_len + 1) * sizeof(char));
462  memcpy(retv->name, tname, tname_len);
463 
464  free(crtc_reply);
465  free(op_reply);
466  return retv;
467 }
468 
469 #if (((XCB_RANDR_MAJOR_VERSION >= RANDR_PREF_MAJOR_VERSION) && \
470  (XCB_RANDR_MINOR_VERSION >= RANDR_PREF_MINOR_VERSION)) || \
471  XCB_RANDR_MAJOR_VERSION > RANDR_PREF_MAJOR_VERSION)
479 static workarea *
480 x11_get_monitor_from_randr_monitor(xcb_randr_monitor_info_t *mon) {
481  // Query to the name of the monitor.
482  xcb_generic_error_t *err;
483  xcb_get_atom_name_cookie_t anc =
484  xcb_get_atom_name(xcb->connection, mon->name);
485  xcb_get_atom_name_reply_t *atom_reply =
486  xcb_get_atom_name_reply(xcb->connection, anc, &err);
487  if (err != NULL) {
488  g_warning("Could not get RandR monitor name: X11 error code %d\n",
489  err->error_code);
490  free(err);
491  return NULL;
492  }
493  workarea *retv = g_malloc0(sizeof(workarea));
494 
495  // Is primary monitor.
496  retv->primary = mon->primary;
497 
498  // Position and size.
499  retv->x = mon->x;
500  retv->y = mon->y;
501  retv->w = mon->width;
502  retv->h = mon->height;
503 
504  // Physical
505  retv->mw = mon->width_in_millimeters;
506  retv->mh = mon->height_in_millimeters;
507 
508  // Name
509  retv->name =
510  g_strdup_printf("%.*s", xcb_get_atom_name_name_length(atom_reply),
511  xcb_get_atom_name_name(atom_reply));
512 
513  // Free name atom.
514  free(atom_reply);
515 
516  return retv;
517 }
518 #endif
519 
520 static int x11_is_extension_present(const char *extension) {
521  xcb_query_extension_cookie_t randr_cookie =
522  xcb_query_extension(xcb->connection, strlen(extension), extension);
523 
524  xcb_query_extension_reply_t *randr_reply =
525  xcb_query_extension_reply(xcb->connection, randr_cookie, NULL);
526 
527  int present = randr_reply->present;
528 
529  free(randr_reply);
530 
531  return present;
532 }
533 
535  xcb_xinerama_query_screens_cookie_t screens_cookie =
536  xcb_xinerama_query_screens_unchecked(xcb->connection);
537 
538  xcb_xinerama_query_screens_reply_t *screens_reply =
539  xcb_xinerama_query_screens_reply(xcb->connection, screens_cookie, NULL);
540 
541  xcb_xinerama_screen_info_iterator_t screens_iterator =
542  xcb_xinerama_query_screens_screen_info_iterator(screens_reply);
543 
544  for (; screens_iterator.rem > 0;
545  xcb_xinerama_screen_info_next(&screens_iterator)) {
546  workarea *w = g_malloc0(sizeof(workarea));
547 
548  w->x = screens_iterator.data->x_org;
549  w->y = screens_iterator.data->y_org;
550  w->w = screens_iterator.data->width;
551  w->h = screens_iterator.data->height;
552 
553  w->next = xcb->monitors;
554  xcb->monitors = w;
555  }
556 
557  int index = 0;
558  for (workarea *iter = xcb->monitors; iter; iter = iter->next) {
559  iter->monitor_id = index++;
560  }
561 
562  free(screens_reply);
563 }
564 
566  if (xcb->monitors) {
567  return;
568  }
569  // If RANDR is not available, try Xinerama
570  if (!x11_is_extension_present("RANDR")) {
571  // Check if xinerama is available.
572  if (x11_is_extension_present("XINERAMA")) {
573  g_debug("Query XINERAMA for monitor layout.");
575  return;
576  }
577  g_debug("No RANDR or Xinerama available for getting monitor layout.");
578  return;
579  }
580  g_debug("Query RANDR for monitor layout.");
581 
582  g_debug("Randr XCB api version: %d.%d.", XCB_RANDR_MAJOR_VERSION,
583  XCB_RANDR_MINOR_VERSION);
584 #if (((XCB_RANDR_MAJOR_VERSION == RANDR_PREF_MAJOR_VERSION) && \
585  (XCB_RANDR_MINOR_VERSION >= RANDR_PREF_MINOR_VERSION)) || \
586  XCB_RANDR_MAJOR_VERSION > RANDR_PREF_MAJOR_VERSION)
587  xcb_randr_query_version_cookie_t cversion = xcb_randr_query_version(
589  xcb_randr_query_version_reply_t *rversion =
590  xcb_randr_query_version_reply(xcb->connection, cversion, NULL);
591  if (rversion) {
592  g_debug("Found randr version: %d.%d", rversion->major_version,
593  rversion->minor_version);
594  // Check if we are 1.5 and up.
595  if (((rversion->major_version == RANDR_PREF_MAJOR_VERSION) &&
596  (rversion->minor_version >= RANDR_PREF_MINOR_VERSION)) ||
597  (rversion->major_version > RANDR_PREF_MAJOR_VERSION)) {
598  xcb_randr_get_monitors_cookie_t t =
599  xcb_randr_get_monitors(xcb->connection, xcb->screen->root, 1);
600  xcb_randr_get_monitors_reply_t *mreply =
601  xcb_randr_get_monitors_reply(xcb->connection, t, NULL);
602  if (mreply) {
603  xcb_randr_monitor_info_iterator_t iter =
604  xcb_randr_get_monitors_monitors_iterator(mreply);
605  while (iter.rem > 0) {
606  workarea *w = x11_get_monitor_from_randr_monitor(iter.data);
607  if (w) {
608  w->next = xcb->monitors;
609  xcb->monitors = w;
610  }
611  xcb_randr_monitor_info_next(&iter);
612  }
613  free(mreply);
614  }
615  }
616  free(rversion);
617  }
618 #endif
619 
620  // If no monitors found.
621  if (xcb->monitors == NULL) {
622  xcb_randr_get_screen_resources_current_reply_t *res_reply;
623  xcb_randr_get_screen_resources_current_cookie_t src;
624  src = xcb_randr_get_screen_resources_current(xcb->connection,
625  xcb->screen->root);
626  res_reply = xcb_randr_get_screen_resources_current_reply(xcb->connection,
627  src, NULL);
628  if (!res_reply) {
629  return; // just report error
630  }
631  int mon_num =
632  xcb_randr_get_screen_resources_current_outputs_length(res_reply);
633  xcb_randr_output_t *ops =
634  xcb_randr_get_screen_resources_current_outputs(res_reply);
635 
636  // Get primary.
637  xcb_randr_get_output_primary_cookie_t pc =
638  xcb_randr_get_output_primary(xcb->connection, xcb->screen->root);
639  xcb_randr_get_output_primary_reply_t *pc_rep =
640  xcb_randr_get_output_primary_reply(xcb->connection, pc, NULL);
641 
642  for (int i = mon_num - 1; i >= 0; i--) {
644  if (w) {
645  w->next = xcb->monitors;
646  xcb->monitors = w;
647  if (pc_rep && pc_rep->output == ops[i]) {
648  w->primary = TRUE;
649  }
650  }
651  }
652  // If exists, free primary output reply.
653  if (pc_rep) {
654  free(pc_rep);
655  }
656  free(res_reply);
657  }
658 
659  // Number monitor
660  int index = 0;
661  for (workarea *iter = xcb->monitors; iter; iter = iter->next) {
662  iter->monitor_id = index++;
663  }
664 }
665 
667  int is_term = isatty(fileno(stdout));
668  printf("Monitor layout:\n");
669  for (workarea *iter = xcb->monitors; iter; iter = iter->next) {
670  printf("%s ID%s: %d", (is_term) ? color_bold : "",
671  is_term ? color_reset : "", iter->monitor_id);
672  if (iter->primary) {
673  printf(" (primary)");
674  }
675  printf("\n");
676  printf("%s name%s: %s\n", (is_term) ? color_bold : "",
677  is_term ? color_reset : "", iter->name);
678  printf("%s position%s: %d,%d\n", (is_term) ? color_bold : "",
679  is_term ? color_reset : "", iter->x, iter->y);
680  printf("%s size%s: %d,%d\n", (is_term) ? color_bold : "",
681  is_term ? color_reset : "", iter->w, iter->h);
682  if (iter->mw > 0 && iter->mh > 0) {
683  printf("%s size%s: %dmm,%dmm dpi: %.0f,%.0f\n",
684  (is_term) ? color_bold : "", is_term ? color_reset : "", iter->mw,
685  iter->mh, iter->w * 25.4 / (double)iter->mw,
686  iter->h * 25.4 / (double)iter->mh);
687  }
688  printf("\n");
689  }
690 }
691 
693  GSpawnChildSetupFunc *child_setup,
694  gpointer *user_data) {
695  if (context == NULL) {
696  return;
697  }
698 
699  SnLauncherContext *sncontext;
700 
701  sncontext = sn_launcher_context_new(xcb->sndisplay, xcb->screen_nbr);
702 
703  sn_launcher_context_set_name(sncontext, context->name);
704  sn_launcher_context_set_description(sncontext, context->description);
705  if (context->binary != NULL) {
706  sn_launcher_context_set_binary_name(sncontext, context->binary);
707  }
708  if (context->icon != NULL) {
709  sn_launcher_context_set_icon_name(sncontext, context->icon);
710  }
711  if (context->app_id != NULL) {
712  sn_launcher_context_set_application_id(sncontext, context->app_id);
713  }
714  if (context->wmclass != NULL) {
715  sn_launcher_context_set_wmclass(sncontext, context->wmclass);
716  }
717 
718  xcb_get_property_cookie_t c;
719  unsigned int current_desktop = 0;
720 
721  c = xcb_ewmh_get_current_desktop(&xcb->ewmh, xcb->screen_nbr);
722  if (xcb_ewmh_get_current_desktop_reply(&xcb->ewmh, c, &current_desktop,
723  NULL)) {
724  sn_launcher_context_set_workspace(sncontext, current_desktop);
725  }
726 
727  sn_launcher_context_initiate(sncontext, "rofi", context->command,
729 
730  *child_setup = (GSpawnChildSetupFunc)sn_launcher_context_setup_child_process;
731  *user_data = sncontext;
732 }
733 
734 static int monitor_get_dimension(int monitor_id, workarea *mon) {
735  memset(mon, 0, sizeof(workarea));
736  mon->w = xcb->screen->width_in_pixels;
737  mon->h = xcb->screen->height_in_pixels;
738 
739  workarea *iter = NULL;
740  for (iter = xcb->monitors; iter; iter = iter->next) {
741  if (iter->monitor_id == monitor_id) {
742  *mon = *iter;
743  return TRUE;
744  }
745  }
746  return FALSE;
747 }
748 // find the dimensions of the monitor displaying point x,y
749 static void monitor_dimensions(int x, int y, workarea *mon) {
750  if (mon == NULL) {
751  g_error("%s: mon == NULL", __FUNCTION__);
752  return;
753  }
754  memset(mon, 0, sizeof(workarea));
755  mon->w = xcb->screen->width_in_pixels;
756  mon->h = xcb->screen->height_in_pixels;
757 
758  for (workarea *iter = xcb->monitors; iter; iter = iter->next) {
759  if (INTERSECT(x, y, iter->x, iter->y, iter->w, iter->h)) {
760  *mon = *iter;
761  break;
762  }
763  }
764 }
765 
776 static int pointer_get(xcb_window_t root, int *x, int *y) {
777  *x = 0;
778  *y = 0;
779  xcb_query_pointer_cookie_t c = xcb_query_pointer(xcb->connection, root);
780  xcb_query_pointer_reply_t *r =
781  xcb_query_pointer_reply(xcb->connection, c, NULL);
782  if (r) {
783  *x = r->root_x;
784  *y = r->root_y;
785  free(r);
786  return TRUE;
787  }
788 
789  return FALSE;
790 }
791 
792 static int monitor_active_from_winid(xcb_drawable_t id, workarea *mon) {
793  if (mon == NULL) {
794  g_error("%s: mon == NULL", __FUNCTION__);
795  return FALSE;
796  }
797  xcb_window_t root = xcb->screen->root;
798  xcb_get_geometry_cookie_t c = xcb_get_geometry(xcb->connection, id);
799  xcb_get_geometry_reply_t *r =
800  xcb_get_geometry_reply(xcb->connection, c, NULL);
801  if (r) {
802  xcb_translate_coordinates_cookie_t ct =
803  xcb_translate_coordinates(xcb->connection, id, root, r->x, r->y);
804  xcb_translate_coordinates_reply_t *t =
805  xcb_translate_coordinates_reply(xcb->connection, ct, NULL);
806  if (t) {
807  // place the menu above the window
808  // if some window is focused, place menu above window, else fall
809  // back to selected monitor.
810  mon->x = t->dst_x - r->x;
811  mon->y = t->dst_y - r->y;
812  mon->w = r->width;
813  mon->h = r->height;
814  free(r);
815  free(t);
816  return TRUE;
817  }
818  free(r);
819  }
820  return FALSE;
821 }
822 static int monitor_active_from_id_focused(int mon_id, workarea *mon) {
823  int retv = FALSE;
824  xcb_window_t active_window;
825  xcb_get_property_cookie_t awc;
826  if (mon == NULL) {
827  g_error("%s: mon == NULL", __FUNCTION__);
828  return retv;
829  }
830  awc = xcb_ewmh_get_active_window(&xcb->ewmh, xcb->screen_nbr);
831  if (!xcb_ewmh_get_active_window_reply(&xcb->ewmh, awc, &active_window,
832  NULL)) {
833  g_debug(
834  "Failed to get active window, falling back to mouse location (-5).");
835  return retv;
836  }
837  xcb_query_tree_cookie_t tree_cookie =
838  xcb_query_tree(xcb->connection, active_window);
839  xcb_query_tree_reply_t *tree_reply =
840  xcb_query_tree_reply(xcb->connection, tree_cookie, NULL);
841  if (!tree_reply) {
842  g_debug(
843  "Failed to get parent window, falling back to mouse location (-5).");
844  return retv;
845  }
846  // get geometry.
847  xcb_get_geometry_cookie_t c =
848  xcb_get_geometry(xcb->connection, active_window);
849  xcb_get_geometry_reply_t *r =
850  xcb_get_geometry_reply(xcb->connection, c, NULL);
851  if (!r) {
852  g_debug("Failed to get geometry of active window, falling back to mouse "
853  "location (-5).");
854  free(tree_reply);
855  return retv;
856  }
857  xcb_translate_coordinates_cookie_t ct = xcb_translate_coordinates(
858  xcb->connection, tree_reply->parent, r->root, r->x, r->y);
859  xcb_translate_coordinates_reply_t *t =
860  xcb_translate_coordinates_reply(xcb->connection, ct, NULL);
861  if (t) {
862  if (mon_id == -2) {
863  // place the menu above the window
864  // if some window is focused, place menu above window, else fall
865  // back to selected monitor.
866  mon->x = t->dst_x - r->x;
867  mon->y = t->dst_y - r->y;
868  mon->w = r->width;
869  mon->h = r->height;
870  retv = TRUE;
873  mon->x += r->x;
874  mon->y += r->y;
875  }
876  g_debug("mon pos: %d %d %d-%d", mon->x, mon->y, mon->w, mon->h);
877  } else if (mon_id == -4) {
878  g_debug("Find monitor at location: %d %d", t->dst_x, t->dst_y);
879  monitor_dimensions(t->dst_x, t->dst_y, mon);
880  g_debug("Monitor found pos: %d %d %d-%d", mon->x, mon->y, mon->w, mon->h);
881  retv = TRUE;
882  }
883  free(t);
884  } else {
885  g_debug("Failed to get translate position of active window, falling back "
886  "to mouse location (-5).");
887  }
888  free(r);
889  free(tree_reply);
890  return retv;
891 }
892 static int monitor_active_from_id(int mon_id, workarea *mon) {
893  xcb_window_t root = xcb->screen->root;
894  int x, y;
895  if (mon == NULL) {
896  g_error("%s: mon == NULL", __FUNCTION__);
897  return FALSE;
898  }
899  g_debug("Monitor id: %d", mon_id);
900  // At mouse position.
901  if (mon_id == -3) {
902  if (pointer_get(root, &x, &y)) {
903  monitor_dimensions(x, y, mon);
904  mon->x = x;
905  mon->y = y;
906  return TRUE;
907  }
908  }
909  // Focused monitor
910  else if (mon_id == -1) {
911  g_debug("rofi on current monitor");
912  // Get the current desktop.
913  unsigned int current_desktop = 0;
914  xcb_get_property_cookie_t gcdc;
915  gcdc = xcb_ewmh_get_current_desktop(&xcb->ewmh, xcb->screen_nbr);
916  if (xcb_ewmh_get_current_desktop_reply(&xcb->ewmh, gcdc, &current_desktop,
917  NULL)) {
918  g_debug("Found current desktop: %u", current_desktop);
919  xcb_get_property_cookie_t c =
920  xcb_ewmh_get_desktop_viewport(&xcb->ewmh, xcb->screen_nbr);
921  xcb_ewmh_get_desktop_viewport_reply_t vp;
922  if (xcb_ewmh_get_desktop_viewport_reply(&xcb->ewmh, c, &vp, NULL)) {
923  g_debug("Found %d number of desktops", vp.desktop_viewport_len);
924  if (current_desktop < vp.desktop_viewport_len) {
925  g_debug("Found viewport for desktop: %d %d",
926  vp.desktop_viewport[current_desktop].x,
927  vp.desktop_viewport[current_desktop].y);
928  monitor_dimensions(vp.desktop_viewport[current_desktop].x,
929  vp.desktop_viewport[current_desktop].y, mon);
930  g_debug("Found monitor @: %d %d %dx%d", mon->x, mon->y, mon->w,
931  mon->h);
932  xcb_ewmh_get_desktop_viewport_reply_wipe(&vp);
933  return TRUE;
934  }
935  g_debug("Viewport does not exist for current desktop: %d, falling "
936  "back to mouse location (-5)",
937  current_desktop);
938  xcb_ewmh_get_desktop_viewport_reply_wipe(&vp);
939  } else {
940  g_debug("Failed to get viewport for current desktop: %d, falling back "
941  "to mouse location (-5).",
942  current_desktop);
943  }
944  } else {
945  g_debug("Failed to get current desktop, falling back to mouse location "
946  "(-5).");
947  }
948  } else if (mon_id == -2 || mon_id == -4) {
949  if (monitor_active_from_id_focused(mon_id, mon)) {
950  return TRUE;
951  }
952  }
953  // Monitor that has mouse pointer.
954  else if (mon_id == -5) {
955  if (pointer_get(root, &x, &y)) {
956  monitor_dimensions(x, y, mon);
957  return TRUE;
958  }
959  // This is our give up point.
960  return FALSE;
961  }
962  g_debug("Failed to find monitor, fall back to monitor showing mouse.");
963  return monitor_active_from_id(-5, mon);
964 }
965 
966 // determine which monitor holds the active window, or failing that the mouse
967 // pointer
968 
969 gboolean mon_set = FALSE;
971  0,
972 };
974  if (mon == NULL) {
975  g_error("%s: mon == NULL", __FUNCTION__);
976  return FALSE;
977  }
978  g_debug("Monitor active");
979  if (mon_set) {
980  if (mon) {
981  *mon = mon_cache;
982  return TRUE;
983  }
984  }
985  if (config.monitor != NULL) {
986  g_debug("Monitor lookup by name : %s", config.monitor);
987  for (workarea *iter = xcb->monitors; iter; iter = iter->next) {
988  if (g_strcmp0(config.monitor, iter->name) == 0) {
989  *mon = *iter;
990  mon_cache = *mon;
991  mon_set = TRUE;
992  return TRUE;
993  }
994  }
995  }
996  g_debug("Monitor lookup by name failed: %s", config.monitor);
997  // Grab primary.
998  if (g_strcmp0(config.monitor, "primary") == 0) {
999  for (workarea *iter = xcb->monitors; iter; iter = iter->next) {
1000  if (iter->primary) {
1001  *mon = *iter;
1002  mon_cache = *mon;
1003  mon_set = TRUE;
1004  return TRUE;
1005  }
1006  }
1007  }
1008  if (g_str_has_prefix(config.monitor, "wid:")) {
1009  char *end = NULL;
1010  xcb_drawable_t win = g_ascii_strtoll(config.monitor + 4, &end, 0);
1011  if (end != config.monitor) {
1012  if (monitor_active_from_winid(win, mon)) {
1013  mon_cache = *mon;
1014  mon_set = TRUE;
1015  return TRUE;
1016  }
1017  }
1018  }
1019  {
1020  // IF fail, fall back to classic mode.
1021  char *end = NULL;
1022  gint64 mon_id = g_ascii_strtoll(config.monitor, &end, 0);
1023  if (end != config.monitor) {
1024  if (mon_id >= 0) {
1025  if (monitor_get_dimension(mon_id, mon)) {
1026  mon_cache = *mon;
1027  mon_set = TRUE;
1028  return TRUE;
1029  }
1030  g_warning("Failed to find selected monitor.");
1031  } else {
1032  int val = monitor_active_from_id(mon_id, mon);
1033  mon_cache = *mon;
1034  mon_set = TRUE;
1035  return val;
1036  }
1037  }
1038  }
1039  // Fallback.
1040  monitor_dimensions(0, 0, mon);
1041  mon_cache = *mon;
1042  mon_set = TRUE;
1043  return FALSE;
1044 }
1045 
1052 static void rofi_view_paste(RofiViewState *state,
1053  xcb_selection_notify_event_t *xse) {
1054  if (xse->property == XCB_ATOM_NONE) {
1055  g_warning("Failed to convert selection");
1056  } else if (xse->property == xcb->ewmh.UTF8_STRING) {
1057  gchar *text = window_get_text_prop(xse->requestor, xcb->ewmh.UTF8_STRING);
1058  if (text != NULL && text[0] != '\0') {
1059  unsigned int dl = strlen(text);
1060  // Strip new line
1061  for (unsigned int i = 0; i < dl; i++) {
1062  if (text[i] == '\n') {
1063  text[i] = '\0';
1064  }
1065  }
1066  rofi_view_handle_text(state, text);
1067  }
1068  g_free(text);
1069  } else {
1070  g_warning("Failed");
1071  }
1072 }
1073 
1074 static gboolean
1076  NkBindingsMouseButton *button) {
1077  switch (x11_button) {
1078  case 1:
1079  *button = NK_BINDINGS_MOUSE_BUTTON_PRIMARY;
1080  break;
1081  case 3:
1082  *button = NK_BINDINGS_MOUSE_BUTTON_SECONDARY;
1083  break;
1084  case 2:
1085  *button = NK_BINDINGS_MOUSE_BUTTON_MIDDLE;
1086  break;
1087  case 8:
1088  *button = NK_BINDINGS_MOUSE_BUTTON_BACK;
1089  break;
1090  case 9:
1091  *button = NK_BINDINGS_MOUSE_BUTTON_FORWARD;
1092  break;
1093  case 4:
1094  case 5:
1095  case 6:
1096  case 7:
1097  return FALSE;
1098  default:
1099  *button = NK_BINDINGS_MOUSE_BUTTON_EXTRA + x11_button;
1100  }
1101  return TRUE;
1102 }
1103 
1104 static gboolean x11_button_to_nk_bindings_scroll(guint32 x11_button,
1105  NkBindingsScrollAxis *axis,
1106  gint32 *steps) {
1107  *steps = 1;
1108  switch (x11_button) {
1109  case 4:
1110  *steps = -1;
1111  /* fallthrough */
1112  case 5:
1113  *axis = NK_BINDINGS_SCROLL_AXIS_VERTICAL;
1114  break;
1115  case 6:
1116  *steps = -1;
1117  /* fallthrough */
1118  case 7:
1119  *axis = NK_BINDINGS_SCROLL_AXIS_HORIZONTAL;
1120  break;
1121  default:
1122  return FALSE;
1123  }
1124  return TRUE;
1125 }
1126 
1130 static void main_loop_x11_event_handler_view(xcb_generic_event_t *event) {
1132  if (state == NULL) {
1133  return;
1134  }
1135 
1136  switch (event->response_type & ~0x80) {
1137  case XCB_CLIENT_MESSAGE: {
1138  xcb_client_message_event_t *cme = (xcb_client_message_event_t *)event;
1139  xcb_atom_t atom = cme->data.data32[0];
1140  xcb_timestamp_t time = cme->data.data32[1];
1141  if (atom == netatoms[WM_TAKE_FOCUS]) {
1142  xcb_set_input_focus(xcb->connection, XCB_INPUT_FOCUS_NONE, cme->window,
1143  time);
1144  xcb_flush(xcb->connection);
1145  }
1146  break;
1147  }
1148  case XCB_DESTROY_NOTIFY: {
1149  xcb_window_t win = ((xcb_destroy_notify_event_t *)event)->window;
1150  if (win != rofi_view_get_window()) {
1151 #ifdef WINDOW_MODE
1152  window_client_handle_signal(win, FALSE);
1153 #endif
1154  } else {
1155  g_main_loop_quit(xcb->main_loop);
1156  }
1157  break;
1158  }
1159  case XCB_CREATE_NOTIFY: {
1160  xcb_window_t win = ((xcb_create_notify_event_t *)event)->window;
1161  if (win != rofi_view_get_window()) {
1162 #ifdef WINDOW_MODE
1163  window_client_handle_signal(win, TRUE);
1164 #endif
1165  }
1166  break;
1167  }
1168  case XCB_EXPOSE:
1170  break;
1171  case XCB_CONFIGURE_NOTIFY: {
1172  xcb_configure_notify_event_t *xce = (xcb_configure_notify_event_t *)event;
1173  rofi_view_temp_configure_notify(state, xce);
1174  break;
1175  }
1176  case XCB_MOTION_NOTIFY: {
1177  xcb_motion_notify_event_t *xme = (xcb_motion_notify_event_t *)event;
1178  gboolean button_mask = xme->state & XCB_EVENT_MASK_BUTTON_1_MOTION;
1179  if (button_mask && config.click_to_exit == TRUE) {
1180  xcb->mouse_seen = TRUE;
1181  }
1182  rofi_view_handle_mouse_motion(state, xme->event_x, xme->event_y,
1183  !button_mask && config.hover_select);
1184  break;
1185  }
1186  case XCB_BUTTON_PRESS: {
1187  xcb_button_press_event_t *bpe = (xcb_button_press_event_t *)event;
1188  NkBindingsMouseButton button;
1189  NkBindingsScrollAxis axis;
1190  gint32 steps;
1191 
1192  xcb->last_timestamp = bpe->time;
1193  rofi_view_handle_mouse_motion(state, bpe->event_x, bpe->event_y, FALSE);
1194  if (x11_button_to_nk_bindings_button(bpe->detail, &button)) {
1195  nk_bindings_seat_handle_button(xcb->bindings_seat, NULL, button,
1196  NK_BINDINGS_BUTTON_STATE_PRESS, bpe->time);
1197  } else if (x11_button_to_nk_bindings_scroll(bpe->detail, &axis, &steps)) {
1198  nk_bindings_seat_handle_scroll(xcb->bindings_seat, NULL, axis, steps);
1199  }
1200  break;
1201  }
1202  case XCB_BUTTON_RELEASE: {
1203  xcb_button_release_event_t *bre = (xcb_button_release_event_t *)event;
1204  NkBindingsMouseButton button;
1205 
1206  xcb->last_timestamp = bre->time;
1207  if (x11_button_to_nk_bindings_button(bre->detail, &button)) {
1208  nk_bindings_seat_handle_button(xcb->bindings_seat, NULL, button,
1209  NK_BINDINGS_BUTTON_STATE_RELEASE,
1210  bre->time);
1211  }
1212  if (config.click_to_exit == TRUE) {
1213  if (!xcb->mouse_seen) {
1214  rofi_view_temp_click_to_exit(state, bre->event);
1215  }
1216  xcb->mouse_seen = FALSE;
1217  }
1218  break;
1219  }
1220  // Paste event.
1221  case XCB_SELECTION_NOTIFY:
1222  rofi_view_paste(state, (xcb_selection_notify_event_t *)event);
1223  break;
1224  case XCB_KEYMAP_NOTIFY: {
1225  xcb_keymap_notify_event_t *kne = (xcb_keymap_notify_event_t *)event;
1226  for (gint32 by = 0; by < 31; ++by) {
1227  for (gint8 bi = 0; bi < 7; ++bi) {
1228  if (kne->keys[by] & (1 << bi)) {
1229  // X11 keycodes starts at 8
1230  nk_bindings_seat_handle_key(xcb->bindings_seat, NULL,
1231  (8 * by + bi) + 8,
1232  NK_BINDINGS_KEY_STATE_PRESSED);
1233  }
1234  }
1235  }
1236  break;
1237  }
1238  case XCB_KEY_PRESS: {
1239  xcb_key_press_event_t *xkpe = (xcb_key_press_event_t *)event;
1240  gchar *text;
1241 
1242  xcb->last_timestamp = xkpe->time;
1243  text = nk_bindings_seat_handle_key_with_modmask(
1244  xcb->bindings_seat, NULL, xkpe->state, xkpe->detail,
1245  NK_BINDINGS_KEY_STATE_PRESS);
1246  if (text != NULL) {
1247  rofi_view_handle_text(state, text);
1248  g_free(text);
1249  }
1250  break;
1251  }
1252  case XCB_KEY_RELEASE: {
1253  xcb_key_release_event_t *xkre = (xcb_key_release_event_t *)event;
1254  xcb->last_timestamp = xkre->time;
1255  nk_bindings_seat_handle_key(xcb->bindings_seat, NULL, xkre->detail,
1256  NK_BINDINGS_KEY_STATE_RELEASE);
1257  break;
1258  }
1259  default:
1260  break;
1261  }
1262  rofi_view_maybe_update(state);
1263 }
1264 
1265 static gboolean main_loop_x11_event_handler(xcb_generic_event_t *ev,
1266  G_GNUC_UNUSED gpointer user_data) {
1267  if (ev == NULL) {
1268  int status = xcb_connection_has_error(xcb->connection);
1269  if (status > 0) {
1270  g_warning("The XCB connection to X server had a fatal error: %d", status);
1271  g_main_loop_quit(xcb->main_loop);
1272  return G_SOURCE_REMOVE;
1273  }
1274  g_warning("main_loop_x11_event_handler: ev == NULL, status == %d", status);
1275  return G_SOURCE_CONTINUE;
1276  }
1277  uint8_t type = ev->response_type & ~0x80;
1278  if (type == xcb->xkb.first_event) {
1279  switch (ev->pad0) {
1280  case XCB_XKB_MAP_NOTIFY: {
1281  struct xkb_keymap *keymap = xkb_x11_keymap_new_from_device(
1282  nk_bindings_seat_get_context(xcb->bindings_seat), xcb->connection,
1283  xcb->xkb.device_id, 0);
1284  struct xkb_state *state = xkb_x11_state_new_from_device(
1285  keymap, xcb->connection, xcb->xkb.device_id);
1286  nk_bindings_seat_update_keymap(xcb->bindings_seat, keymap, state);
1287  xkb_keymap_unref(keymap);
1288  xkb_state_unref(state);
1289  break;
1290  }
1291  case XCB_XKB_STATE_NOTIFY: {
1292  xcb_xkb_state_notify_event_t *ksne = (xcb_xkb_state_notify_event_t *)ev;
1293  nk_bindings_seat_update_mask(xcb->bindings_seat, NULL, ksne->baseMods,
1294  ksne->latchedMods, ksne->lockedMods,
1295  ksne->baseGroup, ksne->latchedGroup,
1296  ksne->lockedGroup);
1298  break;
1299  }
1300  }
1301  return G_SOURCE_CONTINUE;
1302  }
1303  if (xcb->sndisplay != NULL) {
1304  sn_xcb_display_process_event(xcb->sndisplay, ev);
1305  }
1307  return G_SOURCE_CONTINUE;
1308 }
1309 
1310 void rofi_xcb_set_input_focus(xcb_window_t w) {
1311  if (config.steal_focus != TRUE) {
1312  xcb->focus_revert = 0;
1313  return;
1314  }
1315  xcb_generic_error_t *error;
1316  xcb_get_input_focus_reply_t *freply;
1317  xcb_get_input_focus_cookie_t fcookie = xcb_get_input_focus(xcb->connection);
1318  freply = xcb_get_input_focus_reply(xcb->connection, fcookie, &error);
1319  if (error != NULL) {
1320  g_warning("Could not get input focus (error %d), will revert focus to best "
1321  "effort",
1322  error->error_code);
1323  free(error);
1324  xcb->focus_revert = 0;
1325  } else {
1326  xcb->focus_revert = freply->focus;
1327  }
1328  xcb_set_input_focus(xcb->connection, XCB_INPUT_FOCUS_POINTER_ROOT, w,
1329  XCB_CURRENT_TIME);
1330  xcb_flush(xcb->connection);
1331 }
1332 
1334  if (xcb->focus_revert == 0) {
1335  return;
1336  }
1337 
1338  xcb_set_input_focus(xcb->connection, XCB_INPUT_FOCUS_POINTER_ROOT,
1339  xcb->focus_revert, XCB_CURRENT_TIME);
1340  xcb_flush(xcb->connection);
1341 }
1342 
1343 static int take_pointer(xcb_window_t w, int iters) {
1344  int i = 0;
1345  while (TRUE) {
1346  if (xcb_connection_has_error(xcb->connection)) {
1347  g_warning("Connection has error");
1348  exit(EXIT_FAILURE);
1349  }
1350  xcb_grab_pointer_cookie_t cc =
1351  xcb_grab_pointer(xcb->connection, 1, w, XCB_EVENT_MASK_BUTTON_RELEASE,
1352  XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, w, XCB_NONE,
1353  XCB_CURRENT_TIME);
1354  xcb_grab_pointer_reply_t *r =
1355  xcb_grab_pointer_reply(xcb->connection, cc, NULL);
1356  if (r) {
1357  if (r->status == XCB_GRAB_STATUS_SUCCESS) {
1358  free(r);
1359  return 1;
1360  }
1361  free(r);
1362  }
1363  if ((++i) > iters) {
1364  break;
1365  }
1366  struct timespec del = {.tv_sec = 0, .tv_nsec = 1000000};
1367  nanosleep(&del, NULL);
1368  }
1369  return 0;
1370 }
1371 
1372 static int take_keyboard(xcb_window_t w, int iters) {
1373  int i = 0;
1374  while (TRUE) {
1375  if (xcb_connection_has_error(xcb->connection)) {
1376  g_warning("Connection has error");
1377  exit(EXIT_FAILURE);
1378  }
1379  xcb_grab_keyboard_cookie_t cc =
1380  xcb_grab_keyboard(xcb->connection, 1, w, XCB_CURRENT_TIME,
1381  XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
1382  xcb_grab_keyboard_reply_t *r =
1383  xcb_grab_keyboard_reply(xcb->connection, cc, NULL);
1384  if (r) {
1385  if (r->status == XCB_GRAB_STATUS_SUCCESS) {
1386  free(r);
1387  return 1;
1388  }
1389  free(r);
1390  }
1391  if ((++i) > iters) {
1392  break;
1393  }
1394  struct timespec del = {.tv_sec = 0, .tv_nsec = 1000000};
1395  nanosleep(&del, NULL);
1396  }
1397  return 0;
1398 }
1399 
1400 static void release_keyboard(void) {
1401  xcb_ungrab_keyboard(xcb->connection, XCB_CURRENT_TIME);
1402 }
1403 static void release_pointer(void) {
1404  xcb_ungrab_pointer(xcb->connection, XCB_CURRENT_TIME);
1405 }
1406 
1408 static int error_trap_depth = 0;
1409 static void error_trap_push(G_GNUC_UNUSED SnDisplay *display,
1410  G_GNUC_UNUSED xcb_connection_t *xdisplay) {
1411  ++error_trap_depth;
1412 }
1413 
1414 static void error_trap_pop(G_GNUC_UNUSED SnDisplay *display,
1415  xcb_connection_t *xdisplay) {
1416  if (error_trap_depth == 0) {
1417  g_warning("Error trap underflow!");
1418  exit(EXIT_FAILURE);
1419  }
1420 
1421  xcb_flush(xdisplay);
1422  --error_trap_depth;
1423 }
1424 
1429  // X atom values
1430  for (int i = 0; i < NUM_NETATOMS; i++) {
1431  xcb_intern_atom_cookie_t cc = xcb_intern_atom(
1432  xcb->connection, 0, strlen(netatom_names[i]), netatom_names[i]);
1433  xcb_intern_atom_reply_t *r =
1434  xcb_intern_atom_reply(xcb->connection, cc, NULL);
1435  if (r) {
1436  netatoms[i] = r->atom;
1437  free(r);
1438  }
1439  }
1440 }
1441 
1443  xcb_window_t wm_win = 0;
1444  xcb_get_property_cookie_t cc = xcb_ewmh_get_supporting_wm_check_unchecked(
1446 
1447  if (xcb_ewmh_get_supporting_wm_check_reply(&xcb->ewmh, cc, &wm_win, NULL)) {
1448  xcb_ewmh_get_utf8_strings_reply_t wtitle;
1449  xcb_get_property_cookie_t cookie =
1450  xcb_ewmh_get_wm_name_unchecked(&(xcb->ewmh), wm_win);
1451  if (xcb_ewmh_get_wm_name_reply(&(xcb->ewmh), cookie, &wtitle, (void *)0)) {
1452  if (wtitle.strings_len > 0) {
1453  g_debug("Found window manager: |%s|", wtitle.strings);
1454  if (g_strcmp0(wtitle.strings, "i3") == 0) {
1457  } else if (g_strcmp0(wtitle.strings, "bspwm") == 0) {
1459  }
1460  }
1461  xcb_ewmh_get_utf8_strings_reply_wipe(&wtitle);
1462  }
1463  }
1464 }
1465 
1466 gboolean display_setup(GMainLoop *main_loop, NkBindings *bindings) {
1467  // Get DISPLAY, first env, then argument.
1468  // We never modify display_str content.
1469  char *display_str = (char *)g_getenv("DISPLAY");
1470  find_arg_str("-display", &display_str);
1471 
1472  xcb->main_loop = main_loop;
1473  xcb->source = g_water_xcb_source_new(g_main_loop_get_context(xcb->main_loop),
1474  display_str, &xcb->screen_nbr,
1475  main_loop_x11_event_handler, NULL, NULL);
1476  if (xcb->source == NULL) {
1477  g_warning("Failed to open display: %s", display_str);
1478  return FALSE;
1479  }
1480  xcb->connection = g_water_xcb_source_get_connection(xcb->source);
1481 
1482  TICK_N("Open Display");
1483 
1484  xcb->screen = xcb_aux_get_screen(xcb->connection, xcb->screen_nbr);
1485 
1487 
1488  xcb_intern_atom_cookie_t *ac =
1489  xcb_ewmh_init_atoms(xcb->connection, &xcb->ewmh);
1490  xcb_generic_error_t *errors = NULL;
1491  xcb_ewmh_init_atoms_replies(&xcb->ewmh, ac, &errors);
1492  if (errors) {
1493  g_warning("Failed to create EWMH atoms");
1494  free(errors);
1495  }
1496  // Discover the current active window manager.
1498  TICK_N("Setup XCB");
1499 
1500  if (xkb_x11_setup_xkb_extension(
1501  xcb->connection, XKB_X11_MIN_MAJOR_XKB_VERSION,
1502  XKB_X11_MIN_MINOR_XKB_VERSION, XKB_X11_SETUP_XKB_EXTENSION_NO_FLAGS,
1503  NULL, NULL, &xcb->xkb.first_event, NULL) < 0) {
1504  g_warning("cannot setup XKB extension!");
1505  return FALSE;
1506  }
1507 
1508  xcb->xkb.device_id = xkb_x11_get_core_keyboard_device_id(xcb->connection);
1509 
1510  enum {
1511  required_events =
1512  (XCB_XKB_EVENT_TYPE_NEW_KEYBOARD_NOTIFY |
1513  XCB_XKB_EVENT_TYPE_MAP_NOTIFY | XCB_XKB_EVENT_TYPE_STATE_NOTIFY),
1514 
1515  required_nkn_details = (XCB_XKB_NKN_DETAIL_KEYCODES),
1516 
1517  required_map_parts =
1518  (XCB_XKB_MAP_PART_KEY_TYPES | XCB_XKB_MAP_PART_KEY_SYMS |
1519  XCB_XKB_MAP_PART_MODIFIER_MAP | XCB_XKB_MAP_PART_EXPLICIT_COMPONENTS |
1520  XCB_XKB_MAP_PART_KEY_ACTIONS | XCB_XKB_MAP_PART_VIRTUAL_MODS |
1521  XCB_XKB_MAP_PART_VIRTUAL_MOD_MAP),
1522 
1523  required_state_details =
1524  (XCB_XKB_STATE_PART_MODIFIER_BASE | XCB_XKB_STATE_PART_MODIFIER_LATCH |
1525  XCB_XKB_STATE_PART_MODIFIER_LOCK | XCB_XKB_STATE_PART_GROUP_BASE |
1526  XCB_XKB_STATE_PART_GROUP_LATCH | XCB_XKB_STATE_PART_GROUP_LOCK),
1527  };
1528 
1529  static const xcb_xkb_select_events_details_t details = {
1530  .affectNewKeyboard = required_nkn_details,
1531  .newKeyboardDetails = required_nkn_details,
1532  .affectState = required_state_details,
1533  .stateDetails = required_state_details,
1534  };
1535  xcb_xkb_select_events(xcb->connection, xcb->xkb.device_id,
1536  required_events, /* affectWhich */
1537  0, /* clear */
1538  required_events, /* selectAll */
1539  required_map_parts, /* affectMap */
1540  required_map_parts, /* map */
1541  &details);
1542 
1543  xcb->bindings_seat = nk_bindings_seat_new(bindings, XKB_CONTEXT_NO_FLAGS);
1544  struct xkb_keymap *keymap = xkb_x11_keymap_new_from_device(
1545  nk_bindings_seat_get_context(xcb->bindings_seat), xcb->connection,
1546  xcb->xkb.device_id, XKB_KEYMAP_COMPILE_NO_FLAGS);
1547  if (keymap == NULL) {
1548  g_warning("Failed to get Keymap for current keyboard device.");
1549  return FALSE;
1550  }
1551  struct xkb_state *state = xkb_x11_state_new_from_device(
1552  keymap, xcb->connection, xcb->xkb.device_id);
1553  if (state == NULL) {
1554  g_warning("Failed to get state object for current keyboard device.");
1555  return FALSE;
1556  }
1557 
1558  nk_bindings_seat_update_keymap(xcb->bindings_seat, keymap, state);
1559  xkb_state_unref(state);
1560  xkb_keymap_unref(keymap);
1561 
1562  // determine numlock mask so we can bind on keys with and without it
1564 
1565  if (xcb_connection_has_error(xcb->connection)) {
1566  g_warning("Connection has error");
1567  return FALSE;
1568  }
1569 
1570  uint32_t val[] = {XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY};
1571 
1572  xcb_change_window_attributes(xcb->connection, xcb_stuff_get_root_window(),
1573  XCB_CW_EVENT_MASK, val);
1574 
1575  // startup not.
1576  xcb->sndisplay =
1577  sn_xcb_display_new(xcb->connection, error_trap_push, error_trap_pop);
1578  if (xcb_connection_has_error(xcb->connection)) {
1579  g_warning("Connection has error");
1580  return FALSE;
1581  }
1582 
1583  if (xcb->sndisplay != NULL) {
1584  xcb->sncontext = sn_launchee_context_new_from_environment(xcb->sndisplay,
1585  xcb->screen_nbr);
1586  }
1587  if (xcb_connection_has_error(xcb->connection)) {
1588  g_warning("Connection has error");
1589  return FALSE;
1590  }
1591 
1592  return TRUE;
1593 }
1594 
1596  xcb_depth_t *root_depth = NULL;
1597  xcb_depth_iterator_t depth_iter;
1598  for (depth_iter = xcb_screen_allowed_depths_iterator(xcb->screen);
1599  depth_iter.rem; xcb_depth_next(&depth_iter)) {
1600  xcb_depth_t *d = depth_iter.data;
1601 
1602  xcb_visualtype_iterator_t visual_iter;
1603  for (visual_iter = xcb_depth_visuals_iterator(d); visual_iter.rem;
1604  xcb_visualtype_next(&visual_iter)) {
1605  xcb_visualtype_t *v = visual_iter.data;
1606  if ((v->bits_per_rgb_value == 8) && (d->depth == 32) &&
1607  (v->_class == XCB_VISUAL_CLASS_TRUE_COLOR)) {
1608  depth = d;
1609  visual = v;
1610  }
1611  if (xcb->screen->root_visual == v->visual_id) {
1612  root_depth = d;
1613  root_visual = v;
1614  }
1615  }
1616  }
1617  if (visual != NULL) {
1618  xcb_void_cookie_t c;
1619  xcb_generic_error_t *e;
1620  map = xcb_generate_id(xcb->connection);
1621  c = xcb_create_colormap_checked(xcb->connection, XCB_COLORMAP_ALLOC_NONE,
1622  map, xcb->screen->root, visual->visual_id);
1623  e = xcb_request_check(xcb->connection, c);
1624  if (e) {
1625  depth = NULL;
1626  visual = NULL;
1627  free(e);
1628  }
1629  }
1630 
1631  if (visual == NULL) {
1632  depth = root_depth;
1633  visual = root_visual;
1634  map = xcb->screen->default_colormap;
1635  }
1636 }
1637 
1638 static void x11_lookup_cursors(void) {
1639  xcb_cursor_context_t *ctx;
1640 
1641  if (xcb_cursor_context_new(xcb->connection, xcb->screen, &ctx) < 0) {
1642  return;
1643  }
1644 
1645  for (int i = 0; i < NUM_CURSORS; ++i) {
1646  cursors[i] = xcb_cursor_load_cursor(ctx, cursor_names[i].css_name);
1647 
1648  if (cursors[i] == XCB_CURSOR_NONE) {
1649  cursors[i] =
1650  xcb_cursor_load_cursor(ctx, cursor_names[i].traditional_name);
1651  }
1652  }
1653 
1654  xcb_cursor_context_free(ctx);
1655 }
1656 
1658 unsigned int lazy_grab_retry_count_kb = 0;
1660 unsigned int lazy_grab_retry_count_pt = 0;
1661 static gboolean lazy_grab_pointer(G_GNUC_UNUSED gpointer data) {
1662  // After 5 sec.
1663  if (lazy_grab_retry_count_pt > (5 * 1000)) {
1664  g_warning("Failed to grab pointer after %u times. Giving up.",
1666  return G_SOURCE_REMOVE;
1667  }
1669  return G_SOURCE_REMOVE;
1670  }
1672  return G_SOURCE_CONTINUE;
1673 }
1674 static gboolean lazy_grab_keyboard(G_GNUC_UNUSED gpointer data) {
1675  // After 5 sec.
1676  if (lazy_grab_retry_count_kb > (5 * 1000)) {
1677  g_warning("Failed to grab keyboard after %u times. Giving up.",
1679  g_main_loop_quit(xcb->main_loop);
1680  return G_SOURCE_REMOVE;
1681  }
1683  return G_SOURCE_REMOVE;
1684  }
1686  return G_SOURCE_CONTINUE;
1687 }
1688 
1689 gboolean display_late_setup(void) {
1691 
1693 
1697  // Try to grab the keyboard as early as possible.
1698  // We grab this using the rootwindow (as dmenu does it).
1699  // this seems to result in the smallest delay for most people.
1700  if (find_arg("-normal-window") >= 0) {
1701  return TRUE;
1702  }
1703  if (find_arg("-no-lazy-grab") >= 0) {
1705  g_warning("Failed to grab keyboard, even after %d uS.", 500 * 1000);
1706  return FALSE;
1707  }
1708  if (!take_pointer(xcb_stuff_get_root_window(), 100)) {
1709  g_warning("Failed to grab mouse pointer, even after %d uS.", 100 * 1000);
1710  }
1711  } else {
1713  g_timeout_add(1, lazy_grab_keyboard, NULL);
1714  }
1716  g_timeout_add(1, lazy_grab_pointer, NULL);
1717  }
1718  }
1719  return TRUE;
1720 }
1721 
1722 xcb_window_t xcb_stuff_get_root_window(void) { return xcb->screen->root; }
1723 
1725  release_keyboard();
1726  release_pointer();
1727  xcb_flush(xcb->connection);
1728 }
1729 
1730 void display_cleanup(void) {
1731  if (xcb->connection == NULL) {
1732  return;
1733  }
1734 
1735  g_debug("Cleaning up XCB and XKB");
1736 
1737  nk_bindings_seat_free(xcb->bindings_seat);
1738  if (xcb->sncontext != NULL) {
1739  sn_launchee_context_unref(xcb->sncontext);
1740  xcb->sncontext = NULL;
1741  }
1742  if (xcb->sndisplay != NULL) {
1743  sn_display_unref(xcb->sndisplay);
1744  xcb->sndisplay = NULL;
1745  }
1747  xcb_ewmh_connection_wipe(&(xcb->ewmh));
1748  xcb_flush(xcb->connection);
1749  xcb_aux_sync(xcb->connection);
1750  g_water_xcb_source_free(xcb->source);
1751  xcb->source = NULL;
1752  xcb->connection = NULL;
1753  xcb->screen = NULL;
1754  xcb->screen_nbr = 0;
1755 }
1756 
1757 void x11_disable_decoration(xcb_window_t window) {
1758  // Flag used to indicate we are setting the decoration type.
1759  const uint32_t MWM_HINTS_DECORATIONS = (1 << 1);
1760  // Motif property data structure
1761  struct MotifWMHints {
1762  uint32_t flags;
1763  uint32_t functions;
1764  uint32_t decorations;
1765  int32_t inputMode;
1766  uint32_t state;
1767  };
1768 
1769  struct MotifWMHints hints;
1770  hints.flags = MWM_HINTS_DECORATIONS;
1771  hints.decorations = 0;
1772  hints.functions = 0;
1773  hints.inputMode = 0;
1774  hints.state = 0;
1775 
1776  xcb_atom_t ha = netatoms[_MOTIF_WM_HINTS];
1777  xcb_change_property(xcb->connection, XCB_PROP_MODE_REPLACE, window, ha, ha,
1778  32, 5, &hints);
1779 }
1780 
1781 void x11_set_cursor(xcb_window_t window, X11CursorType type) {
1782  if (type < 0 || type >= NUM_CURSORS) {
1783  return;
1784  }
1785 
1786  if (cursors[type] == XCB_CURSOR_NONE) {
1787  return;
1788  }
1789 
1790  xcb_change_window_attributes(xcb->connection, window, XCB_CW_CURSOR,
1791  &(cursors[type]));
1792 }
char * rofi_latin_to_utf8_strdup(const char *input, gssize length)
Definition: helper.c:785
int find_arg_str(const char *const key, char **val)
Definition: helper.c:311
int find_arg(const char *const key)
Definition: helper.c:302
#define color_reset
Definition: rofi.h:95
#define color_bold
Definition: rofi.h:97
#define TICK()
Definition: timings.h:64
#define TICK_N(a)
Definition: timings.h:69
xcb_window_t rofi_view_get_window(void)
Definition: view.c:2256
RofiViewState * rofi_view_get_active(void)
Definition: view.c:522
void rofi_view_handle_text(RofiViewState *state, char *text)
Definition: view.c:1540
void rofi_view_handle_mouse_motion(RofiViewState *state, gint x, gint y, gboolean find_mouse_target)
Definition: view.c:1582
void rofi_view_temp_click_to_exit(RofiViewState *state, xcb_window_t target)
Definition: view.c:1670
void rofi_view_temp_configure_notify(RofiViewState *state, xcb_configure_notify_event_t *xce)
Definition: view.c:1636
void rofi_view_frame_callback(void)
Definition: view.c:1679
void rofi_view_maybe_update(RofiViewState *state)
Definition: view.c:1610
NkBindings * bindings
Definition: rofi.c:119
GMainLoop * main_loop
Definition: rofi.c:122
Settings config
const gchar * binary
Definition: helper.h:290
const gchar * wmclass
Definition: helper.h:298
const gchar * app_id
Definition: helper.h:296
const gchar * description
Definition: helper.h:292
const gchar * name
Definition: helper.h:288
const gchar * icon
Definition: helper.h:294
const gchar * command
Definition: helper.h:300
gboolean steal_focus
Definition: settings.h:177
int click_to_exit
Definition: settings.h:148
gboolean hover_select
Definition: settings.h:122
char * monitor
Definition: settings.h:137
Definition: xcb.h:94
int w
Definition: xcb.h:104
int x
Definition: xcb.h:100
int monitor_id
Definition: xcb.h:96
char * name
Definition: xcb.h:109
int mh
Definition: xcb.h:107
struct _workarea * next
Definition: xcb.h:111
int h
Definition: xcb.h:106
int mw
Definition: xcb.h:107
int primary
Definition: xcb.h:98
int y
Definition: xcb.h:102
GWaterXcbSource * source
Definition: xcb-internal.h:46
xcb_connection_t * connection
Definition: xcb-internal.h:47
uint8_t first_event
Definition: xcb-internal.h:56
SnLauncheeContext * sncontext
Definition: xcb-internal.h:52
int32_t device_id
Definition: xcb-internal.h:58
struct _workarea * monitors
Definition: xcb-internal.h:53
xcb_timestamp_t last_timestamp
Definition: xcb-internal.h:60
xcb_ewmh_connection_t ewmh
Definition: xcb-internal.h:48
gboolean mouse_seen
Definition: xcb-internal.h:62
xcb_screen_t * screen
Definition: xcb-internal.h:49
struct _xcb_stuff::@8 xkb
NkBindingsSeat * bindings_seat
Definition: xcb-internal.h:61
int screen_nbr
Definition: xcb-internal.h:50
GMainLoop * main_loop
Definition: xcb-internal.h:45
xcb_window_t focus_revert
Definition: xcb-internal.h:63
SnDisplay * sndisplay
Definition: xcb-internal.h:51
GTimer * time
Definition: view.c:234
workarea mon
Definition: view.c:111
MenuFlags flags
Definition: view.c:107
unsigned long long count
Definition: view.c:117
xcb_colormap_t map
Definition: xcb.c:98
gboolean display_late_setup(void)
Definition: xcb.c:1689
static int take_pointer(xcb_window_t w, int iters)
Definition: xcb.c:1343
int monitor_active(workarea *mon)
Definition: xcb.c:973
const struct @4 cursor_names[]
static void x11_build_monitor_layout_xinerama()
Definition: xcb.c:534
#define RANDR_PREF_MAJOR_VERSION
Definition: xcb.c:72
const char * traditional_name
Definition: xcb.c:117
void display_early_cleanup(void)
Definition: xcb.c:1724
static int x11_is_extension_present(const char *extension)
Definition: xcb.c:520
static gboolean lazy_grab_pointer(G_GNUC_UNUSED gpointer data)
Definition: xcb.c:1661
cairo_surface_t * x11_helper_get_screenshot_surface(void)
Definition: xcb.c:337
void display_startup_notification(RofiHelperExecuteContext *context, GSpawnChildSetupFunc *child_setup, gpointer *user_data)
Definition: xcb.c:692
static void x11_build_monitor_layout()
Definition: xcb.c:565
void display_cleanup(void)
Definition: xcb.c:1730
xcb_stuff * xcb
Definition: xcb.c:91
static xcb_pixmap_t get_root_pixmap(xcb_connection_t *c, xcb_screen_t *screen, xcb_atom_t atom)
Definition: xcb.c:343
static void release_pointer(void)
Definition: xcb.c:1403
struct _xcb_stuff xcb_int
Definition: xcb.c:85
xcb_depth_t * depth
Definition: xcb.c:96
static int monitor_active_from_winid(xcb_drawable_t id, workarea *mon)
Definition: xcb.c:792
static void x11_create_visual_and_colormap(void)
Definition: xcb.c:1595
static gboolean x11_button_to_nk_bindings_scroll(guint32 x11_button, NkBindingsScrollAxis *axis, gint32 *steps)
Definition: xcb.c:1104
static void monitor_dimensions(int x, int y, workarea *mon)
Definition: xcb.c:749
void rofi_xcb_revert_input_focus(void)
Definition: xcb.c:1333
static uint32_t * create_kernel(double radius, double deviation, uint32_t *sum2)
Definition: xcb.c:139
static void x11_lookup_cursors(void)
Definition: xcb.c:1638
void rofi_xcb_set_input_focus(xcb_window_t w)
Definition: xcb.c:1310
static gboolean lazy_grab_keyboard(G_GNUC_UNUSED gpointer data)
Definition: xcb.c:1674
static xcb_visualtype_t * lookup_visual(xcb_screen_t *s, xcb_visualid_t visual)
Definition: xcb.c:121
#define INTERSECT(x, y, x1, y1, w1, h1)
Definition: xcb.c:77
static void error_trap_pop(G_GNUC_UNUSED SnDisplay *display, xcb_connection_t *xdisplay)
Definition: xcb.c:1414
void x11_set_cursor(xcb_window_t window, X11CursorType type)
Definition: xcb.c:1781
cairo_surface_t * x11_helper_get_bg_surface(void)
Definition: xcb.c:363
workarea mon_cache
Definition: xcb.c:970
unsigned int lazy_grab_retry_count_pt
Definition: xcb.c:1660
static xcb_visualtype_t * root_visual
Definition: xcb.c:102
static void x11_create_frequently_used_atoms(void)
Definition: xcb.c:1428
static int monitor_active_from_id_focused(int mon_id, workarea *mon)
Definition: xcb.c:822
static gboolean x11_button_to_nk_bindings_button(guint32 x11_button, NkBindingsMouseButton *button)
Definition: xcb.c:1075
xcb_cursor_t cursors[NUM_CURSORS]
Definition: xcb.c:109
static void x11_monitor_free(workarea *m)
Definition: xcb.c:416
cairo_surface_t * x11_helper_get_screenshot_surface_window(xcb_window_t window, int size)
Definition: xcb.c:276
static void x11_helper_discover_window_manager(void)
Definition: xcb.c:1442
static int monitor_get_dimension(int monitor_id, workarea *mon)
Definition: xcb.c:734
static int take_keyboard(xcb_window_t w, int iters)
Definition: xcb.c:1372
xcb_window_t xcb_stuff_get_root_window(void)
Definition: xcb.c:1722
gboolean mon_set
Definition: xcb.c:969
unsigned int lazy_grab_retry_count_kb
Definition: xcb.c:1658
static void rofi_view_paste(RofiViewState *state, xcb_selection_notify_event_t *xse)
Definition: xcb.c:1052
const char * css_name
Definition: xcb.c:115
void window_set_atom_prop(xcb_window_t w, xcb_atom_t prop, xcb_atom_t *atoms, int count)
Definition: xcb.c:403
const char * netatom_names[]
Definition: xcb.c:104
void cairo_image_surface_blur(cairo_surface_t *surface, double radius, double deviation)
Definition: xcb.c:167
static int monitor_active_from_id(int mon_id, workarea *mon)
Definition: xcb.c:892
static void x11_monitors_free(void)
Definition: xcb.c:421
gboolean display_setup(GMainLoop *main_loop, NkBindings *bindings)
Definition: xcb.c:1466
void display_dump_monitor_layout(void)
Definition: xcb.c:666
static void error_trap_push(G_GNUC_UNUSED SnDisplay *display, G_GNUC_UNUSED xcb_connection_t *xdisplay)
Definition: xcb.c:1409
WindowManagerQuirk current_window_manager
Definition: xcb.c:80
static int pointer_get(xcb_window_t root, int *x, int *y)
Definition: xcb.c:776
#define RANDR_PREF_MINOR_VERSION
Definition: xcb.c:74
#define sn_launcher_context_set_application_id
Definition: xcb.c:56
static int error_trap_depth
Definition: xcb.c:1408
static void release_keyboard(void)
Definition: xcb.c:1400
char * window_get_text_prop(xcb_window_t w, xcb_atom_t atom)
Definition: xcb.c:377
static gboolean main_loop_x11_event_handler(xcb_generic_event_t *ev, G_GNUC_UNUSED gpointer user_data)
Definition: xcb.c:1265
void x11_disable_decoration(xcb_window_t window)
Definition: xcb.c:1757
static void main_loop_x11_event_handler_view(xcb_generic_event_t *event)
Definition: xcb.c:1130
static workarea * x11_get_monitor_from_output(xcb_randr_output_t out)
Definition: xcb.c:432
xcb_atom_t netatoms[NUM_NETATOMS]
Definition: xcb.c:103
xcb_visualtype_t * visual
Definition: xcb.c:97
#define ATOM_CHAR(x)
Definition: xcb.h:76
WindowManagerQuirk
Definition: xcb.h:195
@ WM_PANGO_WORKSPACE_NAMES
Definition: xcb.h:201
@ WM_DO_NOT_CHANGE_CURRENT_DESKTOP
Definition: xcb.h:199
@ WM_EWHM
Definition: xcb.h:197
@ WM_ROOT_WINDOW_OFFSET
Definition: xcb.h:203
X11CursorType
Definition: xcb.h:174
@ NUM_CURSORS
Definition: xcb.h:181
@ NUM_NETATOMS
Definition: xcb.h:85
@ EWMH_ATOMS
Definition: xcb.h:85