This commit is contained in:
Your Name 2023-10-30 15:00:27 +03:00
parent ea6d60ce95
commit 9081bd6d9c
5 changed files with 67 additions and 39 deletions

View File

@ -1,6 +1,6 @@
CFLAGS:=-s -O0 -pedantic -Wall -Wextra -DWLR_USE_UNSTABLE -b CFLAGS:=-s -O0 -pedantic -Wall -Wextra -DWLR_USE_UNSTABLE -Wno-unused-parameter
LDFLAGS:=$(shell pkg-config --libs wlroots wayland-server libinput) LDFLAGS:=$(shell pkg-config --libs wlroots wayland-server)
CC:=cc 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)

View File

@ -2,9 +2,5 @@
#define _CONFIG_H #define _CONFIG_H
#define LOG_LEVEL WLR_ERROR #define LOG_LEVEL WLR_ERROR
static const MonitorRule monrules[] = {
/* [monitor name] [x] [y] [resolution x] [resolution y]*/
{"VGA-1", -1, -1, 1440, 900}
};
#endif #endif

View File

@ -21,23 +21,30 @@
#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>
#include "structs.h"
#include "config.h" #include "config.h"
#include "die.h" #include "die.h"
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_scene *scene;
struct wlr_output_layout *output_layout;
struct wlr_allocator *alloc;
/* Monitors */ /* Monitors */
struct wl_list outputs; struct wl_list outputs;
struct wl_listener new_output; 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 #endif

View File

@ -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

View File

@ -1,42 +1,79 @@
#include "main.h" #include "main.h"
void rendermon(struct wl_listener *listener, void *data) { 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) { 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) { void createmon(struct wl_listener *listener, void *data) {
struct server *server = wl_container_of(listener, server, new_output); struct server *server = wl_container_of(listener, server, new_output);
struct wlr_output *wlr_output = data; 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 (wl_list_length(&wlr_output->modes) > 0) {
if (!wlr_output_commit(wlr_output)) struct wlr_output_mode *mode = wl_container_of((&wlr_output->modes)->prev, mode, link);
return; 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) { 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);
/* Create a renderer with the default implementation */
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);
/* 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_data_device_manager_create(server->wl_display);
wlr_export_dmabuf_manager_v1_create(server->wl_display); wlr_export_dmabuf_manager_v1_create(server->wl_display);
wlr_screencopy_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); wlr_primary_selection_v1_device_manager_create(server->wl_display);
/* Init monitors */ /* Init monitors */
wl_list_init(&server->outputs);
server->new_output.notify = createmon; server->new_output.notify = createmon;
wl_signal_add(&server->backend->events.new_output, &server->new_output); 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); const char *socket = wl_display_add_socket_auto(server->wl_display);
assert(socket); assert(socket);