1 /*
2  * Copyright (C) 1997-2009, Michael Jennings
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to
6  * deal in the Software without restriction, including without limitation the
7  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8  * sell copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies of the Software, its documentation and marketing & publicity
13  * materials, and acknowledgment shall be given in the documentation, materials
14  * and software packages that this Software was used.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 
24 #ifndef _TERM_H_
25 #define _TERM_H_
26 
27 #include <stdio.h>
28 #include <X11/Xfuncproto.h>
29 #include <X11/Intrinsic.h>	/* Xlib, Xutil, Xresource, Xfuncproto */
30 
31 /************ Macros and Definitions ************/
32 /* Macros to make parsing escape sequences slightly more readable.... <G> */
33 #define OPT_SET_OR_TOGGLE(s, mask, bit) do { \
34         if (!(s) || !(*(s))) { \
35 	  if ((mask) & (bit)) { \
36 	    (mask) &= ~(bit); \
37           } else { \
38 	    (mask) |= (bit); \
39           } \
40         } else if (BOOL_OPT_ISTRUE(s)) { \
41 	  if ((mask) & (bit)) return; \
42 	  (mask) |= (bit); \
43 	} else if (BOOL_OPT_ISFALSE(s)) { \
44 	  if (!((mask) & (bit))) return; \
45 	  (mask) &= ~(bit); \
46 	} \
47       } while (0)
48 /* The macro below forces bit to the opposite state from what we want, so that the
49    code that follows will set it right.  Hackish, but saves space. :)  Use this
50    if you need to do some processing other than just setting the flag right. */
51 #define OPT_SET_OR_TOGGLE_NEG(s, mask, bit) do { if (s) { \
52 	if (BOOL_OPT_ISTRUE(s)) { \
53 	  if ((mask) & (bit)) return; \
54 	  (mask) &= ~(bit); \
55 	} else if (BOOL_OPT_ISFALSE(s)) { \
56 	  if (!((mask) & (bit))) return; \
57 	  (mask) |= (bit); \
58 	} \
59       } } while (0)
60 
61 /* XTerm escape sequences: ESC ] Ps;Pt BEL */
62 # define ESCSEQ_XTERM_NAME           0
63 # define ESCSEQ_XTERM_ICONNAME       1
64 # define ESCSEQ_XTERM_TITLE          2
65 # define ESCSEQ_XTERM_PROP           3
66 # define ESCSEQ_XTERM_CHANGE_COLOR   4
67 # define ESCSEQ_XTERM_FGCOLOR       10
68 # define ESCSEQ_XTERM_BGCOLOR       11
69 # define ESCSEQ_XTERM_CURSOR_COLOR  12
70 # define ESCSEQ_XTERM_PTR_FGCOLOR   13
71 # define ESCSEQ_XTERM_PTR_BGCOLOR   14
72 # define ESCSEQ_XTERM_TEK_FGCOLOR   15
73 # define ESCSEQ_XTERM_TEK_BGCOLOR   16
74 # define ESCSEQ_XTERM_HILIGHT_COLOR 17
75 # define ESCSEQ_XTERM_BOLD_COLOR    18
76 # define ESCSEQ_XTERM_ULINE_COLOR   19
77 # define ESCSEQ_XTERM_LOGFILE       46
78 # define ESCSEQ_XTERM_FONT          50
79 
80 /* rxvt/Eterm extensions of XTerm escape sequences: ESC ] Ps;Pt BEL */
81 # define ESCSEQ_XTERM_TAKEOVER     5     /* Steal keyboard focus and raise window */
82 # define ESCSEQ_XTERM_ETERMSEQ     6     /* Eterm proprietary escape sequences */
83 # define ESCSEQ_XTERM_PIXMAP      20     /* new bg pixmap */
84 # define ESCSEQ_XTERM_DUMPSCREEN  30     /* Dump contents of scrollback to a file */
85 # define ESCSEQ_XTERM_RESTOREFG   39     /* change default fg color */
86 # define ESCSEQ_XTERM_RESTOREBG   49     /* change default bg color */
87 
88 # define restoreFG  512  /* restore default fg color */
89 # define restoreBG  513  /* restore default bg color */
90 
91 enum ansi_color_list {
92     minColor,				/* 0 */
93     BlackColor = minColor,
94     Red3Color,
95     Green3Color,
96     Yellow3Color,
97     Blue3Color,
98     Magenta3Color,
99     Cyan3Color,
100     maxColor,				/* minColor + 7 */
101     AntiqueWhiteColor = maxColor,
102     minBright,				/* maxColor + 1 */
103     Grey25Color = minBright,
104     RedColor,
105     GreenColor,
106     YellowColor,
107     BlueColor,
108     MagentaColor,
109     CyanColor,
110     maxBright,				/* minBright + 7 */
111     WhiteColor = maxBright,
112 };
113 
114 enum color_list {  /* Extra colors */
115     fgColor = 256,
116     bgColor,
117 # ifndef NO_CURSORCOLOR
118     cursorColor,
119     cursorColor2,
120 # endif
121 # ifndef NO_BOLDUNDERLINE
122     colorBD,
123     colorUL,
124 # endif
125 #ifdef ESCREEN
126     ES_COLOR_CURRENT,
127     ES_COLOR_ACTIVE,
128 #endif
129     pointerColor,
130     borderColor,
131     NRS_COLORS,				/* */
132     topShadowColor = NRS_COLORS,
133     bottomShadowColor,
134     unfocusedTopShadowColor,
135     unfocusedBottomShadowColor,
136     menuTopShadowColor,
137     menuBottomShadowColor,
138     unfocusedMenuTopShadowColor,
139     unfocusedMenuBottomShadowColor,
140     TOTAL_COLORS			/* */
141 };
142 
143 # define EXTRA_COLORS		(TOTAL_COLORS - NRS_COLORS)
144 
145 #ifdef HOTKEY_CTRL
146 # define HOTKEY ctrl
147 #elif defined(HOTKEY_META)
148 # define HOTKEY meta
149 #endif
150 
151 #define PrivCases(bit)	do {if (mode == 't') state = !(PrivateModes & bit); else state = mode; \
152                             switch (state) { \
153                               case 's': SavedModes |= (PrivateModes & bit); continue; break; \
154                               case 'r': state = (SavedModes & bit) ? 1 : 0; \
155                               default:  PrivMode(state, bit); break; \
156                             }} while (0)
157 
158 #define COLOR_NAME(c)   ((rs_color[c]) ? (rs_color[c]) : (def_colorName[c]))
159 
160 /************ Variables ************/
161 #ifdef META8_OPTION
162 extern unsigned char meta_char;	/* Alt-key prefix */
163 #endif
164 extern unsigned long PrivateModes;
165 extern unsigned long SavedModes;
166 extern char *def_colorName[];
167 extern char *rs_color[NRS_COLORS];
168 extern Pixel PixColors[NRS_COLORS + EXTRA_COLORS];
169 extern unsigned int MetaMask, AltMask, NumLockMask;
170 extern unsigned int modmasks[];
171 
172 /************ Function Prototypes ************/
173 _XFUNCPROTOBEGIN
174 
175 extern void get_modifiers(void);
176 extern void lookup_key(XEvent *);
177 #ifdef PRINTPIPE
178 extern FILE *popen_printer(void);
179 extern int pclose_printer(FILE *);
180 extern void process_print_pipe(void);
181 #endif
182 extern void process_escape_seq(void);
183 extern void process_csi_seq(void);
184 extern void process_xterm_seq(void);
185 extern void process_window_mode(unsigned int, int []);
186 extern void process_terminal_mode(int, int, unsigned int, int []);
187 extern void process_sgr_mode(unsigned int, int []);
188 extern void set_colorfgbg(void);
189 extern void set_title(const char *);
190 extern void set_icon_name(const char *);
191 extern void append_to_title(const char *);
192 extern void append_to_icon_name(const char *);
193 extern void xterm_seq(int, const char *);
194 
195 _XFUNCPROTOEND
196 
197 #endif	/* _TERM_H_ */
198