labwc.h: remove "extern struct server server"

This commit is contained in:
Johan Malm 2020-09-08 20:18:12 +01:00
parent 84ebd2dae5
commit e99d0bb34e
11 changed files with 62 additions and 47 deletions

View file

@ -83,8 +83,6 @@ struct server {
struct view *cycle_view;
};
extern struct server server;
struct output {
struct wl_list link;
struct server *server;
@ -142,6 +140,7 @@ struct view {
};
struct xwayland_unmanaged {
struct server *server;
struct wlr_xwayland_surface *xwayland_surface;
struct wl_list link;
int lx, ly;
@ -166,7 +165,8 @@ void xdg_toplevel_decoration(struct wl_listener *listener, void *data);
void xdg_surface_new(struct wl_listener *listener, void *data);
void xwayland_surface_new(struct wl_listener *listener, void *data);
void xwayland_unmanaged_create(struct wlr_xwayland_surface *xsurface);
void xwayland_unmanaged_create(struct server *server,
struct wlr_xwayland_surface *xsurface);
void view_init_position(struct view *view);
/**
@ -179,13 +179,15 @@ struct wlr_box view_get_surface_geometry(struct view *view);
struct wlr_box view_geometry(struct view *view);
void view_resize(struct view *view, struct wlr_box geo);
void view_focus(struct view *view);
struct view *view_next(struct view *current);
struct view *view_next(struct server *server, struct view *current);
bool view_hasfocus(struct view *view);
struct view *view_at(struct server *server, double lx, double ly,
struct wlr_surface **surface, double *sx, double *sy,
int *view_area);
void seat_init(struct wlr_seat *seat);
void seat_focus_surface(struct wlr_surface *surface);
struct wlr_surface *seat_focused_surface(void);
void interactive_begin(struct view *view, enum cursor_mode mode,
uint32_t edges);

View file

@ -11,7 +11,7 @@ void action(struct server *server, struct keybind *keybind)
if (!strcasecmp(keybind->action, "Exit")) {
wl_display_terminate(server->wl_display);
} else if (!strcasecmp(keybind->action, "NextWindow")) {
server->cycle_view = view_next(server->cycle_view);
server->cycle_view = view_next(server, server->cycle_view);
} else if (!strcasecmp(keybind->action, "Execute")) {
spawn_async_no_shell(keybind->command);
} else if (!strcasecmp(keybind->action, "debug-views")) {

View file

@ -35,10 +35,8 @@ static void show_one_xdg_view(struct view *view)
}
fprintf(stderr, " %p %s", (void *)view,
view->xdg_surface->toplevel->app_id);
fprintf(stderr, " {%d, %d, %d, %d}\n", view->xdg_surface->geometry.x,
view->xdg_surface->geometry.y,
view->xdg_surface->geometry.height,
view->xdg_surface->geometry.width);
fprintf(stderr, " {%d, %d, %d, %d}\n", view->x, view->y, view->w,
view->h);
}
static void show_one_xwl_view(struct view *view)
@ -52,7 +50,7 @@ static void show_one_xwl_view(struct view *view)
} else {
fprintf(stderr, "-");
}
fprintf(stderr, " %p %s {%d,%d,%d,%d}\n", (void *)view,
fprintf(stderr, " %p.4 %s {%d,%d,%d,%d}\n", (void *)view,
view->xwayland_surface->class, view->xwayland_surface->x,
view->xwayland_surface->y, view->xwayland_surface->width,
view->xwayland_surface->height);

View file

@ -65,7 +65,8 @@ static void keyboard_handle_key(struct wl_listener *listener, void *data)
server->cycle_view = NULL;
} else if (event->state == WLR_KEY_PRESSED) {
/* cycle to next */
server->cycle_view = view_next(server->cycle_view);
server->cycle_view = view_next(server,
server->cycle_view);
return;
}
}

View file

@ -88,6 +88,7 @@ static void render_decorations(struct wlr_output *output, struct view *view)
struct render_data {
struct wlr_output *output;
struct wlr_output_layout *output_layout;
struct wlr_renderer *renderer;
int lx, ly;
struct timespec *when;
@ -96,37 +97,28 @@ struct render_data {
static void render_surface(struct wlr_surface *surface, int sx, int sy,
void *data)
{
/* This function is called for every surface that needs to be rendered.
*/
struct render_data *rdata = data;
struct wlr_output *output = rdata->output;
/* We first obtain a wlr_texture, which is a GPU resource. wlroots
* automatically handles negotiating these with the client. The
* underlying resource could be an opaque handle passed from the client,
* or the client could have sent a pixel buffer which we copied to the
* GPU, or a few other means. You don't have to worry about this,
* wlroots takes care of it. */
struct wlr_texture *texture = wlr_surface_get_texture(surface);
if (texture == NULL) {
if (!texture)
return;
}
/* The view has a position in layout coordinates. If you have two
* displays, one next to the other, both 1080p, a view on the rightmost
* display might have layout coordinates of 2000,100. We need to
* translate that to output-local coordinates, or (2000 - 1920). */
double ox = 0, oy = 0;
wlr_output_layout_output_coords(server.output_layout, output, &ox, &oy);
wlr_output_layout_output_coords(rdata->output_layout, rdata->output,
&ox, &oy);
ox += rdata->lx + sx;
oy += rdata->ly + sy;
/* TODO: Support HiDPI */
struct wlr_box box = {
.x = ox * output->scale,
.y = oy * output->scale,
.width = surface->current.width * output->scale,
.height = surface->current.height * output->scale,
.x = ox * rdata->output->scale,
.y = oy * rdata->output->scale,
.width = surface->current.width * rdata->output->scale,
.height = surface->current.height * rdata->output->scale,
};
/*
@ -145,7 +137,7 @@ static void render_surface(struct wlr_surface *surface, int sx, int sy,
enum wl_output_transform transform =
wlr_output_transform_invert(surface->current.transform);
wlr_matrix_project_box(matrix, &box, transform, 0,
output->transform_matrix);
rdata->output->transform_matrix);
/*
* This takes our matrix, the texture, and an alpha, and performs the
@ -192,6 +184,7 @@ void output_frame(struct wl_listener *listener, void *data)
struct render_data rdata = {
.output = output->wlr_output,
.output_layout = output->server->output_layout,
.lx = view->x,
.ly = view->y,
.renderer = renderer,
@ -215,9 +208,12 @@ void output_frame(struct wl_listener *listener, void *data)
/* Render xwayland override_redirect surfaces */
struct xwayland_unmanaged *unmanaged;
wl_list_for_each_reverse (unmanaged, &server.unmanaged_surfaces, link) {
wl_list_for_each_reverse (unmanaged,
&output->server->unmanaged_surfaces,
link) {
struct render_data rdata = {
.output = output->wlr_output,
.output_layout = output->server->output_layout,
.lx = unmanaged->lx,
.ly = unmanaged->ly,
.renderer = renderer,

View file

@ -1,11 +1,23 @@
#include "labwc.h"
static struct wlr_seat *current_seat;
void seat_init(struct wlr_seat *seat)
{
current_seat = seat;
}
void seat_focus_surface(struct wlr_surface *surface)
{
if (!surface) {
wlr_seat_keyboard_notify_clear_focus(server.seat);
wlr_seat_keyboard_notify_clear_focus(current_seat);
return;
}
/* TODO: add keyboard stuff */
wlr_seat_keyboard_notify_enter(server.seat, surface, NULL, 0, NULL);
wlr_seat_keyboard_notify_enter(current_seat, surface, NULL, 0, NULL);
}
struct wlr_surface *seat_focused_surface(void)
{
return current_seat->keyboard_state.focused_surface;
}

View file

@ -158,6 +158,7 @@ void server_init(struct server *server)
wlr_log(WLR_ERROR, "cannot allocate seat0");
exit(EXIT_FAILURE);
}
seat_init(server->seat);
server->cursor = wlr_cursor_create();
if (!server->cursor) {

View file

@ -140,10 +140,10 @@ void view_focus(struct view *view)
/* TODO: move xwayland decendants to front */
}
static struct view *first_view(void)
static struct view *first_view(struct server *server)
{
struct view *view;
view = wl_container_of(server.views.next, view, link);
view = wl_container_of(server->views.next, view, link);
return view;
}
@ -172,21 +172,22 @@ static int has_focusable_view(struct wl_list *wl_list)
return false;
}
/*
* Return next view. If NULL provided, return second view from front.
/**
* view_next - return next view
* @current: view used as reference point for defining 'next'
* Note: If @current=NULL, the list's second view is returned
*/
/* TODO: rename function */
struct view *view_next(struct view *current)
struct view *view_next(struct server *server, struct view *current)
{
if (!has_focusable_view(&server.views))
if (!has_focusable_view(&server->views))
return NULL;
struct view *view = current ? current : first_view();
struct view *view = current ? current : first_view(server);
/* Replacement for wl_list_for_each_from() */
do {
view = wl_container_of(view->link.next, view, link);
} while (&view->link == &server.views || !isfocusable(view));
} while (&view->link == &server->views || !isfocusable(view));
return view;
}

View file

@ -148,7 +148,7 @@ static void xdg_toplevel_view_unmap(struct view *view)
{
view->mapped = false;
wl_list_remove(&view->commit.link);
view_focus(view_next(view));
view_focus(view_next(view->server, view));
}
static const struct view_impl xdg_toplevel_view_impl = {

View file

@ -26,7 +26,8 @@ static void unmanaged_handle_map(struct wl_listener *listener, void *data)
wl_container_of(listener, unmanaged, map);
struct wlr_xwayland_surface *xsurface = unmanaged->xwayland_surface;
wl_list_insert(server.unmanaged_surfaces.prev, &unmanaged->link);
wl_list_insert(unmanaged->server->unmanaged_surfaces.prev,
&unmanaged->link);
wl_signal_add(&xsurface->surface->events.commit, &unmanaged->commit);
unmanaged->commit.notify = unmanaged_handle_commit;
@ -46,9 +47,10 @@ static void unmanaged_handle_unmap(struct wl_listener *listener, void *data)
wl_list_remove(&unmanaged->link);
wl_list_remove(&unmanaged->commit.link);
if (server.seat->keyboard_state.focused_surface == xsurface->surface) {
if (seat_focused_surface() == xsurface->surface) {
struct xwayland_unmanaged *u;
wl_list_for_each (u, &server.unmanaged_surfaces, link) {
struct wl_list *list = &unmanaged->server->unmanaged_surfaces;
wl_list_for_each (u, list, link) {
struct wlr_xwayland_surface *prev = u->xwayland_surface;
if (!wlr_xwayland_or_surface_wants_focus(prev))
continue;
@ -68,10 +70,12 @@ static void unmanaged_handle_destroy(struct wl_listener *listener, void *data)
free(unmanaged);
}
void xwayland_unmanaged_create(struct wlr_xwayland_surface *xsurface)
void xwayland_unmanaged_create(struct server *server,
struct wlr_xwayland_surface *xsurface)
{
struct xwayland_unmanaged *unmanaged;
unmanaged = calloc(1, sizeof(struct xwayland_unmanaged));
unmanaged->server = server;
unmanaged->xwayland_surface = xsurface;
wl_signal_add(&xsurface->events.request_configure,
&unmanaged->request_configure);

View file

@ -87,7 +87,7 @@ static void unmap(struct view *view)
{
view->mapped = false;
wl_list_remove(&view->commit.link);
view_focus(view_next(view));
view_focus(view_next(view->server, view));
}
static const struct view_impl xwl_view_impl = {
@ -109,7 +109,7 @@ void xwayland_surface_new(struct wl_listener *listener, void *data)
* but add them to server.unmanaged_surfaces so that we can render them
*/
if (xsurface->override_redirect) {
xwayland_unmanaged_create(xsurface);
xwayland_unmanaged_create(server, xsurface);
return;
}