diff options
Diffstat (limited to 'src/bar.c')
-rw-r--r-- | src/bar.c | 54 |
1 files changed, 47 insertions, 7 deletions
@@ -29,6 +29,11 @@ #include "ratpoison.h" +/* Possible values for bar_is_raised status. */ +#define BAR_IS_WINDOW_LIST 1 +#define BAR_IS_MESSAGE 2 + +/* Hide the bar from sight. */ int hide_bar (screen_info *s) { @@ -42,12 +47,13 @@ hide_bar (screen_info *s) return 0; } +/* Show window listing in bar. */ int show_bar (screen_info *s) { if (!s->bar_is_raised) { - s->bar_is_raised = 1; + s->bar_is_raised = BAR_IS_WINDOW_LIST; XMapWindow (dpy, s->bar_window); update_window_names (s); @@ -56,9 +62,14 @@ show_bar (screen_info *s) return 1; } + /* If the bar is raised we still need to display the window + names. */ + update_window_names (s); return 0; } +/* Calculate the width required for the bar to display the window + list. */ static int calc_bar_width (XFontStruct *font) { @@ -88,7 +99,7 @@ int bar_y (screen_info *s) { if (BAR_LOCATION % 2) return 0; - else return s->root_attr.height - (FONT_HEIGHT (s->font) + BAR_PADDING * 2) - 2; + else return s->root_attr.height - (FONT_HEIGHT (s->font) + BAR_Y_PADDING * 2) - 2; } void @@ -97,14 +108,14 @@ update_window_names (screen_info *s) char str[100]; /* window names are capped at 99 chars */ int width = calc_bar_width (s->font); rp_window *cur; - int cur_x = 5; + int cur_x = BAR_X_PADDING; if (!s->bar_is_raised) return; XMoveResizeWindow (dpy, s->bar_window, bar_x (s, width), bar_y (s), width, - (FONT_HEIGHT (s->font) + BAR_PADDING * 2)); + (FONT_HEIGHT (s->font) + BAR_Y_PADDING * 2)); XClearWindow (dpy, s->bar_window); XRaiseWindow (dpy, s->bar_window); @@ -112,7 +123,7 @@ update_window_names (screen_info *s) /* Draw them in reverse order they were added in, so the oldest windows appear on the left and the newest on the right end of the - program bar. */ + bar. */ for (cur = rp_window_head; cur; cur = cur->next) { if (cur->state == STATE_UNMAPPED) continue; @@ -121,14 +132,43 @@ update_window_names (screen_info *s) if ( rp_current_window == cur) { XDrawString (dpy, s->bar_window, s->bold_gc, cur_x, - BAR_PADDING + s->font->max_bounds.ascent, str, strlen (str)); + BAR_Y_PADDING + s->font->max_bounds.ascent, str, + strlen (str)); } else { XDrawString (dpy, s->bar_window, s->normal_gc, cur_x, - BAR_PADDING + s->font->max_bounds.ascent, str, strlen (str)); + BAR_Y_PADDING + s->font->max_bounds.ascent, str, + strlen (str)); } cur_x += 10 + XTextWidth (s->font, str, strlen (str)); } } + +void +display_msg_in_bar (screen_info *s, char *msg) +{ + int width = BAR_X_PADDING * 2 + XTextWidth (s->font, msg, strlen (msg)); + + /* Map the bar if needed */ + if (!s->bar_is_raised) + { + s->bar_is_raised = BAR_IS_MESSAGE; + XMapWindow (dpy, s->bar_window); + } + + /* Reset the alarm to auto-hide the bar in BAR_TIMEOUT seconds. */ + alarm (BAR_TIMEOUT); + + XMoveResizeWindow (dpy, s->bar_window, + bar_x (s, width), bar_y (s), + width, + (FONT_HEIGHT (s->font) + BAR_Y_PADDING * 2)); + XClearWindow (dpy, s->bar_window); + XRaiseWindow (dpy, s->bar_window); + + XDrawString (dpy, s->bar_window, s->bold_gc, BAR_X_PADDING, + BAR_Y_PADDING + s->font->max_bounds.ascent, msg, + strlen (msg)); +} |