@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,299 @@
|
|
|
1
|
+
#include "input-replay.h"
|
|
2
|
+
|
|
3
|
+
#include "app-windows.h"
|
|
4
|
+
|
|
5
|
+
#include <dlfcn.h>
|
|
6
|
+
|
|
7
|
+
#include <cmath>
|
|
8
|
+
#include <cstdio>
|
|
9
|
+
#include <functional>
|
|
10
|
+
#include <memory>
|
|
11
|
+
#include <vector>
|
|
12
|
+
|
|
13
|
+
#ifdef GDK_WINDOWING_X11
|
|
14
|
+
#include <gdk/x11/gdkx.h>
|
|
15
|
+
#include <X11/XKBlib.h>
|
|
16
|
+
#include <X11/keysym.h>
|
|
17
|
+
#endif
|
|
18
|
+
|
|
19
|
+
namespace ngn::gtk {
|
|
20
|
+
|
|
21
|
+
namespace {
|
|
22
|
+
|
|
23
|
+
#ifdef GDK_WINDOWING_X11
|
|
24
|
+
|
|
25
|
+
// libXtst's calls, found at run time.
|
|
26
|
+
struct XTest {
|
|
27
|
+
int (*motion)(Display *, int screen, int x, int y, unsigned long delay){nullptr};
|
|
28
|
+
int (*button)(Display *, unsigned button, Bool press, unsigned long delay){nullptr};
|
|
29
|
+
int (*key)(Display *, unsigned keycode, Bool press, unsigned long delay){nullptr};
|
|
30
|
+
Bool (*query)(Display *, int *event, int *error, int *major, int *minor){nullptr};
|
|
31
|
+
explicit operator bool() const {
|
|
32
|
+
return motion && button && key && query;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const XTest &xtest() {
|
|
37
|
+
static XTest found = [] {
|
|
38
|
+
XTest t;
|
|
39
|
+
void *lib = dlopen("libXtst.so.6", RTLD_NOW | RTLD_LOCAL);
|
|
40
|
+
if (lib) {
|
|
41
|
+
t.motion = reinterpret_cast<decltype(t.motion)>(dlsym(lib, "XTestFakeMotionEvent"));
|
|
42
|
+
t.button = reinterpret_cast<decltype(t.button)>(dlsym(lib, "XTestFakeButtonEvent"));
|
|
43
|
+
t.key = reinterpret_cast<decltype(t.key)>(dlsym(lib, "XTestFakeKeyEvent"));
|
|
44
|
+
t.query = reinterpret_cast<decltype(t.query)>(dlsym(lib, "XTestQueryExtension"));
|
|
45
|
+
}
|
|
46
|
+
return t;
|
|
47
|
+
}();
|
|
48
|
+
return found;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
struct Replay {
|
|
52
|
+
// Cleared if the window goes before the script ends.
|
|
53
|
+
GtkWidget *window{nullptr};
|
|
54
|
+
// The window's display, kept to post to after the window goes.
|
|
55
|
+
GdkDisplay *display{nullptr};
|
|
56
|
+
InputScript script;
|
|
57
|
+
size_t at{0};
|
|
58
|
+
std::function<void()> done;
|
|
59
|
+
// Set when the window unrealizes: a destroyed window a caller still holds is not a finished script.
|
|
60
|
+
bool closed{false};
|
|
61
|
+
gulong unrealizeHandler{0};
|
|
62
|
+
// Whether the script's press of the primary button is not yet released. The X server holds a
|
|
63
|
+
// posted press for every client until its release, so a script that stops before its `up`, its
|
|
64
|
+
// window closed, releases it.
|
|
65
|
+
bool pressed{false};
|
|
66
|
+
~Replay() {
|
|
67
|
+
if (window) {
|
|
68
|
+
if (unrealizeHandler) {
|
|
69
|
+
g_signal_handler_disconnect(window, unrealizeHandler);
|
|
70
|
+
}
|
|
71
|
+
g_object_remove_weak_pointer(G_OBJECT(window), reinterpret_cast<gpointer *>(&window));
|
|
72
|
+
}
|
|
73
|
+
if (display) {
|
|
74
|
+
if (pressed && !gdk_display_is_closed(display)) {
|
|
75
|
+
Display *x = gdk_x11_display_get_xdisplay(display);
|
|
76
|
+
xtest().button(x, 1, False, 0);
|
|
77
|
+
XFlush(x);
|
|
78
|
+
}
|
|
79
|
+
g_object_unref(display);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
Display *displayOf(GtkWidget *window) {
|
|
85
|
+
return gdk_x11_display_get_xdisplay(gtk_widget_get_display(window));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// A point in the window's content, in points from its top left, on the root window in pixels.
|
|
89
|
+
std::pair<int, int> onRoot(GtkWidget *window, double x, double y) {
|
|
90
|
+
GtkNative *native = gtk_widget_get_native(window);
|
|
91
|
+
GdkSurface *surface = gtk_native_get_surface(native);
|
|
92
|
+
double tx = 0, ty = 0;
|
|
93
|
+
// The content's place in the surface, past a client-side shadow.
|
|
94
|
+
gtk_native_get_surface_transform(native, &tx, &ty);
|
|
95
|
+
int scale = gdk_surface_get_scale_factor(surface);
|
|
96
|
+
Display *display = displayOf(window);
|
|
97
|
+
Window child = 0;
|
|
98
|
+
int rx = 0, ry = 0;
|
|
99
|
+
XTranslateCoordinates(
|
|
100
|
+
display, gdk_x11_surface_get_xid(surface), DefaultRootWindow(display), static_cast<int>(std::lround((x + tx) * scale)),
|
|
101
|
+
static_cast<int>(std::lround((y + ty) * scale)), &rx, &ry, &child);
|
|
102
|
+
return {rx, ry};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
void pointerTo(GtkWidget *window, const InputStep &step) {
|
|
106
|
+
auto [x, y] = onRoot(window, step.x, step.y);
|
|
107
|
+
xtest().motion(displayOf(window), -1, x, y, 0);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// The X keysym a script's key names: a character, or escape, return, space, tab, delete or an arrow.
|
|
111
|
+
unsigned long keysymOf(const std::string &key) {
|
|
112
|
+
if (key == "left") return XK_Left;
|
|
113
|
+
if (key == "right") return XK_Right;
|
|
114
|
+
if (key == "up") return XK_Up;
|
|
115
|
+
if (key == "down") return XK_Down;
|
|
116
|
+
if (key == "escape") return XK_Escape;
|
|
117
|
+
if (key == "return") return XK_Return;
|
|
118
|
+
if (key == "space") return XK_space;
|
|
119
|
+
if (key == "tab") return XK_Tab;
|
|
120
|
+
if (key == "delete") return XK_BackSpace;
|
|
121
|
+
gunichar c = g_utf8_get_char(key.c_str());
|
|
122
|
+
return gdk_unicode_to_keyval(c);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// The key that types `keysym`, and its group and level: 0 alone, 1 with Shift, 2 with AltGr
|
|
126
|
+
// (ISO_Level3_Shift), 3 with both. One in the `active` group if any, else in the lowest group.
|
|
127
|
+
// None when no key types it.
|
|
128
|
+
std::optional<GdkKeymapKey> keyFor(GdkDisplay *display, unsigned long keysym, int active) {
|
|
129
|
+
GdkKeymapKey *keys = nullptr;
|
|
130
|
+
int count = 0;
|
|
131
|
+
std::optional<GdkKeymapKey> best;
|
|
132
|
+
auto rank = [active](const GdkKeymapKey &k) { return std::make_pair(k.group == active ? -1 : k.group, k.level); };
|
|
133
|
+
if (gdk_display_map_keyval(display, static_cast<guint>(keysym), &keys, &count)) {
|
|
134
|
+
for (int i = 0; i < count; ++i) {
|
|
135
|
+
if (keys[i].level < 4 && (!best || rank(keys[i]) < rank(*best))) {
|
|
136
|
+
best = keys[i];
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
g_free(keys);
|
|
140
|
+
}
|
|
141
|
+
return best;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// A key down and up, in the group and at the level that types it, with the script's modifiers held
|
|
145
|
+
// too: command is Linux's primary modifier, Ctrl. A key in another group than the active one is
|
|
146
|
+
// posted with its group locked, and the keyboard's group put back after.
|
|
147
|
+
void pressKey(GdkDisplay *gdkDisplay, unsigned long keysym, unsigned modifiers) {
|
|
148
|
+
Display *display = gdk_x11_display_get_xdisplay(gdkDisplay);
|
|
149
|
+
XkbStateRec state{};
|
|
150
|
+
XkbGetState(display, XkbUseCoreKbd, &state);
|
|
151
|
+
auto key = keyFor(gdkDisplay, keysym, state.group);
|
|
152
|
+
unsigned level3 = key && key->level >= 2 ? XKeysymToKeycode(display, XK_ISO_Level3_Shift) : 0;
|
|
153
|
+
if (!key || (key->level >= 2 && level3 == 0)) {
|
|
154
|
+
fprintf(stderr, "[ngn] input script: no key for keysym 0x%lx\n", keysym);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
std::vector<unsigned> held;
|
|
158
|
+
if (modifiers & (InputStep::Command | InputStep::Control)) held.push_back(XKeysymToKeycode(display, XK_Control_L));
|
|
159
|
+
if (modifiers & InputStep::Option) held.push_back(XKeysymToKeycode(display, XK_Alt_L));
|
|
160
|
+
if ((modifiers & InputStep::Shift) || (key->level & 1)) held.push_back(XKeysymToKeycode(display, XK_Shift_L));
|
|
161
|
+
if (level3) held.push_back(level3);
|
|
162
|
+
bool otherGroup = key->group != state.group;
|
|
163
|
+
if (otherGroup) XkbLockGroup(display, XkbUseCoreKbd, static_cast<unsigned>(key->group));
|
|
164
|
+
for (unsigned m : held) xtest().key(display, m, True, 0);
|
|
165
|
+
xtest().key(display, key->keycode, True, 0);
|
|
166
|
+
xtest().key(display, key->keycode, False, 0);
|
|
167
|
+
for (auto m = held.rbegin(); m != held.rend(); ++m) xtest().key(display, *m, False, 0);
|
|
168
|
+
if (otherGroup) XkbLockGroup(display, XkbUseCoreKbd, state.locked_group);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
void play(Replay &replay, const InputStep &step) {
|
|
172
|
+
GtkWidget *window = replay.window;
|
|
173
|
+
Display *display = displayOf(window);
|
|
174
|
+
switch (step.kind) {
|
|
175
|
+
case InputStep::Kind::Move:
|
|
176
|
+
case InputStep::Kind::Drag:
|
|
177
|
+
pointerTo(window, step);
|
|
178
|
+
break;
|
|
179
|
+
case InputStep::Kind::Down:
|
|
180
|
+
pointerTo(window, step);
|
|
181
|
+
xtest().button(display, 1, True, 0);
|
|
182
|
+
replay.pressed = true;
|
|
183
|
+
break;
|
|
184
|
+
case InputStep::Kind::Up:
|
|
185
|
+
pointerTo(window, step);
|
|
186
|
+
xtest().button(display, 1, False, 0);
|
|
187
|
+
replay.pressed = false;
|
|
188
|
+
break;
|
|
189
|
+
case InputStep::Kind::Secondary:
|
|
190
|
+
pointerTo(window, step);
|
|
191
|
+
xtest().button(display, 3, True, 0);
|
|
192
|
+
xtest().button(display, 3, False, 0);
|
|
193
|
+
break;
|
|
194
|
+
case InputStep::Kind::Key:
|
|
195
|
+
pressKey(gtk_widget_get_display(window), keysymOf(step.key), step.modifiers);
|
|
196
|
+
break;
|
|
197
|
+
case InputStep::Kind::Type: {
|
|
198
|
+
for (const char *p = step.key.c_str(); *p; p = g_utf8_next_char(p)) {
|
|
199
|
+
pressKey(gtk_widget_get_display(window), gdk_unicode_to_keyval(g_utf8_get_char(p)), 0);
|
|
200
|
+
}
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
default:
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
XFlush(display);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Plays from `replay->at`: a wait waits, and every other step leaves the loop a moment to take
|
|
210
|
+
// the event before the next, as a person's input arrives.
|
|
211
|
+
void playNext(std::shared_ptr<Replay> replay) {
|
|
212
|
+
// A destroyed window that another reference keeps is unrealized, with no surface to post to; one
|
|
213
|
+
// unrealized since the script began is closed even if something realizes it again.
|
|
214
|
+
if (!replay->window || replay->closed || !gtk_widget_get_realized(replay->window)) {
|
|
215
|
+
fprintf(stderr, "[ngn] input script: the window closed before the script ended\n");
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (replay->at >= replay->script.steps.size()) {
|
|
219
|
+
fprintf(stderr, "[ngn] input script done\n");
|
|
220
|
+
if (replay->done) {
|
|
221
|
+
replay->done();
|
|
222
|
+
}
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const auto &step = replay->script.steps[replay->at++];
|
|
226
|
+
if (step.kind == InputStep::Kind::Wait) {
|
|
227
|
+
runAfter(step.amount / 1000, [replay] { playNext(replay); });
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
play(*replay, step);
|
|
231
|
+
runAfter(0.03, [replay] { playNext(replay); });
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
#endif
|
|
235
|
+
|
|
236
|
+
} // namespace
|
|
237
|
+
|
|
238
|
+
std::optional<std::string> inputReplayProblem(GtkWidget *window, const InputScript &script) {
|
|
239
|
+
if (script.error) {
|
|
240
|
+
return *script.error;
|
|
241
|
+
}
|
|
242
|
+
for (const auto &step : script.steps) {
|
|
243
|
+
switch (step.kind) {
|
|
244
|
+
case InputStep::Kind::Scroll:
|
|
245
|
+
case InputStep::Kind::Magnify:
|
|
246
|
+
case InputStep::Kind::Rotate:
|
|
247
|
+
case InputStep::Kind::Choose:
|
|
248
|
+
return "scroll, magnify, rotate and choose are not played on Linux";
|
|
249
|
+
default:
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
#ifdef GDK_WINDOWING_X11
|
|
254
|
+
if (!window || !GDK_IS_X11_DISPLAY(gtk_widget_get_display(window))) {
|
|
255
|
+
return "an input script plays under X11 only";
|
|
256
|
+
}
|
|
257
|
+
return xtestProblem(displayOf(window));
|
|
258
|
+
#else
|
|
259
|
+
return "an input script plays under X11 only";
|
|
260
|
+
#endif
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
#ifdef GDK_WINDOWING_X11
|
|
264
|
+
std::optional<std::string> xtestProblem(Display *display) {
|
|
265
|
+
if (!xtest()) {
|
|
266
|
+
return "libXtst.so.6 is not installed";
|
|
267
|
+
}
|
|
268
|
+
// Without the extension on the server, the library's calls post nothing and report no error.
|
|
269
|
+
int event = 0, error = 0, major = 0, minor = 0;
|
|
270
|
+
if (!xtest().query(display, &event, &error, &major, &minor)) {
|
|
271
|
+
return "the X server has no XTEST extension";
|
|
272
|
+
}
|
|
273
|
+
return std::nullopt;
|
|
274
|
+
}
|
|
275
|
+
#endif
|
|
276
|
+
|
|
277
|
+
bool replayInputScript(GtkWidget *window, InputScript script, std::function<void()> done) {
|
|
278
|
+
if (auto problem = inputReplayProblem(window, script)) {
|
|
279
|
+
fprintf(stderr, "[ngn] input script: %s\n", problem->c_str());
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
#ifdef GDK_WINDOWING_X11
|
|
283
|
+
auto replay = std::make_shared<Replay>();
|
|
284
|
+
replay->window = window;
|
|
285
|
+
replay->display = GDK_DISPLAY(g_object_ref(gtk_widget_get_display(window)));
|
|
286
|
+
replay->script = std::move(script);
|
|
287
|
+
replay->done = std::move(done);
|
|
288
|
+
g_object_add_weak_pointer(G_OBJECT(window), reinterpret_cast<gpointer *>(&replay->window));
|
|
289
|
+
replay->unrealizeHandler = g_signal_connect(window, "unrealize", G_CALLBACK(+[](GtkWidget *, gpointer data) {
|
|
290
|
+
static_cast<Replay *>(data)->closed = true;
|
|
291
|
+
}), replay.get());
|
|
292
|
+
playNext(std::move(replay));
|
|
293
|
+
return true;
|
|
294
|
+
#else
|
|
295
|
+
return false;
|
|
296
|
+
#endif
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
} // namespace ngn::gtk
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// A dev or test run's input script (ngn/input-script.h) on GTK. GDK has no public way to make an
|
|
2
|
+
// event, so under X11 each step is posted to the X server through the XTest extension, at the
|
|
3
|
+
// window's own points: it reaches GTK as a person's input would, native controls included.
|
|
4
|
+
// libXtst is opened at run time, so a host without it, or one under Wayland, plays nothing and
|
|
5
|
+
// says why. The pointer steps (move, down, drag, up, secondary), key and type play; scroll,
|
|
6
|
+
// magnify, rotate and choose are AppKit's and are refused when the script is read.
|
|
7
|
+
#pragma once
|
|
8
|
+
|
|
9
|
+
#include "ngn/input-script.h"
|
|
10
|
+
|
|
11
|
+
#include <gtk/gtk.h>
|
|
12
|
+
|
|
13
|
+
#include <functional>
|
|
14
|
+
#include <optional>
|
|
15
|
+
#include <string>
|
|
16
|
+
|
|
17
|
+
// Xlib's Display, without its header.
|
|
18
|
+
struct _XDisplay;
|
|
19
|
+
|
|
20
|
+
namespace ngn::gtk {
|
|
21
|
+
|
|
22
|
+
// Why the script cannot play here, or nothing when it can.
|
|
23
|
+
std::optional<std::string> inputReplayProblem(GtkWidget *window, const InputScript &script);
|
|
24
|
+
|
|
25
|
+
#ifdef GDK_WINDOWING_X11
|
|
26
|
+
// Why XTest cannot post to this X connection: libXtst missing, or the server without the extension.
|
|
27
|
+
std::optional<std::string> xtestProblem(_XDisplay *display);
|
|
28
|
+
#endif
|
|
29
|
+
|
|
30
|
+
// Plays the script into `window` from now, a step at a time on the main loop, and logs
|
|
31
|
+
// "[ngn] input script done" after the last, then calls `done`, which a script whose window
|
|
32
|
+
// closes first never reaches. A press the script has not released when it stops, done or its window
|
|
33
|
+
// closed, is released then. False, having logged why, when it cannot play.
|
|
34
|
+
bool replayInputScript(GtkWidget *window, InputScript script, std::function<void()> done = {});
|
|
35
|
+
|
|
36
|
+
} // namespace ngn::gtk
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#include "launcher-badge.h"
|
|
2
|
+
|
|
3
|
+
#include <gio/gio.h>
|
|
4
|
+
|
|
5
|
+
namespace ngn::gtk {
|
|
6
|
+
|
|
7
|
+
std::string launcherEntryUri(const std::string &appId) {
|
|
8
|
+
return "application://" + appId + ".desktop";
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
std::function<void(int)> makeLauncherBadge(const std::string &appId) {
|
|
12
|
+
return [uri = launcherEntryUri(appId)](int count) {
|
|
13
|
+
GDBusConnection *bus = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr);
|
|
14
|
+
if (!bus) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
GVariantBuilder props;
|
|
18
|
+
g_variant_builder_init(&props, G_VARIANT_TYPE("a{sv}"));
|
|
19
|
+
g_variant_builder_add(&props, "{sv}", "count", g_variant_new_int64(count > 0 ? count : 0));
|
|
20
|
+
g_variant_builder_add(&props, "{sv}", "count-visible", g_variant_new_boolean(count > 0));
|
|
21
|
+
g_dbus_connection_emit_signal(
|
|
22
|
+
bus, nullptr, "/com/canonical/unity/launcherentry", kLauncherEntryInterface, "Update",
|
|
23
|
+
g_variant_new("(sa{sv})", uri.c_str(), &props), nullptr);
|
|
24
|
+
g_dbus_connection_flush_sync(bus, nullptr, nullptr);
|
|
25
|
+
g_object_unref(bus);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
} // namespace ngn::gtk
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// The Notifications badge on Linux: the count goes out as the com.canonical.Unity.LauncherEntry
|
|
2
|
+
// `Update` signal for the app's desktop entry, `application://<app id>.desktop`, best effort. KDE
|
|
3
|
+
// Plasma's task manager and Ubuntu's dock show it; stock GNOME shows nothing. It is the
|
|
4
|
+
// `showBadge` the notification centre (notifications.h) takes.
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include <functional>
|
|
8
|
+
#include <string>
|
|
9
|
+
|
|
10
|
+
namespace ngn::gtk {
|
|
11
|
+
|
|
12
|
+
inline constexpr const char *kLauncherEntryInterface = "com.canonical.Unity.LauncherEntry";
|
|
13
|
+
|
|
14
|
+
// The desktop entry the signal names.
|
|
15
|
+
std::string launcherEntryUri(const std::string &appId);
|
|
16
|
+
|
|
17
|
+
// Sends the count each time it is called, so a dock that starts later hears the next one: no dock
|
|
18
|
+
// asks for it.
|
|
19
|
+
std::function<void(int count)> makeLauncherBadge(const std::string &appId);
|
|
20
|
+
|
|
21
|
+
} // namespace ngn::gtk
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
#include "locales.h"
|
|
2
|
+
|
|
3
|
+
#include "ngn/posix-locale.h"
|
|
4
|
+
|
|
5
|
+
#include <glib.h>
|
|
6
|
+
|
|
7
|
+
#include <langinfo.h>
|
|
8
|
+
#include <locale.h>
|
|
9
|
+
|
|
10
|
+
#include <cstdint>
|
|
11
|
+
#include <cstdlib>
|
|
12
|
+
#include <functional>
|
|
13
|
+
|
|
14
|
+
namespace ngn::gtk {
|
|
15
|
+
|
|
16
|
+
namespace {
|
|
17
|
+
|
|
18
|
+
std::string env(const char *name) {
|
|
19
|
+
const char *value = getenv(name);
|
|
20
|
+
return value ? value : "";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Reads `read` in the locale `category` is set to, through the C library's locale data; nothing
|
|
24
|
+
// where the system has no data for it (a container with only C.UTF-8) or no glibc to ask.
|
|
25
|
+
template <typename T>
|
|
26
|
+
std::optional<T> inLocale(const char *category, int mask, const std::function<T(locale_t)> &read) {
|
|
27
|
+
#ifdef __GLIBC__
|
|
28
|
+
std::string name = localeOf(category);
|
|
29
|
+
if (!languageTagOf(name)) {
|
|
30
|
+
return std::nullopt;
|
|
31
|
+
}
|
|
32
|
+
locale_t locale = newlocale(mask, name.c_str(), static_cast<locale_t>(0));
|
|
33
|
+
if (locale == static_cast<locale_t>(0)) {
|
|
34
|
+
return std::nullopt;
|
|
35
|
+
}
|
|
36
|
+
T value = read(locale);
|
|
37
|
+
freelocale(locale);
|
|
38
|
+
return value;
|
|
39
|
+
#else
|
|
40
|
+
return std::nullopt;
|
|
41
|
+
#endif
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
[[maybe_unused]] std::string trimmed(std::string text) {
|
|
45
|
+
auto last = text.find_last_not_of(' ');
|
|
46
|
+
return last == std::string::npos ? "" : text.substr(0, last + 1);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// GLib's name for the local zone ("Europe/London"), without a leading colon or zoneinfo path.
|
|
50
|
+
std::string localTimeZone() {
|
|
51
|
+
GTimeZone *zone = g_time_zone_new_local();
|
|
52
|
+
std::string name = g_time_zone_get_identifier(zone);
|
|
53
|
+
g_time_zone_unref(zone);
|
|
54
|
+
if (!name.empty() && name[0] == ':') {
|
|
55
|
+
name.erase(0, 1);
|
|
56
|
+
}
|
|
57
|
+
if (auto at = name.find("zoneinfo/"); at != std::string::npos) {
|
|
58
|
+
name.erase(0, at + 9);
|
|
59
|
+
}
|
|
60
|
+
return name;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
class GlibcLocales final : public LocaleSource {
|
|
64
|
+
public:
|
|
65
|
+
std::vector<LocaleFacts> locales() override {
|
|
66
|
+
std::string region = systemRegionCode();
|
|
67
|
+
LocaleFacts formats{.measurementSystem = measurementSystemOf(1, region), .temperatureUnit = temperatureUnitOf(region)};
|
|
68
|
+
#ifdef __GLIBC__
|
|
69
|
+
if (auto numbers = inLocale<std::pair<std::string, std::string>>("LC_NUMERIC", LC_NUMERIC_MASK, [](locale_t l) {
|
|
70
|
+
return std::make_pair(std::string(nl_langinfo_l(RADIXCHAR, l)), std::string(nl_langinfo_l(THOUSEP, l)));
|
|
71
|
+
})) {
|
|
72
|
+
formats.decimalSeparator = numbers->first;
|
|
73
|
+
formats.groupingSeparator = numbers->second;
|
|
74
|
+
}
|
|
75
|
+
if (auto money = inLocale<std::pair<std::string, std::string>>("LC_MONETARY", LC_MONETARY_MASK, [](locale_t l) {
|
|
76
|
+
return std::make_pair(trimmed(nl_langinfo_l(INT_CURR_SYMBOL, l)), std::string(nl_langinfo_l(CURRENCY_SYMBOL, l)));
|
|
77
|
+
})) {
|
|
78
|
+
formats.currencyCode = money->first;
|
|
79
|
+
formats.currencySymbol = money->second;
|
|
80
|
+
}
|
|
81
|
+
if (auto measurement = inLocale<int>("LC_MEASUREMENT", LC_MEASUREMENT_MASK, [](locale_t l) {
|
|
82
|
+
return static_cast<int>(nl_langinfo_l(_NL_MEASUREMENT_MEASUREMENT, l)[0]);
|
|
83
|
+
})) {
|
|
84
|
+
formats.measurementSystem = measurementSystemOf(*measurement, region);
|
|
85
|
+
}
|
|
86
|
+
#endif
|
|
87
|
+
std::vector<LocaleFacts> out;
|
|
88
|
+
for (const auto &tag : preferredLanguageTags(env("LANGUAGE"), localeOf("LC_MESSAGES"))) {
|
|
89
|
+
auto facts = formats;
|
|
90
|
+
facts.languageTag = tag;
|
|
91
|
+
facts.rightToLeft = rightToLeftLanguage(tag);
|
|
92
|
+
out.push_back(std::move(facts));
|
|
93
|
+
}
|
|
94
|
+
return out;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
CalendarFacts calendars() override {
|
|
98
|
+
CalendarFacts facts{.calendar = "gregorian", .timeZone = localTimeZone()};
|
|
99
|
+
#ifdef __GLIBC__
|
|
100
|
+
if (auto time = inLocale<std::pair<bool, int>>("LC_TIME", LC_TIME_MASK, [](locale_t l) {
|
|
101
|
+
auto weekStart = static_cast<unsigned>(reinterpret_cast<uintptr_t>(nl_langinfo_l(_NL_TIME_WEEK_1STDAY, l)));
|
|
102
|
+
return std::make_pair(uses24HourClockIn(nl_langinfo_l(T_FMT, l)), firstWeekdayOf(weekStart, nl_langinfo_l(_NL_TIME_FIRST_WEEKDAY, l)[0]));
|
|
103
|
+
})) {
|
|
104
|
+
facts.uses24hourClock = time->first;
|
|
105
|
+
facts.firstWeekday = time->second;
|
|
106
|
+
}
|
|
107
|
+
#endif
|
|
108
|
+
return facts;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
} // namespace
|
|
113
|
+
|
|
114
|
+
std::string localeOf(const char *category) {
|
|
115
|
+
for (const char *name : {"LC_ALL", category, "LANG"}) {
|
|
116
|
+
if (auto value = env(name); !value.empty()) {
|
|
117
|
+
return value;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return "";
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
std::shared_ptr<LocaleSource> makeLocaleSource() {
|
|
124
|
+
return std::make_shared<GlibcLocales>();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
std::string systemRegionCode() {
|
|
128
|
+
return regionOfLocale(localeOf("LC_MONETARY"));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
} // namespace ngn::gtk
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// The OS half of NgNativeLocalization on Linux (the core's desktop-expo.h): the user's languages
|
|
2
|
+
// from LANGUAGE and the messages locale, and the formats from the C library's locale data for the
|
|
3
|
+
// locale each category names (LC_NUMERIC, LC_MONETARY, LC_MEASUREMENT, LC_TIME), as GNOME's and
|
|
4
|
+
// KDE's Formats settings set them. The time zone is GLib's local one.
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include "ngn/desktop-expo.h"
|
|
8
|
+
|
|
9
|
+
#include <memory>
|
|
10
|
+
#include <string>
|
|
11
|
+
|
|
12
|
+
namespace ngn::gtk {
|
|
13
|
+
|
|
14
|
+
// The locale a category is set to (`LC_TIME`, say): LC_ALL, then the category's own variable,
|
|
15
|
+
// then LANG, as the C library reads them. Empty when none is set.
|
|
16
|
+
std::string localeOf(const char *category);
|
|
17
|
+
|
|
18
|
+
std::shared_ptr<LocaleSource> makeLocaleSource();
|
|
19
|
+
|
|
20
|
+
// The region the formats are set to (LC_MONETARY's locale, "GB"), or empty.
|
|
21
|
+
std::string systemRegionCode();
|
|
22
|
+
|
|
23
|
+
} // namespace ngn::gtk
|