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