Commit Graph

157 Commits

Author SHA1 Message Date
Christian Hergert
056e9012d2 macos: improve monitor detection at display coordinates
This needs to handle the boundary case where the value is exactly equal
to the edge of a rectangle (which gdk_rectangle_contains_point() does not
consider to be containing). However, if there is a monitor in the list
that is a better match, we still want to prefer it.
2022-02-15 12:38:07 -08:00
Andy Russell
37702af22b
gdk: fix reversed and sluggish scrolling on MacOS
When using an external mouse on MacOS, the scrolling behavior is
reversed from the user's scrolling preference. Additionally, it is
noticeably sluggish.

This commit fixes both issues by negating the deltas and multiplying
them by 32 before constructing a new scroll event. 32 seems to be the
"traditional" scaling factor according to [Druid], but I'm not sure
where that value actually comes from. Regardless, scaling the deltas by
this amount makes scrolling feel a lot more responsive in the GTK demos.

Scrolling with a trackpad is not affected by either issue because it
triggers a different code path that uses more precise deltas, and
already negates them.

[Druid]: https://linebender.gitbook.io/linebender-graphics-wiki/mouse-wheel#external-mouse-wheel-vs-trackpad
2022-02-14 14:05:39 -05:00
Bilal Elmoussaoui
f41cfd3caa macos: Don't set NULL as a display name
Other GDK backends ensure there is always a default name set.
Fixes https://github.com/gtk-rs/gtk4-rs/issues/868
2022-02-08 13:38:33 +01:00
Matthias Clasen
59eb9aeb73 Merge branch 'wip/chergert/macos-fixes' into 'main'
various macOS fixes

See merge request GNOME/gtk!4424
2022-02-07 23:56:40 +00:00
Mosè Giordano
2ceba0d31c Include gdk-private.h to fix error about g_source_set_static_name
Without this change we get the following error:

```
[1/13] Compiling C object gdk/macos/libgdk-macos.a.p/gdkdisplaylinksource.c.o
ninja: job failed: /opt/bin/aarch64-apple-darwin20-libgfortran5-cxx11/aarch64-apple-darwin20-clang -Igdk/macos/libgdk-macos.a.p -Igdk/macos -I../gdk/macos -I. -I.. -Igdk -I../gdk -Isubprojects/pango/pango -I../subprojects/pango/pango -Isubprojects/pango -I../subprojects/pango -I/workspace/destdir/include/gdk-pixbuf-2.0 -I/workspace/destdir/include -I/workspace/destdir/include/glib-2.0 -I/workspace/destdir/lib/glib-2.0/include -I/workspace/destdir/lib/libffi-3.2.1/include -I/workspace/destdir/include/libpng16 -I/usr/include/libmount -I/usr/include/blkid -I/workspace/destdir/include/cairo -I/workspace/destdir/include/pixman-1 -I/workspace/destdir/include/freetype2 -I/workspace/destdir/include/fribidi -I/workspace/destdir/include/harfbuzz -I/workspace/destdir/include/graphene-1.0 -I/workspace/destdir/lib/graphene-1.0/include -I/workspace/destdir/include/gio-unix-2.0 -fcolor-diagnostics -Wall -Winvalid-pch -std=gnu99 -O2 -g -DG_LOG_USE_STRUCTURED=1 -DGLIB_DISABLE_DEPRECATION_WARNINGS '-DGTK_VERSION="4.6.0"' -D_GNU_SOURCE -DG_ENABLE_DEBUG -DGTK_COMPILATION '-DG_LOG_DOMAIN="Gdk"' -xobjective-c -fno-strict-aliasing -Wno-c++11-extensions -Wno-missing-include-dirs -Wno-typedef-redefinition -Wformat=2 -Wformat-nonliteral -Wformat-security -Wignored-qualifiers -Wimplicit-function-declaration -Wmisleading-indentation -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn -Wnested-externs -Wold-style-definition -Wpointer-arith -Wshadow -Wstrict-prototypes -Wswitch-default -Wswitch-enum -Wundef -Wuninitialized -Wunused -Werror=address -Werror=array-bounds -Werror=empty-body -Werror=implicit -Werror=implicit-fallthrough -Werror=init-self -Werror=int-to-pointer-cast -Werror=main -Werror=missing-braces -Werror=missing-declarations -Werror=missing-prototypes -Werror=nonnull -Werror=pointer-to-int-cast -Werror=redundant-decls -Werror=return-type -Werror=sequence-point -Werror=trigraphs -Werror=vla -Werror=write-strings -Wnull-dereference -fvisibility=hidden -MD -MQ gdk/macos/libgdk-macos.a.p/gdkdisplaylinksource.c.o -MF gdk/macos/libgdk-macos.a.p/gdkdisplaylinksource.c.o.d -o gdk/macos/libgdk-macos.a.p/gdkdisplaylinksource.c.o -c ../gdk/macos/gdkdisplaylinksource.c
../gdk/macos/gdkdisplaylinksource.c:201:3: error: implicit declaration of function 'g_source_set_static_name' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
  g_source_set_static_name (source, "[gdk] quartz frame clock");
  ^
1 error generated.
ninja: subcommand failed
```
2022-02-05 21:51:40 +00:00
Christian Hergert
95168e179c macos: fallback to conversion on WCG colorspace
We don't want to risk having something really weird come out if we have a
WCG colorspace, so instead only do the performance hack on systems where
the output is likely reasonable.

We will want to eventually just be drawing in the appropriate colorspace,
but that is not available yet.
2022-02-05 12:42:57 -08:00
Christian Hergert
2be51dc3b1 macos: handle sizing changes when switching monitors
This should make sure that our scales are updated as well as
ensuring we repaint the whole surface.
2022-02-04 12:29:57 -08:00
Christian Hergert
6b85d501f0 macos: assume monitor colorspace when drawing
When using software rendering w/ cairo, assume we're drawing in
the best-monitor's colorspace rather than RGB to avoid colorspace
conversions on every frame.
2022-02-04 09:46:10 -08:00
Christian Hergert
473aceea68 macos: add API to get monitor colorspace 2022-02-04 09:45:55 -08:00
Christian Hergert
8ea0a4fc50 macos: precalculate clip regions as CGRect
We can make our drawRect do less work if we precalculate the clip
and damage regions upfront by intersecting them with the bounds.
2022-02-04 09:31:37 -08:00
Christian Hergert
8112b49c36 macos: fix unmaximize opacity around edges of window 2022-02-03 19:26:16 -08:00
Christian Hergert
58b9c3a6d4 macos: use CGContext to draw cairo surfaces
Instead of relying on cairo_t to perform drawing from our backing
image surface to the Core Graphics context, we can convert the
cairo_image_surface_t into a CGImageRef without having to copy
data if we are certain of the alignment of the image up front.

Without this, there are many situations, based on the size of the
window that could cause cairo to take a slow path and malloc/copy
the data to ensure that alignment.

The previous commit titled "macos: align image surface rowstride to
16-bytes" ensures that this invariant is true so that our drawing
code can assume we can reference the framebuffer from the
cairo_image_surface_t using a CGDataProvider.

Since GdkMacosCairoContext and GdkMacosCairoSubview are coordinating,
we can also setup the transformation/scale early when drawing the
cairo_image_surface_t instead of when copying it to Core Graphics.

Furthermore, the CGImageRef is created with an RGB colorspace so
that we are not performing colorspace conversion to the output
device. We don't get color matching between displays, but we don't
expect that anyway, particularly with the software renderer.
2022-02-03 19:26:16 -08:00
Christian Hergert
4373743d4c macos: align image surface rowstride to 16-bytes
When creating a cairo_image_surface_t we want both the framebuffer pointer
and each row to be aligned to 16-bytes so that Core Graphics will use more
optimal paths.

However, cairo_image_surface_create() will not guarantee that the rowstride
is aligned to 16-bytes so we must do that ourselves.
2022-02-03 19:26:16 -08:00
Christian Hergert
58159552ba macos: avoid unnecessarily destroying cairo_t
This avoids destroying a cairo_t when we are within the frame as it
otherwise causes the surface to unnecessarily flush.
2022-02-03 19:26:16 -08:00
Christian Hergert
4bff24f83a macos: cleanup window surface when destroying context
Make sure we release the cairo_surface_t for the window when
disposing the GdkMacosCairoContext.
2022-02-03 19:26:16 -08:00
Christian Hergert
f644925570 macos: be more careful about freezing/thawing surfaces
We need to avoid conflating the managing of frame callbacks from
the freeze/thaw mechanics and ensure we don't perform extra thaw
requests at the wrong time.
2022-02-03 19:26:16 -08:00
Christian Hergert
8a4fd3f2af macos: check for destroyed surfaces in vfuncs 2022-02-03 19:26:16 -08:00
Christian Hergert
b7130a1ce3 macos: be more defensive about freezing updates
We only need to freeze the updates if we weren't in the queue already.
That should be the case, but just better to be defensive here.
2022-02-03 19:26:16 -08:00
Christian Hergert
519a44d224 macos: push to head of awaiting frames
Always add to the head of awaiting frames as the list is processed
in the opposite direction.
2022-02-03 19:26:16 -08:00
Christian Hergert
936034e07a macos: remove popup surface from parent 2022-02-03 19:26:16 -08:00
Christian Hergert
ea43939f52 macos: handle NULL frame-clock when thawing 2022-02-03 19:26:16 -08:00
Matthias Clasen
2772ff624f gdk: Prepare touchpad events for sequences
It makes sense to connect the begin/update/end events
for touchpad swipes and pinches in a sequence. This
commit adds the plumbing for it, but not backends
are setting sequences yet.
2021-12-15 21:58:57 -05:00
Benjamin Otte
6536e3dc54 macos: Fix return value 2021-11-03 22:53:59 +01:00
Matthias Clasen
d7d4cef66d Merge branch 'wip/chergert/use-fabs-in-macos' into 'master'
macos: fix scale on macOS 12 beta

See merge request GNOME/gtk!4065
2021-10-27 19:37:01 +00:00
Emmanuele Bassi
82c0654f76 Merge branch 'fix-mac-kana-eisu' into 'master'
Correct translation of Mac JIS Eisu & Kana keys

Closes #4117

See merge request GNOME/gtk!3782
2021-10-22 15:05:29 +00:00
Matthias Clasen
bddf9f9ca3 docs: Cosmetics
Do a round of "the the" removal.
2021-10-18 08:35:54 -04:00
Christian Hergert
e3ef21f770 macos: fix scale on macOS 12 beta
This is a port of the fix in the quartz backend to the new macOS backend.

From the original commit:

In macOS-12.sdk CGContextConverSizeToDeviceSpace returns a negative
height and passing that to CGContextScaleCTM in turn causes the cairo
surface to draw outside the window where it can't be seen. Passing the
absolute values of the scale factors fixes the display on macOS 12 without
affecting earlier macOS versions.
2021-10-14 14:46:30 -07:00
Benjamin Otte
f584d4f500 gl: Check allowed APIs in realize()
Add gdk_gl_context_is_api_allowed() for backends and make them use it.

Finally, have them return the final API as the return value (or 0 on
error).

And then use that api instead of a use_es boolean flag.

Fixes #4221
2021-10-08 03:31:07 +02:00
Benjamin Otte
dc6e831524 gdk: hdr => high depth
The term "hdr" is so overloaded, we shouldn't use them anywhere, except
from maybe describing all of this work in blog posts and other marketing
materials.

So do renames:
* hdr => high_depth
* request_hdr => prefers_high_depth

This more accurately describes what is going on.
2021-10-06 22:50:07 +02:00
Benjamin Otte
7ede468849 gdk: Add a request_hdr argument to begin_frame()
It's not used by anyone, it's just there.

gdk_draw_context_begin_frame_full() has been added so renderers can
make use of it.
2021-10-06 03:44:58 +02:00
Christian Hergert
e77eaa0ace macos: handle NULL surface when creating GL context
Fixes #4279
2021-09-28 17:36:23 -07:00
Benjamin Otte
4e836493cc macos: Don't include gdkinternals.h 2021-09-24 22:50:29 +02:00
Benjamin Otte
d61c71c378 macos: Actually set the vfuncs 2021-09-24 22:11:57 +02:00
Benjamin Otte
23acc993cc gdk: Make sure only one GL backend is used
Creative people managed to create an X11 display and a Wayland display
at once, thereby getting EGL and GLX involved in a fight to the death
over the ownership of the glFoo() symbolspace.

A way to force such a fight with available tools here is (on Wayland)
running something like:
GTK_INSPECTOR_DISPLAY=:1 GTK_DEBUG=interactive gtk4-demo

Related: xdg-desktop-portal-gnome#5
2021-09-24 01:59:37 +02:00
Peter Bloomfield
9eb8aa9a32 gdkmacoseventsource: Include "gdk-private.h"
_gdk_macos_event_source_new() calls g_source_set_static_name(), which
for GLib versions before 2.69.1 is a macro defined in gdk-private.h.

Fixes #4195

modified:   gdk/macos/gdkmacoseventsource.c
2021-08-24 16:55:52 -04:00
Matthias Clasen
19b534f7de Avoid copying static debug strings
The g_source_set_name calls were showing up as a
major source of strdups in our profiles. Avoid that
by using new GLib api when available.
2021-07-28 22:42:46 -04:00
Benjamin Otte
f5dc71021f dnd: Guard drags with a reference when finishing
Usually the "dnd-finished" signal will be used to unref the GdkDrag. In
those cases, we would lose the object, so that when we do the final
drag_drop_done() afterwards, we wouldn't have a remaining reference.

With the reference guard, this now works.
2021-07-26 02:18:54 +02:00
gsittyz
bd7b8e87c1 Correct translation of Mac JIS Eisu & Kana keys
Since UCKeyTranslate() converts these keys to Space key unexpectedly,
applications can't distinguish these keys by keysyms.
To solve it, this fix translates these keys by the same way with
function keys & keypad keys.
This patch is equivalent to the patch proposed in:
https://bugzilla.gnome.org/show_bug.cgi?id=702841

Closes #4117
2021-07-24 20:59:18 +09:00
Benjamin Otte
e06e0e8555 gdk: Move GL context construction to GdkGLContext
Now that we have the display's context to hook into, we can use it to
construct other GL contexts and don't need a GdkSurface vfunc anymore.

This has the added benefit that backends can have different GdkGLContext
classes on the display and get new GLContexts generated from them, so
we get multiple GL backend support per GDK backend for free.

I originally wanted to make this a vfunc on GdkGLContextClass, but
it turns out all the abckends would just call g_object_new() anyway.
2021-07-22 16:27:32 +02:00
Benjamin Otte
9f1d6e1f44 gl: Move vfunc
Instead of
  Display::make_gl_context_current()
we now have
  GLContext::clear_current()
  GLContext::make_current()

This fits better with the backends (we can actually implement
clearCurrent on macOS now) and makes it easier to implement different GL
backends for backends (like EGL/GLX on X11).

We also pass a surfaceless boolean to make_current() so the calling code
can decide if a surface needs to be bound or not, because the backends
were all doing whatever, which was very counterproductive.
2021-07-22 16:27:32 +02:00
Benjamin Otte
505436340b gdk: Get rid of paint contexts
... or more exactly: Only use paint contexts with
gdk_cairo_draw_from_gl().

Instead of paint contexts being the only contexts who call swapBuffer(),
any context can be used for this, when it's used with
begin_frame()/end_frame().

This removes 2 features:

1. We no longer need a big sharing hierarchy. All contexts are now
   shared with gdk_display_get_gl_context().
2. There is no longer a difference between attached and non-attached
   contexts. All contexts work the same way.
2021-07-22 16:27:31 +02:00
Benjamin Otte
430b6f8fb1 gdk: Add GdkDisplay::init_gl vfunc
The vfunc is called to initialize GL and it returns a "base" context
that GDK then uses as the context all others are shared with. So the GL
context share tree now looks like:

+ context from init_gl
  - context1
  - context2
  ...

So this is a flat tree now, the complexity is gone.

The only caveat is that backends now need to create a GL context when
initializing GL so some refactoring was needed.

Two new functions have been added:

* gdk_display_prepare_gl()
  This is public API and can be used to ensure that GL has been
  initialized or if not, retrieve an error to display (or debug-print).
* gdk_display_get_gl_context()
  This is a private function to retrieve the base context from
  init_gl(). It replaces gdk_surface_get_shared_data_context().
2021-07-22 16:23:56 +02:00
Matthias Clasen
92177d9663 Merge branch 'wip/chergert/gdk-macos-gdkdrop' into 'master'
GdkDrop suport for macOS backend

See merge request GNOME/gtk!3683
2021-06-24 15:03:19 +00:00
Christian Hergert
3fd931d392 macos: implement GdkDrop for macOS
This gets the basic mechanics of the drop portion of DnD working on the
macOS backend. You can drag, for example, from TextEdit into GNOME
Text Editor when using the macOS backend.

Other content formats are supported, and match what is currently
supported by the clipboard backend as the implementation to read
from the pasteboard is shared.

Currently, we look up the GdkDrag for the new GdkDrop. However,
nothing is stashing the drag away for further lookup. More work is
needed on GdkMacosDrag for that to be doable.
2021-06-17 17:26:42 -07:00
Christian Hergert
6c1dce2878 macos: make pasteboard usage reusable
We will want to be able to reuse the pasteboard reading code from
the macOS DnD drop backend. This just removes the pasteboard
bits from the implementation and allows that to be passed in as in
both clipboard and DnD cases we'll have a specific NSPasteboard
to read from.
2021-06-17 17:19:19 -07:00
Christian Hergert
ad1260505d macos: check for GdkMacosBaseView before using as such
We can get events for external windows such as those from native
file chooser dialogs.
2021-06-17 17:18:19 -07:00
Matthias Clasen
22827f2cc7 macos: Fix a compiler warning 2021-06-17 17:14:14 -07:00
Christian Hergert
b64370cd48 macos: move drag motion to GdkMacosDrag
This doesn't help to be pushed off into the surface, as it makes things
more different than the X11 implementation.
2021-06-17 13:24:39 -07:00
Christian Hergert
6c8e176cc0 macos: fix position of drag surface 2021-06-17 13:23:38 -07:00
Christian Hergert
057bda6cd7 macos: register known clipboard types for drag destination 2021-06-17 13:23:18 -07:00