render-ready

This commit is contained in:
vaxerski 2022-03-17 19:03:15 +01:00
parent 6e1819b3dc
commit ab7d727532
7 changed files with 68 additions and 48 deletions

View File

@ -19,6 +19,8 @@ CCompositor::CCompositor() {
return;
}
wlr_renderer_init_wl_display(m_sWLRRenderer, m_sWLDisplay);
m_sWLRAllocator = wlr_allocator_autocreate(m_sWLRBackend, m_sWLRRenderer);
if (!m_sWLRAllocator) {
@ -29,56 +31,36 @@ CCompositor::CCompositor() {
m_sWLRCompositor = wlr_compositor_create(m_sWLDisplay, m_sWLRRenderer);
wlr_export_dmabuf_manager_v1_create(m_sWLDisplay);
wlr_screencopy_manager_v1_create(m_sWLDisplay);
wlr_data_control_manager_v1_create(m_sWLDisplay);
wlr_data_device_manager_create(m_sWLDisplay);
wlr_gamma_control_manager_v1_create(m_sWLDisplay);
wlr_primary_selection_v1_device_manager_create(m_sWLDisplay);
wlr_viewporter_create(m_sWLDisplay);
m_sWLRSubCompositor = wlr_subcompositor_create(m_sWLDisplay);
m_sWLRDataDevMgr = wlr_data_device_manager_create(m_sWLDisplay);
m_sWLRXDGActivation - wlr_xdg_activation_v1_create(m_sWLDisplay);
m_sWLROutputLayout = wlr_output_layout_create();
// wl_signal_add(&m_sWLRXDGActivation->events.request_activate, &Events::listen_activate);
wl_signal_add(&m_sWLROutputLayout->events.change, &Events::listen_change);
wl_signal_add(&m_sWLRBackend->events.new_output, &Events::listen_newOutput);
m_sWLRIdle = wlr_idle_create(m_sWLDisplay);
m_sWLRLayerShell = wlr_layer_shell_v1_create(m_sWLDisplay);
m_sWLRScene = wlr_scene_create();
wlr_scene_attach_output_layout(m_sWLRScene, m_sWLROutputLayout);
m_sWLRXDGShell = wlr_xdg_shell_create(m_sWLDisplay);
wl_signal_add(&m_sWLRLayerShell->events.new_surface, &Events::listen_newLayerSurface);
wl_signal_add(&m_sWLRXDGShell->events.new_surface, &Events::listen_newXDGSurface);
wlr_server_decoration_manager_set_default_mode(wlr_server_decoration_manager_create(m_sWLDisplay), WLR_SERVER_DECORATION_MANAGER_MODE_SERVER);
wlr_xdg_decoration_manager_v1_create(m_sWLDisplay);
m_sWLRCursor = wlr_cursor_create();
wlr_cursor_attach_output_layout(m_sWLRCursor, m_sWLROutputLayout);
m_sWLRXCursorMgr = wlr_xcursor_manager_create(NULL, 24);
m_sWLRVKeyboardMgr = wlr_virtual_keyboard_manager_v1_create(m_sWLDisplay);
m_sWLRSeat = wlr_seat_create(m_sWLDisplay, "seat0");
m_sWLROutputMgr = wlr_output_manager_v1_create(m_sWLDisplay);
m_sWLRPresentation = wlr_presentation_create(m_sWLDisplay, m_sWLRBackend);
m_sWLRXCursorMgr = wlr_xcursor_manager_create(nullptr, 24);
wlr_xcursor_manager_load(m_sWLRXCursorMgr, 1);
wl_signal_add(&m_sWLRCursor->events.motion, &Events::listen_mouseMove);
wl_signal_add(&m_sWLRCursor->events.motion_absolute, &Events::listen_mouseMoveAbsolute);
wl_signal_add(&m_sWLRCursor->events.button, &Events::listen_mouseButton);
wl_signal_add(&m_sWLRCursor->events.axis, &Events::listen_mouseAxis);
wl_signal_add(&m_sWLRCursor->events.frame, &Events::listen_mouseFrame);
m_sWLRSeat = wlr_seat_create(m_sWLDisplay, "seat0");
wl_signal_add(&m_sWLRBackend->events.new_input, &Events::listen_newInput);
wl_signal_add(&m_sWLRVKeyboardMgr->events.new_virtual_keyboard, &Events::listen_newKeyboard);
wl_signal_add(&m_sWLRSeat->events.request_set_cursor, &Events::listen_requestMouse);
wl_signal_add(&m_sWLRSeat->events.request_set_selection, &Events::listen_requestSetSel);
wl_signal_add(&m_sWLRSeat->events.request_set_primary_selection, &Events::listen_requestSetPrimarySel);
wl_signal_add(&m_sWLROutputMgr->events.apply, &Events::listen_outputMgrApply);
wl_signal_add(&m_sWLROutputMgr->events.test, &Events::listen_outputMgrTest);
// TODO: XWayland
}
@ -107,6 +89,7 @@ void CCompositor::startCompositor() {
if (!m_szWLDisplaySocket) {
Debug::log(CRIT, "m_szWLDisplaySocket NULL!");
wlr_backend_destroy(m_sWLRBackend);
RIP("m_szWLDisplaySocket NULL!");
}
@ -118,6 +101,8 @@ void CCompositor::startCompositor() {
if (!wlr_backend_start(m_sWLRBackend)) {
Debug::log(CRIT, "Backend did not start!");
wlr_backend_destroy(m_sWLRBackend);
wl_display_destroy(m_sWLDisplay);
RIP("Backend did not start!");
}

View File

@ -22,6 +22,8 @@ public:
wlr_renderer* m_sWLRRenderer;
wlr_allocator* m_sWLRAllocator;
wlr_compositor* m_sWLRCompositor;
wlr_subcompositor* m_sWLRSubCompositor;
wlr_data_device_manager* m_sWLRDataDevMgr;
wlr_xdg_activation_v1* m_sWLRXDGActivation;
wlr_output_layout* m_sWLROutputLayout;
wlr_idle* m_sWLRIdle;
@ -33,6 +35,7 @@ public:
wlr_seat* m_sWLRSeat;
wlr_output_manager_v1* m_sWLROutputMgr;
wlr_presentation* m_sWLRPresentation;
wlr_scene* m_sWLRScene;
// ------------------------------------------------- //

View File

@ -16,13 +16,13 @@ void Events::listener_change(wl_listener* listener, void* data) {
const auto CONFIGHEAD = wlr_output_configuration_head_v1_create(CONFIG, m.output);
// TODO: clients off of disabled
wlr_box BOX;
wlr_output_layout_get_box(g_pCompositor->m_sWLROutputLayout, m.output, &BOX);
const auto BOX = wlr_output_layout_get_box(g_pCompositor->m_sWLROutputLayout, m.output);
m.vecSize.x = BOX->width;
m.vecSize.y = BOX->height;
m.vecPosition.x = BOX->x;
m.vecPosition.y = BOX->y;
m.vecSize.x = BOX.width;
m.vecSize.y = BOX.height;
m.vecPosition.x = BOX.x;
m.vecPosition.y = BOX.y;
CONFIGHEAD->state.enabled = m.output->enabled;
CONFIGHEAD->state.mode = m.output->current_mode;
@ -77,22 +77,24 @@ void Events::listener_newOutput(wl_listener* listener, void* data) {
void Events::listener_monitorFrame(wl_listener* listener, void* data) {
SMonitor* const PMONITOR = wl_container_of(listener, PMONITOR, listen_monitorFrame);
const auto TIMENOWNS = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
const float bgcol[4] = {0.1f,0.1f,0.1f,1.f};
const float rectcol[4] = {0.69f,0.1f,0.69f,1.f};
while (!wlr_output_commit(PMONITOR->output)) {
if (!wlr_output_attach_render(PMONITOR->output, nullptr))
return;
if (!wlr_output_attach_render(PMONITOR->output, nullptr))
return;
wlr_renderer_begin(g_pCompositor->m_sWLRRenderer, PMONITOR->vecSize.x, PMONITOR->vecSize.y);
wlr_renderer_clear(g_pCompositor->m_sWLRRenderer, bgcol);
wlr_renderer_begin(g_pCompositor->m_sWLRRenderer, PMONITOR->vecSize.x, PMONITOR->vecSize.y);
wlr_renderer_clear(g_pCompositor->m_sWLRRenderer, bgcol);
// TODO: render clients
// TODO: render clients
wlr_output_render_software_cursors(PMONITOR->output, NULL);
wlr_output_render_software_cursors(PMONITOR->output, NULL);
wlr_renderer_end(g_pCompositor->m_sWLRRenderer);
}
wlr_renderer_end(g_pCompositor->m_sWLRRenderer);
wlr_output_commit(PMONITOR->output);
}
void Events::listener_monitorDestroy(wl_listener* listener, void* data) {
@ -159,7 +161,7 @@ void Events::listener_mouseButton(wl_listener* listener, void* data) {
}
void Events::listener_mouseFrame(wl_listener* listener, void* data) {
wlr_seat_pointer_notify_frame(g_pCompositor->m_sWLRSeat);
}
void Events::listener_mouseMove(wl_listener* listener, void* data) {
@ -167,11 +169,30 @@ void Events::listener_mouseMove(wl_listener* listener, void* data) {
}
void Events::listener_mouseMoveAbsolute(wl_listener* listener, void* data) {
g_pInputManager->onMouseWarp((wlr_event_pointer_motion_absolute*)data);
}
void Events::listener_newInput(wl_listener* listener, void* data) {
const auto DEVICE = (wlr_input_device*)data;
switch(DEVICE->type) {
case WLR_INPUT_DEVICE_KEYBOARD:
Debug::log(LOG, "Attached a keyboard with name %s", DEVICE->name);
// TODO:
break;
case WLR_INPUT_DEVICE_POINTER:
Debug::log(LOG, "Attached a mouse with name %s", DEVICE->name);
wlr_cursor_attach_input_device(g_pCompositor->m_sWLRCursor, DEVICE);
break;
default:
break;
}
uint32_t capabilities = WL_SEAT_CAPABILITY_POINTER;
// todo: keyboard caps
wlr_seat_set_capabilities(g_pCompositor->m_sWLRSeat, capabilities);
}
void Events::listener_newKeyboard(wl_listener* listener, void* data) {

View File

@ -64,6 +64,8 @@ extern "C" {
#include <wlr/types/wlr_xdg_decoration_v1.h>
#include <wlr/types/wlr_xdg_output_v1.h>
#include <wlr/types/wlr_xdg_shell.h>
#include <wlr/types/wlr_subcompositor.h>
#include <wlr/types/wlr_scene.h>
#include <wlr/util/log.h>
#include <wlr/xwayland.h>
#include <xkbcommon/xkbcommon.h>

View File

@ -20,3 +20,6 @@ void CInputManager::onMouseWarp(wlr_event_pointer_motion_absolute* e) {
wlr_cursor_warp_absolute(g_pCompositor->m_sWLRCursor, e->device, e->x, e->y);
}
Vector2D CInputManager::getMouseCoordsInternal() {
return m_vMouseCoords;
}

View File

@ -8,6 +8,9 @@ public:
void onMouseMoved(wlr_event_pointer_motion*);
void onMouseWarp(wlr_event_pointer_motion_absolute*);
Vector2D getMouseCoordsInternal();
private:
Vector2D m_vMouseCoords = Vector2D(0,0);
Vector2D m_vWLRMouseCoords = Vector2D(0,0);

View File

@ -22,5 +22,8 @@ int main(int argc, char** argv) {
// If we are here it means we got yote.
Debug::log(LOG, "Hyprland reached the end.");
wl_display_destroy_clients(g_pCompositor->m_sWLDisplay);
wl_display_destroy(g_pCompositor->m_sWLDisplay);
return EXIT_SUCCESS;
}