aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncaen <mail@duncano.de>2018-08-15 14:55:37 +0200
committerDuncaen <mail@duncano.de>2018-08-15 14:55:37 +0200
commitbd9c6deea43607de95eb043bf47be563eab9cbe4 (patch)
tree920410155c668968d28c1a6a62953c827ff27bb8
parentc30aa15c1f26eee1fde72c38d40dfe3068076a45 (diff)
parent4f4bccd1627c845330235721f593d2e93418723d (diff)
downloadst-bd9c6deea43607de95eb043bf47be563eab9cbe4.tar.gz
Merge branch 'master' of git://git.suckless.org/st
-rw-r--r--FAQ2
-rw-r--r--LICENSE9
-rw-r--r--Makefile60
-rw-r--r--arg.h22
-rw-r--r--config.def.h584
-rw-r--r--config.mk25
-rw-r--r--st.12
-rw-r--r--st.c691
-rw-r--r--st.h199
-rw-r--r--st.info7
-rw-r--r--win.h52
-rw-r--r--x.c750
12 files changed, 1167 insertions, 1236 deletions
diff --git a/FAQ b/FAQ
index 4defff9..921c493 100644
--- a/FAQ
+++ b/FAQ
@@ -6,7 +6,7 @@ Use the excellent tool of [utmp](http://git.suckless.org/utmp/) for this task.
It means that st doesn’t 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 can manualy run `tic -sx st.info`.
+you can manually run `tic -sx st.info`.
## Nothing works, and nothing is said about an unknown terminal!
diff --git a/LICENSE b/LICENSE
index fa0c63e..c356c39 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,13 +1,16 @@
MIT/X Consortium License
+© 2014-2018 Hiltjo Posthuma <hiltjo at codemadness dot org>
+© 2018 Devin J. Pohly <djpohly at gmail dot com>
+© 2014-2017 Quentin Rameau <quinq at fifth dot space>
© 2009-2012 Aurélien APTEL <aurelien dot aptel at gmail dot com>
-© 2009 Anselm R Garbe <garbeam at gmail dot com>
-© 2012-2016 Roberto E. Vargas Caballero <k0ga at shike2 dot com>
+© 2008-2017 Anselm R Garbe <garbeam at gmail dot com>
+© 2012-2017 Roberto E. Vargas Caballero <k0ga at shike2 dot com>
© 2012-2016 Christoph Lohmann <20h at r-36 dot net>
© 2013 Eon S. Jeon <esjeon at hyunmu dot am>
© 2013 Alexander Sedov <alex0player at gmail dot com>
© 2013 Mark Edgar <medgar123 at gmail dot com>
-© 2013 Eric Pruitt <eric.pruitt at gmail dot com>
+© 2013-2014 Eric Pruitt <eric.pruitt at gmail dot com>
© 2013 Michael Forney <mforney at mforney dot org>
© 2013-2014 Markus Teich <markus dot teich at stusta dot mhn dot de>
© 2014-2015 Laslo Hunhold <dev at frign dot de>
diff --git a/Makefile b/Makefile
index d8595fe..0b3cecd 100644
--- a/Makefile
+++ b/Makefile
@@ -1,63 +1,57 @@
# st - simple terminal
# See LICENSE file for copyright and license details.
+.POSIX:
include config.mk
SRC = st.c x.c
-OBJ = ${SRC:.c=.o}
+OBJ = $(SRC:.c=.o)
all: options st
options:
@echo st build options:
- @echo "CFLAGS = ${CFLAGS}"
- @echo "LDFLAGS = ${LDFLAGS}"
- @echo "CC = ${CC}"
+ @echo "CFLAGS = $(STCFLAGS)"
+ @echo "LDFLAGS = $(STLDFLAGS)"
+ @echo "CC = $(CC)"
config.h:
cp config.def.h config.h
.c.o:
- @echo CC $<
- @${CC} -c ${CFLAGS} $<
+ $(CC) $(STCFLAGS) -c $<
st.o: config.h st.h win.h
x.o: arg.h st.h win.h
-${OBJ}: config.h config.mk
+$(OBJ): config.h config.mk
-st: ${OBJ}
- @echo CC -o $@
- @${CC} -o $@ ${OBJ} ${LDFLAGS}
+st: $(OBJ)
+ $(CC) -o $@ $(OBJ) $(STLDFLAGS)
clean:
- @echo cleaning
- @rm -f st ${OBJ} st-${VERSION}.tar.gz
+ rm -f st $(OBJ) st-$(VERSION).tar.gz
dist: clean
- @echo creating dist tarball
- @mkdir -p st-${VERSION}
- @cp -R LICENSE Makefile README config.mk config.def.h st.info st.1 arg.h ${SRC} st-${VERSION}
- @tar -cf st-${VERSION}.tar st-${VERSION}
- @gzip st-${VERSION}.tar
- @rm -rf st-${VERSION}
-
-install: all
- @echo installing executable file to ${DESTDIR}${PREFIX}/bin
- @mkdir -p ${DESTDIR}${PREFIX}/bin
- @cp -f st ${DESTDIR}${PREFIX}/bin
- @chmod 755 ${DESTDIR}${PREFIX}/bin/st
- @echo installing manual page to ${DESTDIR}${MANPREFIX}/man1
- @mkdir -p ${DESTDIR}${MANPREFIX}/man1
- @sed "s/VERSION/${VERSION}/g" < st.1 > ${DESTDIR}${MANPREFIX}/man1/st.1
- @chmod 644 ${DESTDIR}${MANPREFIX}/man1/st.1
+ mkdir -p st-$(VERSION)
+ cp -R FAQ LEGACY TODO LICENSE Makefile README config.mk\
+ config.def.h st.info st.1 arg.h st.h win.h $(SRC)\
+ st-$(VERSION)
+ tar -cf - st-$(VERSION) | gzip > st-$(VERSION).tar.gz
+ rm -rf st-$(VERSION)
+
+install: st
+ mkdir -p $(DESTDIR)$(PREFIX)/bin
+ cp -f st $(DESTDIR)$(PREFIX)/bin
+ chmod 755 $(DESTDIR)$(PREFIX)/bin/st
+ mkdir -p $(DESTDIR)$(MANPREFIX)/man1
+ sed "s/VERSION/$(VERSION)/g" < st.1 > $(DESTDIR)$(MANPREFIX)/man1/st.1
+ chmod 644 $(DESTDIR)$(MANPREFIX)/man1/st.1
+ tic -sx st.info
@echo Please see the README file regarding the terminfo entry of st.
- @tic -sx st.info
uninstall:
- @echo removing executable file from ${DESTDIR}${PREFIX}/bin
- @rm -f ${DESTDIR}${PREFIX}/bin/st
- @echo removing manual page from ${DESTDIR}${MANPREFIX}/man1
- @rm -f ${DESTDIR}${MANPREFIX}/man1/st.1
+ rm -f $(DESTDIR)$(PREFIX)/bin/st
+ rm -f $(DESTDIR)$(MANPREFIX)/man1/st.1
.PHONY: all options clean dist install uninstall
diff --git a/arg.h b/arg.h
index ba3fb3f..a22e019 100644
--- a/arg.h
+++ b/arg.h
@@ -21,28 +21,30 @@ extern char *argv0;
argc--;\
break;\
}\
- for (brk_ = 0, argv[0]++, argv_ = argv;\
- argv[0][0] && !brk_;\
- argv[0]++) {\
+ int i_;\
+ for (i_ = 1, brk_ = 0, argv_ = argv;\
+ argv[0][i_] && !brk_;\
+ i_++) {\
if (argv_ != argv)\
break;\
- argc_ = argv[0][0];\
+ argc_ = argv[0][i_];\
switch (argc_)
+
#define ARGEND }\
}
#define ARGC() argc_
-#define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\
+#define EARGF(x) ((argv[0][i_+1] == '\0' && argv[1] == NULL)?\
((x), abort(), (char *)0) :\
- (brk_ = 1, (argv[0][1] != '\0')?\
- (&argv[0][1]) :\
+ (brk_ = 1, (argv[0][i_+1] != '\0')?\
+ (&argv[0][i_+1]) :\
(argc--, argv++, argv[0])))
-#define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\
+#define ARGF() ((argv[0][i_+1] == '\0' && argv[1] == NULL)?\
(char *)0 :\
- (brk_ = 1, (argv[0][1] != '\0')?\
- (&argv[0][1]) :\
+ (brk_ = 1, (argv[0][i_+1] != '\0')?\
+ (&argv[0][i_+1]) :\
(argc--, argv++, argv[0])))
#endif
diff --git a/config.def.h b/config.def.h
index 1fcf5a2..82b1b09 100644
--- a/config.def.h
+++ b/config.def.h
@@ -5,8 +5,8 @@
*
* font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
*/
-char font[] = "-xos4-terminus-medium-r-normal-*-12-*-*-*-*-*-*-*,";
-int borderpx = 2;
+static char *font = "Liberation Mono:pixelsize=12:antialias=true:autohint=true";
+static int borderpx = 2;
/*
* What program is execed by st depends of these precedence rules:
@@ -16,45 +16,45 @@ int borderpx = 2;
* 4: value of shell in /etc/passwd
* 5: value of shell in config.h
*/
-static char shell[] = "/usr/bin/yash";
-static char *utmp = NULL;
-static char stty_args[] = "stty raw pass8 nl -echo -iexten -cstopb 38400";
+static char *shell = "/bin/sh";
+char *utmp = NULL;
+char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400";
/* identification sequence returned in DA and DECID */
-static char vtiden[] = "\033[?6c";
+char *vtiden = "\033[?6c";
/* Kerning / character bounding-box multipliers */
-float cwscale = 1.0;
-float chscale = 1.0;
+static float cwscale = 1.0;
+static float chscale = 1.0;
/*
* word delimiter string
*
* More advanced example: " `'\"()[]{}"
*/
-static char worddelimiters[] = " `'\"()[]{}";
+char *worddelimiters = " ";
/* selection timeouts (in milliseconds) */
-unsigned int doubleclicktimeout = 300;
-unsigned int tripleclicktimeout = 600;
+static unsigned int doubleclicktimeout = 300;
+static unsigned int tripleclicktimeout = 600;
/* alt screens */
int allowaltscreen = 1;
/* frames per second st should at maximum draw to the screen */
-unsigned int xfps = 120;
-unsigned int actionfps = 30;
+static unsigned int xfps = 120;
+static unsigned int actionfps = 30;
/*
* blinking timeout (set to 0 to disable blinking) for the terminal blinking
* attribute.
*/
-unsigned int blinktimeout = 800;
+static unsigned int blinktimeout = 800;
/*
* thickness of underline and bar cursors
*/
-unsigned int cursorthickness = 2;
+static unsigned int cursorthickness = 2;
/*
* bell volume. It must be a value between -100 and 100. Use 0 for disabling
@@ -63,7 +63,7 @@ unsigned int cursorthickness = 2;
static int bellvolume = 0;
/* default TERM value */
-char termname[] = "st-256color";
+char *termname = "st-256color";
/*
* spaces per tab
@@ -80,79 +80,35 @@ char termname[] = "st-256color";
*
* stty tabs
*/
-static unsigned int tabspaces = 4;
-
-// Base 00 - Black
-#define COLOR00 "#181818"
-//Base 08 - Red
-#define COLOR01 "#ab4642"
-// Base 0B - Green
-#define COLOR02 "#a1b56c"
-// Base 0A - Yellow
-#define COLOR03 "#f7ca88"
-// Base 0D - Blue
-#define COLOR04 "#7cafc2"
-// Base 0E - Magenta
-#define COLOR05 "#ba8baf"
-// Base 0C - Cyan
-#define COLOR06 "#86c1b9"
-// Base 05 - White
-#define COLOR07 "#d8d8d8"
-
-// Base 03 - Bright Black
-#define COLOR08 "#585858"
-// Base 08 - Bright Red
-#define COLOR09 COLOR01
-// Base 0B - Bright Green
-#define COLOR10 COLOR02
-// Base 0A - Bright Yellow
-#define COLOR11 COLOR03
-// Base 0D - Bright Blue
-#define COLOR12 COLOR04
-// Base 0E - Bright Magenta
-#define COLOR13 COLOR05
-// Base 0C - Bright Cyan
-#define COLOR14 COLOR06
-
-// Base 07 - Bright White
-#define COLOR15 "#f8f8f8"
-// Base 09
-#define COLOR16 "#dc9656"
-// Base 0F
-#define COLOR17 "#a16946"
-// Base 01
-#define COLOR18 "#282828"
-// Base 02
-#define COLOR19 "#383838"
-// Base 04
-#define COLOR20 "#b8b8b8"
-// Base 06
-#define COLOR21 "#e8e8e8"
-
-const char *colorname[] = {
- /* solarized dark */
- COLOR00, /* 0: black */
- COLOR01, /* 1: red */
- COLOR02, /* 2: green */
- COLOR03, /* 3: yellow */
- COLOR04, /* 4: blue */
- COLOR05, /* 5: magenta */
- COLOR06, /* 6: cyan */ COLOR07, /* 7: white */
- COLOR08, /* 8: brblack */
- COLOR09, /* 9: brred */
- COLOR10, /* 10: brgreen */
- COLOR11, /* 11: bryellow */
- COLOR12, /* 12: brblue */
- COLOR13, /* 13: brmagenta*/
- COLOR14, /* 14: brcyan */
- COLOR15, /* 15: brwhite */
+unsigned int tabspaces = 8;
+
+/* Terminal colors (16 first used in escape sequence) */
+static const char *colorname[] = {
+ /* 8 normal colors */
+ "black",
+ "red3",
+ "green3",
+ "yellow3",
+ "blue2",
+ "magenta3",
+ "cyan3",
+ "gray90",
+
+ /* 8 bright colors */
+ "gray50",
+ "red",
+ "green",
+ "yellow",
+ "#5c5cff",
+ "magenta",
+ "cyan",
+ "white",
+
[255] = 0,
- COLOR16,
- COLOR17,
- COLOR18,
- COLOR19,
- COLOR20,
- COLOR21
+
+ /* more colors can be added after 255 to use with DefaultXX */
+ "#cccccc",
+ "#555555",
};
@@ -162,8 +118,8 @@ const char *colorname[] = {
*/
unsigned int defaultfg = 7;
unsigned int defaultbg = 0;
-unsigned int defaultcs = 7;
-unsigned int defaultrcs = 0;
+static unsigned int defaultcs = 256;
+static unsigned int defaultrcs = 257;
/*
* Default shape of cursor
@@ -172,33 +128,33 @@ unsigned int defaultrcs = 0;
* 6: Bar ("|")
* 7: Snowman ("☃")
*/
-unsigned int cursorshape = 2;
+static unsigned int cursorshape = 2;
/*
* Default columns and rows numbers
*/
-unsigned int cols = 80;
-unsigned int rows = 24;
+static unsigned int cols = 80;
+static unsigned int rows = 24;
/*
* Default colour and shape of the mouse cursor
*/
-unsigned int mouseshape = XC_xterm;
-unsigned int mousefg = 7;
-unsigned int mousebg = 0;
+static unsigned int mouseshape = XC_xterm;
+static unsigned int mousefg = 7;
+static unsigned int mousebg = 0;
/*
* Color used to display font attributes when fontconfig selected a font which
* doesn't match the ones requested.
*/
-unsigned int defaultattr = 11;
+static unsigned int defaultattr = 11;
/*
* Internal mouse shortcuts.
* Beware that overloading Button1 will disable the selection.
*/
-MouseShortcut mshortcuts[] = {
+static MouseShortcut mshortcuts[] = {
/* button mask string */
{ Button4, XK_ANY_MOD, "\031" },
{ Button5, XK_ANY_MOD, "\005" },
@@ -208,7 +164,7 @@ MouseShortcut mshortcuts[] = {
#define MODKEY Mod1Mask
#define TERMMOD (ControlMask|ShiftMask)
-Shortcut shortcuts[] = {
+static Shortcut shortcuts[] = {
/* mask keysym function argument */
{ XK_ANY_MOD, XK_Break, sendbreak, {.i = 0} },
{ ControlMask, XK_Print, toggleprinter, {.i = 0} },
@@ -266,226 +222,223 @@ static uint ignoremod = Mod2Mask|XK_SWITCH_MOD;
* Note that if you want to use ShiftMask with selmasks, set this to an other
* modifier, set to 0 to not use it.
*/
-uint forceselmod = ShiftMask;
+static uint forceselmod = ShiftMask;
/*
* This is the huge key array which defines all compatibility to the Linux
* world. Please decide about changes wisely.
*/
static Key key[] = {
- /* keysym mask string appkey appcursor crlf */
- { XK_KP_Home, ShiftMask, "\033[2J", 0, -1, 0},
- { XK_KP_Home, ShiftMask, "\033[1;2H", 0, +1, 0},
- { XK_KP_Home, XK_ANY_MOD, "\033[H", 0, -1, 0},
- { XK_KP_Home, XK_ANY_MOD, "\033[1~", 0, +1, 0},
- { XK_KP_Up, XK_ANY_MOD, "\033Ox", +1, 0, 0},
- { XK_KP_Up, XK_ANY_MOD, "\033[A", 0, -1, 0},
- { XK_KP_Up, XK_ANY_MOD, "\033OA", 0, +1, 0},
- { XK_KP_Down, XK_ANY_MOD, "\033Or", +1, 0, 0},
- { XK_KP_Down, XK_ANY_MOD, "\033[B", 0, -1, 0},
- { XK_KP_Down, XK_ANY_MOD, "\033OB", 0, +1, 0},
- { XK_KP_Left, XK_ANY_MOD, "\033Ot", +1, 0, 0},
- { XK_KP_Left, XK_ANY_MOD, "\033[D", 0, -1, 0},
- { XK_KP_Left, XK_ANY_MOD, "\033OD", 0, +1, 0},
- { XK_KP_Right, XK_ANY_MOD, "\033Ov", +1, 0, 0},
- { XK_KP_Right, XK_ANY_MOD, "\033[C", 0, -1, 0},
- { XK_KP_Right, XK_ANY_MOD, "\033OC", 0, +1, 0},
- { XK_KP_Prior, ShiftMask, "\033[5;2~", 0, 0, 0},
- { XK_KP_Prior, XK_ANY_MOD, "\033[5~", 0, 0, 0},
- { XK_KP_Begin, XK_ANY_MOD, "\033[E", 0, 0, 0},
- { XK_KP_End, ControlMask, "\033[J", -1, 0, 0},
- { XK_KP_End, ControlMask, "\033[1;5F", +1, 0, 0},
- { XK_KP_End, ShiftMask, "\033[K", -1, 0, 0},
- { XK_KP_End, ShiftMask, "\033[1;2F", +1, 0, 0},
- { XK_KP_End, XK_ANY_MOD, "\033[4~", 0, 0, 0},
- { XK_KP_Next, ShiftMask, "\033[6;2~", 0, 0, 0},
- { XK_KP_Next, XK_ANY_MOD, "\033[6~", 0, 0, 0},
- { XK_KP_Insert, ShiftMask, "\033[2;2~", +1, 0, 0},
- { XK_KP_Insert, ShiftMask, "\033[4l", -1, 0, 0},
- { XK_KP_Insert, ControlMask, "\033[L", -1, 0, 0},
- { XK_KP_Insert, ControlMask, "\033[2;5~", +1, 0, 0},
- { XK_KP_Insert, XK_ANY_MOD, "\033[4h", -1, 0, 0},
- { XK_KP_Insert, XK_ANY_MOD, "\033[2~", +1, 0, 0},
- { XK_KP_Delete, ControlMask, "\033[M", -1, 0, 0},
- { XK_KP_Delete, ControlMask, "\033[3;5~", +1, 0, 0},
- { XK_KP_Delete, ShiftMask, "\033[2K", -1, 0, 0},
- { XK_KP_Delete, ShiftMask, "\033[3;2~", +1, 0, 0},
- { XK_KP_Delete, XK_ANY_MOD, "\033[P", -1, 0, 0},
- { XK_KP_Delete, XK_ANY_MOD, "\033[3~", +1, 0, 0},
- { XK_KP_Multiply, XK_ANY_MOD, "\033Oj", +2, 0, 0},
- { XK_KP_Add, XK_ANY_MOD, "\033Ok", +2, 0, 0},
- { XK_KP_Enter, XK_ANY_MOD, "\033OM", +2, 0, 0},
- { XK_KP_Enter, XK_ANY_MOD, "\r", -1, 0, -1},
- { XK_KP_Enter, XK_ANY_MOD, "\r\n", -1, 0, +1},
- { XK_KP_Subtract, XK_ANY_MOD, "\033Om", +2, 0, 0},
- { XK_KP_Decimal, XK_ANY_MOD, "\033On", +2, 0, 0},
- { XK_KP_Divide, XK_ANY_MOD, "\033Oo", +2, 0, 0},
- { XK_KP_0, XK_ANY_MOD, "\033Op", +2, 0, 0},
- { XK_KP_1, XK_ANY_MOD, "\033Oq", +2, 0, 0},
- { XK_KP_2, XK_ANY_MOD, "\033Or", +2, 0, 0},
- { XK_KP_3, XK_ANY_MOD, "\033Os", +2, 0, 0},
- { XK_KP_4, XK_ANY_MOD, "\033Ot", +2, 0, 0},
- { XK_KP_5, XK_ANY_MOD, "\033Ou", +2, 0, 0},
- { XK_KP_6, XK_ANY_MOD, "\033Ov", +2, 0, 0},
- { XK_KP_7, XK_ANY_MOD, "\033Ow", +2, 0, 0},
- { XK_KP_8, XK_ANY_MOD, "\033Ox", +2, 0, 0},
- { XK_KP_9, XK_ANY_MOD, "\033Oy", +2, 0, 0},
- { XK_Up, ShiftMask, "\033[1;2A", 0, 0, 0},
- { XK_Up, Mod1Mask, "\033[1;3A", 0, 0, 0},
- { XK_Up, ShiftMask|Mod1Mask,"\033[1;4A", 0, 0, 0},
- { XK_Up, ControlMask, "\033[1;5A", 0, 0, 0},
- { XK_Up, ShiftMask|ControlMask,"\033[1;6A", 0, 0, 0},
- { XK_Up, ControlMask|Mod1Mask,"\033[1;7A", 0, 0, 0},
- { XK_Up,ShiftMask|ControlMask|Mod1Mask,"\033[1;8A", 0, 0, 0},
- { XK_Up, XK_ANY_MOD, "\033[A", 0, -1, 0},
- { XK_Up, XK_ANY_MOD, "\033OA", 0, +1, 0},
- { XK_Down, ShiftMask, "\033[1;2B", 0, 0, 0},
- { XK_Down, Mod1Mask, "\033[1;3B", 0, 0, 0},
- { XK_Down, ShiftMask|Mod1Mask,"\033[1;4B", 0, 0, 0},
- { XK_Down, ControlMask, "\033[1;5B", 0, 0, 0},
- { XK_Down, ShiftMask|ControlMask,"\033[1;6B", 0, 0, 0},
- { XK_Down, ControlMask|Mod1Mask,"\033[1;7B", 0, 0, 0},
- { XK_Down,ShiftMask|ControlMask|Mod1Mask,"\033[1;8B",0, 0, 0},
- { XK_Down, XK_ANY_MOD, "\033[B", 0, -1, 0},
- { XK_Down, XK_ANY_MOD, "\033OB", 0, +1, 0},
- { XK_Left, ShiftMask, "\033[1;2D", 0, 0, 0},
- { XK_Left, Mod1Mask, "\033[1;3D", 0, 0, 0},
- { XK_Left, ShiftMask|Mod1Mask,"\033[1;4D", 0, 0, 0},
- { XK_Left, ControlMask, "\033[1;5D", 0, 0, 0},
- { XK_Left, ShiftMask|ControlMask,"\033[1;6D", 0, 0, 0},
- { XK_Left, ControlMask|Mod1Mask,"\033[1;7D", 0, 0, 0},
- { XK_Left,ShiftMask|ControlMask|Mod1Mask,"\033[1;8D",0, 0, 0},
- { XK_Left, XK_ANY_MOD, "\033[D", 0, -1, 0},
- { XK_Left, XK_ANY_MOD, "\033OD", 0, +1, 0},
- { XK_Right, ShiftMask, "\033[1;2C", 0, 0, 0},
- { XK_Right, Mod1Mask, "\033[1;3C", 0, 0, 0},
- { XK_Right, ShiftMask|Mod1Mask,"\033[1;4C", 0, 0, 0},
- { XK_Right, ControlMask, "\033[1;5C", 0, 0, 0},
- { XK_Right, ShiftMask|ControlMask,"\033[1;6C", 0, 0, 0},
- { XK_Right, ControlMask|Mod1Mask,"\033[1;7C", 0, 0, 0},
- { XK_Right,ShiftMask|ControlMask|Mod1Mask,"\033[1;8C",0, 0, 0},
- { XK_Right, XK_ANY_MOD, "\033[C", 0, -1, 0},
- { XK_Right, XK_ANY_MOD, "\033OC", 0, +1, 0},
- { XK_ISO_Left_Tab, ShiftMask, "\033[Z", 0, 0, 0},
- { XK_Return, Mod1Mask, "\033\r", 0, 0, -1},
- { XK_Return, Mod1Mask, "\033\r\n", 0, 0, +1},
- { XK_Return, XK_ANY_MOD, "\r", 0, 0, -1},
- { XK_Return, XK_ANY_MOD, "\r\n", 0, 0, +1},
- { XK_Insert, ShiftMask, "\033[4l", -1, 0, 0},
- { XK_Insert, ShiftMask, "\033[2;2~", +1, 0, 0},
- { XK_Insert, ControlMask, "\033[L", -1, 0, 0},
- { XK_Insert, ControlMask, "\033[2;5~", +1, 0, 0},
- { XK_Insert, XK_ANY_MOD, "\033[4h", -1, 0, 0},
- { XK_Insert, XK_ANY_MOD, "\033[2~", +1, 0, 0},
- { XK_Delete, ControlMask, "\033[M", -1, 0, 0},
- { XK_Delete, ControlMask, "\033[3;5~", +1, 0, 0},
- { XK_Delete, ShiftMask, "\033[2K", -1, 0, 0},
- { XK_Delete, ShiftMask, "\033[3;2~", +1, 0, 0},
- { XK_Delete, XK_ANY_MOD, "\033[P", -1, 0, 0},
- { XK_Delete, XK_ANY_MOD, "\033[3~", +1, 0, 0},
- { XK_BackSpace, XK_NO_MOD, "\177", 0, 0, 0},
- { XK_BackSpace, Mod1Mask, "\033\177", 0, 0, 0},
- { XK_Home, ShiftMask, "\033[2J", 0, -1, 0},
- { XK_Home, ShiftMask, "\033[1;2H", 0, +1, 0},
- { XK_Home, XK_ANY_MOD, "\033[H", 0, -1, 0},
- { XK_Home, XK_ANY_MOD, "\033[1~", 0, +1, 0},
- { XK_End, ControlMask, "\033[J", -1, 0, 0},
- { XK_End, ControlMask, "\033[1;5F", +1, 0, 0},
- { XK_End, ShiftMask, "\033[K", -1, 0, 0},
- { XK_End, ShiftMask, "\033[1;2F", +1, 0, 0},
- { XK_End, XK_ANY_MOD, "\033[4~", 0, 0, 0},
- { XK_Prior, ControlMask, "\033[5;5~", 0, 0, 0},
- { XK_Prior, ShiftMask, "\033[5;2~", 0, 0, 0},
- { XK_Prior, XK_ANY_MOD, "\033[5~", 0, 0, 0},
- { XK_Next, ControlMask, "\033[6;5~", 0, 0, 0},
- { XK_Next, ShiftMask, "\033[6;2~", 0, 0, 0},
- { XK_Next, XK_ANY_MOD, "\033[6~", 0, 0, 0},
- { XK_F1, XK_NO_MOD, "\033OP" , 0, 0, 0},
- { XK_F1, /* F13 */ ShiftMask, "\033[1;2P", 0, 0, 0},
- { XK_F1, /* F25 */ ControlMask, "\033[1;5P", 0, 0, 0},
- { XK_F1, /* F37 */ Mod4Mask, "\033[1;6P", 0, 0, 0},
- { XK_F1, /* F49 */ Mod1Mask, "\033[1;3P", 0, 0, 0},
- { XK_F1, /* F61 */ Mod3Mask, "\033[1;4P", 0, 0, 0},
- { XK_F2, XK_NO_MOD, "\033OQ" , 0, 0, 0},
- { XK_F2, /* F14 */ ShiftMask, "\033[1;2Q", 0, 0, 0},
- { XK_F2, /* F26 */ ControlMask, "\033[1;5Q", 0, 0, 0},
- { XK_F2, /* F38 */ Mod4Mask, "\033[1;6Q", 0, 0, 0},
- { XK_F2, /* F50 */ Mod1Mask, "\033[1;3Q", 0, 0, 0},
- { XK_F2, /* F62 */ Mod3Mask, "\033[1;4Q", 0, 0, 0},
- { XK_F3, XK_NO_MOD, "\033OR" , 0, 0, 0},
- { XK_F3, /* F15 */ ShiftMask, "\033[1;2R", 0, 0, 0},
- { XK_F3, /* F27 */ ControlMask, "\033[1;5R", 0, 0, 0},
- { XK_F3, /* F39 */ Mod4Mask, "\033[1;6R", 0, 0, 0},
- { XK_F3, /* F51 */ Mod1Mask, "\033[1;3R", 0, 0, 0},
- { XK_F3, /* F63 */ Mod3Mask, "\033[1;4R", 0, 0, 0},
- { XK_F4, XK_NO_MOD, "\033OS" , 0, 0, 0},
- { XK_F4, /* F16 */ ShiftMask, "\033[1;2S", 0, 0, 0},
- { XK_F4, /* F28 */ ControlMask, "\033[1;5S", 0, 0, 0},
- { XK_F4, /* F40 */ Mod4Mask, "\033[1;6S", 0, 0, 0},
- { XK_F4, /* F52 */ Mod1Mask, "\033[1;3S", 0, 0, 0},
- { XK_F5, XK_NO_MOD, "\033[15~", 0, 0, 0},
- { XK_F5, /* F17 */ ShiftMask, "\033[15;2~", 0, 0, 0},
- { XK_F5, /* F29 */ ControlMask, "\033[15;5~", 0, 0, 0},
- { XK_F5, /* F41 */ Mod4Mask, "\033[15;6~", 0, 0, 0},
- { XK_F5, /* F53 */ Mod1Mask, "\033[15;3~", 0, 0, 0},
- { XK_F6, XK_NO_MOD, "\033[17~", 0, 0, 0},
- { XK_F6, /* F18 */ ShiftMask, "\033[17;2~", 0, 0, 0},
- { XK_F6, /* F30 */ ControlMask, "\033[17;5~", 0, 0, 0},
- { XK_F6, /* F42 */ Mod4Mask, "\033[17;6~", 0, 0, 0},
- { XK_F6, /* F54 */ Mod1Mask, "\033[17;3~", 0, 0, 0},
- { XK_F7, XK_NO_MOD, "\033[18~", 0, 0, 0},
- { XK_F7, /* F19 */ ShiftMask, "\033[18;2~", 0, 0, 0},
- { XK_F7, /* F31 */ ControlMask, "\033[18;5~", 0, 0, 0},
- { XK_F7, /* F43 */ Mod4Mask, "\033[18;6~", 0, 0, 0},
- { XK_F7, /* F55 */ Mod1Mask, "\033[18;3~", 0, 0, 0},
- { XK_F8, XK_NO_MOD, "\033[19~", 0, 0, 0},
- { XK_F8, /* F20 */ ShiftMask, "\033[19;2~", 0, 0, 0},
- { XK_F8, /* F32 */ ControlMask, "\033[19;5~", 0, 0, 0},
- { XK_F8, /* F44 */ Mod4Mask, "\033[19;6~", 0, 0, 0},
- { XK_F8, /* F56 */ Mod1Mask, "\033[19;3~", 0, 0, 0},
- { XK_F9, XK_NO_MOD, "\033[20~", 0, 0, 0},
- { XK_F9, /* F21 */ ShiftMask, "\033[20;2~", 0, 0, 0},
- { XK_F9, /* F33 */ ControlMask, "\033[20;5~", 0, 0, 0},
- { XK_F9, /* F45 */ Mod4Mask, "\033[20;6~", 0, 0, 0},
- { XK_F9, /* F57 */ Mod1Mask, "\033[20;3~", 0, 0, 0},
- { XK_F10, XK_NO_MOD, "\033[21~", 0, 0, 0},
- { XK_F10, /* F22 */ ShiftMask, "\033[21;2~", 0, 0, 0},
- { XK_F10, /* F34 */ ControlMask, "\033[21;5~", 0, 0, 0},
- { XK_F10, /* F46 */ Mod4Mask, "\033[21;6~", 0, 0, 0},
- { XK_F10, /* F58 */ Mod1Mask, "\033[21;3~", 0, 0, 0},
- { XK_F11, XK_NO_MOD, "\033[23~", 0, 0, 0},
- { XK_F11, /* F23 */ ShiftMask, "\033[23;2~", 0, 0, 0},
- { XK_F11, /* F35 */ ControlMask, "\033[23;5~", 0, 0, 0},
- { XK_F11, /* F47 */ Mod4Mask, "\033[23;6~", 0, 0, 0},
- { XK_F11, /* F59 */ Mod1Mask, "\033[23;3~", 0, 0, 0},
- { XK_F12, XK_NO_MOD, "\033[24~", 0, 0, 0},
- { XK_F12, /* F24 */ ShiftMask, "\033[24;2~", 0, 0, 0},
- { XK_F12, /* F36 */ ControlMask, "\033[24;5~", 0, 0, 0},
- { XK_F12, /* F48 */ Mod4Mask, "\033[24;6~", 0, 0, 0},
- { XK_F12, /* F60 */ Mod1Mask, "\033[24;3~", 0, 0, 0},
- { XK_F13, XK_NO_MOD, "\033[1;2P", 0, 0, 0},
- { XK_F14, XK_NO_MOD, "\033[1;2Q", 0, 0, 0},
- { XK_F15, XK_NO_MOD, "\033[1;2R", 0, 0, 0},
- { XK_F16, XK_NO_MOD, "\033[1;2S", 0, 0, 0},
- { XK_F17, XK_NO_MOD, "\033[15;2~", 0, 0, 0},
- { XK_F18, XK_NO_MOD, "\033[17;2~", 0, 0, 0},
- { XK_F19, XK_NO_MOD, "\033[18;2~", 0, 0, 0},
- { XK_F20, XK_NO_MOD, "\033[19;2~", 0, 0, 0},
- { XK_F21, XK_NO_MOD, "\033[20;2~", 0, 0, 0},
- { XK_F22, XK_NO_MOD, "\033[21;2~", 0, 0, 0},
- { XK_F23, XK_NO_MOD, "\033[23;2~", 0, 0, 0},
- { XK_F24, XK_NO_MOD, "\033[24;2~", 0, 0, 0},
- { XK_F25, XK_NO_MOD, "\033[1;5P", 0, 0, 0},
- { XK_F26, XK_NO_MOD, "\033[1;5Q", 0, 0, 0},
- { XK_F27, XK_NO_MOD, "\033[1;5R", 0, 0, 0},
- { XK_F28, XK_NO_MOD, "\033[1;5S", 0, 0, 0},
- { XK_F29, XK_NO_MOD, "\033[15;5~", 0, 0, 0},
- { XK_F30, XK_NO_MOD, "\033[17;5~", 0, 0, 0},
- { XK_F31, XK_NO_MOD, "\033[18;5~", 0, 0, 0},
- { XK_F32, XK_NO_MOD, "\033[19;5~", 0, 0, 0},
- { XK_F33, XK_NO_MOD, "\033[20;5~", 0, 0, 0},
- { XK_F34, XK_NO_MOD, "\033[21;5~", 0, 0, 0},
- { XK_F35, XK_NO_MOD, "\033[23;5~", 0, 0, 0},
+ /* keysym mask string appkey appcursor */
+ { XK_KP_Home, ShiftMask, "\033[2J", 0, -1},
+ { XK_KP_Home, ShiftMask, "\033[1;2H", 0, +1},
+ { XK_KP_Home, XK_ANY_MOD, "\033[H", 0, -1},
+ { XK_KP_Home, XK_ANY_MOD, "\033[1~", 0, +1},
+ { XK_KP_Up, XK_ANY_MOD, "\033Ox", +1, 0},
+ { XK_KP_Up, XK_ANY_MOD, "\033[A", 0, -1},
+ { XK_KP_Up, XK_ANY_MOD, "\033OA", 0, +1},
+ { XK_KP_Down, XK_ANY_MOD, "\033Or", +1, 0},
+ { XK_KP_Down, XK_ANY_MOD, "\033[B", 0, -1},
+ { XK_KP_Down, XK_ANY_MOD, "\033OB", 0, +1},
+ { XK_KP_Left, XK_ANY_MOD, "\033Ot", +1, 0},
+ { XK_KP_Left, XK_ANY_MOD, "\033[D", 0, -1},
+ { XK_KP_Left, XK_ANY_MOD, "\033OD", 0, +1},
+ { XK_KP_Right, XK_ANY_MOD, "\033Ov", +1, 0},
+ { XK_KP_Right, XK_ANY_MOD, "\033[C", 0, -1},
+ { XK_KP_Right, XK_ANY_MOD, "\033OC", 0, +1},
+ { XK_KP_Prior, ShiftMask, "\033[5;2~", 0, 0},
+ { XK_KP_Prior, XK_ANY_MOD, "\033[5~", 0, 0},
+ { XK_KP_Begin, XK_ANY_MOD, "\033[E", 0, 0},
+ { XK_KP_End, ControlMask, "\033[J", -1, 0},
+ { XK_KP_End, ControlMask, "\033[1;5F", +1, 0},
+ { XK_KP_End, ShiftMask, "\033[K", -1, 0},
+ { XK_KP_End, ShiftMask, "\033[1;2F", +1, 0},
+ { XK_KP_End, XK_ANY_MOD, "\033[4~", 0, 0},
+ { XK_KP_Next, ShiftMask, "\033[6;2~", 0, 0},
+ { XK_KP_Next, XK_ANY_MOD, "\033[6~", 0, 0},
+ { XK_KP_Insert, ShiftMask, "\033[2;2~", +1, 0},
+ { XK_KP_Insert, ShiftMask, "\033[4l", -1, 0},
+ { XK_KP_Insert, ControlMask, "\033[L", -1, 0},
+ { XK_KP_Insert, ControlMask, "\033[2;5~", +1, 0},
+ { XK_KP_Insert, XK_ANY_MOD, "\033[4h", -1, 0},
+ { XK_KP_Insert, XK_ANY_MOD, "\033[2~", +1, 0},
+ { XK_KP_Delete, ControlMask, "\033[M", -1, 0},
+ { XK_KP_Delete, ControlMask, "\033[3;5~", +1, 0},
+ { XK_KP_Delete, ShiftMask, "\033[2K", -1, 0},
+ { XK_KP_Delete, ShiftMask, "\033[3;2~", +1, 0},
+ { XK_KP_Delete, XK_ANY_MOD, "\033[P", -1, 0},
+ { XK_KP_Delete, XK_ANY_MOD, "\033[3~", +1, 0},
+ { XK_KP_Multiply, XK_ANY_MOD, "\033Oj", +2, 0},
+ { XK_KP_Add, XK_ANY_MOD, "\033Ok", +2, 0},
+ { XK_KP_Enter, XK_ANY_MOD, "\033OM", +2, 0},
+ { XK_KP_Enter, XK_ANY_MOD, "\r", -1, 0},
+ { XK_KP_Subtract, XK_ANY_MOD, "\033Om", +2, 0},
+ { XK_KP_Decimal, XK_ANY_MOD, "\033On", +2, 0},
+ { XK_KP_Divide, XK_ANY_MOD, "\033Oo", +2, 0},
+ { XK_KP_0, XK_ANY_MOD, "\033Op", +2, 0},
+ { XK_KP_1, XK_ANY_MOD, "\033Oq", +2, 0},
+ { XK_KP_2, XK_ANY_MOD, "\033Or", +2, 0},
+ { XK_KP_3, XK_ANY_MOD, "\033Os", +2, 0},
+ { XK_KP_4, XK_ANY_MOD, "\033Ot", +2, 0},
+ { XK_KP_5, XK_ANY_MOD, "\033Ou", +2, 0},
+ { XK_KP_6, XK_ANY_MOD, "\033Ov", +2, 0},
+ { XK_KP_7, XK_ANY_MOD, "\033Ow", +2, 0},
+ { XK_KP_8, XK_ANY_MOD, "\033Ox", +2, 0},
+ { XK_KP_9, XK_ANY_MOD, "\033Oy", +2, 0},
+ { XK_Up, ShiftMask, "\033[1;2A", 0, 0},
+ { XK_Up, Mod1Mask, "\033[1;3A", 0, 0},
+ { XK_Up, ShiftMask|Mod1Mask,"\033[1;4A", 0, 0},
+ { XK_Up, ControlMask, "\033[1;5A", 0, 0},
+ { XK_Up, ShiftMask|ControlMask,"\033[1;6A", 0, 0},
+ { XK_Up, ControlMask|Mod1Mask,"\033[1;7A", 0, 0},
+ { XK_Up,ShiftMask|ControlMask|Mod1Mask,"\033[1;8A", 0, 0},
+ { XK_Up, XK_ANY_MOD, "\033[A", 0, -1},
+ { XK_Up, XK_ANY_MOD, "\033OA", 0, +1},
+ { XK_Down, ShiftMask, "\033[1;2B", 0, 0},
+ { XK_Down, Mod1Mask, "\033[1;3B", 0, 0},
+ { XK_Down, ShiftMask|Mod1Mask,"\033[1;4B", 0, 0},
+ { XK_Down, ControlMask, "\033[1;5B", 0, 0},
+ { XK_Down, ShiftMask|ControlMask,"\033[1;6B", 0, 0},
+ { XK_Down, ControlMask|Mod1Mask,"\033[1;7B", 0, 0},
+ { XK_Down,ShiftMask|ControlMask|Mod1Mask,"\033[1;8B",0, 0},
+ { XK_Down, XK_ANY_MOD, "\033[B", 0, -1},
+ { XK_Down, XK_ANY_MOD, "\033OB", 0, +1},
+ { XK_Left, ShiftMask, "\033[1;2D", 0, 0},
+ { XK_Left, Mod1Mask, "\033[1;3D", 0, 0},
+ { XK_Left, ShiftMask|Mod1Mask,"\033[1;4D", 0, 0},
+ { XK_Left, ControlMask, "\033[1;5D", 0, 0},
+ { XK_Left, ShiftMask|ControlMask,"\033[1;6D", 0, 0},
+ { XK_Left, ControlMask|Mod1Mask,"\033[1;7D", 0, 0},
+ { XK_Left,ShiftMask|ControlMask|Mod1Mask,"\033[1;8D",0, 0},
+ { XK_Left, XK_ANY_MOD, "\033[D", 0, -1},
+ { XK_Left, XK_ANY_MOD, "\033OD", 0, +1},
+ { XK_Right, ShiftMask, "\033[1;2C", 0, 0},
+ { XK_Right, Mod1Mask, "\033[1;3C", 0, 0},
+ { XK_Right, ShiftMask|Mod1Mask,"\033[1;4C", 0, 0},
+ { XK_Right, ControlMask, "\033[1;5C", 0, 0},
+ { XK_Right, ShiftMask|ControlMask,"\033[1;6C", 0, 0},
+ { XK_Right, ControlMask|Mod1Mask,"\033[1;7C", 0, 0},
+ { XK_Right,ShiftMask|ControlMask|Mod1Mask,"\033[1;8C",0, 0},
+ { XK_Right, XK_ANY_MOD, "\033[C", 0, -1},
+ { XK_Right, XK_ANY_MOD, "\033OC", 0, +1},
+ { XK_ISO_Left_Tab, ShiftMask, "\033[Z", 0, 0},
+ { XK_Return, Mod1Mask, "\033\r", 0, 0},
+ { XK_Return, XK_ANY_MOD, "\r", 0, 0},
+ { XK_Insert, ShiftMask, "\033[4l", -1, 0},
+ { XK_Insert, ShiftMask, "\033[2;2~", +1, 0},
+ { XK_Insert, ControlMask, "\033[L", -1, 0},
+ { XK_Insert, ControlMask, "\033[2;5~", +1, 0},
+ { XK_Insert, XK_ANY_MOD, "\033[4h", -1, 0},
+ { XK_Insert, XK_ANY_MOD, "\033[2~", +1, 0},
+ { XK_Delete, ControlMask, "\033[M", -1, 0},
+ { XK_Delete, ControlMask, "\033[3;5~", +1, 0},
+ { XK_Delete, ShiftMask, "\033[2K", -1, 0},
+ { XK_Delete, ShiftMask, "\033[3;2~", +1, 0},
+ { XK_Delete, XK_ANY_MOD, "\033[P", -1, 0},
+ { XK_Delete, XK_ANY_MOD, "\033[3~", +1, 0},
+ { XK_BackSpace, XK_NO_MOD, "\177", 0, 0},
+ { XK_BackSpace, Mod1Mask, "\033\177", 0, 0},
+ { XK_Home, ShiftMask, "\033[2J", 0, -1},
+ { XK_Home, ShiftMask, "\033[1;2H", 0, +1},
+ { XK_Home, XK_ANY_MOD, "\033[H", 0, -1},
+ { XK_Home, XK_ANY_MOD, "\033[1~", 0, +1},
+ { XK_End, ControlMask, "\033[J", -1, 0},
+ { XK_End, ControlMask, "\033[1;5F", +1, 0},
+ { XK_End, ShiftMask, "\033[K", -1, 0},
+ { XK_End, ShiftMask, "\033[1;2F", +1, 0},
+ { XK_End, XK_ANY_MOD, "\033[4~", 0, 0},
+ { XK_Prior, ControlMask, "\033[5;5~", 0, 0},
+ { XK_Prior, ShiftMask, "\033[5;2~", 0, 0},
+ { XK_Prior, XK_ANY_MOD, "\033[5~", 0, 0},
+ { XK_Next, ControlMask, "\033[6;5~", 0, 0},
+ { XK_Next, ShiftMask, "\033[6;2~", 0, 0},
+ { XK_Next, XK_ANY_MOD, "\033[6~", 0, 0},
+ { XK_F1, XK_NO_MOD, "\033OP" , 0, 0},
+ { XK_F1, /* F13 */ ShiftMask, "\033[1;2P", 0, 0},
+ { XK_F1, /* F25 */ ControlMask, "\033[1;5P", 0, 0},
+ { XK_F1, /* F37 */ Mod4Mask, "\033[1;6P", 0, 0},
+ { XK_F1, /* F49 */ Mod1Mask, "\033[1;3P", 0, 0},
+ { XK_F1, /* F61 */ Mod3Mask, "\033[1;4P", 0, 0},
+ { XK_F2, XK_NO_MOD, "\033OQ" , 0, 0},
+ { XK_F2, /* F14 */ ShiftMask, "\033[1;2Q", 0, 0},
+ { XK_F2, /* F26 */ ControlMask, "\033[1;5Q", 0, 0},
+ { XK_F2, /* F38 */ Mod4Mask, "\033[1;6Q", 0, 0},
+ { XK_F2, /* F50 */ Mod1Mask, "\033[1;3Q", 0, 0},
+ { XK_F2, /* F62 */ Mod3Mask, "\033[1;4Q", 0, 0},
+ { XK_F3, XK_NO_MOD, "\033OR" , 0, 0},
+ { XK_F3, /* F15 */ ShiftMask, "\033[1;2R", 0, 0},
+ { XK_F3, /* F27 */ ControlMask, "\033[1;5R", 0, 0},
+ { XK_F3, /* F39 */ Mod4Mask, "\033[1;6R", 0, 0},
+ { XK_F3, /* F51 */ Mod1Mask, "\033[1;3R", 0, 0},
+ { XK_F3, /* F63 */ Mod3Mask, "\033[1;4R", 0, 0},
+ { XK_F4, XK_NO_MOD, "\033OS" , 0, 0},
+ { XK_F4, /* F16 */ ShiftMask, "\033[1;2S", 0, 0},
+ { XK_F4, /* F28 */ ControlMask, "\033[1;5S", 0, 0},
+ { XK_F4, /* F40 */ Mod4Mask, "\033[1;6S", 0, 0},
+ { XK_F4, /* F52 */ Mod1Mask, "\033[1;3S", 0, 0},
+ { XK_F5, XK_NO_MOD, "\033[15~", 0, 0},
+ { XK_F5, /* F17 */ ShiftMask, "\033[15;2~", 0, 0},
+ { XK_F5, /* F29 */ ControlMask, "\033[15;5~", 0, 0},
+ { XK_F5, /* F41 */ Mod4Mask, "\033[15;6~", 0, 0},
+ { XK_F5, /* F53 */ Mod1Mask, "\033[15;3~", 0, 0},
+ { XK_F6, XK_NO_MOD, "\033[17~", 0, 0},
+ { XK_F6, /* F18 */ ShiftMask, "\033[17;2~", 0, 0},
+ { XK_F6, /* F30 */ ControlMask, "\033[17;5~", 0, 0},
+ { XK_F6, /* F42 */ Mod4Mask, "\033[17;6~", 0, 0},
+ { XK_F6, /* F54 */ Mod1Mask, "\033[17;3~", 0, 0},
+ { XK_F7, XK_NO_MOD, "\033[18~", 0, 0},
+ { XK_F7, /* F19 */ ShiftMask, "\033[18;2~", 0, 0},
+ { XK_F7, /* F31 */ ControlMask, "\033[18;5~", 0, 0},
+ { XK_F7, /* F43 */ Mod4Mask, "\033[18;6~", 0, 0},
+ { XK_F7, /* F55 */ Mod1Mask, "\033[18;3~", 0, 0},
+ { XK_F8, XK_NO_MOD, "\033[19~", 0, 0},
+ { XK_F8, /* F20 */ ShiftMask, "\033[19;2~", 0, 0},
+ { XK_F8, /* F32 */ ControlMask, "\033[19;5~", 0, 0},
+ { XK_F8, /* F44 */ Mod4Mask, "\033[19;6~", 0, 0},
+ { XK_F8, /* F56 */ Mod1Mask, "\033[19;3~", 0, 0},
+ { XK_F9, XK_NO_MOD, "\033[20~", 0, 0},
+ { XK_F9, /* F21 */ ShiftMask, "\033[20;2~", 0, 0},
+ { XK_F9, /* F33 */ ControlMask, "\033[20;5~", 0, 0},
+ { XK_F9, /* F45 */ Mod4Mask, "\033[20;6~", 0, 0},
+ { XK_F9, /* F57 */ Mod1Mask, "\033[20;3~", 0, 0},
+ { XK_F10, XK_NO_MOD, "\033[21~", 0, 0},
+ { XK_F10, /* F22 */ ShiftMask, "\033[21;2~", 0, 0},
+ { XK_F10, /* F34 */ ControlMask, "\033[21;5~", 0, 0},
+ { XK_F10, /* F46 */ Mod4Mask, "\033[21;6~", 0, 0},
+ { XK_F10, /* F58 */ Mod1Mask, "\033[21;3~", 0, 0},
+ { XK_F11, XK_NO_MOD, "\033[23~", 0, 0},
+ { XK_F11, /* F23 */ ShiftMask, "\033[23;2~", 0, 0},
+ { XK_F11, /* F35 */ ControlMask, "\033[23;5~", 0, 0},
+ { XK_F11, /* F47 */ Mod4Mask, "\033[23;6~", 0, 0},
+ { XK_F11, /* F59 */ Mod1Mask, "\033[23;3~", 0, 0},
+ { XK_F12, XK_NO_MOD, "\033[24~", 0, 0},
+ { XK_F12, /* F24 */ ShiftMask, "\033[24;2~", 0, 0},
+ { XK_F12, /* F36 */ ControlMask, "\033[24;5~", 0, 0},
+ { XK_F12, /* F48 */ Mod4Mask, "\033[24;6~", 0, 0},
+ { XK_F12, /* F60 */ Mod1Mask, "\033[24;3~", 0, 0},
+ { XK_F13, XK_NO_MOD, "\033[1;2P", 0, 0},
+ { XK_F14, XK_NO_MOD, "\033[1;2Q", 0, 0},
+ { XK_F15, XK_NO_MOD, "\033[1;2R", 0, 0},
+ { XK_F16, XK_NO_MOD, "\033[1;2S", 0, 0},
+ { XK_F17, XK_NO_MOD, "\033[15;2~", 0, 0},
+ { XK_F18, XK_NO_MOD, "\033[17;2~", 0, 0},
+ { XK_F19, XK_NO_MOD, "\033[18;2~", 0, 0},
+ { XK_F20, XK_NO_MOD, "\033[19;2~", 0, 0},
+ { XK_F21, XK_NO_MOD, "\033[20;2~", 0, 0},
+ { XK_F22, XK_NO_MOD, "\033[21;2~", 0, 0},
+ { XK_F23, XK_NO_MOD, "\033[23;2~", 0, 0},
+ { XK_F24, XK_NO_MOD, "\033[24;2~", 0, 0},
+ { XK_F25, XK_NO_MOD, "\033[1;5P", 0, 0},
+ { XK_F26, XK_NO_MOD, "\033[1;5Q", 0, 0},
+ { XK_F27, XK_NO_MOD, "\033[1;5R", 0, 0},
+ { XK_F28, XK_NO_MOD, "\033[1;5S", 0, 0},
+ { XK_F29, XK_NO_MOD, "\033[15;5~", 0, 0},
+ { XK_F30, XK_NO_MOD, "\033[17;5~", 0, 0},
+ { XK_F31, XK_NO_MOD, "\033[18;5~", 0, 0},
+ { XK_F32, XK_NO_MOD, "\033[19;5~", 0, 0},
+ { XK_F33, XK_NO_MOD, "\033[20;5~", 0, 0},
+ { XK_F34, XK_NO_MOD, "\033[21;5~", 0, 0},
+ { XK_F35, XK_NO_MOD, "\033[23;5~", 0, 0},
};
/*
@@ -495,7 +448,7 @@ static Key key[] = {
* ButtonRelease and MotionNotify.
* If no match is found, regular selection is used.
*/
-uint selmasks[] = {
+static uint selmasks[] = {
[SEL_RECTANGULAR] = Mod1Mask,
};
@@ -503,8 +456,7 @@ uint selmasks[] = {
* Printable characters in ASCII, used to estimate the advance width
* of single wide characters.
*/
-char ascii_printable[] =
+static char ascii_printable[] =
" !\"#$%&'()*+,-./0123456789:;<=>?"
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
"`abcdefghijklmnopqrstuvwxyz{|}~";
-
diff --git a/config.mk b/config.mk
index c84c5ee..e676105 100644
--- a/config.mk
+++ b/config.mk
@@ -1,28 +1,33 @@
# st version
-VERSION = 0.7
+VERSION = 0.8.1
# Customize below to fit your system
# paths
PREFIX = /usr/local
-MANPREFIX = ${PREFIX}/share/man
+MANPREFIX = $(PREFIX)/share/man
X11INC = /usr/X11R6/include
X11LIB = /usr/X11R6/lib
# includes and libs
-INCS = -I. -I/usr/include -I${X11INC} \
+INCS = -I$(X11INC) \
`pkg-config --cflags fontconfig` \
`pkg-config --cflags freetype2`
-LIBS = -L/usr/lib -lc -L${X11LIB} -lm -lrt -lX11 -lutil -lXft \
- `pkg-config --libs fontconfig` \
+LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \
+ `pkg-config --libs fontconfig` \
`pkg-config --libs freetype2`
# flags
-CPPFLAGS = -DVERSION=\"${VERSION}\" -D_XOPEN_SOURCE=600
-CFLAGS += -g -std=c99 -pedantic -Wall -Wvariadic-macros -Os ${INCS} ${CPPFLAGS}
-LDFLAGS += -g ${LIBS}
+CPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600
+STCFLAGS = $(INCS) $(CPPFLAGS) $(CFLAGS)
+STLDFLAGS = $(LIBS) $(LDFLAGS)
-# compiler and linker
-# CC = cc
+# OpenBSD:
+#CPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600 -D_BSD_SOURCE
+#LIBS = -L$(X11LIB) -lm -lX11 -lutil -lXft \
+# `pkg-config --libs fontconfig` \
+# `pkg-config --libs freetype2`
+# compiler and linker
+# CC = c99
diff --git a/st.1 b/st.1
index bbca7e5..81bceff 100644
--- a/st.1
+++ b/st.1
@@ -120,7 +120,7 @@ st executes
instead of the shell. If this is used it
.B must be the last option
on the command line, as in xterm / rxvt.
-This option is only intended for compability,
+This option is only intended for compatibility,
and all the remaining arguments are used as a command
even without it.
.SH SHORTCUTS
diff --git a/st.c b/st.c
index 8d4a9f2..76bb3ea 100644
--- a/st.c
+++ b/st.c
@@ -3,38 +3,22 @@
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
-#include <locale.h>
#include <pwd.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
-#include <stdint.h>
#include <sys/ioctl.h>
#include <sys/select.h>
-#include <sys/stat.h>
-#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <termios.h>
-#include <time.h>
#include <unistd.h>
-#include <libgen.h>
-#include <fontconfig/fontconfig.h>
#include <wchar.h>
-/* X11 */
-#include <X11/cursorfont.h>
-#include <X11/Xft/Xft.h>
-
-char *argv0;
-
-#define Glyph Glyph_
-#define Font Font_
-
-#include "win.h"
#include "st.h"
+#include "win.h"
#if defined(__linux)
#include <pty.h>
@@ -46,21 +30,33 @@ char *argv0;
/* Arbitrary sizes */
#define UTF_INVALID 0xFFFD
+#define UTF_SIZ 4
#define ESC_BUF_SIZ (128*UTF_SIZ)
#define ESC_ARG_SIZ 16
#define STR_BUF_SIZ ESC_BUF_SIZ
#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 DEFAULT(a, b) (a) = (a) ? (a) : (b)
#define ISCONTROLC0(c) (BETWEEN(c, 0, 0x1f) || (c) == '\177')
#define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f))
#define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c))
#define ISDELIM(u) (utf8strchr(worddelimiters, u) != NULL)
/* constants */
-#define ISO14755CMD "dmenu -w %lu -p codepoint: </dev/null"
+#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,
@@ -94,6 +90,51 @@ enum escape_state {
ESC_DCS =128,
};
+typedef struct {
+ Glyph attr; /* current char attributes */
+ int x;
+ int y;
+ char state;
+} TCursor;
+
+typedef struct {
+ int mode;
+ int type;
+ int snap;
+ /*
+ * Selection variables:
+ * nb – normalized coordinates of the beginning of the selection
+ * ne – normalized coordinates of the end of the selection
+ * ob – original coordinates of the beginning of the selection
+ * oe – original coordinates of the end of the selection
+ */
+ struct {
+ int x, y;
+ } nb, ne, ob, oe;
+
+ int alt;
+} Selection;
+
+/* Internal representation of the screen */
+typedef struct {
+ int row; /* nb row */
+ int col; /* nb col */
+ Line *line; /* screen */
+ Line *alt; /* alternate screen */
+ int *dirty; /* dirtyness of lines */
+ TCursor c; /* cursor */
+ int ocx; /* old cursor col */
+ int ocy; /* old cursor row */
+ int top; /* top scroll limit */
+ int bot; /* bottom scroll limit */
+ int mode; /* terminal mode flags */
+ int esc; /* escape state flags */
+ char trantbl[4]; /* charset table translation */
+ int charset; /* current charset */
+ int icharset; /* selected charset for sequence */
+ int *tabs;
+} Term;
+
/* CSI Escape sequence structs */
/* ESC '[' [[ [<priv>] <arg> [;]] <mode> [<mode>]] */
typedef struct {
@@ -115,36 +156,10 @@ typedef struct {
int narg; /* nb of args */
} STREscape;
-typedef struct {
- KeySym k;
- uint mask;
- char *s;
- /* three valued logic variables: 0 indifferent, 1 on, -1 off */
- signed char appkey; /* application keypad */
- signed char appcursor; /* application cursor */
- signed char crlf; /* crlf mode */
-} Key;
-
-/* 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 zoomreset(const Arg *);
-static void printsel(const Arg *);
-static void printscreen(const Arg *) ;
-static void iso14755(const Arg *);
-static void toggleprinter(const Arg *);
-static void sendbreak(const Arg *);
-
-/* config.h for applying patches and the configuration. */
-#include "config.h"
-
-static void execsh(void);
-static void stty(void);
+static void execsh(char *, char **);
+static void stty(char **);
static void sigchld(int);
+static void ttywriteraw(const char *, size_t);
static void csidump(void);
static void csihandle(void);
@@ -173,16 +188,16 @@ static void tnewline(int);
static void tputtab(int);
static void tputc(Rune);
static void treset(void);
-static void tresize(int, int);
static void tscrollup(int, int);
static void tscrolldown(int, int);
static void tsetattr(int *, int);
static void tsetchar(Rune, Glyph *, int, int);
+static void tsetdirt(int, int);
static void tsetscroll(int, int);
static void tswapscreen(void);
static void tsetmode(int, int, int *, int);
+static int twrite(const char *, int, int);
static void tfulldirt(void);
-static void techo(Rune);
static void tcontrolcode(uchar );
static void tdectest(char );
static void tdefutf8(char);
@@ -190,54 +205,37 @@ static int32_t tdefcolor(int *, int *, int);
static void tdeftran(char);
static void tstrsequence(uchar);
+static void drawregion(int, int, int, int);
+
+static void selnormalize(void);
static void selscroll(int, int);
static void selsnap(int *, int *, int);
+static size_t utf8decode(const char *, Rune *, size_t);
static Rune utf8decodebyte(char, size_t *);
static char utf8encodebyte(Rune, size_t);
-static char *utf8strchr(char *s, Rune u);
+static char *utf8strchr(char *, Rune);
static size_t utf8validate(Rune *, size_t);
static char *base64dec(const char *);
+static char base64dec_getc(const char **);
static ssize_t xwrite(int, const char *, size_t);
-static void *xrealloc(void *, size_t);
/* Globals */
-TermWindow win;
-Term term;
-Selection sel;
-int cmdfd;
-pid_t pid;
-char **opt_cmd = NULL;
-char *opt_class = NULL;
-char *opt_embed = NULL;
-char *opt_font = NULL;
-char *opt_io = NULL;
-char *opt_line = NULL;
-char *opt_name = NULL;
-char *opt_title = NULL;
-int oldbutton = 3; /* button event on startup: 3 = release */
-
+static Term term;
+static Selection sel;
static CSIEscape csiescseq;
static STREscape strescseq;
static int iofd = 1;
-
-char *usedfont = NULL;
-double usedfontsize = 0;
-double defaultfontsize = 0;
+static int cmdfd;
+static pid_t pid;
static uchar utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0};
static uchar utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8};
static Rune utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000};
static Rune utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF};
-/* config.h array lengths */
-size_t colornamelen = LEN(colorname);
-size_t mshortcutslen = LEN(mshortcuts);
-size_t shortcutslen = LEN(shortcuts);
-size_t selmaskslen = LEN(selmasks);
-
ssize_t
xwrite(int fd, const char *s, size_t len)
{
@@ -258,10 +256,10 @@ xwrite(int fd, const char *s, size_t len)
void *
xmalloc(size_t len)
{
- void *p = malloc(len);
+ void *p;
- if (!p)
- die("Out of memory\n");
+ if (!(p = malloc(len)))
+ die("malloc: %s\n", strerror(errno));
return p;
}
@@ -270,7 +268,7 @@ void *
xrealloc(void *p, size_t len)
{
if ((p = realloc(p, len)) == NULL)
- die("Out of memory\n");
+ die("realloc: %s\n", strerror(errno));
return p;
}
@@ -279,13 +277,13 @@ char *
xstrdup(char *s)
{
if ((s = strdup(s)) == NULL)
- die("Out of memory\n");
+ die("strdup: %s\n", strerror(errno));
return s;
}
size_t
-utf8decode(char *c, Rune *u, size_t clen)
+utf8decode(const char *c, Rune *u, size_t clen)
{
size_t i, j, len, type;
Rune udecoded;
@@ -386,6 +384,13 @@ static const char base64_digits[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
+char
+base64dec_getc(const char **src)
+{
+ while (**src && !isprint(**src)) (*src)++;
+ return *((*src)++);
+}
+
char *
base64dec(const char *src)
{
@@ -393,13 +398,13 @@ base64dec(const char *src)
char *result, *dst;
if (in_len % 4)
- return NULL;
+ in_len += 4 - (in_len % 4);
result = dst = xmalloc(in_len / 4 * 3 + 1);
while (*src) {
- int a = base64_digits[(unsigned char) *src++];
- int b = base64_digits[(unsigned char) *src++];
- int c = base64_digits[(unsigned char) *src++];
- int d = base64_digits[(unsigned char) *src++];
+ int a = base64_digits[(unsigned char) base64dec_getc(&src)];
+ int b = 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)];
*dst++ = (a << 2) | ((b & 0x30) >> 4);
if (c == -1)
@@ -416,45 +421,69 @@ base64dec(const char *src)
void
selinit(void)
{
- clock_gettime(CLOCK_MONOTONIC, &sel.tclick1);
- clock_gettime(CLOCK_MONOTONIC, &sel.tclick2);
sel.mode = SEL_IDLE;
sel.snap = 0;
sel.ob.x = -1;
- sel.primary = NULL;
- sel.clipboard = NULL;
}
int
-x2col(int x)
+tlinelen(int y)
{
- x -= borderpx;
- x /= win.cw;
+ int i = term.col;
+
+ if (term.line[y][i - 1].mode & ATTR_WRAP)
+ return i;
+
+ while (i > 0 && term.line[y][i - 1].u == ' ')
+ --i;
- return LIMIT(x, 0, term.col-1);
+ return i;
}
-int
-y2row(int y)
+void
+selstart(int col, int row, int snap)
{
- y -= borderpx;
- y /= win.ch;
+ selclear();
+ sel.mode = SEL_EMPTY;
+ sel.type = SEL_REGULAR;
+ sel.alt = IS_SET(MODE_ALTSCREEN);
+ sel.snap = snap;
+ sel.oe.x = sel.ob.x = col;
+ sel.oe.y = sel.ob.y = row;
+ selnormalize();
- return LIMIT(y, 0, term.row-1);
+ if (sel.snap != 0)
+ sel.mode = SEL_READY;
+ tsetdirt(sel.nb.y, sel.ne.y);
}
-int
-tlinelen(int y)
+void
+selextend(int col, int row, int type, int done)
{
- int i = term.col;
+ int oldey, oldex, oldsby, oldsey, oldtype;
- if (term.line[y][i - 1].mode & ATTR_WRAP)
- return i;
+ if (sel.mode == SEL_IDLE)
+ return;
+ if (done && sel.mode == SEL_EMPTY) {
+ selclear();
+ return;
+ }
- while (i > 0 && term.line[y][i - 1].u == ' ')
- --i;
+ oldey = sel.oe.y;
+ oldex = sel.oe.x;
+ oldsby = sel.nb.y;
+ oldsey = sel.ne.y;
+ oldtype = sel.type;
- return i;
+ sel.oe.x = col;
+ sel.oe.y = row;
+ selnormalize();
+ sel.type = type;
+
+ if (oldey != sel.oe.y || oldex != sel.oe.x || oldtype != sel.type)
+ tsetdirt(MIN(sel.nb.y, oldsby), MAX(sel.ne.y, oldsey));
+
+ sel.mode = done ? SEL_IDLE : SEL_READY;
}
void
@@ -488,7 +517,8 @@ selnormalize(void)
int
selected(int x, int y)
{
- if (sel.mode == SEL_EMPTY)
+ if (sel.mode == SEL_EMPTY || sel.ob.x == -1 ||
+ sel.alt != IS_SET(MODE_ALTSCREEN))
return 0;
if (sel.type == SEL_RECTANGULAR)
@@ -628,24 +658,6 @@ getsel(void)
}
void
-selpaste(const Arg *dummy)
-{
- xselpaste();
-}
-
-void
-clipcopy(const Arg *dummy)
-{
- xclipcopy();
-}
-
-void
-clippaste(const Arg *dummy)
-{
- xclippaste();
-}
-
-void
selclear(void)
{
if (sel.ob.x == -1)
@@ -667,29 +679,29 @@ die(const char *errstr, ...)
}
void
-execsh(void)
+execsh(char *cmd, char **args)
{
- char **args, *sh, *prog;
+ char *sh, *prog;
const struct passwd *pw;
errno = 0;
if ((pw = getpwuid(getuid())) == NULL) {
if (errno)
- die("getpwuid:%s\n", strerror(errno));
+ die("getpwuid: %s\n", strerror(errno));
else
die("who are you?\n");
}
if ((sh = getenv("SHELL")) == NULL)
- sh = (pw->pw_shell[0]) ? pw->pw_shell : shell;
+ sh = (pw->pw_shell[0]) ? pw->pw_shell : cmd;
- if (opt_cmd)
- prog = opt_cmd[0];
+ if (args)
+ prog = args[0];
else if (utmp)
prog = utmp;
else
prog = sh;
- args = (opt_cmd) ? opt_cmd : (char *[]) {prog, NULL};
+ DEFAULT(args, ((char *[]) {prog, NULL}));
unsetenv("COLUMNS");
unsetenv("LINES");
@@ -699,7 +711,6 @@ execsh(void)
setenv("SHELL", sh, 1);
setenv("HOME", pw->pw_dir, 1);
setenv("TERM", termname, 1);
- xsetenv();
signal(SIGCHLD, SIG_DFL);
signal(SIGHUP, SIG_DFL);
@@ -719,7 +730,7 @@ sigchld(int a)
pid_t p;
if ((p = waitpid(pid, &stat, WNOHANG)) < 0)
- die("Waiting for pid %hd failed: %s\n", pid, strerror(errno));
+ die("waiting for pid %hd failed: %s\n", pid, strerror(errno));
if (pid != p)
return;
@@ -729,9 +740,8 @@ sigchld(int a)
exit(0);
}
-
void
-stty(void)
+stty(char **args)
{
char cmd[_POSIX_ARG_MAX], **p, *q, *s;
size_t n, siz;
@@ -741,7 +751,7 @@ stty(void)
memcpy(cmd, stty_args, n);
q = cmd + n;
siz = sizeof(cmd) - n;
- for (p = opt_cmd; p && (s = *p); ++p) {
+ for (p = args; p && (s = *p); ++p) {
if ((n = strlen(s)) > siz-1)
die("stty parameter length too long\n");
*q++ = ' ';
@@ -751,40 +761,40 @@ stty(void)
}
*q = '\0';
if (system(cmd) != 0)
- perror("Couldn't call stty");
+ perror("Couldn't call stty");
}
-void
-ttynew(void)
+int
+ttynew(char *line, char *cmd, char *out, char **args)
{
int m, s;
- struct winsize w = {term.row, term.col, 0, 0};
- if (opt_io) {
+ if (out) {
term.mode |= MODE_PRINT;
- iofd = (!strcmp(opt_io, "-")) ?
- 1 : open(opt_io, O_WRONLY | O_CREAT, 0666);
+ iofd = (!strcmp(out, "-")) ?
+ 1 : open(out, O_WRONLY | O_CREAT, 0666);
if (iofd < 0) {
fprintf(stderr, "Error opening %s:%s\n",
- opt_io, strerror(errno));
+ out, strerror(errno));
}
}
- if (opt_line) {
- if ((cmdfd = open(opt_line, O_RDWR)) < 0)
- die("open line failed: %s\n", strerror(errno));
+ if (line) {
+ if ((cmdfd = open(line, O_RDWR)) < 0)
+ die("open line '%s' failed: %s\n",
+ line, strerror(errno));
dup2(cmdfd, 0);
- stty();
- return;
+ stty(args);
+ return cmdfd;
}
/* seems to work fine on linux, openbsd and freebsd */
- if (openpty(&m, &s, NULL, NULL, &w) < 0)
+ if (openpty(&m, &s, NULL, NULL, NULL) < 0)
die("openpty failed: %s\n", strerror(errno));
switch (pid = fork()) {
case -1:
- die("fork failed\n");
+ die("fork failed: %s\n", strerror(errno));
break;
case 0:
close(iofd);
@@ -796,14 +806,23 @@ ttynew(void)
die("ioctl TIOCSCTTY failed: %s\n", strerror(errno));
close(s);
close(m);
- execsh();
+#ifdef __OpenBSD__
+ if (pledge("stdio getpw proc exec", NULL) == -1)
+ die("pledge\n");
+#endif
+ execsh(cmd, args);
break;
default:
+#ifdef __OpenBSD__
+ if (pledge("stdio rpath tty proc", NULL) == -1)
+ die("pledge\n");
+#endif
close(s);
cmdfd = m;
signal(SIGCHLD, sigchld);
break;
}
+ return cmdfd;
}
size_t
@@ -811,44 +830,53 @@ ttyread(void)
{
static char buf[BUFSIZ];
static int buflen = 0;
- char *ptr;
- int charsize; /* size of utf8 char in bytes */
- Rune unicodep;
+ int written;
int ret;
/* append read bytes to unprocessed bytes */
if ((ret = read(cmdfd, buf+buflen, LEN(buf)-buflen)) < 0)
- die("Couldn't read from shell: %s\n", strerror(errno));
-
+ die("couldn't read from shell: %s\n", strerror(errno));
buflen += ret;
- ptr = buf;
-
- for (;;) {
- if (IS_SET(MODE_UTF8) && !IS_SET(MODE_SIXEL)) {
- /* process a complete utf8 char */
- charsize = utf8decode(ptr, &unicodep, buflen);
- if (charsize == 0)
- break;
- tputc(unicodep);
- ptr += charsize;
- buflen -= charsize;
- } else {
- if (buflen <= 0)
- break;
- tputc(*ptr++ & 0xFF);
- buflen--;
- }
- }
+ written = twrite(buf, buflen, 0);
+ buflen -= written;
/* keep any uncomplete utf8 char for the next call */
if (buflen > 0)
- memmove(buf, ptr, buflen);
+ memmove(buf, buf + written, buflen);
return ret;
}
void
-ttywrite(const char *s, size_t n)
+ttywrite(const char *s, size_t n, int may_echo)
+{
+ const char *next;
+
+ if (may_echo && IS_SET(MODE_ECHO))
+ twrite(s, n, 1);
+
+ if (!IS_SET(MODE_CRLF)) {
+ ttywriteraw(s, n);
+ return;
+ }
+
+ /* This is similar to how the kernel handles ONLCR for ttys */
+ while (n > 0) {
+ if (*s == '\r') {
+ next = s + 1;
+ ttywriteraw("\r\n", 2);
+ } else {
+ next = memchr(s, '\r', n);
+ DEFAULT(next, s + n);
+ ttywriteraw(s, next - s);
+ }
+ n -= next - s;
+ s = next;
+ }
+}
+
+void
+ttywriteraw(const char *s, size_t n)
{
fd_set wfd, rfd;
ssize_t r;
@@ -905,44 +933,25 @@ write_error:
}
void
-ttysend(char *s, size_t n)
-{
- int len;
- char *t, *lim;
- Rune u;
-
- ttywrite(s, n);
- if (!IS_SET(MODE_ECHO))
- return;
-
- lim = &s[n];
- for (t = s; t < lim; t += len) {
- if (IS_SET(MODE_UTF8) && !IS_SET(MODE_SIXEL)) {
- len = utf8decode(t, &u, n);
- } else {
- u = *t & 0xFF;
- len = 1;
- }
- if (len <= 0)
- break;
- techo(u);
- n -= len;
- }
-}
-
-void
-ttyresize(void)
+ttyresize(int tw, int th)
{
struct winsize w;
w.ws_row = term.row;
w.ws_col = term.col;
- w.ws_xpixel = win.tw;
- w.ws_ypixel = win.th;
+ w.ws_xpixel = tw;
+ w.ws_ypixel = th;
if (ioctl(cmdfd, TIOCSWINSZ, &w) < 0)
fprintf(stderr, "Couldn't set window size: %s\n", strerror(errno));
}
+void
+ttyhangup()
+{
+ /* Send SIGHUP to shell */
+ kill(pid, SIGHUP);
+}
+
int
tattrset(int attr)
{
@@ -1038,8 +1047,6 @@ tnew(int col, int row)
{
term = (Term){ .c = { .attr = { .fg = defaultfg, .bg = defaultbg } } };
tresize(col, row);
- term.numlock = 1;
-
treset();
}
@@ -1402,9 +1409,6 @@ tsetattr(int *attr, int l)
case 9:
term.c.attr.mode |= ATTR_STRUCK;
break;
- case 21:
- term.c.attr.mode &= ~ATTR_BOLD;
- break;
case 22:
term.c.attr.mode &= ~(ATTR_BOLD | ATTR_FAINT);
break;
@@ -1478,20 +1482,16 @@ tsetscroll(int t, int b)
void
tsetmode(int priv, int set, int *args, int narg)
{
- int *lim, mode;
- int alt;
+ int alt, *lim;
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 */
- 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);
@@ -1511,36 +1511,36 @@ tsetmode(int priv, int set, int *args, int narg)
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);
- 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);
- 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);
- 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);
- 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 */
- MODBIT(term.mode, set, MODE_FOCUS);
+ xsetmode(set, MODE_FOCUS);
break;
case 1006: /* 1006: extended reporting mode */
- MODBIT(term.mode, set, MODE_MOUSESGR);
+ xsetmode(set, MODE_MOUSESGR);
break;
case 1034:
- MODBIT(term.mode, set, MODE_8BIT);
+ xsetmode(set, MODE_8BIT);
break;
case 1049: /* swap screen & set/restore cursor as xterm */
if (!allowaltscreen)
@@ -1565,7 +1565,7 @@ tsetmode(int priv, int set, int *args, int narg)
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
@@ -1586,8 +1586,8 @@ tsetmode(int priv, int set, int *args, int narg)
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);
@@ -1655,7 +1655,7 @@ csihandle(void)
break;
case 'c': /* DA -- Device Attributes */
if (csiescseq.arg[0] == 0)
- ttywrite(vtiden, sizeof(vtiden) - 1);
+ ttywrite(vtiden, strlen(vtiden), 0);
break;
case 'C': /* CUF -- Cursor <n> Forward */
case 'a': /* HPR -- Cursor <n> Forward */
@@ -1702,7 +1702,6 @@ csihandle(void)
tputtab(csiescseq.arg[0]);
break;
case 'J': /* ED -- Clear screen */
- selclear();
switch (csiescseq.arg[0]) {
case 0: /* below */
tclearregion(term.c.x, term.c.y, term.col-1, term.c.y);
@@ -1783,7 +1782,7 @@ csihandle(void)
if (csiescseq.arg[0] == 6) {
len = snprintf(buf, sizeof(buf),"\033[%i;%iR",
term.c.y+1, term.c.x+1);
- ttywrite(buf, len);
+ ttywrite(buf, len, 0);
}
break;
case 'r': /* DECSTBM -- Set Scrolling Region */
@@ -1805,11 +1804,8 @@ csihandle(void)
case ' ':
switch (csiescseq.mode[1]) {
case 'q': /* DECSCUSR -- Set Cursor Style */
- DEFAULT(csiescseq.arg[0], 1);
- if (!BETWEEN(csiescseq.arg[0], 0, 6)) {
+ if (xsetcursor(csiescseq.arg[0]))
goto unknown;
- }
- win.cursor = csiescseq.arg[0];
break;
default:
goto unknown;
@@ -1873,8 +1869,8 @@ strhandle(void)
dec = base64dec(strescseq.args[2]);
if (dec) {
- xsetsel(dec, CurrentTime);
- clipcopy(NULL);
+ xsetsel(dec);
+ xclipcopy();
} else {
fprintf(stderr, "erresc: invalid base64\n");
}
@@ -1979,8 +1975,7 @@ void
tprinter(char *s, size_t len)
{
if (iofd != -1 && xwrite(iofd, s, len) < 0) {
- fprintf(stderr, "Error writing in %s:%s\n",
- opt_io, strerror(errno));
+ perror("Error writing to output file");
close(iofd);
iofd = -1;
}
@@ -1989,14 +1984,11 @@ tprinter(char *s, size_t len)
void
iso14755(const Arg *arg)
{
- unsigned long id = xwinid();
- char cmd[sizeof(ISO14755CMD) + NUMMAXLEN(id)];
FILE *p;
char *us, *e, codepoint[9], uc[UTF_SIZ];
unsigned long utf32;
- snprintf(cmd, sizeof(cmd), ISO14755CMD, id);
- if (!(p = popen(cmd, "r")))
+ if (!(p = popen(ISO14755CMD, "r")))
return;
us = fgets(codepoint, sizeof(codepoint), p);
@@ -2008,7 +2000,7 @@ iso14755(const Arg *arg)
(*e != '\n' && *e != '\0'))
return;
- ttysend(uc, utf8encode(utf32, uc));
+ ttywrite(uc, utf8encode(utf32, uc), 1);
}
void
@@ -2082,22 +2074,6 @@ tputtab(int n)
}
void
-techo(Rune u)
-{
- if (ISCONTROL(u)) { /* control code */
- if (u & 0x80) {
- u &= 0x7f;
- tputc('^');
- tputc('[');
- } else if (u != '\n' && u != '\r' && u != '\t') {
- u ^= 0x40;
- tputc('^');
- }
- }
- tputc(u);
-}
-
-void
tdefutf8(char ascii)
{
if (ascii == 'G')
@@ -2181,10 +2157,7 @@ tcontrolcode(uchar ascii)
/* backwards compatibility to xterm */
strhandle();
} else {
- if (!(win.state & WIN_FOCUSED))
- xseturgency(1);
- if (bellvolume)
- xbell(bellvolume);
+ xbell();
}
break;
case '\033': /* ESC */
@@ -2240,7 +2213,7 @@ tcontrolcode(uchar ascii)
case 0x99: /* TODO: SGCI */
break;
case 0x9a: /* DECID -- Identify Terminal */
- ttywrite(vtiden, sizeof(vtiden) - 1);
+ ttywrite(vtiden, strlen(vtiden), 0);
break;
case 0x9b: /* TODO: CSI */
case 0x9c: /* TODO: ST */
@@ -2312,7 +2285,7 @@ eschandle(uchar ascii)
}
break;
case 'Z': /* DECID -- Identify Terminal */
- ttywrite(vtiden, sizeof(vtiden) - 1);
+ ttywrite(vtiden, strlen(vtiden), 0);
break;
case 'c': /* RIS -- Reset to inital state */
treset();
@@ -2320,10 +2293,10 @@ eschandle(uchar ascii)
xloadcols();
break;
case '=': /* DECPAM -- Application keypad */
- term.mode |= MODE_APPKEYPAD;
+ xsetmode(1, MODE_APPKEYPAD);
break;
case '>': /* DECPNM -- Normal keypad */
- term.mode &= ~MODE_APPKEYPAD;
+ xsetmode(0, MODE_APPKEYPAD);
break;
case '7': /* DECSC -- Save Cursor */
tcursor(CURSOR_SAVE);
@@ -2490,6 +2463,38 @@ check_control_code:
}
}
+int
+twrite(const char *buf, int buflen, int show_ctrl)
+{
+ int charsize;
+ Rune u;
+ int n;
+
+ for (n = 0; n < buflen; n += charsize) {
+ if (IS_SET(MODE_UTF8) && !IS_SET(MODE_SIXEL)) {
+ /* process a complete utf8 char */
+ charsize = utf8decode(buf + n, &u, buflen - n);
+ if (charsize == 0)
+ break;
+ } else {
+ u = buf[n] & 0xFF;
+ charsize = 1;
+ }
+ if (show_ctrl && ISCONTROL(u)) {
+ if (u & 0x80) {
+ u &= 0x7f;
+ tputc('^');
+ tputc('[');
+ } else if (u != '\n' && u != '\r' && u != '\t') {
+ u ^= 0x40;
+ tputc('^');
+ }
+ }
+ tputc(u);
+ }
+ return n;
+}
+
void
tresize(int col, int row)
{
@@ -2524,9 +2529,6 @@ tresize(int col, int row)
free(term.alt[i]);
}
- /* resize to new width */
- term.specbuf = xrealloc(term.specbuf, col * sizeof(GlyphFontSpec));
-
/* resize to new height */
term.line = xrealloc(term.line, row * sizeof(Line));
term.alt = xrealloc(term.alt, row * sizeof(Line));
@@ -2576,127 +2578,50 @@ tresize(int col, int row)
}
void
-zoom(const Arg *arg)
-{
- Arg larg;
-
- larg.f = usedfontsize + arg->f;
- zoomabs(&larg);
-}
-
-void
-zoomabs(const Arg *arg)
-{
- xunloadfonts();
- xloadfonts(usedfont, arg->f);
- cresize(0, 0);
- ttyresize();
- redraw();
- xhints();
-}
-
-void
-zoomreset(const Arg *arg)
-{
- Arg larg;
-
- if (defaultfontsize > 0) {
- larg.f = defaultfontsize;
- zoomabs(&larg);
- }
-}
-
-void
resettitle(void)
{
- xsettitle(opt_title ? opt_title : "st");
+ xsettitle(NULL);
}
void
-redraw(void)
-{
- tfulldirt();
- draw();
-}
-
-int
-match(uint mask, uint state)
-{
- return mask == XK_ANY_MOD || mask == (state & ~ignoremod);
-}
-
-void
-numlock(const Arg *dummy)
-{
- term.numlock ^= 1;
-}
-
-char*
-kmap(KeySym k, uint state)
+drawregion(int x1, int y1, int x2, int y2)
{
- Key *kp;
- int i;
-
- /* Check for mapped keys out of X11 function keys. */
- for (i = 0; i < LEN(mappedkeys); i++) {
- if (mappedkeys[i] == k)
- break;
- }
- if (i == LEN(mappedkeys)) {
- if ((k & 0xFFFF) < 0xFD00)
- return NULL;
- }
-
- for (kp = key; kp < key + LEN(key); kp++) {
- if (kp->k != k)
- continue;
-
- if (!match(kp->mask, state))
- continue;
-
- if (IS_SET(MODE_APPKEYPAD) ? kp->appkey < 0 : kp->appkey > 0)
- continue;
- if (term.numlock && kp->appkey == 2)
- continue;
-
- if (IS_SET(MODE_APPCURSOR) ? kp->appcursor < 0 : kp->appcursor > 0)
+ int y;
+ for (y = y1; y < y2; y++) {
+ if (!term.dirty[y])
continue;
- if (IS_SET(MODE_CRLF) ? kp->crlf < 0 : kp->crlf > 0)
- continue;
-
- return kp->s;
+ term.dirty[y] = 0;
+ xdrawline(term.line[y], x1, y, x2);
}
-
- return NULL;
}
void
-cresize(int width, int height)
+draw(void)
{
- int col, row;
+ int cx = term.c.x;
- if (width != 0)
- win.w = width;
- if (height != 0)
- win.h = height;
+ if (!xstartdraw())
+ return;
- col = (win.w - 2 * borderpx) / win.cw;
- row = (win.h - 2 * borderpx) / win.ch;
+ /* adjust cursor position */
+ LIMIT(term.ocx, 0, term.col-1);
+ LIMIT(term.ocy, 0, term.row-1);
+ if (term.line[term.ocy][term.ocx].mode & ATTR_WDUMMY)
+ term.ocx--;
+ if (term.line[term.c.y][cx].mode & ATTR_WDUMMY)
+ cx--;
- tresize(col, row);
- xresize(col, row);
+ drawregion(0, 0, term.col, term.row);
+ xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
+ term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
+ term.ocx = cx, term.ocy = term.c.y;
+ xfinishdraw();
}
void
-usage(void)
+redraw(void)
{
- die("usage: %s [-aiv] [-c class] [-f font] [-g geometry]"
- " [-n name] [-o file]\n"
- " [-T title] [-t title] [-w windowid]"
- " [[-e] command [args ...]]\n"
- " %s [-aiv] [-c class] [-f font] [-g geometry]"
- " [-n name] [-o file]\n"
- " [-T title] [-t title] [-w windowid] -l line"
- " [stty_args ...]\n", argv0, argv0);
+ tfulldirt();
+ draw();
}
diff --git a/st.h b/st.h
index 44d4938..dac64d8 100644
--- a/st.h
+++ b/st.h
@@ -1,7 +1,7 @@
/* See LICENSE for license details. */
-/* Arbitrary sizes */
-#define UTF_SIZ 4
+#include <stdint.h>
+#include <sys/types.h>
/* macros */
#define MIN(a, b) ((a) < (b) ? (a) : (b))
@@ -9,10 +9,10 @@
#define LEN(a) (sizeof(a) / sizeof(a)[0])
#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
#define DIVCEIL(n, d) (((n) + ((d) - 1)) / (d))
+#define DEFAULT(a, b) (a) = (a) ? (a) : (b)
#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)))
@@ -36,34 +36,6 @@ enum glyph_attribute {
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,
@@ -80,11 +52,6 @@ enum selection_snap {
SNAP_LINE = 2
};
-enum window_state {
- WIN_VISIBLE = 1,
- WIN_FOCUSED = 2
-};
-
typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned long ulong;
@@ -92,6 +59,7 @@ typedef unsigned short ushort;
typedef uint_least32_t Rune;
+#define Glyph Glyph_
typedef struct {
Rune u; /* character code */
ushort mode; /* attribute flags */
@@ -101,72 +69,6 @@ typedef struct {
typedef Glyph *Line;
-typedef struct {
- Glyph attr; /* current char attributes */
- int x;
- int y;
- char state;
-} TCursor;
-
-/* Internal representation of the screen */
-typedef struct {
- int row; /* nb row */
- int col; /* nb col */
- Line *line; /* screen */
- Line *alt; /* alternate screen */
- int *dirty; /* dirtyness of lines */
- GlyphFontSpec *specbuf; /* font spec buffer used for rendering */
- TCursor c; /* cursor */
- int top; /* top scroll limit */
- int bot; /* bottom scroll limit */
- int mode; /* terminal mode flags */
- int esc; /* escape state flags */
- char trantbl[4]; /* charset table translation */
- int charset; /* current charset */
- int icharset; /* selected charset for sequence */
- int numlock; /* lock numbers in keyboard */
- int *tabs;
-} Term;
-
-/* Purely graphic info */
-typedef struct {
- int tw, th; /* tty width and height */
- int w, h; /* window width and height */
- int ch; /* char height */
- int cw; /* char width */
- char state; /* focus, redraw, visible */
- int cursor; /* cursor style */
-} TermWindow;
-
-typedef struct {
- uint b;
- uint mask;
- char *s;
-} MouseShortcut;
-
-typedef struct {
- int mode;
- int type;
- int snap;
- /*
- * Selection variables:
- * nb – normalized coordinates of the beginning of the selection
- * ne – normalized coordinates of the end of the selection
- * ob – original coordinates of the beginning of the selection
- * oe – original coordinates of the end of the selection
- */
- struct {
- int x, y;
- } nb, ne, ob, oe;
-
- char *primary, *clipboard;
- int alt;
- struct timespec tclick1;
- struct timespec tclick2;
-
- //Atom xtarget;
-} Selection;
-
typedef union {
int i;
uint ui;
@@ -174,99 +76,48 @@ typedef union {
const void *v;
} Arg;
-typedef struct {
- uint mod;
- KeySym keysym;
- void (*func)(const Arg *);
- const Arg arg;
-} Shortcut;
-
void die(const char *, ...);
void redraw(void);
+void draw(void);
+
+void iso14755(const Arg *);
+void printscreen(const Arg *);
+void printsel(const Arg *);
+void sendbreak(const Arg *);
+void toggleprinter(const Arg *);
int tattrset(int);
void tnew(int, int);
-void tsetdirt(int, int);
+void tresize(int, int);
void tsetdirtattr(int);
-int match(uint, uint);
-void ttynew(void);
+void ttyhangup(void);
+int ttynew(char *, char *, char *, char **);
size_t ttyread(void);
-void ttyresize(void);
-void ttysend(char *, size_t);
-void ttywrite(const char *, size_t);
+void ttyresize(int, int);
+void ttywrite(const char *, size_t, int);
void resettitle(void);
-char *kmap(KeySym, uint);
-void cresize(int, int);
void selclear(void);
-
void selinit(void);
-void selnormalize(void);
+void selstart(int, int, int);
+void selextend(int, int, int, int);
int selected(int, int);
char *getsel(void);
-int x2col(int);
-int y2row(int);
-size_t utf8decode(char *, Rune *, size_t);
size_t utf8encode(Rune, char *);
void *xmalloc(size_t);
+void *xrealloc(void *, size_t);
char *xstrdup(char *);
-void usage(void);
-
-/* Globals */
-extern TermWindow win;
-extern Term term;
-extern Selection sel;
-extern int cmdfd;
-extern pid_t pid;
-extern char **opt_cmd;
-extern char *opt_class;
-extern char *opt_embed;
-extern char *opt_font;
-extern char *opt_io;
-extern char *opt_line;
-extern char *opt_name;
-extern char *opt_title;
-extern int oldbutton;
-
-extern char *usedfont;
-extern double usedfontsize;
-extern double defaultfontsize;
-
/* config.h globals */
-extern char font[];
-extern int borderpx;
-extern float cwscale;
-extern float chscale;
-extern unsigned int doubleclicktimeout;
-extern unsigned int tripleclicktimeout;
+extern char *utmp;
+extern char *stty_args;
+extern char *vtiden;
+extern char *worddelimiters;
extern int allowaltscreen;
-extern unsigned int xfps;
-extern unsigned int actionfps;
-extern unsigned int cursorthickness;
-extern unsigned int blinktimeout;
-extern char termname[];
-extern const char *colorname[];
-extern size_t colornamelen;
+extern char *termname;
+extern unsigned int tabspaces;
extern unsigned int defaultfg;
extern unsigned int defaultbg;
-extern unsigned int defaultcs;
-extern unsigned int defaultrcs;
-extern unsigned int cursorshape;
-extern unsigned int cols;
-extern unsigned int rows;
-extern unsigned int mouseshape;
-extern unsigned int mousefg;
-extern unsigned int mousebg;
-extern unsigned int defaultattr;
-extern MouseShortcut mshortcuts[];
-extern size_t mshortcutslen;
-extern Shortcut shortcuts[];
-extern size_t shortcutslen;
-extern uint forceselmod;
-extern uint selmasks[];
-extern size_t selmaskslen;
-extern char ascii_printable[];
diff --git a/st.info b/st.info
index 4d77eae..52fc617 100644
--- a/st.info
+++ b/st.info
@@ -25,6 +25,7 @@ st| simpleterm,
cuu=\E[%p1%dA,
dch=\E[%p1%dP,
dch1=\E[P,
+ dim=\E[2m,
dl=\E[%p1%dM,
dl1=\E[M,
ech=\E[%p1%dX,
@@ -142,7 +143,6 @@ st| simpleterm,
khome=\E[1~,
kil1=\E[2;5~,
krmir=\E[2;2~,
- kich1=\E[2~,
knp=\E[6~,
kmous=\E[M,
kpp=\E[5~,
@@ -185,7 +185,10 @@ st| simpleterm,
tsl=\E]0;,
xenl,
vpa=\E[%i%p1%dd,
-# Tmux unofficial extensions, see TERMINFO EXTENSIONS in tmux(1)
+# XTerm extensions
+ rmxx=\E[29m,
+ smxx=\E[9m,
+# tmux extensions, see TERMINFO EXTENSIONS in tmux(1)
Se,
Ss,
Tc,
diff --git a/win.h b/win.h
index 428111c..31f327d 100644
--- a/win.h
+++ b/win.h
@@ -1,30 +1,38 @@
/* See LICENSE for license details. */
-/* X modifiers */
-#define XK_ANY_MOD UINT_MAX
-#define XK_NO_MOD 0
-#define XK_SWITCH_MOD (1<<13)
+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,
+};
-typedef XftGlyphFontSpec GlyphFontSpec;
-
-void draw(void);
-void drawregion(int, int, int, int);
-void run(void);
-
-void xbell(int);
+void xbell(void);
void xclipcopy(void);
-void xclippaste(void);
-void xhints(void);
-void xinit(void);
+void xdrawcursor(int, int, Glyph, int, int, Glyph);
+void xdrawline(Line, int, int, int);
+void xfinishdraw(void);
void xloadcols(void);
int xsetcolorname(int, const char *);
-void xloadfonts(char *, double);
-void xsetenv(void);
void xsettitle(char *);
+int xsetcursor(int);
+void xsetmode(int, unsigned int);
void xsetpointermotion(int);
-void xseturgency(int);
-void xunloadfonts(void);
-void xresize(int, int);
-void xselpaste(void);
-unsigned long xwinid(void);
-void xsetsel(char *, Time);
+void xsetsel(char *);
+int xstartdraw(void);
diff --git a/x.c b/x.c
index fbfd350..00cb6b1 100644
--- a/x.c
+++ b/x.c
@@ -1,46 +1,95 @@
/* See LICENSE for license details. */
#include <errno.h>
+#include <math.h>
+#include <limits.h>
#include <locale.h>
#include <signal.h>
-#include <stdint.h>
#include <sys/select.h>
#include <time.h>
#include <unistd.h>
#include <libgen.h>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
-#include <X11/Xutil.h>
#include <X11/cursorfont.h>
#include <X11/keysym.h>
#include <X11/Xft/Xft.h>
#include <X11/XKBlib.h>
+static char *argv0;
#include "arg.h"
+#include "st.h"
+#include "win.h"
-#define Glyph Glyph_
-#define Font Font_
+/* types used in config.h */
+typedef struct {
+ uint mod;
+ KeySym keysym;
+ void (*func)(const Arg *);
+ const Arg arg;
+} Shortcut;
-#include "win.h"
-#include "st.h"
+typedef struct {
+ uint b;
+ uint mask;
+ char *s;
+} MouseShortcut;
+
+typedef struct {
+ KeySym k;
+ uint mask;
+ char *s;
+ /* three-valued logic variables: 0 indifferent, 1 on, -1 off */
+ signed char appkey; /* application keypad */
+ signed char appcursor; /* application cursor */
+} Key;
+
+/* X modifiers */
+#define XK_ANY_MOD UINT_MAX
+#define XK_NO_MOD 0
+#define XK_SWITCH_MOD (1<<13)
+
+/* 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 zoomreset(const Arg *);
+
+/* config.h for applying patches and the configuration. */
+#include "config.h"
/* XEMBED messages */
#define XEMBED_FOCUS_IN 4
#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)
typedef XftDraw *Draw;
typedef XftColor Color;
+typedef XftGlyphFontSpec GlyphFontSpec;
/* Purely graphic info */
typedef struct {
+ int tw, th; /* tty width and height */
+ int w, h; /* window width and height */
+ int ch; /* char height */
+ int cw; /* char width */
+ int mode; /* window state/mode flags */
+ int cursor; /* cursor style */
+} TermWindow;
+
+typedef struct {
Display *dpy;
Colormap cmap;
Window win;
Drawable buf;
+ GlyphFontSpec *specbuf; /* font spec buffer used for rendering */
Atom xembed, wmdeletewin, netwmname, netwmpid;
XIM xim;
XIC xic;
@@ -55,9 +104,13 @@ typedef struct {
typedef struct {
Atom xtarget;
+ char *primary, *clipboard;
+ struct timespec tclick1;
+ struct timespec tclick2;
} XSelection;
/* Font structure */
+#define Font Font_
typedef struct {
int height;
int width;
@@ -85,10 +138,20 @@ static int xmakeglyphfontspecs(XftGlyphFontSpec *, const Glyph *, int, int, int)
static void xdrawglyphfontspecs(const XftGlyphFontSpec *, Glyph, int, int, int);
static void xdrawglyph(Glyph, int, int);
static void xclear(int, int, int, int);
-static void xdrawcursor(void);
static int xgeommasktogravity(int);
+static void xinit(int, int);
+static void cresize(int, int);
+static void xresize(int, int);
+static void xhints(void);
+static int xloadcolor(int, const char *, Color *);
static int xloadfont(Font *, FcPattern *);
+static void xloadfonts(char *, double);
static void xunloadfont(Font *);
+static void xunloadfonts(void);
+static void xsetenv(void);
+static void xseturgency(int);
+static int evcol(XEvent *);
+static int evrow(XEvent *);
static void expose(XEvent *);
static void visibility(XEvent *);
@@ -104,10 +167,14 @@ static void propnotify(XEvent *);
static void selnotify(XEvent *);
static void selclear_(XEvent *);
static void selrequest(XEvent *);
-
-static void selcopy(Time);
-static void getbuttoninfo(XEvent *);
+static void setsel(char *, Time);
+static void mousesel(XEvent *, int);
static void mousereport(XEvent *);
+static char *kmap(KeySym, uint);
+static int match(uint, uint);
+
+static void run(void);
+static void usage(void);
static void (*handler[LASTEvent])(XEvent *) = {
[KeyPress] = kpress,
@@ -139,6 +206,7 @@ static void (*handler[LASTEvent])(XEvent *) = {
static DC dc;
static XWindow xw;
static XSelection xsel;
+static TermWindow win;
/* Font Ring Cache */
enum {
@@ -157,34 +225,127 @@ typedef struct {
/* Fontcache is an array now. A new font will be appended to the array. */
static Fontcache frc[16];
static int frclen = 0;
+static char *usedfont = NULL;
+static double usedfontsize = 0;
+static double defaultfontsize = 0;
+
+static char *opt_class = NULL;
+static char **opt_cmd = NULL;
+static char *opt_embed = NULL;
+static char *opt_font = NULL;
+static char *opt_io = NULL;
+static char *opt_line = NULL;
+static char *opt_name = NULL;
+static char *opt_title = NULL;
+
+static int oldbutton = 3; /* button event on startup: 3 = release */
void
-getbuttoninfo(XEvent *e)
+clipcopy(const Arg *dummy)
{
- int type;
- uint state = e->xbutton.state & ~(Button1Mask | forceselmod);
+ Atom clipboard;
+
+ free(xsel.clipboard);
+ xsel.clipboard = NULL;
+
+ if (xsel.primary != NULL) {
+ xsel.clipboard = xstrdup(xsel.primary);
+ clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0);
+ XSetSelectionOwner(xw.dpy, clipboard, xw.win, CurrentTime);
+ }
+}
+
+void
+clippaste(const Arg *dummy)
+{
+ Atom clipboard;
+
+ clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0);
+ XConvertSelection(xw.dpy, clipboard, xsel.xtarget, clipboard,
+ xw.win, CurrentTime);
+}
+
+void
+selpaste(const Arg *dummy)
+{
+ XConvertSelection(xw.dpy, XA_PRIMARY, xsel.xtarget, XA_PRIMARY,
+ xw.win, CurrentTime);
+}
+
+void
+numlock(const Arg *dummy)
+{
+ win.mode ^= MODE_NUMLOCK;
+}
+
+void
+zoom(const Arg *arg)
+{
+ Arg larg;
+
+ larg.f = usedfontsize + arg->f;
+ zoomabs(&larg);
+}
+
+void
+zoomabs(const Arg *arg)
+{
+ xunloadfonts();
+ xloadfonts(usedfont, arg->f);
+ cresize(0, 0);
+ redraw();
+ xhints();
+}
- sel.alt = IS_SET(MODE_ALTSCREEN);
+void
+zoomreset(const Arg *arg)
+{
+ Arg larg;
+
+ if (defaultfontsize > 0) {
+ larg.f = defaultfontsize;
+ zoomabs(&larg);
+ }
+}
+
+int
+evcol(XEvent *e)
+{
+ int x = e->xbutton.x - borderpx;
+ LIMIT(x, 0, win.tw - 1);
+ return x / win.cw;
+}
- sel.oe.x = x2col(e->xbutton.x);
- sel.oe.y = y2row(e->xbutton.y);
- selnormalize();
+int
+evrow(XEvent *e)
+{
+ int y = e->xbutton.y - borderpx;
+ LIMIT(y, 0, win.th - 1);
+ return y / win.ch;
+}
- sel.type = SEL_REGULAR;
- for (type = 1; type < selmaskslen; ++type) {
+void
+mousesel(XEvent *e, int done)
+{
+ int type, seltype = SEL_REGULAR;
+ uint state = e->xbutton.state & ~(Button1Mask | forceselmod);
+
+ for (type = 1; type < LEN(selmasks); ++type) {
if (match(selmasks[type], state)) {
- sel.type = type;
+ seltype = type;
break;
}
}
+ selextend(evcol(e), evrow(e), seltype, done);
+ if (done)
+ setsel(getsel(), e->xbutton.time);
}
void
mousereport(XEvent *e)
{
- int x = x2col(e->xbutton.x), y = y2row(e->xbutton.y),
- button = e->xbutton.button, state = e->xbutton.state,
- len;
+ int len, x = evcol(e), y = evrow(e),
+ button = e->xbutton.button, state = e->xbutton.state;
char buf[40];
static int ox, oy;
@@ -240,7 +401,7 @@ mousereport(XEvent *e)
return;
}
- ttywrite(buf, len);
+ ttywrite(buf, len, 0);
}
void
@@ -248,58 +409,42 @@ bpress(XEvent *e)
{
struct timespec now;
MouseShortcut *ms;
+ int snap;
if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) {
mousereport(e);
return;
}
- for (ms = mshortcuts; ms < mshortcuts + mshortcutslen; ms++) {
+ for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) {
if (e->xbutton.button == ms->b
&& match(ms->mask, e->xbutton.state)) {
- ttysend(ms->s, strlen(ms->s));
+ ttywrite(ms->s, strlen(ms->s), 1);
return;
}
}
if (e->xbutton.button == Button1) {
- clock_gettime(CLOCK_MONOTONIC, &now);
-
- /* Clear previous selection, logically and visually. */
- selclear_(NULL);
- sel.mode = SEL_EMPTY;
- sel.type = SEL_REGULAR;
- sel.oe.x = sel.ob.x = x2col(e->xbutton.x);
- sel.oe.y = sel.ob.y = y2row(e->xbutton.y);
-
/*
* If the user clicks below predefined timeouts specific
* snapping behaviour is exposed.
*/
- if (TIMEDIFF(now, sel.tclick2) <= tripleclicktimeout) {
- sel.snap = SNAP_LINE;
- } else if (TIMEDIFF(now, sel.tclick1) <= doubleclicktimeout) {
- sel.snap = SNAP_WORD;
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ if (TIMEDIFF(now, xsel.tclick2) <= tripleclicktimeout) {
+ snap = SNAP_LINE;
+ } else if (TIMEDIFF(now, xsel.tclick1) <= doubleclicktimeout) {
+ snap = SNAP_WORD;
} else {
- sel.snap = 0;
+ snap = 0;
}
- selnormalize();
+ xsel.tclick2 = xsel.tclick1;
+ xsel.tclick1 = now;
- if (sel.snap != 0)
- sel.mode = SEL_READY;
- tsetdirt(sel.nb.y, sel.ne.y);
- sel.tclick2 = sel.tclick1;
- sel.tclick1 = now;
+ selstart(evcol(e), evrow(e), snap);
}
}
void
-selcopy(Time t)
-{
- xsetsel(getsel(), t);
-}
-
-void
propnotify(XEvent *e)
{
XPropertyEvent *xpev;
@@ -319,18 +464,16 @@ selnotify(XEvent *e)
ulong nitems, ofs, rem;
int format;
uchar *data, *last, *repl;
- Atom type, incratom, property;
+ Atom type, incratom, property = None;
incratom = XInternAtom(xw.dpy, "INCR", 0);
ofs = 0;
- if (e->type == SelectionNotify) {
+ if (e->type == SelectionNotify)
property = e->xselection.property;
- } else if(e->type == PropertyNotify) {
+ else if (e->type == PropertyNotify)
property = e->xproperty.atom;
- } else {
- return;
- }
+
if (property == None)
return;
@@ -386,10 +529,10 @@ selnotify(XEvent *e)
}
if (IS_SET(MODE_BRCKTPASTE) && ofs == 0)
- ttywrite("\033[200~", 6);
- ttysend((char *)data, nitems * format / 8);
+ ttywrite("\033[200~", 6, 0);
+ ttywrite((char *)data, nitems * format / 8, 1);
if (IS_SET(MODE_BRCKTPASTE) && rem == 0)
- ttywrite("\033[201~", 6);
+ ttywrite("\033[201~", 6, 0);
XFree(data);
/* number of 32-bit chunks returned */
ofs += nitems * format / 32;
@@ -403,35 +546,9 @@ selnotify(XEvent *e)
}
void
-xselpaste(void)
-{
- XConvertSelection(xw.dpy, XA_PRIMARY, xsel.xtarget, XA_PRIMARY,
- xw.win, CurrentTime);
-}
-
-void
xclipcopy(void)
{
- Atom clipboard;
-
- if (sel.clipboard != NULL)
- free(sel.clipboard);
-
- if (sel.primary != NULL) {
- sel.clipboard = xstrdup(sel.primary);
- clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0);
- XSetSelectionOwner(xw.dpy, clipboard, xw.win, CurrentTime);
- }
-}
-
-void
-xclippaste(void)
-{
- Atom clipboard;
-
- clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0);
- XConvertSelection(xw.dpy, clipboard, xsel.xtarget, clipboard,
- xw.win, CurrentTime);
+ clipcopy(NULL);
}
void
@@ -475,9 +592,9 @@ selrequest(XEvent *e)
*/
clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0);
if (xsre->selection == XA_PRIMARY) {
- seltext = sel.primary;
+ seltext = xsel.primary;
} else if (xsre->selection == clipboard) {
- seltext = sel.clipboard;
+ seltext = xsel.clipboard;
} else {
fprintf(stderr,
"Unhandled clipboard selection 0x%lx\n",
@@ -499,14 +616,23 @@ selrequest(XEvent *e)
}
void
-xsetsel(char *str, Time t)
+setsel(char *str, Time t)
{
- free(sel.primary);
- sel.primary = str;
+ if (!str)
+ return;
+
+ free(xsel.primary);
+ xsel.primary = str;
XSetSelectionOwner(xw.dpy, XA_PRIMARY, xw.win, t);
if (XGetSelectionOwner(xw.dpy, XA_PRIMARY) != xw.win)
- selclear_(NULL);
+ selclear();
+}
+
+void
+xsetsel(char *str)
+{
+ setsel(str, CurrentTime);
}
void
@@ -517,54 +643,57 @@ brelease(XEvent *e)
return;
}
- if (e->xbutton.button == Button2) {
- xselpaste();
- } else if (e->xbutton.button == Button1) {
- if (sel.mode == SEL_READY) {
- getbuttoninfo(e);
- selcopy(e->xbutton.time);
- } else
- selclear_(NULL);
- sel.mode = SEL_IDLE;
- tsetdirt(sel.nb.y, sel.ne.y);
- }
+ if (e->xbutton.button == Button2)
+ selpaste(NULL);
+ else if (e->xbutton.button == Button1)
+ mousesel(e, 1);
}
void
bmotion(XEvent *e)
{
- int oldey, oldex, oldsby, oldsey;
-
if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) {
mousereport(e);
return;
}
- if (!sel.mode)
- return;
+ mousesel(e, 0);
+}
+
+void
+cresize(int width, int height)
+{
+ int col, row;
- sel.mode = SEL_READY;
- oldey = sel.oe.y;
- oldex = sel.oe.x;
- oldsby = sel.nb.y;
- oldsey = sel.ne.y;
- getbuttoninfo(e);
+ if (width != 0)
+ win.w = width;
+ if (height != 0)
+ win.h = height;
- if (oldey != sel.oe.y || oldex != sel.oe.x)
- tsetdirt(MIN(sel.nb.y, oldsby), MAX(sel.ne.y, oldsey));
+ col = (win.w - 2 * borderpx) / win.cw;
+ row = (win.h - 2 * borderpx) / win.ch;
+ col = MAX(1, col);
+ row = MAX(1, row);
+
+ tresize(col, row);
+ xresize(col, row);
+ ttyresize(win.tw, win.th);
}
void
xresize(int col, int row)
{
- win.tw = MAX(1, col * win.cw);
- win.th = MAX(1, row * win.ch);
+ 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 */
+ xw.specbuf = xrealloc(xw.specbuf, col * sizeof(GlyphFontSpec));
}
ushort
@@ -604,7 +733,7 @@ xloadcols(void)
static int loaded;
Color *cp;
- dc.collen = MAX(colornamelen, 256);
+ dc.collen = MAX(LEN(colorname), 256);
dc.col = xmalloc(dc.collen * sizeof(Color));
if (loaded) {
@@ -615,9 +744,9 @@ xloadcols(void)
for (i = 0; i < dc.collen; i++)
if (!xloadcolor(i, NULL, &dc.col[i])) {
if (colorname[i])
- die("Could not allocate color '%s'\n", colorname[i]);
+ die("could not allocate color '%s'\n", colorname[i]);
else
- die("Could not allocate color %d\n", i);
+ die("could not allocate color %d\n", i);
}
loaded = 1;
}
@@ -657,19 +786,21 @@ xhints(void)
XClassHint class = {opt_name ? opt_name : termname,
opt_class ? opt_class : termname};
XWMHints wm = {.flags = InputHint, .input = 1};
- XSizeHints *sizeh = NULL;
+ XSizeHints *sizeh;
sizeh = XAllocSizeHints();
- sizeh->flags = PSize | PResizeInc | PBaseSize;
+ sizeh->flags = PSize | PResizeInc | PBaseSize | PMinSize;
sizeh->height = win.h;
sizeh->width = win.w;
sizeh->height_inc = win.ch;
sizeh->width_inc = win.cw;
sizeh->base_height = 2 * borderpx;
sizeh->base_width = 2 * borderpx;
+ sizeh->min_height = win.ch + 2 * borderpx;
+ sizeh->min_width = win.cw + 2 * borderpx;
if (xw.isfixed) {
- sizeh->flags |= PMaxSize | PMinSize;
+ sizeh->flags |= PMaxSize;
sizeh->min_width = sizeh->max_width = win.w;
sizeh->min_height = sizeh->max_height = win.h;
}
@@ -742,7 +873,7 @@ xloadfont(Font *f, FcPattern *pattern)
if ((XftPatternGetInteger(f->match->pattern, "slant", 0,
&haveattr) != XftResultMatch) || haveattr < wantattr) {
f->badslant = 1;
- fputs("st: font slant does not match\n", stderr);
+ fputs("font slant does not match\n", stderr);
}
}
@@ -751,7 +882,7 @@ xloadfont(Font *f, FcPattern *pattern)
if ((XftPatternGetInteger(f->match->pattern, "weight", 0,
&haveattr) != XftResultMatch) || haveattr != wantattr) {
f->badweight = 1;
- fputs("st: font weight does not match\n", stderr);
+ fputs("font weight does not match\n", stderr);
}
}
@@ -778,16 +909,14 @@ xloadfonts(char *fontstr, double fontsize)
{
FcPattern *pattern;
double fontval;
- float ceilf(float);
- if (fontstr[0] == '-') {
+ if (fontstr[0] == '-')
pattern = XftXlfdParse(fontstr, False, False);
- } else {
+ else
pattern = FcNameParse((FcChar8 *)fontstr);
- }
if (!pattern)
- die("st: can't open font %s\n", fontstr);
+ die("can't open font %s\n", fontstr);
if (fontsize > 1) {
FcPatternDel(pattern, FC_PIXEL_SIZE);
@@ -813,7 +942,7 @@ xloadfonts(char *fontstr, double fontsize)
}
if (xloadfont(&dc.font, pattern))
- die("st: can't open font %s\n", fontstr);
+ die("can't open font %s\n", fontstr);
if (usedfontsize < 0) {
FcPatternGetDouble(dc.font.match->pattern,
@@ -830,17 +959,17 @@ xloadfonts(char *fontstr, double fontsize)
FcPatternDel(pattern, FC_SLANT);
FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
if (xloadfont(&dc.ifont, pattern))
- die("st: can't open font %s\n", fontstr);
+ die("can't open font %s\n", fontstr);
FcPatternDel(pattern, FC_WEIGHT);
FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
if (xloadfont(&dc.ibfont, pattern))
- die("st: can't open font %s\n", fontstr);
+ die("can't open font %s\n", fontstr);
FcPatternDel(pattern, FC_SLANT);
FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ROMAN);
if (xloadfont(&dc.bfont, pattern))
- die("st: can't open font %s\n", fontstr);
+ die("can't open font %s\n", fontstr);
FcPatternDestroy(pattern);
}
@@ -868,7 +997,7 @@ xunloadfonts(void)
}
void
-xinit(void)
+xinit(int cols, int rows)
{
XGCValues gcvalues;
Cursor cursor;
@@ -877,13 +1006,13 @@ xinit(void)
XColor xmousefg, xmousebg;
if (!(xw.dpy = XOpenDisplay(NULL)))
- die("Can't open display\n");
+ die("can't open display\n");
xw.scr = XDefaultScreen(xw.dpy);
xw.vis = XDefaultVisual(xw.dpy, xw.scr);
/* font */
if (!FcInit())
- die("Could not init fontconfig.\n");
+ die("could not init fontconfig.\n");
usedfont = (opt_font == NULL)? font : opt_font;
xloadfonts(usedfont, 0);
@@ -893,8 +1022,8 @@ xinit(void)
xloadcols();
/* adjust fixed window geometry */
- win.w = 2 * borderpx + term.col * win.cw;
- win.h = 2 * borderpx + term.row * win.ch;
+ win.w = 2 * borderpx + cols * win.cw;
+ win.h = 2 * borderpx + rows * win.ch;
if (xw.gm & XNegative)
xw.l += DisplayWidth(xw.dpy, xw.scr) - win.w - 2;
if (xw.gm & YNegative)
@@ -925,6 +1054,9 @@ xinit(void)
XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel);
XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h);
+ /* font spec buffer */
+ xw.specbuf = xmalloc(cols * sizeof(GlyphFontSpec));
+
/* Xft rendering context */
xw.draw = XftDrawCreate(xw.dpy, xw.buf, xw.vis, xw.cmap);
@@ -973,11 +1105,16 @@ xinit(void)
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();
XSync(xw.dpy, False);
+ clock_gettime(CLOCK_MONOTONIC, &xsel.tclick1);
+ clock_gettime(CLOCK_MONOTONIC, &xsel.tclick2);
+ xsel.primary = NULL;
+ xsel.clipboard = NULL;
xsel.xtarget = XInternAtom(xw.dpy, "UTF8_STRING", 0);
if (xsel.xtarget == None)
xsel.xtarget = XA_STRING;
@@ -1092,6 +1229,9 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x
frc[frclen].font = XftFontOpenPattern(xw.dpy,
fontpattern);
+ if (!frc[frclen].font)
+ die("XftFontOpenPattern failed seeking fallback font: %s\n",
+ strerror(errno));
frc[frclen].flags = frcflags;
frc[frclen].unicodep = rune;
@@ -1186,21 +1326,22 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
}
}
- if (base.mode & ATTR_REVERSE) {
- temp = fg;
- fg = bg;
- bg = temp;
- }
-
if ((base.mode & ATTR_BOLD_FAINT) == ATTR_FAINT) {
colfg.red = fg->color.red / 2;
colfg.green = fg->color.green / 2;
colfg.blue = fg->color.blue / 2;
+ colfg.alpha = fg->color.alpha;
XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colfg, &revfg);
fg = &revfg;
}
- if (base.mode & ATTR_BLINK && term.mode & MODE_BLINK)
+ if (base.mode & ATTR_REVERSE) {
+ temp = fg;
+ fg = bg;
+ bg = temp;
+ }
+
+ if (base.mode & ATTR_BLINK && win.mode & MODE_BLINK)
fg = bg;
if (base.mode & ATTR_INVISIBLE)
@@ -1209,15 +1350,16 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
/* Intelligent cleaning up of the borders. */
if (x == 0) {
xclear(0, (y == 0)? 0 : winy, borderpx,
- winy + win.ch + ((y >= term.row-1)? win.h : 0));
+ winy + win.ch +
+ ((winy + win.ch >= borderpx + win.th)? win.h : 0));
}
- if (x + charlen >= term.col) {
+ if (winx + width >= borderpx + win.tw) {
xclear(winx + width, (y == 0)? 0 : winy, win.w,
- ((y >= term.row-1)? win.h : (winy + win.ch)));
+ ((winy + win.ch >= borderpx + win.th)? win.h : (winy + win.ch)));
}
if (y == 0)
xclear(winx, 0, winx + width, borderpx);
- if (y == term.row-1)
+ if (winy + win.ch >= borderpx + win.th)
xclear(winx, winy + win.ch, winx + width, win.h);
/* Clean up the region we want to draw to. */
@@ -1259,42 +1401,27 @@ xdrawglyph(Glyph g, int x, int y)
}
void
-xdrawcursor(void)
+xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
{
- static int oldx = 0, oldy = 0;
- int curx;
- Glyph g = {' ', ATTR_NULL, defaultbg, defaultcs}, og;
- int ena_sel = sel.ob.x != -1 && sel.alt == IS_SET(MODE_ALTSCREEN);
Color drawcol;
- LIMIT(oldx, 0, term.col-1);
- LIMIT(oldy, 0, term.row-1);
-
- curx = term.c.x;
-
- /* adjust position if in dummy */
- if (term.line[oldy][oldx].mode & ATTR_WDUMMY)
- oldx--;
- if (term.line[term.c.y][curx].mode & ATTR_WDUMMY)
- curx--;
-
/* remove the old cursor */
- og = term.line[oldy][oldx];
- if (ena_sel && selected(oldx, oldy))
+ if (selected(ox, oy))
og.mode ^= ATTR_REVERSE;
- xdrawglyph(og, oldx, oldy);
+ xdrawglyph(og, ox, oy);
- g.u = term.line[term.c.y][term.c.x].u;
- g.mode |= term.line[term.c.y][term.c.x].mode &
- (ATTR_BOLD | ATTR_ITALIC | ATTR_UNDERLINE | ATTR_STRUCK);
+ if (IS_SET(MODE_HIDE))
+ return;
/*
* Select the right color for the right mode.
*/
+ g.mode &= ATTR_BOLD|ATTR_ITALIC|ATTR_UNDERLINE|ATTR_STRUCK|ATTR_WIDE;
+
if (IS_SET(MODE_REVERSE)) {
g.mode |= ATTR_REVERSE;
g.bg = defaultfg;
- if (ena_sel && selected(term.c.x, term.c.y)) {
+ if (selected(cx, cy)) {
drawcol = dc.col[defaultcs];
g.fg = defaultrcs;
} else {
@@ -1302,64 +1429,60 @@ xdrawcursor(void)
g.fg = defaultcs;
}
} else {
- if (ena_sel && selected(term.c.x, term.c.y)) {
- drawcol = dc.col[defaultrcs];
+ if (selected(cx, cy)) {
g.fg = defaultfg;
g.bg = defaultrcs;
} else {
- drawcol = dc.col[defaultcs];
+ g.fg = defaultbg;
+ g.bg = defaultcs;
}
+ drawcol = dc.col[g.bg];
}
- if (IS_SET(MODE_HIDE))
- 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);
+ case 7: /* st extension: snowman (U+2603) */
+ g.u = 0x2603;
case 0: /* Blinking Block */
case 1: /* Blinking Block (Default) */
case 2: /* Steady Block */
- g.mode |= term.line[term.c.y][curx].mode & ATTR_WIDE;
- xdrawglyph(g, term.c.x, term.c.y);
+ xdrawglyph(g, cx, cy);
break;
case 3: /* Blinking Underline */
case 4: /* Steady Underline */
XftDrawRect(xw.draw, &drawcol,
- borderpx + curx * win.cw,
- borderpx + (term.c.y + 1) * win.ch - \
+ borderpx + cx * win.cw,
+ borderpx + (cy + 1) * win.ch - \
cursorthickness,
win.cw, cursorthickness);
break;
case 5: /* Blinking bar */
case 6: /* Steady bar */
XftDrawRect(xw.draw, &drawcol,
- borderpx + curx * win.cw,
- borderpx + term.c.y * win.ch,
+ borderpx + cx * win.cw,
+ borderpx + cy * win.ch,
cursorthickness, win.ch);
break;
}
} else {
XftDrawRect(xw.draw, &drawcol,
- borderpx + curx * win.cw,
- borderpx + term.c.y * win.ch,
+ borderpx + cx * win.cw,
+ borderpx + cy * win.ch,
win.cw - 1, 1);
XftDrawRect(xw.draw, &drawcol,
- borderpx + curx * win.cw,
- borderpx + term.c.y * win.ch,
+ borderpx + cx * win.cw,
+ borderpx + cy * win.ch,
1, win.ch - 1);
XftDrawRect(xw.draw, &drawcol,
- borderpx + (curx + 1) * win.cw - 1,
- borderpx + term.c.y * win.ch,
+ borderpx + (cx + 1) * win.cw - 1,
+ borderpx + cy * win.ch,
1, win.ch - 1);
XftDrawRect(xw.draw, &drawcol,
- borderpx + curx * win.cw,
- borderpx + (term.c.y + 1) * win.ch - 1,
+ borderpx + cx * win.cw,
+ borderpx + (cy + 1) * win.ch - 1,
win.cw, 1);
}
- oldx = curx, oldy = term.c.y;
}
void
@@ -1375,6 +1498,7 @@ void
xsettitle(char *p)
{
XTextProperty prop;
+ DEFAULT(p, opt_title);
Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle,
&prop);
@@ -1383,60 +1507,51 @@ xsettitle(char *p)
XFree(prop.value);
}
-void
-draw(void)
+int
+xstartdraw(void)
{
- drawregion(0, 0, term.col, term.row);
- 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);
+ return IS_SET(MODE_VISIBLE);
}
void
-drawregion(int x1, int y1, int x2, int y2)
+xdrawline(Line line, int x1, int y1, int x2)
{
- int i, x, y, ox, numspecs;
+ int i, x, ox, numspecs;
Glyph base, new;
- XftGlyphFontSpec *specs;
- int ena_sel = sel.ob.x != -1 && sel.alt == IS_SET(MODE_ALTSCREEN);
+ XftGlyphFontSpec *specs = xw.specbuf;
- if (!(win.state & WIN_VISIBLE))
- return;
-
- for (y = y1; y < y2; y++) {
- if (!term.dirty[y])
+ 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)
continue;
-
- term.dirty[y] = 0;
-
- specs = term.specbuf;
- numspecs = xmakeglyphfontspecs(specs, &term.line[y][x1], x2 - x1, x1, y);
-
- i = ox = 0;
- for (x = x1; x < x2 && i < numspecs; x++) {
- new = term.line[y][x];
- if (new.mode == ATTR_WDUMMY)
- continue;
- if (ena_sel && selected(x, y))
- new.mode ^= ATTR_REVERSE;
- if (i > 0 && ATTRCMP(base, new)) {
- xdrawglyphfontspecs(specs, base, i, ox, y);
- specs += i;
- numspecs -= i;
- i = 0;
- }
- if (i == 0) {
- ox = x;
- base = new;
- }
- i++;
+ if (selected(x, y1))
+ new.mode ^= ATTR_REVERSE;
+ if (i > 0 && ATTRCMP(base, new)) {
+ xdrawglyphfontspecs(specs, base, i, ox, y1);
+ specs += i;
+ numspecs -= i;
+ i = 0;
+ }
+ if (i == 0) {
+ ox = x;
+ base = new;
}
- if (i > 0)
- xdrawglyphfontspecs(specs, base, i, ox, y);
+ i++;
}
- xdrawcursor();
+ if (i > 0)
+ xdrawglyphfontspecs(specs, base, i, ox, y1);
+}
+
+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);
}
void
@@ -1450,13 +1565,13 @@ visibility(XEvent *ev)
{
XVisibilityEvent *e = &ev->xvisibility;
- MODBIT(win.state, e->state != VisibilityFullyObscured, WIN_VISIBLE);
+ MODBIT(win.mode, e->state != VisibilityFullyObscured, MODE_VISIBLE);
}
void
unmap(XEvent *ev)
{
- win.state &= ~WIN_VISIBLE;
+ win.mode &= ~MODE_VISIBLE;
}
void
@@ -1467,6 +1582,25 @@ xsetpointermotion(int set)
}
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)
+{
+ DEFAULT(cursor, 1);
+ if (!BETWEEN(cursor, 0, 6))
+ return 1;
+ win.cursor = cursor;
+ return 0;
+}
+
+void
xseturgency(int add)
{
XWMHints *h = XGetWMHints(xw.dpy, xw.win);
@@ -1477,15 +1611,12 @@ xseturgency(int add)
}
void
-xbell(int vol)
+xbell(void)
{
- XkbBell(xw.dpy, xw.win, vol, (Atom)NULL);
-}
-
-unsigned long
-xwinid(void)
-{
- return xw.win;
+ if (!(IS_SET(MODE_FOCUSED)))
+ xseturgency(1);
+ if (bellvolume)
+ XkbBell(xw.dpy, xw.win, bellvolume, (Atom)NULL);
}
void
@@ -1498,18 +1629,61 @@ focus(XEvent *ev)
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);
+ 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);
+ ttywrite("\033[O", 3, 0);
}
}
+int
+match(uint mask, uint state)
+{
+ return mask == XK_ANY_MOD || mask == (state & ~ignoremod);
+}
+
+char*
+kmap(KeySym k, uint state)
+{
+ Key *kp;
+ int i;
+
+ /* Check for mapped keys out of X11 function keys. */
+ for (i = 0; i < LEN(mappedkeys); i++) {
+ if (mappedkeys[i] == k)
+ break;
+ }
+ if (i == LEN(mappedkeys)) {
+ if ((k & 0xFFFF) < 0xFD00)
+ return NULL;
+ }
+
+ for (kp = key; kp < key + LEN(key); kp++) {
+ if (kp->k != k)
+ continue;
+
+ if (!match(kp->mask, state))
+ continue;
+
+ if (IS_SET(MODE_APPKEYPAD) ? kp->appkey < 0 : kp->appkey > 0)
+ continue;
+ if (IS_SET(MODE_NUMLOCK) && kp->appkey == 2)
+ continue;
+
+ if (IS_SET(MODE_APPCURSOR) ? kp->appcursor < 0 : kp->appcursor > 0)
+ continue;
+
+ return kp->s;
+ }
+
+ return NULL;
+}
+
void
kpress(XEvent *ev)
{
@@ -1526,7 +1700,7 @@ kpress(XEvent *ev)
len = XmbLookupString(xw.xic, e, buf, sizeof buf, &ksym, &status);
/* 1. shortcuts */
- for (bp = shortcuts; bp < shortcuts + shortcutslen; bp++) {
+ for (bp = shortcuts; bp < shortcuts + LEN(shortcuts); bp++) {
if (ksym == bp->keysym && match(bp->mod, e->state)) {
bp->func(&(bp->arg));
return;
@@ -1535,7 +1709,7 @@ kpress(XEvent *ev)
/* 2. custom keys from config.h */
if ((customkey = kmap(ksym, e->state))) {
- ttysend(customkey, strlen(customkey));
+ ttywrite(customkey, strlen(customkey), 1);
return;
}
@@ -1554,7 +1728,7 @@ kpress(XEvent *ev)
len = 2;
}
}
- ttysend(buf, len);
+ ttywrite(buf, len, 1);
}
@@ -1567,14 +1741,13 @@ cmessage(XEvent *e)
*/
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) {
- win.state &= ~WIN_FOCUSED;
+ win.mode &= ~MODE_FOCUSED;
}
} else if (e->xclient.data.l[0] == xw.wmdeletewin) {
- /* Send SIGHUP to shell */
- kill(pid, SIGHUP);
+ ttyhangup();
exit(0);
}
}
@@ -1586,7 +1759,6 @@ resize(XEvent *e)
return;
cresize(e->xconfigure.width, e->xconfigure.height);
- ttyresize();
}
void
@@ -1596,6 +1768,7 @@ run(void)
int w = win.w, h = win.h;
fd_set rfd;
int xfd = XConnectionNumber(xw.dpy), xev, blinkset = 0, dodraw = 0;
+ int ttyfd;
struct timespec drawtimeout, *tv = NULL, now, last, lastblink;
long deltatime;
@@ -1615,29 +1788,28 @@ run(void)
}
} while (ev.type != MapNotify);
+ ttyfd = ttynew(opt_line, shell, opt_io, opt_cmd);
cresize(w, h);
- ttynew();
- ttyresize();
clock_gettime(CLOCK_MONOTONIC, &last);
lastblink = last;
for (xev = actionfps;;) {
FD_ZERO(&rfd);
- FD_SET(cmdfd, &rfd);
+ FD_SET(ttyfd, &rfd);
FD_SET(xfd, &rfd);
- if (pselect(MAX(xfd, cmdfd)+1, &rfd, NULL, NULL, tv, NULL) < 0) {
+ if (pselect(MAX(xfd, ttyfd)+1, &rfd, NULL, NULL, tv, NULL) < 0) {
if (errno == EINTR)
continue;
die("select failed: %s\n", strerror(errno));
}
- if (FD_ISSET(cmdfd, &rfd)) {
+ if (FD_ISSET(ttyfd, &rfd)) {
ttyread();
if (blinktimeout) {
blinkset = tattrset(ATTR_BLINK);
if (!blinkset)
- MODBIT(term.mode, 0, MODE_BLINK);
+ MODBIT(win.mode, 0, MODE_BLINK);
}
}
@@ -1652,7 +1824,7 @@ run(void)
dodraw = 0;
if (blinktimeout && TIMEDIFF(now, lastblink) > blinktimeout) {
tsetdirtattr(ATTR_BLINK);
- term.mode ^= MODE_BLINK;
+ win.mode ^= MODE_BLINK;
lastblink = now;
dodraw = 1;
}
@@ -1676,7 +1848,7 @@ run(void)
if (xev && !FD_ISSET(xfd, &rfd))
xev--;
- if (!FD_ISSET(cmdfd, &rfd) && !FD_ISSET(xfd, &rfd)) {
+ if (!FD_ISSET(ttyfd, &rfd) && !FD_ISSET(xfd, &rfd)) {
if (blinkset) {
if (TIMEDIFF(now, lastblink) \
> blinktimeout) {
@@ -1698,6 +1870,19 @@ run(void)
}
}
+void
+usage(void)
+{
+ die("usage: %s [-aiv] [-c class] [-f font] [-g geometry]"
+ " [-n name] [-o file]\n"
+ " [-T title] [-t title] [-w windowid]"
+ " [[-e] command [args ...]]\n"
+ " %s [-aiv] [-c class] [-f font] [-g geometry]"
+ " [-n name] [-o file]\n"
+ " [-T title] [-t title] [-w windowid] -l line"
+ " [stty_args ...]\n", argv0, argv0);
+}
+
int
main(int argc, char *argv[])
{
@@ -1743,23 +1928,26 @@ main(int argc, char *argv[])
opt_embed = EARGF(usage());
break;
case 'v':
- die("%s " VERSION " (c) 2010-2016 st engineers\n", argv0);
+ die("%s " VERSION "\n", argv0);
break;
default:
usage();
} ARGEND;
run:
- if (argc > 0) {
- /* eat all remaining arguments */
+ if (argc > 0) /* eat all remaining arguments */
opt_cmd = argv;
- if (!opt_title && !opt_line)
- opt_title = basename(xstrdup(argv[0]));
- }
+
+ if (!opt_title)
+ opt_title = (opt_line || !opt_cmd) ? "st" : opt_cmd[0];
+
setlocale(LC_CTYPE, "");
XSetLocaleModifiers("");
- tnew(MAX(cols, 1), MAX(rows, 1));
- xinit();
+ cols = MAX(cols, 1);
+ rows = MAX(rows, 1);
+ tnew(cols, rows);
+ xinit(cols, rows);
+ xsetenv();
selinit();
run();