Fix potential crash in libkrandr if number of monitors increases after initial scan and before settings are applied

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

@ -599,8 +599,9 @@ bool KRandrSimpleAPI::applySystemwideDisplayConfiguration(TQPtrList<SingleScreen
randr_display = qt_xdisplay(); randr_display = qt_xdisplay();
randr_screen_info = read_screen_info(randr_display); randr_screen_info = read_screen_info(randr_display);
for (i = 0; i < randr_screen_info->n_output; i++) { for (i = 0; i < screenInfoArray.count(); i++) {
screendata = screenInfoArray.at(i); screendata = screenInfoArray.at(i);
if (screendata) {
output_info = randr_screen_info->outputs[i]->info; output_info = randr_screen_info->outputs[i]->info;
command.append(" --output ").append(output_info->name); command.append(" --output ").append(output_info->name);
if (screendata->is_primary || screendata->is_extended) { if (screendata->is_primary || screendata->is_extended) {
@ -624,6 +625,10 @@ bool KRandrSimpleAPI::applySystemwideDisplayConfiguration(TQPtrList<SingleScreen
command.append(" --off"); command.append(" --off");
} }
} }
else {
printf("[WARNING] Unable to find configuration for monitor %d; settings may not be correctly applied...\n\r", i); fflush(stdout);
}
}
freeScreenInfoStructure(randr_screen_info); freeScreenInfoStructure(randr_screen_info);
TQString xrandr_command_output = exec(command.ascii()); TQString xrandr_command_output = exec(command.ascii());
@ -643,7 +648,7 @@ bool KRandrSimpleAPI::applySystemwideDisplayConfiguration(TQPtrList<SingleScreen
// FIXME: This also only occurs when the primary display has been changed // FIXME: This also only occurs when the primary display has been changed
// FIXME: Check for that condition as well! // FIXME: Check for that condition as well!
if (kapp->desktop()->numScreens() > 1) { if (kapp->desktop()->numScreens() > 1) {
for (i = 0; i < randr_screen_info->n_output; i++) { for (i = 0; i < screenInfoArray.count(); i++) {
screendata = screenInfoArray.at(i); screendata = screenInfoArray.at(i);
if (screendata->is_primary == true) { if (screendata->is_primary == true) {
kapp->desktop()->emitResizedSignal(i); kapp->desktop()->emitResizedSignal(i);
@ -654,7 +659,7 @@ bool KRandrSimpleAPI::applySystemwideDisplayConfiguration(TQPtrList<SingleScreen
randr_display = qt_xdisplay(); randr_display = qt_xdisplay();
randr_screen_info = read_screen_info(randr_display); randr_screen_info = read_screen_info(randr_display);
// Turn off all displays // Turn off all displays
for (i = 0; i < randr_screen_info->n_output; i++) { for (i = 0; i < screenInfoArray.count(); i++) {
screendata = screenInfoArray.at(i); screendata = screenInfoArray.at(i);
output_info = randr_screen_info->outputs[i]->info; output_info = randr_screen_info->outputs[i]->info;
@ -668,7 +673,7 @@ bool KRandrSimpleAPI::applySystemwideDisplayConfiguration(TQPtrList<SingleScreen
freeScreenInfoStructure(randr_screen_info); freeScreenInfoStructure(randr_screen_info);
randr_screen_info = read_screen_info(randr_display); randr_screen_info = read_screen_info(randr_display);
// Turn on the primary display // Turn on the primary display
for (i = 0; i < randr_screen_info->n_output; i++) { for (i = 0; i < screenInfoArray.count(); i++) {
screendata = screenInfoArray.at(i); screendata = screenInfoArray.at(i);
output_info = randr_screen_info->outputs[i]->info; output_info = randr_screen_info->outputs[i]->info;
@ -684,7 +689,7 @@ bool KRandrSimpleAPI::applySystemwideDisplayConfiguration(TQPtrList<SingleScreen
freeScreenInfoStructure(randr_screen_info); freeScreenInfoStructure(randr_screen_info);
// Handle the remaining displays // Handle the remaining displays
randr_screen_info = read_screen_info(randr_display); randr_screen_info = read_screen_info(randr_display);
for (i = 0; i < randr_screen_info->n_output; i++) { for (i = 0; i < screenInfoArray.count(); i++) {
screendata = screenInfoArray.at(i); screendata = screenInfoArray.at(i);
output_info = randr_screen_info->outputs[i]->info; output_info = randr_screen_info->outputs[i]->info;
@ -708,7 +713,7 @@ bool KRandrSimpleAPI::applySystemwideDisplayConfiguration(TQPtrList<SingleScreen
} }
freeScreenInfoStructure(randr_screen_info); freeScreenInfoStructure(randr_screen_info);
randr_screen_info = read_screen_info(randr_display); randr_screen_info = read_screen_info(randr_display);
for (i = 0; i < randr_screen_info->n_output; i++) { for (i = 0; i < screenInfoArray.count(); i++) {
screendata = screenInfoArray.at(i); screendata = screenInfoArray.at(i);
output_info = randr_screen_info->outputs[i]->info; output_info = randr_screen_info->outputs[i]->info;
@ -891,7 +896,7 @@ void KRandrSimpleAPI::applySystemwideDisplayGamma(TQPtrList<SingleScreenData> sc
if (isValid() == true) { if (isValid() == true) {
randr_display = qt_xdisplay(); randr_display = qt_xdisplay();
randr_screen_info = read_screen_info(randr_display); randr_screen_info = read_screen_info(randr_display);
for (i = 0; i < randr_screen_info->n_output; i++) { for (i = 0; i < screenInfoArray.count(); i++) {
screendata = screenInfoArray.at(i); screendata = screenInfoArray.at(i);
output_info = randr_screen_info->outputs[i]->info; output_info = randr_screen_info->outputs[i]->info;
CrtcInfo *current_crtc = randr_screen_info->outputs[i]->cur_crtc; CrtcInfo *current_crtc = randr_screen_info->outputs[i]->cur_crtc;
@ -943,7 +948,7 @@ void KRandrSimpleAPI::applySystemwideDisplayDPMS(TQPtrList<SingleScreenData> scr
if (isValid() == true) { if (isValid() == true) {
randr_display = qt_xdisplay(); randr_display = qt_xdisplay();
randr_screen_info = read_screen_info(randr_display); randr_screen_info = read_screen_info(randr_display);
for (i = 0; i < randr_screen_info->n_output; i++) { for (i = 0; i < screenInfoArray.count(); i++) {
screendata = screenInfoArray.at(i); screendata = screenInfoArray.at(i);
output_info = randr_screen_info->outputs[i]->info; output_info = randr_screen_info->outputs[i]->info;
CrtcInfo *current_crtc = randr_screen_info->outputs[i]->cur_crtc; CrtcInfo *current_crtc = randr_screen_info->outputs[i]->cur_crtc;

Loading…
Cancel
Save