1515#include < QJsonObject>
1616#include < QJsonParseError>
1717
18+ PluginScaleManager::PluginScaleManager (QWaylandCompositor *compositor)
19+ : QWaylandCompositorExtensionTemplate(compositor)
20+ , m_compositor(compositor)
21+ {
22+ }
23+
24+ void PluginScaleManager::setPluginScale (const uint32_t &scale)
25+ {
26+ if (scale == m_scale)
27+ return ;
28+ m_scale = scale;
29+ if (!m_compositor)
30+ return ;
31+
32+ auto outputs = m_compositor->outputs ();
33+ std::for_each (outputs.begin (), outputs.end (), [this ](auto *output) {
34+ // 120 is base of fractional scale.
35+ output->setScaleFactor (std::ceil (m_scale / 120 ));
36+ });
37+
38+ Q_EMIT pluginScaleChanged (m_scale);
39+ }
40+
41+ uint32_t PluginScaleManager::pluginScale ()
42+ {
43+ return m_scale;
44+ }
45+
46+ void PluginScaleManager::initialize ()
47+ {
48+ QWaylandCompositorExtensionTemplate::initialize ();
49+ QWaylandCompositor *compositor = static_cast <QWaylandCompositor *>(extensionContainer ());
50+ Q_ASSERT (compositor);
51+
52+ init (compositor->display (), 1 );
53+ m_compositor = compositor;
54+ connect (compositor, &QWaylandCompositor::outputAdded, this , [this ](auto *output) {
55+ output->setScaleFactor (std::ceil (m_scale / 120 ));
56+ });
57+ }
58+
59+ void PluginScaleManager::wp_fractional_scale_manager_v1_get_fractional_scale (Resource *resource, uint32_t id, struct ::wl_resource *surface)
60+ {
61+ QWaylandSurface *qwaylandSurface = QWaylandSurface::fromResource (surface);
62+ QWaylandResource shellSurfaceResource (
63+ wl_resource_create (resource->client (), &::wp_fractional_scale_v1_interface, wl_resource_get_version (resource->handle ), id));
64+ auto pluginScale = new PluginScale (this , qwaylandSurface, shellSurfaceResource);
65+ pluginScale->send_preferred_scale (m_scale);
66+ }
67+
68+ PluginScale::PluginScale (PluginScaleManager *manager, QWaylandSurface *surface, const QWaylandResource &resource)
69+ {
70+ setParent (manager);
71+ init (resource.resource ());
72+ setExtensionContainer (surface);
73+ QWaylandCompositorExtension::initialize ();
74+
75+ connect (manager, &PluginScaleManager::pluginScaleChanged, this , [this ](uint32_t scale) {
76+ send_preferred_scale (scale);
77+ });
78+ }
79+
80+ void PluginScale::wp_fractional_scale_v1_destroy (Resource *resource)
81+ {
82+ Q_UNUSED (resource)
83+ deleteLater ();
84+ }
85+
1886PluginSurface::PluginSurface (PluginManager* manager, const QString& pluginId, const QString& itemKey, const QString &displayName, int pluginFlags, int pluginType, int sizePolicy, QWaylandSurface *surface, const QWaylandResource &resource)
1987 : m_manager(manager)
2088 , m_surface(surface)
@@ -29,8 +97,6 @@ PluginSurface::PluginSurface(PluginManager* manager, const QString& pluginId, co
2997 init (resource.resource ());
3098 setExtensionContainer (surface);
3199 QWaylandCompositorExtension::initialize ();
32-
33- connect (surface, &QWaylandSurface::bufferSizeChanged, this , &PluginSurface::sizeChanged);
34100}
35101
36102QWaylandQuickShellIntegration* PluginSurface::createIntegration (QWaylandQuickShellSurfaceItem *item)
@@ -73,9 +139,14 @@ uint32_t PluginSurface::pluginSizePolicy () const
73139 return m_sizePolicy;
74140}
75141
76- QSize PluginSurface::pluginSize () const
142+ int PluginSurface::height () const
77143{
78- return m_surface->bufferSize () / qApp->devicePixelRatio ();
144+ return m_height;
145+ }
146+
147+ int PluginSurface::width () const
148+ {
149+ return m_width;
79150}
80151
81152QString PluginSurface::dccIcon () const
@@ -151,6 +222,23 @@ void PluginSurface::setGlobalPos(const QPoint &pos)
151222 send_raw_global_pos (p.x (), p.y ());
152223}
153224
225+ void PluginSurface::plugin_source_size (Resource *resource, int32_t width, int32_t height)
226+ {
227+ Q_UNUSED (resource);
228+ if (width == 0 || height == 0 )
229+ return ;
230+
231+ if (height != m_height) {
232+ m_height = height;
233+ Q_EMIT heightChanged ();
234+ }
235+
236+ if (width != m_width) {
237+ m_width = width;
238+ Q_EMIT widthChanged ();
239+ }
240+ }
241+
154242PluginPopup::PluginPopup (PluginManager* manager, const QString &pluginId, const QString &itemKey, int x, int y, int popupType, QWaylandSurface *surface, const QWaylandResource &resource)
155243 : m_manager(manager)
156244 , m_surface(surface)
@@ -215,6 +303,16 @@ void PluginPopup::setY(int32_t y)
215303 Q_EMIT yChanged ();
216304}
217305
306+ int PluginPopup::height () const
307+ {
308+ return m_height;
309+ }
310+
311+ int PluginPopup::width () const
312+ {
313+ return m_width;
314+ }
315+
218316int32_t PluginPopup::popupType () const
219317{
220318 return m_popupType;
@@ -238,6 +336,24 @@ void PluginPopup::plugin_popup_destroy(Resource *resource)
238336{
239337 wl_resource_destroy (resource->handle );
240338}
339+
340+ void PluginPopup::plugin_popup_source_size (Resource *resource, int32_t width, int32_t height)
341+ {
342+ Q_UNUSED (resource);
343+ if (width == 0 || height == 0 )
344+ return ;
345+
346+ if (height != m_height) {
347+ m_height = height;
348+ Q_EMIT heightChanged ();
349+ }
350+
351+ if (width != m_width) {
352+ m_width = width;
353+ Q_EMIT widthChanged ();
354+ }
355+ }
356+
241357PluginManager::PluginManager (QWaylandCompositor *compositor)
242358 : QWaylandCompositorExtensionTemplate(compositor)
243359{
0 commit comments