From 063195922f667a1d25efdb3ccdbd426fcf62cb9f Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Sat, 19 Nov 2022 21:03:22 +0100 Subject: [PATCH] [DMenu] Add -ellipsize-mode option. --- doc/rofi-dmenu.5 | 9 +++++++++ doc/rofi-dmenu.5.markdown | 6 ++++++ include/view.h | 6 +++++- include/widgets/listview.h | 3 ++- pkgconfig/rofi.pc.in | 2 +- source/modes/dmenu.c | 22 +++++++++++++++++++--- source/view.c | 5 +++-- source/widgets/listview.c | 4 ++-- 8 files changed, 47 insertions(+), 10 deletions(-) diff --git a/doc/rofi-dmenu.5 b/doc/rofi-dmenu.5 index 674f949e..c11dc96c 100644 --- a/doc/rofi-dmenu.5 +++ b/doc/rofi-dmenu.5 @@ -298,6 +298,15 @@ When multi-select is enabled, prefix this string when element is not selected. .PP \fIdefault\fP: "☐ " +.PP +\fB\fC-ellipsize-mode\fR (start|middle|end) + +.PP +Set ellipsize mode on the listview. + +.PP +\fIdefault\fP "end" + .SH PARSING ROW OPTIONS .PP Extra options for individual rows can be also set. See the \fBrofi-script(5)\fP manpage for details; the syntax and supported features are identical. diff --git a/doc/rofi-dmenu.5.markdown b/doc/rofi-dmenu.5.markdown index f9732a5d..ff2f0203 100644 --- a/doc/rofi-dmenu.5.markdown +++ b/doc/rofi-dmenu.5.markdown @@ -192,6 +192,12 @@ When multi-select is enabled, prefix this string when element is not selected. *default*: "☐ " +`-ellipsize-mode` (start|middle|end) + +Set ellipsize mode on the listview. + +*default* "end" + ## PARSING ROW OPTIONS Extra options for individual rows can be also set. See the **rofi-script(5)** manpage for details; the syntax and supported features are identical. diff --git a/include/view.h b/include/view.h index 9ca8bfbf..17326a1e 100644 --- a/include/view.h +++ b/include/view.h @@ -29,6 +29,7 @@ #define ROFI_VIEW_H #include "mode.h" +#include #include /** * @defgroup View View @@ -338,9 +339,12 @@ void rofi_capture_screenshot(void); void rofi_view_set_window_title(const char *title); /** + @param state The window state handle + @param mode The pango ellipsize mode to user * set ellipsize mode to start. */ -void rofi_view_ellipsize_start(RofiViewState *state); +void rofi_view_ellipsize_listview(RofiViewState *state, + PangoEllipsizeMode mode); /** * @param new_x New XIM window x pos diff --git a/include/widgets/listview.h b/include/widgets/listview.h index ad44f15c..5ffb4f31 100644 --- a/include/widgets/listview.h +++ b/include/widgets/listview.h @@ -29,6 +29,7 @@ #define ROFI_LISTVIEW_H #include "widgets/textbox.h" +#include /** * @defgroup listview listview @@ -276,7 +277,7 @@ void listview_toggle_ellipsizing(listview *lv); * Set ellipsize mode to start. */ -void listview_set_ellipsize_start(listview *lv); +void listview_set_ellipsize(listview *lv, PangoEllipsizeMode mode); /** * @param lv Handler to the listview object. diff --git a/pkgconfig/rofi.pc.in b/pkgconfig/rofi.pc.in index 0c290594..59fb53b2 100644 --- a/pkgconfig/rofi.pc.in +++ b/pkgconfig/rofi.pc.in @@ -7,6 +7,6 @@ pluginsdir=@libdir@/rofi/ Name: rofi Description: Header files for rofi plugins -Requires.private: glib-2.0 >= 2.40 gmodule-2.0 cairo +Requires.private: glib-2.0 >= 2.40 gmodule-2.0 cairo pango Version: @VERSION@ Cflags: -I${includedir}/ diff --git a/source/modes/dmenu.c b/source/modes/dmenu.c index f5b667a3..ee5e9288 100644 --- a/source/modes/dmenu.c +++ b/source/modes/dmenu.c @@ -29,8 +29,8 @@ #define G_LOG_DOMAIN "Modes.DMenu" #include "config.h" -#include "modes/dmenu.h" #include "helper.h" +#include "modes/dmenu.h" #include "rofi-icon-fetcher.h" #include "rofi.h" #include "settings.h" @@ -299,7 +299,7 @@ static gpointer read_input_thread(gpointer userdata) { i = 0; if (block) { double elapsed = g_timer_elapsed(tim, NULL); - if ( elapsed >= 0.1 || block->length == BLOCK_LINES_SIZE) { + if (elapsed >= 0.1 || block->length == BLOCK_LINES_SIZE) { g_timer_start(tim); g_async_queue_push(pd->async_queue, block); block = NULL; @@ -957,7 +957,21 @@ int dmenu_mode_dialog(void) { rofi_view_create(&dmenu_mode, input, menu_flags, dmenu_finalize); if (find_arg("-keep-right") >= 0) { - rofi_view_ellipsize_start(state); + rofi_view_ellipsize_listview(state, PANGO_ELLIPSIZE_START); + } + char *ellipsize_mode = NULL; + if (find_arg_str("-ellipsize-mode", &ellipsize_mode) >= 0) { + if (ellipsize_mode) { + if (g_ascii_strcasecmp(ellipsize_mode, "start") == 0) { + rofi_view_ellipsize_listview(state, PANGO_ELLIPSIZE_START); + } else if (g_ascii_strcasecmp(ellipsize_mode, "middle") == 0) { + rofi_view_ellipsize_listview(state, PANGO_ELLIPSIZE_MIDDLE); + } else if (g_ascii_strcasecmp(ellipsize_mode, "end") == 0) { + rofi_view_ellipsize_listview(state, PANGO_ELLIPSIZE_END); + } else { + g_warning("Unrecognized ellipsize mode: '%s'", ellipsize_mode); + } + } } rofi_view_set_selected_line(state, pd->selected_line); rofi_view_set_active(state); @@ -1021,4 +1035,6 @@ void print_dmenu_options(void) { "When multi-select is enabled prefix this string when element " "is not selected.", NULL, is_term); + print_help_msg("-ellipsize-mode", "end", + "Set ellipsize mode(start | middle | end).", NULL, is_term); } diff --git a/source/view.c b/source/view.c index 1c432891..491c1404 100644 --- a/source/view.c +++ b/source/view.c @@ -2499,8 +2499,9 @@ void rofi_view_clear_input(RofiViewState *state) { } } -void rofi_view_ellipsize_start(RofiViewState *state) { - listview_set_ellipsize_start(state->list_view); +void rofi_view_ellipsize_listview(RofiViewState *state, + PangoEllipsizeMode mode) { + listview_set_ellipsize(state->list_view, mode); } void rofi_view_switch_mode(RofiViewState *state, Mode *mode) { diff --git a/source/widgets/listview.c b/source/widgets/listview.c index 0668b8da..79e81893 100644 --- a/source/widgets/listview.c +++ b/source/widgets/listview.c @@ -1104,9 +1104,9 @@ void listview_set_fixed_num_lines(listview *lv) { } } -void listview_set_ellipsize_start(listview *lv) { +void listview_set_ellipsize(listview *lv, PangoEllipsizeMode mode) { if (lv) { - lv->emode = PANGO_ELLIPSIZE_START; + lv->emode = mode; for (unsigned int i = 0; i < lv->cur_elements; i++) { textbox_set_ellipsize(lv->boxes[i].textbox, lv->emode); }