diff options
| author | Alexander Golubev <fatzer2@gmail.com> | 2026-03-23 11:18:23 +0300 |
|---|---|---|
| committer | Alexander Golubev <fatzer2@gmail.com> | 2026-03-23 13:14:34 +0300 |
| commit | 94620219ffaf0be7e15d73750137b0d45ed24685 (patch) | |
| tree | c4f33f67389e565ad1c72bccba02b5c200ee7601 /kcontrol/background/bgmonitor.cpp | |
| parent | 6715f2542ef39e3df7b0050aa483b4e4973ac693 (diff) | |
| download | tdebase-Fat-Zer/fix/kdesktop-multihead.tar.gz tdebase-Fat-Zer/fix/kdesktop-multihead.zip | |
kdesktop: better support for old-school multihead setupsFat-Zer/fix/kdesktop-multihead
This fixes several issues on "old-school multihead" X11 setups (with
several screens per display i.e. when DISPLAY has form ":x.y"
also known as "TDE_MULTIHEAD" or "Zaphode mode"). Also it slightly
enhances functionality for more common xinerama setups. In particular:
* fixed an issue where on primary screen wallpaper is getting rendered
for both secondary and primary on certain kdesktop configurations.
* fixed an issue on walpaper config dialog where previews for two
monitors were displayed overlapped.
* update preview in config dialog in case a monitor gets
connected/disconnected.
* some minor whitespace cleanup.
Diffstat (limited to 'kcontrol/background/bgmonitor.cpp')
| -rw-r--r-- | kcontrol/background/bgmonitor.cpp | 84 |
1 files changed, 53 insertions, 31 deletions
diff --git a/kcontrol/background/bgmonitor.cpp b/kcontrol/background/bgmonitor.cpp index ac826a1ff..75fd56546 100644 --- a/kcontrol/background/bgmonitor.cpp +++ b/kcontrol/background/bgmonitor.cpp @@ -5,16 +5,16 @@ Copyright (C) 2002 Laurent Montel <montell@club-internet.fr> Copyright (C) 2003 Waldo Bastian <bastian@kde.org> Copyright (C) 2005 David Saxton <david@bluehaze.org> - + This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License + modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. - + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. - + You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, @@ -30,6 +30,8 @@ #include <tqpixmap.h> #include <tqwhatsthis.h> +#include <memory> + #include "bgmonitor.h" // Constants used (should they be placed somewhere?) @@ -40,16 +42,10 @@ BGMonitorArrangement::BGMonitorArrangement(TQWidget *parent, const char *name) : TQWidget(parent, name) { - m_pBGMonitor.resize( TQApplication::desktop()->numScreens(), 0l ); - - for (int screen = 0; screen < TQApplication::desktop()->numScreens(); ++screen) - { - BGMonitorLabel * label = new BGMonitorLabel(this); - m_pBGMonitor[screen] = label; - - connect( label->monitor(), TQ_SIGNAL(imageDropped(const TQString &)), this, TQ_SIGNAL(imageDropped(const TQString &)) ); - } - + connect(TQApplication::desktop(), TQ_SIGNAL(screenCountChanged(int)), + this , TQ_SLOT(updateArrangement())); + connect(TQApplication::desktop(), TQ_SIGNAL(resized(int)), + this , TQ_SLOT(updateArrangement())); parent->setFixedSize(200, 186); setFixedSize(200, 186); updateArrangement(); @@ -92,40 +88,66 @@ void BGMonitorArrangement::updateArrangement() // value. The expanded value is used for setting the size of the monitor // image that contains the preview of the background. The monitor image // will set the background preview back to the normal value. - + + bool isVDesktop = TQApplication::desktop()->isVirtualDesktop(); TQRect overallGeometry; - for (int screen = 0; screen < TQApplication::desktop()->numScreens(); ++screen) - overallGeometry |= TQApplication::desktop()->screenGeometry(screen); - + size_t screen_num = isVDesktop ? TQApplication::desktop()->numScreens() : 1; + + // create/destroy monitors + if (m_pBGMonitor.size() != screen_num) { + size_t old_size = m_pBGMonitor.size(); + if(old_size<screen_num) { + for (size_t screen = old_size; screen < screen_num; ++screen) + { + m_pBGMonitor.emplace_back(std::make_unique<BGMonitorLabel>(this)); + connect( m_pBGMonitor[screen]->monitor(), TQ_SIGNAL(imageDropped(const TQString &)), this, TQ_SIGNAL(imageDropped(const TQString &)) ); + } + } else { + m_pBGMonitor.resize(screen_num); + } + } + overallGeometry = TQApplication::desktop()->screenGeometry(); + if (isVDesktop) { + for (size_t screen = 0; screen < screen_num; ++screen) + overallGeometry |= TQApplication::desktop()->screenGeometry(screen); + } else { + overallGeometry = TQApplication::desktop()->screenGeometry(); + } + TQRect expandedOverallGeometry = expandToPreview(overallGeometry); - + double scale = TQMIN( double(width()) / double(expandedOverallGeometry.width()), double(height()) / double(expandedOverallGeometry.height()) ); - + m_combinedPreviewSize = overallGeometry.size() * scale; - + m_maxPreviewSize = TQSize(0,0); int previousMax = 0; - - for (int screen = 0; screen < TQApplication::desktop()->numScreens(); ++screen) - { + + auto screenSetupWorker = [&](size_t screen){ TQPoint topLeft = (TQApplication::desktop()->screenGeometry(screen).topLeft() - overallGeometry.topLeft()) * scale; - TQPoint expandedTopLeft = expandToPreview(topLeft); - TQSize previewSize = TQApplication::desktop()->screenGeometry(screen).size() * scale; + + TQPoint expandedTopLeft = expandToPreview(topLeft); TQSize expandedPreviewSize = expandToPreview(previewSize); - + if ( (previewSize.width() * previewSize.height()) > previousMax ) { previousMax = previewSize.width() * previewSize.height(); m_maxPreviewSize = previewSize; } - + m_pBGMonitor[screen]->setPreviewPosition( TQRect( topLeft, previewSize ) ); m_pBGMonitor[screen]->setGeometry( TQRect( expandedTopLeft, expandedPreviewSize ) ); m_pBGMonitor[screen]->updateMonitorGeometry(); + }; + if(isVDesktop) { + for (size_t screen = 0; screen < screen_num; ++screen) + screenSetupWorker(screen); + } else { + screenSetupWorker(TQApplication::desktop()->primaryScreen()); } } @@ -142,7 +164,7 @@ void BGMonitorArrangement::setPixmap( const KPixmap & pm ) for (unsigned screen = 0; screen < m_pBGMonitor.size(); ++screen) { TQRect position = m_pBGMonitor[screen]->previewPosition(); - + TQPixmap monitorPixmap( position.size(), pm.depth() ); copyBlt( &monitorPixmap, 0, 0, &pm, position.x(), position.y(), position.width(), position.height() ); m_pBGMonitor[screen]->monitor()->setPixmap(monitorPixmap); @@ -160,7 +182,7 @@ BGMonitorLabel::BGMonitorLabel(TQWidget *parent, const char *name) setScaledContents(true); setPixmap( TQPixmap( locate("data", "kcontrol/pics/monitor.png") ) ); m_pBGMonitor = new BGMonitor(this); - + TQWhatsThis::add( this, i18n("This picture of a monitor contains a preview of what the current settings will look like on your desktop.") ); } @@ -169,7 +191,7 @@ void BGMonitorLabel::updateMonitorGeometry() { double scaleX = double(width()) / double(sizeHint().width()); double scaleY = double(height()) / double(sizeHint().height()); - + kdDebug() << k_funcinfo << " Setting geometry to " << TQRect( int(23*scaleX), int(14*scaleY), int(151*scaleX), int(115*scaleY) ) << endl; m_pBGMonitor->setGeometry( int(23*scaleX), int(14*scaleY), int(151*scaleX), int(115*scaleY) ); } |
