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:
parent
fc40aa520f
commit
59635919ea
9 changed files with 67 additions and 50 deletions
|
@ -48,6 +48,7 @@ typedef enum
|
|||
TB_MARKUP = 1 << 20,
|
||||
TB_WRAP = 1 << 21,
|
||||
TB_PASSWORD = 1 << 22,
|
||||
TB_INDICATOR = 1 << 23,
|
||||
} TextboxFlags;
|
||||
|
||||
typedef enum
|
||||
|
|
|
@ -24,6 +24,8 @@ typedef enum
|
|||
MENU_NORMAL_WINDOW = 2,
|
||||
/** ERROR dialog */
|
||||
MENU_ERROR_DIALOG = 4,
|
||||
/** INDICATOR */
|
||||
MENU_INDICATOR = 8,
|
||||
} MenuFlags;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 )
|
||||
|
|
|
@ -76,7 +76,7 @@ struct xkb_stuff xkb = {
|
|||
.compose = {
|
||||
.table = NULL,
|
||||
.state = NULL
|
||||
}
|
||||
}
|
||||
};
|
||||
char *config_path = NULL;
|
||||
// Array of modi.
|
||||
|
|
|
@ -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 ) {
|
||||
|
@ -326,15 +327,11 @@ 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 );
|
||||
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 )
|
||||
|
|
|
@ -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 ) {
|
||||
|
|
Loading…
Add table
Reference in a new issue