diff --git a/AGENTS.md b/AGENTS.md index 7acb33c7..96d18be6 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -165,6 +165,30 @@ narratives and test notes, is `docs/reference/mcde-agents-history-2026-11-13.txt kills the child (`mcdeChildPid`) and unlinks the half-written target. Measured: a 4 GB copy shows the window with "129.0 MB of 4295.0 MB" while the file is written. +- **The web browser** (t0179): the desktop has one action for a web page, + `McdeWeb` (`programs/types/datatypes.dt.src`; `EXEC_STRING` runs + `dtsystemsettings -open-web "%Arg_1%"`), and the choice of browser lives in + `~/.dt/defaults` as `web:` (Default Programs pane). `-open-web` is handled + **before Xt is set up** -- an action must not need a display -- and starts + the program with `execlp`, never a shell; the argument is refused when it + carries a shell character. The `.html` and `.htm` criteria of + `programs/types/firefox.dt` map their `Open` to `McdeWeb`, so a double click + in dtfile follows the file's choice (measured: with `web: mcdetest-browser` + dtfile hands the page to that program, with `web: firefox` a Firefox window + opens). Measured too: an action whose `ARG_TYPE` names a data type the file + does not have is refused ("Either action ... does not apply"), so McdeWeb + takes `ARG_TYPE *` and is named only by the types that may use it. +- **Firefox's look and keys** (`dtthemesync`, the `Firefox()` part): every + profile under `~/.mozilla/firefox` that has a `prefs.js` gets a `user.js` + (`browser.download.dir` = `~/Downloads`, `browser.download.folderList` 2, + reduced motion, no cosmetic animations, no smooth scrolling, and + `ui.key.accelKey` 91 -- Command is Mod4 in MCDE) and a `chrome/userChrome.css` + written from the palette (toolbar, tabs, arrow panels). Measured: the files + appear with `--toolbar-bgcolor: #c6b2a8` from Default.dp. Firefox is GTK and + takes no part in the desktop's global menu: dtbar shows only the M menu while + it has the focus. A Firefox window's own Cmd+T/W/L was **not** measured + (the user.js sets the accelerator; that measurement needs a person at the + keyboard); the `dtexplorer` of the task is its own program, still to come. - **dtcmprefs** (`programs/dtcmprefs`): the calendar's settings window on the shared McdePrefs pattern -- General (first day of the week, week numbers, default appointment length), Accounts (a read-only note: the diff --git a/programs/dtsystemsettings/defaults.c b/programs/dtsystemsettings/defaults.c index f81ce1cf..09779b96 100644 --- a/programs/dtsystemsettings/defaults.c +++ b/programs/dtsystemsettings/defaults.c @@ -167,6 +167,60 @@ Present(const char *name) /* ---- the rows ----------------------------------------------------------- */ + +/* dtsystemsettings -open-web URL|PATH: the browser from ~/.dt/defaults, + * started without a shell (t0179). Returns 0 when the program started and + * printed nothing, 1 with a sentence otherwise. */ +int +OpenWebCommand(const char *arg) +{ + char path[1024], line[256], prog[128] = ""; + FILE *f; + pid_t pid; + const char *home = getenv("HOME"); + const char *p; + + if (arg == NULL || arg[0] == '\0') { + printf("No address was given.\n"); + return 1; + } + for (p = arg; *p != '\0'; p++) + if (*p == '\n' || *p == ';' || *p == '|' || *p == '`' || + *p == '$' || *p == '\'' || *p == '"') { + printf("That is not an address: %s\n", arg); + return 1; + } + if (home != NULL && (size_t) snprintf(path, sizeof path, + "%s/.dt/defaults", home) < sizeof path && + (f = fopen(path, "r")) != NULL) { + while (fgets(line, sizeof line, f) != NULL) { + line[strcspn(line, "\r\n")] = '\0'; + if (strncmp(line, "web:", 4) == 0) { + char *v = line + 4; + + while (*v == ' ' || *v == '\t') + v++; + (void)snprintf(prog, sizeof prog, "%s", v); + } + } + fclose(f); + } + if (prog[0] == '\0') + (void)snprintf(prog, sizeof prog, "firefox"); + pid = fork(); + if (pid == 0) { + (void)setsid(); + execlp(prog, prog, arg, (char *) NULL); + _exit(127); + } + if (pid < 0) { + printf("The browser could not be started.\n"); + return 1; + } + printf("Opened in %s: %s\n", prog, arg); + return 0; +} + static void Chosen(Widget w, XtPointer data, XtPointer call) { @@ -229,13 +283,41 @@ Row(Widget parent, const Kind *k) return row; } +/* the pair once the pane is laid out: a radio state set before its page is + * managed does not paint (measured, as in the Keyboard pane) */ +static void +SyncLinks(XtPointer data, XtIntervalId *id) +{ + char v[32]; + Widget want; + + (void) data; + (void) id; + Get("web-open", v, sizeof v); + want = strcmp(v, "window") == 0 ? windowToggle : tabToggle; + if (getenv("MCDE_DEFAULTS_DEBUG") != NULL) + fprintf(stderr, "defaults: web-open='%s' -> %s\n", v, + want == tabToggle ? "tab" : "window"); + XmToggleButtonSetState(windowToggle, False, True); + XmToggleButtonSetState(tabToggle, False, True); + XmToggleButtonSetState(want, True, True); + /* the radio's own indicator follows the group only after a redraw */ + XmUpdateDisplay(want); + XmUpdateDisplay(windowToggle); +} + static void LinkChosen(Widget w, XtPointer data, XtPointer call) { (void) w; (void) call; - if (((XmToggleButtonCallbackStruct *) call)->set) + Boolean on = ((XmToggleButtonCallbackStruct *) call)->set; + + if (on) Set("web-open", (const char *) data); + XmToggleButtonSetState(w, on, False); + XmToggleButtonSetState(w == windowToggle ? tabToggle : windowToggle, + False, False); } Widget @@ -252,9 +334,11 @@ MakeDefaults(Widget parent) (void) Row(box, &kinds[i]); (void) Text(box, "linksLabel", "A link from another program opens:"); + /* two toggles kept exclusive by the callbacks: a radio box in a page + * that is laid out late does not paint its state (measured) */ radio = XtVaCreateManagedWidget("linksMode", xmRowColumnWidgetClass, box, XmNorientation, XmVERTICAL, - XmNradioBehavior, True, XmNspacing, 2, XmNmarginWidth, 0, NULL); + XmNspacing, 2, XmNmarginWidth, 0, NULL); windowToggle = XtVaCreateManagedWidget("in a new window", xmToggleButtonWidgetClass, radio, NULL); tabToggle = XtVaCreateManagedWidget("in a tab of the window that is " @@ -272,6 +356,7 @@ MakeDefaults(Widget parent) XmToggleButtonSetState(tabToggle, False, False); XmToggleButtonSetState(want, True, False); } + XtAppAddTimeOut(app, 0, SyncLinks, NULL); XtAddCallback(windowToggle, XmNvalueChangedCallback, LinkChosen, (XtPointer) "window"); XtAddCallback(tabToggle, XmNvalueChangedCallback, LinkChosen, diff --git a/programs/dtsystemsettings/main.c b/programs/dtsystemsettings/main.c index f803f527..14b9c687 100644 --- a/programs/dtsystemsettings/main.c +++ b/programs/dtsystemsettings/main.c @@ -1317,6 +1317,12 @@ main(int argc, char **argv) const char *start = NULL; int i; + /* the action of a web page (programs/types, McdeWeb) starts no window + * and needs no display: done before Xt is set up */ + for (i = 1; i + 1 < argc; i++) + if (strcmp(argv[i], "-open-web") == 0) + return OpenWebCommand(argv[i + 1]); + XtSetLanguageProc(NULL, NULL, NULL); shell = XtVaAppInitialize(&app, "Dtsystemsettings", NULL, 0, &argc, argv, (String *) fallback, XmNtitle, "System Settings", NULL); @@ -1329,6 +1335,8 @@ main(int argc, char **argv) return ApplyDisplaysCommand(XtDisplay(shell)); else if (strcmp(argv[i], "-set-timezone") == 0 && i + 1 < argc) return SetTimezoneCommand(argv[i + 1]); + else if (strcmp(argv[i], "-open-web") == 0 && i + 1 < argc) + return OpenWebCommand(argv[++i]); else if (strcmp(argv[i], "-set-default-printer") == 0 && i + 1 < argc) return SetDefaultPrinterCommand(argv[++i]); diff --git a/programs/dtsystemsettings/ui.h b/programs/dtsystemsettings/ui.h index e0bd20a2..64a36013 100644 --- a/programs/dtsystemsettings/ui.h +++ b/programs/dtsystemsettings/ui.h @@ -83,6 +83,8 @@ Widget MakeEnergy(Widget parent); Widget MakeInternet(Widget parent); /* the default programs (defaults.c), ~/.dt/defaults */ Widget MakeDefaults(Widget parent); +/* dtsystemsettings -open-web URL: the browser of ~/.dt/defaults (t0179) */ +int OpenWebCommand(const char *arg); /* what this computer is (sysinfo.c): Hardware | Network | Software */ Widget MakeSysinfo(Widget parent); /* the Startup Disk pane (startupdisk.c) */ diff --git a/programs/dtthemesync/dtthemesync.c b/programs/dtthemesync/dtthemesync.c index b99ae86a..c69572f9 100644 --- a/programs/dtthemesync/dtthemesync.c +++ b/programs/dtthemesync/dtthemesync.c @@ -34,6 +34,7 @@ #define _POSIX_C_SOURCE 200809L +#include #include #include #include @@ -483,6 +484,83 @@ KdeGlobals(char *out, size_t len) } } + +/* ---- Firefox --------------------------------------------------------------- + * + * Firefox is a package, MCDE does not depend on it; when a profile exists it + * is made to look and behave like the rest (t0179): the palette in + * userChrome.css, no animation and no smooth scrolling, downloads into + * ~/Downloads, and Command as the accelerator (ui.key.accelKey = 91, the + * Windows/Meta key that dtkeys gives Command). A profile is a directory + * with prefs.js; nothing is made for a browser that is not there. + */ + +static void +Firefox(const char *palette) +{ + char dirpath[2048], path[2100], buf[8192], b[16], f[16], t[16], tf[16], + s[16], sf[16], l[16], d[16]; + DIR *dir; + struct dirent *de; + + snprintf(dirpath, sizeof dirpath, "%s/.mozilla/firefox", home); + if ((dir = opendir(dirpath)) == NULL) + return; + Hex(&MAIN->bg, b, sizeof b); + Hex(&MAIN->fg, f, sizeof f); + Hex(&TEXT->bg, t, sizeof t); + Hex(&TEXT->fg, tf, sizeof tf); + Hex(&ACTIVE->bg, s, sizeof s); + Hex(&ACTIVE->fg, sf, sizeof sf); + Hex(&MAIN->bs, l, sizeof l); + Hex(&MAIN->ts, d, sizeof d); + while ((de = readdir(dir)) != NULL) { + char rel[1400]; + + if (de->d_name[0] == '.') + continue; + snprintf(path, sizeof path, "%s/%s/prefs.js", dirpath, + de->d_name); + if (access(path, R_OK) != 0) + continue; /* not a profile */ + snprintf(buf, sizeof buf, + "// MCDE (dtthemesync): written from the palette %s, changes are lost\n" + "user_pref(\"browser.download.dir\", \"%s/Downloads\");\n" + "user_pref(\"browser.download.folderList\", 2);\n" + "user_pref(\"browser.download.useDownloadDir\", true);\n" + "user_pref(\"ui.prefersReducedMotion\", 1);\n" + "user_pref(\"toolkit.cosmeticAnimations.enabled\", false);\n" + "user_pref(\"general.smoothScroll\", false);\n" + "// Command is Mod4 in MCDE (dtkeys); Firefox calls it accelKey\n" + "user_pref(\"ui.key.accelKey\", 91);\n", + palette != NULL ? palette : "the session", home); + snprintf(rel, sizeof rel, ".mozilla/firefox/%s/user.js", + de->d_name); + if (WriteFile(rel, buf) == 0 && verbose) + fprintf(stderr, "dtthemesync: Firefox profile %s\n", + de->d_name); + snprintf(buf, sizeof buf, + "/* MCDE (dtthemesync): the palette, changes are lost */\n" + ":root {\n" + " --toolbar-bgcolor: %s !important;\n" + " --toolbar-color: %s !important;\n" + " --lwt-accent-color: %s !important;\n" + " --lwt-text-color: %s !important;\n" + " --lwt-selected-tab-background-color: %s !important;\n" + " --tab-selected-textcolor: %s !important;\n" + " --arrowpanel-background: %s !important;\n" + " --arrowpanel-color: %s !important;\n" + "}\n" + "#nav-bar, #TabsToolbar, #PersonalToolbar {" + " background: %s !important; color: %s !important; }\n", + b, f, b, f, s, sf, t, tf, b, f); + snprintf(rel, sizeof rel, + ".mozilla/firefox/%s/chrome/userChrome.css", de->d_name); + (void) WriteFile(rel, buf); + } + closedir(dir); +} + /* ---- XSETTINGS ------------------------------------------------------------- */ static Atom @@ -787,6 +865,7 @@ main(int argc, char **argv) (void) WriteFile(".config/qt6ct/qt6ct.conf", buf); KdeGlobals(buf, sizeof buf); (void) WriteFile(".config/kdeglobals", buf); + Firefox(palette); if ((f = fopen(state, "w")) != NULL) { fprintf(f, "%s\n", theme); diff --git a/programs/types/datatypes.dt.src b/programs/types/datatypes.dt.src index b0f8482b..81ea92c8 100644 --- a/programs/types/datatypes.dt.src +++ b/programs/types/datatypes.dt.src @@ -56,6 +56,15 @@ ACTION Open TYPE MAP MAP_ACTION Dticon } +ACTION McdeWeb +{ + LABEL %|nls-1-Open| + ARG_TYPE * + TYPE COMMAND + WINDOW_TYPE NO_STDIO + EXEC_STRING CDE_INSTALLATION_TOP/bin/dtsystemsettings -open-web "%Arg_1%" +} + ACTION Print { LABEL %|nls-2-Print| @@ -704,7 +713,7 @@ XCOMM ####################################################### DATA_ATTRIBUTES HTML { - ACTIONS Open,Print + ACTIONS McdeWeb,Print ICON Dtdata IS_TEXT true NAME_TEMPLATE %s.html diff --git a/programs/types/firefox.dt b/programs/types/firefox.dt index 799da40e..746119f0 100644 --- a/programs/types/firefox.dt +++ b/programs/types/firefox.dt @@ -50,7 +50,7 @@ ACTION Open { ARG_TYPE firefox_FILE_1 TYPE MAP - MAP_ACTION firefox + MAP_ACTION McdeWeb LABEL Open } @@ -93,7 +93,7 @@ ACTION Open { ARG_TYPE firefox_FILE_3 TYPE MAP - MAP_ACTION firefox + MAP_ACTION McdeWeb LABEL Open }