public
Description: A dynamic, hackable window manager written in Python
Homepage: http://incise.org/whimsy.html
Clone URL: git://github.com/mackstann/whimsy.git
whimsy / whimsy / main.py
100644 47 lines (35 sloc) 1.636 kb
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
# Written by Nick Welch in the years 2005-2008. Author disclaims copyright.
 
import os, signal
 
from Xlib import display
from Xlib.support.connect import get_display
 
from whimsy.signals import publisher
from whimsy.models.window_manager import window_manager
from whimsy.models.layout import layout
from whimsy.controllers.x_event_controller import x_event_controller
from whimsy.controllers.tick_controller import tick_controller
 
def wait_signal_handler(*args):
    try:
        os.waitpid(-1, os.WNOHANG | os.WUNTRACED)
    except OSError:
        pass
 
class main(object):
    def __init__(self):
        os.environ['DISPLAY'] = get_display(None)[0]
 
        self.dpy = display.Display()
        self.hub = publisher()
        self.wm = window_manager(self.hub, self.dpy)
        self.layout = layout(self.hub, self.wm)
        self.xec = x_event_controller(self.hub, self.dpy)
        self.ticker = tick_controller(self.hub)
 
        self.hub.defaults['wm'] = self.wm
        self.hub.defaults['hub'] = self.hub
 
        self.hub.attach('tick', self.xec.select_and_emit_all)
 
    def run(self):
        signal.signal(signal.SIGCHLD, wait_signal_handler)
        signal.signal(signal.SIGTERM, lambda signum, frame: self.ticker.stop())
        signal.signal(signal.SIGINT, lambda signum, frame: self.ticker.stop())
        signal.signal(signal.SIGPIPE, lambda signum, frame: self.ticker.stop())
        signal.signal(signal.SIGUSR1, lambda signum, frame: self.ticker.stop())
        signal.signal(signal.SIGUSR2, lambda signum, frame: self.ticker.stop())
 
        self.wm.manage()
        self.ticker.tick_forever()