Skip to content

Commit 7d63da6

Browse files
committed
add autostart code for Flatpak (whohoo!)
1 parent da11ab9 commit 7d63da6

6 files changed

Lines changed: 40 additions & 3 deletions

File tree

.clangd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
CompileFlags:
2-
Add: [-std=c++20, -I/usr/include/pipewire-0.3/, -I/usr/include/spa-0.2/]
2+
Add: [-std=c++20, -I/usr/include/pipewire-0.3/, -I/usr/include/spa-0.2/, -I/usr/include/glib-2.0/, -I/usr/lib/glib-2.0/include/]
33
Remove:
44
- -mno-direct-extern-access

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ find_package(PkgConfig REQUIRED)
4545
# PipeWire dependencies
4646
pkg_check_modules(PIPEWIRE REQUIRED libpipewire-0.3)
4747

48+
# Flatpak stuff
49+
if(IS_FLATPAK)
50+
pkg_check_modules(LIBPORTAL IMPORTED_TARGET REQUIRED libportal)
51+
pkg_check_modules(LIBPORTALQT IMPORTED_TARGET REQUIRED libportal-qt6)
52+
endif(IS_FLATPAK)
53+
4854
# Translations
4955
ki18n_install(po)
5056

dist/flatpak/de.berny23.virtual_surround_manager.Devel.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,23 @@
6767
"commit": "3e67b89a1adb4c98c248668189f8e21c6ddc68be"
6868
}
6969
]
70+
},
71+
{
72+
"name": "libportal",
73+
"buildsystem": "meson",
74+
"config-opts": [
75+
"-Ddocs=false",
76+
"-Dvapi=false",
77+
"-Dbackend-qt6=enabled"
78+
],
79+
"sources": [
80+
{
81+
"type": "git",
82+
"url": "https://github.com/flatpak/libportal.git",
83+
"tag": "0.10.0",
84+
"commit": "c23024018c8eb076549a1517fcb2d7f80d3e2ed5"
85+
}
86+
]
7087
}
7188
]
7289
}

src/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ target_link_libraries(virtual-surround-manager PRIVATE ${PIPEWIRE_LIBRARIES})
3939
if(IS_FLATPAK)
4040
message(STATUS "Flatpak build")
4141
target_compile_definitions(virtual-surround-manager PRIVATE IS_FLATPAK=1)
42+
target_link_libraries(virtual-surround-manager
43+
PRIVATE
44+
PkgConfig::LIBPORTAL
45+
PkgConfig::LIBPORTALQT
46+
)
4247
endif(IS_FLATPAK)
4348

4449
# AppImage stuff

src/frontend_manager.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,10 @@ void FrontendManager::set_autostart_enabled(bool value) {
236236
const QString destination = QStandardPaths::standardLocations(QStandardPaths::ConfigLocation).value(0) + QStringLiteral("/autostart/de.berny23.virtual_surround_manager.desktop");
237237

238238
#ifdef IS_FLATPAK
239-
// TODO: Use portal with option autostart like this: https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Background.html
240-
// This can be called with the variable m_autostart_enabled directly, outside if.
239+
// Use libportal to request Flatpak autostart
240+
g_autoptr(GPtrArray) cmd = nullptr;
241+
XdpBackgroundFlags flags = value ? XDP_BACKGROUND_FLAG_AUTOSTART : XDP_BACKGROUND_FLAG_NONE;
242+
xdp_portal_request_background(XdpQt::globalPortalObject(), nullptr, const_cast<char *>("Autostart"), cmd, flags, nullptr, nullptr, this);
241243
#endif
242244

243245
if (m_autostart_enabled) {

src/frontend_manager.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
#include <qtmetamacros.h>
1616
#include <qurl.h>
1717

18+
#ifdef IS_FLATPAK
19+
#include <glib.h>
20+
#include <glibconfig.h>
21+
#include <libportal-qt6/portal-qt6.h>
22+
#include <libportal/background.h>
23+
#endif
24+
1825
class FrontendManager : public QObject {
1926
Q_OBJECT
2027
// Whether virtual surround sound is enabled or not

0 commit comments

Comments
 (0)