From 69d40e264017ff5f1cd3cb24a79d073d4e76b1e2 Mon Sep 17 00:00:00 2001 From: wheaney <42350981+wheaney@users.noreply.github.com> Date: Thu, 10 Oct 2024 12:38:08 -0700 Subject: [PATCH] Fix caching of backend object, copy SystemBackground from GNOME magnifier implemenation --- gnome/src/extension.js | 22 ++++++++++++---------- gnome/src/monitormanager.js | 5 +---- gnome/src/systembackground.js | 31 +++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 gnome/src/systembackground.js diff --git a/gnome/src/extension.js b/gnome/src/extension.js index 5f62bfd..29a38f1 100644 --- a/gnome/src/extension.js +++ b/gnome/src/extension.js @@ -9,6 +9,7 @@ import { CursorManager } from './cursormanager.js'; import Globals from './globals.js'; import { Logger } from './logger.js'; import { MonitorManager } from './monitormanager.js'; +import { SystemBackground } from './systembackground.js'; import { isValidKeepAlive } from './time.js'; import { IPC_FILE_PATH, XREffect } from './xrEffect.js'; @@ -250,24 +251,25 @@ export default class BreezyDesktopExtension extends Extension { this._cursor_manager = new CursorManager(Main.layoutManager.uiGroup, refreshRate); this._cursor_manager.enable(); - this._overlay = new St.Bin(); - this._overlay.opacity = 255; + const overlayContent = new Clutter.Actor({clip_to_allocation: true}); + + this._overlay = new St.Bin({ + child: overlayContent + }); this._overlay.set_position(targetMonitor.x, targetMonitor.y); this._overlay.set_size(targetMonitor.width, targetMonitor.height); - Globals.logger.log_debug(`BreezyDesktopExtension _effect_enable overlay size: \ - ${targetMonitor.width}x${targetMonitor.height} at ${targetMonitor.x},${targetMonitor.y}`); - const overlayContent = new Clutter.Actor({clip_to_allocation: true}); + global.stage.add_child(this._overlay); + Shell.util_set_hidden_from_pick(this._overlay, true); + + this._background = new SystemBackground(); + overlayContent.add_child(this._background); + const uiClone = new Clutter.Clone({ source: Main.layoutManager.uiGroup, clip_to_allocation: true }); uiClone.x = -targetMonitor.x; uiClone.y = -targetMonitor.y; overlayContent.add_child(uiClone); - this._overlay.set_child(overlayContent); - - Shell.util_set_hidden_from_pick(this._overlay, true); - global.stage.add_child(this._overlay); - // In GS 45, use of "actor" was renamed to "child". const clutterContainer = Clutter.Container !== undefined; this._actor_added_connection = global.stage.connect( diff --git a/gnome/src/monitormanager.js b/gnome/src/monitormanager.js index ca8a6a5..6cf5532 100644 --- a/gnome/src/monitormanager.js +++ b/gnome/src/monitormanager.js @@ -280,7 +280,6 @@ export const MonitorManager = GObject.registerClass({ this._monitorsChangedConnection = null; this._displayConfigProxy = null; - this._backendManager = null; this._monitorProperties = null; this._changeHookFn = null; this._needsConfigCheck = this.use_optimal_monitor_config; @@ -292,7 +291,6 @@ export const MonitorManager = GObject.registerClass({ enable() { Globals.logger.log_debug('MonitorManager enable'); - this._backendManager = global.backend.get_monitor_manager(); newDisplayConfig(this.extension_path, ((proxy, error) => { if (error) { return; @@ -310,7 +308,6 @@ export const MonitorManager = GObject.registerClass({ this._monitorsChangedConnection = null; this._displayConfigProxy = null; - this._backendManager = null; this._monitorProperties = null; this._changeHookFn = null; } @@ -402,7 +399,7 @@ export const MonitorManager = GObject.registerClass({ const monitorProperties = []; for (let i = 0; i < result.length; i++) { const [monitorName, connectorName, vendor, product, serial, refreshRate] = result[i]; - const monitorIndex = this._backendManager.get_monitor_for_connector(connectorName); + const monitorIndex = global.backend.get_monitor_manager().get_monitor_for_connector(connectorName); Globals.logger.log_debug(`Found monitor ${monitorName}, vendor ${vendor}, product ${product}, serial ${serial}, connector ${connectorName}, index ${monitorIndex}`); if (monitorIndex >= 0) { monitorProperties[monitorIndex] = { diff --git a/gnome/src/systembackground.js b/gnome/src/systembackground.js new file mode 100644 index 0000000..23039b9 --- /dev/null +++ b/gnome/src/systembackground.js @@ -0,0 +1,31 @@ +import Cogl from 'gi://Cogl'; +import GLib from 'gi://GLib'; +import GObject from 'gi://GObject'; +import Meta from 'gi://Meta'; + +const DEFAULT_BACKGROUND_COLOR = new Cogl.Color({red: 40, green: 40, blue: 40, alpha: 255}); + +let _systemBackground; + +export const SystemBackground = GObject.registerClass({ + Signals: {'loaded': {}}, +}, class SystemBackground extends Meta.BackgroundActor { + _init() { + if (_systemBackground == null) { + _systemBackground = new Meta.Background({meta_display: global.display}); + _systemBackground.set_color(DEFAULT_BACKGROUND_COLOR); + } + + super._init({ + meta_display: global.display, + monitor: 0, + }); + this.content.background = _systemBackground; + + let id = GLib.idle_add(GLib.PRIORITY_DEFAULT, () => { + this.emit('loaded'); + return GLib.SOURCE_REMOVE; + }); + GLib.Source.set_name_by_id(id, '[gnome-shell] SystemBackground.loaded'); + } +});