Skip to content

Instantly share code, notes, and snippets.

@flozz
Created May 14, 2018 18:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flozz/cf5492f483841f38500c633cef13dc27 to your computer and use it in GitHub Desktop.
Save flozz/cf5492f483841f38500c633cef13dc27 to your computer and use it in GitHub Desktop.
A small hack that allows to manipulate windows on GNOME Shell / Wayland
#!/usr/bin/env python
import json
import pydbus
GNOME_SHELL = "org.gnome.Shell"
META_WINDOW_JS = """
(function(params) {
function _findWindow(windowTitle) {
for (var i = 0 ; i < windowActors.length ; i++) {
var win = windowActors[i].get_meta_window();
if (win.get_title() == windowTitle) {
return win;
}
}
return null;
}
var windowActors = global.get_window_actors();
var win = _findWindow(params.uuid);
if (win) {
if (params.position !== undefined) {
win.move_frame(false, params.position[0], params.position[1]);
}
if (params.above === true) {
win.make_above();
}
if (params.above === false) {
win.unmake_above();
}
if (params.stick === true) {
win.stick();
}
if (params.stick === false) {
win.unstick();
}
}
})(%s);
"""
def _exec_js(js, params):
js = js % json.dumps(params)
bus = pydbus.SessionBus()
shell = bus.get(GNOME_SHELL)
shell.Eval(js)
_exec_js(META_WINDOW_JS, {
"uuid": "Simple Screencast",
"above": True
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment