0.8.4 update, scroll added as separate prog

This commit is contained in:
Luke Smith 2021-02-05 22:14:48 -05:00
parent 73c034ba05
commit fa3c401390
No known key found for this signature in database
GPG Key ID: 4C50B54A911F6252
15 changed files with 493 additions and 585 deletions

7
.gitignore vendored
View File

@ -1,5 +1,4 @@
st patches/
.gitignore
*.o *.o
pkg/ st
*.pkg.tar.xz
patches

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "scroll"]
path = scroll
url = https://github.com/lukesmithxyz/scroll.git

View File

@ -1,3 +1,2 @@
github: lukesmithxyz github: lukesmithxyz
custom: ["https://lukesmith.xyz/donate", "https://paypal.me/lukemsmith", "https://lukesmith.xyz/crypto"] custom: ["https://lukesmith.xyz/donate", "https://lukesmith.xyz/crypto"]
patreon: lukesmith

View File

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

View File

@ -15,9 +15,6 @@ options:
@echo "LDFLAGS = $(STLDFLAGS)" @echo "LDFLAGS = $(STLDFLAGS)"
@echo "CC = $(CC)" @echo "CC = $(CC)"
config.h:
cp config.def.h config.h
.c.o: .c.o:
$(CC) $(STCFLAGS) -c $< $(CC) $(STCFLAGS) -c $<
@ -32,17 +29,20 @@ st: $(OBJ)
$(CC) -o $@ $(OBJ) $(STLDFLAGS) $(CC) -o $@ $(OBJ) $(STLDFLAGS)
clean: clean:
rm -f st $(OBJ) st-$(VERSION).tar.gz *.o *.orig *.rej rm -f st $(OBJ) st-$(VERSION).tar.gz *.rej *.orig *.o
dist: clean dist: clean
mkdir -p st-$(VERSION) mkdir -p st-$(VERSION)
cp -R FAQ LEGACY TODO LICENSE Makefile README config.mk\ cp -R FAQ LEGACY TODO LICENSE Makefile README config.mk\
config.def.h st.info st.1 arg.h st.h win.h $(SRC)\ config.h st.info st.1 arg.h st.h win.h $(SRC)\
st-$(VERSION) st-$(VERSION)
tar -cf - st-$(VERSION) | gzip > st-$(VERSION).tar.gz tar -cf - st-$(VERSION) | gzip > st-$(VERSION).tar.gz
rm -rf st-$(VERSION) rm -rf st-$(VERSION)
install: st install: st
git submodule init
git submodule update
$(MAKE) install -C scroll
mkdir -p $(DESTDIR)$(PREFIX)/bin mkdir -p $(DESTDIR)$(PREFIX)/bin
cp -f st $(DESTDIR)$(PREFIX)/bin cp -f st $(DESTDIR)$(PREFIX)/bin
cp -f st-copyout $(DESTDIR)$(PREFIX)/bin cp -f st-copyout $(DESTDIR)$(PREFIX)/bin
@ -62,4 +62,4 @@ uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/st-urlhandler rm -f $(DESTDIR)$(PREFIX)/bin/st-urlhandler
rm -f $(DESTDIR)$(MANPREFIX)/man1/st.1 rm -f $(DESTDIR)$(MANPREFIX)/man1/st.1
.PHONY: all options clean dist install uninstall .PHONY: all options clean dist scroll install uninstall

View File

@ -10,7 +10,7 @@ The [suckless terminal (st)](https://st.suckless.org/) with some additional feat
## Bindings for ## Bindings for
+ **scrollback** with `alt-↑/↓` or `alt-pageup/down` or `shift` while scrolling the mouse + scroll with `alt-↑/↓` or `alt-pageup/down` or `shift` while scrolling the mouse ([scroll](https://github.com/lukesmithxyz/scroll) must be installed)
+ OR **vim-bindings**: scroll up/down in history with `alt-k` and `alt-j`. Faster with `alt-u`/`alt-d`. + OR **vim-bindings**: scroll up/down in history with `alt-k` and `alt-j`. Faster with `alt-u`/`alt-d`.
+ **zoom/change font size**: same bindings as above, but holding down shift as well. `alt-home` returns to default + **zoom/change font size**: same bindings as above, but holding down shift as well. `alt-home` returns to default
+ **copy text** with `alt-c`, **paste** is `alt-v` or `shift-insert` + **copy text** with `alt-c`, **paste** is `alt-v` or `shift-insert`
@ -24,10 +24,10 @@ The [suckless terminal (st)](https://st.suckless.org/) with some additional feat
## Other st patches ## Other st patches
+ Vertcenter + Boxdraw
+ Scrollback + Ligatures
+ font2 + font2
+ updated to latest version 0.8.2 + updated to latest version 0.8.4
## Installation for newbs ## Installation for newbs

View File

@ -5,20 +5,22 @@
* *
* font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html * font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
*/ */
static char *font = "mono:pixelsize=14:antialias=true:autohint=true"; static char *font = "mono:pixelsize=12:antialias=true:autohint=true";
static char *font2[] = { "JoyPixels:pixelsize=10:antialias=true:autohint=true" }; static char *font2[] = { "JoyPixels:pixelsize=10:antialias=true:autohint=true" };
static int borderpx = 2; static int borderpx = 2;
/* /*
* What program is execed by st depends of these precedence rules: * What program is execed by st depends of these precedence rules:
* 1: program passed with -e * 1: program passed with -e
* 2: utmp option * 2: scroll and/or utmp
* 3: SHELL environment variable * 3: SHELL environment variable
* 4: value of shell in /etc/passwd * 4: value of shell in /etc/passwd
* 5: value of shell in config.h * 5: value of shell in config.h
*/ */
static char *shell = "/bin/sh"; static char *shell = "/bin/sh";
char *utmp = NULL; char *utmp = NULL;
/* scroll program: to enable use a string like "scroll" */
char *scroll = "scroll";
char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400"; char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400";
/* identification sequence returned in DA and DECID */ /* identification sequence returned in DA and DECID */
@ -42,6 +44,10 @@ static unsigned int tripleclicktimeout = 600;
/* alt screens */ /* alt screens */
int allowaltscreen = 1; int allowaltscreen = 1;
/* allow certain non-interactive (insecure) window operations such as:
setting the clipboard text */
int allowwindowops = 0;
/* /*
* draw latency range in ms - from new content/keypress/etc until drawing. * draw latency range in ms - from new content/keypress/etc until drawing.
* within this range, st draws when content stops arriving (idle). mostly it's * within this range, st draws when content stops arriving (idle). mostly it's
@ -57,13 +63,6 @@ static double maxlatency = 33;
*/ */
static unsigned int blinktimeout = 800; static unsigned int blinktimeout = 800;
/*
* interval (in milliseconds) between each successive call to ximspot. This
* improves terminal performance while not reducing functionality to those
* whom need XIM support.
*/
int ximspot_update_interval = 1000;
/* /*
* thickness of underline and bar cursors * thickness of underline and bar cursors
*/ */
@ -76,10 +75,10 @@ static unsigned int cursorthickness = 2;
* 0: disable (render all U25XX glyphs normally from the font). * 0: disable (render all U25XX glyphs normally from the font).
*/ */
const int boxdraw = 1; const int boxdraw = 1;
const int boxdraw_bold = 1; const int boxdraw_bold = 0;
/* braille (U28XX): 1: render as adjacent "pixels", 0: use font */ /* braille (U28XX): 1: render as adjacent "pixels", 0: use font */
const int boxdraw_braille = 1; const int boxdraw_braille = 0;
/* /*
* bell volume. It must be a value between -100 and 100. Use 0 for disabling * bell volume. It must be a value between -100 and 100. Use 0 for disabling
@ -175,6 +174,13 @@ static unsigned int mousebg = 0;
*/ */
static unsigned int defaultattr = 11; static unsigned int defaultattr = 11;
/*
* Force mouse select/shortcuts while mask is active (when MODE_MOUSE is set).
* Note that if you want to use ShiftMask with selmasks, set this to an other
* modifier, set to 0 to not use it.
*/
static uint forcemousemod = ShiftMask;
/* /*
* Xresources preferences to load at startup * Xresources preferences to load at startup
*/ */
@ -202,6 +208,8 @@ ResourcePref resources[] = {
{ "cursorColor", STRING, &colorname[256] }, { "cursorColor", STRING, &colorname[256] },
{ "termname", STRING, &termname }, { "termname", STRING, &termname },
{ "shell", STRING, &shell }, { "shell", STRING, &shell },
{ "minlatency", INTEGER, &minlatency },
{ "maxlatency", INTEGER, &maxlatency },
{ "blinktimeout", INTEGER, &blinktimeout }, { "blinktimeout", INTEGER, &blinktimeout },
{ "bellvolume", INTEGER, &bellvolume }, { "bellvolume", INTEGER, &bellvolume },
{ "tabspaces", INTEGER, &tabspaces }, { "tabspaces", INTEGER, &tabspaces },
@ -209,7 +217,6 @@ ResourcePref resources[] = {
{ "cwscale", FLOAT, &cwscale }, { "cwscale", FLOAT, &cwscale },
{ "chscale", FLOAT, &chscale }, { "chscale", FLOAT, &chscale },
{ "alpha", FLOAT, &alpha }, { "alpha", FLOAT, &alpha },
{ "ximspot_update_interval", INTEGER, &ximspot_update_interval },
}; };
/* /*
@ -217,27 +224,23 @@ ResourcePref resources[] = {
* Beware that overloading Button1 will disable the selection. * Beware that overloading Button1 will disable the selection.
*/ */
static MouseShortcut mshortcuts[] = { static MouseShortcut mshortcuts[] = {
/* button mask string */ /* mask button function argument release */
{ Button4, XK_NO_MOD, "\031" }, { XK_ANY_MOD, Button2, selpaste, {.i = 0}, 1 },
{ Button5, XK_NO_MOD, "\005" }, { ShiftMask, Button4, ttysend, {.s = "\033[5;2~"} },
{ XK_ANY_MOD, Button4, ttysend, {.s = "\031"} },
{ ShiftMask, Button5, ttysend, {.s = "\033[6;2~"} },
{ XK_ANY_MOD, Button5, ttysend, {.s = "\005"} },
}; };
/* Internal keyboard shortcuts. */ /* Internal keyboard shortcuts. */
#define MODKEY Mod1Mask #define MODKEY Mod1Mask
#define TERMMOD (Mod1Mask|ShiftMask) #define TERMMOD (Mod1Mask|ShiftMask)
MouseKey mkeys[] = {
/* button mask function argument */
{ Button4, XK_NO_MOD, kscrollup, {.i = 1} },
{ Button5, XK_NO_MOD, kscrolldown, {.i = 1} },
{ Button4, TERMMOD, zoom, {.f = +1} },
{ Button5, TERMMOD, zoom, {.f = -1} },
};
static char *openurlcmd[] = { "/bin/sh", "-c", "st-urlhandler -o", "externalpipe", NULL }; static char *openurlcmd[] = { "/bin/sh", "-c", "st-urlhandler -o", "externalpipe", NULL };
static char *copyurlcmd[] = { "/bin/sh", "-c", "st-urlhandler -c", "externalpipe", NULL }; static char *copyurlcmd[] = { "/bin/sh", "-c", "st-urlhandler -c", "externalpipe", NULL };
static char *copyoutput[] = { "/bin/sh", "-c", "st-copyout", "externalpipe", NULL }; static char *copyoutput[] = { "/bin/sh", "-c", "st-copyout", "externalpipe", NULL };
static Shortcut shortcuts[] = { static Shortcut shortcuts[] = {
/* mask keysym function argument */ /* mask keysym function argument */
{ XK_ANY_MOD, XK_Break, sendbreak, {.i = 0} }, { XK_ANY_MOD, XK_Break, sendbreak, {.i = 0} },
@ -246,23 +249,14 @@ static Shortcut shortcuts[] = {
{ XK_ANY_MOD, XK_Print, printsel, {.i = 0} }, { XK_ANY_MOD, XK_Print, printsel, {.i = 0} },
{ TERMMOD, XK_Prior, zoom, {.f = +1} }, { TERMMOD, XK_Prior, zoom, {.f = +1} },
{ TERMMOD, XK_Next, zoom, {.f = -1} }, { TERMMOD, XK_Next, zoom, {.f = -1} },
{ MODKEY, XK_Home, zoomreset, {.f = 0} }, { TERMMOD, XK_Home, zoomreset, {.f = 0} },
{ TERMMOD, XK_C, clipcopy, {.i = 0} },
{ TERMMOD, XK_V, clippaste, {.i = 0} },
{ MODKEY, XK_c, clipcopy, {.i = 0} }, { MODKEY, XK_c, clipcopy, {.i = 0} },
{ ShiftMask, XK_Insert, clippaste, {.i = 0} }, { ShiftMask, XK_Insert, clippaste, {.i = 0} },
{ MODKEY, XK_v, clippaste, {.i = 0} }, { MODKEY, XK_v, clippaste, {.i = 0} },
{ XK_ANY_MOD, Button2, selpaste, {.i = 0} }, { ShiftMask, XK_Insert, selpaste, {.i = 0} },
{ MODKEY, XK_Num_Lock, numlock, {.i = 0} }, { TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
{ MODKEY, XK_Control_L, iso14755, {.i = 0} },
{ ShiftMask, XK_Page_Up, kscrollup, {.i = -1} },
{ ShiftMask, XK_Page_Down, kscrolldown, {.i = -1} },
{ MODKEY, XK_Page_Up, kscrollup, {.i = -1} },
{ MODKEY, XK_Page_Down, kscrolldown, {.i = -1} },
{ MODKEY, XK_k, kscrollup, {.i = 1} },
{ MODKEY, XK_j, kscrolldown, {.i = 1} },
{ MODKEY, XK_Up, kscrollup, {.i = 1} },
{ MODKEY, XK_Down, kscrolldown, {.i = 1} },
{ MODKEY, XK_u, kscrollup, {.i = -1} },
{ MODKEY, XK_d, kscrolldown, {.i = -1} },
{ MODKEY, XK_s, changealpha, {.f = -0.05} }, { MODKEY, XK_s, changealpha, {.f = -0.05} },
{ MODKEY, XK_a, changealpha, {.f = +0.05} }, { MODKEY, XK_a, changealpha, {.f = +0.05} },
{ TERMMOD, XK_Up, zoom, {.f = +1} }, { TERMMOD, XK_Up, zoom, {.f = +1} },
@ -291,10 +285,6 @@ static Shortcut shortcuts[] = {
* * 0: no value * * 0: no value
* * > 0: cursor application mode enabled * * > 0: cursor application mode enabled
* * < 0: cursor application mode disabled * * < 0: cursor application mode disabled
* crlf value
* * 0: no value
* * > 0: crlf mode is enabled
* * < 0: crlf mode is disabled
* *
* Be careful with the order of the definitions because st searches in * Be careful with the order of the definitions because st searches in
* this table sequentially, so any XK_ANY_MOD must be in the last * this table sequentially, so any XK_ANY_MOD must be in the last
@ -313,13 +303,6 @@ static KeySym mappedkeys[] = { -1 };
*/ */
static uint ignoremod = Mod2Mask|XK_SWITCH_MOD; static uint ignoremod = Mod2Mask|XK_SWITCH_MOD;
/*
* Override mouse-select while mask is active (when MODE_MOUSE is set).
* Note that if you want to use ShiftMask with selmasks, set this to an other
* modifier, set to 0 to not use it.
*/
static uint forceselmod = ShiftMask;
/* /*
* This is the huge key array which defines all compatibility to the Linux * This is the huge key array which defines all compatibility to the Linux
* world. Please decide about changes wisely. * world. Please decide about changes wisely.

View File

@ -1,19 +1,15 @@
# st version # st version
VERSION = 0.8.2 VERSION = 0.8.4
# Customize below to fit your system # Customize below to fit your system
# paths # paths
PREFIX ?= /usr/local PREFIX = /usr/local
MANPREFIX = $(PREFIX)/share/man MANPREFIX = $(PREFIX)/share/man
X11INC = /usr/X11R6/include X11INC = /usr/X11R6/include
X11LIB = /usr/X11R6/lib X11LIB = /usr/X11R6/lib
# include X11 in Ubuntu
# X11INC = /usr/include/X11R6
# X11LIB = /usr/lib/X11R6
PKG_CONFIG = pkg-config PKG_CONFIG = pkg-config
# includes and libs # includes and libs
@ -34,8 +30,8 @@ STLDFLAGS = $(LIBS) $(LDFLAGS)
# OpenBSD: # OpenBSD:
#CPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600 -D_BSD_SOURCE #CPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600 -D_BSD_SOURCE
#LIBS = -L$(X11LIB) -lm -lX11 -lutil -lXft \ #LIBS = -L$(X11LIB) -lm -lX11 -lutil -lXft \
# `pkg-config --libs fontconfig` \ # `$(PKG_CONFIG) --libs fontconfig` \
# `pkg-config --libs freetype2` # `$(PKG_CONFIG) --libs freetype2`
# compiler and linker # compiler and linker
# CC = c99 # CC = c99

1
scroll Submodule

@ -0,0 +1 @@
Subproject commit 210539923ef83edff0e7519a54455b7f89aabdbc

10
st.1
View File

@ -1,6 +1,6 @@
.TH ST 1 st\-VERSION .TH ST 1 st\-VERSION
.SH NAME .SH NAME
st \- simple terminal (Luke Smith (https://lukesmith.xyz)'s build) st \- simple terminal
.SH SYNOPSIS .SH SYNOPSIS
.B st .B st
.RB [ \-aiv ] .RB [ \-aiv ]
@ -176,10 +176,6 @@ Print the full screen to the
.B Print Screen .B Print Screen
Print the selection to the Print the selection to the
.I iofile. .I iofile.
.TP
.B Alt-Ctrl
Launch dmenu to enter a unicode codepoint and send the corresponding glyph
to st.
.SH CUSTOMIZATION .SH CUSTOMIZATION
.B st .B st
can be customized by creating a custom config.h and (re)compiling the source can be customized by creating a custom config.h and (re)compiling the source
@ -191,7 +187,7 @@ See the LICENSE file for the terms of redistribution.
.SH SEE ALSO .SH SEE ALSO
.BR tabbed (1), .BR tabbed (1),
.BR utmp (1), .BR utmp (1),
.BR stty (1) .BR stty (1),
.BR scroll (1)
.SH BUGS .SH BUGS
See the TODO file in the distribution. See the TODO file in the distribution.

436
st.c
View File

@ -14,7 +14,6 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <termios.h> #include <termios.h>
#include <time.h>
#include <unistd.h> #include <unistd.h>
#include <wchar.h> #include <wchar.h>
@ -36,23 +35,13 @@
#define ESC_ARG_SIZ 16 #define ESC_ARG_SIZ 16
#define STR_BUF_SIZ ESC_BUF_SIZ #define STR_BUF_SIZ ESC_BUF_SIZ
#define STR_ARG_SIZ ESC_ARG_SIZ #define STR_ARG_SIZ ESC_ARG_SIZ
#define HISTSIZE 2000
/* macros */ /* macros */
#define IS_SET(flag) ((term.mode & (flag)) != 0) #define IS_SET(flag) ((term.mode & (flag)) != 0)
#define NUMMAXLEN(x) ((int)(sizeof(x) * 2.56 + 0.5) + 1) #define ISCONTROLC0(c) (BETWEEN(c, 0, 0x1f) || (c) == 0x7f)
#define ISCONTROLC0(c) (BETWEEN(c, 0, 0x1f) || (c) == '\177')
#define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f)) #define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f))
#define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c)) #define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c))
#define ISDELIM(u) (u && wcschr(worddelimiters, u)) #define ISDELIM(u) (u && wcschr(worddelimiters, u))
#define TLINE(y) ((y) < term.scr ? term.hist[((y) + term.histi - \
term.scr + HISTSIZE + 1) % HISTSIZE] : \
term.line[(y) - term.scr])
#define TLINE_HIST(y) ((y) <= HISTSIZE-term.row+2 ? term.hist[(y)] : term.line[(y-HISTSIZE+term.row-3)])
/* constants */
#define ISO14755CMD "dmenu -w \"$WINDOWID\" -p codepoint: </dev/null"
enum term_mode { enum term_mode {
MODE_WRAP = 1 << 0, MODE_WRAP = 1 << 0,
@ -62,7 +51,6 @@ enum term_mode {
MODE_ECHO = 1 << 4, MODE_ECHO = 1 << 4,
MODE_PRINT = 1 << 5, MODE_PRINT = 1 << 5,
MODE_UTF8 = 1 << 6, MODE_UTF8 = 1 << 6,
MODE_SIXEL = 1 << 7,
}; };
enum cursor_movement { enum cursor_movement {
@ -89,12 +77,11 @@ enum charset {
enum escape_state { enum escape_state {
ESC_START = 1, ESC_START = 1,
ESC_CSI = 2, ESC_CSI = 2,
ESC_STR = 4, /* OSC, PM, APC */ ESC_STR = 4, /* DCS, OSC, PM, APC */
ESC_ALTCHARSET = 8, ESC_ALTCHARSET = 8,
ESC_STR_END = 16, /* a final string was encountered */ ESC_STR_END = 16, /* a final string was encountered */
ESC_TEST = 32, /* Enter in test mode */ ESC_TEST = 32, /* Enter in test mode */
ESC_UTF8 = 64, ESC_UTF8 = 64,
ESC_DCS =128,
}; };
typedef struct { typedef struct {
@ -128,9 +115,6 @@ typedef struct {
int col; /* nb col */ int col; /* nb col */
Line *line; /* screen */ Line *line; /* screen */
Line *alt; /* alternate screen */ Line *alt; /* alternate screen */
Line hist[HISTSIZE]; /* history buffer */
int histi; /* history index */
int scr; /* scroll back */
int *dirty; /* dirtyness of lines */ int *dirty; /* dirtyness of lines */
TCursor c; /* cursor */ TCursor c; /* cursor */
int ocx; /* old cursor col */ int ocx; /* old cursor col */
@ -143,14 +127,14 @@ typedef struct {
int charset; /* current charset */ int charset; /* current charset */
int icharset; /* selected charset for sequence */ int icharset; /* selected charset for sequence */
int *tabs; int *tabs;
struct timespec last_ximspot_update; Rune lastc; /* last printed char outside of sequence, 0 if control */
} Term; } Term;
/* CSI Escape sequence structs */ /* CSI Escape sequence structs */
/* ESC '[' [[ [<priv>] <arg> [;]] <mode> [<mode>]] */ /* ESC '[' [[ [<priv>] <arg> [;]] <mode> [<mode>]] */
typedef struct { typedef struct {
char buf[ESC_BUF_SIZ]; /* raw string */ char buf[ESC_BUF_SIZ]; /* raw string */
int len; /* raw string length */ size_t len; /* raw string length */
char priv; char priv;
int arg[ESC_ARG_SIZ]; int arg[ESC_ARG_SIZ];
int narg; /* nb of args */ int narg; /* nb of args */
@ -161,8 +145,9 @@ typedef struct {
/* ESC type [[ [<priv>] <arg> [;]] <mode>] ESC '\' */ /* ESC type [[ [<priv>] <arg> [;]] <mode>] ESC '\' */
typedef struct { typedef struct {
char type; /* ESC type ... */ char type; /* ESC type ... */
char buf[STR_BUF_SIZ]; /* raw string */ char *buf; /* allocated raw string */
int len; /* raw string length */ size_t siz; /* allocation size */
size_t len; /* raw string length */
char *args[STR_ARG_SIZ]; char *args[STR_ARG_SIZ];
int narg; /* nb of args */ int narg; /* nb of args */
} STREscape; } STREscape;
@ -199,8 +184,8 @@ static void tnewline(int);
static void tputtab(int); static void tputtab(int);
static void tputc(Rune); static void tputc(Rune);
static void treset(void); static void treset(void);
static void tscrollup(int, int, int); static void tscrollup(int, int);
static void tscrolldown(int, int, int); static void tscrolldown(int, int);
static void tsetattr(int *, int); static void tsetattr(int *, int);
static void tsetchar(Rune, Glyph *, int, int); static void tsetchar(Rune, Glyph *, int, int);
static void tsetdirt(int, int); static void tsetdirt(int, int);
@ -380,8 +365,9 @@ static const char base64_digits[] = {
char char
base64dec_getc(const char **src) base64dec_getc(const char **src)
{ {
while (**src && !isprint(**src)) (*src)++; while (**src && !isprint(**src))
return *((*src)++); (*src)++;
return **src ? *((*src)++) : '='; /* emulate padding if string ends */
} }
char * char *
@ -399,6 +385,10 @@ base64dec(const char *src)
int c = base64_digits[(unsigned char) base64dec_getc(&src)]; int c = base64_digits[(unsigned char) base64dec_getc(&src)];
int d = base64_digits[(unsigned char) base64dec_getc(&src)]; int d = base64_digits[(unsigned char) base64dec_getc(&src)];
/* invalid input. 'a' can be -1, e.g. if src is "\n" (c-str) */
if (a == -1 || b == -1)
break;
*dst++ = (a << 2) | ((b & 0x30) >> 4); *dst++ = (a << 2) | ((b & 0x30) >> 4);
if (c == -1) if (c == -1)
break; break;
@ -424,24 +414,10 @@ tlinelen(int y)
{ {
int i = term.col; int i = term.col;
if (TLINE(y)[i - 1].mode & ATTR_WRAP) if (term.line[y][i - 1].mode & ATTR_WRAP)
return i; return i;
while (i > 0 && TLINE(y)[i - 1].u == ' ') while (i > 0 && term.line[y][i - 1].u == ' ')
--i;
return i;
}
int
tlinehistlen(int y)
{
int i = term.col;
if (TLINE_HIST(y)[i - 1].mode & ATTR_WRAP)
return i;
while (i > 0 && TLINE_HIST(y)[i - 1].u == ' ')
--i; --i;
return i; return i;
@ -550,7 +526,7 @@ selsnap(int *x, int *y, int direction)
* Snap around if the word wraps around at the end or * Snap around if the word wraps around at the end or
* beginning of a line. * beginning of a line.
*/ */
prevgp = &TLINE(*y)[*x]; prevgp = &term.line[*y][*x];
prevdelim = ISDELIM(prevgp->u); prevdelim = ISDELIM(prevgp->u);
for (;;) { for (;;) {
newx = *x + direction; newx = *x + direction;
@ -565,14 +541,14 @@ selsnap(int *x, int *y, int direction)
yt = *y, xt = *x; yt = *y, xt = *x;
else else
yt = newy, xt = newx; yt = newy, xt = newx;
if (!(TLINE(yt)[xt].mode & ATTR_WRAP)) if (!(term.line[yt][xt].mode & ATTR_WRAP))
break; break;
} }
if (newx >= tlinelen(newy)) if (newx >= tlinelen(newy))
break; break;
gp = &TLINE(newy)[newx]; gp = &term.line[newy][newx];
delim = ISDELIM(gp->u); delim = ISDELIM(gp->u);
if (!(gp->mode & ATTR_WDUMMY) && (delim != prevdelim if (!(gp->mode & ATTR_WDUMMY) && (delim != prevdelim
|| (delim && gp->u != prevgp->u))) || (delim && gp->u != prevgp->u)))
@ -593,14 +569,14 @@ selsnap(int *x, int *y, int direction)
*x = (direction < 0) ? 0 : term.col - 1; *x = (direction < 0) ? 0 : term.col - 1;
if (direction < 0) { if (direction < 0) {
for (; *y > 0; *y += direction) { for (; *y > 0; *y += direction) {
if (!(TLINE(*y-1)[term.col-1].mode if (!(term.line[*y-1][term.col-1].mode
& ATTR_WRAP)) { & ATTR_WRAP)) {
break; break;
} }
} }
} else if (direction > 0) { } else if (direction > 0) {
for (; *y < term.row-1; *y += direction) { for (; *y < term.row-1; *y += direction) {
if (!(TLINE(*y)[term.col-1].mode if (!(term.line[*y][term.col-1].mode
& ATTR_WRAP)) { & ATTR_WRAP)) {
break; break;
} }
@ -631,13 +607,13 @@ getsel(void)
} }
if (sel.type == SEL_RECTANGULAR) { if (sel.type == SEL_RECTANGULAR) {
gp = &TLINE(y)[sel.nb.x]; gp = &term.line[y][sel.nb.x];
lastx = sel.ne.x; lastx = sel.ne.x;
} else { } else {
gp = &TLINE(y)[sel.nb.y == y ? sel.nb.x : 0]; gp = &term.line[y][sel.nb.y == y ? sel.nb.x : 0];
lastx = (sel.ne.y == y) ? sel.ne.x : term.col-1; lastx = (sel.ne.y == y) ? sel.ne.x : term.col-1;
} }
last = &TLINE(y)[MIN(lastx, linelen-1)]; last = &term.line[y][MIN(lastx, linelen-1)];
while (last >= gp && last->u == ' ') while (last >= gp && last->u == ' ')
--last; --last;
@ -657,7 +633,8 @@ getsel(void)
* st. * st.
* FIXME: Fix the computer world. * FIXME: Fix the computer world.
*/ */
if ((y < sel.ne.y || lastx >= linelen) && !(last->mode & ATTR_WRAP)) if ((y < sel.ne.y || lastx >= linelen) &&
(!(last->mode & ATTR_WRAP) || sel.type == SEL_RECTANGULAR))
*ptr++ = '\n'; *ptr++ = '\n';
} }
*ptr = 0; *ptr = 0;
@ -688,7 +665,7 @@ die(const char *errstr, ...)
void void
execsh(char *cmd, char **args) execsh(char *cmd, char **args)
{ {
char *sh, *prog; char *sh, *prog, *arg;
const struct passwd *pw; const struct passwd *pw;
errno = 0; errno = 0;
@ -702,13 +679,20 @@ execsh(char *cmd, char **args)
if ((sh = getenv("SHELL")) == NULL) if ((sh = getenv("SHELL")) == NULL)
sh = (pw->pw_shell[0]) ? pw->pw_shell : cmd; sh = (pw->pw_shell[0]) ? pw->pw_shell : cmd;
if (args) if (args) {
prog = args[0]; prog = args[0];
else if (utmp) arg = NULL;
} else if (scroll) {
prog = scroll;
arg = utmp ? utmp : sh;
} else if (utmp) {
prog = utmp; prog = utmp;
else arg = NULL;
} else {
prog = sh; prog = sh;
DEFAULT(args, ((char *[]) {prog, NULL})); arg = NULL;
}
DEFAULT(args, ((char *[]) {prog, arg, NULL}));
unsetenv("COLUMNS"); unsetenv("COLUMNS");
unsetenv("LINES"); unsetenv("LINES");
@ -746,7 +730,7 @@ sigchld(int a)
die("child exited with status %d\n", WEXITSTATUS(stat)); die("child exited with status %d\n", WEXITSTATUS(stat));
else if (WIFSIGNALED(stat)) else if (WIFSIGNALED(stat))
die("child terminated due to signal %d\n", WTERMSIG(stat)); die("child terminated due to signal %d\n", WTERMSIG(stat));
exit(0); _exit(0);
} }
void void
@ -839,30 +823,31 @@ ttyread(void)
{ {
static char buf[BUFSIZ]; static char buf[BUFSIZ];
static int buflen = 0; static int buflen = 0;
int written; int ret, written;
int ret;
/* append read bytes to unprocessed bytes */ /* append read bytes to unprocessed bytes */
if ((ret = read(cmdfd, buf+buflen, LEN(buf)-buflen)) < 0) ret = read(cmdfd, buf+buflen, LEN(buf)-buflen);
die("couldn't read from shell: %s\n", strerror(errno));
buflen += ret;
switch (ret) {
case 0:
exit(0);
case -1:
die("couldn't read from shell: %s\n", strerror(errno));
default:
buflen += ret;
written = twrite(buf, buflen, 0); written = twrite(buf, buflen, 0);
buflen -= written; buflen -= written;
/* keep any uncomplete utf8 char for the next call */ /* keep any incomplete UTF-8 byte sequence for the next call */
if (buflen > 0) if (buflen > 0)
memmove(buf, buf + written, buflen); memmove(buf, buf + written, buflen);
return ret; return ret;
} }
}
void void
ttywrite(const char *s, size_t n, int may_echo) ttywrite(const char *s, size_t n, int may_echo)
{ {
const char *next; const char *next;
Arg arg = (Arg) { .i = term.scr };
kscrolldown(&arg);
if (may_echo && IS_SET(MODE_ECHO)) if (may_echo && IS_SET(MODE_ECHO))
twrite(s, n, 1); twrite(s, n, 1);
@ -1058,16 +1043,10 @@ void
tnew(int col, int row) tnew(int col, int row)
{ {
term = (Term){ .c = { .attr = { .fg = defaultfg, .bg = defaultbg } } }; term = (Term){ .c = { .attr = { .fg = defaultfg, .bg = defaultbg } } };
clock_gettime(CLOCK_MONOTONIC, &term.last_ximspot_update);
tresize(col, row); tresize(col, row);
treset(); treset();
} }
int tisaltscr(void)
{
return IS_SET(MODE_ALTSCREEN);
}
void void
tswapscreen(void) tswapscreen(void)
{ {
@ -1080,53 +1059,13 @@ tswapscreen(void)
} }
void void
kscrolldown(const Arg* a) tscrolldown(int orig, int n)
{
int n = a->i;
if (n < 0)
n = term.row + n;
if (n > term.scr)
n = term.scr;
if (term.scr > 0) {
term.scr -= n;
selscroll(0, -n);
tfulldirt();
}
}
void
kscrollup(const Arg* a)
{
int n = a->i;
if (n < 0)
n = term.row + n;
if (term.scr <= HISTSIZE-n) {
term.scr += n;
selscroll(0, n);
tfulldirt();
}
}
void
tscrolldown(int orig, int n, int copyhist)
{ {
int i; int i;
Line temp; Line temp;
LIMIT(n, 0, term.bot-orig+1); LIMIT(n, 0, term.bot-orig+1);
if (copyhist) {
term.histi = (term.histi - 1 + HISTSIZE) % HISTSIZE;
temp = term.hist[term.histi];
term.hist[term.histi] = term.line[term.bot];
term.line[term.bot] = temp;
}
tsetdirt(orig, term.bot-n); tsetdirt(orig, term.bot-n);
tclearregion(0, term.bot-n+1, term.col-1, term.bot); tclearregion(0, term.bot-n+1, term.col-1, term.bot);
@ -1140,23 +1079,13 @@ tscrolldown(int orig, int n, int copyhist)
} }
void void
tscrollup(int orig, int n, int copyhist) tscrollup(int orig, int n)
{ {
int i; int i;
Line temp; Line temp;
LIMIT(n, 0, term.bot-orig+1); LIMIT(n, 0, term.bot-orig+1);
if (copyhist) {
term.histi = (term.histi + 1) % HISTSIZE;
temp = term.hist[term.histi];
term.hist[term.histi] = term.line[orig];
term.line[orig] = temp;
}
if (term.scr > 0 && term.scr < HISTSIZE)
term.scr = MIN(term.scr + n, HISTSIZE-1);
tclearregion(0, orig, term.col-1, orig+n-1); tclearregion(0, orig, term.col-1, orig+n-1);
tsetdirt(orig+n, term.bot); tsetdirt(orig+n, term.bot);
@ -1175,29 +1104,19 @@ selscroll(int orig, int n)
if (sel.ob.x == -1) if (sel.ob.x == -1)
return; return;
if (BETWEEN(sel.ob.y, orig, term.bot) || BETWEEN(sel.oe.y, orig, term.bot)) { if (BETWEEN(sel.nb.y, orig, term.bot) != BETWEEN(sel.ne.y, orig, term.bot)) {
if ((sel.ob.y += n) > term.bot || (sel.oe.y += n) < term.top) { selclear();
} else if (BETWEEN(sel.nb.y, orig, term.bot)) {
sel.ob.y += n;
sel.oe.y += n;
if (sel.ob.y < term.top || sel.ob.y > term.bot ||
sel.oe.y < term.top || sel.oe.y > term.bot) {
selclear(); selclear();
return;
}
if (sel.type == SEL_RECTANGULAR) {
if (sel.ob.y < term.top)
sel.ob.y = term.top;
if (sel.oe.y > term.bot)
sel.oe.y = term.bot;
} else { } else {
if (sel.ob.y < term.top) {
sel.ob.y = term.top;
sel.ob.x = 0;
}
if (sel.oe.y > term.bot) {
sel.oe.y = term.bot;
sel.oe.x = term.col;
}
}
selnormalize(); selnormalize();
} }
} }
}
void void
tnewline(int first_col) tnewline(int first_col)
@ -1205,7 +1124,7 @@ tnewline(int first_col)
int y = term.c.y; int y = term.c.y;
if (y == term.bot) { if (y == term.bot) {
tscrollup(term.top, 1, 1); tscrollup(term.top, 1);
} else { } else {
y++; y++;
} }
@ -1373,14 +1292,14 @@ void
tinsertblankline(int n) tinsertblankline(int n)
{ {
if (BETWEEN(term.c.y, term.top, term.bot)) if (BETWEEN(term.c.y, term.top, term.bot))
tscrolldown(term.c.y, n, 0); tscrolldown(term.c.y, n);
} }
void void
tdeleteline(int n) tdeleteline(int n)
{ {
if (BETWEEN(term.c.y, term.top, term.bot)) if (BETWEEN(term.c.y, term.top, term.bot))
tscrollup(term.c.y, n, 0); tscrollup(term.c.y, n);
} }
int32_t int32_t
@ -1730,6 +1649,12 @@ csihandle(void)
if (csiescseq.arg[0] == 0) if (csiescseq.arg[0] == 0)
ttywrite(vtiden, strlen(vtiden), 0); ttywrite(vtiden, strlen(vtiden), 0);
break; break;
case 'b': /* REP -- if last char is printable print it <n> more times */
DEFAULT(csiescseq.arg[0], 1);
if (term.lastc)
while (csiescseq.arg[0]-- > 0)
tputc(term.lastc);
break;
case 'C': /* CUF -- Cursor <n> Forward */ case 'C': /* CUF -- Cursor <n> Forward */
case 'a': /* HPR -- Cursor <n> Forward */ case 'a': /* HPR -- Cursor <n> Forward */
DEFAULT(csiescseq.arg[0], 1); DEFAULT(csiescseq.arg[0], 1);
@ -1811,11 +1736,11 @@ csihandle(void)
break; break;
case 'S': /* SU -- Scroll <n> line up */ case 'S': /* SU -- Scroll <n> line up */
DEFAULT(csiescseq.arg[0], 1); DEFAULT(csiescseq.arg[0], 1);
tscrollup(term.top, csiescseq.arg[0], 0); tscrollup(term.top, csiescseq.arg[0]);
break; break;
case 'T': /* SD -- Scroll <n> line down */ case 'T': /* SD -- Scroll <n> line down */
DEFAULT(csiescseq.arg[0], 1); DEFAULT(csiescseq.arg[0], 1);
tscrolldown(term.top, csiescseq.arg[0], 0); tscrolldown(term.top, csiescseq.arg[0]);
break; break;
case 'L': /* IL -- Insert <n> blank lines */ case 'L': /* IL -- Insert <n> blank lines */
DEFAULT(csiescseq.arg[0], 1); DEFAULT(csiescseq.arg[0], 1);
@ -1890,7 +1815,7 @@ csihandle(void)
void void
csidump(void) csidump(void)
{ {
int i; size_t i;
uint c; uint c;
fprintf(stderr, "ESC["); fprintf(stderr, "ESC[");
@ -1931,13 +1856,21 @@ strhandle(void)
case ']': /* OSC -- Operating System Command */ case ']': /* OSC -- Operating System Command */
switch (par) { switch (par) {
case 0: case 0:
if (narg > 1) {
xsettitle(strescseq.args[1]);
xseticontitle(strescseq.args[1]);
}
return;
case 1: case 1:
if (narg > 1)
xseticontitle(strescseq.args[1]);
return;
case 2: case 2:
if (narg > 1) if (narg > 1)
xsettitle(strescseq.args[1]); xsettitle(strescseq.args[1]);
return; return;
case 52: case 52:
if (narg > 2) { if (narg > 2 && allowwindowops) {
dec = base64dec(strescseq.args[2]); dec = base64dec(strescseq.args[2]);
if (dec) { if (dec) {
xsetsel(dec); xsetsel(dec);
@ -1948,23 +1881,12 @@ strhandle(void)
} }
return; return;
case 4: /* color set */ case 4: /* color set */
case 10: /* foreground set */ if (narg < 3)
case 11: /* background set */
case 12: /* cursor color */
if ((par == 4 && narg < 3) || narg < 2)
break; break;
p = strescseq.args[((par == 4) ? 2 : 1)]; p = strescseq.args[2];
/* FALLTHROUGH */ /* FALLTHROUGH */
case 104: /* color reset, here p = NULL */ case 104: /* color reset, here p = NULL */
if (par == 10)
j = defaultfg;
else if (par == 11)
j = defaultbg;
else if (par == 12)
j = defaultcs;
else
j = (narg > 1) ? atoi(strescseq.args[1]) : -1; j = (narg > 1) ? atoi(strescseq.args[1]) : -1;
if (xsetcolorname(j, p)) { if (xsetcolorname(j, p)) {
if (par == 104 && narg <= 1) if (par == 104 && narg <= 1)
return; /* color reset without parameter */ return; /* color reset without parameter */
@ -1975,8 +1897,6 @@ strhandle(void)
* TODO if defaultbg color is changed, borders * TODO if defaultbg color is changed, borders
* are dirty * are dirty
*/ */
if (j == defaultbg)
xclearwin();
redraw(); redraw();
} }
return; return;
@ -1986,7 +1906,6 @@ strhandle(void)
xsettitle(strescseq.args[0]); xsettitle(strescseq.args[0]);
return; return;
case 'P': /* DCS -- Device Control String */ case 'P': /* DCS -- Device Control String */
term.mode |= ESC_DCS;
case '_': /* APC -- Application Program Command */ case '_': /* APC -- Application Program Command */
case '^': /* PM -- Privacy Message */ case '^': /* PM -- Privacy Message */
return; return;
@ -2018,56 +1937,6 @@ strparse(void)
} }
} }
void
strdump(void)
{
int i;
uint c;
fprintf(stderr, "ESC%c", strescseq.type);
for (i = 0; i < strescseq.len; i++) {
c = strescseq.buf[i] & 0xff;
if (c == '\0') {
putc('\n', stderr);
return;
} else if (isprint(c)) {
putc(c, stderr);
} else if (c == '\n') {
fprintf(stderr, "(\\n)");
} else if (c == '\r') {
fprintf(stderr, "(\\r)");
} else if (c == 0x1b) {
fprintf(stderr, "(\\e)");
} else {
fprintf(stderr, "(%02x)", c);
}
}
fprintf(stderr, "ESC\\\n");
}
void
strreset(void)
{
memset(&strescseq, 0, sizeof(strescseq));
}
void
sendbreak(const Arg *arg)
{
if (tcsendbreak(cmdfd, 0))
perror("Error sending break");
}
void
tprinter(char *s, size_t len)
{
if (iofd != -1 && xwrite(iofd, s, len) < 0) {
perror("Error writing to output file");
close(iofd);
iofd = -1;
}
}
void void
externalpipe(const Arg *arg) externalpipe(const Arg *arg)
{ {
@ -2099,19 +1968,16 @@ externalpipe(const Arg *arg)
/* ignore sigpipe for now, in case child exists early */ /* ignore sigpipe for now, in case child exists early */
oldsigpipe = signal(SIGPIPE, SIG_IGN); oldsigpipe = signal(SIGPIPE, SIG_IGN);
newline = 0; newline = 0;
/* modify externalpipe patch to pipe history too */ for (n = 0; n < term.row; n++) {
for (n = 0; n <= HISTSIZE + 2; n++) { bp = term.line[n];
bp = TLINE_HIST(n); lastpos = MIN(tlinelen(n) + 1, term.col) - 1;
lastpos = MIN(tlinehistlen(n) +1, term.col) - 1;
if (lastpos < 0) if (lastpos < 0)
break; break;
if (lastpos == 0)
continue;
end = &bp[lastpos + 1]; end = &bp[lastpos + 1];
for (; bp < end; ++bp) for (; bp < end; ++bp)
if (xwrite(to[1], buf, utf8encode(bp->u, buf)) < 0) if (xwrite(to[1], buf, utf8encode(bp->u, buf)) < 0)
break; break;
if ((newline = TLINE_HIST(n)[lastpos].mode & ATTR_WRAP)) if ((newline = term.line[n][lastpos].mode & ATTR_WRAP))
continue; continue;
if (xwrite(to[1], "\n", 1) < 0) if (xwrite(to[1], "\n", 1) < 0)
break; break;
@ -2125,25 +1991,56 @@ externalpipe(const Arg *arg)
} }
void void
iso14755(const Arg *arg) strdump(void)
{ {
FILE *p; size_t i;
char *us, *e, codepoint[9], uc[UTF_SIZ]; uint c;
unsigned long utf32;
if (!(p = popen(ISO14755CMD, "r"))) fprintf(stderr, "ESC%c", strescseq.type);
for (i = 0; i < strescseq.len; i++) {
c = strescseq.buf[i] & 0xff;
if (c == '\0') {
putc('\n', stderr);
return; return;
} else if (isprint(c)) {
putc(c, stderr);
} else if (c == '\n') {
fprintf(stderr, "(\\n)");
} else if (c == '\r') {
fprintf(stderr, "(\\r)");
} else if (c == 0x1b) {
fprintf(stderr, "(\\e)");
} else {
fprintf(stderr, "(%02x)", c);
}
}
fprintf(stderr, "ESC\\\n");
}
us = fgets(codepoint, sizeof(codepoint), p); void
pclose(p); strreset(void)
{
strescseq = (STREscape){
.buf = xrealloc(strescseq.buf, STR_BUF_SIZ),
.siz = STR_BUF_SIZ,
};
}
if (!us || *us == '\0' || *us == '-' || strlen(us) > 7) void
return; sendbreak(const Arg *arg)
if ((utf32 = strtoul(us, &e, 16)) == ULONG_MAX || {
(*e != '\n' && *e != '\0')) if (tcsendbreak(cmdfd, 0))
return; perror("Error sending break");
}
ttywrite(uc, utf8encode(utf32, uc), 1); void
tprinter(char *s, size_t len)
{
if (iofd != -1 && xwrite(iofd, s, len) < 0) {
perror("Error writing to output file");
close(iofd);
iofd = -1;
}
} }
void void
@ -2255,12 +2152,9 @@ tdectest(char c)
void void
tstrsequence(uchar c) tstrsequence(uchar c)
{ {
strreset();
switch (c) { switch (c) {
case 0x90: /* DCS -- Device Control String */ case 0x90: /* DCS -- Device Control String */
c = 'P'; c = 'P';
term.esc |= ESC_DCS;
break; break;
case 0x9f: /* APC -- Application Program Command */ case 0x9f: /* APC -- Application Program Command */
c = '_'; c = '_';
@ -2272,6 +2166,7 @@ tstrsequence(uchar c)
c = ']'; c = ']';
break; break;
} }
strreset();
strescseq.type = c; strescseq.type = c;
term.esc |= ESC_STR; term.esc |= ESC_STR;
} }
@ -2314,6 +2209,7 @@ tcontrolcode(uchar ascii)
return; return;
case '\032': /* SUB */ case '\032': /* SUB */
tsetchar('?', &term.c.attr, term.c.x, term.c.y); tsetchar('?', &term.c.attr, term.c.x, term.c.y);
/* FALLTHROUGH */
case '\030': /* CAN */ case '\030': /* CAN */
csireset(); csireset();
break; break;
@ -2409,7 +2305,7 @@ eschandle(uchar ascii)
return 0; return 0;
case 'D': /* IND -- Linefeed */ case 'D': /* IND -- Linefeed */
if (term.c.y == term.bot) { if (term.c.y == term.bot) {
tscrollup(term.top, 1, 1); tscrollup(term.top, 1);
} else { } else {
tmoveto(term.c.x, term.c.y+1); tmoveto(term.c.x, term.c.y+1);
} }
@ -2422,7 +2318,7 @@ eschandle(uchar ascii)
break; break;
case 'M': /* RI -- Reverse index */ case 'M': /* RI -- Reverse index */
if (term.c.y == term.top) { if (term.c.y == term.top) {
tscrolldown(term.top, 1, 1); tscrolldown(term.top, 1);
} else { } else {
tmoveto(term.c.x, term.c.y-1); tmoveto(term.c.x, term.c.y-1);
} }
@ -2468,16 +2364,14 @@ tputc(Rune u)
Glyph *gp; Glyph *gp;
control = ISCONTROL(u); control = ISCONTROL(u);
if (!IS_SET(MODE_UTF8) && !IS_SET(MODE_SIXEL)) { if (u < 127 || !IS_SET(MODE_UTF8)) {
c[0] = u; c[0] = u;
width = len = 1; width = len = 1;
} else { } else {
len = utf8encode(u, c); len = utf8encode(u, c);
if (!control && (width = wcwidth(u)) == -1) { if (!control && (width = wcwidth(u)) == -1)
memcpy(c, "\357\277\275", 4); /* UTF_INVALID */
width = 1; width = 1;
} }
}
if (IS_SET(MODE_PRINT)) if (IS_SET(MODE_PRINT))
tprinter(c, len); tprinter(c, len);
@ -2491,24 +2385,12 @@ tputc(Rune u)
if (term.esc & ESC_STR) { if (term.esc & ESC_STR) {
if (u == '\a' || u == 030 || u == 032 || u == 033 || if (u == '\a' || u == 030 || u == 032 || u == 033 ||
ISCONTROLC1(u)) { ISCONTROLC1(u)) {
term.esc &= ~(ESC_START|ESC_STR|ESC_DCS); term.esc &= ~(ESC_START|ESC_STR);
if (IS_SET(MODE_SIXEL)) {
/* TODO: render sixel */;
term.mode &= ~MODE_SIXEL;
return;
}
term.esc |= ESC_STR_END; term.esc |= ESC_STR_END;
goto check_control_code; goto check_control_code;
} }
if (IS_SET(MODE_SIXEL)) { if (strescseq.len+len >= strescseq.siz) {
/* TODO: implement sixel mode */
return;
}
if (term.esc&ESC_DCS && strescseq.len == 0 && u == 'q')
term.mode |= MODE_SIXEL;
if (strescseq.len+len >= sizeof(strescseq.buf)-1) {
/* /*
* Here is a bug in terminals. If the user never sends * Here is a bug in terminals. If the user never sends
* some code to stop the str or esc command, then st * some code to stop the str or esc command, then st
@ -2522,7 +2404,10 @@ tputc(Rune u)
* term.esc = 0; * term.esc = 0;
* strhandle(); * strhandle();
*/ */
if (strescseq.siz > (SIZE_MAX - UTF_SIZ) / 2)
return; return;
strescseq.siz *= 2;
strescseq.buf = xrealloc(strescseq.buf, strescseq.siz);
} }
memmove(&strescseq.buf[strescseq.len], c, len); memmove(&strescseq.buf[strescseq.len], c, len);
@ -2541,6 +2426,8 @@ check_control_code:
/* /*
* control codes are not shown ever * control codes are not shown ever
*/ */
if (!term.esc)
term.lastc = 0;
return; return;
} else if (term.esc & ESC_START) { } else if (term.esc & ESC_START) {
if (term.esc & ESC_CSI) { if (term.esc & ESC_CSI) {
@ -2571,7 +2458,7 @@ check_control_code:
*/ */
return; return;
} }
if (sel.ob.x != -1 && BETWEEN(term.c.y, sel.ob.y, sel.oe.y)) if (selected(term.c.x, term.c.y))
selclear(); selclear();
gp = &term.line[term.c.y][term.c.x]; gp = &term.line[term.c.y][term.c.x];
@ -2590,6 +2477,7 @@ check_control_code:
} }
tsetchar(u, &term.c.attr, term.c.x, term.c.y); tsetchar(u, &term.c.attr, term.c.x, term.c.y);
term.lastc = u;
if (width == 2) { if (width == 2) {
gp->mode |= ATTR_WIDE; gp->mode |= ATTR_WIDE;
@ -2613,7 +2501,7 @@ twrite(const char *buf, int buflen, int show_ctrl)
int n; int n;
for (n = 0; n < buflen; n += charsize) { for (n = 0; n < buflen; n += charsize) {
if (IS_SET(MODE_UTF8) && !IS_SET(MODE_SIXEL)) { if (IS_SET(MODE_UTF8)) {
/* process a complete utf8 char */ /* process a complete utf8 char */
charsize = utf8decode(buf + n, &u, buflen - n); charsize = utf8decode(buf + n, &u, buflen - n);
if (charsize == 0) if (charsize == 0)
@ -2640,7 +2528,7 @@ twrite(const char *buf, int buflen, int show_ctrl)
void void
tresize(int col, int row) tresize(int col, int row)
{ {
int i, j; int i;
int minrow = MIN(row, term.row); int minrow = MIN(row, term.row);
int mincol = MIN(col, term.col); int mincol = MIN(col, term.col);
int *bp; int *bp;
@ -2677,14 +2565,6 @@ tresize(int col, int row)
term.dirty = xrealloc(term.dirty, row * sizeof(*term.dirty)); term.dirty = xrealloc(term.dirty, row * sizeof(*term.dirty));
term.tabs = xrealloc(term.tabs, col * sizeof(*term.tabs)); term.tabs = xrealloc(term.tabs, col * sizeof(*term.tabs));
for (i = 0; i < HISTSIZE; i++) {
term.hist[i] = xrealloc(term.hist[i], col * sizeof(Glyph));
for (j = mincol; j < col; j++) {
term.hist[i][j] = term.c.attr;
term.hist[i][j].u = ' ';
}
}
/* resize each row to new width, zero-pad if needed */ /* resize each row to new width, zero-pad if needed */
for (i = 0; i < minrow; i++) { for (i = 0; i < minrow; i++) {
term.line[i] = xrealloc(term.line[i], col * sizeof(Glyph)); term.line[i] = xrealloc(term.line[i], col * sizeof(Glyph));
@ -2737,19 +2617,20 @@ void
drawregion(int x1, int y1, int x2, int y2) drawregion(int x1, int y1, int x2, int y2)
{ {
int y; int y;
for (y = y1; y < y2; y++) { for (y = y1; y < y2; y++) {
if (!term.dirty[y]) if (!term.dirty[y])
continue; continue;
term.dirty[y] = 0; term.dirty[y] = 0;
xdrawline(TLINE(y), x1, y, x2); xdrawline(term.line[y], x1, y, x2);
} }
} }
void void
draw(void) draw(void)
{ {
int cx = term.c.x; int cx = term.c.x, ocx = term.ocx, ocy = term.ocy;
if (!xstartdraw()) if (!xstartdraw())
return; return;
@ -2763,19 +2644,14 @@ draw(void)
cx--; cx--;
drawregion(0, 0, term.col, term.row); drawregion(0, 0, term.col, term.row);
if (term.scr == 0)
xdrawcursor(cx, term.c.y, term.line[term.c.y][cx], xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
term.ocx, term.ocy, term.line[term.ocy][term.ocx], term.ocx, term.ocy, term.line[term.ocy][term.ocx],
term.line[term.ocy], term.col); term.line[term.ocy], term.col);
term.ocx = cx, term.ocy = term.c.y; term.ocx = cx;
term.ocy = term.c.y;
xfinishdraw(); xfinishdraw();
if (ocx != term.ocx || ocy != term.ocy)
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
if (ximspot_update_interval && TIMEDIFF(now, term.last_ximspot_update) > ximspot_update_interval) {
xximspot(term.ocx, term.ocy); xximspot(term.ocx, term.ocy);
term.last_ximspot_update = now;
}
} }
void void

25
st.h
View File

@ -39,12 +39,6 @@ enum glyph_attribute {
ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT, ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
}; };
enum drawing_mode {
DRAW_NONE = 0,
DRAW_BG = 1 << 0,
DRAW_FG = 1 << 1,
};
enum selection_mode { enum selection_mode {
SEL_IDLE = 0, SEL_IDLE = 0,
SEL_EMPTY = 1, SEL_EMPTY = 1,
@ -83,30 +77,20 @@ typedef union {
uint ui; uint ui;
float f; float f;
const void *v; const void *v;
const char *s;
} Arg; } Arg;
typedef struct {
uint b;
uint mask;
void (*func)(const Arg *);
const Arg arg;
} MouseKey;
void die(const char *, ...); void die(const char *, ...);
void redraw(void); void redraw(void);
void draw(void); void draw(void);
void externalpipe(const Arg *); void externalpipe(const Arg *);
void iso14755(const Arg *);
void kscrolldown(const Arg *);
void kscrollup(const Arg *);
void printscreen(const Arg *); void printscreen(const Arg *);
void printsel(const Arg *); void printsel(const Arg *);
void sendbreak(const Arg *); void sendbreak(const Arg *);
void toggleprinter(const Arg *); void toggleprinter(const Arg *);
int tattrset(int); int tattrset(int);
int tisaltscr(void);
void tnew(int, int); void tnew(int, int);
void tresize(int, int); void tresize(int, int);
void tsetdirtattr(int); void tsetdirtattr(int);
@ -141,16 +125,15 @@ void drawboxes(int, int, int, int, XftColor *, XftColor *, const XftGlyphFontSpe
/* config.h globals */ /* config.h globals */
extern char *utmp; extern char *utmp;
extern char *scroll;
extern char *stty_args; extern char *stty_args;
extern char *vtiden; extern char *vtiden;
extern wchar_t *worddelimiters; extern wchar_t *worddelimiters;
extern int allowaltscreen; extern int allowaltscreen;
extern int allowwindowops;
extern char *termname; extern char *termname;
extern unsigned int tabspaces; extern unsigned int tabspaces;
extern unsigned int defaultfg; extern unsigned int defaultfg;
extern unsigned int defaultbg; extern unsigned int defaultbg;
extern unsigned int defaultcs;
extern const int boxdraw, boxdraw_bold, boxdraw_braille;
extern float alpha; extern float alpha;
extern MouseKey mkeys[]; extern const int boxdraw, boxdraw_bold, boxdraw_braille;
extern int ximspot_update_interval;

33
st.info
View File

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

2
win.h
View File

@ -30,6 +30,7 @@ void xdrawline(Line, int, int, int);
void xfinishdraw(void); void xfinishdraw(void);
void xloadcols(void); void xloadcols(void);
int xsetcolorname(int, const char *); int xsetcolorname(int, const char *);
void xseticontitle(char *);
void xsettitle(char *); void xsettitle(char *);
int xsetcursor(int); int xsetcursor(int);
void xsetmode(int, unsigned int); void xsetmode(int, unsigned int);
@ -37,4 +38,3 @@ void xsetpointermotion(int);
void xsetsel(char *); void xsetsel(char *);
int xstartdraw(void); int xstartdraw(void);
void xximspot(int, int); void xximspot(int, int);
void xclearwin(void);

325
x.c
View File

@ -16,7 +16,7 @@
#include <X11/XKBlib.h> #include <X11/XKBlib.h>
#include <X11/Xresource.h> #include <X11/Xresource.h>
static char *argv0; char *argv0;
#include "arg.h" #include "arg.h"
#include "st.h" #include "st.h"
#include "win.h" #include "win.h"
@ -31,9 +31,11 @@ typedef struct {
} Shortcut; } Shortcut;
typedef struct { typedef struct {
uint b; uint mod;
uint mask; uint button;
char *s; void (*func)(const Arg *);
const Arg arg;
uint release;
} MouseShortcut; } MouseShortcut;
typedef struct { typedef struct {
@ -72,6 +74,7 @@ static void changealpha(const Arg *);
static void zoom(const Arg *); static void zoom(const Arg *);
static void zoomabs(const Arg *); static void zoomabs(const Arg *);
static void zoomreset(const Arg *); static void zoomreset(const Arg *);
static void ttysend(const Arg *);
/* config.h for applying patches and the configuration. */ /* config.h for applying patches and the configuration. */
#include "config.h" #include "config.h"
@ -94,10 +97,8 @@ typedef XftGlyphFontSpec GlyphFontSpec;
typedef struct { typedef struct {
int tw, th; /* tty width and height */ int tw, th; /* tty width and height */
int w, h; /* window width and height */ int w, h; /* window width and height */
int hborderpx, vborderpx;
int ch; /* char height */ int ch; /* char height */
int cw; /* char width */ int cw; /* char width */
int cyo; /* char y offset */
int mode; /* window state/mode flags */ int mode; /* window state/mode flags */
int cursor; /* cursor style */ int cursor; /* cursor style */
} TermWindow; } TermWindow;
@ -108,9 +109,13 @@ typedef struct {
Window win; Window win;
Drawable buf; Drawable buf;
GlyphFontSpec *specbuf; /* font spec buffer used for rendering */ GlyphFontSpec *specbuf; /* font spec buffer used for rendering */
Atom xembed, wmdeletewin, netwmname, netwmpid; Atom xembed, wmdeletewin, netwmname, netwmiconname, netwmpid;
struct {
XIM xim; XIM xim;
XIC xic; XIC xic;
XPoint spot;
XVaNestedList spotlist;
} ime;
Draw draw; Draw draw;
Visual *vis; Visual *vis;
XSetWindowAttributes attrs; XSetWindowAttributes attrs;
@ -154,13 +159,14 @@ typedef struct {
static inline ushort sixd_to_16bit(int); static inline ushort sixd_to_16bit(int);
static int xmakeglyphfontspecs(XftGlyphFontSpec *, const Glyph *, int, int, int); static int xmakeglyphfontspecs(XftGlyphFontSpec *, const Glyph *, int, int, int);
static void xdrawglyphfontspecs(const XftGlyphFontSpec *, Glyph, int, int, int, int); static void xdrawglyphfontspecs(const XftGlyphFontSpec *, Glyph, int, int, int);
static void xdrawglyph(Glyph, int, int); static void xdrawglyph(Glyph, int, int);
static void xclear(int, int, int, int); static void xclear(int, int, int, int);
static int xgeommasktogravity(int); static int xgeommasktogravity(int);
static void ximopen(Display *); static int ximopen(Display *);
static void ximinstantiate(Display *, XPointer, XPointer); static void ximinstantiate(Display *, XPointer, XPointer);
static void ximdestroy(XIM, XPointer, XPointer); static void ximdestroy(XIM, XPointer, XPointer);
static int xicdestroy(XIC, XPointer, XPointer);
static void xinit(int, int); static void xinit(int, int);
static void cresize(int, int); static void cresize(int, int);
static void xresize(int, int); static void xresize(int, int);
@ -184,6 +190,8 @@ static void kpress(XEvent *);
static void cmessage(XEvent *); static void cmessage(XEvent *);
static void resize(XEvent *); static void resize(XEvent *);
static void focus(XEvent *); static void focus(XEvent *);
static uint buttonmask(uint);
static int mouseaction(XEvent *, uint);
static void brelease(XEvent *); static void brelease(XEvent *);
static void bpress(XEvent *); static void bpress(XEvent *);
static void bmotion(XEvent *); static void bmotion(XEvent *);
@ -349,10 +357,16 @@ zoomreset(const Arg *arg)
} }
} }
void
ttysend(const Arg *arg)
{
ttywrite(arg->s, strlen(arg->s), 1);
}
int int
evcol(XEvent *e) evcol(XEvent *e)
{ {
int x = e->xbutton.x - win.hborderpx; int x = e->xbutton.x - borderpx;
LIMIT(x, 0, win.tw - 1); LIMIT(x, 0, win.tw - 1);
return x / win.cw; return x / win.cw;
} }
@ -360,7 +374,7 @@ evcol(XEvent *e)
int int
evrow(XEvent *e) evrow(XEvent *e)
{ {
int y = e->xbutton.y - win.vborderpx; int y = e->xbutton.y - borderpx;
LIMIT(y, 0, win.th - 1); LIMIT(y, 0, win.th - 1);
return y / win.ch; return y / win.ch;
} }
@ -369,7 +383,7 @@ void
mousesel(XEvent *e, int done) mousesel(XEvent *e, int done)
{ {
int type, seltype = SEL_REGULAR; int type, seltype = SEL_REGULAR;
uint state = e->xbutton.state & ~(Button1Mask | forceselmod); uint state = e->xbutton.state & ~(Button1Mask | forcemousemod);
for (type = 1; type < LEN(selmasks); ++type) { for (type = 1; type < LEN(selmasks); ++type) {
if (match(selmasks[type], state)) { if (match(selmasks[type], state)) {
@ -445,36 +459,51 @@ mousereport(XEvent *e)
ttywrite(buf, len, 0); ttywrite(buf, len, 0);
} }
uint
buttonmask(uint button)
{
return button == Button1 ? Button1Mask
: button == Button2 ? Button2Mask
: button == Button3 ? Button3Mask
: button == Button4 ? Button4Mask
: button == Button5 ? Button5Mask
: 0;
}
int
mouseaction(XEvent *e, uint release)
{
MouseShortcut *ms;
/* ignore Button<N>mask for Button<N> - it's set on release */
uint state = e->xbutton.state & ~buttonmask(e->xbutton.button);
for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) {
if (ms->release == release &&
ms->button == e->xbutton.button &&
(match(ms->mod, state) || /* exact or forced */
match(ms->mod, state & ~forcemousemod))) {
ms->func(&(ms->arg));
return 1;
}
}
return 0;
}
void void
bpress(XEvent *e) bpress(XEvent *e)
{ {
struct timespec now; struct timespec now;
MouseShortcut *ms;
MouseKey *mk;
int snap; int snap;
if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) { if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forcemousemod)) {
mousereport(e); mousereport(e);
return; return;
} }
if (tisaltscr()) { if (mouseaction(e, 0))
for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) {
if (e->xbutton.button == ms->b
&& match(ms->mask, e->xbutton.state)) {
ttywrite(ms->s, strlen(ms->s), 1);
return; return;
}
}
}
for (mk = mkeys; mk < mkeys + LEN(mkeys); mk++) {
if (e->xbutton.button == mk->b
&& match(mk->mask, e->xbutton.state)) {
mk->func(&mk->arg);
return;
}
}
if (e->xbutton.button == Button1) { if (e->xbutton.button == Button1) {
/* /*
@ -690,21 +719,21 @@ xsetsel(char *str)
void void
brelease(XEvent *e) brelease(XEvent *e)
{ {
if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) { if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forcemousemod)) {
mousereport(e); mousereport(e);
return; return;
} }
if (e->xbutton.button == Button2) if (mouseaction(e, 1))
selpaste(NULL); return;
else if (e->xbutton.button == Button1) if (e->xbutton.button == Button1)
mousesel(e, 1); mousesel(e, 1);
} }
void void
bmotion(XEvent *e) bmotion(XEvent *e)
{ {
if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) { if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forcemousemod)) {
mousereport(e); mousereport(e);
return; return;
} }
@ -727,9 +756,6 @@ cresize(int width, int height)
col = MAX(1, col); col = MAX(1, col);
row = MAX(1, row); row = MAX(1, row);
win.hborderpx = (win.w - col * win.cw) / 2;
win.vborderpx = (win.h - row * win.ch) / 2;
tresize(col, row); tresize(col, row);
xresize(col, row); xresize(col, row);
ttyresize(win.tw, win.th); ttyresize(win.tw, win.th);
@ -808,12 +834,6 @@ xloadcols(void)
if (opt_alpha) if (opt_alpha)
alpha = strtof(opt_alpha, NULL); alpha = strtof(opt_alpha, NULL);
dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * alpha); dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * alpha);
dc.col[defaultbg].color.red =
((unsigned short)(dc.col[defaultbg].color.red * alpha)) & 0xff00;
dc.col[defaultbg].color.green =
((unsigned short)(dc.col[defaultbg].color.green * alpha)) & 0xff00;
dc.col[defaultbg].color.blue =
((unsigned short)(dc.col[defaultbg].color.blue * alpha)) & 0xff00;
dc.col[defaultbg].pixel &= 0x00FFFFFF; dc.col[defaultbg].pixel &= 0x00FFFFFF;
dc.col[defaultbg].pixel |= (unsigned char)(0xff * alpha) << 24; dc.col[defaultbg].pixel |= (unsigned char)(0xff * alpha) << 24;
loaded = 1; loaded = 1;
@ -832,8 +852,6 @@ xsetcolorname(int x, const char *name)
XftColorFree(xw.dpy, xw.vis, xw.cmap, &dc.col[x]); XftColorFree(xw.dpy, xw.vis, xw.cmap, &dc.col[x]);
dc.col[x] = ncolor; dc.col[x] = ncolor;
if (x == defaultbg)
dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * alpha);
return 0; return 0;
} }
@ -849,13 +867,6 @@ xclear(int x1, int y1, int x2, int y2)
x1, y1, x2-x1, y2-y1); x1, y1, x2-x1, y2-y1);
} }
void
xclearwin(void)
{
xclear(0, 0, win.w, win.h);
}
void void
xhints(void) xhints(void)
{ {
@ -869,8 +880,8 @@ xhints(void)
sizeh->flags = PSize | PResizeInc | PBaseSize | PMinSize; sizeh->flags = PSize | PResizeInc | PBaseSize | PMinSize;
sizeh->height = win.h; sizeh->height = win.h;
sizeh->width = win.w; sizeh->width = win.w;
sizeh->height_inc = 1; sizeh->height_inc = win.ch;
sizeh->width_inc = 1; sizeh->width_inc = win.cw;
sizeh->base_height = 2 * borderpx; sizeh->base_height = 2 * borderpx;
sizeh->base_width = 2 * borderpx; sizeh->base_width = 2 * borderpx;
sizeh->min_height = win.ch + 2 * borderpx; sizeh->min_height = win.ch + 2 * borderpx;
@ -1031,7 +1042,6 @@ xloadfonts(char *fontstr, double fontsize)
/* Setting character width and height. */ /* Setting character width and height. */
win.cw = ceilf(dc.font.width * cwscale); win.cw = ceilf(dc.font.width * cwscale);
win.ch = ceilf(dc.font.height * chscale); win.ch = ceilf(dc.font.height * chscale);
win.cyo = ceilf(dc.font.height * (chscale - 1) / 2);
FcPatternDel(pattern, FC_SLANT); FcPatternDel(pattern, FC_SLANT);
FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC); FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
@ -1171,31 +1181,40 @@ xunloadfonts(void)
xunloadfont(&dc.ibfont); xunloadfont(&dc.ibfont);
} }
void int
ximopen(Display *dpy) ximopen(Display *dpy)
{ {
XIMCallback destroy = { .client_data = NULL, .callback = ximdestroy }; XIMCallback imdestroy = { .client_data = NULL, .callback = ximdestroy };
XICCallback icdestroy = { .client_data = NULL, .callback = xicdestroy };
if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) { xw.ime.xim = XOpenIM(xw.dpy, NULL, NULL, NULL);
XSetLocaleModifiers("@im=local"); if (xw.ime.xim == NULL)
if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) { return 0;
XSetLocaleModifiers("@im=");
if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) if (XSetIMValues(xw.ime.xim, XNDestroyCallback, &imdestroy, NULL))
die("XOpenIM failed. Could not open input device.\n"); fprintf(stderr, "XSetIMValues: "
"Could not set XNDestroyCallback.\n");
xw.ime.spotlist = XVaCreateNestedList(0, XNSpotLocation, &xw.ime.spot,
NULL);
if (xw.ime.xic == NULL) {
xw.ime.xic = XCreateIC(xw.ime.xim, XNInputStyle,
XIMPreeditNothing | XIMStatusNothing,
XNClientWindow, xw.win,
XNDestroyCallback, &icdestroy,
NULL);
} }
} if (xw.ime.xic == NULL)
if (XSetIMValues(xw.xim, XNDestroyCallback, &destroy, NULL) != NULL) fprintf(stderr, "XCreateIC: Could not create input context.\n");
die("XSetIMValues failed. Could not set input method value.\n");
xw.xic = XCreateIC(xw.xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, return 1;
XNClientWindow, xw.win, XNFocusWindow, xw.win, NULL);
if (xw.xic == NULL)
die("XCreateIC failed. Could not obtain input method.\n");
} }
void void
ximinstantiate(Display *dpy, XPointer client, XPointer call) ximinstantiate(Display *dpy, XPointer client, XPointer call)
{ {
ximopen(dpy); if (ximopen(dpy))
XUnregisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL, XUnregisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
ximinstantiate, NULL); ximinstantiate, NULL);
} }
@ -1203,9 +1222,17 @@ ximinstantiate(Display *dpy, XPointer client, XPointer call)
void void
ximdestroy(XIM xim, XPointer client, XPointer call) ximdestroy(XIM xim, XPointer client, XPointer call)
{ {
xw.xim = NULL; xw.ime.xim = NULL;
XRegisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL, XRegisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
ximinstantiate, NULL); ximinstantiate, NULL);
XFree(xw.ime.spotlist);
}
int
xicdestroy(XIC xim, XPointer client, XPointer call)
{
xw.ime.xic = NULL;
return 1;
} }
void void
@ -1247,8 +1274,8 @@ xinit(int cols, int rows)
xloadcols(); xloadcols();
/* adjust fixed window geometry */ /* adjust fixed window geometry */
win.w = 2 * win.hborderpx + cols * win.cw; win.w = 2 * borderpx + cols * win.cw;
win.h = 2 * win.vborderpx + rows * win.ch; win.h = 2 * borderpx + rows * win.ch;
if (xw.gm & XNegative) if (xw.gm & XNegative)
xw.l += DisplayWidth(xw.dpy, xw.scr) - win.w - 2; xw.l += DisplayWidth(xw.dpy, xw.scr) - win.w - 2;
if (xw.gm & YNegative) if (xw.gm & YNegative)
@ -1282,7 +1309,10 @@ xinit(int cols, int rows)
xw.draw = XftDrawCreate(xw.dpy, xw.buf, xw.vis, xw.cmap); xw.draw = XftDrawCreate(xw.dpy, xw.buf, xw.vis, xw.cmap);
/* input methods */ /* input methods */
ximopen(xw.dpy); if (!ximopen(xw.dpy)) {
XRegisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
ximinstantiate, NULL);
}
/* white cursor, black outline */ /* white cursor, black outline */
cursor = XCreateFontCursor(xw.dpy, mouseshape); cursor = XCreateFontCursor(xw.dpy, mouseshape);
@ -1305,6 +1335,7 @@ xinit(int cols, int rows)
xw.xembed = XInternAtom(xw.dpy, "_XEMBED", False); xw.xembed = XInternAtom(xw.dpy, "_XEMBED", False);
xw.wmdeletewin = XInternAtom(xw.dpy, "WM_DELETE_WINDOW", False); xw.wmdeletewin = XInternAtom(xw.dpy, "WM_DELETE_WINDOW", False);
xw.netwmname = XInternAtom(xw.dpy, "_NET_WM_NAME", False); xw.netwmname = XInternAtom(xw.dpy, "_NET_WM_NAME", False);
xw.netwmiconname = XInternAtom(xw.dpy, "_NET_WM_ICON_NAME", False);
XSetWMProtocols(xw.dpy, xw.win, &xw.wmdeletewin, 1); XSetWMProtocols(xw.dpy, xw.win, &xw.wmdeletewin, 1);
xw.netwmpid = XInternAtom(xw.dpy, "_NET_WM_PID", False); xw.netwmpid = XInternAtom(xw.dpy, "_NET_WM_PID", False);
@ -1313,8 +1344,8 @@ xinit(int cols, int rows)
win.mode = MODE_NUMLOCK; win.mode = MODE_NUMLOCK;
resettitle(); resettitle();
XMapWindow(xw.dpy, xw.win);
xhints(); xhints();
XMapWindow(xw.dpy, xw.win);
XSync(xw.dpy, False); XSync(xw.dpy, False);
clock_gettime(CLOCK_MONOTONIC, &xsel.tclick1); clock_gettime(CLOCK_MONOTONIC, &xsel.tclick1);
@ -1331,7 +1362,7 @@ xinit(int cols, int rows)
int int
xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x, int y) xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x, int y)
{ {
float winx = win.hborderpx + x * win.cw, winy = win.vborderpx + y * win.ch, xp, yp; float winx = borderpx + x * win.cw, winy = borderpx + y * win.ch, xp, yp;
ushort mode, prevmode = USHRT_MAX; ushort mode, prevmode = USHRT_MAX;
Font *font = &dc.font; Font *font = &dc.font;
int frcflags = FRC_NORMAL; int frcflags = FRC_NORMAL;
@ -1344,7 +1375,7 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x
FcCharSet *fccharset; FcCharSet *fccharset;
int i, f, numspecs = 0; int i, f, numspecs = 0;
for (i = 0, xp = winx, yp = winy + font->ascent + win.cyo; i < len; ++i) { for (i = 0, xp = winx, yp = winy + font->ascent; i < len; ++i) {
/* Fetch rune and mode for current glyph. */ /* Fetch rune and mode for current glyph. */
rune = glyphs[i].u; rune = glyphs[i].u;
mode = glyphs[i].mode; mode = glyphs[i].mode;
@ -1369,7 +1400,7 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x
font = &dc.bfont; font = &dc.bfont;
frcflags = FRC_BOLD; frcflags = FRC_BOLD;
} }
yp = winy + font->ascent + win.cyo; yp = winy + font->ascent;
} }
if (mode & ATTR_BOXDRAW) { if (mode & ATTR_BOXDRAW) {
@ -1469,13 +1500,14 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x
} }
void void
xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, int y, int dmode) xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, int y)
{ {
int charlen = len * ((base.mode & ATTR_WIDE) ? 2 : 1); int charlen = len * ((base.mode & ATTR_WIDE) ? 2 : 1);
int winx = win.hborderpx + x * win.cw, winy = win.vborderpx + y * win.ch, int winx = borderpx + x * win.cw, winy = borderpx + y * win.ch,
width = charlen * win.cw; width = charlen * win.cw;
Color *fg, *bg, *temp, revfg, revbg, truefg, truebg; Color *fg, *bg, *temp, revfg, revbg, truefg, truebg;
XRenderColor colfg, colbg; XRenderColor colfg, colbg;
XRectangle r;
/* Fallback on color display for attributes not supported by the font */ /* Fallback on color display for attributes not supported by the font */
if (base.mode & ATTR_ITALIC && base.mode & ATTR_BOLD) { if (base.mode & ATTR_ITALIC && base.mode & ATTR_BOLD) {
@ -1508,6 +1540,10 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
bg = &dc.col[base.bg]; bg = &dc.col[base.bg];
} }
/* Change basic system colors [0-7] to bright system colors [8-15] */
if ((base.mode & ATTR_BOLD_FAINT) == ATTR_BOLD && BETWEEN(base.fg, 0, 7))
fg = &dc.col[base.fg + 8];
if (IS_SET(MODE_REVERSE)) { if (IS_SET(MODE_REVERSE)) {
if (fg == &dc.col[defaultfg]) { if (fg == &dc.col[defaultfg]) {
fg = &dc.col[defaultbg]; fg = &dc.col[defaultbg];
@ -1555,27 +1591,31 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
if (base.mode & ATTR_INVISIBLE) if (base.mode & ATTR_INVISIBLE)
fg = bg; fg = bg;
if (dmode & DRAW_BG) {
/* Intelligent cleaning up of the borders. */ /* Intelligent cleaning up of the borders. */
if (x == 0) { if (x == 0) {
xclear(0, (y == 0)? 0 : winy, win.vborderpx, xclear(0, (y == 0)? 0 : winy, borderpx,
winy + win.ch + winy + win.ch +
((winy + win.ch >= win.vborderpx + win.th)? win.h : 0)); ((winy + win.ch >= borderpx + win.th)? win.h : 0));
} }
if (winx + width >= win.hborderpx + win.tw) { if (winx + width >= borderpx + win.tw) {
xclear(winx + width, (y == 0)? 0 : winy, win.w, xclear(winx + width, (y == 0)? 0 : winy, win.w,
((winy + win.ch >= win.vborderpx + win.th)? win.h : (winy + win.ch))); ((winy + win.ch >= borderpx + win.th)? win.h : (winy + win.ch)));
} }
if (y == 0) if (y == 0)
xclear(winx, 0, winx + width, win.hborderpx); xclear(winx, 0, winx + width, borderpx);
if (winy + win.ch >= win.vborderpx + win.th) if (winy + win.ch >= borderpx + win.th)
xclear(winx, winy + win.ch, winx + width, win.h); xclear(winx, winy + win.ch, winx + width, win.h);
/* Fill the background */ /* Clean up the region we want to draw to. */
XftDrawRect(xw.draw, bg, winx, winy, width, win.ch); XftDrawRect(xw.draw, bg, winx, winy, width, win.ch);
}
if (dmode & DRAW_FG) { /* Set the clip region because Xft is sometimes dirty. */
r.x = 0;
r.y = 0;
r.height = win.ch;
r.width = width;
XftDrawSetClipRectangles(xw.draw, winx, winy, &r, 1);
if (base.mode & ATTR_BOXDRAW) { if (base.mode & ATTR_BOXDRAW) {
drawboxes(winx, winy, width / len, win.ch, fg, bg, specs, len); drawboxes(winx, winy, width / len, win.ch, fg, bg, specs, len);
} else { } else {
@ -1585,15 +1625,17 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
/* Render underline and strikethrough. */ /* Render underline and strikethrough. */
if (base.mode & ATTR_UNDERLINE) { if (base.mode & ATTR_UNDERLINE) {
XftDrawRect(xw.draw, fg, winx, winy + win.cyo + dc.font.ascent + 1, XftDrawRect(xw.draw, fg, winx, winy + dc.font.ascent + 1,
width, 1); width, 1);
} }
if (base.mode & ATTR_STRUCK) { if (base.mode & ATTR_STRUCK) {
XftDrawRect(xw.draw, fg, winx, winy + win.cyo + 2 * dc.font.ascent / 3, XftDrawRect(xw.draw, fg, winx, winy + 2 * dc.font.ascent / 3,
width, 1); width, 1);
} }
}
/* Reset clip to none. */
XftDrawSetClip(xw.draw, 0);
} }
void void
@ -1603,7 +1645,7 @@ xdrawglyph(Glyph g, int x, int y)
XftGlyphFontSpec spec; XftGlyphFontSpec spec;
numspecs = xmakeglyphfontspecs(&spec, &g, 1, x, y); numspecs = xmakeglyphfontspecs(&spec, &g, 1, x, y);
xdrawglyphfontspecs(&spec, g, numspecs, x, y, DRAW_BG | DRAW_FG); xdrawglyphfontspecs(&spec, g, numspecs, x, y);
} }
void void
@ -1651,8 +1693,9 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og, Line line, int le
/* draw the new one */ /* draw the new one */
if (IS_SET(MODE_FOCUSED)) { if (IS_SET(MODE_FOCUSED)) {
switch (win.cursor) { switch (win.cursor) {
case 7: /* st extension: snowman (U+2603) */ case 7: /* st extension */
g.u = 0x2603; g.u = 0x2603; /* snowman (U+2603) */
/* FALLTHROUGH */
case 0: /* Blinking Block */ case 0: /* Blinking Block */
case 1: /* Blinking Block (Default) */ case 1: /* Blinking Block (Default) */
case 2: /* Steady Block */ case 2: /* Steady Block */
@ -1661,35 +1704,35 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og, Line line, int le
case 3: /* Blinking Underline */ case 3: /* Blinking Underline */
case 4: /* Steady Underline */ case 4: /* Steady Underline */
XftDrawRect(xw.draw, &drawcol, XftDrawRect(xw.draw, &drawcol,
win.hborderpx + cx * win.cw, borderpx + cx * win.cw,
win.vborderpx + (cy + 1) * win.ch - \ borderpx + (cy + 1) * win.ch - \
cursorthickness, cursorthickness,
win.cw, cursorthickness); win.cw, cursorthickness);
break; break;
case 5: /* Blinking bar */ case 5: /* Blinking bar */
case 6: /* Steady bar */ case 6: /* Steady bar */
XftDrawRect(xw.draw, &drawcol, XftDrawRect(xw.draw, &drawcol,
win.hborderpx + cx * win.cw, borderpx + cx * win.cw,
win.vborderpx + cy * win.ch, borderpx + cy * win.ch,
cursorthickness, win.ch); cursorthickness, win.ch);
break; break;
} }
} else { } else {
XftDrawRect(xw.draw, &drawcol, XftDrawRect(xw.draw, &drawcol,
win.hborderpx + cx * win.cw, borderpx + cx * win.cw,
win.vborderpx + cy * win.ch, borderpx + cy * win.ch,
win.cw - 1, 1); win.cw - 1, 1);
XftDrawRect(xw.draw, &drawcol, XftDrawRect(xw.draw, &drawcol,
win.hborderpx + cx * win.cw, borderpx + cx * win.cw,
win.vborderpx + cy * win.ch, borderpx + cy * win.ch,
1, win.ch - 1); 1, win.ch - 1);
XftDrawRect(xw.draw, &drawcol, XftDrawRect(xw.draw, &drawcol,
win.hborderpx + (cx + 1) * win.cw - 1, borderpx + (cx + 1) * win.cw - 1,
win.vborderpx + cy * win.ch, borderpx + cy * win.ch,
1, win.ch - 1); 1, win.ch - 1);
XftDrawRect(xw.draw, &drawcol, XftDrawRect(xw.draw, &drawcol,
win.hborderpx + cx * win.cw, borderpx + cx * win.cw,
win.vborderpx + (cy + 1) * win.ch - 1, borderpx + (cy + 1) * win.ch - 1,
win.cw, 1); win.cw, 1);
} }
} }
@ -1703,6 +1746,19 @@ xsetenv(void)
setenv("WINDOWID", buf, 1); setenv("WINDOWID", buf, 1);
} }
void
xseticontitle(char *p)
{
XTextProperty prop;
DEFAULT(p, opt_title);
Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle,
&prop);
XSetWMIconName(xw.dpy, xw.win, &prop);
XSetTextProperty(xw.dpy, xw.win, &prop, xw.netwmiconname);
XFree(prop.value);
}
void void
xsettitle(char *p) xsettitle(char *p)
{ {
@ -1725,17 +1781,11 @@ xstartdraw(void)
void void
xdrawline(Line line, int x1, int y1, int x2) xdrawline(Line line, int x1, int y1, int x2)
{ {
int i, x, ox, numspecs, numspecs_cached; int i, x, ox, numspecs;
Glyph base, new; Glyph base, new;
XftGlyphFontSpec *specs; XftGlyphFontSpec *specs = xw.specbuf;
numspecs_cached = xmakeglyphfontspecs(xw.specbuf, &line[x1], x2 - x1, x1, y1); numspecs = xmakeglyphfontspecs(specs, &line[x1], x2 - x1, x1, y1);
/* Draw line in 2 passes: background and foreground. This way wide glyphs
won't get truncated (#223) */
for (int dmode = DRAW_BG; dmode <= DRAW_FG; dmode <<= 1) {
specs = xw.specbuf;
numspecs = numspecs_cached;
i = ox = 0; i = ox = 0;
for (x = x1; x < x2 && i < numspecs; x++) { for (x = x1; x < x2 && i < numspecs; x++) {
new = line[x]; new = line[x];
@ -1744,7 +1794,7 @@ xdrawline(Line line, int x1, int y1, int x2)
if (selected(x, y1)) if (selected(x, y1))
new.mode ^= ATTR_REVERSE; new.mode ^= ATTR_REVERSE;
if (i > 0 && ATTRCMP(base, new)) { if (i > 0 && ATTRCMP(base, new)) {
xdrawglyphfontspecs(specs, base, i, ox, y1, dmode); xdrawglyphfontspecs(specs, base, i, ox, y1);
specs += i; specs += i;
numspecs -= i; numspecs -= i;
i = 0; i = 0;
@ -1756,8 +1806,7 @@ xdrawline(Line line, int x1, int y1, int x2)
i++; i++;
} }
if (i > 0) if (i > 0)
xdrawglyphfontspecs(specs, base, i, ox, y1, dmode); xdrawglyphfontspecs(specs, base, i, ox, y1);
}
} }
void void
@ -1773,11 +1822,13 @@ xfinishdraw(void)
void void
xximspot(int x, int y) xximspot(int x, int y)
{ {
XPoint spot = { borderpx + x * win.cw, borderpx + (y + 1) * win.ch }; if (xw.ime.xic == NULL)
XVaNestedList attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL); return;
XSetICValues(xw.xic, XNPreeditAttributes, attr, NULL); xw.ime.spot.x = borderpx + x * win.cw;
XFree(attr); xw.ime.spot.y = borderpx + (y + 1) * win.ch;
XSetICValues(xw.ime.xic, XNPreeditAttributes, xw.ime.spotlist, NULL);
} }
void void
@ -1819,8 +1870,7 @@ xsetmode(int set, unsigned int flags)
int int
xsetcursor(int cursor) xsetcursor(int cursor)
{ {
DEFAULT(cursor, 1); if (!BETWEEN(cursor, 0, 7)) /* 7: st extension */
if (!BETWEEN(cursor, 0, 6))
return 1; return 1;
win.cursor = cursor; win.cursor = cursor;
return 0; return 0;
@ -1854,13 +1904,15 @@ focus(XEvent *ev)
return; return;
if (ev->type == FocusIn) { if (ev->type == FocusIn) {
XSetICFocus(xw.xic); if (xw.ime.xic)
XSetICFocus(xw.ime.xic);
win.mode |= MODE_FOCUSED; win.mode |= MODE_FOCUSED;
xseturgency(0); xseturgency(0);
if (IS_SET(MODE_FOCUS)) if (IS_SET(MODE_FOCUS))
ttywrite("\033[I", 3, 0); ttywrite("\033[I", 3, 0);
} else { } else {
XUnsetICFocus(xw.xic); if (xw.ime.xic)
XUnsetICFocus(xw.ime.xic);
win.mode &= ~MODE_FOCUSED; win.mode &= ~MODE_FOCUSED;
if (IS_SET(MODE_FOCUS)) if (IS_SET(MODE_FOCUS))
ttywrite("\033[O", 3, 0); ttywrite("\033[O", 3, 0);
@ -1915,7 +1967,7 @@ kpress(XEvent *ev)
{ {
XKeyEvent *e = &ev->xkey; XKeyEvent *e = &ev->xkey;
KeySym ksym; KeySym ksym;
char buf[32], *customkey; char buf[64], *customkey;
int len; int len;
Rune c; Rune c;
Status status; Status status;
@ -1924,7 +1976,10 @@ kpress(XEvent *ev)
if (IS_SET(MODE_KBDLOCK)) if (IS_SET(MODE_KBDLOCK))
return; return;
len = XmbLookupString(xw.xic, e, buf, sizeof buf, &ksym, &status); if (xw.ime.xic)
len = XmbLookupString(xw.ime.xic, e, buf, sizeof buf, &ksym, &status);
else
len = XLookupString(e, buf, sizeof buf, &ksym, NULL);
/* 1. shortcuts */ /* 1. shortcuts */
for (bp = shortcuts; bp < shortcuts + LEN(shortcuts); bp++) { for (bp = shortcuts; bp < shortcuts + LEN(shortcuts); bp++) {
if (ksym == bp->keysym && match(bp->mod, e->state)) { if (ksym == bp->keysym && match(bp->mod, e->state)) {
@ -2052,7 +2107,7 @@ run(void)
* triggers drawing, we first wait a bit to ensure we got * triggers drawing, we first wait a bit to ensure we got
* everything, and if nothing new arrives - we draw. * everything, and if nothing new arrives - we draw.
* We start with trying to wait minlatency ms. If more content * We start with trying to wait minlatency ms. If more content
* arrives sooner, we retry with shorter and shorter preiods, * arrives sooner, we retry with shorter and shorter periods,
* and eventually draw even without idle after maxlatency ms. * and eventually draw even without idle after maxlatency ms.
* Typically this results in low latency while interacting, * Typically this results in low latency while interacting,
* maximum latency intervals during `cat huge.txt`, and perfect * maximum latency intervals during `cat huge.txt`, and perfect
@ -2160,7 +2215,7 @@ main(int argc, char *argv[])
{ {
xw.l = xw.t = 0; xw.l = xw.t = 0;
xw.isfixed = False; xw.isfixed = False;
win.cursor = cursorshape; xsetcursor(cursorshape);
ARGBEGIN { ARGBEGIN {
case 'a': case 'a':