Backport to GNOME versions 44 and 43

Works in gnome-shell nested
This commit is contained in:
wheaney 2024-07-11 12:55:13 -07:00
parent 7369cb0551
commit 048b98ec99
13 changed files with 116 additions and 81 deletions

View File

@ -15,11 +15,11 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import Clutter from 'gi://Clutter'; const Clutter = imports.gi.Clutter;
import GObject from 'gi://GObject'; const GObject = imports.gi.GObject;
// Copied almost verbatim from ui/magnifier.js. // Copied almost verbatim from ui/magnifier.js.
export const MouseSpriteContent = GObject.registerClass({ var MouseSpriteContent = GObject.registerClass({
Implements: [Clutter.Content], Implements: [Clutter.Content],
}, class MouseSpriteContent extends GObject.Object { }, class MouseSpriteContent extends GObject.Object {
_init() { _init() {

View File

@ -1,12 +1,15 @@
import Clutter from 'gi://Clutter'; const Clutter = imports.gi.Clutter;
import GLib from 'gi://GLib'; const Meta = imports.gi.Meta;
import Meta from 'gi://Meta'; const PointerWatcher = imports.ui.pointerWatcher;
import * as PointerWatcher from 'resource:///org/gnome/shell/ui/pointerWatcher.js';
import { MouseSpriteContent } from './cursor.js'; const ExtensionUtils = imports.misc.extensionUtils;
import Globals from './globals.js'; const Me = ExtensionUtils.getCurrentExtension();
const Globals = Me.imports.globals;
const { MouseSpriteContent } = Me.imports.cursor;
// Taken from https://github.com/jkitching/soft-brightness-plus // Taken from https://github.com/jkitching/soft-brightness-plus
export class CursorManager { var CursorManager = class CursorManager {
constructor(mainActor, refreshRate) { constructor(mainActor, refreshRate) {
this._mainActor = mainActor; this._mainActor = mainActor;
this._refreshRate = refreshRate; this._refreshRate = refreshRate;

View File

@ -1,19 +1,21 @@
import Clutter from 'gi://Clutter' const Clutter = imports.gi.Clutter;
import Gio from 'gi://Gio'; const Gio = imports.gi.Gio;
import GLib from 'gi://GLib'; const GLib = imports.gi.GLib;
import Meta from 'gi://Meta'; const Meta = imports.gi.Meta;
import Shell from 'gi://Shell'; const Shell = imports.gi.Shell;
import St from 'gi://St'; const St = imports.gi.St;
import { CursorManager } from './cursormanager.js'; const Main = imports.ui.main;
import Globals from './globals.js';
import { Logger } from './logger.js';
import { MonitorManager } from './monitormanager.js';
import { isValidKeepAlive } from './time.js';
import { IPC_FILE_PATH, XREffect } from './xrEffect.js';
import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js'; const ExtensionUtils = imports.misc.extensionUtils;
import * as Main from 'resource:///org/gnome/shell/ui/main.js'; const Me = ExtensionUtils.getCurrentExtension();
const Globals = Me.imports.globals;
const { CursorManager } = Me.imports.cursormanager;
const { Logger } = Me.imports.logger;
const { MonitorManager } = Me.imports.monitormanager;
const { isValidKeepAlive } = Me.imports.time;
const { IPC_FILE_PATH, XREffect } = Me.imports.xrEffect;
const SUPPORTED_MONITOR_PRODUCTS = [ const SUPPORTED_MONITOR_PRODUCTS = [
'VITURE', 'VITURE',
@ -24,11 +26,10 @@ const SUPPORTED_MONITOR_PRODUCTS = [
'SmartGlasses' // TCL/RayNeo 'SmartGlasses' // TCL/RayNeo
]; ];
export default class BreezyDesktopExtension extends Extension { class BreezyDesktopExtension {
constructor(metadata, uuid) { constructor(extensionPath) {
super(metadata, uuid); this.path = extensionPath;
this.settings = ExtensionUtils.getSettings();
this.settings = this.getSettings();
// Set/destroyed by enable/disable // Set/destroyed by enable/disable
this._cursor_manager = null; this._cursor_manager = null;
@ -521,6 +522,6 @@ export default class BreezyDesktopExtension extends Extension {
} }
} }
function init() { function init(meta) {
return new Extension(); return new BreezyDesktopExtension(meta.path);
} }

View File

@ -2,5 +2,4 @@ const Globals = {
logger: null, logger: null,
ipc_file: null, // Gio.File instance, file exists if set ipc_file: null, // Gio.File instance, file exists if set
extension_dir: null // string path extension_dir: null // string path
} }
export default Globals;

View File

@ -0,0 +1,27 @@
function isGnome45OrLater() {
return !imports.gi.versions['GLib'];
}
async function importGiModule(module) {
return isGnome45OrLater() ? import(`gi://${module}`) : Promise.resolve(imports.gi[module]);
}
// Function to dynamically import modules based on GJS version
async function importGiModules(modules) {
return Promise.all(modules.map(importGiModule));
}
async function importNativeModule(path, name) {
return isGnome45OrLater() ? import(`resource:///org/gnome/shell/${path}/${name}.js`) : Promise.resolve(imports[path][name]);
}
// GNOME 44 and older don't have a base extension class
const ExtensionUtils = imports.misc.extensionUtils;
class BaseExtension {
getSettings() {
return ExtensionUtils.getSettings();
}
}
var ExtensionClassPromise = isGnome45OrLater() ? import(`resource:///org/gnome/shell/extensions/extension.js`) : Promise.resolve(BaseExtension);

View File

@ -1,30 +1,30 @@
export const UINT8_SIZE = 1; var UINT8_SIZE = 1;
export const BOOL_SIZE = UINT8_SIZE; var BOOL_SIZE = UINT8_SIZE;
export const UINT_SIZE = 4; var UINT_SIZE = 4;
export const FLOAT_SIZE = 4; var FLOAT_SIZE = 4;
export const DATA_VIEW_INFO_OFFSET_INDEX = 0; var DATA_VIEW_INFO_OFFSET_INDEX = 0;
export const DATA_VIEW_INFO_SIZE_INDEX = 1; var DATA_VIEW_INFO_SIZE_INDEX = 1;
export const DATA_VIEW_INFO_COUNT_INDEX = 2; var DATA_VIEW_INFO_COUNT_INDEX = 2;
// computes the end offset, exclusive // computes the end offset, exclusive
export function dataViewEnd(dataViewInfo) { function dataViewEnd(dataViewInfo) {
return dataViewInfo[DATA_VIEW_INFO_OFFSET_INDEX] + dataViewInfo[DATA_VIEW_INFO_SIZE_INDEX] * dataViewInfo[DATA_VIEW_INFO_COUNT_INDEX]; return dataViewInfo[DATA_VIEW_INFO_OFFSET_INDEX] + dataViewInfo[DATA_VIEW_INFO_SIZE_INDEX] * dataViewInfo[DATA_VIEW_INFO_COUNT_INDEX];
} }
export function dataViewUint8(dataView, dataViewInfo) { function dataViewUint8(dataView, dataViewInfo) {
return dataView.getUint8(dataViewInfo[DATA_VIEW_INFO_OFFSET_INDEX]); return dataView.getUint8(dataViewInfo[DATA_VIEW_INFO_OFFSET_INDEX]);
} }
export function dataViewUint(dataView, dataViewInfo) { function dataViewUint(dataView, dataViewInfo) {
return dataView.getUint32(dataViewInfo[DATA_VIEW_INFO_OFFSET_INDEX], true); return dataView.getUint32(dataViewInfo[DATA_VIEW_INFO_OFFSET_INDEX], true);
} }
export function dataViewBigUint(dataView, dataViewInfo) { function dataViewBigUint(dataView, dataViewInfo) {
return Number(dataView.getBigUint64(dataViewInfo[DATA_VIEW_INFO_OFFSET_INDEX], true)); return Number(dataView.getBigUint64(dataViewInfo[DATA_VIEW_INFO_OFFSET_INDEX], true));
} }
export function dataViewUint32Array(dataView, dataViewInfo) { function dataViewUint32Array(dataView, dataViewInfo) {
const uintArray = [] const uintArray = []
let offset = dataViewInfo[DATA_VIEW_INFO_OFFSET_INDEX]; let offset = dataViewInfo[DATA_VIEW_INFO_OFFSET_INDEX];
for (let i = 0; i < dataViewInfo[DATA_VIEW_INFO_COUNT_INDEX]; i++) { for (let i = 0; i < dataViewInfo[DATA_VIEW_INFO_COUNT_INDEX]; i++) {
@ -34,7 +34,7 @@ export function dataViewUint32Array(dataView, dataViewInfo) {
return uintArray; return uintArray;
} }
export function dataViewUint8Array(dataView, dataViewInfo) { function dataViewUint8Array(dataView, dataViewInfo) {
const uintArray = [] const uintArray = []
let offset = dataViewInfo[DATA_VIEW_INFO_OFFSET_INDEX]; let offset = dataViewInfo[DATA_VIEW_INFO_OFFSET_INDEX];
for (let i = 0; i < dataViewInfo[DATA_VIEW_INFO_SIZE_INDEX] * dataViewInfo[DATA_VIEW_INFO_COUNT_INDEX]; i++) { for (let i = 0; i < dataViewInfo[DATA_VIEW_INFO_SIZE_INDEX] * dataViewInfo[DATA_VIEW_INFO_COUNT_INDEX]; i++) {
@ -44,11 +44,11 @@ export function dataViewUint8Array(dataView, dataViewInfo) {
return uintArray; return uintArray;
} }
export function dataViewFloat(dataView, dataViewInfo) { function dataViewFloat(dataView, dataViewInfo) {
return dataView.getFloat32(dataViewInfo[DATA_VIEW_INFO_OFFSET_INDEX], true); return dataView.getFloat32(dataViewInfo[DATA_VIEW_INFO_OFFSET_INDEX], true);
} }
export function dataViewFloatArray(dataView, dataViewInfo) { function dataViewFloatArray(dataView, dataViewInfo) {
const floatArray = [] const floatArray = []
let offset = dataViewInfo[DATA_VIEW_INFO_OFFSET_INDEX]; let offset = dataViewInfo[DATA_VIEW_INFO_OFFSET_INDEX];
for (let i = 0; i < dataViewInfo[DATA_VIEW_INFO_COUNT_INDEX]; i++) { for (let i = 0; i < dataViewInfo[DATA_VIEW_INFO_COUNT_INDEX]; i++) {

View File

@ -14,15 +14,15 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import * as Config from 'resource:///org/gnome/shell/misc/config.js'; const Config = imports.misc.config;
import Gio from 'gi://Gio'; const Gio = imports.gi.Gio;
import GLib from 'gi://GLib'; const GLib = imports.gi.GLib;
import GObject from 'gi://GObject'; const GObject = imports.gi.GObject;
import System from 'system'; const System = imports.system;
const LOG_DIR_NAME = 'breezy_gnome/logs/gjs'; const LOG_DIR_NAME = 'breezy_gnome/logs/gjs';
export const Logger = GObject.registerClass({ var Logger = GObject.registerClass({
GTypeName: 'Logger', GTypeName: 'Logger',
Properties: { Properties: {
'title': GObject.ParamSpec.string( 'title': GObject.ParamSpec.string(

View File

@ -1,3 +1,3 @@
export function degreeToRadian(degree) { function degreeToRadian(degree) {
return degree * Math.PI / 180; return degree * Math.PI / 180;
} }

View File

@ -5,7 +5,7 @@
"settings-schema": "com.xronlinux.BreezyDesktop", "settings-schema": "com.xronlinux.BreezyDesktop",
"session-modes": ["user", "unlock-dialog"], "session-modes": ["user", "unlock-dialog"],
"shell-version": [ "shell-version": [
"45", "46" "43", "44"
], ],
"url": "https://github.com/wheaney/breezy-desktop" "url": "https://github.com/wheaney/breezy-desktop"
} }

View File

@ -16,12 +16,15 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import Gio from 'gi://Gio'; const Gio = imports.gi.Gio;
import GObject from 'gi://GObject'; const GObject = imports.gi.GObject;
import * as Main from 'resource:///org/gnome/shell/ui/main.js'; const Main = imports.ui.main;
import Globals from './globals.js'; const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Globals = Me.imports.globals;
let cachedDisplayConfigProxy = null; let cachedDisplayConfigProxy = null;
@ -43,7 +46,7 @@ function getDisplayConfigProxy(extPath) {
return cachedDisplayConfigProxy; return cachedDisplayConfigProxy;
} }
export function newDisplayConfig(extPath, callback) { function newDisplayConfig(extPath, callback) {
const DisplayConfigProxy = getDisplayConfigProxy(extPath); const DisplayConfigProxy = getDisplayConfigProxy(extPath);
new DisplayConfigProxy( new DisplayConfigProxy(
Gio.DBus.session, Gio.DBus.session,
@ -190,7 +193,7 @@ function performOptimalModeCheck(displayConfigProxy, connectorName, headsetAsPri
} }
// Monitor change handling // Monitor change handling
export const MonitorManager = GObject.registerClass({ var MonitorManager = GObject.registerClass({
Properties: { Properties: {
'use-optimal-monitor-config': GObject.ParamSpec.boolean( 'use-optimal-monitor-config': GObject.ParamSpec.boolean(
'use-optimal-monitor-config', 'use-optimal-monitor-config',

View File

@ -1,6 +1,6 @@
import Gio from 'gi://Gio'; const Gio = imports.gi.Gio;
export function getShaderSource(path) { function getShaderSource(path) {
const file = Gio.file_new_for_path(path); const file = Gio.file_new_for_path(path);
const data = file.load_contents(null); const data = file.load_contents(null);

View File

@ -1,11 +1,11 @@
export function getEpochSec() { function getEpochSec() {
return toSec(Date.now()); return toSec(Date.now());
} }
export function toSec(milliseconds) { function toSec(milliseconds) {
return Math.floor(milliseconds / 1000); return Math.floor(milliseconds / 1000);
} }
export function isValidKeepAlive(dateSec, strictCheck = false) { function isValidKeepAlive(dateSec, strictCheck = false) {
return Math.abs(toSec(Date.now()) - dateSec) <= (strictCheck ? 1 : 5); return Math.abs(toSec(Date.now()) - dateSec) <= (strictCheck ? 1 : 5);
} }

View File

@ -1,13 +1,15 @@
import Clutter from 'gi://Clutter'; const Clutter = imports.gi.Clutter;
import Cogl from 'gi://Cogl'; const Cogl = imports.gi.Cogl;
import GdkPixbuf from 'gi://GdkPixbuf'; const GdkPixbuf = imports.gi.GdkPixbuf;
import GLib from 'gi://GLib'; const GLib = imports.gi.GLib;
import GObject from 'gi://GObject'; const GObject = imports.gi.GObject;
import Shell from 'gi://Shell'; const Shell = imports.gi.Shell;
import Globals from './globals.js'; const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
import { const Globals = Me.imports.globals;
const {
dataViewEnd, dataViewEnd,
dataViewUint8, dataViewUint8,
dataViewBigUint, dataViewBigUint,
@ -21,12 +23,12 @@ import {
FLOAT_SIZE, FLOAT_SIZE,
UINT_SIZE, UINT_SIZE,
UINT8_SIZE UINT8_SIZE
} from "./ipc.js"; } = Me.imports.ipc;
import { degreeToRadian } from "./math.js"; const { degreeToRadian } = Me.imports.math;
import { getShaderSource } from "./shader.js"; const { getShaderSource } = Me.imports.shader;
import { isValidKeepAlive, toSec } from "./time.js"; const { isValidKeepAlive, toSec } = Me.imports.time;
export const IPC_FILE_PATH = "/dev/shm/breezy_desktop_imu"; var IPC_FILE_PATH = "/dev/shm/breezy_desktop_imu";
// the driver should be using the same data layout version // the driver should be using the same data layout version
const DATA_LAYOUT_VERSION = 3; const DATA_LAYOUT_VERSION = 3;
@ -220,7 +222,7 @@ function checkParityByte(dataView) {
return parityByte === parity; return parityByte === parity;
} }
export const XREffect = GObject.registerClass({ var XREffect = GObject.registerClass({
Properties: { Properties: {
'supported-device-detected': GObject.ParamSpec.boolean( 'supported-device-detected': GObject.ParamSpec.boolean(
'supported-device-detected', 'supported-device-detected',