The class Desktop (gb.qt4) has only a few properties as well as a method and a constant. You can use them to get information about the screen and desktop.
This class must always be viewed in conjunction with the Desktop class of the Desktop component and the Screens and Screen classes.
All properties and their description can be found in the following table:
Property | Type | Description |
---|---|---|
Height | Integer | Specifies the height of the usable desktop on a monitor. The usable desktop rectangle is the screen area minus all stationary desktop panels. Equivalent to Screens[0]. AvailableHeight |
Width | Integer | Specifies the width of the usable desktop on a monitor. The usable desktop rectangle is the screen area minus all stationary desktop panels. Equivalent to Screens[0]. AvailableWidth |
Resolution | Integer | Specifies the resolution of the screen in DPI (Dots Per Inch). |
Scale | Integer | Returns half the height of the default desktop font in pixels. |
HasSystemTray | Boolean | Returns True if the desktop has a task bar. |
Table 15.6.1.1: Overview of desktop class properties (gb. qt4)
Following the suggestion in the Gambas documentation, you can use the following procedure to read the properties of the desktop and display them in a MessageBox:
Public Sub btnGetDesktopInformation_Click() Dim sMessage, sLabel As String sMessage = "<hr><b>Desktop-Eigenschaften</b><hr>" sMessage &= "Nutzbare Desktop-Höhe = " & Desktop.Height & " Pixel" sMessage &= "<br>Nutzbare Desktop-Breite = " & Desktop.Width & " Pixel" sMessage &= "<br>Desktop-Top = " & Desktop.Y sMessage &= "<br>Desktop-Left = " & Desktop.X & "<hr>" sMessage &= "Zeichensatz = " & Desktop.Charset sLabel = IIf(Desktop.HasSystemTray = False, " Nein", " Ja.") sMessage &= "<br>SystemTray = " & sLabel ' Desktop.HasSystemTray sMessage &= "<br>Skalierungsfaktor = " & Desktop.Scale sMessage &= "<br>Auflösung = " & Desktop.Resolution & " DPI <hr>" Message.Info(sMessage) End ' btnGetDesktopInformation_Click()
Figure 15.6.1.1: Display Properties Desktop
The constant Desktop.Charset specifies the character set used by the graphical user interface to display text. The QT and GTK+ components use the UTF-8 character set. You must be careful, because the underlying operating system could use a different font!
The specified method not only returns a screen copy of the complete desktop as an object of type Picture, but also allows you to copy a selected part of it as an option:
Static Function Screenshot ([ X As Integer, Y As Integer, Width As Integer, Height As Integer ]) As Picture
This procedure returns a screen copy that is immediately displayed in a PictureBox and then saves the current screen dump in a specific directory as png-graphic with highest quality (→ 100).
[1] Public Sub btnGetScreenShot_Click() [2] FMain.Hide [3] Wait 0.1 ' In der Praxis bis auf 3 Sekunden erhöhen! [4] PictureBox1.Picture = Desktop.Screenshot() [5] PictureBox1.Picture.Save(User.Home &/ "current_screenshot.png", 100) [6] FMain.Show [7] [8] ' Alternative ohne direkte Anzeige - Option Speichern-Dialog [9] ' FMain.Hide [10] ' Wait 0.05 [11] ' Desktop.Screenshot().Save(User.Home &/ "current_screenshot.png", 100) [12] ' FMain.Show [13] [14] End ' btnGetScreenShot_Click()
With an additional Save dialog you can save several screen copies comfortably.
If you do not use the display, you will be able to save the screen copy immediately in the specified image path and in the required quality using the save procedure Desktop. screenshot. save (Path, Quality).
Figure 15.6.3.1: Desktop Project: Display Screen Copy (Xubuntu in a VM)
You can also determine the names of the virtual desktops if you have wmctrl installed on your system. With the order:
hans@linux:~$ wmctrl -d
you get the following output with the option -d, where the current desktop is marked with an asterisk and the name of the desktop is at the end of the line:
0 - DG: 1680x1050 VP: N/A WA: 0,24 1680x1002 WEB 1 - DG: 1680x1050 VP: N/A WA: 0,24 1680x1002 EXPLORER 2 * DG: 1680x1050 VP: 0,0 WA: 0,24 1680x1002 GAMBAS 3 - DG: 1680x1050 VP: N/A WA: 0,24 1680x1002 TERMINAL
For a Gambas procedure that does the same thing, use the Shell or Exec instruction (→ chapter 21.3.1 Use Quick-Syntax) and some strings and arrays to determine and display the desktop identifiers from the returned string stored in the variable sList:
Public Sub btnGetDesktopName_Click() Dim sElement, sListe, sMessage As String Dim aMatrix, aZeile As New String[] Shell "wmctrl -d" To sListe If sListe Then aMatrix = Split(sListe, "\n") sMessage = "<hr><b>Desktop-Bezeichner</b><hr>" For Each sElement In aMatrix If sElement Then aZeile = Split(sElement, " ") sMessage &= "<br>" & aZeile[aZeile.Count - 1] Endif Next ' sElement Message.Info(sMessage) End ' btnGetDesktopName_Click()
Figure 15.6.4.1: Display of desktop names (identifiers)