Files
mcde/include/Mcde/GlobalMenu.h
T
lotherkandClaude Opus 5.5 7757e1b19f mcde: dtterm's menus in dtbar; every menu bar of a window hidden; no rebuild of an open menu
dtterm does not call DtInitialize: it starts the program side itself
(_DtMcdeGlobalMenuInitialize, declared in Mcde/GlobalMenu.h when Xt is in).
McdeGlobalMenu.c keeps all menu bars (dtterm has one per tab), hides any the
program manages while the bar runs (Xt change hook) and exports the first
that lives.  dtterm's menus follow the tab with the focus
(_DtTermViewMenuSetCurrent, setContext split into contextFor), since from the
bar they are not posted from the tab.  dtbar defers a new menu text while one
of its menus is open (the open menu was pulled away under the click).
Tested on Xvfb: dtterm's Window/Edit/Options/Help in the bar, no menu bar in
the window with two tabs, Window > New Tab from the bar makes the third.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 07:43:50 +00:00

96 lines
3.6 KiB
C

/*
* 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);
#ifdef _XtIntrinsic_h
/*
* The program side (lib/DtSvc/DtUtil2/McdeGlobalMenu.c, in libDtSvc).
* DtInitialize() calls it; a program that does not call DtInitialize (dtterm)
* calls it itself, after XtAppInitialize and before it makes a menu bar.
*/
extern void _DtMcdeGlobalMenuInitialize(Display *dpy, Widget toplevel);
#endif
#endif /* _Mcde_GlobalMenu_h */