KWin
Loading...
Searching...
No Matches
dpms.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6#include "dpms.h"
7#include "display.h"
8#include "output.h"
9
10#include <QPointer>
11
12#include <qwayland-server-dpms.h>
13
14namespace KWin
15{
16
17static const quint32 s_version = 1;
18
19class DpmsManagerInterfacePrivate : public QtWaylandServer::org_kde_kwin_dpms_manager
20{
21public:
23
24protected:
25 void org_kde_kwin_dpms_manager_get(Resource *resource, uint32_t id, wl_resource *output) override;
26};
27
28class DpmsInterface : public QObject, QtWaylandServer::org_kde_kwin_dpms
29{
30 Q_OBJECT
31public:
32 explicit DpmsInterface(OutputInterface *output, wl_resource *resource);
33
34 void sendSupported();
35 void sendMode();
36 void sendDone();
37
38 QPointer<OutputInterface> m_output;
39
40protected:
41 void org_kde_kwin_dpms_destroy_resource(Resource *resource) override;
42 void org_kde_kwin_dpms_set(Resource *resource, uint32_t mode) override;
43 void org_kde_kwin_dpms_release(Resource *resource) override;
44};
45
47 : QtWaylandServer::org_kde_kwin_dpms_manager(*display, s_version)
48{
49}
50
51void DpmsManagerInterfacePrivate::org_kde_kwin_dpms_manager_get(Resource *resource, uint32_t id, wl_resource *output)
52{
54
55 wl_resource *dpms_resource = wl_resource_create(resource->client(), &org_kde_kwin_dpms_interface, resource->version(), id);
56 if (!dpms_resource) {
57 wl_client_post_no_memory(resource->client());
58 return;
59 }
60
61 new DpmsInterface(o, dpms_resource);
62}
63
65 : QObject(parent)
66 , d(new DpmsManagerInterfacePrivate(display))
67{
68}
69
71
72DpmsInterface::DpmsInterface(OutputInterface *output, wl_resource *resource)
73 : QObject()
74 , QtWaylandServer::org_kde_kwin_dpms(resource)
75 , m_output(output)
76{
77 if (!m_output || m_output->isRemoved()) {
78 return;
79 }
80
82 sendMode();
83 sendDone();
84
85 connect(m_output->handle(), &Output::capabilitiesChanged, this, [this]() {
86 sendSupported();
87 sendDone();
88 });
89 connect(m_output->handle(), &Output::dpmsModeChanged, this, [this]() {
90 sendMode();
91 sendDone();
92 });
93}
94
96{
97 wl_resource_destroy(resource->handle);
98}
99
101{
102 delete this;
103}
104
105void DpmsInterface::org_kde_kwin_dpms_set(Resource *resource, uint32_t mode)
106{
107 if (!m_output || m_output->isRemoved()) {
108 return;
109 }
110
111 Output::DpmsMode dpmsMode;
112 switch (mode) {
113 case ORG_KDE_KWIN_DPMS_MODE_ON:
114 dpmsMode = Output::DpmsMode::On;
115 break;
116 case ORG_KDE_KWIN_DPMS_MODE_STANDBY:
117 dpmsMode = Output::DpmsMode::Standby;
118 break;
119 case ORG_KDE_KWIN_DPMS_MODE_SUSPEND:
120 dpmsMode = Output::DpmsMode::Suspend;
121 break;
122 case ORG_KDE_KWIN_DPMS_MODE_OFF:
123 dpmsMode = Output::DpmsMode::Off;
124 break;
125 default:
126 return;
127 }
128
129 m_output->handle()->setDpmsMode(dpmsMode);
130}
131
133{
134 if (!m_output || m_output->isRemoved()) {
135 return;
136 }
137
138 send_supported(m_output->handle()->capabilities() & Output::Capability::Dpms ? 1 : 0);
139}
140
142{
143 if (!m_output || m_output->isRemoved()) {
144 return;
145 }
146
147 const auto mode = m_output->handle()->dpmsMode();
148 org_kde_kwin_dpms_mode wlMode;
149 switch (mode) {
151 wlMode = ORG_KDE_KWIN_DPMS_MODE_ON;
152 break;
154 wlMode = ORG_KDE_KWIN_DPMS_MODE_STANDBY;
155 break;
157 wlMode = ORG_KDE_KWIN_DPMS_MODE_SUSPEND;
158 break;
160 wlMode = ORG_KDE_KWIN_DPMS_MODE_OFF;
161 break;
162 default:
163 Q_UNREACHABLE();
164 }
165 send_mode(wlMode);
166}
167
169{
170 send_done();
171}
172
173}
174
175#include "dpms.moc"
176
177#include "moc_dpms.cpp"
Class holding the Wayland server display loop.
Definition display.h:34
DpmsInterface(OutputInterface *output, wl_resource *resource)
Definition dpms.cpp:72
QPointer< OutputInterface > m_output
Definition dpms.cpp:38
void sendSupported()
Definition dpms.cpp:132
void org_kde_kwin_dpms_release(Resource *resource) override
Definition dpms.cpp:95
void org_kde_kwin_dpms_destroy_resource(Resource *resource) override
Definition dpms.cpp:100
void org_kde_kwin_dpms_set(Resource *resource, uint32_t mode) override
Definition dpms.cpp:105
DpmsManagerInterface(Display *display, QObject *parent=nullptr)
Definition dpms.cpp:64
void org_kde_kwin_dpms_manager_get(Resource *resource, uint32_t id, wl_resource *output) override
Definition dpms.cpp:51
DpmsManagerInterfacePrivate(Display *d)
Definition dpms.cpp:46
void capabilitiesChanged()
void dpmsModeChanged()
static OutputInterface * get(wl_resource *native)
Definition output.cpp:320