aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-08-06 08:40:16 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-08-06 08:40:16 -0400
commitc102f184994638155248991e50a7a8ae5c620c91 (patch)
tree2ee8ed6f0bf7e9a7249ff0a49fe83d8999fd01a1
parentStart to build out window management functions (diff)
downloadsway-c102f184994638155248991e50a7a8ae5c620c91.tar.gz
sway-c102f184994638155248991e50a7a8ae5c620c91.tar.zst
sway-c102f184994638155248991e50a7a8ae5c620c91.zip
Add layout containers for new outputs
-rw-r--r--sway/handlers.c1
-rw-r--r--sway/layout.c38
-rw-r--r--sway/layout.h16
-rw-r--r--sway/main.c2
4 files changed, 55 insertions, 2 deletions
diff --git a/sway/handlers.c b/sway/handlers.c
index d6d30b71..9bf3f964 100644
--- a/sway/handlers.c
+++ b/sway/handlers.c
@@ -5,6 +5,7 @@
5#include "handlers.h" 5#include "handlers.h"
6 6
7bool handle_output_created(wlc_handle output) { 7bool handle_output_created(wlc_handle output) {
8 add_output(output);
8 return true; 9 return true;
9} 10}
10 11
diff --git a/sway/layout.c b/sway/layout.c
index aeb8167e..e61094e2 100644
--- a/sway/layout.c
+++ b/sway/layout.c
@@ -1,8 +1,46 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <stdbool.h> 2#include <stdbool.h>
3#include <wlc/wlc.h> 3#include <wlc/wlc.h>
4#include "list.h"
4#include "layout.h" 5#include "layout.h"
5 6
7list_t *outputs;
8
9void init_layout() {
10 outputs = create_list();
11}
12
13struct sway_container *get_container(wlc_handle output, int *index) {
14 int i;
15 for (i = 0; i < outputs->length; ++i) {
16 struct sway_container *c = outputs->items[i];
17 if (c->output == output) {
18 return c;
19 }
20 }
21 return NULL;
22}
23
24void add_output(wlc_handle output) {
25 struct sway_container *container = malloc(sizeof(struct sway_container));
26 // TODO: Get default layout from config
27 container->output = output;
28 container->children = create_list();
29 container->layout = LAYOUT_TILE_HORIZ;
30 list_add(outputs, container);
31}
32
33void destroy_output(wlc_handle output) {
34 int index;
35 struct sway_container *c = get_container(output, &index);
36 // TODO: Move all windows in this output somewhere else?
37 // I don't think this will ever be called unless we destroy the output ourselves
38 if (!c) {
39 return;
40 }
41 list_del(outputs, index);
42}
43
6wlc_handle get_topmost(wlc_handle output, size_t offset) { 44wlc_handle get_topmost(wlc_handle output, size_t offset) {
7 size_t memb; 45 size_t memb;
8 const wlc_handle *views = wlc_output_get_views(output, &memb); 46 const wlc_handle *views = wlc_output_get_views(output, &memb);
diff --git a/sway/layout.h b/sway/layout.h
index a6fb35a7..24d214d8 100644
--- a/sway/layout.h
+++ b/sway/layout.h
@@ -4,11 +4,23 @@
4#include <wlc/wlc.h> 4#include <wlc/wlc.h>
5#include "list.h" 5#include "list.h"
6 6
7typedef enum {
8 LAYOUT_TILE_HORIZ,
9 LAYOUT_TILE_VERT,
10 LAYOUT_TABBED,
11 LAYOUT_STACKED
12} container_layout_t;
13
7struct sway_container { 14struct sway_container {
8 wlc_handle output; // May be NULL 15 wlc_handle output;
9 list_t children; 16 list_t *children;
17 container_layout_t layout;
10}; 18};
11 19
20extern list_t *outputs;
21
22void init_layout();
23void add_output(wlc_handle output);
12wlc_handle get_topmost(wlc_handle output, size_t offset); 24wlc_handle get_topmost(wlc_handle output, size_t offset);
13 25
14#endif 26#endif
diff --git a/sway/main.c b/sway/main.c
index 303d2776..3a6c3f9d 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -2,6 +2,7 @@
2#include <stdlib.h> 2#include <stdlib.h>
3#include <stdbool.h> 3#include <stdbool.h>
4#include <wlc/wlc.h> 4#include <wlc/wlc.h>
5#include "layout.h"
5#include "config.h" 6#include "config.h"
6#include "handlers.h" 7#include "handlers.h"
7 8
@@ -27,6 +28,7 @@ void load_config() {
27 28
28int main(int argc, char **argv) { 29int main(int argc, char **argv) {
29 load_config(); 30 load_config();
31 init_layout();
30 32
31 static struct wlc_interface interface = { 33 static struct wlc_interface interface = {
32 .output = { 34 .output = {