diff --git a/doc/rofi.1.markdown b/doc/rofi.1.markdown index 79f342b88..4ee0fa127 100644 --- a/doc/rofi.1.markdown +++ b/doc/rofi.1.markdown @@ -683,6 +683,19 @@ configuration { or pass `-window-hide-active-window true` on command line. +You can sort the currently active window to the top of the list with the +'sort-active-window-first' setting: + +```css +configuration { + window { + sort-active-window-first: true; + } +} +``` + +or pass `-sort-active-window-first true` on command line. + You can prefer the icon theme above the window set icon with the 'prefer-icon-theme' setting: diff --git a/source/modes/window.c b/source/modes/window.c index 9aa53c51d..4f0b793cb 100644 --- a/source/modes/window.c +++ b/source/modes/window.c @@ -26,6 +26,8 @@ */ /** The log domain of this dialog. */ +#include +#include #define G_LOG_DOMAIN "Modes.Window" #include "config.h" @@ -696,6 +698,25 @@ static void _window_mode_load_data(Mode *sw, unsigned int cd) { } xcb_ewmh_get_windows_reply_wipe(&clients); } + +static gint _window_mode_sort(gconstpointer a, gconstpointer b, gpointer data) { + WindowModePrivateData *pd = (WindowModePrivateData *)data; + gint wa = *(const int *)a; + gint wb = *(const int *)b; + const client *ca = window_client(pd, wa); + const client *cb = window_client(pd, wb); + if (ca == NULL || cb == NULL) { + return 0; + } + if (ca->active) { + return -1; + } + if (cb->active) { + return 1; + } + + return 0; +} static int window_mode_init(Mode *sw) { if (mode_get_private_data(sw) == NULL) { @@ -717,6 +738,13 @@ static int window_mode_init(Mode *sw) { if (!window_matching_fields_parsed) { window_mode_parse_fields(); } + // Sort active window first. + p = rofi_theme_find_property(wid, P_BOOLEAN, "sort-active-window-first", + FALSE); + if (p && p->type == P_BOOLEAN && p->value.b == TRUE) { + g_qsort_with_data(pd->ids->array, pd->ids->len, sizeof(xcb_window_t), + _window_mode_sort, pd); + } } return TRUE; } @@ -736,6 +764,13 @@ static int window_mode_init_cd(Mode *sw) { if (!window_matching_fields_parsed) { window_mode_parse_fields(); } + // Sort active window first. + p = rofi_theme_find_property(wid, P_BOOLEAN, "sort-active-window-first", + FALSE); + if (p && p->type == P_BOOLEAN && p->value.b == TRUE) { + g_qsort_with_data(pd->ids->array, pd->ids->len, sizeof(xcb_window_t), + _window_mode_sort, pd); + } } return TRUE; }