KWayland

outputconfiguration.cpp
1 /*
2  SPDX-FileCopyrightText: 2015 Sebastian Kügler <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #include "outputconfiguration.h"
7 #include "event_queue.h"
8 #include "outputmanagement.h"
9 #include "wayland_pointer_p.h"
10 
11 #include "wayland-org_kde_kwin_outputdevice-client-protocol.h"
12 #include "wayland-output-management-client-protocol.h"
13 
14 namespace KWayland
15 {
16 namespace Client
17 {
18 class Q_DECL_HIDDEN OutputConfiguration::Private
19 {
20 public:
21  Private() = default;
22 
23  void setup(org_kde_kwin_outputconfiguration *outputconfiguration);
24 
25  WaylandPointer<org_kde_kwin_outputconfiguration, org_kde_kwin_outputconfiguration_destroy> outputconfiguration;
26  static struct org_kde_kwin_outputconfiguration_listener s_outputconfigurationListener;
27  EventQueue *queue = nullptr;
28 
29  OutputConfiguration *q;
30 
31 private:
32  static void appliedCallback(void *data, org_kde_kwin_outputconfiguration *config);
33  static void failedCallback(void *data, org_kde_kwin_outputconfiguration *config);
34 };
35 
36 OutputConfiguration::OutputConfiguration(QObject *parent)
37  : QObject(parent)
38  , d(new Private)
39 {
40  d->q = this;
41 }
42 
43 OutputConfiguration::~OutputConfiguration()
44 {
45  release();
46 }
47 
48 void OutputConfiguration::setup(org_kde_kwin_outputconfiguration *outputconfiguration)
49 {
50  Q_ASSERT(outputconfiguration);
51  Q_ASSERT(!d->outputconfiguration);
52  d->outputconfiguration.setup(outputconfiguration);
53  d->setup(outputconfiguration);
54 }
55 
56 void OutputConfiguration::Private::setup(org_kde_kwin_outputconfiguration *outputconfiguration)
57 {
58  org_kde_kwin_outputconfiguration_add_listener(outputconfiguration, &s_outputconfigurationListener, this);
59 }
60 
61 void OutputConfiguration::release()
62 {
63  d->outputconfiguration.release();
64 }
65 
66 void OutputConfiguration::destroy()
67 {
68  d->outputconfiguration.destroy();
69 }
70 
71 void OutputConfiguration::setEventQueue(EventQueue *queue)
72 {
73  d->queue = queue;
74 }
75 
76 EventQueue *OutputConfiguration::eventQueue()
77 {
78  return d->queue;
79 }
80 
81 OutputConfiguration::operator org_kde_kwin_outputconfiguration *()
82 {
83  return d->outputconfiguration;
84 }
85 
86 OutputConfiguration::operator org_kde_kwin_outputconfiguration *() const
87 {
88  return d->outputconfiguration;
89 }
90 
91 bool OutputConfiguration::isValid() const
92 {
93  return d->outputconfiguration.isValid();
94 }
95 
96 // Requests
97 
98 void OutputConfiguration::setEnabled(OutputDevice *outputdevice, OutputDevice::Enablement enable)
99 {
100  qint32 _enable = ORG_KDE_KWIN_OUTPUTDEVICE_ENABLEMENT_DISABLED;
101  if (enable == OutputDevice::Enablement::Enabled) {
102  _enable = ORG_KDE_KWIN_OUTPUTDEVICE_ENABLEMENT_ENABLED;
103  }
104  org_kde_kwin_outputdevice *od = outputdevice->output();
105  org_kde_kwin_outputconfiguration_enable(d->outputconfiguration, od, _enable);
106 }
107 
108 void OutputConfiguration::setMode(OutputDevice *outputdevice, const int modeId)
109 {
110  org_kde_kwin_outputdevice *od = outputdevice->output();
111  org_kde_kwin_outputconfiguration_mode(d->outputconfiguration, od, modeId);
112 }
113 
114 void OutputConfiguration::setTransform(OutputDevice *outputdevice, KWayland::Client::OutputDevice::Transform transform)
115 {
116  auto toTransform = [transform]() {
117  switch (transform) {
119  case KWayland::Client::OutputDevice::Transform::Normal:
120  return WL_OUTPUT_TRANSFORM_NORMAL;
121  case KWayland::Client::OutputDevice::Transform::Rotated90:
122  return WL_OUTPUT_TRANSFORM_90;
123  case KWayland::Client::OutputDevice::Transform::Rotated180:
124  return WL_OUTPUT_TRANSFORM_180;
125  case KWayland::Client::OutputDevice::Transform::Rotated270:
126  return WL_OUTPUT_TRANSFORM_270;
127  case KWayland::Client::OutputDevice::Transform::Flipped:
128  return WL_OUTPUT_TRANSFORM_FLIPPED;
129  case KWayland::Client::OutputDevice::Transform::Flipped90:
130  return WL_OUTPUT_TRANSFORM_FLIPPED_90;
131  case KWayland::Client::OutputDevice::Transform::Flipped180:
132  return WL_OUTPUT_TRANSFORM_FLIPPED_180;
133  case KWayland::Client::OutputDevice::Transform::Flipped270:
134  return WL_OUTPUT_TRANSFORM_FLIPPED_270;
135  }
136  abort();
137  };
138  org_kde_kwin_outputdevice *od = outputdevice->output();
139  org_kde_kwin_outputconfiguration_transform(d->outputconfiguration, od, toTransform());
140 }
141 
142 void OutputConfiguration::setPosition(OutputDevice *outputdevice, const QPoint &pos)
143 {
144  org_kde_kwin_outputdevice *od = outputdevice->output();
145  org_kde_kwin_outputconfiguration_position(d->outputconfiguration, od, pos.x(), pos.y());
146 }
147 
148 void OutputConfiguration::setScale(OutputDevice *outputdevice, qint32 scale)
149 {
150  setScaleF(outputdevice, scale);
151 }
152 
153 void OutputConfiguration::setScaleF(OutputDevice *outputdevice, qreal scale)
154 {
155  org_kde_kwin_outputdevice *od = outputdevice->output();
156  if (wl_proxy_get_version(d->outputconfiguration) < ORG_KDE_KWIN_OUTPUTCONFIGURATION_SCALEF_SINCE_VERSION) {
157  org_kde_kwin_outputconfiguration_scale(d->outputconfiguration, od, qRound(scale));
158  } else {
159  org_kde_kwin_outputconfiguration_scalef(d->outputconfiguration, od, wl_fixed_from_double(scale));
160  }
161 }
162 
163 void OutputConfiguration::setColorCurves(OutputDevice *outputdevice, QVector<quint16> red, QVector<quint16> green, QVector<quint16> blue)
164 {
165  org_kde_kwin_outputdevice *od = outputdevice->output();
166 
167  wl_array wlRed, wlGreen, wlBlue;
168 
169  auto fillArray = [](QVector<quint16> &origin, wl_array *dest) {
170  wl_array_init(dest);
171  const size_t memLength = sizeof(uint16_t) * origin.size();
172  void *s = wl_array_add(dest, memLength);
173  memcpy(s, origin.data(), memLength);
174  };
175  fillArray(red, &wlRed);
176  fillArray(green, &wlGreen);
177  fillArray(blue, &wlBlue);
178 
179  org_kde_kwin_outputconfiguration_colorcurves(d->outputconfiguration, od, &wlRed, &wlGreen, &wlBlue);
180 
181  wl_array_release(&wlRed);
182  wl_array_release(&wlGreen);
183  wl_array_release(&wlBlue);
184 }
185 
186 void OutputConfiguration::setOverscan(OutputDevice *outputdevice, uint32_t overscan)
187 {
188  org_kde_kwin_outputdevice *od = outputdevice->output();
189  if (wl_proxy_get_version(d->outputconfiguration) >= ORG_KDE_KWIN_OUTPUTCONFIGURATION_OVERSCAN_SINCE_VERSION) {
190  org_kde_kwin_outputconfiguration_overscan(d->outputconfiguration, od, overscan);
191  }
192 }
193 
194 void OutputConfiguration::setVrrPolicy(OutputDevice *outputdevice, OutputDevice::VrrPolicy policy)
195 {
196  if (wl_proxy_get_version(d->outputconfiguration) >= ORG_KDE_KWIN_OUTPUTCONFIGURATION_SET_VRR_POLICY_SINCE_VERSION) {
197  org_kde_kwin_outputdevice *od = outputdevice->output();
198  org_kde_kwin_outputconfiguration_set_vrr_policy(d->outputconfiguration, od, static_cast<uint32_t>(policy));
199  }
200 }
201 
202 void OutputConfiguration::apply()
203 {
204  org_kde_kwin_outputconfiguration_apply(d->outputconfiguration);
205 }
206 
207 // Callbacks
208 org_kde_kwin_outputconfiguration_listener OutputConfiguration::Private::s_outputconfigurationListener = {appliedCallback, failedCallback};
209 
210 void OutputConfiguration::Private::appliedCallback(void *data, org_kde_kwin_outputconfiguration *config)
211 {
212  Q_UNUSED(config);
213  auto o = reinterpret_cast<OutputConfiguration::Private *>(data);
214  Q_EMIT o->q->applied();
215 }
216 
217 void OutputConfiguration::Private::failedCallback(void *data, org_kde_kwin_outputconfiguration *config)
218 {
219  Q_UNUSED(config);
220  auto o = reinterpret_cast<OutputConfiguration::Private *>(data);
221  Q_EMIT o->q->failed();
222 }
223 
224 }
225 }
OutputDeviceInterface::Transform transform() const
The new value for transform.
Wrapper class for wl_event_queue interface.
Definition: event_queue.h:54
int x() const const
int y() const const
T * data()
int scale() const
The new value for scale.
int size() const const
Wrapper for the org_kde_kwin_outputdevice interface.
Definition: outputdevice.h:57
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Aug 3 2021 22:50:47 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.