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
{
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

View File

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

View File

@ -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;
}

View File

@ -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.

View File

@ -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 )

View File

@ -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 );

View File

@ -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;
}

View File

@ -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 )

View File

@ -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 ) {