Skip to content

Commit

Permalink
Revert "Revert "Fixes: NB#231615 - Status indicators are updated when…
Browse files Browse the repository at this point in the history
… display is on but the frontmost window does not contain a status area""

This reverts commit c796bf7.
  • Loading branch information
Eetu Lehmusvuo committed Apr 4, 2011
1 parent 693d523 commit b123961
Show file tree
Hide file tree
Showing 17 changed files with 272 additions and 36 deletions.
79 changes: 72 additions & 7 deletions src/systemui/statusarea/statusarearenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@

#include <QDebug>
#include "statusarearenderer.h"
#include "statusarea.h"
#include <MOnDisplayChangeEvent>
#include <MStyle>
#include "statusareastyle.h"
#include <QX11Info>
#include "x11wrapper.h"
#include <QMeeGoLivePixmap>
#include <QMeeGoGraphicsSystemHelper>
#include <QX11Info>
#include "x11wrapper.h"

// Update the pixmap 5 times per second at most
static const int ACCUMULATION_INTERVAL = 200;
Expand All @@ -37,6 +35,8 @@ StatusAreaRenderer::StatusAreaRenderer(QObject *parent) :
statusArea(new StatusArea),
statusAreaLivePixmap(NULL),
statusAreaPropertyWindow(0),
windowManagerWindow(0),
statusBarVisible(false),
#ifdef HAVE_QMSYSTEM
displayState(new MeeGo::QmDisplayState()),
#endif
Expand All @@ -54,13 +54,19 @@ StatusAreaRenderer::StatusAreaRenderer(QObject *parent) :
connect(displayState, SIGNAL(displayStateChanged(MeeGo::QmDisplayState::DisplayState)), this, SLOT(setSceneRender(MeeGo::QmDisplayState::DisplayState)));
setSceneRender(displayState->get());
#endif

statusBarVisibleAtom = X11Wrapper::XInternAtom(QX11Info::display(), "_MEEGOTOUCH_STATUSBAR_VISIBLE", False);
windowManagerWindowAtom = X11Wrapper::XInternAtom(QX11Info::display(), "_NET_SUPPORTING_WM_CHECK", False);

setSizeFromStyle();
if(!createSharedPixmapHandle() || !createBackPixmap()) {
qWarning() << "Shared Pixmap was not created. Status area will not render";
} else {
createStatusAreaPropertyWindow();
setSharedPixmapHandleToWindowProperty();
setStatusAreaPropertyWindowIdToRootWindowProperty();

setupStatusBarVisibleListener();
}

connect(&accumulationTimer, SIGNAL(timeout()), this, SLOT(renderAccumulatedRegion()));
Expand Down Expand Up @@ -177,6 +183,8 @@ void StatusAreaRenderer::setSharedPixmapHandleToWindowProperty()

StatusAreaRenderer::~StatusAreaRenderer()
{
XEventListener::unregisterEventFilter(this);

scene->removeItem(statusArea);
delete statusArea;

Expand Down Expand Up @@ -212,7 +220,7 @@ void StatusAreaRenderer::accumulateSceneChanges(const QList<QRectF> &region)
accumulatedRegion = accumulatedRegion.united(r);
}

if (renderScene && !accumulationTimer.isActive()) {
if (statusBarVisible && renderScene && !accumulationTimer.isActive()) {
accumulationTimer.setSingleShot(true);
accumulationTimer.start(ACCUMULATION_INTERVAL);
}
Expand All @@ -221,7 +229,6 @@ void StatusAreaRenderer::accumulateSceneChanges(const QList<QRectF> &region)
void StatusAreaRenderer::renderAccumulatedRegion()
{
if (!accumulatedRegion.isEmpty() && !statusAreaPixmap.isNull() && !backPixmap.isNull()) {

if (statusAreaLivePixmap && !QMeeGoGraphicsSystemHelper::isRunningMeeGo()) {
QMeeGoGraphicsSystemHelper::switchToMeeGo();
}
Expand Down Expand Up @@ -260,9 +267,67 @@ void StatusAreaRenderer::renderAccumulatedRegion()
painter.drawPixmap(sourceRect, backPixmap, sourceRect);
painter.end();
}
accumulatedRegion = QRectF(0.0f, 0.0f, 0.0f, 0.0f);
}
}


accumulatedRegion = QRectF(0.0f, 0.0f, 0.0f, 0.0f);
void StatusAreaRenderer::setupStatusBarVisibleListener()
{
Atom type;
int format;
unsigned long length, after;
uchar *data = 0;

bool success = false;
if (X11Wrapper::XGetWindowProperty(QX11Info::display(), QX11Info::appRootWindow(), windowManagerWindowAtom,
0, 1024, False, XA_WINDOW, &type, &format, &length, &after, &data) == Success) {
if (type == XA_WINDOW && format == 32) {
windowManagerWindow = *((Window*) data);
X11Wrapper::XFree(data);

success = getStatusBarVisibleProperty();
}
}

if (success) {
XEventListener::registerEventFilter(this, PropertyChangeMask);
} else {
// Assume status bar is visible when WM window or _MEEGOTOUCH_STATUSBAR_VISIBLE property are not available
statusBarVisible = true;
XEventListener::unregisterEventFilter(this);
}
}

bool StatusAreaRenderer::getStatusBarVisibleProperty()
{
Atom type;
int format;
unsigned long length, after;
uchar *data = 0;

bool success = false;
if (X11Wrapper::XGetWindowProperty(QX11Info::display(), windowManagerWindow, statusBarVisibleAtom,
0, 1024, False, XA_CARDINAL, &type, &format, &length, &after, &data) == Success) {
if (type == XA_CARDINAL) {
statusBarVisible = *data;
X11Wrapper::XFree(data);
X11Wrapper::XSelectInput(QX11Info::display(), windowManagerWindow, PropertyChangeMask);
success = true;
}
}
return success;
}

bool StatusAreaRenderer::xEventFilter(const XEvent &event)
{
if (event.xproperty.window == windowManagerWindow && event.xproperty.atom == statusBarVisibleAtom) {
if (!getStatusBarVisibleProperty()) {
// Fetching property failed so try setuping the window and property again
setupStatusBarVisibleListener();
}
}
return false;
}

#ifdef HAVE_QMSYSTEM
Expand Down
33 changes: 28 additions & 5 deletions src/systemui/statusarea/statusarearenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

#include <MNamespace>
#include <QTimer>
#include <MOnDisplayChangeEvent>
#include "statusarea.h"
#include "xeventlistener.h"

#ifdef HAVE_QMSYSTEM
#include "qmdisplaystate.h"
Expand All @@ -34,7 +37,7 @@ class QMeeGoLivePixmap;
/*!
* StatusAreaRenderer renders the contents of the scene to a shared pixmap which is then shown by libmeegotouch.
*/
class StatusAreaRenderer : public QObject
class StatusAreaRenderer : public QObject, XEventListenerFilterInterface
{
Q_OBJECT

Expand All @@ -57,8 +60,14 @@ class StatusAreaRenderer : public QObject
*/
uint sharedPixmapHandle();

/*!
* X event filter for _MEEGOTOUCH_STATUSBAR_VISIBLE changes
*/
bool xEventFilter(const XEvent &event);

private slots:
/*!

/*!
* \brief Combine the given regions into one and start a timer to draw the region
*/
virtual void accumulateSceneChanges(const QList<QRectF> &region);
Expand All @@ -83,6 +92,11 @@ private slots:
void statusIndicatorMenuVisibilityChanged(bool visible);

private:
//! Setups listening of statusbar visibility from WM window property
void setupStatusBarVisibleListener();

//! Fetches the _MEEGOTOUCH_STATUSBAR_VISIBLE value from WM window property
bool getStatusBarVisibleProperty();

//! Creates a window for sharing shared pixmap handle.
void createStatusAreaPropertyWindow();
Expand All @@ -103,7 +117,7 @@ private slots:
QPixmap statusAreaPixmap;
//! Back buffer pixmap - the content is first rendered here and then copied to the shared pixmap
QPixmap backPixmap;
// Used for better performance if MeeGo graphics system is available, wrapped by backPixmap
//! Used for better performance if MeeGo graphics system is available, wrapped by backPixmap
QMeeGoLivePixmap* statusAreaLivePixmap;

//! Creates a shared pixmap for status area
Expand All @@ -115,14 +129,18 @@ private slots:
//! set the status bar size with information from style
void setSizeFromStyle();

// TODO: resolve why #include <X11/Xlib.h> in header results in compilation error
//! Window id for the status area property window.
ulong statusAreaPropertyWindow;
Window statusAreaPropertyWindow;
//! Window id of the window manager window
Window windowManagerWindow;

//! Status Area dimensions.
uint statusAreaHeight;
uint statusAreaWidth;

//! Whether status bar is currently visible according to compositor
bool statusBarVisible;

#ifdef HAVE_QMSYSTEM
//! Keep track of device display state
MeeGo::QmDisplayState* displayState;
Expand All @@ -136,6 +154,11 @@ private slots:
//! Changes in the scene are combined to this rect
QRectF accumulatedRegion;

//! _MEEGOTOUCH_STATUSBAR_VISIBLE atom
Atom statusBarVisibleAtom;
//! _NET_SUPPORTING_WM_CHECK atom
Atom windowManagerWindowAtom;

#ifdef UNIT_TEST
friend class Ut_StatusAreaRenderer;
#endif
Expand Down
3 changes: 2 additions & 1 deletion src/systemui/sysuid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
**
****************************************************************************/


#include <MLocale>
#include <MTheme>
#include <MLocale>
Expand All @@ -27,10 +28,10 @@
#include "sysuid.h"
#include "sysuidrequest.h"
#include "batterybusinesslogic.h"
#include "statusarearendereradaptor.h"
#include "screenlockbusinesslogic.h"
#include "shutdownbusinesslogic.h"
#include "statusarearenderer.h"
#include "statusarearendereradaptor.h"
#include "statusindicatormenubusinesslogic.h"
#include "statusindicatormenuadaptor.h"
#include "notificationmanager.h"
Expand Down
1 change: 1 addition & 0 deletions src/systemui/xeventlistener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "xeventlistener.h"

#include <QSharedPointer>
#include <X11/X.h>

static long maskMap[LASTEvent];

Expand Down
3 changes: 1 addition & 2 deletions src/systemui/xeventlistener.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
#include <QHash>
#include <QObject>
#include <QAbstractEventDispatcher>
#include <QX11Info>
#include "x11wrapper.h"
#include <X11/Xlib.h>

/*!
* An interface for classes registering to XEventListener.
Expand Down
32 changes: 32 additions & 0 deletions tests/stubs/statusarearenderer_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class StatusAreaRendererStub : public StubBase {
virtual void createStatusAreaPropertyWindow();
virtual void setStatusAreaPropertyWindowIdToRootWindowProperty();
virtual void setSharedPixmapHandleToWindowProperty();
virtual void setupStatusBarVisibleListener();
virtual bool getStatusBarVisibleProperty();
virtual bool xEventFilter(const XEvent &event);
};

// 2. IMPLEMENT STUB
Expand Down Expand Up @@ -82,6 +85,23 @@ void StatusAreaRendererStub::setSharedPixmapHandleToWindowProperty() {
stubMethodEntered("setSharedPixmapHandleToWindowProperty");
}

void StatusAreaRendererStub::setupStatusBarVisibleListener() {
stubMethodEntered("setupStatusBarVisibleListener");
}

bool StatusAreaRendererStub::getStatusBarVisibleProperty() {
stubMethodEntered("getStatusBarVisibleProperty");
return stubReturnValue<bool>("getStatusBarVisibleProperty");
}


bool StatusAreaRendererStub::xEventFilter(const XEvent &event) {
QList<ParameterBase*> params;
params.append( new Parameter<XEvent>(event));
stubMethodEntered("xEventFilter");
return stubReturnValue<bool>("xEventFilter");
}

// 3. CREATE A STUB INSTANCE
StatusAreaRendererStub gDefaultStatusAreaRendererStub;
StatusAreaRendererStub* gStatusAreaRendererStub = &gDefaultStatusAreaRendererStub;
Expand Down Expand Up @@ -139,4 +159,16 @@ void StatusAreaRenderer::setSharedPixmapHandleToWindowProperty() {
gStatusAreaRendererStub->setSharedPixmapHandleToWindowProperty();
}

void StatusAreaRenderer::setupStatusBarVisibleListener() {
gStatusAreaRendererStub->setupStatusBarVisibleListener();
}

bool StatusAreaRenderer::getStatusBarVisibleProperty() {
return gStatusAreaRendererStub->getStatusBarVisibleProperty();
}

bool StatusAreaRenderer::xEventFilter(const XEvent &event) {
return gStatusAreaRendererStub->xEventFilter(event);
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "x11wrapper.h"
#include <stubbase.h>

struct XGetWindowPropertyDataReturnValueData;

// 1. DECLARE STUB
// FIXME - stubgen is not yet finished
Expand Down Expand Up @@ -51,6 +52,8 @@ class X11WrapperStub : public StubBase
virtual int XGrabPointer(Display *display, Window grab_window, Bool owner_events, unsigned int event_mask,
int pointer_mode, int keyboard_mode, Window confine_to, Cursor cursor, Time time);
virtual int XDeleteProperty(Display *display, Window w, Atom property);

virtual void stubSetXGetWindowPropertyDataReturnValues(Window window, XGetWindowPropertyDataReturnValueData data);
};

// 2. IMPLEMENT STUB
Expand Down Expand Up @@ -91,6 +94,17 @@ Status X11WrapperStub::XGetWindowAttributes(Display *display, Window w, XWindowA
return stubReturnValue<Status>("XGetWindowAttributes");
}

struct XGetWindowPropertyDataReturnValueData {
Atom type;
int format;
unsigned char* data;
};
QHash<Window, XGetWindowPropertyDataReturnValueData> xGetWindowPropertyDataReturnValueHash;
void X11WrapperStub::stubSetXGetWindowPropertyDataReturnValues(Window window, XGetWindowPropertyDataReturnValueData data)
{
xGetWindowPropertyDataReturnValueHash.insert(window, data);
}

int X11WrapperStub::XGetWindowProperty(Display *display, Window w, Atom property, long long_offset, long long_length, Bool del, Atom req_type, Atom *actual_type_return, int *actual_format_return, unsigned long *nitems_return, unsigned long *bytes_after_return, unsigned char **prop_return)
{
QList<ParameterBase *> params;
Expand All @@ -107,6 +121,12 @@ int X11WrapperStub::XGetWindowProperty(Display *display, Window w, Atom property
params.append(new Parameter<unsigned long * >(bytes_after_return));
params.append(new Parameter<unsigned char ** >(prop_return));
stubMethodEntered("XGetWindowProperty", params);

XGetWindowPropertyDataReturnValueData data = xGetWindowPropertyDataReturnValueHash.value(w);
*actual_type_return = data.type;
*actual_format_return = data.format;
*prop_return = data.data;

return stubReturnValue<int>("XGetWindowProperty");
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ut_eventeater/ut_eventeater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <MApplication>
#include <MWindow>
#include <QWidget>
#include "x11wrapper_stub.h"
#include "x11wrapper_modified_stub.h"
#include "xeventlistener_stub.h"

// QWidget stubs
Expand Down
2 changes: 1 addition & 1 deletion tests/ut_screenlockwindow/ut_screenlockwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "notificationsink_stub.h"
#include "sysuid_stub.h"
#include <X11/Xutil.h>
#include "x11wrapper_stub.h"
#include "x11wrapper_modified_stub.h"

// X stubs to avoid crashes
void XSetWMProperties(Display *, Window, XTextProperty *, XTextProperty *, char **, int, XSizeHints *, XWMHints *, XClassHint *)
Expand Down
2 changes: 1 addition & 1 deletion tests/ut_shutdownui/ut_shutdownui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <QtTest/QtTest>
#include "ut_shutdownui.h"
#include "shutdownui.h"
#include "x11wrapper_stub.h"
#include "x11wrapper_modified_stub.h"

#include <MApplication>
#include <MWindow>
Expand Down
Loading

0 comments on commit b123961

Please sign in to comment.