bspwm/messages.c

1293 lines
33 KiB
C
Raw Normal View History

/* Copyright (c) 2012, Bastien Dejean
2013-10-08 21:05:56 +02:00
* All rights reserved.
2014-01-19 14:41:37 +01:00
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
2014-01-19 14:41:37 +01:00
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
2014-01-19 14:41:37 +01:00
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
2013-10-08 21:05:56 +02:00
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2013-10-08 21:05:56 +02:00
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
2012-09-27 10:46:04 +02:00
#include <stdio.h>
2012-08-29 12:45:44 +02:00
#include <stdlib.h>
#include <string.h>
2015-12-22 19:25:45 +01:00
#include <stdbool.h>
#include <unistd.h>
#include "bspwm.h"
#include "desktop.h"
#include "monitor.h"
#include "pointer.h"
#include "query.h"
#include "rule.h"
#include "restore.h"
#include "settings.h"
#include "tree.h"
#include "window.h"
2014-02-17 11:55:34 +01:00
#include "common.h"
#include "parse.h"
#include "messages.h"
2012-07-31 14:32:13 +02:00
2014-02-17 11:55:34 +01:00
int handle_message(char *msg, int msg_len, FILE *rsp)
2013-09-21 12:39:59 +02:00
{
int cap = INIT_CAP;
int num = 0;
char **args = malloc(cap * sizeof(char *));
2015-12-22 19:25:45 +01:00
if (args == NULL) {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
}
2013-09-21 12:39:59 +02:00
for (int i = 0, j = 0; i < msg_len; i++) {
if (msg[i] == 0) {
args[num++] = msg + j;
j = i + 1;
}
if (num >= cap) {
cap *= 2;
char **new = realloc(args, cap * sizeof(char *));
if (new == NULL) {
free(args);
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
} else {
args = new;
}
}
}
2013-09-21 12:39:59 +02:00
if (num < 1) {
free(args);
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
}
2013-09-21 12:39:59 +02:00
char **args_orig = args;
2014-02-17 11:55:34 +01:00
int ret = process_message(args, num, rsp);
free(args_orig);
return ret;
2013-09-21 12:39:59 +02:00
}
2014-02-17 11:55:34 +01:00
int process_message(char **args, int num, FILE *rsp)
2013-09-21 12:39:59 +02:00
{
2015-12-22 19:25:45 +01:00
if (streq("node", *args)) {
return cmd_node(++args, --num);
} else if (streq("desktop", *args)) {
return cmd_desktop(++args, --num);
} else if (streq("monitor", *args)) {
return cmd_monitor(++args, --num);
} else if (streq("query", *args)) {
return cmd_query(++args, --num, rsp);
2015-12-22 19:25:45 +01:00
} else if (streq("subscribe", *args)) {
return cmd_subscribe(++args, --num, rsp);
} else if (streq("wm", *args)) {
return cmd_wm(++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)) {
return cmd_config(++args, --num, rsp);
} else if (streq("quit", *args)) {
return cmd_quit(++args, --num);
}
2013-09-21 12:39:59 +02:00
2014-02-17 11:55:34 +01:00
return MSG_UNKNOWN;
2013-09-21 12:39:59 +02:00
}
2015-12-22 19:25:45 +01:00
int cmd_node(char **args, int num)
2012-07-31 14:32:13 +02:00
{
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
2013-07-14 12:24:43 -04:00
coordinates_t ref = {mon, mon->desk, mon->desk->focus};
coordinates_t trg = ref;
if ((*args)[0] != OPT_CHR) {
2015-12-22 19:25:45 +01:00
if (node_from_desc(*args, &ref, &trg)) {
num--, args++;
2015-12-22 19:25:45 +01:00
} else {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
}
}
2015-12-22 19:25:45 +01:00
if (trg.node == NULL) {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
}
bool dirty = false;
while (num > 0) {
if (streq("-f", *args) || streq("--focus", *args)) {
coordinates_t dst = trg;
if (num > 1 && *(args + 1)[0] != OPT_CHR) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (!node_from_desc(*args, &trg, &dst)) {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
}
}
focus_node(dst.monitor, dst.desktop, dst.node);
2015-11-07 12:21:13 +01:00
} else if (streq("-a", *args) || streq("--activate", *args)) {
coordinates_t dst = trg;
if (num > 1 && *(args + 1)[0] != OPT_CHR) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (!node_from_desc(*args, &trg, &dst)) {
2015-11-07 12:21:13 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
}
2015-11-07 12:21:13 +01:00
}
if (dst.desktop == mon->desk) {
return MSG_FAILURE;
}
activate_node(dst.monitor, dst.desktop, dst.node);
} else if (streq("-d", *args) || streq("--to-desktop", *args)) {
num--, args++;
coordinates_t dst;
if (desktop_from_desc(*args, &trg, &dst)) {
if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.desktop->focus)) {
trg.monitor = dst.monitor;
trg.desktop = dst.desktop;
2015-12-22 19:25:45 +01:00
} else {
return MSG_FAILURE;
}
} else {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
}
} else if (streq("-m", *args) || streq("--to-monitor", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
coordinates_t dst;
if (monitor_from_desc(*args, &trg, &dst)) {
if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.monitor->desk, dst.monitor->desk->focus)) {
trg.monitor = dst.monitor;
trg.desktop = dst.monitor->desk;
2015-12-22 19:25:45 +01:00
} else {
return MSG_FAILURE;
}
} else {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
}
2015-12-22 19:25:45 +01:00
} else if (streq("-n", *args) || streq("--to-node", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
coordinates_t dst;
if (node_from_desc(*args, &trg, &dst)) {
if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.node)) {
trg.monitor = dst.monitor;
trg.desktop = dst.desktop;
2015-12-22 19:25:45 +01:00
} else {
return MSG_FAILURE;
}
} else {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
}
} else if (streq("-s", *args) || streq("--swap", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
coordinates_t dst;
if (node_from_desc(*args, &trg, &dst)) {
if (swap_nodes(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.node)) {
trg.monitor = dst.monitor;
trg.desktop = dst.desktop;
2015-12-22 19:25:45 +01:00
} else {
return MSG_FAILURE;
}
} else {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
}
2015-12-22 19:25:45 +01:00
} else if (streq("-l", *args) || streq("--layer", *args)) {
num--, args++;
if (num < 1) {
return MSG_SYNTAX;
}
if (trg.node->client == NULL) {
return MSG_FAILURE;
}
stack_layer_t lyr;
if (parse_stack_layer(*args, &lyr)) {
set_layer(trg.monitor, trg.desktop, trg.node, lyr);
} else {
return MSG_FAILURE;
}
} else if (streq("-t", *args) || streq("--state", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 1) {
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
client_state_t cst;
2015-12-22 19:25:45 +01:00
bool alternate = false;
if ((*args)[0] == '~') {
alternate = true;
(*args)++;
}
if (parse_client_state(*args, &cst)) {
2015-12-22 19:25:45 +01:00
if (trg.node->client == NULL) {
return MSG_FAILURE;
}
if (alternate && trg.node->client->state == cst) {
cst = trg.node->client->last_state;
}
set_state(trg.monitor, trg.desktop, trg.node, cst);
dirty = true;
} else {
return MSG_FAILURE;
}
} else if (streq("-g", *args) || streq("--flag", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
char *key = strtok(*args, EQL_TOK);
char *val = strtok(NULL, EQL_TOK);
alter_state_t a;
bool b;
if (val == NULL) {
a = ALTER_TOGGLE;
} else {
if (parse_bool(val, &b)) {
a = ALTER_SET;
} else {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
}
}
if (streq("locked", key)) {
2015-12-22 19:25:45 +01:00
set_locked(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->locked));
} else if (streq("sticky", key)) {
2015-12-22 19:25:45 +01:00
set_sticky(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->sticky));
} else if (streq("private", key)) {
2015-12-22 19:25:45 +01:00
set_private(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->private));
} else {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
}
2015-12-22 19:25:45 +01:00
} else if (streq("-p", *args) || streq("--presel-dir", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
if (trg.node->vacant) {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
}
if (streq("cancel", *args)) {
2015-12-22 19:25:45 +01:00
cancel_presel(trg.monitor, trg.desktop, trg.node);
} else {
2015-12-22 19:25:45 +01:00
bool alternate = false;
if ((*args)[0] == '~') {
alternate = true;
(*args)++;
}
direction_t dir;
if (parse_direction(*args, &dir)) {
2015-12-22 19:25:45 +01:00
if (alternate && trg.node->presel != NULL && trg.node->presel->split_dir == dir) {
cancel_presel(trg.monitor, trg.desktop, trg.node);
} else {
presel_dir(trg.monitor, trg.desktop, trg.node, dir);
draw_presel_feedback(trg.monitor, trg.desktop, trg.node);
}
} else {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
}
}
2015-12-22 19:25:45 +01:00
} else if (streq("-o", *args) || streq("--presel-ratio", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
if (trg.node->vacant) {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
}
double rat;
if (sscanf(*args, "%lf", &rat) != 1 || rat <= 0 || rat >= 1) {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
} else {
presel_ratio(trg.monitor, trg.desktop, trg.node, rat);
draw_presel_feedback(trg.monitor, trg.desktop, trg.node);
}
} else if (streq("-r", *args) || streq("--ratio", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 1) {
return MSG_SYNTAX;
}
if ((*args)[0] == '+' || (*args)[0] == '-') {
int pix;
if (sscanf(*args, "%i", &pix) == 1) {
2015-12-22 19:25:45 +01:00
int max = (trg.node->split_type == TYPE_HORIZONTAL ? trg.node->rectangle.height : trg.node->rectangle.width);
double rat = ((max * trg.node->split_ratio) + pix) / max;
if (rat > 0 && rat < 1) {
trg.node->split_ratio = rat;
} else {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
}
} else {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
}
} else {
double rat;
2015-12-22 19:25:45 +01:00
if (sscanf(*args, "%lf", &rat) == 1 && rat > 0 && rat < 1) {
trg.node->split_ratio = rat;
} else {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
}
}
dirty = true;
2015-12-22 19:25:45 +01:00
} else if (streq("-F", *args) || streq("--flip", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
flip_t flp;
if (parse_flip(*args, &flp)) {
flip_tree(trg.node, flp);
dirty = true;
} else {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
}
2015-12-22 19:25:45 +01:00
} else if (streq("-R", *args) || streq("--rotate", *args)) {
num--, args++;
if (num < 1) {
return MSG_SYNTAX;
}
2015-12-22 19:25:45 +01:00
int deg;
if (parse_degree(*args, &deg)) {
rotate_tree(trg.node, deg);
dirty = true;
} else {
return MSG_FAILURE;
}
2015-12-22 19:25:45 +01:00
} else if (streq("-E", *args) || streq("--equalize", *args)) {
equalize_tree(trg.node);
dirty = true;
} else if (streq("-B", *args) || streq("--balance", *args)) {
balance_tree(trg.node);
dirty = true;
} else if (streq("-C", *args) || streq("--circulate", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
circulate_dir_t cir;
if (parse_circulate_direction(*args, &cir)) {
circulate_leaves(trg.monitor, trg.desktop, trg.node, cir);
dirty = true;
} else {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
}
} else if (streq("-c", *args) || streq("--close", *args)) {
2015-12-22 19:25:45 +01:00
if (num > 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
if (locked_count(trg.node) > 0) {
return MSG_FAILURE;
}
window_close(trg.node);
} else if (streq("-k", *args) || streq("--kill", *args)) {
2015-12-22 19:25:45 +01:00
if (num > 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
window_kill(trg.monitor, trg.desktop, trg.node);
dirty = true;
} else {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
}
2013-10-05 22:32:40 +02:00
num--, args++;
}
2015-12-22 19:25:45 +01:00
if (dirty) {
arrange(trg.monitor, trg.desktop);
2015-12-22 19:25:45 +01:00
}
2014-02-17 11:55:34 +01:00
return MSG_SUCCESS;
}
2014-02-17 11:55:34 +01:00
int cmd_desktop(char **args, int num)
{
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
2013-07-14 12:24:43 -04:00
coordinates_t ref = {mon, mon->desk, NULL};
coordinates_t trg = ref;
if ((*args)[0] != OPT_CHR) {
2015-12-22 19:25:45 +01:00
if (desktop_from_desc(*args, &ref, &trg)) {
num--, args++;
2015-12-22 19:25:45 +01:00
} else {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
}
}
bool dirty = false;
while (num > 0) {
if (streq("-f", *args) || streq("--focus", *args)) {
coordinates_t dst = trg;
if (num > 1 && *(args + 1)[0] != OPT_CHR) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (!desktop_from_desc(*args, &trg, &dst)) {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
}
}
focus_node(dst.monitor, dst.desktop, dst.desktop->focus);
2015-12-22 19:25:45 +01:00
} else if (streq("-a", *args) || streq("--activate", *args)) {
coordinates_t dst = trg;
if (num > 1 && *(args + 1)[0] != OPT_CHR) {
num--, args++;
if (!desktop_from_desc(*args, &trg, &dst)) {
return MSG_FAILURE;
}
}
activate_desktop(dst.monitor, dst.desktop);
} else if (streq("-m", *args) || streq("--to-monitor", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
if (trg.monitor->desk_head == trg.monitor->desk_tail) {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
}
coordinates_t dst;
if (monitor_from_desc(*args, &trg, &dst)) {
2015-12-22 19:25:45 +01:00
if (transfer_desktop(trg.monitor, dst.monitor, trg.desktop)) {
trg.monitor = dst.monitor;
} else {
return MSG_FAILURE;
}
} else {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
}
} else if (streq("-s", *args) || streq("--swap", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
coordinates_t dst;
2015-12-22 19:25:45 +01:00
if (desktop_from_desc(*args, &trg, &dst)) {
if (swap_desktops(trg.monitor, trg.desktop, dst.monitor, dst.desktop)) {
trg.monitor = dst.monitor;
} else {
return MSG_FAILURE;
}
} else {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
}
2015-05-26 23:31:19 +02:00
} else if (streq("-b", *args) || streq("--bubble", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 1) {
2015-05-26 23:31:19 +02:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
2015-05-26 23:31:19 +02:00
cycle_dir_t cyc;
if (parse_cycle_direction(*args, &cyc)) {
desktop_t *d = trg.desktop;
if (cyc == CYCLE_PREV) {
if (d->prev == NULL) {
while (d->next != NULL) {
swap_desktops(trg.monitor, d, trg.monitor, d->next);
}
} else {
swap_desktops(trg.monitor, d, trg.monitor, d->prev);
}
} else {
if (d->next == NULL) {
while (d->prev != NULL) {
swap_desktops(trg.monitor, d, trg.monitor, d->prev);
}
} else {
swap_desktops(trg.monitor, d, trg.monitor, d->next);
}
}
} else {
return MSG_FAILURE;
}
} else if (streq("-l", *args) || streq("--layout", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
layout_t lyt;
cycle_dir_t cyc;
2015-12-22 19:25:45 +01:00
if (parse_cycle_direction(*args, &cyc)) {
change_layout(trg.monitor, trg.desktop, (trg.desktop->layout + 1) % 2);
2015-12-22 19:25:45 +01:00
} else if (parse_layout(*args, &lyt)) {
change_layout(trg.monitor, trg.desktop, lyt);
2015-12-22 19:25:45 +01:00
} else {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
}
} else if (streq("-n", *args) || streq("--rename", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
rename_desktop(trg.monitor, trg.desktop, *args);
} else if (streq("-r", *args) || streq("--remove", *args)) {
if (trg.desktop->root == NULL &&
trg.monitor->desk_head != trg.monitor->desk_tail) {
remove_desktop(trg.monitor, trg.desktop);
2014-02-17 11:55:34 +01:00
return MSG_SUCCESS;
} else {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
}
}
num--, args++;
}
2015-12-22 19:25:45 +01:00
if (dirty) {
arrange(trg.monitor, trg.desktop);
2015-12-22 19:25:45 +01:00
}
2014-02-17 11:55:34 +01:00
return MSG_SUCCESS;
}
2014-02-17 11:55:34 +01:00
int cmd_monitor(char **args, int num)
{
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
2013-07-14 12:24:43 -04:00
coordinates_t ref = {mon, NULL, NULL};
coordinates_t trg = ref;
if ((*args)[0] != OPT_CHR) {
2015-12-22 19:25:45 +01:00
if (monitor_from_desc(*args, &ref, &trg)) {
num--, args++;
2015-12-22 19:25:45 +01:00
} else {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
}
}
while (num > 0) {
if (streq("-f", *args) || streq("--focus", *args)) {
coordinates_t dst = trg;
if (num > 1 && *(args + 1)[0] != OPT_CHR) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (!monitor_from_desc(*args, &trg, &dst)) {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
}
}
focus_node(dst.monitor, dst.monitor->desk, dst.monitor->desk->focus);
} else if (streq("-d", *args) || streq("--reset-desktops", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
desktop_t *d = trg.monitor->desk_head;
while (num > 0 && d != NULL) {
rename_desktop(trg.monitor, d, *args);
initialize_desktop(d);
arrange(trg.monitor, d);
d = d->next;
num--, args++;
}
put_status(SBSC_MASK_REPORT);
while (num > 0) {
add_desktop(trg.monitor, make_desktop(*args));
num--, args++;
}
while (d != NULL) {
desktop_t *next = d->next;
2015-12-22 19:25:45 +01:00
if (d == mon->desk) {
focus_node(trg.monitor, d->prev, d->prev->focus);
2015-12-22 19:25:45 +01:00
}
merge_desktops(trg.monitor, d, mon, mon->desk);
remove_desktop(trg.monitor, d);
d = next;
}
} else if (streq("-a", *args) || streq("--add-desktops", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
while (num > 0) {
add_desktop(trg.monitor, make_desktop(*args));
num--, args++;
}
} else if (streq("-r", *args) || streq("--remove-desktops", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
while (num > 0) {
coordinates_t dst;
if (locate_desktop(*args, &dst) && dst.monitor->desk_head != dst.monitor->desk_tail && dst.desktop->root == NULL) {
remove_desktop(dst.monitor, dst.desktop);
show_desktop(dst.monitor->desk);
}
num--, args++;
}
} else if (streq("-o", *args) || streq("--order-desktops", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
desktop_t *d = trg.monitor->desk_head;
while (d != NULL && num > 0) {
desktop_t *next = d->next;
coordinates_t dst;
if (locate_desktop(*args, &dst) && dst.monitor == trg.monitor) {
swap_desktops(trg.monitor, d, dst.monitor, dst.desktop);
2015-12-22 19:25:45 +01:00
if (next == dst.desktop) {
next = d;
2015-12-22 19:25:45 +01:00
}
}
d = next;
num--, args++;
}
} else if (streq("-g", *args) || streq("--rectangle", *args)) {
num--, args++;
if (num < 1) {
return MSG_SYNTAX;
}
xcb_rectangle_t r;
if (parse_rectangle(*args, &r)) {
update_root(trg.monitor, &r);
} else {
return MSG_SYNTAX;
}
} else if (streq("-n", *args) || streq("--rename", *args)) {
num--, args++;
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
}
rename_monitor(trg.monitor, *args);
} else if (streq("-s", *args) || streq("--swap", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
coordinates_t dst;
2015-12-22 19:25:45 +01:00
if (monitor_from_desc(*args, &trg, &dst)) {
swap_monitors(trg.monitor, dst.monitor);
2015-12-22 19:25:45 +01:00
} else {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
}
} else {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
}
num--, args++;
}
2014-02-17 11:55:34 +01:00
return MSG_SUCCESS;
}
2014-02-17 11:55:34 +01:00
int cmd_query(char **args, int num, FILE *rsp)
2013-10-05 22:32:40 +02:00
{
coordinates_t ref = {mon, mon->desk, mon->desk->focus};
coordinates_t trg = {NULL, NULL, NULL};
2015-12-22 19:25:45 +01:00
monitor_select_t *monitor_sel = NULL;
desktop_select_t *desktop_sel = NULL;
node_select_t *node_sel = NULL;
domain_t dom = DOMAIN_TREE;
2015-12-22 19:25:45 +01:00
int d = 0, t = 0, ret = MSG_SUCCESS;
while (num > 0) {
if (streq("-T", *args) || streq("--tree", *args)) {
dom = DOMAIN_TREE, d++;
} else if (streq("-M", *args) || streq("--monitors", *args)) {
dom = DOMAIN_MONITOR, d++;
} else if (streq("-D", *args) || streq("--desktops", *args)) {
dom = DOMAIN_DESKTOP, d++;
2015-12-22 19:25:45 +01:00
} else if (streq("-N", *args) || streq("--nodes", *args)) {
dom = DOMAIN_NODE, d++;
} else if (streq("-m", *args) || streq("--monitor", *args)) {
if (num > 1 && *(args + 1)[0] != OPT_CHR) {
num--, args++;
2015-12-22 19:25:45 +01:00
if ((*args)[0] == '.') {
monitor_sel = malloc(sizeof(monitor_select_t));
*monitor_sel = make_monitor_select();
if (!parse_monitor_modifiers(*args, monitor_sel)) {
ret = MSG_FAILURE;
goto end;
}
} else if (!monitor_from_desc(*args, &ref, &trg)) {
ret = MSG_FAILURE;
goto end;
}
} else {
trg.monitor = ref.monitor;
}
t++;
} else if (streq("-d", *args) || streq("--desktop", *args)) {
if (num > 1 && *(args + 1)[0] != OPT_CHR) {
num--, args++;
2015-12-22 19:25:45 +01:00
if ((*args)[0] == '.') {
desktop_sel = malloc(sizeof(desktop_select_t));
*desktop_sel = make_desktop_select();
if (!parse_desktop_modifiers(*args, desktop_sel)) {
ret = MSG_FAILURE;
goto end;
}
} else if (!desktop_from_desc(*args, &ref, &trg)) {
ret = MSG_FAILURE;
goto end;
}
} else {
trg.monitor = ref.monitor;
trg.desktop = ref.desktop;
}
t++;
2015-12-22 19:25:45 +01:00
} else if (streq("-n", *args) || streq("--node", *args)) {
if (num > 1 && *(args + 1)[0] != OPT_CHR) {
num--, args++;
2015-12-22 19:25:45 +01:00
if ((*args)[0] == '.') {
node_sel = malloc(sizeof(node_select_t));
*node_sel = make_node_select();
if (!parse_node_modifiers(*args, node_sel)) {
ret = MSG_FAILURE;
goto end;
}
} else if (!node_from_desc(*args, &ref, &trg)) {
ret = MSG_FAILURE;
goto end;
}
} else {
trg = ref;
}
t++;
} else {
2015-12-22 19:25:45 +01:00
ret = MSG_SYNTAX;
goto end;
}
num--, args++;
}
if (d != 1 || t > 1) {
2015-12-22 19:25:45 +01:00
ret = MSG_SYNTAX;
goto end;
}
2015-12-22 19:25:45 +01:00
if (dom == DOMAIN_NODE) {
query_node_ids(trg, node_sel, rsp);
} else if (dom == DOMAIN_DESKTOP) {
query_desktop_names(trg, desktop_sel, rsp);
} else if (dom == DOMAIN_MONITOR) {
query_monitor_names(trg, monitor_sel, rsp);
} else {
if (trg.node != NULL) {
query_node(trg.node, rsp);
} else if (trg.desktop != NULL) {
query_desktop(trg.desktop, rsp);
} else if (trg.monitor != NULL) {
query_monitor(trg.monitor, rsp);
} else {
2015-12-22 19:25:45 +01:00
ret = MSG_SYNTAX;
goto end;
}
fprintf(rsp, "\n");
}
2015-12-22 19:25:45 +01:00
end:
free(monitor_sel);
free(desktop_sel);
free(node_sel);
return ret;
}
2014-02-17 11:55:34 +01:00
int cmd_rule(char **args, int num, FILE *rsp)
{
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
while (num > 0) {
if (streq("-a", *args) || streq("--add", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 2) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
rule_t *rule = make_rule();
2015-12-22 19:25:45 +01:00
char *class_name = strtok(*args, COL_TOK);
char *instance_name = strtok(NULL, COL_TOK);
snprintf(rule->class_name, sizeof(rule->class_name), "%s", class_name);
snprintf(rule->instance_name, sizeof(rule->instance_name), "%s", instance_name==NULL?MATCH_ANY:instance_name);
num--, args++;
size_t i = 0;
while (num > 0) {
if (streq("-o", *args) || streq("--one-shot", *args)) {
rule->one_shot = true;
} else {
2015-12-22 19:25:45 +01:00
for (size_t j = 0; i < sizeof(rule->effect) && j < strlen(*args); i++, j++) {
rule->effect[i] = (*args)[j];
2015-12-22 19:25:45 +01:00
}
if (num > 1 && i < sizeof(rule->effect)) {
rule->effect[i++] = ' ';
2015-12-22 19:25:45 +01:00
}
}
num--, args++;
}
rule->effect[MIN(i, sizeof(rule->effect) - 1)] = '\0';
add_rule(rule);
} else if (streq("-r", *args) || streq("--remove", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
int idx;
while (num > 0) {
2015-12-22 19:25:45 +01:00
if (parse_index(*args, &idx)) {
remove_rule_by_index(idx - 1);
2015-12-22 19:25:45 +01:00
} else if (streq("tail", *args)) {
remove_rule(rule_tail);
2015-12-22 19:25:45 +01:00
} else if (streq("head", *args)) {
remove_rule(rule_head);
2015-12-22 19:25:45 +01:00
} else {
remove_rule_by_cause(*args);
2015-12-22 19:25:45 +01:00
}
num--, args++;
}
} else if (streq("-l", *args) || streq("--list", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
list_rules(rsp);
} else {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
}
num--, args++;
}
2014-02-17 11:55:34 +01:00
return MSG_SUCCESS;
}
2014-02-17 11:55:34 +01:00
int cmd_pointer(char **args, int num)
2013-10-05 22:32:40 +02:00
{
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
while (num > 0) {
if (streq("-t", *args) || streq("--track", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 2) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
int x, y;
2015-12-22 19:25:45 +01:00
if (sscanf(*args, "%i", &x) == 1 && sscanf(*(args + 1), "%i", &y) == 1) {
track_pointer(x, y);
2015-12-22 19:25:45 +01:00
} else {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
}
2014-04-19 14:04:06 -04:00
num--, args++;
} else if (streq("-g", *args) || streq("--grab", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
pointer_action_t pac;
2015-12-22 19:25:45 +01:00
if (parse_pointer_action(*args, &pac)) {
grab_pointer(pac);
2015-12-22 19:25:45 +01:00
} else {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
}
} else if (streq("-u", *args) || streq("--ungrab", *args)) {
ungrab_pointer();
} else {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
}
num--, args++;
}
2014-02-17 11:55:34 +01:00
return MSG_SUCCESS;
}
2015-12-22 19:25:45 +01:00
int cmd_wm(char **args, int num, FILE *rsp)
2013-10-05 22:32:40 +02:00
{
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
}
while (num > 0) {
2015-12-22 19:25:45 +01:00
if (streq("-d", *args) || streq("--dump-state", *args)) {
query_tree(rsp);
fprintf(rsp, "\n");
} else if (streq("-l", *args) || streq("--load-state", *args)) {
num--, args++;
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
}
if (!restore_tree(*args)) {
return MSG_FAILURE;
}
2015-12-22 19:25:45 +01:00
} else if (streq("-a", *args) || streq("--add-monitor", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 2) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
}
2015-12-22 19:25:45 +01:00
char *name = *args;
num--, args++;
xcb_rectangle_t r;
if (parse_rectangle(*args, &r)) {
monitor_t *m = make_monitor(&r);
snprintf(m->name, sizeof(m->name), "%s", name);
add_monitor(m);
add_desktop(m, make_desktop(NULL));
} else {
return MSG_SYNTAX;
}
2015-12-22 19:25:45 +01:00
} else if (streq("-r", *args) || streq("--remove-monitor", *args)) {
num--, args++;
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
}
2015-12-22 19:25:45 +01:00
if (mon_head == mon_tail) {
return MSG_FAILURE;
}
2015-12-22 19:25:45 +01:00
monitor_t *m = find_monitor(*args);
if (m != NULL) {
remove_monitor(m);
} else {
2015-12-22 19:25:45 +01:00
return MSG_FAILURE;
}
2015-12-22 19:25:45 +01:00
} else if (streq("-o", *args) || streq("--adopt-orphans", *args)) {
adopt_orphans();
} else if (streq("-g", *args) || streq("--get-status", *args)) {
print_report(rsp);
2015-12-22 19:25:45 +01:00
} else if (streq("-h", *args) || streq("--record-history", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
bool b;
2015-12-22 19:25:45 +01:00
if (parse_bool(*args, &b)) {
record_history = b;
2015-12-22 19:25:45 +01:00
} else {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
} else {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
}
num--, args++;
}
2014-02-17 11:55:34 +01:00
return MSG_SUCCESS;
}
2014-02-17 11:55:34 +01:00
int cmd_config(char **args, int num, FILE *rsp)
2013-10-05 22:32:40 +02:00
{
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
coordinates_t ref = {mon, mon->desk, mon->desk->focus};
coordinates_t trg = {NULL, NULL, NULL};
2015-12-22 19:25:45 +01:00
if ((*args)[0] == OPT_CHR) {
if (streq("-m", *args) || streq("--monitor", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
if (!monitor_from_desc(*args, &ref, &trg)) {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
}
} else if (streq("-d", *args) || streq("--desktop", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
if (!desktop_from_desc(*args, &ref, &trg)) {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
}
} else if (streq("-n", *args) || streq("--node", *args)) {
num--, args++;
2015-12-22 19:25:45 +01:00
if (num < 1) {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
if (!node_from_desc(*args, &ref, &trg)) {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
}
} else {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
}
num--, args++;
}
2015-12-22 19:25:45 +01:00
if (num == 2) {
return set_setting(trg, *args, *(args + 1));
2015-12-22 19:25:45 +01:00
} else if (num == 1) {
return get_setting(trg, *args, rsp);
2015-12-22 19:25:45 +01:00
} else {
2014-02-17 11:55:34 +01:00
return MSG_SYNTAX;
2015-12-22 19:25:45 +01:00
}
}
int cmd_subscribe(char **args, int num, FILE *rsp)
{
int field = 0;
if (num < 1) {
field = SBSC_MASK_REPORT;
} else {
subscriber_mask_t mask;
while (num > 0) {
if (parse_subscriber_mask(*args, &mask)) {
field |= mask;
} else {
return MSG_SYNTAX;
}
num--, args++;
}
}
add_subscriber(rsp, field);
return MSG_SUBSCRIBE;
}
2014-02-17 11:55:34 +01:00
int cmd_quit(char **args, int num)
2013-10-05 22:32:40 +02:00
{
2015-12-22 19:25:45 +01:00
if (num > 0 && sscanf(*args, "%i", &exit_status) != 1) {
return MSG_SYNTAX;
}
running = false;
2014-02-17 11:55:34 +01:00
return MSG_SUCCESS;
}
2014-02-17 11:55:34 +01:00
int set_setting(coordinates_t loc, char *name, char *value)
{
2015-12-22 19:25:45 +01:00
bool colors_changed = false;
#define DESK_WIN_DEF_SET(k, v) \
if (loc.node != NULL) \
loc.node->client->k = v; \
else if (loc.desktop != NULL) \
loc.desktop->k = v; \
else if (loc.monitor != NULL) \
for (desktop_t *d = loc.monitor->desk_head; d != NULL; d = d->next) \
d->k = v; \
else \
k = v;
if (streq("border_width", name)) {
unsigned int bw;
if (sscanf(value, "%u", &bw) != 1)
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
DESK_WIN_DEF_SET(border_width, bw)
#undef DESK_WIN_DEF_SET
#define DESK_DEF_SET(k, v) \
if (loc.desktop != NULL) \
loc.desktop->k = v; \
else if (loc.monitor != NULL) \
return MSG_SYNTAX; \
else \
k = v;
} else if (streq("window_gap", name)) {
int wg;
if (sscanf(value, "%i", &wg) != 1)
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
DESK_DEF_SET(window_gap, wg)
#undef DESK_DEF_SET
#define MON_DESK_SET(k, v) \
if (loc.desktop != NULL) \
loc.desktop->k = v; \
else if (loc.monitor != NULL) \
loc.monitor->k = v; \
else \
for (monitor_t *m = mon_head; m != NULL; m = m->next) \
m->k = v;
} else if (streq("top_padding", name)) {
int tp;
2015-12-22 19:25:45 +01:00
if (sscanf(value, "%i", &tp) != 1) {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
}
MON_DESK_SET(top_padding, tp)
} else if (streq("right_padding", name)) {
int rp;
2015-12-22 19:25:45 +01:00
if (sscanf(value, "%i", &rp) != 1) {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
}
MON_DESK_SET(right_padding, rp)
} else if (streq("bottom_padding", name)) {
int bp;
2015-12-22 19:25:45 +01:00
if (sscanf(value, "%i", &bp) != 1) {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
}
MON_DESK_SET(bottom_padding, bp)
} else if (streq("left_padding", name)) {
int lp;
2015-12-22 19:25:45 +01:00
if (sscanf(value, "%i", &lp) != 1) {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
}
MON_DESK_SET(left_padding, lp)
#undef MON_DESK_SET
#define SET_STR(s) \
} else if (streq(#s, name)) { \
if (snprintf(s, sizeof(s), "%s", value) < 0) \
return MSG_FAILURE;
SET_STR(external_rules_command)
SET_STR(status_prefix)
#undef SET_STR
} else if (streq("split_ratio", name)) {
double r;
2015-12-22 19:25:45 +01:00
if (sscanf(value, "%lf", &r) == 1 && r > 0 && r < 1) {
split_ratio = r;
2015-12-22 19:25:45 +01:00
} else {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
2015-12-22 19:25:45 +01:00
}
2014-02-17 11:55:34 +01:00
return MSG_SUCCESS;
#define SET_COLOR(s) \
} else if (streq(#s, name)) { \
2015-12-22 19:25:45 +01:00
if (!is_hex_color(value)) { \
return MSG_FAILURE; \
} else { \
snprintf(s, sizeof(s), "%s", value); \
colors_changed = true; \
}
SET_COLOR(normal_border_color)
2015-12-22 19:25:45 +01:00
SET_COLOR(active_border_color)
SET_COLOR(focused_border_color)
SET_COLOR(presel_feedback_color)
#undef SET_COLOR
} 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;
2015-12-22 19:25:45 +01:00
if (parse_bool(value, &b)) {
if (b == focus_follows_pointer) {
return MSG_SUCCESS;
}
focus_follows_pointer = b;
uint32_t values[] = {CLIENT_EVENT_MASK | (focus_follows_pointer ? XCB_EVENT_MASK_ENTER_WINDOW : 0)};
for (monitor_t *m = mon_head; m != NULL; m = m->next) {
for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) {
2015-12-22 19:25:45 +01:00
xcb_change_window_attributes(dpy, n->id, XCB_CW_EVENT_MASK, values);
}
}
}
if (focus_follows_pointer) {
for (monitor_t *m = mon_head; m != NULL; m = m->next) {
window_show(m->root);
}
} else {
for (monitor_t *m = mon_head; m != NULL; m = m->next) {
window_hide(m->root);
}
disable_motion_recorder();
}
2014-02-17 11:55:34 +01:00
return MSG_SUCCESS;
} else {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
}
#define SET_BOOL(s) \
} else if (streq(#s, name)) { \
if (!parse_bool(value, &s)) \
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
SET_BOOL(borderless_monocle)
SET_BOOL(gapless_monocle)
SET_BOOL(paddingless_monocle)
2015-12-22 19:25:45 +01:00
SET_BOOL(single_monocle)
SET_BOOL(pointer_follows_focus)
SET_BOOL(pointer_follows_monitor)
SET_BOOL(history_aware_focus)
SET_BOOL(focus_by_distance)
SET_BOOL(ignore_ewmh_focus)
SET_BOOL(center_pseudo_tiled)
#undef SET_BOOL
#define SET_MON_BOOL(s) \
} else if (streq(#s, name)) { \
if (!parse_bool(value, &s)) \
return MSG_FAILURE; \
if (s) \
update_monitors();
SET_MON_BOOL(remove_disabled_monitors)
SET_MON_BOOL(remove_unplugged_monitors)
SET_MON_BOOL(merge_overlapping_monitors)
#undef SET_MON_BOOL
} else {
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
}
2012-08-29 12:45:44 +02:00
2015-12-22 19:25:45 +01:00
for (monitor_t *m = mon_head; m != NULL; m = m->next) {
for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
arrange(m, d);
2015-12-22 19:25:45 +01:00
if (colors_changed) {
update_colors_in(d->root, d, m);
}
}
}
2014-02-17 11:55:34 +01:00
return MSG_SUCCESS;
2012-08-29 12:45:44 +02:00
}
2014-02-17 11:55:34 +01:00
int get_setting(coordinates_t loc, char *name, FILE* rsp)
2012-09-14 11:30:41 +02:00
{
if (streq("split_ratio", name))
2014-02-17 11:55:34 +01:00
fprintf(rsp, "%lf", split_ratio);
else if (streq("window_gap", name))
if (loc.desktop != NULL)
2014-02-17 11:55:34 +01:00
fprintf(rsp, "%i", loc.desktop->window_gap);
else if (loc.monitor != NULL)
return MSG_SYNTAX;
else
fprintf(rsp, "%i", window_gap);
else if (streq("border_width", name))
if (loc.node != NULL)
2014-02-17 11:55:34 +01:00
fprintf(rsp, "%u", loc.node->client->border_width);
else if (loc.desktop != NULL)
2014-02-17 11:55:34 +01:00
fprintf(rsp, "%u", loc.desktop->border_width);
else
fprintf(rsp, "%u", border_width);
else if (streq("external_rules_command", name))
2014-02-17 11:55:34 +01:00
fprintf(rsp, "%s", external_rules_command);
else if (streq("status_prefix", name))
2014-02-17 11:55:34 +01:00
fprintf(rsp, "%s", status_prefix);
else if (streq("initial_polarity", name))
fprintf(rsp, "%s", initial_polarity == FIRST_CHILD ? "first_child" : "second_child");
#define MON_DESK_GET(k) \
else if (streq(#k, name)) \
if (loc.desktop != NULL) \
2014-02-17 11:55:34 +01:00
fprintf(rsp, "%i", loc.desktop->k); \
else if (loc.monitor != NULL) \
2014-02-17 11:55:34 +01:00
fprintf(rsp, "%i", loc.monitor->k); \
else \
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
MON_DESK_GET(top_padding)
MON_DESK_GET(right_padding)
MON_DESK_GET(bottom_padding)
MON_DESK_GET(left_padding)
#undef DESKGET
#define GET_COLOR(s) \
else if (streq(#s, name)) \
2014-02-17 11:55:34 +01:00
fprintf(rsp, "%s", s);
GET_COLOR(normal_border_color)
2015-12-22 19:25:45 +01:00
GET_COLOR(active_border_color)
GET_COLOR(focused_border_color)
GET_COLOR(presel_feedback_color)
#undef GET_COLOR
#define GET_BOOL(s) \
else if (streq(#s, name)) \
fprintf(rsp, "%s", BOOL_STR(s));
GET_BOOL(borderless_monocle)
GET_BOOL(gapless_monocle)
GET_BOOL(paddingless_monocle)
2015-12-22 19:25:45 +01:00
GET_BOOL(single_monocle)
GET_BOOL(focus_follows_pointer)
GET_BOOL(pointer_follows_focus)
GET_BOOL(pointer_follows_monitor)
GET_BOOL(history_aware_focus)
GET_BOOL(focus_by_distance)
GET_BOOL(ignore_ewmh_focus)
GET_BOOL(center_pseudo_tiled)
GET_BOOL(remove_disabled_monitors)
GET_BOOL(remove_unplugged_monitors)
GET_BOOL(merge_overlapping_monitors)
#undef GET_BOOL
else
2014-02-17 11:55:34 +01:00
return MSG_FAILURE;
fprintf(rsp, "\n");
2014-02-17 11:55:34 +01:00
return MSG_SUCCESS;
2012-09-14 11:30:41 +02:00
}