summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2016-06-26 15:48:12 +0200
committerDave Davenport <qball@gmpclient.org>2016-06-26 15:48:12 +0200
commit6e2d0b63191996b3d247cb535aa9c100c13c7464 (patch)
tree796bd328a199244ee4807b49e6dcba870a4b1f28
parentad5b985abe444d45005f74e3eb45c66a3c8e334b (diff)
Add selection counter in dmenu mode
-rw-r--r--include/view-internal.h2
-rw-r--r--include/view.h1
-rw-r--r--include/widget.h14
-rw-r--r--source/dialogs/dmenu.c13
-rw-r--r--source/scrollbar.c5
-rw-r--r--source/textbox.c5
-rw-r--r--source/view.c22
-rw-r--r--source/widget.c21
8 files changed, 75 insertions, 8 deletions
diff --git a/include/view-internal.h b/include/view-internal.h
index 43ba6875..8d6f2bdd 100644
--- a/include/view-internal.h
+++ b/include/view-internal.h
@@ -37,6 +37,8 @@ struct RofiViewState
textbox *case_indicator;
textbox **boxes;
scrollbar *scrollbar;
+ // Small overlay.
+ textbox *overlay;
int *distance;
unsigned int *line_map;
diff --git a/include/view.h b/include/view.h
index 4a69ab83..28f4e438 100644
--- a/include/view.h
+++ b/include/view.h
@@ -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
diff --git a/include/widget.h b/include/widget.h
index 57e2371a..acf3037d 100644
--- a/include/widget.h
+++ b/include/widget.h
@@ -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
diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c
index a38a88cb..ebb0b9cd 100644
--- a/source/dialogs/dmenu.c
+++ b/source/dialogs/dmenu.c
@@ -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;
diff --git a/source/scrollbar.c b/source/scrollbar.c
index 0ea46f5c..84e3219b 100644
--- a/source/scrollbar.c
+++ b/source/scrollbar.c
@@ -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 );
diff --git a/source/textbox.c b/source/textbox.c
index e19234b2..05602581 100644
--- a/source/textbox.c
+++ b/source/textbox.c
@@ -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 */
diff --git a/source/view.c b/source/view.c
index f6d9b3d5..277c7f7b 100644
--- a/source/view.c
+++ b/source/view.c
@@ -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;
+}
diff --git a/source/widget.c b/source/widget.c
index 15162ba7..fe788c97 100644
--- a/source/widget.c
+++ b/source/widget.c
@@ -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;
+ }
+}