various: log memory events

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I6a6a69643b6d00277bb9bcfeb4cd01dc78d7cd3d
This commit is contained in:
raf 2025-09-30 20:11:06 +03:00
commit bc77b887ad
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
7 changed files with 280 additions and 47 deletions

View file

@ -14,6 +14,7 @@ static void registry_global(void *data, struct wl_registry *registry,
chroma_log("DEBUG", "Registry global: %s (id=%u, version=%u)", interface, id,
version);
chroma_log("TRACE", "Checking interface binding for: %s", interface);
if (strcmp(interface, wl_compositor_interface.name) == 0) {
state->compositor = wl_registry_bind(registry, id, &wl_compositor_interface,
@ -22,6 +23,7 @@ static void registry_global(void *data, struct wl_registry *registry,
chroma_log("ERROR", "Failed to bind compositor");
} else {
chroma_log("INFO", "Bound compositor (version %u)", version);
chroma_log("TRACE", "Compositor binding successful, interface ready");
}
} else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
state->layer_shell =
@ -31,6 +33,9 @@ static void registry_global(void *data, struct wl_registry *registry,
chroma_log("ERROR", "Failed to bind layer shell");
} else {
chroma_log("INFO", "Bound layer shell (version %u)", version);
chroma_log(
"TRACE",
"wlr-layer-shell protocol available, wallpaper support enabled");
}
} else if (strcmp(interface, wl_output_interface.name) == 0) {
struct wl_output *output = wl_registry_bind(
@ -52,9 +57,10 @@ static void registry_global(void *data, struct wl_registry *registry,
static void registry_global_remove(void *data, struct wl_registry *registry,
uint32_t id) {
chroma_state_t *state = (chroma_state_t *)data;
(void)registry; // Unused parameter
(void)registry;
chroma_log("DEBUG", "Registry global remove: id=%u", id);
chroma_log("TRACE", "Global object removal initiated for id=%u", id);
chroma_output_remove(state, id);
}
@ -63,24 +69,31 @@ const struct wl_registry_listener chroma_registry_listener_impl = {
.global_remove = registry_global_remove,
};
/* Layer surface event handlers */
// Layer surface event handlers
static void layer_surface_configure(void *data,
struct zwlr_layer_surface_v1 *layer_surface,
uint32_t serial, uint32_t width,
uint32_t height) {
chroma_output_t *output = (chroma_output_t *)data;
(void)layer_surface; // Unused parameter
(void)layer_surface;
chroma_log("DEBUG", "Layer surface configure: %ux%u, serial=%u", width,
height, serial);
chroma_log(
"TRACE",
"Configuring layer surface for output %u: dimensions=%ux%u, serial=%u",
output->id, width, height, serial);
output->configure_serial = serial;
/* Acknowledge the configure event */
// Acknowledge the configure event
zwlr_layer_surface_v1_ack_configure(output->layer_surface, serial);
chroma_log("TRACE", "Sent configure acknowledgment for output %u serial %u",
output->id, serial);
/* Commit the surface to apply the acknowledgment */
// Commit the surface to apply the acknowledgment
wl_surface_commit(output->surface);
chroma_log("TRACE", "Surface committed for output %u", output->id);
chroma_log("DEBUG", "Acknowledged layer surface configure for output %u",
output->id);
@ -89,11 +102,11 @@ static void layer_surface_configure(void *data,
static void layer_surface_closed(void *data,
struct zwlr_layer_surface_v1 *layer_surface) {
chroma_output_t *output = (chroma_output_t *)data;
(void)layer_surface; /* Unused parameter */
(void)layer_surface;
chroma_log("INFO", "Layer surface closed for output %u", output->id);
/* Clean up the surface */
// Clean up the surface
if (output->surface) {
chroma_surface_destroy(output);
}
@ -105,17 +118,17 @@ const struct zwlr_layer_surface_v1_listener chroma_layer_surface_listener_impl =
.closed = layer_surface_closed,
};
/* Output event handlers */
// Output event handlers
static void output_geometry(void *data, struct wl_output *output, int32_t x,
int32_t y, int32_t physical_width,
int32_t physical_height, int32_t subpixel,
const char *make, const char *model,
int32_t transform) {
chroma_output_t *chroma_output = (chroma_output_t *)data;
(void)output; // Unused parameter
(void)subpixel; // Unused parameter
(void)make; // Unused parameter
(void)model; // Unused parameter
(void)output;
(void)subpixel;
(void)make;
(void)model;
chroma_output->x = x;
chroma_output->y = y;
@ -124,24 +137,36 @@ static void output_geometry(void *data, struct wl_output *output, int32_t x,
chroma_log("DEBUG", "Output %u geometry: %dx%d at (%d,%d), transform=%d",
chroma_output->id, physical_width, physical_height, x, y,
transform);
chroma_log("TRACE",
"Output %u geometry details: physical_size=%dx%dmm, "
"position=(%d,%d), transform=%d",
chroma_output->id, physical_width, physical_height, x, y,
transform);
}
static void output_mode(void *data, struct wl_output *output, uint32_t flags,
int32_t width, int32_t height, int32_t refresh) {
chroma_output_t *chroma_output = (chroma_output_t *)data;
(void)output; // Unused parameter
(void)output;
if (flags & WL_OUTPUT_MODE_CURRENT) {
chroma_output->width = width;
chroma_output->height = height;
chroma_log("DEBUG", "Output %u mode: %dx%d@%d (current)", chroma_output->id,
width, height, refresh);
chroma_log("TRACE",
"Current mode set for output %u: %dx%d@%dHz, flags=0x%x",
chroma_output->id, width, height, refresh, flags);
} else {
chroma_log("TRACE",
"Non-current mode for output %u: %dx%d@%dHz, flags=0x%x",
chroma_output->id, width, height, refresh, flags);
}
}
static void output_scale(void *data, struct wl_output *output, int32_t scale) {
chroma_output_t *chroma_output = (chroma_output_t *)data;
(void)output; // Unused parameter
(void)output;
chroma_output->scale = scale;
chroma_log("DEBUG", "Output %u scale: %d", chroma_output->id, scale);
@ -150,7 +175,7 @@ static void output_scale(void *data, struct wl_output *output, int32_t scale) {
static void output_name(void *data, struct wl_output *output,
const char *name) {
chroma_output_t *chroma_output = (chroma_output_t *)data;
(void)output; // Unused parameter
(void)output;
free(chroma_output->name);
chroma_output->name = strdup(name);
@ -165,7 +190,7 @@ static void output_name(void *data, struct wl_output *output,
static void output_description(void *data, struct wl_output *output,
const char *description) {
chroma_output_t *chroma_output = (chroma_output_t *)data;
(void)output; // Unused parameter
(void)output;
free(chroma_output->description);
chroma_output->description = strdup(description);
@ -180,16 +205,23 @@ static void output_description(void *data, struct wl_output *output,
static void output_done(void *data, struct wl_output *output) {
chroma_output_t *chroma_output = (chroma_output_t *)data;
(void)output; /* Unused parameter */
(void)output;
chroma_log("DEBUG", "Output %u done - configuration complete",
chroma_output->id);
chroma_log("TRACE",
"Output %u configuration finalized: %dx%d, scale=%d, name='%s'",
chroma_output->id, chroma_output->width, chroma_output->height,
chroma_output->scale,
chroma_output->name ? chroma_output->name : "unknown");
// Mark output as active and ready for wallpaper assignment
chroma_output->active = true;
// Trigger wallpaper assignment for this output
if (chroma_output->state) {
chroma_log("TRACE", "Triggering wallpaper assignment for output %u",
chroma_output->id);
handle_output_done(chroma_output->state, chroma_output);
}
}
@ -203,7 +235,7 @@ const struct wl_output_listener chroma_output_listener_impl = {
.done = output_done,
};
/* Wayland connection functions */
// Wayland connection functions
int chroma_wayland_connect(chroma_state_t *state) {
if (!state) {
return CHROMA_ERROR_INIT;
@ -230,11 +262,13 @@ int chroma_wayland_connect(chroma_state_t *state) {
state);
// Roundtrip to get all globals
chroma_log("TRACE", "Starting Wayland display roundtrip to discover globals");
if (wl_display_roundtrip(state->display) == -1) {
chroma_log("ERROR", "Failed to roundtrip Wayland display");
chroma_wayland_disconnect(state);
return CHROMA_ERROR_WAYLAND;
}
chroma_log("TRACE", "Wayland display roundtrip completed");
// Check if we got a compositor
if (!state->compositor) {
@ -301,7 +335,7 @@ void chroma_wayland_disconnect(chroma_state_t *state) {
chroma_log("INFO", "Disconnected from Wayland display");
}
/* Output management functions */
// Output management functions
int chroma_output_add(chroma_state_t *state, uint32_t id,
struct wl_output *output) {
if (!state || !output) {
@ -318,16 +352,19 @@ int chroma_output_add(chroma_state_t *state, uint32_t id,
chroma_output->wl_output = output;
chroma_output->id = id;
chroma_output->scale = 1; // Default scale
chroma_output->scale = 1; // default scale
chroma_output->active = false;
chroma_output->state = state;
// Add output listener
wl_output_add_listener(output, &chroma_output_listener_impl, chroma_output);
chroma_log("TRACE", "Output listener attached for output %u", id);
state->output_count++;
chroma_log("INFO", "Added output %u (total: %d)", id, state->output_count);
chroma_log("TRACE",
"Output %u initialized with default scale=1, active=false", id);
return CHROMA_OK;
}
@ -345,25 +382,28 @@ void chroma_output_remove(chroma_state_t *state, uint32_t id) {
chroma_log("INFO", "Removing output %u (%s)", id,
output->name ? output->name : "unknown");
/* Clean up surface if it exists */
// Clean up surface if it exists
if (output->surface) {
chroma_surface_destroy(output);
}
/* Clean up Wayland output */
// Clean up Wayland output
if (output->wl_output) {
wl_output_destroy(output->wl_output);
}
/* Free allocated strings */
// Free allocated strings
free(output->name);
free(output->description);
/* Remove from array by shifting remaining elements */
// Remove from array by shifting remaining elements
int index = output - state->outputs;
int remaining = state->output_count - index - 1;
chroma_log("TRACE", "Removing output %u from array: index=%d, remaining=%d",
id, index, remaining);
if (remaining > 0) {
memmove(output, output + 1, remaining * sizeof(chroma_output_t));
chroma_log("TRACE", "Shifted %d outputs in array after removal", remaining);
}
state->output_count--;