|
|
@ -15,6 +15,7 @@
|
|
|
|
#include "focus.h"
|
|
|
|
#include "focus.h"
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t keys_pressed[32];
|
|
|
|
uint32_t keys_pressed[32];
|
|
|
|
|
|
|
|
int keys_pressed_length = 0;
|
|
|
|
|
|
|
|
|
|
|
|
static struct wlc_origin mouse_origin;
|
|
|
|
static struct wlc_origin mouse_origin;
|
|
|
|
|
|
|
|
|
|
|
@ -23,6 +24,15 @@ static bool dragging = false;
|
|
|
|
static bool m2_held = false;
|
|
|
|
static bool m2_held = false;
|
|
|
|
static bool resizing = false;
|
|
|
|
static bool resizing = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool floating_mod_pressed(void) {
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
while (i < keys_pressed_length) {
|
|
|
|
|
|
|
|
if (keys_pressed[i++] == config->floating_mod)
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool pointer_test(swayc_t *view, void *_origin) {
|
|
|
|
static bool pointer_test(swayc_t *view, void *_origin) {
|
|
|
|
const struct wlc_origin *origin = _origin;
|
|
|
|
const struct wlc_origin *origin = _origin;
|
|
|
|
// Determine the output that the view is under
|
|
|
|
// Determine the output that the view is under
|
|
|
@ -286,7 +296,6 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
|
|
|
|
if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) {
|
|
|
|
if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static uint8_t head = 0;
|
|
|
|
|
|
|
|
bool cmd_success = false;
|
|
|
|
bool cmd_success = false;
|
|
|
|
|
|
|
|
|
|
|
|
struct sway_mode *mode = config->current_mode;
|
|
|
|
struct sway_mode *mode = config->current_mode;
|
|
|
@ -295,15 +304,15 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
|
|
|
|
|
|
|
|
|
|
|
|
// Find key, if it has been pressed
|
|
|
|
// Find key, if it has been pressed
|
|
|
|
int mid = 0;
|
|
|
|
int mid = 0;
|
|
|
|
while (mid < head && keys_pressed[mid] != sym) {
|
|
|
|
while (mid < keys_pressed_length && keys_pressed[mid] != sym) {
|
|
|
|
++mid;
|
|
|
|
++mid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Add or remove key depending on state
|
|
|
|
//Add or remove key depending on state
|
|
|
|
if (state == WLC_KEY_STATE_PRESSED && mid == head && head + 1 < QSIZE) {
|
|
|
|
if (state == WLC_KEY_STATE_PRESSED && mid == keys_pressed_length && keys_pressed_length + 1 < QSIZE) {
|
|
|
|
keys_pressed[head++] = sym;
|
|
|
|
keys_pressed[keys_pressed_length++] = sym;
|
|
|
|
} else if (state == WLC_KEY_STATE_RELEASED && mid < head) {
|
|
|
|
} else if (state == WLC_KEY_STATE_RELEASED && mid < keys_pressed_length) {
|
|
|
|
memmove(keys_pressed + mid, keys_pressed + mid + 1, sizeof*keys_pressed * (--head - mid));
|
|
|
|
memmove(keys_pressed + mid, keys_pressed + mid + 1, sizeof*keys_pressed * (--keys_pressed_length - mid));
|
|
|
|
keys_pressed[head] = 0;
|
|
|
|
keys_pressed[keys_pressed_length] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// TODO: reminder to check conflicts with mod+q+a versus mod+q
|
|
|
|
// TODO: reminder to check conflicts with mod+q+a versus mod+q
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
@ -317,7 +326,7 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
|
|
|
|
match = false;
|
|
|
|
match = false;
|
|
|
|
xkb_keysym_t *key = binding->keys->items[j];
|
|
|
|
xkb_keysym_t *key = binding->keys->items[j];
|
|
|
|
uint8_t k;
|
|
|
|
uint8_t k;
|
|
|
|
for (k = 0; k < head; ++k) {
|
|
|
|
for (k = 0; k < keys_pressed_length; ++k) {
|
|
|
|
if (keys_pressed[k] == *key) {
|
|
|
|
if (keys_pressed[k] == *key) {
|
|
|
|
match = true;
|
|
|
|
match = true;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -333,9 +342,9 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
|
|
|
|
int j;
|
|
|
|
int j;
|
|
|
|
for (j = 0; j < binding->keys->length; ++j) {
|
|
|
|
for (j = 0; j < binding->keys->length; ++j) {
|
|
|
|
uint8_t k;
|
|
|
|
uint8_t k;
|
|
|
|
for (k = 0; k < head; ++k) {
|
|
|
|
for (k = 0; k < keys_pressed_length; ++k) {
|
|
|
|
memmove(keys_pressed + k, keys_pressed + k + 1, sizeof*keys_pressed * (--head - k));
|
|
|
|
memmove(keys_pressed + k, keys_pressed + k + 1, sizeof*keys_pressed * (--keys_pressed_length - k));
|
|
|
|
keys_pressed[head] = 0;
|
|
|
|
keys_pressed[keys_pressed_length] = 0;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -355,84 +364,67 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
|
|
|
|
static wlc_handle prev_handle = 0;
|
|
|
|
static wlc_handle prev_handle = 0;
|
|
|
|
mouse_origin = *origin;
|
|
|
|
mouse_origin = *origin;
|
|
|
|
bool changed_floating = false;
|
|
|
|
bool changed_floating = false;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
if (!active_workspace) {
|
|
|
|
if (!active_workspace) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Do checks to determine if proper keys are being held
|
|
|
|
// Do checks to determine if proper keys are being held
|
|
|
|
swayc_t *view = active_workspace->focused;
|
|
|
|
swayc_t *view = get_focused_view(active_workspace);
|
|
|
|
uint32_t edge = 0;
|
|
|
|
uint32_t edge = 0;
|
|
|
|
if (dragging && view) {
|
|
|
|
if (dragging && view && view->is_floating) {
|
|
|
|
if (view->is_floating) {
|
|
|
|
int dx = mouse_origin.x - prev_pos.x;
|
|
|
|
while (keys_pressed[i++]) {
|
|
|
|
int dy = mouse_origin.y - prev_pos.y;
|
|
|
|
if (keys_pressed[i] == config->floating_mod) {
|
|
|
|
view->x += dx;
|
|
|
|
int dx = mouse_origin.x - prev_pos.x;
|
|
|
|
view->y += dy;
|
|
|
|
int dy = mouse_origin.y - prev_pos.y;
|
|
|
|
changed_floating = true;
|
|
|
|
view->x += dx;
|
|
|
|
} else if (resizing && view && view->is_floating) {
|
|
|
|
view->y += dy;
|
|
|
|
int dx = mouse_origin.x - prev_pos.x;
|
|
|
|
changed_floating = true;
|
|
|
|
int dy = mouse_origin.y - prev_pos.y;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
// Move and resize the view based on the dx/dy and mouse position
|
|
|
|
|
|
|
|
int midway_x = view->x + view->width/2;
|
|
|
|
|
|
|
|
int midway_y = view->y + view->height/2;
|
|
|
|
|
|
|
|
if (dx < 0) {
|
|
|
|
|
|
|
|
changed_floating = true;
|
|
|
|
|
|
|
|
if (mouse_origin.x > midway_x) {
|
|
|
|
|
|
|
|
view->width += dx;
|
|
|
|
|
|
|
|
edge += WLC_RESIZE_EDGE_RIGHT;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
view->x += dx;
|
|
|
|
|
|
|
|
view->width -= dx;
|
|
|
|
|
|
|
|
edge += WLC_RESIZE_EDGE_LEFT;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (dx > 0){
|
|
|
|
|
|
|
|
changed_floating = true;
|
|
|
|
|
|
|
|
if (mouse_origin.x > midway_x) {
|
|
|
|
|
|
|
|
view->width += dx;
|
|
|
|
|
|
|
|
edge += WLC_RESIZE_EDGE_RIGHT;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
view->x += dx;
|
|
|
|
|
|
|
|
view->width -= dx;
|
|
|
|
|
|
|
|
edge += WLC_RESIZE_EDGE_LEFT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (resizing && view) {
|
|
|
|
|
|
|
|
if (view->is_floating) {
|
|
|
|
|
|
|
|
while (keys_pressed[i++]) {
|
|
|
|
|
|
|
|
if (keys_pressed[i] == config->floating_mod) {
|
|
|
|
|
|
|
|
int dx = mouse_origin.x - prev_pos.x;
|
|
|
|
|
|
|
|
int dy = mouse_origin.y - prev_pos.y;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Move and resize the view based on the dx/dy and mouse position
|
|
|
|
|
|
|
|
int midway_x = view->x + view->width/2;
|
|
|
|
|
|
|
|
int midway_y = view->y + view->height/2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (dx < 0) {
|
|
|
|
|
|
|
|
changed_floating = true;
|
|
|
|
|
|
|
|
if (mouse_origin.x > midway_x) {
|
|
|
|
|
|
|
|
view->width += dx;
|
|
|
|
|
|
|
|
edge += WLC_RESIZE_EDGE_RIGHT;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
view->x += dx;
|
|
|
|
|
|
|
|
view->width -= dx;
|
|
|
|
|
|
|
|
edge += WLC_RESIZE_EDGE_LEFT;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (dx > 0){
|
|
|
|
|
|
|
|
changed_floating = true;
|
|
|
|
|
|
|
|
if (mouse_origin.x > midway_x) {
|
|
|
|
|
|
|
|
view->width += dx;
|
|
|
|
|
|
|
|
edge += WLC_RESIZE_EDGE_RIGHT;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
view->x += dx;
|
|
|
|
|
|
|
|
view->width -= dx;
|
|
|
|
|
|
|
|
edge += WLC_RESIZE_EDGE_LEFT;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (dy < 0) {
|
|
|
|
if (dy < 0) {
|
|
|
|
changed_floating = true;
|
|
|
|
changed_floating = true;
|
|
|
|
if (mouse_origin.y > midway_y) {
|
|
|
|
if (mouse_origin.y > midway_y) {
|
|
|
|
view->height += dy;
|
|
|
|
view->height += dy;
|
|
|
|
edge += WLC_RESIZE_EDGE_BOTTOM;
|
|
|
|
edge += WLC_RESIZE_EDGE_BOTTOM;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
view->y += dy;
|
|
|
|
view->y += dy;
|
|
|
|
view->height -= dy;
|
|
|
|
view->height -= dy;
|
|
|
|
edge += WLC_RESIZE_EDGE_TOP;
|
|
|
|
edge += WLC_RESIZE_EDGE_TOP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (dy > 0) {
|
|
|
|
} else if (dy > 0) {
|
|
|
|
changed_floating = true;
|
|
|
|
changed_floating = true;
|
|
|
|
if (mouse_origin.y > midway_y) {
|
|
|
|
if (mouse_origin.y > midway_y) {
|
|
|
|
view->height += dy;
|
|
|
|
view->height += dy;
|
|
|
|
edge += WLC_RESIZE_EDGE_BOTTOM;
|
|
|
|
edge += WLC_RESIZE_EDGE_BOTTOM;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
edge = WLC_RESIZE_EDGE_BOTTOM;
|
|
|
|
edge = WLC_RESIZE_EDGE_BOTTOM;
|
|
|
|
view->y += dy;
|
|
|
|
view->y += dy;
|
|
|
|
view->height -= dy;
|
|
|
|
view->height -= dy;
|
|
|
|
edge += WLC_RESIZE_EDGE_TOP;
|
|
|
|
edge += WLC_RESIZE_EDGE_TOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -489,9 +481,12 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
arrange_windows(pointer->parent, -1, -1);
|
|
|
|
arrange_windows(pointer->parent, -1, -1);
|
|
|
|
dragging = m1_held;
|
|
|
|
if (floating_mod_pressed()) {
|
|
|
|
resizing = m2_held;
|
|
|
|
dragging = m1_held;
|
|
|
|
return true;
|
|
|
|
resizing = m2_held;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//Dont want pointer sent to window while dragging or resizing
|
|
|
|
|
|
|
|
return (dragging || resizing);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (pointer && pointer != focused);
|
|
|
|
return (pointer && pointer != focused);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|