Skip to content

Commit

Permalink
implement the shutdown event
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Crisci committed Oct 29, 2018
1 parent 9f671a1 commit d338889
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
9 changes: 8 additions & 1 deletion i3ipc/i3ipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Event(object):
WINDOW = (1 << 3)
BARCONFIG_UPDATE = (1 << 4)
BINDING = (1 << 5)
# 1 << 6 is shutdown
SHUTDOWN = (1 << 6)
TICK = (1 << 7)


Expand Down Expand Up @@ -620,6 +620,8 @@ def subscribe(self, events):
events_obj.append("barconfig_update")
if events & Event.BINDING:
events_obj.append("binding")
if events & Event.SHUTDOWN:
events_obj.append("shutdown")
if events & Event.TICK:
events_obj.append("tick")

Expand Down Expand Up @@ -656,6 +658,8 @@ def on(self, detailed_event, handler):
event_type = Event.BARCONFIG_UPDATE
elif event == "binding":
event_type = Event.BINDING
elif event == "shutdown":
event_type = Event.SHUTDOWN
elif event == "tick":
event_type = Event.TICK

Expand Down Expand Up @@ -711,6 +715,9 @@ def event_socket_poll(self):
elif msg_type == Event.BINDING:
event_name = 'binding'
event = BindingEvent(data)
elif msg_type == Event.SHUTDOWN:
event_name = 'shutdown'
event = GenericEvent(data)
elif msg_type == Event.TICK:
event_name = 'tick'
event = TickEvent(data)
Expand Down
20 changes: 20 additions & 0 deletions test/test_shutdown_event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from threading import Timer
from ipctest import IpcTest
import i3ipc


class TestShutdownEvent(IpcTest):
event = None

def restart_func(t, i3):
i3.command('restart')

def on_shutdown(self, i3, e):
self.event = e
i3.main_quit()

def test_shutdown_event(self, i3):
i3.on('shutdown::restart', self.on_shutdown)
Timer(0.001, self.restart_func, args=(i3, )).start()
i3.main(timeout=1)
assert self.event

0 comments on commit d338889

Please sign in to comment.