def __init__(self): """Initialize new EventHandler""" # The dictionary that contains pairs like {window_id: 'layout'} self._windows_layout = {} # The current window id self._current_id = -1 # The previous window id self._previous_id = -1 # The keyboard controller self._keyboard_controller = KeyBoardController()
class EventHandler(object): """A EventHandler class contain methods that handle an i3 event""" def __init__(self): """Initialize new EventHandler""" # The dictionary that contains pairs like {window_id: 'layout'} self._windows_layout = {} # The current window id self._current_id = -1 # The previous window id self._previous_id = -1 # The keyboard controller self._keyboard_controller = KeyBoardController() def on_window_close(self, i3con, event): # pylint: disable=unused-argument """ The hendler on close window event - i3 is the connection to the ipc - event is an object with the data of the event sent from i3 """ current_id = event.container.props.id if current_id in self._windows_layout: del self._windows_layout[current_id] self._current_id = self._previous_id self._keyboard_controller.\ set_layout(self._windows_layout.get(self._current_id, 'us')) def on_window_focus(self, i3con, event): # pylint: disable=unused-argument """ The hendler on focus window event - i3 is the connection to the ipc - event is an object with the data of the event sent from i3 """ self._previous_id = self._current_id self._current_id = event.container.props.id if self._previous_id > 0: self._windows_layout[self._previous_id] = \ self._keyboard_controller.get_current() if self._current_id in self._windows_layout: self._keyboard_controller.\ set_layout(self._windows_layout[self._current_id]) else: self._keyboard_controller.\ set_layout(KeyBoardController.DEFAULT_KEYBOARD_LAYOUT)