import IBus from 'gi://IBus'; import * as Main from 'resource:///org/gnome/shell/ui/main.js'; import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js'; import { getInputSourceManager, INPUT_SOURCE_TYPE_XKB, INPUT_SOURCE_TYPE_IBUS, } from 'resource:///org/gnome/shell/ui/status/keyboard.js'; import {getIBusManager} from 'resource:///org/gnome/shell/misc/ibusManager.js'; export default class HangulOverviewLatin extends Extension { enable() { this._showingId = Main.overview.connect('showing', () => this._ensureLatin()); } disable() { Main.overview.disconnect(this._showingId); this._showingId = null; } _ensureLatin() { const ism = getInputSourceManager(); const src = ism.currentSource; if (src?.type !== INPUT_SOURCE_TYPE_IBUS || !src.id.startsWith('hangul')) return; // ibus-hangul's InputMode handler toggles regardless of the state // argument, so only activate it when currently in Hangul mode. const prop = this._findProp(src.properties, 'InputMode'); if (prop) { if (prop.get_state() === IBus.PropState.CHECKED) { getIBusManager().activateProperty( prop.get_key(), IBus.PropState.UNCHECKED); } return; } // No InputMode property: switch to the first xkb source instead for (const i of Object.keys(ism.inputSources)) { if (ism.inputSources[i].type === INPUT_SOURCE_TYPE_XKB) { ism.inputSources[i].activate(true); return; } } } _findProp(props, key) { for (let i = 0, prop; (prop = props?.get(i)); i++) { if (prop.get_key() === key) return prop; } return null; } }