1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 #include "WidgetUtilsGtk.h"
7 
8 namespace mozilla {
9 
10 namespace widget {
11 
IsTouchDeviceSupportPresent()12 int32_t WidgetUtilsGTK::IsTouchDeviceSupportPresent() {
13 #if GTK_CHECK_VERSION(3, 4, 0)
14   int32_t result = 0;
15   GdkDisplay* display = gdk_display_get_default();
16   if (!display) {
17     return 0;
18   }
19 
20   GdkDeviceManager* manager = gdk_display_get_device_manager(display);
21   if (!manager) {
22     return 0;
23   }
24 
25   GList* devices =
26       gdk_device_manager_list_devices(manager, GDK_DEVICE_TYPE_SLAVE);
27   GList* list = devices;
28 
29   while (devices) {
30     GdkDevice* device = static_cast<GdkDevice*>(devices->data);
31     if (gdk_device_get_source(device) == GDK_SOURCE_TOUCHSCREEN) {
32       result = 1;
33       break;
34     }
35     devices = devices->next;
36   }
37 
38   if (list) {
39     g_list_free(list);
40   }
41 
42   return result;
43 #else
44   return 0;
45 #endif
46 }
47 
48 }  // namespace widget
49 
50 }  // namespace mozilla
51