diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-01-30 23:09:21 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2018-01-30 23:09:21 -0500 |
commit | b28602aa7425cf435150e6008624429737e037d3 (patch) | |
tree | dafe7d23c48457299f33803832f6b89e09a915ce /sway/commands/workspace.c | |
parent | Remove include/sway/old/ (diff) | |
download | sway-b28602aa7425cf435150e6008624429737e037d3.tar.gz sway-b28602aa7425cf435150e6008624429737e037d3.tar.zst sway-b28602aa7425cf435150e6008624429737e037d3.zip |
Implement workspaces
Diffstat (limited to 'sway/commands/workspace.c')
-rw-r--r-- | sway/commands/workspace.c | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c new file mode 100644 index 00000000..12984ed4 --- /dev/null +++ b/sway/commands/workspace.c | |||
@@ -0,0 +1,101 @@ | |||
1 | #define _XOPEN_SOURCE 500 | ||
2 | #include <string.h> | ||
3 | #include <strings.h> | ||
4 | #include "sway/commands.h" | ||
5 | #include "sway/config.h" | ||
6 | #include "sway/input/seat.h" | ||
7 | #include "sway/workspace.h" | ||
8 | #include "list.h" | ||
9 | #include "log.h" | ||
10 | #include "stringop.h" | ||
11 | |||
12 | struct cmd_results *cmd_workspace(int argc, char **argv) { | ||
13 | struct cmd_results *error = NULL; | ||
14 | if ((error = checkarg(argc, "workspace", EXPECTED_AT_LEAST, 1))) { | ||
15 | return error; | ||
16 | } | ||
17 | |||
18 | int output_location = -1; | ||
19 | |||
20 | swayc_t *current_container = config->handler_context.current_container; | ||
21 | swayc_t *old_workspace = NULL, *old_output = NULL; | ||
22 | if (current_container) { | ||
23 | if (current_container->type == C_WORKSPACE) { | ||
24 | old_workspace = current_container; | ||
25 | } else { | ||
26 | old_workspace = swayc_parent_by_type(current_container, C_WORKSPACE); | ||
27 | } | ||
28 | old_output = swayc_parent_by_type(current_container, C_OUTPUT); | ||
29 | } | ||
30 | |||
31 | for (int i = 0; i < argc; ++i) { | ||
32 | if (strcasecmp(argv[i], "output") == 0) { | ||
33 | output_location = i; | ||
34 | break; | ||
35 | } | ||
36 | } | ||
37 | if (output_location >= 0) { | ||
38 | if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, output_location + 2))) { | ||
39 | return error; | ||
40 | } | ||
41 | struct workspace_output *wso = calloc(1, sizeof(struct workspace_output)); | ||
42 | if (!wso) { | ||
43 | return cmd_results_new(CMD_FAILURE, "workspace output", | ||
44 | "Unable to allocate workspace output"); | ||
45 | } | ||
46 | wso->workspace = join_args(argv, argc - 2); | ||
47 | wso->output = strdup(argv[output_location + 1]); | ||
48 | int i = -1; | ||
49 | if ((i = list_seq_find(config->workspace_outputs, workspace_output_cmp_workspace, wso)) != -1) { | ||
50 | struct workspace_output *old = config->workspace_outputs->items[i]; | ||
51 | free(old); // workspaces can only be assigned to a single output | ||
52 | list_del(config->workspace_outputs, i); | ||
53 | } | ||
54 | wlr_log(L_DEBUG, "Assigning workspace %s to output %s", wso->workspace, wso->output); | ||
55 | list_add(config->workspace_outputs, wso); | ||
56 | } else { | ||
57 | if (config->reading || !config->active) { | ||
58 | return cmd_results_new(CMD_DEFER, "workspace", NULL); | ||
59 | } | ||
60 | swayc_t *ws = NULL; | ||
61 | if (strcasecmp(argv[0], "number") == 0) { | ||
62 | if (!(ws = workspace_by_number(argv[1]))) { | ||
63 | char *name = join_args(argv + 1, argc - 1); | ||
64 | ws = workspace_create(name); | ||
65 | free(name); | ||
66 | } | ||
67 | } else if (strcasecmp(argv[0], "next") == 0) { | ||
68 | ws = workspace_next(old_workspace); | ||
69 | } else if (strcasecmp(argv[0], "prev") == 0) { | ||
70 | ws = workspace_prev(old_workspace); | ||
71 | } else if (strcasecmp(argv[0], "next_on_output") == 0) { | ||
72 | ws = workspace_output_next(old_output); | ||
73 | } else if (strcasecmp(argv[0], "prev_on_output") == 0) { | ||
74 | ws = workspace_output_prev(old_output); | ||
75 | } else if (strcasecmp(argv[0], "back_and_forth") == 0) { | ||
76 | // if auto_back_and_forth is enabled, workspace_switch will swap | ||
77 | // the workspaces. If we created prev_workspace here, workspace_switch | ||
78 | // would put us back on original workspace. | ||
79 | if (config->auto_back_and_forth) { | ||
80 | ws = old_workspace; | ||
81 | } else if (prev_workspace_name | ||
82 | && !(ws = workspace_by_name(prev_workspace_name))) { | ||
83 | ws = workspace_create(prev_workspace_name); | ||
84 | } | ||
85 | } else { | ||
86 | char *name = join_args(argv, argc); | ||
87 | if (!(ws = workspace_by_name(name))) { | ||
88 | ws = workspace_create(name); | ||
89 | } | ||
90 | free(name); | ||
91 | } | ||
92 | workspace_switch(ws); | ||
93 | current_container = config->handler_context.seat->focus; | ||
94 | swayc_t *new_output = swayc_parent_by_type(current_container, C_OUTPUT); | ||
95 | |||
96 | if (config->mouse_warping && old_output != new_output) { | ||
97 | // TODO: Warp mouse | ||
98 | } | ||
99 | } | ||
100 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
101 | } | ||