Commit Graph

224 Commits

Author SHA1 Message Date
Morgane Glidic 0de497f868
libweston/desktop: Update my Copyright
Signed-off-by: Morgane Glidic <sardemff7+git@sardemff7.net>
2024-02-11 19:07:39 +01:00
Derek Foreman e193a178e8 xwm: Fix accidental resizing of windows
If an X window has not been resized yet, and the user clicks (not drags)
on a part of the window frame that can be used to resize, the window
will resize to 512, 512.

This is likely because of the changes in ba82af938 and 2acd2c748
that change resize behaviour but missed updating saved size when the
client's initial configure occurs.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2023-10-25 07:36:17 +00:00
Brendan King 751c1c9496 xwayland: fix segfault when running x11perf
Running "x11perf -reps 1 -repeat 1 -all" will segfault, due to
windows being left on lists after being destroyed.

The fix was devised after running Weston under valgrind whilst
x11perf was running.

Fixes: https://gitlab.freedesktop.org/wayland/weston/-/issues/797

Signed-off-by: Brendan King <Brendan.King@imgtec.com>
2023-08-11 14:18:13 +03:00
Derek Foreman 60a00d8c6c xwayland: Use weston_coord
Smash weston_coord into a whole bunch of xwayland internals.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2023-07-19 07:41:33 -05:00
Alexandros Frantzis ca7b631310 xwayland: Allow shells to make xwayland surfaces fullscreen
The fullscreen state for xwayland surfaces can currently only be
effectively set from the client side. This commit enables
libweston-desktop based shells to properly set the fullscreen state
for xwayland surfaces.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
2023-07-06 21:19:18 +00:00
Daniel Stone eff5e7e0f3 xwayland: Add client destroy listener
Make sure that we consistently mark the client as NULL when it's
destroyed, and destroy it on process exit as well, so we have a
consistent state.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2023-06-19 21:32:47 +01:00
Daniel Stone 506901d918 xwayland: Rename destroy_listener to be more explicit
compositor_destroy_listener tells us exactly what it is.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2023-06-19 21:32:47 +01:00
Daniel Stone 104676ec1f xwayland: Remove process exit status from libweston API
This shouldn't be relevant to the core.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2023-06-19 21:32:47 +01:00
Daniel Stone e64232a808 xwayland: Only pass Xwayland wl_client to libweston
Remove all handling of process/PID internals from libweston's Xwayland
launcher, and keep this only in the frontend. libweston now only sees
the wl_client and nothing else.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2023-06-19 21:32:47 +01:00
Derek Foreman e8208d21d7 libweston: Use weston_coord in struct weston_output
Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2023-06-12 16:55:22 -05:00
Liu, Kai1 b468687dd2 xwm: WM_TRANSIENT_FOR should not point to override-redirect window
The override-redirect window will not be assigned a shell_surface
object. If it is used as a parent window, it will cause a crash
when calling the set_parent function.

The EWMH specification does not describe the behavior of an
override-redirect window as a parent window, so we should ignore
this case.

Signed-off-by: Liu, Kai1 <kai1.liu@intel.com>
2023-06-09 09:10:28 +00:00
Sergio Gómez ed012ee505 libweston: Store view instead of surface, and add flags, to activation data
Since we want to pass the view to the surface activation listener inside the
constraints code, and the surface is reachable from the view anyway.

The flags field will let us pass the reason for activation to the constraints
code, which will then handle especially the fullscreen case.

Signed-off-by: Sergio Gómez <sergio.g.delreal@gmail.com>
2023-05-25 12:07:03 +03:00
Pekka Paalanen eb2a12a92c xwayland: comment on cleanup_after_cairo()
I tried this, and it causes a crash. Leave a note for the future when we
happen to use some other backend with xwayland and find a "leak".

The reason this is a comment and not a Gitlab issue is that you probably
would not go looking for a Gitlab issue saying an idea is a bad one.
This comment is more likely to be found.

It's not really a leak either, it only needs to be fixed if you want a
clean ASan leak report.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2023-04-12 12:34:58 +00:00
Derek Foreman 87881e2cf6 xwm: Add support for xwayland_shell_v1
Use the new protocol to prevent races in surface to window association.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2023-03-03 08:21:24 +00:00
Derek Foreman 8e1d7fe4da xwm: Init window link after removing it
In future code the window link will end up in a state where it may or may
not be on the unpaired_window_list and we'll want to go from that state
to one where it's definitely not on the list.

Initting the list after removal (in these two places) allows us to
unconditionally remove it later.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2023-03-03 08:20:34 +00:00
Michael Tretter 48b39d31ef shared: extract hash table implementation from xwayland
The hash table implementation is useful for other modules as well. Move it from
xwayland to the shared code.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2023-03-03 08:08:46 +00:00
Alexandros Frantzis 2acd2c7489 xwayland: Handle shell hint for client to choose dimensions
A config event with width == 0 or height == 0 from the shell is a hint
to the client to choose its own dimensions. Since X11 clients don't
support such hints we make a best guess by trying to use the last saved
dimensions or, as a fallback, the current dimensions.

This hint is mainly used by libweston/desktop shells when transitioning
to a normal state from maximized, fullscreen or after a resize [1].
Without support for this hint the aforementioned transition causes
xwayland surfaces to be configured to a 1x1 size.

To be able to use the last saved dimensions with xwayland surface, the
shell needs to first set the maximized/fullscreen state and only then
set the new size, which is currently the case for desktop-shell.
Otherwise, if the new size is set first, then the last saved dimensions
will be set to the fullscreen/maximized values and won't be useful when
restoring to a normal window size.

[1] Recently we've introduced ba82af938a
"desktop-shell: do not forget to reset pending config size after
resizes". As we were not handling the 0x0 size hint, resizing X
applications started to fail. This patch fixes that.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
Co-authored-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2023-02-28 19:13:22 +02:00
Derek Foreman 9d24fb96fb xwm: Be careful with window size when minimizing
If we're minimized from maximized or fullscreen state, we want to leave
the saved size alone, so we can restore it if we clear fullscreen or
maximized state later.

Signed-off-by: Hideyuki Nagase <hideyukn@microsoft.com>
2023-02-03 11:02:51 +02:00
Philipp Zabel f639c9cac4 build: fix meson deprecation warnings
Stop using features that Meson 0.63.0 throws deprecation warnings about:

  WARNING: Deprecated features used:
   * 0.56.0: {'dependency.get_pkgconfig_variable'}
   * 0.62.0: {'pkgconfig.generate variable for builtin directories'}

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
2023-01-31 09:43:41 +02:00
Derek Foreman e7251a759b xwm: Preserve unmaximized window size at map time
This fixes a problem that can be seen with Firefox running under xwayland.
- Start it (or another client that remembers its size and maximized state),
- resize it
- maximize it
- exit it
- restart it
- unmaximize it

The size will be changed to a default size and not the previous unmaximized
size.

To fix this, save the unmaximized height and width like we do for the
fullscreen case.

Co-authored-by: Steve Pronovost <spronovo@microsoft.com>
Co-authored-by: Brenton DeGeer <brdegeer@microsoft.com>
Signed-off-by: Hideyuki Nagase <hideyukn@microsoft.com>
Signed-off-by: Steve Pronovost <spronovo@microsoft.com>
Signed-off-by: Brenton DeGeer <brdegeer@microsoft.com>
Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2023-01-09 22:16:29 +00:00
Derek Foreman 1d36f7655d xwm: Assert if we try to fetch our own selection
Now that we don't accidentally delay our selection ownership changes,
let's assert() if we somehow find ourselves downloading our own selection,
as the assertion is simpler to understand than the mess that ensues if
we hit this.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-12-07 10:03:37 +02:00
Derek Foreman 11bcad116f xwm: Propagate selection ownership immediately
If we don't xcb_flush() when we set the selection owner, we end up with
a ridiculous corner case where we can run use a command line X client
like 'xclip -i -selection clipboard' to crash weston.

Start weston, ensure Xwayland is running (set a selection with xclip), set
the clipboard from a wayland client, then set the clipboard with xclip
again.

Since xclip doesn't do anything xwm notices except set the clipboard, it
won't provoke a flush on our selection ownership change. xclip will take
ownership, then we call xcb_convert_selection(), and THEN we flush, sending
out our pending ownership change and the xcb_convert_selection() request.

The ownership change takes place first, we attempt to get our own selection
and weston explodes in a mess.

Stop this from happening with a flush when changing selection ownership.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-12-07 10:03:37 +02:00
Derek Foreman bb993df236 xwm: Don't crash when setting selection with no seat
It's possible to set the clipboard with no seat present - one way is to
use the RDP backend and then run 'xclip -i -selection clipboard' locally
without making an RDP connection.

Check if seat is NULL to prevent this from crashing.

Fixes #698

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-12-07 10:03:37 +02:00
Derek Foreman a04fd99212 xwm: Fix selection if no seat present at startup
It's possible that there are no seats present at startup (especially with
the RDP backend, which creates and removes seats for connections), and
previously we'd just fail to set up XWayland cut and paste properly.

We should set up a listener and find a seat when one becomes available -
but we also need to switch seats if ours is removed.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
Co-authored-by: Hideyuki Nagase <hideyukn@microsoft.com>
2022-12-07 10:03:37 +02:00
Marius Vlad cfe35b591f shared/cairo-util: Re-use the PangoContext for layout creation
Rather than creating a new PangoContext each time the menu redraw
handler is triggered re-use it if one was created previously.

All toytoolkit clients do create a layout (and implicitly a
PangoContext) but only those that have menu redraw
handler installed will create a new layout for each redraw of the menu,
effectively creating a new PangoContext each time.

Reported-by: Pekka Paalanen <pekka.paalanen@collabora.com>
Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2022-11-10 11:07:12 +02:00
Derek Foreman 1cb46994e3 xwm: Check size hints in weston_wm_window_is_positioned()
Currently we can't tell the difference between a window intentionally
created at 0,0 and a window that we can place anywhere.

Check the size hints to see if the flags indicating the placement
is intentional are present.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-09-23 11:25:10 +00:00
Derek Foreman dac2f146ea xwm: Perform a roundtrip to send a deferred WM_TAKE_FOCUS
WM_TAKE_FOCUS requires a valid timestamp that isn't XCB_TIME_CURRENT. To
get one, we set a property on the window and wait for the notification
that it was set - this notification comes with a valid timestamp.

Once we have that timestamp, delete the property, and fire off the slightly
delayed WM_TAKE_FOCUS client request.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-08-08 12:43:34 +00:00
Derek Foreman ae4209978c xwayland: Don't focus an already focused xwayland window
We've been doing this when clicking on windows, even if they're
already activated. This leads to sending extra WM_TAKE_FOCUS events
as well as re-rendering the decor every mouse click.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-08-08 12:43:34 +00:00
Hideyuki Nagase 5afe6c5b39 xwm: Change event mask for WM_TAKE_FOCUS
This should be XCB_EVENT_MASK_NO_EVENT, but was not.

Co-authored-by: Steve Pronovost <spronovo@microsoft.com>
Co-authored-by: Brenton DeGeer <brdegeer@microsoft.com>
Signed-off-by: Hideyuki Nagase <hideyukn@microsoft.com>
Signed-off-by: Steve Pronovost <spronovo@microsoft.com>
Signed-off-by: Brenton DeGeer <brdegeer@microsoft.com>
2022-08-08 12:43:34 +00:00
Hideyuki Nagase 55b2bf9393 xwayland: Respect client WM_TAKE_FOCUS setting
According to https://tronche.com/gui/x/icccm/sec-4.html#s-4.1.7 we should
send this focus notification only if a client has WM_TAKE_FOCUS set in
their WM_PROTOCOLS property. We've been sending it unconditionally.

Rather, we've been not-sending it unconditionally because the event mask
is wrong, but that will be fixed in a future commit. Fixing the event
mask first would break some clients (such as xterm).

Co-authored-by: Steve Pronovost <spronovo@microsoft.com>
Co-authored-by: Brenton DeGeer <brdegeer@microsoft.com>
Signed-off-by: Hideyuki Nagase <hideyukn@microsoft.com>
Signed-off-by: Steve Pronovost <spronovo@microsoft.com>
Signed-off-by: Brenton DeGeer <brdegeer@microsoft.com>
2022-08-08 12:43:34 +00:00
Derek Foreman 0aac3dd343 xwm: Don't send synthetic ConfigureNotify to windows that were mapped O-R
It's entirely possible, if ridiculous, for an X11 client to change a
window's override redirect flag while it's mapped. If this changes from
true to false we will start receiving Configure requests for the window.

That leads us to a crash when we try to query the window's current
position from the shell to send a configure notify event, as the shell
doesn't know about the surface.

Instead of trying to cleverly handle this, mostly go back to the behaviour
these clients would've seen before commit cf5aca5a and don't send them
a synthetic configure notify.

We also specifically check in weston_wm_handle_configure_request for
the same condition, and early return there, bypassing a couple of
other things we would've done previously.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-08-02 12:22:50 +00:00
Derek Foreman d6b112c857 xwayland: Only prevent focus change to inactive toplevels
Commit b18f788e2e76 broke motif applications by ensuring they could never
focus their menus - since then any attempt by an application to focus any
window would be met by the window manager immediately refocusing the
currently active toplevel window.

Later we loosened the restriction in 9e07d25a1b to allow clients that
received focus from a grab to do so - but motif applications like nedit
don't set focus in this way, and remain broken.

This patch further loosens our restrictions, now only reverting a focus
change to an inactive top level. This will hopefully prevent any
confusing input routing without breaking reasonable clients.

This restores functionality to motif menus.

Fixes #636
Fixes b18f788e2e

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-07-28 20:49:56 +00:00
Daniel Stone 5b11f4066a xwayland: Allow for old WM_NORMAL_HINTS
There are two versions of WM_NORMAL_HINTS: the original pre-ICCCM
version (standardised by Xlib itself?) provides 15 elements of 32 bits
each, with the ICCCM v1 extending this by 3 additional elements.

Since the flags are enough to identify which elements are present, and
the structure is append-only, we only need to read the minimum length
between what the user provided and what we support.

Fixes a heap overrun found with ASan.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-07-05 13:25:37 +01:00
Derek Foreman cf5aca5a0d xwm: Generate more synthetic ConfigureNotify events
Many programs use this information to help position pop-ups properly, and
without it funny things happen. For example, nedit and tkinter apps will
position their menus incorrectly either all the time or after an initial
window move, firefox may position right-click pop-ups incorrectly
depending on other internal state.

https://tronche.com/gui/x/icccm/sec-4.html#s-4.1.5 has much detail on
how this should work, and the Advice to Implementors section shows that
common client practices will break in the face of our miserly handling
of ConfigureNotify events.

Instead of trying to send it only for configure requests received when a
client is in a fullscreen state, send them much more frequently.

Fixes #619

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-06-29 11:44:48 +00:00
Derek Foreman ea9a01f2e3 xwm: Prepare send_configurenotify for non-fullscreen use
Currently weston_wm_window_send_configurenotify is only called for
fullscreen clients, and it is written to be correct only in that case.

Fix it up to handle other cases properly so we can use it for them in a
later commit. Synthetic Configure Notify events are relative to the
root window, so this means adding our window co-ordinate when
necessary.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-06-29 11:44:48 +00:00
Derek Foreman 23e3a3285a libweston-desktop: Add get_position
Plumb the new weston_desktop_api_get_position() through to xwayland.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-06-29 11:44:48 +00:00
Derek Foreman af51618708 xwayland/window-manager: Add support for _NET_FRAME_EXTENTS
https://specifications.freedesktop.org/wm-spec/1.4/ar01s05.html says
"The Window Manager MUST set _NET_FRAME_EXTENTS to the extents of the
window's frame", so this is probably something we should be doing.

Some programs (such as some versions of Firefox) expect this to be present,
and will render popups in wrong locations if it's not.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-06-22 12:05:23 -05:00
Hideyuki Nagase d902088bfc xwayland: support minimizing
Allow minimizing xwayland windows.

Co-authored-by: Steve Pronovost <spronovo@microsoft.com>
Co-authored-by: Brenton DeGeer <brdegeer@microsoft.com>
Signed-off-by: Hideyuki Nagase <hideyukn@microsoft.com>
Signed-off-by: Steve Pronovost <spronovo@microsoft.com>
Signed-off-by: Brenton DeGeer <brdegeer@microsoft.com>
2022-06-22 09:57:25 -05:00
Marius Vlad 49d6532254 shared/xcb-xwayland: Split into common helpers
Avoid duplication of atom retrieval. This is particuarly useful
if one would one to reuse atom retrival in other parts, like tests.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Suggested-by: Daniel Stone <daniel.stone@collabora.com>
2022-06-22 08:08:41 +00:00
Derek Foreman 107d69f10c xwayland: Stop drawing shadows on maximized windows
This is especially weird on multi-head setups, but we shouldn't be doing
it in any cases.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-06-20 16:57:48 +00:00
Derek Foreman 8763f3800e xwayland: Update net_wm state when we change it.
According to the wm-spec we must keep the _NET_WM_STATE property updated
to reflect the current state of the window.

This has been biting me when firefox starts maximized, then I click the
maximize button to toggle to unmaximized state. The next time I mouse over
the maximize button (which causes the frame to be re-rendered with the
maximized button in a highlighted state) we re-read the window state and
weston then believes the window is maximized even though it is being
rendered in a not-maximized state.

Update the state when we change maximized status so this doesn't happen.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-06-20 16:57:48 +00:00
Derek Foreman 40e76fe19d xwayland: Set non zero default saved window size
If a client starts off maximized, clicking the unmaximize button would
result in a 0x0 window - basically a blob of decor with no content.

Instead, use 512x512 as a totally random default value.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-06-20 16:57:48 +00:00
Derek Foreman aa507417c2 xwm: Fix pasting in some cases
I guess this reverts commit 73bdc0ce85
"xwm: Fix fd leak in weston_wm_send_data()"

That commit closes the send half of a pipe in weston_wm_send_data,
claiming that it's dup()licated later, and we'll leak the fd if
we don't close it.

That may have been true at the time? But currently that fd is only
duplicated by wl_event_loop_add_fd() in its normal operation, and
closing our original before that fd handler ever fires results
in an EBADF on write, and the data never reaching its intended
destination.

Worse, by the time that handler is called there might be another
use for that fd, and we could push data into it and close it.

To provoke the problem, launch an app like FireFox over Xwayland,
cut something to the clipboard, then close the app (this is the
path where the wm has stored the clipboard contents and the
app has gone away). relaunch it and paste the clipboard content
back in. clipboard_client_data() will EBADF on write, and the
data won't be pasted.

Reported-by: Hideyuki Nagase <hideyukn@microsoft.com>
Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-05-31 17:57:03 +00:00
Hideyuki Nagase 8aa1c30bf1 xwayland: Honour the XCURSOR_THEME environment variable
Toy toolkit apps already do this since commit 807cd2e589

Co-authored-by: Steve Pronovost <spronovo@microsoft.com>
Co-authored-by: Brenton DeGeer <brdegeer@microsoft.com>
Signed-off-by: Hideyuki Nagase <hideyukn@microsoft.com>
Signed-off-by: Steve Pronovost <spronovo@microsoft.com>
Signed-off-by: Brenton DeGeer <brdegeer@microsoft.com>
2022-04-20 08:23:19 +00:00
shierote f2d6d21eec libweston: correct argument name in the handler of wl_data_source.accept
Signed-off-by: Taishi Eguchi <taishi2060@gmail.com>
2022-04-14 12:05:57 +00:00
Derek Foreman c826d8fa0d xwayland: Fix user after free on shutdown
We need to remove our listener link before we free the structure
it's inside, or the signal list walk will try to dereference it.

Remove the improbable NULL check at the same time.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-01-21 11:42:03 +00:00
Derek Foreman c00aba6893 xwayland: Fix copy and paste error
This leg of the if/else ladder is a duplicate of the previous conditional.

It appears to have been intended to log enter events, but we already
handle those earlier. The drop event is already logged as well,
so let's just discard this branch entirely.

Fixes #552

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2021-10-25 17:24:41 -05:00
Emmanuel Gil Peyrot eff793ab46 Fix indentation all through the project
Fixes a “regression” from 04918f3b0b, but
also other missed pieces.
2021-07-31 15:28:20 +00:00
John Good f33ddd0839 Allow programmatically closing xwayland window 2021-07-23 19:40:00 +00:00
Marius Vlad cdeeb881a0 xwayland/window-manager: Handle weston_wm_window's name/class destruction
Memleak found by ASAN:

Direct leak of 21 byte(s) in 1 object(s) allocated from:
    #0 0x7fe7a917fe8f in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.6+0xa9e8f)
    #1 0x7fe7a9129874  (/usr/lib/x86_64-linux-gnu/libasan.so.6+0x53874)
    #2 0x7fe7a5a23469 in weston_wm_window_read_properties ../xwayland/window-manager.c:574
    #3 0x7fe7a5a28d3b in weston_wm_handle_map_request ../xwayland/window-manager.c:1178
    #4 0x7fe7a5a31660 in weston_wm_handle_event ../xwayland/window-manager.c:2291
    #5 0x7fe7a8c261a1 in wl_event_loop_dispatch ../src/event-loop.c:1027

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2021-06-01 13:55:33 +03:00