Skip to content

Commit 8d3a85a

Browse files
committed
fix: popup scaling incorrectly
Set plugin scaling via fractional scaling protocol instead of QT environment variables log: as title
1 parent 1042d74 commit 8d3a85a

File tree

10 files changed

+237
-17
lines changed

10 files changed

+237
-17
lines changed

panels/dock/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ qt_add_qml_module(dock-plugin
143143
qt_generate_wayland_protocol_server_sources(dock-plugin
144144
FILES
145145
${DDE_TRAY_LOADER_PROTOCOL}
146+
${WaylandProtocols_DATADIR}/staging/fractional-scale/fractional-scale-v1.xml
146147
)
147148

148149
target_link_libraries(dock-plugin PUBLIC

panels/dock/DockCompositor.qml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Item {
2424
property ListModel fixedPluginSurfaces: ListModel {}
2525

2626
property var compositor: waylandCompositor
27+
property var panelScale: 1.0
2728

2829
signal pluginSurfacesUpdated()
2930
signal popupCreated(var popup)
@@ -107,5 +108,14 @@ Item {
107108
dockCompositor.requestShutdown()
108109
}
109110
}
111+
112+
PluginScaleManager{
113+
id: pluginScaleManager
114+
pluginScale: dockCompositor.panelScale * 120
115+
116+
Component.onCompleted: {
117+
pluginScaleManager.setCompositor(waylandCompositor)
118+
}
119+
}
110120
}
111121
}

panels/dock/dockpanel.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ bool DockPanel::init()
137137
else {
138138
m_dockScreen = window()->screen();
139139
}
140+
rootObject()->installEventFilter(this);
141+
Q_EMIT devicePixelRatioChanged(window()->devicePixelRatio());
140142
}
141143
});
142144

@@ -391,6 +393,22 @@ QString DockPanel::screenName() const
391393
return {};
392394
return m_dockScreen->name();
393395
}
396+
397+
qreal DockPanel::devicePixelRatio() const
398+
{
399+
if (!window())
400+
return 1.0;
401+
return window()->devicePixelRatio();
402+
}
403+
404+
bool DockPanel::eventFilter(QObject *watched, QEvent *event)
405+
{
406+
if (watched == window() && event->type() == QEvent::DevicePixelRatioChange) {
407+
Q_EMIT devicePixelRatioChanged(window()->devicePixelRatio());
408+
}
409+
410+
return false;
411+
}
394412
}
395413

396414
#include "dockpanel.moc"

panels/dock/dockpanel.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class DockPanel : public DS_NAMESPACE::DPanel, public QDBusContext
3333
Q_PROPERTY(bool showInPrimary READ showInPrimary WRITE setShowInPrimary NOTIFY showInPrimaryChanged FINAL)
3434
Q_PROPERTY(QString screenName READ screenName NOTIFY screenNameChanged FINAL)
3535

36+
Q_PROPERTY(qreal devicePixelRatio READ devicePixelRatio NOTIFY devicePixelRatioChanged FINAL)
37+
3638
Q_PROPERTY(bool debugMode READ debugMode FINAL CONSTANT)
3739

3840
public:
@@ -82,6 +84,11 @@ class DockPanel : public DS_NAMESPACE::DPanel, public QDBusContext
8284
void setDockScreen(QScreen *screen);
8385
QString screenName() const;
8486

87+
qreal devicePixelRatio() const;
88+
89+
protected:
90+
bool eventFilter(QObject *watched, QEvent *event) override;
91+
8592
private Q_SLOTS:
8693
void onWindowGeometryChanged();
8794
void launcherVisibleChanged(bool visible);
@@ -103,6 +110,7 @@ private Q_SLOTS:
103110
void dockScreenChanged(QScreen *screen);
104111
void screenNameChanged();
105112
void requestClosePopup();
113+
void devicePixelRatioChanged(qreal ratio);
106114

107115
private:
108116
ColorTheme m_theme;

panels/dock/loadtrayplugins.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,6 @@ void LoadTrayPlugins::setProcessEnv(QProcess *process)
118118
if (!process) return;
119119

120120
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
121-
env.insert("QT_SCALE_FACTOR", QString::number(qApp->devicePixelRatio()));
122-
env.insert("D_DXCB_DISABLE_OVERRIDE_HIDPI", "1");
123-
124121
// TODO: use protocols to determine the environment instead of environment variables
125122
env.remove("DDE_CURRENT_COMPOSITOR");
126123

panels/dock/package/main.qml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,10 @@ Window {
552552
return Qt.size(Panel.frontendWindowRect.width, Panel.frontendWindowRect.height)
553553
})
554554

555+
DockCompositor.panelScale = Qt.binding(function(){
556+
return Panel.devicePixelRatio
557+
})
558+
555559
dock.itemIconSizeBase = dock.dockItemMaxSize
556560
dock.visible = Panel.hideState !== Dock.Hide
557561
changeDragAreaAnchor()

panels/dock/pluginmanagerextension.cpp

Lines changed: 134 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,88 @@
1515
#include <QJsonObject>
1616
#include <QJsonParseError>
1717

18+
PluginScaleManager::PluginScaleManager(QWaylandCompositor *compositor)
19+
: QWaylandCompositorExtensionTemplate(compositor)
20+
, m_compositor(compositor)
21+
{
22+
if (m_compositor) {
23+
connect(m_compositor, &QWaylandCompositor::outputAdded, this, [this](auto *output) {
24+
output->setScaleFactor(std::ceil(m_scale / 120));
25+
});
26+
}
27+
}
28+
29+
void PluginScaleManager::setPluginScale(const uint32_t &scale)
30+
{
31+
if (scale == m_scale)
32+
return;
33+
m_scale = scale;
34+
if (!m_compositor)
35+
return;
36+
37+
auto outputs = m_compositor->outputs();
38+
std::for_each(outputs.begin(), outputs.end(), [this](auto *output) {
39+
// 120 is base of fractional scale.
40+
output->setScaleFactor(std::ceil(m_scale / 120));
41+
});
42+
43+
Q_EMIT pluginScaleChanged(m_scale);
44+
}
45+
46+
uint32_t PluginScaleManager::pluginScale()
47+
{
48+
return m_scale;
49+
}
50+
51+
void PluginScaleManager::initialize()
52+
{
53+
QWaylandCompositorExtensionTemplate::initialize();
54+
QWaylandCompositor *compositor = static_cast<QWaylandCompositor *>(extensionContainer());
55+
init(compositor->display(), 1);
56+
}
57+
58+
void PluginScaleManager::wp_fractional_scale_manager_v1_get_fractional_scale(Resource *resource, uint32_t id, struct ::wl_resource *surface)
59+
{
60+
QWaylandSurface *qwaylandSurface = QWaylandSurface::fromResource(surface);
61+
QWaylandResource shellSurfaceResource(
62+
wl_resource_create(resource->client(), &::wp_fractional_scale_v1_interface, wl_resource_get_version(resource->handle), id));
63+
auto pluginScale = new PluginScale(this, qwaylandSurface, shellSurfaceResource);
64+
pluginScale->send_preferred_scale(m_scale);
65+
}
66+
67+
void PluginScaleManager::setCompositor(QWaylandCompositor *compositor)
68+
{
69+
if (m_compositor) {
70+
disconnect(m_compositor, &QWaylandCompositor::outputAdded, this, nullptr);
71+
}
72+
73+
if (compositor == m_compositor)
74+
return;
75+
76+
m_compositor = compositor;
77+
connect(m_compositor, &QWaylandCompositor::outputAdded, this, [this](auto *output) {
78+
output->setScaleFactor(std::ceil(m_scale / 120));
79+
});
80+
}
81+
82+
PluginScale::PluginScale(PluginScaleManager *manager, QWaylandSurface *surface, const QWaylandResource &resource)
83+
{
84+
setParent(manager);
85+
init(resource.resource());
86+
setExtensionContainer(surface);
87+
QWaylandCompositorExtension::initialize();
88+
89+
connect(manager, &PluginScaleManager::pluginScaleChanged, this, [this](uint32_t scale) {
90+
send_preferred_scale(scale);
91+
});
92+
}
93+
94+
void PluginScale::wp_fractional_scale_v1_destroy(Resource *resource)
95+
{
96+
Q_UNUSED(resource)
97+
deleteLater();
98+
}
99+
18100
PluginSurface::PluginSurface(PluginManager* manager, const QString& pluginId, const QString& itemKey, const QString &displayName, int pluginFlags, int pluginType, int sizePolicy, QWaylandSurface *surface, const QWaylandResource &resource)
19101
: m_manager(manager)
20102
, m_surface(surface)
@@ -29,8 +111,6 @@ PluginSurface::PluginSurface(PluginManager* manager, const QString& pluginId, co
29111
init(resource.resource());
30112
setExtensionContainer(surface);
31113
QWaylandCompositorExtension::initialize();
32-
33-
connect(surface, &QWaylandSurface::bufferSizeChanged, this, &PluginSurface::sizeChanged);
34114
}
35115

36116
QWaylandQuickShellIntegration* PluginSurface::createIntegration(QWaylandQuickShellSurfaceItem *item)
@@ -73,9 +153,14 @@ uint32_t PluginSurface::pluginSizePolicy () const
73153
return m_sizePolicy;
74154
}
75155

76-
QSize PluginSurface::pluginSize() const
156+
int PluginSurface::height() const
157+
{
158+
return m_height;
159+
}
160+
161+
int PluginSurface::width() const
77162
{
78-
return m_surface->bufferSize() / qApp->devicePixelRatio();
163+
return m_width;
79164
}
80165

81166
QString PluginSurface::dccIcon() const
@@ -151,6 +236,23 @@ void PluginSurface::setGlobalPos(const QPoint &pos)
151236
send_raw_global_pos(p.x(), p.y());
152237
}
153238

239+
void PluginSurface::plugin_source_size(Resource *resource, int32_t width, int32_t height)
240+
{
241+
Q_UNUSED(resource);
242+
if (width == 0 || height == 0)
243+
return;
244+
245+
if (height != m_height) {
246+
m_height = height;
247+
Q_EMIT heightChanged();
248+
}
249+
250+
if (width != m_width) {
251+
m_width = width;
252+
Q_EMIT widthChanged();
253+
}
254+
}
255+
154256
PluginPopup::PluginPopup(PluginManager* manager, const QString &pluginId, const QString &itemKey, int x, int y, int popupType, QWaylandSurface *surface, const QWaylandResource &resource)
155257
: m_manager(manager)
156258
, m_surface(surface)
@@ -215,6 +317,16 @@ void PluginPopup::setY(int32_t y)
215317
Q_EMIT yChanged();
216318
}
217319

320+
int PluginPopup::height() const
321+
{
322+
return m_height;
323+
}
324+
325+
int PluginPopup::width() const
326+
{
327+
return m_width;
328+
}
329+
218330
int32_t PluginPopup::popupType() const
219331
{
220332
return m_popupType;
@@ -238,6 +350,24 @@ void PluginPopup::plugin_popup_destroy(Resource *resource)
238350
{
239351
wl_resource_destroy(resource->handle);
240352
}
353+
354+
void PluginPopup::plugin_popup_source_size(Resource *resource, int32_t width, int32_t height)
355+
{
356+
Q_UNUSED(resource);
357+
if (width == 0 || height == 0)
358+
return;
359+
360+
if (height != m_height) {
361+
m_height = height;
362+
Q_EMIT heightChanged();
363+
}
364+
365+
if (width != m_width) {
366+
m_width = width;
367+
Q_EMIT widthChanged();
368+
}
369+
}
370+
241371
PluginManager::PluginManager(QWaylandCompositor *compositor)
242372
: QWaylandCompositorExtensionTemplate(compositor)
243373
{

0 commit comments

Comments
 (0)