diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-02-26 02:59:31 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-02-26 02:59:31 +0100 |
commit | 30c54eb40dbd1e27ba24724997f1393f8488e556 (patch) | |
tree | 17b61f125928389deae34a18b9af3db8c9a967d2 /src | |
parent | place a black panel either on the top or the bottom (diff) | |
download | xpybar-30c54eb40dbd1e27ba24724997f1393f8488e556.tar.gz xpybar-30c54eb40dbd1e27ba24724997f1393f8488e556.tar.bz2 xpybar-30c54eb40dbd1e27ba24724997f1393f8488e556.tar.xz |
flexibility
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rwxr-xr-x | src/__main__.py | 53 | ||||
-rw-r--r-- | src/x.py | 106 |
2 files changed, 130 insertions, 29 deletions
diff --git a/src/__main__.py b/src/__main__.py index 36ee486..72575cf 100755 --- a/src/__main__.py +++ b/src/__main__.py @@ -1,43 +1,39 @@ #!/usr/bin/env python3 +''' +xpybar – xmobar replacement written in python +Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) -import time, sys -import Xlib.display, Xlib.Xatom, Xlib.ext.randr, Xlib.X +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. -WIDTH, HEIGHT, LEFT, TOP, Y = 1600, 12, 1600, 24, 1200 - 24 - 12 +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. -display = Xlib.display.Display() -screen = display.screen() +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +''' -window = screen.root.create_window(LEFT, Y, WIDTH, HEIGHT, 0, screen.root_depth, - Xlib.X.InputOutput, Xlib.X.CopyFromParent, - event_mask = ( - Xlib.X.StructureNotifyMask | - Xlib.X.ButtonReleaseMask - ), - colormap = Xlib.X.CopyFromParent) +import Xlib.display, Xlib.Xatom, Xlib.ext.randr, Xlib.X -window.set_wm_name('xpybar') -window.set_wm_icon_name('xpybar') -window.set_wm_class('bar', 'xpybar') +from x import * -_CARD = display.intern_atom("CARDINAL") -_PSTRUT = display.intern_atom("_NET_WM_STRUT_PARTIAL") -window.change_property(_PSTRUT, _CARD, 32, topx(LEFT, TOP, WIDTH, HEIGHT)) -top = lambda x, y, width, height : [0, 0, y + height, 0, 0, 0, 0, 0, x, x + width, 0, 0] -bottom = lambda x, y, width, height : [0, 0, 0, y + height, 0, 0, 0, 0, 0, 0, x, x + width] +open_x() -_ATOM = display.intern_atom("ATOM") -_TYPE = display.intern_atom("_NET_WM_WINDOW_TYPE") -_DOCK = display.intern_atom("_NET_WM_WINDOW_TYPE_DOCK") -window.change_property(_TYPE, _ATOM, 32, [_DOCK]) +width, height, left, top, panel_height, at_top = get_monitors()[0][:3] + [24, 1 * 12, True] +print(width, height, left, top) +display = get_display() +window = create_panel(width, height, left, top, panel_height, at_top) gc = window.create_gc() window.map() display.flush() -e = None while True: try: e = display.next_event() @@ -45,11 +41,10 @@ while True: break except KeyboardInterrupt: break - gc.change(foreground = screen.black_pixel) - window.fill_rectangle(gc, 0, 0, 1600, 12) + gc.change(foreground = get_screen().black_pixel) + window.fill_rectangle(gc, 0, 0, width, panel_height) display.flush() window.unmap() -display.flush() -display.close() +close_x() diff --git a/src/x.py b/src/x.py new file mode 100644 index 0000000..f82a943 --- /dev/null +++ b/src/x.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python3 +''' +xpybar – xmobar replacement written in python +Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +''' + +import subprocess +import Xlib.display, Xlib.Xatom, Xlib.ext.randr, Xlib.X + + +display = None +screen = None +screen_i = None + + +def open_x(screen_no = None): + global display, screen, screen_i + display = Xlib.display.Display() + screen_i = screen_no if screen_no is not None else display.get_default_screen() + screen = display.screen(screen_i) + + +def get_monitors(): + global screen_i + p = subprocess.Popen(['xrandr'], stdout = subprocess.PIPE) + p = p.communicate()[0].decode('utf-8', 'replace') + s = -1 + rc = [] + prim = None + for line in p.split('\n'): + if line.startswith('Screen '): + s = int(line[len('Screen '):].split(':')[0]) + elif s == screen_i: + if ' connected ' in line: + m = line.replace('-', '+-').replace('++', '+') + p = ' primary ' in m + m = m.replace(' primary ', ' ') + m = m.split(' ')[2].replace('+', 'x').split('x') + m = [int(x) for x in m] + if p and (prim is None): + prim = m + else: + rc.append(m) + if prim is not None: + rc = [prim] + rc + return rc + + +def get_display(): + global display + return display + + +def get_screen(): + global screen + return screen + + +def create_panel(width, height, left, top, panel_height, at_top): + global display, screen + ypos = top if at_top else (height - top - panel_height) + window = screen.root.create_window(left, ypos, width, panel_height, 0, screen.root_depth, + Xlib.X.InputOutput, Xlib.X.CopyFromParent, + event_mask = ( + Xlib.X.StructureNotifyMask | + Xlib.X.ButtonReleaseMask + ), + colormap = Xlib.X.CopyFromParent) + + top_ = lambda x, y, w, h : [0, 0, y + h, 0, 0, 0, 0, 0, x, x + w, 0, 0] + bottom_ = lambda x, y, w, h : [0, 0, 0, y + h, 0, 0, 0, 0, 0, 0, x, x + w] + + window.set_wm_name('xpybar') + window.set_wm_icon_name('xpybar') + window.set_wm_class('bar', 'xpybar') + + _CARD = display.intern_atom("CARDINAL") + _PSTRUT = display.intern_atom("_NET_WM_STRUT_PARTIAL") + window.change_property(_PSTRUT, _CARD, 32, (top_ if at_top else bottom_)(left, top, width, panel_height)) + + _ATOM = display.intern_atom("ATOM") + _TYPE = display.intern_atom("_NET_WM_WINDOW_TYPE") + _DOCK = display.intern_atom("_NET_WM_WINDOW_TYPE_DOCK") + window.change_property(_TYPE, _ATOM, 32, [_DOCK]) + + return window + + +def close_x(): + global display + display.flush() + display.close() + |