Bug 1861709 replace AudioCallbackDriver::ThreadRunning() assertions that mean to...
[gecko.git] / widget / windows / InputDeviceUtils.cpp
blob3636b93d6a820639054d063b299a6815eb8c6ebc
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"
9 #define INITGUID
10 #include <dbt.h>
11 #include <hidclass.h>
12 #include <ntddmou.h>
13 #include <setupapi.h>
15 namespace mozilla {
16 namespace widget {
18 HDEVNOTIFY
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) {
32 if (!aHandle) {
33 return;
35 UnregisterDeviceNotification(aHandle);
38 DWORD
39 InputDeviceUtils::CountMouseDevices() {
40 HDEVINFO hdev =
41 SetupDiGetClassDevs(&GUID_DEVINTERFACE_MOUSE, nullptr, nullptr,
42 DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);
43 if (hdev == INVALID_HANDLE_VALUE) {
44 return 0;
47 DWORD count = 0;
48 SP_INTERFACE_DEVICE_DATA info = {};
49 info.cbSize = sizeof(SP_INTERFACE_DEVICE_DATA);
50 while (SetupDiEnumDeviceInterfaces(hdev, nullptr, &GUID_DEVINTERFACE_MOUSE,
51 count, &info)) {
52 if (info.Flags & SPINT_ACTIVE) {
53 count++;
56 SetupDiDestroyDeviceInfoList(hdev);
57 return count;
60 } // namespace widget
61 } // namespace mozilla