1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2025-04-14 17:43:01 -04:00

[Window] Allow active window to be sorted on top.

fixes: #2048
This commit is contained in:
Qball 2025-01-20 18:27:19 +01:00
parent 5b95abce92
commit 8542b3ee7e
2 changed files with 48 additions and 0 deletions

View file

@ -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:

View file

@ -26,6 +26,8 @@
*/
/** The log domain of this dialog. */
#include <X11/X.h>
#include <xcb/xproto.h>
#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;
}