Index: views/touchui/touch_factory.cc |
diff --git a/views/touchui/touch_factory.cc b/views/touchui/touch_factory.cc |
index 86087829e9818d14123cf787ae3b5aea301537fb..472f456187a062812840bdb67a2b3f43116ddffe 100644 |
--- a/views/touchui/touch_factory.cc |
+++ b/views/touchui/touch_factory.cc |
@@ -7,7 +7,12 @@ |
#include <gdk/gdkx.h> |
#include <X11/extensions/XInput2.h> |
+#include "base/compiler_specific.h" |
#include "base/logging.h" |
+#include "ui/base/x/x11_util.h" |
+ |
+// The X cursor is hidden if it is idle for kCursorIdleSeconds seconds. |
+static int kCursorIdleSeconds = 5; |
namespace views { |
@@ -17,8 +22,25 @@ TouchFactory* TouchFactory::GetInstance() { |
} |
TouchFactory::TouchFactory() |
- : touch_device_lookup_(), |
+ : is_cursor_visible_(true), |
+ cursor_timer_(), |
touch_device_list_() { |
+ Pixmap blank; |
+ XColor black; |
+ static char nodata[] = { 0,0,0,0,0,0,0,0 }; |
+ black.red = black.green = black.blue = 0; |
+ Display* display = ui::GetXDisplay(); |
+ |
+ blank = XCreateBitmapFromData(display, ui::GetX11RootWindow(), nodata, 8, 8); |
+ invisible_cursor_ = XCreatePixmapCursor(display, blank, blank, |
+ &black, &black, 0, 0); |
+ |
+ SetCursorVisible(false, false); |
+} |
+ |
+TouchFactory::~TouchFactory() { |
+ SetCursorVisible(true, false); |
+ XFreeCursor(ui::GetXDisplay(), invisible_cursor_); |
} |
void TouchFactory::SetTouchDeviceList( |
@@ -76,4 +98,33 @@ bool TouchFactory::UngrabTouchDevices(Display* display) { |
return success; |
} |
+void TouchFactory::SetCursorVisible(bool show, bool start_timer) { |
+ // The cursor is going to be shown. Reset the timer for hiding it. |
+ if (show && start_timer) { |
+ cursor_timer_.Stop(); |
+ cursor_timer_.Start(base::TimeDelta::FromSeconds(kCursorIdleSeconds), |
+ this, &TouchFactory::HideCursorForInactivity), |
+ } else { |
+ cursor_timer_.Stop(); |
+ } |
+ |
+ if (show == is_cursor_visible_) |
+ return; |
+ |
+ is_cursor_visible_ = show; |
+ |
+ GdkDisplay* display = gdk_display_get_default(); |
+ if (!display) |
+ return; |
+ |
+ Display* xdisplay = GDK_DISPLAY_XDISPLAY(display); |
+ Window window = DefaultRootWindow(xdisplay); |
+ |
+ if (is_cursor_visible_) { |
+ XUndefineCursor(xdisplay, window); |
+ } else { |
+ XDefineCursor(xdisplay, window, invisible_cursor_); |
+ } |
+} |
+ |
} // namespace views |