diff --git a/.gitignore b/.gitignore index 0d3573ce..9e131bc9 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ qrc_* ckb-dev-detect-report.gz ckb-next-dev-detect-report.gz macos/pkgproj/build +compile_commands.json diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 4d8359dd..4670aa7d 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -398,6 +398,13 @@ elseif (LINUX) ) endif() endif() + + target_sources( + ckb-next + PRIVATE + wayland/waylandutils.cpp + wayland/waylandutils.h + ) endif () if (MAC_LEGACY) diff --git a/src/gui/extrasettingswidget.cpp b/src/gui/extrasettingswidget.cpp index e3fa9f3f..e39244c1 100644 --- a/src/gui/extrasettingswidget.cpp +++ b/src/gui/extrasettingswidget.cpp @@ -5,9 +5,7 @@ #include "ckbsettings.h" #include "animdetailsdialog.h" #include "kbmanager.h" -#ifdef USE_XCB_SCREENSAVER -#include "idletimer.h" -#endif +#include "wayland/waylandutils.h" // KbLight static int lastSharedDimming = -2; @@ -79,7 +77,7 @@ ExtraSettingsWidget::ExtraSettingsWidget(QWidget *parent) : #endif // We need to explicitly disable this if there's a wayland session. // If not, the idle timer will only count when there's activity inside XWayland windows. - if(IdleTimer::isWayland()){ + if(WaylandUtils::isWayland()){ QString notSupported(tr("This feature is not supported under Wayland")); ui->timerBox->setToolTip(notSupported); ui->timerMinBox->setToolTip(notSupported); diff --git a/src/gui/idletimer.cpp b/src/gui/idletimer.cpp index 99e35c86..d6af6d0d 100644 --- a/src/gui/idletimer.cpp +++ b/src/gui/idletimer.cpp @@ -54,13 +54,3 @@ int IdleTimer::getIdleTime(){ return 0; } #endif - -bool IdleTimer::isWayland(){ - QByteArray wdesktop = qgetenv("WAYLAND_DESKTOP"); - if(!wdesktop.isEmpty()) - return true; - QString stype(qgetenv("XDG_SESSION_TYPE")); - if(stype == "wayland") - return true; - return false; -} diff --git a/src/gui/idletimer.h b/src/gui/idletimer.h index 55d0e9ee..2249d989 100644 --- a/src/gui/idletimer.h +++ b/src/gui/idletimer.h @@ -5,7 +5,6 @@ class IdleTimer { public: static int getIdleTime(); - static bool isWayland(); }; #endif // IDLETIMER_H diff --git a/src/gui/kbmanager.cpp b/src/gui/kbmanager.cpp index c7f1d834..ef58addd 100644 --- a/src/gui/kbmanager.cpp +++ b/src/gui/kbmanager.cpp @@ -1,6 +1,7 @@ #include "kbmanager.h" #include "idletimer.h" #include +#include "wayland/waylandutils.h" #ifndef Q_OS_MACOS QString devpath = "/dev/input/ckb%1"; @@ -74,7 +75,7 @@ void KbManager::init(const QString& guiVersion){ return; _kbManager = new KbManager(); #ifdef USE_XCB_SCREENSAVER - if(!IdleTimer::isWayland() && CkbSettings::get("Program/IdleTimerEnable", true).toBool()){ + if(!WaylandUtils::isWayland() && CkbSettings::get("Program/IdleTimerEnable", true).toBool()){ setIdleTimer(true); } #endif diff --git a/src/gui/kbmodeeventmgr.cpp b/src/gui/kbmodeeventmgr.cpp index 9fdc1883..4191f8b3 100644 --- a/src/gui/kbmodeeventmgr.cpp +++ b/src/gui/kbmodeeventmgr.cpp @@ -4,7 +4,7 @@ #include #include "kbwidget.h" #include -#include "idletimer.h" +#include "wayland/waylandutils.h" #include "kbwindowinfomodel.h" KbModeEventMgr::KbModeEventMgr(QWidget* parent, KbMode* m) : @@ -15,7 +15,7 @@ KbModeEventMgr::KbModeEventMgr(QWidget* parent, KbMode* m) : connect(model, &KbWindowInfoModel::rowsInserted, this, &KbModeEventMgr::rowsChanged); connect(model, &KbWindowInfoModel::rowsRemoved, this, &KbModeEventMgr::rowsChanged); ui->setupUi(this); - if(!IdleTimer::isWayland()) + if(!WaylandUtils::isWayland()) ui->waylandWarning->hide(); ui->modeLabel->setText(QString(tr("Switch to mode \"%1\" when:")).arg(m->name())); ui->tableView->setModel(model); diff --git a/src/gui/wayland/waylandutils.cpp b/src/gui/wayland/waylandutils.cpp new file mode 100644 index 00000000..94f1be0f --- /dev/null +++ b/src/gui/wayland/waylandutils.cpp @@ -0,0 +1,25 @@ +#include "waylandutils.h" + +#include + +namespace WaylandUtils +{ + +bool isWayland() +{ + if (qGuiApp->platformName() == "wayland") { + return true; + } + + if(!qEnvironmentVariableIsEmpty("WAYLAND_DESKTOP")) { + return true; + } + + if(qEnvironmentVariable("XDG_SESSION_TYPE") == "wayland") { + return true; + } + + return false; +} + +} // WaylandUtils diff --git a/src/gui/wayland/waylandutils.h b/src/gui/wayland/waylandutils.h new file mode 100644 index 00000000..12769e14 --- /dev/null +++ b/src/gui/wayland/waylandutils.h @@ -0,0 +1,13 @@ +#ifndef WAYLANDUTILS_HPP +#define WAYLANDUTILS_HPP + +#include + +namespace WaylandUtils +{ + +bool isWayland(); + +} // WaylandUtils + +#endif // WAYLANDUTILS_HPP