@@ -428,6 +428,29 @@ pl__windows_procedure(HWND tHwnd, UINT tMsg, WPARAM tWParam, LPARAM tLParam)
428428 break ;
429429 }
430430
431+ case WM_INPUT :
432+ {
433+ UINT uSize = 0 ;
434+ GetRawInputData ((HRAWINPUT )tLParam , RID_INPUT , NULL , & uSize , sizeof (RAWINPUTHEADER ));
435+ if (uSize > 0 )
436+ {
437+ RAWINPUT * ptRaw = (RAWINPUT * )malloc (uSize );
438+ if (GetRawInputData ((HRAWINPUT )tLParam , RID_INPUT , ptRaw , & uSize , sizeof (RAWINPUTHEADER )) == uSize )
439+ {
440+ if (ptRaw -> header .dwType == RIM_TYPEMOUSE )
441+ {
442+ // get current cursor pos in client space and feed as mouse event
443+ POINT tCurrent ;
444+ GetCursorPos (& tCurrent );
445+ ScreenToClient (tHwnd , & tCurrent );
446+ gptIOI -> add_mouse_pos_event ((float )tCurrent .x , (float )tCurrent .y );
447+ }
448+ }
449+ free (ptRaw );
450+ }
451+ break ;
452+ }
453+
431454 case WM_MOUSEMOVE :
432455 {
433456 tMouseHandle = tHwnd ;
@@ -844,7 +867,31 @@ pl_get_window_attribute(plWindow* ptWindow, plWindowAttribute tAttribute, plWind
844867bool
845868pl_set_cursor_mode (plWindow * ptWindow , plCursorMode tMode )
846869{
847- return tMode == PL_CURSOR_MODE_NORMAL ;
870+ HWND tHwnd = (HWND )ptWindow -> _pBackendData ;
871+
872+ if (tMode == PL_CURSOR_MODE_NORMAL )
873+ {
874+ ShowCursor (true);
875+ ClipCursor (NULL );
876+ return true;
877+ }
878+ else if (tMode == PL_CURSOR_MODE_HIDDEN )
879+ {
880+ ShowCursor (false);
881+ ClipCursor (NULL );
882+ return true;
883+ }
884+ else if (tMode == PL_CURSOR_MODE_DISABLED )
885+ {
886+ ShowCursor (false);
887+ RECT tRect ;
888+ GetClientRect (tHwnd , & tRect );
889+ MapWindowPoints (tHwnd , NULL , (POINT * )& tRect , 2 );
890+ ClipCursor (& tRect );
891+ return true;
892+ }
893+
894+ return false;
848895}
849896
850897plCursorMode
@@ -856,7 +903,23 @@ pl_get_cursor_mode(plWindow* ptWindow)
856903bool
857904pl_set_raw_mouse_input (plWindow * ptWindow , bool bValue )
858905{
859- return !bValue ;
906+ HWND tHwnd = (HWND )ptWindow -> _pBackendData ;
907+ RAWINPUTDEVICE tRid = {
908+ .usUsagePage = 0x01 ,
909+ .usUsage = 0x02 ,
910+ .dwFlags = bValue ? 0 : RIDEV_REMOVE ,
911+ .hwndTarget = bValue ? tHwnd : NULL
912+ };
913+ return RegisterRawInputDevices (& tRid , 1 , sizeof (tRid ));
914+ }
915+
916+ bool
917+ pl_set_mouse_pos (plWindow * ptWindow , plVec2 tPos )
918+ {
919+ HWND tHwnd = (HWND )ptWindow -> _pBackendData ;
920+ POINT tPoint = {(LONG )tPos .x , (LONG )tPos .y };
921+ ClientToScreen (tHwnd , & tPoint );
922+ return SetCursorPos (tPoint .x , tPoint .y );
860923}
861924
862925bool
@@ -868,29 +931,31 @@ pl_set_fullscreen(plWindow* ptWindow, const plFullScreenDesc* tDesc)
868931const plWindowCapabilities *
869932pl_get_window_capabilities (void )
870933{
871- static plWindowCapabilities tCapabilities = {};
934+ static plWindowCapabilities tCapabilities = {0 };
872935
873- tCapabilities .uCursorModeCount = 1 ;
874- tCapabilities .uAttributeCount = 1 ;
936+ tCapabilities .uCursorModeCount = 3 ;
937+ tCapabilities .uAttributeCount = 1 ;
875938 tCapabilities .uFullScreenModeCount = 2 ;
876939
877940 static const plWindowAttribute atSupportedAttributes [] = {
878941 -1
879942 };
880943
881944 static const plCursorMode atSupportedCursorModes [] = {
882- PL_CURSOR_MODE_NORMAL
945+ PL_CURSOR_MODE_NORMAL ,
946+ PL_CURSOR_MODE_HIDDEN ,
947+ PL_CURSOR_MODE_DISABLED
883948 };
884949
885950 static const plFullScreenMode atSupportedScreenModes [] = {
886951 PL_FULLSCREEN_MODE_NONE ,
887952 PL_FULLSCREEN_MODE_EXCLUSIVE
888953 };
889954
890- tCapabilities .atCursorModes = atSupportedCursorModes ;
891- tCapabilities .atFullScreenModes = atSupportedScreenModes ;
892- tCapabilities .atWindowAttributes = atSupportedAttributes ;
893- tCapabilities .tFlags = PL_WINDOW_CAPABILITY_FLAGS_NONE ;
955+ tCapabilities .atCursorModes = atSupportedCursorModes ;
956+ tCapabilities .atFullScreenModes = atSupportedScreenModes ;
957+ tCapabilities .atWindowAttributes = atSupportedAttributes ;
958+ tCapabilities .tFlags = PL_WINDOW_CAPABILITY_FLAGS_RAW_MOUSE_INPUT ;
894959
895960 return & tCapabilities ;
896961}
0 commit comments