#!/usr/bin/env python3
"""Custom killing of apps."""
import sys

import i3ipc
from i3_helpers import sh

CTRL_Q = ['Skype', 'Slack']
CUSTOM = ['Chromium']


def kill_custom(i3, which):
    """Kill apps differently according to their class."""
    tree = i3.get_tree()
    if which == 'focused':
        windows = [tree.find_focused()]
    elif which == 'all':
        windows = [win for ws in tree.workspaces() for win in ws.leaves()]

    for win in windows:
        i3.command(f'[con_id={win.id}] focus')
        win_class = win.window_class
        if win_class in CUSTOM:
            if win_class == 'Chromium':
                sh(f'xdotool key --window {win.window} comma+k+v')
        elif win_class in CTRL_Q:
            sh(f'xkill -id {win.window}')
        else:
            i3.command('kill')


if __name__ == '__main__':
    import argparse

    parser = argparse.ArgumentParser()
    parser.add_argument('--which', '-w', default='focused')
    pars_args = parser.parse_args()

    i3_conn = i3ipc.Connection()
    kill_custom(i3_conn, which=pars_args.which)
    sys.exit(0)

@@ -158,89 +158,38 @@
 def 
-kill_custom(i3, which):%0A    %22%22%22Kill apps differently according to their class.%22%22%22
+_get_windows(i3, which='all'):
 %0A   
@@ -377,16 +377,160 @@
 aves()%5D%0A
+    return windows%0A%0A%0Adef kill_custom(i3, which):%0A    %22%22%22Kill apps differently according to their class.%22%22%22%0A    windows = _get_windows(i3, which)
 %0A    for
@@ -769,16 +769,326 @@
 a+k+v')%0A
+                # If the window was not killed using xdotool then do kill it with i3%0A                remaining_window_classes = %5B%0A                    win.window_class for win in _get_windows(i3)%0A                %5D%0A                if win_class in remaining_window_classes:%0A                    i3.command('kill')%0A
         

kill chromium with i3 if custom kill didn't work