<commit_before>#include <stdlib.h>
#include <wlc/wlc.h>
#include <wlc/wlc-wayland.h>
#include <wlc/wlc-render.h>
#include "wayland-desktop-shell-server-protocol.h"
#include "wayland-swaylock-server-protocol.h"
#include "sway/layout.h"
#include "sway/input_state.h"
#include "sway/extensions.h"
#include "sway/security.h"
#include "sway/ipc-server.h"
#include "log.h"

struct desktop_shell_state desktop_shell;

static struct panel_config *find_or_create_panel_config(struct wl_resource *resource) {
	for (int i = 0; i < desktop_shell.panels->length; i++) {
		struct panel_config *conf = desktop_shell.panels->items[i];
		if (conf->wl_resource == resource) {
			sway_log(L_DEBUG, "Found existing panel config for resource %p", resource);
			return conf;
		}
	}
	sway_log(L_DEBUG, "Creating panel config for resource %p", resource);
	struct panel_config *config = calloc(1, sizeof(struct panel_config));
	if (!config) {
		sway_log(L_ERROR, "Unable to create panel config");
		return NULL;
	}
	list_add(desktop_shell.panels, config);
	config->wl_resource = resource;
	return config;
}

void background_surface_destructor(struct wl_resource *resource) {
	sway_log(L_DEBUG, "Background surface killed");
	int i;
	for (i = 0; i < desktop_shell.backgrounds->length; ++i) {
		struct background_config *config = desktop_shell.backgrounds->items[i];
		if (config->wl_surface_res == resource) {
			list_del(desktop_shell.backgrounds, i);
			break;
		}
	}
}

void panel_surface_destructor(struct wl_resource *resource) {
	sway_log(L_DEBUG, "Panel surface killed");
	int i;
	for (i = 0; i < desktop_shell.panels->length; ++i) {
		struct panel_config *config = desktop_shell.panels->items[i];
		if (config->wl_surface_res == resource) {
			list_del(desktop_shell.panels, i);
			arrange_windows(&root_container, -1, -1);
			break;
		}
	}
}

void lock_surface_destructor(struct wl_resource *resource) {
	sway_log(L_DEBUG, "Lock surface killed");
	int i;
	for (i = 0; i < desktop_shell.lock_surfaces->length; ++i) {
		struct wl_resource *surface = desktop_shell.lock_surfaces->items[i];
		if (surface == resource) {
			list_del(desktop_shell.lock_surfaces, i);
			arrange_windows(&root_container, -1, -1);
			desktop_shell.is_locked = false;
			break;
		}
	}
}

static void set_background(struct wl_client *client, struct wl_resource *resource,
		struct wl_resource *_output, struct wl_resource *surface) {
	pid_t pid;
	wl_client_get_credentials(client, &pid, NULL, NULL);
	if (!(get_feature_policy(pid) & FEATURE_BACKGROUND)) {
		sway_log(L_INFO, "Denying background feature to %d", pid);
		return;
	}
	wlc_handle output = wlc_handle_from_wl_output_resource(_output);
	if (!output) {
		return;
	}
	sway_log(L_DEBUG, "Setting surface %p as background for output %d", surface, (int)output);
	struct background_config *config = malloc(sizeof(struct background_config));
	if (!config) {
		sway_log(L_ERROR, "Unable to allocate background config");
		return;
	}
	config->client = client;
	config->output = output;
	config->surface = wlc_resource_from_wl_surface_resource(surface);<commit_msg>sway: extensions: only unlock if lock_surfaces.length == 0<commit_after>#include <stdlib.h>
#include <wlc/wlc.h>
#include <wlc/wlc-wayland.h>
#include <wlc/wlc-render.h>
#include "wayland-desktop-shell-server-protocol.h"
#include "wayland-swaylock-server-protocol.h"
#include "sway/layout.h"
#include "sway/input_state.h"
#include "sway/extensions.h"
#include "sway/security.h"
#include "sway/ipc-server.h"
#include "log.h"

struct desktop_shell_state desktop_shell;

static struct panel_config *find_or_create_panel_config(struct wl_resource *resource) {
	for (int i = 0; i < desktop_shell.panels->length; i++) {
		struct panel_config *conf = desktop_shell.panels->items[i];
		if (conf->wl_resource == resource) {
			sway_log(L_DEBUG, "Found existing panel config for resource %p", resource);
			return conf;
		}
	}
	sway_log(L_DEBUG, "Creating panel config for resource %p", resource);
	struct panel_config *config = calloc(1, sizeof(struct panel_config));
	if (!config) {
		sway_log(L_ERROR, "Unable to create panel config");
		return NULL;
	}
	list_add(desktop_shell.panels, config);
	config->wl_resource = resource;
	return config;
}

void background_surface_destructor(struct wl_resource *resource) {
	sway_log(L_DEBUG, "Background surface killed");
	int i;
	for (i = 0; i < desktop_shell.backgrounds->length; ++i) {
		struct background_config *config = desktop_shell.backgrounds->items[i];
		if (config->wl_surface_res == resource) {
			list_del(desktop_shell.backgrounds, i);
			break;
		}
	}
}

void panel_surface_destructor(struct wl_resource *resource) {
	sway_log(L_DEBUG, "Panel surface killed");
	int i;
	for (i = 0; i < desktop_shell.panels->length; ++i) {
		struct panel_config *config = desktop_shell.panels->items[i];
		if (config->wl_surface_res == resource) {
			list_del(desktop_shell.panels, i);
			arrange_windows(&root_container, -1, -1);
			break;
		}
	}
}

void lock_surface_destructor(struct wl_resource *resource) {
	sway_log(L_DEBUG, "Lock surface killed");
	int i;
	for (i = 0; i < desktop_shell.lock_surfaces->length; ++i) {
		struct wl_resource *surface = desktop_shell.lock_surfaces->items[i];
		if (surface == resource) {
			list_del(desktop_shell.lock_surfaces, i);
			arrange_windows(&root_container, -1, -1);
			break;
		}
	}
	if (desktop_shell.lock_surfaces->length == 0) {
		desktop_shell.is_locked = false;
	}
}

static void set_background(struct wl_client *client, struct wl_resource *resource,
		struct wl_resource *_output, struct wl_resource *surface) {
	pid_t pid;
	wl_client_get_credentials(client, &pid, NULL, NULL);
	if (!(get_feature_policy(pid) & FEATURE_BACKGROUND)) {
		sway_log(L_INFO, "Denying background feature to %d", pid);
		return;
	}
	wlc_handle output = wlc_handle_from_wl_output_resource(_output);
	if (!output) {
		return;
	}
	sway_log(L_DEBUG, "Setting surface %p as background for output %d", surface, (int)output);
	struct background_config *config = malloc(sizeof(struct background_config));
	if (!config) {
		sway_log(L_ERROR, "Unable to allocate background config");
		return;
	}
	config->client = client;
	config->output = output;
	config->surface = wlc_resource_from_wl_surface_resource(surface);
{'fraction_non_alphanumeric': 0.131131773004168, 'fraction_numerical': 0.0032061558191728116, 'mean_word_length': 5.445247933884297, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 42, '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': '3991103', 'n_tokens_mistral': 2339, 'n_tokens_neox': 2216, 'n_words': 492}