<commit_before>/* Copyright ©2006-2010 <NAME> <<EMAIL> at Gmail>
 * See LICENSE file for license details.
 */
#include "dat.h"
#include <limits.h>
#include "fns.h"

static void float_placeframe(Frame*);

void
float_attach(Area *a, Frame *f) {

	if(f->client->floating == Off)
		f->client->floating = On;

	f->r = f->floatr;
	float_placeframe(f);
	assert(a->sel != f);
	frame_insert(f, a->sel);

	if(a->sel == nil)
		area_setsel(a, f);
}

void
float_detach(Frame *f) {
	Frame *pr;
	Area *a, *sel, *oldsel;
	View *v;

	v = f->view;
	a = f->area;
	sel = view_findarea(v, v->selscreen, v->selcol, false);
	oldsel = v->oldsel;
	pr = f->aprev;

	frame_remove(f);

	if(a->sel == f) {
		while(pr && pr->client->nofocus)
			pr = pr->aprev;
		if(!pr)
			for(pr=a->frame; pr && pr->anext; pr=pr->anext)
				if(!pr->client->nofocus) break;
		a->sel = nil;
		area_setsel(a, pr);
	}
	f->area = nil;

	if(oldsel)
		area_focus(oldsel);
	else if(!a->frame || pr && pr->client->nofocus)
		if(sel && sel->frame)
			area_focus(sel);
}

void
float_resizeframe(Frame *f, Rectangle r) {

	if(f->area->view == selview)
		client_resize(f->client, r);
	else
		frame_resize(f, r);
}

void
float_arrange(Area *a) {
	Frame *f;

	assert(a->floating);

	switch(a->mode) {
	case Coldefault:
		break;
	case Colstack:
		for(f=a->frame; f; f=f->anext)
			f->collapsed = (f != a->sel);
		break;
	default:
		die("not reached");
		break;
	}
	for(f=a->frame; f; f=f->anext)
		f->r = f->floatr;
	view_update(a->view);
}

static void
rect_push(Vector_rect *vec, Rectangle r) {
	Rectangle *rp;
	int i;

	for(i=0; i < vec->n; i++) {
		rp = &vec->ary[i];
		if(rect_contains_p(*rp, r))
			return;
		if(rect_contains_p(r, *rp)) {
			*rp = r;
			return;
		}
	}
	vector_rpush(vec, r);
}

Vector_rect*
unique_rects(Vector_rect *vec, Rectangle orig) {<commit_msg>Don't collapse dock/menu/toolbar windows in float+stack mode.<commit_after>/* Copyright ©2006-2010 <NAME> <<EMAIL> at Gmail>
 * See LICENSE file for license details.
 */
#include "dat.h"
#include <limits.h>
#include "fns.h"

static void float_placeframe(Frame*);

void
float_attach(Area *a, Frame *f) {

	if(f->client->floating == Off)
		f->client->floating = On;

	f->r = f->floatr;
	float_placeframe(f);
	assert(a->sel != f);
	frame_insert(f, a->sel);

	if(a->sel == nil)
		area_setsel(a, f);
}

void
float_detach(Frame *f) {
	Frame *pr;
	Area *a, *sel, *oldsel;
	View *v;

	v = f->view;
	a = f->area;
	sel = view_findarea(v, v->selscreen, v->selcol, false);
	oldsel = v->oldsel;
	pr = f->aprev;

	frame_remove(f);

	if(a->sel == f) {
		while(pr && pr->client->nofocus)
			pr = pr->aprev;
		if(!pr)
			for(pr=a->frame; pr && pr->anext; pr=pr->anext)
				if(!pr->client->nofocus) break;
		a->sel = nil;
		area_setsel(a, pr);
	}
	f->area = nil;

	if(oldsel)
		area_focus(oldsel);
	else if(!a->frame || pr && pr->client->nofocus)
		if(sel && sel->frame)
			area_focus(sel);
}

void
float_resizeframe(Frame *f, Rectangle r) {

	if(f->area->view == selview)
		client_resize(f->client, r);
	else
		frame_resize(f, r);
}

void
float_arrange(Area *a) {
	Frame *f;

	assert(a->floating);

	switch(a->mode) {
	case Coldefault:
		break;
	case Colstack:
		for(f=a->frame; f; f=f->anext)
			f->collapsed = !(f->client->w.ewmh.type & (TypeDock|TypeMenu|TypeToolbar))
				    && (f != a->sel);
		break;
	default:
		die("not reached");
		break;
	}
	for(f=a->frame; f; f=f->anext)
		f->r = f->floatr;
	view_update(a->view);
}

static void
rect_push(Vector_rect *vec, Rectangle r) {
	Rectangle *rp;
	int i;

	for(i=0; i < vec->n; i++) {
		rp = &vec->ary[i];
		if(rect_contains_p(*rp, r))
			return;
		if(rect_contains_p(r, *rp)) {
			*rp = r;
			return;
		}
	}
	vector_rpush(vec, r);
}

Vector_rect*
unique_rects(Vector_rect *vec, Rectangle orig) {
{'fraction_non_alphanumeric': 0.20106809078771695, 'fraction_numerical': 0.004806408544726302, 'mean_word_length': 3.6825, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 105, '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': '7509525', 'n_tokens_mistral': 1766, 'n_tokens_neox': 1653, 'n_words': 342}