diff options
author | Aurélien Aptel <aurelien.aptel@gmail.com> | 2011-04-26 20:22:15 +0200 |
---|---|---|
committer | Aurélien Aptel <aurelien.aptel@gmail.com> | 2011-04-26 20:22:15 +0200 |
commit | 3d0eeac7a8e69ca5641f48c6ac48c51f41db0ed1 (patch) | |
tree | 436416f97943d2b1a861f08df2eebcc9cd7ae339 | |
parent | 31ba817cc3484e0cd41f06ed653ac1b7429d938d (diff) | |
download | st-patched-3d0eeac7a8e69ca5641f48c6ac48c51f41db0ed1.tar.bz2 st-patched-3d0eeac7a8e69ca5641f48c6ac48c51f41db0ed1.tar.xz st-patched-3d0eeac7a8e69ca5641f48c6ac48c51f41db0ed1.zip |
cleanup.
-rw-r--r-- | st.c | 104 |
1 files changed, 27 insertions, 77 deletions
@@ -163,8 +163,8 @@ typedef struct { | |||
163 | 163 | ||
164 | #include "config.h" | 164 | #include "config.h" |
165 | 165 | ||
166 | static void die(const char *errstr, ...); | 166 | static void die(const char*, ...); |
167 | static void draw(); | 167 | static void draw(void); |
168 | static void drawregion(int, int, int, int); | 168 | static void drawregion(int, int, int, int); |
169 | static void execsh(void); | 169 | static void execsh(void); |
170 | static void sigchld(int); | 170 | static void sigchld(int); |
@@ -363,11 +363,11 @@ int | |||
363 | utf8size(char *s) { | 363 | utf8size(char *s) { |
364 | unsigned char c = *s; | 364 | unsigned char c = *s; |
365 | 365 | ||
366 | if (~c&B7) | 366 | if(~c&B7) |
367 | return 1; | 367 | return 1; |
368 | else if ((c&(B7|B6|B5)) == (B7|B6)) | 368 | else if((c&(B7|B6|B5)) == (B7|B6)) |
369 | return 2; | 369 | return 2; |
370 | else if ((c&(B7|B6|B5|B4)) == (B7|B6|B5)) | 370 | else if((c&(B7|B6|B5|B4)) == (B7|B6|B5)) |
371 | return 3; | 371 | return 3; |
372 | else | 372 | else |
373 | return 4; | 373 | return 4; |
@@ -523,20 +523,25 @@ xsetsel(char *str) { | |||
523 | void | 523 | void |
524 | brelease(XEvent *e) { | 524 | brelease(XEvent *e) { |
525 | int b; | 525 | int b; |
526 | |||
526 | sel.mode = 0; | 527 | sel.mode = 0; |
527 | getbuttoninfo(e, &b, &sel.ex, &sel.ey); | 528 | getbuttoninfo(e, &b, &sel.ex, &sel.ey); |
528 | |||
529 | if(sel.bx == sel.ex && sel.by == sel.ey) { | 529 | if(sel.bx == sel.ex && sel.by == sel.ey) { |
530 | sel.bx = -1; | 530 | sel.bx = -1; |
531 | if(b == 2) | 531 | if(b == 2) |
532 | selpaste(); | 532 | selpaste(); |
533 | |||
534 | else if(b == 1) { | 533 | else if(b == 1) { |
535 | /* double click to select word */ | ||
536 | struct timeval now; | 534 | struct timeval now; |
537 | gettimeofday(&now, NULL); | 535 | gettimeofday(&now, NULL); |
538 | 536 | ||
539 | if(TIMEDIFFERENCE(now, sel.tclick1) <= DOUBLECLICK_TIMEOUT) { | 537 | if(TIMEDIFFERENCE(now, sel.tclick2) <= TRIPLECLICK_TIMEOUT) { |
538 | /* triple click on the line */ | ||
539 | sel.b.x = sel.bx = 0; | ||
540 | sel.e.x = sel.ex = term.col; | ||
541 | sel.b.y = sel.e.y = sel.ey; | ||
542 | selcopy(); | ||
543 | } else if(TIMEDIFFERENCE(now, sel.tclick1) <= DOUBLECLICK_TIMEOUT) { | ||
544 | /* double click to select word */ | ||
540 | sel.bx = sel.ex; | 545 | sel.bx = sel.ex; |
541 | while(term.line[sel.ey][sel.bx-1].state & GLYPH_SET && | 546 | while(term.line[sel.ey][sel.bx-1].state & GLYPH_SET && |
542 | term.line[sel.ey][sel.bx-1].c[0] != ' ') sel.bx--; | 547 | term.line[sel.ey][sel.bx-1].c[0] != ' ') sel.bx--; |
@@ -547,19 +552,9 @@ brelease(XEvent *e) { | |||
547 | sel.b.y = sel.e.y = sel.ey; | 552 | sel.b.y = sel.e.y = sel.ey; |
548 | selcopy(); | 553 | selcopy(); |
549 | } | 554 | } |
550 | |||
551 | /* triple click on the line */ | ||
552 | if(TIMEDIFFERENCE(now, sel.tclick2) <= TRIPLECLICK_TIMEOUT) { | ||
553 | sel.b.x = sel.bx = 0; | ||
554 | sel.e.x = sel.ex = term.col; | ||
555 | sel.b.y = sel.e.y = sel.ey; | ||
556 | selcopy(); | ||
557 | } | ||
558 | } | 555 | } |
559 | } else { | 556 | } else if(b == 1) |
560 | if(b == 1) | 557 | selcopy(); |
561 | selcopy(); | ||
562 | } | ||
563 | memcpy(&sel.tclick2, &sel.tclick1, sizeof(struct timeval)); | 558 | memcpy(&sel.tclick2, &sel.tclick1, sizeof(struct timeval)); |
564 | gettimeofday(&sel.tclick1, NULL); | 559 | gettimeofday(&sel.tclick1, NULL); |
565 | draw(); | 560 | draw(); |
@@ -683,10 +678,6 @@ ttyread(void) { | |||
683 | 678 | ||
684 | void | 679 | void |
685 | ttywrite(const char *s, size_t n) { | 680 | ttywrite(const char *s, size_t n) { |
686 | {size_t nn; | ||
687 | for(nn = 0; nn < n; nn++) | ||
688 | dump(s[nn]); | ||
689 | } | ||
690 | if(write(cmdfd, s, n) == -1) | 681 | if(write(cmdfd, s, n) == -1) |
691 | die("write error on tty: %s\n", SERRNO); | 682 | die("write error on tty: %s\n", SERRNO); |
692 | } | 683 | } |
@@ -921,9 +912,9 @@ tsetattr(int *attr, int l) { | |||
921 | term.c.attr.mode &= ~ATTR_REVERSE; | 912 | term.c.attr.mode &= ~ATTR_REVERSE; |
922 | break; | 913 | break; |
923 | case 38: | 914 | case 38: |
924 | if (i + 2 < l && attr[i + 1] == 5) { | 915 | if(i + 2 < l && attr[i + 1] == 5) { |
925 | i += 2; | 916 | i += 2; |
926 | if (BETWEEN(attr[i], 0, 255)) | 917 | if(BETWEEN(attr[i], 0, 255)) |
927 | term.c.attr.fg = attr[i]; | 918 | term.c.attr.fg = attr[i]; |
928 | else | 919 | else |
929 | fprintf(stderr, "erresc: bad fgcolor %d\n", attr[i]); | 920 | fprintf(stderr, "erresc: bad fgcolor %d\n", attr[i]); |
@@ -935,9 +926,9 @@ tsetattr(int *attr, int l) { | |||
935 | term.c.attr.fg = DefaultFG; | 926 | term.c.attr.fg = DefaultFG; |
936 | break; | 927 | break; |
937 | case 48: | 928 | case 48: |
938 | if (i + 2 < l && attr[i + 1] == 5) { | 929 | if(i + 2 < l && attr[i + 1] == 5) { |
939 | i += 2; | 930 | i += 2; |
940 | if (BETWEEN(attr[i], 0, 255)) | 931 | if(BETWEEN(attr[i], 0, 255)) |
941 | term.c.attr.bg = attr[i]; | 932 | term.c.attr.bg = attr[i]; |
942 | else | 933 | else |
943 | fprintf(stderr, "erresc: bad bgcolor %d\n", attr[i]); | 934 | fprintf(stderr, "erresc: bad bgcolor %d\n", attr[i]); |
@@ -1348,7 +1339,6 @@ tputc(char *c) { | |||
1348 | tmoveto(term.c.x+1, term.c.y); | 1339 | tmoveto(term.c.x+1, term.c.y); |
1349 | else | 1340 | else |
1350 | term.c.state |= CURSOR_WRAPNEXT; | 1341 | term.c.state |= CURSOR_WRAPNEXT; |
1351 | break; | ||
1352 | } | 1342 | } |
1353 | } | 1343 | } |
1354 | } | 1344 | } |
@@ -1447,7 +1437,7 @@ xloadcols(void) { | |||
1447 | unsigned long white = WhitePixel(xw.dpy, xw.scr); | 1437 | unsigned long white = WhitePixel(xw.dpy, xw.scr); |
1448 | 1438 | ||
1449 | for(i = 0; i < 16; i++) { | 1439 | for(i = 0; i < 16; i++) { |
1450 | if (!XAllocNamedColor(xw.dpy, xw.cmap, colorname[i], &color, &color)) { | 1440 | if(!XAllocNamedColor(xw.dpy, xw.cmap, colorname[i], &color, &color)) { |
1451 | dc.col[i] = white; | 1441 | dc.col[i] = white; |
1452 | fprintf(stderr, "Could not allocate color '%s'\n", colorname[i]); | 1442 | fprintf(stderr, "Could not allocate color '%s'\n", colorname[i]); |
1453 | } else | 1443 | } else |
@@ -1461,7 +1451,7 @@ xloadcols(void) { | |||
1461 | color.red = r == 0 ? 0 : 0x3737 + 0x2828 * r; | 1451 | color.red = r == 0 ? 0 : 0x3737 + 0x2828 * r; |
1462 | color.green = g == 0 ? 0 : 0x3737 + 0x2828 * g; | 1452 | color.green = g == 0 ? 0 : 0x3737 + 0x2828 * g; |
1463 | color.blue = b == 0 ? 0 : 0x3737 + 0x2828 * b; | 1453 | color.blue = b == 0 ? 0 : 0x3737 + 0x2828 * b; |
1464 | if (!XAllocColor(xw.dpy, xw.cmap, &color)) { | 1454 | if(!XAllocColor(xw.dpy, xw.cmap, &color)) { |
1465 | dc.col[i] = white; | 1455 | dc.col[i] = white; |
1466 | fprintf(stderr, "Could not allocate color %d\n", i); | 1456 | fprintf(stderr, "Could not allocate color %d\n", i); |
1467 | } else | 1457 | } else |
@@ -1488,8 +1478,7 @@ xclear(int x1, int y1, int x2, int y2) { | |||
1488 | } | 1478 | } |
1489 | 1479 | ||
1490 | void | 1480 | void |
1491 | xhints(void) | 1481 | xhints(void) { |
1492 | { | ||
1493 | XClassHint class = {opt_class ? opt_class : TNAME, TNAME}; | 1482 | XClassHint class = {opt_class ? opt_class : TNAME, TNAME}; |
1494 | XWMHints wm = {.flags = InputHint, .input = 1}; | 1483 | XWMHints wm = {.flags = InputHint, .input = 1}; |
1495 | XSizeHints size = { | 1484 | XSizeHints size = { |
@@ -1505,8 +1494,7 @@ xhints(void) | |||
1505 | } | 1494 | } |
1506 | 1495 | ||
1507 | XFontSet | 1496 | XFontSet |
1508 | xinitfont(char *fontstr) | 1497 | xinitfont(char *fontstr) { |
1509 | { | ||
1510 | XFontSet set; | 1498 | XFontSet set; |
1511 | char *def, **missing; | 1499 | char *def, **missing; |
1512 | int n; | 1500 | int n; |
@@ -1522,8 +1510,7 @@ xinitfont(char *fontstr) | |||
1522 | } | 1510 | } |
1523 | 1511 | ||
1524 | void | 1512 | void |
1525 | xgetfontinfo(XFontSet set, int *ascent, int *descent, short *lbearing, short *rbearing) | 1513 | xgetfontinfo(XFontSet set, int *ascent, int *descent, short *lbearing, short *rbearing) { |
1526 | { | ||
1527 | XFontStruct **xfonts; | 1514 | XFontStruct **xfonts; |
1528 | char **font_names; | 1515 | char **font_names; |
1529 | int i, n; | 1516 | int i, n; |
@@ -1540,8 +1527,7 @@ xgetfontinfo(XFontSet set, int *ascent, int *descent, short *lbearing, short *rb | |||
1540 | } | 1527 | } |
1541 | 1528 | ||
1542 | void | 1529 | void |
1543 | initfonts(char *fontstr, char *bfontstr) | 1530 | initfonts(char *fontstr, char *bfontstr) { |
1544 | { | ||
1545 | if((dc.font.set = xinitfont(fontstr)) == NULL || | 1531 | if((dc.font.set = xinitfont(fontstr)) == NULL || |
1546 | (dc.bfont.set = xinitfont(bfontstr)) == NULL) | 1532 | (dc.bfont.set = xinitfont(bfontstr)) == NULL) |
1547 | die("Can't load font %s\n", dc.font.set ? BOLDFONT : FONT); | 1533 | die("Can't load font %s\n", dc.font.set ? BOLDFONT : FONT); |
@@ -1674,40 +1660,6 @@ xdrawcursor(void) { | |||
1674 | } | 1660 | } |
1675 | } | 1661 | } |
1676 | 1662 | ||
1677 | #ifdef DEBUG | ||
1678 | /* basic drawing routines */ | ||
1679 | void | ||
1680 | xdrawc(int x, int y, Glyph g) { | ||
1681 | int sl = utf8size(g.c); | ||
1682 | XRectangle r = { x * xw.cw, y * xw.ch, xw.cw, xw.ch }; | ||
1683 | XSetBackground(xw.dpy, dc.gc, dc.col[g.bg]); | ||
1684 | XSetForeground(xw.dpy, dc.gc, dc.col[g.fg]); | ||
1685 | XmbDrawImageString(xw.dpy, xw.buf, g.mode&ATTR_BOLD?dc.bfont.fs:dc.font.fs, | ||
1686 | dc.gc, r.x, r.y+dc.font.ascent, g.c, sl); | ||
1687 | } | ||
1688 | |||
1689 | void | ||
1690 | drawregion(int x0, int x1, int y0, int y1) { | ||
1691 | draw(); | ||
1692 | } | ||
1693 | |||
1694 | void | ||
1695 | draw() { | ||
1696 | int x, y; | ||
1697 | |||
1698 | xclear(0, 0, term.col-1, term.row-1); | ||
1699 | for(y = 0; y < term.row; y++) | ||
1700 | for(x = 0; x < term.col; x++) | ||
1701 | if(term.line[y][x].state & GLYPH_SET) | ||
1702 | xdrawc(x, y, term.line[y][x]); | ||
1703 | |||
1704 | xdrawcursor(); | ||
1705 | XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, xw.bufw, xw.bufh, BORDER, BORDER); | ||
1706 | XFlush(xw.dpy); | ||
1707 | } | ||
1708 | |||
1709 | #else | ||
1710 | /* optimized drawing routine */ | ||
1711 | void | 1663 | void |
1712 | draw() { | 1664 | draw() { |
1713 | drawregion(0, 0, term.col, term.row); | 1665 | drawregion(0, 0, term.col, term.row); |
@@ -1753,8 +1705,6 @@ drawregion(int x1, int y1, int x2, int y2) { | |||
1753 | XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, xw.bufw, xw.bufh, BORDER, BORDER); | 1705 | XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, xw.bufw, xw.bufh, BORDER, BORDER); |
1754 | } | 1706 | } |
1755 | 1707 | ||
1756 | #endif | ||
1757 | |||
1758 | void | 1708 | void |
1759 | expose(XEvent *ev) { | 1709 | expose(XEvent *ev) { |
1760 | XExposeEvent *e = &ev->xexpose; | 1710 | XExposeEvent *e = &ev->xexpose; |
@@ -1900,7 +1850,7 @@ run(void) { | |||
1900 | } | 1850 | } |
1901 | while(XPending(xw.dpy)) { | 1851 | while(XPending(xw.dpy)) { |
1902 | XNextEvent(xw.dpy, &ev); | 1852 | XNextEvent(xw.dpy, &ev); |
1903 | if (XFilterEvent(&ev, xw.win)) | 1853 | if(XFilterEvent(&ev, xw.win)) |
1904 | continue; | 1854 | continue; |
1905 | if(handler[ev.type]) | 1855 | if(handler[ev.type]) |
1906 | (handler[ev.type])(&ev); | 1856 | (handler[ev.type])(&ev); |