diff --git a/AGENTS.md b/AGENTS.md index 5264db07..6956ef72 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -345,9 +345,24 @@ narratives and test notes, is `docs/reference/mcde-agents-history-2026-11-13.txt the first opening (tests, `tools/mcde-shot.sh`). Measured: typing `disp` lists the pane second (`docs/screenshots/leopard/Spotlight-mcde.png`); Return on `displays` starts `dtsystemsettings -pane displays` and its - window "Displays" appears. **Not done yet:** the two-column list grouped by - category, documents/mail/PDF/web results, the magnifier button in dtbar with - `-at X,Y`, and the clipboard without the 1 s poll (XFixes). + window "Displays" appears. **The clipboard history is told, it does not + ask** (t0080): `XFixesSelectSelectionInput` on CLIPBOARD + (`XFixesSetSelectionOwnerNotifyMask`), the new owner is read once when the + event arrives. `configure.ac` checks libXfixes and gives only dtlaunch + `XFIXESLIB` and `XFIXES_CPPFLAGS` (-DHAVE_XFIXES) -- not a define in + `config.h`, which would recompile the whole tree. Without the library or the + extension the owner is asked every 5 s (`POLL_MS`). Measured with `strace` + (writes to the X socket, 10 s idle after a 4 s start): **10 with the 1 s + poll, 0 with XFixes, 2 (at 5.0 s and 10.0 s) in the fallback** (the fallback + tested with an LD_PRELOAD shim that makes `XFixesQueryExtension` fail: an + Xvfb started with `-extension XFIXES` aborts as soon as any Motif client + connects, `privates.h: dixGetPrivateAddr: Assertion key->initialized`, also + for an unmodified dtpad, so it cannot serve for this). Both paths still + catch a copy (`xclip` while the launcher idles, then `dtlaunch -show`: the + history shows it). The recipe has `x11/libXfixes/buildlink3.mk` for it -- + not yet through a real cross build. **Not done yet:** the two-column list + grouped by category, documents/mail/PDF/web results, and the magnifier button + in dtbar with `-at X,Y`. - **Printers**: `dtsystemsettings/printers.c` lists the CUPS queues (`mcde_sys_printers`: lpstat -p/-d, parsed), shows the chosen one (state, location, model, default, shared), and adds one from what mDNS finds diff --git a/configure.ac b/configure.ac index a7568073..2f11be32 100644 --- a/configure.ac +++ b/configure.ac @@ -641,6 +641,17 @@ AC_CHECK_LIB(Xt, XtInitialize, [XTOOLLIB="-lXt ${XTOOLLIB}"], , [${EXTRA_INCS} ${EXTRA_LIBS}]) AC_CHECK_LIB(Xmu, XmuMakeAtom, [XTOOLLIB="-lXmu ${XTOOLLIB}"], , [${EXTRA_INCS} ${EXTRA_LIBS}]) +dnl MCDE: dtlaunch is told of a new clipboard owner by XFixes instead of asking +dnl for the clipboard every second (tasksd t0080); without libXfixes it asks +dnl every 5 s. Only dtlaunch uses it: XFIXESLIB and XFIXES_CPPFLAGS are its own +dnl (not a define in config.h: that would recompile every file of the tree). +XFIXESLIB="" +XFIXES_CPPFLAGS="" +AC_CHECK_LIB(Xfixes, XFixesSelectSelectionInput, + [XFIXESLIB="-lXfixes"; XFIXES_CPPFLAGS="-DHAVE_XFIXES"], , + [${EXTRA_INCS} ${EXTRA_LIBS}]) +AC_SUBST(XFIXESLIB) +AC_SUBST(XFIXES_CPPFLAGS) AC_CHECK_LIB(ICE, IceCloseConnection, [XTOOLLIB="-lICE ${XTOOLLIB}"], , [${EXTRA_INCS} ${EXTRA_LIBS}]) AC_CHECK_LIB(SM, SmcOpenConnection, [XTOOLLIB="-lSM ${XTOOLLIB}"], , diff --git a/pkgsrc/Makefile b/pkgsrc/Makefile index f15ddce7..77840607 100644 --- a/pkgsrc/Makefile +++ b/pkgsrc/Makefile @@ -219,6 +219,7 @@ post-install: pam-install .include "../../x11/libXScrnSaver/buildlink3.mk" .include "../../x11/libXinerama/buildlink3.mk" .include "../../x11/libXrandr/buildlink3.mk" +.include "../../x11/libXfixes/buildlink3.mk" .include "../../x11/libXdmcp/buildlink3.mk" .include "../../x11/xbitmaps/buildlink3.mk" .include "../../x11/libXmu/buildlink3.mk" diff --git a/programs/dtlaunch/Makefile.am b/programs/dtlaunch/Makefile.am index b1cc54e6..b12df904 100644 --- a/programs/dtlaunch/Makefile.am +++ b/programs/dtlaunch/Makefile.am @@ -5,7 +5,8 @@ MAINTAINERCLEANFILES = Makefile.in bin_PROGRAMS = dtlaunch dtlaunch_SOURCES = dtlaunch.c model.c model.h -dtlaunch_LDADD = $(XTOOLLIB) -lm +dtlaunch_CPPFLAGS = $(XFIXES_CPPFLAGS) +dtlaunch_LDADD = $(XFIXESLIB) $(XTOOLLIB) -lm check_PROGRAMS = test_model test_model_SOURCES = test_model.c model.c model.h diff --git a/programs/dtlaunch/dtlaunch.c b/programs/dtlaunch/dtlaunch.c index 9af69b6b..a122e4eb 100644 --- a/programs/dtlaunch/dtlaunch.c +++ b/programs/dtlaunch/dtlaunch.c @@ -15,9 +15,13 @@ * closes. Up and Down move in the list. The panes are asked for once, from * `dtsystemsettings -list-panes' (a pipe and exec, no shell, no display). * - * The clipboard history: every second the owner of CLIPBOARD is asked for its - * text (Xt selections, ICCCM); a new text goes to the top, at most HISTORY - * entries, kept in memory only -- passwords pass through the clipboard. + * The clipboard history: when the owner of CLIPBOARD changes (an XFixes + * selection event: the launcher is told, it does not ask) the new owner is + * asked for its text (Xt selections, ICCCM); a new text goes to the top, at + * most HISTORY entries, kept in memory only -- passwords pass through the + * clipboard. Without XFixes (libXfixes missing at build time, or the X server + * has no such extension) the owner is asked every POLL_MS; idle, the launcher + * with XFixes sends nothing to the server (tasksd t0080). * * One launcher per display: the first one owns the selection _MCDE_DTLAUNCH; * `dtlaunch -show' asks that one to open and exits; `dtlaunch -quit' asks it @@ -47,6 +51,9 @@ #include #include #include +#ifdef HAVE_XFIXES +#include +#endif #include #include #include @@ -59,7 +66,7 @@ #define HISTORY 50 #define MAXITEMS 40 #define MAXCLIP (64 * 1024) -#define POLL_MS 1000 +#define POLL_MS 5000 /* only without XFixes: how often to ask */ typedef enum { K_APP, K_SNIPPET, K_CLIP, K_CALC, K_PANE } Kind; @@ -87,6 +94,7 @@ static struct { size_t npanes; int panes_loaded; char *initial_text; /* -text: the field of the first opening */ + int xfixes_event; /* event type of XFixesSelectionNotify, or 0 */ char *history[HISTORY]; size_t nhistory; Item items[MAXITEMS]; @@ -359,18 +367,47 @@ got_clipboard(Widget w, XtPointer client, Atom *selection, Atom *type, XtFree((char *)value); } +/* ask OWNER of CLIPBOARD for its text, unless that is the launcher itself (it + * offers text of its own: offer()) or nobody */ +static void +request_clipboard(Window owner, Time t) +{ + if (owner != None && owner != XtWindow(L.top)) + XtGetSelectionValue(L.top, L.a_clipboard, L.a_utf8, + got_clipboard, NULL, t); +} + +/* without XFixes: ask every POLL_MS */ static void poll_clipboard(XtPointer client, XtIntervalId *id) { - Window owner = XGetSelectionOwner(L.dpy, L.a_clipboard); - (void)client; (void)id; - if (owner != None && owner != XtWindow(L.top)) - XtGetSelectionValue(L.top, L.a_clipboard, L.a_utf8, - got_clipboard, NULL, XtLastTimestampProcessed(L.dpy)); + request_clipboard(XGetSelectionOwner(L.dpy, L.a_clipboard), + XtLastTimestampProcessed(L.dpy)); (void)XtAppAddTimeOut(L.app, POLL_MS, poll_clipboard, NULL); } +/* Be told when the owner of CLIPBOARD changes, instead of asking: 1 when the + * X server has XFixes and the launcher was built with it, else 0 (the caller + * then polls). The text there now is read once, so the history starts with it. */ +static int +watch_clipboard(void) +{ +#ifdef HAVE_XFIXES + int ev_base, err_base; + + if (!XFixesQueryExtension(L.dpy, &ev_base, &err_base)) + return 0; + L.xfixes_event = ev_base + XFixesSelectionNotify; + XFixesSelectSelectionInput(L.dpy, L.root, L.a_clipboard, + XFixesSetSelectionOwnerNotifyMask); + request_clipboard(XGetSelectionOwner(L.dpy, L.a_clipboard), CurrentTime); + return 1; +#else + return 0; +#endif +} + /* ---- showing, hiding, doing -------------------------------------------- */ /* The panes of System Settings: what `dtsystemsettings -list-panes' prints, @@ -932,7 +969,8 @@ main(int argc, char **argv) fprintf(stderr, "dtlaunch: hot key \"%s\" not understood\n", res.hotkey); } - (void)XtAppAddTimeOut(L.app, POLL_MS, poll_clipboard, NULL); + if (!watch_clipboard()) + (void)XtAppAddTimeOut(L.app, POLL_MS, poll_clipboard, NULL); if (show_now) show(); @@ -948,6 +986,18 @@ main(int argc, char **argv) show(); continue; } +#ifdef HAVE_XFIXES + if (L.xfixes_event != 0 && ev.type == L.xfixes_event) { + XFixesSelectionNotifyEvent *sn = + (XFixesSelectionNotifyEvent *)&ev; + + /* a new owner of CLIPBOARD: read what it has now */ + if (sn->selection == L.a_clipboard) + request_clipboard(sn->owner, + sn->selection_timestamp); + continue; + } +#endif if (ev.type == ClientMessage && ev.xclient.message_type == L.a_show) { show();