MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / initialize

Method initialize

source/MRViewer/MRSpaceMouseHandlerWinEvents.cpp:25–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23{
24
25bool HandlerWinEvents::initialize()
26{
27 auto window = getViewerInstance().window;
28 if ( !window )
29 {
30 assert( !"no glfw window while trying to initialize SpaceMouse::HandlerWinEvents" );
31 return false;
32 }
33 auto winHndl = glfwGetWin32Window( window );
34 if ( !winHndl )
35 {
36 assert( !"no window handler while trying to initialize SpaceMouse::HandlerWinEvents" );
37 return false;
38 }
39
40 std::array<RAWINPUTDEVICE, 1> rawDevices;
41 for ( auto& rawDevice : rawDevices )
42 {
43 rawDevice.usUsagePage = HID_USAGE_PAGE_GENERIC;
44 rawDevice.usUsage = HID_USAGE_GENERIC_MULTI_AXIS_CONTROLLER;
45 rawDevice.hwndTarget = winHndl;
46 rawDevice.dwFlags = 0;
47 }
48 if ( !RegisterRawInputDevices( rawDevices.data(), unsigned( rawDevices.size() ), sizeof( RAWINPUTDEVICE ) ) )
49 {
50 spdlog::warn( "Could not register raw devices" );
51 return false;
52 }
53
54 auto handler = Win32MessageHandler::getHandler( winHndl );
55 if ( !handler || !handler->isValid() )
56 {
57 assert( !"invalid Win32MessageHandler while trying to initialize SpaceMouse::HandlerWinEvents" );
58 return false;
59 }
60
61 winHandler_ = std::move( handler );
62
63 auto processRawInput = [this] ( HWND, UINT message, WPARAM /*wParam*/, LPARAM lParam )->bool
64 {
65 if ( message != WM_INPUT )
66 return false;
67
68 RAWINPUT rawInput;
69 UINT rawSize = sizeof( RAWINPUT );
70 GetRawInputData( ( HRAWINPUT )lParam, RID_INPUT, &rawInput, &rawSize, sizeof( RAWINPUTHEADER ) );
71 if ( rawInput.header.dwType != RIM_TYPEHID )
72 return false;
73
74 resetDevice_( rawInput.header.hDevice );
75
76 Action action;
77 DataPacketRaw rawPacket;
78 unsigned packetSize = rawInput.data.hid.dwSizeHid;
79 std::copy( rawInput.data.hid.bRawData, rawInput.data.hid.bRawData + std::min( size_t( rawInput.data.hid.dwSizeHid ), rawPacket.size() ), rawPacket.data() );
80 device_->parseRawEvent( rawPacket, packetSize, action );
81
82 ++numMsg_;

Callers

nothing calls this directly

Calls 7

minFunction · 0.85
parseRawEventMethod · 0.80
processActionMethod · 0.80
dataMethod · 0.45
sizeMethod · 0.45
isValidMethod · 0.45
connectMethod · 0.45

Tested by

no test coverage detected