brewery
notashelf /
48fa1cc8525bbb05a245b13dba7ec49afa48077a

chroma

public

Lightweight wallpaper daemon for Wayland

Star0tarball
clone
ssh://git@git.notashelf.dev:33/notashelf/chroma.git
include/chroma.hC222 lines7.4 KB
1
#ifndef CHROMA_H
2
#define CHROMA_H
3
4
#include "wlr-layer-shell-unstable-v1.h"
5
#include "xdg-shell.h"
6
#include <EGL/egl.h>
7
#include <GL/gl.h>
8
#include <signal.h>
9
#include <stdbool.h>
10
#include <stdint.h>
11
#include <sys/types.h>
12
#include <wayland-client.h>
13
#include <wayland-egl.h>
14
15
#define CHROMA_VERSION "1.0.0"
16
#define MAX_OUTPUTS 16
17
#define MAX_PATH_LEN 4096
18
#define CONFIG_FILE_NAME "chroma.conf"
19
20
// Error codes
21
typedef enum {
22
  CHROMA_OK = 0,
23
  CHROMA_ERROR_INIT = -1,
24
  CHROMA_ERROR_WAYLAND = -2,
25
  CHROMA_ERROR_EGL = -3,
26
  CHROMA_ERROR_IMAGE = -4,
27
  CHROMA_ERROR_CONFIG = -5,
28
  CHROMA_ERROR_MEMORY = -6
29
} chroma_error_t;
30
31
// Image data structure
32
typedef struct {
33
  unsigned char *data; // RGBA pixel data
34
  int width;
35
  int height;
36
  int channels;
37
  char path[MAX_PATH_LEN];
38
  bool loaded;
39
} chroma_image_t;
40
41
// Wayland output information
42
typedef struct {
43
  struct wl_output *wl_output;
44
  uint32_t id;
45
  int32_t x, y;
46
  int32_t width, height;
47
  int32_t scale;
48
  enum wl_output_transform transform;
49
  char *name;
50
  char *description;
51
  bool active;
52
53
  // Back reference to state
54
  struct chroma_state *state;
55
56
  // Rendering context
57
  struct wl_surface *surface;
58
  struct zwlr_layer_surface_v1 *layer_surface;
59
  struct wl_egl_window *egl_window;
60
  EGLSurface egl_surface;
61
  uint32_t configure_serial;
62
63
  // Associated wallpaper
64
  chroma_image_t *image;
65
} chroma_output_t;
66
67
// Config mapping structure
68
typedef struct {
69
  char output_name[256];
70
  char image_path[MAX_PATH_LEN];
71
} chroma_config_mapping_t;
72
73
// Application configuration
74
typedef struct {
75
  chroma_config_mapping_t mappings[MAX_OUTPUTS];
76
  int mapping_count;
77
  char default_image[MAX_PATH_LEN];
78
  bool daemon_mode;
79
} chroma_config_t;
80
81
// Main application state
82
typedef struct chroma_state {
83
  // Wayland globals
84
  struct wl_display *display;
85
  struct wl_registry *registry;
86
  struct wl_compositor *compositor;
87
  struct zwlr_layer_shell_v1 *layer_shell;
88
89
  // EGL context
90
  EGLDisplay egl_display;
91
  EGLContext egl_context;
92
  EGLConfig egl_config;
93
94
  // Outputs
95
  chroma_output_t outputs[MAX_OUTPUTS];
96
  int output_count;
97
98
  // Images
99
  chroma_image_t images[MAX_OUTPUTS];
100
  int image_count;
101
102
  // Configuration
103
  chroma_config_t config;
104
105
  // State flags
106
  bool running;
107
  bool initialized;
108
} chroma_state_t;
109
110
// Function declarations
111
112
// Initialization and cleanup
113
int chroma_init(chroma_state_t *state);
114
void chroma_cleanup(chroma_state_t *state);
115
116
// Wayland management
117
int chroma_wayland_connect(chroma_state_t *state);
118
void chroma_wayland_disconnect(chroma_state_t *state);
119
void chroma_registry_listener(void *data, struct wl_registry *registry,
120
                              uint32_t id, const char *interface,
121
                              uint32_t version);
122
void chroma_registry_remove(void *data, struct wl_registry *registry,
123
                            uint32_t id);
124
125
// Output management
126
int chroma_output_add(chroma_state_t *state, uint32_t id,
127
                      struct wl_output *output);
128
void chroma_output_remove(chroma_state_t *state, uint32_t id);
129
chroma_output_t *chroma_output_find_by_id(chroma_state_t *state, uint32_t id);
130
chroma_output_t *chroma_output_find_by_name(chroma_state_t *state,
131
                                            const char *name);
132
133
// Output event handlers
134
void chroma_output_geometry(void *data, struct wl_output *output, int32_t x,
135
                            int32_t y, int32_t physical_width,
136
                            int32_t physical_height, int32_t subpixel,
137
                            const char *make, const char *model,
138
                            int32_t transform);
139
void chroma_output_mode(void *data, struct wl_output *output, uint32_t flags,
140
                        int32_t width, int32_t height, int32_t refresh);
141
void chroma_output_scale(void *data, struct wl_output *output, int32_t scale);
142
void chroma_output_name(void *data, struct wl_output *output, const char *name);
143
void chroma_output_description(void *data, struct wl_output *output,
144
                               const char *description);
145
void chroma_output_done(void *data, struct wl_output *output);
146
147
// EGL and rendering
148
int chroma_egl_init(chroma_state_t *state);
149
void chroma_egl_cleanup(chroma_state_t *state);
150
int chroma_surface_create(chroma_state_t *state, chroma_output_t *output);
151
void chroma_surface_destroy(chroma_output_t *output);
152
int chroma_render_wallpaper(chroma_state_t *state, chroma_output_t *output);
153
154
// Layer shell functions
155
void chroma_layer_surface_configure(void *data,
156
                                    struct zwlr_layer_surface_v1 *layer_surface,
157
                                    uint32_t serial, uint32_t width,
158
                                    uint32_t height);
159
void chroma_layer_surface_closed(void *data,
160
                                 struct zwlr_layer_surface_v1 *layer_surface);
161
162
// Image loading
163
void chroma_image_init_stb(void);
164
int chroma_image_load(chroma_image_t *image, const char *path);
165
void chroma_image_free(chroma_image_t *image);
166
chroma_image_t *chroma_image_find_by_path(chroma_state_t *state,
167
                                          const char *path);
168
chroma_image_t *chroma_image_get_or_load(chroma_state_t *state,
169
                                         const char *path);
170
int chroma_image_validate(const char *path);
171
int chroma_image_get_info(const char *path, int *width, int *height,
172
                          int *channels);
173
void chroma_images_cleanup(chroma_state_t *state);
174
175
// Configuration
176
int chroma_config_load(chroma_config_t *config, const char *config_file);
177
void chroma_config_free(chroma_config_t *config);
178
const char *chroma_config_get_image_for_output(chroma_config_t *config,
179
                                               const char *output_name);
180
181
// Main loop and events
182
int chroma_run(chroma_state_t *state);
183
void chroma_handle_signals(void);
184
int chroma_reload_config(chroma_state_t *state, const char *config_file);
185
int chroma_update_outputs(chroma_state_t *state);
186
void chroma_get_stats(chroma_state_t *state, int *active_outputs,
187
                      int *loaded_images);
188
void handle_output_done(chroma_state_t *state, chroma_output_t *output);
189
190
// Utilities
191
void chroma_log(const char *level, const char *format, ...);
192
const char *chroma_error_string(chroma_error_t error);
193
void chroma_set_log_level(int level);
194
int chroma_get_log_level(void);
195
void chroma_set_signal_state(chroma_state_t *state, const char *config_file);
196
void chroma_cleanup_signals(void);
197
char *chroma_expand_path(const char *path);
198
int chroma_mkdir_recursive(const char *path, mode_t mode);
199
char *chroma_get_config_dir(void);
200
bool chroma_path_exists(const char *path);
201
bool chroma_is_regular_file(const char *path);
202
bool chroma_is_directory(const char *path);
203
long chroma_get_file_size(const char *path);
204
const char *chroma_get_file_extension(const char *path);
205
int chroma_strcasecmp(const char *s1, const char *s2);
206
size_t chroma_strlcpy(char *dst, const char *src, size_t size);
207
size_t chroma_strlcat(char *dst, const char *src, size_t size);
208
long long chroma_get_time_ms(void);
209
void chroma_sleep_ms(long ms);
210
void chroma_format_memory_size(size_t bytes, char *buffer, size_t buffer_size);
211
void chroma_utils_cleanup(void);
212
213
// Listener structures
214
extern const struct wl_registry_listener chroma_registry_listener_impl;
215
extern const struct wl_output_listener chroma_output_listener_impl;
216
extern const struct zwlr_layer_surface_v1_listener
217
    chroma_layer_surface_listener_impl;
218
219
// Global state for signal handling
220
extern volatile sig_atomic_t chroma_should_quit;
221
222
#endif // CHROMA_H