aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-08-06 08:24:14 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-08-06 08:24:14 -0400
commit82bc36c6812b24fca27c2ec176e2c2998e4df6d5 (patch)
treee43f61300ecb8f868bf9e40e43bdbd60bf02ecfb
parentClean up config loading and launch wayland (diff)
downloadsway-82bc36c6812b24fca27c2ec176e2c2998e4df6d5.tar.gz
sway-82bc36c6812b24fca27c2ec176e2c2998e4df6d5.tar.zst
sway-82bc36c6812b24fca27c2ec176e2c2998e4df6d5.zip
Start to build out window management functions
-rw-r--r--sway/handlers.c32
-rw-r--r--sway/handlers.h15
-rw-r--r--sway/layout.c10
-rw-r--r--sway/layout.h14
-rw-r--r--sway/main.c15
5 files changed, 85 insertions, 1 deletions
diff --git a/sway/handlers.c b/sway/handlers.c
new file mode 100644
index 00000000..d6d30b71
--- /dev/null
+++ b/sway/handlers.c
@@ -0,0 +1,32 @@
1#include <stdlib.h>
2#include <stdbool.h>
3#include <wlc/wlc.h>
4#include "layout.h"
5#include "handlers.h"
6
7bool handle_output_created(wlc_handle output) {
8 return true;
9}
10
11void handle_output_destroyed(wlc_handle output) {
12}
13
14void handle_output_resolution_change(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to) {
15}
16
17bool handle_view_created(wlc_handle view) {
18 printf("View created, focusing");
19 wlc_view_focus(view);
20 wlc_view_bring_to_front(view);
21 return true;
22}
23
24void handle_view_destroyed(wlc_handle view) {
25 printf("View destroyed");
26 wlc_view_focus(get_topmost(wlc_view_get_output(view), 0));
27 return true;
28}
29
30void handle_view_focus(wlc_handle view, bool focus) {
31 wlc_view_set_state(view, WLC_BIT_ACTIVATED, focus);
32}
diff --git a/sway/handlers.h b/sway/handlers.h
new file mode 100644
index 00000000..36496fb7
--- /dev/null
+++ b/sway/handlers.h
@@ -0,0 +1,15 @@
1#ifndef _SWAY_HANDLERS_H
2#define _SWAY_HANDLERS_H
3
4#include <stdbool.h>
5#include <wlc/wlc.h>
6
7bool handle_output_created(wlc_handle output);
8void handle_output_destroyed(wlc_handle output);
9void handle_output_resolution_change(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to);
10
11bool handle_view_created(wlc_handle view);
12void handle_view_destroyed(wlc_handle view);
13void handle_view_focus(wlc_handle view, bool focus);
14
15#endif
diff --git a/sway/layout.c b/sway/layout.c
new file mode 100644
index 00000000..aeb8167e
--- /dev/null
+++ b/sway/layout.c
@@ -0,0 +1,10 @@
1#include <stdlib.h>
2#include <stdbool.h>
3#include <wlc/wlc.h>
4#include "layout.h"
5
6wlc_handle get_topmost(wlc_handle output, size_t offset) {
7 size_t memb;
8 const wlc_handle *views = wlc_output_get_views(output, &memb);
9 return (memb > 0 ? views[(memb - 1 + offset) % memb] : 0);
10}
diff --git a/sway/layout.h b/sway/layout.h
new file mode 100644
index 00000000..a6fb35a7
--- /dev/null
+++ b/sway/layout.h
@@ -0,0 +1,14 @@
1#ifndef _SWAY_LAYOUT_H
2#define _SWAY_LAYOUT_H
3
4#include <wlc/wlc.h>
5#include "list.h"
6
7struct sway_container {
8 wlc_handle output; // May be NULL
9 list_t children;
10};
11
12wlc_handle get_topmost(wlc_handle output, size_t offset);
13
14#endif
diff --git a/sway/main.c b/sway/main.c
index 9b19a2f0..303d2776 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -3,6 +3,7 @@
3#include <stdbool.h> 3#include <stdbool.h>
4#include <wlc/wlc.h> 4#include <wlc/wlc.h>
5#include "config.h" 5#include "config.h"
6#include "handlers.h"
6 7
7struct sway_config *config; 8struct sway_config *config;
8 9
@@ -27,7 +28,19 @@ void load_config() {
27int main(int argc, char **argv) { 28int main(int argc, char **argv) {
28 load_config(); 29 load_config();
29 30
30 static struct wlc_interface interface = { }; 31 static struct wlc_interface interface = {
32 .output = {
33 .created = handle_output_created,
34 .destroyed = handle_output_destroyed,
35 .resolution = handle_output_resolution_change
36 },
37 .view = {
38 .created = handle_view_created,
39 .destroyed = handle_view_destroyed,
40 .focus = handle_view_focus
41 }
42 };
43
31 if (!wlc_init(&interface, argc, argv)) { 44 if (!wlc_init(&interface, argc, argv)) {
32 return 1; 45 return 1;
33 } 46 }