mirror of https://github.com/davatorium/rofi.git
Add -format option to dmenu.
This commit is contained in:
parent
4d3b9e414d
commit
9307a1668e
|
@ -512,6 +512,16 @@ The following options are further explained in the theming section:
|
||||||
Only return a selected item, do not allow custom entry.
|
Only return a selected item, do not allow custom entry.
|
||||||
This mode always returns an entry, or returns directly when no entries given.
|
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
|
### Message dialog
|
||||||
|
|
||||||
`-e` *message*
|
`-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
|
Or any combination: \-u 0,2\-3,9
|
||||||
.fi
|
.fi
|
||||||
.RE
|
.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
|
.SS Message dialog
|
||||||
.PP
|
.PP
|
||||||
\fB\fC\-e\fR \fImessage\fP
|
\fB\fC\-e\fR \fImessage\fP
|
||||||
|
|
|
@ -45,13 +45,13 @@ typedef const char * ( *get_display_value )( unsigned int selected_line, void *d
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
/** Entry is selected. */
|
/** Entry is selected. */
|
||||||
MENU_OK = 0x0010000,
|
MENU_OK = 0x00010000,
|
||||||
/** User canceled the operation. (e.g. pressed escape) */
|
/** User canceled the operation. (e.g. pressed escape) */
|
||||||
MENU_CANCEL = 0x0020000,
|
MENU_CANCEL = 0x00020000,
|
||||||
/** User requested a mode switch */
|
/** User requested a mode switch */
|
||||||
MENU_NEXT = 0x0040000,
|
MENU_NEXT = 0x00040000,
|
||||||
/** Custom (non-matched) input was entered. */
|
/** Custom (non-matched) input was entered. */
|
||||||
MENU_CUSTOM_INPUT = 0x0080000,
|
MENU_CUSTOM_INPUT = 0x00080000,
|
||||||
/** User wanted to delete entry from history. */
|
/** User wanted to delete entry from history. */
|
||||||
MENU_ENTRY_DELETE = 0x00100000,
|
MENU_ENTRY_DELETE = 0x00100000,
|
||||||
/** User wants to jump to another switcher. */
|
/** 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_SKIP_PAGER ), \
|
||||||
X ( _NET_WM_STATE_ABOVE ), \
|
X ( _NET_WM_STATE_ABOVE ), \
|
||||||
X ( _NET_WM_STATE_DEMANDS_ATTENTION ), \
|
X ( _NET_WM_STATE_DEMANDS_ATTENTION ), \
|
||||||
|
X ( _NET_WM_STATE_WITHDRAWN ), \
|
||||||
X ( _NET_WM_DESKTOP ), \
|
X ( _NET_WM_DESKTOP ), \
|
||||||
X ( CLIPBOARD ), \
|
X ( CLIPBOARD ), \
|
||||||
X ( UTF8_STRING ), \
|
X ( UTF8_STRING ), \
|
||||||
|
|
|
@ -127,6 +127,28 @@ static const char *get_display_data ( unsigned int index, void *data, G_GNUC_UNU
|
||||||
return retv[index];
|
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 )
|
int dmenu_switcher_dialog ( char **input )
|
||||||
{
|
{
|
||||||
char *dmenu_prompt = "dmenu ";
|
char *dmenu_prompt = "dmenu ";
|
||||||
|
@ -137,10 +159,14 @@ int dmenu_switcher_dialog ( char **input )
|
||||||
int restart = FALSE;
|
int restart = FALSE;
|
||||||
|
|
||||||
int number_mode = FALSE;
|
int number_mode = FALSE;
|
||||||
|
char *format = "s";
|
||||||
// Check if the user requested number mode.
|
// Check if the user requested number mode.
|
||||||
if ( find_arg ( "-i" ) >= 0 ) {
|
if ( find_arg ( "-i" ) >= 0 ) {
|
||||||
number_mode = TRUE;
|
number_mode = TRUE;
|
||||||
|
format = "i";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
find_arg_str ( "-format", &format );
|
||||||
// Check prompt
|
// Check prompt
|
||||||
find_arg_str ( "-p", &dmenu_prompt );
|
find_arg_str ( "-p", &dmenu_prompt );
|
||||||
find_arg_int ( "-l", &selected_line );
|
find_arg_int ( "-l", &selected_line );
|
||||||
|
@ -176,18 +202,11 @@ int dmenu_switcher_dialog ( char **input )
|
||||||
*/
|
*/
|
||||||
restart = TRUE;
|
restart = TRUE;
|
||||||
if ( ( mretv & ( MENU_OK | MENU_QUICK_SWITCH ) ) && list[selected_line] != NULL ) {
|
if ( ( mretv & ( MENU_OK | MENU_QUICK_SWITCH ) ) && list[selected_line] != NULL ) {
|
||||||
if ( number_mode ) {
|
dmenu_format_line ( format, list[selected_line], selected_line );
|
||||||
fprintf ( stdout, "%d", selected_line );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fputs ( list[selected_line], stdout );
|
|
||||||
}
|
|
||||||
retv = TRUE;
|
retv = TRUE;
|
||||||
if ( ( mretv & MENU_QUICK_SWITCH ) ) {
|
if ( ( mretv & MENU_QUICK_SWITCH ) ) {
|
||||||
retv = 10 + ( mretv & MENU_LOWER_MASK );
|
retv = 10 + ( mretv & MENU_LOWER_MASK );
|
||||||
}
|
}
|
||||||
fputc ( '\n', stdout );
|
|
||||||
fflush ( stdout );
|
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
selected_line = next_pos - 1;
|
selected_line = next_pos - 1;
|
||||||
|
@ -196,14 +215,12 @@ int dmenu_switcher_dialog ( char **input )
|
||||||
// We normally do not want to restart the loop.
|
// We normally do not want to restart the loop.
|
||||||
restart = FALSE;
|
restart = FALSE;
|
||||||
if ( ( mretv & ( MENU_OK | MENU_CUSTOM_INPUT ) ) && list[selected_line] != NULL ) {
|
if ( ( mretv & ( MENU_OK | MENU_CUSTOM_INPUT ) ) && list[selected_line] != NULL ) {
|
||||||
if ( number_mode ) {
|
if ( ( mretv & MENU_CUSTOM_INPUT ) ) {
|
||||||
fprintf ( stdout, "%d", selected_line );
|
dmenu_format_line ( format, *input, -1 );
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
fputs ( list[selected_line], stdout );
|
dmenu_format_line ( format, list[selected_line], selected_line );
|
||||||
}
|
}
|
||||||
fputc ( '\n', stdout );
|
|
||||||
fflush ( stdout );
|
|
||||||
if ( ( mretv & MENU_SHIFT ) ) {
|
if ( ( mretv & MENU_SHIFT ) ) {
|
||||||
restart = TRUE;
|
restart = TRUE;
|
||||||
// Move to next line.
|
// Move to next line.
|
||||||
|
@ -215,14 +232,12 @@ int dmenu_switcher_dialog ( char **input )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( ( mretv & MENU_QUICK_SWITCH ) ) {
|
else if ( ( mretv & MENU_QUICK_SWITCH ) ) {
|
||||||
if ( number_mode ) {
|
if ( ( mretv & MENU_CUSTOM_INPUT ) ) {
|
||||||
fprintf ( stdout, "%d", selected_line );
|
dmenu_format_line ( format, *input, -1 );
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
fputs ( list[selected_line], stdout );
|
dmenu_format_line ( format, list[selected_line], selected_line );
|
||||||
}
|
}
|
||||||
fputc ( '\n', stdout );
|
|
||||||
fflush ( stdout );
|
|
||||||
|
|
||||||
restart = FALSE;
|
restart = FALSE;
|
||||||
retv = 10 + ( mretv & MENU_LOWER_MASK );
|
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] ) ) {
|
if ( client_has_state ( c, netatoms[_NET_WM_STATE_DEMANDS_ATTENTION] ) ) {
|
||||||
c->demands = TRUE;
|
c->demands = TRUE;
|
||||||
}
|
}
|
||||||
|
if ( client_has_state ( c, netatoms[_NET_WM_STATE_WITHDRAWN] ) ) {
|
||||||
|
c->demands = TRUE;
|
||||||
|
}
|
||||||
if ( ( c->hint_flags & XUrgencyHint ) == XUrgencyHint ) {
|
if ( ( c->hint_flags & XUrgencyHint ) == XUrgencyHint ) {
|
||||||
c->demands = TRUE;
|
c->demands = TRUE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue