CDE's front panel stays as it is. Left of the trash it gets one part of MCDE's (dtwm/WmMcdePanel.c): first the programs kept in the panel (~/.dt/panel-apps), then the running programs no main panel control names. A click brings a window forward on its workspace, or starts a kept program; the right button offers Keep in Panel / Remove from Panel, and dragging a running one to the left with the button held keeps it too. The command to start a kept program comes from WM_COMMAND, else from the process of _NET_WM_PID through the new mcde_sys_process_command (NetBSD: sysctl kern.proc_args, Linux: /proc/PID/cmdline), else the class. The buttons are CDE's panel controls (_DtCreateControl) with the class's icon; a blank of the same width in the arrow row keeps every drawer's arrow over its control; colour and pattern come from the panel row, so the part follows the palette. Hooks: UI.c (MainControlCreate), WmManage.c (manage, unmanage), PopupMenu.c (the menu button over the part). Measured on Xvfb (build/mcde-shots/panel-*.png, theme-*.png): dtterm and dtcalc appear left of the trash; Keep in Panel wrote "Dtterm dtterm", the drag "Dtcalc 'dtcalc'"; with none running a click on the kept dtcalc started it; in a dtsession with the Default and the Arizona palette the part has the panel's colours and the bar, the panel and the windows all change with the palette. www: the front panel and the colours. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
681 lines
19 KiB
C
681 lines
19 KiB
C
/*
|
|
* WmMcdePanel.c -- MCDE: the programs left of the trash in the front panel
|
|
*
|
|
* Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE.
|
|
*
|
|
* The front panel stays CDE's: its controls, subpanels and workspace
|
|
* switch. Left of the trash it gets one more part, made here:
|
|
*
|
|
* - the programs kept in the panel (~/.dt/panel-apps, one a line:
|
|
* CLASS <tab> COMMAND); a click starts one, or brings it forward when
|
|
* it runs; the right button offers "Remove from Panel";
|
|
* - then the programs running that have no place in the panel -- not
|
|
* kept, and no main panel control names them (CLIENT_NAME, or a
|
|
* PUSH_ACTION that begins with the program's class); a click brings
|
|
* the window forward (on its workspace); the right button offers
|
|
* "Keep in Panel", and so does dragging it to the left with the button
|
|
* held.
|
|
*
|
|
* Keeping a program needs the command that starts it: the client's
|
|
* WM_COMMAND, else the command line of its process (_NET_WM_PID,
|
|
* mcde_sys_process_command), else its class in lower case.
|
|
*
|
|
* The part is a form in the main panel's control row, between the control
|
|
* before the trash and the trash; above it, in the row of the subpanel
|
|
* arrows, a blank of the same width keeps every arrow over its control
|
|
* (UI.c, ArrowCreate). An unmanaged form passes its attachment on, so the
|
|
* trash moves back when the part is empty. The buttons are CDE's own
|
|
* panel controls (_DtCreateControl) with the class's icon. The part is
|
|
* redrawn after dtwm manages or unmanages a window (WmManage.c).
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <strings.h>
|
|
#include <ctype.h>
|
|
#include <sys/types.h>
|
|
|
|
#include "WmGlobal.h"
|
|
#include "WmFunction.h"
|
|
#include "WmWrkspace.h"
|
|
#include "DataBaseLoad.h"
|
|
#include "UI.h"
|
|
#include "WmMcdePanel.h"
|
|
|
|
#include <X11/Xatom.h>
|
|
#include <Dt/WsmP.h>
|
|
#include <Xm/Xm.h>
|
|
#include <Xm/Form.h>
|
|
#include <Xm/Label.h>
|
|
#include <Xm/PushB.h>
|
|
#include <Xm/RowColumn.h>
|
|
#include <Xm/Separator.h>
|
|
#include <Dt/DtStrDefs.h>
|
|
#include <Dt/Icon.h>
|
|
#include <Dt/Control.h>
|
|
#include <Dt/IconFile.h>
|
|
#include <Mcde/McdeSys.h>
|
|
|
|
#define MAX_APPS 48
|
|
|
|
typedef struct {
|
|
char cls[64]; /* WM_CLASS class */
|
|
char cmd[1024]; /* what starts it */
|
|
} Kept;
|
|
|
|
static Kept kept[MAX_APPS];
|
|
static int nkept;
|
|
|
|
static Widget area, spacer, menu, menuItem;
|
|
static ControlData *trash;
|
|
static XtIntervalId pending;
|
|
|
|
/* the buttons now: class, kept (an index into kept[]) or running only */
|
|
static struct {
|
|
Widget w;
|
|
char cls[64];
|
|
int keptIndex; /* -1: running, not kept */
|
|
} buttons[MAX_APPS];
|
|
static int nbuttons, menuFor = -1, pressX;
|
|
|
|
/* ---- the kept programs -------------------------------------------------- */
|
|
|
|
static void
|
|
KeptFile(char *buf, size_t len)
|
|
{
|
|
const char *home = getenv("HOME");
|
|
|
|
snprintf(buf, len, "%s/.dt/panel-apps", home != NULL ? home : ".");
|
|
}
|
|
|
|
static void
|
|
ReadKept(void)
|
|
{
|
|
char path[1100], line[1200], *tab;
|
|
FILE *fp;
|
|
|
|
nkept = 0;
|
|
KeptFile(path, sizeof path);
|
|
if ((fp = fopen(path, "r")) == NULL)
|
|
return;
|
|
while (nkept < MAX_APPS && fgets(line, sizeof line, fp) != NULL) {
|
|
line[strcspn(line, "\r\n")] = '\0';
|
|
if (line[0] == '#' || (tab = strchr(line, '\t')) == NULL)
|
|
continue;
|
|
*tab = '\0';
|
|
snprintf(kept[nkept].cls, sizeof kept[nkept].cls, "%s", line);
|
|
snprintf(kept[nkept].cmd, sizeof kept[nkept].cmd, "%s", tab + 1);
|
|
nkept++;
|
|
}
|
|
fclose(fp);
|
|
}
|
|
|
|
static void
|
|
WriteKept(void)
|
|
{
|
|
char path[1100], tmp[1200];
|
|
FILE *fp;
|
|
int i;
|
|
|
|
KeptFile(path, sizeof path);
|
|
snprintf(tmp, sizeof tmp, "%s.new", path);
|
|
if ((fp = fopen(tmp, "w")) == NULL)
|
|
return;
|
|
fprintf(fp, "# the programs kept in the front panel: CLASS <tab> "
|
|
"COMMAND (MCDE dtwm)\n");
|
|
for (i = 0; i < nkept; i++)
|
|
fprintf(fp, "%s\t%s\n", kept[i].cls, kept[i].cmd);
|
|
if (fclose(fp) == 0)
|
|
(void) rename(tmp, path);
|
|
}
|
|
|
|
static int
|
|
KeptIndex(const char *cls)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < nkept; i++)
|
|
if (strcasecmp(kept[i].cls, cls) == 0)
|
|
return i;
|
|
return -1;
|
|
}
|
|
|
|
/* ---- the windows -------------------------------------------------------- */
|
|
|
|
/* a program's window of its own: not a transient, not dtwm's panels */
|
|
static Boolean
|
|
IsProgram(ClientData *pCD)
|
|
{
|
|
return pCD != NULL && pCD->clientClass != NULL &&
|
|
pCD->transientLeader == NULL &&
|
|
!(pCD->dtwmBehaviors & (DtWM_BEHAVIOR_PANEL |
|
|
DtWM_BEHAVIOR_SUBPANEL)) &&
|
|
pCD->clientState != WITHDRAWN_STATE &&
|
|
strcasecmp(pCD->clientClass, "Dtwm") != 0;
|
|
}
|
|
|
|
/* the first window of class CLS, or NULL */
|
|
static ClientData *
|
|
WindowOf(const char *cls)
|
|
{
|
|
WmScreenData *pSD = ACTIVE_PSD;
|
|
ClientListEntry *e;
|
|
|
|
for (e = pSD->clientList; e != NULL; e = e->nextSibling)
|
|
if (e->pCD != NULL && e == &e->pCD->clientEntry &&
|
|
IsProgram(e->pCD) &&
|
|
strcasecmp(e->pCD->clientClass, cls) == 0)
|
|
return e->pCD;
|
|
return NULL;
|
|
}
|
|
|
|
/* does a control of the main panel stand for class CLS */
|
|
static Boolean
|
|
InPanel(const char *cls)
|
|
{
|
|
size_t n = strlen(cls);
|
|
int i, j;
|
|
|
|
for (i = 0; i < panel.box_data_count; i++) {
|
|
BoxData *b = panel.box_data[i];
|
|
|
|
for (j = 0; j < b->control_data_count; j++) {
|
|
ElementValue *v = b->control_data[j]->element_values;
|
|
const char *client =
|
|
(const char *) v[CONTROL_CLIENT_NAME].parsed_value;
|
|
const char *action =
|
|
(const char *) v[CONTROL_PUSH_ACTION].parsed_value;
|
|
|
|
if ((client != NULL && strcasecmp(client, cls) == 0) ||
|
|
(action != NULL && strncasecmp(action, cls, n) == 0))
|
|
return True;
|
|
}
|
|
}
|
|
return False;
|
|
}
|
|
|
|
/* bring PCD forward, on its workspace */
|
|
static void
|
|
Raise(ClientData *pCD)
|
|
{
|
|
WmScreenData *pSD = PSD_FOR_CLIENT(pCD);
|
|
|
|
if (!ClientInWorkspace(pSD->pActiveWS, pCD) && pCD->numInhabited > 0) {
|
|
WmWorkspaceData *pWS = GetWorkspaceData(pSD,
|
|
pCD->pWsList[0].wsID);
|
|
|
|
if (pWS != NULL)
|
|
ChangeToWorkspace(pWS);
|
|
}
|
|
(void) F_Normalize_And_Raise(NULL, pCD, NULL);
|
|
}
|
|
|
|
/* the command that starts PCD's program again */
|
|
static void
|
|
CommandOf(ClientData *pCD, char *buf, size_t len)
|
|
{
|
|
char **argv = NULL;
|
|
int argc = 0, i;
|
|
size_t n = 0;
|
|
|
|
buf[0] = '\0';
|
|
if (XGetCommand(DISPLAY, pCD->client, &argv, &argc) && argc > 0) {
|
|
for (i = 0; i < argc && n + 4 < len; i++)
|
|
n += (size_t) snprintf(buf + n, len - n, "%s'%s'",
|
|
i > 0 ? " " : "", argv[i]);
|
|
XFreeStringList(argv);
|
|
if (strchr(buf, '\n') == NULL)
|
|
return;
|
|
}
|
|
{
|
|
Atom a = XInternAtom(DISPLAY, "_NET_WM_PID", False), type;
|
|
int format;
|
|
unsigned long items, after;
|
|
unsigned char *data = NULL;
|
|
|
|
if (XGetWindowProperty(DISPLAY, pCD->client, a, 0, 1, False,
|
|
XA_CARDINAL, &type, &format, &items, &after, &data) ==
|
|
Success && data != NULL && items == 1 &&
|
|
mcde_sys_process_command((pid_t) *(long *) data, buf,
|
|
len) == MCDE_SYS_OK && strchr(buf, '\n') == NULL) {
|
|
XFree(data);
|
|
return;
|
|
}
|
|
if (data != NULL)
|
|
XFree(data);
|
|
}
|
|
/* the class, in lower case: dtterm, xclock */
|
|
for (i = 0; pCD->clientClass[i] != '\0' && (size_t) i + 1 < len; i++)
|
|
buf[i] = (char) tolower((unsigned char) pCD->clientClass[i]);
|
|
buf[i] = '\0';
|
|
}
|
|
|
|
/* ---- the part ----------------------------------------------------------- */
|
|
|
|
static void Update(void);
|
|
|
|
static void
|
|
DebugGeometry(XtPointer data, XtIntervalId *id)
|
|
{
|
|
Widget p = XtParent(area), t = trash->icon;
|
|
|
|
(void) data;
|
|
(void) id;
|
|
fprintf(stderr, "dtwm panel: area %dx%d+%d managed %d; parent %dx%d; "
|
|
"trash +%d; shell %dx%d\n", XtWidth(area), XtHeight(area),
|
|
XtX(area), XtIsManaged(area), XtWidth(p), XtHeight(p), XtX(t),
|
|
XtWidth(panel.shell), XtHeight(panel.shell));
|
|
}
|
|
|
|
static void
|
|
Later(XtPointer data, XtIntervalId *id)
|
|
{
|
|
(void) data;
|
|
(void) id;
|
|
pending = 0;
|
|
Update();
|
|
}
|
|
|
|
void
|
|
McdePanelChanged(void)
|
|
{
|
|
if (area == NULL || pending != 0)
|
|
return;
|
|
pending = XtAppAddTimeOut(wmGD.mwmAppContext, 200, Later, NULL);
|
|
}
|
|
|
|
static void
|
|
Keep(int b)
|
|
{
|
|
ClientData *pCD = WindowOf(buttons[b].cls);
|
|
|
|
if (pCD == NULL || nkept >= MAX_APPS || KeptIndex(buttons[b].cls) >= 0)
|
|
return;
|
|
snprintf(kept[nkept].cls, sizeof kept[nkept].cls, "%s",
|
|
pCD->clientClass);
|
|
CommandOf(pCD, kept[nkept].cmd, sizeof kept[nkept].cmd);
|
|
nkept++;
|
|
WriteKept();
|
|
McdePanelChanged();
|
|
}
|
|
|
|
static void
|
|
Unkeep(int b)
|
|
{
|
|
int k = buttons[b].keptIndex;
|
|
|
|
if (k < 0)
|
|
return;
|
|
memmove(kept + k, kept + k + 1, (size_t) (nkept - k - 1) * sizeof kept[0]);
|
|
nkept--;
|
|
WriteKept();
|
|
McdePanelChanged();
|
|
}
|
|
|
|
static void
|
|
MenuChosen(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
(void) w;
|
|
(void) data;
|
|
(void) call;
|
|
if (menuFor < 0 || menuFor >= nbuttons)
|
|
return;
|
|
if (buttons[menuFor].keptIndex >= 0)
|
|
Unkeep(menuFor);
|
|
else
|
|
Keep(menuFor);
|
|
}
|
|
|
|
static void
|
|
Clicked(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
int b = (int) (intptr_t) data;
|
|
ClientData *pCD;
|
|
|
|
(void) w;
|
|
(void) call;
|
|
if (b < 0 || b >= nbuttons)
|
|
return;
|
|
if ((pCD = WindowOf(buttons[b].cls)) != NULL)
|
|
Raise(pCD);
|
|
else if (buttons[b].keptIndex >= 0)
|
|
(void) F_Exec(kept[buttons[b].keptIndex].cmd, NULL, NULL);
|
|
}
|
|
|
|
static void
|
|
PostMenu(int b, XButtonEvent *ev)
|
|
{
|
|
XmString s;
|
|
|
|
menuFor = b;
|
|
s = XmStringCreateLocalized(buttons[b].keptIndex >= 0 ?
|
|
"Remove from Panel" : "Keep in Panel");
|
|
XtVaSetValues(menuItem, XmNlabelString, s, NULL);
|
|
XmStringFree(s);
|
|
XmMenuPosition(menu, ev);
|
|
XtManageChild(menu);
|
|
}
|
|
|
|
Boolean
|
|
McdePanelPost(Widget form, XButtonEvent *ev)
|
|
{
|
|
Position ax, ay;
|
|
Widget g;
|
|
int b;
|
|
|
|
if (area == NULL || !XtIsManaged(area) || XtParent(area) != form)
|
|
return False;
|
|
ax = XtX(area);
|
|
ay = XtY(area);
|
|
if (ev->x < ax || ev->y < ay || ev->x >= ax + (int) XtWidth(area) ||
|
|
ev->y >= ay + (int) XtHeight(area))
|
|
return False;
|
|
g = XmObjectAtPoint(area, (Position) (ev->x - ax),
|
|
(Position) (ev->y - ay));
|
|
for (b = 0; b < nbuttons; b++)
|
|
if (buttons[b].w == g) {
|
|
PostMenu(b, ev);
|
|
return True;
|
|
}
|
|
return True; /* the part, between buttons: no menu of CDE's */
|
|
}
|
|
|
|
/* the right button: the menu; the left one dragged out to the left: keep.
|
|
* The buttons are gadgets (_DtCreateControl): their events come to the
|
|
* part, which finds the button under the pointer (XmObjectAtPoint). */
|
|
static int pressedButton = -1;
|
|
|
|
static void
|
|
Pressed(Widget w, XtPointer data, XEvent *ev, Boolean *cont)
|
|
{
|
|
int b;
|
|
Widget g;
|
|
|
|
(void) cont;
|
|
(void) data;
|
|
if (getenv("MCDE_PANEL_DEBUG"))
|
|
fprintf(stderr, "dtwm panel: %s button %u at %d,%d\n",
|
|
ev->type == ButtonPress ? "press" : "release",
|
|
ev->xbutton.button, ev->xbutton.x, ev->xbutton.y);
|
|
if (ev->type == ButtonRelease && ev->xbutton.button == Button1)
|
|
b = pressedButton;
|
|
else {
|
|
g = XmObjectAtPoint(w, (Position) ev->xbutton.x,
|
|
(Position) ev->xbutton.y);
|
|
for (b = 0; b < nbuttons; b++)
|
|
if (buttons[b].w == g)
|
|
break;
|
|
if (b == nbuttons)
|
|
return;
|
|
}
|
|
if (b < 0 || b >= nbuttons)
|
|
return;
|
|
if (ev->type == ButtonPress && ev->xbutton.button == Button1)
|
|
pressedButton = b;
|
|
if (ev->type == ButtonPress && ev->xbutton.button == Button1) {
|
|
pressX = ev->xbutton.x_root;
|
|
return;
|
|
}
|
|
if (ev->type == ButtonRelease && ev->xbutton.button == Button1) {
|
|
Position ax = 0, ay = 0;
|
|
|
|
XtTranslateCoords(area, 0, 0, &ax, &ay);
|
|
/* let go left of the part, having moved there */
|
|
if (buttons[b].keptIndex < 0 && ev->xbutton.x_root < ax &&
|
|
pressX - ev->xbutton.x_root > 8)
|
|
Keep(b);
|
|
return;
|
|
}
|
|
if (ev->type != ButtonPress || ev->xbutton.button != Button3)
|
|
return;
|
|
PostMenu(b, &ev->xbutton);
|
|
}
|
|
|
|
static void
|
|
AddButton(const char *cls, int keptIndex)
|
|
{
|
|
Widget w;
|
|
Arg al[16];
|
|
int ac = 0;
|
|
String icon;
|
|
char lower[64];
|
|
size_t i;
|
|
|
|
if (nbuttons >= MAX_APPS)
|
|
return;
|
|
/* the class's icon, as CDE names them (Dtterm, Dtcalc), else in
|
|
* lower case, else the icon of an action */
|
|
icon = _DtGetIconFileName(XtScreen(area), (String) cls, NULL, NULL,
|
|
panel.main_icon_size);
|
|
if (icon == NULL) {
|
|
for (i = 0; cls[i] != '\0' && i + 1 < sizeof lower; i++)
|
|
lower[i] = (char) tolower((unsigned char) cls[i]);
|
|
lower[i] = '\0';
|
|
icon = _DtGetIconFileName(XtScreen(area), lower, NULL, NULL,
|
|
panel.main_icon_size);
|
|
}
|
|
if (icon == NULL)
|
|
icon = GetIconName("Dtactn", panel.main_icon_size);
|
|
XtSetArg(al[ac], XmNbackground, panel.primary_pixel_set->bg); ac++;
|
|
XtSetArg(al[ac], XmNforeground, panel.primary_pixel_set->fg); ac++;
|
|
XtSetArg(al[ac], XmNarmColor, panel.primary_pixel_set->sc); ac++;
|
|
XtSetArg(al[ac], XmNpixmapBackground, panel.primary_pixel_set->bg); ac++;
|
|
XtSetArg(al[ac], XmNpixmapForeground, panel.primary_pixel_set->fg); ac++;
|
|
XtSetArg(al[ac], XmNpixmapPosition, XmPIXMAP_TOP); ac++;
|
|
XtSetArg(al[ac], XmNimageName, icon); ac++;
|
|
XtSetArg(al[ac], XmNstring, NULL); ac++;
|
|
XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
|
|
XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
|
|
if (nbuttons == 0) {
|
|
XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
|
|
} else {
|
|
XtSetArg(al[ac], XmNleftAttachment, XmATTACH_WIDGET); ac++;
|
|
XtSetArg(al[ac], XmNleftWidget, buttons[nbuttons - 1].w); ac++;
|
|
}
|
|
w = _DtCreateControl(area, "mcdeApp", al, ac);
|
|
XtFree(icon);
|
|
XtManageChild(w);
|
|
XtAddCallback(w, XmNcallback, Clicked, (XtPointer) (intptr_t) nbuttons);
|
|
buttons[nbuttons].w = w;
|
|
snprintf(buttons[nbuttons].cls, sizeof buttons[nbuttons].cls, "%s", cls);
|
|
buttons[nbuttons].keptIndex = keptIndex;
|
|
nbuttons++;
|
|
}
|
|
|
|
/* the panel grows by what the part did not get: with a session's
|
|
* geometry the panel's shell did not grow by itself, and the form squeezed
|
|
* the part to a pixel (measured in a dtsession); shrinking likewise */
|
|
static Dimension shown;
|
|
|
|
static void
|
|
Grow(XtPointer data, XtIntervalId *id)
|
|
{
|
|
Dimension want = (Dimension) (intptr_t) data, have = XtWidth(area);
|
|
int delta = (int) want - (int) have;
|
|
|
|
(void) id;
|
|
if (delta == 0 || !XtIsManaged(area))
|
|
return;
|
|
XtVaSetValues(panel.shell, XmNwidth,
|
|
(Dimension) ((int) XtWidth(panel.shell) + delta), NULL);
|
|
/* the form squeezed the part while there was no room; now there is */
|
|
XtVaSetValues(area, XmNwidth, want, NULL);
|
|
XtVaSetValues(spacer, XmNwidth, want, NULL);
|
|
}
|
|
|
|
static void
|
|
Update(void)
|
|
{
|
|
WmScreenData *pSD = ACTIVE_PSD;
|
|
ClientListEntry *e;
|
|
Dimension width = 0;
|
|
int i, j;
|
|
|
|
if (area == NULL)
|
|
return;
|
|
for (i = 0; i < nbuttons; i++)
|
|
XtDestroyWidget(buttons[i].w);
|
|
nbuttons = 0;
|
|
for (i = 0; i < nkept; i++)
|
|
AddButton(kept[i].cls, i);
|
|
for (e = pSD->clientList; e != NULL; e = e->nextSibling) {
|
|
ClientData *pCD = e->pCD;
|
|
|
|
if (pCD == NULL || e != &pCD->clientEntry || !IsProgram(pCD) ||
|
|
KeptIndex(pCD->clientClass) >= 0 ||
|
|
InPanel(pCD->clientClass))
|
|
continue;
|
|
for (j = 0; j < nbuttons; j++)
|
|
if (strcasecmp(buttons[j].cls, pCD->clientClass) == 0)
|
|
break;
|
|
if (j == nbuttons)
|
|
AddButton(pCD->clientClass, -1);
|
|
}
|
|
if (getenv("MCDE_PANEL_DEBUG"))
|
|
fprintf(stderr, "dtwm panel: %d buttons (%d kept)\n", nbuttons,
|
|
nkept);
|
|
if (nbuttons == 0) {
|
|
if (XtIsManaged(area) && shown > 1)
|
|
XtVaSetValues(panel.shell, XmNwidth, (Dimension)
|
|
((int) XtWidth(panel.shell) - (int) shown), NULL);
|
|
shown = 0;
|
|
XtUnmanageChild(area);
|
|
XtUnmanageChild(spacer);
|
|
return;
|
|
}
|
|
for (i = 0; i < nbuttons; i++) {
|
|
XtWidgetGeometry pref;
|
|
|
|
if (XtQueryGeometry(buttons[i].w, NULL, &pref) != XtGeometryNo &&
|
|
(pref.request_mode & CWWidth))
|
|
width += pref.width;
|
|
else
|
|
width += XtWidth(buttons[i].w);
|
|
}
|
|
/* the panel gives back what the part had: Grow asks only for the
|
|
* difference */
|
|
if (XtIsManaged(area) && shown > 1 && shown != width)
|
|
XtVaSetValues(panel.shell, XmNwidth, (Dimension)
|
|
((int) XtWidth(panel.shell) + (int) width - (int) shown),
|
|
NULL);
|
|
shown = width;
|
|
XtVaSetValues(area, XmNwidth, width, NULL);
|
|
XtVaSetValues(spacer, XmNwidth, width, NULL);
|
|
XtManageChild(area);
|
|
XtManageChild(spacer);
|
|
XtAppAddTimeOut(wmGD.mwmAppContext, 0, Grow, (XtPointer) (intptr_t) width);
|
|
if (getenv("MCDE_PANEL_DEBUG"))
|
|
XtAppAddTimeOut(wmGD.mwmAppContext, 500, DebugGeometry, NULL);
|
|
}
|
|
|
|
/* after the main panel's controls are made (UI.c, MainControlCreate) */
|
|
void
|
|
McdePanelCreate(void)
|
|
{
|
|
int i, j;
|
|
unsigned char att = XmATTACH_FORM;
|
|
Widget left = NULL;
|
|
Arg al[12];
|
|
int ac;
|
|
|
|
trash = NULL;
|
|
for (i = 0; i < panel.box_data_count && trash == NULL; i++)
|
|
for (j = 0; j < panel.box_data[i]->control_data_count; j++) {
|
|
ControlData *c = panel.box_data[i]->control_data[j];
|
|
const char *name =
|
|
(const char *) c->element_values[CONTROL_NAME].parsed_value;
|
|
|
|
if (name != NULL && strcmp(name, "Trash") == 0 &&
|
|
c->icon != NULL && c->arrow != NULL) {
|
|
trash = c;
|
|
break;
|
|
}
|
|
}
|
|
if (getenv("MCDE_PANEL_DEBUG"))
|
|
fprintf(stderr, "dtwm panel: create, trash %s\n",
|
|
trash != NULL ? "found" : "not found");
|
|
if (trash == NULL)
|
|
return;
|
|
ReadKept();
|
|
|
|
/* the part, in the control row before the trash */
|
|
XtVaGetValues(trash->icon, XmNleftAttachment, &att, XmNleftWidget,
|
|
&left, NULL);
|
|
/* the background of the row it sits in: a colour, or a pattern
|
|
* (UI.c gives the control forms a pixmap in some colour modes) */
|
|
{
|
|
Pixel bg;
|
|
Pixmap pm = XmUNSPECIFIED_PIXMAP;
|
|
|
|
XtVaGetValues(XtParent(trash->icon), XmNbackground, &bg,
|
|
XmNbackgroundPixmap, &pm, NULL);
|
|
ac = 0;
|
|
XtSetArg(al[ac], XmNbackground, bg); ac++;
|
|
if (pm != XmUNSPECIFIED_PIXMAP && pm != None) {
|
|
XtSetArg(al[ac], XmNbackgroundPixmap, pm); ac++;
|
|
}
|
|
}
|
|
XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
|
|
XtSetArg(al[ac], XmNtopOffset, 1); ac++;
|
|
XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
|
|
XtSetArg(al[ac], XmNbottomOffset, 1); ac++;
|
|
XtSetArg(al[ac], XmNleftAttachment, att); ac++;
|
|
if (att == XmATTACH_WIDGET) {
|
|
XtSetArg(al[ac], XmNleftWidget, left); ac++;
|
|
}
|
|
XtSetArg(al[ac], XmNresizePolicy, XmRESIZE_NONE); ac++;
|
|
XtSetArg(al[ac], XmNwidth, 1); ac++;
|
|
area = XmCreateForm(XtParent(trash->icon), "mcdeRunning", al, ac);
|
|
XtVaSetValues(trash->icon, XmNleftAttachment, XmATTACH_WIDGET,
|
|
XmNleftWidget, area, NULL);
|
|
|
|
/* its blank in the arrow row, before the trash's arrow */
|
|
att = XmATTACH_FORM;
|
|
left = NULL;
|
|
XtVaGetValues(trash->arrow, XmNleftAttachment, &att, XmNleftWidget,
|
|
&left, NULL);
|
|
{
|
|
Pixel bg;
|
|
Pixmap pm = XmUNSPECIFIED_PIXMAP;
|
|
|
|
XtVaGetValues(trash->arrow, XmNbackground, &bg, NULL);
|
|
XtVaGetValues(XtParent(trash->arrow), XmNbackgroundPixmap, &pm,
|
|
NULL);
|
|
ac = 0;
|
|
XtSetArg(al[ac], XmNbackground, bg); ac++;
|
|
if (pm != XmUNSPECIFIED_PIXMAP && pm != None) {
|
|
XtSetArg(al[ac], XmNbackgroundPixmap, pm); ac++;
|
|
}
|
|
}
|
|
XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
|
|
XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
|
|
XtSetArg(al[ac], XmNleftAttachment, att); ac++;
|
|
if (att == XmATTACH_WIDGET) {
|
|
XtSetArg(al[ac], XmNleftWidget, left); ac++;
|
|
}
|
|
XtSetArg(al[ac], XmNrecomputeSize, False); ac++;
|
|
XtSetArg(al[ac], XmNwidth, 1); ac++;
|
|
{
|
|
XmString empty = XmStringCreateLocalized("");
|
|
|
|
XtSetArg(al[ac], XmNlabelString, empty); ac++;
|
|
spacer = XmCreateLabel(XtParent(trash->arrow),
|
|
"mcdeRunningArrows", al, ac);
|
|
XmStringFree(empty);
|
|
}
|
|
XtVaSetValues(trash->arrow, XmNleftAttachment, XmATTACH_WIDGET,
|
|
XmNleftWidget, spacer, NULL);
|
|
|
|
XtAddEventHandler(area, ButtonPressMask | ButtonReleaseMask, False,
|
|
Pressed, NULL);
|
|
|
|
/* the menu of the right button */
|
|
menu = XmCreatePopupMenu(area, "mcdeRunningMenu", NULL, 0);
|
|
menuItem = XmCreatePushButton(menu, "keep", NULL, 0);
|
|
XtAddCallback(menuItem, XmNactivateCallback, MenuChosen, NULL);
|
|
XtManageChild(menuItem);
|
|
|
|
Update();
|
|
}
|