1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-12-02 14:05:13 -05:00

[DMenu] Add -ellipsize-mode option.

This commit is contained in:
Dave Davenport 2022-11-19 21:03:22 +01:00
parent 66d782e0e7
commit 063195922f
8 changed files with 47 additions and 10 deletions

View file

@ -298,6 +298,15 @@ When multi-select is enabled, prefix this string when element is not selected.
.PP .PP
\fIdefault\fP: "☐ " \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 .SH PARSING ROW OPTIONS
.PP .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. 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.

View file

@ -192,6 +192,12 @@ When multi-select is enabled, prefix this string when element is not selected.
*default*: "☐ " *default*: "☐ "
`-ellipsize-mode` (start|middle|end)
Set ellipsize mode on the listview.
*default* "end"
## PARSING ROW OPTIONS ## 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. Extra options for individual rows can be also set. See the **rofi-script(5)** manpage for details; the syntax and supported features are identical.

View file

@ -29,6 +29,7 @@
#define ROFI_VIEW_H #define ROFI_VIEW_H
#include "mode.h" #include "mode.h"
#include <pango/pango.h>
#include <xcb/xcb.h> #include <xcb/xcb.h>
/** /**
* @defgroup View View * @defgroup View View
@ -338,9 +339,12 @@ void rofi_capture_screenshot(void);
void rofi_view_set_window_title(const char *title); 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. * 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 * @param new_x New XIM window x pos

View file

@ -29,6 +29,7 @@
#define ROFI_LISTVIEW_H #define ROFI_LISTVIEW_H
#include "widgets/textbox.h" #include "widgets/textbox.h"
#include <pango/pango.h>
/** /**
* @defgroup listview listview * @defgroup listview listview
@ -276,7 +277,7 @@ void listview_toggle_ellipsizing(listview *lv);
* Set ellipsize mode to start. * 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. * @param lv Handler to the listview object.

View file

@ -7,6 +7,6 @@ pluginsdir=@libdir@/rofi/
Name: rofi Name: rofi
Description: Header files for rofi plugins 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@ Version: @VERSION@
Cflags: -I${includedir}/ Cflags: -I${includedir}/

View file

@ -29,8 +29,8 @@
#define G_LOG_DOMAIN "Modes.DMenu" #define G_LOG_DOMAIN "Modes.DMenu"
#include "config.h" #include "config.h"
#include "modes/dmenu.h"
#include "helper.h" #include "helper.h"
#include "modes/dmenu.h"
#include "rofi-icon-fetcher.h" #include "rofi-icon-fetcher.h"
#include "rofi.h" #include "rofi.h"
#include "settings.h" #include "settings.h"
@ -299,7 +299,7 @@ static gpointer read_input_thread(gpointer userdata) {
i = 0; i = 0;
if (block) { if (block) {
double elapsed = g_timer_elapsed(tim, NULL); 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_timer_start(tim);
g_async_queue_push(pd->async_queue, block); g_async_queue_push(pd->async_queue, block);
block = NULL; block = NULL;
@ -957,7 +957,21 @@ int dmenu_mode_dialog(void) {
rofi_view_create(&dmenu_mode, input, menu_flags, dmenu_finalize); rofi_view_create(&dmenu_mode, input, menu_flags, dmenu_finalize);
if (find_arg("-keep-right") >= 0) { 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_selected_line(state, pd->selected_line);
rofi_view_set_active(state); rofi_view_set_active(state);
@ -1021,4 +1035,6 @@ void print_dmenu_options(void) {
"When multi-select is enabled prefix this string when element " "When multi-select is enabled prefix this string when element "
"is not selected.", "is not selected.",
NULL, is_term); NULL, is_term);
print_help_msg("-ellipsize-mode", "end",
"Set ellipsize mode(start | middle | end).", NULL, is_term);
} }

View file

@ -2499,8 +2499,9 @@ void rofi_view_clear_input(RofiViewState *state) {
} }
} }
void rofi_view_ellipsize_start(RofiViewState *state) { void rofi_view_ellipsize_listview(RofiViewState *state,
listview_set_ellipsize_start(state->list_view); PangoEllipsizeMode mode) {
listview_set_ellipsize(state->list_view, mode);
} }
void rofi_view_switch_mode(RofiViewState *state, Mode *mode) { void rofi_view_switch_mode(RofiViewState *state, Mode *mode) {

View file

@ -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) { if (lv) {
lv->emode = PANGO_ELLIPSIZE_START; lv->emode = mode;
for (unsigned int i = 0; i < lv->cur_elements; i++) { for (unsigned int i = 0; i < lv->cur_elements; i++) {
textbox_set_ellipsize(lv->boxes[i].textbox, lv->emode); textbox_set_ellipsize(lv->boxes[i].textbox, lv->emode);
} }