Files
mcde/programs/dtbar/about.c
T
lotherkandClaude Sonnet 5.5 d53ea094e7 licence: CNCL for what Makronix wrote itself
LICENSE at the root; the 103 files new in ext/src/mcde (none was in the CDE
import) carry the CNCL line instead of the LGPL notice.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-14 11:48:02 +00:00

233 lines
6.9 KiB
C

/*
* about.c -- dtbar: About This Computer
*
* License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
*
* One small window: the logo, the system and its version, a button for the
* software update, then the computer in three lines -- processor, memory,
* startup disk -- and "More Info..." for the rest (machine, kernel, host
* name, space on the disk, the desktop's version). What the computer is
* comes from McdeSys (mcde_sys_info), never from a look of our own at the
* system.
*
* C99, POSIX, Xt and Motif only (ext/src/mcde/AGENTS.md).
*/
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <string.h>
#include <X11/Intrinsic.h>
#include <X11/Shell.h>
#include <Xm/Xm.h>
#include <Xm/Form.h>
#include <Xm/Label.h>
#include <Xm/MwmUtil.h>
#include <Xm/Protocols.h>
#include <Xm/PushB.h>
#include <Xm/RowColumn.h>
#include <Xm/Separator.h>
#include <Dt/Dt.h>
#include <Mcde/McdeSys.h>
#include "dtbar.h"
static Widget aboutShell, moreBox, moreButton;
static XmRenderTable
AboutFont(Widget w, int size, Boolean bold)
{
XmRendition r;
XmRenderTable rt;
Arg a[4];
int n = 0;
XtSetArg(a[n], XmNfontType, XmFONT_IS_XFT); n++;
XtSetArg(a[n], XmNfontName, "Hack"); n++;
XtSetArg(a[n], XmNfontSize, size); n++;
if (bold) {
XtSetArg(a[n], XmNfontStyle, "Bold"); n++;
}
r = XmRenditionCreate(w, XmFONTLIST_DEFAULT_TAG, a, n);
rt = XmRenderTableAddRenditions(NULL, &r, 1, XmMERGE_REPLACE);
XmRenditionFree(r);
return rt;
}
static Widget
Text(Widget parent, const char *name, const char *text, XmRenderTable font,
unsigned char align)
{
XmString s = XmStringCreateLocalized((char *) text);
Arg a[4];
int n = 0;
Widget w;
XtSetArg(a[n], XmNlabelString, s); n++;
XtSetArg(a[n], XmNalignment, align); n++;
if (font != NULL) {
XtSetArg(a[n], XmNrenderTable, font); n++;
}
w = XtCreateManagedWidget(name, xmLabelWidgetClass, parent, a, n);
XmStringFree(s);
return w;
}
/* "31 GB", "512 MB" */
static void
Size(unsigned long long bytes, char *buf, size_t len)
{
if (bytes >= (1ULL << 30))
snprintf(buf, len, "%llu GB", (bytes + (1ULL << 29)) >> 30);
else
snprintf(buf, len, "%llu MB", (bytes + (1ULL << 19)) >> 20);
}
/* a box of KEY VALUE lines; the keys right, the values left */
static Widget
Table(Widget parent, const char *name, const char *const *rows, int n)
{
Widget rc = XtVaCreateManagedWidget(name, xmRowColumnWidgetClass, parent,
XmNorientation, XmVERTICAL, XmNpacking, XmPACK_COLUMN,
XmNnumColumns, 2, XmNisAligned, False, XmNspacing, 2, NULL);
int i;
XmRenderTable bold = AboutFont(parent, 10, True);
for (i = 0; i < n; i++)
Text(rc, "key", rows[2 * i], bold, XmALIGNMENT_END);
for (i = 0; i < n; i++)
Text(rc, "value", rows[2 * i + 1], NULL, XmALIGNMENT_BEGINNING);
return rc;
}
/* a button of its own width-ish in the middle of the window, not across it */
static Widget
Button(Widget parent, const char *label)
{
Widget row = XtVaCreateManagedWidget("row", xmFormWidgetClass, parent,
XmNfractionBase, 10, XmNshadowThickness, 0, NULL);
XmString s = XmStringCreateLocalized((char *) label);
Widget b = XtVaCreateManagedWidget("button", xmPushButtonWidgetClass, row,
XmNlabelString, s, XmNleftAttachment, XmATTACH_POSITION,
XmNleftPosition, 3, XmNrightAttachment, XmATTACH_POSITION,
XmNrightPosition, 7, XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM, NULL);
XmStringFree(s);
return b;
}
static void
More(Widget w, XtPointer data, XtPointer call)
{
XmString s;
(void) w;
(void) data;
(void) call;
if (XtIsManaged(moreBox)) {
XtUnmanageChild(moreBox);
s = XmStringCreateLocalized("More Info...");
} else {
XtManageChild(moreBox);
s = XmStringCreateLocalized("Less Info");
}
XtVaSetValues(moreButton, XmNlabelString, s, NULL);
XmStringFree(s);
}
static void
Closed(Widget w, XtPointer data, XtPointer call)
{
(void) w;
(void) data;
(void) call;
XtDestroyWidget(aboutShell);
aboutShell = NULL;
}
void
ShowAbout(void)
{
McdeSysInfo i;
Widget box, logo, b;
Pixel fg, bg;
Pixmap pm;
char version[128], cpu[200], mem[32], free_[32], size[32], disk[200];
const char *rows[6], *more[10];
Atom del;
if (aboutShell != NULL) {
XtPopup(aboutShell, XtGrabNone);
XRaiseWindow(XtDisplay(aboutShell), XtWindow(aboutShell));
return;
}
(void) mcde_sys_info(&i);
aboutShell = XtVaCreatePopupShell("about", topLevelShellWidgetClass,
barShell, XmNtitle, "About This Computer", XmNallowShellResize, True,
XmNmwmFunctions, MWM_FUNC_MOVE | MWM_FUNC_CLOSE | MWM_FUNC_MINIMIZE,
XmNmwmDecorations, MWM_DECOR_BORDER | MWM_DECOR_TITLE |
MWM_DECOR_MENU | MWM_DECOR_MINIMIZE, XmNdeleteResponse, XmDO_NOTHING,
NULL);
del = XInternAtom(XtDisplay(aboutShell), "WM_DELETE_WINDOW", False);
XmAddWMProtocolCallback(aboutShell, del, Closed, NULL);
box = XtVaCreateManagedWidget("box", xmRowColumnWidgetClass, aboutShell,
XmNorientation, XmVERTICAL, XmNentryAlignment, XmALIGNMENT_CENTER,
XmNmarginWidth, 28, XmNmarginHeight, 20, XmNspacing, 6,
XmNisAligned, True, NULL);
/* the logo, the system and its version */
XtVaGetValues(box, XmNforeground, &fg, XmNbackground, &bg, NULL);
pm = XmGetPixmap(XtScreen(box),
CDE_INSTALLATION_TOP "/appconfig/icons/C/MakronixDtlogo.pm", fg, bg);
if (pm != XmUNSPECIFIED_PIXMAP) {
logo = XtVaCreateManagedWidget("logo", xmLabelWidgetClass, box,
XmNlabelType, XmPIXMAP, XmNlabelPixmap, pm, NULL);
(void) logo;
}
Text(box, "system", i.system, AboutFont(box, 22, True), XmALIGNMENT_CENTER);
snprintf(version, sizeof version, "Version %s", i.version);
Text(box, "version", version, NULL, XmALIGNMENT_CENTER);
b = Button(box, "Software Update...");
XtSetSensitive(b, False); /* the update comes with sysupgrade */
XtVaCreateManagedWidget("sep", xmSeparatorWidgetClass, box, NULL);
/* the computer in three lines */
if (i.cpus > 1)
snprintf(cpu, sizeof cpu, "%s, %d processors",
i.cpu[0] != '\0' ? i.cpu : "unknown", i.cpus);
else
snprintf(cpu, sizeof cpu, "%s", i.cpu[0] != '\0' ? i.cpu :
"unknown");
Size(i.memory, mem, sizeof mem);
snprintf(disk, sizeof disk, "%s", i.disk[0] != '\0' ? i.disk : "unknown");
rows[0] = "Processor"; rows[1] = cpu;
rows[2] = "Memory"; rows[3] = mem;
rows[4] = "Startup Disk"; rows[5] = disk;
Table(box, "facts", rows, 3);
/* and the rest, on request */
Size(i.diskFree, free_, sizeof free_);
Size(i.diskSize, size, sizeof size);
snprintf(version, sizeof version, "%s free of %s", free_, size);
more[0] = "Computer"; more[1] = i.model;
more[2] = "Kernel"; more[3] = i.kernel;
more[4] = "Host Name"; more[5] = i.hostname;
more[6] = "Disk Space"; more[7] = version;
more[8] = "Desktop"; more[9] = DtVERSION_STRING;
moreBox = Table(box, "more", more, 5);
XtUnmanageChild(moreBox);
moreButton = Button(box, "More Info...");
XtAddCallback(moreButton, XmNactivateCallback, More, NULL);
Text(box, "copyright", "\302\251 2026 The Makronix project",
AboutFont(box, 8, False), XmALIGNMENT_CENTER);
XtPopup(aboutShell, XtGrabNone);
}