MCDE: the bar after dtsession, its menus only for the focused program, a Network pane
Konrad, 2026-11-13: "panel fehlt, top leiste is lila", the network settings
"zu rudimentaer, keine ip config, kein dns", the global menu only while a
program that has one is in front.
The bar (and the launcher, the drop-down terminal, the login items) came
from Xsession.d, before dtsession had loaded the session's resources and
the colour server: dtbar took *background from ~/.Xdefaults (#6e1e7d, the
user's base16 theme; dtbar PID 1270788 started before dtsession 1270795).
Restarting dtbar in the running session gave the palette's colours. Now
dtsession runs sys.sessionetc -- the first of CDE_CONFIGURATION_TOP/config
and CDE_INSTALLATION_TOP/config, as sys.session is found -- before the
user's sessionetc (SmRestore.c, StartEtc); it sources config/sessionetc.d,
where 0080.dtlaunch, 0085.dtdropdown, 0090.dtbar and 0095.loginitems moved.
The bar takes colour set 5, the programs' background, not set 6 of a menu
bar (Dtbar*secondaryColorSetId: 5; measured #c6b2a8 with Default.dp).
dtwm publishes the focused client as _NET_ACTIVE_WINDOW (EWMH, WmEwmh.c
SetNetActiveWindow from SetKeyboardFocus and where the focus is dropped);
dtbar shows a program's menus only while the active window is the menus'
owner, a dialog of it (WM_TRANSIENT_FOR) or a window of the same program
(WM_CLIENT_LEADER). Measured on Xvfb with dtwm, dtbar, dtpad and xterm,
clicking: dtpad -> its menus, xterm -> M only, dtpad -> its menus again.
Network (dtsystemsettings/network.c, docs/reference/netconfig.txt): Show:
Network Status (a light and a sentence per card, Configure...) or one card
with the tabs TCP/IP (Using DHCP, with manual address, Manually, Off;
address, mask, router, DHCP client ID, Renew DHCP Lease; IPv6), DNS
(servers, search domains, what resolv.conf has now), Wi-Fi and Ethernet;
the lock and Apply Now as Accounts. McdeSys mcde_sys_net_config,
_configure, _renew (replacing mcde_sys_net_dhcp, which was declared and
implemented nowhere): NetBSD one block per interface in dhcpcd.conf, as
ifconfig.if(5) recommends, sysinst's static address in ifconfig.IF read and
moved there, applied with dhcpcd -n IF (cross-compiled with the tree's
x86_64--netbsd-gcc, not run); Linux the NetworkManager profile (nmcli).
mcde_sys_interfaces took the last IPv4 address (the secondary one), now the
first. Measured on this host, read only: the pane shows the three cards,
172.20.10.2/28 by DHCP, router 172.20.10.1, DNS 1.1.1.1, MAC, MTU 1500;
test_sysinfo (new checks: settings read, 300.1.2.3 refused) exit 0.
Nothing was applied on the development host.
From the review of 2026-11-12's commits: libDtTerm links libMcdeSound
(977a7347c made the bell call McdeSoundEvent; dtcodegen did not link); the
PLIST lacked dtphoto, dtpaint, dttoolbox, mcdesoundd, libMcdeSound, their
data and the sound themes (51 entries, from the installed tree); mcdesoundd
was started by nothing (sessionetc.d/0075.mcdesoundd) and took the
selection from a running server; dttoolbox kept only the first line of the
Selected menu and rebuilt it every 500 ms, and NewMenu returned an
uninitialised pointer past 64 menus.
Built and installed with make mcde-host MCDE_DIRS=install, exit 0.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
85fd446593
commit
1b524eb94c
34 files changed
+2264
-127
No files matched your search
@@ -0,0 +1,108 @@
|
||||
The network settings of an interface -- where each system keeps them
|
||||
Read 2026-11-13 for System Settings > Network (MCDE: McdeSys
|
||||
mcde_sys_net_config / mcde_sys_net_configure).
|
||||
|
||||
== NetBSD: dhcpcd.conf, one block per interface ==
|
||||
|
||||
src/share/man/man5/ifconfig.if.5, DESCRIPTION, 4th paragraph:
|
||||
|
||||
If the line is equal to "dhcp", dhcpcd(8) will be started for the
|
||||
interface. However, it is instead recommended that dhcpcd is set to true
|
||||
in rc.conf(5) and any per interface configuration or restriction is done
|
||||
in dhcpcd.conf(5).
|
||||
|
||||
So: rc.conf dhcpcd=YES, and per interface a block in /etc/dhcpcd.conf.
|
||||
sysinst (src/usr.sbin/sysinst/net.c:1154-1205) still writes a static
|
||||
address as "ADDR netmask MASK" into /etc/ifconfig.IF and defaultroute= into
|
||||
rc.conf, DHCP as dhcpcd=YES with dhcpcd_flags="-qM IF". McdeSys reads both
|
||||
(an inet line in ifconfig.IF means "Manually") and writes the recommended
|
||||
form; the inet lines of ifconfig.IF are taken out when it does, "up" and
|
||||
"media" stay.
|
||||
|
||||
src/external/bsd/dhcpcd/dist/src/dhcpcd.conf.5 (dhcpcd 10.5.2):
|
||||
|
||||
interface interface
|
||||
Subsequent options are only parsed for this interface.
|
||||
static value
|
||||
Configures a static value. If you set ip_address then dhcpcd will
|
||||
not attempt to obtain a lease and will just use the value for the
|
||||
address with an infinite lease time. [...] For IPv4, you should use
|
||||
the inform ipaddress option instead of setting a static address.
|
||||
interface eth0
|
||||
noipv6rs
|
||||
static ip_address=192.168.0.10/24
|
||||
static ip6_address=fd51:42f8:caae:d92e::ff/64
|
||||
static routers=192.168.0.1
|
||||
static domain_name_servers=192.168.0.1 fd51:42f8:caae:d92e::1
|
||||
inform [address[/cidr[/broadcast_address]]]
|
||||
Behaves like request as above, but sends a DHCP INFORM instead of
|
||||
DISCOVER/REQUEST. This does not get a lease as such, just notifies
|
||||
the DHCP server of the address in use.
|
||||
clientid string
|
||||
Send the clientid.
|
||||
noipv4 Don't attempt to configure an IPv4 address.
|
||||
noipv6 Don't solicit or accept IPv6 Router Advertisements and DHCPv6.
|
||||
|
||||
How the pane's choices map (the block between "# MCDE network IF begin" and
|
||||
"# MCDE network IF end"):
|
||||
Using DHCP (no block, or only clientid)
|
||||
Using DHCP with manual address inform ADDR/PREFIX
|
||||
Manually static ip_address=ADDR/PREFIX
|
||||
static routers=ROUTER
|
||||
Off noipv4
|
||||
IPv6 Automatically (nothing)
|
||||
IPv6 Manually static ip6_address=ADDR/PREFIX
|
||||
IPv6 Off noipv6
|
||||
DNS servers, search domains static domain_name_servers=A B ...
|
||||
static domain_search=D E ...
|
||||
dhcpcd hands DNS to resolvconf(8) (openresolv), which writes
|
||||
/etc/resolv.conf; the current servers are read from that file.
|
||||
Applied now by "/etc/rc.d/dhcpcd restart" (rc.subr(8)).
|
||||
|
||||
src/share/man/man5/rc.conf.5:
|
||||
defaultroute A string. Default IPv4 network route.
|
||||
dhcpcd Boolean value. Set true to configure some or all network
|
||||
interfaces using dhcpcd. [...] If you need to restrict
|
||||
dhcpcd to one or a number of interfaces, or need a separate
|
||||
configuration per interface, then this should be done in
|
||||
the configuration file - see dhcpcd.conf(5)
|
||||
|
||||
== Linux: NetworkManager, nmcli(1) 1.56.1 ==
|
||||
|
||||
man 5 nm-settings-nmcli (Debian 14 host):
|
||||
|
||||
ipv4.method "auto" - Enables automatic IPv4 address assignment from
|
||||
DHCP [...] "manual" - [...] you must set at least one IP
|
||||
address and subnet mask in the "ipv4.addresses" property.
|
||||
"disabled" - Disables the IPv4 protocol in this connection
|
||||
profile.
|
||||
ipv4.addresses A list of IPv4 addresses and their prefix length.
|
||||
ipv6.method "auto" [...] "manual" [...] "disabled" [...]
|
||||
|
||||
Using DHCP ipv4.method auto, ipv4.addresses ""
|
||||
Using DHCP with manual address ipv4.method auto, ipv4.addresses ADDR/P
|
||||
Manually ipv4.method manual, ipv4.addresses,
|
||||
ipv4.gateway
|
||||
Off ipv4.method disabled
|
||||
DNS ipv4.dns, ipv4.dns-search
|
||||
DHCP client ID ipv4.dhcp-client-id
|
||||
Read with "nmcli -t -g PROPS connection show NAME" (configured) and
|
||||
"nmcli -t -g IP4.ADDRESS,... device show IF" (current); written with
|
||||
"nmcli connection modify NAME ..." and applied with "nmcli connection up
|
||||
NAME". Measured on this host 2026-11-13: device enxde5285b18f9e,
|
||||
connection "Wired connection 1", ipv4.method auto, ipv4.dns 1.1.1.1,
|
||||
IP4.ADDRESS 172.20.10.3/28, IP4.GATEWAY 172.20.10.1.
|
||||
|
||||
== The look: the Network pane of the 10.4 generation ==
|
||||
|
||||
Konrad 2026-11-13: "nimm mac os x 10.4 network config as inspiration";
|
||||
https://devices.eduroam.ac.ke/mediawiki-1.25.1/index.php?title=Mac_OS_X_10.4_-_Tiger
|
||||
(screenshots of the pane, read 2026-11-13). What that pane has: "Show:"
|
||||
chooses Network Status or one port; a port has the tabs AirPort, TCP/IP,
|
||||
DNS, WINS, AppleTalk, 802.1X, Proxies, Ethernet; TCP/IP has "Configure
|
||||
IPv4:" (Using DHCP, Using DHCP with manual address, Manually, Off), IP
|
||||
Address, Subnet Mask, Router, DHCP Client ID, "Renew DHCP Lease",
|
||||
"Configure IPv6"; DNS has DNS Servers and Search Domains; the lock ("Click
|
||||
the lock to prevent further changes") and "Apply Now" at the bottom.
|
||||
MCDE takes Network Status, TCP/IP, DNS, Wi-Fi, Ethernet, the lock and
|
||||
Apply Now; WINS, AppleTalk, 802.1X and Proxies are not drawn yet.
|
||||
@@ -820,6 +820,7 @@ programs/dtinfo/tools/misc/treeres
|
||||
# programs/dtlogin
|
||||
programs/dtlogin/config/0015.sun.env
|
||||
programs/dtlogin/config/0060.dtsysenv
|
||||
programs/dtlogin/config/sys.sessionetc
|
||||
programs/dtlogin/config/Dtlogin
|
||||
programs/dtlogin/config/Xaccess
|
||||
programs/dtlogin/config/Xconfig
|
||||
|
||||
+35
-3
@@ -117,6 +117,25 @@ place of CDE; pkgsrc builds it on any platform from `pkgsrc/`.
|
||||
(null sink, own socket): the slider changes the volume it reaches.
|
||||
dtwm places and maximizes windows below the bar (`McdeExcludeBar` in
|
||||
`programs/dtwm/WmMultiHead.c`); a full-screen window covers it.
|
||||
The bar shows a program's menus only while one of its windows has the
|
||||
focus: dtwm publishes the focused client as `_NET_ACTIVE_WINDOW` (EWMH;
|
||||
`SetNetActiveWindow` in WmEwmh.c, called from SetKeyboardFocus and where
|
||||
the focus is dropped), and the bar compares it with the menus' owner --
|
||||
the window itself, a dialog of it (WM_TRANSIENT_FOR), or a window of the
|
||||
same program (WM_CLIENT_LEADER). A program without a global menu in
|
||||
front: the bar shows only the M menu (Konrad, 2026-11-13). The bar has
|
||||
colour set 5, the programs' background, not set 6 of a menu bar
|
||||
(`Dtbar*secondaryColorSetId: 5`).
|
||||
- The desktop's own programs -- mcdesoundd, dtlaunch, dtterm -dropdown,
|
||||
dtbar, the login items -- are started by dtsession, not by Xsession:
|
||||
`programs/dtlogin/config/sys.sessionetc.src` (installed as
|
||||
config/sys.sessionetc) sources the scripts of `config/sessionetc.d`, and
|
||||
dtsession runs it before the user's ~/.dt/sessions/sessionetc (StartEtc,
|
||||
SmRestore.c), after the session's resources and the colour server are
|
||||
there. Started from Xsession.d they came up before dtsession and took
|
||||
`*background` from the user's ~/.Xdefaults: a purple bar on 2026-11-13
|
||||
(the user's base16 theme), measured by restarting dtbar in the running
|
||||
session.
|
||||
- "Always on Top" (dtwm, `programs/dtwm/WmFunction.c`): `ClientData.mcdeAbove`
|
||||
per window, set by `f.mcde_above` (a toggle with a check mark in the
|
||||
window menu, WmMenu.c) or by `_NET_WM_STATE_ABOVE` (WmEwmh.c, also when a
|
||||
@@ -348,7 +367,20 @@ place of CDE; pkgsrc builds it on any platform from `pkgsrc/`.
|
||||
(sys.resources) the same way, for programs started afterwards; the
|
||||
families come from Xft. dtsession saves RESOURCE_MANAGER at logout
|
||||
(`SmSave.c`, OutputResource), so both persist.
|
||||
Network lists the Wi-Fi networks in reach (`wifi.c`,
|
||||
Network (`network.c`, docs/reference/netconfig.txt in the Makronix
|
||||
tree): "Show:" Network Status (every card, a light, a sentence,
|
||||
Configure...) or one card with the tabs TCP/IP (Configure IPv4: Using
|
||||
DHCP, Using DHCP with manual address, Manually, Off; address, mask,
|
||||
router, DHCP client ID, Renew DHCP Lease; Configure IPv6), DNS (servers,
|
||||
search domains; what resolv.conf has now below), Wi-Fi and Ethernet (ID,
|
||||
media, MTU); the lock and Apply Now as Accounts has them. McdeSys
|
||||
`mcde_sys_net_config`/`_configure`/`_renew`: NetBSD one block per
|
||||
interface in /etc/dhcpcd.conf ("# MCDE network IF begin/end"), as
|
||||
ifconfig.if(5) recommends, sysinst's static address in ifconfig.IF read
|
||||
and moved there, applied with dhcpcd -n IF; Linux the NetworkManager
|
||||
profile of the device (nmcli connection modify/up). Never apply on the
|
||||
development host or in the build VM over its ssh card.
|
||||
The Wi-Fi tab lists the networks in reach (`wifi.c`,
|
||||
mcde_sys_wifi_scan: NetBSD wpa_cli scan_results, else ifconfig -v IF
|
||||
list scan as root; Linux nmcli -t). "Join..." opens a terminal: su, then
|
||||
`dtsystemsettings -join-wifi IF [SSID as hex]`, which asks the network's
|
||||
@@ -369,7 +401,7 @@ place of CDE; pkgsrc builds it on any platform from `pkgsrc/`.
|
||||
(_DtSetSmState, SM_STATE_START|SM_STATE_CONFIRM) and "Save These Windows
|
||||
as Home Session" (_DT_SM_SAVE_TO_HOME), as dtstyle sends them; and the
|
||||
programs opened at login, ~/.dt/login-items, started by
|
||||
`programs/dtlogin/config/0095.loginitems` (Xsession.d, after 5 seconds,
|
||||
`programs/dtlogin/config/0095.loginitems` (sessionetc.d, after 5 seconds,
|
||||
each through sh in the background).
|
||||
Date & Time chooses the time zone (`timezone.c`): regions and places
|
||||
from mcde_sys_timezones (zone1970.tab); "Set Time Zone" runs
|
||||
@@ -407,7 +439,7 @@ place of CDE; pkgsrc builds it on any platform from `pkgsrc/`.
|
||||
down below the top bar and takes the keyboard; the key sends it up. The
|
||||
key is grabbed on the root window and taken in dtterm's own event dispatcher
|
||||
(`XtSetEventDispatcher`): a root window registered with a widget did not
|
||||
bring it. Started by `Xsession.d/0085.dtdropdown`. Test with an XTest
|
||||
bring it. Started by `sessionetc.d/0085.dtdropdown`. Test with an XTest
|
||||
event on the key's own keycode: `xdotool key F12` maps F12 to a spare
|
||||
keycode, which the grab never sees (measured).
|
||||
- `programs/dtterm/Profiles.c` -- terminal profiles (font, colours, command)
|
||||
|
||||
@@ -89,8 +89,59 @@ typedef struct {
|
||||
|
||||
/* the network interfaces; returns count */
|
||||
int mcde_sys_interfaces(McdeSysInterface *ifs, size_t max);
|
||||
/* address by DHCP (the default), now and at every boot */
|
||||
int mcde_sys_net_dhcp(const char *ifname);
|
||||
|
||||
/* how an interface gets its IPv4 and IPv6 addresses (System Settings >
|
||||
* Network, TCP/IP); docs/reference/netconfig.txt in the Makronix tree */
|
||||
typedef enum {
|
||||
MCDE_IPV4_DHCP, /* Using DHCP */
|
||||
MCDE_IPV4_DHCP_MANUAL, /* Using DHCP with manual address */
|
||||
MCDE_IPV4_MANUAL, /* Manually */
|
||||
MCDE_IPV4_OFF
|
||||
} McdeSysIpv4;
|
||||
|
||||
typedef enum {
|
||||
MCDE_IPV6_AUTO, /* Automatically (router advertisements) */
|
||||
MCDE_IPV6_MANUAL,
|
||||
MCDE_IPV6_OFF
|
||||
} McdeSysIpv6;
|
||||
|
||||
#define MCDE_NET_DNS_MAX 4
|
||||
|
||||
typedef struct {
|
||||
/* configured: what the interface gets at every start */
|
||||
McdeSysIpv4 ipv4;
|
||||
char address[48]; /* IPv4, dotted */
|
||||
char netmask[48]; /* dotted: 255.255.255.0 */
|
||||
char router[48];
|
||||
char clientid[64]; /* the DHCP client ID, or "" */
|
||||
McdeSysIpv6 ipv6;
|
||||
char address6[64];
|
||||
int prefix6; /* 1..128 */
|
||||
char dns[MCDE_NET_DNS_MAX][48]; /* the DNS servers */
|
||||
int ndns;
|
||||
char search[MCDE_NET_DNS_MAX][96]; /* search domains */
|
||||
int nsearch;
|
||||
/* now, read only: what the interface has at this moment */
|
||||
char cur_address[48];
|
||||
char cur_netmask[48];
|
||||
char cur_router[48];
|
||||
char cur_address6[64];
|
||||
int cur_prefix6;
|
||||
char cur_dns[MCDE_NET_DNS_MAX][48];
|
||||
int ncur_dns;
|
||||
char mac[24]; /* the Ethernet ID, aa:bb:cc:dd:ee:ff */
|
||||
int mtu;
|
||||
char media[64]; /* "1000baseT full-duplex", or "" */
|
||||
} McdeSysNetConfig;
|
||||
|
||||
/* the settings of IFNAME, configured and current */
|
||||
int mcde_sys_net_config(const char *ifname, McdeSysNetConfig *config);
|
||||
/* configure IFNAME (the "configured" part of CONFIG), now and at every
|
||||
* start; the administrator only */
|
||||
int mcde_sys_net_configure(const char *ifname,
|
||||
const McdeSysNetConfig *config);
|
||||
/* ask the DHCP server again (Renew DHCP Lease) */
|
||||
int mcde_sys_net_renew(const char *ifname);
|
||||
/* the Wi-Fi networks in reach; returns count */
|
||||
int mcde_sys_wifi_scan(const char *ifname, McdeSysWifi *nets, size_t max);
|
||||
/* join a Wi-Fi network, now and at every boot; passphrase NULL if open */
|
||||
|
||||
@@ -9,6 +9,11 @@ libDtTerm_la_SOURCES =
|
||||
libDtTerm_la_LIBADD = Term/libTerm.la TermPrim/libTermPrim.la \
|
||||
TermView/libTermView.la
|
||||
|
||||
# MCDE: the bell plays the desktop's TerminalBell (TermPrimRender.c,
|
||||
# McdeSoundEvent); every program that links libDtTerm needs it, not only
|
||||
# dtterm (dtcodegen did not link)
|
||||
libDtTerm_la_LIBADD += $(top_builddir)/lib/McdeSound/libMcdeSound.la
|
||||
|
||||
if OPENBSD
|
||||
libDtTerm_la_LIBADD += -lutil
|
||||
endif
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <Mcde/McdeSys.h>
|
||||
|
||||
@@ -446,6 +449,282 @@ mcde_sys_wifi_join(const char *ifname, const char *ssid,
|
||||
return mcde_sys_run(argv);
|
||||
}
|
||||
|
||||
/* ---- the settings of an interface: NetworkManager keeps them in the
|
||||
* connection profile of the device ("nmcli -t -g ... connection show"),
|
||||
* what the device has now comes from the kernel (/proc/net/route,
|
||||
* /sys/class/net). docs/reference/netconfig.txt in the Makronix tree. */
|
||||
|
||||
/* "\:" and "\\" of nmcli's terse output back to ':' and '\' */
|
||||
static void
|
||||
NmUnescape(char *s)
|
||||
{
|
||||
char *r = s, *w = s;
|
||||
|
||||
while (*r != '\0') {
|
||||
if (*r == '\\' && r[1] != '\0')
|
||||
r++;
|
||||
*w++ = *r++;
|
||||
}
|
||||
*w = '\0';
|
||||
}
|
||||
|
||||
/* the next line of BUF (cut there); *P moves past it, NULL at the end */
|
||||
static char *
|
||||
NextLine(char **p)
|
||||
{
|
||||
char *start = *p, *nl;
|
||||
|
||||
if (start == NULL)
|
||||
return NULL;
|
||||
if ((nl = strchr(start, '\n')) != NULL) {
|
||||
*nl = '\0';
|
||||
*p = nl + 1;
|
||||
} else
|
||||
*p = NULL;
|
||||
return start;
|
||||
}
|
||||
|
||||
/* the connection profile NetworkManager uses for IFNAME into NAME */
|
||||
static int
|
||||
NmConnection(const char *ifname, char *name, size_t len)
|
||||
{
|
||||
const char *nm = mcde_sys_which(nmcliPaths);
|
||||
char out[512], *p = out, *line;
|
||||
char *argv[] = { NULL, "-t", "-g", "GENERAL.CONNECTION", "device",
|
||||
"show", (char *) ifname, NULL };
|
||||
|
||||
if (nm == NULL)
|
||||
return mcde_sys_fail(MCDE_SYS_ENOTSUP, "NetworkManager (nmcli) "
|
||||
"is not installed: the settings cannot be changed here.");
|
||||
argv[0] = (char *) nm;
|
||||
if (mcde_sys_capture(argv, out, sizeof out) != MCDE_SYS_OK ||
|
||||
(line = NextLine(&p)) == NULL || line[0] == '\0')
|
||||
return mcde_sys_fail(MCDE_SYS_ENOENT, "NetworkManager has no "
|
||||
"settings for %s.", ifname);
|
||||
NmUnescape(line);
|
||||
snprintf(name, len, "%s", line);
|
||||
return MCDE_SYS_OK;
|
||||
}
|
||||
|
||||
/* the items of a list as nmcli prints it (',' between them) into DST */
|
||||
static int
|
||||
Items(char *list, char (*dst)[48], int max)
|
||||
{
|
||||
char *item, *last = NULL;
|
||||
int n = 0;
|
||||
|
||||
for (item = strtok_r(list, ",", &last); item != NULL && n < max;
|
||||
item = strtok_r(NULL, ",", &last)) {
|
||||
while (*item == ' ')
|
||||
item++;
|
||||
if (*item != '\0')
|
||||
snprintf(dst[n++], sizeof dst[0], "%s", item);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
static void
|
||||
SysfsLine(const char *ifname, const char *what, char *buf, size_t len)
|
||||
{
|
||||
char path[256];
|
||||
|
||||
snprintf(path, sizeof path, "/sys/class/net/%s/%s", ifname, what);
|
||||
buf[0] = '\0';
|
||||
(void) mcde_sys_file_value(path, "", buf, len);
|
||||
}
|
||||
|
||||
int
|
||||
mcde_sys_net_config_backend(const char *ifname, McdeSysNetConfig *c)
|
||||
{
|
||||
const char *nm = mcde_sys_which(nmcliPaths);
|
||||
char conn[256], out[4096], *p = out, *f[8], speed[32], duplex[32];
|
||||
char line[256];
|
||||
FILE *fp;
|
||||
int i, r;
|
||||
char *argv[] = { NULL, "-t", "-g", "ipv4.method,ipv4.addresses,"
|
||||
"ipv4.gateway,ipv4.dns,ipv4.dns-search,ipv4.dhcp-client-id,"
|
||||
"ipv6.method,ipv6.addresses", "connection", "show", conn, NULL };
|
||||
|
||||
SysfsLine(ifname, "address", c->mac, sizeof c->mac);
|
||||
SysfsLine(ifname, "speed", speed, sizeof speed);
|
||||
SysfsLine(ifname, "duplex", duplex, sizeof duplex);
|
||||
if (atoi(speed) > 0)
|
||||
snprintf(c->media, sizeof c->media, "%d Mbit/s%s%s",
|
||||
atoi(speed), duplex[0] != '\0' ? ", " : "", duplex);
|
||||
/* /proc/net/route: Iface Destination Gateway ..., hexadecimal in
|
||||
* the kernel's byte order; the default route has destination 0 */
|
||||
if ((fp = fopen("/proc/net/route", "r")) != NULL) {
|
||||
while (fgets(line, sizeof line, fp) != NULL) {
|
||||
char name[64];
|
||||
unsigned int dst, gw;
|
||||
struct in_addr a;
|
||||
|
||||
if (sscanf(line, "%63s %x %x", name, &dst, &gw) == 3 &&
|
||||
strcmp(name, ifname) == 0 && dst == 0 && gw != 0) {
|
||||
a.s_addr = gw;
|
||||
inet_ntop(AF_INET, &a, c->cur_router,
|
||||
sizeof c->cur_router);
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
if ((r = NmConnection(ifname, conn, sizeof conn)) != MCDE_SYS_OK)
|
||||
return r;
|
||||
argv[0] = (char *) nm;
|
||||
if (mcde_sys_capture(argv, out, sizeof out) != MCDE_SYS_OK)
|
||||
return mcde_sys_fail(MCDE_SYS_EFAIL, "nmcli does not tell the "
|
||||
"settings of \"%s\".", conn);
|
||||
for (i = 0; i < 8; i++) {
|
||||
if ((f[i] = NextLine(&p)) == NULL)
|
||||
f[i] = "";
|
||||
NmUnescape(f[i]);
|
||||
}
|
||||
/* 0 method, 1 addresses, 2 gateway, 3 dns, 4 search, 5 client id,
|
||||
* 6 ipv6 method, 7 ipv6 addresses */
|
||||
if (strcmp(f[0], "manual") == 0)
|
||||
c->ipv4 = MCDE_IPV4_MANUAL;
|
||||
else if (strcmp(f[0], "disabled") == 0)
|
||||
c->ipv4 = MCDE_IPV4_OFF;
|
||||
else
|
||||
c->ipv4 = f[1][0] != '\0' ? MCDE_IPV4_DHCP_MANUAL :
|
||||
MCDE_IPV4_DHCP;
|
||||
if (f[1][0] != '\0') {
|
||||
char *slash, *comma;
|
||||
|
||||
if ((comma = strchr(f[1], ',')) != NULL)
|
||||
*comma = '\0';
|
||||
if ((slash = strchr(f[1], '/')) != NULL) {
|
||||
*slash = '\0';
|
||||
mcde_sys_net_mask(atoi(slash + 1), c->netmask,
|
||||
sizeof c->netmask);
|
||||
}
|
||||
snprintf(c->address, sizeof c->address, "%s", f[1]);
|
||||
}
|
||||
snprintf(c->router, sizeof c->router, "%s", f[2]);
|
||||
c->ndns = Items(f[3], c->dns, MCDE_NET_DNS_MAX);
|
||||
{
|
||||
char *item, *last = NULL;
|
||||
|
||||
for (item = strtok_r(f[4], ",", &last); item != NULL &&
|
||||
c->nsearch < MCDE_NET_DNS_MAX;
|
||||
item = strtok_r(NULL, ",", &last))
|
||||
snprintf(c->search[c->nsearch++], sizeof c->search[0],
|
||||
"%s", item);
|
||||
}
|
||||
snprintf(c->clientid, sizeof c->clientid, "%s", f[5]);
|
||||
c->ipv6 = strcmp(f[6], "manual") == 0 ? MCDE_IPV6_MANUAL :
|
||||
strcmp(f[6], "disabled") == 0 ? MCDE_IPV6_OFF : MCDE_IPV6_AUTO;
|
||||
if (f[7][0] != '\0') {
|
||||
char *slash, *comma;
|
||||
|
||||
if ((comma = strchr(f[7], ',')) != NULL)
|
||||
*comma = '\0';
|
||||
if ((slash = strchr(f[7], '/')) != NULL) {
|
||||
*slash = '\0';
|
||||
c->prefix6 = atoi(slash + 1);
|
||||
}
|
||||
snprintf(c->address6, sizeof c->address6, "%s", f[7]);
|
||||
}
|
||||
return MCDE_SYS_OK;
|
||||
}
|
||||
|
||||
/* N strings WIDTH bytes apart from LIST, joined by ',' into BUF */
|
||||
static void
|
||||
Join(const char *list, int n, size_t width, char *buf, size_t len)
|
||||
{
|
||||
size_t at = 0;
|
||||
int i;
|
||||
|
||||
buf[0] = '\0';
|
||||
for (i = 0; i < n && at < len; i++)
|
||||
at += (size_t) snprintf(buf + at, len - at, "%s%s",
|
||||
i > 0 ? "," : "", list + (size_t) i * width);
|
||||
}
|
||||
|
||||
int
|
||||
mcde_sys_net_configure_backend(const char *ifname, const McdeSysNetConfig *c)
|
||||
{
|
||||
const char *nm = mcde_sys_which(nmcliPaths);
|
||||
char conn[256], addr4[80] = "", addr6[96] = "", dns[256], search[512];
|
||||
const char *m4, *m6;
|
||||
char *argv[24];
|
||||
int n = 0, r;
|
||||
|
||||
if ((r = NmConnection(ifname, conn, sizeof conn)) != MCDE_SYS_OK)
|
||||
return r;
|
||||
switch (c->ipv4) {
|
||||
case MCDE_IPV4_MANUAL:
|
||||
m4 = "manual";
|
||||
break;
|
||||
case MCDE_IPV4_OFF:
|
||||
m4 = "disabled";
|
||||
break;
|
||||
default:
|
||||
m4 = "auto"; /* with an address: DHCP with manual address */
|
||||
break;
|
||||
}
|
||||
if (c->ipv4 == MCDE_IPV4_MANUAL || c->ipv4 == MCDE_IPV4_DHCP_MANUAL)
|
||||
snprintf(addr4, sizeof addr4, "%s/%d", c->address,
|
||||
mcde_sys_net_prefix(c->netmask));
|
||||
m6 = c->ipv6 == MCDE_IPV6_MANUAL ? "manual" :
|
||||
c->ipv6 == MCDE_IPV6_OFF ? "disabled" : "auto";
|
||||
if (c->ipv6 == MCDE_IPV6_MANUAL)
|
||||
snprintf(addr6, sizeof addr6, "%s/%d", c->address6, c->prefix6);
|
||||
Join(c->dns[0], c->ndns, sizeof c->dns[0], dns, sizeof dns);
|
||||
Join(c->search[0], c->nsearch, sizeof c->search[0], search,
|
||||
sizeof search);
|
||||
|
||||
argv[n++] = (char *) nm;
|
||||
argv[n++] = "connection";
|
||||
argv[n++] = "modify";
|
||||
argv[n++] = conn;
|
||||
argv[n++] = "ipv4.method";
|
||||
argv[n++] = (char *) m4;
|
||||
argv[n++] = "ipv4.addresses";
|
||||
argv[n++] = addr4;
|
||||
argv[n++] = "ipv4.gateway";
|
||||
argv[n++] = c->ipv4 == MCDE_IPV4_MANUAL ? (char *) c->router : "";
|
||||
argv[n++] = "ipv4.dns";
|
||||
argv[n++] = dns;
|
||||
argv[n++] = "ipv4.dns-search";
|
||||
argv[n++] = search;
|
||||
argv[n++] = "ipv4.dhcp-client-id";
|
||||
argv[n++] = (char *) c->clientid;
|
||||
argv[n++] = "ipv6.method";
|
||||
argv[n++] = (char *) m6;
|
||||
argv[n++] = "ipv6.addresses";
|
||||
argv[n++] = addr6;
|
||||
argv[n] = NULL;
|
||||
if (mcde_sys_run(argv) != MCDE_SYS_OK)
|
||||
return mcde_sys_fail(MCDE_SYS_EFAIL, "NetworkManager did not "
|
||||
"take the settings.");
|
||||
return mcde_sys_net_renew(ifname);
|
||||
}
|
||||
|
||||
/* the profile activated again: NetworkManager asks DHCP anew and applies
|
||||
* what was changed */
|
||||
int
|
||||
mcde_sys_net_renew(const char *ifname)
|
||||
{
|
||||
const char *nm = mcde_sys_which(nmcliPaths);
|
||||
char conn[256];
|
||||
char *argv[] = { NULL, "connection", "up", conn, NULL };
|
||||
int r;
|
||||
|
||||
if (!mcde_sys_net_ifname_ok(ifname))
|
||||
return mcde_sys_fail(MCDE_SYS_EINVAL, "There is no network "
|
||||
"card of that name.");
|
||||
if ((r = NmConnection(ifname, conn, sizeof conn)) != MCDE_SYS_OK)
|
||||
return r;
|
||||
argv[0] = (char *) nm;
|
||||
if (mcde_sys_run(argv) != MCDE_SYS_OK)
|
||||
return mcde_sys_fail(MCDE_SYS_EFAIL, "NetworkManager could not "
|
||||
"bring \"%s\" up again.", conn);
|
||||
return MCDE_SYS_OK;
|
||||
}
|
||||
|
||||
/* ---- users: the group sudo administers (Debian; wheel where there is no
|
||||
* sudo group); chpasswd(8) takes the password on its standard input,
|
||||
* gpasswd(1) adds to and removes from a group */
|
||||
|
||||
@@ -14,10 +14,15 @@
|
||||
#define _DEFAULT_SOURCE /* and on Linux */
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <net/if.h>
|
||||
#include <netdb.h>
|
||||
@@ -66,7 +71,11 @@ mcde_sys_interfaces(McdeSysInterface *ifs, size_t max)
|
||||
fam = a->ifa_addr->sa_family;
|
||||
/* an IPv4 address first; an IPv6 one only if there is none,
|
||||
* and not the link-local one every interface has */
|
||||
if (fam == AF_INET || (fam == AF_INET6 && it->address[0] == '\0')) {
|
||||
/* the first IPv4 address is the primary one (ip(8) lists it
|
||||
* first; later ones are "secondary") */
|
||||
if ((fam == AF_INET && (it->address[0] == '\0' ||
|
||||
strchr(it->address, ':') != NULL)) ||
|
||||
(fam == AF_INET6 && it->address[0] == '\0')) {
|
||||
char host[NI_MAXHOST];
|
||||
|
||||
if (fam == AF_INET6 && IN6_IS_ADDR_LINKLOCAL(
|
||||
@@ -85,3 +94,218 @@ mcde_sys_interfaces(McdeSysInterface *ifs, size_t max)
|
||||
freeifaddrs(all);
|
||||
return (int) n;
|
||||
}
|
||||
|
||||
/* ---- the settings of one interface (System Settings > Network) ---------
|
||||
* What every system has the same way is here: the addresses the interface
|
||||
* has now (getifaddrs), its MTU (SIOCGIFMTU, ioctl(2) on a socket, as
|
||||
* ifconfig(8) asks it on both), the DNS servers in use (resolv.conf(5),
|
||||
* written by resolvconf on NetBSD and by NetworkManager or systemd on
|
||||
* Linux), and the checks of what the user typed. Where the configuration
|
||||
* lives -- dhcpcd.conf(5) on NetBSD, NetworkManager on Linux -- the
|
||||
* backend knows (docs/reference/netconfig.txt in the Makronix tree). */
|
||||
|
||||
int
|
||||
mcde_sys_net_ifname_ok(const char *name)
|
||||
{
|
||||
const char *p;
|
||||
|
||||
if (name == NULL || name[0] == '\0' || name[0] == '-' ||
|
||||
strlen(name) >= IFNAMSIZ)
|
||||
return 0;
|
||||
for (p = name; *p != '\0'; p++)
|
||||
if (!isalnum((unsigned char) *p) && *p != '_' && *p != '-' &&
|
||||
*p != '.')
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* the prefix length of a dotted netmask, -1 when it is none */
|
||||
int
|
||||
mcde_sys_net_prefix(const char *netmask)
|
||||
{
|
||||
struct in_addr a;
|
||||
unsigned long m;
|
||||
int n = 0;
|
||||
|
||||
if (inet_pton(AF_INET, netmask, &a) != 1)
|
||||
return -1;
|
||||
m = ntohl(a.s_addr);
|
||||
while (m & 0x80000000UL) {
|
||||
n++;
|
||||
m = (m << 1) & 0xffffffffUL;
|
||||
}
|
||||
return m == 0 ? n : -1;
|
||||
}
|
||||
|
||||
void
|
||||
mcde_sys_net_mask(int prefix, char *buf, size_t len)
|
||||
{
|
||||
unsigned long m = prefix <= 0 ? 0 :
|
||||
(0xffffffffUL << (32 - (prefix > 32 ? 32 : prefix))) & 0xffffffffUL;
|
||||
|
||||
snprintf(buf, len, "%lu.%lu.%lu.%lu", (m >> 24) & 255, (m >> 16) & 255,
|
||||
(m >> 8) & 255, m & 255);
|
||||
}
|
||||
|
||||
static int
|
||||
Ipv4(const char *s)
|
||||
{
|
||||
struct in_addr a;
|
||||
|
||||
return s != NULL && inet_pton(AF_INET, s, &a) == 1;
|
||||
}
|
||||
|
||||
static int
|
||||
Ipv6(const char *s)
|
||||
{
|
||||
struct in6_addr a;
|
||||
|
||||
return s != NULL && inet_pton(AF_INET6, s, &a) == 1;
|
||||
}
|
||||
|
||||
/* a domain name: letters, digits, '-' and '.', not beginning with '-' */
|
||||
static int
|
||||
Domain(const char *s)
|
||||
{
|
||||
const char *p;
|
||||
|
||||
if (s[0] == '\0' || s[0] == '-' || s[0] == '.' || strlen(s) > 95)
|
||||
return 0;
|
||||
for (p = s; *p != '\0'; p++)
|
||||
if (!isalnum((unsigned char) *p) && *p != '-' && *p != '.')
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
Current(const char *ifname, McdeSysNetConfig *c)
|
||||
{
|
||||
struct ifaddrs *all, *a;
|
||||
struct ifreq ifr;
|
||||
char line[256];
|
||||
FILE *fp;
|
||||
int s;
|
||||
|
||||
if (getifaddrs(&all) == 0) {
|
||||
for (a = all; a != NULL; a = a->ifa_next) {
|
||||
if (a->ifa_addr == NULL ||
|
||||
strcmp(a->ifa_name, ifname) != 0)
|
||||
continue;
|
||||
if (a->ifa_addr->sa_family == AF_INET &&
|
||||
c->cur_address[0] == '\0') {
|
||||
inet_ntop(AF_INET, &((struct sockaddr_in *)
|
||||
a->ifa_addr)->sin_addr, c->cur_address,
|
||||
sizeof c->cur_address);
|
||||
if (a->ifa_netmask != NULL)
|
||||
inet_ntop(AF_INET, &((struct sockaddr_in *)
|
||||
a->ifa_netmask)->sin_addr,
|
||||
c->cur_netmask,
|
||||
sizeof c->cur_netmask);
|
||||
} else if (a->ifa_addr->sa_family == AF_INET6 &&
|
||||
c->cur_address6[0] == '\0') {
|
||||
struct in6_addr *in6 = &((struct sockaddr_in6 *)
|
||||
a->ifa_addr)->sin6_addr;
|
||||
int i, bits = 0;
|
||||
|
||||
if (IN6_IS_ADDR_LINKLOCAL(in6))
|
||||
continue;
|
||||
inet_ntop(AF_INET6, in6, c->cur_address6,
|
||||
sizeof c->cur_address6);
|
||||
if (a->ifa_netmask != NULL) {
|
||||
unsigned char *m = ((struct sockaddr_in6 *)
|
||||
a->ifa_netmask)->sin6_addr.s6_addr;
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
unsigned char b = m[i];
|
||||
|
||||
while (b & 0x80) {
|
||||
bits++;
|
||||
b = (unsigned char) (b << 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
c->cur_prefix6 = bits;
|
||||
}
|
||||
}
|
||||
freeifaddrs(all);
|
||||
}
|
||||
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) >= 0) {
|
||||
memset(&ifr, 0, sizeof ifr);
|
||||
snprintf(ifr.ifr_name, sizeof ifr.ifr_name, "%s", ifname);
|
||||
if (ioctl(s, SIOCGIFMTU, &ifr) == 0)
|
||||
c->mtu = ifr.ifr_mtu;
|
||||
close(s);
|
||||
}
|
||||
if ((fp = fopen("/etc/resolv.conf", "r")) != NULL) {
|
||||
while (fgets(line, sizeof line, fp) != NULL &&
|
||||
c->ncur_dns < MCDE_NET_DNS_MAX) {
|
||||
char *last = NULL, *k = strtok_r(line, " \t\r\n", &last),
|
||||
*v = strtok_r(NULL, " \t\r\n", &last);
|
||||
|
||||
if (k != NULL && v != NULL &&
|
||||
strcmp(k, "nameserver") == 0)
|
||||
snprintf(c->cur_dns[c->ncur_dns++],
|
||||
sizeof c->cur_dns[0], "%s", v);
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
mcde_sys_net_config(const char *ifname, McdeSysNetConfig *c)
|
||||
{
|
||||
if (!mcde_sys_net_ifname_ok(ifname))
|
||||
return mcde_sys_fail(MCDE_SYS_EINVAL, "There is no network "
|
||||
"card of that name.");
|
||||
memset(c, 0, sizeof *c);
|
||||
c->prefix6 = 64;
|
||||
Current(ifname, c);
|
||||
return mcde_sys_net_config_backend(ifname, c);
|
||||
}
|
||||
|
||||
int
|
||||
mcde_sys_net_configure(const char *ifname, const McdeSysNetConfig *c)
|
||||
{
|
||||
const char *p;
|
||||
int i;
|
||||
|
||||
if (!mcde_sys_net_ifname_ok(ifname))
|
||||
return mcde_sys_fail(MCDE_SYS_EINVAL, "There is no network "
|
||||
"card of that name.");
|
||||
if (geteuid() != 0)
|
||||
return mcde_sys_fail(MCDE_SYS_EPERM, "Only the administrator "
|
||||
"can change the network settings: click the lock first.");
|
||||
if (c->ipv4 == MCDE_IPV4_MANUAL || c->ipv4 == MCDE_IPV4_DHCP_MANUAL) {
|
||||
if (!Ipv4(c->address))
|
||||
return mcde_sys_fail(MCDE_SYS_EINVAL, "\"%s\" is no "
|
||||
"IPv4 address.", c->address);
|
||||
if (mcde_sys_net_prefix(c->netmask) < 1)
|
||||
return mcde_sys_fail(MCDE_SYS_EINVAL, "\"%s\" is no "
|
||||
"subnet mask (255.255.255.0, for example).",
|
||||
c->netmask);
|
||||
}
|
||||
if (c->ipv4 == MCDE_IPV4_MANUAL && c->router[0] != '\0' &&
|
||||
!Ipv4(c->router))
|
||||
return mcde_sys_fail(MCDE_SYS_EINVAL, "\"%s\" is no router "
|
||||
"address.", c->router);
|
||||
if (c->ipv6 == MCDE_IPV6_MANUAL && (!Ipv6(c->address6) ||
|
||||
c->prefix6 < 1 || c->prefix6 > 128))
|
||||
return mcde_sys_fail(MCDE_SYS_EINVAL, "\"%s/%d\" is no IPv6 "
|
||||
"address with its prefix length.", c->address6,
|
||||
c->prefix6);
|
||||
for (i = 0; i < c->ndns; i++)
|
||||
if (!Ipv4(c->dns[i]) && !Ipv6(c->dns[i]))
|
||||
return mcde_sys_fail(MCDE_SYS_EINVAL, "\"%s\" is no "
|
||||
"DNS server address.", c->dns[i]);
|
||||
for (i = 0; i < c->nsearch; i++)
|
||||
if (!Domain(c->search[i]))
|
||||
return mcde_sys_fail(MCDE_SYS_EINVAL, "\"%s\" is no "
|
||||
"domain name.", c->search[i]);
|
||||
for (p = c->clientid; *p != '\0'; p++)
|
||||
if (!isgraph((unsigned char) *p) || *p == '"' || *p == '\\' ||
|
||||
*p == '\'')
|
||||
return mcde_sys_fail(MCDE_SYS_EINVAL, "The DHCP client "
|
||||
"ID may hold letters, digits and signs, no blanks "
|
||||
"or quotes.");
|
||||
return mcde_sys_net_configure_backend(ifname, c);
|
||||
}
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <sys/utsname.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
@@ -31,6 +32,8 @@
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/envsys.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <net80211/ieee80211_ioctl.h>
|
||||
#include <prop/proplib.h>
|
||||
#include <sys/select.h>
|
||||
@@ -568,6 +571,435 @@ mcde_sys_wifi_join(const char *ifname, const char *ssid,
|
||||
return MCDE_SYS_OK;
|
||||
}
|
||||
|
||||
/* ---- the settings of an interface: one block per interface in
|
||||
* dhcpcd.conf(5), dhcpcd=YES in rc.conf -- what ifconfig.if(5) recommends
|
||||
* ("it is instead recommended that dhcpcd is set to true in rc.conf(5) and
|
||||
* any per interface configuration or restriction is done in
|
||||
* dhcpcd.conf(5)"). A static address sysinst wrote into /etc/ifconfig.IF
|
||||
* (net.c:1168) is read as "Manually" and moved into the block when the
|
||||
* settings are applied. docs/reference/netconfig.txt. */
|
||||
#define DHCPCD_CONF "/etc/dhcpcd.conf"
|
||||
static char dhcpcdp[] = "/sbin/dhcpcd";
|
||||
static char routep[] = "/sbin/route";
|
||||
static char rcdhcpcd[] = "/etc/rc.d/dhcpcd";
|
||||
|
||||
/* VAR=VALUE of rc.conf (the last one wins, as sh reads it), unquoted */
|
||||
static int
|
||||
RcConfGet(const char *var, char *buf, size_t len)
|
||||
{
|
||||
char line[1024];
|
||||
size_t vlen = strlen(var);
|
||||
FILE *fp = fopen(RC_CONF, "r");
|
||||
int found = 0;
|
||||
|
||||
buf[0] = '\0';
|
||||
if (fp == NULL)
|
||||
return 0;
|
||||
while (fgets(line, sizeof line, fp) != NULL) {
|
||||
char *v, *e;
|
||||
|
||||
if (strncmp(line, var, vlen) != 0 || line[vlen] != '=')
|
||||
continue;
|
||||
v = line + vlen + 1;
|
||||
v[strcspn(v, "#\n")] = '\0';
|
||||
while (*v == '"' || *v == '\'')
|
||||
v++;
|
||||
e = v + strlen(v);
|
||||
while (e > v && (e[-1] == '"' || e[-1] == '\'' || e[-1] == ' '))
|
||||
*--e = '\0';
|
||||
snprintf(buf, len, "%s", v);
|
||||
found = 1;
|
||||
}
|
||||
fclose(fp);
|
||||
return found;
|
||||
}
|
||||
|
||||
static int
|
||||
Yes(const char *v)
|
||||
{
|
||||
return strcasecmp(v, "yes") == 0 || strcasecmp(v, "true") == 0 ||
|
||||
strcasecmp(v, "on") == 0 || strcmp(v, "1") == 0;
|
||||
}
|
||||
|
||||
/* "ADDR/PREFIX" into ADDR and a dotted netmask (IPv4) */
|
||||
static void
|
||||
SplitCidr(const char *v, char *addr, size_t alen, char *mask, size_t mlen)
|
||||
{
|
||||
const char *slash = strchr(v, '/');
|
||||
|
||||
snprintf(addr, alen, "%.*s", slash != NULL ? (int) (slash - v) :
|
||||
(int) strlen(v), v);
|
||||
if (slash != NULL)
|
||||
mcde_sys_net_mask(atoi(slash + 1), mask, mlen);
|
||||
}
|
||||
|
||||
/* the words of V (blanks between them) into DST */
|
||||
static int
|
||||
Words(char *v, char *dst, size_t width, int max)
|
||||
{
|
||||
char *w, *last = NULL;
|
||||
int n = 0;
|
||||
|
||||
for (w = strtok_r(v, " \t", &last); w != NULL && n < max;
|
||||
w = strtok_r(NULL, " \t", &last))
|
||||
snprintf(dst + (size_t) n++ * width, width, "%s", w);
|
||||
return n;
|
||||
}
|
||||
|
||||
/* is LINE of an ifconfig.IF an IPv4 address: "inet ADDR ..." or sysinst's
|
||||
* "ADDR netmask MASK" */
|
||||
static int
|
||||
StaticLine(const char *line, char *addr, size_t alen, char *mask,
|
||||
size_t mlen)
|
||||
{
|
||||
char a[64] = "", m[64] = "", w[16] = "";
|
||||
|
||||
if (sscanf(line, "inet %63s netmask %63s", a, m) == 2 ||
|
||||
(sscanf(line, "%63s %15s %63s", a, w, m) == 3 &&
|
||||
strcmp(w, "netmask") == 0 && strchr(a, '.') != NULL)) {
|
||||
snprintf(addr, alen, "%s", a);
|
||||
snprintf(mask, mlen, "%s", m);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
mcde_sys_net_config_backend(const char *ifname, McdeSysNetConfig *c)
|
||||
{
|
||||
char path[256], line[512], out[4096], v[256], *l, *last = NULL;
|
||||
struct ifaddrs *all, *a;
|
||||
FILE *fp;
|
||||
int in = 0, have4 = 0, dhcpLine = 0;
|
||||
char *argv[5];
|
||||
|
||||
/* the Ethernet ID: the link-level address getifaddrs gives */
|
||||
if (getifaddrs(&all) == 0) {
|
||||
for (a = all; a != NULL; a = a->ifa_next) {
|
||||
struct sockaddr_dl *dl;
|
||||
unsigned char *m;
|
||||
|
||||
if (a->ifa_addr == NULL || a->ifa_addr->sa_family !=
|
||||
AF_LINK || strcmp(a->ifa_name, ifname) != 0)
|
||||
continue;
|
||||
dl = (struct sockaddr_dl *) a->ifa_addr;
|
||||
if (dl->sdl_alen != 6)
|
||||
continue;
|
||||
m = (unsigned char *) LLADDR(dl);
|
||||
snprintf(c->mac, sizeof c->mac,
|
||||
"%02x:%02x:%02x:%02x:%02x:%02x", m[0], m[1], m[2],
|
||||
m[3], m[4], m[5]);
|
||||
}
|
||||
freeifaddrs(all);
|
||||
}
|
||||
/* the media, as ifconfig(8) prints it */
|
||||
argv[0] = ifconfigp;
|
||||
argv[1] = (char *) ifname;
|
||||
argv[2] = NULL;
|
||||
if (mcde_sys_capture(argv, out, sizeof out) == MCDE_SYS_OK)
|
||||
for (l = strtok_r(out, "\n", &last); l != NULL;
|
||||
l = strtok_r(NULL, "\n", &last))
|
||||
if ((l = strstr(l, "media: ")) != NULL) {
|
||||
snprintf(c->media, sizeof c->media, "%s", l + 7);
|
||||
break;
|
||||
}
|
||||
/* the router now: route(8) get default, if it goes out here */
|
||||
argv[0] = routep;
|
||||
argv[1] = "-n";
|
||||
argv[2] = "get";
|
||||
argv[3] = "default";
|
||||
argv[4] = NULL;
|
||||
if (mcde_sys_capture(argv, out, sizeof out) == MCDE_SYS_OK) {
|
||||
char gw[64] = "", ifn[64] = "";
|
||||
|
||||
last = NULL;
|
||||
for (l = strtok_r(out, "\n", &last); l != NULL;
|
||||
l = strtok_r(NULL, "\n", &last)) {
|
||||
(void) sscanf(l, " gateway: %63s", gw);
|
||||
(void) sscanf(l, " interface: %63s", ifn);
|
||||
}
|
||||
if (strcmp(ifn, ifname) == 0)
|
||||
snprintf(c->cur_router, sizeof c->cur_router, "%s", gw);
|
||||
}
|
||||
|
||||
/* the block of the interface in dhcpcd.conf */
|
||||
c->ipv4 = MCDE_IPV4_DHCP;
|
||||
c->ipv6 = MCDE_IPV6_AUTO;
|
||||
if ((fp = fopen(DHCPCD_CONF, "r")) != NULL) {
|
||||
while (fgets(line, sizeof line, fp) != NULL) {
|
||||
char *t = line + strspn(line, " \t");
|
||||
|
||||
t[strcspn(t, "#\r\n")] = '\0';
|
||||
if (strncmp(t, "interface ", 10) == 0) {
|
||||
in = strcmp(t + 10 + strspn(t + 10, " \t"),
|
||||
ifname) == 0;
|
||||
continue;
|
||||
}
|
||||
if (!in)
|
||||
continue;
|
||||
if (strcmp(t, "noipv4") == 0) {
|
||||
c->ipv4 = MCDE_IPV4_OFF;
|
||||
have4 = 1;
|
||||
} else if (strcmp(t, "noipv6") == 0)
|
||||
c->ipv6 = MCDE_IPV6_OFF;
|
||||
else if (sscanf(t, "inform %255s", v) == 1) {
|
||||
c->ipv4 = MCDE_IPV4_DHCP_MANUAL;
|
||||
SplitCidr(v, c->address, sizeof c->address,
|
||||
c->netmask, sizeof c->netmask);
|
||||
have4 = 1;
|
||||
} else if (sscanf(t, "clientid %63s", v) == 1)
|
||||
snprintf(c->clientid, sizeof c->clientid, "%s",
|
||||
v);
|
||||
else if (sscanf(t, "static ip_address=%255s", v) == 1) {
|
||||
c->ipv4 = MCDE_IPV4_MANUAL;
|
||||
SplitCidr(v, c->address, sizeof c->address,
|
||||
c->netmask, sizeof c->netmask);
|
||||
have4 = 1;
|
||||
} else if (sscanf(t, "static routers=%47s", v) == 1)
|
||||
snprintf(c->router, sizeof c->router, "%s", v);
|
||||
else if (sscanf(t, "static ip6_address=%255s", v) == 1) {
|
||||
char *slash = strchr(v, '/');
|
||||
|
||||
c->ipv6 = MCDE_IPV6_MANUAL;
|
||||
if (slash != NULL) {
|
||||
*slash = '\0';
|
||||
c->prefix6 = atoi(slash + 1);
|
||||
}
|
||||
snprintf(c->address6, sizeof c->address6, "%s",
|
||||
v);
|
||||
} else if (strncmp(t, "static domain_name_servers=",
|
||||
27) == 0)
|
||||
c->ndns = Words(t + 27, c->dns[0],
|
||||
sizeof c->dns[0], MCDE_NET_DNS_MAX);
|
||||
else if (strncmp(t, "static domain_search=", 21) == 0)
|
||||
c->nsearch = Words(t + 21, c->search[0],
|
||||
sizeof c->search[0], MCDE_NET_DNS_MAX);
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
/* sysinst's static address in ifconfig.IF, defaultroute in rc.conf */
|
||||
snprintf(path, sizeof path, "/etc/ifconfig.%s", ifname);
|
||||
if (!have4 && (fp = fopen(path, "r")) != NULL) {
|
||||
while (fgets(line, sizeof line, fp) != NULL) {
|
||||
line[strcspn(line, "#\r\n")] = '\0';
|
||||
if (strcmp(line, "dhcp") == 0)
|
||||
dhcpLine = 1;
|
||||
else if (StaticLine(line, c->address, sizeof c->address,
|
||||
c->netmask, sizeof c->netmask)) {
|
||||
c->ipv4 = MCDE_IPV4_MANUAL;
|
||||
have4 = 1;
|
||||
(void) RcConfGet("defaultroute", c->router,
|
||||
sizeof c->router);
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
/* no address configured and no dhcpcd: the interface gets none */
|
||||
if (!have4 && !dhcpLine && (!RcConfGet("dhcpcd", v, sizeof v) ||
|
||||
!Yes(v)))
|
||||
c->ipv4 = MCDE_IPV4_OFF;
|
||||
return MCDE_SYS_OK;
|
||||
}
|
||||
|
||||
/* FILE with the lines between "# MCDE network IF begin" and "... end"
|
||||
* replaced by BLOCK (taken out when BLOCK is empty); kept mode, renamed
|
||||
* into place */
|
||||
static int
|
||||
ReplaceBlock(const char *file, const char *ifname, const char *block)
|
||||
{
|
||||
char line[1024], begin[96], end[96], tmp[256];
|
||||
struct stat st;
|
||||
FILE *from, *to;
|
||||
int fd, skip = 0;
|
||||
mode_t mode = 0644;
|
||||
|
||||
snprintf(begin, sizeof begin, "# MCDE network %s begin\n", ifname);
|
||||
snprintf(end, sizeof end, "# MCDE network %s end\n", ifname);
|
||||
snprintf(tmp, sizeof tmp, "%s.mcdeXXXXXX", file);
|
||||
if (stat(file, &st) == 0)
|
||||
mode = st.st_mode & 07777;
|
||||
if ((fd = mkstemp(tmp)) < 0 || (to = fdopen(fd, "w")) == NULL)
|
||||
return mcde_sys_fail(MCDE_SYS_EFAIL, "Cannot write beside %s.",
|
||||
file);
|
||||
if ((from = fopen(file, "r")) != NULL) {
|
||||
while (fgets(line, sizeof line, from) != NULL) {
|
||||
if (strcmp(line, begin) == 0) {
|
||||
skip = 1;
|
||||
continue;
|
||||
}
|
||||
if (skip) {
|
||||
if (strcmp(line, end) == 0)
|
||||
skip = 0;
|
||||
continue;
|
||||
}
|
||||
fputs(line, to);
|
||||
}
|
||||
fclose(from);
|
||||
}
|
||||
if (block[0] != '\0')
|
||||
fprintf(to, "%s%s%s", begin, block, end);
|
||||
if (fchmod(fd, mode) != 0 || fclose(to) != 0 || rename(tmp, file) != 0) {
|
||||
unlink(tmp);
|
||||
return mcde_sys_fail(MCDE_SYS_EFAIL, "Cannot write %s.", file);
|
||||
}
|
||||
return MCDE_SYS_OK;
|
||||
}
|
||||
|
||||
/* /etc/ifconfig.IF without its IPv4 addresses and "dhcp" (dhcpcd.conf has
|
||||
* them now), "up" kept or added; 1 when an address was taken out */
|
||||
static int
|
||||
StripIfconfig(const char *ifname, int *removed)
|
||||
{
|
||||
char path[256], tmp[300], line[512], a[64], m[64];
|
||||
FILE *from, *to;
|
||||
int fd, up = 0;
|
||||
|
||||
*removed = 0;
|
||||
snprintf(path, sizeof path, "/etc/ifconfig.%s", ifname);
|
||||
snprintf(tmp, sizeof tmp, "%s.mcdeXXXXXX", path);
|
||||
if ((fd = mkstemp(tmp)) < 0 || (to = fdopen(fd, "w")) == NULL)
|
||||
return mcde_sys_fail(MCDE_SYS_EFAIL, "Cannot write beside %s.",
|
||||
path);
|
||||
if ((from = fopen(path, "r")) != NULL) {
|
||||
while (fgets(line, sizeof line, from) != NULL) {
|
||||
char bare[512];
|
||||
|
||||
snprintf(bare, sizeof bare, "%s", line);
|
||||
bare[strcspn(bare, "#\r\n")] = '\0';
|
||||
if (StaticLine(bare, a, sizeof a, m, sizeof m)) {
|
||||
*removed = 1;
|
||||
continue;
|
||||
}
|
||||
if (strcmp(bare, "dhcp") == 0)
|
||||
continue;
|
||||
if (strcmp(bare, "up") == 0)
|
||||
up = 1;
|
||||
fputs(line, to);
|
||||
}
|
||||
fclose(from);
|
||||
}
|
||||
if (!up)
|
||||
fputs("up\n", to);
|
||||
if (fchmod(fd, 0644) != 0 || fclose(to) != 0 || rename(tmp, path) != 0) {
|
||||
unlink(tmp);
|
||||
return mcde_sys_fail(MCDE_SYS_EFAIL, "Cannot write %s.", path);
|
||||
}
|
||||
return MCDE_SYS_OK;
|
||||
}
|
||||
|
||||
int
|
||||
mcde_sys_net_configure_backend(const char *ifname, const McdeSysNetConfig *c)
|
||||
{
|
||||
char block[2048], flags[512], nflags[600];
|
||||
size_t at = 0;
|
||||
int i, removed;
|
||||
char *argv[4];
|
||||
|
||||
#define ADD(...) (at += (size_t) snprintf(block + at, \
|
||||
at < sizeof block ? sizeof block - at : 0, __VA_ARGS__))
|
||||
block[0] = '\0';
|
||||
ADD("interface %s\n", ifname);
|
||||
switch (c->ipv4) {
|
||||
case MCDE_IPV4_OFF:
|
||||
ADD("noipv4\n");
|
||||
break;
|
||||
case MCDE_IPV4_MANUAL:
|
||||
ADD("static ip_address=%s/%d\n", c->address,
|
||||
mcde_sys_net_prefix(c->netmask));
|
||||
if (c->router[0] != '\0')
|
||||
ADD("static routers=%s\n", c->router);
|
||||
break;
|
||||
case MCDE_IPV4_DHCP_MANUAL:
|
||||
ADD("inform %s/%d\n", c->address,
|
||||
mcde_sys_net_prefix(c->netmask));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (c->clientid[0] != '\0' && c->ipv4 != MCDE_IPV4_OFF &&
|
||||
c->ipv4 != MCDE_IPV4_MANUAL)
|
||||
ADD("clientid %s\n", c->clientid);
|
||||
if (c->ipv6 == MCDE_IPV6_OFF)
|
||||
ADD("noipv6\n");
|
||||
else if (c->ipv6 == MCDE_IPV6_MANUAL)
|
||||
ADD("static ip6_address=%s/%d\n", c->address6, c->prefix6);
|
||||
if (c->ndns > 0) {
|
||||
ADD("static domain_name_servers=");
|
||||
for (i = 0; i < c->ndns; i++)
|
||||
ADD("%s%s", i > 0 ? " " : "", c->dns[i]);
|
||||
ADD("\n");
|
||||
}
|
||||
if (c->nsearch > 0) {
|
||||
ADD("static domain_search=");
|
||||
for (i = 0; i < c->nsearch; i++)
|
||||
ADD("%s%s", i > 0 ? " " : "", c->search[i]);
|
||||
ADD("\n");
|
||||
}
|
||||
#undef ADD
|
||||
if (at >= sizeof block)
|
||||
return mcde_sys_fail(MCDE_SYS_EINVAL, "Too many settings.");
|
||||
/* "interface IF" alone says nothing: no block then */
|
||||
if (strchr(strchr(block, '\n') + 1, '\n') == NULL)
|
||||
block[0] = '\0';
|
||||
if (ReplaceBlock(DHCPCD_CONF, ifname, block) != MCDE_SYS_OK ||
|
||||
StripIfconfig(ifname, &removed) != MCDE_SYS_OK)
|
||||
return MCDE_SYS_EFAIL;
|
||||
/* sysinst's defaultroute belonged to the address just moved */
|
||||
if (removed && RcConfSet("defaultroute", "\"\"") != MCDE_SYS_OK)
|
||||
return MCDE_SYS_EFAIL;
|
||||
if (RcConfSet("dhcpcd", "YES") != MCDE_SYS_OK)
|
||||
return MCDE_SYS_EFAIL;
|
||||
/* sysinst's dhcpcd_flags="-qM wm0" restricts dhcpcd to wm0: then this
|
||||
* interface joins the list */
|
||||
if (RcConfGet("dhcpcd_flags", flags, sizeof flags)) {
|
||||
char copy[512], *w, *last = NULL;
|
||||
int names = 0, mine = 0;
|
||||
|
||||
snprintf(copy, sizeof copy, "%s", flags);
|
||||
for (w = strtok_r(copy, " \t", &last); w != NULL;
|
||||
w = strtok_r(NULL, " \t", &last))
|
||||
if (w[0] != '-') {
|
||||
names = 1;
|
||||
mine |= strcmp(w, ifname) == 0;
|
||||
}
|
||||
if (names && !mine) {
|
||||
snprintf(nflags, sizeof nflags, "\"%s %s\"", flags,
|
||||
ifname);
|
||||
if (RcConfSet("dhcpcd_flags", nflags) != MCDE_SYS_OK)
|
||||
return MCDE_SYS_EFAIL;
|
||||
}
|
||||
}
|
||||
/* now: a running dhcpcd reads the file again and binds the interface
|
||||
* anew (dhcpcd(8) -n); else it is started as the boot does */
|
||||
argv[0] = rcdhcpcd;
|
||||
argv[1] = "status";
|
||||
argv[2] = NULL;
|
||||
if (mcde_sys_run(argv) == MCDE_SYS_OK)
|
||||
return mcde_sys_net_renew(ifname);
|
||||
argv[1] = "start";
|
||||
if (mcde_sys_run(argv) != MCDE_SYS_OK)
|
||||
return mcde_sys_fail(MCDE_SYS_EFAIL, "dhcpcd did not start "
|
||||
"(/etc/rc.d/dhcpcd start).");
|
||||
return MCDE_SYS_OK;
|
||||
}
|
||||
|
||||
int
|
||||
mcde_sys_net_renew(const char *ifname)
|
||||
{
|
||||
char *argv[] = { dhcpcdp, "-n", (char *) ifname, NULL };
|
||||
|
||||
if (!mcde_sys_net_ifname_ok(ifname))
|
||||
return mcde_sys_fail(MCDE_SYS_EINVAL, "There is no network "
|
||||
"card of that name.");
|
||||
if (geteuid() != 0)
|
||||
return mcde_sys_fail(MCDE_SYS_EPERM, "Only the administrator "
|
||||
"can renew the lease: click the lock first.");
|
||||
if (mcde_sys_run(argv) != MCDE_SYS_OK)
|
||||
return mcde_sys_fail(MCDE_SYS_EFAIL, "dhcpcd did not renew the "
|
||||
"lease of %s.", ifname);
|
||||
return MCDE_SYS_OK;
|
||||
}
|
||||
|
||||
/* ---- users: wheel administers (su(1) takes only wheel); the password is
|
||||
* hashed here, as passwd(1) does, with pw_gensalt(3) and crypt(3), and only
|
||||
* the hash goes to usermod(8) -- the password itself is on no command line */
|
||||
|
||||
@@ -34,6 +34,18 @@ int mcde_sys_file_value(const char *file, const char *key, char *buf,
|
||||
void mcde_sys_info_backend(McdeSysInfo *info);
|
||||
/* the backend: Wi-Fi or not, and the network joined (net.c asks) */
|
||||
McdeSysNetKind mcde_sys_if_kind(const char *name, char *ssid, size_t len);
|
||||
/* net.c: an interface name that may go on a command line; the prefix
|
||||
* length of a dotted netmask (-1: none) and the netmask of a prefix */
|
||||
int mcde_sys_net_ifname_ok(const char *name);
|
||||
int mcde_sys_net_prefix(const char *netmask);
|
||||
void mcde_sys_net_mask(int prefix, char *buf, size_t len);
|
||||
/* the backend: the configured settings of IFNAME, its router, Ethernet ID
|
||||
* and media into CONFIG (net.c has filled in the current addresses, the MTU
|
||||
* and the DNS servers in use); and writing the configured part, checked */
|
||||
int mcde_sys_net_config_backend(const char *ifname,
|
||||
McdeSysNetConfig *config);
|
||||
int mcde_sys_net_configure_backend(const char *ifname,
|
||||
const McdeSysNetConfig *config);
|
||||
/* users.c: is LOGIN a member of the administrators' group */
|
||||
int mcde_sys_user_is_admin(const char *login);
|
||||
/* the backend: the group whose members administer the computer */
|
||||
|
||||
@@ -57,6 +57,39 @@ main(void)
|
||||
ifs[k].kind == MCDE_NET_WIRED ? "wired" : "other",
|
||||
ifs[k].up ? "up" : "down", ifs[k].address,
|
||||
ifs[k].ssid[0] != '\0' ? " ssid " : "", ifs[k].ssid);
|
||||
/* the settings of each card, read; and a nonsense address that
|
||||
* must be refused before anything is written */
|
||||
for (k = 0; k < n; k++) {
|
||||
static const char *const m4[] = { "dhcp",
|
||||
"dhcp+manual", "manual", "off" };
|
||||
McdeSysNetConfig c, bad;
|
||||
int r;
|
||||
|
||||
if (ifs[k].kind == MCDE_NET_OTHER)
|
||||
continue;
|
||||
r = mcde_sys_net_config(ifs[k].name, &c);
|
||||
printf("netcfg %s %s %s/%s router %s now %s/%s via %s "
|
||||
"dns %d mac %s mtu %d%s%s\n", ifs[k].name,
|
||||
(unsigned) c.ipv4 < 4 ? m4[c.ipv4] : "?",
|
||||
c.address, c.netmask, c.router, c.cur_address,
|
||||
c.cur_netmask, c.cur_router, c.ncur_dns, c.mac,
|
||||
c.mtu, r == MCDE_SYS_OK ? "" : " -- ",
|
||||
r == MCDE_SYS_OK ? "" : mcde_sys_error());
|
||||
if ((unsigned) c.ipv4 > MCDE_IPV4_OFF ||
|
||||
(c.cur_address[0] != '\0' && c.cur_netmask[0] ==
|
||||
'\0')) {
|
||||
printf("FAIL netcfg %s\n", ifs[k].name);
|
||||
failures++;
|
||||
}
|
||||
bad = c;
|
||||
bad.ipv4 = MCDE_IPV4_MANUAL;
|
||||
snprintf(bad.address, sizeof bad.address, "300.1.2.3");
|
||||
if (mcde_sys_net_configure(ifs[k].name, &bad) ==
|
||||
MCDE_SYS_OK) {
|
||||
printf("FAIL 300.1.2.3 taken\n");
|
||||
failures++;
|
||||
}
|
||||
}
|
||||
if (mcde_sys_volume_get(&vol, &muted) == MCDE_SYS_OK) {
|
||||
printf("volume %d%%%s\n", vol, muted ? " muted" : "");
|
||||
if (vol < 0 || vol > 150) {
|
||||
|
||||
@@ -2570,8 +2570,10 @@ dt/bin/dtopen_pdf
|
||||
dt/bin/dtopen_ps
|
||||
dt/bin/dtopen_video
|
||||
dt/bin/dtpad
|
||||
dt/bin/dtpaint
|
||||
dt/bin/dtpdm
|
||||
dt/bin/dtpdmd
|
||||
dt/bin/dtphoto
|
||||
dt/bin/dtprintegrate
|
||||
dt/bin/dtprintinfo
|
||||
dt/bin/dtremotelogin
|
||||
@@ -2592,9 +2594,11 @@ dt/bin/dtstyle
|
||||
dt/bin/dtsystemsettings
|
||||
dt/bin/dtterm
|
||||
dt/bin/dtthemesync
|
||||
dt/bin/dttoolbox
|
||||
dt/bin/dttypes
|
||||
dt/bin/dtwm
|
||||
dt/bin/huffcode
|
||||
dt/bin/mcdesoundd
|
||||
dt/bin/rpc.cmsd
|
||||
dt/bin/rpc.ttdbserver
|
||||
dt/bin/tt_type_comp
|
||||
@@ -2633,10 +2637,6 @@ dt/config/Xsession.d/0072.dtkeys
|
||||
dt/config/Xsession.d/0075.homefolders
|
||||
dt/config/Xsession.d/0077.dtappscan
|
||||
dt/config/Xsession.d/0078.dtthemesync
|
||||
dt/config/Xsession.d/0080.dtlaunch
|
||||
dt/config/Xsession.d/0085.dtdropdown
|
||||
dt/config/Xsession.d/0090.dtbar
|
||||
dt/config/Xsession.d/0095.loginitems
|
||||
dt/config/Xsetup
|
||||
dt/config/Xstartup
|
||||
dt/config/dtspcdenv
|
||||
@@ -2645,8 +2645,14 @@ dt/config/dtterm.ti
|
||||
dt/config/en_US.UTF-8
|
||||
dt/config/fonts.conf
|
||||
dt/config/ims/start.conf
|
||||
dt/config/sessionetc.d/0075.mcdesoundd
|
||||
dt/config/sessionetc.d/0080.dtlaunch
|
||||
dt/config/sessionetc.d/0085.dtdropdown
|
||||
dt/config/sessionetc.d/0090.dtbar
|
||||
dt/config/sessionetc.d/0095.loginitems
|
||||
dt/config/svc/CDE.lcx
|
||||
dt/config/sys.dtprofile
|
||||
dt/config/sys.sessionetc
|
||||
dt/copyright
|
||||
dt/examples/dtlaunch/snippets.example
|
||||
dt/fonts/hack/Hack-Bold.ttf
|
||||
@@ -2679,6 +2685,7 @@ dt/include/Dt/SvcPam.h
|
||||
dt/include/Dt/Term.h
|
||||
dt/include/Dt/TermPrim.h
|
||||
dt/include/Dt/Wsm.h
|
||||
dt/include/Mcde/Displays.h
|
||||
dt/include/Mcde/GlobalMenu.h
|
||||
dt/include/Mcde/Image.h
|
||||
dt/include/Mcde/McdeSys.h
|
||||
@@ -2719,6 +2726,7 @@ dt/lib/libDtSvc.la
|
||||
dt/lib/libDtTerm.la
|
||||
dt/lib/libDtWidget.la
|
||||
dt/lib/libDtXinerama.la
|
||||
dt/lib/libMcdeSound.la
|
||||
dt/lib/libMcdeSys.la
|
||||
dt/lib/libcsa.la
|
||||
dt/lib/libtt.la
|
||||
@@ -3535,6 +3543,7 @@ dt/share/cde/fontaliases/fixed.alias
|
||||
dt/share/cde/fontaliases/fonts.alias
|
||||
dt/share/cde/fontaliases/fonts.dir
|
||||
dt/share/cde/fontaliases/mixed.alias
|
||||
dt/share/dtphoto/dtphoto.menu
|
||||
dt/share/palettes/Alpine.dp
|
||||
dt/share/palettes/Arizona.dp
|
||||
dt/share/palettes/BeigeRose.dp
|
||||
@@ -3578,6 +3587,49 @@ dt/share/palettes/White.dp
|
||||
dt/share/palettes/WhiteBlack.dp
|
||||
dt/share/palettes/desc.C
|
||||
dt/share/palettes/desc.en_US.UTF-8
|
||||
dt/share/sounds/themes/Base/beep.wav
|
||||
dt/share/sounds/themes/Base/clock_chime_hour.wav
|
||||
dt/share/sounds/themes/Base/deiconify.wav
|
||||
dt/share/sounds/themes/Base/desk_switch.wav
|
||||
dt/share/sounds/themes/Base/drop_copy.wav
|
||||
dt/share/sounds/themes/Base/drop_move.wav
|
||||
dt/share/sounds/themes/Base/end.wav
|
||||
dt/share/sounds/themes/Base/error.wav
|
||||
dt/share/sounds/themes/Base/iconify.wav
|
||||
dt/share/sounds/themes/Base/launch.wav
|
||||
dt/share/sounds/themes/Base/new_mail.wav
|
||||
dt/share/sounds/themes/Base/open_folder.wav
|
||||
dt/share/sounds/themes/Base/print_files.wav
|
||||
dt/share/sounds/themes/Base/remove.wav
|
||||
dt/share/sounds/themes/Base/remove_to_dumpster.wav
|
||||
dt/share/sounds/themes/Base/search_hit.wav
|
||||
dt/share/sounds/themes/Base/search_miss.wav
|
||||
dt/share/sounds/themes/Base/start.wav
|
||||
dt/share/sounds/themes/Base/terminal_bell.wav
|
||||
dt/share/sounds/themes/Base/theme.ss
|
||||
dt/share/sounds/themes/Base/warning.wav
|
||||
dt/share/sounds/themes/Camouflage/beep.wav
|
||||
dt/share/sounds/themes/Camouflage/clock_chime_hour.wav
|
||||
dt/share/sounds/themes/Camouflage/deiconify.wav
|
||||
dt/share/sounds/themes/Camouflage/desk_switch.wav
|
||||
dt/share/sounds/themes/Camouflage/drop_copy.wav
|
||||
dt/share/sounds/themes/Camouflage/drop_move.wav
|
||||
dt/share/sounds/themes/Camouflage/end.wav
|
||||
dt/share/sounds/themes/Camouflage/error.wav
|
||||
dt/share/sounds/themes/Camouflage/iconify.wav
|
||||
dt/share/sounds/themes/Camouflage/launch.wav
|
||||
dt/share/sounds/themes/Camouflage/new_mail.wav
|
||||
dt/share/sounds/themes/Camouflage/open_folder.wav
|
||||
dt/share/sounds/themes/Camouflage/print_files.wav
|
||||
dt/share/sounds/themes/Camouflage/remove.wav
|
||||
dt/share/sounds/themes/Camouflage/remove_to_dumpster.wav
|
||||
dt/share/sounds/themes/Camouflage/search_hit.wav
|
||||
dt/share/sounds/themes/Camouflage/search_miss.wav
|
||||
dt/share/sounds/themes/Camouflage/start.wav
|
||||
dt/share/sounds/themes/Camouflage/terminal_bell.wav
|
||||
dt/share/sounds/themes/Camouflage/theme.ss
|
||||
dt/share/sounds/themes/Camouflage/warning.wav
|
||||
dt/share/toolchest/system.chestrc
|
||||
share/doc/mcde/CONTRIBUTORS
|
||||
share/doc/mcde/COPYING
|
||||
share/doc/mcde/HISTORY
|
||||
|
||||
@@ -50,7 +50,9 @@ static Display *dpy;
|
||||
static Widget shell, form, bar, clockLabel;
|
||||
static Widget sink; /* the root's and the client's events go here */
|
||||
static Atom aBar, aMenu, aActive, aActivate, aRefresh, aUtf8, aManager;
|
||||
static Atom aNetActive, aLeader;
|
||||
static Window client; /* the window whose menus are shown */
|
||||
static Boolean focused = True; /* client's program has the focus */
|
||||
static McdeMenuItem items[MCDE_MENU_MAX];
|
||||
static int nitems;
|
||||
static Widget appWidgets[2 * MCDE_MENU_MAX]; /* what Rebuild made */
|
||||
@@ -103,6 +105,10 @@ static const char *fallback[] = {
|
||||
"Dtbar*mbar.shadowThickness: 0",
|
||||
"Dtbar*mcdeM.labelString: M",
|
||||
"Dtbar*clock.marginWidth: 10",
|
||||
/* the bar has the colours of the programs' windows (colour set 5,
|
||||
* primary), not those of a menu bar (6, secondary): it is the
|
||||
* desktop's, as the front panel is (Konrad, 2026-11-13) */
|
||||
"Dtbar*secondaryColorSetId: 5",
|
||||
NULL
|
||||
};
|
||||
|
||||
@@ -643,7 +649,7 @@ Rebuild(void)
|
||||
for (i = 0; i < nappWidgets; i++)
|
||||
XtDestroyWidget(appWidgets[i]);
|
||||
nappWidgets = 0;
|
||||
if (client != None)
|
||||
if (client != None && focused)
|
||||
Build(bar, 0, nitems, 0);
|
||||
}
|
||||
|
||||
@@ -658,6 +664,7 @@ ReadMenu(void)
|
||||
|
||||
static char *shown; /* the text the bar shows now */
|
||||
static Window shownFor;
|
||||
static Boolean shownFocused;
|
||||
const char *text = "";
|
||||
|
||||
if (posted > 0) {
|
||||
@@ -671,7 +678,8 @@ ReadMenu(void)
|
||||
text = (const char *) data;
|
||||
/* the same menus again (a refresh that changed nothing): an open menu
|
||||
* must not be pulled away under the pointer */
|
||||
if (shown != NULL && shownFor == client && strcmp(shown, text) == 0) {
|
||||
if (shown != NULL && shownFor == client && shownFocused == focused &&
|
||||
strcmp(shown, text) == 0) {
|
||||
if (data != NULL)
|
||||
XFree(data);
|
||||
return;
|
||||
@@ -679,6 +687,7 @@ ReadMenu(void)
|
||||
free(shown);
|
||||
shown = strdup(text);
|
||||
shownFor = client;
|
||||
shownFocused = focused;
|
||||
nitems = McdeMenuParse(text, items, MCDE_MENU_MAX);
|
||||
if (nitems < 0)
|
||||
nitems = 0;
|
||||
@@ -687,6 +696,67 @@ ReadMenu(void)
|
||||
Rebuild();
|
||||
}
|
||||
|
||||
/* a WINDOW property of W, or None */
|
||||
static Window
|
||||
WindowProperty(Window w, Atom name)
|
||||
{
|
||||
Atom type;
|
||||
int format;
|
||||
unsigned long n, after;
|
||||
unsigned char *data = NULL;
|
||||
Window v = None;
|
||||
|
||||
if (w != None && XGetWindowProperty(dpy, w, name, 0, 1, False,
|
||||
XA_WINDOW, &type, &format, &n, &after, &data) == Success &&
|
||||
data != NULL && n == 1 && format == 32)
|
||||
v = (Window) *(long *) data;
|
||||
if (data != NULL)
|
||||
XFree(data);
|
||||
return v;
|
||||
}
|
||||
|
||||
/* is ACTIVE a window of the program whose menus the bar has: the window
|
||||
* itself, one of its dialogs (WM_TRANSIENT_FOR, ICCCM 4.1.2.6), or another
|
||||
* window of the same program (WM_CLIENT_LEADER, ICCCM 5.1) */
|
||||
static Boolean
|
||||
OfClient(Window active)
|
||||
{
|
||||
Window w, leader;
|
||||
int depth;
|
||||
|
||||
if (client == None || active == None)
|
||||
return False;
|
||||
for (w = active, depth = 0; w != None && depth < 8; depth++) {
|
||||
if (w == client)
|
||||
return True;
|
||||
w = WindowProperty(w, XA_WM_TRANSIENT_FOR);
|
||||
}
|
||||
leader = WindowProperty(client, aLeader);
|
||||
return leader != None && WindowProperty(active, aLeader) == leader;
|
||||
}
|
||||
|
||||
/* the window manager's _NET_ACTIVE_WINDOW (EWMH): a program that does not
|
||||
* give its menus to the bar has the focus -- the bar shows none, not the
|
||||
* menus of the last program that did. Without the property (a window
|
||||
* manager that does not set it) the bar keeps the last menus, as before. */
|
||||
static void
|
||||
UpdateFocused(void)
|
||||
{
|
||||
Atom type;
|
||||
int format;
|
||||
unsigned long n, after;
|
||||
unsigned char *data = NULL;
|
||||
|
||||
if (XGetWindowProperty(dpy, DefaultRootWindow(dpy), aNetActive, 0, 1,
|
||||
False, XA_WINDOW, &type, &format, &n, &after, &data) == Success &&
|
||||
data != NULL && n == 1 && format == 32)
|
||||
focused = OfClient((Window) *(long *) data);
|
||||
else
|
||||
focused = True;
|
||||
if (data != NULL)
|
||||
XFree(data);
|
||||
}
|
||||
|
||||
static void
|
||||
Follow(Window w)
|
||||
{
|
||||
@@ -699,6 +769,7 @@ Follow(Window w)
|
||||
XtRegisterDrawable(dpy, client, sink);
|
||||
XSelectInput(dpy, client, PropertyChangeMask | StructureNotifyMask);
|
||||
}
|
||||
UpdateFocused();
|
||||
ReadMenu();
|
||||
}
|
||||
|
||||
@@ -732,6 +803,11 @@ Events(Widget w, XtPointer data, XEvent *ev, Boolean *cont)
|
||||
if (ev->xproperty.window == DefaultRootWindow(dpy) &&
|
||||
ev->xproperty.atom == aActive)
|
||||
ReadActive();
|
||||
else if (ev->xproperty.window == DefaultRootWindow(dpy) &&
|
||||
ev->xproperty.atom == aNetActive) {
|
||||
UpdateFocused();
|
||||
ReadMenu();
|
||||
}
|
||||
else if (ev->xproperty.window == client &&
|
||||
ev->xproperty.atom == aMenu)
|
||||
ReadMenu();
|
||||
@@ -800,6 +876,8 @@ main(int argc, char **argv)
|
||||
aRefresh = XInternAtom(dpy, "_MCDE_MENU_REFRESH", False);
|
||||
aUtf8 = XInternAtom(dpy, "UTF8_STRING", False);
|
||||
aManager = XInternAtom(dpy, "MANAGER", False);
|
||||
aNetActive = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False);
|
||||
aLeader = XInternAtom(dpy, "WM_CLIENT_LEADER", False);
|
||||
|
||||
owner = XGetSelectionOwner(dpy, aBar);
|
||||
if (owner != None) {
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
#!/bin/ksh
|
||||
#
|
||||
# 0075.mcdesoundd -- MCDE: the desktop's sounds
|
||||
#
|
||||
# Sourced by sys.sessionetc (sessionetc.d), once dtsession is up.
|
||||
# mcdesoundd plays the events the programs send (a folder opens, the
|
||||
# terminal's bell, a workspace switch; programs/mcdesoundd). Without it
|
||||
# they fall back to the X bell. One per display: started a second time it
|
||||
# says so and ends. Remove the execute bit to switch it off.
|
||||
#
|
||||
if [ -x "$DT_BINPATH/mcdesoundd" ]; then
|
||||
"$DT_BINPATH/mcdesoundd" > /dev/null 2>&1 &
|
||||
fi
|
||||
@@ -2,9 +2,10 @@
|
||||
#
|
||||
# 0080.dtlaunch -- MCDE: the launcher runs in every session
|
||||
#
|
||||
# Sourced by Xsession (Xsession.d). dtlaunch is one per display: started a
|
||||
# second time it only opens the running one, so this does no harm in a
|
||||
# session that already has it. Remove the execute bit to switch it off.
|
||||
# Sourced by sys.sessionetc (sessionetc.d), once dtsession is up. dtlaunch
|
||||
# is one per display: started a second time it only opens the running one,
|
||||
# so this does no harm in a session that already has it. Remove the execute
|
||||
# bit to switch it off.
|
||||
#
|
||||
if [ -x "$DT_BINPATH/dtlaunch" ]; then
|
||||
"$DT_BINPATH/dtlaunch" &
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
#
|
||||
# 0085.dtdropdown -- MCDE: the terminal that drops down from the top
|
||||
#
|
||||
# Sourced by Xsession (Xsession.d). dtterm -dropdown stays hidden until its
|
||||
# key (F12; the resource Dtterm*dropdownKey) and comes down below the top
|
||||
# bar. Remove the execute bit to switch it off.
|
||||
# Sourced by sys.sessionetc (sessionetc.d), once dtsession is up. dtterm
|
||||
# -dropdown stays hidden until its key (F12; the resource
|
||||
# Dtterm*dropdownKey) and comes down below the top bar. Remove the execute
|
||||
# bit to switch it off.
|
||||
#
|
||||
if [ -x "$DT_BINPATH/dtterm" ]; then
|
||||
"$DT_BINPATH/dtterm" -dropdown &
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
#
|
||||
# 0090.dtbar -- MCDE: the bar at the top of the screen runs in every session
|
||||
#
|
||||
# Sourced by Xsession (Xsession.d). dtbar is one per screen: started a
|
||||
# second time it says so and ends. Remove the execute bit to switch it off;
|
||||
# the programs then keep their menu bars in their windows.
|
||||
# Sourced by sys.sessionetc (sessionetc.d), once dtsession is up. dtbar is
|
||||
# one per screen: started a second time it says so and ends. Remove the
|
||||
# execute bit to switch it off; the programs then keep their menu bars in
|
||||
# their windows.
|
||||
#
|
||||
if [ -x "$DT_BINPATH/dtbar" ]; then
|
||||
"$DT_BINPATH/dtbar" &
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
#
|
||||
# 0095.loginitems -- MCDE: the programs the user opens at every login
|
||||
#
|
||||
# Sourced by Xsession (Xsession.d), as 0090.dtbar. ~/.dt/login-items holds
|
||||
# one command a line (System Settings, Startup, writes it); "#" begins a
|
||||
# comment. Each runs in the background through sh, a little after the
|
||||
# Sourced by sys.sessionetc (sessionetc.d), as 0090.dtbar. ~/.dt/login-items
|
||||
# holds one command a line (System Settings, Startup, writes it); "#" begins
|
||||
# a comment. Each runs in the background through sh, a little after the
|
||||
# desktop, so its window finds the window manager.
|
||||
#
|
||||
if [ -r "$HOME/.dt/login-items" ]; then
|
||||
|
||||
@@ -11,7 +11,7 @@ CPP_TARGETS = 0060.dtsysenv Dtlogin Xaccess Xconfig Xconfig.con \
|
||||
Xservers Xservers.con Xservers.nc Xsession Xsession.ive \
|
||||
Xsetup Xstartup current.session display.current.session \
|
||||
display.home.session dtlslocale dtprofile home.session \
|
||||
sys.dtprofile
|
||||
sys.dtprofile sys.sessionetc
|
||||
|
||||
|
||||
|
||||
@@ -73,14 +73,22 @@ CLEANFILES = $(CPP_TARGETS)
|
||||
|
||||
configsdir=$(CDE_INSTALLATION_TOP)/config
|
||||
dist_configs_DATA = Xaccess Xconfig Xfailsafe Xservers
|
||||
dist_configs_SCRIPTS = sys.dtprofile Xfailsafe Xreset Xsetup Xstartup
|
||||
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 0080.dtlaunch 0085.dtdropdown 0090.dtbar \
|
||||
0095.loginitems
|
||||
dist_xsess_SCRIPTS = 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
|
||||
sessetcdir=$(CDE_INSTALLATION_TOP)/config/sessionetc.d
|
||||
dist_sessetc_SCRIPTS = 0075.mcdesoundd 0080.dtlaunch 0085.dtdropdown 0090.dtbar 0095.loginitems
|
||||
|
||||
dist_bin_SCRIPTS = Xsession
|
||||
|
||||
sys.sessionetc: sys.sessionetc.src
|
||||
$(RM) $@
|
||||
$(GENCPP) -P -DXCOMM=# $(AM_CPPFLAGS) $< > $@
|
||||
|
||||
# fake - installed under a different name
|
||||
sys.dtprofile: dtprofile
|
||||
$(RM) $@
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
XCOMM!KORNSHELL
|
||||
XCOMM
|
||||
XCOMM sys.sessionetc -- MCDE: the desktop programs, once the session is up
|
||||
XCOMM
|
||||
XCOMM Run by dtsession after it restored the session resources, started
|
||||
XCOMM the colour server and the window manager, and before the user file
|
||||
XCOMM ~/.dt/sessions/sessionetc (programs/dtsession/SmRestore.c, StartEtc).
|
||||
XCOMM A copy in CDE_CONFIGURATION_TOP/config is taken before this one, the
|
||||
XCOMM way sys.session and sys.resources are found. It sources every
|
||||
XCOMM executable file in the sessionetc.d directories, in the order of their
|
||||
XCOMM names: the loop Xsession runs over Xsession.d (Xsession.src).
|
||||
XCOMM Xsession.d sets up the environment before dtsession; an X client that
|
||||
XCOMM takes the colours of the desktop belongs here, or it starts with
|
||||
XCOMM whatever ~/.Xdefaults says. Remove the execute bit of a script to
|
||||
XCOMM switch it off.
|
||||
XCOMM
|
||||
DT_BINPATH=CDE_INSTALLATION_TOP/bin
|
||||
DT_INSTALL_CONFIG=CDE_INSTALLATION_TOP/config
|
||||
DT_CONFIG=CDE_CONFIGURATION_TOP/config
|
||||
|
||||
for i in $DT_INSTALL_CONFIG $DT_CONFIG; do
|
||||
if [[ -d $i/sessionetc.d ]]; then
|
||||
for SCRIPT in $(ls $i/sessionetc.d); do
|
||||
if [ -x $i/sessionetc.d/$SCRIPT ] &&
|
||||
[ ! -d $i/sessionetc.d/$SCRIPT ]; then
|
||||
. $i/sessionetc.d/$SCRIPT
|
||||
fi
|
||||
done
|
||||
fi
|
||||
done
|
||||
@@ -2408,6 +2408,35 @@ StartEtc( Boolean exiting )
|
||||
struct stat buf;
|
||||
char *execArray[3];
|
||||
|
||||
/*
|
||||
* MCDE: before the user's sessionetc, the system's sys.sessionetc --
|
||||
* the first of CDE_CONFIGURATION_TOP/config and CDE_INSTALLATION_TOP/
|
||||
* config that has one, the way sys.session and sys.resources are found.
|
||||
* It starts the desktop's own programs (the top bar, the launcher, ...)
|
||||
* once the session's resources and the colour server are there; started
|
||||
* from Xsession.d they came up before them, with the colours of
|
||||
* whatever ~/.Xdefaults says (*background).
|
||||
*/
|
||||
if (!exiting) {
|
||||
static char *sysEtc[] = {
|
||||
CDE_CONFIGURATION_TOP "/config/sys.sessionetc",
|
||||
CDE_INSTALLATION_TOP "/config/sys.sessionetc",
|
||||
NULL
|
||||
};
|
||||
int i;
|
||||
|
||||
for (i = 0; sysEtc[i] != NULL; i++) {
|
||||
if (access(sysEtc[i], X_OK) == 0) {
|
||||
execArray[0] = sysEtc[i];
|
||||
execArray[1] = "sys.sessionetc";
|
||||
execArray[2] = NULL;
|
||||
StartClient(execArray[0], execArray, NULL, NULL, NULL,
|
||||
False, False, -1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (exiting) {
|
||||
execArray[0] = smGD.exitPath;
|
||||
execArray[1] = smExitFile;
|
||||
|
||||
@@ -5,6 +5,7 @@ MAINTAINERCLEANFILES = Makefile.in
|
||||
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
|
||||
dtsystemsettings_CPPFLAGS = -I$(top_srcdir)/include $(DT_INCDIR) \
|
||||
|
||||
@@ -350,90 +350,7 @@ MakeSound(Widget parent)
|
||||
return box;
|
||||
}
|
||||
|
||||
/* ---- the network pane --------------------------------------------------- */
|
||||
|
||||
#define NET_ROWS 8
|
||||
|
||||
static Widget netValues[NET_ROWS], netKeys[NET_ROWS];
|
||||
|
||||
static void
|
||||
NetworkRead(void)
|
||||
{
|
||||
McdeSysInterface ifs[32];
|
||||
int n = mcde_sys_interfaces(ifs, 32), i, row = 0;
|
||||
char key[64], value[160];
|
||||
|
||||
for (i = 0; i < n && row < NET_ROWS; i++) {
|
||||
const McdeSysInterface *it = &ifs[i];
|
||||
|
||||
if (it->kind == MCDE_NET_OTHER)
|
||||
continue;
|
||||
snprintf(key, sizeof key, "%s (%s)", it->kind == MCDE_NET_WIFI ?
|
||||
"Wi-Fi" : "Ethernet", it->name);
|
||||
if (!it->up)
|
||||
snprintf(value, sizeof value, "%s",
|
||||
it->kind == MCDE_NET_WIFI ? "not connected" :
|
||||
"no cable");
|
||||
else if (it->ssid[0] != '\0')
|
||||
snprintf(value, sizeof value, "%s, address %s", it->ssid,
|
||||
it->address);
|
||||
else
|
||||
snprintf(value, sizeof value, "address %s", it->address);
|
||||
SetText(netKeys[row], key);
|
||||
SetText(netValues[row], value);
|
||||
XtManageChild(netKeys[row]);
|
||||
XtManageChild(netValues[row]);
|
||||
row++;
|
||||
}
|
||||
if (row == 0) {
|
||||
SetText(netKeys[0], "Network");
|
||||
SetText(netValues[0], "no network card");
|
||||
XtManageChild(netKeys[0]);
|
||||
XtManageChild(netValues[0]);
|
||||
row = 1;
|
||||
}
|
||||
for (; row < NET_ROWS; row++) {
|
||||
XtUnmanageChild(netKeys[row]);
|
||||
XtUnmanageChild(netValues[row]);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
NetworkRefresh(Widget w, XtPointer data, XtPointer call)
|
||||
{
|
||||
(void) w;
|
||||
(void) data;
|
||||
(void) call;
|
||||
NetworkRead();
|
||||
}
|
||||
|
||||
static Widget
|
||||
MakeNetwork(Widget parent)
|
||||
{
|
||||
Widget box = XtVaCreateWidget("network", xmRowColumnWidgetClass, parent,
|
||||
XmNspacing, 10, NULL);
|
||||
const char *rows[2 * NET_ROWS];
|
||||
Widget table;
|
||||
WidgetList kids;
|
||||
int i;
|
||||
|
||||
Text(box, "intro", "The network cards of this computer and their "
|
||||
"addresses:");
|
||||
for (i = 0; i < NET_ROWS; i++) {
|
||||
rows[2 * i] = "";
|
||||
rows[2 * i + 1] = "";
|
||||
}
|
||||
table = Table(box, rows, NET_ROWS, netValues);
|
||||
XtVaGetValues(table, XmNchildren, &kids, NULL);
|
||||
for (i = 0; i < NET_ROWS; i++)
|
||||
netKeys[i] = kids[i];
|
||||
PaneButton(box, "Refresh", NetworkRefresh, NULL);
|
||||
NetworkRead();
|
||||
if (MakeWifi(box) != NULL)
|
||||
XtVaCreateManagedWidget("sep", xmSeparatorWidgetClass, box,
|
||||
XmNpositionIndex, 3, NULL);
|
||||
return box;
|
||||
}
|
||||
/* ---- the network pane: network.c ---------------------------------------- */
|
||||
|
||||
/* ---- the Bluetooth pane ------------------------------------------------- */
|
||||
|
||||
@@ -734,10 +651,12 @@ main(int argc, char **argv)
|
||||
else if (strcmp(argv[i], "-join-wifi") == 0 && i + 1 < argc)
|
||||
return JoinWifiCommand(argv[i + 1],
|
||||
i + 2 < argc ? argv[i + 2] : NULL);
|
||||
else if (strcmp(argv[i], "-renew-dhcp") == 0 && i + 1 < argc)
|
||||
return RenewDhcpCommand(argv[i + 1]);
|
||||
else {
|
||||
fprintf(stderr, "usage: dtsystemsettings [-pane ID | "
|
||||
"-apply-update | -apply-displays | -set-timezone ZONE | -join-wifi IF "
|
||||
"[SSID-HEX]]\n");
|
||||
"[SSID-HEX] | -renew-dhcp IF]\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,762 @@
|
||||
/*
|
||||
* network.c -- dtsystemsettings: the Network pane
|
||||
*
|
||||
* Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE.
|
||||
*
|
||||
* "Show:" chooses Network Status -- every card with a light and a sentence
|
||||
* of what it is doing, and "Configure..." -- or one card. A card has the
|
||||
* tabs TCP/IP (Configure IPv4: Using DHCP, Using DHCP with manual address,
|
||||
* Manually, Off; address, subnet mask, router, DHCP client ID, Renew DHCP
|
||||
* Lease; Configure IPv6: Automatically, Manually, Off), DNS (servers and
|
||||
* search domains, one a line), Wi-Fi (wifi.c, a Wi-Fi card only) and
|
||||
* Ethernet (its ID, media, MTU). The pane of that generation's System
|
||||
* Preferences is the model (docs/reference/netconfig.txt in the Makronix
|
||||
* tree). Where the system keeps the settings McdeSys knows
|
||||
* (mcde_sys_net_config, mcde_sys_net_configure): dhcpcd.conf on NetBSD,
|
||||
* NetworkManager on Linux.
|
||||
*
|
||||
* Changing them is the administrator's: as a user the fields show what is
|
||||
* set and the lock offers "Unlock...", which opens this pane as root in a
|
||||
* terminal after su(1) -- as Accounts does. As root "Apply Now" writes and
|
||||
* applies them at once. While DHCP gives an address the fields show what
|
||||
* the card has now, greyed.
|
||||
*
|
||||
* 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 <unistd.h>
|
||||
|
||||
#include <X11/Intrinsic.h>
|
||||
#include <Xm/Xm.h>
|
||||
#include <Xm/Form.h>
|
||||
#include <Xm/Frame.h>
|
||||
#include <Xm/Label.h>
|
||||
#include <Xm/PushB.h>
|
||||
#include <Xm/RowColumn.h>
|
||||
#include <Xm/Separator.h>
|
||||
#include <Xm/Text.h>
|
||||
#include <Xm/TextF.h>
|
||||
#include <Xm/ToggleB.h>
|
||||
|
||||
#include <Mcde/McdeSys.h>
|
||||
|
||||
#include "ui.h"
|
||||
|
||||
#define MAX_IFS 16
|
||||
|
||||
static McdeSysInterface ifs[MAX_IFS];
|
||||
static int nifs;
|
||||
static Widget showMenu, showButtons[MAX_IFS + 1], holder;
|
||||
static int shown; /* 0: Network Status, i: ifs[i - 1] */
|
||||
static int root;
|
||||
|
||||
/* the card's page */
|
||||
static McdeSysNetConfig cfg;
|
||||
static Widget v4Buttons[4], v6Buttons[3], v4Menu, v6Menu;
|
||||
static Widget fAddr, fMask, fRouter, fClient, fAddr6, fPrefix6, renew;
|
||||
static Widget tDns, tSearch, note, tabRow, tabPages[4];
|
||||
static int v4, v6, ntabs;
|
||||
|
||||
static Widget showRow, showSep; /* the head that stays */
|
||||
|
||||
static void Show(int which);
|
||||
|
||||
/* W below ABOVE; ABOVE NULL: below the head (the top of the form before
|
||||
* there is one). The pane is one form: a RowColumn taller than the window
|
||||
* wrapped into a second column, a form inside the form stayed 1x1
|
||||
* (measured on Xvfb, 2026-11-13) */
|
||||
static Widget
|
||||
Stack(Widget w, Widget above)
|
||||
{
|
||||
if (above == NULL)
|
||||
above = showSep;
|
||||
XtVaSetValues(w, XmNtopAttachment, above != NULL ? XmATTACH_WIDGET :
|
||||
XmATTACH_FORM, XmNtopWidget, above, XmNtopOffset, above != NULL ?
|
||||
8 : 0, XmNleftAttachment, XmATTACH_FORM, NULL);
|
||||
return w;
|
||||
}
|
||||
|
||||
static const char *const v4Names[] = { "Using DHCP",
|
||||
"Using DHCP with manual address", "Manually", "Off" };
|
||||
static const McdeSysIpv4 v4Values[] = { MCDE_IPV4_DHCP,
|
||||
MCDE_IPV4_DHCP_MANUAL, MCDE_IPV4_MANUAL, MCDE_IPV4_OFF };
|
||||
static const char *const v6Names[] = { "Automatically", "Manually", "Off" };
|
||||
static const McdeSysIpv6 v6Values[] = { MCDE_IPV6_AUTO, MCDE_IPV6_MANUAL,
|
||||
MCDE_IPV6_OFF };
|
||||
|
||||
static void
|
||||
Kind(const McdeSysInterface *it, char *buf, size_t len)
|
||||
{
|
||||
snprintf(buf, len, "%s (%s)", it->kind == MCDE_NET_WIFI ? "Wi-Fi" :
|
||||
"Ethernet", it->name);
|
||||
}
|
||||
|
||||
static void
|
||||
ReadInterfaces(void)
|
||||
{
|
||||
McdeSysInterface all[32];
|
||||
int n = mcde_sys_interfaces(all, 32), i;
|
||||
|
||||
nifs = 0;
|
||||
for (i = 0; i < n && nifs < MAX_IFS; i++)
|
||||
if (all[i].kind != MCDE_NET_OTHER)
|
||||
ifs[nifs++] = all[i];
|
||||
}
|
||||
|
||||
/* ---- Network Status ---------------------------------------------------- */
|
||||
|
||||
static void
|
||||
ConfigureClicked(Widget w, XtPointer data, XtPointer call)
|
||||
{
|
||||
(void) w;
|
||||
(void) call;
|
||||
Show((int) (long) data);
|
||||
}
|
||||
|
||||
/* a light: green connected, yellow on but not joined, red no address */
|
||||
static void
|
||||
Light(Widget parent, const char *colour)
|
||||
{
|
||||
Widget l = Text(parent, "light", "\342\227\217"); /* U+25CF */
|
||||
|
||||
XtVaSetValues(l, XtVaTypedArg, XmNforeground, XmRString, colour,
|
||||
strlen(colour) + 1, XmNrenderTable, PaneFont(parent, 14, True),
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
MakeStatus(Widget parent)
|
||||
{
|
||||
Widget grid;
|
||||
char kind[64], text[256];
|
||||
int i;
|
||||
|
||||
grid = Stack(Text(parent, "intro", "The network cards of this "
|
||||
"computer:"), NULL);
|
||||
/* filled first, managed then: a container managed empty in a form
|
||||
* stays 1x1 (Motif) */
|
||||
grid = Stack(XtVaCreateWidget("cards", xmRowColumnWidgetClass,
|
||||
parent, XmNspacing, 6, XmNmarginWidth, 0, XmNpacking,
|
||||
XmPACK_COLUMN, XmNnumColumns, 1, NULL), grid);
|
||||
for (i = 0; i < nifs; i++) {
|
||||
const McdeSysInterface *it = &ifs[i];
|
||||
Widget row = XtVaCreateManagedWidget("row",
|
||||
xmRowColumnWidgetClass, grid, XmNorientation, XmHORIZONTAL,
|
||||
XmNmarginWidth, 0, XmNspacing, 8,
|
||||
XmNentryVerticalAlignment, XmALIGNMENT_CENTER, NULL);
|
||||
Widget words;
|
||||
|
||||
Kind(it, kind, sizeof kind);
|
||||
if (it->up && it->ssid[0] != '\0') {
|
||||
Light(row, "green3");
|
||||
snprintf(text, sizeof text, "%s is connected to \"%s\" "
|
||||
"and has the IP address %s.", kind, it->ssid,
|
||||
it->address);
|
||||
} else if (it->up) {
|
||||
Light(row, "green3");
|
||||
snprintf(text, sizeof text, "%s is connected and has the "
|
||||
"IP address %s.", kind, it->address);
|
||||
} else if (it->kind == MCDE_NET_WIFI) {
|
||||
Light(row, "gold");
|
||||
snprintf(text, sizeof text, "%s is on but is not "
|
||||
"connected to a network.", kind);
|
||||
} else {
|
||||
Light(row, "red3");
|
||||
snprintf(text, sizeof text, "%s has no IP address: is the "
|
||||
"cable plugged in?", kind);
|
||||
}
|
||||
words = Text(row, "sentence", text);
|
||||
XtVaSetValues(words, XmNalignment, XmALIGNMENT_BEGINNING, NULL);
|
||||
Button(row, "Configure...", ConfigureClicked,
|
||||
(XtPointer) (long) (i + 1));
|
||||
}
|
||||
if (nifs == 0)
|
||||
Text(grid, "none", "This computer has no network card.");
|
||||
XtManageChild(grid);
|
||||
}
|
||||
|
||||
/* ---- one card: the fields --------------------------------------------- */
|
||||
|
||||
static Widget
|
||||
Field(Widget parent, const char *name, int columns)
|
||||
{
|
||||
return XtVaCreateManagedWidget(name, xmTextFieldWidgetClass, parent,
|
||||
XmNcolumns, columns, XmNmarginHeight, 1, XmNshadowThickness, 1,
|
||||
XmNhighlightThickness, 1, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
SetField(Widget w, const char *text)
|
||||
{
|
||||
XmTextFieldSetString(w, (char *) text);
|
||||
}
|
||||
|
||||
static void
|
||||
GetField(Widget w, char *buf, size_t len)
|
||||
{
|
||||
char *s = XmTextFieldGetString(w);
|
||||
char *p = s, *e;
|
||||
|
||||
while (*p == ' ' || *p == '\t')
|
||||
p++;
|
||||
e = p + strlen(p);
|
||||
while (e > p && (e[-1] == ' ' || e[-1] == '\t'))
|
||||
*--e = '\0';
|
||||
snprintf(buf, len, "%s", p);
|
||||
XtFree(s);
|
||||
}
|
||||
|
||||
static void
|
||||
Editable(Widget w, Boolean on)
|
||||
{
|
||||
XtSetSensitive(w, root && on);
|
||||
}
|
||||
|
||||
/* what the fields show and allow for the chosen methods */
|
||||
static void
|
||||
UpdateFields(void)
|
||||
{
|
||||
char b[64];
|
||||
McdeSysIpv4 m4 = v4Values[v4];
|
||||
McdeSysIpv6 m6 = v6Values[v6];
|
||||
|
||||
if (m4 == MCDE_IPV4_OFF) {
|
||||
SetField(fAddr, "");
|
||||
SetField(fMask, "");
|
||||
SetField(fRouter, "");
|
||||
} else if (m4 == MCDE_IPV4_DHCP) {
|
||||
SetField(fAddr, cfg.cur_address);
|
||||
SetField(fMask, cfg.cur_netmask);
|
||||
SetField(fRouter, cfg.cur_router);
|
||||
} else {
|
||||
GetField(fAddr, b, sizeof b);
|
||||
if (b[0] == '\0')
|
||||
SetField(fAddr, cfg.address[0] != '\0' ? cfg.address :
|
||||
cfg.cur_address);
|
||||
GetField(fMask, b, sizeof b);
|
||||
if (b[0] == '\0')
|
||||
SetField(fMask, cfg.netmask[0] != '\0' ? cfg.netmask :
|
||||
cfg.cur_netmask[0] != '\0' ? cfg.cur_netmask :
|
||||
"255.255.255.0");
|
||||
GetField(fRouter, b, sizeof b);
|
||||
if (b[0] == '\0' || m4 == MCDE_IPV4_DHCP_MANUAL)
|
||||
SetField(fRouter, m4 == MCDE_IPV4_MANUAL &&
|
||||
cfg.router[0] != '\0' ? cfg.router :
|
||||
cfg.cur_router);
|
||||
}
|
||||
Editable(fAddr, m4 == MCDE_IPV4_MANUAL || m4 == MCDE_IPV4_DHCP_MANUAL);
|
||||
Editable(fMask, m4 == MCDE_IPV4_MANUAL || m4 == MCDE_IPV4_DHCP_MANUAL);
|
||||
Editable(fRouter, m4 == MCDE_IPV4_MANUAL);
|
||||
Editable(fClient, m4 == MCDE_IPV4_DHCP || m4 == MCDE_IPV4_DHCP_MANUAL);
|
||||
XtSetSensitive(renew, m4 == MCDE_IPV4_DHCP ||
|
||||
m4 == MCDE_IPV4_DHCP_MANUAL);
|
||||
|
||||
if (m6 == MCDE_IPV6_OFF) {
|
||||
SetField(fAddr6, "");
|
||||
SetField(fPrefix6, "");
|
||||
} else if (m6 == MCDE_IPV6_AUTO) {
|
||||
SetField(fAddr6, cfg.cur_address6);
|
||||
if (cfg.cur_address6[0] != '\0') {
|
||||
snprintf(b, sizeof b, "%d", cfg.cur_prefix6);
|
||||
SetField(fPrefix6, b);
|
||||
} else
|
||||
SetField(fPrefix6, "");
|
||||
} else {
|
||||
GetField(fAddr6, b, sizeof b);
|
||||
if (b[0] == '\0')
|
||||
SetField(fAddr6, cfg.address6);
|
||||
GetField(fPrefix6, b, sizeof b);
|
||||
if (b[0] == '\0') {
|
||||
snprintf(b, sizeof b, "%d", cfg.prefix6 > 0 ?
|
||||
cfg.prefix6 : 64);
|
||||
SetField(fPrefix6, b);
|
||||
}
|
||||
}
|
||||
Editable(fAddr6, m6 == MCDE_IPV6_MANUAL);
|
||||
Editable(fPrefix6, m6 == MCDE_IPV6_MANUAL);
|
||||
}
|
||||
|
||||
static void
|
||||
V4Chosen(Widget w, XtPointer data, XtPointer call)
|
||||
{
|
||||
(void) w;
|
||||
(void) call;
|
||||
v4 = (int) (long) data;
|
||||
UpdateFields();
|
||||
}
|
||||
|
||||
static void
|
||||
V6Chosen(Widget w, XtPointer data, XtPointer call)
|
||||
{
|
||||
(void) w;
|
||||
(void) call;
|
||||
v6 = (int) (long) data;
|
||||
UpdateFields();
|
||||
}
|
||||
|
||||
static Widget
|
||||
Choice(Widget parent, const char *name, const char *const *labels, int n,
|
||||
Widget *buttons, XtCallbackProc cb)
|
||||
{
|
||||
Widget pull = XmCreatePulldownMenu(parent, (char *) name, NULL, 0);
|
||||
Widget menu;
|
||||
Arg a[1];
|
||||
int i;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
XmString s = XmStringCreateLocalized((char *) labels[i]);
|
||||
|
||||
buttons[i] = XtVaCreateManagedWidget("choice",
|
||||
xmPushButtonWidgetClass, pull, XmNlabelString, s, NULL);
|
||||
XmStringFree(s);
|
||||
XtAddCallback(buttons[i], XmNactivateCallback, cb,
|
||||
(XtPointer) (long) i);
|
||||
}
|
||||
XtSetArg(a[0], XmNsubMenuId, pull);
|
||||
menu = XmCreateOptionMenu(parent, (char *) name, a, 1);
|
||||
XtUnmanageChild(XmOptionLabelGadget(menu));
|
||||
XtManageChild(menu);
|
||||
return menu;
|
||||
}
|
||||
|
||||
/* keys right-aligned in the first column, the fields in the second */
|
||||
static Widget
|
||||
Grid(Widget parent, int rows)
|
||||
{
|
||||
return XtVaCreateManagedWidget("grid", xmRowColumnWidgetClass, parent,
|
||||
XmNorientation, XmVERTICAL, XmNpacking, XmPACK_COLUMN,
|
||||
XmNnumColumns, 2, XmNisAligned, False, XmNspacing, 2,
|
||||
XmNmarginWidth, 0, XmNentryVerticalAlignment, XmALIGNMENT_CENTER,
|
||||
XmNuserData, (XtPointer) (long) rows, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
Key(Widget grid, const char *text)
|
||||
{
|
||||
Widget k = Text(grid, "key", text);
|
||||
|
||||
XtVaSetValues(k, XmNalignment, XmALIGNMENT_END, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
RenewClicked(Widget w, XtPointer data, XtPointer call)
|
||||
{
|
||||
const char *ifname = ifs[shown - 1].name;
|
||||
char cmd[512], inner[160];
|
||||
|
||||
(void) w;
|
||||
(void) data;
|
||||
(void) call;
|
||||
if (mcde_sys_net_renew(ifname) == MCDE_SYS_OK) {
|
||||
SetText(note, "The lease is renewed.");
|
||||
return;
|
||||
}
|
||||
if (!root) {
|
||||
/* asking the DHCP server again is the administrator's on
|
||||
* NetBSD: in a terminal, after su(1) */
|
||||
snprintf(inner, sizeof inner, "dtsystemsettings -renew-dhcp %s",
|
||||
ifname);
|
||||
AsRoot("Renew DHCP Lease", inner, cmd, sizeof cmd);
|
||||
Spawn(cmd);
|
||||
SetText(note, "The password is asked for in the window that "
|
||||
"opened.");
|
||||
return;
|
||||
}
|
||||
SetText(note, mcde_sys_error());
|
||||
}
|
||||
|
||||
static void
|
||||
MakeTcpIp(Widget parent)
|
||||
{
|
||||
Widget grid;
|
||||
char b[16];
|
||||
int i;
|
||||
|
||||
grid = Grid(parent, 5);
|
||||
Key(grid, "Configure IPv4:");
|
||||
Key(grid, "IP Address:");
|
||||
Key(grid, "Subnet Mask:");
|
||||
Key(grid, "Router:");
|
||||
Key(grid, "DHCP Client ID:");
|
||||
v4Menu = Choice(grid, "configureIPv4", v4Names, 4, v4Buttons,
|
||||
V4Chosen);
|
||||
fAddr = Field(grid, "address", 16);
|
||||
fMask = Field(grid, "netmask", 16);
|
||||
fRouter = Field(grid, "router", 16);
|
||||
fClient = Field(grid, "clientid", 16);
|
||||
renew = PaneButton(parent, "Renew DHCP Lease", RenewClicked, NULL);
|
||||
XtVaCreateManagedWidget("sep", xmSeparatorWidgetClass, parent, NULL);
|
||||
/* IPv6 in one line: the window has the height of the overview */
|
||||
grid = XtVaCreateManagedWidget("ipv6", xmRowColumnWidgetClass, parent,
|
||||
XmNorientation, XmHORIZONTAL, XmNmarginWidth, 0, XmNspacing, 4,
|
||||
XmNentryVerticalAlignment, XmALIGNMENT_CENTER, NULL);
|
||||
Text(grid, "key", "Configure IPv6:");
|
||||
v6Menu = Choice(grid, "configureIPv6", v6Names, 3, v6Buttons,
|
||||
V6Chosen);
|
||||
fAddr6 = Field(grid, "address6", 22);
|
||||
Text(grid, "slash", "/");
|
||||
fPrefix6 = Field(grid, "prefix6", 3);
|
||||
|
||||
for (v4 = 0, i = 0; i < 4; i++)
|
||||
if (v4Values[i] == cfg.ipv4)
|
||||
v4 = i;
|
||||
for (v6 = 0, i = 0; i < 3; i++)
|
||||
if (v6Values[i] == cfg.ipv6)
|
||||
v6 = i;
|
||||
XtVaSetValues(v4Menu, XmNmenuHistory, v4Buttons[v4], NULL);
|
||||
XtVaSetValues(v6Menu, XmNmenuHistory, v6Buttons[v6], NULL);
|
||||
XtSetSensitive(v4Menu, root);
|
||||
XtSetSensitive(v6Menu, root);
|
||||
SetField(fClient, cfg.clientid);
|
||||
if (cfg.ipv4 == MCDE_IPV4_MANUAL || cfg.ipv4 == MCDE_IPV4_DHCP_MANUAL) {
|
||||
SetField(fAddr, cfg.address);
|
||||
SetField(fMask, cfg.netmask);
|
||||
}
|
||||
if (cfg.ipv4 == MCDE_IPV4_MANUAL)
|
||||
SetField(fRouter, cfg.router);
|
||||
if (cfg.ipv6 == MCDE_IPV6_MANUAL) {
|
||||
SetField(fAddr6, cfg.address6);
|
||||
snprintf(b, sizeof b, "%d", cfg.prefix6);
|
||||
SetField(fPrefix6, b);
|
||||
}
|
||||
UpdateFields();
|
||||
}
|
||||
|
||||
/* N strings WIDTH bytes apart from ITEMS, one a line, in a text */
|
||||
static Widget
|
||||
Lines(Widget parent, const char *name, const char *items, int n,
|
||||
size_t width)
|
||||
{
|
||||
char text[1024];
|
||||
size_t at = 0;
|
||||
Widget w;
|
||||
Arg a[5];
|
||||
int i;
|
||||
|
||||
text[0] = '\0';
|
||||
for (i = 0; i < n && at < sizeof text; i++)
|
||||
at += (size_t) snprintf(text + at, sizeof text - at, "%s%s",
|
||||
i > 0 ? "\n" : "", items + (size_t) i * width);
|
||||
XtSetArg(a[0], XmNeditMode, XmMULTI_LINE_EDIT);
|
||||
XtSetArg(a[1], XmNrows, 3);
|
||||
XtSetArg(a[2], XmNcolumns, 34);
|
||||
XtSetArg(a[3], XmNeditable, root ? True : False);
|
||||
XtSetArg(a[4], XmNscrollHorizontal, False);
|
||||
w = XmCreateScrolledText(parent, (char *) name, a, 5);
|
||||
XmTextSetString(w, text);
|
||||
XtManageChild(w);
|
||||
return w;
|
||||
}
|
||||
|
||||
static void
|
||||
MakeDns(Widget parent)
|
||||
{
|
||||
char now[256];
|
||||
size_t at = 0;
|
||||
int i;
|
||||
|
||||
Text(parent, "dnsLabel", "DNS Servers (one a line):");
|
||||
tDns = Lines(parent, "dns", cfg.dns[0], cfg.ndns, sizeof cfg.dns[0]);
|
||||
Text(parent, "searchLabel", "Search Domains (one a line):");
|
||||
tSearch = Lines(parent, "search", cfg.search[0], cfg.nsearch,
|
||||
sizeof cfg.search[0]);
|
||||
now[0] = '\0';
|
||||
for (i = 0; i < cfg.ncur_dns && at < sizeof now; i++)
|
||||
at += (size_t) snprintf(now + at, sizeof now - at, "%s%s",
|
||||
i > 0 ? ", " : "", cfg.cur_dns[i]);
|
||||
{
|
||||
char text[300];
|
||||
|
||||
snprintf(text, sizeof text, "In use now: %s", now[0] != '\0' ?
|
||||
now : "none");
|
||||
Text(parent, "dnsNow", text);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
MakeEthernet(Widget parent, const McdeSysInterface *it)
|
||||
{
|
||||
char mtu[16];
|
||||
const char *rows[6];
|
||||
|
||||
snprintf(mtu, sizeof mtu, "%d", cfg.mtu);
|
||||
rows[0] = it->kind == MCDE_NET_WIFI ? "Wi-Fi ID:" : "Ethernet ID:";
|
||||
rows[1] = cfg.mac[0] != '\0' ? cfg.mac : "unknown";
|
||||
rows[2] = "Media:";
|
||||
rows[3] = cfg.media[0] != '\0' ? cfg.media : "unknown";
|
||||
rows[4] = "MTU:";
|
||||
rows[5] = cfg.mtu > 0 ? mtu : "unknown";
|
||||
Table(parent, rows, 3, NULL);
|
||||
}
|
||||
|
||||
/* the tabs: toggle buttons in one radio row, the page of the one set */
|
||||
static void
|
||||
TabChosen(Widget w, XtPointer data, XtPointer call)
|
||||
{
|
||||
XmToggleButtonCallbackStruct *cbs = (XmToggleButtonCallbackStruct *)
|
||||
call;
|
||||
int i, which = (int) (long) data;
|
||||
|
||||
(void) w;
|
||||
if (!cbs->set)
|
||||
return;
|
||||
for (i = 0; i < ntabs; i++)
|
||||
if (i == which)
|
||||
XtManageChild(tabPages[i]);
|
||||
else
|
||||
XtUnmanageChild(tabPages[i]);
|
||||
}
|
||||
|
||||
static Widget
|
||||
Tab(const char *label, Widget pages)
|
||||
{
|
||||
XmString s = XmStringCreateLocalized((char *) label);
|
||||
Widget t = XtVaCreateManagedWidget("tab", xmToggleButtonWidgetClass,
|
||||
tabRow, XmNlabelString, s, XmNindicatorOn, False,
|
||||
XmNshadowThickness, 2, XmNfillOnSelect, True, XmNmarginWidth, 10,
|
||||
XmNset, ntabs == 0 ? XmSET : XmUNSET, NULL);
|
||||
Widget page = XtVaCreateWidget("page", xmRowColumnWidgetClass, pages,
|
||||
XmNspacing, 4, XmNmarginWidth, 10, XmNmarginHeight, 6,
|
||||
XmNleftAttachment, XmATTACH_FORM, XmNtopAttachment, XmATTACH_FORM,
|
||||
NULL);
|
||||
|
||||
XmStringFree(s);
|
||||
XtAddCallback(t, XmNvalueChangedCallback, TabChosen,
|
||||
(XtPointer) (long) ntabs);
|
||||
tabPages[ntabs++] = page;
|
||||
return page;
|
||||
}
|
||||
|
||||
/* the lines of a multi-line text into N strings WIDTH bytes apart */
|
||||
static int
|
||||
ReadLines(Widget w, char *dst, size_t width, int max)
|
||||
{
|
||||
char *s = XmTextGetString(w), *line, *last = NULL;
|
||||
int n = 0;
|
||||
|
||||
for (line = strtok_r(s, "\n", &last); line != NULL && n < max;
|
||||
line = strtok_r(NULL, "\n", &last)) {
|
||||
char *p = line + strspn(line, " \t,"), *e;
|
||||
|
||||
e = p + strcspn(p, " \t,");
|
||||
*e = '\0';
|
||||
if (*p != '\0')
|
||||
snprintf(dst + (size_t) n++ * width, width, "%s", p);
|
||||
}
|
||||
XtFree(s);
|
||||
return n;
|
||||
}
|
||||
|
||||
static void
|
||||
ApplyClicked(Widget w, XtPointer data, XtPointer call)
|
||||
{
|
||||
McdeSysNetConfig c = cfg;
|
||||
char b[16];
|
||||
|
||||
(void) w;
|
||||
(void) data;
|
||||
(void) call;
|
||||
c.ipv4 = v4Values[v4];
|
||||
c.ipv6 = v6Values[v6];
|
||||
GetField(fAddr, c.address, sizeof c.address);
|
||||
GetField(fMask, c.netmask, sizeof c.netmask);
|
||||
GetField(fRouter, c.router, sizeof c.router);
|
||||
GetField(fClient, c.clientid, sizeof c.clientid);
|
||||
GetField(fAddr6, c.address6, sizeof c.address6);
|
||||
GetField(fPrefix6, b, sizeof b);
|
||||
c.prefix6 = atoi(b);
|
||||
c.ndns = ReadLines(tDns, c.dns[0], sizeof c.dns[0], MCDE_NET_DNS_MAX);
|
||||
c.nsearch = ReadLines(tSearch, c.search[0], sizeof c.search[0],
|
||||
MCDE_NET_DNS_MAX);
|
||||
SetText(note, "Applying ...");
|
||||
XmUpdateDisplay(note);
|
||||
if (mcde_sys_net_configure(ifs[shown - 1].name, &c) != MCDE_SYS_OK) {
|
||||
Message(holder, mcde_sys_error(), 1);
|
||||
SetText(note, "Not applied.");
|
||||
return;
|
||||
}
|
||||
Show(shown);
|
||||
SetText(note, "Applied: the card has the new settings, now and at "
|
||||
"every start.");
|
||||
}
|
||||
|
||||
static void
|
||||
UnlockClicked(Widget w, XtPointer data, XtPointer call)
|
||||
{
|
||||
char cmd[512];
|
||||
|
||||
(void) w;
|
||||
(void) data;
|
||||
(void) call;
|
||||
AsRoot("Unlock Network", "dtsystemsettings -pane network", cmd,
|
||||
sizeof cmd);
|
||||
Spawn(cmd);
|
||||
}
|
||||
|
||||
static void
|
||||
MakeCard(Widget parent, const McdeSysInterface *it)
|
||||
{
|
||||
Widget frame, pages, bottom, page;
|
||||
int r = mcde_sys_net_config(it->name, &cfg);
|
||||
|
||||
ntabs = 0;
|
||||
tabRow = Stack(XtVaCreateWidget("tabs", xmRowColumnWidgetClass,
|
||||
parent, XmNorientation, XmHORIZONTAL, XmNradioBehavior, True,
|
||||
XmNradioAlwaysOne, True, XmNspacing, 0, XmNmarginWidth, 0,
|
||||
XmNmarginHeight, 0, NULL), NULL);
|
||||
/* managed at once: the pane is realized here, so the frame and its
|
||||
* form follow their children (ShowLater) */
|
||||
frame = Stack(XtVaCreateManagedWidget("frame", xmFrameWidgetClass,
|
||||
parent, XmNrightAttachment, XmATTACH_FORM, NULL), tabRow);
|
||||
XtVaSetValues(frame, XmNtopOffset, 0, NULL);
|
||||
pages = XtVaCreateManagedWidget("pages", xmFormWidgetClass, frame, NULL);
|
||||
|
||||
page = Tab("TCP/IP", pages);
|
||||
MakeTcpIp(page);
|
||||
page = Tab("DNS", pages);
|
||||
MakeDns(page);
|
||||
if (it->kind == MCDE_NET_WIFI) {
|
||||
page = Tab("Wi-Fi", pages);
|
||||
(void) MakeWifi(page, it->name);
|
||||
}
|
||||
page = Tab(it->kind == MCDE_NET_WIFI ? "Card" : "Ethernet", pages);
|
||||
MakeEthernet(page, it);
|
||||
XtManageChild(tabPages[0]);
|
||||
XtManageChild(tabRow);
|
||||
|
||||
note = Stack(Text(parent, "note", r == MCDE_SYS_OK ? " " :
|
||||
mcde_sys_error()), frame);
|
||||
bottom = Stack(XtVaCreateManagedWidget("bottom", xmRowColumnWidgetClass,
|
||||
parent, XmNorientation, XmHORIZONTAL, XmNmarginWidth, 0,
|
||||
XmNmarginHeight, 0, XmNspacing, 10, NULL), note);
|
||||
if (!root) {
|
||||
Text(bottom, "locked", "Click the lock to make changes.");
|
||||
Button(bottom, "Unlock...", UnlockClicked, NULL);
|
||||
} else
|
||||
Text(bottom, "unlocked", "Unlocked: changes take effect at "
|
||||
"Apply Now.");
|
||||
XtSetSensitive(Button(bottom, "Apply Now", ApplyClicked, NULL),
|
||||
root && r == MCDE_SYS_OK);
|
||||
}
|
||||
|
||||
/* ---- the pane ---------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
Show(int which)
|
||||
{
|
||||
WidgetList kids;
|
||||
Cardinal n;
|
||||
|
||||
shown = which < 0 || which > nifs ? 0 : which;
|
||||
XtVaGetValues(holder, XmNchildren, &kids, XmNnumChildren, &n, NULL);
|
||||
while (n > 0) {
|
||||
Widget k = kids[--n];
|
||||
|
||||
if (k != showRow && k != showSep)
|
||||
XtDestroyWidget(k);
|
||||
}
|
||||
if (showMenu != NULL)
|
||||
XtVaSetValues(showMenu, XmNmenuHistory, showButtons[shown], NULL);
|
||||
if (shown == 0) {
|
||||
ReadInterfaces();
|
||||
MakeStatus(holder);
|
||||
} else
|
||||
MakeCard(holder, &ifs[shown - 1]);
|
||||
}
|
||||
|
||||
/* the first page once the pane is realized: built under an unrealized form
|
||||
* the containers kept the 16x16 of their empty start (Xt defers
|
||||
* change_managed until realization; measured with xwininfo on Xvfb) */
|
||||
static void
|
||||
ShowLater(XtPointer data, XtIntervalId *id)
|
||||
{
|
||||
(void) data;
|
||||
(void) id;
|
||||
if (holder != NULL)
|
||||
Show(0);
|
||||
}
|
||||
|
||||
static void
|
||||
ShowChosen(Widget w, XtPointer data, XtPointer call)
|
||||
{
|
||||
(void) w;
|
||||
(void) call;
|
||||
Show((int) (long) data);
|
||||
}
|
||||
|
||||
static void
|
||||
Gone(Widget w, XtPointer data, XtPointer call)
|
||||
{
|
||||
(void) w;
|
||||
(void) data;
|
||||
(void) call;
|
||||
showMenu = NULL;
|
||||
holder = NULL;
|
||||
showRow = showSep = NULL;
|
||||
}
|
||||
|
||||
Widget
|
||||
MakeNetwork(Widget parent)
|
||||
{
|
||||
Widget box = XtVaCreateWidget("network", xmFormWidgetClass, parent,
|
||||
NULL);
|
||||
Widget row, pull, sep;
|
||||
Arg a[1];
|
||||
char label[64];
|
||||
int i;
|
||||
|
||||
root = geteuid() == 0;
|
||||
showRow = showSep = NULL;
|
||||
ReadInterfaces();
|
||||
row = Stack(XtVaCreateManagedWidget("showRow", xmRowColumnWidgetClass,
|
||||
box, XmNorientation, XmHORIZONTAL, XmNmarginWidth, 0, NULL), NULL);
|
||||
Text(row, "showLabel", "Show:");
|
||||
pull = XmCreatePulldownMenu(row, "showMenu", NULL, 0);
|
||||
for (i = 0; i <= nifs; i++) {
|
||||
XmString s;
|
||||
|
||||
if (i == 0)
|
||||
snprintf(label, sizeof label, "Network Status");
|
||||
else
|
||||
Kind(&ifs[i - 1], label, sizeof label);
|
||||
s = XmStringCreateLocalized(label);
|
||||
showButtons[i] = XtVaCreateManagedWidget("show",
|
||||
xmPushButtonWidgetClass, pull, XmNlabelString, s, NULL);
|
||||
XmStringFree(s);
|
||||
XtAddCallback(showButtons[i], XmNactivateCallback, ShowChosen,
|
||||
(XtPointer) (long) i);
|
||||
}
|
||||
XtSetArg(a[0], XmNsubMenuId, pull);
|
||||
showMenu = XmCreateOptionMenu(row, "show", a, 1);
|
||||
XtUnmanageChild(XmOptionLabelGadget(showMenu));
|
||||
XtManageChild(showMenu);
|
||||
sep = Stack(XtVaCreateManagedWidget("sep", xmSeparatorWidgetClass, box,
|
||||
NULL), row);
|
||||
XtVaSetValues(sep, XmNrightAttachment, XmATTACH_FORM, NULL);
|
||||
showRow = row;
|
||||
showSep = sep;
|
||||
holder = box;
|
||||
XtAddCallback(box, XmNdestroyCallback, Gone, NULL);
|
||||
XtAppAddTimeOut(app, 0, ShowLater, NULL);
|
||||
return box;
|
||||
}
|
||||
|
||||
/* dtsystemsettings -renew-dhcp IF: what the terminal of "Renew DHCP Lease"
|
||||
* runs as root */
|
||||
int
|
||||
RenewDhcpCommand(const char *ifname)
|
||||
{
|
||||
int r = mcde_sys_net_renew(ifname);
|
||||
|
||||
printf("%s\n", r == MCDE_SYS_OK ? "The lease is renewed." :
|
||||
mcde_sys_error());
|
||||
printf("\nPress Return to close this window.\n");
|
||||
fflush(stdout);
|
||||
(void) getchar();
|
||||
return r == MCDE_SYS_OK ? 0 : 1;
|
||||
}
|
||||
@@ -11,8 +11,8 @@
|
||||
* _DT_SM_STM_PROTOCOL).
|
||||
*
|
||||
* The programs opened at login: one command a line in ~/.dt/login-items,
|
||||
* started by Xsession.d/0095.loginitems (programs/dtlogin/config) as
|
||||
* Xsession.d starts the bar. A line can be added or taken out here.
|
||||
* started by sessionetc.d/0095.loginitems (programs/dtlogin/config) as
|
||||
* sys.sessionetc starts the bar. A line can be added or taken out here.
|
||||
*
|
||||
* C99, POSIX, Xt and Motif only (ext/src/mcde/AGENTS.md).
|
||||
*/
|
||||
@@ -142,7 +142,7 @@ WriteItems(void)
|
||||
if ((fp = fopen(tmp, "w")) == NULL)
|
||||
return 0;
|
||||
fprintf(fp, "# the programs opened at login, one command a line\n"
|
||||
"# (MCDE System Settings, Startup; started by Xsession.d/"
|
||||
"# (MCDE System Settings, Startup; started by sessionetc.d/"
|
||||
"0095.loginitems)\n");
|
||||
for (i = 0; i < nitems; i++)
|
||||
fprintf(fp, "%s\n", items[i]);
|
||||
|
||||
@@ -39,8 +39,12 @@ void ServerResource(Display *dpy, const char *name, const char *class,
|
||||
/* the pane in desktop.c, opened on its desktop or its screen saver page */
|
||||
Widget MakeDesktop(Widget parent);
|
||||
Widget MakeScreenSaver(Widget parent);
|
||||
/* the Wi-Fi part of the Network pane (wifi.c); NULL without a Wi-Fi card */
|
||||
Widget MakeWifi(Widget parent);
|
||||
/* the Network pane (network.c); dtsystemsettings -renew-dhcp IF */
|
||||
Widget MakeNetwork(Widget parent);
|
||||
int RenewDhcpCommand(const char *ifname);
|
||||
/* the Wi-Fi tab of a card in the Network pane (wifi.c); IFNAME NULL: the
|
||||
* first Wi-Fi card, NULL returned without one */
|
||||
Widget MakeWifi(Widget parent, const char *ifname);
|
||||
/* dtsystemsettings -join-wifi IF [SSID in hex]: the terminal of "Join..." */
|
||||
int JoinWifiCommand(const char *ifname, const char *hexssid);
|
||||
/* the Backup pane (backup.c) */
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE.
|
||||
*
|
||||
* Part of the Network pane: for the first Wi-Fi card, the networks McdeSys
|
||||
* The Wi-Fi tab of a card in the Network pane: the networks McdeSys
|
||||
* finds (mcde_sys_wifi_scan) with their signal and whether they are
|
||||
* secured; "Scan" looks again, "Join..." joins the one chosen. Joining
|
||||
* changes the system (mcde_sys_wifi_join, root), so it runs in a terminal
|
||||
@@ -146,17 +146,20 @@ JoinClicked(Widget w, XtPointer data, XtPointer call)
|
||||
"opened.");
|
||||
}
|
||||
|
||||
/* the Wi-Fi part of the Network pane; NULL when there is no Wi-Fi card */
|
||||
/* the Wi-Fi tab of a card in the Network pane (IFNAME, or the first Wi-Fi
|
||||
* card when NULL); NULL when there is no Wi-Fi card */
|
||||
Widget
|
||||
MakeWifi(Widget parent)
|
||||
MakeWifi(Widget parent, const char *ifname)
|
||||
{
|
||||
McdeSysInterface ifs[32];
|
||||
int n = mcde_sys_interfaces(ifs, 32), i;
|
||||
int n = ifname != NULL ? 0 : mcde_sys_interfaces(ifs, 32), i;
|
||||
Widget box, row;
|
||||
Arg a[4];
|
||||
char text[96];
|
||||
|
||||
wifiIf[0] = '\0';
|
||||
if (ifname != NULL)
|
||||
snprintf(wifiIf, sizeof wifiIf, "%s", ifname);
|
||||
for (i = 0; i < n; i++)
|
||||
if (ifs[i].kind == MCDE_NET_WIFI) {
|
||||
snprintf(wifiIf, sizeof wifiIf, "%s", ifs[i].name);
|
||||
|
||||
@@ -79,10 +79,15 @@ FindMenu(const char *name)
|
||||
static Menu *
|
||||
NewMenu(const char *name)
|
||||
{
|
||||
static Menu spill; /* past MAXMENU: filled, never shown */
|
||||
Menu *m;
|
||||
|
||||
if (nmenus >= MAXMENU || (m = FindMenu(name)) != NULL)
|
||||
if ((m = FindMenu(name)) != NULL)
|
||||
return m;
|
||||
if (nmenus >= MAXMENU) {
|
||||
memset(&spill, 0, sizeof spill);
|
||||
return &spill;
|
||||
}
|
||||
m = &menus[nmenus++];
|
||||
memset(m, 0, sizeof *m);
|
||||
snprintf(m->name, sizeof m->name, "%s", name);
|
||||
@@ -380,10 +385,13 @@ PollPublished(XtPointer data, XtIntervalId *id)
|
||||
if (m == NULL)
|
||||
m = NewMenu("Selected");
|
||||
m->n = 0;
|
||||
/* kept before strtok_r cuts the text into lines: kept
|
||||
* after, it held the first line only and every poll
|
||||
* rebuilt the menu */
|
||||
snprintf(lastSelected, sizeof lastSelected, "%s", text);
|
||||
for (line = strtok_r(text, "\n", &save); line != NULL;
|
||||
line = strtok_r(NULL, "\n", &save))
|
||||
ParseEntry(m, line);
|
||||
snprintf(lastSelected, sizeof lastSelected, "%s", text);
|
||||
if (XtIsManaged(selectedSub) &&
|
||||
XtParent(selectedSub) != NULL &&
|
||||
XtIsManaged(XtParent(selectedSub)))
|
||||
|
||||
@@ -231,7 +231,8 @@ void SetupWmEwmh (void)
|
||||
XA__NET_WM_STATE_MAXIMIZED_HORZ,
|
||||
XA__NET_WM_STATE_FULLSCREEN,
|
||||
XA__NET_WM_STATE_ABOVE,
|
||||
XA__NET_WM_STATE_BELOW
|
||||
XA__NET_WM_STATE_BELOW,
|
||||
XA__NET_ACTIVE_WINDOW
|
||||
};
|
||||
|
||||
static char *atom_names[] = {
|
||||
@@ -248,7 +249,8 @@ void SetupWmEwmh (void)
|
||||
_XA__NET_WM_STATE_MAXIMIZED_HORZ,
|
||||
_XA__NET_WM_STATE_FULLSCREEN,
|
||||
_XA__NET_WM_STATE_ABOVE,
|
||||
_XA__NET_WM_STATE_BELOW
|
||||
_XA__NET_WM_STATE_BELOW,
|
||||
_XA__NET_ACTIVE_WINDOW
|
||||
};
|
||||
|
||||
Atom atoms[XtNumber(atom_names) + 1];
|
||||
@@ -269,6 +271,7 @@ void SetupWmEwmh (void)
|
||||
wmGD.xa__NET_WM_STATE_FULLSCREEN = atoms[XA__NET_WM_STATE_FULLSCREEN];
|
||||
wmGD.xa__NET_WM_STATE_ABOVE = atoms[XA__NET_WM_STATE_ABOVE];
|
||||
wmGD.xa__NET_WM_STATE_BELOW = atoms[XA__NET_WM_STATE_BELOW];
|
||||
wmGD.xa__NET_ACTIVE_WINDOW = atoms[XA__NET_ACTIVE_WINDOW];
|
||||
|
||||
for (scr = 0; scr < wmGD.numScreens; ++scr)
|
||||
{
|
||||
@@ -296,6 +299,35 @@ void SetupWmEwmh (void)
|
||||
XChangeProperty(DISPLAY, wmGD.Screens[scr].rootWindow,
|
||||
atoms[XA__NET_SUPPORTED], XA_ATOM, 32, PropModeReplace,
|
||||
(unsigned char *)&atoms[XA__NET_SUPPORTING_WM_CHECK],
|
||||
12);
|
||||
13);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Publishes the window with the keyboard focus as _NET_ACTIVE_WINDOW
|
||||
* on the root of every managed screen (EWMH), None when the focus is
|
||||
* on the root or on an icon. MCDE: the top bar reads it to show a
|
||||
* program's menus only while one of its windows is the active one.
|
||||
*
|
||||
* @param pCD The client that has the focus now, or NULL
|
||||
*/
|
||||
void SetNetActiveWindow (ClientData *pCD)
|
||||
{
|
||||
Window w = None;
|
||||
int scr;
|
||||
|
||||
if (wmGD.xa__NET_ACTIVE_WINDOW == None) return;
|
||||
|
||||
if (pCD && (pCD->clientState == NORMAL_STATE ||
|
||||
pCD->clientState == MAXIMIZED_STATE))
|
||||
w = pCD->client;
|
||||
|
||||
for (scr = 0; scr < wmGD.numScreens; ++scr)
|
||||
{
|
||||
if (!wmGD.Screens[scr].managed) continue;
|
||||
|
||||
XChangeProperty(DISPLAY, wmGD.Screens[scr].rootWindow,
|
||||
wmGD.xa__NET_ACTIVE_WINDOW, XA_WINDOW, 32,
|
||||
PropModeReplace, (unsigned char *)&w, 1);
|
||||
}
|
||||
}
|
||||
@@ -31,5 +31,6 @@ void ProcessNetWmFullscreenMonitors (ClientData *pCD,
|
||||
void ProcessNetWmState (ClientData *pCD, long action,
|
||||
Atom firstProperty, Atom secondProperty);
|
||||
void SetupWmEwmh (void);
|
||||
void SetNetActiveWindow (ClientData *pCD);
|
||||
|
||||
#endif
|
||||
@@ -139,6 +139,7 @@ extern Pixel FPselectcolor;
|
||||
#define _XA__NET_WM_STATE_FULLSCREEN "_NET_WM_STATE_FULLSCREEN"
|
||||
#define _XA__NET_WM_STATE_ABOVE "_NET_WM_STATE_ABOVE"
|
||||
#define _XA__NET_WM_STATE_BELOW "_NET_WM_STATE_BELOW"
|
||||
#define _XA__NET_ACTIVE_WINDOW "_NET_ACTIVE_WINDOW"
|
||||
|
||||
/* window manager exit value on fatal errors: */
|
||||
#define WM_ERROR_EXIT_VALUE 1
|
||||
@@ -1996,6 +1997,7 @@ typedef struct _WmGlobalData
|
||||
Atom xa__NET_WM_STATE_FULLSCREEN;
|
||||
Atom xa__NET_WM_STATE_ABOVE;
|
||||
Atom xa__NET_WM_STATE_BELOW;
|
||||
Atom xa__NET_ACTIVE_WINDOW;
|
||||
|
||||
/* atoms used for workspace management: */
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
*/
|
||||
|
||||
#include "WmGlobal.h"
|
||||
#include "WmEwmh.h"
|
||||
/*
|
||||
* include extern functions
|
||||
*/
|
||||
@@ -334,6 +335,8 @@ void SetKeyboardFocus (ClientData *pCD, long focusFlags)
|
||||
SetFocusIndication (pCD);
|
||||
}
|
||||
|
||||
SetNetActiveWindow (pCD);
|
||||
|
||||
} /* END OF FUNCTION SetKeyboardFocus */
|
||||
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
*/
|
||||
|
||||
#include "WmGlobal.h"
|
||||
#include "WmEwmh.h"
|
||||
#include "WmICCC.h"
|
||||
/*
|
||||
* include extern functions
|
||||
@@ -1280,7 +1281,10 @@ void WithdrawWindow (ClientData *pCD)
|
||||
if (wmGD.nextKeyboardFocus == pCD)
|
||||
wmGD.nextKeyboardFocus = NULL;
|
||||
if (wmGD.keyboardFocus == pCD)
|
||||
{
|
||||
wmGD.keyboardFocus = NULL;
|
||||
SetNetActiveWindow (NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Fix for 5325 - Delete reference by dirty stack
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
*/
|
||||
|
||||
#include "WmGlobal.h"
|
||||
#include "WmEwmh.h"
|
||||
#include "WmICCC.h"
|
||||
#include "WmProtocol.h"
|
||||
#include "WmIPC.h"
|
||||
@@ -492,6 +493,7 @@ static void SetupWindowStateWithEventMask (ClientData *pCD, int newState,
|
||||
{
|
||||
ClearFocusIndication (pCD, False /*no refresh*/);
|
||||
wmGD.keyboardFocus = NULL;
|
||||
SetNetActiveWindow (NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,6 +199,12 @@ main(int argc, char **argv)
|
||||
|
||||
XtAddEventHandler(area, NoEventMask, True, Message, NULL);
|
||||
sel = XInternAtom(dpy, "_MCDE_SOUND_SERVER", False);
|
||||
/* one per display, as dtbar: a second start (a login script and a
|
||||
* user's) leaves the running one alone */
|
||||
if (XGetSelectionOwner(dpy, sel) != None) {
|
||||
fprintf(stderr, "mcdesoundd: a server runs already\n");
|
||||
return 0;
|
||||
}
|
||||
XSetSelectionOwner(dpy, sel, service, CurrentTime);
|
||||
if (XGetSelectionOwner(dpy, sel) != service) {
|
||||
fprintf(stderr, "mcdesoundd: another server owns the selection\n");
|
||||
|
||||
Reference in new issue
Block a user