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

KDE's Doxygen guidelines are available online.