summaryrefslogtreecommitdiffstats
path: root/source/kde/kde/patch/libkscreen/7eb0390bf70fc7fb5a39bd501ffcc327a07c328a.patch
blob: b0e5e71369ee22af7f9510d519abe76b1c29e6bf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
From 7eb0390bf70fc7fb5a39bd501ffcc327a07c328a Mon Sep 17 00:00:00 2001
From: Ilya Pominov <ipominov@astralinux.ru>
Date: Thu, 23 Sep 2021 14:24:16 +0300
Subject: [PATCH] XrandR: Fix impossibilty to change resolution in VirtualBox

In VirtualBox KDE runs at low resolution,
and when you try to change the resolution through the "Screen Settings"
it returns to the original one again.
How to check:
- run KDE neon on VirtualBox
- change the resolution

VirtualBox sets the hotplug_mode_update property, but its preferred mode
is always 800x600, and KScreen returns the resolution to 800x600.

Now XRandRCrtc stores the timestamp of the last resolution change
request from backend, and the timestamp of the last config update from
X11.
If the changes were initiated by XRandR backend (i.e. 'timestamp of the
last config update from X11' less or equal 'last resolution change
request'), then the followPreferedMode flag in KScreenConfig is set to
false.

BUG: 407058
---
 backends/xcbeventlistener.cpp    |  7 ++++++-
 backends/xcbeventlistener.h      |  2 +-
 backends/xrandr/xrandr.cpp       |  4 +++-
 backends/xrandr/xrandr.h         |  2 +-
 backends/xrandr/xrandrconfig.cpp |  9 +++++++--
 backends/xrandr/xrandrcrtc.cpp   | 23 +++++++++++++++++++++++
 backends/xrandr/xrandrcrtc.h     |  7 +++++++
 backends/xrandr/xrandroutput.cpp |  2 +-
 8 files changed, 49 insertions(+), 7 deletions(-)

diff --git a/backends/xcbeventlistener.cpp b/backends/xcbeventlistener.cpp
index dba81dc..4c3a527 100644
--- a/backends/xcbeventlistener.cpp
+++ b/backends/xcbeventlistener.cpp
@@ -139,6 +139,8 @@ void XCBEventListener::handleScreenChange(xcb_generic_event_t *e)
     }
 
     qCDebug(KSCREEN_XCB_HELPER) << "RRScreenChangeNotify";
+    qCDebug(KSCREEN_XCB_HELPER) << "\tTimestamp: " << e2->timestamp;
+    qCDebug(KSCREEN_XCB_HELPER) << "\tConfig_timestamp: " << e2->config_timestamp;
     qCDebug(KSCREEN_XCB_HELPER) << "\tWindow:" << e2->request_window;
     qCDebug(KSCREEN_XCB_HELPER) << "\tRoot:" << e2->root;
     qCDebug(KSCREEN_XCB_HELPER) << "\tRotation: " << rotationToString((xcb_randr_rotation_t)e2->rotation);
@@ -157,15 +159,17 @@ void XCBEventListener::handleXRandRNotify(xcb_generic_event_t *e)
     if (randrEvent->subCode == XCB_RANDR_NOTIFY_CRTC_CHANGE) {
         xcb_randr_crtc_change_t crtc = randrEvent->u.cc;
         qCDebug(KSCREEN_XCB_HELPER) << "RRNotify_CrtcChange";
+        qCDebug(KSCREEN_XCB_HELPER) << "\tTimestamp: " << crtc.timestamp;
         qCDebug(KSCREEN_XCB_HELPER) << "\tCRTC: " << crtc.crtc;
         qCDebug(KSCREEN_XCB_HELPER) << "\tMode: " << crtc.mode;
         qCDebug(KSCREEN_XCB_HELPER) << "\tRotation: " << rotationToString((xcb_randr_rotation_t)crtc.rotation);
         qCDebug(KSCREEN_XCB_HELPER) << "\tGeometry: " << crtc.x << crtc.y << crtc.width << crtc.height;
-        Q_EMIT crtcChanged(crtc.crtc, crtc.mode, (xcb_randr_rotation_t)crtc.rotation, QRect(crtc.x, crtc.y, crtc.width, crtc.height));
+        Q_EMIT crtcChanged(crtc.crtc, crtc.mode, (xcb_randr_rotation_t)crtc.rotation, QRect(crtc.x, crtc.y, crtc.width, crtc.height), crtc.timestamp);
 
     } else if (randrEvent->subCode == XCB_RANDR_NOTIFY_OUTPUT_CHANGE) {
         xcb_randr_output_change_t output = randrEvent->u.oc;
         qCDebug(KSCREEN_XCB_HELPER) << "RRNotify_OutputChange";
+        qCDebug(KSCREEN_XCB_HELPER) << "\tTimestamp: " << output.timestamp;
         qCDebug(KSCREEN_XCB_HELPER) << "\tOutput: " << output.output;
         qCDebug(KSCREEN_XCB_HELPER) << "\tCRTC: " << output.crtc;
         qCDebug(KSCREEN_XCB_HELPER) << "\tMode: " << output.mode;
@@ -181,6 +185,7 @@ void XCBEventListener::handleXRandRNotify(xcb_generic_event_t *e)
             xcb_get_atom_name_reply(QX11Info::connection(), xcb_get_atom_name(QX11Info::connection(), property.atom), nullptr));
 
         qCDebug(KSCREEN_XCB_HELPER) << "RRNotify_OutputProperty (ignored)";
+        qCDebug(KSCREEN_XCB_HELPER) << "\tTimestamp: " << property.timestamp;
         qCDebug(KSCREEN_XCB_HELPER) << "\tOutput: " << property.output;
         qCDebug(KSCREEN_XCB_HELPER) << "\tProperty: " << xcb_get_atom_name_name(reply.data());
         qCDebug(KSCREEN_XCB_HELPER) << "\tState (newValue, Deleted): " << property.status;
diff --git a/backends/xcbeventlistener.h b/backends/xcbeventlistener.h
index 35577d9..68136d8 100644
--- a/backends/xcbeventlistener.h
+++ b/backends/xcbeventlistener.h
@@ -30,7 +30,7 @@ Q_SIGNALS:
     void outputsChanged();
 
     /* Emitted only when XRandR 1.2 or newer is available */
-    void crtcChanged(xcb_randr_crtc_t crtc, xcb_randr_mode_t mode, xcb_randr_rotation_t rotation, const QRect &geom);
+    void crtcChanged(xcb_randr_crtc_t crtc, xcb_randr_mode_t mode, xcb_randr_rotation_t rotation, const QRect &geom, xcb_timestamp_t timestamp);
     void outputChanged(xcb_randr_output_t output, xcb_randr_crtc_t crtc, xcb_randr_mode_t mode, xcb_randr_connection_t connection);
     void outputPropertyChanged(xcb_randr_output_t output);
 
diff --git a/backends/xrandr/xrandr.cpp b/backends/xrandr/xrandr.cpp
index 71cbd77..115f268 100644
--- a/backends/xrandr/xrandr.cpp
+++ b/backends/xrandr/xrandr.cpp
@@ -45,6 +45,7 @@ XRandR::XRandR()
     qRegisterMetaType<xcb_randr_mode_t>("xcb_randr_mode_t");
     qRegisterMetaType<xcb_randr_connection_t>("xcb_randr_connection_t");
     qRegisterMetaType<xcb_randr_rotation_t>("xcb_randr_rotation_t");
+    qRegisterMetaType<xcb_timestamp_t>("xcb_timestamp_t");
 
     // Use our own connection to make sure that we won't mess up Qt's connection
     // if something goes wrong on our side.
@@ -143,7 +144,7 @@ void XRandR::outputChanged(xcb_randr_output_t output, xcb_randr_crtc_t crtc, xcb
     qCDebug(KSCREEN_XRANDR) << "Output" << xOutput->id() << ": connected =" << xOutput->isConnected() << ", enabled =" << xOutput->isEnabled();
 }
 
-void XRandR::crtcChanged(xcb_randr_crtc_t crtc, xcb_randr_mode_t mode, xcb_randr_rotation_t rotation, const QRect &geom)
+void XRandR::crtcChanged(xcb_randr_crtc_t crtc, xcb_randr_mode_t mode, xcb_randr_rotation_t rotation, const QRect &geom, xcb_timestamp_t timestamp)
 {
     XRandRCrtc *xCrtc = s_internalConfig->crtc(crtc);
     if (!xCrtc) {
@@ -152,6 +153,7 @@ void XRandR::crtcChanged(xcb_randr_crtc_t crtc, xcb_randr_mode_t mode, xcb_randr
         xCrtc->update(mode, rotation, geom);
     }
 
+    xCrtc->updateConfigTimestamp(timestamp);
     m_configChangeCompressor->start();
 }
 
diff --git a/backends/xrandr/xrandr.h b/backends/xrandr/xrandr.h
index 91dd7aa..6b998c8 100644
--- a/backends/xrandr/xrandr.h
+++ b/backends/xrandr/xrandr.h
@@ -44,7 +44,7 @@ public:
 
 private:
     void outputChanged(xcb_randr_output_t output, xcb_randr_crtc_t crtc, xcb_randr_mode_t mode, xcb_randr_connection_t connection);
-    void crtcChanged(xcb_randr_crtc_t crtc, xcb_randr_mode_t mode, xcb_randr_rotation_t rotation, const QRect &geom);
+    void crtcChanged(xcb_randr_crtc_t crtc, xcb_randr_mode_t mode, xcb_randr_rotation_t rotation, const QRect &geom, xcb_timestamp_t timestamp);
     void screenChanged(xcb_randr_rotation_t rotation, const QSize &sizePx, const QSize &sizeMm);
 
     static quint8 *getXProperty(xcb_randr_output_t output, xcb_atom_t atom, size_t &len);
diff --git a/backends/xrandr/xrandrconfig.cpp b/backends/xrandr/xrandrconfig.cpp
index fa0929c..5cbf4c7 100644
--- a/backends/xrandr/xrandrconfig.cpp
+++ b/backends/xrandr/xrandrconfig.cpp
@@ -504,6 +504,8 @@ bool XRandRConfig::disableOutput(const OutputPtr &kscreenOutput) const
                         XCB_NONE,
                         xOutput->isConnected() ? XCB_RANDR_CONNECTION_CONNECTED : XCB_RANDR_CONNECTION_DISCONNECTED,
                         kscreenOutput->isPrimary());
+        if (xOutput->crtc())
+            xOutput->crtc()->updateTimestamp(reply->timestamp);
     }
     return (reply->status == XCB_RANDR_SET_CONFIG_SUCCESS);
 }
@@ -573,7 +575,7 @@ bool XRandRConfig::changeOutput(const KScreen::OutputPtr &kscreenOutput) const
                             << "\n"
                             << "\tCRTC:" << xOutput->crtc()->crtc() << "\n"
                             << "\tPos:" << kscreenOutput->pos() << "\n"
-                            << "\tMode:" << modeId << kscreenOutput->currentMode() << "\n"
+                            << "\tMode:" << kscreenOutput->currentMode() << "Preferred:" << kscreenOutput->preferredModeId() << "\n"
                             << "\tRotation:" << kscreenOutput->rotation();
 
     if (!sendConfig(kscreenOutput, xOutput->crtc())) {
@@ -605,6 +607,9 @@ bool XRandRConfig::sendConfig(const KScreen::OutputPtr &kscreenOutput, XRandRCrt
         qCDebug(KSCREEN_XRANDR) << "\tResult: unknown (error)";
         return false;
     }
-    qCDebug(KSCREEN_XRANDR) << "\tResult: " << reply->status;
+
+    crtc->updateTimestamp(reply->timestamp);
+
+    qCDebug(KSCREEN_XRANDR) << "\tResult: " << reply->status << " timestamp: " << reply->timestamp;
     return (reply->status == XCB_RANDR_SET_CONFIG_SUCCESS);
 }
diff --git a/backends/xrandr/xrandrcrtc.cpp b/backends/xrandr/xrandrcrtc.cpp
index c3cd291..9209501 100644
--- a/backends/xrandr/xrandrcrtc.cpp
+++ b/backends/xrandr/xrandrcrtc.cpp
@@ -16,6 +16,8 @@ XRandRCrtc::XRandRCrtc(xcb_randr_crtc_t crtc, XRandRConfig *config)
     , m_crtc(crtc)
     , m_mode(0)
     , m_rotation(XCB_RANDR_ROTATION_ROTATE_0)
+    , m_timestamp(XCB_CURRENT_TIME)
+    , m_configTimestamp(XCB_CURRENT_TIME)
 {
     update();
 }
@@ -111,3 +113,24 @@ void XRandRCrtc::update(xcb_randr_mode_t mode, xcb_randr_rotation_t rotation, co
     m_geometry = geom;
     m_rotation = rotation;
 }
+
+void XRandRCrtc::updateTimestamp(const xcb_timestamp_t tmstamp)
+{
+    if (tmstamp > m_timestamp) {
+        qCDebug(KSCREEN_XRANDR) << "XRandRCrtc " << m_crtc << " m_timestamp update " << m_timestamp << " => " << tmstamp;
+        m_timestamp = tmstamp;
+    }
+}
+
+void XRandRCrtc::updateConfigTimestamp(const xcb_timestamp_t tmstamp)
+{
+    if (tmstamp > m_configTimestamp) {
+        qCDebug(KSCREEN_XRANDR) << "XRandRCrtc " << m_crtc << " m_configTimestamp update" << m_configTimestamp << " => " << tmstamp;
+        m_configTimestamp = tmstamp;
+    }
+}
+
+bool XRandRCrtc::isChangedFromOutside() const
+{
+    return m_configTimestamp > m_timestamp;
+}
diff --git a/backends/xrandr/xrandrcrtc.h b/backends/xrandr/xrandrcrtc.h
index 4de4a09..8be23d2 100644
--- a/backends/xrandr/xrandrcrtc.h
+++ b/backends/xrandr/xrandrcrtc.h
@@ -41,6 +41,10 @@ public:
     void update();
     void update(xcb_randr_crtc_t mode, xcb_randr_rotation_t rotation, const QRect &geom);
 
+    void updateTimestamp(const xcb_timestamp_t tmstamp);
+    void updateConfigTimestamp(const xcb_timestamp_t tmstamp);
+    bool isChangedFromOutside() const;
+
 private:
     xcb_randr_crtc_t m_crtc;
     xcb_randr_mode_t m_mode;
@@ -50,4 +54,7 @@ private:
 
     QVector<xcb_randr_output_t> m_possibleOutputs;
     QVector<xcb_randr_output_t> m_outputs;
+
+    xcb_timestamp_t m_timestamp;
+    xcb_timestamp_t m_configTimestamp;
 };
diff --git a/backends/xrandr/xrandroutput.cpp b/backends/xrandr/xrandroutput.cpp
index 92a39cf..4aa2290 100644
--- a/backends/xrandr/xrandroutput.cpp
+++ b/backends/xrandr/xrandroutput.cpp
@@ -403,7 +403,7 @@ KScreen::OutputPtr XRandROutput::toKScreenOutput() const
 
     // See https://bugzilla.redhat.com/show_bug.cgi?id=1290586
     // QXL will be creating a new mode we need to jump to every time the display is resized
-    kscreenOutput->setFollowPreferredMode(m_hotplugModeUpdate);
+    kscreenOutput->setFollowPreferredMode(m_hotplugModeUpdate && m_crtc && m_crtc->isChangedFromOutside());
 
     kscreenOutput->setConnected(isConnected());
     if (isConnected()) {
-- 
GitLab