-
Notifications
You must be signed in to change notification settings - Fork 733
/
cinnamon-killer-daemon
executable file
·59 lines (46 loc) · 1.85 KB
/
cinnamon-killer-daemon
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
#!/usr/bin/python3
""" Creates a keybinding that allows cinnamon to be restarted by pressing Ctrl + Alt + Esc,
and runs in the background to detect that keybinding
"""
import os
import syslog
from setproctitle import setproctitle
import gi
gi.require_version('Keybinder', '3.0') # noqa
gi.require_version('Gtk', '3.0') # noqa
from gi.repository import Keybinder
from gi.repository import Gtk, Gio
SETTINGS_SCHEMA = 'org.cinnamon.desktop.keybindings.media-keys'
SETTINGS_KEY = 'restart-cinnamon'
class KillerDaemon:
def __init__(self):
Keybinder.init()
self.bindings = None
self.settings = Gio.Settings(schema_id=SETTINGS_SCHEMA)
self.apply_bindings()
self.settings.connect('changed::' + SETTINGS_KEY, self.apply_bindings)
def apply_bindings(self, settings=None, key=None):
# Ubind the previous bindings
try:
if self.bindings is not None:
for binding in self.bindings:
Keybinder.unbind(binding)
except Exception as detail:
syslog.syslog(detail)
# Get the new ones
self.bindings = self.settings.get_strv(SETTINGS_KEY)
# Bind them
try:
if self.bindings is not None:
for binding in self.bindings:
if Keybinder.bind(binding, self.restart_cinnamon, None):
syslog.syslog("Bound Cinnamon restart to %s." % binding)
except Exception as detail:
syslog.syslog(detail)
def restart_cinnamon(self, keystring, data):
os.system("nemo -n &") # restart nemo if it's not running already
os.system("cinnamon-launcher &") # restart Cinnamon whether it's running or not (can be handy in case of a DE freeze)
if __name__ == '__main__':
setproctitle("cinnamon-killer-daemon")
daemon = KillerDaemon()
Gtk.main()