From 7c5dea76bf90caad177e1dd78991b699a3f58bd5 Mon Sep 17 00:00:00 2001 From: tpearson Date: Tue, 4 Oct 2011 01:33:33 +0000 Subject: Fix a potential crash in the displayconfig control center module git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1257191 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kcontrol/displayconfig/displayconfig.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'kcontrol/displayconfig') diff --git a/kcontrol/displayconfig/displayconfig.cpp b/kcontrol/displayconfig/displayconfig.cpp index ad2d31fff..b6b2b8a5e 100644 --- a/kcontrol/displayconfig/displayconfig.cpp +++ b/kcontrol/displayconfig/displayconfig.cpp @@ -465,13 +465,14 @@ void KDisplayConfig::updateDraggableMonitorInformationInternal (int monitor_id, j=i; } monitors = base->monitorPhyArrange->childrenListObject(); - primary_monitor = 0; + primary_monitor = NULL; if ( monitors.count() ) { for ( i = 0; i < int(monitors.count()); ++i ) { if (::tqqt_cast(TQT_TQWIDGET(monitors.at( i )))) { DraggableMonitor *monitor = static_cast(TQT_TQWIDGET(monitors.at( i ))); - if (monitor->screen_id == j) + if (monitor->screen_id == j) { primary_monitor = monitor; + } } } } @@ -614,16 +615,21 @@ bool KDisplayConfig::applyMonitorLayoutRules(DraggableMonitor* monitor_to_move) void KDisplayConfig::moveMonitor(DraggableMonitor* monitor, int realx, int realy) { int i; int j; + bool primary_found; DraggableMonitor *primary_monitor; SingleScreenData *screendata; // Find the primary monitor + primary_found = false; for (i=0;iis_primary) + if (screendata->is_primary) { j=i; + primary_found = true; + } } TQObjectList monitors = base->monitorPhyArrange->childrenListObject(); + primary_monitor = NULL; if ( monitors.count() ) { for ( i = 0; i < int(monitors.count()); ++i ) { if (::tqqt_cast(TQT_TQWIDGET(monitors.at( i )))) { @@ -634,13 +640,15 @@ void KDisplayConfig::moveMonitor(DraggableMonitor* monitor, int realx, int realy } } - int tx = realx * base->monitorPhyArrange->resize_factor; - int ty = realy * base->monitorPhyArrange->resize_factor; - - if (!monitor->isHidden()) - monitor->move((base->monitorPhyArrange->width()/2)-(primary_monitor->width()/2)+tx,(base->monitorPhyArrange->height()/2)-(primary_monitor->height()/2)+ty); - else - monitor->move(base->monitorPhyArrange->width(), base->monitorPhyArrange->height()); + if (primary_found && primary_monitor) { + int tx = realx * base->monitorPhyArrange->resize_factor; + int ty = realy * base->monitorPhyArrange->resize_factor; + + if (!monitor->isHidden()) + monitor->move((base->monitorPhyArrange->width()/2)-(primary_monitor->width()/2)+tx,(base->monitorPhyArrange->height()/2)-(primary_monitor->height()/2)+ty); + else + monitor->move(base->monitorPhyArrange->width(), base->monitorPhyArrange->height()); + } } // int KDisplayConfig::realResolutionSliderValue() { @@ -1058,6 +1066,8 @@ void KDisplayConfig::updateDragDropDisplay() { int currentScreenIndex = base->monitorDisplaySelectDD->currentItem(); + ensureMonitorDataConsistency(); + // Add the screens to the workspace // Set the scaling small to start with base->monitorPhyArrange->resize_factor = 0.0625; // This always needs to divide by a multiple of 2 -- cgit v1.2.1