OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/touchui/touch_factory.h" | 5 #include "views/touchui/touch_factory.h" |
6 | 6 |
7 #include <gdk/gdkx.h> | 7 #include <gdk/gdkx.h> |
8 #include <X11/extensions/XInput2.h> | 8 #include <X11/extensions/XInput2.h> |
9 | 9 |
| 10 #include "base/compiler_specific.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "ui/base/x/x11_util.h" |
| 13 |
| 14 // The X cursor is hidden if it is idle for kCursorIdleSeconds seconds. |
| 15 static int kCursorIdleSeconds = 5; |
11 | 16 |
12 namespace views { | 17 namespace views { |
13 | 18 |
14 // static | 19 // static |
15 TouchFactory* TouchFactory::GetInstance() { | 20 TouchFactory* TouchFactory::GetInstance() { |
16 return Singleton<TouchFactory>::get(); | 21 return Singleton<TouchFactory>::get(); |
17 } | 22 } |
18 | 23 |
19 TouchFactory::TouchFactory() | 24 TouchFactory::TouchFactory() |
20 : touch_device_lookup_(), | 25 : is_cursor_visible_(true), |
| 26 cursor_timer_(), |
21 touch_device_list_() { | 27 touch_device_list_() { |
| 28 Pixmap blank; |
| 29 XColor black; |
| 30 static char nodata[] = { 0,0,0,0,0,0,0,0 }; |
| 31 black.red = black.green = black.blue = 0; |
| 32 Display* display = ui::GetXDisplay(); |
| 33 |
| 34 blank = XCreateBitmapFromData(display, ui::GetX11RootWindow(), nodata, 8, 8); |
| 35 invisible_cursor_ = XCreatePixmapCursor(display, blank, blank, |
| 36 &black, &black, 0, 0); |
| 37 |
| 38 SetCursorVisible(false, false); |
| 39 } |
| 40 |
| 41 TouchFactory::~TouchFactory() { |
| 42 SetCursorVisible(true, false); |
| 43 XFreeCursor(ui::GetXDisplay(), invisible_cursor_); |
22 } | 44 } |
23 | 45 |
24 void TouchFactory::SetTouchDeviceList( | 46 void TouchFactory::SetTouchDeviceList( |
25 const std::vector<unsigned int>& devices) { | 47 const std::vector<unsigned int>& devices) { |
26 touch_device_lookup_.reset(); | 48 touch_device_lookup_.reset(); |
27 touch_device_list_.clear(); | 49 touch_device_list_.clear(); |
28 for (std::vector<unsigned int>::const_iterator iter = devices.begin(); | 50 for (std::vector<unsigned int>::const_iterator iter = devices.begin(); |
29 iter != devices.end(); ++iter) { | 51 iter != devices.end(); ++iter) { |
30 DCHECK(*iter < touch_device_lookup_.size()); | 52 DCHECK(*iter < touch_device_lookup_.size()); |
31 touch_device_lookup_[*iter] = true; | 53 touch_device_lookup_[*iter] = true; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 bool success = true; | 91 bool success = true; |
70 for (std::vector<int>::const_iterator iter = | 92 for (std::vector<int>::const_iterator iter = |
71 touch_device_list_.begin(); | 93 touch_device_list_.begin(); |
72 iter != touch_device_list_.end(); ++iter) { | 94 iter != touch_device_list_.end(); ++iter) { |
73 Status status = XIUngrabDevice(display, *iter, CurrentTime); | 95 Status status = XIUngrabDevice(display, *iter, CurrentTime); |
74 success = success && status == GrabSuccess; | 96 success = success && status == GrabSuccess; |
75 } | 97 } |
76 return success; | 98 return success; |
77 } | 99 } |
78 | 100 |
| 101 void TouchFactory::SetCursorVisible(bool show, bool start_timer) { |
| 102 // The cursor is going to be shown. Reset the timer for hiding it. |
| 103 if (show && start_timer) { |
| 104 cursor_timer_.Stop(); |
| 105 cursor_timer_.Start(base::TimeDelta::FromSeconds(kCursorIdleSeconds), |
| 106 this, &TouchFactory::HideCursorForInactivity), |
| 107 } else { |
| 108 cursor_timer_.Stop(); |
| 109 } |
| 110 |
| 111 if (show == is_cursor_visible_) |
| 112 return; |
| 113 |
| 114 is_cursor_visible_ = show; |
| 115 |
| 116 GdkDisplay* display = gdk_display_get_default(); |
| 117 if (!display) |
| 118 return; |
| 119 |
| 120 Display* xdisplay = GDK_DISPLAY_XDISPLAY(display); |
| 121 Window window = DefaultRootWindow(xdisplay); |
| 122 |
| 123 if (is_cursor_visible_) { |
| 124 XUndefineCursor(xdisplay, window); |
| 125 } else { |
| 126 XDefineCursor(xdisplay, window, invisible_cursor_); |
| 127 } |
| 128 } |
| 129 |
79 } // namespace views | 130 } // namespace views |
OLD | NEW |