basalt-gtk 0.0.0-rc5

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 (71) hide show
  1. package/LICENSE +21 -0
  2. package/cli/runLinux.js +29 -0
  3. package/cli/shared.js +75 -0
  4. package/native/CMakeLists.txt +362 -0
  5. package/native/gtk/ColorSchemeGtk.cpp +58 -0
  6. package/native/gtk/ComponentRegistryGtk.cpp +101 -0
  7. package/native/gtk/FontRegistryFontconfig.cpp +127 -0
  8. package/native/gtk/GtkAnimationChoreographer.cpp +73 -0
  9. package/native/gtk/GtkAnimationChoreographer.h +49 -0
  10. package/native/gtk/GtkDropTarget.cpp +269 -0
  11. package/native/gtk/GtkDropTarget.h +40 -0
  12. package/native/gtk/GtkFocus.cpp +296 -0
  13. package/native/gtk/GtkFocus.h +113 -0
  14. package/native/gtk/GtkImageLoader.cpp +128 -0
  15. package/native/gtk/GtkImageLoader.h +87 -0
  16. package/native/gtk/GtkKeyEvents.cpp +91 -0
  17. package/native/gtk/GtkKeyEvents.h +21 -0
  18. package/native/gtk/GtkMenuBar.cpp +45 -0
  19. package/native/gtk/GtkMountingManager.cpp +1027 -0
  20. package/native/gtk/GtkMountingManager.h +146 -0
  21. package/native/gtk/GtkRunLoopObserver.cpp +77 -0
  22. package/native/gtk/GtkRunLoopObserver.h +41 -0
  23. package/native/gtk/GtkScrollView.cpp +626 -0
  24. package/native/gtk/GtkScrollView.h +209 -0
  25. package/native/gtk/GtkSkiaContext.cpp +248 -0
  26. package/native/gtk/GtkSkiaContext.h +62 -0
  27. package/native/gtk/GtkSkiaModule.cpp +80 -0
  28. package/native/gtk/GtkSkiaModule.h +51 -0
  29. package/native/gtk/GtkSkiaPeer.cpp +285 -0
  30. package/native/gtk/GtkSkiaPeer.h +63 -0
  31. package/native/gtk/GtkTextInput.cpp +428 -0
  32. package/native/gtk/GtkTextInput.h +123 -0
  33. package/native/gtk/GtkTextPeer.cpp +425 -0
  34. package/native/gtk/GtkTextPeer.h +87 -0
  35. package/native/gtk/GtkTitleBar.cpp +273 -0
  36. package/native/gtk/GtkTitleBar.h +96 -0
  37. package/native/gtk/GtkTitleBarLayout.cpp +45 -0
  38. package/native/gtk/GtkTitleBarLayout.h +36 -0
  39. package/native/gtk/GtkTouchDispatcher.cpp +671 -0
  40. package/native/gtk/GtkTouchDispatcher.h +139 -0
  41. package/native/gtk/GtkWindowControl.cpp +223 -0
  42. package/native/gtk/GtkWindowModule.cpp +194 -0
  43. package/native/gtk/GtkWindowModule.h +62 -0
  44. package/native/gtk/PangoTextLayout.cpp +295 -0
  45. package/native/gtk/PangoTextLayout.h +54 -0
  46. package/native/gtk/PangoTextLayoutManager.cpp +140 -0
  47. package/native/gtk/PlatformServicesGtk.cpp +583 -0
  48. package/native/gtk/RnView.cpp +1407 -0
  49. package/native/gtk/RnView.h +339 -0
  50. package/native/gtk/demo_layout_gtk.cpp +57 -0
  51. package/native/gtk/main_gtk.cpp +1981 -0
  52. package/native/gtk/mount_harness_gtk.cpp +143 -0
  53. package/native/tests/TestMainGtk.cpp +25 -0
  54. package/native/tests/notification_stub.cpp +103 -0
  55. package/native/tests/test_accessibility.cpp +251 -0
  56. package/native/tests/test_focus.cpp +194 -0
  57. package/native/tests/test_hittest.cpp +242 -0
  58. package/native/tests/test_image.cpp +135 -0
  59. package/native/tests/test_key_events_gtk.cpp +112 -0
  60. package/native/tests/test_mounting.cpp +415 -0
  61. package/native/tests/test_scrollview.cpp +258 -0
  62. package/native/tests/test_skia_texture.cpp +120 -0
  63. package/native/tests/test_text.cpp +147 -0
  64. package/native/tests/test_textinput.cpp +598 -0
  65. package/native/tests/test_titlebar.cpp +137 -0
  66. package/native/tests/test_titlebar_drag.cpp +138 -0
  67. package/native/tests/test_version.cpp +49 -0
  68. package/native/tests/test_view.cpp +162 -0
  69. package/native/tests/test_viewprops.cpp +254 -0
  70. package/package.json +26 -0
  71. package/react-native.config.js +21 -0
@@ -0,0 +1,91 @@
1
+ #include "GtkKeyEvents.h"
2
+
3
+ #include <glib.h>
4
+
5
+ #include <string>
6
+
7
+ namespace basalt {
8
+ namespace {
9
+
10
+ const char *specialNameFor(guint keyval) {
11
+ switch (keyval) {
12
+ case GDK_KEY_Up:
13
+ case GDK_KEY_KP_Up:
14
+ return kKeyArrowUp;
15
+ case GDK_KEY_Down:
16
+ case GDK_KEY_KP_Down:
17
+ return kKeyArrowDown;
18
+ case GDK_KEY_Left:
19
+ case GDK_KEY_KP_Left:
20
+ return kKeyArrowLeft;
21
+ case GDK_KEY_Right:
22
+ case GDK_KEY_KP_Right:
23
+ return kKeyArrowRight;
24
+ case GDK_KEY_Page_Up:
25
+ case GDK_KEY_KP_Page_Up:
26
+ return kKeyPageUp;
27
+ case GDK_KEY_Page_Down:
28
+ case GDK_KEY_KP_Page_Down:
29
+ return kKeyPageDown;
30
+ case GDK_KEY_Home:
31
+ case GDK_KEY_KP_Home:
32
+ return kKeyHome;
33
+ case GDK_KEY_End:
34
+ case GDK_KEY_KP_End:
35
+ return kKeyEnd;
36
+ case GDK_KEY_Delete:
37
+ case GDK_KEY_KP_Delete:
38
+ return kKeyDelete;
39
+ case GDK_KEY_BackSpace:
40
+ return kKeyBackspace;
41
+ case GDK_KEY_Return:
42
+ case GDK_KEY_KP_Enter:
43
+ return kKeyEnter;
44
+ case GDK_KEY_Tab:
45
+ // Shift-Tab is its own keyval here, as back-tab is its own character on
46
+ // AppKit. Reported as Tab with shift set, for the same reason: that is what a
47
+ // browser reports and what an app will have bound.
48
+ case GDK_KEY_ISO_Left_Tab:
49
+ return kKeyTab;
50
+ case GDK_KEY_Escape:
51
+ return kKeyEscape;
52
+ default:
53
+ return nullptr;
54
+ }
55
+ }
56
+
57
+ } // namespace
58
+
59
+ std::optional<KeyCombination> keyCombinationFrom(guint keyval, GdkModifierType state) {
60
+ KeyModifiers modifiers;
61
+ modifiers.alt = (state & GDK_ALT_MASK) != 0;
62
+ modifiers.ctrl = (state & GDK_CONTROL_MASK) != 0;
63
+ // Super is `meta`. W3C names the Windows and Command keys Meta, and this is the
64
+ // key in that position on a Linux keyboard -- so an app that binds metaKey gets
65
+ // the same physical key on all three desktops. GDK_META_MASK is a different
66
+ // key again on X11, historically the one next to Alt, and almost nothing has
67
+ // one; mapping it here would give an app a modifier it cannot press.
68
+ modifiers.meta = (state & GDK_SUPER_MASK) != 0;
69
+ modifiers.shift = (state & GDK_SHIFT_MASK) != 0;
70
+
71
+ if (const char *special = specialNameFor(keyval)) {
72
+ return KeyCombination{std::string(special), modifiers};
73
+ }
74
+
75
+ // A keyval already accounts for Shift -- `A` and `a` are different keyvals --
76
+ // so case follows the character here without doing anything, which is what a
77
+ // browser reports and what AppKit needs `characters` for.
78
+ const guint32 codepoint = gdk_keyval_to_unicode(keyval);
79
+ if (codepoint == 0) {
80
+ // A bare modifier, or a keyval with no character and no name of ours.
81
+ return std::nullopt;
82
+ }
83
+ char utf8[8] = {};
84
+ const gint length = g_unichar_to_utf8(static_cast<gunichar>(codepoint), utf8);
85
+ if (length <= 0) {
86
+ return std::nullopt;
87
+ }
88
+ return KeyCombination{std::string(utf8, static_cast<size_t>(length)), modifiers};
89
+ }
90
+
91
+ } // namespace basalt
@@ -0,0 +1,21 @@
1
+ // A GDK key press as a key combination, in core/KeyEvents.h's vocabulary.
2
+ //
3
+ // The GTK counterpart of appkit/AppKitKeyEvents.h, and deliberately not shared
4
+ // with it: a keyval is not an NSEvent and the two have nothing in common but the
5
+ // names they produce -- which is exactly why those names are constants in core.
6
+
7
+ #pragma once
8
+
9
+ #include "KeyEvents.h"
10
+
11
+ #include <gtk/gtk.h>
12
+
13
+ #include <optional>
14
+
15
+ namespace basalt {
16
+
17
+ // Nothing for a press with no key to speak of: a bare modifier, or a keyval that
18
+ // maps to no character and no name.
19
+ std::optional<KeyCombination> keyCombinationFrom(guint keyval, GdkModifierType state);
20
+
21
+ } // namespace basalt
@@ -0,0 +1,45 @@
1
+ // The Linux half of core/MenuModel.h: no application menu, and why.
2
+ //
3
+ // This is not unimplemented. GNOME's guidelines have said since GNOME 3 that an
4
+ // application should use a header bar with a menu button rather than a menu
5
+ // bar, GTK4 removed `GtkMenuBar` along with the rest of GtkMenu, and this
6
+ // host's window already has a header bar -- which is where a GTK app's menu
7
+ // belongs and which `<TitleBar>` already lets an app fill.
8
+ //
9
+ // Answering `applicationMenuSupported() == false` is the honest reply, and it
10
+ // is the reason that function exists: an app can ask, put its commands in its
11
+ // own header, and ship something a GNOME user recognises, rather than shipping
12
+ // a File menu nobody on Linux can see.
13
+ //
14
+ // What Linux does *not* lack is menus. `showMenu` in PlatformServicesGtk.cpp is
15
+ // a real GtkPopoverMenu, and it is what a header-bar menu button opens; the
16
+ // developer menu already uses it. What is missing is only the bar.
17
+ //
18
+ // If this ever changes, the shape to build is `GtkPopoverMenuBar` over a
19
+ // `GMenuModel`, packed above the surface root -- which is a layout change to
20
+ // the window rather than an addition to this file, because the surface would
21
+ // no longer start at the top of the content area.
22
+
23
+ #include "MenuModel.h"
24
+
25
+ #include <string>
26
+
27
+ namespace basalt {
28
+
29
+ bool applicationMenuSupported() {
30
+ return false;
31
+ }
32
+
33
+ std::string describeApplicationMenu() {
34
+ // Nothing is installed, so there is nothing to describe. The empty string is
35
+ // what a test asserting "this platform has no menu bar" reads.
36
+ return {};
37
+ }
38
+
39
+ void setApplicationMenu(const MenuModel & /*menu*/, std::function<void(int)> /*onChosen*/) {
40
+ // Deliberately nothing. An app that checked `applicationMenuSupported()`
41
+ // already knows; one that did not is no worse off than before it described a
42
+ // menu, and a warning on every render would be noise it cannot act on.
43
+ }
44
+
45
+ } // namespace basalt