Chromium Code Reviews| Index: views/touchui/touch_factory.cc |
| diff --git a/views/touchui/touch_factory.cc b/views/touchui/touch_factory.cc |
| index 86087829e9818d14123cf787ae3b5aea301537fb..49521a29f4fbddc58d715ca45db2960ec3032384 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,27 @@ TouchFactory* TouchFactory::GetInstance() { |
| } |
| TouchFactory::TouchFactory() |
| - : touch_device_lookup_(), |
| + : hiding_cursor_(false), |
| + ALLOW_THIS_IN_INITIALIZER_LIST(cursor_timer_( |
| + base::TimeDelta::FromSeconds(kCursorIdleSeconds), this, |
| + &TouchFactory::HideCursorForInactivity)), |
| + touch_device_lookup_(), |
| 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_ = XCreatePixmapCursor(display, blank, blank, &black, &black, 0, 0); |
| + |
| + SetCursorVisibility(false); |
| +} |
| + |
| +TouchFactory::~TouchFactory() { |
| + SetCursorVisibility(true); |
| + XFreeCursor(ui::GetXDisplay(), invisible_); |
| } |
| void TouchFactory::SetTouchDeviceList( |
| @@ -76,4 +100,28 @@ bool TouchFactory::UngrabTouchDevices(Display* display) { |
| return success; |
| } |
| +void TouchFactory::SetCursorVisibility(bool show) { |
| + // The cursor is going to be shown. Reset the timer for hiding it. |
| + if (show) |
| + 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
|
| + |
| + if (show == !hiding_cursor_) |
| + return; |
| + |
| + hiding_cursor_ = !show; |
| + |
| + GdkDisplay* display = gdk_display_get_default(); |
| + if (!display) |
| + return; |
| + |
| + Display* xdisplay = GDK_DISPLAY_XDISPLAY(display); |
| + Window window = DefaultRootWindow(xdisplay); |
| + |
| + if (hiding_cursor_) { |
| + XDefineCursor(xdisplay, window, invisible_); |
| + } else { |
| + XUndefineCursor(xdisplay, window); |
| + } |
| +} |
| + |
| } // namespace views |