KWaylandServer

dpms_interface.cpp
1 /*
2  SPDX-FileCopyrightText: 2015 Martin Gräßlin <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #include "display.h"
7 #include "dpms_interface_p.h"
8 #include "output_interface.h"
9 
10 namespace KWaylandServer
11 {
12 static const quint32 s_version = 1;
13 
14 DpmsManagerInterfacePrivate::DpmsManagerInterfacePrivate(DpmsManagerInterface *_q, Display *display)
15  : QtWaylandServer::org_kde_kwin_dpms_manager(*display, s_version)
16  , q(_q)
17 {
18 }
19 
20 void DpmsManagerInterfacePrivate::org_kde_kwin_dpms_manager_get(Resource *resource, uint32_t id, wl_resource *output)
21 {
22  OutputInterface *o = OutputInterface::get(output);
23 
24  wl_resource *dpms_resource = wl_resource_create(resource->client(), &org_kde_kwin_dpms_interface, resource->version(), id);
25  if (!dpms_resource) {
26  wl_client_post_no_memory(resource->client());
27  return;
28  }
29  auto dpms = new DpmsInterface(o, dpms_resource);
30 
31  dpms->sendSupported();
32  dpms->sendMode();
33  dpms->sendDone();
34 }
35 
36 DpmsManagerInterface::DpmsManagerInterface(Display *display, QObject *parent)
37  : QObject(parent)
38  , d(new DpmsManagerInterfacePrivate(this, display))
39 {
40 }
41 
42 DpmsManagerInterface::~DpmsManagerInterface() = default;
43 
44 DpmsInterface::DpmsInterface(OutputInterface *output, wl_resource *resource)
45  : QObject()
46  , QtWaylandServer::org_kde_kwin_dpms(resource)
47  , output(output)
48 {
49  connect(output, &OutputInterface::dpmsSupportedChanged, this, [this] {
50  sendSupported();
51  sendDone();
52  });
53  connect(output, &OutputInterface::dpmsModeChanged, this, [this] {
54  sendMode();
55  sendDone();
56  });
57 }
58 
59 DpmsInterface::~DpmsInterface() = default;
60 
61 void DpmsInterface::org_kde_kwin_dpms_release(Resource *resource)
62 {
63  wl_resource_destroy(resource->handle);
64 }
65 
66 void DpmsInterface::org_kde_kwin_dpms_destroy_resource(Resource *resource)
67 {
68  Q_UNUSED(resource)
69  delete this;
70 }
71 
72 void DpmsInterface::org_kde_kwin_dpms_set(Resource *resource, uint32_t mode)
73 {
74  Q_UNUSED(resource)
75  OutputInterface::DpmsMode dpmsMode;
76  switch (mode) {
77  case ORG_KDE_KWIN_DPMS_MODE_ON:
78  dpmsMode = OutputInterface::DpmsMode::On;
79  break;
80  case ORG_KDE_KWIN_DPMS_MODE_STANDBY:
81  dpmsMode = OutputInterface::DpmsMode::Standby;
82  break;
83  case ORG_KDE_KWIN_DPMS_MODE_SUSPEND:
84  dpmsMode = OutputInterface::DpmsMode::Suspend;
85  break;
86  case ORG_KDE_KWIN_DPMS_MODE_OFF:
87  dpmsMode = OutputInterface::DpmsMode::Off;
88  break;
89  default:
90  return;
91  }
92  Q_EMIT output->dpmsModeRequested(dpmsMode);
93 }
94 
95 void DpmsInterface::sendSupported()
96 {
97  send_supported(output->isDpmsSupported() ? 1 : 0);
98 }
99 
100 void DpmsInterface::sendMode()
101 {
102  const auto mode = output->dpmsMode();
103  org_kde_kwin_dpms_mode wlMode;
104  switch (mode) {
105  case OutputInterface::DpmsMode::On:
106  wlMode = ORG_KDE_KWIN_DPMS_MODE_ON;
107  break;
108  case OutputInterface::DpmsMode::Standby:
109  wlMode = ORG_KDE_KWIN_DPMS_MODE_STANDBY;
110  break;
111  case OutputInterface::DpmsMode::Suspend:
112  wlMode = ORG_KDE_KWIN_DPMS_MODE_SUSPEND;
113  break;
114  case OutputInterface::DpmsMode::Off:
115  wlMode = ORG_KDE_KWIN_DPMS_MODE_OFF;
116  break;
117  default:
118  Q_UNREACHABLE();
119  }
120  send_mode(wlMode);
121 }
122 
123 void DpmsInterface::sendDone()
124 {
125  send_done();
126 }
127 
128 }
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 25 2021 23:08:43 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.