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

Window *ewmhwin;

static void	ewmh_getwinstate(Client*);
static void	ewmh_setstate(Client*, Atom, int);
static void	tick(long, void*);

static Handlers	client_handlers;
static Handlers	root_handlers;

void
ewmh_init(void) {
	char myname[] = "wmii";
	long win;

	ewmhwin = createwindow(&scr.root,
		Rect(0, 0, 1, 1), 0 /*depth*/,
		InputOnly, nil, 0);

	win = ewmhwin->xid;
	changeprop_long(&scr.root, Net("SUPPORTING_WM_CHECK"), "WINDOW", &win, 1);
	changeprop_long(ewmhwin, Net("SUPPORTING_WM_CHECK"), "WINDOW", &win, 1);
	changeprop_string(ewmhwin, Net("WM_NAME"), myname);

	changeprop_long(&scr.root, Net("DESKTOP_VIEWPORT"), "CARDINAL",
			(long[2]){0, 0}, 2);

	pushhandler(&scr.root, &root_handlers, nil);

	tick(0L, nil);

	long supported[] = {
		/* Misc */
		NET("SUPPORTED"),
		/* Root Properties/Messages */
		NET("ACTIVE_WINDOW"),
		NET("CLOSE_WINDOW"),
		NET("CURRENT_DESKTOP"),
		/* Client Properties */
		NET("FRAME_EXTENTS"),
		NET("WM_DESKTOP"),
		NET("WM_FULLSCREEN_MONITORS"),
		NET("WM_NAME"),
		NET("WM_PID"),
		NET("WM_STRUT"),
		NET("WM_STRUT_PARTIAL"),
		/* States */
		NET("WM_STATE"),
		STATE("DEMANDS_ATTENTION"),
		STATE("FULLSCREEN"),
		STATE("SHADED"),
		/* Window Types */
		NET("WM_WINDOW_TYPE"),
		TYPE("DIALOG"),
		TYPE("DOCK"),
		TYPE("NORMAL"),
		TYPE("MENU"),
		TYPE("SPLASH"),
		TYPE("TOOLBAR"),
		/* Actions */
		NET("WM_ALLOWED_ACTIONS"),
		ACTION("FULLSCREEN"),
		/* Desktops */
		NET("DESKTOP_NAMES"),
		NET("NUMBER_OF_DESKTOPS"),
		/* Client List */
		NET("CLIENT_LIST"),
		NET("CLIENT_LIST_STACKING"),
	};
	changeprop_long(&scr.root, Net("SUPPORTED"), "ATOM", supported, nelem(supported));
}

inline bool
ewmh_responsive_p(Client *c) {
	return c->w.ewmh.ping == 0 || nsec() / 1000000 - c->w.ewmh.ping < PingTime;
}

void
ewmh_checkresponsive(Client *c) {

	if(!ewmh_responsive_p(c))
		if(!c->dead)
			frame_draw(c->sel);
		else if(c->dead++ == 1)
			event("Unresponsive %#C\n", c);
}

static void
tick(long id, void *v) {
	static int count;
	Client *c;
	ulong time;
	int mod, i;

	time = nsec() / 1000000;
	count++;
	mod = count % PingPartition;
	for(i=0, c=client; c; c=c->next, i++)
		if(c->proto & ProtoPing) {
			if(!ewmh_responsive_p(c))
				ewmh_checkresponsive(c);
			if(i % PingPartition == mod)
				sendmessage(&c->w, "WM_PROTOCOLS", NET("WM_PING"), time, c->w.xid, 0, 0);
			if(i % PingPartition == mod)
				Dprint(DEwmh, "_NET_WM_PING %#C %,uld\n", c, time);<commit_msg>Fix ping lag calculation on 32 bit systems. Closes issue #187.<commit_after>/* Copyright ©2007-2010 <NAME> <<EMAIL>>
 * See LICENSE file for license details.
 */
#include "dat.h"
#include <limits.h>
#include "fns.h"

Window *ewmhwin;

static void	ewmh_getwinstate(Client*);
static void	ewmh_setstate(Client*, Atom, int);
static void	tick(long, void*);

static Handlers	client_handlers;
static Handlers	root_handlers;

void
ewmh_init(void) {
	char myname[] = "wmii";
	long win;

	ewmhwin = createwindow(&scr.root,
		Rect(0, 0, 1, 1), 0 /*depth*/,
		InputOnly, nil, 0);

	win = ewmhwin->xid;
	changeprop_long(&scr.root, Net("SUPPORTING_WM_CHECK"), "WINDOW", &win, 1);
	changeprop_long(ewmhwin, Net("SUPPORTING_WM_CHECK"), "WINDOW", &win, 1);
	changeprop_string(ewmhwin, Net("WM_NAME"), myname);

	changeprop_long(&scr.root, Net("DESKTOP_VIEWPORT"), "CARDINAL",
			(long[2]){0, 0}, 2);

	pushhandler(&scr.root, &root_handlers, nil);

	tick(0L, nil);

	long supported[] = {
		/* Misc */
		NET("SUPPORTED"),
		/* Root Properties/Messages */
		NET("ACTIVE_WINDOW"),
		NET("CLOSE_WINDOW"),
		NET("CURRENT_DESKTOP"),
		/* Client Properties */
		NET("FRAME_EXTENTS"),
		NET("WM_DESKTOP"),
		NET("WM_FULLSCREEN_MONITORS"),
		NET("WM_NAME"),
		NET("WM_PID"),
		NET("WM_STRUT"),
		NET("WM_STRUT_PARTIAL"),
		/* States */
		NET("WM_STATE"),
		STATE("DEMANDS_ATTENTION"),
		STATE("FULLSCREEN"),
		STATE("SHADED"),
		/* Window Types */
		NET("WM_WINDOW_TYPE"),
		TYPE("DIALOG"),
		TYPE("DOCK"),
		TYPE("NORMAL"),
		TYPE("MENU"),
		TYPE("SPLASH"),
		TYPE("TOOLBAR"),
		/* Actions */
		NET("WM_ALLOWED_ACTIONS"),
		ACTION("FULLSCREEN"),
		/* Desktops */
		NET("DESKTOP_NAMES"),
		NET("NUMBER_OF_DESKTOPS"),
		/* Client List */
		NET("CLIENT_LIST"),
		NET("CLIENT_LIST_STACKING"),
	};
	changeprop_long(&scr.root, Net("SUPPORTED"), "ATOM", supported, nelem(supported));
}

inline bool
ewmh_responsive_p(Client *c) {
	return c->w.ewmh.ping == 0 || (ulong)(nsec() / 1000000) - c->w.ewmh.ping < PingTime;
}

void
ewmh_checkresponsive(Client *c) {

	if(!ewmh_responsive_p(c))
		if(!c->dead)
			frame_draw(c->sel);
		else if(c->dead++ == 1)
			event("Unresponsive %#C\n", c);
}

static void
tick(long id, void *v) {
	static int count;
	Client *c;
	ulong time;
	int mod, i;

	time = nsec() / 1000000;
	count++;
	mod = count % PingPartition;
	for(i=0, c=client; c; c=c->next, i++)
		if(c->proto & ProtoPing) {
			if(!ewmh_responsive_p(c))
				ewmh_checkresponsive(c);
			if(i % PingPartition == mod)
				sendmessage(&c->w, "WM_PROTOCOLS", NET("WM_PING"), time, c->w.xid, 0, 0);
			if(i % PingPartition == mod)
				Dprint(DEwmh, "_NET_WM_PING %#C %,uld\n", c, time);
{'fraction_non_alphanumeric': 0.1944922547332186, 'fraction_numerical': 0.016255498183209028, 'mean_word_length': 4.703380588876772, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 31, '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': '1148827', 'n_tokens_mistral': 2364, 'n_tokens_neox': 2114, 'n_words': 415}