def get_desk(i_or_name):
    if isinstance(i_or_name, int):
        return i_or_name

    assert isinstance(i_or_name, basestring)
    
    nextdesk = None
    names = ewmh.get_desktop_names().reply()
    ci = ewmh.get_current_desktop().reply()
    visibles = ewmh.get_visible_desktops().reply()

    cname = names[ci] if ci < len(names) else ''
    fnames = names[:]

    if visibles:
        not_cur_or_vis = lambda (i, nm): i not in visibles or i == ci
        fnames = [nm for i, nm in filter(not_cur_or_vis, enumerate(fnames))]

    fnames = filter(lambda n: n.lower().startswith(i_or_name.lower()), fnames)
    fnames = sorted(fnames)

    if cname in fnames:
        posInPrefix = (fnames.index(cname) + 1) % len(fnames)
        nextdesk = names.index(fnames[posInPrefix])
    elif len(fnames):
        nextdesk = names.index(fnames[0])

    return nextdesk
def get_desk(i_or_name):
    if isinstance(i_or_name, int):
        return i_or_name

    assert isinstance(i_or_name, basestring)

    nextdesk = None
    names = ewmh.get_desktop_names().reply()
    ci = ewmh.get_current_desktop().reply()
    visibles = ewmh.get_visible_desktops().reply()

    cname = names[ci] if ci < len(names) else ''
    fnames = names[:]

    if visibles:
        not_cur_or_vis = lambda (i, nm): i not in visibles or i == ci
        fnames = [nm for i, nm in filter(not_cur_or_vis, enumerate(fnames))]

    fnames = filter(lambda n: n.lower().startswith(i_or_name.lower()), fnames)
    fnames = sorted(fnames)

    if cname in fnames:
        posInPrefix = (fnames.index(cname) + 1) % len(fnames)
        nextdesk = names.index(fnames[posInPrefix])
    elif len(fnames):
        nextdesk = names.index(fnames[0])

    return nextdesk
Example #3
0
def do_goto_window(letter):
    if letter not in marked:
        print("mark %s does not exist" % letter, file=sys.stderr)
        return

    wid = marked[letter]
    try:
        wdesk = ewmh.get_wm_desktop(wid).reply()
        desktop = ewmh.get_current_desktop().reply()
        visibles = ewmh.get_visible_desktops().reply() or [desktop]

        if wdesk is not None and wdesk not in visibles:
            ewmh.request_current_desktop_checked(wdesk).check()
        ewmh.request_active_window_checked(wid, source=1).check()
    except xproto.BadWindow:
        print("%d no longer exists" % wid, file=sys.stderr)
Example #4
0
def do_goto_window(letter):
    if letter not in marked:
        print >> sys.stderr, 'mark %s does not exist' % letter
        return

    wid = marked[letter]
    try:
        wdesk = ewmh.get_wm_desktop(wid).reply()
        desktop = ewmh.get_current_desktop().reply()
        visibles = ewmh.get_visible_desktops().reply() or [desktop]

        if wdesk is not None and wdesk not in visibles:
            ewmh.request_current_desktop_checked(wdesk).check()
        ewmh.request_active_window_checked(wid, source=1).check()
    except xcb.xproto.BadWindow:
        print >> sys.stderr, '%d no longer exists' % wid
Example #5
0
def cb_property_notify(e):
    global activewin, desk_num, desktop, monitors, phys_monitors, root_geom, stacking, visibles, workarea

    aname = util.get_atom_name(e.atom)
    if aname == "_NET_DESKTOP_GEOMETRY":
        root_geom = ewmh.get_desktop_geometry().reply()
        monitors = xinerama.get_monitors()
        phys_monitors = xinerama.get_physical_mapping(monitors)
    elif aname == "_NET_ACTIVE_WINDOW":
        activewin = ewmh.get_active_window().reply()
    elif aname == "_NET_CURRENT_DESKTOP":
        desktop = ewmh.get_current_desktop().reply()
        if visibles is None or len(visibles) == 1:
            visibles = [desktop]
    elif aname == "_NET_VISIBLE_DESKTOPS":
        visibles = ewmh.get_visible_desktops().reply()
    elif aname == "_NET_NUMBER_OF_DESKTOPS":
        desk_num = ewmh.get_number_of_desktops().reply()
    elif aname == "_NET_CLIENT_LIST_STACKING":
        stacking = ewmh.get_client_list_stacking().reply()
    elif aname == "_NET_WORKAREA":
        update_workarea()
Example #6
0
def cb_property_notify(e):
    global activewin, desk_num, desktop, monitors, phys_monitors, root_geom, \
           stacking, visibles, workarea

    aname = util.get_atom_name(e.atom)
    if aname == '_NET_DESKTOP_GEOMETRY':
        root_geom = ewmh.get_desktop_geometry().reply()
        monitors = xinerama.get_monitors()
        phys_monitors = xinerama.get_physical_mapping(monitors)
    elif aname == '_NET_ACTIVE_WINDOW':
        activewin = ewmh.get_active_window().reply()
    elif aname == '_NET_CURRENT_DESKTOP':
        desktop = ewmh.get_current_desktop().reply()
        if visibles is None or len(visibles) == 1:
            visibles = [desktop]
    elif aname == '_NET_VISIBLE_DESKTOPS':
        visibles = ewmh.get_visible_desktops().reply()
    elif aname == '_NET_NUMBER_OF_DESKTOPS':
        desk_num = ewmh.get_number_of_desktops().reply()
    elif aname == '_NET_CLIENT_LIST_STACKING':
        stacking = ewmh.get_client_list_stacking().reply()
    elif aname == '_NET_WORKAREA':
        update_workarea()
def remove_empty_current_desktop():
    # This isn't as straight-forward as decrementing _NET_NUMBER_OF_DESKTOPS.
    # We need to make sure we remove the right name, too.
    # AND only do it if there are no clients on this desktop.
    clients = ewmh.get_client_list().reply()
    cur = ewmh.get_current_desktop().reply()
    for c in clients:
        if ewmh.get_wm_desktop(c).reply() == cur:
            return

    names = ewmh.get_desktop_names().reply()
    if cur < len(names):
        names.pop(cur)
        ewmh.set_desktop_names_checked(names).check()

    # Subtract one from every client's desktop above the current one
    for c in clients:
        cdesk = ewmh.get_wm_desktop(c).reply()
        if cdesk > cur and cdesk != 0xffffffff:
            ewmh.set_wm_desktop_checked(c, cdesk - 1).check()

    ndesks = ewmh.get_number_of_desktops().reply()
    ewmh.request_number_of_desktops_checked(ndesks - 1).check()
def remove_empty_current_desktop():
    # This isn't as straight-forward as decrementing _NET_NUMBER_OF_DESKTOPS.
    # We need to make sure we remove the right name, too.
    # AND only do it if there are no clients on this desktop.
    clients = ewmh.get_client_list().reply()
    cur = ewmh.get_current_desktop().reply()
    for c in clients:
        if ewmh.get_wm_desktop(c).reply() == cur:
            return

    names = ewmh.get_desktop_names().reply()
    if cur < len(names):
        names.pop(cur)
        ewmh.set_desktop_names_checked(names).check()

    # Subtract one from every client's desktop above the current one
    for c in clients:
        cdesk = ewmh.get_wm_desktop(c).reply()
        if cdesk > cur and cdesk != 0xffffffff:
            ewmh.set_wm_desktop_checked(c, cdesk - 1).check()

    ndesks = ewmh.get_number_of_desktops().reply()
    ewmh.request_number_of_desktops_checked(ndesks - 1).check()
Example #9
0
def cb_prop_change(widget, e):
    global activewin, desk_names, desk_num, desktop, stacking, visibles

    if e.atom == '_NET_DESKTOP_GEOMETRY':
        root_geom = ewmh.get_desktop_geometry().reply()
        update_monitor_area()
    elif e.atom == '_NET_ACTIVE_WINDOW':
        activewin = ewmh.get_active_window().reply()
    elif e.atom == '_NET_CURRENT_DESKTOP':
        desktop = ewmh.get_current_desktop().reply()
    elif e.atom == '_NET_CLIENT_LIST_STACKING':
        stacking = ewmh.get_client_list_stacking().reply()
    elif e.atom == '_NET_VISIBLE_DESKTOPS':
        visibles = ewmh.get_visible_desktops().reply()
    elif e.atom in ('_NET_DESKTOP_NAMES', '_NET_NUMBER_OF_DESKTOPS'):
        desk_num = ewmh.get_number_of_desktops().reply()
        desk_names = ewmh.get_desktop_names().reply()

        # This works around what I think is weird behavior in Openbox.
        # Sometimes Openbox will "fix" the desktop names... please don't!
        if len(desk_names) > desk_num:
            names = desk_names[0:desk_num]
            ewmh.set_desktop_names_checked(names).check()
        desk_names = ewmh.get_desktop_names().reply()
Example #10
0
def cb_prop_change(widget, e):
    global activewin, desk_names, desk_num, desktop, stacking, visibles

    if e.atom == '_NET_DESKTOP_GEOMETRY':
        root_geom = ewmh.get_desktop_geometry().reply()
        update_monitor_area()
    elif e.atom == '_NET_ACTIVE_WINDOW':
        activewin = ewmh.get_active_window().reply()
    elif e.atom == '_NET_CURRENT_DESKTOP':
        desktop = ewmh.get_current_desktop().reply()
    elif e.atom == '_NET_CLIENT_LIST_STACKING':
        stacking = ewmh.get_client_list_stacking().reply()
    elif e.atom == '_NET_VISIBLE_DESKTOPS':
        visibles = ewmh.get_visible_desktops().reply()
    elif e.atom in ('_NET_DESKTOP_NAMES', '_NET_NUMBER_OF_DESKTOPS'):
        desk_num = ewmh.get_number_of_desktops().reply()
        desk_names = ewmh.get_desktop_names().reply()

        # This works around what I think is weird behavior in Openbox.
        # Sometimes Openbox will "fix" the desktop names... please don't!
        if len(desk_names) > desk_num:
            names = desk_names[0:desk_num]
            ewmh.set_desktop_names_checked(names).check()
        desk_names = ewmh.get_desktop_names().reply()
Example #11
0
import sys

from xpybutil import conn, root

import xpybutil.ewmh as ewmh

if len(sys.argv) == 2 and sys.argv[1] == '--help':
    print("Usage: ")
    print("   set_desktop_name NAME_OF_NEW_DESKTOP  - sets current desktop name")
    print("   set_desktop_name NR NAME_OF_NEW_DESKTOP - sets name of NRth desktop")

if len(sys.argv) > 2:
    desktop_offset = int(sys.argv[1])
    new_name = sys.argv[2]

else:
    desktop_offset = ewmh.get_current_desktop().reply()
    new_name = sys.argv[1]

current_names = ewmh.get_desktop_names().reply()

current_names[desktop_offset] = new_name

# Not sure why I have to do it twice - somehow
# doesn't work if I only call it once
c = ewmh.set_desktop_names(current_names)
c = ewmh.set_desktop_names(current_names)

ewmh.set_current_desktop(0)
Example #12
0
                utilwm = window.WindowManagers.Openbox
            elif wm.lower() == 'kwin':
                utilwm = window.WindowManagers.KWin

            print '%s window manager is running...' % wm
            sys.stdout.flush()

    if not _wmrunning:
        time.sleep(1)

root_geom = ewmh.get_desktop_geometry().reply()
monitors = xinerama.get_monitors()
phys_monitors = xinerama.get_physical_mapping(monitors)
desk_num = ewmh.get_number_of_desktops().reply()
activewin = ewmh.get_active_window().reply()
desktop = ewmh.get_current_desktop().reply()
visibles = ewmh.get_visible_desktops().reply() or [desktop]
stacking = ewmh.get_client_list_stacking().reply()
workarea = []

def quit():
    print 'Exiting...'
    import tile
    for tiler in tile.tilers:
        tile.get_active_tiler(tiler)[0].untile()
    sys.exit(0)

def update_workarea():
    '''
    We update the current workarea either by autodetecting struts, or by
    using margins specified in the config file. Never both, though.
Example #13
0
def getCurrentDesktop():
    return ewmh.get_current_desktop().reply()
Example #14
0
def getCurrentDesktop():
    return ewmh.get_current_desktop().reply()
Example #15
0
def get_focused_workspace() -> int:
    return get_current_desktop().reply()
Example #16
0
#!/usr/bin/env python
"Helper for setting current desktop's name"

import sys

import xpybutil.ewmh as ewmh

if len(sys.argv) == 2 and sys.argv[1] == '--help':
    print("""
        Usage:\n
            set_desktop_name NAME_OF_NEW_DESKTOP  - sets current desktop name
            set_desktop_name NR NAME_OF_NEW_DESKTOP - sets name of NRth desktop
        """)

if len(sys.argv) > 2:
    desktop_offset = int(sys.argv[1])
    new_name = sys.argv[2]

else:
    desktop_offset = ewmh.get_current_desktop().reply()
    new_name = sys.argv[1]

current_names = ewmh.get_desktop_names().reply()

current_names[desktop_offset] = new_name

# Not sure why I have to do it twice - somehow
# doesn't work if I only call it once
c = ewmh.set_desktop_names(current_names)
c = ewmh.set_desktop_names(current_names)