duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

win32_raw_input_source.h (1944B)


      1 // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
      2 // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
      3 
      4 #pragma once
      5 #include "common/windows_headers.h"
      6 #include "input_source.h"
      7 #include <array>
      8 #include <functional>
      9 #include <mutex>
     10 #include <vector>
     11 
     12 class SettingsInterface;
     13 
     14 class Win32RawInputSource final : public InputSource
     15 {
     16 public:
     17   Win32RawInputSource();
     18   ~Win32RawInputSource();
     19 
     20   bool Initialize(SettingsInterface& si, std::unique_lock<std::mutex>& settings_lock) override;
     21   void UpdateSettings(SettingsInterface& si, std::unique_lock<std::mutex>& settings_lock) override;
     22   bool ReloadDevices() override;
     23   void Shutdown() override;
     24 
     25   void PollEvents() override;
     26   std::vector<std::pair<std::string, std::string>> EnumerateDevices() override;
     27   std::vector<InputBindingKey> EnumerateMotors() override;
     28   bool GetGenericBindingMapping(std::string_view device, GenericInputBindingMapping* mapping) override;
     29   void UpdateMotorState(InputBindingKey key, float intensity) override;
     30   void UpdateMotorState(InputBindingKey large_key, InputBindingKey small_key, float large_intensity,
     31                         float small_intensity) override;
     32 
     33   std::optional<InputBindingKey> ParseKeyString(std::string_view device, std::string_view binding) override;
     34   TinyString ConvertKeyToString(InputBindingKey key) override;
     35   TinyString ConvertKeyToIcon(InputBindingKey key) override;
     36 
     37 private:
     38   struct MouseState
     39   {
     40     HANDLE device;
     41     u32 button_state;
     42     s32 last_x;
     43     s32 last_y;
     44   };
     45 
     46   static bool RegisterDummyClass();
     47   static LRESULT CALLBACK DummyWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
     48 
     49   static std::string GetMouseDeviceName(u32 index);
     50 
     51   bool CreateDummyWindow();
     52   void DestroyDummyWindow();
     53   bool OpenDevices();
     54   void CloseDevices();
     55 
     56   bool ProcessRawInputEvent(const RAWINPUT* event);
     57 
     58   HWND m_dummy_window = {};
     59 
     60   std::vector<MouseState> m_mice;
     61 };