<commit_before>#include "layer_shell.h"

#include <stdlib.h>

#include <wayland-server.h>
#include <wlr/types/wlr_box.h>
#include <wlr/types/wlr_layer_shell_v1.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_damage.h>
#include <wlr/util/log.h>

#include "output.h"
#include "seat.h"
#include "server.h"
#include "view.h"

static const uint32_t LAYER_BOTH_HORIZ =
		ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
static const uint32_t LAYER_BOTH_VERT =
		ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;

static void wc_layer_shell_commit(struct wl_listener *listener, void *data) {
	struct wc_layer *layer = wl_container_of(listener, layer, commit);
	struct wlr_layer_surface_v1 *layer_surface = layer->layer_surface;
	struct wlr_output *wlr_output = layer_surface->output;
	if (wlr_output == NULL) {
		return;
	}
	struct wlr_box old_geo = layer->geo;
	wc_layer_shell_arrange_layers(wlr_output->data);

	if (memcmp(&old_geo, &layer->geo, sizeof(struct wlr_box)) != 0) {
		wc_output_damage_surface(
				wlr_output->data, layer_surface->surface, NULL, old_geo);
	}

	pixman_region32_t damage;
	pixman_region32_init(&damage);
	wlr_surface_get_effective_damage(layer_surface->surface, &damage);
	pixman_region32_translate(&damage, layer->geo.x, layer->geo.y);
	wc_output_damage_surface(
			wlr_output->data, layer_surface->surface, &damage, layer->geo);

	pixman_region32_fini(&damage);
}

static void wc_layer_shell_map(struct wl_listener *listener, void *data) {
	struct wc_layer *layer = wl_container_of(listener, layer, map);
	struct wlr_layer_surface_v1 *layer_surface = layer->layer_surface;
	layer->mapped = true;

	pixman_region32_t damage;
	pixman_region32_init(&damage);
	wlr_surface_get_effective_damage(layer_surface->surface, &damage);
	pixman_region32_translate(&damage, layer->geo.x, layer->geo.y);

	wc_output_damage_surface(layer_surface->output->data,
			layer_surface->surface, &damage, layer->geo);

	pixman_region32_fini(&damage);
}

static void wc_layer_shell_unmap(struct wl_listener *listener, void *data) {
	struct wc_layer *layer = wl_container_of(listener, layer, unmap);
	struct wlr_layer_surface_v1 *layer_surface = layer->layer_surface;
	layer->mapped = false;

	pixman_region32_t damage;
	pixman_region32_init(&damage);
	wlr_surface_get_effective_damage(layer_surface->surface, &damage);
	pixman_region32_translate(&damage, layer->geo.x, layer->geo.y);

	wc_output_damage_surface(layer_surface->output->data,
			layer_surface->surface, &damage, layer->geo);

	pixman_region32_fini(&damage);
}

void wc_layer_shell_destroy(struct wl_listener *listener, void *data) {
	struct wc_layer *layer = wl_container_of(listener, layer, destroy);
	wl_list_remove(&layer->link);
<commit_msg>Always damage the entire surface on unmap<commit_after>#include "layer_shell.h"

#include <stdlib.h>

#include <wayland-server.h>
#include <wlr/types/wlr_box.h>
#include <wlr/types/wlr_layer_shell_v1.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_damage.h>
#include <wlr/util/log.h>

#include "output.h"
#include "seat.h"
#include "server.h"
#include "view.h"

static const uint32_t LAYER_BOTH_HORIZ =
		ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
static const uint32_t LAYER_BOTH_VERT =
		ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;

static void wc_layer_shell_commit(struct wl_listener *listener, void *data) {
	struct wc_layer *layer = wl_container_of(listener, layer, commit);
	struct wlr_layer_surface_v1 *layer_surface = layer->layer_surface;
	struct wlr_output *wlr_output = layer_surface->output;
	if (wlr_output == NULL) {
		return;
	}
	struct wlr_box old_geo = layer->geo;
	wc_layer_shell_arrange_layers(wlr_output->data);

	if (memcmp(&old_geo, &layer->geo, sizeof(struct wlr_box)) != 0) {
		wc_output_damage_surface(
				wlr_output->data, layer_surface->surface, NULL, old_geo);
	}

	pixman_region32_t damage;
	pixman_region32_init(&damage);
	wlr_surface_get_effective_damage(layer_surface->surface, &damage);
	pixman_region32_translate(&damage, layer->geo.x, layer->geo.y);
	wc_output_damage_surface(
			wlr_output->data, layer_surface->surface, &damage, layer->geo);

	pixman_region32_fini(&damage);
}

static void wc_layer_shell_map(struct wl_listener *listener, void *data) {
	struct wc_layer *layer = wl_container_of(listener, layer, map);
	struct wlr_layer_surface_v1 *layer_surface = layer->layer_surface;
	layer->mapped = true;

	pixman_region32_t damage;
	pixman_region32_init(&damage);
	wlr_surface_get_effective_damage(layer_surface->surface, &damage);
	pixman_region32_translate(&damage, layer->geo.x, layer->geo.y);

	wc_output_damage_surface(layer_surface->output->data,
			layer_surface->surface, &damage, layer->geo);

	pixman_region32_fini(&damage);
}

static void wc_layer_shell_unmap(struct wl_listener *listener, void *data) {
	struct wc_layer *layer = wl_container_of(listener, layer, unmap);
	struct wlr_layer_surface_v1 *layer_surface = layer->layer_surface;
	layer->mapped = false;

	wc_output_damage_surface(layer_surface->output->data,
			layer_surface->surface, NULL, layer->geo);
}

void wc_layer_shell_destroy(struct wl_listener *listener, void *data) {
	struct wc_layer *layer = wl_container_of(listener, layer, destroy);
	wl_list_remove(&layer->link);

{'fraction_non_alphanumeric': 0.11655753040224509, 'fraction_numerical': 0.01234798877455566, 'mean_word_length': 7.275541795665634, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 78, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7426617', 'n_tokens_mistral': 2158, 'n_tokens_neox': 2080, 'n_words': 333}