| 1 | import sys |
|---|
| 2 | |
|---|
| 3 | from samuraix.plugin import Plugin |
|---|
| 4 | from samuraix.screen import Screen |
|---|
| 5 | from ooxcb.contrib import cairo |
|---|
| 6 | from ooxcb.protocol import xproto |
|---|
| 7 | import ooxcb |
|---|
| 8 | |
|---|
| 9 | from yahiko.ui import Window |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | def 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 | |
|---|
| 18 | def 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 | |
|---|
| 44 | class 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 | |
|---|
| 62 | def 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 | |
|---|