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 /sway/workspace.c | |
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
Diffstat (limited to 'sway/workspace.c')
-rw-r--r-- | sway/workspace.c | 67 |
1 files changed, 67 insertions, 0 deletions
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 | } | ||