summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorvaxerski <43317083+vaxerski@users.noreply.github.com>2022-03-16 21:37:21 +0100
committervaxerski <43317083+vaxerski@users.noreply.github.com>2022-03-16 21:37:21 +0100
commitffd309ca2adc313f2aaaea08b4cac9553982b48c (patch)
treea7c1a0a6df56069bef6868de5ef5a9531dd2386a /src
parentde4c836e97a5798a09bcf96fbdf4cbaf29b0dc5e (diff)
some basic startup code
Diffstat (limited to 'src')
-rw-r--r--src/Compositor.cpp109
-rw-r--r--src/Compositor.hpp40
-rw-r--r--src/defines.hpp4
-rw-r--r--src/events/Events.cpp5
-rw-r--r--src/events/Events.hpp25
-rw-r--r--src/main.cpp15
6 files changed, 195 insertions, 3 deletions
diff --git a/src/Compositor.cpp b/src/Compositor.cpp
index e69de29b..cc6f6d41 100644
--- a/src/Compositor.cpp
+++ b/src/Compositor.cpp
@@ -0,0 +1,109 @@
+#include "Compositor.hpp"
+
+CCompositor::CCompositor() {
+ m_sWLDisplay = wl_display_create();
+
+ m_sWLRBackend = wlr_backend_autocreate(m_sWLDisplay);
+
+ if (!m_sWLRBackend) {
+ Debug::log(CRIT, "m_sWLRBackend was NULL!");
+ RIP("m_sWLRBackend NULL!");
+ return;
+ }
+
+ m_sWLRRenderer = wlr_renderer_autocreate(m_sWLRBackend);
+
+ if (!m_sWLRRenderer) {
+ Debug::log(CRIT, "m_sWLRRenderer was NULL!");
+ RIP("m_sWLRRenderer NULL!");
+ return;
+ }
+
+ m_sWLRAllocator = wlr_allocator_autocreate(m_sWLRBackend, m_sWLRRenderer);
+
+ if (!m_sWLRAllocator) {
+ Debug::log(CRIT, "m_sWLRAllocator was NULL!");
+ RIP("m_sWLRAllocator NULL!");
+ return;
+ }
+
+
+ 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_sWLRXDGActivation - wlr_xdg_activation_v1_create(m_sWLDisplay);
+ m_sWLROutputLayout = wlr_output_layout_create();
+
+ wl_signal_add(&m_sWLRXDGActivation->events.request_activate, &Events::listener_activate);
+ wl_signal_add(&m_sWLROutputLayout->events.change, &Events::listener_change);
+ wl_signal_add(&m_sWLRBackend->events.new_output, &Events::listener_newOutput);
+
+ m_sWLRIdle = wlr_idle_create(m_sWLDisplay);
+ m_sWLRLayerShell = wlr_layer_shell_v1_create(m_sWLDisplay);
+ m_sWLRXDGShell = wlr_xdg_shell_create(m_sWLDisplay);
+
+ wl_signal_add(&m_sWLRLayerShell->events.new_surface, &Events::listener_newLayerSurface);
+ wl_signal_add(&m_sWLRXDGShell->events.new_surface, &Events::listener_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);
+
+ wl_signal_add(&m_sWLRCursor->events.motion, &Events::listener_mouseMove);
+ wl_signal_add(&m_sWLRCursor->events.motion_absolute, &Events::listener_mouseMoveAbsolute);
+ wl_signal_add(&m_sWLRCursor->events.button, &Events::listener_mouseButton);
+ wl_signal_add(&m_sWLRCursor->events.axis, &Events::listener_mouseAxis);
+ wl_signal_add(&m_sWLRCursor->events.frame, &Events::listener_mouseFrame);
+ wl_signal_add(&m_sWLRBackend->events.new_input, &Events::listener_newInput);
+ wl_signal_add(&m_sWLRVKeyboardMgr->events.new_virtual_keyboard, &Events::listener_newKeyboard);
+ wl_signal_add(&m_sWLRSeat->events.request_set_cursor, &Events::listener_requestMouse);
+ wl_signal_add(&m_sWLRSeat->events.request_set_selection, &Events::listener_requestSetSel);
+ wl_signal_add(&m_sWLRSeat->events.request_set_primary_selection, &Events::listener_requestSetPrimarySel);
+ wl_signal_add(&m_sWLROutputMgr->events.apply, &Events::listener_outputMgrApply);
+ wl_signal_add(&m_sWLROutputMgr->events.test, &Events::listener_outputMgrTest);
+
+ // TODO: XWayland
+}
+
+void CCompositor::startCompositor() {
+ m_szWLDisplaySocket = wl_display_add_socket_auto(m_sWLDisplay);
+
+ if (!m_szWLDisplaySocket) {
+ Debug::log(CRIT, "m_szWLDisplaySocket NULL!");
+ RIP("m_szWLDisplaySocket NULL!");
+ }
+
+ setenv("WAYLAND_DISPLAY", m_szWLDisplaySocket, 1);
+
+ signal(SIGPIPE, SIG_IGN);
+
+
+ if (!wlr_backend_start(m_sWLRBackend)) {
+ Debug::log(CRIT, "Backend did not start!");
+ RIP("Backend did not start!");
+ }
+
+ wlr_xcursor_manager_set_cursor_image(m_sWLRXCursorMgr, "left_ptr", m_sWLRCursor);
+
+ // This blocks until we are done.
+ Debug::log(LOG, "Hyprland is ready, running the event loop!");
+ wl_display_run(m_sWLDisplay);
+} \ No newline at end of file
diff --git a/src/Compositor.hpp b/src/Compositor.hpp
index e69de29b..2e724804 100644
--- a/src/Compositor.hpp
+++ b/src/Compositor.hpp
@@ -0,0 +1,40 @@
+#pragma once
+
+#include <memory>
+
+#include "defines.hpp"
+#include "debug/Log.hpp"
+#include "events/Events.hpp"
+
+class CCompositor {
+public:
+ CCompositor();
+ ~CCompositor();
+
+ // ------------------ WLR BASICS ------------------ //
+ wl_display* m_sWLDisplay;
+ wlr_backend* m_sWLRBackend;
+ wlr_renderer* m_sWLRRenderer;
+ wlr_allocator* m_sWLRAllocator;
+ wlr_compositor* m_sWLRCompositor;
+ wlr_xdg_activation_v1* m_sWLRXDGActivation;
+ wlr_output_layout* m_sWLROutputLayout;
+ wlr_idle* m_sWLRIdle;
+ wlr_layer_shell_v1* m_sWLRLayerShell;
+ wlr_xdg_shell* m_sWLRXDGShell;
+ wlr_cursor* m_sWLRCursor;
+ wlr_xcursor_manager* m_sWLRXCursorMgr;
+ wlr_virtual_keyboard_manager_v1* m_sWLRVKeyboardMgr;
+ wlr_seat* m_sWLRSeat;
+ wlr_output_manager_v1* m_sWLROutputMgr;
+ wlr_presentation* m_sWLRPresentation;
+ // ------------------------------------------------- //
+
+
+ const char* m_szWLDisplaySocket;
+
+ void startCompositor();
+};
+
+
+inline std::unique_ptr<CCompositor> g_pCompositor; \ No newline at end of file
diff --git a/src/defines.hpp b/src/defines.hpp
index f72dbb18..ecf90ae8 100644
--- a/src/defines.hpp
+++ b/src/defines.hpp
@@ -6,4 +6,6 @@
#define ISDEBUG false
#endif
-#define RIP(format, ... ) { fprintf(stderr, format "\n", ##__VA_ARGS__); exit(EXIT_FAILURE); } \ No newline at end of file
+#define RIP(format, ... ) { fprintf(stderr, format "\n", ##__VA_ARGS__); exit(EXIT_FAILURE); }
+
+#define LISTENER(name) inline wl_listener listener_##name = {.notify = ##name}; \ No newline at end of file
diff --git a/src/events/Events.cpp b/src/events/Events.cpp
new file mode 100644
index 00000000..6df4c20b
--- /dev/null
+++ b/src/events/Events.cpp
@@ -0,0 +1,5 @@
+#include "Events.hpp"
+
+void Events::listener_activate(wl_listener* listener, void* data) {
+
+} \ No newline at end of file
diff --git a/src/events/Events.hpp b/src/events/Events.hpp
new file mode 100644
index 00000000..7bd24e60
--- /dev/null
+++ b/src/events/Events.hpp
@@ -0,0 +1,25 @@
+#pragma once
+#include "../defines.hpp"
+
+namespace Events {
+ LISTENER(activate);
+ LISTENER(change);
+ LISTENER(newOutput);
+ LISTENER(newLayerSurface);
+ LISTENER(newXDGSurface);
+
+ LISTENER(mouseMove);
+ LISTENER(mouseMoveAbsolute);
+ LISTENER(mouseButton);
+ LISTENER(mouseAxis);
+ LISTENER(mouseFrame);
+ LISTENER(newInput);
+ LISTENER(newKeyboard);
+
+ LISTENER(requestMouse);
+ LISTENER(requestSetSel);
+ LISTENER(requestSetPrimarySel);
+
+ LISTENER(outputMgrApply);
+ LISTENER(outputMgrTest);
+}; \ No newline at end of file
diff --git a/src/main.cpp b/src/main.cpp
index 7b380308..da0437e8 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,14 +1,25 @@
#include "defines.hpp"
#include "debug/Log.hpp"
+#include "Compositor.hpp"
int main(int argc, char** argv) {
-
-
if (!getenv("XDG_RUNTIME_DIR"))
RIP("XDG_RUNTIME_DIR not set!");
+ Debug::log(LOG, "Welcome to Hyprland!");
+
+ // let's init the compositor.
+ // it initializes basic Wayland stuff in the constructor.
+ g_pCompositor = std::make_unique<CCompositor>();
+
+ Debug::log(LOG, "Hyprland init finished.");
+
+ // If all's good to go, start.
+ g_pCompositor->startCompositor();
+ // If we are here it means we got yote.
+ Debug::log(LOG, "Hyprland reached the end.");
return EXIT_SUCCESS;
}