Motif 2.3.8 shifts the channels of a PNG without alpha the wrong way and draws only its blue (docs/reference/motif-png.txt). libDtSvc gets McdeImageGetPixmap/McdeImageFreePixmap (Mcde/Image.h): PNG through libpng's simplified interface (png_image, the background for the alpha), packed by the visual's masks; every other format still through XmGetPixmap. dtwm's backdrops and slideshow and the small pictures of System Settings use it. dtwm now also frees a backdrop pixmap that is not in Motif's cache (a scaled copy), which it kept for good before. configure finds libpng >= 1.6 with pkg-config; the recipe includes graphics/png's buildlink3.mk (Motif depends on it already); the header is in the PLIST. Measured on Xvfb: the RGB PNG that showed only blue (slide-3.png before) shows its colours as backdrop (build/mcde-shots/slide-3.png) and as a small picture (desk-2.png). A 16-bit PNG is not measured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1039 lines
30 KiB
C
1039 lines
30 KiB
C
/*
|
|
* desktop.c -- dtsystemsettings: the backdrop and the screen saver
|
|
*
|
|
* Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE.
|
|
*
|
|
* 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;
|
|
|
|
/* ---- 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);
|
|
}
|
|
}
|
|
|
|
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");
|
|
}
|
|
(void) _DtWsmChangeBackdrop(dpy, DefaultRootWindow(dpy), path, None,
|
|
(DtWsmBackdropImageType) style);
|
|
XFlush(dpy);
|
|
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]);
|
|
(void) _DtWsmChangeBackdrop(dpy, DefaultRootWindow(dpy),
|
|
path, None, (DtWsmBackdropImageType) style);
|
|
XFlush(dpy);
|
|
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);
|
|
|
|
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
|
|
|
|
static Widget saverList, saverArea, saverAfter, saverLock, saverNote;
|
|
static char *savers[MAX_SAVERS];
|
|
static int nsavers, saverChosen = -1;
|
|
static void *saverRunning;
|
|
|
|
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 = 0;
|
|
|
|
XmScaleGetValue(saverAfter, &minutes);
|
|
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 = XmToggleButtonGetState(saverLock) ?
|
|
minutes * 60 : 0;
|
|
_DtSetSmState(dpy, sm, &state);
|
|
if (saverChosen >= 0) {
|
|
saver.saverList = savers[saverChosen];
|
|
_DtSetSmSaver(dpy, sm, &saver);
|
|
}
|
|
XFlush(dpy);
|
|
SetText(saverNote, minutes > 0 ? "" :
|
|
"The screen saver does not start by itself.");
|
|
}
|
|
|
|
static void
|
|
SaverChosen(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
int pos = ((XmListCallbackStruct *) call)->item_position;
|
|
|
|
(void) w;
|
|
(void) data;
|
|
if (pos < 1 || pos > nsavers)
|
|
return;
|
|
saverChosen = pos - 1;
|
|
SaverPreview();
|
|
SaverSend();
|
|
}
|
|
|
|
static void
|
|
SaverChanged(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
(void) w;
|
|
(void) data;
|
|
(void) call;
|
|
SaverSend();
|
|
}
|
|
|
|
static Widget
|
|
MakeSaverPage(Widget parent)
|
|
{
|
|
Display *dpy = XtDisplay(parent);
|
|
Widget form, frame, controls;
|
|
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; tok = strtok_r(NULL, " \t", &last))
|
|
savers[nsavers++] = strdup(tok);
|
|
free(list);
|
|
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", xmFormWidgetClass, parent,
|
|
XmNwidth, 600, XmNheight, 400, NULL);
|
|
controls = XtVaCreateManagedWidget("controls", xmRowColumnWidgetClass,
|
|
form, XmNbottomAttachment, XmATTACH_FORM,
|
|
XmNleftAttachment, XmATTACH_FORM, NULL);
|
|
(void) Text(controls, "label", "Start the screen saver after "
|
|
"(minutes; 0: never):");
|
|
saverAfter = XtVaCreateManagedWidget("after", xmScaleWidgetClass,
|
|
controls, XmNorientation, XmHORIZONTAL, XmNminimum, 0,
|
|
XmNmaximum, 120, XmNvalue, minutes > 120 ? 120 : minutes,
|
|
XmNshowValue, True, XmNscaleWidth, 320, NULL);
|
|
XtAddCallback(saverAfter, XmNvalueChangedCallback, SaverChanged, NULL);
|
|
saverLock = XtVaCreateManagedWidget(
|
|
"Ask for the password when it stops", xmToggleButtonWidgetClass,
|
|
controls, XmNset, lock, NULL);
|
|
XtAddCallback(saverLock, XmNvalueChangedCallback, SaverChanged, NULL);
|
|
saverNote = Text(controls, "note", "");
|
|
|
|
n = 0;
|
|
XtSetArg(a[n], XmNvisibleItemCount, 12); n++;
|
|
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_WIDGET); n++;
|
|
XtSetArg(a[n], XmNbottomWidget, controls); n++;
|
|
XtSetArg(a[n], XmNbottomOffset, 8); n++;
|
|
saverList = XmCreateScrolledList(form, "savers", a, n);
|
|
XtVaSetValues(XtParent(saverList), XmNwidth, 200, NULL);
|
|
for (i = 0; i < nsavers; i++) {
|
|
const char *label = savers[i];
|
|
XmString s;
|
|
|
|
/* "StartDtscreenSwarm": the name without its prefix */
|
|
if (strncmp(label, "StartDtscreen", 13) == 0 && label[13])
|
|
label += 13;
|
|
s = XmStringCreateLocalized((char *) label);
|
|
XmListAddItemUnselected(saverList, s, 0);
|
|
XmStringFree(s);
|
|
if (current != NULL && strstr(current, savers[i]) == current)
|
|
saverChosen = i;
|
|
}
|
|
if (saverChosen >= 0)
|
|
XmListSelectPos(saverList, saverChosen + 1, False);
|
|
XtManageChild(saverList);
|
|
XtAddCallback(saverList, XmNbrowseSelectionCallback, SaverChosen, NULL);
|
|
frame = XtVaCreateManagedWidget("previewFrame", xmFrameWidgetClass,
|
|
form, XmNshadowType, XmSHADOW_IN,
|
|
XmNtopAttachment, XmATTACH_FORM,
|
|
XmNleftAttachment, XmATTACH_WIDGET,
|
|
XmNleftWidget, XtParent(saverList), XmNleftOffset, 12,
|
|
XmNrightAttachment, XmATTACH_FORM,
|
|
XmNbottomAttachment, XmATTACH_WIDGET, XmNbottomWidget, controls,
|
|
XmNbottomOffset, 8, NULL);
|
|
saverArea = XtVaCreateManagedWidget("preview", xmDrawingAreaWidgetClass,
|
|
frame, XmNbackground, BlackPixelOfScreen(XtScreen(parent)), 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 */
|
|
static 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);
|
|
}
|