From c13c678a5467d643ee8f9b6504e32a8a20daba9b Mon Sep 17 00:00:00 2001 From: Bastien Dejean Date: Tue, 6 Jan 2015 20:10:09 +0100 Subject: [PATCH] Add new setting: initial_polarity Fixes #193. --- contrib/bash_completion | 2 +- contrib/zsh_completion | 2 +- doc/bspwm.1 | 11 +++++++++-- doc/bspwm.1.txt | 3 +++ messages.c | 21 +++++++++++++++++++++ messages.h | 1 + settings.c | 1 + settings.h | 1 + tree.c | 9 +++++++-- types.h | 5 +++++ 10 files changed, 50 insertions(+), 6 deletions(-) diff --git a/contrib/bash_completion b/contrib/bash_completion index 05dbc25..ba9c77c 100644 --- a/contrib/bash_completion +++ b/contrib/bash_completion @@ -1,7 +1,7 @@ _bspc() { local commands='window desktop monitor query pointer rule restore control config quit' - 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 border_width window_gap top_padding right_padding bottom_padding left_padding split_ratio borderless_monocle gapless_monocle focus_follows_pointer pointer_follows_focus pointer_follows_monitor apply_floating_atom auto_alternate auto_cancel history_aware_focus focus_by_distance ignore_ewmh_focus remove_disabled_monitors remove_unplugged_monitors merge_overlapping_monitors' + 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 border_width window_gap top_padding right_padding bottom_padding left_padding split_ratio initial_polarity borderless_monocle gapless_monocle focus_follows_pointer pointer_follows_focus pointer_follows_monitor apply_floating_atom auto_alternate auto_cancel history_aware_focus focus_by_distance ignore_ewmh_focus remove_disabled_monitors remove_unplugged_monitors merge_overlapping_monitors' COMPREPLY=() diff --git a/contrib/zsh_completion b/contrib/zsh_completion index b93ae99..a00e501 100644 --- a/contrib/zsh_completion +++ b/contrib/zsh_completion @@ -3,7 +3,7 @@ _bspc() { local -a commands settings 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' 'border_width' 'window_gap' 'top_padding' 'right_padding' 'bottom_padding' 'left_padding' 'split_ratio' 'borderless_monocle' 'gapless_monocle' 'focus_follows_pointer' 'pointer_follows_focus' 'pointer_follows_monitor' 'apply_floating_atom' 'auto_alternate' 'auto_cancel' 'history_aware_focus' 'focus_by_distance' 'ignore_ewmh_focus' 'remove_disabled_monitors' 'remove_unplugged_monitors' 'merge_overlapping_monitors') + 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' 'border_width' 'window_gap' 'top_padding' 'right_padding' 'bottom_padding' 'left_padding' 'split_ratio' 'initial_polarity' 'borderless_monocle' 'gapless_monocle' 'focus_follows_pointer' 'pointer_follows_focus' 'pointer_follows_monitor' 'apply_floating_atom' 'auto_alternate' 'auto_cancel' 'history_aware_focus' 'focus_by_distance' 'ignore_ewmh_focus' 'remove_disabled_monitors' 'remove_unplugged_monitors' 'merge_overlapping_monitors') if (( CURRENT == 2 )) ; then _values 'command' "$commands[@]" elif (( CURRENT == 3 )) ; then diff --git a/doc/bspwm.1 b/doc/bspwm.1 index 95fab40..fe41e21 100644 --- a/doc/bspwm.1 +++ b/doc/bspwm.1 @@ -2,12 +2,12 @@ .\" Title: bspwm .\" Author: [see the "Author" section] .\" Generator: DocBook XSL Stylesheets v1.78.1 -.\" Date: 11/23/2014 +.\" Date: 01/06/2015 .\" Manual: Bspwm Manual .\" Source: Bspwm 0.8.9 .\" Language: English .\" -.TH "BSPWM" "1" "11/23/2014" "Bspwm 0\&.8\&.9" "Bspwm Manual" +.TH "BSPWM" "1" "01/06/2015" "Bspwm 0\&.8\&.9" "Bspwm Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- @@ -1061,6 +1061,13 @@ External command used to retrieve rule consequences\&. The command will receive command)\&. .RE .PP +\fIinitial_polarity\fR +.RS 4 +On which child should a new window be attached when adding a window on a single window tree in automatic mode\&. Accept the following values: +\fBfirst_child\fR, +\fBsecond_child\fR\&. +.RE +.PP \fIhistory_aware_focus\fR .RS 4 Give priority to the focus history when focusing nodes\&. diff --git a/doc/bspwm.1.txt b/doc/bspwm.1.txt index 85e5117..89b4d10 100644 --- a/doc/bspwm.1.txt +++ b/doc/bspwm.1.txt @@ -652,6 +652,9 @@ Global Settings '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). +'initial_polarity':: + On which child should a new window be attached when adding a window on a single window tree in automatic mode. Accept the following values: *first_child*, *second_child*. + 'history_aware_focus':: Give priority to the focus history when focusing nodes. diff --git a/messages.c b/messages.c index d859a3f..c0f773a 100644 --- a/messages.c +++ b/messages.c @@ -958,6 +958,13 @@ int set_setting(coordinates_t loc, char *name, char *value) SETCOLOR(normal_private_border_color) SETCOLOR(urgent_border_color) #undef SETCOLOR + } else if (streq("initial_polarity", name)) { + child_polarity_t p; + if (parse_child_polarity(value, &p)) { + initial_polarity = p; + } else { + return MSG_FAILURE; + } } else if (streq("focus_follows_pointer", name)) { bool b; if (parse_bool(value, &b) && b != focus_follows_pointer) { @@ -1037,6 +1044,8 @@ int get_setting(coordinates_t loc, char *name, FILE* rsp) fprintf(rsp, "%s", external_rules_command); else if (streq("status_prefix", name)) fprintf(rsp, "%s", status_prefix); + else if (streq("initial_polarity", name)) + fprintf(rsp, "%s", initial_polarity == FIRST_CHILD ? "first_child" : "second_child"); #define MONDESKGET(k) \ else if (streq(#k, name)) \ if (loc.desktop != NULL) \ @@ -1197,6 +1206,18 @@ bool parse_pointer_action(char *s, pointer_action_t *a) return false; } +bool parse_child_polarity(char *s, child_polarity_t *p) +{ + if (streq("first_child", s)) { + *p = FIRST_CHILD; + return true; + } else if (streq("second_child", s)) { + *p = SECOND_CHILD; + return true; + } + return false; +} + bool parse_degree(char *s, int *d) { int i = atoi(s); diff --git a/messages.h b/messages.h index bac39c4..dbcd44e 100644 --- a/messages.h +++ b/messages.h @@ -53,6 +53,7 @@ bool parse_circulate_direction(char *s, circulate_dir_t *d); bool parse_history_direction(char *s, history_dir_t *d); bool parse_flip(char *s, flip_t *f); bool parse_pointer_action(char *s, pointer_action_t *a); +bool parse_child_polarity(char *s, child_polarity_t *p); bool parse_degree(char *s, int *d); bool parse_window_id(char *s, long int *i); bool parse_bool_declaration(char *s, char **key, bool *value, alter_state_t *state); diff --git a/settings.c b/settings.c index a18fe9a..1d73146 100644 --- a/settings.c +++ b/settings.c @@ -60,6 +60,7 @@ void load_settings(void) split_ratio = SPLIT_RATIO; window_gap = WINDOW_GAP; border_width = BORDER_WIDTH; + initial_polarity = FIRST_CHILD; borderless_monocle = BORDERLESS_MONOCLE; gapless_monocle = GAPLESS_MONOCLE; diff --git a/settings.h b/settings.h index 5fe17b4..41f2cfc 100644 --- a/settings.h +++ b/settings.h @@ -88,6 +88,7 @@ char urgent_border_color[MAXLEN]; double split_ratio; int window_gap; unsigned int border_width; +child_polarity_t initial_polarity; bool borderless_monocle; bool gapless_monocle; diff --git a/tree.c b/tree.c index 82786d0..c428a40 100644 --- a/tree.c +++ b/tree.c @@ -181,8 +181,13 @@ void insert_node(monitor_t *m, desktop_t *d, node_t *n, node_t *f) switch (f->split_mode) { case MODE_AUTOMATIC: if (p == NULL) { - c->first_child = n; - c->second_child = f; + if (initial_polarity == FIRST_CHILD) { + c->first_child = n; + c->second_child = f; + } else { + c->first_child = f; + c->second_child = n; + } if (m->rectangle.width > m->rectangle.height) c->split_type = TYPE_VERTICAL; else diff --git a/types.h b/types.h index 9782ede..3fca404 100644 --- a/types.h +++ b/types.h @@ -142,6 +142,11 @@ typedef enum { DESKTOP_URGENCY_OFF } desktop_urgency_t; +typedef enum { + FIRST_CHILD, + SECOND_CHILD +} child_polarity_t; + typedef struct { desktop_status_t status; bool urgent; -- 2.44.0