swaymux/Keys/RestoreKeyListener.h

53 lines
1.3 KiB
C++

//
// Created by grimmauld on 11.03.24.
//
#ifndef SWAYMUX_RESTOREKEYLISTENER_H
#define SWAYMUX_RESTOREKEYLISTENER_H
#include "AbstractKeyListener.h"
#include "../mainwindow.h"
#include "../sway_bindings/Formatter.h"
#include "../tree/SwayTreeModel.h"
class RestoreKeyListener : public MainWindowAwareKeyListener {
public:
explicit RestoreKeyListener(MainWindow *pWindow) : MainWindowAwareKeyListener(pWindow) {}
void handleKeyEvent(const QKeyEvent *keyEvent) const override {
std::set<int> containersToRestore = getSelectedContainerIds();
if (containersToRestore.empty())
return;
Formatter cmd;
int newWorkspaceId = createNewWorkspaceId();
for (auto id: containersToRestore) {
cmd << "[con_id=" << id << "] move workspace " << newWorkspaceId << " ; ";
}
std::cout << cmd.str() << "\n";
auto resp = SwayTreeModel::sway.sendIPC(swaymsg(0, cmd.str()));
std::cout << resp.msg << "\n";
updateMainWindow();
}
std::string getDescription() override {
return "Restore selected windows to a new workspace";
}
std::string getKeyText() override {
return "+";
}
[[nodiscard]] bool canAcceptKey(int key) const override {
return key == Qt::Key_Plus;
}
};
#endif //SWAYMUX_RESTOREKEYLISTENER_H