diff options
author | FRIGN <dev@frign.de> | 2015-07-09 23:59:50 +0200 |
---|---|---|
committer | Christoph Lohmann <20h@r-36.net> | 2015-07-10 13:58:09 +0200 |
commit | 13233574ed1ead29bb7e99e71a0665e62c640617 (patch) | |
tree | 266ca14d1c85787535d39784f6c148bc33456f4b | |
parent | 9de853a98da8fe0f458b244970f0e0d3e9b38a50 (diff) | |
download | st-13233574ed1ead29bb7e99e71a0665e62c640617.tar.gz st-13233574ed1ead29bb7e99e71a0665e62c640617.zip |
Use BSD-style function notation
Put the opening brace on a new line. This was already used for some
functions inside st.c.
Signed-off-by: Christoph Lohmann <20h@r-36.net>
-rw-r--r-- | st.c | 385 |
1 files changed, 256 insertions, 129 deletions
@@ -550,7 +550,8 @@ static Fontcache frc[16]; | |||
550 | static int frclen = 0; | 550 | static int frclen = 0; |
551 | 551 | ||
552 | ssize_t | 552 | ssize_t |
553 | xwrite(int fd, const char *s, size_t len) { | 553 | xwrite(int fd, const char *s, size_t len) |
554 | { | ||
554 | size_t aux = len; | 555 | size_t aux = len; |
555 | 556 | ||
556 | while(len > 0) { | 557 | while(len > 0) { |
@@ -564,7 +565,8 @@ xwrite(int fd, const char *s, size_t len) { | |||
564 | } | 565 | } |
565 | 566 | ||
566 | void * | 567 | void * |
567 | xmalloc(size_t len) { | 568 | xmalloc(size_t len) |
569 | { | ||
568 | void *p = malloc(len); | 570 | void *p = malloc(len); |
569 | 571 | ||
570 | if(!p) | 572 | if(!p) |
@@ -574,7 +576,8 @@ xmalloc(size_t len) { | |||
574 | } | 576 | } |
575 | 577 | ||
576 | void * | 578 | void * |
577 | xrealloc(void *p, size_t len) { | 579 | xrealloc(void *p, size_t len) |
580 | { | ||
578 | if((p = realloc(p, len)) == NULL) | 581 | if((p = realloc(p, len)) == NULL) |
579 | die("Out of memory\n"); | 582 | die("Out of memory\n"); |
580 | 583 | ||
@@ -582,7 +585,8 @@ xrealloc(void *p, size_t len) { | |||
582 | } | 585 | } |
583 | 586 | ||
584 | char * | 587 | char * |
585 | xstrdup(char *s) { | 588 | xstrdup(char *s) |
589 | { | ||
586 | if((s = strdup(s)) == NULL) | 590 | if((s = strdup(s)) == NULL) |
587 | die("Out of memory\n"); | 591 | die("Out of memory\n"); |
588 | 592 | ||
@@ -590,7 +594,8 @@ xstrdup(char *s) { | |||
590 | } | 594 | } |
591 | 595 | ||
592 | size_t | 596 | size_t |
593 | utf8decode(char *c, Rune *u, size_t clen) { | 597 | utf8decode(char *c, Rune *u, size_t clen) |
598 | { | ||
594 | size_t i, j, len, type; | 599 | size_t i, j, len, type; |
595 | Rune udecoded; | 600 | Rune udecoded; |
596 | 601 | ||
@@ -613,7 +618,8 @@ utf8decode(char *c, Rune *u, size_t clen) { | |||
613 | } | 618 | } |
614 | 619 | ||
615 | Rune | 620 | Rune |
616 | utf8decodebyte(char c, size_t *i) { | 621 | utf8decodebyte(char c, size_t *i) |
622 | { | ||
617 | for(*i = 0; *i < LEN(utfmask); ++(*i)) | 623 | for(*i = 0; *i < LEN(utfmask); ++(*i)) |
618 | if(((uchar)c & utfmask[*i]) == utfbyte[*i]) | 624 | if(((uchar)c & utfmask[*i]) == utfbyte[*i]) |
619 | return (uchar)c & ~utfmask[*i]; | 625 | return (uchar)c & ~utfmask[*i]; |
@@ -621,7 +627,8 @@ utf8decodebyte(char c, size_t *i) { | |||
621 | } | 627 | } |
622 | 628 | ||
623 | size_t | 629 | size_t |
624 | utf8encode(Rune u, char *c) { | 630 | utf8encode(Rune u, char *c) |
631 | { | ||
625 | size_t len, i; | 632 | size_t len, i; |
626 | 633 | ||
627 | len = utf8validate(&u, 0); | 634 | len = utf8validate(&u, 0); |
@@ -636,12 +643,14 @@ utf8encode(Rune u, char *c) { | |||
636 | } | 643 | } |
637 | 644 | ||
638 | char | 645 | char |
639 | utf8encodebyte(Rune u, size_t i) { | 646 | utf8encodebyte(Rune u, size_t i) |
647 | { | ||
640 | return utfbyte[i] | (u & ~utfmask[i]); | 648 | return utfbyte[i] | (u & ~utfmask[i]); |
641 | } | 649 | } |
642 | 650 | ||
643 | char * | 651 | char * |
644 | utf8strchr(char *s, Rune u) { | 652 | utf8strchr(char *s, Rune u) |
653 | { | ||
645 | Rune r; | 654 | Rune r; |
646 | size_t i, j, len; | 655 | size_t i, j, len; |
647 | 656 | ||
@@ -656,7 +665,8 @@ utf8strchr(char *s, Rune u) { | |||
656 | } | 665 | } |
657 | 666 | ||
658 | size_t | 667 | size_t |
659 | utf8validate(Rune *u, size_t i) { | 668 | utf8validate(Rune *u, size_t i) |
669 | { | ||
660 | if(!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF)) | 670 | if(!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF)) |
661 | *u = UTF_INVALID; | 671 | *u = UTF_INVALID; |
662 | for(i = 1; *u > utfmax[i]; ++i) | 672 | for(i = 1; *u > utfmax[i]; ++i) |
@@ -665,7 +675,8 @@ utf8validate(Rune *u, size_t i) { | |||
665 | } | 675 | } |
666 | 676 | ||
667 | void | 677 | void |
668 | selinit(void) { | 678 | selinit(void) |
679 | { | ||
669 | memset(&sel.tclick1, 0, sizeof(sel.tclick1)); | 680 | memset(&sel.tclick1, 0, sizeof(sel.tclick1)); |
670 | memset(&sel.tclick2, 0, sizeof(sel.tclick2)); | 681 | memset(&sel.tclick2, 0, sizeof(sel.tclick2)); |
671 | sel.mode = SEL_IDLE; | 682 | sel.mode = SEL_IDLE; |
@@ -678,7 +689,8 @@ selinit(void) { | |||
678 | } | 689 | } |
679 | 690 | ||
680 | int | 691 | int |
681 | x2col(int x) { | 692 | x2col(int x) |
693 | { | ||
682 | x -= borderpx; | 694 | x -= borderpx; |
683 | x /= xw.cw; | 695 | x /= xw.cw; |
684 | 696 | ||
@@ -686,7 +698,8 @@ x2col(int x) { | |||
686 | } | 698 | } |
687 | 699 | ||
688 | int | 700 | int |
689 | y2row(int y) { | 701 | y2row(int y) |
702 | { | ||
690 | y -= borderpx; | 703 | y -= borderpx; |
691 | y /= xw.ch; | 704 | y /= xw.ch; |
692 | 705 | ||
@@ -694,7 +707,8 @@ y2row(int y) { | |||
694 | } | 707 | } |
695 | 708 | ||
696 | int | 709 | int |
697 | tlinelen(int y) { | 710 | tlinelen(int y) |
711 | { | ||
698 | int i = term.col; | 712 | int i = term.col; |
699 | 713 | ||
700 | if(term.line[y][i - 1].mode & ATTR_WRAP) | 714 | if(term.line[y][i - 1].mode & ATTR_WRAP) |
@@ -707,7 +721,8 @@ tlinelen(int y) { | |||
707 | } | 721 | } |
708 | 722 | ||
709 | void | 723 | void |
710 | selnormalize(void) { | 724 | selnormalize(void) |
725 | { | ||
711 | int i; | 726 | int i; |
712 | 727 | ||
713 | if(sel.type == SEL_REGULAR && sel.ob.y != sel.oe.y) { | 728 | if(sel.type == SEL_REGULAR && sel.ob.y != sel.oe.y) { |
@@ -734,7 +749,8 @@ selnormalize(void) { | |||
734 | } | 749 | } |
735 | 750 | ||
736 | int | 751 | int |
737 | selected(int x, int y) { | 752 | selected(int x, int y) |
753 | { | ||
738 | if(sel.mode == SEL_EMPTY) | 754 | if(sel.mode == SEL_EMPTY) |
739 | return 0; | 755 | return 0; |
740 | 756 | ||
@@ -748,7 +764,8 @@ selected(int x, int y) { | |||
748 | } | 764 | } |
749 | 765 | ||
750 | void | 766 | void |
751 | selsnap(int *x, int *y, int direction) { | 767 | selsnap(int *x, int *y, int direction) |
768 | { | ||
752 | int newx, newy, xt, yt; | 769 | int newx, newy, xt, yt; |
753 | int delim, prevdelim; | 770 | int delim, prevdelim; |
754 | Glyph *gp, *prevgp; | 771 | Glyph *gp, *prevgp; |
@@ -820,7 +837,8 @@ selsnap(int *x, int *y, int direction) { | |||
820 | } | 837 | } |
821 | 838 | ||
822 | void | 839 | void |
823 | getbuttoninfo(XEvent *e) { | 840 | getbuttoninfo(XEvent *e) |
841 | { | ||
824 | int type; | 842 | int type; |
825 | uint state = e->xbutton.state & ~(Button1Mask | forceselmod); | 843 | uint state = e->xbutton.state & ~(Button1Mask | forceselmod); |
826 | 844 | ||
@@ -840,7 +858,8 @@ getbuttoninfo(XEvent *e) { | |||
840 | } | 858 | } |
841 | 859 | ||
842 | void | 860 | void |
843 | mousereport(XEvent *e) { | 861 | mousereport(XEvent *e) |
862 | { | ||
844 | int x = x2col(e->xbutton.x), y = y2row(e->xbutton.y), | 863 | int x = x2col(e->xbutton.x), y = y2row(e->xbutton.y), |
845 | button = e->xbutton.button, state = e->xbutton.state, | 864 | button = e->xbutton.button, state = e->xbutton.state, |
846 | len; | 865 | len; |
@@ -903,7 +922,8 @@ mousereport(XEvent *e) { | |||
903 | } | 922 | } |
904 | 923 | ||
905 | void | 924 | void |
906 | bpress(XEvent *e) { | 925 | bpress(XEvent *e) |
926 | { | ||
907 | struct timespec now; | 927 | struct timespec now; |
908 | Mousekey *mk; | 928 | Mousekey *mk; |
909 | 929 | ||
@@ -952,7 +972,8 @@ bpress(XEvent *e) { | |||
952 | } | 972 | } |
953 | 973 | ||
954 | char * | 974 | char * |
955 | getsel(void) { | 975 | getsel(void) |
976 | { | ||
956 | char *str, *ptr; | 977 | char *str, *ptr; |
957 | int y, bufsize, lastx, linelen; | 978 | int y, bufsize, lastx, linelen; |
958 | Glyph *gp, *last; | 979 | Glyph *gp, *last; |
@@ -1002,12 +1023,14 @@ getsel(void) { | |||
1002 | } | 1023 | } |
1003 | 1024 | ||
1004 | void | 1025 | void |
1005 | selcopy(Time t) { | 1026 | selcopy(Time t) |
1027 | { | ||
1006 | xsetsel(getsel(), t); | 1028 | xsetsel(getsel(), t); |
1007 | } | 1029 | } |
1008 | 1030 | ||
1009 | void | 1031 | void |
1010 | selnotify(XEvent *e) { | 1032 | selnotify(XEvent *e) |
1033 | { | ||
1011 | ulong nitems, ofs, rem; | 1034 | ulong nitems, ofs, rem; |
1012 | int format; | 1035 | int format; |
1013 | uchar *data, *last, *repl; | 1036 | uchar *data, *last, *repl; |
@@ -1052,13 +1075,15 @@ selnotify(XEvent *e) { | |||
1052 | } | 1075 | } |
1053 | 1076 | ||
1054 | void | 1077 | void |
1055 | selpaste(const Arg *dummy) { | 1078 | selpaste(const Arg *dummy) |
1079 | { | ||
1056 | XConvertSelection(xw.dpy, XA_PRIMARY, sel.xtarget, XA_PRIMARY, | 1080 | XConvertSelection(xw.dpy, XA_PRIMARY, sel.xtarget, XA_PRIMARY, |
1057 | xw.win, CurrentTime); | 1081 | xw.win, CurrentTime); |
1058 | } | 1082 | } |
1059 | 1083 | ||
1060 | void | 1084 | void |
1061 | clipcopy(const Arg *dummy) { | 1085 | clipcopy(const Arg *dummy) |
1086 | { | ||
1062 | Atom clipboard; | 1087 | Atom clipboard; |
1063 | 1088 | ||
1064 | if(sel.clipboard != NULL) | 1089 | if(sel.clipboard != NULL) |
@@ -1072,7 +1097,8 @@ clipcopy(const Arg *dummy) { | |||
1072 | } | 1097 | } |
1073 | 1098 | ||
1074 | void | 1099 | void |
1075 | clippaste(const Arg *dummy) { | 1100 | clippaste(const Arg *dummy) |
1101 | { | ||
1076 | Atom clipboard; | 1102 | Atom clipboard; |
1077 | 1103 | ||
1078 | clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0); | 1104 | clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0); |
@@ -1081,7 +1107,8 @@ clippaste(const Arg *dummy) { | |||
1081 | } | 1107 | } |
1082 | 1108 | ||
1083 | void | 1109 | void |
1084 | selclear(XEvent *e) { | 1110 | selclear(XEvent *e) |
1111 | { | ||
1085 | if(sel.ob.x == -1) | 1112 | if(sel.ob.x == -1) |
1086 | return; | 1113 | return; |
1087 | sel.mode = SEL_IDLE; | 1114 | sel.mode = SEL_IDLE; |
@@ -1090,7 +1117,8 @@ selclear(XEvent *e) { | |||
1090 | } | 1117 | } |
1091 | 1118 | ||
1092 | void | 1119 | void |
1093 | selrequest(XEvent *e) { | 1120 | selrequest(XEvent *e) |
1121 | { | ||
1094 | XSelectionRequestEvent *xsre; | 1122 | XSelectionRequestEvent *xsre; |
1095 | XSelectionEvent xev; | 1123 | XSelectionEvent xev; |
1096 | Atom xa_targets, string, clipboard; | 1124 | Atom xa_targets, string, clipboard; |
@@ -1147,7 +1175,8 @@ selrequest(XEvent *e) { | |||
1147 | } | 1175 | } |
1148 | 1176 | ||
1149 | void | 1177 | void |
1150 | xsetsel(char *str, Time t) { | 1178 | xsetsel(char *str, Time t) |
1179 | { | ||
1151 | free(sel.primary); | 1180 | free(sel.primary); |
1152 | sel.primary = str; | 1181 | sel.primary = str; |
1153 | 1182 | ||
@@ -1157,7 +1186,8 @@ xsetsel(char *str, Time t) { | |||
1157 | } | 1186 | } |
1158 | 1187 | ||
1159 | void | 1188 | void |
1160 | brelease(XEvent *e) { | 1189 | brelease(XEvent *e) |
1190 | { | ||
1161 | if(IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) { | 1191 | if(IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) { |
1162 | mousereport(e); | 1192 | mousereport(e); |
1163 | return; | 1193 | return; |
@@ -1177,7 +1207,8 @@ brelease(XEvent *e) { | |||
1177 | } | 1207 | } |
1178 | 1208 | ||
1179 | void | 1209 | void |
1180 | bmotion(XEvent *e) { | 1210 | bmotion(XEvent *e) |
1211 | { | ||
1181 | int oldey, oldex, oldsby, oldsey; | 1212 | int oldey, oldex, oldsby, oldsey; |
1182 | 1213 | ||
1183 | if(IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) { | 1214 | if(IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) { |
@@ -1200,7 +1231,8 @@ bmotion(XEvent *e) { | |||
1200 | } | 1231 | } |
1201 | 1232 | ||
1202 | void | 1233 | void |
1203 | die(const char *errstr, ...) { | 1234 | die(const char *errstr, ...) |
1235 | { | ||
1204 | va_list ap; | 1236 | va_list ap; |
1205 | 1237 | ||
1206 | va_start(ap, errstr); | 1238 | va_start(ap, errstr); |
@@ -1210,7 +1242,8 @@ die(const char *errstr, ...) { | |||
1210 | } | 1242 | } |
1211 | 1243 | ||
1212 | void | 1244 | void |
1213 | execsh(void) { | 1245 | execsh(void) |
1246 | { | ||
1214 | char **args, *sh, *prog; | 1247 | char **args, *sh, *prog; |
1215 | const struct passwd *pw; | 1248 | const struct passwd *pw; |
1216 | char buf[sizeof(long) * 8 + 1]; | 1249 | char buf[sizeof(long) * 8 + 1]; |
@@ -1259,7 +1292,8 @@ execsh(void) { | |||
1259 | } | 1292 | } |
1260 | 1293 | ||
1261 | void | 1294 | void |
1262 | sigchld(int a) { | 1295 | sigchld(int a) |
1296 | { | ||
1263 | int stat; | 1297 | int stat; |
1264 | pid_t p; | 1298 | pid_t p; |
1265 | 1299 | ||
@@ -1300,7 +1334,8 @@ stty(void) | |||
1300 | } | 1334 | } |
1301 | 1335 | ||
1302 | void | 1336 | void |
1303 | ttynew(void) { | 1337 | ttynew(void) |
1338 | { | ||
1304 | int m, s; | 1339 | int m, s; |
1305 | struct winsize w = {term.row, term.col, 0, 0}; | 1340 | struct winsize w = {term.row, term.col, 0, 0}; |
1306 | 1341 | ||
@@ -1352,7 +1387,8 @@ ttynew(void) { | |||
1352 | } | 1387 | } |
1353 | 1388 | ||
1354 | void | 1389 | void |
1355 | ttyread(void) { | 1390 | ttyread(void) |
1391 | { | ||
1356 | static char buf[BUFSIZ]; | 1392 | static char buf[BUFSIZ]; |
1357 | static int buflen = 0; | 1393 | static int buflen = 0; |
1358 | char *ptr; | 1394 | char *ptr; |
@@ -1378,13 +1414,15 @@ ttyread(void) { | |||
1378 | } | 1414 | } |
1379 | 1415 | ||
1380 | void | 1416 | void |
1381 | ttywrite(const char *s, size_t n) { | 1417 | ttywrite(const char *s, size_t n) |
1418 | { | ||
1382 | if(xwrite(cmdfd, s, n) == -1) | 1419 | if(xwrite(cmdfd, s, n) == -1) |
1383 | die("write error on tty: %s\n", strerror(errno)); | 1420 | die("write error on tty: %s\n", strerror(errno)); |
1384 | } | 1421 | } |
1385 | 1422 | ||
1386 | void | 1423 | void |
1387 | ttysend(char *s, size_t n) { | 1424 | ttysend(char *s, size_t n) |
1425 | { | ||
1388 | int len; | 1426 | int len; |
1389 | Rune u; | 1427 | Rune u; |
1390 | 1428 | ||
@@ -1398,7 +1436,8 @@ ttysend(char *s, size_t n) { | |||
1398 | } | 1436 | } |
1399 | 1437 | ||
1400 | void | 1438 | void |
1401 | ttyresize(void) { | 1439 | ttyresize(void) |
1440 | { | ||
1402 | struct winsize w; | 1441 | struct winsize w; |
1403 | 1442 | ||
1404 | w.ws_row = term.row; | 1443 | w.ws_row = term.row; |
@@ -1410,7 +1449,8 @@ ttyresize(void) { | |||
1410 | } | 1449 | } |
1411 | 1450 | ||
1412 | int | 1451 | int |
1413 | tattrset(int attr) { | 1452 | tattrset(int attr) |
1453 | { | ||
1414 | int i, j; | 1454 | int i, j; |
1415 | 1455 | ||
1416 | for(i = 0; i < term.row-1; i++) { | 1456 | for(i = 0; i < term.row-1; i++) { |
@@ -1424,7 +1464,8 @@ tattrset(int attr) { | |||
1424 | } | 1464 | } |
1425 | 1465 | ||
1426 | void | 1466 | void |
1427 | tsetdirt(int top, int bot) { | 1467 | tsetdirt(int top, int bot) |
1468 | { | ||
1428 | int i; | 1469 | int i; |
1429 | 1470 | ||
1430 | LIMIT(top, 0, term.row-1); | 1471 | LIMIT(top, 0, term.row-1); |
@@ -1435,7 +1476,8 @@ tsetdirt(int top, int bot) { | |||
1435 | } | 1476 | } |
1436 | 1477 | ||
1437 | void | 1478 | void |
1438 | tsetdirtattr(int attr) { | 1479 | tsetdirtattr(int attr) |
1480 | { | ||
1439 | int i, j; | 1481 | int i, j; |
1440 | 1482 | ||
1441 | for(i = 0; i < term.row-1; i++) { | 1483 | for(i = 0; i < term.row-1; i++) { |
@@ -1449,12 +1491,14 @@ tsetdirtattr(int attr) { | |||
1449 | } | 1491 | } |
1450 | 1492 | ||
1451 | void | 1493 | void |
1452 | tfulldirt(void) { | 1494 | tfulldirt(void) |
1495 | { | ||
1453 | tsetdirt(0, term.row-1); | 1496 | tsetdirt(0, term.row-1); |
1454 | } | 1497 | } |
1455 | 1498 | ||
1456 | void | 1499 | void |
1457 | tcursor(int mode) { | 1500 | tcursor(int mode) |
1501 | { | ||
1458 | static TCursor c[2]; | 1502 | static TCursor c[2]; |
1459 | int alt = IS_SET(MODE_ALTSCREEN); | 1503 | int alt = IS_SET(MODE_ALTSCREEN); |
1460 | 1504 | ||
@@ -1467,7 +1511,8 @@ tcursor(int mode) { | |||
1467 | } | 1511 | } |
1468 | 1512 | ||
1469 | void | 1513 | void |
1470 | treset(void) { | 1514 | treset(void) |
1515 | { | ||
1471 | uint i; | 1516 | uint i; |
1472 | 1517 | ||
1473 | term.c = (TCursor){{ | 1518 | term.c = (TCursor){{ |
@@ -1494,7 +1539,8 @@ treset(void) { | |||
1494 | } | 1539 | } |
1495 | 1540 | ||
1496 | void | 1541 | void |
1497 | tnew(int col, int row) { | 1542 | tnew(int col, int row) |
1543 | { | ||
1498 | term = (Term){ .c = { .attr = { .fg = defaultfg, .bg = defaultbg } } }; | 1544 | term = (Term){ .c = { .attr = { .fg = defaultfg, .bg = defaultbg } } }; |
1499 | tresize(col, row); | 1545 | tresize(col, row); |
1500 | term.numlock = 1; | 1546 | term.numlock = 1; |
@@ -1503,7 +1549,8 @@ tnew(int col, int row) { | |||
1503 | } | 1549 | } |
1504 | 1550 | ||
1505 | void | 1551 | void |
1506 | tswapscreen(void) { | 1552 | tswapscreen(void) |
1553 | { | ||
1507 | Line *tmp = term.line; | 1554 | Line *tmp = term.line; |
1508 | 1555 | ||
1509 | term.line = term.alt; | 1556 | term.line = term.alt; |
@@ -1513,7 +1560,8 @@ tswapscreen(void) { | |||
1513 | } | 1560 | } |
1514 | 1561 | ||
1515 | void | 1562 | void |
1516 | tscrolldown(int orig, int n) { | 1563 | tscrolldown(int orig, int n) |
1564 | { | ||
1517 | int i; | 1565 | int i; |
1518 | Line temp; | 1566 | Line temp; |
1519 | 1567 | ||
@@ -1532,7 +1580,8 @@ tscrolldown(int orig, int n) { | |||
1532 | } | 1580 | } |
1533 | 1581 | ||
1534 | void | 1582 | void |
1535 | tscrollup(int orig, int n) { | 1583 | tscrollup(int orig, int n) |
1584 | { | ||
1536 | int i; | 1585 | int i; |
1537 | Line temp; | 1586 | Line temp; |
1538 | 1587 | ||
@@ -1551,7 +1600,8 @@ tscrollup(int orig, int n) { | |||
1551 | } | 1600 | } |
1552 | 1601 | ||
1553 | void | 1602 | void |
1554 | selscroll(int orig, int n) { | 1603 | selscroll(int orig, int n) |
1604 | { | ||
1555 | if(sel.ob.x == -1) | 1605 | if(sel.ob.x == -1) |
1556 | return; | 1606 | return; |
1557 | 1607 | ||
@@ -1580,7 +1630,8 @@ selscroll(int orig, int n) { | |||
1580 | } | 1630 | } |
1581 | 1631 | ||
1582 | void | 1632 | void |
1583 | tnewline(int first_col) { | 1633 | tnewline(int first_col) |
1634 | { | ||
1584 | int y = term.c.y; | 1635 | int y = term.c.y; |
1585 | 1636 | ||
1586 | if(y == term.bot) { | 1637 | if(y == term.bot) { |
@@ -1592,7 +1643,8 @@ tnewline(int first_col) { | |||
1592 | } | 1643 | } |
1593 | 1644 | ||
1594 | void | 1645 | void |
1595 | csiparse(void) { | 1646 | csiparse(void) |
1647 | { | ||
1596 | char *p = csiescseq.buf, *np; | 1648 | char *p = csiescseq.buf, *np; |
1597 | long int v; | 1649 | long int v; |
1598 | 1650 | ||
@@ -1622,12 +1674,14 @@ csiparse(void) { | |||
1622 | 1674 | ||
1623 | /* for absolute user moves, when decom is set */ | 1675 | /* for absolute user moves, when decom is set */ |
1624 | void | 1676 | void |
1625 | tmoveato(int x, int y) { | 1677 | tmoveato(int x, int y) |
1678 | { | ||
1626 | tmoveto(x, y + ((term.c.state & CURSOR_ORIGIN) ? term.top: 0)); | 1679 | tmoveto(x, y + ((term.c.state & CURSOR_ORIGIN) ? term.top: 0)); |
1627 | } | 1680 | } |
1628 | 1681 | ||
1629 | void | 1682 | void |
1630 | tmoveto(int x, int y) { | 1683 | tmoveto(int x, int y) |
1684 | { | ||
1631 | int miny, maxy; | 1685 | int miny, maxy; |
1632 | 1686 | ||
1633 | if(term.c.state & CURSOR_ORIGIN) { | 1687 | if(term.c.state & CURSOR_ORIGIN) { |
@@ -1643,7 +1697,8 @@ tmoveto(int x, int y) { | |||
1643 | } | 1697 | } |
1644 | 1698 | ||
1645 | void | 1699 | void |
1646 | tsetchar(Rune u, Glyph *attr, int x, int y) { | 1700 | tsetchar(Rune u, Glyph *attr, int x, int y) |
1701 | { | ||
1647 | static char *vt100_0[62] = { /* 0x41 - 0x7e */ | 1702 | static char *vt100_0[62] = { /* 0x41 - 0x7e */ |
1648 | "↑", "↓", "→", "←", "█", "▚", "☃", /* A - G */ | 1703 | "↑", "↓", "→", "←", "█", "▚", "☃", /* A - G */ |
1649 | 0, 0, 0, 0, 0, 0, 0, 0, /* H - O */ | 1704 | 0, 0, 0, 0, 0, 0, 0, 0, /* H - O */ |
@@ -1678,7 +1733,8 @@ tsetchar(Rune u, Glyph *attr, int x, int y) { | |||
1678 | } | 1733 | } |
1679 | 1734 | ||
1680 | void | 1735 | void |
1681 | tclearregion(int x1, int y1, int x2, int y2) { | 1736 | tclearregion(int x1, int y1, int x2, int y2) |
1737 | { | ||
1682 | int x, y, temp; | 1738 | int x, y, temp; |
1683 | Glyph *gp; | 1739 | Glyph *gp; |
1684 | 1740 | ||
@@ -1707,7 +1763,8 @@ tclearregion(int x1, int y1, int x2, int y2) { | |||
1707 | } | 1763 | } |
1708 | 1764 | ||
1709 | void | 1765 | void |
1710 | tdeletechar(int n) { | 1766 | tdeletechar(int n) |
1767 | { | ||
1711 | int dst, src, size; | 1768 | int dst, src, size; |
1712 | Glyph *line; | 1769 | Glyph *line; |
1713 | 1770 | ||
@@ -1723,7 +1780,8 @@ tdeletechar(int n) { | |||
1723 | } | 1780 | } |
1724 | 1781 | ||
1725 | void | 1782 | void |
1726 | tinsertblank(int n) { | 1783 | tinsertblank(int n) |
1784 | { | ||
1727 | int dst, src, size; | 1785 | int dst, src, size; |
1728 | Glyph *line; | 1786 | Glyph *line; |
1729 | 1787 | ||
@@ -1739,19 +1797,22 @@ tinsertblank(int n) { | |||
1739 | } | 1797 | } |
1740 | 1798 | ||
1741 | void | 1799 | void |
1742 | tinsertblankline(int n) { | 1800 | tinsertblankline(int n) |
1801 | { | ||
1743 | if(BETWEEN(term.c.y, term.top, term.bot)) | 1802 | if(BETWEEN(term.c.y, term.top, term.bot)) |
1744 | tscrolldown(term.c.y, n); | 1803 | tscrolldown(term.c.y, n); |
1745 | } | 1804 | } |
1746 | 1805 | ||
1747 | void | 1806 | void |
1748 | tdeleteline(int n) { | 1807 | tdeleteline(int n) |
1808 | { | ||
1749 | if(BETWEEN(term.c.y, term.top, term.bot)) | 1809 | if(BETWEEN(term.c.y, term.top, term.bot)) |
1750 | tscrollup(term.c.y, n); | 1810 | tscrollup(term.c.y, n); |
1751 | } | 1811 | } |
1752 | 1812 | ||
1753 | int32_t | 1813 | int32_t |
1754 | tdefcolor(int *attr, int *npar, int l) { | 1814 | tdefcolor(int *attr, int *npar, int l) |
1815 | { | ||
1755 | int32_t idx = -1; | 1816 | int32_t idx = -1; |
1756 | uint r, g, b; | 1817 | uint r, g, b; |
1757 | 1818 | ||
@@ -1800,7 +1861,8 @@ tdefcolor(int *attr, int *npar, int l) { | |||
1800 | } | 1861 | } |
1801 | 1862 | ||
1802 | void | 1863 | void |
1803 | tsetattr(int *attr, int l) { | 1864 | tsetattr(int *attr, int l) |
1865 | { | ||
1804 | int i; | 1866 | int i; |
1805 | int32_t idx; | 1867 | int32_t idx; |
1806 | 1868 | ||
@@ -1900,7 +1962,8 @@ tsetattr(int *attr, int l) { | |||
1900 | } | 1962 | } |
1901 | 1963 | ||
1902 | void | 1964 | void |
1903 | tsetscroll(int t, int b) { | 1965 | tsetscroll(int t, int b) |
1966 | { | ||
1904 | int temp; | 1967 | int temp; |
1905 | 1968 | ||
1906 | LIMIT(t, 0, term.row-1); | 1969 | LIMIT(t, 0, term.row-1); |
@@ -1915,7 +1978,8 @@ tsetscroll(int t, int b) { | |||
1915 | } | 1978 | } |
1916 | 1979 | ||
1917 | void | 1980 | void |
1918 | tsetmode(int priv, int set, int *args, int narg) { | 1981 | tsetmode(int priv, int set, int *args, int narg) |
1982 | { | ||
1919 | int *lim, mode; | 1983 | int *lim, mode; |
1920 | int alt; | 1984 | int alt; |
1921 | 1985 | ||
@@ -2047,7 +2111,8 @@ tsetmode(int priv, int set, int *args, int narg) { | |||
2047 | } | 2111 | } |
2048 | 2112 | ||
2049 | void | 2113 | void |
2050 | csihandle(void) { | 2114 | csihandle(void) |
2115 | { | ||
2051 | char buf[40]; | 2116 | char buf[40]; |
2052 | int len; | 2117 | int len; |
2053 | 2118 | ||
@@ -2256,7 +2321,8 @@ csihandle(void) { | |||
2256 | } | 2321 | } |
2257 | 2322 | ||
2258 | void | 2323 | void |
2259 | csidump(void) { | 2324 | csidump(void) |
2325 | { | ||
2260 | int i; | 2326 | int i; |
2261 | uint c; | 2327 | uint c; |
2262 | 2328 | ||
@@ -2279,12 +2345,14 @@ csidump(void) { | |||
2279 | } | 2345 | } |
2280 | 2346 | ||
2281 | void | 2347 | void |
2282 | csireset(void) { | 2348 | csireset(void) |
2349 | { | ||
2283 | memset(&csiescseq, 0, sizeof(csiescseq)); | 2350 | memset(&csiescseq, 0, sizeof(csiescseq)); |
2284 | } | 2351 | } |
2285 | 2352 | ||
2286 | void | 2353 | void |
2287 | strhandle(void) { | 2354 | strhandle(void) |
2355 | { | ||
2288 | char *p = NULL; | 2356 | char *p = NULL; |
2289 | int j, narg, par; | 2357 | int j, narg, par; |
2290 | 2358 | ||
@@ -2334,7 +2402,8 @@ strhandle(void) { | |||
2334 | } | 2402 | } |
2335 | 2403 | ||
2336 | void | 2404 | void |
2337 | strparse(void) { | 2405 | strparse(void) |
2406 | { | ||
2338 | int c; | 2407 | int c; |
2339 | char *p = strescseq.buf; | 2408 | char *p = strescseq.buf; |
2340 | 2409 | ||
@@ -2355,7 +2424,8 @@ strparse(void) { | |||
2355 | } | 2424 | } |
2356 | 2425 | ||
2357 | void | 2426 | void |
2358 | strdump(void) { | 2427 | strdump(void) |
2428 | { | ||
2359 | int i; | 2429 | int i; |
2360 | uint c; | 2430 | uint c; |
2361 | 2431 | ||
@@ -2380,12 +2450,14 @@ strdump(void) { | |||
2380 | } | 2450 | } |
2381 | 2451 | ||
2382 | void | 2452 | void |
2383 | strreset(void) { | 2453 | strreset(void) |
2454 | { | ||
2384 | memset(&strescseq, 0, sizeof(strescseq)); | 2455 | memset(&strescseq, 0, sizeof(strescseq)); |
2385 | } | 2456 | } |
2386 | 2457 | ||
2387 | void | 2458 | void |
2388 | tprinter(char *s, size_t len) { | 2459 | tprinter(char *s, size_t len) |
2460 | { | ||
2389 | if(iofd != -1 && xwrite(iofd, s, len) < 0) { | 2461 | if(iofd != -1 && xwrite(iofd, s, len) < 0) { |
2390 | fprintf(stderr, "Error writing in %s:%s\n", | 2462 | fprintf(stderr, "Error writing in %s:%s\n", |
2391 | opt_io, strerror(errno)); | 2463 | opt_io, strerror(errno)); |
@@ -2395,22 +2467,26 @@ tprinter(char *s, size_t len) { | |||
2395 | } | 2467 | } |
2396 | 2468 | ||
2397 | void | 2469 | void |
2398 | toggleprinter(const Arg *arg) { | 2470 | toggleprinter(const Arg *arg) |
2471 | { | ||
2399 | term.mode ^= MODE_PRINT; | 2472 | term.mode ^= MODE_PRINT; |
2400 | } | 2473 | } |
2401 | 2474 | ||
2402 | void | 2475 | void |
2403 | printscreen(const Arg *arg) { | 2476 | printscreen(const Arg *arg) |
2477 | { | ||
2404 | tdump(); | 2478 | tdump(); |
2405 | } | 2479 | } |
2406 | 2480 | ||
2407 | void | 2481 | void |
2408 | printsel(const Arg *arg) { | 2482 | printsel(const Arg *arg) |
2483 | { | ||
2409 | tdumpsel(); | 2484 | tdumpsel(); |
2410 | } | 2485 | } |
2411 | 2486 | ||
2412 | void | 2487 | void |
2413 | tdumpsel(void) { | 2488 | tdumpsel(void) |
2489 | { | ||
2414 | char *ptr; | 2490 | char *ptr; |
2415 | 2491 | ||
2416 | if((ptr = getsel())) { | 2492 | if((ptr = getsel())) { |
@@ -2420,7 +2496,8 @@ tdumpsel(void) { | |||
2420 | } | 2496 | } |
2421 | 2497 | ||
2422 | void | 2498 | void |
2423 | tdumpline(int n) { | 2499 | tdumpline(int n) |
2500 | { | ||
2424 | char buf[UTF_SIZ]; | 2501 | char buf[UTF_SIZ]; |
2425 | Glyph *bp, *end; | 2502 | Glyph *bp, *end; |
2426 | 2503 | ||
@@ -2434,7 +2511,8 @@ tdumpline(int n) { | |||
2434 | } | 2511 | } |
2435 | 2512 | ||
2436 | void | 2513 | void |
2437 | tdump(void) { | 2514 | tdump(void) |
2515 | { | ||
2438 | int i; | 2516 | int i; |
2439 | 2517 | ||
2440 | for(i = 0; i < term.row; ++i) | 2518 | for(i = 0; i < term.row; ++i) |
@@ -2442,7 +2520,8 @@ tdump(void) { | |||
2442 | } | 2520 | } |
2443 | 2521 | ||
2444 | void | 2522 | void |
2445 | tputtab(int n) { | 2523 | tputtab(int n) |
2524 | { | ||
2446 | uint x = term.c.x; | 2525 | uint x = term.c.x; |
2447 | 2526 | ||
2448 | if(n > 0) { | 2527 | if(n > 0) { |
@@ -2458,7 +2537,8 @@ tputtab(int n) { | |||
2458 | } | 2537 | } |
2459 | 2538 | ||
2460 | void | 2539 | void |
2461 | techo(Rune u) { | 2540 | techo(Rune u) |
2541 | { | ||
2462 | if(ISCONTROL(u)) { /* control code */ | 2542 | if(ISCONTROL(u)) { /* control code */ |
2463 | if(u & 0x80) { | 2543 | if(u & 0x80) { |
2464 | u &= 0x7f; | 2544 | u &= 0x7f; |
@@ -2473,7 +2553,8 @@ techo(Rune u) { | |||
2473 | } | 2553 | } |
2474 | 2554 | ||
2475 | void | 2555 | void |
2476 | tdeftran(char ascii) { | 2556 | tdeftran(char ascii) |
2557 | { | ||
2477 | static char cs[] = "0B"; | 2558 | static char cs[] = "0B"; |
2478 | static int vcs[] = {CS_GRAPHIC0, CS_USA}; | 2559 | static int vcs[] = {CS_GRAPHIC0, CS_USA}; |
2479 | char *p; | 2560 | char *p; |
@@ -2486,7 +2567,8 @@ tdeftran(char ascii) { | |||
2486 | } | 2567 | } |
2487 | 2568 | ||
2488 | void | 2569 | void |
2489 | tdectest(char c) { | 2570 | tdectest(char c) |
2571 | { | ||
2490 | int x, y; | 2572 | int x, y; |
2491 | 2573 | ||
2492 | if(c == '8') { /* DEC screen alignment test. */ | 2574 | if(c == '8') { /* DEC screen alignment test. */ |
@@ -2498,7 +2580,8 @@ tdectest(char c) { | |||
2498 | } | 2580 | } |
2499 | 2581 | ||
2500 | void | 2582 | void |
2501 | tstrsequence(uchar c) { | 2583 | tstrsequence(uchar c) |
2584 | { | ||
2502 | switch (c) { | 2585 | switch (c) { |
2503 | case 0x90: /* DCS -- Device Control String */ | 2586 | case 0x90: /* DCS -- Device Control String */ |
2504 | c = 'P'; | 2587 | c = 'P'; |
@@ -2519,7 +2602,8 @@ tstrsequence(uchar c) { | |||
2519 | } | 2602 | } |
2520 | 2603 | ||
2521 | void | 2604 | void |
2522 | tcontrolcode(uchar ascii) { | 2605 | tcontrolcode(uchar ascii) |
2606 | { | ||
2523 | switch(ascii) { | 2607 | switch(ascii) { |
2524 | case '\t': /* HT */ | 2608 | case '\t': /* HT */ |
2525 | tputtab(1); | 2609 | tputtab(1); |
@@ -2602,7 +2686,8 @@ tcontrolcode(uchar ascii) { | |||
2602 | * more characters for this sequence, otherwise 0 | 2686 | * more characters for this sequence, otherwise 0 |
2603 | */ | 2687 | */ |
2604 | int | 2688 | int |
2605 | eschandle(uchar ascii) { | 2689 | eschandle(uchar ascii) |
2690 | { | ||
2606 | switch(ascii) { | 2691 | switch(ascii) { |
2607 | case '[': | 2692 | case '[': |
2608 | term.esc |= ESC_CSI; | 2693 | term.esc |= ESC_CSI; |
@@ -2681,7 +2766,8 @@ eschandle(uchar ascii) { | |||
2681 | } | 2766 | } |
2682 | 2767 | ||
2683 | void | 2768 | void |
2684 | tputc(Rune u) { | 2769 | tputc(Rune u) |
2770 | { | ||
2685 | char c[UTF_SIZ]; | 2771 | char c[UTF_SIZ]; |
2686 | int control; | 2772 | int control; |
2687 | int width, len; | 2773 | int width, len; |
@@ -2803,7 +2889,8 @@ tputc(Rune u) { | |||
2803 | } | 2889 | } |
2804 | 2890 | ||
2805 | void | 2891 | void |
2806 | tresize(int col, int row) { | 2892 | tresize(int col, int row) |
2893 | { | ||
2807 | int i; | 2894 | int i; |
2808 | int minrow = MIN(row, term.row); | 2895 | int minrow = MIN(row, term.row); |
2809 | int mincol = MIN(col, term.col); | 2896 | int mincol = MIN(col, term.col); |
@@ -2887,7 +2974,8 @@ tresize(int col, int row) { | |||
2887 | } | 2974 | } |
2888 | 2975 | ||
2889 | void | 2976 | void |
2890 | xresize(int col, int row) { | 2977 | xresize(int col, int row) |
2978 | { | ||
2891 | xw.tw = MAX(1, col * xw.cw); | 2979 | xw.tw = MAX(1, col * xw.cw); |
2892 | xw.th = MAX(1, row * xw.ch); | 2980 | xw.th = MAX(1, row * xw.ch); |
2893 | 2981 | ||
@@ -2899,12 +2987,14 @@ xresize(int col, int row) { | |||
2899 | } | 2987 | } |
2900 | 2988 | ||
2901 | ushort | 2989 | ushort |
2902 | sixd_to_16bit(int x) { | 2990 | sixd_to_16bit(int x) |
2991 | { | ||
2903 | return x == 0 ? 0 : 0x3737 + 0x2828 * x; | 2992 | return x == 0 ? 0 : 0x3737 + 0x2828 * x; |
2904 | } | 2993 | } |
2905 | 2994 | ||
2906 | int | 2995 | int |
2907 | xloadcolor(int i, const char *name, Color *ncolor) { | 2996 | xloadcolor(int i, const char *name, Color *ncolor) |
2997 | { | ||
2908 | XRenderColor color = { .alpha = 0xffff }; | 2998 | XRenderColor color = { .alpha = 0xffff }; |
2909 | 2999 | ||
2910 | if(!name) { | 3000 | if(!name) { |
@@ -2926,7 +3016,8 @@ xloadcolor(int i, const char *name, Color *ncolor) { | |||
2926 | } | 3016 | } |
2927 | 3017 | ||
2928 | void | 3018 | void |
2929 | xloadcols(void) { | 3019 | xloadcols(void) |
3020 | { | ||
2930 | int i; | 3021 | int i; |
2931 | static int loaded; | 3022 | static int loaded; |
2932 | Color *cp; | 3023 | Color *cp; |
@@ -2947,7 +3038,8 @@ xloadcols(void) { | |||
2947 | } | 3038 | } |
2948 | 3039 | ||
2949 | int | 3040 | int |
2950 | xsetcolorname(int x, const char *name) { | 3041 | xsetcolorname(int x, const char *name) |
3042 | { | ||
2951 | Color ncolor; | 3043 | Color ncolor; |
2952 | 3044 | ||
2953 | if(!BETWEEN(x, 0, LEN(dc.col))) | 3045 | if(!BETWEEN(x, 0, LEN(dc.col))) |
@@ -2963,7 +3055,8 @@ xsetcolorname(int x, const char *name) { | |||
2963 | } | 3055 | } |
2964 | 3056 | ||
2965 | void | 3057 | void |
2966 | xtermclear(int col1, int row1, int col2, int row2) { | 3058 | xtermclear(int col1, int row1, int col2, int row2) |
3059 | { | ||
2967 | XftDrawRect(xw.draw, | 3060 | XftDrawRect(xw.draw, |
2968 | &dc.col[IS_SET(MODE_REVERSE) ? defaultfg : defaultbg], | 3061 | &dc.col[IS_SET(MODE_REVERSE) ? defaultfg : defaultbg], |
2969 | borderpx + col1 * xw.cw, | 3062 | borderpx + col1 * xw.cw, |
@@ -2976,14 +3069,16 @@ xtermclear(int col1, int row1, int col2, int row2) { | |||
2976 | * Absolute coordinates. | 3069 | * Absolute coordinates. |
2977 | */ | 3070 | */ |
2978 | void | 3071 | void |
2979 | xclear(int x1, int y1, int x2, int y2) { | 3072 | xclear(int x1, int y1, int x2, int y2) |
3073 | { | ||
2980 | XftDrawRect(xw.draw, | 3074 | XftDrawRect(xw.draw, |
2981 | &dc.col[IS_SET(MODE_REVERSE)? defaultfg : defaultbg], | 3075 | &dc.col[IS_SET(MODE_REVERSE)? defaultfg : defaultbg], |
2982 | x1, y1, x2-x1, y2-y1); | 3076 | x1, y1, x2-x1, y2-y1); |
2983 | } | 3077 | } |
2984 | 3078 | ||
2985 | void | 3079 | void |
2986 | xhints(void) { | 3080 | xhints(void) |
3081 | { | ||
2987 | XClassHint class = {opt_class ? opt_class : termname, termname}; | 3082 | XClassHint class = {opt_class ? opt_class : termname, termname}; |
2988 | XWMHints wm = {.flags = InputHint, .input = 1}; | 3083 | XWMHints wm = {.flags = InputHint, .input = 1}; |
2989 | XSizeHints *sizeh = NULL; | 3084 | XSizeHints *sizeh = NULL; |
@@ -3015,7 +3110,8 @@ xhints(void) { | |||
3015 | } | 3110 | } |
3016 | 3111 | ||
3017 | int | 3112 | int |
3018 | xgeommasktogravity(int mask) { | 3113 | xgeommasktogravity(int mask) |
3114 | { | ||
3019 | switch(mask & (XNegative|YNegative)) { | 3115 | switch(mask & (XNegative|YNegative)) { |
3020 | case 0: | 3116 | case 0: |
3021 | return NorthWestGravity; | 3117 | return NorthWestGravity; |
@@ -3028,7 +3124,8 @@ xgeommasktogravity(int mask) { | |||
3028 | } | 3124 | } |
3029 | 3125 | ||
3030 | int | 3126 | int |
3031 | xloadfont(Font *f, FcPattern *pattern) { | 3127 | xloadfont(Font *f, FcPattern *pattern) |
3128 | { | ||
3032 | FcPattern *match; | 3129 | FcPattern *match; |
3033 | FcResult result; | 3130 | FcResult result; |
3034 | 3131 | ||
@@ -3056,7 +3153,8 @@ xloadfont(Font *f, FcPattern *pattern) { | |||
3056 | } | 3153 | } |
3057 | 3154 | ||
3058 | void | 3155 | void |
3059 | xloadfonts(char *fontstr, double fontsize) { | 3156 | xloadfonts(char *fontstr, double fontsize) |
3157 | { | ||
3060 | FcPattern *pattern; | 3158 | FcPattern *pattern; |
3061 | double fontval; | 3159 | double fontval; |
3062 | float ceilf(float); | 3160 | float ceilf(float); |
@@ -3130,7 +3228,8 @@ xloadfonts(char *fontstr, double fontsize) { | |||
3130 | } | 3228 | } |
3131 | 3229 | ||
3132 | void | 3230 | void |
3133 | xunloadfont(Font *f) { | 3231 | xunloadfont(Font *f) |
3232 | { | ||
3134 | XftFontClose(xw.dpy, f->match); | 3233 | XftFontClose(xw.dpy, f->match); |
3135 | FcPatternDestroy(f->pattern); | 3234 | FcPatternDestroy(f->pattern); |
3136 | if(f->set) | 3235 | if(f->set) |
@@ -3138,7 +3237,8 @@ xunloadfont(Font *f) { | |||
3138 | } | 3237 | } |
3139 | 3238 | ||
3140 | void | 3239 | void |
3141 | xunloadfonts(void) { | 3240 | xunloadfonts(void) |
3241 | { | ||
3142 | /* Free the loaded fonts in the font cache. */ | 3242 | /* Free the loaded fonts in the font cache. */ |
3143 | while(frclen > 0) | 3243 | while(frclen > 0) |
3144 | XftFontClose(xw.dpy, frc[--frclen].font); | 3244 | XftFontClose(xw.dpy, frc[--frclen].font); |
@@ -3150,7 +3250,8 @@ xunloadfonts(void) { | |||
3150 | } | 3250 | } |
3151 | 3251 | ||
3152 | void | 3252 | void |
3153 | xzoom(const Arg *arg) { | 3253 | xzoom(const Arg *arg) |
3254 | { | ||
3154 | Arg larg; | 3255 | Arg larg; |
3155 | 3256 | ||
3156 | larg.f = usedfontsize + arg->f; | 3257 | larg.f = usedfontsize + arg->f; |
@@ -3158,7 +3259,8 @@ xzoom(const Arg *arg) { | |||
3158 | } | 3259 | } |
3159 | 3260 | ||
3160 | void | 3261 | void |
3161 | xzoomabs(const Arg *arg) { | 3262 | xzoomabs(const Arg *arg) |
3263 | { | ||
3162 | xunloadfonts(); | 3264 | xunloadfonts(); |
3163 | xloadfonts(usedfont, arg->f); | 3265 | xloadfonts(usedfont, arg->f); |
3164 | cresize(0, 0); | 3266 | cresize(0, 0); |
@@ -3167,7 +3269,8 @@ xzoomabs(const Arg *arg) { | |||
3167 | } | 3269 | } |
3168 | 3270 | ||
3169 | void | 3271 | void |
3170 | xzoomreset(const Arg *arg) { | 3272 | xzoomreset(const Arg *arg) |
3273 | { | ||
3171 | Arg larg; | 3274 | Arg larg; |
3172 | 3275 | ||
3173 | if(defaultfontsize > 0) { | 3276 | if(defaultfontsize > 0) { |
@@ -3177,7 +3280,8 @@ xzoomreset(const Arg *arg) { | |||
3177 | } | 3280 | } |
3178 | 3281 | ||
3179 | void | 3282 | void |
3180 | xinit(void) { | 3283 | xinit(void) |
3284 | { | ||
3181 | XGCValues gcvalues; | 3285 | XGCValues gcvalues; |
3182 | Cursor cursor; | 3286 | Cursor cursor; |
3183 | Window parent; | 3287 | Window parent; |
@@ -3408,7 +3512,8 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x | |||
3408 | } | 3512 | } |
3409 | 3513 | ||
3410 | void | 3514 | void |
3411 | xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, int y) { | 3515 | xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, int y) |
3516 | { | ||
3412 | int charlen = len * ((base.mode & ATTR_WIDE) ? 2 : 1); | 3517 | int charlen = len * ((base.mode & ATTR_WIDE) ? 2 : 1); |
3413 | int winx = borderpx + x * xw.cw, winy = borderpx + y * xw.ch, | 3518 | int winx = borderpx + x * xw.cw, winy = borderpx + y * xw.ch, |
3414 | width = charlen * xw.cw; | 3519 | width = charlen * xw.cw; |
@@ -3541,7 +3646,8 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i | |||
3541 | } | 3646 | } |
3542 | 3647 | ||
3543 | void | 3648 | void |
3544 | xdrawglyph(Glyph g, int x, int y) { | 3649 | xdrawglyph(Glyph g, int x, int y) |
3650 | { | ||
3545 | int numspecs; | 3651 | int numspecs; |
3546 | XftGlyphFontSpec spec; | 3652 | XftGlyphFontSpec spec; |
3547 | numspecs = xmakeglyphfontspecs(&spec, &g, 1, x, y); | 3653 | numspecs = xmakeglyphfontspecs(&spec, &g, 1, x, y); |
@@ -3549,7 +3655,8 @@ xdrawglyph(Glyph g, int x, int y) { | |||
3549 | } | 3655 | } |
3550 | 3656 | ||
3551 | void | 3657 | void |
3552 | xdrawcursor(void) { | 3658 | xdrawcursor(void) |
3659 | { | ||
3553 | static int oldx = 0, oldy = 0; | 3660 | static int oldx = 0, oldy = 0; |
3554 | int curx; | 3661 | int curx; |
3555 | Glyph g = {' ', ATTR_NULL, defaultbg, defaultcs}; | 3662 | Glyph g = {' ', ATTR_NULL, defaultbg, defaultcs}; |
@@ -3626,7 +3733,8 @@ xdrawcursor(void) { | |||
3626 | 3733 | ||
3627 | 3734 | ||
3628 | void | 3735 | void |
3629 | xsettitle(char *p) { | 3736 | xsettitle(char *p) |
3737 | { | ||
3630 | XTextProperty prop; | 3738 | XTextProperty prop; |
3631 | 3739 | ||
3632 | Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle, | 3740 | Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle, |
@@ -3637,18 +3745,21 @@ xsettitle(char *p) { | |||
3637 | } | 3745 | } |
3638 | 3746 | ||
3639 | void | 3747 | void |
3640 | xresettitle(void) { | 3748 | xresettitle(void) |
3749 | { | ||
3641 | xsettitle(opt_title ? opt_title : "st"); | 3750 | xsettitle(opt_title ? opt_title : "st"); |
3642 | } | 3751 | } |
3643 | 3752 | ||
3644 | void | 3753 | void |
3645 | redraw(void) { | 3754 | redraw(void) |
3755 | { | ||
3646 | tfulldirt(); | 3756 | tfulldirt(); |
3647 | draw(); | 3757 | draw(); |
3648 | } | 3758 | } |
3649 | 3759 | ||
3650 | void | 3760 | void |
3651 | draw(void) { | 3761 | draw(void) |
3762 | { | ||
3652 | drawregion(0, 0, term.col, term.row); | 3763 | drawregion(0, 0, term.col, term.row); |
3653 | XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, xw.w, | 3764 | XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, xw.w, |
3654 | xw.h, 0, 0); | 3765 | xw.h, 0, 0); |
@@ -3658,7 +3769,8 @@ draw(void) { | |||
3658 | } | 3769 | } |
3659 | 3770 | ||
3660 | void | 3771 | void |
3661 | drawregion(int x1, int y1, int x2, int y2) { | 3772 | drawregion(int x1, int y1, int x2, int y2) |
3773 | { | ||
3662 | int i, x, y, ox, numspecs; | 3774 | int i, x, y, ox, numspecs; |
3663 | Glyph base, new; | 3775 | Glyph base, new; |
3664 | XftGlyphFontSpec* specs; | 3776 | XftGlyphFontSpec* specs; |
@@ -3703,30 +3815,35 @@ drawregion(int x1, int y1, int x2, int y2) { | |||
3703 | } | 3815 | } |
3704 | 3816 | ||
3705 | void | 3817 | void |
3706 | expose(XEvent *ev) { | 3818 | expose(XEvent *ev) |
3819 | { | ||
3707 | redraw(); | 3820 | redraw(); |
3708 | } | 3821 | } |
3709 | 3822 | ||
3710 | void | 3823 | void |
3711 | visibility(XEvent *ev) { | 3824 | visibility(XEvent *ev) |
3825 | { | ||
3712 | XVisibilityEvent *e = &ev->xvisibility; | 3826 | XVisibilityEvent *e = &ev->xvisibility; |
3713 | 3827 | ||
3714 | MODBIT(xw.state, e->state != VisibilityFullyObscured, WIN_VISIBLE); | 3828 | MODBIT(xw.state, e->state != VisibilityFullyObscured, WIN_VISIBLE); |
3715 | } | 3829 | } |
3716 | 3830 | ||
3717 | void | 3831 | void |
3718 | unmap(XEvent *ev) { | 3832 | unmap(XEvent *ev) |
3833 | { | ||
3719 | xw.state &= ~WIN_VISIBLE; | 3834 | xw.state &= ~WIN_VISIBLE; |
3720 | } | 3835 | } |
3721 | 3836 | ||
3722 | void | 3837 | void |
3723 | xsetpointermotion(int set) { | 3838 | xsetpointermotion(int set) |
3839 | { | ||
3724 | MODBIT(xw.attrs.event_mask, set, PointerMotionMask); | 3840 | MODBIT(xw.attrs.event_mask, set, PointerMotionMask); |
3725 | XChangeWindowAttributes(xw.dpy, xw.win, CWEventMask, &xw.attrs); | 3841 | XChangeWindowAttributes(xw.dpy, xw.win, CWEventMask, &xw.attrs); |
3726 | } | 3842 | } |
3727 | 3843 | ||
3728 | void | 3844 | void |
3729 | xseturgency(int add) { | 3845 | xseturgency(int add) |
3846 | { | ||
3730 | XWMHints *h = XGetWMHints(xw.dpy, xw.win); | 3847 | XWMHints *h = XGetWMHints(xw.dpy, xw.win); |
3731 | 3848 | ||
3732 | MODBIT(h->flags, add, XUrgencyHint); | 3849 | MODBIT(h->flags, add, XUrgencyHint); |
@@ -3735,7 +3852,8 @@ xseturgency(int add) { | |||
3735 | } | 3852 | } |
3736 | 3853 | ||
3737 | void | 3854 | void |
3738 | focus(XEvent *ev) { | 3855 | focus(XEvent *ev) |
3856 | { | ||
3739 | XFocusChangeEvent *e = &ev->xfocus; | 3857 | XFocusChangeEvent *e = &ev->xfocus; |
3740 | 3858 | ||
3741 | if(e->mode == NotifyGrab) | 3859 | if(e->mode == NotifyGrab) |
@@ -3756,17 +3874,20 @@ focus(XEvent *ev) { | |||
3756 | } | 3874 | } |
3757 | 3875 | ||
3758 | int | 3876 | int |
3759 | match(uint mask, uint state) { | 3877 | match(uint mask, uint state) |
3878 | { | ||
3760 | return mask == XK_ANY_MOD || mask == (state & ~ignoremod); | 3879 | return mask == XK_ANY_MOD || mask == (state & ~ignoremod); |
3761 | } | 3880 | } |
3762 | 3881 | ||
3763 | void | 3882 | void |
3764 | numlock(const Arg *dummy) { | 3883 | numlock(const Arg *dummy) |
3884 | { | ||
3765 | term.numlock ^= 1; | 3885 | term.numlock ^= 1; |
3766 | } | 3886 | } |
3767 | 3887 | ||
3768 | char* | 3888 | char* |
3769 | kmap(KeySym k, uint state) { | 3889 | kmap(KeySym k, uint state) |
3890 | { | ||
3770 | Key *kp; | 3891 | Key *kp; |
3771 | int i; | 3892 | int i; |
3772 | 3893 | ||
@@ -3805,7 +3926,8 @@ kmap(KeySym k, uint state) { | |||
3805 | } | 3926 | } |
3806 | 3927 | ||
3807 | void | 3928 | void |
3808 | kpress(XEvent *ev) { | 3929 | kpress(XEvent *ev) |
3930 | { | ||
3809 | XKeyEvent *e = &ev->xkey; | 3931 | XKeyEvent *e = &ev->xkey; |
3810 | KeySym ksym; | 3932 | KeySym ksym; |
3811 | char buf[32], *customkey; | 3933 | char buf[32], *customkey; |
@@ -3852,7 +3974,8 @@ kpress(XEvent *ev) { | |||
3852 | 3974 | ||
3853 | 3975 | ||
3854 | void | 3976 | void |
3855 | cmessage(XEvent *e) { | 3977 | cmessage(XEvent *e) |
3978 | { | ||
3856 | /* | 3979 | /* |
3857 | * See xembed specs | 3980 | * See xembed specs |
3858 | * http://standards.freedesktop.org/xembed-spec/xembed-spec-latest.html | 3981 | * http://standards.freedesktop.org/xembed-spec/xembed-spec-latest.html |
@@ -3872,7 +3995,8 @@ cmessage(XEvent *e) { | |||
3872 | } | 3995 | } |
3873 | 3996 | ||
3874 | void | 3997 | void |
3875 | cresize(int width, int height) { | 3998 | cresize(int width, int height) |
3999 | { | ||
3876 | int col, row; | 4000 | int col, row; |
3877 | 4001 | ||
3878 | if(width != 0) | 4002 | if(width != 0) |
@@ -3889,7 +4013,8 @@ cresize(int width, int height) { | |||
3889 | } | 4013 | } |
3890 | 4014 | ||
3891 | void | 4015 | void |
3892 | resize(XEvent *e) { | 4016 | resize(XEvent *e) |
4017 | { | ||
3893 | if(e->xconfigure.width == xw.w && e->xconfigure.height == xw.h) | 4018 | if(e->xconfigure.width == xw.w && e->xconfigure.height == xw.h) |
3894 | return; | 4019 | return; |
3895 | 4020 | ||
@@ -3897,7 +4022,8 @@ resize(XEvent *e) { | |||
3897 | } | 4022 | } |
3898 | 4023 | ||
3899 | void | 4024 | void |
3900 | run(void) { | 4025 | run(void) |
4026 | { | ||
3901 | XEvent ev; | 4027 | XEvent ev; |
3902 | int w = xw.w, h = xw.h; | 4028 | int w = xw.w, h = xw.h; |
3903 | fd_set rfd; | 4029 | fd_set rfd; |
@@ -4004,7 +4130,8 @@ run(void) { | |||
4004 | } | 4130 | } |
4005 | 4131 | ||
4006 | void | 4132 | void |
4007 | usage(void) { | 4133 | usage(void) |
4134 | { | ||
4008 | die("%s " VERSION " (c) 2010-2015 st engineers\n" | 4135 | die("%s " VERSION " (c) 2010-2015 st engineers\n" |
4009 | "usage: st [-a] [-v] [-c class] [-f font] [-g geometry] [-o file]\n" | 4136 | "usage: st [-a] [-v] [-c class] [-f font] [-g geometry] [-o file]\n" |
4010 | " [-i] [-t title] [-w windowid] [-e command ...] [command ...]\n" | 4137 | " [-i] [-t title] [-w windowid] [-e command ...] [command ...]\n" |
@@ -4014,7 +4141,8 @@ usage(void) { | |||
4014 | } | 4141 | } |
4015 | 4142 | ||
4016 | int | 4143 | int |
4017 | main(int argc, char *argv[]) { | 4144 | main(int argc, char *argv[]) |
4145 | { | ||
4018 | uint cols = 80, rows = 24; | 4146 | uint cols = 80, rows = 24; |
4019 | 4147 | ||
4020 | xw.l = xw.t = 0; | 4148 | xw.l = xw.t = 0; |
@@ -4075,4 +4203,3 @@ run: | |||
4075 | 4203 | ||
4076 | return 0; | 4204 | return 0; |
4077 | } | 4205 | } |
4078 | |||