Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/scripts/xinitrc
blob: a87019ade35578647837d4c1a6ab2e6729f50196 (plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/python

import os
import subprocess
import signal

from gi.repository import SugarRunner

devnull = open("/dev/null")
main_loop = None


def _write_display(display_path):
    tmp_display_path = "%s.tmp" % display_path

    with open(tmp_display_path, "w") as f:
        f.write(os.environ["DISPLAY"])

    os.rename(tmp_display_path, display_path)


def _setup_outputs():
    """Sugar doesn't handle multiple outputs properly. To avoid issues
       we keep the first output in the list returned by xrandr and turn
       off everything else.
    """
    outputs = SugarRunner.list_outputs()
    if not outputs:
        return

    on_output = os.environ.get("SUGAR_RUNNER_OUTPUT", outputs[0])
    for output in outputs:
        if output != on_output:
            subprocess.check_call(["xrandr", "--output", output, "--off"])


def _load_xkb_config():
    if "SUGAR_RUNNER_XKBCONFIG" not in os.environ:
        return

    with open(os.environ["SUGAR_RUNNER_XKBCONFIG"]) as f:
        config = f.read()

    process = subprocess.Popen(["xkbcomp", "-", os.environ["DISPLAY"]],
                               stdin=subprocess.PIPE, stdout=devnull)
    process.communicate(input=config)


def _child_watch_cb(pid, condition):
    window_pid = os.environ.get("SUGAR_RUNNER_WINDOW_PID", None)
    if window_pid:
        os.kill(int(window_pid), signal.SIGTERM)

    global main_loop
    main_loop.quit()


def _add_output_to_environ(output):
    for line in output.strip().split("\n"):
        name, value = line.strip().split("=", 1)
        os.environ[name] = value


def _start_dbus():
    output = subprocess.check_output(["dbus-launch", "--exit-with-session"])
    _add_output_to_environ(output)


def _start_keyring():
    output = subprocess.check_output(["gnome-keyring-daemon",
                                      "--start", "-d",
                                      "--components=secrets,pkcs11,ssh,gpg"])
    _add_output_to_environ(output)

if "SUGAR_RUNNER_DISPLAY_PATH" in os.environ:
    _write_display(os.environ["SUGAR_RUNNER_DISPLAY_PATH"])

_setup_outputs()
_load_xkb_config()
_start_dbus()
_start_keyring()

subprocess.check_call(["sugar"])