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

Add ranges for urgent active in dmenu mode.

This commit is contained in:
QC 2015-04-05 11:53:08 +02:00
parent 808eee4b85
commit d6ced176d4
5 changed files with 94 additions and 14 deletions

View file

@ -3,8 +3,11 @@
- Number mode for dmenu. allows user to get index back instead of content. - Number mode for dmenu. allows user to get index back instead of content.
- Combi mode. Combine multiple views into one. - Combi mode. Combine multiple views into one.
- Highlight current window. - Highlight current window.
- Highlight urgent and active row in window view.
- DMenu allow rows to be highlighted.
Bug fixes: Bug fixes:
- On a single item in list disable auto-select. - On a single item in list disable auto-select.
- Fix cursor position (#140)
Improvements: Improvements:
- Add Ctrl(Shift)Tab to switch modi's. - Add Ctrl(Shift)Tab to switch modi's.
- Auto size number of columns based on available columns. - Auto size number of columns based on available columns.

View file

@ -400,10 +400,18 @@ daemon listening to specific key-combinations.
`-a` *X* `-a` *X*
Active row, mark row X as active. (starting at 0) Active row, mark row X as active. (starting at 0)
You can specify single element: -a 3
A range: -a 3-8
or a set of rows: -a 0,2
Or any combination: -a 0,2-3,9
`-u` *X* `-u` *X*
Urgent row, mark row X as urgent. (starting at 0) Urgent row, mark row X as urgent. (starting at 0)
You can specify single element: -u 3
A range: -u 3-8
or a set of rows: -u 0,2
Or any combination: -u 0,2-3,9
### Message dialog ### Message dialog

View file

@ -503,6 +503,10 @@ Number mode, return the index of the selected row. (starting at 0)
.RS .RS
.nf .nf
Active row, mark row X as active. (starting at 0) Active row, mark row X as active. (starting at 0)
You can specify single element: \-a 3
A range: \-a 3\-8
or a set of rows: \-a 0,2
Or any combination: \-a 0,2\-3,9
.fi .fi
.RE .RE
.PP .PP
@ -511,6 +515,10 @@ Active row, mark row X as active. (starting at 0)
.RS .RS
.nf .nf
Urgent row, mark row X as urgent. (starting at 0) Urgent row, mark row X as urgent. (starting at 0)
You can specify single element: \-u 3
A range: \-u 3\-8
or a set of rows: \-u 0,2
Or any combination: \-u 0,2\-3,9
.fi .fi
.RE .RE
.SS Message dialog .SS Message dialog

View file

@ -64,18 +64,65 @@ static char **get_dmenu ( int *length )
return retv; return retv;
} }
struct range_pair
{
unsigned int start;
unsigned int stop;
};
static unsigned int row_urgent = 0xFFFFFFFF; struct range_pair * urgent_list = NULL;
static unsigned int row_active = 0xFFFFFFFF; unsigned int num_urgent_list = 0;
struct range_pair * active_list = NULL;
unsigned int num_active_list = 0;
static void parse_pair ( char *input, struct range_pair *item )
{
int index = 0;
for ( char *token = strsep ( &input, "-" );
token != NULL;
token = strsep ( &input, "-" ) ) {
if ( index == 0 ) {
item->start = item->stop = (unsigned int) strtoul ( token, NULL, 10 );
index++;
}
else {
if ( token[0] == '\0' ) {
item->stop = 0xFFFFFFFF;
}
else{
item->stop = (unsigned int) strtoul ( token, NULL, 10 );
}
}
}
}
static void parse_ranges ( char *input, struct range_pair **list, unsigned int *length )
{
char *endp;
for ( char *token = strtok_r ( input, ",", &endp );
token != NULL;
token = strtok_r ( NULL, ",", &endp ) ) {
// Make space.
*list = g_realloc ( ( *list ), ( ( *length ) + 1 ) * sizeof ( struct range_pair ) );
// Parse a single pair.
parse_pair ( token, &( ( *list )[*length] ) );
( *length )++;
}
}
static const char *get_display_data ( unsigned int index, void *data, G_GNUC_UNUSED int *state ) static const char *get_display_data ( unsigned int index, void *data, G_GNUC_UNUSED int *state )
{ {
char **retv = (char * *) data; char **retv = (char * *) data;
if ( index == row_urgent ) { for ( unsigned int i = 0; i < num_active_list; i++ ) {
*state |= URGENT; if ( index >= active_list[i].start && index <= active_list[i].stop ) {
*state |= ACTIVE;
}
} }
if ( index == row_active ) { for ( unsigned int i = 0; i < num_urgent_list; i++ ) {
*state |= ACTIVE; if ( index >= urgent_list[i].start && index <= urgent_list[i].stop ) {
*state |= URGENT;
}
} }
return retv[index]; return retv[index];
} }
@ -97,8 +144,18 @@ int dmenu_switcher_dialog ( char **input )
// 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 );
find_arg_uint ( "-u", &row_urgent ); // Urgent.
find_arg_uint ( "-a", &row_active ); char *str = NULL;
find_arg_str ( "-u", &str );
if ( str != NULL ) {
parse_ranges ( str, &urgent_list, &num_urgent_list );
}
// Active
str = NULL;
find_arg_str ( "-a", &str );
if ( str != NULL ) {
parse_ranges ( str, &active_list, &num_active_list );
}
do { do {
int mretv = menu ( list, length, input, dmenu_prompt, int mretv = menu ( list, length, input, dmenu_prompt,
@ -138,6 +195,8 @@ int dmenu_switcher_dialog ( char **input )
} while ( restart ); } while ( restart );
g_strfreev ( list ); g_strfreev ( list );
g_free ( urgent_list );
g_free ( active_list );
return retv; return retv;
} }

View file

@ -147,18 +147,20 @@ void textbox_font ( textbox *tb, TextBoxFontType tbft )
} }
if ( ( tbft & FMOD_MASK ) ) { if ( ( tbft & FMOD_MASK ) ) {
if ( ( tbft & ACTIVE ) ) { if ( ( tbft & ACTIVE ) ) {
if(tbft&HIGHLIGHT) { if ( tbft & HIGHLIGHT ) {
tb->color_fg = color_hlfg; tb->color_fg = color_hlfg;
tb->color_bg = color_fg_active; tb->color_bg = color_fg_active;
}else { }
else {
tb->color_fg = color_fg_active; tb->color_fg = color_fg_active;
} }
} }
else if ( ( tbft & URGENT ) ) { else if ( ( tbft & URGENT ) ) {
if(tbft&HIGHLIGHT) { if ( tbft & HIGHLIGHT ) {
tb->color_fg = color_hlfg; tb->color_fg = color_hlfg;
tb->color_bg = color_fg_urgent; tb->color_bg = color_fg_urgent;
}else { }
else {
tb->color_fg = color_fg_urgent; tb->color_fg = color_fg_urgent;
} }
} }
@ -318,8 +320,8 @@ void textbox_draw ( textbox *tb )
// draw the cursor // draw the cursor
if ( tb->flags & TB_EDITABLE ) { if ( tb->flags & TB_EDITABLE ) {
XftDrawRect ( draw, &tb->color_fg, XftDrawRect ( draw, &tb->color_fg,
x / PANGO_SCALE + cursor_x, y/PANGO_SCALE, // Align with font x / PANGO_SCALE + cursor_x, y / PANGO_SCALE, // Align with font
cursor_width, font_height ); cursor_width, font_height );
} }
// flip canvas to window // flip canvas to window