2024-03-11 13:33:26 +01:00
|
|
|
//
|
|
|
|
// 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"
|
|
|
|
|
2024-03-11 17:11:26 +01:00
|
|
|
class RestoreKeyListener : public MainWindowAwareKeyListener {
|
2024-03-11 13:33:26 +01:00
|
|
|
public:
|
2024-03-11 17:11:26 +01:00
|
|
|
explicit RestoreKeyListener(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 containersToRestore = getSelectedContainers();
|
2024-03-11 13:33:26 +01:00
|
|
|
|
2024-03-11 17:11:26 +01:00
|
|
|
if (containersToRestore.empty())
|
2024-03-11 13:33:26 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
Formatter cmd;
|
2024-03-26 18:01:53 +01:00
|
|
|
auto newWorkspaceId = createNewWorkspaceId(containersToRestore);
|
2024-03-11 13:33:26 +01:00
|
|
|
|
2024-03-26 18:01:53 +01:00
|
|
|
for (auto node: containersToRestore) {
|
|
|
|
cmd << "[con_id=" << node->node.id << "] move workspace " << newWorkspaceId << " ; ";
|
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 "Restore selected windows to a new workspace";
|
|
|
|
}
|
|
|
|
|
2024-03-13 21:43:57 +01:00
|
|
|
const std::string getKeyText() override {
|
2024-03-11 13:33:26 +01:00
|
|
|
return "+";
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] bool canAcceptKey(int key) const override {
|
|
|
|
return key == Qt::Key_Plus;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //SWAYMUX_RESTOREKEYLISTENER_H
|