From 63963aba09fc4f158419de9bfb3f41ef58d61fde Mon Sep 17 00:00:00 2001 From: DaPigGuy Date: Tue, 18 Mar 2025 03:53:31 -0700 Subject: [PATCH 1/2] refactor: simplify GNOME version compatibility methods Needing to pass every version in existence is a needless maintenance burden, so don't. --- src/prefs/prefs.ts | 4 ++-- src/utils/compatibility.ts | 41 +++++++++++++++----------------------- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/src/prefs/prefs.ts b/src/prefs/prefs.ts index f7d64ecb..8df8ea36 100644 --- a/src/prefs/prefs.ts +++ b/src/prefs/prefs.ts @@ -5,7 +5,7 @@ import Gtk4 from '@girs/gtk-4.0'; import { CustomizationPage } from '@pano/prefs/customization'; import { DangerZonePage } from '@pano/prefs/dangerZone'; import { GeneralPage } from '@pano/prefs/general'; -import { isGnome47OrHigher } from '@pano/utils/compatibility'; +import { isGnomeVersionOrHigher } from '@pano/utils/compatibility'; export default class PanoExtensionPreferences extends ExtensionPreferences { override fillPreferencesWindow(window: Adw.PreferencesWindow): Promise | void { @@ -23,7 +23,7 @@ export default class PanoExtensionPreferences extends ExtensionPreferences { * gnome 47 explicitly states, that we need to return a Promise, so we check the version at runtime and decide what to return, to support older versions of gnome shell, that don't expected a promise here * @see https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/extensions/prefs.js#L34 */ - if (isGnome47OrHigher()) { + if (isGnomeVersionOrHigher(47)) { return Promise.resolve(); } return; diff --git a/src/utils/compatibility.ts b/src/utils/compatibility.ts index 9de868ec..c326b009 100644 --- a/src/utils/compatibility.ts +++ b/src/utils/compatibility.ts @@ -4,38 +4,29 @@ import { Notification, Source as MessageTraySource } from '@girs/gnome-shell/dis import St from '@girs/st-16'; // compatibility functions to check if a specific gnome-shell is used -export function isGnomeVersion(version: number): boolean { - const [major, _minor, _patch, ..._rest]: Array = PACKAGE_VERSION.split('.').map((num) => { - const result = parseInt(num); - if (isNaN(result)) { - return undefined; - } - return result; - }); - - if (major === undefined) { - return PACKAGE_VERSION.includes(version.toString()); +const GNOME_VERSION = PACKAGE_VERSION.split('.').reduce((acc, str): number[] => { + const result = parseInt(str); + if (isNaN(result)) { + return acc; } - return major === version; -} + return [...acc, result]; +}, [] as number[]); -export function isOneGnomeVersion(versions: number[]): boolean { - for (const version of versions) { - const isVersion = isGnomeVersion(version); - if (isVersion) { - return true; - } +export function isGnomeVersionOrHigher(version: number): boolean { + if (GNOME_VERSION.length < 1) { + console.error('[pano] FATAL ERROR: gnome version not correctly detected (case 1)'); + return false; } - return false; -} + const major = GNOME_VERSION[0]; -// compatibility check functions for gnome-shell 47 + if (major === undefined) { + console.error('[pano] FATAL ERROR: gnome version not correctly detected (case 2)'); + return false; + } -// this check if it is gnome 47 or higher, which includes all supported versions above and inclusive gnome 47 -export function isGnome47OrHigher(): boolean { - return isOneGnomeVersion([47, 48]); + return major >= version; } // compatibility check functions for gnome-shell 45 / 46 From 0bc523f42f1391537e54eff2babd9a11917bdaad Mon Sep 17 00:00:00 2001 From: DaPigGuy Date: Tue, 18 Mar 2025 03:53:43 -0700 Subject: [PATCH 2/2] fix: adjust to MetaCursor changes See https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3622 Fixes #350 --- src/components/panoItem.ts | 4 ++-- src/components/searchBox.ts | 6 +++--- src/utils/shell_compatibility.ts | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/components/panoItem.ts b/src/components/panoItem.ts index 2f8cf324..f237cba0 100644 --- a/src/components/panoItem.ts +++ b/src/components/panoItem.ts @@ -13,7 +13,7 @@ import { DBItem } from '@pano/utils/db'; import { registerGObjectClass, SignalRepresentationType, SignalsDefinition } from '@pano/utils/gjs'; import { getPanoItemTypes } from '@pano/utils/panoItemType'; import { getCurrentExtensionSettings } from '@pano/utils/shell'; -import { orientationCompatibility } from '@pano/utils/shell_compatibility'; +import { MetaCursorPointer, orientationCompatibility } from '@pano/utils/shell_compatibility'; import { getVirtualKeyboard, WINDOW_POSITIONS } from '@pano/utils/ui'; export type PanoItemSignalType = 'on-remove' | 'on-favorite' | 'activated'; @@ -68,7 +68,7 @@ export class PanoItem extends St.BoxLayout { this.connect('key-focus-in', () => this.setSelected(true)); this.connect('key-focus-out', () => this.setSelected(false)); this.connect('enter-event', () => { - Shell.Global.get().display.set_cursor(Meta.Cursor.POINTING_HAND); + Shell.Global.get().display.set_cursor(MetaCursorPointer); if (!this.selected) { this.set_style(`border: 4px solid ${this.settings.get_string('hovered-item-border-color')}`); } diff --git a/src/components/searchBox.ts b/src/components/searchBox.ts index 2bed5093..294a1e1c 100644 --- a/src/components/searchBox.ts +++ b/src/components/searchBox.ts @@ -9,7 +9,7 @@ import { ItemType } from '@pano/utils/db'; import { registerGObjectClass, SignalRepresentationType, SignalsDefinition } from '@pano/utils/gjs'; import { getPanoItemTypes, ICON_PACKS } from '@pano/utils/panoItemType'; import { getCurrentExtensionSettings, gettext } from '@pano/utils/shell'; -import { orientationCompatibility } from '@pano/utils/shell_compatibility'; +import { MetaCursorPointer, orientationCompatibility } from '@pano/utils/shell_compatibility'; export type SearchBoxSignalType = | 'search-text-changed' @@ -224,10 +224,10 @@ export class SearchBox extends St.BoxLayout { } icon.connect('enter-event', () => { - Shell.Global.get().display.set_cursor(Meta.Cursor.POINTING_HAND); + Shell.Global.get().display.set_cursor(MetaCursorPointer); }); icon.connect('motion-event', () => { - Shell.Global.get().display.set_cursor(Meta.Cursor.POINTING_HAND); + Shell.Global.get().display.set_cursor(MetaCursorPointer); }); icon.connect('leave-event', () => { Shell.Global.get().display.set_cursor(Meta.Cursor.DEFAULT); diff --git a/src/utils/shell_compatibility.ts b/src/utils/shell_compatibility.ts index 1164e434..12428325 100644 --- a/src/utils/shell_compatibility.ts +++ b/src/utils/shell_compatibility.ts @@ -22,6 +22,22 @@ function metaSupportsUnredirectForDisplay() { ); } +// Meta.Cursor.POINTING_HAND was renamed to Meta.Cursor.POINTER in GNOME 48 (Meta 16) + +interface NewMetaCursor { + POINTER: Meta.Cursor | null | undefined; +} + +export const MetaCursorPointer: Meta.Cursor = (() => { + const pointer = (Meta.Cursor as unknown as NewMetaCursor).POINTER; + + if (pointer !== undefined && pointer !== null) { + return pointer; + } + + return Meta.Cursor.POINTING_HAND; +})(); + // actual compatibility functions export type OrientationReturnType = { vertical: boolean } | { orientation: Clutter.Orientation };