|
|
|
@ -13,18 +13,10 @@
|
|
|
|
|
#include "workspace.h"
|
|
|
|
|
#include "container.h"
|
|
|
|
|
#include "focus.h"
|
|
|
|
|
|
|
|
|
|
#define KEY_CACHE_SIZE 32
|
|
|
|
|
uint32_t keys_pressed[KEY_CACHE_SIZE];
|
|
|
|
|
#include "input_state.h"
|
|
|
|
|
|
|
|
|
|
static struct wlc_origin mouse_origin;
|
|
|
|
|
|
|
|
|
|
static bool m1_held = false;
|
|
|
|
|
static bool dragging = false;
|
|
|
|
|
static bool m2_held = false;
|
|
|
|
|
static bool resizing = false;
|
|
|
|
|
static bool lock_left, lock_right, lock_top, lock_bottom = false;
|
|
|
|
|
|
|
|
|
|
static bool pointer_test(swayc_t *view, void *_origin) {
|
|
|
|
|
const struct wlc_origin *origin = _origin;
|
|
|
|
|
// Determine the output that the view is under
|
|
|
|
@ -90,29 +82,6 @@ swayc_t *container_under_pointer(void) {
|
|
|
|
|
return lookup;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct wlc_geometry saved_floating;
|
|
|
|
|
|
|
|
|
|
static void start_floating(swayc_t *view) {
|
|
|
|
|
if (view->is_floating) {
|
|
|
|
|
saved_floating.origin.x = view->x;
|
|
|
|
|
saved_floating.origin.y = view->y;
|
|
|
|
|
saved_floating.size.w = view->width;
|
|
|
|
|
saved_floating.size.h = view->height;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void reset_floating(swayc_t *view) {
|
|
|
|
|
if (view->is_floating) {
|
|
|
|
|
view->x = saved_floating.origin.x;
|
|
|
|
|
view->y = saved_floating.origin.y;
|
|
|
|
|
view->width = saved_floating.size.w;
|
|
|
|
|
view->height = saved_floating.size.h;
|
|
|
|
|
arrange_windows(view->parent, -1, -1);
|
|
|
|
|
}
|
|
|
|
|
dragging = resizing = false;
|
|
|
|
|
lock_left = lock_right = lock_top = lock_bottom = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Handles */
|
|
|
|
|
|
|
|
|
|
static bool handle_output_created(wlc_handle output) {
|
|
|
|
@ -327,10 +296,10 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
|
|
|
|
|
if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
bool cmd_success = false;
|
|
|
|
|
|
|
|
|
|
// Revert floating container back to original position on keypress
|
|
|
|
|
if (state == WLC_KEY_STATE_PRESSED && (dragging || resizing)) {
|
|
|
|
|
if (state == WLC_KEY_STATE_PRESSED &&
|
|
|
|
|
(pointer_state.floating.drag || pointer_state.floating.resize)) {
|
|
|
|
|
reset_floating(get_focused_view(&root_container));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -356,16 +325,10 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int total = 0;
|
|
|
|
|
for (i = 0; i < KEY_CACHE_SIZE && !mod; ++i) {
|
|
|
|
|
total += keys_pressed[i] != 0;
|
|
|
|
|
if (state == WLC_KEY_STATE_PRESSED && keys_pressed[i] == 0) {
|
|
|
|
|
keys_pressed[i] = sym;
|
|
|
|
|
break;
|
|
|
|
|
} else if (state == WLC_KEY_STATE_RELEASED && keys_pressed[i] == sym) {
|
|
|
|
|
keys_pressed[i] = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (state == WLC_KEY_STATE_PRESSED) {
|
|
|
|
|
press_key(sym);
|
|
|
|
|
} else { // WLC_KEY_STATE_RELEASED
|
|
|
|
|
release_key(sym);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: reminder to check conflicts with mod+q+a versus mod+q
|
|
|
|
@ -376,32 +339,22 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
|
|
|
|
|
bool match;
|
|
|
|
|
int j;
|
|
|
|
|
for (j = 0; j < binding->keys->length; ++j) {
|
|
|
|
|
match = false;
|
|
|
|
|
xkb_keysym_t *key = binding->keys->items[j];
|
|
|
|
|
int k;
|
|
|
|
|
for (k = 0; k < KEY_CACHE_SIZE; ++k) {
|
|
|
|
|
if (keys_pressed[k] == *key) {
|
|
|
|
|
match = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (match == false) {
|
|
|
|
|
if ((match = check_key(*key)) == false) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (match) {
|
|
|
|
|
// Remove matched keys from keys_pressed
|
|
|
|
|
if (state == WLC_KEY_STATE_PRESSED) {
|
|
|
|
|
handle_command(config, binding->command);
|
|
|
|
|
cmd_success = true;
|
|
|
|
|
return true;
|
|
|
|
|
} else if (state == WLC_KEY_STATE_RELEASED) {
|
|
|
|
|
// TODO: --released
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return cmd_success;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct wlc_origin *origin) {
|
|
|
|
@ -415,7 +368,7 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
|
|
|
|
|
// Do checks to determine if proper keys are being held
|
|
|
|
|
swayc_t *view = get_focused_view(active_workspace);
|
|
|
|
|
uint32_t edge = 0;
|
|
|
|
|
if (dragging && view) {
|
|
|
|
|
if (pointer_state.floating.drag && view) {
|
|
|
|
|
if (view->is_floating) {
|
|
|
|
|
int dx = mouse_origin.x - prev_pos.x;
|
|
|
|
|
int dy = mouse_origin.y - prev_pos.y;
|
|
|
|
@ -423,7 +376,7 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
|
|
|
|
|
view->y += dy;
|
|
|
|
|
changed_floating = true;
|
|
|
|
|
}
|
|
|
|
|
} else if (resizing && view) {
|
|
|
|
|
} else if (pointer_state.floating.resize && view) {
|
|
|
|
|
if (view->is_floating) {
|
|
|
|
|
int dx = mouse_origin.x - prev_pos.x;
|
|
|
|
|
int dy = mouse_origin.y - prev_pos.y;
|
|
|
|
@ -434,24 +387,24 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
|
|
|
|
|
int midway_x = view->x + view->width/2;
|
|
|
|
|
int midway_y = view->y + view->height/2;
|
|
|
|
|
if (dx < 0) {
|
|
|
|
|
if (!lock_right) {
|
|
|
|
|
if (!pointer_state.lock.right) {
|
|
|
|
|
if (view->width > min_sane_w) {
|
|
|
|
|
changed_floating = true;
|
|
|
|
|
view->width += dx;
|
|
|
|
|
edge += WLC_RESIZE_EDGE_RIGHT;
|
|
|
|
|
}
|
|
|
|
|
} else if (mouse_origin.x < midway_x && !lock_left) {
|
|
|
|
|
} else if (mouse_origin.x < midway_x && !pointer_state.lock.left) {
|
|
|
|
|
changed_floating = true;
|
|
|
|
|
view->x += dx;
|
|
|
|
|
view->width -= dx;
|
|
|
|
|
edge += WLC_RESIZE_EDGE_LEFT;
|
|
|
|
|
}
|
|
|
|
|
} else if (dx > 0) {
|
|
|
|
|
if (mouse_origin.x > midway_x && !lock_right) {
|
|
|
|
|
if (mouse_origin.x > midway_x && !pointer_state.lock.right) {
|
|
|
|
|
changed_floating = true;
|
|
|
|
|
view->width += dx;
|
|
|
|
|
edge += WLC_RESIZE_EDGE_RIGHT;
|
|
|
|
|
} else if (!lock_left) {
|
|
|
|
|
} else if (!pointer_state.lock.left) {
|
|
|
|
|
if (view->width > min_sane_w) {
|
|
|
|
|
changed_floating = true;
|
|
|
|
|
view->x += dx;
|
|
|
|
@ -462,24 +415,24 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dy < 0) {
|
|
|
|
|
if (!lock_bottom) {
|
|
|
|
|
if (!pointer_state.lock.bottom) {
|
|
|
|
|
if (view->height > min_sane_h) {
|
|
|
|
|
changed_floating = true;
|
|
|
|
|
view->height += dy;
|
|
|
|
|
edge += WLC_RESIZE_EDGE_BOTTOM;
|
|
|
|
|
}
|
|
|
|
|
} else if (mouse_origin.y < midway_y && !lock_top) {
|
|
|
|
|
} else if (mouse_origin.y < midway_y && !pointer_state.lock.top) {
|
|
|
|
|
changed_floating = true;
|
|
|
|
|
view->y += dy;
|
|
|
|
|
view->height -= dy;
|
|
|
|
|
edge += WLC_RESIZE_EDGE_TOP;
|
|
|
|
|
}
|
|
|
|
|
} else if (dy > 0) {
|
|
|
|
|
if (mouse_origin.y > midway_y && !lock_bottom) {
|
|
|
|
|
if (mouse_origin.y > midway_y && !pointer_state.lock.bottom) {
|
|
|
|
|
changed_floating = true;
|
|
|
|
|
view->height += dy;
|
|
|
|
|
edge += WLC_RESIZE_EDGE_BOTTOM;
|
|
|
|
|
} else if (!lock_top) {
|
|
|
|
|
} else if (!pointer_state.lock.top) {
|
|
|
|
|
if (view->height > min_sane_h) {
|
|
|
|
|
changed_floating = true;
|
|
|
|
|
view->y += dy;
|
|
|
|
@ -493,7 +446,8 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
|
|
|
|
|
if (config->focus_follows_mouse && prev_handle != handle) {
|
|
|
|
|
//Dont change focus if fullscreen
|
|
|
|
|
swayc_t *focused = get_focused_view(view);
|
|
|
|
|
if (!(focused->type == C_VIEW && wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN) && !(m1_held || m2_held)) {
|
|
|
|
|
if (!(focused->type == C_VIEW && wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN)
|
|
|
|
|
&& !(pointer_state.l_held || pointer_state.r_held)) {
|
|
|
|
|
set_focused_container(container_under_pointer());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -516,13 +470,6 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum pointer_values {
|
|
|
|
|
M_LEFT_CLICK = 272,
|
|
|
|
|
M_RIGHT_CLICK = 273,
|
|
|
|
|
M_SCROLL_CLICK = 274,
|
|
|
|
|
M_SCROLL_UP = 275,
|
|
|
|
|
M_SCROLL_DOWN = 276,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers,
|
|
|
|
|
uint32_t button, enum wlc_button_state state, const struct wlc_origin *origin) {
|
|
|
|
@ -534,10 +481,10 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
|
|
|
|
|
if (state == WLC_BUTTON_STATE_PRESSED) {
|
|
|
|
|
sway_log(L_DEBUG, "Mouse button %u pressed", button);
|
|
|
|
|
if (button == M_LEFT_CLICK) {
|
|
|
|
|
m1_held = true;
|
|
|
|
|
pointer_state.l_held = true;
|
|
|
|
|
}
|
|
|
|
|
if (button == M_RIGHT_CLICK) {
|
|
|
|
|
m2_held = true;
|
|
|
|
|
pointer_state.r_held = true;
|
|
|
|
|
}
|
|
|
|
|
swayc_t *pointer = container_under_pointer();
|
|
|
|
|
set_focused_container(pointer);
|
|
|
|
@ -552,30 +499,31 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
|
|
|
|
|
}
|
|
|
|
|
arrange_windows(pointer->parent, -1, -1);
|
|
|
|
|
if (modifiers->mods & config->floating_mod) {
|
|
|
|
|
dragging = m1_held;
|
|
|
|
|
resizing = m2_held;
|
|
|
|
|
int midway_x = pointer->x + pointer->width/2;
|
|
|
|
|
int midway_y = pointer->y + pointer->height/2;
|
|
|
|
|
lock_bottom = origin->y < midway_y;
|
|
|
|
|
lock_top = !lock_bottom;
|
|
|
|
|
lock_right = origin->x < midway_x;
|
|
|
|
|
lock_left = !lock_right;
|
|
|
|
|
|
|
|
|
|
pointer_state.floating.drag = pointer_state.l_held;
|
|
|
|
|
pointer_state.floating.resize = pointer_state.r_held;
|
|
|
|
|
pointer_state.lock.bottom = origin->y < midway_y;
|
|
|
|
|
pointer_state.lock.top = !pointer_state.lock.bottom;
|
|
|
|
|
pointer_state.lock.right = origin->x < midway_x;
|
|
|
|
|
pointer_state.lock.left = !pointer_state.lock.right;
|
|
|
|
|
start_floating(pointer);
|
|
|
|
|
}
|
|
|
|
|
//Dont want pointer sent to window while dragging or resizing
|
|
|
|
|
return (dragging || resizing);
|
|
|
|
|
return (pointer_state.floating.drag || pointer_state.floating.resize);
|
|
|
|
|
}
|
|
|
|
|
return (pointer && pointer != focused);
|
|
|
|
|
} else {
|
|
|
|
|
sway_log(L_DEBUG, "Mouse button %u released", button);
|
|
|
|
|
if (button == M_LEFT_CLICK) {
|
|
|
|
|
m1_held = false;
|
|
|
|
|
dragging = false;
|
|
|
|
|
pointer_state.l_held = false;
|
|
|
|
|
pointer_state.floating.drag = false;
|
|
|
|
|
}
|
|
|
|
|
if (button == M_RIGHT_CLICK) {
|
|
|
|
|
m2_held = false;
|
|
|
|
|
resizing = false;
|
|
|
|
|
lock_top = lock_bottom = lock_left = lock_right = false;
|
|
|
|
|
pointer_state.r_held = false;
|
|
|
|
|
pointer_state.floating.resize = false;
|
|
|
|
|
pointer_state.lock = (struct pointer_lock){false ,false ,false ,false};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
@ -590,10 +538,6 @@ static void handle_wlc_ready(void) {
|
|
|
|
|
}
|
|
|
|
|
free_flat_list(config->cmd_queue);
|
|
|
|
|
config->active = true;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < KEY_CACHE_SIZE; ++i) {
|
|
|
|
|
keys_pressed[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|