概要
Linux上において親指シフトを行う際oyainputを利用している。
https://github.com/shimamu/gnome-oyainput-indicatorを参考にして導入してみた。
oyainputの挙動を監視してパネル上に表示できるようにした。
環境
- Linux mint 22
- fcitx5
- oyainput
- cinnamon
考え方
oyainputを監視して挙動を判断する。そのため、oyainputにて状態を表示するファイルを生成するようにプログラムに追加をした。
パネル上に状態を表示するためGnome extensionを利用した。
oyainputへの追加
oyainputが動いている間で親指シフトが無効になっている時にoyainput-puaseというファイルを生成してこれの有無で判定している。
/dev/shmに判定ファイルを置いているのはRAM上で十分だからである。/tmpでもよいが、より明確にRAMでの処理とした。
oyainput.cの追記をdiff形式下記に示す。
18a19
> #define PAUSE_FILE "/dev/shm/oyainput-paused"
30a32,40
> void create_pause_file() {
> int fd = open(PAUSE_FILE, O_CREAT | O_WRONLY, 0644);
> if (fd >= 0) close(fd);
> }
>
> void remove_pause_file() {
> unlink(PAUSE_FILE);
> }
>
115a129
> create_pause_file();
121a136
> remove_pause_file();
128a144
> remove_pause_file();
131a148
> create_pause_file();
199a217
> remove_pause_file();
387a406
> remove_pause_file();
390a410
> create_pause_file();
405a426
> remove_pause_file();
411a433
> create_pause_file();
これでmake;make installする。
パネル上でのoyainputの表示
"---"がoyainputが起動してない。"o--"で親指シフトがオフ、"oya"で親指シフトがオンの状態を表している。
ホームの以下(.local/share/cinnamon/extensions/gnome-oyainput-indicator@shimaumu.github.com/)に二つの拡張用のファイルを設置する。
const St = imports.gi.St;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Clutter = imports.gi.Clutter;
const Main = imports.ui.main;
const PAUSED_FILE_PATH = '/dev/shm/oyainput-paused';
let indicator;
let timeoutId;
function isPaused() {
return GLib.file_test(PAUSED_FILE_PATH, GLib.FileTest.EXISTS);
}
function isOyainputRunningAsync(callback) {
let subprocess = new Gio.Subprocess({
argv: ['pgrep', '-x', 'oyainput'],
flags: Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_PIPE,
});
subprocess.init(null);
subprocess.communicate_utf8_async(null, null, (proc, res) => {
try {
let [, stdout] = proc.communicate_utf8_finish(res);
callback(stdout.trim().length > 0);
} catch (e) {
global.logError(e);
callback(false);
}
});
}
function updateLabel() {
isOyainputRunningAsync((running) => {
indicator.set_style_class_name('');
if (!running) {
indicator.set_text('---');
} else if (isPaused()) {
indicator.set_text('o--');
indicator.set_style_class_name('paused');
} else {
indicator.set_text('oya');
indicator.set_style_class_name('running');
}
});
}
function init() { }
function enable() {
indicator = new St.Label({
text: '...',
y_align: Clutter.ActorAlign.CENTER,
style_class: 'oyainput-label',
});
// パネルの右側に追加(左側にしたい場合は _leftBox に変更)
Main.panel._rightBox.insert_child_at_index(indicator, 0);
updateLabel();
timeoutId = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 1, () => {
updateLabel();
return true;
});
}
function disable() {
if (timeoutId) {
GLib.source_remove(timeoutId);
timeoutId = null;
}
if (indicator) {
Main.panel._rightBox.remove_child(indicator);
indicator.destroy();
indicator = null;
}
}
{
"uuid": "gnome-oyainput-indicator@shimaumu.github.com",
"name": "Oyainput Indicator",
"description": "Shows the status of oyainput process",
"version": 1,
"cinnamon-version": ["5.0", "5.2", "6.0"]
}
これらを設置してから、一旦ログアウトしてから、「システムの設定」「拡張機能」にて「Oyainput indicator」を有効にする。
感想
親指シフトを多用する自分としては親指シフトが有効かどうかは気になっていたので、リンクにもあるgnome-oyainput-indicatorはありがたかった。さらにAIのサポートで実装する上で大いに参考になった。けど、修正もあった。