diff options
author | Zandr Martin <zandrmartin@gmail.com> | 2016-09-01 21:39:08 -0500 |
---|---|---|
committer | Zandr Martin <zandrmartin@gmail.com> | 2016-09-01 21:39:08 -0500 |
commit | b374c35758777f98e5ddbe4b0dc43bd7c80f36d7 (patch) | |
tree | 04bb4cfc3da7d2e0de7fbc38db42f65c66d2df4c /sway/commands/workspace.c | |
parent | Merge pull request #874 from yohanesu75/ipc-client-fix (diff) | |
download | sway-b374c35758777f98e5ddbe4b0dc43bd7c80f36d7.tar.gz sway-b374c35758777f98e5ddbe4b0dc43bd7c80f36d7.tar.zst sway-b374c35758777f98e5ddbe4b0dc43bd7c80f36d7.zip |
refactor commands.c
Diffstat (limited to 'sway/commands/workspace.c')
-rw-r--r-- | sway/commands/workspace.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c new file mode 100644 index 00000000..5eaca423 --- /dev/null +++ b/sway/commands/workspace.c | |||
@@ -0,0 +1,78 @@ | |||
1 | #include <string.h> | ||
2 | #include "commands.h" | ||
3 | #include "config.h" | ||
4 | #include "input_state.h" | ||
5 | #include "list.h" | ||
6 | #include "log.h" | ||
7 | #include "workspace.h" | ||
8 | |||
9 | struct cmd_results *cmd_workspace(int argc, char **argv) { | ||
10 | struct cmd_results *error = NULL; | ||
11 | if ((error = checkarg(argc, "workspace", EXPECTED_AT_LEAST, 1))) { | ||
12 | return error; | ||
13 | } | ||
14 | if (argc == 1 || (argc == 2 && strcasecmp(argv[0], "number") == 0) ) { | ||
15 | if (config->reading || !config->active) { | ||
16 | return cmd_results_new(CMD_DEFER, "workspace", NULL); | ||
17 | } | ||
18 | // Handle workspace next/prev | ||
19 | swayc_t *ws = NULL; | ||
20 | if (argc == 2) { | ||
21 | if (!(ws = workspace_by_number(argv[1]))) { | ||
22 | ws = workspace_create(argv[1]); | ||
23 | } | ||
24 | } else if (strcasecmp(argv[0], "next") == 0) { | ||
25 | ws = workspace_next(); | ||
26 | } else if (strcasecmp(argv[0], "prev") == 0) { | ||
27 | ws = workspace_prev(); | ||
28 | } else if (strcasecmp(argv[0], "next_on_output") == 0) { | ||
29 | ws = workspace_output_next(); | ||
30 | } else if (strcasecmp(argv[0], "prev_on_output") == 0) { | ||
31 | ws = workspace_output_prev(); | ||
32 | } else if (strcasecmp(argv[0], "back_and_forth") == 0) { | ||
33 | // if auto_back_and_forth is enabled, workspace_switch will swap | ||
34 | // the workspaces. If we created prev_workspace here, workspace_switch | ||
35 | // would put us back on original workspace. | ||
36 | if (config->auto_back_and_forth) { | ||
37 | ws = swayc_active_workspace(); | ||
38 | } else if (prev_workspace_name && !(ws = workspace_by_name(prev_workspace_name))) { | ||
39 | ws = workspace_create(prev_workspace_name); | ||
40 | } | ||
41 | } else { | ||
42 | if (!(ws = workspace_by_name(argv[0]))) { | ||
43 | ws = workspace_create(argv[0]); | ||
44 | } | ||
45 | } | ||
46 | swayc_t *old_output = swayc_active_output(); | ||
47 | workspace_switch(ws); | ||
48 | swayc_t *new_output = swayc_active_output(); | ||
49 | |||
50 | if (config->mouse_warping && old_output != new_output) { | ||
51 | swayc_t *focused = get_focused_view(ws); | ||
52 | if (focused && focused->type == C_VIEW) { | ||
53 | center_pointer_on(focused); | ||
54 | } | ||
55 | } | ||
56 | } else { | ||
57 | if (strcasecmp(argv[1], "output") == 0) { | ||
58 | if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, 3))) { | ||
59 | return error; | ||
60 | } | ||
61 | struct workspace_output *wso = calloc(1, sizeof(struct workspace_output)); | ||
62 | wso->workspace = strdup(argv[0]); | ||
63 | wso->output = strdup(argv[2]); | ||
64 | int i = -1; | ||
65 | if ((i = list_seq_find(config->workspace_outputs, workspace_output_cmp_workspace, wso)) != -1) { | ||
66 | struct workspace_output *old = config->workspace_outputs->items[i]; | ||
67 | free(old); // workspaces can only be assigned to a single output | ||
68 | list_del(config->workspace_outputs, i); | ||
69 | } | ||
70 | sway_log(L_DEBUG, "Assigning workspace %s to output %s", argv[0], argv[2]); | ||
71 | list_add(config->workspace_outputs, wso); | ||
72 | if (!config->reading) { | ||
73 | // TODO: Move workspace to output. (don't do so when reloading) | ||
74 | } | ||
75 | } | ||
76 | } | ||
77 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
78 | } | ||