diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-10-04 01:32:07 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-10-04 01:32:07 +0000 |
commit | b63fc7fc7586d2af5d45554f30e99b17d9c578e6 (patch) | |
tree | 6f92a1ecfef7b20cfdb4a6ed40f886dfa0e4a2d6 | |
parent | 515f9aacbe27e9cd8b8378d338d12fed2ec3cfd1 (diff) | |
download | tdelibs-b63fc7fc7586d2af5d45554f30e99b17d9c578e6.tar.gz tdelibs-b63fc7fc7586d2af5d45554f30e99b17d9c578e6.zip |
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
-rw-r--r-- | krandr/libkrandr.cc | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/krandr/libkrandr.cc b/krandr/libkrandr.cc index 182ca7dcf..74e4184a7 100644 --- a/krandr/libkrandr.cc +++ b/krandr/libkrandr.cc @@ -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; |