Basic ouput handling
This commit is contained in:
parent
6ace2c9aa9
commit
955b75ef23
8 changed files with 180 additions and 10 deletions
15
include/kiwmi/desktop/output.h
Normal file
15
include/kiwmi/desktop/output.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
/* Copyright (c), Charlotte Meyer <dev@buffet.sh>
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#ifndef KIWMI_DESKTOP_OUTPUT_H
|
||||
#define KIWMI_DESKTOP_OUTPUT_H
|
||||
|
||||
#include <wayland-server.h>
|
||||
|
||||
void new_output_notify(struct wl_listener *listener, void *data);
|
||||
|
||||
#endif /* KIWMI_DESKTOP_OUTPUT_H */
|
26
include/kiwmi/output.h
Normal file
26
include/kiwmi/output.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
/* Copyright (c), Charlotte Meyer <dev@buffet.sh>
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#ifndef KIWMI_OUTPUT_H
|
||||
#define KIWMI_OUTPUT_H
|
||||
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/types/wlr_output.h>
|
||||
|
||||
#include "kiwmi/server.h"
|
||||
|
||||
struct kiwmi_output {
|
||||
struct wl_list link;
|
||||
struct kiwmi_server *server;
|
||||
struct wlr_output *wlr_output;
|
||||
struct wl_listener frame;
|
||||
struct wl_listener destroy;
|
||||
};
|
||||
|
||||
struct kiwmi_output *output_create(struct wlr_output *wlr_output, struct kiwmi_server *server);
|
||||
|
||||
#endif /* KIWMI_OUTPUT_H */
|
|
@ -21,10 +21,12 @@ struct kiwmi_server {
|
|||
struct wlr_data_device_manager *data_device_manager;
|
||||
struct wlr_output_layout *output_layout;
|
||||
const char *socket;
|
||||
struct wl_list outputs; // struct kiwmi_output::link
|
||||
struct wl_listener new_output;
|
||||
};
|
||||
|
||||
bool server_init(struct kiwmi_server *server);
|
||||
void server_run(struct kiwmi_server *server);
|
||||
bool server_run(struct kiwmi_server *server);
|
||||
void server_fini(struct kiwmi_server *server);
|
||||
|
||||
#endif /* KIWMI_SERVER_H */
|
||||
|
|
41
kiwmi/desktop/output.c
Normal file
41
kiwmi/desktop/output.c
Normal file
|
@ -0,0 +1,41 @@
|
|||
/* Copyright (c), Charlotte Meyer <dev@buffet.sh>
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "kiwmi/desktop/output.h"
|
||||
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/types/wlr_output.h>
|
||||
#include <wlr/util/log.h>
|
||||
|
||||
#include "kiwmi/output.h"
|
||||
#include "kiwmi/server.h"
|
||||
|
||||
void
|
||||
new_output_notify(struct wl_listener *listener, void *data)
|
||||
{
|
||||
struct kiwmi_server *server = wl_container_of(listener, server, new_output);
|
||||
struct wlr_output *wlr_output = data;
|
||||
|
||||
wlr_log(WLR_DEBUG, "New output %p: %s", wlr_output, wlr_output->name);
|
||||
|
||||
if (!wl_list_empty(&wlr_output->modes)) {
|
||||
struct wlr_output_mode *mode = wl_container_of(wlr_output->modes.prev, mode, link);
|
||||
wlr_output_set_mode(wlr_output, mode);
|
||||
}
|
||||
|
||||
struct kiwmi_output *output = output_create(wlr_output, server);
|
||||
if (!output) {
|
||||
wlr_log(WLR_ERROR, "Failed to create output");
|
||||
return;
|
||||
}
|
||||
|
||||
wl_list_insert(&server->outputs, &output->link);
|
||||
|
||||
wlr_output_layout_add_auto(server->output_layout, wlr_output);
|
||||
|
||||
wlr_output_create_global(wlr_output);
|
||||
}
|
|
@ -26,7 +26,10 @@ main(void)
|
|||
|
||||
wlr_log(WLR_INFO, "Starting kiwmi v" KIWMI_VERSION);
|
||||
|
||||
server_run(&server);
|
||||
if (!server_run(&server)) {
|
||||
wlr_log(WLR_ERROR, "Failed to run server");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
server_fini(&server);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
kiwmi_sources = files(
|
||||
'main.c',
|
||||
'server.c',
|
||||
'output.c',
|
||||
'desktop/output.c',
|
||||
)
|
||||
|
||||
kiwmi_deps = [
|
||||
|
|
71
kiwmi/output.c
Normal file
71
kiwmi/output.c
Normal file
|
@ -0,0 +1,71 @@
|
|||
/* Copyright (c), Charlotte Meyer <dev@buffet.sh>
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "kiwmi/output.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/types/wlr_output.h>
|
||||
#include <wlr/render/wlr_renderer.h>
|
||||
|
||||
#include "kiwmi/server.h"
|
||||
|
||||
static void output_frame_notify(struct wl_listener *listener, void *data);
|
||||
static void output_destroy_nofity(struct wl_listener *listener, void *data);
|
||||
|
||||
struct kiwmi_output *
|
||||
output_create(struct wlr_output *wlr_output, struct kiwmi_server *server)
|
||||
{
|
||||
struct kiwmi_output *output = calloc(1, sizeof(*output));
|
||||
if (!output) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
output->wlr_output = wlr_output;
|
||||
output->server = server;
|
||||
|
||||
output->frame.notify = output_frame_notify;
|
||||
wl_signal_add(&wlr_output->events.frame, &output->frame);
|
||||
|
||||
output->destroy.notify = output_destroy_nofity;
|
||||
wl_signal_add(&wlr_output->events.destroy, &output->destroy);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
static void
|
||||
output_frame_notify(struct wl_listener *listener, void *data)
|
||||
{
|
||||
struct kiwmi_output *output = wl_container_of(listener, output, frame);
|
||||
struct wlr_output *wlr_output = data;
|
||||
struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend);
|
||||
|
||||
wlr_output_make_current(wlr_output, NULL);
|
||||
wlr_renderer_begin(renderer, wlr_output->width, wlr_output->height);
|
||||
{
|
||||
float color[] = {0.18f, 0.20f, 0.25f, 1.0f};
|
||||
wlr_renderer_clear(renderer, color);
|
||||
wlr_output_render_software_cursors(wlr_output, NULL);
|
||||
wlr_output_swap_buffers(wlr_output, NULL, NULL);
|
||||
}
|
||||
wlr_renderer_end(renderer);
|
||||
}
|
||||
|
||||
static void
|
||||
output_destroy_nofity(struct wl_listener *listener, void *data)
|
||||
{
|
||||
struct kiwmi_output *output = wl_container_of(listener, output, destroy);
|
||||
|
||||
wlr_output_layout_remove(output->server->output_layout, output->wlr_output);
|
||||
|
||||
wl_list_remove(&output->link);
|
||||
wl_list_remove(&output->frame.link);
|
||||
wl_list_remove(&output->frame.link);
|
||||
|
||||
free(output);
|
||||
}
|
|
@ -17,6 +17,8 @@
|
|||
#include <wlr/types/wlr_output_layout.h>
|
||||
#include <wlr/util/log.h>
|
||||
|
||||
#include "kiwmi/desktop/output.h"
|
||||
|
||||
bool
|
||||
server_init(struct kiwmi_server *server)
|
||||
{
|
||||
|
@ -26,6 +28,7 @@ server_init(struct kiwmi_server *server)
|
|||
server->backend = wlr_backend_autocreate(server->wl_display, NULL);
|
||||
if (!server->backend) {
|
||||
wlr_log(WLR_ERROR, "Failed to create backend");
|
||||
wl_display_destroy(server->wl_display);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -37,6 +40,19 @@ server_init(struct kiwmi_server *server)
|
|||
|
||||
server->output_layout = wlr_output_layout_create();
|
||||
|
||||
wl_list_init(&server->outputs);
|
||||
|
||||
server->new_output.notify = new_output_notify;
|
||||
wl_signal_add(&server->backend->events.new_output, &server->new_output);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
server_run(struct kiwmi_server *server)
|
||||
{
|
||||
wlr_log(WLR_DEBUG, "Running Wayland server on display '%s'", server->socket);
|
||||
|
||||
server->socket = wl_display_add_socket_auto(server->wl_display);
|
||||
if (!server->socket) {
|
||||
wlr_log(WLR_ERROR, "Failed to open Wayland socket");
|
||||
|
@ -54,15 +70,9 @@ server_init(struct kiwmi_server *server)
|
|||
|
||||
setenv("WAYLAND_DISPLAY", server->socket, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
server_run(struct kiwmi_server *server)
|
||||
{
|
||||
wlr_log(WLR_DEBUG, "Running Wayland server on display '%s'", server->socket);
|
||||
|
||||
wl_display_run(server->wl_display);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in a new issue