Commit graph

509 commits

Author SHA1 Message Date
David Turner
879243e370 xwm: Fix double-close
When an FD is passed to xcb_connect_to_fd(), xcb takes ownership of that
FD and is responsible for closing it, which it does when
xcb_disconnect() is called.  But the xwayland handler code also keeps a
copy of the FD and closes it via safe_close() in
server_finish_process().

This double-close can cause all sorts of problems if another part of
wlroots allocates another FD between the two closes - the latter close
will close the wrong FD and things go horribly wrong (in my case leading
to use-after-free and segfaults).

Fix this by setting wm_fd[0]=-1 after calling xwm_create(), and ensuring
that xwm_create() closes the FD if startup errors occur.
2025-10-20 14:02:29 +01:00
JiDe Zhang
d7ae9a866b xwayland: fix assertion failure in wlr_xwayland_shell_v1
The issue occurred when `wlr_xwayland_shell_v1` was destroyed before
`wlr_xwayland`. This happened because `wlr_xwayland` didn't remove the
listener for the shell's destroy event in `handle_shell_destroy`.
2025-09-16 13:59:06 +08:00
tokyo4j
6d8bb66f98 xwm: add support for _NET_WM_ICON 2025-06-26 08:50:02 +00:00
Simon Ser
221b37355f xwayland: require xcb-xfixes 1.15
xcb-xfixes 1.15 was released back in 2022. Let's simplify our build
setup by requiring it.
2025-06-16 07:40:04 +00:00
Rémi Bernon
6c78225160 xwayland: Activate no_focus_window when a Wayland window is activated
None active window might be interpreted from an X point of view as a
transient focus state, and is used by multiple X window managers when
a temporary focus change is in progress, or simply when grabbing the
keyboard.

From Wine side, we translate any active window change to the Win32
application, and handling None active window as an actual window
deactivation and focus loss creates spurious events and an undesired
feedback loop, as apps might react to it.

We still want to be able to detect actual focus loss under an XWayland
session, and having XWayland window manager focus an actual X window
instead will make the distinction possible.
2025-06-12 08:56:09 +00:00
Rémi Bernon
83a5bdf5d5 xwayland: Create a dummy no_focus_window to use for non-X window focus 2025-06-12 08:56:09 +00:00
David Turner
fae4c5097d xwayland: Remove has_utf8_title field 2025-05-22 15:10:26 +00:00
Simon Ser
af34aaad53 xwayland: handle unset _NET_WM_NAME
The spec says [1]:

> If set, the Window Manager should use this in preference to WM_NAME.

However we overwrite WM_NAME with NULL when _NET_WM_NAME is unset.
Fix this by storing both WM_NAME and _NET_WM_NAME, so that we
handle properly all combinations of events (e.g. a client setting
both and later clearing one).

[1]: https://specifications.freedesktop.org/wm-spec/1.3/ar01s05.html#id-1.6.2
2025-05-15 10:23:01 +02:00
Simon Ser
78aaaaf7b6 Revert "xwayland: Reset signal mask and handlers before exec"
This reverts commit 954dba3968.

Motivations:

- This only resets some state, but other global state such as other
  signal handlers, process limits (e.g. NOFILE) or system-specific
  settings are left as-is. The chunk of state which does get reset
  is opinionated.
- Compositors have other ways to do this, e.g. with pthread_atfork()
  or with empty signal handler callbacks.
2025-04-20 21:12:33 +02:00
Kirill Primak
5fd43add1c Fix/cleanup includes a bit 2025-04-15 20:13:29 +03:00
xurui
db2c907f93 xwayland/selection/dnd: always send finished event
Signed-off-by: xurui <xurui@kylinos.cn>
2025-03-23 15:17:10 +01:00
Kenny Levinsen
954dba3968 xwayland: Reset signal mask and handlers before exec
Certain signal-related properties, such as the signal mask and handlers
that are set to ignore, are not reset by exec and therefore affect the
new process image.

In case of Xwayland, a compositor setting SIGCHLD to SIG_IGN causes
keyboard compilation to fail as it expects waitpid to work by default.

Reset the signal mask and the two signals that sway is known to set.
2025-03-13 01:37:20 +01:00
Simon Ser
08c74f36a9 xwayland/xwm: log when property type is invalid 2025-03-06 15:22:49 +01:00
Simon Ser
5175b6e94e xwayland/xwm: handle deleted properties
X11 clients might delete window properties. In that case, reset
our state to the initial value.
2025-03-06 15:21:13 +01:00
Guido Günther
e752e3ec06 xwm: Handle NET_WM_WINDOW_OPACITY
Lot of clients use it (e.g. both Qt and GTK) although it never made it
into the spec at

  https://specifications.freedesktop.org/wm-spec/latest-single/

until recently

  https://gitlab.freedesktop.org/xdg/xdg-specs/-/merge_requests/97

Signed-off-by: Guido Günther <agx@sigxcpu.org>
2025-03-06 14:18:20 +00:00
Kirill Primak
8f56f7ca43 Assert (almost all) signals have no attached listeners on destroy 2025-01-15 19:53:11 +03:00
Kirill Primak
38923826c3 xwayland,render/vulkan: fix some size assertions 2024-12-30 12:47:54 +03:00
Consolatis
41e2331843 xwm: add missing NET_WM_STATE states
https://specifications.freedesktop.org/wm-spec/latest/ar01s05.html#id-1.6.8
2024-12-20 21:47:17 +00:00
Consolatis
546c5d000d xwayland: fix xdg->xwayland drag-and-drop
As struct wlr_drag is destroyed on drop and in the process resets
the focus, a xwayland dnd listener would also reset xwm->drag_focus.

This prevents the xcb replies from being processed and also prevents
the transfer if a compositor would not additionally request new focus
in its wlr_drag destroy handler (which is something usually only done
when in a focus-follows-mouse setting).

This patch creates a new xwm->drop_focus pointer which is a copy of
xwm->drag_focus at drop time. The xcb reply handler and transfer
logic now use the new xwm->drop_focus for their authorization checks.
2024-12-11 08:51:10 +01:00
Simon Ser
a7ebe7c026 xwayland: remove loop to find drag focus surface
We can just use wlr_xwayland_surface_try_from_wlr_surface() here
instead.
2024-12-07 14:49:26 +01:00
Simon Ser
c7acfe906b xwayland: listen to drag focus destroy signal
The wlr_drag takes care of resetting the focused wlr_surface when
it's destroyed, however we store the wlr_xwayland_surface, which
may be destroyed before.
2024-12-07 14:49:26 +01:00
Tycho Andersen
631e5be0d7 xwayland: don't fail on SIGCHLD
SIGCHLD here isn't fatal: we have other means of notifying that things were
successful or failure, and it causes many compositors to have to do a bunch
of extra work:

https://github.com/qtile/qtile/issues/5101
https://github.com/flacjacket/pywlroots/pull/207#issuecomment-2502680133
https://github.com/djpohly/dwl/pull/212

Signed-off-by: Tycho Andersen <tycho@tycho.pizza>
2024-12-06 14:09:28 +00:00
Consolatis
be3d2b74cf dnd: ensure internal dnd handlers are unlinked on xwm_destroy()
Fixes #3925
2024-11-29 13:42:55 +00:00
Kirill Primak
c0d4d7217b Add missing destroy events on automatically destroyed objects 2024-11-26 17:49:22 +00:00
Simon Ser
6ada67da9b xwayland/xwm: implement somewhat asynchronous request flushing
Instead of calling xcb_flush() directly, wait until the FD is
writable.

Ideally we'd have a non-blocking variant instead of xcb_flush(),
but libxcb doesn't have this. Also libxcb blocks when its internal
buffer is full, but not much we can do here.
2024-10-07 21:51:15 +03:00
Simon Ser
c9fe96102d xwayland/xwm: extract read loop to separate function 2024-10-07 21:47:00 +03:00
zhoulei
2c64f36e88 xwayland/xwm: listen shell destroy signal
Otherwise we got invaild write in wl_list_remove.

Fixes: e209fe2d0 ("Fix memory leak in xwayland.c")

Signed-off-by: zhoulei <zhoulei@kylinos.cn>
2024-08-13 11:33:04 +08:00
project-repo
e209fe2d05 Fix memory leak in xwayland.c 2024-08-12 14:06:10 +00:00
John Lindgren
6214144735 xwayland: add wlr_xwayland_surface_has_window_type()
The infrastructure to read _NET_WM_WINDOW_TYPE already exists in wlroots
(it's used for example in wlr_xwayland_or_surface_wants_focus()). But
the window type isn't easily accessible to the compositor because the
atoms to compare against are private to xwm.c.

labwc has recently gone to a fair amount of effort (including opening a
whole new xcb connection) just to get the needed window type atoms:
a04b394e59

It seems much cleaner to add the remaining few (3) atoms to wlroots and
implement a shared function which can be used by any wlroots compositor.

v2: naming updates
2024-08-10 16:10:34 +00:00
Consolatis
0a388a14f1 xwm: supply wlr_xwayland pointer to user_event_handler callback
Previously it was supplying a pointer to private struct wlr_xwm
which was useless for compositors. The wlr_xwayland pointer in
contrast does have a generic data field and thus can be used by
compositors to attach their own pointer.

Additionally change the return value from int to bool.
2024-08-08 17:00:08 +00:00
Consolatis
20997df416 xwm: add request_close signal
This is especially useful if the compositor wants to support X11
panels to control windows. Without the signal a compositor does
have to hook into the user_event_handler callback but that would
not change the _NET_SUPPORTED root window property.
2024-08-08 15:49:11 +00:00
Kirill Primak
7e13dfdd4d xwayland: remove stray empty line 2024-08-02 17:52:19 +03:00
Consolatis
ceb4fcedca xwm: expose individual axis for _set_maximized()
This allows compositors to support both axis individually.
To keep existing behavior, compositors can supply the same
maximized state for both axis.
2024-08-02 14:46:37 +00:00
John Lindgren
f9199bb6d4 xwayland: set focus to XCB_POINTER_ROOT rather than XCB_NONE
Fixes an issue with keyboard grabs not working when no XWayland windows
are focused.
2024-08-01 13:19:24 +00:00
John Lindgren
5083efe18b xwayland: add wlr_xwayland_surface_offer_focus()
In labwc, we have had trouble with XWayland windows using the Globally
Active input model (see wlr_xwayland_icccm_input_model()). Under
traditional X11, these windows do not expect to be given focus directly
by the window manager; rather, the WM sends them a WM_TAKE_FOCUS message
prompting the client to take focus voluntarily.

Currently, these clients are difficult to support with wlroots, because
wlr_xwayland_surface_activate() assumes the client window will always
accept the keyboard focus after being sent WM_TAKE_FOCUS. Some Globally
Active client windows (e.g. panels/toolbars) don't want to be focused.
It's useless at best to focus them, and might even make them misbehave.
Others do need keyboard focus to be functional -- and there doesn't seem
to be any reliable way to know this in advance.

Adding wlr_xwayland_surface_offer_focus() allows the compositor to send
WM_TAKE_FOCUS to a client window supporting it and then see whether the
client accepts or ignores the offer. If it accepts, the surface will emit
the focus_in signal notifying the compositor that it has received focus.

This is entirely opt-in. A compositor that doesn't want to use the new
function can continue to call wlr_xwayland_surface_activate() directly
just as before.
2024-08-01 13:19:24 +00:00
John Lindgren
eb5312022a xwayland: add focus_in and grab_focus events
Allows the compositor to know when the XWayland focus changes.
2024-08-01 13:19:24 +00:00
John Lindgren
aa1163e640 xwayland: factor out xwm_set_focused_window()
Currently _NET_WM_STATE is updated in xwm_focus_window() but
_NET_ACTIVE_WINDOW is updated in xwm_surface_activate(). In some cases
(for example, client-initiated focus changes) the two properties can get
out of sync.

Factor out a new function which updates both properties in sync.

Adjust the logic in xwm_handle_focus_in() to call either
xwm_focus_window() or xwm_set_focused_window(), or neither, as
appropriate.
2024-08-01 13:19:24 +00:00
Isaac Freund
d3b7e040af wlr_xwayland_surface: fix prefix of two functions
Since we're breaking this API anyways, replace the ambiguous "or" in the
function name with the explicit "override redirect" to avoid confusion.
2024-07-13 19:56:58 +00:00
Consolatis
8abd43803b xwayland: remove saved_{width,height}
This has been introduced way back in
be297d9d14 but is never used anywhere.

If compositors want to save the old dimensions before reacting to a
fullscreen or maximize event they can just grab the sizes within their
event handlers instead.
2024-04-30 15:24:40 +00:00
Ilia Bozhinov
c63275d75e xwayland: add a size-safe wrapper for xcb_send_event
xcb_send_event expects the caller to always provide 32 byte data, even if the actual event struct is
smaller than that.

Reference: https://gitlab.freedesktop.org/xorg/lib/libxcb/-/issues/18
2024-04-20 15:12:45 +02:00
Vaxry
50eae512d9 xwayland: add wlr_xwayland_get_xwm_connection
Allows the compositors to get the xwm connection
2024-03-09 11:21:17 +00:00
John Lindgren
2521fba37c xwayland: add map_request signal
For XWayland surfaces that start maximized, it's best to send an initial
Configure event to set the size of the surface before mapping it. This
reduces visual glitches since the application sees the correct maximized
size when performing its initial layout and drawing.

wlroots surfaces emit their first "map" event after the XWayland window
has already been mapped and the first frame has been drawn & committed.
This is too late to send the initial Configure event.

So, add a new "map_request" event which is emitted immediately before
telling XWayland to map the window. Compositors can connect to this
event to send the initial Configure event to an XWayland app based on
its requested maximized (or fullscreen) state.

Compositors should not place anything visually on the screen at this
point but rather wait until the "map" event as before.
2024-02-23 12:46:25 -05:00
Kenny Levinsen
51c1e4aed1 xwayland/xwm: Initialize client_id_cookie
scan-build is a little confused, thinking xwm->xres value could change
during the execution of xwayland_surface_create so client_id_cookie
could end up used uninitialized.

The struct is just an unsigned int, so no harm in initializing it to get
it off the list.
2024-02-22 23:13:36 +01:00
Kenny Levinsen
484a87ce61 xwayland/xwm: Allocate to the right variable
837060f894 made a change to only allocate the xcb_window_t array if it
was not going to be zero-sized. It accidentally shadowed the variable so
the output of the allocation would never be used.

Regressed-by: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4563
2024-02-22 17:46:05 +01:00
Kenny Levinsen
837060f894 xwayland/xwm: Avoid zero-size allocaiton
Zero-sized allocations have glibc-specific behavior, so avoid those.
2024-02-22 14:10:46 +01:00
Simon Ser
842093bb84 Define _POSIX_C_SOURCE globally
Stop trying to maintain a per-file _POSIX_C_SOURCE. Instead,
require POSIX.1-2008 globally. A lot of core source files depend
on that already.

Some care must be taken on a few select files where we need a bit
more than POSIX. Some files need XSI extensions (_XOPEN_SOURCE) and
some files need BSD extensions (_DEFAULT_SOURCE). In both cases,
these feature test macros imply _POSIX_C_SOURCE. Make sure to not
define both these macros and _POSIX_C_SOURCE explicitly to avoid
POSIX requirement conflicts (e.g. _POSIX_C_SOURCE says POSIX.1-2001
but _XOPEN_SOURCE says POSIX.1-2008).

Additionally, there is one special case in render/vulkan/vulkan.c.
That file needs major()/minor(), and these are system-specific.
On FreeBSD, _POSIX_C_SOURCE hides system-specific symbols so we need
to make sure it's not defined for this file. On Linux, we can
explicitly include <sys/sysmacros.h> and ensure that apart from
symbols defined there the file only uses POSIX toys.
2024-02-15 15:41:12 +01:00
Grigory Kirillov
0867dd4e6b xwayland: add support for _NET_WM_WINDOW_TYPE_DESKTOP atom 2024-01-25 19:27:37 +03:00
Sarunas Valaskevicius
7c080c3b60 Fix disappearing menus in QT apps
A motivating example of such problem - Zoom's popups that open on button presses.

Before this fix the popup would flicker and immediately disappear - because the PID is not yet
available for the verification (as the surface has not been associated yet), wlroots would refuse to
focus the popup and instead focus the previous window. This leads QT to interpret this as a sign to
close the popup.

This change moves the PID aqcuisition to an earlier phase - just where the window is created.
2024-01-25 11:45:05 +03:00
Kirill Primak
f91fc445ff xwayland/xwm: associate even on xcb_get_property() failure
This matches the behavior before f5797be8a8.
2024-01-24 12:42:18 +03:00
Kirill Primak
d18670b922 xwayland: close pipe fds on set_cloexec() error 2024-01-17 15:44:37 +00:00