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