This commit is contained in:
Your Name 2023-10-31 18:01:36 +03:00
parent 9081bd6d9c
commit b5fba46c63
3 changed files with 52 additions and 29 deletions

View File

@ -1,18 +1,21 @@
CFLAGS:=-s -O0 -pedantic -Wall -Wextra -DWLR_USE_UNSTABLE -Wno-unused-parameter CFLAGS:=-O0 -pedantic -Wall -Wextra -DWLR_USE_UNSTABLE -Wno-unused-parameter -g
LDFLAGS:=$(shell pkg-config --libs wlroots wayland-server) LDFLAGS:=$(shell pkg-config --libs wlroots wayland-server)
CC:=tcc CC:=tcc
WAYLAND_SCANNER:=$(shell pkg-config --variable=wayland_scanner wayland-scanner) WAYLAND_SCANNER:=$(shell pkg-config --variable=wayland_scanner wayland-scanner)
WAYLAND_PROTOCOLS:=$(shell pkg-config --variable=pkgdatadir wayland-protocols) WAYLAND_PROTOCOLS:=$(shell pkg-config --variable=pkgdatadir wayland-protocols)
all: xdg-shell-protocol.h wlr-layer-shell-unstable-v1-protocol.h all: xdg-shell-protocol.h xdg-shell-protocol.c wlr-layer-shell-unstable-v1-protocol.h
$(CC) $(CFLAGS) $(LDFLAGS) src/*.c -Iinclude/ -I. -o micro-wm $(CC) $(CFLAGS) $(LDFLAGS) src/*.c -Iinclude/ -I. -o micro-wm
xdg-shell-protocol.h: xdg-shell-protocol.h:
$(WAYLAND_SCANNER) server-header $(WAYLAND_PROTOCOLS)/stable/xdg-shell/xdg-shell.xml $@ $(WAYLAND_SCANNER) server-header $(WAYLAND_PROTOCOLS)/stable/xdg-shell/xdg-shell.xml $@
xdg-shell-protocol.c:
$(WAYLAND_SCANNER) private-code $(WAYLAND_PROTOCOLS)/stable/xdg-shell/xdg-shell.xml src/$@
wlr-layer-shell-unstable-v1-protocol.h: wlr-layer-shell-unstable-v1-protocol.h:
$(WAYLAND_SCANNER) server-header protocols/wlr-layer-shell-unstable-v1.xml $@ $(WAYLAND_SCANNER) server-header protocols/wlr-layer-shell-unstable-v1.xml $@
clean: clean:
rm micro-wm *-protocol.h rm micro-wm *-protocol.h src/*-protocol.c

View File

@ -6,18 +6,16 @@
#include <assert.h> #include <assert.h>
#include <wayland-server-core.h> #include <wayland-server-core.h>
#include <wlr/backend.h> #include <wlr/backend.h>
#include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h> #include <wlr/render/wlr_renderer.h>
#include <wlr/render/allocator.h> #include <wlr/render/allocator.h>
#include <wlr/types/wlr_compositor.h> #include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_data_control_v1.h>
#include <wlr/types/wlr_data_device.h> #include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_export_dmabuf_v1.h> #include <wlr/types/wlr_input_device.h>
#include <wlr/types/wlr_gamma_control_v1.h> #include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_primary_selection_v1.h>
#include <wlr/types/wlr_screencopy_v1.h>
#include <wlr/types/wlr_cursor.h> #include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_scene.h>
#include <wlr/types/wlr_seat.h> #include <wlr/types/wlr_seat.h>
#include <wlr/types/wlr_xdg_shell.h> #include <wlr/types/wlr_xdg_shell.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
@ -26,11 +24,13 @@
struct server { struct server {
struct wl_display *wl_display; struct wl_display *wl_display;
struct wl_event_loop *wl_event_loop;
struct wlr_backend *backend; struct wlr_backend *backend;
struct wlr_renderer *renderer; struct wlr_renderer *renderer;
struct wlr_allocator *alloc;
/* Monitors */ struct wlr_cursor *cursor;
struct wlr_output_layout *output_layout;
struct wl_list outputs; struct wl_list outputs;
struct wl_listener new_output; struct wl_listener new_output;
}; };
@ -39,12 +39,20 @@ struct output {
struct wlr_output *wlr_output; struct wlr_output *wlr_output;
struct server *server; struct server *server;
struct timespec last_frame;
struct wl_listener destroy; struct wl_listener destroy;
struct wl_listener frame; struct wl_listener frame;
struct wl_list link; struct wl_list link;
}; };
struct keyboard {
struct wlr_input_device *device;
struct server *server;
struct wl_listener modifiers;
struct wl_listener key;
struct wl_list link;
};
#endif #endif

View File

@ -5,18 +5,21 @@ void rendermon(struct wl_listener *listener, void *data) {
struct server *server = output->server; struct server *server = output->server;
struct wlr_output *wlr_output = data; struct wlr_output *wlr_output = data;
struct timespec now; if (!wlr_output_attach_render(output->wlr_output, NULL))
clock_gettime(CLOCK_MONOTONIC, &now); return;
output->last_frame = now;
wlr_output_render_software_cursors(output->wlr_output, NULL);
int width, height; int width, height;
wlr_output_effective_resolution(output->wlr_output, &width, &height); wlr_output_effective_resolution(output->wlr_output, &width, &height);
wlr_renderer_begin(server->renderer, width, height); wlr_renderer_begin(server->renderer, width, height);
float color[4] = {0.3, 0.3, 0.3, 1.0}; float color[4] = {0.3, 0.3, 0.3, 1.0};
wlr_renderer_clear(server->renderer, color); wlr_renderer_clear(server->renderer, color);
wlr_renderer_end(server->renderer); wlr_renderer_end(server->renderer);
wlr_output_commit(output->wlr_output); wlr_output_commit(output->wlr_output);
} }
@ -41,12 +44,15 @@ void createmon(struct wl_listener *listener, void *data) {
die("createmon", 1); die("createmon", 1);
} }
wlr_output_init_render(wlr_output, server->alloc, server->renderer);
if (wl_list_length(&wlr_output->modes) > 0) { 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, wlr_output_preferred_mode(wlr_output));
wlr_output_set_mode(wlr_output, mode); wlr_output_enable(wlr_output, 1);
if (!wlr_output_commit(wlr_output))
return;
} }
clock_gettime(CLOCK_MONOTONIC, &output->last_frame);
output->server = server; output->server = server;
output->wlr_output = wlr_output; output->wlr_output = wlr_output;
@ -58,28 +64,29 @@ void createmon(struct wl_listener *listener, void *data) {
output->frame.notify = rendermon; output->frame.notify = rendermon;
wl_signal_add(&wlr_output->events.frame, &output->frame); wl_signal_add(&wlr_output->events.frame, &output->frame);
wlr_output_schedule_frame(wlr_output); wlr_output_commit(wlr_output);
wlr_output_layout_add_auto(server->output_layout, wlr_output);
} }
void server_init(struct server *server) { void server_init(struct server *server) {
server->wl_display = wl_display_create(); server->wl_display = wl_display_create();
assert(server->wl_display); 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); server->backend = wlr_backend_autocreate(server->wl_display);
assert(server->backend); assert(server->backend);
server->renderer = wlr_renderer_autocreate(server->backend); server->renderer = wlr_renderer_autocreate(server->backend);
assert(server->renderer); assert(server->renderer);
wlr_renderer_init_wl_display(server->renderer, server->wl_display);
server->alloc = wlr_allocator_autocreate(server->backend, server->renderer);
assert(server->alloc);
wlr_compositor_create(server->wl_display, server->renderer);
wlr_data_device_manager_create(server->wl_display); 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); server->output_layout = wlr_output_layout_create();
wlr_data_control_manager_v1_create(server->wl_display);
wlr_gamma_control_manager_v1_create(server->wl_display);
wlr_primary_selection_v1_device_manager_create(server->wl_display);
/* Init monitors */ /* Init monitors */
wl_list_init(&server->outputs); wl_list_init(&server->outputs);
@ -87,12 +94,17 @@ void server_init(struct server *server) {
wl_signal_add(&server->backend->events.new_output, &server->new_output); wl_signal_add(&server->backend->events.new_output, &server->new_output);
const char *socket = wl_display_add_socket_auto(server->wl_display); const char *socket = wl_display_add_socket_auto(server->wl_display);
assert(socket); if (!socket) {
wlr_backend_destroy(server->backend);
wl_display_destroy(server->wl_display);
die("wl_display_add_socket_auto", 1);
}
printf("Running compositor on wayland display '%s'\n", socket); printf("Running compositor on wayland display '%s'\n", socket);
setenv("WAYLAND_DISPLAY", socket, 1); setenv("WAYLAND_DISPLAY", socket, 1);
if (!wlr_backend_start(server->backend)) { if (!wlr_backend_start(server->backend)) {
wlr_backend_destroy(server->backend);
wl_display_destroy(server->wl_display); wl_display_destroy(server->wl_display);
die("wlr_backend_start", 1); die("wlr_backend_start", 1);
} }