From 2f3e71bfb99194163418662d6324a2a2f4545e70 Mon Sep 17 00:00:00 2001 From: tpearson Date: Sun, 18 Apr 2010 01:56:34 +0000 Subject: Fixed screen switching (worked around Qt bug) git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1115935 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kcontrol/randr/krandrtray.cpp | 62 ++++++++++++++++++++++++++++++++++++------- kcontrol/randr/krandrtray.h | 7 +++++ 2 files changed, 60 insertions(+), 9 deletions(-) (limited to 'kcontrol/randr') diff --git a/kcontrol/randr/krandrtray.cpp b/kcontrol/randr/krandrtray.cpp index 20e617d75..3c1317e92 100644 --- a/kcontrol/randr/krandrtray.cpp +++ b/kcontrol/randr/krandrtray.cpp @@ -32,6 +32,8 @@ #include #include +#include + #include "configdialog.h" #include "krandrtray.h" @@ -55,7 +57,7 @@ KRandRSystemTray::KRandRSystemTray(QWidget* parent, const char *name) QToolTip::add(this, i18n("Screen resize & rotate")); my_parent = parent; - printf("Reading configuration...\n\r"); + //printf("Reading configuration...\n\r"); globalKeys = new KGlobalAccel(this); KGlobalAccel* keys = globalKeys; #include "krandrbindings.cpp" @@ -66,7 +68,14 @@ KRandRSystemTray::KRandRSystemTray(QWidget* parent, const char *name) connect(kapp, SIGNAL(settingsChanged(int)), SLOT(slotSettingsChanged(int))); +#if (QT_VERSION-0 >= 0x030200) // XRANDR support +// connect(this, SIGNAL(screenSizeChanged(int, int)), kapp->desktop(), SLOT( desktopResized())); +#endif + randr_display = XOpenDisplay(NULL); + + last_known_x = currentScreen()->currentPixelWidth(); + last_known_y = currentScreen()->currentPixelHeight(); } void KRandRSystemTray::mousePressEvent(QMouseEvent* e) @@ -124,7 +133,13 @@ void KRandRSystemTray::contextMenuAboutToShow(KPopupMenu* menu) if (screenDeactivated == 1) { findPrimaryDisplay(); refresh(); - + + // HACK + // This is needed because Qt does not properly generate screen + // resize events when switching screens, so KDE gets stuck in the old resolution + currentScreen()->proposeSize(GetHackResolutionParameter()); + currentScreen()->applyProposed(); + currentScreen()->proposeSize(GetDefaultResolutionParameter()); currentScreen()->applyProposed(); } @@ -187,11 +202,22 @@ void KRandRSystemTray::configChanged() static bool first = true; - if (!first) + if ((last_known_x == currentScreen()->currentPixelWidth()) && \ + (last_known_y == currentScreen()->currentPixelHeight())) { + first = true; + } + + last_known_x = currentScreen()->currentPixelWidth(); + last_known_y = currentScreen()->currentPixelHeight(); + + if (!first) { + emit (screenSizeChanged(currentScreen()->currentPixelWidth(), currentScreen()->currentPixelHeight())); + KRandrPassivePopup::message( i18n("Screen configuration has changed"), currentScreen()->changedMessage(), SmallIcon("window_fullscreen"), this, "ScreenChangeNotification"); + } first = false; } @@ -226,6 +252,15 @@ int KRandRSystemTray::GetDefaultResolutionParameter() return returnIndex; } +int KRandRSystemTray::GetHackResolutionParameter() { + int resparm; + + resparm = GetDefaultResolutionParameter(); + resparm++; + + return resparm; +} + void KRandRSystemTray::populateMenu(KPopupMenu* menu) { int lastIndex = 0; @@ -299,9 +334,6 @@ void KRandRSystemTray::populateMenu(KPopupMenu* menu) void KRandRSystemTray::slotResolutionChanged(int parameter) { -// if (currentScreen()->currentSize() == parameter) -// return; - if (currentScreen()->currentSize() == parameter) { //printf("This resolution is already in use; applying again...\n\r"); currentScreen()->proposeSize(parameter); @@ -454,8 +486,8 @@ void KRandRSystemTray::slotCycleDisplays() } } - printf("Active: %d\n\r", current_on_index); - printf("Max: %d\n\r", max_index); + //printf("Active: %d\n\r", current_on_index); + //printf("Max: %d\n\r", max_index); if ((current_on_index == -1) && (max_index == -1)) { // There is no connected display available! ABORT @@ -521,6 +553,12 @@ void KRandRSystemTray::slotCycleDisplays() findPrimaryDisplay(); refresh(); + // HACK + // This is needed because Qt does not properly generate screen + // resize events when switching screens, so KDE gets stuck in the old resolution + currentScreen()->proposeSize(GetHackResolutionParameter()); + currentScreen()->applyProposed(); + currentScreen()->proposeSize(GetDefaultResolutionParameter()); currentScreen()->applyProposed(); } @@ -553,7 +591,7 @@ void KRandRSystemTray::findPrimaryDisplay() output_name = output_info->name; output_id = randr_screen_info->outputs[i]->id; - printf("ACTIVE CHECK: Found output %s\n\r", output_name); + //printf("ACTIVE CHECK: Found output %s\n\r", output_name); randr_screen_info->cur_crtc = randr_screen_info->outputs[i]->cur_crtc; randr_screen_info->cur_output = randr_screen_info->outputs[i]; @@ -695,6 +733,12 @@ void KRandRSystemTray::slotOutputChanged(int parameter) findPrimaryDisplay(); refresh(); + // HACK + // This is needed because Qt does not properly generate screen + // resize events when switching screens, so KDE gets stuck in the old resolution + currentScreen()->proposeSize(GetHackResolutionParameter()); + currentScreen()->applyProposed(); + currentScreen()->proposeSize(GetDefaultResolutionParameter()); currentScreen()->applyProposed(); } diff --git a/kcontrol/randr/krandrtray.h b/kcontrol/randr/krandrtray.h index 9387f8cad..9ce8fe993 100644 --- a/kcontrol/randr/krandrtray.h +++ b/kcontrol/randr/krandrtray.h @@ -43,6 +43,9 @@ public: void configChanged(); +signals: + void screenSizeChanged(int x, int y); + protected slots: void slotScreenActivated(); void slotResolutionChanged(int parameter); @@ -61,6 +64,7 @@ private: void populateMenu(KPopupMenu* menu); void addOutputMenu(KPopupMenu* menu); int GetDefaultResolutionParameter(); + int GetHackResolutionParameter(); void findPrimaryDisplay(); bool m_popupUp; @@ -70,6 +74,9 @@ private: Display *randr_display; ScreenInfo *randr_screen_info; QWidget* my_parent; + + int last_known_x; + int last_known_y; }; #endif -- cgit v1.2.3