2008-04-19 15:41:14 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim:expandtab:shiftwidth=4:tabstop=4:
|
|
|
|
*/
|
2012-05-21 11:12:37 +00: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 15:41:14 +00:00
|
|
|
|
2012-03-22 23:24:40 +00:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
#include "mozilla/X11Util.h"
|
2010-09-09 23:46:25 +00:00
|
|
|
#endif
|
2008-04-19 15:41:14 +00:00
|
|
|
#include "nsIdleServiceQt.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "prlink.h"
|
|
|
|
|
2013-08-25 23:56:53 +00:00
|
|
|
#if defined(MOZ_X11)
|
2011-09-29 06:19:26 +00:00
|
|
|
typedef bool (*_XScreenSaverQueryExtension_fn)(Display* dpy, int* event_base,
|
2008-04-19 15:41:14 +00:00
|
|
|
int* error_base);
|
|
|
|
|
|
|
|
typedef XScreenSaverInfo* (*_XScreenSaverAllocInfo_fn)(void);
|
|
|
|
|
|
|
|
typedef void (*_XScreenSaverQueryInfo_fn)(Display* dpy, Drawable drw,
|
|
|
|
XScreenSaverInfo *info);
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
static _XScreenSaverQueryExtension_fn _XSSQueryExtension = nullptr;
|
|
|
|
static _XScreenSaverAllocInfo_fn _XSSAllocInfo = nullptr;
|
|
|
|
static _XScreenSaverQueryInfo_fn _XSSQueryInfo = nullptr;
|
2010-09-09 23:46:25 +00:00
|
|
|
#endif
|
2008-04-19 15:41:14 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool sInitialized = false;
|
2008-04-19 15:41:14 +00:00
|
|
|
|
2012-06-29 08:32:21 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(nsIdleServiceQt, nsIdleService)
|
2008-04-19 15:41:14 +00:00
|
|
|
|
|
|
|
nsIdleServiceQt::nsIdleServiceQt()
|
2013-08-25 23:56:53 +00:00
|
|
|
#if defined(MOZ_X11)
|
2012-07-30 14:20:58 +00:00
|
|
|
: mXssInfo(nullptr)
|
2010-09-09 23:46:25 +00:00
|
|
|
#endif
|
2008-04-19 15:41:14 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Initialize()
|
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
sInitialized = true;
|
2008-04-19 15:41:14 +00:00
|
|
|
|
2013-08-25 23:56:53 +00:00
|
|
|
#if defined(MOZ_X11)
|
2008-04-19 15:41:14 +00: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-09 23:46:25 +00:00
|
|
|
#endif
|
2008-04-19 15:41:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIdleServiceQt::~nsIdleServiceQt()
|
|
|
|
{
|
2013-08-25 23:56:53 +00:00
|
|
|
#if defined(MOZ_X11)
|
2008-04-19 15:41:14 +00: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 14:20:58 +00:00
|
|
|
xsslib = nullptr;
|
2008-04-19 15:41:14 +00:00
|
|
|
}
|
|
|
|
#endif
|
2010-09-09 23:46:25 +00:00
|
|
|
#endif
|
2008-04-19 15:41:14 +00:00
|
|
|
}
|
|
|
|
|
2010-04-16 17:37:16 +00:00
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
nsIdleServiceQt::PollIdleTime(uint32_t *aIdleTime)
|
2008-04-19 15:41:14 +00:00
|
|
|
{
|
2013-08-25 23:56:53 +00:00
|
|
|
#if defined(MOZ_X11)
|
2008-04-19 15:41:14 +00:00
|
|
|
// Ask xscreensaver about idle time:
|
2010-04-16 17:37:16 +00:00
|
|
|
*aIdleTime = 0;
|
2008-04-19 15:41:14 +00:00
|
|
|
|
|
|
|
// We might not have a display (cf. in xpcshell)
|
2012-03-22 23:24:40 +00:00
|
|
|
Display *dplay = mozilla::DefaultXDisplay();
|
2008-04-19 15:41:14 +00:00
|
|
|
if (!dplay) {
|
2010-04-16 17:37:16 +00:00
|
|
|
return false;
|
2008-04-19 15:41:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!sInitialized) {
|
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
if (!_XSSQueryExtension || !_XSSAllocInfo || !_XSSQueryInfo) {
|
2010-04-16 17:37:16 +00:00
|
|
|
return false;
|
2008-04-19 15:41:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int event_base, error_base;
|
|
|
|
if (_XSSQueryExtension(dplay, &event_base, &error_base)) {
|
|
|
|
if (!mXssInfo)
|
|
|
|
mXssInfo = _XSSAllocInfo();
|
|
|
|
if (!mXssInfo)
|
2010-04-16 17:37:16 +00:00
|
|
|
return false;
|
2008-04-19 15:41:14 +00:00
|
|
|
|
2012-03-22 23:24:40 +00:00
|
|
|
_XSSQueryInfo(dplay, RootWindowOfScreen(DefaultScreenOfDisplay(mozilla::DefaultXDisplay())), mXssInfo);
|
2010-04-16 17:37:16 +00:00
|
|
|
*aIdleTime = mXssInfo->idle;
|
|
|
|
return true;
|
2008-04-19 15:41:14 +00:00
|
|
|
}
|
2010-09-09 23:46:25 +00:00
|
|
|
#endif
|
2008-04-19 15:41:14 +00:00
|
|
|
|
2010-04-16 17:37:16 +00:00
|
|
|
return false;
|
2008-04-19 15:41:14 +00:00
|
|
|
}
|
2010-04-16 17:37:16 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
nsIdleServiceQt::UsePollMode()
|
|
|
|
{
|
2013-08-25 23:56:53 +00:00
|
|
|
#if defined(MOZ_X11)
|
2010-09-09 23:46:25 +00:00
|
|
|
return false;
|
|
|
|
#endif
|
2010-04-16 17:37:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|