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