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_ICONSIZE=gconf.client_get_default().get_int('/apps/compiz-1/plugins/unityshell/screen0/options/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 lf=Unity.LauncherFavorites.get_default().enumerate_ids() #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 y = pos * (LF_ICONSIZE + LF_ICONPADDING) + PANEL_HEIGHT