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 
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 #if KWAYLANDCLIENT_BUILD_DEPRECATED_SINCE(5, 50)
149 void OutputConfiguration::setScale(OutputDevice *outputdevice, qint32 scale)
150 {
151  setScaleF(outputdevice, scale);
152 }
153 #endif
154 
155 void OutputConfiguration::setScaleF(OutputDevice *outputdevice, qreal scale)
156 {
157  org_kde_kwin_outputdevice *od = outputdevice->output();
158  if (wl_proxy_get_version(d->outputconfiguration) < ORG_KDE_KWIN_OUTPUTCONFIGURATION_SCALEF_SINCE_VERSION) {
159  org_kde_kwin_outputconfiguration_scale(d->outputconfiguration, od, qRound(scale));
160  } else {
161  org_kde_kwin_outputconfiguration_scalef(d->outputconfiguration, od, wl_fixed_from_double(scale));
162  }
163 }
164 
165 void OutputConfiguration::setColorCurves(OutputDevice *outputdevice, QVector<quint16> red, QVector<quint16> green, QVector<quint16> blue)
166 {
167  org_kde_kwin_outputdevice *od = outputdevice->output();
168 
169  wl_array wlRed;
170  wl_array wlGreen;
171  wl_array 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::setOverscan(OutputDevice *outputdevice, uint32_t overscan)
191 {
192  org_kde_kwin_outputdevice *od = outputdevice->output();
193  if (wl_proxy_get_version(d->outputconfiguration) >= ORG_KDE_KWIN_OUTPUTCONFIGURATION_OVERSCAN_SINCE_VERSION) {
194  org_kde_kwin_outputconfiguration_overscan(d->outputconfiguration, od, overscan);
195  }
196 }
197 
198 void OutputConfiguration::setVrrPolicy(OutputDevice *outputdevice, OutputDevice::VrrPolicy policy)
199 {
200  if (wl_proxy_get_version(d->outputconfiguration) >= ORG_KDE_KWIN_OUTPUTCONFIGURATION_SET_VRR_POLICY_SINCE_VERSION) {
201  org_kde_kwin_outputdevice *od = outputdevice->output();
202  org_kde_kwin_outputconfiguration_set_vrr_policy(d->outputconfiguration, od, static_cast<uint32_t>(policy));
203  }
204 }
205 
206 void OutputConfiguration::apply()
207 {
208  org_kde_kwin_outputconfiguration_apply(d->outputconfiguration);
209 }
210 
211 // Callbacks
212 org_kde_kwin_outputconfiguration_listener OutputConfiguration::Private::s_outputconfigurationListener = {appliedCallback, failedCallback};
213 
214 void OutputConfiguration::Private::appliedCallback(void *data, org_kde_kwin_outputconfiguration *config)
215 {
216  Q_UNUSED(config);
217  auto o = reinterpret_cast<OutputConfiguration::Private *>(data);
218  Q_EMIT o->q->applied();
219 }
220 
221 void OutputConfiguration::Private::failedCallback(void *data, org_kde_kwin_outputconfiguration *config)
222 {
223  Q_UNUSED(config);
224  auto o = reinterpret_cast<OutputConfiguration::Private *>(data);
225  Q_EMIT o->q->failed();
226 }
227 
228 }
229 }
virtual void release(quint64 objid)
Wrapper for the org_kde_kwin_outputdevice interface.
Definition: outputdevice.h:57
int x() const const
int y() const const
T * data()
Wrapper class for wl_event_queue interface.
Definition: event_queue.h:54
Q_SCRIPTABLE Q_NOREPLY void abort()
int size() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Feb 8 2023 03:59:21 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.