@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,57 @@
|
|
|
1
|
+
#include "accent-colour.h"
|
|
2
|
+
|
|
3
|
+
#include "settings-portal.h"
|
|
4
|
+
|
|
5
|
+
#include <adwaita.h>
|
|
6
|
+
|
|
7
|
+
namespace ngn::gtk {
|
|
8
|
+
|
|
9
|
+
AccentFollower::AccentFollower() {
|
|
10
|
+
if (adw_get_major_version() > 1 || adw_get_minor_version() >= 6) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
portal_ = std::make_unique<SettingsPortal>(std::vector<std::string>{"accent-color"}, [this](const std::string &, GVariant *value) {
|
|
14
|
+
GVariant *color = portalValue(value);
|
|
15
|
+
accent_.reset();
|
|
16
|
+
if (color && g_variant_is_of_type(color, G_VARIANT_TYPE("(ddd)"))) {
|
|
17
|
+
Rgb rgb;
|
|
18
|
+
g_variant_get(color, "(ddd)", &rgb.red, &rgb.green, &rgb.blue);
|
|
19
|
+
accent_ = rgb;
|
|
20
|
+
}
|
|
21
|
+
if (color) {
|
|
22
|
+
g_variant_unref(color);
|
|
23
|
+
}
|
|
24
|
+
apply();
|
|
25
|
+
});
|
|
26
|
+
g_signal_connect_swapped(adw_style_manager_get_default(), "notify::dark", G_CALLBACK(+[](AccentFollower *self) { self->apply(); }), this);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
AccentFollower::~AccentFollower() {
|
|
30
|
+
if (portal_) {
|
|
31
|
+
g_signal_handlers_disconnect_by_data(adw_style_manager_get_default(), this);
|
|
32
|
+
}
|
|
33
|
+
if (provider_) {
|
|
34
|
+
if (GdkDisplay *display = gdk_display_get_default()) {
|
|
35
|
+
gtk_style_context_remove_provider_for_display(display, GTK_STYLE_PROVIDER(provider_));
|
|
36
|
+
}
|
|
37
|
+
g_clear_object(&provider_);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
void AccentFollower::apply() {
|
|
42
|
+
bool dark = adw_style_manager_get_dark(adw_style_manager_get_default());
|
|
43
|
+
auto colors = accent_ ? accentColors(*accent_, dark) : std::nullopt;
|
|
44
|
+
css_ = colors ? accentCss(*colors) : std::string();
|
|
45
|
+
GdkDisplay *display = gdk_display_get_default();
|
|
46
|
+
if (!display) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (!provider_) {
|
|
50
|
+
provider_ = gtk_css_provider_new();
|
|
51
|
+
// Over libadwaita's stylesheet (the theme's priority), under the app's own CSS.
|
|
52
|
+
gtk_style_context_add_provider_for_display(display, GTK_STYLE_PROVIDER(provider_), GTK_STYLE_PROVIDER_PRIORITY_THEME + 1);
|
|
53
|
+
}
|
|
54
|
+
gtk_css_provider_load_from_data(provider_, css_.c_str(), -1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
} // namespace ngn::gtk
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// The desktop's accent colour below libadwaita 1.6, which draws its own blue whatever the desktop
|
|
2
|
+
// says: the settings portal's org.freedesktop.appearance accent-color, worked out as libadwaita 1.6
|
|
3
|
+
// does (the core's accent-colors.h) and applied over libadwaita's stylesheet as its accent_bg_color,
|
|
4
|
+
// accent_fg_color and accent_color, again as the style turns dark or light and as the desktop's
|
|
5
|
+
// accent changes. From 1.6 libadwaita follows the portal itself and this does nothing.
|
|
6
|
+
#pragma once
|
|
7
|
+
|
|
8
|
+
#include "ngn/accent-colors.h"
|
|
9
|
+
|
|
10
|
+
#include <gtk/gtk.h>
|
|
11
|
+
|
|
12
|
+
#include <memory>
|
|
13
|
+
#include <optional>
|
|
14
|
+
#include <string>
|
|
15
|
+
|
|
16
|
+
namespace ngn::gtk {
|
|
17
|
+
|
|
18
|
+
class SettingsPortal;
|
|
19
|
+
|
|
20
|
+
class AccentFollower {
|
|
21
|
+
public:
|
|
22
|
+
AccentFollower();
|
|
23
|
+
~AccentFollower();
|
|
24
|
+
AccentFollower(const AccentFollower &) = delete;
|
|
25
|
+
AccentFollower &operator=(const AccentFollower &) = delete;
|
|
26
|
+
|
|
27
|
+
// The CSS applied now: empty when the desktop sets no accent, or libadwaita follows it itself.
|
|
28
|
+
const std::string &css() const {
|
|
29
|
+
return css_;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private:
|
|
33
|
+
void apply();
|
|
34
|
+
|
|
35
|
+
std::unique_ptr<SettingsPortal> portal_;
|
|
36
|
+
std::optional<Rgb> accent_;
|
|
37
|
+
GtkCssProvider *provider_{nullptr};
|
|
38
|
+
std::string css_;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
} // namespace ngn::gtk
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
#include "accessibility-settings.h"
|
|
2
|
+
|
|
3
|
+
#include "settings-portal.h"
|
|
4
|
+
|
|
5
|
+
#include <adwaita.h>
|
|
6
|
+
#include <gtk/gtk.h>
|
|
7
|
+
|
|
8
|
+
#include <cstring>
|
|
9
|
+
#include <memory>
|
|
10
|
+
|
|
11
|
+
namespace ngn::gtk {
|
|
12
|
+
|
|
13
|
+
namespace {
|
|
14
|
+
|
|
15
|
+
// An int or enum GtkSettings property newer than the floor, or `fallback` where GTK lacks it.
|
|
16
|
+
int settingOr(GtkSettings *settings, const char *name, int fallback) {
|
|
17
|
+
GParamSpec *spec = g_object_class_find_property(G_OBJECT_GET_CLASS(settings), name);
|
|
18
|
+
if (!spec) {
|
|
19
|
+
return fallback;
|
|
20
|
+
}
|
|
21
|
+
GValue value = G_VALUE_INIT;
|
|
22
|
+
g_value_init(&value, spec->value_type);
|
|
23
|
+
g_object_get_property(G_OBJECT(settings), name, &value);
|
|
24
|
+
int out = G_VALUE_HOLDS_ENUM(&value) ? g_value_get_enum(&value) : G_VALUE_HOLDS_INT(&value) ? g_value_get_int(&value) : fallback;
|
|
25
|
+
g_value_unset(&value);
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// A portal number, 0 where the value is none.
|
|
30
|
+
guint32 portalNumber(GVariant *value) {
|
|
31
|
+
GVariant *inner = portalValue(value);
|
|
32
|
+
guint32 n = inner && g_variant_is_of_type(inner, G_VARIANT_TYPE_UINT32) ? g_variant_get_uint32(inner) : 0;
|
|
33
|
+
if (inner) {
|
|
34
|
+
g_variant_unref(inner);
|
|
35
|
+
}
|
|
36
|
+
return n;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
} // namespace
|
|
40
|
+
|
|
41
|
+
bool gtkWantsMoreContrast(int interfaceContrast) {
|
|
42
|
+
// GtkInterfaceContrast: 0 unsupported, 1 no preference, 2 more, 3 less. The property reads 0 on
|
|
43
|
+
// a GTK without it, and 1 where nothing is asked for.
|
|
44
|
+
return interfaceContrast == 2;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
AccessibilitySettingsWatcher::AccessibilitySettingsWatcher(std::function<void(const AccessibilitySettings &)> changed, GDBusConnection *connection)
|
|
48
|
+
: changed_(std::move(changed)), cancellable_(g_cancellable_new()) {
|
|
49
|
+
GtkSettings *settings = gtk_settings_get_default();
|
|
50
|
+
for (const char *name : {"notify::gtk-enable-animations", "notify::gtk-interface-reduced-motion", "notify::gtk-interface-contrast"}) {
|
|
51
|
+
if (settings && g_object_class_find_property(G_OBJECT_GET_CLASS(settings), strchr(name, ':') + 2)) {
|
|
52
|
+
g_signal_connect_swapped(settings, name, G_CALLBACK(+[](AccessibilitySettingsWatcher *self) {
|
|
53
|
+
self->readGtk();
|
|
54
|
+
self->report();
|
|
55
|
+
}), this);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
g_signal_connect_swapped(adw_style_manager_get_default(), "notify::high-contrast", G_CALLBACK(+[](AccessibilitySettingsWatcher *self) {
|
|
59
|
+
self->readGtk();
|
|
60
|
+
self->report();
|
|
61
|
+
}), this);
|
|
62
|
+
readGtk();
|
|
63
|
+
report();
|
|
64
|
+
|
|
65
|
+
// The settings portal's reduced-motion and contrast, on the session bus or the test's connection.
|
|
66
|
+
portal_ = std::make_unique<SettingsPortal>(
|
|
67
|
+
std::vector<std::string>{"reduced-motion", "contrast"}, [this](const std::string &key, GVariant *value) { readPortal(key, value); },
|
|
68
|
+
connection);
|
|
69
|
+
|
|
70
|
+
// AT-SPI's own status, which says whether a screen reader runs: on the session bus, or the test's
|
|
71
|
+
// connection.
|
|
72
|
+
auto proxyOn = [connection](GDBusProxyFlags flags, const char *name, const char *path, const char *interface, GCancellable *cancellable,
|
|
73
|
+
GAsyncReadyCallback ready, gpointer data) {
|
|
74
|
+
if (connection) {
|
|
75
|
+
g_dbus_proxy_new(connection, flags, nullptr, name, path, interface, cancellable, ready, data);
|
|
76
|
+
} else {
|
|
77
|
+
g_dbus_proxy_new_for_bus(G_BUS_TYPE_SESSION, flags, nullptr, name, path, interface, cancellable, ready, data);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
proxyOn(
|
|
81
|
+
G_DBUS_PROXY_FLAGS_NONE, "org.a11y.Bus", "/org/a11y/bus", "org.a11y.Status", cancellable_,
|
|
82
|
+
+[](GObject *, GAsyncResult *result, gpointer data) {
|
|
83
|
+
GDBusProxy *proxy = g_dbus_proxy_new_finish(result, nullptr);
|
|
84
|
+
if (!proxy) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
auto *self = static_cast<AccessibilitySettingsWatcher *>(data);
|
|
88
|
+
self->status_ = proxy;
|
|
89
|
+
g_signal_connect_swapped(proxy, "g-properties-changed", G_CALLBACK(+[](AccessibilitySettingsWatcher *self) {
|
|
90
|
+
self->readStatus();
|
|
91
|
+
}), self);
|
|
92
|
+
self->readStatus();
|
|
93
|
+
},
|
|
94
|
+
this);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
AccessibilitySettingsWatcher::~AccessibilitySettingsWatcher() {
|
|
98
|
+
// Replies still on their way find nothing to call.
|
|
99
|
+
g_cancellable_cancel(cancellable_);
|
|
100
|
+
g_clear_object(&cancellable_);
|
|
101
|
+
if (GtkSettings *settings = gtk_settings_get_default()) {
|
|
102
|
+
g_signal_handlers_disconnect_by_data(settings, this);
|
|
103
|
+
}
|
|
104
|
+
g_signal_handlers_disconnect_by_data(adw_style_manager_get_default(), this);
|
|
105
|
+
if (status_) {
|
|
106
|
+
g_signal_handlers_disconnect_by_data(status_, this);
|
|
107
|
+
g_clear_object(&status_);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
void AccessibilitySettingsWatcher::readGtk() {
|
|
112
|
+
GtkSettings *settings = gtk_settings_get_default();
|
|
113
|
+
if (settings) {
|
|
114
|
+
gboolean animations = TRUE;
|
|
115
|
+
g_object_get(settings, "gtk-enable-animations", &animations, nullptr);
|
|
116
|
+
sources_.animations = animations;
|
|
117
|
+
// GtkReducedMotion: 0 no preference, 1 reduce. GtkInterfaceContrast: 0 no preference, 1 more.
|
|
118
|
+
sources_.gtkReducedMotion = settingOr(settings, "gtk-interface-reduced-motion", 0) == 1;
|
|
119
|
+
}
|
|
120
|
+
bool gtkContrast = settings && gtkWantsMoreContrast(settingOr(settings, "gtk-interface-contrast", 0));
|
|
121
|
+
sources_.highContrast = adw_style_manager_get_high_contrast(adw_style_manager_get_default()) || gtkContrast;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
void AccessibilitySettingsWatcher::readPortal(const std::string &key, GVariant *value) {
|
|
125
|
+
// reduced-motion 1 is reduce; contrast 1 is higher.
|
|
126
|
+
if (key == "reduced-motion") {
|
|
127
|
+
sources_.portalReducedMotion = portalNumber(value) == 1;
|
|
128
|
+
} else if (key == "contrast") {
|
|
129
|
+
sources_.portalContrast = portalNumber(value) == 1;
|
|
130
|
+
}
|
|
131
|
+
report();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
void AccessibilitySettingsWatcher::readStatus() {
|
|
135
|
+
GVariant *enabled = status_ ? g_dbus_proxy_get_cached_property(status_, "ScreenReaderEnabled") : nullptr;
|
|
136
|
+
sources_.screenReader = enabled && g_variant_is_of_type(enabled, G_VARIANT_TYPE_BOOLEAN) && g_variant_get_boolean(enabled);
|
|
137
|
+
if (enabled) {
|
|
138
|
+
g_variant_unref(enabled);
|
|
139
|
+
}
|
|
140
|
+
report();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
void AccessibilitySettingsWatcher::report() {
|
|
144
|
+
auto settings = linuxAccessibility(sources_);
|
|
145
|
+
if (reported_ != settings) {
|
|
146
|
+
reported_ = settings;
|
|
147
|
+
changed_(settings);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
WatchedHostState makeWatchedHostState() {
|
|
152
|
+
WatchedHostState made;
|
|
153
|
+
made.state = std::make_shared<HostState>();
|
|
154
|
+
// Heard at start, so the state is made before the watcher.
|
|
155
|
+
made.accessibility = std::make_unique<AccessibilitySettingsWatcher>([state = made.state](const AccessibilitySettings &settings) { state->accessibility.set(settings); });
|
|
156
|
+
return made;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
} // namespace ngn::gtk
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// The desktop's accessibility settings on GTK, as AccessibilityInfo reads them (host-state.h's
|
|
2
|
+
// linuxAccessibility): reduce motion from the settings portal's reduced-motion, GTK 4.22's
|
|
3
|
+
// gtk-interface-reduced-motion and gtk-enable-animations; increase contrast from the portal's
|
|
4
|
+
// contrast, libadwaita's high-contrast and GTK 4.20's gtk-interface-contrast; a screen reader from
|
|
5
|
+
// AT-SPI's org.a11y.Status. Each is read at start and followed as it changes; a source that is not
|
|
6
|
+
// there (an older GTK, no portal, no AT-SPI bus) counts as off.
|
|
7
|
+
#pragma once
|
|
8
|
+
|
|
9
|
+
#include "ngn/host-state.h"
|
|
10
|
+
|
|
11
|
+
#include <gio/gio.h>
|
|
12
|
+
|
|
13
|
+
#include <functional>
|
|
14
|
+
#include <memory>
|
|
15
|
+
#include <optional>
|
|
16
|
+
|
|
17
|
+
namespace ngn::gtk {
|
|
18
|
+
|
|
19
|
+
class SettingsPortal;
|
|
20
|
+
|
|
21
|
+
// Whether a gtk-interface-contrast value asks for more contrast. GtkInterfaceContrast is 0
|
|
22
|
+
// unsupported, 1 no preference, 2 more, 3 less: only 2 does.
|
|
23
|
+
bool gtkWantsMoreContrast(int interfaceContrast);
|
|
24
|
+
|
|
25
|
+
class AccessibilitySettingsWatcher {
|
|
26
|
+
public:
|
|
27
|
+
// `changed` hears the settings at start and on each change, on the GTK thread. The portal and
|
|
28
|
+
// AT-SPI are reached through the session bus, or through `connection` where a test gives one.
|
|
29
|
+
explicit AccessibilitySettingsWatcher(std::function<void(const AccessibilitySettings &)> changed, GDBusConnection *connection = nullptr);
|
|
30
|
+
~AccessibilitySettingsWatcher();
|
|
31
|
+
AccessibilitySettingsWatcher(const AccessibilitySettingsWatcher &) = delete;
|
|
32
|
+
AccessibilitySettingsWatcher &operator=(const AccessibilitySettingsWatcher &) = delete;
|
|
33
|
+
|
|
34
|
+
const LinuxAccessibilitySources &sources() const {
|
|
35
|
+
return sources_;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private:
|
|
39
|
+
void readGtk();
|
|
40
|
+
void readPortal(const std::string &key, GVariant *value);
|
|
41
|
+
void readStatus();
|
|
42
|
+
void report();
|
|
43
|
+
|
|
44
|
+
std::function<void(const AccessibilitySettings &)> changed_;
|
|
45
|
+
LinuxAccessibilitySources sources_;
|
|
46
|
+
std::optional<AccessibilitySettings> reported_;
|
|
47
|
+
GCancellable *cancellable_{nullptr};
|
|
48
|
+
std::unique_ptr<SettingsPortal> portal_;
|
|
49
|
+
GDBusProxy *status_{nullptr};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// The host's state with its accessibility settings kept in step by a watcher: made together, so
|
|
53
|
+
// the state of a running app never lacks its feed. Only the instance that runs the app makes one;
|
|
54
|
+
// a second launch hands its links on and exits before it has any state to feed.
|
|
55
|
+
struct WatchedHostState {
|
|
56
|
+
std::shared_ptr<HostState> state;
|
|
57
|
+
std::unique_ptr<AccessibilitySettingsWatcher> accessibility;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
WatchedHostState makeWatchedHostState();
|
|
61
|
+
|
|
62
|
+
} // namespace ngn::gtk
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
#include "accessible-text.h"
|
|
2
|
+
|
|
3
|
+
#include "view-widget.h"
|
|
4
|
+
|
|
5
|
+
#include "ngn/text-units.h"
|
|
6
|
+
|
|
7
|
+
#include <dlfcn.h>
|
|
8
|
+
|
|
9
|
+
#include <algorithm>
|
|
10
|
+
|
|
11
|
+
namespace ngn::gtk {
|
|
12
|
+
|
|
13
|
+
namespace {
|
|
14
|
+
|
|
15
|
+
// The text a Paragraph's widget draws, laid out as it draws it, or nothing for another widget.
|
|
16
|
+
PangoLayout *layoutOf(GtkAccessible *self) {
|
|
17
|
+
ViewData *d = viewData(GTK_WIDGET(self));
|
|
18
|
+
return d ? paragraphLayout(*d) : nullptr;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
std::string textOf(PangoLayout *layout) {
|
|
22
|
+
const char *text = layout ? pango_layout_get_text(layout) : nullptr;
|
|
23
|
+
return text ? text : "";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Where Pango breaks words, sentences and lines in the layout, in characters.
|
|
27
|
+
TextBreaks breaksOf(PangoLayout *layout) {
|
|
28
|
+
TextBreaks breaks;
|
|
29
|
+
int count = 0;
|
|
30
|
+
const PangoLogAttr *attrs = pango_layout_get_log_attrs_readonly(layout, &count);
|
|
31
|
+
for (int i = 0; i < count; i++) {
|
|
32
|
+
if (attrs[i].is_word_start) {
|
|
33
|
+
breaks.words.push_back(i);
|
|
34
|
+
}
|
|
35
|
+
if (attrs[i].is_sentence_start) {
|
|
36
|
+
breaks.sentences.push_back(i);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const char *text = pango_layout_get_text(layout);
|
|
40
|
+
for (GSList *line = pango_layout_get_lines_readonly(layout); line; line = line->next) {
|
|
41
|
+
auto *l = static_cast<PangoLayoutLine *>(line->data);
|
|
42
|
+
breaks.lines.push_back(static_cast<int>(g_utf8_pointer_to_offset(text, text + l->start_index)));
|
|
43
|
+
}
|
|
44
|
+
return breaks;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// An offset GTK gives, which may be G_MAXUINT for "to the end".
|
|
48
|
+
int offsetOf(unsigned int offset) {
|
|
49
|
+
return static_cast<int>(std::min<unsigned int>(offset, G_MAXINT));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// NUL-terminated, as GTK's own implementations return it.
|
|
53
|
+
GBytes *bytesOf(const std::string &text) {
|
|
54
|
+
return g_bytes_new(text.c_str(), text.size() + 1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
GBytes *getContents(GtkAccessible *self, unsigned int start, unsigned int end) {
|
|
58
|
+
return bytesOf(textBetween(textOf(layoutOf(self)), offsetOf(start), offsetOf(end)));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
GBytes *getContentsAt(GtkAccessible *self, unsigned int offset, int granularity, unsigned int *start, unsigned int *end) {
|
|
62
|
+
PangoLayout *layout = layoutOf(self);
|
|
63
|
+
if (!layout) {
|
|
64
|
+
*start = *end = 0;
|
|
65
|
+
return bytesOf("");
|
|
66
|
+
}
|
|
67
|
+
auto text = textOf(layout);
|
|
68
|
+
auto unit = static_cast<TextUnit>(std::clamp(granularity, 0, static_cast<int>(TextUnit::Paragraph)));
|
|
69
|
+
auto span = textUnitAt(text, breaksOf(layout), offsetOf(offset), unit);
|
|
70
|
+
*start = static_cast<unsigned int>(span.start);
|
|
71
|
+
*end = static_cast<unsigned int>(span.end);
|
|
72
|
+
return bytesOf(textBetween(text, span.start, span.end));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// GTK 4.14's default callbacks leave the name and value arrays NULL, which its AT-SPI handler then
|
|
76
|
+
// indexes, so a screen reader asking for attributes would crash the host. A Paragraph has none:
|
|
77
|
+
// empty, NULL-terminated arrays.
|
|
78
|
+
gboolean getAttributes(GtkAccessible *, unsigned int, gsize *n_ranges, gpointer *ranges, char ***names, char ***values) {
|
|
79
|
+
*n_ranges = 0;
|
|
80
|
+
*ranges = nullptr;
|
|
81
|
+
*names = g_new0(char *, 1);
|
|
82
|
+
*values = g_new0(char *, 1);
|
|
83
|
+
return FALSE;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
void getDefaultAttributes(GtkAccessible *, char ***names, char ***values) {
|
|
87
|
+
*names = g_new0(char *, 1);
|
|
88
|
+
*values = g_new0(char *, 1);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
void interfaceInit(gpointer vtable, gpointer) {
|
|
92
|
+
fillAccessibleTextInterface(static_cast<AccessibleTextInterface *>(vtable));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
AccessibleTextUpdate &testUpdate() {
|
|
96
|
+
static AccessibleTextUpdate update = nullptr;
|
|
97
|
+
return update;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// The change to tell, or nothing when there is no one to tell.
|
|
101
|
+
void tellChange(GtkWidget *widget, int change, const std::string &text) {
|
|
102
|
+
using Update = void (*)(GtkAccessible *, int, unsigned int, unsigned int);
|
|
103
|
+
static auto gtkUpdate = reinterpret_cast<Update>(dlsym(RTLD_DEFAULT, "gtk_accessible_text_update_contents"));
|
|
104
|
+
Update update = testUpdate() ? testUpdate() : gtkUpdate;
|
|
105
|
+
GType type = accessibleTextType();
|
|
106
|
+
bool has = testUpdate() || (type && widget && G_TYPE_CHECK_INSTANCE_TYPE(widget, type));
|
|
107
|
+
if (!update || !has || !widget || text.empty()) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
update(GTK_ACCESSIBLE(widget), change, 0, static_cast<unsigned int>(g_utf8_strlen(text.c_str(), -1)));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
} // namespace
|
|
114
|
+
|
|
115
|
+
void fillAccessibleTextInterface(AccessibleTextInterface *iface) {
|
|
116
|
+
iface->get_contents = getContents;
|
|
117
|
+
iface->get_contents_at = getContentsAt;
|
|
118
|
+
iface->get_attributes = getAttributes;
|
|
119
|
+
iface->get_default_attributes = getDefaultAttributes;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
GType accessibleTextType() {
|
|
123
|
+
static GType type = [] {
|
|
124
|
+
using GetType = GType (*)();
|
|
125
|
+
auto get = reinterpret_cast<GetType>(dlsym(RTLD_DEFAULT, "gtk_accessible_text_get_type"));
|
|
126
|
+
return get ? get() : GType(0);
|
|
127
|
+
}();
|
|
128
|
+
return type;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
void implementAccessibleText(GType type) {
|
|
132
|
+
if (GType text = accessibleTextType()) {
|
|
133
|
+
static const GInterfaceInfo info{interfaceInit, nullptr, nullptr};
|
|
134
|
+
g_type_add_interface_static(type, text, &info);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// GtkAccessibleTextContentChange.
|
|
139
|
+
void accessibleTextRemoved(GtkWidget *widget, const std::string &text) {
|
|
140
|
+
tellChange(widget, 1, text);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
void accessibleTextInserted(GtkWidget *widget, const std::string &text) {
|
|
144
|
+
tellChange(widget, 0, text);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
void setAccessibleTextUpdate(AccessibleTextUpdate update) {
|
|
148
|
+
testUpdate() = update;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
} // namespace ngn::gtk
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// A Paragraph's text through GTK's GtkAccessibleText, so a screen reader reads it by character,
|
|
2
|
+
// word, sentence, line and paragraph (AT-SPI's Text interface). GTK has it from 4.14, past the 4.10
|
|
3
|
+
// floor the host builds against, so the interface is found and added at run time: below 4.14 a
|
|
4
|
+
// Paragraph is read by its name alone, as before. A text input's field is GTK's own GtkText or
|
|
5
|
+
// GtkTextView, which implement it themselves from 4.14.
|
|
6
|
+
#pragma once
|
|
7
|
+
|
|
8
|
+
#include <gtk/gtk.h>
|
|
9
|
+
|
|
10
|
+
#include <string>
|
|
11
|
+
|
|
12
|
+
namespace ngn::gtk {
|
|
13
|
+
|
|
14
|
+
// GTK 4.14's GtkAccessibleTextInterface, which the headers the host builds against may lack: its
|
|
15
|
+
// first members, in their order. GTK fills the rest with its defaults.
|
|
16
|
+
struct AccessibleTextInterface {
|
|
17
|
+
GTypeInterface g_iface;
|
|
18
|
+
GBytes *(*get_contents)(GtkAccessible *self, unsigned int start, unsigned int end);
|
|
19
|
+
// `granularity` is GtkAccessibleTextGranularity: character, word, sentence, line, paragraph.
|
|
20
|
+
GBytes *(*get_contents_at)(GtkAccessible *self, unsigned int offset, int granularity, unsigned int *start, unsigned int *end);
|
|
21
|
+
unsigned int (*get_caret_position)(GtkAccessible *self);
|
|
22
|
+
gboolean (*get_selection)(GtkAccessible *self, gsize *n_ranges, gpointer *ranges);
|
|
23
|
+
gboolean (*get_attributes)(GtkAccessible *self, unsigned int offset, gsize *n_ranges, gpointer *ranges, char ***attribute_names,
|
|
24
|
+
char ***attribute_values);
|
|
25
|
+
void (*get_default_attributes)(GtkAccessible *self, char ***attribute_names, char ***attribute_values);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// GtkAccessibleText's type, or 0 below GTK 4.14.
|
|
29
|
+
GType accessibleTextType();
|
|
30
|
+
|
|
31
|
+
// Adds GtkAccessibleText to `type`, a view type whose widgets draw a Paragraph, when GTK has it.
|
|
32
|
+
void implementAccessibleText(GType type);
|
|
33
|
+
|
|
34
|
+
// Fills a GtkAccessibleText vtable with a Paragraph's callbacks.
|
|
35
|
+
void fillAccessibleTextInterface(AccessibleTextInterface *iface);
|
|
36
|
+
|
|
37
|
+
// Tells a screen reader that a Paragraph's text is going, or has come, as GTK's own labels do for a
|
|
38
|
+
// text set on them. GTK needs the removal before the contents change and the insertion after, so
|
|
39
|
+
// these are two calls around the change. Nothing below GTK 4.14, or for a widget without the
|
|
40
|
+
// interface.
|
|
41
|
+
void accessibleTextRemoved(GtkWidget *widget, const std::string &text);
|
|
42
|
+
void accessibleTextInserted(GtkWidget *widget, const std::string &text);
|
|
43
|
+
|
|
44
|
+
// gtk_accessible_text_update_contents's shape, which a test replaces to see the calls (nullptr
|
|
45
|
+
// restores GTK's). A replacement is called for any widget, whether or not GTK has the interface.
|
|
46
|
+
using AccessibleTextUpdate = void (*)(GtkAccessible *, int change, unsigned int start, unsigned int end);
|
|
47
|
+
void setAccessibleTextUpdate(AccessibleTextUpdate update);
|
|
48
|
+
|
|
49
|
+
} // namespace ngn::gtk
|