Ottenere informazioni relative allo schermo mediante le funzioni del API di CBX

Da Gambas-it.org - Wikipedia.

Il protocollo XCB (X C-language Binding) è stato realizzato con lo scopo di sostituire Xlib presentando rispetto a quest'ultimo ad esempio dimensioni ridotte, un accesso diretto al protocollo, migliorando il threading e la estensibilità.
E' possibile mediante alcune risorse del API di CBX ottenere informazioni generali relative allo schermo in uso.

Per poter fruire delle risorse di XCB in Gambas, bisognerà utilizzare la libreria attualmente alla versione: "libxcb.so.1.1.0"


Mostriamo un semplice esempio:

Library "libxcb:1.1.0"

Public Struct xcb_screen_t
  root As Integer
  default_colormap As Integer
  white_pixel As Integer
  black_pixel As Integer
  current_input_masks As Integer
  width_in_pixels As Short
  height_in_pixels As Short
  width_in_millimeters As Short
  height_in_millimeters As Short
  min_installed_maps As Short
  max_installed_maps As Short
  root_visual As Integer
  backing_stores As Byte
  save_unders As Byte
  root_depth As Byte
  allowed_depths_len As Byte
End Struct
 
' xcb_connection_t * xcb_connect (const char *display, int *screen)
' Connects to the X server specified by display.
Private Extern xcb_connect(display As String, screen As Pointer) As Pointer

' const xcb_setup_t * xcb_get_setup (xcb_connection_t *c)
' Accessor for the data returned by the server when the xcb_connection_t was initialized.
Private Extern xcb_get_setup(c As Pointer) As Pointer

' xcb_screen_iterator_t xcb_setup_roots_iterator (const xcb_setup_t *R)
' Get the next element of the iterator.
Private Extern xcb_setup_roots_iterator(R As Pointer) As Pointer

' void xcb_disconnect (xcb_connection *c)
' Closes the file descriptor and frees all memory associated with the connection.
Private Extern xcb_disconnect(c As Pointer)


Public Sub Main()

 Dim disp, xcb_setup As Pointer
 Dim scr As Xcb_screen_t
 
' Apre una connessione con il server X:
 disp = xcb_connect(Null, 0)
 
' Ottiene il primo schermo:
 xcb_setup = xcb_get_setup(disp)
 
 scr = xcb_setup_roots_iterator(xcb_setup)
 
' Mostra in console alcune informazioni sullo schermo utilizzato:
 With scr
   Print "Dimensioni dello schermo:\n"
   Print "Larghezza in pixel:           "; .width_in_pixels
   Print "Altezza in pixel:              "; .height_in_pixels
   Print "Larghezza in millimetri:       "; .width_in_millimeters
   Print "Altezza in millimetri:         "; .height_in_millimeters
   Print "Mappa dei colori predefinita:   "; .default_colormap
 End With
  
' Va in chiusura:
 xcb_disconnect(disp)

End



Riferimenti