From 8720409ad3da70e2097073ecc5d1b16a1e4e9600 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Tue, 17 Aug 2021 18:16:25 +0200 Subject: [PATCH] [Window] Allow rofi to stay active on closing a window ```css configuration { window { close-on-delete: false; } } ``` fixes: #1071 --- doc/rofi.1 | 16 ++++++++++++++++ doc/rofi.1.markdown | 10 ++++++++++ source/dialogs/window.c | 38 +++++++++++++++++++++++++++++--------- 3 files changed, 55 insertions(+), 9 deletions(-) diff --git a/doc/rofi.1 b/doc/rofi.1 index fcd9e4d5..73f0afbc 100644 --- a/doc/rofi.1 +++ b/doc/rofi.1 @@ -887,6 +887,22 @@ Default: \fI"wmctrl \-i \-R {window}"\fP .PP Show window thumbnail (if available) as icon in the window switcher. +.PP +You can stop rofi from existing when closing a window (allowing multiple to be closed in a row). + +.PP +.RS + +.nf +configuration { + window { + close\-on\-delete: false; + } +} + +.fi +.RE + .SS Combi settings .PP \fB\fC\-combi\-modi\fR \fImode1\fP,\fImode2\fP diff --git a/doc/rofi.1.markdown b/doc/rofi.1.markdown index 253af81e..7597acc1 100644 --- a/doc/rofi.1.markdown +++ b/doc/rofi.1.markdown @@ -525,6 +525,16 @@ Default: *"wmctrl -i -R {window}"* Show window thumbnail (if available) as icon in the window switcher. +You can stop rofi from existing when closing a window (allowing multiple to be closed in a row). + +```css +configuration { + window { + close-on-delete: false; + } +} +``` + ### Combi settings `-combi-modi` *mode1*,*mode2* diff --git a/source/dialogs/window.c b/source/dialogs/window.c index cea263c9..527fa43a 100644 --- a/source/dialogs/window.c +++ b/source/dialogs/window.c @@ -58,6 +58,7 @@ #include "timings.h" #include "rofi-icon-fetcher.h" +#include "mode-private.h" #define WINLIST 32 @@ -181,20 +182,27 @@ static int winlist_append ( winlist *l, xcb_window_t w, client *d ) return l->len - 1; } +static void client_free ( client *c ) +{ + if ( c == NULL ) { + return; + } + if ( c->icon ) { + cairo_surface_destroy ( c->icon ); + } + g_free ( c->title ); + g_free ( c->class ); + g_free ( c->name ); + g_free ( c->role ); + g_free ( c->wmdesktopstr ); +} static void winlist_empty ( winlist *l ) { while ( l->len > 0 ) { client *c = l->data[--l->len]; if ( c != NULL ) { - if ( c->icon ) { - cairo_surface_destroy ( c->icon ); - } - g_free ( c->title ); - g_free ( c->class ); - g_free ( c->name ); - g_free ( c->role ); - g_free ( c->wmdesktopstr ); - g_free ( c ); + client_free ( c ); + g_free ( c ); } } } @@ -710,6 +718,18 @@ static ModeMode window_mode_result ( Mode *sw, int mretv, G_GNUC_UNUSED char **i else if ( ( mretv & ( MENU_ENTRY_DELETE ) ) == MENU_ENTRY_DELETE ) { xcb_ewmh_request_close_window ( &( xcb->ewmh ), xcb->screen_nbr, rmpd->ids->array[selected_line], XCB_CURRENT_TIME, XCB_EWMH_CLIENT_SOURCE_TYPE_OTHER ); xcb_flush ( xcb->connection ); + ThemeWidget *wid = rofi_config_find_widget ( sw->name, NULL, TRUE ); + Property *p = rofi_theme_find_property ( wid, P_BOOLEAN, "close-on-delete", TRUE ); + if ( p && p->type == P_BOOLEAN && p->value.b == FALSE ){ + // Force a reload. + client_free ( rmpd->ids->data[selected_line] ); + g_free ( rmpd->ids->data[selected_line] ); + memmove(&(rmpd->ids->array[selected_line]), &(rmpd->ids->array[selected_line+1]), rmpd->ids->len-selected_line); + memmove(&(rmpd->ids->data[selected_line]), &(rmpd->ids->data[selected_line+1]), rmpd->ids->len-selected_line); + rmpd->ids->len--; + + retv = RELOAD_DIALOG; + } } else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] != '\0' ) { GError *error = NULL;