From be6fe8ac617c099e522e03226fb76f5f00ca6833 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Sat, 23 Jul 2022 20:21:00 +0200 Subject: [PATCH] [Textbox] Remove the dot indicator. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Weird hack from dmenu that dripped through rofi code-base for multi-select. Change it so it is just a prefix to the string of ☐ and ☑. --- doc/rofi-dmenu.5 | 18 +++++++++++++++++ doc/rofi-dmenu.5.markdown | 11 ++++++++++ include/view.h | 2 -- include/widgets/listview.h | 7 ------- include/widgets/textbox.h | 1 - source/modes/dmenu.c | 41 ++++++++++++++++++++++++++++++++------ source/view.c | 4 ---- source/widgets/listview.c | 8 +------- source/widgets/textbox.c | 35 +++++++++----------------------- 9 files changed, 74 insertions(+), 53 deletions(-) diff --git a/doc/rofi-dmenu.5 b/doc/rofi-dmenu.5 index 89699be1..b4f134ff 100644 --- a/doc/rofi-dmenu.5 +++ b/doc/rofi-dmenu.5 @@ -280,6 +280,24 @@ The column separator. This is a regex. .PP \fIdefault\fP: '\\t' +.PP +\fB\fC-ballot-selected-str\fR \fIstring\fP + +.PP +When multi-select is enabled, prefix this string when element is selected. + +.PP +\fIdefault\fP: "☑ " + +.PP +\fB\fC-ballot-unselected-str\fR \fIstring\fP + +.PP +When multi-select is enabled, prefix this string when element is not selected. + +.PP +\fIdefault\fP: "☑ " + .SH RETURN VALUE .RS .IP \(bu 2 diff --git a/doc/rofi-dmenu.5.markdown b/doc/rofi-dmenu.5.markdown index d3b7796e..46db5844 100644 --- a/doc/rofi-dmenu.5.markdown +++ b/doc/rofi-dmenu.5.markdown @@ -180,6 +180,17 @@ The column separator. This is a regex. *default*: '\t' +`-ballot-selected-str` *string* + +When multi-select is enabled, prefix this string when element is selected. + +*default*: "☑ " + +`-ballot-unselected-str` *string* + +When multi-select is enabled, prefix this string when element is not selected. + +*default*: "☑ " ## RETURN VALUE diff --git a/include/view.h b/include/view.h index 19af45c5..8fbe0159 100644 --- a/include/view.h +++ b/include/view.h @@ -54,8 +54,6 @@ typedef enum { MENU_NORMAL_WINDOW = 2, /** ERROR dialog */ MENU_ERROR_DIALOG = 4, - /** INDICATOR */ - MENU_INDICATOR = 8, } MenuFlags; /** diff --git a/include/widgets/listview.h b/include/widgets/listview.h index a2e95675..07e76929 100644 --- a/include/widgets/listview.h +++ b/include/widgets/listview.h @@ -230,13 +230,6 @@ void listview_set_scroll_type(listview *lv, ScrollType type); void listview_set_mouse_activated_cb(listview *lv, listview_mouse_activated_cb cb, void *udata); -/** - * @param lv Handler to the listview object - * @param enable boolean to enable/disable multi-select - * - * Enable,disable multi-select. - */ -void listview_set_multi_select(listview *lv, gboolean enable); /** * @param lv Handler to the listview object. * @param num_lines the maximum number of lines to display. diff --git a/include/widgets/textbox.h b/include/widgets/textbox.h index d9320391..b8b5ea20 100644 --- a/include/widgets/textbox.h +++ b/include/widgets/textbox.h @@ -93,7 +93,6 @@ typedef enum { TB_MARKUP = 1 << 20, TB_WRAP = 1 << 21, TB_PASSWORD = 1 << 22, - TB_INDICATOR = 1 << 23, } TextboxFlags; /** * Flags indicating current state of the textbox. diff --git a/source/modes/dmenu.c b/source/modes/dmenu.c index ad4a7ae5..fc4d1d67 100644 --- a/source/modes/dmenu.c +++ b/source/modes/dmenu.c @@ -108,6 +108,9 @@ typedef struct { int pipefd2[2]; guint wake_source; gboolean loading; + + char *ballot_selected; + char *ballot_unselected; } DmenuModePrivateData; #define BLOCK_LINES_SIZE 2048 @@ -338,8 +341,16 @@ static unsigned int dmenu_mode_get_num_entries(const Mode *sw) { } static gchar *dmenu_format_output_string(const DmenuModePrivateData *pd, - const char *input) { + const char *input, + const unsigned int index) { if (pd->columns == NULL) { + if (pd->multi_select) { + if (pd->selected_list && bitget(pd->selected_list, index) == TRUE) { + return g_strdup_printf("%s%s", pd->ballot_selected, input); + } else { + return g_strdup_printf("%s%s", pd->ballot_unselected, input); + } + } return g_strdup(input); } char *retv = NULL; @@ -350,6 +361,12 @@ static gchar *dmenu_format_output_string(const DmenuModePrivateData *pd, ; } GString *str_retv = g_string_new(""); + + if (pd->selected_list && bitget(pd->selected_list, index) == TRUE) { + g_string_append(str_retv, pd->ballot_selected); + } else { + g_string_append(str_retv, pd->ballot_unselected); + } for (uint32_t i = 0; pd->columns && pd->columns[i]; i++) { unsigned int index = (unsigned int)g_ascii_strtoull(pd->columns[i], NULL, 10); @@ -407,7 +424,8 @@ static char *get_display_data(const Mode *data, unsigned int index, int *state, *state |= MARKUP; } char *my_retv = - (get_entry ? dmenu_format_output_string(pd, retv[index].entry) : NULL); + (get_entry ? dmenu_format_output_string(pd, retv[index].entry, index) + : NULL); return my_retv; } @@ -856,8 +874,11 @@ int dmenu_mode_dialog(void) { pd->only_selected = FALSE; pd->multi_select = FALSE; + pd->ballot_selected = "☑ "; + pd->ballot_unselected = "☐ "; + find_arg_str("ballot-selected-str", &(pd->ballot_selected)); + find_arg_str("ballot-unselected-str", &(pd->ballot_unselected)); if (find_arg("-multi-select") >= 0) { - menu_flags = MENU_INDICATOR; pd->multi_select = TRUE; } if (find_arg("-markup-rows") >= 0) { @@ -964,8 +985,16 @@ void print_dmenu_options(void) { print_help_msg("-w", "windowid", "Position over window with X11 windowid.", NULL, is_term); print_help_msg("-keep-right", "", "Set ellipsize to end.", NULL, is_term); - print_help_msg("--display-columns", "", "Only show the selected columns", - NULL, is_term); - print_help_msg("--display-column-separator", "\t", + print_help_msg("-display-columns", "", "Only show the selected columns", NULL, + is_term); + print_help_msg("-display-column-separator", "\t", "Separator to use to split columns (regex)", NULL, is_term); + print_help_msg("-ballot-selected-str", "\t", + "When multi-select is enabled prefix this string when element " + "is selected.", + NULL, is_term); + print_help_msg("-ballot-unselected-str", "\t", + "When multi-select is enabled prefix this string when element " + "is not selected.", + NULL, is_term); } diff --git a/source/view.c b/source/view.c index 29569f40..7416316f 100644 --- a/source/view.c +++ b/source/view.c @@ -1974,10 +1974,6 @@ static void rofi_view_add_widget(RofiViewState *state, widget *parent_widget, listview_set_selection_changed_callback( state->list_view, selection_changed_callback, (void *)state); box_add((box *)parent_widget, WIDGET(state->list_view), TRUE); - // Set configuration - listview_set_multi_select(state->list_view, - (state->menu_flags & MENU_INDICATOR) == - MENU_INDICATOR); listview_set_scroll_type(state->list_view, config.scroll_method); listview_set_mouse_activated_cb( state->list_view, rofi_view_listview_mouse_activated_cb, state); diff --git a/source/widgets/listview.c b/source/widgets/listview.c index acf8eeca..55e61fd8 100644 --- a/source/widgets/listview.c +++ b/source/widgets/listview.c @@ -102,7 +102,6 @@ struct _listview { gboolean filtered; gboolean cycle; - gboolean multi_select; ScrollType scroll_type; @@ -168,7 +167,7 @@ static void listview_set_state(_listview_row r, TextBoxFontType tbft) { } static void listview_add_widget(listview *lv, _listview_row *row, widget *wid, const char *label) { - TextboxFlags flags = (lv->multi_select) ? TB_INDICATOR : 0; + TextboxFlags flags = 0; if (strcasecmp(label, "element-icon") == 0) { row->icon = icon_create(WIDGET(wid), "element-icon"); box_add((box *)wid, WIDGET(row->icon), FALSE); @@ -1052,11 +1051,6 @@ void listview_set_mouse_activated_cb(listview *lv, lv->mouse_activated_data = udata; } } -void listview_set_multi_select(listview *lv, gboolean enable) { - if (lv) { - lv->multi_select = enable; - } -} void listview_set_num_lines(listview *lv, unsigned int num_lines) { if (lv) { lv->menu_lines = num_lines; diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c index b8915e45..e4f28915 100644 --- a/source/widgets/textbox.c +++ b/source/widgets/textbox.c @@ -40,9 +40,6 @@ #include "theme.h" -/** The space reserved for the DOT when enabling multi-select. */ -#define DOT_OFFSET 15 - static void textbox_draw(widget *, cairo_t *); static void textbox_free(widget *); static int textbox_get_width(widget *); @@ -78,7 +75,6 @@ static void textbox_resize(widget *wid, short w, short h) { } static int textbox_get_desired_height(widget *wid, const int width) { textbox *tb = (textbox *)wid; - unsigned int offset = ((tb->flags & TB_INDICATOR) ? DOT_OFFSET : 0); if ((tb->flags & TB_AUTOHEIGHT) == 0) { return tb->widget.h; } @@ -88,8 +84,7 @@ static int textbox_get_desired_height(widget *wid, const int width) { int old_width = pango_layout_get_width(tb->layout); pango_layout_set_width( tb->layout, - PANGO_SCALE * - (width - widget_padding_get_padding_width(WIDGET(tb)) - offset)); + PANGO_SCALE * (width - widget_padding_get_padding_width(WIDGET(tb)))); int height = textbox_get_estimated_height(tb, pango_layout_get_line_count(tb->layout)); @@ -386,11 +381,10 @@ 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_font_width(tb) + - widget_padding_get_padding_width(WIDGET(tb)) + offset; + widget_padding_get_padding_width(WIDGET(tb)); } else { // set ellipsize if ((tb->flags & TB_EDITABLE) == TB_EDITABLE) { @@ -407,8 +401,7 @@ void textbox_moveresize(textbox *tb, int x, int y, int w, int h) { int tw = MAX(1, w); pango_layout_set_width( tb->layout, - PANGO_SCALE * - (tw - widget_padding_get_padding_width(WIDGET(tb)) - offset)); + PANGO_SCALE * (tw - widget_padding_get_padding_width(WIDGET(tb)))); int hd = textbox_get_height(tb); h = MAX(hd, h); } @@ -423,9 +416,8 @@ 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 - - widget_padding_get_padding_width(WIDGET(tb)) - offset)); + tb->layout, PANGO_SCALE * (tb->widget.w - + widget_padding_get_padding_width(WIDGET(tb)))); widget_queue_redraw(WIDGET(tb)); } @@ -453,7 +445,7 @@ static void textbox_draw(widget *wid, cairo_t *draw) { return; } textbox *tb = (textbox *)wid; - int dot_offset = ((tb->flags & TB_INDICATOR) ? DOT_OFFSET : 0); + int dot_offset = 0; if (tb->changed) { __textbox_update_pango_text(tb); @@ -536,11 +528,6 @@ static void textbox_draw(widget *wid, cairo_t *draw) { cursor_height); cairo_fill(draw); } - - if ((tb->flags & TB_INDICATOR) == TB_INDICATOR && (tb->tbft & (SELECTED))) { - cairo_arc(draw, DOT_OFFSET / 2.0, tb->widget.h / 2.0, 2.0, 0, 2.0 * M_PI); - cairo_fill(draw); - } } // cursor handling for edit mode @@ -902,9 +889,7 @@ void textbox_cleanup(void) { int textbox_get_width(widget *wid) { textbox *tb = (textbox *)wid; if (tb->flags & TB_AUTOWIDTH) { - unsigned int offset = (tb->flags & TB_INDICATOR) ? DOT_OFFSET : 0; - return textbox_get_font_width(tb) + widget_padding_get_padding_width(wid) + - offset; + return textbox_get_font_width(tb) + widget_padding_get_padding_width(wid); } return tb->widget.w; } @@ -966,10 +951,8 @@ int textbox_get_desired_width(widget *wid, G_GNUC_UNUSED const int height) { return 0; } textbox *tb = (textbox *)wid; - unsigned int offset = ((tb->flags & TB_INDICATOR) ? DOT_OFFSET : 0); if (wid->expand && tb->flags & TB_AUTOWIDTH) { - return textbox_get_font_width(tb) + widget_padding_get_padding_width(wid) + - offset; + return textbox_get_font_width(tb) + widget_padding_get_padding_width(wid); } RofiDistance w = rofi_theme_get_distance(WIDGET(tb), "width", 0); int wi = distance_get_pixel(w, ROFI_ORIENTATION_HORIZONTAL); @@ -983,7 +966,7 @@ int textbox_get_desired_width(widget *wid, G_GNUC_UNUSED const int height) { int width = textbox_get_font_width(tb); // Restore. pango_layout_set_width(tb->layout, old_width); - return width + padding + offset; + return width + padding; } void textbox_set_ellipsize(textbox *tb, PangoEllipsizeMode mode) {