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"
|
2024-03-08 13:13:28 +01:00
|
|
|
#include "../sway_bindings/swayoutputs.h"
|
2024-03-11 17:11:26 +01:00
|
|
|
#include "MainWindowAwareKeyListener.h"
|
2024-03-08 10:53:30 +01:00
|
|
|
|
2024-03-11 17:11:26 +01:00
|
|
|
class CreateWorkspaceKeyListener : public MainWindowAwareKeyListener {
|
2024-03-08 10:53:30 +01:00
|
|
|
public:
|
2024-03-11 17:11:26 +01:00
|
|
|
explicit CreateWorkspaceKeyListener(MainWindow *pWindow) : MainWindowAwareKeyListener(pWindow) {}
|
2024-03-08 10:53:30 +01:00
|
|
|
|
|
|
|
void handleKeyEvent(const QKeyEvent *keyEvent) const override {
|
|
|
|
|
|
|
|
Formatter cmd;
|
2024-03-11 17:11:26 +01:00
|
|
|
const auto* selectedOutput = findSelectedValidOutput();
|
|
|
|
if (selectedOutput != nullptr)
|
|
|
|
cmd << "focus output " << selectedOutput->node.name << " , ";
|
|
|
|
|
2024-04-01 11:53:37 +02:00
|
|
|
cmd << "workspace " << createNewWorkspaceId({}, selectedOutput);
|
2024-03-09 12:55:29 +01:00
|
|
|
auto resp = SwayTreeModel::sway.sendIPC(swaymsg(0, cmd.str()));
|
2024-03-08 10:53:30 +01:00
|
|
|
std::cout << resp.msg << "\n";
|
2024-03-08 13:13:28 +01:00
|
|
|
QApplication::quit();
|
2024-03-08 10:53:30 +01:00
|
|
|
}
|
|
|
|
|
2024-03-13 21:43:57 +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";
|
|
|
|
}
|
|
|
|
|
2024-03-13 21:43:57 +01:00
|
|
|
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
|