sway/output: Create, move code from handlers.c here.

This commit is contained in:
S. Christoffer Eliesen 2015-10-25 01:20:00 +02:00
parent 010368150b
commit c6bb23b7dd
3 changed files with 120 additions and 46 deletions

10
include/output.h Normal file
View file

@ -0,0 +1,10 @@
#ifndef _SWAY_OUTPUT_H
#define _SWAY_OUTPUT_H
#include "container.h"
#include "focus.h"
swayc_t *output_by_name(const char* name);
swayc_t *swayc_adjacent_output(swayc_t *output, enum movement_direction dir);
#endif

View file

@ -13,6 +13,7 @@
#include "stringop.h" #include "stringop.h"
#include "workspace.h" #include "workspace.h"
#include "container.h" #include "container.h"
#include "output.h"
#include "focus.h" #include "focus.h"
#include "input_state.h" #include "input_state.h"
#include "resize.h" #include "resize.h"
@ -364,66 +365,34 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
// don't do the switch if the pointer is in a mode. // don't do the switch if the pointer is in a mode.
if (config->seamless_mouse && !pointer_state.mode && if (config->seamless_mouse && !pointer_state.mode &&
!pointer_state.left.held && !pointer_state.right.held && !pointer_state.scroll.held) { !pointer_state.left.held && !pointer_state.right.held && !pointer_state.scroll.held) {
swayc_t *output = swayc_active_output();
// TODO: This implementation is naïve: We assume all outputs are swayc_t *output = swayc_active_output(), *adjacent = NULL;
// perfectly aligned (ie. only a single output per edge which covers
// the whole edge).
if (origin->x == 0) { // Left edge if (origin->x == 0) { // Left edge
for(int i = 0; i < root_container.children->length; ++i) { if ((adjacent = swayc_adjacent_output(output, MOVE_LEFT))) {
swayc_t *c = root_container.children->items[i]; if (workspace_switch(adjacent)) {
if (c == output || c->type != C_OUTPUT) { new_origin.x = adjacent->width;
continue;
}
if (c->y == output->y && c->x + c->width == output->x) {
sway_log(L_DEBUG, "%s is right of %s", output->name, c->name);
if (workspace_switch(c)) {
new_origin.x = c->width;
}
} }
} }
} else if ((double)origin->x == output->width) { // Right edge } else if ((double)origin->x == output->width) { // Right edge
for(int i = 0; i < root_container.children->length; ++i) { if ((adjacent = swayc_adjacent_output(output, MOVE_RIGHT))) {
swayc_t *c = root_container.children->items[i]; if (workspace_switch(adjacent)) {
if (c == output || c->type != C_OUTPUT) {
continue;
}
if (c->y == output->y && output->x + output->width == c->x) {
sway_log(L_DEBUG, "%s is left of %s", output->name, c->name);
if (workspace_switch(c)) {
new_origin.x = 0; new_origin.x = 0;
} }
} }
} } else if (origin->y == 0) { // Top edge
} if ((adjacent = swayc_adjacent_output(output, MOVE_UP))) {
if (origin->y == 0) { // Top edge if (workspace_switch(adjacent)) {
for(int i = 0; i < root_container.children->length; ++i) { new_origin.y = adjacent->height;
swayc_t *c = root_container.children->items[i];
if (c == output || c->type != C_OUTPUT) {
continue;
}
if (output->x == c->x && c->y + c->height == output->y) {
sway_log(L_DEBUG, "%s is below %s", output->name, c->name);
if (workspace_switch(c)) {
new_origin.y = c->height;
}
} }
} }
} else if ((double)origin->y == output->height) { // Bottom edge } else if ((double)origin->y == output->height) { // Bottom edge
for(int i = 0; i < root_container.children->length; ++i) { if ((adjacent = swayc_adjacent_output(output, MOVE_DOWN))) {
swayc_t *c = root_container.children->items[i]; if (workspace_switch(adjacent)) {
if (c == output || c->type != C_OUTPUT) {
continue;
}
if (output->x == c->x && output->y + output->height == c->y) {
sway_log(L_DEBUG, "%s is above %s", output->name, c->name);
if (workspace_switch(c)) {
new_origin.y = 0; new_origin.y = 0;
} }
} }
} }
} }
}
// Update pointer origin // Update pointer origin
pointer_state.delta.x = origin->x - pointer_state.origin.x; pointer_state.delta.x = origin->x - pointer_state.origin.x;

95
sway/output.c Normal file
View file

@ -0,0 +1,95 @@
#include <strings.h>
#include "output.h"
#include "log.h"
swayc_t *output_by_name(const char* name) {
if (strcasecmp(name, "left") == 0) {
return swayc_adjacent_output(NULL, MOVE_LEFT);
}
else if (strcasecmp(name, "right") == 0) {
return swayc_adjacent_output(NULL, MOVE_RIGHT);
}
else if (strcasecmp(name, "up") == 0) {
return swayc_adjacent_output(NULL, MOVE_UP);
}
else if (strcasecmp(name, "down") == 0) {
return swayc_adjacent_output(NULL, MOVE_DOWN);
}
else {
for(int i = 0; i < root_container.children->length; ++i) {
swayc_t *c = root_container.children->items[i];
if (c->type == C_OUTPUT && strcasecmp(c->name, name) == 0) {
return c;
}
}
}
return NULL;
}
swayc_t *swayc_adjacent_output(swayc_t *output, enum movement_direction dir) {
// TODO: This implementation is naïve: We assume all outputs are
// perfectly aligned (ie. only a single output per edge which covers
// the whole edge).
if (!output) {
output = swayc_active_output();
}
swayc_t *adjacent = NULL;
switch(dir) {
case MOVE_LEFT:
for(int i = 0; i < root_container.children->length; ++i) {
swayc_t *c = root_container.children->items[i];
if (c == output || c->type != C_OUTPUT) {
continue;
}
if (c->y == output->y && c->x + c->width == output->x) {
sway_log(L_DEBUG, "%s is left of current output %s", c->name, output->name);
adjacent = c;
break;
}
}
break;
case MOVE_RIGHT:
for(int i = 0; i < root_container.children->length; ++i) {
swayc_t *c = root_container.children->items[i];
if (c == output || c->type != C_OUTPUT) {
continue;
}
if (c->y == output->y && output->x + output->width == c->x) {
sway_log(L_DEBUG, "%s is right of current output %s", c->name, output->name);
adjacent = c;
break;
}
}
break;
case MOVE_UP:
for(int i = 0; i < root_container.children->length; ++i) {
swayc_t *c = root_container.children->items[i];
if (c == output || c->type != C_OUTPUT) {
continue;
}
if (output->x == c->x && c->y + c->height == output->y) {
sway_log(L_DEBUG, "%s is above current output %s", c->name, output->name);
adjacent = c;
break;
}
}
break;
case MOVE_DOWN:
for(int i = 0; i < root_container.children->length; ++i) {
swayc_t *c = root_container.children->items[i];
if (c == output || c->type != C_OUTPUT) {
continue;
}
if (output->x == c->x && output->y + output->height == c->y) {
sway_log(L_DEBUG, "%s is below current output %s", c->name, output->name);
adjacent = c;
break;
}
}
break;
default:
sway_abort("Function called with invalid argument.");
break;
}
return adjacent;
}