Example #1
0
def get_window_title(id):
    for line in sh.xprop("-id", id).split("\n"):
        if line.startswith("WM_NAME") or line.startswith("_NET_WM_NAME"):
            try:
                ind = line.find("=")
            except ValueError:
                return "ERROR"
            
            #+3 and -1, instead of +2 because there's quotes on either side
            title = line[ind+3:-1]
            if len(title) >= max_title_len:
                title = title[:max_title_len] + "..."
            return title
def get_window_title(id):
    for line in sh.xprop("-id", id).split("\n"):
        if line.startswith("WM_NAME") or line.startswith("_NET_WM_NAME"):
            try:
                ind = line.find("=")
            except ValueError:
                return "ERROR"

            #+3 and -1, instead of +2 because there's quotes on either side
            title = line[ind + 3:-1]
            if len(title) >= max_title_len:
                title = title[:max_title_len] + "..."
            return title
Example #3
0
    def get_title(self):
        try:
            xprop_text = sh.xprop('-name', "Spotify Free - Linux Preview")
            xprop_text = unicode(xprop_text)
        except sh.ErrorReturnCode_1:
            return None

        _title_re = '_NET_WM_ICON_NAME\(UTF8_STRING\) = \"(.*)\"'
        match = re.search(_title_re, xprop_text)

        if match is not None:
            title = match.group(1)
        else:
            return None

        return title
Example #4
0
        fifo.flush()
    except BrokenPipeError:
        print("THERE'S A BREAK IN THE PIPE YO")
        exit(0)
        

def handle_update(line, stdin):
    if line.startswith("_NET_ACTIVE_WINDOW(WINDOW)"):
        #There should only be one id, but get_window_ids returns a list
        global focused
        focused = get_window_ids(line)[0]
        update_fifo()

    elif line.startswith("_NET_CLIENT_LIST(WINDOW)"):
        window_ids = get_window_ids(line)
        #New windows created
        for id in window_ids:
            if id not in curr_windows:
                curr_windows.append(id)
        #Windows removed
        for id in curr_windows:
            if id not in window_ids:
                curr_windows.remove(id)
        
        update_fifo()

        

sh.xprop("-spy", "-root", _out=handle_update)
print("Ending script")
    try:
        fifo.flush()
    except BrokenPipeError:
        print("THERE'S A BREAK IN THE PIPE YO")
        exit(0)


def handle_update(line, stdin):
    if line.startswith("_NET_ACTIVE_WINDOW(WINDOW)"):
        #There should only be one id, but get_window_ids returns a list
        global focused
        focused = get_window_ids(line)[0]
        update_fifo()

    elif line.startswith("_NET_CLIENT_LIST(WINDOW)"):
        window_ids = get_window_ids(line)
        #New windows created
        for id in window_ids:
            if id not in curr_windows:
                curr_windows.append(id)
        #Windows removed
        for id in curr_windows:
            if id not in window_ids:
                curr_windows.remove(id)

        update_fifo()


sh.xprop("-spy", "-root", _out=handle_update)
print("Ending script")