From 9081bd6d9c3407a5c8e7dc0fbadfdb096bf3adb0 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 30 Oct 2023 15:00:27 +0300 Subject: [PATCH] fix --- Makefile | 6 ++--- config.h | 4 --- include/main.h | 19 +++++++++----- include/structs.h | 12 --------- src/main.c | 65 +++++++++++++++++++++++++++++++++++++---------- 5 files changed, 67 insertions(+), 39 deletions(-) delete mode 100644 include/structs.h diff --git a/Makefile b/Makefile index 8b5247f..8e52c09 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ -CFLAGS:=-s -O0 -pedantic -Wall -Wextra -DWLR_USE_UNSTABLE -b -LDFLAGS:=$(shell pkg-config --libs wlroots wayland-server libinput) -CC:=cc +CFLAGS:=-s -O0 -pedantic -Wall -Wextra -DWLR_USE_UNSTABLE -Wno-unused-parameter +LDFLAGS:=$(shell pkg-config --libs wlroots wayland-server) +CC:=tcc WAYLAND_SCANNER:=$(shell pkg-config --variable=wayland_scanner wayland-scanner) WAYLAND_PROTOCOLS:=$(shell pkg-config --variable=pkgdatadir wayland-protocols) diff --git a/config.h b/config.h index 3d48b97..cbe6bb6 100644 --- a/config.h +++ b/config.h @@ -2,9 +2,5 @@ #define _CONFIG_H #define LOG_LEVEL WLR_ERROR -static const MonitorRule monrules[] = { - /* [monitor name] [x] [y] [resolution x] [resolution y]*/ - {"VGA-1", -1, -1, 1440, 900} -}; #endif diff --git a/include/main.h b/include/main.h index f5339e0..7f066de 100644 --- a/include/main.h +++ b/include/main.h @@ -21,23 +21,30 @@ #include #include #include -#include "structs.h" #include "config.h" #include "die.h" struct server { struct wl_display *wl_display; - + struct wl_event_loop *wl_event_loop; struct wlr_backend *backend; struct wlr_renderer *renderer; - struct wlr_scene *scene; - struct wlr_output_layout *output_layout; - - struct wlr_allocator *alloc; /* Monitors */ struct wl_list outputs; struct wl_listener new_output; }; +struct output { + struct wlr_output *wlr_output; + struct server *server; + + struct timespec last_frame; + + struct wl_listener destroy; + struct wl_listener frame; + + struct wl_list link; +}; + #endif diff --git a/include/structs.h b/include/structs.h deleted file mode 100644 index 7c52f47..0000000 --- a/include/structs.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _STRUCTS_H -#define _STRUCTS_H - -typedef struct { - const char *name; - int x; - int y; - int res_x; - int res_y; -} MonitorRule; - -#endif diff --git a/src/main.c b/src/main.c index 7ae3323..28bca15 100644 --- a/src/main.c +++ b/src/main.c @@ -1,42 +1,79 @@ #include "main.h" void rendermon(struct wl_listener *listener, void *data) { + struct output *output = wl_container_of(listener, output, frame); + struct server *server = output->server; + struct wlr_output *wlr_output = data; + + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + output->last_frame = now; + + int width, height; + wlr_output_effective_resolution(output->wlr_output, &width, &height); + wlr_renderer_begin(server->renderer, width, height); + + float color[4] = {0.3, 0.3, 0.3, 1.0}; + wlr_renderer_clear(server->renderer, color); + + wlr_renderer_end(server->renderer); + wlr_output_commit(output->wlr_output); } void cleanupmon(struct wl_listener *listener, void *data) { + struct output *output = wl_container_of(listener, output, destroy); + + wl_list_remove(&output->link); + wl_list_remove(&output->destroy.link); + wl_list_remove(&output->frame.link); + + free(output); } void createmon(struct wl_listener *listener, void *data) { struct server *server = wl_container_of(listener, server, new_output); struct wlr_output *wlr_output = data; - wlr_output_init_render(wlr_output, server->alloc, server->renderer); - wlr_output_set_mode(wlr_output, wlr_output_preferred_mode(wlr_output)); + struct output *output = malloc(sizeof(struct output)); + if (output == NULL) { + wlr_backend_destroy(server->backend); + wl_display_destroy(server->wl_display); + die("createmon", 1); + } - wlr_output_enable(wlr_output, 1); - if (!wlr_output_commit(wlr_output)) - return; + if (wl_list_length(&wlr_output->modes) > 0) { + struct wlr_output_mode *mode = wl_container_of((&wlr_output->modes)->prev, mode, link); + wlr_output_set_mode(wlr_output, mode); + } - wlr_output_layout_add_auto(server->output_layout, wlr_output); + clock_gettime(CLOCK_MONOTONIC, &output->last_frame); + + output->server = server; + output->wlr_output = wlr_output; + wl_list_insert(&server->outputs, &output->link); + + output->destroy.notify = cleanupmon; + wl_signal_add(&wlr_output->events.destroy, &output->destroy); + + output->frame.notify = rendermon; + wl_signal_add(&wlr_output->events.frame, &output->frame); + + wlr_output_schedule_frame(wlr_output); } void server_init(struct server *server) { server->wl_display = wl_display_create(); assert(server->wl_display); + server->wl_event_loop = wl_display_get_event_loop(server->wl_display); + assert(server->wl_event_loop); + server->backend = wlr_backend_autocreate(server->wl_display); assert(server->backend); - /* Create a renderer with the default implementation */ server->renderer = wlr_renderer_autocreate(server->backend); assert(server->renderer); - wlr_renderer_init_wl_display(server->renderer, server->wl_display); - - /* Create a default allocator */ - server->alloc = wlr_allocator_autocreate(server->backend, server->renderer); - assert(server->alloc); - wlr_data_device_manager_create(server->wl_display); wlr_export_dmabuf_manager_v1_create(server->wl_display); wlr_screencopy_manager_v1_create(server->wl_display); @@ -45,9 +82,9 @@ void server_init(struct server *server) { wlr_primary_selection_v1_device_manager_create(server->wl_display); /* Init monitors */ + wl_list_init(&server->outputs); server->new_output.notify = createmon; wl_signal_add(&server->backend->events.new_output, &server->new_output); - wl_list_init(&server->outputs); const char *socket = wl_display_add_socket_auto(server->wl_display); assert(socket);