swaymux/Keys/CreateWorkspaceKeyListener.h

46 lines
1.3 KiB
C++

//
// Created by grimmauld on 07.03.24.
//
#ifndef SWAYMUX_CREATEWORKSPACEKEYLISTENER_H
#define SWAYMUX_CREATEWORKSPACEKEYLISTENER_H
#include <QTreeView>
#include <iostream>
#include "AbstractKeyListener.h"
#include "../tree/SwayTreeModel.h"
#include "../sway_bindings/swayoutputs.h"
#include "MainWindowAwareKeyListener.h"
class CreateWorkspaceKeyListener : public MainWindowAwareKeyListener {
public:
explicit CreateWorkspaceKeyListener(MainWindow *pWindow) : MainWindowAwareKeyListener(pWindow) {}
void handleKeyEvent(const QKeyEvent *keyEvent) const override {
Formatter cmd;
const auto* selectedOutput = findSelectedValidOutput();
if (selectedOutput != nullptr)
cmd << "focus output " << selectedOutput->node.name << " , ";
cmd << "workspace " << createNewWorkspaceId({}, selectedOutput);
auto resp = SwayTreeModel::sway.sendIPC(swaymsg(0, cmd.str()));
std::cout << resp.msg << "\n";
QApplication::quit();
}
const std::string getDescription() override {
return "Create and switch to new empty workspace on selected output";
}
const std::string getKeyText() override {
return "C";
}
[[nodiscard]] bool canAcceptKey(int key) const override {
return key == Qt::Key_C;
}
};
#endif //SWAYMUX_CREATEWORKSPACEKEYLISTENER_H