diff --git a/ext/src/mcde/AGENTS.md b/ext/src/mcde/AGENTS.md index e039ed7422..40a9791cd5 100644 --- a/ext/src/mcde/AGENTS.md +++ b/ext/src/mcde/AGENTS.md @@ -81,8 +81,16 @@ place of CDE; pkgsrc builds it on any platform from `pkgsrc/`. `include/Mcde/GlobalMenu.h` (a selection, properties, client messages); the program side is `lib/DtSvc/DtUtil2/McdeGlobalMenu.c`, started by `DtInitialize`, so every CDE program takes part without a change of its own - and without a Motif patch: an Xt create hook finds its XmMenuBar, the bar - hides it and shows its tree, a click calls the button's own callback. The + and without a change of its own: an Xt create hook finds its XmMenuBar, the + bar hides it (unmanaged) and shows its tree, a click calls the button's + own callback. Motif refuses the accelerators of an unmanaged menu bar + (RCPopup.c, AllWidgetsAccessible), so the hidden bar is marked with + `_XmMenuBarSetExported` (motif/lib/Xm/RowColumnP.h, our Motif) and its + shortcuts keep working -- dtpad Command+F with the bar running, tested. + A push button named options/preferences/settings/global (or labelled + Preferences, Options..., Settings..., Global...) without a shortcut gets + Command+comma, as on every desktop of that kind (dtterm: Global Options, + tested). The text form is `McdeMenuModel.c` with its test (`test_menumodel`, `make check`). A foreign window is registered with a hidden core widget, never with a shell (a shell stops on "Event with wrong window"). diff --git a/ext/src/mcde/lib/DtSvc/DtUtil2/McdeGlobalMenu.c b/ext/src/mcde/lib/DtSvc/DtUtil2/McdeGlobalMenu.c index b56374e915..8e7348223f 100644 --- a/ext/src/mcde/lib/DtSvc/DtUtil2/McdeGlobalMenu.c +++ b/ext/src/mcde/lib/DtSvc/DtUtil2/McdeGlobalMenu.c @@ -27,6 +27,7 @@ #include #include #include +#include /* _XmMenuBarSetExported: MCDE's Motif */ #include #include #include @@ -118,6 +119,47 @@ LabelText(Widget w, const char *resource, char *buf, size_t len) XmStringFree(xs); } +/* + * Command+, opens a program's settings, in every program (Konrad: "cmd + , + * for preferences in whatever (dt) app is in focus"). CDE's programs name + * that item differently -- dtcm "options", dtfile "setPreferences", dtmail + * "Mail Options...", dtterm "Global..." -- so an item is found by its + * widget name or its English label, and gets the shortcut if it has none. + * A menu of switches called "options" (dtpad, dtcalc) is no settings item: + * only push buttons count. + */ +static Boolean +IsSettingsItem(Widget w, const char *label) +{ + static const char *const names[] = { "options", "setPreferences", + "preferences", "settings", "global", "Mail Options...", NULL }; + static const char *const labels[] = { "Preferences", "Set Preferences", + "Options...", "Mail Options...", "Global...", "Settings...", NULL }; + const char *n = XtName(w); + int i; + + for (i = 0; names[i] != NULL; i++) + if (strcmp(n, names[i]) == 0) + return True; + for (i = 0; labels[i] != NULL; i++) + if (strncmp(label, labels[i], strlen(labels[i])) == 0) + return True; + return False; +} + +static void +SettingsShortcut(Widget w, const char *label, const char *accelText) +{ + XmString t; + + if (accelText[0] != '\0' || !IsSettingsItem(w, label)) + return; + t = XmStringCreateLocalized("Cmd+,"); + XtVaSetValues(w, XmNaccelerator, "Mod4comma", + XmNacceleratorText, t, NULL); + XmStringFree(t); +} + static void Walk(Exported *e, Widget rc, int depth, McdeMenuItem *items) { @@ -169,6 +211,11 @@ Walk(Exported *e, Widget rc, int depth, McdeMenuItem *items) if (m->kind == MCDE_MENU_PUSH || m->kind == MCDE_MENU_TOGGLE) LabelText(w, XmNacceleratorText, m->accelerator, sizeof m->accelerator); + if (m->kind == MCDE_MENU_PUSH) { + SettingsShortcut(w, m->label, m->accelerator); + LabelText(w, XmNacceleratorText, m->accelerator, + sizeof m->accelerator); + } } e->items[e->count++] = w; if (sub != NULL) @@ -220,6 +267,8 @@ Place(Exported *e) if (!Alive(mb) || ShellOf(mb) != e->shell) continue; + /* hidden, but its accelerators (Command+F, ...) still work */ + _XmMenuBarSetExported(mb, bar != None); if (bar != None && XtIsManaged(mb)) XtUnmanageChild(mb); else if (bar == None && !XtIsManaged(mb)) @@ -243,8 +292,10 @@ ChangeHook(Widget w, XtPointer client, XtPointer call) return; for (i = 0; i < nmenubars; i++) if (Alive(menubars[i]) && XtParent(menubars[i]) == d->widget && - XtIsManaged(menubars[i])) + XtIsManaged(menubars[i])) { + _XmMenuBarSetExported(menubars[i], True); XtUnmanageChild(menubars[i]); + } } /* the cascades are told they open, so that they bring their entries up to diff --git a/ext/src/mcde/motif/lib/Xm/RCPopup.c b/ext/src/mcde/motif/lib/Xm/RCPopup.c index 2ee6f4e0bd..a715cd4b7b 100644 --- a/ext/src/mcde/motif/lib/Xm/RCPopup.c +++ b/ext/src/mcde/motif/lib/Xm/RCPopup.c @@ -44,6 +44,7 @@ static char *rcsid = "$XConsortium: RCPopup.c /main/7 1996/03/28 15:15:24 daniel #include #include #include +#include #include #include #include @@ -1097,13 +1098,48 @@ MatchInKeyboardList( * accessible if it, and its ancestors, are both sensitive and * managed. This is useful for MenuBars and Option Menus only. */ +/* MCDE: menu bars the global menu shows in the desktop's top bar; their + * window hides them (unmanaged), the accelerators stay (RowColumnP.h) */ +static XContext exportedContext = 0; + +void +_XmMenuBarSetExported(Widget bar, Boolean exported) +{ + XtPointer v; + + if (bar == NULL || !XtIsWidget(bar)) + return; + if (exportedContext == 0) + exportedContext = XUniqueContext(); + if (exported) + XSaveContext(XtDisplay(bar), (XID) bar, exportedContext, + (XPointer) bar); + else if (XFindContext(XtDisplay(bar), (XID) bar, exportedContext, + (XPointer *) &v) == 0) + XDeleteContext(XtDisplay(bar), (XID) bar, exportedContext); +} + +static Boolean +IsExported(Widget w) +{ + XPointer v; + + return exportedContext != 0 && XtIsWidget(w) && + XFindContext(XtDisplay(w), (XID) w, exportedContext, &v) == 0; +} + static Boolean AllWidgetsAccessible( Widget w ) { + Widget bar = w; + while (w && XtParent(w) && !XtIsShell(w)) { - if (!XtIsSensitive(w) || !XtIsManaged(w) || !w->core.mapped_when_managed) + if (!XtIsSensitive(w)) + return (False); + if ((!XtIsManaged(w) || !w->core.mapped_when_managed) && + !(w == bar && IsExported(w))) return (False); w = XtParent(w); diff --git a/ext/src/mcde/motif/lib/Xm/RowColumnP.h b/ext/src/mcde/motif/lib/Xm/RowColumnP.h index 8843a10519..58ddf4fa5a 100644 --- a/ext/src/mcde/motif/lib/Xm/RowColumnP.h +++ b/ext/src/mcde/motif/lib/Xm/RowColumnP.h @@ -278,6 +278,11 @@ typedef struct _XmRowColumnClassRec externalref XmRowColumnClassRec xmRowColumnClassRec; +/* MCDE: a menu bar shown by the desktop's global menu (DtSvc, + * McdeGlobalMenu.c) is unmanaged in its window, but its accelerators + * still work (RCPopup.c, AllWidgetsAccessible) */ +extern void _XmMenuBarSetExported(Widget bar, Boolean exported); + /* Constraint Definition */