Return dict: {'window title' : window handle} for all visible windows
351676
def getWindows():    #https://sjohannes.wordpress.com/2012/03/23/win32-python-getting-all-window-titles/
    """"""
    titles = {}

    def foreach_window(hwnd, lparam):
        if IsWindowVisible(hwnd):
            length = GetWindowTextLength(hwnd)
            buff = ctypes.create_unicode_buffer(length + 1)
            GetWindowText(hwnd, buff, length + 1)
            titles[buff.value] = hwnd
        return True
    EnumWindows(EnumWindowsProc(foreach_window), 0)

    return titles
714430
def get_open_window_names():
    '''
    
    '''
    raw_names = subprocess.check_output(['wmctrl', '-l']).decode('utf8').split('\n')
    split_names = [name.split() for name in raw_names if name]
    name_dict = {}
    for name in split_names:
        if not int(name[1]):
            name_dict[' '.join(name[3:]).lower()] = name[0]
    return name_dict
646353
def title(self):
        
        with switch_window(self._browser, self.name):
            return self._browser.title
321818
def getWmWindowType(self, win, str=False):
        
        types = self._getProperty('_NET_WM_WINDOW_TYPE', win) or []
        if not str:
            return types
        return [self._getAtomName(t) for t in types]
1099214
def windows(self):
        
        from foxpuppet.windows import BrowserWindow

        return [
            BrowserWindow(self.selenium, handle)
            for handle in self.selenium.window_handles
        ]
776605
def close_other_windows(self):
        
        main_window_handle = self.current_window_handle
        for window_handle in self.window_handles:
            if window_handle == main_window_handle:
                continue
            self.switch_to_window(window_handle)
            self.close()
        self.switch_to_window(main_window_handle)
1372437
def getWindowByTitle(self, wildcard, order=0):
        
        EnumWindowsProc = ctypes.WINFUNCTYPE(
            ctypes.c_bool,
            ctypes.POINTER(ctypes.c_int),
            ctypes.py_object)
        def callback(hwnd, context):
            if ctypes.windll.user32.IsWindowVisible(hwnd):
                length = ctypes.windll.user32.GetWindowTextLengthW(hwnd)
                buff = ctypes.create_unicode_buffer(length + 1)
                ctypes.windll.user32.GetWindowTextW(hwnd, buff, length + 1)
                if re.search(context["wildcard"], buff.value, flags=re.I) != None and not context["handle"]:
                    if context["order"] > 0:
                        context["order"] -= 1
                    else:
                        context["handle"] = hwnd
            return True
        data = {"wildcard": wildcard, "handle": None, "order": order}
        ctypes.windll.user32.EnumWindows(EnumWindowsProc(callback), ctypes.py_object(data))
        return data["handle"]
737456
def _get_windows(peak_list):
    
    win_list = []
    for t0, t1, hints in peak_list:
        p_w = (t0, t1)
        for w in win_list:
            if p_w[0] <= w[0][1] and p_w[1] >= w[0][0]:
                w[0] = (min(p_w[0], w[0][0]), max(p_w[1], w[0][1]))
                w[1].append((t0, t1, hints))
                break
        else:
            win_list.append([p_w, [(t0, t1, hints)]])
    return win_list
14011
def __grabHotkeysForWindow(self, window):
        
        c = self.app.configManager
        hotkeys = c.hotKeys + c.hotKeyFolders
        window_info = self.get_window_info(window)
        for item in hotkeys:
            if item.get_applicable_regex() is not None and item._should_trigger_window_title(window_info):
                self.__enqueue(self.__grabHotkey, item.hotKey, item.modifiers, window)
            elif self.__needsMutterWorkaround(item):
                self.__enqueue(self.__grabHotkey, item.hotKey, item.modifiers, window)
1160737
def getWindow(self):
        
        if self.getPID() != -1:
            return PlatformManager.getWindowTitle(PlatformManager.getWindowByPID(self.getPID()))
        else:
            return ""
767751
def load_last_visible_toolbars(self):
        """"""
        toolbars_names = CONF.get('main', 'last_visible_toolbars', default=[])

        if toolbars_names:
            dic = {}
            for toolbar in self.toolbarslist:
                dic[toolbar.objectName()] = toolbar

            toolbars = []
            for name in toolbars_names:
                if name in dic:
                    toolbars.append(dic[name])
            self.visible_toolbars = toolbars
        else:
            self.get_visible_toolbars()
        self._update_show_toolbars_action()
278281
def get_active_window(self):
        
        app = get_app()

        try:
            return self._active_window_for_cli[app]
        except KeyError:
            self._active_window_for_cli[app] = self._last_active_window or self.windows[0]
            return self.windows[0]
724575
def _get_window_list(self):
        
        window_list = Quartz.CGWindowListCopyWindowInfo(Quartz.kCGWindowListExcludeDesktopElements, Quartz.kCGNullWindowID)
        return window_list
1049402
def find_window(self):
        """"""
        window = self.app.activeWindow()

        while True:
            parent_window = window.parent()
            if parent_window:
                window = parent_window
            else:
                break

        return window
115947
def get_window_at_mouse(self):
        
        window_ret = ctypes.c_ulong(0)
        _libxdo.xdo_get_window_at_mouse(self._xdo, ctypes.byref(window_ret))
        return window_ret.value
888482
def setWindowTitle(self, newTitle=''):
        """"""
        title = 'Rampage - ' + newTitle
        super(MainWindow, self).setWindowTitle(title)
836241
def get_active_window(self):
        
        window_ret = window_t(0)
        _libxdo.xdo_get_active_window(self._xdo, ctypes.byref(window_ret))
        return window_ret.value