@@ -1,9 +1,10 @@
|
||||
import Gio from 'gi://Gio';
|
||||
import Meta from 'gi://Meta';
|
||||
import Shell from 'gi://Shell';
|
||||
|
||||
const BUS = 'io.qvac.Jarvis.Shell';
|
||||
const PATH = '/io/qvac/Jarvis/Shell';
|
||||
const XML = `<node><interface name="io.qvac.Jarvis.Shell"><method name="ListWindows"><arg type="s" direction="out"/></method><method name="FocusedWindow"><arg type="s" direction="out"/></method><method name="FocusWindow"><arg type="t" direction="in"/></method></interface></node>`;
|
||||
const XML = `<node><interface name="io.qvac.Jarvis.Shell"><method name="ListWindows"><arg type="s" direction="out"/></method><method name="FocusedWindow"><arg type="s" direction="out"/></method><method name="FocusWindow"><arg type="t" direction="in"/></method><method name="Screenshot"><arg type="s" direction="in"/><arg type="s" direction="out"/></method></interface></node>`;
|
||||
const describe = (window) => ({ id: Number(window.get_id?.() || 0), title: window.get_title?.() || '', wm_class: window.get_wm_class?.() || '', pid: Number(window.get_pid?.() || 0), rect: (() => { const r = window.get_frame_rect?.(); return r ? [r.x, r.y, r.width, r.height] : null; })(), focused: window === global.display.get_focus_window?.() });
|
||||
|
||||
export function installShellService() {
|
||||
@@ -11,6 +12,17 @@ export function installShellService() {
|
||||
ListWindows() { const windows = global.display.get_tab_list(Meta.TabList.NORMAL_ALL, null).map(describe); return JSON.stringify(windows); },
|
||||
FocusedWindow() { const window = global.display.get_focus_window?.(); return JSON.stringify(window ? describe(window) : null); },
|
||||
FocusWindow(id) { const window = global.display.get_tab_list(Meta.TabList.NORMAL_ALL, null).find((candidate) => Number(candidate.get_id?.()) === Number(id)); if (!window) throw new Error('window not found'); window.activate(global.get_current_time()); },
|
||||
async Screenshot(filename) {
|
||||
const file = Gio.File.new_for_path(filename);
|
||||
const stream = file.replace(null, false, Gio.FileCreateFlags.REPLACE_DESTINATION, null);
|
||||
try {
|
||||
const screenshot = new Shell.Screenshot();
|
||||
await screenshot.screenshot(false, stream);
|
||||
} finally {
|
||||
stream.close(null);
|
||||
}
|
||||
return filename;
|
||||
},
|
||||
};
|
||||
const ownerId = Gio.bus_own_name(Gio.BusType.SESSION, BUS, Gio.BusNameOwnerFlags.NONE, (connection) => { const exported = Gio.DBusExportedObject.wrapJSObject(XML, implementation); exported.export(connection, PATH); implementation._exported = exported; }, null, () => {});
|
||||
return () => { implementation._exported?.unexport(); Gio.bus_unown_name(ownerId); };
|
||||
|
||||
Reference in New Issue
Block a user