Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Simplified dirsInit; better variable names for colors
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 4100a87208f1c1332201f0d04ae8081059c3dcb12fa345e1eb6e7ac6ddf820bd
User & Date: jmcclure 2020-03-30 19:14:31
Context
2020-03-30
23:01
Adjusted vertical spacing check-in: d152045be2 user: jmcclure tags: trunk
19:14
Simplified dirsInit; better variable names for colors check-in: 4100a87208 user: jmcclure tags: trunk
2020-03-25
23:42
Added some emacs-style keys check-in: 7348de7b2c user: jmcclure tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to config.h.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

static const char *font = "PT Sans";
static const char bang = '!';

static unsigned long
	colBG = 0x404448,
	colFG = 0xEEEEEE,
	colCS = 0xFFDD88,
	colBD = 0x000000;

static int
	x = 0,
	y = 0,
	w = 0,
	/* 'h' is determined by font metrics */
	left = 4, // TODO, I hate this ... needs to come from font metrics
	bpx = 1;

static Key keys[] = {
/*   Modifiers             Keysym           Function     Args */
	{ ControlMask,          XK_q,            quit,        { 0 } },
	{ 0,                    XK_Escape,       quit,        { 0 } },
	{ 0,                    XK_Tab,          complete,    { .v = "default" } },
	{ 0,                    XK_Return,       run,         { .v = "default" } },

|



|
|
|
|



|
|
<
<
|







1
2
3
4
5
6
7
8
9
10
11
12
13
14


15
16
17
18
19
20
21
22

static const char *font = "sans:size=10";
static const char bang = '!';

static unsigned long
	color_background = 0x404448,
	color_foreground = 0xEEEEEE,
	color_cursor     = 0xFFDD88,
	color_border     = 0x000000;

static int
	x = 0,
	y = 0, /* y=-1 for bottom of screen */
	w = 0, /* w=0 for screen width */


	border_px = 1;

static Key keys[] = {
/*   Modifiers             Keysym           Function     Args */
	{ ControlMask,          XK_q,            quit,        { 0 } },
	{ 0,                    XK_Escape,       quit,        { 0 } },
	{ 0,                    XK_Tab,          complete,    { .v = "default" } },
	{ 0,                    XK_Return,       run,         { .v = "default" } },

Changes to interrobang.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/* Copyright 2020 Jesse McClure <code@jessemcclure.org>
 * See LICENSE for details
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <X11/Xatom.h>
#include <X11/Xft/Xft.h>

#define MAX 1024










<
<







1
2
3
4
5
6
7
8
9


10
11
12
13
14
15
16
/* Copyright 2020 Jesse McClure <code@jessemcclure.org>
 * See LICENSE for details
 */

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


#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <X11/Xatom.h>
#include <X11/Xft/Xft.h>

#define MAX 1024

64
65
66
67
68
69
70
71
72
73
74
75
76
77
78


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131


132
133
134
135
136
137
138
139
140
141
142
143
static Atom XA_CLIPBOARD;


/* INITIALIZATION FUNCTIONS: IN ORDER OF CALL */

static int dirsInit(int argc, const char *argv[]) {
	const char *var;
	if ((var=getenv("XDG_DATA_HOME"))) {
		snprintf(line, MAX, "%s/interrobang/tab/", var);
		setenv(ENV_TAB, line, 1);
		snprintf(line, MAX, "%s/interrobang/run/", var);
		setenv(ENV_RUN, line, 1);
	}
	else if ((var=getenv("HOME"))) {
		snprintf(line, MAX, "%s/.local/share/interrobang/tab/", var);


		setenv(ENV_TAB, line, 1);
		snprintf(line, MAX, "%s/.local/share/interrobang/run/", var);
		setenv(ENV_RUN, line, 1);
	}
	line[0] = '\0';
	return 0;
}

static int xlibInit(int argc, const char *argv[]) {
	int i;
	dpy = XOpenDisplay(0x0);
	scr = DefaultScreen(dpy);
	root = RootWindow(dpy, scr);
	w = (w ? w : DisplayWidth(dpy,scr) - bpx * 2);
	XA_CLIPBOARD = XInternAtom(dpy, "CLIPBOARD", False);
	for (i = 0; i < 1000; i++) {
		if (XGrabKeyboard(dpy,root,True,GrabModeAsync,GrabModeAsync,
			CurrentTime) == GrabSuccess) break;
		usleep(1000);
	}
	if (i == 1000) {
		fprintf(stderr, "Unable to grab keyboard\n");
		XCloseDisplay(dpy);
		exit(1);
	}
	return 0;
}

static int colorsInit(int argc, const char *argv[]) {
	XRenderColor xrcol;
	xrcol.red = ((colFG & 0xFF0000) >> 8) | 0xFF;
	xrcol.green = (colFG & 0x00FF00) | 0xFF;
	xrcol.blue = (colFG << 8) | 0xFF;
	xrcol.alpha = 0xFFFF;
	XftColorAllocValue(dpy, DefaultVisual(dpy, scr), DefaultColormap(dpy, scr), &xrcol, &xcol);
	gc = DefaultGC(dpy, scr);
	XSetForeground(dpy, gc, colCS);
	XSetBackground(dpy, gc, colBG);
	return 0;
}

static int fontInit(int argc, const char *argv[]) {
	xfont = XftFontOpenName(dpy, scr, font);
	fh = xfont->ascent;
	h = fh + xfont->descent;
	return 0;
}

static int winInit(int argc, const char *argv[]) {
	XSetWindowAttributes wa;
	wa.override_redirect = True;
	wa.border_pixel = colBD;
	wa.background_pixel = colBG;


	win = XCreateWindow(dpy, root, x, y, w, h, bpx, DefaultDepth(dpy,scr), CopyFromParent,
			DefaultVisual(dpy,scr), CWOverrideRedirect|CWBorderPixel|CWBackPixel, &wa);
	xdraw = XftDrawCreate(dpy, win, DefaultVisual(dpy, scr), DefaultColormap(dpy, scr));
	XMapWindow(dpy, win);
	XFillRectangle(dpy, win, gc, left + 2, h-fh-3, 2, fh-2);
	return 0;
}

static int keymapInit(int argc, const char *argv[]) {
	int i, j;
	const char *name;
	for (j = 0; keymaps[j].name; j++) {







|

<
<
<
<
|

>
>
|
|
|
<









<
















|
|
|



|
|













|
|
>
>
|



<







62
63
64
65
66
67
68
69
70




71
72
73
74
75
76
77

78
79
80
81
82
83
84
85
86

87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

132
133
134
135
136
137
138
static Atom XA_CLIPBOARD;


/* INITIALIZATION FUNCTIONS: IN ORDER OF CALL */

static int dirsInit(int argc, const char *argv[]) {
	const char *var;
	if ((var=getenv("XDG_DATA_HOME")))
		snprintf(line, MAX, "%s/interrobang/tab/", var);




	else if ((var=getenv("HOME")))
		snprintf(line, MAX, "%s/.local/share/interrobang/tab/", var);
	else /* fallback to package defaults */
		strcpy(line,"/usr/lib/interrobang/tab/");
	setenv(ENV_TAB, line, 1);
	strcpy(line + strlen(line) - 4, "run/");
	setenv(ENV_RUN, line, 1);

	line[0] = '\0';
	return 0;
}

static int xlibInit(int argc, const char *argv[]) {
	int i;
	dpy = XOpenDisplay(0x0);
	scr = DefaultScreen(dpy);
	root = RootWindow(dpy, scr);

	XA_CLIPBOARD = XInternAtom(dpy, "CLIPBOARD", False);
	for (i = 0; i < 1000; i++) {
		if (XGrabKeyboard(dpy,root,True,GrabModeAsync,GrabModeAsync,
			CurrentTime) == GrabSuccess) break;
		usleep(1000);
	}
	if (i == 1000) {
		fprintf(stderr, "Unable to grab keyboard\n");
		XCloseDisplay(dpy);
		exit(1);
	}
	return 0;
}

static int colorsInit(int argc, const char *argv[]) {
	XRenderColor xrcol;
	xrcol.red =   ((color_foreground & 0xFF0000) >> 8 ) | 0xFF;
	xrcol.green = ((color_foreground & 0x00FF00)      ) | 0xFF;
	xrcol.blue =  ((color_foreground & 0x0000FF) << 8 ) | 0xFF;
	xrcol.alpha = 0xFFFF;
	XftColorAllocValue(dpy, DefaultVisual(dpy, scr), DefaultColormap(dpy, scr), &xrcol, &xcol);
	gc = DefaultGC(dpy, scr);
	XSetForeground(dpy, gc, color_cursor);
	XSetBackground(dpy, gc, color_background);
	return 0;
}

static int fontInit(int argc, const char *argv[]) {
	xfont = XftFontOpenName(dpy, scr, font);
	fh = xfont->ascent;
	h = fh + xfont->descent;
	return 0;
}

static int winInit(int argc, const char *argv[]) {
	XSetWindowAttributes wa;
	wa.override_redirect = True;
	wa.border_pixel = color_border;
	wa.background_pixel = color_background;
	w = (w ? w : DisplayWidth(dpy,scr) - border_px * 2);
	y = (y == -1 ? DisplayHeight(dpy, scr) - border_px * 2 - h : y);
	win = XCreateWindow(dpy, root, x, y, w, h, border_px, DefaultDepth(dpy,scr), CopyFromParent,
			DefaultVisual(dpy,scr), CWOverrideRedirect|CWBorderPixel|CWBackPixel, &wa);
	xdraw = XftDrawCreate(dpy, win, DefaultVisual(dpy, scr), DefaultColormap(dpy, scr));
	XMapWindow(dpy, win);

	return 0;
}

static int keymapInit(int argc, const char *argv[]) {
	int i, j;
	const char *name;
	for (j = 0; keymaps[j].name; j++) {
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200

201
202
203
204
205
206
207
	pos += len;
	return 0;
}

static int redraw() {
	XGlyphInfo ext;
	XClearWindow(dpy, win);
	XftDrawStringUtf8(xdraw, &xcol, xfont, left, fh-2, (XftChar8 *) line, strlen(line));
	XftTextExtentsUtf8(dpy, xfont, (XftChar8 *) line, pos, &ext);
	XFillRectangle(dpy, win, gc, left + ext.xOff + 2, h-fh-3, 2, fh-2);
	return 0;
}

static int mainLoop() {
	XEvent ev;
	KeySym key;
	int len;
	char txt[32];
	snprintf(txt, 32, "/tmp/iBang%d", getpid());
	setenv(ENV_TEMP, txt, 1);

	while (!XNextEvent(dpy, &ev) && running) {
		if (XFilterEvent(&ev,win) || ev.type != KeyPress)
			continue;
		key = NoSymbol;
		XLookupString(&ev.xkey, txt, sizeof txt, &key, NULL);
		len = strlen(txt);
		if (!keymapCheck(ev.xkey.state, key) && !iscntrl(*txt))







|

|










>







176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
	pos += len;
	return 0;
}

static int redraw() {
	XGlyphInfo ext;
	XClearWindow(dpy, win);
	XftDrawStringUtf8(xdraw, &xcol, xfont, 0, fh-2, (XftChar8 *) line, strlen(line));
	XftTextExtentsUtf8(dpy, xfont, (XftChar8 *) line, pos, &ext);
	XFillRectangle(dpy, win, gc, ext.xOff + 2, h-fh-3, 2, fh-2);
	return 0;
}

static int mainLoop() {
	XEvent ev;
	KeySym key;
	int len;
	char txt[32];
	snprintf(txt, 32, "/tmp/iBang%d", getpid());
	setenv(ENV_TEMP, txt, 1);
	redraw();
	while (!XNextEvent(dpy, &ev) && running) {
		if (XFilterEvent(&ev,win) || ev.type != KeyPress)
			continue;
		key = NoSymbol;
		XLookupString(&ev.xkey, txt, sizeof txt, &key, NULL);
		len = strlen(txt);
		if (!keymapCheck(ev.xkey.state, key) && !iscntrl(*txt))