Skip to content

All your computers and your phone/iPhone, working as one desk. Screens, apps, files, clipboard, calls, texts, notifications, mouse and keyboard, shared between Mac, Windows, Linux , Android, Web and ios / ipados . Free and open source. No account, no cloud, and no shared network needed.

2.1 KB
Raw Blame
// TwinDesk — Copyright (C) 2026 inukaasith. GPL-3.0, see LICENSE.
// Keep the pointer here while an app is fullscreen (kvmConfig stayFullscreen, #373), X11: the
// active window (_NET_ACTIVE_WINDOW) has _NET_WM_STATE_FULLSCREEN. Asked only when the pointer
// pushes on an edge, at most every 0.3 s, on a connection of its own (the capture's threads never
// share one). Wayland has no way to ask: it stays off there (the setting isn't shown).
#include "helper.h"
#include <X11/Xatom.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

static int stay;
static Display *dpy;
static double lastAt = -1;
static int lastVal;

void fullscreen_config(const JObj *c) { stay = jbool(c, "stayFullscreen", 0); }

static double now_s(void) {
  struct timespec t;
  clock_gettime(CLOCK_MONOTONIC, &t);
  return t.tv_sec + t.tv_nsec / 1e9;
}

static int window_prop(Window w, Atom prop, Atom type, unsigned long *out, int max) {
  Atom got; int fmt; unsigned long n = 0, after; unsigned char *data = NULL;
  if (XGetWindowProperty(dpy, w, prop, 0, max, False, type, &got, &fmt, &n, &after, &data) != Success || !data) return 0;
  int k = 0;
  if (got == type && fmt == 32) for (; k < (int)n && k < max; k++) out[k] = ((unsigned long *)data)[k];
  XFree(data);
  return k;
}

static int compute(void) {
  if (!dpy && !(dpy = XOpenDisplay(NULL))) return 0;
  Window root = DefaultRootWindow(dpy);
  unsigned long act[1];
  if (window_prop(root, XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False), XA_WINDOW, act, 1) != 1 || !act[0]) return 0;
  unsigned long st[16];
  int n = window_prop((Window)act[0], XInternAtom(dpy, "_NET_WM_STATE", False), XA_ATOM, st, 16);
  Atom fs = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False);
  for (int i = 0; i < n; i++) if (st[i] == fs) return 1;
  return 0;
}

// 1: an app is fullscreen and the edge should hold the pointer here.
int fullscreen_holds(void) {
  if (!stay || getenv("WAYLAND_DISPLAY")) return 0; // XWayland sees only X apps: no answer there
  double t = now_s();
  if (lastAt >= 0 && t - lastAt < 0.3) return lastVal;
  lastAt = t;
  lastVal = compute();
  return lastVal;
}