diff --git a/src/libkirigami/tabletmodewatcher.cpp b/src/libkirigami/tabletmodewatcher.cpp index 7f7e855e..c7f97a7e 100644 --- a/src/libkirigami/tabletmodewatcher.cpp +++ b/src/libkirigami/tabletmodewatcher.cpp @@ -1,131 +1,139 @@ /* * Copyright 2018 Marco Martin * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include "tabletmodewatcher.h" #include "tabletmodemanager_interface.h" #ifdef Q_OS_ANDROID #include #endif //TODO: All the dbus stuff should be conditional, optional win32 support namespace Kirigami { class TabletModeWatcherSingleton { public: TabletModeWatcher self; }; Q_GLOBAL_STATIC(TabletModeWatcherSingleton, privateTabletModeWatcherSelf) class TabletModeWatcherPrivate { public: TabletModeWatcherPrivate(TabletModeWatcher *watcher) : q(watcher) { #if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) isTabletModeAvailable = true; isTabletMode = true; #elif defined(Q_OS_MACOS) isTabletModeAvailable = false; isTabletMode = false; #elif defined(Q_OS_LINUX) || defined(Q_OS_UNIX) - m_interface = new OrgKdeKWinTabletModeManagerInterface(QStringLiteral("org.kde.KWin"), QStringLiteral("/org/kde/KWin"), QDBusConnection::sessionBus(), q); - - if (m_interface->isValid()) { - //NOTE: the initial call is actually sync, because is better a tiny freeze than having the ui always recalculated and changed at the start - isTabletModeAvailable = m_interface->tabletModeAvailable(); - isTabletMode = m_interface->tabletMode(); - QObject::connect(m_interface, &OrgKdeKWinTabletModeManagerInterface::tabletModeChanged, - q, [this](bool tabletMode) { - setIsTablet(tabletMode); - }); - QObject::connect(m_interface, &OrgKdeKWinTabletModeManagerInterface::tabletModeAvailableChanged, - q, [this](bool avail) { - isTabletModeAvailable = avail; - emit q->tabletModeAvailableChanged(avail); - }); + //Mostly for debug purposes and for platforms which are always mobile, + //such as Plasma Mobile + if (qEnvironmentVariableIsSet("QT_QUICK_CONTROLS_MOBILE")) { + isTabletMode = (QString::fromLatin1(qgetenv("QT_QUICK_CONTROLS_MOBILE")) == QStringLiteral("1") || + QString::fromLatin1(qgetenv("QT_QUICK_CONTROLS_MOBILE")) == QStringLiteral("true")); + isTabletModeAvailable = isTabletMode; } else { - isTabletModeAvailable = false; - isTabletMode = false; + m_interface = new OrgKdeKWinTabletModeManagerInterface(QStringLiteral("org.kde.KWin"), QStringLiteral("/org/kde/KWin"), QDBusConnection::sessionBus(), q); + + if (m_interface->isValid()) { + //NOTE: the initial call is actually sync, because is better a tiny freeze than having the ui always recalculated and changed at the start + isTabletModeAvailable = m_interface->tabletModeAvailable(); + isTabletMode = m_interface->tabletMode(); + QObject::connect(m_interface, &OrgKdeKWinTabletModeManagerInterface::tabletModeChanged, + q, [this](bool tabletMode) { + setIsTablet(tabletMode); + }); + QObject::connect(m_interface, &OrgKdeKWinTabletModeManagerInterface::tabletModeAvailableChanged, + q, [this](bool avail) { + isTabletModeAvailable = avail; + emit q->tabletModeAvailableChanged(avail); + }); + } else { + isTabletModeAvailable = false; + isTabletMode = false; + } } //TODO: case for Windows #else isTabletModeAvailable = false; isTabletMode = false; #endif } ~TabletModeWatcherPrivate() {}; void setIsTablet(bool tablet); TabletModeWatcher *q; -#ifndef Q_OS_ANDROID - OrgKdeKWinTabletModeManagerInterface *m_interface; +#if (defined(Q_OS_LINUX) || defined(Q_OS_UNIX)) && !defined(Q_OS_ANDROID) + OrgKdeKWinTabletModeManagerInterface *m_interface = nullptr; #endif bool isTabletModeAvailable = false; bool isTabletMode = false; }; void TabletModeWatcherPrivate::setIsTablet(bool tablet) { if (isTabletMode == tablet) { return; } isTabletMode = tablet; emit q->tabletModeChanged(tablet); } TabletModeWatcher::TabletModeWatcher(QObject *parent) : QObject(parent), d(new TabletModeWatcherPrivate(this)) { } TabletModeWatcher::~TabletModeWatcher() { delete d; } TabletModeWatcher *TabletModeWatcher::self() { return &privateTabletModeWatcherSelf()->self; } bool TabletModeWatcher::isTabletModeAvailable() const { return d->isTabletModeAvailable; } bool TabletModeWatcher::isTabletMode() const { return d->isTabletMode; } } #include "moc_tabletmodewatcher.cpp" diff --git a/src/settings.cpp b/src/settings.cpp index 8042143f..3490745f 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1,93 +1,84 @@ /* * Copyright 2016 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "settings.h" #include #include #include #include #include "libkirigami/tabletmodewatcher.h" Settings::Settings(QObject *parent) : QObject(parent) { -#if defined(Q_OS_IOS) || defined(Q_OS_ANDROID) || defined(Q_OS_BLACKBERRY) || defined(Q_OS_QNX) || defined(Q_OS_WINRT) - m_mobile = true; -#else - if (qEnvironmentVariableIsSet("QT_QUICK_CONTROLS_MOBILE")) { - m_mobile = (QString::fromLatin1(qgetenv("QT_QUICK_CONTROLS_MOBILE")) == QStringLiteral("1") || - QString::fromLatin1(qgetenv("QT_QUICK_CONTROLS_MOBILE")) == QStringLiteral("true")); - } else { - m_mobile = Kirigami::TabletModeWatcher::self()->isTabletMode(); - connect(Kirigami::TabletModeWatcher::self(), &Kirigami::TabletModeWatcher::tabletModeChanged, - this, [this](bool tabletMode) { - setIsMobile(tabletMode); - }); - } -#endif + m_mobile = Kirigami::TabletModeWatcher::self()->isTabletMode(); + connect(Kirigami::TabletModeWatcher::self(), &Kirigami::TabletModeWatcher::tabletModeChanged, + this, [this](bool tabletMode) { + setIsMobile(tabletMode); + }); const QString configPath = QStandardPaths::locate(QStandardPaths::ConfigLocation, QStringLiteral("kdeglobals")); if (QFile::exists(configPath)) { QSettings globals(configPath, QSettings::IniFormat); globals.beginGroup(QStringLiteral("KDE")); m_scrollLines = qMax(1, globals.value(QStringLiteral("WheelScrollLines"), 3).toInt()); } else { m_scrollLines = 3; } } Settings::~Settings() { } void Settings::setIsMobile(bool mobile) { if (mobile == m_mobile) { return; } m_mobile = mobile; emit isMobileChanged(); } bool Settings::isMobile() const { return m_mobile; } QString Settings::style() const { return m_style; } void Settings::setStyle(const QString &style) { m_style = style; } int Settings::mouseWheelScrollLines() const { return m_scrollLines; } #include "moc_settings.cpp"