[Gambas-user] Trouble with X11.GetWindowProperty()

Martin Fischer martin.fischer6 at web.de
Sun Sep 24 21:34:02 CEST 2023


Hi fellow gambassins,

I want to read the value of the WM_CLASS X11 atom by using
   X11.GetWindowProperty(winId, "WM_CLASS")

WM_CLASS is a string-atom, so GetWindowProperty should return a Variant
containing a String[] (one string for instanceName, one for className).

BUT what I get is a Variant containing a single String that contains the
NULL bytes that terminate the C-strings.
In the debugger such a string (for the Firefox window) looks like:
   "Navigator\x00firefox\x00"

Now: is this a bug or a feature?

Sure. I can read this string as stream like so:

--------------------------------------------------------
'' Returns the WM_CLASS of the given window
Fast Public Function GetWindowClass(winId As Integer) As WindowClass
     Dim wmClass As String = X11.GetWindowProperty(winId, "WM_CLASS")

     Dim resStream As Stream
     resStream = Open String wmClass For Read
     resStream.NullTerminatedString = True

     Dim instanceName, className As String
     instanceName = Read #resStream As String
     Seek #resStream, instanceName.Len + 1 ' skip the \0 to be able to
read next string
     className = Read #resStream As String

     Return New WindowClass([instanceName, className])

Catch
     Error.Raise(Subst("Could not get WM_CLASS for window &1: &2",
winId, Error.Text))
End
--------------------------------------------------------

But this does not seem to be the way it should work...


Any ideas about this issue?

Regards,
Martin
____________________________
Martin Fischer



More information about the User mailing list