@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,1105 @@
|
|
|
1
|
+
#include "split-view.h"
|
|
2
|
+
|
|
3
|
+
#include "gtk-backend.h"
|
|
4
|
+
#include "screens.h"
|
|
5
|
+
#include "view-widget.h"
|
|
6
|
+
|
|
7
|
+
#include <react/renderer/core/ConcreteState.h>
|
|
8
|
+
#include <react/renderer/core/RawEvent.h>
|
|
9
|
+
|
|
10
|
+
#include <adwaita.h>
|
|
11
|
+
|
|
12
|
+
#include <algorithm>
|
|
13
|
+
#include <cmath>
|
|
14
|
+
#include <set>
|
|
15
|
+
#include <string>
|
|
16
|
+
|
|
17
|
+
using facebook::react::ConcreteState;
|
|
18
|
+
using facebook::react::Float;
|
|
19
|
+
using facebook::react::RawEvent;
|
|
20
|
+
using facebook::react::Rect;
|
|
21
|
+
using facebook::react::Size;
|
|
22
|
+
|
|
23
|
+
// A pane's slot in its page: it asks for no size, puts the pane at its top left at the slot's size,
|
|
24
|
+
// and reports that size, which the pane's layout takes.
|
|
25
|
+
struct _NgnPaneSlot {
|
|
26
|
+
GtkWidget parent;
|
|
27
|
+
ngn::gtk::SplitViews *splits;
|
|
28
|
+
ngn::Tag pane;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
G_DECLARE_FINAL_TYPE(NgnPaneSlot, ngn_pane_slot, NGN, PANE_SLOT, GtkWidget)
|
|
32
|
+
G_DEFINE_TYPE(NgnPaneSlot, ngn_pane_slot, GTK_TYPE_WIDGET)
|
|
33
|
+
|
|
34
|
+
namespace ngn::gtk {
|
|
35
|
+
// What a pane slot calls as it is allocated.
|
|
36
|
+
void paneSlotAllocated(SplitViews *splits, Tag pane, int width, int height);
|
|
37
|
+
} // namespace ngn::gtk
|
|
38
|
+
|
|
39
|
+
static void ngn_pane_slot_measure(GtkWidget *, GtkOrientation, int, int *minimum, int *natural, int *, int *) {
|
|
40
|
+
*minimum = 0;
|
|
41
|
+
*natural = 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static void ngn_pane_slot_size_allocate(GtkWidget *widget, int width, int height, int) {
|
|
45
|
+
for (GtkWidget *child = gtk_widget_get_first_child(widget); child; child = gtk_widget_get_next_sibling(child)) {
|
|
46
|
+
GtkAllocation all{0, 0, width, height};
|
|
47
|
+
gtk_widget_size_allocate(child, &all, -1);
|
|
48
|
+
}
|
|
49
|
+
auto *slot = NGN_PANE_SLOT(widget);
|
|
50
|
+
if (slot->splits && slot->pane >= 0 && width > 0 && height > 0) {
|
|
51
|
+
ngn::gtk::paneSlotAllocated(slot->splits, slot->pane, width, height);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static void ngn_pane_slot_dispose(GObject *object) {
|
|
56
|
+
while (GtkWidget *child = gtk_widget_get_first_child(GTK_WIDGET(object))) {
|
|
57
|
+
gtk_widget_unparent(child);
|
|
58
|
+
}
|
|
59
|
+
G_OBJECT_CLASS(ngn_pane_slot_parent_class)->dispose(object);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static void ngn_pane_slot_class_init(NgnPaneSlotClass *klass) {
|
|
63
|
+
G_OBJECT_CLASS(klass)->dispose = ngn_pane_slot_dispose;
|
|
64
|
+
GTK_WIDGET_CLASS(klass)->measure = ngn_pane_slot_measure;
|
|
65
|
+
GTK_WIDGET_CLASS(klass)->size_allocate = ngn_pane_slot_size_allocate;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static void ngn_pane_slot_init(NgnPaneSlot *slot) {
|
|
69
|
+
slot->splits = nullptr;
|
|
70
|
+
slot->pane = -1;
|
|
71
|
+
gtk_widget_set_overflow(GTK_WIDGET(slot), GTK_OVERFLOW_HIDDEN);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
namespace ngn::gtk {
|
|
75
|
+
|
|
76
|
+
namespace {
|
|
77
|
+
|
|
78
|
+
// The label of the item the app selects in a list, or null where it selects none.
|
|
79
|
+
const char *selectedLabel(const SourceList &list) {
|
|
80
|
+
auto chosen = selectedRow(list);
|
|
81
|
+
for (const auto &group : list.groups) {
|
|
82
|
+
for (const auto &row : group.rows) {
|
|
83
|
+
if (chosen == row.tag) {
|
|
84
|
+
return row.label.c_str();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return nullptr;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
void send(const ViewData *d, const char *name, folly::dynamic payload) {
|
|
92
|
+
if (d && d->emitter) {
|
|
93
|
+
d->emitter->dispatchEvent(name, std::move(payload), RawEvent::Category::Discrete);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const SplitPaneProps *paneProps(const ViewData *d) {
|
|
98
|
+
return d ? dynamic_cast<const SplitPaneProps *>(d->props.get()) : nullptr;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Rows at the height Yoga gives them (kSidebarRowHeight), so the list draws in the space its
|
|
102
|
+
// sections take in layout.
|
|
103
|
+
void addSourceListStyle() {
|
|
104
|
+
static bool added = false;
|
|
105
|
+
if (added || !gdk_display_get_default()) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
added = true;
|
|
109
|
+
GtkCssProvider *provider = gtk_css_provider_new();
|
|
110
|
+
std::string css = ".ngn-source-list { background: transparent; margin: 0; padding: 0; }"
|
|
111
|
+
".ngn-source-list > row { min-height: " +
|
|
112
|
+
std::to_string(static_cast<int>(kSidebarRowHeight)) +
|
|
113
|
+
"px; padding-top: 0; padding-bottom: 0; margin-top: 0; margin-bottom: 0; }"
|
|
114
|
+
".ngn-source-list > row.ngn-section-title { min-height: " +
|
|
115
|
+
std::to_string(static_cast<int>(kSidebarHeaderHeight)) + "px; }";
|
|
116
|
+
gtk_css_provider_load_from_data(provider, css.c_str(), -1);
|
|
117
|
+
gtk_style_context_add_provider_for_display(
|
|
118
|
+
gdk_display_get_default(), GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
|
119
|
+
g_object_unref(provider);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
struct RowTarget {
|
|
123
|
+
SplitViews *splits;
|
|
124
|
+
Tag parent;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
constexpr const char *kTabsHost = "RNSTabsHostIOS";
|
|
128
|
+
constexpr const char *kTabScreen = "RNSTabsScreenIOS";
|
|
129
|
+
|
|
130
|
+
// Takes a source list's box out of wherever it is: a view, or a tab list's scrolled window.
|
|
131
|
+
void detachBox(GtkWidget *box) {
|
|
132
|
+
GtkWidget *parent = gtk_widget_get_parent(box);
|
|
133
|
+
if (parent && GTK_IS_VIEWPORT(parent)) {
|
|
134
|
+
gtk_viewport_set_child(GTK_VIEWPORT(parent), nullptr);
|
|
135
|
+
} else if (parent) {
|
|
136
|
+
gtk_widget_unparent(box);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
} // namespace
|
|
141
|
+
|
|
142
|
+
void paneSlotAllocated(SplitViews *splits, Tag pane, int width, int height) {
|
|
143
|
+
splits->reportSizeFromSlot(pane, width, height);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
SplitViews::~SplitViews() {
|
|
147
|
+
if (flush_ != 0) {
|
|
148
|
+
g_source_remove(flush_);
|
|
149
|
+
}
|
|
150
|
+
if (choose_ != 0) {
|
|
151
|
+
g_source_remove(choose_);
|
|
152
|
+
}
|
|
153
|
+
for (auto &[parent, l] : lists_) {
|
|
154
|
+
if (l.refill != 0) {
|
|
155
|
+
g_source_remove(l.refill);
|
|
156
|
+
}
|
|
157
|
+
for (Tag tag : l.hosted) {
|
|
158
|
+
backend_.unhostView(tag);
|
|
159
|
+
}
|
|
160
|
+
for (GtkWidget *box : l.boxes) {
|
|
161
|
+
detachBox(box);
|
|
162
|
+
g_object_unref(box);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
for (auto &[tag, s] : splits_) {
|
|
166
|
+
tearDown(s);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
void SplitViews::moveHeaderBar(Split &s, bool overContent) {
|
|
171
|
+
const WindowChrome *chrome = chromeOf(backend_.surfaceWidget(s.surfaceId));
|
|
172
|
+
if (!chrome || !s.contentToolbar) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
GtkWidget *header = chrome->headerBar;
|
|
176
|
+
bool overIt = gtk_widget_is_ancestor(header, s.contentToolbar);
|
|
177
|
+
if (overIt == overContent) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
g_object_ref(header);
|
|
181
|
+
if (overContent) {
|
|
182
|
+
adw_toolbar_view_remove(ADW_TOOLBAR_VIEW(chrome->toolbarView), header);
|
|
183
|
+
adw_toolbar_view_add_top_bar(ADW_TOOLBAR_VIEW(s.contentToolbar), header);
|
|
184
|
+
} else {
|
|
185
|
+
adw_toolbar_view_remove(ADW_TOOLBAR_VIEW(s.contentToolbar), header);
|
|
186
|
+
// First again, above a menu bar.
|
|
187
|
+
GtkWidget *menuBar = chrome->menuBar;
|
|
188
|
+
if (menuBar) {
|
|
189
|
+
g_object_ref(menuBar);
|
|
190
|
+
adw_toolbar_view_remove(ADW_TOOLBAR_VIEW(chrome->toolbarView), menuBar);
|
|
191
|
+
}
|
|
192
|
+
adw_toolbar_view_add_top_bar(ADW_TOOLBAR_VIEW(chrome->toolbarView), header);
|
|
193
|
+
if (menuBar) {
|
|
194
|
+
adw_toolbar_view_add_top_bar(ADW_TOOLBAR_VIEW(chrome->toolbarView), menuBar);
|
|
195
|
+
g_object_unref(menuBar);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
g_object_unref(header);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
namespace {
|
|
202
|
+
|
|
203
|
+
// Whether `widget` is in a window and shown there: no ancestor is hidden, or a covered child.
|
|
204
|
+
bool shownInWindow(GtkWidget *widget) {
|
|
205
|
+
if (!widget || !gtk_widget_get_root(widget)) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
for (GtkWidget *w = widget; w; w = gtk_widget_get_parent(w)) {
|
|
209
|
+
if (!gtk_widget_get_visible(w) || !gtk_widget_get_child_visible(w)) {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
} // namespace
|
|
217
|
+
|
|
218
|
+
void SplitViews::placeHeader(SurfaceId surfaceId) {
|
|
219
|
+
Split *shown = nullptr;
|
|
220
|
+
for (auto &[tag, s] : splits_) {
|
|
221
|
+
if (s.surfaceId == surfaceId && s.window && s.contentToolbar && shownInWindow(backend_.view(tag))) {
|
|
222
|
+
shown = &s;
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
// Back over the window first, from a split view that is not the one it goes to.
|
|
227
|
+
for (auto &[tag, s] : splits_) {
|
|
228
|
+
if (s.surfaceId == surfaceId && &s != shown) {
|
|
229
|
+
moveHeaderBar(s, false);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (shown) {
|
|
233
|
+
moveHeaderBar(*shown, true);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
void SplitViews::placeHeaders() {
|
|
238
|
+
std::set<SurfaceId> surfaces;
|
|
239
|
+
for (const auto &[tag, s] : splits_) {
|
|
240
|
+
if (s.window && s.contentToolbar) {
|
|
241
|
+
surfaces.insert(s.surfaceId);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
for (SurfaceId surfaceId : surfaces) {
|
|
245
|
+
placeHeader(surfaceId);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
void SplitViews::tearDown(Split &s) {
|
|
250
|
+
moveHeaderBar(s, false);
|
|
251
|
+
for (Tag pane : {s.sidebar, s.content}) {
|
|
252
|
+
if (pane >= 0) {
|
|
253
|
+
backend_.unhostView(pane);
|
|
254
|
+
backend_.hooks.detachInput(pane);
|
|
255
|
+
backend_.hooks.containerRoot(pane, false);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (s.tabs) {
|
|
259
|
+
// The tab list's box leaves with the scrolled window's viewport, and stays in lists_.
|
|
260
|
+
Tag host = NGN_PANE_SLOT(s.contentSlot)->pane;
|
|
261
|
+
for (Tag screen : s.screens) {
|
|
262
|
+
backend_.unhostView(screen);
|
|
263
|
+
}
|
|
264
|
+
backend_.hooks.detachInput(host);
|
|
265
|
+
backend_.hooks.containerRoot(host, false);
|
|
266
|
+
s.tabList = nullptr;
|
|
267
|
+
}
|
|
268
|
+
if (s.bin && gtk_widget_get_parent(s.bin)) {
|
|
269
|
+
gtk_widget_unparent(s.bin);
|
|
270
|
+
}
|
|
271
|
+
g_clear_object(&s.bin);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
void SplitViews::place(SurfaceId surfaceId, Tag split, bool window) {
|
|
275
|
+
GtkWidget *widget = backend_.view(split);
|
|
276
|
+
ViewData *d = viewData(widget);
|
|
277
|
+
if (!d || splits_.contains(split)) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
auto &s = splits_[split];
|
|
281
|
+
s.surfaceId = surfaceId;
|
|
282
|
+
s.window = window;
|
|
283
|
+
s.tabs = d->component == kTabsHost;
|
|
284
|
+
s.view = adw_navigation_split_view_new();
|
|
285
|
+
auto slot = [this](GtkWidget *&out) {
|
|
286
|
+
out = GTK_WIDGET(g_object_new(ngn_pane_slot_get_type(), nullptr));
|
|
287
|
+
NGN_PANE_SLOT(out)->splits = this;
|
|
288
|
+
return out;
|
|
289
|
+
};
|
|
290
|
+
GtkWidget *sidebarChild = slot(s.sidebarSlot);
|
|
291
|
+
GtkWidget *contentChild = slot(s.contentSlot);
|
|
292
|
+
const WindowChrome *chrome = window ? chromeOf(backend_.surfaceWidget(surfaceId)) : nullptr;
|
|
293
|
+
bool fullHeight = chrome && !runsUnderHeaderBar(*chrome);
|
|
294
|
+
if (fullHeight) {
|
|
295
|
+
sidebarChild = adw_toolbar_view_new();
|
|
296
|
+
s.sidebarHeader = adw_header_bar_new();
|
|
297
|
+
adw_header_bar_set_show_title(ADW_HEADER_BAR(s.sidebarHeader), FALSE);
|
|
298
|
+
adw_toolbar_view_add_top_bar(ADW_TOOLBAR_VIEW(sidebarChild), s.sidebarHeader);
|
|
299
|
+
// A compact window shows the sidebar alone while the window's header bar, with the sidebar
|
|
300
|
+
// button, is on the hidden content: this brings the content back.
|
|
301
|
+
s.contentButton = gtk_button_new_from_icon_name("go-next-symbolic");
|
|
302
|
+
gtk_widget_set_tooltip_text(s.contentButton, "Show Content");
|
|
303
|
+
gtk_accessible_update_property(GTK_ACCESSIBLE(s.contentButton), GTK_ACCESSIBLE_PROPERTY_LABEL, "Show Content", -1);
|
|
304
|
+
gtk_widget_set_visible(s.contentButton, FALSE);
|
|
305
|
+
g_signal_connect_data(s.contentButton, "clicked", G_CALLBACK(+[](GtkButton *, gpointer data) {
|
|
306
|
+
auto *t = static_cast<RowTarget *>(data);
|
|
307
|
+
if (auto it = t->splits->splits_.find(t->parent); it != t->splits->splits_.end()) {
|
|
308
|
+
t->splits->toggle(it->second.surfaceId);
|
|
309
|
+
}
|
|
310
|
+
}), new RowTarget{this, split}, [](gpointer data, GClosure *) { delete static_cast<RowTarget *>(data); }, GConnectFlags(0));
|
|
311
|
+
adw_header_bar_pack_start(ADW_HEADER_BAR(s.sidebarHeader), s.contentButton);
|
|
312
|
+
adw_toolbar_view_set_content(ADW_TOOLBAR_VIEW(sidebarChild), s.sidebarSlot);
|
|
313
|
+
contentChild = s.contentToolbar = adw_toolbar_view_new();
|
|
314
|
+
adw_toolbar_view_set_content(ADW_TOOLBAR_VIEW(contentChild), s.contentSlot);
|
|
315
|
+
}
|
|
316
|
+
if (s.tabs && !window) {
|
|
317
|
+
// A tabs host that is not the window's has no header bar of its own to carry a sidebar button,
|
|
318
|
+
// and its tab list is its sidebar: a button over the content brings it forward while compact.
|
|
319
|
+
GtkWidget *overlay = gtk_overlay_new();
|
|
320
|
+
gtk_overlay_set_child(GTK_OVERLAY(overlay), contentChild);
|
|
321
|
+
s.sidebarButton = gtk_button_new_from_icon_name("sidebar-show-symbolic");
|
|
322
|
+
gtk_widget_add_css_class(s.sidebarButton, "circular");
|
|
323
|
+
gtk_widget_set_halign(s.sidebarButton, GTK_ALIGN_START);
|
|
324
|
+
gtk_widget_set_valign(s.sidebarButton, GTK_ALIGN_START);
|
|
325
|
+
gtk_widget_set_margin_start(s.sidebarButton, 6);
|
|
326
|
+
gtk_widget_set_margin_top(s.sidebarButton, 6);
|
|
327
|
+
gtk_widget_set_tooltip_text(s.sidebarButton, "Show Tabs");
|
|
328
|
+
gtk_accessible_update_property(GTK_ACCESSIBLE(s.sidebarButton), GTK_ACCESSIBLE_PROPERTY_LABEL, "Show Tabs", -1);
|
|
329
|
+
gtk_widget_set_visible(s.sidebarButton, FALSE);
|
|
330
|
+
g_signal_connect_data(s.sidebarButton, "clicked", G_CALLBACK(+[](GtkButton *, gpointer data) {
|
|
331
|
+
auto *t = static_cast<RowTarget *>(data);
|
|
332
|
+
t->splits->toggleHost(t->parent);
|
|
333
|
+
}), new RowTarget{this, split}, [](gpointer data, GClosure *) { delete static_cast<RowTarget *>(data); }, GConnectFlags(0));
|
|
334
|
+
gtk_overlay_add_overlay(GTK_OVERLAY(overlay), s.sidebarButton);
|
|
335
|
+
contentChild = overlay;
|
|
336
|
+
}
|
|
337
|
+
AdwNavigationPage *sidebar = adw_navigation_page_new(sidebarChild, "Sidebar");
|
|
338
|
+
// Titled by the sidebar's selected row (titleContent), or a tabs host's chosen tab: none until then.
|
|
339
|
+
AdwNavigationPage *content = adw_navigation_page_new(contentChild, "");
|
|
340
|
+
// The router's back and forward are the only history: the stack's own pop is off.
|
|
341
|
+
adw_navigation_page_set_can_pop(content, FALSE);
|
|
342
|
+
adw_navigation_split_view_set_sidebar(ADW_NAVIGATION_SPLIT_VIEW(s.view), sidebar);
|
|
343
|
+
adw_navigation_split_view_set_content(ADW_NAVIGATION_SPLIT_VIEW(s.view), content);
|
|
344
|
+
s.bin = GTK_WIDGET(g_object_ref_sink(adw_breakpoint_bin_new()));
|
|
345
|
+
// Smaller than the breakpoint, as the bin asks; the split view takes what Yoga gives the view.
|
|
346
|
+
gtk_widget_set_size_request(s.bin, 1, 1);
|
|
347
|
+
adw_breakpoint_bin_set_child(ADW_BREAKPOINT_BIN(s.bin), s.view);
|
|
348
|
+
s.breakpoint = adw_breakpoint_new(adw_breakpoint_condition_new_length(ADW_BREAKPOINT_CONDITION_MAX_WIDTH, 1, ADW_LENGTH_UNIT_PX));
|
|
349
|
+
auto *target = new RowTarget{this, split};
|
|
350
|
+
g_signal_connect_data(s.breakpoint, "apply", G_CALLBACK(+[](AdwBreakpoint *, gpointer data) {
|
|
351
|
+
auto *t = static_cast<RowTarget *>(data);
|
|
352
|
+
t->splits->setCompact(t->parent, true);
|
|
353
|
+
}), target, [](gpointer data, GClosure *) { delete static_cast<RowTarget *>(data); }, GConnectFlags(0));
|
|
354
|
+
g_signal_connect_data(s.breakpoint, "unapply", G_CALLBACK(+[](AdwBreakpoint *, gpointer data) {
|
|
355
|
+
auto *t = static_cast<RowTarget *>(data);
|
|
356
|
+
t->splits->setCompact(t->parent, false);
|
|
357
|
+
}), new RowTarget(*target), [](gpointer data, GClosure *) { delete static_cast<RowTarget *>(data); }, GConnectFlags(0));
|
|
358
|
+
adw_breakpoint_bin_add_breakpoint(ADW_BREAKPOINT_BIN(s.bin), s.breakpoint);
|
|
359
|
+
d->split = s.bin;
|
|
360
|
+
gtk_widget_set_parent(s.bin, widget);
|
|
361
|
+
if (s.tabs) {
|
|
362
|
+
// The tabs fill the sidebar's page; the screens share the content's, which is a container of
|
|
363
|
+
// its own rooted at the host, as on macOS.
|
|
364
|
+
s.tabList = gtk_scrolled_window_new();
|
|
365
|
+
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(s.tabList), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
|
|
366
|
+
gtk_widget_set_parent(s.tabList, s.sidebarSlot);
|
|
367
|
+
NGN_PANE_SLOT(s.contentSlot)->pane = split;
|
|
368
|
+
backend_.hooks.containerRoot(split, true);
|
|
369
|
+
backend_.hooks.attachInput(s.contentSlot, surfaceId, split);
|
|
370
|
+
}
|
|
371
|
+
// The panes (a tabs host's screens) already mounted, found before hosting moves them out.
|
|
372
|
+
std::vector<Tag> panes;
|
|
373
|
+
for (GtkWidget *c = gtk_widget_get_first_child(widget); c; c = gtk_widget_get_next_sibling(c)) {
|
|
374
|
+
ViewData *child = viewData(c);
|
|
375
|
+
bool pane = child && (s.tabs ? child->component == kTabScreen
|
|
376
|
+
: child->component == SidebarComponentName || child->component == SplitContentComponentName);
|
|
377
|
+
if (pane) {
|
|
378
|
+
panes.push_back(child->tag);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
for (Tag pane : panes) {
|
|
382
|
+
if (s.tabs) {
|
|
383
|
+
hostScreen(s, pane);
|
|
384
|
+
} else {
|
|
385
|
+
host(s, pane);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
if (s.tabs) {
|
|
389
|
+
showTabList(split);
|
|
390
|
+
}
|
|
391
|
+
applySidebar(s);
|
|
392
|
+
show(s);
|
|
393
|
+
gtk_widget_queue_allocate(widget);
|
|
394
|
+
if (fullHeight) {
|
|
395
|
+
placeHeader(surfaceId);
|
|
396
|
+
// A header bar in a page shows the page's title when it has no title widget of its own: the
|
|
397
|
+
// window's, as it showed over the whole window.
|
|
398
|
+
// libadwaita asks every page for a title, so an untitled window leaves the page's.
|
|
399
|
+
// The surface's window: a split view placed inside a screen still being pushed has no root yet.
|
|
400
|
+
// A tabs host's page takes the chosen tab's title instead (showTabList).
|
|
401
|
+
GtkRoot *root = s.tabs ? nullptr : gtk_widget_get_root(backend_.surfaceWidget(surfaceId));
|
|
402
|
+
if (root && GTK_IS_WINDOW(root)) {
|
|
403
|
+
g_object_bind_property_full(
|
|
404
|
+
root, "title", content, "title", G_BINDING_SYNC_CREATE,
|
|
405
|
+
+[](GBinding *, const GValue *from, GValue *to, gpointer) -> gboolean {
|
|
406
|
+
const char *title = g_value_get_string(from);
|
|
407
|
+
if (!title || !*title) {
|
|
408
|
+
return FALSE;
|
|
409
|
+
}
|
|
410
|
+
g_value_set_string(to, title);
|
|
411
|
+
return TRUE;
|
|
412
|
+
},
|
|
413
|
+
nullptr, nullptr, nullptr);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
if (window) {
|
|
417
|
+
backend_.headers().refreshChrome(surfaceId);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
void SplitViews::applySidebar(Split &s) {
|
|
422
|
+
applyWidths(s);
|
|
423
|
+
const auto *p = paneProps(backend_.data(s.sidebar));
|
|
424
|
+
if (!p) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
s.collapsedProp = p->collapsed;
|
|
428
|
+
if (auto collapsed = s.collapse.propChanged(p->collapsed)) {
|
|
429
|
+
s.folding.setCollapsed(*collapsed);
|
|
430
|
+
}
|
|
431
|
+
// What the user left it as last time wins over the app's prop, which hears of it, as an
|
|
432
|
+
// NSSplitView's autosave restores its divider on macOS.
|
|
433
|
+
auto key = sidebarCollapsedKey(p->autosaveName);
|
|
434
|
+
if (auto saved = key && readPreference ? savedSidebarCollapsed(readPreference(*key)) : std::nullopt) {
|
|
435
|
+
if (s.collapse.toolkitChanged(*saved)) {
|
|
436
|
+
send(backend_.data(s.sidebar), "sidebarCollapse", folly::dynamic::object("collapsed", *saved));
|
|
437
|
+
}
|
|
438
|
+
s.folding.setCollapsed(*saved);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
void SplitViews::host(Split &s, Tag pane) {
|
|
443
|
+
const ViewData *d = backend_.data(pane);
|
|
444
|
+
if (!d) {
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
bool sidebar = d->component == SidebarComponentName;
|
|
448
|
+
GtkWidget *slot = sidebar ? s.sidebarSlot : s.contentSlot;
|
|
449
|
+
(sidebar ? s.sidebar : s.content) = pane;
|
|
450
|
+
NGN_PANE_SLOT(slot)->pane = pane;
|
|
451
|
+
backend_.hostView(pane, slot);
|
|
452
|
+
backend_.hooks.containerRoot(pane, true);
|
|
453
|
+
backend_.hooks.attachInput(slot, s.surfaceId, pane);
|
|
454
|
+
// A sidebar whose lists were filled before it came here titles the content now: its own, and
|
|
455
|
+
// those of views within it, which are kept by their own tags.
|
|
456
|
+
if (GtkWidget *widget = sidebar ? backend_.view(pane) : nullptr) {
|
|
457
|
+
titleContent(widget, nullptr);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
void SplitViews::hostScreen(Split &s, Tag screen) {
|
|
462
|
+
// A screen Fabric moved here from another tabs host leaves that host's list, which would
|
|
463
|
+
// otherwise unhost it, and size it, as it goes.
|
|
464
|
+
for (auto &[tag, other] : splits_) {
|
|
465
|
+
if (&other != &s) {
|
|
466
|
+
std::erase(other.screens, screen);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
backend_.hostView(screen, s.contentSlot);
|
|
470
|
+
if (std::find(s.screens.begin(), s.screens.end(), screen) == s.screens.end()) {
|
|
471
|
+
s.screens.push_back(screen);
|
|
472
|
+
}
|
|
473
|
+
// A screen added later takes the size the others have.
|
|
474
|
+
if (int w = gtk_widget_get_width(s.contentSlot), h = gtk_widget_get_height(s.contentSlot); w > 0 && h > 0) {
|
|
475
|
+
reportSizeFromSlot(NGN_PANE_SLOT(s.contentSlot)->pane, w, h);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
void SplitViews::showTabList(Tag split) {
|
|
480
|
+
auto it = splits_.find(split);
|
|
481
|
+
auto l = lists_.find(split);
|
|
482
|
+
if (it == splits_.end() || !it->second.tabList || l == lists_.end() || l->second.boxes.empty()) {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
// The content page's title, which the header bar shows when the tab's screen sets none of its own.
|
|
486
|
+
auto chosen = selectedRow(l->second.lists[0]);
|
|
487
|
+
for (const auto &group : l->second.lists[0].groups) {
|
|
488
|
+
for (const auto &row : group.rows) {
|
|
489
|
+
if (chosen == row.tag && !row.label.empty()) {
|
|
490
|
+
adw_navigation_page_set_title(adw_navigation_split_view_get_content(ADW_NAVIGATION_SPLIT_VIEW(it->second.view)), row.label.c_str());
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
GtkWidget *box = l->second.boxes[0];
|
|
495
|
+
GtkWidget *viewport = gtk_widget_get_parent(box);
|
|
496
|
+
if (viewport && gtk_widget_get_parent(viewport) == it->second.tabList) {
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
detachBox(box);
|
|
500
|
+
gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(it->second.tabList), box);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
void SplitViews::inserted(Tag parent, Tag child) {
|
|
504
|
+
auto it = splits_.find(parent);
|
|
505
|
+
const ViewData *d = backend_.data(child);
|
|
506
|
+
if (it != splits_.end() && it->second.tabs) {
|
|
507
|
+
if (d && d->component == kTabScreen) {
|
|
508
|
+
hostScreen(it->second, child);
|
|
509
|
+
}
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
if (it == splits_.end()) {
|
|
513
|
+
retitleSidebarsHolding(parent);
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
if (!d || (d->component != SidebarComponentName && d->component != SplitContentComponentName)) {
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
host(it->second, child);
|
|
520
|
+
if (d->component == SidebarComponentName) {
|
|
521
|
+
applySidebar(it->second);
|
|
522
|
+
show(it->second);
|
|
523
|
+
}
|
|
524
|
+
// A split in another's sidebar: the pane's lists may title that one's content too.
|
|
525
|
+
retitleSidebarsHolding(parent);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
void SplitViews::removed(Tag parent, Tag child) {
|
|
529
|
+
// The sidebar out of its split, kept for another place: no row of it titles this content, and
|
|
530
|
+
// nothing it selects after does. `host` makes it the split's again, put back.
|
|
531
|
+
if (auto it = splits_.find(parent); it != splits_.end() && !it->second.tabs && it->second.sidebar == child) {
|
|
532
|
+
Split &s = it->second;
|
|
533
|
+
adw_navigation_page_set_title(adw_navigation_split_view_get_content(ADW_NAVIGATION_SPLIT_VIEW(s.view)), "");
|
|
534
|
+
// What `host` registered for it, let go here: once the split has forgotten it, `deleted`
|
|
535
|
+
// would not.
|
|
536
|
+
backend_.hooks.detachInput(child);
|
|
537
|
+
backend_.hooks.containerRoot(child, false);
|
|
538
|
+
s.sidebar = -1;
|
|
539
|
+
NGN_PANE_SLOT(s.sidebarSlot)->pane = -1;
|
|
540
|
+
}
|
|
541
|
+
// And a split whose sidebar holds this one, nested: its rows may have titled that content too.
|
|
542
|
+
retitleSidebarsHolding(parent);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
void SplitViews::retitleSidebarsHolding(Tag parent) {
|
|
546
|
+
GtkWidget *from = backend_.view(parent);
|
|
547
|
+
if (!from) {
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
// Lists under a view of their own in a sidebar came or went with it: the content is titled by
|
|
551
|
+
// what the sidebar holds now, or by nothing.
|
|
552
|
+
for (const auto &[tag, s] : splits_) {
|
|
553
|
+
GtkWidget *pane = s.sidebar >= 0 ? backend_.view(s.sidebar) : nullptr;
|
|
554
|
+
if (!s.tabs && pane && (from == pane || gtk_widget_is_ancestor(from, pane))) {
|
|
555
|
+
titleContent(pane, nullptr);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
std::optional<Tag> SplitViews::splitOf(Tag pane) const {
|
|
561
|
+
for (const auto &[tag, s] : splits_) {
|
|
562
|
+
if (s.sidebar == pane || s.content == pane) {
|
|
563
|
+
return tag;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
return std::nullopt;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
void SplitViews::applyWidths(Split &s) {
|
|
570
|
+
s.widths = sidebarWidths(paneProps(backend_.data(s.sidebar)));
|
|
571
|
+
auto *view = ADW_NAVIGATION_SPLIT_VIEW(s.view);
|
|
572
|
+
// From the narrowest to the width it starts at, as the window allows: libadwaita's split view
|
|
573
|
+
// has no divider to drag.
|
|
574
|
+
adw_navigation_split_view_set_min_sidebar_width(view, s.widths.minimum);
|
|
575
|
+
adw_navigation_split_view_set_max_sidebar_width(view, s.widths.starting);
|
|
576
|
+
adw_navigation_split_view_set_sidebar_width_fraction(view, 0.25);
|
|
577
|
+
// Compact below the core's width: the breakpoint applies up to a pixel under it.
|
|
578
|
+
double compact = std::max<double>(1, std::ceil(sidebarCompactWidth(s.widths)) - 1);
|
|
579
|
+
adw_breakpoint_set_condition(s.breakpoint, adw_breakpoint_condition_new_length(ADW_BREAKPOINT_CONDITION_MAX_WIDTH, compact, ADW_LENGTH_UNIT_PX));
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
void SplitViews::show(Split &s) {
|
|
583
|
+
auto showing = s.folding.showing();
|
|
584
|
+
auto *view = ADW_NAVIGATION_SPLIT_VIEW(s.view);
|
|
585
|
+
if (adw_navigation_split_view_get_collapsed(view) != showing.stacked) {
|
|
586
|
+
adw_navigation_split_view_set_collapsed(view, showing.stacked);
|
|
587
|
+
}
|
|
588
|
+
if (adw_navigation_split_view_get_show_content(view) != showing.content) {
|
|
589
|
+
adw_navigation_split_view_set_show_content(view, showing.content);
|
|
590
|
+
}
|
|
591
|
+
if (s.contentButton) {
|
|
592
|
+
gtk_widget_set_visible(s.contentButton, showing.stacked && !showing.content);
|
|
593
|
+
}
|
|
594
|
+
// The sidebar button moves with the sidebar: over it beside the content, else to the window's
|
|
595
|
+
// header bar.
|
|
596
|
+
if (s.sidebarButton) {
|
|
597
|
+
gtk_widget_set_visible(s.sidebarButton, showing.stacked && showing.content);
|
|
598
|
+
}
|
|
599
|
+
bool overSidebar = s.window && s.sidebarHeader && !showing.stacked;
|
|
600
|
+
if (overSidebar != s.buttonOverSidebar) {
|
|
601
|
+
s.buttonOverSidebar = overSidebar;
|
|
602
|
+
backend_.headers().refreshChrome(s.surfaceId);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
void SplitViews::propsChanged(Tag tag) {
|
|
607
|
+
auto split = splitOf(tag);
|
|
608
|
+
if (!split) {
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
auto &s = splits_[*split];
|
|
612
|
+
if (tag != s.sidebar) {
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
applyWidths(s);
|
|
616
|
+
// Only a change of the collapsed input reaches the toolkit: an unrelated update (a width) leaves
|
|
617
|
+
// the state the user or a saved preference set.
|
|
618
|
+
if (const auto *p = paneProps(backend_.data(tag)); p && s.collapsedProp != p->collapsed) {
|
|
619
|
+
s.collapsedProp = p->collapsed;
|
|
620
|
+
if (auto collapsed = s.collapse.propChanged(p->collapsed)) {
|
|
621
|
+
s.folding.setCollapsed(*collapsed);
|
|
622
|
+
show(s);
|
|
623
|
+
autosave(s);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
void SplitViews::autosave(const Split &s) {
|
|
629
|
+
const auto *p = paneProps(backend_.data(s.sidebar));
|
|
630
|
+
auto key = p ? sidebarCollapsedKey(p->autosaveName) : std::nullopt;
|
|
631
|
+
if (key && writePreference) {
|
|
632
|
+
writePreference(*key, folly::dynamic(s.collapse.collapsed()));
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
GtkWidget *SplitViews::sidebarHeaderShown(SurfaceId surfaceId) const {
|
|
637
|
+
for (const auto &[tag, s] : splits_) {
|
|
638
|
+
if (s.surfaceId == surfaceId && s.window && s.sidebarHeader && !s.folding.showing().stacked) {
|
|
639
|
+
return s.sidebarHeader;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
return nullptr;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
void SplitViews::setCompact(Tag split, bool compact) {
|
|
646
|
+
auto it = splits_.find(split);
|
|
647
|
+
if (it == splits_.end() || it->second.folding.compact() == compact) {
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
it->second.folding.setCompact(compact);
|
|
651
|
+
show(it->second);
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
std::optional<Tag> SplitViews::windowSplit(SurfaceId surfaceId) const {
|
|
655
|
+
for (const auto &[tag, s] : splits_) {
|
|
656
|
+
if (s.surfaceId == surfaceId && s.window) {
|
|
657
|
+
return tag;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
return std::nullopt;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
bool SplitViews::toggle(SurfaceId surfaceId) {
|
|
664
|
+
auto split = windowSplit(surfaceId);
|
|
665
|
+
return split && toggleHost(*split);
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
bool SplitViews::toggleHost(Tag split) {
|
|
669
|
+
auto it = splits_.find(split);
|
|
670
|
+
if (it == splits_.end()) {
|
|
671
|
+
return false;
|
|
672
|
+
}
|
|
673
|
+
auto &s = it->second;
|
|
674
|
+
auto collapsed = s.folding.toggle();
|
|
675
|
+
if (collapsed && s.collapse.toolkitChanged(*collapsed)) {
|
|
676
|
+
send(backend_.data(s.sidebar), "sidebarCollapse", folly::dynamic::object("collapsed", *collapsed));
|
|
677
|
+
}
|
|
678
|
+
show(s);
|
|
679
|
+
if (collapsed) {
|
|
680
|
+
autosave(s);
|
|
681
|
+
}
|
|
682
|
+
return true;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
void SplitViews::deleted(Tag tag) {
|
|
686
|
+
sizes_.forget(tag);
|
|
687
|
+
if (auto it = splits_.find(tag); it != splits_.end()) {
|
|
688
|
+
SurfaceId surfaceId = it->second.surfaceId;
|
|
689
|
+
bool window = it->second.window;
|
|
690
|
+
if (ViewData *d = backend_.data(tag)) {
|
|
691
|
+
d->split = nullptr;
|
|
692
|
+
}
|
|
693
|
+
tearDown(it->second);
|
|
694
|
+
splits_.erase(it);
|
|
695
|
+
if (window) {
|
|
696
|
+
placeHeader(surfaceId);
|
|
697
|
+
backend_.headers().refreshChrome(surfaceId);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
reported_.erase(tag);
|
|
701
|
+
for (auto &[split, s] : splits_) {
|
|
702
|
+
std::erase(s.screens, tag);
|
|
703
|
+
// The content's title is the deleted sidebar's selected row: taken off with it, while the split
|
|
704
|
+
// still knows which sidebar was its own.
|
|
705
|
+
if (s.sidebar == tag && !s.tabs) {
|
|
706
|
+
adw_navigation_page_set_title(adw_navigation_split_view_get_content(ADW_NAVIGATION_SPLIT_VIEW(s.view)), "");
|
|
707
|
+
}
|
|
708
|
+
for (auto [pane, slot] : {std::pair{&s.sidebar, s.sidebarSlot}, std::pair{&s.content, s.contentSlot}}) {
|
|
709
|
+
if (*pane == tag) {
|
|
710
|
+
backend_.hooks.detachInput(tag);
|
|
711
|
+
backend_.hooks.containerRoot(tag, false);
|
|
712
|
+
*pane = -1;
|
|
713
|
+
NGN_PANE_SLOT(slot)->pane = -1;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
if (auto it = lists_.find(tag); it != lists_.end()) {
|
|
718
|
+
setSourceLists(tag, {});
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
// --- Source lists ------------------------------------------------------------------------------
|
|
723
|
+
|
|
724
|
+
void SplitViews::setSourceLists(Tag parent, const std::vector<SourceList> &lists) {
|
|
725
|
+
// Only the selection moved (the app's answer to a choice, or the core's to a tab): the rows stay,
|
|
726
|
+
// since the pointer that chose one may still be on it, and the selection moves.
|
|
727
|
+
auto known = lists_.find(parent);
|
|
728
|
+
bool moved = known != lists_.end() && known->second.lists.size() == lists.size() && known->second.boxes.size() == lists.size() &&
|
|
729
|
+
!lists.empty() && known->second.refill == 0;
|
|
730
|
+
for (size_t i = 0; moved && i < lists.size(); i++) {
|
|
731
|
+
moved = known->second.lists[i] == lists[i] || onlySelectionDiffers(known->second.lists[i], lists[i]);
|
|
732
|
+
}
|
|
733
|
+
if (moved) {
|
|
734
|
+
known->second.lists = lists;
|
|
735
|
+
for (size_t i = 0; i < lists.size(); i++) {
|
|
736
|
+
select(known->second, i);
|
|
737
|
+
}
|
|
738
|
+
showTabList(parent);
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
rebuild(parent, lists);
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
void SplitViews::select(Lists &l, size_t index) {
|
|
745
|
+
GtkWidget *box = l.boxes[index];
|
|
746
|
+
auto selected = selectedRow(l.lists[index]);
|
|
747
|
+
GtkListBoxRow *row = nullptr;
|
|
748
|
+
for (GtkWidget *c = gtk_widget_get_first_child(box); c && selected; c = gtk_widget_get_next_sibling(c)) {
|
|
749
|
+
if (GTK_IS_LIST_BOX_ROW(c) && g_object_get_data(G_OBJECT(c), "ngn-row") == GINT_TO_POINTER(*selected)) {
|
|
750
|
+
row = GTK_LIST_BOX_ROW(c);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
if (gtk_list_box_get_selected_row(GTK_LIST_BOX(box)) == row) {
|
|
754
|
+
// No row changes, so none says so: an item selected or not in a folded section has no row,
|
|
755
|
+
// but titles the content all the same.
|
|
756
|
+
titleContent(box, row);
|
|
757
|
+
return;
|
|
758
|
+
}
|
|
759
|
+
l.syncing = true;
|
|
760
|
+
gtk_list_box_select_row(GTK_LIST_BOX(box), row);
|
|
761
|
+
l.syncing = false;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
void SplitViews::rebuild(Tag parent, const std::vector<SourceList> &lists) {
|
|
765
|
+
auto &l = lists_[parent];
|
|
766
|
+
for (Tag tag : l.hosted) {
|
|
767
|
+
backend_.unhostView(tag);
|
|
768
|
+
backend_.hooks.detachInput(tag);
|
|
769
|
+
backend_.hooks.containerRoot(tag, false);
|
|
770
|
+
}
|
|
771
|
+
l.hosted.clear();
|
|
772
|
+
GtkWidget *parentWidget = backend_.view(parent);
|
|
773
|
+
while (l.boxes.size() > lists.size()) {
|
|
774
|
+
GtkWidget *box = l.boxes.back();
|
|
775
|
+
detachBox(box);
|
|
776
|
+
g_object_unref(box);
|
|
777
|
+
l.boxes.pop_back();
|
|
778
|
+
}
|
|
779
|
+
l.lists = lists;
|
|
780
|
+
if (lists.empty()) {
|
|
781
|
+
// Its rows gone, so is the title they gave the content.
|
|
782
|
+
if (parentWidget) {
|
|
783
|
+
titleContent(parentWidget, nullptr);
|
|
784
|
+
}
|
|
785
|
+
if (l.refill != 0) {
|
|
786
|
+
g_source_remove(l.refill);
|
|
787
|
+
}
|
|
788
|
+
lists_.erase(parent);
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
addSourceListStyle();
|
|
792
|
+
while (l.boxes.size() < lists.size()) {
|
|
793
|
+
GtkWidget *box = GTK_WIDGET(g_object_ref_sink(gtk_list_box_new()));
|
|
794
|
+
gtk_widget_add_css_class(box, "navigation-sidebar");
|
|
795
|
+
gtk_widget_add_css_class(box, "ngn-source-list");
|
|
796
|
+
gtk_list_box_set_selection_mode(GTK_LIST_BOX(box), GTK_SELECTION_SINGLE);
|
|
797
|
+
g_object_set_data_full(G_OBJECT(box), "ngn-frame", new Rect{}, [](gpointer p) { delete static_cast<Rect *>(p); });
|
|
798
|
+
auto *target = new RowTarget{this, parent};
|
|
799
|
+
g_signal_connect_data(box, "row-selected", G_CALLBACK(+[](GtkListBox *list, GtkListBoxRow *row, gpointer data) {
|
|
800
|
+
auto *t = static_cast<RowTarget *>(data);
|
|
801
|
+
t->splits->titleContent(GTK_WIDGET(list), row);
|
|
802
|
+
if (row && g_object_get_data(G_OBJECT(row), "ngn-row")) {
|
|
803
|
+
t->splits->chose(t->parent, GPOINTER_TO_INT(g_object_get_data(G_OBJECT(row), "ngn-row")));
|
|
804
|
+
}
|
|
805
|
+
}), target, [](gpointer data, GClosure *) { delete static_cast<RowTarget *>(data); }, GConnectFlags(0));
|
|
806
|
+
g_signal_connect_data(box, "row-activated", G_CALLBACK(+[](GtkListBox *, GtkListBoxRow *row, gpointer data) {
|
|
807
|
+
auto *t = static_cast<RowTarget *>(data);
|
|
808
|
+
if (gpointer section = g_object_get_data(G_OBJECT(row), "ngn-section")) {
|
|
809
|
+
Tag tag = GPOINTER_TO_INT(section);
|
|
810
|
+
t->splits->fold(t->parent, tag, !t->splits->folded(t->parent, tag));
|
|
811
|
+
}
|
|
812
|
+
}), new RowTarget(*target), [](gpointer data, GClosure *) { delete static_cast<RowTarget *>(data); }, GConnectFlags(0));
|
|
813
|
+
l.boxes.push_back(box);
|
|
814
|
+
}
|
|
815
|
+
// A tabs host's list fills its sidebar instead, once it is placed.
|
|
816
|
+
const ViewData *parentData = backend_.data(parent);
|
|
817
|
+
bool tabs = parentData && parentData->component == kTabsHost;
|
|
818
|
+
for (size_t i = 0; i < lists.size(); i++) {
|
|
819
|
+
l.folds.setList(lists[i]);
|
|
820
|
+
if (!tabs && parentWidget && gtk_widget_get_parent(l.boxes[i]) != parentWidget) {
|
|
821
|
+
gtk_widget_set_parent(l.boxes[i], parentWidget);
|
|
822
|
+
}
|
|
823
|
+
fill(parent, l, i);
|
|
824
|
+
}
|
|
825
|
+
if (tabs) {
|
|
826
|
+
showTabList(parent);
|
|
827
|
+
return;
|
|
828
|
+
}
|
|
829
|
+
layOut();
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
void SplitViews::fill(Tag parent, Lists &l, size_t index) {
|
|
833
|
+
GtkWidget *box = l.boxes[index];
|
|
834
|
+
const SourceList &list = l.lists[index];
|
|
835
|
+
l.syncing = true;
|
|
836
|
+
while (GtkWidget *row = gtk_widget_get_first_child(box)) {
|
|
837
|
+
gtk_list_box_remove(GTK_LIST_BOX(box), row);
|
|
838
|
+
}
|
|
839
|
+
GtkListBoxRow *selected = nullptr;
|
|
840
|
+
auto selectedTag = selectedRow(list);
|
|
841
|
+
for (const auto &group : list.groups) {
|
|
842
|
+
bool folded = group.collapsible && l.folds.folded(group.tag);
|
|
843
|
+
if (!group.title.empty()) {
|
|
844
|
+
GtkWidget *title = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
|
|
845
|
+
GtkWidget *label = gtk_label_new(group.title.c_str());
|
|
846
|
+
gtk_widget_add_css_class(label, "heading");
|
|
847
|
+
gtk_widget_add_css_class(label, "dim-label");
|
|
848
|
+
gtk_label_set_xalign(GTK_LABEL(label), 0);
|
|
849
|
+
gtk_widget_set_hexpand(label, TRUE);
|
|
850
|
+
gtk_box_append(GTK_BOX(title), label);
|
|
851
|
+
if (group.collapsible) {
|
|
852
|
+
gtk_box_append(GTK_BOX(title), gtk_image_new_from_icon_name(folded ? "pan-end-symbolic" : "pan-down-symbolic"));
|
|
853
|
+
}
|
|
854
|
+
GtkWidget *row = gtk_list_box_row_new();
|
|
855
|
+
gtk_list_box_row_set_child(GTK_LIST_BOX_ROW(row), title);
|
|
856
|
+
gtk_list_box_row_set_selectable(GTK_LIST_BOX_ROW(row), FALSE);
|
|
857
|
+
gtk_list_box_row_set_activatable(GTK_LIST_BOX_ROW(row), group.collapsible);
|
|
858
|
+
gtk_widget_add_css_class(row, "ngn-section-title");
|
|
859
|
+
gtk_accessible_update_property(GTK_ACCESSIBLE(row), GTK_ACCESSIBLE_PROPERTY_LABEL, group.title.c_str(), -1);
|
|
860
|
+
if (group.collapsible) {
|
|
861
|
+
g_object_set_data(G_OBJECT(row), "ngn-section", GINT_TO_POINTER(group.tag));
|
|
862
|
+
gtk_accessible_update_state(GTK_ACCESSIBLE(row), GTK_ACCESSIBLE_STATE_EXPANDED, !folded, -1);
|
|
863
|
+
}
|
|
864
|
+
gtk_list_box_append(GTK_LIST_BOX(box), row);
|
|
865
|
+
}
|
|
866
|
+
if (folded) {
|
|
867
|
+
continue;
|
|
868
|
+
}
|
|
869
|
+
for (const auto &r : group.rows) {
|
|
870
|
+
GtkWidget *row = gtk_list_box_row_new();
|
|
871
|
+
g_object_set_data(G_OBJECT(row), "ngn-row", GINT_TO_POINTER(r.tag));
|
|
872
|
+
g_object_set_data_full(G_OBJECT(row), "ngn-label", g_strdup(r.label.c_str()), g_free);
|
|
873
|
+
if (r.custom) {
|
|
874
|
+
// The item's own views, in a slot of the row that is a container of its own.
|
|
875
|
+
GtkWidget *slot = makeHostSlot();
|
|
876
|
+
backend_.hostView(r.tag, slot);
|
|
877
|
+
if (const ViewData *d = backend_.data(r.tag)) {
|
|
878
|
+
backend_.hooks.containerRoot(r.tag, true);
|
|
879
|
+
backend_.hooks.attachInput(slot, d->surfaceId, r.tag);
|
|
880
|
+
}
|
|
881
|
+
l.hosted.push_back(r.tag);
|
|
882
|
+
gtk_list_box_row_set_child(GTK_LIST_BOX_ROW(row), slot);
|
|
883
|
+
} else {
|
|
884
|
+
GtkWidget *content = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
|
|
885
|
+
GtkWidget *label = gtk_label_new(r.label.c_str());
|
|
886
|
+
gtk_label_set_xalign(GTK_LABEL(label), 0);
|
|
887
|
+
gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END);
|
|
888
|
+
gtk_widget_set_hexpand(label, TRUE);
|
|
889
|
+
gtk_box_append(GTK_BOX(content), label);
|
|
890
|
+
if (!r.badge.empty()) {
|
|
891
|
+
GtkWidget *badge = gtk_label_new(r.badge.c_str());
|
|
892
|
+
gtk_widget_add_css_class(badge, "dim-label");
|
|
893
|
+
gtk_box_append(GTK_BOX(content), badge);
|
|
894
|
+
}
|
|
895
|
+
gtk_list_box_row_set_child(GTK_LIST_BOX_ROW(row), content);
|
|
896
|
+
}
|
|
897
|
+
gtk_list_box_append(GTK_LIST_BOX(box), row);
|
|
898
|
+
if (selectedTag == r.tag) {
|
|
899
|
+
selected = GTK_LIST_BOX_ROW(row);
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
gtk_list_box_select_row(GTK_LIST_BOX(box), selected);
|
|
904
|
+
// Said again: a refill that keeps the same row selected may emit nothing.
|
|
905
|
+
titleContent(box, selected);
|
|
906
|
+
l.syncing = false;
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
void SplitViews::titleContent(GtkWidget *within, GtkListBoxRow *row) {
|
|
910
|
+
for (auto &[tag, s] : splits_) {
|
|
911
|
+
GtkWidget *pane = s.sidebar >= 0 ? backend_.view(s.sidebar) : nullptr;
|
|
912
|
+
if (s.tabs || !pane || !(within == pane || gtk_widget_is_ancestor(within, pane))) {
|
|
913
|
+
continue;
|
|
914
|
+
}
|
|
915
|
+
// The sidebar's selected row, whichever of its lists holds it, not the row of the list that
|
|
916
|
+
// asked: a list with nothing selected, filled after the one that has it, would clear the title.
|
|
917
|
+
// The app selects one row in a sidebar; were there more, the first list's would title it.
|
|
918
|
+
// A row the user picked, before the app hears of it, or else the item the app selects, which a
|
|
919
|
+
// folded section shows no row for.
|
|
920
|
+
// The row just selected, first: another list may still hold the one selected before it.
|
|
921
|
+
const char *label = row ? static_cast<const char *>(g_object_get_data(G_OBJECT(row), "ngn-label")) : nullptr;
|
|
922
|
+
for (const auto &[parent, l] : lists_) {
|
|
923
|
+
for (size_t i = 0; i < l.boxes.size() && !label; i++) {
|
|
924
|
+
GtkWidget *box = l.boxes[i];
|
|
925
|
+
if (!(box == pane || gtk_widget_is_ancestor(box, pane))) {
|
|
926
|
+
continue;
|
|
927
|
+
}
|
|
928
|
+
if (GtkListBoxRow *selected = gtk_list_box_get_selected_row(GTK_LIST_BOX(box))) {
|
|
929
|
+
label = static_cast<const char *>(g_object_get_data(G_OBJECT(selected), "ngn-label"));
|
|
930
|
+
} else if (i < l.lists.size()) {
|
|
931
|
+
label = selectedLabel(l.lists[i]);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
adw_navigation_page_set_title(adw_navigation_split_view_get_content(ADW_NAVIGATION_SPLIT_VIEW(s.view)), label ? label : "");
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
void SplitViews::layOut() {
|
|
940
|
+
for (auto &[parent, l] : lists_) {
|
|
941
|
+
for (size_t i = 0; i < l.boxes.size() && i < l.lists.size(); i++) {
|
|
942
|
+
std::optional<Rect> frame;
|
|
943
|
+
for (const auto &group : l.lists[i].groups) {
|
|
944
|
+
const ViewData *section = backend_.data(group.tag);
|
|
945
|
+
if (!section) {
|
|
946
|
+
continue;
|
|
947
|
+
}
|
|
948
|
+
Rect f = section->layout.frame;
|
|
949
|
+
if (!frame) {
|
|
950
|
+
frame = f;
|
|
951
|
+
} else {
|
|
952
|
+
Float left = std::min(frame->origin.x, f.origin.x), top = std::min(frame->origin.y, f.origin.y);
|
|
953
|
+
Float right = std::max(frame->origin.x + frame->size.width, f.origin.x + f.size.width);
|
|
954
|
+
Float bottom = std::max(frame->origin.y + frame->size.height, f.origin.y + f.size.height);
|
|
955
|
+
frame = Rect{{left, top}, {right - left, bottom - top}};
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
auto *held = static_cast<Rect *>(g_object_get_data(G_OBJECT(l.boxes[i]), "ngn-frame"));
|
|
959
|
+
if (frame && held && *held != *frame) {
|
|
960
|
+
*held = *frame;
|
|
961
|
+
if (GtkWidget *p = gtk_widget_get_parent(l.boxes[i])) {
|
|
962
|
+
gtk_widget_queue_allocate(p);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
void SplitViews::chose(Tag parent, Tag row) {
|
|
970
|
+
auto it = lists_.find(parent);
|
|
971
|
+
if (it == lists_.end() || it->second.syncing) {
|
|
972
|
+
return;
|
|
973
|
+
}
|
|
974
|
+
if (auto split = splits_.find(parent); split != splits_.end() && split->second.tabs) {
|
|
975
|
+
chosenTab_ = {split->second.surfaceId, parent, row};
|
|
976
|
+
if (choose_ == 0) {
|
|
977
|
+
choose_ = g_idle_add_full(G_PRIORITY_DEFAULT, [](gpointer self) -> gboolean {
|
|
978
|
+
auto *splits = static_cast<SplitViews *>(self);
|
|
979
|
+
splits->choose_ = 0;
|
|
980
|
+
auto chosen = splits->chosenTab_;
|
|
981
|
+
splits->backend_.hooks.chooseTab(chosen.surfaceId, chosen.host, chosen.screen);
|
|
982
|
+
return G_SOURCE_REMOVE;
|
|
983
|
+
}, this, nullptr);
|
|
984
|
+
}
|
|
985
|
+
// At a compact width the choice brings the content forward.
|
|
986
|
+
if (split->second.folding.compact()) {
|
|
987
|
+
split->second.folding.chose();
|
|
988
|
+
show(split->second);
|
|
989
|
+
}
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
send(backend_.data(row), "sidebarSelect", folly::dynamic::object());
|
|
993
|
+
// At a compact width the choice brings the content forward.
|
|
994
|
+
for (auto &[tag, s] : splits_) {
|
|
995
|
+
if (s.folding.compact() && s.sidebar >= 0) {
|
|
996
|
+
if (GtkWidget *pane = backend_.view(s.sidebar), *list = backend_.view(parent); pane && list && (list == pane || gtk_widget_is_ancestor(list, pane))) {
|
|
997
|
+
s.folding.chose();
|
|
998
|
+
show(s);
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
bool SplitViews::folded(Tag parent, Tag section) const {
|
|
1005
|
+
auto it = lists_.find(parent);
|
|
1006
|
+
return it != lists_.end() && it->second.folds.folded(section);
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
void SplitViews::fold(Tag parent, Tag section, bool folded) {
|
|
1010
|
+
auto it = lists_.find(parent);
|
|
1011
|
+
if (it == lists_.end()) {
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
auto &l = it->second;
|
|
1015
|
+
l.folds.fold(section, folded);
|
|
1016
|
+
// The section's layout follows: a folded one is only its title row.
|
|
1017
|
+
if (const ViewData *d = backend_.data(section)) {
|
|
1018
|
+
if (auto state = std::dynamic_pointer_cast<const ConcreteState<SidebarSectionState>>(d->state);
|
|
1019
|
+
state && state->getData().collapsed != folded) {
|
|
1020
|
+
state->updateState(SidebarSectionState{.collapsed = folded});
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
// Rebuilt on the next idle, at most once: the row activated is the list's own until its signal
|
|
1024
|
+
// returns.
|
|
1025
|
+
if (l.refill == 0) {
|
|
1026
|
+
l.refill = g_idle_add_full(G_PRIORITY_DEFAULT, [](gpointer data) -> gboolean {
|
|
1027
|
+
auto *t = static_cast<RowTarget *>(data);
|
|
1028
|
+
if (auto it = t->splits->lists_.find(t->parent); it != t->splits->lists_.end()) {
|
|
1029
|
+
it->second.refill = 0;
|
|
1030
|
+
}
|
|
1031
|
+
t->splits->refill(t->parent);
|
|
1032
|
+
return G_SOURCE_REMOVE;
|
|
1033
|
+
}, new RowTarget{this, parent}, [](gpointer data) { delete static_cast<RowTarget *>(data); });
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
void SplitViews::refill(Tag parent) {
|
|
1038
|
+
auto it = lists_.find(parent);
|
|
1039
|
+
if (it == lists_.end()) {
|
|
1040
|
+
return;
|
|
1041
|
+
}
|
|
1042
|
+
rebuild(parent, std::vector<SourceList>(it->second.lists));
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
GtkWidget *SplitViews::splitWidget(Tag split) const {
|
|
1046
|
+
auto it = splits_.find(split);
|
|
1047
|
+
return it == splits_.end() ? nullptr : it->second.view;
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
GtkWidget *SplitViews::contentButton(Tag split) const {
|
|
1051
|
+
auto it = splits_.find(split);
|
|
1052
|
+
return it == splits_.end() ? nullptr : it->second.contentButton;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
AdwBreakpoint *SplitViews::breakpoint(Tag split) const {
|
|
1056
|
+
auto it = splits_.find(split);
|
|
1057
|
+
return it == splits_.end() ? nullptr : it->second.breakpoint;
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
std::vector<GtkWidget *> SplitViews::lists(Tag parent) const {
|
|
1061
|
+
auto it = lists_.find(parent);
|
|
1062
|
+
return it == lists_.end() ? std::vector<GtkWidget *>{} : it->second.boxes;
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
// --- Sizes -------------------------------------------------------------------------------------
|
|
1066
|
+
|
|
1067
|
+
void SplitViews::reportSizeFromSlot(Tag pane, int width, int height) {
|
|
1068
|
+
Size size{static_cast<Float>(width), static_cast<Float>(height)};
|
|
1069
|
+
reported_[pane] = size;
|
|
1070
|
+
// A tabs host's content slot sizes every screen still in it.
|
|
1071
|
+
auto split = splits_.find(pane);
|
|
1072
|
+
bool tabs = split != splits_.end() && split->second.tabs;
|
|
1073
|
+
bool changed = false;
|
|
1074
|
+
for (Tag target : tabs ? split->second.screens : std::vector<Tag>{pane}) {
|
|
1075
|
+
if (!tabs || backend_.isHosted(target)) {
|
|
1076
|
+
changed = sizes_.report(target, size) || changed;
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
if (changed && flush_ == 0) {
|
|
1080
|
+
// Once a frame at most, however many allocations a resize takes.
|
|
1081
|
+
flush_ = g_idle_add_full(G_PRIORITY_DEFAULT, [](gpointer self) -> gboolean {
|
|
1082
|
+
auto *splits = static_cast<SplitViews *>(self);
|
|
1083
|
+
splits->flush_ = 0;
|
|
1084
|
+
splits->flushSizes();
|
|
1085
|
+
return G_SOURCE_REMOVE;
|
|
1086
|
+
}, this, nullptr);
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
void SplitViews::flushSizes() {
|
|
1091
|
+
for (const auto &[tag, size] : sizes_.flush()) {
|
|
1092
|
+
const ViewData *d = backend_.data(tag);
|
|
1093
|
+
auto state = d ? std::dynamic_pointer_cast<const ConcreteState<SplitPaneState>>(d->state) : nullptr;
|
|
1094
|
+
if (state && state->getData().size != size) {
|
|
1095
|
+
state->updateState(SplitPaneState{.size = size});
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
std::optional<Size> SplitViews::paneSize(Tag pane) const {
|
|
1101
|
+
auto it = reported_.find(pane);
|
|
1102
|
+
return it == reported_.end() ? std::nullopt : std::optional(it->second);
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
} // namespace ngn::gtk
|