Skip to content

Commit f691bcd

Browse files
tsic404deepin-bot[bot]
authored andcommitted
fix: popup scaling incorrectly
Set plugin scaling via fractional scaling protocol instead of QT environment variables log: as title
1 parent 137e505 commit f691bcd

File tree

11 files changed

+218
-18
lines changed

11 files changed

+218
-18
lines changed

debian/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Build-Depends:
3232
libqt6svg6,
3333
libdtk6declarative, qml6-module-qtquick-controls2-styles-chameleon, qt6-declarative-private-dev,
3434
libyaml-cpp-dev,
35-
qt6-l10n-tools, qt6-svg-dev, dde-tray-loader-dev (>= 1.99.5),
35+
qt6-l10n-tools, qt6-svg-dev, dde-tray-loader-dev (> 1.99.6),
3636
dde-application-manager-api (>= 1.2.16), dde-control-center-dev (>= 6.0.73)
3737
Standards-Version: 3.9.8
3838
Homepage: http://www.deepin.org

panels/dock/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ qt_add_qml_module(dock-plugin
148148
qt_generate_wayland_protocol_server_sources(dock-plugin
149149
FILES
150150
${DDE_TRAY_LOADER_PROTOCOL}
151+
${WaylandProtocols_DATADIR}/staging/fractional-scale/fractional-scale-v1.xml
151152
)
152153

153154
target_link_libraries(dock-plugin PUBLIC

panels/dock/DockCompositor.qml

Lines changed: 6 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,10 @@ Item {
107108
dockCompositor.requestShutdown()
108109
}
109110
}
111+
112+
PluginScaleManager{
113+
id: pluginScaleManager
114+
pluginScale: dockCompositor.panelScale * 120
115+
}
110116
}
111117
}

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: 120 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,74 @@
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+
1886
PluginSurface::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

36102
QWaylandQuickShellIntegration* 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

81152
QString 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+
154242
PluginPopup::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+
218316
int32_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+
241357
PluginManager::PluginManager(QWaylandCompositor *compositor)
242358
: QWaylandCompositorExtensionTemplate(compositor)
243359
{

0 commit comments

Comments
 (0)