Skip to content

Instantly share code, notes, and snippets.

@gcoda
Created October 23, 2019 07:08
Show Gist options
  • Save gcoda/46981e6b5b65c10a56ec79ef8ab649c6 to your computer and use it in GitHub Desktop.
Save gcoda/46981e6b5b65c10a56ec79ef8ab649c6 to your computer and use it in GitHub Desktop.
Gnome Shell Eval Wrapper
const { spawn } = require('child_process')
const argument = {
width: 500,
height: 300,
x: 100,
y: 100,
}
/*
https://developer.gnome.org/meta/stable/MetaWindow.html
https://developer.gnome.org/meta/stable/MetaWindowActor.html
*/
shellEval(size => {
let windows = global.get_window_actors()
windows.forEach(w => {
const mw = w.get_meta_window()
if (mw.appears_focused) {
mw.move_resize_frame(
true,
size.x,
size.y,
size.width,
size.height
)
}
})
}, argument)
shellEval(() => {
imports.ui.status.keyboard
.getInputSourceManager()
.inputSources[0].activate()
})
//.then(console.log)
/**************************************************/
function makeEvalString(fn, arg) {
return `(${fn.toString()})(${JSON.stringify(arg)})`
}
function shellEval(fn = () => {}, arg = {}) {
return new Promise(resolve => {
const str = makeEvalString(fn, arg)
const gdbus = spawn('gdbus', [
'call',
'--session',
'--dest',
'org.gnome.Shell',
'--object-path',
'/org/gnome/Shell',
'--method',
'org.gnome.Shell.Eval',
str,
])
// gdbus.stdout.on("data", data => {})
// gdbus.stderr.on("data", data => {})
gdbus.on('close', resolve)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment