wlr_scene_*_create() functions all allocate memory via calloc() and
return NULL if the allocation fails. Previously, the failures were
handled in any of 3 different ways:
- sending a wayland protocol error
- exiting labwc with an error
- segfault (no NULL check at all)
Since labwc does not attempt to survive heap exhaustion in other
allocation paths (such as `znew`), it seems more consistent to use the
same die_if_null() check used in those paths to exit with an error.
For the three most common create() functions (tree, rect, buffer),
add small lab_wlr_ wrappers to common/scene-helpers.
4f8b80700e added a check for the output
being enabled when creating a layershell surface with automatic output
selection. This causes labwc to send a `layer_surface.close()` and
`wl_surface.destroy()` to layershell clients when creating a new
layershell surface on a disabled output which is still part of the layout
(e.g. `wlopm --off`).
This MR replaces the `output_is_usable()` check with a dedicated check,
bypassing the check for the output being enabled.
Fixes: #3410
Reported-By: coruja
Ensure that pointer focus is restored to the surface below when a layer
surface or popup is unmapped. Can be tested like below:
1. Open a terminal and move the cursor over it so it becomes an I-beam
2. Open a launcher (e.g. fuzzel) so the cursor becomes an arrow
3. Close the launcher
4. The cursor should become an I-beam again
Note: this commit restores `cursor_update_focus()` in
`handle_popup_destroy()` which was removed in bdbb1be3. I don't remember
why it was removed.
When a opening a layer-shell popup via IPC (like `lxVqt-qdbus openmenu` or
`xfce4-popup-applicationsmenu`), give keyboard focus to the popup, not the
parent layer-shell surface.
Written-by: @tokyo4j
...in support of enabling panel menus to be opened by keyboard shortcuts
and get keyboard focus so that they can be operated with the keyboard.
An example use-case is the xfce4-panel applications-menu being opened by
the command xfce4-popup-applicationmenu.
Soften the new rule introduced by 155c153 because it broke lxqt-runner
which defaults to the top-layer, and we do not want to knowingly break
user-space without a very good reason which we do not have for this.
Fixes: #3381
...so that clients with on-demand keyboard interactivity in the
background/bottom/top layers do not steal focus. The reason for this is to
avoid desktop components like panels and desktops from stealing keyboard
focus if they are re-started.
We still let such clients in the overlay layer get focus on map so that
for example labnag with its default <prompt> setting take keyboard focus
on map, whilst still letting users click on something else to move focus
away.
Fixes: #3167
- check for valid scene_output in output_is_usable()
- change many "output != NULL" checks to use output_is_usable()
- remove one now-redundant separate check for valid scene_output
Fixes a crash at startup (with autoEnableOutputs=no) due to
dereferencing null scene_output in create_output_config() since:
7d7ece21d9
("output: suppress error when output position is unavailable")
Fixes: #3357
struct ssd_part and struct node_descriptor seem to have essentially the
same purpose: tag a wlr_scene_node with some extra data indicating what
we're using it for.
Also, as with enum ssd_part_type (now lab_node_type), ssd_part is used
for several types of nodes that are not part of SSD.
So instead of the current chaining (node_descriptor -> ssd_part), let's
flatten/unify the two structs.
In detail:
- First, merge node_descriptor_type into lab_node_type.
- Add a separate view pointer in node_descriptor, since in the case of
SSD buttons we need separate view and button data pointers.
- Rename ssd_part_button to simply ssd_button. It no longer contains
an ssd_part as base.
- Add node_try_ssd_button_from_node() which replaces
node_ssd_part_from_node() + button_try_from_ssd_part().
- Factor out ssd_button_free() to be called in node descriptor destroy.
- Finally, get_cursor_context() needs a little reorganization to handle
the unified structs.
Overall, this simplifies the code a bit, and in my opinion makes it
easier to understand. No functional change intended.
This is a common practice in C projects, which simply enforces that
each header must compile cleanly without implicit dependencies on
other headers (see also the previous commit).
Call seat_set_focus_layer(seat, NULL) in node-destroy-handler to avoid
seat->focused_layer becoming invalid and causing UAF issues in certain
situations like when outputs (and therefore layer-trees) are destroyed.
Fixes: #2863
Helped-by: @Consolatis
Alternative to 7bf08af which was reverted in the previous commit.
7bf08af fixed the problem that layer-shell clients are terminated when
it's unmapped, by sending configure events in node-destroy handler
rather than in unmap handler. But it caused a UAF bug when an output
with layer-shell clients is destroyed.
So this patch fixes the original issue by simply skipping the surface in
arrange_one_layer() if it's being unmapped.
This ensures all event listeners are removed before the emitting
wlroots object is being destroyed. This will be enforced with asserts
in wlroots 0.19 but there is no reason to not do it right now either.
This change in wlroots 0.19 is implemented via commit
8f56f7ca43257cc05c7c4eb57a0f541e05cf9a79
"Assert (almost all) signals have no attached listeners on destroy"
With wlroots 0.18, layer-shell's new_surface event is emitted on
zwlr_layer_shell_v1.get_layer_surface request rather than the first
commit. This change layer-shell clients like fuzzel to flicker on launch
because labwc was sending a configure event with fullscreen geometry due
to the absence of geometry hints on get_layer_surface requests.
This commit removes the code that updates the usable area from
new_surface handler, preventing unintended configure events with
fullscreen geometry.
See https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/3514
which added support on the wlroots side.
We now re-run popup positioning (for both xdg-shell and layer-shell
popups) when the "reposition" event is received. This allows popups that
change size (such as qmpanel's applications menu) to be positioned
correctly.
xdg-shell v3 also gives the compositor some additional "hints" for popup
positioning (reactive, parent_size, and parent_configure_serial) which
are available but we don't make use of currently.
This fixes an issue detected by the static analyzer.
Rather than setting up the new popup as usual return
a wayland error to the client and destroy the popup.
...for the following reasons:
1. We interpret 'normal input-focus semantics' for clients with on-demand
keyboard interactivity to means that a surface receives input focus on
cursor-button-press AND on map (the latter previously missing), just
like a normal window would. In this regard, we do not differentiate
between layers.
2. Most layer-surfaces set the keyboard interactivity at a similar time to
their first (and normally only) map, so the absence of an explicit
attempt to focus on map does not make a difference. However, for a
long-running layer-shell client (such as lxqt-runner) which sets the
interactivity on launch and then maps/unmaps many times throughout its
lifetime, a specific focus-attempt is required on map to avoid the
client itself having to keep resetting its interactivity to grab the
keyboard on map.
3. Compositors like sway and river process focus (for clients with
keyboard-interactivity) in their map-handlers, so this makes for a
common approach.
Fixes: #1653
...and on unmap.
Add `try_to_focus_next_layer_or_toplevel()` which does the following
(in order of precedence):
- Give focus to last added overlay/top layer-shell client with exclusive
interactivity on the output nearest the pointer (normally the one where
the users is currently working). The reason for not considering clients
on all outputs is that giving focus to a client on another output may be
confusing to the user.
- Give focus to topmost toplevel if one exists (this was done previously
anyway).
Use the following logic:
- Exclusive: Grant regardless of layer (previously it was only given if
in top or overlay layers) AND grant if in the same or higher layer
(nearer overlay) compared with other clients with exclusive
interactivity.
- On-demand: Grant only if no other layer-shell client has exclusive
keyboard interactivity. Previously it was treated the same as
exclusive.
- None: Unset focus if the commit associated with the 'none' came from
the currently focused layer. Previously it was just unset regardless.
Need to handle new unified mapping, where mapping is attached to the
wlr_surface objects instead of their parents. Also, most of them require
a new associate event for xsurface objects, their surface member will be
NULL before this event is received.
Refactored by jlindgren:
- add struct mappable
- unify map/unmap logic