2008-04-19 19:41:14 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim:expandtab:shiftwidth=4:tabstop=4:
|
|
|
|
*/
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2008-04-19 19:41:14 +04:00
|
|
|
|
2012-03-23 03:24:40 +04:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
#include "mozilla/X11Util.h"
|
2010-09-10 03:46:25 +04:00
|
|
|
#endif
|
2008-04-19 19:41:14 +04:00
|
|
|
#include "nsIdleServiceQt.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "prlink.h"
|
|
|
|
|
2011-08-24 20:15:58 +04:00
|
|
|
#if !defined(MOZ_PLATFORM_MAEMO) && defined(MOZ_X11)
|
2011-09-29 10:19:26 +04:00
|
|
|
typedef bool (*_XScreenSaverQueryExtension_fn)(Display* dpy, int* event_base,
|
2008-04-19 19:41:14 +04:00
|
|
|
int* error_base);
|
|
|
|
|
|
|
|
typedef XScreenSaverInfo* (*_XScreenSaverAllocInfo_fn)(void);
|
|
|
|
|
|
|
|
typedef void (*_XScreenSaverQueryInfo_fn)(Display* dpy, Drawable drw,
|
|
|
|
XScreenSaverInfo *info);
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
static _XScreenSaverQueryExtension_fn _XSSQueryExtension = nullptr;
|
|
|
|
static _XScreenSaverAllocInfo_fn _XSSAllocInfo = nullptr;
|
|
|
|
static _XScreenSaverQueryInfo_fn _XSSQueryInfo = nullptr;
|
2010-09-10 03:46:25 +04:00
|
|
|
#endif
|
2008-04-19 19:41:14 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool sInitialized = false;
|
2008-04-19 19:41:14 +04:00
|
|
|
|
2012-06-29 12:32:21 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(nsIdleServiceQt, nsIdleService)
|
2008-04-19 19:41:14 +04:00
|
|
|
|
|
|
|
nsIdleServiceQt::nsIdleServiceQt()
|
2011-08-24 20:15:58 +04:00
|
|
|
#if !defined(MOZ_PLATFORM_MAEMO) && defined(MOZ_X11)
|
2012-07-30 18:20:58 +04:00
|
|
|
: mXssInfo(nullptr)
|
2010-09-10 03:46:25 +04:00
|
|
|
#endif
|
2008-04-19 19:41:14 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Initialize()
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
sInitialized = true;
|
2008-04-19 19:41:14 +04:00
|
|
|
|
2011-08-24 20:15:58 +04:00
|
|
|
#if !defined(MOZ_PLATFORM_MAEMO) && defined(MOZ_X11)
|
2008-04-19 19:41:14 +04:00
|
|
|
// This will leak - See comments in ~nsIdleServiceQt().
|
|
|
|
PRLibrary* xsslib = PR_LoadLibrary("libXss.so.1");
|
|
|
|
if (!xsslib) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_XSSQueryExtension = (_XScreenSaverQueryExtension_fn)
|
|
|
|
PR_FindFunctionSymbol(xsslib, "XScreenSaverQueryExtension");
|
|
|
|
_XSSAllocInfo = (_XScreenSaverAllocInfo_fn)
|
|
|
|
PR_FindFunctionSymbol(xsslib, "XScreenSaverAllocInfo");
|
|
|
|
_XSSQueryInfo = (_XScreenSaverQueryInfo_fn)
|
|
|
|
PR_FindFunctionSymbol(xsslib, "XScreenSaverQueryInfo");
|
2010-09-10 03:46:25 +04:00
|
|
|
#endif
|
2008-04-19 19:41:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIdleServiceQt::~nsIdleServiceQt()
|
|
|
|
{
|
2011-08-24 20:15:58 +04:00
|
|
|
#if !defined(MOZ_PLATFORM_MAEMO) && defined(MOZ_X11)
|
2008-04-19 19:41:14 +04:00
|
|
|
if (mXssInfo)
|
|
|
|
XFree(mXssInfo);
|
|
|
|
|
|
|
|
// It is not safe to unload libXScrnSaver until each display is closed because
|
|
|
|
// the library registers callbacks through XESetCloseDisplay (Bug 397607).
|
|
|
|
// (Also the library and its functions are scoped for the file not the object.)
|
|
|
|
#if 0
|
|
|
|
if (xsslib) {
|
|
|
|
PR_UnloadLibrary(xsslib);
|
2012-07-30 18:20:58 +04:00
|
|
|
xsslib = nullptr;
|
2008-04-19 19:41:14 +04:00
|
|
|
}
|
|
|
|
#endif
|
2010-09-10 03:46:25 +04:00
|
|
|
#endif
|
2008-04-19 19:41:14 +04:00
|
|
|
}
|
|
|
|
|
2010-04-16 21:37:16 +04:00
|
|
|
bool
|
|
|
|
nsIdleServiceQt::PollIdleTime(PRUint32 *aIdleTime)
|
2008-04-19 19:41:14 +04:00
|
|
|
{
|
2011-08-24 20:15:58 +04:00
|
|
|
#if !defined(MOZ_PLATFORM_MAEMO) && defined(MOZ_X11)
|
2008-04-19 19:41:14 +04:00
|
|
|
// Ask xscreensaver about idle time:
|
2010-04-16 21:37:16 +04:00
|
|
|
*aIdleTime = 0;
|
2008-04-19 19:41:14 +04:00
|
|
|
|
|
|
|
// We might not have a display (cf. in xpcshell)
|
2012-03-23 03:24:40 +04:00
|
|
|
Display *dplay = mozilla::DefaultXDisplay();
|
2008-04-19 19:41:14 +04:00
|
|
|
if (!dplay) {
|
2010-04-16 21:37:16 +04:00
|
|
|
return false;
|
2008-04-19 19:41:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!sInitialized) {
|
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
if (!_XSSQueryExtension || !_XSSAllocInfo || !_XSSQueryInfo) {
|
2010-04-16 21:37:16 +04:00
|
|
|
return false;
|
2008-04-19 19:41:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int event_base, error_base;
|
|
|
|
if (_XSSQueryExtension(dplay, &event_base, &error_base)) {
|
|
|
|
if (!mXssInfo)
|
|
|
|
mXssInfo = _XSSAllocInfo();
|
|
|
|
if (!mXssInfo)
|
2010-04-16 21:37:16 +04:00
|
|
|
return false;
|
2008-04-19 19:41:14 +04:00
|
|
|
|
2012-03-23 03:24:40 +04:00
|
|
|
_XSSQueryInfo(dplay, RootWindowOfScreen(DefaultScreenOfDisplay(mozilla::DefaultXDisplay())), mXssInfo);
|
2010-04-16 21:37:16 +04:00
|
|
|
*aIdleTime = mXssInfo->idle;
|
|
|
|
return true;
|
2008-04-19 19:41:14 +04:00
|
|
|
}
|
2010-09-10 03:46:25 +04:00
|
|
|
#endif
|
2008-04-19 19:41:14 +04:00
|
|
|
|
2010-04-16 21:37:16 +04:00
|
|
|
return false;
|
2008-04-19 19:41:14 +04:00
|
|
|
}
|
2010-04-16 21:37:16 +04:00
|
|
|
|
|
|
|
bool
|
|
|
|
nsIdleServiceQt::UsePollMode()
|
|
|
|
{
|
2011-08-24 20:15:58 +04:00
|
|
|
#if !defined(MOZ_PLATFORM_MAEMO) && defined(MOZ_X11)
|
2010-09-10 03:46:25 +04:00
|
|
|
return false;
|
|
|
|
#endif
|
2010-04-16 21:37:16 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|