aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Lohmann <20h@r-36.net>2012-11-02 19:56:02 +0100
committerChristoph Lohmann <20h@r-36.net>2012-11-02 19:56:02 +0100
commitdcf0955466fad18da645f6cfc5ba36fc14d78f8e (patch)
tree856bb5710a2396edd8742b3a8316566aa1b2b8db
parent48389be574e1b152aa92e4ae6a415214374b472e (diff)
downloadst-patched-dcf0955466fad18da645f6cfc5ba36fc14d78f8e.tar.bz2
st-patched-dcf0955466fad18da645f6cfc5ba36fc14d78f8e.tar.xz
st-patched-dcf0955466fad18da645f6cfc5ba36fc14d78f8e.zip
Moving to the dwm config.h variable usage.
-rw-r--r--config.def.h60
-rw-r--r--st.c80
2 files changed, 72 insertions, 68 deletions
diff --git a/config.def.h b/config.def.h
index a8f48ea..1ba6d8e 100644
--- a/config.def.h
+++ b/config.def.h
@@ -1,11 +1,19 @@
1/* See LICENSE file for copyright and license details. */
1 2
2#define FONT "Liberation Mono:pixelsize=12:antialias=false:autohint=false" 3/* appearance */
4static char font[] = "Liberation Mono:pixelsize=12:antialias=false:autohint=false";
5static unsigned int borderpx = 2;
6static char shell[] = "/bin/sh";
3 7
4/* Space in pixels around the terminal buffer */ 8/* double-click timeout (in milliseconds) between clicks for selection */
5#define BORDER 2 9static unsigned int doubleclicktimeout = 300;
10static unsigned int tripleclicktimeout = 600;
11
12/* TERM value */
13static char termname[] = "st-256color";
14
15static unsigned int tabspaces = 8;
6 16
7/* Default shell to use if SHELL is not set in the env */
8#define SHELL "/bin/sh"
9 17
10/* Terminal colors (16 first used in escape sequence) */ 18/* Terminal colors (16 first used in escape sequence) */
11static const char *colorname[] = { 19static const char *colorname[] = {
@@ -36,21 +44,26 @@ static const char *colorname[] = {
36 "#333333", 44 "#333333",
37}; 45};
38 46
39/* Default colors (colorname index)
40 foreground, background, cursor, unfocused cursor */
41#define DefaultFG 7
42#define DefaultBG 0
43#define DefaultCS 256
44#define DefaultUCS 257
45
46/* Special keys (change & recompile st.info accordingly)
47 Keep in mind that kpress() in st.c hardcodes some keys.
48
49 Mask value:
50 * Use XK_ANY_MOD to match the key no matter modifiers state
51 * Use XK_NO_MOD to match the key alone (no modifiers)
52 47
53 key, mask, output */ 48/*
49 * Default colors (colorname index)
50 * foreground, background, cursor, unfocused cursor
51 */
52static unsigned int defaultfg = 7;
53static unsigned int defaultbg = 0;
54static unsigned int defaultcs = 256;
55static unsigned int defaultucs = 257;
56
57/*
58 * Special keys (change & recompile st.info accordingly)
59 * Keep in mind that kpress() in st.c hardcodes some keys.
60 *
61 * Mask value:
62 * * Use XK_ANY_MOD to match the key no matter modifiers state
63 * * Use XK_NO_MOD to match the key alone (no modifiers)
64 */
65
66/* key, mask, output */
54static Key key[] = { 67static Key key[] = {
55 { XK_BackSpace, XK_NO_MOD, "\177" }, 68 { XK_BackSpace, XK_NO_MOD, "\177" },
56 { XK_Insert, XK_NO_MOD, "\033[2~" }, 69 { XK_Insert, XK_NO_MOD, "\033[2~" },
@@ -82,12 +95,3 @@ static Shortcut shortcuts[] = {
82 { MODKEY|ShiftMask, XK_Next, xzoom, {.i = -1} }, 95 { MODKEY|ShiftMask, XK_Next, xzoom, {.i = -1} },
83}; 96};
84 97
85/* Set TERM to this */
86#define TNAME "st-256color"
87
88/* double-click timeout (in milliseconds) between clicks for selection */
89#define DOUBLECLICK_TIMEOUT 300
90#define TRIPLECLICK_TIMEOUT (2*DOUBLECLICK_TIMEOUT)
91
92#define TAB 8
93
diff --git a/st.c b/st.c
index c4ff67c..cdf1fdc 100644
--- a/st.c
+++ b/st.c
@@ -72,8 +72,8 @@
72#define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg) 72#define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg)
73#define IS_SET(flag) (term.mode & (flag)) 73#define IS_SET(flag) (term.mode & (flag))
74#define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + (t1.tv_usec-t2.tv_usec)/1000) 74#define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + (t1.tv_usec-t2.tv_usec)/1000)
75#define X2COL(x) (((x) - BORDER)/xw.cw) 75#define X2COL(x) (((x) - borderpx)/xw.cw)
76#define Y2ROW(y) (((y) - BORDER)/xw.ch) 76#define Y2ROW(y) (((y) - borderpx)/xw.ch)
77 77
78#define VT102ID "\033[?6c" 78#define VT102ID "\033[?6c"
79 79
@@ -803,13 +803,13 @@ brelease(XEvent *e) {
803 sel.bx = -1; 803 sel.bx = -1;
804 gettimeofday(&now, NULL); 804 gettimeofday(&now, NULL);
805 805
806 if(TIMEDIFF(now, sel.tclick2) <= TRIPLECLICK_TIMEOUT) { 806 if(TIMEDIFF(now, sel.tclick2) <= tripleclicktimeout) {
807 /* triple click on the line */ 807 /* triple click on the line */
808 sel.b.x = sel.bx = 0; 808 sel.b.x = sel.bx = 0;
809 sel.e.x = sel.ex = term.col; 809 sel.e.x = sel.ex = term.col;
810 sel.b.y = sel.e.y = sel.ey; 810 sel.b.y = sel.e.y = sel.ey;
811 selcopy(); 811 selcopy();
812 } else if(TIMEDIFF(now, sel.tclick1) <= DOUBLECLICK_TIMEOUT) { 812 } else if(TIMEDIFF(now, sel.tclick1) <= doubleclicktimeout) {
813 /* double click to select word */ 813 /* double click to select word */
814 sel.bx = sel.ex; 814 sel.bx = sel.ex;
815 while(sel.bx > 0 && term.line[sel.ey][sel.bx-1].state & GLYPH_SET && 815 while(sel.bx > 0 && term.line[sel.ey][sel.bx-1].state & GLYPH_SET &&
@@ -894,8 +894,8 @@ execsh(void) {
894 signal(SIGTERM, SIG_DFL); 894 signal(SIGTERM, SIG_DFL);
895 signal(SIGALRM, SIG_DFL); 895 signal(SIGALRM, SIG_DFL);
896 896
897 DEFAULT(envshell, SHELL); 897 DEFAULT(envshell, shell);
898 putenv("TERM="TNAME); 898 setenv("TERM", termname, 1);
899 args = opt_cmd ? opt_cmd : (char *[]){envshell, "-i", NULL}; 899 args = opt_cmd ? opt_cmd : (char *[]){envshell, "-i", NULL};
900 execvp(args[0], args); 900 execvp(args[0], args);
901 exit(EXIT_FAILURE); 901 exit(EXIT_FAILURE);
@@ -1045,12 +1045,12 @@ treset(void) {
1045 1045
1046 term.c = (TCursor){{ 1046 term.c = (TCursor){{
1047 .mode = ATTR_NULL, 1047 .mode = ATTR_NULL,
1048 .fg = DefaultFG, 1048 .fg = defaultfg,
1049 .bg = DefaultBG 1049 .bg = defaultbg
1050 }, .x = 0, .y = 0, .state = CURSOR_DEFAULT}; 1050 }, .x = 0, .y = 0, .state = CURSOR_DEFAULT};
1051 1051
1052 memset(term.tabs, 0, term.col * sizeof(*term.tabs)); 1052 memset(term.tabs, 0, term.col * sizeof(*term.tabs));
1053 for(i = TAB; i < term.col; i += TAB) 1053 for(i = tabspaces; i < term.col; i += tabspaces)
1054 term.tabs[i] = 1; 1054 term.tabs[i] = 1;
1055 term.top = 0; 1055 term.top = 0;
1056 term.bot = term.row - 1; 1056 term.bot = term.row - 1;
@@ -1310,8 +1310,8 @@ tsetattr(int *attr, int l) {
1310 case 0: 1310 case 0:
1311 term.c.attr.mode &= ~(ATTR_REVERSE | ATTR_UNDERLINE | ATTR_BOLD \ 1311 term.c.attr.mode &= ~(ATTR_REVERSE | ATTR_UNDERLINE | ATTR_BOLD \
1312 | ATTR_ITALIC | ATTR_BLINK); 1312 | ATTR_ITALIC | ATTR_BLINK);
1313 term.c.attr.fg = DefaultFG; 1313 term.c.attr.fg = defaultfg;
1314 term.c.attr.bg = DefaultBG; 1314 term.c.attr.bg = defaultbg;
1315 break; 1315 break;
1316 case 1: 1316 case 1:
1317 term.c.attr.mode |= ATTR_BOLD; 1317 term.c.attr.mode |= ATTR_BOLD;
@@ -1361,7 +1361,7 @@ tsetattr(int *attr, int l) {
1361 } 1361 }
1362 break; 1362 break;
1363 case 39: 1363 case 39:
1364 term.c.attr.fg = DefaultFG; 1364 term.c.attr.fg = defaultfg;
1365 break; 1365 break;
1366 case 48: 1366 case 48:
1367 if(i + 2 < l && attr[i + 1] == 5) { 1367 if(i + 2 < l && attr[i + 1] == 5) {
@@ -1380,7 +1380,7 @@ tsetattr(int *attr, int l) {
1380 } 1380 }
1381 break; 1381 break;
1382 case 49: 1382 case 49:
1383 term.c.attr.bg = DefaultBG; 1383 term.c.attr.bg = defaultbg;
1384 break; 1384 break;
1385 default: 1385 default:
1386 if(BETWEEN(attr[i], 30, 37)) { 1386 if(BETWEEN(attr[i], 30, 37)) {
@@ -2091,7 +2091,7 @@ tresize(int col, int row) {
2091 memset(bp, 0, sizeof(*term.tabs) * (col - term.col)); 2091 memset(bp, 0, sizeof(*term.tabs) * (col - term.col));
2092 while(--bp > term.tabs && !*bp) 2092 while(--bp > term.tabs && !*bp)
2093 /* nothing */ ; 2093 /* nothing */ ;
2094 for(bp += TAB; bp < term.tabs + col; bp += TAB) 2094 for(bp += tabspaces; bp < term.tabs + col; bp += tabspaces)
2095 *bp = 1; 2095 *bp = 1;
2096 } 2096 }
2097 /* update terminal size */ 2097 /* update terminal size */
@@ -2107,8 +2107,8 @@ tresize(int col, int row) {
2107 2107
2108void 2108void
2109xresize(int col, int row) { 2109xresize(int col, int row) {
2110 xw.tw = MAX(1, 2*BORDER + col * xw.cw); 2110 xw.tw = MAX(1, 2*borderpx + col * xw.cw);
2111 xw.th = MAX(1, 2*BORDER + row * xw.ch); 2111 xw.th = MAX(1, 2*borderpx + row * xw.ch);
2112 2112
2113 XftDrawChange(xw.xft_draw, xw.buf); 2113 XftDrawChange(xw.xft_draw, xw.buf);
2114} 2114}
@@ -2154,9 +2154,9 @@ xloadcols(void) {
2154void 2154void
2155xtermclear(int col1, int row1, int col2, int row2) { 2155xtermclear(int col1, int row1, int col2, int row2) {
2156 XftDrawRect(xw.xft_draw, 2156 XftDrawRect(xw.xft_draw,
2157 &dc.xft_col[IS_SET(MODE_REVERSE) ? DefaultFG : DefaultBG], 2157 &dc.xft_col[IS_SET(MODE_REVERSE) ? defaultfg : defaultbg],
2158 BORDER + col1 * xw.cw, 2158 borderpx + col1 * xw.cw,
2159 BORDER + row1 * xw.ch, 2159 borderpx + row1 * xw.ch,
2160 (col2-col1+1) * xw.cw, 2160 (col2-col1+1) * xw.cw,
2161 (row2-row1+1) * xw.ch); 2161 (row2-row1+1) * xw.ch);
2162} 2162}
@@ -2167,13 +2167,13 @@ xtermclear(int col1, int row1, int col2, int row2) {
2167void 2167void
2168xclear(int x1, int y1, int x2, int y2) { 2168xclear(int x1, int y1, int x2, int y2) {
2169 XftDrawRect(xw.xft_draw, 2169 XftDrawRect(xw.xft_draw,
2170 &dc.xft_col[IS_SET(MODE_REVERSE) ? DefaultFG : DefaultBG], 2170 &dc.xft_col[IS_SET(MODE_REVERSE) ? defaultfg : defaultbg],
2171 x1, y1, x2-x1, y2-y1); 2171 x1, y1, x2-x1, y2-y1);
2172} 2172}
2173 2173
2174void 2174void
2175xhints(void) { 2175xhints(void) {
2176 XClassHint class = {opt_class ? opt_class : TNAME, TNAME}; 2176 XClassHint class = {opt_class ? opt_class : termname, termname};
2177 XWMHints wm = {.flags = InputHint, .input = 1}; 2177 XWMHints wm = {.flags = InputHint, .input = 1};
2178 XSizeHints *sizeh = NULL; 2178 XSizeHints *sizeh = NULL;
2179 2179
@@ -2184,8 +2184,8 @@ xhints(void) {
2184 sizeh->width = xw.w; 2184 sizeh->width = xw.w;
2185 sizeh->height_inc = xw.ch; 2185 sizeh->height_inc = xw.ch;
2186 sizeh->width_inc = xw.cw; 2186 sizeh->width_inc = xw.cw;
2187 sizeh->base_height = 2*BORDER; 2187 sizeh->base_height = 2*borderpx;
2188 sizeh->base_width = 2*BORDER; 2188 sizeh->base_width = 2*borderpx;
2189 } else { 2189 } else {
2190 sizeh->flags = PMaxSize | PMinSize; 2190 sizeh->flags = PMaxSize | PMinSize;
2191 sizeh->min_width = sizeh->max_width = xw.fw; 2191 sizeh->min_width = sizeh->max_width = xw.fw;
@@ -2293,7 +2293,7 @@ xinit(void) {
2293 xw.vis = XDefaultVisual(xw.dpy, xw.scr); 2293 xw.vis = XDefaultVisual(xw.dpy, xw.scr);
2294 2294
2295 /* font */ 2295 /* font */
2296 usedfont = (opt_font == NULL)? FONT : opt_font; 2296 usedfont = (opt_font == NULL)? font : opt_font;
2297 xloadfonts(usedfont, 0); 2297 xloadfonts(usedfont, 0);
2298 2298
2299 /* colors */ 2299 /* colors */
@@ -2313,14 +2313,14 @@ xinit(void) {
2313 xw.w = xw.fw; 2313 xw.w = xw.fw;
2314 } else { 2314 } else {
2315 /* window - default size */ 2315 /* window - default size */
2316 xw.h = 2*BORDER + term.row * xw.ch; 2316 xw.h = 2*borderpx + term.row * xw.ch;
2317 xw.w = 2*BORDER + term.col * xw.cw; 2317 xw.w = 2*borderpx + term.col * xw.cw;
2318 xw.fx = 0; 2318 xw.fx = 0;
2319 xw.fy = 0; 2319 xw.fy = 0;
2320 } 2320 }
2321 2321
2322 attrs.background_pixel = dc.xft_col[DefaultBG].pixel; 2322 attrs.background_pixel = dc.xft_col[defaultbg].pixel;
2323 attrs.border_pixel = dc.xft_col[DefaultBG].pixel; 2323 attrs.border_pixel = dc.xft_col[defaultbg].pixel;
2324 attrs.bit_gravity = NorthWestGravity; 2324 attrs.bit_gravity = NorthWestGravity;
2325 attrs.event_mask = FocusChangeMask | KeyPressMask 2325 attrs.event_mask = FocusChangeMask | KeyPressMask
2326 | ExposureMask | VisibilityChangeMask | StructureNotifyMask 2326 | ExposureMask | VisibilityChangeMask | StructureNotifyMask
@@ -2370,7 +2370,7 @@ xinit(void) {
2370 2370
2371void 2371void
2372xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) { 2372xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
2373 int winx = BORDER + x * xw.cw, winy = BORDER + y * xw.ch, 2373 int winx = borderpx + x * xw.cw, winy = borderpx + y * xw.ch,
2374 width = charlen * xw.cw; 2374 width = charlen * xw.cw;
2375 Font *font = &dc.font; 2375 Font *font = &dc.font;
2376 XGlyphInfo extents; 2376 XGlyphInfo extents;
@@ -2407,8 +2407,8 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
2407 font = &dc.ibfont; 2407 font = &dc.ibfont;
2408 2408
2409 if(IS_SET(MODE_REVERSE)) { 2409 if(IS_SET(MODE_REVERSE)) {
2410 if(fg == &dc.xft_col[DefaultFG]) { 2410 if(fg == &dc.xft_col[defaultfg]) {
2411 fg = &dc.xft_col[DefaultBG]; 2411 fg = &dc.xft_col[defaultbg];
2412 } else { 2412 } else {
2413 colfg.red = ~fg->color.red; 2413 colfg.red = ~fg->color.red;
2414 colfg.green = ~fg->color.green; 2414 colfg.green = ~fg->color.green;
@@ -2418,8 +2418,8 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
2418 fg = &revfg; 2418 fg = &revfg;
2419 } 2419 }
2420 2420
2421 if(bg == &dc.xft_col[DefaultBG]) { 2421 if(bg == &dc.xft_col[defaultbg]) {
2422 bg = &dc.xft_col[DefaultFG]; 2422 bg = &dc.xft_col[defaultfg];
2423 } else { 2423 } else {
2424 colbg.red = ~bg->color.red; 2424 colbg.red = ~bg->color.red;
2425 colbg.green = ~bg->color.green; 2425 colbg.green = ~bg->color.green;
@@ -2436,7 +2436,7 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
2436 2436
2437 /* Intelligent cleaning up of the borders. */ 2437 /* Intelligent cleaning up of the borders. */
2438 if(x == 0) { 2438 if(x == 0) {
2439 xclear(0, (y == 0)? 0 : winy, BORDER, 2439 xclear(0, (y == 0)? 0 : winy, borderpx,
2440 winy + xw.ch + (y == term.row-1)? xw.h : 0); 2440 winy + xw.ch + (y == term.row-1)? xw.h : 0);
2441 } 2441 }
2442 if(x + charlen >= term.col-1) { 2442 if(x + charlen >= term.col-1) {
@@ -2444,7 +2444,7 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
2444 (y == term.row-1)? xw.h : (winy + xw.ch)); 2444 (y == term.row-1)? xw.h : (winy + xw.ch));
2445 } 2445 }
2446 if(y == 0) 2446 if(y == 0)
2447 xclear(winx, 0, winx + width, BORDER); 2447 xclear(winx, 0, winx + width, borderpx);
2448 if(y == term.row-1) 2448 if(y == term.row-1)
2449 xclear(winx, winy + xw.ch, winx + width, xw.h); 2449 xclear(winx, winy + xw.ch, winx + width, xw.h);
2450 2450
@@ -2462,7 +2462,7 @@ void
2462xdrawcursor(void) { 2462xdrawcursor(void) {
2463 static int oldx = 0, oldy = 0; 2463 static int oldx = 0, oldy = 0;
2464 int sl; 2464 int sl;
2465 Glyph g = {{' '}, ATTR_NULL, DefaultBG, DefaultCS, 0}; 2465 Glyph g = {{' '}, ATTR_NULL, defaultbg, defaultcs, 0};
2466 2466
2467 LIMIT(oldx, 0, term.col-1); 2467 LIMIT(oldx, 0, term.col-1);
2468 LIMIT(oldy, 0, term.row-1); 2468 LIMIT(oldy, 0, term.row-1);
@@ -2482,10 +2482,10 @@ xdrawcursor(void) {
2482 /* draw the new one */ 2482 /* draw the new one */
2483 if(!(term.c.state & CURSOR_HIDE)) { 2483 if(!(term.c.state & CURSOR_HIDE)) {
2484 if(!(xw.state & WIN_FOCUSED)) 2484 if(!(xw.state & WIN_FOCUSED))
2485 g.bg = DefaultUCS; 2485 g.bg = defaultucs;
2486 2486
2487 if(IS_SET(MODE_REVERSE)) 2487 if(IS_SET(MODE_REVERSE))
2488 g.mode |= ATTR_REVERSE, g.fg = DefaultCS, g.bg = DefaultFG; 2488 g.mode |= ATTR_REVERSE, g.fg = defaultcs, g.bg = defaultfg;
2489 2489
2490 sl = utf8size(g.c); 2490 sl = utf8size(g.c);
2491 xdraws(g.c, g, term.c.x, term.c.y, 1, sl); 2491 xdraws(g.c, g, term.c.x, term.c.y, 1, sl);
@@ -2720,8 +2720,8 @@ cresize(int width, int height)
2720 if(height != 0) 2720 if(height != 0)
2721 xw.h = height; 2721 xw.h = height;
2722 2722
2723 col = (xw.w - 2*BORDER) / xw.cw; 2723 col = (xw.w - 2*borderpx) / xw.cw;
2724 row = (xw.h - 2*BORDER) / xw.ch; 2724 row = (xw.h - 2*borderpx) / xw.ch;
2725 if(col == term.col && row == term.row) 2725 if(col == term.col && row == term.row)
2726 return; 2726 return;
2727 2727