I'm writing an app where I want a small window to open next to its launcher item. I can have it open at the mouse position (which will be near the launcher), but that isn't very precise or satisfying. How can I get the screen position of a launcher icon using python so I can set my Gtk.Window position? Thanks!


This is what I've been able to figure out, although it's not as satisfying as just getting x,y coordinates.

You can get an ordered list of the launcher items currently in the panel, then find your launchers index in the list and multiply by the icon size + some padding for the top panel and icon spacing to give approximate y coordinate.

See code below. I hope this helps anyone else who may be searching for a way to do this.

    from gi.repository import Unity
    import gconf

    #Get Icon size

    LF_ICONPADDING=10 # Guesstimate
    PANEL_HEIGHT=16  # Guesstimate, will depend on fontsize. Don't know where to get this
    #Use unity api to get a list of launcher panel items  

    #Find the position of my .desktop file 
    #(add 2 for the dash icon and because lists start at 0)
    pos=lf.index('nautilus.desktop') + 2

    #calculate approximate y coordinate

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.