diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/dialogs/dmenu.c | 7 | ||||
-rw-r--r-- | source/dialogs/run.c | 7 | ||||
-rw-r--r-- | source/dialogs/script.c | 7 | ||||
-rw-r--r-- | source/dialogs/window.c | 4 | ||||
-rw-r--r-- | source/helper.c | 56 | ||||
-rw-r--r-- | source/history.c | 1 | ||||
-rw-r--r-- | source/i3-support.c | 2 | ||||
-rw-r--r-- | source/keyb.c | 110 | ||||
-rw-r--r-- | source/rofi.c | 201 | ||||
-rw-r--r-- | source/textbox.c | 26 | ||||
-rw-r--r-- | source/x11-helper.c | 61 | ||||
-rw-r--r-- | source/xrmoptions.c | 274 |
12 files changed, 266 insertions, 490 deletions
diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index d500486a..d92ed614 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -57,7 +57,6 @@ typedef struct _DmenuModePrivateData unsigned int cmd_list_length; } DmenuModePrivateData; - static char **get_dmenu ( unsigned int *length ) { char buffer[1024]; @@ -96,7 +95,6 @@ static char ** dmenu_mode_get_data ( unsigned int *length, Switcher *sw ) return rmpd->cmd_list; } - static void parse_pair ( char *input, struct range_pair *item ) { int index = 0; @@ -209,7 +207,6 @@ static void dmenu_mode_free ( Switcher *sw ) } DmenuModePrivateData *pd = (DmenuModePrivateData *) sw->private_data; - g_strfreev ( pd->cmd_list ); g_free ( pd->urgent_list ); g_free ( pd->active_list ); @@ -295,8 +292,7 @@ int dmenu_switcher_dialog ( void ) unsigned int cmd_list_length = 0; char **cmd_list = dmenu_mode.get_data ( &( cmd_list_length ), &dmenu_mode ); - - int only_selected = FALSE; + int only_selected = FALSE; if ( find_arg ( "-only-match" ) >= 0 || find_arg ( "-no-custom" ) >= 0 ) { only_selected = TRUE; if ( cmd_list_length == 0 ) { @@ -392,7 +388,6 @@ int dmenu_switcher_dialog ( void ) } } while ( restart ); - g_free ( input ); dmenu_mode.destroy ( &dmenu_mode ); return retv; diff --git a/source/dialogs/run.c b/source/dialogs/run.c index d32f0f8e..fe87c935 100644 --- a/source/dialogs/run.c +++ b/source/dialogs/run.c @@ -79,7 +79,6 @@ static void exec_cmd ( const char *cmd, int run_in_term ) return; } - execsh ( cmd, run_in_term ); /** @@ -155,7 +154,6 @@ static char ** get_apps_external ( char **retv, unsigned int *length, unsigned i retv = g_realloc ( retv, ( ( *length ) + 2 ) * sizeof ( char* ) ); retv[( *length )] = g_strdup ( buffer ); - ( *length )++; } if ( fclose ( inp ) != 0 ) { @@ -181,14 +179,12 @@ static char ** get_apps ( unsigned int *length ) return NULL; } - path = g_strdup_printf ( "%s/%s", cache_dir, RUN_CACHE_FILE ); retv = history_get_list ( path, length ); g_free ( path ); // Keep track of how many where loaded as favorite. num_favorites = ( *length ); - path = g_strdup ( getenv ( "PATH" ) ); for ( const char *dirname = strtok ( path, ":" ); @@ -259,7 +255,6 @@ static char ** get_apps ( unsigned int *length ) } } - if ( ( *length ) > num_favorites ) { g_qsort_with_data ( &retv[num_favorites], ( *length ) - num_favorites, sizeof ( char* ), sort_func, @@ -278,7 +273,6 @@ typedef struct _RunModePrivateData unsigned int cmd_list_length; } RunModePrivateData; - static void run_mode_init ( Switcher *sw ) { if ( sw->private_data == NULL ) { @@ -333,7 +327,6 @@ static SwitcherMode run_mode_result ( int mretv, char **input, unsigned int sele return retv; } - static void run_mode_destroy ( Switcher *sw ) { RunModePrivateData *rmpd = (RunModePrivateData *) sw->private_data; diff --git a/source/dialogs/script.c b/source/dialogs/script.c index 7452bd7c..3bb54b1a 100644 --- a/source/dialogs/script.c +++ b/source/dialogs/script.c @@ -25,7 +25,6 @@ * */ - #include <config.h> #include <stdio.h> #include <stdlib.h> @@ -39,10 +38,6 @@ #include "dialogs/script.h" #include "helper.h" - - - - static char **get_script_output ( const char *command, unsigned int *length ) { char **retv = NULL; @@ -102,7 +97,6 @@ typedef struct _ScriptModePrivateData unsigned int cmd_list_length; } ScriptModePrivateData; - static void script_mode_init ( Switcher *sw ) { if ( sw->private_data == NULL ) { @@ -145,7 +139,6 @@ static SwitcherMode script_mode_result ( int mretv, char **input, unsigned int s new_list = execute_executor ( sw, *input, &new_length ); } - // If a new list was generated, use that an loop around. if ( new_list != NULL ) { g_strfreev ( rmpd->cmd_list ); diff --git a/source/dialogs/window.c b/source/dialogs/window.c index 85ba7f2f..6aad4ebc 100644 --- a/source/dialogs/window.c +++ b/source/dialogs/window.c @@ -44,7 +44,6 @@ #include "i3-support.h" #include "dialogs/window.h" - #define WINLIST 32 #define CLIENTTITLE 100 @@ -417,8 +416,6 @@ static char ** _window_mode_get_data ( unsigned int *length, Switcher *sw, unsig // if we happen to have a window destroyed while we're working... pd->ids = winlist_new (); - - // calc widths of fields for ( i = nwins - 1; i > -1; i-- ) { client *c; @@ -549,7 +546,6 @@ static SwitcherMode window_mode_result ( int mretv, G_GNUC_UNUSED char **input, return retv; } - static void window_mode_destroy ( Switcher *sw ) { SwitcherModePrivateData *rmpd = (SwitcherModePrivateData *) sw->private_data; diff --git a/source/helper.c b/source/helper.c index 8e2a8d0b..2011d7e0 100644 --- a/source/helper.c +++ b/source/helper.c @@ -84,9 +84,7 @@ char* fgets_s ( char* s, int n, FILE *iop, char sep ) * * @returns TRUE to stop replacement, FALSE to continue */ -static gboolean helper_eval_cb ( const GMatchInfo *info, - GString *res, - gpointer data ) +static gboolean helper_eval_cb ( const GMatchInfo *info, GString *res, gpointer data ) { gchar *match; // Get the match @@ -131,10 +129,7 @@ int helper_parse_setup ( char * string, char ***output, int *length, ... ) // Replace hits within {-\w+}. GRegex *reg = g_regex_new ( "{[-\\w]+}", 0, 0, NULL ); - char *res = g_regex_replace_eval ( reg, - string, -1, - 0, 0, helper_eval_cb, h, - NULL ); + char *res = g_regex_replace_eval ( reg, string, -1, 0, 0, helper_eval_cb, h, NULL ); // Free regex. g_regex_unref ( reg ); // Destroy key-value storage. @@ -147,8 +142,7 @@ int helper_parse_setup ( char * string, char ***output, int *length, ... ) g_free ( res ); // Throw error if shell parsing fails. if ( error ) { - char *msg = g_strdup_printf ( "Failed to parse: '%s'\nError: '%s'", string, - error->message ); + char *msg = g_strdup_printf ( "Failed to parse: '%s'\nError: '%s'", string, error->message ); error_dialog ( msg, FALSE ); g_free ( msg ); // print error. @@ -190,9 +184,7 @@ char **tokenize ( const char *input, int case_sensitive ) // Iterate over tokens. // strtok should still be valid for utf8. - for ( token = strtok_r ( str, " ", &saveptr ); - token != NULL; - token = strtok_r ( NULL, " ", &saveptr ) ) { + for ( token = strtok_r ( str, " ", &saveptr ); token != NULL; token = strtok_r ( NULL, " ", &saveptr ) ) { retv = g_realloc ( retv, sizeof ( char* ) * ( num_tokens + 2 ) ); retv[num_tokens] = token_collate_key ( token, case_sensitive ); retv[num_tokens + 1] = NULL; @@ -368,19 +360,10 @@ int execute_generator ( const char * cmd ) int fd = -1; GError *error = NULL; - g_spawn_async_with_pipes ( NULL, - args, - NULL, - G_SPAWN_SEARCH_PATH, - NULL, - NULL, - NULL, - NULL, &fd, NULL, - &error ); + g_spawn_async_with_pipes ( NULL, args, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL, &fd, NULL, &error ); if ( error != NULL ) { - char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", cmd, - error->message ); + char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", cmd, error->message ); error_dialog ( msg, FALSE ); g_free ( msg ); // print error. @@ -391,7 +374,6 @@ int execute_generator ( const char * cmd ) return fd; } - int create_pid_file ( const char *pidfile ) { if ( pidfile == NULL ) { @@ -452,40 +434,32 @@ void config_sanity_check ( ) GString *msg = g_string_new ( "<big><b>The configuration failed to validate:</b></big>\n" ); if ( config.element_height < 1 ) { - g_string_append_printf ( - msg, - "\t<b>config.element_height</b>=%d is invalid. An element needs to be atleast 1 line high.\n", - config.element_height ); + g_string_append_printf ( msg, "\t<b>config.element_height</b>=%d is invalid. An element needs to be atleast 1 line high.\n", + config.element_height ); config.element_height = 1; found_error = TRUE; } if ( config.menu_columns == 0 ) { - g_string_append_printf ( - msg, - "\t<b>config.menu_columns</b>=%d is invalid. You need at least one visible column.\n", - config.menu_columns ); + g_string_append_printf ( msg, "\t<b>config.menu_columns</b>=%d is invalid. You need at least one visible column.\n", + config.menu_columns ); config.menu_columns = 1; found_error = TRUE; } if ( config.menu_width == 0 ) { - show_error_message ( - "<b>config.menu_width</b>=0 is invalid. You cannot have a window with no width.", TRUE ); + show_error_message ( "<b>config.menu_width</b>=0 is invalid. You cannot have a window with no width.", TRUE ); config.menu_columns = 50; found_error = TRUE; } if ( !( config.location >= WL_CENTER && config.location <= WL_WEST ) ) { - g_string_append_printf ( - msg, "\t<b>config.location</b>=%d is invalid. Value should be between %d and %d.\n", - config.location, WL_CENTER, WL_WEST ); + g_string_append_printf ( msg, "\t<b>config.location</b>=%d is invalid. Value should be between %d and %d.\n", + config.location, WL_CENTER, WL_WEST ); config.location = WL_CENTER; found_error = 1; } if ( 0 ) { if ( !( config.line_margin <= 50 ) ) { - g_string_append_printf ( - msg, - "\t<b>config.line_margin</b>=%d is invalid. Value should be between %d and %d.\n", - config.line_margin, 0, 50 ); + g_string_append_printf ( msg, "\t<b>config.line_margin</b>=%d is invalid. Value should be between %d and %d.\n", + config.line_margin, 0, 50 ); config.line_margin = 2; found_error = 1; } diff --git a/source/history.c b/source/history.c index 1423cbe0..6f14e505 100644 --- a/source/history.c +++ b/source/history.c @@ -109,7 +109,6 @@ static _element ** __history_get_element_list ( FILE *fd, unsigned int *length ) return retv; } - void history_set ( const char *filename, const char *entry ) { if ( config.disable_history ) { diff --git a/source/i3-support.c b/source/i3-support.c index ebf7c7e6..1cdf21a0 100644 --- a/source/i3-support.c +++ b/source/i3-support.c @@ -76,7 +76,6 @@ void i3_support_focus_window ( Window id ) return; } - // Formulate command snprintf ( command, upm, "[id=\"%lu\"] focus", id ); // Prepare header. @@ -141,7 +140,6 @@ void i3_support_free_internals ( void ) #else - void i3_support_focus_window ( Window id ) { fprintf ( stderr, "Trying to control i3, when i3 support is not enabled.\n" ); diff --git a/source/keyb.c b/source/keyb.c index 9b14448e..e9577d05 100644 --- a/source/keyb.c +++ b/source/keyb.c @@ -34,63 +34,36 @@ extern unsigned int NumlockMask; */ DefaultBinding bindings[NUM_ABE] = { - { .id = PASTE_PRIMARY, .name = "kb-primary-paste", - .keybinding = - "Control+Shift+v,Shift+Insert", }, - { .id = PASTE_SECONDARY, .name = "kb-secondary-paste", .keybinding = - "Control+v,Insert", }, - { .id = CLEAR_LINE, .name = "kb-clear-line", .keybinding = - "Control+u", }, - { .id = MOVE_FRONT, .name = "kb-move-front", .keybinding = - "Control+a", }, - { .id = MOVE_END, .name = "kb-move-end", .keybinding = - "Control+e", }, + { .id = PASTE_PRIMARY, .name = "kb-primary-paste", .keybinding = "Control+Shift+v,Shift+Insert", }, + { .id = PASTE_SECONDARY, .name = "kb-secondary-paste", .keybinding = "Control+v,Insert", }, + { .id = CLEAR_LINE, .name = "kb-clear-line", .keybinding = "Control+u", }, + { .id = MOVE_FRONT, .name = "kb-move-front", .keybinding = "Control+a", }, + { .id = MOVE_END, .name = "kb-move-end", .keybinding = "Control+e", }, { .id = MOVE_WORD_BACK, .name = "kb-move-word-back", .keybinding = "Alt+b", }, { .id = MOVE_WORD_FORWARD, .name = "kb-move-word-forward", .keybinding = "Alt+f", }, - { .id = MOVE_CHAR_BACK, .name = "kb-move-char-back", .keybinding = - "Left,Control+b" }, - { .id = MOVE_CHAR_FORWARD, .name = "kb-move-char-forward", .keybinding = - "Right,Control+f" }, - { .id = REMOVE_WORD_BACK, .name = "kb-remove-word-back", .keybinding = - "Control+Alt+h", }, - { .id = REMOVE_WORD_FORWARD, .name = "kb-remove-word-forward", .keybinding = - "Control+Alt+d", }, - { .id = REMOVE_CHAR_FORWARD, .name = "kb-remove-char-forward", .keybinding = - "Delete,Control+d", }, - { .id = REMOVE_CHAR_BACK, .name = "kb-remove-char-back", .keybinding = - "BackSpace,Control+h", }, - { .id = ACCEPT_ENTRY, .name = "kb-accept-entry", .keybinding = - "Control+j,Control+m,Return,KP_Enter", }, - { .id = ACCEPT_CUSTOM, .name = "kb-accept-custom", .keybinding = - "Control+Return", }, - { .id = ACCEPT_ENTRY_CONTINUE, .name = "kb-accept-entry-continue", .keybinding = - "Shift+Return", }, - { .id = MODE_NEXT, .name = "kb-mode-next", .keybinding = - "Shift+Right,Control+Tab" }, - { .id = MODE_PREVIOUS, .name = "kb-mode-previous", .keybinding = - "Shift+Left,Control+Shift+Tab" }, - { .id = TOGGLE_CASE_SENSITIVITY, .name = "kb-toggle-case-sensitivity", .keybinding = - "grave,dead_grave" }, - { .id = DELETE_ENTRY, .name = "kb-delete-entry", .keybinding = - "Shift+Delete" }, - { .id = ROW_LEFT, .name = "kb-row-left", .keybinding = - "Control+Page_Up" }, - { .id = ROW_RIGHT, .name = "kb-row-right", .keybinding = - "Control+Page_Down" }, - { .id = ROW_UP, .name = "kb-row-up", .keybinding = - "Up,Control+p,Shift+Tab" }, - { .id = ROW_DOWN, .name = "kb-row-down", .keybinding = - "Down,Control+n" }, + { .id = MOVE_CHAR_BACK, .name = "kb-move-char-back", .keybinding = "Left,Control+b" }, + { .id = MOVE_CHAR_FORWARD, .name = "kb-move-char-forward", .keybinding = "Right,Control+f" }, + { .id = REMOVE_WORD_BACK, .name = "kb-remove-word-back", .keybinding = "Control+Alt+h", }, + { .id = REMOVE_WORD_FORWARD, .name = "kb-remove-word-forward", .keybinding = "Control+Alt+d", }, + { .id = REMOVE_CHAR_FORWARD, .name = "kb-remove-char-forward", .keybinding = "Delete,Control+d", }, + { .id = REMOVE_CHAR_BACK, .name = "kb-remove-char-back", .keybinding = "BackSpace,Control+h", }, + { .id = ACCEPT_ENTRY, .name = "kb-accept-entry", .keybinding = "Control+j,Control+m,Return,KP_Enter", }, + { .id = ACCEPT_CUSTOM, .name = "kb-accept-custom", .keybinding = "Control+Return", }, + { .id = ACCEPT_ENTRY_CONTINUE, .name = "kb-accept-entry-continue", .keybinding = "Shift+Return", }, + { .id = MODE_NEXT, .name = "kb-mode-next", .keybinding = "Shift+Right,Control+Tab" }, + { .id = MODE_PREVIOUS, .name = "kb-mode-previous", .keybinding = "Shift+Left,Control+Shift+Tab" }, + { .id = TOGGLE_CASE_SENSITIVITY, .name = "kb-toggle-case-sensitivity", .keybinding = "grave,dead_grave" }, + { .id = DELETE_ENTRY, .name = "kb-delete-entry", .keybinding = "Shift+Delete" }, + { .id = ROW_LEFT, .name = "kb-row-left", .keybinding = "Control+Page_Up" }, + { .id = ROW_RIGHT, .name = "kb-row-right", .keybinding = "Control+Page_Down" }, + { .id = ROW_UP, .name = "kb-row-up", .keybinding = "Up,Control+p,Shift+Tab" }, + { .id = ROW_DOWN, .name = "kb-row-down", .keybinding = "Down,Control+n" }, { .id = ROW_TAB, .name = "kb-row-tab", .keybinding = "Tab" }, { .id = PAGE_PREV, .name = "kb-page-prev", .keybinding = "Page_Up" }, - { .id = PAGE_NEXT, .name = "kb-page-next", .keybinding = - "Page_Down" }, - { .id = ROW_FIRST, .name = "kb-row-first", .keybinding = - "Home,KP_Home" }, - { .id = ROW_LAST, .name = "kb-row-last", .keybinding = - "End,KP_End" }, - { .id = ROW_SELECT, .name = "kb-row-select", .keybinding = - "Control+space" }, + { .id = PAGE_NEXT, .name = "kb-page-next", .keybinding = "Page_Down" }, + { .id = ROW_FIRST, .name = "kb-row-first", .keybinding = "Home,KP_Home" }, + { .id = ROW_LAST, .name = "kb-row-last", .keybinding = "End,KP_End" }, + { .id = ROW_SELECT, .name = "kb-row-select", .keybinding = "Control+space" }, { .id = CANCEL, .name = "kb-cancel", .keybinding = "Escape" }, { .id = CUSTOM_1, .name = "kb-custom-1", .keybinding = "Alt+1" }, { .id = CUSTOM_2, .name = "kb-custom-2", .keybinding = "Alt+2" }, @@ -102,27 +75,17 @@ DefaultBinding bindings[NUM_ABE] = { .id = CUSTOM_8, .name = "kb-custom-8", .keybinding = "Alt+8" }, { .id = CUSTOM_9, .name = "kb-custom-9", .keybinding = "Alt+9" }, { .id = CUSTOM_10, .name = "kb-custom-10", .keybinding = "Alt+0" }, - { .id = CUSTOM_11, .name = "kb-custom-11", .keybinding = - "Alt+Shift+1" }, - { .id = CUSTOM_12, .name = "kb-custom-12", .keybinding = - "Alt+Shift+2" }, - { .id = CUSTOM_13, .name = "kb-custom-13", .keybinding = - "Alt+Shift+3" }, - { .id = CUSTOM_14, .name = "kb-custom-14", .keybinding = - "Alt+Shift+4" }, - { .id = CUSTOM_15, .name = "kb-custom-15", .keybinding = - "Alt+Shift+5" }, - { .id = CUSTOM_16, .name = "kb-custom-16", .keybinding = - "Alt+Shift+6" }, - { .id = CUSTOM_17, .name = "kb-custom-17", .keybinding = - "Alt+Shift+7" }, - { .id = CUSTOM_18, .name = "kb-custom-18", .keybinding = - "Alt+Shift+8" }, - { .id = CUSTOM_19, .name = "kb-custom-19", .keybinding = - "Alt+Shift+9" }, + { .id = CUSTOM_11, .name = "kb-custom-11", .keybinding = "Alt+Shift+1" }, + { .id = CUSTOM_12, .name = "kb-custom-12", .keybinding = "Alt+Shift+2" }, + { .id = CUSTOM_13, .name = "kb-custom-13", .keybinding = "Alt+Shift+3" }, + { .id = CUSTOM_14, .name = "kb-custom-14", .keybinding = "Alt+Shift+4" }, + { .id = CUSTOM_15, .name = "kb-custom-15", .keybinding = "Alt+Shift+5" }, + { .id = CUSTOM_16, .name = "kb-custom-16", .keybinding = "Alt+Shift+6" }, + { .id = CUSTOM_17, .name = "kb-custom-17", .keybinding = "Alt+Shift+7" }, + { .id = CUSTOM_18, .name = "kb-custom-18", .keybinding = "Alt+Shift+8" }, + { .id = CUSTOM_19, .name = "kb-custom-19", .keybinding = "Alt+Shift+9" }, }; - void setup_abe ( void ) { for ( int iter = 0; iter < NUM_ABE; iter++ ) { @@ -133,8 +96,7 @@ void setup_abe ( void ) abe[id].num_bindings = 0; abe[id].kb = NULL; - config_parser_add_option ( xrm_String, - abe[id].name, (void * *) &( abe[id].keystr ) ); + config_parser_add_option ( xrm_String, abe[id].name, (void * *) &( abe[id].keystr ) ); } } diff --git a/source/rofi.c b/source/rofi.c index 763ce15e..9c003158 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -130,7 +130,6 @@ static inline MainLoopEvent wait_for_xevent_or_timeout ( Display *display, int x return ML_XEVENT; } - /** * Levenshtein Sorting. */ @@ -199,9 +198,7 @@ static Window create_window ( Display *display ) Window box = XCreateWindow ( display, DefaultRootWindow ( display ), 0, 0, 200, 100, config.menu_bw, vinfo.depth, InputOutput, vinfo.visual, CWColormap | CWBorderPixel | CWBackPixel, &attr ); - XSelectInput ( display, box, - KeyReleaseMask | KeyPressMask | ExposureMask | - ButtonPressMask | StructureNotifyMask | FocusChangeMask ); + XSelectInput ( display, box, KeyReleaseMask | KeyPressMask | ExposureMask | ButtonPressMask | StructureNotifyMask | FocusChangeMask ); gc = XCreateGC ( display, box, 0, 0 ); int line_style = LineOnOffDash; @@ -215,15 +212,12 @@ static Window create_window ( Display *display ) XSetForeground ( display, gc, color_separator ( display ) ); // make it an unmanaged window if ( !normal_window_mode ) { - window_set_atom_prop ( display, box, netatoms[_NET_WM_STATE], - &netatoms[_NET_WM_STATE_ABOVE], - 1 ); + window_set_atom_prop ( display, box, netatoms[_NET_WM_STATE], &netatoms[_NET_WM_STATE_ABOVE], 1 ); XSetWindowAttributes sattr = { .override_redirect = True }; XChangeWindowAttributes ( display, box, CWOverrideRedirect, &sattr ); } else{ - window_set_atom_prop ( display, box, netatoms[_NET_WM_WINDOW_TYPE], - &netatoms[_NET_WM_WINDOW_TYPE_NORMAL], 1 ); + window_set_atom_prop ( display, box, netatoms[_NET_WM_WINDOW_TYPE], &netatoms[_NET_WM_WINDOW_TYPE_NORMAL], 1 ); } // Set the WM_NAME @@ -353,7 +347,6 @@ static void calculate_window_position ( MenuState *state, const workarea *mon ) state->y += config.y_offset; } - /** * @param state Internal state of the menu. * @@ -367,12 +360,10 @@ static void menu_calculate_rows_columns ( MenuState *state ) // Calculate the number or rows. We do this by getting the num_lines rounded up to X columns // (num elements is better name) then dividing by columns. - state->max_rows = MIN ( state->menu_lines, - (unsigned int) ( - ( state->num_lines + - ( state->columns - state->num_lines % state->columns ) % - state->columns ) / ( state->columns ) - ) ); + state->max_rows = MIN ( state->menu_lines, (unsigned int) ( ( state->num_lines + + ( state->columns - state->num_lines % + state->columns ) % state->columns ) / + ( state->columns ) ) ); // Always have at least one row. state->max_rows = MAX ( 1, state->max_rows ); @@ -382,8 +373,7 @@ static void menu_calculate_rows_columns ( MenuState *state ) // If it would fit in one column, only use one column. if ( state->num_lines < state->max_elements ) { state->columns = - ( state->num_lines + ( state->max_rows - state->num_lines % state->max_rows ) % - state->max_rows ) / state->max_rows; + ( state->num_lines + ( state->max_rows - state->num_lines % state->max_rows ) % state->max_rows ) / state->max_rows; state->max_elements = state->menu_lines * state->columns; } // Sanitize. @@ -410,8 +400,7 @@ static void menu_calculate_window_and_element_width ( MenuState *state, workarea } else{ // Calculate as float to stop silly, big rounding down errors. - state->w = config.menu_width < - 101 ? ( mon->w / 100.0f ) * ( float ) config.menu_width : config.menu_width; + state->w = config.menu_width < 101 ? ( mon->w / 100.0f ) * ( float ) config.menu_width : config.menu_width; // Compensate for border width. state->w -= config.menu_bw * 2; } @@ -419,8 +408,7 @@ static void menu_calculate_window_and_element_width ( MenuState *state, workarea if ( state->columns > 0 ) { state->element_width = state->w - ( 2 * ( config.padding ) ); // Divide by the # columns - state->element_width = - ( state->element_width - ( state->columns - 1 ) * config.line_margin ) / state->columns; + state->element_width = ( state->element_width - ( state->columns - 1 ) * config.line_margin ) / state->columns; } } @@ -525,9 +513,8 @@ inline static void menu_nav_up ( MenuState *state ) */ inline static void menu_nav_down ( MenuState *state ) { - state->selected = state->selected < state->filtered_lines - 1 ? MIN ( - state->filtered_lines - 1, state->selected + 1 ) : 0; - state->update = TRUE; + state->selected = state->selected < state->filtered_lines - 1 ? MIN ( state->filtered_lines - 1, state->selected + 1 ) : 0; + state->update = TRUE; } /** * @param state The current MenuState @@ -715,8 +702,7 @@ static void menu_refilter ( MenuState *state ) // input changed for ( unsigned int i = 0; i < state->num_lines; i++ ) { - int match = state->sw->token_match ( tokens, state->lines[i], config.case_sensitive, i, - state->sw ); + int match = state->sw->token_match ( tokens, state->lines[i], config.case_sensitive, i, state->sw ); // If each token was matched, add it to list. if ( match ) { @@ -754,15 +740,13 @@ static void menu_refilter ( MenuState *state ) state->rchanged = TRUE; } - static void menu_draw ( MenuState *state ) { unsigned int i, offset = 0; // selected row is always visible. // If selected is visible do not scroll. - if ( ( ( state->selected - ( state->last_offset ) ) < ( state->max_elements ) ) - && ( state->selected >= ( state->last_offset ) ) ) { + if ( ( ( state->selected - ( state->last_offset ) ) < ( state->max_elements ) ) && ( state->selected >= ( state->last_offset ) ) ) { offset = state->last_offset; } else{ @@ -782,8 +766,7 @@ static void menu_draw ( MenuState *state ) unsigned int a_lines = MIN ( ( state->filtered_lines - offset ), state->max_elements ); // Calculate number of columns - unsigned int columns = ( a_lines + ( state->max_rows - a_lines % state->max_rows ) % - state->max_rows ) / state->max_rows; + unsigned int columns = ( a_lines + ( state->max_rows - a_lines % state->max_rows ) % state->max_rows ) / state->max_rows; columns = MIN ( columns, state->columns ); // Update the handle length. @@ -814,16 +797,12 @@ static void menu_draw ( MenuState *state ) 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. - textbox_moveresize ( state->boxes[i], - ex + x_offset, ey + y_offset, - element_width, element_height ); + textbox_moveresize ( state->boxes[i], ex + x_offset, ey + y_offset, element_width, element_height ); { TextBoxFontType type = ( ( ( i % state->max_rows ) & 1 ) == 0 ) ? NORMAL : ALT; int fstate = 0; - const char *text = state->sw->mgrv ( state->line_map[i + offset], state->sw, - &fstate ); - TextBoxFontType tbft = fstate | - ( ( i + offset ) == state->selected ? HIGHLIGHT : type ); + const char *text = state->sw->mgrv ( state->line_map[i + offset], state->sw, &fstate ); + TextBoxFontType tbft = fstate | ( ( i + offset ) == state->selected ? HIGHLIGHT : type ); textbox_font ( state->boxes[i], tbft ); textbox_text ( state->boxes[i], text ); } @@ -856,8 +835,7 @@ static void menu_update ( MenuState *state ) menu_draw ( state ); // Why do we need the special -1? XDrawLine ( display, main_window, gc, 0, - state->line_height + ( config.padding ) * 1 + config.line_margin + 1, - state->w, + state->line_height + ( config.padding ) * 1 + config.line_margin + 1, state->w, state->line_height + ( config.padding ) * 1 + config.line_margin + 1 ); if ( state->message_tb ) { XDrawLine ( display, main_window, gc, @@ -867,10 +845,8 @@ static void menu_update ( MenuState *state ) if ( config.sidebar_mode == TRUE ) { XDrawLine ( display, main_window, gc, - 0, - state->h - state->line_height - ( config.padding ) * 1 - 1 - config.line_margin, - state->w, - state->h - state->line_height - ( config.padding ) * 1 - 1 - config.line_margin ); + 0, state->h - state->line_height - ( config.padding ) * 1 - 1 - config.line_margin, + state->w, state->h - state->line_height - ( config.padding ) * 1 - 1 - config.line_margin ); for ( unsigned int j = 0; j < num_switchers; j++ ) { textbox_draw ( switchers[j].tb ); } @@ -912,13 +888,11 @@ static void menu_resize ( MenuState *state ) unsigned int sbw = config.line_margin + 8; scrollbar_move ( state->scrollbar, state->w - config.padding - sbw, state->top_offset ); if ( config.sidebar_mode == TRUE ) { - int width = ( state->w - ( 2 * ( config.padding ) + - ( num_switchers - 1 ) * config.line_margin ) ) / num_switchers; + int width = ( state->w - ( 2 * ( config.padding ) + ( num_switchers - 1 ) * config.line_margin ) ) / num_switchers; for ( unsigned int j = 0; j < num_switchers; j++ ) { textbox_moveresize ( switchers[j].tb, config.padding + j * ( width + config.line_margin ), - state->h - state->line_height - config.padding, - width, state->line_height ); + state->h - state->line_height - config.padding, width, state->line_height ); textbox_show ( switchers[j].tb ); textbox_draw ( switchers[j].tb ); } @@ -928,8 +902,7 @@ static void menu_resize ( MenuState *state ) */ { unsigned int last_length = state->max_elements; - int element_height = state->line_height * config.element_height + - config.line_margin; + int element_height = state->line_height * config.element_height + config.line_margin; // Calculated new number of boxes. unsigned int h = ( state->h - state->top_offset ); if ( config.sidebar_mode == TRUE ) { @@ -948,21 +921,17 @@ static void menu_resize ( MenuState *state ) int x_offset = config.padding; // Add newly added boxes. for ( unsigned int i = last_length; i < state->max_elements; i++ ) { - state->boxes[i] = textbox_create ( main_window, &vinfo, map, 0, - x_offset, y_offset, + state->boxes[i] = textbox_create ( main_window, &vinfo, map, 0, x_offset, y_offset, state->element_width, element_height, NORMAL, "" ); } - scrollbar_resize ( state->scrollbar, -1, - ( state->max_rows ) * ( element_height ) - config.line_margin ); + |