From dd115cece3490a2d1791880cd45fae4b274a123a Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 10 Aug 2015 23:47:14 -0400 Subject: Prevent passing WM keys, improve multihead support --- sway/handlers.c | 35 +++++++++++++++++++---------------- sway/layout.c | 21 +++++++++++++++++++-- sway/workspace.c | 15 +++++++++++---- 3 files changed, 49 insertions(+), 22 deletions(-) diff --git a/sway/handlers.c b/sway/handlers.c index 938dc3fd..f183c418 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -57,24 +57,27 @@ bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers // Lowercase if necessary sym = tolower(sym); - if (state == WLC_KEY_STATE_PRESSED) { - int i; - for (i = 0; i < mode->bindings->length; ++i) { - struct sway_binding *binding = mode->bindings->items[i]; - - if ((modifiers->mods & binding->modifiers) == binding->modifiers) { - bool match = true; - int j; - for (j = 0; j < binding->keys->length; ++j) { - xkb_keysym_t *k = binding->keys->items[j]; - if (sym != *k) { - match = false; - break; - } + int i; + for (i = 0; i < mode->bindings->length; ++i) { + struct sway_binding *binding = mode->bindings->items[i]; + + if ((modifiers->mods & binding->modifiers) == binding->modifiers) { + bool match = true; + int j; + for (j = 0; j < binding->keys->length; ++j) { + xkb_keysym_t *k = binding->keys->items[j]; + if (sym != *k) { + match = false; + break; } + } - if (match) { - cmd_success = handle_command(config, binding->command); + if (match) { + // TODO: --released + if (state == WLC_KEY_STATE_PRESSED) { + cmd_success = !handle_command(config, binding->command); + } else { + cmd_success = true; } } } diff --git a/sway/layout.c b/sway/layout.c index 37f47673..08d1952c 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -4,6 +4,7 @@ #include "list.h" #include "log.h" #include "layout.h" +#include "container.h" #include "workspace.h" swayc_t root_container; @@ -35,10 +36,16 @@ void arrange_windows(swayc_t *container, int width, int height) { height = container->height; } + int x = 0, y = 0; switch (container->type) { case C_ROOT: for (i = 0; i < container->children->length; ++i) { - arrange_windows(container->children->items[i], -1, -1); + swayc_t *child = container->children->items[i]; + sway_log(L_DEBUG, "Arranging output at %d", x); + child->x = x; + child->y = y; + arrange_windows(child, child->width, child->height); + x += child->width; } return; case C_VIEW: @@ -85,7 +92,6 @@ void arrange_windows(swayc_t *container, int width, int height) { total_weight += child->weight; } - int x = 0, y = 0; switch (container->layout) { case L_HORIZ: default: @@ -307,6 +313,13 @@ swayc_t *create_container(swayc_t *parent, wlc_handle handle) { return c; } +void add_output_widths(swayc_t *container, void *_width) { + int *width = _width; + if (container->type == C_OUTPUT) { + *width += container->width; + } +} + void add_output(wlc_handle output) { sway_log(L_DEBUG, "Adding output %d", output); const struct wlc_size* size = wlc_output_get_resolution(output); @@ -317,6 +330,9 @@ void add_output(wlc_handle output) { container->height = size->h; add_child(&root_container, container); + int total_width = 0; + container_map(&root_container, add_output_widths, &total_width); + swayc_t *workspace = create_container(container, -1); workspace->type = C_WORKSPACE; workspace->name = workspace_next_name(); @@ -324,6 +340,7 @@ void add_output(wlc_handle output) { workspace->height = size->h; workspace->layout = L_HORIZ; // TODO: Get default layout from config add_child(container, workspace); + sway_log(L_DEBUG, "Added workspace %s for output %d", workspace->name, output); workspace_switch(workspace); diff --git a/sway/workspace.c b/sway/workspace.c index 01779723..53675c03 100644 --- a/sway/workspace.c +++ b/sway/workspace.c @@ -9,10 +9,18 @@ swayc_t *active_workspace = NULL; +int ws_num = 1; + char *workspace_next_name(void) { - //TODO change this i guess. seems pretty bad - char *name = malloc(sizeof("1")); - return strcpy(name, "1"); + int l = 1; + if (ws_num >= 10) { + l = 2; + } else if (ws_num >= 100) { + l = 3; + } + char *name = malloc(l + 1); + sprintf(name, "%d", ws_num++); + return name; } swayc_t *workspace_create(const char* name) { @@ -45,7 +53,6 @@ bool workspace_destroy(swayc_t *workspace) { sway_log(L_DEBUG, "Workspace: Destroying workspace '%s'", workspace->name); free_swayc(workspace); return true; - } void set_mask(swayc_t *view, void *data) { -- cgit v1.2.3-70-g09d2