*click_to_focus* is now a button name

Booleans are deprecated but still accepted.
This commit is contained in:
Bastien Dejean 2017-07-12 10:33:51 +02:00
parent 61d5ca4756
commit 0a9b6153af
11 changed files with 85 additions and 27 deletions

View file

@ -2,12 +2,12 @@
.\" Title: bspwm
.\" Author: [see the "Author" section]
.\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
.\" Date: 06/04/2017
.\" Date: 07/12/2017
.\" Manual: Bspwm Manual
.\" Source: Bspwm 0.9.2-48-gfab441b
.\" Source: Bspwm 0.9.2-57-g61d5ca4
.\" Language: English
.\"
.TH "BSPWM" "1" "06/04/2017" "Bspwm 0\&.9\&.2\-48\-gfab441b" "Bspwm Manual"
.TH "BSPWM" "1" "07/12/2017" "Bspwm 0\&.9\&.2\-57\-g61d5ca4" "Bspwm Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
@ -1123,14 +1123,20 @@ Action performed when pressing
.PP
\fIclick_to_focus\fR
.RS 4
Focus a window (or a monitor) by clicking it\&.
Button used for focusing a window (or a monitor)\&. The possible values are:
\fBbutton1\fR,
\fBbutton2\fR,
\fBbutton3\fR,
\fBany\fR,
\fBnone\fR\&.
.RE
.PP
\fIswallow_first_click\fR
.RS 4
Don\(cqt replay the click that makes a window focused when
Don\(cqt replay the click that makes a window focused if
\fIclick_to_focus\fR
is set\&.
isn\(cqt
\fBnone\fR\&.
.RE
.PP
\fIfocus_follows_pointer\fR
@ -1198,11 +1204,10 @@ Window border width\&.
.RE
.SH "POINTER BINDINGS"
.PP
\fIbutton1\fR
.RS 4
Focus the window under the pointer if
\fIclick_to_focus\fR
is set\&.
.RS 4
Focus the window (or the monitor) under the pointer if the value isn\(cqt
\fBnone\fR\&.
.RE
.PP
\fIpointer_modifier\fR + \fIbutton1\fR

View file

@ -651,10 +651,10 @@ Global Settings
Action performed when pressing 'pointer_modifier' + 'button<n>'. Accept the following values: *move*, *resize_side*, *resize_corner*, *focus*, *none*.
'click_to_focus'::
Focus a window (or a monitor) by clicking it.
Button used for focusing a window (or a monitor). The possible values are: *button1*, *button2*, *button3*, *any*, *none*.
'swallow_first_click'::
Don't replay the click that makes a window focused when 'click_to_focus' is set.
Don't replay the click that makes a window focused if 'click_to_focus' isn't *none*.
'focus_follows_pointer'::
Focus the window under the pointer.
@ -707,8 +707,8 @@ Node Settings
Pointer Bindings
----------------
'button1'::
Focus the window under the pointer if 'click_to_focus' is set.
'click_to_focus'::
Focus the window (or the monitor) under the pointer if the value isn't *none*.
'pointer_modifier' + 'button1'::
Move the window under the pointer.

View file

@ -340,12 +340,12 @@ void button_press(xcb_generic_event_t *evt)
{
xcb_button_press_event_t *e = (xcb_button_press_event_t *) evt;
bool replay = false;
uint8_t buttons[] = {XCB_BUTTON_INDEX_1, XCB_BUTTON_INDEX_2, XCB_BUTTON_INDEX_3};
for (unsigned int i = 0; i < LENGTH(buttons); i++) {
if (e->detail != buttons[i]) {
for (unsigned int i = 0; i < LENGTH(BUTTONS); i++) {
if (e->detail != BUTTONS[i]) {
continue;
}
if (click_to_focus && cleaned_mask(e->state) == XCB_NONE) {
if ((click_to_focus == XCB_BUTTON_INDEX_ANY || click_to_focus == BUTTONS[i]) &&
cleaned_mask(e->state) == XCB_NONE) {
bool pff = pointer_follows_focus;
bool pfm = pointer_follows_monitor;
pointer_follows_focus = false;

View file

@ -29,6 +29,7 @@
#include <xcb/xcb_event.h>
uint8_t randr_base;
static const xcb_button_index_t BUTTONS[] = {XCB_BUTTON_INDEX_1, XCB_BUTTON_INDEX_2, XCB_BUTTON_INDEX_3};
void handle_event(xcb_generic_event_t *evt);
void map_request(xcb_generic_event_t *evt);

View file

@ -1487,7 +1487,7 @@ void set_setting(coordinates_t loc, char *name, char *value, FILE *rsp)
return;
}
} else if (streq("click_to_focus", name)) {
if (parse_bool(value, &click_to_focus)) {
if (parse_button_index(value, &click_to_focus)) {
ungrab_buttons();
grab_buttons();
} else {
@ -1621,6 +1621,8 @@ void get_setting(coordinates_t loc, char *name, FILE* rsp)
fprintf(rsp, "%s", TIGHTNESS_STR(directional_focus_tightness));
} else if (streq("pointer_modifier", name)) {
print_modifier_mask(pointer_modifier, rsp);
} else if (streq("click_to_focus", name)) {
print_button_index(click_to_focus, rsp);
} else if (streq("pointer_motion_interval", name)) {
fprintf(rsp, "%u", pointer_motion_interval);
} else if (streq("pointer_action1", name) ||
@ -1643,7 +1645,6 @@ void get_setting(coordinates_t loc, char *name, FILE* rsp)
GET_BOOL(gapless_monocle)
GET_BOOL(paddingless_monocle)
GET_BOOL(single_monocle)
GET_BOOL(click_to_focus)
GET_BOOL(swallow_first_click)
GET_BOOL(focus_follows_pointer)
GET_BOOL(pointer_follows_focus)

View file

@ -213,6 +213,35 @@ bool parse_modifier_mask(char *s, uint16_t *m)
return false;
}
bool parse_button_index(char *s, int8_t *b)
{
bool v;
if (strcmp(s, "any") == 0) {
*b = XCB_BUTTON_INDEX_ANY;
return true;
} else if (strcmp(s, "button1") == 0) {
*b = XCB_BUTTON_INDEX_1;
return true;
} else if (strcmp(s, "button2") == 0) {
*b = XCB_BUTTON_INDEX_2;
return true;
} else if (strcmp(s, "button3") == 0) {
*b = XCB_BUTTON_INDEX_3;
return true;
} else if (strcmp(s, "none") == 0) {
*b = -1;
return true;
} else if (parse_bool(s, &v)) {
if (v) {
*b = XCB_BUTTON_INDEX_1;
} else {
*b = -1;
}
return true;
}
return false;
}
bool parse_pointer_action(char *s, pointer_action_t *a)
{
if (streq("move", s)) {

View file

@ -22,6 +22,7 @@ bool parse_history_direction(char *s, history_dir_t *d);
bool parse_flip(char *s, flip_t *f);
bool parse_resize_handle(char *s, resize_handle_t *h);
bool parse_modifier_mask(char *s, uint16_t *m);
bool parse_button_index(char *s, int8_t *b);
bool parse_pointer_action(char *s, pointer_action_t *a);
bool parse_child_polarity(char *s, child_polarity_t *p);
bool parse_tightness(char *s, tightness_t *t);

View file

@ -50,13 +50,12 @@ void pointer_init(void)
void window_grab_buttons(xcb_window_t win)
{
uint8_t buttons[] = {XCB_BUTTON_INDEX_1, XCB_BUTTON_INDEX_2, XCB_BUTTON_INDEX_3};
for (unsigned int i = 0; i < LENGTH(buttons); i++) {
if (click_to_focus) {
window_grab_button(win, buttons[i], XCB_NONE);
for (unsigned int i = 0; i < LENGTH(BUTTONS); i++) {
if (click_to_focus == XCB_BUTTON_INDEX_ANY || click_to_focus == BUTTONS[i]) {
window_grab_button(win, BUTTONS[i], XCB_NONE);
}
if (pointer_actions[i] != ACTION_NONE) {
window_grab_button(win, buttons[i], pointer_modifier);
window_grab_button(win, BUTTONS[i], pointer_modifier);
}
}
}

View file

@ -340,6 +340,27 @@ void print_modifier_mask(uint16_t m, FILE *rsp)
}
}
void print_button_index(int8_t b, FILE *rsp)
{
switch (b) {
case XCB_BUTTON_INDEX_ANY:
fprintf(rsp, "any");
break;
case XCB_BUTTON_INDEX_1:
fprintf(rsp, "button1");
break;
case XCB_BUTTON_INDEX_2:
fprintf(rsp, "button2");
break;
case XCB_BUTTON_INDEX_3:
fprintf(rsp, "button3");
break;
case -1:
fprintf(rsp, "none");
break;
}
}
void print_pointer_action(pointer_action_t a, FILE *rsp)
{
switch (a) {

View file

@ -65,6 +65,7 @@ void fprint_monitor_name(monitor_t *m, FILE *rsp);
void fprint_desktop_id(desktop_t *d, FILE *rsp);
void fprint_desktop_name(desktop_t *d, FILE *rsp);
void print_modifier_mask(uint16_t m, FILE *rsp);
void print_button_index(int8_t b, FILE *rsp);
void print_pointer_action(pointer_action_t a, FILE *rsp);
node_select_t make_node_select(void);
desktop_select_t make_desktop_select(void);

View file

@ -54,7 +54,7 @@
#define POINTER_FOLLOWS_MONITOR false
#define IGNORE_EWMH_FOCUS false
#define CENTER_PSEUDO_TILED true
#define CLICK_TO_FOCUS false
#define CLICK_TO_FOCUS -1
#define SWALLOW_FIRST_CLICK false
#define HONOR_SIZE_HINTS false
#define REMOVE_DISABLED_MONITORS false
@ -89,7 +89,7 @@ bool pointer_follows_focus;
bool pointer_follows_monitor;
bool ignore_ewmh_focus;
bool center_pseudo_tiled;
bool click_to_focus;
int8_t click_to_focus;
bool swallow_first_click;
bool honor_size_hints;
bool remove_disabled_monitors;