struct view *cycle_view;
};
-extern struct server server;
-
struct output {
struct wl_list link;
struct server *server;
};
struct xwayland_unmanaged {
+ struct server *server;
struct wlr_xwayland_surface *xwayland_surface;
struct wl_list link;
int lx, ly;
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);
/**
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);
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")) {
}
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)
} 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);
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;
}
}
struct render_data {
struct wlr_output *output;
+ struct wlr_output_layout *output_layout;
struct wlr_renderer *renderer;
int lx, ly;
struct timespec *when;
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,
};
/*
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
struct render_data rdata = {
.output = output->wlr_output,
+ .output_layout = output->server->output_layout,
.lx = view->x,
.ly = view->y,
.renderer = renderer,
/* 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,
#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;
}
wlr_log(WLR_ERROR, "cannot allocate seat0");
exit(EXIT_FAILURE);
}
+ seat_init(server->seat);
server->cursor = wlr_cursor_create();
if (!server->cursor) {
/* 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;
}
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->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 = {
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;
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;
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->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 = {
* 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;
}