def main(socket, type, timeout, message): """ Excepts arguments and evaluates them. """ if not socket: socket = i3.get_socket_path() if not socket: print("Couldn't get socket path. Are you sure i3 is running?") return False # Initializes default socket with given path and timeout try: i3.default_socket(i3.Socket(path=socket, timeout=timeout)) except i3.ConnectionError: print("Couldn't connect to socket at '%s'." % socket) return False # Format input if type in i3.EVENT_TYPES: event_type = type event = message type = 'subscribe' elif type == 'subscribe': message = message.split(' ') message_len = len(message) if message_len >= 1: event_type = message[0] if message_len >= 2: event = ' '.join(message[1:]) else: event = '' else: # Let if fail event_type = '' try: if type == 'subscribe': i3.subscribe(event_type, event) else: output = i3.msg(type, message) print(output) except i3.i3Exception as i3error: print(i3error)
print(props['title']) # if exact match then notifcation has been cleared if props['title'] == 'Telegram': cmd = [ 'wmctrl', '-b', 'remove,demands_attention', '-r', TELEGRAMINSTANCE, '-x' ] print('Request removal') subprocess.Popen(cmd) else: if not ws['container']['urgent']: cmd = [ 'wmctrl', '-b', 'add,demands_attention', '-r', TELEGRAMINSTANCE, '-x' ] print('Request adding') subprocess.Popen(cmd) socketpath = i3.get_socket_path() if not os.path.exists(socketpath): print('I3 is not running') sys.exit(3) try: i3.Subscription(workspacechange, 'workspace') i3.Subscription(windowchange, 'window') except Exception as e: print('Failed', e) sys.exit(4)
def windowchange(ws, wsp, *args): if ws['change'] == 'title': props = ws['container']['window_properties'] if props['instance'] == TELEGRAMINSTANCE: print(props['title']) # if exact match then notifcation has been cleared if props['title'] == 'Telegram': cmd = ['wmctrl', '-b', 'remove,demands_attention', '-r', TELEGRAMINSTANCE, '-x'] print('Request removal') subprocess.Popen(cmd) else: if not ws['container']['urgent']: cmd = ['wmctrl', '-b', 'add,demands_attention', '-r', TELEGRAMINSTANCE, '-x'] print('Request adding') subprocess.Popen(cmd) socketpath = i3.get_socket_path() if not os.path.exists(socketpath): print('I3 is not running') sys.exit(3) try: i3.Subscription(workspacechange, 'workspace') i3.Subscription(windowchange, 'window') except Exception as e: print('Failed', e) sys.exit(4)