2019-10-13 12:48:12 +00:00
|
|
|
/*
|
2020-01-24 20:08:57 +00:00
|
|
|
* Copyright (c) 2019 - 2020 Andri Yngvason
|
2019-10-13 12:48:12 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
|
|
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
|
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
|
|
|
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2019-10-13 12:38:47 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
2020-01-24 20:18:37 +00:00
|
|
|
#include <string.h>
|
2020-03-04 21:24:02 +00:00
|
|
|
#include <wayland-client-protocol.h>
|
2019-10-13 12:38:47 +00:00
|
|
|
#include <wayland-client.h>
|
|
|
|
|
|
|
|
#include "output.h"
|
|
|
|
#include "strlcpy.h"
|
|
|
|
#include "logging.h"
|
|
|
|
|
2020-01-24 20:08:57 +00:00
|
|
|
#include "xdg-output-unstable-v1.h"
|
|
|
|
|
2019-10-13 12:38:47 +00:00
|
|
|
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;
|
|
|
|
|
2020-03-04 21:24:02 +00:00
|
|
|
output->x = x;
|
|
|
|
output->y = y;
|
2019-10-13 12:38:47 +00:00
|
|
|
strlcpy(output->make, make, sizeof(output->make));
|
2020-01-24 20:08:57 +00:00
|
|
|
strlcpy(output->model, model, sizeof(output->model));
|
2019-10-13 12:38:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void output_handle_mode(void* data, struct wl_output* wl_output,
|
|
|
|
uint32_t flags, int32_t width, int32_t height,
|
|
|
|
int32_t refresh)
|
|
|
|
{
|
2020-03-04 21:24:02 +00:00
|
|
|
struct output* output = data;
|
|
|
|
|
|
|
|
if (!(flags & WL_OUTPUT_MODE_CURRENT))
|
|
|
|
return;
|
|
|
|
|
|
|
|
output->width = width;
|
|
|
|
output->height = height;
|
2019-10-13 12:38:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2020-01-24 20:08:57 +00:00
|
|
|
zxdg_output_v1_destroy(output->xdg_output);
|
2019-10-13 12:38:47 +00:00
|
|
|
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;
|
|
|
|
}
|
2019-10-13 12:58:56 +00:00
|
|
|
|
2020-01-24 20:08:57 +00:00
|
|
|
void output_logical_position(void* data, struct zxdg_output_v1* xdg_output,
|
|
|
|
int32_t x, int32_t y)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void output_logical_size(void* data, struct zxdg_output_v1* xdg_output,
|
|
|
|
int32_t width, int32_t height)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void output_name(void* data, struct zxdg_output_v1* xdg_output,
|
|
|
|
const char* name)
|
|
|
|
{
|
|
|
|
struct output* self = data;
|
|
|
|
|
|
|
|
strlcpy(self->name, name, sizeof(self->name));
|
|
|
|
}
|
|
|
|
|
|
|
|
void output_description(void* data, struct zxdg_output_v1* xdg_output,
|
|
|
|
const char* description)
|
|
|
|
{
|
|
|
|
struct output* self = data;
|
|
|
|
|
|
|
|
strlcpy(self->description, description, sizeof(self->description));
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct zxdg_output_v1_listener xdg_output_listener = {
|
|
|
|
.logical_position = output_logical_position,
|
|
|
|
.logical_size = output_logical_size,
|
|
|
|
.done = NULL, /* Deprecated */
|
|
|
|
.name = output_name,
|
|
|
|
.description = output_description,
|
|
|
|
};
|
|
|
|
|
|
|
|
void output_set_xdg_output(struct output* self,
|
|
|
|
struct zxdg_output_v1* xdg_output)
|
|
|
|
{
|
|
|
|
self->xdg_output = xdg_output;
|
|
|
|
|
|
|
|
zxdg_output_v1_add_listener(self->xdg_output, &xdg_output_listener,
|
|
|
|
self);
|
|
|
|
}
|
|
|
|
|
2019-10-13 12:58:56 +00:00
|
|
|
struct output* output_find_by_id(struct wl_list* list, uint32_t id)
|
|
|
|
{
|
|
|
|
struct output* output;
|
|
|
|
|
|
|
|
wl_list_for_each(output, list, link)
|
|
|
|
if (output->id == id)
|
|
|
|
return output;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-01-24 20:18:37 +00:00
|
|
|
struct output* output_find_by_name(struct wl_list* list, const char* name)
|
|
|
|
{
|
|
|
|
struct output* output;
|
|
|
|
|
|
|
|
wl_list_for_each(output, list, link)
|
|
|
|
if (strcmp(output->name, name) == 0)
|
|
|
|
return output;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-10-13 12:58:56 +00:00
|
|
|
struct output* output_first(struct wl_list* list)
|
|
|
|
{
|
|
|
|
struct output* output;
|
|
|
|
|
|
|
|
wl_list_for_each(output, list, link)
|
|
|
|
return output;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|