/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim:expandtab:shiftwidth=4:tabstop=4:
*/ /* 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/. */
#include <gtk/gtk.h>
#include"nsUserIdleServiceGTK.h" #include"nsDebug.h" #include"prlink.h" #include"mozilla/Logging.h" #include"WidgetUtilsGtk.h" #ifdef MOZ_X11 # include <X11/Xlib.h> # include <X11/Xutil.h> # include <gdk/gdkx.h> #endif #ifdef MOZ_ENABLE_DBUS # include <gio/gio.h> # include "AsyncDBus.h" # include "WakeLockListener.h" # include "nsIObserverService.h" # include "mozilla/UniquePtrExtensions.h" #endif
using mozilla::LogLevel; static mozilla::LazyLogModule sIdleLog("nsIUserIdleService");
class UserIdleServiceX11 : public UserIdleServiceImpl { public: bool PollIdleTime(uint32_t* aIdleTime) override { // Ask xscreensaver about idle time:
*aIdleTime = 0;
// We might not have a display (cf. in xpcshell)
Display* dplay = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); if (!dplay) {
MOZ_LOG(sIdleLog, LogLevel::Warning, ("No display found!\n")); returnfalse;
}
int event_base, error_base; if (mXSSQueryExtension(dplay, &event_base, &error_base)) { if (!mXssInfo) mXssInfo = mXSSAllocInfo(); if (!mXssInfo) returnfalse;
mXSSQueryInfo(dplay, GDK_ROOT_WINDOW(), mXssInfo);
*aIdleTime = mXssInfo->idle;
MOZ_LOG(sIdleLog, LogLevel::Info,
("UserIdleServiceX11::PollIdleTime() %d\n", *aIdleTime)); returntrue;
} // If we get here, we couldn't get to XScreenSaver:
MOZ_LOG(sIdleLog, LogLevel::Warning,
("XSSQueryExtension returned false!\n")); returnfalse;
}
if (!mozilla::widget::GdkIsX11Display()) { returnfalse;
}
// This will leak - See comments in ~UserIdleServiceX11().
PRLibrary* xsslib = PR_LoadLibrary("libXss.so.1"); if (!xsslib) // ouch.
{
MOZ_LOG(sIdleLog, LogLevel::Warning, ("Failed to find libXss.so!\n")); returnfalse;
}
if (!mXSSQueryExtension) {
MOZ_LOG(sIdleLog, LogLevel::Warning,
("Failed to get XSSQueryExtension!\n"));
} if (!mXSSAllocInfo) {
MOZ_LOG(sIdleLog, LogLevel::Warning, ("Failed to get XSSAllocInfo!\n"));
} if (!mXSSQueryInfo) {
MOZ_LOG(sIdleLog, LogLevel::Warning, ("Failed to get XSSQueryInfo!\n"));
} if (!mXSSQueryExtension || !mXSSAllocInfo || !mXSSQueryInfo) { // We're missing X11 symbols returnfalse;
}
// 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);
xsslib = nullptr;
} # endif
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.