mirror of
https://github.com/alrayyes/st.git
synced 2024-11-26 04:46:22 +00:00
we definately need pixmaps for the drawing, currently drawing into the window is painfully slow! much more slower than drawing into a pixmap and mapping that when finished -- several optimisations
This commit is contained in:
parent
0a5e510209
commit
cf65699a29
2 changed files with 85 additions and 97 deletions
22
config.h
22
config.h
|
@ -6,7 +6,7 @@
|
||||||
#define LINESPACE 1 /* additional pixel between each line */
|
#define LINESPACE 1 /* additional pixel between each line */
|
||||||
|
|
||||||
/* Terminal colors */
|
/* Terminal colors */
|
||||||
static char* colorname[] = {
|
static const char *colorname[] = {
|
||||||
"black",
|
"black",
|
||||||
"red",
|
"red",
|
||||||
"green",
|
"green",
|
||||||
|
@ -26,14 +26,14 @@ static char* colorname[] = {
|
||||||
|
|
||||||
|
|
||||||
/* special keys */
|
/* special keys */
|
||||||
static Key key[] = {
|
static const char *key[] = {
|
||||||
{ XK_Delete, "\033[3~" },
|
[XK_Delete] = "\033[3~",
|
||||||
{ XK_Home, "\033[1~" },
|
[XK_Home] = "\033[1~",
|
||||||
{ XK_End, "\033[4~" },
|
[XK_End] = "\033[4~",
|
||||||
{ XK_Prior, "\033[5~" },
|
[XK_Prior] = "\033[5~",
|
||||||
{ XK_Next, "\033[6~" },
|
[XK_Next] = "\033[6~",
|
||||||
{ XK_Left, "\033[D" },
|
[XK_Left] = "\033[D",
|
||||||
{ XK_Right, "\033[C" },
|
[XK_Right] = "\033[C",
|
||||||
{ XK_Up, "\033[A" },
|
[XK_Up] = "\033[A",
|
||||||
{ XK_Down, "\033[B" },
|
[XK_Down] = "\033[B",
|
||||||
};
|
};
|
||||||
|
|
158
st.c
158
st.c
|
@ -1,5 +1,5 @@
|
||||||
/* See LICENSE for licence details. */
|
/* See LICENSE for licence details. */
|
||||||
#define _XOPEN_SOURCE
|
#define _XOPEN_SOURCE 600
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
@ -107,61 +107,68 @@ typedef struct {
|
||||||
GC gc;
|
GC gc;
|
||||||
} DC;
|
} DC;
|
||||||
|
|
||||||
void die(const char *errstr, ...);
|
static void die(const char *errstr, ...);
|
||||||
void draw(int);
|
static void draw(int);
|
||||||
void execsh(void);
|
static void execsh(void);
|
||||||
void sigchld(int);
|
static void sigchld(int);
|
||||||
char* kmap(KeySym);
|
static void run(void);
|
||||||
void kpress(XKeyEvent *);
|
|
||||||
void resize(XEvent *);
|
|
||||||
void run(void);
|
|
||||||
|
|
||||||
int escaddc(char);
|
static int escaddc(char);
|
||||||
int escfinal(char);
|
static int escfinal(char);
|
||||||
void escdump(void);
|
static void escdump(void);
|
||||||
void eschandle(void);
|
static void eschandle(void);
|
||||||
void escparse(void);
|
static void escparse(void);
|
||||||
void escreset(void);
|
static void escreset(void);
|
||||||
|
|
||||||
void tclearregion(int, int, int, int);
|
static void tclearregion(int, int, int, int);
|
||||||
void tcpos(int);
|
static void tcpos(int);
|
||||||
void tcursor(int);
|
static void tcursor(int);
|
||||||
void tdeletechar(int);
|
static void tdeletechar(int);
|
||||||
void tdeleteline(int);
|
static void tdeleteline(int);
|
||||||
void tdump(void);
|
static void tdump(void);
|
||||||
void tinsertblank(int);
|
static void tinsertblank(int);
|
||||||
void tinsertblankline(int);
|
static void tinsertblankline(int);
|
||||||
void tmoveto(int, int);
|
static void tmoveto(int, int);
|
||||||
void tnew(int, int);
|
static void tnew(int, int);
|
||||||
void tnewline(void);
|
static void tnewline(void);
|
||||||
void tputc(char);
|
static void tputc(char);
|
||||||
void tputs(char*, int);
|
static void tputs(char*, int);
|
||||||
void tresize(int, int);
|
static void tresize(int, int);
|
||||||
void tscroll(void);
|
static void tscroll(void);
|
||||||
void tsetattr(int*, int);
|
static void tsetattr(int*, int);
|
||||||
void tsetchar(char);
|
static void tsetchar(char);
|
||||||
void tsetscroll(int, int);
|
static void tsetscroll(int, int);
|
||||||
|
|
||||||
void ttynew(void);
|
static void ttynew(void);
|
||||||
void ttyread(void);
|
static void ttyread(void);
|
||||||
void ttyresize(int, int);
|
static void ttyresize(int, int);
|
||||||
void ttywrite(char *, size_t);
|
static void ttywrite(const char *, size_t);
|
||||||
|
|
||||||
unsigned long xgetcol(const char *);
|
static unsigned long xgetcol(const char *);
|
||||||
void xclear(int, int, int, int);
|
static void xclear(int, int, int, int);
|
||||||
void xcursor(int);
|
static void xcursor(int);
|
||||||
void xdrawc(int, int, Glyph);
|
static void xdrawc(int, int, Glyph);
|
||||||
void xinit(void);
|
static void xinit(void);
|
||||||
void xscroll(void);
|
static void xscroll(void);
|
||||||
|
|
||||||
|
static void expose(XEvent *);
|
||||||
|
static void kpress(XEvent *);
|
||||||
|
static void resize(XEvent *);
|
||||||
|
|
||||||
|
static void (*handler[LASTEvent])(XEvent *) = {
|
||||||
|
[KeyPress] = kpress,
|
||||||
|
[Expose] = expose,
|
||||||
|
[ConfigureNotify] = resize
|
||||||
|
};
|
||||||
|
|
||||||
/* Globals */
|
/* Globals */
|
||||||
DC dc;
|
static DC dc;
|
||||||
XWindow xw;
|
static XWindow xw;
|
||||||
Term term;
|
static Term term;
|
||||||
Escseq escseq;
|
static Escseq escseq;
|
||||||
int cmdfd;
|
static int cmdfd;
|
||||||
pid_t pid;
|
static pid_t pid;
|
||||||
int running;
|
static int running;
|
||||||
|
|
||||||
void
|
void
|
||||||
die(const char *errstr, ...) {
|
die(const char *errstr, ...) {
|
||||||
|
@ -259,7 +266,7 @@ ttyread(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ttywrite(char *s, size_t n) {
|
ttywrite(const char *s, size_t n) {
|
||||||
if(write(cmdfd, s, n) == -1)
|
if(write(cmdfd, s, n) == -1)
|
||||||
die("write error on tty: %s\n", SERRNO);
|
die("write error on tty: %s\n", SERRNO);
|
||||||
}
|
}
|
||||||
|
@ -997,29 +1004,25 @@ draw(int redraw_all) {
|
||||||
xcursor(CSdraw);
|
xcursor(CSdraw);
|
||||||
}
|
}
|
||||||
|
|
||||||
char*
|
void
|
||||||
kmap(KeySym k) {
|
expose(XEvent *ev) {
|
||||||
int i;
|
draw(SCredraw);
|
||||||
for(i = 0; i < LEN(key); i++)
|
|
||||||
if(key[i].k == k)
|
|
||||||
return (char*)key[i].s;
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
kpress(XKeyEvent *e) {
|
kpress(XEvent *ev) {
|
||||||
|
XKeyEvent *e = &ev->xkey;
|
||||||
KeySym ksym;
|
KeySym ksym;
|
||||||
char buf[32];
|
char buf[32];
|
||||||
int len;
|
int len;
|
||||||
int meta;
|
int meta;
|
||||||
int shift;
|
int shift;
|
||||||
char* skmap;
|
|
||||||
|
|
||||||
meta = e->state & Mod1Mask;
|
meta = e->state & Mod1Mask;
|
||||||
shift = e->state & ShiftMask;
|
shift = e->state & ShiftMask;
|
||||||
len = XLookupString(e, buf, sizeof(buf), &ksym, NULL);
|
len = XLookupString(e, buf, sizeof(buf), &ksym, NULL);
|
||||||
if(skmap = kmap(ksym))
|
if(key[ksym])
|
||||||
ttywrite(skmap, strlen(skmap));
|
ttywrite(key[ksym], strlen(key[ksym]));
|
||||||
else if(len > 0) {
|
else if(len > 0) {
|
||||||
buf[sizeof(buf)-1] = '\0';
|
buf[sizeof(buf)-1] = '\0';
|
||||||
if(meta && len == 1)
|
if(meta && len == 1)
|
||||||
|
@ -1054,7 +1057,6 @@ resize(XEvent *e) {
|
||||||
|
|
||||||
void
|
void
|
||||||
run(void) {
|
run(void) {
|
||||||
int ret;
|
|
||||||
XEvent ev;
|
XEvent ev;
|
||||||
fd_set rfd;
|
fd_set rfd;
|
||||||
int xfd = XConnectionNumber(xw.dis);
|
int xfd = XConnectionNumber(xw.dis);
|
||||||
|
@ -1067,34 +1069,20 @@ run(void) {
|
||||||
FD_ZERO(&rfd);
|
FD_ZERO(&rfd);
|
||||||
FD_SET(cmdfd, &rfd);
|
FD_SET(cmdfd, &rfd);
|
||||||
FD_SET(xfd, &rfd);
|
FD_SET(xfd, &rfd);
|
||||||
XFlush(xw.dis);
|
if(select(MAX(xfd, cmdfd)+1, &rfd, NULL, NULL, NULL) == -1) {
|
||||||
ret = select(MAX(xfd, cmdfd)+1, &rfd, NULL, NULL, NULL);
|
if(errno == EINTR)
|
||||||
|
continue;
|
||||||
if(ret < 0)
|
|
||||||
die("select failed: %s\n", SERRNO);
|
die("select failed: %s\n", SERRNO);
|
||||||
|
|
||||||
if(FD_ISSET(xfd, &rfd)) {
|
|
||||||
while(XPending(xw.dis)) {
|
|
||||||
XNextEvent(xw.dis, &ev);
|
|
||||||
switch (ev.type) {
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
case KeyPress:
|
|
||||||
kpress(&ev.xkey);
|
|
||||||
break;
|
|
||||||
case Expose:
|
|
||||||
draw(SCredraw);
|
|
||||||
break;
|
|
||||||
case ConfigureNotify:
|
|
||||||
resize(&ev);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(FD_ISSET(cmdfd, &rfd)) {
|
if(FD_ISSET(cmdfd, &rfd)) {
|
||||||
ttyread();
|
ttyread();
|
||||||
draw(SCupdate);
|
draw(SCupdate);
|
||||||
}
|
}
|
||||||
|
while(XPending(xw.dis)) {
|
||||||
|
XNextEvent(xw.dis, &ev);
|
||||||
|
if(handler[ev.type])
|
||||||
|
(handler[ev.type])(&ev);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue