Commit Graph

9374 Commits

Author SHA1 Message Date
Christian Hergert
0243736003 macos: support ARM/PowerPC time conversion for DisplayLink times
When converting DisplayLink frame presentation times, we need to take into
account the arch-specific types. This tracks changes in GNOME/GLib!1566 so
that precision is not lost.
2020-07-27 12:49:57 -07:00
Matthias Clasen
73f4f518b8 gdk: Improve struct packing in places
Plug some holes in our structs by rearranging
a few fields. This is was done looking at
pahole output.
2020-07-25 11:57:37 -04:00
Benjamin Otte
3078b180fe Replace "gdouble" with "double" 2020-07-25 00:47:36 +02:00
Benjamin Otte
d375dce9f5 Replace "gchar" with "char" 2020-07-25 00:47:36 +02:00
Benjamin Otte
d7266b25ba Replace "gint" with "int" 2020-07-25 00:47:36 +02:00
Chun-wei Fan
89f7d841ab gdk/gdkarrayimpl.c: Fix build on Visual Studio
It seems like initializing something to an empty array using `{}` is a GCCism,
so just stuff a 0 within the braces to accomplish the same thing.
2020-07-24 16:25:24 +08:00
Matthias Clasen
2e07fcd680 Merge branch 'wip/chergert/quartz4u' into 'master'
Merge GDK macOS branch

See merge request GNOME/gtk!2272
2020-07-21 22:22:41 +00:00
Christian Hergert
9dbf99d91a macos: prototype new GDK backend for macOS
This is fairly substantial rewrite of the GDK backend for quartz and
renamed to macOS to allow for a greenfield implementation.

Many things have come across from the quartz implementation fairly
intact such as the eventloop integration design and discovery of
event windows from the NSEvent.

However much has been changed to fit in with the new GDK design and
how removal of child GdkWindow have been completely eliminated.
Furthermore, the new GdkPopup allows for regular NSWindow to be used
to provide popovers unlike the previous implementation.

The object design more closely follows the ideal for a GDK backend.

Views have been broken out into subclasses so that we can support
multiple GSK renderer paths such as GL and Cairo (and Metal in the
future). However mixed mode GL and Cairo will not be supported. Currently
only the Cairo renderer has been implemented.

A new frame clock implementation using CVDisplayLink provides more
accurate information about when to draw drawing the next frame. Some
testing will need to be done here to understand the power implications
of this.

This implementation has also gained edge snapping for CSD windows. Some
work was also done to ensure that CSD windows have opaque regions
registered with the display server.

     ** This is still very much a work-in-progress **

Some outstanding work that needs to be done:

 - Finish a GL context for macOS and alternate NSView for GL rendering
   (possibly using speciailized CALayer for OpenGL).
 - Input rework to ensure that we don't loose remapping of keys that was
   dropped from GDK during GTK 4 development.
 - Make sure input methods continue to work.
 - Drag-n-Drop is still very much a work in progress
 - High resolution input scrolling needs various work in GDK to land
   first before we can plumb that to NSEvent.
 - gtk/ has a number of things based on GDK_WINDOWING_QUARTZ that need
   to be updated to use the macOS backend.

But this is good enough to start playing with and breaking things which
is what I'd like to see.
2020-07-21 14:45:12 -07:00
Christian Hergert
0154a7f528 gdk: disable file transfer portal on macOS 2020-07-21 14:45:12 -07:00
Christian Hergert
7884ab6161 build: fix linking support on macOS with Clang
This was preventing any sort of building on macOS, even though the quartz
backend is currently non-functional. Fixing this is a pre-requisite to
getting a new macOS backend compiling.
2020-07-21 14:45:12 -07:00
Matthias Clasen
bc542c5304 gdk: Update gdkkeysyms.h
Run the gdkkeysyms-update.pl script to pick up several
new keysyms:
GDK_dead_lowline
GDK_dead_aboveverticalline
GDK_dead_belowverticalline
GDK_dead_longsolidusoverlay
GDK_Keyboard
GDK_WWAN
GDK_RFKill
GDK_AudioPreset
2020-07-21 16:55:28 -04:00
Timm Bäder
11f07cb5ad GdkRGBA: Fix typo in documentation 2020-07-17 05:49:11 +02:00
Benjamin Otte
90b7b84337 array: Add a bunch of new features
* GDK_ARRAY_BY_VALUE
  #define this to get GArray-like behavior
* gdk_array_splice (v, 0, 0, NULL, 25)
  Adding items but passing NULL as the items will zero() them.
* gdk_array_set_size()
  A nicer way to call gdk_array_splice()
* constify getters
2020-07-16 18:09:58 +02:00
Benjamin Otte
a4cd974912 array: Add null-termination 2020-07-16 18:09:57 +02:00
Benjamin Otte
8bf8ac5076 Add GdkArray
This is a scary idea where you #define a bunch of preprocessor values
and then #include "gdkarrayimpl.c" and end up with a dynamic array for
that data type.

See https://en.wikipedia.org/wiki/X_Macro for what's going on.

What are the advantages over using GArray or GPtrArray?

 * It's typesafe
   Because it works like C++ templates, we can use the actual type of
   the object instead of having to use gpointer.

 * It's one less indirection
   instead of 2 indirections via self->array->data, this array is
   embedded, so self->array is the actual data, and just one indirection
   away. This is pretty irrelevant in general, but can be very noticable
   in tight loops.

 * It's all inline
   Because the whole API is defined as static inline functions, the
   compiler has full access to everything and can (and does) optimize
   out unnecessary calls, thereby speeding up some operations quite
   significantly, when full optimizations are enabled.

 * It has more features
   In particular preallocation allows for avoiding malloc() calls, which
   can again speed up tight loops a lot.
   But there's also splice(), which is very useful when used with
   listmodels.
2020-07-16 18:09:57 +02:00
Matthias Clasen
c12261a6ec Merge branch 'wip/fix-picom-crasher' into 'master'
x11: Don't set up frame sync fence on unsupported compositors

Closes #2927

See merge request GNOME/gtk!2245
2020-07-15 01:40:49 +00:00
Emmanuel Gil Peyrot
74a4432688 gdk/wayland: Add an API to inhibit and uninhibit idle
This uses the idle-inhibit protocol from wayland-protocols, to attach an
inhibitor to the GdkSurface.  The inhibit function can be called as many
times as the user wants, but the uninhibit function MUST be called as
many times to unset the idle inhibition.

This has been tested on Sway.
2020-07-14 21:47:22 +02:00
Ray Strode
d0ec616fba x11: Don't set up frame sync fence on unsupported compositors
Not all compositors support _NET_WM_FRAME_DRAWN.  In cases
where the compositor doesn't support _NET_WM_FRAME_DRAWN we don't
need to do all the fancy damage tracking and fence watching.

Furthermore, if the compositor doesn't support _NET_WM_FRAME_DRAWN,
it's possible that one frame will start before the previous frame has
made it through the pipeline, leading to a blown assertion.

This commit side-steps the unnecessary code and associated assertion
when _NET_WM_FRAME_DRAWN isn't supported.

Fixes: https://gitlab.gnome.org/GNOME/gtk/-/issues/2927
2020-07-14 14:33:12 -04:00
Matthias Clasen
d441e7106b x11: Plug a memory leak
Don't leak atoms when we're storing the clipboard.
2020-07-09 18:19:32 -04:00
Carlos Garnacho
c0c5ce2f9b gdk/x11: Ignore regular crossing events while in implicit grabs
If we create an implicit grab on a surface, leave the surface, and
release the button, we would get 2 XI_Leave events, one with mode
XINotifyNormal when the pointer leaves the surface, and another with
mode XINotifyUngrab when the button is released.

Meanwhile, the upper layers rely on crossing events being paired,
and particularly in no crossing event being sent until the implicit
grab is dismissed (either by releasing it, or via more pervasive
grabs).

Ignoring the set of XINotifyNormal events while an implicit grab
is active adapts the X11 backend to this behavior. If the grab were
released or taken away by another grab, a crossing event with one
of the other XINotify*Grab/XINotify*Ungrab will be generated.

Fixes: https://gitlab.gnome.org/GNOME/gtk/-/issues/2879
2020-07-09 17:02:07 +02:00
Caolán McNamara
7e97c2513f gtk#767 add a way to change the application_id of a toplevel wayland GdkSurface
so LibreOffice can reuse toplevels and get the right task icons

references;
 https://gitlab.gnome.org/GNOME/gtk/-/issues/767
 https://lists.freedesktop.org/archives/wayland-devel/2019-July/040704.html
 e0d6ad1d5e
 https://bugs.documentfoundation.org/show_bug.cgi?id=125934
 https://bugzilla.redhat.com/show_bug.cgi?id=1334915
 https://bugreports.qt.io/browse/QTBUG-77182
2020-07-07 15:56:12 +01:00
Ray Strode
56b3669411 x11: Avoid thawing surface until frame is drawn
Since commit 972134abe4 a frame getting
drawn has three states (with the vendor nvidia driver at least):

1. drawn by gtk waiting on the GPU
2. drawn by GPU waiting on the compositor
3. drawn by compositor

Those three states are encoded in two flags: frame_pending and
frame_still_painting.

frame_pending means step 1 is done, but step 2 and 3 are still
in progress.  frame_still_painting means step 2 is still in progress.

After step 1 is finished the surface is frozen until step 3 is finished.

When the compositor notifies gtk it's done with step 3, with a
_NET_WM_FRAME_DRAWN client message, the toolkit thaws the surface to
allow the next frame to proceed.

The compositor sometimes sends gtk a _NET_WM_FRAME_DRAWN client message
between steps 1 and 2.  This message should be ignored because it's not
a reply to the current frame.

Unfortunately, gtk currently assumes if it gets a _NET_WM_FRAME_DRAWN
client message while waiting for step 2 that it's actually at step 3,
and proceeds to draw a new frame while the existing frame is still
pending, leading to a blown assertion.

This commit addresses the problem by ignoring _NET_WM_FRAME_DRAWN
client messages from the compositor unless actually expecting one.

Fixes: #2902
2020-06-30 14:36:15 -04:00
Ray Strode
e3b5b76cdd x11: Handle window getting unmapped while frame still pending
Since commit 972134abe4 we now call
glClientWaitSync for the vendor nvidia driver, to know when a frame
is ready for the compositor to process.

If a surface is hidden while a frame is still being rendered by the GPU,
the surface will never produce the damage event the code relies on to
trigger the call to glClientWaitSync. This leaves the fence dangling,
and the next time the surface is shown, it will start a fresh frame
and blow an assertion since the fence from the last frame is still
hanging around.

This commit ensures a frame gets fully wrapped up before hiding a
surface.
2020-06-30 14:36:07 -04:00
Matthias Clasen
9f2926dde3 gdk: Better help for GDK_DEBUG
Include docstrings and format the list of supported
values better.

Also, add the same warning we have for GTK_DEBUG when
the environment variable is ignored.
2020-06-28 13:42:02 -04:00
Matthias Clasen
d46b04631e wayland: Respect GDK_DEBUG=default-settings
You can get this in other ways for Wayland (by
setting GSETTINGS_BACKEND=memory), but it is better
to be consistent across backends.
2020-06-28 13:42:02 -04:00
Matthias Clasen
4d7d031ee0 gdk: Small documentation fixes
Make sure gdk_event_get_seat shows up.
2020-06-28 12:24:03 -04:00
Matthias Clasen
674ede8665 docs: Remove ancient version information
We treat 4.0 as a new era.
2020-06-27 21:46:22 -04:00
Carlos Garnacho
469a4a73f9 gdk: Drop gdk_device_get_last_event_surface()
This kind of transient state sets the expectative that events update
devices, while it's more accurate to say that devices generate events.
It does not make to expose this function anymore.
2020-06-24 11:24:04 +02:00
Carlos Garnacho
7be6afe84d gdk: Depend less on gdk_event_get_device()
For the most part, we are interested in seats here.
2020-06-23 23:42:53 +02:00
Carlos Garnacho
cf1fbdf8b5 gdk: Add gdk_event_get_seat()
It currently fetches the seat from the event device, will be changed
in future commits.
2020-06-23 23:42:53 +02:00
Carlos Garnacho
6d2860efb7 gdk: Drop gdk_seat_get_logical_pointers()
Events come from hardware devices and are handled by controllers,
there's no need to use logical pointers, nor to peek them. Drop this
unused API.
2020-06-23 23:42:53 +02:00
Carlos Garnacho
5f29b8fcec gdk: Drop GdkGrabOwnership
We no longer expose such low level tweaks, this is essentially
unused.
2020-06-23 23:42:53 +02:00
Carlos Garnacho
59a8106373 gdk: Drop supports_multidevice API
Crossing events are now detached from widget state, all tricky consequences
from getting multiple crossing events are now somewhat moot. Resort to sending
all generated crossing events, and drop this barely (ever?) used API.
2020-06-23 23:42:53 +02:00
Carlos Garnacho
c1d90273ca gdk: Drop GDK_SOURCE_ERASER
All tools come from devices with GDK_SOURCE_PEN.
2020-06-23 23:42:53 +02:00
Ray Strode
1912513d7a x11: Ensure bound context is compatible with sync fence
Commit a0f6ff101e made sure that a
context was bound before calling glClientWaitSync, but it doesn't
check that the context shares objects with the context that created
the fence.

This commit does a little more validation before deciding the current
context is good enough.
2020-06-22 19:09:43 -04:00
Ray Strode
a0f6ff101e x11: ensure some context is bound before calling glClientWaitSync
Since commit 972134abe4 we now call
glClientWaitSync for the vendor nvidia driver, to know when a frame
is ready for the compositor to process.

glClientWaitSync can be called regardless of which context is currently
bound, but if no context is bound at all, it returns 0 without
doing anything.

This commit checks for that edge case, and ensures a context gets
made current in the event no context is already current, before calling
glClientWaitSync.
2020-06-22 17:13:54 -04:00
Matthias Clasen
367d24be7f Merge branch 'keyval-to-uni-fix' into 'master'
gdk: Make gdk_keyval_to_unicode platform-independent

See merge request GNOME/gtk!2132
2020-06-22 18:13:25 +00:00
Matthias Clasen
c6fe8818ed gdk: Clarify the docs of gdk_keyval_to_unicode
Explicitly state that the conversion does not
take locale into account, and point out GDK_KEY_KP_Decimal
as a candidate for special-casing.
2020-06-22 13:24:34 -04:00
Ray Strode
05736afaf8 x11: be more verbose when glClientWaitSync behaves unexpectedtly
When given a 0 timeout, glClientWaitSync is only supposed to return one
of three possible values:

 - GL_ALREADY_SIGNALED - fence fired
 - GL_WAIT_FAILED - there was an error
 - GL_TIMEOUT_EXPIRED - fence hasn't fired yet

In addition, it can also return GL_CONDITION_SATISFIED if a non-zero
timeout is passed, and the fence fires while waiting on the timeout.

Since commit 972134abe4 we now call
glClientWaitSync (with a 0 timeout), but one user is reporting it's
returning some value that's not one of the above four.

This commit changes the g_assert to a g_error so we can see what
value is getting returned.

May help with https://gitlab.gnome.org/GNOME/gtk/-/issues/2858
2020-06-22 11:16:32 -04:00
Matthias Clasen
2df139cf40 gdk: Make gdk_keyval_to_unicode platform-independent
The result of gdk_keyval_to_unicode should not depend
on the platform.
2020-06-22 08:31:10 -04:00
Matthias Clasen
79b1d24128 Merge branch 'gtk4-arb_fbo' into 'master'
Switch to GL_ARB_framebuffer_object

See merge request GNOME/gtk!2079
2020-06-20 17:12:52 +00:00
Emmanuele Bassi
1c856a208f Rename master and slave device
We already use the "logical/virtual" and "physical" names in the
documentation, there's no reason to use loaded terms just because X11
uses them.
2020-06-18 19:22:20 +01:00
Yuri Chornoivan
c0cf839729 Fix minor typos 2020-06-18 10:47:16 +03:00
Rico Tzschichholz
7c1cf7781b gdk: Drop gdk_device_get_axis_value leftovers 2020-06-16 15:31:29 +02:00
Yariv Barkan
887aa2abdd frame clock: fix scheduling
Fix scheduling of the frame clock when we don't receive "frame drawn"
messages from the compositor.

If we received "frame drawn" events recently, then the "smooth frame
time" would be in sync with the vsync time. When we don't receive frame
drawn events, the "smooth frame time" is simply incremented by constant
multiples of the refresh interval. In both cases we can use this smooth
time as the basis for scheduling the next clock cycle.

By only using the "smooth frame time" as a basis we also benefit from
more consistent scheduling cadence. If, for example, we got "frame
drawn" events, then didn't receive them for a few frames, we would still
be in sync when we start receiving these events again.
2020-06-15 08:54:18 +02:00
Yariv Barkan
9c5d6eaa71 frame clock: adjust reported frame time
When an animation is started while the application is idle, that often
happens as a result of some external event. This can be an input event,
an expired timer, data arriving over the network etc. The result is that
the first animation clock cycle could be scheduled at some random time,
as opposed to follow up cycles which are usually scheduled right after a
vsync.

Since the frame time we report to the application is correlated to the
time when the frame clock was scheduled to run, this can result in
uneven times reported in the first few animation frames. In order to fix
that, we measure the phase of the first clock cycle - i.e. the offset
between the first cycle and the preceding vsync. Once we start receiving
"frame drawn" signals, the cadence of the frame clock scheduling becomes
tied to the vsync. In order to maintain the regularity of the reported
frame times, we adjust subsequent reported frame times with the
aforementioned phase.
2020-06-15 08:54:17 +02:00
Christoph Reiter
85d822b2e8 Fix various compiler warnings with the 64bit mingw build
Use better matching format modifiers/specifiers, initialise some things
which in theory wont be written to because of getters using g_return_if_fail(),
a cast, and gsize as input for malloc because gsize!=glong on 64bit Windows.
2020-06-14 20:02:36 +02:00
Emmanuel Gil Peyrot
404d79153e Switch to GL_ARB_framebuffer_object
GTK 4.0 was currently using GL_EXT_framebuffer_object, which is
deprecated as the ARB version has been merged into OpenGL 3.0 as well as
OpenGL ES 2.0, and provides laxer requirements.

This is a port of !2076 for 4.x.
2020-06-12 15:08:44 +02:00
Matthias Clasen
4b241f8da2 Merge branch 'scroll-compression' into 'master'
gdk: Compress scroll events

Closes #2800

See merge request GNOME/gtk!2066
2020-06-10 14:35:01 +00:00
Matthias Clasen
2c82151d65 gdk: Drop axis labels
This was only ever implemented on X11, and the labels
here were atom names, so unlikely to be useful for
anything interesting.
2020-06-10 07:36:30 -04:00