Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

[WIP] Remove usages of wlr_output_layout_get() #1070

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/output-layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ static void animate_cat(struct sample_state *sample,

if (ur_collision && ul_collision && ll_collision && lr_collision) {
// oops we went off the screen somehow
struct wlr_output_layout_output *l_output =
wlr_output_layout_get(sample->layout, output);
sample->x_offs = l_output->x + 20;
sample->y_offs = l_output->y + 20;
struct wlr_box box;
wlr_output_layout_get_box(sample->layout, output, &box);
sample->x_offs = box.x + 20;
sample->y_offs = box.y + 20;
} else if (ur_collision && ul_collision) {
sample->y_vel = fabs(sample->y_vel);
} else if (lr_collision && ll_collision) {
Expand Down
32 changes: 32 additions & 0 deletions include/types/wlr_output_layout.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef TYPES_WLR_OUTPUT_LAYOUT_H
#define TYPES_WLR_OUTPUT_LAYOUT_H

#include <wlr/types/wlr_output_layout.h>

struct wlr_output_layout_output_state {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to keep this around?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I think the whole point of this state struct was to keep some stuff private.

struct wlr_output_layout *layout;
struct wlr_output_layout_output *l_output;

bool auto_configured;

struct wl_listener mode;
struct wl_listener scale;
struct wl_listener transform;
struct wl_listener output_destroy;
};

struct wlr_output_layout_output {
struct wlr_output *output;
int x, y;
struct wl_list link;
struct wlr_output_layout_output_state *state;

struct {
struct wl_signal destroy;
} events;
};

struct wlr_output_layout_output *wlr_output_layout_get(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function will be exported because it has the wlr_ prefix. If it's in a private header, it shouldn't.

struct wlr_output_layout *layout, struct wlr_output *reference);

#endif
23 changes: 4 additions & 19 deletions include/wlr/types/wlr_output_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,6 @@ struct wlr_output_layout {
void *data;
};

struct wlr_output_layout_output_state;

struct wlr_output_layout_output {
struct wlr_output *output;
int x, y;
struct wl_list link;
struct wlr_output_layout_output_state *state;

struct {
struct wl_signal destroy;
} events;
};

/**
* Creates a wlr_output_layout, which can be used to describing outputs in
* physical space relative to one another, and perform various useful operations
Expand All @@ -43,9 +30,6 @@ struct wlr_output_layout *wlr_output_layout_create();

void wlr_output_layout_destroy(struct wlr_output_layout *layout);

struct wlr_output_layout_output *wlr_output_layout_get(
struct wlr_output_layout *layout, struct wlr_output *reference);

struct wlr_output *wlr_output_layout_output_at(struct wlr_output_layout *layout,
double lx, double ly);

Expand Down Expand Up @@ -82,10 +66,11 @@ void wlr_output_layout_closest_point(struct wlr_output_layout *layout,
/**
* Get the box of the layout for the given reference output in layout
* coordinates. If `reference` is NULL, the box will be for the extents of the
* entire layout.
* entire layout. Returns false if the reference output is present and not in
* the layout or there are no outputs in the layout.
*/
struct wlr_box *wlr_output_layout_get_box(
struct wlr_output_layout *layout, struct wlr_output *reference);
bool wlr_output_layout_get_box(struct wlr_output_layout *layout,
struct wlr_output *reference, struct wlr_box *box);

/**
* Add an auto configured output to the layout. This will place the output in a
Expand Down
32 changes: 16 additions & 16 deletions rootston/desktop.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,13 @@ void view_arrange_maximized(struct roots_view *view) {

struct wlr_output *output = view_get_output(view);
struct roots_output *roots_output = output->data;
struct wlr_box *output_box =
wlr_output_layout_get_box(view->desktop->layout, output);
struct wlr_box output_box;
wlr_output_layout_get_box(view->desktop->layout, output, &output_box);
struct wlr_box usable_area;
memcpy(&usable_area, &roots_output->usable_area,
sizeof(struct wlr_box));
usable_area.x += output_box->x;
usable_area.y += output_box->y;
usable_area.x += output_box.x;
usable_area.y += output_box.y;

view_move_resize(view, usable_area.x, usable_area.y,
usable_area.width, usable_area.height);
Expand Down Expand Up @@ -274,10 +274,10 @@ void view_set_fullscreen(struct roots_view *view, bool fullscreen,
view->saved.width = view_box.width;
view->saved.height = view_box.height;

struct wlr_box *output_box =
wlr_output_layout_get_box(view->desktop->layout, output);
view_move_resize(view, output_box->x, output_box->y, output_box->width,
output_box->height);
struct wlr_box output_box;
wlr_output_layout_get_box(view->desktop->layout, output, &output_box);
view_move_resize(view, output_box.x, output_box.y, output_box.width,
output_box.height);
view_rotate(view, 0);

roots_output->fullscreen_view = view;
Expand Down Expand Up @@ -341,14 +341,14 @@ bool view_center(struct roots_view *view) {
return false;
}

const struct wlr_output_layout_output *l_output =
wlr_output_layout_get(desktop->layout, output);
struct wlr_box layout_box;
wlr_output_layout_get_box(desktop->layout, output, &layout_box);

int width, height;
wlr_output_effective_resolution(output, &width, &height);

double view_x = (double)(width - box.width) / 2 + l_output->x;
double view_y = (double)(height - box.height) / 2 + l_output->y;
double view_x = (double)(width - box.width) / 2 + layout_box.x;
double view_y = (double)(height - box.height) / 2 + layout_box.y;
view_move(view, view_x, view_y);

return true;
Expand Down Expand Up @@ -717,10 +717,10 @@ static void handle_layout_change(struct wl_listener *listener, void *data) {
return;
}

struct wlr_box *center_output_box =
wlr_output_layout_get_box(desktop->layout, center_output);
double center_x = center_output_box->x + center_output_box->width/2;
double center_y = center_output_box->y + center_output_box->height/2;
struct wlr_box center_output_box;
wlr_output_layout_get_box(desktop->layout, center_output, &center_output_box);
double center_x = center_output_box.x + center_output_box.width/2;
double center_y = center_output_box.y + center_output_box.height/2;

struct roots_view *view;
wl_list_for_each(view, &desktop->views, link) {
Expand Down
32 changes: 16 additions & 16 deletions rootston/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ static void render_output(struct roots_output *output) {

float clear_color[] = {0.25f, 0.25f, 0.25f, 1.0f};

const struct wlr_box *output_box =
wlr_output_layout_get_box(desktop->layout, wlr_output);
struct wlr_box output_box;
wlr_output_layout_get_box(desktop->layout, wlr_output, &output_box);

// Check if we can delegate the fullscreen surface to the output
if (output->fullscreen_view != NULL &&
Expand All @@ -413,10 +413,10 @@ static void render_output(struct roots_output *output) {
// Make sure the view is centered on screen
struct wlr_box view_box;
view_get_box(view, &view_box);
double view_x = (double)(output_box->width - view_box.width) / 2 +
output_box->x;
double view_y = (double)(output_box->height - view_box.height) / 2 +
output_box->y;
double view_x = (double)(output_box.width - view_box.width) / 2 +
output_box.x;
double view_y = (double)(output_box.height - view_box.height) / 2 +
output_box.y;
view_move(view, view_x, view_y);

if (has_standalone_surface(view)) {
Expand Down Expand Up @@ -468,9 +468,9 @@ static void render_output(struct roots_output *output) {
wlr_renderer_clear(renderer, clear_color);
}

render_layer(output, output_box, &data,
render_layer(output, &output_box, &data,
&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND]);
render_layer(output, output_box, &data,
render_layer(output, &output_box, &data,
&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]);

// If a view is fullscreen on this output, render it
Expand Down Expand Up @@ -502,7 +502,7 @@ static void render_output(struct roots_output *output) {
render_view(view, &data);
}
// Render top layer above shell views
render_layer(output, output_box, &data,
render_layer(output, &output_box, &data,
&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]);
}

Expand All @@ -511,7 +511,7 @@ static void render_output(struct roots_output *output) {
drag_icons_for_each_surface(server->input, render_surface, &data.layout,
&data);

render_layer(output, output_box, &data,
render_layer(output, &output_box, &data,
&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]);

renderer_end:
Expand Down Expand Up @@ -621,10 +621,10 @@ static void damage_whole_surface(struct wlr_surface *surface, int sx, int sy,

void output_damage_whole_local_surface(struct roots_output *output,
struct wlr_surface *surface, double ox, double oy, float rotation) {
struct wlr_output_layout_output *layout = wlr_output_layout_get(
output->desktop->layout, output->wlr_output);
struct wlr_box box;
wlr_output_layout_get_box(output->desktop->layout, output->wlr_output, &box);
struct damage_data data = { .output = output };
surface_for_each_surface(surface, ox + layout->x, oy + layout->y, 0,
surface_for_each_surface(surface, ox + box.x, oy + box.y, 0,
&data.layout, damage_whole_surface, &data);
}

Expand Down Expand Up @@ -703,10 +703,10 @@ static void damage_from_surface(struct wlr_surface *surface, int sx, int sy,

void output_damage_from_local_surface(struct roots_output *output,
struct wlr_surface *surface, double ox, double oy, float rotation) {
struct wlr_output_layout_output *layout = wlr_output_layout_get(
output->desktop->layout, output->wlr_output);
struct wlr_box box;
wlr_output_layout_get_box(output->desktop->layout, output->wlr_output, &box);
struct damage_data data = { .output = output };
surface_for_each_surface(surface, ox + layout->x, oy + layout->y, 0,
surface_for_each_surface(surface, ox + box.x, oy + box.y, 0,
&data.layout, damage_from_surface, &data);
}

Expand Down
60 changes: 35 additions & 25 deletions types/wlr_cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <wlr/types/wlr_output.h>
#include <wlr/util/log.h>
#include "util/signal.h"
#include "types/wlr_output_layout.h"

struct wlr_cursor_device {
struct wlr_cursor *cursor;
Expand Down Expand Up @@ -203,46 +204,51 @@ static void cursor_warp_unchecked(struct wlr_cursor *cur,
* Absolute movement for touch and pen devices will be relative to this box and
* pointer movement will be constrained to this box.
*
* If none of these are set, returns NULL and absolute movement should be
* If none of these are set, returns false and absolute movement should be
* relative to the extents of the layout.
*/
static struct wlr_box *get_mapping(struct wlr_cursor *cur,
struct wlr_input_device *dev) {
static bool get_mapping(struct wlr_cursor *cur,
struct wlr_input_device *dev, struct wlr_box *box) {
assert(cur->state->layout);
struct wlr_cursor_device *c_device = get_cursor_device(cur, dev);

if (c_device) {
if (c_device->mapped_box) {
return c_device->mapped_box;
memcpy(box, c_device->mapped_box, sizeof(struct wlr_box));
return true;
}
if (c_device->mapped_output) {
return wlr_output_layout_get_box(cur->state->layout,
c_device->mapped_output);
if (c_device->mapped_output &&
wlr_output_layout_get_box(cur->state->layout,
c_device->mapped_output, box)) {
return true;
}
}

if (cur->state->mapped_box) {
return cur->state->mapped_box;
memcpy(box, cur->state->mapped_box, sizeof(struct wlr_box));
return true;
}
if (cur->state->mapped_output) {
return wlr_output_layout_get_box(cur->state->layout,
cur->state->mapped_output);

if (cur->state->mapped_output &&
wlr_output_layout_get_box(cur->state->layout,
cur->state->mapped_output, box)) {
return true;
}

return NULL;
return false;
}

bool wlr_cursor_warp(struct wlr_cursor *cur, struct wlr_input_device *dev,
double lx, double ly) {
assert(cur->state->layout);

struct wlr_box mapping;
bool result = false;
struct wlr_box *mapping = get_mapping(cur, dev);
if (mapping) {
result = wlr_box_contains_point(mapping, lx, ly);
if (get_mapping(cur, dev, &mapping)) {
result = wlr_box_contains_point(&mapping, lx, ly);
} else {
result = wlr_output_layout_contains_point(cur->state->layout, NULL,
lx, ly);
result =
wlr_output_layout_contains_point(cur->state->layout, NULL, lx, ly);
}

if (result) {
Expand All @@ -254,9 +260,9 @@ bool wlr_cursor_warp(struct wlr_cursor *cur, struct wlr_input_device *dev,

static void cursor_warp_closest(struct wlr_cursor *cur,
struct wlr_input_device *dev, double lx, double ly) {
struct wlr_box *mapping = get_mapping(cur, dev);
if (mapping) {
wlr_box_closest_point(mapping, lx, ly, &lx, &ly);
struct wlr_box mapping;
if (get_mapping(cur, dev, &mapping)) {
wlr_box_closest_point(&mapping, lx, ly, &lx, &ly);
} else {
wlr_output_layout_closest_point(cur->state->layout, NULL, lx, ly,
&lx, &ly);
Expand All @@ -270,13 +276,17 @@ void wlr_cursor_absolute_to_layout_coords(struct wlr_cursor *cur,
double *lx, double *ly) {
assert(cur->state->layout);

struct wlr_box *mapping = get_mapping(cur, dev);
if (!mapping) {
mapping = wlr_output_layout_get_box(cur->state->layout, NULL);
struct wlr_box mapping;
if (!get_mapping(cur, dev, &mapping) &&
!wlr_output_layout_get_box(cur->state->layout, NULL, &mapping)) {
// no outputs in the layout
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dunno what to do here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think setting everything to zero is sane.

*lx = 0;
*ly = 0;
return;
}

*lx = !isnan(x) ? mapping->width * x + mapping->x : cur->x;
*ly = !isnan(y) ? mapping->height * y + mapping->y : cur->y;
*lx = !isnan(x) ? mapping.width * x + mapping.x : cur->x;
*ly = !isnan(y) ? mapping.height * y + mapping.y : cur->y;
}

void wlr_cursor_warp_absolute(struct wlr_cursor *cur,
Expand Down
Loading