swaymux/Keys/MoveToScratchpadKeyListener.h

51 lines
1.3 KiB
C
Raw Normal View History

//
// 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 MainWindowAwareKeyListener {
public:
explicit MoveToScratchpadKeyListener(MainWindow *pWindow) : MainWindowAwareKeyListener(pWindow) {}
void handleKeyEvent(const QKeyEvent *keyEvent) const override {
std::set<int> containersToScratch = getSelectedContainerIds();
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";
updateMainWindow();
}
const std::string getDescription() override {
return "Move selected windows to scratchpad";
}
const std::string getKeyText() override {
return "-";
}
[[nodiscard]] bool canAcceptKey(int key) const override {
return key == Qt::Key_Minus;
}
};
#endif //SWAYMUX_MOVETOSCRATCHPADKEYLISTENER_H