<commit_before>#include <stdlib.h>
#include <swc.h>

#include "screen.h"
#include "util.h"
#include "window.h"
#include "wm.h"

void
new_window(struct swc_window *swc)
{
	debug("Adding new window");
	struct window *window = malloc(sizeof(struct window));
	if (!window)
		die("Failed to allocate window");

	window->swc = swc;
	window->screen = NULL;

	swc_window_set_handler(swc, &window_handler, window);
	swc_window_set_stacked(window->swc); /* TODO other modes? */
	screen_add_window(wm.active_screen, window);
	focus_window(window);
}

void
focus_window(struct window *window)
{
	debug("Switching window focus");
	if (window)
		swc_window_focus(window->swc);
		/*
		* TODO
		* - set borders ?
		*/
	else
		swc_window_focus(NULL);

	wm.active_window = window;
}

void
fullscreen_winodw(struct window *window)
{
	debug("Fullscreening window");
	focus_window(window);
	swc_window_set_fullscreen(window->swc, window->screen->swc);
}

void
show_window(struct window *window)
{
	debug("Showing window");
	swc_window_show(window->swc);
}

void
hide_window(struct window *window)
{
	debug("Hiding window");
	swc_window_hide(window->swc);
}

void
set_window_position(struct window *window, int32_t x, int32_t y)
{
	debug("Setting window position");
	swc_window_set_position(window->swc, x, y);
}

void
set_window_size(struct window *window, uint32_t width, uint32_t height)
{
	debug("Setting window size");
	swc_window_set_size(window->swc, width, height);
}

void
set_window_geometry(struct window *window, struct swc_rectangle *geometry)
{
	debug("Setting window geometry");
	swc_window_set_geometry(window->swc, geometry);
}

void
set_window_border(struct window *window, uint32_t color, int width)
{
	debug("Setting window border");
	swc_window_set_border(window->swc, color, width);
}

void
window_entered(void *data)
{
	debug("Window entered");
	struct window *window = data;

	focus_window(window);
}

void
window_destroy(void *data)
{
	debug("Window destroyed");
	struct window *window = data;

	/*
	 * TODO
	 * - change focus ?
	 */

	screen_remove_window(window->screen, window);
	free(window);
}
<commit_msg>set the window border on focus<commit_after>#include <stdlib.h>
#include <swc.h>

#include "screen.h"
#include "util.h"
#include "window.h"
#include "wm.h"

void
new_window(struct swc_window *swc)
{
	debug("Adding new window");
	struct window *window = malloc(sizeof(struct window));
	if (!window)
		die("Failed to allocate window");

	window->swc = swc;
	window->screen = NULL;

	swc_window_set_handler(swc, &window_handler, window);
	swc_window_set_stacked(window->swc); /* TODO other modes? */
	screen_add_window(wm.active_screen, window);
	focus_window(window);
}

void
focus_window(struct window *window)
{
	debug("Switching window focus");
	if (window) {
		swc_window_focus(window->swc);
		/* TODO get the border color (and size?) from the config */
		set_window_border(window, 0xffffffff, 1);
	} else {
		swc_window_focus(NULL);
	}

	wm.active_window = window;
}

void
fullscreen_winodw(struct window *window)
{
	debug("Fullscreening window");
	focus_window(window);
	swc_window_set_fullscreen(window->swc, window->screen->swc);
}

void
show_window(struct window *window)
{
	debug("Showing window");
	swc_window_show(window->swc);
}

void
hide_window(struct window *window)
{
	debug("Hiding window");
	swc_window_hide(window->swc);
}

void
set_window_position(struct window *window, int32_t x, int32_t y)
{
	debug("Setting window position");
	swc_window_set_position(window->swc, x, y);
}

void
set_window_size(struct window *window, uint32_t width, uint32_t height)
{
	debug("Setting window size");
	swc_window_set_size(window->swc, width, height);
}

void
set_window_geometry(struct window *window, struct swc_rectangle *geometry)
{
	debug("Setting window geometry");
	swc_window_set_geometry(window->swc, geometry);
}

void
set_window_border(struct window *window, uint32_t color, int width)
{
	debug("Setting window border");
	swc_window_set_border(window->swc, color, width);
}

void
window_entered(void *data)
{
	debug("Window entered");
	struct window *window = data;

	focus_window(window);
}

void
window_destroy(void *data)
{
	debug("Window destroyed");
	struct window *window = data;

	/* TODO change focus? */

	screen_remove_window(window->screen, window);
	free(window);
}

{'fraction_non_alphanumeric': 0.1353296193129062, 'fraction_numerical': 0.00510677808727948, 'mean_word_length': 5.961227786752827, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, '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': '3893476', 'n_tokens_mistral': 1593, 'n_tokens_neox': 1543, 'n_words': 341}