Skip to content

Commit e014a1f

Browse files
author
Chris Warren-Smith
committed
SDL: updates for flatpak install
1 parent 71a56ce commit e014a1f

14 files changed

Lines changed: 74 additions & 31 deletions

File tree

CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ set(VERSION "12.29")
99
cmake_minimum_required(VERSION 3.10)
1010
project(SmallBASIC VERSION ${VERSION} LANGUAGES C CXX)
1111

12-
set(CMAKE_CXX_STANDARD 14)
12+
# clang-check ../*.cpp
13+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
14+
set(CMAKE_CXX_STANDARD 20)
1315
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1416

1517
# cmake -DWITH_DEBUG=ON
@@ -85,7 +87,7 @@ function(buildSDL)
8587
include_directories(${FONTCONFIG_INCLUDE_DIRS})
8688
add_compile_options(${FONTCONFIG_CFLAGS_OTHER})
8789
execute_process(
88-
COMMAND ${XXD_EXECUTABLE} -i images/sb-desktop-128x128.png
90+
COMMAND ${XXD_EXECUTABLE} -i ${CMAKE_SOURCE_DIR}/images/io.github.smallbasic.png
8991
OUTPUT_FILE ${CMAKE_BINARY_DIR}/src/platform/sdl/icon.h
9092
)
9193
endif()
@@ -109,8 +111,9 @@ function(buildSDL)
109111
set(IMPL_LOG_WRITE ON)
110112

111113
# Process assets
114+
message("generating main_bas.h")
112115
execute_process(
113-
COMMAND ${XXD_EXECUTABLE} -i src/platform/android/app/src/main/assets/main.bas
116+
COMMAND ${XXD_EXECUTABLE} -i ${CMAKE_SOURCE_DIR}/src/platform/android/app/src/main/assets/main.bas
114117
OUTPUT_FILE ${CMAKE_BINARY_DIR}/src/platform/sdl/main_bas.h
115118
)
116119
writeConfig()

Makefile.am

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,19 @@ appImage:
7474
# https://docs.flathub.org/docs/for-app-authors/submission
7575
#
7676

77-
flatpak-build:
78-
flatpak-builder build-dir io.github.smallbasic.json --force-clean
77+
flatpak-build-all:
78+
flatpak-builder --force-clean build-dir io.github.smallbasic.json
7979

80-
flatpak-test:
80+
flatpak-build:
81+
flatpak-builder --build-only --force-clean --disable-download --disable-updates build-dir io.github.smallbasic.json && \
8182
flatpak-builder --run build-dir io.github.smallbasic.json sbasicg
8283

8384
flatpak-install:
8485
flatpak-builder --user --install --force-clean build-dir io.github.smallbasic.json
8586

87+
flatpak-run:
88+
flatpak run io.github.smallbasic
89+
8690
EXTRA_DIST = \
8791
documentation/build_kwp.cpp \
8892
documentation/sbasic_ref.csv \

configure.ac

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ function buildSDL() {
174174

175175
PKG_CHECK_MODULES([SDL3], [sdl3])
176176

177+
AC_MSG_CHECKING([for SDL3 library linking])
178+
SDL3_LIBS=`pkg-config sdl3 --libs --static`
179+
177180
SAVED_CPPFLAGS="$CPPFLAGS"
178181
CPPFLAGS="$CPPFLAGS `pkg-config freetype2 --cflags`"
179182
AC_CHECK_HEADERS([ft2build.h], [], [AC_MSG_ERROR([libfreetype6-dev not installed: configure failed.])])
@@ -224,10 +227,6 @@ function buildSDL() {
224227

225228
(cd images && xxd -i sb-desktop-128x128.png > ../src/platform/sdl/icon.h)
226229

227-
AC_MSG_CHECKING([for SDL3 library linking])
228-
SDL3_LIBS=`pkg-config sdl3 --libs --static`
229-
AC_MSG_RESULT([$SDL3_LIBS])
230-
231230
dnl backlinking support for modules
232231
PACKAGE_LIBS="${PACKAGE_LIBS} -ldl -no-pie"
233232
PACKAGE_LIBS="${PACKAGE_LIBS} ${FONTCONFIG_LIBS}"

src/common/brun.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,9 @@ void exec_setup_predefined_variables() {
288288
}
289289
}
290290
#elif defined(_UnixOS)
291-
if (getenv("HOME")) {
291+
if (getenv("XDG_DATA_HOME")) {
292+
strlcpy(homedir, getenv("XDG_DATA_HOME"), sizeof(homedir));
293+
} else if (getenv("HOME")) {
292294
strlcpy(homedir, getenv("HOME"), sizeof(homedir));
293295
} else {
294296
strcpy(homedir, "/tmp/");

src/platform/android/app/src/main/assets/main.bas

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -413,14 +413,6 @@ sub listFiles(byref frm, path, sortDir, byref basList)
413413
return bn
414414
end
415415

416-
sub mk_label(labText, labCol, x, y)
417-
local bn = mk_bn(0, labText, labCol)
418-
bn.type = "label"
419-
bn.x = x
420-
bn.y = y
421-
frm.inputs << bn
422-
end
423-
424416
sub mk_link(value, labText, labCol, x, y)
425417
local bn = mk_bn(value, labText, labCol)
426418
bn.type = "link"
@@ -429,10 +421,24 @@ sub listFiles(byref frm, path, sortDir, byref basList)
429421
frm.inputs << bn
430422
end
431423

424+
sub mk_folder_link(path)
425+
local bn_label = mk_bn(0, "Files in ", colText2)
426+
bn_label.x = 3
427+
bn_label.y = -lineSpacing
428+
bn_label.type = "label"
429+
frm.inputs << bn_label
430+
431+
local bn = mk_bn(0, "[" + path + "]", colText)
432+
bn.type = "folder-dialog"
433+
bn.x = -1
434+
bn.y = -1
435+
frm.inputs << bn
436+
end
437+
432438
if (is_android) then
433439
mk_link(sortNameId, "[Name]", name_col, 0, -linespacing)
434440
else
435-
mk_label("Files in " + path, colText, 3, -lineSpacing)
441+
mk_folder_link(path)
436442
mk_link(backId, "[Go up]", colNav, 0, -linespacing)
437443
mk_link(sortNameId, "[Name]", name_col, -(char_w * 8), -1)
438444
endif

src/platform/android/jni/runtime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct Runtime : public System {
4747
int getUnicodeChar(int keyCode, int metaState);
4848
void redraw() { _graphics->redraw(); }
4949
void handleKeyEvent(MAEvent &event);
50+
void openFolder() override {}
5051
void pause(int timeout);
5152
MAEvent processEvents(int waitFlag) override;
5253
void processEvent(MAEvent &event);

src/platform/sdl/io.github.smallbasic.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"--socket=pulseaudio",
1616
"--device=dri",
1717
"--share=ipc",
18+
"--talk-name=org.freedesktop.portal.Desktop",
1819
"--env=SBASICPATH=/app/lib/smallbasic/plugins"
1920
],
2021
"modules": [
@@ -24,15 +25,15 @@
2425
"build-commands": [
2526
"./autogen.sh",
2627
"./configure --prefix=/app",
27-
"make -j$(nproc)",
28+
"make -s",
2829
"mkdir -p ${FLATPAK_DEST}/lib/smallbasic/plugins",
2930
"find . -name '*.so' -exec install -Dm755 {} ${FLATPAK_DEST}/lib/smallbasic/plugins/ \\;"
3031
],
3132
"sources": [
3233
{
3334
"type": "git",
3435
"url": "https://github.com/smallbasic/smallbasic.plugins.git",
35-
"commit": "master"
36+
"commit": "12_32"
3637
}
3738
]
3839
}, {

src/platform/sdl/runtime.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of SmallBASIC
22
//
3-
// Copyright(C) 2001-2019 Chris Warren-Smith.
3+
// Copyright(C) 2001-2026 Chris Warren-Smith.
44
//
55
// This program is distributed under the terms of the GPL v2.0 or later
66
// Download the GNU Public License (GPL) from www.gnu.org
@@ -28,6 +28,7 @@
2828
#include <SDL3/SDL_messagebox.h>
2929
#include <SDL3/SDL_mutex.h>
3030
#include <SDL3/SDL_thread.h>
31+
#include <SDL3/SDL_dialog.h>
3132
#include <cmath>
3233

3334
#define WAIT_INTERVAL 5
@@ -380,7 +381,7 @@ void Runtime::handleKeyEvent(MAEvent &event) const {
380381
// ignore ALT press without modifier key
381382
event.key = -1;
382383
} else if ((event.nativeKey & SDL_KMOD_CTRL) &&
383-
(event.nativeKey & SDL_KMOD_ALT)) {
384+
(event.nativeKey & SDL_KMOD_ALT)) {
384385
event.key = SB_KEY_CTRL_ALT(event.key);
385386
} else if ((event.nativeKey & SDL_KMOD_CTRL) &&
386387
(event.nativeKey & SDL_KMOD_SHIFT)) {
@@ -566,6 +567,23 @@ void Runtime::pollEvents(bool blocking) {
566567
}
567568
}
568569

570+
void openFolderCallBack(void *userdata, const char *const *filelist, int filter) {
571+
if (filelist && filelist[0]) {
572+
Runtime *runtime = (Runtime *)userdata;
573+
runtime->onFolderSelected(filelist[0]);
574+
}
575+
}
576+
577+
void Runtime::onFolderSelected(const char *folder) {
578+
chdir(folder);
579+
setRestart();
580+
}
581+
582+
void Runtime::openFolder() {
583+
// when running inside flatpak, this will grant access to selected folder
584+
SDL_ShowOpenFolderDialog(openFolderCallBack, this, _window, nullptr, false);
585+
}
586+
569587
MAEvent Runtime::processEvents(int waitFlag) {
570588
switch (waitFlag) {
571589
case 1:

src/platform/sdl/runtime.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ struct Runtime final : System {
4040
bool toggleFullscreen();
4141
void handleKeyEvent(MAEvent &event) const;
4242
bool hasEvent() const { return _eventQueue && !_eventQueue->empty(); }
43+
void onFolderSelected(const char *folder);
44+
void openFolder() override;
4345
void pause(int timeout);
4446
void pollEvents(bool blocking);
4547
MAEvent *popEvent() { return _eventQueue->pop(); }

src/ui/form.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ void FormLink::clicked(int x, int y, bool pressed) {
111111
if (!pressed && _external && form != nullptr && g_system->isRunning()) {
112112
const char *value = getValue();
113113
g_system->browseFile(value != nullptr ? value : _link.c_str());
114+
} else if (!pressed && _folder) {
115+
g_system->openFolder();
114116
} else {
115117
FormInput::clicked(x, y, pressed);
116118
}
@@ -221,7 +223,9 @@ FormInput *create_input(var_p_t v_field) {
221223
widget = new FormLabel(label, x, y, w, h);
222224
} else if (strcasecmp("link", type) == 0) {
223225
bool external = map_get_int(v_field, FORM_INPUT_IS_EXTERNAL, 0);
224-
widget = new FormLink(label, external, x, y, w, h);
226+
widget = new FormLink(label, external, false, x, y, w, h);
227+
} else if (strcasecmp("folder-dialog", type) == 0) {
228+
widget = new FormLink(label, false, true, x, y, w, h);
225229
} else if (strcasecmp("listbox", type) == 0 ||
226230
strcasecmp("list", type) == 0) {
227231
ListModel *model = new ListModel(get_selected_index(v_field), value);

0 commit comments

Comments
 (0)