Skip to content

Commit e9ae432

Browse files
committed
refactor: provide osd as separate application
This aligns the implementation with KScreen. It's a prerequisite for our port to Qt 6.
1 parent 270eb75 commit e9ae432

36 files changed

+663
-1168
lines changed

CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
1616
include(KDEInstallDirs)
1717
include(KDECMakeSettings)
1818
include(KDECompilerSettings NO_POLICY_SCOPE)
19+
include(ECMConfiguredInstall)
20+
include(ECMGenerateDBusServiceFile)
1921
include(ECMInstallIcons)
2022
include(ECMMarkAsTest)
2123
include(ECMQtDeclareLoggingCategory)
@@ -29,6 +31,15 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
2931
DBusAddons
3032
Declarative
3133
I18n
34+
WindowSystem
35+
)
36+
37+
find_package(LayerShellQt)
38+
set_package_properties(LayerShellQt PROPERTIES
39+
DESCRIPTION "Layer shell Qt bindings"
40+
URL "https://invent.kde.org/plasma/layer-shell-qt"
41+
PURPOSE "Required for the screen selection osd"
42+
TYPE REQUIRED
3243
)
3344

3445
set(MIN_DISMAN_VERSION "0.519.80")

plasma-integration/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
add_subdirectory(kded)
2+
add_subdirectory(osd)
23
add_subdirectory(plasmoid)
34
ki18n_install(po)

plasma-integration/kded/CMakeLists.txt

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ set(kdisplay_daemon_SRCS
1111
daemon.cpp
1212
config.cpp
1313
generator.cpp
14-
osd.cpp
15-
osdmanager.cpp
16-
osdaction.cpp
14+
../osd/osdaction.cpp
1715
${CMAKE_SOURCE_DIR}/common/orientation_sensor.cpp
1816
${CMAKE_SOURCE_DIR}/common/utils.cpp
1917
)
@@ -32,6 +30,10 @@ qt5_add_dbus_adaptor(kdisplay_daemon_SRCS
3230
daemon.h
3331
KDisplayDaemon
3432
)
33+
qt5_add_dbus_interface(kdisplay_daemon_SRCS
34+
../osd/org.kwinft.kdisplay.osdService.xml
35+
osdservice_interface
36+
)
3537

3638
add_library(kdisplayd MODULE ${kdisplay_daemon_SRCS})
3739

@@ -51,12 +53,3 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/kdisplayd.desktop.cmake
5153
kcoreaddons_desktop_to_json(kdisplayd ${CMAKE_CURRENT_BINARY_DIR}/kdisplayd.desktop)
5254

5355
install(TARGETS kdisplayd DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/kded)
54-
55-
set(QML_FILES
56-
qml/Osd.qml
57-
qml/OsdItem.qml
58-
qml/OsdSelector.qml
59-
qml/OutputIdentifier.qml
60-
)
61-
62-
install(FILES ${QML_FILES} DESTINATION ${KDE_INSTALL_DATADIR}/kded_kdisplay/qml)

plasma-integration/kded/daemon.cpp

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "generator.h"
1414
#include "kdisplay_daemon_debug.h"
1515
#include "kdisplayadaptor.h"
16-
#include "osdmanager.h"
16+
#include "osdservice_interface.h"
1717

1818
#include <disman/configmonitor.h>
1919
#include <disman/getconfigoperation.h>
@@ -37,6 +37,7 @@ KDisplayDaemon::KDisplayDaemon(QObject* parent, const QList<QVariant>&)
3737
, m_orientationSensor(new OrientationSensor(this))
3838
{
3939
Disman::Log::instance();
40+
qMetaTypeId<KDisplay::OsdAction>();
4041

4142
connect(new Disman::GetConfigOperation,
4243
&Disman::GetConfigOperation::finished,
@@ -68,8 +69,15 @@ void KDisplayDaemon::init(Disman::ConfigOperation* op)
6869
connect(action, &QAction::triggered, this, &KDisplayDaemon::displayButton);
6970

7071
new KdisplayAdaptor(this);
71-
// Initialize OSD manager to register its dbus interface
72-
m_osdManager = new OsdManager(this);
72+
73+
QString const osdService = QStringLiteral("org.kwinft.kdisplay.osdService");
74+
QString const osdPath = QStringLiteral("/org/kwinft/kdisplay/osdService");
75+
m_osdServiceInterface = new OrgKwinftKdisplayOsdServiceInterface(
76+
osdService, osdPath, QDBusConnection::sessionBus(), this);
77+
78+
// Set a longer timeout to not assume timeout while the osd is still shown
79+
m_osdServiceInterface->setTimeout(
80+
std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::seconds(60)).count());
7381

7482
connect(cfg, &Disman::Config::output_added, this, &KDisplayDaemon::applyConfig);
7583
connect(cfg, &Disman::Config::output_removed, this, &KDisplayDaemon::applyConfig);
@@ -160,26 +168,25 @@ void KDisplayDaemon::applyConfig()
160168
{
161169
qCDebug(KDISPLAY_KDED) << "Applying config";
162170

163-
const bool showOsd = m_monitoredConfig->outputs().size() > 1 && !m_startingUp
171+
auto const should_show_osd = m_monitoredConfig->outputs().size() > 1 && !m_startingUp
164172
&& m_monitoredConfig->cause() == Disman::Config::Cause::generated;
165173

166-
if (showOsd) {
174+
if (should_show_osd) {
167175
qCDebug(KDISPLAY_KDED) << "Getting ideal config from user via OSD...";
168-
auto action = m_osdManager->showActionSelector();
169-
connect(action, &OsdAction::selected, this, &KDisplayDaemon::applyOsdAction);
176+
show_osd();
170177
} else {
171-
m_osdManager->hideOsd();
178+
m_osdServiceInterface->hideOsd();
172179
}
173180
}
174181

175182
void KDisplayDaemon::applyLayoutPreset(const QString& presetName)
176183
{
177-
const QMetaEnum actionEnum = QMetaEnum::fromType<OsdAction::Action>();
184+
auto const actionEnum = QMetaEnum::fromType<KDisplay::OsdAction::Action>();
178185
Q_ASSERT(actionEnum.isValid());
179186

180187
bool ok;
181-
auto action
182-
= static_cast<OsdAction::Action>(actionEnum.keyToValue(qPrintable(presetName), &ok));
188+
auto action = static_cast<KDisplay::OsdAction::Action>(
189+
actionEnum.keyToValue(qPrintable(presetName), &ok));
183190
if (!ok) {
184191
qCWarning(KDISPLAY_KDED) << "Cannot apply unknown screen layout preset named" << presetName;
185192
return;
@@ -201,7 +208,7 @@ void KDisplayDaemon::setAutoRotate(bool value)
201208
refreshConfig();
202209
}
203210

204-
void KDisplayDaemon::applyOsdAction(OsdAction::Action action)
211+
void KDisplayDaemon::applyOsdAction(KDisplay::OsdAction::Action action)
205212
{
206213
qCDebug(KDISPLAY_KDED) << "Applying OSD action:" << action;
207214

@@ -218,27 +225,24 @@ void KDisplayDaemon::configChanged()
218225
updateOrientation();
219226
}
220227

221-
void KDisplayDaemon::showOsd(const QString& icon, const QString& text)
222-
{
223-
QDBusMessage msg = QDBusMessage::createMethodCall(QLatin1String("org.kde.plasmashell"),
224-
QLatin1String("/org/kde/osdService"),
225-
QLatin1String("org.kde.osdService"),
226-
QLatin1String("showText"));
227-
msg << icon << text;
228-
QDBusConnection::sessionBus().asyncCall(msg);
229-
}
230-
231-
void KDisplayDaemon::showOutputIdentifier()
228+
void KDisplayDaemon::show_osd()
232229
{
233-
m_osdManager->showOutputIdentifiers();
230+
auto call = m_osdServiceInterface->showActionSelector();
231+
auto watcher = new QDBusPendingCallWatcher(call);
232+
connect(watcher, &QDBusPendingCallWatcher::finished, this, [this, watcher] {
233+
watcher->deleteLater();
234+
QDBusReply<int> reply = *watcher;
235+
if (!reply.isValid()) {
236+
return;
237+
}
238+
applyOsdAction(static_cast<KDisplay::OsdAction::Action>(reply.value()));
239+
});
234240
}
235241

236242
void KDisplayDaemon::displayButton()
237243
{
238244
qCDebug(KDISPLAY_KDED) << "displayBtn triggered";
239-
240-
auto action = m_osdManager->showActionSelector();
241-
connect(action, &OsdAction::selected, this, &KDisplayDaemon::applyOsdAction);
245+
show_osd();
242246
}
243247

244248
void KDisplayDaemon::setMonitorForChanges(bool enabled)

plasma-integration/kded/daemon.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@
77
#ifndef KSCREEN_DAEMON_H
88
#define KSCREEN_DAEMON_H
99

10-
#include "osdaction.h"
10+
#include "../osd/osdaction.h"
1111

1212
#include <disman/config.h>
1313

1414
#include <kdedmodule.h>
1515

1616
#include <QVariant>
1717

18+
class OrgKwinftKdisplayOsdServiceInterface;
19+
1820
namespace Disman
1921
{
2022
class ConfigOperation;
2123
}
2224

2325
class OrientationSensor;
24-
class OsdManager;
2526

2627
class KDisplayDaemon : public KDEDModule
2728
{
@@ -50,21 +51,19 @@ public Q_SLOTS:
5051
void displayButton();
5152
void setMonitorForChanges(bool enabled);
5253

53-
void showOutputIdentifier();
54-
void applyOsdAction(OsdAction::Action action);
54+
void show_osd();
55+
void applyOsdAction(KDisplay::OsdAction::Action action);
5556

5657
void doApplyConfig(Disman::ConfigPtr const& config);
5758
void refreshConfig();
5859

59-
void showOsd(const QString& icon, const QString& text);
60-
6160
void update_auto_rotate();
6261
void updateOrientation();
6362

6463
Disman::ConfigPtr m_monitoredConfig;
6564
bool m_monitoring;
6665
bool m_configDirty = true;
67-
OsdManager* m_osdManager;
66+
OrgKwinftKdisplayOsdServiceInterface* m_osdServiceInterface;
6867
OrientationSensor* m_orientationSensor;
6968
bool m_startingUp = true;
7069
};

plasma-integration/kded/generator.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
namespace Generator
1616
{
1717

18-
Disman::ConfigPtr displaySwitch(OsdAction::Action action, Disman::ConfigPtr const& config)
18+
Disman::ConfigPtr displaySwitch(KDisplay::OsdAction::Action action, Disman::ConfigPtr const& config)
1919
{
2020
qCDebug(KDISPLAY_KDED) << "Display Switch";
2121

@@ -33,17 +33,17 @@ Disman::ConfigPtr displaySwitch(OsdAction::Action action, Disman::ConfigPtr cons
3333

3434
auto success = false;
3535
switch (action) {
36-
case OsdAction::ExtendLeft: {
36+
case KDisplay::OsdAction::ExtendLeft: {
3737
qCDebug(KDISPLAY_KDED) << "Extend to left";
3838
success = generator.extend(Disman::Generator::Extend_direction::left);
3939
break;
4040
}
41-
case OsdAction::ExtendRight: {
41+
case KDisplay::OsdAction::ExtendRight: {
4242
qCDebug(KDISPLAY_KDED) << "Extend to right";
4343
success = generator.extend(Disman::Generator::Extend_direction::right);
4444
break;
4545
}
46-
case OsdAction::SwitchToExternal: {
46+
case KDisplay::OsdAction::SwitchToExternal: {
4747
qCDebug(KDISPLAY_KDED) << "Turn off embedded (laptop)";
4848
auto embedded = generator.embedded();
4949
if (embedded) {
@@ -52,18 +52,18 @@ Disman::ConfigPtr displaySwitch(OsdAction::Action action, Disman::ConfigPtr cons
5252
}
5353
break;
5454
}
55-
case OsdAction::SwitchToInternal: {
55+
case KDisplay::OsdAction::SwitchToInternal: {
5656
qCDebug(KDISPLAY_KDED) << "Turn off external screen";
5757
// TODO: Why would a user want to do that?
5858
qCWarning(KDISPLAY_KDED)
5959
<< "Weird option to turn off external was selected, just do nothing instead.";
6060
break;
6161
}
62-
case OsdAction::Clone: {
62+
case KDisplay::OsdAction::Clone: {
6363
success = generator.replicate();
6464
break;
6565
}
66-
case OsdAction::NoAction:
66+
case KDisplay::OsdAction::NoAction:
6767
return nullptr;
6868
}
6969

plasma-integration/kded/generator.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
*/
77
#pragma once
88

9-
#include "osdaction.h"
9+
#include "../osd/osdaction.h"
1010

1111
#include <disman/types.h>
1212

1313
namespace Generator
1414
{
1515

16-
Disman::ConfigPtr displaySwitch(OsdAction::Action action, Disman::ConfigPtr const& config);
16+
Disman::ConfigPtr displaySwitch(KDisplay::OsdAction::Action action,
17+
Disman::ConfigPtr const& config);
1718

1819
}

0 commit comments

Comments
 (0)