Skip to content

Instantly share code, notes, and snippets.

@SergKolo
Created November 3, 2016 10:55
Show Gist options
  • Save SergKolo/b78b12cd32537f5d94f084fe00d9e092 to your computer and use it in GitHub Desktop.
Save SergKolo/b78b12cd32537f5d94f084fe00d9e092 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# Author: Serg Kolo
# Date: Oct 3rd, 2016
# Description: Script for aligning the center of
# user's active window with the center of the monitor
# Tested on: Ubuntu 16.04
from __future__ import print_function
from gi.repository import Gdk,Gio
import subprocess
import sys
def gsettings_get(schema, path, key):
"""Get value of gsettings schema"""
if path is None:
gsettings = Gio.Settings.new(schema)
else:
gsettings = Gio.Settings.new_with_path(schema, path)
return gsettings.get_value(key)
def get_x_offset():
schema = 'org.compiz.unityshell'
path = '/org/compiz/profiles/unity/plugins/unityshell/'
key = 'icon-size'
return gsettings_get(schema,path,key)
def get_y_offset(*args):
command = ['xprop','-notype','_NET_FRAME_EXTENTS',
'-id',str(args[0])
]
out = subprocess.check_output(command)
return int(out.decode().strip().split(',')[-2])
def main():
screen = Gdk.Screen.get_default()
window = screen.get_active_window()
window.unmaximize()
window_width = window.get_width()
window_height = window.get_height()
window_y = window.get_origin()[-1]
window_monitor = screen.get_monitor_at_window(window)
monitor_width = screen.get_monitor_geometry(window_monitor).width
x_offset = int(str(get_x_offset()))
new_width = int(float(sys.argv[1]) * (monitor_width - x_offset))
print(monitor_width,new_width)
window.resize(new_width,window_height)
window.process_all_updates()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment