Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Unified Diff: views/touchui/touch_factory.cc

Issue 6242012: touch: Hide the X cursor when not in use. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't hide cursor when a mouse event is in progress. Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698