@ng-native/desktop 0.26.0 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -3
- package/bin/app-config.mjs +1 -0
- package/bin/archive.mjs +166 -0
- package/bin/autolink.mjs +61 -30
- package/bin/cli.mjs +127 -27
- package/bin/host.mjs +255 -58
- package/bin/package-linux.mjs +1394 -0
- package/bin/package.mjs +171 -35
- package/bin/plist.mjs +6 -2
- package/bin/png-icon.mjs +315 -0
- package/bin/prebuilt.mjs +147 -26
- package/bin/toolchain.mjs +258 -19
- package/native/CMakeLists.txt +64 -6
- package/native/appkit/CMakeLists.txt +2 -1
- package/native/appkit/appkit-backend.h +1 -0
- package/native/appkit/appkit-backend.mm +13 -0
- package/native/appkit/header-toolbar.mm +28 -25
- package/native/appkit/host-view.h +10 -0
- package/native/appkit/host-view.mm +146 -40
- package/native/appkit/input-replay.h +6 -0
- package/native/appkit/input-replay.mm +21 -12
- package/native/appkit/main.mm +11 -7
- package/native/appkit/native-controls.mm +13 -1
- package/native/appkit/split-view.mm +7 -13
- package/native/appkit/text-input-field.h +4 -0
- package/native/appkit/text-input-field.mm +20 -1
- package/native/cmake/curl.cmake +79 -0
- package/native/cmake/libraries/react-native-reanimated.cmake +5 -0
- package/native/cmake/libraries/react-native-worklets.cmake +5 -0
- package/native/cmake/linked-modules.cmake +20 -4
- package/native/cmake/react-native.cmake +18 -1
- package/native/core/include/ngn/accent-colors.h +38 -0
- package/native/core/include/ngn/accessibility-relations.h +65 -0
- package/native/core/include/ngn/accessibility.h +26 -0
- package/native/core/include/ngn/animated-frame-loop.h +56 -0
- package/native/core/include/ngn/app-info.h +24 -8
- package/native/core/include/ngn/app-menus.h +14 -1
- package/native/core/include/ngn/app-windows.h +15 -2
- package/native/core/include/ngn/aria-role.h +96 -0
- package/native/core/include/ngn/audio.h +2 -0
- package/native/core/include/ngn/camera.h +9 -0
- package/native/core/include/ngn/control-sizes.h +7 -2
- package/native/core/include/ngn/crash-report.h +31 -0
- package/native/core/include/ngn/curl-network.h +93 -0
- package/native/core/include/ngn/dbus-menu.h +39 -0
- package/native/core/include/ngn/default-menu.h +36 -0
- package/native/core/include/ngn/desktop-expo.h +7 -1
- package/native/core/include/ngn/desktop-modules.h +22 -0
- package/native/core/include/ngn/desktop-props.h +21 -1
- package/native/core/include/ngn/desktop-view-props.h +6 -0
- package/native/core/include/ngn/focus-order.h +10 -0
- package/native/core/include/ngn/header-bar.h +22 -0
- package/native/core/include/ngn/host-os.h +6 -0
- package/native/core/include/ngn/host-reload.h +21 -0
- package/native/core/include/ngn/host-state.h +23 -0
- package/native/core/include/ngn/image-source.h +26 -1
- package/native/core/include/ngn/input-script.h +3 -3
- package/native/core/include/ngn/input.h +4 -1
- package/native/core/include/ngn/launch-frame.h +21 -0
- package/native/core/include/ngn/launch-settings.h +23 -5
- package/native/core/include/ngn/mounting-backend.h +5 -0
- package/native/core/include/ngn/mounting-manager.h +1 -0
- package/native/core/include/ngn/native-controls.h +26 -5
- package/native/core/include/ngn/notification-schedule.h +74 -0
- package/native/core/include/ngn/notifications.h +2 -1
- package/native/core/include/ngn/openssl-update-crypto.h +15 -0
- package/native/core/include/ngn/photo-library.h +60 -20
- package/native/core/include/ngn/posix-locale.h +43 -0
- package/native/core/include/ngn/runtime.h +5 -0
- package/native/core/include/ngn/safe-areas.h +14 -2
- package/native/core/include/ngn/split-view.h +78 -0
- package/native/core/include/ngn/surface-metrics.h +7 -0
- package/native/core/include/ngn/system.h +14 -0
- package/native/core/include/ngn/text-input.h +13 -0
- package/native/core/include/ngn/text-units.h +38 -0
- package/native/core/include/ngn/updates.h +14 -2
- package/native/core/include/ngn/view-box.h +40 -0
- package/native/core/include/ngn/view-transform.h +15 -0
- package/native/core/include/ngn/web-browser.h +46 -0
- package/native/core/src/accent-colors.cpp +88 -0
- package/native/core/src/accessibility-relations.cpp +138 -0
- package/native/core/src/accessibility.cpp +50 -0
- package/native/core/src/animated-frame-loop.cpp +166 -0
- package/native/core/src/app-menus.cpp +26 -9
- package/native/core/src/app-windows.cpp +27 -6
- package/native/core/src/aria-role.cpp +127 -0
- package/native/core/src/control-sizes.cpp +9 -5
- package/native/core/src/crash-report.cpp +196 -0
- package/native/core/src/curl-network.cpp +1562 -0
- package/native/core/src/dbus-menu.cpp +71 -0
- package/native/core/src/default-menu.cpp +134 -0
- package/native/core/src/desktop-view-props.cpp +14 -0
- package/native/core/src/focus-order.cpp +19 -0
- package/native/core/src/header-bar.cpp +20 -0
- package/native/core/src/host-os.cpp +19 -0
- package/native/core/src/host-reload.cpp +45 -0
- package/native/core/src/host-state.cpp +8 -0
- package/native/core/src/image-source.cpp +90 -0
- package/native/core/src/input-dispatcher.cpp +27 -5
- package/native/core/src/input-script.cpp +3 -2
- package/native/core/src/launch-settings.cpp +76 -0
- package/native/core/src/libraries/react-native-reanimated.cpp +6 -1
- package/native/core/src/modules/app-info.cpp +55 -6
- package/native/core/src/modules/app-modules.cpp +1 -1
- package/native/core/src/modules/audio.cpp +4 -2
- package/native/core/src/modules/camera.cpp +8 -11
- package/native/core/src/modules/desktop-expo.cpp +10 -5
- package/native/core/src/modules/desktop-modules.cpp +106 -41
- package/native/core/src/modules/file-photo-picker.cpp +408 -0
- package/native/core/src/modules/notifications.cpp +13 -17
- package/native/core/src/modules/photo-library.cpp +42 -13
- package/native/core/src/modules/web-browser.cpp +89 -0
- package/native/core/src/mounting-manager.cpp +12 -0
- package/native/core/src/native-controls.cpp +42 -1
- package/native/core/src/notification-schedule.cpp +429 -0
- package/native/core/src/openssl-update-crypto.cpp +83 -0
- package/native/core/src/posix-locale.cpp +192 -0
- package/native/core/src/runtime.cpp +30 -1
- package/native/core/src/safe-areas.cpp +19 -4
- package/native/core/src/spawn-rules.cpp +4 -1
- package/native/core/src/split-view.cpp +93 -0
- package/native/core/src/system.cpp +19 -0
- package/native/core/src/text-input.cpp +18 -1
- package/native/core/src/text-units.cpp +99 -0
- package/native/core/src/updates.cpp +76 -17
- package/native/core/src/view-box.cpp +75 -40
- package/native/core/src/view-transform.cpp +28 -0
- package/native/docker/Dockerfile +38 -0
- package/native/docker/Dockerfile.fedora +36 -0
- package/native/docker/glibc-floor.sh +49 -0
- package/native/gtk/CMakeLists.txt +137 -0
- package/native/gtk/accent-colour.cpp +57 -0
- package/native/gtk/accent-colour.h +41 -0
- package/native/gtk/accessibility-settings.cpp +159 -0
- package/native/gtk/accessibility-settings.h +62 -0
- package/native/gtk/accessible-text.cpp +151 -0
- package/native/gtk/accessible-text.h +49 -0
- package/native/gtk/accessible.cpp +306 -0
- package/native/gtk/accessible.h +75 -0
- package/native/gtk/alerts.cpp +267 -0
- package/native/gtk/alerts.h +30 -0
- package/native/gtk/animation-frames.cpp +159 -0
- package/native/gtk/animation-frames.h +20 -0
- package/native/gtk/app-info.cpp +91 -0
- package/native/gtk/app-info.h +25 -0
- package/native/gtk/app-windows.cpp +439 -0
- package/native/gtk/app-windows.h +150 -0
- package/native/gtk/audio.cpp +370 -0
- package/native/gtk/audio.h +54 -0
- package/native/gtk/auth-session.cpp +73 -0
- package/native/gtk/auth-session.h +16 -0
- package/native/gtk/battery.cpp +110 -0
- package/native/gtk/battery.h +19 -0
- package/native/gtk/box-paint.cpp +262 -0
- package/native/gtk/box-paint.h +32 -0
- package/native/gtk/cairo-canvas.cpp +755 -0
- package/native/gtk/cairo-canvas.h +49 -0
- package/native/gtk/camera.cpp +909 -0
- package/native/gtk/camera.h +69 -0
- package/native/gtk/capture.cpp +46 -0
- package/native/gtk/capture.h +19 -0
- package/native/gtk/clock-format.cpp +151 -0
- package/native/gtk/clock-format.h +36 -0
- package/native/gtk/crypto.cpp +75 -0
- package/native/gtk/crypto.h +14 -0
- package/native/gtk/dbus-properties.cpp +131 -0
- package/native/gtk/dbus-properties.h +61 -0
- package/native/gtk/drag-and-drop.cpp +339 -0
- package/native/gtk/drag-and-drop.h +30 -0
- package/native/gtk/file-dialogs.cpp +239 -0
- package/native/gtk/file-dialogs.h +21 -0
- package/native/gtk/file-system.cpp +212 -0
- package/native/gtk/file-system.h +25 -0
- package/native/gtk/focus.cpp +282 -0
- package/native/gtk/focus.h +37 -0
- package/native/gtk/fonts.cpp +89 -0
- package/native/gtk/fonts.h +22 -0
- package/native/gtk/gst-frames.cpp +150 -0
- package/native/gtk/gst-frames.h +47 -0
- package/native/gtk/gst-playback.cpp +496 -0
- package/native/gtk/gst-playback.h +81 -0
- package/native/gtk/gtk-backend.cpp +690 -0
- package/native/gtk/gtk-backend.h +134 -0
- package/native/gtk/host-sources.cpp +354 -0
- package/native/gtk/host-sources.h +46 -0
- package/native/gtk/image-manipulator.cpp +254 -0
- package/native/gtk/image-manipulator.h +30 -0
- package/native/gtk/image-view.cpp +256 -0
- package/native/gtk/image-view.h +54 -0
- package/native/gtk/input-replay.cpp +299 -0
- package/native/gtk/input-replay.h +36 -0
- package/native/gtk/launcher-badge.cpp +29 -0
- package/native/gtk/launcher-badge.h +21 -0
- package/native/gtk/locales.cpp +131 -0
- package/native/gtk/locales.h +23 -0
- package/native/gtk/location.cpp +274 -0
- package/native/gtk/location.h +19 -0
- package/native/gtk/main.cpp +1092 -0
- package/native/gtk/menus.cpp +447 -0
- package/native/gtk/menus.h +100 -0
- package/native/gtk/native-controls.cpp +831 -0
- package/native/gtk/native-controls.h +58 -0
- package/native/gtk/network-state.cpp +72 -0
- package/native/gtk/network-state.h +24 -0
- package/native/gtk/notifications.cpp +235 -0
- package/native/gtk/notifications.h +30 -0
- package/native/gtk/pango-text.cpp +274 -0
- package/native/gtk/pango-text.h +73 -0
- package/native/gtk/portal.cpp +451 -0
- package/native/gtk/portal.h +71 -0
- package/native/gtk/printing.cpp +338 -0
- package/native/gtk/printing.h +34 -0
- package/native/gtk/proxy-resolver.cpp +74 -0
- package/native/gtk/proxy-resolver.h +20 -0
- package/native/gtk/screens.cpp +1461 -0
- package/native/gtk/screens.h +274 -0
- package/native/gtk/scroll-view.cpp +414 -0
- package/native/gtk/scroll-view.h +82 -0
- package/native/gtk/secret-store.cpp +120 -0
- package/native/gtk/secret-store.h +27 -0
- package/native/gtk/settings-portal.cpp +129 -0
- package/native/gtk/settings-portal.h +47 -0
- package/native/gtk/split-view.cpp +1105 -0
- package/native/gtk/split-view.h +195 -0
- package/native/gtk/status-notifier.cpp +487 -0
- package/native/gtk/status-notifier.h +43 -0
- package/native/gtk/surface-input.cpp +251 -0
- package/native/gtk/surface-input.h +57 -0
- package/native/gtk/system-access.cpp +295 -0
- package/native/gtk/system-access.h +37 -0
- package/native/gtk/text-field.cpp +827 -0
- package/native/gtk/text-field.h +78 -0
- package/native/gtk/video.cpp +527 -0
- package/native/gtk/video.h +47 -0
- package/native/gtk/view-widget.cpp +431 -0
- package/native/gtk/view-widget.h +105 -0
- package/native/gtk/window-scale.cpp +95 -0
- package/native/gtk/window-scale.h +35 -0
- package/native/scripts/atspi-check.py +310 -0
- package/native/scripts/atspi-check.test.py +48 -0
- package/native/scripts/build.sh +20 -3
- package/native/scripts/compilers.sh +17 -0
- package/native/scripts/deb-depends-check.sh +22 -0
- package/native/scripts/fetch.sh +23 -2
- package/native/scripts/launch-cell.sh +157 -0
- package/native/scripts/launch-probe.sh +14 -3
- package/native/scripts/make-prebuilt.mjs +133 -44
- package/native/scripts/prebuilt-host-cache.mjs +71 -40
- package/native/scripts/reset-for-compilers.sh +44 -0
- package/native/scripts/start-xvfb.sh +35 -0
- package/native/shim/paragraph-platform/react/renderer/components/text/HostPlatformParagraphProps.h +35 -0
- package/native/shim/view-platform/react/renderer/components/view/HostPlatformViewTraitsInitializer.h +5 -2
- package/native/shim/worklets/linux-reanimated-props.h +14 -0
- package/native/shim/worklets/linux-worklets.h +23 -0
- package/package.json +6 -3
- package/prebuilt.json +70 -6
|
@@ -0,0 +1,690 @@
|
|
|
1
|
+
#include "gtk-backend.h"
|
|
2
|
+
|
|
3
|
+
#include "accessible.h"
|
|
4
|
+
#include "accessible-text.h"
|
|
5
|
+
#include "focus.h"
|
|
6
|
+
#include "image-view.h"
|
|
7
|
+
#if NGN_GSTREAMER
|
|
8
|
+
#include "camera.h"
|
|
9
|
+
#include "video.h"
|
|
10
|
+
#endif
|
|
11
|
+
#include "native-controls.h"
|
|
12
|
+
#include "scroll-view.h"
|
|
13
|
+
#include "text-field.h"
|
|
14
|
+
#include "view-widget.h"
|
|
15
|
+
#include "window-scale.h"
|
|
16
|
+
|
|
17
|
+
#include "ngn/library-components.h"
|
|
18
|
+
|
|
19
|
+
#include <react/renderer/components/view/ViewProps.h>
|
|
20
|
+
|
|
21
|
+
#include <algorithm>
|
|
22
|
+
#include <utility>
|
|
23
|
+
|
|
24
|
+
namespace ngn::gtk {
|
|
25
|
+
|
|
26
|
+
namespace {
|
|
27
|
+
|
|
28
|
+
void applyViewProps(GtkWidget *widget, const ViewData &data) {
|
|
29
|
+
if (auto props = std::dynamic_pointer_cast<const facebook::react::ViewProps>(data.props)) {
|
|
30
|
+
gtk_widget_set_opacity(widget, props->opacity);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// The parent places the view (its frame and transform); the view lays out its own children and
|
|
35
|
+
// draws itself again. The parent's allocation draws it again too, which a child's blend mode,
|
|
36
|
+
// drawn by the parent (view-widget.h), needs.
|
|
37
|
+
void relayout(GtkWidget *widget) {
|
|
38
|
+
if (GtkWidget *parent = gtk_widget_get_parent(widget)) {
|
|
39
|
+
gtk_widget_queue_allocate(parent);
|
|
40
|
+
}
|
|
41
|
+
gtk_widget_queue_allocate(widget);
|
|
42
|
+
gtk_widget_queue_draw(widget);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
} // namespace
|
|
46
|
+
|
|
47
|
+
GtkBackend::GtkBackend()
|
|
48
|
+
: uiThread_(std::this_thread::get_id()),
|
|
49
|
+
headers_(std::make_unique<Headers>(*this)),
|
|
50
|
+
modals_(std::make_unique<Modals>(*this)),
|
|
51
|
+
splitViews_(std::make_unique<SplitViews>(*this)) {}
|
|
52
|
+
|
|
53
|
+
GtkBackend::~GtkBackend() {
|
|
54
|
+
// Each gives back the views it hosts before the views go.
|
|
55
|
+
splitViews_.reset();
|
|
56
|
+
modals_.reset();
|
|
57
|
+
headers_.reset();
|
|
58
|
+
for (auto &[surfaceId, surface] : surfaces_) {
|
|
59
|
+
g_object_weak_unref(G_OBJECT(surface), surfaceGone, this);
|
|
60
|
+
}
|
|
61
|
+
for (auto &[tag, entry] : searchEntries_) {
|
|
62
|
+
g_object_unref(entry);
|
|
63
|
+
}
|
|
64
|
+
{
|
|
65
|
+
std::lock_guard lock(tasksMutex_);
|
|
66
|
+
if (drainSource_ != 0) {
|
|
67
|
+
g_source_remove(drainSource_);
|
|
68
|
+
drainSource_ = 0;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
for (auto &[tag, widget] : views_) {
|
|
72
|
+
if (gtk_widget_get_parent(widget)) {
|
|
73
|
+
gtk_widget_unparent(widget);
|
|
74
|
+
}
|
|
75
|
+
g_object_unref(widget);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
void GtkBackend::addSurface(SurfaceId surfaceId, GtkWidget *surface) {
|
|
80
|
+
removeSurface(surfaceId);
|
|
81
|
+
surfaces_[surfaceId] = surface;
|
|
82
|
+
// A surface finalized with its window (the window closed) is forgotten then, so that nothing
|
|
83
|
+
// reads it after: a header or modal let go of later finds no window.
|
|
84
|
+
g_object_weak_ref(G_OBJECT(surface), surfaceGone, this);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
void GtkBackend::removeSurface(SurfaceId surfaceId) {
|
|
88
|
+
headers_->removeSurface(surfaceId);
|
|
89
|
+
if (auto it = surfaces_.find(surfaceId); it != surfaces_.end()) {
|
|
90
|
+
g_object_weak_unref(G_OBJECT(it->second), surfaceGone, this);
|
|
91
|
+
surfaces_.erase(it);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
void GtkBackend::surfaceGone(gpointer self, GObject *surface) {
|
|
96
|
+
auto &surfaces = static_cast<GtkBackend *>(self)->surfaces_;
|
|
97
|
+
for (auto it = surfaces.begin(); it != surfaces.end(); ++it) {
|
|
98
|
+
if (G_OBJECT(it->second) == surface) {
|
|
99
|
+
surfaces.erase(it);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
GtkWidget *GtkBackend::view(Tag tag) const {
|
|
106
|
+
auto it = views_.find(tag);
|
|
107
|
+
return it == views_.end() ? nullptr : it->second;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
GtkWidget *GtkBackend::surfaceWidget(SurfaceId surfaceId) const {
|
|
111
|
+
auto it = surfaces_.find(surfaceId);
|
|
112
|
+
return it == surfaces_.end() ? nullptr : it->second;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
ViewData *GtkBackend::data(Tag tag) const {
|
|
116
|
+
return viewData(view(tag));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
void GtkBackend::hostView(Tag tag, GtkWidget *slot) {
|
|
120
|
+
GtkWidget *widget = view(tag);
|
|
121
|
+
if (!widget) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
unhostView(tag);
|
|
125
|
+
GtkWidget *placeholder = makeViewWidget();
|
|
126
|
+
g_object_ref_sink(placeholder);
|
|
127
|
+
gtk_widget_set_child_visible(placeholder, FALSE);
|
|
128
|
+
// Unparenting makes a widget visible again: a covered screen (a tab not chosen) stays hidden.
|
|
129
|
+
gboolean childVisible = gtk_widget_get_child_visible(widget);
|
|
130
|
+
if (GtkWidget *parent = gtk_widget_get_parent(widget)) {
|
|
131
|
+
gtk_widget_insert_after(placeholder, parent, widget);
|
|
132
|
+
gtk_widget_unparent(widget);
|
|
133
|
+
}
|
|
134
|
+
gtk_widget_set_parent(widget, slot);
|
|
135
|
+
gtk_widget_set_child_visible(widget, childVisible);
|
|
136
|
+
hosted_[tag] = {.placeholder = placeholder, .slot = slot};
|
|
137
|
+
gtk_widget_queue_resize(slot);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
void GtkBackend::unhostView(Tag tag) {
|
|
141
|
+
auto it = hosted_.find(tag);
|
|
142
|
+
if (it == hosted_.end()) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
Hosted hosted = it->second;
|
|
146
|
+
hosted_.erase(it);
|
|
147
|
+
GtkWidget *widget = view(tag);
|
|
148
|
+
if (widget && gtk_widget_get_parent(widget) == hosted.slot) {
|
|
149
|
+
gboolean childVisible = gtk_widget_get_child_visible(widget);
|
|
150
|
+
gtk_widget_unparent(widget);
|
|
151
|
+
if (GtkWidget *parent = gtk_widget_get_parent(hosted.placeholder)) {
|
|
152
|
+
gtk_widget_insert_after(widget, parent, hosted.placeholder);
|
|
153
|
+
}
|
|
154
|
+
gtk_widget_set_child_visible(widget, childVisible);
|
|
155
|
+
relayout(widget);
|
|
156
|
+
}
|
|
157
|
+
if (gtk_widget_get_parent(hosted.placeholder)) {
|
|
158
|
+
gtk_widget_unparent(hosted.placeholder);
|
|
159
|
+
}
|
|
160
|
+
g_object_unref(hosted.placeholder);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
bool GtkBackend::isHosted(Tag tag) const {
|
|
164
|
+
auto it = hosted_.find(tag);
|
|
165
|
+
GtkWidget *widget = view(tag);
|
|
166
|
+
return it != hosted_.end() && widget && gtk_widget_get_parent(widget) == it->second.slot;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
void GtkBackend::windowRescaled(GtkWidget *window) {
|
|
170
|
+
for (const auto &[tag, widget] : views_) {
|
|
171
|
+
ViewData *d = viewData(widget);
|
|
172
|
+
if (d && d->image && GTK_WIDGET(gtk_widget_get_root(widget)) == window) {
|
|
173
|
+
applyImageProps(*d, windowScale(widget));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
GtkWidget *GtkBackend::searchEntry(Tag tag) const {
|
|
179
|
+
auto it = searchEntries_.find(tag);
|
|
180
|
+
return it == searchEntries_.end() ? nullptr : it->second;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
void GtkBackend::runOnUiThread(std::function<void()> task) {
|
|
184
|
+
std::lock_guard lock(tasksMutex_);
|
|
185
|
+
tasks_.push_back(std::move(task));
|
|
186
|
+
if (drainSource_ == 0) {
|
|
187
|
+
// One idle at the default priority, above GDK's redraw, drains the queue in order.
|
|
188
|
+
drainSource_ = g_idle_add_full(
|
|
189
|
+
G_PRIORITY_DEFAULT,
|
|
190
|
+
[](gpointer self) -> gboolean {
|
|
191
|
+
static_cast<GtkBackend *>(self)->drain();
|
|
192
|
+
return G_SOURCE_REMOVE;
|
|
193
|
+
},
|
|
194
|
+
this, nullptr);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
void GtkBackend::drain() {
|
|
199
|
+
std::deque<std::function<void()>> tasks;
|
|
200
|
+
{
|
|
201
|
+
std::lock_guard lock(tasksMutex_);
|
|
202
|
+
tasks.swap(tasks_);
|
|
203
|
+
drainSource_ = 0;
|
|
204
|
+
}
|
|
205
|
+
for (auto &task : tasks) {
|
|
206
|
+
task();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
bool GtkBackend::onUiThread() const {
|
|
211
|
+
return std::this_thread::get_id() == uiThread_;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
void GtkBackend::serviceUiThread() {
|
|
215
|
+
drain();
|
|
216
|
+
g_main_context_iteration(nullptr, FALSE);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
namespace {
|
|
220
|
+
|
|
221
|
+
// react-native-svg's elements draw nothing of their own: the svg draws them. A foreignObject's
|
|
222
|
+
// views stay hidden with them.
|
|
223
|
+
void hideSvgElement(GtkWidget *widget) {
|
|
224
|
+
const std::string &component = viewData(widget)->component;
|
|
225
|
+
if (component.starts_with("RNSVG") && component != "RNSVGSvgView") {
|
|
226
|
+
gtk_widget_set_child_visible(widget, FALSE);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Takes `widget` out of its parent, if it has one. GTK makes an unparented widget visible again:
|
|
231
|
+
// one setCovered or hideSvgElement hid stays hidden where it is inserted next.
|
|
232
|
+
void unparentStayingHidden(GtkWidget *widget) {
|
|
233
|
+
if (gtk_widget_get_parent(widget)) {
|
|
234
|
+
gboolean childVisible = gtk_widget_get_child_visible(widget);
|
|
235
|
+
gtk_widget_unparent(widget);
|
|
236
|
+
gtk_widget_set_child_visible(widget, childVisible);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
} // namespace
|
|
241
|
+
|
|
242
|
+
void GtkBackend::createView(const ShadowView &view) {
|
|
243
|
+
GtkWidget *widget = makeViewWidget(accessibleRole(view), std::string_view(view.componentName) == "Paragraph");
|
|
244
|
+
g_object_ref_sink(widget);
|
|
245
|
+
ViewData *d = viewData(widget);
|
|
246
|
+
d->tag = view.tag;
|
|
247
|
+
d->component = view.componentName;
|
|
248
|
+
d->props = view.props;
|
|
249
|
+
d->state = view.state;
|
|
250
|
+
d->emitter = view.eventEmitter;
|
|
251
|
+
d->surfaceId = view.surfaceId;
|
|
252
|
+
d->layout = view.layoutMetrics;
|
|
253
|
+
if (d->component == "TextInput") {
|
|
254
|
+
makeTextField(widget, *d);
|
|
255
|
+
} else if (d->component == "ScrollView") {
|
|
256
|
+
makeScrollView(widget, *d);
|
|
257
|
+
applyScrollViewState(*d);
|
|
258
|
+
} else if (d->component == "Image") {
|
|
259
|
+
makeImageView(widget, *d);
|
|
260
|
+
#if NGN_GSTREAMER
|
|
261
|
+
} else if (d->component == VideoViewComponentName) {
|
|
262
|
+
// The view's events reach whichever emitter the view has when they come.
|
|
263
|
+
d->video = makeVideoSurface(widget, [this, tag = view.tag](const std::string &name) {
|
|
264
|
+
auto found = views_.find(tag);
|
|
265
|
+
ViewData *data = found != views_.end() ? viewData(found->second) : nullptr;
|
|
266
|
+
if (data && data->emitter) {
|
|
267
|
+
if (auto emitter = std::dynamic_pointer_cast<const facebook::react::ViewEventEmitter>(data->emitter)) {
|
|
268
|
+
emitter->dispatchEvent(name, folly::dynamic::object(), facebook::react::RawEvent::Category::Discrete);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
} else if (d->component == CameraComponentName) {
|
|
273
|
+
d->camera = makeCameraSurface(widget, view.tag, [this, tag = view.tag](const std::string &name, folly::dynamic payload) {
|
|
274
|
+
auto found = views_.find(tag);
|
|
275
|
+
ViewData *data = found != views_.end() ? viewData(found->second) : nullptr;
|
|
276
|
+
if (data && data->emitter) {
|
|
277
|
+
if (auto emitter = std::dynamic_pointer_cast<const facebook::react::ViewEventEmitter>(data->emitter)) {
|
|
278
|
+
emitter->dispatchEvent(name, std::move(payload), facebook::react::RawEvent::Category::Discrete);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
#endif
|
|
283
|
+
} else if (d->component == "RNSScreenStackHeaderConfig") {
|
|
284
|
+
// What of a header shows is in the window's header bar: its subtree is neither drawn nor hit
|
|
285
|
+
// in the content.
|
|
286
|
+
gtk_widget_set_child_visible(widget, FALSE);
|
|
287
|
+
hooks.containerRoot(view.tag, true);
|
|
288
|
+
} else if (d->component == SidebarSectionComponentName) {
|
|
289
|
+
// Its source list draws it, over the space it takes (split-view.h).
|
|
290
|
+
gtk_widget_set_child_visible(widget, FALSE);
|
|
291
|
+
} else if (d->component == "RNSSearchBar") {
|
|
292
|
+
GtkWidget *entry = makeSearchEntry(*this, view.tag);
|
|
293
|
+
searchEntries_[view.tag] = GTK_WIDGET(g_object_ref_sink(entry));
|
|
294
|
+
if (view.props) {
|
|
295
|
+
applySearchBar(entry, *view.props);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
hideSvgElement(widget);
|
|
299
|
+
makeControl(widget, *d);
|
|
300
|
+
if (auto accessibility = accessibilityOf(view)) {
|
|
301
|
+
applyAccessibility(accessibleWidget(*d), *accessibility);
|
|
302
|
+
applyActions(*d, *accessibility);
|
|
303
|
+
}
|
|
304
|
+
applyViewProps(widget, *d);
|
|
305
|
+
views_[view.tag] = widget;
|
|
306
|
+
#if NGN_GSTREAMER
|
|
307
|
+
// Once registered, so what they send at once reaches the view: a frame the player shows already,
|
|
308
|
+
// as the first, and a camera's mountError.
|
|
309
|
+
if (auto video = std::dynamic_pointer_cast<const VideoViewProps>(view.props); d->video && video) {
|
|
310
|
+
applyVideoSurface(*d->video, videoViewModel(video->values));
|
|
311
|
+
}
|
|
312
|
+
if (auto camera = std::dynamic_pointer_cast<const CameraProps>(view.props); d->camera && camera) {
|
|
313
|
+
applyCameraSurface(*d->camera, *camera);
|
|
314
|
+
}
|
|
315
|
+
#endif
|
|
316
|
+
if (view.tag == view.surfaceId) {
|
|
317
|
+
if (auto it = surfaces_.find(view.surfaceId); it != surfaces_.end()) {
|
|
318
|
+
gtk_widget_set_parent(widget, it->second);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
void GtkBackend::deleteView(SurfaceId, Tag tag) {
|
|
324
|
+
auto it = views_.find(tag);
|
|
325
|
+
if (it == views_.end()) {
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
modals_->unmounted(tag);
|
|
329
|
+
headers_->forget(tag);
|
|
330
|
+
relations_.erase(tag);
|
|
331
|
+
splitViews_->deleted(tag);
|
|
332
|
+
unhostView(tag);
|
|
333
|
+
if (viewData(it->second)->component == "RNSScreenStackHeaderConfig") {
|
|
334
|
+
hooks.containerRoot(tag, false);
|
|
335
|
+
}
|
|
336
|
+
if (auto entry = searchEntries_.find(tag); entry != searchEntries_.end()) {
|
|
337
|
+
if (gtk_widget_get_parent(entry->second)) {
|
|
338
|
+
gtk_widget_unparent(entry->second);
|
|
339
|
+
}
|
|
340
|
+
g_object_unref(entry->second);
|
|
341
|
+
searchEntries_.erase(entry);
|
|
342
|
+
}
|
|
343
|
+
if (gtk_widget_get_parent(it->second)) {
|
|
344
|
+
gtk_widget_unparent(it->second);
|
|
345
|
+
}
|
|
346
|
+
g_object_unref(it->second);
|
|
347
|
+
views_.erase(it);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
void GtkBackend::insertChild(SurfaceId surfaceId, Tag parent, Tag child, int index) {
|
|
351
|
+
auto p = views_.find(parent), c = views_.find(child);
|
|
352
|
+
if (p == views_.end() || c == views_.end()) {
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
unhostView(child);
|
|
356
|
+
unparentStayingHidden(c->second);
|
|
357
|
+
// Fabric's order is the drawing order. The index counts views only: a TextInput's field is a
|
|
358
|
+
// child of its own, after them.
|
|
359
|
+
GtkWidget *parentWidget = contentWidget(p->second);
|
|
360
|
+
GtkWidget *sibling = gtk_widget_get_first_child(parentWidget);
|
|
361
|
+
for (int i = 0; sibling; sibling = gtk_widget_get_next_sibling(sibling)) {
|
|
362
|
+
if (!NGN_IS_VIEW(sibling) || i++ == index) {
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
gtk_widget_insert_before(c->second, parentWidget, sibling);
|
|
367
|
+
// An svg element's view stays hidden, however it came here.
|
|
368
|
+
hideSvgElement(c->second);
|
|
369
|
+
// An Image's source was picked before it had a window, at the first monitor's scale.
|
|
370
|
+
if (ViewData *d = viewData(c->second); d && d->image) {
|
|
371
|
+
applyImageProps(*d, windowScale(c->second));
|
|
372
|
+
}
|
|
373
|
+
if (viewData(c->second)->component == "ModalHostView") {
|
|
374
|
+
modals_->mounted(surfaceId, child);
|
|
375
|
+
}
|
|
376
|
+
splitViews_->inserted(parent, child);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
void GtkBackend::removeChild(SurfaceId, Tag parent, Tag child, int) {
|
|
380
|
+
modals_->unmounted(child);
|
|
381
|
+
unhostView(child);
|
|
382
|
+
if (auto c = views_.find(child); c != views_.end()) {
|
|
383
|
+
unparentStayingHidden(c->second);
|
|
384
|
+
}
|
|
385
|
+
splitViews_->removed(parent, child);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
void GtkBackend::updateProps(const ShadowView &view) {
|
|
389
|
+
auto it = views_.find(view.tag);
|
|
390
|
+
if (it == views_.end()) {
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
ViewData *d = viewData(it->second);
|
|
394
|
+
d->props = view.props;
|
|
395
|
+
forgetText(*d);
|
|
396
|
+
followRole(view);
|
|
397
|
+
applyViewProps(it->second, *d);
|
|
398
|
+
if (auto accessibility = accessibilityOf(view)) {
|
|
399
|
+
applyAccessibility(accessibleWidget(*d), *accessibility);
|
|
400
|
+
applyActions(*d, *accessibility);
|
|
401
|
+
}
|
|
402
|
+
applyTextFieldProps(*d);
|
|
403
|
+
applyScrollViewProps(*d);
|
|
404
|
+
applyControlProps(*d);
|
|
405
|
+
if (d->image) {
|
|
406
|
+
applyImageProps(*d, windowScale(it->second));
|
|
407
|
+
}
|
|
408
|
+
#if NGN_GSTREAMER
|
|
409
|
+
if (auto video = std::dynamic_pointer_cast<const VideoViewProps>(view.props); d->video && video) {
|
|
410
|
+
applyVideoSurface(*d->video, videoViewModel(video->values));
|
|
411
|
+
}
|
|
412
|
+
if (auto camera = std::dynamic_pointer_cast<const CameraProps>(view.props); d->camera && camera) {
|
|
413
|
+
applyCameraSurface(*d->camera, *camera);
|
|
414
|
+
}
|
|
415
|
+
#endif
|
|
416
|
+
if (GtkWidget *entry = searchEntry(view.tag); entry && view.props) {
|
|
417
|
+
applySearchBar(entry, *view.props);
|
|
418
|
+
}
|
|
419
|
+
splitViews_->propsChanged(view.tag);
|
|
420
|
+
relayout(it->second);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
void GtkBackend::updateState(const ShadowView &view) {
|
|
424
|
+
if (auto it = views_.find(view.tag); it != views_.end()) {
|
|
425
|
+
ViewData *d = viewData(it->second);
|
|
426
|
+
bool paragraph = d->component == "Paragraph";
|
|
427
|
+
std::string before = d->state && paragraph ? paragraphText(d->state) : std::string();
|
|
428
|
+
std::string after = view.state && paragraph ? paragraphText(view.state) : std::string();
|
|
429
|
+
// The old text goes before the contents change, the new one comes after.
|
|
430
|
+
if (before != after) {
|
|
431
|
+
accessibleTextRemoved(d->widget, before);
|
|
432
|
+
}
|
|
433
|
+
d->state = view.state;
|
|
434
|
+
forgetText(*d);
|
|
435
|
+
applyScrollViewState(*d);
|
|
436
|
+
// A Paragraph's label is its text, which is in its state, and so is whether it is static text
|
|
437
|
+
// or no element at all.
|
|
438
|
+
followRole(view);
|
|
439
|
+
if (auto accessibility = accessibilityOf(view)) {
|
|
440
|
+
applyAccessibility(accessibleWidget(*d), *accessibility);
|
|
441
|
+
applyActions(*d, *accessibility);
|
|
442
|
+
}
|
|
443
|
+
if (before != after) {
|
|
444
|
+
accessibleTextInserted(d->widget, after);
|
|
445
|
+
}
|
|
446
|
+
gtk_widget_queue_draw(d->widget);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
void GtkBackend::applyActions(ViewData &d, const AxInfo &info) {
|
|
451
|
+
// A native control and a text input's field are GTK's own widgets, with GTK's own actions.
|
|
452
|
+
if (d.field || d.control) {
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
applyAccessibleActions(
|
|
456
|
+
d.widget, info,
|
|
457
|
+
{.perform =
|
|
458
|
+
[this](GtkWidget *widget, AxVerb verb) {
|
|
459
|
+
ViewData *v = viewData(widget);
|
|
460
|
+
auto props = v ? std::dynamic_pointer_cast<const facebook::react::ViewProps>(v->props) : nullptr;
|
|
461
|
+
auto emitter = v ? std::dynamic_pointer_cast<const facebook::react::ViewEventEmitter>(v->emitter) : nullptr;
|
|
462
|
+
if (!props) {
|
|
463
|
+
return false;
|
|
464
|
+
}
|
|
465
|
+
SurfaceId surface = v->surfaceId;
|
|
466
|
+
Tag tag = v->tag;
|
|
467
|
+
return performAxVerb(*props, emitter.get(), verb, [this, surface, tag] { return hooks.activate(surface, tag); });
|
|
468
|
+
},
|
|
469
|
+
.send =
|
|
470
|
+
[](GtkWidget *widget, const std::string &name) {
|
|
471
|
+
ViewData *v = viewData(widget);
|
|
472
|
+
auto props = v ? std::dynamic_pointer_cast<const facebook::react::ViewProps>(v->props) : nullptr;
|
|
473
|
+
auto emitter = v ? std::dynamic_pointer_cast<const facebook::react::ViewEventEmitter>(v->emitter) : nullptr;
|
|
474
|
+
return props && sendAxAction(*props, emitter.get(), name);
|
|
475
|
+
}});
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
void GtkBackend::followRole(const ShadowView &view) {
|
|
479
|
+
auto it = views_.find(view.tag);
|
|
480
|
+
GtkAccessibleRole role = accessibleRole(view);
|
|
481
|
+
if (it == views_.end() || gtk_accessible_get_accessible_role(GTK_ACCESSIBLE(it->second)) == role) {
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
GtkWidget *old = it->second;
|
|
485
|
+
GtkWidget *next = makeViewWidget(role, isTextWidget(old));
|
|
486
|
+
g_object_ref_sink(next);
|
|
487
|
+
// What the backend set on the old widget that the view's props and state do not set again below.
|
|
488
|
+
gtk_widget_set_child_visible(next, gtk_widget_get_child_visible(old));
|
|
489
|
+
gtk_widget_set_focusable(next, gtk_widget_get_focusable(old));
|
|
490
|
+
gtk_widget_set_focus_on_click(next, gtk_widget_get_focus_on_click(old));
|
|
491
|
+
gtk_widget_set_can_target(next, gtk_widget_get_can_target(old));
|
|
492
|
+
if (GdkCursor *cursor = gtk_widget_get_cursor(old)) {
|
|
493
|
+
gtk_widget_set_cursor(next, cursor);
|
|
494
|
+
}
|
|
495
|
+
// The focus, wherever in the subtree it is: moving a widget out from under its parent takes it.
|
|
496
|
+
GtkRoot *root = gtk_widget_get_root(old);
|
|
497
|
+
GtkWidget *focus = root ? gtk_root_get_focus(root) : nullptr;
|
|
498
|
+
if (focus && focus != old && !gtk_widget_is_ancestor(focus, old)) {
|
|
499
|
+
focus = nullptr;
|
|
500
|
+
}
|
|
501
|
+
// The view's data (its props, state, layout and text field) goes with it; the old widget keeps
|
|
502
|
+
// the new one's empty data to free.
|
|
503
|
+
swapViewData(old, next);
|
|
504
|
+
// The focus moving to its replacement is no focus change for the view (focus.h).
|
|
505
|
+
g_object_set_data(G_OBJECT(old), "ngn-replaced-by", next);
|
|
506
|
+
// A state update replaces a Paragraph's widget with no props update to follow.
|
|
507
|
+
applyViewProps(next, *viewData(next));
|
|
508
|
+
// A focused field's GtkText loses the focus as it moves and takes it back after: the app hears
|
|
509
|
+
// neither.
|
|
510
|
+
TextField *field = focus ? textFieldOf(focus) : nullptr;
|
|
511
|
+
ViewData *fieldView = field ? std::exchange(field->view, nullptr) : nullptr;
|
|
512
|
+
// In the old one's place among its siblings, with its children in their order.
|
|
513
|
+
if (GtkWidget *parent = gtk_widget_get_parent(old)) {
|
|
514
|
+
gtk_widget_insert_after(next, parent, old);
|
|
515
|
+
gtk_widget_unparent(old);
|
|
516
|
+
}
|
|
517
|
+
while (GtkWidget *child = gtk_widget_get_first_child(old)) {
|
|
518
|
+
g_object_ref(child);
|
|
519
|
+
// Unparenting makes a child visible again: a covered screen stays hidden.
|
|
520
|
+
gboolean childVisible = gtk_widget_get_child_visible(child);
|
|
521
|
+
gtk_widget_unparent(child);
|
|
522
|
+
gtk_widget_insert_before(child, next, nullptr);
|
|
523
|
+
gtk_widget_set_child_visible(child, childVisible);
|
|
524
|
+
g_object_unref(child);
|
|
525
|
+
}
|
|
526
|
+
// An Image hears a new scale through its widget: the new one listens too, and keeps the load.
|
|
527
|
+
// Once parented, so it picks by its window's scale rather than the first monitor's.
|
|
528
|
+
if (viewData(next)->image) {
|
|
529
|
+
makeImageView(next, *viewData(next));
|
|
530
|
+
}
|
|
531
|
+
it->second = next;
|
|
532
|
+
// GTK's relations point at widgets: the view's own go onto its new widget, and those of the views
|
|
533
|
+
// that name it move to it.
|
|
534
|
+
auto names = [&](const std::vector<Tag> &tags) { return std::find(tags.begin(), tags.end(), view.tag) != tags.end(); };
|
|
535
|
+
for (const auto &[source, relations] : relations_) {
|
|
536
|
+
if (source == view.tag || names(relations.labelledBy) || names(relations.describedBy)) {
|
|
537
|
+
applyRelations(source);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
if (field && GTK_IS_TEXT(focus)) {
|
|
541
|
+
// Focusing a GtkText selects all of it: the caret stays where the user left it.
|
|
542
|
+
gtk_text_grab_focus_without_selecting(GTK_TEXT(focus));
|
|
543
|
+
} else if (focus) {
|
|
544
|
+
gtk_widget_grab_focus(focus == old ? next : focus);
|
|
545
|
+
}
|
|
546
|
+
if (fieldView) {
|
|
547
|
+
field->view = fieldView;
|
|
548
|
+
}
|
|
549
|
+
g_object_unref(old);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
void GtkBackend::updateLayout(const ShadowView &view) {
|
|
553
|
+
if (auto it = views_.find(view.tag); it != views_.end()) {
|
|
554
|
+
ViewData *d = viewData(it->second);
|
|
555
|
+
bool resized = d->layout.frame.size != view.layoutMetrics.frame.size;
|
|
556
|
+
d->layout = view.layoutMetrics;
|
|
557
|
+
forgetText(*d);
|
|
558
|
+
// A slot is measured from the view it hosts, and GTK keeps a measurement until a resize.
|
|
559
|
+
if (auto hosted = hosted_.find(view.tag); resized && hosted != hosted_.end()) {
|
|
560
|
+
gtk_widget_queue_resize(hosted->second.slot);
|
|
561
|
+
}
|
|
562
|
+
// A field's natural alignment follows the layout's direction, and a scroll view's scroll bars
|
|
563
|
+
// the content's size against its own.
|
|
564
|
+
applyTextFieldProps(*d);
|
|
565
|
+
updateScrollers(*d);
|
|
566
|
+
relayout(it->second);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
void GtkBackend::updateEventEmitter(const ShadowView &view) {
|
|
571
|
+
if (auto it = views_.find(view.tag); it != views_.end()) {
|
|
572
|
+
viewData(it->second)->emitter = view.eventEmitter;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
void GtkBackend::dispatchCommand(Tag tag, const std::string &name, const folly::dynamic &args) {
|
|
577
|
+
if (auto it = views_.find(tag); it != views_.end()) {
|
|
578
|
+
textFieldCommand(*viewData(it->second), name, args);
|
|
579
|
+
if (GtkWidget *entry = searchEntry(tag)) {
|
|
580
|
+
runSearchBarCommand(entry, name, args);
|
|
581
|
+
}
|
|
582
|
+
scrollViewCommand(*viewData(it->second), name, args);
|
|
583
|
+
controlCommand(*viewData(it->second), name, args);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
void GtkBackend::setCovered(SurfaceId, Tag tag, bool covered) {
|
|
588
|
+
if (auto it = views_.find(tag); it != views_.end()) {
|
|
589
|
+
gtk_widget_set_child_visible(it->second, !covered);
|
|
590
|
+
// A child shown again has no allocation until its parent allocates it.
|
|
591
|
+
relayout(it->second);
|
|
592
|
+
// A window split view in it is no longer shown, or shown again: the header bar follows.
|
|
593
|
+
splitViews_->placeHeaders();
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
void GtkBackend::setPresented(SurfaceId surfaceId, Tag screen, bool presented) {
|
|
598
|
+
modals_->setPresented(surfaceId, screen, presented);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
void GtkBackend::setFrontHeader(SurfaceId surfaceId, const std::optional<ScreenStacks::FrontHeader> &header) {
|
|
602
|
+
headers_->show(surfaceId, header);
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
void GtkBackend::setAccessibilityRelations(SurfaceId, Tag tag, const AxRelations &relations) {
|
|
606
|
+
if (relations.empty()) {
|
|
607
|
+
relations_.erase(tag);
|
|
608
|
+
} else {
|
|
609
|
+
relations_[tag] = relations;
|
|
610
|
+
}
|
|
611
|
+
applyRelations(tag);
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
void GtkBackend::applyRelations(Tag tag) {
|
|
615
|
+
GtkWidget *widget = view(tag);
|
|
616
|
+
if (!widget) {
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
auto it = relations_.find(tag);
|
|
620
|
+
AxRelations relations = it == relations_.end() ? AxRelations{} : it->second;
|
|
621
|
+
GtkAccessible *source = GTK_ACCESSIBLE(relationWidget(*viewData(widget)));
|
|
622
|
+
auto point = [&](GtkAccessibleRelation relation, const std::vector<Tag> &tags) {
|
|
623
|
+
GList *targets = nullptr;
|
|
624
|
+
for (Tag target : tags) {
|
|
625
|
+
if (GtkWidget *w = view(target)) {
|
|
626
|
+
targets = g_list_append(targets, relationWidget(*viewData(w)));
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
if (targets) {
|
|
630
|
+
// A list of references goes in a GValue as a GList, which GTK keeps: the varargs form takes
|
|
631
|
+
// them one by one, up to a null.
|
|
632
|
+
GValue value = G_VALUE_INIT;
|
|
633
|
+
g_value_init(&value, G_TYPE_POINTER);
|
|
634
|
+
g_value_set_pointer(&value, targets);
|
|
635
|
+
// GTK compares two lists of references by membership, so one in another order is "the same"
|
|
636
|
+
// and would keep the old order: the old value goes first.
|
|
637
|
+
gtk_accessible_reset_relation(source, relation);
|
|
638
|
+
gtk_accessible_update_relation_value(source, 1, &relation, &value);
|
|
639
|
+
g_value_unset(&value);
|
|
640
|
+
} else {
|
|
641
|
+
gtk_accessible_reset_relation(source, relation);
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
point(GTK_ACCESSIBLE_RELATION_LABELLED_BY, relations.labelledBy);
|
|
645
|
+
point(GTK_ACCESSIBLE_RELATION_DESCRIBED_BY, relations.describedBy);
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
void GtkBackend::didMount(SurfaceId surfaceId) {
|
|
649
|
+
modals_->settle();
|
|
650
|
+
splitViews_->layOut();
|
|
651
|
+
splitViews_->placeHeaders();
|
|
652
|
+
headers_->refresh();
|
|
653
|
+
if (onMount) {
|
|
654
|
+
onMount(surfaceId);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
void GtkBackend::updateDesktopProps(SurfaceId, Tag tag, const DesktopProps &props) {
|
|
659
|
+
if (auto it = views_.find(tag); it != views_.end()) {
|
|
660
|
+
ViewData *d = viewData(it->second);
|
|
661
|
+
d->desktop = props;
|
|
662
|
+
applyFocusable(it->second, *d);
|
|
663
|
+
updateScrollers(*d);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
void GtkBackend::setSplitView(SurfaceId surfaceId, Tag split, bool window) {
|
|
668
|
+
splitViews_->place(surfaceId, split, window);
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
void GtkBackend::setSourceLists(SurfaceId, Tag parent, const std::vector<SourceList> &lists) {
|
|
672
|
+
splitViews_->setSourceLists(parent, lists);
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
void GtkBackend::announce(SurfaceId surfaceId, const Announcement &announcement) {
|
|
676
|
+
announceOn(surfaceWidget(surfaceId), announcement);
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
void GtkBackend::setSvgDrawing(SurfaceId, Tag svg, std::shared_ptr<const SvgDocument> document) {
|
|
680
|
+
if (auto it = views_.find(svg); it != views_.end() && viewData(it->second)->component == "RNSVGSvgView") {
|
|
681
|
+
viewData(it->second)->svg = std::move(document);
|
|
682
|
+
gtk_widget_queue_draw(it->second);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
std::vector<facebook::react::ComponentDescriptorProvider> GtkBackend::componentProviders() const {
|
|
687
|
+
return libraryComponents();
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
} // namespace ngn::gtk
|