| 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 #if defined(TOOLKIT_USES_GTK) |
| 8 // TODO(sad) Remove all TOOLKIT_USES_GTK uses once we move to aura only. |
| 7 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
| 8 #include <gdk/gdkx.h> | 10 #include <gdk/gdkx.h> |
| 11 #endif |
| 9 #include <X11/cursorfont.h> | 12 #include <X11/cursorfont.h> |
| 10 #include <X11/extensions/XInput.h> | 13 #include <X11/extensions/XInput.h> |
| 11 #include <X11/extensions/XInput2.h> | 14 #include <X11/extensions/XInput2.h> |
| 12 #include <X11/extensions/XIproto.h> | 15 #include <X11/extensions/XIproto.h> |
| 13 | 16 |
| 14 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
| 15 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
| 16 #include "base/logging.h" | 19 #include "base/logging.h" |
| 17 #include "base/message_loop.h" | 20 #include "base/message_loop.h" |
| 18 #include "ui/base/x/x11_util.h" | 21 #include "ui/base/x/x11_util.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 reinterpret_cast<XIValuatorClassInfo*>(info->classes[i]); | 67 reinterpret_cast<XIValuatorClassInfo*>(info->classes[i]); |
| 65 | 68 |
| 66 const char* atom = XGetAtomName(display, v->label); | 69 const char* atom = XGetAtomName(display, v->label); |
| 67 if (atom && strcmp(atom, atom_tp) == 0) | 70 if (atom && strcmp(atom, atom_tp) == 0) |
| 68 return v; | 71 return v; |
| 69 } | 72 } |
| 70 | 73 |
| 71 return NULL; | 74 return NULL; |
| 72 } | 75 } |
| 73 | 76 |
| 77 #if defined(TOOLKIT_USES_GTK) |
| 74 // Setup XInput2 select for the GtkWidget. | 78 // Setup XInput2 select for the GtkWidget. |
| 75 gboolean GtkWidgetRealizeCallback(GSignalInvocationHint* hint, guint nparams, | 79 gboolean GtkWidgetRealizeCallback(GSignalInvocationHint* hint, guint nparams, |
| 76 const GValue* pvalues, gpointer data) { | 80 const GValue* pvalues, gpointer data) { |
| 77 GtkWidget* widget = GTK_WIDGET(g_value_get_object(pvalues)); | 81 GtkWidget* widget = GTK_WIDGET(g_value_get_object(pvalues)); |
| 78 GdkWindow* window = widget->window; | 82 GdkWindow* window = widget->window; |
| 79 views::TouchFactory* factory = static_cast<views::TouchFactory*>(data); | 83 views::TouchFactory* factory = static_cast<views::TouchFactory*>(data); |
| 80 | 84 |
| 81 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_TOPLEVEL && | 85 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_TOPLEVEL && |
| 82 GDK_WINDOW_TYPE(window) != GDK_WINDOW_CHILD && | 86 GDK_WINDOW_TYPE(window) != GDK_WINDOW_CHILD && |
| 83 GDK_WINDOW_TYPE(window) != GDK_WINDOW_DIALOG) | 87 GDK_WINDOW_TYPE(window) != GDK_WINDOW_DIALOG) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 105 | 109 |
| 106 g_type_class_unref(klass); | 110 g_type_class_unref(klass); |
| 107 } | 111 } |
| 108 | 112 |
| 109 void RemoveGtkWidgetRealizeNotifier() { | 113 void RemoveGtkWidgetRealizeNotifier() { |
| 110 if (realize_signal_id != 0) | 114 if (realize_signal_id != 0) |
| 111 g_signal_remove_emission_hook(realize_signal_id, realize_hook_id); | 115 g_signal_remove_emission_hook(realize_signal_id, realize_hook_id); |
| 112 realize_signal_id = 0; | 116 realize_signal_id = 0; |
| 113 realize_hook_id = 0; | 117 realize_hook_id = 0; |
| 114 } | 118 } |
| 119 #endif |
| 115 | 120 |
| 116 } // namespace | 121 } // namespace |
| 117 | 122 |
| 118 namespace views { | 123 namespace views { |
| 119 | 124 |
| 120 // static | 125 // static |
| 121 TouchFactory* TouchFactory::GetInstance() { | 126 TouchFactory* TouchFactory::GetInstance() { |
| 122 return Singleton<TouchFactory>::get(); | 127 return Singleton<TouchFactory>::get(); |
| 123 } | 128 } |
| 124 | 129 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 140 Display* display = ui::GetXDisplay(); | 145 Display* display = ui::GetXDisplay(); |
| 141 Pixmap blank = XCreateBitmapFromData(display, ui::GetX11RootWindow(), | 146 Pixmap blank = XCreateBitmapFromData(display, ui::GetX11RootWindow(), |
| 142 nodata, 8, 8); | 147 nodata, 8, 8); |
| 143 invisible_cursor_ = XCreatePixmapCursor(display, blank, blank, | 148 invisible_cursor_ = XCreatePixmapCursor(display, blank, blank, |
| 144 &black, &black, 0, 0); | 149 &black, &black, 0, 0); |
| 145 arrow_cursor_ = XCreateFontCursor(display, XC_arrow); | 150 arrow_cursor_ = XCreateFontCursor(display, XC_arrow); |
| 146 | 151 |
| 147 SetCursorVisible(false, false); | 152 SetCursorVisible(false, false); |
| 148 UpdateDeviceList(display); | 153 UpdateDeviceList(display); |
| 149 | 154 |
| 155 #if defined(TOOLKIT_USES_GTK) |
| 150 // TODO(sad): Here, we only setup so that the X windows created by GTK+ are | 156 // TODO(sad): Here, we only setup so that the X windows created by GTK+ are |
| 151 // setup for XInput2 events. We need a way to listen for XInput2 events for X | 157 // setup for XInput2 events. We need a way to listen for XInput2 events for X |
| 152 // windows created by other means (e.g. for context menus). | 158 // windows created by other means (e.g. for context menus). |
| 153 SetupGtkWidgetRealizeNotifier(this); | 159 SetupGtkWidgetRealizeNotifier(this); |
| 154 | 160 #endif |
| 155 // Make sure the list of devices is kept up-to-date by listening for | 161 // Make sure the list of devices is kept up-to-date by listening for |
| 156 // XI_HierarchyChanged event on the root window. | 162 // XI_HierarchyChanged event on the root window. |
| 157 unsigned char mask[XIMaskLen(XI_LASTEVENT)]; | 163 unsigned char mask[XIMaskLen(XI_LASTEVENT)]; |
| 158 memset(mask, 0, sizeof(mask)); | 164 memset(mask, 0, sizeof(mask)); |
| 159 | 165 |
| 160 XISetMask(mask, XI_HierarchyChanged); | 166 XISetMask(mask, XI_HierarchyChanged); |
| 161 | 167 |
| 162 XIEventMask evmask; | 168 XIEventMask evmask; |
| 163 evmask.deviceid = XIAllDevices; | 169 evmask.deviceid = XIAllDevices; |
| 164 evmask.mask_len = sizeof(mask); | 170 evmask.mask_len = sizeof(mask); |
| 165 evmask.mask = mask; | 171 evmask.mask = mask; |
| 166 XISelectEvents(display, ui::GetX11RootWindow(), &evmask, 1); | 172 XISelectEvents(display, ui::GetX11RootWindow(), &evmask, 1); |
| 167 } | 173 } |
| 168 | 174 |
| 169 TouchFactory::~TouchFactory() { | 175 TouchFactory::~TouchFactory() { |
| 170 #if defined(TOUCH_UI) | 176 #if defined(TOUCH_UI) |
| 171 if (!base::MessagePumpForUI::HasXInput2()) | 177 if (!base::MessagePumpForUI::HasXInput2()) |
| 172 return; | 178 return; |
| 173 #endif | 179 #endif |
| 174 | 180 |
| 175 SetCursorVisible(true, false); | 181 SetCursorVisible(true, false); |
| 176 Display* display = ui::GetXDisplay(); | 182 Display* display = ui::GetXDisplay(); |
| 177 XFreeCursor(display, invisible_cursor_); | 183 XFreeCursor(display, invisible_cursor_); |
| 178 XFreeCursor(display, arrow_cursor_); | 184 XFreeCursor(display, arrow_cursor_); |
| 179 | 185 |
| 186 #if defined(TOOLKIT_USES_GTK) |
| 180 RemoveGtkWidgetRealizeNotifier(); | 187 RemoveGtkWidgetRealizeNotifier(); |
| 188 #endif |
| 181 } | 189 } |
| 182 | 190 |
| 183 void TouchFactory::UpdateDeviceList(Display* display) { | 191 void TouchFactory::UpdateDeviceList(Display* display) { |
| 184 // Detect touch devices. | 192 // Detect touch devices. |
| 185 // NOTE: The new API for retrieving the list of devices (XIQueryDevice) does | 193 // NOTE: The new API for retrieving the list of devices (XIQueryDevice) does |
| 186 // not provide enough information to detect a touch device. As a result, the | 194 // not provide enough information to detect a touch device. As a result, the |
| 187 // old version of query function (XListInputDevices) is used instead. | 195 // old version of query function (XListInputDevices) is used instead. |
| 188 // If XInput2 is not supported, this will return null (with count of -1) so | 196 // If XInput2 is not supported, this will return null (with count of -1) so |
| 189 // we assume there cannot be any touch devices. | 197 // we assume there cannot be any touch devices. |
| 190 int count = 0; | 198 int count = 0; |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 float* max) { | 445 float* max) { |
| 438 if (valuator_lookup_[deviceid][tp] >= 0) { | 446 if (valuator_lookup_[deviceid][tp] >= 0) { |
| 439 *min = touch_param_min_[deviceid][tp]; | 447 *min = touch_param_min_[deviceid][tp]; |
| 440 *max = touch_param_max_[deviceid][tp]; | 448 *max = touch_param_max_[deviceid][tp]; |
| 441 return true; | 449 return true; |
| 442 } | 450 } |
| 443 return false; | 451 return false; |
| 444 } | 452 } |
| 445 | 453 |
| 446 } // namespace views | 454 } // namespace views |
| OLD | NEW |