Moves the mode bits used by x.c from Term to TermWindow, absorbing
UI/input-related mode bits (visible/focused/numlock) along the way.
This is gradually reducing external references to Term. Since
TermWindow is already internal to x.c, we add xsetmode() to allow st to
modify window bits in accordance with escape sequences.
IS_SET() is redefined accordingly (term.mode in st.c, win.mode in x.c).
Signed-off-by: Devin J. Pohly <[email protected]>
#define STR_ARG_SIZ ESC_ARG_SIZ
/* macros */
#define STR_ARG_SIZ ESC_ARG_SIZ
/* macros */
+#define IS_SET(flag) ((term.mode & (flag)) != 0)
#define NUMMAXLEN(x) ((int)(sizeof(x) * 2.56 + 0.5) + 1)
#define ISCONTROLC0(c) (BETWEEN(c, 0, 0x1f) || (c) == '\177')
#define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f))
#define NUMMAXLEN(x) ((int)(sizeof(x) * 2.56 + 0.5) + 1)
#define ISCONTROLC0(c) (BETWEEN(c, 0, 0x1f) || (c) == '\177')
#define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f))
/* constants */
#define ISO14755CMD "dmenu -w \"$WINDOWID\" -p codepoint: </dev/null"
/* constants */
#define ISO14755CMD "dmenu -w \"$WINDOWID\" -p codepoint: </dev/null"
+enum term_mode {
+ MODE_WRAP = 1 << 0,
+ MODE_INSERT = 1 << 1,
+ MODE_ALTSCREEN = 1 << 2,
+ MODE_CRLF = 1 << 3,
+ MODE_ECHO = 1 << 4,
+ MODE_PRINT = 1 << 5,
+ MODE_UTF8 = 1 << 6,
+ MODE_SIXEL = 1 << 7,
+};
+
enum cursor_movement {
CURSOR_SAVE,
CURSOR_LOAD
enum cursor_movement {
CURSOR_SAVE,
CURSOR_LOAD
{
term = (Term){ .c = { .attr = { .fg = defaultfg, .bg = defaultbg } } };
tresize(col, row);
{
term = (Term){ .c = { .attr = { .fg = defaultfg, .bg = defaultbg } } };
tresize(col, row);
void
tsetmode(int priv, int set, int *args, int narg)
{
void
tsetmode(int priv, int set, int *args, int narg)
{
- int *lim, mode;
- int alt;
for (lim = args + narg; args < lim; ++args) {
if (priv) {
switch (*args) {
case 1: /* DECCKM -- Cursor key */
for (lim = args + narg; args < lim; ++args) {
if (priv) {
switch (*args) {
case 1: /* DECCKM -- Cursor key */
- MODBIT(term.mode, set, MODE_APPCURSOR);
+ xsetmode(set, MODE_APPCURSOR);
break;
case 5: /* DECSCNM -- Reverse video */
break;
case 5: /* DECSCNM -- Reverse video */
- mode = term.mode;
- MODBIT(term.mode, set, MODE_REVERSE);
- if (mode != term.mode)
- redraw();
+ xsetmode(set, MODE_REVERSE);
break;
case 6: /* DECOM -- Origin */
MODBIT(term.c.state, set, CURSOR_ORIGIN);
break;
case 6: /* DECOM -- Origin */
MODBIT(term.c.state, set, CURSOR_ORIGIN);
case 12: /* att610 -- Start blinking cursor (IGNORED) */
break;
case 25: /* DECTCEM -- Text Cursor Enable Mode */
case 12: /* att610 -- Start blinking cursor (IGNORED) */
break;
case 25: /* DECTCEM -- Text Cursor Enable Mode */
- MODBIT(term.mode, !set, MODE_HIDE);
+ xsetmode(!set, MODE_HIDE);
break;
case 9: /* X10 mouse compatibility mode */
xsetpointermotion(0);
break;
case 9: /* X10 mouse compatibility mode */
xsetpointermotion(0);
- MODBIT(term.mode, 0, MODE_MOUSE);
- MODBIT(term.mode, set, MODE_MOUSEX10);
+ xsetmode(0, MODE_MOUSE);
+ xsetmode(set, MODE_MOUSEX10);
break;
case 1000: /* 1000: report button press */
xsetpointermotion(0);
break;
case 1000: /* 1000: report button press */
xsetpointermotion(0);
- MODBIT(term.mode, 0, MODE_MOUSE);
- MODBIT(term.mode, set, MODE_MOUSEBTN);
+ xsetmode(0, MODE_MOUSE);
+ xsetmode(set, MODE_MOUSEBTN);
break;
case 1002: /* 1002: report motion on button press */
xsetpointermotion(0);
break;
case 1002: /* 1002: report motion on button press */
xsetpointermotion(0);
- MODBIT(term.mode, 0, MODE_MOUSE);
- MODBIT(term.mode, set, MODE_MOUSEMOTION);
+ xsetmode(0, MODE_MOUSE);
+ xsetmode(set, MODE_MOUSEMOTION);
break;
case 1003: /* 1003: enable all mouse motions */
xsetpointermotion(set);
break;
case 1003: /* 1003: enable all mouse motions */
xsetpointermotion(set);
- MODBIT(term.mode, 0, MODE_MOUSE);
- MODBIT(term.mode, set, MODE_MOUSEMANY);
+ xsetmode(0, MODE_MOUSE);
+ xsetmode(set, MODE_MOUSEMANY);
break;
case 1004: /* 1004: send focus events to tty */
break;
case 1004: /* 1004: send focus events to tty */
- MODBIT(term.mode, set, MODE_FOCUS);
+ xsetmode(set, MODE_FOCUS);
break;
case 1006: /* 1006: extended reporting mode */
break;
case 1006: /* 1006: extended reporting mode */
- MODBIT(term.mode, set, MODE_MOUSESGR);
+ xsetmode(set, MODE_MOUSESGR);
- MODBIT(term.mode, set, MODE_8BIT);
+ xsetmode(set, MODE_8BIT);
break;
case 1049: /* swap screen & set/restore cursor as xterm */
if (!allowaltscreen)
break;
case 1049: /* swap screen & set/restore cursor as xterm */
if (!allowaltscreen)
tcursor((set) ? CURSOR_SAVE : CURSOR_LOAD);
break;
case 2004: /* 2004: bracketed paste mode */
tcursor((set) ? CURSOR_SAVE : CURSOR_LOAD);
break;
case 2004: /* 2004: bracketed paste mode */
- MODBIT(term.mode, set, MODE_BRCKTPASTE);
+ xsetmode(set, MODE_BRCKTPASTE);
break;
/* Not implemented mouse modes. See comments there. */
case 1001: /* mouse highlight mode; can hang the
break;
/* Not implemented mouse modes. See comments there. */
case 1001: /* mouse highlight mode; can hang the
switch (*args) {
case 0: /* Error (IGNORED) */
break;
switch (*args) {
case 0: /* Error (IGNORED) */
break;
- case 2: /* KAM -- keyboard action */
- MODBIT(term.mode, set, MODE_KBDLOCK);
+ case 2:
+ xsetmode(set, MODE_KBDLOCK);
break;
case 4: /* IRM -- Insertion-replacement */
MODBIT(term.mode, set, MODE_INSERT);
break;
case 4: /* IRM -- Insertion-replacement */
MODBIT(term.mode, set, MODE_INSERT);
xloadcols();
break;
case '=': /* DECPAM -- Application keypad */
xloadcols();
break;
case '=': /* DECPAM -- Application keypad */
- term.mode |= MODE_APPKEYPAD;
+ xsetmode(1, MODE_APPKEYPAD);
break;
case '>': /* DECPNM -- Normal keypad */
break;
case '>': /* DECPNM -- Normal keypad */
- term.mode &= ~MODE_APPKEYPAD;
+ xsetmode(0, MODE_APPKEYPAD);
break;
case '7': /* DECSC -- Save Cursor */
tcursor(CURSOR_SAVE);
break;
case '7': /* DECSC -- Save Cursor */
tcursor(CURSOR_SAVE);
-
-void
-numlock(const Arg *dummy)
-{
- term.numlock ^= 1;
-}
#define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
#define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || \
(a).bg != (b).bg)
#define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
#define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || \
(a).bg != (b).bg)
-#define IS_SET(flag) ((term.mode & (flag)) != 0)
#define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + \
(t1.tv_nsec-t2.tv_nsec)/1E6)
#define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit)))
#define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + \
(t1.tv_nsec-t2.tv_nsec)/1E6)
#define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit)))
ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
};
ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
};
-enum term_mode {
- MODE_WRAP = 1 << 0,
- MODE_INSERT = 1 << 1,
- MODE_APPKEYPAD = 1 << 2,
- MODE_ALTSCREEN = 1 << 3,
- MODE_CRLF = 1 << 4,
- MODE_MOUSEBTN = 1 << 5,
- MODE_MOUSEMOTION = 1 << 6,
- MODE_REVERSE = 1 << 7,
- MODE_KBDLOCK = 1 << 8,
- MODE_HIDE = 1 << 9,
- MODE_ECHO = 1 << 10,
- MODE_APPCURSOR = 1 << 11,
- MODE_MOUSESGR = 1 << 12,
- MODE_8BIT = 1 << 13,
- MODE_BLINK = 1 << 14,
- MODE_FBLINK = 1 << 15,
- MODE_FOCUS = 1 << 16,
- MODE_MOUSEX10 = 1 << 17,
- MODE_MOUSEMANY = 1 << 18,
- MODE_BRCKTPASTE = 1 << 19,
- MODE_PRINT = 1 << 20,
- MODE_UTF8 = 1 << 21,
- MODE_SIXEL = 1 << 22,
- MODE_MOUSE = MODE_MOUSEBTN|MODE_MOUSEMOTION|MODE_MOUSEX10\
- |MODE_MOUSEMANY,
-};
-
enum selection_mode {
SEL_IDLE = 0,
SEL_EMPTY = 1,
enum selection_mode {
SEL_IDLE = 0,
SEL_EMPTY = 1,
char trantbl[4]; /* charset table translation */
int charset; /* current charset */
int icharset; /* selected charset for sequence */
char trantbl[4]; /* charset table translation */
int charset; /* current charset */
int icharset; /* selected charset for sequence */
- int numlock; /* lock numbers in keyboard */
int w, h; /* window width and height */
int ch; /* char height */
int cw; /* char width */
int w, h; /* window width and height */
int ch; /* char height */
int cw; /* char width */
- char state; /* focus, redraw, visible */
+ int mode; /* window state/mode flags */
int cursor; /* cursor style */
} TermWindow;
int cursor; /* cursor style */
} TermWindow;
void redraw(void);
void iso14755(const Arg *);
void redraw(void);
void iso14755(const Arg *);
-void numlock(const Arg *);
void printscreen(const Arg *);
void printsel(const Arg *);
void sendbreak(const Arg *);
void printscreen(const Arg *);
void printsel(const Arg *);
void sendbreak(const Arg *);
/* See LICENSE for license details. */
/* See LICENSE for license details. */
+enum win_mode {
+ MODE_VISIBLE = 1 << 0,
+ MODE_FOCUSED = 1 << 1,
+ MODE_APPKEYPAD = 1 << 2,
+ MODE_MOUSEBTN = 1 << 3,
+ MODE_MOUSEMOTION = 1 << 4,
+ MODE_REVERSE = 1 << 5,
+ MODE_KBDLOCK = 1 << 6,
+ MODE_HIDE = 1 << 7,
+ MODE_APPCURSOR = 1 << 8,
+ MODE_MOUSESGR = 1 << 9,
+ MODE_8BIT = 1 << 10,
+ MODE_BLINK = 1 << 11,
+ MODE_FBLINK = 1 << 12,
+ MODE_FOCUS = 1 << 13,
+ MODE_MOUSEX10 = 1 << 14,
+ MODE_MOUSEMANY = 1 << 15,
+ MODE_BRCKTPASTE = 1 << 16,
+ MODE_NUMLOCK = 1 << 17,
+ MODE_MOUSE = MODE_MOUSEBTN|MODE_MOUSEMOTION|MODE_MOUSEX10\
+ |MODE_MOUSEMANY,
+};
+
void draw(void);
void drawregion(int, int, int, int);
void draw(void);
void drawregion(int, int, int, int);
int xsetcolorname(int, const char *);
void xsettitle(char *);
int xsetcursor(int);
int xsetcolorname(int, const char *);
void xsettitle(char *);
int xsetcursor(int);
+void xsetmode(int, unsigned int);
void xsetpointermotion(int);
void xsetsel(char *);
void xsetpointermotion(int);
void xsetsel(char *);
/* function definitions used in config.h */
static void clipcopy(const Arg *);
static void clippaste(const Arg *);
/* function definitions used in config.h */
static void clipcopy(const Arg *);
static void clippaste(const Arg *);
+static void numlock(const Arg *);
static void selpaste(const Arg *);
static void zoom(const Arg *);
static void zoomabs(const Arg *);
static void selpaste(const Arg *);
static void zoom(const Arg *);
static void zoomabs(const Arg *);
#define XEMBED_FOCUS_OUT 5
/* macros */
#define XEMBED_FOCUS_OUT 5
/* macros */
+#define IS_SET(flag) ((win.mode & (flag)) != 0)
#define TRUERED(x) (((x) & 0xff0000) >> 8)
#define TRUEGREEN(x) (((x) & 0xff00))
#define TRUEBLUE(x) (((x) & 0xff) << 8)
#define TRUERED(x) (((x) & 0xff0000) >> 8)
#define TRUEGREEN(x) (((x) & 0xff00))
#define TRUEBLUE(x) (((x) & 0xff) << 8)
static XSelection xsel;
static TermWindow win;
static XSelection xsel;
static TermWindow win;
-enum window_state {
- WIN_VISIBLE = 1,
- WIN_FOCUSED = 2
-};
-
/* Font Ring Cache */
enum {
FRC_NORMAL,
/* Font Ring Cache */
enum {
FRC_NORMAL,
+void
+numlock(const Arg *dummy)
+{
+ win.mode ^= MODE_NUMLOCK;
+}
+
void
zoom(const Arg *arg)
{
void
zoom(const Arg *arg)
{
XChangeProperty(xw.dpy, xw.win, xw.netwmpid, XA_CARDINAL, 32,
PropModeReplace, (uchar *)&thispid, 1);
XChangeProperty(xw.dpy, xw.win, xw.netwmpid, XA_CARDINAL, 32,
PropModeReplace, (uchar *)&thispid, 1);
+ win.mode = MODE_NUMLOCK;
resettitle();
XMapWindow(xw.dpy, xw.win);
xhints();
resettitle();
XMapWindow(xw.dpy, xw.win);
xhints();
if (base.mode & ATTR_REVERSE) {
temp = fg;
fg = bg;
bg = temp;
}
if (base.mode & ATTR_REVERSE) {
temp = fg;
fg = bg;
bg = temp;
}
- if (base.mode & ATTR_BLINK && term.mode & MODE_BLINK)
+ if (base.mode & ATTR_BLINK && win.mode & MODE_BLINK)
fg = bg;
if (base.mode & ATTR_INVISIBLE)
fg = bg;
if (base.mode & ATTR_INVISIBLE)
return;
/* draw the new one */
return;
/* draw the new one */
- if (win.state & WIN_FOCUSED) {
+ if (IS_SET(MODE_FOCUSED)) {
switch (win.cursor) {
case 7: /* st extension: snowman */
utf8decode("☃", &g.u, UTF_SIZ);
switch (win.cursor) {
case 7: /* st extension: snowman */
utf8decode("☃", &g.u, UTF_SIZ);
Glyph base, new;
XftGlyphFontSpec *specs;
Glyph base, new;
XftGlyphFontSpec *specs;
- if (!(win.state & WIN_VISIBLE))
+ if (!(IS_SET(MODE_VISIBLE)))
return;
for (y = y1; y < y2; y++) {
return;
for (y = y1; y < y2; y++) {
{
XVisibilityEvent *e = &ev->xvisibility;
{
XVisibilityEvent *e = &ev->xvisibility;
- MODBIT(win.state, e->state != VisibilityFullyObscured, WIN_VISIBLE);
+ MODBIT(win.mode, e->state != VisibilityFullyObscured, MODE_VISIBLE);
}
void
unmap(XEvent *ev)
{
}
void
unmap(XEvent *ev)
{
- win.state &= ~WIN_VISIBLE;
+ win.mode &= ~MODE_VISIBLE;
XChangeWindowAttributes(xw.dpy, xw.win, CWEventMask, &xw.attrs);
}
XChangeWindowAttributes(xw.dpy, xw.win, CWEventMask, &xw.attrs);
}
+void
+xsetmode(int set, unsigned int flags)
+{
+ int mode = win.mode;
+ MODBIT(win.mode, set, flags);
+ if ((win.mode & MODE_REVERSE) != (mode & MODE_REVERSE))
+ redraw();
+}
+
int
xsetcursor(int cursor)
{
int
xsetcursor(int cursor)
{
- if (!(win.state & WIN_FOCUSED))
+ if (!(IS_SET(MODE_FOCUSED)))
xseturgency(1);
if (bellvolume)
XkbBell(xw.dpy, xw.win, bellvolume, (Atom)NULL);
xseturgency(1);
if (bellvolume)
XkbBell(xw.dpy, xw.win, bellvolume, (Atom)NULL);
if (ev->type == FocusIn) {
XSetICFocus(xw.xic);
if (ev->type == FocusIn) {
XSetICFocus(xw.xic);
- win.state |= WIN_FOCUSED;
+ win.mode |= MODE_FOCUSED;
xseturgency(0);
if (IS_SET(MODE_FOCUS))
ttywrite("\033[I", 3, 0);
} else {
XUnsetICFocus(xw.xic);
xseturgency(0);
if (IS_SET(MODE_FOCUS))
ttywrite("\033[I", 3, 0);
} else {
XUnsetICFocus(xw.xic);
- win.state &= ~WIN_FOCUSED;
+ win.mode &= ~MODE_FOCUSED;
if (IS_SET(MODE_FOCUS))
ttywrite("\033[O", 3, 0);
}
if (IS_SET(MODE_FOCUS))
ttywrite("\033[O", 3, 0);
}
if (IS_SET(MODE_APPKEYPAD) ? kp->appkey < 0 : kp->appkey > 0)
continue;
if (IS_SET(MODE_APPKEYPAD) ? kp->appkey < 0 : kp->appkey > 0)
continue;
- if (term.numlock && kp->appkey == 2)
+ if (IS_SET(MODE_NUMLOCK) && kp->appkey == 2)
continue;
if (IS_SET(MODE_APPCURSOR) ? kp->appcursor < 0 : kp->appcursor > 0)
continue;
if (IS_SET(MODE_APPCURSOR) ? kp->appcursor < 0 : kp->appcursor > 0)
*/
if (e->xclient.message_type == xw.xembed && e->xclient.format == 32) {
if (e->xclient.data.l[1] == XEMBED_FOCUS_IN) {
*/
if (e->xclient.message_type == xw.xembed && e->xclient.format == 32) {
if (e->xclient.data.l[1] == XEMBED_FOCUS_IN) {
- win.state |= WIN_FOCUSED;
+ win.mode |= MODE_FOCUSED;
xseturgency(0);
} else if (e->xclient.data.l[1] == XEMBED_FOCUS_OUT) {
xseturgency(0);
} else if (e->xclient.data.l[1] == XEMBED_FOCUS_OUT) {
- win.state &= ~WIN_FOCUSED;
+ win.mode &= ~MODE_FOCUSED;
}
} else if (e->xclient.data.l[0] == xw.wmdeletewin) {
/* Send SIGHUP to shell */
}
} else if (e->xclient.data.l[0] == xw.wmdeletewin) {
/* Send SIGHUP to shell */
if (blinktimeout) {
blinkset = tattrset(ATTR_BLINK);
if (!blinkset)
if (blinktimeout) {
blinkset = tattrset(ATTR_BLINK);
if (!blinkset)
- MODBIT(term.mode, 0, MODE_BLINK);
+ MODBIT(win.mode, 0, MODE_BLINK);
dodraw = 0;
if (blinktimeout && TIMEDIFF(now, lastblink) > blinktimeout) {
tsetdirtattr(ATTR_BLINK);
dodraw = 0;
if (blinktimeout && TIMEDIFF(now, lastblink) > blinktimeout) {
tsetdirtattr(ATTR_BLINK);
- term.mode ^= MODE_BLINK;
+ win.mode ^= MODE_BLINK;
lastblink = now;
dodraw = 1;
}
lastblink = now;
dodraw = 1;
}