aboutsummaryrefslogtreecommitdiff
path: root/sys/cmd/term/x.c
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-06-06 13:15:14 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-06-06 13:15:14 -0700
commitc320322dffd8f4648cc24ab731ac64dda6eec77d (patch)
tree9c668d1e1a331991abeb8aa3b838ba470be7252b /sys/cmd/term/x.c
parent7b5b105d84103d4320de510f0fdab345b5d2f477 (diff)
changed all caps
Diffstat (limited to 'sys/cmd/term/x.c')
-rw-r--r--sys/cmd/term/x.c155
1 files changed, 77 insertions, 78 deletions
diff --git a/sys/cmd/term/x.c b/sys/cmd/term/x.c
index 9e0327c..129d639 100644
--- a/sys/cmd/term/x.c
+++ b/sys/cmd/term/x.c
@@ -10,22 +10,21 @@
#include <X11/XKBlib.h>
#include "term.h"
-#include "win.h"
/* types used in config.h */
typedef struct {
- uint mod;
+ uint mod;
KeySym keysym;
void (*func)(Arg *);
- Arg arg;
+ Arg arg;
} Shortcut;
typedef struct {
uint mod;
uint button;
void (*func)(Arg *);
- Arg arg;
- uint release;
+ Arg arg;
+ uint release;
} MouseShortcut;
typedef struct {
@@ -133,9 +132,9 @@ typedef struct {
} DC;
static inline ushort sixd_to_16bit(int);
-static int xmakeglyphfontspecs(XftGlyphFontSpec *, Glyph *, int, int, int);
-static void xdrawglyphfontspecs(XftGlyphFontSpec *, Glyph, int, int, int);
-static void xdrawglyph(Glyph, int, int);
+static int xmakeglyphfontspecs(XftGlyphFontSpec *, Letter *, int, int, int);
+static void xdrawglyphfontspecs(XftGlyphFontSpec *, Letter, int, int, int);
+static void xdrawglyph(Letter, int, int);
static void xclear(int, int, int, int);
static int xgeommasktogravity(int);
static int ximopen(Display *);
@@ -281,7 +280,7 @@ selpaste(Arg *_)
void
numlock(Arg *_)
{
- win.mode ^= MODE_NUMLOCK;
+ win.mode ^= Wnumlock;
}
void
@@ -339,7 +338,7 @@ evrow(XEvent *e)
void
mousesel(XEvent *e, int done)
{
- int type, seltype = SEL_REGULAR;
+ int type, seltype = SelRegular;
uint state = e->xbutton.state & ~(Button1Mask | forcemousemod);
for (type = 1; type < arrlen(selmasks); ++type) {
@@ -365,17 +364,17 @@ mousereport(XEvent *e)
if (e->xbutton.type == MotionNotify) {
if (x == ox && y == oy)
return;
- if (!IS_SET(MODE_MOUSEMOTION) && !IS_SET(MODE_MOUSEMANY))
+ if (!IS_SET(Wmousemotion) && !IS_SET(Wmousemany))
return;
/* MOUSE_MOTION: no reporting if no button is pressed */
- if (IS_SET(MODE_MOUSEMOTION) && oldbutton == 3)
+ if (IS_SET(Wmousemotion) && oldbutton == 3)
return;
button = oldbutton + 32;
ox = x;
oy = y;
} else {
- if (!IS_SET(MODE_MOUSESGR) && e->xbutton.type == ButtonRelease) {
+ if (!IS_SET(Wmousesgr) && e->xbutton.type == ButtonRelease) {
button = 3;
} else {
button -= Button1;
@@ -388,21 +387,21 @@ mousereport(XEvent *e)
oy = y;
} else if (e->xbutton.type == ButtonRelease) {
oldbutton = 3;
- /* MODE_MOUSEX10: no button release reporting */
- if (IS_SET(MODE_MOUSEX10))
+ /* Wmousex10: no button release reporting */
+ if (IS_SET(Wmousex10))
return;
if (button == 64 || button == 65)
return;
}
}
- if (!IS_SET(MODE_MOUSEX10)) {
+ if (!IS_SET(Wmousex10)) {
button += ((state & ShiftMask ) ? 4 : 0)
+ ((state & Mod4Mask ) ? 8 : 0)
+ ((state & ControlMask) ? 16 : 0);
}
- if (IS_SET(MODE_MOUSESGR)) {
+ if (IS_SET(Wmousesgr)) {
len = snprintf(buf, sizeof(buf), "\033[<%d;%d;%d%c",
button, x+1, y+1,
e->xbutton.type == ButtonRelease ? 'm' : 'M');
@@ -454,7 +453,7 @@ bpress(XEvent *e)
struct timespec now;
int snap;
- if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forcemousemod)) {
+ if (IS_SET(Wmouse) && !(e->xbutton.state & forcemousemod)) {
mousereport(e);
return;
}
@@ -469,9 +468,9 @@ bpress(XEvent *e)
*/
clock_gettime(CLOCK_MONOTONIC, &now);
if (TIMEDIFF(now, xsel.tclick2) <= tripleclicktimeout) {
- snap = SNAP_LINE;
+ snap = SnapLine;
} else if (TIMEDIFF(now, xsel.tclick1) <= doubleclicktimeout) {
- snap = SNAP_WORD;
+ snap = SnapWord;
} else {
snap = 0;
}
@@ -566,10 +565,10 @@ selnotify(XEvent *e)
*repl++ = '\r';
}
- if (IS_SET(MODE_BRCKTPASTE) && ofs == 0)
+ if (IS_SET(Wbrcktpaste) && ofs == 0)
ttywrite("\033[200~", 6, 0);
ttywrite((char *)data, nitems * format / 8, 1);
- if (IS_SET(MODE_BRCKTPASTE) && rem == 0)
+ if (IS_SET(Wbrcktpaste) && rem == 0)
ttywrite("\033[201~", 6, 0);
XFree(data);
/* number of 32-bit chunks returned */
@@ -676,7 +675,7 @@ xsetsel(char *str)
void
brelease(XEvent *e)
{
- if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forcemousemod)) {
+ if (IS_SET(Wmouse) && !(e->xbutton.state & forcemousemod)) {
mousereport(e);
return;
}
@@ -690,7 +689,7 @@ brelease(XEvent *e)
void
bmotion(XEvent *e)
{
- if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forcemousemod)) {
+ if (IS_SET(Wmouse) && !(e->xbutton.state & forcemousemod)) {
mousereport(e);
return;
}
@@ -813,7 +812,7 @@ void
xclear(int x1, int y1, int x2, int y2)
{
XftDrawRect(xw.draw,
- &dc.col[IS_SET(MODE_REVERSE)? defaultfg : defaultbg],
+ &dc.col[IS_SET(Wreverse)? defaultfg : defaultbg],
x1, y1, x2-x1, y2-y1);
}
@@ -1184,7 +1183,7 @@ xinit(int cols, int rows)
XChangeProperty(xw.dpy, xw.win, xw.netwmpid, XA_CARDINAL, 32,
PropModeReplace, (uchar *)&thispid, 1);
- win.mode = MODE_NUMLOCK;
+ win.mode = Wnumlock;
resettitle();
xhints();
XMapWindow(xw.dpy, xw.win);
@@ -1200,7 +1199,7 @@ xinit(int cols, int rows)
}
int
-xmakeglyphfontspecs(XftGlyphFontSpec *specs, Glyph *glyphs, int len, int x, int y)
+xmakeglyphfontspecs(XftGlyphFontSpec *specs, Letter *glyphs, int len, int x, int y)
{
float winx = borderpx + x * win.cw, winy = borderpx + y * win.ch, xp, yp;
ushort mode, prevmode = USHRT_MAX;
@@ -1221,7 +1220,7 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, Glyph *glyphs, int len, int x, int
mode = glyphs[i].mode;
/* Skip dummy wide-character spacing. */
- if (mode == ATTR_WDUMMY)
+ if (mode == Gwdummy)
continue;
/* Determine font for glyph if different from previous glyph. */
@@ -1229,14 +1228,14 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, Glyph *glyphs, int len, int x, int
prevmode = mode;
font = &dc.font;
frcflags = FRC_NORMAL;
- runewidth = win.cw * ((mode & ATTR_WIDE) ? 2.0f : 1.0f);
- if ((mode & ATTR_ITALIC) && (mode & ATTR_BOLD)) {
+ runewidth = win.cw * ((mode & Gwide) ? 2.0f : 1.0f);
+ if ((mode & Gitalic) && (mode & Gbold)) {
font = &dc.ibfont;
frcflags = FRC_ITALICBOLD;
- } else if (mode & ATTR_ITALIC) {
+ } else if (mode & Gitalic) {
font = &dc.ifont;
frcflags = FRC_ITALIC;
- } else if (mode & ATTR_BOLD) {
+ } else if (mode & Gbold) {
font = &dc.bfont;
frcflags = FRC_BOLD;
}
@@ -1332,9 +1331,9 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, Glyph *glyphs, int len, int x, int
}
void
-xdrawglyphfontspecs(XftGlyphFontSpec *specs, Glyph base, int len, int x, int y)
+xdrawglyphfontspecs(XftGlyphFontSpec *specs, Letter base, int len, int x, int y)
{
- int charlen = len * ((base.mode & ATTR_WIDE) ? 2 : 1);
+ int charlen = len * ((base.mode & Gwide) ? 2 : 1);
int winx = borderpx + x * win.cw, winy = borderpx + y * win.ch,
width = charlen * win.cw;
Color *fg, *bg, *temp, revfg, revbg, truefg, truebg;
@@ -1342,11 +1341,11 @@ xdrawglyphfontspecs(XftGlyphFontSpec *specs, Glyph base, int len, int x, int y)
XRectangle r;
/* Fallback on color display for attributes not supported by the font */
- if (base.mode & ATTR_ITALIC && base.mode & ATTR_BOLD) {
+ if (base.mode & Gitalic && base.mode & Gbold) {
if (dc.ibfont.badslant || dc.ibfont.badweight)
base.fg = defaultattr;
- } else if ((base.mode & ATTR_ITALIC && dc.ifont.badslant) ||
- (base.mode & ATTR_BOLD && dc.bfont.badweight)) {
+ } else if ((base.mode & Gitalic && dc.ifont.badslant) ||
+ (base.mode & Gbold && dc.bfont.badweight)) {
base.fg = defaultattr;
}
@@ -1373,10 +1372,10 @@ xdrawglyphfontspecs(XftGlyphFontSpec *specs, Glyph base, int len, int x, int y)
}
/* Change basic system colors [0-7] to bright system colors [8-15] */
- if ((base.mode & ATTR_BOLD_FAINT) == ATTR_BOLD && BETWEEN(base.fg, 0, 7))
+ if ((base.mode & Gfaint) == Gbold && BETWEEN(base.fg, 0, 7))
fg = &dc.col[base.fg + 8];
- if (IS_SET(MODE_REVERSE)) {
+ if (IS_SET(Wreverse)) {
if (fg == &dc.col[defaultfg]) {
fg = &dc.col[defaultbg];
} else {
@@ -1402,7 +1401,7 @@ xdrawglyphfontspecs(XftGlyphFontSpec *specs, Glyph base, int len, int x, int y)
}
}
- if ((base.mode & ATTR_BOLD_FAINT) == ATTR_FAINT) {
+ if ((base.mode & Gboldfaint) == Gfaint) {
colfg.red = fg->color.red / 2;
colfg.green = fg->color.green / 2;
colfg.blue = fg->color.blue / 2;
@@ -1411,16 +1410,16 @@ xdrawglyphfontspecs(XftGlyphFontSpec *specs, Glyph base, int len, int x, int y)
fg = &revfg;
}
- if (base.mode & ATTR_REVERSE) {
+ if (base.mode & Greverse) {
temp = fg;
fg = bg;
bg = temp;
}
- if (base.mode & ATTR_BLINK && win.mode & MODE_BLINK)
+ if (base.mode & Gblink && win.mode & Wblink)
fg = bg;
- if (base.mode & ATTR_INVISIBLE)
+ if (base.mode & Ginvisible)
fg = bg;
/* Intelligent cleaning up of the borders. */
@@ -1452,12 +1451,12 @@ xdrawglyphfontspecs(XftGlyphFontSpec *specs, Glyph base, int len, int x, int y)
XftDrawGlyphFontSpec(xw.draw, fg, specs, len);
/* Render underline and strikethrough. */
- if (base.mode & ATTR_UNDERLINE) {
+ if (base.mode & Gunline) {
XftDrawRect(xw.draw, fg, winx, winy + dc.font.ascent + 1,
width, 1);
}
- if (base.mode & ATTR_STRUCK) {
+ if (base.mode & Gstruck) {
XftDrawRect(xw.draw, fg, winx, winy + 2 * dc.font.ascent / 3,
width, 1);
}
@@ -1467,7 +1466,7 @@ xdrawglyphfontspecs(XftGlyphFontSpec *specs, Glyph base, int len, int x, int y)
}
void
-xdrawglyph(Glyph g, int x, int y)
+xdrawglyph(Letter g, int x, int y)
{
int numspecs;
XftGlyphFontSpec spec;
@@ -1477,25 +1476,25 @@ xdrawglyph(Glyph g, int x, int y)
}
void
-xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
+xdrawcursor(int cx, int cy, Letter g, int ox, int oy, Letter og)
{
Color drawcol;
/* remove the old cursor */
if (selected(ox, oy))
- og.mode ^= ATTR_REVERSE;
+ og.mode ^= Greverse;
xdrawglyph(og, ox, oy);
- if (IS_SET(MODE_HIDE))
+ if (IS_SET(Whide))
return;
/*
* Select the right color for the right mode.
*/
- g.mode &= ATTR_BOLD|ATTR_ITALIC|ATTR_UNDERLINE|ATTR_STRUCK|ATTR_WIDE;
+ g.mode &= Gbold|Gitalic|Gunline|Gstruck|Gwide;
- if (IS_SET(MODE_REVERSE)) {
- g.mode |= ATTR_REVERSE;
+ if (IS_SET(Wreverse)) {
+ g.mode |= Greverse;
g.bg = defaultfg;
if (selected(cx, cy)) {
drawcol = dc.col[defaultcs];
@@ -1516,7 +1515,7 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
}
/* draw the new one */
- if (IS_SET(MODE_FOCUSED)) {
+ if (IS_SET(Wfocused)) {
switch (win.cursor) {
case 7: /* st extension */
g.u = 0x2603; /* snowman (U+2603) */
@@ -1587,25 +1586,25 @@ xsettitle(char *p)
int
xstartdraw(void)
{
- return IS_SET(MODE_VISIBLE);
+ return IS_SET(Wvisible);
}
void
xdrawline(Line line, int x1, int y1, int x2)
{
int i, x, ox, numspecs;
- Glyph base, new;
+ Letter base, new;
XftGlyphFontSpec *specs = xw.specbuf;
numspecs = xmakeglyphfontspecs(specs, &line[x1], x2 - x1, x1, y1);
i = ox = 0;
for (x = x1; x < x2 && i < numspecs; x++) {
new = line[x];
- if (new.mode == ATTR_WDUMMY)
+ if (new.mode == Gwdummy)
continue;
if (selected(x, y1))
- new.mode ^= ATTR_REVERSE;
- if (i > 0 && ATTRCMP(base, new)) {
+ new.mode ^= Greverse;
+ if (i > 0 && GLYPHCMP(base, new)) {
xdrawglyphfontspecs(specs, base, i, ox, y1);
specs += i;
numspecs -= i;
@@ -1627,7 +1626,7 @@ xfinishdraw(void)
XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, win.w,
win.h, 0, 0);
XSetForeground(xw.dpy, dc.gc,
- dc.col[IS_SET(MODE_REVERSE)?
+ dc.col[IS_SET(Wreverse)?
defaultfg : defaultbg].pixel);
}
@@ -1654,13 +1653,13 @@ visibility(XEvent *ev)
{
XVisibilityEvent *e = &ev->xvisibility;
- MODBIT(win.mode, e->state != VisibilityFullyObscured, MODE_VISIBLE);
+ MODBIT(win.mode, e->state != VisibilityFullyObscured, Wvisible);
}
void
unmap(XEvent *ev)
{
- win.mode &= ~MODE_VISIBLE;
+ win.mode &= ~Wvisible;
}
void
@@ -1675,7 +1674,7 @@ xsetmode(int set, uint flags)
{
int mode = win.mode;
MODBIT(win.mode, set, flags);
- if ((win.mode & MODE_REVERSE) != (mode & MODE_REVERSE))
+ if ((win.mode & Wreverse) != (mode & Wreverse))
redraw();
}
@@ -1701,7 +1700,7 @@ xseturgency(int add)
void
xbell(void)
{
- if (!(IS_SET(MODE_FOCUSED)))
+ if (!(IS_SET(Wfocused)))
xseturgency(1);
if (bellvolume)
XkbBell(xw.dpy, xw.win, bellvolume, (Atom)nil);
@@ -1718,15 +1717,15 @@ focus(XEvent *ev)
if (ev->type == FocusIn) {
if (xw.ime.xic)
XSetICFocus(xw.ime.xic);
- win.mode |= MODE_FOCUSED;
+ win.mode |= Wfocused;
xseturgency(0);
- if (IS_SET(MODE_FOCUS))
+ if (IS_SET(Wfocus))
ttywrite("\033[I", 3, 0);
} else {
if (xw.ime.xic)
XUnsetICFocus(xw.ime.xic);
- win.mode &= ~MODE_FOCUSED;
- if (IS_SET(MODE_FOCUS))
+ win.mode &= ~Wfocused;
+ if (IS_SET(Wfocus))
ttywrite("\033[O", 3, 0);
}
}
@@ -1760,12 +1759,12 @@ kmap(KeySym k, uint state)
if (!match(kp->mask, state))
continue;
- if (IS_SET(MODE_APPKEYPAD) ? kp->appkey < 0 : kp->appkey > 0)
+ if (IS_SET(Wappkeypad) ? kp->appkey < 0 : kp->appkey > 0)
continue;
- if (IS_SET(MODE_NUMLOCK) && kp->appkey == 2)
+ if (IS_SET(Wnumlock) && kp->appkey == 2)
continue;
- if (IS_SET(MODE_APPCURSOR) ? kp->appcursor < 0 : kp->appcursor > 0)
+ if (IS_SET(Wappcursor) ? kp->appcursor < 0 : kp->appcursor > 0)
continue;
return kp->s;
@@ -1785,7 +1784,7 @@ kpress(XEvent *ev)
Status status;
Shortcut *bp;
- if (IS_SET(MODE_KBDLOCK))
+ if (IS_SET(Wkbdblock))
return;
if (xw.ime.xic)
@@ -1810,7 +1809,7 @@ kpress(XEvent *ev)
if (len == 0)
return;
if (len == 1 && e->state & Mod1Mask) {
- if (IS_SET(MODE_8BIT)) {
+ if (IS_SET(W8bit)) {
if (*buf < 0177) {
c = *buf | 0x80;
len = utf8·runetobyte(buf, &c);
@@ -1833,10 +1832,10 @@ cmessage(XEvent *e)
*/
if (e->xclient.message_type == xw.xembed && e->xclient.format == 32) {
if (e->xclient.data.l[1] == XEMBED_FOCUS_IN) {
- win.mode |= MODE_FOCUSED;
+ win.mode |= Wfocused;
xseturgency(0);
} else if (e->xclient.data.l[1] == XEMBED_FOCUS_OUT) {
- win.mode &= ~MODE_FOCUSED;
+ win.mode &= ~Wfocused;
}
} else if (e->xclient.data.l[0] == xw.wmdeletewin) {
ttyhangup();
@@ -1938,13 +1937,13 @@ run(void)
/* idle detected or maxlatency exhausted -> draw */
timeout = -1;
- if (blinktimeout && tattrset(ATTR_BLINK)) {
+ if (blinktimeout && tattrset(Gblink)) {
timeout = blinktimeout - TIMEDIFF(now, lastblink);
if (timeout <= 0) {
if (-timeout > blinktimeout) /* start visible */
- win.mode |= MODE_BLINK;
- win.mode ^= MODE_BLINK;
- tsetdirtattr(ATTR_BLINK);
+ win.mode |= Wblink;
+ win.mode ^= Wblink;
+ tsetdirtattr(Gblink);
lastblink = now;
timeout = blinktimeout;
}