Files
mcde/programs/dtsystemsettings/appearance.c
T
lotherk 11cd07b560 MCDE: the IRIX cursor font as an Xcursor theme, both themes in Appearance (t0301)
The IRIX cursor font x_eoe usr/lib/X11/fonts/misc/cursor.pcf is extracted
with the sw parser, pcf2bdf turns it into BDF, and bdf-cursors.py makes
58 Xcursor names from the glyphs (form + _mask).  The Solaris and IRIX
themes are in share/icons/Solaris and share/icons/IRIX; the Appearance
pane has a "Cursor theme:" menu (Solaris, IRIX) that keeps the choice in
~/.dt/cursor-theme; 0079.dtcursor exports XCURSOR_THEME from it.
Measured: XcursorLibraryLoadImage("left_ptr", "IRIX", 16) returns a
16x16 image, and the menu shows Solaris/IRIX; choosing Solaris wrote
~/.dt/cursor-theme.
2026-11-16 14:32:23 +00:00

1228 lines
32 KiB
C

/*
* appearance.c -- dtsystemsettings: the colours and the fonts of the desktop
*
* License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
*
* Appearance: CDE's palettes (*.dp, eight colours each), every one drawn as
* a row of its colours. Choosing one does what dtstyle does
* (programs/dtstyle/ColorMain.c, the resource "*0*ColorPalette: NAME.dp"
* merged with _DtAddToResource(3)); dtsession saves the resources at logout
* (dtsession/SmSave.c, OutputResource) and its colour server allocates the
* palette at the next login. On a TrueColor screen -- every screen today --
* the colour server cannot change colours that are allocated, so dtstyle
* says the same: the palette takes effect at the next session.
*
* Fonts: the family and size of the render table every MCDE program draws
* with (dtsession/sys.resources.src: *mcde.fontName, *mcde.fontSize), merged
* the same way; a program started after the change uses it at once. The
* families are the ones fontconfig knows, listed through Xft.
*
* The palettes are found where dtsession's colour server looks
* (dtsession/SrvFile_io.c): ~/.dt/palettes, CDE_CONFIGURATION_TOP/palettes,
* CDE_INSTALLATION_TOP/palettes; a name found earlier wins.
*
* C99, POSIX, Xt and Motif only (ext/src/mcde/AGENTS.md); Xft as Motif uses
* it.
*/
#define _POSIX_C_SOURCE 200809L
#include <dirent.h>
#include <strings.h>
#include <sys/stat.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Intrinsic.h>
#include <X11/Xresource.h>
#include <X11/Xft/Xft.h>
#include <Xm/Xm.h>
#include <Xm/Label.h>
#include <Xm/PushBG.h>
#include <Xm/Separator.h>
#include <Xm/TextF.h>
#include <Xm/List.h>
#include <Xm/PushB.h>
#include <Xm/RowColumn.h>
#include <Xm/Scale.h>
#include <Xm/ScrolledW.h>
#include <Xm/ToggleB.h>
#include <Dt/DtP.h>
#include "ui.h"
/* ---- the resources as they are now -------------------------------------- */
/* VALUE of the resource NAME/CLASS in the server's resources, or DEF */
void
ServerResource(Display *dpy, const char *name, const char *class, const char *def,
char *buf, size_t len)
{
char *s = XResourceManagerString(dpy), *type = NULL;
XrmDatabase db;
XrmValue v;
snprintf(buf, len, "%s", def);
if (s == NULL || (db = XrmGetStringDatabase(s)) == NULL)
return;
if (XrmGetResource(db, name, class, &type, &v) && v.addr != NULL)
snprintf(buf, len, "%.*s", (int) v.size, (char *) v.addr);
XrmDestroyDatabase(db);
/* XrmValue counts the NUL; a value may end in blanks */
while (buf[0] != '\0' && (buf[strlen(buf) - 1] == ' ' ||
buf[strlen(buf) - 1] == '\t'))
buf[strlen(buf) - 1] = '\0';
}
/* ---- Appearance --------------------------------------------------------- */
#define MAX_PALETTES 128
#define SWATCH 14
#define ROW_LABEL_W 210
typedef struct {
char name[64];
char path[512];
} Palette;
/* an option menu and its items: the value is the item's index */
typedef struct {
Widget menu;
Widget item[16];
int n;
} Opt;
static Palette pal[MAX_PALETTES];
static int npal;
/* the Solaris cursors of share/cursors */
#define MAX_CURSORS 64
static char *cursorNames[MAX_CURSORS];
static int ncursors;
static Opt cursorOpt;
/* the Xcursor themes of share/icons (Solaris, IRIX, ...) */
#define MAX_CURSOR_THEMES 16
static char *themeNames[MAX_CURSOR_THEMES];
static int nthemes;
static Opt themeOpt;
static Widget appNote, appLogout, palNote, hiNote;
/* the directories with an index.theme under share/icons */
static void
ScanCursorThemes(const char *dir)
{
DIR *d = opendir(dir);
struct dirent *de;
char path[600];
if (d == NULL)
return;
while ((de = readdir(d)) != NULL && nthemes < MAX_CURSOR_THEMES) {
FILE *f;
if (de->d_name[0] == '.')
continue;
snprintf(path, sizeof path, "%s/%s/index.theme", dir,
de->d_name);
if ((f = fopen(path, "r")) == NULL)
continue;
fclose(f);
themeNames[nthemes] = strdup(de->d_name);
nthemes++;
}
closedir(d);
}
static int
ThemeCompare(const void *a, const void *b)
{
return strcmp(*(char *const *) a, *(char *const *) b);
}
/* the chosen Xcursor theme: ~/.dt/cursor-theme, for 0079.dtcursor */
static void
CursorThemeChosen(Widget w, XtPointer data, XtPointer call)
{
int i = (int) (long) data;
const char *home = getenv("HOME");
char path[600];
if (i < 0 || i >= nthemes)
return;
if (home != NULL) {
FILE *f;
snprintf(path, sizeof path, "%s/.dt/cursor-theme", home);
if ((f = fopen(path, "w")) != NULL) {
fprintf(f, "%s\n", themeNames[i]);
fclose(f);
}
}
(void) w;
(void) call;
}
static void
ScanCursors(const char *dir)
{
DIR *d = opendir(dir);
struct dirent *de;
size_t n;
if (d == NULL)
return;
while ((de = readdir(d)) != NULL && ncursors < MAX_CURSORS) {
n = strlen(de->d_name);
if (n < 8 || strcmp(de->d_name + n - 7, ".cursor") != 0)
continue;
cursorNames[ncursors] = strdup(de->d_name);
cursorNames[ncursors][n - 7] = '\0';
ncursors++;
}
closedir(d);
}
static int
CursorCompare(const void *a, const void *b)
{
return strcmp(*(char *const *) a, *(char *const *) b);
}
static int
PaletteCompare(const void *a, const void *b)
{
return strcmp(((const Palette *) a)->name, ((const Palette *) b)->name);
}
static void
ScanPalettes(const char *dir)
{
DIR *d = opendir(dir);
struct dirent *de;
int i;
if (d == NULL)
return;
while ((de = readdir(d)) != NULL && npal < MAX_PALETTES) {
size_t n = strlen(de->d_name);
if (n < 4 || strcmp(de->d_name + n - 3, ".dp") != 0 ||
n - 3 >= sizeof pal[0].name)
continue;
for (i = 0; i < npal; i++)
if (strncmp(pal[i].name, de->d_name, n - 3) == 0 &&
pal[i].name[n - 3] == '\0')
break;
if (i < npal)
continue;
snprintf(pal[npal].name, sizeof pal[npal].name, "%.*s",
(int) (n - 3), de->d_name);
snprintf(pal[npal].path, sizeof pal[npal].path, "%s/%s", dir,
de->d_name);
npal++;
}
closedir(d);
}
/* the palette's colours side by side; None when it cannot be read */
static Pixmap
Swatches(Widget w, const char *path)
{
Display *dpy = XtDisplay(w);
Screen *scr = XtScreen(w);
Colormap cmap = DefaultColormapOfScreen(scr);
char line[64];
FILE *fp = fopen(path, "r");
Pixmap pm;
GC gc;
XColor c;
int n = 0;
if (fp == NULL)
return None;
pm = XCreatePixmap(dpy, RootWindowOfScreen(scr), 8 * SWATCH + 1,
SWATCH + 1, (unsigned int) DefaultDepthOfScreen(scr));
gc = XCreateGC(dpy, pm, 0, NULL);
XSetForeground(dpy, gc, BlackPixelOfScreen(scr));
XFillRectangle(dpy, pm, gc, 0, 0, 8 * SWATCH + 1, SWATCH + 1);
while (n < 8 && fgets(line, sizeof line, fp) != NULL) {
line[strcspn(line, " \t\r\n")] = '\0';
/* "#RRRRGGGGBBBB" or a colour's name (Black.dp: "Black") */
if (line[0] == '\0' || !XParseColor(dpy, cmap, line, &c) ||
!XAllocColor(dpy, cmap, &c))
continue;
XSetForeground(dpy, gc, c.pixel);
XFillRectangle(dpy, pm, gc, n * SWATCH + 1, 1, SWATCH - 1,
SWATCH - 1);
n++;
}
fclose(fp);
XFreeGC(dpy, gc);
if (n == 0) {
XFreePixmap(dpy, pm);
return None;
}
return pm;
}
/* the other toolkits follow MCDE (programs/dtthemesync): GTK at once
* through XSETTINGS, Qt and X programs when they start */
static void
ThemeSync(const char *palette)
{
pid_t pid = fork();
if (pid == 0) {
if (palette != NULL)
execl(CDE_INSTALLATION_TOP "/bin/dtthemesync",
"dtthemesync", "-palette", palette, (char *) NULL);
else
execl(CDE_INSTALLATION_TOP "/bin/dtthemesync",
"dtthemesync", (char *) NULL);
_exit(127);
} else if (pid > 0)
(void) waitpid(pid, NULL, 0);
}
/* ---- the shape of the pane: a labelled row, its note, a separator -------- */
static Widget
Row(Widget col, const char *label)
{
Widget row = XtVaCreateManagedWidget("row", xmRowColumnWidgetClass, col,
XmNorientation, XmHORIZONTAL, XmNspacing, 8, XmNmarginWidth, 0,
XmNmarginHeight, 0, NULL);
Widget l = Text(row, "rowLabel", label);
XtVaSetValues(l, XmNwidth, ROW_LABEL_W, XmNrecomputeSize, False,
XmNalignment, XmALIGNMENT_END, NULL);
return row;
}
/* a sentence under a row, aligned with the controls, not with the labels */
static Widget
Note(Widget col, const char *text)
{
Widget l = Text(col, "note", text);
XtVaSetValues(l, XmNmarginLeft, ROW_LABEL_W + 8, NULL);
return l;
}
/* a heading over the controls, in their column */
static Widget
Heading(Widget col, const char *text)
{
Widget row = Row(col, "");
Widget l = Text(row, "heading", text);
XtVaSetValues(l, XmNrenderTable, PaneFont(l, 10, True), NULL);
return l;
}
static Widget
Sep(Widget col)
{
return XtVaCreateManagedWidget("sep", xmSeparatorWidgetClass, col,
XmNorientation, XmHORIZONTAL, XmNmarginTop, 6, XmNmarginBottom, 6,
NULL);
}
/* ---- option menus ------------------------------------------------------- */
static int
OptValue(const Opt *o)
{
Widget h = NULL;
int i;
if (o == NULL || o->menu == NULL)
return 0;
XtVaGetValues(o->menu, XmNmenuHistory, &h, NULL);
for (i = 0; i < o->n; i++)
if (o->item[i] == h)
return i;
return 0;
}
static void
OptSet(Opt *o, int v)
{
if (v < 0 || v >= o->n)
v = 0;
XtVaSetValues(o->menu, XmNmenuHistory, o->item[v], NULL);
}
/* an option menu of LABELS; the callback gets the item's index as its data */
static Widget
OptMenu(Widget parent, const char *name, const char *const *labels, int n,
int cur, XtCallbackProc cb, Opt *o)
{
Arg a[2];
Widget pd;
int i;
XtSetArg(a[0], XmNvisibleItemCount, n < 12 ? n : 12);
o->menu = XmCreateOptionMenu(parent, (char *) name, a, 1);
pd = XmCreatePulldownMenu(o->menu, "optMenu", NULL, 0);
o->n = n < 16 ? n : 16;
for (i = 0; i < o->n; i++) {
XmString s = XmStringCreateLocalized((char *) labels[i]);
o->item[i] = XtVaCreateManagedWidget("optItem",
xmPushButtonGadgetClass, pd, XmNlabelString, s,
XmNuserData, (XtPointer) (long) i, NULL);
XmStringFree(s);
if (cb != NULL)
XtAddCallback(o->item[i], XmNactivateCallback, cb,
(XtPointer) (long) i);
}
XtVaSetValues(o->menu, XmNsubMenuId, pd, NULL);
XtManageChild(o->menu);
OptSet(o, cur);
return o->menu;
}
/* ---- the palette, its strip and the highlight colour -------------------- */
static Opt palOpt, hiOpt;
static Widget palStrip[8];
static Pixmap palSwatch[8];
static char palHex[8][40];
static int palN;
/* "#RRRRGGGGBBBB" reads as "#RRGGBB" in a menu; a name stays a name */
static void
ShortColour(const char *in, char *out, size_t len)
{
if (in[0] == '#' && strlen(in) == 13)
(void)snprintf(out, len, "#%c%c%c%c%c%c", in[1], in[2],
in[5], in[6], in[9], in[10]);
else
(void)snprintf(out, len, "%s", in);
}
/* a small field of one colour; None when the name cannot be parsed */
static Pixmap
ColourChip(Widget w, const char *colour, int size)
{
Display *dpy = XtDisplay(w);
Screen *scr = XtScreen(w);
XColor c;
Pixmap pm;
GC gc;
if (!XParseColor(dpy, DefaultColormapOfScreen(scr), colour, &c) ||
!XAllocColor(dpy, DefaultColormapOfScreen(scr), &c))
return None;
pm = XCreatePixmap(dpy, RootWindowOfScreen(scr), (unsigned) size,
(unsigned) size, (unsigned) DefaultDepthOfScreen(scr));
gc = XCreateGC(dpy, pm, 0, NULL);
XSetForeground(dpy, gc, c.pixel);
XFillRectangle(dpy, pm, gc, 0, 0, (unsigned) size, (unsigned) size);
XFreeGC(dpy, gc);
return pm;
}
/* the colours of the palette in use: the strip and the highlight menu follow
* it (the reference offers the palette's colours there) */
static void
PaletteRead(Widget w, const char *path)
{
FILE *fp = fopen(path, "r");
char line[64];
int n = 0, i;
for (i = 0; i < 8; i++) {
palHex[i][0] = '\0';
if (palSwatch[i] != None) {
XFreePixmap(XtDisplay(w), palSwatch[i]);
palSwatch[i] = None;
XtVaSetValues(palStrip[i], XmNlabelType, XmSTRING,
XmNlabelString, XmStringCreateLocalized((char *)""),
XmNlabelPixmap, None, NULL);
}
}
if (fp != NULL) {
while (n < 8 && fgets(line, sizeof line, fp) != NULL) {
Pixmap pm;
line[strcspn(line, " \t\r\n")] = '\0';
if (line[0] == '\0')
continue;
(void)snprintf(palHex[n], sizeof palHex[n], "%s",
line);
pm = ColourChip(w, line, SWATCH);
palSwatch[n] = pm;
if (pm != None) {
XmString s = XmStringCreateLocalized(
(char *) "");
XtVaSetValues(palStrip[n], XmNlabelType,
XmPIXMAP, XmNlabelPixmap, pm,
XmNlabelString, s, NULL);
XmStringFree(s);
}
n++;
}
fclose(fp);
}
palN = n;
for (i = 0; i < hiOpt.n; i++) {
char shown[64];
XmString s;
Pixmap pm = None;
if (i < palN) {
ShortColour(palHex[i], shown, sizeof shown);
pm = ColourChip(w, palHex[i], SWATCH - 2);
XtSetSensitive(hiOpt.item[i], True);
} else {
(void)snprintf(shown, sizeof shown, "-");
XtSetSensitive(hiOpt.item[i], False);
}
s = XmStringCreateLocalized(shown);
XtVaSetValues(hiOpt.item[i], XmNlabelString, s,
XmNlabelType, pm != None ? XmPIXMAP_AND_STRING : XmSTRING,
XmNlabelPixmap, pm, XmNpixmapPlacement, XmPIXMAP_LEFT, NULL);
XmStringFree(s);
}
}
/* the chosen palette: dtstyle's line (ColorMain.c), screen 0 as the colour
* server's; the session's colours change at the next login */
static void
PaletteChosen(Widget w, XtPointer data, XtPointer call)
{
int i = (int) (long) data;
char res[160];
if (i < 0 || i >= npal)
return;
(void) call;
(void) w;
snprintf(res, sizeof res, "*%d*ColorPalette: %s.dp\n",
XScreenNumberOfScreen(XtScreen(appNote)), pal[i].name);
_DtAddToResource(XtDisplay(appNote), res);
snprintf(res, sizeof res, "%s.dp", pal[i].name);
ThemeSync(res);
snprintf(res, sizeof res, "%s: GTK programs follow now, MCDE's at the "
"next login.", pal[i].name);
SetText(palNote, res);
snprintf(res, sizeof res, "In use: %s.", pal[i].name);
SetText(appNote, res);
XtSetSensitive(appLogout, True);
PaletteRead(appNote, pal[i].path);
}
/* the highlight colour: Motif's focus highlight and the select colour of the
* widgets that name one, for programs started after this */
/* set the chosen pointer: dtcursor -set NAME (sets the root window's
* cursor and keeps the name in ~/.dt/cursor) */
static void
CursorChosen(Widget w, XtPointer data, XtPointer call)
{
int i = (int) (long) data;
const char *home = getenv("HOME");
char path[600];
if (i < 0 || i >= ncursors)
return;
if (home != NULL) {
FILE *f;
snprintf(path, sizeof path, "%s/.dt/cursor", home);
if ((f = fopen(path, "w")) != NULL) {
fprintf(f, "%s\n", cursorNames[i]);
fclose(f);
}
}
if (fork() == 0) {
setsid();
execlp("dtcursor", "dtcursor", "-set", cursorNames[i],
(char *) NULL);
_exit(127);
}
(void) w;
(void) call;
}
static void
HighlightChosen(Widget w, XtPointer data, XtPointer call)
{
int i = (int) (long) data;
char res[200], note[160];
(void) w;
(void) call;
if (i < 0 || i >= palN)
return;
(void)snprintf(res, sizeof res, "*highlightColor: %s\n"
"*selectColor: %s\n", palHex[i], palHex[i]);
_DtAddToResource(XtDisplay(appNote), res);
ShortColour(palHex[i], note, sizeof note);
(void)snprintf(res, sizeof res, "Highlight %s: programs started from "
"now on use it.", note);
SetText(hiNote, res);
}
static void
LogOutNow(Widget w, XtPointer data, XtPointer call)
{
(void) w;
(void) data;
(void) call;
Spawn("dtaction ExitSession");
}
/* ---- the title bar double click (dtwm) ---------------------------------- */
/* libDtSvc (DtUtil1/WmRestart.c) has no header for it; input.c declares it
* the same way */
int _DtWmRestartNoConfirm(Display *display, Window root);
static Widget tbToggle, tbNote;
static void
TitleApply(Widget w, XtPointer data, XtPointer call)
{
Display *dpy = XtDisplay(tbToggle);
char res[96];
(void) w;
(void) data;
(void) call;
(void)snprintf(res, sizeof res, "Dtwm*mcdeTitleBarDoubleClick: %s\n",
XmToggleButtonGetState(tbToggle) ? "minimize" : "none");
_DtAddToResource(dpy, res);
(void) _DtWmRestartNoConfirm(dpy, DefaultRootWindow(dpy));
SetText(tbNote, "The window manager has restarted with it.");
}
static Boolean
TitleOn(Display *dpy)
{
char v[64];
ServerResource(dpy, "dtwm.mcdeTitleBarDoubleClick",
"Dtwm.McdeTitleBarDoubleClick", "none", v, sizeof v);
return strcasecmp(v, "minimize") == 0;
}
/* ---- the number of recent items ----------------------------------------- */
static Opt recOpt[3];
static const char *const recKeys[3] = { "applications", "documents",
"servers" };
static const char *const recNames[3] = { "Applications", "Documents",
"Servers" };
static const int recValues[] = { 0, 5, 10, 15, 20, 30, 50 };
#define NRECVALUES ((int) (sizeof recValues / sizeof recValues[0]))
static void
RecentFile(char *buf, size_t len)
{
const char *home = getenv("HOME");
(void)snprintf(buf, len, "%s/.dt/recent.conf", home != NULL ? home :
".");
}
static void
RecentRead(int *v)
{
char path[600], line[128];
FILE *fp;
for (int i = 0; i < 3; i++)
v[i] = 10;
RecentFile(path, sizeof path);
if ((fp = fopen(path, "r")) == NULL)
return;
while (fgets(line, sizeof line, fp) != NULL) {
int k;
line[strcspn(line, "\r\n")] = '\0';
for (k = 0; k < 3; k++) {
size_t l = strlen(recKeys[k]);
if (strncmp(line, recKeys[k], l) == 0 && line[l] == '=')
v[k] = atoi(line + l + 1);
}
}
fclose(fp);
}
static void
RecentWrite(void)
{
char path[600];
FILE *fp;
int i;
RecentFile(path, sizeof path);
if ((fp = fopen(path, "w")) == NULL)
return;
for (i = 0; i < 3; i++)
fprintf(fp, "%s=%d\n", recKeys[i],
recValues[OptValue(&recOpt[i])]);
fclose(fp);
}
static void
RecentChanged(Widget w, XtPointer data, XtPointer call)
{
(void) w;
(void) data;
(void) call;
RecentWrite();
}
/* ---- font smoothing ----------------------------------------------------- */
static Opt aaOpt;
static Widget aaSize, aaNote;
static void
AaFile(char *buf, size_t len)
{
const char *home = getenv("HOME");
(void)snprintf(buf, len, "%s/.config/fontconfig/conf.d/"
"60-mcde-antialias.conf", home != NULL ? home : ".");
}
/* ~/.config/fontconfig/conf.d/60-mcde-antialias.conf, the rule fontconfig
* (and with it Xft, GTK, Qt and everything else) follows for new programs */
static void
AaWrite(int off, int minSize)
{
char path[700], dir[700], tmp[740];
FILE *fp;
char *p;
AaFile(path, sizeof path);
if (off == 0 && minSize <= 0) {
(void)remove(path);
return;
}
/* the folders from the top down: conf.d needs fontconfig, that .config */
(void)snprintf(dir, sizeof dir, "%s", path);
if ((p = strrchr(dir, '/')) != NULL)
*p = '\0';
else
dir[0] = '\0';
for (p = dir + 1; p != NULL && *p != '\0'; p++)
if (*p == '/') {
*p = '\0';
(void)mkdir(dir, 0755);
*p = '/';
}
if (dir[0] != '\0')
(void)mkdir(dir, 0755);
(void)snprintf(tmp, sizeof tmp, "%s.new", path);
if ((fp = fopen(tmp, "w")) == NULL)
return;
fputs("<?xml version=\"1.0\"?>\n"
"<!DOCTYPE fontconfig SYSTEM \"fonts.dtd\">\n"
"<!-- Made by dtsystemsettings: Appearance, font smoothing. -->\n"
"<fontconfig>\n"
" <match target=\"font\">\n", fp);
if (off == 0 && minSize > 0)
fprintf(fp, " <test compare=\"less_eq\" name=\"size\">"
"<double>%d</double></test>\n", minSize);
fputs(" <edit name=\"antialias\" mode=\"assign\">"
"<bool>false</bool></edit>\n"
" </match>\n"
"</fontconfig>\n", fp);
fclose(fp);
(void)rename(tmp, path);
}
/* the state the file describes: 2 off, 0 an upper size, -1 no rule */
static int
AaRead(int *minSize)
{
char path[700], line[256];
FILE *fp;
int off = 0, min = -1;
*minSize = 0;
AaFile(path, sizeof path);
if ((fp = fopen(path, "r")) == NULL)
return -1;
while (fgets(line, sizeof line, fp) != NULL) {
char *p;
if (strstr(line, "name=\"size\"") != NULL)
min = 0;
if (min == 0 && (p = strstr(line, "<double>")) != NULL)
min = atoi(p + 8);
}
fclose(fp);
if (min >= 0) {
*minSize = min;
return 0;
}
off = 1;
return 2;
}
static void
AaApply(Widget w, XtPointer data, XtPointer call)
{
char *text = XmTextFieldGetString(aaSize);
int min = text != NULL ? atoi(text) : 0;
int mode = OptValue(&aaOpt);
(void) w;
(void) data;
(void) call;
if (min < 0 || min > 72)
min = 0;
AaWrite(mode == 2 ? 1 : 0, mode == 2 ? 0 : min);
SetText(aaNote, mode == 2 ? "Smoothing is off for new programs."
: min > 0 ? "Sizes up to this one are drawn without smoothing in "
"new programs." : "The programs decide themselves.");
XtFree(text);
}
/* ---- the pane ----------------------------------------------------------- */
Widget
MakeAppearance(Widget parent)
{
Display *dpy = XtDisplay(parent);
Widget sw = XtVaCreateManagedWidget("appearanceScroll",
xmScrolledWindowWidgetClass, parent,
XmNscrollingPolicy, XmAUTOMATIC, XmNwidth, 760, XmNheight, 640,
NULL);
Widget box = XtVaCreateManagedWidget("appearance",
xmRowColumnWidgetClass, sw, XmNspacing, 8, NULL);
Widget row, b;
char dir[512], current[64], name[64], class[64], buf[128];
const char *home = getenv("HOME");
int i, scr = XScreenNumberOfScreen(XtScreen(parent));
char *palNames[MAX_PALETTES];
XmString s;
npal = 0;
if (home != NULL) {
snprintf(dir, sizeof dir, "%s/.dt/palettes", home);
ScanPalettes(dir);
}
ScanPalettes(CDE_CONFIGURATION_TOP "/palettes");
ScanPalettes(CDE_INSTALLATION_TOP "/palettes");
qsort(pal, (size_t) npal, sizeof pal[0], PaletteCompare);
ncursors = 0;
ScanCursors(CDE_INSTALLATION_TOP "/share/cursors");
qsort(cursorNames, (size_t) ncursors, sizeof cursorNames[0],
CursorCompare);
nthemes = 0;
ScanCursorThemes(CDE_INSTALLATION_TOP "/share/icons");
qsort(themeNames, (size_t) nthemes, sizeof themeNames[0],
ThemeCompare);
/* what the colour server reads: Dtsession.<screen>.ColorPalette */
snprintf(name, sizeof name, "dtsession.%d.colorPalette", scr);
snprintf(class, sizeof class, "Dtsession.%d.ColorPalette", scr);
ServerResource(dpy, name, class, "Default.dp", current, sizeof current);
if (strlen(current) > 3 &&
strcmp(current + strlen(current) - 3, ".dp") == 0)
current[strlen(current) - 3] = '\0';
/* 1: the palette and the highlight colour */
row = Row(box, "Appearance:");
if (npal > MAX_PALETTES)
npal = MAX_PALETTES;
for (i = 0; i < npal; i++)
palNames[i] = pal[i].name;
{
int cur = 0;
for (i = 0; i < npal; i++)
if (strcmp(pal[i].name, current) == 0)
cur = i;
(void) OptMenu(row, "palette", (const char *const *) palNames,
npal, cur, PaletteChosen, &palOpt);
}
(void) Note(box, "For the overall look of buttons, menus and "
"windows.");
palNote = Note(box, "");
row = Row(box, "");
row = XtVaCreateManagedWidget("paletteStrip", xmRowColumnWidgetClass,
row, XmNorientation, XmHORIZONTAL, XmNspacing, 2,
XmNmarginWidth, 0, XmNmarginHeight, 0, NULL);
for (i = 0; i < 8; i++) {
s = XmStringCreateLocalized((char *) "");
palStrip[i] = XtVaCreateManagedWidget("chip",
xmLabelWidgetClass, row, XmNlabelString, s,
XmNlabelType, XmSTRING, XmNmarginWidth, 0,
XmNmarginHeight, 0, NULL);
XmStringFree(s);
palSwatch[i] = None;
}
row = Row(box, "Highlight Color:");
{
static const char *const dummy[] = { "-", "-", "-", "-", "-",
"-", "-", "-" };
(void) OptMenu(row, "highlight", dummy, 8, 0, HighlightChosen,
&hiOpt);
}
(void) Note(box, "For selected text.");
hiNote = Note(box, "");
/* the Xcursor theme: Solaris, IRIX, ... (GTK, Qt, Firefox) */
if (nthemes > 0) {
char saved[128];
int cur = 0;
FILE *f;
saved[0] = '\0';
if (home != NULL) {
snprintf(dir, sizeof dir, "%s/.dt/cursor-theme", home);
if ((f = fopen(dir, "r")) != NULL) {
if (fgets(saved, sizeof saved, f) != NULL) {
char *nl = strchr(saved, '\n');
if (nl != NULL)
*nl = '\0';
}
fclose(f);
}
}
for (i = 0; i < nthemes; i++)
if (strcmp(themeNames[i], saved) == 0)
cur = i;
row = Row(box, "Cursor theme:");
(void) OptMenu(row, "cursortheme",
(const char *const *) themeNames, nthemes, cur,
CursorThemeChosen, &themeOpt);
(void) Note(box, "For GTK, Qt and Firefox (Xcursor); the "
"pointer below is the Motif one.");
}
/* the pointer: the Solaris cursors of share/cursors (dtcursor) */
if (ncursors > 0) {
char saved[128];
int cur = 0;
FILE *f;
saved[0] = '\0';
if (home != NULL) {
snprintf(dir, sizeof dir, "%s/.dt/cursor", home);
if ((f = fopen(dir, "r")) != NULL) {
if (fgets(saved, sizeof saved, f) != NULL) {
char *nl = strchr(saved, '\n');
if (nl != NULL)
*nl = '\0';
}
fclose(f);
}
}
for (i = 0; i < ncursors; i++)
if (strcmp(cursorNames[i], saved) == 0)
cur = i;
row = Row(box, "Pointer:");
(void) OptMenu(row, "cursor",
(const char *const *) cursorNames, ncursors, cur,
CursorChosen, &cursorOpt);
(void) Note(box, "The pointer of the desktop (Solaris cursors).");
}
(void) Sep(box);
/* 2: the scroll bars and the title bar */
(void) Heading(box, "Scroll bars:");
(void) Note(box, "Motif pages a list when the scroll bar is clicked,\n"
"and jumps to the place with the middle button. Arrow buttons at\n"
"both ends and smooth scrolling are not part of Motif.");
row = Row(box, "");
tbToggle = XtVaCreateManagedWidget("Minimize when double-clicking a "
"window title bar", xmToggleButtonWidgetClass, row,
XmNset, TitleOn(dpy) ? XmSET : XmUNSET, NULL);
XtVaSetValues(tbToggle, XmNalignment, XmALIGNMENT_BEGINNING, NULL);
row = Row(box, "");
(void) Button(row, "Apply (restarts the window manager)", TitleApply,
NULL);
tbNote = Note(box, "");
(void) Sep(box);
/* 3: the number of recent items */
row = Row(box, "Number of Recent Items:");
for (i = 0; i < 3; i++) {
static const char *const values[] = { "0", "5", "10", "15",
"20", "30", "50" };
if (i > 0)
(void) Text(row, "recentGap", " ");
(void) Text(row, "recentName", recNames[i]);
(void) OptMenu(row, "recent", values, NRECVALUES, 2,
RecentChanged, &recOpt[i]);
}
(void) Note(box, "Documents is the list in the bar's M menu, Servers "
"the addresses\nin Connect to Server; 0 leaves the list empty. "
"Applications has no\nlist of its own yet.");
{
int v[3];
RecentRead(v);
for (i = 0; i < 3; i++) {
int k;
for (k = 0; k < NRECVALUES; k++)
if (recValues[k] == v[i])
OptSet(&recOpt[i], k);
}
}
(void) Sep(box);
/* 4: font smoothing */
row = Row(box, "Font smoothing style:");
{
static const char *const styles[] = { "Automatic - best for the "
"main display", "On", "Off" };
int min = 0, state = AaRead(&min);
int cur = state == 2 ? 2 : 0;
(void) OptMenu(row, "smoothing", styles, 3, cur, NULL, &aaOpt);
XtAddCallback(aaOpt.item[0], XmNactivateCallback, AaApply, NULL);
XtAddCallback(aaOpt.item[1], XmNactivateCallback, AaApply, NULL);
XtAddCallback(aaOpt.item[2], XmNactivateCallback, AaApply, NULL);
row = Row(box, "Turn off smoothing below");
aaSize = XtVaCreateManagedWidget("smoothingSize",
xmTextFieldWidgetClass, row, XmNcolumns, 3, NULL);
(void)snprintf(buf, sizeof buf, "%d", min > 0 ? min : 8);
XmTextFieldSetString(aaSize, buf);
(void) Text(row, "andSmaller", "and smaller.");
b = Button(row, "Apply", AaApply, NULL);
XtSetSensitive(b, True);
aaNote = Note(box, "");
}
(void) Sep(box);
/* the fonts of every window (MakeFonts below) */
(void) Heading(box, "Fonts:");
{
Widget frow = Row(box, "");
Widget fb = MakeFonts(frow);
XtManageChild(fb);
}
/* the palette of the session: the strip and the highlight colours */
{
int cur = 0;
for (i = 0; i < npal; i++)
if (strcmp(pal[i].name, current) == 0)
cur = i;
if (npal > 0)
PaletteRead(box, pal[cur].path);
}
appNote = Text(box, "note", "");
{
char text[128];
snprintf(text, sizeof text, "In use: %s.", current);
SetText(appNote, text);
}
appLogout = PaneButton(box, "Log Out Now...", LogOutNow, NULL);
XtSetSensitive(appLogout, False);
return sw;
}
/* ---- Fonts -------------------------------------------------------------- */
#define MAX_FAMILIES 512
static Widget fontList, fontSize, fontPreview;
static char *families[MAX_FAMILIES];
static int nfamilies;
static int
StringCompare(const void *a, const void *b)
{
return strcmp(*(char *const *) a, *(char *const *) b);
}
static void
ListFamilies(Display *dpy, int scr)
{
XftFontSet *fs = XftListFonts(dpy, scr, NULL, XFT_FAMILY, NULL);
int i, j;
nfamilies = 0;
if (fs == NULL)
return;
for (i = 0; i < fs->nfont && nfamilies < MAX_FAMILIES; i++) {
FcChar8 *f = NULL;
if (FcPatternGetString(fs->fonts[i], FC_FAMILY, 0, &f) !=
FcResultMatch || f == NULL || f[0] == '.')
continue;
families[nfamilies++] = strdup((const char *) f);
}
XftFontSetDestroy(fs);
qsort(families, (size_t) nfamilies, sizeof families[0], StringCompare);
for (i = j = 0; i < nfamilies; i++) {
if (j > 0 && strcmp(families[j - 1], families[i]) == 0) {
free(families[i]);
continue;
}
families[j++] = families[i];
}
nfamilies = j;
}
static void
FontsGone(Widget w, XtPointer data, XtPointer call)
{
int i;
(void) w;
(void) data;
(void) call;
for (i = 0; i < nfamilies; i++)
free(families[i]);
nfamilies = 0;
}
/* the chosen family, or NULL */
static const char *
Family(void)
{
int *pos = NULL, n = 0;
const char *f = NULL;
if (XmListGetSelectedPos(fontList, &pos, &n) && n > 0 &&
pos[0] >= 1 && pos[0] <= nfamilies)
f = families[pos[0] - 1];
XtFree((char *) pos);
return f;
}
/* the preview in the chosen font; its size into SIZE */
static const char *
Preview(int *size)
{
const char *f = Family();
XmRendition r;
XmRenderTable rt;
Arg a[4];
int n = 0;
*size = 10;
if (f == NULL)
return NULL;
XmScaleGetValue(fontSize, size);
XtSetArg(a[n], XmNfontType, XmFONT_IS_XFT); n++;
XtSetArg(a[n], XmNfontName, (XtArgVal) f); n++;
XtSetArg(a[n], XmNfontSize, *size); n++;
r = XmRenditionCreate(fontPreview, XmFONTLIST_DEFAULT_TAG, a, n);
rt = XmRenderTableAddRenditions(NULL, &r, 1, XmMERGE_REPLACE);
XmRenditionFree(r);
XtVaSetValues(fontPreview, XmNrenderTable, rt, NULL);
XmRenderTableFree(rt);
return f;
}
static void
FontApply(Widget w, XtPointer data, XtPointer call)
{
char res[256];
int size;
const char *f = Preview(&size);
(void) w;
(void) data;
(void) call;
if (f == NULL)
return;
/* sys.resources' lines, with the new values */
snprintf(res, sizeof res, "*mcde.fontName: %s\n*mcde.fontSize: %d\n",
f, size);
_DtAddToResource(XtDisplay(fontList), res);
ThemeSync(NULL);
}
Widget
MakeFonts(Widget parent)
{
Display *dpy = XtDisplay(parent);
Widget box = XtVaCreateWidget("fonts", xmRowColumnWidgetClass, parent,
XmNspacing, 6, NULL);
char name[128], size[16];
int i, sel = 0;
Arg a[4];
int n = 0;
XtAddCallback(box, XmNdestroyCallback, FontsGone, NULL);
ServerResource(dpy, "dtsystemsettings.mcde.fontName",
"Dtsystemsettings.Mcde.FontName", "Hack", name, sizeof name);
ServerResource(dpy, "dtsystemsettings.mcde.fontSize",
"Dtsystemsettings.Mcde.FontSize", "10", size, sizeof size);
ListFamilies(dpy, XScreenNumberOfScreen(XtScreen(parent)));
/* the font in use is offered even when fontconfig does not list it
* here (a session without MCDE's fonts.conf) */
for (i = 0; i < nfamilies; i++)
if (strcmp(families[i], name) == 0)
break;
if (i == nfamilies && nfamilies < MAX_FAMILIES) {
memmove(families + 1, families,
(size_t) nfamilies * sizeof families[0]);
families[0] = strdup(name);
nfamilies++;
}
(void) Text(box, "label", "The font of every window:");
XtSetArg(a[n], XmNvisibleItemCount, 6); n++;
XtSetArg(a[n], XmNselectionPolicy, XmBROWSE_SELECT); n++;
XtSetArg(a[n], XmNwidth, 320); n++;
fontList = XmCreateScrolledList(box, "families", a, n);
for (i = 0; i < nfamilies; i++) {
XmString s = XmStringCreateLocalized(families[i]);
XmListAddItemUnselected(fontList, s, 0);
XmStringFree(s);
if (strcmp(families[i], name) == 0)
sel = i + 1;
}
XtManageChild(fontList);
if (sel > 0) {
XmListSelectPos(fontList, sel, False);
XmListSetPos(fontList, sel > 4 ? sel - 4 : 1);
}
XtAddCallback(fontList, XmNbrowseSelectionCallback, FontApply, NULL);
(void) Text(box, "label", "Size (points):");
fontSize = XtVaCreateManagedWidget("size", xmScaleWidgetClass, box,
XmNorientation, XmHORIZONTAL, XmNminimum, 7, XmNmaximum, 20,
XmNvalue, atoi(size) >= 7 && atoi(size) <= 20 ? atoi(size) : 10,
XmNshowValue, True, XmNscaleWidth, 280, NULL);
XtAddCallback(fontSize, XmNvalueChangedCallback, FontApply, NULL);
fontPreview = Text(box, "preview",
"The quick brown fox jumps over the lazy dog. 0123456789");
(void) Text(box, "note",
"Programs started from now on use it; the others when they start "
"again.");
{
int sz;
(void) Preview(&sz);
}
return box;
}