Commit graph

316 commits

Author SHA1 Message Date
Kirill Primak e76e13ef85 view: fix child position calc
Previously, the position was calculated incorrectly for nested
subsurfaces.
2021-09-08 09:36:17 +02:00
Kirill Primak ae80bdedf9 surface: chase wlr subsurface list/link change 2021-09-06 17:39:28 +02:00
Kirill Primak 72b0491ca0 view: fix saved buffer order 2021-09-05 12:31:46 +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
novenary dbc326ba84 Don't apply hide_edge_borders to any floating container
This fixes the following scenario:
- Place a floating window so its border is right at the edge of the
  screen
- Create a new split
- The border disappears
- Moving the window does not restore the border
2021-06-20 15:39:04 -04:00
Simon Ser 3162766eef Iterate over subsurfaces below the parent surface
Update for the breaking change in [1].

[1]: https://github.com/swaywm/wlroots/pull/2948
2021-06-03 14:06:29 +02:00
Ronan Pigott 5a73dc1bc2 view: commit transactions for foreign toplevel requests 2021-05-17 08:57:20 +02:00
Rouven Czerwinski 30e400c0a3 view: handle case where map_ws is NULL
When a criteria places the view into the scratchpad, map_ws is NULL and
trying to access map_ws->fullscreen will result in SIGSEGFAULT with:

  #0  0x0000000000455327 in should_focus (view=0x15a6a70) at ../sway/tree/view.c:604
          prev_con = 0x0
          len = <optimized out>
          seat = 0x12233c0
          prev_ws = 0x1264c80
          map_ws = 0x0
          criterias = <optimized out>
          seat = <optimized out>
          prev_con = <optimized out>
          prev_ws = <optimized out>
          map_ws = <optimized out>
          criterias = <optimized out>
          len = <optimized out>
          num_children = <optimized out>
  #1  view_map (view=view@entry=0x15a6a70, wlr_surface=0x15a5cb0, fullscreen=<optimized out>, fullscreen_output=<optimized out>, decoration=<optimized out>) at ../sway/tree/view.c:809
          __PRETTY_FUNCTION__ = "view_map"
          ws = <optimized out>
          seat = <optimized out>
          node = <optimized out>
          target_sibling = <optimized out>
          container = 0x1625400
          set_focus = <optimized out>
          app_id = <optimized out>
          class = <optimized out>
  #2  0x0000000000423a7e in handle_map (listener=0x15a6c78, data=<optimized out>) at ../sway/desktop/xdg_shell.c:454
          xdg_shell_view = 0x15a6a70
          view = 0x15a6a70
          xdg_surface = 0x15a6620
          csd = <optimized out>
  #3  0x00007f508bd3674c in wlr_signal_emit_safe (signal=signal@entry=0x15a6718, data=data@entry=0x15a6620) at ../subprojects/wlroots/util/signal.c:29
          pos = 0x15a6c78
          l = 0x15a6c78
          cursor = {link = {prev = 0x15a6c78, next = 0x7fff53d58190}, notify = 0x7f508bd366c0 <handle_noop>}
          end = {link = {prev = 0x7fff53d58170, next = 0x15a6718}, notify = 0x7f508bd366c0 <handle_noop>}
  #4  0x00007f508bd15b29 in handle_xdg_surface_commit (wlr_surface=<optimized out>) at ../subprojects/wlroots/types/xdg_shell/wlr_xdg_surface.c:384
          surface = 0x15a6620
  #5  0x00007f508bd2e981 in surface_commit_state (surface=surface@entry=0x15a5cb0, next=next@entry=0x15a5e18) at ../subprojects/wlroots/types/wlr_surface.c:455
          __PRETTY_FUNCTION__ = "surface_commit_state"
          invalid_buffer = <optimized out>
          subsurface = 0x15a6038
  #6  0x00007f508bd2f53b in surface_commit_pending (surface=0x15a5cb0) at ../subprojects/wlroots/types/wlr_surface.c:474
          next_seq = 3
          next_seq = <optimized out>
  #7  surface_commit (client=<optimized out>, resource=<optimized out>) at ../subprojects/wlroots/types/wlr_surface.c:542
          surface = 0x15a5cb0
          subsurface = <optimized out>

If map_ws is NULL we assume the view is places into the scratchpad and
return false as well.
2021-04-29 09:06:05 +02:00
Tudor Brindus 80128d23ba tree/view: don't give focus to views mapped under fullscreen views
Fixes #6211.
2021-04-25 11:20:56 +02:00
Dominique Martinet 8529141150 view_destroy: fix use-after-free with subsurface_destroy
remove view from its own unmap event listener so when subsurfaces
link try to remove themselves they won't run into it.

This fixes the following ASAN use-after-free error on a build slightly
modified to instrument wl_list operations:
==71705==ERROR: AddressSanitizer: heap-use-after-free on address 0x6160000829a0 at pc 0x000000508eb7 bp 0x7ffec8fd8030 sp 0x7ffec8fd8028
WRITE of size 8 at 0x6160000829a0 thread T0
    #0 0x508eb6 in wl_list_remove ../common/list.c:181
    #1 0x4f4998 in view_child_destroy ../sway/tree/view.c:1131
    #2 0x4f38fa in subsurface_handle_destroy ../sway/tree/view.c:946
    #3 0x7fda50744892 in wlr_signal_emit_safe ../util/signal.c:29
    #4 0x7fda5072f0dd in subsurface_destroy ../types/wlr_surface.c:649
    #5 0x7fda507312c4 in subsurface_handle_surface_destroy ../types/wlr_surface.c:1094
    #6 0x7fda50744892 in wlr_signal_emit_safe ../util/signal.c:29
    #7 0x7fda5072f305 in surface_handle_resource_destroy ../types/wlr_surface.c:677
    #8 0x7fda508180ce in destroy_resource (/lib64/libwayland-server.so.0+0xc0ce)
    #9 0x7fda508187f2 in wl_client_destroy (/lib64/libwayland-server.so.0+0xc7f2)
    #10 0x7fda50818e5f in wl_client_connection_data (/lib64/libwayland-server.so.0+0xce5f)
    #11 0x7fda50818219 in wl_event_loop_dispatch (/lib64/libwayland-server.so.0+0xc219)
    #12 0x7fda50818984 in wl_display_run (/lib64/libwayland-server.so.0+0xc984)
    #13 0x43122c in server_run ../sway/server.c:254
    #14 0x42f47c in main ../sway/main.c:433
    #15 0x7fda503cab74 in __libc_start_main (/lib64/libc.so.6+0x27b74)
    #16 0x40f6fd in _start (/opt/wayland/bin/sway+0x40f6fd)

0x6160000829a0 is located 288 bytes inside of 592-byte region [0x616000082880,0x616000082ad0)
freed by thread T0 here:
    #0 0x7fda50f01a27 in free (/lib64/libasan.so.6+0xaea27)
    #1 0x4532d8 in destroy ../sway/desktop/xdg_shell.c:262
    #2 0x4ed17b in view_destroy ../sway/tree/view.c:67
    #3 0x4ed300 in view_begin_destroy ../sway/tree/view.c:83
    #4 0x454a3f in handle_destroy ../sway/desktop/xdg_shell.c:507
    #5 0x7fda50744892 in wlr_signal_emit_safe ../util/signal.c:29
    #6 0x7fda506e2c87 in reset_xdg_surface ../types/xdg_shell/wlr_xdg_surface.c:481
    #7 0x7fda506e3018 in destroy_xdg_surface ../types/xdg_shell/wlr_xdg_surface.c:516
    #8 0x7fda506dfbe5 in xdg_client_handle_resource_destroy ../types/xdg_shell/wlr_xdg_shell.c:71
    #9 0x7fda508180ce in destroy_resource (/lib64/libwayland-server.so.0+0xc0ce)

previously allocated by thread T0 here:
    #0 0x7fda50f01ed7 in calloc (/lib64/libasan.so.6+0xaeed7)
    #1 0x454bc8 in handle_xdg_shell_surface ../sway/desktop/xdg_shell.c:528
    #2 0x7fda50744892 in wlr_signal_emit_safe ../util/signal.c:29
    #3 0x7fda506e2363 in handle_xdg_surface_commit ../types/xdg_shell/wlr_xdg_surface.c:378
    #4 0x7fda5072e368 in surface_commit_state ../types/wlr_surface.c:455
    #5 0x7fda5072e51d in surface_commit_pending ../types/wlr_surface.c:474
    #6 0x7fda5072ea58 in surface_commit ../types/wlr_surface.c:542
    #7 0x7fda4fb3ac03 in ffi_call_unix64 (/lib64/libffi.so.6+0x6c03)

Fixes #5168
2021-04-22 23:19:08 +02:00
Kenny Levinsen d79ea9a0db view: subsurface NULL check in view_from_wlr_surface
Necessary NULL checks had been added to xdg_shell and xwayland surfaces,
but subsurfaces had been missed.
2021-03-24 00:55:15 +01:00
Kenny Levinsen 70842f4e14 view: Handle NULL role object when role is set
wlr_(xdg|xwayland)_surface_from_wlr_surface can return NULL even though
wlr_surface_is_(xdg|xwayland)_surface returned true.
2021-03-21 12:27:29 +01:00
Kenny Levinsen 1a6471be17 view: Set parent for view_child subsurfaces on init
view_child_init was calling view_init_subsurfaces, which did not set the
parent attribute for the subchildren. This lead to the subchildren
acting as standalone children. If the parent was an xdg_popup, this
would make the subchild unaware of the popup position.

Introduce view_child_init_subsurfaces for view_child_init to use
instead.

Closes: https://github.com/swaywm/sway/issues/6038
2021-02-23 00:17:32 +01:00
Kenny Levinsen 79e43b19d7 view: Mark subchildren as unmapped in view_child_destroy
The subchildren lose their parent association at this point, so they
will not be able to see that the parent is unmapped.

Instead, just set the subchildren to be unmapped directly.
2021-02-23 00:17:32 +01:00
Kenny Levinsen e7af5b6309 view: Recursively check mapped of view_child tree
A subsurface may be set to mapped without its parent.
2021-02-23 00:17:32 +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
Kenny Levinsen 63a6635163 view: Read geometry directly in view_update_size 2021-02-09 09:37:10 +01:00
Kenny Levinsen 90fa6953ea shells: Only center tiled views on size change
The size of a tiled container cannot change in response to new buffer
sizes, so there is no need to commit a new transaction. Instead, simply
recenter the view with the new geometry, leaving the full transaction
flow for floating containers.
2021-02-09 09:37:10 +01:00
Kenny Levinsen 50205ade9d transaction: Move centering to view_center_surface
This will allow us to reuse it for centering elsewhere.
2021-02-09 09:37:10 +01:00
Kenny Levinsen cf1e3be228 view: Save surface x and y on saved buffers
We need to use surface_x and surface_y when rendering and damaging saved
buffers as these compensate for views that have been centered due to
being smaller than their container.

Add them to the surface positions on the saved buffer so we have the
values from the time the buffer was saved.
2021-02-09 09:37:10 +01:00
fwsmit 241ce2af83 Implement foreign toplevel fullscreen output hints 2021-01-25 11:54:44 -07:00
BrassyPanache 62ec528c8c Adhere to ICCCM focus specification
For certain applications (e.g. JetBrains) the parent window controls
input. We need to adhere to the ICCCM input focus specification to
properly handle these cases.

Relates to swaywm/wlroots#2604
2021-01-20 10:50:04 +01:00
Simon Ser 5438cc158a Switch to wlr_xdg_surface_for_each_popup_surface
Instead of calling wlr_xdg_surface_for_each_popup and then
wlr_surface_for_each_surface, use the new for_each_popup_surface helper
introduced in [1] that does it in one go.

[1]: https://github.com/swaywm/wlroots/pull/2609
2021-01-12 11:25:34 +01: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
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 0cb9282aee Smart borders fix: always show borders for floating containers
Currently, in view_autoconfigure, the only condition for show_border
is !view_is_only_visible. view_is_only_visible does not cross the
boundary between the workspace's tiling and floating lists and does not
differentiate between them.

The result is, that in a workspace with zero or more tiling containers
and a single floating container, the floating container will lose its
borders as soon as it is split, provided that a only one view is visible
within the floating container.

Fixed by adjusting the condition for show_borders.
2020-10-25 21:59:40 -04:00
Ronan Pigott b7f28cd6b7 view: remove foreign toplevel listeners on destroy 2020-08-05 11:05:49 +02:00
Ronan Pigott f478f4cc66 view: implement foreign toplevel fullscreen request 2020-08-05 11:05:49 +02:00
Ronan Pigott 3520fd2c19 view: display scratchpad hidden containers when activated by ftm 2020-07-25 11:53:01 -04:00
Simon Ser b5a35c484f tree/view: fix segfault in view_update_title
xdg-shell doesn't allow clients to set the title to NULL, so we
shouldn't need to call wlr_foreign_toplevel_handle_v1_set_title with an
empty string to reset the old one.

Closes: https://github.com/swaywm/sway/issues/5488
2020-07-03 09:23:35 +02:00
Johan Bjäreholt 1f8dbb320a tree/view: Make foreign-toplevel app_id fallback to class
It is not a part of the foreign-toplevel-management protocol to get the
class of a toplevel, only for getting the app_id.
For xwayland clients this is an issue because that means that you cannot
identify what application the toplevel refers to which is the point of
the app_id property.

By falling back to class when an app_id does not exist solves this problem.

Phoc also uses app_id and class interchangeably in their implementation
of foreign-toplevel-management, in fact they always do that and not only
for just this protocol.
c8d8a4c544/src/xwayland.c (L236)
2020-07-01 17:21:57 +02:00
Tudor Brindus bb85b9070d tree/view: fix smart borders with tabbed/stacked ancestor
Fixes #5484.
2020-06-27 21:05:58 -04:00
Drew DeVault 8d5e627bc9 Implement wlr-foreign-toplevel-management-v1 2020-06-23 22:26:00 +02:00
Simon Ser e19bd1e474 Add support for viewporter
Depends on [1].

[1]: https://github.com/swaywm/wlroots/pull/2092
2020-06-17 10:18:58 -06:00
Simon Ser f9361ae36c Remove view child surface_{map,unmap} listeners on destroy 2020-06-12 19:37:19 -04:00
Ronan Pigott 90d936d4ad view: fix surface_new_subsurface use-after-free 2020-06-13 00:55:33 +02:00
Tudor Brindus ed08f2f20c tree/view: fix smart gaps when ancestor container is tabbed or stacked
Fixes #5406.
2020-06-08 19:01:45 -04:00
Kalyan Sriram e3e548a648
Save transform during transaction
Closes: https://github.com/swaywm/sway/issues/5412
2020-06-05 14:13:18 +02:00
Kenny Levinsen 5a4a7bc0da container: Remove useless surface dimensions
The adjustments to resize logic left them unnecessary.
2020-06-03 16:41:17 +02:00
Kenny Levinsen 4edd429053 view: update_size should only update pending size
Updating the current size outside transactions lead to rendering
glitches during resizes.
2020-06-03 16:41:17 +02:00
Kenny Levinsen fcd0ab8f33 view: Save all buffers associated with view
During the execution of a resize transaction, the buffer associated
with a view's surface is saved and reused until the client acknowledges
the resulting configure event.

However, only one the main buffer of the main surface was stored and
rendered, meaning that subsurfaces disappear during resize.

Iterate over all, store and render buffers from all surfaces in the view
to ensure that correct rendering is preserved.
2020-06-03 16:41:17 +02:00
Damien Tardy-Panis 0cbd26f0da Add views idle inhibition status in get_tree output
Fixes #5286
2020-05-29 17:29:41 -04:00
Michael Weiser 0f11aa037a commands: Add per-view shortcuts_inhibitor command
Add a separate per-view shortcuts_inhibitor command that can be used
with criteria to override the per-seat defaults. This allows to e.g.
disable shortcuts inhibiting globally but enable it for specific,
known-good virtualization and remote desktop software or, alternatively,
to blacklist that one slightly broken piece of software that just
doesn't seem to get it right but insists on trying.

Add a flag to sway_view and handling logic in the input manager that
respects that flag if configured but falls back to per-seat config
otherwise. Add the actual command but with just enable and disable
subcommands since there's no value in duplicating the per-seat
activate/deactivate/toggle logic here. Split the inhibitor retrieval
helper in two so we can use the backend half in the command to retrieve
inhibitors for a specific surface and not just the currently focused
one. Extend the manual page with documentation of the command and
references to its per-seat sibling and usefulness with criteria.

Signed-off-by: Michael Weiser <michael.weiser@gmx.de>
2020-05-13 21:22:16 -04:00
Simon Ser 3a5d9b3b32 Update for new wlr_buffer API
Update for [1].

[1]: https://github.com/swaywm/wlroots/pull/2044
2020-04-02 23:23:56 +02:00
Simon Ser 9d0aa0cb83 Use wlr_client_buffer
Update for breaking changes in [1].

[1]: https://github.com/swaywm/wlroots/pull/2043
2020-03-06 23:57:43 +01:00
Brian Ashworth 0c23525d47 tree/view: do not attempt enter on hidden child
If a subsurface is created for a surface that is associated with a
scratchpad hidden view, do not attempt to send an enter to it. The
subsurface is not on any output and since there is no workspace
associated with the view, attempting to get the output for the NULL
workspace will result in a SIGSEGV.
2020-02-18 10:27:37 +01:00
Brian Ashworth c99d423ad9 view: remove workspace pid mapping for assigns
If a view is mapped to a workspace using an assign, the pid should still
be removed from the pid mapping list. This prevents child processes from
matching against it and mapping a view to a likely undesired workspace.
2020-01-09 09:52:37 +01:00
Ronan Pigott 3975ca28c2 smart_borders: separate smartness from edge types 2019-11-04 21:16:27 -05:00
Ronan Pigott ec66bb987a view: create container before selecting workspace 2019-09-22 15:18:51 -04:00
Brian Ashworth da0ad4c39e view: always populate pid
If the view was mapped as fullscreen or the view was assigned either a
workspace or output, the pid was not being populated since it was
occurring as part of the pid mapping check in select_workspace. This
extracts the pid population and makes it so it is always executed
2019-09-20 20:47:59 +03:00