AsRoot() ran "su -m root -c CMD"; su(1): -m "Leave the environment unmodified", so root found CMD (dtsystemsettings, dtbackup ...) through the user's PATH -- a ~/bin/dtsystemsettings ran as root -- and HOME stayed the user's, so root wrote ~/.dt files there (review 2026-11-13, tasksd t0079). Now plain su (HOME and SHELL become root's), the root command sets PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/pkg/sbin:/usr/pkg/bin:<dt>/bin and XAUTHORITY (the user's, or $HOME/.Xauthority, only if the path is plain) so root still reaches the display. On NetBSD su's -c is a login class and the words after the login go to the shell, so the form works there as on Linux. A command too long for the buffer is not run at all instead of cut. Checked: dtsystemsettings builds (make mcde-linux); the generated command run under sh with a fake dtsystemsettings first in PATH finds none (PATH=/sbin:...:/usr/pkg/dt/bin), /tmp/pwned is not created. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
737 lines
21 KiB
C
737 lines
21 KiB
C
/*
|
|
* main.c -- dtsystemsettings: the settings of the computer in one window
|
|
*
|
|
* Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE.
|
|
*
|
|
* The window shows every pane as an icon, in four bands (panes.c): Personal,
|
|
* Hardware, Internet & Network, System. A click opens the pane in the same
|
|
* window, "Show All" goes back. Panes drawn here take what they show and
|
|
* change from McdeSys (include/Mcde/McdeSys.h) and never run a system tool;
|
|
* the others start the program that has them (CDE's style manager, the
|
|
* printer tool). dtsystemsettings -pane ID opens a pane at once (the menus
|
|
* of the top bar do that).
|
|
*
|
|
* C99, POSIX, Xt and Motif only (ext/src/mcde/AGENTS.md).
|
|
*/
|
|
|
|
#define _POSIX_C_SOURCE 200809L
|
|
|
|
#include <errno.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
#include <sys/wait.h>
|
|
|
|
#include <X11/Intrinsic.h>
|
|
#include <X11/Shell.h>
|
|
#include <Xm/Xm.h>
|
|
#include <Xm/Form.h>
|
|
#include <Xm/Frame.h>
|
|
#include <Xm/Label.h>
|
|
#include <Xm/MessageB.h>
|
|
#include <Xm/PushB.h>
|
|
#include <Xm/RowColumn.h>
|
|
#include <Xm/Scale.h>
|
|
#include <Xm/Separator.h>
|
|
#include <Xm/ToggleB.h>
|
|
#include <Dt/Dt.h>
|
|
|
|
#include <Mcde/McdeSys.h>
|
|
#include <dirent.h>
|
|
#include <sys/stat.h>
|
|
|
|
#include <Mcde/Sound.h>
|
|
|
|
#include "panes.h"
|
|
#include "ui.h"
|
|
|
|
XtAppContext app;
|
|
static Widget shell, title, showAll, overview, paneArea, current;
|
|
static const Pane *shown;
|
|
static XtIntervalId clockTimer;
|
|
|
|
static const char *fallback[] = {
|
|
"Dtsystemsettings*overview*category.marginHeight: 6",
|
|
"Dtsystemsettings*paneArea.marginWidth: 20",
|
|
"Dtsystemsettings*paneArea.marginHeight: 16",
|
|
NULL
|
|
};
|
|
|
|
/* ---- small helpers ------------------------------------------------------ */
|
|
|
|
XmRenderTable
|
|
PaneFont(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;
|
|
}
|
|
|
|
Widget
|
|
Text(Widget parent, const char *name, const char *text)
|
|
{
|
|
XmString s = XmStringCreateLocalized((char *) text);
|
|
Widget w = XtVaCreateManagedWidget(name, xmLabelWidgetClass, parent,
|
|
XmNlabelString, s, XmNalignment, XmALIGNMENT_BEGINNING, NULL);
|
|
|
|
XmStringFree(s);
|
|
return w;
|
|
}
|
|
|
|
void
|
|
SetText(Widget w, const char *text)
|
|
{
|
|
XmString s = XmStringCreateLocalized((char *) text);
|
|
|
|
XtVaSetValues(w, XmNlabelString, s, NULL);
|
|
XmStringFree(s);
|
|
}
|
|
|
|
Widget
|
|
Button(Widget parent, const char *label, XtCallbackProc cb, XtPointer data)
|
|
{
|
|
XmString s = XmStringCreateLocalized((char *) label);
|
|
Widget b = XtVaCreateManagedWidget("button", xmPushButtonWidgetClass,
|
|
parent, XmNlabelString, s, NULL);
|
|
|
|
XmStringFree(s);
|
|
if (cb != NULL)
|
|
XtAddCallback(b, XmNactivateCallback, cb, data);
|
|
return b;
|
|
}
|
|
|
|
/* a button in a pane, its own width (a column would stretch it across) */
|
|
Widget
|
|
PaneButton(Widget parent, const char *label, XtCallbackProc cb, XtPointer data)
|
|
{
|
|
Widget row = XtVaCreateManagedWidget("buttonRow", xmRowColumnWidgetClass,
|
|
parent, XmNorientation, XmHORIZONTAL, XmNmarginWidth, 0, NULL);
|
|
|
|
return Button(row, label, cb, data);
|
|
}
|
|
|
|
/* a column of KEY VALUE lines; the keys right and bold */
|
|
Widget
|
|
Table(Widget parent, const char *const *rows, int n, Widget *values)
|
|
{
|
|
Widget rc = XtVaCreateManagedWidget("table", xmRowColumnWidgetClass,
|
|
parent, XmNorientation, XmVERTICAL, XmNpacking, XmPACK_COLUMN,
|
|
XmNnumColumns, 2, XmNisAligned, False, XmNspacing, 3, NULL);
|
|
XmRenderTable bold = PaneFont(parent, 10, True);
|
|
int i;
|
|
|
|
for (i = 0; i < n; i++) {
|
|
Widget k = Text(rc, "key", rows[2 * i]);
|
|
|
|
XtVaSetValues(k, XmNalignment, XmALIGNMENT_END,
|
|
XmNrenderTable, bold, NULL);
|
|
}
|
|
for (i = 0; i < n; i++) {
|
|
Widget v = Text(rc, "value", rows[2 * i + 1]);
|
|
|
|
if (values != NULL)
|
|
values[i] = v;
|
|
}
|
|
return rc;
|
|
}
|
|
|
|
Pixmap
|
|
Icon(Widget w, const char *file)
|
|
{
|
|
char path[512];
|
|
Pixel fg, bg;
|
|
|
|
XtVaGetValues(w, XmNforeground, &fg, XmNbackground, &bg, NULL);
|
|
snprintf(path, sizeof path, "%s/appconfig/icons/C/%s",
|
|
CDE_INSTALLATION_TOP, file);
|
|
return XmGetPixmap(XtScreen(w), path, fg, bg);
|
|
}
|
|
|
|
/* start a command line in a session of its own, no zombie: the child
|
|
* forks the program and ends at once */
|
|
void
|
|
Spawn(const char *command)
|
|
{
|
|
pid_t pid = fork();
|
|
|
|
if (pid == 0) {
|
|
if (fork() == 0) {
|
|
setsid();
|
|
execl("/bin/sh", "sh", "-c", command, (char *) NULL);
|
|
_exit(127);
|
|
}
|
|
_exit(0);
|
|
}
|
|
if (pid > 0)
|
|
while (waitpid(pid, NULL, 0) < 0 && errno == EINTR)
|
|
;
|
|
}
|
|
|
|
static void
|
|
MessageClosed(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
(void) data;
|
|
(void) call;
|
|
XtDestroyWidget(XtParent(w));
|
|
}
|
|
|
|
void
|
|
Message(Widget parent, const char *text, int error)
|
|
{
|
|
XmString m = XmStringCreateLocalized((char *) text);
|
|
Arg a[2];
|
|
Widget d;
|
|
|
|
XtSetArg(a[0], XmNmessageString, m);
|
|
d = error ? XmCreateErrorDialog(parent, "message", a, 1) :
|
|
XmCreateInformationDialog(parent, "message", a, 1);
|
|
XtUnmanageChild(XmMessageBoxGetChild(d, XmDIALOG_CANCEL_BUTTON));
|
|
XtUnmanageChild(XmMessageBoxGetChild(d, XmDIALOG_HELP_BUTTON));
|
|
XtAddCallback(d, XmNokCallback, MessageClosed, NULL);
|
|
XtManageChild(d);
|
|
XmStringFree(m);
|
|
}
|
|
|
|
/* a path that may stand in single quotes on a command line */
|
|
static int
|
|
PlainPath(const char *p)
|
|
{
|
|
return p != NULL && p[0] == '/' &&
|
|
strspn(p, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
"0123456789/._-") == strlen(p);
|
|
}
|
|
|
|
/*
|
|
* A terminal in which su(1) asks for root's password and runs COMMAND as root.
|
|
* Not "su -m": that keeps the user's whole environment (su(1): "Leave the
|
|
* environment unmodified"), so root looked COMMAND up in the user's PATH --
|
|
* a ~/bin/dtsystemsettings would run as root -- and wrote ~/.dt files into the
|
|
* user's home (review 2026-11-13, tasksd t0079). Plain su sets HOME and
|
|
* SHELL to root's and keeps the rest; the command sets PATH itself, and
|
|
* XAUTHORITY is named so root still reaches this display with the user's
|
|
* cookie (DISPLAY is kept by su). On NetBSD su's -c is a login class; the
|
|
* words after the login go to the shell, so "su root -c CMD" runs CMD there
|
|
* as on Linux. A command that does not fit is not run at all.
|
|
*/
|
|
void
|
|
AsRoot(const char *title, const char *command, char *buf, size_t len)
|
|
{
|
|
char xauth[300] = "";
|
|
const char *x = getenv("XAUTHORITY"), *home = getenv("HOME");
|
|
int n;
|
|
|
|
if (PlainPath(x))
|
|
snprintf(xauth, sizeof xauth, "XAUTHORITY=%s; export XAUTHORITY; ",
|
|
x);
|
|
else if (PlainPath(home) && strlen(home) < 200)
|
|
snprintf(xauth, sizeof xauth, "XAUTHORITY=%s/.Xauthority; "
|
|
"export XAUTHORITY; ", home);
|
|
n = snprintf(buf, len, "dtterm -title '%s' -geometry 70x12 -e su root "
|
|
"-c 'PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/pkg/sbin:/usr/pkg/bin:"
|
|
CDE_INSTALLATION_TOP "/bin; export PATH; %s%s'", title, xauth,
|
|
command);
|
|
if (n < 0 || (size_t) n >= len)
|
|
buf[0] = '\0';
|
|
}
|
|
|
|
/* ---- the sound pane ----------------------------------------------------- */
|
|
|
|
static Widget soundState, soundScale, soundMute;
|
|
|
|
static void
|
|
SoundRead(void)
|
|
{
|
|
int vol = 0, muted = 0;
|
|
|
|
if (mcde_sys_volume_get(&vol, &muted) != MCDE_SYS_OK) {
|
|
SetText(soundState, "There is no sound output.");
|
|
XtSetSensitive(soundScale, False);
|
|
XtSetSensitive(soundMute, False);
|
|
return;
|
|
}
|
|
SetText(soundState, "The volume of the sound output:");
|
|
XmScaleSetValue(soundScale, vol > 100 ? 100 : vol);
|
|
XmToggleButtonSetState(soundMute, muted, False);
|
|
}
|
|
|
|
static void
|
|
SoundVolume(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
(void) w;
|
|
(void) data;
|
|
(void) mcde_sys_volume_set(((XmScaleCallbackStruct *) call)->value);
|
|
}
|
|
|
|
static void
|
|
SoundMute(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
(void) w;
|
|
(void) data;
|
|
(void) mcde_sys_volume_mute(((XmToggleButtonCallbackStruct *) call)->set);
|
|
}
|
|
|
|
static void
|
|
SoundPreview(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
(void) w;
|
|
(void) call;
|
|
(void) McdeSoundEvent(XtDisplay(w), (const char *) data);
|
|
}
|
|
|
|
static void
|
|
SoundTheme(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
(void) call;
|
|
(void) McdeSoundSetTheme(XtDisplay(w), (const char *) data);
|
|
}
|
|
|
|
/* the themes are directories next to the current one */
|
|
static void
|
|
MakeThemes(Widget box)
|
|
{
|
|
char root[512], path[768], *slash;
|
|
DIR *d;
|
|
struct dirent *e;
|
|
Widget row;
|
|
|
|
(void) McdeSoundInit();
|
|
snprintf(root, sizeof root, "%s", McdeSoundThemeDir());
|
|
if ((slash = strrchr(root, '/')) == NULL)
|
|
return;
|
|
*slash = '\0';
|
|
if ((d = opendir(root)) == NULL)
|
|
return;
|
|
XtVaCreateManagedWidget("themeLabel", xmLabelWidgetClass, box,
|
|
XmNlabelString, XmStringCreateLocalized("Sound theme:"), NULL);
|
|
row = XtVaCreateManagedWidget("themes", xmRowColumnWidgetClass, box,
|
|
XmNorientation, XmHORIZONTAL, XmNspacing, 4, NULL);
|
|
while ((e = readdir(d)) != NULL) {
|
|
struct stat st;
|
|
Widget b;
|
|
char *dir;
|
|
|
|
if (e->d_name[0] == '.')
|
|
continue;
|
|
snprintf(path, sizeof path, "%s/%s", root, e->d_name);
|
|
if (stat(path, &st) != 0 || !S_ISDIR(st.st_mode))
|
|
continue;
|
|
b = XtVaCreateManagedWidget(e->d_name, xmPushButtonWidgetClass,
|
|
row, NULL);
|
|
dir = strdup(path);
|
|
XtAddCallback(b, XmNactivateCallback, SoundTheme,
|
|
(XtPointer) dir);
|
|
}
|
|
closedir(d);
|
|
}
|
|
|
|
static Widget
|
|
MakeSound(Widget parent)
|
|
{
|
|
Widget box = XtVaCreateWidget("sound", xmRowColumnWidgetClass, parent,
|
|
XmNspacing, 10, NULL);
|
|
|
|
soundState = Text(box, "state", "");
|
|
soundScale = XtVaCreateManagedWidget("volume", xmScaleWidgetClass, box,
|
|
XmNorientation, XmHORIZONTAL, XmNminimum, 0, XmNmaximum, 100,
|
|
XmNshowValue, True, XmNscaleWidth, 320, NULL);
|
|
XtAddCallback(soundScale, XmNvalueChangedCallback, SoundVolume, NULL);
|
|
soundMute = XtVaCreateManagedWidget("Mute", xmToggleButtonWidgetClass,
|
|
box, NULL);
|
|
XtAddCallback(soundMute, XmNvalueChangedCallback, SoundMute, NULL);
|
|
|
|
XtVaCreateManagedWidget("eventsLabel", xmLabelWidgetClass, box,
|
|
XmNlabelString,
|
|
XmStringCreateLocalized("Desktop events (click to hear):"), NULL);
|
|
{
|
|
Widget row;
|
|
int i, n;
|
|
|
|
(void) McdeSoundInit();
|
|
n = McdeSoundCount();
|
|
row = XtVaCreateManagedWidget("events", xmRowColumnWidgetClass,
|
|
box, XmNorientation, XmHORIZONTAL, XmNpacking,
|
|
XmPACK_COLUMN, XmNnumColumns, 4, XmNspacing, 4, NULL);
|
|
for (i = 0; i < n; i++) {
|
|
const char *name = McdeSoundEventName(i);
|
|
Widget b;
|
|
|
|
if (name == NULL)
|
|
continue;
|
|
b = XtVaCreateManagedWidget(name,
|
|
xmPushButtonWidgetClass, row, NULL);
|
|
XtAddCallback(b, XmNactivateCallback, SoundPreview,
|
|
(XtPointer) name);
|
|
}
|
|
}
|
|
MakeThemes(box);
|
|
SoundRead();
|
|
return box;
|
|
}
|
|
|
|
/* ---- the network pane: network.c ---------------------------------------- */
|
|
|
|
/* ---- the Bluetooth pane ------------------------------------------------- */
|
|
|
|
static Widget btState, btButton;
|
|
static McdeSysBluetooth bt;
|
|
|
|
static void
|
|
BluetoothRead(void)
|
|
{
|
|
char text[96];
|
|
|
|
(void) mcde_sys_bluetooth(&bt);
|
|
if (!bt.present) {
|
|
SetText(btState, "This computer has no Bluetooth controller.");
|
|
SetText(btButton, "Turn Bluetooth On");
|
|
XtSetSensitive(btButton, False);
|
|
return;
|
|
}
|
|
snprintf(text, sizeof text, "Bluetooth is %s (%s).", bt.on ? "on" :
|
|
"off", bt.name);
|
|
SetText(btState, text);
|
|
SetText(btButton, bt.on ? "Turn Bluetooth Off" : "Turn Bluetooth On");
|
|
XtSetSensitive(btButton, True);
|
|
}
|
|
|
|
static void
|
|
BluetoothPower(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
(void) w;
|
|
(void) data;
|
|
(void) call;
|
|
if (mcde_sys_bluetooth_power(!bt.on) != MCDE_SYS_OK)
|
|
SetText(btState, mcde_sys_error());
|
|
else
|
|
BluetoothRead();
|
|
}
|
|
|
|
static Widget
|
|
MakeBluetooth(Widget parent)
|
|
{
|
|
Widget box = XtVaCreateWidget("bluetooth", xmRowColumnWidgetClass,
|
|
parent, XmNspacing, 10, NULL);
|
|
|
|
btState = Text(box, "state", "");
|
|
btButton = PaneButton(box, "Turn Bluetooth Off", BluetoothPower, NULL);
|
|
BluetoothRead();
|
|
return box;
|
|
}
|
|
|
|
/* ---- the date and time pane --------------------------------------------- */
|
|
|
|
static Widget dtTime, dtDate, dtZone;
|
|
|
|
static void
|
|
ClockTick(XtPointer data, XtIntervalId *id)
|
|
{
|
|
char buf[96];
|
|
time_t now = time(NULL);
|
|
struct tm tm;
|
|
|
|
(void) data;
|
|
(void) id;
|
|
clockTimer = 0;
|
|
if (dtTime == NULL)
|
|
return;
|
|
localtime_r(&now, &tm);
|
|
strftime(buf, sizeof buf, "%H:%M:%S", &tm);
|
|
SetText(dtTime, buf);
|
|
strftime(buf, sizeof buf, "%A, %e %B %Y", &tm);
|
|
SetText(dtDate, buf);
|
|
strftime(buf, sizeof buf, "Time zone: %Z (UTC%z)", &tm);
|
|
SetText(dtZone, buf);
|
|
clockTimer = XtAppAddTimeOut(app, 1000, ClockTick, NULL);
|
|
}
|
|
|
|
static void
|
|
ClockGone(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
(void) w;
|
|
(void) data;
|
|
(void) call;
|
|
dtTime = dtDate = dtZone = NULL;
|
|
if (clockTimer != 0)
|
|
XtRemoveTimeOut(clockTimer);
|
|
clockTimer = 0;
|
|
}
|
|
|
|
static Widget
|
|
MakeDateTime(Widget parent)
|
|
{
|
|
Widget box = XtVaCreateWidget("datetime", xmRowColumnWidgetClass,
|
|
parent, XmNspacing, 8, NULL);
|
|
|
|
dtTime = Text(box, "time", "");
|
|
XtVaSetValues(dtTime, XmNrenderTable, PaneFont(box, 28, True), NULL);
|
|
dtDate = Text(box, "date", "");
|
|
dtZone = Text(box, "zone", "");
|
|
XtVaCreateManagedWidget("sep", xmSeparatorWidgetClass, box, NULL);
|
|
(void) MakeZoneChooser(box);
|
|
XtAddCallback(box, XmNdestroyCallback, ClockGone, NULL);
|
|
ClockTick(NULL, NULL);
|
|
return box;
|
|
}
|
|
|
|
/* ---- the about pane ----------------------------------------------------- */
|
|
|
|
static Widget
|
|
MakeAbout(Widget parent)
|
|
{
|
|
Widget box = XtVaCreateWidget("about", xmRowColumnWidgetClass, parent,
|
|
XmNspacing, 8, NULL);
|
|
McdeSysInfo i;
|
|
char version[128], cpu[200], mem[32], disk[200];
|
|
const char *rows[18];
|
|
|
|
(void) mcde_sys_info(&i);
|
|
snprintf(version, sizeof version, "%s %s", i.system, i.version);
|
|
snprintf(cpu, sizeof cpu, "%s (%d)", i.cpu, i.cpus);
|
|
snprintf(mem, sizeof mem, "%llu MB", i.memory >> 20);
|
|
snprintf(disk, sizeof disk, "%s, %llu of %llu MB free", i.disk,
|
|
i.diskFree >> 20, i.diskSize >> 20);
|
|
rows[0] = "System"; rows[1] = version;
|
|
rows[2] = "Kernel"; rows[3] = i.kernel;
|
|
rows[4] = "Computer"; rows[5] = i.model;
|
|
rows[6] = "Processor"; rows[7] = cpu;
|
|
rows[8] = "Memory"; rows[9] = mem;
|
|
rows[10] = "Startup Disk"; rows[11] = disk;
|
|
rows[12] = "Host Name"; rows[13] = i.hostname;
|
|
rows[14] = "Desktop"; rows[15] = DtVERSION_STRING;
|
|
rows[16] = "System Layer"; rows[17] = mcde_sys_backend();
|
|
Table(box, rows, 9, NULL);
|
|
return box;
|
|
}
|
|
|
|
/* ---- the window --------------------------------------------------------- */
|
|
|
|
static void
|
|
ShowOverview(void)
|
|
{
|
|
if (current != NULL) {
|
|
XtDestroyWidget(current);
|
|
current = NULL;
|
|
}
|
|
shown = NULL;
|
|
XtUnmanageChild(paneArea);
|
|
XtManageChild(overview);
|
|
SetText(title, "System Settings");
|
|
XtVaSetValues(shell, XmNtitle, "System Settings", NULL);
|
|
XtSetSensitive(showAll, False);
|
|
}
|
|
|
|
static void
|
|
ShowPane(const Pane *p)
|
|
{
|
|
Widget w = NULL;
|
|
|
|
if (p == NULL || p->kind == PANE_LATER)
|
|
return;
|
|
if (p->kind == PANE_COMMAND) {
|
|
Spawn(p->command);
|
|
return;
|
|
}
|
|
if (current != NULL)
|
|
XtDestroyWidget(current);
|
|
if (strcmp(p->id, "sound") == 0)
|
|
w = MakeSound(paneArea);
|
|
else if (strcmp(p->id, "network") == 0)
|
|
w = MakeNetwork(paneArea);
|
|
else if (strcmp(p->id, "bluetooth") == 0)
|
|
w = MakeBluetooth(paneArea);
|
|
else if (strcmp(p->id, "datetime") == 0)
|
|
w = MakeDateTime(paneArea);
|
|
else if (strcmp(p->id, "about") == 0)
|
|
w = MakeAbout(paneArea);
|
|
else if (strcmp(p->id, "accounts") == 0)
|
|
w = MakeAccounts(paneArea);
|
|
else if (strcmp(p->id, "update") == 0)
|
|
w = MakeUpdate(paneArea);
|
|
else if (strcmp(p->id, "appearance") == 0)
|
|
w = MakeAppearance(paneArea);
|
|
else if (strcmp(p->id, "backup") == 0)
|
|
w = MakeBackup(paneArea);
|
|
else if (strcmp(p->id, "sharing") == 0)
|
|
w = MakeSharing(paneArea);
|
|
else if (strcmp(p->id, "startup") == 0)
|
|
w = MakeStartup(paneArea);
|
|
else if (strcmp(p->id, "desktop") == 0)
|
|
w = MakeDesktop(paneArea);
|
|
else if (strcmp(p->id, "screensaver") == 0)
|
|
w = MakeScreenSaver(paneArea);
|
|
else if (strcmp(p->id, "fonts") == 0)
|
|
w = MakeFonts(paneArea);
|
|
else if (strcmp(p->id, "keyboard") == 0)
|
|
w = MakeKeyboard(paneArea);
|
|
else if (strcmp(p->id, "mouse") == 0)
|
|
w = MakeMouse(paneArea);
|
|
else if (strcmp(p->id, "displays") == 0)
|
|
w = MakeDisplays(paneArea);
|
|
else if (strcmp(p->id, "language") == 0)
|
|
w = MakeLanguage(paneArea);
|
|
if (w == NULL)
|
|
return;
|
|
current = w;
|
|
shown = p;
|
|
XtManageChild(w);
|
|
XtUnmanageChild(overview);
|
|
XtManageChild(paneArea);
|
|
SetText(title, p->label);
|
|
XtVaSetValues(shell, XmNtitle, p->label, NULL);
|
|
XtSetSensitive(showAll, True);
|
|
}
|
|
|
|
static void
|
|
PaneClicked(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
(void) w;
|
|
(void) call;
|
|
ShowPane((const Pane *) data);
|
|
}
|
|
|
|
static void
|
|
ShowAllClicked(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
(void) w;
|
|
(void) data;
|
|
(void) call;
|
|
ShowOverview();
|
|
}
|
|
|
|
/* the overview: one band a category, its panes as icons with their names */
|
|
static Widget
|
|
MakeOverview(Widget parent)
|
|
{
|
|
Widget box = XtVaCreateWidget("overview", xmRowColumnWidgetClass, parent,
|
|
XmNspacing, 4, NULL);
|
|
XmRenderTable bold = PaneFont(box, 11, True);
|
|
int c, i;
|
|
|
|
for (c = 0; c < CAT_COUNT; c++) {
|
|
Widget band, inner, row, l;
|
|
|
|
band = XtVaCreateManagedWidget("category", xmFrameWidgetClass,
|
|
box, XmNshadowType, XmSHADOW_ETCHED_IN, NULL);
|
|
inner = XtVaCreateManagedWidget("inner", xmRowColumnWidgetClass,
|
|
band, XmNspacing, 2, NULL);
|
|
l = Text(inner, "name", categoryNames[c]);
|
|
XtVaSetValues(l, XmNrenderTable, bold, NULL);
|
|
row = XtVaCreateManagedWidget("panes", xmRowColumnWidgetClass,
|
|
inner, XmNorientation, XmHORIZONTAL, XmNspacing, 8, NULL);
|
|
for (i = 0; i < paneCount; i++) {
|
|
const Pane *p = &panes[i];
|
|
Widget item, b;
|
|
|
|
if (p->category != c)
|
|
continue;
|
|
/* the icon in a field of one size, the name under it:
|
|
* the CDE icons are 16 to 37 pixels high, the names
|
|
* stand on one line all the same */
|
|
item = XtVaCreateManagedWidget("item",
|
|
xmRowColumnWidgetClass, row, XmNspacing, 0,
|
|
XmNmarginWidth, 0, XmNmarginHeight, 0,
|
|
XmNentryAlignment, XmALIGNMENT_CENTER, NULL);
|
|
b = XtVaCreateManagedWidget(p->id, xmPushButtonWidgetClass,
|
|
item, XmNlabelType, XmPIXMAP,
|
|
XmNlabelPixmap, Icon(row, p->icon),
|
|
XmNshadowThickness, 0, XmNrecomputeSize, False,
|
|
XmNwidth, 112, XmNheight, 44, NULL);
|
|
l = Text(item, "label", p->label);
|
|
XtVaSetValues(l, XmNalignment, XmALIGNMENT_CENTER, NULL);
|
|
if (p->kind == PANE_LATER) {
|
|
XtSetSensitive(b, False);
|
|
XtSetSensitive(l, False);
|
|
} else
|
|
XtAddCallback(b, XmNactivateCallback, PaneClicked,
|
|
(XtPointer) p);
|
|
}
|
|
}
|
|
return box;
|
|
}
|
|
|
|
int
|
|
main(int argc, char **argv)
|
|
{
|
|
Widget form, bar, sep;
|
|
const char *start = NULL;
|
|
int i;
|
|
|
|
XtSetLanguageProc(NULL, NULL, NULL);
|
|
shell = XtVaAppInitialize(&app, "Dtsystemsettings", NULL, 0, &argc,
|
|
argv, (String *) fallback, XmNtitle, "System Settings", NULL);
|
|
for (i = 1; i < argc; i++) {
|
|
if (strcmp(argv[i], "-pane") == 0 && i + 1 < argc)
|
|
start = argv[++i];
|
|
else if (strcmp(argv[i], "-apply-update") == 0)
|
|
return ApplyUpdate();
|
|
else if (strcmp(argv[i], "-apply-displays") == 0)
|
|
return ApplyDisplaysCommand(XtDisplay(shell));
|
|
else if (strcmp(argv[i], "-set-timezone") == 0 && i + 1 < argc)
|
|
return SetTimezoneCommand(argv[i + 1]);
|
|
else if (strcmp(argv[i], "-join-wifi") == 0 && i + 1 < argc)
|
|
return JoinWifiCommand(argv[i + 1],
|
|
i + 2 < argc ? argv[i + 2] : NULL);
|
|
else if (strcmp(argv[i], "-renew-dhcp") == 0 && i + 1 < argc)
|
|
return RenewDhcpCommand(argv[i + 1]);
|
|
else {
|
|
fprintf(stderr, "usage: dtsystemsettings [-pane ID | "
|
|
"-apply-update | -apply-displays | -set-timezone ZONE | -join-wifi IF "
|
|
"[SSID-HEX] | -renew-dhcp IF]\n");
|
|
return 1;
|
|
}
|
|
}
|
|
/* a CDE program: its menus would go to the top bar, and it is one */
|
|
(void) DtInitialize(XtDisplay(shell), shell, argv[0], "Dtsystemsettings");
|
|
|
|
form = XtVaCreateManagedWidget("form", xmFormWidgetClass, shell,
|
|
XmNmarginWidth, 8, XmNmarginHeight, 8, NULL);
|
|
bar = XtVaCreateManagedWidget("toolbar", xmRowColumnWidgetClass, form,
|
|
XmNorientation, XmHORIZONTAL, XmNspacing, 12,
|
|
XmNtopAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM,
|
|
XmNrightAttachment, XmATTACH_FORM, NULL);
|
|
showAll = Button(bar, "Show All", ShowAllClicked, NULL);
|
|
title = Text(bar, "title", "System Settings");
|
|
XtVaSetValues(title, XmNrenderTable, PaneFont(bar, 12, True), NULL);
|
|
sep = XtVaCreateManagedWidget("sep", xmSeparatorWidgetClass, form,
|
|
XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, bar,
|
|
XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM,
|
|
NULL);
|
|
overview = MakeOverview(form);
|
|
XtVaSetValues(overview, XmNtopAttachment, XmATTACH_WIDGET,
|
|
XmNtopWidget, sep, XmNleftAttachment, XmATTACH_FORM,
|
|
XmNrightAttachment, XmATTACH_FORM, XmNbottomAttachment,
|
|
XmATTACH_FORM, NULL);
|
|
paneArea = XtVaCreateWidget("paneArea", xmRowColumnWidgetClass, form,
|
|
XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, sep,
|
|
XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM,
|
|
XmNbottomAttachment, XmATTACH_FORM, NULL);
|
|
XtManageChild(overview);
|
|
XtSetSensitive(showAll, False);
|
|
XtRealizeWidget(shell);
|
|
if (start != NULL) {
|
|
const Pane *p = PaneFind(start);
|
|
|
|
if (p == NULL)
|
|
fprintf(stderr, "dtsystemsettings: no pane \"%s\"\n", start);
|
|
else
|
|
ShowPane(p);
|
|
}
|
|
XtAppMainLoop(app);
|
|
return 0;
|
|
}
|