Commit Graph

2963 Commits

Author SHA1 Message Date
Benjamin Otte
14e44f36bf glx: Move error trap even further out
This way we only create one error trap for all attempts to create a
context instead of up to 3.
2023-06-06 05:20:34 +02:00
Benjamin Otte
1e60ad1430 glx: Ignore all errors
In error cases, glXCreateContextAttribsARB() will always return NULL so
it is enough to run the loop until the first non-NULL context is
returned.

And at that point, we can just look at the return value and ignore all
errors.
2023-06-06 05:20:34 +02:00
Matthias Clasen
c380d17621 Revert "gdk/x11: Also grab keyboard during XDnD grabs"
This reverts commit ae94417f80.
2023-06-03 12:25:25 -04:00
Matthias Clasen
686d18dfc2 x11: Stop using passive grabs
The keynav that this implements is half-broken under
xwayland anyway, and it confused and complicates things
on the compositor side.
2023-06-03 12:25:25 -04:00
Benjamin Otte
0a1702ae99 Merge branch 'wip/otte/fix-glx' into 'main'
glx: Trap errors inside loop

Closes #5857

See merge request GNOME/gtk!6056
2023-06-03 16:19:09 +00:00
Benjamin Otte
0016fea36b glx: Trap errors inside loop
Instead of trapping errors for the whole loop trying to create GL
contexts, trap them once per GL context.

Apparently GLX does throw an error when a too high version is requested
and doesn't just return NULL and then that error lingers when we try
lower versions.

Fixes #5857
2023-06-03 18:03:56 +02:00
Matthias Clasen
c8c895d160 Merge branch 'trap-bad-rr-errors' into 'main'
x11: Trap XRandr errors when getting outputs during init and update

See merge request GNOME/gtk!6046
2023-06-02 11:31:45 +00:00
Marco Trevisan (Treviño)
f2a2889153 x11: Trap XRandr errors when getting outputs during init and update
We may try to update the XRR outputs and Crtcs when they're changing in
the server, and so we may get BadRROutput that we're currently not
handling properly.

As per this, use traps and check whether we got errors, and if we did
let's ignore the current output.

It's not required to call init_randr13() again because if we got errors
it's very likely that there's a change coming that will be notified at
next iteration during which we'll repeat the init actions.
2023-06-02 00:30:14 +02:00
Marco Trevisan (Treviño)
be4f6ff3da gdkselectioninputstream-x11: Explicitly handle stream ownership in signal
The display xevent signal connection takes the ownership of the stream
until we get a valid event, so it should manage the stream lifetime.

So make this clearer, by automatically removing the stream reference
when we disconnect from the xevent signal handler.
2023-05-30 17:59:19 +02:00
Marco Trevisan (Treviño)
4fcf899852 gdkselectioninputstream-x11: Make it clearer how we manage the stream ownership
It gets unreffed during gdk_x11_selection_input_stream_complete, so use
APIs that make this clearer.
2023-05-30 17:54:29 +02:00
Marco Trevisan (Treviño)
371e860184 gtkselectioninputstream-x11: Do not add an extra reference to the returned stream
We create a new stream during gdk_x11_selection_input_stream_new_async()
then such stream is referenced when passed to the task via
g_task_return_pointer(), so there's no need to reference it again before
returning it, or we'd end up leaking.

Fixes: https://gitlab.gnome.org/GNOME/gtk/-/issues/4892
2023-05-30 17:50:56 +02:00
Marco Trevisan (Treviño)
bce1e0bfdd gtkselectioninputstream-x11: Do not add unreffed bytes to the chunks queue
This should never happen, but we may exit the loop because of count value
with an unreffed bytes pointer being added back to the chunks queue.
2023-05-30 17:43:57 +02:00
Marco Trevisan (Treviño)
468d2cb7f2 gtkselectioninputstream-x11: Do not add EOF marker twice to the chunks queue
We were adding the same EOF marker two times back to the chunks queue,
one implicitly, and the other time could happen when exiting the loop.
2023-05-30 17:42:59 +02:00
Benjamin Otte
c7b62d89e3 glx: Implement support for EXT_swap_control
XWayland (at least on gnome-shell) does not support SGI_swap_control,
which we were using to unset the swap interval.

It does support EXT_swap_control though, which is the more modern
version of the same thing, so this commit adds support for that.

And now GDK_DEBUG=no-vsync gives me >1000fps instead of just 60fps,
2023-05-24 21:44:43 +02:00
Benjamin Otte
7573a9d2a7 gl: Rewrite update area tracking code
Make it more generic. That way we could dynamically change the number of
buffers we track.

We don't do that yet though.
2023-05-24 21:44:29 +02:00
Matthias Clasen
e5f1e4545d gdk: Change the private export handle api
Make unexport_handle take the handle, so we
can in the future deal with multiple exports.

Update the one caller in gtkwindow.c to pass
the handle.
2023-05-14 23:49:44 -04:00
Matthias Clasen
2cd5b4df1b Add missing va marshallers
Whenever we pass a marshaller to g_signal_new,
call g_signal_set_va_marshaller with the corresponding
va marshaller.
2023-05-13 12:38:24 -04:00
Benjamin Otte
6cc1548c5f Merge branch 'wip/carlosg/x11-artifacts' into 'main'
gdk/x11: Invalidate whole surface after size change

See merge request GNOME/gtk!5857
2023-04-29 18:11:21 +00:00
Carlos Garnacho
24302315fb gdk/x11: Invalidate whole surface after size change
The Expose events following a ConfigureNotify may arrive at
a time that we did not resize the surface yet, making these
expose events a no-op. Even though gsk/gtk take care of the
window content itself, this might lead to unrendered portions
of the window shadow.

This may be seen with GSK_RENDERER=cairo and GDK_BACKEND=x11,
attempting to tile a window (e.g. gtk4-demo) left or right.
The window will show black rectangles or other artifacts in
the window shadow areas that correspond to the newly painted
portions (as the window needs to expand vertically).

In order to fix this with a similar behavior to Wayland,
consider ourselves the whole surface invalidated after resize,
in order to ensure everything is painted from scratch.
2023-04-29 11:51:32 +02:00
Benjamin Otte
5f833f1d31 glcontext: Compute matching version the simple way
Do it all in one function instead of requiring two different ones.
2023-04-27 02:13:32 +02:00
Benjamin Otte
ab2a548479 glx: Make sure highest possible GL version is created
Mirror EGL here.
2023-04-27 02:13:32 +02:00
Benjamin Otte
f86429177a gdk: Introduce GdkGLVersion
... and use it.

Makes the code simpler.
2023-04-27 02:13:32 +02:00
Benjamin Otte
9d0448756f display: Remove ::create_surface() vfunc
Instead, have a toplevel_type and popup_type in GdkDisplay and
call g_object_new() with those types.
2023-04-26 21:03:34 +02:00
Benjamin Otte
cb642bec25 gdk: Remove GDK_SURFACE_DRAG enum member
I want to remove the whole enum, but this value was used all over the
place. So removing it first ensures I didn't forget anything.
2023-04-26 21:03:34 +02:00
Benjamin Otte
486196c979 x11: Add private gdk_x11_drag_surface_new()
... and use it.
2023-04-26 21:03:34 +02:00
Benjamin Otte
83faacabe3 x11: Set frame clock in ::constructed 2023-04-26 21:03:34 +02:00
Benjamin Otte
31aae62f9a x11: Move window construction to ::constructed() 2023-04-26 21:03:34 +02:00
Benjamin Otte
cbe89b955a x11: Get rid of sizes when constructing surfaces
Just call XCreateWindow with 0, 0, 1, 1 size.
2023-04-26 21:03:34 +02:00
Benjamin Otte
2d827978a6 x11: Remove unused variable 2023-04-26 21:03:34 +02:00
Benjamin Otte
7ef5f6ef1a display: Remove x/y/w/h from create_surface() 2023-04-26 21:03:34 +02:00
Marc-André Lureau
d69cdf6c05 gdk: drop libangle GLES minimum version
GLES 2.0 version is fine now with current gtk according to B. Otte.
Let's use the same minimum requirement for all implementations.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2023-04-17 04:50:17 +00:00
Benjamin Otte
cfaf1b3e71 x11: Remove commented outdated code
... and it's copy/paste into the win32 backend
2023-04-13 17:15:35 +02:00
Matthias Clasen
76ac91512b Deprecate gdk_surface_create_similar_surface
This function is part of the cairo drawing API and
we are moving away from that. Update all callers.
2023-04-01 23:09:19 -04:00
Matthias Clasen
075bea788b Add gdk_surface_get_scale
Add a scale property to GdkSurface and use the
fractional scale for it on Wayland.
2023-04-01 19:09:16 -04:00
Matthias Clasen
a1c5a806b3 Convert headers to #pragma once
The conversion was done by guard2one.
2023-03-31 15:11:10 -04:00
Ivan Molodetskikh
11d9bbfd6e x11/surface: Get current drag surface size with compute-size signal
Query and update size of drag surfaces, similarly to how it's done for
the Wayland backend in the previous commit.
2023-03-14 19:41:44 -07:00
Matthias Clasen
5cca7488d4 x11: Stop using g_slice 2023-03-14 14:56:42 -04:00
Jonas Ådahl
f2a0a8b8be x11/surface: Clear compute_size idle source also when destroying
Doing it on hide() is not enough, since in some edge cases we didn't
ever actually map, we just attempted to compute the size, e.g. in
response to a ConfigureNotify event, then the window was destroyed.

Related: https://gitlab.gnome.org/GNOME/mutter/-/issues/2678
2023-03-10 23:34:50 +01:00
Carlos Garnacho
ae94417f80 gdk/x11: Also grab keyboard during XDnD grabs
The drag source must handle events and messaging, this also
includes keyboard handling for accessibility and cancellation.

Closes: https://gitlab.gnome.org/GNOME/gtk/-/issues/5604
2023-02-18 23:02:22 +01:00
Carlos Garnacho
824e983372 gdk/x11: Reset all scroll valuators on enter
We no longer need to make much distinction between multiple logical
devices, plus it breaks esp. with the Xwayland input device distribution.
Just iterate across all devices and reset their scroll valuators.

Closes: https://gitlab.gnome.org/GNOME/gtk/-/issues/4160
2023-02-04 13:13:19 +01:00
Benjamin Otte
c17049c6d1 Merge branch 'wip/otte/gl-is-current' into 'main'
gdk: Add private GLContext::is_current() check

Closes #5392

See merge request GNOME/gtk!5463
2023-02-02 21:56:32 +00:00
Matthias Clasen
8796950651 Deprecate more startup-notification API 2023-02-02 08:30:32 +01:00
Benjamin Otte
c6cef6db52 gdk: Add private GLContext::is_current() check
... and use this check in gdk_gl_context_make_current() and
gdk_gl_context_get_current() to make sure the context really is still
current.

The context no longer being current can happen when external GL
implementations make their own contexts current in the same threads GDK
contexts are used in.
And that can happen for example by WebKit.

Theoretically, this should also allow external EGL code to run in X11
applications when GDK chooses to use GLX, but I didn't try it.

Fixes #5392
2023-02-02 04:23:51 +01:00
Matthias Clasen
746d12fc43 Silence a compiler warning
Clang was complaining that we never use the
value stored in mime_type. Just don't store it,
we are only interested in the side-effect
(interning the string).
2023-01-13 12:07:40 -05:00
Matthias Clasen
0073bb79a7 Deprecate gdk_display_put_event
The documentation already tells you not to
use this function.

Ifdef the remaining users in the X11 backend.
2023-01-09 15:46:25 -05:00
Matthias Clasen
8349ae2bc4 x11: Make a call NULL-safe
Make it safe to call gdk_x11_app_launch_context_get_startup_notify_id
with a NULL info.
2023-01-04 16:37:31 -05:00
Carlos Garnacho
7fab1b85ad gdk/x11: Emit "remove" s-n message from gdk_toplevel_set_startup_id
In the way towards deprecating gdk_display_notify_startup_complete(),
make gdk_toplevel_set_startup_id() on X11 perform this piece of messaging
itself. It should be harmless that the message is emitted twice, if
callers do still use that API.
2023-01-03 14:58:25 +01:00
Carlos Garnacho
c24358cfbc gdk/x11: Clear all data in GdkSurfaceX11 finalization
Currently, the GdkSurfaceX11 implementation relies that the upper
layers hid the surface before destruction, and that no
GdkSurfaceClass.compute_resize happened between them. If these
circumstances happened, there would be a compute_size timeout left
dangling after the surface got destroyed, poking at incorrect data
later on. Something that looks like this was reported in the
recent mutter-x11-frames "SSD frames server":

    mutter-x11-frames:423016): GLib-GObject-WARNING **: 19:41:16.869: invalid unclassed pointer in cast to 'GtkWindow'

    Thread 1 "mutter-x11-fram" received signal SIGTRAP, Trace/breakpoint trap.
    g_logv (log_domain=0x7ffff7f7c4f8 "GLib-GObject", log_level=G_LOG_LEVEL_WARNING, format=<optimized out>, args=<optimized out>) at ../../../glib/gmessages.c:1433
    1433	../../../glib/gmessages.c: No such file or directory.
    (gdb) bt
    #0  g_logv (log_domain=0x7ffff7f7c4f8 "GLib-GObject", log_level=G_LOG_LEVEL_WARNING, format=<optimized out>, args=<optimized out>) at ../../../glib/gmessages.c:1433
    #1  0x00007ffff73470ff in g_log (log_domain=log_domain@entry=0x7ffff7f7c4f8 "GLib-GObject", log_level=log_level@entry=G_LOG_LEVEL_WARNING, format=format@entry=0x7ffff7f84da8 "invalid unclassed pointer in cast to '%s'")
        at ../../../glib/gmessages.c:1471
    #2  0x00007ffff7f72892 in g_type_check_instance_cast (type_instance=type_instance@entry=0x5555558e04b0, iface_type=<optimized out>) at ../../../gobject/gtype.c:4144
    #3  0x00007ffff791e77d in toplevel_compute_size (toplevel=<optimized out>, size=0x7fffffffe170, widget=0x5555558e04b0) at ../../../gtk/gtkwindow.c:4227
    #4  0x00007ffff7f4f3b0 in g_closure_invoke (closure=0x555555898cc0, return_value=return_value@entry=0x0, n_param_values=2, param_values=param_values@entry=0x7fffffffdeb0, invocation_hint=invocation_hint@entry=0x7fffffffde30)
        at ../../../gobject/gclosure.c:832
    #5  0x00007ffff7f62076 in signal_emit_unlocked_R
        (node=node@entry=0x55555588feb0, detail=detail@entry=0, instance=instance@entry=0x55555560e990, emission_return=emission_return@entry=0x0, instance_and_params=instance_and_params@entry=0x7fffffffdeb0)
        at ../../../gobject/gsignal.c:3796
    #6  0x00007ffff7f68bf5 in g_signal_emit_valist (instance=<optimized out>, signal_id=<optimized out>, detail=<optimized out>, var_args=var_args@entry=0x7fffffffe050) at ../../../gobject/gsignal.c:3549
    #7  0x00007ffff7f68dbf in <emit signal ??? on instance 0x55555560e990 [GdkX11Toplevel]> (instance=<optimized out>, signal_id=<optimized out>, detail=detail@entry=0) at ../../../gobject/gsignal.c:3606
    #8  0x00007ffff7a8de96 in gdk_toplevel_notify_compute_size (toplevel=<optimized out>, size=size@entry=0x7fffffffe170) at ../../../gdk/gdktoplevel.c:112
    #9  0x00007ffff7a4b15a in compute_toplevel_size (surface=surface@entry=0x55555560e990 [GdkX11Toplevel], update_geometry=update_geometry@entry=1, width=width@entry=0x7fffffffe220, height=height@entry=0x7fffffffe224)
        at ../../../gdk/x11/gdksurface-x11.c:281
    #10 0x00007ffff7a4c3b2 in compute_size_idle (user_data=0x55555560e990) at ../../../gdk/x11/gdksurface-x11.c:356
    #11 0x00007ffff733f67f in g_main_dispatch (context=0x55555563f6e0) at ../../../glib/gmain.c:3444
    #12 g_main_context_dispatch (context=context@entry=0x55555563f6e0) at ../../../glib/gmain.c:4162
    #13 0x00007ffff733fa38 in g_main_context_iterate (context=0x55555563f6e0, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at ../../../glib/gmain.c:4238
    #14 0x00007ffff733fcef in g_main_loop_run (loop=loop@entry=0x5555560874a0) at ../../../glib/gmain.c:4438
    #15 0x0000555555557de0 in main (argc=<optimized out>, argv=<optimized out>) at ../src/frames/main.c:68

It perhaps makes sense to warn in these situations, but either way
it sounds like gdk_surface_x11_finalize() could enforce the correct
behavior by ensuring there is no dangling timeouts/data. This commit
does that.
2022-12-07 13:16:36 +01:00
Luca Bacci
f788e994a9 GLX: Add extra glXMakeContextCurrent () call to work around a DRI issue
Reference: https://gitlab.freedesktop.org/mesa/mesa/-/issues/7808

Fixes #4499, #5387, #5170
2022-12-02 14:20:43 +01:00
Matthias Clasen
fe56f3413a Don't emit ::notify from a getter
GdkX11Keymap ddetermines the direction of the
keymap on demand, and was emitting notify::direction
2022-11-26 21:53:33 -05:00