Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to wlr scene-graph #50

Merged
merged 10 commits into from Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 10 additions & 1 deletion include/desktop/desktop.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,32 @@
#define KIWMI_DESKTOP_DESKTOP_H

#include <wayland-server.h>
#include <wlr/types/wlr_scene.h>

#include "desktop/stratum.h"

struct kiwmi_desktop {
struct wlr_compositor *compositor;

struct wlr_xdg_shell *xdg_shell;
struct wlr_xdg_decoration_manager_v1 *xdg_decoration_manager;
struct wlr_layer_shell_v1 *layer_shell;

struct wlr_data_device_manager *data_device_manager;

struct wlr_output_layout *output_layout;
struct wl_list outputs; // struct kiwmi_output::link
struct wl_list views; // struct kiwmi_view::link

float bg_color[4];
struct wlr_scene *scene;
struct wlr_scene_rect *background_rect;
struct wlr_scene_tree *strata[KIWMI_STRATA_COUNT];

struct wl_listener xdg_shell_new_surface;
struct wl_listener xdg_toplevel_new_decoration;
struct wl_listener layer_shell_new_surface;
struct wl_listener new_output;
struct wl_listener output_layout_change;

struct {
struct wl_signal new_output;
Expand Down
45 changes: 45 additions & 0 deletions include/desktop/desktop_surface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* Copyright (c), Niclas Meyer <[email protected]>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#ifndef KIWMI_DESKTOP_DESKTOP_SURFACE_H
#define KIWMI_DESKTOP_DESKTOP_SURFACE_H

struct wlr_surface;
struct kiwmi_desktop;

enum kiwmi_desktop_surface_type {
KIWMI_DESKTOP_SURFACE_VIEW,
KIWMI_DESKTOP_SURFACE_LAYER,
};

struct kiwmi_desktop_surface {
// The tree is where the config is supposed to put custom decorations (it
// also contains the surface_node)
struct wlr_scene_tree *tree;
struct wlr_scene_node *surface_node;

struct wlr_scene_tree *popups_tree;

enum kiwmi_desktop_surface_type type;
const struct kiwmi_desktop_surface_impl *impl;
};

struct kiwmi_desktop_surface_impl {
struct kiwmi_output *(*get_output)(
struct kiwmi_desktop_surface *desktop_surface);
};

struct kiwmi_desktop_surface *
desktop_surface_at(struct kiwmi_desktop *desktop, double lx, double ly);
struct kiwmi_output *
desktop_surface_get_output(struct kiwmi_desktop_surface *desktop_surface);
void desktop_surface_get_pos(
struct kiwmi_desktop_surface *desktop_surface,
int *lx,
int *ly);

#endif /* KIWMI_DESKTOP_DESKTOP_SURFACE_H */
14 changes: 4 additions & 10 deletions include/desktop/layer_shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,26 @@
#include <wlr/types/wlr_surface.h>
#include <wlr/util/box.h>

#include "desktop/desktop_surface.h"
#include "desktop/output.h"

struct kiwmi_layer {
struct wl_list link;
struct kiwmi_desktop_surface desktop_surface;

struct wlr_layer_surface_v1 *layer_surface;
uint32_t layer;
uint32_t layer; // enum zwlr_layer_shell_v1_layer

struct kiwmi_output *output;

struct wl_listener destroy;
struct wl_listener commit;
struct wl_listener map;
struct wl_listener unmap;

struct wlr_box geom;
};

void arrange_layers(struct kiwmi_output *output);

struct kiwmi_layer *layer_at(
struct wl_list *layers,
struct wlr_surface **surface,
double ox,
double oy,
double *sx,
double *sy);
void layer_shell_new_surface_notify(struct wl_listener *listener, void *data);

#endif /* KIWMI_DESKTOP_LAYER_SHELL_H */
12 changes: 7 additions & 5 deletions include/desktop/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@
#include <wayland-server.h>
#include <wlr/util/box.h>

#include "desktop/stratum.h"

struct kiwmi_output {
struct wl_list link;
struct kiwmi_desktop *desktop;
struct wlr_output *wlr_output;

struct wl_listener frame;
struct wl_listener commit;
struct wl_listener destroy;
struct wl_listener mode;

struct wl_list layers[4]; // struct kiwmi_layer_surface::link
struct wlr_box usable_area;
struct wl_list layers[4]; // struct kiwmi_layer::link
struct wlr_scene_tree *strata[KIWMI_STRATA_COUNT];

int damaged;
struct wlr_box usable_area;

struct {
struct wl_signal destroy;
Expand All @@ -42,7 +45,6 @@ struct kiwmi_render_data {
};

void new_output_notify(struct wl_listener *listener, void *data);

void output_damage(struct kiwmi_output *output);
void output_layout_change_notify(struct wl_listener *listener, void *data);

#endif /* KIWMI_DESKTOP_OUTPUT_H */
20 changes: 20 additions & 0 deletions include/desktop/popup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* Copyright (c), Niclas Meyer <[email protected]>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#ifndef KIWMI_DESKTOP_POPUP_H
#define KIWMI_DESKTOP_POPUP_H

struct wlr_xdg_popup;
struct kiwmi_desktop_surface;

struct kiwmi_desktop_surface *
popup_get_desktop_surface(struct wlr_xdg_popup *popup);
void popup_attach(
struct wlr_xdg_popup *popup,
struct kiwmi_desktop_surface *desktop_surface);

#endif /* KIWMI_DESKTOP_POPUP_H */
33 changes: 33 additions & 0 deletions include/desktop/stratum.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* Copyright (c), Niclas Meyer <[email protected]>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#ifndef KIWMI_DESKTOP_STRATUM_H
#define KIWMI_DESKTOP_STRATUM_H

#include <stdint.h>

/**
* A stratum is a layer in the scene-graph (the name was chosen to avoid
* confusion with layer-shell). The root node contains a scene_tree for each
* stratum, which itself contains a scene_tree per output.
*/

// There are some assumptions made about the values, don't mindlessly change.
enum kiwmi_stratum {
KIWMI_STRATUM_LS_BACKGROUND, // LS == layer_shell
KIWMI_STRATUM_LS_BOTTOM,
KIWMI_STRATUM_NORMAL,
KIWMI_STRATUM_LS_TOP,
KIWMI_STRATUM_LS_OVERLAY,
KIWMI_STRATUM_POPUPS,
Comment on lines +24 to +26
Copy link
Author

Choose a reason for hiding this comment

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

Other compositors have top, normal popups, fulscreen, overlay, overlay popups, but since kiwmi doesn’t support client-initiated fulscreen, i left it like this.

(This is just a note for later ig.)

KIWMI_STRATA_COUNT,
KIWMI_STRATUM_NONE = KIWMI_STRATA_COUNT,
};

enum kiwmi_stratum stratum_from_layer_shell_layer(uint32_t layer);

#endif /* KIWMI_DESKTOP_STRATUM_H */
91 changes: 5 additions & 86 deletions include/desktop/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <wlr/types/wlr_xdg_shell.h>
#include <wlr/util/edges.h>

#include "desktop/desktop_surface.h"

enum kiwmi_view_prop {
KIWMI_VIEW_PROP_APP_ID,
KIWMI_VIEW_PROP_TITLE,
Expand All @@ -28,7 +30,7 @@ enum kiwmi_view_type {

struct kiwmi_view {
struct wl_list link;
struct wl_list children; // struct kiwmi_view_child::link
struct kiwmi_desktop_surface desktop_surface;

struct kiwmi_desktop *desktop;

Expand All @@ -47,16 +49,10 @@ struct kiwmi_view {
struct wl_listener unmap;
struct wl_listener commit;
struct wl_listener destroy;
struct wl_listener new_popup;
struct wl_listener new_subsurface;
struct wl_listener request_move;
struct wl_listener request_resize;

int x;
int y;

bool mapped;
bool hidden;

struct {
struct wl_signal unmap;
Expand All @@ -71,58 +67,12 @@ struct kiwmi_view {

struct kiwmi_view_impl {
void (*close)(struct kiwmi_view *view);
void (*for_each_surface)(
struct kiwmi_view *view,
wlr_surface_iterator_func_t callback,
void *user_data);
pid_t (*get_pid)(struct kiwmi_view *view);
void (*set_activated)(struct kiwmi_view *view, bool activated);
void (*set_size)(struct kiwmi_view *view, uint32_t width, uint32_t height);
const char *(
*get_string_prop)(struct kiwmi_view *view, enum kiwmi_view_prop prop);
void (*set_tiled)(struct kiwmi_view *view, enum wlr_edges edges);
struct wlr_surface *(*surface_at)(
struct kiwmi_view *view,
double sx,
double sy,
double *sub_x,
double *sub_y);
};

enum kiwmi_view_child_type {
KIWMI_VIEW_CHILD_SUBSURFACE,
KIWMI_VIEW_CHILD_XDG_POPUP,
};

struct kiwmi_view_child {
struct wl_list link;
struct wl_list children; // struct kiwmi_view_child::link

struct kiwmi_view *view;
struct kiwmi_view_child *parent;

enum kiwmi_view_child_type type;
const struct kiwmi_view_child_impl *impl;

struct wlr_surface *wlr_surface;
union {
struct wlr_subsurface *wlr_subsurface;
struct wlr_xdg_popup *wlr_xdg_popup;
};

bool mapped;

struct wl_listener commit;
struct wl_listener map;
struct wl_listener unmap;
struct wl_listener new_popup;
struct wl_listener new_subsurface;
struct wl_listener extension_destroy; // the union'ed object destroy
struct wl_listener surface_destroy; // wlr_surface::events.destroy
};

struct kiwmi_view_child_impl {
void (*reconfigure)(struct kiwmi_view_child *child);
};

struct kiwmi_request_resize_event {
Expand All @@ -131,10 +81,6 @@ struct kiwmi_request_resize_event {
};

void view_close(struct kiwmi_view *view);
void view_for_each_surface(
struct kiwmi_view *view,
wlr_surface_iterator_func_t callback,
void *user_data);
pid_t view_get_pid(struct kiwmi_view *view);
void view_get_size(struct kiwmi_view *view, uint32_t *width, uint32_t *height);
const char *view_get_app_id(struct kiwmi_view *view);
Expand All @@ -143,42 +89,15 @@ void view_set_activated(struct kiwmi_view *view, bool activated);
void view_set_size(struct kiwmi_view *view, uint32_t width, uint32_t height);
void view_set_pos(struct kiwmi_view *view, uint32_t x, uint32_t y);
void view_set_tiled(struct kiwmi_view *view, enum wlr_edges edges);
struct wlr_surface *view_surface_at(
struct kiwmi_view *view,
double sx,
double sy,
double *sub_x,
double *sub_y);
void view_set_hidden(struct kiwmi_view *view, bool hidden);

void view_focus(struct kiwmi_view *view);
struct kiwmi_view *view_at(
struct kiwmi_desktop *desktop,
double lx,
double ly,
struct wlr_surface **surface,
double *sx,
double *sy);
struct kiwmi_view *view_at(struct kiwmi_desktop *desktop, double lx, double ly);
void view_move(struct kiwmi_view *view);
void view_resize(struct kiwmi_view *view, uint32_t edges);
struct kiwmi_view *view_create(
struct kiwmi_desktop *desktop,
enum kiwmi_view_type type,
const struct kiwmi_view_impl *impl);

void
view_init_subsurfaces(struct kiwmi_view_child *child, struct kiwmi_view *view);
bool view_child_is_mapped(struct kiwmi_view_child *child);
void view_child_damage(struct kiwmi_view_child *child);
void view_child_destroy(struct kiwmi_view_child *child);
struct kiwmi_view_child *view_child_create(
struct kiwmi_view_child *parent,
struct kiwmi_view *view,
struct wlr_surface *wlr_surface,
enum kiwmi_view_child_type type,
const struct kiwmi_view_child_impl *impl);
struct kiwmi_view_child *view_child_subsurface_create(
struct kiwmi_view_child *parent,
struct kiwmi_view *view,
struct wlr_subsurface *subsurface);

#endif /* KIWMI_DESKTOP_VIEW_H */
16 changes: 0 additions & 16 deletions include/luak/kiwmi_renderer.h

This file was deleted.

Loading