mirror of
https://github.com/swaywm/sway.git
synced 2024-11-14 06:24:20 +01:00
style
This commit is contained in:
parent
299406a048
commit
d72cc92541
@ -30,11 +30,11 @@ enum pointer_values {
|
|||||||
|
|
||||||
enum pointer_mode {
|
enum pointer_mode {
|
||||||
// Target
|
// Target
|
||||||
M_FLOATING = 1 << 0,
|
M_FLOATING = 1,
|
||||||
M_TILING = 1 << 1,
|
M_TILING = 2,
|
||||||
// Action
|
// Action
|
||||||
M_DRAGGING = 1 << 2,
|
M_DRAGGING = 4,
|
||||||
M_RESIZING = 1 << 3,
|
M_RESIZING = 8,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct pointer_button_state {
|
struct pointer_button_state {
|
||||||
|
@ -17,6 +17,12 @@
|
|||||||
#include "input_state.h"
|
#include "input_state.h"
|
||||||
#include "resize.h"
|
#include "resize.h"
|
||||||
|
|
||||||
|
// Event should be sent to client
|
||||||
|
#define EVENT_PASSTHROUGH false
|
||||||
|
|
||||||
|
// Event handled by sway and should not be sent to client
|
||||||
|
#define EVENT_HANDLED true
|
||||||
|
|
||||||
static bool pointer_test(swayc_t *view, void *_origin) {
|
static bool pointer_test(swayc_t *view, void *_origin) {
|
||||||
const struct mouse_origin *origin = _origin;
|
const struct mouse_origin *origin = _origin;
|
||||||
// Determine the output that the view is under
|
// Determine the output that the view is under
|
||||||
@ -276,7 +282,7 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
|
|||||||
uint32_t key, uint32_t sym, enum wlc_key_state state) {
|
uint32_t key, uint32_t sym, enum wlc_key_state state) {
|
||||||
|
|
||||||
if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) {
|
if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) {
|
||||||
return false;
|
return EVENT_PASSTHROUGH;
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset pointer mode on keypress
|
// reset pointer mode on keypress
|
||||||
@ -289,7 +295,7 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
|
|||||||
if (sym < 70000 /* bullshit made up number */) {
|
if (sym < 70000 /* bullshit made up number */) {
|
||||||
if (!isalnum(sym) && sym != ' ' && sym != XKB_KEY_Escape && sym != XKB_KEY_Tab) {
|
if (!isalnum(sym) && sym != ' ' && sym != XKB_KEY_Escape && sym != XKB_KEY_Tab) {
|
||||||
// God fucking dammit
|
// God fucking dammit
|
||||||
return false;
|
return EVENT_PASSTHROUGH;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,14 +326,14 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
|
|||||||
if (match) {
|
if (match) {
|
||||||
if (state == WLC_KEY_STATE_PRESSED) {
|
if (state == WLC_KEY_STATE_PRESSED) {
|
||||||
handle_command(config, binding->command);
|
handle_command(config, binding->command);
|
||||||
return true;
|
return EVENT_HANDLED;
|
||||||
} else if (state == WLC_KEY_STATE_RELEASED) {
|
} else if (state == WLC_KEY_STATE_RELEASED) {
|
||||||
// TODO: --released
|
// TODO: --released
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return EVENT_PASSTHROUGH;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct wlc_origin *origin) {
|
static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct wlc_origin *origin) {
|
||||||
@ -351,13 +357,12 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
|
|||||||
set_focused_container(pointer_state.view);
|
set_focused_container(pointer_state.view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return EVENT_PASSTHROUGH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers,
|
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) {
|
uint32_t button, enum wlc_button_state state, const struct wlc_origin *origin) {
|
||||||
enum { DONT_SEND_CLICK = true, SEND_CLICK = false };
|
|
||||||
|
|
||||||
// Update view pointer is on
|
// Update view pointer is on
|
||||||
pointer_state.view = container_under_pointer();
|
pointer_state.view = container_under_pointer();
|
||||||
@ -412,7 +417,7 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
|
|||||||
|
|
||||||
// dont change focus or mode if fullscreen
|
// dont change focus or mode if fullscreen
|
||||||
if (swayc_is_fullscreen(focused)) {
|
if (swayc_is_fullscreen(focused)) {
|
||||||
return SEND_CLICK;
|
return EVENT_PASSTHROUGH;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set pointer mode
|
// set pointer mode
|
||||||
@ -421,12 +426,12 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
|
|||||||
|
|
||||||
// Return if mode has been set
|
// Return if mode has been set
|
||||||
if (pointer_state.mode) {
|
if (pointer_state.mode) {
|
||||||
return DONT_SEND_CLICK;
|
return EVENT_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always send mouse release
|
// Always send mouse release
|
||||||
if (state == WLC_BUTTON_STATE_RELEASED) {
|
if (state == WLC_BUTTON_STATE_RELEASED) {
|
||||||
return SEND_CLICK;
|
return EVENT_PASSTHROUGH;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check whether to change focus
|
// Check whether to change focus
|
||||||
@ -448,7 +453,7 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Finally send click
|
// Finally send click
|
||||||
return SEND_CLICK;
|
return EVENT_PASSTHROUGH;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_wlc_ready(void) {
|
static void handle_wlc_ready(void) {
|
||||||
|
@ -56,23 +56,24 @@ static struct mode_state {
|
|||||||
// initial view state
|
// initial view state
|
||||||
double x, y, w, h;
|
double x, y, w, h;
|
||||||
swayc_t *ptr;
|
swayc_t *ptr;
|
||||||
// containers resized with tiling resize
|
// Containers used for resizing horizontally
|
||||||
struct {
|
struct {
|
||||||
double x, w;
|
double w;
|
||||||
swayc_t *ptr;
|
swayc_t *ptr;
|
||||||
struct {
|
struct {
|
||||||
double x, w;
|
double w;
|
||||||
swayc_t *ptr;
|
swayc_t *ptr;
|
||||||
} sib;
|
} parent;
|
||||||
} lr;
|
} horiz;
|
||||||
|
// Containers used for resizing vertically
|
||||||
struct {
|
struct {
|
||||||
double y, h;
|
double h;
|
||||||
swayc_t *ptr;
|
swayc_t *ptr;
|
||||||
struct {
|
struct {
|
||||||
double y, h;
|
double h;
|
||||||
swayc_t *ptr;
|
swayc_t *ptr;
|
||||||
} sib;
|
} parent;
|
||||||
} tb;
|
} vert;
|
||||||
} initial;
|
} initial;
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
@ -92,23 +93,19 @@ static void set_initial_view(swayc_t *view) {
|
|||||||
|
|
||||||
static void set_initial_sibling(void) {
|
static void set_initial_sibling(void) {
|
||||||
bool reset = true;
|
bool reset = true;
|
||||||
if ((initial.lr.ptr = get_swayc_in_direction(initial.ptr, lock.left ? MOVE_RIGHT: MOVE_LEFT))) {
|
if ((initial.horiz.ptr = get_swayc_in_direction(initial.ptr, lock.left ? MOVE_RIGHT: MOVE_LEFT))) {
|
||||||
initial.lr.x = initial.lr.ptr->x;
|
initial.horiz.w = initial.horiz.ptr->width;
|
||||||
initial.lr.w = initial.lr.ptr->width;
|
initial.horiz.parent.ptr = get_swayc_in_direction(initial.horiz.ptr, lock.left ? MOVE_LEFT : MOVE_RIGHT);
|
||||||
initial.lr.sib.ptr = get_swayc_in_direction(initial.lr.ptr, lock.left ? MOVE_LEFT : MOVE_RIGHT);
|
initial.horiz.parent.w = initial.horiz.parent.ptr->width;
|
||||||
initial.lr.sib.x = initial.lr.sib.ptr->x;
|
|
||||||
initial.lr.sib.w = initial.lr.sib.ptr->width;
|
|
||||||
reset = false;
|
reset = false;
|
||||||
}
|
}
|
||||||
if ((initial.tb.ptr = get_swayc_in_direction(initial.ptr, lock.top ? MOVE_DOWN: MOVE_UP))) {
|
if ((initial.vert.ptr = get_swayc_in_direction(initial.ptr, lock.top ? MOVE_DOWN: MOVE_UP))) {
|
||||||
initial.tb.y = initial.tb.ptr->y;
|
initial.vert.h = initial.vert.ptr->height;
|
||||||
initial.tb.h = initial.tb.ptr->height;
|
initial.vert.parent.ptr = get_swayc_in_direction(initial.vert.ptr, lock.top ? MOVE_UP : MOVE_DOWN);
|
||||||
initial.tb.sib.ptr = get_swayc_in_direction(initial.tb.ptr, lock.top ? MOVE_UP : MOVE_DOWN);
|
initial.vert.parent.h = initial.vert.parent.ptr->height;
|
||||||
initial.tb.sib.y = initial.tb.sib.ptr->y;
|
|
||||||
initial.tb.sib.h = initial.tb.sib.ptr->height;
|
|
||||||
reset = false;
|
reset = false;
|
||||||
}
|
}
|
||||||
// If nothing changes just undo the mode
|
// If nothing will change just undo the mode
|
||||||
if (reset) {
|
if (reset) {
|
||||||
pointer_state.mode = 0;
|
pointer_state.mode = 0;
|
||||||
}
|
}
|
||||||
@ -123,6 +120,16 @@ static void reset_initial_view(void) {
|
|||||||
pointer_state.mode = 0;
|
pointer_state.mode = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void reset_initial_sibling(void) {
|
||||||
|
initial.horiz.ptr->width = initial.horiz.w;
|
||||||
|
initial.horiz.parent.ptr->width = initial.horiz.parent.w;
|
||||||
|
initial.vert.ptr->height = initial.vert.h;
|
||||||
|
initial.vert.parent.ptr->height = initial.vert.parent.h;
|
||||||
|
arrange_windows(initial.horiz.ptr->parent, -1, -1);
|
||||||
|
arrange_windows(initial.vert.ptr->parent, -1, -1);
|
||||||
|
pointer_state.mode = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Mode set left/right click
|
// Mode set left/right click
|
||||||
|
|
||||||
static void pointer_mode_set_left(void) {
|
static void pointer_mode_set_left(void) {
|
||||||
@ -228,7 +235,7 @@ void pointer_mode_update(void) {
|
|||||||
if (initial.w + dx > min_sane_w) {
|
if (initial.w + dx > min_sane_w) {
|
||||||
initial.ptr->width = initial.w + dx;
|
initial.ptr->width = initial.w + dx;
|
||||||
}
|
}
|
||||||
} else { //lock.right
|
} else { // lock.right
|
||||||
if (initial.w - dx > min_sane_w) {
|
if (initial.w - dx > min_sane_w) {
|
||||||
initial.ptr->width = initial.w - dx;
|
initial.ptr->width = initial.w - dx;
|
||||||
initial.ptr->x = initial.x + dx;
|
initial.ptr->x = initial.x + dx;
|
||||||
@ -238,7 +245,7 @@ void pointer_mode_update(void) {
|
|||||||
if (initial.h + dy > min_sane_h) {
|
if (initial.h + dy > min_sane_h) {
|
||||||
initial.ptr->height = initial.h + dy;
|
initial.ptr->height = initial.h + dy;
|
||||||
}
|
}
|
||||||
} else { //lock.bottom
|
} else { // lock.bottom
|
||||||
if (initial.h - dy > min_sane_h) {
|
if (initial.h - dy > min_sane_h) {
|
||||||
initial.ptr->height = initial.h - dy;
|
initial.ptr->height = initial.h - dy;
|
||||||
initial.ptr->y = initial.y + dy;
|
initial.ptr->y = initial.y + dy;
|
||||||
@ -264,34 +271,34 @@ void pointer_mode_update(void) {
|
|||||||
dx -= pointer_state.right.x;
|
dx -= pointer_state.right.x;
|
||||||
dy -= pointer_state.right.y;
|
dy -= pointer_state.right.y;
|
||||||
// resize if we can
|
// resize if we can
|
||||||
if (initial.lr.ptr) {
|
if (initial.horiz.ptr) {
|
||||||
if (lock.left) {
|
if (lock.left) {
|
||||||
// Check whether its fine to resize
|
// Check whether its fine to resize
|
||||||
if (initial.w + dx > min_sane_w && initial.lr.w - dx > min_sane_w) {
|
if (initial.w + dx > min_sane_w && initial.horiz.w - dx > min_sane_w) {
|
||||||
initial.lr.ptr->width = initial.lr.w - dx;
|
initial.horiz.ptr->width = initial.horiz.w - dx;
|
||||||
initial.lr.sib.ptr->width = initial.lr.sib.w + dx;
|
initial.horiz.parent.ptr->width = initial.horiz.parent.w + dx;
|
||||||
}
|
}
|
||||||
} else { //lock.right
|
} else { // lock.right
|
||||||
if (initial.w - dx > min_sane_w && initial.lr.w + dx > min_sane_w) {
|
if (initial.w - dx > min_sane_w && initial.horiz.w + dx > min_sane_w) {
|
||||||
initial.lr.ptr->width = initial.lr.w + dx;
|
initial.horiz.ptr->width = initial.horiz.w + dx;
|
||||||
initial.lr.sib.ptr->width = initial.lr.sib.w - dx;
|
initial.horiz.parent.ptr->width = initial.horiz.parent.w - dx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
arrange_windows(initial.lr.ptr->parent, -1, -1);
|
arrange_windows(initial.horiz.ptr->parent, -1, -1);
|
||||||
}
|
}
|
||||||
if (initial.tb.ptr) {
|
if (initial.vert.ptr) {
|
||||||
if (lock.top) {
|
if (lock.top) {
|
||||||
if (initial.h + dy > min_sane_h && initial.tb.h - dy > min_sane_h) {
|
if (initial.h + dy > min_sane_h && initial.vert.h - dy > min_sane_h) {
|
||||||
initial.tb.ptr->height = initial.tb.h - dy;
|
initial.vert.ptr->height = initial.vert.h - dy;
|
||||||
initial.tb.sib.ptr->height = initial.tb.sib.h + dy;
|
initial.vert.parent.ptr->height = initial.vert.parent.h + dy;
|
||||||
}
|
}
|
||||||
} else { //lock.bottom
|
} else { // lock.bottom
|
||||||
if (initial.h - dy > min_sane_h && initial.tb.h + dy > min_sane_h) {
|
if (initial.h - dy > min_sane_h && initial.vert.h + dy > min_sane_h) {
|
||||||
initial.tb.ptr->height = initial.tb.h + dy;
|
initial.vert.ptr->height = initial.vert.h + dy;
|
||||||
initial.tb.sib.ptr->height = initial.tb.sib.h - dy;
|
initial.vert.parent.ptr->height = initial.vert.parent.h - dy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
arrange_windows(initial.tb.ptr->parent, -1, -1);
|
arrange_windows(initial.vert.ptr->parent, -1, -1);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
@ -300,15 +307,17 @@ void pointer_mode_update(void) {
|
|||||||
|
|
||||||
void pointer_mode_reset(void) {
|
void pointer_mode_reset(void) {
|
||||||
switch (pointer_state.mode) {
|
switch (pointer_state.mode) {
|
||||||
case M_FLOATING | M_DRAGGING:
|
|
||||||
case M_FLOATING | M_RESIZING:
|
case M_FLOATING | M_RESIZING:
|
||||||
|
case M_FLOATING | M_DRAGGING:
|
||||||
reset_initial_view();
|
reset_initial_view();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case M_TILING | M_DRAGGING:
|
|
||||||
case M_TILING | M_RESIZING:
|
case M_TILING | M_RESIZING:
|
||||||
|
(void) reset_initial_sibling;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case M_TILING | M_DRAGGING:
|
||||||
default:
|
default:
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user