1- // SPDX-FileCopyrightText: 2018 - 2024 UnionTech Software Technology Co., Ltd.
1+ // SPDX-FileCopyrightText: 2018 - 2026 UnionTech Software Technology Co., Ltd.
22//
33// SPDX-License-Identifier: GPL-3.0-or-later
44#include " displayworker.h"
1212#include < QJsonObject>
1313#include < QLoggingCategory>
1414
15- #include < Registry.hpp >
16- #include < WayQtUtils.hpp >
17- #include < OutputManager.hpp >
18- #include < Output.hpp >
19- #include < TreeLandOutputManager.hpp >
15+ #include < Registry.h >
16+ #include < WayQtUtils.h >
17+ #include < OutputManager.h >
18+ #include < Output.h >
19+ #include < TreeLandOutputManager.h >
2020
2121Q_LOGGING_CATEGORY (DdcDisplayWorker, " dcc-display-worker" )
2222
@@ -41,14 +41,8 @@ DisplayWorker::DisplayWorker(DisplayModel *model, QObject *parent, bool isSync)
4141
4242 if (WQt::Utils::isTreeland ()) {
4343 m_reg = new WQt::Registry (WQt::Wayland::display (), this );
44+ connect (m_reg, &WQt::Registry::interfaceRegistered, this , &DisplayWorker::onInterfaceRegistered);
4445 m_reg->setup ();
45- auto *opMgr = m_reg->outputManager ();
46- if (!opMgr) {
47- qFatal (" Unable to start the output manager" );
48- }
49- connect (opMgr, &WQt::OutputManager::done, this , [this ]() {
50- onWlMonitorListChanged ();
51- });
5246 } else {
5347 connect (m_displayInter, &DisplayDBusProxy::WallpaperURlsChanged, this , &DisplayWorker::updateWallpaper);
5448 connect (m_displayInter, &DisplayDBusProxy::WorkspaceSwitched, this , &DisplayWorker::updateWallpaper);
@@ -84,20 +78,7 @@ DisplayWorker::~DisplayWorker()
8478
8579void DisplayWorker::active ()
8680{
87- if (WQt::Utils::isTreeland ()) {
88- m_reg->outputManager ()->waitForDone ();
89- onWlMonitorListChanged ();
90-
91- m_model->setDisplayMode (EXTEND_MODE); // TODO: use dconfig
92- auto *treelandOpMgr = m_reg->treeLandOutputManager ();
93- m_model->setPrimary (treelandOpMgr->mPrimaryOutput );
94- connect (treelandOpMgr, &WQt::TreeLandOutputManager::primaryOutputChanged, this , [this ](){
95- m_model->setPrimary (m_reg->treeLandOutputManager ()->mPrimaryOutput );
96- });
97-
98- m_model->setResolutionRefreshEnable (true );
99- m_model->setBrightnessEnable (false ); // TODO: support gamma effects
100- } else {
81+ if (!WQt::Utils::isTreeland ()) {
10182 // m_model->setAllowEnableMultiScaleRatio(
10283 // valueByQSettings<bool>(DCC_CONFIG_FILES,
10384 // "Display",
@@ -234,6 +215,11 @@ void DisplayWorker::onWlMonitorListChanged()
234215 if (isNew)
235216 wlMonitorAdded (head);
236217 }
218+ for (auto output : m_reg->waylandOutputs ()) {
219+ wlOutputAdded (output);
220+ }
221+ connect (m_reg, &WQt::Registry::outputAdded, this , &DisplayWorker::wlOutputAdded);
222+ connect (m_reg, &WQt::Registry::outputRemoved, this , &DisplayWorker::wlOutputRemoved);
237223}
238224
239225void DisplayWorker::updateWallpaper ()
@@ -248,6 +234,17 @@ void DisplayWorker::updateMonitorWallpaper(Monitor *mon)
248234 mon->setWallpaper (m_displayInter->GetCurrentWorkspaceBackgroundForMonitor (mon->name ()));
249235}
250236
237+ void DisplayWorker::onBrightnessChanged (const treeland_output_color_control_v1 *colorControl, double brightness)
238+ {
239+ brightness = qBound (0.0 , brightness / 100.0 , 1.0 );
240+ for (auto it (m_control_monitors.cbegin ()); it != m_control_monitors.cend (); ++it) {
241+ if (it.value () == colorControl) {
242+ it.key ()->setBrightness (brightness);
243+ return ;
244+ }
245+ }
246+ }
247+
251248void DisplayWorker::onMonitorsBrightnessChanged (const BrightnessMap &brightness)
252249{
253250 if (brightness.isEmpty ())
@@ -283,6 +280,39 @@ void DisplayWorker::onGetScreenScalesFinished(QDBusPendingCallWatcher *w)
283280 w->deleteLater ();
284281}
285282
283+ void DisplayWorker::onInterfaceRegistered (WQt::Registry::Interface interface)
284+ {
285+ switch (interface) {
286+ case WQt::Registry::OutputManagerInterface: {
287+ auto *opMgr = m_reg->outputManager ();
288+ if (!opMgr) {
289+ qCFatal (DdcDisplayWorker) << " Unable to start the output manager" ;
290+ }
291+ connect (opMgr, &WQt::OutputManager::done, this , &DisplayWorker::onWlOutputManagerDone);
292+ } break ;
293+ case WQt::Registry::TreeLandOutputManagerInterface: {
294+ connect (m_reg->treeLandOutputManager (), &WQt::TreeLandOutputManager::brightnessChanged, this , &DisplayWorker::onBrightnessChanged);
295+ } break ;
296+ default :
297+ break ;
298+ }
299+ }
300+
301+ void DisplayWorker::onWlOutputManagerDone ()
302+ {
303+ onWlMonitorListChanged ();
304+
305+ m_model->setDisplayMode (EXTEND_MODE); // TODO: use dconfig
306+ auto *treelandOpMgr = m_reg->treeLandOutputManager ();
307+ m_model->setPrimary (treelandOpMgr->mPrimaryOutput );
308+ connect (treelandOpMgr, &WQt::TreeLandOutputManager::primaryOutputChanged, this , [this ](){
309+ m_model->setPrimary (m_reg->treeLandOutputManager ()->mPrimaryOutput );
310+ });
311+
312+ m_model->setResolutionRefreshEnable (true );
313+ m_model->setBrightnessEnable (false ); // TODO: support gamma effects
314+ }
315+
286316#ifndef DCC_DISABLE_ROTATE
287317
288318constexpr static int wlRotate2dcc (int wlRotate) {
@@ -511,6 +541,13 @@ void DisplayWorker::setMonitorBrightness(Monitor *mon, const double brightness)
511541 auto *gammaConfig = m_wl_gammaConfig->value (mon);
512542 gammaConfig->brightness = brightness;
513543 gammaEffect->setConfiguration (*gammaConfig);
544+ #else
545+ for (auto it (m_control_monitors.cbegin ()); it != m_control_monitors.cend (); ++it) {
546+ if (it.key () == mon) {
547+ m_reg->treeLandOutputManager ()->setBrightness (it.value (), brightness * 100.0 );
548+ break ;
549+ }
550+ }
514551#endif
515552 } else {
516553 m_displayInter->SetAndSaveBrightness (mon->name (), std::max (brightness, m_model->minimumBrightnessScale ())).waitForFinished ();
@@ -544,7 +581,7 @@ void DisplayWorker::setMonitorPosition(QHash<Monitor *, QPair<int, int>> monitor
544581
545582void DisplayWorker::setUiScale (const double value)
546583{
547- qDebug ( ) << " set display scale:" << value;
584+ qCDebug (DdcDisplayWorker ) << " set display scale:" << value;
548585 double rv = value;
549586 if (rv < 0 )
550587 rv = m_model->uiScale ();
@@ -563,7 +600,7 @@ void DisplayWorker::setUiScale(const double value)
563600 cfgHead->setScale (rv);
564601 }
565602 opCfg->apply ();
566- connect (opCfg, &WQt::OutputConfiguration::succeeded, this , [ this , rv ]() {
603+ connect (opCfg, &WQt::OutputConfiguration::succeeded, this , [this , rv]() {
567604 m_model->setUIScale (rv);
568605 });
569606 } else {
@@ -876,10 +913,42 @@ void DisplayWorker::wlMonitorRemoved(WQt::OutputHead *head)
876913 head->deleteLater ();
877914
878915 m_wl_monitors.remove (monitor);
916+ if (m_control_monitors.contains (monitor)) {
917+ m_reg->treeLandOutputManager ()->destroyColorControl (m_control_monitors.value (monitor));
918+ m_control_monitors.remove (monitor);
919+ }
879920
880921 monitor->deleteLater ();
881922}
882923
924+ void DisplayWorker::wlOutputAdded (WQt::Output *output)
925+ {
926+ connect (output, &WQt::Output::done, this , &DisplayWorker::updateControl);
927+ }
928+
929+ void DisplayWorker::wlOutputRemoved (WQt::Output *output)
930+ {
931+ Q_UNUSED (output);
932+ // TODO:
933+ }
934+
935+ void DisplayWorker::updateControl ()
936+ {
937+ for (auto output : m_reg->waylandOutputs ()) {
938+ if (output->isReady ()) {
939+ for (auto it (m_wl_monitors.cbegin ()); it != m_wl_monitors.cend (); ++it) {
940+ if (it.key ()->name () == output->name ()) {
941+ if (!m_control_monitors.contains (it.key ())) {
942+ auto control = m_reg->treeLandOutputManager ()->getColorControl (output->get ());
943+ m_control_monitors.insert (it.key (), control);
944+ }
945+ break ;
946+ }
947+ }
948+ }
949+ }
950+ }
951+
883952void DisplayWorker::setAmbientLightAdjustBrightness (bool able)
884953{
885954 m_displayInter->setAmbientLightAdjustBrightness (able);
0 commit comments