Skip to content

Commit

Permalink
Reinstate the *rule* command
Browse files Browse the repository at this point in the history
External rules are truly optional. At last.
  • Loading branch information
baskerville committed Dec 12, 2013
1 parent 9a23707 commit cd97a32
Show file tree
Hide file tree
Showing 23 changed files with 361 additions and 106 deletions.
3 changes: 3 additions & 0 deletions bspwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ void init(void)
monitor_uid = desktop_uid = 0;
mon = mon_head = mon_tail = pri_mon = NULL;
history_head = history_tail = history_needle = NULL;
rule_head = rule_tail = NULL;
stack_head = stack_tail = NULL;
subscribe_head = subscribe_tail = NULL;
pending_rule_head = pending_rule_tail = NULL;
Expand Down Expand Up @@ -295,6 +296,8 @@ void cleanup(void)
{
while (mon_head != NULL)
remove_monitor(mon_head);
while (rule_head != NULL)
remove_rule(rule_head);
while (stack_head != NULL)
remove_stack(stack_head);
while (subscribe_head != NULL)
Expand Down
2 changes: 2 additions & 0 deletions bspwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ monitor_t *pri_mon;
history_t *history_head;
history_t *history_tail;
history_t *history_needle;
rule_t *rule_head;
rule_t *rule_tail;
stacking_list_t *stack_head;
stacking_list_t *stack_tail;
subscriber_list_t *subscribe_head;
Expand Down
4 changes: 2 additions & 2 deletions contrib/bash_completion
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
_bspc() {
local commands='window desktop monitor query pointer restore control config quit'
local commands='window desktop monitor query pointer rule restore control config quit'

local settings='rule_command status_prefix focused_border_color active_border_color normal_border_color presel_border_color focused_locked_border_color active_locked_border_color normal_locked_border_color focused_sticky_border_color normal_sticky_border_color focused_private_border_color active_private_border_color normal_private_border_color urgent_border_color focused_frame_opacity active_frame_opacity normal_frame_opacity border_width window_gap top_padding right_padding bottom_padding left_padding split_ratio growth_factor borderless_monocle gapless_monocle focus_follows_pointer pointer_follows_monitor apply_floating_atom auto_alternate auto_cancel history_aware_focus ignore_ewmh_focus remove_disabled_monitor'
local settings='external_rules_command status_prefix focused_border_color active_border_color normal_border_color presel_border_color focused_locked_border_color active_locked_border_color normal_locked_border_color focused_sticky_border_color normal_sticky_border_color focused_private_border_color active_private_border_color normal_private_border_color urgent_border_color focused_frame_opacity active_frame_opacity normal_frame_opacity border_width window_gap top_padding right_padding bottom_padding left_padding split_ratio growth_factor borderless_monocle gapless_monocle focus_follows_pointer pointer_follows_monitor apply_floating_atom auto_alternate auto_cancel history_aware_focus ignore_ewmh_focus remove_disabled_monitor'

COMPREPLY=()

Expand Down
4 changes: 2 additions & 2 deletions contrib/zsh_completion
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

_bspc() {
local -a commands settings
commands=('window' 'desktop' 'monitor' 'query' 'pointer' 'restore' 'control' 'config' 'quit')
settings=('rule_command' 'status_prefix' 'focused_border_color' 'active_border_color' 'normal_border_color' 'presel_border_color' 'focused_locked_border_color' 'active_locked_border_color' 'normal_locked_border_color' 'focused_sticky_border_color' 'normal_sticky_border_color' 'focused_private_border_color' 'active_private_border_color' 'normal_private_border_color' 'urgent_border_color' 'focused_frame_opacity' 'active_frame_opacity' 'normal_frame_opacity' 'border_width' 'window_gap' 'top_padding' 'right_padding' 'bottom_padding' 'left_padding' 'split_ratio' 'growth_factor' 'borderless_monocle' 'gapless_monocle' 'focus_follows_pointer' 'pointer_follows_monitor' 'apply_floating_atom' 'auto_alternate' 'auto_cancel' 'history_aware_focus' 'ignore_ewmh_focus' 'remove_disabled_monitor')
commands=('window' 'desktop' 'monitor' 'query' 'pointer' 'rule' 'restore' 'control' 'config' 'quit')
settings=('external_rules_command' 'status_prefix' 'focused_border_color' 'active_border_color' 'normal_border_color' 'presel_border_color' 'focused_locked_border_color' 'active_locked_border_color' 'normal_locked_border_color' 'focused_sticky_border_color' 'normal_sticky_border_color' 'focused_private_border_color' 'active_private_border_color' 'normal_private_border_color' 'urgent_border_color' 'focused_frame_opacity' 'active_frame_opacity' 'normal_frame_opacity' 'border_width' 'window_gap' 'top_padding' 'right_padding' 'bottom_padding' 'left_padding' 'split_ratio' 'growth_factor' 'borderless_monocle' 'gapless_monocle' 'focus_follows_pointer' 'pointer_follows_monitor' 'apply_floating_atom' 'auto_alternate' 'auto_cancel' 'history_aware_focus' 'ignore_ewmh_focus' 'remove_disabled_monitor')
if (( CURRENT == 2 )) ; then
_values 'command' "$commands[@]"
elif (( CURRENT == 3 )) ; then
Expand Down
81 changes: 52 additions & 29 deletions doc/bspwm.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
.\" Title: bspwm
.\" Author: [see the "Author" section]
.\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
.\" Date: 12/05/2013
.\" Date: 12/12/2013
.\" Manual: Bspwm Manual
.\" Source: Bspwm 0.8.7
.\" Language: English
.\"
.TH "BSPWM" "1" "12/05/2013" "Bspwm 0\&.8\&.7" "Bspwm Manual"
.TH "BSPWM" "1" "12/12/2013" "Bspwm 0\&.8\&.7" "Bspwm Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
Expand Down Expand Up @@ -827,6 +827,42 @@ Pass the pointer root coordinates for the current pointer action\&.
Terminate the current pointer action\&.
.RE
.RE
.SS "Rule"
.sp
.it 1 an-trap
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
.ps +1
\fBGeneral Syntax\fR
.RS 4
.sp
rule \fIOPTIONS\fR
.RE
.sp
.it 1 an-trap
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
.ps +1
\fBOptions\fR
.RS 4
.PP
\fB\-a\fR, \fB\-\-add\fR <class_name>|<instance_name>|* [\fB\-o\fR|\fB\-\-one\-shot\fR] [desktop=DESKTOP_SEL|monitor=MONITOR_SEL] [(floating|fullscreen|locked|sticky|private|frame|center|lower|follow|manage|focus)=(true|false)]
.RS 4
Create a new rule\&.
.RE
.PP
\fB\-r\fR, \fB\-\-remove\fR ^<n>|head|tail|<class_name>|<instance_name>|*\&...
.RS 4
Remove the given rules\&.
.RE
.PP
\fB\-l\fR, \fB\-\-list\fR [<class_name>|<instance_name>|*]
.RS 4
List the rules\&.
.RE
.RE
.SS "Config"
.sp
.it 1 an-trap
Expand Down Expand Up @@ -864,33 +900,6 @@ Colors are either X color names or \fI#RRGGBB\fR, booleans are \fItrue\fR or \fI
All the boolean settings are \fIfalse\fR by default\&.
.SS "Global Settings"
.PP
\fIrule_command\fR
.RS 4
External command used to retrieve rule consequences\&. The command will receive the the ID of the window being processed as its first argument\&. The output of that command must have the following format:
\fBkey1=value1 key2=value2 \&...\fR, where
\fBkeyN\fR
is one of
\fIfloating\fR,
\fIfullscreen\fR,
\fIlocked\fR,
\fIsticky\fR,
\fIprivate\fR,
\fIframe\fR,
\fIcenter\fR,
\fIlower\fR,
\fIfollow\fR,
\fImanage\fR,
\fIfocus\fR,
\fIdesktop\fR
or
\fImonitor\fR\&.
.RE
.PP
\fIstatus_prefix\fR
.RS 4
Prefix prepended to each of the status lines\&.
.RE
.PP
\fIfocused_border_color\fR
.RS 4
Color of the border of a focused window of a focused monitor\&.
Expand Down Expand Up @@ -988,6 +997,20 @@ Default split ratio\&.
Intensity of the growth involved in pulling or pushing an edge\&.
.RE
.PP
\fIstatus_prefix\fR
.RS 4
Prefix prepended to each of the status lines\&.
.RE
.PP
\fIexternal_rules_command\fR
.RS 4
External command used to retrieve rule consequences\&. The command will receive the the ID of the window being processed as its first argument and the class and instance names as second and third arguments\&. The output of that command must have the following format:
\fBkey1=value1 key2=value2 \&...\fR
(the valid key/value pairs are given in the description of the
\fIrule\fR
command)\&.
.RE
.PP
\fIhistory_aware_focus\fR
.RS 4
Give priority to the focus history when focusing nodes\&.
Expand Down
32 changes: 26 additions & 6 deletions doc/bspwm.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,26 @@ Options
*-u*, *--ungrab*::
Terminate the current pointer action.
Rule
~~~~
General Syntax
^^^^^^^^^^^^^^
rule 'OPTIONS'
Options
^^^^^^^
*-a*, *--add* <class_name>|<instance_name>|* [*-o*|*--one-shot*] [desktop=DESKTOP_SEL|monitor=MONITOR_SEL] [(floating|fullscreen|locked|sticky|private|frame|center|lower|follow|manage|focus)=(true|false)]::
Create a new rule.
*-r*, *--remove* ^<n>|head|tail|<class_name>|<instance_name>|*...::
Remove the given rules.
*-l*, *--list* [<class_name>|<instance_name>|*]::
List the rules.
Config
~~~~~~
Expand Down Expand Up @@ -535,12 +555,6 @@ All the boolean settings are 'false' by default.
Global Settings
~~~~~~~~~~~~~~~

'rule_command'::
External command used to retrieve rule consequences. The command will receive the the ID of the window being processed as its first argument. The output of that command must have the following format: *key1=value1 key2=value2 ...*, where *keyN* is one of 'floating', 'fullscreen', 'locked', 'sticky', 'private', 'frame', 'center', 'lower', 'follow', 'manage', 'focus', 'desktop' or 'monitor'.

'status_prefix'::
Prefix prepended to each of the status lines.

'focused_border_color'::
Color of the border of a focused window of a focused monitor.

Expand Down Expand Up @@ -598,6 +612,12 @@ Global Settings
'growth_factor'::
Intensity of the growth involved in pulling or pushing an edge.

'status_prefix'::
Prefix prepended to each of the status lines.

'external_rules_command'::
External command used to retrieve rule consequences. The command will receive the the ID of the window being processed as its first argument and the class and instance names as second and third arguments. The output of that command must have the following format: *key1=value1 key2=value2 ...* (the valid key/value pairs are given in the description of the 'rule' command).

'history_aware_focus'::
Give priority to the focus history when focusing nodes.

Expand Down
6 changes: 6 additions & 0 deletions examples/bspwmrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ bspc config window_gap 12
bspc config split_ratio 0.52
bspc config borderless_monocle true
bspc config gapless_monocle true

bspc rule -a Gimp desktop=^8 follow=on floating=on
bspc rule -a Chromium desktop=^2
bspc rule -a mplayer2 floating=on
bspc rule -a Kupfer.py focus=on
bspc rule -a Screenkey manage=off
3 changes: 1 addition & 2 deletions examples/external_rules/bspwmrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#! /bin/sh

bspc config rule_command "$(which rule_command)"
bspwm_rules
bspc config external_rules_command "$(which external_rules)"
14 changes: 14 additions & 0 deletions examples/external_rules/external_rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#! /bin/sh

wid=$1
class=$2
instance=$3

if [ "$instance" = fontforge ] ; then
title=$(xtitle "$wid")
case "$title" in
Layers|Tools|Warning)
echo "focus = off"
;;
esac
fi
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions examples/external_rules/lua/bspwmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#! /bin/sh

bspc config external_rules_command "$(which external_rules)"
bspwm_rules
File renamed without changes.
File renamed without changes.
File renamed without changes.
74 changes: 67 additions & 7 deletions messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "monitor.h"
#include "pointer.h"
#include "query.h"
#include "rule.h"
#include "restore.h"
#include "settings.h"
#include "tree.h"
Expand Down Expand Up @@ -89,6 +90,8 @@ bool process_message(char **args, int num, char *rsp)
return cmd_restore(++args, --num);
} else if (streq("control", *args)) {
return cmd_control(++args, --num, rsp);
} else if (streq("rule", *args)) {
return cmd_rule(++args, --num, rsp);
} else if (streq("pointer", *args)) {
return cmd_pointer(++args, --num);
} else if (streq("config", *args)) {
Expand All @@ -108,7 +111,7 @@ bool cmd_window(char **args, int num)
coordinates_t ref = {mon, mon->desk, mon->desk->focus};
coordinates_t trg = ref;

if (*args[0] != OPT_CHR) {
if ((*args)[0] != OPT_CHR) {
if (node_from_desc(*args, &ref, &trg))
num--, args++;
else
Expand Down Expand Up @@ -324,7 +327,7 @@ bool cmd_desktop(char **args, int num)
coordinates_t ref = {mon, mon->desk, NULL};
coordinates_t trg = ref;

if (*args[0] != OPT_CHR) {
if ((*args)[0] != OPT_CHR) {
if (desktop_from_desc(*args, &ref, &trg))
num--, args++;
else
Expand Down Expand Up @@ -474,7 +477,7 @@ bool cmd_monitor(char **args, int num)
coordinates_t ref = {mon, NULL, NULL};
coordinates_t trg = ref;

if (*args[0] != OPT_CHR) {
if ((*args)[0] != OPT_CHR) {
if (monitor_from_desc(*args, &ref, &trg))
num--, args++;
else
Expand Down Expand Up @@ -643,6 +646,63 @@ bool cmd_query(char **args, int num, char *rsp)
return true;
}

bool cmd_rule(char **args, int num, char *rsp)
{
if (num < 1)
return false;
while (num > 0) {
if (streq("-a", *args) || streq("--add", *args)) {
num--, args++;
if (num < 2)
return false;
rule_t *rule = make_rule();
snprintf(rule->cause, sizeof(rule->cause), "%s", *args);
num--, args++;
size_t i = 0;
while (num > 0) {
if (streq("-o", *args) || streq("--one-shot", *args)) {
rule->one_shot = true;
} else {
PRINTF("%s %i\n", *args, (int)strlen(*args));
for (size_t j = 0; i < sizeof(rule->effect) && j < strlen(*args); i++, j++) {
PRINTF("i %i, j %i\n", (int)i, (int)j);
rule->effect[i] = (*args)[j];
}
if (num > 1 && i < sizeof(rule->effect))
rule->effect[i++] = ' ';
}
num--, args++;
}
rule->effect[MIN(i, sizeof(rule->effect) - 1)] = '\0';
add_rule(rule);
} else if (streq("-r", *args) || streq("--remove", *args)) {
num--, args++;
if (num < 1)
return false;
int idx;
while (num > 0) {
if (parse_index(*args, &idx))
remove_rule_by_index(idx - 1);
else if (streq("tail", *args))
remove_rule(rule_tail);
else if (streq("head", *args))
remove_rule(rule_head);
else
remove_rule_by_cause(*args);
num--, args++;
}
} else if (streq("-l", *args) || streq("--list", *args)) {
num--, args++;
list_rules(num > 0 ? *args : NULL, rsp);
} else {
return false;
}
num--, args++;
}

return true;
}

bool cmd_pointer(char **args, int num)
{
if (num < 1)
Expand Down Expand Up @@ -743,7 +803,7 @@ bool cmd_config(char **args, int num, char *rsp)
return false;
coordinates_t ref = {mon, mon->desk, mon->desk->focus};
coordinates_t trg = {NULL, NULL, NULL};
if (*args[0] == OPT_CHR) {
if ((*args)[0] == OPT_CHR) {
if (streq("-d", *args) || streq("--desktop", *args)) {
num--, args++;
if (num < 1)
Expand Down Expand Up @@ -818,7 +878,7 @@ bool set_setting(coordinates_t loc, char *name, char *value)
#define SETSTR(s) \
} else if (streq(#s, name)) { \
return snprintf(s, sizeof(s), "%s", value) >= 0;
SETSTR(rule_command)
SETSTR(external_rules_command)
SETSTR(status_prefix)
#undef SETSTR
} else if (streq("split_ratio", name)) {
Expand Down Expand Up @@ -928,8 +988,8 @@ bool get_setting(coordinates_t loc, char *name, char* rsp)
return false;
else
snprintf(rsp, BUFSIZ, "%u", loc.desktop->border_width);
else if (streq("rule_command", name))
snprintf(rsp, BUFSIZ, "%s", rule_command);
else if (streq("external_rules_command", name))
snprintf(rsp, BUFSIZ, "%s", external_rules_command);
else if (streq("status_prefix", name))
snprintf(rsp, BUFSIZ, "%s", status_prefix);
#define MONGET(k) \
Expand Down
1 change: 1 addition & 0 deletions messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ bool cmd_window(char **args, int num);
bool cmd_desktop(char **args, int num);
bool cmd_monitor(char **args, int num);
bool cmd_query(char **args, int num, char *rsp);
bool cmd_rule(char **args, int num, char *rsp);
bool cmd_pointer(char **args, int num);
bool cmd_restore(char **args, int num);
bool cmd_control(char **args, int num, char *rsp);
Expand Down
Loading

0 comments on commit cd97a32

Please sign in to comment.