aquamarine/tests/SimpleWindow.cpp

94 lines
3.5 KiB
C++
Raw Normal View History

2024-06-18 18:45:05 +02:00
#include <aquamarine/backend/Backend.hpp>
#include <aquamarine/output/Output.hpp>
#include <aquamarine/input/Input.hpp>
2024-06-18 18:45:05 +02:00
#include <iostream>
#include <wayland-server.h>
2024-06-18 18:45:05 +02:00
using namespace Hyprutils::Signal;
using namespace Hyprutils::Memory;
#define SP CSharedPointer
2024-06-18 18:45:05 +02:00
static const char* aqLevelToString(Aquamarine::eBackendLogLevel level) {
switch (level) {
case Aquamarine::eBackendLogLevel::AQ_LOG_TRACE: return "TRACE";
case Aquamarine::eBackendLogLevel::AQ_LOG_DEBUG: return "DEBUG";
case Aquamarine::eBackendLogLevel::AQ_LOG_ERROR: return "ERROR";
case Aquamarine::eBackendLogLevel::AQ_LOG_WARNING: return "WARNING";
case Aquamarine::eBackendLogLevel::AQ_LOG_CRITICAL: return "CRITICAL";
default: break;
}
return "UNKNOWN";
}
void aqLog(Aquamarine::eBackendLogLevel level, std::string msg) {
std::cout << "[AQ] [" << aqLevelToString(level) << "] " << msg << "\n";
}
CHyprSignalListener newOutputListener, outputFrameListener, outputStateListener, mouseMotionListener, keyboardKeyListener, newMouseListener, newKeyboardListener;
SP<Aquamarine::IOutput> output;
//
void onFrame() {
std::cout << "[Client] onFrame\n";
auto buf = output->swapchain->next(nullptr);
2024-06-22 17:31:01 +02:00
output->state->setBuffer(buf);
output->commit();
}
void onState(const Aquamarine::IOutput::SStateEvent& event) {
std::cout << "[Client] onState with size " << std::format("{}", event.size) << "\n";
2024-06-22 17:31:01 +02:00
output->state->setEnabled(true);
output->state->setCustomMode(makeShared<Aquamarine::SOutputMode>(Aquamarine::SOutputMode{.pixelSize = event.size}));
output->state->setFormat(DRM_FORMAT_XRGB8888);
output->commit();
}
2024-06-18 18:45:05 +02:00
int main(int argc, char** argv, char** envp) {
Aquamarine::SBackendOptions options;
options.logFunction = aqLog;
std::vector<Aquamarine::SBackendImplementationOptions> implementations;
Aquamarine::SBackendImplementationOptions waylandOptions;
waylandOptions.backendType = Aquamarine::eBackendType::AQ_BACKEND_WAYLAND;
2024-06-18 18:45:05 +02:00
waylandOptions.backendRequestMode = Aquamarine::eBackendRequestMode::AQ_BACKEND_REQUEST_IF_AVAILABLE;
implementations.emplace_back(waylandOptions);
auto aqBackend = Aquamarine::CBackend::create(implementations, options);
newOutputListener = aqBackend->events.newOutput.listen([](const SP<Aquamarine::IOutput> newOutput) {
output = newOutput;
std::cout << "[Client] Got a new output named " << output->name << "\n";
outputFrameListener = output->events.frame.listen([] { onFrame(); });
outputStateListener = output->events.state.listen([](const Aquamarine::IOutput::SStateEvent& event) { onState(event); });
});
newMouseListener = aqBackend->events.newPointer.listen([](const SP<Aquamarine::IPointer>& pointer) {
mouseMotionListener = pointer->events.warp.listen([](const Aquamarine::IPointer::SWarpEvent& event) {
std::cout << "[Client] Mouse warped to " << std::format("{}", event.absolute) << "\n";
});
});
newKeyboardListener = aqBackend->events.newKeyboard.listen([](const SP<Aquamarine::IKeyboard>& keyboard) {
keyboardKeyListener = keyboard->events.key.listen([](const Aquamarine::IKeyboard::SKeyEvent& event) {
std::cout << "[Client] Key " << std::format("{}", event.key) << " state: " << event.pressed << " \n";
});
});
if (!aqBackend || !aqBackend->start()) {
2024-06-18 18:45:05 +02:00
std::cout << "Failed to start the aq backend\n";
return 1;
}
2024-06-27 00:07:59 +02:00
// FIXME: write an event loop.
// aqBackend->enterLoop();
2024-06-18 18:45:05 +02:00
return 0;
}