2018-03-30 14:41:33 +11:00
|
|
|
#ifndef _SWAY_CONTAINER_H
|
|
|
|
#define _SWAY_CONTAINER_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <wlr/types/wlr_box.h>
|
|
|
|
#include <wlr/types/wlr_surface.h>
|
|
|
|
#include "list.h"
|
|
|
|
|
|
|
|
extern struct sway_container root_container;
|
|
|
|
|
|
|
|
struct sway_view;
|
|
|
|
struct sway_seat;
|
|
|
|
|
2018-05-22 08:27:42 +10:00
|
|
|
#define TITLEBAR_BORDER_THICKNESS 1
|
|
|
|
|
|
|
|
// Padding includes titlebar border
|
|
|
|
#define TITLEBAR_H_PADDING 3
|
|
|
|
#define TITLEBAR_V_PADDING 4
|
|
|
|
|
2018-03-30 14:41:33 +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.
|
|
|
|
*/
|
|
|
|
enum sway_container_type {
|
|
|
|
C_ROOT,
|
|
|
|
C_OUTPUT,
|
|
|
|
C_WORKSPACE,
|
|
|
|
C_CONTAINER,
|
|
|
|
C_VIEW,
|
|
|
|
|
2018-04-06 13:22:08 +10:00
|
|
|
// Keep last
|
2018-03-30 14:41:33 +11:00
|
|
|
C_TYPES,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum sway_container_layout {
|
|
|
|
L_NONE,
|
|
|
|
L_HORIZ,
|
|
|
|
L_VERT,
|
|
|
|
L_STACKED,
|
|
|
|
L_TABBED,
|
2018-05-25 09:10:35 +10:00
|
|
|
L_FLOATING,
|
2018-03-30 14:41:33 +11:00
|
|
|
};
|
|
|
|
|
|
|
|
enum sway_container_border {
|
|
|
|
B_NONE,
|
|
|
|
B_PIXEL,
|
|
|
|
B_NORMAL,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sway_root;
|
|
|
|
struct sway_output;
|
2018-04-17 09:31:34 +10:00
|
|
|
struct sway_workspace;
|
2018-03-30 14:41:33 +11:00
|
|
|
struct sway_view;
|
|
|
|
|
2018-06-03 16:35:06 +10:00
|
|
|
struct sway_container_state {
|
|
|
|
// Container/swayc properties
|
|
|
|
enum sway_container_layout layout;
|
|
|
|
double swayc_x, swayc_y;
|
|
|
|
double swayc_width, swayc_height;
|
|
|
|
|
2018-07-25 20:56:23 +10:00
|
|
|
bool is_fullscreen;
|
|
|
|
|
2018-06-11 11:03:43 +10:00
|
|
|
bool has_gaps;
|
|
|
|
double current_gaps;
|
|
|
|
double gaps_inner;
|
|
|
|
double gaps_outer;
|
|
|
|
|
2018-06-23 16:24:11 +10:00
|
|
|
struct sway_container *parent;
|
|
|
|
list_t *children;
|
2018-06-03 16:35:06 +10:00
|
|
|
|
2018-07-15 15:20:21 +10:00
|
|
|
struct sway_container *focused_inactive_child;
|
|
|
|
bool focused;
|
|
|
|
|
2018-06-03 16:35:06 +10:00
|
|
|
// View properties
|
|
|
|
double view_x, view_y;
|
|
|
|
double view_width, view_height;
|
|
|
|
|
|
|
|
enum sway_container_border border;
|
|
|
|
int border_thickness;
|
|
|
|
bool border_top;
|
|
|
|
bool border_bottom;
|
|
|
|
bool border_left;
|
|
|
|
bool border_right;
|
2018-06-23 16:24:11 +10:00
|
|
|
|
|
|
|
// Workspace properties
|
2018-07-25 20:56:23 +10:00
|
|
|
struct sway_container *ws_fullscreen;
|
2018-06-23 16:24:11 +10:00
|
|
|
struct sway_container *ws_floating;
|
2018-06-03 16:35:06 +10:00
|
|
|
};
|
|
|
|
|
2018-03-30 14:41:33 +11:00
|
|
|
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;
|
2018-04-17 09:31:34 +10:00
|
|
|
struct sway_workspace *sway_workspace;
|
2018-03-30 14:41:33 +11:00
|
|
|
struct sway_view *sway_view;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A unique ID to identify this container. Primarily used in the
|
|
|
|
* get_tree JSON output.
|
|
|
|
*/
|
|
|
|
size_t id;
|
|
|
|
|
2018-06-06 19:19:30 +10:00
|
|
|
// The pending state is the main container properties, and the current state is in the below struct.
|
|
|
|
// This means most places of the code can refer to the main variables (pending state) and it'll just work.
|
|
|
|
struct sway_container_state current;
|
2018-06-03 16:35:06 +10:00
|
|
|
|
2018-05-05 12:36:50 +10:00
|
|
|
char *name; // The view's title (unformatted)
|
|
|
|
char *formatted_title; // The title displayed in the title bar
|
2018-03-30 14:41:33 +11:00
|
|
|
|
|
|
|
enum sway_container_type type;
|
|
|
|
enum sway_container_layout layout;
|
|
|
|
enum sway_container_layout prev_layout;
|
|
|
|
|
2018-05-24 22:30:44 +10:00
|
|
|
bool is_sticky;
|
2018-05-04 22:24:25 +10:00
|
|
|
|
2018-04-03 04:35:43 +10:00
|
|
|
// For C_ROOT, this has no meaning
|
2018-05-26 16:26:10 +10:00
|
|
|
// For other types, this is the position in layout coordinates
|
2018-04-30 21:24:13 +10:00
|
|
|
// Includes borders
|
2018-03-30 14:41:33 +11:00
|
|
|
double x, y;
|
|
|
|
double width, height;
|
2018-05-25 11:15:43 +10:00
|
|
|
double saved_x, saved_y;
|
2018-04-28 11:26:14 +10:00
|
|
|
double saved_width, saved_height;
|
2018-03-30 14:41:33 +11:00
|
|
|
|
2018-07-25 20:56:23 +10:00
|
|
|
bool is_fullscreen;
|
|
|
|
|
2018-06-09 23:34:56 +10:00
|
|
|
// The gaps currently applied to the container.
|
|
|
|
double current_gaps;
|
|
|
|
|
|
|
|
bool has_gaps;
|
|
|
|
double gaps_inner;
|
|
|
|
double gaps_outer;
|
|
|
|
|
2018-03-30 14:41:33 +11:00
|
|
|
list_t *children;
|
|
|
|
|
|
|
|
struct sway_container *parent;
|
|
|
|
|
2018-07-22 14:10:40 +10:00
|
|
|
// Indicates that the container is a scratchpad container.
|
|
|
|
// Both hidden and visible scratchpad containers have scratchpad=true.
|
|
|
|
// Hidden scratchpad containers have a NULL parent.
|
|
|
|
bool scratchpad;
|
|
|
|
|
2018-04-03 14:47:45 +10:00
|
|
|
float alpha;
|
|
|
|
|
2018-05-02 23:07:52 +10:00
|
|
|
struct wlr_texture *title_focused;
|
|
|
|
struct wlr_texture *title_focused_inactive;
|
|
|
|
struct wlr_texture *title_unfocused;
|
|
|
|
struct wlr_texture *title_urgent;
|
2018-05-03 15:02:16 +10:00
|
|
|
size_t title_height;
|
2018-05-02 23:07:52 +10:00
|
|
|
|
2018-06-23 16:24:11 +10:00
|
|
|
list_t *instructions; // struct sway_transaction_instruction *
|
|
|
|
|
|
|
|
bool destroying;
|
|
|
|
|
2018-07-14 23:14:55 +10:00
|
|
|
// If true, indicates that the container has pending state that differs from
|
|
|
|
// the current.
|
|
|
|
bool dirty;
|
|
|
|
|
2018-03-30 14:41:33 +11:00
|
|
|
struct {
|
|
|
|
struct wl_signal destroy;
|
2018-04-01 11:21:26 +10:00
|
|
|
// Raised after the tree updates, but before arrange_windows
|
|
|
|
// Passed the previous parent
|
|
|
|
struct wl_signal reparent;
|
2018-03-30 14:41:33 +11:00
|
|
|
} events;
|
2018-05-19 23:33:36 +10:00
|
|
|
|
|
|
|
struct wl_listener reparent;
|
2018-03-30 14:41:33 +11:00
|
|
|
};
|
|
|
|
|
2018-03-31 15:44:17 +11:00
|
|
|
struct sway_container *container_create(enum sway_container_type type);
|
|
|
|
|
2018-04-01 11:21:26 +10:00
|
|
|
const char *container_type_to_str(enum sway_container_type type);
|
|
|
|
|
2018-04-06 08:31:19 +10:00
|
|
|
struct sway_container *output_create(struct sway_output *sway_output);
|
2018-03-30 14:41:33 +11:00
|
|
|
|
2018-04-01 10:52:34 +10:00
|
|
|
/**
|
|
|
|
* Create a new container container. A container container can be a a child of
|
|
|
|
* a workspace container or another container container.
|
|
|
|
*/
|
|
|
|
struct sway_container *container_container_create();
|
2018-03-30 14:41:33 +11:00
|
|
|
|
2018-04-01 10:52:34 +10:00
|
|
|
/**
|
|
|
|
* Create a new output. Outputs are children of the root container and have no
|
|
|
|
* order in the tree structure.
|
|
|
|
*/
|
2018-04-04 09:52:17 +10:00
|
|
|
struct sway_container *output_create(struct sway_output *sway_output);
|
2018-04-01 10:52:34 +10:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new workspace container. Workspaces are children of an output
|
|
|
|
* container and are ordered alphabetically by name.
|
|
|
|
*/
|
2018-04-06 08:31:19 +10:00
|
|
|
struct sway_container *workspace_create(struct sway_container *output,
|
|
|
|
const char *name);
|
2018-03-30 14:41:33 +11:00
|
|
|
|
2018-04-01 10:52:34 +10:00
|
|
|
/*
|
|
|
|
* Create a new view container. A view can be a child of a workspace container
|
|
|
|
* or a container container and are rendered in the order and structure of
|
|
|
|
* how they are attached to the tree.
|
|
|
|
*/
|
2018-03-30 14:41:33 +11:00
|
|
|
struct sway_container *container_view_create(
|
|
|
|
struct sway_container *sibling, struct sway_view *sway_view);
|
|
|
|
|
2018-06-23 16:24:11 +10:00
|
|
|
void container_free(struct sway_container *cont);
|
|
|
|
|
2018-04-04 02:25:19 +10:00
|
|
|
struct sway_container *container_destroy(struct sway_container *container);
|
|
|
|
|
2018-04-03 11:01:33 +10:00
|
|
|
struct sway_container *container_close(struct sway_container *container);
|
|
|
|
|
2018-03-30 14:53:38 +11:00
|
|
|
void container_descendants(struct sway_container *root,
|
2018-03-30 14:41:33 +11:00
|
|
|
enum sway_container_type type,
|
|
|
|
void (*func)(struct sway_container *item, void *data), void *data);
|
|
|
|
|
|
|
|
/**
|
2018-04-01 10:52:34 +10:00
|
|
|
* Search a container's descendants a container based on test criteria. Returns
|
|
|
|
* the first container that passes the test.
|
2018-03-30 14:41:33 +11:00
|
|
|
*/
|
|
|
|
struct sway_container *container_find(struct sway_container *container,
|
|
|
|
bool (*test)(struct sway_container *view, void *data), void *data);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds a parent container with the given struct sway_containerype.
|
|
|
|
*/
|
|
|
|
struct sway_container *container_parent(struct sway_container *container,
|
|
|
|
enum sway_container_type type);
|
|
|
|
|
|
|
|
/**
|
2018-04-01 10:52:34 +10:00
|
|
|
* Find a container at the given coordinates. Returns the the surface and
|
|
|
|
* surface-local coordinates of the given layout coordinates if the container
|
|
|
|
* is a view and the view contains a surface at those coordinates.
|
2018-03-30 14:41:33 +11:00
|
|
|
*/
|
2018-04-01 10:52:34 +10:00
|
|
|
struct sway_container *container_at(struct sway_container *container,
|
2018-05-19 22:54:50 +10:00
|
|
|
double ox, double oy, struct wlr_surface **surface,
|
2018-03-30 14:41:33 +11:00
|
|
|
double *sx, double *sy);
|
|
|
|
|
2018-05-24 22:30:44 +10:00
|
|
|
/**
|
|
|
|
* Same as container_at, but only checks floating views and expects coordinates
|
|
|
|
* to be layout coordinates, as that's what floating views use.
|
|
|
|
*/
|
|
|
|
struct sway_container *floating_container_at(double lx, double ly,
|
|
|
|
struct wlr_surface **surface, double *sx, double *sy);
|
|
|
|
|
2018-03-30 14:41:33 +11:00
|
|
|
/**
|
2018-04-01 10:52:34 +10:00
|
|
|
* Apply the function for each descendant of the container breadth first.
|
2018-03-30 14:41:33 +11:00
|
|
|
*/
|
2018-03-30 14:53:38 +11:00
|
|
|
void container_for_each_descendant_bfs(struct sway_container *container,
|
|
|
|
void (*f)(struct sway_container *container, void *data), void *data);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply the function for each child of the container depth first.
|
|
|
|
*/
|
|
|
|
void container_for_each_descendant_dfs(struct sway_container *container,
|
2018-03-30 14:41:33 +11:00
|
|
|
void (*f)(struct sway_container *container, void *data), void *data);
|
|
|
|
|
2018-04-01 10:52:34 +10:00
|
|
|
/**
|
|
|
|
* Returns true if the given container is an ancestor of this container.
|
|
|
|
*/
|
2018-05-28 12:45:42 +10:00
|
|
|
bool container_has_ancestor(struct sway_container *container,
|
|
|
|
struct sway_container *ancestor);
|
2018-03-31 01:31:21 +11:00
|
|
|
|
2018-04-01 10:52:34 +10:00
|
|
|
/**
|
|
|
|
* Returns true if the given container is a child descendant of this container.
|
|
|
|
*/
|
2018-04-01 05:22:10 +10:00
|
|
|
bool container_has_child(struct sway_container *con,
|
|
|
|
struct sway_container *child);
|
|
|
|
|
2018-05-13 02:37:48 +10:00
|
|
|
int container_count_descendants_of_type(struct sway_container *con,
|
|
|
|
enum sway_container_type type);
|
|
|
|
|
2018-04-04 09:52:17 +10:00
|
|
|
void container_create_notify(struct sway_container *container);
|
|
|
|
|
2018-04-06 08:31:19 +10:00
|
|
|
void container_damage_whole(struct sway_container *container);
|
|
|
|
|
2018-04-03 03:49:37 +10:00
|
|
|
bool container_reap_empty(struct sway_container *con);
|
|
|
|
|
|
|
|
struct sway_container *container_reap_empty_recursive(
|
|
|
|
struct sway_container *con);
|
|
|
|
|
|
|
|
struct sway_container *container_flatten(struct sway_container *container);
|
|
|
|
|
2018-05-02 23:07:52 +10:00
|
|
|
void container_update_title_textures(struct sway_container *container);
|
|
|
|
|
2018-05-03 15:02:16 +10:00
|
|
|
/**
|
|
|
|
* Calculate the container's title_height property.
|
|
|
|
*/
|
|
|
|
void container_calculate_title_height(struct sway_container *container);
|
|
|
|
|
2018-05-25 21:07:59 +10:00
|
|
|
/**
|
|
|
|
* Notify a container that a tree modification has changed in its children,
|
|
|
|
* so the container can update its tree representation.
|
|
|
|
*/
|
|
|
|
void container_notify_subtree_changed(struct sway_container *container);
|
2018-05-03 15:02:16 +10:00
|
|
|
|
2018-05-22 08:27:42 +10:00
|
|
|
/**
|
|
|
|
* Return the height of a regular title bar.
|
|
|
|
*/
|
2018-05-22 09:44:34 +10:00
|
|
|
size_t container_titlebar_height(void);
|
2018-05-22 08:27:42 +10:00
|
|
|
|
2018-05-24 22:30:44 +10:00
|
|
|
void container_set_floating(struct sway_container *container, bool enable);
|
|
|
|
|
2018-05-26 16:32:24 +10:00
|
|
|
void container_set_geometry_from_floating_view(struct sway_container *con);
|
2018-05-24 22:30:44 +10:00
|
|
|
|
|
|
|
/**
|
2018-05-25 09:26:23 +10:00
|
|
|
* Determine if the given container is itself floating.
|
|
|
|
* This will return false for any descendants of a floating container.
|
|
|
|
*/
|
|
|
|
bool container_is_floating(struct sway_container *container);
|
|
|
|
|
2018-06-03 16:35:06 +10:00
|
|
|
/**
|
|
|
|
* Get a container's box in layout coordinates.
|
|
|
|
*/
|
2018-06-27 17:47:41 +10:00
|
|
|
void container_get_box(struct sway_container *container, struct wlr_box *box);
|
2018-06-03 16:35:06 +10:00
|
|
|
|
2018-07-18 16:13:28 +10:00
|
|
|
/**
|
|
|
|
* Move a floating container by the specified amount.
|
|
|
|
*/
|
|
|
|
void container_floating_translate(struct sway_container *con,
|
|
|
|
double x_amount, double y_amount);
|
|
|
|
|
2018-07-07 18:36:20 +10:00
|
|
|
/**
|
|
|
|
* Move a floating container to a new layout-local position.
|
|
|
|
*/
|
|
|
|
void container_floating_move_to(struct sway_container *con,
|
|
|
|
double lx, double ly);
|
|
|
|
|
2018-07-14 23:14:55 +10:00
|
|
|
/**
|
|
|
|
* Mark a container as dirty if it isn't already. Dirty containers will be
|
|
|
|
* included in the next transaction then unmarked as dirty.
|
|
|
|
*/
|
|
|
|
void container_set_dirty(struct sway_container *container);
|
|
|
|
|
2018-07-16 14:30:31 +10:00
|
|
|
bool container_has_urgent_child(struct sway_container *container);
|
|
|
|
|
2018-07-18 16:13:28 +10:00
|
|
|
/**
|
|
|
|
* If the container is involved in a drag or resize operation via a mouse, this
|
|
|
|
* ends the operation.
|
|
|
|
*/
|
|
|
|
void container_end_mouse_operation(struct sway_container *container);
|
|
|
|
|
2018-07-25 20:56:23 +10:00
|
|
|
void container_set_fullscreen(struct sway_container *container, bool enable);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if the container is fullscreen, or a child of a fullscreen split
|
|
|
|
* container.
|
|
|
|
*/
|
|
|
|
bool container_is_fullscreen_or_child(struct sway_container *container);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrap the children of parent in a new container. The new container will be the
|
|
|
|
* only child of parent.
|
|
|
|
*
|
|
|
|
* The new container is returned.
|
|
|
|
*/
|
|
|
|
struct sway_container *container_wrap_children(struct sway_container *parent);
|
|
|
|
|
2018-03-30 14:41:33 +11:00
|
|
|
#endif
|