mirror of
https://github.com/hyprwm/Hyprland
synced 2025-01-10 14:09:49 +01:00
keybinds: add new window destruction dispatchers (#8962)
This commit is contained in:
parent
983bc067da
commit
c9822b08f9
2 changed files with 84 additions and 6 deletions
|
@ -12,6 +12,7 @@
|
||||||
#include "eventLoop/EventLoopManager.hpp"
|
#include "eventLoop/EventLoopManager.hpp"
|
||||||
#include "debug/Log.hpp"
|
#include "debug/Log.hpp"
|
||||||
#include "helpers/varlist/VarList.hpp"
|
#include "helpers/varlist/VarList.hpp"
|
||||||
|
#include "../helpers/signal/Signal.hpp"
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
@ -63,8 +64,12 @@ CKeybindManager::CKeybindManager() {
|
||||||
|
|
||||||
m_mDispatchers["exec"] = spawn;
|
m_mDispatchers["exec"] = spawn;
|
||||||
m_mDispatchers["execr"] = spawnRaw;
|
m_mDispatchers["execr"] = spawnRaw;
|
||||||
m_mDispatchers["killactive"] = killActive;
|
m_mDispatchers["killactive"] = closeActive;
|
||||||
m_mDispatchers["closewindow"] = kill;
|
m_mDispatchers["forcekillactive"] = killActive;
|
||||||
|
m_mDispatchers["closewindow"] = closeWindow;
|
||||||
|
m_mDispatchers["killwindow"] = killWindow;
|
||||||
|
m_mDispatchers["signal"] = signalActive;
|
||||||
|
m_mDispatchers["signalwindow"] = signalWindow;
|
||||||
m_mDispatchers["togglefloating"] = toggleActiveFloating;
|
m_mDispatchers["togglefloating"] = toggleActiveFloating;
|
||||||
m_mDispatchers["setfloating"] = setActiveFloating;
|
m_mDispatchers["setfloating"] = setActiveFloating;
|
||||||
m_mDispatchers["settiled"] = setActiveTiled;
|
m_mDispatchers["settiled"] = setActiveTiled;
|
||||||
|
@ -978,17 +983,23 @@ uint64_t CKeybindManager::spawnRawProc(std::string args, PHLWORKSPACE pInitialWo
|
||||||
}
|
}
|
||||||
|
|
||||||
SDispatchResult CKeybindManager::killActive(std::string args) {
|
SDispatchResult CKeybindManager::killActive(std::string args) {
|
||||||
|
kill(g_pCompositor->m_pLastWindow.lock()->getPID(), SIGKILL);
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
SDispatchResult CKeybindManager::closeActive(std::string args) {
|
||||||
g_pCompositor->closeWindow(g_pCompositor->m_pLastWindow.lock());
|
g_pCompositor->closeWindow(g_pCompositor->m_pLastWindow.lock());
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
SDispatchResult CKeybindManager::kill(std::string args) {
|
SDispatchResult CKeybindManager::closeWindow(std::string args) {
|
||||||
const auto PWINDOW = g_pCompositor->getWindowByRegex(args);
|
const auto PWINDOW = g_pCompositor->getWindowByRegex(args);
|
||||||
|
|
||||||
if (!PWINDOW) {
|
if (!PWINDOW) {
|
||||||
Debug::log(ERR, "kill: no window found");
|
Debug::log(ERR, "closeWindow: no window found");
|
||||||
return {.success = false, .error = "kill: no window found"};
|
return {.success = false, .error = "closeWindow: no window found"};
|
||||||
}
|
}
|
||||||
|
|
||||||
g_pCompositor->closeWindow(PWINDOW);
|
g_pCompositor->closeWindow(PWINDOW);
|
||||||
|
@ -996,6 +1007,69 @@ SDispatchResult CKeybindManager::kill(std::string args) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDispatchResult CKeybindManager::killWindow(std::string args) {
|
||||||
|
const auto PWINDOW = g_pCompositor->getWindowByRegex(args);
|
||||||
|
|
||||||
|
if (!PWINDOW) {
|
||||||
|
Debug::log(ERR, "killWindow: no window found");
|
||||||
|
return {.success = false, .error = "killWindow: no window found"};
|
||||||
|
}
|
||||||
|
|
||||||
|
kill(PWINDOW->getPID(), SIGKILL);
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
SDispatchResult CKeybindManager::signalActive(std::string args) {
|
||||||
|
if (!std::all_of(args.begin(), args.end(), ::isdigit))
|
||||||
|
return {.success = false, .error = "signalActive: signal has to be int"};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const auto SIGNALNUM = std::stoi(args);
|
||||||
|
if (SIGNALNUM < 1 || SIGNALNUM > 31) {
|
||||||
|
Debug::log(ERR, "signalActive: invalid signal number {}", SIGNALNUM);
|
||||||
|
return {.success = false, .error = std::format("signalActive: invalid signal number {}", SIGNALNUM)};
|
||||||
|
}
|
||||||
|
kill(g_pCompositor->m_pLastWindow.lock()->getPID(), SIGNALNUM);
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
Debug::log(ERR, "signalActive: invalid signal format \"{}\"", args);
|
||||||
|
return {.success = false, .error = std::format("signalActive: invalid signal format \"{}\"", args)};
|
||||||
|
}
|
||||||
|
|
||||||
|
kill(g_pCompositor->m_pLastWindow.lock()->getPID(), std::stoi(args));
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
SDispatchResult CKeybindManager::signalWindow(std::string args) {
|
||||||
|
const auto WINDOWREGEX = args.substr(0, args.find_first_of(','));
|
||||||
|
const auto SIGNAL = args.substr(args.find_first_of(',') + 1);
|
||||||
|
|
||||||
|
const auto PWINDOW = g_pCompositor->getWindowByRegex(WINDOWREGEX);
|
||||||
|
|
||||||
|
if (!PWINDOW) {
|
||||||
|
Debug::log(ERR, "signalWindow: no window");
|
||||||
|
return {.success = false, .error = "signalWindow: no window"};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!std::all_of(SIGNAL.begin(), SIGNAL.end(), ::isdigit))
|
||||||
|
return {.success = false, .error = "signalWindow: signal has to be int"};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const auto SIGNALNUM = std::stoi(SIGNAL);
|
||||||
|
if (SIGNALNUM < 1 || SIGNALNUM > 31) {
|
||||||
|
Debug::log(ERR, "signalWindow: invalid signal number {}", SIGNALNUM);
|
||||||
|
return {.success = false, .error = std::format("signalWindow: invalid signal number {}", SIGNALNUM)};
|
||||||
|
}
|
||||||
|
kill(PWINDOW->getPID(), SIGNALNUM);
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
Debug::log(ERR, "signalWindow: invalid signal format \"{}\"", SIGNAL);
|
||||||
|
return {.success = false, .error = std::format("signalWindow: invalid signal format \"{}\"", SIGNAL)};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
void CKeybindManager::clearKeybinds() {
|
void CKeybindManager::clearKeybinds() {
|
||||||
m_vKeybinds.clear();
|
m_vKeybinds.clear();
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,8 +152,12 @@ class CKeybindManager {
|
||||||
static uint64_t spawnWithRules(std::string, PHLWORKSPACE pInitialWorkspace);
|
static uint64_t spawnWithRules(std::string, PHLWORKSPACE pInitialWorkspace);
|
||||||
|
|
||||||
// -------------- Dispatchers -------------- //
|
// -------------- Dispatchers -------------- //
|
||||||
|
static SDispatchResult closeActive(std::string);
|
||||||
static SDispatchResult killActive(std::string);
|
static SDispatchResult killActive(std::string);
|
||||||
static SDispatchResult kill(std::string);
|
static SDispatchResult closeWindow(std::string);
|
||||||
|
static SDispatchResult killWindow(std::string);
|
||||||
|
static SDispatchResult signalActive(std::string);
|
||||||
|
static SDispatchResult signalWindow(std::string);
|
||||||
static SDispatchResult spawn(std::string);
|
static SDispatchResult spawn(std::string);
|
||||||
static SDispatchResult spawnRaw(std::string);
|
static SDispatchResult spawnRaw(std::string);
|
||||||
static SDispatchResult toggleActiveFloating(std::string);
|
static SDispatchResult toggleActiveFloating(std::string);
|
||||||
|
|
Loading…
Reference in a new issue