Move output handling into its own source file
parent
b19a8e10f2
commit
59fa4cfeaa
|
@ -0,0 +1,16 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
struct output {
|
||||||
|
struct wl_output* wl_output;
|
||||||
|
struct wl_list link;
|
||||||
|
|
||||||
|
uint32_t id;
|
||||||
|
uint32_t width;
|
||||||
|
uint32_t height;
|
||||||
|
char make[256];
|
||||||
|
char model[256];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct output* output_new(struct wl_output* wl_output, uint32_t id);
|
||||||
|
void output_destroy(struct output* output);
|
||||||
|
void output_list_destroy(struct wl_list* list);
|
|
@ -45,6 +45,7 @@ sources = [
|
||||||
'src/strlcpy.c',
|
'src/strlcpy.c',
|
||||||
'src/shm.c',
|
'src/shm.c',
|
||||||
'src/screencopy.c',
|
'src/screencopy.c',
|
||||||
|
'src/output.c',
|
||||||
]
|
]
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
|
87
src/main.c
87
src/main.c
|
@ -38,6 +38,7 @@
|
||||||
#include "screencopy.h"
|
#include "screencopy.h"
|
||||||
#include "strlcpy.h"
|
#include "strlcpy.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
#include "output.h"
|
||||||
|
|
||||||
enum frame_capture_backend_type {
|
enum frame_capture_backend_type {
|
||||||
FRAME_CAPTURE_BACKEND_NONE = 0,
|
FRAME_CAPTURE_BACKEND_NONE = 0,
|
||||||
|
@ -45,17 +46,6 @@ enum frame_capture_backend_type {
|
||||||
FRAME_CAPTURE_BACKEND_DMABUF,
|
FRAME_CAPTURE_BACKEND_DMABUF,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct output {
|
|
||||||
struct wl_output* wl_output;
|
|
||||||
struct wl_list link;
|
|
||||||
|
|
||||||
uint32_t id;
|
|
||||||
uint32_t width;
|
|
||||||
uint32_t height;
|
|
||||||
char make[256];
|
|
||||||
char model[256];
|
|
||||||
};
|
|
||||||
|
|
||||||
struct wayvnc {
|
struct wayvnc {
|
||||||
struct wl_display* display;
|
struct wl_display* display;
|
||||||
struct wl_registry* registry;
|
struct wl_registry* registry;
|
||||||
|
@ -95,53 +85,6 @@ frame_capture_backend_from_string(const char* str)
|
||||||
return FRAME_CAPTURE_BACKEND_NONE;
|
return FRAME_CAPTURE_BACKEND_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void output_handle_geometry(void* data, struct wl_output* wl_output,
|
|
||||||
int32_t x, int32_t y, int32_t phys_width,
|
|
||||||
int32_t phys_height, int32_t subpixel,
|
|
||||||
const char* make, const char* model,
|
|
||||||
int32_t transform)
|
|
||||||
{
|
|
||||||
struct output* output = data;
|
|
||||||
|
|
||||||
strlcpy(output->make, make, sizeof(output->make));
|
|
||||||
strlcpy(output->model, model, sizeof(output->make));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void output_handle_mode(void* data, struct wl_output* wl_output,
|
|
||||||
uint32_t flags, int32_t width, int32_t height,
|
|
||||||
int32_t refresh)
|
|
||||||
{
|
|
||||||
struct output* output = data;
|
|
||||||
|
|
||||||
if (!(flags & WL_OUTPUT_MODE_CURRENT))
|
|
||||||
return;
|
|
||||||
|
|
||||||
output->width = width;
|
|
||||||
output->height = height;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void output_handle_done(void* data, struct wl_output* wl_output)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static void output_handle_scale(void* data, struct wl_output* wl_output,
|
|
||||||
int32_t factor)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static const struct wl_output_listener output_listener = {
|
|
||||||
.geometry = output_handle_geometry,
|
|
||||||
.mode = output_handle_mode,
|
|
||||||
.done = output_handle_done,
|
|
||||||
.scale = output_handle_scale,
|
|
||||||
};
|
|
||||||
|
|
||||||
void output_destroy(struct output* output)
|
|
||||||
{
|
|
||||||
wl_output_destroy(output->wl_output);
|
|
||||||
free(output);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct output* wayvnc_output_find(struct wayvnc* self, uint32_t id)
|
struct output* wayvnc_output_find(struct wayvnc* self, uint32_t id)
|
||||||
{
|
{
|
||||||
struct output* output;
|
struct output* output;
|
||||||
|
@ -153,17 +96,6 @@ struct output* wayvnc_output_find(struct wayvnc* self, uint32_t id)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void output_list_destroy(struct wl_list* list)
|
|
||||||
{
|
|
||||||
struct output* output;
|
|
||||||
struct output* tmp;
|
|
||||||
|
|
||||||
wl_list_for_each_safe(output, tmp, list, link) {
|
|
||||||
wl_list_remove(&output->link);
|
|
||||||
output_destroy(output);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void registry_add(void* data, struct wl_registry* registry,
|
static void registry_add(void* data, struct wl_registry* registry,
|
||||||
uint32_t id, const char* interface,
|
uint32_t id, const char* interface,
|
||||||
uint32_t version)
|
uint32_t version)
|
||||||
|
@ -171,19 +103,16 @@ static void registry_add(void* data, struct wl_registry* registry,
|
||||||
struct wayvnc* self = data;
|
struct wayvnc* self = data;
|
||||||
|
|
||||||
if (strcmp(interface, wl_output_interface.name) == 0) {
|
if (strcmp(interface, wl_output_interface.name) == 0) {
|
||||||
struct output* output = calloc(1, sizeof(*output));
|
struct wl_output* wl_output =
|
||||||
if (!output) {
|
wl_registry_bind(registry, id, &wl_output_interface,
|
||||||
log_error("OOM\n");
|
version);
|
||||||
|
if (!wl_output)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
output->id = id;
|
struct output* output = output_new(wl_output, id);
|
||||||
output->wl_output = wl_registry_bind(registry, id,
|
if (!output)
|
||||||
&wl_output_interface,
|
return;
|
||||||
version);
|
|
||||||
|
|
||||||
wl_output_add_listener(output->wl_output, &output_listener,
|
|
||||||
output);
|
|
||||||
wl_list_insert(&self->outputs, &output->link);
|
wl_list_insert(&self->outputs, &output->link);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <wayland-client.h>
|
||||||
|
|
||||||
|
#include "output.h"
|
||||||
|
#include "strlcpy.h"
|
||||||
|
#include "logging.h"
|
||||||
|
|
||||||
|
static void output_handle_geometry(void* data, struct wl_output* wl_output,
|
||||||
|
int32_t x, int32_t y, int32_t phys_width,
|
||||||
|
int32_t phys_height, int32_t subpixel,
|
||||||
|
const char* make, const char* model,
|
||||||
|
int32_t transform)
|
||||||
|
{
|
||||||
|
struct output* output = data;
|
||||||
|
|
||||||
|
strlcpy(output->make, make, sizeof(output->make));
|
||||||
|
strlcpy(output->model, model, sizeof(output->make));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void output_handle_mode(void* data, struct wl_output* wl_output,
|
||||||
|
uint32_t flags, int32_t width, int32_t height,
|
||||||
|
int32_t refresh)
|
||||||
|
{
|
||||||
|
struct output* output = data;
|
||||||
|
|
||||||
|
if (!(flags & WL_OUTPUT_MODE_CURRENT))
|
||||||
|
return;
|
||||||
|
|
||||||
|
output->width = width;
|
||||||
|
output->height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void output_handle_done(void* data, struct wl_output* wl_output)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void output_handle_scale(void* data, struct wl_output* wl_output,
|
||||||
|
int32_t factor)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct wl_output_listener output_listener = {
|
||||||
|
.geometry = output_handle_geometry,
|
||||||
|
.mode = output_handle_mode,
|
||||||
|
.done = output_handle_done,
|
||||||
|
.scale = output_handle_scale,
|
||||||
|
};
|
||||||
|
|
||||||
|
void output_destroy(struct output* output)
|
||||||
|
{
|
||||||
|
wl_output_destroy(output->wl_output);
|
||||||
|
free(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
void output_list_destroy(struct wl_list* list)
|
||||||
|
{
|
||||||
|
struct output* output;
|
||||||
|
struct output* tmp;
|
||||||
|
|
||||||
|
wl_list_for_each_safe(output, tmp, list, link) {
|
||||||
|
wl_list_remove(&output->link);
|
||||||
|
output_destroy(output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct output* output_new(struct wl_output* wl_output, uint32_t id)
|
||||||
|
{
|
||||||
|
struct output* output = calloc(1, sizeof(*output));
|
||||||
|
if (!output) {
|
||||||
|
log_error("OOM\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
output->wl_output = wl_output;
|
||||||
|
output->id = id;
|
||||||
|
|
||||||
|
wl_output_add_listener(output->wl_output, &output_listener,
|
||||||
|
output);
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
Loading…
Reference in New Issue