extension.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. // Mutter has no layer-shell: turns the engine's per-output toplevels into desktop windows and reports the pointer
  2. // and per-monitor window states (WE 2.8 rules) a Wayland client can't see.
  3. import Clutter from 'gi://Clutter';
  4. import Cogl from 'gi://Cogl';
  5. import GObject from 'gi://GObject';
  6. import Gio from 'gi://Gio';
  7. import GLib from 'gi://GLib';
  8. import Meta from 'gi://Meta';
  9. import Shell from 'gi://Shell';
  10. import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';
  11. import * as Main from 'resource:///org/gnome/shell/ui/main.js';
  12. import {WorkspaceBackground} from 'resource:///org/gnome/shell/ui/workspace.js';
  13. const APP_ID = 'linux-wallpaperengine';
  14. const TITLE_PREFIX = 'linux-wallpaperengine wallpaper ';
  15. const BUS_NAME = 'org.linuxwallpaperengine.Shell';
  16. const OBJECT_PATH = '/org/linuxwallpaperengine/Shell';
  17. const API_VERSION = 1;
  18. const FLAG_FOCUSED = 1;
  19. const FLAG_MAXIMIZED = 2;
  20. const FLAG_FULLSCREEN = 4;
  21. const INTERFACE = `
  22. <node>
  23. <interface name="org.linuxwallpaperengine.Shell">
  24. <property name="Version" type="u" access="read"/>
  25. <property name="Supported" type="b" access="read"/>
  26. <property name="NeedsHelper" type="b" access="read"/>
  27. <method name="SpawnHelper">
  28. <arg type="s" name="socket" direction="in"/>
  29. </method>
  30. <method name="GetState">
  31. <arg type="a(sdd)" name="pointer" direction="out"/>
  32. <arg type="a(ssu)" name="windows" direction="out"/>
  33. </method>
  34. <signal name="PointerMoved">
  35. <arg type="a(sdd)" name="pointer"/>
  36. </signal>
  37. <signal name="DesktopButton">
  38. <arg type="b" name="pressed"/>
  39. </signal>
  40. <signal name="WindowsChanged">
  41. <arg type="a(ssu)" name="windows"/>
  42. </signal>
  43. </interface>
  44. </node>`;
  45. // Same rounded work-area clip the overview gives workspace backgrounds; bounds and radius are monitor fractions.
  46. const CLIP_DECLARATIONS = `
  47. uniform vec4 bounds;
  48. uniform vec2 radius;
  49. `;
  50. const CLIP_CODE = `
  51. vec2 p = cogl_tex_coord_in[0].xy;
  52. float inside = step(bounds.x, p.x) * step(p.x, bounds.z) * step(bounds.y, p.y) * step(p.y, bounds.w);
  53. if (radius.x > 0.0 && radius.y > 0.0) {
  54. vec2 corner = clamp(p, bounds.xy + radius, bounds.zw - radius);
  55. inside *= 1.0 - smoothstep(0.96, 1.0, length((p - corner) / radius));
  56. }
  57. cogl_color_out *= inside;
  58. `;
  59. const OverviewClipEffect = GObject.registerClass(
  60. class OverviewClipEffect extends Shell.GLSLEffect {
  61. _init(params) {
  62. super._init(params);
  63. this._boundsLocation = this.get_uniform_location('bounds');
  64. this._radiusLocation = this.get_uniform_location('radius');
  65. }
  66. vfunc_build_pipeline() {
  67. // Cogl samples first, the clip only scales the result
  68. this.add_glsl_snippet(Cogl.SnippetHook.FRAGMENT, CLIP_DECLARATIONS, CLIP_CODE, false);
  69. }
  70. setClip(bounds, radius) {
  71. this.set_uniform_float(this._boundsLocation, 4, bounds);
  72. this.set_uniform_float(this._radiusLocation, 2, radius);
  73. this.queue_repaint();
  74. }
  75. });
  76. // 49+: set_type on any MetaWindow. 46-48: only via MetaWaylandClient for Shell-spawned clients (the helper).
  77. // 45: no Wayland desktop windows, the wallpaper stays lowest in the normal layer like DING.
  78. const CAN_SET_TYPE = typeof Meta.Window.prototype.set_type === 'function';
  79. const CAN_MAKE_DESKTOP = typeof Meta.WaylandClient?.prototype.make_desktop === 'function';
  80. const CAN_HIDE = typeof Meta.WaylandClient?.prototype.hide_from_window_list === 'function';
  81. const SUPPORTED = CAN_SET_TYPE || CAN_HIDE;
  82. const HELPER = 'linux-wallpaperengine-gnome-helper';
  83. // icon extensions using a bottom-layer normal window (DING on Ubuntu 46, its Gtk4 fork)
  84. const DESKTOP_ICON_APPS = ['com.rastersoft.ding', 'com.desktop.ding'];
  85. // windows can move under a still pointer, re-pick after this long
  86. const PICK_INTERVAL_US = 250000;
  87. function isMaximized(window) {
  88. const flags = window.get_maximize_flags ? window.get_maximize_flags() : window.get_maximized();
  89. return flags === Meta.MaximizeFlags.BOTH;
  90. }
  91. function cursorTracker() {
  92. return global.backend.get_cursor_tracker?.() ?? Meta.CursorTracker.get_for_display(global.display);
  93. }
  94. function appIdOf(window) {
  95. return window.get_sandboxed_app_id() || window.get_gtk_application_id() || window.get_wm_class() || '';
  96. }
  97. export default class WallpaperEngineExtension extends Extension {
  98. enable() {
  99. this._wallpapers = new Map();
  100. this._watched = new Map();
  101. this._windowsJson = '';
  102. this._windows = [];
  103. this._pointerIdle = 0;
  104. this._stateIdle = 0;
  105. this._dbus = Gio.DBusExportedObject.wrapJSObject(INTERFACE, this);
  106. this._dbus.export(Gio.DBus.session, OBJECT_PATH);
  107. this._nameId = Gio.bus_own_name_on_connection(Gio.DBus.session, BUS_NAME, Gio.BusNameOwnerFlags.NONE,
  108. null, null);
  109. this._displaySignals = [
  110. global.display.connect('window-created', (_display, window) => this._watch(window)),
  111. global.display.connect('notify::focus-window', () => this._queueState()),
  112. // a window moved to another monitor keeps its size
  113. global.display.connect('window-entered-monitor', () => this._queueState()),
  114. global.display.connect('restacked', () => {
  115. this._pickStale = true;
  116. this._pruneWallpapers();
  117. this._keepBelowDesktopWindows();
  118. this._queueState();
  119. }),
  120. ];
  121. this._workspaceSignal = global.workspace_manager.connect('active-workspace-changed',
  122. () => this._queueState());
  123. this._monitorManager = global.backend.get_monitor_manager();
  124. this._monitorSignal = this._monitorManager.connect('monitors-changed', () => {
  125. for (const window of this._wallpapers.keys())
  126. this._place(window);
  127. this._queueState();
  128. this._queuePointer();
  129. });
  130. this._helperClients = new Set();
  131. this._raisedIds = new Map();
  132. this._shown = new Set();
  133. this._cursorTracker = cursorTracker();
  134. this._cursorSignal = this._cursorTracker.connect('position-invalidated', () => this._queuePointer());
  135. this._leftDown = false;
  136. this._leftForwarded = false;
  137. this._pointerOverDesktop = false;
  138. this._pickStale = true;
  139. this._pickX = this._pickY = -1;
  140. this._pickTime = 0;
  141. this._paintSignal = global.stage.connect('after-paint', () => this._pollLeftButton());
  142. this._overviewClones = new Map();
  143. this._overviewSignal = Main.overview.connect('showing', () => this._syncOverview());
  144. this._workareaSignal = global.display.connect('workareas-changed', () => this._syncOverview());
  145. for (const actor of global.get_window_actors())
  146. this._watch(actor.meta_window);
  147. this._queueState();
  148. }
  149. disable() {
  150. for (const id of [this._pointerIdle, this._stateIdle]) {
  151. if (id)
  152. GLib.source_remove(id);
  153. }
  154. this._pointerIdle = this._stateIdle = 0;
  155. Main.overview.disconnect(this._overviewSignal);
  156. global.display.disconnect(this._workareaSignal);
  157. for (const background of [...this._overviewClones.keys()])
  158. this._dropOverviewClone(background);
  159. this._overviewClones = null;
  160. this._cursorTracker.disconnect(this._cursorSignal);
  161. global.stage.disconnect(this._paintSignal);
  162. this._monitorManager.disconnect(this._monitorSignal);
  163. global.workspace_manager.disconnect(this._workspaceSignal);
  164. for (const id of this._displaySignals)
  165. global.display.disconnect(id);
  166. for (const [window, ids] of this._watched) {
  167. for (const id of ids)
  168. window.disconnect(id);
  169. }
  170. this._watched.clear();
  171. // otherwise they would be plain windows covering the monitor
  172. for (const window of this._wallpapers.keys())
  173. window.delete(global.display.get_current_time_roundtrip());
  174. this._wallpapers.clear();
  175. Gio.bus_unown_name(this._nameId);
  176. this._dbus.unexport();
  177. this._dbus = null;
  178. this._cursorTracker = this._monitorManager = null;
  179. for (const [window, id] of this._raisedIds)
  180. window.disconnect(id);
  181. this._helperClients = null;
  182. this._raisedIds = null;
  183. this._shown = null;
  184. }
  185. get Version() {
  186. return API_VERSION;
  187. }
  188. get Supported() {
  189. return SUPPORTED;
  190. }
  191. get NeedsHelper() {
  192. return !CAN_SET_TYPE && CAN_HIDE;
  193. }
  194. // Only ever runs our own helper; callers just pick an engine socket in the runtime folder (Flatpak calls come
  195. // through xdg-dbus-proxy, so the caller's pid is meaningless)
  196. SpawnHelperAsync([socket], invocation) {
  197. try {
  198. if (!this.NeedsHelper)
  199. throw new Error('this GNOME Shell makes desktop windows without the helper');
  200. const runtime = `${GLib.get_user_runtime_dir()}/`;
  201. const socketName = socket.startsWith(runtime) ? socket.slice(runtime.length) : '';
  202. if (!/^(app\/[^/]+\/)?lwe-gnome-(\d+_)?\d+\.sock$/.test(socketName))
  203. throw new Error(`refusing a helper for ${socket}`);
  204. const helper = GLib.build_filenamev([this.path, HELPER]);
  205. const launcher = new Gio.SubprocessLauncher({flags: Gio.SubprocessFlags.NONE});
  206. const client = Meta.WaylandClient.new(global.context, launcher);
  207. const process = client.spawnv(global.display, [helper, socket]);
  208. this._helperClients.add(client);
  209. process.wait_async(null, () => this._helperClients?.delete(client));
  210. invocation.return_value(null);
  211. } catch (error) {
  212. invocation.return_error_literal(Gio.DBusError, Gio.DBusError.ACCESS_DENIED, error.message);
  213. }
  214. }
  215. GetState() {
  216. return [this._pointer(), this._windows];
  217. }
  218. // fractions from the top left, stage and surface coords differ without scale-monitor-framebuffer
  219. _pointer() {
  220. const [x, y] = global.get_pointer();
  221. const result = [];
  222. for (const [window, connector] of this._wallpapers) {
  223. const frame = window.get_frame_rect();
  224. if (frame.width > 0 && frame.height > 0)
  225. result.push([connector, (x - frame.x) / frame.width, (y - frame.y) / frame.height]);
  226. }
  227. return result;
  228. }
  229. _watch(window) {
  230. if (this._watched.has(window))
  231. return;
  232. // title and app id may come after the window exists
  233. const check = () => {
  234. if (!this._wallpapers.has(window) && this._isWallpaper(window))
  235. this._adopt(window);
  236. this._queueState();
  237. };
  238. const ids = [
  239. window.connect('notify::wm-class', check),
  240. window.connect('notify::title', check),
  241. window.connect('notify::minimized', () => this._queueState()),
  242. window.connect('notify::maximized-horizontally', () => this._queueState()),
  243. window.connect('notify::maximized-vertically', () => this._queueState()),
  244. window.connect('notify::fullscreen', () => this._queueState()),
  245. window.connect('size-changed', () => {
  246. this._queueState();
  247. if (this._wallpapers.has(window))
  248. this._queuePointer();
  249. }),
  250. window.connect('workspace-changed', () => this._queueState()),
  251. window.connect('unmanaged', () => {
  252. for (const id of this._watched.get(window) ?? [])
  253. window.disconnect(id);
  254. this._watched.delete(window);
  255. this._raisedIds?.delete(window);
  256. this._shown?.delete(window);
  257. if (this._wallpapers.delete(window))
  258. this._syncOverview();
  259. this._queueState();
  260. }),
  261. ];
  262. this._watched.set(window, ids);
  263. check();
  264. }
  265. _isWallpaper(window) {
  266. return window.get_client_type() === Meta.WindowClientType.WAYLAND &&
  267. window.get_wm_class() === APP_ID &&
  268. (window.get_title() ?? '').startsWith(TITLE_PREFIX);
  269. }
  270. _adopt(window) {
  271. const connector = window.get_title().slice(TITLE_PREFIX.length);
  272. this._wallpapers.set(window, connector);
  273. // not fullscreen on the engine side (would hide the top bar), the monitor size comes from here
  274. if (CAN_SET_TYPE) {
  275. window.set_type(Meta.WindowType.DESKTOP);
  276. window.hide_from_window_list();
  277. } else {
  278. const client = [...this._helperClients].find(candidate => candidate.owns_window(window));
  279. if (!client) {
  280. console.error(`${this.uuid}: ${window.get_title()} is not from a helper connection, it stays a window`);
  281. return;
  282. }
  283. if (CAN_MAKE_DESKTOP) {
  284. client.make_desktop(window);
  285. } else {
  286. this._raisedIds.set(window, window.connect_after('raised', () => window.lower()));
  287. this._returnFocus(window, global.display.focus_window);
  288. }
  289. client.hide_from_window_list(window);
  290. }
  291. window.stick();
  292. this._place(window);
  293. const shownId = window.connect('shown', () => {
  294. window.disconnect(shownId);
  295. this._shown.add(window);
  296. this._place(window);
  297. this._keepBelowDesktopWindows();
  298. });
  299. this._queuePointer();
  300. this._syncOverview();
  301. }
  302. // The overview hides the window group, so a clone over each workspace background keeps it live
  303. _syncOverview() {
  304. if (!this._overviewClones)
  305. return;
  306. const found = new Set();
  307. const walk = actor => {
  308. if (actor instanceof WorkspaceBackground) {
  309. found.add(actor);
  310. this._syncWorkspaceBackground(actor);
  311. return;
  312. }
  313. for (const child of actor.get_children())
  314. walk(child);
  315. };
  316. walk(Main.layoutManager.overviewGroup);
  317. for (const background of [...this._overviewClones.keys()]) {
  318. if (!found.has(background))
  319. this._dropOverviewClone(background);
  320. }
  321. }
  322. _wallpaperActorOn(monitorIndex) {
  323. for (const window of this._wallpapers.keys()) {
  324. if (window.get_monitor() === monitorIndex && window.get_compositor_private())
  325. return window.get_compositor_private();
  326. }
  327. return null;
  328. }
  329. _syncWorkspaceBackground(background) {
  330. const source = SUPPORTED ? this._wallpaperActorOn(background._monitorIndex) : null;
  331. const existing = this._overviewClones.get(background);
  332. if (existing?.clone.source === source && source) {
  333. this._updateOverviewClip(background, existing);
  334. return;
  335. }
  336. if (existing)
  337. this._dropOverviewClone(background);
  338. if (!source)
  339. return;
  340. const clone = new Clutter.Clone({source, x_expand: true, y_expand: true});
  341. const effect = new OverviewClipEffect();
  342. clone.add_effect(effect);
  343. const group = background._backgroundGroup;
  344. group.add_child(clone);
  345. group.set_child_above_sibling(clone, null);
  346. const entry = {clone, effect, group, signals: [], content: null, contentSignal: 0};
  347. const manager = background._bgManager;
  348. entry.signals.push([manager, manager.connect('changed', () => {
  349. group.set_child_above_sibling(clone, null);
  350. this._updateOverviewClip(background, entry);
  351. })]);
  352. entry.signals.push([background, background.connect('destroy', () => this._dropOverviewClone(background, true))]);
  353. this._overviewClones.set(background, entry);
  354. this._updateOverviewClip(background, entry);
  355. }
  356. _updateOverviewClip(background, entry) {
  357. const content = background._bgManager?.backgroundActor?.content;
  358. if (!content)
  359. return;
  360. if (entry.content !== content) {
  361. if (entry.contentSignal)
  362. entry.content.disconnect(entry.contentSignal);
  363. entry.content = content;
  364. entry.contentSignal = content.connect('notify::rounded-clip-radius',
  365. () => this._updateOverviewClip(background, entry));
  366. }
  367. const monitor = Main.layoutManager.monitors[background._monitorIndex];
  368. const area = background._workarea;
  369. if (!monitor || !area || monitor.width <= 0 || monitor.height <= 0)
  370. return;
  371. const left = (area.x - monitor.x) / monitor.width;
  372. const top = (area.y - monitor.y) / monitor.height;
  373. const radius = content.rounded_clip_radius;
  374. entry.effect.setClip(
  375. [left, top, left + area.width / monitor.width, top + area.height / monitor.height],
  376. [radius / monitor.width, radius / monitor.height]);
  377. }
  378. _dropOverviewClone(background, destroyed = false) {
  379. const entry = this._overviewClones?.get(background);
  380. if (!entry)
  381. return;
  382. this._overviewClones.delete(background);
  383. if (destroyed)
  384. return;
  385. for (const [object, id] of entry.signals)
  386. object.disconnect(id);
  387. if (entry.contentSignal)
  388. entry.content.disconnect(entry.contentSignal);
  389. entry.clone.destroy();
  390. }
  391. // DING shares the wallpaper's layer and later windows land on top; keep the wallpaper lowest, under the icons
  392. _keepBelowDesktopWindows() {
  393. const stack = global.display.sort_windows_by_stacking(global.display.list_all_windows());
  394. for (const wallpaper of this._wallpapers.keys()) {
  395. const layer = wallpaper.get_layer();
  396. const index = stack.indexOf(wallpaper);
  397. // lowering re-emits restacked
  398. if (stack.slice(0, Math.max(index, 0))
  399. .some(window => window.get_layer() === layer && !this._wallpapers.has(window)))
  400. wallpaper.lower();
  401. }
  402. }
  403. // GNOME 45 drops a gone client's window without 'unmanaged' (Shell 45.2)
  404. _pruneWallpapers() {
  405. const live = new Set(global.display.list_all_windows());
  406. for (const window of [...this._wallpapers.keys()]) {
  407. if (!this._shown.has(window) || live.has(window))
  408. continue;
  409. for (const id of this._watched.get(window) ?? [])
  410. window.disconnect(id);
  411. this._watched.delete(window);
  412. this._wallpapers.delete(window);
  413. this._shown.delete(window);
  414. this._raisedIds.delete(window);
  415. this._syncOverview();
  416. }
  417. }
  418. _returnFocus(window, previous) {
  419. const shownId = window.connect('shown', () => {
  420. window.disconnect(shownId);
  421. if (window.has_focus() && previous && previous !== window && !previous.minimized)
  422. previous.activate(global.display.get_current_time_roundtrip());
  423. });
  424. }
  425. _place(window) {
  426. const connector = this._wallpapers.get(window);
  427. const monitor = this._monitorManager.get_monitor_for_connector(connector);
  428. if (monitor < 0)
  429. return;
  430. const area = global.display.get_monitor_geometry(monitor);
  431. window.move_resize_frame(false, area.x, area.y, area.width, area.height);
  432. }
  433. // Clicks on desktop icons never reach our surface, but WE polls the left button each frame (sub_14010D9B0) and
  434. // counts a press over the icon view. Stage events miss Wayland client input, so poll once per painted frame too.
  435. _pollLeftButton() {
  436. if (this._wallpapers.size === 0)
  437. return;
  438. const [, , mods] = global.get_pointer();
  439. const down = (mods & Clutter.ModifierType.BUTTON1_MASK) !== 0;
  440. if (down === this._leftDown) {
  441. if (!down)
  442. this._updatePointerOverDesktop();
  443. return;
  444. }
  445. this._leftDown = down;
  446. // pick before the press, icons react to it (DING starts a rubber band)
  447. if (down && !Main.overview.visible && this._pointerOverDesktop) {
  448. this._leftForwarded = true;
  449. this._dbus?.emit_signal('DesktopButton', new GLib.Variant('(b)', [true]));
  450. } else if (!down && this._leftForwarded) {
  451. this._leftForwarded = false;
  452. this._dbus?.emit_signal('DesktopButton', new GLib.Variant('(b)', [false]));
  453. }
  454. }
  455. // runs every frame, a pick walks the whole stage
  456. _updatePointerOverDesktop() {
  457. const [x, y] = global.get_pointer();
  458. const now = GLib.get_monotonic_time();
  459. if (!this._pickStale && x === this._pickX && y === this._pickY && now - this._pickTime < PICK_INTERVAL_US)
  460. return;
  461. this._pickStale = false;
  462. this._pickX = x;
  463. this._pickY = y;
  464. this._pickTime = now;
  465. this._pointerOverDesktop = this._overOtherDesktopWindow(x, y);
  466. }
  467. _overOtherDesktopWindow(x, y) {
  468. let actor = global.stage.get_actor_at_pos(Clutter.PickMode.REACTIVE, x, y);
  469. while (actor && !(actor instanceof Meta.WindowActor))
  470. actor = actor.get_parent();
  471. const window = actor?.get_meta_window();
  472. return !!window && this._isDesktop(window);
  473. }
  474. // other desktop windows and icon windows
  475. _isDesktop(window) {
  476. if (this._wallpapers.has(window))
  477. return false;
  478. return window.get_window_type() === Meta.WindowType.DESKTOP ||
  479. DESKTOP_ICON_APPS.includes(window.get_gtk_application_id());
  480. }
  481. _queuePointer() {
  482. if (this._pointerIdle || this._wallpapers.size === 0)
  483. return;
  484. this._pointerIdle = GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => {
  485. this._pointerIdle = 0;
  486. this._dbus?.emit_signal('PointerMoved', new GLib.Variant('(a(sdd))', [this._pointer()]));
  487. return GLib.SOURCE_REMOVE;
  488. });
  489. }
  490. _queueState() {
  491. if (this._stateIdle)
  492. return;
  493. this._stateIdle = GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => {
  494. this._stateIdle = 0;
  495. this._updateState();
  496. return GLib.SOURCE_REMOVE;
  497. });
  498. }
  499. // GNOME 46 can't list logical monitors, only outputs with a wallpaper are reported
  500. _connectorsOf(monitorIndex) {
  501. return [...new Set(this._wallpapers.values())]
  502. .filter(connector => this._monitorManager.get_monitor_for_connector(connector) === monitorIndex);
  503. }
  504. // WE 2.8 (sub_14003D050 / sub_14003BBA0): visible, unminimized windows on the current desktop. Maximized marks its
  505. // monitor; the foreground root window marks focused, and fullscreen if not maximized and at least monitor-sized.
  506. _collectWindows() {
  507. const workspace = global.workspace_manager.get_active_workspace();
  508. const focus = global.display.focus_window?.find_root_ancestor() ?? null;
  509. const windows = [];
  510. for (const actor of global.get_window_actors()) {
  511. const window = actor.meta_window;
  512. if (this._wallpapers.has(window) || window.minimized || !window.showing_on_its_workspace() ||
  513. !window.located_on_workspace(workspace) || window.is_override_redirect())
  514. continue;
  515. if (window.get_window_type() === Meta.WindowType.DOCK || this._isDesktop(window))
  516. continue;
  517. const maximized = isMaximized(window);
  518. let flags = maximized ? FLAG_MAXIMIZED : 0;
  519. if (window === focus) {
  520. flags |= FLAG_FOCUSED;
  521. const frame = window.get_frame_rect();
  522. const area = global.display.get_monitor_geometry(window.get_monitor());
  523. if (!maximized && (window.is_fullscreen() || (frame.width >= area.width && frame.height >= area.height)))
  524. flags |= FLAG_FULLSCREEN;
  525. }
  526. if (flags === 0)
  527. continue;
  528. for (const connector of this._connectorsOf(window.get_monitor()))
  529. windows.push([appIdOf(window), connector, flags]);
  530. }
  531. return windows;
  532. }
  533. _updateState() {
  534. const windows = this._collectWindows();
  535. const json = JSON.stringify(windows);
  536. if (json === this._windowsJson)
  537. return;
  538. this._windowsJson = json;
  539. this._windows = windows;
  540. this._dbus?.emit_signal('WindowsChanged', new GLib.Variant('(a(ssu))', [windows]));
  541. }
  542. }