swaymux/Keys/CloseKeyListener.h
LordGrimmauld f3b60a4a2a Add new functions
- move to scratch
- restore (move selected to new workspace)
- close
2024-03-11 13:33:26 +01:00

59 lines
1.5 KiB
C++

//
// Created by grimmauld on 11.03.24.
//
#ifndef SWAYMUX_CLOSEKEYLISTENER_H
#define SWAYMUX_CLOSEKEYLISTENER_H
#include "AbstractKeyListener.h"
class CloseKeyListener : public AbstractKeyListener {
public:
explicit CloseKeyListener(MainWindow *pWindow) : window(pWindow) {}
void handleKeyEvent(const QKeyEvent *keyEvent) const override {
auto selectedNodes = window->model->getSelectedNodes(window->ui->treeView);
std::set<int> containersToKill;
for (auto* container: selectedNodes) {
auto containers = container->accumulateContainers();
for (auto* containerToMove : container->accumulateContainers()) {
containersToKill.insert(containerToMove->node.id);
}
}
if (containersToKill.empty())
return;
Formatter cmd;
for (auto id: containersToKill) {
cmd << "[con_id=" << id << "] kill ; ";
}
std::cout << cmd.str() << "\n";
auto resp = SwayTreeModel::sway.sendIPC(swaymsg(0, cmd.str()));
std::cout << resp.msg << "\n";
usleep(100000); // give sway time to react. Not great but works i guess.
window->updateModel();
}
std::string getDescription() override {
return "Close selected windows";
}
std::string getKeyText() override {
return "Q / DEL";
}
[[nodiscard]] bool canAcceptKey(int key) const override {
return key == Qt::Key_Q || key == Qt::Key_Delete;
}
private:
MainWindow *window;
};
#endif //SWAYMUX_CLOSEKEYLISTENER_H