Compare commits

...

488 Commits

Author SHA1 Message Date
Emmanuele Bassi
99cfaf622d Make GtkPasswordEntry a true final type
Use G_DECLARE_FINAL_TYPE in the header, and G_DEFINE_FINAL_TYPE in the
source.
2022-03-16 14:38:24 +00:00
Emmanuele Bassi
80617f01c3 Use G_DEFINE_FINAL_TYPE for final types
If we're using G_DECLARE_FINAL_TYPE in the header, we should use
G_DEFINE_FINAL_TYPE in the source.
2022-03-16 14:35:32 +00:00
Emmanuele Bassi
33085457a7 Require GLib 2.70
We are going to use G_DEFINE_FINAL_TYPE and friends.
2022-03-16 14:10:40 +00:00
Matthias Clasen
df593ee651 Merge branch 'wip/carlosg/im-text-location' into 'main'
gtkimcontextwayland: Add native surface offset to input coordinates

Closes #4668

See merge request GNOME/gtk!4573
2022-03-16 11:54:26 +00:00
Carlos Garnacho
4dcd011486 gtkimcontextwayland: Add native surface offset to input coordinates
We were missing the surface offset (e.g. shadows) at the time of expressing
the text caret location in surface coordinates. Add this offset so the
coordinates are as expected by the compositor.

Fixes: https://gitlab.gnome.org/GNOME/gtk/-/issues/4668
2022-03-16 09:57:42 +01:00
Matthias Clasen
6fe7e373e2 Merge branch 'gtk/gss-search-delay' into 'main'
searchentry: Make search delay editable

Closes #4133

See merge request GNOME/gtk!4563
2022-03-15 22:40:54 +00:00
Ondřej Míchal
0c3583b4bd searchentry: Make search delay editable
The default search delay of 150ms can be too low at times[0], leading app
developers to add additional delay while handling the search-changed
signal[1].

Based on past work from hugsie[2].

Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/4133

[0] https://github.com/getting-things-gnome/gtg/issues/281
[1] https://github.com/getting-things-gnome/gtg/pull/587
[2] https://gitlab.gnome.org/GNOME/gtk/-/issues/678
2022-03-15 23:55:10 +02:00
Kjartan Maraas
5bd0179a88 Update Norwegian Bokmål translation
(cherry picked from commit 72a557087c)
2022-03-15 15:26:58 +00:00
Matthias Clasen
f116efd48e Merge branch 'main' into 'main'
gtkplacessidebar: Prevent calling g_object_unref on null

See merge request GNOME/gtk!4569
2022-03-15 14:37:14 +00:00
Matthias Clasen
8057bee295 Apply 1 suggestion(s) to 1 file(s) 2022-03-15 14:35:09 +00:00
Matthias Clasen
ab330f1efc Merge branch 'wip/jimmac/symbolics-gnome-42-sync' into 'main'
icons: update symbolics

See merge request GNOME/gtk!4571
2022-03-15 14:29:27 +00:00
Matthias Clasen
eaf4fb68f3 Merge branch 'avoid-objcopy-on-arm' into 'main'
build: Avoid objcopy on arm

Closes #4757, #4748, and #4752

See merge request GNOME/gtk!4567
2022-03-15 13:08:53 +00:00
Jakub Steiner
bfe193e6e2 icons: update symbolics
- match the metaphors/style updates of gnome 42

See https://gitlab.gnome.org/GNOME/gtk/-/issues/4764
2022-03-15 08:31:26 +01:00
Мирослав Николић
aa8dec3d27 Update Serbian translation
(cherry picked from commit b59f9b97f3)
2022-03-15 06:33:46 +00:00
Matthias Clasen
d2e7060150 Merge branch 'builder-tool-nodisplay' into 'main'
gtk-builder-tool: Operate without display

See merge request GNOME/gtk!4568
2022-03-14 22:15:11 +00:00
Fina Wilke
08f3acb534 gtkplacessidebar: Prevent calling g_object_unref on null
g_object_unref would be called on a null end_icon when provider_account_status
is CLOUD_PROVIDERS_ACCOUNT_STATUS_IDLE
2022-03-14 22:33:35 +01:00
Matthias Clasen
525f96f2f8 gtk-builder-tool: Operate without display
The simplify and validate commands can function
without a display connection, only preview absolutely
needs one. Allow this, by using gtk_init_check().
2022-03-14 15:40:12 -04:00
Matthias Clasen
b6b2682bd6 build: Avoid objcopy on arm
The trickery we do with objcopy and ld to speed up
resource inclusion does not seem to work right on
32bit Arm, so just skip it there.

Fixes: #4757, #4748, #4752
2022-03-14 08:44:09 -04:00
Christian Kirbach
1832964188 Update German translation
(cherry picked from commit a1f4735652)
2022-03-13 22:09:17 +00:00
Matthias Clasen
eb599653e6 Merge branch 'wip/lantw/build-Don't-use-ld-and-objcopy-when-cross-compiling' into 'main'
build: Don't use ld and objcopy when cross-compiling

See merge request GNOME/gtk!4565
2022-03-13 14:31:23 +00:00
Ting-Wei Lan
e1e88ce665 build: Don't use ld and objcopy when cross-compiling
These commands don't work when compiling Windows binaries on Linux.
2022-03-13 15:19:46 +08:00
Balázs Úr
66d21689bc Update Hungarian translation 2022-03-13 00:23:04 +00:00
Matthias Clasen
8186cb8bee Merge branch 'wip/chergert/for-main' into 'main'
macos: fit'n'finish fixes for main

See merge request GNOME/gtk!4564
2022-03-12 19:07:41 +00:00
Baurzhan Muftakhidinov
9b8f28903b Update Kazakh translation
(cherry picked from commit 6ac723321f)
2022-03-12 13:23:41 +00:00
Anders Jonsson
1cd42825c2 Update Swedish translation
(cherry picked from commit 343b08f3e6)
2022-03-12 11:39:33 +00:00
Christian Hergert
166444f115 macos: exclude popups from window list
This probably only matters if you do window list integration for the global
menu on macOS.
2022-03-11 22:36:26 -08:00
Christian Hergert
3cd68c5de5 macos: pass events to foreign windows 2022-03-11 18:25:47 -08:00
Christian Hergert
9e2357d5f3 macos: clear sorted surfaces when showing file chooser
When showing the native file chooser, we need to ensure we clear the
sorted surfaces in the display so that we don't risk delivering events
correctly on the next frame.
2022-03-11 18:19:44 -08:00
Christian Hergert
bd0c68f641 macos: dont steal key window from NSPanel
Or we risk making it really difficult to use native file choosers.
2022-03-11 18:07:34 -08:00
Christian Hergert
c3a7d79154 macos: fix window level for popups
This comment isn't really accurate anymore it seems, so we can start
setting the proper stacking order for popups now.
2022-03-11 18:01:05 -08:00
Christian Hergert
25624083dd macos: fix attachment of popups to parents
We had code to do it and it never actually got used correctly. This ensures
that the popup services are attached to the parents so that they get proper
stacking orders when displayed. Additionally, it fixes popups from being
shown as their own windows in Exposé.
2022-03-11 17:53:42 -08:00
Christian Hergert
407b5246a6 macos: fix window activation during shadow click-through
If we are clicking through the shadow of a window, we need to take special
care to not raise the old window on mouseUp. This is normally done by the
display server for us, so we need to use the proper API that is public to
handle this (rather than CGSSetWindowTags()). Doing so requires us to
dispatch the event to the NSView and then cancel the activcation from
the mouseDown: event there.
2022-03-11 14:44:07 -08:00
Christian Hergert
6bedcf22bc macos: select new key window after processing events
If we closed a key window in response to events, we need to denote another
window as the new key window. This is easiest to do from an idle so that
we don't clobber notification pairs of "did resign"/"did become" key
window.

We have a sorted set of surfaces by display server stacking, so we can
take the first one we come across that is already mapped and re-show it
to become key/main.
2022-03-11 14:44:06 -08:00
Christian Hergert
eeb9d6c398 macos: request layout with server-side decoration
If we have server-side decorations we might need to request a layout in
response to the resize notification. We don't need to do this in other
cases because we already handle that in the process of doing the resize
(and that code is that way because of delayed delivery of NSNotification).
2022-03-11 14:44:06 -08:00
Christian Hergert
cf8d2374c5 macos: fix resize when using server-side decorations
If we are using NSWindow titled windows, we don't end up waking up the
frame clock when the window is resized on the display server. This ensures
that we do that after getting a notification of resize.
2022-03-11 14:44:06 -08:00
Christian Hergert
9fa5378d83 macos: set main window in addition to key
If we are showing the window, we might also want to make it the main
window for the application when shown.
2022-03-11 14:44:06 -08:00
Dušan Kazik
90352d760d Update Slovak translation
(cherry picked from commit c8d1f23ff5)
2022-03-11 07:44:15 +00:00
Balázs Úr
c3c1763a9f Update Hungarian translation 2022-03-11 01:09:19 +00:00
Matthias Clasen
9f7c9ce6ad Merge branch 'better-format-conversions' into 'main'
gdk: Clean up the optimised premultiply conversion function

See merge request GNOME/gtk!4550
2022-03-10 19:26:25 +00:00
Matthias Clasen
1f155bf39a Merge branch 'wlprotocols-dependency-correctness' into 'main'
meson: use proper handling of wayland-protocols dependency

See merge request GNOME/gtk!4561
2022-03-10 19:15:39 +00:00
Christian Hergert
84014e3414 macos: make transient-for key window when hiding surface
This only handled the popover case before and not the transient-for case.
2022-03-10 08:04:14 -08:00
Christian Hergert
4ced1c90f1 macos: actually drop unnecessary momentum events
These would get passed along to the NSApplication which we don't really
need to have happen. Denote it as such.
2022-03-10 03:21:12 -08:00
Christian Hergert
54c3b947fc macos: queue all pending events
Rather than process these a single event at a time, queue all of the
outstanding events from the NSEvent queue.
2022-03-10 03:20:07 -08:00
Eli Schwartz
94007caf8d meson: use proper handling of wayland-protocols dependency
Ensure that resolution of the subproject occurs via the dependency
interface, not the "poke at subprojects manually" interface, and make
that actually work via --wrap-mode=forcefallback.

There's no need to mark it as not-required and then manually invoke
subproject(), since fallback should work correctly and it is always
needed.

However, if fallback was performed (or forced) it would error out since
get_variable() was instructed to only use pkg-config while the relevant
variable was exported by the subproject as an internal fallback
dependency.
2022-03-10 00:08:36 -05:00
Matthias Clasen
675c8b45b1 Merge branch 'wip/jimmac/legacy-icons-gtk4' into 'main'
icons: add missing legacy fullcolor

See merge request GNOME/gtk!4558
2022-03-09 23:37:26 +00:00
Christian Hergert
ea59d174a0 macos: drop enter/exit when in manual drag/resize
If we are in a manual resize/drag then we don't want to generate crossing
events as they can just confuse things.
2022-03-09 13:20:53 -08:00
Christian Hergert
32935d9fb0 macos: allow dropping NSEvent without propagation
There are cases we might want to consume a NSEvent without creating a
GdkEvent or passing it along to the NSApplication for processing. This
creates a new value we can use and check against to propagate that without
having to do out parameters at the slightly odd invalid pointer value for
a GdkEvent (similar to how MMAP_FAILED is done).
2022-03-09 13:19:22 -08:00
Christian Hergert
b390e1da4f macos: do not focus new window when resigning main
This can get in the way of how we track changes while events are actively
processing. Instead, we may want to delay this until the next main loop
idle and then check to see if we have a main window as the NSNotification
may have come in right after this.
2022-03-09 12:33:46 -08:00
Jiri Grönroos
cccd1147e7 Update Finnish translation
(cherry picked from commit d188c6dbaf)
2022-03-09 19:03:58 +00:00
Emmanuele Bassi
d8db5f3217 Merge branch 'fix_gtk_accessible_update_relation_example' into 'main'
fix docs for gtk_accessible_update_relation example

See merge request GNOME/gtk!4559
2022-03-09 18:22:54 +00:00
Marek Černocký
f5bb364bb5 Fixed Czech translation 2022-03-09 19:06:22 +01:00
Caolán McNamara
20c41dce80 fix docs for gtk_accessible_update_relation example 2022-03-09 16:24:47 +00:00
Jakub Steiner
a9de385ac5 icons: add missing legacy fullcolor
- relied on in testsuite

See https://gitlab.gnome.org/GNOME/gtk/-/issues/4754
2022-03-09 16:19:16 +01:00
Anders Jonsson
ead210c170 Update Swedish translation
(cherry picked from commit 9053fd8335)
2022-03-09 10:50:11 +00:00
Matthias Clasen
2ad471542a Merge branch 'fix-focus-issues' into 'main'
Fix some focus issues

See merge request GNOME/gtk!4556
2022-03-08 19:37:45 +00:00
Danial Behzadi
d73cff5846 Update Persian translation
(cherry picked from commit a9720259f0)
2022-03-08 15:01:00 +00:00
Matthias Clasen
213376ee0a text: Stop blinking when we lose focus
We were looking at GtkWidget:has-focus from
event controller signal handlers here, but
the widget property is only changed after
the event controllers.
2022-03-08 06:06:47 -07:00
Matthias Clasen
1cc100415f focus controller: Update for active window
When the window gains or looses active status,
update the focus controllers status.
2022-03-08 06:06:47 -07:00
Matthias Clasen
d9ad7884e9 window: Update has-focus property
Update the :has-focus property of the focus
widget when the active status of the window
changes.

We change the property after generating the
GDK_CROSSING_ACTIVE crossing events.
2022-03-08 06:05:49 -07:00
Ask Hjorth Larsen
f545d7a910 Updated Danish translation 2022-03-08 01:28:14 +01:00
Ask Hjorth Larsen
206eb647a4 Updated Danish translation of gtk-properties 2022-03-08 01:28:11 +01:00
Aurimas Černius
00e637b480 Updated Lithuanian translation 2022-03-07 18:29:37 +02:00
Emmanuele Bassi
bfc8b7b7b6 Merge branch 'gdk-tests-naming' into 'main'
Use the correct name for installed gdk tests

See merge request GNOME/gtk!4555
2022-03-07 15:34:31 +00:00
Sebastien Bacher
c44288c739 Use the correct name for installed gdk tests 2022-03-07 16:13:38 +01:00
Luna Jernberg
2fb5104731 Update Swedish translation
(cherry picked from commit 89bba41fd7)
2022-03-07 08:09:54 +00:00
Matthias Clasen
0ae4d80766 Merge branch 'wip/chergert/for-main' into 'main'
macos: fixes for main

See merge request GNOME/gtk!4553
2022-03-06 01:36:13 +00:00
Christian Hergert
f5098e4fc5 macos: fix cursor blink time
The value from settings is for the duration of the blink period, not the
timeout. This fixes the blink lasting longer than 10 seconds.
2022-03-05 12:01:53 -08:00
Christian Hergert
28607f082c macos: require input region to become key
Some things cannot become key windows (like tooltips). We can use the
input_region existence to determine if we should allow it as a key window.
2022-03-05 11:58:43 -08:00
Matthias Clasen
f3968f2f1e Merge branch 'fix-doc-typo' into 'main'
Fix a documentation typo

Closes #4747

See merge request GNOME/gtk!4552
2022-03-05 05:50:10 +00:00
Matthias Clasen
88fa226223 Fix a documentation typo
It is XDG_DATA_HOME.

Fixes: #4747
2022-03-04 22:18:06 -07:00
Jordi Mas i Hernandez
c4c496a31c Update Catalan translation
(cherry picked from commit 2be2912e43)
2022-03-04 21:40:53 +00:00
Changwoo Ryu
c1eac4a421 Update Korean translation 2022-03-04 14:22:53 +00:00
Changwoo Ryu
b5d1323f49 Update Korean translation
(cherry picked from commit 2755ad19be)
2022-03-04 14:20:48 +00:00
Matthias Clasen
e297ac319d Merge branch 'fixup-shadernode-constructor' into 'main'
Fix up preconditions of gsk_gl_shader_node_new

Closes #4739

See merge request GNOME/gtk!4551
2022-03-04 06:06:35 +00:00
Matthias Clasen
bf852bea24 Fix up preconditions of gsk_gl_shader_node_new
These were not quite right, and implied that args
may be NULL, when it really can't.

Fixes: #4739
2022-03-03 22:40:10 -07:00
Matthias Clasen
a652507b7b Merge branch 'center-layout-setters' into 'main'
gtk: Have GtkCenterLayout hold a reference to its widgets

See merge request GNOME/gtk!4544
2022-03-03 19:38:28 +00:00
Jason Francis
4a2a76c231 gtk: Have GtkCenterLayout hold a reference to its widgets 2022-03-03 14:00:25 -05:00
Benjamin Otte
8cb7369b7a Merge branch 'wip/chergert/KHR_swap_buffers_with_damage' into 'main'
gdk: use EGL_KHR_swap_buffers_with_damage

See merge request GNOME/gtk!4548
2022-03-03 15:29:47 +00:00
Emmanuel Gil Peyrot
588076d166 gdk: Add a rgb8 → rgba8 conversion macro
This one can be used for both premultiplied and non-premultiplied alpha
formats, since alpha is always 255.  It is useful for opaque PNG upload
on both cairo and GL renderers.
2022-03-03 16:05:52 +01:00
Emmanuel Gil Peyrot
3a98b28ab7 gdk: Make the optimized premultiply function a macro
That way, all permutations are possible.  Previously it was only useful
in the cairo renderer, which required rgba8 → premultiplied bgra8, while
the GL renderer required rgba8 → premultiplied rgba8.  Now both are
available.
2022-03-03 16:04:45 +01:00
Emmanuel Gil Peyrot
cfeedcc321 gdk: Remove pixel format conversion ARM intrinsics
This was only useful when building for AArch32 without -mfpu=neon, on
AArch64 or with -mfpu=neon gcc is smart enough to do the auto-
vectorisation, leading to code almost as good as what I wrote in
1fdf5b7cf8.
2022-03-03 16:04:45 +01:00
Matthias Clasen
d0aedbc9fc Merge branch 'bilelmoussaoui/docs' into 'main'
headerbar: Fix docs

See merge request GNOME/gtk!4545
2022-03-03 14:11:25 +00:00
Changwoo Ryu
5557a528b6 Update Korean translation
(cherry picked from commit 156f99560d)
2022-03-03 12:46:55 +00:00
Christian Hergert
5316eb0c35 gdk: use EGL_KHR_swap_buffers_with_damage
It appears that NVIDIA does not implement EGL_EXT_swap_buffers_with_damage
on their EGL implementation, but does implement the KHR variant of it.
This checks for a suitable implementation and stores a pointer to the
compatible implementation within the GdkGLContextPrivate struct.
2022-03-03 01:22:01 -08:00
Bilal Elmoussaoui
e6afe28de5 headerbar: Fix docs 2022-03-03 08:36:33 +00:00
Matthias Clasen
eaf0353205 Merge branch 'wip/chergert/for-main' into 'main'
macos: various fixes

See merge request GNOME/gtk!4543
2022-03-02 13:37:06 +00:00
Carlos Garnacho
f9f9bd3f5b Merge branch 'xdg-activation-no-surface' into 'main'
wayland: xdg-activation: Don't assume there's a focus surface

See merge request GNOME/gtk!4366
2022-03-02 12:44:52 +00:00
Christian Hergert
ca79688f52 macos: clear window stack before requesting motion
We want to ensure that we recalculate the sort order of windows before
processing the motion. Generally this would be done in response from the
display server in GdkMacosWindow, but I've seen it possible to race there.
2022-03-02 01:04:53 -08:00
Christian Hergert
efa8f903c2 macos: invalidate surface contents when mapping 2022-03-02 00:48:06 -08:00
Christian Hergert
f7d0b91267 macos: move children when monitor changes
We can rely on other code to move monitors, but specifically with children
we want to try harder to move them as a group and keep positioning in tact.
2022-03-02 00:47:27 -08:00
Christian Hergert
ed4f0de2b0 macos: make move_resize possibly idempotent
We need to handle the case where we might be racing against an incoming
configure event due to how notifications are queued from the display
server. Rather than calling configure (and possibly causing other things
to move around) this just queries the display server directly for the
coordinates that we care about.

Additionally, we can display:NO as we are in control of all the display
process now using CALayer.
2022-03-02 00:45:44 -08:00
Christian Hergert
50b96dcdd5 macos: handle transient-for from configure
We failed to handle the toplevel with transient-for case here which could
cause our X/Y calculations to be off in other areas such as best monitor
detection.
2022-03-02 00:43:33 -08:00
Christian Hergert
cf25f2c04b macos: use parent frame clock again
We do actually need the parent frame clock here because it is the way we
ensure that we get layout called for our popup surfaces at the same time
as the parent surface.
2022-03-02 00:42:09 -08:00
Christian Hergert
ddf07ffe22 macos: reduce chances for layout cycles
We need to be more careful about when we request a layout because it can
cause us to get into a layout cycle at maximum frame rate.
2022-03-02 00:40:21 -08:00
Christian Hergert
82f1eaacc9 macos: improve initial placement of toplevels with parent
This doesn't appear to happen much, but if it does it is nice to setup
the window placement initially. Generally, transient-for is set after
the creation of the toplevel rather than here.
2022-03-02 00:38:39 -08:00
Christian Hergert
4cdb07fa02 macos: leave a note about monitor configuration
It can be helpful to see what the range of monitor values is when emulating
the GDK coordinate system.
2022-03-02 00:37:07 -08:00
Christian Hergert
bdd5393084 macos: use GdkMacosBuffer for storing damage region
The GdkMacosBuffer object already has storage for tracking the damage
region as it is used in GdkMacosCairoContext to manually copy regions from
the front buffer to the back buffer. This makes the GdkMacosGLContext also
use that field so that we can easily drop old damage regions when the
buffer is lost. This happens during resizes, monitor changes, etc.
2022-03-02 00:36:17 -08:00
Christian Hergert
27b87ebec5 macos: add clamp helper to keep rectangle in workarea
This helper is useful to ensure we are consistent with how we keep a
window clamped to the workarea of a monitor when placing windows on
screen. (This does not affect snap-to-edges).
2022-03-02 00:34:27 -08:00
Christian Hergert
8c0df66d5f macos: style cleanup 2022-03-02 00:33:13 -08:00
Christian Hergert
e5238bf54f macos: add re-entrancy check when monitors change 2022-03-02 00:32:50 -08:00
Christian Hergert
e9abcde031 macos: check for best_monitor before using
Make sure we have a monitor to enqueue/dequeue from before using it. That
also allows us to use this from destroy and what-not.
2022-03-02 00:32:07 -08:00
Goran Vidović
d45281e6c7 Update Croatian translation
(cherry picked from commit 4eee322654)
2022-03-01 13:05:13 +00:00
Goran Vidović
3fd5ebffcb Update Croatian translation
(cherry picked from commit 67ae05d855)
2022-03-01 12:54:18 +00:00
Carlos Garnacho
88a621fa13 Merge branch 'wip/carlosg/focus-request-over-xdg-activation' into 'main'
wayland: Use xdg-activation for non-startup initiated focus requests

See merge request GNOME/gtk!4535
2022-03-01 11:21:12 +00:00
Marek Černocký
ce4b799f1e Updated Czech translation 2022-03-01 12:08:18 +01:00
Carlos Garnacho
4dcacff312 wayland: Use xdg-activation for non-startup initiated focus requests
Currently, we have all the plumbing in place so that GTK consumes the
startup notification ID when focusing a window through the xdg-activation
protocol.

This however misses the case that a window might be requested to be
focused with no startup ID (i.e. via interaction with the application,
not through GApplication or other application launching logic).

In this case, we let the application create a token that will be
consumed by itself. The serial used is that from the last
interaction, so the compositor will still be able to do focus prevention
logic if it applies.

Since we already do have a last serial at hand, prefer xdg-activation
all the way over the now stale gtk-shell focusing support. The timestamp
argument becomes unused, but that is a weak argument to prefer the
private protocol over the standard one. The gtk-shell protocol support
is so far left for interaction with older Mutter.
2022-03-01 11:38:51 +01:00
Matthias Clasen
fd7667246d Merge branch 'wip/chergert/for-main' into 'main'
macos: various fixes and multi-monitor frame clocks

Closes #4736, #4735, #4732, #4733, and #4734

See merge request GNOME/gtk!4533
2022-02-28 22:13:03 +00:00
Matthias Clasen
b8cb15f28d Merge branch 'wip/carlosg/scrolledwindow-warning' into 'main'
gtkscrolledwindow: Do not try to doubly trigger deceleration

Closes #4730

See merge request GNOME/gtk!4536
2022-02-28 21:50:19 +00:00
Christian Hergert
51607ce93c macos: avoid size/origin changes when possible
If _gdk_macos_surface_move_resize() was called with various -1 parameters
we really want to avoid changing anything even if we think we know what
the value might be. Otherwise, we risk messing up in-flight operations that
we have not yet been notified of yet.

This improves the chances we place windows in an appropriate location as
they don't et screwed up before window-manager placement.
2022-02-28 13:09:57 -08:00
Christian Hergert
66284cd245 macos: start application in foreground
We need to bring the application to the foreground in multiple ways, and
this call to [NSApp activateIgnoringOtherApps:YES] ensures that we become
foreground before the first window is opened. Otherwise we end up starting
applications in the background.

Fixes #4736
2022-02-28 12:20:24 -08:00
Christian Hergert
f9faecd5b7 macos: add GDK_NOTE when surface changes monitor 2022-02-28 12:13:29 -08:00
Christian Hergert
92261b5022 macos: add GDK_NOTE for surface sizing and placement
This can be useful to debug sizing issues with the surface as well as the
"window manager" placement code.
2022-02-28 11:50:21 -08:00
Christian Hergert
91f5bfd211 macos: leave note about monitor discovery 2022-02-28 11:36:27 -08:00
Christian Hergert
63f20b173d macos: external access to display name helpers
These can be handy to print debug information when we don't have a
GdkMacosMonitor to work with.
2022-02-28 11:36:27 -08:00
Christian Hergert
25b3bd64af macos: fix redisplay of GdkPopup
This broke recently during the configure cleanups and also needed to have
the tail directions fixed again.
2022-02-28 11:36:27 -08:00
Christian Hergert
fc4d36e50a macos: fix cairo renderer with double buffering
If we are double buffering surfaces with IOSurface then we need to copy
the area that was damaged in the previous frame to the back buffer. This
can be done with IOSurface but we need to hold the read-only lock so that
we don't cause the underlying IOSurface contents to be invalidated.

Additionally, since this is only used in the context of rendering to a
GdkMacosSurface, we know the life-time of the cairo_surface_t and can
simply lock/unlock the IOSurface buffer from begin_frame/end_frame to have
the buffer flushing semantics we want.

To ensure that we don't over damage, we store the damage in begin_frame
(and copy it) and then subtract it from the next frames damage to determine
the smallest amount we need to copy (taking scale factor into account).

We don't care to modify the damage region to swapBuffers because they
already have the right contents and could potentially fall into another
tile anyway and we'd like to avoid damaging that.

Fixes #4735
2022-02-28 11:36:27 -08:00
Christian Hergert
dbede0b115 macos: add readonly IOSurfaceLock helper
This can be used to lock a surface for reading to avoid causing the
surface contents to be invalidated. This is needed when reading back from
a front-buffer to the back-buffer as is needed when using Cairo surfaces
to implement something similar to BufferAge.
2022-02-28 11:36:27 -08:00
Christian Hergert
1e40033852 macos: short-circuit on NSEventPhaseMayBegin
We only need to send a single event in this case, so just short-circuit
instead of trying to return an additional event.
2022-02-28 11:36:27 -08:00
Christian Hergert
478bf45320 macos: support mix-rate monitors
Previously, a single CVDisplayLink was used to drive updates for all
surfaces across all monitors. It used a 'best guess' rate which would
allow for updates across monitors of mixed rates. This is undesirable for
situations where you might have a 144hz monitor as it does not allow for
reaching up to that frame rate.

Instead, we want to use a per-monitor CVDisplayLink which will fire at the
rate of the monitor down to the level of updates we require. This commit
does just that.

When a surface crosses onto a new monitor, that monitor is used to drive
the GdkFrameClock.

Fixes #4732
2022-02-28 11:36:27 -08:00
Christian Hergert
dac0b7d609 macos: use video mode for refresh rate and interval
Using the mode allows better detection of refresh rate and refresh
interval for the CVDisplayLink bridge to GdkFrameClock. Using it can help
ensure that our 144hz displays can actually reach that rather than falling
back to just 60hz.

This will also need future commits to rework the displaylink source to be
per-monitor.
2022-02-28 11:36:27 -08:00
Christian Hergert
d14987e819 macos: send stop event when fingers touch
When the fingers are placed on the touchpad, we get a scroll event with
the phase NSEventPhaseMayBegin. We can use this to synthesize an is_stop
event. This results in the scrolledwindow stopping scroll with stop
gestures.

This can cause another warning as well, however, which should be addressed
from #4730.

Fixes #4733
2022-02-28 11:36:27 -08:00
Christian Hergert
3a0077f65f macos: remove emulated scroll events
We don't appear to actually need the emulated scroll events and they get
in the way of proper scrolling with the touchpad.

Fixes #4734
2022-02-28 11:36:27 -08:00
Christian Hergert
03882ef8e5 macos: do not inherit parents frame clock
Windows can end up on different monitors despite having a parent or
transient-for ancestor. We want them to be driven by the CVDisplayLink
for the best-monitor, and so this needs to be unshared.
2022-02-28 11:36:27 -08:00
Christian Hergert
505e10f3ea macos: calculate best monitor when changing screens
When we change screens, we can keep track of the best monitor so that we
can use it to register CVDisplayLink callbacks.
2022-02-28 11:36:27 -08:00
Christian Hergert
1e01444de8 macos: remove duplicated opaque_region field
This can be relied upon from GdkSurface and we do not need to keep a copy
of it. Just remove it and use the GdkSurface.opaque_region field.
2022-02-28 11:36:27 -08:00
Christian Hergert
4404c43cd3 macos: use display id when creating CVDisplayLink
Currently we're using a display link that is for all active displays which
is just the display server trying to find some timings that try to overlap
as many as possible.

That was fine for a prototype, but we really need to do better for
situations with mixed frame rate (such as 60hz and 120hz promotion
displays). Additionally, the 144hz external monitor I have will never
reach 144hz using the current design.

This is just the first step in changing this, but the goal is to have
one of these attached to each GdkMacosMonitor which we can then use to
thaw surfaces specific to that monitor.
2022-02-28 11:36:27 -08:00
Christian Hergert
92a7c7cdc3 macos: move feedback mechanisms into separate file
We will eventually be needing additional feedback from the display server
which would be nice to keep away from the rest of GdkMacosDisplay for
cleanliness sake. Particularly for feedback from mission control and other
environment factors that requires private API for proper integration.
2022-02-28 11:36:23 -08:00
Carlos Garnacho
33db142eab gtkscrolledwindow: Do not try to doubly trigger deceleration
This may come from different sources at around the same time, e.g.
a hold gesture while on overshoot. Avoid doing that if an
animation is already set.

Fixes: https://gitlab.gnome.org/GNOME/gtk/-/issues/4730
2022-02-28 20:27:43 +01:00
Carlos Garnacho
68319afd23 Merge branch 'startup-vs-xdg-activation' into 'main'
Startup tracking with xdg-activation

See merge request GNOME/gtk!3883
2022-02-28 17:29:09 +00:00
Guido Günther
25f4e597ee print-editor: Use gtk_window_present()
This lets xdg-activation work as otherwise gdk_wayland_surface_focus is
never invoked.
2022-02-28 16:55:54 +00:00
Guido Günther
db8339ca66 demo: Use gtk_window_present()
This lets xdg-activation work as otherwise gdk_wayland_surface_focus is
never invoked.
2022-02-28 16:55:54 +00:00
Guido Günther
5ba02e3459 widget-factory: Use gtk_window_present()
This lets xdg-activation work as otherwise gdk_wayland_surface_focus is
never invoked.
2022-02-28 16:55:54 +00:00
Guido Günther
999509be61 wayland: Keep startup_notification_id around long enough
When using xdg_activation we need to keep the id around until we send
the first activate to signal succesful startup.
2022-02-28 16:55:54 +00:00
Guido Günther
5dca6dce91 window: Make sure we call gdk_wayland_surface_focus
When using xdg_activation this is responsible for submitting
the activation token / startup id to the compositor.
2022-02-28 16:55:54 +00:00
Luca Bacci
d3acfa8c2b Merge branch 'gdk-win32-configure-as-needed-fullscreen' into 'main'
GdkWin32: Configure as needed when fullscreening toplevels

Closes #4631

See merge request GNOME/gtk!4506
2022-02-28 15:11:36 +00:00
Luca Bacci
c1cc8c979b Merge branch 'win32-fix-4724-gtk4' into 'main'
gdkkeys-win32: Only perform substitution as last-resort [GTK4]

See merge request GNOME/gtk!4531
2022-02-28 08:44:10 +00:00
Matthias Clasen
eed74f6ea0 Merge branch 'ci-disable-debug' into 'main'
CI: disable debug for MSVC

See merge request GNOME/gtk!4525
2022-02-27 15:45:16 +00:00
Philip Zander
e5a4b91997 gdkkeys-win32: Only perform substitution as last-resort
Instead of performing keyboard layout substitution whenever we find a matching
entry in the registry, first try to load the original layout and only attempt
substitution when that fails.

See #4724
2022-02-27 16:40:58 +01:00
Matthias Clasen
885b34d382 Merge branch 'wip/ricotz/annotations' into 'main'
gdk: Add missing out annotation on gdk_content_deserialize_finish

See merge request GNOME/gtk!4529
2022-02-27 00:50:07 +00:00
Rico Tzschichholz
3faf9d85bb gdk: Add missing out annotation on gdk_content_deserialize_finish 2022-02-26 22:05:20 +01:00
Benjamin Otte
4cd4c25c25 Merge branch 'wip/otte/for-main' into 'main'
glrenderer: Don't return NULL form render_texture()

See merge request GNOME/gtk!4522
2022-02-26 20:15:18 +00:00
Benjamin Otte
bffa5dfddd listview: Fix return_if_fail()s 2022-02-26 20:35:44 +01:00
Benjamin Otte
2fe20878c3 flattenlistmodel: Fix indentation 2022-02-26 20:35:44 +01:00
Benjamin Otte
b28c3ef3d9 renderers: Handle large viewports
When large viewports are passed to gsk_renderer_render_texture(), don't
fail (or even return NULL).

Instead, draw multiple tiles and assemble them into a memory texture.

Tests added to the testsuite for this.
2022-02-26 20:35:44 +01:00
Matthias Clasen
ed5fb4bbfe Merge branch 'try-to-fix-ci-build' into 'main'
Revert "Bump the wayland-protocols dep"

See merge request GNOME/gtk!4528
2022-02-26 18:08:38 +00:00
Matthias Clasen
2dd86aaa00 Revert "Bump the wayland-protocols dep"
This reverts commit 6a7da77980.

This is causing various build problems between wayland-protocols
and wayland-scanner.
2022-02-26 12:03:22 -05:00
Christoph Reiter
eaf952d902 CI: disable debug for MSVC
CI currently fails with "fatal error LNK1318: Unexpected PDB error; OK (0) ''"
Google tells me it might be related to hitting a memory limit. Let's try
disabling debug for now.
2022-02-26 16:32:15 +01:00
Piotr Drąg
88cb6a46f2 Update Polish translation 2022-02-26 13:29:33 +01:00
Matthias Clasen
c76b4bdc77 Merge branch 'wip/chergert/macos-add-window-accessor' into 'main'
macos: add getter for NSWindow with macOS windowing

See merge request GNOME/gtk!4509
2022-02-26 03:17:59 +00:00
Matej Urbančič
62fe4eae16 Update Slovenian translation 2022-02-25 21:13:32 +00:00
Christian Hergert
99a40de8ad macos: add getter for NSWindow with macOS windowing
There may be various reasons that an application could need access to the
underlying NSWindow that is being used to display the GdkMacosSurface
contents. This provides a minimal API to do that without exposing our
implementation details through public API.

As our rendering system is likely to change over time, we very much want
to keep GdkMacosView, GdkMacosLayer, GdkMacosTile, and GdkMacosWindow all
private implementation details which are subject to change.

As this is public API, we are a bit long-winded with the name so it is
clear what is being accessed without polluting symbol names with things
like "ns" as we used to.
2022-02-25 11:36:39 -08:00
Aleksandr Melman
b8376407a4 Update Russian translation 2022-02-25 18:38:49 +00:00
Luca Bacci
a5643b0c83 Merge branch 'gdk-win32-fix-issue-1402-gtk4' into 'main'
Fix last error reporting when calling GetClipboardOwner

Closes #1402

See merge request GNOME/gtk!4521
2022-02-25 16:54:15 +00:00
Luca Bacci
828688d5cd Fix last error reporting when calling GetClipboardOwner
Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/1402
2022-02-25 17:14:39 +01:00
Matthias Clasen
fc47b913b1 Merge branch 'wip/chergert/macos-fix-popover-tails' into 'main'
macos: fix positioning of popover tails

See merge request GNOME/gtk!4515
2022-02-25 15:50:15 +00:00
Matthias Clasen
7d8b3357a5 Merge branch 'wip/chergert/better-positioning' into 'main'
macos: fix positioning of popover tails

See merge request GNOME/gtk!4516
2022-02-25 15:49:50 +00:00
Matthias Clasen
e0b98bc7de Merge branch 'wip/chergert/macos-fix-titled-resize' into 'main'
macos: fix origin during live resize of titled window

See merge request GNOME/gtk!4519
2022-02-25 15:49:07 +00:00
Matthias Clasen
493b145496 Merge branch 'wip/chergert/macos-unfullscreen' into 'main'
macos: restore unfullscreen frame with style mask

See merge request GNOME/gtk!4518
2022-02-25 15:48:44 +00:00
Matthias Clasen
1b2c11d7f5 Merge branch 'wip/chergert/fix-macos-overshoot' into 'main'
macos: fix kinetic scrolling with overshoot

See merge request GNOME/gtk!4517
2022-02-25 14:37:45 +00:00
Christian Hergert
a56828237a macos: fix origin during live resize of titled window
When using server-side-decorations, we need to avoid potential cycles with
compute-size as it may not have the new sizing information yet. We can
just short circuit during "live resize" to get that effect.

Fixes poor window resizing from top-left on titled windows.
2022-02-24 23:29:18 -08:00
Christian Hergert
56e2a7e8bb macos: restore unfullscreen frame with style mask
This doesn't give us appropriate results if we use the window delegate.
Instead, we need to adjust the frame at the same time we change the
style mask so that we end up in the same location.
2022-02-24 22:32:43 -08:00
Christian Hergert
f278f3610b macos: fix kinetic scrolling with overshoot
Previously we had issues on macos where the overshoot would keep showing.
To fix this we need to actually use discrete events instead of the
generated deltas from macOS in the scroll wheel case. Additionally, we need
to drop the kinetic momentum events from macOS and rely on the gtk kinetic
events which are already happening anyway. We also need to submit the
is_stop event for the GDK_SCROLL_SMOOTH case when we detect it.

To keep the discrete scroll events correct, we need to alter the hack in
gtkscrolledwindow.c to use the same path as other platforms except for
when a smooth scroll event is in place. In the future, I would imagine that
this falls into the boundary of high-precision scrolling and would share
the same code paths as other platforms.

With all of these in place, kinetic scrolling with overshoot appears the
same on macOS as other platforms.
2022-02-24 18:58:48 -08:00
Christian Hergert
c111e633e9 macos: remove unused code 2022-02-24 18:58:07 -08:00
Christian Hergert
eea7cf30bb macos: create new windows with slight origin offset
When creating new windows, it is better if we create them with a slight
offset to where they were created before so that they are visible to the
user separately from what they might be overshadowing.
2022-02-24 18:58:07 -08:00
Christian Hergert
36bdcfaccb macos: fix positioning of popover tails
This broke with the previous fixes for initial window positioning. We need
the initial positioning so that tails will be displayed correctly when the
popover surface is displayed.
2022-02-24 16:29:53 -08:00
Luming Zh
45bb820656 Update Chinese (China) translation 2022-02-25 00:07:39 +00:00
Fran Dieguez
617deb8bb6 Update Galician translation 2022-02-24 12:53:57 +00:00
Matthias Clasen
8efcd34dbe Merge branch 'ebassi/unexport-x11' into 'main'
Remove unnecessary warning

See merge request GNOME/gtk!4512
2022-02-24 12:32:41 +00:00
Daniel Mustieles
a78b573f8b Updated Spanish translation 2022-02-24 12:54:02 +01:00
Emmanuele Bassi
226f0e0567 Remove unnecessary warning
Unexporting the window handle on X11 is a no-op, so there's no need
to emit a warning.
2022-02-24 02:04:06 +00:00
Rafael Fontenelle
4304a494ae Update Brazilian Portuguese translation 2022-02-23 23:54:08 +00:00
Matthias Clasen
b71ff21530 Merge branch 'bump-wayland-dep' into 'main'
Bump the wayland-protocols dep

See merge request GNOME/gtk!4511
2022-02-23 21:05:01 +00:00
Matthias Clasen
6a7da77980 Bump the wayland-protocols dep
Bump the dep to 1.25, so we can add support
for toplevel bounds.
2022-02-23 14:30:49 -05:00
Matthias Clasen
c5f92340ee Fix up tests for version bump 2022-02-23 14:29:48 -05:00
Hugo Carvalho
572a884e90 Update Portuguese translation 2022-02-23 11:29:15 +00:00
Emin Tufan Çetin
69bc9d0702 Update Turkish translation 2022-02-23 09:42:06 +00:00
Yuri Chornoivan
34ff9e359b Update Ukrainian translation 2022-02-23 07:10:19 +00:00
Benjamin Otte
de705c2a2b Add 4.8 version macros 2022-02-22 22:55:48 -05:00
Benjamin Otte
d1102f586c build: Set version to 4.7 2022-02-22 22:55:42 -05:00
Matthias Clasen
bcb6cf04ed Merge branch 'wip/chergert/macos-window-manager' into 'main'
macos: improve placement of windows

See merge request GNOME/gtk!4510
2022-02-23 03:53:33 +00:00
Matthias Clasen
c9dbb30aff Merge branch 'ebassi/docs-related' into 'main'
docs: Split dependencies from related libraries

See merge request GNOME/gtk!4474
2022-02-23 03:28:47 +00:00
Matthias Clasen
2c88797195 Merge branch 'wip/chergert/macos-iosurface' into 'main'
macos: modernize rendering with CALayer and IOSurface

See merge request GNOME/gtk!4477
2022-02-23 03:10:43 +00:00
Christian Hergert
89a351fd66 macos: improve placement of windows
This does some very basic window management so that we place surfaces in
locations where they can actually be interacted with correctly.
2022-02-22 18:43:46 -08:00
Christian Hergert
e1d3d01e2f macos: update CGL context when surface resizes 2022-02-22 13:15:25 -08:00
Christian Hergert
76a58c40db macos: force pixel format without depth/stencil
We don't need either depth or stencil buffers, so we want a pixel format
without them so that things like glClear() can do less work.
2022-02-22 13:09:30 -08:00
Yosef Or Boczko
3b0ceeb09a Update Hebrew translation 2022-02-22 20:22:59 +00:00
Danial Behzadi
f95e082186 Update Persian translation 2022-02-22 20:08:03 +00:00
Christian Hergert
df8e2bc0a0 macos: only invalidate tiles when size changes
If the size changes, we need to relayout the tiles. Otherwise we can keep
using what we had before. Generally, that shouldn't happen, but the
previous check was failing in a number of ways.
2022-02-22 12:01:29 -08:00
Christian Hergert
42164fa8bb macos: reload IOSurface when monitor configuration changes
We also want to reload buffer contents if the display server changes the
monitor configuration, such as after changing resolution or orientation.
2022-02-22 12:01:29 -08:00
Christian Hergert
6016e17a38 macos: double buffer IOSurface
It looks like, particularly on the M1, we might need to double buffer the
contents of the IOSurface<->OpenGL texture bindings. This doesn't appear
to show up on the Intel macbooks I've tried, but I've seen it in the wild
on an M1.
2022-02-22 12:01:29 -08:00
Christian Hergert
b2de83efcb macos: restore key window after hiding popup
This fixes the focus returning to the parent window after the popup has
been hidden in the form of being a "Key Window" in macOS.
2022-02-22 12:01:29 -08:00
Christian Hergert
493f90499b macos: fix window drag across mixed-scale monitors
If we have a 2x scale laptop with a 1x scale external display, we would
need to create a new IOSurface for the external display once it crosses
a boundary, otherwise we won't have something capable of displaying
correctly on the second monitor.
2022-02-22 12:01:29 -08:00
Christian Hergert
8b71cff71d macos: use CALayer and IOSurface for rendering
This provides a major shift in how we draw both when accelerated OpenGL
as well as software rendering with Cairo. In short, it uses tiles of Core
Animation's CALayer to display contents from an OpenGL or Cairo rendering
so that the window can provide partial damage updates. Partial damage is
not generally available when using OpenGL as the whole buffer is flipped
even if you only submitted a small change using a scissor rect.

Thankfully, this speeds up Cairo rendering a bit too by using IOSurface to
upload contents to the display server. We use the tiling system we do for
OpenGL which reduces overall complexity and differences between them.

A New Buffer
============

GdkMacosBuffer is a wrapper around an IOSurfaceRef. The term buffer was
used because 1) surface is already used and 2) it loosely maps to a
front/back buffer semantic.

However, it appears that IOSurfaceRef contents are being retained in
some fashion (likely in the compositor result) so we can update the same
IOSurfaceRef without flipping as long as we're fast. This appears to be
what Chromium does as well, but Firefox uses two IOSurfaceRef and flips
between them. We would like to avoid two surfaces because it doubles the
GPU VRAM requirements of the application.

Changes to Windows
==================

Previously, the NSWindow would dynamically change between different
types of NSView based on the renderer being used. This is no longer
necessary as we just have a single NSView type, GdkMacosView, which
inherits from GdkMacosBaseView just to keep the tedius stuff separate
from the machinery of GdkMacosView. We can merge those someday if we
are okay with that.

Changes to Views
================

GdkMacosCairoView, GdkMacosCairoSubView, GdkMacosGLView have all been
removed and replaced with GdkMacosView. This new view has a single
CALayer (GdkMacosLayer) attached to it which itself has sublayers.

The contents of the CALayer is populated with an IOSurfaceRef which
we allocated with the GdkMacosSurface. The surface is replaced when
the NSWindow resizes.

Changes to Layers
=================

We now have a dedicated GdkMacosLayer which contains sublayers of
GdkMacosTile. The tile has a maximum size of 128x128 pixels in device
units.

The GdkMacosTile is partitioned by splitting both the transparent
region (window bounds minus opaque area) and then by splitting the
opaque area.

A tile has either translucent contents (and therefore is not opaque) or
has opaque contents (and therefore is opaque). An opaque tile never
contains transparent contents. As such, the opaque tiles contain a black
background so that Core Animation will consider the tile's bounds as
opaque. This can be verified with "Quartz Debug -> Show opaque regions".

Changes to Cairo
================

GTK 4 cannot currently use cairo-quartz because of how CSS borders are
rendered. It simply causes errors in the cairo_quartz_surface_t backend.

Since we are restricted to using cairo_image_surface_t (which happens to
be faster anyway) we can use the IOSurfaceBaseAddress() to obtain a
mapping of the IOSurfaceRef in user-space. It always uses BGRA 32-bit
with alpha channel even if we will discard the alpha channel as that is
necessary to hit the fast paths in other parts of the platform. Note
that while Cairo says CAIRO_FORMAT_ARGB32, it is really 32-bit BGRA on
little-endian as we expect.

OpenGL will render flipped (Quartz Native Co-ordinates) while Cairo
renders with 0,O in the top-left. We could use cairo_translate() and
cairo_scale() to reverse this, but it looks like some cairo things may
not look quite as right if we do so. To reduce the chances of one-off
bugs this continues to draw as Cairo would normally, but instead uses
an CGAffineTransform in the tiles and some CGRect translation when
swapping buffers to get the same effect.

Changes to OpenGL
=================

To simplify things, removal of all NSOpenGL* related components have
been removed and we strictly use the Core GL (CGL*) API. This probably
should have been done long ago anyay.

Most examples found in the browsers to use IOSurfaceRef with OpenGL are
using Legacy GL and there is still work underway to make this fit in
with the rest of how the GSK GL renderer works.

Since IOSurfaceRef bound to a texture/framebuffer will not have a
default framebuffer ID of 0, we needed to add a default framebuffer id
to the GdkGLContext. GskGLRenderer can use this to setup the command
queue in such a way that our IOSurface destination has been
glBindFramebuffer() as if it were the default drawable.

This stuff is pretty slight-of-hand, so where things are and what needs
flushing when and where has been a bit of an experiment to see what
actually works to get synchronization across subsystems.

Efficient Damages
=================

After we draw with Cairo, we unlock the IOSurfaceRef and the contents
are uploaded to the GPU. To make the contents visible to the app,
we must clear the tiles contents with `layer.contents=nil;` and then
re-apply the IOSurfaceRef. Since the buffer has likely not changed, we
only do this if the tile overlaps the damage region.

This gives the effect of having more tightly controlled damage regions
even though updating the layer would damage be the whole window (as it
is with OpenGL/Metal today with the exception of scissor-rect).

This too can be verified usign "Quartz Debug -> Flash screen udpates".

Frame Synchronized Resize
=========================

In GTK 4, we have the ability to perform sizing changes from compute-size
during the layout phase. Since the macOS backend already tracks window
resizes manually, we can avoid doing the setFrame: immediately and instead
do it within the frame clock's layout phase.

Doing so gives us vastly better resize experience as we're more likely to
get the size-change and updated-contents in the same frame on screen. It
makes things feel "connected" in a way they weren't before.

Some additional effort to tweak gravity during the process is also
necessary but we were already doing that in the GTK 4 backend.

Backporting
===========

The design here has made an attempt to make it possible to backport by
keeping GdkMacosBuffer, GdkMacosLayer, and GdkMacosTile fairly
independent. There may be an opportunity to integrate this into GTK 3's
quartz backend with a fair bit of work. Doing so could improve the
situation for applications which are damage-rich such as The GIMP.
2022-02-22 12:01:29 -08:00
Christian Hergert
f9268e8137 gsk/gl: support non-standard default framebuffer
There are situations where our "default framebuffer" is not actually
zero, yet we still want to apply a scissor rect.

Generally, 0 is the default framebuffer. But on platforms where we need
to bind a platform-specific feature to a GL_FRAMEBUFFER, we might have a
default that is not 0. For example, on macOS we bind an IOSurfaceRef to
a GL_TEXTURE_RECTANGLE which then is assigned as the backing store for a
framebuffer. This is different than using gsk_gl_renderer_render_texture()
in that we don't want to incur an extra copy to the destination surface
nor do we even have a way to pass a texture_id into render_texture().
2022-02-22 12:01:24 -08:00
Christian Hergert
b4b282dc81 macos: fix allocation for filechoosernative filter
The GtkFileCHooserNativeQuartz injects a NSComboBox into the NSSavePanel
(which is displayed in a remote process since 10.15 whether or not you are
a sandboxed application). The style has changed and we need more space
here to not clip part of the combobox out of view.

I tried every size from 22 to 30 and this seemed to look the most natural
without skewing the location of the text within the combobox.
2022-02-22 11:53:33 -08:00
Matthias Clasen
d4d328f96f Merge branch 'scale-button-empty-icon-list' into 'main'
Don't crash when updating the icon on a `GtkScaleButton` with a non-`NULL` empty icon list

See merge request GNOME/gtk!4475
2022-02-22 19:39:32 +00:00
Matthias Clasen
553eb55f8a Merge branch 'wip/hadess/app-id-inspector-4' into 'main'
inspector: Show app ID and resource path in the General tab

See merge request GNOME/gtk!4493
2022-02-22 19:37:36 +00:00
Matthias Clasen
9ea43096d4 Merge branch 'wip/chergert/macos-fix-event-filter' into 'main'
macos: improve event filtering for foreign panels

See merge request GNOME/gtk!4495
2022-02-22 19:36:43 +00:00
Matthias Clasen
e9ffe8f212 Merge branch 'wip/chergert/macos-fix-fullscreen' into 'main'
macos: allow windows to enter fullscreen

See merge request GNOME/gtk!4494
2022-02-22 19:36:20 +00:00
Matthias Clasen
931be7d729 Merge branch 'optimise-png-premultiply' into 'main'
gdk: Specialise RGBA8 → premultiplied BGRA8 conversion

See merge request GNOME/gtk!4481
2022-02-22 19:25:41 +00:00
Matthias Clasen
378bb481fa Merge branch 'ebassi/graphene-build-opts' into 'main'
build: Disable graphene tests

See merge request GNOME/gtk!4500
2022-02-22 18:05:14 +00:00
Matthias Clasen
8f83c7e255 Merge branch 'emoji-40' into 'main'
emoji: Update data to CLDRv40 and add more locales

Closes #4568

See merge request GNOME/gtk!4507
2022-02-22 18:04:24 +00:00
Matthias Clasen
3c99b50d2c Merge branch 'wip/chergert/gsk-gl-less-glClear' into 'main'
gsk/gl: avoid clearing opaque regions

See merge request GNOME/gtk!4504
2022-02-22 17:56:40 +00:00
Matthias Clasen
9fccbeaa75 Merge branch 'wip/chergert/macos-fix-backdrop' into 'main'
macos: fix backdrop when displaying popover

See merge request GNOME/gtk!4505
2022-02-22 17:54:20 +00:00
Matthias Clasen
d35bac452b Merge branch 'wip/chergert/macos-fix-toplevel-resize' into 'main'
macos: fix configure, move-resize, and compute-size

See merge request GNOME/gtk!4486
2022-02-22 13:10:34 +00:00
Kévin Commaille
d8c79e91a2 emoji: Add more locales
Based on the locales that are at least 85% translated in Damned Lies:
https://l10n.gnome.org/releases/gnome-41/
Limited by the locales available in emojibase

Closes #4568
2022-02-22 11:28:15 +01:00
Kévin Commaille
7f5a249056 emoji: Update data to CLDR v40
Based on emojibase-data v7.0.1
Contains the changes in Unicode 14.0

https://unicode.org/versions/Unicode14.0.0/
https://cldr.unicode.org/index/downloads/cldr-40
https://github.com/milesj/emojibase/blob/b85382524c/packages/data/CHANGELOG.md
2022-02-22 11:28:15 +01:00
Kévin Commaille
70ce353a58 emoji: Fix the convert-emoji program
The annotation field has been renamed to label in emojibase-data

https://github.com/milesj/emojibase/blob/b85382524c/packages/data/CHANGELOG.md
2022-02-22 11:28:06 +01:00
Luca Bacci
ab65e8e178 GdkWin32: Configure as needed when going fullscreen
Apply the fixes made by Chun-Wei Fan in [1] also for fullscreening /
unfullscreen. Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/4631

Also set the SWP_FRAMECHANGED flag as written by Raymond Chen in "How
do I switch a window between normal and fullscreen?" [2]

> An important flag to pass here is SWP_FRAME­CHANGED, which tells
> the window manager to recalculate the window decorations (which we
> need it to do because we just changed them).

References:
[1] - https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/3712
[2] - https://devblogs.microsoft.com/oldnewthing/20100412-00/?p=14353
2022-02-22 09:15:28 +01:00
Christian Hergert
c0ede8d46e macos: fix backdrop when displaying popover
Previously, the popover would cause the window to go into the :backdrop
state which is not what we want for consistency with other platforms. This
fixes that by walking up the surface chain when we get notified of
loosing or acquiring "key" input from the display server.
2022-02-22 00:08:37 -08:00
Luca Bacci
8f02ea39e5 Merge branch 'gdk-win32-implicit-grabs-cleanup' into 'main'
GdkWin32: Remove implicit_grab_surface

Closes #4188

See merge request GNOME/gtk!4503
2022-02-22 07:53:54 +00:00
Luca Bacci
8a8cd4e248 Merge branch 'win32-ime-fix-popup-positioning' into 'main'
Win32 IME: Fix popup positioning

Closes #374 and #2338

See merge request GNOME/gtk!4501
2022-02-22 07:52:59 +00:00
Christian Hergert
08d0575ed0 gsk/gl: avoid clearing opaque regions
If the rendering operation is over an opaque region, we can potentially
avoid clearing a large section of the framebuffer destination. Some cases
you do want to clear, such as when clearing the whole contents as some
drivers have fast paths for that to avoid bringing data back into the
framebuffer.
2022-02-21 23:43:17 -08:00
Luca Bacci
43476c09ed GdkWin32: Remove implicit_grab_surface 2022-02-21 17:38:50 +01:00
Luca Bacci
6123212a68 Win32 IME: Fix popup position 2022-02-21 16:13:06 +01:00
Luca Bacci
6106207b93 Win32 IME: Rename a variable 2022-02-21 15:53:22 +01:00
Luca Bacci
b5036faa2a Win32 IME: Keep track of the client widget 2022-02-21 15:53:13 +01:00
Luca Bacci
56fd3af4d0 Win32 IME: Remove the get_window_position util function
It always returns (0, 0)
2022-02-21 15:49:52 +01:00
Emmanuele Bassi
26beab6064 build: Disable graphene tests
When building Graphene as a subproject we don't really need
to build tests. Disabling tests also removes the dependency
on mutest.
2022-02-21 13:41:40 +00:00
Emmanuele Bassi
f41fe7b8e4 Merge branch 'msvc-cmake-dep' into 'main'
Meson: Use CMake more for finding deps on Visual Studio-like builds

See merge request GNOME/gtk!4499
2022-02-21 13:37:12 +00:00
Luca Bacci
7d6797c9ed Merge branch 'forward-port-mr-775-to-gtk4' into 'main'
gtkimcontextime.c: Fix preedit window placement on HiDPI

See merge request GNOME/gtk!4498
2022-02-21 12:01:21 +00:00
Chun-wei Fan
2e34d62111 meson.build: Use CMake to find libjpeg on MSVC-like builds
One may be using IJG libjpeg or libjpeg-turbo to build GTK, and their
build files may or may not generate pkg-config files for us.  To make
things easier, we can make use of CMake's built-in support for finding
IJG libjpeg or libjpeg-turbo.
2022-02-21 17:53:50 +08:00
Chun-wei Fan
6eda5deeff meson.build: Use CMake to find libtiff on MSVC-like
The CMake build files for libtiff may or may not generate pkg-config
files for us, so we can use Meson's CMake support to help us find
libtiff, as CMake has built-in support for finding libtiff.
2022-02-21 17:53:40 +08:00
Chun-wei Fan
83b98738b6 meson.build: Consolidate items with MSVC-like compilers
Add a variable in meson.build that covers Visual Studio-like compilers,
so that we can use it to help us find depedencies using CMake rather
than via pkg-config, where applicable.

Change the existing use case for finding libpng accordingly.
2022-02-21 17:53:31 +08:00
Emin Tufan Çetin
a07455aa0d Update Turkish translation 2022-02-20 15:04:41 +00:00
Emin Tufan Çetin
49a4d27245 Update Turkish translation 2022-02-20 14:47:56 +00:00
Danial Behzadi
ff59bf356b Update Persian translation 2022-02-20 11:14:09 +00:00
Chun-wei Fan
c6ce05b782 gtkimcontextime.c: Fix preedit window placement on HiDPI
We must also take the scaling factor into account for placing the IME
preedit window that is often used for Chinese and Japanese input on
Windows.
2022-02-19 18:31:28 +01:00
Christian Hergert
db77204a52 macos: improve event filtering for foreign panels
We might have panels with controls in them where the window is running in
another process. The control could have a wrapper window which we would
see from this process. This can happen with the GtkFileChooserNative, but
any NSSavePanel in macOS 10.15+ is out of process (not just sandboxed
applications).
2022-02-18 03:39:52 -08:00
Christian Hergert
4c08d1643f macos: fix configure, move-resize, and compute-size
This significantly cleans up how we handle various move-resize, compute-
size, and configure (notification of changes) in the macOS GDK backend.

Originally when prototyping this backend, there were some bits that came
over from the quartz backend and some bits which did not. It got confusing
and so this makes an attempt to knock down all that technical debt.

It is much simpler now in that the GdkMacosSurface makes requests of the
GdkMacosWindow, and the GdkMacosWindow notifies the GdkMacosSurface of
changes that happen.

User resizes are delayed until the next compute-size so that we are much
closer to the layout phase, reducing chances for in-between frames.

This also improves the situation of leaving maximized state so that a
grab and drag feels like you'd expect on other platforms.

I removed the opacity hack we had in before, because that is all coming
out anyway and it's a bit obnoxious to maintain through the async flows
here.
2022-02-18 02:50:46 -08:00
Christian Hergert
592436503c macos: allow windows to enter fullscreen
This fixes GTK's NSWindow for toplevels so that they are allowed to enter
fullscreen. We were already handlign the state transitions from the
setStyleMask: halper, but we didn't previously tell the window we are
allowed to transition into that.

There is a bit of a mismatch here in that GTK doesn't have any such flag
that determines if a window is "allowed" by policy to enter fullscreen
since window managers on Linux are free to do that at will.
2022-02-18 01:54:10 -08:00
Bastien Nocera
1877bb8a27 inspector: Show app ID and resource path in the General tab
This makes it easier to figure out those values (which are mentioned in
the GtkApplication documentation) rather than working that out from the
way they're generated (or documented as being generated).
2022-02-17 15:14:16 +01:00
Matthias Clasen
67a5120b5b Merge branch 'wip/chergert/macos-gst-cgl' into 'main'
media: support OpenGL-based video playback on macOS

See merge request GNOME/gtk!4491
2022-02-17 13:54:42 +00:00
Matthias Clasen
9d8f56edaa Merge branch 'wip/chergert/macos-fix-popup-input' into 'main'
macos: fix keyboard input on popovers

See merge request GNOME/gtk!4490
2022-02-17 13:53:04 +00:00
Christian Hergert
7ec9c5181d media: support OpenGL-based video playback on macOS
If we have GStreamer on macOS we likely have support for CGL to get an
OpenGL context we can use. This provides the missing pieces to get
accelerated video playback in gtk4-widget-factory working.
2022-02-16 21:31:20 -08:00
Christian Hergert
853ef43dae macos: fix keyboard input on popovers
GdkPopup can also become the "key" window (just not the "main" window).
2022-02-16 17:53:59 -08:00
Emmanuel Gil Peyrot
1fdf5b7cf8 gdk: Optimise RGBA8 → premultiplied BGRA8 for ARM
This more than halves the total runtime of this function since the
previous commit, from 8.36% to 4.02%, and is most likely memory
bandwidth limited on this specific board now.

I tried to do a SSE2 version as well, but couldn’t find any equivalent
of the LD4/ST4 ARM instruction.
2022-02-16 16:36:33 +01:00
Emmanuel Gil Peyrot
0e3ed7a738 gdk: Specialise RGBA8 → premultiplied BGRA8 conversion
On x86 on a Kaby Lake CPU, this makes it go from 6.63% of the total
execution time (loading some PNGs using the cairo backend) down to
3.20%.

On ARM on a Cortex-A7, on the same workload, this makes it go from 57%
to 8.36%.
2022-02-16 16:35:39 +01:00
Matthias Clasen
9c1a66518b Merge branch 'wip/chergert/for-macos-1' into 'main'
macos: various correctness fixes

See merge request GNOME/gtk!4485
2022-02-16 13:54:43 +00:00
Matthias Clasen
280544b874 Merge branch 'wip/baedert/for-master' into 'main'
gtkgstpaintable: Handle a NULL value

See merge request GNOME/gtk!4484
2022-02-16 13:48:51 +00:00
Christian Hergert
3c9687fcf1 macos: add helper to check if surface is opaque 2022-02-16 03:08:55 -08:00
Christian Hergert
f207402228 macos: use input_region to specify tracking areas
We want our tracking area to be limited to the input region so that we
don't pass along events outside of them for the window. This improves the
chances we click-out of a popover with a large shadow.

This still doesn't let us pass-through clicks for large shadows on top-
level windows though.
2022-02-16 03:07:51 -08:00
Christian Hergert
a080f1197a macos: ignore mouse events outside tracking area
We also need to ignore events outside the tracking areas when we are
translating them from NSevent into GdkEvent.
2022-02-16 03:06:51 -08:00
Christian Hergert
8f0b9bf5ae macos: fix incorrect signal disconnect 2022-02-16 01:46:25 -08:00
Timm Bäder
b74d3c2221 gtkgstpaintable: Handle a NULL value
gst_element_factory_make can return NULL.
2022-02-16 10:02:24 +01:00
Benjamin Otte
49b0ee21c1 Merge branch 'wip/otte/for-main' into 'main'
glcontext: Remove leftover function call

Closes #4697

See merge request GNOME/gtk!4483
2022-02-16 03:07:05 +00:00
Benjamin Otte
481634930c glcontext: Remove leftover function call
That call should have been removed way back when.

Add a testcase to make sure this keeps working.

Fixes #4697
2022-02-16 03:48:15 +01:00
Christian Hergert
d58c038fe8 macos: remove assertion from external API
We only should be asserting in static functions. Furthermore, this function
did not need to have GDK_BEGIN_MACOS_ALLOC_POOL as nothing is being
allocated there which would cause pooling to get used.
2022-02-15 12:38:07 -08:00
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
Benjamin Otte
82e4690564 Merge branch 'viewport-scroll-to-focus' into 'main'
scrolledwindow: Set scroll-to-focus on viewports

See merge request GNOME/gtk!4356
2022-02-15 16:05:32 +00:00
Maximiliano Sandoval R
8dc2c4b24a viewport: Set scroll-to-focus to TRUE by default
In GTK 3 this was the default.
2022-02-15 16:29:08 +01:00
Christian Hergert
3e913ff16e Merge branch 'mac-scrolling-fix' into 'main'
gdk: fix reversed and sluggish scrolling on MacOS

See merge request GNOME/gtk!4479
2022-02-14 23:00:27 +00: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
Benjamin Otte
12908ab863 docs: Add Since annotations to GDK_VERSION macros 2022-02-14 00:30:50 +01:00
Matej Urbančič
4cb599f378 Update Slovenian translation 2022-02-13 18:58:22 +00:00
Matej Urbančič
fe210fb0dd Update Slovenian translation 2022-02-13 18:56:28 +00:00
Asier Sarasua Garmendia
1fee30af36 Update Basque translation 2022-02-13 09:22:58 +00:00
Sebastian Dröge
3f329b2d0f Don't crash when updating the icon on a GtkScaleButton with a non-NULL empty icon list 2022-02-13 11:16:32 +02:00
Marek Černocký
1fd03acf9d Updated Czech translation 2022-02-12 19:48:40 +01:00
Benjamin Otte
a26c1a5f0d widget-factory: Make <F11> toggle fullscreen 2022-02-12 19:05:19 +01:00
Emmanuele Bassi
7a608bda27 docs: Split dependencies from related libraries
We currently list everything as a dependencies, regardless of whether
it actually is; this is a source of confusion for users that read the
GTK documentation.

Gi-docgen has a new "related" key in the project configuration which
allows us to list libraries that are merely related to the namespace
we are documenting; the "dependencies" key is used to document the
actual namespace dependencies, now.
2022-02-12 17:28:00 +00:00
Jordi Mas i Hernandez
c400dce0b1 Update Catalan translation 2022-02-12 14:41:46 +00:00
Matthias Clasen
5912b2d64a Merge branch 'wip/chergert/fix-text-overdraw' into 'main'
css: reduce overdraws from "textview > text"

See merge request GNOME/gtk!4472
2022-02-12 08:34:18 +00:00
Christian Hergert
e38e8ed73e css: reduce overdraws from "textview > text"
This was causing us to draw the same background content twice which is a
significant amount of bits to flip in the GPU for maximized windows,
especially twice.
2022-02-11 23:06:16 -08:00
Matthias Clasen
5088103d31 4.6.1 2022-02-11 20:09:15 -05:00
Matthias Clasen
76b185e6f6 Merge branch 'wip/chergert/popover-opaque-region' into 'main'
add opaque regions to popovers

Closes #4689

See merge request GNOME/gtk!4468
2022-02-11 23:16:43 +00:00
Christian Hergert
f3999f7ebf popover: use GtkNative opaque region API
This updates GtkPopover to use the new GtkNative abstraction for
reporting opaque regions of the window, in hopes that it can speed
up compositors for things like animated lists, menu transitions,
and more.

Fixes #4689
2022-02-11 14:37:46 -08:00
Christian Hergert
f8e7ecfde1 window: use GtkNative API to update opaque region
This switches to using the new GtkNative machinery for updating the
opaque region. Some amount of local calculation is still required for
determining when we should apply shadows, and this inherits what was
done previous for that.

Related #4689
2022-02-11 14:37:46 -08:00
Christian Hergert
cc49e044a5 native: add API to update opaque region
This abstracts the machinery to update the opaque region for a GtkWindow
into GtkNative so it may be used from other native impelementations such
as GtkPopover.

Related #4689
2022-02-11 14:37:43 -08:00
Matthias Clasen
9205193147 Merge branch 'bilelmoussaoui/entry-completion' into 'main'
entry completion: add checks that entry is set already

See merge request GNOME/gtk!4450
2022-02-11 17:49:26 +00:00
Matthias Clasen
124d689f45 Merge branch 'enum-docs' into 'main'
docs: Use links in enums

See merge request GNOME/gtk!4452
2022-02-11 17:35:42 +00:00
Matthias Clasen
d2a2591d28 Merge branch 'bilelmoussaoui/g-i' into 'main'
g-i: add a couple of missing nullable annotations

See merge request GNOME/gtk!4470
2022-02-11 17:33:05 +00:00
Carlos Garnacho
64a1a1dd6b Merge branch 'primary' into 'main'
gdk: don't leak wayland primary selection offers

See merge request GNOME/gtk!4458
2022-02-11 14:29:19 +00:00
Bilal Elmoussaoui
3b383569a4 g-i: Add nullable annotations to EventControllerKey::im-context
Fixes https://github.com/gtk-rs/gtk4-rs/issues/874
2022-02-11 12:59:55 +01:00
Bilal Elmoussaoui
c2fe438676 g-i: Add nullable annotations to CellArea getters
Fixes https://github.com/gtk-rs/gtk4-rs/issues/891
2022-02-11 12:55:28 +01:00
Emmanuele Bassi
0ade146e26 Merge branch 'bilelmoussaoui/layout-manager' into 'main'
layout manager: add a check if the widget exists

See merge request GNOME/gtk!4469
2022-02-11 11:51:44 +00:00
Bilal Elmoussaoui
ba266325d0 g-i: Mark FileChooser [s|g]et_current_[folder|name] as nullable
The code seems to already check if folder/name is NULL
Fixes https://github.com/gtk-rs/gtk4-rs/issues/896
2022-02-11 12:21:58 +01:00
Bilal Elmoussaoui
e6322e177e g-i: Mark get_print_settings as nullable
Fixes https://github.com/gtk-rs/gtk4-rs/issues/880
2022-02-11 12:07:54 +01:00
Maximiliano Sandoval R
080a4cda49 docs: Use links in enums
Properties already refer to their object, so

    [property@Widget:sensitive] property on [class@Widget]

is redundant.
2022-02-11 12:07:09 +01:00
Bilal Elmoussaoui
6b63868641 g-i: mark get_selected_printer as nullable
There is no selected printer if the user closes the dialog
Fixes https://github.com/gtk-rs/gtk4-rs/issues/882
2022-02-11 12:05:42 +01:00
Bilal Elmoussaoui
cb710f1999 g-i: mark EventController::name as nullable
Fixes https://github.com/gtk-rs/gtk4-rs/issues/893
2022-02-11 12:02:07 +01:00
Bilal Elmoussaoui
85bb9aaefc g-i: add nullable annotation to gtk_single_selection_get_model 2022-02-11 11:56:40 +01:00
Bilal Elmoussaoui
6c02017212 layout manager: add a check if the widget exists
Avoid a crash when calling _gtk_widget_get_first_child
Fixes https://github.com/gtk-rs/gtk4-rs/issues/889
2022-02-11 11:44:16 +01:00
Matthias Clasen
90bccf4e82 Merge branch 'fix-wayland-subproject-build' into 'main'
NEWS: Updates

See merge request GNOME/gtk!4466
2022-02-10 21:57:27 +00:00
Matthias Clasen
18db7ad470 NEWS: Updates 2022-02-10 15:06:37 -05:00
Julian Orth
468ddd4d49 gdk: don't leak wayland primary selection offers
Signed-off-by: Julian Orth <ju.orth@gmail.com>
2022-02-10 20:44:32 +01:00
Matthias Clasen
ff4b5c8996 Merge branch 'fix-wayland-subproject-build' into 'main'
Fix build with wayland-protocols subproject

Closes #4530

See merge request GNOME/gtk!4465
2022-02-10 19:13:33 +00:00
Matthias Clasen
06aa640664 Fix build with wayland-protocols subproject
The missing files() was pointed out in #4530.

Fixes: #4530
2022-02-10 13:21:28 -05:00
Matthias Clasen
9f24229f82 Merge branch 'column-view-column-new-nullable-factory' into 'main'
Allow passing a `NULL` factory to `gtk_column_view_column_new()`

See merge request GNOME/gtk!4454
2022-02-10 11:42:38 +00:00
Matthias Clasen
214370ee23 Merge branch 'icon-view-drag-dest-item-nullable' into 'main'
Mark `path` out parameter of `gtk_icon_view_get_drag_dest_item()` as `(nullable)`

See merge request GNOME/gtk!4451
2022-02-10 11:24:04 +00:00
Matthias Clasen
217d817408 Merge branch 'gwagner/gtkbuilder-rng' into 'main'
tools: updated gtk4builder.rng to current state

See merge request GNOME/gtk!4457
2022-02-09 19:25:32 +00:00
Matthias Clasen
6dfaafc9f2 Merge branch 'update-keysyms' into 'main'
gdk: Update keyboard symbols from libxkbcommon

See merge request GNOME/gtk!4422
2022-02-09 19:23:59 +00:00
Matthias Clasen
287de3844d Merge branch 'gtk_assisten_set_current_page-no-pages-guard' into 'main'
Don't dereference a `NULL` page in `gtk_assistant_set_current_page()` if there are no pages at all

See merge request GNOME/gtk!4464
2022-02-09 19:19:24 +00:00
Sebastian Dröge
878e4a34d3 Don't dereference a NULL page in gtk_assistant_set_current_page() if there are no pages at all 2022-02-09 17:50:55 +02:00
Matthias Clasen
b893dc9552 Merge branch 'bilelmoussaoui/g-i' into 'main'
gdk: mark gdk_device_get_device_tool as nullable

See merge request GNOME/gtk!4463
2022-02-09 13:43:50 +00:00
Matthias Clasen
687b80a037 Merge branch 'revert-misdeprecation' into 'main'
Revert "Deprecate GdkDevice:source"

See merge request GNOME/gtk!4462
2022-02-09 13:13:35 +00:00
Bilal Elmoussaoui
a8a98523db gdk: mark gdk_device_get_device_tool as nullable 2022-02-09 13:09:47 +00:00
Matthias Clasen
0a224964a6 Revert "Deprecate GdkDevice:source"
This reverts commit fd9e0dd13a.
2022-02-09 07:55:28 -05:00
Luca Bacci
0457c37847 Merge branch 'win32-fix-ctrl-shift-gtk4' into 'main'
gdkkeys-win32: Also ignore Ctrl + Shift (etc.)

See merge request GNOME/gtk!4460
2022-02-09 10:08:52 +00:00
Philip Zander
037c0e4005 gdkkeys-win32: Also ignore Ctrl + Shift (etc.)
Some Windows keymaps have bogus mappings for the Ctrl modifier. !4423 attempted
to fix this by ignoring the Ctrl layer, but that was not enough. We also need to
ignore combinations of Ctrl with other modifiers, i.e. Ctrl + Shift. For example,
Ctrl + Shift + 6 is mapped to the character 0x1E on a US keyboard (but it should
be treated as Ctrl + ^). Basically, always ignore Ctrl unless it is used in
conjunction with Alt, i.e. as part of AltGr.

Related issue: #4667
2022-02-09 10:43:07 +01:00
Christian Hergert
b9389d3784 Merge branch 'bilelmoussaoui/macos-gdk-display' into 'main'
macos: Don't set NULL as a display name

See merge request GNOME/gtk!4453
2022-02-09 00:30:04 +00:00
Günther Wagner
86a3400f2e tools: updated gtk4builder.rng to current state 2022-02-08 21:42:41 +01:00
Sebastian Dröge
8245fd4beb Allow passing a NULL factory to gtk_column_view_column_new() 2022-02-08 16:25:28 +02: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
Sebastian Dröge
07d6ef13c5 Mark path out parameter of gtk_icon_view_get_drag_dest_item() as (nullable)
It can be set to `NULL` and the function body handles `NULL` explictly,
so annotate it accordingly.
2022-02-08 12:50:24 +02:00
Bilal Elmoussaoui
883e8328e0 entry completion: add checks that entry is set already
If any of the APIs that assumes that the entry is set already is used
before having one already set, things break pretty badly.

Fixes a downstream issue reported at https://github.com/gtk-rs/gtk4-rs/issues/873
2022-02-08 11:22:52 +01:00
Benjamin Otte
c6d5816c95 Merge branch 'wip/otte/for-main' into 'main'
gltexture: Only use glGetFramebufferParameter() when available

Closes #4678

See merge request GNOME/gtk!4449
2022-02-08 02:08:26 +00:00
Benjamin Otte
f37c5ebd26 rgba: Fix GDK_RGBA() macro to work with alpha
Previously we dividied by an integer, so alpha was either 0.0 or 1.0.
2022-02-08 01:34:19 +01:00
Benjamin Otte
2c71825324 gltexture: Only use glGetFramebufferParameter() when available
Fixes #4678
2022-02-08 01:34:19 +01:00
Matthias Clasen
38ad56e6a1 Merge branch 'wip/jimmac/selected_text' into 'main'
style: legible text selections

Closes #4664

See merge request GNOME/gtk!4433
2022-02-08 00:15:45 +00:00
Matthias Clasen
84d698464c Merge branch 'antoniof-main-patch-89408' into 'main'
columnviewcolumn: Define autocleanup function

See merge request GNOME/gtk!4440
2022-02-07 23:57:46 +00:00
Matthias Clasen
9363269ceb Merge branch 'more-noexecstack' into 'main'
demos: Make our stack noexec

See merge request GNOME/gtk!4439
2022-02-07 23:57:26 +00: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
Matthias Clasen
d9109a0e92 Merge branch 'mg/gdk-macos-gdkdisplaylinksource' into 'main'
Include `gdk-private.h` to fix error about `g_source_set_static_name`

See merge request GNOME/gtk!4443
2022-02-07 23:54:55 +00:00
Matthias Clasen
f27c0c65b1 Merge branch 'mg/implicit-declaration-free' into 'main'
gdkjpeg: include `stdlib.h` necessary for `free`

See merge request GNOME/gtk!4445
2022-02-07 23:53:36 +00:00
Matej Urbančič
212f629876 Update Slovenian translation 2022-02-07 19:39:08 +00:00
Matej Urbančič
05f2f3ba8c Update Slovenian translation 2022-02-07 19:30:34 +00:00
Emmanuele Bassi
a66072f312 Merge branch 'drop-target-get-formats-transfer-none' into 'main'
Mark `gtk_drop_target_get_formats()` return value as `transfer none`

See merge request GNOME/gtk!4446
2022-02-07 15:17:39 +00:00
Sebastian Dröge
3ba582375d Mark gtk_drop_target_get_formats() return value as transfer none
It was wrongly inferred as `transfer full` by gobject-introspection.
2022-02-07 16:23:01 +02:00
Mosè Giordano
4c211f1872 gdkjpeg: include stdlib.h necessary for free
`free` is defined in `stdlib.h`, see for example
<https://pubs.opengroup.org/onlinepubs/009604499/functions/free.html>.  Without
this include compilation can fail with the following error:

```
../gdk/loaders/gdkjpeg.c: In function ‘gdk_save_jpeg’:
../gdk/loaders/gdkjpeg.c:264:7: warning: implicit declaration of function ‘free’ [-Wimplicit-function-declaration]
       free (data);
       ^
../gdk/loaders/gdkjpeg.c:264:7: warning: incompatible implicit declaration of built-in function ‘free’
../gdk/loaders/gdkjpeg.c:264:7: note: include ‘<stdlib.h>’ or provide a declaration of ‘free’
../gdk/loaders/gdkjpeg.c:302:67: error: ‘free’ undeclared (first use in this function)
   return g_bytes_new_with_free_func (data, size, (GDestroyNotify) free, NULL);
                                                                   ^
../gdk/loaders/gdkjpeg.c:302:67: note: each undeclared identifier is reported only once for each function it appears in
../gdk/loaders/gdkjpeg.c:303:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
```
2022-02-06 15:41:33 +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
Asier Sarasua Garmendia
34959b58f4 Update Basque translation 2022-02-05 11:21:02 +00: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
Benjamin Otte
14bdf82e33 Merge branch 'wip/hadess/inspector-search-by-pointer-gtk4' into 'main'
inspector: Search by pointer address

See merge request GNOME/gtk!4442
2022-02-04 18:07:28 +00: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
Bastien Nocera
0621dbc745 inspector: Search by pointer address
Useful to find a widget that corresponds to a pointer address in gdb.
2022-02-04 18:39:56 +01: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
António Fernandes
94ef818c9a columnviewcolumn: Define autocleanup function 2022-02-04 11:13:46 +00: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
Jan Alexander Steffens (heftig)
d8befc612f demos: Make our stack noexec
This is similar to https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/4330
and https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/4334, which fixed
the main library but missed the demos.
2022-02-03 19:14:36 +00:00
Emmanuele Bassi
06ec4ec148 Merge branch 'zbrown/its-a-filename' into 'main'
cssprovider: from_path takes a path

See merge request GNOME/gtk!4436
2022-02-02 23:11:44 +00:00
Zander Brown
6fbcb967a0 cssprovider: from_path takes a path
Annotate it as such so that bindings can expose that appropriately

Related: https://github.com/gtk-rs/gtk4-rs/issues/861
2022-02-02 22:47:39 +00:00
Emmanuele Bassi
82e0241c42 Merge branch 'fix-app-launch-context-docs' into 'main'
gdkapplaunchcontext: Fix docs a bit

See merge request GNOME/gtk!4434
2022-02-01 20:34:41 +00:00
Phaedrus Leeds
8e000c2dbf gdkapplaunchcontext: Fix docs a bit
The set_screen() and set_display() methods no longer exist.
2022-02-01 11:17:55 -08:00
Jakub Steiner
1f1aafd5c2 style: legible text selections
- follow adwaita styling

Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/4664
2022-02-01 17:12:52 +01:00
Luca Bacci
d314298644 Merge branch 'win32-keys-ignore-ctrl-gtk4' into 'main'
gdkkeys-win32: Ignore CTRL bit for key translation

Closes #4667

See merge request GNOME/gtk!4431
2022-02-01 15:33:01 +00:00
Emmanuele Bassi
3cbe3abf67 Merge branch '4602-fix-kerning-of-gl-rendered-glyphs' into 'main'
Fix kerning of GL rendered glyphs

Closes #4602

See merge request GNOME/gtk!4429
2022-02-01 14:31:47 +00:00
Philip Zander
90ab8b8dd3 gdkkeys-win32: Ignore CTRL bit for key translation
Some keymaps on Windows contain bogus mappings for Ctrl+key for certain
keys, e.g. Ctrl+Backspace = Delete, or Ctrl+[ = 0x1B. These are never
used on Windows, so we should ignore them.

Fixes #4667
2022-02-01 14:12:56 +01:00
Marek Kasik
cb1dd66220 Fix kerning of GL rendered glyphs
Multiple scaled shifts by 1024 too.

Fixes: #4602
2022-02-01 09:31:35 +01:00
Boyuan Yang
d033a099ae Update Chinese (China) translation 2022-01-31 03:51:23 +00:00
Boyuan Yang
78d9e5e181 Update Chinese (China) translation 2022-01-31 03:46:30 +00:00
sicklylife
41270ba8c9 Update Japanese translation 2022-01-30 15:26:50 +00:00
sicklylife
e2277438e9 Update Japanese translation 2022-01-30 15:15:27 +00:00
Piotr Drąg
b0936c913b Update Polish translation 2022-01-29 14:59:17 +01:00
Väinö Mäkelä
4b05eb62c9 gdk: Update keyboard symbols from libxkbcommon
GTK's old key symbol list is missing a few symbols like the per mille
sign that is included in some keyboard layouts. This commit updates
gdkkeyuni.c to match libxkbcommon's current key symbol list.
2022-01-29 14:31:09 +02:00
Aleksandr Melman
fbacf0cb65 Update Russian translation 2022-01-28 11:05:57 +00:00
Emmanuele Bassi
05a53a1582 Merge branch 'infobar-xml' into 'main'
Escape Builder XML in GtkInfoBar docs

See merge request GNOME/gtk!4421
2022-01-28 10:49:37 +00:00
Elliott Sales de Andrade
be5873a057 Escape Builder XML in GtkInfoBar docs 2022-01-28 05:32:16 -05:00
Daniel Mustieles
c97f46bf28 Updated Spanish translation 2022-01-28 11:01:09 +01:00
Emmanuele Bassi
1d47882eab Merge branch 'ebassi/manifest-dep-fix' into 'main'
flatpak: Add wayland-protocols to the manifests

See merge request GNOME/gtk!4420
2022-01-28 02:05:59 +00:00
Emmanuele Bassi
9dcbbb4300 flatpak: Use "main" branch for wayland
The default branch for wayland has changed, but the "master" branch
is still available with an older version.
2022-01-28 01:25:04 +00:00
Matthias Clasen
c9eda02fa1 Merge branch 'tiled-window-bracket-fix' into 'main'
theme: Drop shadow and border fixes for tiled windows

See merge request GNOME/gtk!4418
2022-01-27 17:29:13 +00:00
Matthias Clasen
a37584a404 Merge branch 'wip/baedert/for-master' into 'main'
build: Make GCC ignore fallthrough comments

Closes #4663

See merge request GNOME/gtk!4419
2022-01-27 16:27:12 +00:00
Leônidas Araújo
566f217f6f Update Brazilian Portuguese translation 2022-01-27 16:25:07 +00:00
Matheus Barbosa
ca34c79443 Update Brazilian Portuguese translation 2022-01-27 15:47:53 +00:00
Timm Bäder
4be6c5b197 gesturesingle: Get rid of a fallthrough comment
Fixes #4663
2022-01-27 16:06:56 +01:00
Timm Bäder
7194196100 build: Make GCC ignore fallthrough comments
From the GCC manpage:

> Wimplicit-fallthrough=5 doesn't recognize any comments as
> fallthrough comments, only attributes disable
> the warning.

So, check for the =5 version after checking for the simple version. This
way we get -Wfallhrough with clang and -Wfallthrough -Wfallthrough=5
with GCC, which works.
2022-01-27 16:05:33 +01:00
Yuri Chornoivan
d9d2eb978d Update Ukrainian translation 2022-01-27 14:47:37 +00:00
Carlos Garnacho
c8460c51bd Merge branch 'realize-vs-focus-in' into 'main'
gtktext: Make sure input method sees focus in

See merge request GNOME/gtk!4402
2022-01-27 14:13:55 +00:00
Joonas Henriksson
b4d0235a05 theme: Fix incorrect border color for tiled windows 2022-01-27 06:08:40 +02:00
Joonas Henriksson
a5d1f78bf2 theme: Fix drop shadow for tiled windows
Misplaced curly bracket prevented the :backdrop styling from getting
applied. Also fix the indentation while at it.
2022-01-27 05:50:06 +02:00
Carlos Garnacho
9a7750e339 Merge branch 'hold-gestures' into 'main'
Add hold gestures

See merge request GNOME/gtk!3454
2022-01-26 23:37:28 +00:00
Fran Dieguez
d7c4ac7d02 Update Galician translation 2022-01-26 23:36:27 +00:00
Hugo Carvalho
1a08be066e Update Portuguese translation 2022-01-26 22:48:02 +00:00
José Expósito
fe86aa5f6b gtkgestureswipe: Don't filter hold events
Part-of: <!3454>
2022-01-26 22:49:53 +01:00
José Expósito
34133ec1e8 gtkgesturerotate: Don't filter hold events
Part-of: <!3454>
2022-01-26 22:49:53 +01:00
José Expósito
a99a75827c gtkgesturezoom: Don't filter hold events
Part-of: <!3454>
2022-01-26 22:49:53 +01:00
José Expósito
3bfcc12ec0 gtkgesture: Handle hold gestures
Hold gestures are used to bring existing gestures on touchpad
semantically closer to touchscreen gestures.

Touchpad gestures observe hold gestures with a matching amount of
fingers and emit their begin and end signals when fingers are detected
or removed on/from the touchpad.

When a hold cancel event is detected, it is required to wait a few
milliseconds until the next event(s) are received to avoid emitting
multiple begin signals.

Part-of: <!3454>
2022-01-26 22:49:53 +01:00
José Expósito
382341e1bf gtkgesture: Add hold to EVENT_IS_TOUCHPAD_GESTURE
Part-of: <!3454>
2022-01-26 22:49:53 +01:00
José Expósito
44b0d8b330 scrolledwindow: Stop kinetic scrolling on begin
Stop kinetic scrolling when a scroll begin signal is sent during the
event capture phase.

Part-of: <!3454>
2022-01-26 22:49:53 +01:00
José Expósito
62808722d2 kineticscrolling: Add stop function
Move the logic to stop kinetic scrolling to its own function and allow
to call it from the outside.

Part-of: <!3454>
2022-01-26 22:49:53 +01:00
José Expósito
f09338c8de gtkeventcontrollerscroll: Handle hold gestures
Handle hold events:

 - GDK_TOUCHPAD_GESTURE_PHASE_BEGIN: scroll-begin is emitted.
 - GDK_TOUCHPAD_GESTURE_PHASE_END: A hold gesture ends only when all
   fingers are lifted from the touchpad without movement, so
   scroll-end is emitted right away.
 - GDK_TOUCHPAD_GESTURE_PHASE_CANCEL: A hold gesture is cancelled when
   some fingers are lifted/put down or movement is detected. In this
   case, scroll-end is emitted after a small timeout only if
   GDK_SCROLL wasn't detected.

Part-of: <!3454>
2022-01-26 22:49:53 +01:00
José Expósito
ec91b2de10 gtkeventcontrollerscroll: Refactor scroll end
Move the logic to end scrolling to its own function to be able to
reuse it.

Refactor, no functional changes.

Part-of: <!3454>
2022-01-26 22:49:53 +01:00
José Expósito
5cd289dc1d gtkeventcontrollerscroll: Refactor scroll begin
Move the logic to begin scrolling to its own function to be able to
reuse it.

Refactor, no functional changes.

Part-of: <!3454>
2022-01-26 22:49:53 +01:00
José Expósito
299caaa383 wayland/pointer-gestures: Receive hold gesture
Add the glue code to receive hold gesture events from the compositor,
transform them into GdkEvents and finally enqueue them.

Part-of: <!3454>
2022-01-26 22:49:53 +01:00
José Expósito
0aa2a4ef14 gtkmain: Handle hold events
Part-of: <!3454>
2022-01-26 22:49:53 +01:00
José Expósito
331f1ee722 gdk/events: Add hold GdkEvent
Allow to create hold events as well as the required functions to get
information about the event: gesture phase, finger count, etc

Part-of: <!3454>
2022-01-26 22:49:53 +01:00
José Expósito
0f351508bc build: Bump wayland-protocols to v1.23
Part-of: <!3454>
2022-01-26 22:47:51 +01:00
Matthias Clasen
304527ab01 Merge branch 'sri-main-patch-28302' into 'main'
Update docs/reference/gtk/migrating-3to4.md

See merge request GNOME/gtk!4404
2022-01-26 19:37:28 +00:00
Matthias Clasen
b3d778469a Merge branch 'rafaelff-hig' into 'main'
buildertool: use curly apostrophe

See merge request GNOME/gtk!4414
2022-01-26 19:35:21 +00:00
Matthias Clasen
6f5210afea Merge branch 'wip/carlosg/touchpad-gesture-fixes' into 'main'
Touchpad gesture fixes

See merge request GNOME/gtk!4417
2022-01-26 19:32:33 +00:00
Matthias Clasen
6b1de35c01 Merge branch 'antoniof-main-patch-39484' into 'main'
gtkbitset: Define autocleanup function

See merge request GNOME/gtk!4416
2022-01-26 19:29:08 +00:00
Matthias Clasen
8fccfc7a3d Merge branch 'bilelmoussaoui/g-i' into 'main'
g-i: mark GtkSnapshot to_(node|paintable) as nullable

See merge request GNOME/gtk!4413
2022-01-26 19:19:42 +00:00
Carlos Garnacho
6fd3645713 gtk/gesture: Fix point info lookup on touchpad events
Since the addition of GdkEventSequence in touchpad events, these
are now stored in the gesture using that sequence. This bit of touchpad
gesture handling was however missing to be updated, still looking up
the special NULL sequence.

Use the last sequence here, which will be the one coming from touchpad
gesture events.
2022-01-26 16:02:00 +01:00
Carlos Garnacho
8e86e6325b gtk/main: Do not use touchpad event sequence for pointer focus lookup
Despite touchpad gestures having a sequence, these must use the logical
pointer focus. Avoid using the sequence for GtkPointerFocus lookups with
those events, in order to ensure those events make it all the way to the
intended target.

This is fallout from adding GdkEventSequence information to touchpad
gestures.
2022-01-26 15:59:36 +01:00
Carlos Garnacho
2b41e72196 gdk: Always request "flush events" frame clock phase on events
This change is done for 2 reasons:

- The logic to request this phase when compressing scroll events is
  slightly broken. If there are multiple scroll events that are
  coalesced into one, the surface frame clock will not get this request.
  The worst case is having >= 2 scroll events on every frame, as the
  compressed event will be left in the queue, and be further compressed
  on future events.

- Even scroll events aside, this phase is requested in oddly specific
  places that are not enough to cover all events, others do rely on
  unrelated GdkFrameClock activity that happens to flush the events
  as well.

Unify this phase request so it explicitly happens on the arrival of any
event. This ensures that events (compressed or not) will be handled
promptly after arrival.
2022-01-26 15:49:29 +01:00
António Fernandes
1a64eeb88e gtkbitset: Define autocleanup function 2022-01-25 21:33:31 +00:00
Emmanuele Bassi
2f8eac2c0a Merge branch 'fix-popovermenu-removechild' into 'main'
popovermenu: Fix crash when removing child

See merge request GNOME/gtk!4393
2022-01-25 15:40:28 +00:00
Kévin Commaille
aaba777ad0 popovermenu: Fix crash when removing child
gtk_menu_section_box_remove_custom was looking in the wrong place for the
stack ancestor, causing an assertion error.
2022-01-25 15:31:00 +01:00
Guido Günther
a580547f47 gtktext: Make sure input method sees focus in
Currently when the widget is realized after the focus in event the input
method isn't activated as enable is never sent. The call trace is

  gtk_text_focus_changed ->
    gtk_im_context_focus_in ->
      gtk_im_context_wayland_focus_in

which returns early as self->widget is NULL since it's set up in
gtk_text_realize() via gtk_im_context_set_client_widget(). Handle that
case by invoking gtk_im_context_focus_in() from gtk_text_realize() too.

A case where the above happens is a GtkSearchEntry in a GtkSearchBar.
E.g. in gtk4-demo when starting the demo and then hitting the search
button right away.
2022-01-25 11:15:29 +01:00
Boyuan Yang
00ee7ffa6a Update Chinese (China) translation 2022-01-24 19:46:37 +00:00
Leônidas Araújo
f02b7d55b1 Update Brazilian Portuguese translation 2022-01-24 17:08:46 +00:00
Rafael Fontenelle
bed709a322 buildertool: use curly apostrophe 2022-01-24 17:04:17 +00:00
Bilal Elmoussaoui
b362eeefdf g-i: mark GtkSnapshot to_(node|paintable) as nullable
Fixes an upstream issue reported at https://github.com/gtk-rs/gtk4-rs/issues/845
2022-01-23 22:11:07 +00:00
Matthias Clasen
7b02498963 Merge branch 'matthiasc/for-main' into 'main'
Use pango api better

See merge request GNOME/gtk!4412
2022-01-23 15:19:39 +00:00
Matthias Clasen
6fd53f28f3 Use pango api better
Avoid direct access to PangoLayoutLine members,
use pango api for it where we can.#
2022-01-23 09:55:46 -05:00
Matthias Clasen
fefc8b5a82 Merge branch 'matthiasc/for-main' into 'main'
Use pango api better

See merge request GNOME/gtk!4411
2022-01-23 14:34:58 +00:00
Matthias Clasen
4fe976549e Use pango api better
Avoid direct access to PangoLayoutLine members,
use pango api for it where we can.
2022-01-23 09:09:57 -05:00
Matthias Clasen
044ff82d0b Merge branch 'matthiasc/for-main' into 'main'
Use pango api better

See merge request GNOME/gtk!4409
2022-01-23 04:29:58 +00:00
Matthias Clasen
feac1e5fba Use pango api better
Avoid direct access to PangoLayoutLine members,
use pango api for it where we can.
2022-01-22 23:10:53 -05:00
Yaron Shahrabani
dd5455fcd2 Update Hebrew translation 2022-01-21 16:04:24 +00:00
Yaron Shahrabani
315971f02d Update Hebrew translation 2022-01-21 15:53:39 +00:00
Emmanuele Bassi
a092986af3 Merge branch 'targz' into 'main'
ci: Put gtk dll into an archive

Closes #4653

See merge request GNOME/gtk!4403
2022-01-19 19:58:36 +00:00
Sri Ramkrishna
6633f4e02f Update docs/reference/gtk/migrating-3to4.md 2022-01-19 19:24:01 +00:00
Guido Günther
ee8970f23d ci: Only use letters in "expose_as" 2022-01-19 18:51:29 +01:00
Guido Günther
46f1e4c414 ci: Put gtk dll into an archive
This avoids the wild card that makes the CI fail
2022-01-19 18:51:16 +01:00
Dz Chen
a853e27765 Update Chinese (China) translation 2022-01-19 15:44:00 +00:00
Matthias Clasen
68985d42bb Merge branch 'win32-gl-improvements' into 'main'
Windows: Some fixes to GL context realization (EGL/GLES in particular)

See merge request GNOME/gtk!4386
2022-01-19 13:49:40 +00:00
Matthias Clasen
9146a21738 Merge branch 'bilelmoussaoui/g-i' into 'main'
g-i: mark gtk_text_iter_get_child_anchor as nullable

See merge request GNOME/gtk!4401
2022-01-19 13:48:57 +00:00
Luca Bacci
8c2128703b Merge branch 'provide-libgtk-dll-as-ci-artifact' into 'main'
Provide GTK DLL as GitLab CI artifact

See merge request GNOME/gtk!4395
2022-01-19 11:17:28 +00:00
Luca Bacci
b2d9cae0ec Provide GTK DLL as GitLab CI artifact 2022-01-19 11:17:28 +00:00
Carlos Garnacho
11eb66298d Merge branch 'context-early' into 'main'
gtkimcontextwayland: Remember context on focus-in so enable can happen later

See merge request GNOME/gtk!4397
2022-01-19 10:48:48 +00:00
Bilal Elmoussaoui
0f67e46549 g-i: mark gtk_text_iter_get_paintable as nullable 2022-01-19 10:22:40 +00:00
Guido Günther
45397534eb gtkimcontextwayland: Save context even when text_input isn't around yet
Remember the current context on focus-in even though the text-input
isn't set up yet. This helps in the case where the text-input is not yet
created but a widget already got focused. Without that the enable()
invocation in text_input_enter() woulnd't be invoked leaving the input
method disabled.

This fixes

    gtk4-demo --run=search_entry

which would initially not show the on-screen keyboard when e.g using
phoc/sway as compositor.
2022-01-19 10:20:46 +00:00
Bilal Elmoussaoui
ffa93b87f8 g-i: mark gtk_text_iter_get_child_anchor as nullable 2022-01-19 10:18:40 +00:00
Guido Günther
4d741bac98 wayland: xdg-activation: Don't assume there's a focus surface
Tools like gtk4-launch can't set surface on the activation token so
don't require it. If the compositor requires it we can't do anything
about it anyway. This avoids a critical:

   (gtk4-launch:23497): Gdk-CRITICAL **: 17:07:24.704: gdk_wayland_surface_get_wl_surface: assertion 'GDK_IS_WAYLAND_SURFACE (surface)' failed

Fixes: be4216e051 ("gdk/wayland: Support the xdg-activation wayland protocol")

Signed-off-by: Guido Günther <agx@sigxcpu.org>
2022-01-19 08:57:10 +01:00
Chun-wei Fan
0fe37d1828 gdkdisplay-win32.c: Clean up GL initialization further 2022-01-19 11:56:32 +08:00
Chun-wei Fan
43839898b3 GDK: Force GLES 3.0+ on libANGLE
...when libANGLE is being used on Windows, by checking for a
Windows-specific an ANGLE-specific extension.
2022-01-19 11:56:32 +08:00
Chun-wei Fan
6f2848c311 Cleanup "GDK/Win32: Try to fix initializing GLES contexts"
As per Benjamin's suggestions, cleanup the previous implementation on
initializing the GLES context on Windows, so that we use more items that are
already in GDK proper and integrate two functions into one.
2022-01-19 11:56:32 +08:00
Chun-wei Fan
38c17c1f79 gdkglcontext-win32-wgl.c: Cleanup GL context creation
Instead of first trying to explicitly ask for a WGL 4.1 context, ask for
the WGL context version that matches what is reported via
epoxy_gl_version(), so that we get the maximum WGL version that is
supported by the graphics drivers, and make sure any WGL contexts that
are shared with this (initial) WGL context are created likewise.

We can try to do a default-bog-standard 3.2 core WGL context creation
if the need arises, but let's leave that alone for now.
2022-01-19 11:56:32 +08:00
Chun-wei Fan
b85aa10700 gdkglcontext.c: Ensure EGL contexts are in-sync with shared context
The EGL context that we are actually creating must have matching OpenGL/ES
versions and allowed GL API set with the previously-created EGL context
that will be shared with it so that they can interoperate together, if
applicable.

This will fix the situation by making sure that we request for the
OpenGL/ES version and OpenGL API set that match with what we have in our shared
EGL context.  Otherwise, the newly-created EGL context assumed a OpenGL/ES 2.0
context that supported desktop OpenGL, which may not be what we wanted, such as
in the case of libANGLE.
2022-01-19 11:56:32 +08:00
Chun-wei Fan
598c7d9cf4 GDK/Win32: Try to fix initializing GLES contexts
We are now able to create EGL contexts properly on Windows, but not GLES.  This
tries to fix things by doing the following:

*  Record the GL context type in a more proper fashion, using an Enum.  This
   makes things a bit cleaner.
*  Force GLES-3.0+ contexts, since libANGLE requires this to properly work with
   the shaders-its 2.0 contexts don't work well with our shaders.
2022-01-19 11:56:32 +08:00
Chun-wei Fan
3e9d858af1 gskrenderer.c: Use GL renderer on Windows by default
Since now we have the shaders working on Windows under GLES with libANGLE using
a 3.0+ context, drop the check to fall back to the Cairo renderer when GLES is
being used.
2022-01-19 11:56:32 +08:00
Matthias Clasen
6fd29e6600 Merge branch 'wip/wayland-surface-offset' into 'main'
Fix DND hotspot position under Wayland + EGL/Vulkan

See merge request GNOME/gtk!3705
2022-01-18 23:48:26 +00:00
Matthias Clasen
b67636747b Merge branch 'gdksurface-wayland-assert' into 'main'
gdksurface-wayland: Fix contradictory assert

See merge request GNOME/gtk!4385
2022-01-18 23:46:59 +00:00
Matthias Clasen
ea464c9874 Merge branch 'gsk-transform-nullable' into 'main'
Mark various GskTransform functions as nullable in their return value

See merge request GNOME/gtk!4378
2022-01-18 23:44:23 +00:00
Matthias Clasen
0e9c4a3964 Merge branch 'document_shortcut_func_ret' into 'main'
gtk: document return value of ShortcutFunc

See merge request GNOME/gtk!4389
2022-01-18 23:41:15 +00:00
Matthias Clasen
1b15f89dfd Merge branch 'wip/dont-always-restore-saved-gtk4' into 'main'
wayland: Don't always restore the saved size when floating

Closes #4634

See merge request GNOME/gtk!4394
2022-01-18 23:40:49 +00:00
Matthias Clasen
7192ff672e Merge branch 'build-post-install-query-media-modules' into 'main'
Meson: Also query media modules in post-install

See merge request GNOME/gtk!4380
2022-01-18 23:39:26 +00:00
Matthias Clasen
7a99e03888 Merge branch 'ebassi/fix-release-test' into 'main'
reftest: Avoid assertions being compiled out

See merge request GNOME/gtk!4391
2022-01-18 15:07:37 +00:00
Jonas Ådahl
be7a391a13 wayland: Don't always restore the saved size when floating
We only save the size when we transition from floating to fixed, so that
we can restore the size to the one prior to being fixed.

However, we should not restore to this size whenever we see a 0x0 size
from xdg_toplevel, as it can do that any time it doesn't care about the
size, e.g. when the surface is floating and just changing state.

Fix this by only using the saved size when transitioning from fixed to
floating, not when staying floating while previously floating.

Closes: https://gitlab.gnome.org/GNOME/gtk/-/issues/4634
2022-01-18 15:46:10 +01:00
Emmanuele Bassi
23aec81f1a reftest: Avoid assertions being compiled out
Calling functions inside a g_assert() means those functions will be
compiled out when building with G_DISABLE_ASSERT.

This fixes the release job in the CI pipeline.
2022-01-18 14:07:37 +00:00
Alexandros Theodotou
738d962aca gtk: document return value of ShortcutFunc 2022-01-18 10:58:47 +00:00
Luca Bacci
93bc97b7ec Merge branch 'fix-keyboard-shortcuts-win32' into 'main'
Win32 key events cleanup

See merge request GNOME/gtk!4349
2022-01-17 13:34:17 +00:00
Luca Bacci
243bb57a27 GdkWin32: Add translation result w/o CAPS LOCK to key events for accelerator matching 2022-01-17 14:14:55 +01:00
Luca Bacci
4916ebd05e GdkWin32: Remove _gdk_input_codepage variable
It's unused
2022-01-17 14:14:55 +01:00
Luca Bacci
8bbf48eb64 GdkWin32: Code reorganization for gdk_event_translate 2022-01-17 14:14:47 +01:00
Matthias Clasen
56920092b9 Merge branch 'ebassi/issue-4596' into 'main'
i18n: Detect more translatable attribute values

Closes #4596

See merge request GNOME/gtk!4383
2022-01-17 12:58:01 +00:00
Luca Bacci
672ab4fc35 Merge branch 'win32-imcontextime-ignore-control-characters' into 'main'
Fix handling of control characters & remove Win32-specific hacks from gdkkeyuni.c

Closes #2865

See merge request GNOME/gtk!4387
2022-01-17 11:44:12 +00:00
Philip Zander
52616dee8e GtkIMContextIME: Ignore ASCII control characters
Make GtkIMContextIME ignore ASCII control characters just like other
IMContext implementations (e.G. GtkIMContextSimple). Fixes bogus
characters appearing in text input fields (old bug 676077).
2022-01-17 12:03:01 +01:00
Chun-wei Fan
905f021bbd Revert "Bug 676077: Fix handling of Keyboard Input on Windows"
The actual code that does the IM context code handling on Windows now uses the
native Windows APIs to handle keystrokes, so this patch is no longer needed, as
it was found that it instead caused issues.

Pointed out in issue #2865.

This reverts commit fd6ce9975e.
2022-01-17 11:38:37 +01:00
Kritphong Mongkhonvanit
55016ada92 gdksurface-wayland: Fix contradictory assert
gdk_wayland_toplevel_inhibit_idle() contained a contradictory assert
that always fail. More specifically, in the branch that is supposed to
create the idle inhibitor, there is an assertion that it must already
exist and that the refcount must be greater than zero. This causes a
crash on WMs/DEs that use the ZWP idle inhibit manager protocol such as
KDE Plasma and Sway. Fix this by just asserting that the refcount is
zero instead.
2022-01-17 15:50:08 +07:00
Aurimas Černius
3bfaaab4f7 Updated Lithuanian translation 2022-01-16 21:38:08 +02:00
Emmanuele Bassi
9e83eb6501 i18n: Detect more translatable attribute values
GtkBuilder uses GMarkup, which defines a boolean attribute value as:

- yes/no
- true/false
- 1/0

The ITS file for GtkBuilder UI definitions is only using the first pair,
likely because Glade only ever used those values. GTK's own tools, though,
will typically simplify the full yes/no and true/false strings to 1 and 0,
to minimise the parsing time.

Fixes: #4596
2022-01-16 14:03:05 +00:00
Luca Bacci
ef1905a665 post install: query media modules 2022-01-14 18:57:03 +01:00
Sebastian Dröge
c44badd26a Mark various GskTransform functions as nullable in their return value
Various transforms are normalized with their next transform, and if they
end up being the identity transform will return NULL.

For example a translation by (x,y,z) and followed by (-x,-y,-z) will
result in NULL.
2022-01-14 11:57:23 +02:00
Jonas Ådahl
66ebc660b4 wayland/surface: Use wl_surface_offset() instead of x,y of attach()
This makes the hotspot of DND surfaces work when using the Vulkan and
OpenGL renderers.

This bumps the CI image used to the newly built image. This is needed to
install a new enough libwayland-client.so needed for wl_surface.offset.

This is done by adding wayland as a meson subproject, building it
on-demand if the version in the system is not new enough. As
libwayland-client.so is pulled in implicitly when linking to gtk4, the
compile step needs LD_LIBRARY_PATH set to make ld find the right library
to link to.
2022-01-14 09:27:07 +01:00
Luca Bacci
06e5da456f Merge branch 'win32-fix-altgr-gtk4' into 'main'
IMContextSimple/IMContextIME: Fix AltGr not working on Win32 [GTK4]

See merge request GNOME/gtk!4375
2022-01-13 23:02:50 +00:00
Boyuan Yang
689486eae5 Update Chinese (China) translation 2022-01-13 20:20:45 +00:00
Emmanuele Bassi
48dc6ecfe3 Merge branch 'ebassi/docs-repo-link' into 'main'
docs: Point source links to the correct branch

See merge request GNOME/gtk!4373
2022-01-13 16:58:47 +00:00
Philip Zander
b9bc7d9166 IMContextSimple/IMContextIME: Fix AltGr not working on Win32
The old code assumed that any key press containing Ctrl or Alt cannot be
regular text input. This is not correct on Win32 as AltGr = Ctrl + Alt.
2022-01-13 17:26:59 +01:00
Emmanuele Bassi
63ee135a1e Update the link to the development branch
The default development branch for GTK is now "main".
2022-01-13 14:42:34 +00:00
Emmanuele Bassi
ca2aa52ba9 docs: Point to the correct development branch
The default development branch of GTK is now "main".
2022-01-13 14:39:39 +00:00
Emmanuele Bassi
96d28738c9 docs: Point source links to the correct branch
The default development branch for GTK is now "main".
2022-01-13 14:39:03 +00:00
Piotr Drąg
e4b05e55e1 Update POTFILES.in 2022-01-13 13:43:15 +01:00
Luca Bacci
4a4a579fd9 Merge branch 'forward-port-gdk-win32-keymap-bugfixes-to-gtk4' into 'main'
GdkWin32Keymap bugfixes

See merge request GNOME/gtk!4372
2022-01-12 21:36:19 +00:00
Fran Dieguez
df716e5c9f Update Galician translation 2022-01-12 21:35:13 +00:00
Fran Dieguez
52000177d9 Update Galician translation 2022-01-12 21:34:57 +00:00
David Hogan
7d6257cb1e gdkkeys-win32: Perform keyboard layout substitution
For some users, GetKeyboardLayoutNameA() returns an alias instead of the
fully resolved keyboard layout identifier. In that case, we have to
query the registry to resolve the alias before we can look up the DLL
path.

See comments under https://gitlab.gnome.org/GNOME/gtk/-/issues/4610
2022-01-12 21:44:28 +01:00
Philip Zander
db0234ecb4 gdkkeys-win32: Fix handling of SGCAPS
Contrary to what you can read on the internet, SGCAPS keys don't work
by having capslock toggle the KBDCTRL bit, they actually have two
consecutive table entries, the first of which is for the normal
version and the second of which is for the capslocked version.

Background: SGCAPS is short for Swiss German caps because Swiss German
was the first layout to use this feature. For keys with the SGCAPS flag,
capslock has a different effect than pressing shift. For example:
Shift + ü = è,  CapsLock + ü = Ü,  CapsLock + Shift + ü = È
2022-01-12 21:44:24 +01:00
Philip Zander
438fad803e gdkkeys-win32: Fix crash when keyboard DLL failed to load
DLL loading failures should not happen under normal circumstances, but
we should at least try not to crash and and print better diagnostic
messages if they do happen.

See https://gitlab.gnome.org/GNOME/gtk/-/issues/4610
2022-01-12 21:44:15 +01:00
Philip Zander
82f8f878bc gdkkeys-win32: Add keysym mapping for capslock key
Add missing mapping between VK_CAPITAL and GDK_KEY_Caps_Lock, so
applications get a meaningful keyval rather than ffffff.
2022-01-12 21:44:07 +01:00
Philip Zander
b0818f9535 gdkkeys-win32: Fix capslock handling
Previously, we treated CapsLock and KanaLock as part of the global
keyboard state, much like NumLock and ScrollLock, rather than using
the supplied modifier mask. This was because GDK does not have a
modifier mask for KanaLock, only for CapsLock, so it would not have been
possible to properly support it.

However, this approach ended up causing problems, with certain keyboard
shortcuts not registering when capslock was active. This was first
observed in Inkscape [0] and appears to affect shortcuts consisting of a
single key (like 'a') with no additional modifiers (wheareas shortcuts
like 'ctrl+a' work).

So now we are using the supplied GDK_LOCK_MASK instead, and dropped
support for KanaLock, which we probably don't need anyway (since regular
text input should be handled by the IME input module -- the keymap is
mainly for shortcuts and keybindings, where you don't really want
KanaLock).

[0] https://gitlab.com/inkscape/inkscape/-/issues/3082
2022-01-12 21:43:53 +01:00
Luca Bacci
c71cb35e9d Merge branch 'forward-port-rewrite-gdkwin32keymap-to-gtk4' into 'main'
Rewrite GdkWin32Keymap (V2)

Closes #1033 and #2055

See merge request GNOME/gtk!4338
2022-01-12 19:53:54 +00:00
Luca Bacci
5bf5d25bc1 Merge branch 'fix-build-no-pangoft' into 'main'
Improve and fix building font features on Windows (was: Fix builds without PangoFT2)

Closes #4605

See merge request GNOME/gtk!4339
2022-01-12 19:53:39 +00:00
Matthias Clasen
45d6b3ba51 Merge branch 'fabian.kirsch-main-patch-28134' into 'main'
corrected small typo input-handling.md

See merge request GNOME/gtk!4368
2022-01-12 19:38:10 +00:00
Matthias Clasen
e4e1b9ccbe Merge branch '4627-printing-Unref-old-spool_io-before-setting-new-one' into 'main'
printing: Unref old spool_io before setting new one

Closes #4627

See merge request GNOME/gtk!4370
2022-01-12 19:37:18 +00:00
Matthias Clasen
d50df7db37 Merge branch 'revert-texture-annotations' into 'main'
Revert "gir: Annotate `GdkTexture` constructors for reading from a...

See merge request GNOME/gtk!4371
2022-01-12 19:34:18 +00:00
Philip Zander
ea65abc7e2 Rewrite GdkWin32Keymap (load table directly from layout DLL)
The old code used repeated calls to `ToUnicodeEx` to populate
the translation table, which is slow and buggy. The new code
directly loads the layout driver DLLs from Windows.

See https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/4338
2022-01-12 19:01:35 +01:00
Marek Kasik
915090f118 printing: Unref old spool_io before setting new one
Unref private spool_io of GtkPrintJob before setting it to a new one
in gtk_print_job_set_source_file() and gtk_print_job_set_source_fd()
to prevent a leak.

Fixes: #4627
2022-01-12 12:47:28 +01:00
Chun-wei Fan
629dcd3dcf meson.build: Don't apply iso-codes cflag on Windows
They are no longer applicable for Windows builds.
2022-01-12 17:29:30 +08:00
Chun-wei Fan
169172a9e0 demos: Always build font explorer demo
We are no longer using PangoFT2 APIs in this demo, so make sure that we build
it on all builds since we already depend on a HarfBuzz/Pango version that
provide everything that we need here.

Drop the unnecessary pangofc-font.h include as a result.
2022-01-12 17:29:30 +08:00
Chun-wei Fan
0a3fad4d47 gtk-demo/language-names.c: Acquire language names natively on Windows
Like what was done on gtk/language-names.c, acquire the language names via the
native Windows NLS APIs, eliminating a run-time dependency on iso-codes on
Windows.
2022-01-12 17:29:30 +08:00
Chun-wei Fan
b666a767e4 language-names: Use Windows APIs to acquire language names
Instead of relying on the iso-codes package, use the native Windows NLS APIs to
acquire the localized (translated) language names so that we do not need to
incur an extra runtime dependency on Windows.  It's not coverering 100% of the
languages that we would like to support through this, but should cover much of
the things that are required.
2022-01-12 17:29:30 +08:00
Chun-wei Fan
ee2dd1acc7 gtk/meson.build: Fix builds without PangoFT2
We aren't really using PangoFT2 for [language|script]-names.c, and are
always using items from them, so make sure they are being built.

Also always include the pangoft2 dependency in gtk_dep if it is found.
2022-01-12 17:29:28 +08:00
Fabian Kirsch
4f36583898 corrected small typo input-handling.md 2022-01-12 09:02:01 +00:00
456 changed files with 66415 additions and 70799 deletions

View File

@@ -25,7 +25,7 @@ variables:
BACKEND_FLAGS: "-Dx11-backend=true -Dwayland-backend=true -Dbroadway-backend=true"
FEATURE_FLAGS: "-Dvulkan=enabled -Dcloudproviders=enabled"
MESON_TEST_TIMEOUT_MULTIPLIER: 3
FEDORA_IMAGE: "registry.gitlab.gnome.org/gnome/gtk/fedora:v35"
FEDORA_IMAGE: "registry.gitlab.gnome.org/gnome/gtk/fedora:v36"
FLATPAK_IMAGE: "registry.gitlab.gnome.org/gnome/gnome-runtime-images/gnome:master"
.only-default:
@@ -88,7 +88,7 @@ fedora-x86_64:
- meson compile -C _build
- meson install -C _build
- PKG_CONFIG_PATH=${CI_PROJECT_DIR}/_install/lib64/pkgconfig:${CI_PROJECT_DIR}/_install/share/pkgconfig meson setup _build_hello examples/hello
- meson compile -C _build_hello
- LD_LIBRARY_PATH=${CI_PROJECT_DIR}/_install/lib64 meson compile -C _build_hello
- .gitlab-ci/run-tests.sh _build x11
- .gitlab-ci/run-tests.sh _build wayland
- .gitlab-ci/run-tests.sh _build waylandgles
@@ -156,6 +156,11 @@ msys2-mingw64:
variables:
MSYSTEM: "MINGW64"
CHERE_INVOKING: "yes"
artifacts:
when: always
expose_as: 'Windows_DLL_MSYS2_64_bit_toolchain'
paths:
- "${CI_PROJECT_DIR}/_build/gtkdll.tar.gz"
macos:
extends: .only-default

View File

@@ -95,6 +95,8 @@ RUN dnf -y install \
weston-libs \
which \
xorg-x11-server-Xvfb \
&& dnf install -y 'dnf-command(builddep)' \
&& dnf builddep -y wayland \
&& dnf clean all
# Enable sudo for wheel users

View File

@@ -6,7 +6,7 @@ call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliar
:: FIXME: make warnings fatal
pip3 install --upgrade --user meson==0.59 || goto :error
meson -Dmedia-gstreamer=disabled _build || goto :error
meson -Ddebug=false -Dmedia-gstreamer=disabled _build || goto :error
ninja -C _build || goto :error
goto :EOF

View File

@@ -73,3 +73,5 @@ unset CCACHE_DISABLE
ninja -C _build
ccache --show-stats
tar zcf _build/gtkdll.tar.gz _build/gtk/libgtk*.dll

71
NEWS
View File

@@ -1,5 +1,72 @@
Overview of Changes
===================
Overview of Changes in 4.6.1, 11-02-2022
========================================
* GtkFontChooser:
- Stop using PangoFc api
- Fix a crash
- Use new HarfBuzz api
* GtkMenuButton:
- Update accessible description
* GtkTextView:
- Fix intra-widget dnd
* Printing:
- Fix an fd leak
* Input:
- Make sure input methods get focus-in events
- Always flush events to avoid scroll event pileup
- Support hold events
- Update keysyms from libxkbcommon
* Theme:
- Improve text selection legibility
* Introspection:
- Add missing nullable annotations everywhere
* Build:
- Make stack noexec again
- Avoid symbol leaks
- Drop unneeded script data
* Windows:
- Stop using WM_SYNCPAINT
- Relax check for GL 3.x legacy contexts
- Use native apis for language names
- Rewrite the keymap code
- Use the GL renderer by default
* Wayland:
- Fix support for the new high-contrast setting
- Avoid redundant scale changes
- Fix DND hotspot handling
- Don't always restore the saved size when floating
* MacOS:
- Various performance improvements
* Translation updates:
Brazilian Portuguese
Catalan
Chinese (China)
Galician
Hebrew
Japanese
Lithuanian
Persian
Polish
Portuguese
Russian
Slovenian
Spanish
Ukrainian
Overview of Changes in 4.6.0, 30-12-2021
========================================
* GtkProgressBar:
- Fix handling of "inverted"

View File

@@ -43,7 +43,8 @@
"sources" : [
{
"type" : "git",
"url" : "https://gitlab.freedesktop.org/wayland/wayland.git"
"url" : "https://gitlab.freedesktop.org/wayland/wayland.git",
"branch" : "main"
}
]
},

View File

@@ -43,7 +43,8 @@
"sources" : [
{
"type" : "git",
"url" : "https://gitlab.freedesktop.org/wayland/wayland.git"
"url" : "https://gitlab.freedesktop.org/wayland/wayland.git",
"branch" : "main"
}
]
},

View File

@@ -43,7 +43,8 @@
"sources" : [
{
"type" : "git",
"url" : "https://gitlab.freedesktop.org/wayland/wayland.git"
"url" : "https://gitlab.freedesktop.org/wayland/wayland.git",
"branch" : "main"
}
]
},

View File

@@ -13,7 +13,7 @@ if 'DESTDIR' not in os.environ:
gtk_moduledir = os.path.join(gtk_libdir, 'gtk-' + gtk_api_version, gtk_abi_version)
gtk_printmodule_dir = os.path.join(gtk_moduledir, 'printbackends')
gtk_immodule_dir = os.path.join(gtk_moduledir, 'immodules')
gtk_mediamodule_dir = os.path.join(gtk_moduledir, 'media')
print('Compiling GSettings schemas...')
glib_compile_schemas = subprocess.check_output(['pkg-config',
@@ -40,6 +40,6 @@ if 'DESTDIR' not in os.environ:
gio_querymodules = 'gio-querymodules'
subprocess.call([gio_querymodules, gtk_printmodule_dir])
print('Updating module cache for input methods...')
os.makedirs(gtk_immodule_dir, exist_ok=True)
subprocess.call([gio_querymodules, gtk_immodule_dir])
print('Updating module cache for media backends...')
os.makedirs(gtk_mediamodule_dir, exist_ok=True)
subprocess.call([gio_querymodules, gtk_mediamodule_dir])

View File

@@ -12,7 +12,6 @@
*/
#include <gtk/gtk.h>
#include <pango/pangofc-font.h>
#include <hb.h>
#include <hb-ot.h>
#include <glib/gi18n.h>

View File

@@ -18,15 +18,81 @@
#include "language-names.h"
#ifdef G_OS_WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#else
#ifndef ISO_CODES_PREFIX
#define ISO_CODES_PREFIX "/usr"
#endif
#define ISO_CODES_DATADIR ISO_CODES_PREFIX "/share/xml/iso-codes"
#define ISO_CODES_LOCALESDIR ISO_CODES_PREFIX "/share/locale"
#endif
static GHashTable *language_map;
#ifdef G_OS_WIN32
/* if we are using native Windows use native Windows API for language names */
static BOOL CALLBACK
get_win32_all_locales_scripts (LPWSTR locale_w, DWORD flags, LPARAM param)
{
wchar_t *langname_w = NULL;
wchar_t locale_abbrev_w[9];
gchar *langname, *locale_abbrev, *locale, *p;
gint i;
const LCTYPE iso639_lctypes[] = { LOCALE_SISO639LANGNAME, LOCALE_SISO639LANGNAME2 };
GHashTable *ht_scripts_langs = (GHashTable *) param;
PangoLanguage *lang;
gint langname_size, locale_abbrev_size;
langname_size = GetLocaleInfoEx (locale_w, LOCALE_SLOCALIZEDDISPLAYNAME, langname_w, 0);
if (langname_size == 0)
return FALSE;
langname_w = g_new0 (wchar_t, langname_size);
if (langname_size == 0)
return FALSE;
GetLocaleInfoEx (locale_w, LOCALE_SLOCALIZEDDISPLAYNAME, langname_w, langname_size);
langname = g_utf16_to_utf8 (langname_w, -1, NULL, NULL, NULL);
locale = g_utf16_to_utf8 (locale_w, -1, NULL, NULL, NULL);
p = strchr (locale, '-');
lang = pango_language_from_string (locale);
if (g_hash_table_lookup (ht_scripts_langs, lang) == NULL)
g_hash_table_insert (ht_scripts_langs, lang, langname);
/*
* Track 3+-letter ISO639-2/3 language codes as well (these have a max length of 9 including terminating NUL)
* ISO639-2: iso639_lctypes[0] = LOCALE_SISO639LANGNAME
* ISO639-3: iso639_lctypes[1] = LOCALE_SISO639LANGNAME2
*/
for (i = 0; i < 2; i++)
{
locale_abbrev_size = GetLocaleInfoEx (locale_w, iso639_lctypes[i], locale_abbrev_w, 0);
if (locale_abbrev_size > 0)
{
GetLocaleInfoEx (locale_w, iso639_lctypes[i], locale_abbrev_w, locale_abbrev_size);
locale_abbrev = g_utf16_to_utf8 (locale_abbrev_w, -1, NULL, NULL, NULL);
lang = pango_language_from_string (locale_abbrev);
if (g_hash_table_lookup (ht_scripts_langs, lang) == NULL)
g_hash_table_insert (ht_scripts_langs, lang, langname);
g_free (locale_abbrev);
}
}
g_free (locale);
g_free (langname_w);
return TRUE;
}
#else /* non-Windows */
static char *
get_first_item_in_semicolon_list (const char *list)
{
@@ -210,6 +276,7 @@ languages_variant_init (const char *variant)
g_free (filename);
g_free (buf);
}
#endif
static void
languages_init (void)
@@ -218,8 +285,13 @@ languages_init (void)
return;
language_map = g_hash_table_new_full (NULL, NULL, NULL, g_free);
#ifdef G_OS_WIN32
g_return_if_fail (EnumSystemLocalesEx (&get_win32_all_locales_scripts, LOCALE_ALL, (LPARAM) language_map, NULL));
#else
languages_variant_init ("iso_639");
languages_variant_init ("iso_639_3");
#endif
}
const char *

View File

@@ -1040,7 +1040,7 @@ out:
g_signal_connect_swapped (G_OBJECT (demo), "destroy", G_CALLBACK (g_application_quit), app);
}
else
gtk_widget_show (GTK_WIDGET (window));
gtk_window_present (GTK_WINDOW (window));
if (autoquit)
g_timeout_add_seconds (1, auto_quit, app);

View File

@@ -98,6 +98,7 @@ demos = files([
'transparent.c',
'tree_store.c',
'video_player.c',
'font_features.c',
])
gtkdemo_deps = [ libgtk_dep, ]
@@ -128,14 +129,9 @@ extra_demo_sources = files([
'script-names.c',
'unicode-names.c',
'suggestionentry.c',
'language-names.c',
])
if harfbuzz_dep.found() and pangoft_dep.found()
demos += files(['font_features.c'])
extra_demo_sources += files(['language-names.c'])
gtkdemo_deps += [ harfbuzz_dep, epoxy_dep ]
endif
if os_unix
demos += files('pagesetup.c')
endif
@@ -164,7 +160,7 @@ endif
ld = find_program('ld', required : false)
if build_machine.system() == 'linux' and objcopy.found() and objcopy_supports_add_symbol and ld.found()
if not meson.is_cross_build() and build_machine.cpu_family() != 'arm' and build_machine.system() == 'linux' and objcopy.found() and objcopy_supports_add_symbol and ld.found()
glib_compile_resources = find_program('glib-compile-resources')
# Create the resource blob
@@ -174,6 +170,7 @@ if build_machine.system() == 'linux' and objcopy.found() and objcopy_supports_ad
depfile : 'gtkdemo.gresource.d',
command : [glib_compile_resources,
'--generate',
'--internal',
'--target=@OUTPUT@',
'--dependency-file=@DEPFILE@',
'--sourcedir=' + meson.current_source_dir(),
@@ -187,6 +184,7 @@ if build_machine.system() == 'linux' and objcopy.found() and objcopy_supports_ad
depfile : 'gtkdemo_resources.c.d',
command : [glib_compile_resources,
'--generate-source',
'--internal',
'--target=@OUTPUT@',
'--dependency-file=@DEPFILE@',
'--sourcedir=' + meson.current_source_dir(),
@@ -200,6 +198,7 @@ if build_machine.system() == 'linux' and objcopy.found() and objcopy_supports_ad
input : gtkdemo_gresource,
output : 'gtkdemo_resources.o',
command : [ld,
'-z', 'noexecstack',
'-r',
'-b','binary',
'@INPUT@',
@@ -210,6 +209,7 @@ if build_machine.system() == 'linux' and objcopy.found() and objcopy_supports_ad
input : gtkdemo_resources_binary,
output : 'gtkdemo_resources2.o',
command : [objcopy,
'--strip-all',
'--add-symbol','_g_binary_gtkdemo_resource_data=.data:0',
'@INPUT@',
'@OUTPUT@'])

View File

@@ -871,7 +871,7 @@ activate (GApplication *app)
update_ui ();
gtk_widget_show (main_window);
gtk_window_present (GTK_WINDOW (main_window));
}
static void

View File

@@ -8,7 +8,7 @@ endif
ld = find_program('ld', required : false)
if build_machine.system() == 'linux' and objcopy.found() and objcopy_supports_add_symbol and ld.found()
if not meson.is_cross_build() and build_machine.cpu_family() != 'arm' and build_machine.system() == 'linux' and objcopy.found() and objcopy_supports_add_symbol and ld.found()
glib_compile_resources = find_program('glib-compile-resources')
# Create the resource blob
@@ -18,6 +18,7 @@ if build_machine.system() == 'linux' and objcopy.found() and objcopy_supports_ad
depfile: 'widgetfactory.gresource.d',
command : [glib_compile_resources,
'--generate',
'--internal',
'--target=@OUTPUT@',
'--dependency-file=@DEPFILE@',
'--sourcedir=' + meson.current_source_dir(),
@@ -31,6 +32,7 @@ if build_machine.system() == 'linux' and objcopy.found() and objcopy_supports_ad
depfile: 'widgetfactory_resources.c.d',
command : [glib_compile_resources,
'--generate-source',
'--internal',
'--target=@OUTPUT@',
'--dependency-file=@DEPFILE@',
'--sourcedir=' + meson.current_source_dir(),
@@ -44,6 +46,7 @@ if build_machine.system() == 'linux' and objcopy.found() and objcopy_supports_ad
input : widgetfactory_gresource,
output : 'widgetfactory_resources.o',
command : [ld,
'-z', 'noexecstack',
'-r',
'-b','binary',
'@INPUT@',
@@ -54,6 +57,7 @@ if build_machine.system() == 'linux' and objcopy.found() and objcopy_supports_ad
input : widgetfactory_resources_binary,
output : 'widgetfactory_resources2.o',
command : [objcopy,
'--strip-all',
'--add-symbol','_g_binary_widgetfactory_resource_data=.data:0',
'@INPUT@',
'@OUTPUT@'])

View File

@@ -2053,6 +2053,7 @@ activate (GApplication *app)
{ "win.open", { "<Control>o", NULL } },
{ "win.record", { "<Control>r", NULL } },
{ "win.lock", { "<Control>l", NULL } },
{ "win.fullscreen", { "F11", NULL } },
};
struct {
const char *action_and_target;
@@ -2359,7 +2360,7 @@ activate (GApplication *app)
model = (GMenuModel *)gtk_builder_get_object (builder, "new_style_context_menu_model");
set_up_context_popover (widget, model);
gtk_widget_show (GTK_WIDGET (window));
gtk_window_present (window);
g_object_unref (builder);
}

View File

@@ -7,20 +7,21 @@ authors = "GTK Development Team"
logo_url = "gtk-logo.svg"
license = "GPL-2.1-or-later"
description = "The GTK toolkit"
dependencies = [ "GObject-2.0" ]
devhelp = true
[dependencies."GObject-2.0"]
name = "GObject"
description = "The base type system library"
docs_url = "https://docs.gtk.org/gobject/"
dependencies = ["Gdk-4.0"]
[dependencies."Gdk-4.0"]
name = "GDK"
description = "The GTK drawing kit"
docs_url = "https://docs.gtk.org/gdk/"
[theme]
name = "basic"
show_index_summary = true
[source-location]
base_url = "https://gitlab.gnome.org/GNOME/gtk/-/blob/master/"
base_url = "https://gitlab.gnome.org/GNOME/gtk/-/blob/main/"
[extra]
content_images = [

View File

@@ -7,20 +7,20 @@ authors = "GTK Development Team"
logo_url = "gtk-logo.svg"
license = "GPL-2.1-or-later"
description = "The GTK toolkit"
dependencies = [ "GObject-2.0" ]
dependencies = ["Gdk-4.0"]
devhelp = true
[dependencies."GObject-2.0"]
name = "GObject"
description = "The base type system library"
docs_url = "https://docs.gtk.org/gobject/"
[dependencies."Gdk-4.0"]
name = "GDK"
description = "The GTK drawing kit"
docs_url = "https://docs.gtk.org/gdk4/"
[theme]
name = "basic"
show_index_summary = true
[source-location]
base_url = "https://gitlab.gnome.org/GNOME/gtk/-/blob/master/"
base_url = "https://gitlab.gnome.org/GNOME/gtk/-/blob/main/"
[extra]
content_images = [

View File

@@ -8,7 +8,7 @@ authors = "GTK Development Team"
logo_url = "gtk-logo.svg"
license = "LGPL-2.1-or-later"
description = "The GTK toolkit"
dependencies = [ "GObject-2.0", "cairo-1.0", "Pango-1.0", "GdkWayland-4.0", "GdkX11-4.0" ]
dependencies = ["GObject-2.0", "Gio-2.0", "cairo-1.0", "Pango-1.0", "GdkPixbuf-2.0"]
devhelp = true
search_index = true
@@ -17,6 +17,11 @@ search_index = true
description = "The base type system library"
docs_url = "https://docs.gtk.org/gobject/"
[dependencies."Gio-2.0"]
name = "GIO"
description = "GObject Interfaces and Objects, Networking, IPC, and I/O"
docs_url = "https://docs.gtk.org/gio/"
[dependencies."cairo-1.0"]
name = "Cairo"
description = "A 2D graphics library with support for multiple output devices"
@@ -27,12 +32,19 @@ search_index = true
description = "Text shaping and rendering"
docs_url = "https://docs.gtk.org/Pango/"
[dependencies."GdkWayland-4.0"]
[dependencies."GdkPixbuf-2.0"]
name = "GdkPixbuf"
description = "Image data loading"
docs_url = "https://docs.gtk.org/gdk-pixbuf/"
related = ["GdkWayland-4.0", "GdkX11-4.0"]
[related."GdkWayland-4.0"]
name = "GdkWayland"
description = "GDK Wayland Backend"
docs_url = "https://docs.gtk.org/gdk4-wayland/"
[dependencies."GdkX11-4.0"]
[related."GdkX11-4.0"]
name = "GdkX11"
description = "GDK X11 Backend"
docs_url = "https://docs.gtk.org/gdk4-x11/"
@@ -43,7 +55,7 @@ show_index_summary = true
show_class_hierarchy = true
[source-location]
base_url = "https://gitlab.gnome.org/GNOME/gtk/-/blob/master/"
base_url = "https://gitlab.gnome.org/GNOME/gtk/-/blob/main/"
[extra]
content_files = [

View File

@@ -8,25 +8,16 @@ authors = "GTK Development Team"
logo_url = "gtk-logo.svg"
license = "LGPL-2.1-or-later"
description = "The GTK toolkit"
dependencies = [ "GObject-2.0", "Graphene-1.0", "Pango-1.0", "Gdk-4.0" ]
devhelp = true
search_index = true
[dependencies."GObject-2.0"]
name = "GObject"
description = "The base type system library"
docs_url = "https://docs.gtk.org/gobject/"
dependencies = ["Graphene-1.0", "Gdk-4.0"]
[dependencies."Graphene-1.0"]
name = "Graphene"
description = "A thin layer of mathematical types for 3D libraries"
docs_url = "https://ebassi.github.io/graphene/docs/"
[dependencies."Pango-1.0"]
name = "Pango"
description = "Text shaping and rendering"
docs_url = "https://docs.gtk.org/Pango/"
[dependencies."Gdk-4.0"]
name = "GDK"
description = "The GTK windowing system abstraction"
@@ -38,7 +29,7 @@ show_index_summary = true
show_class_hierarchy = true
[source-location]
base_url = "https://gitlab.gnome.org/GNOME/gtk/-/blob/master/"
base_url = "https://gitlab.gnome.org/GNOME/gtk/-/blob/main/"
[extra]
content_images = [

View File

@@ -170,7 +170,7 @@ activate (GtkApplication *app,
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_widget_set_halign (box, GTK_ALIGN_CENTER);
gtk_widget_set_valign (box, GTK_ALIGN_CENTER);
gtk_window_set_child (GTK_WINDOW (window), box);
button = gtk_button_new_with_label ("Hello World");
@@ -752,7 +752,7 @@ templates, resources, application menus, settings, [class@Gtk.HeaderBar], [class
The full, buildable sources for these examples can be found in the
`examples` directory of the GTK source distribution, or
[online](https://gitlab.gnome.org/GNOME/gtk/blob/master/examples) in the GTK
[online](https://gitlab.gnome.org/GNOME/gtk/blob/main/examples) in the GTK
source code repository. You can build each example separately by using make
with the `Makefile.example` file. For more information, see the `README`
included in the examples directory.
@@ -972,7 +972,7 @@ example_app_window_class_init (ExampleAppWindowClass *class)
...
```
([full source](https://gitlab.gnome.org/GNOME/gtk/blob/master/examples/application2/exampleappwin.c))
([full source](https://gitlab.gnome.org/GNOME/gtk/blob/main/examples/application2/exampleappwin.c))
You may have noticed that we used the `_from_resource()` variant of the function
that sets a template. Now we need to use
@@ -1043,7 +1043,7 @@ example_app_window_class_init (ExampleAppWindowClass *class)
...
```
([full source](https://gitlab.gnome.org/GNOME/gtk/blob/master/examples/application3/exampleappwin.c))
([full source](https://gitlab.gnome.org/GNOME/gtk/blob/main/examples/application3/exampleappwin.c))
Now we revisit the `example_app_window_open()` function that is called for each
commandline argument, and construct a GtkTextView that we then add as a page
@@ -1087,7 +1087,7 @@ example_app_window_open (ExampleAppWindow *win,
...
```
([full source](https://gitlab.gnome.org/GNOME/gtk/blob/master/examples/application3/exampleappwin.c))
([full source](https://gitlab.gnome.org/GNOME/gtk/blob/main/examples/application3/exampleappwin.c))
Lastly, we add a [class@Gtk.StackSwitcher] to the titlebar area in the UI file, and we
tell it to display information about our stack.
@@ -1188,7 +1188,7 @@ example_app_class_init (ExampleAppClass *class)
...
```
([full source](https://gitlab.gnome.org/GNOME/gtk/blob/master/examples/application4/exampleapp.c))
([full source](https://gitlab.gnome.org/GNOME/gtk/blob/main/examples/application4/exampleapp.c))
Our preferences menu item does not do anything yet, but the Quit menu item
is fully functional. Note that it can also be activated by the usual Ctrl-Q
@@ -1258,7 +1258,7 @@ example_app_window_init (ExampleAppWindow *win)
...
```
([full source](https://gitlab.gnome.org/GNOME/gtk/blob/master/examples/application5/exampleappwin.c))
([full source](https://gitlab.gnome.org/GNOME/gtk/blob/main/examples/application5/exampleappwin.c))
The code to connect the font setting is a little more involved, since there
is no simple object property that it corresponds to, so we are not going to
@@ -1429,7 +1429,7 @@ preferences_activated (GSimpleAction *action,
...
```
([full source](https://gitlab.gnome.org/GNOME/gtk/blob/master/examples/application6/exampleapp.c))
([full source](https://gitlab.gnome.org/GNOME/gtk/blob/main/examples/application6/exampleapp.c))
After all this work, our application can now show a preference dialog
like this:
@@ -1549,7 +1549,7 @@ example_app_window_init (ExampleAppWindow *win)
...
```
([full source](https://gitlab.gnome.org/GNOME/gtk/blob/master/examples/application7/exampleappwin.c))
([full source](https://gitlab.gnome.org/GNOME/gtk/blob/main/examples/application7/exampleappwin.c))
With the search bar, our application now looks like this:
@@ -1682,7 +1682,7 @@ example_app_window_init (ExampleAppWindow *win)
...
```
([full source](https://gitlab.gnome.org/GNOME/gtk/blob/master/examples/application8/exampleappwin.c))
([full source](https://gitlab.gnome.org/GNOME/gtk/blob/main/examples/application8/exampleappwin.c))
What our application looks like now:
@@ -1760,10 +1760,10 @@ example_app_window_init (ExampleAppWindow *win)
...
```
([full source](https://gitlab.gnome.org/GNOME/gtk/blob/master/examples/application9/exampleappwin.c))
([full source](https://gitlab.gnome.org/GNOME/gtk/blob/main/examples/application9/exampleappwin.c))
We also need a function that counts the lines of the currently active tab,
and updates the `lines` label. See the [full source](https://gitlab.gnome.org/GNOME/gtk/blob/master/examples/application9/exampleappwin.c)
and updates the `lines` label. See the [full source](https://gitlab.gnome.org/GNOME/gtk/blob/main/examples/application9/exampleappwin.c)
if you are interested in the details.
This brings our example application to this appearance:

View File

@@ -8,24 +8,10 @@ authors = "GTK Development Team"
logo_url = "gtk-logo.svg"
license = "LGPL-2.1-or-later"
description = "The GTK toolkit"
dependencies = [ "GObject-2.0", "Graphene-1.0", "Pango-1.0", "Gdk-4.0", "Gsk-4.0" ]
devhelp = true
search_index = true
[dependencies."GObject-2.0"]
name = "GObject"
description = "The base type system library"
docs_url = "https://docs.gtk.org/gobject/"
[dependencies."Graphene-1.0"]
name = "Graphene"
description = "A thin layer of mathematical types for 3D libraries"
docs_url = "https://ebassi.github.io/graphene/docs"
[dependencies."Pango-1.0"]
name = "Pango"
description = "Text shaping and rendering"
docs_url = "https://docs.gtk.org/Pango/"
dependencies = ["Gdk-4.0", "Gsk-4.0"]
[dependencies."Gdk-4.0"]
name = "GDK"
@@ -37,13 +23,35 @@ search_index = true
description = "The GTK rendering abstraction"
docs_url = "https://docs.gtk.org/gsk4/"
related = ["Pango-1.0", "Graphene-1.0", "GObject-2.0", "Gio-2.0"]
[related."GObject-2.0"]
name = "GObject"
description = "The base type system library"
docs_url = "https://docs.gtk.org/gobject/"
[related."Gio-2.0"]
name = "GIO"
description = "GObject Interfaces and Objects, Networking, IPC, and I/O"
docs_url = "https://docs.gtk.org/gio/"
[related."Graphene-1.0"]
name = "Graphene"
description = "A thin layer of mathematical types for 3D libraries"
docs_url = "https://ebassi.github.io/graphene/docs"
[related."Pango-1.0"]
name = "Pango"
description = "Text shaping and rendering"
docs_url = "https://docs.gtk.org/Pango/"
[theme]
name = "basic"
show_index_summary = true
show_class_hierarchy = true
[source-location]
base_url = "https://gitlab.gnome.org/GNOME/gtk/-/blob/master/"
base_url = "https://gitlab.gnome.org/GNOME/gtk/-/blob/main/"
[extra]
# The same order will be used when generating the index

View File

@@ -42,7 +42,7 @@ univocally identifies events that are related to the same
interaction.
When GTK creates a `GdkSurface`, it connects to the ::event
signal on it, which receives all of these input events. Surfaces have
signal on it, which receives all of these input events. Surfaces
have signals and properties, e.g. to deal with window management
related events.

View File

@@ -1382,5 +1382,5 @@ a new family of widgets for this purpose that uses list models instead
of tree models, and widgets instead of cell renderers.
To learn more about the new list widgets, you can read the [List Widget
Overview](#ListWidget).
Overview](https://docs.gtk.org/gtk4/section-list-widget.html).

View File

@@ -26,7 +26,7 @@ GTK with your code applied, and run the test suite, on multiple platforms
and architectures, and verify that nothing breaks. They also allow us to
do proper code reviews, so we can iterate over the changes.
You should follow the [contribution guide](https://gitlab.gnome.org/GNOME/gtk/blob/master/CONTRIBUTING.md)
You should follow the [contribution guide](https://gitlab.gnome.org/GNOME/gtk/blob/main/CONTRIBUTING.md)
for GTK, available on GitLab.
If you want to discuss your approach before or after working on it,

View File

@@ -372,7 +372,7 @@ library you are using:
The `test` accessibility backend is recommended for test suites and remote
continuous integration pipelines.
### `XDG_DTA_HOME`, `XDG_DATA_DIRS`
### `XDG_DATA_HOME`, `XDG_DATA_DIRS`
GTK uses these environment variables to locate icon themes
and MIME information. For more information, see the

View File

@@ -31,8 +31,7 @@
* `GdkAppLaunchContext` handles launching an application in a graphical context.
*
* It is an implementation of `GAppLaunchContext` that provides startup
* notification and allows to launch applications on a specific screen
* or workspace.
* notification and allows to launch applications on a specific workspace.
*
* ## Launching an application
*
@@ -41,7 +40,6 @@
*
* context = gdk_display_get_app_launch_context (display);
*
* gdk_app_launch_context_set_display (display);
* gdk_app_launch_context_set_timestamp (gdk_event_get_time (event));
*
* if (!g_app_info_launch_default_for_uri ("http://www.gtk.org", context, &error))
@@ -196,6 +194,10 @@ gdk_app_launch_context_get_display (GdkAppLaunchContext *context)
* This only works when running under a window manager that
* supports multiple workspaces, as described in the
* [Extended Window Manager Hints](http://www.freedesktop.org/Standards/wm-spec).
* Specifically this sets the `_NET_WM_DESKTOP` property described
* in that spec.
*
* This only works when using the X11 backend.
*
* When the workspace is not specified or @desktop is set to -1,
* it is up to the window manager to pick one, typically it will

View File

@@ -576,7 +576,7 @@ gdk_content_deserialize_async (GInputStream *stream,
/**
* gdk_content_deserialize_finish:
* @result: the `GAsyncResult`
* @value: return location for the result of the operation
* @value: (out): return location for the result of the operation
* @error: return location for an error
*
* Finishes a content deserialization operation.

View File

@@ -132,8 +132,6 @@ gdk_device_class_init (GdkDeviceClass *klass)
* GdkDevice:source: (attributes org.gtk.Property.get=gdk_device_get_source)
*
* Source type for the device.
*
* Deprecated: 4.6: Use GdkDeviceTool:tool-type instead
*/
device_props[PROP_SOURCE] =
g_param_spec_enum ("source",
@@ -598,8 +596,6 @@ gdk_device_get_has_cursor (GdkDevice *device)
* Determines the type of the device.
*
* Returns: a `GdkInputSource`
*
* Deprecated: 4.6: Use gdk_device_tool_get_tool_type() instead
*/
GdkInputSource
gdk_device_get_source (GdkDevice *device)
@@ -1242,7 +1238,7 @@ gdk_device_get_num_touches (GdkDevice *device)
*
* Retrieves the current tool for @device.
*
* Returns: (transfer none): the `GdkDeviceTool`
* Returns: (transfer none) (nullable): the `GdkDeviceTool`
*/
GdkDeviceTool *
gdk_device_get_device_tool (GdkDevice *device)

View File

@@ -92,7 +92,7 @@ GDK_AVAILABLE_IN_ALL
GdkDisplay * gdk_device_get_display (GdkDevice *device);
GDK_AVAILABLE_IN_ALL
GdkSeat * gdk_device_get_seat (GdkDevice *device);
GDK_DEPRECATED_IN_4_6_FOR(gdk_device_tool_get_tool_type)
GDK_AVAILABLE_IN_ALL
GdkDeviceTool * gdk_device_get_device_tool (GdkDevice *device);
GDK_AVAILABLE_IN_ALL

View File

@@ -1721,12 +1721,12 @@ gdk_display_init_egl (GdkDisplay *self,
self->have_egl_buffer_age =
epoxy_has_egl_extension (priv->egl_display, "EGL_EXT_buffer_age");
self->have_egl_swap_buffers_with_damage =
epoxy_has_egl_extension (priv->egl_display, "EGL_EXT_swap_buffers_with_damage");
self->have_egl_no_config_context =
epoxy_has_egl_extension (priv->egl_display, "EGL_KHR_no_config_context");
self->have_egl_pixel_format_float =
epoxy_has_egl_extension (priv->egl_display, "EGL_EXT_pixel_format_float");
self->have_egl_win32_libangle =
epoxy_has_egl_extension (priv->egl_display, "EGL_ANGLE_d3d_share_handle_client_buffer");
if (self->have_egl_no_config_context)
priv->egl_config_high_depth = gdk_display_create_egl_config (self,

View File

@@ -107,9 +107,9 @@ struct _GdkDisplay
/* egl info */
guint have_egl_buffer_age : 1;
guint have_egl_swap_buffers_with_damage : 1;
guint have_egl_no_config_context : 1;
guint have_egl_pixel_format_float : 1;
guint have_egl_win32_libangle : 1;
};
struct _GdkDisplayClass

View File

@@ -719,14 +719,6 @@ gdk_event_queue_handle_scroll_compression (GdkDisplay *display)
gdk_event_unref (old_event);
}
if (g_queue_get_length (&display->queued_events) == 1 &&
g_queue_peek_head_link (&display->queued_events) == scrolls)
{
GdkFrameClock *clock = gdk_surface_get_frame_clock (surface);
if (clock) /* might be NULL if surface was destroyed */
gdk_frame_clock_request_phase (clock, GDK_FRAME_CLOCK_PHASE_FLUSH_EVENTS);
}
}
static void
@@ -832,14 +824,6 @@ _gdk_event_queue_handle_motion_compression (GdkDisplay *display)
g_queue_delete_link (&display->queued_events, pending_motions);
pending_motions = next;
}
if (g_queue_get_length (&display->queued_events) == 1 &&
g_queue_peek_head_link (&display->queued_events) == pending_motions)
{
GdkFrameClock *clock = gdk_surface_get_frame_clock (pending_motion_surface);
if (clock) /* might be NULL if surface was destroyed */
gdk_frame_clock_request_phase (clock, GDK_FRAME_CLOCK_PHASE_FLUSH_EVENTS);
}
}
void
@@ -2512,7 +2496,8 @@ static const GdkEventTypeInfo gdk_touchpad_event_info = {
GDK_DEFINE_EVENT_TYPE (GdkTouchpadEvent, gdk_touchpad_event,
&gdk_touchpad_event_info,
GDK_EVENT_TYPE_SLOT (GDK_TOUCHPAD_SWIPE)
GDK_EVENT_TYPE_SLOT (GDK_TOUCHPAD_PINCH))
GDK_EVENT_TYPE_SLOT (GDK_TOUCHPAD_PINCH)
GDK_EVENT_TYPE_SLOT (GDK_TOUCHPAD_HOLD))
GdkEvent *
gdk_touchpad_event_new_swipe (GdkSurface *surface,
@@ -2586,6 +2571,27 @@ gdk_touchpad_event_new_pinch (GdkSurface *surface,
return (GdkEvent *) self;
}
GdkEvent *
gdk_touchpad_event_new_hold (GdkSurface *surface,
GdkDevice *device,
guint32 time,
GdkModifierType state,
GdkTouchpadGesturePhase phase,
double x,
double y,
int n_fingers)
{
GdkTouchpadEvent *self = gdk_event_alloc (GDK_TOUCHPAD_HOLD, surface, device, time);
self->state = state;
self->phase = phase;
self->x = x;
self->y = y;
self->n_fingers = n_fingers;
return (GdkEvent *) self;
}
/**
* gdk_touchpad_event_get_gesture_phase:
* @event: (type GdkTouchpadEvent): a touchpad event
@@ -2601,7 +2607,8 @@ gdk_touchpad_event_get_gesture_phase (GdkEvent *event)
g_return_val_if_fail (GDK_IS_EVENT (event), 0);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_TOUCHPAD_PINCH) ||
GDK_IS_EVENT_TYPE (event, GDK_TOUCHPAD_SWIPE), 0);
GDK_IS_EVENT_TYPE (event, GDK_TOUCHPAD_SWIPE) ||
GDK_IS_EVENT_TYPE (event, GDK_TOUCHPAD_HOLD), 0);
return self->phase;
}
@@ -2621,7 +2628,8 @@ gdk_touchpad_event_get_n_fingers (GdkEvent *event)
g_return_val_if_fail (GDK_IS_EVENT (event), 0);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_TOUCHPAD_PINCH) ||
GDK_IS_EVENT_TYPE (event, GDK_TOUCHPAD_SWIPE), 0);
GDK_IS_EVENT_TYPE (event, GDK_TOUCHPAD_SWIPE) ||
GDK_IS_EVENT_TYPE (event, GDK_TOUCHPAD_HOLD), 0);
return self->n_fingers;
}

View File

@@ -169,6 +169,8 @@ typedef struct _GdkTouchpadEvent GdkTouchpadEvent;
* @GDK_PAD_RING: A tablet pad axis event from a "ring".
* @GDK_PAD_STRIP: A tablet pad axis event from a "strip".
* @GDK_PAD_GROUP_MODE: A tablet pad group mode change.
* @GDK_TOUCHPAD_HOLD: A touchpad hold gesture event, the current state
* is determined by its phase field. Since: 4.6
* @GDK_EVENT_LAST: marks the end of the GdkEventType enumeration.
*
* Specifies the type of the event.
@@ -203,6 +205,7 @@ typedef enum
GDK_PAD_RING,
GDK_PAD_STRIP,
GDK_PAD_GROUP_MODE,
GDK_TOUCHPAD_HOLD,
GDK_EVENT_LAST /* helper variable for decls */
} GdkEventType;

View File

@@ -533,6 +533,15 @@ GdkEvent * gdk_touchpad_event_new_pinch (GdkSurface *surface,
double scale,
double angle_delta);
GdkEvent * gdk_touchpad_event_new_hold (GdkSurface *surface,
GdkDevice *device,
guint32 time,
GdkModifierType state,
GdkTouchpadGesturePhase phase,
double x,
double y,
int n_fingers);
GdkEvent * gdk_pad_event_new_ring (GdkSurface *surface,
GdkDevice *device,
guint32 time,

View File

@@ -117,6 +117,7 @@ typedef struct {
#ifdef HAVE_EGL
EGLContext egl_context;
EGLBoolean (*eglSwapBuffersWithDamage) (EGLDisplay, EGLSurface, const EGLint *, EGLint);
#endif
} GdkGLContextPrivate;
@@ -278,7 +279,11 @@ gdk_gl_context_real_realize (GdkGLContext *context,
int i = 0;
G_GNUC_UNUSED gint64 start_time = GDK_PROFILER_CURRENT_TIME;
gdk_gl_context_get_required_version (context, &major, &minor);
if (share != NULL)
gdk_gl_context_get_required_version (share, &major, &minor);
else
gdk_gl_context_get_required_version (context, &major, &minor);
debug_bit = gdk_gl_context_get_debug_enabled (context);
forward_bit = gdk_gl_context_get_forward_compatible (context);
legacy_bit = GDK_DISPLAY_DEBUG_CHECK (display, GL_LEGACY) ||
@@ -416,6 +421,11 @@ gdk_gl_context_real_realize (GdkGLContext *context,
gdk_gl_context_set_is_legacy (context, legacy_bit);
if (epoxy_has_egl_extension (egl_display, "EGL_KHR_swap_buffers_with_damage"))
priv->eglSwapBuffersWithDamage = (gpointer)epoxy_eglGetProcAddress ("eglSwapBuffersWithDamageKHR");
else if (epoxy_has_egl_extension (egl_display, "EGL_EXT_swap_buffers_with_damage"))
priv->eglSwapBuffersWithDamage = (gpointer)epoxy_eglGetProcAddress ("eglSwapBuffersWithDamageEXT");
gdk_profiler_end_mark (start_time, "realize GdkWaylandGLContext", NULL);
return api;
@@ -604,7 +614,7 @@ gdk_gl_context_real_end_frame (GdkDrawContext *draw_context,
gdk_profiler_add_mark (GDK_PROFILER_CURRENT_TIME, 0, "EGL", "swap buffers");
if (display->have_egl_swap_buffers_with_damage)
if (priv->eglSwapBuffersWithDamage)
{
EGLint stack_rects[4 * 4]; /* 4 rects */
EGLint *heap_rects = NULL;
@@ -628,7 +638,7 @@ gdk_gl_context_real_end_frame (GdkDrawContext *draw_context,
rects[j++] = rect.width * scale;
rects[j++] = rect.height * scale;
}
eglSwapBuffersWithDamageEXT (gdk_display_get_egl_display (display), egl_surface, rects, n_rects);
priv->eglSwapBuffersWithDamage (gdk_display_get_egl_display (display), egl_surface, rects, n_rects);
g_free (heap_rects);
}
else
@@ -644,6 +654,12 @@ gdk_gl_context_surface_resized (GdkDrawContext *draw_context)
gdk_gl_context_clear_old_updated_area (context);
}
static guint
gdk_gl_context_real_get_default_framebuffer (GdkGLContext *self)
{
return 0;
}
static void
gdk_gl_context_class_init (GdkGLContextClass *klass)
{
@@ -655,6 +671,7 @@ gdk_gl_context_class_init (GdkGLContextClass *klass)
klass->is_shared = gdk_gl_context_real_is_shared;
klass->make_current = gdk_gl_context_real_make_current;
klass->clear_current = gdk_gl_context_real_clear_current;
klass->get_default_framebuffer = gdk_gl_context_real_get_default_framebuffer;
draw_context_class->begin_frame = gdk_gl_context_real_begin_frame;
draw_context_class->end_frame = gdk_gl_context_real_end_frame;
@@ -1048,26 +1065,29 @@ gdk_gl_context_get_required_version (GdkGLContext *context,
{
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
gboolean force_gles = FALSE;
#ifdef G_ENABLE_DEBUG
GdkDisplay *display;
#endif
int default_major, default_minor;
int maj, min;
g_return_if_fail (GDK_IS_GL_CONTEXT (context));
#ifdef G_ENABLE_DEBUG
display = gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context));
#ifdef G_ENABLE_DEBUG
force_gles = GDK_DISPLAY_DEBUG_CHECK (display, GL_GLES);
#endif
/* libANGLE on Windows at least requires GLES 3.0+ */
if (display->have_egl_win32_libangle)
force_gles = TRUE;
/* Default fallback values for uninitialised contexts; we
* enforce a context version number of 3.2 for desktop GL,
* and 2.0 for GLES
*/
if (gdk_gl_context_get_use_es (context) || force_gles)
{
default_major = 2;
default_major = display->have_egl_win32_libangle ? 3 : 2;
default_minor = 0;
}
else

View File

@@ -71,6 +71,8 @@ struct _GdkGLContextClass
gboolean (* is_shared) (GdkGLContext *self,
GdkGLContext *other);
guint (* get_default_framebuffer) (GdkGLContext *self);
};
typedef struct {

View File

@@ -175,10 +175,19 @@ gdk_gl_texture_do_download (gpointer texture_,
glGenFramebuffers (1, &fbo);
glBindFramebuffer (GL_FRAMEBUFFER, fbo);
glFramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, self->id, 0);
glGetFramebufferParameteriv (GL_FRAMEBUFFER, GL_IMPLEMENTATION_COLOR_READ_FORMAT, &gl_read_format);
glGetFramebufferParameteriv (GL_FRAMEBUFFER, GL_IMPLEMENTATION_COLOR_READ_TYPE, &gl_read_type);
if (!gdk_gl_texture_find_format (gdk_gl_context_get_use_es (self->context), gl_read_format, gl_read_type, &actual_format))
actual_format = GDK_MEMORY_R8G8B8A8_PREMULTIPLIED; /* pray */
if (gdk_gl_context_check_version (self->context, 4, 3, 3, 1))
{
glGetFramebufferParameteriv (GL_FRAMEBUFFER, GL_IMPLEMENTATION_COLOR_READ_FORMAT, &gl_read_format);
glGetFramebufferParameteriv (GL_FRAMEBUFFER, GL_IMPLEMENTATION_COLOR_READ_TYPE, &gl_read_type);
if (!gdk_gl_texture_find_format (gdk_gl_context_get_use_es (self->context), gl_read_format, gl_read_type, &actual_format))
actual_format = GDK_MEMORY_R8G8B8A8_PREMULTIPLIED; /* pray */
}
else
{
gl_read_format = GL_RGBA;
gl_read_type = GL_UNSIGNED_BYTE;
actual_format = GDK_MEMORY_R8G8B8A8_PREMULTIPLIED;
}
if (download->format == actual_format &&
(download->stride == expected_stride))

View File

@@ -1,16 +1,16 @@
#!/usr/bin/env perl
# Updates https://gitlab.gnome.org/GNOME/gtk/tree/master/gdk/gdkkeysyms.h from upstream (X.org 7.x),
# Updates https://gitlab.gnome.org/GNOME/gtk/tree/main/gdk/gdkkeysyms.h from upstream (X.org 7.x),
# from https://cgit.freedesktop.org/xorg/proto/x11proto/plain/keysymdef.h
#
#
# Author : Simos Xenitellis <simos at gnome dot org>.
# Author : Bastien Nocera <hadess@hadess.net>
# Version : 1.2
#
# Input : https://cgit.freedesktop.org/xorg/proto/x11proto/plain/keysymdef.h
# Input : https://cgit.freedesktop.org/xorg/proto/x11proto/plain/XF86keysym.h
# Output : https://gitlab.gnome.org/GNOME/gtk/tree/master/gdk/gdkkeysyms.h
#
# Output : https://gitlab.gnome.org/GNOME/gtk/tree/main/gdk/gdkkeysyms.h
#
# Notes : It downloads keysymdef.h from the Internet, if not found locally,
# Notes : and creates an updated gdkkeysyms.h
# Notes : This version updates the source of gdkkeysyms.h from CVS to the GIT server.
@@ -24,7 +24,7 @@ if ( ! -f "keysymdef.h" )
{
print "Trying to download keysymdef.h from\n";
print "http://cgit.freedesktop.org/xorg/proto/x11proto/plain/keysymdef.h\n";
die "Unable to download keysymdef.h from http://cgit.freedesktop.org/xorg/proto/x11proto/plain/keysymdef.h\n"
die "Unable to download keysymdef.h from http://cgit.freedesktop.org/xorg/proto/x11proto/plain/keysymdef.h\n"
unless system("wget -c -O keysymdef.h \"http://cgit.freedesktop.org/xorg/proto/x11proto/plain/keysymdef.h\"") == 0;
print " done.\n\n";
}
@@ -39,7 +39,7 @@ if ( ! -f "XF86keysym.h" )
{
print "Trying to download XF86keysym.h from\n";
print "http://cgit.freedesktop.org/xorg/proto/x11proto/plain/XF86keysym.h\n";
die "Unable to download keysymdef.h from http://cgit.freedesktop.org/xorg/proto/x11proto/plain/XF86keysym.h\n"
die "Unable to download keysymdef.h from http://cgit.freedesktop.org/xorg/proto/x11proto/plain/XF86keysym.h\n"
unless system("wget -c -O XF86keysym.h \"http://cgit.freedesktop.org/xorg/proto/x11proto/plain/XF86keysym.h\"") == 0;
print " done.\n\n";
}
@@ -82,7 +82,7 @@ print OUT_GDKKEYSYMS $LICENSE_HEADER;
print OUT_GDKKEYSYMS<<EOF;
/*
* File auto-generated from script https://gitlab.gnome.org/GNOME/gtk/tree/master/gdk/gdkkeysyms-update.pl
* File auto-generated from script https://gitlab.gnome.org/GNOME/gtk/tree/main/gdk/gdkkeysyms-update.pl
* using the input file
* http://cgit.freedesktop.org/xorg/proto/x11proto/plain/keysymdef.h
* and
@@ -111,7 +111,7 @@ while (<IN_KEYSYMDEF>)
$_ = $keysymelements[1];
die "Internal error, was expecting \"XC_*\", found: $_\n" if ( ! /^XK_/ );
$_ = $keysymelements[2];
die "Internal error, was expecting \"0x*\", found: $_\n" if ( ! /^0x/ );

View File

@@ -18,7 +18,7 @@
/*
* File auto-generated from script https://gitlab.gnome.org/GNOME/gtk/tree/master/gdk/gdkkeysyms-update.pl
* File auto-generated from script https://gitlab.gnome.org/GNOME/gtk/tree/main/gdk/gdkkeysyms-update.pl
* using the input file
* http://cgit.freedesktop.org/xorg/proto/x11proto/plain/keysymdef.h
* and

View File

@@ -369,7 +369,7 @@ static const struct {
{ 0x07a2, 0x0388 }, /* Greek_EPSILONaccent Έ GREEK CAPITAL LETTER EPSILON WITH TONOS */
{ 0x07a3, 0x0389 }, /* Greek_ETAaccent Ή GREEK CAPITAL LETTER ETA WITH TONOS */
{ 0x07a4, 0x038a }, /* Greek_IOTAaccent Ί GREEK CAPITAL LETTER IOTA WITH TONOS */
{ 0x07a5, 0x03aa }, /* Greek_IOTAdieresis Ϊ GREEK CAPITAL LETTER IOTA WITH DIALYTIKA */
{ 0x07a5, 0x03aa }, /* Greek_IOTAdiaeresis Ϊ GREEK CAPITAL LETTER IOTA WITH DIALYTIKA */
{ 0x07a7, 0x038c }, /* Greek_OMICRONaccent Ό GREEK CAPITAL LETTER OMICRON WITH TONOS */
{ 0x07a8, 0x038e }, /* Greek_UPSILONaccent Ύ GREEK CAPITAL LETTER UPSILON WITH TONOS */
{ 0x07a9, 0x03ab }, /* Greek_UPSILONdieresis Ϋ GREEK CAPITAL LETTER UPSILON WITH DIALYTIKA */
@@ -436,22 +436,22 @@ static const struct {
{ 0x07f7, 0x03c7 }, /* Greek_chi χ GREEK SMALL LETTER CHI */
{ 0x07f8, 0x03c8 }, /* Greek_psi ψ GREEK SMALL LETTER PSI */
{ 0x07f9, 0x03c9 }, /* Greek_omega ω GREEK SMALL LETTER OMEGA */
/* 0x08a1 leftradical ? ??? */
/* 0x08a2 topleftradical ? ??? */
/* 0x08a3 horizconnector ? ??? */
{ 0x08a1, 0x23b7 }, /* leftradical ??? */
{ 0x08a2, 0x250c }, /* topleftradical ┌ BOX DRAWINGS LIGHT DOWN AND RIGHT */
{ 0x08a3, 0x2500 }, /* horizconnector ─ BOX DRAWINGS LIGHT HORIZONTAL */
{ 0x08a4, 0x2320 }, /* topintegral ⌠ TOP HALF INTEGRAL */
{ 0x08a5, 0x2321 }, /* botintegral ⌡ BOTTOM HALF INTEGRAL */
{ 0x08a6, 0x2502 }, /* vertconnector │ BOX DRAWINGS LIGHT VERTICAL */
/* 0x08a7 topleftsqbracket ? ??? */
/* 0x08a8 botleftsqbracket ? ??? */
/* 0x08a9 toprightsqbracket ? ??? */
/* 0x08aa botrightsqbracket ? ??? */
/* 0x08ab topleftparens ? ??? */
/* 0x08ac botleftparens ? ??? */
/* 0x08ad toprightparens ? ??? */
/* 0x08ae botrightparens ? ??? */
/* 0x08af leftmiddlecurlybrace ? ??? */
/* 0x08b0 rightmiddlecurlybrace ? ??? */
{ 0x08a7, 0x23a1 }, /* topleftsqbracket ??? */
{ 0x08a8, 0x23a3 }, /* botleftsqbracket ??? */
{ 0x08a9, 0x23a4 }, /* toprightsqbracket ??? */
{ 0x08aa, 0x23a6 }, /* botrightsqbracket ??? */
{ 0x08ab, 0x239b }, /* topleftparens ??? */
{ 0x08ac, 0x239d }, /* botleftparens ??? */
{ 0x08ad, 0x239e }, /* toprightparens ??? */
{ 0x08ae, 0x23a0 }, /* botrightparens ??? */
{ 0x08af, 0x23a8 }, /* leftmiddlecurlybrace ??? */
{ 0x08b0, 0x23ac }, /* rightmiddlecurlybrace ??? */
/* 0x08b1 topleftsummation ? ??? */
/* 0x08b2 botleftsummation ? ??? */
/* 0x08b3 topvertsummationconnector ? ??? */
@@ -467,8 +467,8 @@ static const struct {
{ 0x08c1, 0x221d }, /* variation ∝ PROPORTIONAL TO */
{ 0x08c2, 0x221e }, /* infinity ∞ INFINITY */
{ 0x08c5, 0x2207 }, /* nabla ∇ NABLA */
{ 0x08c8, 0x2245 }, /* approximate ≅ APPROXIMATELY EQUAL TO */
/* 0x08c9 similarequal ? ??? */
{ 0x08c8, 0x223c }, /* approximate TILDE OPERATOR */
{ 0x08c9, 0x2243 }, /* similarequal ≃ ASYMPTOTICALLY EQUAL TO */
{ 0x08cd, 0x21d4 }, /* ifonlyif ⇔ LEFT RIGHT DOUBLE ARROW */
{ 0x08ce, 0x21d2 }, /* implies ⇒ RIGHTWARDS DOUBLE ARROW */
{ 0x08cf, 0x2261 }, /* identical ≡ IDENTICAL TO */
@@ -485,7 +485,7 @@ static const struct {
{ 0x08fc, 0x2191 }, /* uparrow ↑ UPWARDS ARROW */
{ 0x08fd, 0x2192 }, /* rightarrow → RIGHTWARDS ARROW */
{ 0x08fe, 0x2193 }, /* downarrow ↓ DOWNWARDS ARROW */
{ 0x09df, 0x2422 }, /* blank ␢ BLANK SYMBOL */
/* 0x09df blank ? ??? */
{ 0x09e0, 0x25c6 }, /* soliddiamond ◆ BLACK DIAMOND */
{ 0x09e1, 0x2592 }, /* checkerboard ▒ MEDIUM SHADE */
{ 0x09e2, 0x2409 }, /* ht ␉ SYMBOL FOR HORIZONTAL TABULATION */
@@ -499,11 +499,11 @@ static const struct {
{ 0x09ec, 0x250c }, /* upleftcorner ┌ BOX DRAWINGS LIGHT DOWN AND RIGHT */
{ 0x09ed, 0x2514 }, /* lowleftcorner └ BOX DRAWINGS LIGHT UP AND RIGHT */
{ 0x09ee, 0x253c }, /* crossinglines ┼ BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL */
/* 0x09ef horizlinescan1 ? ??? */
/* 0x09f0 horizlinescan3 ? ??? */
{ 0x09ef, 0x23ba }, /* horizlinescan1 ⎺ HORIZONTAL SCAN LINE-1 (Unicode 3.2 draft) */
{ 0x09f0, 0x23bb }, /* horizlinescan3 ⎻ HORIZONTAL SCAN LINE-3 (Unicode 3.2 draft) */
{ 0x09f1, 0x2500 }, /* horizlinescan5 ─ BOX DRAWINGS LIGHT HORIZONTAL */
/* 0x09f2 horizlinescan7 ? ??? */
/* 0x09f3 horizlinescan9 ? ??? */
{ 0x09f2, 0x23bc }, /* horizlinescan7 ⎼ HORIZONTAL SCAN LINE-7 (Unicode 3.2 draft) */
{ 0x09f3, 0x23bd }, /* horizlinescan9 ⎽ HORIZONTAL SCAN LINE-9 (Unicode 3.2 draft) */
{ 0x09f4, 0x251c }, /* leftt ├ BOX DRAWINGS LIGHT VERTICAL AND RIGHT */
{ 0x09f5, 0x2524 }, /* rightt ┤ BOX DRAWINGS LIGHT VERTICAL AND LEFT */
{ 0x09f6, 0x2534 }, /* bott ┴ BOX DRAWINGS LIGHT UP AND HORIZONTAL */
@@ -519,9 +519,9 @@ static const struct {
{ 0x0aa8, 0x200a }, /* hairspace HAIR SPACE */
{ 0x0aa9, 0x2014 }, /* emdash — EM DASH */
{ 0x0aaa, 0x2013 }, /* endash EN DASH */
/* 0x0aac signifblank ? ??? */
{ 0x0aac, 0x2423 }, /* signifblank ␣ OPEN BOX */
{ 0x0aae, 0x2026 }, /* ellipsis … HORIZONTAL ELLIPSIS */
/* 0x0aaf doubbaselinedot ? ??? */
{ 0x0aaf, 0x2025 }, /* doubbaselinedot ‥ TWO DOT LEADER */
{ 0x0ab0, 0x2153 }, /* onethird ⅓ VULGAR FRACTION ONE THIRD */
{ 0x0ab1, 0x2154 }, /* twothirds ⅔ VULGAR FRACTION TWO THIRDS */
{ 0x0ab2, 0x2155 }, /* onefifth ⅕ VULGAR FRACTION ONE FIFTH */
@@ -532,9 +532,9 @@ static const struct {
{ 0x0ab7, 0x215a }, /* fivesixths ⅚ VULGAR FRACTION FIVE SIXTHS */
{ 0x0ab8, 0x2105 }, /* careof ℅ CARE OF */
{ 0x0abb, 0x2012 }, /* figdash FIGURE DASH */
{ 0x0abc, 0x2329 }, /* leftanglebracket 〈 LEFT-POINTING ANGLE BRACKET */
{ 0x0abc, 0x27e8 }, /* leftanglebracket ⟨ MATHEMATICAL LEFT ANGLE BRACKET */
{ 0x0abd, 0x002e }, /* decimalpoint . FULL STOP */
{ 0x0abe, 0x232a }, /* rightanglebracket 〉 RIGHT-POINTING ANGLE BRACKET */
{ 0x0abe, 0x27e9 }, /* rightanglebracket ⟩ MATHEMATICAL RIGHT ANGLE BRACKET */
/* 0x0abf marker ? ??? */
{ 0x0ac3, 0x215b }, /* oneeighth ⅛ VULGAR FRACTION ONE EIGHTH */
{ 0x0ac4, 0x215c }, /* threeeighths ⅜ VULGAR FRACTION THREE EIGHTHS */
@@ -546,12 +546,13 @@ static const struct {
{ 0x0acc, 0x25c1 }, /* leftopentriangle ◁ WHITE LEFT-POINTING TRIANGLE */
{ 0x0acd, 0x25b7 }, /* rightopentriangle ▷ WHITE RIGHT-POINTING TRIANGLE */
{ 0x0ace, 0x25cb }, /* emopencircle ○ WHITE CIRCLE */
{ 0x0acf, 0x25a1 }, /* emopenrectangle WHITE SQUARE */
{ 0x0acf, 0x25af }, /* emopenrectangle WHITE VERTICAL RECTANGLE */
{ 0x0ad0, 0x2018 }, /* leftsinglequotemark LEFT SINGLE QUOTATION MARK */
{ 0x0ad1, 0x2019 }, /* rightsinglequotemark RIGHT SINGLE QUOTATION MARK */
{ 0x0ad2, 0x201c }, /* leftdoublequotemark “ LEFT DOUBLE QUOTATION MARK */
{ 0x0ad3, 0x201d }, /* rightdoublequotemark ” RIGHT DOUBLE QUOTATION MARK */
{ 0x0ad4, 0x211e }, /* prescription ℞ PRESCRIPTION TAKE */
{ 0x0ad5, 0x2030 }, /* permille ‰ PER MILLE SIGN */
{ 0x0ad6, 0x2032 }, /* minutes PRIME */
{ 0x0ad7, 0x2033 }, /* seconds ″ DOUBLE PRIME */
{ 0x0ad9, 0x271d }, /* latincross ✝ LATIN CROSS */
@@ -560,7 +561,7 @@ static const struct {
{ 0x0adc, 0x25c0 }, /* filledlefttribullet ◀ BLACK LEFT-POINTING TRIANGLE */
{ 0x0add, 0x25b6 }, /* filledrighttribullet ▶ BLACK RIGHT-POINTING TRIANGLE */
{ 0x0ade, 0x25cf }, /* emfilledcircle ● BLACK CIRCLE */
{ 0x0adf, 0x25a0 }, /* emfilledrect BLACK SQUARE */
{ 0x0adf, 0x25ae }, /* emfilledrect BLACK VERTICAL RECTANGLE */
{ 0x0ae0, 0x25e6 }, /* enopencircbullet ◦ WHITE BULLET */
{ 0x0ae1, 0x25ab }, /* enopensquarebullet ▫ WHITE SMALL SQUARE */
{ 0x0ae2, 0x25ad }, /* openrectbullet ▭ WHITE RECTANGLE */
@@ -805,15 +806,16 @@ static const struct {
{ 0x0ef0, 0x3171 }, /* Hangul_SunkyeongeumMieum ㅱ HANGUL LETTER KAPYEOUNMIEUM */
{ 0x0ef1, 0x3178 }, /* Hangul_SunkyeongeumPieub ㅸ HANGUL LETTER KAPYEOUNPIEUP */
{ 0x0ef2, 0x317f }, /* Hangul_PanSios ㅿ HANGUL LETTER PANSIOS */
/* 0x0ef3 Hangul_KkogjiDalrinIeung ? ??? */
{ 0x0ef3, 0x3181 }, /* Hangul_KkogjiDalrinIeung ㆁ HANGUL LETTER YESIEUNG */
{ 0x0ef4, 0x3184 }, /* Hangul_SunkyeongeumPhieuf ㆄ HANGUL LETTER KAPYEOUNPHIEUPH */
{ 0x0ef5, 0x3186 }, /* Hangul_YeorinHieuh ㆆ HANGUL LETTER YEORINHIEUH */
{ 0x0ef6, 0x318d }, /* Hangul_AraeA ㆍ HANGUL LETTER ARAEA */
{ 0x0ef7, 0x318e }, /* Hangul_AraeAE ㆎ HANGUL LETTER ARAEAE */
{ 0x0ef8, 0x11eb }, /* Hangul_J_PanSios ᇫ HANGUL JONGSEONG PANSIOS */
/* 0x0ef9 Hangul_J_KkogjiDalrinIeung ? ??? */
{ 0x0ef9, 0x11f0 }, /* Hangul_J_KkogjiDalrinIeung ᇰ HANGUL JONGSEONG YESIEUNG */
{ 0x0efa, 0x11f9 }, /* Hangul_J_YeorinHieuh ᇹ HANGUL JONGSEONG YEORINHIEUH */
{ 0x0eff, 0x20a9 }, /* Korean_Won ₩ WON SIGN */
{ 0x13a4, 0x20ac }, /* Euro € EURO SIGN */
{ 0x13bc, 0x0152 }, /* OE Œ LATIN CAPITAL LIGATURE OE */
{ 0x13bd, 0x0153 }, /* oe œ LATIN SMALL LIGATURE OE */
{ 0x13be, 0x0178 }, /* Ydiaeresis Ÿ LATIN CAPITAL LETTER Y WITH DIAERESIS */
@@ -835,18 +837,13 @@ static const struct {
/* Following items added to GTK, not in the xterm table */
/* A few ASCII control characters */
#ifndef GDK_WINDOWING_WIN32
{ 0xFF08 /* Backspace */, '\b' },
{ 0xFF09 /* Tab */, '\t' },
#endif
{ 0xFF0A /* Linefeed */, '\n' },
{ 0xFF0B /* Vert. Tab */, '\v' },
#ifndef GDK_WINDOWING_WIN32
{ 0xFF0D /* Return */, '\r' },
{ 0xFF1B /* Escape */, '\033' },
#endif
/* Numeric keypad */
@@ -871,9 +868,7 @@ static const struct {
/* End numeric keypad */
#ifndef GDK_WINDOWING_WIN32
{ 0xFFFF /* Delete */, '\177' }
#endif
};
/**
@@ -1084,7 +1079,7 @@ static const struct {
{ 0x07d7, 0x03a7 }, /* Greek_CHI Χ GREEK CAPITAL LETTER CHI */
{ 0x07d8, 0x03a8 }, /* Greek_PSI Ψ GREEK CAPITAL LETTER PSI */
{ 0x07d9, 0x03a9 }, /* Greek_OMEGA Ω GREEK CAPITAL LETTER OMEGA */
{ 0x07a5, 0x03aa }, /* Greek_IOTAdieresis Ϊ GREEK CAPITAL LETTER IOTA WITH DIALYTIKA */
{ 0x07a5, 0x03aa }, /* Greek_IOTAdiaeresis Ϊ GREEK CAPITAL LETTER IOTA WITH DIALYTIKA */
{ 0x07a9, 0x03ab }, /* Greek_UPSILONdieresis Ϋ GREEK CAPITAL LETTER UPSILON WITH DIALYTIKA */
{ 0x07b1, 0x03ac }, /* Greek_alphaaccent ά GREEK SMALL LETTER ALPHA WITH TONOS */
{ 0x07b2, 0x03ad }, /* Greek_epsilonaccent έ GREEK SMALL LETTER EPSILON WITH TONOS */
@@ -1399,6 +1394,7 @@ static const struct {
{ 0x0eed, 0x11c1 }, /* Hangul_J_Phieuf ᇁ HANGUL JONGSEONG PHIEUPH */
{ 0x0eee, 0x11c2 }, /* Hangul_J_Hieuh ᇂ HANGUL JONGSEONG HIEUH */
{ 0x0ef8, 0x11eb }, /* Hangul_J_PanSios ᇫ HANGUL JONGSEONG PANSIOS */
{ 0x0ef9, 0x11f0 }, /* Hangul_J_KkogjiDalrinIeung ᇰ HANGUL JONGSEONG YESIEUNG */
{ 0x0efa, 0x11f9 }, /* Hangul_J_YeorinHieuh ᇹ HANGUL JONGSEONG YEORINHIEUH */
{ 0x0aa2, 0x2002 }, /* enspace EN SPACE */
{ 0x0aa1, 0x2003 }, /* emspace EM SPACE */
@@ -1422,7 +1418,9 @@ static const struct {
{ 0x0af1, 0x2020 }, /* dagger † DAGGER */
{ 0x0af2, 0x2021 }, /* doubledagger ‡ DOUBLE DAGGER */
{ 0x0ae6, 0x2022 }, /* enfilledcircbullet • BULLET */
{ 0x0aaf, 0x2025 }, /* doubbaselinedot ‥ TWO DOT LEADER */
{ 0x0aae, 0x2026 }, /* ellipsis … HORIZONTAL ELLIPSIS */
{ 0x0ad5, 0x2030 }, /* permille ‰ PER MILLE SIGN */
{ 0x0ad6, 0x2032 }, /* minutes PRIME */
{ 0x0ad7, 0x2033 }, /* seconds ″ DOUBLE PRIME */
{ 0x0afc, 0x2038 }, /* caret ‸ CARET */
@@ -1480,7 +1478,8 @@ static const struct {
{ 0x0bd6, 0x222a }, /* downshoe UNION */
{ 0x08bf, 0x222b }, /* integral ∫ INTEGRAL */
{ 0x08c0, 0x2234 }, /* therefore ∴ THEREFORE */
{ 0x08c8, 0x2245 }, /* approximate ≅ APPROXIMATELY EQUAL TO */
{ 0x08c8, 0x223c }, /* approximate TILDE OPERATOR */
{ 0x08c9, 0x2243 }, /* similarequal ≃ ASYMPTOTICALLY EQUAL TO */
{ 0x08bd, 0x2260 }, /* notequal ≠ NOT EQUAL TO */
{ 0x08cf, 0x2261 }, /* identical ≡ IDENTICAL TO */
{ 0x08bc, 0x2264 }, /* lessthanequal ≤ LESS-THAN OR EQUAL TO */
@@ -1498,15 +1497,28 @@ static const struct {
{ 0x0afa, 0x2315 }, /* telephonerecorder ⌕ TELEPHONE RECORDER */
{ 0x08a4, 0x2320 }, /* topintegral ⌠ TOP HALF INTEGRAL */
{ 0x08a5, 0x2321 }, /* botintegral ⌡ BOTTOM HALF INTEGRAL */
{ 0x0abc, 0x2329 }, /* leftanglebracket 〈 LEFT-POINTING ANGLE BRACKET */
{ 0x0abe, 0x232a }, /* rightanglebracket 〉 RIGHT-POINTING ANGLE BRACKET */
{ 0x0bcc, 0x2395 }, /* quad ⎕ APL FUNCTIONAL SYMBOL QUAD (Unicode 3.0) */
{ 0x08a7, 0x23a1 }, /* topleftsqbracket ⎡ ??? */
{ 0x08a8, 0x23a3 }, /* botleftsqbracket ⎣ ??? */
{ 0x08a9, 0x23a4 }, /* toprightsqbracket ⎤ ??? */
{ 0x08aa, 0x23a6 }, /* botrightsqbracket ⎦ ??? */
{ 0x08ab, 0x239b }, /* topleftparens ⎛ ??? */
{ 0x08ac, 0x239d }, /* botleftparens ⎝ ??? */
{ 0x08ad, 0x239e }, /* toprightparens ⎞ ??? */
{ 0x08ae, 0x23a0 }, /* botrightparens ⎠ ??? */
{ 0x08af, 0x23a8 }, /* leftmiddlecurlybrace ⎨ ??? */
{ 0x08b0, 0x23ac }, /* rightmiddlecurlybrace ⎬ ??? */
{ 0x08a1, 0x23b7 }, /* leftradical ⎷ ??? */
{ 0x09ef, 0x23ba }, /* horizlinescan1 ⎺ HORIZONTAL SCAN LINE-1 (Unicode 3.2 draft) */
{ 0x09f0, 0x23bb }, /* horizlinescan3 ⎻ HORIZONTAL SCAN LINE-3 (Unicode 3.2 draft) */
{ 0x09f2, 0x23bc }, /* horizlinescan7 ⎼ HORIZONTAL SCAN LINE-7 (Unicode 3.2 draft) */
{ 0x09f3, 0x23bd }, /* horizlinescan9 ⎽ HORIZONTAL SCAN LINE-9 (Unicode 3.2 draft) */
{ 0x09e2, 0x2409 }, /* ht ␉ SYMBOL FOR HORIZONTAL TABULATION */
{ 0x09e5, 0x240a }, /* lf ␊ SYMBOL FOR LINE FEED */
{ 0x09e9, 0x240b }, /* vt ␋ SYMBOL FOR VERTICAL TABULATION */
{ 0x09e3, 0x240c }, /* ff ␌ SYMBOL FOR FORM FEED */
{ 0x09e4, 0x240d }, /* cr ␍ SYMBOL FOR CARRIAGE RETURN */
{ 0x09df, 0x2422 }, /* blank ␢ BLANK SYMBOL */
{ 0x0aac, 0x2423 }, /* signifblank ␣ OPEN BOX */
{ 0x09e8, 0x2424 }, /* nl ␤ SYMBOL FOR NEWLINE */
{ 0x09f1, 0x2500 }, /* horizlinescan5 ─ BOX DRAWINGS LIGHT HORIZONTAL */
{ 0x08a6, 0x2502 }, /* vertconnector │ BOX DRAWINGS LIGHT VERTICAL */
@@ -1522,11 +1534,11 @@ static const struct {
{ 0x09ee, 0x253c }, /* crossinglines ┼ BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL */
{ 0x09e1, 0x2592 }, /* checkerboard ▒ MEDIUM SHADE */
{ 0x0adf, 0x25a0 }, /* emfilledrect ■ BLACK SQUARE */
{ 0x0acf, 0x25a1 }, /* emopenrectangle □ WHITE SQUARE */
{ 0x0ae7, 0x25aa }, /* enfilledsqbullet ▪ BLACK SMALL SQUARE */
{ 0x0ae1, 0x25ab }, /* enopensquarebullet ▫ WHITE SMALL SQUARE */
{ 0x0adb, 0x25ac }, /* filledrectbullet ▬ BLACK RECTANGLE */
{ 0x0ae2, 0x25ad }, /* openrectbullet ▭ WHITE RECTANGLE */
{ 0x0acf, 0x25af }, /* emopenrectangle ▯ WHITE VERTICAL RECTANGLE */
{ 0x0ae8, 0x25b2 }, /* filledtribulletup ▲ BLACK UP-POINTING TRIANGLE */
{ 0x0ae3, 0x25b3 }, /* opentribulletup △ WHITE UP-POINTING TRIANGLE */
{ 0x0add, 0x25b6 }, /* filledrighttribullet ▶ BLACK RIGHT-POINTING TRIANGLE */
@@ -1556,6 +1568,8 @@ static const struct {
{ 0x0af4, 0x2717 }, /* ballotcross ✗ BALLOT X */
{ 0x0ad9, 0x271d }, /* latincross ✝ LATIN CROSS */
{ 0x0af0, 0x2720 }, /* maltesecross ✠ MALTESE CROSS */
{ 0x0abc, 0x27e8 }, /* leftanglebracket ⟨ MATHEMATICAL LEFT ANGLE BRACKET */
{ 0x0abe, 0x27e9 }, /* rightanglebracket ⟩ MATHEMATICAL RIGHT ANGLE BRACKET */
{ 0x04a4, 0x3001 }, /* kana_comma 、 IDEOGRAPHIC COMMA */
{ 0x04a1, 0x3002 }, /* kana_fullstop 。 IDEOGRAPHIC FULL STOP */
{ 0x04a2, 0x300c }, /* kana_openingbracket 「 LEFT CORNER BRACKET */
@@ -1674,6 +1688,7 @@ static const struct {
{ 0x0ef0, 0x3171 }, /* Hangul_SunkyeongeumMieum ㅱ HANGUL LETTER KAPYEOUNMIEUM */
{ 0x0ef1, 0x3178 }, /* Hangul_SunkyeongeumPieub ㅸ HANGUL LETTER KAPYEOUNPIEUP */
{ 0x0ef2, 0x317f }, /* Hangul_PanSios ㅿ HANGUL LETTER PANSIOS */
{ 0x0ef3, 0x3181 }, /* Hangul_KkogjiDalrinIeung ㆁ HANGUL LETTER YESIEUNG */
{ 0x0ef4, 0x3184 }, /* Hangul_SunkyeongeumPhieuf ㆄ HANGUL LETTER KAPYEOUNPHIEUPH */
{ 0x0ef5, 0x3186 }, /* Hangul_YeorinHieuh ㆆ HANGUL LETTER YEORINHIEUH */
{ 0x0ef6, 0x318d }, /* Hangul_AraeA ㆍ HANGUL LETTER ARAEA */

View File

@@ -166,6 +166,54 @@ r32g32b32a32_float_from_float (guchar *dest,
memcpy (dest, src, sizeof (float) * n * 4);
}
#define PREMULTIPLY_FUNC(name, R1, G1, B1, A1, R2, G2, B2, A2) \
static void \
name (guchar *dest, \
const guchar *src, \
gsize n) \
{ \
for (; n > 0; n--) \
{ \
guchar a = src[A1]; \
guint16 r = (guint16)src[R1] * a + 127; \
guint16 g = (guint16)src[G1] * a + 127; \
guint16 b = (guint16)src[B1] * a + 127; \
dest[R2] = (r + (r >> 8) + 1) >> 8; \
dest[G2] = (g + (g >> 8) + 1) >> 8; \
dest[B2] = (b + (b >> 8) + 1) >> 8; \
dest[A2] = a; \
dest += 4; \
src += 4; \
} \
}
PREMULTIPLY_FUNC(r8g8b8a8_to_r8g8b8a8_premultiplied, 0, 1, 2, 3, 0, 1, 2, 3)
PREMULTIPLY_FUNC(r8g8b8a8_to_b8g8r8a8_premultiplied, 0, 1, 2, 3, 2, 1, 0, 3)
PREMULTIPLY_FUNC(r8g8b8a8_to_a8r8g8b8_premultiplied, 0, 1, 2, 3, 1, 2, 3, 0)
PREMULTIPLY_FUNC(r8g8b8a8_to_a8b8g8r8_premultiplied, 0, 1, 2, 3, 3, 2, 1, 0)
#define ADD_ALPHA_FUNC(name, R1, G1, B1, R2, G2, B2, A2) \
static void \
name (guchar *dest, \
const guchar *src, \
gsize n) \
{ \
for (; n > 0; n--) \
{ \
dest[R2] = src[R1]; \
dest[G2] = src[G1]; \
dest[B2] = src[B1]; \
dest[A2] = 255; \
dest += 4; \
src += 3; \
} \
}
ADD_ALPHA_FUNC(r8g8b8_to_r8g8b8a8, 0, 1, 2, 0, 1, 2, 3)
ADD_ALPHA_FUNC(r8g8b8_to_b8g8r8a8, 0, 1, 2, 2, 1, 0, 3)
ADD_ALPHA_FUNC(r8g8b8_to_a8r8g8b8, 0, 1, 2, 1, 2, 3, 0)
ADD_ALPHA_FUNC(r8g8b8_to_a8b8g8r8, 0, 1, 2, 3, 2, 1, 0)
struct _GdkMemoryFormatDescription
{
GdkMemoryAlpha alpha;
@@ -475,10 +523,59 @@ gdk_memory_convert (guchar *dest_data,
const GdkMemoryFormatDescription *src_desc = &memory_formats[src_format];
float *tmp;
gsize y;
void (*func) (guchar *, const guchar *, gsize) = NULL;
g_assert (dest_format < GDK_MEMORY_N_FORMATS);
g_assert (src_format < GDK_MEMORY_N_FORMATS);
if (src_format == GDK_MEMORY_R8G8B8A8 && dest_format == GDK_MEMORY_R8G8B8A8_PREMULTIPLIED)
func = r8g8b8a8_to_r8g8b8a8_premultiplied;
else if (src_format == GDK_MEMORY_B8G8R8A8 && dest_format == GDK_MEMORY_R8G8B8A8_PREMULTIPLIED)
func = r8g8b8a8_to_b8g8r8a8_premultiplied;
else if (src_format == GDK_MEMORY_R8G8B8A8 && dest_format == GDK_MEMORY_B8G8R8A8_PREMULTIPLIED)
func = r8g8b8a8_to_b8g8r8a8_premultiplied;
else if (src_format == GDK_MEMORY_B8G8R8A8 && dest_format == GDK_MEMORY_B8G8R8A8_PREMULTIPLIED)
func = r8g8b8a8_to_r8g8b8a8_premultiplied;
else if (src_format == GDK_MEMORY_R8G8B8A8 && dest_format == GDK_MEMORY_A8R8G8B8_PREMULTIPLIED)
func = r8g8b8a8_to_a8r8g8b8_premultiplied;
else if (src_format == GDK_MEMORY_B8G8R8A8 && dest_format == GDK_MEMORY_A8R8G8B8_PREMULTIPLIED)
func = r8g8b8a8_to_a8b8g8r8_premultiplied;
else if (src_format == GDK_MEMORY_R8G8B8 && dest_format == GDK_MEMORY_R8G8B8A8_PREMULTIPLIED)
func = r8g8b8_to_r8g8b8a8;
else if (src_format == GDK_MEMORY_B8G8R8 && dest_format == GDK_MEMORY_R8G8B8A8_PREMULTIPLIED)
func = r8g8b8_to_b8g8r8a8;
else if (src_format == GDK_MEMORY_R8G8B8 && dest_format == GDK_MEMORY_B8G8R8A8_PREMULTIPLIED)
func = r8g8b8_to_b8g8r8a8;
else if (src_format == GDK_MEMORY_B8G8R8 && dest_format == GDK_MEMORY_B8G8R8A8_PREMULTIPLIED)
func = r8g8b8_to_r8g8b8a8;
else if (src_format == GDK_MEMORY_R8G8B8 && dest_format == GDK_MEMORY_A8R8G8B8_PREMULTIPLIED)
func = r8g8b8_to_a8r8g8b8;
else if (src_format == GDK_MEMORY_B8G8R8 && dest_format == GDK_MEMORY_A8R8G8B8_PREMULTIPLIED)
func = r8g8b8_to_a8b8g8r8;
else if (src_format == GDK_MEMORY_R8G8B8 && dest_format == GDK_MEMORY_R8G8B8A8)
func = r8g8b8_to_r8g8b8a8;
else if (src_format == GDK_MEMORY_B8G8R8 && dest_format == GDK_MEMORY_R8G8B8A8)
func = r8g8b8_to_b8g8r8a8;
else if (src_format == GDK_MEMORY_R8G8B8 && dest_format == GDK_MEMORY_B8G8R8A8)
func = r8g8b8_to_b8g8r8a8;
else if (src_format == GDK_MEMORY_B8G8R8 && dest_format == GDK_MEMORY_B8G8R8A8)
func = r8g8b8_to_r8g8b8a8;
else if (src_format == GDK_MEMORY_R8G8B8 && dest_format == GDK_MEMORY_A8R8G8B8)
func = r8g8b8_to_a8r8g8b8;
else if (src_format == GDK_MEMORY_B8G8R8 && dest_format == GDK_MEMORY_A8R8G8B8)
func = r8g8b8_to_a8b8g8r8;
if (func != NULL)
{
for (y = 0; y < height; y++)
{
func (dest_data, src_data, width);
src_data += src_stride;
dest_data += dest_stride;
}
return;
}
tmp = g_new (float, width * 4);
for (y = 0; y < height; y++)

View File

@@ -1,5 +1,5 @@
/* GDK - The GIMP Drawing Kit
* Copyright (C) 2000 Red Hat, Inc.
* Copyright (C) 2000 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -52,25 +52,25 @@ layout_iter_get_line_clip_region (PangoLayoutIter *iter,
i = 0;
while (i < n_ranges)
{
{
int *pixel_ranges = NULL;
int n_pixel_ranges = 0;
int j;
/* Note that get_x_ranges returns layout coordinates
*/
if (index_ranges[i*2+1] >= line->start_index &&
index_ranges[i*2] < line->start_index + line->length)
if (index_ranges[i*2+1] >= pango_layout_line_get_start_index (line) &&
index_ranges[i*2] < pango_layout_line_get_start_index (line) + pango_layout_line_get_length (line))
pango_layout_line_get_x_ranges (line,
index_ranges[i*2],
index_ranges[i*2+1],
&pixel_ranges, &n_pixel_ranges);
for (j = 0; j < n_pixel_ranges; j++)
{
GdkRectangle rect;
int x_off, y_off;
x_off = PANGO_PIXELS (pixel_ranges[2*j] - logical_rect.x);
y_off = PANGO_PIXELS (baseline - logical_rect.y);
@@ -124,14 +124,14 @@ gdk_pango_layout_line_get_clip_region (PangoLayoutLine *line,
{
cairo_region_t *clip_region;
PangoLayoutIter *iter;
g_return_val_if_fail (line != NULL, NULL);
g_return_val_if_fail (index_ranges != NULL, NULL);
iter = pango_layout_get_iter (line->layout);
while (pango_layout_iter_get_line_readonly (iter) != line)
pango_layout_iter_next_line (iter);
clip_region = layout_iter_get_line_clip_region(iter, x_origin, y_origin, index_ranges, n_ranges);
pango_layout_iter_free (iter);
@@ -167,26 +167,26 @@ gdk_pango_layout_get_clip_region (PangoLayout *layout,
const int *index_ranges,
int n_ranges)
{
PangoLayoutIter *iter;
PangoLayoutIter *iter;
cairo_region_t *clip_region;
g_return_val_if_fail (PANGO_IS_LAYOUT (layout), NULL);
g_return_val_if_fail (index_ranges != NULL, NULL);
clip_region = cairo_region_create ();
iter = pango_layout_get_iter (layout);
do
{
PangoRectangle logical_rect;
cairo_region_t *line_region;
int baseline;
pango_layout_iter_get_line_extents (iter, NULL, &logical_rect);
baseline = pango_layout_iter_get_baseline (iter);
line_region = layout_iter_get_line_clip_region(iter,
pango_layout_iter_get_line_extents (iter, NULL, &logical_rect);
baseline = pango_layout_iter_get_baseline (iter);
line_region = layout_iter_get_line_clip_region(iter,
x_origin + PANGO_PIXELS (logical_rect.x),
y_origin + PANGO_PIXELS (baseline),
index_ranges,

View File

@@ -33,7 +33,7 @@
((_GDK_RGBA_SELECT_COLOR(str, 0, 0) << 4) | _GDK_RGBA_SELECT_COLOR(str, 0, 1)) / 255., \
((_GDK_RGBA_SELECT_COLOR(str, 1, 2) << 4) | _GDK_RGBA_SELECT_COLOR(str, 1, 3)) / 255., \
((_GDK_RGBA_SELECT_COLOR(str, 2, 4) << 4) | _GDK_RGBA_SELECT_COLOR(str, 2, 5)) / 255., \
((sizeof(str) % 4 == 1) ? ((_GDK_RGBA_SELECT_COLOR(str, 3, 6) << 4) | _GDK_RGBA_SELECT_COLOR(str, 3, 7)) : 0xFF) / 255 })
((sizeof(str) % 4 == 1) ? ((_GDK_RGBA_SELECT_COLOR(str, 3, 6) << 4) | _GDK_RGBA_SELECT_COLOR(str, 3, 7)) : 0xFF) / 255. })
gboolean gdk_rgba_parser_parse (GtkCssParser *parser,

View File

@@ -2244,7 +2244,7 @@ _gdk_windowing_got_event (GdkDisplay *display,
GdkEvent *event,
gulong serial)
{
GdkSurface *event_surface;
GdkSurface *event_surface = NULL;
gboolean unlink_event = FALSE;
GdkDeviceGrabInfo *button_release_grab;
GdkPointerSurfaceInfo *pointer_info = NULL;
@@ -2336,6 +2336,14 @@ _gdk_windowing_got_event (GdkDisplay *display,
*/
_gdk_event_queue_handle_motion_compression (display);
gdk_event_queue_handle_scroll_compression (display);
if (event_surface)
{
GdkFrameClock *clock = gdk_surface_get_frame_clock (event_surface);
if (clock) /* might be NULL if surface was destroyed */
gdk_frame_clock_request_phase (clock, GDK_FRAME_CLOCK_PHASE_FLUSH_EVENTS);
}
}
/**

View File

@@ -83,6 +83,8 @@
*
* A macro that evaluates to the 4.2 version of GDK, in a format
* that can be used by the C pre-processor.
*
* Since: 4.2
*/
#define GDK_VERSION_4_2 (G_ENCODE_VERSION (4, 2))
@@ -91,6 +93,8 @@
*
* A macro that evaluates to the 4.4 version of GDK, in a format
* that can be used by the C pre-processor.
*
* Since: 4.4
*/
#define GDK_VERSION_4_4 (G_ENCODE_VERSION (4, 4))
@@ -99,9 +103,21 @@
*
* A macro that evaluates to the 4.6 version of GDK, in a format
* that can be used by the C pre-processor.
*
* Since: 4.6
*/
#define GDK_VERSION_4_6 (G_ENCODE_VERSION (4, 6))
/**
* GDK_VERSION_4_8:
*
* A macro that evaluates to the 4.8 version of GDK, in a format
* that can be used by the C pre-processor.
*
* Since: 4.8
*/
#define GDK_VERSION_4_8 (G_ENCODE_VERSION (4, 8))
/* evaluates to the current stable version; for development cycles,
* this means the next stable target, with a hard backstop to the
@@ -243,4 +259,18 @@
# define GDK_DEPRECATED_IN_4_6_FOR(f) _GDK_EXTERN
#endif
#if GDK_VERSION_MAX_ALLOWED < GDK_VERSION_4_8
# define GDK_AVAILABLE_IN_4_8 GDK_UNAVAILABLE(4, 8)
#else
# define GDK_AVAILABLE_IN_4_8 _GDK_EXTERN
#endif
#if GDK_VERSION_MIN_REQUIRED >= GDK_VERSION_4_8
# define GDK_DEPRECATED_IN_4_8 GDK_DEPRECATED
# define GDK_DEPRECATED_IN_4_8_FOR(f) GDK_DEPRECATED_FOR(f)
#else
# define GDK_DEPRECATED_IN_4_8 _GDK_EXTERN
# define GDK_DEPRECATED_IN_4_8_FOR(f) _GDK_EXTERN
#endif
#endif /* __GDK_VERSION_MACROS_H__ */

View File

@@ -15,6 +15,8 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include "config.h"
#include "gdkjpegprivate.h"

View File

@@ -45,7 +45,6 @@
options = (NSTrackingMouseEnteredAndExited |
NSTrackingMouseMoved |
NSTrackingInVisibleRect |
NSTrackingActiveAlways);
trackingArea = [[NSTrackingArea alloc] initWithRect:rect
options:options
@@ -57,9 +56,26 @@
return self;
}
-(void)setInputArea:(const cairo_rectangle_int_t *)area
{
NSRect rect = NSMakeRect (area->x, area->y, area->width, area->height);
NSTrackingAreaOptions options;
[self removeTrackingArea:trackingArea];
options = (NSTrackingMouseEnteredAndExited |
NSTrackingMouseMoved |
NSTrackingActiveAlways);
trackingArea = [[NSTrackingArea alloc] initWithRect:rect
options:options
owner:(id)self
userInfo:nil];
[self addTrackingArea:trackingArea];
}
-(void)setOpaqueRegion:(cairo_region_t *)region
{
/* Do nothing */
/* Handled in Subclass */
}
-(BOOL)acceptsFirstMouse

View File

@@ -42,5 +42,6 @@
-(void)setNeedsInvalidateShadow: (BOOL)invalidate;
-(NSTrackingArea *)trackingArea;
-(void)setOpaqueRegion:(cairo_region_t *)region;
-(void)setInputArea:(const cairo_rectangle_int_t *)area;
@end

View File

@@ -1,201 +0,0 @@
/* GdkMacosCairoSubview.c
*
* Copyright © 2020 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "config.h"
#include <CoreGraphics/CoreGraphics.h>
#include <cairo-quartz.h>
#import "GdkMacosCairoSubview.h"
#import "GdkMacosCairoView.h"
#include "gdkmacossurface-private.h"
@implementation GdkMacosCairoSubview
-(void)dealloc
{
g_clear_pointer (&self->clip, cairo_region_destroy);
[super dealloc];
}
-(BOOL)isOpaque
{
return _isOpaque;
}
-(BOOL)isFlipped
{
return YES;
}
-(GdkSurface *)gdkSurface
{
return GDK_SURFACE ([(GdkMacosBaseView *)[self superview] gdkSurface]);
}
-(void)drawRect:(NSRect)rect
{
CGContextRef cgContext;
GdkSurface *gdk_surface;
cairo_surface_t *dest;
const NSRect *rects = NULL;
NSView *root_view;
NSInteger n_rects = 0;
NSRect abs_bounds;
cairo_t *cr;
CGSize scale;
int scale_factor;
if (self->cairoSurface == NULL)
return;
/* Acquire everything we need to do translations, drawing, etc */
gdk_surface = [self gdkSurface];
scale_factor = gdk_surface_get_scale_factor (gdk_surface);
root_view = [[self window] contentView];
cgContext = [[NSGraphicsContext currentContext] CGContext];
abs_bounds = [self convertRect:[self bounds] toView:root_view];
CGContextSaveGState (cgContext);
/* Translate scaling to remove HiDPI scaling from CGContext as
* cairo will be doing that for us already.
*/
scale = CGSizeMake (1.0, 1.0);
scale = CGContextConvertSizeToDeviceSpace (cgContext, scale);
CGContextScaleCTM (cgContext, 1.0 / scale.width, 1.0 / scale.height);
/* Create the cairo surface to draw to the CGContext and translate
* coordinates so we can pretend we are in the same coordinate system
* as the GDK surface.
*/
dest = cairo_quartz_surface_create_for_cg_context (cgContext,
gdk_surface->width * scale_factor,
gdk_surface->height * scale_factor);
cairo_surface_set_device_scale (dest, scale_factor, scale_factor);
/* Create cairo context and translate things into the origin of
* the topmost contentView so that we just draw at 0,0 with a
* clip region to paint the surface.
*/
cr = cairo_create (dest);
cairo_translate (cr, -abs_bounds.origin.x, -abs_bounds.origin.y);
/* Apply the clip if provided one */
if (self->clip != NULL)
{
cairo_rectangle_int_t area;
n_rects = cairo_region_num_rectangles (self->clip);
for (guint i = 0; i < n_rects; i++)
{
cairo_region_get_rectangle (self->clip, i, &area);
cairo_rectangle (cr, area.x, area.y, area.width, area.height);
}
cairo_clip (cr);
}
/* Clip the cairo context based on the rectangles to be drawn
* within the bounding box :rect.
*/
[self getRectsBeingDrawn:&rects count:&n_rects];
for (NSInteger i = 0; i < n_rects; i++)
{
NSRect area = [self convertRect:rects[i] toView:root_view];
cairo_rectangle (cr,
area.origin.x, area.origin.y,
area.size.width, area.size.height);
}
cairo_clip (cr);
/* Now paint the surface (without blending) as we do not need
* any compositing here. The transparent regions (like shadows)
* are already on non-opaque layers.
*/
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
cairo_set_source_surface (cr, self->cairoSurface, 0, 0);
cairo_paint (cr);
/* Cleanup state, flush the surface to the backing layer, and
* restore GState for future use.
*/
cairo_destroy (cr);
cairo_surface_flush (dest);
cairo_surface_destroy (dest);
CGContextRestoreGState (cgContext);
}
-(void)setCairoSurface:(cairo_surface_t *)surface
withDamage:(cairo_region_t *)region
{
if (surface != self->cairoSurface)
{
g_clear_pointer (&self->cairoSurface, cairo_surface_destroy);
if (surface != NULL)
self->cairoSurface = cairo_surface_reference (surface);
}
if (region != NULL)
{
NSView *root_view = [[self window] contentView];
NSRect abs_bounds = [self convertRect:[self bounds] toView:root_view];
guint n_rects = cairo_region_num_rectangles (region);
for (guint i = 0; i < n_rects; i++)
{
cairo_rectangle_int_t rect;
NSRect nsrect;
cairo_region_get_rectangle (region, i, &rect);
nsrect = NSMakeRect (rect.x, rect.y, rect.width, rect.height);
if (NSIntersectsRect (abs_bounds, nsrect))
{
nsrect.origin.x -= abs_bounds.origin.x;
nsrect.origin.y -= abs_bounds.origin.y;
[self setNeedsDisplayInRect:nsrect];
}
}
}
for (id view in [self subviews])
[(GdkMacosCairoSubview *)view setCairoSurface:surface
withDamage:region];
}
-(void)setOpaque:(BOOL)opaque
{
self->_isOpaque = opaque;
}
-(void)setClip:(cairo_region_t*)region
{
if (region != self->clip)
{
g_clear_pointer (&self->clip, cairo_region_destroy);
if (region != NULL)
self->clip = cairo_region_reference (region);
}
}
@end

View File

@@ -1,187 +0,0 @@
/* GdkMacosCairoView.c
*
* Copyright © 2020 Red Hat, Inc.
* Copyright © 2005-2007 Imendio AB
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "config.h"
#include <CoreGraphics/CoreGraphics.h>
#include <cairo-quartz.h>
#import "GdkMacosCairoView.h"
#import "GdkMacosCairoSubview.h"
#include "gdkmacossurface-private.h"
@implementation GdkMacosCairoView
-(void)dealloc
{
g_clear_pointer (&self->opaque, g_ptr_array_unref);
self->transparent = NULL;
[super dealloc];
}
-(BOOL)isOpaque
{
if ([self window])
return [[self window] isOpaque];
return YES;
}
-(BOOL)isFlipped
{
return YES;
}
-(void)setNeedsDisplay:(BOOL)needsDisplay
{
for (id child in [self subviews])
[child setNeedsDisplay:needsDisplay];
}
-(void)setCairoSurface:(cairo_surface_t *)cairoSurface
withDamage:(cairo_region_t *)cairoRegion
{
for (id view in [self subviews])
[(GdkMacosCairoSubview *)view setCairoSurface:cairoSurface
withDamage:cairoRegion];
}
-(void)removeOpaqueChildren
{
[[self->transparent subviews]
makeObjectsPerformSelector:@selector(removeFromSuperview)];
if (self->opaque->len)
g_ptr_array_remove_range (self->opaque, 0, self->opaque->len);
}
-(void)setOpaqueRegion:(cairo_region_t *)region
{
cairo_region_t *transparent_clip;
NSRect abs_bounds;
guint n_rects;
if (region == NULL)
return;
abs_bounds = [self convertRect:[self bounds] toView:nil];
n_rects = cairo_region_num_rectangles (region);
/* First, we create a clip region for the transparent region to use so that
* we dont end up exposing too much other than the corners on CSD.
*/
transparent_clip = cairo_region_create_rectangle (&(cairo_rectangle_int_t) {
abs_bounds.origin.x, abs_bounds.origin.y,
abs_bounds.size.width, abs_bounds.size.height
});
cairo_region_subtract (transparent_clip, region);
[(GdkMacosCairoSubview *)self->transparent setClip:transparent_clip];
cairo_region_destroy (transparent_clip);
/* The common case (at least for opaque windows and CSD) is that we will
* have either one or two opaque rectangles. If we detect that the same
* number of them are available as the previous, we can just resize the
* previous ones to avoid adding/removing views at a fast rate while
* resizing.
*/
if (n_rects == self->opaque->len)
{
for (guint i = 0; i < n_rects; i++)
{
GdkMacosCairoSubview *child;
cairo_rectangle_int_t rect;
child = g_ptr_array_index (self->opaque, i);
cairo_region_get_rectangle (region, i, &rect);
[child setFrame:NSMakeRect (rect.x - abs_bounds.origin.x,
rect.y - abs_bounds.origin.y,
rect.width,
rect.height)];
}
return;
}
[self removeOpaqueChildren];
for (guint i = 0; i < n_rects; i++)
{
GdkMacosCairoSubview *child;
cairo_rectangle_int_t rect;
NSRect nsrect;
cairo_region_get_rectangle (region, i, &rect);
nsrect = NSMakeRect (rect.x - abs_bounds.origin.x,
rect.y - abs_bounds.origin.y,
rect.width,
rect.height);
child = [[GdkMacosCairoSubview alloc] initWithFrame:nsrect];
[child setOpaque:YES];
[child setWantsLayer:YES];
[self->transparent addSubview:child];
g_ptr_array_add (self->opaque, child);
}
}
-(NSView *)initWithFrame:(NSRect)frame
{
if ((self = [super initWithFrame:frame]))
{
/* An array to track all the opaque children placed into
* the child self->transparent. This allows us to reuse them
* when we receive a new opaque area instead of discarding
* them on each draw.
*/
self->opaque = g_ptr_array_new ();
/* Setup our primary subview which will render all content that is not
* within an opaque region (such as shadows for CSD windows). For opaque
* windows, this will all be obscurred by other views, so it doesn't
* matter much to have it here.
*/
self->transparent = [[GdkMacosCairoSubview alloc] initWithFrame:frame];
[self addSubview:self->transparent];
}
return self;
}
-(void)setFrame:(NSRect)rect
{
[super setFrame:rect];
[self->transparent setFrame:NSMakeRect (0, 0, rect.size.width, rect.size.height)];
}
-(BOOL)acceptsFirstMouse
{
return YES;
}
-(BOOL)mouseDownCanMoveWindow
{
return NO;
}
@end

View File

@@ -1,125 +0,0 @@
/* GdkMacosGLView.c
*
* Copyright 2020 Christian Hergert <chergert@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "config.h"
#include <CoreGraphics/CoreGraphics.h>
#include <OpenGL/gl.h>
#include "gdkmacossurface-private.h"
#import "GdkMacosGLView.h"
@implementation GdkMacosGLView
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-(void)lockFocus
{
NSOpenGLContext *context;
[super lockFocus];
context = [self openGLContext];
if ([context view] != self)
[context setView: self];
}
-(void)drawRect:(NSRect)rect
{
}
-(void)clearGLContext
{
if (_openGLContext != nil)
[_openGLContext clearDrawable];
_openGLContext = nil;
}
-(void)setOpenGLContext:(NSOpenGLContext*)context
{
if (_openGLContext != context)
{
if (_openGLContext != nil)
[_openGLContext clearDrawable];
_openGLContext = context;
if (_openGLContext != nil)
{
[_openGLContext setView:self];
[self setWantsLayer:YES];
[self.layer setContentsGravity:kCAGravityBottomLeft];
[_openGLContext update];
}
}
}
-(NSOpenGLContext *)openGLContext
{
return _openGLContext;
}
-(BOOL)isOpaque
{
if ([self window])
return [[self window] isOpaque];
return YES;
}
-(BOOL)isFlipped
{
return YES;
}
-(BOOL)acceptsFirstMouse
{
return YES;
}
-(BOOL)mouseDownCanMoveWindow
{
return NO;
}
-(void)invalidateRegion:(const cairo_region_t *)region
{
if (region != NULL)
{
guint n_rects = cairo_region_num_rectangles (region);
for (guint i = 0; i < n_rects; i++)
{
cairo_rectangle_int_t rect;
NSRect nsrect;
cairo_region_get_rectangle (region, i, &rect);
nsrect = NSMakeRect (rect.x, rect.y, rect.width, rect.height);
[self setNeedsDisplayInRect:nsrect];
}
}
}
G_GNUC_END_IGNORE_DEPRECATIONS
@end

386
gdk/macos/GdkMacosLayer.c Normal file
View File

@@ -0,0 +1,386 @@
/* GdkMacosLayer.c
*
* Copyright © 2022 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "config.h"
#import "GdkMacosLayer.h"
#import "GdkMacosTile.h"
@protocol CanSetContentsOpaque
- (void)setContentsOpaque:(BOOL)mask;
@end
@implementation GdkMacosLayer
#define TILE_MAX_SIZE 128
#define TILE_EDGE_MAX_SIZE 512
static CGAffineTransform flipTransform;
static gboolean hasFlipTransform;
typedef struct
{
GdkMacosTile *tile;
cairo_rectangle_int_t cr_area;
CGRect area;
guint opaque : 1;
} TileInfo;
typedef struct
{
const cairo_region_t *region;
guint n_rects;
guint iter;
cairo_rectangle_int_t rect;
cairo_rectangle_int_t stash;
guint finished : 1;
} Tiler;
static void
tiler_init (Tiler *tiler,
const cairo_region_t *region)
{
memset (tiler, 0, sizeof *tiler);
if (region == NULL)
{
tiler->finished = TRUE;
return;
}
tiler->region = region;
tiler->n_rects = cairo_region_num_rectangles (region);
if (tiler->n_rects > 0)
cairo_region_get_rectangle (region, 0, &tiler->rect);
else
tiler->finished = TRUE;
}
static gboolean
tiler_next (Tiler *tiler,
cairo_rectangle_int_t *tile,
int max_size)
{
if (tiler->finished)
return FALSE;
if (tiler->rect.width == 0 || tiler->rect.height == 0)
{
tiler->iter++;
if (tiler->iter >= tiler->n_rects)
{
tiler->finished = TRUE;
return FALSE;
}
cairo_region_get_rectangle (tiler->region, tiler->iter, &tiler->rect);
}
/* If the next rectangle is too tall, slice the bottom off to
* leave just the height we want into tiler->stash.
*/
if (tiler->rect.height > max_size)
{
tiler->stash = tiler->rect;
tiler->stash.y += max_size;
tiler->stash.height -= max_size;
tiler->rect.height = max_size;
}
/* Now we can take the next horizontal slice */
tile->x = tiler->rect.x;
tile->y = tiler->rect.y;
tile->height = tiler->rect.height;
tile->width = MIN (max_size, tiler->rect.width);
tiler->rect.x += tile->width;
tiler->rect.width -= tile->width;
if (tiler->rect.width == 0)
{
tiler->rect = tiler->stash;
tiler->stash.width = tiler->stash.height = 0;
}
return TRUE;
}
static inline CGRect
toCGRect (const cairo_rectangle_int_t *rect)
{
return CGRectMake (rect->x, rect->y, rect->width, rect->height);
}
static inline cairo_rectangle_int_t
fromCGRect (const CGRect rect)
{
return (cairo_rectangle_int_t) {
rect.origin.x,
rect.origin.y,
rect.size.width,
rect.size.height
};
}
-(id)init
{
if (!hasFlipTransform)
{
hasFlipTransform = TRUE;
flipTransform = CGAffineTransformMakeScale (1, -1);
}
self = [super init];
if (self == NULL)
return NULL;
self->_layoutInvalid = TRUE;
[self setContentsGravity:kCAGravityCenter];
[self setContentsScale:1.0f];
[self setGeometryFlipped:YES];
return self;
}
-(BOOL)isOpaque
{
return NO;
}
-(void)_applyLayout:(GArray *)tiles
{
CGAffineTransform transform;
GArray *prev;
gboolean exhausted;
guint j = 0;
if (self->_isFlipped)
transform = flipTransform;
else
transform = CGAffineTransformIdentity;
prev = g_steal_pointer (&self->_tiles);
self->_tiles = tiles;
exhausted = prev == NULL;
/* Try to use existing CALayer to avoid creating new layers
* as that can be rather expensive.
*/
for (guint i = 0; i < tiles->len; i++)
{
TileInfo *info = &g_array_index (tiles, TileInfo, i);
if (!exhausted)
{
TileInfo *other = NULL;
for (; j < prev->len; j++)
{
other = &g_array_index (prev, TileInfo, j);
if (other->opaque == info->opaque)
{
j++;
break;
}
other = NULL;
}
if (other != NULL)
{
info->tile = g_steal_pointer (&other->tile);
[info->tile setFrame:info->area];
[info->tile setAffineTransform:transform];
continue;
}
}
info->tile = [GdkMacosTile layer];
[info->tile setAffineTransform:transform];
[info->tile setContentsScale:1.0f];
[info->tile setOpaque:info->opaque];
[(id<CanSetContentsOpaque>)info->tile setContentsOpaque:info->opaque];
[info->tile setFrame:info->area];
[self addSublayer:info->tile];
}
/* Release all of our old layers */
if (prev != NULL)
{
for (guint i = 0; i < prev->len; i++)
{
TileInfo *info = &g_array_index (prev, TileInfo, i);
if (info->tile != NULL)
[info->tile removeFromSuperlayer];
}
g_array_unref (prev);
}
}
-(void)layoutSublayers
{
Tiler tiler;
GArray *ar;
cairo_region_t *transparent;
cairo_rectangle_int_t rect;
int max_size;
if (!self->_inSwapBuffer)
return;
self->_layoutInvalid = FALSE;
ar = g_array_sized_new (FALSE, FALSE, sizeof (TileInfo), 32);
rect = fromCGRect ([self bounds]);
rect.x = rect.y = 0;
/* Calculate the transparent region (edges usually) */
transparent = cairo_region_create_rectangle (&rect);
if (self->_opaqueRegion)
cairo_region_subtract (transparent, self->_opaqueRegion);
self->_opaque = cairo_region_is_empty (transparent);
/* If we have transparent borders around the opaque region, then
* we are okay with a bit larger tiles since they don't change
* all that much and are generally small in width.
*/
if (!self->_opaque &&
self->_opaqueRegion &&
!cairo_region_is_empty (self->_opaqueRegion))
max_size = TILE_EDGE_MAX_SIZE;
else
max_size = TILE_MAX_SIZE;
/* Track transparent children */
tiler_init (&tiler, transparent);
while (tiler_next (&tiler, &rect, max_size))
{
TileInfo *info;
g_array_set_size (ar, ar->len+1);
info = &g_array_index (ar, TileInfo, ar->len-1);
info->tile = NULL;
info->opaque = FALSE;
info->cr_area = rect;
info->area = toCGRect (&info->cr_area);
}
/* Track opaque children */
tiler_init (&tiler, self->_opaqueRegion);
while (tiler_next (&tiler, &rect, TILE_MAX_SIZE))
{
TileInfo *info;
g_array_set_size (ar, ar->len+1);
info = &g_array_index (ar, TileInfo, ar->len-1);
info->tile = NULL;
info->opaque = TRUE;
info->cr_area = rect;
info->area = toCGRect (&info->cr_area);
}
cairo_region_destroy (transparent);
[self _applyLayout:g_steal_pointer (&ar)];
[super layoutSublayers];
}
-(void)setFrame:(NSRect)frame
{
if (frame.size.width != self.bounds.size.width ||
frame.size.height != self.bounds.size.height)
{
self->_layoutInvalid = TRUE;
[self setNeedsLayout];
}
[super setFrame:frame];
}
-(void)setOpaqueRegion:(const cairo_region_t *)opaqueRegion
{
g_clear_pointer (&self->_opaqueRegion, cairo_region_destroy);
self->_opaqueRegion = cairo_region_copy (opaqueRegion);
self->_layoutInvalid = TRUE;
[self setNeedsLayout];
}
-(void)swapBuffer:(GdkMacosBuffer *)buffer withDamage:(const cairo_region_t *)damage
{
IOSurfaceRef ioSurface = _gdk_macos_buffer_get_native (buffer);
gboolean flipped = _gdk_macos_buffer_get_flipped (buffer);
double scale = _gdk_macos_buffer_get_device_scale (buffer);
double width = _gdk_macos_buffer_get_width (buffer) / scale;
double height = _gdk_macos_buffer_get_height (buffer) / scale;
if (flipped != self->_isFlipped)
{
self->_isFlipped = flipped;
self->_layoutInvalid = TRUE;
}
if (self->_layoutInvalid)
{
self->_inSwapBuffer = TRUE;
[self layoutSublayers];
self->_inSwapBuffer = FALSE;
}
if (self->_tiles == NULL)
return;
for (guint i = 0; i < self->_tiles->len; i++)
{
const TileInfo *info = &g_array_index (self->_tiles, TileInfo, i);
cairo_region_overlap_t overlap;
CGRect area;
overlap = cairo_region_contains_rectangle (damage, &info->cr_area);
if (overlap == CAIRO_REGION_OVERLAP_OUT)
continue;
area.origin.x = info->area.origin.x / width;
area.size.width = info->area.size.width / width;
area.size.height = info->area.size.height / height;
if (flipped)
area.origin.y = (height - info->area.origin.y - info->area.size.height) / height;
else
area.origin.y = info->area.origin.y / height;
[info->tile swapBuffer:ioSurface withRect:area];
}
}
@end

44
gdk/macos/GdkMacosLayer.h Normal file
View File

@@ -0,0 +1,44 @@
/* GdkMacosLayer.h
*
* Copyright © 2022 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include <QuartzCore/QuartzCore.h>
#include <IOSurface/IOSurface.h>
#include <cairo.h>
#include <glib.h>
#include "gdkmacosbuffer-private.h"
#define GDK_IS_MACOS_LAYER(obj) ((obj) && [obj isKindOfClass:[GdkMacosLayer class]])
@interface GdkMacosLayer : CALayer
{
cairo_region_t *_opaqueRegion;
GArray *_tiles;
guint _opaque : 1;
guint _layoutInvalid : 1;
guint _inSwapBuffer : 1;
guint _isFlipped : 1;
};
-(void)setOpaqueRegion:(const cairo_region_t *)opaqueRegion;
-(void)swapBuffer:(GdkMacosBuffer *)buffer withDamage:(const cairo_region_t *)damage;
@end

View File

@@ -1,7 +1,6 @@
/* GdkMacosGLView.h
/* GdkMacosTile.c
*
* Copyright © 2020 Red Hat, Inc.
* Copyright © 2005-2007 Imendio AB
* Copyright © 2022 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -19,23 +18,34 @@
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include <cairo.h>
#include "config.h"
#import "GdkMacosBaseView.h"
#include <AppKit/AppKit.h>
#define GDK_IS_MACOS_GL_VIEW(obj) ((obj) && [obj isKindOfClass:[GdkMacosGLView class]])
#import "GdkMacosTile.h"
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
@implementation GdkMacosTile
@interface GdkMacosGLView : GdkMacosBaseView
-(id)init
{
NSOpenGLContext *_openGLContext;
self = [super init];
[self setContentsScale:1.0];
[self setEdgeAntialiasingMask:0];
[self setDrawsAsynchronously:YES];
return self;
}
-(void)setOpenGLContext:(NSOpenGLContext*)context;
-(NSOpenGLContext *)openGLContext;
-(void)invalidateRegion:(const cairo_region_t *)region;
-(void)swapBuffer:(IOSurfaceRef)buffer withRect:(CGRect)rect
{
if G_LIKELY ([self contents] == (id)buffer)
[(id<CanSetContentsChanged>)self setContentsChanged];
else
[self setContents:(id)buffer];
G_GNUC_END_IGNORE_DEPRECATIONS
if G_UNLIKELY (!CGRectEqualToRect ([self contentsRect], rect))
self.contentsRect = rect;
}
@end

View File

@@ -1,6 +1,6 @@
/* GdkMacosCairoSubview.h
/* GdkMacosTile.h
*
* Copyright © 2020 Red Hat, Inc.
* Copyright © 2022 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -18,20 +18,20 @@
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include <AppKit/AppKit.h>
#include <QuartzCore/QuartzCore.h>
#define GDK_IS_MACOS_CAIRO_SUBVIEW(obj) ((obj) && [obj isKindOfClass:[GdkMacosCairoSubview class]])
#include "gdkmacosbuffer-private.h"
@interface GdkMacosCairoSubview : NSView
#define GDK_IS_MACOS_TILE(obj) ((obj) && [obj isKindOfClass:[GdkMacosTile class]])
@protocol CanSetContentsChanged
-(void)setContentsChanged;
@end
@interface GdkMacosTile : CALayer
{
BOOL _isOpaque;
cairo_surface_t *cairoSurface;
cairo_region_t *clip;
}
};
-(void)setOpaque:(BOOL)opaque;
-(void)setCairoSurface:(cairo_surface_t *)cairoSurface
withDamage:(cairo_region_t *)region;
-(void)setClip:(cairo_region_t*)region;
-(void)swapBuffer:(IOSurfaceRef)buffer withRect:(CGRect)rect;
@end

100
gdk/macos/GdkMacosView.c Normal file
View File

@@ -0,0 +1,100 @@
/* GdkMacosView.c
*
* Copyright 2022 Christian Hergert <chergert@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "config.h"
#include <CoreGraphics/CoreGraphics.h>
#import "GdkMacosLayer.h"
#import "GdkMacosView.h"
#import "GdkMacosWindow.h"
@implementation GdkMacosView
-(id)initWithFrame:(NSRect)frame
{
if ((self = [super initWithFrame:frame]))
{
GdkMacosLayer *layer = [GdkMacosLayer layer];
[self setLayerContentsRedrawPolicy:NSViewLayerContentsRedrawNever];
[self setLayer:layer];
[self setWantsLayer:YES];
}
return self;
}
-(BOOL)isFlipped
{
return YES;
}
-(BOOL)acceptsFirstMouse
{
return YES;
}
-(BOOL)mouseDownCanMoveWindow
{
return NO;
}
-(void)mouseDown:(NSEvent *)nsevent
{
if ([(GdkMacosWindow *)[self window] needsMouseDownQuirk])
/* We should only hit this when we are trying to click through
* the shadow of a window into another window. Just request
* that the application not activate this window on mouseUp.
* See gdkmacosdisplay-translate.c for the other half of this.
*/
[NSApp preventWindowOrdering];
else
[super mouseDown:nsevent];
}
-(void)setFrame:(NSRect)rect
{
[super setFrame:rect];
self->_nextFrameDirty = TRUE;
}
-(void)setOpaqueRegion:(const cairo_region_t *)opaqueRegion
{
[(GdkMacosLayer *)[self layer] setOpaqueRegion:opaqueRegion];
}
-(BOOL)wantsUpdateLayer
{
return YES;
}
-(void)swapBuffer:(GdkMacosBuffer *)buffer withDamage:(const cairo_region_t *)damage
{
if (self->_nextFrameDirty)
{
self->_nextFrameDirty = FALSE;
[[self layer] setFrame:[self frame]];
}
[(GdkMacosLayer *)[self layer] swapBuffer:buffer withDamage:damage];
}
@end

View File

@@ -1,7 +1,6 @@
/* GdkMacosCairoView.h
/* GdkMacosView.h
*
* Copyright © 2020 Red Hat, Inc.
* Copyright © 2005-2007 Imendio AB
* Copyright 2022 Christian Hergert <chergert@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -23,15 +22,17 @@
#import "GdkMacosBaseView.h"
#define GDK_IS_MACOS_CAIRO_VIEW(obj) ((obj) && [obj isKindOfClass:[GdkMacosCairoView class]])
#include "gdkmacosbuffer-private.h"
@interface GdkMacosCairoView : GdkMacosBaseView
#define GDK_IS_MACOS_VIEW(obj) ((obj) && [obj isKindOfClass:[GdkMacosView class]])
@interface GdkMacosView : GdkMacosBaseView
{
NSView *transparent;
GPtrArray *opaque;
NSRect _nextFrame;
guint _nextFrameDirty : 1;
}
-(void)setCairoSurface:(cairo_surface_t *)cairoSurface
withDamage:(cairo_region_t *)region;
-(void)setOpaqueRegion:(const cairo_region_t *)opaqueRegion;
-(void)swapBuffer:(GdkMacosBuffer *)buffer withDamage:(const cairo_region_t *)damage;
@end

View File

@@ -24,8 +24,7 @@
#include <gdk/gdk.h>
#import "GdkMacosBaseView.h"
#import "GdkMacosCairoView.h"
#import "GdkMacosGLView.h"
#import "GdkMacosView.h"
#import "GdkMacosWindow.h"
#include "gdkmacosclipboard-private.h"
@@ -150,8 +149,7 @@ typedef NSString *CALayerContentsGravity;
_gdk_macos_display_break_all_grabs (GDK_MACOS_DISPLAY (display), time);
/* Reset gravity */
if (GDK_IS_MACOS_GL_VIEW ([self contentView]))
[[[self contentView] layer] setContentsGravity:kCAGravityBottomLeft];
[[[self contentView] layer] setContentsGravity:kCAGravityBottomLeft];
break;
}
@@ -203,69 +201,20 @@ typedef NSString *CALayerContentsGravity;
}
}
-(void)windowDidUnmaximize
{
NSWindowStyleMask style_mask = [self styleMask];
gdk_synthesize_surface_state (GDK_SURFACE (gdk_surface), GDK_TOPLEVEL_STATE_MAXIMIZED, 0);
/* If we are using CSD, then we transitioned to an opaque
* window while we were maximized. Now we need to drop that
* as we are leaving maximized state.
*/
if ((style_mask & NSWindowStyleMaskTitled) == 0 && [self isOpaque])
[self setOpaque:NO];
}
-(void)windowDidMove:(NSNotification *)aNotification
-(void)setFrame:(NSRect)frame display:(BOOL)display
{
NSRect contentRect = [self contentRectForFrameRect:frame];
GdkSurface *surface = GDK_SURFACE (gdk_surface);
gboolean maximized = (surface->state & GDK_TOPLEVEL_STATE_MAXIMIZED) != 0;
/* In case the window is changed when maximized remove the maximized state */
if (maximized && !inMaximizeTransition && !NSEqualRects (lastMaximizedFrame, [self frame]))
[self windowDidUnmaximize];
if (maximized && !inMaximizeTransition && !NSEqualRects (lastMaximizedFrame, frame))
{
gdk_synthesize_surface_state (surface, GDK_TOPLEVEL_STATE_MAXIMIZED, 0);
_gdk_surface_update_size (surface);
}
_gdk_macos_surface_update_position (gdk_surface);
_gdk_macos_surface_reposition_children (gdk_surface);
[self checkSendEnterNotify];
}
-(void)windowDidResize:(NSNotification *)aNotification
{
NSRect content_rect;
GdkSurface *surface;
GdkDisplay *display;
gboolean maximized;
surface = GDK_SURFACE (gdk_surface);
display = gdk_surface_get_display (surface);
content_rect = [self contentRectForFrameRect:[self frame]];
maximized = (surface->state & GDK_TOPLEVEL_STATE_MAXIMIZED) != 0;
/* see same in windowDidMove */
if (maximized && !inMaximizeTransition && !NSEqualRects (lastMaximizedFrame, [self frame]))
[self windowDidUnmaximize];
surface->width = content_rect.size.width;
surface->height = content_rect.size.height;
/* Certain resize operations (e.g. going fullscreen), also move the
* origin of the window.
*/
_gdk_macos_surface_update_position (GDK_MACOS_SURFACE (surface));
[[self contentView] setFrame:NSMakeRect (0, 0, surface->width, surface->height)];
_gdk_surface_update_size (surface);
gdk_surface_request_layout (surface);
_gdk_macos_surface_reposition_children (gdk_surface);
[self checkSendEnterNotify];
[super setFrame:frame display:display];
[[self contentView] setFrame:NSMakeRect (0, 0, contentRect.size.width, contentRect.size.height)];
}
-(id)initWithContentRect:(NSRect)contentRect
@@ -274,7 +223,7 @@ typedef NSString *CALayerContentsGravity;
defer:(BOOL)flag
screen:(NSScreen *)screen
{
GdkMacosCairoView *view;
GdkMacosView *view;
self = [super initWithContentRect:contentRect
styleMask:styleMask
@@ -285,8 +234,9 @@ typedef NSString *CALayerContentsGravity;
[self setAcceptsMouseMovedEvents:YES];
[self setDelegate:(id<NSWindowDelegate>)self];
[self setReleasedWhenClosed:YES];
[self setPreservesContentDuringLiveResize:NO];
view = [[GdkMacosCairoView alloc] initWithFrame:contentRect];
view = [[GdkMacosView alloc] initWithFrame:contentRect];
[self setContentView:view];
[view release];
@@ -303,7 +253,8 @@ typedef NSString *CALayerContentsGravity;
-(BOOL)canBecomeKeyWindow
{
return GDK_IS_TOPLEVEL (gdk_surface);
return GDK_IS_TOPLEVEL (gdk_surface) ||
(GDK_IS_POPUP (gdk_surface) && GDK_SURFACE (gdk_surface)->input_region != NULL);
}
-(void)showAndMakeKey:(BOOL)makeKey
@@ -311,9 +262,12 @@ typedef NSString *CALayerContentsGravity;
inShowOrHide = YES;
if (makeKey && [self canBecomeKeyWindow])
[self makeKeyAndOrderFront:nil];
[self makeKeyAndOrderFront:self];
else
[self orderFront:nil];
[self orderFront:self];
if (makeKey && [self canBecomeMainWindow])
[self makeMainWindow];
inShowOrHide = NO;
@@ -411,12 +365,31 @@ typedef NSString *CALayerContentsGravity;
windowFrame.origin.x = new_origin.x;
windowFrame.origin.y = new_origin.y;
/* And now apply the frame to the window */
[self setFrameOrigin:NSMakePoint(new_origin.x, new_origin.y)];
[self setFrame:NSMakeRect (new_origin.x, new_origin.y,
window_gdk.width, window_gdk.height)
display:YES];
return YES;
}
-(void)windowDidMove:(NSNotification *)notification
{
_gdk_macos_surface_configure ([self gdkSurface]);
}
-(void)windowDidResize:(NSNotification *)notification
{
_gdk_macos_surface_configure (gdk_surface);
/* If we're using server-side decorations, this notification is coming
* in from a display-side change. We need to request a layout in
* addition to the configure event.
*/
if (GDK_IS_MACOS_TOPLEVEL_SURFACE (gdk_surface) &&
GDK_MACOS_TOPLEVEL_SURFACE (gdk_surface)->decorated)
gdk_surface_request_layout (GDK_SURFACE (gdk_surface));
}
/* Used by gdkmacosdisplay-translate.c to decide if our sendEvent() handler
* above will see the event or if it will be subjected to standard processing
* by GDK.
@@ -428,6 +401,7 @@ typedef NSString *CALayerContentsGravity;
-(void)beginManualMove
{
gboolean maximized = GDK_SURFACE (gdk_surface)->state & GDK_TOPLEVEL_STATE_MAXIMIZED;
NSPoint initialMoveLocation;
GdkPoint point;
GdkMonitor *monitor;
@@ -446,6 +420,13 @@ typedef NSString *CALayerContentsGravity;
initialMoveLocation = [NSEvent mouseLocation];
if (maximized)
[self setFrame:NSMakeRect (initialMoveLocation.x - (int)lastUnmaximizedFrame.size.width/2,
initialMoveLocation.y,
lastUnmaximizedFrame.size.width,
lastUnmaximizedFrame.size.height)
display:YES];
_gdk_macos_display_from_display_coords ([self gdkDisplay],
initialMoveLocation.x,
initialMoveLocation.y,
@@ -537,15 +518,7 @@ typedef NSString *CALayerContentsGravity;
new_frame.size.height = min_size.height;
}
/* We could also apply aspect ratio:
new_frame.size.height = new_frame.size.width / [self aspectRatio].width * [self aspectRatio].height;
*/
[self setFrame:new_frame display:YES];
/* Let the resizing be handled by GTK. */
if (g_main_context_pending (NULL))
g_main_context_iteration (NULL, FALSE);
_gdk_macos_surface_user_resize ([self gdkSurface], new_frame);
inTrackManualResize = NO;
@@ -554,49 +527,46 @@ typedef NSString *CALayerContentsGravity;
-(void)beginManualResize:(GdkSurfaceEdge)edge
{
CALayerContentsGravity gravity = kCAGravityBottomLeft;
if (inMove || inManualMove || inManualResize)
return;
inManualResize = YES;
resizeEdge = edge;
if (GDK_IS_MACOS_GL_VIEW ([self contentView]))
switch (edge)
{
CALayerContentsGravity gravity = kCAGravityBottomLeft;
default:
case GDK_SURFACE_EDGE_NORTH:
gravity = kCAGravityTopLeft;
break;
switch (edge)
{
default:
case GDK_SURFACE_EDGE_NORTH:
gravity = kCAGravityTopLeft;
break;
case GDK_SURFACE_EDGE_NORTH_WEST:
gravity = kCAGravityTopRight;
break;
case GDK_SURFACE_EDGE_NORTH_WEST:
gravity = kCAGravityTopRight;
break;
case GDK_SURFACE_EDGE_SOUTH_WEST:
case GDK_SURFACE_EDGE_WEST:
gravity = kCAGravityBottomRight;
break;
case GDK_SURFACE_EDGE_SOUTH_WEST:
case GDK_SURFACE_EDGE_WEST:
gravity = kCAGravityBottomRight;
break;
case GDK_SURFACE_EDGE_SOUTH:
case GDK_SURFACE_EDGE_SOUTH_EAST:
gravity = kCAGravityBottomLeft;
break;
case GDK_SURFACE_EDGE_SOUTH:
case GDK_SURFACE_EDGE_SOUTH_EAST:
gravity = kCAGravityBottomLeft;
break;
case GDK_SURFACE_EDGE_EAST:
gravity = kCAGravityBottomLeft;
break;
case GDK_SURFACE_EDGE_EAST:
gravity = kCAGravityBottomLeft;
break;
case GDK_SURFACE_EDGE_NORTH_EAST:
gravity = kCAGravityTopLeft;
break;
}
[[[self contentView] layer] setContentsGravity:gravity];
case GDK_SURFACE_EDGE_NORTH_EAST:
gravity = kCAGravityTopLeft;
break;
}
[[[self contentView] layer] setContentsGravity:gravity];
initialResizeFrame = [self frame];
initialResizeLocation = convert_nspoint_to_screen (self, [self mouseLocationOutsideOfEventStream]);
}
@@ -710,7 +680,12 @@ typedef NSString *CALayerContentsGravity;
is_opaque = (([self styleMask] & NSWindowStyleMaskTitled) != 0);
if (was_fullscreen != is_fullscreen)
_gdk_macos_surface_update_fullscreen_state (gdk_surface);
{
if (was_fullscreen)
[self setFrame:lastUnfullscreenFrame display:NO];
_gdk_macos_surface_update_fullscreen_state (gdk_surface);
}
if (was_opaque != is_opaque)
{
@@ -760,7 +735,6 @@ typedef NSString *CALayerContentsGravity;
if (state & GDK_TOPLEVEL_STATE_MAXIMIZED)
{
lastMaximizedFrame = newFrame;
[self windowDidUnmaximize];
}
else
{
@@ -775,16 +749,7 @@ typedef NSString *CALayerContentsGravity;
-(void)windowDidEndLiveResize:(NSNotification *)aNotification
{
gboolean maximized = GDK_SURFACE (gdk_surface)->state & GDK_TOPLEVEL_STATE_MAXIMIZED;
inMaximizeTransition = NO;
/* Even if this is CSD, we want to be opaque while maximized
* to speed up compositing by allowing the display server to
* avoid costly blends.
*/
if (maximized)
[self setOpaque:YES];
}
-(NSSize)window:(NSWindow *)window willUseFullScreenContentSize:(NSSize)proposedSize
@@ -797,12 +762,27 @@ typedef NSString *CALayerContentsGravity;
lastUnfullscreenFrame = [self frame];
}
-(void)windowDidEnterFullScreen:(NSNotification *)aNotification
{
initialPositionKnown = NO;
[self checkSendEnterNotify];
}
-(void)windowWillExitFullScreen:(NSNotification *)aNotification
{
[self setFrame:lastUnfullscreenFrame display:YES];
}
-(void)windowDidExitFullScreen:(NSNotification *)aNotification
{
initialPositionKnown = NO;
[self checkSendEnterNotify];
}
-(void)windowDidFailToEnterFullScreen:(NSNotification *)aNotification
{
}
-(void)windowDidFailToExitFullScreen:(NSNotification *)aNotification
{
}
@@ -845,4 +825,15 @@ typedef NSString *CALayerContentsGravity;
return NO;
}
-(void)swapBuffer:(GdkMacosBuffer *)buffer withDamage:(const cairo_region_t *)damage
{
[(GdkMacosView *)[self contentView] swapBuffer:buffer withDamage:damage];
}
-(BOOL)needsMouseDownQuirk
{
return GDK_IS_MACOS_TOPLEVEL_SURFACE (gdk_surface) &&
!GDK_MACOS_TOPLEVEL_SURFACE (gdk_surface)->decorated;
}
@end

View File

@@ -21,9 +21,11 @@
#import <AppKit/AppKit.h>
#import <Foundation/Foundation.h>
#import <IOSurface/IOSurface.h>
#include <gdk/gdk.h>
#include "gdkmacosbuffer-private.h"
#include "gdkmacosdisplay.h"
#include "gdkmacossurface.h"
#include "edgesnapping.h"
@@ -66,5 +68,7 @@
-(BOOL)trackManualMove;
-(BOOL)trackManualResize;
-(void)setDecorated:(BOOL)decorated;
-(void)swapBuffer:(GdkMacosBuffer *)buffer withDamage:(const cairo_region_t *)damage;
-(BOOL)needsMouseDownQuirk;
@end

View File

@@ -26,7 +26,10 @@
#include "gdkdisplaylinksource.h"
#include "gdkdebug.h"
#include "gdkmacoseventsource-private.h"
#include "gdkmacosmonitor-private.h"
#include "gdk-private.h"
static gint64 host_to_frame_clock_time (gint64 val);
@@ -64,7 +67,7 @@ gdk_display_link_source_dispatch (GSource *source,
impl->needs_dispatch = FALSE;
if (callback != NULL)
if (!impl->paused && callback != NULL)
ret = callback (user_data);
return ret;
@@ -75,7 +78,9 @@ gdk_display_link_source_finalize (GSource *source)
{
GdkDisplayLinkSource *impl = (GdkDisplayLinkSource *)source;
CVDisplayLinkStop (impl->display_link);
if (!impl->paused)
CVDisplayLinkStop (impl->display_link);
CVDisplayLinkRelease (impl->display_link);
}
@@ -89,12 +94,18 @@ static GSourceFuncs gdk_display_link_source_funcs = {
void
gdk_display_link_source_pause (GdkDisplayLinkSource *source)
{
g_return_if_fail (source->paused == FALSE);
source->paused = TRUE;
CVDisplayLinkStop (source->display_link);
}
void
gdk_display_link_source_unpause (GdkDisplayLinkSource *source)
{
g_return_if_fail (source->paused == TRUE);
source->paused = FALSE;
CVDisplayLinkStart (source->display_link);
}
@@ -146,6 +157,7 @@ gdk_display_link_source_frame_cb (CVDisplayLinkRef display_link,
/**
* gdk_display_link_source_new:
* @display_id: the identifier of the monitor
*
* Creates a new `GSource` that will activate the dispatch function upon
* notification from a CVDisplayLink that a new frame should be drawn.
@@ -158,41 +170,61 @@ gdk_display_link_source_frame_cb (CVDisplayLinkRef display_link,
* Returns: (transfer full): A newly created `GSource`
*/
GSource *
gdk_display_link_source_new (void)
gdk_display_link_source_new (CGDirectDisplayID display_id,
CGDisplayModeRef mode)
{
GdkDisplayLinkSource *impl;
GSource *source;
CVReturn ret;
double period;
char *name;
source = g_source_new (&gdk_display_link_source_funcs, sizeof *impl);
impl = (GdkDisplayLinkSource *)source;
impl->display_id = display_id;
impl->paused = TRUE;
/*
* Create our link based on currently connected displays.
* If there are multiple displays, this will be something that tries
* to work for all of them. In the future, we may want to explore multiple
* links based on the connected displays.
/* Create DisplayLink for timing information for the display in
* question so that we can produce graphics for that display at whatever
* rate it can provide.
*/
ret = CVDisplayLinkCreateWithActiveCGDisplays (&impl->display_link);
if (ret != kCVReturnSuccess)
if (CVDisplayLinkCreateWithCGDisplay (display_id, &impl->display_link) != kCVReturnSuccess)
{
g_warning ("Failed to initialize CVDisplayLink!");
return source;
goto failure;
}
/*
* Determine our nominal period between frames.
*/
period = CVDisplayLinkGetActualOutputVideoRefreshPeriod (impl->display_link);
if (period == 0.0)
period = 1.0 / 60.0;
impl->refresh_interval = period * 1000000L;
impl->refresh_rate = 1.0 / period * 1000L;
impl->refresh_rate = CGDisplayModeGetRefreshRate (mode) * 1000.0;
/*
* Wire up our callback to be executed within the high-priority thread.
*/
if (impl->refresh_rate == 0)
{
const CVTime time = CVDisplayLinkGetNominalOutputVideoRefreshPeriod (impl->display_link);
if (!(time.flags & kCVTimeIsIndefinite))
impl->refresh_rate = (double)time.timeScale / (double)time.timeValue * 1000.0;
}
if (impl->refresh_rate != 0)
{
impl->refresh_interval = 1000000.0 / (double)impl->refresh_rate * 1000.0;
}
else
{
double period = CVDisplayLinkGetActualOutputVideoRefreshPeriod (impl->display_link);
if (period == 0.0)
period = 1.0 / 60.0;
impl->refresh_rate = 1.0 / period * 1000L;
impl->refresh_interval = period * 1000000L;
}
name = _gdk_macos_monitor_get_connector_name (display_id);
GDK_NOTE (MISC,
g_message ("Monitor \"%s\" discovered with Refresh Rate %d and Interval %"G_GINT64_FORMAT,
name ? name : "unknown",
impl->refresh_rate,
impl->refresh_interval));
g_free (name);
/* Wire up our callback to be executed within the high-priority thread. */
CVDisplayLinkSetOutputCallback (impl->display_link,
gdk_display_link_source_frame_cb,
source);
@@ -200,6 +232,10 @@ gdk_display_link_source_new (void)
g_source_set_static_name (source, "[gdk] quartz frame clock");
return source;
failure:
g_source_unref (source);
return NULL;
}
static gint64

View File

@@ -30,17 +30,20 @@ G_BEGIN_DECLS
typedef struct
{
GSource source;
GSource source;
CVDisplayLinkRef display_link;
gint64 refresh_interval;
guint refresh_rate;
CGDirectDisplayID display_id;
CVDisplayLinkRef display_link;
gint64 refresh_interval;
guint refresh_rate;
guint paused : 1;
volatile gint64 presentation_time;
volatile guint needs_dispatch;
volatile gint64 presentation_time;
volatile guint needs_dispatch;
} GdkDisplayLinkSource;
GSource *gdk_display_link_source_new (void);
GSource *gdk_display_link_source_new (CGDirectDisplayID display_id,
CGDisplayModeRef mode);
void gdk_display_link_source_pause (GdkDisplayLinkSource *source);
void gdk_display_link_source_unpause (GdkDisplayLinkSource *source);

View File

@@ -0,0 +1,60 @@
/*
* Copyright © 2021 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#ifndef __GDK_MACOS_BUFFER_PRIVATE_H__
#define __GDK_MACOS_BUFFER_PRIVATE_H__
#include <CoreGraphics/CoreGraphics.h>
#include <Foundation/Foundation.h>
#include <IOSurface/IOSurface.h>
#include <cairo.h>
#include <glib-object.h>
G_BEGIN_DECLS
#define GDK_TYPE_MACOS_BUFFER (gdk_macos_buffer_get_type())
G_DECLARE_FINAL_TYPE (GdkMacosBuffer, gdk_macos_buffer, GDK, MACOS_BUFFER, GObject)
GdkMacosBuffer *_gdk_macos_buffer_new (int width,
int height,
double device_scale,
int bytes_per_element,
int bits_per_pixel);
IOSurfaceRef _gdk_macos_buffer_get_native (GdkMacosBuffer *self);
void _gdk_macos_buffer_lock (GdkMacosBuffer *self);
void _gdk_macos_buffer_unlock (GdkMacosBuffer *self);
void _gdk_macos_buffer_read_lock (GdkMacosBuffer *self);
void _gdk_macos_buffer_read_unlock (GdkMacosBuffer *self);
guint _gdk_macos_buffer_get_width (GdkMacosBuffer *self);
guint _gdk_macos_buffer_get_height (GdkMacosBuffer *self);
guint _gdk_macos_buffer_get_stride (GdkMacosBuffer *self);
double _gdk_macos_buffer_get_device_scale (GdkMacosBuffer *self);
const cairo_region_t *_gdk_macos_buffer_get_damage (GdkMacosBuffer *self);
void _gdk_macos_buffer_set_damage (GdkMacosBuffer *self,
cairo_region_t *damage);
gpointer _gdk_macos_buffer_get_data (GdkMacosBuffer *self);
gboolean _gdk_macos_buffer_get_flipped (GdkMacosBuffer *self);
void _gdk_macos_buffer_set_flipped (GdkMacosBuffer *self,
gboolean flipped);
G_END_DECLS
#endif /* __GDK_MACOS_BUFFER_PRIVATE_H__ */

310
gdk/macos/gdkmacosbuffer.c Normal file
View File

@@ -0,0 +1,310 @@
/*
* Copyright © 2021 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "config.h"
#include <IOSurface/IOSurface.h>
#include <Foundation/Foundation.h>
#include <OpenGL/CGLIOSurface.h>
#include <QuartzCore/QuartzCore.h>
#include "gdkmacosbuffer-private.h"
struct _GdkMacosBuffer
{
GObject parent_instance;
cairo_region_t *damage;
IOSurfaceRef surface;
int lock_count;
guint bytes_per_element;
guint bits_per_pixel;
guint width;
guint height;
guint stride;
double device_scale;
guint flipped : 1;
};
G_DEFINE_TYPE (GdkMacosBuffer, gdk_macos_buffer, G_TYPE_OBJECT)
static void
gdk_macos_buffer_dispose (GObject *object)
{
GdkMacosBuffer *self = (GdkMacosBuffer *)object;
if (self->lock_count != 0)
g_critical ("Attempt to dispose %s while lock is held",
G_OBJECT_TYPE_NAME (self));
/* We could potentially force the unload of our surface here with
* IOSurfaceSetPurgeable (self->surface, kIOSurfacePurgeableEmpty, NULL)
* but that would cause it to empty when the layers may still be attached
* to it. Better to just let it get GC'd by the system after they have
* moved on to a new buffer.
*/
g_clear_pointer (&self->surface, CFRelease);
g_clear_pointer (&self->damage, cairo_region_destroy);
G_OBJECT_CLASS (gdk_macos_buffer_parent_class)->dispose (object);
}
static void
gdk_macos_buffer_class_init (GdkMacosBufferClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = gdk_macos_buffer_dispose;
}
static void
gdk_macos_buffer_init (GdkMacosBuffer *self)
{
}
static void
add_int (CFMutableDictionaryRef dict,
const CFStringRef key,
int value)
{
CFNumberRef number = CFNumberCreate (NULL, kCFNumberIntType, &value);
CFDictionaryAddValue (dict, key, number);
CFRelease (number);
}
static IOSurfaceRef
create_surface (int width,
int height,
int bytes_per_element,
guint *stride)
{
CFMutableDictionaryRef props;
IOSurfaceRef ret;
size_t bytes_per_row;
size_t total_bytes;
props = CFDictionaryCreateMutable (kCFAllocatorDefault,
16,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
if (props == NULL)
return NULL;
bytes_per_row = IOSurfaceAlignProperty (kIOSurfaceBytesPerRow, width * bytes_per_element);
total_bytes = IOSurfaceAlignProperty (kIOSurfaceAllocSize, height * bytes_per_row);
add_int (props, kIOSurfaceAllocSize, total_bytes);
add_int (props, kIOSurfaceBytesPerElement, bytes_per_element);
add_int (props, kIOSurfaceBytesPerRow, bytes_per_row);
add_int (props, kIOSurfaceHeight, height);
add_int (props, kIOSurfacePixelFormat, (int)'BGRA');
add_int (props, kIOSurfaceWidth, width);
ret = IOSurfaceCreate (props);
CFRelease (props);
*stride = bytes_per_row;
return ret;
}
GdkMacosBuffer *
_gdk_macos_buffer_new (int width,
int height,
double device_scale,
int bytes_per_element,
int bits_per_pixel)
{
GdkMacosBuffer *self;
g_return_val_if_fail (width > 0, NULL);
g_return_val_if_fail (height > 0, NULL);
self = g_object_new (GDK_TYPE_MACOS_BUFFER, NULL);
self->bytes_per_element = bytes_per_element;
self->bits_per_pixel = bits_per_pixel;
self->surface = create_surface (width, height, bytes_per_element, &self->stride);
self->width = width;
self->height = height;
self->device_scale = device_scale;
self->lock_count = 0;
if (self->surface == NULL)
g_clear_object (&self);
return self;
}
IOSurfaceRef
_gdk_macos_buffer_get_native (GdkMacosBuffer *self)
{
g_return_val_if_fail (GDK_IS_MACOS_BUFFER (self), NULL);
return self->surface;
}
/**
* _gdk_macos_buffer_lock:
*
* This function matches the IOSurfaceLock() name but what it really
* does is page the buffer back for the CPU to access from VRAM.
*
* Generally we don't want to do that, but we do need to in some
* cases such as when we are rendering with Cairo. There might
* be an opportunity later to avoid that, but since we are using
* GL pretty much everywhere already, we don't try.
*/
void
_gdk_macos_buffer_lock (GdkMacosBuffer *self)
{
g_return_if_fail (GDK_IS_MACOS_BUFFER (self));
g_return_if_fail (self->lock_count == 0);
self->lock_count++;
IOSurfaceLock (self->surface, 0, NULL);
}
void
_gdk_macos_buffer_unlock (GdkMacosBuffer *self)
{
g_return_if_fail (GDK_IS_MACOS_BUFFER (self));
g_return_if_fail (self->lock_count == 1);
self->lock_count--;
IOSurfaceUnlock (self->surface, 0, NULL);
}
/**
* _gdk_macos_buffer_lock_readonly:
*
* Like _gdk_macos_buffer_lock() but uses the read-only flag to
* indicate we are not interested in retrieving the updates from
* the GPU before modifying the CPU-side cache.
*
* Must be used with _gdk_macos_buffer_unlock_readonly().
*/
void
_gdk_macos_buffer_read_lock (GdkMacosBuffer *self)
{
kern_return_t ret;
g_return_if_fail (GDK_IS_MACOS_BUFFER (self));
g_return_if_fail (self->lock_count == 0);
self->lock_count++;
ret = IOSurfaceLock (self->surface, kIOSurfaceLockReadOnly, NULL);
g_return_if_fail (ret == KERN_SUCCESS);
}
void
_gdk_macos_buffer_read_unlock (GdkMacosBuffer *self)
{
kern_return_t ret;
g_return_if_fail (GDK_IS_MACOS_BUFFER (self));
g_return_if_fail (self->lock_count == 1);
self->lock_count--;
ret = IOSurfaceUnlock (self->surface, kIOSurfaceLockReadOnly, NULL);
g_return_if_fail (ret == KERN_SUCCESS);
}
guint
_gdk_macos_buffer_get_width (GdkMacosBuffer *self)
{
g_return_val_if_fail (GDK_IS_MACOS_BUFFER (self), 0);
return self->width;
}
guint
_gdk_macos_buffer_get_height (GdkMacosBuffer *self)
{
g_return_val_if_fail (GDK_IS_MACOS_BUFFER (self), 0);
return self->height;
}
guint
_gdk_macos_buffer_get_stride (GdkMacosBuffer *self)
{
g_return_val_if_fail (GDK_IS_MACOS_BUFFER (self), 0);
return self->stride;
}
double
_gdk_macos_buffer_get_device_scale (GdkMacosBuffer *self)
{
g_return_val_if_fail (GDK_IS_MACOS_BUFFER (self), 1.0);
return self->device_scale;
}
const cairo_region_t *
_gdk_macos_buffer_get_damage (GdkMacosBuffer *self)
{
g_return_val_if_fail (GDK_IS_MACOS_BUFFER (self), NULL);
return self->damage;
}
void
_gdk_macos_buffer_set_damage (GdkMacosBuffer *self,
cairo_region_t *damage)
{
g_return_if_fail (GDK_IS_MACOS_BUFFER (self));
if (damage == self->damage)
return;
g_clear_pointer (&self->damage, cairo_region_destroy);
self->damage = cairo_region_copy (damage);
}
gpointer
_gdk_macos_buffer_get_data (GdkMacosBuffer *self)
{
g_return_val_if_fail (GDK_IS_MACOS_BUFFER (self), NULL);
return IOSurfaceGetBaseAddress (self->surface);
}
gboolean
_gdk_macos_buffer_get_flipped (GdkMacosBuffer *self)
{
g_return_val_if_fail (GDK_IS_MACOS_BUFFER (self), FALSE);
return self->flipped;
}
void
_gdk_macos_buffer_set_flipped (GdkMacosBuffer *self,
gboolean flipped)
{
g_return_if_fail (GDK_IS_MACOS_BUFFER (self));
self->flipped = !!flipped;
}

View File

@@ -22,18 +22,17 @@
#include "gdkconfig.h"
#include <cairo.h>
#include <QuartzCore/QuartzCore.h>
#include <CoreGraphics/CoreGraphics.h>
#import "GdkMacosCairoView.h"
#include "gdkmacosbuffer-private.h"
#include "gdkmacoscairocontext-private.h"
#include "gdkmacossurface-private.h"
struct _GdkMacosCairoContext
{
GdkCairoContext parent_instance;
cairo_surface_t *window_surface;
GdkCairoContext parent_instance;
};
struct _GdkMacosCairoContextClass
@@ -43,41 +42,150 @@ struct _GdkMacosCairoContextClass
G_DEFINE_TYPE (GdkMacosCairoContext, _gdk_macos_cairo_context, GDK_TYPE_CAIRO_CONTEXT)
static cairo_surface_t *
create_cairo_surface_for_surface (GdkSurface *surface)
{
cairo_surface_t *cairo_surface;
int scale;
int width;
int height;
g_assert (GDK_IS_MACOS_SURFACE (surface));
scale = gdk_surface_get_scale_factor (surface);
width = scale * gdk_surface_get_width (surface);
height = scale * gdk_surface_get_height (surface);
/* We use a cairo image surface here instead of a quartz surface because we
* get strange artifacts with the quartz surface such as empty cross-fades
* when hovering buttons. For performance, we want to be using GL rendering
* so there isn't much point here as correctness is better.
*/
cairo_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
if (cairo_surface != NULL)
cairo_surface_set_device_scale (cairo_surface, scale, scale);
return cairo_surface;
}
static cairo_t *
_gdk_macos_cairo_context_cairo_create (GdkCairoContext *cairo_context)
{
GdkMacosCairoContext *self = (GdkMacosCairoContext *)cairo_context;
const cairo_region_t *damage;
cairo_surface_t *image_surface;
GdkMacosBuffer *buffer;
GdkSurface *surface;
NSWindow *nswindow;
cairo_t *cr;
gpointer data;
double scale;
guint width;
guint height;
guint stride;
gboolean opaque;
g_assert (GDK_IS_MACOS_CAIRO_CONTEXT (self));
return cairo_create (self->window_surface);
surface = gdk_draw_context_get_surface (GDK_DRAW_CONTEXT (self));
nswindow = _gdk_macos_surface_get_native (GDK_MACOS_SURFACE (surface));
opaque = [nswindow isOpaque];
buffer = _gdk_macos_surface_get_buffer (GDK_MACOS_SURFACE (surface));
damage = _gdk_macos_buffer_get_damage (buffer);
width = _gdk_macos_buffer_get_width (buffer);
height = _gdk_macos_buffer_get_height (buffer);
scale = _gdk_macos_buffer_get_device_scale (buffer);
stride = _gdk_macos_buffer_get_stride (buffer);
data = _gdk_macos_buffer_get_data (buffer);
/* Instead of forcing cairo to do everything through a CGContext,
* we just use an image surface backed by an IOSurfaceRef mapped
* into user-space. We can then use pixman which is quite fast as
* far as software rendering goes.
*
* Additionally, cairo_quartz_surface_t can't handle a number of
* tricks that the GSK cairo renderer does with border nodes and
* shadows, so an image surface is necessary for that.
*
* Since our IOSurfaceRef is width*scale-by-height*scale, we undo
* the scaling using cairo_surface_set_device_scale() so the renderer
* just thinks it's on a 2x scale surface for HiDPI.
*/
image_surface = cairo_image_surface_create_for_data (data,
CAIRO_FORMAT_ARGB32,
width,
height,
stride);
cairo_surface_set_device_scale (image_surface, scale, scale);
/* The buffer should already be locked at this point, and will
* be unlocked as part of end_frame.
*/
if (!(cr = cairo_create (image_surface)))
goto failure;
/* Clip to the current damage region */
if (damage != NULL)
{
gdk_cairo_region (cr, damage);
cairo_clip (cr);
}
/* If we have some exposed transparent area in the damage region,
* we need to clear the existing content first to leave an transparent
* area for cairo. We use (surface_bounds or damage)-(opaque) to get
* the smallest set of rectangles we need to clear as it's expensive.
*/
if (!opaque)
{
cairo_region_t *transparent;
cairo_rectangle_int_t r = { 0, 0, width/scale, height/scale };
cairo_save (cr);
if (damage != NULL)
cairo_region_get_extents (damage, &r);
transparent = cairo_region_create_rectangle (&r);
if (surface->opaque_region)
cairo_region_subtract (transparent, surface->opaque_region);
if (!cairo_region_is_empty (transparent))
{
gdk_cairo_region (cr, transparent);
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
cairo_fill (cr);
}
cairo_region_destroy (transparent);
cairo_restore (cr);
}
failure:
cairo_surface_destroy (image_surface);
return cr;
}
static void
copy_surface_data (GdkMacosBuffer *from,
GdkMacosBuffer *to,
const cairo_region_t *region,
int scale)
{
const guint8 *from_base;
guint8 *to_base;
guint from_stride;
guint to_stride;
guint n_rects;
g_assert (GDK_IS_MACOS_BUFFER (from));
g_assert (GDK_IS_MACOS_BUFFER (to));
g_assert (region != NULL);
g_assert (!cairo_region_is_empty (region));
from_base = _gdk_macos_buffer_get_data (from);
from_stride = _gdk_macos_buffer_get_stride (from);
to_base = _gdk_macos_buffer_get_data (to);
to_stride = _gdk_macos_buffer_get_stride (to);
n_rects = cairo_region_num_rectangles (region);
for (guint i = 0; i < n_rects; i++)
{
cairo_rectangle_int_t rect;
int y2;
cairo_region_get_rectangle (region, i, &rect);
rect.y *= scale;
rect.height *= scale;
rect.x *= scale;
rect.width *= scale;
y2 = rect.y + rect.height;
for (int y = rect.y; y < y2; y++)
memcpy (&to_base[y * to_stride + rect.x * 4],
&from_base[y * from_stride + rect.x * 4],
rect.width * 4);
}
}
static void
@@ -86,28 +194,49 @@ _gdk_macos_cairo_context_begin_frame (GdkDrawContext *draw_context,
cairo_region_t *region)
{
GdkMacosCairoContext *self = (GdkMacosCairoContext *)draw_context;
GdkSurface *surface;
NSWindow *nswindow;
GdkMacosBuffer *buffer;
GdkMacosSurface *surface;
g_assert (GDK_IS_MACOS_CAIRO_CONTEXT (self));
surface = gdk_draw_context_get_surface (draw_context);
nswindow = _gdk_macos_surface_get_native (GDK_MACOS_SURFACE (surface));
[CATransaction begin];
[CATransaction setDisableActions:YES];
if (self->window_surface == NULL)
surface = GDK_MACOS_SURFACE (gdk_draw_context_get_surface (draw_context));
buffer = _gdk_macos_surface_get_buffer (surface);
_gdk_macos_buffer_set_damage (buffer, region);
_gdk_macos_buffer_set_flipped (buffer, FALSE);
_gdk_macos_buffer_lock (buffer);
/* If there is damage that was on the previous frame that is not on
* this frame, we need to copy that rendered region over to the back
* buffer so that when swapping buffers, we still have that content.
* This is done with a read-only lock on the IOSurface to avoid
* invalidating the buffer contents.
*/
if (surface->front != NULL)
{
self->window_surface = create_cairo_surface_for_surface (surface);
}
else
{
if (![nswindow isOpaque])
const cairo_region_t *previous = _gdk_macos_buffer_get_damage (surface->front);
if (previous != NULL)
{
cairo_t *cr = cairo_create (self->window_surface);
gdk_cairo_region (cr, region);
cairo_set_source_rgba (cr, 0, 0, 0, 0);
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
cairo_fill (cr);
cairo_destroy (cr);
cairo_region_t *copy;
copy = cairo_region_copy (previous);
cairo_region_subtract (copy, region);
if (!cairo_region_is_empty (copy))
{
int scale = gdk_surface_get_scale_factor (GDK_SURFACE (surface));
_gdk_macos_buffer_read_lock (surface->front);
copy_surface_data (surface->front, buffer, copy, scale);
_gdk_macos_buffer_read_unlock (surface->front);
}
cairo_region_destroy (copy);
}
}
}
@@ -117,28 +246,27 @@ _gdk_macos_cairo_context_end_frame (GdkDrawContext *draw_context,
cairo_region_t *painted)
{
GdkMacosCairoContext *self = (GdkMacosCairoContext *)draw_context;
GdkSurface *surface;
NSView *nsview;
GdkMacosSurface *surface;
GdkMacosBuffer *buffer;
g_assert (GDK_IS_MACOS_CAIRO_CONTEXT (self));
g_assert (self->window_surface != NULL);
surface = gdk_draw_context_get_surface (draw_context);
nsview = _gdk_macos_surface_get_view (GDK_MACOS_SURFACE (surface));
surface = GDK_MACOS_SURFACE (gdk_draw_context_get_surface (draw_context));
buffer = _gdk_macos_surface_get_buffer (surface);
if (GDK_IS_MACOS_CAIRO_VIEW (nsview))
[(GdkMacosCairoView *)nsview setCairoSurface:self->window_surface
withDamage:painted];
_gdk_macos_buffer_unlock (buffer);
_gdk_macos_surface_swap_buffers (surface, painted);
[CATransaction commit];
}
static void
_gdk_macos_cairo_context_surface_resized (GdkDrawContext *draw_context)
{
GdkMacosCairoContext *self = (GdkMacosCairoContext *)draw_context;
g_assert (GDK_IS_MACOS_CAIRO_CONTEXT (draw_context));
g_assert (GDK_IS_MACOS_CAIRO_CONTEXT (self));
g_clear_pointer (&self->window_surface, cairo_surface_destroy);
/* Do nothing, next begin_frame will get new buffer */
}
static void

View File

@@ -0,0 +1,105 @@
/*
* Copyright © 2022 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "config.h"
#include <AppKit/AppKit.h>
#include "gdkmacosdisplay-private.h"
#include "gdkmacossurface-private.h"
static void
gdk_macos_display_user_defaults_changed_cb (CFNotificationCenterRef center,
void *observer,
CFStringRef name,
const void *object,
CFDictionaryRef userInfo)
{
GdkMacosDisplay *self = observer;
g_assert (GDK_IS_MACOS_DISPLAY (self));
_gdk_macos_display_reload_settings (self);
}
static void
gdk_macos_display_monitors_changed_cb (CFNotificationCenterRef center,
void *observer,
CFStringRef name,
const void *object,
CFDictionaryRef userInfo)
{
GdkMacosDisplay *self = observer;
g_assert (GDK_IS_MACOS_DISPLAY (self));
_gdk_macos_display_reload_monitors (self);
/* Now we need to update all our surface positions since they
* probably just changed origins.
*/
for (const GList *iter = _gdk_macos_display_get_surfaces (self);
iter != NULL;
iter = iter->next)
{
GdkMacosSurface *surface = iter->data;
g_assert (GDK_IS_MACOS_SURFACE (surface));
_gdk_macos_surface_monitor_changed (surface);
}
}
void
_gdk_macos_display_feedback_init (GdkMacosDisplay *self)
{
g_return_if_fail (GDK_IS_MACOS_DISPLAY (self));
CFNotificationCenterAddObserver (CFNotificationCenterGetLocalCenter (),
self,
gdk_macos_display_monitors_changed_cb,
CFSTR ("NSApplicationDidChangeScreenParametersNotification"),
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
CFNotificationCenterAddObserver (CFNotificationCenterGetDistributedCenter (),
self,
gdk_macos_display_user_defaults_changed_cb,
CFSTR ("NSUserDefaultsDidChangeNotification"),
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
}
void
_gdk_macos_display_feedback_destroy (GdkMacosDisplay *self)
{
g_return_if_fail (GDK_IS_MACOS_DISPLAY (self));
CFNotificationCenterRemoveObserver (CFNotificationCenterGetDistributedCenter (),
self,
CFSTR ("NSApplicationDidChangeScreenParametersNotification"),
NULL);
CFNotificationCenterRemoveObserver (CFNotificationCenterGetDistributedCenter (),
self,
CFSTR ("NSUserDefaultsDidChangeNotification"),
NULL);
}

View File

@@ -43,6 +43,8 @@ G_BEGIN_DECLS
#define GIC_FILTER_PASSTHRU 0
#define GIC_FILTER_FILTERED 1
#define GDK_MACOS_EVENT_DROP (GdkEvent *)GSIZE_TO_POINTER(1)
struct _GdkMacosDisplay
{
GdkDisplay parent_instance;
@@ -68,16 +70,6 @@ struct _GdkMacosDisplay
*/
GQueue sorted_surfaces;
/* Our CVDisplayLink based GSource which we use to freeze/thaw the
* GdkFrameClock for the surface.
*/
GSource *frame_source;
/* A queue of surfaces which we know are awaiting frames to be drawn. This
* uses the GdkMacosSurface.frame link.
*/
GQueue awaiting_frames;
/* The surface that is receiving keyboard events */
GdkMacosSurface *keyboard_surface;
@@ -92,6 +84,14 @@ struct _GdkMacosDisplay
int min_y;
int max_x;
int max_y;
/* A GSource to select a new main/key window */
guint select_key_in_idle;
/* Note if we have a key window that is not a GdkMacosWindow
* such as a NSPanel used for native dialogs.
*/
guint key_window_is_foregin : 1;
};
struct _GdkMacosDisplayClass
@@ -124,6 +124,8 @@ GdkMonitor *_gdk_macos_display_get_monitor_at_display_coords (GdkMacosDisp
int y);
GdkEvent *_gdk_macos_display_translate (GdkMacosDisplay *self,
NSEvent *event);
void _gdk_macos_display_feedback_init (GdkMacosDisplay *self);
void _gdk_macos_display_feedback_destroy (GdkMacosDisplay *self);
void _gdk_macos_display_break_all_grabs (GdkMacosDisplay *self,
guint32 time);
GdkModifierType _gdk_macos_display_get_current_keyboard_modifiers (GdkMacosDisplay *self);
@@ -136,10 +138,6 @@ GdkMacosSurface *_gdk_macos_display_get_surface_at_display_coords (GdkMacosDisp
void _gdk_macos_display_reload_monitors (GdkMacosDisplay *self);
void _gdk_macos_display_surface_removed (GdkMacosDisplay *self,
GdkMacosSurface *surface);
void _gdk_macos_display_add_frame_callback (GdkMacosDisplay *self,
GdkMacosSurface *surface);
void _gdk_macos_display_remove_frame_callback (GdkMacosDisplay *self,
GdkMacosSurface *surface);
NSWindow *_gdk_macos_display_find_native_under_pointer (GdkMacosDisplay *self,
int *x,
int *y);
@@ -155,7 +153,6 @@ void _gdk_macos_display_surface_resigned_key (GdkMacosDisp
GdkMacosSurface *surface);
void _gdk_macos_display_surface_became_key (GdkMacosDisplay *self,
GdkMacosSurface *surface);
int _gdk_macos_display_get_nominal_refresh_rate (GdkMacosDisplay *self);
void _gdk_macos_display_clear_sorting (GdkMacosDisplay *self);
const GList *_gdk_macos_display_get_surfaces (GdkMacosDisplay *self);
void _gdk_macos_display_send_button_event (GdkMacosDisplay *self,
@@ -174,6 +171,10 @@ void _gdk_macos_display_set_drag (GdkMacosDisp
void _gdk_macos_display_set_drop (GdkMacosDisplay *self,
NSInteger sequence_number,
GdkDrop *drop);
void _gdk_macos_display_position_surface (GdkMacosDisplay *self,
GdkMacosSurface *surface,
int *x,
int *y);
G_END_DECLS

View File

@@ -34,7 +34,7 @@ typedef struct
const char *font_name;
int xft_dpi;
int double_click_time;
int cursor_blink_timeout;
int cursor_blink_time;
guint enable_animations : 1;
guint shell_shows_desktop : 1;
guint shell_shows_menubar : 1;
@@ -65,9 +65,9 @@ _gdk_macos_settings_load (GdkMacosSettings *settings)
ival = [defaults integerForKey:@"NSTextInsertionPointBlinkPeriod"];
if (ival > 0)
settings->cursor_blink_timeout = ival;
settings->cursor_blink_time = ival;
else
settings->cursor_blink_timeout = 1000;
settings->cursor_blink_time = 1000;
settings->primary_button_warps_slider =
[[NSUserDefaults standardUserDefaults] boolForKey:@"AppleScrollerPagingBehavior"] == YES;
@@ -124,9 +124,9 @@ _gdk_macos_display_get_setting (GdkMacosDisplay *self,
g_value_set_int (value, current_settings.xft_dpi);
ret = TRUE;
}
else if (strcmp (setting, "gtk-cursor-blink-timeout") == 0)
else if (strcmp (setting, "gtk-cursor-blink-time") == 0)
{
g_value_set_int (value, current_settings.cursor_blink_timeout);
g_value_set_int (value, current_settings.cursor_blink_time);
ret = TRUE;
}
else if (strcmp (setting, "gtk-double-click-time") == 0)

View File

@@ -211,6 +211,7 @@ fill_button_event (GdkMacosDisplay *display,
GdkDevice *pointer = NULL;
GdkDeviceTool *tool = NULL;
double *axes = NULL;
cairo_region_t *input_region;
g_assert (GDK_IS_MACOS_DISPLAY (display));
g_assert (GDK_IS_MACOS_SURFACE (surface));
@@ -218,6 +219,7 @@ fill_button_event (GdkMacosDisplay *display,
seat = gdk_display_get_default_seat (GDK_DISPLAY (display));
state = get_keyboard_modifiers_from_ns_event (nsevent) |
_gdk_macos_display_get_current_mouse_modifiers (display);
input_region = GDK_SURFACE (surface)->input_region;
switch ((int)[nsevent type])
{
@@ -244,7 +246,8 @@ fill_button_event (GdkMacosDisplay *display,
*/
if (type == GDK_BUTTON_PRESS &&
(x < 0 || x > GDK_SURFACE (surface)->width ||
y < 0 || y > GDK_SURFACE (surface)->height))
y < 0 || y > GDK_SURFACE (surface)->height ||
(input_region && !cairo_region_contains_point (input_region, x, y))))
return NULL;
if (([nsevent subtype] == NSEventSubtypeTabletPoint) &&
@@ -609,6 +612,8 @@ fill_scroll_event (GdkMacosDisplay *self,
GdkModifierType state;
GdkDevice *pointer;
GdkEvent *ret = NULL;
NSEventPhase phase;
NSEventPhase momentumPhase;
GdkSeat *seat;
double dx;
double dy;
@@ -616,11 +621,31 @@ fill_scroll_event (GdkMacosDisplay *self,
g_assert (GDK_IS_MACOS_SURFACE (surface));
g_assert (nsevent != NULL);
phase = [nsevent phase];
momentumPhase = [nsevent momentumPhase];
/* Ignore kinetic scroll events from the display server as we already
* handle those internally.
*/
if (phase == 0 && momentumPhase != 0)
return GDK_MACOS_EVENT_DROP;
seat = gdk_display_get_default_seat (GDK_DISPLAY (self));
pointer = gdk_seat_get_pointer (seat);
state = _gdk_macos_display_get_current_mouse_modifiers (self) |
_gdk_macos_display_get_current_keyboard_modifiers (self);
/* If we are starting a new phase, send a stop so any previous
* scrolling immediately stops.
*/
if (phase == NSEventPhaseMayBegin)
return gdk_scroll_event_new (GDK_SURFACE (surface),
pointer,
NULL,
get_time_from_ns_event (nsevent),
state,
0.0, 0.0, TRUE);
dx = [nsevent deltaX];
dy = [nsevent deltaY];
@@ -664,34 +689,32 @@ fill_scroll_event (GdkMacosDisplay *self,
dy = 0.0;
}
if (dx != 0.0 || dy != 0.0)
if ((dx != 0.0 || dy != 0.0) && ![nsevent hasPreciseScrollingDeltas])
{
if ([nsevent hasPreciseScrollingDeltas])
{
GdkEvent *emulated;
g_assert (ret == NULL);
emulated = gdk_scroll_event_new_discrete (GDK_SURFACE (surface),
pointer,
NULL,
get_time_from_ns_event (nsevent),
state,
direction,
TRUE);
_gdk_event_queue_append (GDK_DISPLAY (self), emulated);
}
else
{
g_assert (ret == NULL);
ret = gdk_scroll_event_new_discrete (GDK_SURFACE (surface),
pointer,
NULL,
get_time_from_ns_event (nsevent),
state,
direction,
FALSE);
}
ret = gdk_scroll_event_new (GDK_SURFACE (surface),
pointer,
NULL,
get_time_from_ns_event (nsevent),
state,
dx,
dy,
FALSE);
}
if (phase == NSEventPhaseEnded || phase == NSEventPhaseCancelled)
{
/* The user must have released their fingers in a touchpad
* scroll, so try to send a scroll is_stop event.
*/
if (ret != NULL)
_gdk_event_queue_append (GDK_DISPLAY (self), g_steal_pointer (&ret));
ret = gdk_scroll_event_new (GDK_SURFACE (surface),
pointer,
NULL,
get_time_from_ns_event (nsevent),
state,
0.0, 0.0, TRUE);
}
return g_steal_pointer (&ret);
@@ -854,9 +877,9 @@ get_surface_from_ns_event (GdkMacosDisplay *self,
find_under_pointer:
if (!surface)
if (surface == NULL && nswindow == NULL)
{
/* Fallback used when no NSSurface set. This happens e.g. when
/* Fallback used when no NSWindow set. This happens e.g. when
* we allow motion events without a window set in gdk_event_translate()
* that occur immediately after the main menu bar was clicked/used.
* This fallback will not return coordinates contained in a window's
@@ -906,7 +929,13 @@ find_surface_for_mouse_event (GdkMacosDisplay *self,
GdkDeviceGrabInfo *grab;
GdkSeat *seat;
surface = get_surface_from_ns_event (self, nsevent, &point, x, y);
/* Even if we had a surface window, it might be for something outside
* the input region (shadow) which we might want to ignore. This is
* handled for us deeper in the event unwrapping.
*/
if (!(surface = get_surface_from_ns_event (self, nsevent, &point, x, y)))
return NULL;
display = gdk_surface_get_display (surface);
seat = gdk_display_get_default_seat (GDK_DISPLAY (self));
pointer = gdk_seat_get_pointer (seat);
@@ -1008,11 +1037,6 @@ find_surface_for_ns_event (GdkMacosDisplay *self,
g_assert (x != NULL);
g_assert (y != NULL);
if (!(surface = get_surface_from_ns_event (self, nsevent, &point, x, y)))
return NULL;
view = (GdkMacosBaseView *)[GDK_MACOS_SURFACE (surface)->window contentView];
_gdk_macos_display_from_display_coords (self, point.x, point.y, &x_tmp, &y_tmp);
switch ((int)[nsevent type])
@@ -1037,7 +1061,9 @@ find_surface_for_ns_event (GdkMacosDisplay *self,
/* Only handle our own entered/exited events, not the ones for the
* titlebar buttons.
*/
if ([nsevent trackingArea] == [view trackingArea])
if ((surface = get_surface_from_ns_event (self, nsevent, &point, x, y)) &&
(view = (GdkMacosBaseView *)[GDK_MACOS_SURFACE (surface)->window contentView]) &&
([nsevent trackingArea] == [view trackingArea]))
return GDK_MACOS_SURFACE (surface);
else
return NULL;
@@ -1060,6 +1086,7 @@ _gdk_macos_display_translate (GdkMacosDisplay *self,
GdkMacosSurface *surface;
GdkMacosWindow *window;
NSEventType event_type;
NSWindow *event_window;
GdkEvent *ret = NULL;
int x;
int y;
@@ -1102,6 +1129,15 @@ _gdk_macos_display_translate (GdkMacosDisplay *self,
return NULL;
}
/* If the event was delivered to NSWindow that is foreign (or rather,
* Cocoa native), then we should pass the event along to that window.
*/
if ((event_window = [nsevent window]) && !GDK_IS_MACOS_WINDOW (event_window))
return NULL;
/* If we can't find a GdkSurface to deliver the event to, then we
* should pass it along to the NSApp.
*/
if (!(surface = find_surface_for_ns_event (self, nsevent, &x, &y)))
return NULL;
@@ -1133,15 +1169,31 @@ _gdk_macos_display_translate (GdkMacosDisplay *self,
if (test_resize (nsevent, surface, x, y))
return NULL;
if ((event_type == NSEventTypeRightMouseDown ||
event_type == NSEventTypeOtherMouseDown ||
event_type == NSEventTypeLeftMouseDown))
if (event_type == NSEventTypeRightMouseDown ||
event_type == NSEventTypeOtherMouseDown ||
event_type == NSEventTypeLeftMouseDown)
{
if (![NSApp isActive])
[NSApp activateIgnoringOtherApps:YES];
if (![window isKeyWindow])
[window makeKeyWindow];
{
NSWindow *orig_window = [nsevent window];
/* To get NSApp to supress activating the window we might
* have clicked through the shadow of, we need to dispatch
* the event and handle it in GdkMacosView:mouseDown to call
* [NSApp preventWindowOrdering]. Calling it here will not
* do anything as the event is not registered.
*/
if (orig_window &&
GDK_IS_MACOS_WINDOW (orig_window) &&
[(GdkMacosWindow *)orig_window needsMouseDownQuirk])
[NSApp sendEvent:nsevent];
[window showAndMakeKey:YES];
_gdk_macos_display_clear_sorting (self);
}
}
switch ((int)event_type)
@@ -1174,7 +1226,11 @@ _gdk_macos_display_translate (GdkMacosDisplay *self,
GdkDevice *pointer = gdk_seat_get_pointer (seat);
GdkDeviceGrabInfo *grab = _gdk_display_get_last_device_grab (GDK_DISPLAY (self), pointer);
if (grab == NULL)
if ([(GdkMacosWindow *)window isInManualResizeOrMove])
{
ret = GDK_MACOS_EVENT_DROP;
}
else if (grab == NULL)
{
if (event_type == NSEventTypeMouseExited)
[[NSCursor arrowCursor] set];

View File

@@ -0,0 +1,155 @@
/*
* Copyright © 2022 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "config.h"
#include "gdkmacosdisplay-private.h"
#include "gdkmacosmonitor-private.h"
#include "gdkmacossurface-private.h"
#include "gdkmacostoplevelsurface-private.h"
#define WARP_OFFSET_X 15
#define WARP_OFFSET_Y 15
static void
_gdk_macos_display_position_toplevel_with_parent (GdkMacosDisplay *self,
GdkMacosSurface *surface,
GdkMacosSurface *parent,
int *x,
int *y)
{
GdkRectangle surface_rect;
GdkRectangle parent_rect;
GdkMonitor *monitor;
g_assert (GDK_IS_MACOS_DISPLAY (self));
g_assert (GDK_IS_MACOS_TOPLEVEL_SURFACE (surface));
g_assert (GDK_IS_MACOS_TOPLEVEL_SURFACE (parent));
monitor = _gdk_macos_surface_get_best_monitor (parent);
/* Try to center on top of the parent but also try to make the whole thing
* visible in case that lands us under the topbar/panel/etc.
*/
parent_rect.x = parent->root_x + parent->shadow_left;
parent_rect.y = parent->root_y + parent->shadow_top;
parent_rect.width = GDK_SURFACE (parent)->width - parent->shadow_left - parent->shadow_right;
parent_rect.height = GDK_SURFACE (parent)->height - parent->shadow_top - parent->shadow_bottom;
surface_rect.width = GDK_SURFACE (surface)->width - surface->shadow_left - surface->shadow_right;
surface_rect.height = GDK_SURFACE (surface)->height - surface->shadow_top - surface->shadow_bottom;
surface_rect.x = parent_rect.x + ((parent_rect.width - surface_rect.width) / 2);
surface_rect.y = parent_rect.y + ((parent_rect.height - surface_rect.height) / 2);
_gdk_macos_monitor_clamp (GDK_MACOS_MONITOR (monitor), &surface_rect);
*x = surface_rect.x - surface->shadow_left;
*y = surface_rect.y - surface->shadow_top;
}
static inline gboolean
has_surface_at_origin (const GList *surfaces,
int x,
int y)
{
for (const GList *iter = surfaces; iter; iter = iter->next)
{
GdkMacosSurface *surface = iter->data;
if (surface->root_x == x && surface->root_y == y)
return TRUE;
}
return FALSE;
}
static void
_gdk_macos_display_position_toplevel (GdkMacosDisplay *self,
GdkMacosSurface *surface,
int *x,
int *y)
{
cairo_rectangle_int_t surface_rect;
GdkRectangle workarea;
const GList *surfaces;
GdkMonitor *monitor;
CGPoint mouse;
g_assert (GDK_IS_MACOS_DISPLAY (self));
g_assert (GDK_IS_MACOS_TOPLEVEL_SURFACE (surface));
mouse = [NSEvent mouseLocation];
monitor = _gdk_macos_display_get_monitor_at_display_coords (self, mouse.x, mouse.y);
gdk_macos_monitor_get_workarea (monitor, &workarea);
/* First place at top-left of current monitor */
surface_rect.width = GDK_SURFACE (surface)->width - surface->shadow_left - surface->shadow_right;
surface_rect.height = GDK_SURFACE (surface)->height - surface->shadow_top - surface->shadow_bottom;
surface_rect.x = workarea.x + ((workarea.width - surface_rect.width) / 2);
surface_rect.y = workarea.y + ((workarea.height - surface_rect.height) / 2);
_gdk_macos_monitor_clamp (GDK_MACOS_MONITOR (surface->best_monitor), &surface_rect);
*x = surface_rect.x - surface->shadow_left;
*y = surface_rect.y - surface->shadow_top;
/* Try to see if there are any other surfaces at this origin and if so,
* adjust until we get something better.
*/
surfaces = _gdk_macos_display_get_surfaces (self);
while (has_surface_at_origin (surfaces, *x, *y))
{
*x += WARP_OFFSET_X;
*y += WARP_OFFSET_Y;
/* If we reached the bottom right, just bail and try the workspace origin */
if (*x + surface->shadow_left + WARP_OFFSET_X > workarea.x + workarea.width ||
*y + surface->shadow_top + WARP_OFFSET_Y > workarea.y + workarea.height)
{
*x = workarea.x - surface->shadow_left;
*y = workarea.y - surface->shadow_top;
return;
}
}
}
/*<private>
* _gdk_macos_display_position_surface:
*
* Tries to position a window on a screen without landing in edges
* and other weird areas the user can't use.
*/
void
_gdk_macos_display_position_surface (GdkMacosDisplay *self,
GdkMacosSurface *surface,
int *x,
int *y)
{
GdkSurface *transient_for;
g_return_if_fail (GDK_IS_MACOS_DISPLAY (self));
g_return_if_fail (GDK_IS_MACOS_TOPLEVEL_SURFACE (surface));
transient_for = GDK_SURFACE (surface)->transient_for;
if (transient_for != NULL)
_gdk_macos_display_position_toplevel_with_parent (self, surface, GDK_MACOS_SURFACE (transient_for), x, y);
else
_gdk_macos_display_position_toplevel (self, surface, x, y);
}

View File

@@ -156,53 +156,13 @@ gdk_macos_display_update_bounds (GdkMacosDisplay *self)
self->width = self->max_x - self->min_x;
self->height = self->max_y - self->min_y;
GDK_NOTE (MISC,
g_message ("Displays reconfigured to bounds %d,%d %dx%d",
self->min_x, self->min_y, self->width, self->height));
GDK_END_MACOS_ALLOC_POOL;
}
static void
gdk_macos_display_monitors_changed_cb (CFNotificationCenterRef center,
void *observer,
CFStringRef name,
const void *object,
CFDictionaryRef userInfo)
{
GdkMacosDisplay *self = observer;
g_assert (GDK_IS_MACOS_DISPLAY (self));
_gdk_macos_display_reload_monitors (self);
/* Now we need to update all our surface positions since they
* probably just changed origins. We ignore the popup surfaces
* since we can rely on the toplevel surfaces to handle that.
*/
for (const GList *iter = _gdk_macos_display_get_surfaces (self);
iter != NULL;
iter = iter->next)
{
GdkMacosSurface *surface = iter->data;
g_assert (GDK_IS_MACOS_SURFACE (surface));
if (GDK_IS_TOPLEVEL (surface))
_gdk_macos_surface_update_position (surface);
}
}
static void
gdk_macos_display_user_defaults_changed_cb (CFNotificationCenterRef center,
void *observer,
CFStringRef name,
const void *object,
CFDictionaryRef userInfo)
{
GdkMacosDisplay *self = observer;
g_assert (GDK_IS_MACOS_DISPLAY (self));
_gdk_macos_display_reload_settings (self);
}
void
_gdk_macos_display_reload_monitors (GdkMacosDisplay *self)
{
@@ -275,52 +235,6 @@ gdk_macos_display_load_seat (GdkMacosDisplay *self)
g_object_unref (seat);
}
static gboolean
gdk_macos_display_frame_cb (gpointer data)
{
GdkMacosDisplay *self = data;
GdkDisplayLinkSource *source;
gint64 presentation_time;
gint64 now;
GList *iter;
g_assert (GDK_IS_MACOS_DISPLAY (self));
source = (GdkDisplayLinkSource *)self->frame_source;
presentation_time = source->presentation_time;
now = g_source_get_time ((GSource *)source);
iter = self->awaiting_frames.head;
while (iter != NULL)
{
GdkMacosSurface *surface = iter->data;
g_assert (GDK_IS_MACOS_SURFACE (surface));
iter = iter->next;
_gdk_macos_display_remove_frame_callback (self, surface);
_gdk_macos_surface_thaw (surface,
source->presentation_time,
source->refresh_interval);
}
return G_SOURCE_CONTINUE;
}
static void
gdk_macos_display_load_display_link (GdkMacosDisplay *self)
{
self->frame_source = gdk_display_link_source_new ();
g_source_set_callback (self->frame_source,
gdk_macos_display_frame_cb,
self,
NULL);
g_source_attach (self->frame_source, NULL);
}
static const char *
gdk_macos_display_get_name (GdkDisplay *display)
{
@@ -396,11 +310,15 @@ gdk_macos_display_queue_events (GdkDisplay *display)
g_return_if_fail (GDK_IS_MACOS_DISPLAY (self));
if ((nsevent = _gdk_macos_event_source_get_pending ()))
while ((nsevent = _gdk_macos_event_source_get_pending ()))
{
GdkEvent *event = _gdk_macos_display_translate (self, nsevent);
if (event != NULL)
if (event == GDK_MACOS_EVENT_DROP)
{
[nsevent release];
}
else if (event != NULL)
{
push_nsevent (event, nsevent);
_gdk_windowing_got_event (GDK_DISPLAY (self),
@@ -424,7 +342,6 @@ _gdk_macos_display_surface_added (GdkMacosDisplay *self,
g_assert (GDK_IS_MACOS_SURFACE (surface));
g_assert (!queue_contains (&self->sorted_surfaces, &surface->sorted));
g_assert (!queue_contains (&self->main_surfaces, &surface->main));
g_assert (!queue_contains (&self->awaiting_frames, &surface->frame));
g_assert (surface->sorted.data == surface);
g_assert (surface->main.data == surface);
g_assert (surface->frame.data == surface);
@@ -451,9 +368,6 @@ _gdk_macos_display_surface_removed (GdkMacosDisplay *self,
if (queue_contains (&self->main_surfaces, &surface->main))
_gdk_macos_display_surface_resigned_main (self, surface);
if (queue_contains (&self->awaiting_frames, &surface->frame))
g_queue_unlink (&self->awaiting_frames, &surface->frame);
g_return_if_fail (self->keyboard_surface != surface);
}
@@ -476,6 +390,21 @@ _gdk_macos_display_surface_became_key (GdkMacosDisplay *self,
event = gdk_focus_event_new (GDK_SURFACE (surface), keyboard, TRUE);
_gdk_event_queue_append (GDK_DISPLAY (self), event);
/* For each parent surface, we want them to look like they
* are also still focused, so ensure they have that same
* state associated with them.
*/
if (GDK_IS_POPUP (surface))
{
for (GdkSurface *parent = GDK_SURFACE (surface)->parent;
parent != NULL;
parent = parent->parent)
{
if (GDK_IS_TOPLEVEL (parent))
gdk_synthesize_surface_state (parent, 0, GDK_TOPLEVEL_STATE_FOCUSED);
}
}
/* We just became the active window. Unlike X11, Mac OS X does
* not send us motion events while the window does not have focus
* ("is not key"). We send a dummy motion notify event now, so that
@@ -484,6 +413,38 @@ _gdk_macos_display_surface_became_key (GdkMacosDisplay *self,
gdk_surface_request_motion (GDK_SURFACE (surface));
}
static gboolean
select_key_in_idle_cb (gpointer data)
{
GdkMacosDisplay *self = data;
g_assert (GDK_IS_MACOS_DISPLAY (self));
self->select_key_in_idle = 0;
/* Don't steal focus from NSPanel, etc */
if (self->key_window_is_foregin)
return G_SOURCE_REMOVE;
if (self->keyboard_surface == NULL)
{
const GList *surfaces = _gdk_macos_display_get_surfaces (self);
for (const GList *iter = surfaces; iter; iter = iter->next)
{
GdkMacosSurface *surface = iter->data;
if (GDK_SURFACE_IS_MAPPED (GDK_SURFACE (surface)))
{
[surface->window showAndMakeKey:YES];
break;
}
}
}
return G_SOURCE_REMOVE;
}
void
_gdk_macos_display_surface_resigned_key (GdkMacosDisplay *self,
GdkMacosSurface *surface)
@@ -512,7 +473,25 @@ _gdk_macos_display_surface_resigned_key (GdkMacosDisplay *self,
_gdk_display_get_next_serial (GDK_DISPLAY (self)));
}
/* For each parent surface, we want them to look like they
* are also still focused, so ensure they have that same
* state associated with them.
*/
if (GDK_IS_POPUP (surface))
{
for (GdkSurface *parent = GDK_SURFACE (surface)->parent;
parent != NULL;
parent = parent->parent)
{
if (GDK_IS_TOPLEVEL (parent))
gdk_synthesize_surface_state (parent, GDK_TOPLEVEL_STATE_FOCUSED, 0);
}
}
_gdk_macos_display_clear_sorting (self);
if (self->select_key_in_idle == 0)
self->select_key_in_idle = g_idle_add (select_key_in_idle_cb, self);
}
/* Raises a transient window.
@@ -551,8 +530,6 @@ void
_gdk_macos_display_surface_resigned_main (GdkMacosDisplay *self,
GdkMacosSurface *surface)
{
GdkMacosSurface *new_surface = NULL;
g_return_if_fail (GDK_IS_MACOS_DISPLAY (self));
g_return_if_fail (GDK_IS_MACOS_SURFACE (surface));
@@ -560,40 +537,6 @@ _gdk_macos_display_surface_resigned_main (GdkMacosDisplay *self,
g_queue_unlink (&self->main_surfaces, &surface->main);
_gdk_macos_display_clear_sorting (self);
if (GDK_SURFACE (surface)->transient_for &&
gdk_surface_get_mapped (GDK_SURFACE (surface)->transient_for))
{
new_surface = GDK_MACOS_SURFACE (GDK_SURFACE (surface)->transient_for);
}
else
{
const GList *surfaces = _gdk_macos_display_get_surfaces (self);
for (const GList *iter = surfaces; iter; iter = iter->next)
{
GdkMacosSurface *item = iter->data;
g_assert (GDK_IS_MACOS_SURFACE (item));
if (item == surface)
continue;
if (GDK_SURFACE_IS_MAPPED (GDK_SURFACE (item)))
{
new_surface = item;
break;
}
}
}
if (new_surface != NULL)
{
NSWindow *nswindow = _gdk_macos_surface_get_native (new_surface);
[nswindow makeKeyAndOrderFront:nswindow];
}
_gdk_macos_display_clear_sorting (self);
}
static GdkSurface *
@@ -654,20 +597,12 @@ gdk_macos_display_finalize (GObject *object)
{
GdkMacosDisplay *self = (GdkMacosDisplay *)object;
CFNotificationCenterRemoveObserver (CFNotificationCenterGetDistributedCenter (),
self,
CFSTR ("NSApplicationDidChangeScreenParametersNotification"),
NULL);
CFNotificationCenterRemoveObserver (CFNotificationCenterGetDistributedCenter (),
self,
CFSTR ("NSUserDefaultsDidChangeNotification"),
NULL);
_gdk_macos_display_feedback_destroy (self);
g_clear_handle_id (&self->select_key_in_idle, g_source_remove);
g_clear_pointer (&self->active_drags, g_hash_table_unref);
g_clear_pointer (&self->active_drops, g_hash_table_unref);
g_clear_object (&GDK_DISPLAY (self)->clipboard);
g_clear_pointer (&self->frame_source, g_source_unref);
g_clear_object (&self->monitors);
g_clear_pointer (&self->name, g_free);
@@ -726,7 +661,8 @@ _gdk_macos_display_open (const char *display_name)
if (self != NULL)
return NULL;
GDK_NOTE (MISC, g_message ("opening display %s", display_name ? display_name : ""));
display_name = display_name ? display_name : "";
GDK_NOTE (MISC, g_message ("opening display %s", display_name));
/* Make the current process a foreground application, i.e. an app
* with a user interface, in case we're not running from a .app bundle
@@ -741,24 +677,10 @@ _gdk_macos_display_open (const char *display_name)
gdk_macos_display_load_seat (self);
gdk_macos_display_load_clipboard (self);
/* Load CVDisplayLink before monitors to access refresh rates */
gdk_macos_display_load_display_link (self);
_gdk_macos_display_reload_monitors (self);
CFNotificationCenterAddObserver (CFNotificationCenterGetLocalCenter (),
self,
gdk_macos_display_monitors_changed_cb,
CFSTR ("NSApplicationDidChangeScreenParametersNotification"),
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
CFNotificationCenterAddObserver (CFNotificationCenterGetDistributedCenter (),
self,
gdk_macos_display_user_defaults_changed_cb,
CFSTR ("NSUserDefaultsDidChangeNotification"),
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
/* Initialize feedback from display server */
_gdk_macos_display_feedback_init (self);
if (event_source == NULL)
{
@@ -770,6 +692,8 @@ _gdk_macos_display_open (const char *display_name)
gdk_display_emit_opened (GDK_DISPLAY (self));
[NSApp activateIgnoringOtherApps:YES];
return GDK_DISPLAY (self);
}
@@ -810,6 +734,7 @@ _gdk_macos_display_get_monitor_at_coords (GdkMacosDisplay *self,
int x,
int y)
{
GdkMacosMonitor *best_match = NULL;
guint n_monitors;
g_return_val_if_fail (GDK_IS_MACOS_DISPLAY (self), NULL);
@@ -819,12 +744,25 @@ _gdk_macos_display_get_monitor_at_coords (GdkMacosDisplay *self,
for (guint i = 0; i < n_monitors; i++)
{
GdkMacosMonitor *monitor = get_monitor (self, i);
const GdkRectangle *geom = &GDK_MONITOR (monitor)->geometry;
if (gdk_rectangle_contains_point (&GDK_MONITOR (monitor)->geometry, x, y))
return GDK_MONITOR (monitor);
if (x >= geom->x &&
y >= geom->y &&
x <= (geom->x + geom->width) &&
y <= (geom->y + geom->height))
{
if (x <= geom->x + geom->width && y < geom->y + geom->height)
return GDK_MONITOR (monitor);
/* Not an exact match as we're on a boundary, but there is
* a good chance another monitor doesn't exist there so we
* would want to still treat this as the best monitor.
*/
best_match = monitor;
}
}
return NULL;
return GDK_MONITOR (best_match);
}
GdkMonitor *
@@ -949,6 +887,14 @@ _gdk_macos_display_get_surface_at_coords (GdkMacosDisplay *self,
*surface_x = x - GDK_MACOS_SURFACE (surface)->root_x;
*surface_y = y - GDK_MACOS_SURFACE (surface)->root_y;
/* One last check to make sure that the x,y is within the input
* region of the window. Otherwise we might send the event to the
* wrong window because of window shadow.
*/
if (surface->input_region != NULL &&
!cairo_region_contains_point (surface->input_region, *surface_x, *surface_y))
continue;
return GDK_MACOS_SURFACE (surface);
}
}
@@ -978,38 +924,6 @@ _gdk_macos_display_get_surface_at_display_coords (GdkMacosDisplay *self,
return _gdk_macos_display_get_surface_at_coords (self, x_gdk, y_gdk, surface_x, surface_y);
}
void
_gdk_macos_display_add_frame_callback (GdkMacosDisplay *self,
GdkMacosSurface *surface)
{
g_return_if_fail (GDK_IS_MACOS_DISPLAY (self));
g_return_if_fail (GDK_IS_MACOS_SURFACE (surface));
if (!queue_contains (&self->awaiting_frames, &surface->frame))
{
g_queue_push_tail_link (&self->awaiting_frames, &surface->frame);
if (self->awaiting_frames.length == 1)
gdk_display_link_source_unpause ((GdkDisplayLinkSource *)self->frame_source);
}
}
void
_gdk_macos_display_remove_frame_callback (GdkMacosDisplay *self,
GdkMacosSurface *surface)
{
g_return_if_fail (GDK_IS_MACOS_DISPLAY (self));
g_return_if_fail (GDK_IS_MACOS_SURFACE (surface));
if (queue_contains (&self->awaiting_frames, &surface->frame))
{
g_queue_unlink (&self->awaiting_frames, &surface->frame);
if (self->awaiting_frames.length == 0)
gdk_display_link_source_pause ((GdkDisplayLinkSource *)self->frame_source);
}
}
NSWindow *
_gdk_macos_display_find_native_under_pointer (GdkMacosDisplay *self,
int *x,
@@ -1029,17 +943,6 @@ _gdk_macos_display_find_native_under_pointer (GdkMacosDisplay *self,
return NULL;
}
int
_gdk_macos_display_get_nominal_refresh_rate (GdkMacosDisplay *self)
{
g_return_val_if_fail (GDK_IS_MACOS_DISPLAY (self), 60 * 1000);
if (self->frame_source == NULL)
return 60 * 1000;
return ((GdkDisplayLinkSource *)self->frame_source)->refresh_rate;
}
void
_gdk_macos_display_clear_sorting (GdkMacosDisplay *self)
{
@@ -1061,11 +964,16 @@ _gdk_macos_display_get_surfaces (GdkMacosDisplay *self)
NSArray *array = [NSApp orderedWindows];
GQueue sorted = G_QUEUE_INIT;
self->key_window_is_foregin = FALSE;
for (id obj in array)
{
NSWindow *nswindow = (NSWindow *)obj;
GdkMacosSurface *surface;
if ([nswindow isKeyWindow])
self->key_window_is_foregin = !GDK_IS_MACOS_WINDOW (nswindow);
if (!GDK_IS_MACOS_WINDOW (nswindow))
continue;

View File

@@ -29,7 +29,7 @@
#include "gdkmacossurface.h"
#import <OpenGL/OpenGL.h>
#import <OpenGL/gl.h>
#import <OpenGL/gl3.h>
#import <AppKit/AppKit.h>
G_BEGIN_DECLS
@@ -39,16 +39,14 @@ struct _GdkMacosGLContext
GdkGLContext parent_instance;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
NSOpenGLContext *gl_context;
CGLContextObj cgl_context;
G_GNUC_END_IGNORE_DEPRECATIONS
NSWindow *dummy_window;
NSView *dummy_view;
GLuint texture;
GLuint target;
GLuint fbo;
cairo_region_t *damage;
guint is_attached : 1;
guint needs_resize : 1;
guint last_opaque : 1;
};
struct _GdkMacosGLContextClass
@@ -56,7 +54,6 @@ struct _GdkMacosGLContextClass
GdkGLContextClass parent_class;
};
G_END_DECLS
#endif /* __GDK_MACOS_GL_CONTEXT_PRIVATE_H__ */

View File

@@ -19,20 +19,139 @@
#include "config.h"
#include "gdkconfig.h"
#include <OpenGL/gl3.h>
#include <OpenGL/CGLIOSurface.h>
#include <QuartzCore/QuartzCore.h>
#include "gdkmacosbuffer-private.h"
#include "gdkmacosglcontext-private.h"
#include "gdkmacossurface-private.h"
#include "gdkmacostoplevelsurface-private.h"
#include "gdkintl.h"
#include <OpenGL/gl.h>
#import "GdkMacosGLView.h"
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
G_DEFINE_TYPE (GdkMacosGLContext, gdk_macos_gl_context, GDK_TYPE_GL_CONTEXT)
#define CHECK(error,cgl_error) _CHECK_CGL(error, G_STRLOC, cgl_error)
static inline gboolean
_CHECK_CGL (GError **error,
const char *location,
CGLError cgl_error)
{
if (cgl_error != kCGLNoError)
{
g_log ("Core OpenGL",
G_LOG_LEVEL_CRITICAL,
"%s: %s",
location, CGLErrorString (cgl_error));
g_set_error (error,
GDK_GL_ERROR,
GDK_GL_ERROR_NOT_AVAILABLE,
"%s",
CGLErrorString (cgl_error));
return FALSE;
}
return TRUE;
}
/* Apple's OpenGL implementation does not contain the extension to
* perform log handler callbacks when errors occur. Therefore, to aid in
* tracking down issues we have a CHECK_GL() macro that can wrap GL
* calls and check for an error afterwards.
*
* To make this easier, we use a statement expression, as this will
* always be using something GCC-compatible on macOS.
*/
#define CHECK_GL(error,func) _CHECK_GL(error, G_STRLOC, ({ func; glGetError(); }))
static inline gboolean
_CHECK_GL (GError **error,
const char *location,
GLenum gl_error)
{
const char *msg;
switch (gl_error)
{
case GL_INVALID_ENUM:
msg = "invalid enum";
break;
case GL_INVALID_VALUE:
msg = "invalid value";
break;
case GL_INVALID_OPERATION:
msg = "invalid operation";
break;
case GL_INVALID_FRAMEBUFFER_OPERATION:
msg = "invalid framebuffer operation";
break;
case GL_OUT_OF_MEMORY:
msg = "out of memory";
break;
default:
msg = "unknown error";
break;
}
if (gl_error != GL_NO_ERROR)
{
g_log ("OpenGL",
G_LOG_LEVEL_CRITICAL,
"%s: %s", location, msg);
if (error != NULL)
g_set_error (error,
GDK_GL_ERROR,
GDK_GL_ERROR_NOT_AVAILABLE,
"%s", msg);
return FALSE;
}
return TRUE;
}
static gboolean
check_framebuffer_status (GLenum target)
{
switch (glCheckFramebufferStatus (target))
{
case GL_FRAMEBUFFER_COMPLETE:
return TRUE;
case GL_FRAMEBUFFER_UNDEFINED:
g_critical ("Framebuffer is undefined");
return FALSE;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
g_critical ("Framebuffer has incomplete attachment");
return FALSE;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
g_critical ("Framebuffer has missing attachment");
return FALSE;
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
g_critical ("Framebuffer has incomplete draw buffer");
return FALSE;
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
g_critical ("Framebuffer has incomplete read buffer");
return FALSE;
case GL_FRAMEBUFFER_UNSUPPORTED:
g_critical ("Framebuffer is unsupported");
return FALSE;
case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
g_critical ("Framebuffer has incomplete multisample");
return FALSE;
default:
g_critical ("Framebuffer has unknown error");
return FALSE;
}
}
static const char *
get_renderer_name (GLint id)
{
@@ -72,97 +191,165 @@ get_renderer_name (GLint id)
}
}
static NSOpenGLContext *
get_ns_open_gl_context (GdkMacosGLContext *self,
GError **error)
static GLuint
create_texture (CGLContextObj cgl_context,
GLuint target,
IOSurfaceRef io_surface,
guint width,
guint height)
{
g_assert (GDK_IS_MACOS_GL_CONTEXT (self));
GLuint texture = 0;
if (self->gl_context == nil)
if (!CHECK_GL (NULL, glActiveTexture (GL_TEXTURE0)) ||
!CHECK_GL (NULL, glGenTextures (1, &texture)) ||
!CHECK_GL (NULL, glBindTexture (target, texture)) ||
!CHECK (NULL, CGLTexImageIOSurface2D (cgl_context,
target,
GL_RGBA,
width,
height,
GL_BGRA,
GL_UNSIGNED_INT_8_8_8_8_REV,
io_surface,
0)) ||
!CHECK_GL (NULL, glTexParameteri (target, GL_TEXTURE_BASE_LEVEL, 0)) ||
!CHECK_GL (NULL, glTexParameteri (target, GL_TEXTURE_MIN_FILTER, GL_NEAREST)) ||
!CHECK_GL (NULL, glTexParameteri (target, GL_TEXTURE_MAG_FILTER, GL_NEAREST)) ||
!CHECK_GL (NULL, glTexParameteri (target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)) ||
!CHECK_GL (NULL, glTexParameteri (target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE)) ||
!CHECK_GL (NULL, glTexParameteri (target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)) ||
!CHECK_GL (NULL, glBindTexture (target, 0)))
{
g_set_error_literal (error,
GDK_GL_ERROR,
GDK_GL_ERROR_NOT_AVAILABLE,
"Cannot access NSOpenGLContext for surface");
return NULL;
glDeleteTextures (1, &texture);
return 0;
}
return self->gl_context;
return texture;
}
static NSOpenGLPixelFormat *
static void
gdk_macos_gl_context_allocate (GdkMacosGLContext *self)
{
GdkSurface *surface;
GLint opaque;
g_assert (GDK_IS_MACOS_GL_CONTEXT (self));
g_assert (self->cgl_context != NULL);
g_assert (self->target != 0);
g_assert (self->texture != 0 || self->fbo == 0);
g_assert (self->fbo != 0 || self->texture == 0);
if (!(surface = gdk_draw_context_get_surface (GDK_DRAW_CONTEXT (self))))
return;
/* Alter to an opaque surface if necessary */
opaque = _gdk_macos_surface_is_opaque (GDK_MACOS_SURFACE (surface));
if (opaque != self->last_opaque)
{
self->last_opaque = !!opaque;
if (!CHECK (NULL, CGLSetParameter (self->cgl_context, kCGLCPSurfaceOpacity, &opaque)))
return;
}
if (self->texture == 0)
{
GdkMacosBuffer *buffer;
IOSurfaceRef io_surface;
guint width;
guint height;
GLuint texture = 0;
GLuint fbo = 0;
buffer = _gdk_macos_surface_get_buffer (GDK_MACOS_SURFACE (surface));
io_surface = _gdk_macos_buffer_get_native (buffer);
width = _gdk_macos_buffer_get_width (buffer);
height = _gdk_macos_buffer_get_height (buffer);
/* We might need to re-enforce our CGL context here to keep
* video playing correctly. Something, somewhere, might have
* changed the context without touching GdkGLContext.
*
* Without this, video_player often breaks in gtk-demo when using
* the GStreamer backend.
*/
CGLSetCurrentContext (self->cgl_context);
if (!(texture = create_texture (self->cgl_context, self->target, io_surface, width, height)) ||
!CHECK_GL (NULL, glGenFramebuffers (1, &fbo)) ||
!CHECK_GL (NULL, glBindFramebuffer (GL_FRAMEBUFFER, fbo)) ||
!CHECK_GL (NULL, glBindTexture (self->target, texture)) ||
!CHECK_GL (NULL, glFramebufferTexture2D (GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0,
self->target,
texture,
0)) ||
!check_framebuffer_status (GL_FRAMEBUFFER))
{
glDeleteFramebuffers (1, &fbo);
glDeleteTextures (1, &texture);
return;
}
glBindTexture (self->target, 0);
glBindFramebuffer (GL_FRAMEBUFFER, 0);
self->texture = texture;
self->fbo = fbo;
}
}
static void
gdk_macos_gl_context_release (GdkMacosGLContext *self)
{
g_assert (GDK_IS_MACOS_GL_CONTEXT (self));
g_assert (self->texture != 0 || self->fbo == 0);
g_assert (self->fbo != 0 || self->texture == 0);
glBindFramebuffer (GL_FRAMEBUFFER, 0);
glActiveTexture (GL_TEXTURE0);
glBindTexture (self->target, 0);
if (self->fbo != 0)
{
glDeleteFramebuffers (1, &self->fbo);
self->fbo = 0;
}
if (self->texture != 0)
{
glDeleteTextures (1, &self->texture);
self->texture = 0;
}
}
static CGLPixelFormatObj
create_pixel_format (int major,
int minor,
GError **error)
{
NSOpenGLPixelFormatAttribute attrs[] = {
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersionLegacy,
NSOpenGLPFAAccelerated,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFABackingStore,
NSOpenGLPFAColorSize, 24,
NSOpenGLPFAAlphaSize, 8,
CGLPixelFormatAttribute attrs[] = {
kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute)kCGLOGLPVersion_Legacy,
kCGLPFAAllowOfflineRenderers, /* allow sharing across GPUs */
kCGLPFADepthSize, 0,
kCGLPFAStencilSize, 0,
kCGLPFAColorSize, 24,
kCGLPFAAlphaSize, 8,
0
};
CGLPixelFormatObj format = NULL;
GLint n_format = 1;
if (major == 3 && minor == 2)
attrs[1] = NSOpenGLProfileVersion3_2Core;
attrs[1] = (CGLPixelFormatAttribute)kCGLOGLPVersion_GL3_Core;
else if (major == 4 && minor == 1)
attrs[1] = NSOpenGLProfileVersion4_1Core;
attrs[1] = (CGLPixelFormatAttribute)kCGLOGLPVersion_GL4_Core;
NSOpenGLPixelFormat *format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
if (format == NULL)
g_set_error (error,
GDK_GL_ERROR,
GDK_GL_ERROR_NOT_AVAILABLE,
"Failed to create pixel format");
if (!CHECK (error, CGLChoosePixelFormat (attrs, &format, &n_format)))
return NULL;
return g_steal_pointer (&format);
}
static NSView *
ensure_gl_view (GdkMacosGLContext *self)
{
GdkMacosSurface *surface;
NSWindow *nswindow;
NSView *nsview;
g_assert (GDK_IS_MACOS_GL_CONTEXT (self));
surface = GDK_MACOS_SURFACE (gdk_draw_context_get_surface (GDK_DRAW_CONTEXT (self)));
nsview = _gdk_macos_surface_get_view (surface);
nswindow = _gdk_macos_surface_get_native (surface);
if G_UNLIKELY (!GDK_IS_MACOS_GL_VIEW (nsview))
{
NSRect frame;
frame = [[nswindow contentView] bounds];
nsview = [[GdkMacosGLView alloc] initWithFrame:frame];
[nsview setWantsBestResolutionOpenGLSurface:YES];
[nsview setPostsFrameChangedNotifications: YES];
[nsview setNeedsDisplay:YES];
[nswindow setContentView:nsview];
[nswindow makeFirstResponder:nsview];
[nsview release];
if (self->dummy_view != NULL)
{
NSView *dummy_view = g_steal_pointer (&self->dummy_view);
[dummy_view release];
}
if (self->dummy_window != NULL)
{
NSWindow *dummy_window = g_steal_pointer (&self->dummy_window);
[dummy_window release];
}
}
return [nswindow contentView];
}
static GdkGLAPI
gdk_macos_gl_context_real_realize (GdkGLContext *context,
GError **error)
@@ -170,195 +357,128 @@ gdk_macos_gl_context_real_realize (GdkGLContext *context,
GdkMacosGLContext *self = (GdkMacosGLContext *)context;
GdkSurface *surface;
GdkDisplay *display;
NSOpenGLContext *shared_gl_context = nil;
NSOpenGLContext *gl_context;
NSOpenGLPixelFormat *pixelFormat;
CGLPixelFormatObj pixelFormat;
CGLContextObj shared_gl_context = nil;
CGLContextObj cgl_context;
CGLContextObj existing;
GdkGLContext *shared;
NSOpenGLContext *existing;
GLint sync_to_framerate = 1;
GLint validate = 0;
GLint renderer_id = 0;
GLint swapRect[4];
int major, minor;
g_assert (GDK_IS_MACOS_GL_CONTEXT (self));
if (self->gl_context != nil)
if (self->cgl_context != nil)
return GDK_GL_API_GL;
if (!gdk_gl_context_is_api_allowed (context, GDK_GL_API_GL, error))
return 0;
existing = [NSOpenGLContext currentContext];
existing = CGLGetCurrentContext ();
gdk_gl_context_get_required_version (context, &major, &minor);
surface = gdk_draw_context_get_surface (GDK_DRAW_CONTEXT (context));
display = gdk_gl_context_get_display (context);
shared = gdk_display_get_gl_context (display);
if (shared != NULL)
{
if (!(shared_gl_context = get_ns_open_gl_context (GDK_MACOS_GL_CONTEXT (shared), error)))
return 0;
if (!(shared_gl_context = GDK_MACOS_GL_CONTEXT (shared)->cgl_context))
{
g_set_error_literal (error,
GDK_GL_ERROR,
GDK_GL_ERROR_NOT_AVAILABLE,
"Cannot access shared CGLContextObj");
return 0;
}
}
GDK_DISPLAY_NOTE (display,
OPENGL,
g_message ("Creating NSOpenGLContext (version %d.%d)",
g_message ("Creating CGLContextObj (version %d.%d)",
major, minor));
if (!(pixelFormat = create_pixel_format (major, minor, error)))
return 0;
gl_context = [[NSOpenGLContext alloc] initWithFormat:pixelFormat
shareContext:shared_gl_context];
[pixelFormat release];
if (gl_context == nil)
if (!CHECK (error, CGLCreateContext (pixelFormat, shared_gl_context, &cgl_context)))
{
g_set_error_literal (error,
GDK_GL_ERROR,
GDK_GL_ERROR_NOT_AVAILABLE,
"Failed to create NSOpenGLContext");
CGLReleasePixelFormat (pixelFormat);
return 0;
}
cgl_context = [gl_context CGLContextObj];
CGLSetCurrentContext (cgl_context);
CGLReleasePixelFormat (pixelFormat);
swapRect[0] = 0;
swapRect[1] = 0;
swapRect[2] = surface ? surface->width : 0;
swapRect[3] = surface ? surface->height : 0;
CGLSetParameter (cgl_context, kCGLCPSwapRectangle, swapRect);
CGLSetParameter (cgl_context, kCGLCPSwapInterval, &sync_to_framerate);
CGLEnable (cgl_context, kCGLCESwapRectangle);
if (validate)
CGLEnable (cgl_context, kCGLCEStateValidation);
CHECK (NULL, CGLEnable (cgl_context, kCGLCEStateValidation));
self->dummy_window = [[NSWindow alloc] initWithContentRect:NSZeroRect
styleMask:0
backing:NSBackingStoreBuffered
defer:NO
screen:nil];
self->dummy_view = [[NSView alloc] initWithFrame:NSZeroRect];
[self->dummy_window setContentView:self->dummy_view];
[gl_context setView:self->dummy_view];
if (!CHECK (error, CGLSetParameter (cgl_context, kCGLCPSwapInterval, &sync_to_framerate)) ||
!CHECK (error, CGLGetParameter (cgl_context, kCGLCPCurrentRendererID, &renderer_id)))
{
CGLReleaseContext (cgl_context);
return 0;
}
GLint renderer_id = 0;
[gl_context getValues:&renderer_id forParameter:NSOpenGLContextParameterCurrentRendererID];
GDK_DISPLAY_NOTE (display,
OPENGL,
g_message ("Created NSOpenGLContext[%p] using %s",
gl_context,
get_renderer_name (renderer_id)));
surface = gdk_draw_context_get_surface (GDK_DRAW_CONTEXT (context));
self->gl_context = g_steal_pointer (&gl_context);
if (existing != NULL)
[existing makeCurrentContext];
return GDK_GL_API_GL;
}
static gboolean
opaque_region_covers_surface (GdkMacosGLContext *self)
{
GdkSurface *surface;
cairo_region_t *region;
g_assert (GDK_IS_MACOS_GL_CONTEXT (self));
surface = gdk_draw_context_get_surface (GDK_DRAW_CONTEXT (self));
region = GDK_MACOS_SURFACE (surface)->opaque_region;
if (region != NULL &&
cairo_region_num_rectangles (region) == 1)
if (surface != NULL)
{
cairo_rectangle_int_t extents;
cairo_region_get_extents (region, &extents);
if (extents.x == 0 &&
extents.y == 0 &&
extents.width == surface->width &&
extents.height == surface->height)
return TRUE;
/* Setup initial swap rectangle. We might not actually need this
* anymore though as we are rendering to an IOSurface and we have
* a scissor clip when rendering to it.
*/
swapRect[0] = 0;
swapRect[1] = 0;
swapRect[2] = surface->width;
swapRect[3] = surface->height;
CGLSetParameter (cgl_context, kCGLCPSwapRectangle, swapRect);
CGLEnable (cgl_context, kCGLCESwapRectangle);
}
return FALSE;
GDK_DISPLAY_NOTE (display,
OPENGL,
g_message ("Created CGLContextObj@%p using %s",
cgl_context,
get_renderer_name (renderer_id)));
self->cgl_context = g_steal_pointer (&cgl_context);
if (existing != NULL)
CGLSetCurrentContext (existing);
return GDK_GL_API_GL;
}
static void
gdk_macos_gl_context_begin_frame (GdkDrawContext *context,
gboolean prefers_high_depth,
cairo_region_t *painted)
cairo_region_t *region)
{
GdkMacosGLContext *self = (GdkMacosGLContext *)context;
GdkMacosBuffer *buffer;
cairo_region_t *copy;
GdkSurface *surface;
g_assert (GDK_IS_MACOS_GL_CONTEXT (self));
copy = cairo_region_copy (region);
surface = gdk_draw_context_get_surface (context);
buffer = _gdk_macos_surface_get_buffer (GDK_MACOS_SURFACE (surface));
g_clear_pointer (&self->damage, cairo_region_destroy);
self->damage = cairo_region_copy (painted);
_gdk_macos_buffer_set_flipped (buffer, TRUE);
_gdk_macos_buffer_set_damage (buffer, region);
/* If begin frame is called, that means we are trying to draw to
* the NSWindow using our view. That might be a GdkMacosCairoView
* but we need it to be a GL view. Also, only in this case do we
* want to replace our damage region for the next frame (to avoid
* doing it multiple times).
*/
ensure_gl_view (self);
/* Create our render target and bind it */
gdk_gl_context_make_current (GDK_GL_CONTEXT (self));
gdk_macos_gl_context_allocate (self);
if (self->needs_resize)
{
CGLContextObj cgl_context = [self->gl_context CGLContextObj];
GLint opaque;
GDK_DRAW_CONTEXT_CLASS (gdk_macos_gl_context_parent_class)->begin_frame (context, prefers_high_depth, region);
self->needs_resize = FALSE;
if (self->dummy_view != NULL)
{
NSRect frame = NSMakeRect (0, 0, surface->width, surface->height);
[self->dummy_window setFrame:frame display:NO];
[self->dummy_view setFrame:frame];
}
/* Possibly update our opaque setting depending on a resize. We can
* rely on getting a resize if decoarated is changed, so this reduces
* how much we adjust the parameter.
*/
if (GDK_IS_MACOS_TOPLEVEL_SURFACE (surface))
opaque = GDK_MACOS_TOPLEVEL_SURFACE (surface)->decorated;
else
opaque = FALSE;
/* If we are maximized, we might be able to make it opaque */
if (opaque == FALSE)
opaque = opaque_region_covers_surface (self);
CGLSetParameter (cgl_context, kCGLCPSurfaceOpacity, &opaque);
[self->gl_context update];
}
GDK_DRAW_CONTEXT_CLASS (gdk_macos_gl_context_parent_class)->begin_frame (context, prefers_high_depth, painted);
if (!self->is_attached)
{
NSView *nsview = _gdk_macos_surface_get_view (GDK_MACOS_SURFACE (surface));
g_assert (self->gl_context != NULL);
g_assert (GDK_IS_MACOS_GL_VIEW (nsview));
[(GdkMacosGLView *)nsview setOpenGLContext:self->gl_context];
}
gdk_gl_context_make_current (GDK_GL_CONTEXT (self));
CHECK_GL (NULL, glBindFramebuffer (GL_FRAMEBUFFER, self->fbo));
}
static void
@@ -366,32 +486,40 @@ gdk_macos_gl_context_end_frame (GdkDrawContext *context,
cairo_region_t *painted)
{
GdkMacosGLContext *self = GDK_MACOS_GL_CONTEXT (context);
GdkSurface *surface;
cairo_rectangle_int_t flush_rect;
GLint swapRect[4];
g_assert (GDK_IS_MACOS_GL_CONTEXT (self));
g_assert (self->gl_context != nil);
g_assert (self->cgl_context != nil);
GDK_DRAW_CONTEXT_CLASS (gdk_macos_gl_context_parent_class)->end_frame (context, painted);
if (!self->is_attached)
{
GdkSurface *surface = gdk_draw_context_get_surface (context);
CGLContextObj glctx = [self->gl_context CGLContextObj];
cairo_rectangle_int_t flush_rect;
GLint swapRect[4];
surface = gdk_draw_context_get_surface (context);
gdk_gl_context_make_current (GDK_GL_CONTEXT (self));
/* Coordinates are in display coordinates, where as flush_rect is
* in GDK coordinates. Must flip Y to match display coordinates where
* 0,0 is the bottom-left corner.
*/
cairo_region_get_extents (painted, &flush_rect);
swapRect[0] = flush_rect.x; /* left */
swapRect[1] = surface->height - flush_rect.y; /* bottom */
swapRect[2] = flush_rect.width; /* width */
swapRect[3] = flush_rect.height; /* height */
CGLSetParameter (glctx, kCGLCPSwapRectangle, swapRect);
/* Coordinates are in display coordinates, where as flush_rect is
* in GDK coordinates. Must flip Y to match display coordinates where
* 0,0 is the bottom-left corner.
*/
cairo_region_get_extents (painted, &flush_rect);
swapRect[0] = flush_rect.x; /* left */
swapRect[1] = surface->height - flush_rect.y; /* bottom */
swapRect[2] = flush_rect.width; /* width */
swapRect[3] = flush_rect.height; /* height */
CGLSetParameter (self->cgl_context, kCGLCPSwapRectangle, swapRect);
[self->gl_context flushBuffer];
}
gdk_macos_gl_context_release (self);
glFlush ();
/* Begin a Core Animation transaction so that all changes we
* make within the window are seen atomically.
*/
[CATransaction begin];
[CATransaction setDisableActions:YES];
_gdk_macos_surface_swap_buffers (GDK_MACOS_SURFACE (surface), painted);
[CATransaction commit];
}
static void
@@ -401,31 +529,21 @@ gdk_macos_gl_context_surface_resized (GdkDrawContext *draw_context)
g_assert (GDK_IS_MACOS_GL_CONTEXT (self));
self->needs_resize = TRUE;
g_clear_pointer (&self->damage, cairo_region_destroy);
if (self->cgl_context != NULL)
CGLUpdateContext (self->cgl_context);
}
static gboolean
gdk_macos_gl_context_clear_current (GdkGLContext *context)
{
GdkMacosGLContext *self = GDK_MACOS_GL_CONTEXT (context);
NSOpenGLContext *current;
g_return_val_if_fail (GDK_IS_MACOS_GL_CONTEXT (self), FALSE);
current = [NSOpenGLContext currentContext];
if (self->gl_context == current)
if (self->cgl_context == CGLGetCurrentContext ())
{
/* The OpenGL mac programming guide suggests that glFlush() is called
* before switching current contexts to ensure that the drawing commands
* are submitted.
*/
if (current != NULL)
glFlush ();
[NSOpenGLContext clearCurrentContext];
glFlush ();
CGLSetCurrentContext (NULL);
}
return TRUE;
@@ -436,22 +554,26 @@ gdk_macos_gl_context_make_current (GdkGLContext *context,
gboolean surfaceless)
{
GdkMacosGLContext *self = GDK_MACOS_GL_CONTEXT (context);
NSOpenGLContext *current;
CGLContextObj current;
g_return_val_if_fail (GDK_IS_MACOS_GL_CONTEXT (self), FALSE);
current = [NSOpenGLContext currentContext];
current = CGLGetCurrentContext ();
if (self->gl_context != current)
if (self->cgl_context != current)
{
/* The OpenGL mac programming guide suggests that glFlush() is called
* before switching current contexts to ensure that the drawing commands
* are submitted.
*
* TODO: investigate if we need this because we may switch contexts
* durring composition and only need it when returning to a
* previous context that uses the other context.
*/
if (current != NULL)
glFlush ();
[self->gl_context makeCurrentContext];
CGLSetCurrentContext (self->cgl_context);
}
return TRUE;
@@ -461,45 +583,45 @@ static cairo_region_t *
gdk_macos_gl_context_get_damage (GdkGLContext *context)
{
GdkMacosGLContext *self = (GdkMacosGLContext *)context;
const cairo_region_t *damage;
GdkMacosBuffer *buffer;
GdkSurface *surface;
g_assert (GDK_IS_MACOS_GL_CONTEXT (self));
if (self->damage != NULL)
return cairo_region_copy (self->damage);
if ((surface = gdk_draw_context_get_surface (GDK_DRAW_CONTEXT (context))) &&
(buffer = GDK_MACOS_SURFACE (surface)->front) &&
(damage = _gdk_macos_buffer_get_damage (buffer)))
return cairo_region_copy (damage);
return GDK_GL_CONTEXT_CLASS (gdk_macos_gl_context_parent_class)->get_damage (context);
}
static guint
gdk_macos_gl_context_get_default_framebuffer (GdkGLContext *context)
{
return GDK_MACOS_GL_CONTEXT (context)->fbo;
}
static void
gdk_macos_gl_context_dispose (GObject *gobject)
{
GdkMacosGLContext *self = GDK_MACOS_GL_CONTEXT (gobject);
if (self->dummy_view != nil)
self->texture = 0;
self->fbo = 0;
if (self->cgl_context != nil)
{
NSView *nsview = g_steal_pointer (&self->dummy_view);
[nsview release];
CGLContextObj cgl_context = g_steal_pointer (&self->cgl_context);
if (cgl_context == CGLGetCurrentContext ())
CGLSetCurrentContext (NULL);
CGLClearDrawable (cgl_context);
CGLDestroyContext (cgl_context);
}
if (self->dummy_window != nil)
{
NSWindow *nswindow = g_steal_pointer (&self->dummy_window);
[nswindow release];
}
if (self->gl_context != nil)
{
NSOpenGLContext *gl_context = g_steal_pointer (&self->gl_context);
if (gl_context == [NSOpenGLContext currentContext])
[NSOpenGLContext clearCurrentContext];
[gl_context clearDrawable];
[gl_context release];
}
g_clear_pointer (&self->damage, cairo_region_destroy);
G_OBJECT_CLASS (gdk_macos_gl_context_parent_class)->dispose (gobject);
}
@@ -520,6 +642,7 @@ gdk_macos_gl_context_class_init (GdkMacosGLContextClass *klass)
gl_class->clear_current = gdk_macos_gl_context_clear_current;
gl_class->make_current = gdk_macos_gl_context_make_current;
gl_class->realize = gdk_macos_gl_context_real_realize;
gl_class->get_default_framebuffer = gdk_macos_gl_context_get_default_framebuffer;
gl_class->backend_type = GDK_GL_CGL;
}
@@ -527,6 +650,7 @@ gdk_macos_gl_context_class_init (GdkMacosGLContextClass *klass)
static void
gdk_macos_gl_context_init (GdkMacosGLContext *self)
{
self->target = GL_TEXTURE_RECTANGLE;
}
G_GNUC_END_IGNORE_DEPRECATIONS

View File

@@ -24,15 +24,25 @@
#include "gdkmacosdisplay.h"
#include "gdkmacosmonitor.h"
#include "gdkmacossurface.h"
#include "gdkmonitorprivate.h"
G_BEGIN_DECLS
GdkMacosMonitor *_gdk_macos_monitor_new (GdkMacosDisplay *display,
CGDirectDisplayID screen_id);
CGDirectDisplayID _gdk_macos_monitor_get_screen_id (GdkMacosMonitor *self);
gboolean _gdk_macos_monitor_reconfigure (GdkMacosMonitor *self);
char *_gdk_macos_monitor_get_localized_name (NSScreen *screen);
char *_gdk_macos_monitor_get_connector_name (CGDirectDisplayID screen_id);
GdkMacosMonitor *_gdk_macos_monitor_new (GdkMacosDisplay *display,
CGDirectDisplayID screen_id);
CGDirectDisplayID _gdk_macos_monitor_get_screen_id (GdkMacosMonitor *self);
gboolean _gdk_macos_monitor_reconfigure (GdkMacosMonitor *self);
CGColorSpaceRef _gdk_macos_monitor_copy_colorspace (GdkMacosMonitor *self);
void _gdk_macos_monitor_add_frame_callback (GdkMacosMonitor *self,
GdkMacosSurface *surface);
void _gdk_macos_monitor_remove_frame_callback (GdkMacosMonitor *self,
GdkMacosSurface *surface);
void _gdk_macos_monitor_clamp (GdkMacosMonitor *self,
GdkRectangle *area);
G_END_DECLS

View File

@@ -22,16 +22,21 @@
#include <gdk/gdk.h>
#include <math.h>
#include "gdkdisplaylinksource.h"
#include "gdkmacosdisplay-private.h"
#include "gdkmacosmonitor-private.h"
#include "gdkmacossurface-private.h"
#include "gdkmacosutils-private.h"
struct _GdkMacosMonitor
{
GdkMonitor parent_instance;
CGDirectDisplayID screen_id;
NSRect workarea;
guint has_opengl : 1;
GdkMonitor parent_instance;
CGDirectDisplayID screen_id;
GdkDisplayLinkSource *display_link;
NSRect workarea;
GQueue awaiting_frames;
guint has_opengl : 1;
guint in_frame : 1;
};
struct _GdkMacosMonitorClass
@@ -56,13 +61,11 @@ void
gdk_macos_monitor_get_workarea (GdkMonitor *monitor,
GdkRectangle *geometry)
{
GDK_BEGIN_MACOS_ALLOC_POOL;
GdkMacosMonitor *self = (GdkMacosMonitor *)monitor;
int x, y;
g_assert (GDK_IS_MACOS_MONITOR (self));
g_assert (geometry != NULL);
g_return_if_fail (GDK_IS_MACOS_MONITOR (self));
g_return_if_fail (geometry != NULL);
x = self->workarea.origin.x;
y = self->workarea.origin.y + self->workarea.size.height;
@@ -75,13 +78,28 @@ gdk_macos_monitor_get_workarea (GdkMonitor *monitor,
geometry->y = y;
geometry->width = self->workarea.size.width;
geometry->height = self->workarea.size.height;
}
GDK_END_MACOS_ALLOC_POOL;
static void
gdk_macos_monitor_dispose (GObject *object)
{
GdkMacosMonitor *self = (GdkMacosMonitor *)object;
if (self->display_link)
{
g_source_destroy ((GSource *)self->display_link);
g_clear_pointer ((GSource **)&self->display_link, g_source_unref);
}
G_OBJECT_CLASS (gdk_macos_monitor_parent_class)->dispose (object);
}
static void
gdk_macos_monitor_class_init (GdkMacosMonitorClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = gdk_macos_monitor_dispose;
}
static void
@@ -142,8 +160,8 @@ GetSubpixelLayout (CGDirectDisplayID screen_id)
return GDK_SUBPIXEL_LAYOUT_UNKNOWN;
}
static char *
GetLocalizedName (NSScreen *screen)
char *
_gdk_macos_monitor_get_localized_name (NSScreen *screen)
{
#ifdef AVAILABLE_MAC_OS_X_VERSION_10_15_AND_LATER
GDK_BEGIN_MACOS_ALLOC_POOL;
@@ -164,8 +182,8 @@ GetLocalizedName (NSScreen *screen)
#endif
}
static char *
GetConnectorName (CGDirectDisplayID screen_id)
char *
_gdk_macos_monitor_get_connector_name (CGDirectDisplayID screen_id)
{
guint unit = CGDisplayUnitNumber (screen_id);
return g_strdup_printf ("unit-%u", unit);
@@ -192,6 +210,68 @@ find_screen (CGDirectDisplayID screen_id)
return screen;
}
static gboolean
gdk_macos_monitor_display_link_cb (GdkMacosMonitor *self)
{
gint64 presentation_time;
gint64 refresh_interval;
gint64 now;
GList *iter;
g_assert (GDK_IS_MACOS_MONITOR (self));
g_assert (!self->display_link->paused);
self->in_frame = TRUE;
presentation_time = self->display_link->presentation_time;
refresh_interval = self->display_link->refresh_interval;
now = g_source_get_time ((GSource *)self->display_link);
iter = self->awaiting_frames.head;
while (iter != NULL)
{
GdkMacosSurface *surface = iter->data;
g_assert (GDK_IS_MACOS_SURFACE (surface));
iter = iter->next;
g_queue_unlink (&self->awaiting_frames, &surface->frame);
_gdk_macos_surface_frame_presented (surface, presentation_time, refresh_interval);
}
if (self->awaiting_frames.length == 0 && !self->display_link->paused)
gdk_display_link_source_pause (self->display_link);
self->in_frame = FALSE;
return G_SOURCE_CONTINUE;
}
static void
_gdk_macos_monitor_reset_display_link (GdkMacosMonitor *self,
CGDisplayModeRef mode)
{
GSource *source;
g_assert (GDK_IS_MACOS_MONITOR (self));
if (self->display_link)
{
g_source_destroy ((GSource *)self->display_link);
g_clear_pointer ((GSource **)&self->display_link, g_source_unref);
}
source = gdk_display_link_source_new (self->screen_id, mode);
self->display_link = (GdkDisplayLinkSource *)source;
g_source_set_callback (source,
(GSourceFunc) gdk_macos_monitor_display_link_cb,
self,
NULL);
g_source_attach (source, NULL);
}
gboolean
_gdk_macos_monitor_reconfigure (GdkMacosMonitor *self)
{
@@ -226,8 +306,8 @@ _gdk_macos_monitor_reconfigure (GdkMacosMonitor *self)
pixel_width = CGDisplayModeGetPixelWidth (mode);
has_opengl = CGDisplayUsesOpenGLAcceleration (self->screen_id);
subpixel_layout = GetSubpixelLayout (self->screen_id);
name = GetLocalizedName (screen);
connector = GetConnectorName (self->screen_id);
name = _gdk_macos_monitor_get_localized_name (screen);
connector = _gdk_macos_monitor_get_connector_name (self->screen_id);
if (width != 0 && pixel_width != 0)
scale_factor = MAX (1, pixel_width / width);
@@ -245,7 +325,7 @@ _gdk_macos_monitor_reconfigure (GdkMacosMonitor *self)
* setting (which is also used by the frame clock).
*/
if (!(refresh_rate = CGDisplayModeGetRefreshRate (mode)))
refresh_rate = _gdk_macos_display_get_nominal_refresh_rate (display);
refresh_rate = 60 * 1000;
gdk_monitor_set_connector (GDK_MONITOR (self), connector);
gdk_monitor_set_model (GDK_MONITOR (self), name);
@@ -265,6 +345,9 @@ _gdk_macos_monitor_reconfigure (GdkMacosMonitor *self)
*/
self->has_opengl = !!has_opengl;
/* Create a new display link to receive feedback about when to render */
_gdk_macos_monitor_reset_display_link (self, mode);
CGDisplayModeRelease (mode);
g_free (name);
g_free (connector);
@@ -298,3 +381,79 @@ _gdk_macos_monitor_get_screen_id (GdkMacosMonitor *self)
return self->screen_id;
}
CGColorSpaceRef
_gdk_macos_monitor_copy_colorspace (GdkMacosMonitor *self)
{
g_return_val_if_fail (GDK_IS_MACOS_MONITOR (self), NULL);
return CGDisplayCopyColorSpace (self->screen_id);
}
void
_gdk_macos_monitor_add_frame_callback (GdkMacosMonitor *self,
GdkMacosSurface *surface)
{
g_return_if_fail (GDK_IS_MACOS_MONITOR (self));
g_return_if_fail (GDK_IS_MACOS_SURFACE (surface));
g_return_if_fail (surface->frame.data == (gpointer)surface);
g_return_if_fail (surface->frame.prev == NULL);
g_return_if_fail (surface->frame.next == NULL);
g_return_if_fail (self->awaiting_frames.head != &surface->frame);
g_return_if_fail (self->awaiting_frames.tail != &surface->frame);
/* Processing frames is always head to tail, so push to the
* head so that we don't possibly re-enter this right after
* adding to the queue.
*/
if (!queue_contains (&self->awaiting_frames, &surface->frame))
{
g_queue_push_head_link (&self->awaiting_frames, &surface->frame);
if (!self->in_frame && self->awaiting_frames.length == 1)
gdk_display_link_source_unpause (self->display_link);
}
}
void
_gdk_macos_monitor_remove_frame_callback (GdkMacosMonitor *self,
GdkMacosSurface *surface)
{
g_return_if_fail (GDK_IS_MACOS_MONITOR (self));
g_return_if_fail (GDK_IS_MACOS_SURFACE (surface));
g_return_if_fail (surface->frame.data == (gpointer)surface);
if (queue_contains (&self->awaiting_frames, &surface->frame))
{
g_queue_unlink (&self->awaiting_frames, &surface->frame);
if (!self->in_frame && self->awaiting_frames.length == 0)
gdk_display_link_source_pause (self->display_link);
}
}
void
_gdk_macos_monitor_clamp (GdkMacosMonitor *self,
GdkRectangle *area)
{
GdkRectangle workarea;
GdkRectangle geom;
g_return_if_fail (GDK_IS_MACOS_MONITOR (self));
g_return_if_fail (area != NULL);
gdk_macos_monitor_get_workarea (GDK_MONITOR (self), &workarea);
gdk_monitor_get_geometry (GDK_MONITOR (self), &geom);
if (area->x + area->width > workarea.x + workarea.width)
area->x = workarea.x + workarea.width - area->width;
if (area->x < workarea.x)
area->x = workarea.x;
if (area->y + area->height > workarea.y + workarea.height)
area->y = workarea.y + workarea.height - area->height;
if (area->y < workarea.y)
area->y = workarea.y;
}

View File

@@ -34,6 +34,7 @@ struct _GdkMacosPopupSurface
{
GdkMacosSurface parent_instance;
GdkPopupLayout *layout;
guint attached : 1;
};
struct _GdkMacosPopupSurfaceClass
@@ -87,6 +88,9 @@ gdk_macos_popup_surface_layout (GdkMacosPopupSurface *self,
gdk_surface_get_origin (GDK_SURFACE (self)->parent, &x, &y);
GDK_SURFACE (self)->x = final_rect.x;
GDK_SURFACE (self)->y = final_rect.y;
x += final_rect.x;
y += final_rect.y;
@@ -135,6 +139,9 @@ gdk_macos_popup_surface_present (GdkPopup *popup,
if (GDK_SURFACE_IS_MAPPED (GDK_SURFACE (self)))
return TRUE;
if (!self->attached && GDK_SURFACE (self)->parent != NULL)
_gdk_macos_popup_surface_attach_to_parent (self);
if (GDK_SURFACE (self)->autohide)
{
GdkDisplay *display = gdk_surface_get_display (GDK_SURFACE (popup));
@@ -200,10 +207,27 @@ enum {
LAST_PROP,
};
static void
_gdk_macos_popup_surface_hide (GdkSurface *surface)
{
GdkMacosPopupSurface *self = (GdkMacosPopupSurface *)surface;
g_assert (GDK_IS_MACOS_POPUP_SURFACE (self));
if (self->attached)
_gdk_macos_popup_surface_detach_from_parent (self);
GDK_SURFACE_CLASS (_gdk_macos_popup_surface_parent_class)->hide (surface);
}
static void
_gdk_macos_popup_surface_finalize (GObject *object)
{
GdkMacosPopupSurface *self = (GdkMacosPopupSurface *)object;
GdkSurface *parent = GDK_SURFACE (self)->parent;
if (parent != NULL)
parent->children = g_list_remove (parent->children, self);
g_clear_object (&GDK_SURFACE (self)->parent);
g_clear_pointer (&self->layout, gdk_popup_layout_unref);
@@ -263,12 +287,15 @@ static void
_gdk_macos_popup_surface_class_init (GdkMacosPopupSurfaceClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GdkSurfaceClass *surface_class = GDK_SURFACE_CLASS (klass);
object_class->finalize = _gdk_macos_popup_surface_finalize;
object_class->get_property = _gdk_macos_popup_surface_get_property;
object_class->set_property = _gdk_macos_popup_surface_set_property;
gdk_popup_install_properties (object_class, 1);
surface_class->hide = _gdk_macos_popup_surface_hide;
gdk_popup_install_properties (object_class, LAST_PROP);
}
static void
@@ -319,14 +346,8 @@ _gdk_macos_popup_surface_new (GdkMacosDisplay *display,
[window setOpaque:NO];
[window setBackgroundColor:[NSColor clearColor]];
[window setDecorated:NO];
#if 0
/* NOTE: We could set these to be popup level, but then
* [NSApp orderedWindows] would not give us the windows
* back with the stacking order applied.
*/
[window setExcludedFromWindowsMenu:YES];
[window setLevel:NSPopUpMenuWindowLevel];
#endif
self = g_object_new (GDK_TYPE_MACOS_POPUP_SURFACE,
"display", display,
@@ -357,6 +378,8 @@ _gdk_macos_popup_surface_attach_to_parent (GdkMacosPopupSurface *self)
[parent addChildWindow:window ordered:NSWindowAbove];
self->attached = TRUE;
_gdk_macos_display_clear_sorting (GDK_MACOS_DISPLAY (surface->display));
}
}
@@ -378,6 +401,8 @@ _gdk_macos_popup_surface_detach_from_parent (GdkMacosPopupSurface *self)
[parent removeChildWindow:window];
self->attached = FALSE;
_gdk_macos_display_clear_sorting (GDK_MACOS_DISPLAY (surface->display));
}
}
@@ -387,9 +412,7 @@ _gdk_macos_popup_surface_reposition (GdkMacosPopupSurface *self)
{
g_return_if_fail (GDK_IS_MACOS_POPUP_SURFACE (self));
if (self->layout == NULL ||
!gdk_surface_get_mapped (GDK_SURFACE (self)) ||
GDK_SURFACE (self)->parent == NULL)
if (self->layout == NULL || GDK_SURFACE (self)->parent == NULL)
return;
gdk_macos_popup_surface_layout (self,

View File

@@ -25,6 +25,7 @@
#include "gdksurfaceprivate.h"
#include "gdkmacosbuffer-private.h"
#include "gdkmacosdisplay.h"
#include "gdkmacossurface.h"
@@ -45,23 +46,38 @@ struct _GdkMacosSurface
GList frame;
GdkMacosWindow *window;
GdkMacosBuffer *buffer;
GdkMacosBuffer *front;
GPtrArray *monitors;
cairo_region_t *input_region;
cairo_region_t *opaque_region;
GdkMonitor *best_monitor;
char *title;
int root_x;
int root_y;
struct {
int root_x;
int root_y;
int width;
int height;
} next_layout;
int shadow_top;
int shadow_right;
int shadow_bottom;
int shadow_left;
cairo_rectangle_int_t next_frame;
gint64 pending_frame_counter;
guint did_initial_present : 1;
guint geometry_dirty : 1;
guint next_frame_set : 1;
guint show_on_next_swap : 1;
guint in_change_monitor : 1;
guint in_frame : 1;
guint awaiting_frame : 1;
};
struct _GdkMacosSurfaceClass
@@ -69,68 +85,70 @@ struct _GdkMacosSurfaceClass
GdkSurfaceClass parent_class;
};
GdkMacosSurface *_gdk_macos_surface_new (GdkMacosDisplay *display,
GdkSurfaceType surface_type,
GdkSurface *parent,
int x,
int y,
int width,
int height);
NSWindow *_gdk_macos_surface_get_native (GdkMacosSurface *self);
CGDirectDisplayID _gdk_macos_surface_get_screen_id (GdkMacosSurface *self);
const char *_gdk_macos_surface_get_title (GdkMacosSurface *self);
void _gdk_macos_surface_set_title (GdkMacosSurface *self,
const char *title);
void _gdk_macos_surface_get_shadow (GdkMacosSurface *self,
int *top,
int *right,
int *bottom,
int *left);
void _gdk_macos_surface_set_shadow (GdkMacosSurface *self,
int top,
int right,
int bottom,
int left);
NSView *_gdk_macos_surface_get_view (GdkMacosSurface *self);
gboolean _gdk_macos_surface_get_modal_hint (GdkMacosSurface *self);
void _gdk_macos_surface_set_modal_hint (GdkMacosSurface *self,
gboolean modal_hint);
void _gdk_macos_surface_set_geometry_hints (GdkMacosSurface *self,
const GdkGeometry *geometry,
GdkSurfaceHints geom_mask);
void _gdk_macos_surface_resize (GdkMacosSurface *self,
int width,
int height);
void _gdk_macos_surface_update_fullscreen_state (GdkMacosSurface *self);
void _gdk_macos_surface_update_position (GdkMacosSurface *self);
void _gdk_macos_surface_show (GdkMacosSurface *self);
void _gdk_macos_surface_thaw (GdkMacosSurface *self,
gint64 predicted_presentation_time,
gint64 refresh_interval);
CGContextRef _gdk_macos_surface_acquire_context (GdkMacosSurface *self,
gboolean clear_scale,
gboolean antialias);
void _gdk_macos_surface_release_context (GdkMacosSurface *self,
CGContextRef cg_context);
void _gdk_macos_surface_synthesize_null_key (GdkMacosSurface *self);
void _gdk_macos_surface_move (GdkMacosSurface *self,
int x,
int y);
void _gdk_macos_surface_move_resize (GdkMacosSurface *self,
int x,
int y,
int width,
int height);
gboolean _gdk_macos_surface_is_tracking (GdkMacosSurface *self,
NSTrackingArea *area);
void _gdk_macos_surface_monitor_changed (GdkMacosSurface *self);
GdkMonitor *_gdk_macos_surface_get_best_monitor (GdkMacosSurface *self);
void _gdk_macos_surface_reposition_children (GdkMacosSurface *self);
void _gdk_macos_surface_set_opacity (GdkMacosSurface *self,
double opacity);
void _gdk_macos_surface_get_root_coords (GdkMacosSurface *self,
int *x,
int *y);
GdkMacosSurface *_gdk_macos_surface_new (GdkMacosDisplay *display,
GdkSurfaceType surface_type,
GdkSurface *parent,
int x,
int y,
int width,
int height);
NSWindow *_gdk_macos_surface_get_native (GdkMacosSurface *self);
CGDirectDisplayID _gdk_macos_surface_get_screen_id (GdkMacosSurface *self);
const char *_gdk_macos_surface_get_title (GdkMacosSurface *self);
void _gdk_macos_surface_set_title (GdkMacosSurface *self,
const char *title);
void _gdk_macos_surface_get_shadow (GdkMacosSurface *self,
int *top,
int *right,
int *bottom,
int *left);
void _gdk_macos_surface_set_shadow (GdkMacosSurface *self,
int top,
int right,
int bottom,
int left);
gboolean _gdk_macos_surface_is_opaque (GdkMacosSurface *self);
NSView *_gdk_macos_surface_get_view (GdkMacosSurface *self);
gboolean _gdk_macos_surface_get_modal_hint (GdkMacosSurface *self);
void _gdk_macos_surface_set_modal_hint (GdkMacosSurface *self,
gboolean modal_hint);
void _gdk_macos_surface_set_geometry_hints (GdkMacosSurface *self,
const GdkGeometry *geometry,
GdkSurfaceHints geom_mask);
void _gdk_macos_surface_resize (GdkMacosSurface *self,
int width,
int height);
void _gdk_macos_surface_update_fullscreen_state (GdkMacosSurface *self);
void _gdk_macos_surface_request_frame (GdkMacosSurface *self);
void _gdk_macos_surface_frame_presented (GdkMacosSurface *self,
gint64 predicted_presentation_time,
gint64 refresh_interval);
void _gdk_macos_surface_show (GdkMacosSurface *self);
void _gdk_macos_surface_synthesize_null_key (GdkMacosSurface *self);
void _gdk_macos_surface_move (GdkMacosSurface *self,
int x,
int y);
void _gdk_macos_surface_move_resize (GdkMacosSurface *self,
int x,
int y,
int width,
int height);
void _gdk_macos_surface_configure (GdkMacosSurface *self);
void _gdk_macos_surface_user_resize (GdkMacosSurface *self,
CGRect new_frame);
gboolean _gdk_macos_surface_is_tracking (GdkMacosSurface *self,
NSTrackingArea *area);
void _gdk_macos_surface_monitor_changed (GdkMacosSurface *self);
GdkMonitor *_gdk_macos_surface_get_best_monitor (GdkMacosSurface *self);
void _gdk_macos_surface_reposition_children (GdkMacosSurface *self);
void _gdk_macos_surface_set_opacity (GdkMacosSurface *self,
double opacity);
void _gdk_macos_surface_get_root_coords (GdkMacosSurface *self,
int *x,
int *y);
GdkMacosBuffer *_gdk_macos_surface_get_buffer (GdkMacosSurface *self);
void _gdk_macos_surface_swap_buffers (GdkMacosSurface *self,
const cairo_region_t *damage);
G_END_DECLS

View File

@@ -23,10 +23,11 @@
#include <float.h>
#include <gdk/gdk.h>
#import "GdkMacosCairoView.h"
#import "GdkMacosView.h"
#include "gdkmacossurface-private.h"
#include "gdkdebug.h"
#include "gdkdeviceprivate.h"
#include "gdkdisplay.h"
#include "gdkeventsprivate.h"
@@ -64,14 +65,86 @@ window_is_fullscreen (GdkMacosSurface *self)
}
void
_gdk_macos_surface_reposition_children (GdkMacosSurface *self)
_gdk_macos_surface_request_frame (GdkMacosSurface *self)
{
g_assert (GDK_IS_MACOS_SURFACE (self));
if (self->awaiting_frame)
return;
if (self->best_monitor != NULL)
{
self->awaiting_frame = TRUE;
_gdk_macos_monitor_add_frame_callback (GDK_MACOS_MONITOR (self->best_monitor), self);
gdk_surface_freeze_updates (GDK_SURFACE (self));
}
}
static void
_gdk_macos_surface_cancel_frame (GdkMacosSurface *self)
{
g_assert (GDK_IS_MACOS_SURFACE (self));
if (!self->awaiting_frame)
return;
if (self->best_monitor != NULL)
{
self->awaiting_frame = FALSE;
_gdk_macos_monitor_remove_frame_callback (GDK_MACOS_MONITOR (self->best_monitor), self);
gdk_surface_thaw_updates (GDK_SURFACE (self));
}
}
void
_gdk_macos_surface_frame_presented (GdkMacosSurface *self,
gint64 presentation_time,
gint64 refresh_interval)
{
GdkFrameTimings *timings;
GdkFrameClock *frame_clock;
g_return_if_fail (GDK_IS_MACOS_SURFACE (self));
self->awaiting_frame = FALSE;
if (GDK_SURFACE_DESTROYED (self))
return;
if (!gdk_surface_get_mapped (GDK_SURFACE (self)))
frame_clock = gdk_surface_get_frame_clock (GDK_SURFACE (self));
if (self->pending_frame_counter)
{
timings = gdk_frame_clock_get_timings (frame_clock, self->pending_frame_counter);
if (timings != NULL)
{
timings->presentation_time = presentation_time - refresh_interval;
timings->complete = TRUE;
}
self->pending_frame_counter = 0;
}
timings = gdk_frame_clock_get_current_timings (frame_clock);
if (timings != NULL)
{
timings->refresh_interval = refresh_interval;
timings->predicted_presentation_time = presentation_time;
}
if (GDK_SURFACE_IS_MAPPED (GDK_SURFACE (self)))
gdk_surface_thaw_updates (GDK_SURFACE (self));
}
void
_gdk_macos_surface_reposition_children (GdkMacosSurface *self)
{
g_assert (GDK_IS_MACOS_SURFACE (self));
if (GDK_SURFACE_DESTROYED (self))
return;
for (const GList *iter = GDK_SURFACE (self)->children;
@@ -85,15 +158,23 @@ _gdk_macos_surface_reposition_children (GdkMacosSurface *self)
if (GDK_IS_MACOS_POPUP_SURFACE (child))
_gdk_macos_popup_surface_reposition (GDK_MACOS_POPUP_SURFACE (child));
}
if (GDK_IS_POPUP (self) && self->did_initial_present)
gdk_surface_request_layout (GDK_SURFACE (self));
}
static void
gdk_macos_surface_set_input_region (GdkSurface *surface,
cairo_region_t *region)
{
GdkMacosSurface *self = (GdkMacosSurface *)surface;
cairo_rectangle_int_t rect;
g_assert (GDK_IS_MACOS_SURFACE (self));
if (self->window == NULL)
return;
cairo_region_get_extents (region, &rect);
[(GdkMacosBaseView *)[self->window contentView] setInputArea:&rect];
}
static void
@@ -105,15 +186,8 @@ gdk_macos_surface_set_opaque_region (GdkSurface *surface,
g_assert (GDK_IS_MACOS_SURFACE (self));
if (region != self->opaque_region)
{
g_clear_pointer (&self->opaque_region, cairo_region_destroy);
self->opaque_region = cairo_region_copy (region);
}
if ((nsview = _gdk_macos_surface_get_view (GDK_MACOS_SURFACE (surface))) &&
GDK_IS_MACOS_CAIRO_VIEW (nsview))
[(GdkMacosCairoView *)nsview setOpaqueRegion:region];
if ((nsview = _gdk_macos_surface_get_view (GDK_MACOS_SURFACE (surface))))
[(GdkMacosView *)nsview setOpaqueRegion:region];
}
static void
@@ -122,10 +196,16 @@ gdk_macos_surface_hide (GdkSurface *surface)
GdkMacosSurface *self = (GdkMacosSurface *)surface;
GdkSeat *seat;
gboolean was_mapped;
gboolean was_key;
g_assert (GDK_IS_MACOS_SURFACE (self));
was_mapped = GDK_SURFACE_IS_MAPPED (GDK_SURFACE (self));
self->show_on_next_swap = FALSE;
_gdk_macos_surface_cancel_frame (self);
was_mapped = GDK_SURFACE_IS_MAPPED (surface);
was_key = [self->window isKeyWindow];
seat = gdk_display_get_default_seat (surface->display);
gdk_seat_ungrab (seat);
@@ -134,8 +214,26 @@ gdk_macos_surface_hide (GdkSurface *surface)
_gdk_surface_clear_update_area (surface);
if (was_mapped)
gdk_surface_freeze_updates (GDK_SURFACE (self));
g_clear_object (&self->buffer);
g_clear_object (&self->front);
if (was_key)
{
GdkSurface *parent;
if (GDK_IS_TOPLEVEL (surface))
parent = surface->transient_for;
else
parent = surface->parent;
/* Return key input to the parent window if necessary */
if (parent != NULL && GDK_SURFACE_IS_MAPPED (parent))
{
GdkMacosWindow *parentWindow = GDK_MACOS_SURFACE (parent)->window;
[parentWindow showAndMakeKey:YES];
}
}
}
static int
@@ -179,6 +277,7 @@ gdk_macos_surface_begin_frame (GdkMacosSurface *self)
{
g_assert (GDK_IS_MACOS_SURFACE (self));
self->in_frame = TRUE;
}
static void
@@ -190,15 +289,18 @@ gdk_macos_surface_end_frame (GdkMacosSurface *self)
g_assert (GDK_IS_MACOS_SURFACE (self));
if (GDK_SURFACE_DESTROYED (self))
return;
display = gdk_surface_get_display (GDK_SURFACE (self));
frame_clock = gdk_surface_get_frame_clock (GDK_SURFACE (self));
if ((timings = gdk_frame_clock_get_current_timings (frame_clock)))
self->pending_frame_counter = timings->frame_counter;
_gdk_macos_display_add_frame_callback (GDK_MACOS_DISPLAY (display), self);
self->in_frame = FALSE;
gdk_surface_freeze_updates (GDK_SURFACE (self));
_gdk_macos_surface_request_frame (self);
}
static void
@@ -210,10 +312,11 @@ gdk_macos_surface_before_paint (GdkMacosSurface *self,
g_assert (GDK_IS_MACOS_SURFACE (self));
g_assert (GDK_IS_FRAME_CLOCK (frame_clock));
if (surface->update_freeze_count > 0)
if (GDK_SURFACE_DESTROYED (self))
return;
gdk_macos_surface_begin_frame (self);
if (surface->update_freeze_count == 0)
gdk_macos_surface_begin_frame (self);
}
static void
@@ -225,10 +328,11 @@ gdk_macos_surface_after_paint (GdkMacosSurface *self,
g_assert (GDK_IS_MACOS_SURFACE (self));
g_assert (GDK_IS_FRAME_CLOCK (frame_clock));
if (surface->update_freeze_count > 0)
if (GDK_SURFACE_DESTROYED (self))
return;
gdk_macos_surface_end_frame (self);
if (surface->update_freeze_count == 0)
gdk_macos_surface_end_frame (self);
}
static void
@@ -370,18 +474,20 @@ gdk_macos_surface_destroy (GdkSurface *surface,
GdkMacosWindow *window = g_steal_pointer (&self->window);
GdkFrameClock *frame_clock;
_gdk_macos_surface_cancel_frame (self);
g_clear_object (&self->best_monitor);
if ((frame_clock = gdk_surface_get_frame_clock (GDK_SURFACE (self))))
{
g_signal_handlers_disconnect_by_func (frame_clock,
G_CALLBACK (gdk_macos_surface_before_paint),
self);
g_signal_handlers_disconnect_by_func (frame_clock,
G_CALLBACK (gdk_macos_surface_before_paint),
G_CALLBACK (gdk_macos_surface_after_paint),
self);
}
g_clear_pointer (&self->title, g_free);
g_clear_pointer (&self->opaque_region, cairo_region_destroy);
if (window != NULL)
[window close];
@@ -390,6 +496,9 @@ gdk_macos_surface_destroy (GdkSurface *surface,
g_clear_pointer (&self->monitors, g_ptr_array_unref);
g_clear_object (&self->buffer);
g_clear_object (&self->front);
g_assert (self->sorted.prev == NULL);
g_assert (self->sorted.next == NULL);
g_assert (self->frame.prev == NULL);
@@ -410,15 +519,6 @@ gdk_macos_surface_constructed (GObject *object)
G_OBJECT_CLASS (gdk_macos_surface_parent_class)->constructed (object);
if (self->window != NULL)
{
NSRect bounds = [[self->window contentView] bounds];
GDK_SURFACE (self)->width = bounds.size.width;
GDK_SURFACE (self)->height = bounds.size.height;
_gdk_macos_surface_update_position (self);
}
if ((frame_clock = gdk_surface_get_frame_clock (GDK_SURFACE (self))))
{
g_signal_connect_object (frame_clock,
@@ -432,6 +532,9 @@ gdk_macos_surface_constructed (GObject *object)
self,
G_CONNECT_SWAPPED);
}
if (self->window != NULL)
_gdk_macos_surface_configure (self);
}
static void
@@ -493,6 +596,11 @@ gdk_macos_surface_class_init (GdkMacosSurfaceClass *klass)
surface_class->set_input_region = gdk_macos_surface_set_input_region;
surface_class->set_opaque_region = gdk_macos_surface_set_opaque_region;
/**
* GdkMacosSurface:native: (attributes org.gtk.Property.get=gdk_macos_surface_get_native_window)
*
* The "native" property contains the underlying NSWindow.
*/
properties [PROP_NATIVE] =
g_param_spec_pointer ("native",
"Native",
@@ -526,7 +634,7 @@ _gdk_macos_surface_new (GdkMacosDisplay *display,
g_return_val_if_fail (GDK_IS_MACOS_DISPLAY (display), NULL);
if (parent != NULL)
frame_clock = g_object_ref (gdk_surface_get_frame_clock (parent));
frame_clock = g_object_ref (parent->frame_clock);
else
frame_clock = _gdk_frame_clock_idle_new ();
@@ -583,6 +691,29 @@ _gdk_macos_surface_get_shadow (GdkMacosSurface *self,
*right = self->shadow_right;
}
gboolean
_gdk_macos_surface_is_opaque (GdkMacosSurface *self)
{
GdkSurface *surface = (GdkSurface *)self;
g_return_val_if_fail (GDK_IS_MACOS_SURFACE (self), FALSE);
if (surface->opaque_region != NULL &&
cairo_region_num_rectangles (surface->opaque_region) == 1)
{
cairo_rectangle_int_t extents;
cairo_region_get_extents (surface->opaque_region, &extents);
return (extents.x == 0 &&
extents.y == 0 &&
extents.width == GDK_SURFACE (self)->width &&
extents.height == GDK_SURFACE (self)->height);
}
return FALSE;
}
const char *
_gdk_macos_surface_get_title (GdkMacosSurface *self)
{
@@ -632,6 +763,27 @@ _gdk_macos_surface_get_native (GdkMacosSurface *self)
return (NSWindow *)self->window;
}
/**
* gdk_macos_surface_get_native_window: (attributes org.gtk.Method.get_property=native)
* @self: a #GdkMacosSurface
*
* Gets the underlying NSWindow used by the surface.
*
* The NSWindow's contentView is an implementation detail and may change
* between releases of GTK.
*
* Returns: (nullable): a #NSWindow or %NULL
*
* Since: 4.8
*/
gpointer
gdk_macos_surface_get_native_window (GdkMacosSurface *self)
{
g_return_val_if_fail (GDK_IS_MACOS_SURFACE (self), NULL);
return _gdk_macos_surface_get_native (self);
}
void
_gdk_macos_surface_set_geometry_hints (GdkMacosSurface *self,
const GdkGeometry *geometry,
@@ -690,64 +842,60 @@ _gdk_macos_surface_update_fullscreen_state (GdkMacosSurface *self)
}
void
_gdk_macos_surface_update_position (GdkMacosSurface *self)
_gdk_macos_surface_configure (GdkMacosSurface *self)
{
GdkSurface *surface = GDK_SURFACE (self);
GdkDisplay *display = gdk_surface_get_display (surface);
NSRect frame_rect = [self->window frame];
NSRect content_rect = [self->window contentRectForFrameRect:frame_rect];
GdkSurface *surface = (GdkSurface *)self;
GdkMacosDisplay *display;
GdkMacosSurface *parent;
NSRect frame_rect;
NSRect content_rect;
g_return_if_fail (GDK_IS_MACOS_SURFACE (self));
if (GDK_SURFACE_DESTROYED (self))
return;
if (surface->parent != NULL)
parent = GDK_MACOS_SURFACE (surface->parent);
else if (surface->transient_for != NULL)
parent = GDK_MACOS_SURFACE (surface->transient_for);
else
parent = NULL;
display = GDK_MACOS_DISPLAY (GDK_SURFACE (self)->display);
frame_rect = [self->window frame];
content_rect = [self->window contentRectForFrameRect:frame_rect];
_gdk_macos_display_from_display_coords (GDK_MACOS_DISPLAY (display),
content_rect.origin.x,
content_rect.origin.y + content_rect.size.height,
&self->root_x, &self->root_y);
if (surface->parent != NULL)
if (parent != NULL)
{
surface->x = self->root_x - GDK_MACOS_SURFACE (surface->parent)->root_x;
surface->y = self->root_y - GDK_MACOS_SURFACE (surface->parent)->root_y;
surface->x = self->root_x - parent->root_x;
surface->y = self->root_y - parent->root_y;
}
else
{
surface->x = self->root_x;
surface->y = self->root_y;
}
}
void
_gdk_macos_surface_thaw (GdkMacosSurface *self,
gint64 presentation_time,
gint64 refresh_interval)
{
GdkFrameTimings *timings;
GdkFrameClock *frame_clock;
g_return_if_fail (GDK_IS_MACOS_SURFACE (self));
gdk_surface_thaw_updates (GDK_SURFACE (self));
frame_clock = gdk_surface_get_frame_clock (GDK_SURFACE (self));
if (self->pending_frame_counter)
if (surface->width != content_rect.size.width ||
surface->height != content_rect.size.height)
{
timings = gdk_frame_clock_get_timings (frame_clock, self->pending_frame_counter);
surface->width = content_rect.size.width;
surface->height = content_rect.size.height;
if (timings != NULL)
{
timings->presentation_time = presentation_time - refresh_interval;
timings->complete = TRUE;
}
g_clear_object (&self->buffer);
g_clear_object (&self->front);
self->pending_frame_counter = 0;
_gdk_surface_update_size (surface);
gdk_surface_invalidate_rect (surface, NULL);
}
timings = gdk_frame_clock_get_current_timings (frame_clock);
if (timings != NULL)
{
timings->refresh_interval = refresh_interval;
timings->predicted_presentation_time = presentation_time;
}
_gdk_macos_surface_reposition_children (self);
}
void
@@ -760,69 +908,18 @@ _gdk_macos_surface_show (GdkMacosSurface *self)
if (GDK_SURFACE_DESTROYED (self))
return;
_gdk_macos_display_clear_sorting (GDK_MACOS_DISPLAY (GDK_SURFACE (self)->display));
self->show_on_next_swap = TRUE;
was_mapped = GDK_SURFACE_IS_MAPPED (GDK_SURFACE (self));
if (!was_mapped)
gdk_surface_set_is_mapped (GDK_SURFACE (self), TRUE);
_gdk_macos_display_clear_sorting (GDK_MACOS_DISPLAY (GDK_SURFACE (self)->display));
[self->window showAndMakeKey:YES];
if (!was_mapped)
{
if (gdk_surface_get_mapped (GDK_SURFACE (self)))
{
_gdk_macos_surface_update_position (self);
gdk_surface_invalidate_rect (GDK_SURFACE (self), NULL);
gdk_surface_thaw_updates (GDK_SURFACE (self));
}
gdk_surface_set_is_mapped (GDK_SURFACE (self), TRUE);
gdk_surface_request_layout (GDK_SURFACE (self));
gdk_surface_invalidate_rect (GDK_SURFACE (self), NULL);
gdk_surface_thaw_updates (GDK_SURFACE (self));
}
[[self->window contentView] setNeedsDisplay:YES];
}
CGContextRef
_gdk_macos_surface_acquire_context (GdkMacosSurface *self,
gboolean clear_scale,
gboolean antialias)
{
CGContextRef cg_context;
g_return_val_if_fail (GDK_IS_MACOS_SURFACE (self), NULL);
if (GDK_SURFACE_DESTROYED (self))
return NULL;
if (!(cg_context = [[NSGraphicsContext currentContext] CGContext]))
return NULL;
CGContextSaveGState (cg_context);
if (!antialias)
CGContextSetAllowsAntialiasing (cg_context, antialias);
if (clear_scale)
{
CGSize scale;
scale = CGSizeMake (1.0, 1.0);
scale = CGContextConvertSizeToDeviceSpace (cg_context, scale);
CGContextScaleCTM (cg_context, 1.0 / fabs (scale.width), 1.0 / fabs (scale.height));
}
return cg_context;
}
void
_gdk_macos_surface_release_context (GdkMacosSurface *self,
CGContextRef cg_context)
{
g_return_if_fail (GDK_IS_MACOS_SURFACE (self));
CGContextRestoreGState (cg_context);
CGContextSetAllowsAntialiasing (cg_context, TRUE);
}
void
@@ -874,52 +971,89 @@ _gdk_macos_surface_move_resize (GdkMacosSurface *self,
GdkDisplay *display;
NSRect content_rect;
NSRect frame_rect;
gboolean size_changed;
gboolean ignore_move;
gboolean ignore_size;
GdkRectangle current;
g_return_if_fail (GDK_IS_MACOS_SURFACE (self));
if ((x == -1 || (x == self->root_x)) &&
(y == -1 || (y == self->root_y)) &&
(width == -1 || (width == surface->width)) &&
(height == -1 || (height == surface->height)))
/* Query for up-to-date values in case we're racing against
* an incoming frame notify which could be queued behind whatever
* we're processing right now.
*/
frame_rect = [self->window frame];
content_rect = [self->window contentRectForFrameRect:frame_rect];
_gdk_macos_display_from_display_coords (GDK_MACOS_DISPLAY (GDK_SURFACE (self)->display),
content_rect.origin.x, content_rect.origin.y,
&current.x, &current.y);
current.width = content_rect.size.width;
current.height = content_rect.size.height;
/* Check if we can ignore the operation all together */
ignore_move = (x == -1 || (x == current.x)) &&
(y == -1 || (y == current.y));
ignore_size = (width == -1 || (width == current.width)) &&
(height == -1 || (height == current.height));
if (ignore_move && ignore_size)
return;
display = gdk_surface_get_display (surface);
if (width == -1)
width = surface->width;
width = current.width;
if (height == -1)
height = surface->height;
height = current.height;
if (x == -1)
x = self->root_x;
x = current.x;
if (y == -1)
y = self->root_y;
size_changed = height != surface->height || width != surface->width;
if (GDK_IS_MACOS_SURFACE (surface->parent))
{
surface->x = x - GDK_MACOS_SURFACE (surface->parent)->root_x;
surface->y = y - GDK_MACOS_SURFACE (surface->parent)->root_y;
}
else
{
surface->x = x;
surface->y = y;
}
y = current.y;
_gdk_macos_display_to_display_coords (GDK_MACOS_DISPLAY (display),
x, y + height, &x, &y);
x, y + height,
&x, &y);
if (!ignore_move)
content_rect.origin = NSMakePoint (x, y);
if (!ignore_size)
content_rect.size = NSMakeSize (width, height);
content_rect = NSMakeRect (x, y, width, height);
frame_rect = [self->window frameRectForContentRect:content_rect];
[self->window setFrame:frame_rect display:YES];
[self->window setFrame:frame_rect display:NO];
}
if (size_changed)
gdk_surface_invalidate_rect (surface, NULL);
void
_gdk_macos_surface_user_resize (GdkMacosSurface *self,
CGRect new_frame)
{
GdkMacosDisplay *display;
CGRect content_rect;
int root_x, root_y;
g_return_if_fail (GDK_IS_MACOS_SURFACE (self));
g_return_if_fail (GDK_IS_TOPLEVEL (self));
if (GDK_SURFACE_DESTROYED (self))
return;
display = GDK_MACOS_DISPLAY (GDK_SURFACE (self)->display);
content_rect = [self->window contentRectForFrameRect:new_frame];
_gdk_macos_display_from_display_coords (display,
new_frame.origin.x,
new_frame.origin.y + new_frame.size.height,
&root_x, &root_y);
self->next_layout.root_x = root_x;
self->next_layout.root_y = root_y;
self->next_layout.width = content_rect.size.width;
self->next_layout.height = content_rect.size.height;
gdk_surface_request_layout (GDK_SURFACE (self));
}
gboolean
@@ -944,14 +1078,24 @@ void
_gdk_macos_surface_monitor_changed (GdkMacosSurface *self)
{
GListModel *monitors;
GdkMonitor *best = NULL;
GdkRectangle rect;
GdkRectangle intersect;
GdkDisplay *display;
GdkMonitor *monitor;
guint n_monitors;
int best_area = 0;
g_return_if_fail (GDK_IS_MACOS_SURFACE (self));
if (self->in_change_monitor)
return;
self->in_change_monitor = TRUE;
_gdk_macos_surface_cancel_frame (self);
_gdk_macos_surface_configure (self);
rect.x = self->root_x;
rect.y = self->root_y;
rect.width = GDK_SURFACE (self)->width;
@@ -986,26 +1130,15 @@ _gdk_macos_surface_monitor_changed (GdkMacosSurface *self)
g_object_unref (monitor);
}
}
GdkMonitor *
_gdk_macos_surface_get_best_monitor (GdkMacosSurface *self)
{
GdkMonitor *best = NULL;
GdkRectangle rect;
int best_area = 0;
g_return_val_if_fail (GDK_IS_MACOS_SURFACE (self), NULL);
rect.x = self->root_x;
rect.y = self->root_y;
rect.width = GDK_SURFACE (self)->width;
rect.height = GDK_SURFACE (self)->height;
/* We need to create a new IOSurface for this monitor */
g_clear_object (&self->buffer);
g_clear_object (&self->front);
/* Determine the best-fit monitor */
for (guint i = 0; i < self->monitors->len; i++)
{
GdkMonitor *monitor = g_ptr_array_index (self->monitors, i);
GdkRectangle intersect;
monitor = g_ptr_array_index (self->monitors, i);
if (gdk_rectangle_intersect (&monitor->geometry, &rect, &intersect))
{
@@ -1013,13 +1146,62 @@ _gdk_macos_surface_get_best_monitor (GdkMacosSurface *self)
if (area > best_area)
{
best = monitor;
best_area = area;
best = monitor;
}
}
}
return best;
if (g_set_object (&self->best_monitor, best))
{
GDK_NOTE (MISC,
g_message ("Surface \"%s\" moved to monitor \"%s\"",
self->title ? self->title : "unknown",
gdk_monitor_get_connector (best)));
_gdk_macos_surface_configure (self);
if (GDK_SURFACE_IS_MAPPED (GDK_SURFACE (self)))
{
_gdk_macos_surface_request_frame (self);
gdk_surface_request_layout (GDK_SURFACE (self));
}
for (const GList *iter = GDK_SURFACE (self)->children;
iter != NULL;
iter = iter->next)
{
GdkMacosSurface *child = iter->data;
GdkRectangle area;
g_set_object (&child->best_monitor, best);
area.x = self->root_x + GDK_SURFACE (child)->x + child->shadow_left;
area.y = self->root_y + GDK_SURFACE (child)->y + child->shadow_top;
area.width = GDK_SURFACE (child)->width - child->shadow_left - child->shadow_right;
area.height = GDK_SURFACE (child)->height - child->shadow_top - child->shadow_bottom;
_gdk_macos_monitor_clamp (GDK_MACOS_MONITOR (best), &area);
area.x -= child->shadow_left;
area.y -= child->shadow_top;
_gdk_macos_surface_move (child, area.x, area.y);
gdk_surface_invalidate_rect (GDK_SURFACE (child), NULL);
}
}
gdk_surface_invalidate_rect (GDK_SURFACE (self), NULL);
self->in_change_monitor = FALSE;
}
GdkMonitor *
_gdk_macos_surface_get_best_monitor (GdkMacosSurface *self)
{
g_return_val_if_fail (GDK_IS_MACOS_SURFACE (self), NULL);
return self->best_monitor;
}
NSView *
@@ -1066,3 +1248,70 @@ _gdk_macos_surface_get_root_coords (GdkMacosSurface *self,
if (y)
*y = out_y;
}
GdkMacosBuffer *
_gdk_macos_surface_get_buffer (GdkMacosSurface *self)
{
g_return_val_if_fail (GDK_IS_MACOS_SURFACE (self), NULL);
if (GDK_SURFACE_DESTROYED (self))
return NULL;
if (self->buffer == NULL)
{
/* Create replacement buffer. We always use 4-byte and 32-bit BGRA for
* our surface as that can work with both Cairo and GL. The GdkMacosTile
* handles opaque regions for the compositor, so using 3-byte/24-bit is
* not a necessary optimization.
*/
double scale = gdk_surface_get_scale_factor (GDK_SURFACE (self));
guint width = GDK_SURFACE (self)->width * scale;
guint height = GDK_SURFACE (self)->height * scale;
self->buffer = _gdk_macos_buffer_new (width, height, scale, 4, 32);
}
return self->buffer;
}
static void
_gdk_macos_surface_do_delayed_show (GdkMacosSurface *self)
{
GdkSurface *surface = (GdkSurface *)self;
g_assert (GDK_IS_MACOS_SURFACE (self));
self->show_on_next_swap = FALSE;
[self->window showAndMakeKey:YES];
_gdk_macos_display_clear_sorting (GDK_MACOS_DISPLAY (surface->display));
gdk_surface_request_motion (surface);
}
void
_gdk_macos_surface_swap_buffers (GdkMacosSurface *self,
const cairo_region_t *damage)
{
GdkMacosBuffer *swap;
g_return_if_fail (GDK_IS_MACOS_SURFACE (self));
g_return_if_fail (damage != NULL);
swap = self->buffer;
self->buffer = self->front;
self->front = swap;
/* This code looks like it swaps buffers, but since the IOSurfaceRef
* appears to be retained on the other side, we really just ask all
* of the GdkMacosTile CALayer's to update their contents.
*/
[self->window swapBuffer:swap withDamage:damage];
/* We might have delayed actually showing the window until the buffer
* contents are ready to be displayed. Doing so ensures that we don't
* get a point where we might have invalid buffer contents before we
* have content to display to the user.
*/
if G_UNLIKELY (self->show_on_next_swap)
_gdk_macos_surface_do_delayed_show (self);
}

View File

@@ -36,7 +36,9 @@ typedef struct _GdkMacosSurfaceClass GdkMacosSurfaceClass;
#define GDK_IS_MACOS_SURFACE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_MACOS_SURFACE))
GDK_AVAILABLE_IN_ALL
GType gdk_macos_surface_get_type (void);
GType gdk_macos_surface_get_type (void);
GDK_AVAILABLE_IN_4_8
gpointer gdk_macos_surface_get_native_window (GdkMacosSurface *self);
G_END_DECLS

View File

@@ -35,6 +35,8 @@ struct _GdkMacosToplevelSurface
{
GdkMacosSurface parent_instance;
GdkToplevelLayout *layout;
int last_computed_width;
int last_computed_height;
guint decorated : 1;
};

View File

@@ -174,6 +174,14 @@ _gdk_macos_toplevel_surface_present (GdkToplevel *toplevel,
_gdk_macos_surface_set_geometry_hints (GDK_MACOS_SURFACE (self), &geometry, mask);
gdk_surface_constrain_size (&geometry, mask, width, height, &width, &height);
GDK_NOTE (MISC,
g_message ("Resizing \"%s\" to %dx%d",
GDK_MACOS_SURFACE (self)->title ?
GDK_MACOS_SURFACE (self)->title :
"untitled",
width, height));
_gdk_macos_surface_resize (GDK_MACOS_SURFACE (self), width, height);
/* Maximized state */
@@ -194,43 +202,22 @@ _gdk_macos_toplevel_surface_present (GdkToplevel *toplevel,
_gdk_macos_toplevel_surface_unfullscreen (self);
}
if (GDK_SURFACE (self)->transient_for != NULL)
if (!GDK_MACOS_SURFACE (self)->did_initial_present)
{
}
else
{
[nswindow setAnimationBehavior:NSWindowAnimationBehaviorDocumentWindow];
int x = 0, y = 0;
if (!self->decorated &&
!GDK_MACOS_SURFACE (self)->did_initial_present &&
GDK_SURFACE (self)->x == 0 &&
GDK_SURFACE (self)->y == 0 &&
(GDK_MACOS_SURFACE (self)->shadow_left ||
GDK_MACOS_SURFACE (self)->shadow_top))
{
int x = GDK_SURFACE (self)->x;
int y = GDK_SURFACE (self)->y;
_gdk_macos_display_position_surface (GDK_MACOS_DISPLAY (display),
GDK_MACOS_SURFACE (self),
&x, &y);
monitor = _gdk_macos_surface_get_best_monitor (GDK_MACOS_SURFACE (self));
GDK_NOTE (MISC,
g_message ("Placing new toplevel \"%s\" at %d,%d",
GDK_MACOS_SURFACE (self)->title ?
GDK_MACOS_SURFACE (self)->title :
"untitled",
x, y));
if (monitor != NULL)
{
GdkRectangle visible;
gdk_macos_monitor_get_workarea (monitor, &visible);
if (x < visible.x)
x = visible.x;
if (y < visible.y)
y = visible.y;
}
x -= GDK_MACOS_SURFACE (self)->shadow_left;
y -= GDK_MACOS_SURFACE (self)->shadow_top;
_gdk_macos_surface_move (GDK_MACOS_SURFACE (self), x, y);
}
_gdk_macos_surface_move (GDK_MACOS_SURFACE (self), x, y);
}
_gdk_macos_surface_show (GDK_MACOS_SURFACE (self));
@@ -381,11 +368,11 @@ static gboolean
_gdk_macos_toplevel_surface_compute_size (GdkSurface *surface)
{
GdkMacosToplevelSurface *self = (GdkMacosToplevelSurface *)surface;
GdkMacosSurface *macos_surface = (GdkMacosSurface *)surface;
GdkToplevelSize size;
GdkDisplay *display;
GdkMonitor *monitor;
int bounds_width, bounds_height;
int width, height;
GdkGeometry geometry;
GdkSurfaceHints mask;
@@ -419,9 +406,6 @@ _gdk_macos_toplevel_surface_compute_size (GdkSurface *surface)
g_warn_if_fail (size.width > 0);
g_warn_if_fail (size.height > 0);
width = surface->width;
height = surface->height;
if (self->layout != NULL &&
gdk_toplevel_layout_get_resizable (self->layout))
{
@@ -437,16 +421,64 @@ _gdk_macos_toplevel_surface_compute_size (GdkSurface *surface)
}
if (size.shadow.is_valid)
_gdk_macos_surface_set_shadow (GDK_MACOS_SURFACE (surface),
_gdk_macos_surface_set_shadow (macos_surface,
size.shadow.top,
size.shadow.right,
size.shadow.bottom,
size.shadow.left);
gdk_surface_constrain_size (&geometry, mask, width, height, &width, &height);
_gdk_macos_surface_set_geometry_hints (macos_surface, &geometry, mask);
_gdk_macos_surface_set_geometry_hints (GDK_MACOS_SURFACE (self), &geometry, mask);
_gdk_macos_surface_resize (GDK_MACOS_SURFACE (self), width, height);
if (surface->state & (GDK_TOPLEVEL_STATE_FULLSCREEN |
GDK_TOPLEVEL_STATE_MAXIMIZED |
GDK_TOPLEVEL_STATE_TILED |
GDK_TOPLEVEL_STATE_TOP_TILED |
GDK_TOPLEVEL_STATE_RIGHT_TILED |
GDK_TOPLEVEL_STATE_BOTTOM_TILED |
GDK_TOPLEVEL_STATE_LEFT_TILED |
GDK_TOPLEVEL_STATE_MINIMIZED) ||
[macos_surface->window inLiveResize])
return FALSE;
/* If we delayed a user resize until the beginning of the frame,
* apply it now so we can start processing updates for it.
*/
if (macos_surface->next_layout.width > 0 &&
macos_surface->next_layout.height > 0)
{
int root_x = macos_surface->next_layout.root_x;
int root_y = macos_surface->next_layout.root_y;
int width = macos_surface->next_layout.width;
int height = macos_surface->next_layout.height;
gdk_surface_constrain_size (&geometry, mask,
width, height,
&width, &height);
macos_surface->next_layout.width = 0;
macos_surface->next_layout.height = 0;
_gdk_macos_surface_move_resize (macos_surface,
root_x, root_y,
width, height);
return FALSE;
}
gdk_surface_constrain_size (&geometry, mask,
size.width, size.height,
&size.width, &size.height);
if ((size.width != self->last_computed_width ||
size.height != self->last_computed_height) &&
(size.width != surface->width ||
size.height != surface->height))
{
self->last_computed_width = size.width;
self->last_computed_height = size.height;
_gdk_macos_surface_resize (macos_surface, size.width, size.height);
}
return FALSE;
}
@@ -616,10 +648,10 @@ _gdk_macos_toplevel_surface_new (GdkMacosDisplay *display,
GdkMacosWindow *window;
GdkMacosSurface *self;
NSScreen *screen;
NSUInteger style_mask;
NSRect content_rect;
NSRect screen_rect;
NSRect visible_frame;
NSScreen *screen;
int nx;
int ny;
@@ -632,20 +664,26 @@ _gdk_macos_toplevel_surface_new (GdkMacosDisplay *display,
NSWindowStyleMaskMiniaturizable |
NSWindowStyleMaskResizable);
_gdk_macos_display_to_display_coords (display, x, y, &nx, &ny);
if (parent != NULL)
{
x += GDK_MACOS_SURFACE (parent)->root_x;
y += GDK_MACOS_SURFACE (parent)->root_y;
}
_gdk_macos_display_to_display_coords (display, x, y + height, &nx, &ny);
screen = _gdk_macos_display_get_screen_at_display_coords (display, nx, ny);
screen_rect = [screen visibleFrame];
nx -= screen_rect.origin.x;
ny -= screen_rect.origin.y;
content_rect = NSMakeRect (nx, ny - height, width, height);
visible_frame = [screen visibleFrame];
content_rect = NSMakeRect (nx - visible_frame.origin.x, ny - visible_frame.origin.y, width, height);
window = [[GdkMacosWindow alloc] initWithContentRect:content_rect
styleMask:style_mask
backing:NSBackingStoreBuffered
defer:NO
screen:screen];
/* Allow NSWindow to go fullscreen */
[window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
self = g_object_new (GDK_TYPE_MACOS_TOPLEVEL_SURFACE,
"display", display,
"frame-clock", frame_clock,
@@ -672,13 +710,21 @@ _gdk_macos_toplevel_surface_attach_to_parent (GdkMacosToplevelSurface *self)
{
NSWindow *parent = _gdk_macos_surface_get_native (GDK_MACOS_SURFACE (surface->transient_for));
NSWindow *window = _gdk_macos_surface_get_native (GDK_MACOS_SURFACE (self));
int x, y;
[parent addChildWindow:window ordered:NSWindowAbove];
if (GDK_SURFACE (self)->modal_hint)
[window setLevel:NSModalPanelWindowLevel];
surface->x = 0;
surface->y = 0;
_gdk_macos_display_clear_sorting (GDK_MACOS_DISPLAY (surface->display));
_gdk_macos_display_position_surface (GDK_MACOS_DISPLAY (surface->display),
GDK_MACOS_SURFACE (surface),
&x, &y);
_gdk_macos_surface_move (GDK_MACOS_SURFACE (surface), x, y);
}
}

View File

@@ -2,13 +2,16 @@ gdk_macos_sources = files([
'edgesnapping.c',
'gdkdisplaylinksource.c',
'gdkmacosbuffer.c',
'gdkmacoscairocontext.c',
'gdkmacosclipboard.c',
'gdkmacoscursor.c',
'gdkmacosdevice.c',
'gdkmacosdisplay.c',
'gdkmacosdisplay-feedback.c',
'gdkmacosdisplay-settings.c',
'gdkmacosdisplay-translate.c',
'gdkmacosdisplay-wm.c',
'gdkmacosdrag.c',
'gdkmacosdrop.c',
'gdkmacosdragsurface.c',
@@ -20,11 +23,10 @@ gdk_macos_sources = files([
'gdkmacosseat.c',
'gdkmacossurface.c',
'gdkmacostoplevelsurface.c',
'GdkMacosBaseView.c',
'GdkMacosCairoView.c',
'GdkMacosCairoSubview.c',
'GdkMacosGLView.c',
'GdkMacosLayer.c',
'GdkMacosTile.c',
'GdkMacosView.c',
'GdkMacosWindow.c',
])
@@ -46,6 +48,7 @@ gdk_macos_frameworks = [
'CoreVideo',
'CoreServices',
'Foundation',
'IOSurface',
'OpenGL',
'QuartzCore',
]

View File

@@ -73,8 +73,9 @@ gdk_wayland_app_launch_context_get_startup_notify_id (GAppLaunchContext *context
xdg_activation_token_v1_set_serial (token,
_gdk_wayland_seat_get_last_implicit_grab_serial (seat, NULL),
gdk_wayland_seat_get_wl_seat (GDK_SEAT (seat)));
xdg_activation_token_v1_set_surface (token,
gdk_wayland_surface_get_wl_surface (focus_surface));
if (focus_surface)
xdg_activation_token_v1_set_surface (token,
gdk_wayland_surface_get_wl_surface (focus_surface));
xdg_activation_token_v1_commit (token);
while (app_launch_data.token == NULL)

View File

@@ -181,8 +181,8 @@ gdk_wayland_cairo_context_end_frame (GdkDrawContext *draw_context,
GdkWaylandCairoContext *self = GDK_WAYLAND_CAIRO_CONTEXT (draw_context);
GdkSurface *surface = gdk_draw_context_get_surface (draw_context);
gdk_wayland_surface_attach_image (surface, self->paint_surface, painted);
gdk_wayland_surface_sync (surface);
gdk_wayland_surface_attach_image (surface, self->paint_surface, painted);
gdk_wayland_surface_request_frame (surface);
gdk_profiler_add_mark (GDK_PROFILER_CURRENT_TIME, 0, "wayland", "surface commit");

View File

@@ -227,6 +227,7 @@ struct _GdkWaylandSeat
struct wl_touch *wl_touch;
struct zwp_pointer_gesture_swipe_v1 *wp_pointer_gesture_swipe;
struct zwp_pointer_gesture_pinch_v1 *wp_pointer_gesture_pinch;
struct zwp_pointer_gesture_hold_v1 *wp_pointer_gesture_hold;
struct zwp_tablet_seat_v2 *wp_tablet_seat;
GdkDisplay *display;
@@ -2856,6 +2857,81 @@ gesture_pinch_end (void *data,
0, 0, 1, 0);
}
static void
emit_gesture_hold_event (GdkWaylandSeat *seat,
GdkTouchpadGesturePhase phase,
guint32 _time,
guint32 n_fingers)
{
GdkEvent *event;
if (!seat->pointer_info.focus)
return;
seat->pointer_info.time = _time;
event = gdk_touchpad_event_new_hold (seat->pointer_info.focus,
seat->logical_pointer,
_time,
device_get_modifiers (seat->logical_pointer),
phase,
seat->pointer_info.surface_x,
seat->pointer_info.surface_y,
n_fingers);
if (GDK_DISPLAY_DEBUG_CHECK (gdk_seat_get_display (GDK_SEAT (seat)), EVENTS))
{
double x, y;
gdk_event_get_position (event, &x, &y);
g_message ("hold event %d, coords: %f %f, seat %p state %d",
gdk_event_get_event_type (event),
x, y, seat,
gdk_event_get_modifier_state (event));
}
_gdk_wayland_display_deliver_event (seat->display, event);
}
static void
gesture_hold_begin (void *data,
struct zwp_pointer_gesture_hold_v1 *hold,
uint32_t serial,
uint32_t time,
struct wl_surface *surface,
uint32_t fingers)
{
GdkWaylandSeat *seat = data;
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (seat->display);
_gdk_wayland_display_update_serial (display, serial);
emit_gesture_hold_event (seat,
GDK_TOUCHPAD_GESTURE_PHASE_BEGIN,
time, fingers);
seat->gesture_n_fingers = fingers;
}
static void
gesture_hold_end (void *data,
struct zwp_pointer_gesture_hold_v1 *hold,
uint32_t serial,
uint32_t time,
int32_t cancelled)
{
GdkWaylandSeat *seat = data;
GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (seat->display);
GdkTouchpadGesturePhase phase;
_gdk_wayland_display_update_serial (display, serial);
phase = (cancelled) ?
GDK_TOUCHPAD_GESTURE_PHASE_CANCEL :
GDK_TOUCHPAD_GESTURE_PHASE_END;
emit_gesture_hold_event (seat, phase, time,
seat->gesture_n_fingers);
}
static void
_gdk_wayland_seat_remove_tool (GdkWaylandSeat *seat,
GdkWaylandTabletToolData *tool)
@@ -3065,6 +3141,11 @@ static const struct zwp_pointer_gesture_pinch_v1_listener gesture_pinch_listener
gesture_pinch_end
};
static const struct zwp_pointer_gesture_hold_v1_listener gesture_hold_listener = {
gesture_hold_begin,
gesture_hold_end
};
static const struct zwp_tablet_v2_listener tablet_listener = {
tablet_handle_name,
tablet_handle_id,
@@ -3120,6 +3201,17 @@ seat_handle_capabilities (void *data,
seat);
zwp_pointer_gesture_pinch_v1_add_listener (seat->wp_pointer_gesture_pinch,
&gesture_pinch_listener, seat);
if (display_wayland->pointer_gestures_version >= ZWP_POINTER_GESTURES_V1_GET_HOLD_GESTURE_SINCE_VERSION)
{
seat->wp_pointer_gesture_hold =
zwp_pointer_gestures_v1_get_hold_gesture (display_wayland->pointer_gestures,
seat->wl_pointer);
zwp_pointer_gesture_hold_v1_set_user_data (seat->wp_pointer_gesture_hold,
seat);
zwp_pointer_gesture_hold_v1_add_listener (seat->wp_pointer_gesture_hold,
&gesture_hold_listener, seat);
}
}
}
else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && seat->wl_pointer)

View File

@@ -366,7 +366,8 @@ gdk_registry_handle_global (void *data,
if (strcmp (interface, "wl_compositor") == 0)
{
display_wayland->compositor =
wl_registry_bind (display_wayland->wl_registry, id, &wl_compositor_interface, MIN (version, 4));
wl_registry_bind (display_wayland->wl_registry, id,
&wl_compositor_interface, MIN (version, 5));
display_wayland->compositor_version = MIN (version, 4);
}
else if (strcmp (interface, "wl_shm") == 0)
@@ -430,6 +431,9 @@ gdk_registry_handle_global (void *data,
}
else if (strcmp (interface, "zwp_pointer_gestures_v1") == 0)
{
display_wayland->pointer_gestures_version =
MIN (version, GDK_ZWP_POINTER_GESTURES_V1_VERSION);
display_wayland->pointer_gestures =
wl_registry_bind (display_wayland->wl_registry,
id, &zwp_pointer_gestures_v1_interface,
@@ -850,6 +854,10 @@ gdk_wayland_display_notify_startup_complete (GdkDisplay *display,
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
char *free_this = NULL;
/* Will be signaled with focus activation */
if (display_wayland->xdg_activation)
return;
if (startup_id == NULL)
{
startup_id = free_this = display_wayland->startup_notification_id;

View File

@@ -52,7 +52,7 @@
G_BEGIN_DECLS
#define GDK_ZWP_POINTER_GESTURES_V1_VERSION 1
#define GDK_ZWP_POINTER_GESTURES_V1_VERSION 3
typedef struct _GdkWaylandSelection GdkWaylandSelection;
@@ -140,6 +140,7 @@ struct _GdkWaylandDisplay
int data_device_manager_version;
int gtk_shell_version;
int xdg_output_manager_version;
int pointer_gestures_version;
int xdg_activation_version;
uint32_t server_decoration_mode;

View File

@@ -101,6 +101,7 @@ gdk_wayland_primary_claim_remote (GdkWaylandPrimary *cb,
{
GDK_DISPLAY_NOTE (gdk_clipboard_get_display (GDK_CLIPBOARD (cb)), CLIPBOARD, g_message ("%p: Ignoring clipboard offer for self", cb));
gdk_content_formats_unref (formats);
g_clear_pointer (&offer, zwp_primary_selection_offer_v1_destroy);
return;
}

View File

@@ -935,12 +935,33 @@ gdk_wayland_surface_attach_image (GdkSurface *surface,
}
}
static void
gdk_wayland_surface_sync_offset (GdkSurface *surface)
{
GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (surface);
if (wl_surface_get_version (impl->display_server.wl_surface) <
WL_SURFACE_OFFSET_SINCE_VERSION)
return;
if (impl->pending_buffer_offset_x == 0 &&
impl->pending_buffer_offset_y == 0)
return;
wl_surface_offset (impl->display_server.wl_surface,
impl->pending_buffer_offset_x,
impl->pending_buffer_offset_y);
impl->pending_buffer_offset_x = 0;
impl->pending_buffer_offset_y = 0;
}
void
gdk_wayland_surface_sync (GdkSurface *surface)
{
gdk_wayland_surface_sync_shadow (surface);
gdk_wayland_surface_sync_opaque_region (surface);
gdk_wayland_surface_sync_input_region (surface);
gdk_wayland_surface_sync_offset (surface);
}
static gboolean
@@ -1477,6 +1498,7 @@ gdk_wayland_surface_configure_toplevel (GdkSurface *surface)
int width, height;
gboolean is_resizing;
gboolean fixed_size;
gboolean was_fixed_size;
gboolean saved_size;
new_state = impl->pending.toplevel.state;
@@ -1491,6 +1513,11 @@ gdk_wayland_surface_configure_toplevel (GdkSurface *surface)
GDK_TOPLEVEL_STATE_TILED) ||
is_resizing;
was_fixed_size =
surface->state & (GDK_TOPLEVEL_STATE_MAXIMIZED |
GDK_TOPLEVEL_STATE_FULLSCREEN |
GDK_TOPLEVEL_STATE_TILED);
width = impl->pending.toplevel.width;
height = impl->pending.toplevel.height;
@@ -1503,7 +1530,7 @@ gdk_wayland_surface_configure_toplevel (GdkSurface *surface)
* the client should configure its size back to what it was before
* being maximize or fullscreen.
*/
if (saved_size && !fixed_size)
if (saved_size && !fixed_size && was_fixed_size)
{
width = impl->saved_width;
height = impl->saved_height;
@@ -2293,8 +2320,7 @@ gdk_wayland_toplevel_inhibit_idle (GdkToplevel *toplevel)
if (!wayland_toplevel->idle_inhibitor)
{
g_assert (wayland_toplevel->idle_inhibitor &&
wayland_toplevel->idle_inhibitor_refcount > 0);
g_assert (wayland_toplevel->idle_inhibitor_refcount == 0);
wayland_toplevel->idle_inhibitor =
zwp_idle_inhibit_manager_v1_create_inhibitor (display_wayland->idle_inhibit_manager,
@@ -3427,39 +3453,80 @@ gdk_wayland_surface_destroy (GdkSurface *surface,
display->toplevels = g_list_remove (display->toplevels, surface);
}
static void
token_done (gpointer data,
struct xdg_activation_token_v1 *provider,
const char *token)
{
char **token_out = data;
*token_out = g_strdup (token);
}
static const struct xdg_activation_token_v1_listener token_listener = {
token_done,
};
static void
gdk_wayland_surface_focus (GdkSurface *surface,
guint32 timestamp)
{
GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (surface);
GdkDisplay *display = gdk_surface_get_display (surface);
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
gchar *startup_id = NULL;
if (!impl->display_server.gtk_surface)
return;
startup_id = g_steal_pointer (&display_wayland->startup_notification_id);
if (timestamp == GDK_CURRENT_TIME)
if (display_wayland->xdg_activation)
{
GdkWaylandDisplay *display_wayland =
GDK_WAYLAND_DISPLAY (gdk_surface_get_display (surface));
GdkWaylandSeat *seat =
GDK_WAYLAND_SEAT (gdk_display_get_default_seat (display));
if (display_wayland->startup_notification_id)
/* If the focus request does not have a startup ID associated, get a
* new token to activate the window.
*/
if (!startup_id)
{
if (display_wayland->xdg_activation)
{
xdg_activation_v1_activate (display_wayland->xdg_activation,
display_wayland->startup_notification_id,
impl->display_server.wl_surface);
}
else if (display_wayland->gtk_shell_version >= 3)
{
gtk_surface1_request_focus (impl->display_server.gtk_surface,
display_wayland->startup_notification_id);
}
struct xdg_activation_token_v1 *token;
struct wl_event_queue *event_queue;
g_clear_pointer (&display_wayland->startup_notification_id, g_free);
event_queue = wl_display_create_queue (display_wayland->wl_display);
token = xdg_activation_v1_get_activation_token (display_wayland->xdg_activation);
wl_proxy_set_queue ((struct wl_proxy *) token, event_queue);
xdg_activation_token_v1_add_listener (token,
&token_listener,
&startup_id);
xdg_activation_token_v1_set_serial (token,
_gdk_wayland_seat_get_last_implicit_grab_serial (seat, NULL),
gdk_wayland_seat_get_wl_seat (GDK_SEAT (seat)));
xdg_activation_token_v1_set_surface (token,
gdk_wayland_surface_get_wl_surface (surface));
xdg_activation_token_v1_commit (token);
while (startup_id == NULL)
wl_display_dispatch_queue (display_wayland->wl_display, event_queue);
xdg_activation_token_v1_destroy (token);
wl_event_queue_destroy (event_queue);
}
xdg_activation_v1_activate (display_wayland->xdg_activation,
startup_id,
impl->display_server.wl_surface);
}
else
gtk_surface1_present (impl->display_server.gtk_surface, timestamp);
else if (impl->display_server.gtk_surface)
{
if (timestamp != GDK_CURRENT_TIME)
gtk_surface1_present (impl->display_server.gtk_surface, timestamp);
else if (startup_id && display_wayland->gtk_shell_version >= 3)
gtk_surface1_request_focus (impl->display_server.gtk_surface,
startup_id);
}
g_free (startup_id);
}
static void

View File

@@ -71,7 +71,7 @@ foreach p: proto_sources
elif proto_stability == 'staging'
proto_version = p.get(2)
output_base = '@0@-@1@'.format(proto_name, proto_version)
input = join_paths(wlproto_dir, '@0@/@1@/@2@.xml'.format(proto_stability, proto_name, output_base))
input = files(join_paths(wlproto_dir, '@0@/@1@/@2@.xml'.format(proto_stability, proto_name, output_base)))
elif proto_stability == 'private'
output_base = proto_name
input = files('protocol/@0@.xml'.format(proto_name))

View File

@@ -1219,11 +1219,10 @@ inner_clipboard_window_procedure (HWND hwnd,
return DefWindowProcW (hwnd, message, wparam, lparam);
}
SetLastError (0);
hwnd_owner = GetClipboardOwner ();
if ((hwnd_owner == NULL) &&
(GetLastError () != ERROR_SUCCESS))
WIN32_API_FAILED ("GetClipboardOwner");
if (hwnd_owner == NULL && GetLastError () != 0)
WIN32_API_FAILED ("GetClipboardOwner");
hwnd_opener = GetOpenClipboardWindow ();

View File

@@ -945,38 +945,71 @@ _gdk_win32_enable_hidpi (GdkWin32Display *display)
}
}
static void
_gdk_win32_check_on_arm64 (GdkWin32Display *display)
gboolean
_gdk_win32_check_processor (GdkWin32ProcessorCheckType check_type)
{
static gsize checked = 0;
static gboolean is_arm64 = FALSE;
static gboolean is_wow64 = FALSE;
if (g_once_init_enter (&checked))
{
gboolean fallback_wow64_check = FALSE;
HMODULE kernel32 = LoadLibraryW (L"kernel32.dll");
if (kernel32 != NULL)
{
display->cpu_funcs.isWow64Process2 =
typedef BOOL (WINAPI *funcIsWow64Process2) (HANDLE, USHORT *, USHORT *);
funcIsWow64Process2 isWow64Process2 =
(funcIsWow64Process2) GetProcAddress (kernel32, "IsWow64Process2");
if (display->cpu_funcs.isWow64Process2 != NULL)
if (isWow64Process2 != NULL)
{
USHORT proc_cpu = 0;
USHORT native_cpu = 0;
display->cpu_funcs.isWow64Process2 (GetCurrentProcess (),
&proc_cpu,
&native_cpu);
isWow64Process2 (GetCurrentProcess (), &proc_cpu, &native_cpu);
if (native_cpu == IMAGE_FILE_MACHINE_ARM64)
display->running_on_arm64 = TRUE;
is_arm64 = TRUE;
if (proc_cpu != IMAGE_FILE_MACHINE_UNKNOWN)
is_wow64 = TRUE;
}
else
{
fallback_wow64_check = TRUE;
}
FreeLibrary (kernel32);
}
else
{
fallback_wow64_check = TRUE;
}
if (fallback_wow64_check)
IsWow64Process (GetCurrentProcess (), &is_wow64);
g_once_init_leave (&checked, 1);
}
switch (check_type)
{
case GDK_WIN32_ARM64:
return is_arm64;
break;
case GDK_WIN32_WOW64:
return is_wow64;
break;
default:
g_warning ("unknown CPU check type");
return FALSE;
break;
}
}
static void
@@ -987,7 +1020,7 @@ gdk_win32_display_init (GdkWin32Display *display_win32)
display_win32->monitors = G_LIST_MODEL (g_list_store_new (GDK_TYPE_MONITOR));
_gdk_win32_enable_hidpi (display_win32);
_gdk_win32_check_on_arm64 (display_win32);
display_win32->running_on_arm64 = _gdk_win32_check_processor (GDK_WIN32_ARM64);
/* if we have DPI awareness, set up fixed scale if set */
if (display_win32->dpi_aware_type != PROCESS_DPI_UNAWARE &&
@@ -1142,16 +1175,18 @@ gdk_win32_display_get_setting (GdkDisplay *display,
#define EGL_PLATFORM_ANGLE_ANGLE 0x3202
#endif
static gboolean
gdk_win32_display_init_gl_backend (GdkDisplay *display,
GError **error)
static GdkGLContext *
gdk_win32_display_init_gl (GdkDisplay *display,
GError **error)
{
gboolean result = FALSE;
GdkWin32Display *display_win32 = GDK_WIN32_DISPLAY (display);
HDC init_gl_hdc = NULL;
if (display_win32->dummy_context_wgl.hdc == NULL)
display_win32->dummy_context_wgl.hdc = GetDC (display_win32->hwnd);
init_gl_hdc = display_win32->dummy_context_wgl.hdc;
/*
* No env vars set, do the regular GL initialization, first WGL and then EGL,
* as WGL is the more tried-and-tested configuration.
@@ -1159,59 +1194,50 @@ gdk_win32_display_init_gl_backend (GdkDisplay *display,
#ifdef HAVE_EGL
/*
* Disable defaulting to EGL for now, since shaders need to be fixed for
* usage against libANGLE EGL. EGL is used more as a compatibility layer
* Disable defaulting to EGL as EGL is used more as a compatibility layer
* on Windows rather than being a native citizen on Windows
*/
if (_gdk_debug_flags & GDK_DEBUG_GL_EGL)
result = gdk_display_init_egl (display,
EGL_PLATFORM_ANGLE_ANGLE,
display_win32->dummy_context_wgl.hdc,
FALSE,
error);
#endif
if (!result)
if (GDK_DEBUG_CHECK (GL_EGL) || GDK_DEBUG_CHECK (GL_GLES))
{
g_clear_error (error);
result = gdk_win32_display_init_wgl (display, error);
}
#ifdef HAVE_EGL
if (!result)
{
g_clear_error (error);
result = gdk_display_init_egl (display,
EGL_PLATFORM_ANGLE_ANGLE,
display_win32->dummy_context_wgl.hdc,
TRUE,
error);
if (gdk_display_init_egl (display,
EGL_PLATFORM_ANGLE_ANGLE,
init_gl_hdc,
FALSE,
error))
{
return g_object_new (GDK_TYPE_WIN32_GL_CONTEXT_EGL,
"display", display,
NULL);
}
else
g_clear_error (error);
}
#endif
return result;
}
if (gdk_win32_display_init_wgl (display, error))
{
return g_object_new (GDK_TYPE_WIN32_GL_CONTEXT_WGL,
"display", display,
NULL);
}
static GdkGLContext *
gdk_win32_display_init_gl (GdkDisplay *display,
GError **error)
{
GdkWin32Display *display_win32 = GDK_WIN32_DISPLAY (display);
GdkGLContext *gl_context = NULL;
if (!gdk_win32_display_init_gl_backend (display, error))
return NULL;
if (display_win32->wgl_pixel_format != 0)
gl_context = g_object_new (GDK_TYPE_WIN32_GL_CONTEXT_WGL, "display", display, NULL);
#ifdef HAVE_EGL
else if (gdk_display_get_egl_display (display))
gl_context = g_object_new (GDK_TYPE_WIN32_GL_CONTEXT_EGL, "display", display, NULL);
g_clear_error (error);
if (gdk_display_init_egl (display,
EGL_PLATFORM_ANGLE_ANGLE,
init_gl_hdc,
TRUE,
error))
{
return g_object_new (GDK_TYPE_WIN32_GL_CONTEXT_EGL,
"display", display,
NULL);
}
#endif
g_return_val_if_fail (gl_context != NULL, NULL);
return gl_context;
return NULL;
}
/**

View File

@@ -105,13 +105,6 @@ typedef enum {
GDK_WIN32_TABLET_INPUT_API_WINPOINTER
} GdkWin32TabletInputAPI;
/* Detect running architecture */
typedef BOOL (WINAPI *funcIsWow64Process2) (HANDLE, USHORT *, USHORT *);
typedef struct _GdkWin32KernelCPUFuncs
{
funcIsWow64Process2 isWow64Process2;
} GdkWin32KernelCPUFuncs;
typedef struct
{
HDC hdc;
@@ -132,7 +125,6 @@ struct _GdkWin32Display
/* WGL/OpenGL Items */
GdkWin32GLDummyContextWGL dummy_context_wgl;
int wgl_pixel_format;
guint gl_version;
GListModel *monitors;
@@ -177,7 +169,6 @@ struct _GdkWin32Display
/* Running CPU items */
guint running_on_arm64 : 1;
GdkWin32KernelCPUFuncs cpu_funcs;
};
struct _GdkWin32DisplayClass

View File

@@ -19,7 +19,7 @@
*/
/*
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* Modified by the GTK+ Team and others 1997-2020. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
@@ -134,15 +134,6 @@ static GSourceFuncs event_funcs = {
NULL
};
/* Whenever we do an implicit grab (call SetCapture() after
* a mouse button is held down), we ref the capturing surface
* and keep that ref here. When mouse buttons are released,
* we remove the implicit grab and synthesize a crossing
* event from the grab surface to whatever surface is now
* under cursor.
*/
static GdkSurface *implicit_grab_surface = NULL;
static GdkSurface *mouse_window = NULL;
static GdkSurface *mouse_window_ignored_leave = NULL;
static int current_x, current_y;
@@ -644,11 +635,9 @@ build_key_event_state (BYTE *key_state)
{
GdkModifierType state;
GdkWin32Keymap *keymap;
keymap = GDK_WIN32_KEYMAP (_gdk_win32_display_get_keymap (_gdk_display));
state = 0;
if (key_state[VK_SHIFT] & 0x80)
state |= GDK_SHIFT_MASK;
state = _gdk_win32_keymap_get_mod_mask (keymap);
if (key_state[VK_CAPITAL] & 0x01)
state |= GDK_LOCK_MASK;
@@ -664,26 +653,6 @@ build_key_event_state (BYTE *key_state)
if (key_state[VK_XBUTTON2] & 0x80)
state |= GDK_BUTTON5_MASK;
keymap = GDK_WIN32_KEYMAP (_gdk_win32_display_get_keymap (_gdk_display));
if (_gdk_win32_keymap_has_altgr (keymap) &&
(key_state[VK_LCONTROL] & 0x80) &&
(key_state[VK_RMENU] & 0x80))
{
state |= GDK_MOD2_MASK;
if (key_state[VK_RCONTROL] & 0x80)
state |= GDK_CONTROL_MASK;
if (key_state[VK_LMENU] & 0x80)
state |= GDK_ALT_MASK;
}
else
{
if (key_state[VK_CONTROL] & 0x80)
state |= GDK_CONTROL_MASK;
if (key_state[VK_MENU] & 0x80)
state |= GDK_ALT_MASK;
}
return state;
}
@@ -1762,16 +1731,12 @@ gdk_event_translate (MSG *msg,
POINT point;
MINMAXINFO *mmi;
HWND hwnd;
BYTE key_state[256];
HIMC himc;
WINDOWPOS *windowpos;
gboolean ignore_leave;
GdkEvent *event;
wchar_t wbuf[100];
int ccount;
GdkDisplay *display;
GdkSurface *window = NULL;
GdkWin32Surface *impl;
@@ -1789,20 +1754,12 @@ gdk_event_translate (MSG *msg,
int button;
char buf[256];
gboolean return_val = FALSE;
int i;
GdkModifierType state;
guint keyval;
guint16 keycode;
guint8 group;
gboolean is_modifier;
double delta_x, delta_y;
GdkScrollDirection direction;
GdkTranslatedKey translated;
display = gdk_display_get_default ();
win32_display = GDK_WIN32_DISPLAY (display);
@@ -1861,35 +1818,39 @@ gdk_event_translate (MSG *msg,
switch (msg->message)
{
case WM_INPUTLANGCHANGE:
_gdk_input_locale = (HKL) msg->lParam;
_gdk_win32_keymap_set_active_layout (GDK_WIN32_KEYMAP (_gdk_win32_display_get_keymap (_gdk_display)), _gdk_input_locale);
GetLocaleInfo (MAKELCID (LOWORD (_gdk_input_locale), SORT_DEFAULT),
LOCALE_IDEFAULTANSICODEPAGE,
buf, sizeof (buf));
_gdk_input_codepage = atoi (buf);
_gdk_keymap_serial++;
GDK_NOTE (EVENTS,
g_print (" cs:%lu hkl:%p%s cp:%d",
(gulong) msg->wParam,
(gpointer) msg->lParam, _gdk_input_locale_is_ime ? " (IME)" : "",
_gdk_input_codepage));
gdk_display_setting_changed (display, "gtk-im-module");
{
GdkWin32Keymap *win32_keymap;
GdkTranslatedKey translated;
/* Generate a dummy key event to "nudge" IMContext */
translated.keyval = GDK_KEY_VoidSymbol;
translated.consumed = 0;
translated.layout = 0;
translated.level = 0;
event = gdk_key_event_new (GDK_KEY_PRESS,
window,
device_manager_win32->core_keyboard,
_gdk_win32_get_next_tick (msg->time),
0,
0,
FALSE,
&translated,
&translated);
_gdk_win32_append_event (event);
win32_keymap = GDK_WIN32_KEYMAP (_gdk_win32_display_get_keymap (_gdk_display));
_gdk_input_locale = (HKL) msg->lParam;
_gdk_win32_keymap_set_active_layout (win32_keymap, _gdk_input_locale);
_gdk_keymap_serial++;
GDK_NOTE (EVENTS,
g_print (" cs:%lu hkl:%p%s",
(gulong) msg->wParam,
(gpointer) msg->lParam,
_gdk_input_locale_is_ime ? " (IME)" : ""));
gdk_display_setting_changed (display, "gtk-im-module");
/* Generate a dummy key event to "nudge" IMContext */
translated.keyval = GDK_KEY_VoidSymbol;
translated.consumed = 0;
translated.layout = 0;
translated.level = 0;
event = gdk_key_event_new (GDK_KEY_PRESS,
window,
device_manager_win32->core_keyboard,
_gdk_win32_get_next_tick (msg->time),
0,
0,
FALSE,
&translated,
&translated);
_gdk_win32_append_event (event);
}
break;
case WM_SYSKEYUP:
@@ -1926,177 +1887,203 @@ gdk_event_translate (MSG *msg,
decode_key_lparam (msg->lParam)));
keyup_or_down:
{
GdkWin32Keymap *win32_keymap;
GdkModifierType state;
guint keyval;
guint16 keycode;
guint8 group;
gboolean is_modifier;
GdkTranslatedKey translated;
GdkTranslatedKey no_lock;
BYTE key_state[256];
wchar_t wbuf[100];
int ccount = 0;
/* Ignore key messages intended for the IME */
if (msg->wParam == VK_PROCESSKEY ||
in_ime_composition)
break;
/* Ignore key messages intended for the IME */
if (msg->wParam == VK_PROCESSKEY || in_ime_composition)
break;
/* Ignore autorepeats on modifiers */
if (msg->message == WM_KEYDOWN &&
(msg->wParam == VK_MENU ||
msg->wParam == VK_CONTROL ||
msg->wParam == VK_SHIFT) &&
((HIWORD(msg->lParam) & KF_REPEAT) >= 1))
break;
/* Ignore autorepeats on modifiers */
if (msg->message == WM_KEYDOWN &&
(msg->wParam == VK_MENU ||
msg->wParam == VK_CONTROL ||
msg->wParam == VK_SHIFT) &&
((HIWORD(msg->lParam) & KF_REPEAT) >= 1))
break;
if (GDK_SURFACE_DESTROYED (window))
break;
if (GDK_SURFACE_DESTROYED (window))
break;
impl = GDK_WIN32_SURFACE (window);
win32_keymap = GDK_WIN32_KEYMAP (_gdk_win32_display_get_keymap (display));
impl = GDK_WIN32_SURFACE (window);
API_CALL (GetKeyboardState, (key_state));
API_CALL (GetKeyboardState, (key_state));
ccount = 0;
ccount = 0;
if (msg->wParam == VK_PACKET)
{
ccount = ToUnicode (VK_PACKET, HIWORD (msg->lParam), key_state, wbuf, 1, 0);
if (ccount == 1)
{
if (wbuf[0] >= 0xD800 && wbuf[0] < 0xDC00)
{
if (msg->message == WM_KEYDOWN)
impl->leading_surrogate_keydown = wbuf[0];
else
impl->leading_surrogate_keyup = wbuf[0];
if (msg->wParam == VK_PACKET)
{
ccount = ToUnicode (VK_PACKET, HIWORD (msg->lParam), key_state, wbuf, 1, 0);
if (ccount == 1)
{
if (wbuf[0] >= 0xD800 && wbuf[0] < 0xDC00)
{
if (msg->message == WM_KEYDOWN)
impl->leading_surrogate_keydown = wbuf[0];
else
impl->leading_surrogate_keyup = wbuf[0];
/* don't emit an event */
return_val = TRUE;
break;
}
else
{
/* wait until an event is created */;
}
}
}
/* don't emit an event */
return_val = TRUE;
break;
}
else
{
/* wait until an event is created */;
}
}
}
keyval = GDK_KEY_VoidSymbol;
keycode = msg->wParam;
keyval = GDK_KEY_VoidSymbol;
keycode = msg->wParam;
if (HIWORD (msg->lParam) & KF_EXTENDED)
{
switch (msg->wParam)
{
case VK_CONTROL:
keycode = VK_RCONTROL;
break;
case VK_SHIFT: /* Actually, KF_EXTENDED is not set
* for the right shift key.
*/
keycode = VK_RSHIFT;
break;
case VK_MENU:
keycode = VK_RMENU;
break;
}
}
else if (msg->wParam == VK_SHIFT &&
LOBYTE (HIWORD (msg->lParam)) == _gdk_win32_keymap_get_rshift_scancode (GDK_WIN32_KEYMAP (_gdk_win32_display_get_keymap (_gdk_display))))
keycode = VK_RSHIFT;
if (HIWORD (msg->lParam) & KF_EXTENDED)
{
switch (msg->wParam)
{
case VK_CONTROL:
keycode = VK_RCONTROL;
break;
case VK_SHIFT: /* Actually, KF_EXTENDED is not set
* for the right shift key.
*/
keycode = VK_RSHIFT;
break;
case VK_MENU:
keycode = VK_RMENU;
break;
}
}
else if (msg->wParam == VK_SHIFT &&
LOBYTE (HIWORD (msg->lParam)) == _gdk_win32_keymap_get_rshift_scancode (win32_keymap))
keycode = VK_RSHIFT;
is_modifier = (msg->wParam == VK_CONTROL ||
msg->wParam == VK_SHIFT ||
msg->wParam == VK_MENU);
/* g_print ("ctrl:%02x lctrl:%02x rctrl:%02x alt:%02x lalt:%02x ralt:%02x\n", key_state[VK_CONTROL], key_state[VK_LCONTROL], key_state[VK_RCONTROL], key_state[VK_MENU], key_state[VK_LMENU], key_state[VK_RMENU]); */
is_modifier = (msg->wParam == VK_CONTROL ||
msg->wParam == VK_SHIFT ||
msg->wParam == VK_MENU);
state = build_key_event_state (key_state);
group = get_active_group ();
state = build_key_event_state (key_state);
group = get_active_group ();
if (msg->wParam == VK_PACKET && ccount == 1)
{
if (wbuf[0] >= 0xD800 && wbuf[0] < 0xDC00)
{
g_assert_not_reached ();
}
else if (wbuf[0] >= 0xDC00 && wbuf[0] < 0xE000)
{
wchar_t leading;
if (msg->wParam == VK_PACKET && ccount == 1)
{
if (wbuf[0] >= 0xD800 && wbuf[0] < 0xDC00)
{
g_assert_not_reached ();
}
else if (wbuf[0] >= 0xDC00 && wbuf[0] < 0xE000)
{
wchar_t leading;
if (msg->message == WM_KEYDOWN)
leading = impl->leading_surrogate_keydown;
else
leading = impl->leading_surrogate_keyup;
if (msg->message == WM_KEYDOWN)
leading = impl->leading_surrogate_keydown;
else
leading = impl->leading_surrogate_keyup;
keyval = gdk_unicode_to_keyval ((leading - 0xD800) * 0x400 + wbuf[0] - 0xDC00 + 0x10000);
}
else
{
keyval = gdk_unicode_to_keyval (wbuf[0]);
}
}
else
{
gdk_keymap_translate_keyboard_state (_gdk_win32_display_get_keymap (display),
keycode,
state,
group,
&keyval,
NULL, NULL, NULL);
}
keyval = gdk_unicode_to_keyval ((leading - 0xD800) * 0x400 + wbuf[0] - 0xDC00 + 0x10000);
}
else
{
keyval = gdk_unicode_to_keyval (wbuf[0]);
}
if (msg->message == WM_KEYDOWN)
impl->leading_surrogate_keydown = 0;
else
impl->leading_surrogate_keyup = 0;
translated.keyval = keyval;
translated.consumed = 0;
translated.layout = 0;
translated.level = 0;
/* Only one release key event is fired when both shift keys are pressed together
and then released. In order to send the missing event, press events for shift
keys are recorded and sent together when the release event occurs.
Other modifiers (e.g. ctrl, alt) don't have this problem. */
if (msg->message == WM_KEYDOWN && msg->wParam == VK_SHIFT)
{
int pressed_shift = msg->lParam & 0xffffff; /* mask shift modifier */
if (both_shift_pressed[0] == 0)
both_shift_pressed[0] = pressed_shift;
else if (both_shift_pressed[0] != pressed_shift)
both_shift_pressed[1] = pressed_shift;
}
no_lock = translated;
}
else
{
int level = 0;
int effective_group = 0;
GdkModifierType consumed = 0;
if (msg->message == WM_KEYUP && msg->wParam == VK_SHIFT)
{
if (both_shift_pressed[0] != 0 && both_shift_pressed[1] != 0)
{
int tmp_retval;
MSG fake_release = *msg;
int pressed_shift = msg->lParam & 0xffffff;
gdk_keymap_translate_keyboard_state ((GdkKeymap*) win32_keymap, keycode, state, group,
&keyval, &effective_group, &level, &consumed);
translated.keyval = keyval;
translated.consumed = consumed;
translated.layout = effective_group;
translated.level = level;
if (both_shift_pressed[0] == pressed_shift)
fake_release.lParam = both_shift_pressed[1];
else
fake_release.lParam = both_shift_pressed[0];
gdk_keymap_translate_keyboard_state ((GdkKeymap*) win32_keymap, keycode,
state & ~GDK_LOCK_MASK, group, &keyval,
&effective_group, &level, &consumed);
no_lock.keyval = keyval;
no_lock.consumed = consumed;
no_lock.layout = effective_group;
no_lock.level = level;
}
both_shift_pressed[0] = both_shift_pressed[1] = 0;
gdk_event_translate (&fake_release, &tmp_retval);
}
both_shift_pressed[0] = both_shift_pressed[1] = 0;
}
if (msg->message == WM_KEYDOWN)
impl->leading_surrogate_keydown = 0;
else
impl->leading_surrogate_keyup = 0;
/* Reset ALT_MASK if it is the Alt key itself */
if (msg->wParam == VK_MENU)
state &= ~GDK_ALT_MASK;
/* Only one release key event is fired when both shift keys are pressed together
and then released. In order to send the missing event, press events for shift
keys are recorded and sent together when the release event occurs.
Other modifiers (e.g. ctrl, alt) don't have this problem. */
if (msg->message == WM_KEYDOWN && msg->wParam == VK_SHIFT)
{
int pressed_shift = msg->lParam & 0xffffff; /* mask shift modifier */
if (both_shift_pressed[0] == 0)
both_shift_pressed[0] = pressed_shift;
else if (both_shift_pressed[0] != pressed_shift)
both_shift_pressed[1] = pressed_shift;
}
/* FIXME do proper translation */
translated.keyval = keyval;
translated.consumed = 0;
translated.layout = group;
translated.level = 0;
event = gdk_key_event_new ((msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
? GDK_KEY_PRESS
: GDK_KEY_RELEASE,
window,
device_manager_win32->core_keyboard,
_gdk_win32_get_next_tick (msg->time),
keycode,
state,
is_modifier,
&translated,
&translated);
if (msg->message == WM_KEYUP && msg->wParam == VK_SHIFT)
{
if (both_shift_pressed[0] != 0 && both_shift_pressed[1] != 0)
{
int tmp_retval;
MSG fake_release = *msg;
int pressed_shift = msg->lParam & 0xffffff;
_gdk_win32_append_event (event);
if (both_shift_pressed[0] == pressed_shift)
fake_release.lParam = both_shift_pressed[1];
else
fake_release.lParam = both_shift_pressed[0];
return_val = TRUE;
both_shift_pressed[0] = both_shift_pressed[1] = 0;
gdk_event_translate (&fake_release, &tmp_retval);
}
both_shift_pressed[0] = both_shift_pressed[1] = 0;
}
/* Reset ALT_MASK if it is the Alt key itself */
if (msg->wParam == VK_MENU)
state &= ~GDK_ALT_MASK;
event = gdk_key_event_new ((msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
? GDK_KEY_PRESS
: GDK_KEY_RELEASE,
window,
device_manager_win32->core_keyboard,
_gdk_win32_get_next_tick (msg->time),
keycode,
state,
is_modifier,
&translated,
&no_lock);
_gdk_win32_append_event (event);
return_val = TRUE;
}
break;
case WM_SYSCHAR:
@@ -2117,73 +2104,82 @@ gdk_event_translate (MSG *msg,
break;
case WM_IME_COMPOSITION:
/* On Win2k WM_IME_CHAR doesn't work correctly for non-Unicode
* applications. Thus, handle WM_IME_COMPOSITION with
* GCS_RESULTSTR instead, fetch the Unicode chars from the IME
* with ImmGetCompositionStringW().
*
* See for instance
* http://groups.google.com/groups?selm=natX5.57%24g77.19788%40nntp2.onemain.com
* and
* http://groups.google.com/groups?selm=u2XfrXw5BHA.1628%40tkmsftngp02
* for comments by other people that seems to have the same
* experience. WM_IME_CHAR just gives question marks, apparently
* because of going through some conversion to the current code
* page.
*
* WM_IME_CHAR might work on NT4 or Win9x with ActiveIMM, but
* use WM_IME_COMPOSITION there, too, to simplify the code.
*/
GDK_NOTE (EVENTS, g_print (" %#lx", (long) msg->lParam));
{
BYTE key_state[256];
wchar_t wbuf[100];
int ccount = 0;
if (!(msg->lParam & GCS_RESULTSTR))
break;
/* On Win2k WM_IME_CHAR doesn't work correctly for non-Unicode
* applications. Thus, handle WM_IME_COMPOSITION with
* GCS_RESULTSTR instead, fetch the Unicode chars from the IME
* with ImmGetCompositionStringW().
*
* See for instance
* http://groups.google.com/groups?selm=natX5.57%24g77.19788%40nntp2.onemain.com
* and
* http://groups.google.com/groups?selm=u2XfrXw5BHA.1628%40tkmsftngp02
* for comments by other people that seems to have the same
* experience. WM_IME_CHAR just gives question marks, apparently
* because of going through some conversion to the current code
* page.
*
* WM_IME_CHAR might work on NT4 or Win9x with ActiveIMM, but
* use WM_IME_COMPOSITION there, too, to simplify the code.
*/
GDK_NOTE (EVENTS, g_print (" %#lx", (long) msg->lParam));
if (GDK_SURFACE_DESTROYED (window))
break;
if (!(msg->lParam & GCS_RESULTSTR))
break;
himc = ImmGetContext (msg->hwnd);
ccount = ImmGetCompositionStringW (himc, GCS_RESULTSTR,
wbuf, sizeof (wbuf));
ImmReleaseContext (msg->hwnd, himc);
if (GDK_SURFACE_DESTROYED (window))
break;
ccount /= 2;
himc = ImmGetContext (msg->hwnd);
ccount = ImmGetCompositionStringW (himc, GCS_RESULTSTR,
wbuf, sizeof (wbuf));
ImmReleaseContext (msg->hwnd, himc);
API_CALL (GetKeyboardState, (key_state));
ccount /= 2;
for (i = 0; i < ccount; i++)
{
/* Build a key press event */
translated.keyval = gdk_unicode_to_keyval (wbuf[i]);
translated.consumed = 0;
translated.layout = get_active_group ();
translated.level = 0;
event = gdk_key_event_new (GDK_KEY_PRESS,
window,
device_manager_win32->core_keyboard,
_gdk_win32_get_next_tick (msg->time),
0,
build_key_event_state (key_state),
FALSE,
&translated,
&translated);
API_CALL (GetKeyboardState, (key_state));
_gdk_win32_append_event (event);
for (i = 0; i < ccount; i++)
{
GdkTranslatedKey translated;
/* Build a key release event. */
event = gdk_key_event_new (GDK_KEY_RELEASE,
window,
device_manager_win32->core_keyboard,
_gdk_win32_get_next_tick (msg->time),
0,
build_key_event_state (key_state),
FALSE,
&translated,
&translated);
/* Build a key press event */
translated.keyval = gdk_unicode_to_keyval (wbuf[i]);
translated.consumed = 0;
translated.layout = get_active_group ();
translated.level = 0;
event = gdk_key_event_new (GDK_KEY_PRESS,
window,
device_manager_win32->core_keyboard,
_gdk_win32_get_next_tick (msg->time),
0,
build_key_event_state (key_state),
FALSE,
&translated,
&translated);
_gdk_win32_append_event (event);
}
return_val = TRUE;
_gdk_win32_append_event (event);
/* Build a key release event. */
event = gdk_key_event_new (GDK_KEY_RELEASE,
window,
device_manager_win32->core_keyboard,
_gdk_win32_get_next_tick (msg->time),
0,
build_key_event_state (key_state),
FALSE,
&translated,
&translated);
_gdk_win32_append_event (event);
}
return_val = TRUE;
}
break;
case WM_LBUTTONDOWN:
@@ -2219,10 +2215,7 @@ gdk_event_translate (MSG *msg,
if (pointer_grab == NULL)
{
SetCapture (GDK_SURFACE_HWND (window));
g_set_object (&implicit_grab_surface, g_object_ref (window));
}
else
g_set_object (&implicit_grab_surface, NULL);
generate_button_event (GDK_BUTTON_PRESS, button,
window, msg);
@@ -2257,7 +2250,7 @@ gdk_event_translate (MSG *msg,
g_set_object (&window, find_window_for_mouse_event (window, msg));
if (pointer_grab == NULL && implicit_grab_surface != NULL)
if (pointer_grab != NULL && pointer_grab->implicit)
{
int state = build_pointer_event_state (msg);
@@ -2280,19 +2273,16 @@ gdk_event_translate (MSG *msg,
synthesize_crossing_events (display,
_gdk_device_manager->system_pointer,
implicit_grab_surface, new_window,
pointer_grab->surface, new_window,
GDK_CROSSING_UNGRAB,
&msg->pt,
0, /* TODO: Set right mask */
_gdk_win32_get_next_tick (msg->time),
FALSE);
g_set_object (&implicit_grab_surface, NULL);
g_set_object (&mouse_window, new_window);
mouse_window_ignored_leave = NULL;
}
}
else
g_set_object (&implicit_grab_surface, NULL);
generate_button_event (GDK_BUTTON_RELEASE, button,
window, msg);
@@ -2980,17 +2970,22 @@ gdk_event_translate (MSG *msg,
break;
case WM_WINDOWPOSCHANGING:
GDK_NOTE (EVENTS, (windowpos = (WINDOWPOS *) msg->lParam,
g_print (" %s %s %dx%d@%+d%+d now below %p",
_gdk_win32_surface_pos_bits_to_string (windowpos->flags),
(windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
(windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
(windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
(windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
(sprintf (buf, "%p", windowpos->hwndInsertAfter),
buf))))),
windowpos->cx, windowpos->cy, windowpos->x, windowpos->y,
GetNextWindow (msg->hwnd, GW_HWNDPREV))));
#ifdef G_ENABLE_DEBUG
{
char buf[256];
GDK_NOTE (EVENTS, (windowpos = (WINDOWPOS *) msg->lParam,
g_print (" %s %s %dx%d@%+d%+d now below %p",
_gdk_win32_surface_pos_bits_to_string (windowpos->flags),
(windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
(windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
(windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
(windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
(sprintf (buf, "%p", windowpos->hwndInsertAfter),
buf))))),
windowpos->cx, windowpos->cy, windowpos->x, windowpos->y,
GetNextWindow (msg->hwnd, GW_HWNDPREV))));
}
#endif
if (GDK_SURFACE_IS_MAPPED (window))
{
@@ -3016,15 +3011,21 @@ gdk_event_translate (MSG *msg,
case WM_WINDOWPOSCHANGED:
windowpos = (WINDOWPOS *) msg->lParam;
GDK_NOTE (EVENTS, g_print (" %s %s %dx%d@%+d%+d",
_gdk_win32_surface_pos_bits_to_string (windowpos->flags),
(windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
(windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
(windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
(windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
(sprintf (buf, "%p", windowpos->hwndInsertAfter),
buf))))),
windowpos->cx, windowpos->cy, windowpos->x, windowpos->y));
#ifdef G_ENABLE_DEBUG
{
char buf[256];
GDK_NOTE (EVENTS, g_print (" %s %s %dx%d@%+d%+d",
_gdk_win32_surface_pos_bits_to_string (windowpos->flags),
(windowpos->hwndInsertAfter == HWND_BOTTOM ? "BOTTOM" :
(windowpos->hwndInsertAfter == HWND_NOTOPMOST ? "NOTOPMOST" :
(windowpos->hwndInsertAfter == HWND_TOP ? "TOP" :
(windowpos->hwndInsertAfter == HWND_TOPMOST ? "TOPMOST" :
(sprintf (buf, "%p", windowpos->hwndInsertAfter),
buf))))),
windowpos->cx, windowpos->cy, windowpos->x, windowpos->y));
}
#endif
/* Break grabs on unmap or minimize */
if (windowpos->flags & SWP_HIDEWINDOW ||

View File

@@ -258,9 +258,6 @@ gdk_win32_display_init_wgl (GdkDisplay *display,
if (!gdk_gl_backend_can_be_used (GDK_GL_WGL, error))
return FALSE;
if (display_win32->wgl_pixel_format != 0)
return TRUE;
/* acquire and cache dummy Window (HWND & HDC) and
* dummy GL Context, it is used to query functions
* and used for other stuff as well
@@ -299,8 +296,6 @@ gdk_win32_display_init_wgl (GdkDisplay *display,
}
}
display_win32->wgl_pixel_format = best_idx;
display_win32->hasWglARBCreateContext =
epoxy_has_wgl_extension (hdc, "WGL_ARB_create_context");
display_win32->hasWglEXTSwapControl =
@@ -432,33 +427,13 @@ create_wgl_context (HDC hdc,
goto gl_fail;
}
/*
* We need a Core GL 4.1 context in order to use the GL support in
* the GStreamer media widget backend, but wglCreateContextAttribsARB()
* may only give us the GL context version that we ask for here, and
* nothing more. So, if we are asking for a pre-GL 4.1 context,
* try to ask for a 4.1 context explicitly first. If that is not supported,
* then we fall back to whatever version that we were asking for (or, even a
* legacy context if that fails), at a price of not able to have GL support
* for the media GStreamer backend.
*/
if (major < 4 || (major == 4 && minor < 1))
hglrc = create_wgl_context_with_attribs (hdc,
hglrc_base,
share,
flags,
4,
1,
is_legacy);
if (hglrc == NULL)
hglrc = create_wgl_context_with_attribs (hdc,
hglrc_base,
share,
flags,
major,
minor,
is_legacy);
hglrc = create_wgl_context_with_attribs (hdc,
hglrc_base,
share,
flags,
major,
minor,
is_legacy);
/* return the legacy context we have if it could be setup properly, in case the 3.0+ context creation failed */
if (hglrc == NULL)
@@ -564,10 +539,27 @@ gdk_win32_gl_context_wgl_realize (GdkGLContext *context,
if (!gdk_gl_context_is_api_allowed (context, GDK_GL_API_GL, error))
return 0;
gdk_gl_context_get_required_version (context, &major, &minor);
debug_bit = gdk_gl_context_get_debug_enabled (context);
compat_bit = gdk_gl_context_get_forward_compatible (context);
/*
* We may need a Core GL 4.1+ context in order to use the GL support in
* the GStreamer media widget backend (such as on Intel drivers), but
* wglCreateContextAttribsARB() may only give us the GL context version
* that we ask for here, and nothing more. So, improve things here by
* asking for the GL version that is reported to us via epoxy_gl_version(),
* rather than the default GL core 3.2 context. Save this up in our
* GdkGLContext so that subsequent contexts that are shared with this
* context are created likewise too.
*/
if (share != NULL)
gdk_gl_context_get_required_version (share, &major, &minor);
else
{
major = display_win32->gl_version / 10;
minor = display_win32->gl_version % 10;
}
if (surface != NULL)
hdc = GDK_WIN32_SURFACE (surface)->hdc;
else
@@ -634,6 +626,7 @@ gdk_win32_gl_context_wgl_realize (GdkGLContext *context,
/* Ensure that any other context is created with a legacy bit set */
gdk_gl_context_set_is_legacy (context, legacy_bit);
gdk_gl_context_set_required_version (context, major, minor);
return GDK_GL_API_GL;
}
@@ -728,10 +721,11 @@ gdk_win32_display_get_wgl_version (GdkDisplay *display,
if (!GDK_IS_WIN32_DISPLAY (display))
return FALSE;
display_win32 = GDK_WIN32_DISPLAY (display);
if (display_win32->wgl_pixel_format == 0)
if (!gdk_gl_backend_can_be_used (GDK_GL_WGL, NULL))
return FALSE;
display_win32 = GDK_WIN32_DISPLAY (display);
if (major != NULL)
*major = display_win32->gl_version / 10;
if (minor != NULL)

View File

@@ -38,7 +38,6 @@ int _gdk_input_ignore_core;
HKL _gdk_input_locale;
gboolean _gdk_input_locale_is_ime = FALSE;
UINT _gdk_input_codepage;
GdkWin32ModalOpKind _modal_operation_in_progress = GDK_WIN32_MODAL_OP_NONE;
HWND _modal_move_resize_window = NULL;

View File

@@ -0,0 +1,26 @@
/*
* Copyright (c) 2021 Philip Zander
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef _WIN64
#define GDK_WIN32_COMPILE_FOR_WOW64 1
#include "gdkkeys-win32-impl.c"
#endif

View File

@@ -0,0 +1,566 @@
/*
* Copyright (c) 2021 Philip Zander
* Copyright (c) 2018 Microsoft
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/* NOTE: When compiling the 32-bit version of the library, in addition to being
* compiled as a regular source file, this file is also included by
* gdkkeys-win32-impl-wow64.c to generate an alternate version of the code
* intended for running on a 64-bit kernel. Because of the way keyboard layout
* DLLs work on Windows, we have to generate two versions and decide at runtime
* which code path to execute. You can read more about the specifics below, in
* the section about KBD_LONG_POINTER. */
#include "gdkkeys-win32.h"
#ifndef GDK_WIN32_COMPILE_FOR_WOW64
#define GDK_WIN32_COMPILE_FOR_WOW64 0
#endif
/* This is our equivalent of the KBD_LONG_POINTER macro in Microsoft's kbd.h.
*
* A KBD_LONG_POINTER represents a pointer native to the *host*.
* I.e. 32 bits on 32-bit Windows and 64 bits on 64-bit Windows.
*
* This is *not* the same as the the bitness of the application, since it is
* possible to execute 32-bit binaries on either a 32-bit *or* a 64-bit host.
* On a 64-bit host, KBD_LONG_PTR will be 64-bits, even if the application
* itself is 32-bit. (Whereas on a 32-bit host, it will be 32-bit.)
*
* For clarity, here is an overview of the bit-size of KBD_LONG_POINTER on all
* possible host & app combinations:
*
* Host 32 64
* App +-----------
* 32 | 32 64
* 64 | - 64
*
* In the official MS headers, KBD_LONG_POINTER is implemented via a macro
* which expands to the attribute `__ptr64` if the keyboard driver is
* compiled for a 64 bit host. Unfortunately, `__ptr64` is only
* supported by MSVC. We use a union here as a workaround.
*
* For all KBD_LONG_POINTERs, we define an alias starting with "KLP".
* Our naming schema (inspired by the Windows headers) is thus the following:
* - FOO: The type FOO itself
* - PFOO: Regular pointer to the type FOO
* - KLPFOO: Keyboard Long Pointer to the type FOO
*/
#if GDK_WIN32_COMPILE_FOR_WOW64
#define DEFINE_KBD_LONG_POINTER(type) \
typedef union { \
P##type ptr; \
UINT64 _align; \
} KLP##type
#else
#define DEFINE_KBD_LONG_POINTER(type) \
typedef union { \
P##type ptr; \
} KLP##type
#endif
DEFINE_KBD_LONG_POINTER (USHORT);
DEFINE_KBD_LONG_POINTER (VOID);
/* Driver definitions
* See
* https://github.com/microsoft/windows-rs/blob/0.28.0/crates/deps/sys/src/Windows/Win32/UI/Input/KeyboardAndMouse/mod.rs
*
* For more information on how these structures work, see also:
* https://github.com/microsoft/Windows-driver-samples/tree/f0adcda012820b1cd44a8b3a1953baf478029738/input/layout
*/
typedef struct
{
BYTE Vk;
BYTE ModBits;
} VK_TO_BIT, *PVK_TO_BIT;
DEFINE_KBD_LONG_POINTER (VK_TO_BIT);
typedef struct
{
KLPVK_TO_BIT pVkToBit;
WORD wMaxModBits;
BYTE ModNumber[1];
} MODIFIERS, *PMODIFIERS;
DEFINE_KBD_LONG_POINTER (MODIFIERS);
typedef struct
{
BYTE Vsc;
USHORT Vk;
} VSC_VK, *PVSC_VK;
DEFINE_KBD_LONG_POINTER (VSC_VK);
typedef struct
{
BYTE Vk;
BYTE Vsc;
} VK_VSC, *PVK_VSC;
DEFINE_KBD_LONG_POINTER (VK_VSC);
typedef struct
{
BYTE VirtualKey;
BYTE Attributes;
WCHAR wch[1];
} VK_TO_WCHARS, *PVK_TO_WCHARS;
DEFINE_KBD_LONG_POINTER (VK_TO_WCHARS);
typedef struct
{
KLPVK_TO_WCHARS pVkToWchars;
BYTE nModifications;
BYTE cbSize;
} VK_TO_WCHAR_TABLE, *PVK_TO_WCHAR_TABLE;
DEFINE_KBD_LONG_POINTER (VK_TO_WCHAR_TABLE);
typedef struct
{
DWORD dwBoth;
WCHAR wchComposed;
USHORT uFlags;
} DEADKEY, *PDEADKEY;
DEFINE_KBD_LONG_POINTER (DEADKEY);
typedef struct
{
KLPMODIFIERS pCharModifiers;
KLPVK_TO_WCHAR_TABLE pVkToWcharTable;
KLPDEADKEY pDeadKey;
KLPVOID pKeyNames;
KLPVOID pKeyNamesExt;
KLPVOID pKeyNamesDead;
KLPUSHORT pusVSCtoVK;
BYTE bMaxVSCtoVK;
KLPVSC_VK pVSCtoVK_E0;
KLPVSC_VK pVSCtoVK_E1;
DWORD fLocaleFlags;
BYTE nLgMaxd;
BYTE cbLgEntry;
KLPVOID pLigature;
} KBDTABLES, *PKBDTABLES;
DEFINE_KBD_LONG_POINTER (KBDTABLES);
/* End of declarations */
static BYTE
keystate_to_modbits (GdkWin32KeymapLayoutInfo *info,
const BYTE keystate[256])
{
PKBDTABLES tables = (PKBDTABLES) info->tables;
PVK_TO_BIT vk_to_bit;
BYTE result = 0;
int i;
if (tables == NULL)
return 0;
vk_to_bit = tables->pCharModifiers.ptr->pVkToBit.ptr;
for (i = 0; vk_to_bit[i].Vk != 0; ++i)
if (keystate[vk_to_bit[i].Vk] & 0x80)
result |= vk_to_bit[i].ModBits;
return result;
}
static BYTE
modbits_to_level (GdkWin32KeymapLayoutInfo *info,
BYTE modbits)
{
PKBDTABLES tables = (PKBDTABLES) info->tables;
PMODIFIERS modifiers;
if (tables == NULL)
return 0;
modifiers = tables->pCharModifiers.ptr;
if (modbits > modifiers->wMaxModBits)
return 0;
return modifiers->ModNumber[modbits];
}
#define POPCOUNT(b) (!!(b & 0x01) + !!(b & 0x02) + !!(b & 0x04) + !!(b & 0x08) + \
!!(b & 0x10) + !!(b & 0x20) + !!(b & 0x40) + !!(b & 0x80))
/*
* vk_to_char_fuzzy:
*
* For a given key and modifier state, return the best-fit character and the
* modifiers used to produce it. Note that not all modifiers need to be used,
* because some modifier combination aren't actually mapped in the keyboard
* layout (for example the Ctrl key typically has no effect, unless used in
* combination with Alt). Such modifiers will not be consumed.
*
* 'Best-fit' means 'consume as many modifiers as possibe'.
*
* For example (assuming a neutral lock state):
*
* - a -> 'a', consumed_mod_bits: []
* - Shift + a -> 'A', consumed_mod_bits: [Shift]
* - Ctrl + a -> 'a', consumed_mod_bits: []
* - Ctrl + Shift + a -> 'A', consumed_mod_bits: [Shift]
*
* If capslock is active, the result could be:
*
* - a -> 'A', consumed_mod_bits: [Shift]
* - Shift + a -> 'a', consumed_mod_bits: []
* - Ctrl + a -> 'a', consumed_mod_bits: []
* - Ctrl + Shift + a -> 'A', consumed_mod_bits: [Shift]
*
* The held down modifiers are supplied in `mod_bits` as a bitmask of KBDSHIFT,
* KBDCTRL, KBDALT etc.
*
* The toggled modifiers are supplied in `lock_state` as a bitmask of CAPLOK and KANALOK.
*
* If the key combination results in a dead key, `is_dead` will be set to TRUE,
* otherwise it will be set to FALSE.
*/
static WCHAR
vk_to_char_fuzzy (GdkWin32KeymapLayoutInfo *info,
BYTE mod_bits,
BYTE lock_bits,
BYTE *consumed_mod_bits,
gboolean *is_dead,
BYTE vk)
{
PKBDTABLES tables = (PKBDTABLES) info->tables;
PVK_TO_WCHAR_TABLE wch_tables;
PVK_TO_WCHAR_TABLE wch_table;
PVK_TO_WCHARS entry;
int table_index;
int entry_index;
int n_levels;
int entry_size;
/* Initialize with defaults */
if (consumed_mod_bits)
*consumed_mod_bits = 0;
if (is_dead)
*is_dead = FALSE;
if (tables == NULL)
return WCH_NONE;
wch_tables = tables->pVkToWcharTable.ptr;
table_index = info->vk_lookup_table[vk].table;
entry_index = info->vk_lookup_table[vk].index;
if (table_index == -1 || entry_index == -1)
return WCH_NONE;
wch_table = &wch_tables[table_index];
n_levels = wch_table->nModifications;
entry_size = wch_table->cbSize;
entry = (PVK_TO_WCHARS) ((PBYTE) wch_table->pVkToWchars.ptr
+ entry_size*entry_index);
if (entry->VirtualKey == vk)
{
gboolean have_sgcaps = FALSE;
WCHAR best_char = WCH_NONE;
BYTE best_modifiers = 0;
int best_score = -1;
gboolean best_is_dead = FALSE;
int level;
/* Take toggled keys into account. For example, capslock normally inverts the
* state of KBDSHIFT (with some exceptions). */
/* Key supporting capslock */
if ((entry->Attributes & CAPLOK) &&
/* Ignore capslock if any modifiers other than shift are pressed.
* E.g. on the German layout, CapsLock + AltGr + q is the same as
* AltGr + q ('@'), but NOT the same as Shift + AltGr + q (not mapped). */
!(mod_bits & ~KBDSHIFT) &&
(lock_bits & CAPLOK))
mod_bits ^= KBDSHIFT;
/* Key supporting combination of capslock + altgr */
if ((entry->Attributes & CAPLOKALTGR) &&
(mod_bits & KBDALTGR) &&
(lock_bits & CAPLOK))
mod_bits ^= KBDSHIFT;
/* In the Swiss German layout, CapsLock + key is different from Shift + key
* for some keys. For such keys, the characters for active capslock are
* in the next entry. */
if ((entry->Attributes & SGCAPS) &&
(lock_bits & CAPLOK))
have_sgcaps = TRUE;
/* I'm not totally sure how kanalok behaves, for now I assume that there
* aren't any special cases. */
if ((entry->Attributes & KANALOK) &&
(lock_bits & KANALOK))
mod_bits ^= KBDKANA;
/* We try to find the entry with the most matching modifiers */
for (level = 0; level < n_levels; ++level)
{
BYTE candidate_modbits = info->level_to_modbits[level];
gboolean candidate_is_dead = FALSE;
WCHAR c;
int score;
if (candidate_modbits & ~mod_bits)
continue;
/* Some keys have bogus mappings for the control key, e.g. Ctrl +
* Backspace = Delete, Ctrl + [ = 0x1B or even Ctrl + Shift + 6 =
* 0x1E on a US keyboard. So we have to ignore all cases of
* Ctrl that aren't part of AltGr.
*/
if ((candidate_modbits & KBDCTRL) && !(candidate_modbits & KBDALT))
continue;
c = entry->wch[level];
if (c == WCH_DEAD || have_sgcaps)
{
/* Next entry contains the undead/capslocked keys */
PVK_TO_WCHARS next_entry;
next_entry = (PVK_TO_WCHARS) ((PBYTE) wch_table->pVkToWchars.ptr
+ entry_size * (entry_index + 1));
c = next_entry->wch[level];
candidate_is_dead = TRUE;
}
if (c == WCH_DEAD || c == WCH_LGTR || c == WCH_NONE)
continue;
score = POPCOUNT (candidate_modbits & mod_bits);
if (score > best_score)
{
best_score = score;
best_char = c;
best_modifiers = candidate_modbits;
best_is_dead = candidate_is_dead;
}
}
if (consumed_mod_bits)
*consumed_mod_bits = best_modifiers;
if (is_dead)
*is_dead = best_is_dead;
return best_char;
}
return WCH_NONE;
}
static void
init_vk_lookup_table (GdkWin32KeymapLayoutInfo *info)
{
PKBDTABLES tables = (PKBDTABLES) info->tables;
PVK_TO_WCHAR_TABLE wch_tables;
PMODIFIERS modifiers;
int i, vk, table_idx;
g_return_if_fail (tables != NULL);
wch_tables = tables->pVkToWcharTable.ptr;
/* Initialize empty table */
memset (info->vk_lookup_table, -1, sizeof (info->vk_lookup_table));
/* Initialize level -> modbits lookup table */
memset (info->level_to_modbits, 0, sizeof(info->level_to_modbits));
info->max_level = 0;
modifiers = tables->pCharModifiers.ptr;
for (i = 0; i <= modifiers->wMaxModBits; ++i)
{
if (modifiers->ModNumber[i] != SHFT_INVALID &&
modifiers->ModNumber[i] != 0 /* Workaround for buggy layouts*/)
{
if (modifiers->ModNumber[i] > info->max_level)
info->max_level = modifiers->ModNumber[i];
info->level_to_modbits[modifiers->ModNumber[i]] = i;
}
}
info->max_modbit_value = modifiers->wMaxModBits;
/* For convenience, we add 256 identity-mapped entries corresponding to the VKs.
* This allows us to return a pointer to them from the `gdk_keysym_to_key_entry`
* function.
*/
for (vk = 0; vk < 256; ++vk)
{
GdkWin32KeymapKeyEntry key_entry = {0};
key_entry.vk = vk;
key_entry.mod_bits = 0;
key_entry.next = -1;
g_array_append_val (info->key_entries, key_entry);
}
/* Special entry for ISO_Left_Tab */
{
GdkWin32KeymapKeyEntry key_entry = {0};
key_entry.vk = VK_TAB;
key_entry.mod_bits = KBDSHIFT;
key_entry.next = -1;
g_array_append_val (info->key_entries, key_entry);
}
/* Initialize generic vk <-> char tables */
for (table_idx = 0; ; ++table_idx)
{
PVK_TO_WCHAR_TABLE wch_table = &wch_tables[table_idx];
int entry_size;
int n_levels;
int entry_idx;
if (wch_table->pVkToWchars.ptr == NULL)
break;
entry_size = wch_table->cbSize;
n_levels = wch_table->nModifications;
for (entry_idx = 0; ; ++entry_idx)
{
PVK_TO_WCHARS entry;
int level;
entry = (PVK_TO_WCHARS) ((PBYTE) wch_table->pVkToWchars.ptr
+ entry_size * entry_idx);
if (entry->VirtualKey == 0)
break;
/* Lookup table to find entry for a VK in O(1). */
/* Only add the first entry, as some layouts (Swiss German) contain
* multiple successive entries for the same VK (SGCAPS). */
if (info->vk_lookup_table[entry->VirtualKey].table < 0)
{
info->vk_lookup_table[entry->VirtualKey].table = table_idx;
info->vk_lookup_table[entry->VirtualKey].index = entry_idx;
}
/* Create reverse lookup entries to find a VK+modifier combinations
* that results in a given character. */
for (level = 0; level < n_levels; ++level)
{
GdkWin32KeymapKeyEntry key_entry = {0};
WCHAR c = entry->wch[level];
int inserted_idx;
gintptr next_idx;
key_entry.vk = entry->VirtualKey;
key_entry.mod_bits = info->level_to_modbits[level];
/* There can be multiple combinations that produce the same character.
* We store all of them in a linked list.
* Check if we already have an entry for the character, so we can chain
* them together. */
if (g_hash_table_lookup_extended (info->reverse_lookup_table,
GINT_TO_POINTER (c),
NULL, (gpointer*)&next_idx))
{
key_entry.next = next_idx;
}
else
{
key_entry.next = -1;
}
/* We store the KeyEntry in an array. In the hash table we only store
* the index. */
g_array_append_val (info->key_entries, key_entry);
inserted_idx = info->key_entries->len - 1;
g_hash_table_insert (info->reverse_lookup_table,
GINT_TO_POINTER (c),
GINT_TO_POINTER (inserted_idx));
}
}
}
}
static gboolean
load_layout_dll (const char *dll,
GdkWin32KeymapLayoutInfo *info)
{
typedef KLPKBDTABLES (*KbdLayerDescriptor)(VOID);
HMODULE lib;
KbdLayerDescriptor func;
KLPKBDTABLES tables;
g_return_val_if_fail (dll != NULL, FALSE);
lib = LoadLibraryA (dll);
if (lib == NULL)
goto fail1;
func = (KbdLayerDescriptor) GetProcAddress (lib, "KbdLayerDescriptor");
if (func == NULL)
goto fail2;
tables = func();
info->lib = lib;
info->tables = (PKBDTABLES) tables.ptr;
return TRUE;
fail2:
FreeLibrary (lib);
fail1:
return FALSE;
}
#if GDK_WIN32_COMPILE_FOR_WOW64
#define GDK_WIN32_KEYMAP_IMPL_NAME gdkwin32_keymap_impl_wow64
#else
#define GDK_WIN32_KEYMAP_IMPL_NAME gdkwin32_keymap_impl
#endif
const GdkWin32KeymapImpl GDK_WIN32_KEYMAP_IMPL_NAME =
{
load_layout_dll,
init_vk_lookup_table,
keystate_to_modbits,
modbits_to_level,
vk_to_char_fuzzy
};

File diff suppressed because it is too large Load Diff

168
gdk/win32/gdkkeys-win32.h Normal file
View File

@@ -0,0 +1,168 @@
/*
* Copyright (c) 2021 Philip Zander
* Copyright (c) 2018 Microsoft
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <glib.h>
#include <windows.h>
/* For lookup table VK -> chars */
typedef struct
{
int table;
int index;
} GdkWin32KeymapTableAndIndex;
/* For reverse lookup char -> VKs */
typedef struct
{
BYTE mod_bits;
BYTE vk;
/* Index of next KeyEntry. -1 if there is no next entry. */
int next;
} GdkWin32KeymapKeyEntry;
typedef struct
{
HKL handle;
/* Keyboard layout identifier */
char name[KL_NAMELENGTH];
/* Path of the layout DLL */
char *file;
/* Handle of the layout DLL */
HINSTANCE lib;
/* The actual conversion tables provided by the layout DLL.
*
* This is a pointer to a KBDTABLES structure. The exact definition
* of this structure depends on the kernel on which the executable
* run and can in general only be determined at runtime. That's why
* we have to use a generic gpointer instead of the actual type here.
*
* See comment on GdkWin32KeymapImpl below for more information. */
gpointer tables;
/* VK -> chars lookup table so we don't have to do a linear scan
* every time we look up a key. */
GdkWin32KeymapTableAndIndex vk_lookup_table[256];
/* List of entries for reverse (char ->VKs) lookup. */
GArray *key_entries;
/* Reverse lookup table (char -> VKs). Key: Unichar. Value: int.
* The value is used to index into the key_entries array. The key_entries
* array can contain multiple consecutive entries for a given char.
* The end of the list for the char is marked by a key entry that has
* mod_bits and vk set to 0xFF. */
GHashTable *reverse_lookup_table;
/* Map level to modbits */
BYTE level_to_modbits[256];
/* Max Number of levels */
BYTE max_level;
/* Maximum possible value of a modbits bitset. */
BYTE max_modbit_value;
} GdkWin32KeymapLayoutInfo;
/* Some keyboard driver constants
* See https://github.com/microsoft/windows-rs/blob/0.28.0/crates/deps/sys/src/Windows/Win32/UI/Input/KeyboardAndMouse/mod.rs
*/
/* Modifier bits */
#define KBDBASE 0x00
#define KBDSHIFT 0x01
#define KBDCTRL 0x02
#define KBDALT 0x04
#define KBDKANA 0x08
#define KBDROYA 0x10
#define KBDLOYA 0x20
#define KBDGRPSELTAP 0x80
#define KBDALTGR (KBDCTRL| KBDALT)
/* */
#define SHFT_INVALID 0x0F
/* Char table constants */
#define WCH_NONE 0xF000
#define WCH_DEAD 0xF001
#define WCH_LGTR 0xF002
/* Char table flags */
#define CAPLOK 0x01
#define SGCAPS 0x02
#define CAPLOKALTGR 0x04
#define KANALOK 0x08
#define GRPSELTAP 0x80
/* IMPORTANT:
*
* Keyboard layout DLLs are dependent on the host architecture.
*
* - 32 bit systems have just one 32 bit DLL in System32.
* - 64 bit systems contain two versions of each layout DLL: One in System32
* for 64-bit applications, and one in SysWOW64 for 32-bit applications.
*
* Here comes the tricky part:
*
* The 32-bit DLL in SysWOW64 is *not* identical to the DLL you would find
* on a true 32 bit system, because all the pointers there are declared with
* the attribute `__ptr64` (which means they are 64 bits wide, but only the
* lower 32 bits are used).
*
* This leads to the following problems:
*
* (1) GCC does not support `__ptr64`
* (2) When compiling the 32-bit library, we need two versions of the same code
* and decide at run-time which one to execute, because we can't know at
* compile time whether we will be running on a true 32-bit system, or on
* WOW64.
*
* To solve this problem, we generate code for both cases (see
* gdkkeys-win32-impl.c + gdkkeys-win32-impl-wow64.c) and encapsulate
* the resulting functions in a struct of type GdkWin32KeymapImpl,
* allowing us to select the correct implementation at runtime.
*
*/
typedef struct
{
gboolean (*load_layout_dll) (const char *dll,
GdkWin32KeymapLayoutInfo *info);
void (*init_vk_lookup_table) (GdkWin32KeymapLayoutInfo *info);
BYTE (*keystate_to_modbits) (GdkWin32KeymapLayoutInfo *info,
const BYTE keystate[256]);
BYTE (*modbits_to_level) (GdkWin32KeymapLayoutInfo *info,
BYTE modbits);
WCHAR (*vk_to_char_fuzzy) (GdkWin32KeymapLayoutInfo *info,
BYTE mod_bits,
BYTE lock_bits,
BYTE *consumed_mod_bits,
gboolean *is_dead,
BYTE vk);
} GdkWin32KeymapImpl;

Some files were not shown because too many files have changed in this diff Show More