Commit e0b1a571 authored by Martin Flöser's avatar Martin Flöser

Add DBus interface to OrientationSensor and a persistent configuration

Summary:
The initial state for user enabled is now read from config. In addition
a DBus interface is provided exporting this property. This allows
KScreen to determine whether automatic screen rotation is available and
whether the user has it enabled or not.

Furthermore KScreen can change the property and this gets stored into
the configuration. Thus KScreen can offer a user interface to
enable/disable automatic screen rotation as well as enabling/disabling
the manual rotation based on the current user settings.

Test Plan:
Not yet tested, coded on the system which doesn't have an
orientation sensor

Reviewers: #kwin, #plasma, sebas, davidedmundson

Subscribers: plasma-devel, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D8738
parent 0abc5e02
......@@ -549,6 +549,7 @@ qt5_add_dbus_adaptor( kwin_KDEINIT_SRCS org.kde.KWin.xml dbusinterface.h KWin::D
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)
......
......@@ -168,6 +168,7 @@ set( testScriptedEffectLoader_SRCS
../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 @@ set( testScreens_SRCS
../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 @@ set( testXRandRScreens_SRCS
../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 @@ set( testScreenEdges_SRCS
)
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")
......
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.kde.kwin.OrientationSensor">
<property name="userEnabled" type="b" access="readwrite"/>
</interface>
</node>
......@@ -18,10 +18,12 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "orientation_sensor.h"
#include <orientationsensoradaptor.h>
#include <QOrientationSensor>
#include <QOrientationReading>
#include <KConfigGroup>
#include <KStatusNotifierItem>
#include <KLocalizedString>
......@@ -84,14 +86,26 @@ void OrientationSensor::setEnabled(bool enabled)
}
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 @@ void OrientationSensor::setupStatusNotifier()
[this] {
m_userEnabled = !m_userEnabled;
startStopSensor();
emit userEnabledChanged(m_userEnabled);
}
);
}
......@@ -123,4 +138,16 @@ void OrientationSensor::startStopSensor()
}
}
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);
}
}
......@@ -21,9 +21,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QObject>
#include <KSharedConfig>
#include <kwin_export.h>
class QOrientationSensor;
class OrientationSensorAdaptor;
class KStatusNotifierItem;
namespace KWin
......@@ -32,6 +35,8 @@ 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 @@ public:
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;
};
......
......@@ -226,6 +226,14 @@ Qt::ScreenOrientation Screens::orientation(int screen) const
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)
......
......@@ -223,12 +223,6 @@ private:
QVector<qreal> m_scales;
};
inline
void Screens::setConfig(KSharedConfig::Ptr config)
{
m_config = config;
}
inline
int Screens::count() const
{
......
......@@ -44,5 +44,11 @@ target_link_libraries(pointergestures Qt5::Gui Qt5::Quick KF5::WaylandClient)
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)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment