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
Lock/switch hand-off: close revoked input devices on a thread (the last close of VMware's virtual USB mouse took ~0.7 s; 903 -> 141 ms) and log slow hand-offs by step; dragged-window layer: only pixels inside app surfaces count as holes on the GPU path
Federico Pereirab46f277c64b2
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex f70b4a6..c7a0411 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -153,6 +153,16 @@ of the matching [GitHub release](https://github.com/lordbasex/LordOS/releases),### Fixed+- **Locking the screen and switching user are faster.** Handing the screen to the sign-in screen waited+ for every input device to close, and the last close of a USB mouse stops its transfers: about 0.7 s for+ VMware's virtual USB mouse, so a lock took 0.6 to 1.1 s there. Access is still cut at once+ (EVIOCREVOKE); the close now happens on a short-lived thread. Measured on a VMware Fusion VM: 903 ms+ → 141 ms from the lock to the sign-in screen. A slow hand-off is logged with the time of each step.+- **A dragged window's corners on the GPU path.** While a window is dragged it is painted from a cached+ layer, and on the GPU path every fully transparent pixel of that layer was taken for the hole of a+ Linux app's window, including the pixels outside its rounded corners. Now only pixels inside an app+ surface can be holes. (Black corners while dragging were also seen in remote-desktop frames; that path+ is still being looked at.)- **Dock → Options → Assign To with two monitors of the same model.** The assignment was kept by thedisplay's name, which two identical monitors share: both showed as checked and new windows went to thefirst. It is now kept by the connector (HDMI-A-1, DP-2…); an assignment saved by name still worksdiff --git a/server/src/remote/monitor.c b/server/src/remote/monitor.cindex 0bb77d4..ca3714c 100644--- a/server/src/remote/monitor.c+++ b/server/src/remote/monitor.c@@ -15,6 +15,7 @@#include "../drmcard.h"#include <errno.h>+#include <pthread.h>#include <time.h>#include <fcntl.h>#include <linux/input.h>@@ -108,40 +109,85 @@ static int send_msg(int type, const void *d, size_t n, const int *fds, int nfds)* last frame of an unlocked desktop. The session itself frees them when it handles RP_UNDISPLAY,* but that is asynchronous and a stuck or hostile session never does. Removing the one on the* screen turns that output off, which is what a switch shows anyway. */-static void drop_framebuffers(int fd) {+static int drop_framebuffers(int fd) {+ int total = 0;for (int pass = 0; pass < 16; pass++) {uint32_t ids[64];struct drm_mode_card_res r = {0};- if (ioctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &r) || !r.count_fbs) return;+ if (ioctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &r) || !r.count_fbs) return total;uint32_t n = r.count_fbs < 64 ? r.count_fbs : 64;r = (struct drm_mode_card_res){ .fb_id_ptr = (uint64_t)(uintptr_t)ids, .count_fbs = n };- if (ioctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &r)) return;+ if (ioctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &r)) return total;if (r.count_fbs < n) n = r.count_fbs;int removed = 0;for (uint32_t i = 0; i < n; i++) {uint32_t id = ids[i];if (!ioctl(fd, DRM_IOCTL_MODE_RMFB, &id)) removed++;}+ total += removed;if (!removed) {sd_log("warning: %u framebuffer(s) of the leaving session could not be removed", n);- return;+ return total;}}+ return total;+}++/* Closing an input device can be slow: the last close of a USB HID device stops its transfers, about+ * 0.7 s for VMware's virtual USB mouse, which held up every lock and switch. Access is already cut by+ * EVIOCREVOKE, so the close happens on a short-lived thread and the hand-off doesn't wait for it. */+static void *close_inputs(void *arg) {+ int *fds = arg;+ for (int i = 0; fds[i] >= 0; i++) close(fds[i]);+ free(fds);+ return NULL;+}+static void close_later(const int *fds, int n) {+ int *list = n > 0 ? malloc(sizeof(int) * ((size_t)n + 1)) : NULL;+ pthread_t th;+ pthread_attr_t at;+ if (list) {+ memcpy(list, fds, sizeof(int) * (size_t)n);+ list[n] = -1;+ if (!pthread_attr_init(&at)) {+ pthread_attr_setdetachstate(&at, PTHREAD_CREATE_DETACHED);+ int ok = !pthread_create(&th, &at, close_inputs, list);+ pthread_attr_destroy(&at);+ if (ok) return;+ }+ free(list);+ }+ for (int i = 0; i < n; i++) close(fds[i]); /* no thread: closed here, as before */}/* Takes the monitor away from the session that has it. */static void take_back(void) {+ double t0 = rd_now();if (conn >= 0) send_msg(RP_UNDISPLAY, NULL, 0, NULL, 0);+ double tsend = rd_now();+ char slow[160] = "";for (int i = 0; i < nin; i++) {+ double a = rd_now();ioctl(ins[i], EVIOCREVOKE, NULL);- close(ins[i]);+ double e = rd_now();+ if (e - a > 0.05 && strlen(slow) < sizeof slow - 40)+ snprintf(slow + strlen(slow), sizeof slow - strlen(slow), " %s revoke %.0f", inname[i], (e - a) * 1000);}+ close_later(ins, nin);nin = 0;+ double t1 = rd_now(), t2 = t1;+ int fbs = 0, had = drm >= 0;if (drm >= 0) {- drop_framebuffers(drm);+ fbs = drop_framebuffers(drm);+ t2 = rd_now();ioctl(drm, DRM_IOCTL_DROP_MASTER, NULL);close(drm);}+ double t3 = rd_now();+ /* a slow hand-off says where the time went (vmwgfx turns the output off on RMFB: about 1 s) */+ if (had && t3 - t0 > 0.25)+ sd_log("monitor: take back %.0f ms (notice %.0f, input %.0f%s, %d framebuffer(s) removed %.0f, release %.0f)",+ (t3 - t0) * 1000, (tsend - t0) * 1000, (t1 - tsend) * 1000, slow, fbs, (t2 - t1) * 1000, (t3 - t2) * 1000);drm = -1;if (conn >= 0) close(conn);conn = -1;diff --git a/server/src/ui/paint.c b/server/src/ui/paint.cindex 9a837ea..ab37e45 100644--- a/server/src/ui/paint.c+++ b/server/src/ui/paint.c@@ -10,6 +10,7 @@#include <stddef.h>#include <stdio.h>#include <stdlib.h>+#include <unistd.h>#include <string.h>#include <time.h>@@ -487,13 +488,34 @@ static void layer_fill(int x0, int y0, int x1, int y1) {else for (int x = x0; x < x1; x++) row[x] = v;}}+/* Where the window's app surfaces are, in layer pixels: only there can a 0 pixel be an app's hole.+ * Elsewhere a 0 is what a rounded clip left outside its corner, and taking it for a hole made the+ * corners of a dragged window black on the GPU path (nothing shows through where there is no app). */+#define LAYER_SURF_MAX 32+typedef struct { int x0, y0, x1, y1; } LSurf;+static LSurf lsurf[LAYER_SURF_MAX];+static int nlsurf, lsurf_all;+static void layer_surfaces(Node *n, int ox, int oy) {+ if (n->type == NODE_RAW || n->s.display_none) return;+ if (n->type == NODE_SURFACE) {+ if (nlsurf == LAYER_SURF_MAX) lsurf_all = 1; /* too many: every 0 counts, as before */+ else lsurf[nlsurf++] = (LSurf){ (int)floorf(VX(n->ax)) - ox, (int)floorf(VY(n->ay)) - oy,+ (int)ceilf(VX(n->ax + n->w)) - ox, (int)ceilf(VY(n->ay + n->h)) - oy };+ }+ if (n->type != NODE_TEXT) for (Node *k = n->first; k; k = k->next) layer_surfaces(k, ox, oy);+}+static int in_surface(int x, int y) {+ if (lsurf_all) return 1;+ for (int i = 0; i < nlsurf; i++) if (x >= lsurf[i].x0 && x < lsurf[i].x1 && y >= lsurf[i].y0 && y < lsurf[i].y1) return 1;+ return 0;+}static void layer_holes(int x0, int y0, int x1, int y1) {if (!gpu_active() || !layer.hole) return;for (int y = y0; y < y1; y++) {uint32_t *row = layer.px + (size_t)y * layer.w;uint8_t *m = layer.hole + (size_t)y * layer.w;for (int x = x0; x < x1; x++) {- m[x] = row[x] == 0;+ m[x] = row[x] == 0 && (nlsurf || lsurf_all) && in_surface(x, y);if (row[x] == SENTINEL) row[x] = 0;}}@@ -550,6 +572,8 @@ static int layer_render(Node *n, float opacity) {paint_node(&lc, n, opacity);layer.rendering = 0;skip_until = skip;+ nlsurf = lsurf_all = 0;+ layer_surfaces(n, x0, y0);layer_holes(0, 0, w, h);layer.valid = 1;layer.painted = 1;@@ -575,6 +599,8 @@ static void layer_render_part(Node *n, float opacity) {paint_node(&lc, n, opacity);layer.rendering = 0;skip_until = skip;+ nlsurf = lsurf_all = 0;+ layer_surfaces(n, x0, y0);layer_holes(px0, py0, px1, py1);layer.painted = 1;float k = paint_view.k, lx = (x0 - paint_view.dx) / k + paint_view.x, ly = (y0 - paint_view.dy) / k + paint_view.y;