-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add support for Gnome 45, which breaks backward extension compatibility. We now ship and maintain two extensions :/. The main change in Gnome seems to be the switch from a custom import implementation to 'standard' ES6 style imports. The init method also seems to have inexplicably been swapped out in favour of extending a magic class. This patch takes the opportunity to clean up some residual cruft and move the extension code out of the mapper script. Specifically: - Ship distinct extensions for Gnome 42-44 and Gnome 45 in /usr/local/share/keyd - Move the named pipe to XDG_RUNTIME_DIR - Initialize the pipe inside the extension instead of the script to avoid potential race conditions during initialization.
- Loading branch information
Showing
6 changed files
with
180 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import * as Main from 'resource:///org/gnome/shell/ui/main.js'; | ||
import GLib from 'gi://GLib'; | ||
import Shell from 'gi://Shell'; | ||
import Gio from 'gi://Gio'; | ||
import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js'; | ||
|
||
let file = Gio.File.new_for_path(makePipe()); | ||
let pipe = file.append_to_async(0, 0, null, on_pipe_open); | ||
|
||
function makePipe() { | ||
let runtime_dir = GLib.getenv('XDG_RUNTIME_DIR'); | ||
if (!runtime_dir) | ||
runtime_dir = '/run/user/'+new TextDecoder().decode( | ||
GLib.spawn_command_line_sync('id -u')[1] | ||
).trim(); | ||
|
||
let path = runtime_dir + '/keyd.fifo'; | ||
GLib.spawn_command_line_sync('mkfifo ' + path); | ||
|
||
return path; | ||
} | ||
|
||
function send(msg) { | ||
if (!pipe) | ||
return; | ||
|
||
try { | ||
pipe.write(msg, null); | ||
} catch { | ||
log('pipe closed, reopening...'); | ||
pipe = null; | ||
file.append_to_async(0, 0, null, on_pipe_open); | ||
} | ||
} | ||
|
||
function on_pipe_open(file, res) { | ||
log('pipe opened'); | ||
pipe = file.append_to_finish(res); | ||
} | ||
|
||
export default class KeydExtension extends Extension { | ||
enable() { | ||
Shell.WindowTracker.get_default().connect('notify::focus-app', () => { | ||
const win = global.display.focus_window; | ||
const cls = win ? win.get_wm_class() : 'root'; | ||
const title = win ? win.get_title() : ''; | ||
|
||
send(`${cls} ${title}\n`); | ||
}); | ||
|
||
Main.layoutManager.connectObject( | ||
'system-modal-opened', () => { | ||
send(`system-modal ${global.stage.get_title()}\n`); | ||
}, | ||
this | ||
); | ||
|
||
GLib.spawn_command_line_async('keyd-application-mapper -d'); | ||
} | ||
|
||
disable() { | ||
GLib.spawn_command_line_async('pkill -f keyd-application-mapper'); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "keyd", | ||
"description": "Used by keyd to obtain active window information.", | ||
"uuid": "keyd", | ||
"shell-version": [ "45" ] | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
const Shell = imports.gi.Shell; | ||
const GLib = imports.gi.GLib; | ||
const Gio = imports.gi.Gio; | ||
const Main = imports.ui.main; | ||
|
||
let file = Gio.File.new_for_path(makePipe()); | ||
let pipe = file.append_to_async(0, 0, null, on_pipe_open); | ||
|
||
function makePipe() { | ||
let runtime_dir = GLib.getenv('XDG_RUNTIME_DIR'); | ||
if (!runtime_dir) | ||
runtime_dir = '/run/user/'+new TextDecoder().decode( | ||
GLib.spawn_command_line_sync('id -u')[1] | ||
).trim(); | ||
|
||
let path = runtime_dir + '/keyd.fifo'; | ||
GLib.spawn_command_line_sync('mkfifo ' + path); | ||
|
||
return path; | ||
} | ||
|
||
function send(msg) { | ||
if (!pipe) | ||
return; | ||
|
||
try { | ||
pipe.write(msg, null); | ||
} catch { | ||
log('pipe closed, reopening...'); | ||
pipe = null; | ||
file.append_to_async(0, 0, null, on_pipe_open); | ||
} | ||
} | ||
|
||
function on_pipe_open(file, res) { | ||
log('pipe opened'); | ||
pipe = file.append_to_finish(res); | ||
} | ||
|
||
function init() { | ||
return { | ||
enable: function() { | ||
Shell.WindowTracker.get_default().connect('notify::focus-app', () => { | ||
const win = global.display.focus_window; | ||
const cls = win ? win.get_wm_class() : 'root'; | ||
const title = win ? win.get_title() : ''; | ||
|
||
send(`${cls} ${title}\n`); | ||
}); | ||
|
||
Main.layoutManager.connectObject( | ||
'system-modal-opened', () => { | ||
send(`system-modal ${global.stage.get_title()}\n`); | ||
}, | ||
this | ||
); | ||
|
||
GLib.spawn_command_line_async('keyd-application-mapper -d'); | ||
}, | ||
|
||
disable: function() { | ||
GLib.spawn_command_line_async('pkill -f keyd-application-mapper'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "keyd", | ||
"description": "Used by keyd to obtain active window information.", | ||
"uuid": "keyd", | ||
"shell-version": [ "42", "43", "44" ] | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters