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:
parent
7bd77684db
commit
be6fe8ac61
9 changed files with 74 additions and 53 deletions
|
@ -280,6 +280,24 @@ The column separator. This is a regex.
|
||||||
.PP
|
.PP
|
||||||
\fIdefault\fP: '\\t'
|
\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
|
.SH RETURN VALUE
|
||||||
.RS
|
.RS
|
||||||
.IP \(bu 2
|
.IP \(bu 2
|
||||||
|
|
|
@ -180,6 +180,17 @@ The column separator. This is a regex.
|
||||||
|
|
||||||
*default*: '\t'
|
*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
|
## RETURN VALUE
|
||||||
|
|
||||||
|
|
|
@ -54,8 +54,6 @@ typedef enum {
|
||||||
MENU_NORMAL_WINDOW = 2,
|
MENU_NORMAL_WINDOW = 2,
|
||||||
/** ERROR dialog */
|
/** ERROR dialog */
|
||||||
MENU_ERROR_DIALOG = 4,
|
MENU_ERROR_DIALOG = 4,
|
||||||
/** INDICATOR */
|
|
||||||
MENU_INDICATOR = 8,
|
|
||||||
} MenuFlags;
|
} MenuFlags;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -230,13 +230,6 @@ void listview_set_scroll_type(listview *lv, ScrollType type);
|
||||||
void listview_set_mouse_activated_cb(listview *lv,
|
void listview_set_mouse_activated_cb(listview *lv,
|
||||||
listview_mouse_activated_cb cb,
|
listview_mouse_activated_cb cb,
|
||||||
void *udata);
|
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 lv Handler to the listview object.
|
||||||
* @param num_lines the maximum number of lines to display.
|
* @param num_lines the maximum number of lines to display.
|
||||||
|
|
|
@ -93,7 +93,6 @@ typedef enum {
|
||||||
TB_MARKUP = 1 << 20,
|
TB_MARKUP = 1 << 20,
|
||||||
TB_WRAP = 1 << 21,
|
TB_WRAP = 1 << 21,
|
||||||
TB_PASSWORD = 1 << 22,
|
TB_PASSWORD = 1 << 22,
|
||||||
TB_INDICATOR = 1 << 23,
|
|
||||||
} TextboxFlags;
|
} TextboxFlags;
|
||||||
/**
|
/**
|
||||||
* Flags indicating current state of the textbox.
|
* Flags indicating current state of the textbox.
|
||||||
|
|
|
@ -108,6 +108,9 @@ typedef struct {
|
||||||
int pipefd2[2];
|
int pipefd2[2];
|
||||||
guint wake_source;
|
guint wake_source;
|
||||||
gboolean loading;
|
gboolean loading;
|
||||||
|
|
||||||
|
char *ballot_selected;
|
||||||
|
char *ballot_unselected;
|
||||||
} DmenuModePrivateData;
|
} DmenuModePrivateData;
|
||||||
|
|
||||||
#define BLOCK_LINES_SIZE 2048
|
#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,
|
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->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);
|
return g_strdup(input);
|
||||||
}
|
}
|
||||||
char *retv = NULL;
|
char *retv = NULL;
|
||||||
|
@ -350,6 +361,12 @@ static gchar *dmenu_format_output_string(const DmenuModePrivateData *pd,
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
GString *str_retv = g_string_new("");
|
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++) {
|
for (uint32_t i = 0; pd->columns && pd->columns[i]; i++) {
|
||||||
unsigned int index =
|
unsigned int index =
|
||||||
(unsigned int)g_ascii_strtoull(pd->columns[i], NULL, 10);
|
(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;
|
*state |= MARKUP;
|
||||||
}
|
}
|
||||||
char *my_retv =
|
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;
|
return my_retv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -856,8 +874,11 @@ int dmenu_mode_dialog(void) {
|
||||||
|
|
||||||
pd->only_selected = FALSE;
|
pd->only_selected = FALSE;
|
||||||
pd->multi_select = 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) {
|
if (find_arg("-multi-select") >= 0) {
|
||||||
menu_flags = MENU_INDICATOR;
|
|
||||||
pd->multi_select = TRUE;
|
pd->multi_select = TRUE;
|
||||||
}
|
}
|
||||||
if (find_arg("-markup-rows") >= 0) {
|
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.",
|
print_help_msg("-w", "windowid", "Position over window with X11 windowid.",
|
||||||
NULL, is_term);
|
NULL, is_term);
|
||||||
print_help_msg("-keep-right", "", "Set ellipsize to end.", 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",
|
print_help_msg("-display-columns", "", "Only show the selected columns", NULL,
|
||||||
NULL, is_term);
|
is_term);
|
||||||
print_help_msg("--display-column-separator", "\t",
|
print_help_msg("-display-column-separator", "\t",
|
||||||
"Separator to use to split columns (regex)", NULL, is_term);
|
"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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1974,10 +1974,6 @@ static void rofi_view_add_widget(RofiViewState *state, widget *parent_widget,
|
||||||
listview_set_selection_changed_callback(
|
listview_set_selection_changed_callback(
|
||||||
state->list_view, selection_changed_callback, (void *)state);
|
state->list_view, selection_changed_callback, (void *)state);
|
||||||
box_add((box *)parent_widget, WIDGET(state->list_view), TRUE);
|
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_scroll_type(state->list_view, config.scroll_method);
|
||||||
listview_set_mouse_activated_cb(
|
listview_set_mouse_activated_cb(
|
||||||
state->list_view, rofi_view_listview_mouse_activated_cb, state);
|
state->list_view, rofi_view_listview_mouse_activated_cb, state);
|
||||||
|
|
|
@ -102,7 +102,6 @@ struct _listview {
|
||||||
gboolean filtered;
|
gboolean filtered;
|
||||||
|
|
||||||
gboolean cycle;
|
gboolean cycle;
|
||||||
gboolean multi_select;
|
|
||||||
|
|
||||||
ScrollType scroll_type;
|
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,
|
static void listview_add_widget(listview *lv, _listview_row *row, widget *wid,
|
||||||
const char *label) {
|
const char *label) {
|
||||||
TextboxFlags flags = (lv->multi_select) ? TB_INDICATOR : 0;
|
TextboxFlags flags = 0;
|
||||||
if (strcasecmp(label, "element-icon") == 0) {
|
if (strcasecmp(label, "element-icon") == 0) {
|
||||||
row->icon = icon_create(WIDGET(wid), "element-icon");
|
row->icon = icon_create(WIDGET(wid), "element-icon");
|
||||||
box_add((box *)wid, WIDGET(row->icon), FALSE);
|
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;
|
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) {
|
void listview_set_num_lines(listview *lv, unsigned int num_lines) {
|
||||||
if (lv) {
|
if (lv) {
|
||||||
lv->menu_lines = num_lines;
|
lv->menu_lines = num_lines;
|
||||||
|
|
|
@ -40,9 +40,6 @@
|
||||||
|
|
||||||
#include "theme.h"
|
#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_draw(widget *, cairo_t *);
|
||||||
static void textbox_free(widget *);
|
static void textbox_free(widget *);
|
||||||
static int textbox_get_width(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) {
|
static int textbox_get_desired_height(widget *wid, const int width) {
|
||||||
textbox *tb = (textbox *)wid;
|
textbox *tb = (textbox *)wid;
|
||||||
unsigned int offset = ((tb->flags & TB_INDICATOR) ? DOT_OFFSET : 0);
|
|
||||||
if ((tb->flags & TB_AUTOHEIGHT) == 0) {
|
if ((tb->flags & TB_AUTOHEIGHT) == 0) {
|
||||||
return tb->widget.h;
|
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);
|
int old_width = pango_layout_get_width(tb->layout);
|
||||||
pango_layout_set_width(
|
pango_layout_set_width(
|
||||||
tb->layout,
|
tb->layout,
|
||||||
PANGO_SCALE *
|
PANGO_SCALE * (width - widget_padding_get_padding_width(WIDGET(tb))));
|
||||||
(width - widget_padding_get_padding_width(WIDGET(tb)) - offset));
|
|
||||||
|
|
||||||
int height =
|
int height =
|
||||||
textbox_get_estimated_height(tb, pango_layout_get_line_count(tb->layout));
|
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
|
// within the parent handled auto width/height modes
|
||||||
void textbox_moveresize(textbox *tb, int x, int y, int w, int h) {
|
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) {
|
if (tb->flags & TB_AUTOWIDTH) {
|
||||||
pango_layout_set_width(tb->layout, -1);
|
pango_layout_set_width(tb->layout, -1);
|
||||||
w = textbox_get_font_width(tb) +
|
w = textbox_get_font_width(tb) +
|
||||||
widget_padding_get_padding_width(WIDGET(tb)) + offset;
|
widget_padding_get_padding_width(WIDGET(tb));
|
||||||
} else {
|
} else {
|
||||||
// set ellipsize
|
// set ellipsize
|
||||||
if ((tb->flags & TB_EDITABLE) == TB_EDITABLE) {
|
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);
|
int tw = MAX(1, w);
|
||||||
pango_layout_set_width(
|
pango_layout_set_width(
|
||||||
tb->layout,
|
tb->layout,
|
||||||
PANGO_SCALE *
|
PANGO_SCALE * (tw - widget_padding_get_padding_width(WIDGET(tb))));
|
||||||
(tw - widget_padding_get_padding_width(WIDGET(tb)) - offset));
|
|
||||||
int hd = textbox_get_height(tb);
|
int hd = textbox_get_height(tb);
|
||||||
h = MAX(hd, h);
|
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
|
// We always want to update this
|
||||||
pango_layout_set_width(
|
pango_layout_set_width(
|
||||||
tb->layout,
|
tb->layout, PANGO_SCALE * (tb->widget.w -
|
||||||
PANGO_SCALE * (tb->widget.w -
|
widget_padding_get_padding_width(WIDGET(tb))));
|
||||||
widget_padding_get_padding_width(WIDGET(tb)) - offset));
|
|
||||||
widget_queue_redraw(WIDGET(tb));
|
widget_queue_redraw(WIDGET(tb));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -453,7 +445,7 @@ static void textbox_draw(widget *wid, cairo_t *draw) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
textbox *tb = (textbox *)wid;
|
textbox *tb = (textbox *)wid;
|
||||||
int dot_offset = ((tb->flags & TB_INDICATOR) ? DOT_OFFSET : 0);
|
int dot_offset = 0;
|
||||||
|
|
||||||
if (tb->changed) {
|
if (tb->changed) {
|
||||||
__textbox_update_pango_text(tb);
|
__textbox_update_pango_text(tb);
|
||||||
|
@ -536,11 +528,6 @@ static void textbox_draw(widget *wid, cairo_t *draw) {
|
||||||
cursor_height);
|
cursor_height);
|
||||||
cairo_fill(draw);
|
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
|
// cursor handling for edit mode
|
||||||
|
@ -902,9 +889,7 @@ void textbox_cleanup(void) {
|
||||||
int textbox_get_width(widget *wid) {
|
int textbox_get_width(widget *wid) {
|
||||||
textbox *tb = (textbox *)wid;
|
textbox *tb = (textbox *)wid;
|
||||||
if (tb->flags & TB_AUTOWIDTH) {
|
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);
|
||||||
return textbox_get_font_width(tb) + widget_padding_get_padding_width(wid) +
|
|
||||||
offset;
|
|
||||||
}
|
}
|
||||||
return tb->widget.w;
|
return tb->widget.w;
|
||||||
}
|
}
|
||||||
|
@ -966,10 +951,8 @@ int textbox_get_desired_width(widget *wid, G_GNUC_UNUSED const int height) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
textbox *tb = (textbox *)wid;
|
textbox *tb = (textbox *)wid;
|
||||||
unsigned int offset = ((tb->flags & TB_INDICATOR) ? DOT_OFFSET : 0);
|
|
||||||
if (wid->expand && tb->flags & TB_AUTOWIDTH) {
|
if (wid->expand && tb->flags & TB_AUTOWIDTH) {
|
||||||
return textbox_get_font_width(tb) + widget_padding_get_padding_width(wid) +
|
return textbox_get_font_width(tb) + widget_padding_get_padding_width(wid);
|
||||||
offset;
|
|
||||||
}
|
}
|
||||||
RofiDistance w = rofi_theme_get_distance(WIDGET(tb), "width", 0);
|
RofiDistance w = rofi_theme_get_distance(WIDGET(tb), "width", 0);
|
||||||
int wi = distance_get_pixel(w, ROFI_ORIENTATION_HORIZONTAL);
|
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);
|
int width = textbox_get_font_width(tb);
|
||||||
// Restore.
|
// Restore.
|
||||||
pango_layout_set_width(tb->layout, old_width);
|
pango_layout_set_width(tb->layout, old_width);
|
||||||
return width + padding + offset;
|
return width + padding;
|
||||||
}
|
}
|
||||||
|
|
||||||
void textbox_set_ellipsize(textbox *tb, PangoEllipsizeMode mode) {
|
void textbox_set_ellipsize(textbox *tb, PangoEllipsizeMode mode) {
|
||||||
|
|
Loading…
Reference in a new issue