// // 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 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(); } 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