MCDE: System Settings > Language replaces dtstyle's language choice

language.c lists the UTF-8 locales of locale -a; 'Use for Next Login' writes
~/.dt/language, which Xsession.d/0010.language reads before the desktop starts.
Compiled and linked with make mcde-host (build/logs/mcde-host-2026-11-13c.log);
not yet run on a display.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
lotherkandClaude Sonnet 5.5 committed 2026-11-13 10:24:31 +00:00
1 parent d36d739a10
commit 58f9281bb5
7 files changed
+276 -4

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
#!/bin/ksh
#
# 0010.language -- MCDE: the language the user chose in System Settings
#
# Sourced by Xsession (Xsession.d), before the desktop starts.
# ~/.dt/language holds one locale name ("de_DE.UTF-8"), written by System
# Settings > Language (programs/dtsystemsettings/language.c); it replaces the
# language of the login screen. A name locale(1) -a does not list is left
# alone, so a locale removed later cannot leave the session without one.
# No file: the login screen's language, as in CDE.
#
if [ -r "$HOME/.dt/language" ]; then
mcde_lang=$(sed -n '1{s/[[:space:]]//g;p;}' "$HOME/.dt/language")
if [ -n "$mcde_lang" ] &&
locale -a 2> /dev/null | grep -qx -- "$mcde_lang"; then
LANG=$mcde_lang
export LANG
[ -n "$LC_ALL" ] && LC_ALL=$mcde_lang && export LC_ALL
fi
unset mcde_lang
fi
+1 -1
View File
@@ -76,7 +76,7 @@ dist_configs_DATA = Xaccess Xconfig Xfailsafe Xservers
dist_configs_SCRIPTS = sys.dtprofile sys.sessionetc Xfailsafe Xreset Xsetup Xstartup
xsessdir=$(CDE_INSTALLATION_TOP)/config/Xsession.d
dist_xsess_SCRIPTS = 0060.dtsysenv 0070.dtfonts 0071.displays 0072.dtkeys 0075.homefolders 0077.dtappscan 0078.dtthemesync
dist_xsess_SCRIPTS = 0010.language 0060.dtsysenv 0070.dtfonts 0071.displays 0072.dtkeys 0075.homefolders 0077.dtappscan 0078.dtthemesync
# MCDE: the desktop programs, started by dtsession through sys.sessionetc
# once the session resources and the colour server are there
+1 -1
View File
@@ -7,7 +7,7 @@ bin_PROGRAMS = dtsystemsettings
dtsystemsettings_SOURCES = main.c panes.c panes.h ui.h accounts.c update.c \
network.c \
input.c appearance.c desktop.c timezone.c wifi.c \
startup.c sharing.c backup.c displays.c
startup.c sharing.c backup.c displays.c language.c
dtsystemsettings_CPPFLAGS = -I$(top_srcdir)/include $(DT_INCDIR) \
-I$(top_builddir)/include $(XFT_CFLAGS) \
-DCDE_INSTALLATION_TOP=\"$(CDE_INSTALLATION_TOP)\" \
+246
View File
@@ -0,0 +1,246 @@
/*
* language.c -- dtsystemsettings: the language of the desktop
*
* Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE.
*
* Replaces CDE's style manager here (Konrad, 2026-11-13: "das alte dtstyle
* muss weg"). The list is what locale(1) -a prints -- the POSIX utility,
* the same source dtlogin's language menu has (dtlslocale) -- reduced to
* the UTF-8 locales and "C". "Use for Next Login" writes the name to
* ~/.dt/language, which Xsession.d/0010.language reads before the desktop
* starts (programs/dtlogin/config); "Use the Login Screen's" removes it.
* A running session keeps its language: every program has read LANG at its
* start. Input methods (dtstyle's "Input Method" dialog) are not here;
* dtimsstart(1) still starts one.
*
* C99, POSIX, Xt and Motif only (ext/src/mcde/AGENTS.md).
*/
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include <Xm/List.h>
#include <Xm/RowColumn.h>
#include "ui.h"
#define MAX_LOCALES 1000
#define LOCALE_LEN 64
static char (*locales)[LOCALE_LEN];
static int nlocales;
static char chosen[LOCALE_LEN]; /* ~/.dt/language, "" without one */
static Widget localeList, useButton, loginButton, langNote;
/* ~/.dt/language into BUF; the path when PATH is not NULL */
static void
LanguageFile(char *buf, size_t len)
{
const char *home = getenv("HOME");
snprintf(buf, len, "%s/.dt/language", home != NULL ? home : "");
}
static void
ReadChosen(void)
{
char path[1024];
FILE *f;
chosen[0] = '\0';
LanguageFile(path, sizeof path);
if ((f = fopen(path, "r")) == NULL)
return;
if (fgets(chosen, sizeof chosen, f) == NULL)
chosen[0] = '\0';
chosen[strcspn(chosen, " \t\r\n")] = '\0';
fclose(f);
}
/* a locale worth offering: C, or one with a UTF-8 code set */
static int
Offered(const char *name)
{
const char *dot = strchr(name, '.');
if (strcmp(name, "C") == 0)
return 1;
return dot != NULL && (strncasecmp(dot + 1, "UTF-8", 5) == 0 ||
strncasecmp(dot + 1, "utf8", 4) == 0);
}
static int
Compare(const void *a, const void *b)
{
return strcmp((const char *) a, (const char *) b);
}
static void
ReadLocales(void)
{
char line[LOCALE_LEN];
FILE *p;
nlocales = 0;
if ((p = popen("locale -a 2>/dev/null", "r")) == NULL)
return;
while (fgets(line, sizeof line, p) != NULL && nlocales < MAX_LOCALES) {
line[strcspn(line, "\r\n")] = '\0';
if (line[0] != '\0' && Offered(line))
snprintf(locales[nlocales++], LOCALE_LEN, "%s", line);
}
(void) pclose(p);
qsort(locales, (size_t) nlocales, sizeof locales[0], Compare);
}
/* the locale selected in the list, or NULL */
static const char *
Selected(void)
{
int *pos = NULL, n = 0, i;
if (!XmListGetSelectedPos(localeList, &pos, &n) || n < 1) {
XtFree((char *) pos);
return NULL;
}
i = pos[0] - 1;
XtFree((char *) pos);
return i >= 0 && i < nlocales ? locales[i] : NULL;
}
static void
ShowState(void)
{
const char *lang = getenv("LANG");
const char *s = Selected();
char text[256];
if (chosen[0] != '\0')
snprintf(text, sizeof text, "This session: %s. Next login: %s.",
lang != NULL ? lang : "C", chosen);
else
snprintf(text, sizeof text, "This session: %s. Next login: the "
"language chosen on the login screen.",
lang != NULL ? lang : "C");
SetText(langNote, text);
XtSetSensitive(useButton, s != NULL && strcmp(s, chosen) != 0);
XtSetSensitive(loginButton, chosen[0] != '\0');
}
static void
LocaleChosen(Widget w, XtPointer data, XtPointer call)
{
(void) w;
(void) data;
(void) call;
ShowState();
}
static void
UseLanguage(Widget w, XtPointer data, XtPointer call)
{
const char *s = Selected();
char path[1024], tmp[1100];
FILE *f;
(void) data;
(void) call;
if (s == NULL)
return;
/* written beside and renamed over, so a reader never sees half */
LanguageFile(path, sizeof path);
snprintf(tmp, sizeof tmp, "%s.new", path);
if ((f = fopen(tmp, "w")) == NULL || fprintf(f, "%s\n", s) < 0 ||
fclose(f) != 0 || rename(tmp, path) != 0) {
remove(tmp);
Message(w, "The language could not be written to ~/.dt/language.",
1);
return;
}
snprintf(chosen, sizeof chosen, "%s", s);
ShowState();
}
static void
UseLoginScreen(Widget w, XtPointer data, XtPointer call)
{
char path[1024];
(void) data;
(void) call;
LanguageFile(path, sizeof path);
if (remove(path) != 0 && chosen[0] != '\0') {
Message(w, "~/.dt/language could not be removed.", 1);
return;
}
chosen[0] = '\0';
ShowState();
}
static void
LanguageGone(Widget w, XtPointer data, XtPointer call)
{
(void) w;
(void) data;
(void) call;
free(locales);
locales = NULL;
nlocales = 0;
}
Widget
MakeLanguage(Widget parent)
{
Widget box = XtVaCreateManagedWidget("language", xmRowColumnWidgetClass,
parent, XmNspacing, 6, NULL);
Widget buttons;
const char *lang = getenv("LANG"), *want;
Arg a[4];
int n, i, sel = 0;
locales = calloc(MAX_LOCALES, sizeof *locales);
if (locales != NULL)
ReadLocales();
ReadChosen();
XtAddCallback(box, XmNdestroyCallback, LanguageGone, NULL);
(void) Text(box, "label", "The language of menus, messages, dates and "
"numbers. It is used from the next login on.");
n = 0;
XtSetArg(a[n], XmNselectionPolicy, XmBROWSE_SELECT); n++;
XtSetArg(a[n], XmNvisibleItemCount, 12); n++;
XtSetArg(a[n], XmNwidth, 360); n++;
localeList = XmCreateScrolledList(box, "locales", a, n);
XtManageChild(localeList);
want = chosen[0] != '\0' ? chosen : lang;
for (i = 0; i < nlocales; i++) {
XmString s = XmStringCreateLocalized(locales[i]);
XmListAddItemUnselected(localeList, s, 0);
XmStringFree(s);
if (want != NULL && strcmp(locales[i], want) == 0)
sel = i + 1;
}
if (sel > 0) {
XmListSelectPos(localeList, sel, False);
XmListSetPos(localeList, sel > 3 ? sel - 3 : 1);
}
XtAddCallback(localeList, XmNbrowseSelectionCallback, LocaleChosen,
NULL);
buttons = XtVaCreateManagedWidget("buttons", xmRowColumnWidgetClass,
box, XmNorientation, XmHORIZONTAL, XmNspacing, 8, NULL);
useButton = PaneButton(buttons, "Use for Next Login", UseLanguage,
NULL);
loginButton = PaneButton(buttons, "Use the Login Screen's",
UseLoginScreen, NULL);
langNote = Text(box, "note", nlocales == 0 ?
"locale -a listed no languages." : "");
ShowState();
return box;
}
+2
View File
@@ -549,6 +549,8 @@ ShowPane(const Pane *p)
w = MakeMouse(paneArea);
else if (strcmp(p->id, "displays") == 0)
w = MakeDisplays(paneArea);
else if (strcmp(p->id, "language") == 0)
w = MakeLanguage(paneArea);
if (w == NULL)
return;
current = w;
+2 -2
View File
@@ -25,8 +25,8 @@ const Pane panes[] = {
NULL },
{ "desktop", "Desktop", CAT_PERSONAL, "DtBkdrp.pm", PANE_OWN, NULL },
{ "fonts", "Fonts", CAT_PERSONAL, "DtFont.pm", PANE_OWN, NULL },
{ "language", "Language", CAT_PERSONAL, "DtI18N.pm", PANE_COMMAND,
"dtstyle" },
{ "language", "Language", CAT_PERSONAL, "DtI18N.pm", PANE_OWN,
NULL },
{ "screensaver", "Screen Saver", CAT_PERSONAL, "DtScrn.pm",
PANE_OWN, NULL },
+3
View File
@@ -61,6 +61,9 @@ int SetTimezoneCommand(const char *zone);
/* the panes in appearance.c */
Widget MakeAppearance(Widget parent);
Widget MakeFonts(Widget parent);
/* the Language pane (language.c), ~/.dt/language at login
* (Xsession.d/0010.language) */
Widget MakeLanguage(Widget parent);
/* the panes in input.c */
Widget MakeKeyboard(Widget parent);
Widget MakeMouse(Widget parent);