swaymux/Keys/CreateWorkspaceKeyListener.h

46 lines
1.3 KiB
C
Raw Normal View History

2024-03-08 10:53:30 +01:00
//
// 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"
2024-03-08 10:53:30 +01:00
class CreateWorkspaceKeyListener : public MainWindowAwareKeyListener {
2024-03-08 10:53:30 +01:00
public:
explicit CreateWorkspaceKeyListener(MainWindow *pWindow) : MainWindowAwareKeyListener(pWindow) {}
2024-03-08 10:53:30 +01:00
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()));
2024-03-08 10:53:30 +01:00
std::cout << resp.msg << "\n";
QApplication::quit();
2024-03-08 10:53:30 +01:00
}
const std::string getDescription() override {
2024-03-08 10:53:30 +01:00
return "Create and switch to new empty workspace on selected output";
}
const std::string getKeyText() override {
2024-03-08 10:53:30 +01:00
return "C";
}
[[nodiscard]] bool canAcceptKey(int key) const override {
return key == Qt::Key_C;
}
};
#endif //SWAYMUX_CREATEWORKSPACEKEYLISTENER_H