2014-10-22 11:53:03 +02:00
|
|
|
/* Copyright (c) 2012, Bastien Dejean
|
2013-10-08 21:05:56 +02:00
|
|
|
* All rights reserved.
|
2014-01-19 14:41:37 +01:00
|
|
|
*
|
2014-01-18 16:30:00 +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
|
|
|
*
|
2014-01-18 16:30:00 +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
|
|
|
*
|
2014-01-18 16:30:00 +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;
|
2014-01-18 16:30:00 +01:00
|
|
|
* 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>
|
2013-10-01 10:48:03 +02:00
|
|
|
#include <string.h>
|
2015-12-22 19:25:45 +01:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <unistd.h>
|
2013-09-19 15:38:22 +02:00
|
|
|
#include "bspwm.h"
|
2013-09-19 15:02:49 +02:00
|
|
|
#include "desktop.h"
|
|
|
|
#include "monitor.h"
|
2013-09-25 18:00:01 +02:00
|
|
|
#include "pointer.h"
|
2013-10-01 10:48:03 +02:00
|
|
|
#include "query.h"
|
2013-12-12 14:38:48 +01:00
|
|
|
#include "rule.h"
|
2013-09-19 15:38:22 +02:00
|
|
|
#include "restore.h"
|
2013-10-01 10:48:03 +02:00
|
|
|
#include "settings.h"
|
|
|
|
#include "tree.h"
|
|
|
|
#include "window.h"
|
2014-02-17 11:55:34 +01:00
|
|
|
#include "common.h"
|
2015-11-22 14:41:00 +01:00
|
|
|
#include "parse.h"
|
2013-09-19 15:38:22 +02:00
|
|
|
#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
|
|
|
{
|
2014-01-18 16:30:00 +01: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
|
|
|
|
2014-01-18 16:30:00 +01: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;
|
2014-01-18 16:30:00 +01:00
|
|
|
} else {
|
|
|
|
args = new;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-09-21 12:39:59 +02:00
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
if (num < 1) {
|
|
|
|
free(args);
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_SYNTAX;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
2013-09-21 12:39:59 +02:00
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
char **args_orig = args;
|
2014-02-17 11:55:34 +01:00
|
|
|
int ret = process_message(args, num, rsp);
|
2014-01-18 16:30:00 +01:00
|
|
|
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);
|
2014-01-18 16:30:00 +01:00
|
|
|
} 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);
|
2014-01-18 16:30:00 +01:00
|
|
|
} 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
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
coordinates_t ref = {mon, mon->desk, mon->desk->focus};
|
|
|
|
coordinates_t trg = ref;
|
2013-07-08 11:42:05 +02:00
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
if ((*args)[0] != OPT_CHR) {
|
2015-12-22 19:25:45 +01:00
|
|
|
if (node_from_desc(*args, &ref, &trg)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
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
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
2013-07-08 11:42:05 +02: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
|
|
|
}
|
2013-07-08 11:42:05 +02:00
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
bool dirty = false;
|
2013-07-08 11:42:05 +02:00
|
|
|
|
2014-01-18 16:30:00 +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 (!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
|
|
|
}
|
2014-01-18 16:30:00 +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;
|
|
|
|
}
|
2015-11-09 15:00:47 +01:00
|
|
|
activate_node(dst.monitor, dst.desktop, dst.node);
|
2014-01-18 16:30:00 +01:00
|
|
|
} 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;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
} else {
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_FAILURE;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
} 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
|
|
|
}
|
2014-01-18 16:30:00 +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;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
} else {
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_FAILURE;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
} else if (streq("-n", *args) || streq("--to-node", *args)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
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
|
|
|
}
|
2014-01-18 16:30:00 +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;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
} else {
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_FAILURE;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
} 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
|
|
|
}
|
2014-01-18 16:30:00 +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;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
} else {
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_FAILURE;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
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;
|
|
|
|
}
|
2015-11-05 14:00:49 +01:00
|
|
|
} else if (streq("-t", *args) || streq("--state", *args)) {
|
|
|
|
num--, args++;
|
2015-12-22 19:25:45 +01:00
|
|
|
if (num < 1) {
|
2015-11-05 14:00:49 +01:00
|
|
|
return MSG_SYNTAX;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2015-11-05 14:00:49 +01:00
|
|
|
client_state_t cst;
|
2015-12-22 19:25:45 +01:00
|
|
|
bool alternate = false;
|
|
|
|
if ((*args)[0] == '~') {
|
|
|
|
alternate = true;
|
|
|
|
(*args)++;
|
|
|
|
}
|
2015-11-05 14:00:49 +01:00
|
|
|
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;
|
|
|
|
}
|
2015-11-05 14:00:49 +01:00
|
|
|
set_state(trg.monitor, trg.desktop, trg.node, cst);
|
|
|
|
dirty = true;
|
|
|
|
} else {
|
|
|
|
return MSG_FAILURE;
|
|
|
|
}
|
|
|
|
} else if (streq("-g", *args) || streq("--flag", *args)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
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
|
|
|
}
|
2014-01-18 16:30:00 +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 {
|
2015-11-05 14:00:49 +01:00
|
|
|
if (parse_bool(val, &b)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
a = ALTER_SET;
|
2015-11-05 14:00:49 +01:00
|
|
|
} else {
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_FAILURE;
|
2015-11-05 14:00:49 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
2015-11-05 14:00:49 +01:00
|
|
|
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));
|
2014-01-18 16:30:00 +01:00
|
|
|
} 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));
|
2014-01-18 16:30:00 +01:00
|
|
|
} 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));
|
2014-01-18 16:30:00 +01:00
|
|
|
} else {
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_FAILURE;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
} else if (streq("-p", *args) || streq("--presel-dir", *args)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
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
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
if (streq("cancel", *args)) {
|
2015-12-22 19:25:45 +01:00
|
|
|
cancel_presel(trg.monitor, trg.desktop, trg.node);
|
2014-01-18 16:30:00 +01:00
|
|
|
} else {
|
2015-12-22 19:25:45 +01:00
|
|
|
bool alternate = false;
|
|
|
|
if ((*args)[0] == '~') {
|
|
|
|
alternate = true;
|
|
|
|
(*args)++;
|
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
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);
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
} else {
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_FAILURE;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
} else if (streq("-o", *args) || streq("--presel-ratio", *args)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
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)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
num--, args++;
|
2015-12-22 19:25:45 +01:00
|
|
|
if (num < 1) {
|
|
|
|
return MSG_SYNTAX;
|
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
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
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
} else {
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_FAILURE;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
} 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
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
dirty = true;
|
2015-12-22 19:25:45 +01:00
|
|
|
} else if (streq("-F", *args) || streq("--flip", *args)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
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;
|
2014-01-18 16:30:00 +01:00
|
|
|
} else {
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_FAILURE;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
} else if (streq("-R", *args) || streq("--rotate", *args)) {
|
2015-10-26 20:56:56 +01:00
|
|
|
num--, args++;
|
|
|
|
if (num < 1) {
|
|
|
|
return MSG_SYNTAX;
|
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
int deg;
|
|
|
|
if (parse_degree(*args, °)) {
|
|
|
|
rotate_tree(trg.node, deg);
|
|
|
|
dirty = true;
|
2015-10-26 20:56:56 +01:00
|
|
|
} 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)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
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);
|
2014-01-18 16:30:00 +01:00
|
|
|
dirty = true;
|
|
|
|
} else {
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_FAILURE;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
} 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;
|
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
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
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
window_kill(trg.monitor, trg.desktop, trg.node);
|
|
|
|
dirty = true;
|
|
|
|
} else {
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_SYNTAX;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
2013-10-05 22:32:40 +02:00
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
num--, args++;
|
|
|
|
}
|
2013-07-08 11:42:05 +02:00
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
if (dirty) {
|
2014-01-18 16:30:00 +01:00
|
|
|
arrange(trg.monitor, trg.desktop);
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2013-07-08 11:42:05 +02:00
|
|
|
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_SUCCESS;
|
2013-07-08 11:42:05 +02:00
|
|
|
}
|
|
|
|
|
2014-02-17 11:55:34 +01:00
|
|
|
int cmd_desktop(char **args, int num)
|
2013-07-08 11:42:05 +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
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
coordinates_t ref = {mon, mon->desk, NULL};
|
|
|
|
coordinates_t trg = ref;
|
2013-07-08 11:42:05 +02:00
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
if ((*args)[0] != OPT_CHR) {
|
2015-12-22 19:25:45 +01:00
|
|
|
if (desktop_from_desc(*args, &ref, &trg)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
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
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
2013-07-08 11:42:05 +02:00
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
bool dirty = false;
|
2013-07-08 11:42:05 +02:00
|
|
|
|
2014-01-18 16:30:00 +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 (!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
|
|
|
}
|
2014-01-18 16:30:00 +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);
|
2014-01-18 16:30:00 +01:00
|
|
|
} 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
|
|
|
}
|
2014-01-18 16:30:00 +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;
|
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
} else {
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_FAILURE;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
} 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
|
|
|
}
|
2014-01-18 16:30:00 +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;
|
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
} 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
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
layout_t lyt;
|
|
|
|
cycle_dir_t cyc;
|
2015-12-22 19:25:45 +01:00
|
|
|
if (parse_cycle_direction(*args, &cyc)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
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)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
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
|
|
|
}
|
2014-01-18 16:30:00 +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
|
|
|
}
|
2015-11-09 15:00:47 +01:00
|
|
|
rename_desktop(trg.monitor, trg.desktop, *args);
|
2014-01-18 16:30:00 +01:00
|
|
|
} 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;
|
2014-01-18 16:30:00 +01:00
|
|
|
} else {
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_FAILURE;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
num--, args++;
|
|
|
|
}
|
2013-07-08 11:42:05 +02:00
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
if (dirty) {
|
2014-01-18 16:30:00 +01:00
|
|
|
arrange(trg.monitor, trg.desktop);
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2013-07-08 11:42:05 +02:00
|
|
|
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_SUCCESS;
|
2013-07-08 11:42:05 +02:00
|
|
|
}
|
|
|
|
|
2014-02-17 11:55:34 +01:00
|
|
|
int cmd_monitor(char **args, int num)
|
2013-07-08 11:42:05 +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
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
coordinates_t ref = {mon, NULL, NULL};
|
|
|
|
coordinates_t trg = ref;
|
2013-07-08 11:42:05 +02:00
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
if ((*args)[0] != OPT_CHR) {
|
2015-12-22 19:25:45 +01:00
|
|
|
if (monitor_from_desc(*args, &ref, &trg)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
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
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
2013-07-08 11:42:05 +02:00
|
|
|
|
2014-01-18 16:30:00 +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
|
|
|
}
|
2014-01-18 16:30:00 +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
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
desktop_t *d = trg.monitor->desk_head;
|
|
|
|
while (num > 0 && d != NULL) {
|
2015-11-09 15:00:47 +01:00
|
|
|
rename_desktop(trg.monitor, d, *args);
|
2014-05-09 20:32:15 +02:00
|
|
|
initialize_desktop(d);
|
|
|
|
arrange(trg.monitor, d);
|
2014-01-18 16:30:00 +01:00
|
|
|
d = d->next;
|
|
|
|
num--, args++;
|
|
|
|
}
|
2015-05-09 21:12:19 +02:00
|
|
|
put_status(SBSC_MASK_REPORT);
|
2014-01-18 16:30:00 +01:00
|
|
|
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) {
|
2014-01-18 16:30:00 +01:00
|
|
|
focus_node(trg.monitor, d->prev, d->prev->focus);
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +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
|
|
|
}
|
2014-01-18 16:30:00 +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
|
|
|
}
|
2014-01-18 16:30:00 +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
|
|
|
}
|
2014-01-18 16:30:00 +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) {
|
2014-01-18 16:30:00 +01:00
|
|
|
next = d;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
d = next;
|
|
|
|
num--, args++;
|
|
|
|
}
|
|
|
|
} else if (streq("-n", *args) || streq("--rename", *args)) {
|
|
|
|
num--, args++;
|
2015-11-09 15:00:47 +01:00
|
|
|
if (num < 1) {
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_SYNTAX;
|
2015-11-09 15:00:47 +01:00
|
|
|
}
|
|
|
|
rename_monitor(trg.monitor, *args);
|
2014-01-18 16:30:00 +01:00
|
|
|
} 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
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
coordinates_t dst;
|
2015-12-22 19:25:45 +01:00
|
|
|
if (monitor_from_desc(*args, &trg, &dst)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
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
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
} else {
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_SYNTAX;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
num--, args++;
|
|
|
|
}
|
2013-07-08 11:42:05 +02:00
|
|
|
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_SUCCESS;
|
2013-07-08 11:42:05 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2014-01-18 16:30:00 +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
|
|
|
monitor_select_t *monitor_sel = NULL;
|
|
|
|
desktop_select_t *desktop_sel = NULL;
|
|
|
|
node_select_t *node_sel = NULL;
|
2014-01-18 16:30:00 +01:00
|
|
|
domain_t dom = DOMAIN_TREE;
|
2015-12-22 19:25:45 +01:00
|
|
|
int d = 0, t = 0, ret = MSG_SUCCESS;
|
2013-07-08 11:42:05 +02:00
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
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++;
|
2014-01-18 16:30:00 +01:00
|
|
|
} 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;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
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;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
t++;
|
2015-12-22 19:25:45 +01:00
|
|
|
} else if (streq("-n", *args) || streq("--node", *args)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
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;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
t++;
|
|
|
|
} else {
|
2015-12-22 19:25:45 +01:00
|
|
|
ret = MSG_SYNTAX;
|
|
|
|
goto end;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
num--, args++;
|
|
|
|
}
|
2013-07-08 11:42:05 +02:00
|
|
|
|
2015-11-22 14:41:00 +01:00
|
|
|
if (d != 1 || t > 1) {
|
2015-12-22 19:25:45 +01:00
|
|
|
ret = MSG_SYNTAX;
|
|
|
|
goto end;
|
2015-11-22 14:41:00 +01:00
|
|
|
}
|
2013-07-08 11:42:05 +02:00
|
|
|
|
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);
|
2015-11-22 14:41:00 +01:00
|
|
|
} 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;
|
2015-11-22 14:41:00 +01:00
|
|
|
}
|
|
|
|
fprintf(rsp, "\n");
|
|
|
|
}
|
2013-07-08 11:42:05 +02:00
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
end:
|
|
|
|
free(monitor_sel);
|
|
|
|
free(desktop_sel);
|
|
|
|
free(node_sel);
|
|
|
|
|
|
|
|
return ret;
|
2013-07-08 11:42:05 +02:00
|
|
|
}
|
|
|
|
|
2014-02-17 11:55:34 +01:00
|
|
|
int cmd_rule(char **args, int num, FILE *rsp)
|
2013-12-12 14:38:48 +01: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
|
|
|
}
|
|
|
|
|
2014-01-18 16:30:00 +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
|
|
|
}
|
2014-01-18 16:30:00 +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);
|
2014-01-18 16:30:00 +01:00
|
|
|
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++) {
|
2014-01-18 16:30:00 +01:00
|
|
|
rule->effect[i] = (*args)[j];
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
if (num > 1 && i < sizeof(rule->effect)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
rule->effect[i++] = ' ';
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
|
2014-01-18 16:30:00 +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
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
int idx;
|
|
|
|
while (num > 0) {
|
2015-12-22 19:25:45 +01:00
|
|
|
if (parse_index(*args, &idx)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
remove_rule_by_index(idx - 1);
|
2015-12-22 19:25:45 +01:00
|
|
|
} else if (streq("tail", *args)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
remove_rule(rule_tail);
|
2015-12-22 19:25:45 +01:00
|
|
|
} else if (streq("head", *args)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
remove_rule(rule_head);
|
2015-12-22 19:25:45 +01:00
|
|
|
} else {
|
2014-01-18 16:30:00 +01:00
|
|
|
remove_rule_by_cause(*args);
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +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);
|
2014-01-18 16:30:00 +01:00
|
|
|
} else {
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_SYNTAX;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
num--, args++;
|
|
|
|
}
|
2013-12-12 14:38:48 +01:00
|
|
|
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_SUCCESS;
|
2013-12-12 14:38:48 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2014-01-18 16:30:00 +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
|
|
|
}
|
2014-01-18 16:30:00 +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) {
|
2014-01-18 16:30:00 +01:00
|
|
|
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++;
|
2014-01-18 16:30:00 +01:00
|
|
|
} 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
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
pointer_action_t pac;
|
2015-12-22 19:25:45 +01:00
|
|
|
if (parse_pointer_action(*args, &pac)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
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
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
} else if (streq("-u", *args) || streq("--ungrab", *args)) {
|
|
|
|
ungrab_pointer();
|
|
|
|
} else {
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_SYNTAX;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
num--, args++;
|
|
|
|
}
|
2013-07-08 11:42:05 +02:00
|
|
|
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_SUCCESS;
|
2013-07-08 11:42:05 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2015-11-22 14:41:00 +01:00
|
|
|
if (num < 1) {
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_SYNTAX;
|
2015-11-22 14:41:00 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
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)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
num--, args++;
|
2015-11-22 14:41:00 +01:00
|
|
|
if (num < 1) {
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_SYNTAX;
|
2015-11-22 14:41:00 +01:00
|
|
|
}
|
|
|
|
if (!restore_tree(*args)) {
|
|
|
|
return MSG_FAILURE;
|
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
} else if (streq("-a", *args) || streq("--add-monitor", *args)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
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-11-22 14:41:00 +01:00
|
|
|
}
|
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-11-22 14:41:00 +01:00
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
} else if (streq("-r", *args) || streq("--remove-monitor", *args)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
num--, args++;
|
2015-11-22 14:41:00 +01:00
|
|
|
if (num < 1) {
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_SYNTAX;
|
2015-11-22 14:41:00 +01:00
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
if (mon_head == mon_tail) {
|
2015-11-22 14:41:00 +01:00
|
|
|
return MSG_FAILURE;
|
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
monitor_t *m = find_monitor(*args);
|
|
|
|
if (m != NULL) {
|
|
|
|
remove_monitor(m);
|
2015-05-09 21:12:19 +02:00
|
|
|
} else {
|
2015-12-22 19:25:45 +01:00
|
|
|
return MSG_FAILURE;
|
2015-05-09 21:12:19 +02:00
|
|
|
}
|
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)) {
|
2015-05-09 21:12:19 +02:00
|
|
|
print_report(rsp);
|
2015-12-22 19:25:45 +01:00
|
|
|
} else if (streq("-h", *args) || streq("--record-history", *args)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
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
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
bool b;
|
2015-12-22 19:25:45 +01:00
|
|
|
if (parse_bool(*args, &b)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
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
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
} else {
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_SYNTAX;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
num--, args++;
|
|
|
|
}
|
2013-07-08 11:42:05 +02:00
|
|
|
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_SUCCESS;
|
2013-07-08 11:42:05 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-01-18 16:30:00 +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
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
if ((*args)[0] == OPT_CHR) {
|
2014-02-09 14:47:27 +01:00
|
|
|
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
|
|
|
}
|
2014-02-09 14:47:27 +01:00
|
|
|
} else if (streq("-d", *args) || streq("--desktop", *args)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
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)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
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
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
} else {
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_SYNTAX;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
num--, args++;
|
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
if (num == 2) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return set_setting(trg, *args, *(args + 1));
|
2015-12-22 19:25:45 +01:00
|
|
|
} else if (num == 1) {
|
2014-01-18 16:30:00 +01:00
|
|
|
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;
|
2013-07-08 11:42:05 +02:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
running = false;
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_SUCCESS;
|
2013-07-08 11:42:05 +02:00
|
|
|
}
|
|
|
|
|
2014-02-17 11:55:34 +01:00
|
|
|
int set_setting(coordinates_t loc, char *name, char *value)
|
2013-07-08 11:42:05 +02:00
|
|
|
{
|
2015-12-22 19:25:45 +01:00
|
|
|
bool colors_changed = false;
|
2015-11-22 14:41:00 +01:00
|
|
|
#define DESK_WIN_DEF_SET(k, v) \
|
2014-02-09 14:47:27 +01:00
|
|
|
if (loc.node != NULL) \
|
|
|
|
loc.node->client->k = v; \
|
|
|
|
else if (loc.desktop != NULL) \
|
2014-01-18 16:30:00 +01:00
|
|
|
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 \
|
2014-05-06 18:24:25 +02:00
|
|
|
k = v;
|
2014-01-18 16:30:00 +01:00
|
|
|
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;
|
2015-11-22 14:41:00 +01:00
|
|
|
DESK_WIN_DEF_SET(border_width, bw)
|
|
|
|
#undef DESK_WIN_DEF_SET
|
|
|
|
#define DESK_DEF_SET(k, v) \
|
2014-02-09 14:47:27 +01:00
|
|
|
if (loc.desktop != NULL) \
|
|
|
|
loc.desktop->k = v; \
|
|
|
|
else if (loc.monitor != NULL) \
|
2015-08-20 16:12:22 -06:00
|
|
|
return MSG_SYNTAX; \
|
2014-02-09 14:47:27 +01:00
|
|
|
else \
|
2014-05-06 18:24:25 +02:00
|
|
|
k = v;
|
2014-01-18 16:30:00 +01:00
|
|
|
} 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;
|
2015-11-22 14:41:00 +01:00
|
|
|
DESK_DEF_SET(window_gap, wg)
|
|
|
|
#undef DESK_DEF_SET
|
|
|
|
#define MON_DESK_SET(k, v) \
|
2014-01-18 16:30:00 +01:00
|
|
|
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
|
|
|
}
|
2015-11-22 14:41:00 +01:00
|
|
|
MON_DESK_SET(top_padding, tp)
|
2014-01-18 16:30:00 +01:00
|
|
|
} 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
|
|
|
}
|
2015-11-22 14:41:00 +01:00
|
|
|
MON_DESK_SET(right_padding, rp)
|
2014-01-18 16:30:00 +01:00
|
|
|
} 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
|
|
|
}
|
2015-11-22 14:41:00 +01:00
|
|
|
MON_DESK_SET(bottom_padding, bp)
|
2014-01-18 16:30:00 +01:00
|
|
|
} 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
|
|
|
}
|
2015-11-22 14:41:00 +01:00
|
|
|
MON_DESK_SET(left_padding, lp)
|
|
|
|
#undef MON_DESK_SET
|
|
|
|
#define SET_STR(s) \
|
2014-01-18 16:30:00 +01:00
|
|
|
} else if (streq(#s, name)) { \
|
2015-06-09 10:07:09 +02:00
|
|
|
if (snprintf(s, sizeof(s), "%s", value) < 0) \
|
|
|
|
return MSG_FAILURE;
|
2015-11-22 14:41:00 +01:00
|
|
|
SET_STR(external_rules_command)
|
|
|
|
SET_STR(status_prefix)
|
|
|
|
#undef SET_STR
|
2014-01-18 16:30:00 +01:00
|
|
|
} 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) {
|
2014-01-18 16:30:00 +01:00
|
|
|
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;
|
2015-11-22 14:41:00 +01:00
|
|
|
#define SET_COLOR(s) \
|
2014-01-18 16:30:00 +01:00
|
|
|
} 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; \
|
|
|
|
}
|
2015-11-22 14:41:00 +01:00
|
|
|
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)
|
2015-11-22 14:41:00 +01:00
|
|
|
#undef SET_COLOR
|
2015-01-06 20:10:09 +01:00
|
|
|
} else if (streq("initial_polarity", name)) {
|
|
|
|
child_polarity_t p;
|
|
|
|
if (parse_child_polarity(value, &p)) {
|
|
|
|
initial_polarity = p;
|
|
|
|
} else {
|
|
|
|
return MSG_FAILURE;
|
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
} 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;
|
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
focus_follows_pointer = b;
|
2015-06-12 22:05:22 +02:00
|
|
|
uint32_t values[] = {CLIENT_EVENT_MASK | (focus_follows_pointer ? XCB_EVENT_MASK_ENTER_WINDOW : 0)};
|
2015-06-09 20:39:00 +02:00
|
|
|
for (monitor_t *m = mon_head; m != NULL; m = m->next) {
|
|
|
|
for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
|
2014-01-18 16:30:00 +01:00
|
|
|
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);
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
2015-06-09 20:39:00 +02:00
|
|
|
}
|
|
|
|
}
|
2015-06-12 22:05:22 +02:00
|
|
|
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;
|
2014-01-18 16:30:00 +01:00
|
|
|
} else {
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_FAILURE;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
2015-11-22 14:41:00 +01:00
|
|
|
#define SET_BOOL(s) \
|
2014-01-18 16:30:00 +01:00
|
|
|
} else if (streq(#s, name)) { \
|
|
|
|
if (!parse_bool(value, &s)) \
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_FAILURE;
|
2015-11-22 14:41:00 +01:00
|
|
|
SET_BOOL(borderless_monocle)
|
|
|
|
SET_BOOL(gapless_monocle)
|
2015-12-22 19:25:45 +01:00
|
|
|
SET_BOOL(single_monocle)
|
2015-11-22 14:41:00 +01:00
|
|
|
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) \
|
2014-09-09 12:23:44 +02:00
|
|
|
} else if (streq(#s, name)) { \
|
|
|
|
if (!parse_bool(value, &s)) \
|
|
|
|
return MSG_FAILURE; \
|
|
|
|
if (s) \
|
|
|
|
update_monitors();
|
2015-11-22 14:41:00 +01:00
|
|
|
SET_MON_BOOL(remove_disabled_monitors)
|
|
|
|
SET_MON_BOOL(remove_unplugged_monitors)
|
|
|
|
SET_MON_BOOL(merge_overlapping_monitors)
|
|
|
|
#undef SET_MON_BOOL
|
2014-01-18 16:30:00 +01:00
|
|
|
} else {
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_FAILURE;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
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) {
|
2014-01-18 16:30:00 +01:00
|
|
|
arrange(m, d);
|
2015-12-22 19:25:45 +01:00
|
|
|
if (colors_changed) {
|
|
|
|
update_colors_in(d->root, d, m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-08 11:42:05 +02:00
|
|
|
|
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
|
|
|
{
|
2014-01-18 16:30:00 +01:00
|
|
|
if (streq("split_ratio", name))
|
2014-02-17 11:55:34 +01:00
|
|
|
fprintf(rsp, "%lf", split_ratio);
|
2014-01-18 16:30:00 +01:00
|
|
|
else if (streq("window_gap", name))
|
2014-05-07 11:09:48 +02:00
|
|
|
if (loc.desktop != NULL)
|
2014-02-17 11:55:34 +01:00
|
|
|
fprintf(rsp, "%i", loc.desktop->window_gap);
|
2015-08-20 16:12:22 -06:00
|
|
|
else if (loc.monitor != NULL)
|
|
|
|
return MSG_SYNTAX;
|
2014-05-07 11:09:48 +02:00
|
|
|
else
|
|
|
|
fprintf(rsp, "%i", window_gap);
|
2014-01-18 16:30:00 +01:00
|
|
|
else if (streq("border_width", name))
|
2014-02-09 14:47:27 +01:00
|
|
|
if (loc.node != NULL)
|
2014-02-17 11:55:34 +01:00
|
|
|
fprintf(rsp, "%u", loc.node->client->border_width);
|
2014-02-09 14:47:27 +01:00
|
|
|
else if (loc.desktop != NULL)
|
2014-02-17 11:55:34 +01:00
|
|
|
fprintf(rsp, "%u", loc.desktop->border_width);
|
2014-02-09 14:47:27 +01:00
|
|
|
else
|
2014-05-07 11:09:48 +02:00
|
|
|
fprintf(rsp, "%u", border_width);
|
2014-01-18 16:30:00 +01:00
|
|
|
else if (streq("external_rules_command", name))
|
2014-02-17 11:55:34 +01:00
|
|
|
fprintf(rsp, "%s", external_rules_command);
|
2014-01-18 16:30:00 +01:00
|
|
|
else if (streq("status_prefix", name))
|
2014-02-17 11:55:34 +01:00
|
|
|
fprintf(rsp, "%s", status_prefix);
|
2015-01-06 20:10:09 +01:00
|
|
|
else if (streq("initial_polarity", name))
|
|
|
|
fprintf(rsp, "%s", initial_polarity == FIRST_CHILD ? "first_child" : "second_child");
|
2015-11-22 14:41:00 +01:00
|
|
|
#define MON_DESK_GET(k) \
|
2014-01-18 16:30:00 +01:00
|
|
|
else if (streq(#k, name)) \
|
|
|
|
if (loc.desktop != NULL) \
|
2014-02-17 11:55:34 +01:00
|
|
|
fprintf(rsp, "%i", loc.desktop->k); \
|
2014-01-18 16:30:00 +01:00
|
|
|
else if (loc.monitor != NULL) \
|
2014-02-17 11:55:34 +01:00
|
|
|
fprintf(rsp, "%i", loc.monitor->k); \
|
2014-01-18 16:30:00 +01:00
|
|
|
else \
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_FAILURE;
|
2015-11-22 14:41:00 +01:00
|
|
|
MON_DESK_GET(top_padding)
|
|
|
|
MON_DESK_GET(right_padding)
|
|
|
|
MON_DESK_GET(bottom_padding)
|
|
|
|
MON_DESK_GET(left_padding)
|
2013-12-25 10:06:02 +01:00
|
|
|
#undef DESKGET
|
2015-11-22 14:41:00 +01:00
|
|
|
#define GET_COLOR(s) \
|
2014-01-18 16:30:00 +01:00
|
|
|
else if (streq(#s, name)) \
|
2014-02-17 11:55:34 +01:00
|
|
|
fprintf(rsp, "%s", s);
|
2015-11-22 14:41:00 +01:00
|
|
|
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)
|
2015-11-22 14:41:00 +01:00
|
|
|
#undef GET_COLOR
|
|
|
|
#define GET_BOOL(s) \
|
2014-01-18 16:30:00 +01:00
|
|
|
else if (streq(#s, name)) \
|
2015-11-22 14:41:00 +01:00
|
|
|
fprintf(rsp, "%s", BOOL_STR(s));
|
|
|
|
GET_BOOL(borderless_monocle)
|
|
|
|
GET_BOOL(gapless_monocle)
|
2015-12-22 19:25:45 +01:00
|
|
|
GET_BOOL(single_monocle)
|
2015-11-22 14:41:00 +01:00
|
|
|
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
|
2014-01-18 16:30:00 +01:00
|
|
|
else
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_FAILURE;
|
2015-08-15 10:55:40 +02:00
|
|
|
fprintf(rsp, "\n");
|
2014-02-17 11:55:34 +01:00
|
|
|
return MSG_SUCCESS;
|
2012-09-14 11:30:41 +02:00
|
|
|
}
|