swm.h 3.5 KiB raw
1
#ifndef SWM_H
2
#define SWM_H
3
4
#include <stdbool.h>
5
#include <stddef.h>
6
7
#define SWM_SLICE 32
8
9
/* Integer rectangle in compositor layout coordinates. */
10
struct swm_box {
11
    int x, y, width, height;
12
};
13
14
/* Parameters controlling a master-stack layout. */
15
struct swm_stack_state {
16
    int msize;
17
    int mwin;
18
    int stacks;
19
};
20
21
/* Workspace state flags exported through ext-workspace. */
22
enum swm_workspace_state {
23
    SWM_WORKSPACE_ACTIVE = 1u << 0,
24
    SWM_WORKSPACE_URGENT = 1u << 1,
25
    SWM_WORKSPACE_HIDDEN = 1u << 2,
26
};
27
28
/* Commands which update master-stack parameters. */
29
enum swm_stack_command {
30
    SWM_MASTER_SHRINK,
31
    SWM_MASTER_GROW,
32
    SWM_MASTER_ADD,
33
    SWM_MASTER_DEL,
34
    SWM_STACK_INC,
35
    SWM_STACK_DEC,
36
    SWM_STACK_RESET,
37
    SWM_FLIP_LAYOUT,
38
};
39
40
/* Side of the output occupied by the master area. */
41
enum swm_layout_side {
42
    SWM_MASTER_LEFT,
43
    SWM_MASTER_TOP,
44
    SWM_MASTER_RIGHT,
45
    SWM_MASTER_BOTTOM,
46
};
47
48
/* Clamp a box to the minimum client size and output bounds. */
49
void swm_box_apply_bounds(struct swm_box *box, const struct swm_box *bounds, unsigned int border);
50
/* Resize a box from the selected edges. */
51
struct swm_box swm_box_resize(
52
    const struct swm_box *box, int dx, int dy, unsigned int edges, unsigned int border
53
);
54
/* Arrange clients into master and stack areas. */
55
size_t swm_stack_layout(
56
    const struct swm_box         *area,
57
    const struct swm_stack_state *state,
58
    int                           rotate,
59
    int                           flip,
60
    size_t                        count,
61
    struct swm_box               *boxes
62
);
63
/* Reconcile pending geometry with a committed client size. */
64
void swm_box_reconcile_commit(
65
    struct swm_box *box, int width, int height, unsigned int border, unsigned int edges
66
);
67
/* Position an input popup inside an output. */
68
struct swm_box swm_popup_position(
69
    const struct swm_box *client,
70
    unsigned int          border,
71
    const struct swm_box *cursor_rect,
72
    int                   width,
73
    int                   height,
74
    const struct swm_box *output
75
);
76
/* Compute the exported state flags for a workspace. */
77
unsigned int swm_workspace_state(bool active, bool occupied, bool urgent);
78
/* Find the next eligible workspace in the requested direction. */
79
int swm_workspace_next(
80
    int         current,
81
    int         count,
82
    int         direction,
83
    int         allow_empty,
84
    const bool *visible_elsewhere,
85
    const bool *occupied
86
);
87
/* Apply a command to master-stack parameters. */
88
bool swm_stack_configure(struct swm_stack_state *state, int command, int side, int *new_side);
89
/* Return whether a rule matches the client identity. */
90
bool swm_rule_matches(
91
    const char *rule_id, const char *rule_title, const char *appid, const char *title
92
);
93
/* Copy a field while replacing state-file delimiters. */
94
void swm_sanitize_field(char *dst, size_t size, const char *src, const char *fallback);
95
/* Parse one persisted window-state record. */
96
bool swm_parse_window_state(
97
    const char     *line,
98
    char           *appid,
99
    size_t          appid_size,
100
    char           *title,
101
    size_t          title_size,
102
    struct swm_box *geometry
103
);
104
/* Compute the effective border width for a client. */
105
unsigned int swm_border_width(
106
    unsigned int configured,
107
    bool         fullscreen,
108
    bool         borderless,
109
    bool         x11,
110
    bool         unmanaged,
111
    bool         client_side
112
);
113
/* Find the next enabled layout in the cycle. */
114
int swm_next_layout(int current, int count, const bool *cycle);
115
116
#endif