Compare commits
68 Commits
Author | SHA1 | Date | |
---|---|---|---|
43a395ae91 | |||
72e3f6c7c0 | |||
33a9a45664 | |||
771bc401f7 | |||
d66bd405c0 | |||
e997303502 | |||
c1145268f6 | |||
0b73612c0d | |||
019449a7e6 | |||
fbae700a3f | |||
e52319cc7d | |||
21e0d6e8b8 | |||
5703aa0390 | |||
28ad288399 | |||
51e19ea11d | |||
26cdfebf31 | |||
cd785755f2 | |||
2cb539142b | |||
99de333951 | |||
895e5b50a8 | |||
384830110b | |||
2e54a21b5a | |||
289c52b7aa | |||
7ceb3d1f72 | |||
ea4d933ed9 | |||
83866428de | |||
1f09f0b0bb | |||
a2c479c4c8 | |||
d2b75db8d7 | |||
b6d280de6d | |||
ba7f4d69af | |||
2b8333f553 | |||
caa1d8fbea | |||
f1546cf9c1 | |||
21367a040f | |||
b650256044 | |||
9acec468fb | |||
927621f6da | |||
add0211522 | |||
d5efd256aa | |||
75b4ba4b4b | |||
ed68fe7dce | |||
4e0135afec | |||
a8cb8e9454 | |||
e85b6b6466 | |||
75f92eb348 | |||
3be4cf11d7 | |||
16d98738e7 | |||
e23acb9188 | |||
7e19e11676 | |||
096b125db7 | |||
d7bf023b2f | |||
b4d68d4daa | |||
30ec9a3dc3 | |||
67d0cb65d0 | |||
4f4bccd162 | |||
8ed7a4b3b7 | |||
732be223ee | |||
5535c1f04c | |||
b51bcd5553 | |||
1911c9274d | |||
29f341da7c | |||
dc3b5babf1 | |||
235a783e03 | |||
30ce2cc002 | |||
041912a791 | |||
bd3f7fd842 | |||
74cff67bd7 |
60
FAQ
60
FAQ
@ -1,6 +1,6 @@
|
|||||||
## Why does st not handle utmp entries?
|
## Why does st not handle utmp entries?
|
||||||
|
|
||||||
Use the excellent tool of [utmp](http://git.suckless.org/utmp/) for this task.
|
Use the excellent tool of [utmp](https://git.suckless.org/utmp/) for this task.
|
||||||
|
|
||||||
## Some _random program_ complains that st is unknown/not recognised/unsupported/whatever!
|
## Some _random program_ complains that st is unknown/not recognised/unsupported/whatever!
|
||||||
|
|
||||||
@ -15,19 +15,18 @@ you can manually run `tic -sx st.info`.
|
|||||||
* Some programs don’t complain about the lacking st description and default to
|
* Some programs don’t complain about the lacking st description and default to
|
||||||
another terminal. In that case see the question about terminfo.
|
another terminal. In that case see the question about terminfo.
|
||||||
|
|
||||||
## I get some weird glitches/visual bug on _random program_!
|
|
||||||
|
|
||||||
Try launching it with a different TERM: $ TERM=xterm myapp. toe(1) will give
|
|
||||||
you a list of available terminals, but you’ll most likely switch between xterm,
|
|
||||||
st or st-256color. The default value for TERM can be changed in config.h
|
|
||||||
(TNAME).
|
|
||||||
|
|
||||||
## How do I scroll back up?
|
## How do I scroll back up?
|
||||||
|
|
||||||
Using a terminal multiplexer.
|
* Using a terminal multiplexer.
|
||||||
|
* `st -e tmux` using C-b [
|
||||||
|
* `st -e screen` using C-a ESC
|
||||||
|
* Using the excellent tool of [scroll](https://git.suckless.org/scroll/).
|
||||||
|
* Using the scrollback [patch](https://st.suckless.org/patches/scrollback/).
|
||||||
|
|
||||||
* `st -e tmux` using C-b [
|
## I would like to have utmp and/or scroll functionality by default
|
||||||
* `st -e screen` using C-a ESC
|
|
||||||
|
You can add the absolute patch of both programs in your config.h
|
||||||
|
file. You only have to modify the value of utmp and scroll variables.
|
||||||
|
|
||||||
## Why doesn't the Del key work in some programs?
|
## Why doesn't the Del key work in some programs?
|
||||||
|
|
||||||
@ -104,7 +103,7 @@ St is emulating the Linux way of handling backspace being delete and delete bein
|
|||||||
backspace.
|
backspace.
|
||||||
|
|
||||||
This is an issue that was discussed in suckless mailing list
|
This is an issue that was discussed in suckless mailing list
|
||||||
<http://lists.suckless.org/dev/1404/20697.html>. Here is why some old grumpy
|
<https://lists.suckless.org/dev/1404/20697.html>. Here is why some old grumpy
|
||||||
terminal users wants its backspace to be how he feels it:
|
terminal users wants its backspace to be how he feels it:
|
||||||
|
|
||||||
Well, I am going to comment why I want to change the behaviour
|
Well, I am going to comment why I want to change the behaviour
|
||||||
@ -163,5 +162,40 @@ terminal users wants its backspace to be how he feels it:
|
|||||||
|
|
||||||
Apply [1].
|
Apply [1].
|
||||||
|
|
||||||
[1] http://st.suckless.org/patches/delkey
|
[1] https://st.suckless.org/patches/delkey
|
||||||
|
|
||||||
|
## Why do images not work in st (in programs such as w3m)?
|
||||||
|
|
||||||
|
This is a terrible hack that overdraws an image on top of the terminal emulator
|
||||||
|
window. It also relies on a very specific way the terminal draws it's contents.
|
||||||
|
|
||||||
|
A more proper (but limited way) would be using sixels. Which st doesn't
|
||||||
|
support.
|
||||||
|
|
||||||
|
## BadLength X error in Xft when trying to render emoji
|
||||||
|
|
||||||
|
Xft makes st crash when rendering color emojis with the following error:
|
||||||
|
|
||||||
|
"X Error of failed request: BadLength (poly request too large or internal Xlib length error)"
|
||||||
|
Major opcode of failed request: 139 (RENDER)
|
||||||
|
Minor opcode of failed request: 20 (RenderAddGlyphs)
|
||||||
|
Serial number of failed request: 1595
|
||||||
|
Current serial number in output stream: 1818"
|
||||||
|
|
||||||
|
This is a known bug in Xft (not st) which happens on some platforms and
|
||||||
|
combination of particular fonts and fontconfig settings.
|
||||||
|
|
||||||
|
See also:
|
||||||
|
https://gitlab.freedesktop.org/xorg/lib/libxft/issues/6
|
||||||
|
https://bugs.freedesktop.org/show_bug.cgi?id=107534
|
||||||
|
https://bugzilla.redhat.com/show_bug.cgi?id=1498269
|
||||||
|
|
||||||
|
The solution is to remove color emoji fonts or disable this in the fontconfig
|
||||||
|
XML configuration. As an ugly workaround (which may work only on newer
|
||||||
|
fontconfig versions (FC_COLOR)), the following code can be used to mask color
|
||||||
|
fonts:
|
||||||
|
|
||||||
|
FcPatternAddBool(fcpattern, FC_COLOR, FcFalse);
|
||||||
|
|
||||||
|
Please don't bother reporting this bug to st, but notify the upstream Xft
|
||||||
|
developers about fixing this bug.
|
||||||
|
2
Makefile
2
Makefile
@ -22,7 +22,7 @@ config.h:
|
|||||||
$(CC) $(STCFLAGS) -c $<
|
$(CC) $(STCFLAGS) -c $<
|
||||||
|
|
||||||
st.o: config.h st.h win.h
|
st.o: config.h st.h win.h
|
||||||
x.o: arg.h st.h win.h
|
x.o: arg.h config.h st.h win.h
|
||||||
|
|
||||||
$(OBJ): config.h config.mk
|
$(OBJ): config.h config.mk
|
||||||
|
|
||||||
|
35
config.def.h
35
config.def.h
@ -11,13 +11,15 @@ 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 = NULL;
|
||||||
char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400";
|
char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400";
|
||||||
|
|
||||||
/* identification sequence returned in DA and DECID */
|
/* identification sequence returned in DA and DECID */
|
||||||
@ -30,9 +32,9 @@ static float chscale = 1.0;
|
|||||||
/*
|
/*
|
||||||
* word delimiter string
|
* word delimiter string
|
||||||
*
|
*
|
||||||
* More advanced example: " `'\"()[]{}"
|
* More advanced example: L" `'\"()[]{}"
|
||||||
*/
|
*/
|
||||||
char *worddelimiters = " ";
|
wchar_t *worddelimiters = L" ";
|
||||||
|
|
||||||
/* selection timeouts (in milliseconds) */
|
/* selection timeouts (in milliseconds) */
|
||||||
static unsigned int doubleclicktimeout = 300;
|
static unsigned int doubleclicktimeout = 300;
|
||||||
@ -150,14 +152,22 @@ static unsigned int mousebg = 0;
|
|||||||
*/
|
*/
|
||||||
static unsigned int defaultattr = 11;
|
static unsigned int defaultattr = 11;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Force mouse select/shortcuts while mask is active (when MODE_MOUSE is set).
|
||||||
|
* Note that if you want to use ShiftMask with selmasks, set this to an other
|
||||||
|
* modifier, set to 0 to not use it.
|
||||||
|
*/
|
||||||
|
static uint forcemousemod = ShiftMask;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Internal mouse shortcuts.
|
* Internal mouse shortcuts.
|
||||||
* Beware that overloading Button1 will disable the selection.
|
* Beware that overloading Button1 will disable the selection.
|
||||||
*/
|
*/
|
||||||
static MouseShortcut mshortcuts[] = {
|
static MouseShortcut mshortcuts[] = {
|
||||||
/* button mask string */
|
/* mask button function argument release */
|
||||||
{ Button4, XK_ANY_MOD, "\031" },
|
{ XK_ANY_MOD, Button2, selpaste, {.i = 0}, 1 },
|
||||||
{ Button5, XK_ANY_MOD, "\005" },
|
{ XK_ANY_MOD, Button4, ttysend, {.s = "\031"} },
|
||||||
|
{ XK_ANY_MOD, Button5, ttysend, {.s = "\005"} },
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Internal keyboard shortcuts. */
|
/* Internal keyboard shortcuts. */
|
||||||
@ -176,8 +186,8 @@ static Shortcut shortcuts[] = {
|
|||||||
{ TERMMOD, XK_C, clipcopy, {.i = 0} },
|
{ TERMMOD, XK_C, clipcopy, {.i = 0} },
|
||||||
{ TERMMOD, XK_V, clippaste, {.i = 0} },
|
{ TERMMOD, XK_V, clippaste, {.i = 0} },
|
||||||
{ TERMMOD, XK_Y, selpaste, {.i = 0} },
|
{ TERMMOD, XK_Y, selpaste, {.i = 0} },
|
||||||
|
{ ShiftMask, XK_Insert, selpaste, {.i = 0} },
|
||||||
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
|
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
|
||||||
{ TERMMOD, XK_I, iso14755, {.i = 0} },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -195,10 +205,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
|
||||||
@ -217,13 +223,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.
|
||||||
|
23
config.mk
23
config.mk
@ -1,5 +1,5 @@
|
|||||||
# st version
|
# st version
|
||||||
VERSION = 0.8.1
|
VERSION = 0.8.3
|
||||||
|
|
||||||
# Customize below to fit your system
|
# Customize below to fit your system
|
||||||
|
|
||||||
@ -10,19 +10,26 @@ MANPREFIX = $(PREFIX)/share/man
|
|||||||
X11INC = /usr/X11R6/include
|
X11INC = /usr/X11R6/include
|
||||||
X11LIB = /usr/X11R6/lib
|
X11LIB = /usr/X11R6/lib
|
||||||
|
|
||||||
|
PKG_CONFIG = pkg-config
|
||||||
|
|
||||||
# includes and libs
|
# includes and libs
|
||||||
INCS = -I$(X11INC) \
|
INCS = -I$(X11INC) \
|
||||||
`pkg-config --cflags fontconfig` \
|
`$(PKG_CONFIG) --cflags fontconfig` \
|
||||||
`pkg-config --cflags freetype2`
|
`$(PKG_CONFIG) --cflags freetype2`
|
||||||
LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \
|
LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \
|
||||||
`pkg-config --libs fontconfig` \
|
`$(PKG_CONFIG) --libs fontconfig` \
|
||||||
`pkg-config --libs freetype2`
|
`$(PKG_CONFIG) --libs freetype2`
|
||||||
|
|
||||||
# flags
|
# flags
|
||||||
CPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600
|
STCPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600
|
||||||
STCFLAGS = $(INCS) $(CPPFLAGS) $(CFLAGS)
|
STCFLAGS = $(INCS) $(STCPPFLAGS) $(CPPFLAGS) $(CFLAGS)
|
||||||
STLDFLAGS = $(LIBS) $(LDFLAGS)
|
STLDFLAGS = $(LIBS) $(LDFLAGS)
|
||||||
|
|
||||||
|
# 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
|
# compiler and linker
|
||||||
# CC = c99
|
# CC = c99
|
||||||
|
|
||||||
|
7
st.1
7
st.1
@ -159,10 +159,6 @@ Copy the selected text to the clipboard selection.
|
|||||||
.TP
|
.TP
|
||||||
.B Ctrl-Shift-v
|
.B Ctrl-Shift-v
|
||||||
Paste from the clipboard selection.
|
Paste from the clipboard selection.
|
||||||
.TP
|
|
||||||
.B Ctrl-Shift-i
|
|
||||||
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
|
||||||
@ -174,7 +170,8 @@ 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.
|
||||||
|
|
||||||
|
183
st.c
183
st.c
@ -38,14 +38,10 @@
|
|||||||
|
|
||||||
/* 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) == '\177')
|
#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) (utf8strchr(worddelimiters, u) != NULL)
|
#define ISDELIM(u) (u && wcschr(worddelimiters, u))
|
||||||
|
|
||||||
/* constants */
|
|
||||||
#define ISO14755CMD "dmenu -w \"$WINDOWID\" -p codepoint: </dev/null"
|
|
||||||
|
|
||||||
enum term_mode {
|
enum term_mode {
|
||||||
MODE_WRAP = 1 << 0,
|
MODE_WRAP = 1 << 0,
|
||||||
@ -139,7 +135,7 @@ typedef struct {
|
|||||||
/* 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 */
|
||||||
@ -150,8 +146,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;
|
||||||
@ -214,7 +211,6 @@ static void selsnap(int *, int *, int);
|
|||||||
static size_t utf8decode(const char *, Rune *, size_t);
|
static size_t utf8decode(const char *, Rune *, size_t);
|
||||||
static Rune utf8decodebyte(char, size_t *);
|
static Rune utf8decodebyte(char, size_t *);
|
||||||
static char utf8encodebyte(Rune, size_t);
|
static char utf8encodebyte(Rune, size_t);
|
||||||
static char *utf8strchr(char *, Rune);
|
|
||||||
static size_t utf8validate(Rune *, size_t);
|
static size_t utf8validate(Rune *, size_t);
|
||||||
|
|
||||||
static char *base64dec(const char *);
|
static char *base64dec(const char *);
|
||||||
@ -256,10 +252,10 @@ xwrite(int fd, const char *s, size_t len)
|
|||||||
void *
|
void *
|
||||||
xmalloc(size_t len)
|
xmalloc(size_t len)
|
||||||
{
|
{
|
||||||
void *p = malloc(len);
|
void *p;
|
||||||
|
|
||||||
if (!p)
|
if (!(p = malloc(len)))
|
||||||
die("Out of memory\n");
|
die("malloc: %s\n", strerror(errno));
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@ -268,7 +264,7 @@ void *
|
|||||||
xrealloc(void *p, size_t len)
|
xrealloc(void *p, size_t len)
|
||||||
{
|
{
|
||||||
if ((p = realloc(p, len)) == NULL)
|
if ((p = realloc(p, len)) == NULL)
|
||||||
die("Out of memory\n");
|
die("realloc: %s\n", strerror(errno));
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@ -277,7 +273,7 @@ char *
|
|||||||
xstrdup(char *s)
|
xstrdup(char *s)
|
||||||
{
|
{
|
||||||
if ((s = strdup(s)) == NULL)
|
if ((s = strdup(s)) == NULL)
|
||||||
die("Out of memory\n");
|
die("strdup: %s\n", strerror(errno));
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@ -341,23 +337,6 @@ utf8encodebyte(Rune u, size_t i)
|
|||||||
return utfbyte[i] | (u & ~utfmask[i]);
|
return utfbyte[i] | (u & ~utfmask[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
|
||||||
utf8strchr(char *s, Rune u)
|
|
||||||
{
|
|
||||||
Rune r;
|
|
||||||
size_t i, j, len;
|
|
||||||
|
|
||||||
len = strlen(s);
|
|
||||||
for (i = 0, j = 0; i < len; i += j) {
|
|
||||||
if (!(j = utf8decode(&s[i], &r, len - i)))
|
|
||||||
break;
|
|
||||||
if (r == u)
|
|
||||||
return &(s[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
utf8validate(Rune *u, size_t i)
|
utf8validate(Rune *u, size_t i)
|
||||||
{
|
{
|
||||||
@ -387,8 +366,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 *
|
||||||
@ -406,6 +386,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;
|
||||||
@ -446,6 +430,7 @@ selstart(int col, int row, int snap)
|
|||||||
selclear();
|
selclear();
|
||||||
sel.mode = SEL_EMPTY;
|
sel.mode = SEL_EMPTY;
|
||||||
sel.type = SEL_REGULAR;
|
sel.type = SEL_REGULAR;
|
||||||
|
sel.alt = IS_SET(MODE_ALTSCREEN);
|
||||||
sel.snap = snap;
|
sel.snap = snap;
|
||||||
sel.oe.x = sel.ob.x = col;
|
sel.oe.x = sel.ob.x = col;
|
||||||
sel.oe.y = sel.ob.y = row;
|
sel.oe.y = sel.ob.y = row;
|
||||||
@ -474,13 +459,12 @@ selextend(int col, int row, int type, int done)
|
|||||||
oldsey = sel.ne.y;
|
oldsey = sel.ne.y;
|
||||||
oldtype = sel.type;
|
oldtype = sel.type;
|
||||||
|
|
||||||
sel.alt = IS_SET(MODE_ALTSCREEN);
|
|
||||||
sel.oe.x = col;
|
sel.oe.x = col;
|
||||||
sel.oe.y = row;
|
sel.oe.y = row;
|
||||||
selnormalize();
|
selnormalize();
|
||||||
sel.type = type;
|
sel.type = type;
|
||||||
|
|
||||||
if (oldey != sel.oe.y || oldex != sel.oe.x || oldtype != sel.type)
|
if (oldey != sel.oe.y || oldex != sel.oe.x || oldtype != sel.type || sel.mode == SEL_EMPTY)
|
||||||
tsetdirt(MIN(sel.nb.y, oldsby), MAX(sel.ne.y, oldsey));
|
tsetdirt(MIN(sel.nb.y, oldsby), MAX(sel.ne.y, oldsey));
|
||||||
|
|
||||||
sel.mode = done ? SEL_IDLE : SEL_READY;
|
sel.mode = done ? SEL_IDLE : SEL_READY;
|
||||||
@ -681,13 +665,13 @@ 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;
|
||||||
if ((pw = getpwuid(getuid())) == NULL) {
|
if ((pw = getpwuid(getuid())) == NULL) {
|
||||||
if (errno)
|
if (errno)
|
||||||
die("getpwuid:%s\n", strerror(errno));
|
die("getpwuid: %s\n", strerror(errno));
|
||||||
else
|
else
|
||||||
die("who are you?\n");
|
die("who are you?\n");
|
||||||
}
|
}
|
||||||
@ -695,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");
|
||||||
@ -730,13 +721,15 @@ sigchld(int a)
|
|||||||
pid_t p;
|
pid_t p;
|
||||||
|
|
||||||
if ((p = waitpid(pid, &stat, WNOHANG)) < 0)
|
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)
|
if (pid != p)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!WIFEXITED(stat) || WEXITSTATUS(stat))
|
if (WIFEXITED(stat) && WEXITSTATUS(stat))
|
||||||
die("child finished with error '%d'\n", stat);
|
die("child exited with status %d\n", WEXITSTATUS(stat));
|
||||||
|
else if (WIFSIGNALED(stat))
|
||||||
|
die("child terminated due to signal %d\n", WTERMSIG(stat));
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -781,7 +774,8 @@ ttynew(char *line, char *cmd, char *out, char **args)
|
|||||||
|
|
||||||
if (line) {
|
if (line) {
|
||||||
if ((cmdfd = open(line, O_RDWR)) < 0)
|
if ((cmdfd = open(line, O_RDWR)) < 0)
|
||||||
die("open line failed: %s\n", strerror(errno));
|
die("open line '%s' failed: %s\n",
|
||||||
|
line, strerror(errno));
|
||||||
dup2(cmdfd, 0);
|
dup2(cmdfd, 0);
|
||||||
stty(args);
|
stty(args);
|
||||||
return cmdfd;
|
return cmdfd;
|
||||||
@ -793,7 +787,7 @@ ttynew(char *line, char *cmd, char *out, char **args)
|
|||||||
|
|
||||||
switch (pid = fork()) {
|
switch (pid = fork()) {
|
||||||
case -1:
|
case -1:
|
||||||
die("fork failed\n");
|
die("fork failed: %s\n", strerror(errno));
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
close(iofd);
|
close(iofd);
|
||||||
@ -805,9 +799,17 @@ ttynew(char *line, char *cmd, char *out, char **args)
|
|||||||
die("ioctl TIOCSCTTY failed: %s\n", strerror(errno));
|
die("ioctl TIOCSCTTY failed: %s\n", strerror(errno));
|
||||||
close(s);
|
close(s);
|
||||||
close(m);
|
close(m);
|
||||||
|
#ifdef __OpenBSD__
|
||||||
|
if (pledge("stdio getpw proc exec", NULL) == -1)
|
||||||
|
die("pledge\n");
|
||||||
|
#endif
|
||||||
execsh(cmd, args);
|
execsh(cmd, args);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
#ifdef __OpenBSD__
|
||||||
|
if (pledge("stdio rpath tty proc", NULL) == -1)
|
||||||
|
die("pledge\n");
|
||||||
|
#endif
|
||||||
close(s);
|
close(s);
|
||||||
cmdfd = m;
|
cmdfd = m;
|
||||||
signal(SIGCHLD, sigchld);
|
signal(SIGCHLD, sigchld);
|
||||||
@ -821,21 +823,26 @@ 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;
|
|
||||||
|
|
||||||
written = twrite(buf, buflen, 0);
|
switch (ret) {
|
||||||
buflen -= written;
|
case 0:
|
||||||
/* keep any uncomplete utf8 char for the next call */
|
exit(0);
|
||||||
if (buflen > 0)
|
case -1:
|
||||||
memmove(buf, buf + written, buflen);
|
die("couldn't read from shell: %s\n", strerror(errno));
|
||||||
|
default:
|
||||||
|
buflen += ret;
|
||||||
|
written = twrite(buf, buflen, 0);
|
||||||
|
buflen -= written;
|
||||||
|
/* keep any incomplete UTF-8 byte sequence for the next call */
|
||||||
|
if (buflen > 0)
|
||||||
|
memmove(buf, buf + written, buflen);
|
||||||
|
return ret;
|
||||||
|
|
||||||
return ret;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1447,7 +1454,8 @@ tsetattr(int *attr, int l)
|
|||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"erresc(default): gfx attr %d unknown\n",
|
"erresc(default): gfx attr %d unknown\n",
|
||||||
attr[i]), csidump();
|
attr[i]);
|
||||||
|
csidump();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1567,6 +1575,7 @@ tsetmode(int priv, int set, int *args, int narg)
|
|||||||
case 1015: /* urxvt mangled mouse mode; incompatible
|
case 1015: /* urxvt mangled mouse mode; incompatible
|
||||||
and can be mistaken for other control
|
and can be mistaken for other control
|
||||||
codes. */
|
codes. */
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"erresc: unknown private set/reset mode %d\n",
|
"erresc: unknown private set/reset mode %d\n",
|
||||||
@ -1808,7 +1817,7 @@ csihandle(void)
|
|||||||
void
|
void
|
||||||
csidump(void)
|
csidump(void)
|
||||||
{
|
{
|
||||||
int i;
|
size_t i;
|
||||||
uint c;
|
uint c;
|
||||||
|
|
||||||
fprintf(stderr, "ESC[");
|
fprintf(stderr, "ESC[");
|
||||||
@ -1838,7 +1847,7 @@ csireset(void)
|
|||||||
void
|
void
|
||||||
strhandle(void)
|
strhandle(void)
|
||||||
{
|
{
|
||||||
char *p = NULL;
|
char *p = NULL, *dec;
|
||||||
int j, narg, par;
|
int j, narg, par;
|
||||||
|
|
||||||
term.esc &= ~(ESC_STR_END|ESC_STR);
|
term.esc &= ~(ESC_STR_END|ESC_STR);
|
||||||
@ -1856,8 +1865,6 @@ strhandle(void)
|
|||||||
return;
|
return;
|
||||||
case 52:
|
case 52:
|
||||||
if (narg > 2) {
|
if (narg > 2) {
|
||||||
char *dec;
|
|
||||||
|
|
||||||
dec = base64dec(strescseq.args[2]);
|
dec = base64dec(strescseq.args[2]);
|
||||||
if (dec) {
|
if (dec) {
|
||||||
xsetsel(dec);
|
xsetsel(dec);
|
||||||
@ -1875,7 +1882,10 @@ strhandle(void)
|
|||||||
case 104: /* color reset, here p = NULL */
|
case 104: /* color reset, here p = NULL */
|
||||||
j = (narg > 1) ? atoi(strescseq.args[1]) : -1;
|
j = (narg > 1) ? atoi(strescseq.args[1]) : -1;
|
||||||
if (xsetcolorname(j, p)) {
|
if (xsetcolorname(j, p)) {
|
||||||
fprintf(stderr, "erresc: invalid color %s\n", p);
|
if (par == 104 && narg <= 1)
|
||||||
|
return; /* color reset without parameter */
|
||||||
|
fprintf(stderr, "erresc: invalid color j=%d, p=%s\n",
|
||||||
|
j, p ? p : "(null)");
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* TODO if defaultbg color is changed, borders
|
* TODO if defaultbg color is changed, borders
|
||||||
@ -1925,7 +1935,7 @@ strparse(void)
|
|||||||
void
|
void
|
||||||
strdump(void)
|
strdump(void)
|
||||||
{
|
{
|
||||||
int i;
|
size_t i;
|
||||||
uint c;
|
uint c;
|
||||||
|
|
||||||
fprintf(stderr, "ESC%c", strescseq.type);
|
fprintf(stderr, "ESC%c", strescseq.type);
|
||||||
@ -1952,7 +1962,10 @@ strdump(void)
|
|||||||
void
|
void
|
||||||
strreset(void)
|
strreset(void)
|
||||||
{
|
{
|
||||||
memset(&strescseq, 0, sizeof(strescseq));
|
strescseq = (STREscape){
|
||||||
|
.buf = xrealloc(strescseq.buf, STR_BUF_SIZ),
|
||||||
|
.siz = STR_BUF_SIZ,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1972,28 +1985,6 @@ tprinter(char *s, size_t len)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
iso14755(const Arg *arg)
|
|
||||||
{
|
|
||||||
FILE *p;
|
|
||||||
char *us, *e, codepoint[9], uc[UTF_SIZ];
|
|
||||||
unsigned long utf32;
|
|
||||||
|
|
||||||
if (!(p = popen(ISO14755CMD, "r")))
|
|
||||||
return;
|
|
||||||
|
|
||||||
us = fgets(codepoint, sizeof(codepoint), p);
|
|
||||||
pclose(p);
|
|
||||||
|
|
||||||
if (!us || *us == '\0' || *us == '-' || strlen(us) > 7)
|
|
||||||
return;
|
|
||||||
if ((utf32 = strtoul(us, &e, 16)) == ULONG_MAX ||
|
|
||||||
(*e != '\n' && *e != '\0'))
|
|
||||||
return;
|
|
||||||
|
|
||||||
ttywrite(uc, utf8encode(utf32, uc), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
toggleprinter(const Arg *arg)
|
toggleprinter(const Arg *arg)
|
||||||
{
|
{
|
||||||
@ -2278,7 +2269,7 @@ eschandle(uchar ascii)
|
|||||||
case 'Z': /* DECID -- Identify Terminal */
|
case 'Z': /* DECID -- Identify Terminal */
|
||||||
ttywrite(vtiden, strlen(vtiden), 0);
|
ttywrite(vtiden, strlen(vtiden), 0);
|
||||||
break;
|
break;
|
||||||
case 'c': /* RIS -- Reset to inital state */
|
case 'c': /* RIS -- Reset to initial state */
|
||||||
treset();
|
treset();
|
||||||
resettitle();
|
resettitle();
|
||||||
xloadcols();
|
xloadcols();
|
||||||
@ -2349,7 +2340,6 @@ tputc(Rune u)
|
|||||||
goto check_control_code;
|
goto check_control_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (IS_SET(MODE_SIXEL)) {
|
if (IS_SET(MODE_SIXEL)) {
|
||||||
/* TODO: implement sixel mode */
|
/* TODO: implement sixel mode */
|
||||||
return;
|
return;
|
||||||
@ -2357,7 +2347,7 @@ tputc(Rune u)
|
|||||||
if (term.esc&ESC_DCS && strescseq.len == 0 && u == 'q')
|
if (term.esc&ESC_DCS && strescseq.len == 0 && u == 'q')
|
||||||
term.mode |= MODE_SIXEL;
|
term.mode |= MODE_SIXEL;
|
||||||
|
|
||||||
if (strescseq.len+len >= sizeof(strescseq.buf)-1) {
|
if (strescseq.len+len >= strescseq.siz) {
|
||||||
/*
|
/*
|
||||||
* 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
|
||||||
@ -2371,7 +2361,10 @@ tputc(Rune u)
|
|||||||
* term.esc = 0;
|
* term.esc = 0;
|
||||||
* strhandle();
|
* strhandle();
|
||||||
*/
|
*/
|
||||||
return;
|
if (strescseq.siz > (SIZE_MAX - UTF_SIZ) / 2)
|
||||||
|
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);
|
||||||
@ -2578,6 +2571,7 @@ 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;
|
||||||
@ -2590,7 +2584,7 @@ drawregion(int x1, int y1, int x2, int y2)
|
|||||||
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;
|
||||||
@ -2606,8 +2600,11 @@ draw(void)
|
|||||||
drawregion(0, 0, term.col, term.row);
|
drawregion(0, 0, term.col, term.row);
|
||||||
xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
|
xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
|
||||||
term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
|
term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
|
||||||
term.ocx = cx, term.ocy = term.c.y;
|
term.ocx = cx;
|
||||||
|
term.ocy = term.c.y;
|
||||||
xfinishdraw();
|
xfinishdraw();
|
||||||
|
if (ocx != term.ocx || ocy != term.ocy)
|
||||||
|
xximspot(term.ocx, term.ocy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
5
st.h
5
st.h
@ -74,13 +74,13 @@ typedef union {
|
|||||||
uint ui;
|
uint ui;
|
||||||
float f;
|
float f;
|
||||||
const void *v;
|
const void *v;
|
||||||
|
const char *s;
|
||||||
} Arg;
|
} Arg;
|
||||||
|
|
||||||
void die(const char *, ...);
|
void die(const char *, ...);
|
||||||
void redraw(void);
|
void redraw(void);
|
||||||
void draw(void);
|
void draw(void);
|
||||||
|
|
||||||
void iso14755(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 *);
|
||||||
@ -113,9 +113,10 @@ char *xstrdup(char *);
|
|||||||
|
|
||||||
/* config.h globals */
|
/* config.h globals */
|
||||||
extern char *utmp;
|
extern char *utmp;
|
||||||
|
extern char *scroll;
|
||||||
extern char *stty_args;
|
extern char *stty_args;
|
||||||
extern char *vtiden;
|
extern char *vtiden;
|
||||||
extern char *worddelimiters;
|
extern wchar_t *worddelimiters;
|
||||||
extern int allowaltscreen;
|
extern int allowaltscreen;
|
||||||
extern char *termname;
|
extern char *termname;
|
||||||
extern unsigned int tabspaces;
|
extern unsigned int tabspaces;
|
||||||
|
34
st.info
34
st.info
@ -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,
|
||||||
@ -168,13 +168,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,
|
||||||
@ -189,10 +184,19 @@ st| simpleterm,
|
|||||||
rmxx=\E[29m,
|
rmxx=\E[29m,
|
||||||
smxx=\E[9m,
|
smxx=\E[9m,
|
||||||
# tmux extensions, see TERMINFO EXTENSIONS in tmux(1)
|
# tmux extensions, see TERMINFO EXTENSIONS in tmux(1)
|
||||||
Se,
|
|
||||||
Ss,
|
|
||||||
Tc,
|
Tc,
|
||||||
Ms=\E]52;%p1%s;%p2%s\007,
|
Ms=\E]52;%p1%s;%p2%s\007,
|
||||||
|
Se=\E[2 q,
|
||||||
|
Ss=\E[%p1%d q,
|
||||||
|
|
||||||
|
st| simpleterm,
|
||||||
|
use=st-mono,
|
||||||
|
colors#8,
|
||||||
|
setab=\E[4%p1%dm,
|
||||||
|
setaf=\E[3%p1%dm,
|
||||||
|
setb=\E[4%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m,
|
||||||
|
setf=\E[3%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m,
|
||||||
|
sgr=%?%p9%t\E(0%e\E(B%;\E[0%?%p6%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;%?%p7%t;8%;m,
|
||||||
|
|
||||||
st-256color| simpleterm with 256 colors,
|
st-256color| simpleterm with 256 colors,
|
||||||
use=st,
|
use=st,
|
||||||
@ -220,3 +224,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,
|
||||||
|
1
win.h
1
win.h
@ -36,3 +36,4 @@ void xsetmode(int, unsigned int);
|
|||||||
void xsetpointermotion(int);
|
void xsetpointermotion(int);
|
||||||
void xsetsel(char *);
|
void xsetsel(char *);
|
||||||
int xstartdraw(void);
|
int xstartdraw(void);
|
||||||
|
void xximspot(int, int);
|
||||||
|
251
x.c
251
x.c
@ -15,7 +15,7 @@
|
|||||||
#include <X11/Xft/Xft.h>
|
#include <X11/Xft/Xft.h>
|
||||||
#include <X11/XKBlib.h>
|
#include <X11/XKBlib.h>
|
||||||
|
|
||||||
static char *argv0;
|
char *argv0;
|
||||||
#include "arg.h"
|
#include "arg.h"
|
||||||
#include "st.h"
|
#include "st.h"
|
||||||
#include "win.h"
|
#include "win.h"
|
||||||
@ -29,9 +29,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 {
|
||||||
@ -56,6 +58,7 @@ static void selpaste(const Arg *);
|
|||||||
static void zoom(const Arg *);
|
static void zoom(const Arg *);
|
||||||
static void zoomabs(const Arg *);
|
static void zoomabs(const Arg *);
|
||||||
static void zoomreset(const Arg *);
|
static void zoomreset(const Arg *);
|
||||||
|
static void ttysend(const Arg *);
|
||||||
|
|
||||||
/* config.h for applying patches and the configuration. */
|
/* config.h for applying patches and the configuration. */
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
@ -91,8 +94,12 @@ typedef struct {
|
|||||||
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, netwmpid;
|
||||||
XIM xim;
|
struct {
|
||||||
XIC xic;
|
XIM xim;
|
||||||
|
XIC xic;
|
||||||
|
XPoint spot;
|
||||||
|
XVaNestedList spotlist;
|
||||||
|
} ime;
|
||||||
Draw draw;
|
Draw draw;
|
||||||
Visual *vis;
|
Visual *vis;
|
||||||
XSetWindowAttributes attrs;
|
XSetWindowAttributes attrs;
|
||||||
@ -139,6 +146,10 @@ static void xdrawglyphfontspecs(const XftGlyphFontSpec *, Glyph, int, int, int);
|
|||||||
static void xdrawglyph(Glyph, int, int);
|
static void xdrawglyph(Glyph, int, int);
|
||||||
static void xclear(int, int, int, int);
|
static void xclear(int, int, int, int);
|
||||||
static int xgeommasktogravity(int);
|
static int xgeommasktogravity(int);
|
||||||
|
static int ximopen(Display *);
|
||||||
|
static void ximinstantiate(Display *, XPointer, XPointer);
|
||||||
|
static void ximdestroy(XIM, XPointer, XPointer);
|
||||||
|
static int xicdestroy(XIC, XPointer, XPointer);
|
||||||
static void xinit(int, int);
|
static void xinit(int, int);
|
||||||
static void cresize(int, int);
|
static void cresize(int, int);
|
||||||
static void xresize(int, int);
|
static void xresize(int, int);
|
||||||
@ -160,6 +171,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 *);
|
||||||
@ -223,8 +236,9 @@ typedef struct {
|
|||||||
} Fontcache;
|
} Fontcache;
|
||||||
|
|
||||||
/* Fontcache is an array now. A new font will be appended to the array. */
|
/* Fontcache is an array now. A new font will be appended to the array. */
|
||||||
static Fontcache frc[16];
|
static Fontcache *frc = NULL;
|
||||||
static int frclen = 0;
|
static int frclen = 0;
|
||||||
|
static int frccap = 0;
|
||||||
static char *usedfont = NULL;
|
static char *usedfont = NULL;
|
||||||
static double usedfontsize = 0;
|
static double usedfontsize = 0;
|
||||||
static double defaultfontsize = 0;
|
static double defaultfontsize = 0;
|
||||||
@ -308,6 +322,12 @@ zoomreset(const Arg *arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ttysend(const Arg *arg)
|
||||||
|
{
|
||||||
|
ttywrite(arg->s, strlen(arg->s), 1);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
evcol(XEvent *e)
|
evcol(XEvent *e)
|
||||||
{
|
{
|
||||||
@ -328,7 +348,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)) {
|
||||||
@ -404,25 +424,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;
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) {
|
if (mouseaction(e, 0))
|
||||||
if (e->xbutton.button == ms->b
|
return;
|
||||||
&& match(ms->mask, e->xbutton.state)) {
|
|
||||||
ttywrite(ms->s, strlen(ms->s), 1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e->xbutton.button == Button1) {
|
if (e->xbutton.button == Button1) {
|
||||||
/*
|
/*
|
||||||
@ -638,21 +684,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;
|
||||||
}
|
}
|
||||||
@ -672,6 +718,8 @@ cresize(int width, int height)
|
|||||||
|
|
||||||
col = (win.w - 2 * borderpx) / win.cw;
|
col = (win.w - 2 * borderpx) / win.cw;
|
||||||
row = (win.h - 2 * borderpx) / win.ch;
|
row = (win.h - 2 * borderpx) / win.ch;
|
||||||
|
col = MAX(1, col);
|
||||||
|
row = MAX(1, row);
|
||||||
|
|
||||||
tresize(col, row);
|
tresize(col, row);
|
||||||
xresize(col, row);
|
xresize(col, row);
|
||||||
@ -681,8 +729,8 @@ cresize(int width, int height)
|
|||||||
void
|
void
|
||||||
xresize(int col, int row)
|
xresize(int col, int row)
|
||||||
{
|
{
|
||||||
win.tw = MAX(1, col * win.cw);
|
win.tw = col * win.cw;
|
||||||
win.th = MAX(1, row * win.ch);
|
win.th = row * win.ch;
|
||||||
|
|
||||||
XFreePixmap(xw.dpy, xw.buf);
|
XFreePixmap(xw.dpy, xw.buf);
|
||||||
xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
|
xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
|
||||||
@ -731,20 +779,20 @@ xloadcols(void)
|
|||||||
static int loaded;
|
static int loaded;
|
||||||
Color *cp;
|
Color *cp;
|
||||||
|
|
||||||
dc.collen = MAX(LEN(colorname), 256);
|
|
||||||
dc.col = xmalloc(dc.collen * sizeof(Color));
|
|
||||||
|
|
||||||
if (loaded) {
|
if (loaded) {
|
||||||
for (cp = dc.col; cp < &dc.col[dc.collen]; ++cp)
|
for (cp = dc.col; cp < &dc.col[dc.collen]; ++cp)
|
||||||
XftColorFree(xw.dpy, xw.vis, xw.cmap, cp);
|
XftColorFree(xw.dpy, xw.vis, xw.cmap, cp);
|
||||||
|
} else {
|
||||||
|
dc.collen = MAX(LEN(colorname), 256);
|
||||||
|
dc.col = xmalloc(dc.collen * sizeof(Color));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < dc.collen; i++)
|
for (i = 0; i < dc.collen; i++)
|
||||||
if (!xloadcolor(i, NULL, &dc.col[i])) {
|
if (!xloadcolor(i, NULL, &dc.col[i])) {
|
||||||
if (colorname[i])
|
if (colorname[i])
|
||||||
die("Could not allocate color '%s'\n", colorname[i]);
|
die("could not allocate color '%s'\n", colorname[i]);
|
||||||
else
|
else
|
||||||
die("Could not allocate color %d\n", i);
|
die("could not allocate color %d\n", i);
|
||||||
}
|
}
|
||||||
loaded = 1;
|
loaded = 1;
|
||||||
}
|
}
|
||||||
@ -757,7 +805,6 @@ xsetcolorname(int x, const char *name)
|
|||||||
if (!BETWEEN(x, 0, dc.collen))
|
if (!BETWEEN(x, 0, dc.collen))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
|
||||||
if (!xloadcolor(x, name, &ncolor))
|
if (!xloadcolor(x, name, &ncolor))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
@ -788,15 +835,17 @@ xhints(void)
|
|||||||
|
|
||||||
sizeh = XAllocSizeHints();
|
sizeh = XAllocSizeHints();
|
||||||
|
|
||||||
sizeh->flags = PSize | PResizeInc | PBaseSize;
|
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 = win.ch;
|
sizeh->height_inc = win.ch;
|
||||||
sizeh->width_inc = win.cw;
|
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_width = win.cw + 2 * borderpx;
|
||||||
if (xw.isfixed) {
|
if (xw.isfixed) {
|
||||||
sizeh->flags |= PMaxSize | PMinSize;
|
sizeh->flags |= PMaxSize;
|
||||||
sizeh->min_width = sizeh->max_width = win.w;
|
sizeh->min_width = sizeh->max_width = win.w;
|
||||||
sizeh->min_height = sizeh->max_height = win.h;
|
sizeh->min_height = sizeh->max_height = win.h;
|
||||||
}
|
}
|
||||||
@ -869,7 +918,7 @@ xloadfont(Font *f, FcPattern *pattern)
|
|||||||
if ((XftPatternGetInteger(f->match->pattern, "slant", 0,
|
if ((XftPatternGetInteger(f->match->pattern, "slant", 0,
|
||||||
&haveattr) != XftResultMatch) || haveattr < wantattr) {
|
&haveattr) != XftResultMatch) || haveattr < wantattr) {
|
||||||
f->badslant = 1;
|
f->badslant = 1;
|
||||||
fputs("st: font slant does not match\n", stderr);
|
fputs("font slant does not match\n", stderr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -878,7 +927,7 @@ xloadfont(Font *f, FcPattern *pattern)
|
|||||||
if ((XftPatternGetInteger(f->match->pattern, "weight", 0,
|
if ((XftPatternGetInteger(f->match->pattern, "weight", 0,
|
||||||
&haveattr) != XftResultMatch) || haveattr != wantattr) {
|
&haveattr) != XftResultMatch) || haveattr != wantattr) {
|
||||||
f->badweight = 1;
|
f->badweight = 1;
|
||||||
fputs("st: font weight does not match\n", stderr);
|
fputs("font weight does not match\n", stderr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -906,14 +955,13 @@ xloadfonts(char *fontstr, double fontsize)
|
|||||||
FcPattern *pattern;
|
FcPattern *pattern;
|
||||||
double fontval;
|
double fontval;
|
||||||
|
|
||||||
if (fontstr[0] == '-') {
|
if (fontstr[0] == '-')
|
||||||
pattern = XftXlfdParse(fontstr, False, False);
|
pattern = XftXlfdParse(fontstr, False, False);
|
||||||
} else {
|
else
|
||||||
pattern = FcNameParse((FcChar8 *)fontstr);
|
pattern = FcNameParse((FcChar8 *)fontstr);
|
||||||
}
|
|
||||||
|
|
||||||
if (!pattern)
|
if (!pattern)
|
||||||
die("st: can't open font %s\n", fontstr);
|
die("can't open font %s\n", fontstr);
|
||||||
|
|
||||||
if (fontsize > 1) {
|
if (fontsize > 1) {
|
||||||
FcPatternDel(pattern, FC_PIXEL_SIZE);
|
FcPatternDel(pattern, FC_PIXEL_SIZE);
|
||||||
@ -939,7 +987,7 @@ xloadfonts(char *fontstr, double fontsize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (xloadfont(&dc.font, pattern))
|
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) {
|
if (usedfontsize < 0) {
|
||||||
FcPatternGetDouble(dc.font.match->pattern,
|
FcPatternGetDouble(dc.font.match->pattern,
|
||||||
@ -956,17 +1004,17 @@ xloadfonts(char *fontstr, double fontsize)
|
|||||||
FcPatternDel(pattern, FC_SLANT);
|
FcPatternDel(pattern, FC_SLANT);
|
||||||
FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
|
FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
|
||||||
if (xloadfont(&dc.ifont, pattern))
|
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);
|
FcPatternDel(pattern, FC_WEIGHT);
|
||||||
FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
|
FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
|
||||||
if (xloadfont(&dc.ibfont, pattern))
|
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);
|
FcPatternDel(pattern, FC_SLANT);
|
||||||
FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ROMAN);
|
FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ROMAN);
|
||||||
if (xloadfont(&dc.bfont, pattern))
|
if (xloadfont(&dc.bfont, pattern))
|
||||||
die("st: can't open font %s\n", fontstr);
|
die("can't open font %s\n", fontstr);
|
||||||
|
|
||||||
FcPatternDestroy(pattern);
|
FcPatternDestroy(pattern);
|
||||||
}
|
}
|
||||||
@ -993,6 +1041,60 @@ xunloadfonts(void)
|
|||||||
xunloadfont(&dc.ibfont);
|
xunloadfont(&dc.ibfont);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ximopen(Display *dpy)
|
||||||
|
{
|
||||||
|
XIMCallback imdestroy = { .client_data = NULL, .callback = ximdestroy };
|
||||||
|
XICCallback icdestroy = { .client_data = NULL, .callback = xicdestroy };
|
||||||
|
|
||||||
|
xw.ime.xim = XOpenIM(xw.dpy, NULL, NULL, NULL);
|
||||||
|
if (xw.ime.xim == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (XSetIMValues(xw.ime.xim, XNDestroyCallback, &imdestroy, NULL))
|
||||||
|
fprintf(stderr, "XSetIMValues: "
|
||||||
|
"Could not set XNDestroyCallback.\n");
|
||||||
|
|
||||||
|
xw.ime.spotlist = XVaCreateNestedList(0, XNSpotLocation, &xw.ime.spot,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
if (xw.ime.xic == NULL) {
|
||||||
|
xw.ime.xic = XCreateIC(xw.ime.xim, XNInputStyle,
|
||||||
|
XIMPreeditNothing | XIMStatusNothing,
|
||||||
|
XNClientWindow, xw.win,
|
||||||
|
XNDestroyCallback, &icdestroy,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
if (xw.ime.xic == NULL)
|
||||||
|
fprintf(stderr, "XCreateIC: Could not create input context.\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ximinstantiate(Display *dpy, XPointer client, XPointer call)
|
||||||
|
{
|
||||||
|
if (ximopen(dpy))
|
||||||
|
XUnregisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
|
||||||
|
ximinstantiate, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ximdestroy(XIM xim, XPointer client, XPointer call)
|
||||||
|
{
|
||||||
|
xw.ime.xim = NULL;
|
||||||
|
XRegisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
|
||||||
|
ximinstantiate, NULL);
|
||||||
|
XFree(xw.ime.spotlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
xicdestroy(XIC xim, XPointer client, XPointer call)
|
||||||
|
{
|
||||||
|
xw.ime.xic = NULL;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
xinit(int cols, int rows)
|
xinit(int cols, int rows)
|
||||||
{
|
{
|
||||||
@ -1003,13 +1105,13 @@ xinit(int cols, int rows)
|
|||||||
XColor xmousefg, xmousebg;
|
XColor xmousefg, xmousebg;
|
||||||
|
|
||||||
if (!(xw.dpy = XOpenDisplay(NULL)))
|
if (!(xw.dpy = XOpenDisplay(NULL)))
|
||||||
die("Can't open display\n");
|
die("can't open display\n");
|
||||||
xw.scr = XDefaultScreen(xw.dpy);
|
xw.scr = XDefaultScreen(xw.dpy);
|
||||||
xw.vis = XDefaultVisual(xw.dpy, xw.scr);
|
xw.vis = XDefaultVisual(xw.dpy, xw.scr);
|
||||||
|
|
||||||
/* font */
|
/* font */
|
||||||
if (!FcInit())
|
if (!FcInit())
|
||||||
die("Could not init fontconfig.\n");
|
die("could not init fontconfig.\n");
|
||||||
|
|
||||||
usedfont = (opt_font == NULL)? font : opt_font;
|
usedfont = (opt_font == NULL)? font : opt_font;
|
||||||
xloadfonts(usedfont, 0);
|
xloadfonts(usedfont, 0);
|
||||||
@ -1030,7 +1132,7 @@ xinit(int cols, int rows)
|
|||||||
xw.attrs.background_pixel = dc.col[defaultbg].pixel;
|
xw.attrs.background_pixel = dc.col[defaultbg].pixel;
|
||||||
xw.attrs.border_pixel = dc.col[defaultbg].pixel;
|
xw.attrs.border_pixel = dc.col[defaultbg].pixel;
|
||||||
xw.attrs.bit_gravity = NorthWestGravity;
|
xw.attrs.bit_gravity = NorthWestGravity;
|
||||||
xw.attrs.event_mask = FocusChangeMask | KeyPressMask
|
xw.attrs.event_mask = FocusChangeMask | KeyPressMask | KeyReleaseMask
|
||||||
| ExposureMask | VisibilityChangeMask | StructureNotifyMask
|
| ExposureMask | VisibilityChangeMask | StructureNotifyMask
|
||||||
| ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
|
| ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
|
||||||
xw.attrs.colormap = xw.cmap;
|
xw.attrs.colormap = xw.cmap;
|
||||||
@ -1058,22 +1160,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 */
|
||||||
if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
|
if (!ximopen(xw.dpy)) {
|
||||||
XSetLocaleModifiers("@im=local");
|
XRegisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
|
||||||
if ((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
|
ximinstantiate, NULL);
|
||||||
XSetLocaleModifiers("@im=");
|
|
||||||
if ((xw.xim = XOpenIM(xw.dpy,
|
|
||||||
NULL, NULL, NULL)) == NULL) {
|
|
||||||
die("XOpenIM failed. Could not open input"
|
|
||||||
" device.\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
xw.xic = XCreateIC(xw.xim, XNInputStyle, XIMPreeditNothing
|
|
||||||
| XIMStatusNothing, XNClientWindow, xw.win,
|
|
||||||
XNFocusWindow, xw.win, NULL);
|
|
||||||
if (xw.xic == NULL)
|
|
||||||
die("XCreateIC failed. Could not obtain input method.\n");
|
|
||||||
|
|
||||||
/* white cursor, black outline */
|
/* white cursor, black outline */
|
||||||
cursor = XCreateFontCursor(xw.dpy, mouseshape);
|
cursor = XCreateFontCursor(xw.dpy, mouseshape);
|
||||||
@ -1104,8 +1194,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);
|
||||||
@ -1215,13 +1305,10 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x
|
|||||||
fontpattern = FcFontSetMatch(0, fcsets, 1,
|
fontpattern = FcFontSetMatch(0, fcsets, 1,
|
||||||
fcpattern, &fcres);
|
fcpattern, &fcres);
|
||||||
|
|
||||||
/*
|
/* Allocate memory for the new cache entry. */
|
||||||
* Overwrite or create the new cache entry.
|
if (frclen >= frccap) {
|
||||||
*/
|
frccap += 16;
|
||||||
if (frclen >= LEN(frc)) {
|
frc = xrealloc(frc, frccap * sizeof(Fontcache));
|
||||||
frclen = LEN(frc) - 1;
|
|
||||||
XftFontClose(xw.dpy, frc[frclen].font);
|
|
||||||
frc[frclen].unicodep = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
frc[frclen].font = XftFontOpenPattern(xw.dpy,
|
frc[frclen].font = XftFontOpenPattern(xw.dpy,
|
||||||
@ -1551,6 +1638,18 @@ xfinishdraw(void)
|
|||||||
defaultfg : defaultbg].pixel);
|
defaultfg : defaultbg].pixel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
xximspot(int x, int y)
|
||||||
|
{
|
||||||
|
if (xw.ime.xic == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
xw.ime.spot.x = borderpx + x * win.cw;
|
||||||
|
xw.ime.spot.y = borderpx + (y + 1) * win.ch;
|
||||||
|
|
||||||
|
XSetICValues(xw.ime.xic, XNPreeditAttributes, xw.ime.spotlist, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
expose(XEvent *ev)
|
expose(XEvent *ev)
|
||||||
{
|
{
|
||||||
@ -1625,13 +1724,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);
|
||||||
@ -1686,7 +1787,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;
|
||||||
@ -1695,7 +1796,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)) {
|
||||||
@ -1728,7 +1832,6 @@ kpress(XEvent *ev)
|
|||||||
ttywrite(buf, len, 1);
|
ttywrite(buf, len, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
cmessage(XEvent *e)
|
cmessage(XEvent *e)
|
||||||
{
|
{
|
||||||
@ -1925,7 +2028,7 @@ main(int argc, char *argv[])
|
|||||||
opt_embed = EARGF(usage());
|
opt_embed = EARGF(usage());
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
die("%s " VERSION " (c) 2010-2016 st engineers\n", argv0);
|
die("%s " VERSION "\n", argv0);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
|
Reference in New Issue
Block a user