2022-03-17 15:53:45 +01:00
|
|
|
#pragma once
|
|
|
|
|
2022-06-09 12:46:55 +02:00
|
|
|
#include "../../defines.hpp"
|
2022-03-18 23:25:26 +01:00
|
|
|
#include <list>
|
2024-04-21 17:29:30 +02:00
|
|
|
#include <any>
|
2022-06-09 12:46:55 +02:00
|
|
|
#include "../../helpers/WLClasses.hpp"
|
2022-06-24 23:27:02 +02:00
|
|
|
#include "../../helpers/Timer.hpp"
|
2022-08-05 13:03:37 +02:00
|
|
|
#include "InputMethodRelay.hpp"
|
2024-04-21 02:47:38 +02:00
|
|
|
#include "../../helpers/signal/Listener.hpp"
|
2022-03-17 15:53:45 +01:00
|
|
|
|
2024-04-27 00:55:41 +02:00
|
|
|
class CPointerConstraint;
|
2024-03-20 02:44:51 +01:00
|
|
|
class CWindow;
|
2024-04-21 17:29:30 +02:00
|
|
|
class CIdleInhibitor;
|
2024-05-03 01:31:48 +02:00
|
|
|
class CVirtualKeyboard;
|
2024-03-02 22:04:55 +01:00
|
|
|
|
2023-12-06 23:54:56 +01:00
|
|
|
enum eClickBehaviorMode {
|
2022-06-27 13:42:20 +02:00
|
|
|
CLICKMODE_DEFAULT = 0,
|
|
|
|
CLICKMODE_KILL
|
|
|
|
};
|
|
|
|
|
2023-12-06 23:54:56 +01:00
|
|
|
enum eMouseBindMode {
|
2023-08-08 18:52:20 +02:00
|
|
|
MBIND_INVALID = -1,
|
|
|
|
MBIND_MOVE = 0,
|
|
|
|
MBIND_RESIZE = 1,
|
|
|
|
MBIND_RESIZE_BLOCK_RATIO = 2,
|
|
|
|
MBIND_RESIZE_FORCE_RATIO = 3
|
2022-09-19 20:04:48 +02:00
|
|
|
};
|
|
|
|
|
2023-12-06 23:54:56 +01:00
|
|
|
enum eBorderIconDirection {
|
2023-02-18 23:35:31 +01:00
|
|
|
BORDERICON_NONE,
|
|
|
|
BORDERICON_UP,
|
|
|
|
BORDERICON_DOWN,
|
|
|
|
BORDERICON_LEFT,
|
|
|
|
BORDERICON_RIGHT,
|
|
|
|
BORDERICON_UP_LEFT,
|
|
|
|
BORDERICON_DOWN_LEFT,
|
|
|
|
BORDERICON_UP_RIGHT,
|
|
|
|
BORDERICON_DOWN_RIGHT,
|
|
|
|
};
|
|
|
|
|
2022-08-07 21:17:03 +02:00
|
|
|
struct STouchData {
|
2024-04-30 03:41:27 +02:00
|
|
|
PHLWINDOWREF touchFocusWindow;
|
|
|
|
PHLLSREF touchFocusLS;
|
|
|
|
wlr_surface* touchFocusSurface = nullptr;
|
|
|
|
Vector2D touchSurfaceOrigin;
|
2022-08-07 21:17:03 +02:00
|
|
|
};
|
|
|
|
|
2023-01-15 20:38:58 +01:00
|
|
|
// The third row is always 0 0 1 and is not expected by `libinput_device_config_calibration_set_matrix`
|
2023-01-17 11:47:39 +01:00
|
|
|
static const float MATRICES[8][6] = {{// normal
|
|
|
|
1, 0, 0, 0, 1, 0},
|
|
|
|
{// rotation 90°
|
|
|
|
0, -1, 1, 1, 0, 0},
|
|
|
|
{// rotation 180°
|
|
|
|
-1, 0, 1, 0, -1, 1},
|
|
|
|
{// rotation 270°
|
|
|
|
0, 1, 0, -1, 0, 1},
|
|
|
|
{// flipped
|
|
|
|
-1, 0, 1, 0, 1, 0},
|
|
|
|
{// flipped + rotation 90°
|
|
|
|
0, 1, 0, 1, 0, 0},
|
|
|
|
{// flipped + rotation 180°
|
|
|
|
1, 0, 0, 0, -1, 1},
|
|
|
|
{// flipped + rotation 270°
|
|
|
|
0, -1, 1, -1, 0, 1}};
|
2023-01-15 20:38:58 +01:00
|
|
|
|
2022-11-25 12:34:29 +01:00
|
|
|
class CKeybindManager;
|
|
|
|
|
2022-03-17 15:53:45 +01:00
|
|
|
class CInputManager {
|
2022-12-16 18:17:31 +01:00
|
|
|
public:
|
2024-04-21 02:47:38 +02:00
|
|
|
CInputManager();
|
2023-11-12 15:03:46 +01:00
|
|
|
~CInputManager();
|
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
void onMouseMoved(wlr_pointer_motion_event*);
|
|
|
|
void onMouseWarp(wlr_pointer_motion_absolute_event*);
|
|
|
|
void onMouseButton(wlr_pointer_button_event*);
|
|
|
|
void onMouseWheel(wlr_pointer_axis_event*);
|
|
|
|
void onKeyboardKey(wlr_keyboard_key_event*, SKeyboard*);
|
|
|
|
void onKeyboardMod(void*, SKeyboard*);
|
|
|
|
|
|
|
|
void newKeyboard(wlr_input_device*);
|
2024-05-03 01:31:48 +02:00
|
|
|
void newVirtualKeyboard(SP<CVirtualKeyboard>);
|
2022-12-16 18:17:31 +01:00
|
|
|
void newMouse(wlr_input_device*, bool virt = false);
|
|
|
|
void newTouchDevice(wlr_input_device*);
|
|
|
|
void newSwitch(wlr_input_device*);
|
|
|
|
void destroyTouchDevice(STouchDevice*);
|
|
|
|
void destroyKeyboard(SKeyboard*);
|
|
|
|
void destroyMouse(wlr_input_device*);
|
|
|
|
void destroySwitch(SSwitchDevice*);
|
|
|
|
|
|
|
|
void unconstrainMouse();
|
2024-03-02 22:04:55 +01:00
|
|
|
bool isConstrained();
|
2022-12-16 18:17:31 +01:00
|
|
|
std::string getActiveLayoutForKeyboard(SKeyboard*);
|
|
|
|
|
|
|
|
Vector2D getMouseCoordsInternal();
|
|
|
|
void refocus();
|
2023-01-31 01:26:15 +01:00
|
|
|
void simulateMouseMovement();
|
2023-09-13 12:33:36 +02:00
|
|
|
void sendMotionEventsToFocused();
|
2022-12-16 18:17:31 +01:00
|
|
|
|
|
|
|
void setKeyboardLayout();
|
|
|
|
void setPointerConfigs();
|
2023-05-24 22:17:33 +02:00
|
|
|
void setTouchDeviceConfigs(STouchDevice* dev = nullptr);
|
2022-12-21 16:11:39 +01:00
|
|
|
void setTabletConfigs();
|
2022-12-16 18:17:31 +01:00
|
|
|
|
|
|
|
void updateDragIcon();
|
|
|
|
void updateCapabilities();
|
|
|
|
|
|
|
|
void setClickMode(eClickBehaviorMode);
|
2022-06-27 13:42:20 +02:00
|
|
|
eClickBehaviorMode getClickMode();
|
2023-07-24 18:50:17 +02:00
|
|
|
void processMouseRequest(wlr_seat_pointer_request_set_cursor_event* e);
|
2022-06-27 13:42:20 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
void onTouchDown(wlr_touch_down_event*);
|
|
|
|
void onTouchUp(wlr_touch_up_event*);
|
|
|
|
void onTouchMove(wlr_touch_motion_event*);
|
2022-08-07 21:17:03 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
STouchData m_sTouchData;
|
2022-03-20 11:14:24 +01:00
|
|
|
|
|
|
|
// for dragging floating windows
|
2024-04-27 13:43:12 +02:00
|
|
|
PHLWINDOWREF currentlyDraggedWindow;
|
|
|
|
eMouseBindMode dragMode = MBIND_INVALID;
|
|
|
|
bool m_bWasDraggingWindow = false;
|
2023-05-31 20:59:38 +02:00
|
|
|
|
|
|
|
// for refocus to be forced
|
2024-04-27 13:43:12 +02:00
|
|
|
PHLWINDOWREF m_pForcedFocus;
|
2022-03-20 11:14:24 +01:00
|
|
|
|
2024-03-02 22:04:55 +01:00
|
|
|
SDrag m_sDrag;
|
2022-03-31 17:25:23 +02:00
|
|
|
|
2024-03-02 22:04:55 +01:00
|
|
|
std::list<SKeyboard> m_lKeyboards;
|
|
|
|
std::list<SMouse> m_lMice;
|
2022-04-17 21:40:04 +02:00
|
|
|
|
2022-06-09 12:46:55 +02:00
|
|
|
// tablets
|
2022-12-16 18:17:31 +01:00
|
|
|
std::list<STablet> m_lTablets;
|
|
|
|
std::list<STabletTool> m_lTabletTools;
|
|
|
|
std::list<STabletPad> m_lTabletPads;
|
2022-06-09 12:46:55 +02:00
|
|
|
|
2022-09-21 15:39:25 +02:00
|
|
|
// Touch devices
|
|
|
|
std::list<STouchDevice> m_lTouchDevices;
|
|
|
|
|
2022-10-04 21:07:21 +02:00
|
|
|
// Switches
|
|
|
|
std::list<SSwitchDevice> m_lSwitches;
|
|
|
|
|
2024-01-19 16:45:34 +01:00
|
|
|
// Exclusive layer surfaces
|
2024-04-30 03:41:27 +02:00
|
|
|
std::deque<PHLLSREF> m_dExclusiveLSes;
|
2022-06-09 12:46:55 +02:00
|
|
|
|
2024-03-02 22:04:55 +01:00
|
|
|
// constraints
|
2024-04-27 00:55:41 +02:00
|
|
|
std::vector<std::weak_ptr<CPointerConstraint>> m_vConstraints;
|
2024-03-02 22:04:55 +01:00
|
|
|
|
2024-04-27 00:55:41 +02:00
|
|
|
//
|
|
|
|
void newTabletTool(wlr_input_device*);
|
|
|
|
void newTabletPad(wlr_input_device*);
|
|
|
|
void focusTablet(STablet*, wlr_tablet_tool*, bool motion = false);
|
|
|
|
void newIdleInhibitor(std::any);
|
|
|
|
void recheckIdleInhibitorStatus();
|
2022-07-07 11:52:12 +02:00
|
|
|
|
2024-04-27 00:55:41 +02:00
|
|
|
void onSwipeBegin(wlr_pointer_swipe_begin_event*);
|
|
|
|
void onSwipeEnd(wlr_pointer_swipe_end_event*);
|
|
|
|
void onSwipeUpdate(wlr_pointer_swipe_update_event*);
|
2022-06-09 12:46:55 +02:00
|
|
|
|
2024-04-27 00:55:41 +02:00
|
|
|
SSwipeGesture m_sActiveSwipe;
|
2022-06-03 18:59:39 +02:00
|
|
|
|
2024-04-27 00:55:41 +02:00
|
|
|
SKeyboard* m_pActiveKeyboard = nullptr;
|
2022-06-24 23:27:02 +02:00
|
|
|
|
2024-04-27 00:55:41 +02:00
|
|
|
CTimer m_tmrLastCursorMovement;
|
2022-08-05 13:03:37 +02:00
|
|
|
|
2024-04-27 00:55:41 +02:00
|
|
|
CInputMethodRelay m_sIMERelay;
|
2024-01-19 16:45:34 +01:00
|
|
|
|
2024-04-27 00:55:41 +02:00
|
|
|
void updateKeyboardsLeds(wlr_input_device* pKeyboard);
|
2022-11-12 12:12:37 +01:00
|
|
|
|
2022-07-20 22:45:06 +02:00
|
|
|
// for shared mods
|
2022-12-16 18:17:31 +01:00
|
|
|
uint32_t accumulateModsFromAllKBs();
|
2022-07-20 22:45:06 +02:00
|
|
|
|
2022-11-07 23:22:13 +01:00
|
|
|
// for virtual keyboards: whether we should respect them as normal ones
|
2022-12-16 18:17:31 +01:00
|
|
|
bool shouldIgnoreVirtualKeyboard(SKeyboard*);
|
2022-11-07 23:22:13 +01:00
|
|
|
|
2022-11-15 11:39:05 +01:00
|
|
|
// for special cursors that we choose
|
2022-12-16 18:17:31 +01:00
|
|
|
void setCursorImageUntilUnset(std::string);
|
|
|
|
void unsetCursorImage();
|
2022-11-15 11:39:05 +01:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
std::string deviceNameToInternalString(std::string);
|
|
|
|
std::string getNameForNewDevice(std::string);
|
2022-12-03 16:56:07 +01:00
|
|
|
|
2023-01-11 18:38:54 +01:00
|
|
|
void releaseAllMouseButtons();
|
|
|
|
|
|
|
|
// for some bugs in follow mouse 0
|
|
|
|
bool m_bLastFocusOnLS = false;
|
|
|
|
|
2024-04-07 16:15:50 +02:00
|
|
|
bool m_bLastFocusOnIMEPopup = false;
|
|
|
|
|
2023-01-17 11:47:39 +01:00
|
|
|
// for hiding cursor on touch
|
|
|
|
bool m_bLastInputTouch = false;
|
|
|
|
|
2023-04-25 17:00:34 +02:00
|
|
|
// for tracking mouse refocus
|
2024-04-27 13:43:12 +02:00
|
|
|
PHLWINDOWREF m_pLastMouseFocus;
|
2023-09-23 02:21:59 +02:00
|
|
|
wlr_surface* m_pLastMouseSurface = nullptr;
|
2023-04-25 17:00:34 +02:00
|
|
|
|
2024-03-09 19:12:55 +01:00
|
|
|
//
|
|
|
|
bool m_bEmptyFocusCursorSet = false;
|
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
private:
|
2024-04-21 02:47:38 +02:00
|
|
|
// Listeners
|
|
|
|
struct {
|
|
|
|
CHyprSignalListener setCursorShape;
|
2024-04-21 17:29:30 +02:00
|
|
|
CHyprSignalListener newIdleInhibitor;
|
2024-05-03 01:31:48 +02:00
|
|
|
CHyprSignalListener newVirtualKeyboard;
|
2024-04-21 02:47:38 +02:00
|
|
|
} m_sListeners;
|
|
|
|
|
2023-03-30 00:44:25 +02:00
|
|
|
bool m_bCursorImageOverridden = false;
|
2023-03-30 01:34:24 +02:00
|
|
|
eBorderIconDirection m_eBorderIconDirection = BORDERICON_NONE;
|
2022-11-15 11:39:05 +01:00
|
|
|
|
2022-06-27 13:42:20 +02:00
|
|
|
// for click behavior override
|
2022-12-16 18:17:31 +01:00
|
|
|
eClickBehaviorMode m_ecbClickBehavior = CLICKMODE_DEFAULT;
|
|
|
|
Vector2D m_vLastCursorPosFloored = Vector2D();
|
2022-06-27 13:42:20 +02:00
|
|
|
|
2023-01-11 18:38:54 +01:00
|
|
|
void processMouseDownNormal(wlr_pointer_button_event* e);
|
|
|
|
void processMouseDownKill(wlr_pointer_button_event* e);
|
2022-06-27 13:42:20 +02:00
|
|
|
|
2023-07-24 18:50:17 +02:00
|
|
|
bool cursorImageUnlocked();
|
|
|
|
|
2023-01-11 18:38:54 +01:00
|
|
|
void disableAllKeyboards(bool virt = false);
|
2022-08-18 17:50:32 +02:00
|
|
|
|
2023-01-11 18:38:54 +01:00
|
|
|
uint32_t m_uiCapabilities = 0;
|
2022-06-09 12:46:55 +02:00
|
|
|
|
2023-01-11 18:38:54 +01:00
|
|
|
void mouseMoveUnified(uint32_t, bool refocus = false);
|
2022-06-09 12:46:55 +02:00
|
|
|
|
2023-01-11 18:38:54 +01:00
|
|
|
STabletTool* ensureTabletToolPresent(wlr_tablet_tool*);
|
2022-06-23 15:48:31 +02:00
|
|
|
|
2023-01-11 18:38:54 +01:00
|
|
|
void applyConfigToKeyboard(SKeyboard*);
|
2022-10-14 21:46:32 +02:00
|
|
|
|
|
|
|
// this will be set after a refocus()
|
2024-04-30 03:41:27 +02:00
|
|
|
wlr_surface* m_pFoundSurfaceToFocus = nullptr;
|
|
|
|
PHLLSREF m_pFoundLSToFocus;
|
|
|
|
PHLWINDOWREF m_pFoundWindowToFocus;
|
2022-11-03 14:34:06 +01:00
|
|
|
|
2023-04-02 14:30:45 +02:00
|
|
|
// for holding focus on buttons held
|
|
|
|
bool m_bFocusHeldByButtons = false;
|
|
|
|
bool m_bRefocusHeldByButtons = false;
|
|
|
|
|
2023-01-11 18:38:54 +01:00
|
|
|
// for releasing mouse buttons
|
|
|
|
std::list<uint32_t> m_lCurrentlyHeldButtons;
|
|
|
|
|
2024-04-21 17:29:30 +02:00
|
|
|
// idle inhibitors
|
|
|
|
struct SIdleInhibitor {
|
|
|
|
std::shared_ptr<CIdleInhibitor> inhibitor;
|
2024-04-27 13:43:12 +02:00
|
|
|
PHLWINDOWREF pWindow;
|
2024-04-21 17:29:30 +02:00
|
|
|
CHyprSignalListener windowDestroyListener;
|
|
|
|
};
|
|
|
|
std::vector<std::unique_ptr<SIdleInhibitor>> m_vIdleInhibitors;
|
|
|
|
|
2022-11-03 14:34:06 +01:00
|
|
|
// swipe
|
2022-12-16 18:17:31 +01:00
|
|
|
void beginWorkspaceSwipe();
|
2024-03-17 16:43:59 +01:00
|
|
|
void updateWorkspaceSwipe(double);
|
|
|
|
void endWorkspaceSwipe();
|
2022-11-25 12:34:29 +01:00
|
|
|
|
2023-02-18 23:35:31 +01:00
|
|
|
void setBorderCursorIcon(eBorderIconDirection);
|
2024-04-27 13:43:12 +02:00
|
|
|
void setCursorIconOnBorder(PHLWINDOW w);
|
2023-02-18 23:35:31 +01:00
|
|
|
|
2023-10-29 19:09:05 +01:00
|
|
|
// temporary. Obeys setUntilUnset.
|
|
|
|
void setCursorImageOverride(const std::string& name);
|
|
|
|
|
2023-03-01 00:06:46 +01:00
|
|
|
// cursor surface
|
2023-10-29 19:09:05 +01:00
|
|
|
struct cursorSI {
|
|
|
|
bool hidden = false; // null surface = hidden
|
|
|
|
CWLSurface wlSurface;
|
|
|
|
Vector2D vHotspot;
|
|
|
|
std::string name; // if not empty, means set by name.
|
|
|
|
bool inUse = false;
|
|
|
|
} m_sCursorSurfaceInfo;
|
|
|
|
|
|
|
|
void restoreCursorIconToApp(); // no-op if restored
|
2023-03-01 00:06:46 +01:00
|
|
|
|
2022-11-25 12:34:29 +01:00
|
|
|
friend class CKeybindManager;
|
2023-10-29 19:09:05 +01:00
|
|
|
friend class CWLSurface;
|
2022-03-17 15:53:45 +01:00
|
|
|
};
|
|
|
|
|
2022-09-25 20:07:48 +02:00
|
|
|
inline std::unique_ptr<CInputManager> g_pInputManager;
|