<commit_before>/*
 * Copy me if you can.
 * by 20h
 */
#include <unistd.h>
#include <locale.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libgen.h>
#include <X11/keysym.h>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xproto.h>
#include <X11/extensions/XTest.h>

/* macros */
#define MAX(a, b)       ((a) > (b) ? (a) : (b))
#define LENGTH(x)       (sizeof x / sizeof x[0])

/* enums */
enum { ColFG, ColBG, ColLast };
enum { NetWMWindowType, NetLast };

/* typedefs */
typedef unsigned int uint;
typedef unsigned long ulong;

typedef struct {
	ulong norm[ColLast];
	ulong press[ColLast];
	ulong high[ColLast];

	Drawable drawable;
	GC gc;
	struct {
		int ascent;
		int descent;
		int height;
		XFontSet set;
		XFontStruct *xfont;
	} font;
} DC; /* draw context */

typedef struct {
	char *label;
	char *cmd;
	uint width;
	int x, y, w, h;
	Bool highlighted;
	Bool pressed;
	Bool forceexit;
} Entry;

/* function declarations */
static void motionnotify(XEvent *e);
static void buttonpress(XEvent *e);
static void buttonrelease(XEvent *e);
static void cleanup(void);
static void configurenotify(XEvent *e);
static void unmapnotify(XEvent *e);
static void die(const char *errstr, ...);
static void drawmenu(void);
static void drawentry(Entry *e);
static void expose(XEvent *e);
static Entry *findentry(int x, int y);
static ulong getcolor(const char *colstr);
static void initfont(const char *fontstr);
static void leavenotify(XEvent *e);
static void press(Entry *e);
static void run(void);
static void setup(void);
static int textnw(const char *text, uint len);
static void unpress(Entry *e);
static void updateentries(void);

/* variables */
static int screen;
static void (*handler[LASTEvent]) (XEvent *) = {
	[ButtonPress] = buttonpress,
	[ButtonRelease] = buttonrelease,
	[ConfigureNotify] = configurenotify,
	[UnmapNotify] = unmapnotify,
	[Expose] = expose,
	[LeaveNotify] = leavenotify,
	[MotionNotify] = motionnotify
};

static Display *dpy;
static DC dc;
static Window root, win;
static Bool running = True, horizontal = False;
/*
 * ww = window width; www = wanted window width; wh = window height;
 * wx = window x position; wy = window y position;
 */
static int ww = 0, www = 0, wh = 0, wx = 0, wy = 0;
static char *name = "thingmenu";

Entry **entries = NULL;
int nentries = 0;
int oneshot = 1;

/* configuration, allows nested code to access above variables */
#include "config.h"

void
motionnotify(XEvent *e)
{
	XPointerMovedEvent *ev = &e->xmotion;
	int i;

	for(i = 0; i < nentries; i++) {
		if(ev->x > entries[i]->x
				&& ev->x < entries[i]->x + entries[i]->w
				&& ev->y > entries[i]->y
				&& ev->y < entries[i]->y + entries[i]->h) {
			if (entries[i]->highlighted != True) {
				entries[i]->highlighted = True;
				drawentry(entries[i]);
			}
			continue;
		}
		if (entries[i]->highlighted == True) {
			entries[i]->highlighted = False;
			drawentry(entries[i]);
		}
	}
}

void
buttonpress(XEvent *e)
{
	XButtonPressedEvent *ev = &e->xbutton;
	Entry *en;

	if((en = findentry(ev->x, ev->y)))
		press(en);
}

void
buttonrelease(XEvent *e)
{
	XButtonPressedEvent *ev = &e->xbutton;
	Entry *en;

	if((en = findentry(ev->x, ev->y)))
		unpress(en);
}

void
cleanup(void)
{
	if(dc.font.set)
		XFreeFontSet(dpy, dc.font.set);
	else
		XFreeFont(dpy, dc.font.xfont);
	XFreePixmap(dpy, dc.drawable);
	XFreeGC(dpy, dc.gc);
	XDestroyWindow(dpy, win);
	XSync(dpy, False);
	XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);<commit_msg>Adding expected behaviour to highlight and press.<commit_after>/*
 * Copy me if you can.
 * by 20h
 */
#include <unistd.h>
#include <locale.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libgen.h>
#include <X11/keysym.h>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xproto.h>
#include <X11/extensions/XTest.h>

/* macros */
#define MAX(a, b)       ((a) > (b) ? (a) : (b))
#define LENGTH(x)       (sizeof x / sizeof x[0])

/* enums */
enum { ColFG, ColBG, ColLast };
enum { NetWMWindowType, NetLast };

/* typedefs */
typedef unsigned int uint;
typedef unsigned long ulong;

typedef struct {
	ulong norm[ColLast];
	ulong press[ColLast];
	ulong high[ColLast];

	Drawable drawable;
	GC gc;
	struct {
		int ascent;
		int descent;
		int height;
		XFontSet set;
		XFontStruct *xfont;
	} font;
} DC; /* draw context */

typedef struct {
	char *label;
	char *cmd;
	uint width;
	int x, y, w, h;
	Bool highlighted;
	Bool pressed;
	Bool forceexit;
} Entry;

/* function declarations */
static void motionnotify(XEvent *e);
static void buttonpress(XEvent *e);
static void buttonrelease(XEvent *e);
static void cleanup(void);
static void configurenotify(XEvent *e);
static void unmapnotify(XEvent *e);
static void die(const char *errstr, ...);
static void drawmenu(void);
static void drawentry(Entry *e);
static void expose(XEvent *e);
static Entry *findentry(int x, int y);
static ulong getcolor(const char *colstr);
static void initfont(const char *fontstr);
static void leavenotify(XEvent *e);
static void press(Entry *e);
static void run(void);
static void setup(void);
static int textnw(const char *text, uint len);
static void unpress(Entry *e);
static void updateentries(void);

/* variables */
static int screen;
static void (*handler[LASTEvent]) (XEvent *) = {
	[ButtonPress] = buttonpress,
	[ButtonRelease] = buttonrelease,
	[ConfigureNotify] = configurenotify,
	[UnmapNotify] = unmapnotify,
	[Expose] = expose,
	[LeaveNotify] = leavenotify,
	[MotionNotify] = motionnotify
};

static Display *dpy;
static DC dc;
static Window root, win;
static Bool running = True, horizontal = False;
/*
 * ww = window width; www = wanted window width; wh = window height;
 * wx = window x position; wy = window y position;
 */
static int ww = 0, www = 0, wh = 0, wx = 0, wy = 0;
static char *name = "thingmenu";

Entry **entries = NULL;
int nentries = 0;
int oneshot = 1;
Bool ispressing = 0;

/* configuration, allows nested code to access above variables */
#include "config.h"

void
motionnotify(XEvent *e)
{
	XPointerMovedEvent *ev = &e->xmotion;
	int i;

	for(i = 0; i < nentries; i++) {
		if(ev->x > entries[i]->x
				&& ev->x < entries[i]->x + entries[i]->w
				&& ev->y > entries[i]->y
				&& ev->y < entries[i]->y + entries[i]->h) {
			if (entries[i]->highlighted != True) {
				if (ispressing) {
					entries[i]->pressed = True;
				} else {
					entries[i]->highlighted = True;
				}
				drawentry(entries[i]);
			}
			continue;
		}
		if (entries[i]->pressed == True) {
			entries[i]->pressed = False;
			drawentry(entries[i]);
		}
		if (entries[i]->highlighted == True) {
			entries[i]->highlighted = False;
			drawentry(entries[i]);
		}
	}
}

void
buttonpress(XEvent *e)
{
	XButtonPressedEvent *ev = &e->xbutton;
	Entry *en;

	ispressing = True;

	if((en = findentry(ev->x, ev->y)))
		press(en);
}

void
buttonrelease(XEvent *e)
{
	XButtonPressedEvent *ev = &e->xbutton;
	Entry *en;

	ispressing = False;

	if((en = findentry(ev->x, ev->y)))
		unpress(en);
}

void
cleanup(void)
{
	if(dc.font.set)
		XFreeFontSet(dpy, dc.font.set);
	else
		XFreeFont(dpy, dc.font.xfont);
	XFreePixmap(dpy, dc.drawable);
	XFreeGC(dpy, dc.gc);
	XDestroyWindow(dpy, win);
	XSync(dpy, False);
	XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
{'fraction_non_alphanumeric': 0.15679347826086956, 'fraction_numerical': 0.006385869565217392, 'mean_word_length': 4.187455954897815, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 80, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '1113066', 'n_tokens_mistral': 2901, 'n_tokens_neox': 2718, 'n_words': 759}