summaryrefslogtreecommitdiffstats
path: root/sway/input_state.c
diff options
context:
space:
mode:
authorLibravatar taiyu <taiyu.len@gmail.com>2015-08-23 07:59:18 -0700
committerLibravatar taiyu <taiyu.len@gmail.com>2015-08-23 07:59:18 -0700
commitd72cc925416847adaf2636cea0773ef6d9a46461 (patch)
treea1c882aca8348ae0558872759df2e8e01f49be62 /sway/input_state.c
parentslight fix (diff)
downloadsway-d72cc925416847adaf2636cea0773ef6d9a46461.tar.gz
sway-d72cc925416847adaf2636cea0773ef6d9a46461.tar.zst
sway-d72cc925416847adaf2636cea0773ef6d9a46461.zip
style
Diffstat (limited to 'sway/input_state.c')
-rw-r--r--sway/input_state.c101
1 files changed, 55 insertions, 46 deletions
diff --git a/sway/input_state.c b/sway/input_state.c
index 8450fe7a..acf90d75 100644
--- a/sway/input_state.c
+++ b/sway/input_state.c
@@ -56,23 +56,24 @@ static struct mode_state {
56 // initial view state 56 // initial view state
57 double x, y, w, h; 57 double x, y, w, h;
58 swayc_t *ptr; 58 swayc_t *ptr;
59 // containers resized with tiling resize 59 // Containers used for resizing horizontally
60 struct { 60 struct {
61 double x, w; 61 double w;
62 swayc_t *ptr; 62 swayc_t *ptr;
63 struct { 63 struct {
64 double x, w; 64 double w;
65 swayc_t *ptr; 65 swayc_t *ptr;
66 } sib; 66 } parent;
67 } lr; 67 } horiz;
68 // Containers used for resizing vertically
68 struct { 69 struct {
69 double y, h; 70 double h;
70 swayc_t *ptr; 71 swayc_t *ptr;
71 struct { 72 struct {
72 double y, h; 73 double h;
73 swayc_t *ptr; 74 swayc_t *ptr;
74 } sib; 75 } parent;
75 } tb; 76 } vert;
76} initial; 77} initial;
77 78
78static struct { 79static struct {
@@ -92,23 +93,19 @@ static void set_initial_view(swayc_t *view) {
92 93
93static void set_initial_sibling(void) { 94static void set_initial_sibling(void) {
94 bool reset = true; 95 bool reset = true;
95 if ((initial.lr.ptr = get_swayc_in_direction(initial.ptr, lock.left ? MOVE_RIGHT: MOVE_LEFT))) { 96 if ((initial.horiz.ptr = get_swayc_in_direction(initial.ptr, lock.left ? MOVE_RIGHT: MOVE_LEFT))) {
96 initial.lr.x = initial.lr.ptr->x; 97 initial.horiz.w = initial.horiz.ptr->width;
97 initial.lr.w = initial.lr.ptr->width; 98 initial.horiz.parent.ptr = get_swayc_in_direction(initial.horiz.ptr, lock.left ? MOVE_LEFT : MOVE_RIGHT);
98 initial.lr.sib.ptr = get_swayc_in_direction(initial.lr.ptr, lock.left ? MOVE_LEFT : MOVE_RIGHT); 99 initial.horiz.parent.w = initial.horiz.parent.ptr->width;
99 initial.lr.sib.x = initial.lr.sib.ptr->x;
100 initial.lr.sib.w = initial.lr.sib.ptr->width;
101 reset = false; 100 reset = false;
102 } 101 }
103 if ((initial.tb.ptr = get_swayc_in_direction(initial.ptr, lock.top ? MOVE_DOWN: MOVE_UP))) { 102 if ((initial.vert.ptr = get_swayc_in_direction(initial.ptr, lock.top ? MOVE_DOWN: MOVE_UP))) {
104 initial.tb.y = initial.tb.ptr->y; 103 initial.vert.h = initial.vert.ptr->height;
105 initial.tb.h = initial.tb.ptr->height; 104 initial.vert.parent.ptr = get_swayc_in_direction(initial.vert.ptr, lock.top ? MOVE_UP : MOVE_DOWN);
106 initial.tb.sib.ptr = get_swayc_in_direction(initial.tb.ptr, lock.top ? MOVE_UP : MOVE_DOWN); 105 initial.vert.parent.h = initial.vert.parent.ptr->height;
107 initial.tb.sib.y = initial.tb.sib.ptr->y;
108 initial.tb.sib.h = initial.tb.sib.ptr->height;
109 reset = false; 106 reset = false;
110 } 107 }
111 // If nothing changes just undo the mode 108 // If nothing will change just undo the mode
112 if (reset) { 109 if (reset) {
113 pointer_state.mode = 0; 110 pointer_state.mode = 0;
114 } 111 }
@@ -123,6 +120,16 @@ static void reset_initial_view(void) {
123 pointer_state.mode = 0; 120 pointer_state.mode = 0;
124} 121}
125 122
123static void reset_initial_sibling(void) {
124 initial.horiz.ptr->width = initial.horiz.w;
125 initial.horiz.parent.ptr->width = initial.horiz.parent.w;
126 initial.vert.ptr->height = initial.vert.h;
127 initial.vert.parent.ptr->height = initial.vert.parent.h;
128 arrange_windows(initial.horiz.ptr->parent, -1, -1);
129 arrange_windows(initial.vert.ptr->parent, -1, -1);
130 pointer_state.mode = 0;
131}
132
126// Mode set left/right click 133// Mode set left/right click
127 134
128static void pointer_mode_set_left(void) { 135static void pointer_mode_set_left(void) {
@@ -228,7 +235,7 @@ void pointer_mode_update(void) {
228 if (initial.w + dx > min_sane_w) { 235 if (initial.w + dx > min_sane_w) {
229 initial.ptr->width = initial.w + dx; 236 initial.ptr->width = initial.w + dx;
230 } 237 }
231 } else { //lock.right 238 } else { // lock.right
232 if (initial.w - dx > min_sane_w) { 239 if (initial.w - dx > min_sane_w) {
233 initial.ptr->width = initial.w - dx; 240 initial.ptr->width = initial.w - dx;
234 initial.ptr->x = initial.x + dx; 241 initial.ptr->x = initial.x + dx;
@@ -238,7 +245,7 @@ void pointer_mode_update(void) {
238 if (initial.h + dy > min_sane_h) { 245 if (initial.h + dy > min_sane_h) {
239 initial.ptr->height = initial.h + dy; 246 initial.ptr->height = initial.h + dy;
240 } 247 }
241 } else { //lock.bottom 248 } else { // lock.bottom
242 if (initial.h - dy > min_sane_h) { 249 if (initial.h - dy > min_sane_h) {
243 initial.ptr->height = initial.h - dy; 250 initial.ptr->height = initial.h - dy;
244 initial.ptr->y = initial.y + dy; 251 initial.ptr->y = initial.y + dy;
@@ -264,34 +271,34 @@ void pointer_mode_update(void) {
264 dx -= pointer_state.right.x; 271 dx -= pointer_state.right.x;
265 dy -= pointer_state.right.y; 272 dy -= pointer_state.right.y;
266 // resize if we can 273 // resize if we can
267 if (initial.lr.ptr) { 274 if (initial.horiz.ptr) {
268 if (lock.left) { 275 if (lock.left) {
269 // Check whether its fine to resize 276 // Check whether its fine to resize
270 if (initial.w + dx > min_sane_w && initial.lr.w - dx > min_sane_w) { 277 if (initial.w + dx > min_sane_w && initial.horiz.w - dx > min_sane_w) {
271 initial.lr.ptr->width = initial.lr.w - dx; 278 initial.horiz.ptr->width = initial.horiz.w - dx;
272 initial.lr.sib.ptr->width = initial.lr.sib.w + dx; 279 initial.horiz.parent.ptr->width = initial.horiz.parent.w + dx;
273 } 280 }
274 } else { //lock.right 281 } else { // lock.right
275 if (initial.w - dx > min_sane_w && initial.lr.w + dx > min_sane_w) { 282 if (initial.w - dx > min_sane_w && initial.horiz.w + dx > min_sane_w) {
276 initial.lr.ptr->width = initial.lr.w + dx; 283 initial.horiz.ptr->width = initial.horiz.w + dx;
277 initial.lr.sib.ptr->width = initial.lr.sib.w - dx; 284 initial.horiz.parent.ptr->width = initial.horiz.parent.w - dx;
278 } 285 }
279 } 286 }
280 arrange_windows(initial.lr.ptr->parent, -1, -1); 287 arrange_windows(initial.horiz.ptr->parent, -1, -1);
281 } 288 }
282 if (initial.tb.ptr) { 289 if (initial.vert.ptr) {
283 if (lock.top) { 290 if (lock.top) {
284 if (initial.h + dy > min_sane_h && initial.tb.h - dy > min_sane_h) { 291 if (initial.h + dy > min_sane_h && initial.vert.h - dy > min_sane_h) {
285 initial.tb.ptr->height = initial.tb.h - dy; 292 initial.vert.ptr->height = initial.vert.h - dy;
286 initial.tb.sib.ptr->height = initial.tb.sib.h + dy; 293 initial.vert.parent.ptr->height = initial.vert.parent.h + dy;
287 } 294 }
288 } else { //lock.bottom 295 } else { // lock.bottom
289 if (initial.h - dy > min_sane_h && initial.tb.h + dy > min_sane_h) { 296 if (initial.h - dy > min_sane_h && initial.vert.h + dy > min_sane_h) {
290 initial.tb.ptr->height = initial.tb.h + dy; 297 initial.vert.ptr->height = initial.vert.h + dy;
291 initial.tb.sib.ptr->height = initial.tb.sib.h - dy; 298 initial.vert.parent.ptr->height = initial.vert.parent.h - dy;
292 } 299 }
293 } 300 }
294 arrange_windows(initial.tb.ptr->parent, -1, -1); 301 arrange_windows(initial.vert.ptr->parent, -1, -1);
295 } 302 }
296 default: 303 default:
297 return; 304 return;
@@ -300,15 +307,17 @@ void pointer_mode_update(void) {
300 307
301void pointer_mode_reset(void) { 308void pointer_mode_reset(void) {
302 switch (pointer_state.mode) { 309 switch (pointer_state.mode) {
303 case M_FLOATING | M_DRAGGING:
304 case M_FLOATING | M_RESIZING: 310 case M_FLOATING | M_RESIZING:
311 case M_FLOATING | M_DRAGGING:
305 reset_initial_view(); 312 reset_initial_view();
306 break; 313 break;
307 314
308 case M_TILING | M_DRAGGING:
309 case M_TILING | M_RESIZING: 315 case M_TILING | M_RESIZING:
316 (void) reset_initial_sibling;
317 break;
318
319 case M_TILING | M_DRAGGING:
310 default: 320 default:
311 return; 321 break;
312 } 322 }
313} 323}
314