Chromium Code Reviews| 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 : hiding_cursor_(false), |
| 26 ALLOW_THIS_IN_INITIALIZER_LIST(cursor_timer_( | |
| 27 base::TimeDelta::FromSeconds(kCursorIdleSeconds), this, | |
| 28 &TouchFactory::HideCursorForInactivity)), | |
| 29 touch_device_lookup_(), | |
| 21 touch_device_list_() { | 30 touch_device_list_() { |
| 31 Pixmap blank; | |
| 32 XColor black; | |
| 33 static char nodata[] = { 0,0,0,0,0,0,0,0 }; | |
| 34 black.red = black.green = black.blue = 0; | |
| 35 Display* display = ui::GetXDisplay(); | |
| 36 | |
| 37 blank = XCreateBitmapFromData(display, ui::GetX11RootWindow(), nodata, 8, 8); | |
| 38 invisible_ = XCreatePixmapCursor(display, blank, blank, &black, &black, 0, 0); | |
| 39 | |
| 40 SetCursorVisibility(false); | |
| 41 } | |
| 42 | |
| 43 TouchFactory::~TouchFactory() { | |
| 44 SetCursorVisibility(true); | |
| 45 XFreeCursor(ui::GetXDisplay(), invisible_); | |
| 22 } | 46 } |
| 23 | 47 |
| 24 void TouchFactory::SetTouchDeviceList( | 48 void TouchFactory::SetTouchDeviceList( |
| 25 const std::vector<unsigned int>& devices) { | 49 const std::vector<unsigned int>& devices) { |
| 26 touch_device_lookup_.reset(); | 50 touch_device_lookup_.reset(); |
| 27 touch_device_list_.clear(); | 51 touch_device_list_.clear(); |
| 28 for (std::vector<unsigned int>::const_iterator iter = devices.begin(); | 52 for (std::vector<unsigned int>::const_iterator iter = devices.begin(); |
| 29 iter != devices.end(); ++iter) { | 53 iter != devices.end(); ++iter) { |
| 30 DCHECK(*iter < touch_device_lookup_.size()); | 54 DCHECK(*iter < touch_device_lookup_.size()); |
| 31 touch_device_lookup_[*iter] = true; | 55 touch_device_lookup_[*iter] = true; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 bool success = true; | 93 bool success = true; |
| 70 for (std::vector<int>::const_iterator iter = | 94 for (std::vector<int>::const_iterator iter = |
| 71 touch_device_list_.begin(); | 95 touch_device_list_.begin(); |
| 72 iter != touch_device_list_.end(); ++iter) { | 96 iter != touch_device_list_.end(); ++iter) { |
| 73 Status status = XIUngrabDevice(display, *iter, CurrentTime); | 97 Status status = XIUngrabDevice(display, *iter, CurrentTime); |
| 74 success = success && status == GrabSuccess; | 98 success = success && status == GrabSuccess; |
| 75 } | 99 } |
| 76 return success; | 100 return success; |
| 77 } | 101 } |
| 78 | 102 |
| 103 void TouchFactory::SetCursorVisibility(bool show) { | |
| 104 // The cursor is going to be shown. Reset the timer for hiding it. | |
| 105 if (show) | |
| 106 cursor_timer_.Reset(); | |
|
sky
2011/01/26 16:17:00
Would this trigger if the user presses the mouse a
sadrul
2011/01/26 17:57:11
It would! I hadn't considered this scenario. I sus
| |
| 107 | |
| 108 if (show == !hiding_cursor_) | |
| 109 return; | |
| 110 | |
| 111 hiding_cursor_ = !show; | |
| 112 | |
| 113 GdkDisplay* display = gdk_display_get_default(); | |
| 114 if (!display) | |
| 115 return; | |
| 116 | |
| 117 Display* xdisplay = GDK_DISPLAY_XDISPLAY(display); | |
| 118 Window window = DefaultRootWindow(xdisplay); | |
| 119 | |
| 120 if (hiding_cursor_) { | |
| 121 XDefineCursor(xdisplay, window, invisible_); | |
| 122 } else { | |
| 123 XUndefineCursor(xdisplay, window); | |
| 124 } | |
| 125 } | |
| 126 | |
| 79 } // namespace views | 127 } // namespace views |
| OLD | NEW |