diff --git a/AGENTS.md b/AGENTS.md index fc650e60..096137a6 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -185,19 +185,17 @@ narratives and test notes, is `docs/reference/mcde-agents-history-2026-11-13.txt half), out to the right unkeeps it. No clock in the panel (the bar has it). Actions at the end of `types/dt.dt.src` take no shell variables and no `CDE_INSTALLATION_TOP` inside `'...'` (`docs/reference/frontpanel.txt`). - Not done: dragging an icon into a drawer (subpanel) or out of one; the - drawers' CDE install zone accepts dropped files, not panel icons (open - point, t0258). Measured on 2026-11-16 while trying it: the drop itself and - ~/.dt/panel-drawers work (class, command and the dock icon that goes away), - and a control added to a subpanel's form is created (widget, icon file), - but it is invisible -- the drawer is sized by SubpanelCreate before the - widget exists and does not grow (a height set on the shell and the form - afterwards is not used when the drawer is posted). A hook before - XtRealizeWidget(form) (McdePanelFillDrawer) ran in neither test; the - experiment was taken back out. Next way: a CONTROL record in - ~/.dt/types/fp_dynamic/ plus a panel restart (dtwm has no panel reload, so - F_Restart), or create the extra controls inside SubpanelCreate before the - form is realized -- then the drawer is sized for them. + An icon dragged from the dock onto a drawer's control in the main row goes + into that drawer: WmMcdePanel.c writes `~/.dt/panel-drawers` + (`SUBPANEL CLASS COMMAND`), the program leaves the dock, and an + icon dragged out of a drawer onto the dock is kept there and leaves the + file. The stored icons join the layout at the end of SubpanelCreate + (`McdePanelFillDrawer`), and the last one holds the form's bottom (as CDE's + own last control does), so a drawer is created as high as its contents -- + the earlier attempt added a widget to a realized form, where it stayed + outside the drawer's height (measured 2026-11-16). An icon added while the + session runs shows in the drawer after the next session: the posted + drawer's shell keeps the height it had when it was created. - **Pictures**: PNG goes through `McdeImageGetPixmap` (libpng), because Motif 2.3.8 draws an RGB PNG as its blue channel only (`docs/reference/motif-png.txt`); free with `McdeImageFreePixmap`. diff --git a/programs/dtwm/UI.c b/programs/dtwm/UI.c index bdbb4664..a4a24a3d 100644 --- a/programs/dtwm/UI.c +++ b/programs/dtwm/UI.c @@ -2967,6 +2967,10 @@ SubpanelCreate (ControlData * main_control_data, XtSetValues (subpanel_data->form, al, 1); + /* MCDE: the icons stored for this drawer join the layout here, after the + * CDE controls, so the drawer is sized for them (WmMcdePanel.c) */ + McdePanelFillDrawer (subpanel_data); + } @@ -3258,6 +3262,10 @@ AddSubpanel (ControlData * control_data) XtSetArg (al[0], XmNtransientFor, panel.shell); XtSetValues (subpanel_data->shell, al, 1); + /* MCDE: the icons stored for this drawer join the layout before the form + * is realized, so the drawer is sized for them (WmMcdePanel.c) */ + McdePanelFillDrawer (subpanel_data); + XtRealizeWidget (subpanel_data->form); _DtWsmSetDtWmHints (XtDisplay (panel.shell), XtWindow (subpanel_data->shell), &vHints); diff --git a/programs/dtwm/WmMcdePanel.c b/programs/dtwm/WmMcdePanel.c index cf6c5af7..64d9fc28 100644 --- a/programs/dtwm/WmMcdePanel.c +++ b/programs/dtwm/WmMcdePanel.c @@ -68,6 +68,10 @@ typedef struct { static Kept kept[MAX_APPS]; static int nkept; +static ClientData *WindowOf(const char *cls); +static void Raise(ClientData *pCD); +static void KeepClass(const char *cls, const char *cmd); + static Widget area, spacer, menu, menuItem, separator, prevWidget; static ControlData *trash, *anchor; static XtIntervalId pending; @@ -142,6 +146,379 @@ KeptIndex(const char *cls) return -1; } +/* ---- the drawers (subpanels) -------------------------------------------- */ + +/* A program can be dragged from the dock into a drawer and back. The + * drawer's form is CDE's (UI.c, SubpanelCreate); the icons stored for it in + * ~/.dt/panel-drawers are added before the form is realized (UI.c, + * AddSubpanel calls McdePanelFillDrawer), so the drawer is sized for them. + * An icon dropped on a drawer's main-row control goes in at once; it shows + * after the next session if the drawer was already full (it does not grow + * once posted). */ + +typedef struct { + char sub[64]; /* SUBPANEL name, e.g. FilesSubpanel */ + char cls[64]; + char cmd[1024]; + Widget w; +} DrawerIcon; + +static DrawerIcon drawerIcons[MAX_APPS]; +static int ndrawerIcons, drawersRead; + +static void +DrawerFile(char *buf, size_t len) +{ + const char *home = getenv("HOME"); + + snprintf(buf, len, "%s/.dt/panel-drawers", home != NULL ? home : "."); +} + +static void +ReadDrawers(void) +{ + char path[1100], line[1400], *t1, *t2; + FILE *fp; + + ndrawerIcons = 0; + drawersRead = 1; + DrawerFile(path, sizeof path); + if ((fp = fopen(path, "r")) == NULL) + return; + while (ndrawerIcons < MAX_APPS && fgets(line, sizeof line, fp) != NULL) { + line[strcspn(line, "\r\n")] = '\0'; + if (line[0] == '#' || (t1 = strchr(line, '\t')) == NULL) + continue; + *t1++ = '\0'; + if ((t2 = strchr(t1, '\t')) == NULL) + continue; + *t2++ = '\0'; + snprintf(drawerIcons[ndrawerIcons].sub, + sizeof drawerIcons[0].sub, "%s", line); + snprintf(drawerIcons[ndrawerIcons].cls, + sizeof drawerIcons[0].cls, "%s", t1); + snprintf(drawerIcons[ndrawerIcons].cmd, + sizeof drawerIcons[0].cmd, "%s", t2); + ndrawerIcons++; + } + fclose(fp); +} + +static void +WriteDrawers(void) +{ + char path[1100], tmp[1200]; + FILE *fp; + int i; + + DrawerFile(path, sizeof path); + snprintf(tmp, sizeof tmp, "%s.new", path); + if ((fp = fopen(tmp, "w")) == NULL) + return; + fprintf(fp, "# programs in the front panel's drawers: SUBPANEL " + "CLASS COMMAND (MCDE dtwm)\n"); + for (i = 0; i < ndrawerIcons; i++) + fprintf(fp, "%s\t%s\t%s\n", drawerIcons[i].sub, + drawerIcons[i].cls, drawerIcons[i].cmd); + if (fclose(fp) == 0) + (void) rename(tmp, path); +} + +static int +InDrawer(const char *cls) +{ + int i; + + for (i = 0; i < ndrawerIcons; i++) + if (strcasecmp(drawerIcons[i].cls, cls) == 0) + return i; + return -1; +} + +static SubpanelData * +SubpanelByName(const char *name) +{ + int i, j; + + if (name == NULL) + return NULL; + for (i = 0; i < panel.box_data_count; i++) + for (j = 0; j < panel.box_data[i]->control_data_count; + j++) { + ControlData *c = panel.box_data[i]->control_data[j]; + const char *n; + + if (c->subpanel_data == NULL) + continue; + n = (const char *) c->subpanel_data-> + element_values[SUBPANEL_NAME].parsed_value; + if (n != NULL && strcmp(n, name) == 0) + return c->subpanel_data; + } + return NULL; +} + +/* the drawer whose main-row icon is at a root position, or NULL */ +static SubpanelData * +SubpanelAtRoot(int xr, int yr) +{ + int i, j; + + for (i = 0; i < panel.box_data_count; i++) + for (j = 0; j < panel.box_data[i]->control_data_count; + j++) { + ControlData *c = panel.box_data[i]->control_data[j]; + Position x = 0, y = 0; + Dimension w = 0, h = 0; + + if (c->subpanel_data == NULL || c->icon == NULL || + !XtIsManaged(c->icon)) + continue; + XtTranslateCoords(c->icon, 0, 0, &x, &y); + XtVaGetValues(c->icon, XmNwidth, &w, XmNheight, &h, + NULL); + if (xr >= x && xr < x + (int) w && yr >= y && + yr < y + (int) h) + return c->subpanel_data; + } + return NULL; +} + +static void +DrawerClicked(Widget w, XtPointer data, XtCallbackProc call) +{ + int i = (int) (intptr_t) data; + ClientData *pCD; + + (void) w; + (void) call; + if (i < 0 || i >= ndrawerIcons) + return; + if ((pCD = WindowOf(drawerIcons[i].cls)) != NULL) + Raise(pCD); + else + (void) F_Exec(drawerIcons[i].cmd, NULL, NULL); +} + +/* drag an icon out of a drawer onto the dock: it is kept there. The handler + * sits on the drawer's form: _DtCreateControl makes a gadget, and a gadget + * has no window for an event handler (a segfault, measured 2026-11-16). */ +static int drawerPressed = -1; + +static void +DrawerFormPressed(Widget form, XtPointer data, XEvent *ev, Boolean *cont) +{ + Position ax = 0, ay = 0; + Dimension aw = 0, ah = 0; + Widget g; + int j; + + (void) data; + (void) cont; + g = XmObjectAtPoint(form, (Position) ev->xbutton.x, + (Position) ev->xbutton.y); + if (ev->type == ButtonPress && ev->xbutton.button == Button1) { + drawerPressed = -1; + for (j = 0; j < ndrawerIcons; j++) + if (drawerIcons[j].w == g) { + drawerPressed = j; + break; + } + return; + } + if (ev->type != ButtonRelease || ev->xbutton.button != Button1 || + drawerPressed < 0 || drawerPressed >= ndrawerIcons) + return; + j = drawerPressed; + drawerPressed = -1; + if (area == NULL || !XtIsManaged(area)) + return; + XtTranslateCoords(area, 0, 0, &ax, &ay); + XtVaGetValues(area, XmNwidth, &aw, XmNheight, &ah, NULL); + if (ev->xbutton.x_root < ax || ev->xbutton.x_root >= ax + (int) aw || + ev->xbutton.y_root < ay || ev->xbutton.y_root >= ay + (int) ah) + return; + { + char cls[64], cmd[1024]; + + snprintf(cls, sizeof cls, "%s", drawerIcons[j].cls); + snprintf(cmd, sizeof cmd, "%s", drawerIcons[j].cmd); + if (drawerIcons[j].w != NULL) + XtDestroyWidget(drawerIcons[j].w); + memmove(drawerIcons + j, drawerIcons + j + 1, + (size_t) (ndrawerIcons - j - 1) * sizeof drawerIcons[0]); + ndrawerIcons--; + WriteDrawers(); + KeepClass(cls, cmd); + } +} + +static void +AddDrawerWidget(int idx) +{ + SubpanelData *sp = SubpanelByName(drawerIcons[idx].sub); + Widget form, *kids = NULL, below = NULL; + Cardinal n = 0, k; + Arg al[20]; + int ac = 0; + String icon; + char lower[64]; + size_t i; + XmString label; + + if (sp == NULL || sp->form == NULL) + return; + form = sp->form; + XtVaGetValues(form, XmNchildren, &kids, XmNnumChildren, &n, NULL); + for (k = n; k > 0; k--) + if (XtIsManaged(kids[k - 1])) { + below = kids[k - 1]; + break; + } + icon = _DtGetIconFileName(XtScreen(form), (String) drawerIcons[idx].cls, + NULL, NULL, panel.sub_icon_size); + if (icon == NULL) { + for (i = 0; drawerIcons[idx].cls[i] != '\0' && + i + 1 < sizeof lower; i++) + lower[i] = (char) tolower((unsigned char) + drawerIcons[idx].cls[i]); + lower[i] = '\0'; + icon = _DtGetIconFileName(XtScreen(form), lower, NULL, NULL, + panel.sub_icon_size); + } + if (icon == NULL) + icon = GetIconName("Dtactn", panel.sub_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++; + label = XmStringCreateLocalized(drawerIcons[idx].cls); + XtSetArg(al[ac], XmNstring, label); ac++; + XtSetArg(al[ac], XmNfontList, panel.font_list); ac++; + XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++; + XtSetArg(al[ac], XmNleftOffset, 5); ac++; + XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++; + XtSetArg(al[ac], XmNrightOffset, 5); ac++; + XtSetArg(al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++; + XtSetArg(al[ac], XmNtopWidget, below); ac++; + XtSetArg(al[ac], XmNtopOffset, 5); ac++; + /* the last icon holds the form's bottom, as CDE's own last control + * does (UI.c, SubpanelControlCreate): that is what makes the form -- + * and with it the drawer -- as high as its contents */ + if (below != NULL) + XtVaSetValues(below, XmNbottomAttachment, XmATTACH_NONE, + NULL); + XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++; + XtSetArg(al[ac], XmNbottomOffset, 5); ac++; + drawerIcons[idx].w = _DtCreateControl(form, "mcdeDrawerApp", al, ac); + XmStringFree(label); + XtFree(icon); + XtManageChild(drawerIcons[idx].w); + XtAddCallback(drawerIcons[idx].w, XmNcallback, DrawerClicked, + (XtPointer) (intptr_t) idx); + { + static Widget forms[8]; + static int nforms; + int f, known = 0; + + for (f = 0; f < nforms; f++) + if (forms[f] == form) + known = 1; + if (!known && nforms < 8) { + forms[nforms++] = form; + XtAddEventHandler(form, ButtonPressMask | + ButtonReleaseMask, False, DrawerFormPressed, + NULL); + } + } + if (getenv("MCDE_PANEL_DEBUG") != NULL) + fprintf(stderr, "dtwm panel: drawer icon %s in %s (widget %p, " + "below %p, realized %d)\n", drawerIcons[idx].cls, + drawerIcons[idx].sub, (void *) drawerIcons[idx].w, + (void *) below, XtIsRealized(form)); + +} + +/* UI.c, AddSubpanel: the stored icons join the layout of a drawer before its + * form is realized, so the drawer is created with the room for them */ +void +McdePanelFillDrawer(void *subpanel) +{ + SubpanelData *sp = (SubpanelData *) subpanel; + const char *name; + int i; + + if (sp == NULL) + return; + if (!drawersRead) + ReadDrawers(); + name = (const char *) sp->element_values[SUBPANEL_NAME].parsed_value; + if (name == NULL) + return; + { + int last = -1; + + for (i = 0; i < ndrawerIcons; i++) + if (strcmp(drawerIcons[i].sub, name) == 0 && + drawerIcons[i].w == NULL) { + AddDrawerWidget(i); + if (drawerIcons[i].w != NULL) + last = i; + } + /* the form is realized with its children; without the height of + * the last added icon it stays at the size CDE gave it and the + * icon sits outside (measured 2026-11-16) */ + if (last >= 0) { + Dimension y = 0, h = 0, want; + + XtVaGetValues(drawerIcons[last].w, XmNy, &y, + XmNheight, &h, NULL); + want = (Dimension) (y + h + 8); + if (getenv("MCDE_PANEL_DEBUG") != NULL) + fprintf(stderr, "dtwm panel: drawer '%s' to " + "%d pixel high for %d icons\n", name, + (int) want, ndrawerIcons); + XtVaSetValues(sp->form, XmNheight, want, NULL); + if (sp->shell != NULL) + XtVaSetValues(sp->shell, XmNheight, want, NULL); + } + } +} + +static void +AddToDrawer(SubpanelData *sp, const char *cls, const char *cmd) +{ + const char *name; + int i; + + if (sp == NULL || InDrawer(cls) >= 0 || ndrawerIcons >= MAX_APPS) + return; + name = (const char *) sp->element_values[SUBPANEL_NAME].parsed_value; + if (name == NULL) + return; + i = ndrawerIcons++; + snprintf(drawerIcons[i].sub, sizeof drawerIcons[0].sub, "%s", name); + snprintf(drawerIcons[i].cls, sizeof drawerIcons[0].cls, "%s", cls); + snprintf(drawerIcons[i].cmd, sizeof drawerIcons[0].cmd, "%s", cmd); + drawerIcons[i].w = NULL; + AddDrawerWidget(i); + WriteDrawers(); + if (KeptIndex(cls) >= 0) { + int k = KeptIndex(cls); + + memmove(kept + k, kept + k + 1, + (size_t) (nkept - k - 1) * sizeof kept[0]); + nkept--; + WriteKept(); + } + McdePanelChanged(); +} + /* ---- the windows -------------------------------------------------------- */ /* a program's window of its own: not a transient, not dtwm's panels */ @@ -308,20 +685,34 @@ McdePanelChanged(void) } static void -Keep(int b) +KeepClass(const char *cls, const char *cmd) { - ClientData *pCD = WindowOf(buttons[b].cls); - - if (pCD == NULL || nkept >= MAX_APPS || KeptIndex(buttons[b].cls) >= 0) + if (nkept >= MAX_APPS || KeptIndex(cls) >= 0) return; - snprintf(kept[nkept].cls, sizeof kept[nkept].cls, "%s", - pCD->clientClass); - CommandOf(pCD, kept[nkept].cmd, sizeof kept[nkept].cmd); + snprintf(kept[nkept].cls, sizeof kept[nkept].cls, "%s", cls); + snprintf(kept[nkept].cmd, sizeof kept[nkept].cmd, "%s", cmd); nkept++; WriteKept(); McdePanelChanged(); } +static void +KeepClient(ClientData *pCD) +{ + char cmd[1024]; + + if (pCD == NULL) + return; + CommandOf(pCD, cmd, sizeof cmd); + KeepClass(pCD->clientClass, cmd); +} + +static void +Keep(int b) +{ + KeepClient(WindowOf(buttons[b].cls)); +} + static void Unkeep(int b) { @@ -488,6 +879,27 @@ Pressed(Widget w, XtPointer data, XEvent *ev, Boolean *cont) XtTranslateCoords(area, 0, 0, &ax, &ay); zone = ZoneAtRoot(ev->xbutton.x_root, ev->xbutton.y_root); + /* dropped on a drawer's icon in the main row: into the drawer */ + if (zone == 0) { + SubpanelData *sp = SubpanelAtRoot(ev->xbutton.x_root, + ev->xbutton.y_root); + + if (sp != NULL) { + char cmd[1024]; + + if (buttons[b].keptIndex >= 0) + snprintf(cmd, sizeof cmd, "%s", + kept[buttons[b].keptIndex].cmd); + else if (WindowOf(buttons[b].cls) != NULL) + CommandOf(WindowOf(buttons[b].cls), cmd, + sizeof cmd); + else + cmd[0] = '\0'; + if (cmd[0] != '\0') + AddToDrawer(sp, buttons[b].cls, cmd); + return; + } + } /* dropped on the kept half (left of the divider): keep */ if (zone == 1 && buttons[b].keptIndex < 0) Keep(b); @@ -699,6 +1111,7 @@ Update(void) if (pCD == NULL || e != &pCD->clientEntry || !IsProgram(pCD) || KeptIndex(pCD->clientClass) >= 0 || + InDrawer(pCD->clientClass) >= 0 || InPanel(pCD->clientClass)) continue; for (j = 0; j < nrun; j++) @@ -819,6 +1232,8 @@ McdePanelCreate(void) if (trash == NULL || anchor == NULL) return; ReadKept(); + if (!drawersRead) + ReadDrawers(); /* the part, in the control row before the trash */ XtVaGetValues(anchor->icon, XmNleftAttachment, &att, XmNleftWidget, @@ -897,5 +1312,13 @@ McdePanelCreate(void) XtAddCallback(menuItem, XmNactivateCallback, MenuChosen, NULL); XtManageChild(menuItem); + { + int d; + + for (d = 0; d < ndrawerIcons; d++) + if (drawerIcons[d].w == NULL) + AddDrawerWidget(d); + } + Update(); } diff --git a/programs/dtwm/WmMcdePanel.h b/programs/dtwm/WmMcdePanel.h index fca77161..ca54a16d 100644 --- a/programs/dtwm/WmMcdePanel.h +++ b/programs/dtwm/WmMcdePanel.h @@ -12,6 +12,9 @@ /* after the main panel's controls are made (UI.c, MainControlCreate) */ extern void McdePanelCreate(void); +/* before a subpanel's form is realized (UI.c, AddSubpanel): the icons stored + * for that drawer become part of its layout, so the drawer is sized for them */ +extern void McdePanelFillDrawer(void *subpanel); /* the menu button pressed on FORM (PopupMenu.c, PostPopupMenu): True when * it was over the part, whose own menu is then posted */ extern Boolean McdePanelPost(Widget form, XButtonEvent *ev);