Last active
December 30, 2015 14:09
-
-
Save kwon37xi/7840457 to your computer and use it in GitHub Desktop.
Linux X Window Screen margin reservation tool.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import gtk | |
import sys | |
''' | |
X Window left/right edge margin reservation tool | |
Other windows cannot overlap the margin area. | |
Usage: screenmargin.py left|right pixel | |
# reserve left side 100 pixel | |
screenmargin.py left 100 | |
# reserve right side 64 pixel | |
screenmargin.py right 64 | |
Requirements: | |
pygtk | |
Reference: | |
_NET_WM_STRUT, _NET_WM_STRUT_PARTIAL | |
http://stackoverflow.com/questions/3859045/preventing-window-overlap-in-gtk | |
''' | |
class ScreenMargin: | |
ALLOWED_POSITIONS = ['left', 'right'] | |
def __init__(self, position, width): | |
self.width = width | |
if position not in ScreenMargin.ALLOWED_POSITIONS: | |
raise Exception('Unknown position : ' + self.position) | |
self.position = position | |
def show(self): | |
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) | |
self.window.set_default_size(self.width, 1) | |
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DOCK) | |
self.window.show() | |
self.set_position() | |
def set_position(self): | |
if self.position == 'left': | |
self.window.move(0, 0) | |
self.window.window.property_change("_NET_WM_STRUT", "CARDINAL", 32, | |
gtk.gdk.PROP_MODE_REPLACE, [self.width, 0, 0, 0]) | |
else: | |
self.window.move(gtk.gdk.screen_width() - self.width, 0) | |
self.window.window.property_change("_NET_WM_STRUT", "CARDINAL", 32, | |
gtk.gdk.PROP_MODE_REPLACE, [0, self.width, 0, 0]) | |
if __name__ == '__main__': | |
position = sys.argv[1] | |
width = int(sys.argv[2]) | |
app = ScreenMargin(position, width) | |
app.show() | |
gtk.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment