cleaned up clipboard support

This commit is contained in:
Eric 2023-10-26 12:58:01 -07:00
parent f4aec571ba
commit f0ebe2bce8
No known key found for this signature in database
GPG Key ID: 89C93F0F8D6D5A98
20 changed files with 207 additions and 199 deletions

56
.efrocachemap generated
View File

@ -4056,26 +4056,26 @@
"build/assets/windows/Win32/ucrtbased.dll": "2def5335207d41b21b9823f6805997f1",
"build/assets/windows/Win32/vc_redist.x86.exe": "b08a55e2e77623fe657bea24f223a3ae",
"build/assets/windows/Win32/vcruntime140d.dll": "865b2af4d1e26a1a8073c89acb06e599",
"build/prefab/full/linux_arm64_gui/debug/ballisticakit": "b3aaa8011f040ba38b1abcff978e3c85",
"build/prefab/full/linux_arm64_gui/release/ballisticakit": "f5623a29f71cf5363ff72fe4436340b1",
"build/prefab/full/linux_arm64_server/debug/dist/ballisticakit_headless": "9f5ec716df130f92e9b055e9fca4bbc8",
"build/prefab/full/linux_arm64_server/release/dist/ballisticakit_headless": "327f6b0da02ecf72006ff88dd37b31ac",
"build/prefab/full/linux_x86_64_gui/debug/ballisticakit": "ede687d69269225dc788851fc4515ccf",
"build/prefab/full/linux_x86_64_gui/release/ballisticakit": "16029a78e585822f78fe4619beba456c",
"build/prefab/full/linux_x86_64_server/debug/dist/ballisticakit_headless": "8f091556ac938da89cab226d9bb59dec",
"build/prefab/full/linux_x86_64_server/release/dist/ballisticakit_headless": "08ea82e016ce2d7ac8d687a795e7a179",
"build/prefab/full/mac_arm64_gui/debug/ballisticakit": "91d4f5cb9b13eb6f2964187fd7ff9cc5",
"build/prefab/full/mac_arm64_gui/release/ballisticakit": "ed93c1d02f14dc147d2d84c8f919568c",
"build/prefab/full/mac_arm64_server/debug/dist/ballisticakit_headless": "5e3eb1b9195fcbf3ec477392b15bff23",
"build/prefab/full/mac_arm64_server/release/dist/ballisticakit_headless": "b6cf7d6cf47f8bbf1b3c4f28ba9c7854",
"build/prefab/full/mac_x86_64_gui/debug/ballisticakit": "f044e3d1d94751272c02f864ddafbe6b",
"build/prefab/full/mac_x86_64_gui/release/ballisticakit": "aa56b6e21eb82ca8af11a248bde876d1",
"build/prefab/full/mac_x86_64_server/debug/dist/ballisticakit_headless": "4ee8ff4b9d37bbc3d7a7db73168f8888",
"build/prefab/full/mac_x86_64_server/release/dist/ballisticakit_headless": "dc62f105598c866680a0fd150b83ea0a",
"build/prefab/full/windows_x86_gui/debug/BallisticaKit.exe": "a04e0837368e5eae80ec084a898b79d8",
"build/prefab/full/windows_x86_gui/release/BallisticaKit.exe": "cd5b75cfa4cf0bfd478092ef812006c4",
"build/prefab/full/windows_x86_server/debug/dist/BallisticaKitHeadless.exe": "4decefaeffa74fb89f39834960c8fd5f",
"build/prefab/full/windows_x86_server/release/dist/BallisticaKitHeadless.exe": "73087f5f43a6e9d4b10529824d671d6b",
"build/prefab/full/linux_arm64_gui/debug/ballisticakit": "671499f10be5561b64b7c1e8551f71bc",
"build/prefab/full/linux_arm64_gui/release/ballisticakit": "8834461aaef9d915828b460426bb16b6",
"build/prefab/full/linux_arm64_server/debug/dist/ballisticakit_headless": "9be5746f3cdb8fdbeb01c3fba0f3cd04",
"build/prefab/full/linux_arm64_server/release/dist/ballisticakit_headless": "1a4e1fb4230ffe937bc11890943bab67",
"build/prefab/full/linux_x86_64_gui/debug/ballisticakit": "809fd63da80c54076100f18c8cde6ba8",
"build/prefab/full/linux_x86_64_gui/release/ballisticakit": "bb3574370f0d601abb9443dc2285689b",
"build/prefab/full/linux_x86_64_server/debug/dist/ballisticakit_headless": "2b1d99684649040257bfe95b0c5a21d9",
"build/prefab/full/linux_x86_64_server/release/dist/ballisticakit_headless": "3a4eaac355dc1ed691aa946f9470fd80",
"build/prefab/full/mac_arm64_gui/debug/ballisticakit": "0cdebb143458f5248efb0227e875d5d4",
"build/prefab/full/mac_arm64_gui/release/ballisticakit": "a4eae535e631ac6d0aaa3fa9203656cf",
"build/prefab/full/mac_arm64_server/debug/dist/ballisticakit_headless": "d2dcb9d5f1201e98ba83b547fb7a317e",
"build/prefab/full/mac_arm64_server/release/dist/ballisticakit_headless": "6cf3c416280b71e5b16516cfb063b198",
"build/prefab/full/mac_x86_64_gui/debug/ballisticakit": "a01e3ef9ec790c0bc385995e598c18dd",
"build/prefab/full/mac_x86_64_gui/release/ballisticakit": "427e518fd557950c4f8fec0b8fca3c86",
"build/prefab/full/mac_x86_64_server/debug/dist/ballisticakit_headless": "b6a2f1c128e3b1c035eff76f38100566",
"build/prefab/full/mac_x86_64_server/release/dist/ballisticakit_headless": "deb872ab495ab8e713ba564b7bc4f169",
"build/prefab/full/windows_x86_gui/debug/BallisticaKit.exe": "c647c1e19b2c3a2bee028ef8215945d5",
"build/prefab/full/windows_x86_gui/release/BallisticaKit.exe": "ce133f1e838b8b6d3b9b4fd7c516d5d8",
"build/prefab/full/windows_x86_server/debug/dist/BallisticaKitHeadless.exe": "f41eb8f74e5cf7a36cc8bbda1eef1933",
"build/prefab/full/windows_x86_server/release/dist/BallisticaKitHeadless.exe": "00ae0c9d9351140edc42ed18b719a2bf",
"build/prefab/lib/linux_arm64_gui/debug/libballisticaplus.a": "becf7a70c7c0d7bb5bfe731dde5e0249",
"build/prefab/lib/linux_arm64_gui/release/libballisticaplus.a": "c9ef036408f0832cd068a34365485e0b",
"build/prefab/lib/linux_arm64_server/debug/libballisticaplus.a": "becf7a70c7c0d7bb5bfe731dde5e0249",
@ -4092,14 +4092,14 @@
"build/prefab/lib/mac_x86_64_gui/release/libballisticaplus.a": "2b57cf28eeadf43d09b1d780a5db1423",
"build/prefab/lib/mac_x86_64_server/debug/libballisticaplus.a": "3314d791a9ab37ea81be824460c63d14",
"build/prefab/lib/mac_x86_64_server/release/libballisticaplus.a": "2b57cf28eeadf43d09b1d780a5db1423",
"build/prefab/lib/windows/Debug_Win32/BallisticaKitGenericPlus.lib": "bd63402d48fce829f16d59c6c1f87977",
"build/prefab/lib/windows/Debug_Win32/BallisticaKitGenericPlus.pdb": "de24c4e6f661f6201b933af3343084cc",
"build/prefab/lib/windows/Debug_Win32/BallisticaKitHeadlessPlus.lib": "84904f537e435d09c06b4b6c10abea7d",
"build/prefab/lib/windows/Debug_Win32/BallisticaKitHeadlessPlus.pdb": "22a32d161e85baa6c6459412a368bf82",
"build/prefab/lib/windows/Release_Win32/BallisticaKitGenericPlus.lib": "f43972d496e1953fdc30ff094a22a0d1",
"build/prefab/lib/windows/Release_Win32/BallisticaKitGenericPlus.pdb": "c069093fb4773f3feac13236d474ecf1",
"build/prefab/lib/windows/Release_Win32/BallisticaKitHeadlessPlus.lib": "4d745c03bbeab02c5f69bed1ae376933",
"build/prefab/lib/windows/Release_Win32/BallisticaKitHeadlessPlus.pdb": "c1e1321bb0d5bb74211377e0f5cae45c",
"build/prefab/lib/windows/Debug_Win32/BallisticaKitGenericPlus.lib": "eda80e0bcb2332fb400e4487aa821fda",
"build/prefab/lib/windows/Debug_Win32/BallisticaKitGenericPlus.pdb": "ae70908e8821b275a7c62541288761c3",
"build/prefab/lib/windows/Debug_Win32/BallisticaKitHeadlessPlus.lib": "4dcc80f1087a342df7f0e13225c6a0d8",
"build/prefab/lib/windows/Debug_Win32/BallisticaKitHeadlessPlus.pdb": "e83c284f0ee5c9bf9e02bdd5e83de604",
"build/prefab/lib/windows/Release_Win32/BallisticaKitGenericPlus.lib": "92bbe105f7bbff92ebe621710bb13629",
"build/prefab/lib/windows/Release_Win32/BallisticaKitGenericPlus.pdb": "f3c9b10ab0dbc35214b20c3323255ea1",
"build/prefab/lib/windows/Release_Win32/BallisticaKitHeadlessPlus.lib": "df9efe46d688a585157edfe5d3b9e912",
"build/prefab/lib/windows/Release_Win32/BallisticaKitHeadlessPlus.pdb": "3c76a27db96c7c277682430ec980d9ce",
"src/assets/ba_data/python/babase/_mgen/__init__.py": "f885fed7f2ed98ff2ba271f9dbe3391c",
"src/assets/ba_data/python/babase/_mgen/enums.py": "28323912b56ec07701eda3d41a6a4101",
"src/ballistica/base/mgen/pyembed/binding_base.inc": "6df0f34207346d89a72924249ddd4706",

View File

@ -1,4 +1,4 @@
### 1.7.28 (build 21512, api 8, 2023-10-26)
### 1.7.28 (build 21516, api 8, 2023-10-26)
- Massively cleaned up code related to rendering and window systems (OpenGL,
SDL, etc). This code had been growing into a nasty tangle for 15 years

View File

@ -52,7 +52,7 @@ if TYPE_CHECKING:
# Build number and version of the ballistica binary we expect to be
# using.
TARGET_BALLISTICA_BUILD = 21512
TARGET_BALLISTICA_BUILD = 21516
TARGET_BALLISTICA_VERSION = '1.7.28'

View File

@ -458,9 +458,9 @@ class PrivateGatherTab(GatherTab):
scale=1.5,
size=(300, 50),
editable=True,
max_chars=20,
description=bui.Lstr(resource='gatherWindow.partyCodeText'),
autoselect=True,
maxwidth=250,
h_align='left',
v_align='center',
text='',
@ -962,7 +962,7 @@ class PrivateGatherTab(GatherTab):
code = cast(str, bui.textwidget(query=self._join_party_code_text))
if not code:
bui.screenmessage(
bui.Lstr(resource='internal.invalidAddressErrorText'),
bui.Lstr(translate=('serverResponses', 'Invalid code.')),
color=(1, 0, 0),
)
bui.getsound('error').play()

View File

@ -1318,7 +1318,7 @@ class MainMenuWindow(bui.Window):
bui.app.classic.resume()
if self._root_widget:
bui.containerwidget(edit=self._root_widget, transition='out_right')
bui.app.ui_v1.clear_main_menu_window()
bui.app.ui_v1.clear_main_menu_window(transition='out_right')
# If there's callbacks waiting for this window to go away, call them.
for call in bui.app.ui_v1.main_menu_resume_callbacks:

View File

@ -318,4 +318,58 @@ auto AppAdapter::GetGraphicsClientContext() -> GraphicsClientContext* {
auto AppAdapter::GetKeyRepeatDelay() -> float { return 0.3f; }
auto AppAdapter::GetKeyRepeatInterval() -> float { return 0.08f; }
auto AppAdapter::ClipboardIsSupported() -> bool {
// We only call our actual virtual function once.
if (!have_clipboard_is_supported_) {
clipboard_is_supported_ = DoClipboardIsSupported();
have_clipboard_is_supported_ = true;
}
return clipboard_is_supported_;
}
auto AppAdapter::ClipboardHasText() -> bool {
// If subplatform says they don't support clipboards, don't even ask.
if (!ClipboardIsSupported()) {
return false;
}
return DoClipboardHasText();
}
void AppAdapter::ClipboardSetText(const std::string& text) {
// If subplatform says they don't support clipboards, this is an error.
if (!ClipboardIsSupported()) {
throw Exception("ClipboardSetText called with no clipboard support.",
PyExcType::kRuntime);
}
DoClipboardSetText(text);
}
auto AppAdapter::ClipboardGetText() -> std::string {
// If subplatform says they don't support clipboards, this is an error.
if (!ClipboardIsSupported()) {
throw Exception("ClipboardGetText called with no clipboard support.",
PyExcType::kRuntime);
}
return DoClipboardGetText();
}
auto AppAdapter::DoClipboardIsSupported() -> bool { return false; }
auto AppAdapter::DoClipboardHasText() -> bool {
// Shouldn't get here since we default to no clipboard support.
FatalError("Shouldn't get here.");
return false;
}
void AppAdapter::DoClipboardSetText(const std::string& text) {
// Shouldn't get here since we default to no clipboard support.
FatalError("Shouldn't get here.");
}
auto AppAdapter::DoClipboardGetText() -> std::string {
// Shouldn't get here since we default to no clipboard support.
FatalError("Shouldn't get here.");
return "";
}
} // namespace ballistica::base

View File

@ -207,6 +207,22 @@ class AppAdapter {
virtual auto GetKeyRepeatDelay() -> float;
virtual auto GetKeyRepeatInterval() -> float;
/// Return whether clipboard operations are supported at all. This gets
/// called when determining whether to display clipboard related UI
/// elements/etc.
auto ClipboardIsSupported() -> bool;
/// Return whether there is currently text on the clipboard.
auto ClipboardHasText() -> bool;
/// Set current clipboard text. Raises an Exception if clipboard is
/// unsupported.
void ClipboardSetText(const std::string& text);
/// Return current text from the clipboard. Raises an Exception if
/// clipboard is unsupported or if there's no text on the clipboard.
auto ClipboardGetText() -> std::string;
protected:
AppAdapter();
virtual ~AppAdapter();
@ -219,10 +235,18 @@ class AppAdapter {
/// context. By default this is simply the main thread.
virtual void DoPushGraphicsContextRunnable(Runnable* runnable);
virtual auto DoClipboardIsSupported() -> bool;
virtual auto DoClipboardHasText() -> bool;
virtual void DoClipboardSetText(const std::string& text);
virtual auto DoClipboardGetText() -> std::string;
private:
void OnAppSuspend_();
void OnAppUnsuspend_();
bool app_suspended_{};
bool app_suspended_ : 1 {};
bool have_clipboard_is_supported_ : 1 {};
bool clipboard_is_supported_ : 1 {};
};
} // namespace ballistica::base

View File

@ -7,6 +7,7 @@
#include "ballistica/base/graphics/graphics.h"
#include "ballistica/base/graphics/graphics_server.h"
#include "ballistica/base/logic/logic.h"
#include "ballistica/base/platform/apple/apple_utils.h"
#include "ballistica/base/platform/apple/from_swift.h"
#include "ballistica/base/support/app_config.h"
#include "ballistica/shared/ballistica.h"
@ -245,6 +246,42 @@ auto AppAdapterApple::GetKeyRepeatInterval() -> float {
#endif
}
auto AppAdapterApple::DoClipboardIsSupported() -> bool {
#if BA_XCODE_BUILD
return BallisticaKit::CocoaFromCpp::ClipboardIsSupported();
#else
return CorePlatform::DoClipboardIsSupported();
#endif
}
auto AppAdapterApple::DoClipboardHasText() -> bool {
#if BA_XCODE_BUILD
return BallisticaKit::CocoaFromCpp::ClipboardHasText();
#else
return CorePlatform::DoClipboardHasText();
#endif
}
void AppAdapterApple::DoClipboardSetText(const std::string& text) {
#if BA_XCODE_BUILD
BallisticaKit::CocoaFromCpp::ClipboardSetText(text);
#else
CorePlatform::DoClipboardSetText(text);
#endif
}
auto AppAdapterApple::DoClipboardGetText() -> std::string {
#if BA_XCODE_BUILD
auto contents = BallisticaKit::CocoaFromCpp::ClipboardGetText();
if (contents) {
return std::string(contents.get());
}
throw Exception("No text on clipboard.");
#else
return CorePlatform::DoClipboardGetText();
#endif
}
} // namespace ballistica::base
#endif // BA_XCODE_BUILD

View File

@ -53,6 +53,10 @@ class AppAdapterApple : public AppAdapter {
void SetHardwareCursorVisible(bool visible) override;
void TerminateApp() override;
void ApplyGraphicsSettings(const GraphicsSettings* settings) override;
auto DoClipboardIsSupported() -> bool override;
auto DoClipboardHasText() -> bool override;
void DoClipboardSetText(const std::string& text) override;
auto DoClipboardGetText() -> std::string override;
private:
class ScopedAllowGraphics_;

View File

@ -834,6 +834,28 @@ auto AppAdapterSDL::HasDirectKeyboardInput() -> bool {
return true;
}
auto AppAdapterSDL::DoClipboardIsSupported() -> bool { return true; }
auto AppAdapterSDL::DoClipboardHasText() -> bool {
return SDL_HasClipboardText();
}
void AppAdapterSDL::DoClipboardSetText(const std::string& text) {
SDL_SetClipboardText(text.c_str());
}
auto AppAdapterSDL::DoClipboardGetText() -> std::string {
// Go through SDL functionality on SDL based platforms;
// otherwise default to no clipboard.
char* out = SDL_GetClipboardText();
if (out == nullptr) {
throw Exception("Error fetching clipboard contents.", PyExcType::kRuntime);
}
std::string out_s{out};
SDL_free(out);
return out_s;
}
} // namespace ballistica::base
#endif // BA_SDL_BUILD

View File

@ -52,6 +52,10 @@ class AppAdapterSDL : public AppAdapter {
auto InGraphicsContext() -> bool override;
void DoPushGraphicsContextRunnable(Runnable* runnable) override;
void CursorPositionForDraw(float* x, float* y) override;
auto DoClipboardIsSupported() -> bool override;
auto DoClipboardHasText() -> bool override;
void DoClipboardSetText(const std::string& text) override;
auto DoClipboardGetText() -> std::string override;
private:
class ScopedAllowGraphics_;

View File

@ -829,6 +829,15 @@ void Input::PushTextInputEvent(const std::string& text) {
return;
}
// Also ignore if there are any mod keys being held.
// We process some of our own keyboard shortcuts and don't
// want text input to come through at the same time.
if (keys_held_.contains(SDLK_LCTRL) || keys_held_.contains(SDLK_RCTRL)
|| keys_held_.contains(SDLK_LALT) || keys_held_.contains(SDLK_RALT)
|| keys_held_.contains(SDLK_LGUI) || keys_held_.contains(SDLK_RGUI)) {
return;
}
// We try to handle char filtering here (to keep it consistent across
// platforms) but make a stink if they sent us something that we can't
// at least translate to unicode.

View File

@ -71,6 +71,7 @@ class BasePlatform {
/// active/inactive.
virtual void LoginAdapterBackEndActiveChange(const std::string& login_type,
bool active);
#pragma mark MISC --------------------------------------------------------------
/// Do we define a platform-specific string editor? This is something like
@ -115,8 +116,8 @@ class BasePlatform {
/// class versions can go here.
virtual void PostInit();
bool ran_base_post_init_ : 1 {};
PythonRef string_edit_adapter_{};
bool ran_base_post_init_{};
std::string public_device_uuid_;
};

View File

@ -5,6 +5,7 @@
#include <list>
#include <unordered_map>
#include "ballistica/base/app_adapter/app_adapter.h"
#include "ballistica/base/assets/sound_asset.h"
#include "ballistica/base/input/input.h"
#include "ballistica/base/platform/base_platform.h"
@ -128,7 +129,7 @@ static PyMethodDef PyHasTouchScreenDef = {
static auto PyClipboardIsSupported(PyObject* self) -> PyObject* {
BA_PYTHON_TRY;
if (g_core->platform->ClipboardIsSupported()) {
if (g_base->app_adapter->ClipboardIsSupported()) {
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
@ -154,7 +155,7 @@ static PyMethodDef PyClipboardIsSupportedDef = {
static auto PyClipboardHasText(PyObject* self) -> PyObject* {
BA_PYTHON_TRY;
if (g_core->platform->ClipboardHasText()) {
if (g_base->app_adapter->ClipboardHasText()) {
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
@ -187,7 +188,7 @@ static auto PyClipboardSetText(PyObject* self, PyObject* args, PyObject* keywds)
const_cast<char**>(kwlist), &value)) {
return nullptr;
}
g_core->platform->ClipboardSetText(value);
g_base->app_adapter->ClipboardSetText(value);
Py_RETURN_NONE;
BA_PYTHON_CATCH;
}
@ -211,7 +212,7 @@ static PyMethodDef PyClipboardSetTextDef = {
static auto PyClipboardGetText(PyObject* self) -> PyObject* {
BA_PYTHON_TRY;
return PyUnicode_FromString(g_core->platform->ClipboardGetText().c_str());
return PyUnicode_FromString(g_base->app_adapter->ClipboardGetText().c_str());
Py_RETURN_FALSE;
BA_PYTHON_CATCH;
}

View File

@ -400,38 +400,6 @@ auto CorePlatformApple::GetSubplatformName() -> std::string {
#endif
}
auto CorePlatformApple::DoClipboardIsSupported() -> bool {
#if BA_XCODE_BUILD
return base::AppleUtils::ClipboardIsSupported();
#else
return CorePlatform::DoClipboardIsSupported();
#endif
}
auto CorePlatformApple::DoClipboardHasText() -> bool {
#if BA_XCODE_BUILD
return base::AppleUtils::ClipboardHasText();
#else
return CorePlatform::DoClipboardHasText();
#endif
}
void CorePlatformApple::DoClipboardSetText(const std::string& text) {
#if BA_XCODE_BUILD
base::AppleUtils::ClipboardSetText(text);
#else
CorePlatform::DoClipboardSetText(text);
#endif
}
auto CorePlatformApple::DoClipboardGetText() -> std::string {
#if BA_XCODE_BUILD
return base::AppleUtils::ClipboardGetText();
#else
return CorePlatform::DoClipboardGetText();
#endif
}
} // namespace ballistica::core
#endif // BA_OSTYPE_MACOS || BA_OSTYPE_IOS_TVOS

View File

@ -21,8 +21,6 @@ class CorePlatformApple : public CorePlatform {
auto GenerateUUID() -> std::string override;
auto DoGetConfigDirectoryMonolithicDefault()
-> std::optional<std::string> override;
// auto GetLocale() -> std::string override;
// auto DoGetDeviceName() -> std::string override;
auto DoHasTouchScreen() -> bool override;
auto GetDefaultUIScale() -> UIScale override;
auto IsRunningOnDesktop() -> bool override;
@ -61,10 +59,6 @@ class CorePlatformApple : public CorePlatform {
auto GetPlatformName() -> std::string override;
auto GetSubplatformName() -> std::string override;
auto DoClipboardIsSupported() -> bool override;
auto DoClipboardHasText() -> bool override;
void DoClipboardSetText(const std::string& text) override;
auto DoClipboardGetText() -> std::string override;
auto GetDeviceUUIDInputs() -> std::list<std::string> override;
protected:

View File

@ -1053,92 +1053,6 @@ auto CorePlatform::GetCurrentWholeSeconds() -> int64_t {
.count();
}
auto CorePlatform::ClipboardIsSupported() -> bool {
// We only call our actual virtual function once.
if (!have_clipboard_is_supported_) {
clipboard_is_supported_ = DoClipboardIsSupported();
have_clipboard_is_supported_ = true;
}
return clipboard_is_supported_;
}
auto CorePlatform::ClipboardHasText() -> bool {
// If subplatform says they don't support clipboards, don't even ask.
if (!ClipboardIsSupported()) {
return false;
}
return DoClipboardHasText();
}
void CorePlatform::ClipboardSetText(const std::string& text) {
// If subplatform says they don't support clipboards, this is an error.
if (!ClipboardIsSupported()) {
throw Exception("ClipboardSetText called with no clipboard support.",
PyExcType::kRuntime);
}
DoClipboardSetText(text);
}
auto CorePlatform::ClipboardGetText() -> std::string {
// If subplatform says they don't support clipboards, this is an error.
if (!ClipboardIsSupported()) {
throw Exception("ClipboardGetText called with no clipboard support.",
PyExcType::kRuntime);
}
return DoClipboardGetText();
}
auto CorePlatform::DoClipboardIsSupported() -> bool {
// Go through SDL functionality on SDL based platforms;
// otherwise default to no clipboard.
#if BA_SDL_BUILD
return true;
#else
return false;
#endif
}
auto CorePlatform::DoClipboardHasText() -> bool {
// Go through SDL functionality on SDL based platforms;
// otherwise default to no clipboard.
#if BA_SDL_BUILD
return SDL_HasClipboardText();
#else
// Shouldn't get here since we default to no clipboard support.
FatalError("Shouldn't get here.");
return false;
#endif
}
void CorePlatform::DoClipboardSetText(const std::string& text) {
// Go through SDL functionality on SDL based platforms;
// otherwise default to no clipboard.
#if BA_SDL_BUILD
SDL_SetClipboardText(text.c_str());
#else
// Shouldn't get here since we default to no clipboard support.
FatalError("Shouldn't get here.");
#endif
}
auto CorePlatform::DoClipboardGetText() -> std::string {
// Go through SDL functionality on SDL based platforms;
// otherwise default to no clipboard.
#if BA_SDL_BUILD
char* out = SDL_GetClipboardText();
if (out == nullptr) {
throw Exception("Error fetching clipboard contents.", PyExcType::kRuntime);
}
std::string out_s{out};
SDL_free(out);
return out_s;
#else
// Shouldn't get here since we default to no clipboard support.
FatalError("Shouldn't get here.");
return "";
#endif
}
auto CorePlatform::System(const char* cmd) -> int {
// By default can support this everywhere outside of Apple's more
// sandboxed platforms (iOS and equivalent). Actually should check

View File

@ -76,24 +76,6 @@ class CorePlatform {
/// requires the path to already exist.
auto AbsPath(const std::string& path, std::string* outpath) -> bool;
#pragma mark CLIPBOARD ---------------------------------------------------------
/// Return whether clipboard operations are supported at all. This gets
/// called when determining whether to display clipboard related UI
/// elements/etc.
auto ClipboardIsSupported() -> bool;
/// Return whether there is currently text on the clipboard.
auto ClipboardHasText() -> bool;
/// Set current clipboard text. Raises an Exception if clipboard is
/// unsupported.
void ClipboardSetText(const std::string& text);
/// Return current text from the clipboard. Raises an Exception if
/// clipboard is unsupported or if there's no text on the clipboard.
auto ClipboardGetText() -> std::string;
#pragma mark PRINTING/LOGGING --------------------------------------------------
/// Display a message to any default log for the platform (android log,
@ -456,11 +438,6 @@ class CorePlatform {
/// Generate a random UUID string.
virtual auto GenerateUUID() -> std::string;
virtual auto DoClipboardIsSupported() -> bool;
virtual auto DoClipboardHasText() -> bool;
virtual void DoClipboardSetText(const std::string& text);
virtual auto DoClipboardGetText() -> std::string;
/// Print a log message to be included in crash logs or other debug
/// mechanisms (example: Crashlytics). V1-cloud-log messages get forwarded
/// to here as well. It can be useful to call this directly to report extra
@ -473,15 +450,13 @@ class CorePlatform {
virtual ~CorePlatform();
private:
bool is_stdin_a_terminal_{};
bool have_has_touchscreen_value_{};
bool have_touchscreen_{};
bool is_tegra_k1_{};
bool have_clipboard_is_supported_{};
bool clipboard_is_supported_{};
bool made_volatile_data_dir_{};
bool have_device_uuid_{};
bool ran_base_post_init_{};
bool is_stdin_a_terminal_ : 1 {};
bool have_has_touchscreen_value_ : 1 {};
bool have_touchscreen_ : 1 {};
bool is_tegra_k1_ : 1 {};
bool made_volatile_data_dir_ : 1 {};
bool have_device_uuid_ : 1 {};
bool ran_base_post_init_ : 1 {};
millisecs_t start_time_millisecs_{};
std::string device_name_;
std::string legacy_device_uuid_;

View File

@ -39,7 +39,7 @@ auto main(int argc, char** argv) -> int {
namespace ballistica {
// These are set automatically via script; don't modify them here.
const int kEngineBuildNumber = 21512;
const int kEngineBuildNumber = 21516;
const char* kEngineVersion = "1.7.28";
const int kEngineApiVersion = 8;

View File

@ -2,6 +2,7 @@
#include "ballistica/ui_v1/widget/text_widget.h"
#include "ballistica/base/app_adapter/app_adapter.h"
#include "ballistica/base/audio/audio.h"
#include "ballistica/base/graphics/component/empty_component.h"
#include "ballistica/base/graphics/component/simple_component.h"
@ -648,10 +649,10 @@ auto TextWidget::HandleMessage(const base::WidgetMessage& m) -> bool {
// If we're doing inline editing, handle clipboard paste.
if (editable() && !ShouldUseStringEditor_()
&& m.type == base::WidgetMessage::Type::kPaste) {
if (g_core->platform->ClipboardIsSupported()) {
if (g_core->platform->ClipboardHasText()) {
if (g_base->app_adapter->ClipboardIsSupported()) {
if (g_base->app_adapter->ClipboardHasText()) {
// Just enter it char by char as if we had typed it...
AddCharsToText_(g_core->platform->ClipboardGetText());
AddCharsToText_(g_base->app_adapter->ClipboardGetText());
}
}
}