Files
lotherk e3d8227249 MCDE: a backdrop per workspace (t0290)
dtsystemsettings has a Workspace menu on the Desktop page: This
Workspace (the active one) or one of the named workspaces, read from
DtWsmGetWorkspaceList.  A chosen backdrop goes to that workspace: dtwm
learned f.change_backdrop_ws INDEX PATH PIXMAP STYLE (the same parse as
f.change_backdrop, with the workspace index first) and
McdeBackdropFromFile on pSD->pWS[INDEX]; SetNewBackdrop keeps the choice
with SaveWorkspaceResources, so dtsession carries it to the next login
and ChangeToWorkspace shows it.  Measured under Xvfb: the menu lists
This Workspace, One, Two, Three, Four; Two + Ankh.bm printed
'dtwm: backdrop ws=1 .../backdrops/Ankh.bm style=0'.  WmMain.c now
includes WmFunction.h (the MCDE prototypes were implicit).
2026-11-16 10:05:40 +00:00

1556 lines
44 KiB
C

/*
* desktop.c -- dtsystemsettings: the backdrop and the screen saver
*
* License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
*
* One pane, two pages, chosen by two buttons at the top: Desktop and Screen
* Saver.
*
* Desktop: a preview of the backdrop in use and its name; on the left the
* places pictures come from -- CDE's backdrops, the Pictures folder of the
* home, folders the user added (~/.dt/backdrop-folders, one per line) and
* "Choose Folder..."; on the right the pictures of the place, small. A click
* makes one the backdrop: dtwm loads the file itself (the request
* "f.change_backdrop PATH 0 STYLE", programs/dtwm/WmSlideshow.c), in the
* style chosen below (fill, fit, centre, tile). "Change picture" makes the
* place a slideshow: "f.mcde_slideshow MINUTES RANDOM STYLE FOLDER" to dtwm
* now, and the resource Dtwm*mcdeSlideshow, which dtsession keeps with the
* other resources, for the next login.
*
* The small pictures are made one at a time while the pane is idle
* (XtAppAddWorkProc), so a folder of large photographs does not hold the
* window: each is loaded with McdeImageGetPixmap (libDtSvc) and scaled with
* Xrender to
* cover its cell.
*
* Screen Saver: the savers of the session ($DTSCREENSAVERLIST, set by
* Xsession), one running in a preview as dtstyle shows it (_DtSaverStart);
* the time until it starts and whether it asks for the password; both go to
* dtsession as dtstyle sends them (programs/dtstyle/Protocol.c,
* SmNewSaverSettings: _DtSetSmState, _DtSetSmSaver).
*
* C99, POSIX, Xt and Motif only (ext/src/mcde/AGENTS.md); Xrender as dtwm
* uses it.
*/
#define _POSIX_C_SOURCE 200809L
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/stat.h>
#include <X11/Intrinsic.h>
#include <X11/Xatom.h>
#include <X11/extensions/Xrender.h>
#include <Xm/Xm.h>
#include <Xm/DrawingA.h>
#include <Xm/FileSB.h>
#include <Xm/Form.h>
#include <Xm/Frame.h>
#include <Xm/Label.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/Action.h>
#include <Dt/Wsm.h>
#include <Dt/WsmP.h>
#include <Dt/SessionM.h>
#include <Dt/SaverP.h>
#include <Dt/DtP.h>
#include <Mcde/Image.h>
#include "ui.h"
#define THUMB_W 80
#define THUMB_H 50
#define PREVIEW_W 128
#define PREVIEW_H 80
#define MAX_PLACES 32
#define MAX_PICTURES 512
static Widget pageDesktop, pageSaver, tabDesktop, tabSaver;
/* the workspace the next backdrop choice goes to; -1 is the active one */
#define MAX_WORKSPACES 16
static char *wsNames[MAX_WORKSPACES + 1];
static Widget wsButtons[MAX_WORKSPACES + 1];
static int wsCount;
static int targetWorkspace = -1;
/* ---- pictures, small ---------------------------------------------------- */
static int
IsPicture(const char *name)
{
static const char *const ext[] = {
".jpg", ".jpeg", ".png", ".xpm", ".pm", ".xbm", ".bm", NULL
};
const char *dot = strrchr(name, '.');
int i;
if (name[0] == '.' || dot == NULL)
return 0;
for (i = 0; ext[i] != NULL; i++)
if (strcasecmp(dot, ext[i]) == 0)
return 1;
return 0;
}
/* a pattern of CDE's (.pm, .bm, .xbm) is tiled, a picture covers */
static int
IsPattern(const char *path)
{
const char *dot = strrchr(path, '.');
return dot != NULL && (strcasecmp(dot, ".pm") == 0 ||
strcasecmp(dot, ".bm") == 0 || strcasecmp(dot, ".xbm") == 0);
}
/* PATH as a W x H pixmap: a small pattern tiled, a picture scaled to cover
* it and cut to the middle. None when it cannot be read. */
static Pixmap
Small(Widget w, const char *path, int width, int height)
{
Display *dpy = XtDisplay(w);
Screen *scr = XtScreen(w);
Pixel fg = BlackPixelOfScreen(scr), bg = WhitePixelOfScreen(scr);
Pixmap src, dst;
Window root;
int x, y;
unsigned int sw, sh, bw, depth;
GC gc;
src = McdeImageGetPixmap(scr, path, fg, bg);
if (src == XmUNSPECIFIED_PIXMAP)
return None;
XGetGeometry(dpy, src, &root, &x, &y, &sw, &sh, &bw, &depth);
dst = XCreatePixmap(dpy, RootWindowOfScreen(scr), (unsigned) width,
(unsigned) height, (unsigned) DefaultDepthOfScreen(scr));
gc = XCreateGC(dpy, dst, 0, NULL);
if (IsPattern(path) || (sw <= (unsigned) width &&
sh <= (unsigned) height)) {
XSetTile(dpy, gc, src);
XSetFillStyle(dpy, gc, FillTiled);
XFillRectangle(dpy, dst, gc, 0, 0, (unsigned) width,
(unsigned) height);
} else {
XRenderPictFormat *fmt = XRenderFindVisualFormat(dpy,
DefaultVisualOfScreen(scr));
XRenderPictureAttributes pa;
Picture ps, pd;
double s = (double) sw / width < (double) sh / height ?
(double) sw / width : (double) sh / height;
XTransform xf = {{
{ XDoubleToFixed(s), XDoubleToFixed(0), XDoubleToFixed(0) },
{ XDoubleToFixed(0), XDoubleToFixed(s), XDoubleToFixed(0) },
{ XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(1) }
}};
memset(&pa, 0, sizeof pa);
ps = XRenderCreatePicture(dpy, src, fmt, 0, &pa);
pd = XRenderCreatePicture(dpy, dst, fmt, 0, &pa);
XRenderSetPictureTransform(dpy, ps, &xf);
XRenderSetPictureFilter(dpy, ps, FilterBilinear, NULL, 0);
/* the source is placed in the destination's space: the middle */
XRenderComposite(dpy, PictOpSrc, ps, None, pd,
(int) ((sw / s - width) / 2), (int) ((sh / s - height) / 2),
0, 0, 0, 0, (unsigned) width, (unsigned) height);
XRenderFreePicture(dpy, ps);
XRenderFreePicture(dpy, pd);
}
XFreeGC(dpy, gc);
McdeImageFreePixmap(scr, src);
return dst;
}
/* ---- the places --------------------------------------------------------- */
typedef struct {
char label[128];
char dir[1024];
} Place;
static Place places[MAX_PLACES];
static int nplaces;
static Widget placeList;
static void
AddPlace(const char *label, const char *dir)
{
struct stat st;
int i;
if (nplaces >= MAX_PLACES || stat(dir, &st) != 0 || !S_ISDIR(st.st_mode))
return;
for (i = 0; i < nplaces; i++)
if (strcmp(places[i].dir, dir) == 0)
return;
snprintf(places[nplaces].label, sizeof places[nplaces].label, "%s",
label);
snprintf(places[nplaces].dir, sizeof places[nplaces].dir, "%s", dir);
nplaces++;
}
static void
FoldersFile(char *buf, size_t len)
{
const char *home = getenv("HOME");
snprintf(buf, len, "%s/.dt/backdrop-folders", home ? home : ".");
}
static void
ReadPlaces(void)
{
const char *home = getenv("HOME");
char path[1100], line[1100];
FILE *fp;
nplaces = 0;
AddPlace("Backdrops", CDE_INSTALLATION_TOP "/backdrops");
if (home != NULL) {
snprintf(path, sizeof path, "%s/.dt/backdrops", home);
AddPlace("My Backdrops", path);
snprintf(path, sizeof path, "%s/Pictures", home);
AddPlace("Pictures", path);
}
FoldersFile(path, sizeof path);
if ((fp = fopen(path, "r")) != NULL) {
while (fgets(line, sizeof line, fp) != NULL) {
const char *base;
line[strcspn(line, "\r\n")] = '\0';
if (line[0] != '/')
continue;
base = strrchr(line, '/');
AddPlace(base[1] != '\0' ? base + 1 : line, line);
}
fclose(fp);
}
}
static void
FillPlaceList(void)
{
int i;
XmString s;
XmListDeleteAllItems(placeList);
for (i = 0; i < nplaces; i++) {
s = XmStringCreateLocalized(places[i].label);
XmListAddItemUnselected(placeList, s, 0);
XmStringFree(s);
}
s = XmStringCreateLocalized("Choose Folder...");
XmListAddItemUnselected(placeList, s, 0);
XmStringFree(s);
}
/* ---- the pictures of a place -------------------------------------------- */
static Pixmap previewPixmap;
static Widget grid, preview, previewName, styleMenu, styleButtons[4];
static Widget changeToggle, intervalMenu, intervalButtons[5], randomToggle;
static char *pictures[MAX_PICTURES];
static Widget cells[MAX_PICTURES];
static int npictures, nextSmall, place = -1, style = DtWSM_BACKDROP_IMAGETYPE_FILL;
static XtWorkProcId smallWork;
static Pixmap blank, blankPreview;
static const int styles[4] = {
DtWSM_BACKDROP_IMAGETYPE_FILL, DtWSM_BACKDROP_IMAGETYPE_FIT,
DtWSM_BACKDROP_IMAGETYPE_CENTER, DtWSM_BACKDROP_IMAGETYPE_TILED
};
static const int intervals[5] = { 5, 15, 30, 60, 1440 };
static int
NameCompare(const void *a, const void *b)
{
return strcasecmp(*(char *const *) a, *(char *const *) b);
}
static void PictureChosen(Widget, XtPointer, XtPointer);
/* one small picture each time Xt is idle; True when all are made */
static Boolean
MakeSmall(XtPointer data)
{
char path[1400];
Pixmap pm;
(void) data;
if (nextSmall >= npictures) {
smallWork = 0;
return True;
}
snprintf(path, sizeof path, "%s/%s", places[place].dir,
pictures[nextSmall]);
pm = Small(grid, path, THUMB_W, THUMB_H);
/* the cell is made with its picture: Motif takes a label's pixmap
* reliably only when the label is created (a pixmap set later was not
* drawn, measured) */
cells[nextSmall] = XtVaCreateManagedWidget("picture",
xmToggleButtonWidgetClass, grid,
XmNlabelType, XmPIXMAP, XmNlabelPixmap, pm != None ? pm : blank,
XmNindicatorOn, XmINDICATOR_NONE, XmNshadowThickness, 2, NULL);
XtAddCallback(cells[nextSmall], XmNvalueChangedCallback, PictureChosen,
(XtPointer) (size_t) nextSmall);
nextSmall++;
return False;
}
static void
ClearPictures(void)
{
int i;
if (smallWork != 0) {
XtRemoveWorkProc(smallWork);
smallWork = 0;
}
for (i = 0; i < npictures; i++) {
if (i < nextSmall) {
Pixmap pm = None;
XtVaGetValues(cells[i], XmNlabelPixmap, &pm, NULL);
XtDestroyWidget(cells[i]);
if (pm != None && pm != blank &&
pm != XmUNSPECIFIED_PIXMAP)
XFreePixmap(XtDisplay(grid), pm);
}
free(pictures[i]);
}
npictures = nextSmall = 0;
}
static void
PreviewExpose(Widget w, XtPointer data, XtPointer call)
{
GC gc;
(void) data;
(void) call;
if (!XtIsRealized(w))
return;
gc = XCreateGC(XtDisplay(w), XtWindow(w), 0, NULL);
XCopyArea(XtDisplay(w), previewPixmap != None ? previewPixmap :
blankPreview, XtWindow(w), gc, 0, 0, PREVIEW_W, PREVIEW_H, 0, 0);
XFreeGC(XtDisplay(w), gc);
}
static void
SetPreview(const char *path, const char *name)
{
Pixmap pm = path != NULL ? Small(preview, path, PREVIEW_W, PREVIEW_H) :
None;
if (previewPixmap != None)
XFreePixmap(XtDisplay(preview), previewPixmap);
previewPixmap = pm;
PreviewExpose(preview, NULL, NULL);
SetText(previewName, name);
}
static void
SetStyle(int s)
{
int i;
style = s;
for (i = 0; i < 4; i++)
if (styles[i] == s)
XtVaSetValues(styleMenu, XmNmenuHistory, styleButtons[i],
NULL);
}
static void
SendSlideshow(Display *dpy, const char *spec)
{
char req[1300], res[1300];
Window wm;
if (_DtGetMwmWindow(dpy, DefaultRootWindow(dpy), &wm) == Success) {
snprintf(req, sizeof req, "f.mcde_slideshow %s", spec);
XChangeProperty(dpy, wm,
XInternAtom(dpy, _XA_DT_WM_REQUEST, False), XA_STRING, 8,
PropModeAppend, (unsigned char *) req, (int) strlen(req) + 1);
}
snprintf(res, sizeof res, "Dtwm*mcdeSlideshow: %s\n", spec);
_DtAddToResource(dpy, res);
XFlush(dpy);
}
/* the slideshow as the controls say: on with the place, or off */
static void
Slideshow(void)
{
Display *dpy = XtDisplay(grid);
char spec[1200];
Widget chosen = NULL;
int i, minutes = 30;
if (!XmToggleButtonGetState(changeToggle) || place < 0) {
SendSlideshow(dpy, "0");
return;
}
XtVaGetValues(intervalMenu, XmNmenuHistory, &chosen, NULL);
for (i = 0; i < 5; i++)
if (intervalButtons[i] == chosen)
minutes = intervals[i];
snprintf(spec, sizeof spec, "%d %d %d %s", minutes,
XmToggleButtonGetState(randomToggle) ? 1 : 0, style,
places[place].dir);
SendSlideshow(dpy, spec);
{
char text[1300];
snprintf(text, sizeof text, "%s, every %d minutes",
places[place].label, minutes);
SetText(previewName, text);
}
}
/* append one request to dtwm's _DT_WM_REQUEST property */
static void
SendWmRequest(Display *dpy, const char *request)
{
Window wmWindow;
Atom prop = XInternAtom(dpy, "_DT_WM_REQUEST", False);
if (_DtGetMwmWindow(dpy, DefaultRootWindow(dpy), &wmWindow) !=
Success)
return;
XChangeProperty(dpy, wmWindow, prop, XA_STRING, 8, PropModeAppend,
(unsigned char *) request, (int) strlen(request) + 1);
XFlush(dpy);
}
/* the backdrop for TARGETWORKSPACE (the active one when it is -1) */
static void
ApplyBackdrop(Display *dpy, const char *path, int imageStyle)
{
if (targetWorkspace < 0) {
(void) _DtWsmChangeBackdrop(dpy, DefaultRootWindow(dpy),
(char *) path, None,
(DtWsmBackdropImageType) imageStyle);
XFlush(dpy);
} else {
char request[1600];
snprintf(request, sizeof request,
"f.change_backdrop_ws %d %s 0 %d", targetWorkspace, path,
imageStyle);
SendWmRequest(dpy, request);
}
}
/* the workspaces of this screen, by title; the first entry is the active
* one ("This Workspace") */
static void
ReadWorkspaces(Display *dpy)
{
Atom *list = NULL;
int n = 0, i;
wsCount = 0;
wsNames[0] = strdup("This Workspace");
if (DtWsmGetWorkspaceList(dpy, DefaultRootWindow(dpy), &list, &n) !=
Success || list == NULL)
return;
for (i = 0; i < n && wsCount < MAX_WORKSPACES; i++) {
DtWsmWorkspaceInfo *info = NULL;
if (DtWsmGetWorkspaceInfo(dpy, DefaultRootWindow(dpy),
list[i], &info) == Success && info != NULL) {
wsNames[wsCount + 1] = strdup(info->pchTitle != NULL ?
info->pchTitle : "Workspace");
DtWsmFreeWorkspaceInfo(info);
} else
wsNames[wsCount + 1] = strdup("Workspace");
wsCount++;
}
XFree(list);
}
static void
WorkspaceChosen(Widget w, XtPointer data, XtPointer call)
{
(void) w;
(void) call;
targetWorkspace = (int) (size_t) data - 1;
}
static void
PictureChosen(Widget w, XtPointer data, XtPointer call)
{
int i = (int) (size_t) data;
char path[1400];
Display *dpy = XtDisplay(w);
if (!((XmToggleButtonCallbackStruct *) call)->set)
return;
snprintf(path, sizeof path, "%s/%s", places[place].dir, pictures[i]);
/* a pattern is tiled; a picture is not, unless asked to be */
if (IsPattern(path))
SetStyle(DtWSM_BACKDROP_IMAGETYPE_TILED);
else if (style == DtWSM_BACKDROP_IMAGETYPE_TILED)
SetStyle(DtWSM_BACKDROP_IMAGETYPE_FILL);
if (XmToggleButtonGetState(changeToggle)) {
XmToggleButtonSetState(changeToggle, False, False);
SendSlideshow(dpy, "0");
}
ApplyBackdrop(dpy, path, style);
SetPreview(path, pictures[i]);
}
static void
ShowPlace(int p)
{
DIR *d;
struct dirent *de;
int i;
ClearPictures();
place = p;
if ((d = opendir(places[p].dir)) == NULL)
return;
while ((de = readdir(d)) != NULL && npictures < MAX_PICTURES)
if (IsPicture(de->d_name))
pictures[npictures++] = strdup(de->d_name);
closedir(d);
qsort(pictures, (size_t) npictures, sizeof pictures[0], NameCompare);
/* four to a row: a horizontal row column packed in columns takes
* XmNnumColumns as its number of rows */
XtVaSetValues(grid, XmNnumColumns, npictures > 0 ? (npictures + 3) / 4 :
1, NULL);
(void) i;
smallWork = XtAppAddWorkProc(app, MakeSmall, NULL);
}
/* "Choose Folder...": a file selection box that selects directories */
static void
FolderDone(Widget w, XtPointer data, XtPointer call)
{
XmFileSelectionBoxCallbackStruct *cb =
(XmFileSelectionBoxCallbackStruct *) call;
char *dir = NULL, path[1100];
FILE *fp;
(void) data;
if (cb->reason == XmCR_OK &&
(dir = XmStringUnparse(cb->value, NULL, XmCHARSET_TEXT,
XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL)) != NULL && dir[0] == '/') {
size_t n = strlen(dir);
while (n > 1 && dir[n - 1] == '/')
dir[--n] = '\0';
FoldersFile(path, sizeof path);
if ((fp = fopen(path, "a")) != NULL) {
fprintf(fp, "%s\n", dir);
fclose(fp);
}
ReadPlaces();
FillPlaceList();
for (n = 0; n < (size_t) nplaces; n++)
if (strcmp(places[n].dir, dir) == 0) {
XmListSelectPos(placeList, (int) n + 1, True);
break;
}
}
XtFree(dir);
XtDestroyWidget(XtParent(w));
}
static void
ChooseFolder(Widget parent)
{
Arg a[4];
int n = 0;
Widget fsb;
XmString t = XmStringCreateLocalized("Choose a Folder of Pictures");
XtSetArg(a[n], XmNfileTypeMask, XmFILE_DIRECTORY); n++;
XtSetArg(a[n], XmNdialogTitle, t); n++;
fsb = XmCreateFileSelectionDialog(parent, "chooseFolder", a, n);
XmStringFree(t);
XtAddCallback(fsb, XmNokCallback, FolderDone, NULL);
XtAddCallback(fsb, XmNcancelCallback, FolderDone, NULL);
XtUnmanageChild(XmFileSelectionBoxGetChild(fsb, XmDIALOG_HELP_BUTTON));
XtManageChild(fsb);
}
static void
PlaceChosen(Widget w, XtPointer data, XtPointer call)
{
int pos = ((XmListCallbackStruct *) call)->item_position;
(void) data;
if (pos == nplaces + 1) {
ChooseFolder(w);
return;
}
if (pos >= 1 && pos <= nplaces && pos - 1 != place) {
ShowPlace(pos - 1);
if (XmToggleButtonGetState(changeToggle))
Slideshow();
}
}
static void
StyleChosen(Widget w, XtPointer data, XtPointer call)
{
int i = (int) (size_t) data;
int k;
(void) w;
(void) call;
style = styles[i];
if (XmToggleButtonGetState(changeToggle)) {
Slideshow();
return;
}
/* the picture chosen, again, in the new style */
for (k = 0; k < nextSmall; k++)
if (XmToggleButtonGetState(cells[k])) {
char path[1400];
Display *dpy = XtDisplay(grid);
snprintf(path, sizeof path, "%s/%s", places[place].dir,
pictures[k]);
ApplyBackdrop(dpy, path, style);
break;
}
}
static void
SlideshowChanged(Widget w, XtPointer data, XtPointer call)
{
(void) w;
(void) data;
(void) call;
XtSetSensitive(intervalMenu, XmToggleButtonGetState(changeToggle));
XtSetSensitive(randomToggle, XmToggleButtonGetState(changeToggle));
Slideshow();
}
static Widget
OptionMenu(Widget parent, const char *name, const char *label,
const char *const *items, int n, Widget *buttons, XtCallbackProc cb)
{
Widget pulldown = XmCreatePulldownMenu(parent, (char *) name, NULL, 0);
XmString s = XmStringCreateLocalized((char *) label);
Arg a[2];
Widget menu;
int i;
for (i = 0; i < n; i++) {
XmString t = XmStringCreateLocalized((char *) items[i]);
buttons[i] = XtVaCreateManagedWidget("item",
xmPushButtonWidgetClass, pulldown, XmNlabelString, t, NULL);
XmStringFree(t);
if (cb != NULL)
XtAddCallback(buttons[i], XmNactivateCallback, cb,
(XtPointer) (size_t) i);
}
XtSetArg(a[0], XmNsubMenuId, pulldown);
XtSetArg(a[1], XmNlabelString, s);
menu = XmCreateOptionMenu(parent, (char *) name, a, 2);
XmStringFree(s);
XtManageChild(menu);
return menu;
}
static void
IntervalChosen(Widget w, XtPointer data, XtPointer call)
{
(void) w;
(void) data;
(void) call;
Slideshow();
}
/* what dtwm shows now: the slideshow, or the backdrop of the workspace */
static void
ReadCurrent(Display *dpy)
{
char spec[1200], folder[1100];
int minutes = 0, rnd = 0, st = style, used = 0, i;
Atom ws;
DtWsmWorkspaceInfo *info = NULL;
ServerResource(dpy, "dtwm.mcdeSlideshow", "Dtwm.McdeSlideshow", "0",
spec, sizeof spec);
if (sscanf(spec, "%d %d %d %n", &minutes, &rnd, &st, &used) >= 3 &&
minutes > 0 && used > 0) {
snprintf(folder, sizeof folder, "%s", spec + used);
XmToggleButtonSetState(changeToggle, True, False);
XmToggleButtonSetState(randomToggle, rnd != 0, False);
for (i = 0; i < 5; i++)
if (intervals[i] == minutes)
XtVaSetValues(intervalMenu, XmNmenuHistory,
intervalButtons[i], NULL);
SetStyle(st);
for (i = 0; i < nplaces; i++)
if (strcmp(places[i].dir, folder) == 0) {
XmListSelectPos(placeList, i + 1, False);
ShowPlace(i);
Slideshow(); /* the name in the preview */
return;
}
}
XtSetSensitive(intervalMenu, False);
XtSetSensitive(randomToggle, False);
if (DtWsmGetCurrentWorkspace(dpy, DefaultRootWindow(dpy), &ws) ==
Success && DtWsmGetWorkspaceInfo(dpy, DefaultRootWindow(dpy), ws,
&info) == Success && info != NULL) {
char *name = info->backdropName != None ?
XGetAtomName(dpy, info->backdropName) : NULL;
if (name != NULL) {
const char *base = strrchr(name, '/');
char path[1200];
struct stat st;
/* a backdrop of CDE's is named without its file: the
* pattern in the backdrops directory */
if (name[0] == '/')
snprintf(path, sizeof path, "%s", name);
else {
snprintf(path, sizeof path, "%s/backdrops/%s.pm",
CDE_INSTALLATION_TOP, name);
if (stat(path, &st) != 0)
snprintf(path, sizeof path,
"%s/backdrops/%s.bm",
CDE_INSTALLATION_TOP, name);
}
SetPreview(stat(path, &st) == 0 ? path : NULL,
base != NULL ? base + 1 : name);
XFree(name);
}
DtWsmFreeWorkspaceInfo(info);
}
}
static Widget
MakeDesktopPage(Widget parent)
{
static const char *const styleNames[4] = {
"Fill Screen", "Fit to Screen", "Centre", "Tile"
};
static const char *const intervalNames[5] = {
"every 5 minutes", "every 15 minutes", "every 30 minutes",
"every hour", "every day"
};
Display *dpy = XtDisplay(parent);
Widget page, form, top, frame, sw, bottom, row;
Arg a[8];
int n;
blank = XCreatePixmap(dpy, DefaultRootWindow(dpy), THUMB_W, THUMB_H,
(unsigned) DefaultDepthOfScreen(XtScreen(parent)));
blankPreview = XCreatePixmap(dpy, DefaultRootWindow(dpy), PREVIEW_W,
PREVIEW_H, (unsigned) DefaultDepthOfScreen(XtScreen(parent)));
{
GC gc = XCreateGC(dpy, blank, 0, NULL);
Pixel bg = 0;
XtVaGetValues(parent, XmNbackground, &bg, NULL);
XSetForeground(dpy, gc, bg);
XFillRectangle(dpy, blank, gc, 0, 0, THUMB_W, THUMB_H);
XFillRectangle(dpy, blankPreview, gc, 0, 0, PREVIEW_W,
PREVIEW_H);
XFreeGC(dpy, gc);
}
/* a column of rows; only the middle -- the places and the pictures
* side by side -- is a form, of a fixed height */
page = XtVaCreateWidget("desktopPage", xmRowColumnWidgetClass, parent,
XmNspacing, 8, NULL);
/* the workspace the next choice belongs to: "This Workspace" (the
* active one) or one of the named workspaces */
targetWorkspace = -1;
ReadWorkspaces(dpy);
row = XtVaCreateManagedWidget("workspaceRow", xmRowColumnWidgetClass,
page, XmNorientation, XmHORIZONTAL, XmNspacing, 8, NULL);
{
Widget menu = OptionMenu(row, "workspaceMenu", "Workspace:",
(const char *const *) wsNames, wsCount + 1, wsButtons,
WorkspaceChosen);
XtVaSetValues(menu, XmNmenuHistory, wsButtons[0], NULL);
}
top = XtVaCreateManagedWidget("current", xmFormWidgetClass, page, NULL);
/* the frame gets the size: the drawing area alone was laid out 0 high
* (measured) */
frame = XtVaCreateManagedWidget("frame", xmFrameWidgetClass, top,
XmNshadowType, XmSHADOW_IN, XmNtopAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM, XmNwidth, PREVIEW_W + 4,
XmNheight, PREVIEW_H + 4, NULL);
preview = XtVaCreateManagedWidget("preview", xmDrawingAreaWidgetClass,
frame, XmNwidth, PREVIEW_W, XmNheight, PREVIEW_H,
XmNresizePolicy, XmRESIZE_NONE, XmNmarginWidth, 0,
XmNmarginHeight, 0, NULL);
XtAddCallback(preview, XmNexposeCallback, PreviewExpose, NULL);
previewName = XtVaCreateManagedWidget("name", xmLabelWidgetClass, top,
XmNleftAttachment, XmATTACH_WIDGET, XmNleftWidget, frame,
XmNleftOffset, 12, XmNtopAttachment, XmATTACH_FORM,
XmNtopOffset, 8, XmNalignment, XmALIGNMENT_BEGINNING, NULL);
SetText(previewName, "");
form = XtVaCreateManagedWidget("middle", xmFormWidgetClass, page,
XmNwidth, 600, XmNheight, 210, NULL);
n = 0;
XtSetArg(a[n], XmNselectionPolicy, XmBROWSE_SELECT); n++;
XtSetArg(a[n], XmNtopAttachment, XmATTACH_FORM); n++;
XtSetArg(a[n], XmNleftAttachment, XmATTACH_FORM); n++;
XtSetArg(a[n], XmNbottomAttachment, XmATTACH_FORM); n++;
placeList = XmCreateScrolledList(form, "places", a, n);
XtVaSetValues(XtParent(placeList), XmNwidth, 150, NULL);
XtManageChild(placeList);
XtAddCallback(placeList, XmNbrowseSelectionCallback, PlaceChosen, NULL);
XtAddCallback(placeList, XmNdefaultActionCallback, PlaceChosen, NULL);
sw = XtVaCreateManagedWidget("pictures", xmScrolledWindowWidgetClass,
form, XmNscrollingPolicy, XmAUTOMATIC,
XmNscrollBarDisplayPolicy, XmAS_NEEDED,
XmNtopAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_WIDGET,
XmNleftWidget, XtParent(placeList), XmNleftOffset, 8,
XmNrightAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM, NULL);
grid = XtVaCreateManagedWidget("grid", xmRowColumnWidgetClass, sw,
XmNorientation, XmHORIZONTAL, XmNpacking, XmPACK_COLUMN,
XmNnumColumns, 1, XmNradioBehavior, True, XmNspacing, 2, NULL);
row = XtVaCreateManagedWidget("style", xmRowColumnWidgetClass, page,
XmNorientation, XmHORIZONTAL, NULL);
styleMenu = OptionMenu(row, "styleMenu", "Show the picture:",
styleNames, 4, styleButtons, StyleChosen);
bottom = XtVaCreateManagedWidget("change", xmRowColumnWidgetClass, page,
XmNorientation, XmHORIZONTAL, XmNspacing, 8, NULL);
changeToggle = XtVaCreateManagedWidget("Change picture:",
xmToggleButtonWidgetClass, bottom, NULL);
XtAddCallback(changeToggle, XmNvalueChangedCallback, SlideshowChanged,
NULL);
intervalMenu = OptionMenu(bottom, "interval", "", intervalNames, 5,
intervalButtons, IntervalChosen);
XtVaSetValues(intervalMenu, XmNmenuHistory, intervalButtons[2], NULL);
randomToggle = XtVaCreateManagedWidget("Random order",
xmToggleButtonWidgetClass, bottom, NULL);
XtAddCallback(randomToggle, XmNvalueChangedCallback, IntervalChosen,
NULL);
ReadPlaces();
FillPlaceList();
ReadCurrent(dpy);
if (place < 0 && nplaces > 0) {
XmListSelectPos(placeList, 1, False);
ShowPlace(0);
}
return page;
}
/* ---- the screen saver --------------------------------------------------- */
#define MAX_SAVERS 32
#define RANDOM_SAVER "StartDtscreenRandom"
static Widget saverList, saverArea, saverAfter, saverAfterLabel, saverLock;
static Widget saverNote, saverRandom, saverOptions, saverTest;
static char *savers[MAX_SAVERS];
static int nsavers, saverChosen = -1;
static void *saverRunning;
static int saverRow[MAX_SAVERS + 8]; /* list row -> saver, -1 header */
static int nsaverRows;
static int saverStep; /* index into saverSteps */
static const int saverSteps[] = { 3, 5, 15, 30, 60, 120, 0 };
#define NSAVERSTEPS ((int) (sizeof saverSteps / sizeof saverSteps[0]))
static Widget testShell;
static void *testRunning;
static Widget optShell, optBatch, optDelay, optNote;
static char optMode[32];
/* the label without "StartDtscreen" */
static const char *
SaverLabel(const char *name)
{
if (strncmp(name, "StartDtscreen", 13) == 0 && name[13])
return name + 13;
return name;
}
static int
SaverRandomIndex(void)
{
int i;
for (i = 0; i < nsavers; i++)
if (strcmp(savers[i], RANDOM_SAVER) == 0)
return i;
return -1;
}
static int
SaverMinutes(void)
{
return saverSteps[saverStep >= 0 && saverStep < NSAVERSTEPS ?
saverStep : 0];
}
static void
SaverStepLabel(void)
{
char text[96];
int m = SaverMinutes();
if (m == 0)
(void)snprintf(text, sizeof text, "Never.");
else if (m == 60)
(void)snprintf(text, sizeof text, "After 1 hour.");
else if (m == 120)
(void)snprintf(text, sizeof text, "After 2 hours.");
else
(void)snprintf(text, sizeof text, "After %d minutes.", m);
SetText(saverAfterLabel, text);
}
/* the step nearest to MINUTES (0 = never) */
static int
SaverStepOf(int minutes)
{
int i, best = 0, diff = 100000;
if (minutes <= 0)
return NSAVERSTEPS - 1;
for (i = 0; i < NSAVERSTEPS - 1; i++) {
int d = saverSteps[i] - minutes;
if (d < 0)
d = -d;
if (d < diff) {
diff = d;
best = i;
}
}
return best;
}
static void
SaverStop(void)
{
if (saverRunning != NULL) {
_DtSaverStop(XtDisplay(saverArea), saverRunning);
saverRunning = NULL;
}
}
static void
SaverPreview(void)
{
SaverStop();
if (saverChosen < 0 || !XtIsRealized(saverArea) ||
!XtIsManaged(pageSaver))
return;
saverRunning = _DtSaverStart(XtDisplay(saverArea), &saverArea, 1,
savers[saverChosen], saverArea);
}
static void
SaverSend(void)
{
Display *dpy = XtDisplay(saverList);
Window sm;
SmStateInfo state;
SmSaverInfo saver;
int minutes = SaverMinutes();
if (_DtGetSmWindow(dpy, RootWindow(dpy, 0), &sm) != Success) {
SetText(saverNote, "No session manager runs: the setting is "
"not kept.");
return;
}
memset(&state, 0, sizeof state);
state.flags = SM_STATE_SAVERTIMEOUT | SM_STATE_LOCKTIMEOUT;
state.smSaverTimeout = minutes * 60;
state.smLockTimeout = (minutes > 0 && XmToggleButtonGetState(saverLock)) ?
minutes * 60 : 0;
_DtSetSmState(dpy, sm, &state);
if (saverChosen >= 0) {
memset(&saver, 0, sizeof saver);
saver.saverList = savers[saverChosen];
_DtSetSmSaver(dpy, sm, &saver);
}
XFlush(dpy);
SetText(saverNote, "");
}
/* ---- Test: the saver over the whole screen, stopped by a key or a click -- */
static void
TestStop(void)
{
if (testRunning != NULL) {
_DtSaverStop(XtDisplay(testShell), testRunning);
testRunning = NULL;
}
if (testShell != NULL) {
XtPopdown(testShell);
XtDestroyWidget(testShell);
testShell = NULL;
}
}
static void
TestTimeout(XtPointer data, XtIntervalId *id)
{
(void) data;
(void) id;
TestStop();
/* back to the preview in the window */
SaverPreview();
}
static void
SaverTestCB(Widget w, XtPointer data, XtPointer call)
{
Display *dpy = XtDisplay(w);
Screen *scr = XtScreen(w);
Widget area;
int idx = saverChosen;
Arg a[8];
int n = 0;
(void) data;
(void) call;
if (testShell != NULL)
return;
if (idx < 0 || idx >= nsavers)
idx = nsavers > 0 ? 0 : -1;
if (idx < 0)
return;
if (saverRunning != NULL)
SaverStop();
n = 0;
XtSetArg(a[n], XmNwidth, WidthOfScreen(scr)); n++;
XtSetArg(a[n], XmNheight, HeightOfScreen(scr)); n++;
XtSetArg(a[n], XmNx, 0); n++;
XtSetArg(a[n], XmNy, 0); n++;
XtSetArg(a[n], XmNoverrideRedirect, True); n++;
XtSetArg(a[n], XmNmappedWhenManaged, False); n++;
testShell = XtCreatePopupShell("saverTest", topLevelShellWidgetClass,
XtParent(w), a, n);
area = XtVaCreateManagedWidget("testArea", xmDrawingAreaWidgetClass,
testShell, XmNbackground, BlackPixelOfScreen(scr),
XmNwidth, WidthOfScreen(scr), XmNheight, HeightOfScreen(scr),
NULL);
XtPopup(testShell, XtGrabNone);
XRaiseWindow(dpy, XtWindow(testShell));
testRunning = _DtSaverStart(dpy, &area, 1, savers[idx], area);
/* dtscreen keeps no event loop of its own; the saver in a window is
* stopped after a few seconds (a session's saver is stopped by
* dtsession's lock, which a settings program does not have) */
XtAppAddTimeOut(app, 8000, TestTimeout, NULL);
}
/* ---- Options: the chosen saver's batch and delay ------------------------ */
/* "StartDtscreenSwarm" -> "swarm" */
static void
SaverMode(char *buf, size_t len)
{
const char *n = saverChosen >= 0 && saverChosen < nsavers ?
savers[saverChosen] : "blank";
size_t i;
if (strncmp(n, "StartDtscreen", 13) == 0)
n += 13;
for (i = 0; n[i] != '\0' && i + 1 < len; i++)
buf[i] = (n[i] >= 'A' && n[i] <= 'Z') ? n[i] - 'A' + 'a' :
n[i];
buf[i] = '\0';
if (i == 0)
(void)snprintf(buf, len, "blank");
}
static void
OptionsFill(void)
{
char name[128], class[128], v[32];
int batch = 100, delay = 30;
SaverMode(optMode, sizeof optMode);
(void)snprintf(name, sizeof name, "dtscreen.%s.batchcount", optMode);
(void)snprintf(class, sizeof class, "Dtscreen.%s.Batchcount", optMode);
ServerResource(XtDisplay(optShell), name, class, "100", v, sizeof v);
batch = atoi(v);
(void)snprintf(name, sizeof name, "dtscreen.%s.delay", optMode);
(void)snprintf(class, sizeof class, "Dtscreen.%s.Delay", optMode);
ServerResource(XtDisplay(optShell), name, class, "30000", v, sizeof v);
delay = atoi(v) / 1000; /* microseconds -> milliseconds */
XmScaleSetValue(optBatch, batch > 0 ? batch : 1);
XmScaleSetValue(optDelay, delay >= 0 ? delay : 0);
{
char text[128];
(void)snprintf(text, sizeof text, "Options for %s:",
SaverLabel(savers[saverChosen]));
SetText(XtNameToWidget(optShell, "*optionsLabel"), text);
}
}
static void
SaverFile(char *buf, size_t len)
{
const char *home = getenv("HOME");
(void)snprintf(buf, len, "%s/.dt/screensaver", home != NULL ? home :
".");
}
static void
OptionsApply(Widget w, XtPointer data, XtPointer call)
{
char res[256], name[128], class[128], path[1024];
int batch = 0, delay = 0;
FILE *f;
(void) data;
(void) call;
XmScaleGetValue(optBatch, &batch);
XmScaleGetValue(optDelay, &delay);
/* dtscreen reads Dtscreen.<mode>.batchcount and .delay (resource.c) */
(void)snprintf(res, sizeof res,
"dtscreen.%s.batchcount: %d\ndtscreen.%s.delay: %d\n",
optMode, batch > 0 ? batch : 1, optMode, (delay < 0 ? 0 : delay) *
1000);
_DtAddToResource(XtDisplay(w), res);
SaverFile(path, sizeof path);
if ((f = fopen(path, "w")) != NULL) {
fprintf(f, "# the screen saver's options (System Settings)\n"
"mode=%s\nbatchcount=%d\ndelay=%d\n", optMode, batch,
delay);
fclose(f);
}
(void)name;
(void)class;
SetText(optNote, "The preview uses it now; a running saver when it "
"starts again.");
SaverPreview();
}
static void
OptionsClose(Widget w, XtPointer data, XtPointer call)
{
(void) w;
(void) data;
(void) call;
XtPopdown(optShell);
}
static void
SaverOptionsCB(Widget w, XtPointer data, XtPointer call)
{
(void) data;
(void) call;
if (saverChosen < 0 || savers[saverChosen] == NULL) {
Message(XtParent(w), "Choose a screen saver first.", 0);
return;
}
if (strcmp(savers[saverChosen], RANDOM_SAVER) == 0) {
Message(XtParent(w), "The random mode takes the options of the "
"saver it picks.", 0);
return;
}
if (optShell == NULL) {
Widget box, row, buttons;
XmString s;
optShell = XtVaCreatePopupShell("saverOptions",
topLevelShellWidgetClass, XtParent(w),
XmNtitle, "Screen Saver Options", NULL);
box = XtVaCreateManagedWidget("optionsBox",
xmRowColumnWidgetClass, optShell, XmNorientation,
XmVERTICAL, XmNmarginWidth, 12, XmNmarginHeight, 12,
XmNspacing, 6, XmNwidth, 380, NULL);
s = XmStringCreateLocalized((char *) "Options:");
XtVaCreateManagedWidget("optionsLabel", xmLabelWidgetClass,
box, XmNlabelString, s, XmNalignment,
XmALIGNMENT_BEGINNING, NULL);
XmStringFree(s);
row = XtVaCreateManagedWidget("batchRow",
xmRowColumnWidgetClass, box, NULL);
(void) Text(row, "batchLabel", "Things per batch:");
optBatch = XtVaCreateManagedWidget("batch", xmScaleWidgetClass,
row, XmNorientation, XmHORIZONTAL, XmNminimum, 1,
XmNmaximum, 500, XmNvalue, 100, XmNshowValue, True,
XmNscaleWidth, 260, NULL);
row = XtVaCreateManagedWidget("delayRow",
xmRowColumnWidgetClass, box, NULL);
(void) Text(row, "delayLabel", "Delay between updates "
"(milliseconds):");
optDelay = XtVaCreateManagedWidget("delay", xmScaleWidgetClass,
row, XmNorientation, XmHORIZONTAL, XmNminimum, 0,
XmNmaximum, 5000, XmNvalue, 30, XmNshowValue, True,
XmNscaleWidth, 260, NULL);
optNote = Text(box, "optionsNote", "");
buttons = XtVaCreateManagedWidget("optionsButtons",
xmRowColumnWidgetClass, box, XmNorientation,
XmHORIZONTAL, XmNspacing, 8, XmNmarginWidth, 0, NULL);
{
Widget ap = Button(buttons, "Apply", OptionsApply,
NULL);
Widget cl = Button(buttons, "Close", OptionsClose,
NULL);
XtVaSetValues(ap, XmNwidth, 90, NULL);
XtVaSetValues(cl, XmNwidth, 90, NULL);
}
}
OptionsFill();
XtPopup(optShell, XtGrabNone);
}
/* ---- the list: the savers, a Pictures group, the choice ----------------- */
static void
SaverChosen(Widget w, XtPointer data, XtPointer call)
{
int row = ((XmListCallbackStruct *) call)->item_position - 1;
int idx;
(void) w;
(void) data;
if (row < 0 || row >= nsaverRows)
return;
idx = saverRow[row];
if (idx < 0)
return; /* a group's head */
saverChosen = idx;
SaverPreview();
SaverSend();
}
static void
SaverChanged(Widget w, XtPointer data, XtPointer call)
{
(void) w;
(void) data;
(void) call;
SaverSend();
}
static void
SaverRandomCB(Widget w, XtPointer data, XtPointer call)
{
int i, idx;
(void) data;
(void) call;
if (!((XmToggleButtonCallbackStruct *) call)->set)
return;
idx = SaverRandomIndex();
if (idx < 0)
return;
for (i = 0; i < nsaverRows; i++)
if (saverRow[i] == idx)
XmListSelectPos(saverList, i + 1, True);
}
static void
SaverAfterCB(Widget w, XtPointer data, XtPointer call)
{
int v = 0;
(void) w;
(void) data;
(void) call;
XmScaleGetValue(saverAfter, &v);
saverStep = v;
SaverStepLabel();
SaverSend();
}
static Widget
MakeSaverPage(Widget parent)
{
Display *dpy = XtDisplay(parent);
Widget form, frame, left, right, bottom, row;
const char *env = getenv("DTSCREENSAVERLIST");
char *list, *tok, *last = NULL, *current = NULL;
Window sm;
SmStateInfo state;
SmSaverInfo saver;
Arg a[8];
int n, i, minutes = 10, lock = 0;
DtDbLoad();
nsavers = 0;
list = strdup(env != NULL ? env : "StartDtscreenBlank");
for (tok = strtok_r(list, " \t", &last); tok != NULL &&
nsavers < MAX_SAVERS - 1; tok = strtok_r(NULL, " \t", &last))
savers[nsavers++] = strdup(tok);
free(list);
/* the random mode is a saver of its own (dtscreen -mode random) */
for (i = 0; i < nsavers; i++)
if (strcmp(savers[i], RANDOM_SAVER) == 0)
break;
if (i == nsavers && nsavers < MAX_SAVERS)
savers[nsavers++] = strdup(RANDOM_SAVER);
memset(&saver, 0, sizeof saver);
if (_DtGetSmWindow(dpy, RootWindow(dpy, 0), &sm) == Success) {
if (_DtGetSmState(dpy, sm, &state) == Success) {
minutes = state.smSaverTimeout / 60;
lock = state.smLockTimeout > 0;
}
if (_DtGetSmSaver(dpy, sm, &saver) == Success &&
saver.saverList != NULL)
current = saver.saverList;
}
form = XtVaCreateWidget("saverPage", xmRowColumnWidgetClass, parent,
XmNspacing, 6, NULL);
/* left: the savers in two groups; right: the preview */
left = XtVaCreateManagedWidget("saverRow", xmRowColumnWidgetClass,
form, XmNorientation, XmHORIZONTAL, XmNspacing, 12,
XmNmarginWidth, 0, NULL);
{
Widget col = XtVaCreateManagedWidget("saverLeft",
xmRowColumnWidgetClass, left, XmNspacing, 4,
XmNmarginWidth, 0, NULL);
n = 0;
XtSetArg(a[n], XmNvisibleItemCount, 14); n++;
XtSetArg(a[n], XmNselectionPolicy, XmBROWSE_SELECT); n++;
saverList = XmCreateScrolledList(col, "savers", a, n);
XtVaSetValues(XtParent(saverList), XmNwidth, 240,
XmNheight, 300, NULL);
nsaverRows = 0;
{
XmString s = XmStringCreateLocalized((char *)
"Screen Savers");
XmListAddItemUnselected(saverList, s, 0);
XmStringFree(s);
saverRow[nsaverRows++] = -1;
}
for (i = 0; i < nsavers; i++) {
char label[128];
XmString s;
if (strcmp(savers[i], RANDOM_SAVER) == 0)
(void)snprintf(label, sizeof label,
" Random");
else
(void)snprintf(label, sizeof label, " %s",
SaverLabel(savers[i]));
s = XmStringCreateLocalized(label);
XmListAddItemUnselected(saverList, s, 0);
XmStringFree(s);
saverRow[nsaverRows++] = i;
if (current != NULL &&
strstr(current, savers[i]) == current)
saverChosen = i;
}
{
XmString s = XmStringCreateLocalized((char *)
"Pictures");
XmListAddItemUnselected(saverList, s, 0);
XmStringFree(s);
saverRow[nsaverRows++] = -1;
s = XmStringCreateLocalized((char *) " (dtscreen "
"reads no picture folders yet)");
XmListAddItemUnselected(saverList, s, 0);
XmStringFree(s);
saverRow[nsaverRows++] = -1;
}
if (saverChosen >= 0)
for (i = 0; i < nsaverRows; i++)
if (saverRow[i] == saverChosen)
XmListSelectPos(saverList, i + 1,
False);
XtManageChild(saverList);
XtAddCallback(saverList, XmNbrowseSelectionCallback,
SaverChosen, NULL);
saverRandom = XtVaCreateManagedWidget("Use random screen "
"saver", xmToggleButtonWidgetClass, col, NULL);
XtAddCallback(saverRandom, XmNvalueChangedCallback,
SaverRandomCB, NULL);
}
{
Widget col = XtVaCreateManagedWidget("saverRight",
xmRowColumnWidgetClass, left, XmNspacing, 6,
XmNmarginWidth, 0, NULL);
Widget row;
frame = XtVaCreateManagedWidget("previewFrame",
xmFrameWidgetClass, col, XmNshadowType, XmSHADOW_IN,
XmNmarginWidth, 0, XmNmarginHeight, 0, NULL);
saverArea = XtVaCreateManagedWidget("preview",
xmDrawingAreaWidgetClass, frame,
XmNbackground, BlackPixelOfScreen(XtScreen(parent)),
XmNwidth, 360, XmNheight, 220, XmNresizePolicy,
XmRESIZE_NONE, NULL);
row = XtVaCreateManagedWidget("saverButtons",
xmRowColumnWidgetClass, col, XmNorientation,
XmHORIZONTAL, XmNspacing, 8, XmNmarginWidth, 0, NULL);
saverOptions = Button(row, "Options...", SaverOptionsCB, NULL);
saverTest = Button(row, "Test", SaverTestCB, NULL);
(void)saverOptions;
(void)saverTest;
}
/* the time, the password, the corners */
bottom = XtVaCreateManagedWidget("saverBottom",
xmRowColumnWidgetClass, form, XmNspacing, 4, XmNmarginWidth, 0,
NULL);
(void) Text(bottom, "afterLabel", "Start screen saver:");
saverAfter = XtVaCreateManagedWidget("after", xmScaleWidgetClass,
bottom, XmNorientation, XmHORIZONTAL, XmNminimum, 0,
XmNmaximum, NSAVERSTEPS - 1, XmNvalue, SaverStepOf(minutes),
XmNshowValue, False, XmNscaleWidth, 320, NULL);
saverAfterLabel = Text(bottom, "afterText", "");
(void) Text(bottom, "afterMarks", " 3 5 15 30 "
"1 hr 2 hr Never");
XtAddCallback(saverAfter, XmNvalueChangedCallback, SaverAfterCB, NULL);
saverLock = XtVaCreateManagedWidget(
"Ask for the password when it stops", xmToggleButtonWidgetClass,
bottom, NULL);
XmToggleButtonSetState(saverLock, lock, False);
XtAddCallback(saverLock, XmNvalueChangedCallback, SaverChanged, NULL);
row = XtVaCreateManagedWidget("saverExtra", xmRowColumnWidgetClass,
bottom, XmNorientation, XmHORIZONTAL, XmNspacing, 8,
XmNmarginWidth, 0, NULL);
{
Widget hot = Button(row, "Hot Corners...", NULL, NULL);
Widget energy = Button(row, "Energy Saver...", NULL, NULL);
(void)hot;
/* both pages belong to panes that are not there yet */
XtSetSensitive(hot, False);
XtSetSensitive(energy, False);
}
(void) Text(bottom, "energyNote", "The display sleeps before the "
"screen saver when the Energy Saver asks for it;\nthat pane is "
"not there yet.");
saverNote = Text(bottom, "note", "");
saverStep = SaverStepOf(minutes);
SaverStepLabel();
(void) Text(bottom, "clockNote", "A clock in the saver needs a clock "
"mode in dtscreen; it has none yet.\nHot corners belong to "
"Expose & Spaces, which is not there yet either.");
XtVaSetValues(saverNote, XmNmarginWidth, 0, NULL);
return form;
}
/* ---- the pane ----------------------------------------------------------- */
static void
ShowPage(int saver)
{
XtUnmanageChild(saver ? pageDesktop : pageSaver);
XtManageChild(saver ? pageSaver : pageDesktop);
XmToggleButtonSetState(tabDesktop, !saver, False);
XmToggleButtonSetState(tabSaver, saver, False);
if (saver)
SaverPreview();
else
SaverStop();
}
static void
TabChosen(Widget w, XtPointer data, XtPointer call)
{
(void) w;
(void) call;
ShowPage((int) (size_t) data);
}
static void
DesktopGone(Widget w, XtPointer data, XtPointer call)
{
int i;
(void) w;
(void) data;
(void) call;
SaverStop();
ClearPictures();
if (previewPixmap != None) {
XFreePixmap(XtDisplay(w), previewPixmap);
previewPixmap = None;
}
for (i = 0; i < nsavers; i++)
free(savers[i]);
nsavers = 0;
saverChosen = -1;
place = -1;
}
static void
PreviewLater(XtPointer data, XtIntervalId *id)
{
(void) data;
(void) id;
SaverPreview();
}
/* the page shown first: SAVER 0 the desktop, 1 the screen saver */
Widget
MakeDesktopPane(Widget parent, int saver)
{
Widget box = XtVaCreateWidget("desktop", xmRowColumnWidgetClass, parent,
XmNspacing, 8, NULL);
Widget tabs = XtVaCreateManagedWidget("tabs", xmRowColumnWidgetClass,
box, XmNorientation, XmHORIZONTAL, XmNspacing, 0,
XmNradioBehavior, True, NULL);
tabDesktop = XtVaCreateManagedWidget("Desktop",
xmToggleButtonWidgetClass, tabs, XmNindicatorOn, XmINDICATOR_NONE,
XmNshadowThickness, 2, NULL);
tabSaver = XtVaCreateManagedWidget("Screen Saver",
xmToggleButtonWidgetClass, tabs, XmNindicatorOn, XmINDICATOR_NONE,
XmNshadowThickness, 2, NULL);
XtAddCallback(tabDesktop, XmNvalueChangedCallback, TabChosen,
(XtPointer) 0);
XtAddCallback(tabSaver, XmNvalueChangedCallback, TabChosen,
(XtPointer) 1);
pageDesktop = MakeDesktopPage(box);
pageSaver = MakeSaverPage(box);
XtAddCallback(box, XmNdestroyCallback, DesktopGone, NULL);
XtManageChild(saver ? pageSaver : pageDesktop);
XmToggleButtonSetState(saver ? tabSaver : tabDesktop, True, False);
if (saver)
/* the preview needs its window: once the pane is shown */
XtAppAddTimeOut(app, 300, PreviewLater, NULL);
return box;
}
Widget
MakeDesktop(Widget parent)
{
return MakeDesktopPane(parent, 0);
}
Widget
MakeScreenSaver(Widget parent)
{
return MakeDesktopPane(parent, 1);
}