Commit Graph

11661 Commits

Author SHA1 Message Date
Sergey Bugaev
d0864b141f Plug GTask leaks
The error-prone pattern seems to be:

  GTask *task = g_task_new (...);

  if (condition)
    {
      g_task_return_... (task, ...);
      /* need g_object_unref (task) here! */
      return;
    }

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
2024-08-07 20:39:40 +03:00
Jonas Ådahl
069b37cde9 gdk/surface: Don't leak the EGLSurface
Each time we create a new window, we create a new EGLSurface. Each time
we destroy a window, we failed to destroy the EGLSurface, due to passing
a GdkDisplay instead of a EGLDisplay to eglDestroySurface().

This effectively leaked not only the EGL surface metadata, but also the
associated DMA buffers. For applications where one opens and closes many
windows over the lifetime of the application, and where the application
runs for a long time; for example a terminal emulator server, this
causes a significant memory leak, as the memory will only ever be freed
once once the application process itself exits, if ever.

Fix this passing an actual EGLDisplay instead of an GdkDisplay, to
eglDestroySurface().
2024-08-07 15:07:16 +03:00
Arjan Molenaar
bf8b0ac8d4 macos: fix window transparency
Revert window decoration changes from
a6ce506714.
2024-08-05 17:16:23 +03:00
Matthias Clasen
71307b1b29 dmabuf: Fix the disjointness check
We were checking the wrong fds here.

This came up while toying with udmabuf and creating multi-plane
NV12 buffers.
2024-08-05 17:15:47 +03:00
Matthias Clasen
325cb8071f subsurface: Avoid a crash
When finalizing a subsurface, we need to make sure it is removed
from the sibling lists in its parent, or bad things will happen.

This should crashes seen in Epiphany nightly.

Fixes: #6891
2024-08-05 17:13:07 +03:00
Simon McVittie
eaa265c924 Avoid calling memcpy with n == 0
Some callers of these functions ask to copy 0 items from a NULL source,
which would be valid if they were copied in a loop (because NULL would
never be dereferenced), but is declared to be undefined behaviour for
Standard C memcpy. Guard the call to memcpy so that we only call it
if we have more than 0 items, and therefore should have a non-NULL
source pointer.

Detected by running a subset of the test suite with
-Dsanitize=address,undefined on x86_64.

Signed-off-by: Simon McVittie <smcv@debian.org>
2024-08-05 17:08:52 +03:00
Simon McVittie
30df7d6082 gdk: Codify the requirement that gsize is pointer-sized
This is widely assumed, but is not guaranteed by Standard C, and is
known to be false on CHERI architectures (which have 64-bit sizes and
128-bit tagged pointers). Add a static assertion to ensure that GTK
will not build on platforms where this assumption does not hold.

As discussed on GNOME/gtk!7510, if GTK switches from gsize to uintptr_t
as its representation of the underlying bits in a pointer, GTK maintainers
would prefer that to be done project-wide so that it's done consistently,
after which this static assertion could be removed.

At the time of writing, GLib makes the same assumption (GNOME/glib#2842),
but GLib contributors are gradually removing it (mostly by replacing gsize
with uintptr_t where a pointer-sized quantity is needed). Finishing
that work in GLib would be a prerequisite for being able to make GTK
work on the affected platforms.

Signed-off-by: Simon McVittie <smcv@debian.org>
2024-08-05 17:06:10 +03:00
Marco Trevisan (Treviño)
0784067c0b gdkdmabufformats: Add autoptr definition 2024-07-25 13:20:19 +03:00
Jie Liu
63d38c0cc2 Ignore grabbing tablet devices without pads or tools
Signed-off-by: Jie Liu <liujie01@kylinos.cn>
2024-07-25 13:20:19 +03:00
Fabio Lagalla
ca36537f14 gdk: Implement fullscreen on selected monitor on macos
The feature was apparently missing, as monitors were always fullscreened at the surface best monitor.

Keep using best monitor if the selected monitor is not specified, otherwise move the window to the selected monitor before going fullscreen.
2024-07-25 13:20:19 +03:00
Matthias Clasen
605b11cdb6 wayland: Add missing listeners
Now that we are using version 6 of the compositor interface,
we need to have preferred scale and bufer transform callbacks
everywhere.
2024-07-25 13:20:19 +03:00
g.willems
6a6da0ba81 win32: Guarantee dnd-move as a cursor name
gdk currently falls back to the default cursor, which may not be
approriate for rendering a DnD move.
2024-07-25 13:10:30 +03:00
Benjamin Otte
c459af78ff vulkan: Add a missing extension
We need to enable this one, too.

Thanks validation layers!
2024-07-25 13:10:29 +03:00
Dr. David Alan Gilbert
3a9bd9bd8a gdk: Remove unused struct 'XPointerUngrabInfo'
'XPointerUngrabInfo' appears unused since
commit 26cbf87d7d ("New approach for grab tracking code")
Remove it.

Signed-off-by: Dr. David Alan Gilbert <dave@treblig.org>
2024-07-25 13:10:29 +03:00
Benjamin Otte
eee0b1ecdd dmabuf: Ref previous context
In case the context's only reference was held by being the current
context, setting the new context would free it.

Resetting it later would then be a use-after-free.

Fixes #6694
2024-07-24 14:58:50 +03:00
Doğukan Korkmaztürk
7a3c6b77ef vulkan: Recreate swapchain when it is necessary or beneficial
Currently, GTK does not check the result of vkAcquireNextImageKHR() and
assumes that it always succeeds. As a result, the vkQueuePresentKHR() is
unconditionally set to wait for the semaphore passed to
vkAcquireNextImageKHR() earlier.

However, if vkAcquireNextImageKHR() fails for some reason, the semaphore
passed to it does not get signalled. This causes the presentation
command to wait for the semaphore to be signalled indefinitely, which
causes GTK to hang.

This change adds error handling around vkAcquireNextImageKHR() to make
GTK recreate the Vulkan swapchain when it is necessary or beneficial and
helps avoiding situations that could cause indefinite waits.
2024-07-24 14:58:27 +03:00
Georges Basile Stavracas Neto
11381d8e64 win32/vulkancontext: Remove unused variable
Silences a compiler warning.
2024-07-24 14:54:54 +03:00
Georges Basile Stavracas Neto
f1d4cf9760 win32/wgl: Initialize hwnd to NULL
Otherwise there's a valid code path that may return it uninitialized.
2024-07-24 14:54:43 +03:00
Georges Basile Stavracas Neto
e9a35fe3f5 win32/cursor: Ignore GdkPixbuf deprecation warning
Seems harmless to ignore this for now, other bits of code also ignore
this.
2024-07-24 14:54:18 +03:00
Robert Ancell
ca1bb23edc glcontext: Remove duplicate check for GL version 2024-07-24 14:52:29 +03:00
Matthias Clasen
1dbea91db4 Merge branch 'wip/xdg-dialog-4-14' into 'gtk-4-14'
gdk/wayland: Implement support for xdg-dialog Wayland protocol [4.14]

See merge request GNOME/gtk!7256
2024-05-29 23:16:34 +00:00
Matthias Clasen
355a9f4d13 Merge branch 'gtk-4-14-backports' into 'gtk-4-14'
[4.14] macOS backports

See merge request GNOME/gtk!7292
2024-05-29 23:14:49 +00:00
Chun-wei Fan
757e35cf67 gdkvulkancontext.c: Use pointers to hash VkShaderModule
VkShaderModule's may or may not be pointers depending on the target
platform, so use pointers to hash those handles to be safe, and retrieve
them from hashes accordingly.

Fixes build on 32-bit Windows at least.
2024-05-29 18:44:06 +08:00
Carlos Garnacho
726a6a883a gdk/wayland: Implement support for xdg-dialog Wayland protocol
This protocol lifts some functionality from the gtk-shell protocol,
namely the ability to tag dialogs as modal. Ensure to use this
new protocol if available for the task, instead of the gtk-shell
protocol.
2024-05-23 12:16:14 +02:00
Carlos Garnacho
a9513b6200 build: Handle in-tree copies of wayland protocols
Convert the array managing the Wayland protocols to contain
dictionary objects for each of the protocol definitions, in order
to make it easier to extend for extra keys in them.

And also add one such extra 'required' key, so that we can
optionally build protocols depending on the wayland-protocol
version detected at runtime. This is necessary to add fallbacks
for upstream protocols without necessarily bumping GTK dependency,
some versioning handling of private protocols was added too
for this purpose, so we can have in-tree copies of them.
2024-05-23 12:16:09 +02:00
Mat
605d1e4043 gdkmacossurface: Set surface before accessing it
Silences the following critial:
_gdk_macos_surface_update_fullscreen_state: assertion
'GDK_IS_MACOS_SURFACE (self)' failed
2024-05-23 01:40:48 +03:00
Mat
e29d84abdb macos: Take shadows into account when positioning popups
Otherwise popups will be misaligned. This becomes noticeable when larger
shadows are used, like in libadwaita.

Regression in 08216dcee9
2024-05-23 01:40:03 +03:00
Matthias Clasen
957ff91fa5 Revert "gdk/frameclock: add mark when we discover frames may drop"
This reverts commit 84a304e66e.

This produces marks that are confusing to me. They don't correlate
with actual gaps in the frame cycle and often overlap with regular
'window presented' marks. Also, the function we are emitting these
marks from is called from the get_frame_time getter, and we
definitely don't want to emit marks from there.
2024-05-01 20:57:51 -04:00
Matthias Clasen
2acd04e5b3 vulkan: Don't forget to update the cache size
In order for the size change check to make sense, vk_pipeline_cache_size
needs to correspond to the size of the cache we last wrote to disk.

We were forgetting to update it after saving the cache, so the
check was ineffective.
2024-05-01 20:57:51 -04:00
Matthias Clasen
2aabbdf069 x11: Implement a missing method
Vulkan on X11 was getting spew for missing an empty_frame
implementation.
2024-05-01 20:57:51 -04:00
Benjamin Otte
fa88ca15c0 dmabuf: Use narrow range instead of full range
It's way more common, and Mutter uses it, too.

Avoid visual glitches when going in/out of offload.

Fixes #6672
2024-05-01 20:57:51 -04:00
Matthias Clasen
dd91a70241 loaders: Make it possible to load png options
We want to store some metadata in our symbolic pngs, so make it
possible to get options when loading a png, along with the texture.

Update all callers.
2024-05-01 20:51:58 -04:00
Benjamin Otte
73d46edf73 glcontext: Split dmabuf import codepaths
Use different codepaths for known formats vs unknown formats.

Be more careful with unknown formats and always import them as
GL_TEXTURE_EXTERNAL_OES when possible (GL can't do EXTERNAL) to avoid
problems.

This is a more defensive approach towards older drivers that don't
support modifiers.

This fixes importing YUV textures on AMD Gen8.

Another approach would be to check for YUV and never try
GL_TEXTURE_2D with them, but I decided to go this way first.

Fixes #6668
2024-05-01 20:51:58 -04:00
Matthias Clasen
10345e134f macos: Respect the default-settings debug key
This makes our behavior more consistent across platforms.
The suggestion came up in discussion in #6545.
2024-05-01 20:51:58 -04:00
Sebastian Wick
830ba15ab7 gdk: Consider XDG_ACTIVATION_TOKEN for the startup notification id
We prefer it over the old DESKTOP_STARTUP_ID environment variable if we
have it and it is valid.

We have to stash and unset XDG_ACTIVATION_TOKEN in addition to
DESKTOP_STARTUP_ID now as well. This makes sure that we don't call any
library functions which might rely on some environment variables. This
way unsetting the environment variables is safe and we can then
afterwards validate and print warnings.
2024-05-01 20:51:58 -04:00
Matthias Clasen
176a34ea9c wayland: Fix an ubsan warning
dev_t requires 8-byte alignment, so we need to use memcpy.
2024-05-01 20:51:58 -04:00
Arjan Molenaar
df9a90a83a macos: Add some docs for the different NSEvent getters 2024-04-25 19:16:37 +02:00
Arjan Molenaar
1af4a47491 macos: fix in-app native shortcuts (again)
Popping an event of the queue in the IMContext handler
prevents it from being forwarded to the NSApp, in case the
(key) event was not handled by IMContext.

So I reverted to a mix of the original (4.13) and new (4.14.1) behavior
for fetching events: NSEvent lookup for IMContext uses loose matching,
so it can work with rewritten events. When sending events to NSApp, only
we're checking for an exact match.

Now in-app keyboard shortcuts (e.g. Ctrl-F2) work from within text
fields again.
2024-04-25 19:16:11 +02:00
Arjan Molenaar
79451fcb72 macos: Avoid repeatedly sending events back to macOS
in the old approach it was possible that one NSEvent was
sent to the underlying NSApp multiple times. This resulted in
those events being forwarded to our (glib) event queue again.

The visual result was that no screen updates were done. Under the hood
the application was very busy with passing events around.

By popping the events off of our event queue, we make sure they're sent
only once.
2024-04-25 19:15:45 +02:00
Luca Bacci
64e512054c GdkWin32: Do not clear surface contents when restoring from minimize
The code does not work anyway since we dropped WS_EX_LAYERED windows.
2024-04-20 16:03:39 +03:00
Luca Bacci
cde8ceae49 GdkWin32: Don't explicitly set the transient owner as active
...when a transient child is hidden.

The system does that automatically
2024-04-20 16:03:25 +03:00
Luca Bacci
9b8826f8a7 GdkWin32: Remove some work arounds that are not needed anymore
2cc650ce was added to work around some of the regressions
introduced by 79557271, but that commit was finally reverted
in 43476c09.

We can now revert 2cc650ce as well.

Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/6614
2024-04-20 16:03:07 +03:00
oreo639
ec14f9a4c6 x11: Remove last_wmspec_check_time
In fetch_net_wm_check_window(), before updating the wmspec_check_window, a
check is performed to verify a 15s difference between last_wmspec_check_time
and the current monotonic time.

The comment suggests that this check is done to ensure that it doesn't check
for a new check window repeatedly over and over again. While that was the case
origionally, currently the last_wmspec_check_time only gets updated when
wmspec_check_window is set, which is already checked earlier, making the time
check useless.

This check causes issues on cold boots where gtk4 applications are not able
to obtain the wmspec_check_window until 15 seconds after boot, making gtk
unable to check for extended wm_hints during that time.

Fixes: #6558
2024-04-17 22:02:18 -04:00
Matthias Clasen
f2588532c0 wayland: Cosmetics
Don't clear the same pointer twice.
2024-04-17 22:00:39 -04:00
Philip Withnall
8eb051f6df gdk: Fix a maybe-uninitialized warning
If there somehow end up being no `supported_versions`, `ctx` would end
up being dereferenced before being initialised. While I think that’s
unlikely, the compiler doesn’t know that, so let’s just initialise the
variable unconditionally.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-04-17 21:59:00 -04:00
Matthias Clasen
7e2cb727b8 build: Add a missing dependency
Add the generated gdk headers to the sources for all the backends,
to guarantee that they are generated before the library is used.

Fixes: #6618
2024-04-17 21:58:48 -04:00
Matthias Clasen
918b5e9bc1 dmabuf texture: Survive multiple disposes
dispose can be called more than once, so be safe for that.
2024-04-17 21:58:28 -04:00
Hansem Ro
497da6b301 xi2: Fix incorrect input source type in Input debug message
This drops cursor and eraser source names to account for their removal
from GdkInputSource so that GDK_DEBUG=input debug message correctly
prints source type in X11 environment.

Fixes: c1d90273 ("gdk: Drop GDK_SOURCE_ERASER")
Fixes: 3285f52d ("gdk: Drop GDK_SOURCE_CURSOR")
Closes: #6619
2024-04-17 21:56:35 -04:00
Carlos Garnacho
af4c9ea61e Merge branch 'provide-touch-serial-later' into 'main'
gdk/wayland: Proivde latest touch serial even after a touch ended

See merge request GNOME/gtk!5782
2024-04-03 08:43:03 +00:00
Chris Williams
979d0f4b1d wayland: Fix detection of empty settings portal response
The ReadAll method returns a one-element tuple, so
g_variant_n_children() is always 1.
2024-04-01 10:33:00 -04:00