swayfx/include/sway/tree/container.h

138 lines
3.1 KiB
C
Raw Normal View History

2017-11-20 09:04:28 +11:00
#ifndef _SWAY_CONTAINER_H
#define _SWAY_CONTAINER_H
#include <stdint.h>
#include <sys/types.h>
#include <wlr/types/wlr_box.h>
2017-12-11 00:48:44 +11:00
#include <wlr/types/wlr_surface.h>
2017-11-20 09:04:28 +11:00
#include "list.h"
2018-03-30 05:31:10 +11:00
extern struct sway_container root_container;
2017-11-20 09:04:28 +11:00
struct sway_view;
2018-01-31 15:09:21 +11:00
struct sway_seat;
2017-11-20 09:04:28 +11:00
/**
* Different kinds of containers.
*
* This enum is in order. A container will never be inside of a container below
* it on this list.
*/
2018-03-30 07:17:55 +11:00
enum sway_container_type {
C_ROOT,
C_OUTPUT,
C_WORKSPACE,
C_CONTAINER,
C_VIEW,
2017-11-20 09:04:28 +11:00
C_TYPES,
};
2018-03-30 07:17:55 +11:00
enum sway_container_layout {
L_NONE,
2017-11-20 09:04:28 +11:00
L_HORIZ,
L_VERT,
L_STACKED,
L_TABBED,
L_FLOATING,
2017-11-20 09:04:28 +11:00
// Keep last
L_LAYOUTS,
};
2018-03-30 07:17:55 +11:00
enum sway_container_border {
B_NONE,
B_PIXEL,
B_NORMAL,
2017-11-20 09:04:28 +11:00
};
2017-12-13 06:02:01 +11:00
struct sway_root;
2017-11-20 09:04:28 +11:00
struct sway_output;
struct sway_view;
struct sway_container {
union {
// TODO: Encapsulate state for other node types as well like C_CONTAINER
struct sway_root *sway_root;
struct sway_output *sway_output;
struct sway_view *sway_view;
2017-11-20 09:04:28 +11:00
};
/**
* A unique ID to identify this container. Primarily used in the
* get_tree JSON output.
*/
size_t id;
char *name;
2018-03-30 07:17:55 +11:00
enum sway_container_type type;
enum sway_container_layout layout;
enum sway_container_layout prev_layout;
enum sway_container_layout workspace_layout;
2017-11-20 09:04:28 +11:00
2018-03-30 12:19:57 +11:00
// TODO convert to layout coordinates
2017-11-20 09:04:28 +11:00
double x, y;
2018-03-30 12:19:57 +11:00
// does not include borders or gaps.
2017-11-20 09:04:28 +11:00
double width, height;
list_t *children;
struct sway_container *parent;
list_t *marks; // list of char*
2017-12-11 03:11:47 +11:00
struct {
struct wl_signal destroy;
} events;
2017-11-20 09:04:28 +11:00
};
// TODO only one container create function and pass the type?
2018-03-30 08:06:29 +11:00
struct sway_container *container_output_create(
2018-03-30 07:17:55 +11:00
struct sway_output *sway_output);
2018-03-30 08:06:29 +11:00
struct sway_container *container_workspace_create(
2018-03-30 07:17:55 +11:00
struct sway_container *output, const char *name);
2018-03-30 08:06:29 +11:00
struct sway_container *container_view_create(
2018-03-30 07:17:55 +11:00
struct sway_container *sibling, struct sway_view *sway_view);
2018-03-30 09:17:31 +11:00
struct sway_container *container_output_destroy(struct sway_container *output);
2017-11-20 09:04:28 +11:00
2018-03-30 08:06:29 +11:00
struct sway_container *container_view_destroy(struct sway_container *view);
2017-11-26 08:30:15 +11:00
2018-03-30 09:17:31 +11:00
struct sway_container *container_set_layout(struct sway_container *container,
enum sway_container_layout layout);
2018-03-30 07:17:55 +11:00
2018-03-30 08:06:29 +11:00
void container_descendents(struct sway_container *root,
2018-03-30 07:17:55 +11:00
enum sway_container_type type,
void (*func)(struct sway_container *item, void *data), void *data);
2018-01-31 15:09:21 +11:00
/**
* Finds a container based on test criteria. Returns the first container that
* passes the test.
*/
2018-03-30 08:06:29 +11:00
struct sway_container *container_find(struct sway_container *container,
2018-03-30 05:31:10 +11:00
bool (*test)(struct sway_container *view, void *data), void *data);
2018-01-31 15:09:21 +11:00
/**
2018-03-30 07:17:55 +11:00
* Finds a parent container with the given struct sway_containerype.
2018-01-31 15:09:21 +11:00
*/
2018-03-30 08:06:29 +11:00
struct sway_container *container_parent(struct sway_container *container,
2018-03-30 07:17:55 +11:00
enum sway_container_type type);
2018-03-30 07:17:55 +11:00
/**
* Find a container at the given coordinates.
*/
2018-03-30 12:19:57 +11:00
struct sway_container *container_at(struct sway_container *parent,
2018-03-30 07:17:55 +11:00
double lx, double ly, struct wlr_surface **surface,
double *sx, double *sy);
2017-12-11 00:48:44 +11:00
2018-02-05 05:39:10 +11:00
/**
* Apply the function for each child of the container breadth first.
2018-02-05 05:39:10 +11:00
*/
2018-03-30 14:08:59 +11:00
void container_for_each_descendent(struct sway_container *container,
2018-03-30 07:17:55 +11:00
void (*f)(struct sway_container *container, void *data), void *data);
2018-02-23 10:03:46 +11:00
2017-11-20 09:04:28 +11:00
#endif