moved things around

This commit is contained in:
Rakarake 2025-12-25 19:37:53 +01:00
parent 7e2171681d
commit 35d8ca7358
3 changed files with 45 additions and 10 deletions

View file

@ -9,6 +9,7 @@
#include <sys/mman.h> #include <sys/mman.h>
#include "renderer.h" #include "renderer.h"
#include "wayland.h" #include "wayland.h"
#include <string.h>
struct timespec program_start; struct timespec program_start;
@ -26,15 +27,24 @@ double time_since_start() {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
char *shader_path = NULL; char *shader_path = NULL;
int output_type = OUTPUT_WINDOW;
if (argc >= 2) { if (argc >= 2) {
shader_path = argv[1]; shader_path = argv[1];
} else { } else {
printf("need to supply path to shader\n"); printf("need to supply path to shader\n");
exit(1); exit(1);
} }
if (argc >= 3) {
// xdg toplevel window (window) or wlr_layer_shell window (layer)
if (strcmp(argv[2], "window")) {
output_type = OUTPUT_WINDOW;
} else if (strcmp(argv[2], "layer")) {
output_type = OUTPUT_LAYER;
}
}
struct client_state state; struct client_state state;
wayland_init(&state); wayland_init(&state, output_type);
Renderer renderer = new_renderer(); Renderer renderer = new_renderer();

View file

@ -71,12 +71,28 @@ registry_handle_global(void *data, struct wl_registry *registry,
if (strcmp(interface, wl_compositor_interface.name) == 0) { if (strcmp(interface, wl_compositor_interface.name) == 0) {
state->wl_compositor = wl_registry_bind( state->wl_compositor = wl_registry_bind(
registry, name, &wl_compositor_interface, 4); registry, name, &wl_compositor_interface, 4);
// Set up wl_surface
state->wl_surface = wl_compositor_create_surface(state->wl_compositor);
} }
if (strcmp(interface, xdg_wm_base_interface.name) == 0) { if (strcmp(interface, xdg_wm_base_interface.name) == 0) {
state->xdg_wm_base = wl_registry_bind( state->xdg_wm_base = wl_registry_bind(
registry, name, &xdg_wm_base_interface, 1); registry, name, &xdg_wm_base_interface, 1);
xdg_wm_base_add_listener(state->xdg_wm_base, xdg_wm_base_add_listener(state->xdg_wm_base,
&xdg_wm_base_listener, state); &xdg_wm_base_listener, state);
state->xdg_surface = xdg_wm_base_get_xdg_surface(
state->xdg_wm_base, state->wl_surface);
xdg_surface_add_listener(state->xdg_surface, &xdg_surface_listener, state);
state->xdg_toplevel = xdg_surface_get_toplevel(state->xdg_surface);
xdg_toplevel_set_title(state->xdg_toplevel, "GLONKERS! 🕴️");
xdg_toplevel_add_listener(state->xdg_toplevel, &xdg_toplevel_listener, state);
}
if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
state->zwlr_layer_shell_v1 = wl_registry_bind(registry, name, &zwlr_layer_shell_v1_interface, 4);
}
if (strcmp(interface, wl_output_interface.name) == 0) {
state->wl_output = wl_registry_bind(
registry, name, &wl_output_interface, 4);
} }
} }
@ -180,23 +196,21 @@ static void egl_init(struct client_state *state) {
} }
/// Initializes wayland and creates an opengl context /// Initializes wayland and creates an opengl context
void wayland_init(struct client_state *state) { void wayland_init(struct client_state *state, int output_type) {
int width = 700, height = 700; int width = 700, height = 700;
state->width = width; state->width = width;
state->height = height; state->height = height;
state->running = 1; state->running = 1;
state->output_type = output_type;
state->wl_display = wl_display_connect(NULL); state->wl_display = wl_display_connect(NULL);
state->wl_registry = wl_display_get_registry(state->wl_display); state->wl_registry = wl_display_get_registry(state->wl_display);
wl_registry_add_listener(state->wl_registry, &wl_registry_listener, state); wl_registry_add_listener(state->wl_registry, &wl_registry_listener, state);
wl_display_roundtrip(state->wl_display); wl_display_roundtrip(state->wl_display);
state->wl_surface = wl_compositor_create_surface(state->wl_compositor); // wlr_layer_shell
state->xdg_surface = xdg_wm_base_get_xdg_surface( //int layer = ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND;
state->xdg_wm_base, state->wl_surface); //struct zwlr_layer_surface_v1 *zwlr_layer_surface = zwlr_layer_shell_v1_get_layer_surface(state->zwlr_layer_shell_v1, state->wl_surface, state->wl_output, layer, "wallpaper");
xdg_surface_add_listener(state->xdg_surface, &xdg_surface_listener, state); // toplevel
state->xdg_toplevel = xdg_surface_get_toplevel(state->xdg_surface);
xdg_toplevel_set_title(state->xdg_toplevel, "GLONKERS! 🕴️");
xdg_toplevel_add_listener(state->xdg_toplevel, &xdg_toplevel_listener, state);
wl_surface_commit(state->wl_surface); wl_surface_commit(state->wl_surface);
egl_init(state); egl_init(state);

View file

@ -1,10 +1,17 @@
#include <EGL/egl.h> #include <EGL/egl.h>
#include <wayland-egl.h> #include <wayland-egl.h>
#include "xdg-shell-protocol.h" #include "xdg-shell-protocol.h"
#include "wlr-layer-shell-unstable-v1-protocol.h"
/// A normal window
#define OUTPUT_WINDOW 0;
/// A desktop layer (wallpaper)
#define OUTPUT_LAYER 1;
struct client_state { struct client_state {
int width, height; int width, height;
int running; int running;
int output_type;
/* Globals */ /* Globals */
struct wl_display *wl_display; struct wl_display *wl_display;
struct wl_registry *wl_registry; struct wl_registry *wl_registry;
@ -17,12 +24,16 @@ struct client_state {
struct wl_egl_window *egl_window; struct wl_egl_window *egl_window;
// wlr_layer_shell
struct zwlr_layer_shell_v1 *zwlr_layer_shell_v1;
struct wl_output *wl_output;
EGLDisplay egl_display; EGLDisplay egl_display;
EGLConfig egl_config; EGLConfig egl_config;
EGLSurface egl_surface; EGLSurface egl_surface;
EGLContext egl_context; EGLContext egl_context;
}; };
void wayland_init(struct client_state *state); void wayland_init(struct client_state *state, int output_type);
void commit(struct client_state *state); void commit(struct client_state *state);