root/sx-background/sxbackground.py

Revision 880d60de64b64afb023616ad34572f19e3068f3b, 1.8 KB (checked in by Friedrich Weber <fred@…>, 14 months ago)

samurai-x2 and plugins: fixed imports (hope i didn't forget anything)

  • Property mode set to 100644
Line 
1import sys
2
3from samuraix.plugin import Plugin
4from samuraix.screen import Screen
5from ooxcb.contrib import cairo
6from ooxcb.protocol import xproto
7import ooxcb
8
9from yahiko.ui import Window
10
11
12def yahiko_render(cr, style, width, height):
13    win = Window(style=style)
14    win.set_render_coords(0, 0, width, height)
15    win.render(cr)
16
17
18def set_root(conn, screen_info, style, func=None):
19    root = screen_info.root
20    geom = root.get_geometry().reply()
21    pixmap = xproto.Pixmap.create(
22            conn, 
23            root, 
24            geom.width, geom.height, 
25            screen_info.root_depth
26    )
27
28    surface = cairo.cairo_xcb_surface_create(
29        conn,
30        pixmap,
31        screen_info.get_root_visual_type(),
32        geom.width, geom.height,
33    )
34    root.change_attributes(back_pixmap=pixmap)
35    cr = cairo.cairo_create(surface)
36    if func is None:
37        func = yahiko_render
38    func(cr, style, geom.width, geom.height)
39
40    root.clear_area(0, 0, geom.width, geom.height)
41    conn.flush()
42
43
44class SXBackground(Plugin):
45    def __init__(self, app):
46        self.app = app
47        app.push_handlers(self)
48
49    def on_load_config(self, config):
50        self.config = config
51
52    def on_ready(self, app):
53        for screen in self.app.screens:
54            self.on_add_screen(app, screen)
55
56    def on_add_screen(self, app, screen):
57        style = self.config.get('background.style')
58        if style:
59            set_root(screen.conn, screen.info, style)
60
61
62def run():
63    conn = ooxcb.connect()
64
65    setup = conn.get_setup()
66
67    import simplejson
68    style = simplejson.loads(sys.argv[1])
69
70    try:
71        for i in xrange(setup.roots_len):
72            screen_info = conn.get_setup().roots[i]
73            set_root(conn, screen_info, style)
74    finally:
75        conn.disconnect()
76
77
78
79
Note: See TracBrowser for help on using the browser.