KWin
Loading...
Searching...
No Matches
outputdevice_v2.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
3 SPDX-FileCopyrightText: 2021 Méven Car <meven.car@enioka.com>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7#include "outputdevice_v2.h"
8
9#include "display.h"
10#include "display_p.h"
11#include "utils/common.h"
12#include "utils/resource.h"
13
14#include "core/output.h"
15
16#include <QDebug>
17#include <QPointer>
18#include <QString>
19
20#include "qwayland-server-kde-output-device-v2.h"
21
22namespace KWin
23{
24
25static const quint32 s_version = 6;
26
27static QtWaylandServer::kde_output_device_v2::transform kwinTransformToOutputDeviceTransform(OutputTransform transform)
28{
29 return static_cast<QtWaylandServer::kde_output_device_v2::transform>(transform.kind());
30}
31
32static QtWaylandServer::kde_output_device_v2::subpixel kwinSubPixelToOutputDeviceSubPixel(Output::SubPixel subPixel)
33{
34 return static_cast<QtWaylandServer::kde_output_device_v2::subpixel>(subPixel);
35}
36
37static uint32_t kwinCapabilitiesToOutputDeviceCapabilities(Output::Capabilities caps)
38{
39 uint32_t ret = 0;
41 ret |= QtWaylandServer::kde_output_device_v2::capability_overscan;
42 }
43 if (caps & Output::Capability::Vrr) {
44 ret |= QtWaylandServer::kde_output_device_v2::capability_vrr;
45 }
47 ret |= QtWaylandServer::kde_output_device_v2::capability_rgb_range;
48 }
50 ret |= QtWaylandServer::kde_output_device_v2::capability_high_dynamic_range;
51 }
53 ret |= QtWaylandServer::kde_output_device_v2::capability_wide_color_gamut;
54 }
56 ret |= QtWaylandServer::kde_output_device_v2::capability_auto_rotate;
57 }
59 ret |= QtWaylandServer::kde_output_device_v2::capability_icc_profile;
60 }
61 return ret;
62}
63
64static QtWaylandServer::kde_output_device_v2::vrr_policy kwinVrrPolicyToOutputDeviceVrrPolicy(VrrPolicy policy)
65{
66 return static_cast<QtWaylandServer::kde_output_device_v2::vrr_policy>(policy);
67}
68
69static QtWaylandServer::kde_output_device_v2::rgb_range kwinRgbRangeToOutputDeviceRgbRange(Output::RgbRange range)
70{
71 return static_cast<QtWaylandServer::kde_output_device_v2::rgb_range>(range);
72}
73
74static QtWaylandServer::kde_output_device_v2::auto_rotate_policy kwinAutoRotationToOutputDeviceAutoRotation(Output::AutoRotationPolicy policy)
75{
76 return static_cast<QtWaylandServer::kde_output_device_v2::auto_rotate_policy>(policy);
77}
78
79class OutputDeviceV2InterfacePrivate : public QtWaylandServer::kde_output_device_v2
80{
81public:
84
85 void sendGeometry(Resource *resource);
86 wl_resource *sendNewMode(Resource *resource, OutputDeviceModeV2Interface *mode);
87 void sendCurrentMode(Resource *resource);
88 void sendDone(Resource *resource);
89 void sendUuid(Resource *resource);
90 void sendEdid(Resource *resource);
91 void sendEnabled(Resource *resource);
92 void sendScale(Resource *resource);
93 void sendEisaId(Resource *resource);
94 void sendName(Resource *resource);
95 void sendSerialNumber(Resource *resource);
96 void sendCapabilities(Resource *resource);
97 void sendOverscan(Resource *resource);
98 void sendVrrPolicy(Resource *resource);
99 void sendRgbRange(Resource *resource);
100 void sendHighDynamicRange(Resource *resource);
101 void sendSdrBrightness(Resource *resource);
102 void sendWideColorGamut(Resource *resource);
103 void sendAutoRotationPolicy(Resource *resource);
104 void sendIccProfilePath(Resource *resource);
105 void sendBrightnessMetadata(Resource *resource);
106 void sendBrightnessOverrides(Resource *resource);
107 void sendSdrGamutWideness(Resource *resource);
108
110 QPointer<Display> m_display;
114 QString m_manufacturer = QStringLiteral("org.kde.kwin");
115 QString m_model = QStringLiteral("none");
116 qreal m_scale = 1.0;
118 QString m_eisaId;
119 QString m_name;
120 subpixel m_subPixel = subpixel_unknown;
121 transform m_transform = transform_normal;
122 QList<OutputDeviceModeV2Interface *> m_modes;
124 QByteArray m_edid;
125 bool m_enabled = true;
126 QUuid m_uuid;
127 uint32_t m_capabilities = 0;
128 uint32_t m_overscan = 0;
129 vrr_policy m_vrrPolicy = vrr_policy_automatic;
130 rgb_range m_rgbRange = rgb_range_automatic;
131 bool m_highDynamicRange = false;
132 uint32_t m_sdrBrightness = 200;
133 bool m_wideColorGamut = false;
134 auto_rotate_policy m_autoRotation = auto_rotate_policy::auto_rotate_policy_in_tablet_mode;
136 std::optional<double> m_maxPeakBrightness;
137 std::optional<double> m_maxAverageBrightness;
138 double m_minBrightness = 0;
140 std::optional<double> m_maxPeakBrightnessOverride;
141 std::optional<double> m_maxAverageBrightnessOverride;
142 std::optional<double> m_minBrightnessOverride;
143
144protected:
145 void kde_output_device_v2_bind_resource(Resource *resource) override;
147};
148
149class OutputDeviceModeV2InterfacePrivate : public QtWaylandServer::kde_output_device_mode_v2
150{
151public:
152 struct ModeResource : Resource
153 {
154 OutputDeviceV2InterfacePrivate::Resource *output;
155 };
156
157 OutputDeviceModeV2InterfacePrivate(OutputDeviceModeV2Interface *q, std::shared_ptr<OutputMode> handle);
159
160 Resource *createResource(OutputDeviceV2InterfacePrivate::Resource *output);
161 Resource *findResource(OutputDeviceV2InterfacePrivate::Resource *output) const;
162
163 void bindResource(wl_resource *resource);
164
166 {
167 return mode->d.get();
168 }
169
171 std::weak_ptr<OutputMode> m_handle;
172 QSize m_size;
173 int m_refreshRate = 60000;
174 bool m_preferred = false;
175
176protected:
177 Resource *kde_output_device_mode_v2_allocate() override;
178};
179
181 : QtWaylandServer::kde_output_device_v2(*display, s_version)
182 , q(q)
183 , m_display(display)
184 , m_handle(handle)
185{
186 DisplayPrivate *displayPrivate = DisplayPrivate::get(display);
187 displayPrivate->outputdevicesV2.append(q);
188}
189
191{
192 if (m_display) {
194 displayPrivate->outputdevicesV2.removeOne(q);
195 }
196}
197
199 : QObject(parent)
200 , d(new OutputDeviceV2InterfacePrivate(this, display, handle))
201{
202 updateEnabled();
203 updateManufacturer();
204 updateEdid();
205 updateUuid();
206 updateModel();
207 updatePhysicalSize();
208 updateGlobalPosition();
209 updateScale();
210 updateTransform();
211 updateEisaId();
212 updateSerialNumber();
213 updateSubPixel();
214 updateOverscan();
215 updateCapabilities();
216 updateVrrPolicy();
217 updateRgbRange();
218 updateName();
219 updateModes();
220 updateHighDynamicRange();
221 updateSdrBrightness();
222 updateWideColorGamut();
223 updateAutoRotate();
224 updateIccProfilePath();
225 updateBrightnessMetadata();
226 updateBrightnessOverrides();
227 updateSdrGamutWideness();
228
230 this, &OutputDeviceV2Interface::updateGlobalPosition);
232 this, &OutputDeviceV2Interface::updateScale);
234 this, &OutputDeviceV2Interface::updateEnabled);
236 this, &OutputDeviceV2Interface::updateTransform);
238 this, &OutputDeviceV2Interface::updateCurrentMode);
240 this, &OutputDeviceV2Interface::updateCapabilities);
242 this, &OutputDeviceV2Interface::updateOverscan);
244 this, &OutputDeviceV2Interface::updateVrrPolicy);
246 this, &OutputDeviceV2Interface::updateModes);
248 this, &OutputDeviceV2Interface::updateRgbRange);
249 connect(handle, &Output::highDynamicRangeChanged, this, &OutputDeviceV2Interface::updateHighDynamicRange);
250 connect(handle, &Output::sdrBrightnessChanged, this, &OutputDeviceV2Interface::updateSdrBrightness);
251 connect(handle, &Output::wideColorGamutChanged, this, &OutputDeviceV2Interface::updateWideColorGamut);
252 connect(handle, &Output::autoRotationPolicyChanged, this, &OutputDeviceV2Interface::updateAutoRotate);
253 connect(handle, &Output::iccProfileChanged, this, &OutputDeviceV2Interface::updateIccProfilePath);
254 connect(handle, &Output::brightnessMetadataChanged, this, &OutputDeviceV2Interface::updateBrightnessMetadata);
255 connect(handle, &Output::brightnessMetadataChanged, this, &OutputDeviceV2Interface::updateBrightnessOverrides);
256 connect(handle, &Output::sdrGamutWidenessChanged, this, &OutputDeviceV2Interface::updateSdrGamutWideness);
257}
258
260{
261 d->globalRemove();
262}
263
265{
266 if (d->isGlobalRemoved()) {
267 return;
268 }
269
270 if (d->m_display) {
271 DisplayPrivate *displayPrivate = DisplayPrivate::get(d->m_display);
272 displayPrivate->outputdevicesV2.removeOne(this);
273 }
274
275 d->globalRemove();
276}
277
279{
280 return d->m_handle;
281}
282
287
289{
290 sendGeometry(resource);
291 sendScale(resource);
292 sendEisaId(resource);
293 sendName(resource);
294 sendSerialNumber(resource);
295
296 for (OutputDeviceModeV2Interface *mode : std::as_const(m_modes)) {
297 sendNewMode(resource, mode);
298 }
299 sendCurrentMode(resource);
300 sendUuid(resource);
301 sendEdid(resource);
302 sendEnabled(resource);
303 sendCapabilities(resource);
304 sendOverscan(resource);
305 sendVrrPolicy(resource);
306 sendRgbRange(resource);
307 sendHighDynamicRange(resource);
308 sendSdrBrightness(resource);
309 sendWideColorGamut(resource);
310 sendAutoRotationPolicy(resource);
311 sendIccProfilePath(resource);
312 sendBrightnessMetadata(resource);
313 sendBrightnessOverrides(resource);
314 sendSdrGamutWideness(resource);
315 sendDone(resource);
316}
317
319{
320 auto privateMode = OutputDeviceModeV2InterfacePrivate::get(mode);
321 // bind mode to client
322 const auto modeResource = privateMode->createResource(resource);
323
324 send_mode(resource->handle, modeResource->handle);
325
326 privateMode->bindResource(modeResource->handle);
327
328 return modeResource->handle;
329}
330
332{
333 const auto modeResource = OutputDeviceModeV2InterfacePrivate::get(m_currentMode)->findResource(outputResource);
334 send_current_mode(outputResource->handle, modeResource->handle);
335}
336
338{
339 send_geometry(resource->handle,
342 m_physicalSize.width(),
343 m_physicalSize.height(),
346 m_model,
348}
349
351{
352 send_scale(resource->handle, wl_fixed_from_double(m_scale));
353}
354
356{
357 send_serial_number(resource->handle, m_serialNumber);
358}
359
361{
362 send_eisa_id(resource->handle, m_eisaId);
363}
364
366{
367 if (resource->version() >= KDE_OUTPUT_DEVICE_V2_NAME_SINCE_VERSION) {
368 send_name(resource->handle, m_name);
369 }
370}
371
373{
374 send_done(resource->handle);
375}
376
378{
379 send_edid(resource->handle, QString::fromStdString(m_edid.toBase64().toStdString()));
380}
381
383{
384 send_enabled(resource->handle, m_enabled);
385}
386
388{
389 send_uuid(resource->handle, m_uuid.toString(QUuid::WithoutBraces));
390}
391
393{
394 send_capabilities(resource->handle, m_capabilities);
395}
396
398{
399 send_overscan(resource->handle, m_overscan);
400}
401
403{
404 send_vrr_policy(resource->handle, m_vrrPolicy);
405}
406
408{
409 send_rgb_range(resource->handle, m_rgbRange);
410}
411
413{
414 if (resource->version() >= KDE_OUTPUT_DEVICE_V2_HIGH_DYNAMIC_RANGE_SINCE_VERSION) {
415 send_high_dynamic_range(resource->handle, m_highDynamicRange ? 1 : 0);
416 }
417}
418
420{
421 if (resource->version() >= KDE_OUTPUT_DEVICE_V2_SDR_BRIGHTNESS_SINCE_VERSION) {
422 send_sdr_brightness(resource->handle, m_sdrBrightness);
423 }
424}
425
427{
428 if (resource->version() >= KDE_OUTPUT_DEVICE_V2_WIDE_COLOR_GAMUT_SINCE_VERSION) {
429 send_wide_color_gamut(resource->handle, m_wideColorGamut ? 1 : 0);
430 }
431}
432
434{
435 if (resource->version() >= KDE_OUTPUT_DEVICE_V2_AUTO_ROTATE_POLICY_SINCE_VERSION) {
436 send_auto_rotate_policy(resource->handle, m_autoRotation);
437 }
438}
439
441{
442 if (resource->version() >= KDE_OUTPUT_DEVICE_V2_ICC_PROFILE_PATH_SINCE_VERSION) {
443 send_icc_profile_path(resource->handle, m_iccProfilePath);
444 }
445}
446
448{
449 if (resource->version() >= KDE_OUTPUT_DEVICE_V2_BRIGHTNESS_METADATA_SINCE_VERSION) {
450 send_brightness_metadata(resource->handle, std::round(m_maxPeakBrightness.value_or(0)), std::round(m_maxAverageBrightness.value_or(0)), std::round(m_minBrightness * 10'000));
451 }
452}
453
455{
456 if (resource->version() >= KDE_OUTPUT_DEVICE_V2_BRIGHTNESS_OVERRIDES_SINCE_VERSION) {
457 send_brightness_overrides(resource->handle, std::round(m_maxPeakBrightnessOverride.value_or(-1)), std::round(m_maxAverageBrightnessOverride.value_or(-1)), std::round(m_minBrightnessOverride.value_or(-0.000'1) * 10'000));
458 }
459}
460
462{
463 if (resource->version() >= KDE_OUTPUT_DEVICE_V2_SDR_GAMUT_WIDENESS_SINCE_VERSION) {
464 send_sdr_gamut_wideness(resource->handle, std::clamp<uint32_t>(m_sdrGamutWideness * 10'000, 0, 10'000));
465 }
466}
467
468void OutputDeviceV2Interface::updateGeometry()
469{
470 const auto clientResources = d->resourceMap();
471 for (const auto &resource : clientResources) {
472 d->sendGeometry(resource);
473 d->sendDone(resource);
474 }
475}
476
477void OutputDeviceV2Interface::updatePhysicalSize()
478{
479 d->m_physicalSize = d->m_handle->physicalSize();
480}
481
482void OutputDeviceV2Interface::updateGlobalPosition()
483{
484 const QPoint arg = d->m_handle->geometry().topLeft();
485 if (d->m_globalPosition == arg) {
486 return;
487 }
488 d->m_globalPosition = arg;
489 updateGeometry();
490}
491
492void OutputDeviceV2Interface::updateManufacturer()
493{
494 d->m_manufacturer = d->m_handle->manufacturer();
495}
496
497void OutputDeviceV2Interface::updateModel()
498{
499 d->m_model = d->m_handle->model();
500}
501
502void OutputDeviceV2Interface::updateSerialNumber()
503{
504 d->m_serialNumber = d->m_handle->serialNumber();
505}
506
507void OutputDeviceV2Interface::updateEisaId()
508{
509 d->m_eisaId = d->m_handle->eisaId();
510}
511
512void OutputDeviceV2Interface::updateName()
513{
514 d->m_name = d->m_handle->name();
515}
516
517void OutputDeviceV2Interface::updateSubPixel()
518{
519 const auto arg = kwinSubPixelToOutputDeviceSubPixel(d->m_handle->subPixel());
520 if (d->m_subPixel != arg) {
521 d->m_subPixel = arg;
522 updateGeometry();
523 }
524}
525
526void OutputDeviceV2Interface::updateTransform()
527{
528 const auto arg = kwinTransformToOutputDeviceTransform(d->m_handle->transform());
529 if (d->m_transform != arg) {
530 d->m_transform = arg;
531 updateGeometry();
532 }
533}
534
535void OutputDeviceV2Interface::updateScale()
536{
537 const qreal scale = d->m_handle->scale();
538 if (qFuzzyCompare(d->m_scale, scale)) {
539 return;
540 }
541 d->m_scale = scale;
542 const auto clientResources = d->resourceMap();
543 for (const auto &resource : clientResources) {
544 d->sendScale(resource);
545 d->sendDone(resource);
546 }
547}
548
549void OutputDeviceV2Interface::updateModes()
550{
551 const auto oldModes = d->m_modes;
552 d->m_modes.clear();
553 d->m_currentMode = nullptr;
554
555 const auto clientResources = d->resourceMap();
556 const auto nativeModes = d->m_handle->modes();
557
558 for (const std::shared_ptr<OutputMode> &mode : nativeModes) {
559 OutputDeviceModeV2Interface *deviceMode = new OutputDeviceModeV2Interface(mode, this);
560 d->m_modes.append(deviceMode);
561
562 if (d->m_handle->currentMode() == mode) {
563 d->m_currentMode = deviceMode;
564 }
565
566 for (auto resource : clientResources) {
567 d->sendNewMode(resource, deviceMode);
568 }
569 }
570
571 for (auto resource : clientResources) {
572 d->sendCurrentMode(resource);
573 }
574
575 qDeleteAll(oldModes.crbegin(), oldModes.crend());
576
577 for (auto resource : clientResources) {
578 d->sendDone(resource);
579 }
580}
581
582void OutputDeviceV2Interface::updateCurrentMode()
583{
584 for (OutputDeviceModeV2Interface *mode : std::as_const(d->m_modes)) {
585 if (mode->handle().lock() == d->m_handle->currentMode()) {
586 if (d->m_currentMode != mode) {
587 d->m_currentMode = mode;
588 const auto clientResources = d->resourceMap();
589 for (auto resource : clientResources) {
590 d->sendCurrentMode(resource);
591 d->sendDone(resource);
592 }
593 updateGeometry();
594 }
595 return;
596 }
597 }
598}
599
600void OutputDeviceV2Interface::updateEdid()
601{
602 d->m_edid = d->m_handle->edid().raw();
603 const auto clientResources = d->resourceMap();
604 for (const auto &resource : clientResources) {
605 d->sendEdid(resource);
606 d->sendDone(resource);
607 }
608}
609
610void OutputDeviceV2Interface::updateEnabled()
611{
612 bool enabled = d->m_handle->isEnabled();
613 if (d->m_enabled != enabled) {
614 d->m_enabled = enabled;
615 const auto clientResources = d->resourceMap();
616 for (const auto &resource : clientResources) {
617 d->sendEnabled(resource);
618 d->sendDone(resource);
619 }
620 }
621}
622
623void OutputDeviceV2Interface::updateUuid()
624{
625 const QUuid uuid = d->m_handle->uuid();
626 if (d->m_uuid != uuid) {
627 d->m_uuid = uuid;
628 const auto clientResources = d->resourceMap();
629 for (const auto &resource : clientResources) {
630 d->sendUuid(resource);
631 d->sendDone(resource);
632 }
633 }
634}
635
636void OutputDeviceV2Interface::updateCapabilities()
637{
638 const uint32_t cap = kwinCapabilitiesToOutputDeviceCapabilities(d->m_handle->capabilities());
639 if (d->m_capabilities != cap) {
640 d->m_capabilities = cap;
641 const auto clientResources = d->resourceMap();
642 for (const auto &resource : clientResources) {
643 d->sendCapabilities(resource);
644 d->sendDone(resource);
645 }
646 }
647}
648
649void OutputDeviceV2Interface::updateOverscan()
650{
651 const uint32_t overscan = d->m_handle->overscan();
652 if (d->m_overscan != overscan) {
653 d->m_overscan = overscan;
654 const auto clientResources = d->resourceMap();
655 for (const auto &resource : clientResources) {
656 d->sendOverscan(resource);
657 d->sendDone(resource);
658 }
659 }
660}
661
662void OutputDeviceV2Interface::updateVrrPolicy()
663{
664 const auto policy = kwinVrrPolicyToOutputDeviceVrrPolicy(d->m_handle->vrrPolicy());
665 if (d->m_vrrPolicy != policy) {
666 d->m_vrrPolicy = policy;
667 const auto clientResources = d->resourceMap();
668 for (const auto &resource : clientResources) {
669 d->sendVrrPolicy(resource);
670 d->sendDone(resource);
671 }
672 }
673}
674
675void OutputDeviceV2Interface::updateRgbRange()
676{
677 const auto rgbRange = kwinRgbRangeToOutputDeviceRgbRange(d->m_handle->rgbRange());
678 if (d->m_rgbRange != rgbRange) {
679 d->m_rgbRange = rgbRange;
680 const auto clientResources = d->resourceMap();
681 for (const auto &resource : clientResources) {
682 d->sendRgbRange(resource);
683 d->sendDone(resource);
684 }
685 }
686}
687
688void OutputDeviceV2Interface::updateHighDynamicRange()
689{
690 if (d->m_highDynamicRange != d->m_handle->highDynamicRange()) {
691 d->m_highDynamicRange = d->m_handle->highDynamicRange();
692 const auto clientResources = d->resourceMap();
693 for (const auto &resource : clientResources) {
694 d->sendHighDynamicRange(resource);
695 d->sendDone(resource);
696 }
697 }
698}
699
700void OutputDeviceV2Interface::updateSdrBrightness()
701{
702 if (d->m_sdrBrightness != d->m_handle->sdrBrightness()) {
703 d->m_sdrBrightness = d->m_handle->sdrBrightness();
704 const auto clientResources = d->resourceMap();
705 for (const auto &resource : clientResources) {
706 d->sendSdrBrightness(resource);
707 d->sendDone(resource);
708 }
709 }
710}
711
712void OutputDeviceV2Interface::updateWideColorGamut()
713{
714 if (d->m_wideColorGamut != d->m_handle->wideColorGamut()) {
715 d->m_wideColorGamut = d->m_handle->wideColorGamut();
716 const auto clientResources = d->resourceMap();
717 for (const auto &resource : clientResources) {
718 d->sendWideColorGamut(resource);
719 d->sendDone(resource);
720 }
721 }
722}
723
724void OutputDeviceV2Interface::updateAutoRotate()
725{
726 const auto policy = kwinAutoRotationToOutputDeviceAutoRotation(d->m_handle->autoRotationPolicy());
727 if (d->m_autoRotation != policy) {
728 d->m_autoRotation = policy;
729 const auto clientResources = d->resourceMap();
730 for (const auto &resource : clientResources) {
731 d->sendAutoRotationPolicy(resource);
732 d->sendDone(resource);
733 }
734 }
735}
736
737void OutputDeviceV2Interface::updateIccProfilePath()
738{
739 if (d->m_iccProfilePath != d->m_handle->iccProfilePath()) {
740 d->m_iccProfilePath = d->m_handle->iccProfilePath();
741 const auto clientResources = d->resourceMap();
742 for (const auto &resource : clientResources) {
743 d->sendIccProfilePath(resource);
744 d->sendDone(resource);
745 }
746 }
747}
748
749void OutputDeviceV2Interface::updateBrightnessMetadata()
750{
751 if (d->m_maxPeakBrightness != d->m_handle->maxPeakBrightness() || d->m_maxAverageBrightness != d->m_handle->maxAverageBrightness() || d->m_minBrightness != d->m_handle->minBrightness()) {
752 d->m_maxPeakBrightness = d->m_handle->maxPeakBrightness();
753 d->m_maxAverageBrightness = d->m_handle->maxAverageBrightness();
754 d->m_minBrightness = d->m_handle->minBrightness();
755 const auto clientResources = d->resourceMap();
756 for (const auto &resource : clientResources) {
757 d->sendBrightnessMetadata(resource);
758 d->sendDone(resource);
759 }
760 }
761}
762
763void OutputDeviceV2Interface::updateBrightnessOverrides()
764{
765 if (d->m_maxPeakBrightnessOverride != d->m_handle->maxPeakBrightnessOverride() || d->m_maxAverageBrightnessOverride != d->m_handle->maxAverageBrightnessOverride() || d->m_minBrightnessOverride != d->m_handle->minBrightnessOverride()) {
766 d->m_maxPeakBrightnessOverride = d->m_handle->maxPeakBrightnessOverride();
767 d->m_maxAverageBrightnessOverride = d->m_handle->maxAverageBrightnessOverride();
768 d->m_minBrightnessOverride = d->m_handle->minBrightnessOverride();
769 const auto clientResources = d->resourceMap();
770 for (const auto &resource : clientResources) {
771 d->sendBrightnessOverrides(resource);
772 d->sendDone(resource);
773 }
774 }
775}
776
777void OutputDeviceV2Interface::updateSdrGamutWideness()
778{
779 if (d->m_sdrGamutWideness != d->m_handle->sdrGamutWideness()) {
780 d->m_sdrGamutWideness = d->m_handle->sdrGamutWideness();
781 const auto clientResources = d->resourceMap();
782 for (const auto &resource : clientResources) {
783 d->sendSdrGamutWideness(resource);
784 d->sendDone(resource);
785 }
786 }
787}
788
790{
791 if (auto devicePrivate = resource_cast<OutputDeviceV2InterfacePrivate *>(native); devicePrivate && !devicePrivate->isGlobalRemoved()) {
792 return devicePrivate->q;
793 }
794 return nullptr;
795}
796
798 : QtWaylandServer::kde_output_device_mode_v2()
799 , q(q)
800 , m_handle(handle)
801 , m_size(handle->size())
802 , m_refreshRate(handle->refreshRate())
803 , m_preferred(handle->flags() & OutputMode::Flag::Preferred)
804{
805}
806
807OutputDeviceModeV2Interface::OutputDeviceModeV2Interface(std::shared_ptr<OutputMode> handle, QObject *parent)
808 : QObject(parent)
809 , d(new OutputDeviceModeV2InterfacePrivate(this, handle))
810{
811}
812
814
816{
817 const auto map = resourceMap();
818 for (Resource *resource : map) {
819 send_removed(resource->handle);
820 }
821}
822
823OutputDeviceModeV2InterfacePrivate::Resource *OutputDeviceModeV2InterfacePrivate::createResource(OutputDeviceV2InterfacePrivate::Resource *output)
824{
825 const auto modeResource = static_cast<ModeResource *>(add(output->client(), output->version()));
826 modeResource->output = output;
827 return modeResource;
828}
829
830OutputDeviceModeV2InterfacePrivate::Resource *OutputDeviceModeV2InterfacePrivate::findResource(OutputDeviceV2InterfacePrivate::Resource *output) const
831{
832 const auto resources = resourceMap();
833 for (const auto &resource : resources) {
834 auto modeResource = static_cast<ModeResource *>(resource);
835 if (modeResource->output == output) {
836 return resource;
837 }
838 }
839 return nullptr;
840}
841
843{
844 return new ModeResource;
845}
846
847std::weak_ptr<OutputMode> OutputDeviceModeV2Interface::handle() const
848{
849 return d->m_handle;
850}
851
853{
854 send_size(resource, m_size.width(), m_size.height());
855 send_refresh(resource, m_refreshRate);
856
857 if (m_preferred) {
858 send_preferred(resource);
859 }
860}
861
863{
864 if (auto devicePrivate = resource_cast<OutputDeviceModeV2InterfacePrivate *>(native)) {
865 return devicePrivate->q;
866 }
867 return nullptr;
868}
869
870}
871
872#include "moc_outputdevice_v2.cpp"
Class holding the Wayland server display loop.
Definition display.h:34
static DisplayPrivate * get(Display *display)
Definition display.cpp:26
QList< OutputDeviceV2Interface * > outputdevicesV2
Definition display_p.h:41
OutputDeviceModeV2Interface(std::shared_ptr< OutputMode > handle, QObject *parent=nullptr)
std::weak_ptr< OutputMode > handle() const
static OutputDeviceModeV2Interface * get(wl_resource *native)
static OutputDeviceModeV2InterfacePrivate * get(OutputDeviceModeV2Interface *mode)
Resource * findResource(OutputDeviceV2InterfacePrivate::Resource *output) const
Resource * createResource(OutputDeviceV2InterfacePrivate::Resource *output)
Resource * kde_output_device_mode_v2_allocate() override
OutputDeviceModeV2InterfacePrivate(OutputDeviceModeV2Interface *q, std::shared_ptr< OutputMode > handle)
static OutputDeviceV2Interface * get(wl_resource *native)
OutputDeviceV2Interface(Display *display, Output *handle, QObject *parent=nullptr)
std::optional< double > m_minBrightnessOverride
void sendIccProfilePath(Resource *resource)
void sendHighDynamicRange(Resource *resource)
std::optional< double > m_maxPeakBrightness
void sendSerialNumber(Resource *resource)
void sendAutoRotationPolicy(Resource *resource)
void sendCurrentMode(Resource *resource)
OutputDeviceV2InterfacePrivate(OutputDeviceV2Interface *q, Display *display, Output *handle)
wl_resource * sendNewMode(Resource *resource, OutputDeviceModeV2Interface *mode)
std::optional< double > m_maxAverageBrightnessOverride
void kde_output_device_v2_bind_resource(Resource *resource) override
void sendBrightnessOverrides(Resource *resource)
void sendBrightnessMetadata(Resource *resource)
std::optional< double > m_maxAverageBrightness
void sendWideColorGamut(Resource *resource)
void sendSdrBrightness(Resource *resource)
std::optional< double > m_maxPeakBrightnessOverride
void sendCapabilities(Resource *resource)
OutputDeviceModeV2Interface * m_currentMode
void sendSdrGamutWideness(Resource *resource)
QList< OutputDeviceModeV2Interface * > m_modes
void enabledChanged()
void rgbRangeChanged()
void overscanChanged()
void currentModeChanged()
void highDynamicRangeChanged()
void geometryChanged()
void autoRotationPolicyChanged()
void sdrBrightnessChanged()
void scaleChanged()
void capabilitiesChanged()
void modesChanged()
void vrrPolicyChanged()
void iccProfileChanged()
void sdrGamutWidenessChanged()
void brightnessMetadataChanged()
void transformChanged()
void wideColorGamutChanged()
VrrPolicy
Definition globals.h:292
OutputDeviceV2InterfacePrivate::Resource * output