diff --git a/kill.py b/kill.py index 835cfa1..ae72d48 100644 --- a/kill.py +++ b/kill.py @@ -38,7 +38,7 @@ def __init__(self): """ super().__init__() self._processes = [] - self._processes_with_window = [] + self._processes_with_window = {} self._actions = [] self._icons = {} self._default_action = "kill_by_id" @@ -185,12 +185,12 @@ def _get_windows(self): except OSError: self.err("Failed to list windows.", str(exc)) - self._processes_with_window = [] + self._processes_with_window = {} for hwnd in handles: try: (_, proc_id) = AltTab.get_window_thread_process_id(hwnd) - self._processes_with_window.append(proc_id) + self._processes_with_window[proc_id] = hwnd except OSError: continue @@ -231,19 +231,26 @@ def _get_processes_from_com_object(self, wmi): if proc.Properties_["ExecutablePath"].Value: databag["ExecutablePath"] = proc.Properties_["ExecutablePath"].Value - label = proc.Properties_["Caption"].Value if not self._hide_background: if is_foreground: - label = label + " (foreground)" + label = '{}: "{}" ({})'.format( + proc.Properties_["Caption"].Value, + AltTab.get_window_text(self._processes_with_window[proc.Properties_["ProcessId"].Value]), + 'foreground' + ) else: - label = label + " (background)" + label = '{} ({})'.format(proc.Properties_["Caption"].Value, 'background') + else: + label = '{}: "{}"'.format( + proc.Properties_["Caption"].Value, + AltTab.get_window_text(self._processes_with_window[proc.Properties_["ProcessId"].Value]) + ) item = self.create_item( category=category, label=label, short_desc=short_desc, - target=proc.Properties_["Name"].Value + "|" - + str(proc.Properties_["ProcessId"].Value), + target=proc.Properties_["Name"].Value + "|" + str(proc.Properties_["ProcessId"].Value), icon_handle=self._get_icon(proc.Properties_["ExecutablePath"].Value), args_hint=kp.ItemArgsHint.REQUIRED, hit_hint=kp.ItemHitHint.IGNORE, @@ -349,6 +356,7 @@ def on_deactivated(self): """ Emptys the process list, when Keypirinha Box is closed """ + self._processes_with_window = {} self._processes = [] # for ico in self._icons.values(): @@ -380,7 +388,6 @@ def on_execute(self, item, action): if act.name() == self._default_action: action = act - if "_admin" in action.name(): self._kill_process_admin(item, action.name()) else: