diff options
author | taiyu <taiyu.len@gmail.com> | 2015-08-19 00:28:53 -0700 |
---|---|---|
committer | taiyu <taiyu.len@gmail.com> | 2015-08-19 00:28:53 -0700 |
commit | e16a4015ff216594eeb237ef81534bfaea7533d6 (patch) | |
tree | 7e4538ac7d353048181132f3f92f73ae348456af | |
parent | fixed floating_modifier related things (diff) | |
download | sway-e16a4015ff216594eeb237ef81534bfaea7533d6.tar.gz sway-e16a4015ff216594eeb237ef81534bfaea7533d6.tar.zst sway-e16a4015ff216594eeb237ef81534bfaea7533d6.zip |
fixed focus key handler
-rw-r--r-- | include/layout.h | 1 | ||||
-rw-r--r-- | sway/commands.c | 39 | ||||
-rw-r--r-- | sway/handlers.c | 163 | ||||
-rw-r--r-- | sway/layout.c | 12 |
4 files changed, 103 insertions, 112 deletions
diff --git a/include/layout.h b/include/layout.h index 282f92ee..98fdb531 100644 --- a/include/layout.h +++ b/include/layout.h | |||
@@ -10,6 +10,7 @@ extern swayc_t root_container; | |||
10 | void init_layout(void); | 10 | void init_layout(void); |
11 | 11 | ||
12 | void add_child(swayc_t *parent, swayc_t *child); | 12 | void add_child(swayc_t *parent, swayc_t *child); |
13 | void add_floating(swayc_t *ws, swayc_t *child); | ||
13 | // Returns parent container which needs to be rearranged. | 14 | // Returns parent container which needs to be rearranged. |
14 | swayc_t *add_sibling(swayc_t *sibling, swayc_t *child); | 15 | swayc_t *add_sibling(swayc_t *sibling, swayc_t *child); |
15 | swayc_t *replace_child(swayc_t *child, swayc_t *new_child); | 16 | swayc_t *replace_child(swayc_t *child, swayc_t *new_child); |
diff --git a/sway/commands.c b/sway/commands.c index 42d6b173..6e1f1848 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -185,40 +185,23 @@ static bool cmd_floating(struct sway_config *config, int argc, char **argv) { | |||
185 | int i; | 185 | int i; |
186 | // Change from nonfloating to floating | 186 | // Change from nonfloating to floating |
187 | if (!view->is_floating) { | 187 | if (!view->is_floating) { |
188 | view->is_floating = true; | 188 | remove_child(view); |
189 | for (i = 0; i < view->parent->children->length; i++) { | 189 | add_floating(active_workspace,view); |
190 | if (view->parent->children->items[i] == view) { | 190 | view->x = (active_workspace->width - view->width)/2; |
191 | // Try to use desired geometry to set w/h | 191 | view->y = (active_workspace->height - view->height)/2; |
192 | if (view->desired_width != -1) { | 192 | arrange_windows(active_workspace, -1, -1); |
193 | view->width = view->desired_width; | 193 | if (view->desired_width != -1) { |
194 | } | 194 | view->width = view->desired_width; |
195 | if (view->desired_height != -1) { | 195 | } |
196 | view->height = view->desired_height; | 196 | if (view->desired_height != -1) { |
197 | } | 197 | view->height = view->desired_height; |
198 | |||
199 | // Swap from the list of whatever container the view was in | ||
200 | // to the workspace->floating list | ||
201 | list_del(view->parent->children, i); | ||
202 | list_add(active_workspace->floating, view); | ||
203 | destroy_container(view->parent); | ||
204 | |||
205 | // Set the new position of the container and arrange windows | ||
206 | view->x = (active_workspace->width - view->width)/2; | ||
207 | view->y = (active_workspace->height - view->height)/2; | ||
208 | sway_log(L_INFO, "Setting container %p to floating at coordinates X:%d Y:%d, W:%d, H:%d", view, view->x, view->y, view->width, view->height); | ||
209 | // Change parent to active_workspace | ||
210 | view->parent = active_workspace; | ||
211 | arrange_windows(active_workspace, -1, -1); | ||
212 | return true; | ||
213 | } | ||
214 | } | 198 | } |
215 | } else { | 199 | } else { |
216 | // Delete the view from the floating list and unset its is_floating flag | 200 | // Delete the view from the floating list and unset its is_floating flag |
217 | // Using length-1 as the index is safe because the view must be the currently | 201 | // Using length-1 as the index is safe because the view must be the currently |
218 | // focused floating output | 202 | // focused floating output |
219 | list_del(active_workspace->floating, active_workspace->floating->length - 1); | 203 | remove_child(view); |
220 | view->is_floating = false; | 204 | view->is_floating = false; |
221 | active_workspace->focused = NULL; | ||
222 | // Get the properly focused container, and add in the view there | 205 | // Get the properly focused container, and add in the view there |
223 | swayc_t *focused = container_under_pointer(); | 206 | swayc_t *focused = container_under_pointer(); |
224 | // If focused is null, it's because the currently focused container is a workspace | 207 | // If focused is null, it's because the currently focused container is a workspace |
diff --git a/sway/handlers.c b/sway/handlers.c index d5909c8f..3ae33294 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include "focus.h" | 15 | #include "focus.h" |
16 | 16 | ||
17 | uint32_t keys_pressed[32]; | 17 | uint32_t keys_pressed[32]; |
18 | int keys_pressed_length = 0; | ||
18 | 19 | ||
19 | static struct wlc_origin mouse_origin; | 20 | static struct wlc_origin mouse_origin; |
20 | 21 | ||
@@ -23,6 +24,15 @@ static bool dragging = false; | |||
23 | static bool m2_held = false; | 24 | static bool m2_held = false; |
24 | static bool resizing = false; | 25 | static bool resizing = false; |
25 | 26 | ||
27 | static bool floating_mod_pressed(void) { | ||
28 | int i = 0; | ||
29 | while (i < keys_pressed_length) { | ||
30 | if (keys_pressed[i++] == config->floating_mod) | ||
31 | return true; | ||
32 | } | ||
33 | return false; | ||
34 | } | ||
35 | |||
26 | static bool pointer_test(swayc_t *view, void *_origin) { | 36 | static bool pointer_test(swayc_t *view, void *_origin) { |
27 | const struct wlc_origin *origin = _origin; | 37 | const struct wlc_origin *origin = _origin; |
28 | // Determine the output that the view is under | 38 | // 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 | |||
286 | if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) { | 296 | if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) { |
287 | return false; | 297 | return false; |
288 | } | 298 | } |
289 | static uint8_t head = 0; | ||
290 | bool cmd_success = false; | 299 | bool cmd_success = false; |
291 | 300 | ||
292 | struct sway_mode *mode = config->current_mode; | 301 | 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 | |||
295 | 304 | ||
296 | // Find key, if it has been pressed | 305 | // Find key, if it has been pressed |
297 | int mid = 0; | 306 | int mid = 0; |
298 | while (mid < head && keys_pressed[mid] != sym) { | 307 | while (mid < keys_pressed_length && keys_pressed[mid] != sym) { |
299 | ++mid; | 308 | ++mid; |
300 | } | 309 | } |
301 | //Add or remove key depending on state | 310 | //Add or remove key depending on state |
302 | if (state == WLC_KEY_STATE_PRESSED && mid == head && head + 1 < QSIZE) { | 311 | if (state == WLC_KEY_STATE_PRESSED && mid == keys_pressed_length && keys_pressed_length + 1 < QSIZE) { |
303 | keys_pressed[head++] = sym; | 312 | keys_pressed[keys_pressed_length++] = sym; |
304 | } else if (state == WLC_KEY_STATE_RELEASED && mid < head) { | 313 | } else if (state == WLC_KEY_STATE_RELEASED && mid < keys_pressed_length) { |
305 | memmove(keys_pressed + mid, keys_pressed + mid + 1, sizeof*keys_pressed * (--head - mid)); | 314 | memmove(keys_pressed + mid, keys_pressed + mid + 1, sizeof*keys_pressed * (--keys_pressed_length - mid)); |
306 | keys_pressed[head] = 0; | 315 | keys_pressed[keys_pressed_length] = 0; |
307 | } | 316 | } |
308 | // TODO: reminder to check conflicts with mod+q+a versus mod+q | 317 | // TODO: reminder to check conflicts with mod+q+a versus mod+q |
309 | int i; | 318 | int i; |
@@ -317,7 +326,7 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier | |||
317 | match = false; | 326 | match = false; |
318 | xkb_keysym_t *key = binding->keys->items[j]; | 327 | xkb_keysym_t *key = binding->keys->items[j]; |
319 | uint8_t k; | 328 | uint8_t k; |
320 | for (k = 0; k < head; ++k) { | 329 | for (k = 0; k < keys_pressed_length; ++k) { |
321 | if (keys_pressed[k] == *key) { | 330 | if (keys_pressed[k] == *key) { |
322 | match = true; | 331 | match = true; |
323 | break; | 332 | break; |
@@ -333,9 +342,9 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier | |||
333 | int j; | 342 | int j; |
334 | for (j = 0; j < binding->keys->length; ++j) { | 343 | for (j = 0; j < binding->keys->length; ++j) { |
335 | uint8_t k; | 344 | uint8_t k; |
336 | for (k = 0; k < head; ++k) { | 345 | for (k = 0; k < keys_pressed_length; ++k) { |
337 | memmove(keys_pressed + k, keys_pressed + k + 1, sizeof*keys_pressed * (--head - k)); | 346 | memmove(keys_pressed + k, keys_pressed + k + 1, sizeof*keys_pressed * (--keys_pressed_length - k)); |
338 | keys_pressed[head] = 0; | 347 | keys_pressed[keys_pressed_length] = 0; |
339 | break; | 348 | break; |
340 | } | 349 | } |
341 | } | 350 | } |
@@ -355,84 +364,67 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct | |||
355 | static wlc_handle prev_handle = 0; | 364 | static wlc_handle prev_handle = 0; |
356 | mouse_origin = *origin; | 365 | mouse_origin = *origin; |
357 | bool changed_floating = false; | 366 | bool changed_floating = false; |
358 | int i = 0; | ||
359 | if (!active_workspace) { | 367 | if (!active_workspace) { |
360 | return false; | 368 | return false; |
361 | } | 369 | } |
362 | // Do checks to determine if proper keys are being held | 370 | // Do checks to determine if proper keys are being held |
363 | swayc_t *view = active_workspace->focused; | 371 | swayc_t *view = get_focused_view(active_workspace); |
364 | uint32_t edge = 0; | 372 | uint32_t edge = 0; |
365 | if (dragging && view) { | 373 | if (dragging && view && view->is_floating) { |
366 | if (view->is_floating) { | 374 | int dx = mouse_origin.x - prev_pos.x; |
367 | while (keys_pressed[i++]) { | 375 | int dy = mouse_origin.y - prev_pos.y; |
368 | if (keys_pressed[i] == config->floating_mod) { | 376 | view->x += dx; |
369 | int dx = mouse_origin.x - prev_pos.x; | 377 | view->y += dy; |
370 | int dy = mouse_origin.y - prev_pos.y; | 378 | changed_floating = true; |
371 | view->x += dx; | 379 | } else if (resizing && view && view->is_floating) { |
372 | view->y += dy; | 380 | int dx = mouse_origin.x - prev_pos.x; |
373 | changed_floating = true; | 381 | int dy = mouse_origin.y - prev_pos.y; |
374 | break; | 382 | |
375 | } | 383 | // Move and resize the view based on the dx/dy and mouse position |
384 | int midway_x = view->x + view->width/2; | ||
385 | int midway_y = view->y + view->height/2; | ||
386 | if (dx < 0) { | ||
387 | changed_floating = true; | ||
388 | if (mouse_origin.x > midway_x) { | ||
389 | view->width += dx; | ||
390 | edge += WLC_RESIZE_EDGE_RIGHT; | ||
391 | } else { | ||
392 | view->x += dx; | ||
393 | view->width -= dx; | ||
394 | edge += WLC_RESIZE_EDGE_LEFT; | ||
395 | } | ||
396 | } else if (dx > 0){ | ||
397 | changed_floating = true; | ||
398 | if (mouse_origin.x > midway_x) { | ||
399 | view->width += dx; | ||
400 | edge += WLC_RESIZE_EDGE_RIGHT; | ||
401 | } else { | ||
402 | view->x += dx; | ||
403 | view->width -= dx; | ||
404 | edge += WLC_RESIZE_EDGE_LEFT; | ||
376 | } | 405 | } |
377 | } | 406 | } |
378 | } else if (resizing && view) { | ||
379 | if (view->is_floating) { | ||
380 | while (keys_pressed[i++]) { | ||
381 | if (keys_pressed[i] == config->floating_mod) { | ||
382 | int dx = mouse_origin.x - prev_pos.x; | ||
383 | int dy = mouse_origin.y - prev_pos.y; | ||
384 | |||
385 | // Move and resize the view based on the dx/dy and mouse position | ||
386 | int midway_x = view->x + view->width/2; | ||
387 | int midway_y = view->y + view->height/2; | ||
388 | |||
389 | |||
390 | if (dx < 0) { | ||
391 | changed_floating = true; | ||
392 | if (mouse_origin.x > midway_x) { | ||
393 | view->width += dx; | ||
394 | edge += WLC_RESIZE_EDGE_RIGHT; | ||
395 | } else { | ||
396 | view->x += dx; | ||
397 | view->width -= dx; | ||
398 | edge += WLC_RESIZE_EDGE_LEFT; | ||
399 | } | ||
400 | } else if (dx > 0){ | ||
401 | changed_floating = true; | ||
402 | if (mouse_origin.x > midway_x) { | ||
403 | view->width += dx; | ||
404 | edge += WLC_RESIZE_EDGE_RIGHT; | ||
405 | } else { | ||
406 | view->x += dx; | ||
407 | view->width -= dx; | ||
408 | edge += WLC_RESIZE_EDGE_LEFT; | ||
409 | } | ||
410 | } | ||
411 | 407 | ||
412 | if (dy < 0) { | 408 | if (dy < 0) { |
413 | changed_floating = true; | 409 | changed_floating = true; |
414 | if (mouse_origin.y > midway_y) { | 410 | if (mouse_origin.y > midway_y) { |
415 | view->height += dy; | 411 | view->height += dy; |
416 | edge += WLC_RESIZE_EDGE_BOTTOM; | 412 | edge += WLC_RESIZE_EDGE_BOTTOM; |
417 | } else { | 413 | } else { |
418 | view->y += dy; | 414 | view->y += dy; |
419 | view->height -= dy; | 415 | view->height -= dy; |
420 | edge += WLC_RESIZE_EDGE_TOP; | 416 | edge += WLC_RESIZE_EDGE_TOP; |
421 | } | 417 | } |
422 | } else if (dy > 0) { | 418 | } else if (dy > 0) { |
423 | changed_floating = true; | 419 | changed_floating = true; |
424 | if (mouse_origin.y > midway_y) { | 420 | if (mouse_origin.y > midway_y) { |
425 | view->height += dy; | 421 | view->height += dy; |
426 | edge += WLC_RESIZE_EDGE_BOTTOM; | 422 | edge += WLC_RESIZE_EDGE_BOTTOM; |
427 | } else { | 423 | } else { |
428 | edge = WLC_RESIZE_EDGE_BOTTOM; | 424 | edge = WLC_RESIZE_EDGE_BOTTOM; |
429 | view->y += dy; | 425 | view->y += dy; |
430 | view->height -= dy; | 426 | view->height -= dy; |
431 | edge += WLC_RESIZE_EDGE_TOP; | 427 | edge += WLC_RESIZE_EDGE_TOP; |
432 | } | ||
433 | } | ||
434 | break; | ||
435 | } | ||
436 | } | 428 | } |
437 | } | 429 | } |
438 | } | 430 | } |
@@ -489,9 +481,12 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w | |||
489 | } | 481 | } |
490 | } | 482 | } |
491 | arrange_windows(pointer->parent, -1, -1); | 483 | arrange_windows(pointer->parent, -1, -1); |
492 | dragging = m1_held; | 484 | if (floating_mod_pressed()) { |
493 | resizing = m2_held; | 485 | dragging = m1_held; |
494 | return true; | 486 | resizing = m2_held; |
487 | } | ||
488 | //Dont want pointer sent to window while dragging or resizing | ||
489 | return (dragging || resizing); | ||
495 | } | 490 | } |
496 | return (pointer && pointer != focused); | 491 | return (pointer && pointer != focused); |
497 | } else { | 492 | } else { |
diff --git a/sway/layout.c b/sway/layout.c index e2e12901..7125ffc3 100644 --- a/sway/layout.c +++ b/sway/layout.c | |||
@@ -38,6 +38,17 @@ void add_child(swayc_t *parent, swayc_t *child) { | |||
38 | } | 38 | } |
39 | } | 39 | } |
40 | 40 | ||
41 | void add_floating(swayc_t *ws, swayc_t *child) { | ||
42 | sway_log(L_DEBUG, "Adding %p (%d, %dx%d) to %p (%d, %dx%d)", child, child->type, | ||
43 | child->width, child->height, ws, ws->type, ws->width, ws->height); | ||
44 | list_add(ws->floating, child); | ||
45 | child->parent = ws; | ||
46 | child->is_floating = true; | ||
47 | if (!ws->focused) { | ||
48 | ws->focused = child; | ||
49 | } | ||
50 | } | ||
51 | |||
41 | swayc_t *add_sibling(swayc_t *sibling, swayc_t *child) { | 52 | swayc_t *add_sibling(swayc_t *sibling, swayc_t *child) { |
42 | swayc_t *parent = sibling->parent; | 53 | swayc_t *parent = sibling->parent; |
43 | int i = index_child(parent, sibling); | 54 | int i = index_child(parent, sibling); |
@@ -76,6 +87,7 @@ swayc_t *remove_child(swayc_t *child) { | |||
76 | break; | 87 | break; |
77 | } | 88 | } |
78 | } | 89 | } |
90 | i = 0; | ||
79 | } else { | 91 | } else { |
80 | for (i = 0; i < parent->children->length; ++i) { | 92 | for (i = 0; i < parent->children->length; ++i) { |
81 | if (parent->children->items[i] == child) { | 93 | if (parent->children->items[i] == child) { |