diff --git a/include/winX.h b/include/winX.h index fc26f48e0..2a62f892e 100644 --- a/include/winX.h +++ b/include/winX.h @@ -331,6 +331,9 @@ extern void (*input_func)(Widget, XEvent *, String *, Cardinal *); extern struct window_procs X11_procs; +/* Flag maintained by the blink callback */ +extern boolean X11_blink; + /* Check for an invalid window id. */ #define check_winid(window) \ do { \ @@ -424,6 +427,9 @@ extern void destroy_status_window(struct xwindow *); extern void adjust_status(struct xwindow *, const char *); extern void null_out_status(void); extern void check_turn_events(void); +#ifdef STATUS_HILITES +extern void X11_tty_status_blink(void); +#endif /* ### wintext.c ### */ extern void delete_text(Widget, XEvent *, String *, Cardinal *); @@ -519,11 +525,13 @@ extern XFontStruct *X11_italic_font(Display *, XFontStruct *); extern XFontStruct *X11_unicode_font(Display *, XFontStruct *); #endif +/* ### winlabel.c ### */ /* Functions for management of enhanced labels */ extern void X11_wrap_widget(Widget); extern void X11_update_label(Widget); extern void X11_set_attrs(Widget, unsigned); extern void X11_set_highlight(Widget, boolean); extern void X11_set_percent(Widget, unsigned, Pixel); +extern void X11_blink_labels(void); #endif /* WINX_H */ diff --git a/win/X11/winX.c b/win/X11/winX.c index bf030ab37..77b84ae78 100644 --- a/win/X11/winX.c +++ b/win/X11/winX.c @@ -112,6 +112,9 @@ static void X11_error_handler(String) __attribute__((noreturn)); ATTRNORETURN static XtErrorHandler X11_error_handler(String); #endif +boolean X11_blink; +static unsigned blink_interval = 500; /* milliseconds */ + static int X11_io_error_handler(Display *); static int (*old_error_handler)(Display *, XErrorEvent *); @@ -200,6 +203,7 @@ static void release_yn_widgets(void); static int input_event(int); static void win_visible(Widget, XtPointer, XEvent *, Boolean *); static void init_standard_windows(void); +static void blink_callback(XtPointer client_data, XtIntervalId *timer); /* * Local variables. @@ -1611,6 +1615,7 @@ X11_init_nhwindows(int *argcp, char **argv) (ArgList) args, num_args); XtOverrideTranslations(toplevel, XtParseTranslationTable("WM_PROTOCOLS: X11_hangup()")); + XtAppAddTimeOut(app_context, blink_interval, blink_callback, NULL); /* We don't need to realize the top level widget. */ @@ -1667,6 +1672,20 @@ X11_init_nhwindows(int *argcp, char **argv) X11_putstr(WIN_MESSAGE, 0, copyright_banner_line(i)); } +static void +blink_callback(XtPointer client_data, XtIntervalId *timer) +{ + nhUse(timer); +#ifdef STATUS_HILITES + X11_tty_status_blink(); +#endif + X11_blink_labels(); + + X11_blink = !X11_blink; + /* Do it again */ + XtAppAddTimeOut(app_context, blink_interval, blink_callback, client_data); +} + /* * All done. */ diff --git a/win/X11/winlabel.c b/win/X11/winlabel.c index e94bb7cc8..76fa007e7 100644 --- a/win/X11/winlabel.c +++ b/win/X11/winlabel.c @@ -282,6 +282,9 @@ update_label(Widget w, WidgetData *data) values.foreground = (values.foreground & 0xFEFEFE) >> 1; values.background = (values.background & 0xFEFEFE) >> 1; } + if ((attrs & HL_BLINK) && X11_blink) { + values.foreground = values.background; + } values.font = font->fid; values.function = GXcopy; GC ggc = XtGetGC(w, @@ -505,3 +508,17 @@ delete_widget(Widget w) } --num_widgets; } + +////////////////////////////////////////////////////////////////////////////// + +/* Call every time the blink flag changes */ +void +X11_blink_labels(void) +{ + for (unsigned i = 0; i < num_widgets; ++i) { + WidgetBucket *bucket = &widget_table[i]; + if (bucket->data->attrs & HL_BLINK) { + update_label(bucket->w, bucket->data); + } + } +} diff --git a/win/X11/winstat.c b/win/X11/winstat.c index e08e968f5..5e5d34cc5 100644 --- a/win/X11/winstat.c +++ b/win/X11/winstat.c @@ -112,9 +112,6 @@ static void adjust_status_fancy(struct xwindow *, const char *); static void adjust_status_tty(struct xwindow *, const char *); static void set_percent(int, int, int); static void tty_status_exposed(Widget, XtPointer, XtPointer); -#ifdef STATUS_HILITES -static void tty_status_blink(XtPointer client_data, XtIntervalId *timer); -#endif static void tty_status_redraw(Widget); static int tty_render_field(Widget, int, int, enum statusfields); static void tty_status_colors(Widget, int, int, Pixel *, Pixel *); @@ -207,10 +204,6 @@ struct tty_cond_field { static Widget X11_status_widget; static struct tty_status_field X11_status_labels[MAXBLSTATS]; static struct tty_cond_field X11_cond_labels[32]; /* Ugh */ -#ifdef STATUS_HILITES -static boolean blink; -static const unsigned long blink_interval = 500; /* milliseconds */ -#endif static struct xwindow *xw_status_win; @@ -361,7 +354,7 @@ X11_status_update_tty( for (unsigned j = 0; j < SIZE(tt_condorder); ++j) { if ((mask & tt_condorder[j].mask) != 0) { struct tty_cond_field *fldp = &X11_cond_labels[j]; - fldp->attrs |= 0x1 << (i - CLR_MAX); + fldp->attrs |= 0x1 << (i - HL_ATTCLR_NONE); } } } @@ -542,10 +535,6 @@ create_tty_status(Widget parent, Widget top) XtAddCallback(X11_status_widget, XtNexposeCallback, tty_status_exposed, (XtPointer) 0); -#ifdef STATUS_HILITES - XtAppAddTimeOut(app_context, blink_interval, tty_status_blink, - (XtPointer) X11_status_widget); -#endif return X11_status_widget; } @@ -564,12 +553,9 @@ tty_status_exposed(Widget w, XtPointer client_data, /* unused */ } #ifdef STATUS_HILITES -static void -tty_status_blink(XtPointer client_data, XtIntervalId *timer) +void +X11_tty_status_blink(void) { - Widget w = (Widget) client_data; - nhUse(timer); - /* Do we have any active blink attributes? */ boolean have_blink = FALSE; for (unsigned i = 0; i < SIZE(X11_status_labels) && !have_blink; ++i) { @@ -580,12 +566,8 @@ tty_status_blink(XtPointer client_data, XtIntervalId *timer) } if (have_blink) { - tty_status_redraw(w); - blink = !blink; + tty_status_redraw(X11_status_widget); } - - /* Do it again */ - XtAppAddTimeOut(app_context, blink_interval, tty_status_blink, client_data); } #endif /* STATUS_HILITES */ @@ -933,7 +915,7 @@ tty_status_colors(Widget w, int color, int attr, Pixel *fgpixel, Pixel *bgpixel) } /* Implement blink */ - if ((attr & HL_BLINK) && blink) { + if ((attr & HL_BLINK) && X11_blink) { *fgpixel = *bgpixel; }