diff options
author | Jose Diez <jose.manuel.diez@gmail.com> | 2015-08-10 22:31:23 +0200 |
---|---|---|
committer | Jose Diez <jose.manuel.diez@gmail.com> | 2015-08-10 22:49:50 +0200 |
commit | 8cc2c6fa7a4b5e8b2d2030033a4bb9f7df45fc42 (patch) | |
tree | d079178cb01d2dd0bbb58792133d64e9cc31d4e7 | |
parent | Merge pull request #10 from taiyu-len/master (diff) | |
download | sway-8cc2c6fa7a4b5e8b2d2030033a4bb9f7df45fc42.tar.gz sway-8cc2c6fa7a4b5e8b2d2030033a4bb9f7df45fc42.tar.zst sway-8cc2c6fa7a4b5e8b2d2030033a4bb9f7df45fc42.zip |
Basic workspace functionality
-rw-r--r-- | sway/commands.c | 19 | ||||
-rw-r--r-- | sway/container.c | 18 | ||||
-rw-r--r-- | sway/container.h | 8 | ||||
-rw-r--r-- | sway/layout.c | 4 | ||||
-rw-r--r-- | sway/workspace.c | 67 | ||||
-rw-r--r-- | sway/workspace.h | 13 |
6 files changed, 128 insertions, 1 deletions
diff --git a/sway/commands.c b/sway/commands.c index 2ce24fa4..94d5a7ff 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include "layout.h" | 10 | #include "layout.h" |
11 | #include "movement.h" | 11 | #include "movement.h" |
12 | #include "log.h" | 12 | #include "log.h" |
13 | #include "workspace.h" | ||
13 | #include "commands.h" | 14 | #include "commands.h" |
14 | 15 | ||
15 | struct modifier_key { | 16 | struct modifier_key { |
@@ -262,6 +263,21 @@ int cmd_fullscreen(struct sway_config *config, int argc, char **argv) { | |||
262 | return 1; | 263 | return 1; |
263 | } | 264 | } |
264 | 265 | ||
266 | int cmd_workspace(struct sway_config *config, int argc, char **argv) { | ||
267 | if (argc != 1) { | ||
268 | sway_log(L_ERROR, "Invalid workspace command (expected 1 arguments, got %d)", argc); | ||
269 | return 1; | ||
270 | } | ||
271 | |||
272 | swayc_t *workspace = workspace_find_by_name(argv[0]); | ||
273 | if (!workspace) { | ||
274 | workspace = workspace_create(argv[0]); | ||
275 | } else sway_log(L_DEBUG, "workspace exists, all ok"); | ||
276 | |||
277 | workspace_switch(workspace); | ||
278 | return 1; | ||
279 | } | ||
280 | |||
265 | /* Keep alphabetized */ | 281 | /* Keep alphabetized */ |
266 | struct cmd_handler handlers[] = { | 282 | struct cmd_handler handlers[] = { |
267 | { "bindsym", cmd_bindsym }, | 283 | { "bindsym", cmd_bindsym }, |
@@ -276,7 +292,8 @@ struct cmd_handler handlers[] = { | |||
276 | { "reload", cmd_reload }, | 292 | { "reload", cmd_reload }, |
277 | { "set", cmd_set }, | 293 | { "set", cmd_set }, |
278 | { "splith", cmd_splith }, | 294 | { "splith", cmd_splith }, |
279 | { "splitv", cmd_splitv } | 295 | { "splitv", cmd_splitv }, |
296 | { "workspace", cmd_workspace } | ||
280 | }; | 297 | }; |
281 | 298 | ||
282 | char **split_directive(char *line, int *argc) { | 299 | char **split_directive(char *line, int *argc) { |
diff --git a/sway/container.c b/sway/container.c new file mode 100644 index 00000000..8ceb6a30 --- /dev/null +++ b/sway/container.c | |||
@@ -0,0 +1,18 @@ | |||
1 | #include "container.h" | ||
2 | #include "layout.h" | ||
3 | |||
4 | void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) { | ||
5 | if (!container->children) { | ||
6 | return NULL; | ||
7 | } | ||
8 | int i; | ||
9 | for (i = 0; i < container->children->length; ++i) { | ||
10 | swayc_t *child = container->children->items[i]; | ||
11 | f(child, data); | ||
12 | |||
13 | if(child->children) | ||
14 | container_map(child, f, data); | ||
15 | } | ||
16 | return NULL; | ||
17 | } | ||
18 | |||
diff --git a/sway/container.h b/sway/container.h new file mode 100644 index 00000000..d853661c --- /dev/null +++ b/sway/container.h | |||
@@ -0,0 +1,8 @@ | |||
1 | #ifndef _SWAY_CONTAINER_H | ||
2 | #define _SWAY_CONTAINER_H | ||
3 | |||
4 | #include "layout.h" | ||
5 | |||
6 | void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *); | ||
7 | |||
8 | #endif | ||
diff --git a/sway/layout.c b/sway/layout.c index 4b156add..28fe33de 100644 --- a/sway/layout.c +++ b/sway/layout.c | |||
@@ -4,6 +4,7 @@ | |||
4 | #include "list.h" | 4 | #include "list.h" |
5 | #include "log.h" | 5 | #include "log.h" |
6 | #include "layout.h" | 6 | #include "layout.h" |
7 | #include "workspace.h" | ||
7 | 8 | ||
8 | swayc_t root_container; | 9 | swayc_t root_container; |
9 | 10 | ||
@@ -314,11 +315,14 @@ void add_output(wlc_handle output) { | |||
314 | 315 | ||
315 | swayc_t *workspace = create_container(container, -1); | 316 | swayc_t *workspace = create_container(container, -1); |
316 | workspace->type = C_WORKSPACE; | 317 | workspace->type = C_WORKSPACE; |
318 | workspace->name = workspace_next_name(); | ||
317 | workspace->width = size->w; // TODO: gaps | 319 | workspace->width = size->w; // TODO: gaps |
318 | workspace->height = size->h; | 320 | workspace->height = size->h; |
319 | workspace->layout = L_HORIZ; // TODO: Get default layout from config | 321 | workspace->layout = L_HORIZ; // TODO: Get default layout from config |
320 | add_child(container, workspace); | 322 | add_child(container, workspace); |
321 | 323 | ||
324 | workspace_switch(workspace); | ||
325 | |||
322 | if (root_container.focused == NULL) { | 326 | if (root_container.focused == NULL) { |
323 | unfocus_all(&root_container); | 327 | unfocus_all(&root_container); |
324 | focus_view(workspace); | 328 | focus_view(workspace); |
diff --git a/sway/workspace.c b/sway/workspace.c new file mode 100644 index 00000000..1c8cef2c --- /dev/null +++ b/sway/workspace.c | |||
@@ -0,0 +1,67 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include <stdbool.h> | ||
3 | #include <wlc/wlc.h> | ||
4 | #include "workspace.h" | ||
5 | #include "layout.h" | ||
6 | #include "list.h" | ||
7 | #include "log.h" | ||
8 | #include "container.h" | ||
9 | |||
10 | swayc_t *active_workspace = NULL; | ||
11 | |||
12 | char *workspace_next_name() { | ||
13 | return "1"; | ||
14 | } | ||
15 | |||
16 | swayc_t *workspace_create(const char* name) { | ||
17 | swayc_t *parent = get_focused_container(&root_container); | ||
18 | while(parent->type != C_OUTPUT) { | ||
19 | parent = parent->parent; | ||
20 | } | ||
21 | |||
22 | swayc_t *workspace = create_container(parent, -1); | ||
23 | workspace->type = C_WORKSPACE; | ||
24 | workspace->name = strdup(name); | ||
25 | workspace->width = parent->width; | ||
26 | workspace->height = parent->height; | ||
27 | workspace->layout = L_HORIZ; // todo: thing | ||
28 | |||
29 | add_child(parent, workspace); | ||
30 | return workspace; | ||
31 | } | ||
32 | |||
33 | bool workspace_by_name(swayc_t *view, void *data) { | ||
34 | return (view->type == C_WORKSPACE) && | ||
35 | (strcasecmp(view->name, (char *) data) == 0); | ||
36 | } | ||
37 | |||
38 | void set_mask(swayc_t *view, void *data) { | ||
39 | uint32_t *p = data; | ||
40 | |||
41 | if(view->type == C_VIEW) { | ||
42 | wlc_view_set_mask(view->handle, *p); | ||
43 | } | ||
44 | } | ||
45 | |||
46 | swayc_t *workspace_find_by_name(const char* name) { | ||
47 | return find_container(&root_container, workspace_by_name, (void *) name); | ||
48 | } | ||
49 | |||
50 | void workspace_switch(swayc_t *workspace) { | ||
51 | if(active_workspace) { | ||
52 | sway_log(L_DEBUG, "workspace: changing from %s to %s", active_workspace->name, workspace->name); | ||
53 | |||
54 | uint32_t mask = 1; | ||
55 | // set all c_views in the old workspace to the invisible mask | ||
56 | container_map(active_workspace, set_mask, &mask); | ||
57 | // and c_views in the new workspace to the visible mask | ||
58 | mask = 2; | ||
59 | container_map(workspace, set_mask, &mask); | ||
60 | |||
61 | wlc_output_set_mask(wlc_get_focused_output(), 2); | ||
62 | unfocus_all(active_workspace); | ||
63 | focus_view(workspace); | ||
64 | } | ||
65 | |||
66 | active_workspace = workspace; | ||
67 | } | ||
diff --git a/sway/workspace.h b/sway/workspace.h new file mode 100644 index 00000000..bc7eed55 --- /dev/null +++ b/sway/workspace.h | |||
@@ -0,0 +1,13 @@ | |||
1 | #ifndef _SWAY_WORKSPACE_H | ||
2 | #define _SWAY_WORKSPACE_H | ||
3 | |||
4 | #include <wlc/wlc.h> | ||
5 | #include "list.h" | ||
6 | #include "layout.h" | ||
7 | |||
8 | char *workspace_next_name(); | ||
9 | swayc_t *workspace_create(const char*); | ||
10 | swayc_t *workspace_find_by_name(const char*); | ||
11 | void workspace_switch(swayc_t*); | ||
12 | |||
13 | #endif | ||