<commit_before>/*
 * (C)opyright MMIV-MMVI <NAME> <<EMAIL>>
 * See LICENSE file for license details.
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "wmii.h"

static Bool
is_empty(View *v) {
	Area *a;
	for(a=v->area; a; a=a->next)
		if(a->frame)
			return False;
	return True;
}

Frame *
clientframe_of_view(View *v, Client *c) {              
	Frame *f;
	for(f=c->frame; f; f=f->cnext)
		if(f->area->view == v)
			break;
	return f;
} 

static void
assign_sel_view(View *v) {
	if(screen->sel != v) {
		if(screen->sel)
			write_event("UnfocusTag %s\n",screen->sel->name);
		screen->sel = v;
		write_event("FocusTag %s\n", screen->sel->name);
	}
}

Client *
sel_client_of_view(View *v) {
	return v->sel && v->sel->sel ? v->sel->sel->client : nil;
}

View *
get_view(const char *name) {
	View *v;
	int cmp;

	for(v = view; v; v=v->next)
		if((cmp=strcmp(name, v->name)) >= 0)
			break;
	if(!v || cmp != 0)
		v = create_view(name);
	return v;
}

View *
create_view(const char *name) {
	static unsigned short id = 1;
	View **i, *v = ixp_emallocz(sizeof(View));

	v->id = id++;
	strncpy(v->name, name, sizeof(v->name));
	create_area(v, nil, 0);
	create_area(v, v->area, 0);
	v->area->floating = True;
	for(i=&view; *i; i=&(*i)->next)
		if(strcmp((*i)->name, name) < 0) break;
	v->next = *i;
	*i = v;
	write_event("CreateTag %s\n", v->name);
	if(!screen->sel)
		assign_sel_view(v);
	return v;
}

void
destroy_view(View *v) {
	Area *a;
	View **i;

	while((a = v->area)) {
		v->area = a->next;
		destroy_area(a);
	};
	for(i=&view; *i; i=&(*i)->next)
		if(*i == v) break;
	*i = v->next;
	if(screen->sel == v)
		for(screen->sel=view; screen->sel && screen->sel->next; screen->sel=screen->sel->next)
			if(screen->sel->next == *i) break;
	write_event("DestroyTag %s\n", v->name);
	free(v);
}

static void
update_frame_selectors(View *v) {
	Area *a;
	Frame *f;

	for(a=v->area; a; a=a->next)
		for(f=a->frame; f; f=f->anext)
			f->client->sel = f;
}

void
focus_view(WMScreen *s, View *v) {
	Frame *f;
	Client *c;

	XGrabServer(blz.dpy);
	assign_sel_view(v);
	update_frame_selectors(v);
	/* gives all(!) clients proper geometry (for use of different tags) */
	for(c=client; c; c=c->next)
		if((f = c->sel)) {
			if(f->view == v) {
				resize_client(c, &f->rect);
				//XMoveWindow(blz.dpy, c->framewin, f->rect.x, f->rect.y);
			}else
				XMoveWindow(blz.dpy, c->framewin, 2 * s->rect.width + f->rect.x,
						f->rect.y);
		}
	if((c = sel_client()))
		focus_client(c, False);
	draw_frames();
	XSync(blz.dpy, False);
	XUngrabServer(blz.dpy);
	flush_masked_events(EnterWindowMask);
}

void
select_view(const char *arg) {
	char buf[256];

	strncpy(buf, arg, sizeof(buf));
	trim(buf, " \t+/");
	if(!strlen(buf))
		return;<commit_msg>Clean up a nasty for-loop<commit_after>/*
 * (C)opyright MMIV-MMVI <NAME> <<EMAIL>>
 * See LICENSE file for license details.
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "wmii.h"

static Bool
is_empty(View *v) {
	Area *a;
	for(a=v->area; a; a=a->next)
		if(a->frame)
			return False;
	return True;
}

Frame *
clientframe_of_view(View *v, Client *c) {              
	Frame *f;
	for(f=c->frame; f; f=f->cnext)
		if(f->area->view == v)
			break;
	return f;
} 

static void
assign_sel_view(View *v) {
	if(screen->sel != v) {
		if(screen->sel)
			write_event("UnfocusTag %s\n",screen->sel->name);
		screen->sel = v;
		write_event("FocusTag %s\n", screen->sel->name);
	}
}

Client *
sel_client_of_view(View *v) {
	return v->sel && v->sel->sel ? v->sel->sel->client : nil;
}

View *
get_view(const char *name) {
	View *v;
	int cmp;

	for(v = view; v; v=v->next)
		if((cmp=strcmp(name, v->name)) >= 0)
			break;
	if(!v || cmp != 0)
		v = create_view(name);
	return v;
}

View *
create_view(const char *name) {
	static unsigned short id = 1;
	View **i, *v = ixp_emallocz(sizeof(View));

	v->id = id++;
	strncpy(v->name, name, sizeof(v->name));
	create_area(v, nil, 0);
	create_area(v, v->area, 0);
	v->area->floating = True;
	for(i=&view; *i; i=&(*i)->next)
		if(strcmp((*i)->name, name) < 0) break;
	v->next = *i;
	*i = v;
	write_event("CreateTag %s\n", v->name);
	if(!screen->sel)
		assign_sel_view(v);
	return v;
}

void
destroy_view(View *v) {
	Area *a;
	View **i;

	while((a = v->area)) {
		v->area = a->next;
		destroy_area(a);
	};
	for(i=&view; *i; i=&(*i)->next)
		if(*i == v) break;
	*i = v->next;
	if(screen->sel == v) {
		for(v = view; v && v->next; v = v->next)
			if(v->next == *i) break;
		screen->sel = *i;
	}
	write_event("DestroyTag %s\n", v->name);
	free(v);
}

static void
update_frame_selectors(View *v) {
	Area *a;
	Frame *f;

	for(a=v->area; a; a=a->next)
		for(f=a->frame; f; f=f->anext)
			f->client->sel = f;
}

void
focus_view(WMScreen *s, View *v) {
	Frame *f;
	Client *c;

	XGrabServer(blz.dpy);
	assign_sel_view(v);
	update_frame_selectors(v);
	/* gives all(!) clients proper geometry (for use of different tags) */
	for(c=client; c; c=c->next)
		if((f = c->sel)) {
			if(f->view == v)
				resize_client(c, &f->rect);
			else
				XMoveWindow(blz.dpy, c->framewin, 2 * s->rect.width + f->rect.x,
						f->rect.y);
		}
	if((c = sel_client()))
		focus_client(c, False);
	draw_frames();
	XSync(blz.dpy, False);
	XUngrabServer(blz.dpy);
	flush_masked_events(EnterWindowMask);
}

void
select_view(const char *arg) {
	char buf[256];

	strncpy(buf, arg, sizeof(buf));
	trim(buf, " \t+/");
	if(!strlen(buf))
		return;
{'fraction_non_alphanumeric': 0.21726245601037228, 'fraction_numerical': 0.003704389701796629, 'mean_word_length': 3.679376083188908, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 141, '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': '2569013', 'n_tokens_mistral': 2546, 'n_tokens_neox': 2404, 'n_words': 503}