Ich habe einfach mal mein Ubuntu 10.10 in VirtualBox gestartet und einen Versuch gewagt. Der Code funktioniert bei mir und sollte auch noch unter Ubuntu 11.04 funktionieren, da hier Standardmäßig ein X Server verwendet wird. Die Umstellung auf Wayland (dem XServer Ersatz) ist noch nicht vollzogen kann aber optional installiert werden.
Damit der Code funktioniert, brauchst du noch die passenden Libs, welche mit folgendem Befehl installiert werden können:
Code: Alles auswählen
EnableExplicit
Structure children
*window[0]
EndStructure
Structure XTextProperty
*value
enconding.i
format.i
nitems.l
EndStructure
ImportC "/usr/lib/libX11.a"
XOpenDisplay (*Display_name)
XDefaultRootWindow (*Display)
XQueryTree (*Display, *Window, *root_return, *parent_return, *children_return.children, *nchildren_return.i)
XFetchName (*Display, *Window, *Name)
XInternAtom (*Display, atom_name.p-ascii, only_if_exists.i)
XGetWindowProperty (*Display, *Window, property.i, long_offset.i, long_length.i, delete.i, req_type.i, *actual_type_return.i, *actual_format_return.i, *nitems_return, *bytes_after_return, *prop_return)
XGetTextProperty (*Display, *Window, *text_prop_return, property.i)
XCloseDisplay (*Display)
XFree (*Memory)
EndImport
;Wir brauchen die libs nur um die Abhängigkeiten aufzulösen
ImportC "/usr/lib/libxcb.a"
EndImport
ImportC "/usr/lib/libXau.a"
EndImport
ImportC "/usr/lib/libXdmcp.a"
EndImport
Global _NET_WM_VISIBLE_NAME.i
Global _NET_WM_NAME.i
Global WM_NAME.i
Global UTF8_STRING.i
Procedure.s GetWindowName(*Display, *Window)
Protected Result.s
If UTF8_STRING
Protected Type.i
Protected Format.i
Protected nItems.i
Protected bytes_after.i
Protected *Name
If _NET_WM_VISIBLE_NAME
If XGetWindowProperty(*Display, *Window, _NET_WM_VISIBLE_NAME, 0, 256, #False, UTF8_STRING, @Type, @Format, @nItems, @bytes_after, @*Name) = 0
If Type = UTF8_STRING And nItems > 0 And format = 8
Result = PeekS(*Name, -1, #PB_UTF8)
XFree(*Name)
ProcedureReturn Result
EndIf
XFree(*Name)
EndIf
If XGetWindowProperty(*Display, *Window, _NET_WM_NAME, 0, 256, #False, UTF8_STRING, @Type, @Format, @nItems, @bytes_after, @*Name) = 0
If Type = UTF8_STRING And nItems > 0 And format = 8
Result = PeekS(*Name, -1, #PB_UTF8)
XFree(*Name)
ProcedureReturn Result
EndIf
XFree(*Name)
EndIf
EndIf
EndIf
Protected Text.XTextProperty
If XGetTextProperty(*Display, *Window, @Text, WM_NAME)
If text\value
If text\format = 8 And text\enconding = UTF8_STRING And text\nitems > 0
Result = PeekS(text\value, -1, #PB_UTF8)
EndIf
XFree(text\value)
EndIf
EndIf
ProcedureReturn Result
EndProcedure
Procedure Enumerate(*Display, *Window)
Protected *childrens.children
Protected nchildren.i = 256
Protected *root
Protected *parent
If XQueryTree(*Display, *Window, @*root, @*parent, @*childrens, @nchildren)
If *childrens
If nchildren > 0
Protected i.i
For i = 0 To nchildren -1
Protected Name.s = GetWindowName(*Display, *childrens\window[i])
If Name <> ""
If FindString(Name, "Mozilla Firefox", 1)
Debug ">>>> " + Name
Else
Debug Name
EndIf
EndIf
Enumerate(*Display, *childrens\window[i])
Next
EndIf
Xfree(*childrens)
EndIf
EndIf
EndProcedure
Define *Display = XOpenDisplay(0)
If *Display
Define *RootWindow = XDefaultRootWindow(*Display)
_NET_WM_VISIBLE_NAME = XInternAtom(*Display, "_NET_WM_VISIBLE_NAME", #True)
_NET_WM_NAME = XInternAtom(*Display, "_NET_WM_NAME", #True)
WM_NAME = XInternAtom(*Display, "WM_NAME", #True)
UTF8_STRING = XInternAtom(*Display, "UTF8_STRING", #True)
Enumerate(*Display, *RootWindow)
XCloseDisplay(*Display)
EndIf