Lines 107-113
Link Here
|
107 |
} |
107 |
} |
108 |
|
108 |
|
109 |
int |
109 |
int |
110 |
bar_y (screen_info *s) |
110 |
bar_y (screen_info *s, int height) |
111 |
{ |
111 |
{ |
112 |
int y = 0; |
112 |
int y = 0; |
113 |
|
113 |
|
Lines 121-133
Link Here
|
121 |
case EastGravity: |
121 |
case EastGravity: |
122 |
case CenterGravity: |
122 |
case CenterGravity: |
123 |
case WestGravity: |
123 |
case WestGravity: |
124 |
y = (s->root_attr.height - (FONT_HEIGHT (defaults.font) + defaults.bar_y_padding * 2) |
124 |
y = (s->root_attr.height - height |
125 |
- defaults.bar_border_width * 2) / 2; |
125 |
- defaults.bar_border_width * 2) / 2; |
126 |
break; |
126 |
break; |
127 |
case SouthEastGravity: |
127 |
case SouthEastGravity: |
128 |
case SouthGravity: |
128 |
case SouthGravity: |
129 |
case SouthWestGravity: |
129 |
case SouthWestGravity: |
130 |
y = (s->root_attr.height - (FONT_HEIGHT (defaults.font) + defaults.bar_y_padding * 2) |
130 |
y = (s->root_attr.height - height |
131 |
- defaults.bar_border_width * 2); |
131 |
- defaults.bar_border_width * 2); |
132 |
break; |
132 |
break; |
133 |
} |
133 |
} |
Lines 148-156
Link Here
|
148 |
if (bar_buffer == NULL) |
148 |
if (bar_buffer == NULL) |
149 |
bar_buffer = sbuf_new (0); |
149 |
bar_buffer = sbuf_new (0); |
150 |
|
150 |
|
151 |
get_window_list (defaults.window_fmt, NULL, bar_buffer, &mark_start, &mark_end); |
151 |
if(!defaults.wrap_window_list){ |
|
|
152 |
get_window_list (defaults.window_fmt, NULL, bar_buffer, &mark_start, &mark_end); |
153 |
marked_message (sbuf_get (bar_buffer), mark_start, mark_end); |
154 |
} |
155 |
else{ |
156 |
get_window_list (defaults.window_fmt, "\n", bar_buffer, &mark_start, &mark_end); |
157 |
marked_wrapped_message(sbuf_get (bar_buffer), mark_start, mark_end); |
158 |
} |
152 |
|
159 |
|
153 |
marked_message (sbuf_get (bar_buffer), mark_start, mark_end); |
|
|
154 |
} |
160 |
} |
155 |
|
161 |
|
156 |
void |
162 |
void |
Lines 167-172
Link Here
|
167 |
free (buffer); |
173 |
free (buffer); |
168 |
} |
174 |
} |
169 |
|
175 |
|
|
|
176 |
|
177 |
int |
178 |
count_lines (char* msg, int len) |
179 |
{ |
180 |
int ret=1; |
181 |
int i=0; |
182 |
for(; i<len; ++i) { |
183 |
if(msg[i]=='\n') ret++; |
184 |
} |
185 |
PRINT_DEBUG("count_lines: %d\n", ret); |
186 |
return ret; |
187 |
} |
188 |
|
189 |
|
190 |
int |
191 |
max_line_length (char* msg) |
192 |
{ |
193 |
int ret=0; |
194 |
int i=0; |
195 |
int j=0; |
196 |
int len=strlen(msg); |
197 |
int current_width=0; |
198 |
char tmp_buf[100]; |
199 |
|
200 |
for(; i<=len; ++j, ++i) { |
201 |
if(msg[i]=='\n' || msg[i]=='\0') { |
202 |
tmp_buf[j]='\0'; |
203 |
current_width = XTextWidth (defaults.font, tmp_buf, strlen (tmp_buf)); |
204 |
if(current_width>ret) ret=current_width; |
205 |
j=0; |
206 |
} |
207 |
else tmp_buf[j]=msg[i]; |
208 |
} |
209 |
PRINT_DEBUG("max_line_length: %d\n", ret); |
210 |
return ret; |
211 |
} |
212 |
|
213 |
int |
214 |
pos_in_line (char* msg, int pos) |
215 |
{ |
216 |
int i=pos - 1; |
217 |
int ret=0; |
218 |
if(i>=0) { |
219 |
for(; i<=pos && i>=0; ++ret, --i) if(msg[i]=='\n') break; |
220 |
} |
221 |
PRINT_DEBUG("pos_in_line(\"%s\", %d) = %d\n", msg, pos, ret); |
222 |
return ret; |
223 |
} |
224 |
|
225 |
int |
226 |
line_beginning (char* msg, int pos) |
227 |
{ |
228 |
int ret=0; |
229 |
int i=pos-1; |
230 |
if(i) { |
231 |
for(; i>=0; --i) { |
232 |
/* PRINT_DEBUG("pos = %d, i = %d, msg[i] = '%c'\n", pos, i, msg[i]); */ |
233 |
if (msg[i]=='\n') { |
234 |
ret=i+1; |
235 |
break; |
236 |
} |
237 |
} |
238 |
} |
239 |
PRINT_DEBUG("line_beginning(\"%s\", %d) = %d\n", msg, pos, ret); |
240 |
return ret; |
241 |
|
242 |
} |
243 |
|
244 |
void |
245 |
marked_wrapped_message (char *msg, int mark_start, int mark_end) |
246 |
{ |
247 |
XGCValues lgv; |
248 |
GC lgc; |
249 |
unsigned long mask; |
250 |
screen_info *s = current_screen (); |
251 |
int i=0; |
252 |
int j=0; |
253 |
int num_lines; |
254 |
int line_no=0; |
255 |
char tmp_buf[100]; |
256 |
|
257 |
|
258 |
|
259 |
int width = defaults.bar_x_padding * 2 + max_line_length(msg); |
260 |
/* XTextWidth (defaults.font, msg, strlen (msg)); */ |
261 |
int line_height = (FONT_HEIGHT (defaults.font) + defaults.bar_y_padding * 2); |
262 |
int height; |
263 |
|
264 |
PRINT_DEBUG ("msg = %s\n", msg); |
265 |
PRINT_DEBUG ("mark_start = %d, mark_end = %d\n", mark_start, mark_end); |
266 |
|
267 |
|
268 |
num_lines = count_lines(msg, strlen(msg)); |
269 |
height = line_height * num_lines; |
270 |
|
271 |
/* Map the bar if needed */ |
272 |
if (!s->bar_is_raised) |
273 |
{ |
274 |
s->bar_is_raised = BAR_IS_MESSAGE; |
275 |
XMapRaised (dpy, s->bar_window); |
276 |
} |
277 |
|
278 |
/* Reset the alarm to auto-hide the bar in BAR_TIMEOUT seconds. */ |
279 |
alarm (defaults.bar_timeout); |
280 |
alarm_signalled = 0; |
281 |
|
282 |
XMoveResizeWindow (dpy, s->bar_window, |
283 |
bar_x (s, width), bar_y (s, height), |
284 |
width, |
285 |
height); |
286 |
|
287 |
XRaiseWindow (dpy, s->bar_window); |
288 |
XClearWindow (dpy, s->bar_window); |
289 |
XSync (dpy, False); |
290 |
|
291 |
/* if(!defaults.wrap_window_list){ |
292 |
XDrawString (dpy, s->bar_window, s->normal_gc, |
293 |
defaults.bar_x_padding, |
294 |
defaults.bar_y_padding + defaults.font->max_bounds.ascent, |
295 |
msg, strlen (msg)); |
296 |
} else { */ |
297 |
for(i=0; i<=strlen(msg); ++i) { |
298 |
if (msg[i]!='\0' && msg[i]!='\n') { |
299 |
tmp_buf[j]=msg[i]; |
300 |
j++; |
301 |
} |
302 |
else { |
303 |
tmp_buf[j]='\0'; |
304 |
XDrawString (dpy, s->bar_window, s->normal_gc, |
305 |
defaults.bar_x_padding, |
306 |
defaults.bar_y_padding + defaults.font->max_bounds.ascent |
307 |
+ line_no * line_height, |
308 |
tmp_buf, strlen(tmp_buf)); |
309 |
j=0; |
310 |
line_no++; |
311 |
} |
312 |
} |
313 |
|
314 |
|
315 |
|
316 |
XSync (dpy, False); |
317 |
|
318 |
/* Crop to boundary conditions. */ |
319 |
if (mark_start < 0) |
320 |
mark_start = 0; |
321 |
|
322 |
if (mark_end < 0) |
323 |
mark_end = 0; |
324 |
|
325 |
if (mark_start > strlen (msg)) |
326 |
mark_start = strlen (msg); |
327 |
|
328 |
if (mark_end > strlen (msg)) |
329 |
mark_end = strlen (msg); |
330 |
|
331 |
if (mark_start > mark_end+mark_start) |
332 |
{ |
333 |
int tmp; |
334 |
tmp = mark_start; |
335 |
mark_start = mark_end; |
336 |
mark_end = tmp; |
337 |
} |
338 |
|
339 |
/* xor the string representing the current window */ |
340 |
if (mark_end) |
341 |
{ |
342 |
int start; |
343 |
int end; |
344 |
/* int width; */ |
345 |
int start_line, end_line; |
346 |
int start_pos_in_line, end_pos_in_line; |
347 |
int start_line_beginning, end_line_beginning; |
348 |
|
349 |
start_line=count_lines(msg, mark_start); |
350 |
end_line=count_lines(msg, mark_end+mark_start-1); |
351 |
|
352 |
start_pos_in_line = pos_in_line(msg, mark_start); |
353 |
end_pos_in_line = pos_in_line(msg, mark_end+mark_start-1); |
354 |
|
355 |
start_line_beginning = line_beginning(msg, mark_start); |
356 |
end_line_beginning = line_beginning(msg, mark_end+mark_start-1); |
357 |
|
358 |
PRINT_DEBUG ("start_line = %d, end_line = %d\n", start_line, end_line); |
359 |
|
360 |
if (mark_start == 0 || start_pos_in_line == 0) |
361 |
start = 0; |
362 |
else |
363 |
start = XTextWidth (defaults.font, |
364 |
&msg[start_line_beginning], |
365 |
start_pos_in_line) + defaults.bar_x_padding; |
366 |
|
367 |
|
368 |
end = XTextWidth (defaults.font, &msg[end_line_beginning], |
369 |
end_pos_in_line + (msg[end_line_beginning+end_pos_in_line+1] == '\0'?1:0) ) |
370 |
+ defaults.bar_x_padding * 2; |
371 |
|
372 |
if (mark_end != strlen (msg)) end -= defaults.bar_x_padding; |
373 |
|
374 |
/* width = end - start; */ |
375 |
|
376 |
PRINT_DEBUG ("start = %d, end = %d, width = %d\n", start, end, width); |
377 |
|
378 |
lgv.foreground = current_screen()->fg_color; |
379 |
lgv.function = GXxor; |
380 |
mask = GCForeground | GCFunction; |
381 |
lgc = XCreateGC(dpy, s->root, mask, &lgv); |
382 |
|
383 |
XFillRectangle (dpy, s->bar_window, lgc, start, (start_line-1)*line_height, width, (end_line-start_line+1)*line_height); |
384 |
|
385 |
lgv.foreground = s->bg_color; |
386 |
lgc = XCreateGC(dpy, s->root, mask, &lgv); |
387 |
|
388 |
XFillRectangle (dpy, s->bar_window, lgc, start, (start_line-1)*line_height, width, (end_line-start_line+1)*line_height); |
389 |
} |
390 |
|
391 |
/* Keep a record of the message. */ |
392 |
if (last_msg) |
393 |
free (last_msg); |
394 |
last_msg = xstrdup (msg); |
395 |
last_mark_start = mark_start; |
396 |
last_mark_end = mark_end; |
397 |
} |
398 |
|
170 |
void |
399 |
void |
171 |
marked_message (char *msg, int mark_start, int mark_end) |
400 |
marked_message (char *msg, int mark_start, int mark_end) |
172 |
{ |
401 |
{ |
Lines 192-198
Link Here
|
192 |
alarm_signalled = 0; |
421 |
alarm_signalled = 0; |
193 |
|
422 |
|
194 |
XMoveResizeWindow (dpy, s->bar_window, |
423 |
XMoveResizeWindow (dpy, s->bar_window, |
195 |
bar_x (s, width), bar_y (s), |
424 |
bar_x (s, width), bar_y (s, height), |
196 |
width, |
425 |
width, |
197 |
height); |
426 |
height); |
198 |
|
427 |
|
Lines 267-272
Link Here
|
267 |
last_mark_start = mark_start; |
496 |
last_mark_start = mark_start; |
268 |
last_mark_end = mark_end; |
497 |
last_mark_end = mark_end; |
269 |
} |
498 |
} |
|
|
499 |
|
270 |
|
500 |
|
271 |
void |
501 |
void |
272 |
show_last_message () |
502 |
show_last_message () |