New programs/dtsystemsettings/security.c with the reference's three tabs:
General "Require password to wake this computer from sleep or screen
saver" writes dtsession's lock time (_DtSetSmState with
SM_STATE_LOCKTIMEOUT; the Screen Saver page reads and writes the
same field, so the two pages show one setting). On: the lock at
the saver's time, or ten minutes without a saver. "Use secure
virtual memory" is NetBSD's vm.swap_encrypt through McdeSys
(now and in /etc/sysctl.conf, root). Automatic login and a
log-out after N minutes are shown as what the desktop has:
dtlogin always asks for a name and a password, and dtsession
has no idle logout -- the pane says so and greys the controls.
Encryption the cgd(4) volumes of /etc/cgd/cgd.conf, and the sentence that
encrypting a disk is a decision of the installation, not of a
running system; changing a passphrase is a follow-up.
Firewall the npf(7) state (rc.conf npf=YES, /etc/npf.conf); the rules
are a follow-up -- a fixed template with the shares of the
Sharing page, never free text.
McdeSys gained the security state: mcde_sys_swap_encrypt_get/_set,
mcde_sys_cgd_volumes, mcde_sys_firewall_get. netbsd.c implements them
(sysctl(8) vm.swap_encrypt, /etc/sysctl.conf through a KeySet() that rc.conf
now uses too, /etc/cgd/cgd.conf, rc.conf's npf), linux.c answers
MCDE_SYS_ENOTSUP with a sentence saying whose feature it is.
test_sysinfo prints all three.
The pane's icon is new: programs/icons/McdeLock.pm (a padlock, palette
colours); "security" is a real pane now, not a greyed entry.
Measured under Xvfb with xdotool (dtsession started in the session):
- the lock checkbox: _DT_SM_STATE_INFO on dtsession's window before the
click 0xfff, ... lockTimeout 0x0; after it 0x100 (SM_STATE_LOCKTIMEOUT),
lockTimeout 0x258 (600 s); a second click puts it back to 0x0;
- the three tabs and their content (docs/screenshots/leopard/
System-Preferences-Security-mcde.png with the lock on, ...-Encryption-
mcde.png, ...-Firewall-mcde.png);
- test_sysinfo on this (Linux) host prints the three MCDE_SYS_ENOTSUP
sentences -- the pane shows them instead of dead controls;
- make check programs/dtsystemsettings: test_panes PASS; the Sound and
Keyboard & Mouse panes still switch their tabs after the layout fix
below;
- make programs/dtsystemsettings, lib/McdeSys exit=0.
A Motif lesson, saved in AGENTS.md: a row column inside the pane area takes
the other orientation unless told, a child added later to a tight-packed
column goes into the next column, and a page managed for the first time after
its widgets were built keeps a height of one line. The pane therefore builds
its page fresh inside an XmPACK_COLUMN container on a tab change; the same
XmNorientation, XmVERTICAL went into the Sound and Keyboard & Mouse page
containers.
Not measured, because this host is not NetBSD or has no root: swapping
vm.swap_encrypt, reading cgd volumes, the npf state and writing npf rules.
They are the follow-up task for the VM.
370 lines
10 KiB
C
370 lines
10 KiB
C
/*
|
|
* sound.c -- dtsystemsettings: the sound of the desktop (t0163)
|
|
*
|
|
* License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
|
|
*
|
|
* Three tabs as the reference has them: Sound Effects, Output, Input.
|
|
*
|
|
* Sound Effects the events of the session's sound theme, a click plays
|
|
* one (McdeSoundEvent, the server of mcdesoundd); the
|
|
* theme itself is chosen from the directories next to the
|
|
* current one.
|
|
* Output the volume of the default output and Mute
|
|
* (mcde_sys_volume_get/_set/_mute), and whether the bar
|
|
* shows it (~/.dt/bar, "showvolume="; dtbar reads it at
|
|
* start).
|
|
* Input a note: McdeSys has no capture API yet, so there is no
|
|
* input level and no input volume to set.
|
|
*
|
|
* C99, POSIX, Xt and Motif only (ext/src/mcde/AGENTS.md).
|
|
*/
|
|
|
|
#define _POSIX_C_SOURCE 200809L
|
|
|
|
#include <dirent.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/types.h>
|
|
|
|
#include <Xm/Xm.h>
|
|
#include <Xm/Label.h>
|
|
#include <Xm/List.h>
|
|
#include <Xm/PushB.h>
|
|
#include <Xm/PushBG.h>
|
|
#include <Xm/RowColumn.h>
|
|
#include <Xm/Scale.h>
|
|
#include <Xm/ToggleB.h>
|
|
|
|
#include <Mcde/McdeSys.h>
|
|
#include <Mcde/Sound.h>
|
|
|
|
#include "ui.h"
|
|
|
|
static Widget soundState, soundScale, soundMute, soundBar, soundThemes;
|
|
static Widget soundList;
|
|
|
|
/* ---- the bar's "show the volume" (~/.dt/bar) ---------------------------- */
|
|
|
|
static void
|
|
BarFile(char *buf, size_t len)
|
|
{
|
|
const char *home = getenv("HOME");
|
|
|
|
(void)snprintf(buf, len, "%s/.dt/bar", home != NULL ? home : ".");
|
|
}
|
|
|
|
static Boolean
|
|
BarShowsVolume(void)
|
|
{
|
|
char path[1024], line[128];
|
|
FILE *f;
|
|
Boolean show = True;
|
|
|
|
BarFile(path, sizeof path);
|
|
if ((f = fopen(path, "r")) == NULL)
|
|
return True;
|
|
while (fgets(line, sizeof line, f) != NULL) {
|
|
line[strcspn(line, "\r\n")] = '\0';
|
|
if (strncmp(line, "showvolume=", 11) == 0)
|
|
show = atoi(line + 11) != 0;
|
|
}
|
|
fclose(f);
|
|
return show;
|
|
}
|
|
|
|
static void
|
|
BarWrite(Boolean show)
|
|
{
|
|
char path[1024], keep[64][160], line[160];
|
|
FILE *f;
|
|
int i, n = 0;
|
|
|
|
BarFile(path, sizeof path);
|
|
if ((f = fopen(path, "r")) != NULL) {
|
|
while (n < 64 && fgets(line, sizeof line, f) != NULL) {
|
|
line[strcspn(line, "\r\n")] = '\0';
|
|
if (line[0] == '\0' ||
|
|
strncmp(line, "showvolume=", 11) == 0)
|
|
continue;
|
|
(void)snprintf(keep[n++], sizeof keep[0], "%s", line);
|
|
}
|
|
fclose(f);
|
|
}
|
|
if ((f = fopen(path, "w")) != NULL) {
|
|
fputs("# the bar (dtbar): what the status area shows\n", f);
|
|
for (i = 0; i < n; i++)
|
|
fprintf(f, "%s\n", keep[i]);
|
|
fprintf(f, "showvolume=%d\n", show ? 1 : 0);
|
|
fclose(f);
|
|
}
|
|
}
|
|
|
|
/* ---- the pages ---------------------------------------------------------- */
|
|
|
|
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 default 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
|
|
SoundBar(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
(void) w;
|
|
(void) data;
|
|
(void) call;
|
|
BarWrite(XmToggleButtonGetState(soundBar));
|
|
SetText(soundState, "The bar reads it when it starts (log out and in, "
|
|
"or start dtbar again).");
|
|
}
|
|
|
|
/* the events of the theme; a click plays one */
|
|
static void
|
|
EventChosen(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
XmListCallbackStruct *c = (XmListCallbackStruct *) call;
|
|
char *text = NULL;
|
|
|
|
(void) w;
|
|
(void) data;
|
|
if (!XmStringGetLtoR(c->item, XmFONTLIST_DEFAULT_TAG, &text))
|
|
return;
|
|
(void) McdeSoundEvent(XtDisplay(w), text);
|
|
XtFree(text);
|
|
}
|
|
|
|
/* the themes: the directories next to the current one */
|
|
static void
|
|
ThemeChosen(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
Widget hist = NULL, item = NULL;
|
|
char *dir = NULL;
|
|
|
|
(void) call;
|
|
XtVaGetValues(soundThemes, XmNmenuHistory, &hist, NULL);
|
|
if (hist == NULL || hist != w)
|
|
return;
|
|
XtVaGetValues(soundThemes, XmNmenuHistory, &item, NULL);
|
|
if (item == NULL)
|
|
return;
|
|
XtVaGetValues(item, XmNuserData, &dir, NULL);
|
|
if (dir != NULL)
|
|
(void) McdeSoundSetTheme(XtDisplay(soundThemes), dir);
|
|
}
|
|
|
|
static void
|
|
MakeThemes(Widget parent, Widget page)
|
|
{
|
|
char root[512], path[768], *slash;
|
|
DIR *d;
|
|
struct dirent *e;
|
|
Widget row, pd;
|
|
XmString s;
|
|
|
|
(void) parent;
|
|
(void) McdeSoundInit();
|
|
snprintf(root, sizeof root, "%s", McdeSoundThemeDir());
|
|
if ((slash = strrchr(root, '/')) == NULL)
|
|
return;
|
|
*slash = '\0';
|
|
if ((d = opendir(root)) == NULL)
|
|
return;
|
|
row = XtVaCreateManagedWidget("themeRow", xmRowColumnWidgetClass,
|
|
page, XmNorientation, XmHORIZONTAL, XmNspacing, 6, NULL);
|
|
s = XmStringCreateLocalized((char *) "Theme:");
|
|
(void) XtVaCreateManagedWidget("themeLabel", xmLabelWidgetClass, row,
|
|
XmNlabelString, s, NULL);
|
|
XmStringFree(s);
|
|
soundThemes = XmCreateOptionMenu(row, "themes", NULL, 0);
|
|
pd = XmCreatePulldownMenu(soundThemes, "themeMenu", NULL, 0);
|
|
while ((e = readdir(d)) != NULL) {
|
|
struct stat st;
|
|
Widget b;
|
|
|
|
if (e->d_name[0] == '.')
|
|
continue;
|
|
(void)snprintf(path, sizeof path, "%s/%s", root, e->d_name);
|
|
if (stat(path, &st) != 0 || !S_ISDIR(st.st_mode))
|
|
continue;
|
|
s = XmStringCreateLocalized(e->d_name);
|
|
b = XtVaCreateManagedWidget("themeItem",
|
|
xmPushButtonGadgetClass, pd, XmNlabelString, s,
|
|
XmNuserData, strdup(path), NULL);
|
|
XmStringFree(s);
|
|
XtAddCallback(b, XmNactivateCallback, ThemeChosen, NULL);
|
|
}
|
|
XtVaSetValues(soundThemes, XmNsubMenuId, pd, NULL);
|
|
XtManageChild(soundThemes);
|
|
closedir(d);
|
|
(void) row;
|
|
}
|
|
|
|
static Widget
|
|
MakeEffectsPage(Widget parent)
|
|
{
|
|
Widget page = XtVaCreateWidget("soundEffects", xmRowColumnWidgetClass,
|
|
parent, XmNspacing, 6, NULL);
|
|
Widget l;
|
|
XmString s;
|
|
int i, n;
|
|
|
|
s = XmStringCreateLocalized((char *) "Choose an alert sound");
|
|
l = XtVaCreateManagedWidget("effectsLabel", xmLabelWidgetClass, page,
|
|
XmNlabelString, s, XmNalignment, XmALIGNMENT_BEGINNING, NULL);
|
|
XmStringFree(s);
|
|
XtVaSetValues(l, XmNrenderTable, PaneFont(page, 11, True), NULL);
|
|
|
|
soundList = XmCreateScrolledList(page, "events", NULL, 0);
|
|
XtVaSetValues(soundList, XmNvisibleItemCount, 10,
|
|
XmNselectionPolicy, XmBROWSE_SELECT, XmNwidth, 320, NULL);
|
|
(void) McdeSoundInit();
|
|
n = McdeSoundCount();
|
|
for (i = 0; i < n; i++) {
|
|
const char *name = McdeSoundEventName(i);
|
|
|
|
if (name == NULL)
|
|
continue;
|
|
s = XmStringCreateLocalized((char *) name);
|
|
XmListAddItemUnselected(soundList, s, 0);
|
|
XmStringFree(s);
|
|
}
|
|
XtAddCallback(soundList, XmNbrowseSelectionCallback, EventChosen,
|
|
NULL);
|
|
XtManageChild(soundList);
|
|
|
|
MakeThemes(page, page);
|
|
(void) Text(page, "effectsNote", "A click plays the event through "
|
|
"mcdesoundd. The list is the session's theme; \"alert\" is what "
|
|
"a warning plays.");
|
|
return page;
|
|
}
|
|
|
|
static Widget
|
|
MakeOutputPage(Widget parent)
|
|
{
|
|
Widget page = XtVaCreateWidget("soundOutput", xmRowColumnWidgetClass,
|
|
parent, XmNspacing, 8, NULL);
|
|
|
|
soundState = Text(page, "state", "");
|
|
soundScale = XtVaCreateManagedWidget("volume", xmScaleWidgetClass, page,
|
|
XmNorientation, XmHORIZONTAL, XmNminimum, 0, XmNmaximum, 100,
|
|
XmNshowValue, True, XmNscaleWidth, 320, NULL);
|
|
XtAddCallback(soundScale, XmNvalueChangedCallback, SoundVolume, NULL);
|
|
soundMute = XtVaCreateManagedWidget("Mute", xmToggleButtonWidgetClass,
|
|
page, NULL);
|
|
XtAddCallback(soundMute, XmNvalueChangedCallback, SoundMute, NULL);
|
|
soundBar = XtVaCreateManagedWidget("Show the volume in the bar",
|
|
xmToggleButtonWidgetClass, page, NULL);
|
|
XmToggleButtonSetState(soundBar, BarShowsVolume(), False);
|
|
XtAddCallback(soundBar, XmNvalueChangedCallback, SoundBar, NULL);
|
|
(void) Text(page, "outputNote", "One output: the default. McdeSys has "
|
|
"no list of sound devices yet, so there is no device to choose.");
|
|
SoundRead();
|
|
return page;
|
|
}
|
|
|
|
static Widget
|
|
MakeInputPage(Widget parent)
|
|
{
|
|
Widget page = XtVaCreateWidget("soundInput", xmRowColumnWidgetClass,
|
|
parent, XmNspacing, 8, NULL);
|
|
|
|
(void) Text(page, "inputNote", "There is no input to show: McdeSys "
|
|
"has no capture API.\nNo input level meter and no input volume; "
|
|
"they belong to the same\naddition as the output device list.");
|
|
return page;
|
|
}
|
|
|
|
/* ---- the pane ----------------------------------------------------------- */
|
|
|
|
static Widget soundPages[3];
|
|
|
|
static void
|
|
SoundTab(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
int which = (int) (size_t) data, i;
|
|
|
|
(void) w;
|
|
if (call != NULL && !((XmToggleButtonCallbackStruct *) call)->set)
|
|
return;
|
|
for (i = 0; i < 3; i++)
|
|
if (soundPages[i] != NULL)
|
|
if (i == which)
|
|
XtManageChild(soundPages[i]);
|
|
else
|
|
XtUnmanageChild(soundPages[i]);
|
|
}
|
|
|
|
Widget
|
|
MakeSound(Widget parent)
|
|
{
|
|
Widget box = XtVaCreateWidget("sound", xmRowColumnWidgetClass, parent,
|
|
XmNspacing, 8, NULL);
|
|
Widget tabs, pages;
|
|
static const char *const labels[3] = { "Sound Effects", "Output",
|
|
"Input" };
|
|
int i;
|
|
|
|
tabs = XtVaCreateManagedWidget("soundTabs", xmRowColumnWidgetClass,
|
|
box, XmNorientation, XmHORIZONTAL, XmNspacing, 4,
|
|
XmNmarginWidth, 0, NULL);
|
|
/* vertical: a child of a vertical row column would pack its pages
|
|
* side by side (the default is the parent's orientation reversed) */
|
|
pages = XtVaCreateManagedWidget("soundPages", xmRowColumnWidgetClass,
|
|
box, XmNorientation, XmVERTICAL, XmNspacing, 4, NULL);
|
|
for (i = 0; i < 3; i++) {
|
|
XmString s = XmStringCreateLocalized((char *) labels[i]);
|
|
Widget t = XtVaCreateManagedWidget("soundTab",
|
|
xmToggleButtonWidgetClass, tabs, XmNlabelString, s,
|
|
XmNindicatorOn, False, XmNshadowThickness, 2,
|
|
XmNfillOnSelect, True, XmNmarginWidth, 10, NULL);
|
|
|
|
XmStringFree(s);
|
|
XtAddCallback(t, XmNvalueChangedCallback, SoundTab,
|
|
(XtPointer) (size_t) i);
|
|
}
|
|
/*
|
|
* the three pages; the first is shown, the tabs look their pages up
|
|
* by name when one is chosen
|
|
*/
|
|
soundPages[0] = MakeEffectsPage(pages);
|
|
soundPages[1] = MakeOutputPage(pages);
|
|
soundPages[2] = MakeInputPage(pages);
|
|
XtManageChild(soundPages[0]);
|
|
{
|
|
Widget first = XtNameToWidget(tabs, "soundTab");
|
|
|
|
if (first != NULL)
|
|
XmToggleButtonSetState(first, True, False);
|
|
}
|
|
return box;
|
|
}
|