Commit graph

355 commits

Author SHA1 Message Date
Daniel De Graaf 69a7b9215e Fix overly-wide mark textures
The width of the texture needs to be calculated using the string that is
actually displayed in the texture.
2021-09-04 17:23:06 +02:00
Hugo Osvaldo Barrera 9acb015755 Deduplicate code for rendering titlebar texts
The title itself and marks were being rendered by two very-similar yet
different functions, and any changes made to one had to be reflected on
the other.

This mostly prevents such oversights from happening, and keeps makes
sure we keep both consistent.
2021-08-27 10:12:57 +02:00
Hugo Osvaldo Barrera 62d90a8e95 Use fixed titlebar heights
Use fixed titlebar heights. The default height is calculated based on
font metrics for the configured font and current locale.

Some testing with titles with emoji and CJK characters (which are
substantially higher in my setup) shows that the titlebars retain their
initial value, text does shift up or down, and all titlebars always
remain aligned.

Also drop some also now-unecessary title_height calculations.

Makes also needed to be updated, since they should be positioned with
the same rules.
2021-08-26 20:16:14 +02:00
Dudemanguy acf946fe4c xdg-decoration: let floating clients set borders
The xdg-decoration protocol allows clients to request whether they want
to use server side decorations or client side decorations. Currently,
sway ignores this and always enforces whatever the server is currently
set to. Although tiled clients cannot be allowed to set borders, there
is no harm in listening requests from floating clients. Sidenote: also
fix an unrelated style error.
2021-08-12 10:02:17 +02:00
Dudemanguy c41dc33590 container: ignore borders in fullscreen windows
When setting the geometry from content for floating windows, the
coordinates for borders are normally taken into account. However in the
case of a floating fullscreen window, we should not be doing this. Since
the content of the container takes the space of the entire output, this
causes the calculated borders to neccesarily be outside of the output.
This later causes a problem when sending surface entrance events since
in a multi-monitor setup, the border coordinates will overlap with
another output despite the surface not actually being on that output at
all. The fix is to just ignore border coordinates for a floating
fullscreen container since fullscreen, of course, does not actually have
any borders. Fixes #6080.
2021-07-06 22:54:24 +02:00
Simon Ser 22226560e3 tree/container: fix indentation 2021-07-05 10:09:39 +02:00
Issam E. Maghni d45623c2db cairo: Replace <cairo/cairo.h> by <cairo.h>
For full context, read
https://gitlab.freedesktop.org/cairo/cairo/-/issues/479
TL;DR, cairo’s pc file adds `/cairo` to CFLAGS.
So namespace cairo shouldn’t be used.
2021-05-10 10:28:32 +02:00
Simon Ser e3e99d961d Avoid creating zero-sized textures for marks
Same as 6327f1b361 ("Avoid creating zero-sized textures for titlebars")
but for marks.
2021-04-20 17:29:16 +02:00
Simon Ser 3173a4f353 Use cairo_image_surface_get_stride instead of guessing it 2021-04-20 17:28:30 +02:00
Simon Ser 6327f1b361 Avoid creating zero-sized textures for titlebars
Creating a zero-sized wlr_texture is incorrect.
2021-04-20 17:22:06 +02:00
ash lea eb9e77f4ea container: don't set fullscreen on children
the original behavior set fullscreen for all descendents of a container,
which causes issues when firefox is one of those children because it
sends its own set_fullscreen request in response to being fullscreened.
2021-04-15 16:58:27 -07:00
Ronan Pigott a558866f42 container: retain focus position on floating enable
When a tiling container is floated, the focus stack needs to be
appropraitely modified to return the container to its original
position in the tree upon floating disable, like i3.
2021-04-11 21:01:33 -04:00
Kenny Levinsen 2e06403548 container: Add view_container_content_at
container_at checks if the position provided matches the currently
focused container with view_container_at as a fast path.

view_container_at checks using the main container geometry, which
includes the titlebar and border area. If a tabbed container is focused,
then positions over unfocused tabs are incorrectly reported as belonging
to the focused container, breaking focus on click.

Add view_container_content_at for use in the focused container fast path
which only tests container content area, and fall back to full workspace
scans for border and titlebar areas.

Closes: https://github.com/swaywm/sway/issues/6074
2021-03-10 17:50:57 +01:00
Kenny Levinsen d358aab8d9 container: Limit tiled focus to container geometry
container_at would maintain the current focus as long as a position was
over one of the container view's surfaces. If an oversized surface was
being clipped, this lead to weird focus behavior.

Instead, use view_container_at for this test, which intersects the
container box before looking at surfaces.
2021-03-01 16:14:10 +01:00
lbonn c6e7cf1ae5 focus: beyond fullscreen when focused explicitly
When issuing a focus command on a specific container, users expect to
proceed it even if is hidden by a fullscreen window.

This matches the behavior of i3.
2021-02-25 09:40:20 -05:00
Simon Ser 66343839b1 Fix wl_shm_format passed to wlr_texture_from_pixels
See https://github.com/swaywm/wlroots/pull/2744
2021-02-23 17:42:04 +01:00
Kenny Levinsen 2c917a8c34 container: Add container_is_current_floating
Needed to check if containers are currently floating from render code,
as container_is_floating checks pending state.
2021-02-22 23:55:22 +01:00
Kenny Levinsen a047b5ee4a container: Move pending state to state struct
Pending state is currently inlined directly in the container struct,
while the current state is in a state struct. A side-effect of this is
that it is not immediately obvious that pending double-buffered state is
accessed, nor is it obvious what state is double-buffered.

Instead, use the state struct for both current and pending.
2021-02-16 22:05:00 -05:00
Ronan Pigott d1c4ed1867 container: set fullscreen mode before attempting focus 2020-12-24 23:34:55 +01:00
Ronan Pigott 8eb0c54693 introduce workspace_squash
workspace_squash is container_flatten in the reverse
direction. Instead of eliminating redundant splits that are
parents of the target container, it eliminates pairs of
redundant H/V splits that are children of the workspace.

Splits are redundant if a con and its grandchild have the
same layout, and the immediate child has the opposite split.

For example, layouts are transformed like:

    H[V[H[app1 app2]] app3] -> H[app1 app2 app3]

i3 uses this operation to simplify the tree after moving
heavily nested containers to a higher level in the tree via
an orthogonal move.
2020-12-20 00:58:42 -05:00
Ronan Pigott ece6a1d408 Change workspace_layout to match i3 behavior
In i3, the workspace_layout command does not affect the
workspace layout. Instead, new workspace level containers
are wrapped in the desired layout and the workspace layout
always defaults to the output orientation.
2020-12-20 00:58:42 -05:00
Ronan Pigott b4850876dc Revert "commands/move: maintain workspace_layout when moving"
This is in preparation for changing the workspace_layout
command to work like it does in i3.

This reverts commit b4a75a1ab2.
2020-12-20 00:58:42 -05:00
Ronan Pigott 2478f2f010 container: don't split single children
In i3 splits are ineffective on singleton H/V containers,
and the command is interpreted to affect the parent layout
instead.
2020-12-20 00:58:42 -05:00
Tudor Brindus 07042486c3 tree/container: introduce container_is_sticky[_or_child] functions
To query whether a container is sticky, checking `con->is_sticky` is
insufficient. `container_is_floating_or_child` must also return true;
this led to a lot of repetition.

This commit introduces `container_is_sticky[_or_child]` functions, and
switches all stickiness checks to use them. (Including ones where the
container is already known to be floating, for consistency.)
2020-11-11 20:43:58 -05:00
Dimitris Triantafyllidis 39328ca4e4 In container_split, set a floating container's view to tiled
Currently, when a floating container with a view is split and
children are added to it, the new views are rendered as tiled,
while the first view stays in floating style.

Here this is addressed by setting the view to tiled as soon
as the container is split, by duplicating the "view part" of
the logic in container_set_floating(..., false). Since the new
container of the view is no longer considered floating, it
makes sense to set the view to tiling at this point.

The view would have to be set back to floating if it was possible
to "unsplit" the container.
2020-10-28 00:36:33 -04:00
mwenzkowski 13a67da614 container: Fix NULL pointer dereference
Reset the workspace layout to the output's default only if the workspace
is actually attached to an output.

Fixes #5762
2020-10-24 19:40:25 -04:00
Ronan Pigott a01573016a view: implement foreign toplevel fullscreen indicator 2020-08-05 11:05:49 +02:00
Ronan Pigott 39d677af15 input: implement xdg_toplevel interactive resize hints 2020-07-13 00:21:52 -04:00
Tudor Brindus b4a75a1ab2 commands/move: maintain workspace_layout when moving
Fixes #5157.
2020-07-03 18:40:59 -04:00
Drew DeVault 8d5e627bc9 Implement wlr-foreign-toplevel-management-v1 2020-06-23 22:26:00 +02:00
Tudor Brindus 53dc83fb68 tree/container: introduce container_toplevel_ancestor helper
This allows us to not have to explicitly write the same while loop
everywhere.
2020-06-07 10:46:14 +02:00
Tudor Brindus 83866558d3 tree/container: refactor tiling_container_at to check bounds
This fixes bugs where a floating container would take input way past its
borders when its parent was fullscreen, since the call to
`tiling_container_at` in input/cursor.c's `node_at_coords` did not check
bounds.
2020-05-30 02:16:15 -04:00
Ian Huang 276e0301e0 interpret "subpixel none" as CAIRO_ANTIALIAS_GRAY
See issue #5228. Currently, WL_OUTPUT_SUBPIXEL_NONE is ignored and
CAIRO_ANTIALIAS_SUBPIXEL is still set. This commit checks if subpixel is
set to none and if so, calls set_antialias with CAIRO_ANTIALIAS_GRAY.
This mirrors the functionality in Mako's
[PR261](https://github.com/emersion/mako/pull/261)
2020-04-20 09:26:37 +02:00
Josh Shone 82d02ce782 Fix hit test for floaters that cross outputs
In the case of multiple overlapping floating windows, this commit fixes an issue where the wrong window would be focused in response to a cursor if one of the windows came from a different output (overhanging).
2020-03-27 21:32:26 +01:00
Brian Ashworth 0b709702c1 container_at_{tabbed,stacked}: check x-axis bounds
The container_at_tabbed and container_at_stacked container were checking
the bounds along the y-axis, but not the x-axis. This made it possible
to cause a segfault for specific resolution, horizontal gap, and
workspace children lengths. The issue is that child_index was -1 and was
resulting in a buffer underflow. Adding the x-axis bound checks for
early returns should prevent this from happening.
2020-02-11 10:09:37 +01:00
Ronan Pigott d88d4bbd9d Fix crash when showing scratchpad hidden split containers 2020-01-16 21:48:25 -05:00
Brian Ashworth a4e4e21edf container: add inactive fullscreen to focus stack
When a container was being made fullscreen and it is on the focused
workspace for a seat, focus was being set to the container. However,
when the container was on a non-focused workspace, the focus stack
wasn't being touched. When assigning a fullscreen container to a
workspace or moving a fullscreen container to a different workspace,
this would make it so the fullscreen container was never added to the
focus stack for the workspace thus preventing access to the workspace.
This adds the container to the top of the focus stack, behind the
container on the focused workspace.
2020-01-14 07:38:57 -07:00
lbonn 7baa3ffece Allow moving a container hidden in scratchpad
(as i3 allows it)

Just update the container's coordinates so that they will be applied at
the next show.
2019-08-20 13:09:52 -04:00
Simon Ser 7488d33d42 Remove xdg-shell v6 support
All major toolkits and apps have gained xdg-shell stable support.

Closes: https://github.com/swaywm/sway/issues/3690
2019-08-20 10:57:20 +09:00
Brian Ashworth 75a7b02529 container_replace: copy {width,height}_fraction
This copies the width and height fractions from the container to the
container replacing it. Without setting these values, the container
is treated as a new container and throws off the existing sizing. Since
one container is replacing the other, it makes sense for the sizing to
remain the same.
2019-08-14 13:18:57 +09:00
Simon Ser f984f21b6a Remove all wayland-server.h includes
The documentation for wayland-server.h says:

> Use of this header file is discouraged. Prefer including
> wayland-server-core.h instead, which does not include the server protocol
> header and as such only defines the library PI, excluding the deprecated API
> below.

Replacing wayland-server.h with wayland-server-core.h allows us to drop the
WL_HIDE_DEPRECATED declaration.

This commit si similar to wlroots' ca45f4490ccc ("Remove all wayland-server.h
includes").
2019-07-27 17:16:56 -04:00
Pedro Côrte-Real d0233af3b3 Rework gaps code to be simpler and correct
Instead of tracking gaps per child apply gaps in two logical places:

1. In tiled containers use the layout code to add the gaps between
windows. This is much simpler and guarantees that the sizing of children
is correct.
2. In the workspace itself apply all the gaps around the edge. Here
we're in the correct position to size inner and outer gaps correctly and
decide on smart gaps in a single location.

Fixes #4296
2019-07-15 23:46:27 -04:00
Pedro Côrte-Real e3a3917d3a Layout tiled using a width/height fraction
Instead of using container->width/height as both the input and output
of the layout calculation have container->width_fraction/height_fraction
as the share of the parent this container occupies and calculate the
layout based on that. That way the container arrangement can always be
recalculated even if width/height have been altered by things like
fullscreen.

To do this several parts are reworked:

- The vertical and horizontal arrangement code is ajusted to work with
  fractions instead of directly with width/height
- The resize code is then changed to manipulate the fractions when
  working on tiled containers.
- Finally the places that manipulated width/height are adjusted to
  match. The adjusted parts are container split, swap, and the input
  seat code.

It's possible that some parts of the code are now adjusting width and
height only for those to be immediately recalculated. That's harmless
and since non-tiled containers are still sized with width/height
directly it may avoid breaking other corner cases.

Fixes #3547
Fixes #4297
2019-07-14 11:13:55 -04:00
random human 0ba959f1ce tree: set correct border value before creating floater 2019-06-27 11:13:02 -04: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 462ad4ea83 cmd_move: respect workspace layout when inserting
When moving a container to become a direct child of the workspace and
the workspace's layout is tabbed or stacked, wrap it in a container
with the same layout. This allows for the following:
- Run `layout tabbed|stacked` on an empty workspace (or use
  `workspace_layout tabbed|stacked` in the config)
- Open some views
- Move one of the views in any direction
- Open another view
- The new container should also be `tabbed`/`stacked`
2019-04-24 19:12:24 -06: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
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 0676ace97f floating: fix size of non-view containers
This fixes the sizing of floating non-view containers. On master, the
floater will get set to the maximum width and height, which by default
is the entire output layout. When setting a non-view container to
floating, this will set a sane default size of 50% of the workspace
width and 75% of the workspace height, or whatever the closest is that
the minimum and maximum floating width/height values allow for. On all
future calls to `floating_natural_resize`, the width and height will be
kept unless they need to be changed to respect the min/max floating
width/height values.
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