2022-03-19 17:48:18 +01:00
|
|
|
#include "KeybindManager.hpp"
|
|
|
|
|
2022-06-10 12:06:27 +02:00
|
|
|
#include <regex>
|
|
|
|
|
2022-04-21 15:50:52 +02:00
|
|
|
CKeybindManager::CKeybindManager() {
|
|
|
|
// initialize all dispatchers
|
|
|
|
|
2022-05-18 12:18:58 +02:00
|
|
|
m_mDispatchers["exec"] = spawn;
|
|
|
|
m_mDispatchers["killactive"] = killActive;
|
|
|
|
m_mDispatchers["togglefloating"] = toggleActiveFloating;
|
|
|
|
m_mDispatchers["workspace"] = changeworkspace;
|
|
|
|
m_mDispatchers["fullscreen"] = fullscreenActive;
|
|
|
|
m_mDispatchers["movetoworkspace"] = moveActiveToWorkspace;
|
|
|
|
m_mDispatchers["movetoworkspacesilent"] = moveActiveToWorkspaceSilent;
|
|
|
|
m_mDispatchers["pseudo"] = toggleActivePseudo;
|
|
|
|
m_mDispatchers["movefocus"] = moveFocusTo;
|
|
|
|
m_mDispatchers["movewindow"] = moveActiveTo;
|
|
|
|
m_mDispatchers["togglegroup"] = toggleGroup;
|
|
|
|
m_mDispatchers["changegroupactive"] = changeGroupActive;
|
|
|
|
m_mDispatchers["togglesplit"] = toggleSplit;
|
|
|
|
m_mDispatchers["splitratio"] = alterSplitRatio;
|
|
|
|
m_mDispatchers["focusmonitor"] = focusMonitor;
|
2022-05-22 11:52:39 +02:00
|
|
|
m_mDispatchers["movecursortocorner"] = moveCursorToCorner;
|
2022-05-26 19:05:32 +02:00
|
|
|
m_mDispatchers["workspaceopt"] = workspaceOpt;
|
2022-05-29 00:00:47 +02:00
|
|
|
m_mDispatchers["exit"] = exitHyprland;
|
2022-05-30 20:05:38 +02:00
|
|
|
m_mDispatchers["movecurrentworkspacetomonitor"] = moveCurrentWorkspaceToMonitor;
|
|
|
|
m_mDispatchers["moveworkspacetomonitor"] = moveWorkspaceToMonitor;
|
2022-05-31 14:01:00 +02:00
|
|
|
m_mDispatchers["togglespecialworkspace"] = toggleSpecialWorkspace;
|
2022-06-06 13:48:17 +02:00
|
|
|
m_mDispatchers["forcerendererreload"] = forceRendererReload;
|
2022-06-06 19:32:14 +02:00
|
|
|
m_mDispatchers["resizeactive"] = resizeActive;
|
2022-06-23 10:14:59 +02:00
|
|
|
m_mDispatchers["moveactive"] = moveActive;
|
2022-06-10 11:41:52 +02:00
|
|
|
m_mDispatchers["cyclenext"] = circleNext;
|
2022-07-01 16:24:37 +02:00
|
|
|
m_mDispatchers["focuswindowbyclass"] = focusWindow;
|
|
|
|
m_mDispatchers["focuswindow"] = focusWindow;
|
2022-06-22 20:23:20 +02:00
|
|
|
m_mDispatchers["submap"] = setSubmap;
|
2022-04-21 15:50:52 +02:00
|
|
|
}
|
|
|
|
|
2022-03-19 17:48:18 +01:00
|
|
|
void CKeybindManager::addKeybind(SKeybind kb) {
|
2022-04-21 17:06:43 +02:00
|
|
|
m_lKeybinds.push_back(kb);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CKeybindManager::removeKeybind(uint32_t mod, const std::string& key) {
|
|
|
|
for (auto it = m_lKeybinds.begin(); it != m_lKeybinds.end(); ++it) {
|
2022-07-08 09:32:09 +02:00
|
|
|
if (isNumber(key) && std::stoi(key) > 9) {
|
|
|
|
const auto KEYNUM = std::stoi(key);
|
|
|
|
|
|
|
|
if (it->modmask == mod && it->keycode == KEYNUM) {
|
|
|
|
it = m_lKeybinds.erase(it);
|
|
|
|
|
|
|
|
if (it == m_lKeybinds.end())
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (it->modmask == mod && it->key == key) {
|
2022-04-21 17:06:43 +02:00
|
|
|
it = m_lKeybinds.erase(it);
|
2022-07-08 09:32:09 +02:00
|
|
|
|
|
|
|
if (it == m_lKeybinds.end())
|
|
|
|
break;
|
2022-04-21 17:06:43 +02:00
|
|
|
}
|
|
|
|
}
|
2022-03-19 17:48:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t CKeybindManager::stringToModMask(std::string mods) {
|
|
|
|
uint32_t modMask = 0;
|
2022-07-06 16:50:11 +02:00
|
|
|
if (mods.contains("SHIFT"))
|
2022-03-19 17:48:18 +01:00
|
|
|
modMask |= WLR_MODIFIER_SHIFT;
|
2022-07-06 16:50:11 +02:00
|
|
|
if (mods.contains("CAPS"))
|
2022-03-19 17:48:18 +01:00
|
|
|
modMask |= WLR_MODIFIER_CAPS;
|
2022-07-06 16:50:11 +02:00
|
|
|
if (mods.contains("CTRL") || mods.contains("CONTROL"))
|
2022-03-19 17:48:18 +01:00
|
|
|
modMask |= WLR_MODIFIER_CTRL;
|
2022-07-06 16:50:11 +02:00
|
|
|
if (mods.contains("ALT"))
|
2022-03-19 17:48:18 +01:00
|
|
|
modMask |= WLR_MODIFIER_ALT;
|
2022-07-06 16:50:11 +02:00
|
|
|
if (mods.contains("MOD2"))
|
2022-03-19 17:48:18 +01:00
|
|
|
modMask |= WLR_MODIFIER_MOD2;
|
2022-07-06 16:50:11 +02:00
|
|
|
if (mods.contains("MOD3"))
|
2022-03-19 17:48:18 +01:00
|
|
|
modMask |= WLR_MODIFIER_MOD3;
|
2022-07-06 16:50:11 +02:00
|
|
|
if (mods.contains("SUPER") || mods.contains("WIN") || mods.contains("LOGO") || mods.contains("MOD4"))
|
2022-03-19 17:48:18 +01:00
|
|
|
modMask |= WLR_MODIFIER_LOGO;
|
2022-07-06 16:50:11 +02:00
|
|
|
if (mods.contains("MOD5"))
|
2022-03-19 17:48:18 +01:00
|
|
|
modMask |= WLR_MODIFIER_MOD5;
|
|
|
|
|
|
|
|
return modMask;
|
|
|
|
}
|
|
|
|
|
2022-07-20 22:45:06 +02:00
|
|
|
bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard) {
|
|
|
|
const auto KEYCODE = e->keycode + 8; // Because to xkbcommon it's +8 from libinput
|
|
|
|
|
2022-07-20 23:17:26 +02:00
|
|
|
const xkb_keysym_t keysym = xkb_state_key_get_one_sym(wlr_keyboard_from_input_device(pKeyboard->keyboard)->xkb_state, KEYCODE);
|
2022-07-20 22:45:06 +02:00
|
|
|
|
|
|
|
const auto MODS = g_pInputManager->accumulateModsFromAllKBs();
|
|
|
|
|
2022-07-20 23:17:26 +02:00
|
|
|
|
2022-07-20 22:45:06 +02:00
|
|
|
bool found = false;
|
|
|
|
if (e->state == WL_KEYBOARD_KEY_STATE_PRESSED) {
|
2022-07-20 23:17:26 +02:00
|
|
|
m_dPressedKeycodes.push_back(KEYCODE);
|
|
|
|
m_dPressedKeysyms.push_back(keysym);
|
|
|
|
|
2022-07-21 18:18:03 +02:00
|
|
|
found = g_pKeybindManager->handleKeybinds(MODS, "", keysym, 0, true, e->time_msec) || found;
|
2022-07-20 22:45:06 +02:00
|
|
|
|
2022-07-21 18:18:03 +02:00
|
|
|
found = g_pKeybindManager->handleKeybinds(MODS, "", 0, KEYCODE, true, e->time_msec) || found;
|
2022-07-20 22:45:06 +02:00
|
|
|
} else if (e->state == WL_KEYBOARD_KEY_STATE_RELEASED) {
|
|
|
|
|
2022-07-20 23:17:26 +02:00
|
|
|
m_dPressedKeycodes.erase(std::remove(m_dPressedKeycodes.begin(), m_dPressedKeycodes.end(), KEYCODE));
|
|
|
|
m_dPressedKeysyms.erase(std::remove(m_dPressedKeysyms.begin(), m_dPressedKeysyms.end(), keysym));
|
|
|
|
|
2022-07-21 18:18:03 +02:00
|
|
|
found = g_pKeybindManager->handleKeybinds(MODS, "", keysym, 0, false, e->time_msec) || found;
|
2022-07-20 23:17:26 +02:00
|
|
|
|
2022-07-21 18:18:03 +02:00
|
|
|
found = g_pKeybindManager->handleKeybinds(MODS, "", 0, KEYCODE, false, e->time_msec) || found;
|
2022-07-20 23:17:26 +02:00
|
|
|
|
|
|
|
shadowKeybinds();
|
2022-07-20 22:45:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return !found;
|
|
|
|
}
|
|
|
|
|
2022-07-21 18:18:03 +02:00
|
|
|
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) {
|
2022-07-21 19:31:38 +02:00
|
|
|
found = g_pKeybindManager->handleKeybinds(MODS, "mouse_down", 0, 0, true, 0);
|
2022-07-21 18:18:03 +02:00
|
|
|
} else {
|
2022-07-21 19:31:38 +02:00
|
|
|
found = g_pKeybindManager->handleKeybinds(MODS, "mouse_up", 0, 0, true, 0);
|
2022-07-21 18:18:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2022-03-19 22:03:40 +01:00
|
|
|
bool found = false;
|
2022-03-27 19:32:50 +02:00
|
|
|
|
2022-07-15 20:54:05 +02:00
|
|
|
if (handleInternalKeybinds(keysym))
|
2022-03-27 19:32:50 +02:00
|
|
|
return true;
|
|
|
|
|
2022-06-21 22:47:27 +02:00
|
|
|
if (g_pCompositor->m_sSeat.exclusiveClient)
|
|
|
|
Debug::log(LOG, "Keybind handling only locked (inhibitor)");
|
2022-04-18 17:16:01 +02:00
|
|
|
|
2022-07-20 23:17:26 +02:00
|
|
|
if (pressed && m_kHeldBack) {
|
|
|
|
// release the held back event
|
|
|
|
wlr_seat_keyboard_notify_key(g_pCompositor->m_sSeat.seat, time, m_kHeldBack, WL_KEYBOARD_KEY_STATE_PRESSED);
|
|
|
|
m_kHeldBack = 0;
|
|
|
|
}
|
|
|
|
|
2022-04-21 17:06:43 +02:00
|
|
|
for (auto& k : m_lKeybinds) {
|
2022-07-20 23:17:26 +02:00
|
|
|
if (modmask != k.modmask || (g_pCompositor->m_sSeat.exclusiveClient && !k.locked) || k.submap != m_szCurrentSelectedSubmap || (!pressed && !k.release) || k.shadowed)
|
2022-03-19 17:48:18 +01:00
|
|
|
continue;
|
|
|
|
|
2022-07-15 20:54:05 +02:00
|
|
|
if (!key.empty()) {
|
|
|
|
if (key != k.key)
|
|
|
|
continue;
|
|
|
|
} else if (k.keycode != -1) {
|
2022-07-08 09:27:17 +02:00
|
|
|
if (keycode != k.keycode)
|
|
|
|
continue;
|
|
|
|
} else {
|
2022-07-15 20:54:05 +02:00
|
|
|
if (keysym == 0)
|
2022-07-08 09:27:17 +02:00
|
|
|
continue; // this is a keycode check run
|
|
|
|
|
|
|
|
// oMg such performance hit!!11!
|
|
|
|
// this little maneouver is gonna cost us 4µs
|
|
|
|
const auto KBKEY = xkb_keysym_from_name(k.key.c_str(), XKB_KEYSYM_CASE_INSENSITIVE);
|
|
|
|
const auto KBKEYUPPER = xkb_keysym_to_upper(KBKEY);
|
|
|
|
// small TODO: fix 0-9 keys and other modified ones with shift
|
|
|
|
|
2022-07-15 20:54:05 +02:00
|
|
|
if (keysym != KBKEY && keysym != KBKEYUPPER)
|
2022-07-08 09:27:17 +02:00
|
|
|
continue;
|
|
|
|
}
|
2022-04-21 15:50:52 +02:00
|
|
|
|
2022-07-20 22:45:06 +02:00
|
|
|
if (pressed && k.release) {
|
|
|
|
// suppress down event
|
2022-07-21 18:48:34 +02:00
|
|
|
m_kHeldBack = keysym;
|
2022-07-20 22:45:06 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-04-21 15:50:52 +02:00
|
|
|
const auto DISPATCHER = m_mDispatchers.find(k.handler);
|
|
|
|
|
|
|
|
// Should never happen, as we check in the ConfigManager, but oh well
|
|
|
|
if (DISPATCHER == m_mDispatchers.end()) {
|
2022-04-14 23:02:10 +02:00
|
|
|
Debug::log(ERR, "Inavlid handler in a keybind! (handler %s does not exist)", k.handler.c_str());
|
2022-04-21 15:50:52 +02:00
|
|
|
} else {
|
|
|
|
// call the dispatcher
|
2022-07-16 14:34:13 +02:00
|
|
|
Debug::log(LOG, "Keybind triggered, calling dispatcher (%d, %s, %d)", modmask, key, keysym);
|
2022-04-21 15:50:52 +02:00
|
|
|
DISPATCHER->second(k.arg);
|
2022-04-14 23:02:10 +02:00
|
|
|
}
|
2022-03-19 22:03:40 +01:00
|
|
|
|
2022-07-24 12:16:26 +02:00
|
|
|
shadowKeybinds(keysym == 0 ? 0 : keysym, keycode == -1 ? -1 : keycode);
|
2022-07-20 23:17:26 +02:00
|
|
|
|
2022-03-19 22:03:40 +01:00
|
|
|
found = true;
|
2022-03-19 17:48:18 +01:00
|
|
|
}
|
2022-03-19 22:03:40 +01:00
|
|
|
|
|
|
|
return found;
|
2022-03-19 17:48:18 +01:00
|
|
|
}
|
|
|
|
|
2022-07-24 12:16:26 +02:00
|
|
|
void CKeybindManager::shadowKeybinds(const xkb_keysym_t& doesntHave, const uint32_t& doesntHaveCode) {
|
2022-07-20 23:17:26 +02:00
|
|
|
// shadow disables keybinds after one has been triggered
|
|
|
|
|
|
|
|
for (auto& k : m_lKeybinds) {
|
|
|
|
|
|
|
|
bool shadow = false;
|
|
|
|
|
|
|
|
const auto KBKEY = xkb_keysym_from_name(k.key.c_str(), XKB_KEYSYM_CASE_INSENSITIVE);
|
|
|
|
const auto KBKEYUPPER = xkb_keysym_to_upper(KBKEY);
|
|
|
|
|
|
|
|
for (auto& pk : m_dPressedKeysyms) {
|
|
|
|
if ((pk == KBKEY || pk == KBKEYUPPER)) {
|
|
|
|
shadow = true;
|
|
|
|
}
|
2022-07-24 12:16:26 +02:00
|
|
|
|
|
|
|
if (pk == doesntHave && doesntHave != 0) {
|
|
|
|
shadow = false;
|
|
|
|
break;
|
|
|
|
}
|
2022-07-20 23:17:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& pk : m_dPressedKeycodes) {
|
|
|
|
if (pk == (unsigned int)k.keycode) {
|
|
|
|
shadow = true;
|
|
|
|
}
|
2022-07-24 12:16:26 +02:00
|
|
|
|
|
|
|
if (pk == doesntHaveCode && doesntHaveCode != 0 && doesntHaveCode != -1) {
|
|
|
|
shadow = false;
|
|
|
|
break;
|
|
|
|
}
|
2022-07-20 23:17:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
k.shadowed = shadow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-27 13:42:20 +02:00
|
|
|
bool CKeybindManager::handleVT(xkb_keysym_t keysym) {
|
2022-03-27 19:32:50 +02:00
|
|
|
// Handles the CTRL+ALT+FX TTY keybinds
|
|
|
|
if (!(keysym >= XKB_KEY_XF86Switch_VT_1 && keysym <= XKB_KEY_XF86Switch_VT_12))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const auto PSESSION = wlr_backend_get_session(g_pCompositor->m_sWLRBackend);
|
|
|
|
if (PSESSION) {
|
2022-06-06 13:48:17 +02:00
|
|
|
const int TTY = keysym - XKB_KEY_XF86Switch_VT_1 + 1;
|
2022-03-27 19:32:50 +02:00
|
|
|
wlr_session_change_vt(PSESSION, TTY);
|
2022-07-13 18:18:23 +02:00
|
|
|
g_pCompositor->m_bSessionActive = false;
|
2022-06-06 13:48:17 +02:00
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& m : g_pCompositor->m_vMonitors) {
|
|
|
|
m->noFrameSchedule = true;
|
2022-07-13 18:18:23 +02:00
|
|
|
m->framesToSkip = 1;
|
2022-06-06 13:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Debug::log(LOG, "Switched to VT %i, destroyed all render data, frames to skip for each: 2", TTY);
|
2022-06-27 13:42:20 +02:00
|
|
|
|
2022-03-27 19:32:50 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-06-27 13:42:20 +02:00
|
|
|
bool CKeybindManager::handleInternalKeybinds(xkb_keysym_t keysym) {
|
|
|
|
if (handleVT(keysym))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// handle ESC while in kill mode
|
|
|
|
if (g_pInputManager->getClickMode() == CLICKMODE_KILL) {
|
|
|
|
const auto KBKEY = xkb_keysym_from_name("ESCAPE", XKB_KEYSYM_CASE_INSENSITIVE);
|
|
|
|
|
|
|
|
if (keysym == KBKEY) {
|
|
|
|
g_pInputManager->setClickMode(CLICKMODE_DEFAULT);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-03-19 17:48:18 +01:00
|
|
|
// Dispatchers
|
|
|
|
|
|
|
|
void CKeybindManager::spawn(std::string args) {
|
2022-04-20 15:58:02 +02:00
|
|
|
if (g_pXWaylandManager->m_sWLRXWayland)
|
|
|
|
args = "WAYLAND_DISPLAY=" + std::string(g_pCompositor->m_szWLDisplaySocket) + " DISPLAY=" + std::string(g_pXWaylandManager->m_sWLRXWayland->display_name) + " " + args;
|
|
|
|
else
|
|
|
|
args = "WAYLAND_DISPLAY=" + std::string(g_pCompositor->m_szWLDisplaySocket) + " " + args;
|
2022-04-20 16:18:58 +02:00
|
|
|
|
2022-03-19 17:48:18 +01:00
|
|
|
Debug::log(LOG, "Executing %s", args.c_str());
|
|
|
|
|
2022-06-15 19:06:51 +02:00
|
|
|
int socket[2];
|
2022-06-16 21:19:36 +02:00
|
|
|
if (pipe(socket) != 0) {
|
|
|
|
Debug::log(LOG, "Unable to create pipe for fork");
|
|
|
|
}
|
2022-06-15 19:06:51 +02:00
|
|
|
|
2022-06-16 21:19:36 +02:00
|
|
|
pid_t child, grandchild;
|
2022-06-15 19:06:51 +02:00
|
|
|
child = fork();
|
2022-06-16 21:19:36 +02:00
|
|
|
if (child < 0) {
|
2022-06-15 19:06:51 +02:00
|
|
|
close(socket[0]);
|
|
|
|
close(socket[1]);
|
|
|
|
Debug::log(LOG, "Fail to create the first fork");
|
|
|
|
return;
|
|
|
|
}
|
2022-06-16 21:19:36 +02:00
|
|
|
if (child == 0) {
|
2022-06-15 19:06:51 +02:00
|
|
|
// run in child
|
|
|
|
grandchild = fork();
|
2022-06-16 21:19:36 +02:00
|
|
|
if (grandchild == 0) {
|
2022-06-15 19:06:51 +02:00
|
|
|
// run in grandchild
|
|
|
|
close(socket[0]);
|
|
|
|
close(socket[1]);
|
|
|
|
execl("/bin/sh", "/bin/sh", "-c", args.c_str(), nullptr);
|
|
|
|
// exit grandchild
|
|
|
|
_exit(0);
|
|
|
|
}
|
|
|
|
close(socket[0]);
|
2022-06-16 21:19:36 +02:00
|
|
|
write(socket[1], &grandchild, sizeof(grandchild));
|
2022-06-15 19:06:51 +02:00
|
|
|
close(socket[1]);
|
|
|
|
// exit child
|
2022-03-19 17:48:18 +01:00
|
|
|
_exit(0);
|
|
|
|
}
|
2022-06-15 19:06:51 +02:00
|
|
|
// run in parent
|
|
|
|
close(socket[1]);
|
2022-06-16 21:19:36 +02:00
|
|
|
read(socket[0], &grandchild, sizeof(grandchild));
|
2022-06-15 19:06:51 +02:00
|
|
|
close(socket[0]);
|
|
|
|
// clear child and leave child to init
|
|
|
|
waitpid(child, NULL, 0);
|
2022-06-16 21:19:36 +02:00
|
|
|
if (child < 0) {
|
2022-06-15 19:06:51 +02:00
|
|
|
Debug::log(LOG, "Fail to create the second fork");
|
|
|
|
return;
|
|
|
|
}
|
2022-06-16 21:19:36 +02:00
|
|
|
Debug::log(LOG, "Process Created with pid %d", grandchild);
|
2022-03-19 17:48:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CKeybindManager::killActive(std::string args) {
|
2022-04-02 18:57:09 +02:00
|
|
|
if (g_pCompositor->m_pLastWindow && g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow)) {
|
|
|
|
g_pXWaylandManager->sendCloseWindow(g_pCompositor->m_pLastWindow);
|
|
|
|
g_pCompositor->m_pLastFocus = nullptr;
|
|
|
|
g_pCompositor->m_pLastWindow = nullptr;
|
2022-07-20 18:39:08 +02:00
|
|
|
g_pEventManager->postEvent(SHyprIPCEvent{"activewindow", ","}); // post an activewindow event to empty, as we are currently unfocused
|
2022-04-02 18:57:09 +02:00
|
|
|
}
|
|
|
|
|
2022-03-20 11:14:24 +01:00
|
|
|
g_pCompositor->focusWindow(g_pCompositor->windowFromCursor());
|
2022-03-19 21:48:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CKeybindManager::clearKeybinds() {
|
2022-04-21 17:06:43 +02:00
|
|
|
m_lKeybinds.clear();
|
2022-03-20 11:14:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CKeybindManager::toggleActiveFloating(std::string args) {
|
2022-04-02 18:57:09 +02:00
|
|
|
const auto ACTIVEWINDOW = g_pCompositor->m_pLastWindow;
|
2022-03-20 11:14:24 +01:00
|
|
|
|
|
|
|
if (g_pCompositor->windowValidMapped(ACTIVEWINDOW)) {
|
2022-06-30 12:09:05 +02:00
|
|
|
// remove drag status
|
|
|
|
g_pInputManager->currentlyDraggedWindow = nullptr;
|
|
|
|
|
2022-03-20 11:14:24 +01:00
|
|
|
ACTIVEWINDOW->m_bIsFloating = !ACTIVEWINDOW->m_bIsFloating;
|
2022-03-20 13:37:07 +01:00
|
|
|
|
2022-05-31 14:01:00 +02:00
|
|
|
if (ACTIVEWINDOW->m_iWorkspaceID == SPECIAL_WORKSPACE_ID) {
|
|
|
|
moveActiveToWorkspace(std::to_string(g_pCompositor->getMonitorFromID(ACTIVEWINDOW->m_iMonitorID)->activeWorkspace));
|
|
|
|
}
|
|
|
|
|
2022-03-20 11:14:24 +01:00
|
|
|
g_pLayoutManager->getCurrentLayout()->changeWindowFloatingMode(ACTIVEWINDOW);
|
|
|
|
}
|
2022-03-20 15:55:47 +01:00
|
|
|
}
|
|
|
|
|
2022-04-02 20:04:32 +02:00
|
|
|
void CKeybindManager::toggleActivePseudo(std::string args) {
|
|
|
|
const auto ACTIVEWINDOW = g_pCompositor->m_pLastWindow;
|
|
|
|
|
|
|
|
if (!g_pCompositor->windowValidMapped(ACTIVEWINDOW))
|
|
|
|
return;
|
|
|
|
|
|
|
|
ACTIVEWINDOW->m_bIsPseudotiled = !ACTIVEWINDOW->m_bIsPseudotiled;
|
|
|
|
|
|
|
|
g_pLayoutManager->getCurrentLayout()->recalculateWindow(ACTIVEWINDOW);
|
|
|
|
}
|
|
|
|
|
2022-04-21 17:21:55 +02:00
|
|
|
void CKeybindManager::changeworkspace(std::string args) {
|
2022-04-21 16:38:48 +02:00
|
|
|
int workspaceToChangeTo = 0;
|
|
|
|
std::string workspaceName = "";
|
|
|
|
|
2022-07-06 11:02:21 +02:00
|
|
|
if (args.find("[internal]") == 0) {
|
|
|
|
workspaceToChangeTo = std::stoi(args.substr(10));
|
|
|
|
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(workspaceToChangeTo);
|
|
|
|
if (PWORKSPACE)
|
|
|
|
workspaceName = PWORKSPACE->m_szName;
|
|
|
|
} else {
|
|
|
|
workspaceToChangeTo = getWorkspaceIDFromString(args, workspaceName);
|
|
|
|
}
|
2022-04-14 23:02:10 +02:00
|
|
|
|
2022-04-20 16:53:41 +02:00
|
|
|
if (workspaceToChangeTo == INT_MAX) {
|
|
|
|
Debug::log(ERR, "Error in changeworkspace, invalid value");
|
|
|
|
return;
|
2022-03-20 15:55:47 +01:00
|
|
|
}
|
|
|
|
|
2022-05-18 14:57:08 +02:00
|
|
|
// remove constraints
|
|
|
|
g_pCompositor->m_sSeat.mouse->constraintActive = false;
|
|
|
|
|
2022-03-20 15:55:47 +01:00
|
|
|
// if it exists, we warp to it
|
|
|
|
if (g_pCompositor->getWorkspaceByID(workspaceToChangeTo)) {
|
2022-04-11 19:51:37 +02:00
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(g_pCompositor->getWorkspaceByID(workspaceToChangeTo)->m_iMonitorID);
|
2022-03-20 15:55:47 +01:00
|
|
|
|
2022-05-24 19:42:43 +02:00
|
|
|
const auto PWORKSPACETOCHANGETO = g_pCompositor->getWorkspaceByID(workspaceToChangeTo);
|
|
|
|
|
2022-05-31 14:01:00 +02:00
|
|
|
if (workspaceToChangeTo == SPECIAL_WORKSPACE_ID)
|
|
|
|
PWORKSPACETOCHANGETO->m_iMonitorID = PMONITOR->ID;
|
|
|
|
|
2022-03-20 15:55:47 +01:00
|
|
|
// if it's not visible, make it visible.
|
2022-03-20 19:14:17 +01:00
|
|
|
if (!g_pCompositor->isWorkspaceVisible(workspaceToChangeTo)) {
|
|
|
|
const auto OLDWORKSPACEID = PMONITOR->activeWorkspace;
|
|
|
|
|
|
|
|
// change it
|
2022-05-31 14:01:00 +02:00
|
|
|
if (workspaceToChangeTo != SPECIAL_WORKSPACE_ID)
|
|
|
|
PMONITOR->activeWorkspace = workspaceToChangeTo;
|
|
|
|
else
|
|
|
|
PMONITOR->specialWorkspaceOpen = true;
|
2022-03-20 15:55:47 +01:00
|
|
|
|
2022-03-20 19:14:17 +01:00
|
|
|
// we need to move XWayland windows to narnia or otherwise they will still process our cursor and shit
|
|
|
|
// and that'd be annoying as hell
|
|
|
|
g_pCompositor->fixXWaylandWindowsOnWorkspace(OLDWORKSPACEID);
|
|
|
|
|
|
|
|
// and fix on the new workspace
|
|
|
|
g_pCompositor->fixXWaylandWindowsOnWorkspace(PMONITOR->activeWorkspace);
|
2022-05-12 11:27:31 +02:00
|
|
|
|
|
|
|
// here and only here begin anim. we don't want to anim visible workspaces on other monitors.
|
2022-05-12 13:03:02 +02:00
|
|
|
// check if anim left or right
|
|
|
|
const auto ANIMTOLEFT = workspaceToChangeTo > OLDWORKSPACEID;
|
|
|
|
|
2022-05-12 11:27:31 +02:00
|
|
|
// start anim on old workspace
|
2022-05-16 23:13:32 +02:00
|
|
|
g_pCompositor->getWorkspaceByID(OLDWORKSPACEID)->startAnim(false, ANIMTOLEFT);
|
2022-05-12 11:27:31 +02:00
|
|
|
|
|
|
|
// start anim on new workspace
|
2022-05-24 19:42:43 +02:00
|
|
|
PWORKSPACETOCHANGETO->startAnim(true, ANIMTOLEFT);
|
2022-05-24 22:21:31 +02:00
|
|
|
|
2022-07-20 18:39:08 +02:00
|
|
|
g_pEventManager->postEvent(SHyprIPCEvent{"workspace", PWORKSPACETOCHANGETO->m_szName});
|
2022-03-20 19:14:17 +01:00
|
|
|
}
|
|
|
|
|
2022-03-20 15:55:47 +01:00
|
|
|
// If the monitor is not the one our cursor's at, warp to it.
|
|
|
|
if (PMONITOR != g_pCompositor->getMonitorFromCursor()) {
|
|
|
|
Vector2D middle = PMONITOR->vecPosition + PMONITOR->vecSize / 2.f;
|
|
|
|
wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, middle.x, middle.y);
|
|
|
|
}
|
|
|
|
|
2022-04-11 19:51:37 +02:00
|
|
|
// set active and deactivate all other in wlr
|
2022-05-24 19:42:43 +02:00
|
|
|
g_pCompositor->deactivateAllWLRWorkspaces(PWORKSPACETOCHANGETO->m_pWlrHandle);
|
2022-05-25 10:25:36 +02:00
|
|
|
PWORKSPACETOCHANGETO->setActive(true);
|
2022-04-11 19:51:37 +02:00
|
|
|
|
2022-05-30 20:05:38 +02:00
|
|
|
// recalc layout
|
|
|
|
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(PWORKSPACETOCHANGETO->m_iMonitorID);
|
|
|
|
|
2022-04-11 19:51:37 +02:00
|
|
|
Debug::log(LOG, "Changed to workspace %i", workspaceToChangeTo);
|
|
|
|
|
2022-04-14 23:02:10 +02:00
|
|
|
// focus
|
|
|
|
g_pInputManager->refocus();
|
|
|
|
|
2022-05-05 13:48:22 +02:00
|
|
|
// mark the monitor dirty
|
|
|
|
g_pHyprRenderer->damageMonitor(PMONITOR);
|
|
|
|
|
2022-03-20 15:55:47 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Workspace doesn't exist, create and switch
|
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromCursor();
|
|
|
|
|
2022-03-20 19:28:57 +01:00
|
|
|
const auto OLDWORKSPACE = PMONITOR->activeWorkspace;
|
2022-03-20 19:27:47 +01:00
|
|
|
|
2022-05-12 13:03:02 +02:00
|
|
|
// get anim direction
|
|
|
|
const auto ANIMTOLEFT = workspaceToChangeTo > OLDWORKSPACE;
|
|
|
|
|
2022-05-12 11:27:31 +02:00
|
|
|
// start anim on old workspace
|
2022-05-30 20:05:38 +02:00
|
|
|
if (const auto POLDWORKSPACE = g_pCompositor->getWorkspaceByID(OLDWORKSPACE); POLDWORKSPACE)
|
|
|
|
POLDWORKSPACE->startAnim(false, ANIMTOLEFT);
|
2022-05-12 11:27:31 +02:00
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
const auto PWORKSPACE = g_pCompositor->m_vWorkspaces.emplace_back(std::make_unique<CWorkspace>(PMONITOR->ID, workspaceName, workspaceToChangeTo == SPECIAL_WORKSPACE_ID)).get();
|
2022-03-20 15:55:47 +01:00
|
|
|
|
2022-05-12 11:27:31 +02:00
|
|
|
// start anim on new workspace
|
2022-05-16 23:13:32 +02:00
|
|
|
PWORKSPACE->startAnim(true, ANIMTOLEFT);
|
2022-05-12 11:27:31 +02:00
|
|
|
|
2022-04-11 19:51:37 +02:00
|
|
|
// We are required to set the name here immediately
|
2022-05-31 14:01:00 +02:00
|
|
|
if (workspaceToChangeTo != SPECIAL_WORKSPACE_ID)
|
|
|
|
wlr_ext_workspace_handle_v1_set_name(PWORKSPACE->m_pWlrHandle, workspaceName.c_str());
|
2022-04-11 19:51:37 +02:00
|
|
|
|
|
|
|
PWORKSPACE->m_iID = workspaceToChangeTo;
|
|
|
|
PWORKSPACE->m_iMonitorID = PMONITOR->ID;
|
2022-05-31 14:01:00 +02:00
|
|
|
|
|
|
|
PMONITOR->specialWorkspaceOpen = false;
|
|
|
|
|
|
|
|
if (workspaceToChangeTo != SPECIAL_WORKSPACE_ID)
|
|
|
|
PMONITOR->activeWorkspace = workspaceToChangeTo;
|
|
|
|
else
|
|
|
|
PMONITOR->specialWorkspaceOpen = true;
|
2022-03-20 19:28:57 +01:00
|
|
|
|
|
|
|
// we need to move XWayland windows to narnia or otherwise they will still process our cursor and shit
|
|
|
|
// and that'd be annoying as hell
|
2022-03-20 19:29:50 +01:00
|
|
|
g_pCompositor->fixXWaylandWindowsOnWorkspace(OLDWORKSPACE);
|
2022-04-11 19:51:37 +02:00
|
|
|
|
|
|
|
// set active and deactivate all other
|
2022-04-28 17:55:25 +02:00
|
|
|
g_pCompositor->deactivateAllWLRWorkspaces(PWORKSPACE->m_pWlrHandle);
|
2022-05-25 10:25:36 +02:00
|
|
|
PWORKSPACE->setActive(true);
|
2022-04-11 19:51:37 +02:00
|
|
|
|
2022-04-14 20:08:39 +02:00
|
|
|
// mark the monitor dirty
|
|
|
|
g_pHyprRenderer->damageMonitor(PMONITOR);
|
|
|
|
|
2022-04-14 23:02:10 +02:00
|
|
|
// focus (clears the last)
|
|
|
|
g_pInputManager->refocus();
|
|
|
|
|
2022-05-24 19:42:43 +02:00
|
|
|
// Event
|
2022-07-20 18:39:08 +02:00
|
|
|
g_pEventManager->postEvent(SHyprIPCEvent{"workspace", PWORKSPACE->m_szName});
|
2022-05-24 19:42:43 +02:00
|
|
|
|
2022-04-11 19:51:37 +02:00
|
|
|
Debug::log(LOG, "Changed to workspace %i", workspaceToChangeTo);
|
2022-03-21 19:18:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CKeybindManager::fullscreenActive(std::string args) {
|
2022-04-02 18:57:09 +02:00
|
|
|
const auto PWINDOW = g_pCompositor->m_pLastWindow;
|
2022-03-21 19:18:33 +01:00
|
|
|
|
|
|
|
if (!g_pCompositor->windowValidMapped(PWINDOW))
|
|
|
|
return;
|
|
|
|
|
2022-06-26 12:12:29 +02:00
|
|
|
g_pCompositor->setWindowFullscreen(PWINDOW, !PWINDOW->m_bIsFullscreen, args == "1" ? FULLSCREEN_MAXIMIZED : FULLSCREEN_FULL);
|
2022-03-23 16:51:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CKeybindManager::moveActiveToWorkspace(std::string args) {
|
2022-04-02 18:57:09 +02:00
|
|
|
const auto PWINDOW = g_pCompositor->m_pLastWindow;
|
2022-03-23 16:51:48 +01:00
|
|
|
|
|
|
|
if (!g_pCompositor->windowValidMapped(PWINDOW))
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto OLDWORKSPACE = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID);
|
|
|
|
|
|
|
|
// hack
|
2022-05-30 15:28:23 +02:00
|
|
|
std::string unusedName;
|
|
|
|
const auto WORKSPACEID = getWorkspaceIDFromString(args, unusedName);
|
|
|
|
|
2022-06-03 11:19:17 +02:00
|
|
|
if (WORKSPACEID == PWINDOW->m_iWorkspaceID) {
|
|
|
|
Debug::log(LOG, "Not moving to workspace because it didn't change.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-18 20:53:29 +02:00
|
|
|
auto PSAVEDSIZE = PWINDOW->m_vRealSize.vec();
|
|
|
|
auto PSAVEDPOS = PWINDOW->m_vRealPosition.vec();
|
|
|
|
|
2022-06-03 11:19:17 +02:00
|
|
|
g_pLayoutManager->getCurrentLayout()->onWindowRemoved(PWINDOW);
|
|
|
|
|
2022-04-21 16:38:48 +02:00
|
|
|
g_pKeybindManager->changeworkspace(args);
|
|
|
|
|
2022-05-30 15:28:23 +02:00
|
|
|
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(WORKSPACEID);
|
2022-03-23 16:51:48 +01:00
|
|
|
|
2022-04-21 16:38:48 +02:00
|
|
|
if (PWORKSPACE == OLDWORKSPACE) {
|
|
|
|
Debug::log(LOG, "Not moving to workspace because it didn't change.");
|
|
|
|
return;
|
|
|
|
}
|
2022-03-23 16:51:48 +01:00
|
|
|
|
2022-05-30 15:28:23 +02:00
|
|
|
if (!PWORKSPACE) {
|
|
|
|
Debug::log(ERR, "Workspace null in moveActiveToWorkspace?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-11 19:51:37 +02:00
|
|
|
OLDWORKSPACE->m_bHasFullscreenWindow = false;
|
2022-03-23 16:51:48 +01:00
|
|
|
|
2022-04-21 16:38:48 +02:00
|
|
|
PWINDOW->m_iWorkspaceID = PWORKSPACE->m_iID;
|
|
|
|
PWINDOW->m_iMonitorID = PWORKSPACE->m_iMonitorID;
|
2022-03-23 16:51:48 +01:00
|
|
|
PWINDOW->m_bIsFullscreen = false;
|
|
|
|
|
2022-04-21 16:38:48 +02:00
|
|
|
if (PWORKSPACE->m_bHasFullscreenWindow) {
|
|
|
|
g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID)->m_bIsFullscreen = false;
|
|
|
|
PWORKSPACE->m_bHasFullscreenWindow = false;
|
2022-03-23 16:51:48 +01:00
|
|
|
}
|
|
|
|
|
2022-07-18 20:53:29 +02:00
|
|
|
if (PWINDOW->m_bIsFullscreen) {
|
|
|
|
PWINDOW->m_bIsFullscreen = false;
|
|
|
|
PSAVEDPOS = PSAVEDPOS + Vector2D(10, 10);
|
|
|
|
PSAVEDSIZE = PSAVEDSIZE - Vector2D(20, 20);
|
|
|
|
}
|
|
|
|
|
2022-03-23 16:51:48 +01:00
|
|
|
// Hack: So that the layout doesnt find our window at the cursor
|
|
|
|
PWINDOW->m_vPosition = Vector2D(-42069, -42069);
|
2022-04-10 21:45:24 +02:00
|
|
|
|
2022-03-23 16:51:48 +01:00
|
|
|
g_pLayoutManager->getCurrentLayout()->onWindowCreated(PWINDOW);
|
|
|
|
|
2022-07-18 20:53:29 +02:00
|
|
|
// and restore it
|
2022-03-23 16:51:48 +01:00
|
|
|
if (PWINDOW->m_bIsFloating) {
|
2022-07-18 20:53:29 +02:00
|
|
|
PWINDOW->m_vRealSize.setValue(PSAVEDSIZE);
|
|
|
|
PWINDOW->m_vRealPosition.setValueAndWarp(PSAVEDPOS - g_pCompositor->getMonitorFromID(OLDWORKSPACE->m_iMonitorID)->vecPosition + g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID)->vecPosition);
|
2022-04-23 14:16:02 +02:00
|
|
|
PWINDOW->m_vPosition = PWINDOW->m_vRealPosition.vec();
|
2022-03-23 16:51:48 +01:00
|
|
|
}
|
2022-05-31 14:01:00 +02:00
|
|
|
|
|
|
|
// undo the damage if we are moving to the special workspace
|
|
|
|
if (WORKSPACEID == SPECIAL_WORKSPACE_ID) {
|
2022-07-06 11:02:21 +02:00
|
|
|
changeworkspace("[internal]" + std::to_string(OLDWORKSPACE->m_iID));
|
2022-05-31 14:01:00 +02:00
|
|
|
OLDWORKSPACE->startAnim(true, true, true);
|
|
|
|
toggleSpecialWorkspace("");
|
|
|
|
g_pCompositor->getWorkspaceByID(SPECIAL_WORKSPACE_ID)->startAnim(false, false, true);
|
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& m : g_pCompositor->m_vMonitors)
|
|
|
|
m->specialWorkspaceOpen = false;
|
2022-05-31 14:01:00 +02:00
|
|
|
}
|
2022-06-08 15:52:38 +02:00
|
|
|
|
|
|
|
g_pInputManager->refocus();
|
2022-03-27 19:32:50 +02:00
|
|
|
}
|
2022-04-09 13:26:55 +02:00
|
|
|
|
2022-05-18 12:18:58 +02:00
|
|
|
void CKeybindManager::moveActiveToWorkspaceSilent(std::string args) {
|
|
|
|
// hacky, but works lol
|
|
|
|
|
|
|
|
int workspaceToMoveTo = 0;
|
|
|
|
std::string workspaceName = "";
|
|
|
|
|
|
|
|
workspaceToMoveTo = getWorkspaceIDFromString(args, workspaceName);
|
|
|
|
|
|
|
|
if (workspaceToMoveTo == INT_MAX) {
|
|
|
|
Debug::log(ERR, "Error in moveActiveToWorkspaceSilent, invalid value");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto PWINDOW = g_pCompositor->m_pLastWindow;
|
|
|
|
|
|
|
|
if (!g_pCompositor->windowValidMapped(PWINDOW))
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID);
|
|
|
|
|
|
|
|
if (workspaceToMoveTo == PMONITOR->activeWorkspace)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// may be null until later!
|
|
|
|
auto PWORKSPACE = g_pCompositor->getWorkspaceByID(workspaceToMoveTo);
|
|
|
|
|
|
|
|
const auto PMONITORNEW = PWORKSPACE ? g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID) : PMONITOR;
|
|
|
|
|
|
|
|
const auto OLDWORKSPACEIDONMONITOR = PMONITORNEW->activeWorkspace;
|
|
|
|
const auto OLDWORKSPACEIDRETURN = PMONITOR->activeWorkspace;
|
|
|
|
|
|
|
|
const auto POLDWORKSPACEONMON = g_pCompositor->getWorkspaceByID(OLDWORKSPACEIDONMONITOR);
|
|
|
|
const auto POLDWORKSPACEIDRETURN = g_pCompositor->getWorkspaceByID(OLDWORKSPACEIDRETURN);
|
|
|
|
|
2022-06-21 22:17:30 +02:00
|
|
|
g_pEventManager->m_bIgnoreEvents = true;
|
2022-05-24 19:42:43 +02:00
|
|
|
|
2022-05-18 12:18:58 +02:00
|
|
|
moveActiveToWorkspace(args);
|
|
|
|
|
|
|
|
PWORKSPACE = g_pCompositor->getWorkspaceByID(workspaceToMoveTo);
|
|
|
|
|
2022-07-06 11:02:21 +02:00
|
|
|
changeworkspace("[internal]" + std::to_string(OLDWORKSPACEIDONMONITOR));
|
|
|
|
changeworkspace("[internal]" + std::to_string(OLDWORKSPACEIDRETURN));
|
2022-05-18 12:18:58 +02:00
|
|
|
|
|
|
|
// revert animations
|
|
|
|
PWORKSPACE->m_vRenderOffset.setValueAndWarp(Vector2D(0,0));
|
|
|
|
PWORKSPACE->m_fAlpha.setValueAndWarp(0.f);
|
|
|
|
|
|
|
|
POLDWORKSPACEIDRETURN->m_vRenderOffset.setValueAndWarp(Vector2D(0, 0));
|
|
|
|
POLDWORKSPACEIDRETURN->m_fAlpha.setValueAndWarp(255.f);
|
|
|
|
|
|
|
|
POLDWORKSPACEONMON->m_vRenderOffset.setValueAndWarp(Vector2D(0, 0));
|
|
|
|
POLDWORKSPACEONMON->m_fAlpha.setValueAndWarp(255.f);
|
2022-05-24 19:42:43 +02:00
|
|
|
|
2022-06-21 22:17:30 +02:00
|
|
|
g_pEventManager->m_bIgnoreEvents = false;
|
2022-06-08 15:52:38 +02:00
|
|
|
|
|
|
|
g_pInputManager->refocus();
|
2022-05-18 12:18:58 +02:00
|
|
|
}
|
|
|
|
|
2022-04-09 13:26:55 +02:00
|
|
|
void CKeybindManager::moveFocusTo(std::string args) {
|
|
|
|
char arg = args[0];
|
|
|
|
|
2022-05-05 12:50:25 +02:00
|
|
|
if (!isDirection(args)) {
|
2022-04-20 16:18:58 +02:00
|
|
|
Debug::log(ERR, "Cannot move focus in direction %c, unsupported direction. Supported: l,r,u/t,d/b", arg);
|
2022-04-09 13:26:55 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto PLASTWINDOW = g_pCompositor->m_pLastWindow;
|
|
|
|
|
2022-05-18 14:57:08 +02:00
|
|
|
// remove constraints
|
|
|
|
g_pCompositor->m_sSeat.mouse->constraintActive = false;
|
|
|
|
|
2022-04-13 20:45:06 +02:00
|
|
|
auto switchToWindow = [&](CWindow* PWINDOWTOCHANGETO) {
|
|
|
|
g_pCompositor->focusWindow(PWINDOWTOCHANGETO);
|
2022-04-23 14:35:34 +02:00
|
|
|
Vector2D middle = PWINDOWTOCHANGETO->m_vRealPosition.goalv() + PWINDOWTOCHANGETO->m_vRealSize.goalv() / 2.f;
|
2022-04-13 20:45:06 +02:00
|
|
|
wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, middle.x, middle.y);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!g_pCompositor->windowValidMapped(PLASTWINDOW)) {
|
|
|
|
const auto PWINDOWTOCHANGETO = g_pCompositor->getFirstWindowOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace);
|
|
|
|
if (!PWINDOWTOCHANGETO)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switchToWindow(PWINDOWTOCHANGETO);
|
|
|
|
|
2022-04-09 13:26:55 +02:00
|
|
|
return;
|
2022-04-13 20:45:06 +02:00
|
|
|
}
|
2022-04-09 13:26:55 +02:00
|
|
|
|
|
|
|
const auto PWINDOWTOCHANGETO = g_pCompositor->getWindowInDirection(PLASTWINDOW, arg);
|
|
|
|
|
2022-04-09 13:33:44 +02:00
|
|
|
if (PWINDOWTOCHANGETO) {
|
2022-04-13 20:45:06 +02:00
|
|
|
switchToWindow(PWINDOWTOCHANGETO);
|
|
|
|
} else {
|
|
|
|
const auto PWINDOWNEXT = g_pCompositor->getNextWindowOnWorkspace(PLASTWINDOW);
|
|
|
|
if (PWINDOWNEXT) {
|
|
|
|
switchToWindow(PWINDOWNEXT);
|
|
|
|
}
|
|
|
|
}
|
2022-04-12 16:44:18 +02:00
|
|
|
}
|
|
|
|
|
2022-04-20 16:18:58 +02:00
|
|
|
void CKeybindManager::moveActiveTo(std::string args) {
|
|
|
|
char arg = args[0];
|
|
|
|
|
2022-05-05 13:02:55 +02:00
|
|
|
const auto LASTMONITOR = g_pCompositor->m_pLastMonitor;
|
|
|
|
|
|
|
|
if (args.find("mon:") == 0) {
|
|
|
|
// hack: save the active window
|
|
|
|
const auto PACTIVE = g_pCompositor->m_pLastWindow;
|
|
|
|
|
|
|
|
// monitor
|
|
|
|
focusMonitor(args.substr(4));
|
|
|
|
|
|
|
|
if (LASTMONITOR == g_pCompositor->m_pLastMonitor) {
|
|
|
|
Debug::log(ERR, "moveActiveTo: moving to an invalid mon");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// restore the active
|
|
|
|
g_pCompositor->focusWindow(PACTIVE);
|
|
|
|
|
|
|
|
moveActiveToWorkspace(std::to_string(g_pCompositor->m_pLastMonitor->activeWorkspace));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-05 12:50:25 +02:00
|
|
|
if (!isDirection(args)) {
|
2022-04-20 16:18:58 +02:00
|
|
|
Debug::log(ERR, "Cannot move window in direction %c, unsupported direction. Supported: l,r,u/t,d/b", arg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto PLASTWINDOW = g_pCompositor->m_pLastWindow;
|
|
|
|
|
2022-04-20 16:53:41 +02:00
|
|
|
if (!g_pCompositor->windowValidMapped(PLASTWINDOW))
|
2022-04-20 16:18:58 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
const auto PWINDOWTOCHANGETO = g_pCompositor->getWindowInDirection(PLASTWINDOW, arg);
|
|
|
|
|
2022-04-20 16:53:41 +02:00
|
|
|
if (!g_pCompositor->windowValidMapped(PWINDOWTOCHANGETO))
|
2022-04-20 16:18:58 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
g_pLayoutManager->getCurrentLayout()->switchWindows(PLASTWINDOW, PWINDOWTOCHANGETO);
|
|
|
|
}
|
|
|
|
|
2022-04-12 16:44:18 +02:00
|
|
|
void CKeybindManager::toggleGroup(std::string args) {
|
2022-05-16 17:37:46 +02:00
|
|
|
SLayoutMessageHeader header;
|
|
|
|
header.pWindow = g_pCompositor->m_pLastWindow;
|
|
|
|
g_pLayoutManager->getCurrentLayout()->layoutMessage(header, "togglegroup");
|
2022-04-12 16:44:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CKeybindManager::changeGroupActive(std::string args) {
|
2022-05-16 17:37:46 +02:00
|
|
|
SLayoutMessageHeader header;
|
|
|
|
header.pWindow = g_pCompositor->m_pLastWindow;
|
2022-05-28 19:16:20 +02:00
|
|
|
if (args == "b")
|
|
|
|
g_pLayoutManager->getCurrentLayout()->layoutMessage(header, "changegroupactiveb");
|
|
|
|
else
|
|
|
|
g_pLayoutManager->getCurrentLayout()->layoutMessage(header, "changegroupactivef");
|
2022-05-16 17:37:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CKeybindManager::toggleSplit(std::string args) {
|
|
|
|
SLayoutMessageHeader header;
|
|
|
|
header.pWindow = g_pCompositor->m_pLastWindow;
|
|
|
|
g_pLayoutManager->getCurrentLayout()->layoutMessage(header, "togglesplit");
|
2022-04-20 16:53:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CKeybindManager::alterSplitRatio(std::string args) {
|
|
|
|
float splitratio = 0;
|
|
|
|
|
|
|
|
if (args == "+" || args == "-") {
|
|
|
|
Debug::log(LOG, "alterSplitRatio: using LEGACY +/-, consider switching to the Hyprland syntax.");
|
|
|
|
splitratio = (args == "+" ? 0.05f : -0.05f);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (splitratio == 0) {
|
|
|
|
splitratio = getPlusMinusKeywordResult(args, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (splitratio == INT_MAX) {
|
|
|
|
Debug::log(ERR, "Splitratio invalid in alterSplitRatio!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto PLASTWINDOW = g_pCompositor->m_pLastWindow;
|
|
|
|
|
|
|
|
if (!g_pCompositor->windowValidMapped(PLASTWINDOW))
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_pLayoutManager->getCurrentLayout()->alterSplitRatioBy(PLASTWINDOW, splitratio);
|
2022-05-05 12:50:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CKeybindManager::focusMonitor(std::string arg) {
|
|
|
|
if (isNumber(arg)) {
|
|
|
|
// change by ID
|
|
|
|
int monID = -1;
|
|
|
|
try {
|
|
|
|
monID = std::stoi(arg);
|
|
|
|
} catch (std::exception& e) {
|
|
|
|
// shouldn't happen but jic
|
|
|
|
Debug::log(ERR, "Error in focusMonitor: invalid num");
|
|
|
|
}
|
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
if (monID > -1 && monID < (int)g_pCompositor->m_vMonitors.size()) {
|
2022-07-06 11:02:21 +02:00
|
|
|
changeworkspace("[internal]" + std::to_string(g_pCompositor->getMonitorFromID(monID)->activeWorkspace));
|
2022-05-05 12:50:25 +02:00
|
|
|
} else {
|
|
|
|
Debug::log(ERR, "Error in focusMonitor: invalid arg 1");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (isDirection(arg)) {
|
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorInDirection(arg[0]);
|
|
|
|
if (PMONITOR) {
|
2022-05-28 18:38:49 +02:00
|
|
|
if (PMONITOR->activeWorkspace < 0) {
|
|
|
|
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace);
|
|
|
|
changeworkspace("name:" + PWORKSPACE->m_szName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
changeworkspace(std::to_string(PMONITOR->activeWorkspace));
|
2022-05-05 12:50:25 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& m : g_pCompositor->m_vMonitors) {
|
|
|
|
if (m->szName == arg) {
|
2022-07-06 11:02:21 +02:00
|
|
|
changeworkspace("[internal]" + std::to_string(m->activeWorkspace));
|
2022-05-05 12:50:25 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Debug::log(ERR, "Error in focusMonitor: no such monitor");
|
|
|
|
}
|
2022-05-18 12:18:58 +02:00
|
|
|
}
|
2022-05-22 11:52:39 +02:00
|
|
|
|
|
|
|
void CKeybindManager::moveCursorToCorner(std::string arg) {
|
|
|
|
if (!isNumber(arg)) {
|
|
|
|
Debug::log(ERR, "moveCursorToCorner, arg has to be a number.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto CORNER = std::stoi(arg);
|
|
|
|
|
|
|
|
if (CORNER < 0 || CORNER > 3) {
|
|
|
|
Debug::log(ERR, "moveCursorToCorner, corner not 0 - 3.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto PWINDOW = g_pCompositor->m_pLastWindow;
|
|
|
|
|
|
|
|
if (!g_pCompositor->windowValidMapped(PWINDOW))
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (CORNER) {
|
|
|
|
case 0:
|
|
|
|
// bottom left
|
|
|
|
wlr_cursor_warp(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, PWINDOW->m_vRealPosition.vec().x, PWINDOW->m_vRealPosition.vec().y + PWINDOW->m_vRealSize.vec().y);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
// bottom right
|
|
|
|
wlr_cursor_warp(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, PWINDOW->m_vRealPosition.vec().x + PWINDOW->m_vRealSize.vec().x, PWINDOW->m_vRealPosition.vec().y + PWINDOW->m_vRealSize.vec().y);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
// top right
|
|
|
|
wlr_cursor_warp(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, PWINDOW->m_vRealPosition.vec().x + PWINDOW->m_vRealSize.vec().x, PWINDOW->m_vRealPosition.vec().y);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
// top left
|
|
|
|
wlr_cursor_warp(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, PWINDOW->m_vRealPosition.vec().x, PWINDOW->m_vRealPosition.vec().y);
|
|
|
|
break;
|
|
|
|
}
|
2022-05-26 19:05:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CKeybindManager::workspaceOpt(std::string args) {
|
|
|
|
|
|
|
|
// current workspace
|
|
|
|
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace);
|
|
|
|
|
|
|
|
if (!PWORKSPACE)
|
|
|
|
return; // ????
|
|
|
|
|
|
|
|
if (args == "allpseudo") {
|
|
|
|
PWORKSPACE->m_bDefaultPseudo = !PWORKSPACE->m_bDefaultPseudo;
|
|
|
|
|
|
|
|
// apply
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : g_pCompositor->m_vWindows) {
|
|
|
|
if (!w->m_bIsMapped || w->m_iWorkspaceID != PWORKSPACE->m_iID)
|
2022-05-26 19:05:32 +02:00
|
|
|
continue;
|
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
w->m_bIsPseudotiled = PWORKSPACE->m_bDefaultPseudo;
|
2022-05-26 19:05:32 +02:00
|
|
|
}
|
|
|
|
} else if (args == "allfloat") {
|
|
|
|
PWORKSPACE->m_bDefaultFloating = !PWORKSPACE->m_bDefaultFloating;
|
|
|
|
// apply
|
|
|
|
|
|
|
|
// we make a copy because changeWindowFloatingMode might invalidate the iterator
|
|
|
|
std::deque<CWindow*> ptrs;
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : g_pCompositor->m_vWindows)
|
|
|
|
ptrs.push_back(w.get());
|
2022-05-26 19:05:32 +02:00
|
|
|
|
|
|
|
for (auto& w : ptrs) {
|
|
|
|
if (!w->m_bIsMapped || w->m_iWorkspaceID != PWORKSPACE->m_iID)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!w->m_bRequestsFloat && w->m_bIsFloating != PWORKSPACE->m_bDefaultFloating) {
|
|
|
|
const auto SAVEDPOS = w->m_vRealPosition.vec();
|
|
|
|
const auto SAVEDSIZE = w->m_vRealSize.vec();
|
|
|
|
|
|
|
|
w->m_bIsFloating = PWORKSPACE->m_bDefaultFloating;
|
|
|
|
g_pLayoutManager->getCurrentLayout()->changeWindowFloatingMode(w);
|
|
|
|
|
|
|
|
if (PWORKSPACE->m_bDefaultFloating) {
|
|
|
|
w->m_vRealPosition.setValueAndWarp(SAVEDPOS);
|
|
|
|
w->m_vRealSize.setValueAndWarp(SAVEDSIZE);
|
|
|
|
g_pXWaylandManager->setWindowSize(w, SAVEDSIZE);
|
|
|
|
w->m_vRealSize = w->m_vRealSize.vec() + Vector2D(4,4);
|
|
|
|
w->m_vRealPosition = w->m_vRealPosition.vec() - Vector2D(2,2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Debug::log(ERR, "Invalid arg in workspaceOpt, opt \"%s\" doesn't exist.", args.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// recalc mon
|
|
|
|
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(g_pCompositor->m_pLastMonitor->ID);
|
2022-05-29 00:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CKeybindManager::exitHyprland(std::string argz) {
|
2022-07-13 18:18:23 +02:00
|
|
|
g_pCompositor->cleanup();
|
2022-05-30 20:05:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CKeybindManager::moveCurrentWorkspaceToMonitor(std::string args) {
|
2022-07-04 16:51:42 +02:00
|
|
|
SMonitor* PMONITOR = nullptr;
|
2022-05-30 20:05:38 +02:00
|
|
|
|
2022-07-04 16:51:42 +02:00
|
|
|
try {
|
|
|
|
if (!isNumber(args) && !isDirection(args)) {
|
|
|
|
PMONITOR = g_pCompositor->getMonitorFromName(args);
|
|
|
|
} else {
|
|
|
|
PMONITOR = isDirection(args) ? g_pCompositor->getMonitorInDirection(args[0]) : g_pCompositor->getMonitorFromID(std::stoi(args));
|
|
|
|
}
|
|
|
|
} catch (std::exception& e) {
|
|
|
|
Debug::log(LOG, "moveCurrentWorkspaceToMonitor: caught exception in monitor", e.what());
|
2022-05-30 20:05:38 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the current workspace
|
|
|
|
const auto PCURRENTWORKSPACE = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace);
|
|
|
|
|
|
|
|
if (!PCURRENTWORKSPACE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_pCompositor->moveWorkspaceToMonitor(PCURRENTWORKSPACE, PMONITOR);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CKeybindManager::moveWorkspaceToMonitor(std::string args) {
|
2022-07-06 16:50:11 +02:00
|
|
|
if (!args.contains(' '))
|
2022-06-06 19:32:14 +02:00
|
|
|
return;
|
2022-05-30 20:05:38 +02:00
|
|
|
|
|
|
|
std::string workspace = args.substr(0, args.find_first_of(' '));
|
|
|
|
std::string monitor = args.substr(args.find_first_of(' ') + 1);
|
|
|
|
|
2022-07-04 16:51:42 +02:00
|
|
|
SMonitor* PMONITOR = nullptr;
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (!isNumber(monitor) && !isDirection(monitor)) {
|
|
|
|
PMONITOR = g_pCompositor->getMonitorFromName(monitor);
|
|
|
|
} else {
|
|
|
|
PMONITOR = isDirection(monitor) ? g_pCompositor->getMonitorInDirection(monitor[0]) : g_pCompositor->getMonitorFromID(std::stoi(monitor));
|
|
|
|
}
|
|
|
|
} catch (std::exception& e) {
|
|
|
|
Debug::log(LOG, "moveWorkspaceToMonitor: caught exception in monitor", e.what());
|
2022-05-30 20:05:38 +02:00
|
|
|
return;
|
|
|
|
}
|
2022-07-04 16:51:42 +02:00
|
|
|
|
2022-05-30 20:05:38 +02:00
|
|
|
|
|
|
|
if (!PMONITOR){
|
|
|
|
Debug::log(ERR, "Ignoring moveWorkspaceToMonitor: monitor doesnt exist");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string workspaceName;
|
|
|
|
const int WORKSPACEID = getWorkspaceIDFromString(workspace, workspaceName);
|
|
|
|
|
|
|
|
if (WORKSPACEID == INT_MAX) {
|
|
|
|
Debug::log(ERR, "moveWorkspaceToMonitor invalid workspace!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(WORKSPACEID);
|
|
|
|
|
2022-05-31 18:47:32 +02:00
|
|
|
if (!PWORKSPACE) {
|
|
|
|
Debug::log(ERR, "moveWorkspaceToMonitor workspace doesn't exist!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-30 20:05:38 +02:00
|
|
|
g_pCompositor->moveWorkspaceToMonitor(PWORKSPACE, PMONITOR);
|
2022-05-31 14:01:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CKeybindManager::toggleSpecialWorkspace(std::string args) {
|
|
|
|
|
|
|
|
if (g_pCompositor->getWindowsOnWorkspace(SPECIAL_WORKSPACE_ID) == 0) {
|
|
|
|
Debug::log(LOG, "Can't open empty special workspace!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool open = false;
|
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& m : g_pCompositor->m_vMonitors) {
|
|
|
|
if (m->specialWorkspaceOpen) {
|
2022-05-31 14:01:00 +02:00
|
|
|
open = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (open)
|
|
|
|
Debug::log(LOG, "Toggling special workspace to closed");
|
|
|
|
else
|
|
|
|
Debug::log(LOG, "Toggling special workspace to open");
|
|
|
|
|
|
|
|
if (open) {
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& m : g_pCompositor->m_vMonitors) {
|
|
|
|
if (m->specialWorkspaceOpen != !open) {
|
|
|
|
m->specialWorkspaceOpen = !open;
|
|
|
|
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID);
|
2022-05-31 14:01:00 +02:00
|
|
|
|
|
|
|
g_pCompositor->getWorkspaceByID(SPECIAL_WORKSPACE_ID)->startAnim(false, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2022-07-04 19:41:55 +02:00
|
|
|
auto PSPECIALWORKSPACE = g_pCompositor->getWorkspaceByID(SPECIAL_WORKSPACE_ID);
|
2022-07-07 19:01:42 +02:00
|
|
|
|
|
|
|
if (!PSPECIALWORKSPACE) {
|
|
|
|
// ??? happens sometimes...?
|
|
|
|
PSPECIALWORKSPACE = g_pCompositor->m_vWorkspaces.emplace_back(std::make_unique<CWorkspace>(g_pCompositor->m_pLastMonitor->ID, "special", true)).get();
|
|
|
|
}
|
|
|
|
|
2022-05-31 14:01:00 +02:00
|
|
|
g_pCompositor->m_pLastMonitor->specialWorkspaceOpen = true;
|
|
|
|
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(g_pCompositor->m_pLastMonitor->ID);
|
|
|
|
|
2022-06-27 19:46:04 +02:00
|
|
|
PSPECIALWORKSPACE->startAnim(true, true);
|
|
|
|
PSPECIALWORKSPACE->m_iMonitorID = g_pCompositor->m_pLastMonitor->ID;
|
2022-05-31 14:01:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
g_pInputManager->refocus();
|
2022-06-06 13:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CKeybindManager::forceRendererReload(std::string args) {
|
2022-06-30 23:55:28 +02:00
|
|
|
bool overAgain = false;
|
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& m : g_pCompositor->m_vMonitors) {
|
|
|
|
auto rule = g_pConfigManager->getMonitorRuleFor(m->szName);
|
2022-06-30 23:55:28 +02:00
|
|
|
if (!g_pHyprRenderer->applyMonitorRule(m.get(), &rule, true)) {
|
|
|
|
overAgain = true;
|
|
|
|
break;
|
|
|
|
}
|
2022-06-06 13:48:17 +02:00
|
|
|
}
|
2022-06-30 23:55:28 +02:00
|
|
|
|
|
|
|
if (overAgain)
|
|
|
|
forceRendererReload(args);
|
2022-06-06 19:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CKeybindManager::resizeActive(std::string args) {
|
2022-07-06 16:50:11 +02:00
|
|
|
if (!args.contains(' '))
|
2022-06-06 19:32:14 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
std::string x = args.substr(0, args.find_first_of(' '));
|
|
|
|
std::string y = args.substr(args.find_first_of(' ') + 1);
|
|
|
|
|
2022-06-23 10:14:59 +02:00
|
|
|
if (x == "exact") {
|
|
|
|
std::string newX = y.substr(0, y.find_first_of(' '));
|
|
|
|
std::string newY = y.substr(y.find_first_of(' ') + 1);
|
|
|
|
|
|
|
|
if (!isNumber(newX) || !isNumber(newY)) {
|
|
|
|
Debug::log(ERR, "resizeTiledWindow: exact args not numbers");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int X = std::stoi(newX);
|
|
|
|
const int Y = std::stoi(newY);
|
|
|
|
|
|
|
|
if (X < 10 || Y < 10) {
|
|
|
|
Debug::log(ERR, "resizeTiledWindow: exact args cannot be < 10");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// calc the delta
|
|
|
|
if (!g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow))
|
|
|
|
return; // ignore
|
|
|
|
|
|
|
|
const auto PWINDOW = g_pCompositor->m_pLastWindow;
|
|
|
|
|
|
|
|
const int DX = X - PWINDOW->m_vRealSize.goalv().x;
|
|
|
|
const int DY = Y - PWINDOW->m_vRealSize.goalv().y;
|
|
|
|
|
|
|
|
g_pLayoutManager->getCurrentLayout()->resizeActiveWindow(Vector2D(DX, DY));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-06 19:32:14 +02:00
|
|
|
if (!isNumber(x) || !isNumber(y)) {
|
|
|
|
Debug::log(ERR, "resizeTiledWindow: args not numbers");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int X = std::stoi(x);
|
|
|
|
const int Y = std::stoi(y);
|
|
|
|
|
|
|
|
g_pLayoutManager->getCurrentLayout()->resizeActiveWindow(Vector2D(X, Y));
|
2022-06-10 11:39:06 +02:00
|
|
|
}
|
|
|
|
|
2022-06-23 10:14:59 +02:00
|
|
|
void CKeybindManager::moveActive(std::string args) {
|
2022-07-06 16:50:11 +02:00
|
|
|
if (!args.contains(' '))
|
2022-06-23 10:14:59 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
std::string x = args.substr(0, args.find_first_of(' '));
|
|
|
|
std::string y = args.substr(args.find_first_of(' ') + 1);
|
|
|
|
|
|
|
|
if (x == "exact") {
|
|
|
|
std::string newX = y.substr(0, y.find_first_of(' '));
|
|
|
|
std::string newY = y.substr(y.find_first_of(' ') + 1);
|
|
|
|
|
|
|
|
if (!isNumber(newX) || !isNumber(newY)) {
|
|
|
|
Debug::log(ERR, "moveActive: exact args not numbers");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int X = std::stoi(newX);
|
|
|
|
const int Y = std::stoi(newY);
|
|
|
|
|
2022-06-25 11:20:03 +02:00
|
|
|
if (X < 0 || Y < 0) {
|
|
|
|
Debug::log(ERR, "moveActive: exact args cannot be < 0");
|
2022-06-23 10:14:59 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// calc the delta
|
|
|
|
if (!g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow))
|
|
|
|
return; // ignore
|
|
|
|
|
|
|
|
const auto PWINDOW = g_pCompositor->m_pLastWindow;
|
|
|
|
|
|
|
|
const int DX = X - PWINDOW->m_vRealPosition.goalv().x;
|
|
|
|
const int DY = Y - PWINDOW->m_vRealPosition.goalv().y;
|
|
|
|
|
|
|
|
g_pLayoutManager->getCurrentLayout()->moveActiveWindow(Vector2D(DX, DY));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isNumber(x) || !isNumber(y)) {
|
|
|
|
Debug::log(ERR, "moveActive: args not numbers");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int X = std::stoi(x);
|
|
|
|
const int Y = std::stoi(y);
|
|
|
|
|
|
|
|
g_pLayoutManager->getCurrentLayout()->moveActiveWindow(Vector2D(X, Y));
|
|
|
|
}
|
|
|
|
|
2022-07-09 18:39:41 +02:00
|
|
|
void CKeybindManager::circleNext(std::string arg) {
|
2022-06-10 11:39:06 +02:00
|
|
|
if (!g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow))
|
|
|
|
return;
|
|
|
|
|
2022-07-16 19:55:40 +02:00
|
|
|
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastWindow->m_iWorkspaceID);
|
|
|
|
|
|
|
|
if (PWORKSPACE->m_bHasFullscreenWindow)
|
|
|
|
return;
|
|
|
|
|
2022-07-09 18:39:41 +02:00
|
|
|
if (arg == "last" || arg == "l" || arg == "prev" || arg == "p")
|
|
|
|
g_pCompositor->focusWindow(g_pCompositor->getPrevWindowOnWorkspace(g_pCompositor->m_pLastWindow));
|
|
|
|
else
|
|
|
|
g_pCompositor->focusWindow(g_pCompositor->getNextWindowOnWorkspace(g_pCompositor->m_pLastWindow));
|
2022-06-10 11:39:06 +02:00
|
|
|
|
|
|
|
const auto MIDPOINT = g_pCompositor->m_pLastWindow->m_vRealPosition.goalv() + g_pCompositor->m_pLastWindow->m_vRealSize.goalv() / 2.f;
|
|
|
|
|
|
|
|
wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, MIDPOINT.x, MIDPOINT.y);
|
|
|
|
}
|
2022-06-10 12:06:27 +02:00
|
|
|
|
2022-07-01 16:24:37 +02:00
|
|
|
void CKeybindManager::focusWindow(std::string regexp) {
|
2022-07-18 01:00:12 +02:00
|
|
|
eFocusWindowMode mode = MODE_CLASS_REGEX;
|
|
|
|
|
2022-07-01 16:24:37 +02:00
|
|
|
std::regex regexCheck(regexp);
|
2022-07-18 01:00:12 +02:00
|
|
|
std::string matchCheck;
|
2022-07-01 16:24:37 +02:00
|
|
|
if (regexp.find("title:") == 0) {
|
2022-07-18 01:00:12 +02:00
|
|
|
mode = MODE_TITLE_REGEX;
|
2022-07-01 16:24:37 +02:00
|
|
|
regexCheck = std::regex(regexp.substr(6));
|
|
|
|
}
|
2022-07-18 01:00:12 +02:00
|
|
|
else if (regexp.find("address:") == 0) {
|
|
|
|
mode = MODE_ADDRESS;
|
|
|
|
matchCheck = regexp.substr(8);
|
|
|
|
}
|
|
|
|
else if (regexp.find("pid:") == 0) {
|
|
|
|
mode = MODE_PID;
|
|
|
|
matchCheck = regexp.substr(4);
|
|
|
|
}
|
2022-06-10 12:06:27 +02:00
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
for (auto& w : g_pCompositor->m_vWindows) {
|
|
|
|
if (!w->m_bIsMapped || w->m_bHidden)
|
2022-06-25 21:18:33 +02:00
|
|
|
continue;
|
|
|
|
|
2022-07-18 01:00:12 +02:00
|
|
|
switch (mode) {
|
|
|
|
case MODE_CLASS_REGEX: {
|
|
|
|
const auto windowClass = g_pXWaylandManager->getAppIDClass(w.get());
|
|
|
|
if (!std::regex_search(g_pXWaylandManager->getAppIDClass(w.get()), regexCheck))
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MODE_TITLE_REGEX: {
|
|
|
|
const auto windowTitle = g_pXWaylandManager->getTitle(w.get());
|
|
|
|
if (!std::regex_search(windowTitle, regexCheck))
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MODE_ADDRESS: {
|
|
|
|
std::string addr = getFormat("0x%x", w.get());
|
|
|
|
if (matchCheck != addr)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MODE_PID: {
|
|
|
|
std::string pid = getFormat("%d", w->getPID());
|
|
|
|
if (matchCheck != pid)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
2022-07-01 16:24:37 +02:00
|
|
|
}
|
2022-06-10 12:06:27 +02:00
|
|
|
|
2022-07-18 01:00:12 +02:00
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
Debug::log(LOG, "Focusing to window name: %s", w->m_szTitle.c_str());
|
2022-06-10 12:06:27 +02:00
|
|
|
|
2022-07-06 11:02:21 +02:00
|
|
|
changeworkspace("[internal]" + std::to_string(w->m_iWorkspaceID));
|
2022-06-10 12:06:27 +02:00
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
g_pCompositor->focusWindow(w.get());
|
2022-06-10 12:06:27 +02:00
|
|
|
|
2022-06-30 15:44:26 +02:00
|
|
|
const auto MIDPOINT = w->m_vRealPosition.goalv() + w->m_vRealSize.goalv() / 2.f;
|
2022-06-10 12:06:27 +02:00
|
|
|
|
|
|
|
wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, MIDPOINT.x, MIDPOINT.y);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-06-22 20:23:20 +02:00
|
|
|
|
|
|
|
void CKeybindManager::setSubmap(std::string submap) {
|
|
|
|
if (submap == "reset" || submap == "") {
|
|
|
|
m_szCurrentSelectedSubmap = "";
|
|
|
|
Debug::log(LOG, "Reset active submap to the default one.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& k : g_pKeybindManager->m_lKeybinds) {
|
|
|
|
if (k.submap == submap) {
|
|
|
|
m_szCurrentSelectedSubmap = submap;
|
|
|
|
Debug::log(LOG, "Changed keybind submap to %s", submap.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Debug::log(ERR, "Cannot set submap %s, submap doesn't exist (wasn't registered!)", submap.c_str());
|
|
|
|
}
|