8#include "tabletmodewatcher.h"
9#include <QCoreApplication>
11#if defined(KIRIGAMI_ENABLE_DBUS)
12#include "settings_interface.h"
13#include <QDBusConnection>
25class TabletModeWatcherSingleton
28 TabletModeWatcher self;
31Q_GLOBAL_STATIC(TabletModeWatcherSingleton, privateTabletModeWatcherSelf)
33class TabletModeWatcherPrivate
35 static constexpr auto PORTAL_GROUP =
"org.kde.TabletMode"_L1;
36 static constexpr auto KEY_AVAILABLE =
"available"_L1;
37 static constexpr auto KEY_ENABLED =
"enabled"_L1;
40 TabletModeWatcherPrivate(TabletModeWatcher *watcher)
46#if !defined(KIRIGAMI_ENABLE_DBUS) && (defined(Q_OS_ANDROID) || defined(Q_OS_IOS))
47 isTabletModeAvailable =
true;
49#elif defined(KIRIGAMI_ENABLE_DBUS)
52 if (qEnvironmentVariableIsSet(
"QT_QUICK_CONTROLS_MOBILE") || qEnvironmentVariableIsSet(
"KDE_KIRIGAMI_TABLET_MODE")) {
57 isTabletModeAvailable = isTabletMode;
58 }
else if (qEnvironmentVariableIsSet(
"QT_NO_XDG_DESKTOP_PORTAL")) {
61 qDBusRegisterMetaType<VariantMapMap>();
62 auto portal =
new OrgFreedesktopPortalSettingsInterface(u
"org.freedesktop.portal.Desktop"_s,
63 u
"/org/freedesktop/portal/desktop"_s,
68 &OrgFreedesktopPortalSettingsInterface::SettingChanged,
71 if (group != PORTAL_GROUP) {
74 if (key == KEY_AVAILABLE) {
75 Q_EMIT q->tabletModeAvailableChanged(value.
variant().
toBool());
76 }
else if (key == KEY_ENABLED) {
81 const auto reply = portal->ReadAll({PORTAL_GROUP});
84 watcher->deleteLater();
87 Q_EMIT q->tabletModeAvailableChanged(properties[KEY_AVAILABLE].toBool());
88 setIsTablet(properties[KEY_ENABLED].toBool());
94 ~TabletModeWatcherPrivate() =
default;
95 void setIsTablet(
bool tablet);
99 bool isTabletModeAvailable =
false;
100 bool isTabletMode =
false;
103void TabletModeWatcherPrivate::setIsTablet(
bool tablet)
105 if (isTabletMode == tablet) {
109 isTabletMode = tablet;
110 TabletModeChangedEvent
event{tablet};
111 Q_EMIT q->tabletModeChanged(tablet);
112 for (
auto *w : watchers) {
117TabletModeWatcher::TabletModeWatcher(
QObject *parent)
119 , d(new TabletModeWatcherPrivate(this))
123TabletModeWatcher::~TabletModeWatcher()
128TabletModeWatcher *TabletModeWatcher::self()
130 return &privateTabletModeWatcherSelf()->self;
133bool TabletModeWatcher::isTabletModeAvailable()
const
135 return d->isTabletModeAvailable;
138bool TabletModeWatcher::isTabletMode()
const
140 return d->isTabletMode;
143void TabletModeWatcher::addWatcher(
QObject *watcher)
145 d->watchers.append(watcher);
148void TabletModeWatcher::removeWatcher(
QObject *watcher)
150 d->watchers.removeAll(watcher);
156#include "moc_tabletmodewatcher.cpp"
bool sendEvent(QObject *receiver, QEvent *event)
QDBusConnection sessionBus()
void finished(QDBusPendingCallWatcher *self)
typename Select< 0 >::Type value() const const
QVariant variant() const const
int registerEventType(int hint)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QString fromLatin1(QByteArrayView str)
bool toBool() const const