]> git.mdlowis.com Git - proto/labwc.git/commitdiff
labwc.h: remove "extern struct server server"
authorJohan Malm <jgm323@gmail.com>
Tue, 8 Sep 2020 19:18:12 +0000 (20:18 +0100)
committerJohan Malm <jgm323@gmail.com>
Tue, 8 Sep 2020 19:18:12 +0000 (20:18 +0100)
include/labwc.h
src/action.c
src/dbg.c
src/keyboard.c
src/output.c
src/seat.c
src/server.c
src/view.c
src/xdg.c
src/xwayland-unmanaged.c
src/xwayland.c

index fbffc8464546b78040e02d3340abc79274f44f9c..3f9f124377cb320a7b2cbf0dd71ab1b4abd27636 100644 (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);
index 9787cb451b3d2efd1fcb9724ae5cf0a3f8a5e6ca..d2c403f7817e28e8ee67a7843f1bce91dbc84100 100644 (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")) {
index ff845fae5299803ede5dd488d6809bc6914c03e5..cd9c9db77fcbaf07cae12883064571e1ab2db790 100644 (file)
--- a/src/dbg.c
+++ b/src/dbg.c
@@ -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);
index 02a2e8214217e84ae55b3434dac3e316ad0e093f..75b2ac08eb57a022d00bb5f0b06c11dd094fa1ad 100644 (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;
                }
        }
index 051514d48f5965aab675605ab9b639ed96c901db..dff1403896bc46277f7d630139e8b350fa6242fb 100644 (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,
index 62e4aca6864da84a29f240aa5a951e29cb2696cb..87473e03b2029beaab8999e5acbd84f497744bb2 100644 (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;
 }
index a4878cac57e6a683b714813ce158cc7c9e0bc748..838712288a0f0ff4357580b1d0f645cd69a0eeab 100644 (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) {
index ef97b50719ded80ef2a84d0102f290495aa42b3c..0132efba9deefaeb6fa3fa2bbc055949d3dd600e 100644 (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;
 }
 
index 63d8186280c533c69a528311136d7267933a809d..5d48560ce8c4fcbd9b67b6e0e65804022095b65a 100644 (file)
--- a/src/xdg.c
+++ b/src/xdg.c
@@ -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 = {
index 2d8d0e4db31c05d33276d697817f56be323327b0..76df5c4c61fbb04487515e6cd88e7631e7d005c0 100644 (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);
index 8400d573627d1b567a05fd71ce7072d9abcfae7c..f0a9df86e51466d956b08d9481ca7bd89606fc89 100644 (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;
        }