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

input_source.h (3538B)


      1 // SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
      2 // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
      3 
      4 #pragma once
      5 
      6 #include <memory>
      7 #include <mutex>
      8 #include <optional>
      9 #include <string_view>
     10 #include <utility>
     11 #include <vector>
     12 
     13 #include "common/small_string.h"
     14 #include "common/types.h"
     15 #include "input_manager.h"
     16 
     17 class SettingsInterface;
     18 
     19 class InputSource
     20 {
     21 public:
     22   InputSource();
     23   virtual ~InputSource();
     24 
     25   virtual bool Initialize(SettingsInterface& si, std::unique_lock<std::mutex>& settings_lock) = 0;
     26   virtual void UpdateSettings(SettingsInterface& si, std::unique_lock<std::mutex>& settings_lock) = 0;
     27   virtual bool ReloadDevices() = 0;
     28   virtual void Shutdown() = 0;
     29 
     30   virtual void PollEvents() = 0;
     31 
     32   virtual std::optional<InputBindingKey> ParseKeyString(std::string_view device, std::string_view binding) = 0;
     33   virtual TinyString ConvertKeyToString(InputBindingKey key) = 0;
     34   virtual TinyString ConvertKeyToIcon(InputBindingKey key) = 0;
     35 
     36   /// Enumerates available devices. Returns a pair of the prefix (e.g. SDL-0) and the device name.
     37   virtual std::vector<std::pair<std::string, std::string>> EnumerateDevices() = 0;
     38 
     39   /// Enumerates available vibration motors at the time of call.
     40   virtual std::vector<InputBindingKey> EnumerateMotors() = 0;
     41 
     42   /// Retrieves bindings that match the generic bindings for the specified device.
     43   /// Returns false if it's not one of our devices.
     44   virtual bool GetGenericBindingMapping(std::string_view device, GenericInputBindingMapping* mapping) = 0;
     45 
     46   /// Informs the source of a new vibration motor state. Changes may not take effect until the next PollEvents() call.
     47   virtual void UpdateMotorState(InputBindingKey key, float intensity) = 0;
     48 
     49   /// Concurrently update both motors where possible, to avoid redundant packets.
     50   virtual void UpdateMotorState(InputBindingKey large_key, InputBindingKey small_key, float large_intensity,
     51                                 float small_intensity);
     52 
     53   /// Creates a key for a generic controller axis event.
     54   static InputBindingKey MakeGenericControllerAxisKey(InputSourceType clazz, u32 controller_index, s32 axis_index);
     55 
     56   /// Creates a key for a generic controller button event.
     57   static InputBindingKey MakeGenericControllerButtonKey(InputSourceType clazz, u32 controller_index, s32 button_index);
     58 
     59   /// Creates a key for a generic controller hat event.
     60   static InputBindingKey MakeGenericControllerHatKey(InputSourceType clazz, u32 controller_index, s32 hat_index,
     61                                                      u8 hat_direction, u32 num_directions);
     62 
     63   /// Creates a key for a generic controller motor event.
     64   static InputBindingKey MakeGenericControllerMotorKey(InputSourceType clazz, u32 controller_index, s32 motor_index);
     65 
     66   /// Parses a generic controller key string.
     67   static std::optional<InputBindingKey> ParseGenericControllerKey(InputSourceType clazz, std::string_view source,
     68                                                                   std::string_view sub_binding);
     69 
     70   /// Converts a generic controller key to a string.
     71   static std::string ConvertGenericControllerKeyToString(InputBindingKey key);
     72 
     73 #ifdef _WIN32
     74   static std::unique_ptr<InputSource> CreateDInputSource();
     75   static std::unique_ptr<InputSource> CreateXInputSource();
     76   static std::unique_ptr<InputSource> CreateWin32RawInputSource();
     77 #endif
     78 #ifndef __ANDROID__
     79   static std::unique_ptr<InputSource> CreateSDLSource();
     80 #else
     81   static std::unique_ptr<InputSource> CreateAndroidSource();
     82 #endif
     83 };