1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sts=2 sw=2 et cin: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "InputDeviceUtils.h"
19 InputDeviceUtils::RegisterNotification(HWND aHwnd
) {
20 DEV_BROADCAST_DEVICEINTERFACE filter
= {};
22 filter
.dbcc_size
= sizeof(DEV_BROADCAST_DEVICEINTERFACE
);
23 filter
.dbcc_devicetype
= DBT_DEVTYP_DEVICEINTERFACE
;
24 // Some touchsreen devices are not GUID_DEVINTERFACE_MOUSE, so here we use
25 // GUID_DEVINTERFACE_HID instead.
26 filter
.dbcc_classguid
= GUID_DEVINTERFACE_HID
;
27 return RegisterDeviceNotification(aHwnd
, &filter
,
28 DEVICE_NOTIFY_WINDOW_HANDLE
);
31 void InputDeviceUtils::UnregisterNotification(HDEVNOTIFY aHandle
) {
35 UnregisterDeviceNotification(aHandle
);
39 InputDeviceUtils::CountMouseDevices() {
41 SetupDiGetClassDevs(&GUID_DEVINTERFACE_MOUSE
, nullptr, nullptr,
42 DIGCF_DEVICEINTERFACE
| DIGCF_PRESENT
);
43 if (hdev
== INVALID_HANDLE_VALUE
) {
48 SP_INTERFACE_DEVICE_DATA info
= {};
49 info
.cbSize
= sizeof(SP_INTERFACE_DEVICE_DATA
);
50 while (SetupDiEnumDeviceInterfaces(hdev
, nullptr, &GUID_DEVINTERFACE_MOUSE
,
52 if (info
.Flags
& SPINT_ACTIVE
) {
56 SetupDiDestroyDeviceInfoList(hdev
);
61 } // namespace mozilla