dtsystemsettings: a Dock pane that works
The Dock entry is back, and it is a pane of its own: it lists the programs kept in the front panel (the CLASS and COMMAND lines of ~/.dt/panel-apps), removes the chosen one, adds one from a command, writes the file at once and restarts the window manager (_DtWmRestartNoConfirm) so the panel is built again. The icon is Dtapps.m.pm -- the entry was PANE_LATER with DtPanel.m.pm, which does not exist, so it was greyed out and had no picture.
This commit is contained in:
1 parent
4aa00e0649
commit
bd2afc27f2
5 files changed
+251
-1
No files matched your search
@@ -7,7 +7,7 @@ bin_PROGRAMS = dtsystemsettings
|
||||
dtsystemsettings_SOURCES = main.c panes.c panes.h ui.h accounts.c update.c \
|
||||
network.c \
|
||||
input.c appearance.c desktop.c timezone.c wifi.c \
|
||||
startup.c sharing.c backup.c displays.c language.c sound.c printers.c parental.c cds.c energy.c internet.c defaults.c sysinfo.c startupdisk.c \
|
||||
startup.c sharing.c backup.c displays.c language.c sound.c printers.c parental.c cds.c dock.c energy.c internet.c defaults.c sysinfo.c startupdisk.c \
|
||||
security.c
|
||||
dtsystemsettings_CPPFLAGS = -I$(top_srcdir)/include $(DT_INCDIR) \
|
||||
-I$(top_builddir)/include $(XFT_CFLAGS) \
|
||||
|
||||
@@ -0,0 +1,245 @@
|
||||
/*
|
||||
* dock.c -- dtsystemsettings: the programs kept in the front panel's dock
|
||||
*
|
||||
* Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE.
|
||||
*
|
||||
* The dock is the part of the front panel left of the Trash: the programs
|
||||
* kept there, then the running programs that have no place in the panel
|
||||
* (WmMcdePanel.c). The kept ones are ~/.dt/panel-apps, one a line:
|
||||
*
|
||||
* CLASS <tab> COMMAND
|
||||
*
|
||||
* This pane shows that list, removes an entry and adds one. A change is
|
||||
* written at once, and the window manager is restarted with
|
||||
* _DtWmRestartNoConfirm so the panel shows it (the panel is dtwm's; it
|
||||
* reads the file when the panel is built).
|
||||
*
|
||||
* C99, POSIX, Xt and Motif only (ext/src/mcde/AGENTS.md).
|
||||
*/
|
||||
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <X11/Intrinsic.h>
|
||||
#include <Xm/DialogS.h>
|
||||
#include <Xm/Form.h>
|
||||
#include <Xm/Label.h>
|
||||
#include <Xm/List.h>
|
||||
#include <Xm/PushB.h>
|
||||
#include <Xm/RowColumn.h>
|
||||
#include <Xm/Separator.h>
|
||||
#include <Xm/TextF.h>
|
||||
|
||||
#include "ui.h"
|
||||
|
||||
#define MAXAPPS 64
|
||||
|
||||
extern int _DtWmRestartNoConfirm(Display *display, Window root);
|
||||
|
||||
static Widget dockList;
|
||||
static Widget addShell, addText;
|
||||
static char apps[MAXAPPS][512];
|
||||
static int napps;
|
||||
|
||||
static const char *
|
||||
Path(void)
|
||||
{
|
||||
static char path[512];
|
||||
const char *home = getenv("HOME");
|
||||
|
||||
(void) snprintf(path, sizeof path, "%s/.dt/panel-apps",
|
||||
home != NULL ? home : ".");
|
||||
return path;
|
||||
}
|
||||
|
||||
static void
|
||||
Load(void)
|
||||
{
|
||||
FILE *f;
|
||||
char line[512];
|
||||
|
||||
napps = 0;
|
||||
if ((f = fopen(Path(), "r")) == NULL)
|
||||
return;
|
||||
while (napps < MAXAPPS && fgets(line, sizeof line, f) != NULL) {
|
||||
char *nl = strchr(line, '\n');
|
||||
|
||||
if (nl != NULL)
|
||||
*nl = '\0';
|
||||
if (line[0] == '\0')
|
||||
continue;
|
||||
(void) snprintf(apps[napps], sizeof apps[0], "%s", line);
|
||||
napps++;
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
static void
|
||||
Save(void)
|
||||
{
|
||||
FILE *f = fopen(Path(), "w");
|
||||
int i;
|
||||
|
||||
if (f == NULL)
|
||||
return;
|
||||
for (i = 0; i < napps; i++)
|
||||
fprintf(f, "%s\n", apps[i]);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
static void
|
||||
Show(void)
|
||||
{
|
||||
XmString items[MAXAPPS];
|
||||
char buf[600];
|
||||
int i;
|
||||
|
||||
XmListDeleteAllItems(dockList);
|
||||
for (i = 0; i < napps; i++) {
|
||||
char *tab = strchr(apps[i], '\t');
|
||||
|
||||
if (tab != NULL)
|
||||
(void) snprintf(buf, sizeof buf, "%.*s - %s",
|
||||
(int) (tab - apps[i]), apps[i], tab + 1);
|
||||
else
|
||||
(void) snprintf(buf, sizeof buf, "%s", apps[i]);
|
||||
items[i] = XmStringCreateLocalized(buf);
|
||||
}
|
||||
if (napps > 0)
|
||||
XmListAddItems(dockList, items, napps, 1);
|
||||
for (i = 0; i < napps; i++)
|
||||
XmStringFree(items[i]);
|
||||
}
|
||||
|
||||
static void
|
||||
Restart(void)
|
||||
{
|
||||
_DtWmRestartNoConfirm(XtDisplay(dockList),
|
||||
DefaultRootWindow(XtDisplay(dockList)));
|
||||
}
|
||||
|
||||
static void
|
||||
RemoveClicked(Widget w, XtPointer cd, XtPointer call)
|
||||
{
|
||||
int *pos = NULL, n = 0, i;
|
||||
|
||||
(void) w; (void) cd; (void) call;
|
||||
if (!XmListGetSelectedPos(dockList, &pos, &n) || n < 1) {
|
||||
Message(dockList, "Choose a program in the list first.", 0);
|
||||
return;
|
||||
}
|
||||
i = pos[0] - 1;
|
||||
XtFree((char *) pos);
|
||||
if (i < 0 || i >= napps)
|
||||
return;
|
||||
memmove(&apps[i], &apps[i + 1],
|
||||
(size_t) (napps - i - 1) * sizeof apps[0]);
|
||||
napps--;
|
||||
Save();
|
||||
Show();
|
||||
Restart();
|
||||
}
|
||||
|
||||
static void
|
||||
AddOk(Widget w, XtPointer cd, XtPointer call)
|
||||
{
|
||||
char *cmd = XmTextFieldGetString(addText);
|
||||
char cls[128], *base;
|
||||
|
||||
(void) w; (void) cd; (void) call;
|
||||
if (cmd == NULL)
|
||||
return;
|
||||
if (cmd[0] == '\0') {
|
||||
XtFree(cmd);
|
||||
Message(dockList, "Name the command to start.", 0);
|
||||
return;
|
||||
}
|
||||
base = strrchr(cmd, '/');
|
||||
base = base != NULL ? base + 1 : cmd;
|
||||
(void) snprintf(cls, sizeof cls, "%s", base);
|
||||
if (cls[0] >= 'a' && cls[0] <= 'z')
|
||||
cls[0] = (char) (cls[0] - 'a' + 'A');
|
||||
if (napps < MAXAPPS) {
|
||||
(void) snprintf(apps[napps], sizeof apps[0], "%s\t%s",
|
||||
cls, cmd);
|
||||
napps++;
|
||||
Save();
|
||||
Show();
|
||||
}
|
||||
XtFree(cmd);
|
||||
XtUnmanageChild(addShell);
|
||||
Restart();
|
||||
}
|
||||
|
||||
static void
|
||||
AddCancel(Widget w, XtPointer cd, XtPointer call)
|
||||
{
|
||||
(void) w; (void) cd; (void) call;
|
||||
XtUnmanageChild(addShell);
|
||||
}
|
||||
|
||||
static void
|
||||
AddClicked(Widget w, XtPointer cd, XtPointer call)
|
||||
{
|
||||
Widget form, ok, cancel;
|
||||
|
||||
(void) w; (void) cd; (void) call;
|
||||
if (addShell == NULL) {
|
||||
addShell = XmCreateDialogShell(dockList, "addProgram", NULL, 0);
|
||||
XtVaSetValues(addShell, XmNtitle, "Add a Program", NULL);
|
||||
form = XtVaCreateManagedWidget("addForm", xmFormWidgetClass,
|
||||
addShell, XmNmarginWidth, 12, XmNmarginHeight, 12,
|
||||
XmNautoUnmanage, False, NULL);
|
||||
(void) Text(form, "addLabel",
|
||||
"Command (the program to start):");
|
||||
addText = XtVaCreateManagedWidget("addCommand",
|
||||
xmTextFieldWidgetClass, form, XmNcolumns, 40,
|
||||
XmNtopAttachment, XmATTACH_WIDGET,
|
||||
XmNtopWidget, XtNameToWidget(form, "addLabel"),
|
||||
XmNleftAttachment, XmATTACH_FORM,
|
||||
XmNrightAttachment, XmATTACH_FORM, NULL);
|
||||
ok = Button(form, "Add", AddOk, NULL);
|
||||
XtVaSetValues(ok, XmNtopAttachment, XmATTACH_WIDGET,
|
||||
XmNtopWidget, addText, XmNleftAttachment, XmATTACH_FORM,
|
||||
NULL);
|
||||
cancel = Button(form, "Cancel", AddCancel, NULL);
|
||||
XtVaSetValues(cancel, XmNtopAttachment, XmATTACH_WIDGET,
|
||||
XmNtopWidget, addText, XmNleftAttachment, XmATTACH_WIDGET,
|
||||
XmNleftWidget, ok, NULL);
|
||||
}
|
||||
XtManageChild(addShell);
|
||||
XtManageChild(XtNameToWidget(addShell, "*addForm"));
|
||||
XmProcessTraversal(addText, XmTRAVERSE_CURRENT);
|
||||
}
|
||||
|
||||
Widget
|
||||
MakeDock(Widget parent)
|
||||
{
|
||||
Widget box, list;
|
||||
|
||||
box = XtVaCreateWidget("dockPane", xmRowColumnWidgetClass, parent,
|
||||
XmNorientation, XmVERTICAL, XmNspacing, 10, NULL);
|
||||
(void) Text(box, "dockLabel",
|
||||
"The programs kept in the dock, left of the Trash in the front "
|
||||
"panel. A click starts the program or brings it forward; the "
|
||||
"right mouse button in the panel removes it.");
|
||||
list = XtVaCreateManagedWidget("dockList", xmListWidgetClass, box,
|
||||
XmNvisibleItemCount, 10, XmNselectionPolicy, XmSINGLE_SELECT,
|
||||
XmNwidth, 420, NULL);
|
||||
dockList = list;
|
||||
(void) Button(box, "Remove from the Dock", RemoveClicked, NULL);
|
||||
(void) Button(box, "Add a Program...", AddClicked, NULL);
|
||||
XtVaCreateManagedWidget("sep", xmSeparatorWidgetClass, box,
|
||||
XmNorientation, XmHORIZONTAL, XmNmarginTop, 4,
|
||||
XmNmarginBottom, 4, NULL);
|
||||
(void) Text(box, "dockNote",
|
||||
"The running programs that are not kept appear in the dock on "
|
||||
"their own; keeping one writes it to ~/.dt/panel-apps. A change "
|
||||
"restarts the window manager, so the panel is built again.");
|
||||
Load();
|
||||
Show();
|
||||
return box;
|
||||
}
|
||||
@@ -1125,6 +1125,8 @@ ShowPane(const Pane *p)
|
||||
else if (strcmp(p->id, "energy") == 0) {
|
||||
w = MakeEnergy(paneArea);
|
||||
}
|
||||
else if (strcmp(p->id, "dock") == 0)
|
||||
w = MakeDock(paneArea);
|
||||
else if (strcmp(p->id, "cds") == 0) {
|
||||
w = MakeCDs(paneArea);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ const Pane panes[] = {
|
||||
"screensaver screen saver bildschirmschoner" },
|
||||
{ "language", "Language", CAT_PERSONAL, "DtI18N.pm", PANE_OWN,
|
||||
NULL, "language sprache locale region formats datum" },
|
||||
{ "dock", "Dock", CAT_PERSONAL, "Dtapps.m.pm", PANE_OWN, NULL,
|
||||
"dock leiste panel front panel programme programs" },
|
||||
{ "security", "Security", CAT_PERSONAL, "McdeLock.pm", PANE_OWN, NULL,
|
||||
"security sicherheit firewall lock sperre password passwort "
|
||||
"encryption verschluesselung cgd swap virtual memory npf" },
|
||||
|
||||
@@ -77,6 +77,7 @@ Widget MakePrinters(Widget parent);
|
||||
Widget MakeParental(Widget parent);
|
||||
/* the CDs & DVDs pane (cds.c): the choice per kind of medium */
|
||||
Widget MakeCDs(Widget parent);
|
||||
Widget MakeDock(Widget parent);
|
||||
/* the Energy Saver pane (energy.c) */
|
||||
Widget MakeEnergy(Widget parent);
|
||||
/* the Internet accounts pane (internet.c) */
|
||||
|
||||
Reference in new issue
Block a user