aboutsummaryrefslogtreecommitdiffstats
path: root/src/__main__.py
blob: 5fee9f63a2726f801be27be31681f2892298efcd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/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 Xlib.display, Xlib.Xatom, Xlib.ext.randr, Xlib.X

from x import *


OUTPUT, HEIGHT, YPOS, TOP = 0, 12, 24, True
FONT = '-misc-fixed-*-*-*-*-10-*-*-*-*-*-*-*'
BACKGROUND, FOREGROUND = (0, 0, 0), (192, 192, 192)


open_x()

width, height, left, top, panel_height, at_top = get_monitors()[OUTPUT][:3] + [YPOS, HEIGHT, TOP]

display = get_display()
window = create_panel(width, height, left, top, panel_height, at_top)
gc = window.create_gc()
cmap = window.get_attributes().colormap

window.map()
display.flush()

background = cmap.alloc_color(*[x * 257 for x in BACKGROUND]).pixel
foreground = cmap.alloc_color(*[x * 257 for x in FOREGROUND]).pixel
font = display.open_font(FONT)
font_q = font.query()
font_height = font_q.font_ascent + font_q.font_descent
text_width = lambda text : font.query_text_extents(text).overall_width

while True:
    try:
        e = display.next_event()
        if e.type == Xlib.X.DestroyNotify:
            break
    except KeyboardInterrupt:
        break
    gc.change(foreground = background)
    window.fill_rectangle(gc, 0, 0, width, panel_height)
    gc.change(foreground = foreground)
    gc.change(font = font)
    draw_text(window, gc, 0, 10, '°°° TEST °°°')
    display.flush()

window.unmap()
close_x()