Commit graph

661 commits

Author SHA1 Message Date
Brian Ashworth 430359519c floating_maximum_size: change default behavior
This changes the way zero (which is the default) is interpreted for both
the width and height of `floating_maximum_size`. It now refers to the
width and height of the entire output layout, which matches i3's
behavior.

This also removes duplicated code to calculate the floating constraints
in three files. Before this, `container_init_floating` used two-thirds
of the workspace width/height as the max and the entire workspace
width/height was used everywhere else. Now, all callers use a single
function `floating_calculate_constraints`.
2019-03-02 09:10:26 +01:00
db 2510e3df38 add --i3 flag to hide_edge_borders
Enables i3-compatible behavior regarding hiding the title bar on tabbed and
stacked containers with one child.

Related issues and merge requests: #3031, #3002, #2912, #2987.
2019-02-24 15:26:37 -05:00
minus 713883f04c Fix crash exiting fullscreened floating container
container_floating_move_to_center and container_fullscreen_disable were
calling recursively when the container spawned as a fullscreen floating
container (via for_window). Such a window now doesn't crash sway anymore
but is still configured with a wrong, zero size, making it not directly
usable.
2019-02-23 21:40:03 -05:00
Brian Ashworth d3d7956576 Handle NULL from output_get_active_workspace
This modifies the places where output_get_active_workspace is called to
handle a NULL result. Some places already handled it and did not need a
change, some just have guard off code blocks, others return errors, and
some have sway_asserts since the case should never happen. A lot of this
is probably just safety precautions since they probably will never be
called when `output_get_active_workspace` is not fully configured with a
workspace.
2019-02-21 21:18:03 +01:00
Brian Ashworth 546b976baa output_evacuate: call workspace_consider_destroy
This calls `workspace_consider_destroy` on the workspace that was
visible on an output that a workspace was just evacuated to. This
prevents having hidden empty workspaces.
2019-02-20 20:17:45 +01:00
Brian Ashworth faf15ee733 workspace_next_name: fallback to next available number
This changes `workspace_next_name` to use the next available number as
the workspace name instead of the number of outputs. This fixes the case
where a number that is already in use could be returned. The workspace
numbers in use have no relation to the number of outputs so it makes
more sense to use the lowest available number
2019-02-17 19:15:19 +01:00
Drew DeVault 487c83f0de Add workspace {prev,next}_on_output --create
This creates the next workspace if you hit the end.
2019-02-17 11:50:07 -05:00
emersion 7baaa3a0f8 Disconnect swaybg instead of killing it
This is much more reliable. This also fixes race conditions when killing swaybg
while it's doing a wl_display_roundtrip.
2019-02-16 19:11:22 -05:00
emersion 8ab64d3fcc Remove unused header include/sway/tree/output.h 2019-02-16 17:40:56 -05:00
Brian Ashworth ab42874f71 seat: allow tree focus changes while layer focused
This allows the focused inactive tree node and visible workspaces to be
changed while a surface layer has focus. The layer temporarily loses
focus, the tree focus changes, and the layer gets refocused.
2019-02-14 11:01:08 +01:00
Brian Ashworth d168d65f2c subsurface_get_root_coords: break on NULL
It is possible for `wlr_surface_is_subsurface` to return true, but
`wlr_surface_from_wlr_surface` to be NULL. This adds a NULL check to the
value returned by `wlr_surface_from_wlr_surface` and breaks out of the
while loop in `subsurface_get_root_coords`.
2019-02-13 09:51:40 +01:00
Brian Ashworth fb4f29289f workspace_get_initial_output: handle focused layer
When a layer surface is focused, `seat_get_focused_workspace` will be
NULL. This changes `workspace_get_initial_output` to use output of the
focus inactive. If the focus inactive is also NULL, then either the
first output or the noop output will be used as fallbacks.
2019-02-11 10:13:16 +01:00
Brian Ashworth 418c19fe52 view: remove pointer constraints on unmap
If the view has any pointer constraints, ensure they are removed
before the view is unmapped and the surface is no longer tied to the
view.
2019-02-10 21:29:45 +01:00
Brian Ashworth 995b6edab6 container_at_stacked: skip titles when zero pixels
It is possible to make the title bars have a zero pixel height while
stacked, by using a blank font and no padding. This causes a division by
zero when attempting to calculate the child index in
container_at_stacked, which then results in a segfault when attempting
to access the child at that bad index (INT_MIN). This just skips the
check to see if the cursor is over a title bar of a child of a stacked
container when the title bar height is zero since there will be no title
bars.
2019-02-09 09:24:43 +01:00
Ryan Dwyer 8995694a2f Remove bad assertion in container_handle_fullscreen_reparent
The assertion could trigger when called from workspace_wrap_children.
2019-01-29 08:05:55 +10:00
mwenzkowski 7c27d73b02 Check xdg_surface's role before using its toplevel
Don't access xdg_surface->toplevel if xdg_surface->role is equal to
WLR_XDG_SURFACE_ROLE_NONE, since this could lead to crash. The same
checks are added for xdg_surface_v6.

Fixes #3311
2019-01-28 16:14:35 +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 0a9ff774ad Center surface inside container when it's too small
The goal here is to center fullscreen views when they are both too small
for the output and refuse to resize to the output's dimensions. It has
the side effect of also centering the view when it's too small for its
container.

Example clients that have this behaviour are emersion's hello-wayland
and weston.

It works by introducing surface_{x,y,width,height} properties to the
container struct. The x and y represent layout-local coordinates where
the surface will be rendered. The width and height are only used to
track the surface's previous dimensions so we can detect when the client
has resized it and recenter and apply damage accordingly.

The new surface properties are calculated when a transaction is applied,
as well as when a view resizes itself unexpectedly. The latter is done
in view_update_size. This function was previously restricted to views
which are floating, but can now be called for any views.

For views which refuse to resize *smaller* than a particular size, such
as gnome-calculator, the surface is still anchored to the top left as
per the current behaviour.
2019-01-28 01:17:21 -05: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
Drew DeVault 71a37ad186
Merge pull request #3494 from ianyfan/commands
i3 command behaviour compatibility fixes
2019-01-22 07:55:31 -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
Ian Fan 34dea3d9d2 commands: allow tiled containers to be stickied
This also stops stickied containers from losing its sticky status when
it is tiled, allowing it to be immediately stickied when floated again.
2019-01-22 11:47:48 +00: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
emersion 6ff54d0640
Fix segfault in output_enable 2019-01-18 14:52:40 +01:00
emersion a737d7ecc4
Better handle outputs without CRTC
This happens if you plug in more outputs than supported by your GPU.

This patch makes it so outputs without CRTCs appear as disabled. As soon as
they get a CRTC (signalled via the mode event), we can enable them.
2019-01-18 10:09:10 +01:00
emersion dc1eac0cf1 output: remove output_add_listeners
Simplify the code by registering signals when outputs are created and removing
signals when they are destroyed.
2019-01-18 10:08:34 +01:00
Brian Ashworth a68bc5f449 Do not damage view child when container is NULL
In `view_child_damage`, do not damage the surface if it has been
unmapped or if the container is NULL.
2019-01-15 09:06: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 ed5aafd90b Refactor seat operations to use an interface
This splits each seat operation (drag/move tiling/floating etc) into a
separate file and introduces a struct sway_seatop_impl to abstract the
operation.

The move_tiling_threshold operation has been merged into move_tiling.

The main logic for each operation is untouched aside from variable
renames.

The following previously-static functions have been made public:
* node_at_coords
* container_raise_floating
* render_rect
* premultiply_alpha
* scale_box
2019-01-10 22:04:42 +10:00
Brian Ashworth 8fd3f32c79 Fix segfaults on output destruction
This fixes two causes of segfaulting when an output is destroyed.

The first occurred when an output was never enabled. The issue was that
the destroy signal was never initialized so when it was emitted, sway
segfaulted. This was fixed by moving the initialization into
`output_create` since all outputs, regardless of whether they have ever
been enabled, will be destroyed at some point.

The second occurred when the cursor was on an output that was being
destroyed. The sway output would have already been removed, but if there
are other outputs, a cursor rebase would still occur. Since the
wlr_output still existed and the sway output was destroyed, the cursor
could be over nothing, resulting in a segfault when trying to get the
sway output, which was destroyed.
2019-01-10 03:07:36 -05:00
Rouven Czerwinski cc858e605a seat: unhide the cursor if it is warped to focus
Unhide the cursor if container warping is enabled.
Also set the image_surface to NULL during view_unmap, otherwise the cursor will
try to access the surface which is currently being unmapped.
2019-01-07 10:30:19 -05:00
Rouven Czerwinski 0b18560952 view: use seat_consider_warp_to_focus in view_unmap
The view_unmap function contained an open coded version of
seat_consider_warp_to_focus, replace it with a call to the function.
2019-01-07 10:30:19 -05:00
John Chen 54d0f3a40e Set font options when computing text width.
Fix #2869
2018-12-31 01:37:33 -05: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 cf7c77e56a Fix wlr_box_intersection args for wlroots 1441
The fix pushed to master missed wlr_box_intersection. This just fixes
those lines so sway renders properly again
2018-12-22 18:54:08 +01:00
Brian Ashworth 88d96bc41f Combine output_by_name and output_by_identifier
This combines `output_by_name` and `output_by_identifier` into a single
function called `output_by_name_or_id`. This allows for output
identifiers to be used in all commands, simplifies the logic of the
callers, and is more efficient since worst case is a single pass through
the output list.
2018-12-20 19:55:29 +01:00
Brian Ashworth 477bca5e28 Terminate swaybg in output_disable
Moves the call to `terminate_swaybg` from inside `apply_output_config` to
`output_disable`. The former was only called when an output was being
disabled. The latter is called when an output is being disabled and when
an output becomes disconnected. Without this, disconnecting an enabled
output would result in a defunct swaybg process.
2018-12-19 09:24:15 +01:00
Brian Ashworth 5f25541022 Allow output ids and wildcard for workspace output
This allows for output identifiers and to be used in the `workspace
<workspace> output <outputs...>` command. Previously, only output names
would be allowed. If an output identifier was given, it would never match
an output. This also allows for the wildcard character (`*`) to be
specified, which can be used to generate a list of workspace names that
should be used when generating new workspaces
2018-12-17 16:25:44 +01:00
mwenzkowski 01420193ef Fix criteria execution in view_map
This patch moves view_execute_criteria(view) below the fullscreen code.
Previously, if a view requested to be started in fullscreen, this was
done after execution of criteria and hence it was impossible to disable
fullscreen via criteria.

Fixes #3285
2018-12-12 13:41:47 +01:00
Ian Fan 98c1e19466 list.c: rename free_flat_list to list_free_items_and_destroy 2018-12-09 01:15:38 +00:00
Ian Fan 19e831ed3d list.c: Remove list_foreach
Most occurrences have been replaced by `free_flat_list` which has been
moved from stringop.c to list.c. The rest have been replaced by for loops.
2018-12-09 00:37:50 +00:00
Brian Ashworth 71ae08530a Fix default_orientation auto
Since the output config is no longer applied before creating the default
workspace, the layout for default workspaces on an output may not be
correct. Due to the ordering of calls in output_enable being changed in
several bug fix PRs, this just fixes the layout after the call to
apply_output_config.
2018-11-28 13:52:54 -05: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
emersion b98563d2d7
Fix segfault when destroying unmapped child view 2018-11-28 14:08:20 +01:00
Ryan Dwyer f737854e30
Merge pull request #3199 from emersion/handle-subsurface-destroy
Handle destroyed subsurfaces
2018-11-28 20:46:22 +10:00
Brian Ashworth 5c6f3d7266 Change execute_command to return a list of results
This matches i3's behavior of returning a list of results that contain
the result of each command that was executed. Additionally, the
`parse_error` attribute has been added to the IPC JSON reply.
2018-11-27 21:42:09 -05:00
emersion 1d30b7c0f6
Damage view child when destroyed 2018-11-27 21:13:08 +01:00