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
175182void 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
236242void 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
244248void KDisplayDaemon::setMonitorForChanges (bool enabled)
0 commit comments