MCPcopy Create free account
hub / github.com/NetHack/NetHack / tt_status_fixup

Function tt_status_fixup

win/X11/winstat.c:544–652  ·  view source on GitHub ↗

make sure foreground, background, and font have reasonable values, then explicitly set them for all the status widgets; also cache some geometry settings in (*xw_status_win).Status_info */

Source from the content-addressed store, hash-verified

542 then explicitly set them for all the status widgets;
543 also cache some geometry settings in (*xw_status_win).Status_info */
544static void
545tt_status_fixup(void)
546{
547 Arg args[6];
548 Cardinal num_args;
549 Widget w;
550 Position lbl_y;
551 int x, y, ci, fld;
552 XFontStruct *font = 0;
553 Pixel fg = 0, bg = 0;
554 struct status_info_t *si = xw_status_win->Win_info.Status_info;
555
556 (void) memset((genericptr_t) args, 0, sizeof args);
557 num_args = 0;
558 XtSetArg(args[num_args], nhStr(XtNfont), &font); num_args++;
559 XtSetArg(args[num_args], nhStr(XtNforeground), &fg); num_args++;
560 XtSetArg(args[num_args], nhStr(XtNbackground), &bg); num_args++;
561 XtGetValues(X11_status_widget, args, num_args);
562 if (fg == bg) {
563 XColor black = get_nhcolor(xw_status_win, CLR_BLACK),
564 white = get_nhcolor(xw_status_win, CLR_WHITE);
565
566 fg = (bg == white.pixel) ? black.pixel : white.pixel;
567 }
568 X11_status_fg = si->fg = fg, X11_status_bg = si->bg = bg;
569
570 if (!font) {
571 w = X11_status_widget;
572 XtSetArg(args[0], nhStr(XtNfont), &font);
573 do {
574 XtGetValues(w, args, ONE);
575 } while (!font && (w = XtParent(w)) != 0);
576
577 if (!font) {
578 /* trial and error time -- this is where we've actually
579 been obtaining the font even though we aren't setting
580 it for any of the field widgets (until for(y,x) below) */
581 XtGetValues(X11_status_labels[0], args, ONE);
582
583 if (!font) { /* this bit is untested... */
584 /* write some text and hope Xaw sets up font for us */
585 XtSetArg(args[0], nhStr(XtNlabel), "NetHack");
586 XtSetValues(X11_status_labels[0], args, ONE);
587 (void) XFlush(XtDisplay(X11_status_labels[0]));
588
589 XtSetArg(args[0], nhStr(XtNfont), &font);
590 XtGetValues(X11_status_labels[0], args, ONE);
591
592 /* if still Null, XTextWidth() would crash so bail out */
593 if (!font)
594 panic("X11 status can't determine font.");
595 }
596 }
597 }
598 X11_status_font = si->fs = font;
599
600 /* amount of space to advance a widget's location by one space;
601 increase width a tiny bit beyond the actual space */

Callers 1

X11_status_update_ttyFunction · 0.85

Calls 2

get_nhcolorFunction · 0.85
panicFunction · 0.50

Tested by

no test coverage detected