diff --git a/AGENTS.md b/AGENTS.md index 78134fe0..71138fa2 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -363,7 +363,12 @@ narratives and test notes, is `docs/reference/mcde-agents-history-2026-11-13.txt 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 -- + history shows it). **The history is opt-in** (`Dtlaunch*clipboardHistory`, + default False; System Settings > Keyboard & Mouse > Shortcuts writes it and + restarts the launcher): off, nothing is asked of the clipboard's owner (0 + requests measured) and the hint line drops "the clipboard". On, a new text + is kept only if its owner does not offer `x-kde-passwordManagerHint` as + "secret" (`docs/reference/clipboard-password-hint.txt`). 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`. diff --git a/programs/dtlaunch/dtlaunch.c b/programs/dtlaunch/dtlaunch.c index a122e4eb..687d2512 100644 --- a/programs/dtlaunch/dtlaunch.c +++ b/programs/dtlaunch/dtlaunch.c @@ -83,7 +83,8 @@ static struct { Display *dpy; Window root; Atom a_clipboard, a_utf8, a_targets, a_text, a_self, a_quit, - a_show; + a_show, a_secret; + Boolean keep_history; /* Dtlaunch*clipboardHistory */ KeyCode hot_code; unsigned int hot_mods; char **programs; @@ -105,11 +106,16 @@ static struct { typedef struct { String hotkey; + Boolean history; } Resources; static XtResource resources[] = { { "hotkey", "Hotkey", XtRString, sizeof(String), XtOffsetOf(Resources, hotkey), XtRString, "Cmd+space" }, + /* off unless asked for (System Settings > Keyboard > Shortcuts): what + * was copied is shown on the screen the moment the launcher opens */ + { "clipboardHistory", "ClipboardHistory", XtRBoolean, sizeof(Boolean), + XtOffsetOf(Resources, history), XtRImmediate, (XtPointer) False }, }; static XrmOptionDescRec options[] = { @@ -350,18 +356,47 @@ remember(const char *text) L.nhistory++; } +/* Password managers (KeePassXC, KDE Wallet ...) offer the target + * x-kde-passwordManagerHint with the value "secret" beside the text they put + * on the clipboard, and clipboard managers are meant to leave such a text + * out (docs/reference/clipboard-password-hint.txt). An owner that does not + * know the target fails the conversion: then the text is an ordinary one. */ +static void +got_hint(Widget w, XtPointer client, Atom *selection, Atom *type, + XtPointer value, unsigned long *length, int *format) +{ + char *text = (char *)client; + int secret; + + (void)w; (void)selection; (void)type; + secret = value != NULL && *format == 8 && *length >= 6 && + memcmp(value, "secret", 6) == 0; + if (!secret) + remember(text); + memset(text, 0, strlen(text)); /* it may have been a password */ + free(text); + XtFree((char *)value); +} + static void got_clipboard(Widget w, XtPointer client, Atom *selection, Atom *type, XtPointer value, unsigned long *length, int *format) { - (void)w; (void)client; (void)selection; + (void)w; (void)client; if (value != NULL && *format == 8 && (*type == L.a_utf8 || *type == XA_STRING)) { char *s = XtMalloc((Cardinal)(*length + 1)); memcpy(s, value, *length); s[*length] = '\0'; - remember(s); + /* only a text that is new asks the owner for the hint: the + * same text again (the poll) costs no second request */ + if (s[0] != '\0' && !(L.nhistory > 0 && + strcmp(L.history[0], s) == 0)) { + XtGetSelectionValue(L.top, *selection, L.a_secret, + got_hint, xstrdup(s), CurrentTime); + } + memset(s, 0, *length); XtFree(s); } XtFree((char *)value); @@ -906,11 +941,13 @@ main(int argc, char **argv) L.a_utf8 = XInternAtom(L.dpy, "UTF8_STRING", False); L.a_targets = XInternAtom(L.dpy, "TARGETS", False); L.a_text = XInternAtom(L.dpy, "TEXT", False); + L.a_secret = XInternAtom(L.dpy, "x-kde-passwordManagerHint", False); L.a_self = XInternAtom(L.dpy, "_MCDE_DTLAUNCH", False); L.a_show = XInternAtom(L.dpy, "_MCDE_DTLAUNCH_SHOW", False); L.a_quit = XInternAtom(L.dpy, "_MCDE_DTLAUNCH_QUIT", False); XtGetApplicationResources(L.top, &res, resources, XtNumber(resources), NULL, 0); + L.keep_history = res.history; s = NULL; show_now = XrmGetResource(XtDatabase(L.dpy), "dtlaunch.show", "Dtlaunch.Show", &s, &(XrmValue){ 0, NULL }) ? True : False; @@ -969,8 +1006,16 @@ main(int argc, char **argv) fprintf(stderr, "dtlaunch: hot key \"%s\" not understood\n", res.hotkey); } - if (!watch_clipboard()) + /* no history, no watching: nothing is asked of the clipboard's owner */ + if (L.keep_history && !watch_clipboard()) (void)XtAppAddTimeOut(L.app, POLL_MS, poll_clipboard, NULL); + if (!L.keep_history) { + XmString none = XmStringCreateLocalized((char *)"Type to find a " + "program, a setting, a snippet, or =1+2"); + + XtVaSetValues(L.hint, XmNlabelString, none, NULL); + XmStringFree(none); + } if (show_now) show(); diff --git a/programs/dtsystemsettings/input.c b/programs/dtsystemsettings/input.c index 79a3e9b7..fd8bcf40 100644 --- a/programs/dtsystemsettings/input.c +++ b/programs/dtsystemsettings/input.c @@ -738,7 +738,8 @@ static struct { }; #define NSHORTCUTS ((int) (sizeof shortcuts / sizeof shortcuts[0])) -static Widget scList, scField, scChange, scNote; +static Widget scList, scField, scChange, scNote, scHistory; +static Boolean scHistoryState; static int scSel = -1; /* ~/.dt/shortcuts: "Name=key", one a line */ @@ -983,6 +984,29 @@ ShortcutRestore(Widget w, XtPointer data, XtPointer call) XmTextFieldSetString(scField, "Cmd+space"); } +/* "The launcher keeps a history of what was copied": Dtlaunch*clipboardHistory, + * off unless asked for (the launcher shows it the moment it opens; t0080). + * Written as the key is, and the launcher started again to read it. */ +static void +LaunchHistoryChanged(Widget w, XtPointer data, XtPointer call) +{ + char res[80]; + + (void) w; + (void) data; + (void) call; + if (inputSyncing) + return; + scHistoryState = XmToggleButtonGetState(scHistory); + (void)snprintf(res, sizeof res, "Dtlaunch*clipboardHistory: %s\n", + scHistoryState ? "True" : "False"); + _DtAddToResource(XtDisplay(scList), res); + RestartDtlaunch(); + SetText(scNote, scHistoryState ? + "Kept in memory only; a password manager's passwords are left out." : + "The launcher keeps no history of what you copy."); +} + static Widget MakeShortcutsPage(Widget parent) { @@ -1007,6 +1031,14 @@ MakeShortcutsPage(Widget parent) scChange = Button(row, "Change", ShortcutChange, NULL); XtSetSensitive(scChange, False); (void) Button(row, "Restore Defaults", ShortcutRestore, NULL); + scHistory = XtVaCreateManagedWidget("The launcher keeps a history of what " + "was copied", xmToggleButtonWidgetClass, box, NULL); + scHistoryState = DtwmResource(XtDisplay(parent), + "dtlaunch.clipboardHistory", "Dtlaunch.ClipboardHistory", "true", + False); + XmToggleButtonSetState(scHistory, scHistoryState, False); + XtAddCallback(scHistory, XmNvalueChangedCallback, + LaunchHistoryChanged, NULL); scNote = Text(box, "shortNote", ""); ShortcutRead(); ShortcutFill(); @@ -1023,8 +1055,8 @@ static Widget inputPage[3]; static void InputSyncToggles(void) { - Widget toggles[10]; - Boolean state[10]; + Widget toggles[11]; + Boolean state[11]; int i, n = 0; toggles[n] = kbRepeat; n++; @@ -1037,6 +1069,7 @@ InputSyncToggles(void) toggles[n] = msScrollNatural; n++; toggles[n] = wfPointer; n++; toggles[n] = wfRaise; n++; + toggles[n] = scHistory; n++; state[0] = kbRepeatState; state[1] = kbKindState == 0; state[2] = kbKindState == 1; @@ -1047,6 +1080,7 @@ InputSyncToggles(void) state[7] = msWheelNaturalState; state[8] = wfPointerState; state[9] = wfRaiseState; + state[10] = scHistoryState; /* off then on, with the notifications: the indicator redraws, and * the pane's own callbacks stand aside (inputSyncing) */ inputSyncing = True;