Skip to content

Commit

Permalink
Fix flatpak build
Browse files Browse the repository at this point in the history
* Patch wxWidgets to automatically select dark theme variant (taken from
  Bambu slicer flatpak manifest)
* Drop python script that selected dark theme
* Add a patch to fix libslic3r build
  • Loading branch information
anarsoul committed Nov 7, 2024
1 parent 1088d0a commit 731a93e
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 163 deletions.
36 changes: 18 additions & 18 deletions .github/workflows/build_all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,21 @@ jobs:
arch: ${{ matrix.arch }}
build-deps-only: ${{ inputs.build-deps-only || false }}
secrets: inherit
# flatpak:
# name: "Flatpak"
# runs-on: ubuntu-latest
# container:
# image: bilelmoussaoui/flatpak-github-actions:gnome-45
# options: --privileged
# steps:
# # maybe i'm too dumb and fucked up to do CI. OH WELL :D -ppd
# - name: "Remove unneeded stuff to free disk space"
# run:
# sudo rm -rf /usr/share/dotnet /opt/ghc "/usr/local/share/boost" "$AGENT_TOOLSDIRECTORY"
# - uses: actions/checkout@v4
# - uses: flatpak/flatpak-github-actions/flatpak-builder@v6
# with:
# bundle: orcaslicer.flatpak
# manifest-path: flatpak/io.github.softfever.OrcaSlicer.yml
# cache-key: flatpak-builder-${{ github.sha }}
# cache: false
flatpak:
name: "Flatpak"
runs-on: ubuntu-latest
container:
image: bilelmoussaoui/flatpak-github-actions:gnome-46
options: --privileged
steps:
# maybe i'm too dumb and fucked up to do CI. OH WELL :D -ppd
- name: "Remove unneeded stuff to free disk space"
run:
sudo rm -rf /usr/share/dotnet /opt/ghc "/usr/local/share/boost" "$AGENT_TOOLSDIRECTORY"
- uses: actions/checkout@v4
- uses: flatpak/flatpak-github-actions/flatpak-builder@v6
with:
bundle: orcaslicer.flatpak
manifest-path: flatpak/io.github.softfever.OrcaSlicer.yml
cache-key: flatpak-builder-${{ github.sha }}
cache: false
8 changes: 1 addition & 7 deletions flatpak/entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,4 @@ grep -q org.freedesktop.Platform.GL.nvidia /.flatpak-info && export WEBKIT_DISAB
# Work-around https://github.com/bambulab/BambuStudio/issues/3440
export LC_ALL=C.UTF-8

if [ $BAMBU_STUDIO_DARK_THEME == true ]; then
export GTK_THEME='Adwaita:dark'
# echo "Message: $(date +%T): INFO: using dark theme variant"
fi

exec /app/bin/orca-slicer "$@" &
$(/app/bin/set-dark-theme-variant.py) &
exec /app/bin/orca-slicer "$@"
58 changes: 5 additions & 53 deletions flatpak/io.github.softfever.OrcaSlicer.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
app-id: io.github.softfever.OrcaSlicer
runtime: org.gnome.Platform
runtime-version: "45"
runtime-version: "46"
sdk: org.gnome.Sdk
command: entrypoint
separate-locales: true
Expand All @@ -17,8 +17,6 @@ finish-args:
# Allow OrcaSlicer to talk to other instances
- --talk-name=io.github.softfever.OrcaSlicer.InstanceCheck.*
- --system-talk-name=org.freedesktop.UDisks2
# set dark theme
- --env=BAMBU_STUDIO_DARK_THEME=false

modules:

Expand All @@ -36,47 +34,6 @@ modules:
url: https://gstreamer.freedesktop.org/src/gst-plugins-good/gst-plugins-good-1.22.8.tar.xz
sha256: e305b9f07f52743ca481da0a4e0c76c35efd60adaf1b0694eb3bb021e2137e39

# xprop, xlib is needed to manipulate the X11 window and set _GTK_THEME_VARIANT dark on X11
# and paint the window dark when PRUSA_SLICER_DARK_THEME is true
# see: entrypoint & set-dark-theme-variant.py (originated from spotify client flatpak)
- name: xprop
sources:
- type: archive
url: http://mirrors.ircam.fr/pub/x.org/individual/app/xprop-1.2.5.tar.gz
sha256: b7bf6b6be6cf23e7966a153fc84d5901c14f01ee952fbd9d930aa48e2385d670
- name: python-flit_core
buildsystem: simple
build-commands:
- pip3 install --no-deps --no-build-isolation --verbose --prefix=${FLATPAK_DEST} .
sources:
- type: archive
url: https://files.pythonhosted.org/packages/c4/e6/c1ac50fe3eebb38a155155711e6e864e254ce4b6e17fe2429b4c4d5b9e80/flit_core-3.9.0.tar.gz
sha256: 72ad266176c4a3fcfab5f2930d76896059851240570ce9a98733b658cb786eba
- name: python-packaging
buildsystem: simple
build-commands:
- pip3 install --no-deps --no-build-isolation --verbose --prefix=${FLATPAK_DEST} .
sources:
- type: archive
url: https://files.pythonhosted.org/packages/51/65/50db4dda066951078f0a96cf12f4b9ada6e4b811516bf0262c0f4f7064d4/packaging-24.1.tar.gz
sha256: 026ed72c8ed3fcce5bf8950572258698927fd1dbda10a5e981cdf0ac37f4f002
- name: python-setuptools_scm
buildsystem: simple
build-commands:
- pip3 install --no-deps --no-build-isolation --verbose --prefix=${FLATPAK_DEST} .
sources:
- type: archive
url: https://files.pythonhosted.org/packages/57/38/930b1241372a9f266a7df2b184fb9d4f497c2cef2e016b014f82f541fe7c/setuptools_scm-6.0.1.tar.gz
sha256: d1925a69cb07e9b29416a275b9fadb009a23c148ace905b2fb220649a6c18e92
- name: python-xlib
buildsystem: simple
build-commands:
- pip3 install --no-deps --no-build-isolation --verbose --prefix=${FLATPAK_DEST} .
sources:
- type: archive
url: https://files.pythonhosted.org/packages/86/f5/8c0653e5bb54e0cbdfe27bf32d41f27bc4e12faa8742778c17f2a71be2c0/python-xlib-0.33.tar.gz
sha256: 55af7906a2c75ce6cb280a584776080602444f75815a7aff4d287bb2d7018b32

# For libOSMesa
- name: mesa
buildsystem: meson
Expand Down Expand Up @@ -162,6 +119,8 @@ modules:
url: https://github.com/SoftFever/Orca-deps-wxWidgets
branch: master
path: ../
- type: patch
path: patches/0001-Enable-using-a-dark-theme-when-Gnome-dark-style-is-s.patch
cleanup:
- "*.la"
- "*.a"
Expand Down Expand Up @@ -323,7 +282,6 @@ modules:
install -Dm644 ${FLATPAK_ID}.metainfo.xml /app/share/metainfo/${FLATPAK_ID}.metainfo.xml
mv /app/share/applications/OrcaSlicer.desktop /app/share/applications/${FLATPAK_ID}.desktop
desktop-file-edit --set-key=Exec --set-value="entrypoint %U" /app/share/applications/${FLATPAK_ID}.desktop
install -Dm755 set-dark-theme-variant.py /app/bin
install -Dm755 entrypoint /app/bin
install -Dm755 umount /app/bin
Expand All @@ -338,20 +296,14 @@ modules:
# OrcaSlicer Source Archive
- type: dir
path: ../
- type: patch
path: patches/libslic3r_missing_include.patch

# AppData metainfo for Gnome Software & Co.
- type: file
path: io.github.softfever.OrcaSlicer.metainfo.xml

# script to set dark theme variant
- type: file
path: set-dark-theme-variant.py

# start-up script
# README: workaround for the following issues, also enables dark theme variant:
# SEE: https://github.com/flathub/com.bambulab.BambuStudio/issues/27
# SEE: https://github.com/flathub/com.bambulab.BambuStudio/issues/3
# SEE: https://github.com/prusa3d/PrusaSlicer/issues/2365
- type: file
path: entrypoint

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
From 221be0af1a0b5bcf05c59b3403f969643b42dbaf Mon Sep 17 00:00:00 2001
From: Paul Cornett <[email protected]>
Date: Sat, 30 Sep 2023 16:42:58 -0700
Subject: [PATCH] Enable using a dark theme when Gnome "dark style" is set

The dark style setting does not cause a dark theme to be used
automatically, so request it explicitly.

Co-authored-by: Colin Kinloch
---
src/gtk/settings.cpp | 112 ++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 111 insertions(+), 1 deletion(-)

diff --git a/src/gtk/settings.cpp b/src/gtk/settings.cpp
index 304724773711..74898d9bb953 100644
--- a/src/gtk/settings.cpp
+++ b/src/gtk/settings.cpp
@@ -183,6 +183,64 @@ static void notify_gtk_font_name(GObject*, GParamSpec*, void*)
}
}

+static bool UpdatePreferDark(GVariant* value)
+{
+ // 0: No preference, 1: Prefer dark appearance, 2: Prefer light appearance
+ gboolean preferDark = g_variant_get_uint32(value) == 1;
+
+ GtkSettings* settings = gtk_settings_get_default();
+ char* themeName;
+ gboolean preferDarkPrev;
+ g_object_get(settings,
+ "gtk-theme-name", &themeName,
+ "gtk-application-prefer-dark-theme", &preferDarkPrev, nullptr);
+
+ // We don't need to enable prefer-dark if the theme is already dark
+ if (strstr(themeName, "-dark") || strstr(themeName, "-Dark"))
+ preferDark = false;
+ g_free(themeName);
+
+ const bool changed = preferDark != preferDarkPrev;
+ if (changed)
+ {
+ g_object_set(settings,
+ "gtk-application-prefer-dark-theme", preferDark, nullptr);
+ }
+ return changed;
+}
+
+// "g-signal" from GDBusProxy
+extern "C" {
+static void
+proxy_g_signal(GDBusProxy*, const char*, const char* signal_name, GVariant* parameters, void*)
+{
+ if (strcmp(signal_name, "SettingChanged") != 0)
+ return;
+
+ const char* nameSpace;
+ const char* key;
+ GVariant* value;
+ g_variant_get(parameters, "(&s&sv)", &nameSpace, &key, &value);
+ if (strcmp(nameSpace, "org.freedesktop.appearance") == 0 &&
+ strcmp(key, "color-scheme") == 0)
+ {
+ if (UpdatePreferDark(value))
+ {
+ for (int i = wxSYS_COLOUR_MAX; i--;)
+ gs_systemColorCache[i].UnRef();
+
+ for (auto* win: wxTopLevelWindows)
+ {
+ wxSysColourChangedEvent event;
+ event.SetEventObject(win);
+ win->HandleWindowEvent(event);
+ }
+ }
+ }
+ g_variant_unref(value);
+}
+}
+
// Some notes on using GtkStyleContext. Style information from a context
// attached to a non-visible GtkWidget is not accurate. The context has an
// internal visibility state, controlled by the widget, which it presumably
@@ -1124,12 +1182,62 @@ bool wxSystemSettingsNative::HasFeature(wxSystemFeature index)
class wxSystemSettingsModule: public wxModule
{
public:
- virtual bool OnInit() wxOVERRIDE { return true; }
+ virtual bool OnInit() wxOVERRIDE;
virtual void OnExit() wxOVERRIDE;
+
+#ifdef __WXGTK3__
+ GDBusProxy* m_proxy;
+#endif
wxDECLARE_DYNAMIC_CLASS(wxSystemSettingsModule);
};
wxIMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule, wxModule);

+bool wxSystemSettingsModule::OnInit()
+{
+#ifdef __WXGTK3__
+ // Gnome has gone to a dark style setting rather than a selectable dark
+ // theme, available via GSettings as the 'color-scheme' key under the
+ // 'org.gnome.desktop.interface' schema. It's also available via a "portal"
+ // (https://docs.flatpak.org/en/latest/portal-api-reference.html), which
+ // has the advantage of allowing the setting to be accessed from within a
+ // virtualized environment such as Flatpak. Since the setting does not
+ // change the theme, we propagate it to the GtkSettings
+ // 'gtk-application-prefer-dark-theme' property to get a dark theme.
+
+ m_proxy = nullptr;
+
+ // GTK_THEME environment variable overrides other settings
+ if (getenv("GTK_THEME") == nullptr)
+ {
+ m_proxy = g_dbus_proxy_new_for_bus_sync(
+ G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, nullptr,
+ "org.freedesktop.portal.Desktop",
+ "/org/freedesktop/portal/desktop",
+ "org.freedesktop.portal.Settings",
+ nullptr, nullptr);
+ }
+ if (m_proxy)
+ {
+ g_signal_connect(m_proxy, "g-signal", G_CALLBACK(proxy_g_signal), nullptr);
+
+ GVariant* ret = g_dbus_proxy_call_sync(m_proxy, "Read",
+ g_variant_new("(ss)", "org.freedesktop.appearance", "color-scheme"),
+ G_DBUS_CALL_FLAGS_NONE, -1, nullptr, nullptr);
+ if (ret)
+ {
+ GVariant* child;
+ g_variant_get(ret, "(v)", &child);
+ GVariant* value = g_variant_get_variant(child);
+ UpdatePreferDark(value);
+ g_variant_unref(value);
+ g_variant_unref(child);
+ g_variant_unref(ret);
+ }
+ }
+#endif // __WXGTK3__
+ return true;
+}
+
void wxSystemSettingsModule::OnExit()
{
#ifdef __WXGTK3__
@@ -1141,6 +1249,8 @@ void wxSystemSettingsModule::OnExit()
g_signal_handlers_disconnect_by_func(settings,
(void*)notify_gtk_font_name, NULL);
}
+ if (m_proxy)
+ g_object_unref(m_proxy);
#endif
if (gs_tlw_parent)
{
--
2.46.2

12 changes: 12 additions & 0 deletions flatpak/patches/libslic3r_missing_include.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp
index 528a72e70..1530fe655 100644
--- a/src/libslic3r/PrintObject.cpp
+++ b/src/libslic3r/PrintObject.cpp
@@ -31,6 +31,7 @@
#include <boost/log/trivial.hpp>

#include <tbb/parallel_for.h>
+#include <tbb/spin_mutex.h>

#include <Shiny/Shiny.h>

Loading

0 comments on commit 731a93e

Please sign in to comment.