LordOS — a free, fast and secure GNU/Linux distribution based on Debian, with its own desktop environment: display server and Wayland compositor in C, a React UI engine on QuickJS, and private native apps.
C cdebiandesktop-environmentebpffirewalllandlocklinuxlinux-distributionopen-sourceprivacyquickjsraspberry-pi-5reactsecuritywaylandwayland-compositor
Honor the decoration mode apps ask for, live; window menu for apps with their own bar
Federico Pereira68f0461b01ec
diff --git a/assets/gtk/LordOS-dark/gtk-3.0/gtk.css b/assets/gtk/LordOS-dark/gtk-3.0/gtk.cssindex a81d0ed..2ea5558 100644--- a/assets/gtk/LordOS-dark/gtk-3.0/gtk.css+++ b/assets/gtk/LordOS-dark/gtk-3.0/gtk.css@@ -1,6 +1,6 @@-/* Tema GTK 3 de LordOS (LordOS-dark): Adwaita con los colores, la barra de título y los semáforos de- * LordOS. Lo elige el portal de LordOS (gtk-theme) según el modo; el acento de GTK 3 es fijo (azul):- * GTK 3 no tiene acento propio. GTK 4 y libadwaita toman el modo y el acento del portal. */+/* LordOS's GTK 3 theme (LordOS-dark): Adwaita with LordOS's colors, title bar and traffic lights. The+ * LordOS portal picks it (gtk-theme) by the mode; GTK 3 has no accent of its own, so it stays blue.+ * GTK 4 and libadwaita take the mode and the accent from the portal. */@import url("resource:///org/gtk/libgtk/theme/Adwaita/gtk-contained-dark.css");@define-color lordos_title_bg #2a2a2e;@define-color lordos_separator rgba(255, 255, 255, 0.08);@@ -11,21 +11,30 @@@define-color theme_base_color #26262b;@define-color theme_fg_color #f5f5f7;-/* Semáforos a la izquierda (el orden lo da LordOS por el portal: close,minimize,maximize:). */+/* Traffic lights like LordOS's default frame: 13 px circles, 8 px apart, vertically centered;+ * the order comes from LordOS through the portal and GSettings (close,minimize,maximize: on the+ * left; the Classic theme asks for :minimize,maximize,close). GTK sizes a title button by its+ * 16 px icon (Chromium and Firefox do the same when they draw their tab strip with this theme), so+ * the button stays 16 px and the circle is a 13 px radial gradient inside it; the icon is the+ * glyph shown on hover, as in LordOS's frame. */headerbar button.titlebutton,.titlebar button.titlebutton {- min-width: 14px; min-height: 14px; padding: 0; margin: 0 3px;- border-radius: 50%; border: none; box-shadow: none; background-image: none;- color: transparent; -gtk-icon-shadow: none; -gtk-icon-transform: scale(0.75);+ min-width: 16px; min-height: 16px; padding: 0; margin: 0 -1px 0 0;+ border-radius: 50%; border: none; box-shadow: none; background-color: transparent;+ color: transparent; -gtk-icon-shadow: none; -gtk-icon-transform: scale(0.62);}-headerbar button.titlebutton.close, .titlebar button.titlebutton.close { background-color: #ff5f57; }-headerbar button.titlebutton.minimize, .titlebar button.titlebutton.minimize { background-color: #febc2e; }-headerbar button.titlebutton.maximize, .titlebar button.titlebutton.maximize { background-color: #28c840; }+headerbar button.titlebutton.close, .titlebar button.titlebutton.close {+ background-image: radial-gradient(circle closest-side, #ff5f57 74%, transparent 81%); }+headerbar button.titlebutton.minimize, .titlebar button.titlebutton.minimize {+ background-image: radial-gradient(circle closest-side, #febc2e 74%, transparent 81%); }+headerbar button.titlebutton.maximize, .titlebar button.titlebutton.maximize {+ background-image: radial-gradient(circle closest-side, #28c840 74%, transparent 81%); }headerbar button.titlebutton:hover, .titlebar button.titlebutton:hover { color: rgba(0, 0, 0, 0.6); }-headerbar button.titlebutton:backdrop, .titlebar button.titlebutton:backdrop { background-color: @lordos_light_off; }+headerbar button.titlebutton:backdrop, .titlebar button.titlebutton:backdrop {+ background-image: radial-gradient(circle closest-side, @lordos_light_off 74%, transparent 81%); }headerbar button.titlebutton:backdrop:hover, .titlebar button.titlebutton:backdrop:hover { color: transparent; }-/* Marco y barra como las ventanas de LordOS */+/* The bar like LordOS windows */decoration { border-radius: 12px 12px 0 0; }headerbar, .titlebar { background-image: none; background-color: @lordos_title_bg; border-bottom: 1px solid @lordos_separator;box-shadow: none; min-height: 40px; }diff --git a/assets/gtk/LordOS/gtk-3.0/gtk.css b/assets/gtk/LordOS/gtk-3.0/gtk.cssindex 1f56e8a..6eefe21 100644--- a/assets/gtk/LordOS/gtk-3.0/gtk.css+++ b/assets/gtk/LordOS/gtk-3.0/gtk.css@@ -1,6 +1,6 @@-/* Tema GTK 3 de LordOS (LordOS): Adwaita con los colores, la barra de título y los semáforos de- * LordOS. Lo elige el portal de LordOS (gtk-theme) según el modo; el acento de GTK 3 es fijo (azul):- * GTK 3 no tiene acento propio. GTK 4 y libadwaita toman el modo y el acento del portal. */+/* LordOS's GTK 3 theme (LordOS): Adwaita with LordOS's colors, title bar and traffic lights. The+ * LordOS portal picks it (gtk-theme) by the mode; GTK 3 has no accent of its own, so it stays blue.+ * GTK 4 and libadwaita take the mode and the accent from the portal. */@import url("resource:///org/gtk/libgtk/theme/Adwaita/gtk-contained.css");@define-color lordos_title_bg #ececee;@define-color lordos_separator rgba(0, 0, 0, 0.1);@@ -11,21 +11,30 @@@define-color theme_base_color #ffffff;@define-color theme_fg_color #1c1c1e;-/* Semáforos a la izquierda (el orden lo da LordOS por el portal: close,minimize,maximize:). */+/* Traffic lights like LordOS's default frame: 13 px circles, 8 px apart, vertically centered;+ * the order comes from LordOS through the portal and GSettings (close,minimize,maximize: on the+ * left; the Classic theme asks for :minimize,maximize,close). GTK sizes a title button by its+ * 16 px icon (Chromium and Firefox do the same when they draw their tab strip with this theme), so+ * the button stays 16 px and the circle is a 13 px radial gradient inside it; the icon is the+ * glyph shown on hover, as in LordOS's frame. */headerbar button.titlebutton,.titlebar button.titlebutton {- min-width: 14px; min-height: 14px; padding: 0; margin: 0 3px;- border-radius: 50%; border: none; box-shadow: none; background-image: none;- color: transparent; -gtk-icon-shadow: none; -gtk-icon-transform: scale(0.75);+ min-width: 16px; min-height: 16px; padding: 0; margin: 0 -1px 0 0;+ border-radius: 50%; border: none; box-shadow: none; background-color: transparent;+ color: transparent; -gtk-icon-shadow: none; -gtk-icon-transform: scale(0.62);}-headerbar button.titlebutton.close, .titlebar button.titlebutton.close { background-color: #ff5f57; }-headerbar button.titlebutton.minimize, .titlebar button.titlebutton.minimize { background-color: #febc2e; }-headerbar button.titlebutton.maximize, .titlebar button.titlebutton.maximize { background-color: #28c840; }+headerbar button.titlebutton.close, .titlebar button.titlebutton.close {+ background-image: radial-gradient(circle closest-side, #ff5f57 74%, transparent 81%); }+headerbar button.titlebutton.minimize, .titlebar button.titlebutton.minimize {+ background-image: radial-gradient(circle closest-side, #febc2e 74%, transparent 81%); }+headerbar button.titlebutton.maximize, .titlebar button.titlebutton.maximize {+ background-image: radial-gradient(circle closest-side, #28c840 74%, transparent 81%); }headerbar button.titlebutton:hover, .titlebar button.titlebutton:hover { color: rgba(0, 0, 0, 0.6); }-headerbar button.titlebutton:backdrop, .titlebar button.titlebutton:backdrop { background-color: @lordos_light_off; }+headerbar button.titlebutton:backdrop, .titlebar button.titlebutton:backdrop {+ background-image: radial-gradient(circle closest-side, @lordos_light_off 74%, transparent 81%); }headerbar button.titlebutton:backdrop:hover, .titlebar button.titlebutton:backdrop:hover { color: transparent; }-/* Marco y barra como las ventanas de LordOS */+/* The bar like LordOS windows */decoration { border-radius: 12px 12px 0 0; }headerbar, .titlebar { background-image: none; background-color: @lordos_title_bg; border-bottom: 1px solid @lordos_separator;box-shadow: none; min-height: 40px; }diff --git a/sdk/wayland.js b/sdk/wayland.jsindex 2f9a854..a29c433 100644--- a/sdk/wayland.js+++ b/sdk/wayland.js@@ -2,9 +2,10 @@// de lord-server (server/src/wl). Para el tema son ventanas como las de las apps LordOS: entran// en el gestor con la app interna 'linux' y su id es 'linux#<superficie>'.//-// Las que piden decoración del servidor (Qt, foot) llevan el marco del tema; las que dibujan-// el suyo (GTK) van "sin marco": args.csd = true, y el tema dibuja solo el contenido. Mover y-// cambiar el tamaño desde la barra de una app GTK llega como pedido del compositor.+// Those that ask for server-side decoration (Qt, foot) get the theme's frame; those that draw their+// own (GTK, Chromium and Firefox with their own bar) go "frameless": args.csd = true, and the theme+// draws only the content. The app may switch while open ('deco'). Moving, resizing and the window+// menu from the app's own bar arrive as requests from the compositor.import { createElement as h } from 'react';import { View, Text, Surface, addListener, onShellKeyboard, shellHasKeyboard } from '@lordos/runtime';import { windows, wm, registerBuiltinApp, windowChrome, pointerWorkArea, getApp } from './windows.js';@@ -95,6 +96,12 @@ globalThis.__lordWayland = (sid, type, d = {}) => {case 'maximize': if (win && !win.maximized) wm.toggleMaximize(id); break;case 'unmaximize': if (win && win.maximized) wm.toggleMaximize(id); break;case 'minimize': if (win) wm.minimize(id); break;+ // The app switched who draws the frame while open (Chromium's «Use system title bar and borders»,+ // Firefox's «Title Bar»): same window, place, size, maximized state, focus and Dock entry; only the+ // theme's frame comes or goes (the content area grows or shrinks by it, and the app is configured).+ case 'deco': if (win && !!win.args?.csd !== !!d.csd) { if (win.windowMenu) wm.closeWindowMenu(id); wm.setArgs(id, { csd: !!d.csd }); } break;+ // right click on the app's own bar (xdg_toplevel.show_window_menu): the theme's window menu+ case 'menu': if (win) { wm.focus(id); wm.showWindowMenu(id, d.x, d.y); } break;default: break;}};diff --git a/sdk/windows.js b/sdk/windows.jsindex 9c52e77..9ba9d53 100644--- a/sdk/windows.js+++ b/sdk/windows.js@@ -322,6 +322,12 @@ export const wm = {// comes out black in screenshots, recordings and remote desktop (docs/MEDIA.md). Used, for// example, by a password app.setProtected: (id, on = true) => patch(id, { protected: !!on }),+ // Merges into a window's args (a Linux app switching between the theme's frame and its own, args.csd).+ setArgs: (id, a) => windows.set((ws) => ws.map((w) => (w.id === id ? { ...w, args: { ...(w.args || {}), ...a } } : w))),+ // The window menu at a screen point (a Linux app with its own bar asked for it,+ // xdg_toplevel.show_window_menu): the theme draws it from w.windowMenu; null closes it.+ showWindowMenu: (id, x, y) => patch(id, { windowMenu: { x: Math.round(x), y: Math.round(y) } }),+ closeWindowMenu: (id) => patch(id, { windowMenu: null }),// Fullscreen for a LordOS app (Player, Photos): the SDK draws it above everything,// without the theme's frame. Esc or wm.setFullscreen(id, false) goes back.setFullscreen: (id, on = true) => windows.set((ws) => ws.map((w) => (w.id === id ? { ...w, fullscreen: !!on, minimized: false } : w))),diff --git a/server/Makefile b/server/Makefileindex 60de4db..482414d 100644--- a/server/Makefile+++ b/server/Makefile@@ -397,6 +397,11 @@ endef$(foreach p,$(CLIENT_PROTO),$(eval $(call wl_client_proto,$(p))))build/dmabuf-client: tests/dmabuf_client.c $(CLIENT_GEN)$(CC) $(CFLAGS) -D_GNU_SOURCE -Ibuild/gen $(WARN) -std=c11 -o $@ tests/dmabuf_client.c $(filter %.c,$(CLIENT_GEN)) -lwayland-client+# Who draws the frame: xdg-decoration and KDE's server-decoration modes, also switched live+# (tests/deco_client.c; run inside a session: WAYLAND_DISPLAY=wayland-0 build/deco-client)+build/deco-client: tests/deco_client.c $(CLIENT_GEN)+ $(CC) $(CFLAGS) -D_GNU_SOURCE -Ibuild/gen $(WARN) -std=c11 -o $@ tests/deco_client.c $(filter %.c,$(CLIENT_GEN)) -lwayland-client+# Clipboard and primary-selection offers bound to their selection (tests/xwayland/clip_offers.sh, docs/WAYLAND.md)build/clip-offers: tests/clip_offers.c $(CLIENT_GEN)$(CC) $(CFLAGS) -D_GNU_SOURCE -Ibuild/gen $(WARN) -std=c11 -o $@ tests/clip_offers.c $(filter %.c,$(CLIENT_GEN)) -lwayland-clientdiff --git a/server/src/main.c b/server/src/main.cindex 7ef4ce4..d04874f 100644--- a/server/src/main.c+++ b/server/src/main.c@@ -1484,6 +1484,7 @@ static void switch_theme(const char *current) {ui_reset();js_init(current);}+ wl_remap_all(); /* Linux app windows stay connected: they come back in the new theme */}/* ---- Settings → Displays and the other hardware pages (src/hw, docs/SETTINGS.md) ---- */diff --git a/server/src/wl/wl.c b/server/src/wl/wl.cindex 8e2cdef..fdc0948 100644--- a/server/src/wl/wl.c+++ b/server/src/wl/wl.c@@ -616,6 +616,7 @@ static void surface_gone(struct wl_resource *r) {if (s->viewport) wl_resource_set_user_data(s->viewport, NULL);if (s->frac) wl_resource_set_user_data(s->frac, NULL);if (s->kde) wl_resource_set_user_data(s->kde, NULL);+ if (s->deco) wl_resource_set_user_data(s->deco, NULL);if (s->node) damage_node(s);if (fs_surf == s) { fs_surf = NULL; ui.dirty = 1; damage_add((Box){ 0, 0, ui.width, ui.height }); }if (cursor_surf == s) { cursor_surf = NULL; cursor_mode = 0; cursor_gen++; }@@ -1621,8 +1622,14 @@ static void top_app_id(struct wl_client *c, struct wl_resource *r, const char *aSurf *s = wl_resource_get_user_data(r);if (s) snprintf(s->app_id, sizeof s->app_id, "%s", a);}+/* The app's own bar asked for the window menu (right click on Chromium's tab strip, a GTK+ * headerbar): JS gets where, in screen coordinates, and the theme shows its window menu there. */static void top_menu(struct wl_client *c, struct wl_resource *r, struct wl_resource *seat, uint32_t serial, int32_t x, int32_t y) {- (void)c; (void)r; (void)seat; (void)serial; (void)x; (void)y;+ (void)c; (void)seat; (void)serial;+ Surf *s = wl_resource_get_user_data(r);+ float ox, oy;+ if (!s || !s->mapped || !origin(s, &ox, &oy)) return;+ emit(s, "menu", "{\"x\":%.0f,\"y\":%.0f}", ox + (float)x, oy + (float)y);}static void top_move(struct wl_client *c, struct wl_resource *r, struct wl_resource *seat, uint32_t serial) {(void)c; (void)seat; (void)serial;@@ -1803,20 +1810,44 @@ static void bind_wm_base(struct wl_client *c, void *data, uint32_t ver, uint32_twl_resource_set_implementation(r, &wm_base_impl, NULL, NULL);}-/* ---- xdg-decoration: server decoration is requested (the theme's frame) ---- */+/* ---- xdg-decoration: the app picks who draws the frame ----+ * We prefer the theme's frame (server side) and say so in the first configure, but the client's+ * choice wins: set_mode(CLIENT_SIDE) means the app draws its own bar and buttons (Chromium with+ * «Use system title bar and borders» off, GTK 4). unset_mode and SERVER_SIDE give the theme's frame.+ * A change after the window is mapped (the user flips Chromium's switch) goes to JS as «deco», and+ * the theme switches that window between its frame and the frameless presentation (sdk/wayland.js). */++static void set_csd(Surf *s, int csd) {+ csd = !!csd;+ if (s->csd == csd) return;+ s->csd = csd;+ if (s->mapped && (s->top || s->xw)) emit(s, "deco", "{\"csd\":%s}", csd ? "true" : "false");+}++/* What the compositor answers to a requested xdg-decoration mode: what the app asked for. */+static uint32_t deco_answer(uint32_t requested) {+ return requested == ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE ? ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE+ : ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE;+}static void deco_destroy(struct wl_client *c, struct wl_resource *r) { (void)c; wl_resource_destroy(r); }static void deco_mode(struct wl_client *c, struct wl_resource *r, uint32_t mode) {- (void)c; (void)mode;+ (void)c;Surf *s = wl_resource_get_user_data(r);- zxdg_toplevel_decoration_v1_send_configure(r, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);- if (s) { s->csd = 0; if (s->sent_configure) send_toplevel_configure(s); }+ uint32_t m = deco_answer(mode);+ zxdg_toplevel_decoration_v1_send_configure(r, m);+ if (!s) return;+ set_csd(s, m == ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE);+ if (s->sent_configure) send_toplevel_configure(s); /* the decoration configure needs an xdg_surface.configure */}-static void deco_unset(struct wl_client *c, struct wl_resource *r) { deco_mode(c, r, 0); }+static void deco_unset(struct wl_client *c, struct wl_resource *r) { deco_mode(c, r, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); }static const struct zxdg_toplevel_decoration_v1_interface deco_impl = { .destroy = deco_destroy, .set_mode = deco_mode, .unset_mode = deco_unset };static void deco_gone(struct wl_resource *r) {Surf *s = wl_resource_get_user_data(r);- if (s) s->deco = NULL;+ if (!s || s->deco != r) return;+ s->deco = NULL;+ /* protocol: without the object the app draws its own frame again (unless GTK 3 asked us via KDE's) */+ if (s->top) set_csd(s, !s->kde_ssd);}static void decm_destroy(struct wl_client *c, struct wl_resource *r) { (void)c; wl_resource_destroy(r); }static void decm_get(struct wl_client *c, struct wl_resource *r, uint32_t id, struct wl_resource *toplevel) {@@ -1824,7 +1855,7 @@ static void decm_get(struct wl_client *c, struct wl_resource *r, uint32_t id, ststruct wl_resource *d = wl_resource_create(c, &zxdg_toplevel_decoration_v1_interface, wl_resource_get_version(r), id);if (!d) { wl_client_post_no_memory(c); return; }wl_resource_set_implementation(d, &deco_impl, s, deco_gone);- if (s) { s->deco = d; s->csd = 0; }+ if (s) { s->deco = d; set_csd(s, 0); }zxdg_toplevel_decoration_v1_send_configure(d, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);}static const struct zxdg_decoration_manager_v1_interface decm_impl = { .destroy = decm_destroy, .get_toplevel_decoration = decm_get };@@ -1867,7 +1898,7 @@ static void kde_request_mode(struct wl_client *c, struct wl_resource *r, uint32_wl_resource_post_event(r, 0, ssd ? KDE_DECO_SERVER : KDE_DECO_CLIENT);if (!s) return;s->kde_ssd = ssd;- if (s->role == R_TOPLEVEL && !s->deco) s->csd = !ssd;+ if (s->role == R_TOPLEVEL && !s->deco) set_csd(s, !ssd); /* live too: Firefox's «Title Bar» switch */}static const struct kde_deco_impl kde_deco_impl = { kde_release, kde_request_mode };static void kde_gone(struct wl_resource *r) {@@ -1898,6 +1929,35 @@ static void geometry(Surf *s, int *w, int *h) {*h = s->has_geom && s->gh > 0 ? s->gh : s->lh;}+/* JS learns about a window: title, app id, content size and whether it draws its own frame. */+static void emit_map(Surf *s, int w, int h) {+ char t[520], a[260];+ json_str(t, sizeof t, s->title);+ json_str(a, sizeof a, s->app_id);+ if (s->xw) { /* X11: WM_CLASS class, and its instance for the .desktop match */+ char alt[260];+ json_str(alt, sizeof alt, s->app_alt);+ emit(s, "map", "{\"title\":\"%s\",\"appId\":\"%s\",\"appAlt\":\"%s\",\"x11\":true,\"width\":%d,\"height\":%d,\"csd\":%s}",+ t, a, alt, w, h, s->csd ? "true" : "false");+ } else+ emit(s, "map", "{\"title\":\"%s\",\"appId\":\"%s\",\"width\":%d,\"height\":%d,\"csd\":%s}", t, a, w, h, s->csd ? "true" : "false");+}++/* A new JS context (the theme was switched live): the windows that are still mapped are announced+ * again, with their maximized state, so they come back in the new theme instead of staying+ * connected but invisible. Their node belongs to the old tree: forgotten until the next paint. */+void wl_remap_all(void) {+ for (int i = 0; i < MAX_SURF; i++) {+ Surf *s = surfs[i];+ if (!s || s->role != R_TOPLEVEL || !s->mapped) continue;+ int w, h;+ geometry(s, &w, &h);+ s->node = 0;+ emit_map(s, w, h);+ if (s->maximized) emit(s, "maximize", "{}");+ }+}+static void surface_commit_role(Surf *s) {if (s->role == R_TOPLEVEL && s->content && s->lw > 0) { /* how the app renders for HiDPI: once per change */int ratio = s->w * 100 / s->lw;@@ -1915,16 +1975,7 @@ static void surface_commit_role(Surf *s) {geometry(s, &w, &h);if (s->content && !s->mapped) {s->mapped = 1;- char t[520], a[260];- json_str(t, sizeof t, s->title);- json_str(a, sizeof a, s->app_id);- if (s->xw) { /* X11: WM_CLASS class, and its instance for the .desktop match */- char alt[260];- json_str(alt, sizeof alt, s->app_alt);- emit(s, "map", "{\"title\":\"%s\",\"appId\":\"%s\",\"appAlt\":\"%s\",\"x11\":true,\"width\":%d,\"height\":%d,\"csd\":%s}",- t, a, alt, w, h, s->csd ? "true" : "false");- } else- emit(s, "map", "{\"title\":\"%s\",\"appId\":\"%s\",\"width\":%d,\"height\":%d,\"csd\":%s}", t, a, w, h, s->csd ? "true" : "false");+ emit_map(s, w, h);s->conf_w = w;s->conf_h = h;} else if (!s->content && s->mapped) {diff --git a/server/src/wl/wl.h b/server/src/wl/wl.hindex b4b1015..d0eb46f 100644--- a/server/src/wl/wl.h+++ b/server/src/wl/wl.h@@ -40,6 +40,7 @@ void wl_set_state(int id, int maximized, int fullscreen);void wl_set_minimized(int id, int minimized); /* X11 windows: iconic and at the bottom of X's stack */int wl_count(void);void wl_output_resized(void); /* headless: one display of ui.width × ui.height */+void wl_remap_all(void); /* a new JS context (theme switched): announce the open windows again *//* The displays (docs/DISPLAYS.md): one wl_output (+ xdg-output) each. x, y, w, h: logical rect in the* global space; pw × ph: physical mode; scale: percent (wl_output.scale is its ceiling, the exact* one goes by fractional-scale-v1). Surfaces get enter/leave and their preferred scale. */diff --git a/server/tests/deco_client.c b/server/tests/deco_client.cnew file mode 100644index 0000000..eb71a9b--- /dev/null+++ b/server/tests/deco_client.c@@ -0,0 +1,225 @@+/* deco_client.c — who draws a window's frame (docs/WAYLAND.md, "Frame and colors"): run inside a+ * LordOS session, it checks that lord-server honors the mode an app asks for.+ *+ * xdg-decoration: the first configure prefers SERVER_SIDE; set_mode(CLIENT_SIDE) is answered+ * CLIENT_SIDE (also after the window is mapped, followed by an xdg_surface.configure);+ * unset_mode and set_mode(SERVER_SIDE) give SERVER_SIDE back.+ * org_kde_kwin_server_decoration (GTK 3): default «server», request_mode(client) → client.+ *+ * WAYLAND_DISPLAY=wayland-0 build/deco-client (prints ok/FAIL per check, exit 1 on a failure)+ * WAYLAND_DISPLAY=wayland-0 build/deco-client hold 6 (then keeps a mapped window and switches+ * its mode every 1.5 s, to watch the theme) */+#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include <unistd.h>+#include <sys/mman.h>+#include <time.h>+#include <wayland-client.h>+#include "client/xdg-shell-client-protocol.h"+#include "client/xdg-decoration-unstable-v1-client-protocol.h"++/* org_kde_kwin_server_decoration: the same hand-written tables as server/src/wl/wl.c */+static const struct wl_interface kde_deco_interface;+static const struct wl_interface *kde_types[] = { NULL, &kde_deco_interface, &wl_surface_interface };+static const struct wl_message kde_mgr_requests[] = { { "create", "no", kde_types + 1 } };+static const struct wl_message kde_mgr_events[] = { { "default_mode", "u", kde_types } };+static const struct wl_interface kde_mgr_interface = { "org_kde_kwin_server_decoration_manager", 1, 1, kde_mgr_requests, 1, kde_mgr_events };+static const struct wl_message kde_deco_requests[] = { { "release", "", kde_types }, { "request_mode", "u", kde_types } };+static const struct wl_message kde_deco_events[] = { { "mode", "u", kde_types } };+static const struct wl_interface kde_deco_interface = { "org_kde_kwin_server_decoration", 1, 2, kde_deco_requests, 1, kde_deco_events };+enum { KDE_NONE = 0, KDE_CLIENT = 1, KDE_SERVER = 2 };++static struct wl_compositor *comp;+static struct wl_shm *shm;+static struct xdg_wm_base *wmbase;+static struct zxdg_decoration_manager_v1 *decm;+static struct wl_proxy *kdem;+static int fails, checks;++static void check(const char *what, long got, long want) {+ checks++;+ if (got == want) printf("ok %s\n", what);+ else { fails++; printf("FAIL %s: got %ld, want %ld\n", what, got, want); }+}++static void reg_global(void *d, struct wl_registry *r, uint32_t name, const char *iface, uint32_t ver) {+ (void)d;+ if (!strcmp(iface, wl_compositor_interface.name)) comp = wl_registry_bind(r, name, &wl_compositor_interface, 4);+ else if (!strcmp(iface, wl_shm_interface.name)) shm = wl_registry_bind(r, name, &wl_shm_interface, 1);+ else if (!strcmp(iface, xdg_wm_base_interface.name)) wmbase = wl_registry_bind(r, name, &xdg_wm_base_interface, ver < 5 ? ver : 5);+ else if (!strcmp(iface, zxdg_decoration_manager_v1_interface.name)) decm = wl_registry_bind(r, name, &zxdg_decoration_manager_v1_interface, 1);+ else if (!strcmp(iface, kde_mgr_interface.name)) kdem = wl_registry_bind(r, name, &kde_mgr_interface, 1);+}+static void reg_remove(void *d, struct wl_registry *r, uint32_t n) { (void)d; (void)r; (void)n; }+static const struct wl_registry_listener reg_l = { reg_global, reg_remove };++static void ping(void *d, struct xdg_wm_base *b, uint32_t serial) { (void)d; xdg_wm_base_pong(b, serial); }+static const struct xdg_wm_base_listener wm_l = { ping };++typedef struct {+ struct wl_surface *surf;+ struct xdg_surface *xs;+ struct xdg_toplevel *top;+ struct zxdg_toplevel_decoration_v1 *deco;+ int mode, mode_events, xs_configures, w, h, closed;+ uint32_t serial;+} Win;++static void xs_configure(void *d, struct xdg_surface *xs, uint32_t serial) {+ Win *w = d;+ w->xs_configures++;+ w->serial = serial;+ xdg_surface_ack_configure(xs, serial);+}+static const struct xdg_surface_listener xs_l = { xs_configure };+static void top_configure(void *d, struct xdg_toplevel *t, int32_t w, int32_t h, struct wl_array *st) {+ (void)t; (void)st;+ Win *win = d;+ if (w > 0) win->w = w;+ if (h > 0) win->h = h;+}+static void top_close(void *d, struct xdg_toplevel *t) { (void)t; ((Win *)d)->closed = 1; }+static void top_bounds(void *d, struct xdg_toplevel *t, int32_t w, int32_t h) { (void)d; (void)t; (void)w; (void)h; }+static void top_caps(void *d, struct xdg_toplevel *t, struct wl_array *c) { (void)d; (void)t; (void)c; }+static const struct xdg_toplevel_listener top_l = { top_configure, top_close, top_bounds, top_caps };+static void deco_configure(void *d, struct zxdg_toplevel_decoration_v1 *z, uint32_t mode) {+ (void)z;+ Win *w = d;+ w->mode = (int)mode;+ w->mode_events++;+}+static const struct zxdg_toplevel_decoration_v1_listener deco_l = { deco_configure };++static int kde_mode = -1, kde_default = -1;+static void kde_mode_ev(void *d, struct wl_proxy *p, uint32_t m) { (void)d; (void)p; kde_mode = (int)m; }+static void kde_default_ev(void *d, struct wl_proxy *p, uint32_t m) { (void)d; (void)p; kde_default = (int)m; }+static void (*kde_deco_listener[])(void *, struct wl_proxy *, uint32_t) = { kde_mode_ev };+static void (*kde_mgr_listener[])(void *, struct wl_proxy *, uint32_t) = { kde_default_ev };++/* a solid buffer: blue for "my own frame" (client side), grey for "the theme's frame" */+static void draw(Win *w, int csd) {+ int W = w->w > 0 ? w->w : 360, H = w->h > 0 ? w->h : 220, stride = W * 4, size = stride * H;+ int fd = memfd_create("deco-client", MFD_CLOEXEC);+ if (fd < 0 || ftruncate(fd, size) < 0) { perror("memfd"); exit(2); }+ uint32_t *px = mmap(NULL, (size_t)size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);+ if (px == MAP_FAILED) { perror("mmap"); exit(2); }+ for (int y = 0; y < H; y++)+ for (int x = 0; x < W; x++) px[y * W + x] = csd ? (y < 36 ? 0xff1e5aa8u : 0xffdfe8f5u) : 0xffe6e6e6u;+ struct wl_shm_pool *pool = wl_shm_create_pool(shm, fd, size);+ struct wl_buffer *b = wl_shm_pool_create_buffer(pool, 0, W, H, stride, WL_SHM_FORMAT_XRGB8888);+ wl_shm_pool_destroy(pool);+ close(fd);+ munmap(px, (size_t)size);+ wl_surface_attach(w->surf, b, 0, 0);+ wl_surface_damage(w->surf, 0, 0, W, H);+ wl_surface_commit(w->surf);+}++static Win *new_window(struct wl_display *dpy, const char *title) {+ Win *w = calloc(1, sizeof *w);+ w->mode = -1;+ w->surf = wl_compositor_create_surface(comp);+ w->xs = xdg_wm_base_get_xdg_surface(wmbase, w->surf);+ xdg_surface_add_listener(w->xs, &xs_l, w);+ w->top = xdg_surface_get_toplevel(w->xs);+ xdg_toplevel_add_listener(w->top, &top_l, w);+ xdg_toplevel_set_title(w->top, title);+ xdg_toplevel_set_app_id(w->top, "deco-client");+ if (decm) {+ w->deco = zxdg_decoration_manager_v1_get_toplevel_decoration(decm, w->top);+ zxdg_toplevel_decoration_v1_add_listener(w->deco, &deco_l, w);+ }+ wl_surface_commit(w->surf);+ wl_display_roundtrip(dpy);+ return w;+}++static void sleep_ms(int ms) { struct timespec t = { ms / 1000, (ms % 1000) * 1000000L }; nanosleep(&t, NULL); }++int main(int argc, char **argv) {+ struct wl_display *dpy = wl_display_connect(NULL);+ if (!dpy) { fprintf(stderr, "deco-client: no Wayland display\n"); return 2; }+ struct wl_registry *reg = wl_display_get_registry(dpy);+ wl_registry_add_listener(reg, ®_l, NULL);+ wl_display_roundtrip(dpy);+ if (!comp || !shm || !wmbase) { fprintf(stderr, "deco-client: missing core globals\n"); return 2; }+ xdg_wm_base_add_listener(wmbase, &wm_l, NULL);+ check("xdg-decoration manager offered", decm != NULL, 1);+ check("KDE server-decoration manager offered", kdem != NULL, 1);+ if (kdem) { wl_proxy_add_listener(kdem, (void (**)(void))kde_mgr_listener, NULL); wl_display_roundtrip(dpy); }+ check("KDE default mode is server", kde_default, KDE_SERVER);+ if (!decm) return 1;++ /* before mapping */+ Win *a = new_window(dpy, "deco-client A");+ check("first configure prefers server side", a->mode, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);+ zxdg_toplevel_decoration_v1_set_mode(a->deco, ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE);+ wl_display_roundtrip(dpy);+ check("set_mode(client) answered client", a->mode, ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE);+ zxdg_toplevel_decoration_v1_unset_mode(a->deco);+ wl_display_roundtrip(dpy);+ check("unset_mode answered server", a->mode, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);+ zxdg_toplevel_decoration_v1_set_mode(a->deco, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);+ wl_display_roundtrip(dpy);+ check("set_mode(server) answered server", a->mode, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);++ /* mapped, then switched live */+ draw(a, 0);+ wl_display_roundtrip(dpy);+ sleep_ms(300);+ wl_display_roundtrip(dpy);+ int before = a->xs_configures;+ zxdg_toplevel_decoration_v1_set_mode(a->deco, ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE);+ wl_display_roundtrip(dpy);+ check("mapped: set_mode(client) answered client", a->mode, ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE);+ check("mapped: followed by an xdg_surface.configure", a->xs_configures > before, 1);+ draw(a, 1);+ wl_display_roundtrip(dpy);+ sleep_ms(400); /* the theme drops its frame: the content area grows → configure */+ wl_display_roundtrip(dpy);+ printf("info content after client side: %dx%d\n", a->w, a->h);+ zxdg_toplevel_decoration_v1_set_mode(a->deco, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);+ wl_display_roundtrip(dpy);+ check("mapped: back to server", a->mode, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);+ draw(a, 0);+ wl_display_roundtrip(dpy);+ sleep_ms(400);+ wl_display_roundtrip(dpy);+ printf("info content after server side: %dx%d\n", a->w, a->h);++ /* GTK 3's protocol */+ if (kdem) {+ struct wl_surface *s2 = wl_compositor_create_surface(comp);+ struct wl_proxy *kd = wl_proxy_marshal_constructor(kdem, 0, &kde_deco_interface, NULL, s2);+ wl_proxy_add_listener(kd, (void (**)(void))kde_deco_listener, NULL);+ wl_display_roundtrip(dpy);+ check("KDE: new decoration says server", kde_mode, KDE_SERVER);+ wl_proxy_marshal(kd, 1, (uint32_t)KDE_CLIENT);+ wl_display_roundtrip(dpy);+ check("KDE: request_mode(client) answered client", kde_mode, KDE_CLIENT);+ wl_proxy_marshal(kd, 1, (uint32_t)KDE_SERVER);+ wl_display_roundtrip(dpy);+ check("KDE: request_mode(server) answered server", kde_mode, KDE_SERVER);+ wl_proxy_marshal(kd, 0);+ wl_proxy_destroy(kd);+ wl_surface_destroy(s2);+ }++ if (argc >= 3 && !strcmp(argv[1], "hold")) {+ int secs = atoi(argv[2]), csd = 0;+ for (int i = 0; i < secs * 2 / 3 + 1 && !a->closed; i++) {+ sleep_ms(1500);+ csd = !csd;+ zxdg_toplevel_decoration_v1_set_mode(a->deco, csd ? ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE : ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);+ wl_display_roundtrip(dpy);+ draw(a, csd);+ wl_display_roundtrip(dpy);+ printf("hold: %s, %dx%d\n", csd ? "client side" : "server side", a->w, a->h);+ fflush(stdout);+ }+ }+ printf("%d checks, %d failed\n", checks, fails);+ wl_display_disconnect(dpy);+ return fails ? 1 : 0;+}diff --git a/themes/README.md b/themes/README.mdindex 7c8a597..48e2de4 100644--- a/themes/README.md+++ b/themes/README.md@@ -55,7 +55,11 @@ were open come back in the new theme. The choice is saved and respected on the n- Linux app windows (Wayland) arrive as windows of the internal app `linux`: if`win.args.csd` is true the app draws its own frame and the theme shows only `<AppHost>`;and `configureWindows({ chrome: { w, h } })` says how much the theme's frame adds (borders +- title bar) so they open at the size they asked for (see `docs/WAYLAND.md`).+ title bar) so they open at the size they asked for (see `docs/WAYLAND.md`). `args.csd` can+ change while the window is open (a browser's title bar switch): render from it every time.+ When such an app asks for the window menu (right click on its own bar), `win.windowMenu` is+ `{ x, y }`: draw the theme's window menu there and call `wm.closeWindowMenu(win.id)` when it+ closes.4. `npm run build` and pick it in Settings → Themes.Images (`<Image src="assets/...">`) are resolved relative to the theme's folder.diff --git a/themes/classic/components/Window.jsx b/themes/classic/components/Window.jsxindex d468456..071a77e 100644--- a/themes/classic/components/Window.jsx+++ b/themes/classic/components/Window.jsx@@ -4,7 +4,7 @@// offers the snap layouts (halves, thirds, quarters; sdk/windows.js "Snapping"). Moving and// resizing are done in C (<WindowShell>, wm.beginMove; docs/WINDOWS.md); a maximized window is// dragged out of its place by JS, and snaps where it is dropped.-import { View, Text, Layer, addListener, wm, AppHost, windowTitle, WindowShell, windowIcon, snapZoneAt, t as tr } from '@lordos/sdk';+import { View, Text, Layer, addListener, wm, AppHost, windowTitle, WindowShell, windowIcon, snapZoneAt, screen, t as tr } from '@lordos/sdk';import { useEffect, useRef, useState } from 'react';import { MinimizeGlyph, MaximizeGlyph, RestoreGlyph, CloseGlyph, LayoutGlyph } from '../glyphs.jsx';import { Menu } from './Menu.jsx';@@ -20,13 +20,18 @@ const LAYOUTS = [{ cells: [[0, 0, 0.5, 0.5], [0.5, 0, 0.5, 0.5], [0, 0.5, 0.5, 0.5], [0.5, 0.5, 0.5, 0.5]], zones: ['top-left', 'top-right', 'bottom-left', 'bottom-right'] },];+const LAYOUTS_W = 4 * 72 + 3 * 8 + 24;++// at: { x, y } under the maximize button (the flyout ends there), or { left, y } where it starts+// (opened from the window menu of an app that draws its own bar).function SnapLayouts({ t, win, at, onEnter, onLeave, onDone }) {const [hover, setHover] = useState(null); // [layout, cell]- const W = 4 * 72 + 3 * 8 + 24;+ const W = LAYOUTS_W;+ const left = at.left != null ? Math.min(at.left, screen.width - W - 6) : at.x - W + BTN_W * 1.5;return (<Layer name="popover"><View onMouseEnter={onEnter} onMouseLeave={onLeave}- style={{ position: 'absolute', left: Math.max(6, at.x - W + BTN_W * 1.5), top: at.y, width: W, padding: 12, gap: 8, borderRadius: t.menuRadius + 2,+ style={{ position: 'absolute', left: Math.max(6, left), top: at.y, width: W, padding: 12, gap: 8, borderRadius: t.menuRadius + 2,backgroundColor: t.panelBg, backdropFilter: t.blur ? `blur(${t.blur}px)` : undefined, border: `1px solid ${t.windowBorder}`, boxShadow: t.shadow }}><Text style={{ fontSize: 11, fontWeight: 600, color: t.textDim, textAlign: 'start' }}>{tr('shell.classic.snapLayouts')}</Text><View style={{ flexDirection: 'row', gap: 8, direction: 'ltr' }}>@@ -94,12 +99,36 @@ export function Window({ win, t, focused, app, tv }) {onMouseEnter={tv.onEnter} onMouseLeave={tv.onLeave} />) : null;- // Linux app with its own frame (GTK, Chromium): only the content, with the theme's shadow.+ // closes the snap layouts a moment after the pointer leaves (or `ms` after opening them from a menu)+ const leaveMax = (ms = 300) => { clearTimeout(hoverTimer.current); clearTimeout(leaveTimer.current); leaveTimer.current = setTimeout(() => setLayouts(null), ms); };+ // The title bar's menu; for an app that draws its own bar it also offers the snap layouts (its+ // maximize button is the app's, so there is no hover flyout).+ const windowMenuItems = (extra) => [+ { label: tr('shell.classic.restore'), disabled: !win.maximized && !win.snapped, onClick: () => wm.snap(win.id, 'restore') },+ { label: tr('shell.classic.minimize'), onClick: () => wm.minimize(win.id) },+ { label: tr('shell.classic.maximize'), disabled: win.maximized, onClick: () => wm.snap(win.id, 'max') },+ '-',+ ...(extra || []),+ { label: tr('shell.classic.snapLeft'), onClick: () => wm.snap(win.id, 'left') },+ { label: tr('shell.classic.snapRight'), onClick: () => wm.snap(win.id, 'right') },+ '-',+ { label: tr('shell.classic.close'), hint: 'Alt+F4', onClick: () => wm.close(win.id) },+ ];++ // Linux app with its own frame (GTK, Chromium and Firefox with their own bar): only the content,+ // with the theme's shadow. A right click on its bar asks for the window menu (w.windowMenu).if (win.args?.csd) {+ const wmenu = !tv && win.windowMenu;return (<WindowShell win={win} resizable={!tv} onMouseDown={() => wm.focus(win.id)} style={{ boxShadow: shadow, ...tvStyle }}><AppHost id={win.id} focused={focused && !tv} />{tvCover}+ {wmenu && (+ <Menu t={t} x={wmenu.x} y={wmenu.y} onClose={() => wm.closeWindowMenu(win.id)} items={windowMenuItems([+ { label: tr('shell.classic.snapLayouts'), onClick: () => { setLayouts({ left: wmenu.x, y: wmenu.y }); leaveMax(3000); } },+ ])} />+ )}+ {layouts && !tv && <SnapLayouts t={t} win={win} at={layouts} onEnter={() => clearTimeout(leaveTimer.current)} onLeave={() => leaveMax()} onDone={() => setLayouts(null)} />}</WindowShell>);}@@ -111,7 +140,6 @@ export function Window({ win, t, focused, app, tv }) {setLayouts({ x: x + w / 2 - BTN_W / 2, y: y + h + 4 });};const enterMax = () => { clearTimeout(leaveTimer.current); clearTimeout(hoverTimer.current); hoverTimer.current = setTimeout(openLayouts, 550); };- const leaveMax = () => { clearTimeout(hoverTimer.current); clearTimeout(leaveTimer.current); leaveTimer.current = setTimeout(() => setLayouts(null), 300); };const titleMenu = (e) => setMenu({ x: e.x, y: e.y });return (<WindowShell win={win} resizable={!tv} onMouseDown={() => wm.focus(win.id)} style={{@@ -135,18 +163,9 @@ export function Window({ win, t, focused, app, tv }) {</View><View style={{ flex: 1 }}><AppHost id={win.id} focused={focused && !tv} /></View>{tvCover}- {layouts && !tv && <SnapLayouts t={t} win={win} at={layouts} onEnter={() => clearTimeout(leaveTimer.current)} onLeave={leaveMax} onDone={() => setLayouts(null)} />}+ {layouts && !tv && <SnapLayouts t={t} win={win} at={layouts} onEnter={() => clearTimeout(leaveTimer.current)} onLeave={() => leaveMax()} onDone={() => setLayouts(null)} />}{menu && (- <Menu t={t} x={menu.x} y={menu.y} onClose={() => setMenu(null)} items={[- { label: tr('shell.classic.restore'), disabled: !win.maximized && !win.snapped, onClick: () => wm.snap(win.id, 'restore') },- { label: tr('shell.classic.minimize'), onClick: () => wm.minimize(win.id) },- { label: tr('shell.classic.maximize'), disabled: win.maximized, onClick: () => wm.snap(win.id, 'max') },- '-',- { label: tr('shell.classic.snapLeft'), onClick: () => wm.snap(win.id, 'left') },- { label: tr('shell.classic.snapRight'), onClick: () => wm.snap(win.id, 'right') },- '-',- { label: tr('shell.classic.close'), hint: 'Alt+F4', onClick: () => wm.close(win.id) },- ]} />+ <Menu t={t} x={menu.x} y={menu.y} onClose={() => setMenu(null)} items={windowMenuItems()} />)}</WindowShell>);diff --git a/themes/default/components/Window.jsx b/themes/default/components/Window.jsxindex 5051807..069d887 100644--- a/themes/default/components/Window.jsx+++ b/themes/default/components/Window.jsx@@ -2,8 +2,9 @@// (the SDK's AppHost); the theme only decides how the frame looks. Moving and resizing (invisible// borders on all 4 sides and 4 corners, <WindowShell>) is done by lord-server in C// (docs/WINDOWS.md); the JS drag below is only kept for a maximized window.-import { View, Text, addListener, wm, AppHost, windowTitle, WindowShell } from '@lordos/sdk';+import { View, Text, addListener, wm, AppHost, windowTitle, WindowShell, t as tr } from '@lordos/sdk';import { useEffect, useRef, useState } from 'react';+import { Menu } from './Menu.jsx';const TITLE_H = 40;const LIGHTS = [@@ -34,12 +35,23 @@ export function Window({ win, app, t, focused, fx }) {return () => { offMove(); offUp(); };}, [win.id]);- // Linux app that draws its own frame (GTK, Chromium): only the content, with the theme's shadow.+ // Linux app that draws its own frame (GTK, Chromium and Firefox with their own bar): only the+ // content, with the theme's shadow. A right click on its bar asks for the window menu+ // (w.windowMenu): the same items as the menu bar's Window menu.if (win.args?.csd) {+ const wmenu = win.windowMenu;return (<WindowShell win={win} onMouseDown={() => wm.focus(win.id)}style={{ boxShadow: focused ? '0 24px 56px rgba(0,0,0,0.5)' : '0 10px 28px rgba(0,0,0,0.3)', ...fxs }}><AppHost id={win.id} focused={focused} />+ {wmenu && (+ <Menu x={wmenu.x} y={wmenu.y} onClose={() => wm.closeWindowMenu(win.id)} items={[+ { label: tr('shell.window.minimize'), onClick: () => wm.minimize(win.id) },+ { label: tr('shell.window.maximize'), checked: !!win.maximized, onClick: () => wm.toggleMaximize(win.id) },+ '-',+ { label: tr('shell.window.close'), onClick: () => wm.close(win.id) },+ ]} />+ )}</WindowShell>);}