[Gambas-user] Test Screen.Available values

Bruce Steers bsteers4 at gmail.com
Sat May 20 03:15:30 CEST 2023


On Wed, 17 May 2023 at 08:24, Bruce Steers <bsteers4 at gmail.com> wrote:

>
>
> On Tue, 16 May 2023 at 19:16, Benoit Minisini <
> benoit.minisini at gambas-basic.org> wrote:
>
>> Le 16/05/2023 à 19:57, Bruce Steers a écrit :
>> >
>> >
>> > Thank you Bruce, Benoit, Mayost
>> > So i guess with all that the best way to add / use a feature like this
>> > would be to just add a disclaimer that it may or may not work depending
>> > on the system.
>> >
>> > Respects
>> > BruceS
>> >
>>
>> As explained in the Qt comment, you can use the 'xprop' command-line
>> tool to read the X11 properties of the root window and look if there is
>> a '_NET_WORKAREA' property and show us what it contains.
>>
>> --
>> Benoît Minisini.
>>
> mine is this...
>
> $ xprop -root _NET_WORKAREA
> _NET_WORKAREA(CARDINAL) = 0, 25, 2646, 999
>
> And that's annoying as that is the entire screen (both monitors) but
> there's only panels on one :-\
>

So i came up with this workaround..
It's a little dirty but it works as well now with QT as it does with gtk3
(gtk2 only reports Screen.Count as 1 so i'm not supporting it)

if using QT it searches through the X11 window list to find the first
_NET_WM_WINDOW_TYPE_NORMAL window the mouse is on.
on my main screen there is a panel (TYPE_DOCK) at the top, then the main
view (TYPE_NORMAL), then a panel at the bottom.

So the following function returns a Rect of the Screen the mouse is on and
if NoPanels is True then only the inner view.

Public Sub CheckScreenSize() As Rect

  Dim s As Screen = Screens[Mouse.Screen]

  If Not NoPanels Then Return Rect(s.X, s.Y, s.Width, s.Height)

  Dim r As Rect = Rect(s.AvailableX, s.AvailableY, s.AvailableWidth,
s.AvailableHeight)
  If Not Component.IsLoaded("gb.desktop.x11") Then Return r

  Select Env["GB_GUI"]
    Case Like "*qt*"
      For Each w As Integer In X11.FindWindow("", "")
        Dim v As Variant = X11.GetWindowProperty(w,
"_NET_WM_WINDOW_TYPE")[0]
        Dim wd As Integer[] = X11.GetWindowGeometry(w)
        If v = "_NET_WM_WINDOW_TYPE_NORMAL" Then
          Dim r2 As Rect = Rect(wd[0], wd[1], wd[2], wd[3])
          If r2.Contains(Mouse.ScreenX, Mouse.ScreenY) Then
            Return r2
          Endif
        Endif
      Next
  End Select

  Return r

End

Respects
BruceS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230520/3fa36754/attachment.htm>


More information about the User mailing list