1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

[Textbox] Remove the dot indicator.

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 ☑.
This commit is contained in:
Dave Davenport 2022-07-23 20:21:00 +02:00
parent 7bd77684db
commit be6fe8ac61
9 changed files with 74 additions and 53 deletions

View file

@ -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

View file

@ -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

View file

@ -54,8 +54,6 @@ typedef enum {
MENU_NORMAL_WINDOW = 2,
/** ERROR dialog */
MENU_ERROR_DIALOG = 4,
/** INDICATOR */
MENU_INDICATOR = 8,
} MenuFlags;
/**

View file

@ -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.

View file

@ -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.

View file

@ -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);
}

View file

@ -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);

View file

@ -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;

View file

@ -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) {