Differenze tra le versioni di "Ottenere informazioni sugli schermi disponibili mediante le funzioni del API di X11"

Da Gambas-it.org - Wikipedia.
 
(8 versioni intermedie di uno stesso utente non sono mostrate)
Riga 1: Riga 1:
 
La libreria '''Xlib''' dello ''X Window System Standard'', versione 11, consente - fra l'altro - anche di ottenere alcune informazioni in ordine agli schermi disponibili.
 
La libreria '''Xlib''' dello ''X Window System Standard'', versione 11, consente - fra l'altro - anche di ottenere alcune informazioni in ordine agli schermi disponibili.
  
Si richiamerà l'attuale libreria condivisa di ''X11'': "libX11.so.6.3.0".
+
Si richiamerà l'attuale libreria condivisa di X11: "''libX11.so.6.4.0'' ".
  
  
 
Mostriamo di seguito un breve codice esemplificativo:
 
Mostriamo di seguito un breve codice esemplificativo:
  Library "libX11:6.3.0"
+
  Library "libX11:6.4.0"
 
   
 
   
  <FONT color=gray>' ''Display *XOpenDisplay(display_name)''
+
  <FONT color=gray>' ''Display *XOpenDisplay(char *display_name)''
  ' ''opens a connection to the X server that controls a display.''</font>
+
  ' ''Opens a connection to the X server that controls a display.''</font>
  '''Private''' Extern XOpenDisplay(displayP As Pointer) As Pointer
+
  Private Extern XOpenDisplay(display_name As Pointer) As Pointer
 
   
 
   
  <FONT color=gray>' ''int XDefaultScreen (display)''
+
  <FONT color=gray>' ''int XDefaultScreen (Display *display)''
  ' ''returns the default screen number referenced by the XOpenDisplay function.''</font>
+
  ' ''Returns the default screen number referenced by the XOpenDisplay function.''</font>
  '''Private''' Extern XDefaultScreen(displayP As Pointer) As Integer
+
  Private Extern XDefaultScreen(display As Pointer) As Integer
 
   
 
   
  <FONT color=gray>' ''int XDefaultDepth (display, screen_number)''
+
  <FONT color=gray>' ''int XDefaultDepth (Display *display, int screen_number)''
  ' ''returns the depth (number of planes) of the default root window for the specified screen.''</font>
+
  ' ''Returns the depth (number of planes) of the default root window for the specified screen.''</font>
  '''Private''' Extern XDefaultDepth(displayP As Pointer, screen_number As Integer) As Integer
+
  Private Extern XDefaultDepth(display As Pointer, screen_number As Integer) As Integer
 
   
 
   
  <FONT color=gray>' ''int XConnectionNumber(display)''
+
  <FONT color=gray>' ''int XConnectionNumber(Display *display)''
  ' ''returns a connection number for the specified display.''</font>
+
  ' ''Returns a connection number for the specified display.''</font>
  '''Private''' Extern XConnectionNumber(displayP As Pointer) As Integer
+
  Private Extern XConnectionNumber(display As Pointer) As Integer
 
   
 
   
  <FONT color=gray>' ''char *XDisplayName(string)''
+
  <FONT color=gray>' ''char *XDisplayName(char *string)''
  ' ''returns the name of the display that XOpenDisplay would attempt to use.''</font>
+
  ' ''Returns the name of the display that XOpenDisplay would attempt to use.''</font>
  '''Private''' Extern XDisplayName(disp_string$ As Pointer) As Pointer
+
  Private Extern XDisplayName(disp_string As Pointer) As Pointer
 
   
 
   
  <FONT color=gray>' ''int XDisplayWidth (display, screen_number)''
+
  <FONT color=gray>' ''int XDisplayWidth (Display *display, int screen_number)''
 
  ' ''Returns the width of the screen in pixels.''</font>
 
  ' ''Returns the width of the screen in pixels.''</font>
  '''Private''' Extern XDisplayWidth(displayP As Pointer, screen_number As Integer) As Integer
+
  Private Extern XDisplayWidth(display As Pointer, screen_number As Integer) As Integer
 
   
 
   
  <FONT color=gray>' ''int XDisplayHeight(display, screen_number)''
+
  <FONT color=gray>' ''int XDisplayHeight(Display *display, int screen_number)''
 
  ' ''Returns an integer that describes the height of the screen in pixels.''</font>
 
  ' ''Returns an integer that describes the height of the screen in pixels.''</font>
  '''Private''' Extern XDisplayHeight(displayP As Pointer, screen_number As Integer) As Integer
+
  Private Extern XDisplayHeight(display As Pointer, screen_number As Integer) As Integer
 
   
 
   
  <FONT color=gray>' ''int XDisplayWidthMM (display, screen_number)''
+
  <FONT color=gray>' ''int XDisplayWidthMM (Display *display, int screen_number)''
  ' ''returns the width of the specified screen in millimeters.''</font>
+
  ' ''Returns the width of the specified screen in millimeters.''</font>
  '''Private''' Extern XDisplayWidthMM(displayP As Pointer, screen_number As Integer) As Integer
+
  Private Extern XDisplayWidthMM(display As Pointer, screen_number As Integer) As Integer
 
   
 
   
  <FONT color=gray>' ''unsigned long XBlackPixel (display, screen_number)''
+
  <FONT color=gray>' ''unsigned long XBlackPixel (Display *display, int screen_number)''
  ' ''returns the black pixel value for the specified screen.''</font>
+
  ' ''Returns the black pixel value for the specified screen.''</font>
  '''Private''' Extern XBlackPixel(displayP As Pointer, screen_number As Integer) As Long
+
  Private Extern XBlackPixel(display As Pointer, screen_number As Integer) As Long
 
   
 
   
  <FONT color=gray>' ''unsigned long XWhitePixel (display, screen_number)''
+
  <FONT color=gray>' ''unsigned long XWhitePixel (Display *display, int screen_number)''
  ' ''returns the white pixel value for the specified screen.''</font>
+
  ' ''Returns the white pixel value for the specified screen.''</font>
  '''Private''' Extern XWhitePixel(displayP As Pointer, screen_number As Integer) As Long
+
  Private Extern XWhitePixel(display As Pointer, screen_number As Integer) As Long
 
   
 
   
  <FONT color=gray>' ''int *XListDepths(display, screen_number, count_return)''
+
  <FONT color=gray>' ''int *XListDepths(Display *display, int screen_number, int count_return)''
  ' ''returns the array of depths that are available on the specified screen.''</font>
+
  ' ''Returns the array of depths that are available on the specified screen.''</font>
  '''Private''' Extern XListDepths(displayP As Pointer, screen_number As Integer, count_return As Pointer) As Pointer
+
  Private Extern XListDepths(display As Pointer, screen_number As Integer, count_return As Pointer) As Pointer
 
   
 
   
  <FONT color=gray>' ''int XScreenCount(display)''
+
  <FONT color=gray>' ''int XScreenCount(Display *display)''
  ' ''returns the number of available screens.''</font>
+
  ' ''Returns the number of available screens.''</font>
  '''Private''' Extern XScreenCount(displayP As Pointer) As Integer
+
  Private Extern XScreenCount(display As Pointer) As Integer
 
   
 
   
  <FONT color=gray>' ''XCloseDisplay (display)''
+
  <FONT color=gray>' ''XCloseDisplay (Display *display)''
  ' ''closes a display or disconnect from the X server.''</font>
+
  ' ''Closes a display or disconnect from the X server.''</font>
  '''Private''' Extern XCloseDisplay(displayP As Pointer)
+
  Private Extern XCloseDisplay(display As Pointer)
 
   
 
   
 
   
 
   
 
  '''Public''' Sub Main()
 
  '''Public''' Sub Main()
 
   
 
   
   Dim display_name, lista, lista_prof As Pointer
+
   Dim disp, lista, lista_prof As Pointer
   Dim depth, screen, connection As Integer
+
   Dim depth, screen, connection, i As Integer
   Dim listrm As Stream
+
 
   Dim j, b As Byte
+
<FONT color=gray>' ''Connessione al Server X e sua impostazione predefinita:''</font>
 +
   disp = XOpenDisplay(0)
 +
   If disp == 0 Then Error.Raise("Impossibile connettersi al Server X !")
 
   
 
   
 +
  screen = XDefaultScreen(disp)
 
   
 
   
<FONT color=gray>' ''Apertura dello schermo ed impostazione di default:''</font>
+
  depth = XDefaultDepth(disp, screen)
    display_name = XOpenDisplay(Null)
+
  If depth = 1 Then
+
    Print "E' evidente che hai uno schermo preistorico !"
    screen = XDefaultScreen(display_name)
+
  Else
+
    Print "Stai utilizzando uno schermo a colori con profondità: "; depth
    depth = XDefaultDepth(display_name, screen)
+
  Endif
    If depth = 1 Then
 
      Print "E' evidente che hai uno schermo preistorico !"
 
    Else
 
      Print "Stai utilizzando uno schermo a colori con profondità: " & depth
 
    Endif
 
 
        
 
        
    connection = XConnectionNumber(display_name)
+
  connection = XConnectionNumber(disp)
    Print "Il numero di connessione è "; connection
+
  Print "Il numero di connessione è "; connection
+
   
 
  <FONT color=gray>' ''Mostra le informazioni relative allo schermo:''</font>
 
  <FONT color=gray>' ''Mostra le informazioni relative allo schermo:''</font>
    Print "Lo schermo è: " & String@(XDisplayName(display_name))
+
  Print "Lo schermo è: "; String@(XDisplayName(disp))
 
      
 
      
    Print "La larghezza dello schermo è: "; XDisplayWidth(display_name, screen)
+
  Print "La larghezza dello schermo è: "; XDisplayWidth(disp, screen)
    Print "L'altezza dello schermo è: "; XDisplayHeight(display_name, screen)   
+
  Print "L'altezza dello schermo è: "; XDisplayHeight(disp, screen)   
    Print "La larghezza dello schermo è di " & XDisplayWidthMM(display_name, screen) & " millimetri"
+
  Print "La larghezza dello schermo è di "; XDisplayWidthMM(disp, screen); " millimetri"
+
 
    Print "Valore dei pixel neri dello schermo: " & XBlackPixel(display_name, screen)
+
  Print "Valore dei pixel neri dello schermo: "; XBlackPixel(disp, screen)
    Print "Valore dei pixel bianchi dello schermo: " & XWhitePixel(display_name, screen)
+
  i = XWhitePixel(disp, screen)
 +
  Print "Valore dei pixel bianchi dello schermo: "; i; " ("; Hex(i); ")"
 
      
 
      
 
      
 
      
    lista = Alloc(SizeOf(gb.Integer))
+
  lista = Alloc(SizeOf(gb.Integer), 1)
    lista_prof = XListDepths(display_name, screen, lista)
+
  lista_prof = XListDepths(disp, screen, lista)
    Print "Numero di valori disponibili della profondità dello schermo: "; Int@(lista)
+
  Print "Numero di valori disponibili della profondità dello schermo: "; Int@(lista)
  <FONT color=gray>' ''Dereferenziamo la variabile di tipo "puntatore" mediante i "Memory-Stream":''</font>
+
  <FONT color=gray>' ''Dereferenziamo la variabile di tipo "puntatore":''</font>
    listrm = Memory lista_prof For Read
+
  For i = 0 To (Int@(lista) - 1) * 4 Step 4
    For j = 0 To (Int@(lista) - 1) * 4 Step 4
+
    Print "Valore profondità disponibile: "; Byte@(lista_prof + i)
      Seek #listrm, j
+
  Next
      Read #listrm, b
+
     
      Print "Valore profondità disponibile: "; b
+
  Print "Schermi disponibili = "; XScreenCount(disp)
    Next
 
 
    
 
    
    Print "Schermi disponibili = "; XScreenCount(display_name)
+
  <FONT color=gray>' ''Chiude la libreria e libera la memoria allocata:''</font>
   
+
  XCloseDisplay(disp)
+
  Free(lista)
  <FONT color=gray>' ''Chiude la libreria:''</font>
 
    XCloseDisplay(display_name)
 
       
 
<FONT color=gray>' ''Libera la memoria allocata:''</font>
 
    Free(lista)
 
 
   
 
   
 
  '''End'''
 
  '''End'''

Versione attuale delle 15:57, 1 mag 2023

La libreria Xlib dello X Window System Standard, versione 11, consente - fra l'altro - anche di ottenere alcune informazioni in ordine agli schermi disponibili.

Si richiamerà l'attuale libreria condivisa di X11: "libX11.so.6.4.0 ".


Mostriamo di seguito un breve codice esemplificativo:

Library "libX11:6.4.0"

' Display *XOpenDisplay(char *display_name)
' Opens a connection to the X server that controls a display.
Private Extern XOpenDisplay(display_name As Pointer) As Pointer

' int XDefaultScreen (Display *display)
' Returns the default screen number referenced by the XOpenDisplay function.
Private Extern XDefaultScreen(display As Pointer) As Integer

' int XDefaultDepth (Display *display, int screen_number)
' Returns the depth (number of planes) of the default root window for the specified screen.
Private Extern XDefaultDepth(display As Pointer, screen_number As Integer) As Integer

' int XConnectionNumber(Display *display)
' Returns a connection number for the specified display.
Private Extern XConnectionNumber(display As Pointer) As Integer

' char *XDisplayName(char *string)
' Returns the name of the display that XOpenDisplay would attempt to use.
Private Extern XDisplayName(disp_string As Pointer) As Pointer

' int XDisplayWidth (Display *display, int screen_number)
' Returns the width of the screen in pixels.
Private Extern XDisplayWidth(display As Pointer, screen_number As Integer) As Integer

' int XDisplayHeight(Display *display, int screen_number)
' Returns an integer that describes the height of the screen in pixels.
Private Extern XDisplayHeight(display As Pointer, screen_number As Integer) As Integer

' int XDisplayWidthMM (Display *display, int screen_number)
' Returns the width of the specified screen in millimeters.
Private Extern XDisplayWidthMM(display As Pointer, screen_number As Integer) As Integer

' unsigned long XBlackPixel (Display *display, int screen_number)
' Returns the black pixel value for the specified screen.
Private Extern XBlackPixel(display As Pointer, screen_number As Integer) As Long

' unsigned long XWhitePixel (Display *display, int screen_number)
' Returns the white pixel value for the specified screen.
Private Extern XWhitePixel(display As Pointer, screen_number As Integer) As Long

' int *XListDepths(Display *display, int screen_number, int count_return)
' Returns the array of depths that are available on the specified screen.
Private Extern XListDepths(display As Pointer, screen_number As Integer, count_return As Pointer) As Pointer

' int XScreenCount(Display *display)
' Returns the number of available screens.
Private Extern XScreenCount(display As Pointer) As Integer

' XCloseDisplay (Display *display)
' Closes a display or disconnect from the X server.
Private Extern XCloseDisplay(display As Pointer)


Public Sub Main()

 Dim disp, lista, lista_prof As Pointer
 Dim depth, screen, connection, i As Integer
  
' Connessione al Server X e sua impostazione predefinita:
 disp = XOpenDisplay(0)
 If disp == 0 Then Error.Raise("Impossibile connettersi al Server X !")

 screen = XDefaultScreen(disp)

 depth = XDefaultDepth(disp, screen)
 If depth = 1 Then
   Print "E' evidente che hai uno schermo preistorico !"
 Else
   Print "Stai utilizzando uno schermo a colori con profondità: "; depth
 Endif
     
 connection = XConnectionNumber(disp)
 Print "Il numero di connessione è "; connection
   
' Mostra le informazioni relative allo schermo:
 Print "Lo schermo è: "; String@(XDisplayName(disp))
   
 Print "La larghezza dello schermo è: "; XDisplayWidth(disp, screen)
 Print "L'altezza dello schermo è: "; XDisplayHeight(disp, screen)  
 Print "La larghezza dello schermo è di "; XDisplayWidthMM(disp, screen); " millimetri"
  
 Print "Valore dei pixel neri dello schermo: "; XBlackPixel(disp, screen)
 i = XWhitePixel(disp, screen)
 Print "Valore dei pixel bianchi dello schermo: "; i; " ("; Hex(i); ")"
   
   
 lista = Alloc(SizeOf(gb.Integer), 1)
 lista_prof = XListDepths(disp, screen, lista)
 Print "Numero di valori disponibili della profondità dello schermo: "; Int@(lista)
' Dereferenziamo la variabile di tipo "puntatore":
 For i = 0 To (Int@(lista) - 1) * 4 Step 4
   Print "Valore profondità disponibile: "; Byte@(lista_prof + i)
 Next
      
 Print "Schermi disponibili = "; XScreenCount(disp)
 
' Chiude la libreria e libera la memoria allocata:
 XCloseDisplay(disp)
 Free(lista)

End