brewery
notashelf /
e72da82b32d46daf27c4ff663e5f918058b65fd7

chroma

public

Lightweight wallpaper daemon for Wayland

Star0tarball
clone
ssh://git@git.notashelf.dev:33/notashelf/chroma.git
include/chroma.hC231 lines7.6 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
66
  // OpenGL resource cache
67
  GLuint texture_id;
68
  GLuint shader_program;
69
  GLuint vbo;
70
  GLuint ebo;
71
  bool gl_resources_initialized;
72
  bool texture_uploaded;
73
} chroma_output_t;
74
75
// Config mapping structure
76
typedef struct {
77
  char output_name[256];
78
  char image_path[MAX_PATH_LEN];
79
} chroma_config_mapping_t;
80
81
// Application configuration
82
typedef struct {
83
  chroma_config_mapping_t mappings[MAX_OUTPUTS];
84
  int mapping_count;
85
  char default_image[MAX_PATH_LEN];
86
  bool daemon_mode;
87
} chroma_config_t;
88
89
// Main application state
90
typedef struct chroma_state {
91
  // Wayland globals
92
  struct wl_display *display;
93
  struct wl_registry *registry;
94
  struct wl_compositor *compositor;
95
  struct zwlr_layer_shell_v1 *layer_shell;
96
97
  // EGL context
98
  EGLDisplay egl_display;
99
  EGLContext egl_context;
100
  EGLConfig egl_config;
101
102
  // Outputs
103
  chroma_output_t outputs[MAX_OUTPUTS];
104
  int output_count;
105
106
  // Images
107
  chroma_image_t images[MAX_OUTPUTS];
108
  int image_count;
109
110
  // Configuration
111
  chroma_config_t config;
112
113
  // State flags
114
  bool running;
115
  bool initialized;
116
} chroma_state_t;
117
118
// Function declarations
119
120
// Initialization and cleanup
121
int chroma_init(chroma_state_t *state);
122
void chroma_cleanup(chroma_state_t *state);
123
124
// Wayland management
125
int chroma_wayland_connect(chroma_state_t *state);
126
void chroma_wayland_disconnect(chroma_state_t *state);
127
void chroma_registry_listener(void *data, struct wl_registry *registry,
128
                              uint32_t id, const char *interface,
129
                              uint32_t version);
130
void chroma_registry_remove(void *data, struct wl_registry *registry,
131
                            uint32_t id);
132
133
// Output management
134
int chroma_output_add(chroma_state_t *state, uint32_t id,
135
                      struct wl_output *output);
136
void chroma_output_remove(chroma_state_t *state, uint32_t id);
137
chroma_output_t *chroma_output_find_by_id(chroma_state_t *state, uint32_t id);
138
chroma_output_t *chroma_output_find_by_name(chroma_state_t *state,
139
                                            const char *name);
140
141
// Output event handlers
142
void chroma_output_geometry(void *data, struct wl_output *output, int32_t x,
143
                            int32_t y, int32_t physical_width,
144
                            int32_t physical_height, int32_t subpixel,
145
                            const char *make, const char *model,
146
                            int32_t transform);
147
void chroma_output_mode(void *data, struct wl_output *output, uint32_t flags,
148
                        int32_t width, int32_t height, int32_t refresh);
149
void chroma_output_scale(void *data, struct wl_output *output, int32_t scale);
150
void chroma_output_name(void *data, struct wl_output *output, const char *name);
151
void chroma_output_description(void *data, struct wl_output *output,
152
                               const char *description);
153
void chroma_output_done(void *data, struct wl_output *output);
154
155
// EGL and rendering
156
int chroma_egl_init(chroma_state_t *state);
157
void chroma_egl_cleanup(chroma_state_t *state);
158
int chroma_surface_create(chroma_state_t *state, chroma_output_t *output);
159
void chroma_surface_destroy(chroma_output_t *output);
160
int chroma_render_wallpaper(chroma_state_t *state, chroma_output_t *output);
161
void chroma_output_invalidate_texture(chroma_output_t *output);
162
163
// Layer shell functions
164
void chroma_layer_surface_configure(void *data,
165
                                    struct zwlr_layer_surface_v1 *layer_surface,
166
                                    uint32_t serial, uint32_t width,
167
                                    uint32_t height);
168
void chroma_layer_surface_closed(void *data,
169
                                 struct zwlr_layer_surface_v1 *layer_surface);
170
171
// Image loading
172
void chroma_image_init_stb(void);
173
int chroma_image_load(chroma_image_t *image, const char *path);
174
void chroma_image_free(chroma_image_t *image);
175
chroma_image_t *chroma_image_find_by_path(chroma_state_t *state,
176
                                          const char *path);
177
chroma_image_t *chroma_image_get_or_load(chroma_state_t *state,
178
                                         const char *path);
179
int chroma_image_validate(const char *path);
180
int chroma_image_get_info(const char *path, int *width, int *height,
181
                          int *channels);
182
void chroma_images_cleanup(chroma_state_t *state);
183
184
// Configuration
185
int chroma_config_load(chroma_config_t *config, const char *config_file);
186
void chroma_config_free(chroma_config_t *config);
187
const char *chroma_config_get_image_for_output(chroma_config_t *config,
188
                                               const char *output_name);
189
190
// Main loop and events
191
int chroma_run(chroma_state_t *state);
192
void chroma_handle_signals(void);
193
int chroma_reload_config(chroma_state_t *state, const char *config_file);
194
int chroma_update_outputs(chroma_state_t *state);
195
void chroma_get_stats(chroma_state_t *state, int *active_outputs,
196
                      int *loaded_images);
197
void handle_output_done(chroma_state_t *state, chroma_output_t *output);
198
199
// Utilities
200
void chroma_log(const char *level, const char *format, ...);
201
const char *chroma_error_string(chroma_error_t error);
202
void chroma_set_log_level(int level);
203
int chroma_get_log_level(void);
204
void chroma_set_signal_state(chroma_state_t *state, const char *config_file);
205
void chroma_cleanup_signals(void);
206
char *chroma_expand_path(const char *path);
207
int chroma_mkdir_recursive(const char *path, mode_t mode);
208
char *chroma_get_config_dir(void);
209
bool chroma_path_exists(const char *path);
210
bool chroma_is_regular_file(const char *path);
211
bool chroma_is_directory(const char *path);
212
long chroma_get_file_size(const char *path);
213
const char *chroma_get_file_extension(const char *path);
214
int chroma_strcasecmp(const char *s1, const char *s2);
215
size_t chroma_strlcpy(char *dst, const char *src, size_t size);
216
size_t chroma_strlcat(char *dst, const char *src, size_t size);
217
long long chroma_get_time_ms(void);
218
void chroma_sleep_ms(long ms);
219
void chroma_format_memory_size(size_t bytes, char *buffer, size_t buffer_size);
220
void chroma_utils_cleanup(void);
221
222
// Listener structures
223
extern const struct wl_registry_listener chroma_registry_listener_impl;
224
extern const struct wl_output_listener chroma_output_listener_impl;
225
extern const struct zwlr_layer_surface_v1_listener
226
    chroma_layer_surface_listener_impl;
227
228
// Global state for signal handling
229
extern volatile sig_atomic_t chroma_should_quit;
230
231
#endif // CHROMA_H