Add wlr_output_layout implementation

An output layout consists of a mapping of outputs to their position in a global
coordinate system that usually cooresponds to the output position in physical
space in front of the user.

Add an example that allows configuration of an output layout and demonstrates
its boundaries with a bouncing image.
This commit is contained in:
Tony Crisci 2017-08-16 11:51:22 -04:00 committed by Drew DeVault
parent 18f1538108
commit 44181b57ac
5 changed files with 422 additions and 0 deletions

View file

@ -2,6 +2,7 @@ lib_wlr_types = static_library('wlr_types', files(
'wlr_input_device.c',
'wlr_keyboard.c',
'wlr_output.c',
'wlr_output_layout.c',
'wlr_pointer.c',
'wlr_region.c',
'wlr_seat.c',

104
types/wlr_output_layout.c Normal file
View file

@ -0,0 +1,104 @@
#include <wlr/util/log.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_layout.h>
#include <stdlib.h>
#include <assert.h>
struct wlr_output_layout *wlr_output_layout_init() {
struct wlr_output_layout *layout = calloc(1, sizeof(struct wlr_output_layout));
wl_list_init(&layout->outputs);
return layout;
}
void wlr_output_layout_destroy(struct wlr_output_layout *layout) {
if (!layout) {
return;
}
struct wlr_output_layout_output *_output, *temp = NULL;
wl_list_for_each_safe(_output, temp, &layout->outputs, link) {
wl_list_remove(&_output->link);
free(_output);
}
free(layout);
}
void wlr_output_layout_add(struct wlr_output_layout *layout,
struct wlr_output *output, int x, int y) {
struct wlr_output_layout_output *layout_output = calloc(1, sizeof(struct wlr_output_layout_output));
layout_output->output = output;
layout_output->x = x;
layout_output->y = y;
wl_list_insert(&layout->outputs, &layout_output->link);
}
static struct wlr_output_layout_output *wlr_output_layout_get(
struct wlr_output_layout *layout, struct wlr_output *reference) {
struct wlr_output_layout_output *ret = NULL;
struct wlr_output_layout_output *_output;
wl_list_for_each(_output, &layout->outputs, link) {
if (_output->output) {
ret = _output;
}
}
return ret;
}
struct wlr_output *wlr_output_layout_output_at(struct wlr_output_layout *layout,
double x, double y) {
struct wlr_output *ret = NULL;
struct wlr_output_layout_output *_output;
wl_list_for_each(_output, &layout->outputs, link) {
if (_output->output) {
int width, height;
wlr_output_effective_resolution(_output->output, &width, &height);
bool has_x = x >= _output->x && x <= _output->x + width;
bool has_y = y >= _output->y && y <= _output->y + height;
if (has_x && has_y) {
ret = _output->output;
break;
}
}
}
return ret;
}
void wlr_output_layout_move(struct wlr_output_layout *layout,
struct wlr_output *output, int x, int y) {
struct wlr_output_layout_output *layout_output =
wlr_output_layout_get(layout, output);
if (layout_output) {
layout_output->x = x;
layout_output->y = y;
}
}
void wlr_output_layout_remove(struct wlr_output_layout *layout,
struct wlr_output *output) {
struct wlr_output_layout_output *layout_output =
wlr_output_layout_get(layout, output);
if (layout_output) {
wl_list_remove(&layout_output->link);
free(layout_output);
}
}
void wlr_output_layout_output_coords(struct wlr_output_layout *layout,
struct wlr_output *reference, int *x, int *y) {
assert(layout && reference);
int src_x = *x;
int src_y = *y;
struct wlr_output_layout_output *_output;
wl_list_for_each(_output, &layout->outputs, link) {
if (_output->output == reference) {
*x = src_x - _output->x;
*y = src_y - _output->y;
return;
}
}
}