Commit graph

76 commits

Author SHA1 Message Date
Ryan Dwyer 93624599b3 Remove move_out_of_tabs_stacks
This fixes the following. Create these layouts and run move right:

(Initial layout -> expected result -> actual result)

* `H[S[unfocused focused] unfocused]` ->
`H[S[unfocused] focused unfocused]` ->
`H[H[S[unfocused] focused] unfocused]`
* `H[S[unfocused focused] V[unfocused]]` ->
`H[S[unfocused] V[unfocused focused]]` ->
`H[H[S[unfocused] focused] V[unfocused]]`

move_out_of_tabs_stacks was originally made to allow views to move out
of the tabbed/stacked container in the parallel direction, but at some
point this has started working using the regular logic.
2018-09-23 13:10:36 +10:00
William Wold f48999dd24 Fix crash moving out of tab container 2018-09-17 01:20:45 -07:00
Ryan Dwyer f6e218a643 Rename seat_get_active_child to seat_get_active_tiling_child
Also renames container to con in one function to prevent ugly line
wrapping.
2018-09-16 22:01:54 +10:00
Ryan Dwyer 2f6935e00f Remove bad assertion in workspace_rejigger
The assertion can be (rightfully) triggered by creating layout
V[H[view view] view] and moving the top right view to the right.

After removing the assertion I found the container being moved needs its
size reset to prevent it from being sized wrongly after arranging.
2018-09-13 17:02:10 +10:00
emersion af9e8f94cc
Merge pull request #2620 from ianyfan/commands
commands: when moving a container, restore focus properly
2018-09-12 09:20:47 +02:00
Ian Fan ae535396b0 commands: when moving container, remove its gaps 2018-09-11 16:46:11 +01:00
Ian Fan c770949a9f commands: when moving container, restore focus properly 2018-09-11 16:46:07 +01:00
Ryan Dwyer 8bb40c24c7 Implement tiling drag
Hold floating_modifier and drag a tiling view to a new location.
2018-09-11 21:34:21 +10:00
Ryan Dwyer 908095ef9a Introduce seat_set_focus_container and seat_set_focus_workspace
These are the same as seat_set_focus, but accept a specific type rather
than using nodes. Doing this adds more typesafety and lets us avoid
using &con->node which looks a little ugly.

This fixes a crash that pretty much nobody would ever come across. If
you have a bindsym for "focus" with no arguments and run it from an
empty workspace, sway would crash because it assumes `container` is not
NULL.
2018-09-06 19:26:56 +10:00
Ryan Dwyer 01117db6d9 Fix crash when moving view across outputs
It was incorrectly determining that the container being moved and the
destination had the same parent, which resulted in tree corruption. Both
parents can be NULL but the containers may belong to different
workspaces.

To reproduce, create layout H[V[view] view] in one workspace then move a
view left or right from another output into that workspace.
2018-09-06 11:53:55 +10:00
Ryan Dwyer dbf4aa3e33 Allow marked containers to be moved out of the scratchpad via move command 2018-09-05 18:01:43 +10:00
Ryan Dwyer 9d168a693d Fix moving workspace to output 2018-09-05 18:01:43 +10:00
Ryan Dwyer 06d9693829 Remove offset argument to container_add_sibling
I added this thinking that it might come in useful. Turns out it didn't.
2018-09-05 18:01:43 +10:00
Ryan Dwyer 7586f150c0 Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers
to layout containers and view containers. Workspaces, outputs and the
root are no longer known as containers. Instead, root, outputs,
workspaces and containers are all a type of node, and containers come in
two types: layout containers and view containers.

In addition to the above, this implements type safe variables. This
means we use specific types such as sway_output and sway_workspace
instead of generic containers or nodes. However, it's worth noting that
in a few places places (eg. seat focus and transactions) referring to
them in a generic way is unavoidable which is why we still use nodes in
some places.

If you want a TL;DR, look at node.h, as well as the struct definitions
for root, output, workspace and container. Note that sway_output now
contains a workspaces list, and workspaces now contain a tiling and
floating list, and containers now contain a pointer back to the
workspace.

There are now functions for seat_get_focused_workspace and
seat_get_focused_container. The latter will return NULL if a workspace
itself is focused. Most other seat functions like seat_get_focus and
seat_set_focus now accept and return nodes.

In the config->handler_context struct, current_container has been
replaced with three pointers: node, container and workspace. node is the
same as what current_container was, while workspace is the workspace
that the node resides on and container is the actual container, which
may be NULL if a workspace itself is focused.

The global root_container variable has been replaced with one simply
called root, which is a pointer to the sway_root instance.

The way outputs are created, enabled, disabled and destroyed has
changed. Previously we'd wrap the sway_output in a container when it is
enabled, but as we don't have containers any more it needs a different
approach. The output_create and output_destroy functions previously
created/destroyed the container, but now they create/destroy the
sway_output. There is a new function output_disable to disable an output
without destroying it.

Containers have a new view property. If this is populated then the
container is a view container, otherwise it's a layout container. Like
before, this property is immutable for the life of the container.

Containers have both a `sway_container *parent` and
`sway_workspace *workspace`. As we use specific types now, parent cannot
point to a workspace so it'll be NULL for containers which are direct
children of the workspace. The workspace property is set for all
containers, except those which are hidden in the scratchpad as they have
no workspace.

In some cases we need to refer to workspaces in a container-like way.
For example, workspaces have layout and children, but when using
specific types this makes it difficult. Likewise, it's difficult for a
container to get its parent's layout when the parent could be another
container or a workspace. To make it easier, some helper functions have
been created: container_parent_layout and container_get_siblings.

container_remove_child has been renamed to container_detach and
container_replace_child has been renamed to container_replace.

`container_handle_fullscreen_reparent(con, old_parent)` has had the
old_parent removed. We now unfullscreen the workspace when detaching the
container, so this function is simplified and only needs one argument
now.

container_notify_subtree_changed has been renamed to
container_update_representation. This is more descriptive of its
purpose. I also wanted to be able to call it with whatever container was
changed rather than the container's parent, which makes bubbling up to
the workspace easier.

There are now state structs per node thing. ie. sway_output_state,
sway_workspace_state and sway_container_state.

The focus, move and layout commands have been completely refactored to
work with the specific types. I considered making these a separate PR,
but I'd be backporting my changes only to replace them again, and it's
easier just to test everything at once.
2018-09-05 18:01:43 +10:00
Ian Fan bc30f2d528 commands: fix moving container to different output
When moving a container to an inactive workspace on a different output, this will change the focus on the destination output back to its last active workspace
2018-08-28 15:08:46 +01:00
Scott Anderson 31c3c8a365 Initialise variable properly 2018-08-27 18:01:17 +12:00
Ryan Dwyer 5dbbab7bdc Remove layout.c
When we have type safety we'll need to have functions for
workspace_add_tiling and so on. This means the existing container
functions will be just for containers, so they are being moved to
container.c. At this point layout.c doesn't contain much else, so I've
relocated everything and removed the file.

* container_swap and its static functions have been moved to the swap
command and made static.
* container_recursive_resize has been moved to the resize command and
made static.
* The following have been moved to container.c:
    * container_handle_fullscreen_reparent
    * container_insert_child
    * container_add_sibling
    * container_add_child
    * container_remove_child
    * container_replace_child
    * container_split
* enum movement_direction and sway_dir_to_wlr have been moved to util.c.

Side note: Several commands included layout.h which then included
root.h. With layout.h gone, root.h has to be included by those commands.
2018-08-26 12:05:16 +10:00
Armin Preiml 1a72149d88 Workspace move cycle
On move workspace to direction: Try the farthest on the opposite
direction if no workspace is found at given direction.
2018-08-25 17:10:41 +02:00
Drew DeVault b945957b9b
Merge pull request #2510 from RyanDwyer/relocate-layout-functions
Relocate container_move, container_move_to and container_get_in_direction
2018-08-25 09:38:33 -04:00
Ryan Dwyer 4b9ad9c238
Merge branch 'master' into commands 2018-08-25 13:06:04 +10:00
Ryan Dwyer f4bc25bcc6 Relocate container_move, container_move_to and container_get_in_direction
* container_move is only called from the move command
* container_move_to was called from both the move command and the sticky
command, but the sticky command can easily not call it
* container_get_in_direction is only called from the focus command

Moving these functions to their respective commands gives better
separation of code and removes bloat from layout.c. These functions will
need to be refactored to take advantage of type safety, so separating
them will make this easier to refactor.

The following static functions have also been moved:

* is_parellel
* invert_movement
* move_offs
* container_limit
* workspace_rejigger
* move_out_of_tabs_stacks
* get_swayc_in_output_direction

They were all used by the move functions, except for the last one which
is used by focus.

Other changes:

* index_child has been renamed to container_sibling_index, moved to
container.c and made public
* sway_output_from_wlr has been renamed to output_from_wlr_output, moved
to output.c and made public
* container_handle_fullscreen_reparent has been made public
* sway_dir_to_wlr has been made public

No changes have been made to any of the moved functions, other than
updating calls to functions that have been renamed.
2018-08-25 12:09:42 +10:00
Ryan Dwyer b6058703fa Refactor destroy functions and save workspaces when there's no outputs
This changes the destroy functions to the following:

* output_begin_destroy
* output_destroy
* workspace_begin_destroy
* workspace_destroy
* container_begin_destroy
* container_destroy
* view_begin_destroy
* view_destroy

The terminology was `destroy` and `free`, and it has been changed to
`begin_destroy` and `destroy` respectively.

When the last output is disconnected, its workspaces will now be stashed
in the root. Upon connection of a new output they will be restored.

There is a new function `workspace_consider_destroy` which decides
whether the given workspace should be destroyed or not (ie. empty and
not visible).

Calling container_begin_destroy will no longer automatically reap the
parents. In some places we want to reap the parents and in some we
don't, so this is left to the caller.

container_reap_empty_recursive and container_reap_empty have been
combined into one function and it will recurse up the tree.
2018-08-24 22:17:28 +10:00
Ian Fan f51b9478f2 commands: implement move absolute 2018-08-20 10:17:32 +01:00
Ryan Dwyer 0f6d212629 Send output enter/leave events correctly
Previously we used a reparent event to detect when a view changes
parent, then sent an output enter/leave to the surfaces if needed. This
worked for tiling views but not floating views, as floating views can
intersect another output without changing parent.

The solution implemented for floating views also applies cleanly to
tiling views, so the previous method has been completely replaced and
the reparent event has been removed.

This introduces a new function container_discover_outputs. This function
compares the container's `current` position to the outputs, sends enter
and leave events as needed, and keeps track of which outputs it's
intersecting in a new `container->outputs` list. If it has entered a new
output with a different scale then the title and marks textures will
also be recreated at the new scale.

The function is called when a transaction applies. This is convenient as
it means we don't have to call it from various places.

There is imperfect rendering when a floating view overlaps two outputs
with different scales. It renders correctly for the most recently
entered output, but there is only one title texture so it renders
incorrectly on the old output.

Fixes #2482
2018-08-20 09:23:24 +10:00
Ryan Dwyer 2b5a404ac9 Replace hacky L_FLOATING container with a list
Workspaces previously had a magical `workspace->floating` container,
which had a layout of L_FLOATING and whose children were actual floating
views. This allowed some conveniences, but was a hacky solution because
the container has to be exempt from focus, coordinate transactions with
the workspace, and omit emitting IPC events (which we didn't do).

This commit changes it to be a list directly in the sway_workspace. The
L_FLOATING layout is no longer used so this has been removed as well.

* Fixes incorrect check in the swap command (it checked if the
containers had the L_FLOATING layout, but this layout applied to the
magical container).
* Introduces workspace_add_floating
2018-08-19 16:18:33 +10:00
Ian Fan e81cc8a575 commands: saner workspace number handling 2018-08-18 17:25:06 +01:00
Ian Fan 453646b887 commands: fix documentation formatting mistakes for move command 2018-08-18 15:50:26 +01:00
Ryan Dwyer 16c663ed49 Rename container_sort_workspaces and container_wrap_children
This commit renames container_sort_workspaces to output_sort_workspaces
and moves it to output.c.

This also renames container_wrap_children to workspace_wrap_children and
moves it to workspace.c. This function is only called with workspaces.
2018-08-18 22:02:03 +10:00
Ryan Dwyer 5653fc754b Deny moving a sticky container to workspace if it's the same output
Rationale: Sticky containers are always assigned to the visible
workspace.

The basic idea here is to check the destination's output (move.c:190).
But if the command was `move container to workspace x` then a workspace
might have been created for it. We could destroy the workspace in this
case, but that results in unnecessary IPC events.

To avoid this, the logic for `move container to workspace x` has been
adjusted. It now delays creating the workspace until the end, and uses
`workspace_get_initial_output` to determine and check the output before
creating it.
2018-08-08 12:50:42 +10:00
Ryan Dwyer 5ac6f2f429 Fix crash when running move container to workspace back_and_forth
The back_and_forth condition is intended to be handled in the else-if
block, but this was never reached because it remained in the first
block's conditions.
2018-08-07 23:04:21 +10:00
Brian Ashworth 639f3368e1
Merge branch 'master' into workspace-move-to-output 2018-08-06 11:47:00 -04:00
Ryan Dwyer f57a3919cf Move workspace moving code out of container_move_to
container_move_to handled moving containers to new parents, as well as
moving workspaces to new outputs.

This commit removes the workspace-moving code from this function and
introduces workspace_move_to_output. Moving workspaces using
container_move_to only happened from the move command, so it's been
implemented as a static function in that file.

Simplifying container_move_to makes it easier for me to fix some issues
in #2420.
2018-08-07 00:03:01 +10:00
Ian Fan f7c21451df commands: fix workspace edge cases 2018-08-06 14:17:58 +01:00
Ian Fan 667b8dcb67 commands: check for special workspaces in workspace & move commands 2018-08-06 14:17:58 +01:00
Ian Fan dd48c8a579 commands: add optional flags to move 2018-08-06 14:17:58 +01:00
Ian Fan 69e1a421fc commands: complete move implementation 2018-08-06 14:17:58 +01:00
Ryan Dwyer 04489ff420 Separate root-related code
This creates a root.c and moves bits and pieces from elsewhere into it.

* layout_init has been renamed to root_create and moved into root.c
* root_destroy has been created and is called on shutdown
* scratchpad code has been moved into root.c, because hidden scratchpad
containers are stored in the root struct
2018-08-04 14:01:20 +10:00
Ryan Dwyer 9e8d628a17 Deny "move container" when an empty workspace is focused 2018-08-03 17:13:37 +10:00
Ryan Dwyer d64c8df7ce Allow moving containers when workspace itself is focused 2018-08-02 20:59:44 +10:00
Ian Fan 03eaf444a4 ipc: prevent emitting a workspace::focus event when moving a container to a different workspace or output
When a container is moved from, say, workspace 1 to workspace 2, workspace 2 is focused in order to arrange the windows before focus is moved back to workspace 1, which caused a workspace:focus event from workspace 2 to workspace 1 to be emitted. This commit inhibits that event.
2018-08-01 16:57:15 +01:00
Ryan Dwyer 9d1f6e095b Send floating container to scratchpad when a child is focused 2018-07-28 22:41:04 +10:00
Ryan Dwyer 08cfba2192 Allow containers to float
Things worth noting:

* When a fullscreen view unmaps, the check to unset fullscreen on the
workspace has been moved out of view_unmap and into container_destroy,
because containers can be fullscreen too
* The calls to `container_reap_empty_recursive(workspace)` have been
removed from `container_set_floating`. That function reaps upwards so it
wouldn't do anything. I'm probably the one who originally added it...
* My fix (b14bd1b0b1) for the tabbed child
crash has a side effect where when you close a floating container, focus
is not given to the tiled container again. I've removed my fix and
removed the call to `send_cursor_motion` from `seat_set_focus_warp`. We
should consider calling it from somewhere earlier in the call stack.
2018-07-28 22:41:04 +10:00
Ryan Dwyer 27a20a4884 Allow containers to be fullscreen 2018-07-26 08:27:07 +10:00
Ryan Dwyer 81e8f31cc6 Implement scratchpad
Implements the following commands:

* move scratchpad
* scratchpad show
* [criteria] scratchpad show

Also fixes these:

* Fix memory leak when executing command with criteria
(use `list_free(views)` instead of `free(views)`)
* Fix crash when running `move to` with no further arguments
2018-07-23 08:24:32 +10:00
Ryan Dwyer 2032f85d94 Simplify transactions by utilising a dirty flag on containers
This PR changes the way we handle transactions to a more simple method.
The new method is to mark containers as dirty from low level code
(eg. arranging, or container_destroy, and eventually seat_set_focus),
then call transaction_commit_dirty which picks up those containers and
runs them through a transaction. The old methods of using transactions
(arrange_and_commit, or creating one manually) are now no longer
possible.

The highest-level code (execute_command and view implementation
handlers) will call transaction_commit_dirty, so most other code just
needs to set containers as dirty. This is done by arranging, but can
also be done by calling container_set_dirty.
2018-07-14 23:14:55 +10:00
Ryan Dwyer ab8a86369c Implement some floating move commands
This implements the following for floating containers:

* move <direction> <amount>
* move [absolute] position <x> <y>
* move [absolute] position mouse
2018-07-09 23:38:29 +10:00
Ryan Dwyer fc6fde7d90 Fix compile error 2018-06-30 21:07:54 +10:00
Ryan Dwyer e8fb6b3325 Fix crash when moving last child of a container to workspace or output
We were arranging a parent which may have been deleted by the reaper,
which meant the `current` children list of the surviving parent had a
dangling pointer.

Instead, we now reap the workspace.
2018-06-29 19:36:22 +10:00
Ryan Dwyer b6a238c7b7 Fix crash when running move <direction> in an empty workspace 2018-06-24 16:03:24 +10:00
Ryan Dwyer b864ac0149 Fix crash when unmapping a view with reapable parents
container_destroy was calling container_reap_empty, which calls
container_destroy and so on. Eventually the original container_destroy
would return a NULL pointer to the caller which caused a crash.

This also fixes an arrange on the wrong container when moving views in
and out of stacks.
2018-06-24 15:50:53 +10:00