diff options
author | Ian Fan <ianfan0@gmail.com> | 2018-10-10 12:23:04 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-10 12:23:04 +0000 |
commit | cd6917d4a821fe904a2c242dff673967aa3ad4b2 (patch) | |
tree | e21f0b633212c6b8084348f08fc68cec2efece8b | |
parent | bar-bindsym: address ianyfan's comments (diff) | |
parent | Merge pull request #2814 from Emantor/mouse-warping-container (diff) | |
download | sway-cd6917d4a821fe904a2c242dff673967aa3ad4b2.tar.gz sway-cd6917d4a821fe904a2c242dff673967aa3ad4b2.tar.zst sway-cd6917d4a821fe904a2c242dff673967aa3ad4b2.zip |
Merge branch 'master' into bar-bindsym
-rw-r--r-- | include/sway/commands.h | 2 | ||||
-rw-r--r-- | include/sway/config.h | 8 | ||||
-rw-r--r-- | sway/commands/mouse_warping.c | 8 | ||||
-rw-r--r-- | sway/commands/resize.c | 26 | ||||
-rw-r--r-- | sway/config.c | 2 | ||||
-rw-r--r-- | sway/input/cursor.c | 1 | ||||
-rw-r--r-- | sway/input/seat.c | 21 | ||||
-rw-r--r-- | sway/sway.5.scd | 7 | ||||
-rw-r--r-- | sway/tree/container.c | 12 | ||||
-rw-r--r-- | sway/tree/view.c | 4 | ||||
-rw-r--r-- | sway/tree/workspace.c | 5 | ||||
-rw-r--r-- | swaybar/main.c | 2 | ||||
-rw-r--r-- | swaymsg/main.c | 2 |
13 files changed, 63 insertions, 37 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h index 48228a98..ab2da1a9 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h | |||
@@ -95,7 +95,7 @@ struct cmd_results *add_color(const char *name, | |||
95 | /** | 95 | /** |
96 | * TODO: Move this function and its dependent functions to container.c. | 96 | * TODO: Move this function and its dependent functions to container.c. |
97 | */ | 97 | */ |
98 | bool container_resize_tiled(struct sway_container *parent, enum wlr_edges edge, | 98 | void container_resize_tiled(struct sway_container *parent, enum wlr_edges edge, |
99 | int amount); | 99 | int amount); |
100 | 100 | ||
101 | sway_cmd cmd_assign; | 101 | sway_cmd cmd_assign; |
diff --git a/include/sway/config.h b/include/sway/config.h index 549d2677..bc02c0fd 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -331,6 +331,12 @@ enum focus_wrapping_mode { | |||
331 | WRAP_FORCE | 331 | WRAP_FORCE |
332 | }; | 332 | }; |
333 | 333 | ||
334 | enum mouse_warping_mode { | ||
335 | WARP_NO, | ||
336 | WARP_OUTPUT, | ||
337 | WARP_CONTAINER | ||
338 | }; | ||
339 | |||
334 | /** | 340 | /** |
335 | * The configuration struct. The result of loading a config file. | 341 | * The configuration struct. The result of loading a config file. |
336 | */ | 342 | */ |
@@ -372,7 +378,7 @@ struct sway_config { | |||
372 | // Flags | 378 | // Flags |
373 | bool focus_follows_mouse; | 379 | bool focus_follows_mouse; |
374 | bool raise_floating; | 380 | bool raise_floating; |
375 | bool mouse_warping; | 381 | enum mouse_warping_mode mouse_warping; |
376 | enum focus_wrapping_mode focus_wrapping; | 382 | enum focus_wrapping_mode focus_wrapping; |
377 | bool active; | 383 | bool active; |
378 | bool failed; | 384 | bool failed; |
diff --git a/sway/commands/mouse_warping.c b/sway/commands/mouse_warping.c index eef32ce7..d067bc65 100644 --- a/sway/commands/mouse_warping.c +++ b/sway/commands/mouse_warping.c | |||
@@ -6,13 +6,15 @@ struct cmd_results *cmd_mouse_warping(int argc, char **argv) { | |||
6 | struct cmd_results *error = NULL; | 6 | struct cmd_results *error = NULL; |
7 | if ((error = checkarg(argc, "mouse_warping", EXPECTED_EQUAL_TO, 1))) { | 7 | if ((error = checkarg(argc, "mouse_warping", EXPECTED_EQUAL_TO, 1))) { |
8 | return error; | 8 | return error; |
9 | } else if (strcasecmp(argv[0], "container") == 0) { | ||
10 | config->mouse_warping = WARP_CONTAINER; | ||
9 | } else if (strcasecmp(argv[0], "output") == 0) { | 11 | } else if (strcasecmp(argv[0], "output") == 0) { |
10 | config->mouse_warping = true; | 12 | config->mouse_warping = WARP_OUTPUT; |
11 | } else if (strcasecmp(argv[0], "none") == 0) { | 13 | } else if (strcasecmp(argv[0], "none") == 0) { |
12 | config->mouse_warping = false; | 14 | config->mouse_warping = WARP_NO; |
13 | } else { | 15 | } else { |
14 | return cmd_results_new(CMD_FAILURE, "mouse_warping", | 16 | return cmd_results_new(CMD_FAILURE, "mouse_warping", |
15 | "Expected 'mouse_warping output|none'"); | 17 | "Expected 'mouse_warping output|container|none'"); |
16 | } | 18 | } |
17 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 19 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
18 | } | 20 | } |
diff --git a/sway/commands/resize.c b/sway/commands/resize.c index 1343b165..6de14ca3 100644 --- a/sway/commands/resize.c +++ b/sway/commands/resize.c | |||
@@ -179,11 +179,11 @@ static void container_recursive_resize(struct sway_container *container, | |||
179 | } | 179 | } |
180 | } | 180 | } |
181 | 181 | ||
182 | static bool resize_tiled(struct sway_container *parent, int amount, | 182 | static void resize_tiled(struct sway_container *parent, int amount, |
183 | enum resize_axis axis) { | 183 | enum resize_axis axis) { |
184 | struct sway_container *focused = parent; | 184 | struct sway_container *focused = parent; |
185 | if (!parent) { | 185 | if (!parent) { |
186 | return false; | 186 | return; |
187 | } | 187 | } |
188 | 188 | ||
189 | enum sway_container_layout parallel_layout = | 189 | enum sway_container_layout parallel_layout = |
@@ -216,7 +216,7 @@ static bool resize_tiled(struct sway_container *parent, int amount, | |||
216 | } | 216 | } |
217 | if (!parent) { | 217 | if (!parent) { |
218 | // Can't resize in this direction | 218 | // Can't resize in this direction |
219 | return false; | 219 | return; |
220 | } | 220 | } |
221 | 221 | ||
222 | // Implement up/down/left/right direction by zeroing one of the weights, | 222 | // Implement up/down/left/right direction by zeroing one of the weights, |
@@ -248,22 +248,22 @@ static bool resize_tiled(struct sway_container *parent, int amount, | |||
248 | if (sibling_pos < parent_pos && minor_weight) { | 248 | if (sibling_pos < parent_pos && minor_weight) { |
249 | double pixels = -amount / minor_weight; | 249 | double pixels = -amount / minor_weight; |
250 | if (major_weight && (sibling_size + pixels / 2) < min_sane) { | 250 | if (major_weight && (sibling_size + pixels / 2) < min_sane) { |
251 | return false; // Too small | 251 | return; // Too small |
252 | } else if (!major_weight && sibling_size + pixels < min_sane) { | 252 | } else if (!major_weight && sibling_size + pixels < min_sane) { |
253 | return false; // Too small | 253 | return; // Too small |
254 | } | 254 | } |
255 | } else if (sibling_pos > parent_pos && major_weight) { | 255 | } else if (sibling_pos > parent_pos && major_weight) { |
256 | double pixels = -amount / major_weight; | 256 | double pixels = -amount / major_weight; |
257 | if (minor_weight && (sibling_size + pixels / 2) < min_sane) { | 257 | if (minor_weight && (sibling_size + pixels / 2) < min_sane) { |
258 | return false; // Too small | 258 | return; // Too small |
259 | } else if (!minor_weight && sibling_size + pixels < min_sane) { | 259 | } else if (!minor_weight && sibling_size + pixels < min_sane) { |
260 | return false; // Too small | 260 | return; // Too small |
261 | } | 261 | } |
262 | } | 262 | } |
263 | } else { | 263 | } else { |
264 | double pixels = amount; | 264 | double pixels = amount; |
265 | if (parent_size + pixels < min_sane) { | 265 | if (parent_size + pixels < min_sane) { |
266 | return false; // Too small | 266 | return; // Too small |
267 | } | 267 | } |
268 | } | 268 | } |
269 | } | 269 | } |
@@ -317,10 +317,9 @@ static bool resize_tiled(struct sway_container *parent, int amount, | |||
317 | } else { | 317 | } else { |
318 | arrange_workspace(parent->workspace); | 318 | arrange_workspace(parent->workspace); |
319 | } | 319 | } |
320 | return true; | ||
321 | } | 320 | } |
322 | 321 | ||
323 | bool container_resize_tiled(struct sway_container *parent, | 322 | void container_resize_tiled(struct sway_container *parent, |
324 | enum wlr_edges edge, int amount) { | 323 | enum wlr_edges edge, int amount) { |
325 | enum resize_axis axis = RESIZE_AXIS_INVALID; | 324 | enum resize_axis axis = RESIZE_AXIS_INVALID; |
326 | switch (edge) { | 325 | switch (edge) { |
@@ -339,7 +338,7 @@ bool container_resize_tiled(struct sway_container *parent, | |||
339 | case WLR_EDGE_NONE: | 338 | case WLR_EDGE_NONE: |
340 | break; | 339 | break; |
341 | } | 340 | } |
342 | return resize_tiled(parent, amount, axis); | 341 | resize_tiled(parent, amount, axis); |
343 | } | 342 | } |
344 | 343 | ||
345 | /** | 344 | /** |
@@ -447,7 +446,10 @@ static struct cmd_results *resize_adjust_tiled(enum resize_axis axis, | |||
447 | } | 446 | } |
448 | } | 447 | } |
449 | 448 | ||
450 | if (!resize_tiled(current, amount->amount, axis)) { | 449 | double old_width = current->width; |
450 | double old_height = current->height; | ||
451 | resize_tiled(current, amount->amount, axis); | ||
452 | if (current->width == old_width && current->height == old_height) { | ||
451 | return cmd_results_new(CMD_INVALID, "resize", | 453 | return cmd_results_new(CMD_INVALID, "resize", |
452 | "Cannot resize any further"); | 454 | "Cannot resize any further"); |
453 | } | 455 | } |
diff --git a/sway/config.c b/sway/config.c index 1926bc08..f239ba1d 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -223,7 +223,7 @@ static void config_defaults(struct sway_config *config) { | |||
223 | // Flags | 223 | // Flags |
224 | config->focus_follows_mouse = true; | 224 | config->focus_follows_mouse = true; |
225 | config->raise_floating = true; | 225 | config->raise_floating = true; |
226 | config->mouse_warping = true; | 226 | config->mouse_warping = WARP_OUTPUT; |
227 | config->focus_wrapping = WRAP_YES; | 227 | config->focus_wrapping = WRAP_YES; |
228 | config->validating = false; | 228 | config->validating = false; |
229 | config->reloading = false; | 229 | config->reloading = false; |
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 6d57c45f..5c446299 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c | |||
@@ -877,6 +877,7 @@ void dispatch_cursor_button(struct sway_cursor *cursor, | |||
877 | while (cont->parent) { | 877 | while (cont->parent) { |
878 | cont = cont->parent; | 878 | cont = cont->parent; |
879 | } | 879 | } |
880 | seat_set_focus_container(seat, cont); | ||
880 | seat_begin_move_floating(seat, cont, button); | 881 | seat_begin_move_floating(seat, cont, button); |
881 | return; | 882 | return; |
882 | } | 883 | } |
diff --git a/sway/input/seat.c b/sway/input/seat.c index f418785d..03ed638e 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c | |||
@@ -772,7 +772,9 @@ void seat_set_focus_warp(struct sway_seat *seat, struct sway_node *node, | |||
772 | } | 772 | } |
773 | 773 | ||
774 | if (last_focus) { | 774 | if (last_focus) { |
775 | if (config->mouse_warping && warp && new_output != last_output) { | 775 | if (config->mouse_warping && warp && |
776 | (new_output != last_output || | ||
777 | config->mouse_warping == WARP_CONTAINER)) { | ||
776 | double x = 0; | 778 | double x = 0; |
777 | double y = 0; | 779 | double y = 0; |
778 | if (container) { | 780 | if (container) { |
@@ -782,9 +784,11 @@ void seat_set_focus_warp(struct sway_seat *seat, struct sway_node *node, | |||
782 | x = new_workspace->x + new_workspace->width / 2.0; | 784 | x = new_workspace->x + new_workspace->width / 2.0; |
783 | y = new_workspace->y + new_workspace->height / 2.0; | 785 | y = new_workspace->y + new_workspace->height / 2.0; |
784 | } | 786 | } |
787 | |||
785 | if (!wlr_output_layout_contains_point(root->output_layout, | 788 | if (!wlr_output_layout_contains_point(root->output_layout, |
786 | new_output->wlr_output, seat->cursor->cursor->x, | 789 | new_output->wlr_output, seat->cursor->cursor->x, |
787 | seat->cursor->cursor->y)) { | 790 | seat->cursor->cursor->y) |
791 | || config->mouse_warping == WARP_CONTAINER) { | ||
788 | wlr_cursor_warp(seat->cursor->cursor, NULL, x, y); | 792 | wlr_cursor_warp(seat->cursor->cursor, NULL, x, y); |
789 | cursor_send_pointer_motion(seat->cursor, 0, true); | 793 | cursor_send_pointer_motion(seat->cursor, 0, true); |
790 | } | 794 | } |
@@ -1038,7 +1042,7 @@ void seat_begin_down(struct sway_seat *seat, struct sway_container *con, | |||
1038 | seat->op_moved = false; | 1042 | seat->op_moved = false; |
1039 | 1043 | ||
1040 | // In case the container was not raised by gaining focus, raise on click | 1044 | // In case the container was not raised by gaining focus, raise on click |
1041 | if (con && !config->raise_floating) { | 1045 | if (!config->raise_floating) { |
1042 | container_raise_floating(con); | 1046 | container_raise_floating(con); |
1043 | } | 1047 | } |
1044 | } | 1048 | } |
@@ -1052,6 +1056,12 @@ void seat_begin_move_floating(struct sway_seat *seat, | |||
1052 | seat->operation = OP_MOVE_FLOATING; | 1056 | seat->operation = OP_MOVE_FLOATING; |
1053 | seat->op_container = con; | 1057 | seat->op_container = con; |
1054 | seat->op_button = button; | 1058 | seat->op_button = button; |
1059 | |||
1060 | // In case the container was not raised by gaining focus, raise on click | ||
1061 | if (!config->raise_floating) { | ||
1062 | container_raise_floating(con); | ||
1063 | } | ||
1064 | |||
1055 | cursor_set_image(seat->cursor, "grab", NULL); | 1065 | cursor_set_image(seat->cursor, "grab", NULL); |
1056 | } | 1066 | } |
1057 | 1067 | ||
@@ -1085,6 +1095,11 @@ void seat_begin_resize_floating(struct sway_seat *seat, | |||
1085 | seat->op_ref_con_ly = con->y; | 1095 | seat->op_ref_con_ly = con->y; |
1086 | seat->op_ref_width = con->width; | 1096 | seat->op_ref_width = con->width; |
1087 | seat->op_ref_height = con->height; | 1097 | seat->op_ref_height = con->height; |
1098 | // | ||
1099 | // In case the container was not raised by gaining focus, raise on click | ||
1100 | if (!config->raise_floating) { | ||
1101 | container_raise_floating(con); | ||
1102 | } | ||
1088 | 1103 | ||
1089 | const char *image = edge == WLR_EDGE_NONE ? | 1104 | const char *image = edge == WLR_EDGE_NONE ? |
1090 | "se-resize" : wlr_xcursor_get_resize_name(edge); | 1105 | "se-resize" : wlr_xcursor_get_resize_name(edge); |
diff --git a/sway/sway.5.scd b/sway/sway.5.scd index 28ab15df..240e0731 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd | |||
@@ -492,9 +492,10 @@ The default colors are: | |||
492 | If _--pango\_markup_ is given, then _mode_ will be interpreted as pango | 492 | If _--pango\_markup_ is given, then _mode_ will be interpreted as pango |
493 | markup. | 493 | markup. |
494 | 494 | ||
495 | *mouse\_warping* output|none | 495 | *mouse\_warping* output|container|none |
496 | If _output_ is specified, the mouse will be moved to new outputs as you | 496 | If _output_ is specified, the mouse will be moved to new outputs as you |
497 | move focus between them. Default is _output_. | 497 | move focus between them. If _container_ is specified, the mouse will be |
498 | moved to the middle of the container on switch. Default is _output_. | ||
498 | 499 | ||
499 | *no\_focus* <criteria> | 500 | *no\_focus* <criteria> |
500 | Prevents windows matching <criteria> from being focused automatically when | 501 | Prevents windows matching <criteria> from being focused automatically when |
@@ -598,7 +599,7 @@ match any output by using the output name "\*". | |||
598 | *workspace* prev\_on\_output|next\_on\_output | 599 | *workspace* prev\_on\_output|next\_on\_output |
599 | Switches to the next workspace on the current output. | 600 | Switches to the next workspace on the current output. |
600 | 601 | ||
601 | *workspace* back_and_forth | 602 | *workspace* back\_and\_forth |
602 | Switches to the previously focused workspace. | 603 | Switches to the previously focused workspace. |
603 | 604 | ||
604 | *workspace* <name> gaps inner|outer <amount> | 605 | *workspace* <name> gaps inner|outer <amount> |
diff --git a/sway/tree/container.c b/sway/tree/container.c index 1664514a..f36fe4b0 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -358,7 +358,6 @@ struct sway_container *container_at(struct sway_workspace *workspace, | |||
358 | struct wlr_surface **surface, double *sx, double *sy) { | 358 | struct wlr_surface **surface, double *sx, double *sy) { |
359 | struct sway_container *c; | 359 | struct sway_container *c; |
360 | 360 | ||
361 | // Focused view's popups | ||
362 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 361 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
363 | struct sway_container *focus = seat_get_focused_container(seat); | 362 | struct sway_container *focus = seat_get_focused_container(seat); |
364 | bool is_floating = focus && container_is_floating_or_child(focus); | 363 | bool is_floating = focus && container_is_floating_or_child(focus); |
@@ -370,14 +369,11 @@ struct sway_container *container_at(struct sway_workspace *workspace, | |||
370 | } | 369 | } |
371 | *surface = NULL; | 370 | *surface = NULL; |
372 | } | 371 | } |
373 | // Cast a ray to handle floating windows | 372 | // Floating |
374 | for (int i = workspace->floating->length - 1; i >= 0; --i) { | 373 | if ((c = floating_container_at(lx, ly, surface ,sx ,sy))) { |
375 | struct sway_container *cn = workspace->floating->items[i]; | 374 | return c; |
376 | if (cn->view && (c = surface_at_view(cn, lx, ly, surface, sx, sy))) { | ||
377 | return c; | ||
378 | } | ||
379 | } | 375 | } |
380 | // If focused is tiling, focused view's non-popups | 376 | // Tiling (focused) |
381 | if (focus && focus->view && !is_floating) { | 377 | if (focus && focus->view && !is_floating) { |
382 | if ((c = surface_at_view(focus, lx, ly, surface, sx, sy))) { | 378 | if ((c = surface_at_view(focus, lx, ly, surface, sx, sy))) { |
383 | return c; | 379 | return c; |
diff --git a/sway/tree/view.c b/sway/tree/view.c index 1f00452d..e613ac0b 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -243,10 +243,10 @@ void view_autoconfigure(struct sway_view *view) { | |||
243 | // title area. We have to offset the surface y by the height of the title, | 243 | // title area. We have to offset the surface y by the height of the title, |
244 | // bar, and disable any top border because we'll always have the title bar. | 244 | // bar, and disable any top border because we'll always have the title bar. |
245 | enum sway_container_layout layout = container_parent_layout(con); | 245 | enum sway_container_layout layout = container_parent_layout(con); |
246 | if (layout == L_TABBED) { | 246 | if (layout == L_TABBED && !container_is_floating(con)) { |
247 | y_offset = container_titlebar_height(); | 247 | y_offset = container_titlebar_height(); |
248 | view->border_top = false; | 248 | view->border_top = false; |
249 | } else if (layout == L_STACKED) { | 249 | } else if (layout == L_STACKED && !container_is_floating(con)) { |
250 | list_t *siblings = container_get_siblings(con); | 250 | list_t *siblings = container_get_siblings(con); |
251 | y_offset = container_titlebar_height() * siblings->length; | 251 | y_offset = container_titlebar_height() * siblings->length; |
252 | view->border_top = false; | 252 | view->border_top = false; |
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index b357d83d..d7650560 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c | |||
@@ -624,7 +624,10 @@ void workspace_add_gaps(struct sway_workspace *ws) { | |||
624 | if (config->smart_gaps) { | 624 | if (config->smart_gaps) { |
625 | struct sway_seat *seat = input_manager_get_default_seat(input_manager); | 625 | struct sway_seat *seat = input_manager_get_default_seat(input_manager); |
626 | struct sway_container *focus = | 626 | struct sway_container *focus = |
627 | seat_get_focus_inactive_view(seat, &ws->node); | 627 | seat_get_focus_inactive_tiling(seat, ws); |
628 | if (focus && !focus->view) { | ||
629 | focus = seat_get_focus_inactive_view(seat, &focus->node); | ||
630 | } | ||
628 | if (focus && focus->view && view_is_only_visible(focus->view)) { | 631 | if (focus && focus->view && view_is_only_visible(focus->view)) { |
629 | return; | 632 | return; |
630 | } | 633 | } |
diff --git a/swaybar/main.c b/swaybar/main.c index d2c579db..db204f4a 100644 --- a/swaybar/main.c +++ b/swaybar/main.c | |||
@@ -62,7 +62,7 @@ int main(int argc, char **argv) { | |||
62 | bar_id = strdup(optarg); | 62 | bar_id = strdup(optarg); |
63 | break; | 63 | break; |
64 | case 'v': | 64 | case 'v': |
65 | fprintf(stdout, "sway version " SWAY_VERSION "\n"); | 65 | fprintf(stdout, "swaybar version " SWAY_VERSION "\n"); |
66 | exit(EXIT_SUCCESS); | 66 | exit(EXIT_SUCCESS); |
67 | break; | 67 | break; |
68 | case 'd': // Debug | 68 | case 'd': // Debug |
diff --git a/swaymsg/main.c b/swaymsg/main.c index 3767daf3..4688737c 100644 --- a/swaymsg/main.c +++ b/swaymsg/main.c | |||
@@ -345,7 +345,7 @@ int main(int argc, char **argv) { | |||
345 | cmdtype = strdup(optarg); | 345 | cmdtype = strdup(optarg); |
346 | break; | 346 | break; |
347 | case 'v': | 347 | case 'v': |
348 | fprintf(stdout, "sway version " SWAY_VERSION "\n"); | 348 | fprintf(stdout, "swaymsg version " SWAY_VERSION "\n"); |
349 | exit(EXIT_SUCCESS); | 349 | exit(EXIT_SUCCESS); |
350 | break; | 350 | break; |
351 | default: | 351 | default: |