- dtsystemsettings: the shell is 1022x550 and stays so (min/max equal); every pane lives in it instead of growing the window (thirteen per-pane XtVaSetValues(shell, width, height) calls are gone), and a taller pane scrolls (the pages sit in an XmScrolledWindow with XmAUTOMATIC). - panes.c: CDs & DVDs had no icon (Dtmedia.m.pm does not exist) - it shows IrixCD.m.pm; Energy Saver shows SDtpowermgr.m.pm; Accounts had the same icon as Startup (DtStart.pm) and shows McdeUser.t.pm. The "Startup Disk" entry and the disabled "Dock" entry (no icon, PANE_LATER) are removed. - McdePrefs: the tab strip is one of many (XmNradioBehavior, XmNradioAlwaysOne). Without it every visited tab stayed pressed (measured 2026-11-21: Keyboard, Mouse and Shortcuts all down at once). - dttoolbox: the window title is "dttoolchest" (msg 1 of the catalog). - McdeSys: mcde_sys_keyboard_is_mac asks the machine (hw.model "Mac...") before usbdevs. At session start the internal keyboard may not be enumerated yet, so dtkeys took a MacBook for a PC keyboard and exchanged Alt and Command (_MCDE_KEYS said "pc", measured 2026-11-21).
371 lines
9.6 KiB
C
371 lines
9.6 KiB
C
/*
|
|
* McdePrefs.c -- MCDE: the settings window of a program (McdePrefs.h)
|
|
*
|
|
* Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE.
|
|
*
|
|
* A top level shell with a row of icon tabs (the reference's icon toolbar
|
|
* as the page chooser), the tab's form under it, and no OK or Cancel: the
|
|
* program's callbacks do their work when a value changes. A tab's form is
|
|
* built when it is shown the first time (a program with many tabs pays only
|
|
* for the one opened). Escape closes, the window's close box only hides it.
|
|
*/
|
|
|
|
#define _POSIX_C_SOURCE 200809L
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include <X11/Intrinsic.h>
|
|
#include <X11/Shell.h>
|
|
#include <X11/keysym.h>
|
|
#include <Xm/Form.h>
|
|
#include <Xm/Label.h>
|
|
#include <Xm/Protocols.h>
|
|
#include <Xm/RowColumn.h>
|
|
#include <Xm/Separator.h>
|
|
#include <Xm/ToggleB.h>
|
|
#include <Xm/Xm.h>
|
|
|
|
#include <Dt/McdePrefs.h>
|
|
|
|
#define MAX_TABS 8
|
|
|
|
typedef struct {
|
|
char name[64];
|
|
char icon[64];
|
|
Widget toggle;
|
|
Widget page;
|
|
Widget (*build)(Widget form, void *data);
|
|
void *data;
|
|
int built;
|
|
} Tab;
|
|
|
|
typedef struct {
|
|
char prog[64];
|
|
Widget shell, box, tabs, pages;
|
|
Pixel fg, bg;
|
|
Tab tab[MAX_TABS];
|
|
int n, current;
|
|
} Prefs;
|
|
|
|
static Prefs *prefs[8];
|
|
|
|
static Prefs *
|
|
Of(Widget w)
|
|
{
|
|
int i;
|
|
|
|
/* the shell itself, or any widget under it (a tab, a row): up the
|
|
* chain until one of our shells or its userData pointer is found */
|
|
for (; w != NULL; w = XtParent(w)) {
|
|
void *d = NULL;
|
|
|
|
for (i = 0; i < 8; i++)
|
|
if (prefs[i] != NULL && prefs[i]->shell == w)
|
|
return prefs[i];
|
|
XtVaGetValues(w, XmNuserData, &d, NULL);
|
|
for (i = 0; i < 8; i++)
|
|
if (prefs[i] != NULL && (void *) prefs[i] == d)
|
|
return prefs[i];
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
/* the window takes the size the page asks for: the reference's window is as
|
|
* tall as the chosen page (XtQueryGeometry gives the preferred size) */
|
|
static void
|
|
FitShell(Prefs *p)
|
|
{
|
|
Widget *kids = NULL, page;
|
|
Cardinal n = 0, i;
|
|
Dimension th = 0;
|
|
int maxy = 0, maxx = 0;
|
|
|
|
if (p == NULL || p->current < 0 || p->current >= p->n)
|
|
return;
|
|
page = p->tab[p->current].page;
|
|
if (!XtIsManaged(page))
|
|
return;
|
|
if (!XtIsSubclass(page, compositeWidgetClass))
|
|
return;
|
|
XtVaGetValues(page, XmNchildren, &kids, XmNnumChildren, &n, NULL);
|
|
for (i = 0; i < n; i++) {
|
|
Position y = 0, x = 0;
|
|
Dimension h = 0, w = 0;
|
|
|
|
if (!XtIsManaged(kids[i]))
|
|
continue;
|
|
XtVaGetValues(kids[i], XmNy, &y, XmNheight, &h,
|
|
XmNx, &x, XmNwidth, &w, NULL);
|
|
if ((int) y + (int) h > maxy)
|
|
maxy = (int) y + (int) h;
|
|
if ((int) x + (int) w > maxx)
|
|
maxx = (int) x + (int) w;
|
|
}
|
|
XtVaGetValues(p->tabs, XmNheight, &th, NULL);
|
|
if (maxy < 60)
|
|
return; /* not laid out yet: the map callback comes */
|
|
if (maxx < 300)
|
|
maxx = 300;
|
|
XtVaSetValues(p->shell, XmNwidth, maxx + 56,
|
|
XmNheight, maxy + (int) th + 64, NULL);
|
|
}
|
|
|
|
static void
|
|
Mapped(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
(void) w;
|
|
(void) call;
|
|
FitShell((Prefs *) data);
|
|
}
|
|
|
|
static void
|
|
ShowTab(Prefs *p, int i)
|
|
{
|
|
int k;
|
|
|
|
if (p == NULL || i < 0 || i >= p->n)
|
|
return;
|
|
if (!p->tab[i].built) {
|
|
p->tab[i].built = 1;
|
|
if (p->tab[i].build != NULL)
|
|
p->tab[i].build(p->tab[i].page, p->tab[i].data);
|
|
}
|
|
for (k = 0; k < p->n; k++)
|
|
if (k == i) {
|
|
XtManageChild(p->tab[k].page);
|
|
XmToggleButtonSetState(p->tab[k].toggle, True, False);
|
|
} else {
|
|
XtUnmanageChild(p->tab[k].page);
|
|
XmToggleButtonSetState(p->tab[k].toggle, False, False);
|
|
}
|
|
p->current = i;
|
|
XtVaSetValues(p->shell, XmNtitle, p->tab[i].name, NULL);
|
|
XmUpdateDisplay(p->tab[i].page);
|
|
FitShell(p);
|
|
(void)McdePrefsConfSet(p->prog, "lasttab", p->tab[i].name);
|
|
}
|
|
|
|
static void
|
|
TabChosen(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
Prefs *p = Of(XtParent(XtParent(w)));
|
|
int i = (int) (size_t) data;
|
|
|
|
if (call != NULL && !((XmToggleButtonCallbackStruct *) call)->set)
|
|
return;
|
|
ShowTab(p, i);
|
|
}
|
|
|
|
static void
|
|
CloseCB(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
(void) w;
|
|
(void) data;
|
|
(void) call;
|
|
}
|
|
|
|
static void
|
|
KeyHandler(Widget w, XtPointer data, XEvent *ev, Boolean *cont)
|
|
{
|
|
Prefs *p = data;
|
|
|
|
(void) w;
|
|
if (ev->type == KeyPress &&
|
|
XLookupKeysym(&ev->xkey, 0) == XK_Escape) {
|
|
XtPopdown(p->shell);
|
|
*cont = False;
|
|
}
|
|
}
|
|
|
|
/* the icon of a tab: .m.pm, else .pm of appconfig/icons/C */
|
|
static Pixmap
|
|
TabIcon(Prefs *p, const char *icon)
|
|
{
|
|
static const char *const exts[] = { ".m.pm", ".pm", ".l.pm" };
|
|
char path[512];
|
|
Pixmap pm = XmUNSPECIFIED_PIXMAP;
|
|
size_t i;
|
|
|
|
if (icon == NULL || icon[0] == '\0')
|
|
return pm;
|
|
for (i = 0; i < sizeof exts / sizeof exts[0] &&
|
|
pm == XmUNSPECIFIED_PIXMAP; i++) {
|
|
(void)snprintf(path, sizeof path,
|
|
"%s/appconfig/icons/C/%s%s", CDE_INSTALLATION_TOP, icon,
|
|
exts[i]);
|
|
pm = XmGetPixmap(XtScreen(p->shell), path, p->fg, p->bg);
|
|
}
|
|
return pm;
|
|
}
|
|
|
|
Widget
|
|
McdePrefsCreate(Widget parent, const char *prog)
|
|
{
|
|
Prefs *p;
|
|
Widget top;
|
|
int i;
|
|
|
|
p = calloc(1, sizeof *p);
|
|
if (p == NULL)
|
|
return NULL;
|
|
(void)snprintf(p->prog, sizeof p->prog, "%s", prog != NULL ? prog :
|
|
"program");
|
|
for (top = parent; XtParent(top) != NULL; top = XtParent(top))
|
|
;
|
|
XtVaGetValues(parent, XmNforeground, &p->fg, XmNbackground, &p->bg,
|
|
NULL);
|
|
p->shell = XtVaCreatePopupShell("mcdePrefs", topLevelShellWidgetClass,
|
|
top, XmNtitle, "Preferences", XmNallowShellResize, True,
|
|
XmNdeleteResponse, XmUNMAP, NULL);
|
|
p->box = XtVaCreateManagedWidget("prefsBox",
|
|
xmRowColumnWidgetClass, p->shell, XmNorientation, XmVERTICAL,
|
|
XmNspacing, 6, XmNmarginWidth, 8, XmNmarginHeight, 8,
|
|
XmNwidth, 560, NULL);
|
|
/* the tabs are one of many: a toggle stays pressed only when it is the
|
|
* chosen page. Without the radio behaviour every tab that was visited
|
|
* stayed pressed (measured 2026-11-21: Keyboard, Mouse and Shortcuts
|
|
* were all down at once). */
|
|
p->tabs = XtVaCreateManagedWidget("prefsTabs",
|
|
xmRowColumnWidgetClass, p->box, XmNorientation, XmHORIZONTAL,
|
|
XmNradioBehavior, True, XmNradioAlwaysOne, True,
|
|
XmNspacing, 4, XmNmarginWidth, 0, XmNentryAlignment,
|
|
XmALIGNMENT_CENTER, NULL);
|
|
p->pages = XtVaCreateManagedWidget("prefsPages",
|
|
xmRowColumnWidgetClass, p->box, XmNspacing, 4,
|
|
XmNmarginWidth, 0, NULL);
|
|
XtVaSetValues(p->shell, XmNuserData, p, NULL);
|
|
XtAddEventHandler(p->shell, KeyPressMask, False, KeyHandler, p);
|
|
/* the page's rows have their sizes once the shell is mapped */
|
|
XtAddCallback(p->shell, XmNmapCallback, Mapped, p);
|
|
for (i = 0; i < 8; i++)
|
|
if (prefs[i] == NULL) {
|
|
prefs[i] = p;
|
|
break;
|
|
}
|
|
return p->shell;
|
|
}
|
|
|
|
int
|
|
McdePrefsAddTab(Widget w, const char *name, const char *icon,
|
|
Widget (*build)(Widget form, void *data), void *data)
|
|
{
|
|
Prefs *p = Of(w);
|
|
Tab *t;
|
|
XmString s;
|
|
Pixmap pm;
|
|
int i;
|
|
|
|
if (p == NULL || p->n >= MAX_TABS || name == NULL)
|
|
return -1;
|
|
t = &p->tab[p->n];
|
|
(void)snprintf(t->name, sizeof t->name, "%s", name);
|
|
(void)snprintf(t->icon, sizeof t->icon, "%s", icon != NULL ? icon :
|
|
"");
|
|
t->build = build;
|
|
t->data = data;
|
|
pm = TabIcon(p, t->icon);
|
|
s = XmStringCreateLocalized((char *) name);
|
|
t->toggle = XtVaCreateManagedWidget("prefsTab",
|
|
xmToggleButtonWidgetClass, p->tabs, XmNlabelString, s,
|
|
XmNindicatorOn, False, XmNshadowThickness, 2,
|
|
XmNfillOnSelect, True, XmNmarginWidth, 10, XmNmarginHeight, 8,
|
|
XmNlabelType, pm != XmUNSPECIFIED_PIXMAP ? XmPIXMAP_AND_STRING :
|
|
XmSTRING, XmNlabelPixmap, pm, XmNpixmapPlacement, XmPIXMAP_TOP,
|
|
NULL);
|
|
XmStringFree(s);
|
|
i = p->n;
|
|
XtAddCallback(t->toggle, XmNvalueChangedCallback, TabChosen,
|
|
(XtPointer) (size_t) i);
|
|
/* a column of rows: each row is a form of its own (a single form with
|
|
* every row attached to the one before is fragile) */
|
|
/* a column of rows: a row is a form of its own, so the rows stack
|
|
* without chained attachments */
|
|
t->page = XtVaCreateWidget("prefsPage", xmRowColumnWidgetClass,
|
|
p->pages, XmNorientation, XmVERTICAL, XmNpacking,
|
|
XmPACK_COLUMN, XmNspacing, 8, XmNmarginWidth, 8,
|
|
XmNmarginHeight, 8, NULL);
|
|
p->n++;
|
|
return i;
|
|
}
|
|
|
|
void
|
|
McdePrefsShow(Widget w, const char *tab)
|
|
{
|
|
Prefs *p = Of(w);
|
|
char last[64];
|
|
int i = -1, k;
|
|
|
|
if (p == NULL || p->n == 0)
|
|
return;
|
|
if (tab != NULL) {
|
|
for (k = 0; k < p->n; k++)
|
|
if (strcmp(p->tab[k].name, tab) == 0)
|
|
i = k;
|
|
}
|
|
if (i < 0 && McdePrefsConfGet(p->prog, "lasttab", last,
|
|
sizeof last))
|
|
for (k = 0; k < p->n; k++)
|
|
if (strcmp(p->tab[k].name, last) == 0)
|
|
i = k;
|
|
if (i < 0)
|
|
i = 0;
|
|
ShowTab(p, i);
|
|
XtPopup(p->shell, XtGrabNone);
|
|
XmProcessTraversal(p->tab[i].page, XmTRAVERSE_CURRENT);
|
|
}
|
|
|
|
Widget
|
|
McdePrefsRowBegin(Widget form, const char *label)
|
|
{
|
|
Widget row = XtVaCreateManagedWidget("prefsRow", xmFormWidgetClass,
|
|
form, NULL);
|
|
XmString s = XmStringCreateLocalized((char *) label);
|
|
|
|
XtVaCreateManagedWidget("prefsLabel", xmLabelWidgetClass, row,
|
|
XmNlabelString, s, XmNwidth, 170, XmNrecomputeSize, False,
|
|
XmNalignment, XmALIGNMENT_END,
|
|
XmNtopAttachment, XmATTACH_FORM,
|
|
XmNleftAttachment, XmATTACH_FORM, NULL);
|
|
XmStringFree(s);
|
|
return row;
|
|
}
|
|
|
|
void
|
|
McdePrefsRowEnd(Widget row, Widget child)
|
|
{
|
|
Widget label = XtNameToWidget(row, "prefsLabel");
|
|
|
|
XtVaSetValues(child,
|
|
XmNtopAttachment, XmATTACH_FORM,
|
|
XmNleftAttachment, XmATTACH_WIDGET, XmNleftWidget, label,
|
|
XmNleftOffset, 10,
|
|
XmNrightAttachment, XmATTACH_FORM, NULL);
|
|
XtManageChild(child);
|
|
}
|
|
|
|
Widget
|
|
McdePrefsSeparator(Widget form)
|
|
{
|
|
return XtVaCreateManagedWidget("prefsSep", xmSeparatorWidgetClass,
|
|
form, XmNorientation, XmHORIZONTAL, XmNmarginTop, 4,
|
|
XmNmarginBottom, 4, NULL);
|
|
}
|
|
|
|
int
|
|
McdePrefsGet(Widget prefs, const char *key, char *buf, size_t len)
|
|
{
|
|
Prefs *p = Of(prefs);
|
|
|
|
return p != NULL ? McdePrefsConfGet(p->prog, key, buf, len) : 0;
|
|
}
|
|
|
|
int
|
|
McdePrefsSet(Widget prefs, const char *key, const char *value)
|
|
{
|
|
Prefs *p = Of(prefs);
|
|
|
|
return p != NULL ? McdePrefsConfSet(p->prog, key, value) : -1;
|
|
}
|