diff options
author | Dave Davenport <qball@gmpclient.org> | 2016-07-18 23:49:26 +0200 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2016-07-18 23:49:26 +0200 |
commit | 59635919ea4825fa50059bca3aebb9c84e84e410 (patch) | |
tree | 7355a8a7cda2cab63cc3d0669392dcf03bf2400f | |
parent | fc40aa520f80e730863ad96f4a09d2f473b8a7c5 (diff) |
Add selection indicator to dmenu mode.
-rw-r--r-- | include/textbox.h | 19 | ||||
-rw-r--r-- | include/view.h | 2 | ||||
-rw-r--r-- | source/dialogs/dmenu.c | 6 | ||||
-rw-r--r-- | source/dialogs/ssh.c | 2 | ||||
-rw-r--r-- | source/dialogs/window.c | 2 | ||||
-rw-r--r-- | source/helper.c | 2 | ||||
-rw-r--r-- | source/rofi.c | 36 | ||||
-rw-r--r-- | source/textbox.c | 44 | ||||
-rw-r--r-- | source/view.c | 4 |
9 files changed, 67 insertions, 50 deletions
diff --git a/include/textbox.h b/include/textbox.h index 455904f8..94c981be 100644 --- a/include/textbox.h +++ b/include/textbox.h @@ -39,15 +39,16 @@ 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, + TB_INDICATOR = 1 << 23, } TextboxFlags; typedef enum diff --git a/include/view.h b/include/view.h index 28f4e438..5ce93d09 100644 --- a/include/view.h +++ b/include/view.h @@ -24,6 +24,8 @@ typedef enum MENU_NORMAL_WINDOW = 2, /** ERROR dialog */ MENU_ERROR_DIALOG = 4, + /** INDICATOR */ + MENU_INDICATOR = 8, } MenuFlags; /** diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index 6fe27791..0303d1b2 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -541,13 +541,17 @@ static void dmenu_finalize ( RofiViewState *state ) int dmenu_switcher_dialog ( void ) { mode_init ( &dmenu_mode ); - MenuFlags menu_flags = MENU_NORMAL; + MenuFlags menu_flags = MENU_INDICATOR; DmenuModePrivateData *pd = (DmenuModePrivateData *) dmenu_mode.private_data; char *input = NULL; unsigned int cmd_list_length = pd->cmd_list_length; char **cmd_list = pd->cmd_list; pd->only_selected = FALSE; + + if ( find_arg ( "-no-selection-indicator") >= 0 ){ + menu_flags = MENU_NORMAL; + } if ( find_arg ( "-markup-rows" ) >= 0 ) { pd->do_markup = TRUE; } diff --git a/source/dialogs/ssh.c b/source/dialogs/ssh.c index 331e5431..9cc75543 100644 --- a/source/dialogs/ssh.c +++ b/source/dialogs/ssh.c @@ -198,7 +198,7 @@ static char **read_hosts_file ( char ** retv, unsigned int *length ) // Reading one line per time. while ( getline ( &buffer, &buffer_length, fd ) > 0 ) { // Evaluate one line. - unsigned int index = 0, ti = 0; + unsigned int index = 0, ti = 0; char *token = buffer; // Tokenize it. diff --git a/source/dialogs/window.c b/source/dialogs/window.c index 22bd7541..bd553fc3 100644 --- a/source/dialogs/window.c +++ b/source/dialogs/window.c @@ -680,7 +680,7 @@ static char * _generate_display_string ( const ModeModePrivateData *pd, client * struct arg d = { pd, c }; char *res = g_regex_replace_eval ( pd->window_regex, config.window_format, -1, 0, 0, helper_eval_cb, &d, NULL ); - return g_strchomp(res); + return g_strchomp ( res ); } static char *_get_display_value ( const Mode *sw, unsigned int selected_line, int *state, int get_entry ) diff --git a/source/helper.c b/source/helper.c index 684256f8..4c0f5bca 100644 --- a/source/helper.c +++ b/source/helper.c @@ -197,7 +197,7 @@ GRegex **tokenize ( const char *input, int case_sensitive ) } char *saveptr = NULL, *token; - GRegex **retv = NULL; + GRegex **retv = NULL; if ( !config.tokenize ) { retv = g_malloc0 ( sizeof ( GRegex* ) * 2 ); retv[0] = (GRegex *) create_regex ( input, case_sensitive ); diff --git a/source/rofi.c b/source/rofi.c index 74b2f5f6..af19c87c 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -74,9 +74,9 @@ struct xkb_stuff xkb = { .keymap = NULL, .state = NULL, .compose = { - .table = NULL, - .state = NULL - } + .table = NULL, + .state = NULL +} }; char *config_path = NULL; // Array of modi. @@ -441,22 +441,22 @@ static gboolean main_loop_x11_event_handler ( xcb_generic_event_t *ev, G_GNUC_UN xkb.state = xkb_x11_state_new_from_device ( xkb.keymap, xcb->connection, xkb.device_id ); break; case XCB_XKB_STATE_NOTIFY: - { - xcb_xkb_state_notify_event_t *ksne = (xcb_xkb_state_notify_event_t *) ev; - guint modmask; - xkb_state_update_mask ( xkb.state, - ksne->baseMods, - ksne->latchedMods, - ksne->lockedMods, - ksne->baseGroup, - ksne->latchedGroup, - ksne->lockedGroup ); - modmask = x11_get_current_mask ( &xkb ); - if ( modmask == 0 ) { - abe_trigger_release ( ); + { + xcb_xkb_state_notify_event_t *ksne = (xcb_xkb_state_notify_event_t *) ev; + guint modmask; + xkb_state_update_mask ( xkb.state, + ksne->baseMods, + ksne->latchedMods, + ksne->lockedMods, + ksne->baseGroup, + ksne->latchedGroup, + ksne->lockedGroup ); + modmask = x11_get_current_mask ( &xkb ); + if ( modmask == 0 ) { + abe_trigger_release ( ); + } + break; } - break; - } } return G_SOURCE_CONTINUE; } diff --git a/source/textbox.c b/source/textbox.c index 05602581..7eb2584b 100644 --- a/source/textbox.c +++ b/source/textbox.c @@ -28,6 +28,7 @@ #include <ctype.h> #include <string.h> #include <glib.h> +#include <math.h> #include "settings.h" #include "textbox.h" #include "keyb.h" @@ -37,6 +38,8 @@ #define SIDE_MARGIN 1 +#define DOT_OFFSET 15 + /** * Font + font color cache. * Avoid re-loading font on every change on every textbox. @@ -130,10 +133,6 @@ void textbox_font ( textbox *tb, TextBoxFontType tbft ) tb->color_fg = color->fg; break; } - if ( ( tbft & SELECTED ) == SELECTED ) { - tb->color_bg = color->hlbg; - tb->color_fg = color->hlfg; - } if ( tb->tbft != tbft ) { tb->update = TRUE; } @@ -207,6 +206,7 @@ void textbox_text ( textbox *tb, const char *text ) // within the parent handled auto width/height modes void textbox_moveresize ( textbox *tb, int x, int y, int w, int h ) { + unsigned int offset = ( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0; if ( tb->flags & TB_AUTOWIDTH ) { pango_layout_set_width ( tb->layout, -1 ); w = textbox_get_width ( tb ); @@ -224,7 +224,7 @@ void textbox_moveresize ( textbox *tb, int x, int y, int w, int h ) if ( tb->flags & TB_AUTOHEIGHT ) { // Width determines height! int tw = MAX ( 1, w ); - pango_layout_set_width ( tb->layout, PANGO_SCALE * ( tw - 2 * SIDE_MARGIN ) ); + pango_layout_set_width ( tb->layout, PANGO_SCALE * ( tw - 2 * SIDE_MARGIN - offset ) ); h = textbox_get_height ( tb ); } @@ -236,7 +236,7 @@ void textbox_moveresize ( textbox *tb, int x, int y, int w, int h ) } // We always want to update this - pango_layout_set_width ( tb->layout, PANGO_SCALE * ( tb->widget.w - 2 * SIDE_MARGIN ) ); + pango_layout_set_width ( tb->layout, PANGO_SCALE * ( tb->widget.w - 2 * SIDE_MARGIN - offset ) ); tb->update = TRUE; } @@ -270,6 +270,7 @@ void textbox_free ( textbox *tb ) static void texbox_update ( textbox *tb ) { + unsigned int offset = ( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0; if ( tb->update ) { if ( tb->main_surface ) { cairo_destroy ( tb->main_draw ); @@ -303,18 +304,18 @@ static void texbox_update ( textbox *tb ) } // Skip the side MARGIN on the X axis. - int x = SIDE_MARGIN; + int x = SIDE_MARGIN + offset; int y = 0; if ( tb->flags & TB_RIGHT ) { int line_width = 0; // Get actual width. pango_layout_get_pixel_size ( tb->layout, &line_width, NULL ); - x = ( tb->widget.w - line_width - SIDE_MARGIN ); + x = ( tb->widget.w - line_width - SIDE_MARGIN - offset ); } else if ( tb->flags & TB_CENTER ) { int tw = textbox_get_font_width ( tb ); - x = ( ( tb->widget.w - tw - 2 * SIDE_MARGIN ) ) / 2; + x = ( ( tb->widget.w - tw - 2 * SIDE_MARGIN - offset ) ) / 2; } short fh = textbox_get_font_height ( tb ); if ( fh > tb->widget.h ) { @@ -325,16 +326,12 @@ static void texbox_update ( textbox *tb ) } // Set ARGB - Color col = tb->color_bg; - double scale = 1.0; - if ( ( tb->tbft & SELECTED ) == SELECTED && ( tb->tbft & FMOD_MASK ) != HIGHLIGHT ) { - scale = 0.4; - } - cairo_set_source_rgba ( tb->main_draw, col.red, col.green, col.blue, col.alpha * scale ); + Color col = tb->color_bg; + cairo_set_source_rgba ( tb->main_draw, col.red, col.green, col.blue, col.alpha ); cairo_paint ( tb->main_draw ); col = tb->color_fg; - cairo_set_source_rgba ( tb->main_draw, col.red, col.green, col.blue, col.alpha * scale ); + cairo_set_source_rgba ( tb->main_draw, col.red, col.green, col.blue, col.alpha ); // draw the cursor if ( tb->flags & TB_EDITABLE && tb->blink ) { cairo_rectangle ( tb->main_draw, x + cursor_x, y, cursor_width, font_height ); @@ -347,6 +344,18 @@ static void texbox_update ( textbox *tb ) cairo_move_to ( tb->main_draw, x, y ); pango_cairo_show_layout ( tb->main_draw, tb->layout ); + if ( ( tb->flags & TB_INDICATOR ) == TB_INDICATOR && ( tb->tbft & ( SELECTED | HIGHLIGHT ) ) ) { + if ( ( tb->tbft & SELECTED ) == SELECTED ) { + cairo_set_source_rgba ( tb->main_draw, col.red, col.green, col.blue, col.alpha ); + } + else if ( ( tb->tbft & HIGHLIGHT ) == HIGHLIGHT ) { + cairo_set_source_rgba ( tb->main_draw, col.red, col.green, col.blue, col.alpha * 0.2 ); + } + + cairo_arc ( tb->main_draw, DOT_OFFSET / 2.0, tb->widget.h / 2.0, 2.0, 0, 2.0 * M_PI ); + cairo_fill ( tb->main_draw ); + } + tb->update = FALSE; } } @@ -674,7 +683,8 @@ void textbox_cleanup ( void ) int textbox_get_width ( textbox *tb ) { - return textbox_get_font_width ( tb ) + 2 * SIDE_MARGIN; + unsigned int offset = ( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0; + return textbox_get_font_width ( tb ) + 2 * SIDE_MARGIN + offset; } int textbox_get_height ( textbox *tb ) diff --git a/source/view.c b/source/view.c index f513cb45..fc47c838 100644 --- a/source/view.c +++ b/source/view.c @@ -398,7 +398,7 @@ static void rofi_view_resize ( RofiViewState *state ) int x_offset = state->border; // Add newly added boxes. for ( unsigned int i = last_length; i < state->max_elements; i++ ) { - state->boxes[i] = textbox_create ( 0, x_offset, y_offset, + state->boxes[i] = textbox_create ( ( state->menu_flags & MENU_INDICATOR ) ? TB_INDICATOR : 0, x_offset, y_offset, state->element_width, element_height, NORMAL, "" ); } scrollbar_resize ( state->scrollbar, -1, ( state->max_rows ) * ( element_height ) - config.line_margin ); @@ -1725,7 +1725,7 @@ RofiViewState *rofi_view_create ( Mode *sw, int x_offset = state->border; for ( unsigned int i = 0; i < state->max_elements; i++ ) { - state->boxes[i] = textbox_create ( 0, x_offset, y_offset, + state->boxes[i] = textbox_create ( ( state->menu_flags & MENU_INDICATOR ) ? TB_INDICATOR : 0, x_offset, y_offset, state->element_width, element_height, NORMAL, "" ); } if ( !config.hide_scrollbar ) { |