From 82bc36c6812b24fca27c2ec176e2c2998e4df6d5 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 6 Aug 2015 08:24:14 -0400 Subject: [PATCH] Start to build out window management functions --- sway/handlers.c | 32 ++++++++++++++++++++++++++++++++ sway/handlers.h | 15 +++++++++++++++ sway/layout.c | 10 ++++++++++ sway/layout.h | 14 ++++++++++++++ sway/main.c | 15 ++++++++++++++- 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 sway/handlers.c create mode 100644 sway/handlers.h create mode 100644 sway/layout.c create mode 100644 sway/layout.h diff --git a/sway/handlers.c b/sway/handlers.c new file mode 100644 index 000000000..d6d30b712 --- /dev/null +++ b/sway/handlers.c @@ -0,0 +1,32 @@ +#include +#include +#include +#include "layout.h" +#include "handlers.h" + +bool handle_output_created(wlc_handle output) { + return true; +} + +void handle_output_destroyed(wlc_handle output) { +} + +void handle_output_resolution_change(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to) { +} + +bool handle_view_created(wlc_handle view) { + printf("View created, focusing"); + wlc_view_focus(view); + wlc_view_bring_to_front(view); + return true; +} + +void handle_view_destroyed(wlc_handle view) { + printf("View destroyed"); + wlc_view_focus(get_topmost(wlc_view_get_output(view), 0)); + return true; +} + +void handle_view_focus(wlc_handle view, bool focus) { + wlc_view_set_state(view, WLC_BIT_ACTIVATED, focus); +} diff --git a/sway/handlers.h b/sway/handlers.h new file mode 100644 index 000000000..36496fb76 --- /dev/null +++ b/sway/handlers.h @@ -0,0 +1,15 @@ +#ifndef _SWAY_HANDLERS_H +#define _SWAY_HANDLERS_H + +#include +#include + +bool handle_output_created(wlc_handle output); +void handle_output_destroyed(wlc_handle output); +void handle_output_resolution_change(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to); + +bool handle_view_created(wlc_handle view); +void handle_view_destroyed(wlc_handle view); +void handle_view_focus(wlc_handle view, bool focus); + +#endif diff --git a/sway/layout.c b/sway/layout.c new file mode 100644 index 000000000..aeb8167ea --- /dev/null +++ b/sway/layout.c @@ -0,0 +1,10 @@ +#include +#include +#include +#include "layout.h" + +wlc_handle get_topmost(wlc_handle output, size_t offset) { + size_t memb; + const wlc_handle *views = wlc_output_get_views(output, &memb); + return (memb > 0 ? views[(memb - 1 + offset) % memb] : 0); +} diff --git a/sway/layout.h b/sway/layout.h new file mode 100644 index 000000000..a6fb35a7a --- /dev/null +++ b/sway/layout.h @@ -0,0 +1,14 @@ +#ifndef _SWAY_LAYOUT_H +#define _SWAY_LAYOUT_H + +#include +#include "list.h" + +struct sway_container { + wlc_handle output; // May be NULL + list_t children; +}; + +wlc_handle get_topmost(wlc_handle output, size_t offset); + +#endif diff --git a/sway/main.c b/sway/main.c index 9b19a2f0b..303d27762 100644 --- a/sway/main.c +++ b/sway/main.c @@ -3,6 +3,7 @@ #include #include #include "config.h" +#include "handlers.h" struct sway_config *config; @@ -27,7 +28,19 @@ void load_config() { int main(int argc, char **argv) { load_config(); - static struct wlc_interface interface = { }; + static struct wlc_interface interface = { + .output = { + .created = handle_output_created, + .destroyed = handle_output_destroyed, + .resolution = handle_output_resolution_change + }, + .view = { + .created = handle_view_created, + .destroyed = handle_view_destroyed, + .focus = handle_view_focus + } + }; + if (!wlc_init(&interface, argc, argv)) { return 1; }