|
|
@ -14,8 +14,13 @@
|
|
|
|
#include "container.h"
|
|
|
|
#include "container.h"
|
|
|
|
#include "focus.h"
|
|
|
|
#include "focus.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t keys_pressed[32];
|
|
|
|
|
|
|
|
|
|
|
|
static struct wlc_origin mouse_origin;
|
|
|
|
static struct wlc_origin mouse_origin;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool m1_held = false;
|
|
|
|
|
|
|
|
static bool m2_held = 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
|
|
|
@ -144,10 +149,10 @@ static bool handle_view_created(wlc_handle handle) {
|
|
|
|
locked_container_focus = true;
|
|
|
|
locked_container_focus = true;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
//set modals as floating containers
|
|
|
|
//set modals as floating containers
|
|
|
|
case WLC_BIT_POPUP:
|
|
|
|
|
|
|
|
case WLC_BIT_MODAL:
|
|
|
|
case WLC_BIT_MODAL:
|
|
|
|
wlc_view_bring_to_front(handle);
|
|
|
|
wlc_view_bring_to_front(handle);
|
|
|
|
newview = new_floating_view(handle);
|
|
|
|
newview = new_floating_view(handle);
|
|
|
|
|
|
|
|
case WLC_BIT_POPUP:
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (newview) {
|
|
|
|
if (newview) {
|
|
|
@ -166,9 +171,9 @@ static void handle_view_destroyed(wlc_handle handle) {
|
|
|
|
//regular view created regularly
|
|
|
|
//regular view created regularly
|
|
|
|
case 0:
|
|
|
|
case 0:
|
|
|
|
case WLC_BIT_MODAL:
|
|
|
|
case WLC_BIT_MODAL:
|
|
|
|
case WLC_BIT_POPUP:
|
|
|
|
|
|
|
|
if (view) {
|
|
|
|
if (view) {
|
|
|
|
arrange_windows(destroy_view(view), -1, -1);
|
|
|
|
swayc_t *parent = destroy_view(view);
|
|
|
|
|
|
|
|
arrange_windows(parent, -1, -1);
|
|
|
|
if (!focused || focused == view) {
|
|
|
|
if (!focused || focused == view) {
|
|
|
|
set_focused_container(container_under_pointer());
|
|
|
|
set_focused_container(container_under_pointer());
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -181,6 +186,7 @@ static void handle_view_destroyed(wlc_handle handle) {
|
|
|
|
//Takes container focus
|
|
|
|
//Takes container focus
|
|
|
|
case WLC_BIT_OVERRIDE_REDIRECT|WLC_BIT_UNMANAGED:
|
|
|
|
case WLC_BIT_OVERRIDE_REDIRECT|WLC_BIT_UNMANAGED:
|
|
|
|
locked_container_focus = false;
|
|
|
|
locked_container_focus = false;
|
|
|
|
|
|
|
|
case WLC_BIT_POPUP:
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
set_focused_container(get_focused_view(&root_container));
|
|
|
|
set_focused_container(get_focused_view(&root_container));
|
|
|
@ -250,7 +256,6 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static uint8_t head = 0;
|
|
|
|
static uint8_t head = 0;
|
|
|
|
static uint32_t array[QSIZE];
|
|
|
|
|
|
|
|
bool cmd_success = false;
|
|
|
|
bool cmd_success = false;
|
|
|
|
|
|
|
|
|
|
|
|
struct sway_mode *mode = config->current_mode;
|
|
|
|
struct sway_mode *mode = config->current_mode;
|
|
|
@ -259,13 +264,13 @@ 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 && array[mid] != sym) {
|
|
|
|
while (mid < head && keys_pressed[mid] != sym) {
|
|
|
|
++mid;
|
|
|
|
++mid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (state == WLC_KEY_STATE_PRESSED && mid == head && head + 1 < QSIZE) {
|
|
|
|
if (state == WLC_KEY_STATE_PRESSED && mid == head && head + 1 < QSIZE) {
|
|
|
|
array[head++] = sym;
|
|
|
|
keys_pressed[head++] = sym;
|
|
|
|
} else if (state == WLC_KEY_STATE_RELEASED && mid < head) {
|
|
|
|
} else if (state == WLC_KEY_STATE_RELEASED && mid < head) {
|
|
|
|
memmove(array + mid, array + mid + 1, sizeof*array * (--head - mid));
|
|
|
|
memmove(keys_pressed + mid, keys_pressed + mid + 1, sizeof*keys_pressed * (--head - mid));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 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;
|
|
|
@ -280,7 +285,7 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
|
|
|
|
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 < head; ++k) {
|
|
|
|
if (array[k] == *key) {
|
|
|
|
if (keys_pressed[k] == *key) {
|
|
|
|
match = true;
|
|
|
|
match = true;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -291,12 +296,12 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (match) {
|
|
|
|
if (match) {
|
|
|
|
//Remove matched keys from array
|
|
|
|
//Remove matched keys from keys_pressed
|
|
|
|
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 < head; ++k) {
|
|
|
|
memmove(array + k, array + k + 1, sizeof*array * (--head - k));
|
|
|
|
memmove(keys_pressed + k, keys_pressed + k + 1, sizeof*keys_pressed * (--head - k));
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -311,13 +316,100 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
|
|
|
|
return cmd_success;
|
|
|
|
return cmd_success;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool handle_pointer_motion(wlc_handle view, uint32_t time, const struct wlc_origin *origin) {
|
|
|
|
static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct wlc_origin *origin) {
|
|
|
|
static wlc_handle prev_view = 0;
|
|
|
|
static struct wlc_origin prev_pos;
|
|
|
|
|
|
|
|
static wlc_handle prev_handle = 0;
|
|
|
|
mouse_origin = *origin;
|
|
|
|
mouse_origin = *origin;
|
|
|
|
if (config->focus_follows_mouse && prev_view != view) {
|
|
|
|
bool changed_floating = false;
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
// Do checks to determine if proper keys are being held
|
|
|
|
|
|
|
|
swayc_t *view = active_workspace->focused;
|
|
|
|
|
|
|
|
if (m1_held) {
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
sway_log(L_DEBUG, "Moving from px: %d to cx: %d and from py: %d to cy: %d", prev_pos.x, mouse_origin.x, prev_pos.y, mouse_origin.y);
|
|
|
|
|
|
|
|
sway_log(L_DEBUG, "Moving: dx: %d, dy: %d", dx, dy);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
view->x += dx;
|
|
|
|
|
|
|
|
view->y += dy;
|
|
|
|
|
|
|
|
changed_floating = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (m2_held) {
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
sway_log(L_DEBUG, "Moving from px: %d to cx: %d and from py: %d to cy: %d", prev_pos.x, mouse_origin.x, prev_pos.y, mouse_origin.y);
|
|
|
|
|
|
|
|
sway_log(L_INFO, "Moving: dx: %d, dy: %d", dx, dy);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
|
|
|
|
sway_log(L_INFO, "Downsizing view to the left");
|
|
|
|
|
|
|
|
view->width += dx;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
sway_log(L_INFO, "Upsizing view to the left");
|
|
|
|
|
|
|
|
view->x += dx;
|
|
|
|
|
|
|
|
view->width -= dx;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (dx > 0){
|
|
|
|
|
|
|
|
changed_floating = true;
|
|
|
|
|
|
|
|
if (mouse_origin.x > midway_x) {
|
|
|
|
|
|
|
|
sway_log(L_INFO, "Upsizing to the right");
|
|
|
|
|
|
|
|
view->width += dx;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
sway_log(L_INFO, "Downsizing to the right");
|
|
|
|
|
|
|
|
view->x += dx;
|
|
|
|
|
|
|
|
view->width -= dx;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (dy < 0) {
|
|
|
|
|
|
|
|
changed_floating = true;
|
|
|
|
|
|
|
|
if (mouse_origin.y > midway_y) {
|
|
|
|
|
|
|
|
sway_log(L_INFO, "Downsizing view to the top");
|
|
|
|
|
|
|
|
view->height += dy;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
sway_log(L_INFO, "Upsizing the view to the top");
|
|
|
|
|
|
|
|
view->y += dy;
|
|
|
|
|
|
|
|
view->height -= dy;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (dy > 0) {
|
|
|
|
|
|
|
|
changed_floating = true;
|
|
|
|
|
|
|
|
if (mouse_origin.y > midway_y) {
|
|
|
|
|
|
|
|
sway_log(L_INFO, "Upsizing to the bottom");
|
|
|
|
|
|
|
|
view->height += dy;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
sway_log(L_INFO, "Downsizing to the bottom");
|
|
|
|
|
|
|
|
view->y += dy;
|
|
|
|
|
|
|
|
view->height -= dy;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config->focus_follows_mouse && prev_handle != handle) {
|
|
|
|
set_focused_container(container_under_pointer());
|
|
|
|
set_focused_container(container_under_pointer());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
prev_view = view;
|
|
|
|
prev_handle = handle;
|
|
|
|
|
|
|
|
prev_pos = mouse_origin;
|
|
|
|
|
|
|
|
if (changed_floating) {
|
|
|
|
|
|
|
|
arrange_windows(view, -1, -1);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -325,9 +417,24 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
|
|
|
|
uint32_t button, enum wlc_button_state state) {
|
|
|
|
uint32_t button, enum wlc_button_state state) {
|
|
|
|
swayc_t *focused = get_focused_container(&root_container);
|
|
|
|
swayc_t *focused = get_focused_container(&root_container);
|
|
|
|
if (state == WLC_BUTTON_STATE_PRESSED) {
|
|
|
|
if (state == WLC_BUTTON_STATE_PRESSED) {
|
|
|
|
|
|
|
|
sway_log(L_DEBUG, "Mouse button %u pressed", button);
|
|
|
|
|
|
|
|
if (button == 272) {
|
|
|
|
|
|
|
|
m1_held = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (button == 273) {
|
|
|
|
|
|
|
|
m2_held = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
swayc_t *pointer = container_under_pointer();
|
|
|
|
swayc_t *pointer = container_under_pointer();
|
|
|
|
set_focused_container(pointer);
|
|
|
|
set_focused_container(pointer);
|
|
|
|
return (pointer && pointer != focused);
|
|
|
|
return (pointer && pointer != focused);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
sway_log(L_DEBUG, "Mouse button %u released", button);
|
|
|
|
|
|
|
|
if (button == 272) {
|
|
|
|
|
|
|
|
m1_held = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (button == 273) {
|
|
|
|
|
|
|
|
m2_held = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|