summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@nokia.com>2009-07-17 13:40:49 (GMT)
committerVolker Hilsheimer <volker.hilsheimer@nokia.com>2009-07-17 13:43:50 (GMT)
commit13254da6c3192937812983f44ce95fe8e1bc602c (patch)
tree72a1959c25a9ee9f133fad81bf9ee9f3d5b90696 /src/gui
parent83d9c5978fd5089457a28f16be6d26b047d80b7d (diff)
downloadQt-13254da6c3192937812983f44ce95fe8e1bc602c.zip
Qt-13254da6c3192937812983f44ce95fe8e1bc602c.tar.gz
Qt-13254da6c3192937812983f44ce95fe8e1bc602c.tar.bz2
Implement QDesktopWidget::screenCountChanged signal on desktop platforms,
and add manual testcase. Provide replacement "screenCount" for numScreens and document numScreens as obsolete to be more consistent with other APIs.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/kernel/qapplication_x11.cpp13
-rw-r--r--src/gui/kernel/qdesktopwidget.h4
-rw-r--r--src/gui/kernel/qdesktopwidget_mac.mm64
-rw-r--r--src/gui/kernel/qdesktopwidget_mac_p.h3
-rw-r--r--src/gui/kernel/qdesktopwidget_win.cpp18
-rw-r--r--src/gui/kernel/qdesktopwidget_x11.cpp25
6 files changed, 80 insertions, 47 deletions
diff --git a/src/gui/kernel/qapplication_x11.cpp b/src/gui/kernel/qapplication_x11.cpp
index cc41299..a07ccdd 100644
--- a/src/gui/kernel/qapplication_x11.cpp
+++ b/src/gui/kernel/qapplication_x11.cpp
@@ -3441,19 +3441,10 @@ int QApplication::x11ProcessEvent(XEvent* event)
QSize oldSize(w->size());
w->data->crect.setWidth(DisplayWidth(X11->display, scr));
w->data->crect.setHeight(DisplayHeight(X11->display, scr));
- QVarLengthArray<QRect> oldSizes(desktop->numScreens());
- for (int i = 0; i < desktop->numScreens(); ++i)
- oldSizes[i] = desktop->screenGeometry(i);
QResizeEvent e(w->size(), oldSize);
QApplication::sendEvent(w, &e);
- for (int i = 0; i < qMin(oldSizes.count(), desktop->numScreens()); ++i) {
- if (oldSizes[i] != desktop->screenGeometry(i))
- emit desktop->resized(i);
- }
- for (int i = oldSizes.count(); i < desktop->numScreens(); ++i)
- emit desktop->resized(i); // added
- for (int i = desktop->numScreens(); i < oldSizes.count(); ++i)
- emit desktop->resized(i); // removed
+ if (w != desktop)
+ QApplication::sendEvent(desktop, &e);
}
#endif // QT_NO_XRANDR
diff --git a/src/gui/kernel/qdesktopwidget.h b/src/gui/kernel/qdesktopwidget.h
index 470f10a..5ac953c 100644
--- a/src/gui/kernel/qdesktopwidget.h
+++ b/src/gui/kernel/qdesktopwidget.h
@@ -85,6 +85,7 @@ public:
Q_SIGNALS:
void resized(int);
void workAreaResized(int);
+ void screenCountChanged(int);
protected:
void resizeEvent(QResizeEvent *e);
@@ -97,6 +98,9 @@ private:
friend class QApplicationPrivate;
};
+inline int QDesktopWidget::screenCount() const
+{ return numScreens(); }
+
QT_END_NAMESPACE
QT_END_HEADER
diff --git a/src/gui/kernel/qdesktopwidget_mac.mm b/src/gui/kernel/qdesktopwidget_mac.mm
index 2489fe4..7dd74da 100644
--- a/src/gui/kernel/qdesktopwidget_mac.mm
+++ b/src/gui/kernel/qdesktopwidget_mac.mm
@@ -97,15 +97,13 @@ QT_USE_NAMESPACE
Q_GLOBAL_STATIC(QDesktopWidgetImplementation, qdesktopWidgetImplementation)
QDesktopWidgetImplementation::QDesktopWidgetImplementation()
- : appScreen(0), displays(0)
+ : appScreen(0)
{
onResize();
}
QDesktopWidgetImplementation::~QDesktopWidgetImplementation()
{
- if (displays)
- [displays release];
}
QDesktopWidgetImplementation *QDesktopWidgetImplementation::instance()
@@ -118,13 +116,7 @@ QRect QDesktopWidgetImplementation::availableRect(int screenIndex) const
if (screenIndex < 0 || screenIndex >= screenCount)
screenIndex = appScreen;
- NSRect r = [[displays objectAtIndex:screenIndex] visibleFrame];
- NSRect primaryRect = [[displays objectAtIndex:0] frame];
-
- const int flippedY = - r.origin.y + // account for position offset and
- primaryRect.size.height - r.size.height; // height difference.
- return QRectF(r.origin.x, flippedY,
- r.size.width, r.size.height).toRect();
+ return availableRects[screenIndex].toRect();
}
QRect QDesktopWidgetImplementation::screenRect(int screenIndex) const
@@ -132,22 +124,28 @@ QRect QDesktopWidgetImplementation::screenRect(int screenIndex) const
if (screenIndex < 0 || screenIndex >= screenCount)
screenIndex = appScreen;
- NSRect r = [[displays objectAtIndex:screenIndex] frame];
- NSRect primaryRect = [[displays objectAtIndex:0] frame];
-
- const int flippedY = - r.origin.y + // account for position offset and
- primaryRect.size.height - r.size.height; // height difference.
- return QRectF(r.origin.x, flippedY,
- r.size.width, r.size.height).toRect();
+ return screenRects[screenIndex].toRect();
}
void QDesktopWidgetImplementation::onResize()
{
- if (displays)
- [displays release];
-
- displays = [[NSScreen screens] retain];
- screenCount = [displays count];
+ QMacCocoaAutoReleasePool pool;
+ NSArray *displays = [NSScreen screens];
+ screenCount = [displays count];
+
+ screenRects.clear();
+ availableRects.clear();
+ NSRect primaryRect = [[displays objectAtIndex:0] frame];
+ for (int i = 0; i<screenCount; i++) {
+ NSRect r = [[displays objectAtIndex:i] frame];
+ const int flippedY = - r.origin.y + // account for position offset and
+ primaryRect.size.height - r.size.height; // height difference.
+ screenRects.append(QRectF(r.origin.x, flippedY,
+ r.size.width, r.size.height));
+ r = [[displays objectAtIndex:i] visibleFrame];
+ availableRects.append(QRectF(r.origin.x, flippedY,
+ r.size.width, r.size.height));
+ }
}
@@ -195,7 +193,7 @@ const QRect QDesktopWidget::screenGeometry(int screen) const
int QDesktopWidget::screenNumber(const QWidget *widget) const
{
- QDesktopWidgetImplementation *d = qdesktopWidgetImplementation();
+ QDesktopWidgetImplementation *d = qdesktopWidgetImplementation();
if (!widget)
return d->appScreen;
QRect frame = widget->frameGeometry();
@@ -216,7 +214,7 @@ int QDesktopWidget::screenNumber(const QWidget *widget) const
int QDesktopWidget::screenNumber(const QPoint &point) const
{
- QDesktopWidgetImplementation *d = qdesktopWidgetImplementation();
+ QDesktopWidgetImplementation *d = qdesktopWidgetImplementation();
int closestScreen = -1;
int shortestDistance = INT_MAX;
for (int i = 0; i < d->screenCount; ++i) {
@@ -232,13 +230,25 @@ int QDesktopWidget::screenNumber(const QPoint &point) const
void QDesktopWidget::resizeEvent(QResizeEvent *)
{
- QDesktopWidgetImplementation *d = qdesktopWidgetImplementation();
+ QDesktopWidgetImplementation *d = qdesktopWidgetImplementation();
+
+ const int oldScreenCount = d->screenCount;
+ const QVector<QRect> oldRects(d->screenRects);
+ const QVector<QRect> oldWorks(d->availableRects);
d->onResize();
- for (int i = 0; i < d->screenCount; ++i) {
- emit resized(i);
+ for (int i = 0; i < qMin(oldScreenCount, d->screenCount); ++i) {
+ if (oldRects.at(i) != d->screenRects.at(i))
+ emit resized(i);
+ }
+ for (int i = 0; i < qMin(oldScreenCount, d->screenCount); ++i) {
+ if (oldWorks.at(i) != d->availableRects.at(i))
+ emit workAreaResized(i);
}
+
+ if (oldscreencount != d->screenCount)
+ emit screenCountChanged(d->screenCount);
}
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qdesktopwidget_mac_p.h b/src/gui/kernel/qdesktopwidget_mac_p.h
index 0fdc455..e9d5d9f 100644
--- a/src/gui/kernel/qdesktopwidget_mac_p.h
+++ b/src/gui/kernel/qdesktopwidget_mac_p.h
@@ -64,7 +64,8 @@ public:
int appScreen;
int screenCount;
- NSArray *displays;
+ QVector<QRectF> availableRects;
+ QVector<QRectF> screenRects;
QRect availableRect(int screenIndex) const;
QRect screenRect(int screenIndex) const;
diff --git a/src/gui/kernel/qdesktopwidget_win.cpp b/src/gui/kernel/qdesktopwidget_win.cpp
index fb176b7..a89e08f 100644
--- a/src/gui/kernel/qdesktopwidget_win.cpp
+++ b/src/gui/kernel/qdesktopwidget_win.cpp
@@ -354,10 +354,8 @@ int QDesktopWidget::screenNumber(const QPoint &point) const
void QDesktopWidget::resizeEvent(QResizeEvent *)
{
Q_D(QDesktopWidget);
- QVector<QRect> oldrects;
- oldrects = *d->rects;
- QVector<QRect> oldworkrects;
- oldworkrects = *d->workrects;
+ const QVector<QRect> oldrects(*d->rects);
+ const QVector<QRect> oldworkrects(*d->workrects);
int oldscreencount = d->screenCount;
QDesktopWidgetPrivate::cleanup();
@@ -368,18 +366,22 @@ void QDesktopWidget::resizeEvent(QResizeEvent *)
#endif
for (int i = 0; i < qMin(oldscreencount, d->screenCount); ++i) {
- QRect oldrect = oldrects[i];
- QRect newrect = d->rects->at(i);
+ const QRect oldrect = oldrects[i];
+ const QRect newrect = d->rects->at(i);
if (oldrect != newrect)
emit resized(i);
}
for (int j = 0; j < qMin(oldscreencount, d->screenCount); ++j) {
- QRect oldrect = oldworkrects[j];
- QRect newrect = d->workrects->at(j);
+ const QRect oldrect = oldworkrects[j];
+ const QRect newrect = d->workrects->at(j);
if (oldrect != newrect)
emit workAreaResized(j);
}
+
+ if (oldscreencount != d->screenCount) {
+ emit screenCountChanged(d->screenCount);
+ }
}
#ifdef Q_CC_MSVC
diff --git a/src/gui/kernel/qdesktopwidget_x11.cpp b/src/gui/kernel/qdesktopwidget_x11.cpp
index 59d3239..1555fc0 100644
--- a/src/gui/kernel/qdesktopwidget_x11.cpp
+++ b/src/gui/kernel/qdesktopwidget_x11.cpp
@@ -372,7 +372,32 @@ int QDesktopWidget::screenNumber(const QPoint &point) const
void QDesktopWidget::resizeEvent(QResizeEvent *event)
{
Q_D(QDesktopWidget);
+ int oldScreenCount = d->screenCount;
+ QVector<QRect> oldRects(oldScreenCount);
+ QVector<QRect> oldWorks(oldScreenCount);
+ for (int i = 0; i < oldScreenCount; ++i) {
+ oldRects[i] = d->rects[i];
+ oldWorks[i] = d->workareas[i];
+ }
+
d->init();
+
+ for (int i = 0; i < qMin(oldScreenCount, d->screenCount); ++i) {
+ if (oldRects.at(i) != d->rects[i])
+ emit resized(i);
+ }
+
+ // ### workareas are just reset by init, not filled with new values
+ // ### so this will not work correctly
+ for (int j = 0; j < qMin(oldScreenCount, d->screenCount); ++j) {
+ if (oldWorks.at(j) != d->workareas[j])
+ emit workAreaResized(j);
+ }
+
+ if (oldScreenCount != d->screenCount) {
+ emit screenCountChanged(d->screenCount);
+ }
+
qt_desktopwidget_workarea_dirty = true;
QWidget::resizeEvent(event);
}