From 52c5592a6f6d55897a03bb9691031c3cf8c71b46 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Sat, 4 May 2019 11:01:09 +0200 Subject: [PATCH] [ListView|Textbox] Add user-settable ellipsize mode. Fixes: #917 --- doc/test_xr.txt | 2 ++ include/keyb.h | 1 + include/widgets/listview.h | 6 ++++++ include/widgets/textbox.h | 9 +++++++++ source/keyb.c | 1 + source/view.c | 5 +++++ source/widgets/listview.c | 21 +++++++++++++++++++++ source/widgets/textbox.c | 19 ++++++++++++++++++- test/mode-test.c | 2 +- 9 files changed, 64 insertions(+), 2 deletions(-) diff --git a/doc/test_xr.txt b/doc/test_xr.txt index fbeca56a..98edf508 100644 --- a/doc/test_xr.txt +++ b/doc/test_xr.txt @@ -190,6 +190,8 @@ rofi.kb-row-last: End,KP_End rofi.kb-row-select: Control+space ! "Take a screenshot of the rofi window" Set from: File rofi.kb-screenshot: Alt+S +! "Toggle between ellipsize modes for displayed data" Set from: Default +! rofi.kb-ellipsize: Alt+period ! "Toggle case sensitivity" Set from: File rofi.kb-toggle-case-sensitivity: grave,dead_grave ! "Toggle sort" Set from: File diff --git a/include/keyb.h b/include/keyb.h index fef1ad52..bc8628b9 100644 --- a/include/keyb.h +++ b/include/keyb.h @@ -126,6 +126,7 @@ typedef enum CUSTOM_18, CUSTOM_19, SCREENSHOT, + CHANGE_ELLIPSIZE, TOGGLE_SORT, SELECT_ELEMENT_1, SELECT_ELEMENT_2, diff --git a/include/widgets/listview.h b/include/widgets/listview.h index abb9b02e..ec5861e1 100644 --- a/include/widgets/listview.h +++ b/include/widgets/listview.h @@ -238,6 +238,12 @@ void listview_set_fixed_num_lines ( listview *lv ); */ void listview_set_max_lines ( listview *lv, unsigned int max_lines ); +/** + * @param lv Handler to the listview object. + * + * Set ellipsize modee. + */ +void listview_toggle_ellipsizing ( listview *lv ); /* @} */ #endif // ROFI_LISTVIEW_H diff --git a/include/widgets/textbox.h b/include/widgets/textbox.h index 550fc3fc..6d666ff0 100644 --- a/include/widgets/textbox.h +++ b/include/widgets/textbox.h @@ -68,6 +68,7 @@ typedef struct double xalign; PangoFontMetrics *metrics; + PangoEllipsizeMode emode; int left_offset; // const char *theme_name; @@ -334,5 +335,13 @@ int textbox_get_desired_width ( widget *wid ); * Move the cursor to the end of the string. */ void textbox_cursor_end ( textbox *tb ); + +/** + * @param tb Handle to the textbox + * @param mode The PangoEllipsizeMode to use displaying the text in the textbox + * + * Set the ellipsizing mode used on the string. + */ +void textbox_set_ellipsize ( textbox *tb, PangoEllipsizeMode mode ); /*@}*/ #endif //ROFI_TEXTBOX_H diff --git a/source/keyb.c b/source/keyb.c index b4603b38..cc5b58c7 100644 --- a/source/keyb.c +++ b/source/keyb.c @@ -77,6 +77,7 @@ ActionBindingEntry rofi_bindings[] = { .id = ROW_LAST, .name = "kb-row-last", .binding = "End,KP_End", .comment = "Go to the last entry" }, { .id = ROW_SELECT, .name = "kb-row-select", .binding = "Control+space", .comment = "Set selected item as input text" }, { .id = SCREENSHOT, .name = "kb-screenshot", .binding = "Alt+S", .comment = "Take a screenshot of the rofi window" }, + { .id = CHANGE_ELLIPSIZE, .name = "kb-ellipsize", .binding = "Alt+period", .comment = "Toggle between ellipsize modes for displayed data" }, { .id = TOGGLE_CASE_SENSITIVITY, .name = "kb-toggle-case-sensitivity", .binding = "grave,dead_grave", .comment = "Toggle case sensitivity" }, { .id = TOGGLE_SORT, .name = "kb-toggle-sort", .binding = "Alt+grave", .comment = "Toggle sort" }, { .id = CANCEL, .name = "kb-cancel", .binding = "Escape,Control+g,Control+bracketleft", .comment = "Quit rofi" }, diff --git a/source/view.c b/source/view.c index e35035fd..e9b4d8d8 100644 --- a/source/view.c +++ b/source/view.c @@ -1149,6 +1149,11 @@ static void rofi_view_trigger_global_action ( KeyBindingAction action ) case SCREENSHOT: rofi_capture_screenshot ( ); break; + case CHANGE_ELLIPSIZE: + if ( state->list_view ) { + listview_toggle_ellipsizing ( state->list_view ); + } + break; case TOGGLE_SORT: if ( state->case_indicator != NULL ) { config.sort = !config.sort; diff --git a/source/widgets/listview.c b/source/widgets/listview.c index b194ced6..cb7f0628 100644 --- a/source/widgets/listview.c +++ b/source/widgets/listview.c @@ -109,6 +109,8 @@ struct _listview char *listview_name; + + PangoEllipsizeMode emode; /** Barview */ struct { @@ -532,6 +534,7 @@ listview *listview_create ( widget *parent, const char *name, listview_update_ca lv->widget.get_desired_height = listview_get_desired_height; lv->eh = eh; + lv->emode = PANGO_ELLIPSIZE_END; lv->scrollbar = scrollbar_create ( WIDGET ( lv ), "scrollbar" ); // Calculate height of an element. // @@ -830,3 +833,21 @@ void listview_set_fixed_num_lines ( listview *lv ) lv->fixed_num_lines = TRUE; } } + +void listview_toggle_ellipsizing ( listview *lv ) +{ + if ( lv ) { + PangoEllipsizeMode mode = lv->emode; + if ( mode == PANGO_ELLIPSIZE_START ) { + mode = PANGO_ELLIPSIZE_MIDDLE; + } else if ( mode == PANGO_ELLIPSIZE_MIDDLE ) { + mode = PANGO_ELLIPSIZE_END; + } else if ( mode == PANGO_ELLIPSIZE_END ) { + mode = PANGO_ELLIPSIZE_START; + } + lv->emode = mode; + for ( unsigned int i = 0; i < lv->cur_elements; i++ ) { + textbox_set_ellipsize ( lv->boxes[i], mode ); + } + } +} diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c index 70c29b10..1adf9fd3 100644 --- a/source/widgets/textbox.c +++ b/source/widgets/textbox.c @@ -177,6 +177,7 @@ textbox* textbox_create ( widget *parent, WidgetType type, const char *name, Tex tb->widget.get_desired_height = textbox_get_desired_height; tb->widget.get_desired_width = textbox_get_desired_width; tb->flags = flags; + tb->emode = PANGO_ELLIPSIZE_END; tb->changed = FALSE; @@ -362,7 +363,9 @@ void textbox_moveresize ( textbox *tb, int x, int y, int w, int h ) pango_layout_set_ellipsize ( tb->layout, PANGO_ELLIPSIZE_MIDDLE ); } else if ( ( tb->flags & TB_WRAP ) != TB_WRAP ) { - pango_layout_set_ellipsize ( tb->layout, PANGO_ELLIPSIZE_END ); + pango_layout_set_ellipsize ( tb->layout, tb->emode ); + } else { + pango_layout_set_ellipsize ( tb->layout, PANGO_ELLIPSIZE_NONE ); } } @@ -950,3 +953,17 @@ int textbox_get_desired_width ( widget *wid ) pango_layout_set_width ( tb->layout, old_width ); return width + padding + offset; } + + +void textbox_set_ellipsize ( textbox *tb, PangoEllipsizeMode mode ) +{ + if ( tb ) + { + tb->emode = mode; + if ( ( tb->flags & TB_WRAP ) != TB_WRAP ) { + // Store the mode. + pango_layout_set_ellipsize ( tb->layout, tb->emode ); + widget_queue_redraw ( WIDGET ( tb ) ); + } + } +} diff --git a/test/mode-test.c b/test/mode-test.c index ba47c59e..a36880ab 100644 --- a/test/mode-test.c +++ b/test/mode-test.c @@ -119,7 +119,7 @@ END_TEST START_TEST(test_mode_num_items) { unsigned int rows = mode_get_num_entries ( &help_keys_mode); - ck_assert_int_eq ( rows, 71); + ck_assert_int_eq ( rows, 72); for ( unsigned int i =0; i < rows; i++ ){ int state = 0; GList *list = NULL;