Merge pull request #265 from xDarksome/main

Scroll workspaces with Super+MouseWheel
This commit is contained in:
Vaxry 2022-07-21 19:40:15 +02:00 committed by GitHub
commit a011c28227
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 53 additions and 18 deletions

View file

@ -102,3 +102,6 @@ bind=ALT,7,movetoworkspace,7
bind=ALT,8,movetoworkspace,8 bind=ALT,8,movetoworkspace,8
bind=ALT,9,movetoworkspace,9 bind=ALT,9,movetoworkspace,9
bind=ALT,0,movetoworkspace,10 bind=ALT,0,movetoworkspace,10
bind=SUPER,mouse_down,workspace,e+1
bind=SUPER,mouse_up,workspace,e-1

View file

@ -111,4 +111,7 @@ bind=ALT,7,movetoworkspace,7
bind=ALT,8,movetoworkspace,8 bind=ALT,8,movetoworkspace,8
bind=ALT,9,movetoworkspace,9 bind=ALT,9,movetoworkspace,9
bind=ALT,0,movetoworkspace,10 bind=ALT,0,movetoworkspace,10
bind=SUPER,mouse_down,workspace,e+1
bind=SUPER,mouse_up,workspace,e-1
)#"; )#";

View file

@ -49,9 +49,7 @@ void Events::listener_mouseButton(wl_listener* listener, void* data) {
} }
void Events::listener_mouseAxis(wl_listener* listener, void* data) { void Events::listener_mouseAxis(wl_listener* listener, void* data) {
const auto E = (wlr_pointer_axis_event*)data; g_pInputManager->onMouseWheel((wlr_pointer_axis_event*)data);
wlr_seat_pointer_notify_axis(g_pCompositor->m_sSeat.seat, E->time_msec, E->orientation, E->delta, E->delta_discrete, E->source);
} }
void Events::listener_requestMouse(wl_listener* listener, void* data) { void Events::listener_requestMouse(wl_listener* listener, void* data) {

View file

@ -217,7 +217,9 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) {
} }
outName = WORKSPACENAME; outName = WORKSPACENAME;
} else { } else {
if (in[0] == 'm') { if (in[0] == 'm' || in[0] == 'e') {
bool onAllMonitors = in[0] == 'e';
if (!g_pCompositor->m_pLastMonitor) { if (!g_pCompositor->m_pLastMonitor) {
Debug::log(ERR, "Relative monitor workspace on monitor null!"); Debug::log(ERR, "Relative monitor workspace on monitor null!");
result = INT_MAX; result = INT_MAX;
@ -258,7 +260,7 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) {
} }
if (const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(searchID); PWORKSPACE && PWORKSPACE->m_iID != SPECIAL_WORKSPACE_ID) { if (const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(searchID); PWORKSPACE && PWORKSPACE->m_iID != SPECIAL_WORKSPACE_ID) {
if (PWORKSPACE->m_iMonitorID == g_pCompositor->m_pLastMonitor->ID) { if (onAllMonitors || PWORKSPACE->m_iMonitorID == g_pCompositor->m_pLastMonitor->ID) {
currentID = PWORKSPACE->m_iID; currentID = PWORKSPACE->m_iID;
if (remains < 0) if (remains < 0)

View file

@ -95,17 +95,17 @@ bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard
m_dPressedKeycodes.push_back(KEYCODE); m_dPressedKeycodes.push_back(KEYCODE);
m_dPressedKeysyms.push_back(keysym); m_dPressedKeysyms.push_back(keysym);
found = g_pKeybindManager->handleKeybinds(MODS, keysym, 0, true, e->time_msec) || found; found = g_pKeybindManager->handleKeybinds(MODS, "", keysym, 0, true, e->time_msec) || found;
found = g_pKeybindManager->handleKeybinds(MODS, 0, KEYCODE, true, e->time_msec) || found; found = g_pKeybindManager->handleKeybinds(MODS, "", 0, KEYCODE, true, e->time_msec) || found;
} else if (e->state == WL_KEYBOARD_KEY_STATE_RELEASED) { } else if (e->state == WL_KEYBOARD_KEY_STATE_RELEASED) {
m_dPressedKeycodes.erase(std::remove(m_dPressedKeycodes.begin(), m_dPressedKeycodes.end(), KEYCODE)); m_dPressedKeycodes.erase(std::remove(m_dPressedKeycodes.begin(), m_dPressedKeycodes.end(), KEYCODE));
m_dPressedKeysyms.erase(std::remove(m_dPressedKeysyms.begin(), m_dPressedKeysyms.end(), keysym)); m_dPressedKeysyms.erase(std::remove(m_dPressedKeysyms.begin(), m_dPressedKeysyms.end(), keysym));
found = g_pKeybindManager->handleKeybinds(MODS, keysym, 0, false, e->time_msec) || found; found = g_pKeybindManager->handleKeybinds(MODS, "", keysym, 0, false, e->time_msec) || found;
found = g_pKeybindManager->handleKeybinds(MODS, 0, KEYCODE, false, e->time_msec) || found; found = g_pKeybindManager->handleKeybinds(MODS, "", 0, KEYCODE, false, e->time_msec) || found;
shadowKeybinds(); shadowKeybinds();
} }
@ -113,10 +113,25 @@ bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard
return !found; return !found;
} }
bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t& key, const int& keycode, bool pressed, uint32_t time) { bool CKeybindManager::onAxisEvent(wlr_pointer_axis_event* e) {
const auto MODS = g_pInputManager->accumulateModsFromAllKBs();
bool found = false;
if (e->source == WLR_AXIS_SOURCE_WHEEL && e->orientation == WLR_AXIS_ORIENTATION_VERTICAL) {
if (e->delta < 0) {
found = g_pKeybindManager->handleKeybinds(MODS, "mouse_down", 0, 0, true, 0);
} else {
found = g_pKeybindManager->handleKeybinds(MODS, "mouse_up", 0, 0, true, 0);
}
}
return !found;
}
bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const std::string& key, const xkb_keysym_t& keysym, const int& keycode, bool pressed, uint32_t time) {
bool found = false; bool found = false;
if (handleInternalKeybinds(key)) if (handleInternalKeybinds(keysym))
return true; return true;
if (g_pCompositor->m_sSeat.exclusiveClient) if (g_pCompositor->m_sSeat.exclusiveClient)
@ -132,12 +147,14 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t
if (modmask != k.modmask || (g_pCompositor->m_sSeat.exclusiveClient && !k.locked) || k.submap != m_szCurrentSelectedSubmap || (!pressed && !k.release) || k.shadowed) if (modmask != k.modmask || (g_pCompositor->m_sSeat.exclusiveClient && !k.locked) || k.submap != m_szCurrentSelectedSubmap || (!pressed && !k.release) || k.shadowed)
continue; continue;
if (k.keycode != -1) { if (!key.empty()) {
if (key != k.key)
continue;
} else if (k.keycode != -1) {
if (keycode != k.keycode) if (keycode != k.keycode)
continue; continue;
} else { } else {
if (key == 0) if (keysym == 0)
continue; // this is a keycode check run continue; // this is a keycode check run
// oMg such performance hit!!11! // oMg such performance hit!!11!
@ -146,13 +163,13 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t
const auto KBKEYUPPER = xkb_keysym_to_upper(KBKEY); const auto KBKEYUPPER = xkb_keysym_to_upper(KBKEY);
// small TODO: fix 0-9 keys and other modified ones with shift // small TODO: fix 0-9 keys and other modified ones with shift
if (key != KBKEY && key != KBKEYUPPER) if (keysym != KBKEY && keysym != KBKEYUPPER)
continue; continue;
} }
if (pressed && k.release) { if (pressed && k.release) {
// suppress down event // suppress down event
m_kHeldBack = key; m_kHeldBack = keysym;
return true; return true;
} }
@ -163,7 +180,7 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t
Debug::log(ERR, "Inavlid handler in a keybind! (handler %s does not exist)", k.handler.c_str()); Debug::log(ERR, "Inavlid handler in a keybind! (handler %s does not exist)", k.handler.c_str());
} else { } else {
// call the dispatcher // call the dispatcher
Debug::log(LOG, "Keybind triggered, calling dispatcher (%d, %d)", modmask, key); Debug::log(LOG, "Keybind triggered, calling dispatcher (%d, %s, %d)", modmask, key, keysym);
DISPATCHER->second(k.arg); DISPATCHER->second(k.arg);
} }

View file

@ -25,6 +25,7 @@ public:
CKeybindManager(); CKeybindManager();
bool onKeyEvent(wlr_keyboard_key_event*, SKeyboard*); bool onKeyEvent(wlr_keyboard_key_event*, SKeyboard*);
bool onAxisEvent(wlr_pointer_axis_event*);
void addKeybind(SKeybind); void addKeybind(SKeybind);
void removeKeybind(uint32_t, const std::string&); void removeKeybind(uint32_t, const std::string&);
@ -42,7 +43,7 @@ private:
xkb_keysym_t m_kHeldBack = 0; xkb_keysym_t m_kHeldBack = 0;
bool handleKeybinds(const uint32_t&, const xkb_keysym_t&, const int&, bool, uint32_t); bool handleKeybinds(const uint32_t&, const std::string&, const xkb_keysym_t&, const int&, bool, uint32_t);
void shadowKeybinds(); void shadowKeybinds();

View file

@ -381,6 +381,16 @@ void CInputManager::processMouseDownKill(wlr_pointer_button_event* e) {
m_ecbClickBehavior = CLICKMODE_DEFAULT; m_ecbClickBehavior = CLICKMODE_DEFAULT;
} }
void CInputManager::onMouseWheel(wlr_pointer_axis_event* e) {
bool passEvent = g_pKeybindManager->onAxisEvent(e);
wlr_idle_notify_activity(g_pCompositor->m_sWLRIdle, g_pCompositor->m_sSeat.seat);
if (passEvent) {
wlr_seat_pointer_notify_axis(g_pCompositor->m_sSeat.seat, e->time_msec, e->orientation, e->delta, e->delta_discrete, e->source);
}
}
Vector2D CInputManager::getMouseCoordsInternal() { Vector2D CInputManager::getMouseCoordsInternal() {
return Vector2D(g_pCompositor->m_sWLRCursor->x, g_pCompositor->m_sWLRCursor->y); return Vector2D(g_pCompositor->m_sWLRCursor->x, g_pCompositor->m_sWLRCursor->y);
} }

View file

@ -17,6 +17,7 @@ public:
void onMouseMoved(wlr_pointer_motion_event*); void onMouseMoved(wlr_pointer_motion_event*);
void onMouseWarp(wlr_pointer_motion_absolute_event*); void onMouseWarp(wlr_pointer_motion_absolute_event*);
void onMouseButton(wlr_pointer_button_event*); void onMouseButton(wlr_pointer_button_event*);
void onMouseWheel(wlr_pointer_axis_event*);
void onKeyboardKey(wlr_keyboard_key_event*, SKeyboard*); void onKeyboardKey(wlr_keyboard_key_event*, SKeyboard*);
void onKeyboardMod(void*, SKeyboard*); void onKeyboardMod(void*, SKeyboard*);