Disable global shortcuts on older plasma versions (#11157)

Co-authored-by: Eugene <inbox@null.page>
This commit is contained in:
Mario Limonciello
2026-04-22 21:00:14 +02:00
committed by GitHub
co-authored by Eugene
parent abc16d2ab6
commit c3ede45627
2 changed files with 61 additions and 0 deletions
+60
View File
@@ -1,6 +1,7 @@
import { app, ipcMain, Menu, Tray, shell, screen, globalShortcut, MenuItemConstructorOptions, WebContents } from 'electron'
import promiseIpc from 'electron-promise-ipc'
import * as remote from '@electron/remote/main'
import { spawnSync } from 'child_process'
import { exec } from 'mz/child_process'
import * as path from 'path'
import * as fs from 'fs'
@@ -21,6 +22,7 @@ export class Application {
private tray?: Tray
private ptyManager = new PTYManager()
private windows: Window[] = []
private cachedPlasmaVersion?: [number, number] | null
private globalHotkey$ = new Subject<void>()
private quitRequested = false
userPluginsPath: string
@@ -38,6 +40,9 @@ export class Application {
ipcMain.on('app:register-global-hotkey', (_event, specs) => {
globalShortcut.unregisterAll()
if (!this.shouldRegisterGlobalHotkeys()) {
return
}
for (const spec of specs) {
globalShortcut.register(spec, () => this.globalHotkey$.next())
}
@@ -220,6 +225,61 @@ export class Application {
return !!this.windows.length
}
private shouldRegisterGlobalHotkeys (): boolean {
const hotkeyMode = this.configStore.hacks?.globalHotkey
if (hotkeyMode != null) {
return !hotkeyMode
}
if (process.platform !== 'linux' || !this.isWaylandSession() || !this.isPlasmaSession()) {
return true
}
const plasmaVersion = this.getPlasmaVersion()
return plasmaVersion ? this.compareVersions(plasmaVersion, [6, 6]) >= 0 : false
}
private isWaylandSession (): boolean {
return (process.env.XDG_SESSION_TYPE ?? '').toLowerCase() === 'wayland' || !!process.env.WAYLAND_DISPLAY
}
private isPlasmaSession (): boolean {
const sessionInfo = [
process.env.XDG_CURRENT_DESKTOP,
process.env.DESKTOP_SESSION,
process.env.GDMSESSION,
].join(':').toLowerCase()
return process.env.KDE_FULL_SESSION === 'true' || sessionInfo.includes('kde') || sessionInfo.includes('plasma')
}
private getPlasmaVersion (): [number, number] | null {
if (this.cachedPlasmaVersion !== undefined) {
return this.cachedPlasmaVersion
}
try {
const result = spawnSync('plasmashell', ['--version'], { encoding: 'utf8' })
const output = result.stdout + result.stderr
const match = /(\d+)\.(\d+)(?:\.(\d+))?/.exec(output)
this.cachedPlasmaVersion = match ? [
parseInt(match[1], 10),
parseInt(match[2], 10),
] : null
} catch {
this.cachedPlasmaVersion = null
}
return this.cachedPlasmaVersion ?? null
}
private compareVersions (a: [number, number], b: [number, number]): number {
for (let i = 0; i < 2; i++) {
if (a[i] !== b[i]) {
return a[i] - b[i]
}
}
return 0
}
focus (): void {
for (const window of this.windows) {
window.present()
+1
View File
@@ -58,5 +58,6 @@ hacks:
disableGPU: false
disableVibrancyWhileDragging: false
enableFluentBackground: false
globalHotkey: null
language: null
defaultQuickConnectProvider: "ssh"