1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2025-01-27 15:25:24 -05:00

Add selection indicator to dmenu mode.

This commit is contained in:
Dave Davenport 2016-07-18 23:49:26 +02:00
parent fc40aa520f
commit 59635919ea
9 changed files with 67 additions and 50 deletions

View file

@ -39,15 +39,16 @@ typedef struct
typedef enum typedef enum
{ {
TB_AUTOHEIGHT = 1 << 0, TB_AUTOHEIGHT = 1 << 0,
TB_AUTOWIDTH = 1 << 1, TB_AUTOWIDTH = 1 << 1,
TB_LEFT = 1 << 16, TB_LEFT = 1 << 16,
TB_RIGHT = 1 << 17, TB_RIGHT = 1 << 17,
TB_CENTER = 1 << 18, TB_CENTER = 1 << 18,
TB_EDITABLE = 1 << 19, TB_EDITABLE = 1 << 19,
TB_MARKUP = 1 << 20, TB_MARKUP = 1 << 20,
TB_WRAP = 1 << 21, TB_WRAP = 1 << 21,
TB_PASSWORD = 1 << 22, TB_PASSWORD = 1 << 22,
TB_INDICATOR = 1 << 23,
} TextboxFlags; } TextboxFlags;
typedef enum typedef enum

View file

@ -24,6 +24,8 @@ typedef enum
MENU_NORMAL_WINDOW = 2, MENU_NORMAL_WINDOW = 2,
/** ERROR dialog */ /** ERROR dialog */
MENU_ERROR_DIALOG = 4, MENU_ERROR_DIALOG = 4,
/** INDICATOR */
MENU_INDICATOR = 8,
} MenuFlags; } MenuFlags;
/** /**

View file

@ -541,13 +541,17 @@ static void dmenu_finalize ( RofiViewState *state )
int dmenu_switcher_dialog ( void ) int dmenu_switcher_dialog ( void )
{ {
mode_init ( &dmenu_mode ); mode_init ( &dmenu_mode );
MenuFlags menu_flags = MENU_NORMAL; MenuFlags menu_flags = MENU_INDICATOR;
DmenuModePrivateData *pd = (DmenuModePrivateData *) dmenu_mode.private_data; DmenuModePrivateData *pd = (DmenuModePrivateData *) dmenu_mode.private_data;
char *input = NULL; char *input = NULL;
unsigned int cmd_list_length = pd->cmd_list_length; unsigned int cmd_list_length = pd->cmd_list_length;
char **cmd_list = pd->cmd_list; char **cmd_list = pd->cmd_list;
pd->only_selected = FALSE; pd->only_selected = FALSE;
if ( find_arg ( "-no-selection-indicator") >= 0 ){
menu_flags = MENU_NORMAL;
}
if ( find_arg ( "-markup-rows" ) >= 0 ) { if ( find_arg ( "-markup-rows" ) >= 0 ) {
pd->do_markup = TRUE; pd->do_markup = TRUE;
} }

View file

@ -198,7 +198,7 @@ static char **read_hosts_file ( char ** retv, unsigned int *length )
// Reading one line per time. // Reading one line per time.
while ( getline ( &buffer, &buffer_length, fd ) > 0 ) { while ( getline ( &buffer, &buffer_length, fd ) > 0 ) {
// Evaluate one line. // Evaluate one line.
unsigned int index = 0, ti = 0; unsigned int index = 0, ti = 0;
char *token = buffer; char *token = buffer;
// Tokenize it. // Tokenize it.

View file

@ -680,7 +680,7 @@ static char * _generate_display_string ( const ModeModePrivateData *pd, client *
struct arg d = { pd, c }; struct arg d = { pd, c };
char *res = g_regex_replace_eval ( pd->window_regex, config.window_format, -1, 0, 0, char *res = g_regex_replace_eval ( pd->window_regex, config.window_format, -1, 0, 0,
helper_eval_cb, &d, NULL ); 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 ) static char *_get_display_value ( const Mode *sw, unsigned int selected_line, int *state, int get_entry )

View file

@ -197,7 +197,7 @@ GRegex **tokenize ( const char *input, int case_sensitive )
} }
char *saveptr = NULL, *token; char *saveptr = NULL, *token;
GRegex **retv = NULL; GRegex **retv = NULL;
if ( !config.tokenize ) { if ( !config.tokenize ) {
retv = g_malloc0 ( sizeof ( GRegex* ) * 2 ); retv = g_malloc0 ( sizeof ( GRegex* ) * 2 );
retv[0] = (GRegex *) create_regex ( input, case_sensitive ); retv[0] = (GRegex *) create_regex ( input, case_sensitive );

View file

@ -74,9 +74,9 @@ struct xkb_stuff xkb = {
.keymap = NULL, .keymap = NULL,
.state = NULL, .state = NULL,
.compose = { .compose = {
.table = NULL, .table = NULL,
.state = NULL .state = NULL
} }
}; };
char *config_path = NULL; char *config_path = NULL;
// Array of modi. // 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 ); xkb.state = xkb_x11_state_new_from_device ( xkb.keymap, xcb->connection, xkb.device_id );
break; break;
case XCB_XKB_STATE_NOTIFY: case XCB_XKB_STATE_NOTIFY:
{ {
xcb_xkb_state_notify_event_t *ksne = (xcb_xkb_state_notify_event_t *) ev; xcb_xkb_state_notify_event_t *ksne = (xcb_xkb_state_notify_event_t *) ev;
guint modmask; guint modmask;
xkb_state_update_mask ( xkb.state, xkb_state_update_mask ( xkb.state,
ksne->baseMods, ksne->baseMods,
ksne->latchedMods, ksne->latchedMods,
ksne->lockedMods, ksne->lockedMods,
ksne->baseGroup, ksne->baseGroup,
ksne->latchedGroup, ksne->latchedGroup,
ksne->lockedGroup ); ksne->lockedGroup );
modmask = x11_get_current_mask ( &xkb ); modmask = x11_get_current_mask ( &xkb );
if ( modmask == 0 ) { if ( modmask == 0 ) {
abe_trigger_release ( ); abe_trigger_release ( );
}
break;
} }
break;
}
} }
return G_SOURCE_CONTINUE; return G_SOURCE_CONTINUE;
} }

View file

@ -28,6 +28,7 @@
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
#include <glib.h> #include <glib.h>
#include <math.h>
#include "settings.h" #include "settings.h"
#include "textbox.h" #include "textbox.h"
#include "keyb.h" #include "keyb.h"
@ -37,6 +38,8 @@
#define SIDE_MARGIN 1 #define SIDE_MARGIN 1
#define DOT_OFFSET 15
/** /**
* Font + font color cache. * Font + font color cache.
* Avoid re-loading font on every change on every textbox. * 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; tb->color_fg = color->fg;
break; break;
} }
if ( ( tbft & SELECTED ) == SELECTED ) {
tb->color_bg = color->hlbg;
tb->color_fg = color->hlfg;
}
if ( tb->tbft != tbft ) { if ( tb->tbft != tbft ) {
tb->update = TRUE; tb->update = TRUE;
} }
@ -207,6 +206,7 @@ void textbox_text ( textbox *tb, const char *text )
// within the parent handled auto width/height modes // within the parent handled auto width/height modes
void textbox_moveresize ( textbox *tb, int x, int y, int w, int h ) 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 ) { if ( tb->flags & TB_AUTOWIDTH ) {
pango_layout_set_width ( tb->layout, -1 ); pango_layout_set_width ( tb->layout, -1 );
w = textbox_get_width ( tb ); 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 ) { if ( tb->flags & TB_AUTOHEIGHT ) {
// Width determines height! // Width determines height!
int tw = MAX ( 1, w ); 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 ); 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 // 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; tb->update = TRUE;
} }
@ -270,6 +270,7 @@ void textbox_free ( textbox *tb )
static void texbox_update ( textbox *tb ) static void texbox_update ( textbox *tb )
{ {
unsigned int offset = ( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0;
if ( tb->update ) { if ( tb->update ) {
if ( tb->main_surface ) { if ( tb->main_surface ) {
cairo_destroy ( tb->main_draw ); cairo_destroy ( tb->main_draw );
@ -303,18 +304,18 @@ static void texbox_update ( textbox *tb )
} }
// Skip the side MARGIN on the X axis. // Skip the side MARGIN on the X axis.
int x = SIDE_MARGIN; int x = SIDE_MARGIN + offset;
int y = 0; int y = 0;
if ( tb->flags & TB_RIGHT ) { if ( tb->flags & TB_RIGHT ) {
int line_width = 0; int line_width = 0;
// Get actual width. // Get actual width.
pango_layout_get_pixel_size ( tb->layout, &line_width, NULL ); 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 ) { else if ( tb->flags & TB_CENTER ) {
int tw = textbox_get_font_width ( tb ); 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 ); short fh = textbox_get_font_height ( tb );
if ( fh > tb->widget.h ) { if ( fh > tb->widget.h ) {
@ -325,16 +326,12 @@ static void texbox_update ( textbox *tb )
} }
// Set ARGB // Set ARGB
Color col = tb->color_bg; Color col = tb->color_bg;
double scale = 1.0; cairo_set_source_rgba ( tb->main_draw, col.red, col.green, col.blue, col.alpha );
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 );
cairo_paint ( tb->main_draw ); cairo_paint ( tb->main_draw );
col = tb->color_fg; 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 // draw the cursor
if ( tb->flags & TB_EDITABLE && tb->blink ) { if ( tb->flags & TB_EDITABLE && tb->blink ) {
cairo_rectangle ( tb->main_draw, x + cursor_x, y, cursor_width, font_height ); 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 ); cairo_move_to ( tb->main_draw, x, y );
pango_cairo_show_layout ( tb->main_draw, tb->layout ); 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; tb->update = FALSE;
} }
} }
@ -674,7 +683,8 @@ void textbox_cleanup ( void )
int textbox_get_width ( textbox *tb ) 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 ) int textbox_get_height ( textbox *tb )

View file

@ -398,7 +398,7 @@ static void rofi_view_resize ( RofiViewState *state )
int x_offset = state->border; int x_offset = state->border;
// Add newly added boxes. // Add newly added boxes.
for ( unsigned int i = last_length; i < state->max_elements; i++ ) { 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, "" ); state->element_width, element_height, NORMAL, "" );
} }
scrollbar_resize ( state->scrollbar, -1, ( state->max_rows ) * ( element_height ) - config.line_margin ); 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; int x_offset = state->border;
for ( unsigned int i = 0; i < state->max_elements; i++ ) { 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, "" ); state->element_width, element_height, NORMAL, "" );
} }
if ( !config.hide_scrollbar ) { if ( !config.hide_scrollbar ) {