Bug 511037 - Maemo/OSSO idle service does not work per spec. r=stuart

This commit is contained in:
Doug Turner 2009-09-17 10:13:45 -07:00
parent 6d83cdc84a
commit 5745b161d2
6 changed files with 49 additions and 171 deletions

View File

@ -81,13 +81,9 @@ CPPSRCS = \
nsAccelerometerUnix.cpp \
$(NULL)
ifdef NS_OSSO
CPPSRCS += nsIdleServiceOSSO.cpp
else
ifdef MOZ_X11
CPPSRCS += nsIdleServiceGTK.cpp
endif
endif
ifdef NS_PRINTING
CPPSRCS += \

View File

@ -65,19 +65,8 @@ static _XScreenSaverQueryInfo_fn _XSSQueryInfo = nsnull;
NS_IMPL_ISUPPORTS1(nsIdleServiceGTK, nsIIdleService)
nsIdleServiceGTK::nsIdleServiceGTK()
: mXssInfo(nsnull)
{
#ifdef PR_LOGGING
if (!sIdleLog)
sIdleLog = PR_NewLogModule("nsIIdleService");
#endif
}
static void Initialize()
{
sInitialized = PR_TRUE;
// This will leak - See comments in ~nsIdleServiceGTK().
PRLibrary* xsslib = PR_LoadLibrary("libXss.so.1");
if (!xsslib) // ouch.
@ -102,6 +91,19 @@ static void Initialize()
if (!_XSSQueryInfo)
PR_LOG(sIdleLog, PR_LOG_WARNING, ("Failed to get XSSQueryInfo!\n"));
#endif
sInitialized = PR_TRUE;
}
nsIdleServiceGTK::nsIdleServiceGTK()
: mXssInfo(nsnull)
{
#ifdef PR_LOGGING
if (!sIdleLog)
sIdleLog = PR_NewLogModule("nsIIdleService");
#endif
Initialize();
}
nsIdleServiceGTK::~nsIdleServiceGTK()
@ -123,6 +125,23 @@ nsIdleServiceGTK::~nsIdleServiceGTK()
NS_IMETHODIMP
nsIdleServiceGTK::GetIdleTime(PRUint32 *aTimeDiff)
{
if (!sInitialized) {
// For some reason, we could not find xscreensaver. This this might be because
// we are on a mobile platforms (e.g. Maemo/OSSO). In this case, fall back to
// using gLastInputEventTime which is
// The last user input event time in microseconds. If there are any pending
// native toolkit input events it returns the current time. The value is
// compatible with PR_IntervalToMicroseconds(PR_IntervalNow()).
// DEFINED IN widget/src/gtk2/nsWindow.cpp
extern PRUint32 gLastInputEventTime;
PRUint32 nowTime = PR_IntervalToMicroseconds(PR_IntervalNow());
*aTimeDiff = (nowTime - gLastInputEventTime) / 1000;
return NS_OK;
}
// Ask xscreensaver about idle time:
*aTimeDiff = 0;
@ -135,9 +154,6 @@ nsIdleServiceGTK::GetIdleTime(PRUint32 *aTimeDiff)
return NS_ERROR_FAILURE;
}
if (!sInitialized) {
Initialize();
}
if (!_XSSQueryExtension || !_XSSAllocInfo || !_XSSQueryInfo) {
return NS_ERROR_FAILURE;
}

View File

@ -1,82 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Idle Service for OSSO.
*
* The Initial Developer of the Original Code is Mozilla Corporation
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Doug Turner <dougt@meer.net> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsIdleServiceOSSO.h"
#include "nsIObserverService.h"
#include "nsServiceManagerUtils.h"
#include "prtime.h"
#include <gtk/gtk.h>
NS_IMPL_ISUPPORTS2(nsIdleServiceOSSO, nsIIdleService, nsIObserver)
nsIdleServiceOSSO::nsIdleServiceOSSO()
: mIdle(PR_FALSE)
{
nsCOMPtr<nsIObserverService> obsServ = do_GetService("@mozilla.org/observer-service;1");
obsServ->AddObserver(this, "system-display-on", PR_FALSE);
obsServ->AddObserver(this, "system-display-dimmed-or-off", PR_FALSE);
}
nsIdleServiceOSSO::~nsIdleServiceOSSO()
{
}
NS_IMETHODIMP
nsIdleServiceOSSO::GetIdleTime(PRUint32 *aTimeDiff)
{
if (mIdle) {
*aTimeDiff = ( PR_Now() - mIdleSince ) / PR_USEC_PER_MSEC;
return NS_OK;
}
*aTimeDiff = 0;
return NS_OK;
}
NS_IMETHODIMP
nsIdleServiceOSSO::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)
{
if (!strcmp(aTopic, "system-display-dimmed-or-off") && mIdle == PR_FALSE) {
mIdle = PR_TRUE;
mIdleSince = PR_Now();
}
else if (!strcmp(aTopic, "system-display-on")) {
mIdle = PR_FALSE;
}
return NS_OK;
}

View File

@ -1,59 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Idle Service for OSSO.
*
* The Initial Developer of the Original Code is Mozilla Corporation
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Doug Turner <dougt@meer.net> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsIdleServiceOSSO_h__
#define nsIdleServiceOSSO_h__
#include "nsIdleService.h"
#include "nsIObserver.h"
class nsIdleServiceOSSO : public nsIdleService, public nsIObserver
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
nsIdleServiceOSSO();
NS_IMETHOD GetIdleTime(PRUint32* idleTime);
private:
~nsIdleServiceOSSO();
PRBool mIdle;
PRTime mIdleSince;
};
#endif // nsIdleServiceOSSO_h__

View File

@ -68,9 +68,7 @@
#include "nsImageToPixbuf.h"
#include "nsPrintDialogGTK.h"
#if defined(NS_OSSO)
#include "nsIdleServiceOSSO.h"
#elif defined(MOZ_X11)
#if defined(MOZ_X11)
#include "nsIdleServiceGTK.h"
#endif
@ -140,9 +138,7 @@ nsNativeThemeGTKConstructor(nsISupports *aOuter, REFNSIID aIID,
}
#endif
#if defined(NS_OSSO)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsIdleServiceOSSO)
#elif defined(MOZ_X11)
#if defined(MOZ_X11)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsIdleServiceGTK)
#endif
@ -339,12 +335,7 @@ static const nsModuleComponentInfo components[] =
NS_IMAGE_TO_PIXBUF_CID,
"@mozilla.org/widget/image-to-gdk-pixbuf;1",
nsImageToPixbufConstructor },
#if defined(NS_OSSO)
{ "User Idle Service",
NS_IDLE_SERVICE_CID,
"@mozilla.org/widget/idleservice;1",
nsIdleServiceOSSOConstructor },
#elif defined(MOZ_X11)
#if defined(MOZ_X11)
{ "User Idle Service",
NS_IDLE_SERVICE_CID,
"@mozilla.org/widget/idleservice;1",

View File

@ -261,6 +261,8 @@ static PRBool gdk_keyboard_get_modmap_masks(Display* aDisplay,
/* initialization static functions */
static nsresult initialize_prefs (void);
PRUint32 gLastInputEventTime = 0;
// this is the last window that had a drag event happen on it.
nsWindow *nsWindow::mLastDragMotionWindow = NULL;
PRBool nsWindow::sIsDraggingOutOf = PR_FALSE;
@ -443,6 +445,8 @@ nsWindow::nsWindow()
gBufferPixmapUsageCount++;
}
// Set gLastInputEventTime to some valid number
gLastInputEventTime = PR_IntervalToMicroseconds(PR_IntervalNow());
}
nsWindow::~nsWindow()
@ -5472,6 +5476,8 @@ GetFirstNSWindowForGDKWindow(GdkWindow *aGdkWindow)
gboolean
motion_notify_event_cb(GtkWidget *widget, GdkEventMotion *event)
{
gLastInputEventTime = PR_IntervalToMicroseconds(PR_IntervalNow());
nsWindow *window = GetFirstNSWindowForGDKWindow(event->window);
if (!window)
return FALSE;
@ -5488,6 +5494,8 @@ motion_notify_event_cb(GtkWidget *widget, GdkEventMotion *event)
gboolean
button_press_event_cb(GtkWidget *widget, GdkEventButton *event)
{
gLastInputEventTime = PR_IntervalToMicroseconds(PR_IntervalNow());
nsWindow *window = GetFirstNSWindowForGDKWindow(event->window);
if (!window)
return FALSE;
@ -5501,6 +5509,8 @@ button_press_event_cb(GtkWidget *widget, GdkEventButton *event)
gboolean
button_release_event_cb(GtkWidget *widget, GdkEventButton *event)
{
gLastInputEventTime = PR_IntervalToMicroseconds(PR_IntervalNow());
nsWindow *window = GetFirstNSWindowForGDKWindow(event->window);
if (!window)
return FALSE;
@ -5636,6 +5646,9 @@ gboolean
key_press_event_cb(GtkWidget *widget, GdkEventKey *event)
{
LOG(("key_press_event_cb\n"));
gLastInputEventTime = PR_IntervalToMicroseconds(PR_IntervalNow());
// find the window with focus and dispatch this event to that widget
nsWindow *window = get_window_for_gtk_widget(widget);
if (!window)
@ -5676,6 +5689,9 @@ gboolean
key_release_event_cb(GtkWidget *widget, GdkEventKey *event)
{
LOG(("key_release_event_cb\n"));
gLastInputEventTime = PR_IntervalToMicroseconds(PR_IntervalNow());
// find the window with focus and dispatch this event to that widget
nsWindow *window = get_window_for_gtk_widget(widget);
if (!window)