mirror of
https://github.com/davatorium/rofi.git
synced 2025-02-03 15:34:54 -05:00
Add selection counter in dmenu mode
This commit is contained in:
parent
ad5b985abe
commit
6e2d0b6319
8 changed files with 75 additions and 8 deletions
|
@ -37,6 +37,8 @@ struct RofiViewState
|
|||
textbox *case_indicator;
|
||||
textbox **boxes;
|
||||
scrollbar *scrollbar;
|
||||
// Small overlay.
|
||||
textbox *overlay;
|
||||
int *distance;
|
||||
unsigned int *line_map;
|
||||
|
||||
|
|
|
@ -154,5 +154,6 @@ void rofi_view_workers_initialize ( void );
|
|||
void rofi_view_workers_finalize ( void );
|
||||
|
||||
void __create_window ( MenuFlags menu_flags );
|
||||
void rofi_view_set_overlay ( RofiViewState *state, const char *text );
|
||||
/**@}*/
|
||||
#endif
|
||||
|
|
|
@ -11,13 +11,15 @@
|
|||
typedef struct
|
||||
{
|
||||
/** X position relative to parent */
|
||||
short x;
|
||||
short x;
|
||||
/** Y position relative to parent */
|
||||
short y;
|
||||
short y;
|
||||
/** Width of the widget */
|
||||
short w;
|
||||
short w;
|
||||
/** Height of the widget */
|
||||
short h;
|
||||
short h;
|
||||
/** enabled or not */
|
||||
gboolean enabled;
|
||||
} Widget;
|
||||
|
||||
/** Macro to get widget from an implementation (e.g. textbox/scrollbar) */
|
||||
|
@ -43,5 +45,9 @@ int widget_intersect ( const Widget *widget, int x, int y );
|
|||
*/
|
||||
void widget_move ( Widget *widget, short x, short y );
|
||||
|
||||
gboolean widget_enabled ( Widget *widget );
|
||||
void widget_disable ( Widget *widget );
|
||||
void widget_enable ( Widget *widget );
|
||||
|
||||
/*@}*/
|
||||
#endif // ROFI_WIDGET_H
|
||||
|
|
|
@ -86,6 +86,7 @@ typedef struct
|
|||
char **cmd_list;
|
||||
unsigned int cmd_list_length;
|
||||
unsigned int only_selected;
|
||||
unsigned int selected_count;
|
||||
} DmenuModePrivateData;
|
||||
|
||||
static char **get_dmenu ( DmenuModePrivateData *pd, FILE *fd, unsigned int *length )
|
||||
|
@ -393,8 +394,7 @@ static void dmenu_finalize ( RofiViewState *state )
|
|||
pd->selected_line = rofi_view_get_selected_line ( state );;
|
||||
MenuReturn mretv = rofi_view_get_return_value ( state );
|
||||
unsigned int next_pos = rofi_view_get_next_position ( state );
|
||||
|
||||
int restart = 0;
|
||||
int restart = 0;
|
||||
// Special behavior.
|
||||
if ( pd->only_selected ) {
|
||||
/**
|
||||
|
@ -436,9 +436,18 @@ static void dmenu_finalize ( RofiViewState *state )
|
|||
if ( pd->selected_list == NULL ) {
|
||||
pd->selected_list = g_malloc0 ( sizeof ( uint32_t ) * ( pd->cmd_list_length / 32 + 1 ) );
|
||||
}
|
||||
pd->selected_count += ( bitget ( pd->selected_list, pd->selected_line ) ? ( -1 ) : ( 1 ) );
|
||||
bittoggle ( pd->selected_list, pd->selected_line );
|
||||
// Move to next line.
|
||||
pd->selected_line = MIN ( next_pos, cmd_list_length - 1 );
|
||||
if ( pd->selected_count > 0 ) {
|
||||
char *str = g_strdup_printf ( "%u/%u", pd->selected_count, pd->cmd_list_length );
|
||||
rofi_view_set_overlay ( state, str );
|
||||
g_free ( str );
|
||||
}
|
||||
else {
|
||||
rofi_view_set_overlay ( state, NULL );
|
||||
}
|
||||
}
|
||||
else {
|
||||
int seen = FALSE;
|
||||
|
|
|
@ -42,7 +42,8 @@ scrollbar *scrollbar_create ( short x, short y, short w, short h )
|
|||
sb->pos = 0;
|
||||
sb->pos_length = 4;
|
||||
|
||||
// Create GC.
|
||||
// Enabled by default
|
||||
sb->widget.enabled = TRUE;
|
||||
return sb;
|
||||
}
|
||||
|
||||
|
@ -76,7 +77,7 @@ void scrollbar_set_handle_length ( scrollbar *sb, unsigned int pos_length )
|
|||
|
||||
void scrollbar_draw ( scrollbar *sb, cairo_t *draw )
|
||||
{
|
||||
if ( sb != NULL ) {
|
||||
if ( sb != NULL && sb->widget.enabled ) {
|
||||
// Calculate position and size.
|
||||
const short bh = sb->widget.h - 0;
|
||||
float sec = ( ( bh ) / (float) sb->length );
|
||||
|
|
|
@ -102,6 +102,8 @@ textbox* textbox_create ( TextboxFlags flags, short x, short y, short w, short h
|
|||
tb->blink_timeout = g_timeout_add ( 1200, textbox_blink, tb );
|
||||
}
|
||||
|
||||
// Enabled by default
|
||||
tb->widget.enabled = TRUE;
|
||||
return tb;
|
||||
}
|
||||
|
||||
|
@ -350,6 +352,9 @@ static void texbox_update ( textbox *tb )
|
|||
}
|
||||
void textbox_draw ( textbox *tb, cairo_t *draw )
|
||||
{
|
||||
if ( tb->widget.enabled == FALSE ) {
|
||||
return;
|
||||
}
|
||||
texbox_update ( tb );
|
||||
|
||||
/* Write buffer */
|
||||
|
|
|
@ -1066,6 +1066,9 @@ void rofi_view_update ( RofiViewState *state )
|
|||
}
|
||||
}
|
||||
}
|
||||
if ( state->overlay ) {
|
||||
textbox_draw ( state->overlay, d );
|
||||
}
|
||||
state->update = FALSE;
|
||||
|
||||
// Draw to actual window.
|
||||
|
@ -1726,6 +1729,8 @@ RofiViewState *rofi_view_create ( Mode *sw,
|
|||
state->top_offset += config.line_margin * 2 + 2;
|
||||
}
|
||||
|
||||
state->overlay = textbox_create ( TB_AUTOWIDTH, 0, 0, 20, state->line_height, URGENT, "blaat" );
|
||||
widget_disable ( WIDGET ( state->overlay ) );
|
||||
// filtered list display
|
||||
state->boxes = g_malloc0_n ( state->max_elements, sizeof ( textbox* ) );
|
||||
|
||||
|
@ -1929,3 +1934,20 @@ Mode * rofi_view_get_mode ( RofiViewState *state )
|
|||
return state->sw;
|
||||
}
|
||||
|
||||
void rofi_view_set_overlay ( RofiViewState *state, const char *text )
|
||||
{
|
||||
if ( state->overlay == NULL ) {
|
||||
return;
|
||||
}
|
||||
if ( text == NULL ) {
|
||||
widget_disable ( WIDGET ( state->overlay ) );
|
||||
state->update = TRUE;
|
||||
return;
|
||||
}
|
||||
widget_enable ( WIDGET ( state->overlay ) );
|
||||
textbox_text ( state->overlay, text );
|
||||
unsigned int x_offset = CacheState.width - ( 2 * state->border ) - textbox_get_width ( state->case_indicator );
|
||||
x_offset -= textbox_get_width ( state->overlay );
|
||||
widget_move ( WIDGET ( state->overlay ), x_offset, state->border );
|
||||
state->update = TRUE;
|
||||
}
|
||||
|
|
|
@ -22,3 +22,24 @@ void widget_move ( Widget *widget, short x, short y )
|
|||
widget->y = y;
|
||||
}
|
||||
}
|
||||
|
||||
gboolean widget_enabled ( Widget *widget )
|
||||
{
|
||||
if ( widget != NULL ) {
|
||||
return widget->enabled;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void widget_enable ( Widget *widget )
|
||||
{
|
||||
if ( widget ) {
|
||||
widget->enabled = TRUE;
|
||||
}
|
||||
}
|
||||
void widget_disable ( Widget *widget )
|
||||
{
|
||||
if ( widget ) {
|
||||
widget->enabled = FALSE;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue