OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 #include "chrome/browser/sync/engine/idle_query_linux.h" |
| 5 |
| 6 #include <X11/Xlib.h> |
| 7 #include <X11/extensions/scrnsaver.h> |
| 8 |
| 9 namespace browser_sync { |
| 10 |
| 11 class IdleData { |
| 12 public: |
| 13 IdleData() { |
| 14 int event_base; |
| 15 int error_base; |
| 16 display = XOpenDisplay(NULL); |
| 17 if (XScreenSaverQueryExtension(display, &event_base, &error_base)) { |
| 18 mit_info = XScreenSaverAllocInfo(); |
| 19 } else { |
| 20 mit_info = NULL; |
| 21 } |
| 22 } |
| 23 |
| 24 ~IdleData() { |
| 25 if (display) { |
| 26 XCloseDisplay(display); |
| 27 display = NULL; |
| 28 } |
| 29 if (mit_info) { |
| 30 XFree(mit_info); |
| 31 } |
| 32 } |
| 33 |
| 34 XScreenSaverInfo *mit_info; |
| 35 Display *display; |
| 36 }; |
| 37 |
| 38 IdleQueryLinux::IdleQueryLinux() : idle_data_(new IdleData()) { |
| 39 } |
| 40 |
| 41 IdleQueryLinux::~IdleQueryLinux() { |
| 42 } |
| 43 |
| 44 int IdleQueryLinux::IdleTime() { |
| 45 if (!idle_data_->mit_info || !idle_data_->display) { |
| 46 return 0; |
| 47 } |
| 48 |
| 49 if (XScreenSaverQueryInfo(idle_data_->display, |
| 50 RootWindow(idle_data_->display, 0), |
| 51 idle_data_->mit_info)) { |
| 52 return (idle_data_->mit_info->idle) / 1000; |
| 53 } else { |
| 54 return 0; |
| 55 } |
| 56 } |
| 57 } // namespace browser_sync |
OLD | NEW |