29#define G_LOG_DOMAIN "Modes.Window"
43#include <xcb/xcb_atom.h>
44#include <xcb/xcb_ewmh.h>
45#include <xcb/xcb_icccm.h>
67#define CLIENTWINDOWTYPE 10
76 WIN_MATCH_FIELD_TITLE,
77 WIN_MATCH_FIELD_CLASS,
80 WIN_MATCH_FIELD_DESKTOP,
82} WinModeMatchingFields;
84static WinModeField matching_window_fields[WIN_MATCH_NUM_FIELDS] = {
86 .field_name =
"title",
90 .field_name =
"class",
102 .field_name =
"desktop",
106static gboolean window_matching_fields_parsed = FALSE;
111 xcb_get_window_attributes_reply_t xattr;
117 xcb_atom_t state[CLIENTSTATE];
119 xcb_atom_t window_type[CLIENTWINDOWTYPE];
125 unsigned int wmdesktopstr_len;
126 cairo_surface_t *
icon;
127 gboolean icon_checked;
128 uint32_t icon_fetch_uid;
129 uint32_t icon_fetch_size;
130 guint icon_fetch_scale;
131 gboolean thumbnail_checked;
132 gboolean icon_theme_checked;
148 unsigned int wmdn_len;
149 unsigned int clf_len;
150 unsigned int name_len;
151 unsigned int title_len;
152 unsigned int role_len;
153 GRegex *window_regex;
155 gboolean hide_active_window;
156 gboolean prefer_icon_theme;
157} WindowModePrivateData;
159winlist *cache_client = NULL;
166static winlist *winlist_new(
void) {
167 winlist *l = g_malloc(
sizeof(winlist));
169 l->array = g_malloc_n(WINLIST + 1,
sizeof(
xcb_window_t));
170 l->data = g_malloc_n(WINLIST + 1,
sizeof(client *));
183static int winlist_append(winlist *l,
xcb_window_t w, client *d) {
184 if (l->len > 0 && !(l->len % WINLIST)) {
186 g_realloc(l->array,
sizeof(
xcb_window_t) * (l->len + WINLIST + 1));
187 l->data = g_realloc(l->data,
sizeof(client *) * (l->len + WINLIST + 1));
191 if (l->data == NULL || l->array == NULL) {
196 l->array[l->len++] = w;
200static void client_free(client *c) {
205 cairo_surface_destroy(c->icon);
211 g_free(c->wmdesktopstr);
213static void winlist_empty(winlist *l) {
215 client *c = l->data[--l->len];
228static void winlist_free(winlist *l) {
253 for (i = (l->len - 1); i >= 0; i--) {
254 if (l->array[i] == w) {
264static void x11_cache_create(
void) {
265 if (cache_client == NULL) {
266 cache_client = winlist_new();
273static void x11_cache_free(
void) {
274 winlist_free(cache_client);
287static xcb_get_window_attributes_reply_t *
289 xcb_get_window_attributes_cookie_t c =
290 xcb_get_window_attributes(
xcb->connection, w);
291 xcb_get_window_attributes_reply_t *r =
292 xcb_get_window_attributes_reply(
xcb->connection, c, NULL);
299static int client_has_state(client *c, xcb_atom_t state) {
300 for (
int i = 0; i < c->states; i++) {
301 if (c->state[i] == state) {
308static int client_has_window_type(client *c, xcb_atom_t type) {
309 for (
int i = 0; i < c->window_types; i++) {
310 if (c->window_type[i] == type) {
318static client *window_client(WindowModePrivateData *pd,
xcb_window_t win) {
323 int idx = winlist_find(cache_client, win);
326 return cache_client->data[idx];
330 xcb_get_window_attributes_reply_t *attr = window_get_attributes(win);
335 client *c = g_malloc0(
sizeof(client));
339 memmove(&c->xattr, attr,
sizeof(xcb_get_window_attributes_reply_t));
341 xcb_get_property_cookie_t cky = xcb_ewmh_get_wm_state(&
xcb->ewmh, win);
342 xcb_ewmh_get_atoms_reply_t states;
343 if (xcb_ewmh_get_wm_state_reply(&
xcb->ewmh, cky, &states, NULL)) {
344 c->states = MIN(CLIENTSTATE, states.atoms_len);
345 memcpy(c->state, states.atoms,
346 MIN(CLIENTSTATE, states.atoms_len) *
sizeof(xcb_atom_t));
347 xcb_ewmh_get_atoms_reply_wipe(&states);
349 cky = xcb_ewmh_get_wm_window_type(&
xcb->ewmh, win);
350 if (xcb_ewmh_get_wm_window_type_reply(&
xcb->ewmh, cky, &states, NULL)) {
351 c->window_types = MIN(CLIENTWINDOWTYPE, states.atoms_len);
352 memcpy(c->window_type, states.atoms,
353 MIN(CLIENTWINDOWTYPE, states.atoms_len) *
sizeof(xcb_atom_t));
354 xcb_ewmh_get_atoms_reply_wipe(&states);
358 if (tmp_title == NULL) {
361 if (tmp_title != NULL) {
362 c->title = g_markup_escape_text(tmp_title, -1);
364 c->title = g_strdup(
"<i>no title set</i>");
367 MAX(c->title ? g_utf8_strlen(c->title, -1) : 0, pd->title_len);
371 c->role = g_markup_escape_text(tmp_role ? tmp_role :
"", -1);
372 pd->role_len = MAX(c->role ? g_utf8_strlen(c->role, -1) : 0, pd->role_len);
375 cky = xcb_icccm_get_wm_class(
xcb->connection, c->window);
376 xcb_icccm_get_wm_class_reply_t wcr;
377 if (xcb_icccm_get_wm_class_reply(
xcb->connection, cky, &wcr, NULL)) {
378 c->class = g_markup_escape_text(wcr.class_name, -1);
379 c->name = g_markup_escape_text(wcr.instance_name, -1);
380 pd->name_len = MAX(c->name ? g_utf8_strlen(c->name, -1) : 0, pd->name_len);
381 xcb_icccm_get_wm_class_reply_wipe(&wcr);
384 xcb_get_property_cookie_t cc =
385 xcb_icccm_get_wm_hints(
xcb->connection, c->window);
386 xcb_icccm_wm_hints_t r;
387 if (xcb_icccm_get_wm_hints_reply(
xcb->connection, cc, &r, NULL)) {
388 c->hint_flags = r.flags;
391 idx = winlist_append(cache_client, c->window, c);
402guint window_reload_timeout = 0;
403static gboolean window_client_reload(G_GNUC_UNUSED
void *data) {
404 window_reload_timeout = 0;
405 if (window_mode.private_data) {
406 window_mode._destroy(&window_mode);
407 window_mode._init(&window_mode);
409 if (window_mode_cd.private_data) {
410 window_mode_cd._destroy(&window_mode_cd);
411 window_mode_cd._init(&window_mode_cd);
413 if (window_mode.private_data || window_mode_cd.private_data) {
416 return G_SOURCE_REMOVE;
418void window_client_handle_signal(G_GNUC_UNUSED
xcb_window_t win,
419 G_GNUC_UNUSED gboolean create) {
421 if (window_reload_timeout > 0) {
422 g_source_remove(window_reload_timeout);
423 window_reload_timeout = 0;
425 window_reload_timeout = g_timeout_add(100, window_client_reload, NULL);
428 unsigned int index) {
429 WindowModePrivateData *rmpd =
432 const winlist *ids = (winlist *)rmpd->ids;
434 int idx = winlist_find(cache_client, ids->array[index]);
436 client *c = cache_client->data[idx];
439 for (
int j = 0; match && tokens[j] != NULL; j++) {
446 if (c->title != NULL && c->title[0] !=
'\0' &&
447 matching_window_fields[WIN_MATCH_FIELD_TITLE].enabled) {
451 if (test == tokens[j]->invert && c->class != NULL &&
452 c->class[0] !=
'\0' &&
453 matching_window_fields[WIN_MATCH_FIELD_CLASS].enabled) {
457 if (test == tokens[j]->invert && c->role != NULL && c->role[0] !=
'\0' &&
458 matching_window_fields[WIN_MATCH_FIELD_ROLE].enabled) {
462 if (test == tokens[j]->invert && c->name != NULL && c->name[0] !=
'\0' &&
463 matching_window_fields[WIN_MATCH_FIELD_NAME].enabled) {
466 if (test == tokens[j]->invert && c->wmdesktopstr != NULL &&
467 c->wmdesktopstr[0] !=
'\0' &&
468 matching_window_fields[WIN_MATCH_FIELD_DESKTOP].enabled) {
481static void window_mode_parse_fields(
void) {
482 window_matching_fields_parsed = TRUE;
485 char *switcher_str = g_strdup(
config.window_match_fields);
486 const char *
const sep =
",#";
488 for (
unsigned int i = 0; i < WIN_MATCH_NUM_FIELDS; i++) {
489 matching_window_fields[i].enabled = FALSE;
491 for (
char *token = strtok_r(switcher_str, sep, &savept); token != NULL;
492 token = strtok_r(NULL, sep, &savept)) {
493 if (strcmp(token,
"all") == 0) {
494 for (
unsigned int i = 0; i < WIN_MATCH_NUM_FIELDS; i++) {
495 matching_window_fields[i].enabled = TRUE;
499 gboolean matched = FALSE;
500 for (
unsigned int i = 0; i < WIN_MATCH_NUM_FIELDS; i++) {
501 const char *field_name = matching_window_fields[i].field_name;
502 if (strcmp(token, field_name) == 0) {
503 matching_window_fields[i].enabled = TRUE;
508 g_warning(
"Invalid window field name :%s", token);
512 g_free(switcher_str);
515static unsigned int window_mode_get_num_entries(
const Mode *sw) {
516 const WindowModePrivateData *pd =
519 return pd->ids ? pd->ids->len : 0;
525const char *invalid_desktop_name =
"n/a";
526static const char *_window_name_list_entry(
const char *str, uint32_t length,
530 while (index < entry && offset < length) {
531 if (str[offset] == 0) {
536 if (offset >= length) {
537 return invalid_desktop_name;
541static void _window_mode_load_data(
Mode *sw,
unsigned int cd) {
542 WindowModePrivateData *pd =
551 xcb_get_property_cookie_t c =
552 xcb_ewmh_get_active_window(&(
xcb->ewmh),
xcb->screen_nbr);
553 if (!xcb_ewmh_get_active_window_reply(&
xcb->ewmh, c, &curr_win_id, NULL)) {
558 unsigned int current_desktop = 0;
559 c = xcb_ewmh_get_current_desktop(&
xcb->ewmh,
xcb->screen_nbr);
560 if (!xcb_ewmh_get_current_desktop_reply(&
xcb->ewmh, c, ¤t_desktop,
565 g_debug(
"Get list from: %d",
xcb->screen_nbr);
566 c = xcb_ewmh_get_client_list_stacking(&
xcb->ewmh,
xcb->screen_nbr);
567 xcb_ewmh_get_windows_reply_t clients = {
570 if (xcb_ewmh_get_client_list_stacking_reply(&
xcb->ewmh, c, &clients, NULL)) {
573 c = xcb_ewmh_get_client_list(&
xcb->ewmh,
xcb->screen_nbr);
574 if (xcb_ewmh_get_client_list_reply(&
xcb->ewmh, c, &clients, NULL)) {
582 if (clients.windows_len > 0) {
587 pd->ids = winlist_new();
589 int has_names = FALSE;
590 ssize_t ws_names_length = 0;
591 char *ws_names = NULL;
592 xcb_get_property_cookie_t prop_cookie =
593 xcb_ewmh_get_desktop_names(&
xcb->ewmh,
xcb->screen_nbr);
594 xcb_ewmh_get_utf8_strings_reply_t names;
595 if (xcb_ewmh_get_desktop_names_reply(&
xcb->ewmh, prop_cookie, &names,
597 ws_names_length = names.strings_len;
598 ws_names = g_malloc0_n(names.strings_len + 1,
sizeof(
char));
599 memcpy(ws_names, names.strings, names.strings_len);
601 xcb_ewmh_get_utf8_strings_reply_wipe(&names);
604 for (i = clients.windows_len - 1; i > -1; i--) {
605 client *winclient = window_client(pd, clients.windows[i]);
606 if ((winclient != NULL) && !winclient->xattr.override_redirect &&
607 !client_has_window_type(winclient,
608 xcb->ewmh._NET_WM_WINDOW_TYPE_DOCK) &&
609 !client_has_window_type(winclient,
610 xcb->ewmh._NET_WM_WINDOW_TYPE_DESKTOP) &&
611 !client_has_state(winclient,
xcb->ewmh._NET_WM_STATE_SKIP_PAGER) &&
612 !client_has_state(winclient,
xcb->ewmh._NET_WM_STATE_SKIP_TASKBAR)) {
614 MAX(pd->clf_len, (winclient->class != NULL)
615 ? (g_utf8_strlen(winclient->class, -1))
618 if (client_has_state(winclient,
619 xcb->ewmh._NET_WM_STATE_DEMANDS_ATTENTION)) {
620 winclient->demands = TRUE;
622 if ((winclient->hint_flags & XCB_ICCCM_WM_HINT_X_URGENCY) != 0) {
623 winclient->demands = TRUE;
626 if (winclient->window == curr_win_id) {
627 winclient->active = TRUE;
630 xcb_get_property_cookie_t cookie;
631 xcb_get_property_reply_t *r;
633 winclient->wmdesktop = 0xFFFFFFFF;
634 cookie = xcb_get_property(
xcb->connection, 0, winclient->window,
635 xcb->ewmh._NET_WM_DESKTOP, XCB_ATOM_CARDINAL,
637 r = xcb_get_property_reply(
xcb->connection, cookie, NULL);
639 if (r->type == XCB_ATOM_CARDINAL) {
640 winclient->wmdesktop = *((uint32_t *)xcb_get_property_value(r));
644 if (winclient->wmdesktop != 0xFFFFFFFF) {
649 if (pango_parse_markup(
650 _window_name_list_entry(ws_names, ws_names_length,
651 winclient->wmdesktop),
652 -1, 0, NULL, &output, NULL, NULL)) {
653 winclient->wmdesktopstr = g_strdup(_window_name_list_entry(
654 ws_names, ws_names_length, winclient->wmdesktop));
655 winclient->wmdesktopstr_len = g_utf8_strlen(output, -1);
656 pd->wmdn_len = MAX(pd->wmdn_len, winclient->wmdesktopstr_len);
659 winclient->wmdesktopstr = g_strdup(
"Invalid name");
660 winclient->wmdesktopstr_len =
661 g_utf8_strlen(winclient->wmdesktopstr, -1);
662 pd->wmdn_len = MAX(pd->wmdn_len, winclient->wmdesktopstr_len);
665 winclient->wmdesktopstr = g_markup_escape_text(
666 _window_name_list_entry(ws_names, ws_names_length,
667 winclient->wmdesktop),
669 winclient->wmdesktopstr_len =
670 g_utf8_strlen(winclient->wmdesktopstr, -1);
671 pd->wmdn_len = MAX(pd->wmdn_len, winclient->wmdesktopstr_len);
674 winclient->wmdesktopstr =
675 g_strdup_printf(
"%u", (uint32_t)winclient->wmdesktop);
676 winclient->wmdesktopstr_len =
677 g_utf8_strlen(winclient->wmdesktopstr, -1);
678 pd->wmdn_len = MAX(pd->wmdn_len, winclient->wmdesktopstr_len);
681 winclient->wmdesktopstr = g_strdup(
"");
682 winclient->wmdesktopstr_len =
683 g_utf8_strlen(winclient->wmdesktopstr, -1);
684 pd->wmdn_len = MAX(pd->wmdn_len, winclient->wmdesktopstr_len);
686 if (cd && winclient->wmdesktop != current_desktop) {
689 if (!pd->hide_active_window || winclient->window != curr_win_id) {
690 winlist_append(pd->ids, winclient->window, NULL);
699 xcb_ewmh_get_windows_reply_wipe(&clients);
701static int window_mode_init(
Mode *sw) {
704 WindowModePrivateData *pd = g_malloc0(
sizeof(*pd));
709 pd->hide_active_window = TRUE;
714 pd->prefer_icon_theme = TRUE;
716 pd->window_regex = g_regex_new(
"{[-\\w]+(:-?[0-9]+)?}", 0, 0, NULL);
718 _window_mode_load_data(sw, FALSE);
719 if (!window_matching_fields_parsed) {
720 window_mode_parse_fields();
725static int window_mode_init_cd(
Mode *sw) {
727 WindowModePrivateData *pd = g_malloc0(
sizeof(*pd));
733 pd->hide_active_window = TRUE;
735 pd->window_regex = g_regex_new(
"{[-\\w]+(:-?[0-9]+)?}", 0, 0, NULL);
737 _window_mode_load_data(sw, TRUE);
738 if (!window_matching_fields_parsed) {
739 window_mode_parse_fields();
749 char window_regex[100];
751 g_snprintf(window_regex,
sizeof window_regex,
"%d", window);
754 window_regex, (
char *)0);
756 GError *error = NULL;
757 g_spawn_async(NULL, args, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL,
760 char *msg = g_strdup_printf(
761 "Failed to execute action for window: '%s'\nError: '%s'", window_regex,
776 G_GNUC_UNUSED
char **input,
777 unsigned int selected_line) {
778 WindowModePrivateData *rmpd =
783 act_on_window(rmpd->ids->array[selected_line]);
786 xcb->focus_revert = 0;
790 uint32_t wmdesktop = 0;
791 xcb_get_property_cookie_t cookie;
792 xcb_get_property_reply_t *r;
794 unsigned int current_desktop = 0;
795 xcb_get_property_cookie_t c =
796 xcb_ewmh_get_current_desktop(&
xcb->ewmh,
xcb->screen_nbr);
797 if (!xcb_ewmh_get_current_desktop_reply(&
xcb->ewmh, c, ¤t_desktop,
802 cookie = xcb_get_property(
803 xcb->connection, 0, rmpd->ids->array[selected_line],
804 xcb->ewmh._NET_WM_DESKTOP, XCB_ATOM_CARDINAL, 0, 1);
805 r = xcb_get_property_reply(
xcb->connection, cookie, NULL);
806 if (r && r->type == XCB_ATOM_CARDINAL) {
807 wmdesktop = *((uint32_t *)xcb_get_property_value(r));
809 if (r && r->type != XCB_ATOM_CARDINAL) {
811 wmdesktop = current_desktop;
816 if (wmdesktop != current_desktop) {
817 xcb_ewmh_request_change_current_desktop(&
xcb->ewmh,
xcb->screen_nbr,
818 wmdesktop, XCB_CURRENT_TIME);
822 xcb_ewmh_request_change_active_window(
823 &
xcb->ewmh,
xcb->screen_nbr, rmpd->ids->array[selected_line],
824 XCB_EWMH_CLIENT_SOURCE_TYPE_OTHER, XCB_CURRENT_TIME,
826 xcb_flush(
xcb->connection);
829 xcb_ewmh_request_close_window(
830 &(
xcb->ewmh),
xcb->screen_nbr, rmpd->ids->array[selected_line],
831 XCB_CURRENT_TIME, XCB_EWMH_CLIENT_SOURCE_TYPE_OTHER);
832 xcb_flush(
xcb->connection);
842 GError *error = NULL;
844 gsize lf_cmd_size = 0;
845 gchar *lf_cmd = g_locale_from_utf8(*input, -1, NULL, &lf_cmd_size, &error);
847 g_warning(
"Failed to convert command to locale encoding: %s",
855 run_in_term ? &context : NULL)) {
865static void window_mode_destroy(
Mode *sw) {
866 WindowModePrivateData *rmpd =
869 winlist_free(rmpd->ids);
872 g_regex_unref(rmpd->window_regex);
878 const WindowModePrivateData *pd;
882static void helper_eval_add_str(GString *str,
const char *input,
int l,
883 int max_len,
int nc) {
885 const char *input_nn = input ? input :
"";
890 int bl = g_utf8_offset_to_pointer(input_nn, l) - input_nn;
891 char *tmp = g_markup_escape_text(input_nn, bl);
892 g_string_append(str, tmp);
896 char *tmp = g_markup_escape_text(input_nn, -1);
897 g_string_append(str, tmp);
901 g_string_append(str, input_nn);
903 spaces = MAX(0, max_len - nc);
907 g_string_append_c(str,
' ');
910static gboolean helper_eval_cb(
const GMatchInfo *info, GString *str,
912 struct arg *d = (
struct arg *)data;
915 match = g_match_info_fetch(info, 0);
918 if (match[2] ==
':') {
919 l = (int)g_ascii_strtoll(&match[3], NULL, 10);
921 if (match[1] ==
'w') {
922 helper_eval_add_str(str, d->c->wmdesktopstr, l, d->pd->wmdn_len,
923 d->c->wmdesktopstr_len);
924 }
else if (match[1] ==
'c') {
925 helper_eval_add_str(str, d->c->class, l, d->pd->clf_len,
926 g_utf8_strlen(d->c->class, -1));
927 }
else if (match[1] ==
't') {
928 helper_eval_add_str(str, d->c->title, l, d->pd->title_len,
929 g_utf8_strlen(d->c->title, -1));
930 }
else if (match[1] ==
'n') {
931 helper_eval_add_str(str, d->c->name, l, d->pd->name_len,
932 g_utf8_strlen(d->c->name, -1));
933 }
else if (match[1] ==
'r') {
934 helper_eval_add_str(str, d->c->role, l, d->pd->role_len,
935 g_utf8_strlen(d->c->role, -1));
942static char *_generate_display_string(
const WindowModePrivateData *pd,
944 struct arg d = {pd, c};
945 char *res = g_regex_replace_eval(pd->window_regex,
config.window_format, -1,
946 0, 0, helper_eval_cb, &d, NULL);
947 return g_strchomp(res);
951 int *state, G_GNUC_UNUSED GList **list,
954 const client *c = window_client(rmpd, rmpd->ids->array[selected_line]);
956 return get_entry ? g_strdup(
"Window has vanished") : NULL;
965 return get_entry ? _generate_display_string(rmpd, c) : NULL;
971static cairo_user_data_key_t data_key;
979static cairo_surface_t *draw_surface_from_data(uint32_t width, uint32_t height,
980 uint32_t
const *
const data) {
982 if (width >= 65536 || height >= 65536) {
985 uint32_t len = width * height;
987 uint32_t *buffer = g_new0(uint32_t, len);
988 cairo_surface_t *surface;
991 for (i = 0; i < len; i++) {
992 uint8_t a = (data[i] >> 24) & 0xff;
993 double alpha = a / 255.0;
994 uint8_t r = ((data[i] >> 16) & 0xff) * alpha;
995 uint8_t g = ((data[i] >> 8) & 0xff) * alpha;
996 uint8_t b = ((data[i] >> 0) & 0xff) * alpha;
997 buffer[i] = (a << 24) | (r << 16) | (g << 8) | b;
1000 surface = cairo_image_surface_create_for_data(
1001 (
unsigned char *)buffer, CAIRO_FORMAT_ARGB32, width, height, width * 4);
1003 cairo_surface_set_user_data(surface, &data_key, buffer, g_free);
1007static cairo_surface_t *ewmh_window_icon_from_reply(xcb_get_property_reply_t *r,
1008 uint32_t preferred_size) {
1009 uint32_t *data, *end, *found_data = 0;
1010 uint32_t found_size = 0;
1012 if (!r || r->type != XCB_ATOM_CARDINAL || r->format != 32 || r->length < 2) {
1016 data = (uint32_t *)xcb_get_property_value(r);
1021 end = data + r->length;
1027 while (data + 1 < end) {
1030 uint64_t data_size = (uint64_t)data[0] * data[1];
1031 if (data_size > (uint64_t)(end - data - 2)) {
1038 uint32_t size = MAX(data[0], data[1]);
1041 gboolean found_icon_too_small = found_size < preferred_size;
1042 gboolean found_icon_too_large = found_size > preferred_size;
1043 gboolean icon_empty = data[0] == 0 || data[1] == 0;
1044 gboolean better_because_bigger = found_icon_too_small && size > found_size;
1045 gboolean better_because_smaller =
1046 found_icon_too_large && size >= preferred_size && size < found_size;
1048 (better_because_bigger || better_because_smaller || found_size == 0)) {
1053 data += data_size + 2;
1060 return draw_surface_from_data(found_data[0], found_data[1], found_data + 2);
1063static cairo_surface_t *get_net_wm_icon(
xcb_window_t xid,
1064 uint32_t preferred_size) {
1065 xcb_get_property_cookie_t cookie = xcb_get_property_unchecked(
1066 xcb->connection, FALSE, xid,
xcb->ewmh._NET_WM_ICON, XCB_ATOM_CARDINAL, 0,
1068 xcb_get_property_reply_t *r =
1069 xcb_get_property_reply(
xcb->connection, cookie, NULL);
1070 cairo_surface_t *surface = ewmh_window_icon_from_reply(r, preferred_size);
1074static cairo_surface_t *
_get_icon(
const Mode *sw,
unsigned int selected_line,
1075 unsigned int size) {
1078 client *c = window_client(rmpd, rmpd->ids->array[selected_line]);
1082 if (c->icon_fetch_size != size || c->icon_fetch_scale != scale) {
1084 cairo_surface_destroy(c->icon);
1087 c->thumbnail_checked = FALSE;
1088 c->icon_checked = FALSE;
1089 c->icon_theme_checked = FALSE;
1092 if (
config.window_thumbnail && c->thumbnail_checked == FALSE) {
1094 c->thumbnail_checked = TRUE;
1096 if (rmpd->prefer_icon_theme == FALSE) {
1097 if (c->icon == NULL && c->icon_checked == FALSE) {
1098 c->icon = get_net_wm_icon(rmpd->ids->array[selected_line], size);
1099 c->icon_checked = TRUE;
1101 if (c->icon == NULL && c->class && c->icon_theme_checked == FALSE) {
1102 if (c->icon_fetch_uid == 0) {
1103 char *class_lower = g_utf8_strdown(c->class, -1);
1105 g_free(class_lower);
1106 c->icon_fetch_size = size;
1107 c->icon_fetch_scale = scale;
1109 c->icon_theme_checked =
1112 cairo_surface_reference(c->icon);
1116 if (c->icon == NULL && c->class && c->icon_theme_checked == FALSE) {
1117 if (c->icon_fetch_uid == 0 || c->icon_fetch_size != size ||
1118 c->icon_fetch_scale != scale) {
1119 char *class_lower = g_utf8_strdown(c->class, -1);
1121 g_free(class_lower);
1122 c->icon_fetch_size = size;
1123 c->icon_fetch_scale = scale;
1125 c->icon_theme_checked =
1128 cairo_surface_reference(c->icon);
1131 if (c->icon_theme_checked == TRUE && c->icon == NULL &&
1132 c->icon_checked == FALSE) {
1133 c->icon = get_net_wm_icon(rmpd->ids->array[selected_line], size);
1134 c->icon_checked = TRUE;
1137 c->icon_fetch_size = size;
1138 c->icon_fetch_scale = scale;
1143Mode window_mode = {.name =
"window",
1144 .cfg_name_key =
"display-window",
1145 ._init = window_mode_init,
1146 ._get_num_entries = window_mode_get_num_entries,
1147 ._result = window_mode_result,
1148 ._destroy = window_mode_destroy,
1149 ._token_match = window_match,
1152 ._get_completion = NULL,
1153 ._preprocess_input = NULL,
1154 .private_data = NULL,
1157Mode window_mode_cd = {.name =
"windowcd",
1158 .cfg_name_key =
"display-windowcd",
1159 ._init = window_mode_init_cd,
1160 ._get_num_entries = window_mode_get_num_entries,
1161 ._result = window_mode_result,
1162 ._destroy = window_mode_destroy,
1163 ._token_match = window_match,
1166 ._get_completion = NULL,
1167 ._preprocess_input = NULL,
1168 .private_data = NULL,
guint display_scale(void)
static cairo_surface_t * _get_icon(const Mode *sw, unsigned int selected_line, unsigned int height)
static char * _get_display_value(const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, G_GNUC_UNUSED GList **attr_list, int get_entry)
Property * rofi_theme_find_property(ThemeWidget *wid, PropertyType type, const char *property, gboolean exact)
gboolean helper_execute_command(const char *wd, const char *cmd, gboolean run_in_term, RofiHelperExecuteContext *context)
ThemeWidget * rofi_config_find_widget(const char *name, const char *state, gboolean exact)
int helper_parse_setup(char *string, char ***output, int *length,...)
int helper_token_match(rofi_int_matcher *const *tokens, const char *input)
gboolean rofi_icon_fetcher_get_ex(const uint32_t uid, cairo_surface_t **surface)
uint32_t rofi_icon_fetcher_query(const char *name, const int size)
void * mode_get_private_data(const Mode *mode)
void mode_set_private_data(Mode *mode, void *pd)
void rofi_view_hide(void)
void rofi_view_reload(void)
xcb_window_t rofi_view_get_window(void)
int rofi_view_error_dialog(const char *msg, int markup)
struct rofi_int_matcher_t rofi_int_matcher
char * window_get_text_prop(xcb_window_t w, xcb_atom_t atom)
WindowManagerQuirk current_window_manager
xcb_atom_t netatoms[NUM_NETATOMS]
cairo_surface_t * x11_helper_get_screenshot_surface_window(xcb_window_t window, int size)
@ WM_PANGO_WORKSPACE_NAMES
@ WM_DO_NOT_CHANGE_CURRENT_DESKTOP