Add index selector for desktops and monitors

This commit is contained in:
Bastien Dejean 2013-09-02 21:03:59 +02:00
parent 8448fe0759
commit e2f085815a
7 changed files with 77 additions and 3 deletions

View file

@ -2,12 +2,12 @@
.\" Title: bspwm
.\" Author: [see the "Author" section]
.\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
.\" Date: 08/28/2013
.\" Date: 09/02/2013
.\" Manual: Bspwm Manual
.\" Source: Bspwm 0.8
.\" Language: English
.\"
.TH "BSPWM" "1" "08/28/2013" "Bspwm 0\&.8" "Bspwm Manual"
.TH "BSPWM" "1" "09/02/2013" "Bspwm 0\&.8" "Bspwm Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
@ -277,6 +277,7 @@ Select a desktop\&.
.\}
.nf
DESKTOP_SEL := <desktop_name>
| ^<n>
| (CYCLE_DIR|last|focused)[\&.occupied|\&.free][\&.urgent|\&.nonurgent]
.fi
.if n \{\
@ -291,6 +292,16 @@ DESKTOP_SEL := <desktop_name>
\fBPrimary Selectors\fR
.RS 4
.PP
<desktop_name>
.RS 4
Selects the desktop with the given name\&.
.RE
.PP
^<n>
.RS 4
Selects the nth desktop\&.
.RE
.PP
\fICYCLE_DIR\fR
.RS 4
Selects the desktop in the given direction relative to the active desktop\&.
@ -344,6 +355,7 @@ Select a monitor\&.
.\}
.nf
MONITOR_SEL := <monitor_name>
| ^<n>
| (DIR|CYCLE_DIR|last|focused)[\&.occupied|\&.free]
.fi
.if n \{\
@ -358,6 +370,16 @@ MONITOR_SEL := <monitor_name>
\fBPrimary Selectors\fR
.RS 4
.PP
<monitor_name>
.RS 4
Selects the monitor with the given name\&.
.RE
.PP
^<n>
.RS 4
Selects the nth monitor\&.
.RE
.PP
\fIDIR\fR
.RS 4
Selects the monitor in the given (spacial) direction relative to the active monitor\&.

View file

@ -197,12 +197,19 @@ Select a desktop.
----
DESKTOP_SEL := <desktop_name>
| ^<n>
| (CYCLE_DIR|last|focused)[.occupied|.free][.urgent|.nonurgent]
----
Primary Selectors
^^^^^^^^^^^^^^^^^
<desktop_name>::
Selects the desktop with the given name.
^<n>::
Selects the nth desktop.
'CYCLE_DIR'::
Selects the desktop in the given direction relative to the active desktop.
@ -234,12 +241,19 @@ Select a monitor.
----
MONITOR_SEL := <monitor_name>
| ^<n>
| (DIR|CYCLE_DIR|last|focused)[.occupied|.free]
----
Primary Selectors
^^^^^^^^^^^^^^^^^
<monitor_name>::
Selects the monitor with the given name.
^<n>::
Selects the nth monitor.
'DIR'::
Selects the monitor in the given (spacial) direction relative to the active monitor.

1
ewmh.c
View file

@ -39,7 +39,6 @@ uint32_t ewmh_get_desktop_index(desktop_t *d)
for (desktop_t *cd = m->desk_head; cd != NULL; cd = cd->next, i++)
if (d == cd)
return i;
return 0;
}

View file

@ -926,3 +926,8 @@ bool parse_window_id(char *s, long int *i)
*i = ret;
return true;
}
bool parse_index(char *s, int *i)
{
return sscanf(s, "^%i", i) == 1;
}

View file

@ -31,5 +31,6 @@ bool parse_fence_move(char *, fence_move_t *);
bool parse_pointer_action(char *, pointer_action_t *);
bool parse_degree(char *, int *);
bool parse_window_id(char *, long int *);
bool parse_index(char *, int *);
#endif

31
query.c
View file

@ -205,9 +205,12 @@ bool desktop_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
dst->desktop = NULL;
cycle_dir_t cyc;
int idx;
if (parse_cycle_direction(desc, &cyc)) {
dst->monitor = ref->monitor;
dst->desktop = closest_desktop(ref->monitor, ref->desktop, cyc, sel);
} else if (parse_index(desc, &idx)) {
desktop_from_index(idx, dst);
} else if (streq("last", desc)) {
if (mon->last_desk != NULL && desktop_matches(mon->last_desk, sel)) {
dst->monitor = mon;
@ -245,10 +248,13 @@ bool monitor_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
direction_t dir;
cycle_dir_t cyc;
int idx;
if (parse_direction(desc, &dir)) {
dst->monitor = nearest_monitor(ref->monitor, dir, sel);
} else if (parse_cycle_direction(desc, &cyc)) {
dst->monitor = closest_monitor(ref->monitor, cyc, sel);
} else if (parse_index(desc, &idx)) {
monitor_from_index(idx, dst);
} else if (streq("last", desc)) {
if (last_mon != NULL && desktop_matches(last_mon->desk, sel)) {
dst->monitor = last_mon;
@ -299,3 +305,28 @@ bool locate_monitor(char *name, coordinates_t *loc)
}
return false;
}
bool desktop_from_index(int i, coordinates_t *loc)
{
for (monitor_t *m = mon_head; m != NULL; m = m->next)
for (desktop_t *d = m->desk_head; d != NULL; d = d->next, i--)
if (i == 1) {
loc->monitor = m;
loc->desktop = d;
loc->node = NULL;
return true;
}
return false;
}
bool monitor_from_index(int i, coordinates_t *loc)
{
for (monitor_t *m = mon_head; m != NULL; m = m->next, i--)
if (i == 1) {
loc->monitor = m;
loc->desktop = NULL;
loc->node = NULL;
return true;
}
return false;
}

View file

@ -20,5 +20,7 @@ bool locate_monitor(char *, coordinates_t *);
bool node_from_desc(char *, coordinates_t *, coordinates_t *);
bool desktop_from_desc(char *, coordinates_t *, coordinates_t *);
bool monitor_from_desc(char *, coordinates_t *, coordinates_t *);
bool desktop_from_index(int, coordinates_t *);
bool monitor_from_index(int, coordinates_t *);
#endif