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 5 #include "chrome/browser/sync/engine/idle_query_linux.h" 6 7 #include <X11/extensions/scrnsaver.h> 8 #include "ui/base/x/x11_util.h" 9 10 namespace browser_sync { 11 12 class IdleData { 13 public: IdleData()14 IdleData() { 15 int event_base; 16 int error_base; 17 if (XScreenSaverQueryExtension(ui::GetXDisplay(), &event_base, 18 &error_base)) { 19 mit_info = XScreenSaverAllocInfo(); 20 } else { 21 mit_info = NULL; 22 } 23 } 24 ~IdleData()25 ~IdleData() { 26 if (mit_info) 27 XFree(mit_info); 28 } 29 30 XScreenSaverInfo *mit_info; 31 }; 32 IdleQueryLinux()33IdleQueryLinux::IdleQueryLinux() : idle_data_(new IdleData()) {} 34 ~IdleQueryLinux()35IdleQueryLinux::~IdleQueryLinux() {} 36 IdleTime()37int IdleQueryLinux::IdleTime() { 38 if (!idle_data_->mit_info) 39 return 0; 40 41 if (XScreenSaverQueryInfo(ui::GetXDisplay(), 42 RootWindow(ui::GetXDisplay(), 0), 43 idle_data_->mit_info)) { 44 return (idle_data_->mit_info->idle) / 1000; 45 } else { 46 return 0; 47 } 48 } 49 50 } // namespace browser_sync 51