1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: misc.c |
2 | * File: misc.c |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * $Id: misc.C,v 1.2 2003/11/24 17:31:27 pcg Exp $ |
|
|
5 | * |
4 | * |
6 | * All portions of code are copyright by their respective author/s. |
5 | * All portions of code are copyright by their respective author/s. |
7 | * Copyright (c) 1996 mj olesen <olesen@me.QueensU.CA> Queen's Univ at Kingston |
6 | * Copyright (c) 1996 mj olesen <olesen@me.QueensU.CA> Queen's Univ at Kingston |
8 | * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> |
7 | * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> |
9 | * Copyright (c) 1998-2000 Geoff Wing <gcw@pobox.com> |
8 | * Copyright (c) 1998-2000 Geoff Wing <gcw@pobox.com> |
|
|
9 | * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> |
10 | * |
10 | * |
11 | * This program is free software; you can redistribute it and/or modify |
11 | * This program is free software; you can redistribute it and/or modify |
12 | * it under the terms of the GNU General Public License as published by |
12 | * it under the terms of the GNU General Public License as published by |
13 | * the Free Software Foundation; either version 2 of the License, or |
13 | * the Free Software Foundation; either version 2 of the License, or |
14 | * (at your option) any later version. |
14 | * (at your option) any later version. |
… | |
… | |
26 | #include "../config.h" /* NECESSARY */ |
26 | #include "../config.h" /* NECESSARY */ |
27 | #include "rxvt.h" /* NECESSARY */ |
27 | #include "rxvt.h" /* NECESSARY */ |
28 | #include "misc.intpro" /* PROTOS for internal routines */ |
28 | #include "misc.intpro" /* PROTOS for internal routines */ |
29 | |
29 | |
30 | /* EXTPROTO */ |
30 | /* EXTPROTO */ |
31 | char * |
31 | char * |
|
|
32 | rxvt_strdup (const char *str) |
|
|
33 | { |
|
|
34 | return str ? strdup (str) : 0; |
|
|
35 | } |
|
|
36 | |
|
|
37 | /* EXTPROTO */ |
|
|
38 | char * |
32 | rxvt_r_basename(const char *str) |
39 | rxvt_r_basename (const char *str) |
33 | { |
40 | { |
34 | char *base = STRRCHR(str, '/'); |
41 | char *base = STRRCHR (str, '/'); |
35 | |
42 | |
36 | return (char *)(base ? base + 1 : str); |
43 | return (char *) (base ? base + 1 : str); |
37 | } |
44 | } |
38 | |
45 | |
39 | /* |
46 | /* |
40 | * Print an error message |
47 | * Print an error message |
41 | */ |
48 | */ |
42 | /* EXTPROTO */ |
49 | /* EXTPROTO */ |
43 | void |
50 | void |
44 | rxvt_print_error(const char *fmt,...) |
51 | rxvt_print_error (const char *fmt,...) |
45 | { |
52 | { |
46 | va_list arg_ptr; |
53 | va_list arg_ptr; |
47 | |
54 | |
48 | va_start(arg_ptr, fmt); |
55 | va_start (arg_ptr, fmt); |
49 | fprintf(stderr, APL_NAME ": "); |
56 | fprintf (stderr, RESNAME ": "); |
50 | vfprintf(stderr, fmt, arg_ptr); |
57 | vfprintf (stderr, fmt, arg_ptr); |
51 | fprintf(stderr, "\n"); |
58 | fprintf (stderr, "\n"); |
52 | va_end(arg_ptr); |
59 | va_end (arg_ptr); |
53 | } |
60 | } |
54 | |
61 | |
55 | /* |
62 | /* |
56 | * check that the first characters of S1 match S2 |
63 | * check that the first characters of S1 match S2 |
57 | * |
64 | * |
… | |
… | |
60 | * Match |
67 | * Match |
61 | * return: STRLEN (S2) |
68 | * return: STRLEN (S2) |
62 | */ |
69 | */ |
63 | /* EXTPROTO */ |
70 | /* EXTPROTO */ |
64 | int |
71 | int |
65 | rxvt_Str_match(const char *s1, const char *s2) |
72 | rxvt_Str_match (const char *s1, const char *s2) |
66 | { |
73 | { |
67 | int n = STRLEN(s2); |
74 | int n = STRLEN (s2); |
68 | |
75 | |
69 | return ((STRNCMP(s1, s2, n) == 0) ? n : 0); |
76 | return ((STRNCMP (s1, s2, n) == 0) ? n : 0); |
70 | } |
77 | } |
71 | |
78 | |
72 | /* EXTPROTO */ |
79 | /* EXTPROTO */ |
73 | const char * |
80 | const char * |
74 | rxvt_Str_skip_space(const char *str) |
81 | rxvt_Str_skip_space (const char *str) |
75 | { |
82 | { |
76 | if (str) |
83 | if (str) |
77 | while (*str && isspace(*str)) |
84 | while (*str && isspace (*str)) |
78 | str++; |
85 | str++; |
|
|
86 | |
79 | return str; |
87 | return str; |
80 | } |
88 | } |
81 | |
89 | |
82 | /* |
90 | /* |
83 | * remove leading/trailing space and strip-off leading/trailing quotes. |
91 | * remove leading/trailing space and strip-off leading/trailing quotes. |
84 | * in place. |
92 | * in place. |
85 | */ |
93 | */ |
86 | /* EXTPROTO */ |
94 | /* EXTPROTO */ |
87 | char * |
95 | char * |
88 | rxvt_Str_trim(char *str) |
96 | rxvt_Str_trim (char *str) |
89 | { |
97 | { |
90 | char *r, *s; |
98 | char *r, *s; |
91 | int n; |
99 | int n; |
92 | |
100 | |
93 | if (!str || !*str) /* shortcut */ |
101 | if (!str || !*str) /* shortcut */ |
94 | return str; |
|
|
95 | |
|
|
96 | /* skip leading spaces */ |
|
|
97 | for (s = str; *s && isspace(*s); s++) ; |
|
|
98 | /* goto end of string */ |
|
|
99 | for (n = 0, r = s; *r++; n++) ; |
|
|
100 | r -= 2; |
|
|
101 | /* dump return */ |
|
|
102 | if (n > 0 && *r == '\n') |
|
|
103 | n--, r--; |
|
|
104 | /* backtrack along trailing spaces */ |
|
|
105 | for (; n > 0 && isspace(*r); r--, n--) ; |
|
|
106 | /* skip matching leading/trailing quotes */ |
|
|
107 | if (*s == '"' && *r == '"' && n > 1) { |
|
|
108 | s++; |
|
|
109 | n -= 2; |
|
|
110 | } |
|
|
111 | /* copy back over: forwards copy */ |
|
|
112 | for (r = str; n; n--) |
|
|
113 | *r++ = *s++; |
|
|
114 | *r = '\0'; |
|
|
115 | |
|
|
116 | return str; |
102 | return str; |
|
|
103 | |
|
|
104 | /* skip leading spaces */ |
|
|
105 | for (s = str; *s && isspace (*s); s++) ; |
|
|
106 | /* goto end of string */ |
|
|
107 | for (n = 0, r = s; *r++; n++) ; |
|
|
108 | r -= 2; |
|
|
109 | /* dump return */ |
|
|
110 | if (n > 0 && *r == '\n') |
|
|
111 | n--, r--; |
|
|
112 | /* backtrack along trailing spaces */ |
|
|
113 | for (; n > 0 && isspace (*r); r--, n--) ; |
|
|
114 | /* skip matching leading/trailing quotes */ |
|
|
115 | if (*s == '"' && *r == '"' && n > 1) |
|
|
116 | { |
|
|
117 | s++; |
|
|
118 | n -= 2; |
|
|
119 | } |
|
|
120 | |
|
|
121 | /* copy back over: forwards copy */ |
|
|
122 | for (r = str; n; n--) |
|
|
123 | *r++ = *s++; |
|
|
124 | *r = '\0'; |
|
|
125 | |
|
|
126 | return str; |
117 | } |
127 | } |
118 | |
128 | |
119 | /* |
129 | /* |
120 | * in-place interpretation of string: |
130 | * in-place interpretation of string: |
121 | * |
131 | * |
… | |
… | |
130 | * |
140 | * |
131 | * returns the converted string length |
141 | * returns the converted string length |
132 | */ |
142 | */ |
133 | /* EXTPROTO */ |
143 | /* EXTPROTO */ |
134 | int |
144 | int |
135 | rxvt_Str_escaped(char *str) |
145 | rxvt_Str_escaped (char *str) |
136 | { |
146 | { |
137 | char ch, *s, *d; |
147 | char ch, *s, *d; |
138 | int i, num, append = 0; |
148 | int i, num, append = 0; |
139 | |
149 | |
140 | if (!str || !*str) |
150 | if (!str || !*str) |
141 | return 0; |
151 | return 0; |
142 | |
152 | |
143 | d = s = str; |
153 | d = s = str; |
144 | |
154 | |
145 | if (*s == 'M' && s[1] == '-') { |
155 | if (*s == 'M' && s[1] == '-') |
|
|
156 | { |
146 | /* Emacs convenience, replace leading `M-..' with `\E..' */ |
157 | /* Emacs convenience, replace leading `M-..' with `\E..' */ |
147 | *d++ = C0_ESC; |
158 | *d++ = C0_ESC; |
148 | s += 2; |
159 | s += 2; |
149 | if (toupper(*s) == 'X') |
160 | if (toupper (*s) == 'X') |
150 | /* append carriage-return for `M-xcommand' */ |
161 | /* append carriage-return for `M-xcommand' */ |
151 | for (*d++ = 'x', append = '\r', s++; isspace(*s); s++) ; |
162 | for (*d++ = 'x', append = '\r', s++; isspace (*s); s++) ; |
152 | } |
163 | } |
153 | for (; (ch = *s++);) { |
164 | for (; (ch = *s++);) |
|
|
165 | { |
154 | if (ch == '\\') { |
166 | if (ch == '\\') |
|
|
167 | { |
155 | ch = *s++; |
168 | ch = *s++; |
156 | if (ch >= '0' && ch <= '7') { /* octal */ |
169 | if (ch >= '0' && ch <= '7') |
157 | num = ch - '0'; |
170 | { /* octal */ |
|
|
171 | num = ch - '0'; |
158 | for (i = 0; i < 2; i++, s++) { |
172 | for (i = 0; i < 2; i++, s++) |
159 | ch = *s; |
173 | { |
|
|
174 | ch = *s; |
160 | if (ch < '0' || ch > '7') |
175 | if (ch < '0' || ch > '7') |
161 | break; |
176 | break; |
162 | num = num * 8 + ch - '0'; |
177 | num = num * 8 + ch - '0'; |
163 | } |
178 | } |
164 | ch = (char)num; |
179 | ch = (char)num; |
165 | } else if (ch == 'a') |
180 | } |
|
|
181 | else if (ch == 'a') |
166 | ch = C0_BEL; /* bell */ |
182 | ch = C0_BEL; /* bell */ |
167 | else if (ch == 'b') |
183 | else if (ch == 'b') |
168 | ch = C0_BS; /* backspace */ |
184 | ch = C0_BS; /* backspace */ |
169 | else if (ch == 'E' || ch == 'e') |
185 | else if (ch == 'E' || ch == 'e') |
170 | ch = C0_ESC; /* escape */ |
186 | ch = C0_ESC; /* escape */ |
|
|
187 | else if (ch == 'n') |
|
|
188 | ch = '\n'; /* newline */ |
|
|
189 | else if (ch == 'r') |
|
|
190 | ch = '\r'; /* carriage-return */ |
|
|
191 | else if (ch == 't') |
|
|
192 | ch = C0_HT; /* tab */ |
|
|
193 | } |
171 | else if (ch == 'n') |
194 | else if (ch == '^') |
172 | ch = '\n'; /* newline */ |
195 | { |
173 | else if (ch == 'r') |
|
|
174 | ch = '\r'; /* carriage-return */ |
|
|
175 | else if (ch == 't') |
|
|
176 | ch = C0_HT; /* tab */ |
|
|
177 | } else if (ch == '^') { |
|
|
178 | ch = *s++; |
196 | ch = *s++; |
179 | ch = toupper(ch); |
197 | ch = toupper (ch); |
180 | ch = (ch == '?' ? 127 : (ch - '@')); |
198 | ch = (ch == '?' ? 127 : (ch - '@')); |
181 | } |
199 | } |
182 | *d++ = ch; |
200 | *d++ = ch; |
183 | } |
201 | } |
184 | |
202 | |
185 | /* ESC] is an XTerm escape sequence, must be terminated */ |
203 | /* ESC] is an XTerm escape sequence, must be terminated */ |
186 | if (*str == '\0' && str[1] == C0_ESC && str[2] == ']') |
204 | if (*str == '\0' && str[1] == C0_ESC && str[2] == ']') |
187 | append = CHAR_ST; |
205 | append = CHAR_ST; |
188 | |
206 | |
189 | /* add trailing character as required */ |
207 | /* add trailing character as required */ |
190 | if (append && d[-1] != append) |
208 | if (append && d[-1] != append) |
191 | *d++ = append; |
209 | *d++ = append; |
192 | *d = '\0'; |
210 | *d = '\0'; |
193 | |
211 | |
194 | return (d - str); |
212 | return (d - str); |
195 | } |
213 | } |
196 | |
214 | |
197 | /* |
215 | /* |
198 | * Split a comma-separated string into an array, stripping leading and |
216 | * Split a comma-separated string into an array, stripping leading and |
199 | * trailing spaces (and paired quotes) from each entry. Empty strings |
217 | * trailing spaces (and paired quotes) from each entry. Empty strings |
200 | * are properly returned |
218 | * are properly returned |
201 | * Caller should free each entry and array when done |
219 | * Caller should free each entry and array when done |
202 | */ |
220 | */ |
203 | /* EXTPROTO */ |
221 | /* EXTPROTO */ |
204 | char ** |
222 | char ** |
205 | rxvt_splitcommastring(const char *cs) |
223 | rxvt_splitcommastring (const char *cs) |
206 | { |
224 | { |
207 | int l, n, p; |
225 | int l, n, p; |
208 | const char *s, *t; |
226 | const char *s, *t; |
209 | char **ret; |
227 | char **ret; |
210 | |
228 | |
211 | if ((s = cs) == NULL) |
229 | if ((s = cs) == NULL) |
212 | s = ""; |
230 | s = ""; |
213 | |
231 | |
214 | for (n = 1, t = s; *t; t++) |
232 | for (n = 1, t = s; *t; t++) |
215 | if (*t == ',') |
233 | if (*t == ',') |
216 | n++; |
234 | n++; |
217 | ret = (char **)malloc((n + 1) * sizeof(char *)); |
235 | ret = (char **)malloc ((n + 1) * sizeof (char *)); |
218 | ret[n] = NULL; |
236 | ret[n] = NULL; |
219 | |
237 | |
220 | for (l = 0, t = s; l < n; l++) { |
238 | for (l = 0, t = s; l < n; l++) |
|
|
239 | { |
221 | for ( ; *t && *t != ','; t++) ; |
240 | for ( ; *t && *t != ','; t++) ; |
222 | p = t - s; |
241 | p = t - s; |
223 | ret[l] = (char *)malloc(p + 1); |
242 | ret[l] = (char *)malloc (p + 1); |
224 | strncpy(ret[l], s, p); |
243 | strncpy (ret[l], s, p); |
225 | ret[l][p] = '\0'; |
244 | ret[l][p] = '\0'; |
226 | rxvt_Str_trim(ret[l]); |
245 | rxvt_Str_trim (ret[l]); |
227 | s = ++t; |
246 | s = ++t; |
228 | } |
247 | } |
229 | return ret; |
248 | return ret; |
230 | } |
249 | } |
231 | |
250 | |
232 | /*----------------------------------------------------------------------* |
251 | /*----------------------------------------------------------------------* |
233 | * file searching |
252 | * file searching |
234 | */ |
253 | */ |
… | |
… | |
242 | * |
261 | * |
243 | * FILE is either semi-colon or zero terminated |
262 | * FILE is either semi-colon or zero terminated |
244 | */ |
263 | */ |
245 | /* INTPROTO */ |
264 | /* INTPROTO */ |
246 | char * |
265 | char * |
247 | rxvt_File_search_path(const char *pathlist, const char *file, const char *ext) |
266 | rxvt_File_search_path (const char *pathlist, const char *file, const char *ext) |
248 | { |
267 | { |
249 | int maxpath, len; |
268 | int maxpath, len; |
250 | const char *p, *path; |
269 | const char *p, *path; |
251 | char name[256]; |
270 | char name[256]; |
252 | |
271 | |
253 | if (!access(file, R_OK)) /* found (plain name) in current directory */ |
272 | if (!access (file, R_OK)) /* found (plain name) in current directory */ |
254 | return STRDUP(file); |
273 | return STRDUP (file); |
255 | |
274 | |
256 | /* semi-colon delimited */ |
275 | /* semi-colon delimited */ |
257 | if ((p = STRCHR(file, ';'))) |
276 | if ((p = STRCHR (file, ';'))) |
258 | len = (p - file); |
277 | len = (p - file); |
259 | else |
278 | else |
260 | len = STRLEN(file); |
279 | len = STRLEN (file); |
261 | |
280 | |
262 | #ifdef DEBUG_SEARCH_PATH |
281 | #ifdef DEBUG_SEARCH_PATH |
263 | getcwd(name, sizeof(name)); |
282 | getcwd (name, sizeof (name)); |
264 | fprintf(stderr, "pwd: \"%s\"\n", name); |
283 | fprintf (stderr, "pwd: \"%s\"\n", name); |
265 | fprintf(stderr, "find: \"%.*s\"\n", len, file); |
284 | fprintf (stderr, "find: \"%.*s\"\n", len, file); |
266 | #endif |
285 | #endif |
267 | |
286 | |
268 | /* leave room for an extra '/' and trailing '\0' */ |
287 | /* leave room for an extra '/' and trailing '\0' */ |
269 | maxpath = sizeof(name) - (len + (ext ? STRLEN(ext) : 0) + 2); |
288 | maxpath = sizeof (name) - (len + (ext ? STRLEN (ext) : 0) + 2); |
270 | if (maxpath <= 0) |
289 | if (maxpath <= 0) |
271 | return NULL; |
|
|
272 | |
|
|
273 | /* check if we can find it now */ |
|
|
274 | STRNCPY(name, file, len); |
|
|
275 | name[len] = '\0'; |
|
|
276 | |
|
|
277 | if (!access(name, R_OK)) |
|
|
278 | return STRDUP(name); |
|
|
279 | if (ext) { |
|
|
280 | STRCAT(name, ext); |
|
|
281 | if (!access(name, R_OK)) |
|
|
282 | return STRDUP(name); |
|
|
283 | } |
|
|
284 | for (path = pathlist; path != NULL && *path != '\0'; path = p) { |
|
|
285 | int n; |
|
|
286 | |
|
|
287 | /* colon delimited */ |
|
|
288 | if ((p = STRCHR(path, ':')) == NULL) |
|
|
289 | p = STRCHR(path, '\0'); |
|
|
290 | |
|
|
291 | n = (p - path); |
|
|
292 | if (*p != '\0') |
|
|
293 | p++; |
|
|
294 | |
|
|
295 | if (n > 0 && n <= maxpath) { |
|
|
296 | STRNCPY(name, path, n); |
|
|
297 | if (name[n - 1] != '/') |
|
|
298 | name[n++] = '/'; |
|
|
299 | name[n] = '\0'; |
|
|
300 | STRNCAT(name, file, len); |
|
|
301 | |
|
|
302 | if (!access(name, R_OK)) |
|
|
303 | return STRDUP(name); |
|
|
304 | if (ext) { |
|
|
305 | STRCAT(name, ext); |
|
|
306 | if (!access(name, R_OK)) |
|
|
307 | return STRDUP(name); |
|
|
308 | } |
|
|
309 | } |
|
|
310 | } |
|
|
311 | return NULL; |
290 | return NULL; |
|
|
291 | |
|
|
292 | /* check if we can find it now */ |
|
|
293 | STRNCPY (name, file, len); |
|
|
294 | name[len] = '\0'; |
|
|
295 | |
|
|
296 | if (!access (name, R_OK)) |
|
|
297 | return STRDUP (name); |
|
|
298 | if (ext) |
|
|
299 | { |
|
|
300 | STRCAT (name, ext); |
|
|
301 | if (!access (name, R_OK)) |
|
|
302 | return STRDUP (name); |
|
|
303 | } |
|
|
304 | for (path = pathlist; path != NULL && *path != '\0'; path = p) |
|
|
305 | { |
|
|
306 | int n; |
|
|
307 | |
|
|
308 | /* colon delimited */ |
|
|
309 | if ((p = STRCHR (path, ':')) == NULL) |
|
|
310 | p = STRCHR (path, '\0'); |
|
|
311 | |
|
|
312 | n = (p - path); |
|
|
313 | if (*p != '\0') |
|
|
314 | p++; |
|
|
315 | |
|
|
316 | if (n > 0 && n <= maxpath) |
|
|
317 | { |
|
|
318 | STRNCPY (name, path, n); |
|
|
319 | if (name[n - 1] != '/') |
|
|
320 | name[n++] = '/'; |
|
|
321 | name[n] = '\0'; |
|
|
322 | STRNCAT (name, file, len); |
|
|
323 | |
|
|
324 | if (!access (name, R_OK)) |
|
|
325 | return STRDUP (name); |
|
|
326 | if (ext) |
|
|
327 | { |
|
|
328 | STRCAT (name, ext); |
|
|
329 | if (!access (name, R_OK)) |
|
|
330 | return STRDUP (name); |
|
|
331 | } |
|
|
332 | } |
|
|
333 | } |
|
|
334 | return NULL; |
312 | } |
335 | } |
313 | |
336 | |
314 | /* EXTPROTO */ |
337 | /* EXTPROTO */ |
315 | char * |
338 | char * |
316 | rxvt_File_find(const char *file, const char *ext, const char *path) |
339 | rxvt_File_find (const char *file, const char *ext, const char *path) |
317 | { |
340 | { |
318 | char *f; |
341 | char *f; |
319 | |
342 | |
320 | if (file == NULL || *file == '\0') |
343 | if (file == NULL || *file == '\0') |
321 | return NULL; |
344 | return NULL; |
322 | |
345 | |
323 | /* search environment variables here too */ |
346 | /* search environment variables here too */ |
324 | if ((f = rxvt_File_search_path(path, file, ext)) == NULL) |
347 | if ((f = rxvt_File_search_path (path, file, ext)) == NULL) |
325 | #ifdef PATH_ENV |
348 | #ifdef PATH_ENV |
326 | if ((f = rxvt_File_search_path(getenv(PATH_ENV), file, ext)) == NULL) |
349 | if ((f = rxvt_File_search_path (getenv (PATH_ENV), file, ext)) == NULL) |
327 | #endif |
350 | #endif |
328 | f = rxvt_File_search_path(getenv("PATH"), file, ext); |
351 | f = rxvt_File_search_path (getenv ("PATH"), file, ext); |
329 | |
352 | |
330 | #ifdef DEBUG_SEARCH_PATH |
353 | #ifdef DEBUG_SEARCH_PATH |
331 | if (f) |
354 | if (f) |
332 | fprintf(stderr, "found: \"%s\"\n", f); |
355 | fprintf (stderr, "found: \"%s\"\n", f); |
333 | #endif |
356 | #endif |
334 | |
357 | |
335 | return f; |
358 | return f; |
336 | } |
359 | } |
337 | #endif /* defined (XPM_BACKGROUND) || (MENUBAR_MAX) */ |
360 | #endif /* defined (XPM_BACKGROUND) || (MENUBAR_MAX) */ |
338 | |
361 | |
339 | /*----------------------------------------------------------------------* |
362 | /*----------------------------------------------------------------------* |
340 | * miscellaneous drawing routines |
363 | * miscellaneous drawing routines |
… | |
… | |
344 | * Draw top/left and bottom/right border shadows around windows |
367 | * Draw top/left and bottom/right border shadows around windows |
345 | */ |
368 | */ |
346 | #if defined(RXVT_SCROLLBAR) || defined(MENUBAR) |
369 | #if defined(RXVT_SCROLLBAR) || defined(MENUBAR) |
347 | /* EXTPROTO */ |
370 | /* EXTPROTO */ |
348 | void |
371 | void |
349 | rxvt_Draw_Shadow(Display *Xdisplay, Window win, GC topShadow, GC botShadow, int x, int y, int w, int h) |
372 | rxvt_Draw_Shadow (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int h) |
350 | { |
373 | { |
351 | int shadow; |
374 | int shadow; |
352 | |
375 | |
353 | shadow = (w == 0 || h == 0) ? 1 : SHADOW; |
376 | shadow = (w == 0 || h == 0) ? 1 : SHADOW; |
354 | w += x - 1; |
377 | w += x - 1; |
355 | h += y - 1; |
378 | h += y - 1; |
356 | for (; shadow-- > 0; x++, y++, w--, h--) { |
379 | for (; shadow-- > 0; x++, y++, w--, h--) |
|
|
380 | { |
357 | XDrawLine(Xdisplay, win, topShadow, x, y, w, y); |
381 | XDrawLine (display, win, topShadow, x, y, w, y); |
358 | XDrawLine(Xdisplay, win, topShadow, x, y, x, h); |
382 | XDrawLine (display, win, topShadow, x, y, x, h); |
359 | XDrawLine(Xdisplay, win, botShadow, w, h, w, y + 1); |
383 | XDrawLine (display, win, botShadow, w, h, w, y + 1); |
360 | XDrawLine(Xdisplay, win, botShadow, w, h, x + 1, h); |
384 | XDrawLine (display, win, botShadow, w, h, x + 1, h); |
361 | } |
385 | } |
362 | } |
386 | } |
363 | #endif |
387 | #endif |
364 | |
388 | |
365 | /* button shapes */ |
389 | /* button shapes */ |
366 | #ifdef MENUBAR |
390 | #ifdef MENUBAR |
367 | /* EXTPROTO */ |
391 | /* EXTPROTO */ |
368 | void |
392 | void |
369 | rxvt_Draw_Triangle(Display *Xdisplay, Window win, GC topShadow, GC botShadow, int x, int y, int w, int type) |
393 | rxvt_Draw_Triangle (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int type) |
370 | { |
394 | { |
371 | switch (type) { |
395 | switch (type) |
|
|
396 | { |
372 | case 'r': /* right triangle */ |
397 | case 'r': /* right triangle */ |
373 | XDrawLine(Xdisplay, win, topShadow, x, y, x, y + w); |
398 | XDrawLine (display, win, topShadow, x, y, x, y + w); |
374 | XDrawLine(Xdisplay, win, topShadow, x, y, x + w, y + w / 2); |
399 | XDrawLine (display, win, topShadow, x, y, x + w, y + w / 2); |
375 | XDrawLine(Xdisplay, win, botShadow, x, y + w, x + w, y + w / 2); |
400 | XDrawLine (display, win, botShadow, x, y + w, x + w, y + w / 2); |
376 | break; |
401 | break; |
377 | |
402 | |
378 | case 'l': /* left triangle */ |
403 | case 'l': /* left triangle */ |
379 | XDrawLine(Xdisplay, win, botShadow, x + w, y + w, x + w, y); |
404 | XDrawLine (display, win, botShadow, x + w, y + w, x + w, y); |
380 | XDrawLine(Xdisplay, win, botShadow, x + w, y + w, x, y + w / 2); |
405 | XDrawLine (display, win, botShadow, x + w, y + w, x, y + w / 2); |
381 | XDrawLine(Xdisplay, win, topShadow, x, y + w / 2, x + w, y); |
406 | XDrawLine (display, win, topShadow, x, y + w / 2, x + w, y); |
382 | break; |
407 | break; |
383 | |
408 | |
384 | case 'd': /* down triangle */ |
409 | case 'd': /* down triangle */ |
385 | XDrawLine(Xdisplay, win, topShadow, x, y, x + w / 2, y + w); |
410 | XDrawLine (display, win, topShadow, x, y, x + w / 2, y + w); |
386 | XDrawLine(Xdisplay, win, topShadow, x, y, x + w, y); |
411 | XDrawLine (display, win, topShadow, x, y, x + w, y); |
387 | XDrawLine(Xdisplay, win, botShadow, x + w, y, x + w / 2, y + w); |
412 | XDrawLine (display, win, botShadow, x + w, y, x + w / 2, y + w); |
388 | break; |
413 | break; |
389 | |
414 | |
390 | case 'u': /* up triangle */ |
415 | case 'u': /* up triangle */ |
391 | XDrawLine(Xdisplay, win, botShadow, x + w, y + w, x + w / 2, y); |
416 | XDrawLine (display, win, botShadow, x + w, y + w, x + w / 2, y); |
392 | XDrawLine(Xdisplay, win, botShadow, x + w, y + w, x, y + w); |
417 | XDrawLine (display, win, botShadow, x + w, y + w, x, y + w); |
393 | XDrawLine(Xdisplay, win, topShadow, x, y + w, x + w / 2, y); |
418 | XDrawLine (display, win, topShadow, x, y + w, x + w / 2, y); |
394 | break; |
419 | break; |
395 | #if 0 |
420 | #if 0 |
396 | case 's': /* square */ |
421 | case 's': /* square */ |
397 | XDrawLine(Xdisplay, win, topShadow, x + w, y, x, y); |
422 | XDrawLine (display, win, topShadow, x + w, y, x, y); |
398 | XDrawLine(Xdisplay, win, topShadow, x, y, x, y + w); |
423 | XDrawLine (display, win, topShadow, x, y, x, y + w); |
399 | XDrawLine(Xdisplay, win, botShadow, x, y + w, x + w, y + w); |
424 | XDrawLine (display, win, botShadow, x, y + w, x + w, y + w); |
400 | XDrawLine(Xdisplay, win, botShadow, x + w, y + w, x + w, y); |
425 | XDrawLine (display, win, botShadow, x + w, y + w, x + w, y); |
401 | break; |
426 | break; |
402 | #endif |
427 | #endif |
|
|
428 | |
403 | } |
429 | } |
404 | } |
430 | } |
405 | #endif |
431 | #endif |
406 | /*----------------------- end-of-file (C source) -----------------------*/ |
432 | /*----------------------- end-of-file (C source) -----------------------*/ |