Compare commits
149 Commits
0.8
...
patch-clic
Author | SHA1 | Date | |
---|---|---|---|
b1e6c91433 | |||
98610fcd37 | |||
6009e6e25b | |||
a0274bc20e | |||
5dbcca4926 | |||
d63b9eb902 | |||
497a756382 | |||
8c68ec5241 | |||
5ce9716281 | |||
f20e169a20 | |||
95f22c5305 | |||
7473a8d1a5 | |||
a3f7420310 | |||
9846a56bd7 | |||
559fdc2786 | |||
8abe4bcb41 | |||
2fc7e532b2 | |||
a6bbc0c96b | |||
eb3b894f40 | |||
3a6d6d7401 | |||
211964d56e | |||
f17abd25b3 | |||
7e8050cc62 | |||
e5e959835b | |||
68d1ad9b54 | |||
0008519903 | |||
72fd32736a | |||
baa9357e96 | |||
8629d9a1da | |||
ef0551932f | |||
af3bb68add | |||
2aefa348ba | |||
e823e2308f | |||
2c5edf28ec | |||
b1d97fec47 | |||
ea7cd7b62f | |||
7fb0c0cc68 | |||
7e1c68f25d | |||
65f1dc4283 | |||
a0467c802d | |||
273db5ceaf | |||
8e31030390 | |||
2f6e597ed8 | |||
1d3142da96 | |||
2ec571a30c | |||
4536f46cff | |||
9e68fdbcdb | |||
4ef0cbd8b9 | |||
28b4c822c5 | |||
fa253f077f | |||
b27a383a3a | |||
81067c65ea | |||
f74a9df6e1 | |||
818ec746f4 | |||
9ba7ecf7b1 | |||
a2a704492b | |||
0f8b40652b | |||
e6e2c6199f | |||
94b8ec0021 | |||
dec6b530a4 | |||
475a0a36cb | |||
e8392b282c | |||
f8afebdfa0 | |||
bda9c9ffa6 | |||
045a0fab4f | |||
9c30066e73 | |||
8304d4f059 | |||
914fb825df | |||
cde480c693 | |||
8211e36d28 | |||
87545c612e | |||
1d59091065 | |||
d6ea0a1a61 | |||
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 | |||
6f0f2b7ec3 | |||
f4020b2cc4 | |||
a5a928bfc1 | |||
6ac8c8aa50 | |||
5345db3c9b | |||
7648697f71 | |||
0b507bb731 | |||
e7ef3c4ce9 |
110
FAQ
110
FAQ
@ -1,6 +1,7 @@
|
|||||||
## 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!
|
||||||
|
|
||||||
@ -8,6 +9,7 @@ It means that st doesn’t have any terminfo entry on your system. Chances are
|
|||||||
you did not `make install`. If you just want to test it without installing it,
|
you did not `make install`. If you just want to test it without installing it,
|
||||||
you can manually run `tic -sx st.info`.
|
you can manually run `tic -sx st.info`.
|
||||||
|
|
||||||
|
|
||||||
## Nothing works, and nothing is said about an unknown terminal!
|
## Nothing works, and nothing is said about an unknown terminal!
|
||||||
|
|
||||||
* Some programs just assume they’re running in xterm i.e. they don’t rely on
|
* Some programs just assume they’re running in xterm i.e. they don’t rely on
|
||||||
@ -15,19 +17,21 @@ 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/).
|
||||||
|
|
||||||
|
|
||||||
|
## I would like to have utmp and/or scroll functionality by default
|
||||||
|
|
||||||
|
You can add the absolute path of both programs in your config.h file. You only
|
||||||
|
have to modify the value of utmp and scroll variables.
|
||||||
|
|
||||||
* `st -e tmux` using C-b [
|
|
||||||
* `st -e screen` using C-a ESC
|
|
||||||
|
|
||||||
## Why doesn't the Del key work in some programs?
|
## Why doesn't the Del key work in some programs?
|
||||||
|
|
||||||
@ -84,12 +88,14 @@ If you are using zsh, then read the zsh FAQ
|
|||||||
|
|
||||||
Putting these lines into your .zshrc will fix the problems.
|
Putting these lines into your .zshrc will fix the problems.
|
||||||
|
|
||||||
|
|
||||||
## How can I use meta in 8bit mode?
|
## How can I use meta in 8bit mode?
|
||||||
|
|
||||||
St supports meta in 8bit mode, but the default terminfo entry doesn't
|
St supports meta in 8bit mode, but the default terminfo entry doesn't
|
||||||
use this capability. If you want it, you have to use the 'st-meta' value
|
use this capability. If you want it, you have to use the 'st-meta' value
|
||||||
in TERM.
|
in TERM.
|
||||||
|
|
||||||
|
|
||||||
## I cannot compile st in OpenBSD
|
## I cannot compile st in OpenBSD
|
||||||
|
|
||||||
OpenBSD lacks librt, despite it being mandatory in POSIX
|
OpenBSD lacks librt, despite it being mandatory in POSIX
|
||||||
@ -98,13 +104,14 @@ If you want to compile st for OpenBSD you have to remove -lrt from config.mk, an
|
|||||||
st will compile without any loss of functionality, because all the functions are
|
st will compile without any loss of functionality, because all the functions are
|
||||||
included in libc on this platform.
|
included in libc on this platform.
|
||||||
|
|
||||||
|
|
||||||
## The Backspace Case
|
## The Backspace Case
|
||||||
|
|
||||||
St is emulating the Linux way of handling backspace being delete and delete being
|
St is emulating the Linux way of handling backspace being delete and delete being
|
||||||
backspace.
|
backspace.
|
||||||
|
|
||||||
This is an issue that was discussed in suckless mailing list
|
This is an issue that was discussed in suckless mailing list
|
||||||
<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
|
||||||
@ -159,9 +166,88 @@ terminal users wants its backspace to be how he feels it:
|
|||||||
[1] http://www.ibb.net/~anne/keyboard.html
|
[1] http://www.ibb.net/~anne/keyboard.html
|
||||||
[2] http://www.tldp.org/HOWTO/Keyboard-and-Console-HOWTO-5.html
|
[2] http://www.tldp.org/HOWTO/Keyboard-and-Console-HOWTO-5.html
|
||||||
|
|
||||||
|
|
||||||
## But I really want the old grumpy behaviour of my terminal
|
## But I really want the old grumpy behaviour of my terminal
|
||||||
|
|
||||||
Apply [1].
|
Apply [1].
|
||||||
|
|
||||||
[1] http://st.suckless.org/patches/delkey
|
[1] https://st.suckless.org/patches/delkey
|
||||||
|
|
||||||
|
|
||||||
|
## Why do images not work in st using the w3m image hack?
|
||||||
|
|
||||||
|
w3mimg uses a hack that draws an image on top of the terminal emulator Drawable
|
||||||
|
window. The hack relies on the terminal to use a single buffer to draw its
|
||||||
|
contents directly.
|
||||||
|
|
||||||
|
st uses double-buffered drawing so the image is quickly replaced and may show a
|
||||||
|
short flicker effect.
|
||||||
|
|
||||||
|
Below is a patch example to change st double-buffering to a single Drawable
|
||||||
|
buffer.
|
||||||
|
|
||||||
|
diff --git a/x.c b/x.c
|
||||||
|
--- a/x.c
|
||||||
|
+++ b/x.c
|
||||||
|
@@ -732,10 +732,6 @@ xresize(int col, int row)
|
||||||
|
win.tw = col * win.cw;
|
||||||
|
win.th = row * win.ch;
|
||||||
|
|
||||||
|
- XFreePixmap(xw.dpy, xw.buf);
|
||||||
|
- xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
|
||||||
|
- DefaultDepth(xw.dpy, xw.scr));
|
||||||
|
- XftDrawChange(xw.draw, xw.buf);
|
||||||
|
xclear(0, 0, win.w, win.h);
|
||||||
|
|
||||||
|
/* resize to new width */
|
||||||
|
@@ -1148,8 +1144,7 @@ xinit(int cols, int rows)
|
||||||
|
gcvalues.graphics_exposures = False;
|
||||||
|
dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures,
|
||||||
|
&gcvalues);
|
||||||
|
- xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
|
||||||
|
- DefaultDepth(xw.dpy, xw.scr));
|
||||||
|
+ xw.buf = xw.win;
|
||||||
|
XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel);
|
||||||
|
XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h);
|
||||||
|
|
||||||
|
@@ -1632,8 +1627,6 @@ xdrawline(Line line, int x1, int y1, int x2)
|
||||||
|
void
|
||||||
|
xfinishdraw(void)
|
||||||
|
{
|
||||||
|
- XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, win.w,
|
||||||
|
- win.h, 0, 0);
|
||||||
|
XSetForeground(xw.dpy, dc.gc,
|
||||||
|
dc.col[IS_SET(MODE_REVERSE)?
|
||||||
|
defaultfg : defaultbg].pixel);
|
||||||
|
|
||||||
|
|
||||||
|
## BadLength X error in Xft when trying to render emoji
|
||||||
|
|
||||||
|
Xft makes st crash when rendering color emojis with the following error:
|
||||||
|
|
||||||
|
"X Error of failed request: BadLength (poly request too large or internal Xlib length error)"
|
||||||
|
Major opcode of failed request: 139 (RENDER)
|
||||||
|
Minor opcode of failed request: 20 (RenderAddGlyphs)
|
||||||
|
Serial number of failed request: 1595
|
||||||
|
Current serial number in output stream: 1818"
|
||||||
|
|
||||||
|
This is a known bug in Xft (not st) which happens on some platforms and
|
||||||
|
combination of particular fonts and fontconfig settings.
|
||||||
|
|
||||||
|
See also:
|
||||||
|
https://gitlab.freedesktop.org/xorg/lib/libxft/issues/6
|
||||||
|
https://bugs.freedesktop.org/show_bug.cgi?id=107534
|
||||||
|
https://bugzilla.redhat.com/show_bug.cgi?id=1498269
|
||||||
|
|
||||||
|
The solution is to remove color emoji fonts or disable this in the fontconfig
|
||||||
|
XML configuration. As an ugly workaround (which may work only on newer
|
||||||
|
fontconfig versions (FC_COLOR)), the following code can be used to mask color
|
||||||
|
fonts:
|
||||||
|
|
||||||
|
FcPatternAddBool(fcpattern, FC_COLOR, FcFalse);
|
||||||
|
|
||||||
|
Please don't bother reporting this bug to st, but notify the upstream Xft
|
||||||
|
developers about fixing this bug.
|
||||||
|
|
||||||
|
As of 2022-09-05 this now seems to be finally fixed in libXft 2.3.5:
|
||||||
|
https://gitlab.freedesktop.org/xorg/lib/libxft/-/blob/libXft-2.3.5/NEWS
|
||||||
|
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
|||||||
MIT/X Consortium License
|
MIT/X Consortium License
|
||||||
|
|
||||||
© 2014-2018 Hiltjo Posthuma <hiltjo at codemadness dot org>
|
© 2014-2022 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>
|
||||||
|
12
Makefile
12
Makefile
@ -7,13 +7,7 @@ include config.mk
|
|||||||
SRC = st.c x.c
|
SRC = st.c x.c
|
||||||
OBJ = $(SRC:.c=.o)
|
OBJ = $(SRC:.c=.o)
|
||||||
|
|
||||||
all: options st
|
all: st
|
||||||
|
|
||||||
options:
|
|
||||||
@echo st build options:
|
|
||||||
@echo "CFLAGS = $(STCFLAGS)"
|
|
||||||
@echo "LDFLAGS = $(STLDFLAGS)"
|
|
||||||
@echo "CC = $(CC)"
|
|
||||||
|
|
||||||
config.h:
|
config.h:
|
||||||
cp config.def.h config.h
|
cp config.def.h config.h
|
||||||
@ -22,7 +16,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
|
||||||
|
|
||||||
@ -54,4 +48,4 @@ uninstall:
|
|||||||
rm -f $(DESTDIR)$(PREFIX)/bin/st
|
rm -f $(DESTDIR)$(PREFIX)/bin/st
|
||||||
rm -f $(DESTDIR)$(MANPREFIX)/man1/st.1
|
rm -f $(DESTDIR)$(MANPREFIX)/man1/st.1
|
||||||
|
|
||||||
.PHONY: all options clean dist install uninstall
|
.PHONY: all clean dist install uninstall
|
||||||
|
22
arg.h
22
arg.h
@ -21,28 +21,30 @@ extern char *argv0;
|
|||||||
argc--;\
|
argc--;\
|
||||||
break;\
|
break;\
|
||||||
}\
|
}\
|
||||||
for (brk_ = 0, argv[0]++, argv_ = argv;\
|
int i_;\
|
||||||
argv[0][0] && !brk_;\
|
for (i_ = 1, brk_ = 0, argv_ = argv;\
|
||||||
argv[0]++) {\
|
argv[0][i_] && !brk_;\
|
||||||
|
i_++) {\
|
||||||
if (argv_ != argv)\
|
if (argv_ != argv)\
|
||||||
break;\
|
break;\
|
||||||
argc_ = argv[0][0];\
|
argc_ = argv[0][i_];\
|
||||||
switch (argc_)
|
switch (argc_)
|
||||||
|
|
||||||
#define ARGEND }\
|
#define ARGEND }\
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ARGC() argc_
|
#define ARGC() argc_
|
||||||
|
|
||||||
#define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\
|
#define EARGF(x) ((argv[0][i_+1] == '\0' && argv[1] == NULL)?\
|
||||||
((x), abort(), (char *)0) :\
|
((x), abort(), (char *)0) :\
|
||||||
(brk_ = 1, (argv[0][1] != '\0')?\
|
(brk_ = 1, (argv[0][i_+1] != '\0')?\
|
||||||
(&argv[0][1]) :\
|
(&argv[0][i_+1]) :\
|
||||||
(argc--, argv++, argv[0])))
|
(argc--, argv++, argv[0])))
|
||||||
|
|
||||||
#define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\
|
#define ARGF() ((argv[0][i_+1] == '\0' && argv[1] == NULL)?\
|
||||||
(char *)0 :\
|
(char *)0 :\
|
||||||
(brk_ = 1, (argv[0][1] != '\0')?\
|
(brk_ = 1, (argv[0][i_+1] != '\0')?\
|
||||||
(&argv[0][1]) :\
|
(&argv[0][i_+1]) :\
|
||||||
(argc--, argv++, argv[0])))
|
(argc--, argv++, argv[0])))
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
71
config.def.h
71
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;
|
||||||
@ -41,9 +43,18 @@ static unsigned int tripleclicktimeout = 600;
|
|||||||
/* alt screens */
|
/* alt screens */
|
||||||
int allowaltscreen = 1;
|
int allowaltscreen = 1;
|
||||||
|
|
||||||
/* frames per second st should at maximum draw to the screen */
|
/* allow certain non-interactive (insecure) window operations such as:
|
||||||
static unsigned int xfps = 120;
|
setting the clipboard text */
|
||||||
static unsigned int actionfps = 30;
|
int allowwindowops = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* draw latency range in ms - from new content/keypress/etc until drawing.
|
||||||
|
* within this range, st draws when content stops arriving (idle). mostly it's
|
||||||
|
* near minlatency, but it waits longer for slow updates to avoid partial draw.
|
||||||
|
* low minlatency will tear/flicker more, as it can "detect" idle too early.
|
||||||
|
*/
|
||||||
|
static double minlatency = 2;
|
||||||
|
static double maxlatency = 33;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* blinking timeout (set to 0 to disable blinking) for the terminal blinking
|
* blinking timeout (set to 0 to disable blinking) for the terminal blinking
|
||||||
@ -109,6 +120,8 @@ static const char *colorname[] = {
|
|||||||
/* more colors can be added after 255 to use with DefaultXX */
|
/* more colors can be added after 255 to use with DefaultXX */
|
||||||
"#cccccc",
|
"#cccccc",
|
||||||
"#555555",
|
"#555555",
|
||||||
|
"gray90", /* default foreground colour */
|
||||||
|
"black", /* default background colour */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -116,9 +129,9 @@ static const char *colorname[] = {
|
|||||||
* Default colors (colorname index)
|
* Default colors (colorname index)
|
||||||
* foreground, background, cursor, reverse cursor
|
* foreground, background, cursor, reverse cursor
|
||||||
*/
|
*/
|
||||||
unsigned int defaultfg = 7;
|
unsigned int defaultfg = 258;
|
||||||
unsigned int defaultbg = 0;
|
unsigned int defaultbg = 259;
|
||||||
static unsigned int defaultcs = 256;
|
unsigned int defaultcs = 256;
|
||||||
static unsigned int defaultrcs = 257;
|
static unsigned int defaultrcs = 257;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -150,14 +163,24 @@ 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" },
|
{ 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. */
|
||||||
@ -176,8 +199,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 +218,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 +236,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.
|
||||||
@ -460,3 +472,14 @@ static char ascii_printable[] =
|
|||||||
" !\"#$%&'()*+,-./0123456789:;<=>?"
|
" !\"#$%&'()*+,-./0123456789:;<=>?"
|
||||||
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
|
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
|
||||||
"`abcdefghijklmnopqrstuvwxyz{|}~";
|
"`abcdefghijklmnopqrstuvwxyz{|}~";
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Open urls starting with urlprefixes, contatining urlchars
|
||||||
|
* by passing as ARG1 to urlhandler.
|
||||||
|
*/
|
||||||
|
char* urlhandler = "xdg-open";
|
||||||
|
char urlchars[] =
|
||||||
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
|
"abcdefghijklmnopqrstuvwxyz"
|
||||||
|
"0123456789-._~:/?#@!$&'*+,;=%";
|
||||||
|
char* urlprefixes[] = {"http://", "https://", NULL};
|
||||||
|
24
config.mk
24
config.mk
@ -1,5 +1,5 @@
|
|||||||
# st version
|
# st version
|
||||||
VERSION = 0.8
|
VERSION = 0.9.2
|
||||||
|
|
||||||
# Customize below to fit your system
|
# Customize below to fit your system
|
||||||
|
|
||||||
@ -10,19 +10,27 @@ 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`
|
||||||
|
#MANPREFIX = ${PREFIX}/man
|
||||||
|
|
||||||
# compiler and linker
|
# compiler and linker
|
||||||
# CC = c99
|
# CC = c99
|
||||||
|
|
||||||
|
192
patches/st-clickurl-0.8.5.diff
Normal file
192
patches/st-clickurl-0.8.5.diff
Normal file
@ -0,0 +1,192 @@
|
|||||||
|
From d5b492049f48dc411b0dd7dc01a403304c20438d Mon Sep 17 00:00:00 2001
|
||||||
|
From: Jishnu Sen <jishnu1@gmail.com>
|
||||||
|
Date: Sun, 7 Apr 2024 22:54:46 -0700
|
||||||
|
Subject: [PATCH] Highlight URLs with control and follow with click
|
||||||
|
|
||||||
|
---
|
||||||
|
config.def.h | 11 +++++++
|
||||||
|
st.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
st.h | 9 ++++++
|
||||||
|
x.c | 24 +++++++++++++-
|
||||||
|
4 files changed, 132 insertions(+), 1 deletion(-)
|
||||||
|
|
||||||
|
diff --git a/config.def.h b/config.def.h
|
||||||
|
index 91ab8ca..4961830 100644
|
||||||
|
--- a/config.def.h
|
||||||
|
+++ b/config.def.h
|
||||||
|
@@ -472,3 +472,14 @@ static char ascii_printable[] =
|
||||||
|
" !\"#$%&'()*+,-./0123456789:;<=>?"
|
||||||
|
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
|
||||||
|
"`abcdefghijklmnopqrstuvwxyz{|}~";
|
||||||
|
+
|
||||||
|
+/*
|
||||||
|
+ * Open urls starting with urlprefixes, contatining urlchars
|
||||||
|
+ * by passing as ARG1 to urlhandler.
|
||||||
|
+ */
|
||||||
|
+char* urlhandler = "xdg-open";
|
||||||
|
+char urlchars[] =
|
||||||
|
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
|
+ "abcdefghijklmnopqrstuvwxyz"
|
||||||
|
+ "0123456789-._~:/?#@!$&'*+,;=%";
|
||||||
|
+char* urlprefixes[] = {"http://", "https://", NULL};
|
||||||
|
diff --git a/st.c b/st.c
|
||||||
|
index 51049ba..8f2156c 100644
|
||||||
|
--- a/st.c
|
||||||
|
+++ b/st.c
|
||||||
|
@@ -643,6 +643,95 @@ getsel(void)
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
+char *
|
||||||
|
+strstrany(char* s, char** strs) {
|
||||||
|
+ char *match;
|
||||||
|
+ for (int i = 0; strs[i]; i++) {
|
||||||
|
+ if ((match = strstr(s, strs[i]))) {
|
||||||
|
+ return match;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ return NULL;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+void
|
||||||
|
+highlighturls(void)
|
||||||
|
+{
|
||||||
|
+ char *match;
|
||||||
|
+ char *linestr = calloc(sizeof(char), term.col+1); /* assume ascii */
|
||||||
|
+ for (int i = term.top; i < term.bot; i++) {
|
||||||
|
+ int url_start = -1;
|
||||||
|
+ for (int j = 0; j < term.col; j++) {
|
||||||
|
+ if (term.line[i][j].u < 127) {
|
||||||
|
+ linestr[j] = term.line[i][j].u;
|
||||||
|
+ }
|
||||||
|
+ linestr[term.col] = '\0';
|
||||||
|
+ }
|
||||||
|
+ while ((match = strstrany(linestr + url_start + 1, urlprefixes))) {
|
||||||
|
+ url_start = match - linestr;
|
||||||
|
+ for (int c = url_start; c < term.col && strchr(urlchars, linestr[c]); c++) {
|
||||||
|
+ term.line[i][c].mode |= ATTR_URL;
|
||||||
|
+ tsetdirt(i, c);
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ free(linestr);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+void
|
||||||
|
+unhighlighturls(void)
|
||||||
|
+{
|
||||||
|
+ for (int i = term.top; i < term.bot; i++) {
|
||||||
|
+ for (int j = 0; j < term.col; j++) {
|
||||||
|
+ Glyph* g = &term.line[i][j];
|
||||||
|
+ if (g->mode & ATTR_URL) {
|
||||||
|
+ g->mode &= ~ATTR_URL;
|
||||||
|
+ tsetdirt(i, j);
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ return;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+void
|
||||||
|
+followurl(int x, int y) {
|
||||||
|
+ char *linestr = calloc(sizeof(char), term.col+1); /* assume ascii */
|
||||||
|
+ char *match;
|
||||||
|
+ for (int i = 0; i < term.col; i++) {
|
||||||
|
+ if (term.line[x][i].u < 127) {
|
||||||
|
+ linestr[i] = term.line[x][i].u;
|
||||||
|
+ }
|
||||||
|
+ linestr[term.col] = '\0';
|
||||||
|
+ }
|
||||||
|
+ int url_start = -1;
|
||||||
|
+ while ((match = strstrany(linestr + url_start + 1, urlprefixes))) {
|
||||||
|
+ url_start = match - linestr;
|
||||||
|
+ int url_end = url_start;
|
||||||
|
+ for (int c = url_start; c < term.col && strchr(urlchars, linestr[c]); c++) {
|
||||||
|
+ url_end++;
|
||||||
|
+ }
|
||||||
|
+ if (url_start <= y && y < url_end) {
|
||||||
|
+ linestr[url_end] = '\0';
|
||||||
|
+ break;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ if (url_start == -1) {
|
||||||
|
+ free(linestr);
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ pid_t chpid;
|
||||||
|
+ if ((chpid = fork()) == 0) {
|
||||||
|
+ if (fork() == 0)
|
||||||
|
+ execlp(urlhandler, urlhandler, linestr + url_start, NULL);
|
||||||
|
+ exit(1);
|
||||||
|
+ }
|
||||||
|
+ if (chpid > 0)
|
||||||
|
+ waitpid(chpid, NULL, 0);
|
||||||
|
+ free(linestr);
|
||||||
|
+ unhighlighturls();
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
void
|
||||||
|
selclear(void)
|
||||||
|
{
|
||||||
|
diff --git a/st.h b/st.h
|
||||||
|
index 519b9bd..354e7f9 100644
|
||||||
|
--- a/st.h
|
||||||
|
+++ b/st.h
|
||||||
|
@@ -34,6 +34,7 @@ enum glyph_attribute {
|
||||||
|
ATTR_WIDE = 1 << 9,
|
||||||
|
ATTR_WDUMMY = 1 << 10,
|
||||||
|
ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
|
||||||
|
+ ATTR_URL = 1 << 14,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum selection_mode {
|
||||||
|
@@ -105,6 +106,10 @@ void selextend(int, int, int, int);
|
||||||
|
int selected(int, int);
|
||||||
|
char *getsel(void);
|
||||||
|
|
||||||
|
+void highlighturls(void);
|
||||||
|
+void unhighlighturls(void);
|
||||||
|
+void followurl(int, int);
|
||||||
|
+
|
||||||
|
size_t utf8encode(Rune, char *);
|
||||||
|
|
||||||
|
void *xmalloc(size_t);
|
||||||
|
@@ -126,3 +131,7 @@ extern unsigned int tabspaces;
|
||||||
|
extern unsigned int defaultfg;
|
||||||
|
extern unsigned int defaultbg;
|
||||||
|
extern unsigned int defaultcs;
|
||||||
|
+extern char *urlhandler;
|
||||||
|
+extern char urlchars[];
|
||||||
|
+extern char *urlprefixes[];
|
||||||
|
+extern int nurlprefixes;
|
||||||
|
diff --git a/x.c b/x.c
|
||||||
|
index 8a16faa..13f68e4 100644
|
||||||
|
--- a/x.c
|
||||||
|
+++ b/x.c
|
||||||
|
@@ -191,6 +191,7 @@ static void usage(void);
|
||||||
|
|
||||||
|
static void (*handler[LASTEvent])(XEvent *) = {
|
||||||
|
[KeyPress] = kpress,
|
||||||
|
+ [KeyRelease] = kpress,
|
||||||
|
[ClientMessage] = cmessage,
|
||||||
|
[ConfigureNotify] = resize,
|
||||||
|
[VisibilityNotify] = visibility,
|
||||||
|
@@ -445,6 +446,15 @@ mouseaction(XEvent *e, uint release)
|
||||||
|
/* ignore Button<N>mask for Button<N> - it's set on release */
|
||||||
|
uint state = e->xbutton.state & ~buttonmask(e->xbutton.button);
|
||||||
|
|
||||||
|
+ if (release == 0 &&
|
||||||
|
+ e->xbutton.button == Button1 &&
|
||||||
|
+ (match(ControlMask, state) ||
|
||||||
|
+ match(ControlMask, state & ~forcemousemod))) {
|
||||||
|
+ followurl(evrow(e), evcol(e));
|
||||||
|
+ return 1;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+
|
||||||
|
for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) {
|
||||||
|
if (ms->release == release &&
|
||||||
|
ms->button == e->xbutton.button &&
|
||||||
|
2.44.0
|
||||||
|
|
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.
|
||||||
|
|
||||||
|
20
st.h
20
st.h
@ -34,6 +34,7 @@ enum glyph_attribute {
|
|||||||
ATTR_WIDE = 1 << 9,
|
ATTR_WIDE = 1 << 9,
|
||||||
ATTR_WDUMMY = 1 << 10,
|
ATTR_WDUMMY = 1 << 10,
|
||||||
ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
|
ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
|
||||||
|
ATTR_URL = 1 << 14,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum selection_mode {
|
enum selection_mode {
|
||||||
@ -74,13 +75,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 *);
|
||||||
@ -91,7 +92,7 @@ void tnew(int, int);
|
|||||||
void tresize(int, int);
|
void tresize(int, int);
|
||||||
void tsetdirtattr(int);
|
void tsetdirtattr(int);
|
||||||
void ttyhangup(void);
|
void ttyhangup(void);
|
||||||
int ttynew(char *, char *, char *, char **);
|
int ttynew(const char *, char *, const char *, char **);
|
||||||
size_t ttyread(void);
|
size_t ttyread(void);
|
||||||
void ttyresize(int, int);
|
void ttyresize(int, int);
|
||||||
void ttywrite(const char *, size_t, int);
|
void ttywrite(const char *, size_t, int);
|
||||||
@ -105,19 +106,30 @@ void selextend(int, int, int, int);
|
|||||||
int selected(int, int);
|
int selected(int, int);
|
||||||
char *getsel(void);
|
char *getsel(void);
|
||||||
|
|
||||||
|
void highlighturls(void);
|
||||||
|
void unhighlighturls(void);
|
||||||
|
void followurl(int, int);
|
||||||
|
|
||||||
size_t utf8encode(Rune, char *);
|
size_t utf8encode(Rune, char *);
|
||||||
|
|
||||||
void *xmalloc(size_t);
|
void *xmalloc(size_t);
|
||||||
void *xrealloc(void *, size_t);
|
void *xrealloc(void *, size_t);
|
||||||
char *xstrdup(char *);
|
char *xstrdup(const 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 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 char *urlhandler;
|
||||||
|
extern char urlchars[];
|
||||||
|
extern char *urlprefixes[];
|
||||||
|
extern int nurlprefixes;
|
||||||
|
41
st.info
41
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,
|
||||||
@ -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,11 +184,26 @@ st| simpleterm,
|
|||||||
# XTerm extensions
|
# XTerm extensions
|
||||||
rmxx=\E[29m,
|
rmxx=\E[29m,
|
||||||
smxx=\E[9m,
|
smxx=\E[9m,
|
||||||
|
BE=\E[?2004h,
|
||||||
|
BD=\E[?2004l,
|
||||||
|
PS=\E[200~,
|
||||||
|
PE=\E[201~,
|
||||||
|
# disabled rep for now: causes some issues with older ncurses versions.
|
||||||
|
# rep=%p1%c\E[%p2%{1}%-%db,
|
||||||
# tmux extensions, see TERMINFO EXTENSIONS in tmux(1)
|
# tmux extensions, see TERMINFO EXTENSIONS in tmux(1)
|
||||||
Se,
|
|
||||||
Ss,
|
|
||||||
Tc,
|
Tc,
|
||||||
Ms=\E]52;%p1%s;%p2%s\007,
|
Ms=\E]52;%p1%s;%p2%s\007,
|
||||||
|
Se=\E[2 q,
|
||||||
|
Ss=\E[%p1%d q,
|
||||||
|
|
||||||
|
st| simpleterm,
|
||||||
|
use=st-mono,
|
||||||
|
colors#8,
|
||||||
|
setab=\E[4%p1%dm,
|
||||||
|
setaf=\E[3%p1%dm,
|
||||||
|
setb=\E[4%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m,
|
||||||
|
setf=\E[3%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m,
|
||||||
|
sgr=%?%p9%t\E(0%e\E(B%;\E[0%?%p6%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;%?%p7%t;8%;m,
|
||||||
|
|
||||||
st-256color| simpleterm with 256 colors,
|
st-256color| simpleterm with 256 colors,
|
||||||
use=st,
|
use=st,
|
||||||
@ -220,3 +231,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,
|
||||||
|
3
win.h
3
win.h
@ -30,9 +30,12 @@ void xdrawline(Line, int, int, int);
|
|||||||
void xfinishdraw(void);
|
void xfinishdraw(void);
|
||||||
void xloadcols(void);
|
void xloadcols(void);
|
||||||
int xsetcolorname(int, const char *);
|
int xsetcolorname(int, const char *);
|
||||||
|
int xgetcolor(int, unsigned char *, unsigned char *, unsigned char *);
|
||||||
|
void xseticontitle(char *);
|
||||||
void xsettitle(char *);
|
void xsettitle(char *);
|
||||||
int xsetcursor(int);
|
int xsetcursor(int);
|
||||||
void xsetmode(int, unsigned int);
|
void xsetmode(int, unsigned int);
|
||||||
void xsetpointermotion(int);
|
void xsetpointermotion(int);
|
||||||
void xsetsel(char *);
|
void xsetsel(char *);
|
||||||
int xstartdraw(void);
|
int xstartdraw(void);
|
||||||
|
void xximspot(int, int);
|
||||||
|
557
x.c
557
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 {
|
||||||
@ -46,7 +48,7 @@ typedef struct {
|
|||||||
/* X modifiers */
|
/* X modifiers */
|
||||||
#define XK_ANY_MOD UINT_MAX
|
#define XK_ANY_MOD UINT_MAX
|
||||||
#define XK_NO_MOD 0
|
#define XK_NO_MOD 0
|
||||||
#define XK_SWITCH_MOD (1<<13)
|
#define XK_SWITCH_MOD (1<<13|1<<14)
|
||||||
|
|
||||||
/* function definitions used in config.h */
|
/* function definitions used in config.h */
|
||||||
static void clipcopy(const Arg *);
|
static void clipcopy(const Arg *);
|
||||||
@ -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"
|
||||||
@ -90,9 +93,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;
|
||||||
@ -139,13 +146,17 @@ static void xdrawglyphfontspecs(const XftGlyphFontSpec *, Glyph, int, int, int);
|
|||||||
static void xdrawglyph(Glyph, int, int);
|
static void xdrawglyph(Glyph, int, int);
|
||||||
static void xclear(int, int, int, int);
|
static void xclear(int, int, int, int);
|
||||||
static int xgeommasktogravity(int);
|
static int xgeommasktogravity(int);
|
||||||
|
static int ximopen(Display *);
|
||||||
|
static void ximinstantiate(Display *, XPointer, XPointer);
|
||||||
|
static void ximdestroy(XIM, XPointer, XPointer);
|
||||||
|
static int xicdestroy(XIC, XPointer, XPointer);
|
||||||
static void xinit(int, int);
|
static void xinit(int, int);
|
||||||
static void cresize(int, int);
|
static void cresize(int, int);
|
||||||
static void xresize(int, int);
|
static void xresize(int, int);
|
||||||
static void xhints(void);
|
static void xhints(void);
|
||||||
static int xloadcolor(int, const char *, Color *);
|
static int xloadcolor(int, const char *, Color *);
|
||||||
static int xloadfont(Font *, FcPattern *);
|
static int xloadfont(Font *, FcPattern *);
|
||||||
static void xloadfonts(char *, double);
|
static void xloadfonts(const char *, double);
|
||||||
static void xunloadfont(Font *);
|
static void xunloadfont(Font *);
|
||||||
static void xunloadfonts(void);
|
static void xunloadfonts(void);
|
||||||
static void xsetenv(void);
|
static void xsetenv(void);
|
||||||
@ -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 *);
|
||||||
@ -178,6 +191,7 @@ static void usage(void);
|
|||||||
|
|
||||||
static void (*handler[LASTEvent])(XEvent *) = {
|
static void (*handler[LASTEvent])(XEvent *) = {
|
||||||
[KeyPress] = kpress,
|
[KeyPress] = kpress,
|
||||||
|
[KeyRelease] = kpress,
|
||||||
[ClientMessage] = cmessage,
|
[ClientMessage] = cmessage,
|
||||||
[ConfigureNotify] = resize,
|
[ConfigureNotify] = resize,
|
||||||
[VisibilityNotify] = visibility,
|
[VisibilityNotify] = visibility,
|
||||||
@ -223,8 +237,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;
|
||||||
@ -238,15 +253,15 @@ static char *opt_line = NULL;
|
|||||||
static char *opt_name = NULL;
|
static char *opt_name = NULL;
|
||||||
static char *opt_title = NULL;
|
static char *opt_title = NULL;
|
||||||
|
|
||||||
static int oldbutton = 3; /* button event on startup: 3 = release */
|
static uint buttons; /* bit field of pressed buttons */
|
||||||
|
|
||||||
void
|
void
|
||||||
clipcopy(const Arg *dummy)
|
clipcopy(const Arg *dummy)
|
||||||
{
|
{
|
||||||
Atom clipboard;
|
Atom clipboard;
|
||||||
|
|
||||||
if (xsel.clipboard != NULL)
|
|
||||||
free(xsel.clipboard);
|
free(xsel.clipboard);
|
||||||
|
xsel.clipboard = NULL;
|
||||||
|
|
||||||
if (xsel.primary != NULL) {
|
if (xsel.primary != NULL) {
|
||||||
xsel.clipboard = xstrdup(xsel.primary);
|
xsel.clipboard = xstrdup(xsel.primary);
|
||||||
@ -308,6 +323,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 +349,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)) {
|
||||||
@ -344,59 +365,68 @@ mousesel(XEvent *e, int done)
|
|||||||
void
|
void
|
||||||
mousereport(XEvent *e)
|
mousereport(XEvent *e)
|
||||||
{
|
{
|
||||||
int len, x = evcol(e), y = evrow(e),
|
int len, btn, code;
|
||||||
button = e->xbutton.button, state = e->xbutton.state;
|
int x = evcol(e), y = evrow(e);
|
||||||
|
int state = e->xbutton.state;
|
||||||
char buf[40];
|
char buf[40];
|
||||||
static int ox, oy;
|
static int ox, oy;
|
||||||
|
|
||||||
/* from urxvt */
|
if (e->type == MotionNotify) {
|
||||||
if (e->xbutton.type == MotionNotify) {
|
|
||||||
if (x == ox && y == oy)
|
if (x == ox && y == oy)
|
||||||
return;
|
return;
|
||||||
if (!IS_SET(MODE_MOUSEMOTION) && !IS_SET(MODE_MOUSEMANY))
|
if (!IS_SET(MODE_MOUSEMOTION) && !IS_SET(MODE_MOUSEMANY))
|
||||||
return;
|
return;
|
||||||
/* MOUSE_MOTION: no reporting if no button is pressed */
|
/* MODE_MOUSEMOTION: no reporting if no button is pressed */
|
||||||
if (IS_SET(MODE_MOUSEMOTION) && oldbutton == 3)
|
if (IS_SET(MODE_MOUSEMOTION) && buttons == 0)
|
||||||
return;
|
return;
|
||||||
|
/* Set btn to lowest-numbered pressed button, or 12 if no
|
||||||
button = oldbutton + 32;
|
* buttons are pressed. */
|
||||||
ox = x;
|
for (btn = 1; btn <= 11 && !(buttons & (1<<(btn-1))); btn++)
|
||||||
oy = y;
|
;
|
||||||
|
code = 32;
|
||||||
} else {
|
} else {
|
||||||
if (!IS_SET(MODE_MOUSESGR) && e->xbutton.type == ButtonRelease) {
|
btn = e->xbutton.button;
|
||||||
button = 3;
|
/* Only buttons 1 through 11 can be encoded */
|
||||||
} else {
|
if (btn < 1 || btn > 11)
|
||||||
button -= Button1;
|
return;
|
||||||
if (button >= 3)
|
if (e->type == ButtonRelease) {
|
||||||
button += 64 - 3;
|
|
||||||
}
|
|
||||||
if (e->xbutton.type == ButtonPress) {
|
|
||||||
oldbutton = button;
|
|
||||||
ox = x;
|
|
||||||
oy = y;
|
|
||||||
} else if (e->xbutton.type == ButtonRelease) {
|
|
||||||
oldbutton = 3;
|
|
||||||
/* MODE_MOUSEX10: no button release reporting */
|
/* MODE_MOUSEX10: no button release reporting */
|
||||||
if (IS_SET(MODE_MOUSEX10))
|
if (IS_SET(MODE_MOUSEX10))
|
||||||
return;
|
return;
|
||||||
if (button == 64 || button == 65)
|
/* Don't send release events for the scroll wheel */
|
||||||
|
if (btn == 4 || btn == 5)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
code = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ox = x;
|
||||||
|
oy = y;
|
||||||
|
|
||||||
|
/* Encode btn into code. If no button is pressed for a motion event in
|
||||||
|
* MODE_MOUSEMANY, then encode it as a release. */
|
||||||
|
if ((!IS_SET(MODE_MOUSESGR) && e->type == ButtonRelease) || btn == 12)
|
||||||
|
code += 3;
|
||||||
|
else if (btn >= 8)
|
||||||
|
code += 128 + btn - 8;
|
||||||
|
else if (btn >= 4)
|
||||||
|
code += 64 + btn - 4;
|
||||||
|
else
|
||||||
|
code += btn - 1;
|
||||||
|
|
||||||
if (!IS_SET(MODE_MOUSEX10)) {
|
if (!IS_SET(MODE_MOUSEX10)) {
|
||||||
button += ((state & ShiftMask ) ? 4 : 0)
|
code += ((state & ShiftMask ) ? 4 : 0)
|
||||||
+ ((state & Mod4Mask ) ? 8 : 0)
|
+ ((state & Mod1Mask ) ? 8 : 0) /* meta key: alt */
|
||||||
+ ((state & ControlMask) ? 16 : 0);
|
+ ((state & ControlMask) ? 16 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_SET(MODE_MOUSESGR)) {
|
if (IS_SET(MODE_MOUSESGR)) {
|
||||||
len = snprintf(buf, sizeof(buf), "\033[<%d;%d;%d%c",
|
len = snprintf(buf, sizeof(buf), "\033[<%d;%d;%d%c",
|
||||||
button, x+1, y+1,
|
code, x+1, y+1,
|
||||||
e->xbutton.type == ButtonRelease ? 'm' : 'M');
|
e->type == ButtonRelease ? 'm' : 'M');
|
||||||
} else if (x < 223 && y < 223) {
|
} else if (x < 223 && y < 223) {
|
||||||
len = snprintf(buf, sizeof(buf), "\033[M%c%c%c",
|
len = snprintf(buf, sizeof(buf), "\033[M%c%c%c",
|
||||||
32+button, 32+x+1, 32+y+1);
|
32+code, 32+x+1, 32+y+1);
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -404,27 +434,66 @@ 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);
|
||||||
|
|
||||||
|
if (release == 0 &&
|
||||||
|
e->xbutton.button == Button1 &&
|
||||||
|
(match(ControlMask, state) ||
|
||||||
|
match(ControlMask, state & ~forcemousemod))) {
|
||||||
|
followurl(evrow(e), evcol(e));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) {
|
||||||
|
if (ms->release == release &&
|
||||||
|
ms->button == e->xbutton.button &&
|
||||||
|
(match(ms->mod, state) || /* exact or forced */
|
||||||
|
match(ms->mod, state & ~forcemousemod))) {
|
||||||
|
ms->func(&(ms->arg));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
bpress(XEvent *e)
|
bpress(XEvent *e)
|
||||||
{
|
{
|
||||||
|
int btn = e->xbutton.button;
|
||||||
struct timespec now;
|
struct timespec now;
|
||||||
MouseShortcut *ms;
|
|
||||||
int snap;
|
int snap;
|
||||||
|
|
||||||
if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) {
|
if (1 <= btn && btn <= 11)
|
||||||
|
buttons |= 1 << (btn-1);
|
||||||
|
|
||||||
|
if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forcemousemod)) {
|
||||||
mousereport(e);
|
mousereport(e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) {
|
if (mouseaction(e, 0))
|
||||||
if (e->xbutton.button == ms->b
|
|
||||||
&& match(ms->mask, e->xbutton.state)) {
|
|
||||||
ttywrite(ms->s, strlen(ms->s), 1);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e->xbutton.button == Button1) {
|
if (btn == Button1) {
|
||||||
/*
|
/*
|
||||||
* If the user clicks below predefined timeouts specific
|
* If the user clicks below predefined timeouts specific
|
||||||
* snapping behaviour is exposed.
|
* snapping behaviour is exposed.
|
||||||
@ -618,6 +687,9 @@ selrequest(XEvent *e)
|
|||||||
void
|
void
|
||||||
setsel(char *str, Time t)
|
setsel(char *str, Time t)
|
||||||
{
|
{
|
||||||
|
if (!str)
|
||||||
|
return;
|
||||||
|
|
||||||
free(xsel.primary);
|
free(xsel.primary);
|
||||||
xsel.primary = str;
|
xsel.primary = str;
|
||||||
|
|
||||||
@ -635,21 +707,26 @@ xsetsel(char *str)
|
|||||||
void
|
void
|
||||||
brelease(XEvent *e)
|
brelease(XEvent *e)
|
||||||
{
|
{
|
||||||
if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) {
|
int btn = e->xbutton.button;
|
||||||
|
|
||||||
|
if (1 <= btn && btn <= 11)
|
||||||
|
buttons &= ~(1 << (btn-1));
|
||||||
|
|
||||||
|
if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forcemousemod)) {
|
||||||
mousereport(e);
|
mousereport(e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e->xbutton.button == Button2)
|
if (mouseaction(e, 1))
|
||||||
selpaste(NULL);
|
return;
|
||||||
else if (e->xbutton.button == Button1)
|
if (btn == 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;
|
||||||
}
|
}
|
||||||
@ -669,6 +746,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);
|
||||||
@ -678,8 +757,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,
|
||||||
@ -728,33 +807,45 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
xgetcolor(int x, unsigned char *r, unsigned char *g, unsigned char *b)
|
||||||
|
{
|
||||||
|
if (!BETWEEN(x, 0, dc.collen - 1))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
*r = dc.col[x].color.red >> 8;
|
||||||
|
*g = dc.col[x].color.green >> 8;
|
||||||
|
*b = dc.col[x].color.blue >> 8;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
xsetcolorname(int x, const char *name)
|
xsetcolorname(int x, const char *name)
|
||||||
{
|
{
|
||||||
Color ncolor;
|
Color ncolor;
|
||||||
|
|
||||||
if (!BETWEEN(x, 0, dc.collen))
|
if (!BETWEEN(x, 0, dc.collen - 1))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
|
||||||
if (!xloadcolor(x, name, &ncolor))
|
if (!xloadcolor(x, name, &ncolor))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
@ -785,15 +876,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;
|
||||||
}
|
}
|
||||||
@ -866,7 +959,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -875,7 +968,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -898,19 +991,18 @@ xloadfont(Font *f, FcPattern *pattern)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
xloadfonts(char *fontstr, double fontsize)
|
xloadfonts(const 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((const 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);
|
||||||
@ -936,7 +1028,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,
|
||||||
@ -953,17 +1045,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);
|
||||||
}
|
}
|
||||||
@ -990,23 +1082,77 @@ xunloadfonts(void)
|
|||||||
xunloadfont(&dc.ibfont);
|
xunloadfont(&dc.ibfont);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ximopen(Display *dpy)
|
||||||
|
{
|
||||||
|
XIMCallback imdestroy = { .client_data = NULL, .callback = ximdestroy };
|
||||||
|
XICCallback icdestroy = { .client_data = NULL, .callback = xicdestroy };
|
||||||
|
|
||||||
|
xw.ime.xim = XOpenIM(xw.dpy, NULL, NULL, NULL);
|
||||||
|
if (xw.ime.xim == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (XSetIMValues(xw.ime.xim, XNDestroyCallback, &imdestroy, NULL))
|
||||||
|
fprintf(stderr, "XSetIMValues: "
|
||||||
|
"Could not set XNDestroyCallback.\n");
|
||||||
|
|
||||||
|
xw.ime.spotlist = XVaCreateNestedList(0, XNSpotLocation, &xw.ime.spot,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
if (xw.ime.xic == NULL) {
|
||||||
|
xw.ime.xic = XCreateIC(xw.ime.xim, XNInputStyle,
|
||||||
|
XIMPreeditNothing | XIMStatusNothing,
|
||||||
|
XNClientWindow, xw.win,
|
||||||
|
XNDestroyCallback, &icdestroy,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
if (xw.ime.xic == NULL)
|
||||||
|
fprintf(stderr, "XCreateIC: Could not create input context.\n");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ximinstantiate(Display *dpy, XPointer client, XPointer call)
|
||||||
|
{
|
||||||
|
if (ximopen(dpy))
|
||||||
|
XUnregisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
|
||||||
|
ximinstantiate, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ximdestroy(XIM xim, XPointer client, XPointer call)
|
||||||
|
{
|
||||||
|
xw.ime.xim = NULL;
|
||||||
|
XRegisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
|
||||||
|
ximinstantiate, NULL);
|
||||||
|
XFree(xw.ime.spotlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
xicdestroy(XIC xim, XPointer client, XPointer call)
|
||||||
|
{
|
||||||
|
xw.ime.xic = NULL;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
xinit(int cols, int rows)
|
xinit(int cols, int rows)
|
||||||
{
|
{
|
||||||
XGCValues gcvalues;
|
XGCValues gcvalues;
|
||||||
Cursor cursor;
|
Cursor cursor;
|
||||||
Window parent;
|
Window parent, root;
|
||||||
pid_t thispid = getpid();
|
pid_t thispid = getpid();
|
||||||
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);
|
||||||
@ -1027,21 +1173,24 @@ 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;
|
||||||
|
|
||||||
|
root = XRootWindow(xw.dpy, xw.scr);
|
||||||
if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0))))
|
if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0))))
|
||||||
parent = XRootWindow(xw.dpy, xw.scr);
|
parent = root;
|
||||||
xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t,
|
xw.win = XCreateWindow(xw.dpy, root, xw.l, xw.t,
|
||||||
win.w, win.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
|
win.w, win.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
|
||||||
xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
|
xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
|
||||||
| CWEventMask | CWColormap, &xw.attrs);
|
| CWEventMask | CWColormap, &xw.attrs);
|
||||||
|
if (parent != root)
|
||||||
|
XReparentWindow(xw.dpy, xw.win, parent, xw.l, xw.t);
|
||||||
|
|
||||||
memset(&gcvalues, 0, sizeof(gcvalues));
|
memset(&gcvalues, 0, sizeof(gcvalues));
|
||||||
gcvalues.graphics_exposures = False;
|
gcvalues.graphics_exposures = False;
|
||||||
dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures,
|
dc.gc = XCreateGC(xw.dpy, xw.win, GCGraphicsExposures,
|
||||||
&gcvalues);
|
&gcvalues);
|
||||||
xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
|
xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
|
||||||
DefaultDepth(xw.dpy, xw.scr));
|
DefaultDepth(xw.dpy, xw.scr));
|
||||||
@ -1055,22 +1204,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);
|
||||||
@ -1093,6 +1230,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);
|
||||||
@ -1101,8 +1239,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);
|
||||||
@ -1212,13 +1350,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,
|
||||||
@ -1370,13 +1505,13 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
|
|||||||
XftDrawGlyphFontSpec(xw.draw, fg, specs, len);
|
XftDrawGlyphFontSpec(xw.draw, fg, specs, len);
|
||||||
|
|
||||||
/* Render underline and strikethrough. */
|
/* Render underline and strikethrough. */
|
||||||
if (base.mode & ATTR_UNDERLINE) {
|
if (base.mode & ATTR_UNDERLINE || base.mode & ATTR_URL) {
|
||||||
XftDrawRect(xw.draw, fg, winx, winy + dc.font.ascent + 1,
|
XftDrawRect(xw.draw, fg, winx, winy + dc.font.ascent * chscale + 1,
|
||||||
width, 1);
|
width, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (base.mode & ATTR_STRUCK) {
|
if (base.mode & ATTR_STRUCK) {
|
||||||
XftDrawRect(xw.draw, fg, winx, winy + 2 * dc.font.ascent / 3,
|
XftDrawRect(xw.draw, fg, winx, winy + 2 * dc.font.ascent * chscale / 3,
|
||||||
width, 1);
|
width, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1436,8 +1571,9 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
|
|||||||
/* draw the new one */
|
/* draw the new one */
|
||||||
if (IS_SET(MODE_FOCUSED)) {
|
if (IS_SET(MODE_FOCUSED)) {
|
||||||
switch (win.cursor) {
|
switch (win.cursor) {
|
||||||
case 7: /* st extension: 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 */
|
||||||
@ -1488,14 +1624,35 @@ xsetenv(void)
|
|||||||
setenv("WINDOWID", buf, 1);
|
setenv("WINDOWID", buf, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
xseticontitle(char *p)
|
||||||
|
{
|
||||||
|
XTextProperty prop;
|
||||||
|
DEFAULT(p, opt_title);
|
||||||
|
|
||||||
|
if (p[0] == '\0')
|
||||||
|
p = opt_title;
|
||||||
|
|
||||||
|
if (Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle,
|
||||||
|
&prop) != Success)
|
||||||
|
return;
|
||||||
|
XSetWMIconName(xw.dpy, xw.win, &prop);
|
||||||
|
XSetTextProperty(xw.dpy, xw.win, &prop, xw.netwmiconname);
|
||||||
|
XFree(prop.value);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
xsettitle(char *p)
|
xsettitle(char *p)
|
||||||
{
|
{
|
||||||
XTextProperty prop;
|
XTextProperty prop;
|
||||||
DEFAULT(p, "st");
|
DEFAULT(p, opt_title);
|
||||||
|
|
||||||
Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle,
|
if (p[0] == '\0')
|
||||||
&prop);
|
p = opt_title;
|
||||||
|
|
||||||
|
if (Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle,
|
||||||
|
&prop) != Success)
|
||||||
|
return;
|
||||||
XSetWMName(xw.dpy, xw.win, &prop);
|
XSetWMName(xw.dpy, xw.win, &prop);
|
||||||
XSetTextProperty(xw.dpy, xw.win, &prop, xw.netwmname);
|
XSetTextProperty(xw.dpy, xw.win, &prop, xw.netwmname);
|
||||||
XFree(prop.value);
|
XFree(prop.value);
|
||||||
@ -1548,6 +1705,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)
|
||||||
{
|
{
|
||||||
@ -1587,8 +1756,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;
|
||||||
@ -1622,13 +1790,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);
|
||||||
@ -1682,8 +1852,8 @@ void
|
|||||||
kpress(XEvent *ev)
|
kpress(XEvent *ev)
|
||||||
{
|
{
|
||||||
XKeyEvent *e = &ev->xkey;
|
XKeyEvent *e = &ev->xkey;
|
||||||
KeySym ksym;
|
KeySym ksym = NoSymbol;
|
||||||
char buf[32], *customkey;
|
char buf[64], *customkey;
|
||||||
int len;
|
int len;
|
||||||
Rune c;
|
Rune c;
|
||||||
Status status;
|
Status status;
|
||||||
@ -1692,7 +1862,25 @@ 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);
|
||||||
|
if (status == XBufferOverflow)
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
len = XLookupString(e, buf, sizeof buf, &ksym, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 0. highlight URLs when control held */
|
||||||
|
if (ksym == XK_Control_L) {
|
||||||
|
highlighturls();
|
||||||
|
} else if (ev->type == KeyRelease && e->keycode == XKeysymToKeycode(e->display, XK_Control_L)) {
|
||||||
|
unhighlighturls();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* KeyRelease not relevant to shortcuts */
|
||||||
|
if (ev->type == KeyRelease)
|
||||||
|
return;
|
||||||
|
|
||||||
/* 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)) {
|
||||||
@ -1725,7 +1913,6 @@ kpress(XEvent *ev)
|
|||||||
ttywrite(buf, len, 1);
|
ttywrite(buf, len, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
cmessage(XEvent *e)
|
cmessage(XEvent *e)
|
||||||
{
|
{
|
||||||
@ -1761,10 +1948,9 @@ run(void)
|
|||||||
XEvent ev;
|
XEvent ev;
|
||||||
int w = win.w, h = win.h;
|
int w = win.w, h = win.h;
|
||||||
fd_set rfd;
|
fd_set rfd;
|
||||||
int xfd = XConnectionNumber(xw.dpy), xev, blinkset = 0, dodraw = 0;
|
int xfd = XConnectionNumber(xw.dpy), ttyfd, xev, drawing;
|
||||||
int ttyfd;
|
struct timespec seltv, *tv, now, lastblink, trigger;
|
||||||
struct timespec drawtimeout, *tv = NULL, now, last, lastblink;
|
double timeout;
|
||||||
long deltatime;
|
|
||||||
|
|
||||||
/* Waiting for window mapping */
|
/* Waiting for window mapping */
|
||||||
do {
|
do {
|
||||||
@ -1785,51 +1971,31 @@ run(void)
|
|||||||
ttyfd = ttynew(opt_line, shell, opt_io, opt_cmd);
|
ttyfd = ttynew(opt_line, shell, opt_io, opt_cmd);
|
||||||
cresize(w, h);
|
cresize(w, h);
|
||||||
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &last);
|
for (timeout = -1, drawing = 0, lastblink = (struct timespec){0};;) {
|
||||||
lastblink = last;
|
|
||||||
|
|
||||||
for (xev = actionfps;;) {
|
|
||||||
FD_ZERO(&rfd);
|
FD_ZERO(&rfd);
|
||||||
FD_SET(ttyfd, &rfd);
|
FD_SET(ttyfd, &rfd);
|
||||||
FD_SET(xfd, &rfd);
|
FD_SET(xfd, &rfd);
|
||||||
|
|
||||||
|
if (XPending(xw.dpy))
|
||||||
|
timeout = 0; /* existing events might not set xfd */
|
||||||
|
|
||||||
|
seltv.tv_sec = timeout / 1E3;
|
||||||
|
seltv.tv_nsec = 1E6 * (timeout - 1E3 * seltv.tv_sec);
|
||||||
|
tv = timeout >= 0 ? &seltv : NULL;
|
||||||
|
|
||||||
if (pselect(MAX(xfd, ttyfd)+1, &rfd, NULL, NULL, tv, NULL) < 0) {
|
if (pselect(MAX(xfd, ttyfd)+1, &rfd, NULL, NULL, tv, NULL) < 0) {
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
die("select failed: %s\n", strerror(errno));
|
die("select failed: %s\n", strerror(errno));
|
||||||
}
|
}
|
||||||
if (FD_ISSET(ttyfd, &rfd)) {
|
|
||||||
ttyread();
|
|
||||||
if (blinktimeout) {
|
|
||||||
blinkset = tattrset(ATTR_BLINK);
|
|
||||||
if (!blinkset)
|
|
||||||
MODBIT(win.mode, 0, MODE_BLINK);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FD_ISSET(xfd, &rfd))
|
|
||||||
xev = actionfps;
|
|
||||||
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||||
drawtimeout.tv_sec = 0;
|
|
||||||
drawtimeout.tv_nsec = (1000 * 1E6)/ xfps;
|
|
||||||
tv = &drawtimeout;
|
|
||||||
|
|
||||||
dodraw = 0;
|
if (FD_ISSET(ttyfd, &rfd))
|
||||||
if (blinktimeout && TIMEDIFF(now, lastblink) > blinktimeout) {
|
ttyread();
|
||||||
tsetdirtattr(ATTR_BLINK);
|
|
||||||
win.mode ^= MODE_BLINK;
|
|
||||||
lastblink = now;
|
|
||||||
dodraw = 1;
|
|
||||||
}
|
|
||||||
deltatime = TIMEDIFF(now, last);
|
|
||||||
if (deltatime > 1000 / (xev ? xfps : actionfps)) {
|
|
||||||
dodraw = 1;
|
|
||||||
last = now;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dodraw) {
|
xev = 0;
|
||||||
while (XPending(xw.dpy)) {
|
while (XPending(xw.dpy)) {
|
||||||
|
xev = 1;
|
||||||
XNextEvent(xw.dpy, &ev);
|
XNextEvent(xw.dpy, &ev);
|
||||||
if (XFilterEvent(&ev, None))
|
if (XFilterEvent(&ev, None))
|
||||||
continue;
|
continue;
|
||||||
@ -1837,30 +2003,45 @@ run(void)
|
|||||||
(handler[ev.type])(&ev);
|
(handler[ev.type])(&ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* To reduce flicker and tearing, when new content or event
|
||||||
|
* triggers drawing, we first wait a bit to ensure we got
|
||||||
|
* everything, and if nothing new arrives - we draw.
|
||||||
|
* We start with trying to wait minlatency ms. If more content
|
||||||
|
* arrives sooner, we retry with shorter and shorter periods,
|
||||||
|
* and eventually draw even without idle after maxlatency ms.
|
||||||
|
* Typically this results in low latency while interacting,
|
||||||
|
* maximum latency intervals during `cat huge.txt`, and perfect
|
||||||
|
* sync with periodic updates from animations/key-repeats/etc.
|
||||||
|
*/
|
||||||
|
if (FD_ISSET(ttyfd, &rfd) || xev) {
|
||||||
|
if (!drawing) {
|
||||||
|
trigger = now;
|
||||||
|
drawing = 1;
|
||||||
|
}
|
||||||
|
timeout = (maxlatency - TIMEDIFF(now, trigger)) \
|
||||||
|
/ maxlatency * minlatency;
|
||||||
|
if (timeout > 0)
|
||||||
|
continue; /* we have time, try to find idle */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* idle detected or maxlatency exhausted -> draw */
|
||||||
|
timeout = -1;
|
||||||
|
if (blinktimeout && tattrset(ATTR_BLINK)) {
|
||||||
|
timeout = blinktimeout - TIMEDIFF(now, lastblink);
|
||||||
|
if (timeout <= 0) {
|
||||||
|
if (-timeout > blinktimeout) /* start visible */
|
||||||
|
win.mode |= MODE_BLINK;
|
||||||
|
win.mode ^= MODE_BLINK;
|
||||||
|
tsetdirtattr(ATTR_BLINK);
|
||||||
|
lastblink = now;
|
||||||
|
timeout = blinktimeout;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
draw();
|
draw();
|
||||||
XFlush(xw.dpy);
|
XFlush(xw.dpy);
|
||||||
|
drawing = 0;
|
||||||
if (xev && !FD_ISSET(xfd, &rfd))
|
|
||||||
xev--;
|
|
||||||
if (!FD_ISSET(ttyfd, &rfd) && !FD_ISSET(xfd, &rfd)) {
|
|
||||||
if (blinkset) {
|
|
||||||
if (TIMEDIFF(now, lastblink) \
|
|
||||||
> blinktimeout) {
|
|
||||||
drawtimeout.tv_nsec = 1000;
|
|
||||||
} else {
|
|
||||||
drawtimeout.tv_nsec = (1E6 * \
|
|
||||||
(blinktimeout - \
|
|
||||||
TIMEDIFF(now,
|
|
||||||
lastblink)));
|
|
||||||
}
|
|
||||||
drawtimeout.tv_sec = \
|
|
||||||
drawtimeout.tv_nsec / 1E9;
|
|
||||||
drawtimeout.tv_nsec %= (long)1E9;
|
|
||||||
} else {
|
|
||||||
tv = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1882,7 +2063,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':
|
||||||
@ -1922,19 +2103,19 @@ 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();
|
||||||
} ARGEND;
|
} ARGEND;
|
||||||
|
|
||||||
run:
|
run:
|
||||||
if (argc > 0) {
|
if (argc > 0) /* eat all remaining arguments */
|
||||||
/* eat all remaining arguments */
|
|
||||||
opt_cmd = argv;
|
opt_cmd = argv;
|
||||||
if (!opt_title && !opt_line)
|
|
||||||
opt_title = basename(xstrdup(argv[0]));
|
if (!opt_title)
|
||||||
}
|
opt_title = (opt_line || !opt_cmd) ? "st" : opt_cmd[0];
|
||||||
|
|
||||||
setlocale(LC_CTYPE, "");
|
setlocale(LC_CTYPE, "");
|
||||||
XSetLocaleModifiers("");
|
XSetLocaleModifiers("");
|
||||||
cols = MAX(cols, 1);
|
cols = MAX(cols, 1);
|
||||||
|
Reference in New Issue
Block a user