Commit Graph

36 Commits

Author SHA1 Message Date
Ronan Pigott f645f8efd6 Fix lingering workspace with scratchpad show
Showing a window in the scratchpad can move a visible scratchpad window
from another workspace to the current one. If the scratchpad window was
the last visible container in that workspace, the old workspace should
be destroyed.
2019-12-12 06:51:13 -05:00
Rouven Czerwinski ddad41f423 Fix sway crashes for scratchpad layouts
Currently container_replace removes the container from the scratchpad
and re-adds it afterwards. For the split commands this results in the
container being send to the scratchpad, which results in a NULL segfault
if the same container should be shown.
Pass an optional workspace to root_scratchpad_add_container, if the
workspace is passed the window will continue to show on the workspace.
If NULL is passed it is sent to the scratchpad.
This was an issue if no other window except the scratchpad container was
on the workspace.

Fixes #4240
2019-06-16 12:29:16 -04:00
Brian Ashworth 69a1a0ff99 Fix scratchpad fullscreen behavior and crash
When setting fullscreen on a hidden scratchpad container, there was a
check to see if there was an existing fullscreen container on the
workspace so it could be fullscreen disabled first. Since the workspace
is NULL, it would cause a SIGSEGV. This adds a NULL check to avoid the
crash.

This also changes the behavior of how fullscreen is handled when adding
a container to the scratchpad or changing visibility of a scratchpad
container to match i3's. The behavior is as follows:
- When adding a container to the scratchpad or hiding a container back
  into the scratchpad, there is an implicit fullscreen disable
- When setting fullscreen on a container that is hidden in the
  scratchpad, it will be fullscreen when shown (and fullscreen disabled
  when hidden as stated above)
- When setting fullscreen global on a container that is hidden in the
  scratchpad, it will be shown immediately as fullscreen global. The
  container is not moved to a workspace and remains in the
  scratchpad. The container will be visible until fullscreen disabled
  or killed. Since the container is in the scratchpad, running
  `scratchpad show` or `move container to scratchpad` will have no
  effect

This also changes `container_replace` to transfer fullscreen and
scratchpad status.
2019-04-13 08:48:37 -06:00
Ashkan Kiani 27f51360b7 Fix scratchpad logic for floating windows
When a tiled window is sent to the scratchpad, we want to use sane
defaults, which is to center it and resize it to the default.

For floating windows, we want to use their existing geometry.
2019-04-12 16:52:24 -04:00
Brian Ashworth f0f20f96aa root_scratchpad_hide: fix crash when layer focused
This fixes a crash in `root_scratchpad_hide` when a layer surface is
focused. Since `seat_get_focus` is NULL when a layer surface is
focused, the call to `node_has_ancestor` was causing a SIGSEGV since it
was attempting to access the parent of NULL. This changes the call to
`seat_get_focus_inactive`, which will return a node even when a layer
surface is focused and is also guaranteed to have something in the
focus stack if a scratchpad container is being hidden (otherwise there
would not be any containers yet).
2019-04-03 19:45:17 +03:00
Brian Ashworth 679c058fac scratchpad: set initial size
This matches i3's behavior of setting scratchpad containers to 50% of
the workspace's width and 75% of the workspace's height, bound by the
minimum and maximum floating width/height.
2019-03-31 17:49:05 -06:00
Brian Ashworth dd28e6a6d6 Fix xwayland configure request scratchpad crash
This fixes a crash in `container_init_floating` when a xwayland view
sends a configure request while in the scratchpad.

`container_init_floating` gets called so the configured minimum and
maximum sizes gets respected when resizing to the requested size. Since
the workspace was NULL, it would SIGSEGV when attempting to get the
workspace's output for the output box retrieval.

This extracts the resizing portion of `container_init_floating` into a
separate function. If the container is in the scratchpad, it will just
be resized and skip the centering.

Additionally, `container_init_floating` has been renamed to
`container_floating_resize_and_center` to more accurately describe what
it does.
2019-03-31 09:32:23 +03:00
mliszcz 200833caae Allow for workspace renaming during exec handling
This change adds support for renaming a workspace when `exec` command
is being processed by keeping sway_workspace and pid_workspace names in
sync.

The change can be verified by running following command:

swaymsg exec <application>; swaymsg rename workspace number 1 to 5

Fixes: #3952
2019-03-23 17:49:27 -04:00
Brian Ashworth 3330faded5 Handle seat_get_focused_workspace returning NULL
This modifiers the callers of seat_get_focused_workspace to handle
getting NULL as the return value, if they did not already.
2019-03-12 19:14:04 +01:00
Ryan Dwyer 6b8bf10941 Introduce container_is_scratchpad_hidden
Just a convenience function that improves readability of the code.

Other things worth noting:

* container_get_siblings and container_sibling_index no longer use the
const keyword
* container_handle_fullscreen_reparent is only ever called after
attaching the container to a workspace, so its con->workspace check has
been changed to an assertion
2019-01-28 10:35:40 +01:00
Ryan Dwyer 20aa8ee67d Implement fullscreen global 2019-01-25 08:29:21 +10:00
M Stoeckl 0af5b26e41 Fix dead stores found by scan-build
In addition to removing unused code, two minor problems are fixed:
 (1) `resize set` and `resize adjust` did not error when given
too many arguments.
 (2) `orientation` was incorrectly overridden to be 'U' for
scroll events in the swaybar tray `handle_click` function.
2019-01-22 10:12:04 -05:00
Brian Ashworth 8ce57f0a77 root_scratchpad_remove_container: do not show
This removes the call to `root_scratchpad_show` from
`root_scratchpad_remove_container` and places it in the
`cmd_move_container`. This also moved the IPC `window::move` event to
`cmd_scratchpad`.
2019-01-22 13:13:34 +01:00
Ryan Dwyer 2301349ad5 Use noop output when there's no outputs connected
Instead of having NULL workspace->output pointers, use a noop output.
This should be safer.
2019-01-22 09:55:13 +01:00
M Stoeckl d7ff776552 Move sway-specific functions in common/util.c into sway/
Modifier handling functions were moved into sway/input/keyboard.c;
opposite_direction for enum wlr_direction into sway/tree/output.c;
and get_parent_pid into sway/tree/root.c .
2019-01-21 12:39:16 -05:00
M Stoeckl 1211a81aad Replace wlr_log with sway_log
This commit mostly duplicates the wlr_log functions, although
with a sway_* prefix. (This is very similar to PR #2009.)
However, the logging function no longer needs to be replaceable,
so sway_log_init's second argument is used to set the exit
callback for sway_abort.

wlr_log_init is still invoked in sway/main.c

This commit makes it easier to remove the wlroots dependency for
the helper programs swaymsg, swaybg, swaybar, and swaynag.
2019-01-21 12:59:42 +01:00
Brian Ashworth 3087942c35 Handle hidden scratchpad containers in commands
This fixes the handling of hidden scratchpad containers for some
commands. For the most part, this just prevents running the commands on
hidden scratchpad containers, but there are some commands that have some
special handling for them.
2019-01-15 09:05:27 +01:00
Ryan Dwyer dd8d2dedf7 Fix crash when scratchpad contains split containers
To reproduce:

* Launch two terminals in a workspace
* `focus parent` to select both terminals
* `move scratchpad`
* `scratchpad show` to show the terminals
* `scratchpad show` to hide the terminals
* `scratchpad show` - crash

When hiding the terminals, it should be moving focus to whatever is in
the workspace, but this wasn't happening because the focus check didn't
consider split containers. So the terminals were hidden in the
scratchpad while still having focus. This confused the next invocation
of scratchpad show, causing it to attempt to hide them instead of show
them, and the hide-related code caused a crash when it tried to arrange
the workspace which was NULL.

This patch corrects the focus check.
2018-12-29 14:45:42 +10:00
Brian Ashworth f52277f66e Fix scratchpad segfault - NULL focused workspace
When adding a container to the scratchpad, it was possible for focus to
be removed from the seat. This occurred when a single child was moved
from it's parent to the scratchpad due to the focus_inactive for the
parent being NULL. If the focus_inactive for the parent is NULL, the
focus_inactive for the workspace should be focused.
2018-11-28 13:02:54 -05:00
Mihai Coman 6aafdd2321 IPC: Trigger move events for scratchpad containers
This patch allows IPC clients to receive window::move events
when containers are moved to scratchpad or when hidden containers
are shown via "scratchpad show" command.
2018-11-26 11:13:47 +02:00
emersion cad851805b
Use #if instead of #ifdef 2018-11-18 00:33:06 +01:00
Ryan Dwyer f7aed5c7e5 Fix containers not being resized when entering scratchpad
This fixes a regression introduced by
662466e8db. When adding a container to the
scratchpad, setting container->scratchpad = true before
container_set_floating made container_set_floating believe that the
container was already floating. This fixes it by setting the property
afterwards instead.
2018-10-25 17:32:16 +10:00
Ryan Dwyer c006717910 Minor refactor of input manager
The input manager is a singleton object. Passing the sway_input_manager
argument to each of its functions is unnecessary, while removing the
argument makes it obvious to the caller that it's a singleton. This
patch removes the argument and makes the input manager use server.input
instead.

On a similar note:

* sway_input_manager.server is removed in favour of using the server
global.
* seat.input is removed because it can get it from server.input.

Due to a circular dependency, creating seat0 is now done directly in
server_init rather than in input_manager_create. This is because
creating seats must be done after server.input is set.

Lastly, it now stores the default seat name using a constant and removes
a second reference to seat0 (in input_manager_get_default_seat).
2018-10-20 13:11:43 +10:00
Ryan Dwyer 24bcb507ec Fix hotplugging down to zero outputs
When the last output is disconnected, output_disable is called like
usual and evacuates the output to the root->saved_workspaces list. It
then calls root_for_each_container to remove (untrack) the output from
each container's outputs list. However root_for_each_container did not
iterate the saved workspaces, so when the output gets freed the
containers would have a dangling pointer in their outputs list. Upon
reconnect, container_discover_outputs would attempt to use the dangling
pointer, causing a crash.

This makes root_for_each_container check the saved workspaces list,
which fixes the problem.
2018-09-30 11:58:56 +10:00
Ryan Dwyer c6ff1f67f1 Fix double iteration of scratchpad containers
root_for_each_container and root_find_container were using incorrect
logic to determine if a container was hidden in the scratchpad.
Containers will have a NULL parent if they are a direct child of a
workspace. Containers will have a NULL workspace if they are hidden in
the scratchpad.

The incorrect check meant that root_for_each_container would run the
callback on scratchpad containers twice. This meant that executing a
command such as `[class="$something"] scratchpad show` would cause the
command to run twice, resulting in the container being shown and hidden
again which is effectively a no op.

Fixes #2655.
2018-09-18 21:53:02 +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
Ryan Dwyer f5b9815128 Prepare arrange code for type safe arguments
This commit changes the arrange code in a way that will support type
safe arguments.

The arrange_output et al functions are now public, however I opted not
to use them directly yet. I've kept the generic arrange_windows there
for convenience until type safety is fully implemented. This means this
patch has much less risk of breaking things as it would otherwise.

To be type safe, arrange_children_of cannot exist in its previous form
because the thing passed to it could be either a workspace or a
container. So it's now renamed to arrange_children and accepts a list_t,
as well as the parent layout and parent's box.

There was some code which checked the grandparent's layout to see if it
was tabbed or stacked and adjusted the Y offset of the grandchild
accordingly. Accessing the grandparent layout isn't easy when using type
safe arguments, and it seemed odd to even need to do this. I determined
that this was needed because a child of a tabbed container would have a
swayc Y matching the top of the tab bar. I've changed this so a child of
a tabbed container will have a swayc Y matching the bottom of the tab
bar, which means we don't need to access the grandparent layout.  Some
tweaks to the rendering and autoconfigure code have been made to
implement this, and the container_at code appears to work without
needing any changes.

arrange_children_of (now arrange_children) would check if the parent had
gaps and would copy them to the child, effectively making the
workspace's gaps recurse into all children. We can't do this any more
without passing has_gaps, gaps_inner and gaps_outer as arguments to
arrange_children, so I've changed the add_gaps function to retrieve it
from the workspace directly.

apply_tabbed_or_stacked_layout has been split into two functions, as it
had different logic depending on the layout.

Lastly, arrange.h had an unnecessary include of transaction.h. I've
removed it, which means I've had to add it to several other files.
2018-08-28 23:50:41 +10:00
Ryan Dwyer 2e7401772e Rename sway_root.outputs to sway_root.all_outputs
This list includes disabled outputs.

When sway_container is demoted, we'll need to store the root's children
(ie. enabled outputs) in the sway_root. It makes sense to put these in a
list called `outputs`, so I'm renaming the existing list in advance.
2018-08-25 23:41:11 +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
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
Ryan Dwyer d6cd79c342 Implement iterators per container type
This introduces the following `for_each` functions:

* root_for_each_workspace
* root_for_each_container
* output_for_each_workspace
* output_for_each_container
* workspace_for_each_container

And introduces the following `find` functions:

* root_find_output
* root_find_workspace
* root_find_container
* output_find_workspace
* output_find_container
* workspace_find_container
* container_find_child

And removes the following functions:

* container_descendants
* container_for_each_descendant
* container_find

This change is preparing the way for demoting sway_container. Eventually
these functions will accept and return sway_outputs, sway_workspaces and
sway_containers (meaning a C_CONTAINER or C_VIEW).

This change also makes it easy to handle abnormalities like the
workspace floating list, root's scratchpad list and (once implemented)
root's saved workspaces list for when there's no connected outputs.
2018-08-18 23:38:54 +10:00
Drew DeVault 98ed05225e
Merge pull request #2458 from RyanDwyer/cleanup-transactions
Simplify transactions
2018-08-15 17:16:32 -04:00
Ryan Dwyer 701fcafc70 Use list_find in more places and refactor/fix workspace prev_next functions
The original purpose of this commit is to replace some for loops with
list_find. But while doing this I found the workspace_prev_next_impl
functions to be difficult to read and also contained a bug, so I
refactored them and fixed the bug.

To reproduce the bug:

* Have two outputs, where the left output has workspaces 1, 2, 3 and the
right output has workspaces 4, 5, 6. Make workspace 2 focused_inactive
and workspace 4 focused.
* Run `workspace prev`.
* Previously it would visit the left output, then apply `workspace prev`
to workspace 2, which focuses workspace 1.
* Now it will focus the rightmost workspace on the left output
(workspace 3).

The refactoring I made to the workspace functions are:

* Added the static keyword.
* They now accept an int dir rather than bool, to avoid an unnecessary
conversion.
* Rather than preparing start and end variables for the purpose of
iterating, just iterate everything.
* Replace for loops with list_find.
* Don't call workspace_output_prev_next_impl (this fixes the bug).
2018-08-15 15:14:35 +10:00
Ryan Dwyer c3ef36d6b5 Simplify transactions
Commit 4b8e3a885b makes it so only one
transaction is committed (ie. configures sent) at a time. This commit
removes the now-unnecessary code which was used to support concurrent
committed transactions.

* Instead of containers storing a list of instructions which they've
been sent, it now stores a single instruction.
* Containers now have an ntxnrefs property. Previously we knew how many
references there were by the length of the instruction list.
* Instructions no longer need a ready property. It was used to avoid
marking an instruction ready twice when they were in a list, but this is
now avoided because there is only one instruction and we nullify the
container->instruction pointer when it's ready.
* When a transaction applies, we no longer need to consider releasing
and resaving the surface, as we know there are no other committed
transactions.
* transaction_notify_view_ready has been renamed to
view_notify_view_ready_by_serial to make it consistent with
transaction_notify_view_ready_by_size.
* Out-of-memory checks have been added when creating transactions and
instructions.
2018-08-15 10:03:55 +10:00
Ryan Dwyer 30e7e0f7c7 Move workspace pid code to root.c 2018-08-04 14:01:49 +10: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