aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/mode.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2017-11-18 11:22:02 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2017-11-18 11:22:02 -0500
commit733993a651c71f7e2198d505960d6bbd31e0e107 (patch)
treee51732c5872b624e73355f9e5b3f762101f3cd0d /sway/commands/mode.c
parentInitial (awful) pass on xdg shell support (diff)
downloadsway-733993a651c71f7e2198d505960d6bbd31e0e107.tar.gz
sway-733993a651c71f7e2198d505960d6bbd31e0e107.tar.zst
sway-733993a651c71f7e2198d505960d6bbd31e0e107.zip
Move everything to sway/old/
Diffstat (limited to 'sway/commands/mode.c')
-rw-r--r--sway/commands/mode.c57
1 files changed, 0 insertions, 57 deletions
diff --git a/sway/commands/mode.c b/sway/commands/mode.c
deleted file mode 100644
index d2985c54..00000000
--- a/sway/commands/mode.c
+++ /dev/null
@@ -1,57 +0,0 @@
1#define _XOPEN_SOURCE 500
2#include <stdbool.h>
3#include <string.h>
4#include <strings.h>
5#include "sway/commands.h"
6#include "sway/config.h"
7#include "sway/ipc-server.h"
8#include "list.h"
9#include "log.h"
10
11struct cmd_results *cmd_mode(int argc, char **argv) {
12 struct cmd_results *error = NULL;
13 if ((error = checkarg(argc, "mode", EXPECTED_AT_LEAST, 1))) {
14 return error;
15 }
16
17 const char *mode_name = argv[0];
18 bool mode_make = (argc == 2 && strcmp(argv[1], "{") == 0);
19 if (mode_make) {
20 if (!config->reading)
21 return cmd_results_new(CMD_FAILURE, "mode", "Can only be used in config file.");
22 }
23 struct sway_mode *mode = NULL;
24 // Find mode
25 int i, len = config->modes->length;
26 for (i = 0; i < len; ++i) {
27 struct sway_mode *find = config->modes->items[i];
28 if (strcasecmp(find->name, mode_name) == 0) {
29 mode = find;
30 break;
31 }
32 }
33 // Create mode if it doesn't exist
34 if (!mode && mode_make) {
35 mode = malloc(sizeof(struct sway_mode));
36 if (!mode) {
37 return cmd_results_new(CMD_FAILURE, "mode", "Unable to allocate mode");
38 }
39 mode->name = strdup(mode_name);
40 mode->bindings = create_list();
41 list_add(config->modes, mode);
42 }
43 if (!mode) {
44 error = cmd_results_new(CMD_INVALID, "mode", "Unknown mode `%s'", mode_name);
45 return error;
46 }
47 if ((config->reading && mode_make) || (!config->reading && !mode_make)) {
48 sway_log(L_DEBUG, "Switching to mode `%s'",mode->name);
49 }
50 // Set current mode
51 config->current_mode = mode;
52 if (!mode_make) {
53 // trigger IPC mode event
54 ipc_event_mode(config->current_mode->name);
55 }
56 return cmd_results_new(mode_make ? CMD_BLOCK_MODE : CMD_SUCCESS, NULL, NULL);
57}