1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2025-09-18 22:58:53 -04:00

Fonts with a * prepended are considered active and slanted.

* Fix bug in window_get_prop call.
 * Use right type (Window instead of unsigned long)
 * Make current active window active
This commit is contained in:
QC 2014-05-25 11:04:45 +02:00
parent 241e4516c0
commit 3a14ec9746

View file

@ -87,6 +87,8 @@ char *i3_socket_path = NULL;
xdgHandle xdg_handle; xdgHandle xdg_handle;
const char *cache_dir = NULL; const char *cache_dir = NULL;
char *active_font = NULL;
/** /**
* Shared 'token_match' function. * Shared 'token_match' function.
* Matches tokenized. * Matches tokenized.
@ -400,6 +402,7 @@ typedef struct
int states; int states;
Atom state[CLIENTSTATE]; Atom state[CLIENTSTATE];
workarea monitor; workarea monitor;
int active;
} client; } client;
@ -634,13 +637,13 @@ void monitor_dimensions ( Screen *screen, int x, int y, workarea *mon )
// determine which monitor holds the active window, or failing that the mouse pointer // determine which monitor holds the active window, or failing that the mouse pointer
void monitor_active ( workarea *mon ) void monitor_active ( workarea *mon )
{ {
Window root = RootWindow ( display, XScreenNumberOfScreen ( screen ) ); Window root = RootWindow ( display, XScreenNumberOfScreen ( screen ) );
unsigned long id; Window id;
Atom type; Atom type;
int count; int count;
if ( window_get_prop ( root, netatoms[_NET_ACTIVE_WINDOW], &type, &count, &id, 1 ) if ( window_get_prop ( root, netatoms[_NET_ACTIVE_WINDOW], &type, &count, &id, sizeof ( Window ) )
&& type == XA_WINDOW && count > 0 ) && type == XA_WINDOW && count > 0 )
{ {
XWindowAttributes *attr = window_get_attributes ( id ); XWindowAttributes *attr = window_get_attributes ( id );
@ -837,10 +840,22 @@ void menu_draw ( textbox **boxes,
} }
else else
{ {
textbox_font ( boxes[i], config.menu_font, char *text = filtered[i + offset];
( i + offset ) == selected ? config.menu_hlfg : config.menu_fg, char *f_fg = ( i + offset ) == selected ? config.menu_hlfg : config.menu_fg;
( i + offset ) == selected ? config.menu_hlbg : config.menu_bg ); char *f_bg = ( i + offset ) == selected ? config.menu_hlbg : config.menu_bg;
textbox_text ( boxes[i], filtered[i + offset] ); char *font = config.menu_font;
// Check for active
if ( text[0] == '*' )
{
// Skip the '*'
text++;
// Use the active version of font.
font = active_font;
}
textbox_font ( boxes[i], font,
f_fg,
f_bg );
textbox_text ( boxes[i], text );
} }
textbox_draw ( boxes[i] ); textbox_draw ( boxes[i] );
@ -1009,6 +1024,11 @@ MenuReturn menu ( char **lines, char **input, char *prompt, Time *time, int *shi
columns = ( num_lines + ( max_rows - num_lines % max_rows ) % max_rows ) / max_rows; columns = ( num_lines + ( max_rows - num_lines % max_rows ) % max_rows ) / max_rows;
max_elements = config.menu_lines * columns; max_elements = config.menu_lines * columns;
} }
// Sanitize.
if ( columns == 0 )
{
columns = 1;
}
} }
// More hacks. // More hacks.
if ( config.hmode == TRUE ) if ( config.hmode == TRUE )
@ -1521,14 +1541,24 @@ MenuReturn menu ( char **lines, char **input, char *prompt, Time *time, int *shi
SwitcherMode run_switcher_window ( char **input ) SwitcherMode run_switcher_window ( char **input )
{ {
SwitcherMode retv = MODE_EXIT; SwitcherMode retv = MODE_EXIT;
// find window list // find window list
Atom type; Atom type;
int nwins; int nwins;
unsigned long wins[100]; Window wins[100];
int count = 0;
Window curr_win_id = 0;
// Get the active window so we can highlight this.
if ( !( window_get_prop ( root, netatoms[_NET_ACTIVE_WINDOW], &type,
&count, &curr_win_id, sizeof ( Window ) )
&& type == XA_WINDOW && count > 0 ) )
{
curr_win_id = 0;
}
if ( window_get_prop ( root, netatoms[_NET_CLIENT_LIST_STACKING], if ( window_get_prop ( root, netatoms[_NET_CLIENT_LIST_STACKING],
&type, &nwins, wins, 100 * sizeof ( unsigned long ) ) &type, &nwins, wins, 100 * sizeof ( Window ) )
&& type == XA_WINDOW ) && type == XA_WINDOW )
{ {
char pattern[50]; char pattern[50];
@ -1539,6 +1569,8 @@ SwitcherMode run_switcher_window ( char **input )
// if we happen to have a window destroyed while we're working... // if we happen to have a window destroyed while we're working...
winlist *ids = winlist_new (); winlist *ids = winlist_new ();
// calc widths of fields // calc widths of fields
for ( i = nwins - 1; i > -1; i-- ) for ( i = nwins - 1; i > -1; i-- )
{ {
@ -1560,7 +1592,10 @@ SwitcherMode run_switcher_window ( char **input )
} }
#endif #endif
if ( c->window == curr_win_id )
{
c->active = TRUE;
}
winlist_append ( ids, c->window, NULL ); winlist_append ( ids, c->window, NULL );
} }
} }
@ -1573,12 +1608,12 @@ SwitcherMode run_switcher_window ( char **input )
#ifdef HAVE_I3_IPC_H #ifdef HAVE_I3_IPC_H
if ( config_i3_mode ) if ( config_i3_mode )
{ {
sprintf ( pattern, "%%-%ds %%s", MAX ( 5, classfield ) ); sprintf ( pattern, "%%s%%-%ds %%s", MAX ( 5, classfield ) );
} }
else else
{ {
#endif #endif
sprintf ( pattern, "%%-%ds %%-%ds %%s", desktops < 10 ? 1 : 2, MAX ( 5, classfield ) ); sprintf ( pattern, "%%s%%-%ds %%-%ds %%s", desktops < 10 ? 1 : 2, MAX ( 5, classfield ) );
#ifdef HAVE_I3_IPC_H #ifdef HAVE_I3_IPC_H
} }
#endif #endif
@ -1614,12 +1649,12 @@ SwitcherMode run_switcher_window ( char **input )
sprintf ( desktop, "%d", (int) wmdesktop + 1 ); sprintf ( desktop, "%d", (int) wmdesktop + 1 );
} }
sprintf ( line, pattern, desktop, c->class, c->title ); sprintf ( line, pattern, ( c->active ) ? "*" : "", desktop, c->class, c->title );
#ifdef HAVE_I3_IPC_H #ifdef HAVE_I3_IPC_H
} }
else else
{ {
sprintf ( line, pattern, c->class, c->title ); sprintf ( line, pattern, ( c->active ) ? "*" : "", c->class, c->title );
} }
#endif #endif
@ -1730,7 +1765,7 @@ static void run_switcher ( int do_fork, SwitcherMode mode )
} }
// KeyPress event // KeyPress event
void handle_keypress ( XEvent *ev ) static void handle_keypress ( XEvent *ev )
{ {
KeySym key = XkbKeycodeToKeysym ( display, ev->xkey.keycode, 0, 0 ); KeySym key = XkbKeycodeToKeysym ( display, ev->xkey.keycode, 0, 0 );
@ -1994,6 +2029,8 @@ static void cleanup ()
// Whipe the handle.. (not working) // Whipe the handle.. (not working)
xdgWipeHandle ( &xdg_handle ); xdgWipeHandle ( &xdg_handle );
free ( active_font );
} }
/** /**
@ -2070,6 +2107,13 @@ int main ( int argc, char *argv[] )
// Sanity check // Sanity check
config_sanity_check (); config_sanity_check ();
// Generate the font string for the line that indicates a selected item.
if ( asprintf ( &active_font, "%s:slant=italic", config.menu_font ) < 0 )
{
fprintf ( stderr, "Failed to construct active string: %s\n", strerror ( errno ) );
return EXIT_FAILURE;
}
// Set up X interaction. // Set up X interaction.
signal ( SIGCHLD, catch_exit ); signal ( SIGCHLD, catch_exit );
screen = DefaultScreenOfDisplay ( display ); screen = DefaultScreenOfDisplay ( display );