aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/container.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-01-30 23:09:21 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-01-30 23:09:21 -0500
commitb28602aa7425cf435150e6008624429737e037d3 (patch)
treedafe7d23c48457299f33803832f6b89e09a915ce /sway/tree/container.c
parentRemove include/sway/old/ (diff)
downloadsway-b28602aa7425cf435150e6008624429737e037d3.tar.gz
sway-b28602aa7425cf435150e6008624429737e037d3.tar.zst
sway-b28602aa7425cf435150e6008624429737e037d3.zip
Implement workspaces
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r--sway/tree/container.c41
1 files changed, 38 insertions, 3 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c
index b7b9bc68..48aabd86 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -3,10 +3,13 @@
3#include <stdlib.h> 3#include <stdlib.h>
4#include <string.h> 4#include <string.h>
5#include <strings.h> 5#include <strings.h>
6#include <wayland-server.h>
6#include <wlr/types/wlr_output_layout.h> 7#include <wlr/types/wlr_output_layout.h>
7#include <wlr/types/wlr_wl_shell.h> 8#include <wlr/types/wlr_wl_shell.h>
8#include "sway/config.h" 9#include "sway/config.h"
9#include "sway/container.h" 10#include "sway/container.h"
11#include "sway/input/input-manager.h"
12#include "sway/input/seat.h"
10#include "sway/layout.h" 13#include "sway/layout.h"
11#include "sway/output.h" 14#include "sway/output.h"
12#include "sway/server.h" 15#include "sway/server.h"
@@ -14,6 +17,26 @@
14#include "sway/workspace.h" 17#include "sway/workspace.h"
15#include "log.h" 18#include "log.h"
16 19
20swayc_t *swayc_by_test(swayc_t *container,
21 bool (*test)(swayc_t *view, void *data), void *data) {
22 if (!container->children) {
23 return NULL;
24 }
25 // TODO: floating windows
26 for (int i = 0; i < container->children->length; ++i) {
27 swayc_t *child = container->children->items[i];
28 if (test(child, data)) {
29 return child;
30 } else {
31 swayc_t *res = swayc_by_test(child, test, data);
32 if (res) {
33 return res;
34 }
35 }
36 }
37 return NULL;
38}
39
17void swayc_descendants_of_type(swayc_t *root, enum swayc_types type, 40void swayc_descendants_of_type(swayc_t *root, enum swayc_types type,
18 void (*func)(swayc_t *item, void *data), void *data) { 41 void (*func)(swayc_t *item, void *data), void *data) {
19 for (int i = 0; i < root->children->length; ++i) { 42 for (int i = 0; i < root->children->length; ++i) {
@@ -127,7 +150,19 @@ swayc_t *new_output(struct sway_output *sway_output) {
127 // Create workspace 150 // Create workspace
128 char *ws_name = workspace_next_name(output->name); 151 char *ws_name = workspace_next_name(output->name);
129 wlr_log(L_DEBUG, "Creating default workspace %s", ws_name); 152 wlr_log(L_DEBUG, "Creating default workspace %s", ws_name);
130 new_workspace(output, ws_name); 153 swayc_t *ws = new_workspace(output, ws_name);
154 output->focused = ws;
155 // Set each seat's focus if not already set
156 // TODO FOCUS: this is probably stupid, we shouldn't define focus in two
157 // places. We should probably put the active workspace on the sway_output
158 // struct instead of trying to do focus semantics like this
159 struct sway_seat *seat = NULL;
160 wl_list_for_each(seat, &input_manager->seats, link) {
161 if (!seat->focus) {
162 seat->focus = ws;
163 }
164 }
165
131 free(ws_name); 166 free(ws_name);
132 return output; 167 return output;
133} 168}
@@ -159,8 +194,8 @@ swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view) {
159 } 194 }
160 const char *title = view_get_title(sway_view); 195 const char *title = view_get_title(sway_view);
161 swayc_t *swayc = new_swayc(C_VIEW); 196 swayc_t *swayc = new_swayc(C_VIEW);
162 wlr_log(L_DEBUG, "Adding new view %p:%s to container %p %d", 197 wlr_log(L_DEBUG, "Adding new view %p:%s to container %p %d %s",
163 swayc, title, sibling, sibling ? sibling->type : 0); 198 swayc, title, sibling, sibling ? sibling->type : 0, sibling->name);
164 // Setup values 199 // Setup values
165 swayc->sway_view = sway_view; 200 swayc->sway_view = sway_view;
166 swayc->name = title ? strdup(title) : NULL; 201 swayc->name = title ? strdup(title) : NULL;