st.h (3574B)
1 /* See LICENSE for license details. */ 2 3 #include <stdint.h> 4 #include <sys/types.h> 5 6 /* macros */ 7 #define MIN(a, b) ((a) < (b) ? (a) : (b)) 8 #define MAX(a, b) ((a) < (b) ? (b) : (a)) 9 #define LEN(a) (sizeof(a) / sizeof(a)[0]) 10 #define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b)) 11 #define DIVCEIL(n, d) (((n) + ((d) - 1)) / (d)) 12 #define DEFAULT(a, b) (a) = (a) ? (a) : (b) 13 #define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x) 14 #define ATTRCMP(a, b) (((a).mode & (~ATTR_WRAP) & (~ATTR_LIGA)) != ((b).mode & (~ATTR_WRAP) & (~ATTR_LIGA)) || \ 15 (a).fg != (b).fg || \ 16 (a).bg != (b).bg) 17 #define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + \ 18 (t1.tv_nsec-t2.tv_nsec)/1E6) 19 #define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit))) 20 21 #define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b)) 22 #define IS_TRUECOL(x) (1 << 24 & (x)) 23 24 enum glyph_attribute { 25 ATTR_NULL = 0, 26 ATTR_BOLD = 1 << 0, 27 ATTR_FAINT = 1 << 1, 28 ATTR_ITALIC = 1 << 2, 29 ATTR_UNDERLINE = 1 << 3, 30 ATTR_BLINK = 1 << 4, 31 ATTR_REVERSE = 1 << 5, 32 ATTR_INVISIBLE = 1 << 6, 33 ATTR_STRUCK = 1 << 7, 34 ATTR_WRAP = 1 << 8, 35 ATTR_WIDE = 1 << 9, 36 ATTR_WDUMMY = 1 << 10, 37 ATTR_BOXDRAW = 1 << 11, 38 ATTR_LIGA = 1 << 12, 39 ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT, 40 }; 41 42 enum selection_mode { 43 SEL_IDLE = 0, 44 SEL_EMPTY = 1, 45 SEL_READY = 2 46 }; 47 48 enum selection_type { 49 SEL_REGULAR = 1, 50 SEL_RECTANGULAR = 2 51 }; 52 53 enum selection_snap { 54 SNAP_WORD = 1, 55 SNAP_LINE = 2 56 }; 57 58 typedef unsigned char uchar; 59 typedef unsigned int uint; 60 typedef unsigned long ulong; 61 typedef unsigned short ushort; 62 63 typedef uint_least32_t Rune; 64 65 #define Glyph Glyph_ 66 typedef struct { 67 Rune u; /* character code */ 68 ushort mode; /* attribute flags */ 69 uint32_t fg; /* foreground */ 70 uint32_t bg; /* background */ 71 } Glyph; 72 73 typedef Glyph *Line; 74 75 typedef union { 76 int i; 77 uint ui; 78 float f; 79 const void *v; 80 const char *s; 81 } Arg; 82 83 void die(const char *, ...); 84 void redraw(void); 85 void tfulldirt(void); 86 void draw(void); 87 88 void externalpipe(const Arg *); 89 void kscrolldown(const Arg *); 90 void kscrollup(const Arg *); 91 92 void printscreen(const Arg *); 93 void printsel(const Arg *); 94 void sendbreak(const Arg *); 95 void toggleprinter(const Arg *); 96 97 int tattrset(int); 98 void tnew(int, int); 99 void tresize(int, int); 100 void tsetdirtattr(int); 101 void ttyhangup(void); 102 int ttynew(const char *, char *, const char *, char **); 103 size_t ttyread(void); 104 void ttyresize(int, int); 105 void ttywrite(const char *, size_t, int); 106 107 void resettitle(void); 108 109 void selclear(void); 110 void selinit(void); 111 void selstart(int, int, int); 112 void selextend(int, int, int, int); 113 int selected(int, int); 114 char *getsel(void); 115 116 size_t utf8encode(Rune, char *); 117 118 void *xmalloc(size_t); 119 void *xrealloc(void *, size_t); 120 char *xstrdup(const char *); 121 122 int isboxdraw(Rune); 123 ushort boxdrawindex(const Glyph *); 124 #ifdef XFT_VERSION 125 /* only exposed to x.c, otherwise we'll need Xft.h for the types */ 126 void boxdraw_xinit(Display *, Colormap, XftDraw *, Visual *); 127 void drawboxes(int, int, int, int, XftColor *, XftColor *, const XftGlyphFontSpec *, int); 128 #endif 129 130 /* config.h globals */ 131 extern char *utmp; 132 extern char *scroll; 133 extern char *stty_args; 134 extern char *vtiden; 135 extern wchar_t *worddelimiters; 136 extern int allowaltscreen; 137 extern int allowwindowops; 138 extern char *termname; 139 extern unsigned int tabspaces; 140 extern unsigned int defaultfg; 141 extern unsigned int defaultbg; 142 extern float alpha; 143 extern float alphaUnfocus; 144 extern const int boxdraw, boxdraw_bold, boxdraw_braille; 145 extern unsigned int defaultcs; 146