swaymux/Keys/RestoreKeyListener.h

53 lines
1.4 KiB
C
Raw Normal View History

//
// 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 {
auto containersToRestore = getSelectedContainers();
if (containersToRestore.empty())
return;
Formatter cmd;
auto newWorkspaceId = createNewWorkspaceId(containersToRestore);
for (auto node: containersToRestore) {
cmd << "[con_id=" << node->node.id << "] move workspace " << newWorkspaceId << " ; ";
}
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 "Restore selected windows to a new workspace";
}
const std::string getKeyText() override {
return "+";
}
[[nodiscard]] bool canAcceptKey(int key) const override {
return key == Qt::Key_Plus;
}
};
#endif //SWAYMUX_RESTOREKEYLISTENER_H