From 6138557ecbc6a638accfb31a1de6f9bdbe006876 Mon Sep 17 00:00:00 2001 From: "gijskruitbosch%gmail.com" Date: Thu, 25 Jan 2007 21:13:32 +0000 Subject: [PATCH] Bug 366337 - implement nsIIdleService on Windows (second attempt) r=emaijala@kolumbus.fi (Ere Maijala) sr=neil@parkwaycc.co.uk (Neil Rashbrook) --- widget/src/build/nsWinWidgetFactory.cpp | 6 +++ widget/src/windows/Makefile.in | 1 + widget/src/windows/nsIdleServiceWin.cpp | 56 +++++++++++++++++++++++++ widget/src/windows/nsIdleServiceWin.h | 54 ++++++++++++++++++++++++ 4 files changed, 117 insertions(+) create mode 100644 widget/src/windows/nsIdleServiceWin.cpp create mode 100644 widget/src/windows/nsIdleServiceWin.h diff --git a/widget/src/build/nsWinWidgetFactory.cpp b/widget/src/build/nsWinWidgetFactory.cpp index bcf707c39256..e50a750a11b6 100644 --- a/widget/src/build/nsWinWidgetFactory.cpp +++ b/widget/src/build/nsWinWidgetFactory.cpp @@ -50,6 +50,7 @@ #include "nsAppShellSingleton.h" #include "nsIServiceManager.h" #include "nsSound.h" +#include "nsIdleServiceWin.h" #include "nsBidiKeyboard.h" @@ -79,6 +80,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsFilePicker) NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound) NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService) NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsIdleServiceWin) #endif NS_GENERIC_FACTORY_CONSTRUCTOR(nsToolkit) @@ -128,6 +130,10 @@ static const nsModuleComponentInfo components[] = NS_BIDIKEYBOARD_CID, "@mozilla.org/widget/bidikeyboard;1", nsBidiKeyboardConstructor }, + { "User Idle Service", + NS_IDLE_SERVICE_CID, + "@mozilla.org/widget/idleservice;1", + nsIdleServiceWinConstructor }, #endif { "Native Theme Renderer", NS_THEMERENDERER_CID, diff --git a/widget/src/windows/Makefile.in b/widget/src/windows/Makefile.in index c89a5bb50099..78ace1195825 100644 --- a/widget/src/windows/Makefile.in +++ b/widget/src/windows/Makefile.in @@ -103,6 +103,7 @@ CPPSRCS += \ nsImageClipboard.cpp \ nsBidiKeyboard.cpp \ nsSound.cpp \ + nsIdleServiceWin.cpp \ $(NULL) endif diff --git a/widget/src/windows/nsIdleServiceWin.cpp b/widget/src/windows/nsIdleServiceWin.cpp new file mode 100644 index 000000000000..756792d03f5d --- /dev/null +++ b/widget/src/windows/nsIdleServiceWin.cpp @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* vim:expandtab:shiftwidth=4:tabstop=4: + */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Gijs Kruitbosch . + * Portions created by the Initial Developer are Copyright (C) 2007 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Gijs Kruitbosch + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsIdleServiceWin.h" +#include + +NS_IMPL_ISUPPORTS1(nsIdleServiceWin, nsIIdleService) + +NS_IMETHODIMP +nsIdleServiceWin::GetIdleTime(PRUint32 *aTimeDiff) +{ + LASTINPUTINFO inputInfo; + inputInfo.cbSize = sizeof(inputInfo); + if (!::GetLastInputInfo(&inputInfo)) + return NS_ERROR_FAILURE; + + *aTimeDiff = GetTickCount() - inputInfo.dwTime; + return NS_OK; +} diff --git a/widget/src/windows/nsIdleServiceWin.h b/widget/src/windows/nsIdleServiceWin.h new file mode 100644 index 000000000000..194efa2d3147 --- /dev/null +++ b/widget/src/windows/nsIdleServiceWin.h @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* vim:expandtab:shiftwidth=4:tabstop=4: + */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Gijs Kruitbosch . + * Portions created by the Initial Developer are Copyright (C) 2007 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Gijs Kruitbosch + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsIdleServiceWin_h__ +#define nsIdleServiceWin_h__ + +#include "nsIdleService.h" + +class nsIdleServiceWin : public nsIdleService +{ +public: + NS_DECL_ISUPPORTS + + NS_IMETHOD GetIdleTime(PRUint32* idleTime); +}; + +#endif // nsIdleServiceWin_h__