Commit graph

537 commits

Author SHA1 Message Date
Ryan Dwyer 56e9f31b2f Check for NULL output in workspace_valid_on_output 2018-09-28 22:35:38 +10:00
Ryan Dwyer 138d10d5d6 Rename workspace_outputs to workspace_configs and fix memory leak
When we eventually implement `workspace <ws> gaps inner|outer <px>`,
we'll need to store the gaps settings for workspaces before they're
created. Rather than create a workspace_gaps struct, the approach I'm
taking is to rename workspace_outputs to workspace_configs and then add
gaps settings to that.

I've added a lookup function workspace_find_config. Note that we have a
similar thing for outputs (output_config struct and output_find_config).

Lastly, when freeing config it would create a memory leak by freeing the
list items but not the workspace or output names inside them. This has
been rectified using a free_workspace_config function.
2018-09-28 22:35:38 +10:00
Ryan Dwyer 22412f57b0 Fix floating views in tabbed/stacked workspaces not getting frame events
view_is_visible would return false, which meant the view wouldn't
receive a frame done event. view_is_visible needs to make an exception
for floating containers.

This also moves the workspace_is_visible check to an earlier location
for performance reasons.
2018-09-28 17:02:35 +10:00
Ryan Dwyer 4e4898e90f Fix race condition crash when view unmaps + maps quickly
When a view unmaps, we start a transaction to destroy the container,
then when the transaction completes we destroy the container and unset
the view's container pointer. But if the view has remapped in the
meantime, the view's container pointer will be pointing to a different
container which should not be cleared.

This adds a check to make sure the view is still pointing to the
container being destroyed before clearing the pointer. The freeing of
the title format is also removed as it is already freed when the view
destroys in view_destroy.
2018-09-26 21:33:54 +10:00
Ryan Dwyer b1a0e95e8e Fix crash when disconnecting output
If the output being disconnected contains views, and the views are being
relocated to another output of a different size, a transaction must
occur to reconfigure them. This means by the time
container_discover_outputs is called, the output is already disabled and
wlr_output is NULL.

I considered making it check output->wlr_output, but output->enabled
should work just as well and is more descriptive.
2018-09-25 08:21:22 +10:00
emersion 4bc327a021
Merge pull request #2694 from RyanDwyer/fix-sticky-jumping-on-switch
Prevent sticky containers from jumping on workspace switch
2018-09-23 09:42:07 +02:00
emersion 1af4d314d1
Merge pull request #2686 from RyanDwyer/tab-scrolling
Implement tab cycling using mouse wheel
2018-09-23 09:39:53 +02:00
Ryan Dwyer 64445f4214 Prevent sticky containers from jumping on workspace switch
If you have swaybar docked to the top, and you create a floating sticky
container and switch workspaces on the same output, the sticky container
would move down by the height of swaybar on each switch.

This happens because when creating the workspace we set the dimensions
to the same as the output, then the subsequent arrange corrects it.
During this arrange, floating containers are translated so they stay
relative to the workspace. This translation needs to not occur for the
initial arrange.

This patch makes workspaces have a zero width and height when first
created, so we can detect whether this is the initial arrange and avoid
translating the floating containers if so.
2018-09-23 11:36:16 +10:00
Drew DeVault 68395f34f6
Merge pull request #2688 from RyanDwyer/exec-commands-without-focus
Allow running commands on containers without focusing them
2018-09-22 19:51:02 -05:00
Ryan Dwyer cb66bbea42 Allow running commands on containers without focusing them
This adds a `con` argument to `execute_command` which allows you to
specify the container to execute the command on. In most cases it leaves
it as `NULL` which makes it use the focused node. We only set it when
executing `for_window` criteria such as when a view maps. This means we
don't send unnecessary IPC focus events, and fixes a crash when the
criteria command is `move scratchpad` (because we can't give focus to a
hidden scratchpad container).

Each of the shell map handlers now check to see if the view has a
workspace. It won't have a workspace if criteria has moved it to the
scratchpad.
2018-09-23 08:39:11 +10:00
Ian Fan d101f3d357 commands: remove obselete code for sticky windows when switching workspace 2018-09-22 23:27:53 +01:00
Geoff Greer c495164f60 swaybar, swaylock, & tree/container: Set cairo font options to render text and lines with subpixel hinting (if available). 2018-09-22 11:34:21 -07:00
emersion eae42606e2
Merge pull request #2660 from RyanDwyer/fix-scratchpad-iteration
Fix double iteration of scratchpad containers
2018-09-22 13:40:01 +02:00
Ryan Dwyer 10ef118e09 Fix pango escaping and refactor escape_markup_text
Fixes #2674.

The cause of the issue was in get_pango_layout. When we call
pango_parse_markup, `text` is the escaped string, and the unescaped
string is then computed and written to `buf`. We were then passing the
unescaped string to pango_layout_set_markup, but this function needs the
escaped string. `buf` is not needed and has been removed.

The other part of this PR refactors escape_markup_text to remove the
dest_length argument and removes the -1 return value on error. It now
assumes that you've allocated dest to the correct length.
2018-09-22 18:33:28 +10:00
Ryan Dwyer bf5933c501 Implement tab cycling using mouse wheel
Firstly, a change had to be made to the container_at functions. If you
create layout `T[view H[view view]]` and hover the second tab, the
container_at functions would return the focus_inactive child. They now
return the split container itself. To compensate for this,
dispatch_cursor_button has been adjusted to find the focus_inactive
child before focusing it.

The actual implementation of wheel scrolling is pretty straightforward.
This uses handle_cursor_axis, so I took a similar approach to
handle_cursor_button (ie. creating a dispatch_cursor_axis function).
2018-09-22 10:42:59 +10:00
emersion 82f1393cbb swaybar: handle hotplugging
Don't kill and respawn swaybars on hotplug.
2018-09-20 18:37:51 +02:00
Ian Fan 81f3fda6fa ipc: add pid information for views in layout tree 2018-09-19 22:21:09 +01: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 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 09733e233f Fix crash when unmapping last child of a tabbed workspace
* Create layout T[view view]
* Move the cursor into the title bar area
* Close both views

Sway would crash because container_at_tabbed would attempt to divide by
zero when there are no children.

The children check isn't needed for the stacked function because it
doesn't divide anything by the number of children.

Fixes #2636.
2018-09-16 14:18:13 +10:00
Ian Fan 34dbbb1314 ipc: handle NULL cases for node_get_output 2018-09-15 09:42:49 +01:00
Ian Fan 25ba80057d Remove redundant container creation in view initialization 2018-09-15 01:24:10 +01:00
Drew DeVault d8a96c9e4d
Merge pull request #2621 from emersion/fix-unmap-segfault
Don't use handler_context in view_unmap
2018-09-11 19:50:00 -04:00
Ryan Dwyer 679c7eb08c Minor fixes to tiling drag implementation
* Make container_add_sibling's `after` argument a boolean.
* Use a constant for drop layout border
* Make thickness an int
* Add button state check
* Move comments in seat_end_move_tiling
2018-09-12 08:46:46 +10:00
emersion 8b263429cf Don't use handler_context in view_unmap 2018-09-11 19:34:58 +02:00
Ryan Dwyer df95c61044 Fix crash in workspace_wrap_children
When workspace_wrap_children is called on a workspace which has a
fullscreen child and the fullscreen child is a direct child of the
workspace, sway would crash.

The workspace's fullscreen pointer is unset when the fullscreen
container is detached and applied again when added to a parent, but in
this case the parent hadn't yet been added to the workspace which meant
con->workspace was NULL.

The fix makes container_handle_fullscreen_reparent return if there's no
workspace, and the fullscreen pointer is reapplied in
workspace_wrap_children.
2018-09-11 23:38:17 +10: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
William Wold 097ed03647 Minor fix 2018-09-10 17:52:42 -07:00
William Wold 22c5dd8a02 Minor fix 2018-09-10 10:18:12 -07:00
William Wold 9a08019267 Prevent stacked layout from crashing 2018-09-10 10:18:12 -07:00
William Wold e787a1581c Give windows pointer focus immediately when they are switched to
Fixes #2401 (aka #2558)

Previously, when switching windows, pointer focus was not changed until the pointer was moved. This makes the pointer enter happen immediately, without the side effects of other attempted fixes.
2018-09-10 10:18:12 -07:00
Ryan Dwyer 9215ca0f01 Align titles to baseline
This does the following:

* Adds a baseline argument to get_text_size (the baseline is the
distance from the top of the texture to the baseline).
* Stores the baseline in the container when calculating the title
height.
* Takes the baseline into account when calculating the config's max font
height.
* When rendering, pads the textures according to the baseline so they
line up.
2018-09-08 16:25:07 +10:00
Ryan Dwyer 635ae9557c Second attempt at restoring focus when closing a fullscreen view
To reproduce the problem this is fixing, create H[view view view],
fullscreen one of the views and close it. The entire workspace will be
given focus rather than one of the siblings.

This happens because we emit the destroy event, so the seat code tries
to find a new focus, but the view it finds is still believed to be
hidden by the fullscreen view so it's discarded and the workspace is
used instead.

This clears the workspace's fullscreen pointer prior to emitting the
destroy event so that the seat code finds an appropriate new focus.
2018-09-06 22:34:09 +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 c6368febc8 Adjust container box
Prior to f5b9815128, children of tabbed
and stacked containers would have their container size and position set
to the same as the tabbed/stacked container. Normally this would be a
problem for a layout such as T[V[view]], but there was some code in the
arrange functions which would check if the grandparent of the view was a
tabbed or stacked container and would offset the view's Y accordingly.

Commit f5b9815128 changed the box to
exclude the titlebar for all tabbed/stacked children so that the
grandparent check could be removed. But this meant the title was not
covered in the container and wasn't damaged when the child changed its
title.

This patch changes it so that a child of a tabbed/stacked container will
have its box include the title bar if the child is a view, but not if
it's a layout container. This fixes the title damage issue while
avoiding the grandparent check in the arrange functions, and matches
what we see visually.
2018-09-06 09:13:36 +10:00
Brian Ashworth c246cf84c8 Call wlr_output_enable on enable/disable if needed 2018-09-05 14:00:00 -04: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 3cc7de3fb4 Fix crash when view in scratchpad becomes urgent 2018-09-05 18:01:43 +10:00
Ryan Dwyer c0da364865 Fix floating view moving to 0,0 when splitting 2018-09-05 18:01:43 +10:00
Ryan Dwyer 4e0452fce3 Fix scratchpad related crashes
* Was crashing when a view was moved to the scratchpad (prev focus had
no parent).
* Was crashing when a hidden scratchpad view unmaps because it has no
workspace.
2018-09-05 18:01:43 +10:00
Ryan Dwyer 93ff7879f1 Fix output position issue
Looks like the output dimensions need to be set when arranging rather
than when a mode is set.

Fixes an issue with position of fullscreen views.
2018-09-05 18:01:43 +10:00
Ryan Dwyer 26204441b4 Apply default config to output
When starting without any output config, the default config was not
applying.
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 acc2628c79 Don't use wlr_output properties
These properties are before rotation.
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
sghctoma 073dcb3a86 Change _XOPEN_SOURCE defines to _POSIX_C_SOURCE 2018-09-03 09:08:49 +02:00
sghctoma df730a8891 Merge remote-tracking branch 'upstream/master' into fix-freebsd-build 2018-09-03 08:57:17 +02:00
Ryan Dwyer 6fb03817c9 Rename fowa enum and use switch in view_request_activate 2018-09-02 18:25:45 +10:00
Ryan Dwyer f057a0195e Implement focus_on_window_activation
Depends on https://github.com/swaywm/wlroots/pull/1223
2018-09-02 18:20:34 +10:00
sghctoma cc16948c85 Fix feature macros for FreeBSD
On FreeBSD, snprintf and vsnprintf are visible only if
_XOPEN_SOURCE >= 600.
2018-08-30 09:34:26 +02:00