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 = getSelectedContainerIds();
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";
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