1
0
mirror of git://git.suckless.org/st synced 2025-04-20 03:44:46 +01:00

Compare commits

..

No commits in common. "master" and "0.8.2" have entirely different histories.

11 changed files with 388 additions and 741 deletions

110
FAQ
View File

@ -1,7 +1,6 @@
## Why does st not handle utmp entries? ## Why does st not handle utmp entries?
Use the excellent tool of [utmp](https://git.suckless.org/utmp/) for this task. Use the excellent tool of [utmp](http://git.suckless.org/utmp/) for this task.
## Some _random program_ complains that st is unknown/not recognised/unsupported/whatever! ## Some _random program_ complains that st is unknown/not recognised/unsupported/whatever!
@ -9,7 +8,6 @@ It means that st doesnt have any terminfo entry on your system. Chances are
you did not `make install`. If you just want to test it without installing it, you did not `make install`. If you just want to test it without installing it,
you can manually run `tic -sx st.info`. you can manually run `tic -sx st.info`.
## Nothing works, and nothing is said about an unknown terminal! ## Nothing works, and nothing is said about an unknown terminal!
* Some programs just assume theyre running in xterm i.e. they dont rely on * Some programs just assume theyre running in xterm i.e. they dont rely on
@ -17,21 +15,19 @@ you can manually run `tic -sx st.info`.
* Some programs dont complain about the lacking st description and default to * Some programs dont complain about the lacking st description and default to
another terminal. In that case see the question about terminfo. another terminal. In that case see the question about terminfo.
## I get some weird glitches/visual bug on _random program_!
Try launching it with a different TERM: $ TERM=xterm myapp. toe(1) will give
you a list of available terminals, but youll most likely switch between xterm,
st or st-256color. The default value for TERM can be changed in config.h
(TNAME).
## How do I scroll back up? ## How do I scroll back up?
* Using a terminal multiplexer. Using a terminal multiplexer.
* `st -e tmux` using C-b [
* `st -e screen` using C-a ESC
* Using the excellent tool of [scroll](https://git.suckless.org/scroll/).
* Using the scrollback [patch](https://st.suckless.org/patches/scrollback/).
## I would like to have utmp and/or scroll functionality by default
You can add the absolute path of both programs in your config.h file. You only
have to modify the value of utmp and scroll variables.
* `st -e tmux` using C-b [
* `st -e screen` using C-a ESC
## Why doesn't the Del key work in some programs? ## Why doesn't the Del key work in some programs?
@ -88,14 +84,12 @@ If you are using zsh, then read the zsh FAQ
Putting these lines into your .zshrc will fix the problems. Putting these lines into your .zshrc will fix the problems.
## How can I use meta in 8bit mode? ## How can I use meta in 8bit mode?
St supports meta in 8bit mode, but the default terminfo entry doesn't St supports meta in 8bit mode, but the default terminfo entry doesn't
use this capability. If you want it, you have to use the 'st-meta' value use this capability. If you want it, you have to use the 'st-meta' value
in TERM. in TERM.
## I cannot compile st in OpenBSD ## I cannot compile st in OpenBSD
OpenBSD lacks librt, despite it being mandatory in POSIX OpenBSD lacks librt, despite it being mandatory in POSIX
@ -104,14 +98,13 @@ If you want to compile st for OpenBSD you have to remove -lrt from config.mk, an
st will compile without any loss of functionality, because all the functions are st will compile without any loss of functionality, because all the functions are
included in libc on this platform. included in libc on this platform.
## The Backspace Case ## The Backspace Case
St is emulating the Linux way of handling backspace being delete and delete being St is emulating the Linux way of handling backspace being delete and delete being
backspace. backspace.
This is an issue that was discussed in suckless mailing list This is an issue that was discussed in suckless mailing list
<https://lists.suckless.org/dev/1404/20697.html>. Here is why some old grumpy <http://lists.suckless.org/dev/1404/20697.html>. Here is why some old grumpy
terminal users wants its backspace to be how he feels it: terminal users wants its backspace to be how he feels it:
Well, I am going to comment why I want to change the behaviour Well, I am going to comment why I want to change the behaviour
@ -166,88 +159,9 @@ terminal users wants its backspace to be how he feels it:
[1] http://www.ibb.net/~anne/keyboard.html [1] http://www.ibb.net/~anne/keyboard.html
[2] http://www.tldp.org/HOWTO/Keyboard-and-Console-HOWTO-5.html [2] http://www.tldp.org/HOWTO/Keyboard-and-Console-HOWTO-5.html
## But I really want the old grumpy behaviour of my terminal ## But I really want the old grumpy behaviour of my terminal
Apply [1]. Apply [1].
[1] https://st.suckless.org/patches/delkey [1] http://st.suckless.org/patches/delkey
## Why do images not work in st using the w3m image hack?
w3mimg uses a hack that draws an image on top of the terminal emulator Drawable
window. The hack relies on the terminal to use a single buffer to draw its
contents directly.
st uses double-buffered drawing so the image is quickly replaced and may show a
short flicker effect.
Below is a patch example to change st double-buffering to a single Drawable
buffer.
diff --git a/x.c b/x.c
--- a/x.c
+++ b/x.c
@@ -732,10 +732,6 @@ xresize(int col, int row)
win.tw = col * win.cw;
win.th = row * win.ch;
- XFreePixmap(xw.dpy, xw.buf);
- xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
- DefaultDepth(xw.dpy, xw.scr));
- XftDrawChange(xw.draw, xw.buf);
xclear(0, 0, win.w, win.h);
/* resize to new width */
@@ -1148,8 +1144,7 @@ xinit(int cols, int rows)
gcvalues.graphics_exposures = False;
dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures,
&gcvalues);
- xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
- DefaultDepth(xw.dpy, xw.scr));
+ xw.buf = xw.win;
XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel);
XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h);
@@ -1632,8 +1627,6 @@ xdrawline(Line line, int x1, int y1, int x2)
void
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)?
defaultfg : defaultbg].pixel);
## BadLength X error in Xft when trying to render emoji
Xft makes st crash when rendering color emojis with the following error:
"X Error of failed request: BadLength (poly request too large or internal Xlib length error)"
Major opcode of failed request: 139 (RENDER)
Minor opcode of failed request: 20 (RenderAddGlyphs)
Serial number of failed request: 1595
Current serial number in output stream: 1818"
This is a known bug in Xft (not st) which happens on some platforms and
combination of particular fonts and fontconfig settings.
See also:
https://gitlab.freedesktop.org/xorg/lib/libxft/issues/6
https://bugs.freedesktop.org/show_bug.cgi?id=107534
https://bugzilla.redhat.com/show_bug.cgi?id=1498269
The solution is to remove color emoji fonts or disable this in the fontconfig
XML configuration. As an ugly workaround (which may work only on newer
fontconfig versions (FC_COLOR)), the following code can be used to mask color
fonts:
FcPatternAddBool(fcpattern, FC_COLOR, FcFalse);
Please don't bother reporting this bug to st, but notify the upstream Xft
developers about fixing this bug.
As of 2022-09-05 this now seems to be finally fixed in libXft 2.3.5:
https://gitlab.freedesktop.org/xorg/lib/libxft/-/blob/libXft-2.3.5/NEWS

View File

@ -1,6 +1,6 @@
MIT/X Consortium License MIT/X Consortium License
© 2014-2022 Hiltjo Posthuma <hiltjo at codemadness dot org> © 2014-2018 Hiltjo Posthuma <hiltjo at codemadness dot org>
© 2018 Devin J. Pohly <djpohly at gmail dot com> © 2018 Devin J. Pohly <djpohly at gmail dot com>
© 2014-2017 Quentin Rameau <quinq at fifth dot space> © 2014-2017 Quentin Rameau <quinq at fifth dot space>
© 2009-2012 Aurélien APTEL <aurelien dot aptel at gmail dot com> © 2009-2012 Aurélien APTEL <aurelien dot aptel at gmail dot com>

View File

@ -7,7 +7,13 @@ include config.mk
SRC = st.c x.c SRC = st.c x.c
OBJ = $(SRC:.c=.o) OBJ = $(SRC:.c=.o)
all: st all: options st
options:
@echo st build options:
@echo "CFLAGS = $(STCFLAGS)"
@echo "LDFLAGS = $(STLDFLAGS)"
@echo "CC = $(CC)"
config.h: config.h:
cp config.def.h config.h cp config.def.h config.h
@ -48,4 +54,4 @@ uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/st rm -f $(DESTDIR)$(PREFIX)/bin/st
rm -f $(DESTDIR)$(MANPREFIX)/man1/st.1 rm -f $(DESTDIR)$(MANPREFIX)/man1/st.1
.PHONY: all clean dist install uninstall .PHONY: all options clean dist install uninstall

View File

@ -11,15 +11,13 @@ static int borderpx = 2;
/* /*
* What program is execed by st depends of these precedence rules: * What program is execed by st depends of these precedence rules:
* 1: program passed with -e * 1: program passed with -e
* 2: scroll and/or utmp * 2: utmp option
* 3: SHELL environment variable * 3: SHELL environment variable
* 4: value of shell in /etc/passwd * 4: value of shell in /etc/passwd
* 5: value of shell in config.h * 5: value of shell in config.h
*/ */
static char *shell = "/bin/sh"; static char *shell = "/bin/sh";
char *utmp = NULL; char *utmp = NULL;
/* scroll program: to enable use a string like "scroll" */
char *scroll = NULL;
char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400"; char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400";
/* identification sequence returned in DA and DECID */ /* identification sequence returned in DA and DECID */
@ -32,9 +30,9 @@ static float chscale = 1.0;
/* /*
* word delimiter string * word delimiter string
* *
* More advanced example: L" `'\"()[]{}" * More advanced example: " `'\"()[]{}"
*/ */
wchar_t *worddelimiters = L" "; char *worddelimiters = " ";
/* selection timeouts (in milliseconds) */ /* selection timeouts (in milliseconds) */
static unsigned int doubleclicktimeout = 300; static unsigned int doubleclicktimeout = 300;
@ -43,18 +41,9 @@ static unsigned int tripleclicktimeout = 600;
/* alt screens */ /* alt screens */
int allowaltscreen = 1; int allowaltscreen = 1;
/* allow certain non-interactive (insecure) window operations such as: /* frames per second st should at maximum draw to the screen */
setting the clipboard text */ static unsigned int xfps = 120;
int allowwindowops = 0; static unsigned int actionfps = 30;
/*
* draw latency range in ms - from new content/keypress/etc until drawing.
* within this range, st draws when content stops arriving (idle). mostly it's
* near minlatency, but it waits longer for slow updates to avoid partial draw.
* low minlatency will tear/flicker more, as it can "detect" idle too early.
*/
static double minlatency = 2;
static double maxlatency = 33;
/* /*
* blinking timeout (set to 0 to disable blinking) for the terminal blinking * blinking timeout (set to 0 to disable blinking) for the terminal blinking
@ -120,8 +109,6 @@ static const char *colorname[] = {
/* more colors can be added after 255 to use with DefaultXX */ /* more colors can be added after 255 to use with DefaultXX */
"#cccccc", "#cccccc",
"#555555", "#555555",
"gray90", /* default foreground colour */
"black", /* default background colour */
}; };
@ -129,9 +116,9 @@ static const char *colorname[] = {
* Default colors (colorname index) * Default colors (colorname index)
* foreground, background, cursor, reverse cursor * foreground, background, cursor, reverse cursor
*/ */
unsigned int defaultfg = 258; unsigned int defaultfg = 7;
unsigned int defaultbg = 259; unsigned int defaultbg = 0;
unsigned int defaultcs = 256; static unsigned int defaultcs = 256;
static unsigned int defaultrcs = 257; static unsigned int defaultrcs = 257;
/* /*
@ -163,24 +150,14 @@ static unsigned int mousebg = 0;
*/ */
static unsigned int defaultattr = 11; static unsigned int defaultattr = 11;
/*
* Force mouse select/shortcuts while mask is active (when MODE_MOUSE is set).
* Note that if you want to use ShiftMask with selmasks, set this to an other
* modifier, set to 0 to not use it.
*/
static uint forcemousemod = ShiftMask;
/* /*
* Internal mouse shortcuts. * Internal mouse shortcuts.
* Beware that overloading Button1 will disable the selection. * Beware that overloading Button1 will disable the selection.
*/ */
static MouseShortcut mshortcuts[] = { static MouseShortcut mshortcuts[] = {
/* mask button function argument release */ /* button mask string */
{ XK_ANY_MOD, Button2, selpaste, {.i = 0}, 1 }, { Button4, XK_ANY_MOD, "\031" },
{ ShiftMask, Button4, ttysend, {.s = "\033[5;2~"} }, { Button5, XK_ANY_MOD, "\005" },
{ XK_ANY_MOD, Button4, ttysend, {.s = "\031"} },
{ ShiftMask, Button5, ttysend, {.s = "\033[6;2~"} },
{ XK_ANY_MOD, Button5, ttysend, {.s = "\005"} },
}; };
/* Internal keyboard shortcuts. */ /* Internal keyboard shortcuts. */
@ -218,6 +195,10 @@ static Shortcut shortcuts[] = {
* * 0: no value * * 0: no value
* * > 0: cursor application mode enabled * * > 0: cursor application mode enabled
* * < 0: cursor application mode disabled * * < 0: cursor application mode disabled
* crlf value
* * 0: no value
* * > 0: crlf mode is enabled
* * < 0: crlf mode is disabled
* *
* Be careful with the order of the definitions because st searches in * Be careful with the order of the definitions because st searches in
* this table sequentially, so any XK_ANY_MOD must be in the last * this table sequentially, so any XK_ANY_MOD must be in the last
@ -236,6 +217,13 @@ static KeySym mappedkeys[] = { -1 };
*/ */
static uint ignoremod = Mod2Mask|XK_SWITCH_MOD; static uint ignoremod = Mod2Mask|XK_SWITCH_MOD;
/*
* Override mouse-select while mask is active (when MODE_MOUSE is set).
* Note that if you want to use ShiftMask with selmasks, set this to an other
* modifier, set to 0 to not use it.
*/
static uint forceselmod = ShiftMask;
/* /*
* This is the huge key array which defines all compatibility to the Linux * This is the huge key array which defines all compatibility to the Linux
* world. Please decide about changes wisely. * world. Please decide about changes wisely.

View File

@ -1,5 +1,5 @@
# st version # st version
VERSION = 0.9.2 VERSION = 0.8.2
# Customize below to fit your system # Customize below to fit your system
@ -28,9 +28,8 @@ STLDFLAGS = $(LIBS) $(LDFLAGS)
# OpenBSD: # OpenBSD:
#CPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600 -D_BSD_SOURCE #CPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600 -D_BSD_SOURCE
#LIBS = -L$(X11LIB) -lm -lX11 -lutil -lXft \ #LIBS = -L$(X11LIB) -lm -lX11 -lutil -lXft \
# `$(PKG_CONFIG) --libs fontconfig` \ # `pkg-config --libs fontconfig` \
# `$(PKG_CONFIG) --libs freetype2` # `pkg-config --libs freetype2`
#MANPREFIX = ${PREFIX}/man
# compiler and linker # compiler and linker
# CC = c99 # CC = c99

3
st.1
View File

@ -170,8 +170,7 @@ See the LICENSE file for the terms of redistribution.
.SH SEE ALSO .SH SEE ALSO
.BR tabbed (1), .BR tabbed (1),
.BR utmp (1), .BR utmp (1),
.BR stty (1), .BR stty (1)
.BR scroll (1)
.SH BUGS .SH BUGS
See the TODO file in the distribution. See the TODO file in the distribution.

390
st.c
View File

@ -38,10 +38,10 @@
/* macros */ /* macros */
#define IS_SET(flag) ((term.mode & (flag)) != 0) #define IS_SET(flag) ((term.mode & (flag)) != 0)
#define ISCONTROLC0(c) (BETWEEN(c, 0, 0x1f) || (c) == 0x7f) #define ISCONTROLC0(c) (BETWEEN(c, 0, 0x1f) || (c) == '\177')
#define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f)) #define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f))
#define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c)) #define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c))
#define ISDELIM(u) (u && wcschr(worddelimiters, u)) #define ISDELIM(u) (utf8strchr(worddelimiters, u) != NULL)
enum term_mode { enum term_mode {
MODE_WRAP = 1 << 0, MODE_WRAP = 1 << 0,
@ -51,6 +51,7 @@ enum term_mode {
MODE_ECHO = 1 << 4, MODE_ECHO = 1 << 4,
MODE_PRINT = 1 << 5, MODE_PRINT = 1 << 5,
MODE_UTF8 = 1 << 6, MODE_UTF8 = 1 << 6,
MODE_SIXEL = 1 << 7,
}; };
enum cursor_movement { enum cursor_movement {
@ -77,11 +78,12 @@ enum charset {
enum escape_state { enum escape_state {
ESC_START = 1, ESC_START = 1,
ESC_CSI = 2, ESC_CSI = 2,
ESC_STR = 4, /* DCS, OSC, PM, APC */ ESC_STR = 4, /* OSC, PM, APC */
ESC_ALTCHARSET = 8, ESC_ALTCHARSET = 8,
ESC_STR_END = 16, /* a final string was encountered */ ESC_STR_END = 16, /* a final string was encountered */
ESC_TEST = 32, /* Enter in test mode */ ESC_TEST = 32, /* Enter in test mode */
ESC_UTF8 = 64, ESC_UTF8 = 64,
ESC_DCS =128,
}; };
typedef struct { typedef struct {
@ -127,14 +129,13 @@ typedef struct {
int charset; /* current charset */ int charset; /* current charset */
int icharset; /* selected charset for sequence */ int icharset; /* selected charset for sequence */
int *tabs; int *tabs;
Rune lastc; /* last printed char outside of sequence, 0 if control */
} Term; } Term;
/* CSI Escape sequence structs */ /* CSI Escape sequence structs */
/* ESC '[' [[ [<priv>] <arg> [;]] <mode> [<mode>]] */ /* ESC '[' [[ [<priv>] <arg> [;]] <mode> [<mode>]] */
typedef struct { typedef struct {
char buf[ESC_BUF_SIZ]; /* raw string */ char buf[ESC_BUF_SIZ]; /* raw string */
size_t len; /* raw string length */ int len; /* raw string length */
char priv; char priv;
int arg[ESC_ARG_SIZ]; int arg[ESC_ARG_SIZ];
int narg; /* nb of args */ int narg; /* nb of args */
@ -145,9 +146,8 @@ typedef struct {
/* ESC type [[ [<priv>] <arg> [;]] <mode>] ESC '\' */ /* ESC type [[ [<priv>] <arg> [;]] <mode>] ESC '\' */
typedef struct { typedef struct {
char type; /* ESC type ... */ char type; /* ESC type ... */
char *buf; /* allocated raw string */ char buf[STR_BUF_SIZ]; /* raw string */
size_t siz; /* allocation size */ int len; /* raw string length */
size_t len; /* raw string length */
char *args[STR_ARG_SIZ]; char *args[STR_ARG_SIZ];
int narg; /* nb of args */ int narg; /* nb of args */
} STREscape; } STREscape;
@ -161,7 +161,6 @@ static void csidump(void);
static void csihandle(void); static void csihandle(void);
static void csiparse(void); static void csiparse(void);
static void csireset(void); static void csireset(void);
static void osc_color_response(int, int, int);
static int eschandle(uchar); static int eschandle(uchar);
static void strdump(void); static void strdump(void);
static void strhandle(void); static void strhandle(void);
@ -187,18 +186,18 @@ static void tputc(Rune);
static void treset(void); static void treset(void);
static void tscrollup(int, int); static void tscrollup(int, int);
static void tscrolldown(int, int); static void tscrolldown(int, int);
static void tsetattr(const int *, int); static void tsetattr(int *, int);
static void tsetchar(Rune, const Glyph *, int, int); static void tsetchar(Rune, Glyph *, int, int);
static void tsetdirt(int, int); static void tsetdirt(int, int);
static void tsetscroll(int, int); static void tsetscroll(int, int);
static void tswapscreen(void); static void tswapscreen(void);
static void tsetmode(int, int, const int *, int); static void tsetmode(int, int, int *, int);
static int twrite(const char *, int, int); static int twrite(const char *, int, int);
static void tfulldirt(void); static void tfulldirt(void);
static void tcontrolcode(uchar ); static void tcontrolcode(uchar );
static void tdectest(char ); static void tdectest(char );
static void tdefutf8(char); static void tdefutf8(char);
static int32_t tdefcolor(const int *, int *, int); static int32_t tdefcolor(int *, int *, int);
static void tdeftran(char); static void tdeftran(char);
static void tstrsequence(uchar); static void tstrsequence(uchar);
@ -211,6 +210,7 @@ static void selsnap(int *, int *, int);
static size_t utf8decode(const char *, Rune *, size_t); static size_t utf8decode(const char *, Rune *, size_t);
static Rune utf8decodebyte(char, size_t *); static Rune utf8decodebyte(char, size_t *);
static char utf8encodebyte(Rune, size_t); static char utf8encodebyte(Rune, size_t);
static char *utf8strchr(char *, Rune);
static size_t utf8validate(Rune *, size_t); static size_t utf8validate(Rune *, size_t);
static char *base64dec(const char *); static char *base64dec(const char *);
@ -227,10 +227,10 @@ static int iofd = 1;
static int cmdfd; static int cmdfd;
static pid_t pid; static pid_t pid;
static const uchar utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; static uchar utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0};
static const uchar utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; static uchar utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8};
static const Rune utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000}; static Rune utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000};
static const Rune utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; static Rune utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF};
ssize_t ssize_t
xwrite(int fd, const char *s, size_t len) xwrite(int fd, const char *s, size_t len)
@ -270,14 +270,12 @@ xrealloc(void *p, size_t len)
} }
char * char *
xstrdup(const char *s) xstrdup(char *s)
{ {
char *p; if ((s = strdup(s)) == NULL)
if ((p = strdup(s)) == NULL)
die("strdup: %s\n", strerror(errno)); die("strdup: %s\n", strerror(errno));
return p; return s;
} }
size_t size_t
@ -339,6 +337,23 @@ utf8encodebyte(Rune u, size_t i)
return utfbyte[i] | (u & ~utfmask[i]); return utfbyte[i] | (u & ~utfmask[i]);
} }
char *
utf8strchr(char *s, Rune u)
{
Rune r;
size_t i, j, len;
len = strlen(s);
for (i = 0, j = 0; i < len; i += j) {
if (!(j = utf8decode(&s[i], &r, len - i)))
break;
if (r == u)
return &(s[i]);
}
return NULL;
}
size_t size_t
utf8validate(Rune *u, size_t i) utf8validate(Rune *u, size_t i)
{ {
@ -350,12 +365,26 @@ utf8validate(Rune *u, size_t i)
return i; return i;
} }
static const char base64_digits[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0,
63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, -1, 0, 0, 0, 0, 1,
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 0, 0, 0, 0, 0, 0, 26, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
char char
base64dec_getc(const char **src) base64dec_getc(const char **src)
{ {
while (**src && !isprint((unsigned char)**src)) while (**src && !isprint(**src)) (*src)++;
(*src)++; return *((*src)++);
return **src ? *((*src)++) : '='; /* emulate padding if string ends */
} }
char * char *
@ -363,13 +392,6 @@ base64dec(const char *src)
{ {
size_t in_len = strlen(src); size_t in_len = strlen(src);
char *result, *dst; char *result, *dst;
static const char base64_digits[256] = {
[43] = 62, 0, 0, 0, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
0, 0, 0, -1, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0,
0, 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
};
if (in_len % 4) if (in_len % 4)
in_len += 4 - (in_len % 4); in_len += 4 - (in_len % 4);
@ -380,10 +402,6 @@ base64dec(const char *src)
int c = base64_digits[(unsigned char) base64dec_getc(&src)]; int c = base64_digits[(unsigned char) base64dec_getc(&src)];
int d = base64_digits[(unsigned char) base64dec_getc(&src)]; int d = base64_digits[(unsigned char) base64dec_getc(&src)];
/* invalid input. 'a' can be -1, e.g. if src is "\n" (c-str) */
if (a == -1 || b == -1)
break;
*dst++ = (a << 2) | ((b & 0x30) >> 4); *dst++ = (a << 2) | ((b & 0x30) >> 4);
if (c == -1) if (c == -1)
break; break;
@ -458,7 +476,7 @@ selextend(int col, int row, int type, int done)
selnormalize(); selnormalize();
sel.type = type; sel.type = type;
if (oldey != sel.oe.y || oldex != sel.oe.x || oldtype != sel.type || sel.mode == SEL_EMPTY) if (oldey != sel.oe.y || oldex != sel.oe.x || oldtype != sel.type)
tsetdirt(MIN(sel.nb.y, oldsby), MAX(sel.ne.y, oldsey)); tsetdirt(MIN(sel.nb.y, oldsby), MAX(sel.ne.y, oldsey));
sel.mode = done ? SEL_IDLE : SEL_READY; sel.mode = done ? SEL_IDLE : SEL_READY;
@ -513,7 +531,7 @@ selsnap(int *x, int *y, int direction)
{ {
int newx, newy, xt, yt; int newx, newy, xt, yt;
int delim, prevdelim; int delim, prevdelim;
const Glyph *gp, *prevgp; Glyph *gp, *prevgp;
switch (sel.snap) { switch (sel.snap) {
case SNAP_WORD: case SNAP_WORD:
@ -586,7 +604,7 @@ getsel(void)
{ {
char *str, *ptr; char *str, *ptr;
int y, bufsize, lastx, linelen; int y, bufsize, lastx, linelen;
const Glyph *gp, *last; Glyph *gp, *last;
if (sel.ob.x == -1) if (sel.ob.x == -1)
return NULL; return NULL;
@ -628,8 +646,7 @@ getsel(void)
* st. * st.
* FIXME: Fix the computer world. * FIXME: Fix the computer world.
*/ */
if ((y < sel.ne.y || lastx >= linelen) && if ((y < sel.ne.y || lastx >= linelen) && !(last->mode & ATTR_WRAP))
(!(last->mode & ATTR_WRAP) || sel.type == SEL_RECTANGULAR))
*ptr++ = '\n'; *ptr++ = '\n';
} }
*ptr = 0; *ptr = 0;
@ -660,7 +677,7 @@ die(const char *errstr, ...)
void void
execsh(char *cmd, char **args) execsh(char *cmd, char **args)
{ {
char *sh, *prog, *arg; char *sh, *prog;
const struct passwd *pw; const struct passwd *pw;
errno = 0; errno = 0;
@ -674,20 +691,13 @@ execsh(char *cmd, char **args)
if ((sh = getenv("SHELL")) == NULL) if ((sh = getenv("SHELL")) == NULL)
sh = (pw->pw_shell[0]) ? pw->pw_shell : cmd; sh = (pw->pw_shell[0]) ? pw->pw_shell : cmd;
if (args) { if (args)
prog = args[0]; prog = args[0];
arg = NULL; else if (utmp)
} else if (scroll) {
prog = scroll;
arg = utmp ? utmp : sh;
} else if (utmp) {
prog = utmp; prog = utmp;
arg = NULL; else
} else {
prog = sh; prog = sh;
arg = NULL; DEFAULT(args, ((char *[]) {prog, NULL}));
}
DEFAULT(args, ((char *[]) {prog, arg, NULL}));
unsetenv("COLUMNS"); unsetenv("COLUMNS");
unsetenv("LINES"); unsetenv("LINES");
@ -725,7 +735,7 @@ sigchld(int a)
die("child exited with status %d\n", WEXITSTATUS(stat)); die("child exited with status %d\n", WEXITSTATUS(stat));
else if (WIFSIGNALED(stat)) else if (WIFSIGNALED(stat))
die("child terminated due to signal %d\n", WTERMSIG(stat)); die("child terminated due to signal %d\n", WTERMSIG(stat));
_exit(0); exit(0);
} }
void void
@ -753,7 +763,7 @@ stty(char **args)
} }
int int
ttynew(const char *line, char *cmd, const char *out, char **args) ttynew(char *line, char *cmd, char *out, char **args)
{ {
int m, s; int m, s;
@ -786,15 +796,14 @@ ttynew(const char *line, char *cmd, const char *out, char **args)
break; break;
case 0: case 0:
close(iofd); close(iofd);
close(m);
setsid(); /* create a new process group */ setsid(); /* create a new process group */
dup2(s, 0); dup2(s, 0);
dup2(s, 1); dup2(s, 1);
dup2(s, 2); dup2(s, 2);
if (ioctl(s, TIOCSCTTY, NULL) < 0) if (ioctl(s, TIOCSCTTY, NULL) < 0)
die("ioctl TIOCSCTTY failed: %s\n", strerror(errno)); die("ioctl TIOCSCTTY failed: %s\n", strerror(errno));
if (s > 2) close(s);
close(s); close(m);
#ifdef __OpenBSD__ #ifdef __OpenBSD__
if (pledge("stdio getpw proc exec", NULL) == -1) if (pledge("stdio getpw proc exec", NULL) == -1)
die("pledge\n"); die("pledge\n");
@ -819,25 +828,21 @@ ttyread(void)
{ {
static char buf[BUFSIZ]; static char buf[BUFSIZ];
static int buflen = 0; static int buflen = 0;
int ret, written; int written;
int ret;
/* append read bytes to unprocessed bytes */ /* append read bytes to unprocessed bytes */
ret = read(cmdfd, buf+buflen, LEN(buf)-buflen); if ((ret = read(cmdfd, buf+buflen, LEN(buf)-buflen)) < 0)
switch (ret) {
case 0:
exit(0);
case -1:
die("couldn't read from shell: %s\n", strerror(errno)); die("couldn't read from shell: %s\n", strerror(errno));
default: buflen += ret;
buflen += ret;
written = twrite(buf, buflen, 0); written = twrite(buf, buflen, 0);
buflen -= written; buflen -= written;
/* keep any incomplete UTF-8 byte sequence for the next call */ /* keep any uncomplete utf8 char for the next call */
if (buflen > 0) if (buflen > 0)
memmove(buf, buf + written, buflen); memmove(buf, buf + written, buflen);
return ret;
} return ret;
} }
void void
@ -939,7 +944,7 @@ ttyresize(int tw, int th)
} }
void void
ttyhangup(void) ttyhangup()
{ {
/* Send SIGHUP to shell */ /* Send SIGHUP to shell */
kill(pid, SIGHUP); kill(pid, SIGHUP);
@ -1097,20 +1102,30 @@ tscrollup(int orig, int n)
void void
selscroll(int orig, int n) selscroll(int orig, int n)
{ {
if (sel.ob.x == -1 || sel.alt != IS_SET(MODE_ALTSCREEN)) if (sel.ob.x == -1)
return; return;
if (BETWEEN(sel.nb.y, orig, term.bot) != BETWEEN(sel.ne.y, orig, term.bot)) { if (BETWEEN(sel.ob.y, orig, term.bot) || BETWEEN(sel.oe.y, orig, term.bot)) {
selclear(); if ((sel.ob.y += n) > term.bot || (sel.oe.y += n) < term.top) {
} else if (BETWEEN(sel.nb.y, orig, term.bot)) {
sel.ob.y += n;
sel.oe.y += n;
if (sel.ob.y < term.top || sel.ob.y > term.bot ||
sel.oe.y < term.top || sel.oe.y > term.bot) {
selclear(); selclear();
} else { return;
selnormalize();
} }
if (sel.type == SEL_RECTANGULAR) {
if (sel.ob.y < term.top)
sel.ob.y = term.top;
if (sel.oe.y > term.bot)
sel.oe.y = term.bot;
} else {
if (sel.ob.y < term.top) {
sel.ob.y = term.top;
sel.ob.x = 0;
}
if (sel.oe.y > term.bot) {
sel.oe.y = term.bot;
sel.oe.x = term.col;
}
}
selnormalize();
} }
} }
@ -1132,7 +1147,6 @@ csiparse(void)
{ {
char *p = csiescseq.buf, *np; char *p = csiescseq.buf, *np;
long int v; long int v;
int sep = ';'; /* colon or semi-colon, but not both */
csiescseq.narg = 0; csiescseq.narg = 0;
if (*p == '?') { if (*p == '?') {
@ -1150,9 +1164,7 @@ csiparse(void)
v = -1; v = -1;
csiescseq.arg[csiescseq.narg++] = v; csiescseq.arg[csiescseq.narg++] = v;
p = np; p = np;
if (sep == ';' && *p == ':') if (*p != ';' || csiescseq.narg == ESC_ARG_SIZ)
sep = ':'; /* allow override to colon once */
if (*p != sep || csiescseq.narg == ESC_ARG_SIZ)
break; break;
p++; p++;
} }
@ -1185,9 +1197,9 @@ tmoveto(int x, int y)
} }
void void
tsetchar(Rune u, const Glyph *attr, int x, int y) tsetchar(Rune u, Glyph *attr, int x, int y)
{ {
static const char *vt100_0[62] = { /* 0x41 - 0x7e */ static char *vt100_0[62] = { /* 0x41 - 0x7e */
"", "", "", "", "", "", "", /* A - G */ "", "", "", "", "", "", "", /* A - G */
0, 0, 0, 0, 0, 0, 0, 0, /* H - O */ 0, 0, 0, 0, 0, 0, 0, 0, /* H - O */
0, 0, 0, 0, 0, 0, 0, 0, /* P - W */ 0, 0, 0, 0, 0, 0, 0, 0, /* P - W */
@ -1299,7 +1311,7 @@ tdeleteline(int n)
} }
int32_t int32_t
tdefcolor(const int *attr, int *npar, int l) tdefcolor(int *attr, int *npar, int l)
{ {
int32_t idx = -1; int32_t idx = -1;
uint r, g, b; uint r, g, b;
@ -1349,7 +1361,7 @@ tdefcolor(const int *attr, int *npar, int l)
} }
void void
tsetattr(const int *attr, int l) tsetattr(int *attr, int l)
{ {
int i; int i;
int32_t idx; int32_t idx;
@ -1467,9 +1479,9 @@ tsetscroll(int t, int b)
} }
void void
tsetmode(int priv, int set, const int *args, int narg) tsetmode(int priv, int set, int *args, int narg)
{ {
int alt; const int *lim; int alt, *lim;
for (lim = args + narg; args < lim; ++args) { for (lim = args + narg; args < lim; ++args) {
if (priv) { if (priv) {
@ -1563,7 +1575,6 @@ tsetmode(int priv, int set, const int *args, int narg)
case 1015: /* urxvt mangled mouse mode; incompatible case 1015: /* urxvt mangled mouse mode; incompatible
and can be mistaken for other control and can be mistaken for other control
codes. */ codes. */
break;
default: default:
fprintf(stderr, fprintf(stderr,
"erresc: unknown private set/reset mode %d\n", "erresc: unknown private set/reset mode %d\n",
@ -1645,12 +1656,6 @@ csihandle(void)
if (csiescseq.arg[0] == 0) if (csiescseq.arg[0] == 0)
ttywrite(vtiden, strlen(vtiden), 0); ttywrite(vtiden, strlen(vtiden), 0);
break; break;
case 'b': /* REP -- if last char is printable print it <n> more times */
LIMIT(csiescseq.arg[0], 1, 65535);
if (term.lastc)
while (csiescseq.arg[0]-- > 0)
tputc(term.lastc);
break;
case 'C': /* CUF -- Cursor <n> Forward */ case 'C': /* CUF -- Cursor <n> Forward */
case 'a': /* HPR -- Cursor <n> Forward */ case 'a': /* HPR -- Cursor <n> Forward */
DEFAULT(csiescseq.arg[0], 1); DEFAULT(csiescseq.arg[0], 1);
@ -1705,7 +1710,7 @@ csihandle(void)
} }
break; break;
case 1: /* above */ case 1: /* above */
if (term.c.y > 0) if (term.c.y > 1)
tclearregion(0, 0, term.col-1, term.c.y-1); tclearregion(0, 0, term.col-1, term.c.y-1);
tclearregion(0, term.c.y, term.c.x, term.c.y); tclearregion(0, term.c.y, term.c.x, term.c.y);
break; break;
@ -1731,7 +1736,6 @@ csihandle(void)
} }
break; break;
case 'S': /* SU -- Scroll <n> line up */ case 'S': /* SU -- Scroll <n> line up */
if (csiescseq.priv) break;
DEFAULT(csiescseq.arg[0], 1); DEFAULT(csiescseq.arg[0], 1);
tscrollup(term.top, csiescseq.arg[0]); tscrollup(term.top, csiescseq.arg[0]);
break; break;
@ -1773,18 +1777,11 @@ csihandle(void)
case 'm': /* SGR -- Terminal attribute (color) */ case 'm': /* SGR -- Terminal attribute (color) */
tsetattr(csiescseq.arg, csiescseq.narg); tsetattr(csiescseq.arg, csiescseq.narg);
break; break;
case 'n': /* DSR -- Device Status Report */ case 'n': /* DSR Device Status Report (cursor position) */
switch (csiescseq.arg[0]) { if (csiescseq.arg[0] == 6) {
case 5: /* Status Report "OK" `0n` */ len = snprintf(buf, sizeof(buf),"\033[%i;%iR",
ttywrite("\033[0n", sizeof("\033[0n") - 1, 0); term.c.y+1, term.c.x+1);
break;
case 6: /* Report Cursor Position (CPR) "<row>;<column>R" */
len = snprintf(buf, sizeof(buf), "\033[%i;%iR",
term.c.y+1, term.c.x+1);
ttywrite(buf, len, 0); ttywrite(buf, len, 0);
break;
default:
goto unknown;
} }
break; break;
case 'r': /* DECSTBM -- Set Scrolling Region */ case 'r': /* DECSTBM -- Set Scrolling Region */
@ -1801,11 +1798,7 @@ csihandle(void)
tcursor(CURSOR_SAVE); tcursor(CURSOR_SAVE);
break; break;
case 'u': /* DECRC -- Restore cursor position (ANSI.SYS) */ case 'u': /* DECRC -- Restore cursor position (ANSI.SYS) */
if (csiescseq.priv) { tcursor(CURSOR_LOAD);
goto unknown;
} else {
tcursor(CURSOR_LOAD);
}
break; break;
case ' ': case ' ':
switch (csiescseq.mode[1]) { switch (csiescseq.mode[1]) {
@ -1823,7 +1816,7 @@ csihandle(void)
void void
csidump(void) csidump(void)
{ {
size_t i; int i;
uint c; uint c;
fprintf(stderr, "ESC["); fprintf(stderr, "ESC[");
@ -1850,41 +1843,11 @@ csireset(void)
memset(&csiescseq, 0, sizeof(csiescseq)); memset(&csiescseq, 0, sizeof(csiescseq));
} }
void
osc_color_response(int num, int index, int is_osc4)
{
int n;
char buf[32];
unsigned char r, g, b;
if (xgetcolor(is_osc4 ? num : index, &r, &g, &b)) {
fprintf(stderr, "erresc: failed to fetch %s color %d\n",
is_osc4 ? "osc4" : "osc",
is_osc4 ? num : index);
return;
}
n = snprintf(buf, sizeof buf, "\033]%s%d;rgb:%02x%02x/%02x%02x/%02x%02x\007",
is_osc4 ? "4;" : "", num, r, r, g, g, b, b);
if (n < 0 || n >= sizeof(buf)) {
fprintf(stderr, "error: %s while printing %s response\n",
n < 0 ? "snprintf failed" : "truncation occurred",
is_osc4 ? "osc4" : "osc");
} else {
ttywrite(buf, n, 1);
}
}
void void
strhandle(void) strhandle(void)
{ {
char *p = NULL, *dec; char *p = NULL;
int j, narg, par; int j, narg, par;
const struct { int idx; char *str; } osc_table[] = {
{ defaultfg, "foreground" },
{ defaultbg, "background" },
{ defaultcs, "cursor" }
};
term.esc &= ~(ESC_STR_END|ESC_STR); term.esc &= ~(ESC_STR_END|ESC_STR);
strparse(); strparse();
@ -1894,21 +1857,15 @@ strhandle(void)
case ']': /* OSC -- Operating System Command */ case ']': /* OSC -- Operating System Command */
switch (par) { switch (par) {
case 0: case 0:
if (narg > 1) {
xsettitle(strescseq.args[1]);
xseticontitle(strescseq.args[1]);
}
return;
case 1: case 1:
if (narg > 1)
xseticontitle(strescseq.args[1]);
return;
case 2: case 2:
if (narg > 1) if (narg > 1)
xsettitle(strescseq.args[1]); xsettitle(strescseq.args[1]);
return; return;
case 52: case 52:
if (narg > 2 && allowwindowops) { if (narg > 2) {
char *dec;
dec = base64dec(strescseq.args[2]); dec = base64dec(strescseq.args[2]);
if (dec) { if (dec) {
xsetsel(dec); xsetsel(dec);
@ -1918,47 +1875,21 @@ strhandle(void)
} }
} }
return; return;
case 10:
case 11:
case 12:
if (narg < 2)
break;
p = strescseq.args[1];
if ((j = par - 10) < 0 || j >= LEN(osc_table))
break; /* shouldn't be possible */
if (!strcmp(p, "?")) {
osc_color_response(par, osc_table[j].idx, 0);
} else if (xsetcolorname(osc_table[j].idx, p)) {
fprintf(stderr, "erresc: invalid %s color: %s\n",
osc_table[j].str, p);
} else {
tfulldirt();
}
return;
case 4: /* color set */ case 4: /* color set */
if (narg < 3) if (narg < 3)
break; break;
p = strescseq.args[2]; p = strescseq.args[2];
/* FALLTHROUGH */ /* FALLTHROUGH */
case 104: /* color reset */ case 104: /* color reset, here p = NULL */
j = (narg > 1) ? atoi(strescseq.args[1]) : -1; j = (narg > 1) ? atoi(strescseq.args[1]) : -1;
if (xsetcolorname(j, p)) {
if (p && !strcmp(p, "?")) { fprintf(stderr, "erresc: invalid color %s\n", p);
osc_color_response(j, 0, 1);
} else if (xsetcolorname(j, p)) {
if (par == 104 && narg <= 1) {
xloadcols();
return; /* color reset without parameter */
}
fprintf(stderr, "erresc: invalid color j=%d, p=%s\n",
j, p ? p : "(null)");
} else { } else {
/* /*
* TODO if defaultbg color is changed, borders * TODO if defaultbg color is changed, borders
* are dirty * are dirty
*/ */
tfulldirt(); redraw();
} }
return; return;
} }
@ -1967,6 +1898,7 @@ strhandle(void)
xsettitle(strescseq.args[0]); xsettitle(strescseq.args[0]);
return; return;
case 'P': /* DCS -- Device Control String */ case 'P': /* DCS -- Device Control String */
term.mode |= ESC_DCS;
case '_': /* APC -- Application Program Command */ case '_': /* APC -- Application Program Command */
case '^': /* PM -- Privacy Message */ case '^': /* PM -- Privacy Message */
return; return;
@ -2001,7 +1933,7 @@ strparse(void)
void void
strdump(void) strdump(void)
{ {
size_t i; int i;
uint c; uint c;
fprintf(stderr, "ESC%c", strescseq.type); fprintf(stderr, "ESC%c", strescseq.type);
@ -2028,10 +1960,7 @@ strdump(void)
void void
strreset(void) strreset(void)
{ {
strescseq = (STREscape){ memset(&strescseq, 0, sizeof(strescseq));
.buf = xrealloc(strescseq.buf, STR_BUF_SIZ),
.siz = STR_BUF_SIZ,
};
} }
void void
@ -2084,12 +2013,12 @@ void
tdumpline(int n) tdumpline(int n)
{ {
char buf[UTF_SIZ]; char buf[UTF_SIZ];
const Glyph *bp, *end; Glyph *bp, *end;
bp = &term.line[n][0]; bp = &term.line[n][0];
end = &bp[MIN(tlinelen(n), term.col) - 1]; end = &bp[MIN(tlinelen(n), term.col) - 1];
if (bp != end || bp->u != ' ') { if (bp != end || bp->u != ' ') {
for ( ; bp <= end; ++bp) for ( ;bp <= end; ++bp)
tprinter(buf, utf8encode(bp->u, buf)); tprinter(buf, utf8encode(bp->u, buf));
} }
tprinter("\n", 1); tprinter("\n", 1);
@ -2160,9 +2089,12 @@ tdectest(char c)
void void
tstrsequence(uchar c) tstrsequence(uchar c)
{ {
strreset();
switch (c) { switch (c) {
case 0x90: /* DCS -- Device Control String */ case 0x90: /* DCS -- Device Control String */
c = 'P'; c = 'P';
term.esc |= ESC_DCS;
break; break;
case 0x9f: /* APC -- Application Program Command */ case 0x9f: /* APC -- Application Program Command */
c = '_'; c = '_';
@ -2174,7 +2106,6 @@ tstrsequence(uchar c)
c = ']'; c = ']';
break; break;
} }
strreset();
strescseq.type = c; strescseq.type = c;
term.esc |= ESC_STR; term.esc |= ESC_STR;
} }
@ -2217,7 +2148,6 @@ tcontrolcode(uchar ascii)
return; return;
case '\032': /* SUB */ case '\032': /* SUB */
tsetchar('?', &term.c.attr, term.c.x, term.c.y); tsetchar('?', &term.c.attr, term.c.x, term.c.y);
/* FALLTHROUGH */
case '\030': /* CAN */ case '\030': /* CAN */
csireset(); csireset();
break; break;
@ -2338,7 +2268,6 @@ eschandle(uchar ascii)
treset(); treset();
resettitle(); resettitle();
xloadcols(); xloadcols();
xsetmode(0, MODE_HIDE);
break; break;
case '=': /* DECPAM -- Application keypad */ case '=': /* DECPAM -- Application keypad */
xsetmode(1, MODE_APPKEYPAD); xsetmode(1, MODE_APPKEYPAD);
@ -2373,13 +2302,15 @@ tputc(Rune u)
Glyph *gp; Glyph *gp;
control = ISCONTROL(u); control = ISCONTROL(u);
if (u < 127 || !IS_SET(MODE_UTF8)) { if (!IS_SET(MODE_UTF8) && !IS_SET(MODE_SIXEL)) {
c[0] = u; c[0] = u;
width = len = 1; width = len = 1;
} else { } else {
len = utf8encode(u, c); len = utf8encode(u, c);
if (!control && (width = wcwidth(u)) == -1) if (!control && (width = wcwidth(u)) == -1) {
memcpy(c, "\357\277\275", 4); /* UTF_INVALID */
width = 1; width = 1;
}
} }
if (IS_SET(MODE_PRINT)) if (IS_SET(MODE_PRINT))
@ -2394,12 +2325,25 @@ tputc(Rune u)
if (term.esc & ESC_STR) { if (term.esc & ESC_STR) {
if (u == '\a' || u == 030 || u == 032 || u == 033 || if (u == '\a' || u == 030 || u == 032 || u == 033 ||
ISCONTROLC1(u)) { ISCONTROLC1(u)) {
term.esc &= ~(ESC_START|ESC_STR); term.esc &= ~(ESC_START|ESC_STR|ESC_DCS);
if (IS_SET(MODE_SIXEL)) {
/* TODO: render sixel */;
term.mode &= ~MODE_SIXEL;
return;
}
term.esc |= ESC_STR_END; term.esc |= ESC_STR_END;
goto check_control_code; goto check_control_code;
} }
if (strescseq.len+len >= strescseq.siz) {
if (IS_SET(MODE_SIXEL)) {
/* TODO: implement sixel mode */
return;
}
if (term.esc&ESC_DCS && strescseq.len == 0 && u == 'q')
term.mode |= MODE_SIXEL;
if (strescseq.len+len >= sizeof(strescseq.buf)-1) {
/* /*
* Here is a bug in terminals. If the user never sends * Here is a bug in terminals. If the user never sends
* some code to stop the str or esc command, then st * some code to stop the str or esc command, then st
@ -2413,10 +2357,7 @@ tputc(Rune u)
* term.esc = 0; * term.esc = 0;
* strhandle(); * strhandle();
*/ */
if (strescseq.siz > (SIZE_MAX - UTF_SIZ) / 2) return;
return;
strescseq.siz *= 2;
strescseq.buf = xrealloc(strescseq.buf, strescseq.siz);
} }
memmove(&strescseq.buf[strescseq.len], c, len); memmove(&strescseq.buf[strescseq.len], c, len);
@ -2431,15 +2372,10 @@ check_control_code:
* they must not cause conflicts with sequences. * they must not cause conflicts with sequences.
*/ */
if (control) { if (control) {
/* in UTF-8 mode ignore handling C1 control characters */
if (IS_SET(MODE_UTF8) && ISCONTROLC1(u))
return;
tcontrolcode(u); tcontrolcode(u);
/* /*
* control codes are not shown ever * control codes are not shown ever
*/ */
if (!term.esc)
term.lastc = 0;
return; return;
} else if (term.esc & ESC_START) { } else if (term.esc & ESC_START) {
if (term.esc & ESC_CSI) { if (term.esc & ESC_CSI) {
@ -2470,7 +2406,7 @@ check_control_code:
*/ */
return; return;
} }
if (selected(term.c.x, term.c.y)) if (sel.ob.x != -1 && BETWEEN(term.c.y, sel.ob.y, sel.oe.y))
selclear(); selclear();
gp = &term.line[term.c.y][term.c.x]; gp = &term.line[term.c.y][term.c.x];
@ -2480,29 +2416,19 @@ check_control_code:
gp = &term.line[term.c.y][term.c.x]; gp = &term.line[term.c.y][term.c.x];
} }
if (IS_SET(MODE_INSERT) && term.c.x+width < term.col) { if (IS_SET(MODE_INSERT) && term.c.x+width < term.col)
memmove(gp+width, gp, (term.col - term.c.x - width) * sizeof(Glyph)); memmove(gp+width, gp, (term.col - term.c.x - width) * sizeof(Glyph));
gp->mode &= ~ATTR_WIDE;
}
if (term.c.x+width > term.col) { if (term.c.x+width > term.col) {
if (IS_SET(MODE_WRAP)) tnewline(1);
tnewline(1);
else
tmoveto(term.col - width, term.c.y);
gp = &term.line[term.c.y][term.c.x]; gp = &term.line[term.c.y][term.c.x];
} }
tsetchar(u, &term.c.attr, term.c.x, term.c.y); tsetchar(u, &term.c.attr, term.c.x, term.c.y);
term.lastc = u;
if (width == 2) { if (width == 2) {
gp->mode |= ATTR_WIDE; gp->mode |= ATTR_WIDE;
if (term.c.x+1 < term.col) { if (term.c.x+1 < term.col) {
if (gp[1].mode == ATTR_WIDE && term.c.x+2 < term.col) {
gp[2].u = ' ';
gp[2].mode &= ~ATTR_WDUMMY;
}
gp[1].u = '\0'; gp[1].u = '\0';
gp[1].mode = ATTR_WDUMMY; gp[1].mode = ATTR_WDUMMY;
} }
@ -2522,7 +2448,7 @@ twrite(const char *buf, int buflen, int show_ctrl)
int n; int n;
for (n = 0; n < buflen; n += charsize) { for (n = 0; n < buflen; n += charsize) {
if (IS_SET(MODE_UTF8)) { if (IS_SET(MODE_UTF8) && !IS_SET(MODE_SIXEL)) {
/* process a complete utf8 char */ /* process a complete utf8 char */
charsize = utf8decode(buf + n, &u, buflen - n); charsize = utf8decode(buf + n, &u, buflen - n);
if (charsize == 0) if (charsize == 0)
@ -2638,7 +2564,6 @@ void
drawregion(int x1, int y1, int x2, int y2) drawregion(int x1, int y1, int x2, int y2)
{ {
int y; int y;
for (y = y1; y < y2; y++) { for (y = y1; y < y2; y++) {
if (!term.dirty[y]) if (!term.dirty[y])
continue; continue;
@ -2651,7 +2576,7 @@ drawregion(int x1, int y1, int x2, int y2)
void void
draw(void) draw(void)
{ {
int cx = term.c.x, ocx = term.ocx, ocy = term.ocy; int cx = term.c.x;
if (!xstartdraw()) if (!xstartdraw())
return; return;
@ -2667,11 +2592,8 @@ draw(void)
drawregion(0, 0, term.col, term.row); drawregion(0, 0, term.col, term.row);
xdrawcursor(cx, term.c.y, term.line[term.c.y][cx], xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
term.ocx, term.ocy, term.line[term.ocy][term.ocx]); term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
term.ocx = cx; term.ocx = cx, term.ocy = term.c.y;
term.ocy = term.c.y;
xfinishdraw(); xfinishdraw();
if (ocx != term.ocx || ocy != term.ocy)
xximspot(term.ocx, term.ocy);
} }
void void

10
st.h
View File

@ -74,7 +74,6 @@ typedef union {
uint ui; uint ui;
float f; float f;
const void *v; const void *v;
const char *s;
} Arg; } Arg;
void die(const char *, ...); void die(const char *, ...);
@ -91,7 +90,7 @@ void tnew(int, int);
void tresize(int, int); void tresize(int, int);
void tsetdirtattr(int); void tsetdirtattr(int);
void ttyhangup(void); void ttyhangup(void);
int ttynew(const char *, char *, const char *, char **); int ttynew(char *, char *, char *, char **);
size_t ttyread(void); size_t ttyread(void);
void ttyresize(int, int); void ttyresize(int, int);
void ttywrite(const char *, size_t, int); void ttywrite(const char *, size_t, int);
@ -109,18 +108,15 @@ size_t utf8encode(Rune, char *);
void *xmalloc(size_t); void *xmalloc(size_t);
void *xrealloc(void *, size_t); void *xrealloc(void *, size_t);
char *xstrdup(const char *); char *xstrdup(char *);
/* config.h globals */ /* config.h globals */
extern char *utmp; extern char *utmp;
extern char *scroll;
extern char *stty_args; extern char *stty_args;
extern char *vtiden; extern char *vtiden;
extern wchar_t *worddelimiters; extern char *worddelimiters;
extern int allowaltscreen; extern int allowaltscreen;
extern int allowwindowops;
extern char *termname; extern char *termname;
extern unsigned int tabspaces; extern unsigned int tabspaces;
extern unsigned int defaultfg; extern unsigned int defaultfg;
extern unsigned int defaultbg; extern unsigned int defaultbg;
extern unsigned int defaultcs;

41
st.info
View File

@ -1,4 +1,4 @@
st-mono| simpleterm monocolor, st| simpleterm,
acsc=+C\,D-A.B0E``aaffgghFiGjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~, acsc=+C\,D-A.B0E``aaffgghFiGjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~,
am, am,
bce, bce,
@ -10,7 +10,7 @@ st-mono| simpleterm monocolor,
civis=\E[?25l, civis=\E[?25l,
clear=\E[H\E[2J, clear=\E[H\E[2J,
cnorm=\E[?12l\E[?25h, cnorm=\E[?12l\E[?25h,
colors#2, colors#8,
cols#80, cols#80,
cr=^M, cr=^M,
csr=\E[%i%p1%d;%p2%dr, csr=\E[%i%p1%d;%p2%dr,
@ -158,7 +158,6 @@ st-mono| simpleterm monocolor,
rc=\E8, rc=\E8,
rev=\E[7m, rev=\E[7m,
ri=\EM, ri=\EM,
rin=\E[%p1%dT,
ritm=\E[23m, ritm=\E[23m,
rmacs=\E(B, rmacs=\E(B,
rmcup=\E[?1049l, rmcup=\E[?1049l,
@ -169,8 +168,13 @@ st-mono| simpleterm monocolor,
rs1=\Ec, rs1=\Ec,
rs2=\E[4l\E>\E[?1034l, rs2=\E[4l\E>\E[?1034l,
sc=\E7, sc=\E7,
sitm=\E[3m, setab=\E[4%p1%dm,
setaf=\E[3%p1%dm,
setb=\E[4%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m,
setf=\E[3%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m,
sgr0=\E[0m, sgr0=\E[0m,
sgr=%?%p9%t\E(0%e\E(B%;\E[0%?%p6%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;%?%p7%t;8%;m,
sitm=\E[3m,
smacs=\E(0, smacs=\E(0,
smcup=\E[?1049h, smcup=\E[?1049h,
smir=\E[4h, smir=\E[4h,
@ -184,26 +188,11 @@ st-mono| simpleterm monocolor,
# XTerm extensions # XTerm extensions
rmxx=\E[29m, rmxx=\E[29m,
smxx=\E[9m, smxx=\E[9m,
BE=\E[?2004h,
BD=\E[?2004l,
PS=\E[200~,
PE=\E[201~,
# disabled rep for now: causes some issues with older ncurses versions.
# rep=%p1%c\E[%p2%{1}%-%db,
# tmux extensions, see TERMINFO EXTENSIONS in tmux(1) # tmux extensions, see TERMINFO EXTENSIONS in tmux(1)
Se,
Ss,
Tc, Tc,
Ms=\E]52;%p1%s;%p2%s\007, Ms=\E]52;%p1%s;%p2%s\007,
Se=\E[2 q,
Ss=\E[%p1%d q,
st| simpleterm,
use=st-mono,
colors#8,
setab=\E[4%p1%dm,
setaf=\E[3%p1%dm,
setb=\E[4%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m,
setf=\E[3%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m,
sgr=%?%p9%t\E(0%e\E(B%;\E[0%?%p6%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;%?%p7%t;8%;m,
st-256color| simpleterm with 256 colors, st-256color| simpleterm with 256 colors,
use=st, use=st,
@ -231,13 +220,3 @@ st-meta-256color| simpleterm with meta key and 256 colors,
smm=\E[?1034h, smm=\E[?1034h,
rs2=\E[4l\E>\E[?1034h, rs2=\E[4l\E>\E[?1034h,
is2=\E[4l\E>\E[?1034h, is2=\E[4l\E>\E[?1034h,
st-bs| simpleterm with backspace as backspace,
use=st,
kbs=\010,
kdch1=\177,
st-bs-256color| simpleterm with backspace as backspace and 256colors,
use=st-256color,
kbs=\010,
kdch1=\177,

3
win.h
View File

@ -30,12 +30,9 @@ void xdrawline(Line, int, int, int);
void xfinishdraw(void); void xfinishdraw(void);
void xloadcols(void); void xloadcols(void);
int xsetcolorname(int, const char *); int xsetcolorname(int, const char *);
int xgetcolor(int, unsigned char *, unsigned char *, unsigned char *);
void xseticontitle(char *);
void xsettitle(char *); void xsettitle(char *);
int xsetcursor(int); int xsetcursor(int);
void xsetmode(int, unsigned int); void xsetmode(int, unsigned int);
void xsetpointermotion(int); void xsetpointermotion(int);
void xsetsel(char *); void xsetsel(char *);
int xstartdraw(void); int xstartdraw(void);
void xximspot(int, int);

495
x.c
View File

@ -15,7 +15,7 @@
#include <X11/Xft/Xft.h> #include <X11/Xft/Xft.h>
#include <X11/XKBlib.h> #include <X11/XKBlib.h>
char *argv0; static char *argv0;
#include "arg.h" #include "arg.h"
#include "st.h" #include "st.h"
#include "win.h" #include "win.h"
@ -29,11 +29,9 @@ typedef struct {
} Shortcut; } Shortcut;
typedef struct { typedef struct {
uint mod; uint b;
uint button; uint mask;
void (*func)(const Arg *); char *s;
const Arg arg;
uint release;
} MouseShortcut; } MouseShortcut;
typedef struct { typedef struct {
@ -48,7 +46,7 @@ typedef struct {
/* X modifiers */ /* X modifiers */
#define XK_ANY_MOD UINT_MAX #define XK_ANY_MOD UINT_MAX
#define XK_NO_MOD 0 #define XK_NO_MOD 0
#define XK_SWITCH_MOD (1<<13|1<<14) #define XK_SWITCH_MOD (1<<13)
/* function definitions used in config.h */ /* function definitions used in config.h */
static void clipcopy(const Arg *); static void clipcopy(const Arg *);
@ -58,7 +56,6 @@ static void selpaste(const Arg *);
static void zoom(const Arg *); static void zoom(const Arg *);
static void zoomabs(const Arg *); static void zoomabs(const Arg *);
static void zoomreset(const Arg *); static void zoomreset(const Arg *);
static void ttysend(const Arg *);
/* config.h for applying patches and the configuration. */ /* config.h for applying patches and the configuration. */
#include "config.h" #include "config.h"
@ -93,13 +90,9 @@ typedef struct {
Window win; Window win;
Drawable buf; Drawable buf;
GlyphFontSpec *specbuf; /* font spec buffer used for rendering */ GlyphFontSpec *specbuf; /* font spec buffer used for rendering */
Atom xembed, wmdeletewin, netwmname, netwmiconname, netwmpid; Atom xembed, wmdeletewin, netwmname, netwmpid;
struct { XIM xim;
XIM xim; XIC xic;
XIC xic;
XPoint spot;
XVaNestedList spotlist;
} ime;
Draw draw; Draw draw;
Visual *vis; Visual *vis;
XSetWindowAttributes attrs; XSetWindowAttributes attrs;
@ -146,17 +139,13 @@ static void xdrawglyphfontspecs(const XftGlyphFontSpec *, Glyph, int, int, int);
static void xdrawglyph(Glyph, int, int); static void xdrawglyph(Glyph, int, int);
static void xclear(int, int, int, int); static void xclear(int, int, int, int);
static int xgeommasktogravity(int); static int xgeommasktogravity(int);
static int ximopen(Display *);
static void ximinstantiate(Display *, XPointer, XPointer);
static void ximdestroy(XIM, XPointer, XPointer);
static int xicdestroy(XIC, XPointer, XPointer);
static void xinit(int, int); static void xinit(int, int);
static void cresize(int, int); static void cresize(int, int);
static void xresize(int, int); static void xresize(int, int);
static void xhints(void); static void xhints(void);
static int xloadcolor(int, const char *, Color *); static int xloadcolor(int, const char *, Color *);
static int xloadfont(Font *, FcPattern *); static int xloadfont(Font *, FcPattern *);
static void xloadfonts(const char *, double); static void xloadfonts(char *, double);
static void xunloadfont(Font *); static void xunloadfont(Font *);
static void xunloadfonts(void); static void xunloadfonts(void);
static void xsetenv(void); static void xsetenv(void);
@ -171,8 +160,6 @@ static void kpress(XEvent *);
static void cmessage(XEvent *); static void cmessage(XEvent *);
static void resize(XEvent *); static void resize(XEvent *);
static void focus(XEvent *); static void focus(XEvent *);
static uint buttonmask(uint);
static int mouseaction(XEvent *, uint);
static void brelease(XEvent *); static void brelease(XEvent *);
static void bpress(XEvent *); static void bpress(XEvent *);
static void bmotion(XEvent *); static void bmotion(XEvent *);
@ -236,9 +223,8 @@ typedef struct {
} Fontcache; } Fontcache;
/* Fontcache is an array now. A new font will be appended to the array. */ /* Fontcache is an array now. A new font will be appended to the array. */
static Fontcache *frc = NULL; static Fontcache frc[16];
static int frclen = 0; static int frclen = 0;
static int frccap = 0;
static char *usedfont = NULL; static char *usedfont = NULL;
static double usedfontsize = 0; static double usedfontsize = 0;
static double defaultfontsize = 0; static double defaultfontsize = 0;
@ -252,7 +238,7 @@ static char *opt_line = NULL;
static char *opt_name = NULL; static char *opt_name = NULL;
static char *opt_title = NULL; static char *opt_title = NULL;
static uint buttons; /* bit field of pressed buttons */ static int oldbutton = 3; /* button event on startup: 3 = release */
void void
clipcopy(const Arg *dummy) clipcopy(const Arg *dummy)
@ -322,12 +308,6 @@ zoomreset(const Arg *arg)
} }
} }
void
ttysend(const Arg *arg)
{
ttywrite(arg->s, strlen(arg->s), 1);
}
int int
evcol(XEvent *e) evcol(XEvent *e)
{ {
@ -348,7 +328,7 @@ void
mousesel(XEvent *e, int done) mousesel(XEvent *e, int done)
{ {
int type, seltype = SEL_REGULAR; int type, seltype = SEL_REGULAR;
uint state = e->xbutton.state & ~(Button1Mask | forcemousemod); uint state = e->xbutton.state & ~(Button1Mask | forceselmod);
for (type = 1; type < LEN(selmasks); ++type) { for (type = 1; type < LEN(selmasks); ++type) {
if (match(selmasks[type], state)) { if (match(selmasks[type], state)) {
@ -364,68 +344,59 @@ mousesel(XEvent *e, int done)
void void
mousereport(XEvent *e) mousereport(XEvent *e)
{ {
int len, btn, code; int len, x = evcol(e), y = evrow(e),
int x = evcol(e), y = evrow(e); button = e->xbutton.button, state = e->xbutton.state;
int state = e->xbutton.state;
char buf[40]; char buf[40];
static int ox, oy; static int ox, oy;
if (e->type == MotionNotify) { /* from urxvt */
if (e->xbutton.type == MotionNotify) {
if (x == ox && y == oy) if (x == ox && y == oy)
return; return;
if (!IS_SET(MODE_MOUSEMOTION) && !IS_SET(MODE_MOUSEMANY)) if (!IS_SET(MODE_MOUSEMOTION) && !IS_SET(MODE_MOUSEMANY))
return; return;
/* MODE_MOUSEMOTION: no reporting if no button is pressed */ /* MOUSE_MOTION: no reporting if no button is pressed */
if (IS_SET(MODE_MOUSEMOTION) && buttons == 0) if (IS_SET(MODE_MOUSEMOTION) && oldbutton == 3)
return; return;
/* Set btn to lowest-numbered pressed button, or 12 if no
* buttons are pressed. */ button = oldbutton + 32;
for (btn = 1; btn <= 11 && !(buttons & (1<<(btn-1))); btn++) ox = x;
; oy = y;
code = 32;
} else { } else {
btn = e->xbutton.button; if (!IS_SET(MODE_MOUSESGR) && e->xbutton.type == ButtonRelease) {
/* Only buttons 1 through 11 can be encoded */ button = 3;
if (btn < 1 || btn > 11) } else {
return; button -= Button1;
if (e->type == ButtonRelease) { if (button >= 3)
button += 64 - 3;
}
if (e->xbutton.type == ButtonPress) {
oldbutton = button;
ox = x;
oy = y;
} else if (e->xbutton.type == ButtonRelease) {
oldbutton = 3;
/* MODE_MOUSEX10: no button release reporting */ /* MODE_MOUSEX10: no button release reporting */
if (IS_SET(MODE_MOUSEX10)) if (IS_SET(MODE_MOUSEX10))
return; return;
/* Don't send release events for the scroll wheel */ if (button == 64 || button == 65)
if (btn == 4 || btn == 5)
return; return;
} }
code = 0;
} }
ox = x;
oy = y;
/* Encode btn into code. If no button is pressed for a motion event in
* MODE_MOUSEMANY, then encode it as a release. */
if ((!IS_SET(MODE_MOUSESGR) && e->type == ButtonRelease) || btn == 12)
code += 3;
else if (btn >= 8)
code += 128 + btn - 8;
else if (btn >= 4)
code += 64 + btn - 4;
else
code += btn - 1;
if (!IS_SET(MODE_MOUSEX10)) { if (!IS_SET(MODE_MOUSEX10)) {
code += ((state & ShiftMask ) ? 4 : 0) button += ((state & ShiftMask ) ? 4 : 0)
+ ((state & Mod1Mask ) ? 8 : 0) /* meta key: alt */ + ((state & Mod4Mask ) ? 8 : 0)
+ ((state & ControlMask) ? 16 : 0); + ((state & ControlMask) ? 16 : 0);
} }
if (IS_SET(MODE_MOUSESGR)) { if (IS_SET(MODE_MOUSESGR)) {
len = snprintf(buf, sizeof(buf), "\033[<%d;%d;%d%c", len = snprintf(buf, sizeof(buf), "\033[<%d;%d;%d%c",
code, x+1, y+1, button, x+1, y+1,
e->type == ButtonRelease ? 'm' : 'M'); e->xbutton.type == ButtonRelease ? 'm' : 'M');
} else if (x < 223 && y < 223) { } else if (x < 223 && y < 223) {
len = snprintf(buf, sizeof(buf), "\033[M%c%c%c", len = snprintf(buf, sizeof(buf), "\033[M%c%c%c",
32+code, 32+x+1, 32+y+1); 32+button, 32+x+1, 32+y+1);
} else { } else {
return; return;
} }
@ -433,57 +404,27 @@ mousereport(XEvent *e)
ttywrite(buf, len, 0); ttywrite(buf, len, 0);
} }
uint
buttonmask(uint button)
{
return button == Button1 ? Button1Mask
: button == Button2 ? Button2Mask
: button == Button3 ? Button3Mask
: button == Button4 ? Button4Mask
: button == Button5 ? Button5Mask
: 0;
}
int
mouseaction(XEvent *e, uint release)
{
MouseShortcut *ms;
/* ignore Button<N>mask for Button<N> - it's set on release */
uint state = e->xbutton.state & ~buttonmask(e->xbutton.button);
for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) {
if (ms->release == release &&
ms->button == e->xbutton.button &&
(match(ms->mod, state) || /* exact or forced */
match(ms->mod, state & ~forcemousemod))) {
ms->func(&(ms->arg));
return 1;
}
}
return 0;
}
void void
bpress(XEvent *e) bpress(XEvent *e)
{ {
int btn = e->xbutton.button;
struct timespec now; struct timespec now;
MouseShortcut *ms;
int snap; int snap;
if (1 <= btn && btn <= 11) if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) {
buttons |= 1 << (btn-1);
if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forcemousemod)) {
mousereport(e); mousereport(e);
return; return;
} }
if (mouseaction(e, 0)) for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) {
return; if (e->xbutton.button == ms->b
&& match(ms->mask, e->xbutton.state)) {
ttywrite(ms->s, strlen(ms->s), 1);
return;
}
}
if (btn == Button1) { if (e->xbutton.button == Button1) {
/* /*
* If the user clicks below predefined timeouts specific * If the user clicks below predefined timeouts specific
* snapping behaviour is exposed. * snapping behaviour is exposed.
@ -697,26 +638,21 @@ xsetsel(char *str)
void void
brelease(XEvent *e) brelease(XEvent *e)
{ {
int btn = e->xbutton.button; if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) {
if (1 <= btn && btn <= 11)
buttons &= ~(1 << (btn-1));
if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forcemousemod)) {
mousereport(e); mousereport(e);
return; return;
} }
if (mouseaction(e, 1)) if (e->xbutton.button == Button2)
return; selpaste(NULL);
if (btn == Button1) else if (e->xbutton.button == Button1)
mousesel(e, 1); mousesel(e, 1);
} }
void void
bmotion(XEvent *e) bmotion(XEvent *e)
{ {
if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forcemousemod)) { if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) {
mousereport(e); mousereport(e);
return; return;
} }
@ -815,27 +751,15 @@ xloadcols(void)
loaded = 1; loaded = 1;
} }
int
xgetcolor(int x, unsigned char *r, unsigned char *g, unsigned char *b)
{
if (!BETWEEN(x, 0, dc.collen - 1))
return 1;
*r = dc.col[x].color.red >> 8;
*g = dc.col[x].color.green >> 8;
*b = dc.col[x].color.blue >> 8;
return 0;
}
int int
xsetcolorname(int x, const char *name) xsetcolorname(int x, const char *name)
{ {
Color ncolor; Color ncolor;
if (!BETWEEN(x, 0, dc.collen - 1)) if (!BETWEEN(x, 0, dc.collen))
return 1; return 1;
if (!xloadcolor(x, name, &ncolor)) if (!xloadcolor(x, name, &ncolor))
return 1; return 1;
@ -981,7 +905,7 @@ xloadfont(Font *f, FcPattern *pattern)
} }
void void
xloadfonts(const char *fontstr, double fontsize) xloadfonts(char *fontstr, double fontsize)
{ {
FcPattern *pattern; FcPattern *pattern;
double fontval; double fontval;
@ -989,7 +913,7 @@ xloadfonts(const char *fontstr, double fontsize)
if (fontstr[0] == '-') if (fontstr[0] == '-')
pattern = XftXlfdParse(fontstr, False, False); pattern = XftXlfdParse(fontstr, False, False);
else else
pattern = FcNameParse((const FcChar8 *)fontstr); pattern = FcNameParse((FcChar8 *)fontstr);
if (!pattern) if (!pattern)
die("can't open font %s\n", fontstr); die("can't open font %s\n", fontstr);
@ -1072,66 +996,12 @@ xunloadfonts(void)
xunloadfont(&dc.ibfont); xunloadfont(&dc.ibfont);
} }
int
ximopen(Display *dpy)
{
XIMCallback imdestroy = { .client_data = NULL, .callback = ximdestroy };
XICCallback icdestroy = { .client_data = NULL, .callback = xicdestroy };
xw.ime.xim = XOpenIM(xw.dpy, NULL, NULL, NULL);
if (xw.ime.xim == NULL)
return 0;
if (XSetIMValues(xw.ime.xim, XNDestroyCallback, &imdestroy, NULL))
fprintf(stderr, "XSetIMValues: "
"Could not set XNDestroyCallback.\n");
xw.ime.spotlist = XVaCreateNestedList(0, XNSpotLocation, &xw.ime.spot,
NULL);
if (xw.ime.xic == NULL) {
xw.ime.xic = XCreateIC(xw.ime.xim, XNInputStyle,
XIMPreeditNothing | XIMStatusNothing,
XNClientWindow, xw.win,
XNDestroyCallback, &icdestroy,
NULL);
}
if (xw.ime.xic == NULL)
fprintf(stderr, "XCreateIC: Could not create input context.\n");
return 1;
}
void
ximinstantiate(Display *dpy, XPointer client, XPointer call)
{
if (ximopen(dpy))
XUnregisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
ximinstantiate, NULL);
}
void
ximdestroy(XIM xim, XPointer client, XPointer call)
{
xw.ime.xim = NULL;
XRegisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
ximinstantiate, NULL);
XFree(xw.ime.spotlist);
}
int
xicdestroy(XIC xim, XPointer client, XPointer call)
{
xw.ime.xic = NULL;
return 1;
}
void void
xinit(int cols, int rows) xinit(int cols, int rows)
{ {
XGCValues gcvalues; XGCValues gcvalues;
Cursor cursor; Cursor cursor;
Window parent, root; Window parent;
pid_t thispid = getpid(); pid_t thispid = getpid();
XColor xmousefg, xmousebg; XColor xmousefg, xmousebg;
@ -1163,24 +1033,21 @@ xinit(int cols, int rows)
xw.attrs.background_pixel = dc.col[defaultbg].pixel; xw.attrs.background_pixel = dc.col[defaultbg].pixel;
xw.attrs.border_pixel = dc.col[defaultbg].pixel; xw.attrs.border_pixel = dc.col[defaultbg].pixel;
xw.attrs.bit_gravity = NorthWestGravity; xw.attrs.bit_gravity = NorthWestGravity;
xw.attrs.event_mask = FocusChangeMask | KeyPressMask | KeyReleaseMask xw.attrs.event_mask = FocusChangeMask | KeyPressMask
| ExposureMask | VisibilityChangeMask | StructureNotifyMask | ExposureMask | VisibilityChangeMask | StructureNotifyMask
| ButtonMotionMask | ButtonPressMask | ButtonReleaseMask; | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
xw.attrs.colormap = xw.cmap; xw.attrs.colormap = xw.cmap;
root = XRootWindow(xw.dpy, xw.scr);
if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0)))) if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0))))
parent = root; parent = XRootWindow(xw.dpy, xw.scr);
xw.win = XCreateWindow(xw.dpy, root, xw.l, xw.t, xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t,
win.w, win.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput, win.w, win.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
| CWEventMask | CWColormap, &xw.attrs); | CWEventMask | CWColormap, &xw.attrs);
if (parent != root)
XReparentWindow(xw.dpy, xw.win, parent, xw.l, xw.t);
memset(&gcvalues, 0, sizeof(gcvalues)); memset(&gcvalues, 0, sizeof(gcvalues));
gcvalues.graphics_exposures = False; gcvalues.graphics_exposures = False;
dc.gc = XCreateGC(xw.dpy, xw.win, GCGraphicsExposures, dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures,
&gcvalues); &gcvalues);
xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h, xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
DefaultDepth(xw.dpy, xw.scr)); DefaultDepth(xw.dpy, xw.scr));
@ -1194,10 +1061,22 @@ xinit(int cols, int rows)
xw.draw = XftDrawCreate(xw.dpy, xw.buf, xw.vis, xw.cmap); xw.draw = XftDrawCreate(xw.dpy, xw.buf, xw.vis, xw.cmap);
/* input methods */ /* input methods */
if (!ximopen(xw.dpy)) { if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
XRegisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL, XSetLocaleModifiers("@im=local");
ximinstantiate, NULL); if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
XSetLocaleModifiers("@im=");
if ((xw.xim = XOpenIM(xw.dpy,
NULL, NULL, NULL)) == NULL) {
die("XOpenIM failed. Could not open input"
" device.\n");
}
}
} }
xw.xic = XCreateIC(xw.xim, XNInputStyle, XIMPreeditNothing
| XIMStatusNothing, XNClientWindow, xw.win,
XNFocusWindow, xw.win, NULL);
if (xw.xic == NULL)
die("XCreateIC failed. Could not obtain input method.\n");
/* white cursor, black outline */ /* white cursor, black outline */
cursor = XCreateFontCursor(xw.dpy, mouseshape); cursor = XCreateFontCursor(xw.dpy, mouseshape);
@ -1220,7 +1099,6 @@ xinit(int cols, int rows)
xw.xembed = XInternAtom(xw.dpy, "_XEMBED", False); xw.xembed = XInternAtom(xw.dpy, "_XEMBED", False);
xw.wmdeletewin = XInternAtom(xw.dpy, "WM_DELETE_WINDOW", False); xw.wmdeletewin = XInternAtom(xw.dpy, "WM_DELETE_WINDOW", False);
xw.netwmname = XInternAtom(xw.dpy, "_NET_WM_NAME", False); xw.netwmname = XInternAtom(xw.dpy, "_NET_WM_NAME", False);
xw.netwmiconname = XInternAtom(xw.dpy, "_NET_WM_ICON_NAME", False);
XSetWMProtocols(xw.dpy, xw.win, &xw.wmdeletewin, 1); XSetWMProtocols(xw.dpy, xw.win, &xw.wmdeletewin, 1);
xw.netwmpid = XInternAtom(xw.dpy, "_NET_WM_PID", False); xw.netwmpid = XInternAtom(xw.dpy, "_NET_WM_PID", False);
@ -1229,8 +1107,8 @@ xinit(int cols, int rows)
win.mode = MODE_NUMLOCK; win.mode = MODE_NUMLOCK;
resettitle(); resettitle();
xhints();
XMapWindow(xw.dpy, xw.win); XMapWindow(xw.dpy, xw.win);
xhints();
XSync(xw.dpy, False); XSync(xw.dpy, False);
clock_gettime(CLOCK_MONOTONIC, &xsel.tclick1); clock_gettime(CLOCK_MONOTONIC, &xsel.tclick1);
@ -1340,10 +1218,13 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x
fontpattern = FcFontSetMatch(0, fcsets, 1, fontpattern = FcFontSetMatch(0, fcsets, 1,
fcpattern, &fcres); fcpattern, &fcres);
/* Allocate memory for the new cache entry. */ /*
if (frclen >= frccap) { * Overwrite or create the new cache entry.
frccap += 16; */
frc = xrealloc(frc, frccap * sizeof(Fontcache)); if (frclen >= LEN(frc)) {
frclen = LEN(frc) - 1;
XftFontClose(xw.dpy, frc[frclen].font);
frc[frclen].unicodep = 0;
} }
frc[frclen].font = XftFontOpenPattern(xw.dpy, frc[frclen].font = XftFontOpenPattern(xw.dpy,
@ -1496,12 +1377,12 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
/* Render underline and strikethrough. */ /* Render underline and strikethrough. */
if (base.mode & ATTR_UNDERLINE) { if (base.mode & ATTR_UNDERLINE) {
XftDrawRect(xw.draw, fg, winx, winy + dc.font.ascent * chscale + 1, XftDrawRect(xw.draw, fg, winx, winy + dc.font.ascent + 1,
width, 1); width, 1);
} }
if (base.mode & ATTR_STRUCK) { if (base.mode & ATTR_STRUCK) {
XftDrawRect(xw.draw, fg, winx, winy + 2 * dc.font.ascent * chscale / 3, XftDrawRect(xw.draw, fg, winx, winy + 2 * dc.font.ascent / 3,
width, 1); width, 1);
} }
@ -1561,9 +1442,8 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
/* draw the new one */ /* draw the new one */
if (IS_SET(MODE_FOCUSED)) { if (IS_SET(MODE_FOCUSED)) {
switch (win.cursor) { switch (win.cursor) {
case 7: /* st extension */ case 7: /* st extension: snowman (U+2603) */
g.u = 0x2603; /* snowman (U+2603) */ g.u = 0x2603;
/* FALLTHROUGH */
case 0: /* Blinking Block */ case 0: /* Blinking Block */
case 1: /* Blinking Block (Default) */ case 1: /* Blinking Block (Default) */
case 2: /* Steady Block */ case 2: /* Steady Block */
@ -1614,35 +1494,14 @@ xsetenv(void)
setenv("WINDOWID", buf, 1); setenv("WINDOWID", buf, 1);
} }
void
xseticontitle(char *p)
{
XTextProperty prop;
DEFAULT(p, opt_title);
if (p[0] == '\0')
p = opt_title;
if (Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle,
&prop) != Success)
return;
XSetWMIconName(xw.dpy, xw.win, &prop);
XSetTextProperty(xw.dpy, xw.win, &prop, xw.netwmiconname);
XFree(prop.value);
}
void void
xsettitle(char *p) xsettitle(char *p)
{ {
XTextProperty prop; XTextProperty prop;
DEFAULT(p, opt_title); DEFAULT(p, opt_title);
if (p[0] == '\0') Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle,
p = opt_title; &prop);
if (Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle,
&prop) != Success)
return;
XSetWMName(xw.dpy, xw.win, &prop); XSetWMName(xw.dpy, xw.win, &prop);
XSetTextProperty(xw.dpy, xw.win, &prop, xw.netwmname); XSetTextProperty(xw.dpy, xw.win, &prop, xw.netwmname);
XFree(prop.value); XFree(prop.value);
@ -1695,18 +1554,6 @@ xfinishdraw(void)
defaultfg : defaultbg].pixel); defaultfg : defaultbg].pixel);
} }
void
xximspot(int x, int y)
{
if (xw.ime.xic == NULL)
return;
xw.ime.spot.x = borderpx + x * win.cw;
xw.ime.spot.y = borderpx + (y + 1) * win.ch;
XSetICValues(xw.ime.xic, XNPreeditAttributes, xw.ime.spotlist, NULL);
}
void void
expose(XEvent *ev) expose(XEvent *ev)
{ {
@ -1746,7 +1593,8 @@ xsetmode(int set, unsigned int flags)
int int
xsetcursor(int cursor) xsetcursor(int cursor)
{ {
if (!BETWEEN(cursor, 0, 7)) /* 7: st extension */ DEFAULT(cursor, 1);
if (!BETWEEN(cursor, 0, 6))
return 1; return 1;
win.cursor = cursor; win.cursor = cursor;
return 0; return 0;
@ -1780,15 +1628,13 @@ focus(XEvent *ev)
return; return;
if (ev->type == FocusIn) { if (ev->type == FocusIn) {
if (xw.ime.xic) XSetICFocus(xw.xic);
XSetICFocus(xw.ime.xic);
win.mode |= MODE_FOCUSED; win.mode |= MODE_FOCUSED;
xseturgency(0); xseturgency(0);
if (IS_SET(MODE_FOCUS)) if (IS_SET(MODE_FOCUS))
ttywrite("\033[I", 3, 0); ttywrite("\033[I", 3, 0);
} else { } else {
if (xw.ime.xic) XUnsetICFocus(xw.xic);
XUnsetICFocus(xw.ime.xic);
win.mode &= ~MODE_FOCUSED; win.mode &= ~MODE_FOCUSED;
if (IS_SET(MODE_FOCUS)) if (IS_SET(MODE_FOCUS))
ttywrite("\033[O", 3, 0); ttywrite("\033[O", 3, 0);
@ -1842,8 +1688,8 @@ void
kpress(XEvent *ev) kpress(XEvent *ev)
{ {
XKeyEvent *e = &ev->xkey; XKeyEvent *e = &ev->xkey;
KeySym ksym = NoSymbol; KeySym ksym;
char buf[64], *customkey; char buf[32], *customkey;
int len; int len;
Rune c; Rune c;
Status status; Status status;
@ -1852,13 +1698,7 @@ kpress(XEvent *ev)
if (IS_SET(MODE_KBDLOCK)) if (IS_SET(MODE_KBDLOCK))
return; return;
if (xw.ime.xic) { len = XmbLookupString(xw.xic, e, buf, sizeof buf, &ksym, &status);
len = XmbLookupString(xw.ime.xic, e, buf, sizeof buf, &ksym, &status);
if (status == XBufferOverflow)
return;
} else {
len = XLookupString(e, buf, sizeof buf, &ksym, NULL);
}
/* 1. shortcuts */ /* 1. shortcuts */
for (bp = shortcuts; bp < shortcuts + LEN(shortcuts); bp++) { for (bp = shortcuts; bp < shortcuts + LEN(shortcuts); bp++) {
if (ksym == bp->keysym && match(bp->mod, e->state)) { if (ksym == bp->keysym && match(bp->mod, e->state)) {
@ -1891,6 +1731,7 @@ kpress(XEvent *ev)
ttywrite(buf, len, 1); ttywrite(buf, len, 1);
} }
void void
cmessage(XEvent *e) cmessage(XEvent *e)
{ {
@ -1926,9 +1767,10 @@ run(void)
XEvent ev; XEvent ev;
int w = win.w, h = win.h; int w = win.w, h = win.h;
fd_set rfd; fd_set rfd;
int xfd = XConnectionNumber(xw.dpy), ttyfd, xev, drawing; int xfd = XConnectionNumber(xw.dpy), xev, blinkset = 0, dodraw = 0;
struct timespec seltv, *tv, now, lastblink, trigger; int ttyfd;
double timeout; struct timespec drawtimeout, *tv = NULL, now, last, lastblink;
long deltatime;
/* Waiting for window mapping */ /* Waiting for window mapping */
do { do {
@ -1949,77 +1791,82 @@ run(void)
ttyfd = ttynew(opt_line, shell, opt_io, opt_cmd); ttyfd = ttynew(opt_line, shell, opt_io, opt_cmd);
cresize(w, h); cresize(w, h);
for (timeout = -1, drawing = 0, lastblink = (struct timespec){0};;) { clock_gettime(CLOCK_MONOTONIC, &last);
lastblink = last;
for (xev = actionfps;;) {
FD_ZERO(&rfd); FD_ZERO(&rfd);
FD_SET(ttyfd, &rfd); FD_SET(ttyfd, &rfd);
FD_SET(xfd, &rfd); FD_SET(xfd, &rfd);
if (XPending(xw.dpy))
timeout = 0; /* existing events might not set xfd */
seltv.tv_sec = timeout / 1E3;
seltv.tv_nsec = 1E6 * (timeout - 1E3 * seltv.tv_sec);
tv = timeout >= 0 ? &seltv : NULL;
if (pselect(MAX(xfd, ttyfd)+1, &rfd, NULL, NULL, tv, NULL) < 0) { if (pselect(MAX(xfd, ttyfd)+1, &rfd, NULL, NULL, tv, NULL) < 0) {
if (errno == EINTR) if (errno == EINTR)
continue; continue;
die("select failed: %s\n", strerror(errno)); die("select failed: %s\n", strerror(errno));
} }
clock_gettime(CLOCK_MONOTONIC, &now); if (FD_ISSET(ttyfd, &rfd)) {
if (FD_ISSET(ttyfd, &rfd))
ttyread(); ttyread();
if (blinktimeout) {
xev = 0; blinkset = tattrset(ATTR_BLINK);
while (XPending(xw.dpy)) { if (!blinkset)
xev = 1; MODBIT(win.mode, 0, MODE_BLINK);
XNextEvent(xw.dpy, &ev);
if (XFilterEvent(&ev, None))
continue;
if (handler[ev.type])
(handler[ev.type])(&ev);
}
/*
* To reduce flicker and tearing, when new content or event
* triggers drawing, we first wait a bit to ensure we got
* everything, and if nothing new arrives - we draw.
* We start with trying to wait minlatency ms. If more content
* arrives sooner, we retry with shorter and shorter periods,
* and eventually draw even without idle after maxlatency ms.
* Typically this results in low latency while interacting,
* maximum latency intervals during `cat huge.txt`, and perfect
* sync with periodic updates from animations/key-repeats/etc.
*/
if (FD_ISSET(ttyfd, &rfd) || xev) {
if (!drawing) {
trigger = now;
drawing = 1;
}
timeout = (maxlatency - TIMEDIFF(now, trigger)) \
/ maxlatency * minlatency;
if (timeout > 0)
continue; /* we have time, try to find idle */
}
/* idle detected or maxlatency exhausted -> draw */
timeout = -1;
if (blinktimeout && tattrset(ATTR_BLINK)) {
timeout = blinktimeout - TIMEDIFF(now, lastblink);
if (timeout <= 0) {
if (-timeout > blinktimeout) /* start visible */
win.mode |= MODE_BLINK;
win.mode ^= MODE_BLINK;
tsetdirtattr(ATTR_BLINK);
lastblink = now;
timeout = blinktimeout;
} }
} }
draw(); if (FD_ISSET(xfd, &rfd))
XFlush(xw.dpy); xev = actionfps;
drawing = 0;
clock_gettime(CLOCK_MONOTONIC, &now);
drawtimeout.tv_sec = 0;
drawtimeout.tv_nsec = (1000 * 1E6)/ xfps;
tv = &drawtimeout;
dodraw = 0;
if (blinktimeout && TIMEDIFF(now, lastblink) > blinktimeout) {
tsetdirtattr(ATTR_BLINK);
win.mode ^= MODE_BLINK;
lastblink = now;
dodraw = 1;
}
deltatime = TIMEDIFF(now, last);
if (deltatime > 1000 / (xev ? xfps : actionfps)) {
dodraw = 1;
last = now;
}
if (dodraw) {
while (XPending(xw.dpy)) {
XNextEvent(xw.dpy, &ev);
if (XFilterEvent(&ev, None))
continue;
if (handler[ev.type])
(handler[ev.type])(&ev);
}
draw();
XFlush(xw.dpy);
if (xev && !FD_ISSET(xfd, &rfd))
xev--;
if (!FD_ISSET(ttyfd, &rfd) && !FD_ISSET(xfd, &rfd)) {
if (blinkset) {
if (TIMEDIFF(now, lastblink) \
> blinktimeout) {
drawtimeout.tv_nsec = 1000;
} else {
drawtimeout.tv_nsec = (1E6 * \
(blinktimeout - \
TIMEDIFF(now,
lastblink)));
}
drawtimeout.tv_sec = \
drawtimeout.tv_nsec / 1E9;
drawtimeout.tv_nsec %= (long)1E9;
} else {
tv = NULL;
}
}
}
} }
} }
@ -2041,7 +1888,7 @@ main(int argc, char *argv[])
{ {
xw.l = xw.t = 0; xw.l = xw.t = 0;
xw.isfixed = False; xw.isfixed = False;
xsetcursor(cursorshape); win.cursor = cursorshape;
ARGBEGIN { ARGBEGIN {
case 'a': case 'a':