@ng-native/desktop 0.26.1 → 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.
Files changed (256) hide show
  1. package/README.md +6 -3
  2. package/bin/app-config.mjs +1 -0
  3. package/bin/archive.mjs +166 -0
  4. package/bin/autolink.mjs +61 -30
  5. package/bin/cli.mjs +127 -27
  6. package/bin/host.mjs +255 -58
  7. package/bin/package-linux.mjs +1394 -0
  8. package/bin/package.mjs +171 -35
  9. package/bin/plist.mjs +6 -2
  10. package/bin/png-icon.mjs +315 -0
  11. package/bin/prebuilt.mjs +147 -26
  12. package/bin/toolchain.mjs +258 -19
  13. package/native/CMakeLists.txt +64 -6
  14. package/native/appkit/CMakeLists.txt +2 -1
  15. package/native/appkit/appkit-backend.h +1 -0
  16. package/native/appkit/appkit-backend.mm +13 -0
  17. package/native/appkit/header-toolbar.mm +28 -25
  18. package/native/appkit/host-view.h +10 -0
  19. package/native/appkit/host-view.mm +146 -40
  20. package/native/appkit/input-replay.h +6 -0
  21. package/native/appkit/input-replay.mm +21 -12
  22. package/native/appkit/main.mm +11 -7
  23. package/native/appkit/native-controls.mm +13 -1
  24. package/native/appkit/split-view.mm +7 -13
  25. package/native/appkit/text-input-field.h +4 -0
  26. package/native/appkit/text-input-field.mm +20 -1
  27. package/native/cmake/curl.cmake +79 -0
  28. package/native/cmake/libraries/react-native-reanimated.cmake +5 -0
  29. package/native/cmake/libraries/react-native-worklets.cmake +5 -0
  30. package/native/cmake/linked-modules.cmake +20 -4
  31. package/native/cmake/react-native.cmake +18 -1
  32. package/native/core/include/ngn/accent-colors.h +38 -0
  33. package/native/core/include/ngn/accessibility-relations.h +65 -0
  34. package/native/core/include/ngn/accessibility.h +26 -0
  35. package/native/core/include/ngn/animated-frame-loop.h +56 -0
  36. package/native/core/include/ngn/app-info.h +24 -8
  37. package/native/core/include/ngn/app-menus.h +14 -1
  38. package/native/core/include/ngn/app-windows.h +15 -2
  39. package/native/core/include/ngn/aria-role.h +96 -0
  40. package/native/core/include/ngn/audio.h +2 -0
  41. package/native/core/include/ngn/camera.h +9 -0
  42. package/native/core/include/ngn/control-sizes.h +7 -2
  43. package/native/core/include/ngn/crash-report.h +31 -0
  44. package/native/core/include/ngn/curl-network.h +93 -0
  45. package/native/core/include/ngn/dbus-menu.h +39 -0
  46. package/native/core/include/ngn/default-menu.h +36 -0
  47. package/native/core/include/ngn/desktop-expo.h +7 -1
  48. package/native/core/include/ngn/desktop-modules.h +22 -0
  49. package/native/core/include/ngn/desktop-props.h +21 -1
  50. package/native/core/include/ngn/desktop-view-props.h +6 -0
  51. package/native/core/include/ngn/focus-order.h +10 -0
  52. package/native/core/include/ngn/header-bar.h +22 -0
  53. package/native/core/include/ngn/host-os.h +6 -0
  54. package/native/core/include/ngn/host-reload.h +21 -0
  55. package/native/core/include/ngn/host-state.h +23 -0
  56. package/native/core/include/ngn/image-source.h +26 -1
  57. package/native/core/include/ngn/input-script.h +3 -3
  58. package/native/core/include/ngn/input.h +4 -1
  59. package/native/core/include/ngn/launch-frame.h +21 -0
  60. package/native/core/include/ngn/launch-settings.h +23 -5
  61. package/native/core/include/ngn/mounting-backend.h +5 -0
  62. package/native/core/include/ngn/mounting-manager.h +1 -0
  63. package/native/core/include/ngn/native-controls.h +26 -5
  64. package/native/core/include/ngn/notification-schedule.h +74 -0
  65. package/native/core/include/ngn/notifications.h +2 -1
  66. package/native/core/include/ngn/openssl-update-crypto.h +15 -0
  67. package/native/core/include/ngn/photo-library.h +60 -20
  68. package/native/core/include/ngn/posix-locale.h +43 -0
  69. package/native/core/include/ngn/runtime.h +5 -0
  70. package/native/core/include/ngn/safe-areas.h +14 -2
  71. package/native/core/include/ngn/split-view.h +78 -0
  72. package/native/core/include/ngn/surface-metrics.h +7 -0
  73. package/native/core/include/ngn/system.h +14 -0
  74. package/native/core/include/ngn/text-input.h +13 -0
  75. package/native/core/include/ngn/text-units.h +38 -0
  76. package/native/core/include/ngn/updates.h +14 -2
  77. package/native/core/include/ngn/view-box.h +40 -0
  78. package/native/core/include/ngn/view-transform.h +15 -0
  79. package/native/core/include/ngn/web-browser.h +46 -0
  80. package/native/core/src/accent-colors.cpp +88 -0
  81. package/native/core/src/accessibility-relations.cpp +138 -0
  82. package/native/core/src/accessibility.cpp +50 -0
  83. package/native/core/src/animated-frame-loop.cpp +166 -0
  84. package/native/core/src/app-menus.cpp +26 -9
  85. package/native/core/src/app-windows.cpp +27 -6
  86. package/native/core/src/aria-role.cpp +127 -0
  87. package/native/core/src/control-sizes.cpp +9 -5
  88. package/native/core/src/crash-report.cpp +196 -0
  89. package/native/core/src/curl-network.cpp +1562 -0
  90. package/native/core/src/dbus-menu.cpp +71 -0
  91. package/native/core/src/default-menu.cpp +134 -0
  92. package/native/core/src/desktop-view-props.cpp +14 -0
  93. package/native/core/src/focus-order.cpp +19 -0
  94. package/native/core/src/header-bar.cpp +20 -0
  95. package/native/core/src/host-os.cpp +19 -0
  96. package/native/core/src/host-reload.cpp +45 -0
  97. package/native/core/src/host-state.cpp +8 -0
  98. package/native/core/src/image-source.cpp +90 -0
  99. package/native/core/src/input-dispatcher.cpp +27 -5
  100. package/native/core/src/input-script.cpp +3 -2
  101. package/native/core/src/launch-settings.cpp +76 -0
  102. package/native/core/src/libraries/react-native-reanimated.cpp +6 -1
  103. package/native/core/src/modules/app-info.cpp +55 -6
  104. package/native/core/src/modules/app-modules.cpp +1 -1
  105. package/native/core/src/modules/audio.cpp +4 -2
  106. package/native/core/src/modules/camera.cpp +8 -11
  107. package/native/core/src/modules/desktop-expo.cpp +10 -5
  108. package/native/core/src/modules/desktop-modules.cpp +106 -41
  109. package/native/core/src/modules/file-photo-picker.cpp +408 -0
  110. package/native/core/src/modules/notifications.cpp +13 -17
  111. package/native/core/src/modules/photo-library.cpp +42 -13
  112. package/native/core/src/modules/web-browser.cpp +89 -0
  113. package/native/core/src/mounting-manager.cpp +12 -0
  114. package/native/core/src/native-controls.cpp +42 -1
  115. package/native/core/src/notification-schedule.cpp +429 -0
  116. package/native/core/src/openssl-update-crypto.cpp +83 -0
  117. package/native/core/src/posix-locale.cpp +192 -0
  118. package/native/core/src/runtime.cpp +30 -1
  119. package/native/core/src/safe-areas.cpp +19 -4
  120. package/native/core/src/spawn-rules.cpp +4 -1
  121. package/native/core/src/split-view.cpp +93 -0
  122. package/native/core/src/system.cpp +19 -0
  123. package/native/core/src/text-input.cpp +18 -1
  124. package/native/core/src/text-units.cpp +99 -0
  125. package/native/core/src/updates.cpp +76 -17
  126. package/native/core/src/view-box.cpp +75 -40
  127. package/native/core/src/view-transform.cpp +28 -0
  128. package/native/docker/Dockerfile +38 -0
  129. package/native/docker/Dockerfile.fedora +36 -0
  130. package/native/docker/glibc-floor.sh +49 -0
  131. package/native/gtk/CMakeLists.txt +137 -0
  132. package/native/gtk/accent-colour.cpp +57 -0
  133. package/native/gtk/accent-colour.h +41 -0
  134. package/native/gtk/accessibility-settings.cpp +159 -0
  135. package/native/gtk/accessibility-settings.h +62 -0
  136. package/native/gtk/accessible-text.cpp +151 -0
  137. package/native/gtk/accessible-text.h +49 -0
  138. package/native/gtk/accessible.cpp +306 -0
  139. package/native/gtk/accessible.h +75 -0
  140. package/native/gtk/alerts.cpp +267 -0
  141. package/native/gtk/alerts.h +30 -0
  142. package/native/gtk/animation-frames.cpp +159 -0
  143. package/native/gtk/animation-frames.h +20 -0
  144. package/native/gtk/app-info.cpp +91 -0
  145. package/native/gtk/app-info.h +25 -0
  146. package/native/gtk/app-windows.cpp +439 -0
  147. package/native/gtk/app-windows.h +150 -0
  148. package/native/gtk/audio.cpp +370 -0
  149. package/native/gtk/audio.h +54 -0
  150. package/native/gtk/auth-session.cpp +73 -0
  151. package/native/gtk/auth-session.h +16 -0
  152. package/native/gtk/battery.cpp +110 -0
  153. package/native/gtk/battery.h +19 -0
  154. package/native/gtk/box-paint.cpp +262 -0
  155. package/native/gtk/box-paint.h +32 -0
  156. package/native/gtk/cairo-canvas.cpp +755 -0
  157. package/native/gtk/cairo-canvas.h +49 -0
  158. package/native/gtk/camera.cpp +909 -0
  159. package/native/gtk/camera.h +69 -0
  160. package/native/gtk/capture.cpp +46 -0
  161. package/native/gtk/capture.h +19 -0
  162. package/native/gtk/clock-format.cpp +151 -0
  163. package/native/gtk/clock-format.h +36 -0
  164. package/native/gtk/crypto.cpp +75 -0
  165. package/native/gtk/crypto.h +14 -0
  166. package/native/gtk/dbus-properties.cpp +131 -0
  167. package/native/gtk/dbus-properties.h +61 -0
  168. package/native/gtk/drag-and-drop.cpp +339 -0
  169. package/native/gtk/drag-and-drop.h +30 -0
  170. package/native/gtk/file-dialogs.cpp +239 -0
  171. package/native/gtk/file-dialogs.h +21 -0
  172. package/native/gtk/file-system.cpp +212 -0
  173. package/native/gtk/file-system.h +25 -0
  174. package/native/gtk/focus.cpp +282 -0
  175. package/native/gtk/focus.h +37 -0
  176. package/native/gtk/fonts.cpp +89 -0
  177. package/native/gtk/fonts.h +22 -0
  178. package/native/gtk/gst-frames.cpp +150 -0
  179. package/native/gtk/gst-frames.h +47 -0
  180. package/native/gtk/gst-playback.cpp +496 -0
  181. package/native/gtk/gst-playback.h +81 -0
  182. package/native/gtk/gtk-backend.cpp +690 -0
  183. package/native/gtk/gtk-backend.h +134 -0
  184. package/native/gtk/host-sources.cpp +354 -0
  185. package/native/gtk/host-sources.h +46 -0
  186. package/native/gtk/image-manipulator.cpp +254 -0
  187. package/native/gtk/image-manipulator.h +30 -0
  188. package/native/gtk/image-view.cpp +256 -0
  189. package/native/gtk/image-view.h +54 -0
  190. package/native/gtk/input-replay.cpp +299 -0
  191. package/native/gtk/input-replay.h +36 -0
  192. package/native/gtk/launcher-badge.cpp +29 -0
  193. package/native/gtk/launcher-badge.h +21 -0
  194. package/native/gtk/locales.cpp +131 -0
  195. package/native/gtk/locales.h +23 -0
  196. package/native/gtk/location.cpp +274 -0
  197. package/native/gtk/location.h +19 -0
  198. package/native/gtk/main.cpp +1092 -0
  199. package/native/gtk/menus.cpp +447 -0
  200. package/native/gtk/menus.h +100 -0
  201. package/native/gtk/native-controls.cpp +831 -0
  202. package/native/gtk/native-controls.h +58 -0
  203. package/native/gtk/network-state.cpp +72 -0
  204. package/native/gtk/network-state.h +24 -0
  205. package/native/gtk/notifications.cpp +235 -0
  206. package/native/gtk/notifications.h +30 -0
  207. package/native/gtk/pango-text.cpp +274 -0
  208. package/native/gtk/pango-text.h +73 -0
  209. package/native/gtk/portal.cpp +451 -0
  210. package/native/gtk/portal.h +71 -0
  211. package/native/gtk/printing.cpp +338 -0
  212. package/native/gtk/printing.h +34 -0
  213. package/native/gtk/proxy-resolver.cpp +74 -0
  214. package/native/gtk/proxy-resolver.h +20 -0
  215. package/native/gtk/screens.cpp +1461 -0
  216. package/native/gtk/screens.h +274 -0
  217. package/native/gtk/scroll-view.cpp +414 -0
  218. package/native/gtk/scroll-view.h +82 -0
  219. package/native/gtk/secret-store.cpp +120 -0
  220. package/native/gtk/secret-store.h +27 -0
  221. package/native/gtk/settings-portal.cpp +129 -0
  222. package/native/gtk/settings-portal.h +47 -0
  223. package/native/gtk/split-view.cpp +1105 -0
  224. package/native/gtk/split-view.h +195 -0
  225. package/native/gtk/status-notifier.cpp +487 -0
  226. package/native/gtk/status-notifier.h +43 -0
  227. package/native/gtk/surface-input.cpp +251 -0
  228. package/native/gtk/surface-input.h +57 -0
  229. package/native/gtk/system-access.cpp +295 -0
  230. package/native/gtk/system-access.h +37 -0
  231. package/native/gtk/text-field.cpp +827 -0
  232. package/native/gtk/text-field.h +78 -0
  233. package/native/gtk/video.cpp +527 -0
  234. package/native/gtk/video.h +47 -0
  235. package/native/gtk/view-widget.cpp +431 -0
  236. package/native/gtk/view-widget.h +105 -0
  237. package/native/gtk/window-scale.cpp +95 -0
  238. package/native/gtk/window-scale.h +35 -0
  239. package/native/scripts/atspi-check.py +310 -0
  240. package/native/scripts/atspi-check.test.py +48 -0
  241. package/native/scripts/build.sh +20 -3
  242. package/native/scripts/compilers.sh +17 -0
  243. package/native/scripts/deb-depends-check.sh +22 -0
  244. package/native/scripts/fetch.sh +23 -2
  245. package/native/scripts/launch-cell.sh +157 -0
  246. package/native/scripts/launch-probe.sh +14 -3
  247. package/native/scripts/make-prebuilt.mjs +133 -44
  248. package/native/scripts/prebuilt-host-cache.mjs +71 -40
  249. package/native/scripts/reset-for-compilers.sh +44 -0
  250. package/native/scripts/start-xvfb.sh +35 -0
  251. package/native/shim/paragraph-platform/react/renderer/components/text/HostPlatformParagraphProps.h +35 -0
  252. package/native/shim/view-platform/react/renderer/components/view/HostPlatformViewTraitsInitializer.h +5 -2
  253. package/native/shim/worklets/linux-reanimated-props.h +14 -0
  254. package/native/shim/worklets/linux-worklets.h +23 -0
  255. package/package.json +6 -3
  256. package/prebuilt.json +70 -6
@@ -0,0 +1,195 @@
1
+ // `<split-view>` and its sidebar on GTK, over the core's split views and source lists
2
+ // (split-view.h): the same for the window's split view and a plain one in the content.
3
+ //
4
+ // A placed split view holds an AdwNavigationSplitView in an AdwBreakpointBin, filling its view. The
5
+ // window's own runs the full height of the window, as a libadwaita window lays one out: each pane is
6
+ // under a header bar of its own in an AdwToolbarView, the window's header bar (its title, history
7
+ // pair, sidebar button and header items) moves over the content pane, and it moves back as the split
8
+ // view goes. A window whose content already runs under its header bar keeps it there. Each
9
+ // pane moves into a slot of its own in a page of the split view, a container of its own for input,
10
+ // and its size goes back to its shadow node as state, coalesced to once a frame (FrameSizes). The
11
+ // core owns collapse (FoldingSplit): the bin's one AdwBreakpoint, whose condition is the core's
12
+ // compact width (sidebarCompactWidth), only tells it the window crossed that width, and the split
13
+ // view's `collapsed` and `show-content` show what it decides. The content page cannot be popped, so
14
+ // the split view's own back gesture and button stay out of the way of the router's history.
15
+ //
16
+ // Neighbouring sidebar sections are one source list, a GtkListBox in the navigation-sidebar style
17
+ // drawn over the sections' frames in their parent, which the sections give their space to and hide
18
+ // in. A titled section starts with its title row, which folds a collapsible section away. An item
19
+ // with children is a custom row holding the item's view in a slot. Choosing a row sends
20
+ // `sidebarSelect` to its item, and the row the app selects is selected again on each change.
21
+ //
22
+ // A tabs host (the core's tabs-host.h) is placed as a split view too, as macOS draws one: its tabs
23
+ // are a source list filling the sidebar's page, and its screens share the content page, each at the
24
+ // page's size, the core covering all but the selected one. Choosing a tab goes to the core
25
+ // (GtkBackend::Hooks::chooseTab), which answers with the list's new selection.
26
+ #pragma once
27
+
28
+ #include "ngn/split-view.h"
29
+
30
+ #include <adwaita.h>
31
+
32
+ #include <gtk/gtk.h>
33
+
34
+ #include <functional>
35
+ #include <map>
36
+ #include <memory>
37
+ #include <optional>
38
+ #include <string>
39
+ #include <vector>
40
+
41
+ namespace ngn::gtk {
42
+
43
+ class GtkBackend;
44
+
45
+ class SplitViews {
46
+ public:
47
+ explicit SplitViews(GtkBackend &backend) : backend_(backend) {}
48
+ ~SplitViews();
49
+
50
+ // The core placed a split view (MountingBackend::setSplitView): `window` for the window's own.
51
+ void place(SurfaceId surfaceId, Tag split, bool window);
52
+ // A view was inserted into `parent`: a pane of a placed split view goes into its page.
53
+ void inserted(Tag parent, Tag child);
54
+ // `child` was taken out of `parent`: a sidebar it leaves is titled by the rows that stay, and a
55
+ // split whose sidebar it was titles its content by nothing.
56
+ void removed(Tag parent, Tag child);
57
+ // A view in a sidebar gained or lost lists of its own: the content takes the sidebar's title.
58
+ void retitleSidebarsHolding(Tag parent);
59
+ // A sidebar's props changed: its widths and whether the app has it collapsed.
60
+ void propsChanged(Tag tag);
61
+ // A view went.
62
+ void deleted(Tag tag);
63
+ // The source lists among `parent`'s children (MountingBackend::setSourceLists).
64
+ void setSourceLists(Tag parent, const std::vector<SourceList> &lists);
65
+ // After a transaction: each source list over its sections' frames.
66
+ void layOut();
67
+ // The window's header bar over the content of the window split view that is shown, else over the
68
+ // whole window: a split view whose screen is covered, or that has left the window, is not shown.
69
+ // Called as a screen is covered or uncovered, and after a transaction.
70
+ void placeHeaders();
71
+
72
+ // The app's preferences, where a sidebar with an autosaveName keeps whether it is collapsed
73
+ // (sidebarCollapsedKey): set once by the host. Without them nothing is kept.
74
+ std::function<std::optional<folly::dynamic>(const std::string &key)> readPreference;
75
+ std::function<void(const std::string &key, const folly::dynamic &value)> writePreference;
76
+
77
+ // The window split view of `surfaceId`'s window, if it has one.
78
+ std::optional<Tag> windowSplit(SurfaceId surfaceId) const;
79
+ // The full-height sidebar's own header bar while the sidebar shows beside the content, where the
80
+ // sidebar button goes, as macOS puts it over the sidebar; null otherwise, when the button stays
81
+ // in the window's header bar.
82
+ GtkWidget *sidebarHeaderShown(SurfaceId surfaceId) const;
83
+ // Show Sidebar (F9, the header bar's sidebar button) for the window's split view. Whether there
84
+ // was one.
85
+ bool toggle(SurfaceId surfaceId);
86
+ // The same for one split view: a nested tabs host's sidebar button.
87
+ bool toggleHost(Tag split);
88
+
89
+ // For tests: the AdwNavigationSplitView and its breakpoint, the window crossing the compact
90
+ // width as the breakpoint says, and a source list's GtkListBox.
91
+ GtkWidget *splitWidget(Tag split) const;
92
+ // The window split view's button in the sidebar's header bar that brings the content back, shown
93
+ // while a compact window shows the sidebar alone.
94
+ GtkWidget *contentButton(Tag split) const;
95
+ AdwBreakpoint *breakpoint(Tag split) const;
96
+ void setCompact(Tag split, bool compact);
97
+ std::vector<GtkWidget *> lists(Tag parent) const;
98
+ // The size a pane's slot last reported.
99
+ std::optional<facebook::react::Size> paneSize(Tag pane) const;
100
+ bool folded(Tag parent, Tag section) const;
101
+ void fold(Tag parent, Tag section, bool folded);
102
+
103
+ // A row chosen in `parent`'s source list.
104
+ void chose(Tag parent, Tag row);
105
+ // A pane's slot was allocated at this size.
106
+ void reportSizeFromSlot(Tag pane, int width, int height);
107
+
108
+ private:
109
+ struct Split {
110
+ SurfaceId surfaceId{-1};
111
+ bool window{false};
112
+ GtkWidget *bin{nullptr};
113
+ GtkWidget *view{nullptr};
114
+ AdwBreakpoint *breakpoint{nullptr};
115
+ GtkWidget *sidebarSlot{nullptr};
116
+ GtkWidget *contentSlot{nullptr};
117
+ // A window's split view, full height: the sidebar's own header bar, and the toolbar view over
118
+ // the content that holds the window's header bar while the split view is there.
119
+ GtkWidget *sidebarHeader{nullptr};
120
+ GtkWidget *contentButton{nullptr};
121
+ GtkWidget *contentToolbar{nullptr};
122
+ Tag sidebar{-1};
123
+ Tag content{-1};
124
+ SidebarCollapse collapse;
125
+ // The collapsed input as last applied, so an update that leaves it alone does not reapply it.
126
+ std::optional<bool> collapsedProp;
127
+ // Where the sidebar button was last laid out: over the sidebar, or in the window's header bar.
128
+ bool buttonOverSidebar{false};
129
+ FoldingSplit folding;
130
+ SidebarWidths widths;
131
+ // A tabs host: its screens, hosted in the content slot, and the scrolled window in the sidebar
132
+ // slot its tab list fills.
133
+ bool tabs{false};
134
+ std::vector<Tag> screens;
135
+ GtkWidget *tabList{nullptr};
136
+ // A nested tabs host's button over its content that shows the tab list while compact.
137
+ GtkWidget *sidebarButton{nullptr};
138
+ };
139
+ struct Lists {
140
+ std::vector<SourceList> lists;
141
+ std::vector<GtkWidget *> boxes;
142
+ SourceListFolds folds;
143
+ // The custom rows' items, hosted in the rows.
144
+ std::vector<Tag> hosted;
145
+ // A rebuild waiting for the next idle, after a fold.
146
+ guint refill{0};
147
+ // While the boxes are rebuilt or their selection set: no choice to report.
148
+ bool syncing{false};
149
+ };
150
+ void host(Split &s, Tag pane);
151
+ // A tabs host's screen into its content slot, at the slot's size.
152
+ void hostScreen(Split &s, Tag screen);
153
+ // The tab list of the tabs host `split` into its sidebar, once both are there, and the chosen
154
+ // tab's title on its content page.
155
+ void showTabList(Tag split);
156
+ // A sidebar first hosted, by placing the split or inserting the sidebar: its widths, the app's
157
+ // collapsed prop, then the saved preference over it.
158
+ void applySidebar(Split &s);
159
+ // Moves the window's header bar over the content pane, or back over the whole window.
160
+ void moveHeaderBar(Split &s, bool overContent);
161
+ void placeHeader(SurfaceId surfaceId);
162
+ void tearDown(Split &s);
163
+ void refill(Tag parent);
164
+ void applyWidths(Split &s);
165
+ void show(Split &s);
166
+ // Saves the collapsed state under the sidebar's autosaveName.
167
+ void autosave(const Split &s);
168
+ void fill(Tag parent, Lists &l, size_t index);
169
+ // The content page's title, which its header bar shows: the label of `row`, selected in a list
170
+ // `within` a sidebar, or none. A tabs host titles its own (showTabList).
171
+ void titleContent(GtkWidget *within, GtkListBoxRow *row);
172
+ // Builds `parent`'s lists afresh, rows and all.
173
+ void rebuild(Tag parent, const std::vector<SourceList> &lists);
174
+ // Selects the row list `index` has selected, without building it again.
175
+ void select(Lists &l, size_t index);
176
+ void flushSizes();
177
+ std::optional<Tag> splitOf(Tag pane) const;
178
+
179
+ GtkBackend &backend_;
180
+ std::map<Tag, Split> splits_;
181
+ std::map<Tag, Lists> lists_;
182
+ FrameSizes sizes_;
183
+ std::map<Tag, facebook::react::Size> reported_;
184
+ guint flush_{0};
185
+ // A tab chosen, sent to the core on the next idle: the core answers with the list's new rows,
186
+ // which must not replace them while the list box is still selecting the row.
187
+ guint choose_{0};
188
+ struct {
189
+ SurfaceId surfaceId{-1};
190
+ Tag host{-1};
191
+ Tag screen{-1};
192
+ } chosenTab_;
193
+ };
194
+
195
+ } // namespace ngn::gtk
@@ -0,0 +1,487 @@
1
+ #include "status-notifier.h"
2
+
3
+ #include "app-windows.h"
4
+
5
+ #include "ngn/dbus-menu.h"
6
+
7
+ #include <gtk/gtk.h>
8
+
9
+ #include <cstdio>
10
+ #include <functional>
11
+ #include <map>
12
+ #include <optional>
13
+ #include <vector>
14
+
15
+ namespace ngn::gtk {
16
+
17
+ namespace {
18
+
19
+ constexpr const char *kItemPath = "/StatusNotifierItem";
20
+ constexpr const char *kMenuPath = "/MenuBar";
21
+
22
+ constexpr const char *kItemXml = R"xml(<node>
23
+ <interface name="org.kde.StatusNotifierItem">
24
+ <property name="Category" type="s" access="read"/>
25
+ <property name="Id" type="s" access="read"/>
26
+ <property name="Title" type="s" access="read"/>
27
+ <property name="Status" type="s" access="read"/>
28
+ <property name="WindowId" type="i" access="read"/>
29
+ <property name="IconName" type="s" access="read"/>
30
+ <property name="IconPixmap" type="a(iiay)" access="read"/>
31
+ <property name="OverlayIconName" type="s" access="read"/>
32
+ <property name="AttentionIconName" type="s" access="read"/>
33
+ <property name="ToolTip" type="(sa(iiay)ss)" access="read"/>
34
+ <property name="ItemIsMenu" type="b" access="read"/>
35
+ <property name="Menu" type="o" access="read"/>
36
+ <method name="ContextMenu"><arg name="x" type="i" direction="in"/><arg name="y" type="i" direction="in"/></method>
37
+ <method name="Activate"><arg name="x" type="i" direction="in"/><arg name="y" type="i" direction="in"/></method>
38
+ <method name="SecondaryActivate"><arg name="x" type="i" direction="in"/><arg name="y" type="i" direction="in"/></method>
39
+ <method name="Scroll"><arg name="delta" type="i" direction="in"/><arg name="orientation" type="s" direction="in"/></method>
40
+ <signal name="NewTitle"/>
41
+ <signal name="NewIcon"/>
42
+ <signal name="NewToolTip"/>
43
+ <signal name="NewStatus"><arg name="status" type="s"/></signal>
44
+ </interface>
45
+ </node>)xml";
46
+
47
+ constexpr const char *kMenuXml = R"xml(<node>
48
+ <interface name="com.canonical.dbusmenu">
49
+ <property name="Version" type="u" access="read"/>
50
+ <property name="TextDirection" type="s" access="read"/>
51
+ <property name="Status" type="s" access="read"/>
52
+ <property name="IconThemePath" type="as" access="read"/>
53
+ <method name="GetLayout">
54
+ <arg name="parentId" type="i" direction="in"/>
55
+ <arg name="recursionDepth" type="i" direction="in"/>
56
+ <arg name="propertyNames" type="as" direction="in"/>
57
+ <arg name="revision" type="u" direction="out"/>
58
+ <arg name="layout" type="(ia{sv}av)" direction="out"/>
59
+ </method>
60
+ <method name="GetGroupProperties">
61
+ <arg name="ids" type="ai" direction="in"/>
62
+ <arg name="propertyNames" type="as" direction="in"/>
63
+ <arg name="properties" type="a(ia{sv})" direction="out"/>
64
+ </method>
65
+ <method name="GetProperty">
66
+ <arg name="id" type="i" direction="in"/>
67
+ <arg name="name" type="s" direction="in"/>
68
+ <arg name="value" type="v" direction="out"/>
69
+ </method>
70
+ <method name="Event">
71
+ <arg name="id" type="i" direction="in"/>
72
+ <arg name="eventId" type="s" direction="in"/>
73
+ <arg name="data" type="v" direction="in"/>
74
+ <arg name="timestamp" type="u" direction="in"/>
75
+ </method>
76
+ <method name="EventGroup">
77
+ <arg name="events" type="a(isvu)" direction="in"/>
78
+ <arg name="idErrors" type="ai" direction="out"/>
79
+ </method>
80
+ <method name="AboutToShow">
81
+ <arg name="id" type="i" direction="in"/>
82
+ <arg name="needUpdate" type="b" direction="out"/>
83
+ </method>
84
+ <method name="AboutToShowGroup">
85
+ <arg name="ids" type="ai" direction="in"/>
86
+ <arg name="updatesNeeded" type="ai" direction="out"/>
87
+ <arg name="idErrors" type="ai" direction="out"/>
88
+ </method>
89
+ <signal name="LayoutUpdated"><arg name="revision" type="u"/><arg name="parent" type="i"/></signal>
90
+ <signal name="ItemsPropertiesUpdated">
91
+ <arg name="updatedProps" type="a(ia{sv})"/>
92
+ <arg name="removedProps" type="a(ias)"/>
93
+ </signal>
94
+ </interface>
95
+ </node>)xml";
96
+
97
+ GDBusInterfaceInfo *interfaceInfo(const char *xml) {
98
+ GDBusNodeInfo *node = g_dbus_node_info_new_for_xml(xml, nullptr);
99
+ // Kept for the process: every icon's objects use it.
100
+ return node->interfaces[0];
101
+ }
102
+
103
+ GDBusInterfaceInfo *itemInterface() {
104
+ static GDBusInterfaceInfo *info = interfaceInfo(kItemXml);
105
+ return info;
106
+ }
107
+
108
+ GDBusInterfaceInfo *menuInterface() {
109
+ static GDBusInterfaceInfo *info = interfaceInfo(kMenuXml);
110
+ return info;
111
+ }
112
+
113
+ GVariant *noPixmaps() {
114
+ return g_variant_new_array(G_VARIANT_TYPE("(iiay)"), nullptr, 0);
115
+ }
116
+
117
+ // A menu node's properties as dbusmenu names them.
118
+ GVariant *nodeProperties(const DbusMenuNode &node, bool root) {
119
+ GVariantBuilder props;
120
+ g_variant_builder_init(&props, G_VARIANT_TYPE("a{sv}"));
121
+ if (root) {
122
+ g_variant_builder_add(&props, "{sv}", "children-display", g_variant_new_string("submenu"));
123
+ } else if (node.separator) {
124
+ g_variant_builder_add(&props, "{sv}", "type", g_variant_new_string("separator"));
125
+ } else {
126
+ g_variant_builder_add(&props, "{sv}", "label", g_variant_new_string(node.label.c_str()));
127
+ g_variant_builder_add(&props, "{sv}", "enabled", g_variant_new_boolean(node.enabled));
128
+ if (node.checked) {
129
+ g_variant_builder_add(&props, "{sv}", "toggle-type", g_variant_new_string("checkmark"));
130
+ g_variant_builder_add(&props, "{sv}", "toggle-state", g_variant_new_int32(1));
131
+ }
132
+ if (!node.children.empty()) {
133
+ g_variant_builder_add(&props, "{sv}", "children-display", g_variant_new_string("submenu"));
134
+ }
135
+ }
136
+ return g_variant_builder_end(&props);
137
+ }
138
+
139
+ // `(ia{sv}av)`: the node, and its children down to `depth` levels (all at -1).
140
+ GVariant *layoutOf(const DbusMenuNode &node, int depth, bool root) {
141
+ GVariantBuilder children;
142
+ g_variant_builder_init(&children, G_VARIANT_TYPE("av"));
143
+ if (depth != 0) {
144
+ for (const auto &child : node.children) {
145
+ g_variant_builder_add(&children, "v", layoutOf(child, depth - 1, false));
146
+ }
147
+ }
148
+ return g_variant_new("(i@a{sv}av)", node.id, nodeProperties(node, root), &children);
149
+ }
150
+
151
+ class Tray;
152
+
153
+ // One icon: its own connection, so closing it takes the icon off the watcher.
154
+ struct Icon {
155
+ TrayIcon icon;
156
+ std::string appId;
157
+ GDBusConnection *connection{nullptr};
158
+ guint item{0};
159
+ guint menu{0};
160
+ DbusMenuNode layout;
161
+ guint32 revision{1};
162
+ TrayEvents *events{nullptr};
163
+
164
+ ~Icon() {
165
+ if (connection) {
166
+ g_dbus_connection_unregister_object(connection, item);
167
+ g_dbus_connection_unregister_object(connection, menu);
168
+ g_dbus_connection_close_sync(connection, nullptr, nullptr);
169
+ g_object_unref(connection);
170
+ }
171
+ }
172
+
173
+ std::string iconName() const {
174
+ return icon.image.empty() ? appId : icon.image;
175
+ }
176
+ std::string title() const {
177
+ return !icon.title.empty() ? icon.title : !icon.tooltip.empty() ? icon.tooltip : appId;
178
+ }
179
+ void emit(const char *interface, const char *path, const char *signal, GVariant *args) const {
180
+ g_dbus_connection_emit_signal(connection, nullptr, path, interface, signal, args, nullptr);
181
+ }
182
+ };
183
+
184
+ using IconRef = std::weak_ptr<Icon>;
185
+
186
+ std::shared_ptr<Icon> iconOf(gpointer data) {
187
+ return static_cast<IconRef *>(data)->lock();
188
+ }
189
+
190
+ GVariant *itemProperty(GDBusConnection *, const gchar *, const gchar *, const gchar *, const gchar *name, GError **error, gpointer data) {
191
+ auto icon = iconOf(data);
192
+ if (!icon) {
193
+ return nullptr;
194
+ }
195
+ std::string n = name;
196
+ const TrayIcon &t = icon->icon;
197
+ if (n == "Category") return g_variant_new_string("ApplicationStatus");
198
+ if (n == "Id") return g_variant_new_string((icon->appId + "-" + t.id).c_str());
199
+ if (n == "Title") return g_variant_new_string(icon->title().c_str());
200
+ if (n == "Status") return g_variant_new_string("Active");
201
+ if (n == "WindowId") return g_variant_new_int32(0);
202
+ if (n == "IconName") return g_variant_new_string(icon->iconName().c_str());
203
+ if (n == "IconPixmap") return noPixmaps();
204
+ if (n == "OverlayIconName" || n == "AttentionIconName") return g_variant_new_string("");
205
+ if (n == "ToolTip") {
206
+ return g_variant_new("(s@a(iiay)ss)", "", noPixmaps(), (t.tooltip.empty() ? icon->title() : t.tooltip).c_str(), "");
207
+ }
208
+ if (n == "ItemIsMenu") return g_variant_new_boolean(t.menu.has_value());
209
+ if (n == "Menu") return g_variant_new_object_path(t.menu ? kMenuPath : "/NO_DBUSMENU");
210
+ g_set_error(error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_PROPERTY, "No property %s", name);
211
+ return nullptr;
212
+ }
213
+
214
+ void itemCall(GDBusConnection *, const gchar *, const gchar *, const gchar *, const gchar *method, GVariant *, GDBusMethodInvocation *invocation, gpointer data) {
215
+ auto icon = iconOf(data);
216
+ // A click on an icon with no menu presses it; with one, the host opens the menu instead.
217
+ if (icon && g_str_equal(method, "Activate") && !icon->icon.menu && icon->events->press) {
218
+ icon->events->press(icon->icon.id);
219
+ }
220
+ g_dbus_method_invocation_return_value(invocation, nullptr);
221
+ }
222
+
223
+ GVariant *menuProperty(GDBusConnection *, const gchar *, const gchar *, const gchar *, const gchar *name, GError **error, gpointer) {
224
+ std::string n = name;
225
+ if (n == "Version") return g_variant_new_uint32(3);
226
+ if (n == "TextDirection") return g_variant_new_string(gtk_widget_get_default_direction() == GTK_TEXT_DIR_RTL ? "rtl" : "ltr");
227
+ if (n == "Status") return g_variant_new_string("normal");
228
+ if (n == "IconThemePath") return g_variant_new_strv(nullptr, 0);
229
+ g_set_error(error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_PROPERTY, "No property %s", name);
230
+ return nullptr;
231
+ }
232
+
233
+ // A click on a menu item: the item the app knows, if it names one.
234
+ bool menuEvent(const Icon &icon, gint32 id, const char *eventId) {
235
+ const DbusMenuNode *node = findDbusMenuNode(icon.layout, id);
236
+ if (!node) {
237
+ return false;
238
+ }
239
+ if (!g_str_equal(eventId, "clicked") || !node->enabled) {
240
+ return true;
241
+ }
242
+ if (node->command != MenuCommand::AppItem) {
243
+ if (icon.events->command) {
244
+ icon.events->command(node->command);
245
+ }
246
+ } else if (!node->itemId.empty() && icon.events->menuSelect) {
247
+ icon.events->menuSelect(icon.icon.id, node->itemId);
248
+ }
249
+ return true;
250
+ }
251
+
252
+ void menuCall(GDBusConnection *, const gchar *, const gchar *, const gchar *, const gchar *method, GVariant *args, GDBusMethodInvocation *invocation, gpointer data) {
253
+ auto icon = iconOf(data);
254
+ if (!icon) {
255
+ g_dbus_method_invocation_return_dbus_error(invocation, "org.freedesktop.DBus.Error.UnknownObject", "The icon is gone");
256
+ return;
257
+ }
258
+ std::string m = method;
259
+ auto unknown = [invocation](gint32 id) {
260
+ g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No menu item %d", id);
261
+ };
262
+ if (m == "GetLayout") {
263
+ gint32 parent = 0, depth = -1;
264
+ g_variant_get(args, "(ii^a&s)", &parent, &depth, nullptr);
265
+ const DbusMenuNode *node = findDbusMenuNode(icon->layout, parent);
266
+ if (!node) {
267
+ unknown(parent);
268
+ return;
269
+ }
270
+ g_dbus_method_invocation_return_value(invocation, g_variant_new("(u@(ia{sv}av))", icon->revision, layoutOf(*node, depth, parent == 0)));
271
+ } else if (m == "GetGroupProperties") {
272
+ GVariantIter *ids = nullptr;
273
+ g_variant_get(args, "(aias)", &ids, nullptr);
274
+ GVariantBuilder out;
275
+ g_variant_builder_init(&out, G_VARIANT_TYPE("a(ia{sv})"));
276
+ gint32 id = 0;
277
+ bool any = false;
278
+ while (g_variant_iter_next(ids, "i", &id)) {
279
+ any = true;
280
+ if (const DbusMenuNode *node = findDbusMenuNode(icon->layout, id)) {
281
+ g_variant_builder_add(&out, "(i@a{sv})", id, nodeProperties(*node, id == 0));
282
+ }
283
+ }
284
+ // dbusmenu: no ids asks for every item.
285
+ if (!any) {
286
+ std::function<void(const DbusMenuNode &)> all = [&](const DbusMenuNode &node) {
287
+ g_variant_builder_add(&out, "(i@a{sv})", node.id, nodeProperties(node, node.id == 0));
288
+ for (const auto &child : node.children) all(child);
289
+ };
290
+ all(icon->layout);
291
+ }
292
+ g_variant_iter_free(ids);
293
+ g_dbus_method_invocation_return_value(invocation, g_variant_new("(@a(ia{sv}))", g_variant_builder_end(&out)));
294
+ } else if (m == "GetProperty") {
295
+ gint32 id = 0;
296
+ const gchar *name = nullptr;
297
+ g_variant_get(args, "(i&s)", &id, &name);
298
+ const DbusMenuNode *node = findDbusMenuNode(icon->layout, id);
299
+ GVariant *props = node ? g_variant_ref_sink(nodeProperties(*node, id == 0)) : nullptr;
300
+ GVariant *value = props ? g_variant_lookup_value(props, name, nullptr) : nullptr;
301
+ if (props) {
302
+ g_variant_unref(props);
303
+ }
304
+ if (!value) {
305
+ unknown(id);
306
+ return;
307
+ }
308
+ g_dbus_method_invocation_return_value(invocation, g_variant_new("(v)", value));
309
+ g_variant_unref(value);
310
+ } else if (m == "Event") {
311
+ gint32 id = 0;
312
+ const gchar *eventId = nullptr;
313
+ g_variant_get(args, "(i&svu)", &id, &eventId, nullptr, nullptr);
314
+ if (!menuEvent(*icon, id, eventId)) {
315
+ unknown(id);
316
+ return;
317
+ }
318
+ g_dbus_method_invocation_return_value(invocation, nullptr);
319
+ } else if (m == "EventGroup") {
320
+ GVariantIter *events = nullptr;
321
+ g_variant_get(args, "(a(isvu))", &events);
322
+ GVariantBuilder errors;
323
+ g_variant_builder_init(&errors, G_VARIANT_TYPE("ai"));
324
+ gint32 id = 0;
325
+ const gchar *eventId = nullptr;
326
+ while (g_variant_iter_next(events, "(i&svu)", &id, &eventId, nullptr, nullptr)) {
327
+ if (!menuEvent(*icon, id, eventId)) {
328
+ g_variant_builder_add(&errors, "i", id);
329
+ }
330
+ }
331
+ g_variant_iter_free(events);
332
+ g_dbus_method_invocation_return_value(invocation, g_variant_new("(@ai)", g_variant_builder_end(&errors)));
333
+ } else if (m == "AboutToShow") {
334
+ g_dbus_method_invocation_return_value(invocation, g_variant_new("(b)", FALSE));
335
+ } else {
336
+ g_dbus_method_invocation_return_value(invocation, g_variant_new("(@ai@ai)", g_variant_new_array(G_VARIANT_TYPE_INT32, nullptr, 0),
337
+ g_variant_new_array(G_VARIANT_TYPE_INT32, nullptr, 0)));
338
+ }
339
+ }
340
+
341
+ const GDBusInterfaceVTable kItemVTable{.method_call = itemCall, .get_property = itemProperty};
342
+ const GDBusInterfaceVTable kMenuVTable{.method_call = menuCall, .get_property = menuProperty};
343
+
344
+ void freeRef(gpointer data) {
345
+ delete static_cast<IconRef *>(data);
346
+ }
347
+
348
+ class Tray final : public TrayBackend, public std::enable_shared_from_this<Tray> {
349
+ public:
350
+ Tray(std::string appId, TrayEvents events) : appId_(std::move(appId)), events_(std::move(events)) {}
351
+
352
+ ~Tray() override {
353
+ if (watch_) {
354
+ g_bus_unwatch_name(watch_);
355
+ }
356
+ }
357
+
358
+ // The watcher, given every icon each time it appears.
359
+ void start() {
360
+ watch_ = g_bus_watch_name(
361
+ G_BUS_TYPE_SESSION, kStatusNotifierWatcher, G_BUS_NAME_WATCHER_FLAGS_NONE,
362
+ [](GDBusConnection *, const gchar *, const gchar *, gpointer data) {
363
+ auto *self = static_cast<Tray *>(data);
364
+ self->watcher_ = true;
365
+ for (auto &[id, icon] : self->icons_) {
366
+ registerIcon(*icon);
367
+ }
368
+ },
369
+ [](GDBusConnection *, const gchar *, gpointer data) { static_cast<Tray *>(data)->watcher_ = false; }, this, nullptr);
370
+ }
371
+
372
+ void setIcons(std::vector<TrayIcon> icons) override {
373
+ onMainContext([weak = weak_from_this(), icons = std::move(icons)]() mutable {
374
+ if (auto self = weak.lock()) {
375
+ self->apply(std::move(icons));
376
+ }
377
+ });
378
+ }
379
+
380
+ private:
381
+ static void registerIcon(const Icon &icon) {
382
+ g_dbus_connection_call(
383
+ icon.connection, kStatusNotifierWatcher, "/StatusNotifierWatcher", kStatusNotifierWatcher, "RegisterStatusNotifierItem",
384
+ g_variant_new("(s)", kItemPath), nullptr, G_DBUS_CALL_FLAGS_NONE, -1, nullptr, nullptr, nullptr);
385
+ }
386
+
387
+ std::shared_ptr<Icon> make(const TrayIcon &spec) {
388
+ GError *error = nullptr;
389
+ gchar *address = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SESSION, nullptr, &error);
390
+ GDBusConnection *connection = address ? g_dbus_connection_new_for_address_sync(
391
+ address, static_cast<GDBusConnectionFlags>(G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT | G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION),
392
+ nullptr, nullptr, &error) : nullptr;
393
+ g_free(address);
394
+ if (!connection) {
395
+ fprintf(stderr, "[ngn] tray icon %s: %s\n", spec.id.c_str(), error ? error->message : "no session bus");
396
+ g_clear_error(&error);
397
+ return nullptr;
398
+ }
399
+ auto icon = std::make_shared<Icon>();
400
+ icon->icon = spec;
401
+ icon->appId = appId_;
402
+ icon->connection = connection;
403
+ icon->events = &events_;
404
+ icon->layout = dbusMenuLayout(spec.menu.value_or(std::vector<MenuItem>{}));
405
+ icon->item = g_dbus_connection_register_object(connection, kItemPath, itemInterface(), &kItemVTable, new IconRef(icon), freeRef, nullptr);
406
+ icon->menu = g_dbus_connection_register_object(connection, kMenuPath, menuInterface(), &kMenuVTable, new IconRef(icon), freeRef, nullptr);
407
+ if (watcher_) {
408
+ registerIcon(*icon);
409
+ }
410
+ return icon;
411
+ }
412
+
413
+ // The new set: an icon whose id was there before keeps its connection and tells the host what
414
+ // changed; one gone closes its connection.
415
+ void apply(std::vector<TrayIcon> icons) {
416
+ std::map<std::string, std::shared_ptr<Icon>> next;
417
+ for (const auto &spec : icons) {
418
+ auto it = icons_.find(spec.id);
419
+ if (it == icons_.end()) {
420
+ if (auto icon = make(spec)) {
421
+ next[spec.id] = std::move(icon);
422
+ }
423
+ continue;
424
+ }
425
+ auto icon = it->second;
426
+ if (!(icon->icon == spec)) {
427
+ auto layout = dbusMenuLayout(spec.menu.value_or(std::vector<MenuItem>{}));
428
+ bool relaid = !(layout == icon->layout);
429
+ bool menuChanged = icon->icon.menu.has_value() != spec.menu.has_value();
430
+ icon->icon = spec;
431
+ icon->layout = std::move(layout);
432
+ for (const char *signal : {"NewTitle", "NewIcon", "NewToolTip"}) {
433
+ icon->emit("org.kde.StatusNotifierItem", kItemPath, signal, nullptr);
434
+ }
435
+ icon->emit("org.kde.StatusNotifierItem", kItemPath, "NewStatus", g_variant_new("(s)", "Active"));
436
+ if (menuChanged) {
437
+ // Menu and ItemIsMenu follow whether there is a menu, which no New* signal tells a host to reread.
438
+ GVariantBuilder changed;
439
+ g_variant_builder_init(&changed, G_VARIANT_TYPE("a{sv}"));
440
+ g_variant_builder_add(&changed, "{sv}", "Menu", g_variant_new_object_path(spec.menu ? kMenuPath : "/NO_DBUSMENU"));
441
+ g_variant_builder_add(&changed, "{sv}", "ItemIsMenu", g_variant_new_boolean(spec.menu.has_value()));
442
+ icon->emit("org.freedesktop.DBus.Properties", kItemPath, "PropertiesChanged",
443
+ g_variant_new("(sa{sv}as)", "org.kde.StatusNotifierItem", &changed, nullptr));
444
+ }
445
+ if (relaid) {
446
+ icon->emit("com.canonical.dbusmenu", kMenuPath, "LayoutUpdated", g_variant_new("(ui)", ++icon->revision, 0));
447
+ }
448
+ }
449
+ next[spec.id] = std::move(icon);
450
+ }
451
+ icons_ = std::move(next);
452
+ }
453
+
454
+ std::string appId_;
455
+ TrayEvents events_;
456
+ guint watch_{0};
457
+ bool watcher_{false};
458
+ std::map<std::string, std::shared_ptr<Icon>> icons_;
459
+ };
460
+
461
+ } // namespace
462
+
463
+ bool statusNotifierWatcherRunning() {
464
+ GDBusConnection *bus = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr);
465
+ if (!bus) {
466
+ return false;
467
+ }
468
+ GVariant *reply = g_dbus_connection_call_sync(
469
+ bus, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "NameHasOwner",
470
+ g_variant_new("(s)", kStatusNotifierWatcher), G_VARIANT_TYPE("(b)"), G_DBUS_CALL_FLAGS_NONE, 1000, nullptr, nullptr);
471
+ g_object_unref(bus);
472
+ if (!reply) {
473
+ return false;
474
+ }
475
+ gboolean owned = FALSE;
476
+ g_variant_get(reply, "(b)", &owned);
477
+ g_variant_unref(reply);
478
+ return owned;
479
+ }
480
+
481
+ std::shared_ptr<TrayBackend> makeStatusNotifierTray(const std::string &appId, TrayEvents events) {
482
+ auto tray = std::make_shared<Tray>(appId, std::move(events));
483
+ tray->start();
484
+ return tray;
485
+ }
486
+
487
+ } // namespace ngn::gtk