diff options
author | taiyu <taiyu.len@gmail.com> | 2015-08-23 12:34:18 -0700 |
---|---|---|
committer | taiyu <taiyu.len@gmail.com> | 2015-08-23 12:34:18 -0700 |
commit | 51ab3c918030565cefbb82dc8e899f324e6c5a21 (patch) | |
tree | 1a9e633ead0ff50f55987310621dab39531d2305 /sway | |
parent | d72cc925416847adaf2636cea0773ef6d9a46461 (diff) | |
parent | 1ac0c8cd47f734809c20bf6a6a0a7278680ed597 (diff) |
merge
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands.c | 5 | ||||
-rw-r--r-- | sway/container.c | 41 | ||||
-rw-r--r-- | sway/focus.c | 1 | ||||
-rw-r--r-- | sway/handlers.c | 23 | ||||
-rw-r--r-- | sway/input_state.c | 54 | ||||
-rw-r--r-- | sway/layout.c | 81 | ||||
-rw-r--r-- | sway/log.c | 8 | ||||
-rw-r--r-- | sway/main.c | 12 |
8 files changed, 168 insertions, 57 deletions
diff --git a/sway/commands.c b/sway/commands.c index 5de1fb0c..7ee8c558 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -372,8 +372,13 @@ static bool cmd_output(struct sway_config *config, int argc, char **argv) { struct output_config *output = calloc(1, sizeof(struct output_config)); output->x = output->y = output->width = output->height = -1; output->name = strdup(argv[0]); + output->enabled = true; // TODO: atoi doesn't handle invalid numbers + + if (strcasecmp(argv[1], "disable") == 0) { + output->enabled = false; + } int i; for (i = 1; i < argc; ++i) { diff --git a/sway/container.c b/sway/container.c index 5d544934..d4f7c693 100644 --- a/sway/container.c +++ b/sway/container.c @@ -59,7 +59,7 @@ swayc_t *new_output(wlc_handle handle) { const char *name = wlc_output_get_name(handle); sway_log(L_DEBUG, "Added output %lu:%s", handle, name); - struct output_config *oc ; + struct output_config *oc = NULL; int i; for (i = 0; i < config->output_configs->length; ++i) { oc = config->output_configs->items[i]; @@ -70,6 +70,10 @@ swayc_t *new_output(wlc_handle handle) { oc = NULL; } + if (oc && !oc->enabled) { + return NULL; + } + swayc_t *output = new_swayc(C_OUTPUT); if (oc && oc->width != -1 && oc->height != -1) { output->width = oc->width; @@ -83,6 +87,24 @@ swayc_t *new_output(wlc_handle handle) { output->handle = handle; output->name = name ? strdup(name) : NULL; output->gaps = config->gaps_outer + config->gaps_inner / 2; + + // Find position for it + if (oc && oc->x != -1 && oc->y != -1) { + sway_log(L_DEBUG, "Set %s position to %d, %d", name, oc->x, oc->y); + output->x = oc->x; + output->y = oc->y; + } else { + int x = 0; + for (i = 0; i < root_container.children->length; ++i) { + swayc_t *c = root_container.children->items[i]; + if (c->type == C_OUTPUT) { + if (c->width + c->x > x) { + x = c->width + c->x; + } + } + } + output->x = x; + } add_child(&root_container, output); @@ -281,7 +303,8 @@ swayc_t *destroy_workspace(swayc_t *workspace) { return NULL; } - if (workspace->children->length == 0) { + // Do not destroy if there are children + if (workspace->children->length == 0 && workspace->floating->length == 0) { sway_log(L_DEBUG, "%s: '%s'", __func__, workspace->name); swayc_t *parent = workspace->parent; free_swayc(workspace); @@ -448,14 +471,16 @@ bool swayc_is_fullscreen(swayc_t *view) { // Mapping void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) { - if (container && container->children && container->children->length) { + if (container) { int i; - for (i = 0; i < container->children->length; ++i) { - swayc_t *child = container->children->items[i]; - f(child, data); - container_map(child, f, data); + if (container->children) { + for (i = 0; i < container->children->length; ++i) { + swayc_t *child = container->children->items[i]; + f(child, data); + container_map(child, f, data); + } } - if (container->type == C_WORKSPACE) { + if (container->floating) { for (i = 0; i < container->floating->length; ++i) { swayc_t *child = container->floating->items[i]; f(child, data); diff --git a/sway/focus.c b/sway/focus.c index a3e5e77a..e369de30 100644 --- a/sway/focus.c +++ b/sway/focus.c @@ -34,7 +34,6 @@ static void update_focus(swayc_t *c) { mask = 2; container_map(c, set_view_visibility, &mask); wlc_output_set_mask(parent->handle, 2); - c->parent->focused = c; destroy_workspace(ws); } break; diff --git a/sway/handlers.c b/sway/handlers.c index 0bb4f613..27f6d294 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -90,6 +90,10 @@ swayc_t *container_under_pointer(void) { static bool handle_output_created(wlc_handle output) { swayc_t *op = new_output(output); + if (!op) { + return false; + } + // Switch to workspace if we need to if (swayc_active_workspace() == NULL) { swayc_t *ws = op->children->items[0]; @@ -108,6 +112,8 @@ static void handle_output_destroyed(wlc_handle output) { } if (i < list->length) { destroy_output(list->items[i]); + } else { + return; } if (list->length > 0) { // switch to other outputs active workspace @@ -292,22 +298,12 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier struct sway_mode *mode = config->current_mode; - if (sym < 70000 /* bullshit made up number */) { - if (!isalnum(sym) && sym != ' ' && sym != XKB_KEY_Escape && sym != XKB_KEY_Tab) { - // God fucking dammit - return EVENT_PASSTHROUGH; - } - } - - // Lowercase if necessary - sym = tolower(sym); - int i; if (state == WLC_KEY_STATE_PRESSED) { - press_key(sym); + press_key(sym, key); } else { // WLC_KEY_STATE_RELEASED - release_key(sym); + release_key(sym, key); } // TODO: reminder to check conflicts with mod+q+a versus mod+q @@ -319,7 +315,7 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier int j; for (j = 0; j < binding->keys->length; ++j) { xkb_keysym_t *key = binding->keys->items[j]; - if ((match = check_key(*key)) == false) { + if ((match = check_key(*key, 0)) == false) { break; } } @@ -467,7 +463,6 @@ static void handle_wlc_ready(void) { config->active = true; } - struct wlc_interface interface = { .output = { .created = handle_output_created, diff --git a/sway/input_state.c b/sway/input_state.c index acf90d75..e911d9cf 100644 --- a/sway/input_state.c +++ b/sway/input_state.c @@ -1,50 +1,76 @@ #include <string.h> #include <stdbool.h> #include <ctype.h> +#include "log.h" #include "input_state.h" #define KEY_STATE_MAX_LENGTH 64 -static keycode key_state_array[KEY_STATE_MAX_LENGTH]; +struct key_state { + /* + * Aims to store state regardless of modifiers. + * If you press a key, then hold shift, then release the key, we'll + * get two different key syms, but the same key code. This handles + * that scenario and makes sure we can use the right bindings. + */ + uint32_t key_sym; + uint32_t alt_sym; + uint32_t key_code; +}; + +static struct key_state key_state_array[KEY_STATE_MAX_LENGTH]; void input_init(void) { int i; for (i = 0; i < KEY_STATE_MAX_LENGTH; ++i) { - key_state_array[i] = 0; + struct key_state none = { 0, 0, 0 }; + key_state_array[i] = none; } } -static uint8_t find_key(keycode key) { +static uint8_t find_key(uint32_t key_sym, uint32_t key_code, bool update) { int i; for (i = 0; i < KEY_STATE_MAX_LENGTH; ++i) { - if (key_state_array[i] == key) { + if (0 == key_sym && 0 == key_code && key_state_array[i].key_sym == 0) { + break; + } + if (key_state_array[i].key_sym == key_sym + || key_state_array[i].alt_sym == key_sym) { + break; + } + if (update && key_state_array[i].key_code == key_code) { + key_state_array[i].alt_sym = key_sym; break; } } return i; } -bool check_key(keycode key) { - return find_key(key) < KEY_STATE_MAX_LENGTH; +bool check_key(uint32_t key_sym, uint32_t key_code) { + return find_key(key_sym, key_code, false) < KEY_STATE_MAX_LENGTH; } -void press_key(keycode key) { +void press_key(uint32_t key_sym, uint32_t key_code) { + if (key_code == 0) { + return; + } // Check if key exists - if (!check_key(key)) { + if (!check_key(key_sym, key_code)) { // Check that we dont exceed buffer length - int insert = find_key(0); + int insert = find_key(0, 0, true); if (insert < KEY_STATE_MAX_LENGTH) { - key_state_array[insert] = key; + key_state_array[insert].key_sym = key_sym; + key_state_array[insert].key_code = key_code; } } } -void release_key(keycode key) { - uint8_t index = find_key(key); +void release_key(uint32_t key_sym, uint32_t key_code) { + uint8_t index = find_key(key_sym, key_code, true); if (index < KEY_STATE_MAX_LENGTH) { - // shift it over and remove key - key_state_array[index] = 0; + struct key_state none = { 0, 0, 0 }; + key_state_array[index] = none; } } diff --git a/sway/layout.c b/sway/layout.c index 4d738433..bc12b9b1 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -242,21 +242,14 @@ void arrange_windows(swayc_t *container, double width, double height) { for (i = 0; i < container->children->length; ++i) { 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, -1, -1); - // Removed for now because wlc works with relative positions - // Addition can be reconsidered once wlc positions are changed - // x += child->width; + x += child->width; } return; case C_OUTPUT: container->width = width; container->height = height; - // These lines make x/y negative and result in stuff glitching out - // Their addition can be reconsidered once wlc positions are changed - // x -= container->x; - // y -= container->y; + x = 0, y = 0; for (i = 0; i < container->children->length; ++i) { swayc_t *child = container->children->items[i]; child->x = x + container->gaps; @@ -375,19 +368,75 @@ swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir) // Test if we can even make a difference here bool can_move = false; int diff = 0; - if (dir == MOVE_LEFT || dir == MOVE_RIGHT) { - if (parent->layout == L_HORIZ || parent->type == C_ROOT) { + int i; + if (parent->type == C_ROOT) { + // Find the next output + int target = -1, max_x = 0, max_y = 0, self = -1; + sway_log(L_DEBUG, "Moving between outputs"); + + for (i = 0; i < parent->children->length; ++i) { + swayc_t *next = parent->children->items[i]; + if (next == container) { + self = i; + sway_log(L_DEBUG, "self is %p %d", next, self); + continue; + } + if (next->type == C_OUTPUT) { + sway_log(L_DEBUG, "Testing with %p %d (dir %d)", next, i, dir); + // Check if it's more extreme + if (dir == MOVE_RIGHT) { + if (container->x + container->width <= next->x) { + if (target == -1 || next->x < max_x) { + target = i; + max_x = next->x; + } + } + } else if (dir == MOVE_LEFT) { + if (container->x >= next->x + next->width) { + if (target == -1 || max_x < next->x) { + target = i; + max_x = next->x; + } + } + } else if (dir == MOVE_DOWN) { + if (container->y + container->height <= next->y) { + if (target == -1 || next->y < max_y) { + target = i; + max_y = next->y; + } + } + } else if (dir == MOVE_UP) { + if (container->y >= next->y + next->height) { + if (target == -1 || max_y < next->y) { + target = i; + max_y = next->y; + } + } + } + } + } + + if (target == -1) { + can_move = false; + } else { can_move = true; - diff = dir == MOVE_LEFT ? -1 : 1; + diff = target - self; } } else { - if (parent->layout == L_VERT) { - can_move = true; - diff = dir == MOVE_UP ? -1 : 1; + if (dir == MOVE_LEFT || dir == MOVE_RIGHT) { + if (parent->layout == L_HORIZ) { + can_move = true; + diff = dir == MOVE_LEFT ? -1 : 1; + } + } else { + if (parent->layout == L_VERT) { + can_move = true; + diff = dir == MOVE_UP ? -1 : 1; + } } } + if (can_move) { - int i; for (i = 0; i < parent->children->length; ++i) { swayc_t *child = parent->children->items[i]; if (child == container) { @@ -53,7 +53,7 @@ void sway_log(log_importance_t verbosity, const char* format, ...) { c = sizeof(verbosity_colors) / sizeof(char *) - 1; } - if (colored) { + if (colored && isatty(STDERR_FILENO)) { fprintf(stderr, "%s", verbosity_colors[c]); } @@ -62,7 +62,7 @@ void sway_log(log_importance_t verbosity, const char* format, ...) { vfprintf(stderr, format, args); va_end(args); - if (colored) { + if (colored && isatty(STDERR_FILENO)) { fprintf(stderr, "\x1B[0m"); } fprintf(stderr, "\n"); @@ -76,7 +76,7 @@ void sway_log_errno(log_importance_t verbosity, char* format, ...) { c = sizeof(verbosity_colors) / sizeof(char *) - 1; } - if (colored) { + if (colored && isatty(STDERR_FILENO)) { fprintf(stderr, "%s", verbosity_colors[c]); } @@ -90,7 +90,7 @@ void sway_log_errno(log_importance_t verbosity, char* format, ...) { strerror_r(errno, error, sizeof(error)); fprintf(stderr, "%s", error); - if (colored) { + if (colored && isatty(STDERR_FILENO)) { fprintf(stderr, "\x1B[0m"); } fprintf(stderr, "\n"); diff --git a/sway/main.c b/sway/main.c index ffbcdbdf..3f2fcd94 100644 --- a/sway/main.c +++ b/sway/main.c @@ -21,6 +21,16 @@ void sway_terminate(void) { static void sigchld_handle(int signal); +static void wlc_log_handler(enum wlc_log_type type, const char *str) { + if (type == WLC_LOG_ERROR) { + sway_log(L_ERROR, "[wlc] %s", str); + } else if (type == WLC_LOG_WARN) { + sway_log(L_INFO, "[wlc] %s", str); + } else { + sway_log(L_DEBUG, "[wlc] %s", str); + } +} + int main(int argc, char **argv) { static int verbose = 0, debug = 0, validate = 0; @@ -38,6 +48,8 @@ int main(int argc, char **argv) { setenv("WLC_DIM", "0", 0); + wlc_log_set_handler(wlc_log_handler); + /* Changing code earlier than this point requires detailed review */ if (!wlc_init(&interface, argc, argv)) { return 1; |