aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar taiyu <taiyu.len@gmail.com>2015-08-27 20:32:56 -0700
committerLibravatar taiyu <taiyu.len@gmail.com>2015-08-27 20:32:56 -0700
commitda79bd65de159730b1468e466b2c31d46fcc0238 (patch)
tree88907b6f193bf57ea81dc27de588e1f500e49de3
parentMerge pull request #144 from Luminarys/master (diff)
downloadsway-da79bd65de159730b1468e466b2c31d46fcc0238.tar.gz
sway-da79bd65de159730b1468e466b2c31d46fcc0238.tar.zst
sway-da79bd65de159730b1468e466b2c31d46fcc0238.zip
use previous outputs
-rw-r--r--include/container.h1
-rw-r--r--sway/container.c26
2 files changed, 26 insertions, 1 deletions
diff --git a/include/container.h b/include/container.h
index 6c0de104..29f75f45 100644
--- a/include/container.h
+++ b/include/container.h
@@ -94,6 +94,7 @@ swayc_t *swayc_focus_by_layout(swayc_t *container, enum swayc_layouts);
94 94
95 95
96swayc_t *swayc_by_handle(wlc_handle handle); 96swayc_t *swayc_by_handle(wlc_handle handle);
97swayc_t *swayc_by_name(const char *name);
97swayc_t *swayc_active_output(void); 98swayc_t *swayc_active_output(void);
98swayc_t *swayc_active_workspace(void); 99swayc_t *swayc_active_workspace(void);
99swayc_t *swayc_active_workspace_for(swayc_t *view); 100swayc_t *swayc_active_workspace_for(swayc_t *view);
diff --git a/sway/container.c b/sway/container.c
index abbd5504..416b8db8 100644
--- a/sway/container.c
+++ b/sway/container.c
@@ -57,6 +57,19 @@ static void free_swayc(swayc_t *cont) {
57swayc_t *new_output(wlc_handle handle) { 57swayc_t *new_output(wlc_handle handle) {
58 const struct wlc_size *size = wlc_output_get_resolution(handle); 58 const struct wlc_size *size = wlc_output_get_resolution(handle);
59 const char *name = wlc_output_get_name(handle); 59 const char *name = wlc_output_get_name(handle);
60 // Find current outputs to see if this already exists
61 {
62 int i, len = root_container.children->length;
63 for (i = 0; i < len; ++i) {
64 swayc_t *op = root_container.children->items[i];
65 const char *op_name = op->name;
66 if (op_name && name && strcmp(op_name, name) == 0) {
67 sway_log(L_DEBUG, "restoring output %lu:%s", handle, op_name);
68 return op;
69 }
70 }
71 }
72
60 sway_log(L_DEBUG, "Added output %lu:%s", handle, name); 73 sway_log(L_DEBUG, "Added output %lu:%s", handle, name);
61 74
62 struct output_config *oc = NULL; 75 struct output_config *oc = NULL;
@@ -329,7 +342,7 @@ swayc_t *destroy_workspace(swayc_t *workspace) {
329 342
330 // Do not destroy if there are children 343 // Do not destroy if there are children
331 if (workspace->children->length == 0 && workspace->floating->length == 0) { 344 if (workspace->children->length == 0 && workspace->floating->length == 0) {
332 sway_log(L_DEBUG, "'%s'", workspace->name); 345 sway_log(L_DEBUG, "destroying '%s'", workspace->name);
333 swayc_t *parent = workspace->parent; 346 swayc_t *parent = workspace->parent;
334 free_swayc(workspace); 347 free_swayc(workspace);
335 return parent; 348 return parent;
@@ -396,6 +409,17 @@ swayc_t *swayc_by_test(swayc_t *container, bool (*test)(swayc_t *view, void *dat
396 return NULL; 409 return NULL;
397} 410}
398 411
412static bool test_name(swayc_t *view, void *data) {
413 if (!view && !view->name) {
414 return false;
415 }
416 return strcmp(view->name, data) == 0;
417}
418
419swayc_t *swayc_by_name(const char *name) {
420 return swayc_by_test(&root_container, test_name, (void *)name);
421}
422
399swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) { 423swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) {
400 if (!ASSERT_NONNULL(container)) { 424 if (!ASSERT_NONNULL(container)) {
401 return NULL; 425 return NULL;