- configure.ac: the C dialect (-std=gnu11 and five GCC 14 downgrades) is configure's own, also handed to dtksh's ksh93 build (MCDE_DIALECT_CFLAGS). - The pkgsrc placeholders folded in from wm/cde (@PREFIX@, @VARBASE@, @PKG_SYSCONFDIR@) are configure options now: --with-logfiles-dir, --with-config-dir, --with-local-bindir; and --with-pamdir (dtlogin, dtsession) and --with-calendar-dir (dtcm, rpc.cmsd) replace paths that were fixed. Defaults unchanged; the recipe passes its paths. - dtfile: programs/dtfile/Navigation.c -- Back/Forward with a history per window, views Icons/Small/List, places in a sidebar, free space in the status line (statvfs). Screenshot: build/mcde-shots/dtfile-7.png. - make mcde-linux (tools/mcde-linux.sh): the development build on this host, every system path under build/mcde-root. tools/mcde-shot.sh: run a program on a private Xvfb with ttsession and dtwm, empty environment and its own HOME, take a screenshot. tools/ext-sync.sh: ext recipes into pkgsrc/<cat>/<name>. Measured: build/logs/mcde-linux-install3-2026-11-09.log (mcde-linux exit=0). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
364 lines
10 KiB
C
364 lines
10 KiB
C
/*
|
|
* Navigation.c -- MCDE: the navigation of the file manager window: a toolbar
|
|
* (back, forward, the view), a sidebar with the places, a history per window,
|
|
* and the free space in the status line.
|
|
*
|
|
* Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE.
|
|
*
|
|
* Written in C99 against POSIX and Motif (ext/src/mcde/AGENTS.md); nothing
|
|
* here knows the operating system. The rest of dtfile is CDE's: this file
|
|
* only adds widgets around its work area and calls its own functions to
|
|
* change the directory (ChangeDirectoryToParent, which checks the path the
|
|
* way the "Go To" dialog does) and the view (as PrefsP.c applies a new view).
|
|
*
|
|
* First step (2026-11-09): toolbar, places, history, free space. Not yet:
|
|
* icons on the toolbar buttons, the column view, devices in the sidebar,
|
|
* the search field, localized strings (catgets).
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/statvfs.h>
|
|
|
|
#include <Xm/Xm.h>
|
|
#include <Xm/Form.h>
|
|
#include <Xm/RowColumn.h>
|
|
#include <Xm/PushB.h>
|
|
#include <Xm/ToggleB.h>
|
|
#include <Xm/List.h>
|
|
#include <Xm/Frame.h>
|
|
#include <Xm/Separator.h>
|
|
|
|
#include <Dt/Connect.h>
|
|
#include <Dt/SharedProcs.h>
|
|
|
|
#include "Encaps.h"
|
|
#include "SharedProcs.h"
|
|
#include "FileMgr.h"
|
|
#include "Desktop.h"
|
|
#include "Main.h"
|
|
#include "Prefs.h"
|
|
#include "Navigation.h"
|
|
|
|
#define SIDEBAR_WIDTH 150
|
|
|
|
/* the places of the sidebar: a label and a path below $HOME, or absolute */
|
|
static const struct {
|
|
const char *label;
|
|
const char *path; /* "~" is $HOME, "~/x" below it */
|
|
} places[] = {
|
|
{ "Computer", "/" },
|
|
{ "Home", "~" },
|
|
{ "Desktop", "~/Desktop" },
|
|
{ "Documents", "~/Documents" },
|
|
{ "Downloads", "~/Downloads" },
|
|
};
|
|
#define NPLACES (sizeof places / sizeof places[0])
|
|
|
|
/* the three views of the toolbar, as dtfile names them (Prefs.h) */
|
|
static const struct {
|
|
const char *label;
|
|
int view;
|
|
} views[MCDE_NVIEWS] = {
|
|
{ "Icons", BY_NAME_AND_ICON },
|
|
{ "Small", BY_NAME_AND_SMALL_ICON },
|
|
{ "List", BY_ATTRIBUTES },
|
|
};
|
|
|
|
static FileMgrData *
|
|
DataOf(FileMgrRec *rec)
|
|
{
|
|
DialogData *dd = _DtGetInstanceData((XtPointer)rec);
|
|
|
|
return dd != NULL ? (FileMgrData *)dd->data : NULL;
|
|
}
|
|
|
|
/* "~/x" -> "$HOME/x"; the result is XtMalloc'd */
|
|
static char *
|
|
ExpandPlace(const char *path)
|
|
{
|
|
const char *home = getenv("HOME");
|
|
size_t len;
|
|
char *s;
|
|
|
|
if (path[0] != '~')
|
|
return XtNewString(path);
|
|
if (home == NULL || home[0] == '\0')
|
|
home = "/";
|
|
len = strlen(home) + strlen(path);
|
|
s = XtMalloc(len + 1);
|
|
(void)snprintf(s, len + 1, "%s%s", home, path + 1);
|
|
return s;
|
|
}
|
|
|
|
static void
|
|
GoTo(FileMgrRec *rec, const char *path, Boolean from_history)
|
|
{
|
|
char *p = XtNewString(path);
|
|
|
|
rec->mcde_navigating = from_history;
|
|
ChangeDirectoryToParent(rec, p); /* checks the path, shows errors */
|
|
XtFree(p);
|
|
rec->mcde_navigating = False;
|
|
}
|
|
|
|
static void
|
|
UpdateButtons(FileMgrRec *rec)
|
|
{
|
|
if (rec->mcde_back == NULL)
|
|
return;
|
|
XtSetSensitive(rec->mcde_back, rec->mcde_history_pos > 0);
|
|
XtSetSensitive(rec->mcde_forward,
|
|
rec->mcde_history_pos + 1 < rec->mcde_history_len);
|
|
}
|
|
|
|
static void
|
|
BackCB(Widget w, XtPointer client, XtPointer call)
|
|
{
|
|
FileMgrRec *rec = (FileMgrRec *)client;
|
|
|
|
(void)w; (void)call;
|
|
if (rec->mcde_history_pos > 0) {
|
|
rec->mcde_history_pos--;
|
|
GoTo(rec, rec->mcde_history[rec->mcde_history_pos], True);
|
|
UpdateButtons(rec);
|
|
}
|
|
}
|
|
|
|
static void
|
|
ForwardCB(Widget w, XtPointer client, XtPointer call)
|
|
{
|
|
FileMgrRec *rec = (FileMgrRec *)client;
|
|
|
|
(void)w; (void)call;
|
|
if (rec->mcde_history_pos + 1 < rec->mcde_history_len) {
|
|
rec->mcde_history_pos++;
|
|
GoTo(rec, rec->mcde_history[rec->mcde_history_pos], True);
|
|
UpdateButtons(rec);
|
|
}
|
|
}
|
|
|
|
static void
|
|
ViewCB(Widget w, XtPointer client, XtPointer call)
|
|
{
|
|
FileMgrRec *rec = (FileMgrRec *)client;
|
|
XmToggleButtonCallbackStruct *cbs = (XmToggleButtonCallbackStruct *)call;
|
|
FileMgrData *data;
|
|
int i;
|
|
|
|
if (!cbs->set || (data = DataOf(rec)) == NULL)
|
|
return;
|
|
for (i = 0; i < MCDE_NVIEWS; i++)
|
|
if (rec->mcde_view[i] == w)
|
|
break;
|
|
if (i == MCDE_NVIEWS || data->view == views[i].view)
|
|
return;
|
|
/* as PrefsP.c applies a view chosen in the Preferences dialog */
|
|
data->view = views[i].view;
|
|
if (data->show_type == SINGLE_DIRECTORY)
|
|
data->view_single = views[i].view;
|
|
else
|
|
data->view_tree = views[i].view;
|
|
data->newSize = True;
|
|
FileMgrRedisplayFiles(rec, data, False);
|
|
}
|
|
|
|
static void
|
|
PlaceCB(Widget w, XtPointer client, XtPointer call)
|
|
{
|
|
FileMgrRec *rec = (FileMgrRec *)client;
|
|
XmListCallbackStruct *cbs = (XmListCallbackStruct *)call;
|
|
int i = cbs->item_position - 1;
|
|
char *path;
|
|
|
|
(void)w;
|
|
if (i < 0 || (size_t)i >= NPLACES)
|
|
return;
|
|
path = ExpandPlace(places[i].path);
|
|
GoTo(rec, path, False);
|
|
XtFree(path);
|
|
}
|
|
|
|
static Widget
|
|
Button(Widget parent, const char *name, const char *label,
|
|
XtCallbackProc cb, XtPointer client)
|
|
{
|
|
XmString s = XmStringCreateLocalized((char *)label);
|
|
Arg args[2];
|
|
Widget b;
|
|
|
|
XtSetArg(args[0], XmNlabelString, s);
|
|
XtSetArg(args[1], XmNtraversalOn, False);
|
|
b = XmCreatePushButton(parent, (char *)name, args, 2);
|
|
XmStringFree(s);
|
|
XtAddCallback(b, XmNactivateCallback, cb, client);
|
|
XtManageChild(b);
|
|
return b;
|
|
}
|
|
|
|
Widget
|
|
_McdeNavCreate(FileMgrRec *rec, Widget parent)
|
|
{
|
|
Widget form, bar, views_rc, frame;
|
|
XmString items[NPLACES];
|
|
Arg args[12];
|
|
size_t k;
|
|
int i, n;
|
|
|
|
rec->mcde_history = NULL;
|
|
rec->mcde_history_len = 0;
|
|
rec->mcde_history_pos = -1;
|
|
rec->mcde_navigating = False;
|
|
|
|
form = XmCreateForm(parent, "mcdeNavigation", NULL, 0);
|
|
|
|
/* the toolbar: back, forward, then the views */
|
|
n = 0;
|
|
XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
|
|
XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
|
|
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
|
|
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
|
|
XtSetArg(args[n], XmNspacing, 4); n++;
|
|
XtSetArg(args[n], XmNmarginHeight, 4); n++;
|
|
bar = XmCreateRowColumn(form, "mcdeToolbar", args, n);
|
|
rec->mcde_toolbar = bar;
|
|
rec->mcde_back = Button(bar, "mcdeBack", "< Back", BackCB, rec);
|
|
rec->mcde_forward = Button(bar, "mcdeForward", "Forward >", ForwardCB,
|
|
rec);
|
|
|
|
n = 0;
|
|
XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
|
|
XtSetArg(args[n], XmNradioBehavior, True); n++;
|
|
XtSetArg(args[n], XmNradioAlwaysOne, True); n++;
|
|
XtSetArg(args[n], XmNspacing, 0); n++;
|
|
views_rc = XmCreateRowColumn(bar, "mcdeViews", args, n);
|
|
for (i = 0; i < MCDE_NVIEWS; i++) {
|
|
XmString s = XmStringCreateLocalized((char *)views[i].label);
|
|
|
|
n = 0;
|
|
XtSetArg(args[n], XmNlabelString, s); n++;
|
|
XtSetArg(args[n], XmNindicatorOn, False); n++;
|
|
XtSetArg(args[n], XmNshadowThickness, 2); n++;
|
|
XtSetArg(args[n], XmNtraversalOn, False); n++;
|
|
rec->mcde_view[i] = XmCreateToggleButton(views_rc,
|
|
"mcdeView", args, n);
|
|
XmStringFree(s);
|
|
XtAddCallback(rec->mcde_view[i], XmNvalueChangedCallback,
|
|
ViewCB, rec);
|
|
XtManageChild(rec->mcde_view[i]);
|
|
}
|
|
XtManageChild(views_rc);
|
|
XtManageChild(bar);
|
|
/* the form gives children without a size of their own what is left, and
|
|
* that is nothing once dtfile sets the window to its saved size: the
|
|
* toolbar keeps the height it asks for */
|
|
{
|
|
XtWidgetGeometry pref;
|
|
|
|
if (XtQueryGeometry(bar, NULL, &pref) != XtGeometryNo &&
|
|
(pref.request_mode & CWHeight))
|
|
XtVaSetValues(bar, XmNheight, pref.height, NULL);
|
|
}
|
|
UpdateButtons(rec);
|
|
|
|
/* the sidebar: the places */
|
|
for (k = 0; k < NPLACES; k++)
|
|
items[k] = XmStringCreateLocalized((char *)places[k].label);
|
|
n = 0;
|
|
XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
|
|
XtSetArg(args[n], XmNtopWidget, bar); n++;
|
|
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
|
|
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
|
|
XtSetArg(args[n], XmNshadowType, XmSHADOW_IN); n++;
|
|
XtSetArg(args[n], XmNwidth, SIDEBAR_WIDTH + 4); n++;
|
|
frame = XmCreateFrame(form, "mcdeSidebarFrame", args, n);
|
|
n = 0;
|
|
XtSetArg(args[n], XmNitems, items); n++;
|
|
XtSetArg(args[n], XmNitemCount, (int)NPLACES); n++;
|
|
XtSetArg(args[n], XmNvisibleItemCount, (int)NPLACES); n++;
|
|
XtSetArg(args[n], XmNselectionPolicy, XmBROWSE_SELECT); n++;
|
|
XtSetArg(args[n], XmNwidth, SIDEBAR_WIDTH); n++;
|
|
XtSetArg(args[n], XmNlistMarginWidth, 6); n++;
|
|
XtSetArg(args[n], XmNlistMarginHeight, 6); n++;
|
|
XtSetArg(args[n], XmNshadowThickness, 0); n++;
|
|
rec->mcde_sidebar = XmCreateList(frame, "mcdeSidebar", args, n);
|
|
for (k = 0; k < NPLACES; k++)
|
|
XmStringFree(items[k]);
|
|
XtAddCallback(rec->mcde_sidebar, XmNbrowseSelectionCallback, PlaceCB,
|
|
rec);
|
|
XtManageChild(rec->mcde_sidebar);
|
|
XtManageChild(frame);
|
|
rec->mcde_sidebar_frame = frame;
|
|
|
|
XtManageChild(form);
|
|
return form;
|
|
}
|
|
|
|
void
|
|
_McdeNavAttachWork(FileMgrRec *rec, Widget work)
|
|
{
|
|
Arg args[6];
|
|
int n = 0;
|
|
|
|
XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
|
|
XtSetArg(args[n], XmNtopWidget, rec->mcde_toolbar); n++;
|
|
XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
|
|
XtSetArg(args[n], XmNleftWidget, rec->mcde_sidebar_frame); n++;
|
|
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
|
|
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
|
|
XtSetValues(work, args, n);
|
|
}
|
|
|
|
void
|
|
_McdeNavVisit(FileMgrRec *rec, const char *dir)
|
|
{
|
|
FileMgrData *data;
|
|
int i;
|
|
|
|
if (rec == NULL || rec->mcde_toolbar == NULL || dir == NULL)
|
|
return;
|
|
if (!rec->mcde_navigating) {
|
|
if (rec->mcde_history_pos >= 0 &&
|
|
strcmp(rec->mcde_history[rec->mcde_history_pos], dir) == 0)
|
|
return;
|
|
/* a new way: what was ahead of us is forgotten */
|
|
for (i = rec->mcde_history_pos + 1; i < rec->mcde_history_len;
|
|
i++)
|
|
XtFree(rec->mcde_history[i]);
|
|
rec->mcde_history_len = rec->mcde_history_pos + 1;
|
|
rec->mcde_history = (char **)XtRealloc(
|
|
(char *)rec->mcde_history,
|
|
(Cardinal)((rec->mcde_history_len + 1) * sizeof(char *)));
|
|
rec->mcde_history[rec->mcde_history_len++] = XtNewString(dir);
|
|
rec->mcde_history_pos = rec->mcde_history_len - 1;
|
|
}
|
|
UpdateButtons(rec);
|
|
|
|
/* the view buttons follow the window's view */
|
|
if ((data = DataOf(rec)) != NULL)
|
|
for (i = 0; i < MCDE_NVIEWS; i++)
|
|
XmToggleButtonSetState(rec->mcde_view[i],
|
|
data->view == views[i].view, False);
|
|
}
|
|
|
|
void
|
|
_McdeNavFreeSpace(const char *dir, char *buf, size_t len)
|
|
{
|
|
struct statvfs sv;
|
|
double bytes;
|
|
size_t used = strlen(buf);
|
|
|
|
if (dir == NULL || statvfs(dir, &sv) != 0 || used + 1 >= len)
|
|
return;
|
|
bytes = (double)sv.f_bavail * (double)sv.f_frsize;
|
|
if (bytes >= 1e9)
|
|
(void)snprintf(buf + used, len - used, ", %.1f GB available",
|
|
bytes / 1e9);
|
|
else
|
|
(void)snprintf(buf + used, len - used, ", %.0f MB available",
|
|
bytes / 1e6);
|
|
}
|