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

vuott at tutanota.com vuott at tutanota.com
Mon Sep 25 00:49:17 CEST 2023


Excuse me, why don't you use the "Replace()" function ?


Print Replace(X11.GetWindowProperty(winId, "WM_CLASS"), Chr(0), Space(4))



24 set 2023, 21:35 da martin.fischer6 at web.de:

> 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
>
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230925/7335857d/attachment.htm>


More information about the User mailing list