mcde: dtbar, the bar at the top with the menus of the active program

include/Mcde/GlobalMenu.h is the protocol (selection _MCDE_BAR_S<n>,
_MCDE_MENU on the program's window, _MCDE_ACTIVE_MENU on the root, client
messages to activate and refresh).  libDtSvc's McdeGlobalMenu.c, started by
DtInitialize, finds every XmMenuBar with an Xt create hook, hides it while
the bar runs and writes its tree; a click in the bar calls the button's own
callback -- no Motif patch, every CDE program takes part.  The text form is
McdeMenuModel.c with its test (PASS test_menumodel).  dtbar: M menu (dtaction
Dtstyle, Dtterm, Dtfile, LockDisplay, ExitSession), the program's menus, the
clock; started by Xsession.d/0090.dtbar.  The Mcde headers are installed.
Tested on Xvfb with dtwm and dtcalc: its menu bar leaves its window, Options
and Help are in the bar, Options > Memory Registers opens dtcalc's dialog.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
lotherkandClaude Opus 5.5 committed 2026-11-10 07:27:29 +00:00
1 parent 261cb1e992
commit e8240130d8
15 files changed
+1311 -4

No files matched your search

+12
View File
@@ -46,6 +46,18 @@ place of CDE; pkgsrc builds it on any platform from `pkgsrc/`.
switch; a program's title goes to its tab (TermParse.c), the window shows
the front tab's. dtterm draws through Xft (`TermPrimRenderXft.c`) and reads
UTF-8 (setlocale in `DtTermMain.c`, from MakroDE).
- `programs/dtbar/dtbar.c` -- the bar at the top of the screen: the M menu,
the menus of the program with the focus, the clock. The protocol is
`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
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").
`MCDE_NO_GLOBAL_MENU` keeps a program's menu bar in its window,
`MCDE_GLOBAL_MENU_DEBUG` logs what the program side does.
- `programs/dtterm/Profiles.c` -- terminal profiles (font, colours, command)
from `~/.dt/dtterm.profiles`, else `config/dtterm.profiles`; the parser is
plain C with its own test (`test_profiles.c`, `make check`). A view with a
+1
View File
@@ -800,6 +800,7 @@ programs/dtterm/Makefile
programs/dtcalc/Makefile
programs/dtlaunch/Makefile
programs/dtbar/Makefile
programs/dtaction/Makefile
+3 -1
View File
@@ -2,7 +2,9 @@ MAINTAINERCLEANFILES = Makefile.in
# Install the header files
nobase_include_HEADERS = Dt/Editor.h \
nobase_include_HEADERS = Mcde/GlobalMenu.h \
Mcde/McdeSys.h \
Dt/Editor.h \
Dt/TermPrim.h \
Dt/Term.h \
Dt/HelpDialog.h \
+86
View File
@@ -0,0 +1,86 @@
/*
* GlobalMenu.h -- MCDE: the menu bar of the active program in the top bar
*
* Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE.
*
* The protocol between a program and the top bar (programs/dtbar), all of it
* ordinary X11: a selection, properties and client messages.
*
* _MCDE_BAR_S<screen> selection owned by the top bar while it runs. A
* program exports its menu bars only then; it watches
* the owner's window and shows its own menu bars
* again when the bar goes away.
* _MCDE_MENU property (UTF8_STRING) on the program's shell
* window: its menu bar, as McdeMenuWrite writes it.
* _MCDE_ACTIVE_MENU property (WINDOW) on the root window: the shell that
* had the focus last. The program sets it on FocusIn;
* the bar shows that shell's _MCDE_MENU.
* _MCDE_MENU_ACTIVATE client message, bar to shell: l[0] the item (its
* line number in _MCDE_MENU), l[1] the time stamp.
* _MCDE_MENU_REFRESH client message, bar to shell: write _MCDE_MENU anew
* (the bar sends it when the pointer comes to it, so
* the menus show sensitivity and toggle states of now).
*
* The text form is one line per item, the tree given by the depth:
*
* DEPTH TAB KIND TAB FLAGS TAB MNEMONIC TAB ACCELERATOR TAB LABEL
*
* KIND is C (cascade), P (push button), T (toggle), S (separator) or L
* (label); FLAGS is "-" or some of s (sensitive), x (checked), r (one of a
* radio group); MNEMONIC is one character or "-"; ACCELERATOR the text the
* menu shows ("Ctrl+C") or "-". Tabs and newlines in a label become spaces.
*
* C99 and POSIX only in the model (McdeMenuModel.c, its test test_menumodel.c);
* the X side is lib/DtSvc/DtUtil2/McdeGlobalMenu.c and programs/dtbar.
*/
#ifndef _Mcde_GlobalMenu_h
#define _Mcde_GlobalMenu_h
#include <stddef.h>
#define MCDE_MENU_MAX 512 /* items in one menu bar */
enum McdeMenuKind {
MCDE_MENU_CASCADE = 'C',
MCDE_MENU_PUSH = 'P',
MCDE_MENU_TOGGLE = 'T',
MCDE_MENU_SEPARATOR = 'S',
MCDE_MENU_LABEL = 'L'
};
#define MCDE_MENU_SENSITIVE 0x1
#define MCDE_MENU_CHECKED 0x2
#define MCDE_MENU_RADIO 0x4
typedef struct {
int depth; /* 0: in the bar itself */
int kind; /* enum McdeMenuKind */
int flags; /* MCDE_MENU_* */
char mnemonic; /* '\0': none */
char accelerator[32]; /* "" : none */
char label[96];
} McdeMenuItem;
/*
* Write N items as text into BUF (LEN bytes, NUL-terminated). Returns the
* length, or -1 if it does not fit or an item is not valid (a depth that
* grows by more than one, an unknown kind).
*/
extern int McdeMenuWrite(const McdeMenuItem *items, int n, char *buf,
size_t len);
/*
* Read TEXT into ITEMS (at most MAX). Returns the number of items, or -1 if
* a line is not of the form above.
*/
extern int McdeMenuParse(const char *text, McdeMenuItem *items, int max);
/*
* The end of the subtree of item I: the first item after I whose depth is not
* greater than that of I (or N). The menu of a cascade I is I+1 .. end-1,
* those of depth items[I].depth + 1 being its own entries.
*/
extern int McdeMenuEnd(const McdeMenuItem *items, int n, int i);
#endif /* _Mcde_GlobalMenu_h */
+6
View File
@@ -149,6 +149,9 @@ DtInitialize(
return (result);
}
/* MCDE: McdeGlobalMenu.c */
extern void _DtMcdeGlobalMenuInitialize(Display *, Widget);
static Boolean
DtBigInitialize(
Display *display,
@@ -188,6 +191,9 @@ DtBigInitialize(
initialized = TRUE;
_DtSvcProcessUnlock();
/* MCDE: the menu bars of this program in the top bar (McdeGlobalMenu.c) */
_DtMcdeGlobalMenuInitialize(display, _DtInitTtContextWidget);
return (initialized);
}
+424
View File
@@ -0,0 +1,424 @@
/*
* McdeGlobalMenu.c -- MCDE: a program's menu bar in the top bar
*
* Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE.
*
* The program side of the protocol in Mcde/GlobalMenu.h. DtInitialize()
* calls _DtMcdeGlobalMenuInitialize(), so every program that is a CDE
* program takes part without a change of its own and without a change to
* Motif: an Xt create hook sees every XmMenuBar the program makes. While the
* top bar runs (it owns _MCDE_BAR_S<screen>), the menu bar of a window is
* unmanaged when the window maps -- the window gets smaller by it, not
* emptier -- and its tree is written to the window as _MCDE_MENU; the focus
* makes the window the active one (_MCDE_ACTIVE_MENU on the root); a click in
* the bar comes back as a client message and calls the real callback of the
* button. When the bar goes away, every menu bar is managed again.
*
* Xt and Motif only (ext/src/mcde/AGENTS.md).
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Intrinsic.h>
#include <X11/IntrinsicP.h>
#include <X11/Xatom.h>
#include <X11/Shell.h>
#include <Xm/Xm.h>
#include <Xm/RowColumn.h>
#include <Xm/CascadeB.h>
#include <Xm/CascadeBG.h>
#include <Xm/PushB.h>
#include <Xm/PushBG.h>
#include <Xm/ToggleB.h>
#include <Xm/ToggleBG.h>
#include <Xm/Separator.h>
#include <Xm/SeparatoG.h>
#include <Xm/Label.h>
#include <Xm/LabelG.h>
#include <Mcde/GlobalMenu.h>
void _DtMcdeGlobalMenuInitialize(Display *dpy, Widget toplevel);
typedef struct {
Widget shell;
Widget menubar;
Widget items[MCDE_MENU_MAX];
int count;
} Exported;
static Exported *exported;
static int nexported;
static Display *display;
static Widget hookWidget; /* the widget the bar's events go to */
static Window bar; /* the owner of _MCDE_BAR_S<screen>, or None */
static int debug; /* MCDE_GLOBAL_MENU_DEBUG: what happens, on stderr */
static Atom aBar, aMenu, aActive, aActivate, aRefresh, aUtf8;
static void SetBar(Window owner);
static Widget
ShellOf(Widget w)
{
while (w != NULL && !XtIsShell(w))
w = XtParent(w);
return w;
}
static Exported *
Find(Widget shell)
{
int i;
for (i = 0; i < nexported; i++)
if (exported[i].shell == shell)
return &exported[i];
return NULL;
}
/* the label of a button as UTF-8 text, into BUF */
static void
LabelText(Widget w, const char *resource, char *buf, size_t len)
{
XmString xs = NULL;
char *t;
buf[0] = '\0';
XtVaGetValues(w, resource, &xs, NULL);
if (xs == NULL)
return;
t = (char *) XmStringUnparse(xs, NULL, XmCHARSET_TEXT, XmCHARSET_TEXT,
NULL, 0, XmOUTPUT_ALL);
if (t != NULL) {
snprintf(buf, len, "%s", t);
XtFree(t);
}
XmStringFree(xs);
}
static void
Walk(Exported *e, Widget rc, int depth, McdeMenuItem *items)
{
WidgetList kids = NULL;
Cardinal nkids = 0, i;
unsigned char radio = False;
XtVaGetValues(rc, XmNchildren, &kids, XmNnumChildren, &nkids,
XmNradioBehavior, &radio, NULL);
for (i = 0; i < nkids && e->count < MCDE_MENU_MAX; i++) {
Widget w = kids[i];
McdeMenuItem *m = &items[e->count];
KeySym mn = NoSymbol;
Widget sub = NULL;
if (!XtIsManaged(w) || w->core.being_destroyed)
continue;
memset(m, 0, sizeof *m);
m->depth = depth;
if (XmIsCascadeButton(w) || XmIsCascadeButtonGadget(w)) {
m->kind = MCDE_MENU_CASCADE;
XtVaGetValues(w, XmNsubMenuId, &sub, NULL);
} else if (XmIsToggleButton(w) || XmIsToggleButtonGadget(w)) {
unsigned char ind = XmN_OF_MANY;
m->kind = MCDE_MENU_TOGGLE;
XtVaGetValues(w, XmNindicatorType, &ind, NULL);
if (XmIsToggleButton(w) ? XmToggleButtonGetState(w) :
XmToggleButtonGadgetGetState(w))
m->flags |= MCDE_MENU_CHECKED;
if (radio || ind == XmONE_OF_MANY)
m->flags |= MCDE_MENU_RADIO;
} else if (XmIsPushButton(w) || XmIsPushButtonGadget(w))
m->kind = MCDE_MENU_PUSH;
else if (XmIsSeparator(w) || XmIsSeparatorGadget(w))
m->kind = MCDE_MENU_SEPARATOR;
else if (XmIsLabel(w) || XmIsLabelGadget(w))
m->kind = MCDE_MENU_LABEL;
else
continue;
if (XtIsSensitive(w))
m->flags |= MCDE_MENU_SENSITIVE;
if (m->kind != MCDE_MENU_SEPARATOR) {
LabelText(w, XmNlabelString, m->label, sizeof m->label);
if (m->kind != MCDE_MENU_LABEL)
XtVaGetValues(w, XmNmnemonic, &mn, NULL);
if (mn > ' ' && mn < 0x7f)
m->mnemonic = (char) mn;
if (m->kind == MCDE_MENU_PUSH || m->kind == MCDE_MENU_TOGGLE)
LabelText(w, XmNacceleratorText, m->accelerator,
sizeof m->accelerator);
}
e->items[e->count++] = w;
if (sub != NULL)
Walk(e, sub, depth + 1, items);
}
}
/* the menu bar of E as _MCDE_MENU on its window */
static void
Export(Exported *e)
{
static McdeMenuItem items[MCDE_MENU_MAX];
static char text[MCDE_MENU_MAX * 160];
int len;
if (!XtIsRealized(e->shell))
return;
e->count = 0;
Walk(e, e->menubar, 0, items);
len = McdeMenuWrite(items, e->count, text, sizeof text);
if (len < 0)
return;
XChangeProperty(display, XtWindow(e->shell), aMenu, aUtf8, 8,
PropModeReplace, (unsigned char *) text, len);
}
static void
MakeActive(Exported *e)
{
Window w;
if (bar == None || !XtIsRealized(e->shell))
return;
Export(e);
w = XtWindow(e->shell);
XChangeProperty(display, DefaultRootWindow(display), aActive,
XA_WINDOW, 32, PropModeReplace, (unsigned char *) &w, 1);
}
/* the window's own menu bar: hidden while the bar shows it */
static void
Place(Exported *e)
{
if (e->menubar == NULL || e->menubar->core.being_destroyed)
return;
if (bar != None && XtIsManaged(e->menubar))
XtUnmanageChild(e->menubar);
else if (bar == None && !XtIsManaged(e->menubar))
XtManageChild(e->menubar);
}
/* the cascades are told they open, so that they bring their entries up to
* date (sensitivity, toggle states), as before a pulldown is shown */
static void
Cascading(Exported *e)
{
XmAnyCallbackStruct cbs;
int i;
memset(&cbs, 0, sizeof cbs);
cbs.reason = XmCR_CASCADING;
for (i = 0; i < e->count; i++)
if (XmIsCascadeButton(e->items[i]) ||
XmIsCascadeButtonGadget(e->items[i]))
XtCallCallbacks(e->items[i], XmNcascadingCallback, &cbs);
}
static void
Activate(Exported *e, int item, Time t)
{
Widget w;
XEvent ev;
if (item < 0 || item >= e->count)
return;
w = e->items[item];
if (debug)
fprintf(stderr, "globalmenu: activate %d %s%s\n", item, XtName(w),
XtIsSensitive(w) ? "" : " (insensitive)");
if (w->core.being_destroyed || !XtIsSensitive(w))
return;
memset(&ev, 0, sizeof ev);
ev.xbutton.type = ButtonRelease;
ev.xbutton.display = display;
ev.xbutton.window = XtWindow(e->shell);
ev.xbutton.time = t;
ev.xbutton.button = Button1;
if (XmIsToggleButton(w))
XmToggleButtonSetState(w, !XmToggleButtonGetState(w), True);
else if (XmIsToggleButtonGadget(w))
XmToggleButtonGadgetSetState(w,
!XmToggleButtonGadgetGetState(w), True);
else if (XmIsPushButton(w) || XmIsPushButtonGadget(w)) {
XmPushButtonCallbackStruct cbs;
memset(&cbs, 0, sizeof cbs);
cbs.reason = XmCR_ACTIVATE;
cbs.event = &ev;
cbs.click_count = 1;
XtCallCallbacks(w, XmNactivateCallback, &cbs);
}
}
static void
ShellEvent(Widget shell, XtPointer client, XEvent *ev, Boolean *cont)
{
Exported *e = Find(shell);
(void) client;
(void) cont;
if (debug)
fprintf(stderr, "globalmenu: event %d on %s%s\n", ev->type,
XtName(shell), e != NULL ? "" : " (no menu bar)");
if (e == NULL)
return;
/* is the bar (still, already) there? Asked when it matters, so a bar
* that starts later is found without listening on the root window */
if (ev->type == MapNotify || (ev->type == FocusIn &&
ev->xfocus.detail != NotifyPointer &&
ev->xfocus.detail != NotifyInferior))
SetBar(XGetSelectionOwner(display, aBar));
switch (ev->type) {
case MapNotify:
Place(e);
if (bar != None)
Export(e);
break;
case FocusIn:
if (ev->xfocus.detail != NotifyPointer &&
ev->xfocus.detail != NotifyInferior)
MakeActive(e);
break;
case ClientMessage:
if (ev->xclient.message_type == aActivate) {
Activate(e, (int) ev->xclient.data.l[0],
(Time) ev->xclient.data.l[1]);
if (!e->shell->core.being_destroyed)
Export(e);
} else if (ev->xclient.message_type == aRefresh) {
Cascading(e);
Export(e);
}
break;
}
}
static void
MenuBarGone(Widget w, XtPointer client, XtPointer call)
{
int i;
(void) client;
(void) call;
for (i = 0; i < nexported; i++)
if (exported[i].menubar == w) {
XtRemoveEventHandler(exported[i].shell,
StructureNotifyMask | FocusChangeMask, True,
ShellEvent, NULL);
exported[i] = exported[--nexported];
return;
}
}
static void
Register(Widget menubar)
{
Widget shell = ShellOf(menubar);
Exported *e;
if (shell == NULL || Find(shell) != NULL)
return; /* one menu bar a window: the first */
exported = (Exported *) XtRealloc((char *) exported,
(Cardinal) ((nexported + 1) * sizeof *exported));
e = &exported[nexported++];
memset(e, 0, sizeof *e);
e->shell = shell;
e->menubar = menubar;
XtAddEventHandler(shell, StructureNotifyMask | FocusChangeMask, True,
ShellEvent, NULL);
XtAddCallback(menubar, XmNdestroyCallback, MenuBarGone, NULL);
}
static void
CreateHook(Widget w, XtPointer client, XtPointer call)
{
XtCreateHookDataRec *d = (XtCreateHookDataRec *) call;
unsigned char type = 0;
(void) w;
(void) client;
if (d == NULL || d->type == NULL || strcmp(d->type, XtHcreate) != 0 ||
!XmIsRowColumn(d->widget))
return;
XtVaGetValues(d->widget, XmNrowColumnType, &type, NULL);
if (type == XmMENU_BAR)
Register(d->widget);
}
static void
SelectInput(Window w, long mask)
{
XWindowAttributes a;
if (XGetWindowAttributes(display, w, &a))
XSelectInput(display, w, a.your_event_mask | mask);
}
/* the bar is there (OWNER), or gone (None): every window follows */
static void
SetBar(Window owner)
{
int i;
if (owner == bar)
return;
if (bar != None)
XtUnregisterDrawable(display, bar);
bar = owner;
if (bar != None) {
XtRegisterDrawable(display, bar, hookWidget);
SelectInput(bar, StructureNotifyMask);
}
for (i = 0; i < nexported; i++) {
Place(&exported[i]);
if (bar != None)
Export(&exported[i]);
}
}
/* DestroyNotify of the bar's window (registered with Xt in SetBar) */
static void
BarEvent(Widget w, XtPointer client, XEvent *ev, Boolean *cont)
{
(void) w;
(void) client;
(void) cont;
if (ev->type == DestroyNotify && bar != None &&
ev->xdestroywindow.window == bar)
SetBar(None);
}
void
_DtMcdeGlobalMenuInitialize(Display *dpy, Widget toplevel)
{
char name[32];
if (display != NULL || dpy == NULL || toplevel == NULL)
return;
if (getenv("MCDE_NO_GLOBAL_MENU") != NULL)
return;
display = dpy;
debug = getenv("MCDE_GLOBAL_MENU_DEBUG") != NULL;
/* The bar's window is registered with a widget of its own: a shell
* stops the program on a StructureNotify of a window not its own
* ("Event with wrong window", Shell.c), so it is a core widget, never
* realized, in a popup shell that is no child of the program's. */
hookWidget = XtVaCreateWidget("mcdeGlobalMenu", widgetClass,
XtCreatePopupShell("mcdeGlobalMenuShell", overrideShellWidgetClass,
ShellOf(toplevel) != NULL ? ShellOf(toplevel) : toplevel, NULL, 0),
XmNwidth, 1, XmNheight, 1, NULL);
snprintf(name, sizeof name, "_MCDE_BAR_S%d", DefaultScreen(dpy));
aBar = XInternAtom(dpy, name, False);
aMenu = XInternAtom(dpy, "_MCDE_MENU", False);
aActive = XInternAtom(dpy, "_MCDE_ACTIVE_MENU", False);
aActivate = XInternAtom(dpy, "_MCDE_MENU_ACTIVATE", False);
aRefresh = XInternAtom(dpy, "_MCDE_MENU_REFRESH", False);
aUtf8 = XInternAtom(dpy, "UTF8_STRING", False);
XtAddCallback(XtHooksOfDisplay(dpy), XtNcreateHook, CreateHook, NULL);
XtAddRawEventHandler(hookWidget, StructureNotifyMask, True, BarEvent,
NULL);
SetBar(XGetSelectionOwner(dpy, aBar));
}
+162
View File
@@ -0,0 +1,162 @@
/*
* McdeMenuModel.c -- MCDE: the text form of a menu bar (Mcde/GlobalMenu.h)
*
* Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE.
*
* C99 and POSIX only, no X: test_menumodel.c tests it (make check).
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Mcde/GlobalMenu.h>
static int
ValidKind(int k)
{
return k == MCDE_MENU_CASCADE || k == MCDE_MENU_PUSH ||
k == MCDE_MENU_TOGGLE || k == MCDE_MENU_SEPARATOR ||
k == MCDE_MENU_LABEL;
}
/* append S to BUF at *AT; RAW 0: tabs and newlines as spaces */
static int
Put(char *buf, size_t len, size_t *at, const char *s, int raw)
{
for (; *s != '\0'; s++) {
if (*at + 1 >= len)
return 0;
buf[(*at)++] = (!raw &&
(*s == '\t' || *s == '\n' || *s == '\r')) ? ' ' : *s;
}
buf[*at] = '\0';
return 1;
}
int
McdeMenuWrite(const McdeMenuItem *items, int n, char *buf, size_t len)
{
size_t at = 0;
char head[64], flags[4], mn[2];
int i, f;
if (len == 0)
return -1;
buf[0] = '\0';
for (i = 0; i < n; i++) {
const McdeMenuItem *m = &items[i];
if (!ValidKind(m->kind) || m->depth < 0 ||
m->depth > (i == 0 ? 0 : items[i - 1].depth + 1))
return -1;
f = 0;
if (m->flags & MCDE_MENU_SENSITIVE)
flags[f++] = 's';
if (m->flags & MCDE_MENU_CHECKED)
flags[f++] = 'x';
if (m->flags & MCDE_MENU_RADIO)
flags[f++] = 'r';
if (f == 0)
flags[f++] = '-';
flags[f] = '\0';
mn[0] = (m->mnemonic > ' ' && m->mnemonic != 0x7f) ?
m->mnemonic : '-';
mn[1] = '\0';
snprintf(head, sizeof head, "%d\t%c\t%s\t%s\t", m->depth,
m->kind, flags, mn);
if (!Put(buf, len, &at, head, 1) ||
!Put(buf, len, &at, m->accelerator[0] != '\0' ?
m->accelerator : "-", 0) ||
!Put(buf, len, &at, "\t", 1) ||
!Put(buf, len, &at, m->label, 0) ||
!Put(buf, len, &at, "\n", 1))
return -1;
}
return (int) at;
}
/* the next field of *P up to a tab (or the end of the line), in DST */
static int
Field(const char **p, char *dst, size_t len, int last)
{
const char *s = *p, *e = s;
size_t n;
while (*e != '\0' && *e != '\n' && (last || *e != '\t'))
e++;
if (!last && *e != '\t')
return 0;
n = (size_t) (e - s);
if (n >= len)
n = len - 1; /* a long label is cut, not refused */
memcpy(dst, s, n);
dst[n] = '\0';
*p = (*e == '\t') ? e + 1 : e;
return 1;
}
int
McdeMenuParse(const char *text, McdeMenuItem *items, int max)
{
const char *p = text;
char f[4][16], *end;
int n = 0, i;
long depth;
while (*p != '\0') {
McdeMenuItem *m;
if (*p == '\n') {
p++;
continue;
}
if (n >= max)
return -1;
m = &items[n];
memset(m, 0, sizeof *m);
for (i = 0; i < 4; i++)
if (!Field(&p, f[i], sizeof f[i], 0))
return -1;
if (!Field(&p, m->accelerator, sizeof m->accelerator, 0) ||
!Field(&p, m->label, sizeof m->label, 1))
return -1;
if (*p == '\n')
p++;
depth = strtol(f[0], &end, 10);
if (*end != '\0' || end == f[0] || depth < 0 ||
depth > (n == 0 ? 0 : items[n - 1].depth + 1))
return -1;
m->depth = (int) depth;
if (strlen(f[1]) != 1 || !ValidKind(f[1][0]))
return -1;
m->kind = f[1][0];
for (end = f[2]; *end != '\0'; end++) {
if (*end == 's')
m->flags |= MCDE_MENU_SENSITIVE;
else if (*end == 'x')
m->flags |= MCDE_MENU_CHECKED;
else if (*end == 'r')
m->flags |= MCDE_MENU_RADIO;
else if (*end != '-')
return -1;
}
if (strlen(f[3]) != 1)
return -1;
m->mnemonic = f[3][0] == '-' ? '\0' : f[3][0];
if (strcmp(m->accelerator, "-") == 0)
m->accelerator[0] = '\0';
n++;
}
return n;
}
int
McdeMenuEnd(const McdeMenuItem *items, int n, int i)
{
int j;
for (j = i + 1; j < n && items[j].depth > items[i].depth; j++)
;
return j;
}
+113
View File
@@ -0,0 +1,113 @@
/*
* test_menumodel.c -- the tests of McdeMenuModel.c (make check)
*
* Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE.
*/
#include <stdio.h>
#include <string.h>
#include <Mcde/GlobalMenu.h>
static int failures;
#define CHECK(cond) do { \
if (!(cond)) { \
printf("FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \
failures++; \
} \
} while (0)
static McdeMenuItem
Item(int depth, int kind, int flags, char mn, const char *acc,
const char *label)
{
McdeMenuItem m;
memset(&m, 0, sizeof m);
m.depth = depth;
m.kind = kind;
m.flags = flags;
m.mnemonic = mn;
snprintf(m.accelerator, sizeof m.accelerator, "%s", acc);
snprintf(m.label, sizeof m.label, "%s", label);
return m;
}
static void
test_roundtrip(void)
{
McdeMenuItem in[8], out[8];
char buf[1024];
int n = 0, len;
in[n++] = Item(0, MCDE_MENU_CASCADE, MCDE_MENU_SENSITIVE, 'W', "", "Window");
in[n++] = Item(1, MCDE_MENU_PUSH, MCDE_MENU_SENSITIVE, 'N', "", "New");
in[n++] = Item(1, MCDE_MENU_PUSH, MCDE_MENU_SENSITIVE, 'T',
"Ctrl+Shift+T", "New Tab");
in[n++] = Item(1, MCDE_MENU_CASCADE, MCDE_MENU_SENSITIVE, 'P', "",
"New Tab with Profile");
in[n++] = Item(2, MCDE_MENU_PUSH, 0, 0, "", "Dark");
in[n++] = Item(1, MCDE_MENU_SEPARATOR, 0, 0, "", "");
in[n++] = Item(0, MCDE_MENU_CASCADE, MCDE_MENU_SENSITIVE, 'O', "",
"Options");
in[n++] = Item(1, MCDE_MENU_TOGGLE, MCDE_MENU_SENSITIVE |
MCDE_MENU_CHECKED | MCDE_MENU_RADIO, 'M', "", "Menu\tBar\n");
len = McdeMenuWrite(in, n, buf, sizeof buf);
CHECK(len > 0 && (size_t) len == strlen(buf));
CHECK(strncmp(buf, "0\tC\ts\tW\t-\tWindow\n1\tP\ts\tN\t-\tNew\n", 31) == 0);
CHECK(strstr(buf, "2\tP\t-\t-\t-\tDark\n") != NULL);
CHECK(strstr(buf, "1\tT\tsxr\tM\t-\tMenu Bar \n") != NULL);
CHECK(McdeMenuParse(buf, out, 8) == n);
CHECK(out[2].kind == MCDE_MENU_PUSH && out[2].mnemonic == 'T' &&
strcmp(out[2].accelerator, "Ctrl+Shift+T") == 0 &&
strcmp(out[2].label, "New Tab") == 0);
CHECK(out[4].depth == 2 && out[4].flags == 0 && out[4].mnemonic == '\0');
CHECK(out[5].kind == MCDE_MENU_SEPARATOR && out[5].label[0] == '\0');
CHECK(out[7].flags == (MCDE_MENU_SENSITIVE | MCDE_MENU_CHECKED |
MCDE_MENU_RADIO));
CHECK(strcmp(out[7].label, "Menu Bar ") == 0);
CHECK(McdeMenuEnd(out, n, 0) == 6); /* Window: 1..5 */
CHECK(McdeMenuEnd(out, n, 3) == 5); /* the profiles: 4 */
CHECK(McdeMenuEnd(out, n, 6) == 8);
CHECK(McdeMenuEnd(out, n, 2) == 3); /* a push button: nothing */
CHECK(McdeMenuParse(buf, out, 7) == -1); /* too many */
CHECK(McdeMenuWrite(in, n, buf, 40) == -1); /* does not fit */
CHECK(McdeMenuWrite(in, 0, buf, sizeof buf) == 0 && buf[0] == '\0');
}
static void
test_invalid(void)
{
McdeMenuItem in[2], out[4];
char buf[256];
in[0] = Item(0, MCDE_MENU_CASCADE, 0, 0, "", "A");
in[1] = Item(2, MCDE_MENU_PUSH, 0, 0, "", "B");
CHECK(McdeMenuWrite(in, 2, buf, sizeof buf) == -1); /* depth jumps */
in[1] = Item(1, 'Q', 0, 0, "", "B");
CHECK(McdeMenuWrite(in, 2, buf, sizeof buf) == -1); /* kind */
CHECK(McdeMenuParse("", out, 4) == 0);
CHECK(McdeMenuParse("1\tP\ts\t-\t-\tX\n", out, 4) == -1);
CHECK(McdeMenuParse("0\tP\ts\t-\t-\n", out, 4) == -1);
CHECK(McdeMenuParse("0\tZ\ts\t-\t-\tX\n", out, 4) == -1);
CHECK(McdeMenuParse("0\tP\tq\t-\t-\tX\n", out, 4) == -1);
CHECK(McdeMenuParse("x\tP\ts\t-\t-\tX\n", out, 4) == -1);
/* no newline at the end is fine */
CHECK(McdeMenuParse("0\tP\ts\tF\t-\tFile", out, 4) == 1 &&
out[0].mnemonic == 'F' && strcmp(out[0].label, "File") == 0);
}
int
main(void)
{
test_roundtrip();
test_invalid();
if (failures == 0)
printf("PASS test_menumodel\n");
return failures == 0 ? 0 : 1;
}
+11 -1
View File
@@ -12,6 +12,7 @@ endif
# USe CPPFLAGS so it will apply to both C and C++ components
libDtSvc_la_CPPFLAGS = -I./include -DMULTIBYTE -DNLS16 -I../include \
-I$(top_srcdir)/include \
@DT_INCDIR@ -DCDE_INSTALLATION_TOP=\"$(CDE_INSTALLATION_TOP)\" \
-DCDE_CONFIGURATION_TOP=\"$(CDE_CONFIGURATION_TOP)\"
@@ -171,9 +172,18 @@ libDtSvc_la_SOURCES = DtCodelibs/buf.C \
DtUtil2/UErrNoBMS.c \
DtUtil2/Utility.c \
DtUtil2/XlationSvc.c \
DtUtil2/XmWrap.c
DtUtil2/XmWrap.c \
DtUtil2/McdeMenuModel.c \
DtUtil2/McdeGlobalMenu.c
if HAS_PAM_LIBRARY
libDtSvc_la_SOURCES += DtUtil2/SvcPam.c
libDtSvc_la_LIBADD = $(PAMLIB)
endif
# MCDE: the text form of a menu bar (DtUtil2/McdeMenuModel.c) is plain C and
# has its own tests (make check)
check_PROGRAMS = test_menumodel
test_menumodel_SOURCES = DtUtil2/test_menumodel.c DtUtil2/McdeMenuModel.c
test_menumodel_CPPFLAGS = -I$(top_srcdir)/include
TESTS = test_menumodel
+4
View File
@@ -2495,6 +2495,7 @@ dt/bin/dsdm
dt/bin/dtaction
dt/bin/dtappgather
dt/bin/dtappintegrate
dt/bin/dtbar
dt/bin/dtbuilder
dt/bin/dtcalc
dt/bin/dtchooser
@@ -2599,6 +2600,7 @@ dt/config/Xsession.d/0030.dttmpdir
dt/config/Xsession.d/0060.dtsysenv
dt/config/Xsession.d/0070.dtfonts
dt/config/Xsession.d/0080.dtlaunch
dt/config/Xsession.d/0090.dtbar
dt/config/Xsetup
dt/config/Xstartup
dt/config/dtspcdenv
@@ -2641,6 +2643,8 @@ dt/include/Dt/SvcPam.h
dt/include/Dt/Term.h
dt/include/Dt/TermPrim.h
dt/include/Dt/Wsm.h
dt/include/Mcde/GlobalMenu.h
dt/include/Mcde/McdeSys.h
dt/include/Tt/tt_c.h
dt/include/Tt/tttk.h
dt/include/csa/csa.h
+1 -1
View File
@@ -6,7 +6,7 @@ SUBDIRS = backdrops icons dsdm dtmail dtpad dtfile dtwm dtlogin \
dtappbuilder palettes dtappintegrate dtprintegrate dtconfig \
dtcreate dtprintinfo fontaliases dtdspmsg ttsnoop dtimsstart \
dtpdm dtsr dtpdmd dtinfo types tttypes util dtopen localized \
dthelp dtdocbook dtlaunch
dthelp dtdocbook dtlaunch dtbar
install-data-hook:
-if [ $(CDE_INSTALLATION_TOP)/bin != $(bindir) ];then \
+9
View File
@@ -0,0 +1,9 @@
MAINTAINERCLEANFILES = Makefile.in
# dtbar, MCDE's bar at the top of the screen (dtbar.c); the menu model it
# reads is in libDtSvc (DtUtil2/McdeMenuModel.c, with its tests).
bin_PROGRAMS = dtbar
dtbar_SOURCES = dtbar.c
dtbar_CPPFLAGS = -I$(top_srcdir)/include
dtbar_LDADD = $(DTCLIENTLIBS) $(XTOOLLIB)
+467
View File
@@ -0,0 +1,467 @@
/*
* dtbar.c -- MCDE: the bar at the top of the screen
*
* Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE.
*
* Left the M menu (the system: settings, lock, log out), then the menus of
* the program that has the focus, right the clock. The menus are not this
* program's own: the program writes its menu bar to its window and keeps the
* buttons, this draws the bar from the text and sends a click back (the
* protocol: include/Mcde/GlobalMenu.h; the program's side is
* lib/DtSvc/DtUtil2/McdeGlobalMenu.c, which every CDE program has through
* DtInitialize). One bar a screen: it owns _MCDE_BAR_S<screen>.
*
* C99, POSIX, Xt and Motif only (ext/src/mcde/AGENTS.md).
*/
#define _POSIX_C_SOURCE 200809L
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <X11/Intrinsic.h>
#include <X11/Shell.h>
#include <X11/Xatom.h>
#include <Xm/Xm.h>
#include <Xm/CascadeBG.h>
#include <Xm/Form.h>
#include <Xm/LabelG.h>
#include <Xm/PushBG.h>
#include <Xm/RowColumn.h>
#include <Xm/SeparatoG.h>
#include <Xm/ToggleBG.h>
#include <Mcde/GlobalMenu.h>
static Display *dpy;
static Widget shell, form, bar, clockLabel;
static Widget sink; /* the root's and the client's events go here */
static Atom aBar, aMenu, aActive, aActivate, aRefresh, aUtf8, aManager;
static Window client; /* the window whose menus are shown */
static McdeMenuItem items[MCDE_MENU_MAX];
static int nitems;
static Widget appWidgets[2 * MCDE_MENU_MAX]; /* what Rebuild made */
static int nappWidgets;
static const char *fallback[] = {
"Dtbar*shadowThickness: 1",
"Dtbar*marginHeight: 1",
"Dtbar*mbar.marginHeight: 0",
"Dtbar*mbar.shadowThickness: 0",
"Dtbar*mcdeM.labelString: M",
"Dtbar*clock.marginWidth: 10",
NULL
};
static int
IgnoreErrors(Display *d, XErrorEvent *e)
{
/* a window that went away under our feet (BadWindow) is no error */
(void) d;
(void) e;
return 0;
}
/* ---- the M menu --------------------------------------------------------- */
static void
Run(const char *action)
{
pid_t pid = fork();
if (pid == 0) {
setsid();
execlp("dtaction", "dtaction", action, (char *) NULL);
_exit(127);
}
}
static void
MAction(Widget w, XtPointer data, XtPointer call)
{
(void) w;
(void) call;
Run((const char *) data);
}
static Widget
Push(Widget menu, const char *label, char mn, XtCallbackProc cb,
XtPointer data)
{
XmString s = XmStringCreateLocalized((char *) label);
Widget b = XtVaCreateManagedWidget("item", xmPushButtonGadgetClass,
menu, XmNlabelString, s, XmNmnemonic, (KeySym) mn, NULL);
XmStringFree(s);
if (cb != NULL)
XtAddCallback(b, XmNactivateCallback, cb, data);
else
XtSetSensitive(b, False);
return b;
}
static void
MakeMMenu(void)
{
Widget menu = XmCreatePulldownMenu(bar, "mcdeMMenu", NULL, 0);
Push(menu, "About Makronix", 'A', MAction, "Dthelpview");
XtVaCreateManagedWidget("sep", xmSeparatorGadgetClass, menu, NULL);
Push(menu, "System Settings...", 'S', MAction, "Dtstyle");
Push(menu, "Software Update...", 'U', NULL, NULL);
XtVaCreateManagedWidget("sep", xmSeparatorGadgetClass, menu, NULL);
Push(menu, "Terminal", 'T', MAction, "Dtterm");
Push(menu, "Files", 'F', MAction, "Dtfile");
XtVaCreateManagedWidget("sep", xmSeparatorGadgetClass, menu, NULL);
Push(menu, "Lock Screen", 'L', MAction, "LockDisplay");
Push(menu, "Log Out...", 'O', MAction, "ExitSession");
XtVaCreateManagedWidget("mcdeM", xmCascadeButtonGadgetClass, bar,
XmNsubMenuId, menu, NULL);
}
/* ---- the program's menus ------------------------------------------------ */
static void
Send(Atom type, long a, long b)
{
XEvent ev;
if (client == None)
return;
memset(&ev, 0, sizeof ev);
ev.xclient.type = ClientMessage;
ev.xclient.window = client;
ev.xclient.message_type = type;
ev.xclient.format = 32;
ev.xclient.data.l[0] = a;
ev.xclient.data.l[1] = b;
XSendEvent(dpy, client, False, NoEventMask, &ev);
XFlush(dpy);
}
static void
ItemActivated(Widget w, XtPointer data, XtPointer call)
{
XmAnyCallbackStruct *cbs = (XmAnyCallbackStruct *) call;
Time t = CurrentTime;
(void) w;
if (cbs != NULL && cbs->event != NULL &&
(cbs->event->type == ButtonRelease || cbs->event->type == ButtonPress))
t = cbs->event->xbutton.time;
else if (cbs != NULL && cbs->event != NULL &&
(cbs->event->type == KeyPress || cbs->event->type == KeyRelease))
t = cbs->event->xkey.time;
Send(aActivate, (long) (size_t) data, (long) t);
}
/* the entries of items[from..to) of depth DEPTH into MENU */
static void
Build(Widget menu, int from, int to, int depth)
{
int i;
for (i = from; i < to; i = McdeMenuEnd(items, to, i)) {
McdeMenuItem *m = &items[i];
XmString s = XmStringCreateLocalized(m->label);
XmString acc = m->accelerator[0] != '\0' ?
XmStringCreateLocalized(m->accelerator) : NULL;
Widget w = NULL, sub;
Arg a[8];
int n = 0;
if (m->depth != depth)
continue;
XtSetArg(a[n], XmNlabelString, s); n++;
if (m->mnemonic != '\0') {
XtSetArg(a[n], XmNmnemonic, (KeySym) m->mnemonic); n++;
}
if (acc != NULL) {
XtSetArg(a[n], XmNacceleratorText, acc); n++;
}
switch (m->kind) {
case MCDE_MENU_CASCADE:
sub = XmCreatePulldownMenu(menu, "appMenu", NULL, 0);
if (menu == bar)
appWidgets[nappWidgets++] = sub;
Build(sub, i + 1, McdeMenuEnd(items, to, i), depth + 1);
XtSetArg(a[n], XmNsubMenuId, sub); n++;
w = XtCreateManagedWidget("appCascade",
xmCascadeButtonGadgetClass, menu, a, n);
break;
case MCDE_MENU_PUSH:
w = XtCreateManagedWidget("appItem",
xmPushButtonGadgetClass, menu, a, n);
XtAddCallback(w, XmNactivateCallback, ItemActivated,
(XtPointer) (size_t) i);
break;
case MCDE_MENU_TOGGLE:
XtSetArg(a[n], XmNset, (m->flags & MCDE_MENU_CHECKED) ?
XmSET : XmUNSET); n++;
XtSetArg(a[n], XmNindicatorType,
(m->flags & MCDE_MENU_RADIO) ? XmONE_OF_MANY :
XmN_OF_MANY); n++;
XtSetArg(a[n], XmNvisibleWhenOff, True); n++;
w = XtCreateManagedWidget("appItem",
xmToggleButtonGadgetClass, menu, a, n);
/* the state shown is the program's: it sets it
* itself, and the next _MCDE_MENU shows it */
XtAddCallback(w, XmNvalueChangedCallback, ItemActivated,
(XtPointer) (size_t) i);
break;
case MCDE_MENU_SEPARATOR:
w = XtCreateManagedWidget("sep",
xmSeparatorGadgetClass, menu, NULL, 0);
break;
default:
w = XtCreateManagedWidget("appLabel",
xmLabelGadgetClass, menu, a, n);
break;
}
if (w != NULL && !(m->flags & MCDE_MENU_SENSITIVE) &&
m->kind != MCDE_MENU_SEPARATOR)
XtSetSensitive(w, False);
if (w != NULL && menu == bar)
appWidgets[nappWidgets++] = w;
XmStringFree(s);
if (acc != NULL)
XmStringFree(acc);
}
}
static void
Rebuild(void)
{
int i;
for (i = 0; i < nappWidgets; i++)
XtDestroyWidget(appWidgets[i]);
nappWidgets = 0;
if (client != None)
Build(bar, 0, nitems, 0);
}
/* the _MCDE_MENU of the client into items[] */
static void
ReadMenu(void)
{
Atom type;
int format;
unsigned long n, after;
unsigned char *data = NULL;
static char *shown; /* the text the bar shows now */
static Window shownFor;
const char *text = "";
if (client != None &&
XGetWindowProperty(dpy, client, aMenu, 0, 1 << 20, False, aUtf8,
&type, &format, &n, &after, &data) == Success && data != NULL)
text = (const char *) data;
/* the same menus again (a refresh that changed nothing): an open menu
* must not be pulled away under the pointer */
if (shown != NULL && shownFor == client && strcmp(shown, text) == 0) {
if (data != NULL)
XFree(data);
return;
}
free(shown);
shown = strdup(text);
shownFor = client;
nitems = McdeMenuParse(text, items, MCDE_MENU_MAX);
if (nitems < 0)
nitems = 0;
if (data != NULL)
XFree(data);
Rebuild();
}
static void
Follow(Window w)
{
if (w == client)
return;
if (client != None)
XtUnregisterDrawable(dpy, client);
client = w;
if (client != None) {
XtRegisterDrawable(dpy, client, sink);
XSelectInput(dpy, client, PropertyChangeMask | StructureNotifyMask);
}
ReadMenu();
}
/* _MCDE_ACTIVE_MENU of the root */
static void
ReadActive(void)
{
Atom type;
int format;
unsigned long n, after;
unsigned char *data = NULL;
Window w = None;
if (XGetWindowProperty(dpy, DefaultRootWindow(dpy), aActive, 0, 1,
False, XA_WINDOW, &type, &format, &n, &after, &data) == Success &&
data != NULL && n == 1 && format == 32)
w = (Window) *(long *) data;
if (data != NULL)
XFree(data);
Follow(w);
}
static void
Events(Widget w, XtPointer data, XEvent *ev, Boolean *cont)
{
(void) w;
(void) data;
(void) cont;
switch (ev->type) {
case PropertyNotify:
if (ev->xproperty.window == DefaultRootWindow(dpy) &&
ev->xproperty.atom == aActive)
ReadActive();
else if (ev->xproperty.window == client &&
ev->xproperty.atom == aMenu)
ReadMenu();
break;
case DestroyNotify:
if (ev->xdestroywindow.window == client)
Follow(None);
break;
case EnterNotify:
/* the program brings its menus up to date before one opens */
if (ev->xcrossing.window == XtWindow(shell))
Send(aRefresh, 0, 0);
break;
case VisibilityNotify:
if (ev->xvisibility.window == XtWindow(shell) &&
ev->xvisibility.state != VisibilityUnobscured)
XRaiseWindow(dpy, XtWindow(shell));
break;
}
}
/* ---- the clock ---------------------------------------------------------- */
static void
Tick(XtPointer data, XtIntervalId *id)
{
XtAppContext app = (XtAppContext) data;
char buf[64];
time_t now = time(NULL);
struct tm tm;
XmString s;
(void) id;
localtime_r(&now, &tm);
strftime(buf, sizeof buf, "%a %e %b %H:%M", &tm);
s = XmStringCreateLocalized(buf);
XtVaSetValues(clockLabel, XmNlabelString, s, NULL);
XmStringFree(s);
/* the next full minute */
XtAppAddTimeOut(app, (unsigned long) (60 - tm.tm_sec) * 1000 + 50,
Tick, data);
}
int
main(int argc, char **argv)
{
XtAppContext app;
char name[32];
Window owner, root;
XEvent ev;
int width;
signal(SIGCHLD, SIG_IGN); /* no zombies of dtaction */
XtSetLanguageProc(NULL, NULL, NULL);
shell = XtVaAppInitialize(&app, "Dtbar", NULL, 0, &argc, argv,
(String *) fallback, XmNoverrideRedirect, True, NULL);
dpy = XtDisplay(shell);
XSetErrorHandler(IgnoreErrors);
snprintf(name, sizeof name, "_MCDE_BAR_S%d", DefaultScreen(dpy));
aBar = XInternAtom(dpy, name, False);
aMenu = XInternAtom(dpy, "_MCDE_MENU", False);
aActive = XInternAtom(dpy, "_MCDE_ACTIVE_MENU", False);
aActivate = XInternAtom(dpy, "_MCDE_MENU_ACTIVATE", False);
aRefresh = XInternAtom(dpy, "_MCDE_MENU_REFRESH", False);
aUtf8 = XInternAtom(dpy, "UTF8_STRING", False);
aManager = XInternAtom(dpy, "MANAGER", False);
owner = XGetSelectionOwner(dpy, aBar);
if (owner != None) {
fprintf(stderr, "dtbar: a bar runs on this screen already\n");
return 0;
}
width = DisplayWidth(dpy, DefaultScreen(dpy));
form = XtVaCreateManagedWidget("form", xmFormWidgetClass, shell,
XmNwidth, width, XmNshadowThickness, 1, NULL);
bar = XmCreateMenuBar(form, "mbar", NULL, 0);
XtVaSetValues(bar, XmNleftAttachment, XmATTACH_FORM,
XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM, NULL);
clockLabel = XtVaCreateManagedWidget("clock", xmLabelGadgetClass, form,
XmNrightAttachment, XmATTACH_FORM, XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM, NULL);
XtVaSetValues(bar, XmNrightAttachment, XmATTACH_WIDGET,
XmNrightWidget, clockLabel, NULL);
MakeMMenu();
XtManageChild(bar);
Tick((XtPointer) app, NULL);
/* the whole width, the height the menu bar wants; an override-redirect
* shell is not sized by a window manager, so it is sized here */
{
XtWidgetGeometry pref;
Dimension h;
memset(&pref, 0, sizeof pref);
(void) XtQueryGeometry(form, NULL, &pref);
h = (pref.request_mode & CWHeight) && pref.height > 0 ?
pref.height : 24;
XtVaSetValues(shell, XmNx, 0, XmNy, 0, XmNwidth, width,
XmNheight, h, NULL);
}
XtRealizeWidget(shell);
/* the bar of this screen; programs find it by the selection, and one
* that started before learns of it from MANAGER (ICCCM 2.8) */
root = DefaultRootWindow(dpy);
XSetSelectionOwner(dpy, aBar, XtWindow(shell), CurrentTime);
if (XGetSelectionOwner(dpy, aBar) != XtWindow(shell)) {
fprintf(stderr, "dtbar: cannot own %s\n", name);
return 1;
}
memset(&ev, 0, sizeof ev);
ev.xclient.type = ClientMessage;
ev.xclient.window = root;
ev.xclient.message_type = aManager;
ev.xclient.format = 32;
ev.xclient.data.l[0] = CurrentTime;
ev.xclient.data.l[1] = (long) aBar;
ev.xclient.data.l[2] = (long) XtWindow(shell);
XSendEvent(dpy, root, False, StructureNotifyMask, &ev);
/* the root and the client's window are registered with a widget, so
* their events come to Events; their masks are selected by hand (raw) */
/* not the shell: it stops on a StructureNotify of another window
* ("Event with wrong window", Shell.c) */
sink = XtVaCreateWidget("sink", widgetClass, XtCreatePopupShell(
"sinkShell", overrideShellWidgetClass, shell, NULL, 0),
XmNwidth, 1, XmNheight, 1, NULL);
XtRegisterDrawable(dpy, root, sink);
XSelectInput(dpy, root, PropertyChangeMask);
XtAddRawEventHandler(sink, PropertyChangeMask | StructureNotifyMask,
False, Events, NULL);
XtAddEventHandler(shell, EnterWindowMask | VisibilityChangeMask, False,
Events, NULL);
ReadActive();
XtAppMainLoop(app);
return 0;
}
+11
View File
@@ -0,0 +1,11 @@
#!/bin/ksh
#
# 0090.dtbar -- MCDE: the bar at the top of the screen runs in every session
#
# Sourced by Xsession (Xsession.d). dtbar is one per screen: started a
# second time it says so and ends. Remove the execute bit to switch it off;
# the programs then keep their menu bars in their windows.
#
if [ -x "$DT_BINPATH/dtbar" ]; then
"$DT_BINPATH/dtbar" &
fi
+1 -1
View File
@@ -76,7 +76,7 @@ dist_configs_DATA = Xaccess Xconfig Xfailsafe Xservers
dist_configs_SCRIPTS = sys.dtprofile Xfailsafe Xreset Xsetup Xstartup
xsessdir=$(CDE_INSTALLATION_TOP)/config/Xsession.d
dist_xsess_SCRIPTS = 0060.dtsysenv 0070.dtfonts 0080.dtlaunch
dist_xsess_SCRIPTS = 0060.dtsysenv 0070.dtfonts 0080.dtlaunch 0090.dtbar
dist_bin_SCRIPTS = Xsession