mirror of
https://github.com/davatorium/rofi.git
synced 2025-03-03 16:05:20 -05:00
Add -format option to dmenu.
This commit is contained in:
parent
4d3b9e414d
commit
9307a1668e
6 changed files with 74 additions and 24 deletions
|
@ -512,6 +512,16 @@ The following options are further explained in the theming section:
|
|||
Only return a selected item, do not allow custom entry.
|
||||
This mode always returns an entry, or returns directly when no entries given.
|
||||
|
||||
`-format` *format*
|
||||
|
||||
Allows the output of dmenu to be customized:
|
||||
|
||||
* 's' selected string.
|
||||
* 'i' index.
|
||||
* 'e' selected string escaped.
|
||||
|
||||
Default: 's'
|
||||
|
||||
### Message dialog
|
||||
|
||||
`-e` *message*
|
||||
|
|
21
doc/rofi.1
21
doc/rofi.1
|
@ -663,6 +663,27 @@ or a set of rows: \-u 0,2
|
|||
Or any combination: \-u 0,2\-3,9
|
||||
.fi
|
||||
.RE
|
||||
.PP
|
||||
\fB\fC\-only\-match\fR
|
||||
.PP
|
||||
.RS
|
||||
.nf
|
||||
Only return a selected item, do not allow custom entry.
|
||||
This mode always returns an entry, or returns directly when no entries given.
|
||||
.fi
|
||||
.RE
|
||||
.PP
|
||||
\fB\fC\-format\fR \fIformat\fP
|
||||
.PP
|
||||
.RS
|
||||
.nf
|
||||
Allows the output of dmenu to be customized:
|
||||
* 's' selected string.
|
||||
* 'i' index.
|
||||
* 'e' selected string escaped.
|
||||
Default: 's'
|
||||
.fi
|
||||
.RE
|
||||
.SS Message dialog
|
||||
.PP
|
||||
\fB\fC\-e\fR \fImessage\fP
|
||||
|
|
|
@ -45,13 +45,13 @@ typedef const char * ( *get_display_value )( unsigned int selected_line, void *d
|
|||
typedef enum
|
||||
{
|
||||
/** Entry is selected. */
|
||||
MENU_OK = 0x0010000,
|
||||
MENU_OK = 0x00010000,
|
||||
/** User canceled the operation. (e.g. pressed escape) */
|
||||
MENU_CANCEL = 0x0020000,
|
||||
MENU_CANCEL = 0x00020000,
|
||||
/** User requested a mode switch */
|
||||
MENU_NEXT = 0x0040000,
|
||||
MENU_NEXT = 0x00040000,
|
||||
/** Custom (non-matched) input was entered. */
|
||||
MENU_CUSTOM_INPUT = 0x0080000,
|
||||
MENU_CUSTOM_INPUT = 0x00080000,
|
||||
/** User wanted to delete entry from history. */
|
||||
MENU_ENTRY_DELETE = 0x00100000,
|
||||
/** User wants to jump to another switcher. */
|
||||
|
|
|
@ -41,6 +41,7 @@ int window_get_cardinal_prop ( Display *display, Window w, Atom atom, unsigned l
|
|||
X ( _NET_WM_STATE_SKIP_PAGER ), \
|
||||
X ( _NET_WM_STATE_ABOVE ), \
|
||||
X ( _NET_WM_STATE_DEMANDS_ATTENTION ), \
|
||||
X ( _NET_WM_STATE_WITHDRAWN ), \
|
||||
X ( _NET_WM_DESKTOP ), \
|
||||
X ( CLIPBOARD ), \
|
||||
X ( UTF8_STRING ), \
|
||||
|
|
|
@ -127,6 +127,28 @@ static const char *get_display_data ( unsigned int index, void *data, G_GNUC_UNU
|
|||
return retv[index];
|
||||
}
|
||||
|
||||
static void dmenu_format_line ( const char *format, const char *string, int selected_line )
|
||||
{
|
||||
for ( int i = 0; format && format[i]; i++ ) {
|
||||
if ( format[i] == 'i' ) {
|
||||
fprintf ( stdout, "%d", selected_line );
|
||||
}
|
||||
else if ( format[i] == 's' ) {
|
||||
fputs ( string, stdout );
|
||||
}
|
||||
else if ( format[i] == 'e' ) {
|
||||
char *quote = g_shell_quote ( string );
|
||||
fputs ( quote, stdout );
|
||||
g_free ( quote );
|
||||
}
|
||||
else {
|
||||
fputc ( format[i], stdout );
|
||||
}
|
||||
}
|
||||
fputc ( '\n', stdout );
|
||||
fflush ( stdout );
|
||||
}
|
||||
|
||||
int dmenu_switcher_dialog ( char **input )
|
||||
{
|
||||
char *dmenu_prompt = "dmenu ";
|
||||
|
@ -137,10 +159,14 @@ int dmenu_switcher_dialog ( char **input )
|
|||
int restart = FALSE;
|
||||
|
||||
int number_mode = FALSE;
|
||||
char *format = "s";
|
||||
// Check if the user requested number mode.
|
||||
if ( find_arg ( "-i" ) >= 0 ) {
|
||||
number_mode = TRUE;
|
||||
format = "i";
|
||||
}
|
||||
|
||||
find_arg_str ( "-format", &format );
|
||||
// Check prompt
|
||||
find_arg_str ( "-p", &dmenu_prompt );
|
||||
find_arg_int ( "-l", &selected_line );
|
||||
|
@ -176,18 +202,11 @@ int dmenu_switcher_dialog ( char **input )
|
|||
*/
|
||||
restart = TRUE;
|
||||
if ( ( mretv & ( MENU_OK | MENU_QUICK_SWITCH ) ) && list[selected_line] != NULL ) {
|
||||
if ( number_mode ) {
|
||||
fprintf ( stdout, "%d", selected_line );
|
||||
}
|
||||
else {
|
||||
fputs ( list[selected_line], stdout );
|
||||
}
|
||||
dmenu_format_line ( format, list[selected_line], selected_line );
|
||||
retv = TRUE;
|
||||
if ( ( mretv & MENU_QUICK_SWITCH ) ) {
|
||||
retv = 10 + ( mretv & MENU_LOWER_MASK );
|
||||
}
|
||||
fputc ( '\n', stdout );
|
||||
fflush ( stdout );
|
||||
return retv;
|
||||
}
|
||||
selected_line = next_pos - 1;
|
||||
|
@ -196,14 +215,12 @@ int dmenu_switcher_dialog ( char **input )
|
|||
// We normally do not want to restart the loop.
|
||||
restart = FALSE;
|
||||
if ( ( mretv & ( MENU_OK | MENU_CUSTOM_INPUT ) ) && list[selected_line] != NULL ) {
|
||||
if ( number_mode ) {
|
||||
fprintf ( stdout, "%d", selected_line );
|
||||
if ( ( mretv & MENU_CUSTOM_INPUT ) ) {
|
||||
dmenu_format_line ( format, *input, -1 );
|
||||
}
|
||||
else {
|
||||
fputs ( list[selected_line], stdout );
|
||||
else{
|
||||
dmenu_format_line ( format, list[selected_line], selected_line );
|
||||
}
|
||||
fputc ( '\n', stdout );
|
||||
fflush ( stdout );
|
||||
if ( ( mretv & MENU_SHIFT ) ) {
|
||||
restart = TRUE;
|
||||
// Move to next line.
|
||||
|
@ -215,14 +232,12 @@ int dmenu_switcher_dialog ( char **input )
|
|||
}
|
||||
}
|
||||
else if ( ( mretv & MENU_QUICK_SWITCH ) ) {
|
||||
if ( number_mode ) {
|
||||
fprintf ( stdout, "%d", selected_line );
|
||||
if ( ( mretv & MENU_CUSTOM_INPUT ) ) {
|
||||
dmenu_format_line ( format, *input, -1 );
|
||||
}
|
||||
else {
|
||||
fputs ( list[selected_line], stdout );
|
||||
else{
|
||||
dmenu_format_line ( format, list[selected_line], selected_line );
|
||||
}
|
||||
fputc ( '\n', stdout );
|
||||
fflush ( stdout );
|
||||
|
||||
restart = FALSE;
|
||||
retv = 10 + ( mretv & MENU_LOWER_MASK );
|
||||
|
|
|
@ -408,6 +408,9 @@ static char ** window_mode_get_data ( unsigned int *length, Switcher *sw )
|
|||
if ( client_has_state ( c, netatoms[_NET_WM_STATE_DEMANDS_ATTENTION] ) ) {
|
||||
c->demands = TRUE;
|
||||
}
|
||||
if ( client_has_state ( c, netatoms[_NET_WM_STATE_WITHDRAWN] ) ) {
|
||||
c->demands = TRUE;
|
||||
}
|
||||
if ( ( c->hint_flags & XUrgencyHint ) == XUrgencyHint ) {
|
||||
c->demands = TRUE;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue