diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -549,6 +549,7 @@ qt5_add_dbus_adaptor( kwin_KDEINIT_SRCS org.kde.kwin.Compositing.xml dbusinterface.h KWin::CompositorDBusInterface ) qt5_add_dbus_adaptor( kwin_KDEINIT_SRCS org.kde.kwin.ColorCorrect.xml colorcorrection/colorcorrectdbusinterface.h KWin::ColorCorrect::ColorCorrectDBusInterface ) qt5_add_dbus_adaptor( kwin_KDEINIT_SRCS ${kwin_effects_dbus_xml} effects.h KWin::EffectsHandlerImpl ) +qt5_add_dbus_adaptor( kwin_KDEINIT_SRCS org.kde.kwin.OrientationSensor.xml orientation_sensor.h KWin::OrientationSensor) qt5_add_dbus_interface( kwin_KDEINIT_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/org.freedesktop.ScreenSaver.xml screenlocker_interface) diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -168,6 +168,7 @@ ../orientation_sensor.cpp ) kconfig_add_kcfg_files(testScriptedEffectLoader_SRCS ../settings.kcfgc) +qt5_add_dbus_adaptor( testScriptedEffectLoader_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/../org.kde.kwin.OrientationSensor.xml ${CMAKE_CURRENT_SOURCE_DIR}/../orientation_sensor.h KWin::OrientationSensor) add_executable( testScriptedEffectLoader ${testScriptedEffectLoader_SRCS}) target_link_libraries(testScriptedEffectLoader @@ -239,10 +240,12 @@ ../orientation_sensor.cpp ) kconfig_add_kcfg_files(testScreens_SRCS ../settings.kcfgc) +qt5_add_dbus_adaptor( testScreens_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/../org.kde.kwin.OrientationSensor.xml ${CMAKE_CURRENT_SOURCE_DIR}/../orientation_sensor.h KWin::OrientationSensor) add_executable( testScreens ${testScreens_SRCS}) target_include_directories(testScreens BEFORE PRIVATE ./) target_link_libraries(testScreens + Qt5::DBus Qt5::Sensors Qt5::Test Qt5::X11Extras @@ -273,9 +276,12 @@ ../orientation_sensor.cpp ) kconfig_add_kcfg_files(testXRandRScreens_SRCS ../settings.kcfgc) +qt5_add_dbus_adaptor( testXRandRScreens_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/../org.kde.kwin.OrientationSensor.xml ${CMAKE_CURRENT_SOURCE_DIR}/../orientation_sensor.h KWin::OrientationSensor) add_executable( testXRandRScreens ${testXRandRScreens_SRCS} ) target_link_libraries( testXRandRScreens Qt5::Test + Qt5::DBus + Qt5::Gui Qt5::Sensors Qt5::Widgets KF5::ConfigCore @@ -316,6 +322,7 @@ ) kconfig_add_kcfg_files(testScreenEdges_SRCS ../settings.kcfgc) qt5_add_dbus_interface( testScreenEdges_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/../org.freedesktop.ScreenSaver.xml screenlocker_interface) +qt5_add_dbus_adaptor( testScreenEdges_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/../org.kde.kwin.OrientationSensor.xml ${CMAKE_CURRENT_SOURCE_DIR}/../orientation_sensor.h KWin::OrientationSensor) add_executable( testScreenEdges ${testScreenEdges_SRCS}) set_target_properties(testScreenEdges PROPERTIES COMPILE_DEFINITIONS "NO_NONE_WINDOW") diff --git a/org.kde.kwin.OrientationSensor.xml b/org.kde.kwin.OrientationSensor.xml new file mode 100644 --- /dev/null +++ b/org.kde.kwin.OrientationSensor.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/orientation_sensor.h b/orientation_sensor.h --- a/orientation_sensor.h +++ b/orientation_sensor.h @@ -21,17 +21,22 @@ #include +#include + #include class QOrientationSensor; +class OrientationSensorAdaptor; class KStatusNotifierItem; namespace KWin { class KWIN_EXPORT OrientationSensor : public QObject { Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.kde.kwin.OrientationSensor") + Q_PROPERTY(bool userEnabled READ isUserEnabled WRITE setUserEnabled NOTIFY userEnabledChanged) public: explicit OrientationSensor(QObject *parent = nullptr); ~OrientationSensor(); @@ -56,17 +61,30 @@ return m_orientation; } + void setConfig(KSharedConfig::Ptr config) { + m_config = config; + } + + bool isUserEnabled() const { + return m_userEnabled; + } + void setUserEnabled(bool enabled); + Q_SIGNALS: void orientationChanged(); + void userEnabledChanged(bool); private: void setupStatusNotifier(); void startStopSensor(); + void loadConfig(); QOrientationSensor *m_sensor; bool m_enabled = false; bool m_userEnabled = true; Orientation m_orientation = Orientation::Undefined; KStatusNotifierItem *m_sni = nullptr; + KSharedConfig::Ptr m_config; + OrientationSensorAdaptor *m_adaptor = nullptr; }; diff --git a/orientation_sensor.cpp b/orientation_sensor.cpp --- a/orientation_sensor.cpp +++ b/orientation_sensor.cpp @@ -18,10 +18,12 @@ along with this program. If not, see . *********************************************************************/ #include "orientation_sensor.h" +#include #include #include +#include #include #include @@ -84,14 +86,26 @@ } m_enabled = enabled; if (m_enabled) { + loadConfig(); setupStatusNotifier(); + m_adaptor = new OrientationSensorAdaptor(this); } else { delete m_sni; m_sni = nullptr; + delete m_adaptor; + m_adaptor = nullptr; } startStopSensor(); } +void OrientationSensor::loadConfig() +{ + if (!m_config) { + return; + } + m_userEnabled = m_config->group("OrientationSensor").readEntry("Enabled", true); +} + void OrientationSensor::setupStatusNotifier() { if (m_sni) { @@ -110,6 +124,7 @@ [this] { m_userEnabled = !m_userEnabled; startStopSensor(); + emit userEnabledChanged(m_userEnabled); } ); } @@ -123,4 +138,16 @@ } } +void OrientationSensor::setUserEnabled(bool enabled) +{ + if (m_userEnabled == enabled) { + return; + } + m_userEnabled = enabled; + if (m_config) { + m_config->group("OrientationSensor").writeEntry("Enabled", m_userEnabled); + } + emit userEnabledChanged(m_userEnabled); +} + } diff --git a/screens.h b/screens.h --- a/screens.h +++ b/screens.h @@ -223,12 +223,6 @@ QVector m_scales; }; -inline -void Screens::setConfig(KSharedConfig::Ptr config) -{ - m_config = config; -} - inline int Screens::count() const { diff --git a/screens.cpp b/screens.cpp --- a/screens.cpp +++ b/screens.cpp @@ -226,6 +226,14 @@ return Qt::PrimaryOrientation; } +void Screens::setConfig(KSharedConfig::Ptr config) +{ + m_config = config; + if (m_orientationSensor) { + m_orientationSensor->setConfig(config); + } +} + BasicScreens::BasicScreens(Platform *backend, QObject *parent) : Screens(parent) , m_backend(backend) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -44,5 +44,11 @@ add_executable(cursorhotspottest cursorhotspottest.cpp) target_link_libraries(cursorhotspottest Qt5::Widgets) -add_executable(orientationtest orientationtest.cpp ../orientation_sensor.cpp) -target_link_libraries(orientationtest Qt5::Widgets Qt5::Sensors KF5::Notifications KF5::I18n) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) +set( orientationtest_SRCS + orientationtest.cpp + ../orientation_sensor.cpp +) +qt5_add_dbus_adaptor( orientationtest_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/../org.kde.kwin.OrientationSensor.xml ${CMAKE_CURRENT_SOURCE_DIR}/../orientation_sensor.h KWin::OrientationSensor) +add_executable(orientationtest ${orientationtest_SRCS}) +target_link_libraries(orientationtest Qt5::DBus Qt5::Widgets Qt5::Sensors KF5::ConfigCore KF5::Notifications KF5::I18n)