Skip to content

Commit

Permalink
use xdg-output to determine geometry when available
Browse files Browse the repository at this point in the history
  • Loading branch information
yorickvP committed Feb 13, 2019
1 parent ae970ca commit c9f51ed
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
4 changes: 4 additions & 0 deletions include/slurp.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "pool-buffer.h"
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
#include "xdg-output-unstable-v1-client-protocol.h"

struct slurp_box {
int32_t x, y;
Expand All @@ -21,6 +22,7 @@ struct slurp_state {
struct wl_shm *shm;
struct wl_compositor *compositor;
struct zwlr_layer_shell_v1 *layer_shell;
struct zxdg_output_manager_v1 *xdg_output_manager;
struct wl_list outputs; // slurp_output::link
struct wl_list seats; // slurp_seat::link

Expand All @@ -47,6 +49,8 @@ struct slurp_output {
struct wl_surface *surface;
struct zwlr_layer_surface_v1 *layer_surface;

struct zxdg_output_v1 *xdg_output;

struct wl_callback *frame_callback;
bool configured;
bool dirty;
Expand Down
36 changes: 35 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,27 @@ static const struct wl_output_listener output_listener = {
.scale = output_handle_scale,
};

static void xdg_output_handle_logical_position(void *data,
struct zxdg_output_v1 *xdg_output, int32_t x, int32_t y) {
struct slurp_output *output = data;
output->geometry.x = x;
output->geometry.y = y;
}
static void xdg_output_handle_logical_size(void *data,
struct zxdg_output_v1 *xdg_output, int32_t width, int32_t height) {
struct slurp_output *output = data;
output->geometry.width = width;
output->geometry.height = height;
}

static const struct zxdg_output_v1_listener xdg_output_listener = {
.logical_position = xdg_output_handle_logical_position,
.logical_size = xdg_output_handle_logical_size,
.done = noop,
.name = noop,
.description = noop,
};

static void create_output(struct slurp_state *state,
struct wl_output *wl_output) {
struct slurp_output *output = calloc(1, sizeof(struct slurp_output));
Expand All @@ -235,7 +256,12 @@ static void create_output(struct slurp_state *state,
output->scale = 1;
wl_list_insert(&state->outputs, &output->link);

wl_output_add_listener(wl_output, &output_listener, output);
if (state->xdg_output_manager) {
output->xdg_output = zxdg_output_manager_v1_get_xdg_output(state->xdg_output_manager, output->wl_output);
zxdg_output_v1_add_listener(output->xdg_output, &xdg_output_listener, output);
} else {
wl_output_add_listener(wl_output, &output_listener, output);
}
}

static void destroy_output(struct slurp_output *output) {
Expand All @@ -247,6 +273,9 @@ static void destroy_output(struct slurp_output *output) {
finish_buffer(&output->buffers[1]);
wl_cursor_theme_destroy(output->cursor_theme);
zwlr_layer_surface_v1_destroy(output->layer_surface);
if (output->xdg_output) {
zxdg_output_v1_destroy(output->xdg_output);
}
wl_surface_destroy(output->surface);
if (output->frame_callback) {
wl_callback_destroy(output->frame_callback);
Expand Down Expand Up @@ -371,6 +400,8 @@ static void handle_global(void *data, struct wl_registry *registry,
struct wl_output *wl_output =
wl_registry_bind(registry, name, &wl_output_interface, 3);
create_output(state, wl_output);
} else if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0) {
state->xdg_output_manager = wl_registry_bind(registry, name, &zxdg_output_manager_v1_interface, (version > 2 ? 2 : version));
}
}

Expand Down Expand Up @@ -478,6 +509,9 @@ int main(int argc, char *argv[]) {
fprintf(stderr, "compositor doesn't support zwlr_layer_shell_v1\n");
return EXIT_FAILURE;
}
if (state.xdg_output_manager == NULL) {
fprintf(stderr, "compositor doesn't support xdg-output. Guessing geometry from physical output size.\n");
}
if (wl_list_empty(&state.outputs)) {
fprintf(stderr, "no wl_output\n");
return EXIT_FAILURE;
Expand Down

0 comments on commit c9f51ed

Please sign in to comment.