swaymux/Keys/CloseKeyListener.h

49 lines
1.2 KiB
C
Raw Normal View History

//
// Created by grimmauld on 11.03.24.
//
#ifndef SWAYMUX_CLOSEKEYLISTENER_H
#define SWAYMUX_CLOSEKEYLISTENER_H
#include "AbstractKeyListener.h"
#include "MainWindowAwareKeyListener.h"
class CloseKeyListener : public MainWindowAwareKeyListener {
public:
explicit CloseKeyListener(MainWindow *pWindow) : MainWindowAwareKeyListener(pWindow) {}
void handleKeyEvent(const QKeyEvent *keyEvent) const override {
auto containersToKill = getSelectedContainers();
if (containersToKill.empty())
return;
Formatter cmd;
for (auto node: containersToKill) {
cmd << "[con_id=" << node->node.id << "] kill ; ";
}
std::cout << cmd.str() << "\n";
auto resp = SwayTreeModel::sway.sendIPC(swaymsg(0, cmd.str()));
std::cout << resp.msg << "\n";
updateMainWindow();
}
const std::string getDescription() override {
return "Close selected windows";
}
const std::string getKeyText() override {
return "Q / DEL";
}
[[nodiscard]] bool canAcceptKey(int key) const override {
return key == Qt::Key_Q || key == Qt::Key_Delete;
}
};
#endif //SWAYMUX_CLOSEKEYLISTENER_H