1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2025-04-14 17:43:01 -04:00

Display desktop number with the pattern in window mode

This is merged from the original upstream at:
https://github.com/seanpringle/simpleswitcher/blob/master/simpleswitcher.c
This commit is contained in:
Daniel Hahler 2014-03-02 10:31:21 +01:00
parent 1bed4252ae
commit ea8c9923d5

View file

@ -528,6 +528,12 @@ void window_set_atom_prop( Window w, Atom prop, Atom *atoms, int count )
XChangeProperty( display, w, prop, XA_ATOM, 32, PropModeReplace, ( unsigned char* )atoms, count );
}
int window_get_cardinal_prop(Window w, Atom atom, unsigned long *list, int count)
{
Atom type; int items;
return window_get_prop(w, atom, &type, &items, list, count*sizeof(unsigned long)) && type == XA_CARDINAL ? items:0;
}
// a ClientMessage
int window_send_message( Window target, Window subject, Atom atom, unsigned long protocol, unsigned long mask, Time time )
{
@ -1165,6 +1171,7 @@ SwitcherMode run_switcher_window ( char **input )
char pattern[50];
int i;
unsigned int classfield = 0;
unsigned long desktops = 0;
// windows we actually display. may be slightly different to _NET_CLIENT_LIST_STACKING
// if we happen to have a window destroyed while we're working...
winlist *ids = winlist_new();
@ -1192,7 +1199,9 @@ SwitcherMode run_switcher_window ( char **input )
}
// Create pattern for printing the line.
sprintf( pattern, "%%-%ds %%s", MAX( 5, classfield ) );
if (!window_get_cardinal_prop(root, netatoms[_NET_NUMBER_OF_DESKTOPS], &desktops, 1))
desktops = 1;
sprintf(pattern, "%%-%ds %%-%ds %%s", desktops < 10 ? 1 : 2, MAX(5, classfield));
char **list = allocate_clear( sizeof( char* ) * ( ids->len+1 ) );
int lines = 0;
@ -1203,9 +1212,20 @@ SwitcherMode run_switcher_window ( char **input )
if ( ( c = window_client( w ) ) ) {
// final line format
unsigned long wmdesktop;
char desktop[5];
desktop[0] = 0;
char *line = allocate( strlen( c->title ) + strlen( c->class ) + classfield + 50 );
sprintf( line, pattern, c->class, c->title );
// find client's desktop. this is zero-based, so we adjust by since most
// normal people don't think like this :-)
if (!window_get_cardinal_prop(c->window, netatoms[_NET_WM_DESKTOP], &wmdesktop, 1))
wmdesktop = 0xFFFFFFFF;
if (wmdesktop < 0xFFFFFFFF)
sprintf(desktop, "%d", (int)wmdesktop+1);
sprintf(line, pattern, desktop, c->class, c->title);
list[lines++] = line;
}