diff --git a/include/dialogs/window.h b/include/dialogs/window.h index af582596..4ebd091c 100644 --- a/include/dialogs/window.h +++ b/include/dialogs/window.h @@ -2,4 +2,5 @@ #define __WINDOW_DIALOG_H__ extern Switcher window_mode; +extern Switcher window_mode_cd; #endif // __WINDOW_DIALOG_H__ diff --git a/source/dialogs/window.c b/source/dialogs/window.c index ca94c660..80d0ad38 100644 --- a/source/dialogs/window.c +++ b/source/dialogs/window.c @@ -171,8 +171,12 @@ static int winlist_find ( winlist *l, Window w ) */ static void x11_cache_create ( void ) { - cache_client = winlist_new (); - cache_xattr = winlist_new (); + if ( cache_client == NULL ) { + cache_client = winlist_new (); + } + if ( cache_xattr == NULL ) { + cache_xattr = winlist_new (); + } } /** @@ -364,7 +368,7 @@ static void window_mode_init ( Switcher *sw ) } } -static char ** window_mode_get_data ( unsigned int *length, Switcher *sw ) +static char ** _window_mode_get_data ( unsigned int *length, Switcher *sw, unsigned int cd ) { SwitcherModePrivateData *pd = (SwitcherModePrivateData *) sw->private_data; if ( !pd->init ) { @@ -389,6 +393,12 @@ static char ** window_mode_get_data ( unsigned int *length, Switcher *sw ) curr_win_id = 0; } + // Get the current desktop. + unsigned long current_desktop = 0; + if ( !window_get_cardinal_prop ( display, root, netatoms[_NET_CURRENT_DESKTOP], ¤t_desktop, 1 ) ) { + current_desktop = 0; + } + if ( window_get_prop ( display, root, netatoms[_NET_CLIENT_LIST_STACKING], &type, &nwins, wins, 100 * sizeof ( Window ) ) && type == XA_WINDOW ) { @@ -457,6 +467,10 @@ static char ** window_mode_get_data ( unsigned int *length, Switcher *sw ) // Assume the client is on all desktops. wmdesktop = 0xFFFFFFFF; } + else if ( cd && wmdesktop != current_desktop ) { + g_free ( line ); + continue; + } if ( wmdesktop < 0xFFFFFFFF ) { sprintf ( desktop, "%d", (int) wmdesktop ); @@ -477,6 +491,14 @@ static char ** window_mode_get_data ( unsigned int *length, Switcher *sw ) *length = pd->cmd_list_length; return pd->cmd_list; } +static char ** window_mode_get_data_cd ( unsigned int *length, Switcher *sw ) +{ + return _window_mode_get_data ( length, sw, TRUE ); +} +static char ** window_mode_get_data ( unsigned int *length, Switcher *sw ) +{ + return _window_mode_get_data ( length, sw, FALSE ); +} static SwitcherMode window_mode_result ( int mretv, G_GNUC_UNUSED char **input, unsigned int selected_line, Switcher *sw ) { SwitcherModePrivateData *rmpd = (SwitcherModePrivateData *) sw->private_data; @@ -556,3 +578,19 @@ Switcher window_mode = .private_data = NULL, .free = NULL }; +Switcher window_mode_cd = +{ + .name = "windowcd", + .tb = NULL, + .keycfg = NULL, + .keystr = NULL, + .modmask = AnyModifier, + .init = window_mode_init, + .get_data = window_mode_get_data_cd, + .result = window_mode_result, + .destroy = window_mode_destroy, + .token_match = window_match, + .mgrv = mgrv, + .private_data = NULL, + .free = NULL +}; diff --git a/source/rofi.c b/source/rofi.c index 8bc82d98..b018bf6b 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -1593,6 +1593,10 @@ static void setup_switchers ( void ) switchers[num_switchers] = &window_mode; num_switchers++; } + else if ( strcasecmp ( token, "windowcd" ) == 0 ) { + switchers[num_switchers] = &window_mode_cd; + num_switchers++; + } // SSh dialog else if ( strcasecmp ( token, "ssh" ) == 0 ) { switchers[num_switchers] = &ssh_mode;