1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* vim:expandtab:shiftwidth=4:tabstop=4:
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 #include "mozilla/X11Util.h"
11 #include "nsIdleServiceQt.h"
12 #include "nsIServiceManager.h"
17 typedef bool (*_XScreenSaverQueryExtension_fn
)(Display
* dpy
, int* event_base
,
20 typedef XScreenSaverInfo
* (*_XScreenSaverAllocInfo_fn
)(void);
22 typedef void (*_XScreenSaverQueryInfo_fn
)(Display
* dpy
, Drawable drw
,
23 XScreenSaverInfo
*info
);
25 static _XScreenSaverQueryExtension_fn _XSSQueryExtension
= nullptr;
26 static _XScreenSaverAllocInfo_fn _XSSAllocInfo
= nullptr;
27 static _XScreenSaverQueryInfo_fn _XSSQueryInfo
= nullptr;
30 static bool sInitialized
= false;
32 NS_IMPL_ISUPPORTS_INHERITED0(nsIdleServiceQt
, nsIdleService
)
34 nsIdleServiceQt::nsIdleServiceQt()
41 static void Initialize()
46 // This will leak - See comments in ~nsIdleServiceQt().
47 PRLibrary
* xsslib
= PR_LoadLibrary("libXss.so.1");
52 _XSSQueryExtension
= (_XScreenSaverQueryExtension_fn
)
53 PR_FindFunctionSymbol(xsslib
, "XScreenSaverQueryExtension");
54 _XSSAllocInfo
= (_XScreenSaverAllocInfo_fn
)
55 PR_FindFunctionSymbol(xsslib
, "XScreenSaverAllocInfo");
56 _XSSQueryInfo
= (_XScreenSaverQueryInfo_fn
)
57 PR_FindFunctionSymbol(xsslib
, "XScreenSaverQueryInfo");
61 nsIdleServiceQt::~nsIdleServiceQt()
67 // It is not safe to unload libXScrnSaver until each display is closed because
68 // the library registers callbacks through XESetCloseDisplay (Bug 397607).
69 // (Also the library and its functions are scoped for the file not the object.)
72 PR_UnloadLibrary(xsslib
);
80 nsIdleServiceQt::PollIdleTime(uint32_t *aIdleTime
)
83 // Ask xscreensaver about idle time:
86 // We might not have a display (cf. in xpcshell)
87 Display
*dplay
= mozilla::DefaultXDisplay();
95 if (!_XSSQueryExtension
|| !_XSSAllocInfo
|| !_XSSQueryInfo
) {
99 int event_base
, error_base
;
100 if (_XSSQueryExtension(dplay
, &event_base
, &error_base
)) {
102 mXssInfo
= _XSSAllocInfo();
106 _XSSQueryInfo(dplay
, RootWindowOfScreen(DefaultScreenOfDisplay(mozilla::DefaultXDisplay())), mXssInfo
);
107 *aIdleTime
= mXssInfo
->idle
;
116 nsIdleServiceQt::UsePollMode()