Fix krandr setting multiple displays as primary

Fix krandr silently failing to apply settings when underlying hardware does not support the requests


git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1257190 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
v3.5.13-sru
tpearson 13 years ago
parent 515f9aacbe
commit b63fc7fc75

@ -26,6 +26,7 @@
#include <tqstringlist.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kapplication.h>
#include <stdlib.h>
@ -50,6 +51,25 @@ unsigned int reverse_bits(register unsigned int x)
return((x >> 16) | (x << 16));
}
// This routine returns the output of an arbitrary Bash command
TQString exec(const char * cmd) {
TQString bashcommand = cmd;
bashcommand = bashcommand.replace("\"", "\\\"");
bashcommand = TQString("/bin/bash -c \"%1\" 2>&1").tqarg(bashcommand);
FILE* pipe = popen(bashcommand.ascii(), "r");
if (!pipe) return "ERROR";
char buffer[128];
TQString result = "";
while(!feof(pipe)) {
if(fgets(buffer, 128, pipe) != NULL) {
result += buffer;
}
}
pclose(pipe);
result.remove(result.length(), 1);
return result;
}
TQString capitalizeString(TQString in) {
return in.left(1).upper() + in.right(in.length()-1);
}
@ -606,7 +626,15 @@ bool KRandrSimpleAPI::applySystemwideDisplayConfiguration(TQPtrList<SingleScreen
}
freeScreenInfoStructure(randr_screen_info);
system(command.ascii());
TQString xrandr_command_output = exec(command.ascii());
xrandr_command_output = xrandr_command_output.stripWhiteSpace();
if (xrandr_command_output != "") {
applySystemwideDisplayConfiguration(oldconfig, FALSE);
accepted = false;
destroyScreenInformationObject(oldconfig);
KMessageBox::sorry(0, xrandr_command_output, i18n("XRandR encountered a problem"));
return accepted;
}
// HACK
// This is needed because Qt does not properly generate screen
@ -778,6 +806,19 @@ void KRandrSimpleAPI::ensureMonitorDataConsistency(TQPtrList<SingleScreenData> s
}
}
bool found_first_primary_monitor = false;
for (i=0;i<numberOfScreens;i++) {
screendata = screenInfoArray.at(i);
if (screendata->is_primary) {
if (!found_first_primary_monitor) {
found_first_primary_monitor = true;
}
else {
screendata->is_primary = false;
}
}
}
for (i=0;i<numberOfScreens;i++) {
screendata = screenInfoArray.at(i);
if (screendata->is_primary) {
@ -1083,6 +1124,8 @@ TQPtrList<SingleScreenData> KRandrSimpleAPI::readCurrentDisplayConfiguration() {
else
screendata->is_primary = true;
screendata->is_extended = screen_active;
if (!screendata->is_extended)
screendata->is_primary = false;
// Get this screen's absolute position
screendata->absolute_x_position = 0;

Loading…
Cancel
Save