X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=spectrwm.c;h=648387cb899ce2caaa963ceb6af808802b861e08;hb=db15c5644f1c18c24a380d6eb4394e26fd24ec01;hp=b0835a7c765180f710c8025f705e46411b2b39fe;hpb=b6d8befdac6e36080add4a17693fa3b4bf81ac66;p=spectrwm.git diff --git a/spectrwm.c b/spectrwm.c index b0835a7..648387c 100644 --- a/spectrwm.c +++ b/spectrwm.c @@ -820,13 +820,14 @@ void adjust_font(struct ws_win *); void bar_class_name(char *, size_t, struct swm_region *); void bar_class_title_name(char *, size_t, struct swm_region *); void bar_cleanup(struct swm_region *); +void bar_extra_setup(void); void bar_extra_stop(void); +void bar_extra_update(void); void bar_fmt(const char *, char *, struct swm_region *, size_t); void bar_fmt_expand(char *, size_t); -void bar_fmt_print(void); +void bar_draw(void); void bar_print(struct swm_region *, const char *); void bar_print_legacy(struct swm_region *, const char *); -void bar_refresh(void); void bar_replace(char *, char *, struct swm_region *, size_t); void bar_replace_pad(char *, int *, size_t); char * bar_replace_seq(char *, char *, struct swm_region *, size_t *, @@ -834,7 +835,6 @@ char * bar_replace_seq(char *, char *, struct swm_region *, size_t *, void bar_setup(struct swm_region *); void bar_title_name(char *, size_t, struct swm_region *); void bar_toggle(struct swm_region *, union arg *); -void bar_update(void); void bar_urgent(char *, size_t); void bar_window_float(char *, size_t, struct swm_region *); void bar_window_name(char *, size_t, struct swm_region *); @@ -2160,8 +2160,9 @@ bar_fmt_expand(char *fmtexp, size_t sz) #endif } +/* Redraws the bar; need to follow with xcb_flush() or focus_flush(). */ void -bar_fmt_print(void) +bar_draw(void) { char fmtexp[SWM_BAR_MAX], fmtnew[SWM_BAR_MAX]; char fmtrep[SWM_BAR_MAX]; @@ -2194,11 +2195,13 @@ bar_fmt_print(void) } } +/* Reads external script output; call when stdin is readable. */ void -bar_update(void) +bar_extra_update(void) { size_t len; char b[SWM_BAR_MAX]; + int redraw = 0; if (bar_enabled && bar_extra && bar_extra_running) { while (fgets(b, sizeof(b), stdin) != NULL) { @@ -2216,6 +2219,8 @@ bar_update(void) /* Append new output to bar. */ strlcat(bar_ext, b, sizeof(bar_ext)); + + redraw = 1; } else { /* Buffer output. */ strlcat(bar_ext_buf, b, sizeof(bar_ext_buf)); @@ -2223,7 +2228,7 @@ bar_update(void) } if (errno != EAGAIN) { - warn("bar_update: bar_extra failed"); + warn("bar_action failed"); bar_extra_stop(); } } else { @@ -2231,15 +2236,22 @@ bar_update(void) * Attempt to drain stdin, so it doesn't cause the main loop to * call us as fast as it can. */ - fgets(b, sizeof(b), stdin); + while (fgets(b, sizeof(b), stdin) != NULL); if (!bar_enabled) return; - bar_ext[0] = '\0'; + /* Clear bar script output if bar script is not running. */ + if (bar_ext[0] != '\0') { + bar_ext[0] = '\0'; + redraw = 1; + } } - bar_fmt_print(); + if (redraw) { + bar_draw(); + xcb_flush(conn); + } } void @@ -2281,13 +2293,13 @@ bar_toggle(struct swm_region *r, union arg *args) stack(); /* must be after stack */ - bar_update(); + bar_draw(); focus_flush(); } void -bar_refresh(void) +bar_extra_setup(void) { struct swm_region *r; uint32_t wa[2]; @@ -2338,7 +2350,7 @@ bar_refresh(void) XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL, wa); } - bar_update(); + bar_draw(); xcb_flush(conn); } @@ -2505,7 +2517,7 @@ bar_setup(struct swm_region *r) "%d x %d\n", WINID(r->bar), X(r->bar), Y(r->bar), WIDTH(r->bar), HEIGHT(r->bar)); - bar_refresh(); + bar_extra_setup(); } void @@ -2568,8 +2580,8 @@ version(struct swm_region *r, union arg *args) "Version: %s Build: %s", SPECTRWM_VERSION, buildstr); else strlcpy(bar_vertext, "", sizeof bar_vertext); - bar_update(); + bar_draw(); xcb_flush(conn); } @@ -3139,6 +3151,9 @@ focus_win(struct ws_win *win) if (win->ws == NULL) goto out; + if (!win->mapped) + goto out; + ws = win->ws; if (validate_ws(ws)) @@ -3224,7 +3239,7 @@ focus_win(struct ws_win *win) } out: - bar_update(); + bar_draw(); DNPRINTF(SWM_D_FOCUS, "focus_win: done.\n"); } @@ -3346,7 +3361,7 @@ switchws(struct swm_region *r, union arg *args) /* Clear bar if new ws is empty. */ if (new_ws->focus_pending == NULL) - bar_update(); + bar_draw(); focus_flush(); @@ -3455,7 +3470,7 @@ cyclescr(struct swm_region *r, union arg *args) rr->s[i].root, XCB_CURRENT_TIME); /* Clear bar since empty. */ - bar_update(); + bar_draw(); } focus_flush(); @@ -3768,7 +3783,7 @@ cycle_layout(struct swm_region *r, union arg *args) ws->cur_layout = &layouts[0]; stack(); - bar_update(); + bar_draw(); focus_win(get_region_focus(r)); @@ -3788,7 +3803,7 @@ stack_config(struct swm_region *r, union arg *args) if (args->id != SWM_ARG_ID_STACKINIT) stack(); - bar_update(); + bar_draw(); focus_flush(); } @@ -4340,8 +4355,8 @@ max_stack(struct workspace *ws, struct swm_geometry *g) } /* Unmap unwanted windows if not multi-screen. */ - if (!(num_screens > 1 || outputs > 1) && (w != win || - w != parent || w->transient != win->id)) + if (num_screens <= 1 && outputs <= 1 && w != win && + w != parent && w->transient != win->id) unmap_window(w); } @@ -6886,51 +6901,51 @@ struct config_option { int funcflags; }; struct config_option configopt[] = { - { "bar_enabled", setconfvalue, SWM_S_BAR_ENABLED }, - { "bar_enabled_ws", setconfvalue, SWM_S_BAR_ENABLED_WS }, + { "autorun", setautorun, 0 }, + { "bar_action", setconfvalue, SWM_S_BAR_ACTION }, { "bar_at_bottom", setconfvalue, SWM_S_BAR_AT_BOTTOM }, { "bar_border", setconfcolor, SWM_S_COLOR_BAR_BORDER }, { "bar_border_width", setconfvalue, SWM_S_BAR_BORDER_WIDTH }, { "bar_color", setconfcolor, SWM_S_COLOR_BAR }, - { "bar_font_color", setconfcolor, SWM_S_COLOR_BAR_FONT }, - { "bar_font", setconfvalue, SWM_S_BAR_FONT }, - { "bar_action", setconfvalue, SWM_S_BAR_ACTION }, { "bar_delay", setconfvalue, SWM_S_BAR_DELAY }, - { "bar_justify", setconfvalue, SWM_S_BAR_JUSTIFY }, + { "bar_enabled", setconfvalue, SWM_S_BAR_ENABLED }, + { "bar_enabled_ws", setconfvalue, SWM_S_BAR_ENABLED_WS }, + { "bar_font", setconfvalue, SWM_S_BAR_FONT }, + { "bar_font_color", setconfcolor, SWM_S_COLOR_BAR_FONT }, { "bar_format", setconfvalue, SWM_S_BAR_FORMAT }, - { "keyboard_mapping", setkeymapping, 0 }, + { "bar_justify", setconfvalue, SWM_S_BAR_JUSTIFY }, { "bind", setconfbinding, 0 }, - { "stack_enabled", setconfvalue, SWM_S_STACK_ENABLED }, + { "border_width", setconfvalue, SWM_S_BORDER_WIDTH }, { "clock_enabled", setconfvalue, SWM_S_CLOCK_ENABLED }, { "clock_format", setconfvalue, SWM_S_CLOCK_FORMAT }, { "color_focus", setconfcolor, SWM_S_COLOR_FOCUS }, { "color_unfocus", setconfcolor, SWM_S_COLOR_UNFOCUS }, { "cycle_empty", setconfvalue, SWM_S_CYCLE_EMPTY }, { "cycle_visible", setconfvalue, SWM_S_CYCLE_VISIBLE }, - { "workspace_limit", setconfvalue, SWM_S_WORKSPACE_LIMIT }, { "dialog_ratio", setconfvalue, SWM_S_DIALOG_RATIO }, - { "verbose_layout", setconfvalue, SWM_S_VERBOSE_LAYOUT }, + { "disable_border", setconfvalue, SWM_S_DISABLE_BORDER }, + { "focus_close", setconfvalue, SWM_S_FOCUS_CLOSE }, + { "focus_close_wrap", setconfvalue, SWM_S_FOCUS_CLOSE_WRAP }, + { "focus_default", setconfvalue, SWM_S_FOCUS_DEFAULT }, + { "focus_mode", setconfvalue, SWM_S_FOCUS_MODE }, + { "keyboard_mapping", setkeymapping, 0 }, + { "layout", setlayout, 0 }, { "modkey", setconfmodkey, 0 }, { "program", setconfspawn, 0 }, { "quirk", setconfquirk, 0 }, { "region", setconfregion, 0 }, - { "spawn_term", setconfvalue, SWM_S_SPAWN_TERM }, - { "screenshot_enabled", setconfvalue, SWM_S_SS_ENABLED }, { "screenshot_app", setconfvalue, SWM_S_SS_APP }, - { "window_name_enabled", setconfvalue, SWM_S_WINDOW_NAME_ENABLED }, - { "urgent_enabled", setconfvalue, SWM_S_URGENT_ENABLED }, + { "screenshot_enabled", setconfvalue, SWM_S_SS_ENABLED }, + { "spawn_position", setconfvalue, SWM_S_SPAWN_ORDER }, + { "spawn_term", setconfvalue, SWM_S_SPAWN_TERM }, + { "stack_enabled", setconfvalue, SWM_S_STACK_ENABLED }, { "term_width", setconfvalue, SWM_S_TERM_WIDTH }, { "title_class_enabled", setconfvalue, SWM_S_TITLE_CLASS_ENABLED }, { "title_name_enabled", setconfvalue, SWM_S_TITLE_NAME_ENABLED }, - { "focus_mode", setconfvalue, SWM_S_FOCUS_MODE }, - { "focus_close", setconfvalue, SWM_S_FOCUS_CLOSE }, - { "focus_close_wrap", setconfvalue, SWM_S_FOCUS_CLOSE_WRAP }, - { "focus_default", setconfvalue, SWM_S_FOCUS_DEFAULT }, - { "spawn_position", setconfvalue, SWM_S_SPAWN_ORDER }, - { "disable_border", setconfvalue, SWM_S_DISABLE_BORDER }, - { "border_width", setconfvalue, SWM_S_BORDER_WIDTH }, - { "autorun", setautorun, 0 }, - { "layout", setlayout, 0 }, + { "urgent_enabled", setconfvalue, SWM_S_URGENT_ENABLED }, + { "verbose_layout", setconfvalue, SWM_S_VERBOSE_LAYOUT }, + { "window_name_enabled", setconfvalue, SWM_S_WINDOW_NAME_ENABLED }, + { "workspace_limit", setconfvalue, SWM_S_WORKSPACE_LIMIT }, }; int @@ -7443,7 +7458,7 @@ expose(xcb_expose_event_t *e) for (i = 0; i < num_screens; i++) TAILQ_FOREACH(r, &screens[i].rl, entry) if (e->window == WINID(r->bar)) - bar_update(); + bar_draw(); xcb_flush(conn); } @@ -7528,7 +7543,7 @@ buttonpress(xcb_button_press_event_t *e) XCB_INPUT_FOCUS_PARENT, e->root, e->time); /* Clear bar since empty. */ - bar_update(); + bar_draw(); handled = 1; goto out; @@ -7909,7 +7924,7 @@ enternotify(xcb_enter_notify_event_t *e) XCB_INPUT_FOCUS_PARENT, e->root, e->time); /* Clear bar since empty. */ - bar_update(); + bar_draw(); focus_flush(); } @@ -8107,7 +8122,7 @@ propertynotify(xcb_property_notify_event_t *e) } } else if (e->atom == XCB_ATOM_WM_CLASS || e->atom == XCB_ATOM_WM_NAME) { - bar_update(); + bar_draw(); } xcb_flush(conn); @@ -8855,7 +8870,7 @@ main(int argc, char *argv[]) struct timeval tv; fd_set rd; int rd_max; - int do_bar_update = 0; + int stdin_ready = 0; int num_readable; /* suppress unused warning since var is needed */ @@ -9018,10 +9033,11 @@ noconfig: tv.tv_sec = 1; tv.tv_usec = 0; num_readable = select(rd_max + 1, &rd, NULL, NULL, &tv); - if (num_readable == -1 && errno != EINTR) + if (num_readable == -1 && errno != EINTR) { DNPRINTF(SWM_D_MISC, "select failed"); - else if (num_readable > 0 && FD_ISSET(STDIN_FILENO, &rd)) - do_bar_update = 1; + } else if (num_readable > 0 && FD_ISSET(STDIN_FILENO, &rd)) { + stdin_ready = 1; + } if (restart_wm) restart(NULL, NULL); @@ -9032,10 +9048,9 @@ noconfig: if (!running) goto done; - if (do_bar_update) { - do_bar_update = 0; - bar_update(); - xcb_flush(conn); + if (stdin_ready) { + stdin_ready = 0; + bar_extra_update(); } } done: