Commit 18b8f22c authored by dacheng yang's avatar dacheng yang Committed by Xaver Hugl
Browse files

fix(randr): screen is dirty when switching display modes

Because of the order of calls in XRandRConfig, screen is dirty when switching display modes.

This patch removes the intermediateScreenSize.
Swap the change order of crtc and screen size, and disable crtc before that.

The previous method was to first set an intermediate screen size then set the crtc and finally set the target screen size.
The modified method is to disable crtc first, then change the screen size and finally set crtc.
This change can effectively solve the problem of blurry screen when switching display modes.
parent 0b1186f3
Pipeline #180541 passed with stage
in 2 minutes and 32 seconds
......@@ -122,16 +122,11 @@ void XRandRConfig::applyKScreenConfig(const KScreen::ConfigPtr &config)
const QSize newScreenSize = screenSize(config);
const QSize currentScreenSize = m_screen->currentSize();
// When the current screen configuration is bigger than the new size (like
// when rotating an output), the XSetScreenSize can fail or apply the smaller
// size only partially, because we apply the size (we have to) before the
// output changes. To prevent all kinds of weird screen sizes from happening,
// we initially set such screen size, that it can take the current as well
// as the new configuration, then we apply the output changes, and finally then
// (if necessary) we reduce the screen size to fix the new configuration precisely.
const QSize intermediateScreenSize =
QSize(qMax(newScreenSize.width(), currentScreenSize.width()), qMax(newScreenSize.height(), currentScreenSize.height()));
// Previously we initially set such screen size, that it can take the current
// as well as the new configuration, then we apply the output changes,
// and finally then (if necessary) we reduce the screen size to
// fix the new configuration precisely.Now we initially disable the output,
// then set the target screen size, and finally we apply the output changes.
int neededCrtcs = 0;
xcb_randr_output_t primaryOutput = 0;
xcb_randr_output_t oldPrimaryOutput = 0;
......@@ -242,7 +237,6 @@ void XRandRConfig::applyKScreenConfig(const KScreen::ConfigPtr &config)
qCDebug(KSCREEN_XRANDR) << "\tChange Screen Size:" << (newScreenSize != currentScreenSize);
if (newScreenSize != currentScreenSize) {
qCDebug(KSCREEN_XRANDR) << "\t\tOld:" << currentScreenSize << "\n"
<< "\t\tIntermediate:" << intermediateScreenSize << "\n"
<< "\t\tNew:" << newScreenSize;
}
......@@ -277,24 +271,14 @@ void XRandRConfig::applyKScreenConfig(const KScreen::ConfigPtr &config)
disableOutput(output);
}
if (intermediateScreenSize != currentScreenSize) {
setScreenSize(intermediateScreenSize);
if (currentScreenSize != newScreenSize) {
for (const KScreen::OutputPtr &output : toChange) {
disableOutput(output);
}
}
bool forceScreenSizeUpdate = false;
for (const KScreen::OutputPtr &output : toChange) {
if (!changeOutput(output)) {
/* If we disabled the output before changing it and XRandR failed
* to re-enable it, then update screen size too */
if (toDisable.contains(output->id())) {
output->setEnabled(false);
qCDebug(KSCREEN_XRANDR) << "Output failed to change: " << output->name();
forceScreenSizeUpdate = true;
}
}
}
for (const KScreen::OutputPtr &output : toEnable) {
if (!enableOutput(output)) {
qCDebug(KSCREEN_XRANDR) << "Output failed to be Enabled: " << output->name();
......@@ -306,7 +290,7 @@ void XRandRConfig::applyKScreenConfig(const KScreen::ConfigPtr &config)
setPrimaryOutput(primaryOutput);
}
if (forceScreenSizeUpdate || intermediateScreenSize != newScreenSize) {
if (forceScreenSizeUpdate || currentScreenSize != newScreenSize) {
QSize newSize = newScreenSize;
if (forceScreenSizeUpdate) {
newSize = screenSize(config);
......@@ -314,6 +298,18 @@ void XRandRConfig::applyKScreenConfig(const KScreen::ConfigPtr &config)
}
setScreenSize(newSize);
}
for (const KScreen::OutputPtr &output : toChange) {
if (!changeOutput(output)) {
/* If we disabled the output before changing it and XRandR failed
* to re-enable it, then update screen size too */
if (toDisable.contains(output->id())) {
output->setEnabled(false);
qCDebug(KSCREEN_XRANDR) << "Output failed to change: " << output->name();
}
}
}
}
void XRandRConfig::printConfig(const ConfigPtr &config) const
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment