swaymux/Keys/MoveToScratchpadKeyListener.h
LordGrimmauld f3b60a4a2a Add new functions
- move to scratch
- restore (move selected to new workspace)
- close
2024-03-11 13:33:26 +01:00

62 lines
1.7 KiB
C++

//
// Created by grimmauld on 11.03.24.
//
#ifndef SWAYMUX_MOVETOSCRATCHPADKEYLISTENER_H
#define SWAYMUX_MOVETOSCRATCHPADKEYLISTENER_H
#include "AbstractKeyListener.h"
#include "../mainwindow.h"
#include "../sway_bindings/Formatter.h"
#include "../tree/SwayTreeModel.h"
class MoveToScratchpadKeyListener : public AbstractKeyListener {
public:
explicit MoveToScratchpadKeyListener(MainWindow *pWindow) : window(pWindow) {}
void handleKeyEvent(const QKeyEvent *keyEvent) const override {
auto selectedNodes = window->model->getSelectedNodes(window->ui->treeView);
std::set<int> containersToScratch;
for (auto* container: selectedNodes) {
auto containers = container->accumulateContainers();
for (auto* containerToMove : container->accumulateContainers()) {
containersToScratch.insert(containerToMove->node.id);
}
}
if (containersToScratch.empty())
return;
Formatter cmd;
for (auto id: containersToScratch) {
cmd << "[con_id=" << id << "] move scratchpad ; ";
}
std::cout << cmd.str() << "\n";
auto resp = SwayTreeModel::sway.sendIPC(swaymsg(0, cmd.str()));
std::cout << resp.msg << "\n";
usleep(100000); // give sway time to react. Not great but works i guess.
window->updateModel();
}
std::string getDescription() override {
return "Move selected windows to scratchpad";
}
std::string getKeyText() override {
return "-";
}
[[nodiscard]] bool canAcceptKey(int key) const override {
return key == Qt::Key_Minus;
}
private:
MainWindow *window;
};
#endif //SWAYMUX_MOVETOSCRATCHPADKEYLISTENER_H