From faf5c49b8cbadbe4cc731dd45629c40bab288445 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Tue, 23 Feb 2016 19:14:21 +0100 Subject: [PATCH 1/6] Remove hardcoded string length in window list. --- source/dialogs/window.c | 45 ++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/source/dialogs/window.c b/source/dialogs/window.c index 379f8005..9e6682a6 100644 --- a/source/dialogs/window.c +++ b/source/dialogs/window.c @@ -48,22 +48,18 @@ #define WINLIST 32 -#define CLIENTTITLE 100 -#define CLIENTCLASS 50 -#define CLIENTNAME 50 #define CLIENTSTATE 10 #define CLIENTWINDOWTYPE 10 -#define CLIENTROLE 50 // a manageable window typedef struct { Window window, trans; XWindowAttributes xattr; - char title[CLIENTTITLE]; - char class[CLIENTCLASS]; - char name[CLIENTNAME]; - char role[CLIENTROLE]; + char *title; + char *class; + char *name; + char *role; int states; Atom state[CLIENTSTATE]; int window_types; @@ -275,26 +271,25 @@ static client* window_client ( Display *display, Window win ) char *name; if ( ( name = window_get_text_prop ( display, c->window, netatoms[_NET_WM_NAME] ) ) && name ) { - snprintf ( c->title, CLIENTTITLE, "%s", name ); - g_free ( name ); + c->title = name; } else if ( XFetchName ( display, c->window, &name ) ) { - snprintf ( c->title, CLIENTTITLE, "%s", name ); + c->title = g_strdup(name); XFree ( name ); } name = window_get_text_prop ( display, c->window, XInternAtom ( display, "WM_WINDOW_ROLE", False ) ); if ( name != NULL ) { - snprintf ( c->role, CLIENTROLE, "%s", name ); + c->role = g_strdup(name); XFree ( name ); } XClassHint chint; if ( XGetClassHint ( display, c->window, &chint ) ) { - snprintf ( c->class, CLIENTCLASS, "%s", chint.res_class ); - snprintf ( c->name, CLIENTNAME, "%s", chint.res_name ); + c->class = g_strdup(chint.res_class); + c->name = g_strdup(chint.res_name); XFree ( chint.res_class ); XFree ( chint.res_name ); } @@ -342,19 +337,19 @@ static int window_match ( const Mode *sw, char **tokens, // If hack not in place it would not match queries spanning multiple fields. // e.g. when searching 'title element' and 'class element' char *ftokens[2] = { tokens[j], NULL }; - if ( !test && c->title[0] != '\0' ) { + if ( !test && c->title != NULL && c->title[0] != '\0' ) { test = token_match ( ftokens, c->title, not_ascii, case_sensitive ); } - if ( !test && c->class[0] != '\0' ) { + if ( !test && c->class != NULL && c->class[0] != '\0' ) { test = token_match ( ftokens, c->class, not_ascii, case_sensitive ); } - if ( !test && c->role[0] != '\0' ) { + if ( !test && c->role != NULL && c->role[0] != '\0' ) { test = token_match ( ftokens, c->role, not_ascii, case_sensitive ); } - if ( !test && c->name[0] != '\0' ) { + if ( !test && c->name != NULL && c->name[0] != '\0' ) { test = token_match ( ftokens, c->name, not_ascii, case_sensitive ); } @@ -430,7 +425,7 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd ) && !client_has_window_type ( c, netatoms[_NET_WM_WINDOW_TYPE_DESKTOP] ) && !client_has_state ( c, netatoms[_NET_WM_STATE_SKIP_PAGER] ) && !client_has_state ( c, netatoms[_NET_WM_STATE_SKIP_TASKBAR] ) ) { - classfield = MAX ( classfield, strlen ( c->class ) ); + classfield = MAX ( classfield, (c->class != NULL)?strlen ( c->class ):0 ); if ( client_has_state ( c, netatoms[_NET_WM_STATE_DEMANDS_ATTENTION] ) ) { c->demands = TRUE; @@ -469,7 +464,7 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd ) unsigned long wmdesktop; char desktop[5]; desktop[0] = 0; - size_t len = strlen ( c->title ) + strlen ( c->class ) + classfield + 50; + size_t len = c->title?strlen ( c->title ):0 + c->class?strlen ( c->class ):0 + classfield + 50; char *line = g_malloc ( len ); if ( !pd->config_i3_mode ) { // find client's desktop. @@ -486,10 +481,10 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd ) snprintf ( desktop, 5, "%d", (int) wmdesktop ); } - snprintf ( line, len, pattern, desktop, c->class, c->title ); + snprintf ( line, len, pattern, desktop, c->class?c->class:"", c->title?c->title:"" ); } else{ - snprintf ( line, len, pattern, c->class, c->title ); + snprintf ( line, len, pattern, c->class?c->class:"", c->title?c->title:"" ); } pd->cmd_list[pd->cmd_list_length++] = line; @@ -584,7 +579,11 @@ static int window_is_not_ascii ( const Mode *sw, unsigned int index ) int idx = winlist_find ( cache_client, ids->array[index] ); g_assert ( idx >= 0 ); client *c = cache_client->data[idx]; - return !g_str_is_ascii ( c->role ) || !g_str_is_ascii ( c->class ) || !g_str_is_ascii ( c->title ) || !g_str_is_ascii ( c->name ); + if ( c->role && !g_str_is_ascii(c->role)) return TRUE; + if ( c->class && !g_str_is_ascii(c->class)) return TRUE; + if ( c->title && !g_str_is_ascii(c->title)) return TRUE; + if ( c->name && !g_str_is_ascii(c->name)) return TRUE; + return FALSE; } #include "mode-private.h" From 87546caa8f768718d4ac7bf7df8a733cefc6d36f Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Tue, 23 Feb 2016 19:34:48 +0100 Subject: [PATCH 2/6] Fix previous commit. --- include/textbox.h | 18 +++++----- source/dialogs/window.c | 77 ++++++++++++++++++++++------------------- source/view.c | 16 ++++----- 3 files changed, 58 insertions(+), 53 deletions(-) diff --git a/include/textbox.h b/include/textbox.h index c321eb47..757b1c62 100644 --- a/include/textbox.h +++ b/include/textbox.h @@ -42,15 +42,15 @@ typedef struct typedef enum { - TB_AUTOHEIGHT = 1 << 0, - TB_AUTOWIDTH = 1 << 1, - TB_LEFT = 1 << 16, - TB_RIGHT = 1 << 17, - TB_CENTER = 1 << 18, - TB_EDITABLE = 1 << 19, - TB_MARKUP = 1 << 20, - TB_WRAP = 1 << 21, - TB_PASSWORD = 1 << 22, + TB_AUTOHEIGHT = 1 << 0, + TB_AUTOWIDTH = 1 << 1, + TB_LEFT = 1 << 16, + TB_RIGHT = 1 << 17, + TB_CENTER = 1 << 18, + TB_EDITABLE = 1 << 19, + TB_MARKUP = 1 << 20, + TB_WRAP = 1 << 21, + TB_PASSWORD = 1 << 22, } TextboxFlags; typedef enum diff --git a/source/dialogs/window.c b/source/dialogs/window.c index 9e6682a6..01da9e49 100644 --- a/source/dialogs/window.c +++ b/source/dialogs/window.c @@ -75,12 +75,11 @@ extern Display *display; typedef struct { Window *array; - void **data; + client **data; int len; } winlist; winlist *cache_client = NULL; -winlist *cache_xattr = NULL; /** * Create a window list, pre-seeded with WINLIST entries. @@ -92,7 +91,7 @@ static winlist* winlist_new () winlist *l = g_malloc ( sizeof ( winlist ) ); l->len = 0; l->array = g_malloc_n ( WINLIST + 1, sizeof ( Window ) ); - l->data = g_malloc_n ( WINLIST + 1, sizeof ( void* ) ); + l->data = g_malloc_n ( WINLIST + 1, sizeof ( client* ) ); return l; } @@ -105,11 +104,11 @@ static winlist* winlist_new () * * @returns 0 if failed, 1 is successful. */ -static int winlist_append ( winlist *l, Window w, void *d ) +static int winlist_append ( winlist *l, Window w, client *d ) { if ( l->len > 0 && !( l->len % WINLIST ) ) { l->array = g_realloc ( l->array, sizeof ( Window ) * ( l->len + WINLIST + 1 ) ); - l->data = g_realloc ( l->data, sizeof ( void* ) * ( l->len + WINLIST + 1 ) ); + l->data = g_realloc ( l->data, sizeof ( client* ) * ( l->len + WINLIST + 1 ) ); } // Make clang-check happy. // TODO: make clang-check clear this should never be 0. @@ -125,7 +124,16 @@ static int winlist_append ( winlist *l, Window w, void *d ) static void winlist_empty ( winlist *l ) { while ( l->len > 0 ) { - g_free ( l->data[--( l->len )] ); + client *c = l->data[l->len]; + if ( c != NULL ) { + g_free ( c->title ); + g_free ( c->class ); + g_free ( c->name ); + g_free ( c->role ); + g_free ( c ); + } + + l->len--; } } @@ -174,9 +182,6 @@ static void x11_cache_create ( void ) if ( cache_client == NULL ) { cache_client = winlist_new (); } - if ( cache_xattr == NULL ) { - cache_xattr = winlist_new (); - } } /** @@ -184,8 +189,6 @@ static void x11_cache_create ( void ) */ static void x11_cache_free ( void ) { - winlist_free ( cache_xattr ); - cache_xattr = NULL; winlist_free ( cache_client ); cache_client = NULL; } @@ -201,21 +204,12 @@ static void x11_cache_free ( void ) */ static XWindowAttributes* window_get_attributes ( Display *display, Window w ) { - int idx = winlist_find ( cache_xattr, w ); + XWindowAttributes *cattr = g_malloc ( sizeof ( XWindowAttributes ) ); - if ( idx < 0 ) { - XWindowAttributes *cattr = g_malloc ( sizeof ( XWindowAttributes ) ); - - if ( XGetWindowAttributes ( display, w, cattr ) ) { - winlist_append ( cache_xattr, w, cattr ); - return cattr; - } - - g_free ( cattr ); - return NULL; + if ( XGetWindowAttributes ( display, w, cattr ) ) { + return cattr; } - - return cache_xattr->data[idx]; + return NULL; } // _NET_WM_STATE_* static int client_has_state ( client *c, Atom state ) @@ -272,24 +266,25 @@ static client* window_client ( Display *display, Window win ) if ( ( name = window_get_text_prop ( display, c->window, netatoms[_NET_WM_NAME] ) ) && name ) { c->title = name; + name = NULL; } else if ( XFetchName ( display, c->window, &name ) ) { - c->title = g_strdup(name); + c->title = g_strdup ( name ); XFree ( name ); } name = window_get_text_prop ( display, c->window, XInternAtom ( display, "WM_WINDOW_ROLE", False ) ); if ( name != NULL ) { - c->role = g_strdup(name); + c->role = g_strdup ( name ); XFree ( name ); } XClassHint chint; if ( XGetClassHint ( display, c->window, &chint ) ) { - c->class = g_strdup(chint.res_class); - c->name = g_strdup(chint.res_name); + c->class = g_strdup ( chint.res_class ); + c->name = g_strdup ( chint.res_name ); XFree ( chint.res_class ); XFree ( chint.res_name ); } @@ -302,6 +297,7 @@ static client* window_client ( Display *display, Window win ) monitor_dimensions ( display, c->xattr.screen, c->xattr.x, c->xattr.y, &c->monitor ); winlist_append ( cache_client, c->window, c ); + g_free ( attr ); return c; } @@ -425,7 +421,7 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd ) && !client_has_window_type ( c, netatoms[_NET_WM_WINDOW_TYPE_DESKTOP] ) && !client_has_state ( c, netatoms[_NET_WM_STATE_SKIP_PAGER] ) && !client_has_state ( c, netatoms[_NET_WM_STATE_SKIP_TASKBAR] ) ) { - classfield = MAX ( classfield, (c->class != NULL)?strlen ( c->class ):0 ); + classfield = MAX ( classfield, ( c->class != NULL ) ? strlen ( c->class ) : 0 ); if ( client_has_state ( c, netatoms[_NET_WM_STATE_DEMANDS_ATTENTION] ) ) { c->demands = TRUE; @@ -464,7 +460,8 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd ) unsigned long wmdesktop; char desktop[5]; desktop[0] = 0; - size_t len = c->title?strlen ( c->title ):0 + c->class?strlen ( c->class ):0 + classfield + 50; + size_t len = + ( ( c->title != NULL ) ? strlen ( c->title ) : 0 ) + ( c->class ? strlen ( c->class ) : 0 ) + classfield + 50; char *line = g_malloc ( len ); if ( !pd->config_i3_mode ) { // find client's desktop. @@ -481,10 +478,10 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd ) snprintf ( desktop, 5, "%d", (int) wmdesktop ); } - snprintf ( line, len, pattern, desktop, c->class?c->class:"", c->title?c->title:"" ); + snprintf ( line, len, pattern, desktop, c->class ? c->class : "", c->title ? c->title : "" ); } else{ - snprintf ( line, len, pattern, c->class?c->class:"", c->title?c->title:"" ); + snprintf ( line, len, pattern, c->class ? c->class : "", c->title ? c->title : "" ); } pd->cmd_list[pd->cmd_list_length++] = line; @@ -579,10 +576,18 @@ static int window_is_not_ascii ( const Mode *sw, unsigned int index ) int idx = winlist_find ( cache_client, ids->array[index] ); g_assert ( idx >= 0 ); client *c = cache_client->data[idx]; - if ( c->role && !g_str_is_ascii(c->role)) return TRUE; - if ( c->class && !g_str_is_ascii(c->class)) return TRUE; - if ( c->title && !g_str_is_ascii(c->title)) return TRUE; - if ( c->name && !g_str_is_ascii(c->name)) return TRUE; + if ( c->role && !g_str_is_ascii ( c->role ) ) { + return TRUE; + } + if ( c->class && !g_str_is_ascii ( c->class ) ) { + return TRUE; + } + if ( c->title && !g_str_is_ascii ( c->title ) ) { + return TRUE; + } + if ( c->name && !g_str_is_ascii ( c->name ) ) { + return TRUE; + } return FALSE; } diff --git a/source/view.c b/source/view.c index 4abcafc5..5944bf13 100644 --- a/source/view.c +++ b/source/view.c @@ -690,14 +690,14 @@ static unsigned int rofi_scroll_per_page ( RofiViewState * state ) static unsigned int rofi_scroll_continious ( RofiViewState * state ) { - unsigned int middle = (state->menu_lines - ((state->menu_lines&1) == 0))/ 2; + unsigned int middle = ( state->menu_lines - ( ( state->menu_lines & 1 ) == 0 ) ) / 2; unsigned int offset = 0; if ( state->selected > middle ) { - if ( state->selected < ( state->filtered_lines - (state->menu_lines -middle) ) ) { + if ( state->selected < ( state->filtered_lines - ( state->menu_lines - middle ) ) ) { offset = state->selected - middle; } // Don't go below zero. - else if ( state->filtered_lines > state->menu_lines){ + else if ( state->filtered_lines > state->menu_lines ) { offset = state->filtered_lines - state->menu_lines; } } @@ -738,13 +738,13 @@ static void rofi_view_draw ( RofiViewState *state, cairo_t *d ) element_width = ( element_width - ( columns - 1 ) * config.line_margin ) / columns; } - int element_height = state->line_height * config.element_height; - int y_offset = state->top_offset; - int x_offset = state->border; + int element_height = state->line_height * config.element_height; + int y_offset = state->top_offset; + int x_offset = state->border; if ( state->rchanged ) { // Move, resize visible boxes and show them. - for ( i = 0; i < max_elements && (i+offset) < state->filtered_lines; i++ ) { + for ( i = 0; i < max_elements && ( i + offset ) < state->filtered_lines; i++ ) { unsigned int ex = ( ( i ) / state->max_rows ) * ( element_width + config.line_margin ); unsigned int ey = ( ( i ) % state->max_rows ) * ( element_height + config.line_margin ); // Move it around. @@ -764,7 +764,7 @@ static void rofi_view_draw ( RofiViewState *state, cairo_t *d ) } else{ // Only do basic redrawing + highlight of row. - for ( i = 0; i < max_elements && (i+offset) < state->filtered_lines; i++ ) { + for ( i = 0; i < max_elements && ( i + offset ) < state->filtered_lines; i++ ) { TextBoxFontType type = ( ( ( i % state->max_rows ) & 1 ) == 0 ) ? NORMAL : ALT; int fstate = 0; mode_get_display_value ( state->sw, state->line_map[i + offset], &fstate, FALSE ); From 319524c7c5a2735797562fcf4694252fb351a4ab Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Fri, 19 Feb 2016 19:29:06 +0100 Subject: [PATCH 3/6] Test for single mainloop --- include/rofi.h | 1 + include/view-internal.h | 1 + include/view.h | 7 +- source/dialogs/dmenu.c | 255 +++++++++++++++++++----------------- source/rofi.c | 277 +++++++++++++++++++++------------------- source/textbox.c | 4 +- source/view.c | 45 +++++-- source/x11-helper.c | 2 +- 8 files changed, 333 insertions(+), 259 deletions(-) diff --git a/include/rofi.h b/include/rofi.h index d4c8646e..ef717cbc 100644 --- a/include/rofi.h +++ b/include/rofi.h @@ -46,6 +46,7 @@ const Mode * rofi_get_mode ( unsigned int index ); */ int locate_switcher ( KeySym key, unsigned int modstate ); +void rofi_set_return_code ( int code ); /** Reset terminal */ #define color_reset "\033[0m" /** Set terminal text bold */ diff --git a/include/view-internal.h b/include/view-internal.h index 38f24511..27ee8a00 100644 --- a/include/view-internal.h +++ b/include/view-internal.h @@ -3,6 +3,7 @@ #include "widget.h" #include "textbox.h" #include "scrollbar.h" +#include "x11-helper.h" /** * @ingroup ViewHandle diff --git a/include/view.h b/include/view.h index 82de0d0f..f9763b83 100644 --- a/include/view.h +++ b/include/view.h @@ -28,13 +28,15 @@ typedef enum * @param prompt The prompt to show. * @param message Extra message to display. * @param flags Flags indicating state of the menu. + * @param finalize the finailze callback * * Main menu callback. * * @returns The command issued (see MenuReturn) */ -RofiViewState *rofi_view_create ( Mode *sw, const char *input, char *prompt, const char *message, MenuFlags flags ) -__attribute__ ( ( nonnull ( 1, 2, 3 ) ) ); +RofiViewState *rofi_view_create ( Mode *sw, const char *input, char *prompt, const char *message, MenuFlags flags, void ( *finalize )( + RofiViewState * ) ) +__attribute__ ( ( nonnull ( 1, 2, 3, 6 ) ) ); /** * @param state The Menu Handle @@ -147,6 +149,7 @@ void rofi_view_cleanup ( void ); */ void rofi_view_call_thread ( gpointer data, gpointer user_data ); +Mode * rofi_view_get_mode ( RofiViewState *state ); /** @} */ /*** * @defgroup ViewThreadPool ViewThreadPool diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index d76b0816..1c584e53 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -68,6 +68,7 @@ typedef struct _DmenuModePrivateData // List with entries. char **cmd_list; unsigned int cmd_list_length; + unsigned int only_selected; } DmenuModePrivateData; static char **get_dmenu ( FILE *fd, unsigned int *length ) @@ -358,23 +359,151 @@ Mode dmenu_mode = .free = NULL }; +static void dmenu_finalize ( RofiViewState *state ) +{ + int retv = FALSE; + DmenuModePrivateData *pd = (DmenuModePrivateData *) (Mode *) ( rofi_view_get_mode ( state ) )->private_data; + unsigned int cmd_list_length = pd->cmd_list_length; + char **cmd_list = pd->cmd_list; + + char *input = g_strdup ( rofi_view_get_user_input ( state ) ); + pd->selected_line = rofi_view_get_selected_line ( state );; + MenuReturn mretv = rofi_view_get_return_value ( state ); + unsigned int next_pos = rofi_view_get_next_position ( state ); + + int restart = 0; + // Special behavior. + // TODO clean this up! + if ( pd->only_selected ) { + /** + * Select item mode. + */ + restart = 1; + // Skip if no valid item is selected. + if ( ( mretv & MENU_CANCEL ) == MENU_CANCEL ) { + // In no custom mode we allow canceling. + restart = ( find_arg ( "-only-match" ) >= 0 ); + } + else if ( pd->selected_line != UINT32_MAX ) { + if ( ( mretv & ( MENU_OK | MENU_QUICK_SWITCH ) ) && cmd_list[pd->selected_line] != NULL ) { + dmenu_output_formatted_line ( pd->format, cmd_list[pd->selected_line], pd->selected_line, input ); + retv = TRUE; + if ( ( mretv & MENU_QUICK_SWITCH ) ) { + retv = 10 + ( mretv & MENU_LOWER_MASK ); + } + rofi_view_free ( state ); + g_free ( input ); + mode_destroy ( &dmenu_mode ); + if ( retv == FALSE ) { + rofi_set_return_code ( EXIT_FAILURE ); + } + else if ( retv >= 10 ) { + rofi_set_return_code ( retv ); + } + else{ + rofi_set_return_code ( EXIT_SUCCESS ); + } + rofi_view_free ( state ); + mode_destroy ( &dmenu_mode ); + rofi_view_set_active ( NULL ); +// g_main_loop_quit(NULL); + return; + } + pd->selected_line = next_pos - 1; + } + // Restart + rofi_view_restart ( state ); + rofi_view_set_selected_line ( state, pd->selected_line ); + return; + } + // We normally do not want to restart the loop. + restart = FALSE; + // Normal mode + if ( ( mretv & MENU_OK ) && pd->selected_line != UINT32_MAX && cmd_list[pd->selected_line] != NULL ) { + dmenu_output_formatted_line ( pd->format, cmd_list[pd->selected_line], pd->selected_line, input ); + if ( ( mretv & MENU_SHIFT ) ) { + restart = TRUE; + int seen = FALSE; + if ( pd->selected_list != NULL ) { + if ( pd->selected_list[pd->num_selected_list - 1].stop == ( pd->selected_line - 1 ) ) { + pd->selected_list[pd->num_selected_list - 1].stop = pd->selected_line; + seen = TRUE; + } + } + if ( !seen ) { + pd->selected_list = g_realloc ( pd->selected_list, + ( pd->num_selected_list + 1 ) * sizeof ( struct range_pair ) ); + pd->selected_list[pd->num_selected_list].start = pd->selected_line; + pd->selected_list[pd->num_selected_list].stop = pd->selected_line; + ( pd->num_selected_list )++; + } + + // Move to next line. + pd->selected_line = MIN ( next_pos, cmd_list_length - 1 ); + } + retv = TRUE; + } + // Custom input + else if ( ( mretv & ( MENU_CUSTOM_INPUT ) ) ) { + dmenu_output_formatted_line ( pd->format, input, -1, input ); + if ( ( mretv & MENU_SHIFT ) ) { + restart = TRUE; + // Move to next line. + pd->selected_line = MIN ( next_pos, cmd_list_length - 1 ); + } + + retv = TRUE; + } + // Quick switch with entry selected. + else if ( ( mretv & MENU_QUICK_SWITCH ) && pd->selected_line < UINT32_MAX ) { + dmenu_output_formatted_line ( pd->format, cmd_list[pd->selected_line], pd->selected_line, input ); + + restart = FALSE; + retv = 10 + ( mretv & MENU_LOWER_MASK ); + } + // Quick switch without entry selected. + else if ( ( mretv & MENU_QUICK_SWITCH ) && pd->selected_line == UINT32_MAX ) { + dmenu_output_formatted_line ( pd->format, input, -1, input ); + + restart = FALSE; + retv = 10 + ( mretv & MENU_LOWER_MASK ); + } + g_free ( input ); + if ( restart ) { + rofi_view_restart ( state ); + rofi_view_set_selected_line ( state, pd->selected_line ); + } + else { + if ( retv == FALSE ) { + rofi_set_return_code ( EXIT_FAILURE ); + } + else if ( retv >= 10 ) { + rofi_set_return_code ( retv ); + } + else{ + rofi_set_return_code ( EXIT_SUCCESS ); + } + rofi_view_free ( state ); + mode_destroy ( &dmenu_mode ); + rofi_view_set_active ( NULL ); + } +} + int dmenu_switcher_dialog ( void ) { mode_init ( &dmenu_mode ); MenuFlags menu_flags = MENU_NORMAL; DmenuModePrivateData *pd = (DmenuModePrivateData *) dmenu_mode.private_data; char *input = NULL; - int retv = FALSE; - int restart = FALSE; unsigned int cmd_list_length = pd->cmd_list_length; char **cmd_list = pd->cmd_list; - int only_selected = FALSE; + pd->only_selected = FALSE; if ( find_arg ( "-markup-rows" ) >= 0 ) { pd->do_markup = TRUE; } if ( find_arg ( "-only-match" ) >= 0 || find_arg ( "-no-custom" ) >= 0 ) { - only_selected = TRUE; + pd->only_selected = TRUE; if ( cmd_list_length == 0 ) { return TRUE; } @@ -416,122 +545,12 @@ int dmenu_switcher_dialog ( void ) g_strfreev ( tokens ); return TRUE; } - - RofiViewState *state = rofi_view_create ( &dmenu_mode, input, pd->prompt, pd->message, menu_flags ); + // TODO remove + RofiViewState *state = rofi_view_create ( &dmenu_mode, input, pd->prompt, pd->message, menu_flags, dmenu_finalize ); rofi_view_set_selected_line ( state, pd->selected_line ); - while ( XPending ( display ) ) { - XEvent ev; - XNextEvent ( display, &ev ); - rofi_view_itterrate ( state, &ev ); - } - do { - retv = FALSE; + rofi_view_set_active ( state ); - rofi_view_set_active ( state ); - // Enter main loop. - while ( !rofi_view_get_completed ( state ) ) { - g_main_context_iteration ( NULL, TRUE ); - } - rofi_view_set_active ( NULL ); - g_free ( input ); - input = g_strdup ( rofi_view_get_user_input ( state ) ); - pd->selected_line = rofi_view_get_selected_line ( state );; - MenuReturn mretv = rofi_view_get_return_value ( state ); - unsigned int next_pos = rofi_view_get_next_position ( state ); - - // Special behavior. - // TODO clean this up! - if ( only_selected ) { - /** - * Select item mode. - */ - restart = 1; - // Skip if no valid item is selected. - if ( ( mretv & MENU_CANCEL ) == MENU_CANCEL ) { - // In no custom mode we allow canceling. - restart = ( find_arg ( "-only-match" ) >= 0 ); - } - else if ( pd->selected_line != UINT32_MAX ) { - if ( ( mretv & ( MENU_OK | MENU_QUICK_SWITCH ) ) && cmd_list[pd->selected_line] != NULL ) { - dmenu_output_formatted_line ( pd->format, cmd_list[pd->selected_line], pd->selected_line, input ); - retv = TRUE; - if ( ( mretv & MENU_QUICK_SWITCH ) ) { - retv = 10 + ( mretv & MENU_LOWER_MASK ); - } - rofi_view_free ( state ); - g_free ( input ); - mode_destroy ( &dmenu_mode ); - return retv; - } - pd->selected_line = next_pos - 1; - } - // Restart - rofi_view_restart ( state ); - rofi_view_set_selected_line ( state, pd->selected_line ); - continue; - } - // We normally do not want to restart the loop. - restart = FALSE; - // Normal mode - if ( ( mretv & MENU_OK ) && pd->selected_line != UINT32_MAX && cmd_list[pd->selected_line] != NULL ) { - dmenu_output_formatted_line ( pd->format, cmd_list[pd->selected_line], pd->selected_line, input ); - if ( ( mretv & MENU_SHIFT ) ) { - restart = TRUE; - int seen = FALSE; - if ( pd->selected_list != NULL ) { - if ( pd->selected_list[pd->num_selected_list - 1].stop == ( pd->selected_line - 1 ) ) { - pd->selected_list[pd->num_selected_list - 1].stop = pd->selected_line; - seen = TRUE; - } - } - if ( !seen ) { - pd->selected_list = g_realloc ( pd->selected_list, - ( pd->num_selected_list + 1 ) * sizeof ( struct range_pair ) ); - pd->selected_list[pd->num_selected_list].start = pd->selected_line; - pd->selected_list[pd->num_selected_list].stop = pd->selected_line; - ( pd->num_selected_list )++; - } - - // Move to next line. - pd->selected_line = MIN ( next_pos, cmd_list_length - 1 ); - } - retv = TRUE; - } - // Custom input - else if ( ( mretv & ( MENU_CUSTOM_INPUT ) ) ) { - dmenu_output_formatted_line ( pd->format, input, -1, input ); - if ( ( mretv & MENU_SHIFT ) ) { - restart = TRUE; - // Move to next line. - pd->selected_line = MIN ( next_pos, cmd_list_length - 1 ); - } - - retv = TRUE; - } - // Quick switch with entry selected. - else if ( ( mretv & MENU_QUICK_SWITCH ) && pd->selected_line < UINT32_MAX ) { - dmenu_output_formatted_line ( pd->format, cmd_list[pd->selected_line], pd->selected_line, input ); - - restart = FALSE; - retv = 10 + ( mretv & MENU_LOWER_MASK ); - } - // Quick switch without entry selected. - else if ( ( mretv & MENU_QUICK_SWITCH ) && pd->selected_line == UINT32_MAX ) { - dmenu_output_formatted_line ( pd->format, input, -1, input ); - - restart = FALSE; - retv = 10 + ( mretv & MENU_LOWER_MASK ); - } - if ( restart ) { - rofi_view_restart ( state ); - rofi_view_set_selected_line ( state, pd->selected_line ); - } - } while ( restart ); - - rofi_view_free ( state ); - g_free ( input ); - mode_destroy ( &dmenu_mode ); - return retv; + return FALSE; } void print_dmenu_options ( void ) diff --git a/source/rofi.c b/source/rofi.c index 95e33c6c..7f1ce608 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -80,9 +80,19 @@ GMainLoop *main_loop = NULL; GSource *main_loop_source = NULL; gboolean quiet = FALSE; -static void process_result ( RofiViewState *state ); +static int dmenu_mode = FALSE; + +int return_code = EXIT_SUCCESS; + +void process_result ( RofiViewState *state ); +void process_result_error ( RofiViewState *state ); gboolean main_loop_x11_event_handler ( G_GNUC_UNUSED gpointer data ); +void rofi_set_return_code ( int code ) +{ + return_code = code; +} + unsigned int rofi_get_num_enabled_modi ( void ) { return num_modi; @@ -155,31 +165,28 @@ static void teardown ( int pfd ) remove_pid_file ( pfd ); } +static int pfd = -1; /** * Start dmenu mode. */ static int run_dmenu () { int ret_state = EXIT_FAILURE; - int pfd = setup (); + pfd = setup (); if ( pfd < 0 ) { return ret_state; } // Dmenu modi has a return state. ret_state = dmenu_switcher_dialog (); - teardown ( pfd ); return ret_state; } -static int pfd = -1; - static void __run_switcher_internal ( ModeMode mode, char *input ) { char *prompt = g_strdup_printf ( "%s:", mode_get_name ( modi[mode] ) ); curr_switcher = mode; - RofiViewState * state = rofi_view_create ( modi[mode], input, prompt, NULL, MENU_NORMAL ); - state->finalize = process_result; + RofiViewState * state = rofi_view_create ( modi[mode], input, prompt, NULL, MENU_NORMAL, process_result ); rofi_view_set_active ( state ); g_free ( prompt ); } @@ -201,57 +208,61 @@ static void run_switcher ( ModeMode mode ) __run_switcher_internal ( mode, input ); g_free ( input ); } -static void process_result ( RofiViewState *state ) +void process_result ( RofiViewState *state ) { - Mode *sw = state->sw; - unsigned int selected_line = rofi_view_get_selected_line ( state );; - MenuReturn mretv = rofi_view_get_return_value ( state ); - char *input = g_strdup ( rofi_view_get_user_input ( state ) ); - rofi_view_set_active ( NULL ); - rofi_view_free ( state ); - ModeMode retv = mode_result ( sw, mretv, &input, selected_line ); + Mode *sw = state->sw; + if ( sw != NULL ) { + unsigned int selected_line = rofi_view_get_selected_line ( state );; + MenuReturn mretv = rofi_view_get_return_value ( state ); + char *input = g_strdup ( rofi_view_get_user_input ( state ) ); + rofi_view_set_active ( NULL ); + rofi_view_free ( state ); + ModeMode retv = mode_result ( sw, mretv, &input, selected_line ); - ModeMode mode = curr_switcher; - // Find next enabled - if ( retv == NEXT_DIALOG ) { - mode = ( mode + 1 ) % num_modi; - } - else if ( retv == PREVIOUS_DIALOG ) { - if ( mode == 0 ) { - mode = num_modi - 1; + ModeMode mode = curr_switcher; + // Find next enabled + if ( retv == NEXT_DIALOG ) { + mode = ( mode + 1 ) % num_modi; + } + else if ( retv == PREVIOUS_DIALOG ) { + if ( mode == 0 ) { + mode = num_modi - 1; + } + else { + mode = ( mode - 1 ) % num_modi; + } + } + else if ( retv == RELOAD_DIALOG ) { + // do nothing. + } + else if ( retv < MODE_EXIT ) { + mode = ( retv ) % num_modi; } else { - mode = ( mode - 1 ) % num_modi; + mode = retv; + } + if ( mode != MODE_EXIT ) { + /** + * Load in the new mode. + */ + __run_switcher_internal ( mode, input ); + g_free ( input ); + main_loop_x11_event_handler ( NULL ); + return; + } + // Cleanup + g_free ( input ); + for ( unsigned int i = 0; i < num_modi; i++ ) { + mode_destroy ( modi[i] ); } } - else if ( retv == RELOAD_DIALOG ) { - // do nothing. - } - else if ( retv < MODE_EXIT ) { - mode = ( retv ) % num_modi; - } - else { - mode = retv; - } - if ( mode != MODE_EXIT ) { - /** - * Load in the new mode. - */ - __run_switcher_internal ( mode, input ); - g_free ( input ); - main_loop_x11_event_handler ( NULL ); - return; - } - // Cleanup - g_free ( input ); - for ( unsigned int i = 0; i < num_modi; i++ ) { - mode_destroy ( modi[i] ); - } - // cleanup +} +void process_result_error ( RofiViewState *state ) +{ + rofi_view_set_active ( NULL ); + rofi_view_free ( state ); teardown ( pfd ); - if ( !daemon_mode ) { - g_main_loop_quit ( main_loop ); - } + g_main_loop_quit ( main_loop ); } int show_error_message ( const char *msg, int markup ) @@ -261,9 +272,9 @@ int show_error_message ( const char *msg, int markup ) return EXIT_FAILURE; } rofi_view_error_dialog ( msg, markup ); - teardown ( pfd ); + //teardown ( pfd ); // TODO this looks incorrect. - g_main_loop_quit ( main_loop ); + // g_main_loop_quit ( main_loop ); return EXIT_SUCCESS; } @@ -552,6 +563,13 @@ gboolean main_loop_x11_event_handler ( G_GNUC_UNUSED gpointer data ) if ( rofi_view_get_completed ( state ) ) { // This menu is done. rofi_view_finalize ( state ); + // cleanup + if ( rofi_view_get_active () == NULL ) { + teardown ( pfd ); + if ( !daemon_mode ) { + g_main_loop_quit ( main_loop ); + } + } } return G_SOURCE_CONTINUE; } @@ -635,6 +653,82 @@ static gboolean delayed_start ( G_GNUC_UNUSED gpointer data ) return FALSE; } +static gboolean startup ( G_GNUC_UNUSED gpointer data ) +{ + // flags to run immediately and exit + char *sname = NULL; + char *msg = NULL; + // Dmenu mode. + if ( dmenu_mode == TRUE ) { + // force off sidebar mode: + config.sidebar_mode = FALSE; + int retv = run_dmenu (); + if ( retv ) { + rofi_set_return_code ( EXIT_SUCCESS ); + // Directly exit. + g_main_loop_quit(main_loop); + } + } + else if ( find_arg_str ( "-e", &( msg ) ) ) { + int markup = FALSE; + if ( find_arg ( "-markup" ) >= 0 ) { + markup = TRUE; + } + show_error_message ( msg, markup ); + } + else if ( find_arg_str ( "-show", &sname ) == TRUE ) { + int index = switcher_get ( sname ); + if ( index < 0 ) { + // Add it to the list + index = add_mode ( sname ); + // Complain + if ( index >= 0 ) { + fprintf ( stdout, "Mode %s not enabled. Please add it to the list of enabled modi: %s\n", + sname, config.modi ); + fprintf ( stdout, "Adding mode: %s\n", sname ); + } + // Run it anyway if found. + } + if ( index >= 0 ) { + run_switcher ( index ); + g_idle_add ( delayed_start, GINT_TO_POINTER ( index ) ); + } + else { + fprintf ( stderr, "The %s switcher has not been enabled\n", sname ); + return G_SOURCE_REMOVE; + } + } + else{ + // Daemon mode, Listen to key presses.. + if ( !grab_global_keybindings () ) { + fprintf ( stderr, "Rofi was launched in daemon mode, but no key-binding was specified.\n" ); + fprintf ( stderr, "Please check the manpage on how to specify a key-binding.\n" ); + fprintf ( stderr, "The following modi are enabled and keys can be specified:\n" ); + for ( unsigned int i = 0; i < num_modi; i++ ) { + const char *name = mode_get_name ( modi[i] ); + fprintf ( stderr, "\t* "color_bold "%s"color_reset ": -key-%s \n", name, name ); + } + // Cleanup + return G_SOURCE_REMOVE; + } + if ( !quiet ) { + fprintf ( stdout, "Rofi is launched in daemon mode.\n" ); + print_global_keybindings (); + } + + // done starting deamon. + + if ( sncontext != NULL ) { + sn_launchee_context_complete ( sncontext ); + } + daemon_mode = TRUE; + XSelectInput ( display, DefaultRootWindow ( display ), KeyPressMask ); + XFlush ( display ); + } + + return G_SOURCE_REMOVE; +} + int main ( int argc, char *argv[] ) { TIMINGS_START (); @@ -651,7 +745,6 @@ int main ( int argc, char *argv[] ) // Detect if we are in dmenu mode. // This has two possible causes. // 1 the user specifies it on the command-line. - int dmenu_mode = FALSE; if ( find_arg ( "-dmenu" ) >= 0 ) { dmenu_mode = TRUE; } @@ -773,31 +866,8 @@ int main ( int argc, char *argv[] ) // Parse the keybindings. parse_keys_abe (); TICK_N ( "Parse ABE" ); - char *msg = NULL; - if ( find_arg_str ( "-e", &( msg ) ) ) { - int markup = FALSE; - if ( find_arg ( "-markup" ) >= 0 ) { - markup = TRUE; - } - return show_error_message ( msg, markup ); - } rofi_view_workers_initialize (); - // Dmenu mode. - if ( dmenu_mode == TRUE ) { - // force off sidebar mode: - config.sidebar_mode = FALSE; - int retv = run_dmenu (); - - // User canceled the operation. - if ( retv == FALSE ) { - return EXIT_FAILURE; - } - else if ( retv >= 10 ) { - return retv; - } - return EXIT_SUCCESS; - } // Setup signal handling sources. // SIGHup signal. @@ -806,60 +876,11 @@ int main ( int argc, char *argv[] ) g_unix_signal_add ( SIGINT, main_loop_signal_handler_int, NULL ); // SIGUSR1 g_unix_signal_add ( SIGUSR1, main_loop_signal_handler_usr1, NULL ); - // flags to run immediately and exit - char *sname = NULL; - if ( find_arg_str ( "-show", &sname ) == TRUE ) { - int index = switcher_get ( sname ); - if ( index < 0 ) { - // Add it to the list - index = add_mode ( sname ); - // Complain - if ( index >= 0 ) { - fprintf ( stdout, "Mode %s not enabled. Please add it to the list of enabled modi: %s\n", - sname, config.modi ); - fprintf ( stdout, "Adding mode: %s\n", sname ); - } - // Run it anyway if found. - } - if ( index >= 0 ) { - run_switcher ( index ); - g_idle_add ( delayed_start, GINT_TO_POINTER ( index ) ); - } - else { - fprintf ( stderr, "The %s switcher has not been enabled\n", sname ); - return EXIT_FAILURE; - } - } - else{ - // Daemon mode, Listen to key presses.. - if ( !grab_global_keybindings () ) { - fprintf ( stderr, "Rofi was launched in daemon mode, but no key-binding was specified.\n" ); - fprintf ( stderr, "Please check the manpage on how to specify a key-binding.\n" ); - fprintf ( stderr, "The following modi are enabled and keys can be specified:\n" ); - for ( unsigned int i = 0; i < num_modi; i++ ) { - const char *name = mode_get_name ( modi[i] ); - fprintf ( stderr, "\t* "color_bold "%s"color_reset ": -key-%s \n", name, name ); - } - // Cleanup - return EXIT_FAILURE; - } - if ( !quiet ) { - fprintf ( stdout, "Rofi is launched in daemon mode.\n" ); - print_global_keybindings (); - } - // done starting deamon. - - if ( sncontext != NULL ) { - sn_launchee_context_complete ( sncontext ); - } - daemon_mode = TRUE; - XSelectInput ( display, DefaultRootWindow ( display ), KeyPressMask ); - XFlush ( display ); - } + g_idle_add ( startup, NULL ); // Start mainloop. g_main_loop_run ( main_loop ); - return EXIT_SUCCESS; + return return_code; } diff --git a/source/textbox.c b/source/textbox.c index efa36023..4a456a56 100644 --- a/source/textbox.c +++ b/source/textbox.c @@ -78,7 +78,7 @@ static gboolean textbox_blink ( gpointer data ) textbox* textbox_create ( TextboxFlags flags, short x, short y, short w, short h, TextBoxFontType tbft, const char *text ) { - textbox *tb = g_malloc0 ( sizeof ( textbox ) ); + textbox *tb = g_slice_new0 ( textbox ); tb->flags = flags; @@ -258,7 +258,7 @@ void textbox_free ( textbox *tb ) tb->main_surface = NULL; } - g_free ( tb ); + g_slice_free ( textbox, tb ); } static void texbox_update ( textbox *tb ) diff --git a/source/view.c b/source/view.c index 5944bf13..9c51fbfe 100644 --- a/source/view.c +++ b/source/view.c @@ -400,6 +400,7 @@ static Window __create_window ( Display *display, MenuFlags menu_flags ) surface = cairo_xlib_surface_create ( display, box, vinfo.visual, 200, 100 ); // Create a drawable. draw = cairo_create ( surface ); + g_assert ( draw != NULL ); cairo_set_operator ( draw, CAIRO_OPERATOR_SOURCE ); // Set up pango context. @@ -1416,7 +1417,8 @@ RofiViewState *rofi_view_create ( Mode *sw, const char *input, char *prompt, const char *message, - MenuFlags menu_flags ) + MenuFlags menu_flags, + void ( *finalize )( RofiViewState *state ) ) { TICK (); RofiViewState *state = __rofi_view_state_create (); @@ -1434,6 +1436,7 @@ RofiViewState *rofi_view_create ( Mode *sw, state->cur_page = -1; state->border = config.padding + config.menu_bw; state->x11_event_loop = rofi_view_mainloop_iter; + state->finalize = finalize; // Request the lines to show. state->num_lines = mode_get_num_entries ( sw ); @@ -1625,6 +1628,7 @@ RofiViewState *rofi_view_create ( Mode *sw, } static void __error_dialog_event_loop ( RofiViewState *state, XEvent *ev ) { + printf ( "Event\n" ); // Handle event. if ( ev->type == Expose ) { while ( XCheckTypedEvent ( display, Expose, ev ) ) { @@ -1632,6 +1636,21 @@ static void __error_dialog_event_loop ( RofiViewState *state, XEvent *ev ) } state->update = TRUE; } + else if ( ev->type == ConfigureNotify ) { + XConfigureEvent xce = ev->xconfigure; + if ( xce.window == main_window ) { + if ( state->x != (int ) xce.x || state->y != (int) xce.y ) { + state->x = xce.x; + state->y = xce.y; + state->update = TRUE; + } + if ( state->w != (unsigned int) xce.width || state->h != (unsigned int ) xce.height ) { + state->w = xce.width; + state->h = xce.height; + cairo_xlib_surface_set_size ( surface, state->w, state->h ); + } + } + } // Key press event. else if ( ev->type == KeyPress ) { while ( XCheckTypedEvent ( display, KeyPress, ev ) ) { @@ -1641,6 +1660,7 @@ static void __error_dialog_event_loop ( RofiViewState *state, XEvent *ev ) } rofi_view_update ( state ); } +void process_result_error ( RofiViewState *state ); void rofi_view_error_dialog ( const char *msg, int markup ) { RofiViewState *state = __rofi_view_state_create (); @@ -1648,7 +1668,8 @@ void rofi_view_error_dialog ( const char *msg, int markup ) state->update = TRUE; state->border = config.padding + config.menu_bw; state->x11_event_loop = __error_dialog_event_loop; - state->finalize = NULL; + // TODO fix + state->finalize = process_result_error; // Try to grab the keyboard as early as possible. // We grab this using the rootwindow (as dmenu does it). @@ -1668,6 +1689,7 @@ void rofi_view_error_dialog ( const char *msg, int markup ) XWindowAttributes attr; if ( main_window == None || XGetWindowAttributes ( display, main_window, &attr ) == 0 ) { main_window = __create_window ( display, MENU_NORMAL ); + printf ( "new window\n" ); } rofi_view_calculate_window_and_element_width ( state ); @@ -1689,15 +1711,18 @@ void rofi_view_error_dialog ( const char *msg, int markup ) XMapRaised ( display, main_window ); if ( sncontext != NULL ) { - sn_launchee_context_complete ( sncontext ); +// sn_launchee_context_complete ( sncontext ); } + printf ( "start\n" ); rofi_view_set_active ( state ); + //rofi_view_queue_redraw(); main_loop_x11_event_handler ( NULL ); - while ( !rofi_view_get_completed ( state ) ) { - g_main_context_iteration ( NULL, TRUE ); - } - rofi_view_set_active ( NULL ); - rofi_view_free ( state ); + //while ( !rofi_view_get_completed ( state ) ) { + // printf("main loop: %d\n", g_main_context_is_owner(g_main_context_default())); + // g_main_context_iteration ( NULL, TRUE ); + //} + //rofi_view_set_active ( NULL ); + //rofi_view_free ( state ); } void rofi_view_cleanup () @@ -1756,4 +1781,8 @@ void rofi_view_workers_finalize ( void ) tpool = NULL; } } +Mode * rofi_view_get_mode ( RofiViewState *state ) +{ + return state->sw; +} diff --git a/source/x11-helper.c b/source/x11-helper.c index 89c89a7b..7137c55d 100644 --- a/source/x11-helper.c +++ b/source/x11-helper.c @@ -521,7 +521,7 @@ void x11_parse_key ( char *combo, unsigned int *mod, KeySym *key ) if ( str->len > 0 ) { show_error_message ( str->str, TRUE ); g_string_free ( str, TRUE ); - exit ( EXIT_FAILURE ); + return; } g_string_free ( str, TRUE ); *key = sym; From 3b58c3a26a8ceec67620198e629d381fb1e0e6c8 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Tue, 23 Feb 2016 21:14:15 +0100 Subject: [PATCH 4/6] Fix issue: #347. --- include/textbox.h | 18 +++++++++--------- source/dialogs/window.c | 1 + source/rofi.c | 10 +++++----- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/textbox.h b/include/textbox.h index 757b1c62..c321eb47 100644 --- a/include/textbox.h +++ b/include/textbox.h @@ -42,15 +42,15 @@ typedef struct typedef enum { - TB_AUTOHEIGHT = 1 << 0, - TB_AUTOWIDTH = 1 << 1, - TB_LEFT = 1 << 16, - TB_RIGHT = 1 << 17, - TB_CENTER = 1 << 18, - TB_EDITABLE = 1 << 19, - TB_MARKUP = 1 << 20, - TB_WRAP = 1 << 21, - TB_PASSWORD = 1 << 22, + TB_AUTOHEIGHT = 1 << 0, + TB_AUTOWIDTH = 1 << 1, + TB_LEFT = 1 << 16, + TB_RIGHT = 1 << 17, + TB_CENTER = 1 << 18, + TB_EDITABLE = 1 << 19, + TB_MARKUP = 1 << 20, + TB_WRAP = 1 << 21, + TB_PASSWORD = 1 << 22, } TextboxFlags; typedef enum diff --git a/source/dialogs/window.c b/source/dialogs/window.c index 01da9e49..fb1d4e2a 100644 --- a/source/dialogs/window.c +++ b/source/dialogs/window.c @@ -537,6 +537,7 @@ static ModeMode window_mode_result ( Mode *sw, int mretv, G_GNUC_UNUSED char **i window_send_message ( display, root, rmpd->ids->array[selected_line], netatoms[_NET_ACTIVE_WINDOW], 2, // 2 = pager SubstructureNotifyMask | SubstructureRedirectMask, 0 ); + XFlush ( display ); } } return retv; diff --git a/source/rofi.c b/source/rofi.c index 7f1ce608..9fe01f3d 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -252,9 +252,6 @@ void process_result ( RofiViewState *state ) } // Cleanup g_free ( input ); - for ( unsigned int i = 0; i < num_modi; i++ ) { - mode_destroy ( modi[i] ); - } } } void process_result_error ( RofiViewState *state ) @@ -356,6 +353,9 @@ static int grab_global_keybindings () */ static void cleanup () { + for ( unsigned int i = 0; i < num_modi; i++ ) { + mode_destroy ( modi[i] ); + } rofi_view_workers_finalize (); if ( main_loop != NULL ) { if ( main_loop_source ) { @@ -664,9 +664,9 @@ static gboolean startup ( G_GNUC_UNUSED gpointer data ) config.sidebar_mode = FALSE; int retv = run_dmenu (); if ( retv ) { - rofi_set_return_code ( EXIT_SUCCESS ); + rofi_set_return_code ( EXIT_SUCCESS ); // Directly exit. - g_main_loop_quit(main_loop); + g_main_loop_quit ( main_loop ); } } else if ( find_arg_str ( "-e", &( msg ) ) ) { From 3f8efed56d482981102b55ab5b76c539b7500e5b Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Tue, 23 Feb 2016 22:04:44 +0100 Subject: [PATCH 5/6] Add missing flush --- source/view.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/view.c b/source/view.c index 9c51fbfe..01e7c62c 100644 --- a/source/view.c +++ b/source/view.c @@ -1620,7 +1620,7 @@ RofiViewState *rofi_view_create ( Mode *sw, state->update = TRUE; rofi_view_refilter ( state ); - rofi_view_update ( state ); +// rofi_view_update ( state ); if ( sncontext != NULL ) { sn_launchee_context_complete ( sncontext ); } @@ -1745,6 +1745,7 @@ void rofi_view_cleanup () main_window = None; XDestroyIC ( xic ); XCloseIM ( xim ); + XFlush ( display ); } if ( map != None ) { From 5a204829f0852ad13e7d8b6d42dfaed06667f043 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Tue, 23 Feb 2016 23:54:35 +0100 Subject: [PATCH 6/6] Fix not updating in daemon mode --- include/textbox.h | 18 +++++++++--------- source/dialogs/window.c | 4 +--- source/rofi.c | 6 +++--- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/include/textbox.h b/include/textbox.h index c321eb47..757b1c62 100644 --- a/include/textbox.h +++ b/include/textbox.h @@ -42,15 +42,15 @@ typedef struct typedef enum { - TB_AUTOHEIGHT = 1 << 0, - TB_AUTOWIDTH = 1 << 1, - TB_LEFT = 1 << 16, - TB_RIGHT = 1 << 17, - TB_CENTER = 1 << 18, - TB_EDITABLE = 1 << 19, - TB_MARKUP = 1 << 20, - TB_WRAP = 1 << 21, - TB_PASSWORD = 1 << 22, + TB_AUTOHEIGHT = 1 << 0, + TB_AUTOWIDTH = 1 << 1, + TB_LEFT = 1 << 16, + TB_RIGHT = 1 << 17, + TB_CENTER = 1 << 18, + TB_EDITABLE = 1 << 19, + TB_MARKUP = 1 << 20, + TB_WRAP = 1 << 21, + TB_PASSWORD = 1 << 22, } TextboxFlags; typedef enum diff --git a/source/dialogs/window.c b/source/dialogs/window.c index fb1d4e2a..48704010 100644 --- a/source/dialogs/window.c +++ b/source/dialogs/window.c @@ -124,7 +124,7 @@ static int winlist_append ( winlist *l, Window w, client *d ) static void winlist_empty ( winlist *l ) { while ( l->len > 0 ) { - client *c = l->data[l->len]; + client *c = l->data[--l->len]; if ( c != NULL ) { g_free ( c->title ); g_free ( c->class ); @@ -132,8 +132,6 @@ static void winlist_empty ( winlist *l ) g_free ( c->role ); g_free ( c ); } - - l->len--; } } diff --git a/source/rofi.c b/source/rofi.c index 9fe01f3d..aed45b6b 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -252,6 +252,9 @@ void process_result ( RofiViewState *state ) } // Cleanup g_free ( input ); + for ( unsigned int i = 0; i < num_modi; i++ ) { + mode_destroy ( modi[i] ); + } } } void process_result_error ( RofiViewState *state ) @@ -353,9 +356,6 @@ static int grab_global_keybindings () */ static void cleanup () { - for ( unsigned int i = 0; i < num_modi; i++ ) { - mode_destroy ( modi[i] ); - } rofi_view_workers_finalize (); if ( main_loop != NULL ) { if ( main_loop_source ) {