Skip to content

Commit

Permalink
[Window] Allow active window to be sorted on top.
Browse files Browse the repository at this point in the history
fixes: #2048
  • Loading branch information
DaveDavenport committed Jan 20, 2025
1 parent 5b95abc commit 8542b3e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
13 changes: 13 additions & 0 deletions doc/rofi.1.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
35 changes: 35 additions & 0 deletions source/modes/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {

Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 8542b3e

Please sign in to comment.