Conoscere gli attributi della finestra di un programma con le funzioni esterne del API di X11

Da Gambas-it.org - Wikipedia.

Ogni finestra di un programma possiede degli attributi specificati nella Struttura XWindowAttributes della libreria di X11.

Per conoscere tali attributi si può utilizzare la funzione XGetWindowAttributes( ) della libreria condivisa: "libX11.so.6.4.0 ".

Tale funzione esterna richiede, fra l'altro, la specificazione del numero identificativo della finestra del programma, della quale si intende conoscere gli attributi specificati nella predett Struttura XWindowAttributes.


Mostriamo un esempio essenziale:

Library "libX11:6.4.0"

Public Struct XWindowAttributes
  x As Integer
  y As Integer
  width As Integer
  height As Integer
  border_width As Integer
  depth As Integer
  visual As Pointer
  root As Long
  classi As Integer
  bit_gravity As Integer
  win_gravity As Integer
  backing_store As Integer
  backing_planes As Long
  backing_pixel As Long
  save_under As Boolean
  colormap As Long
  map_installed As Boolean
  map_state As Integer
  all_event_masks As Long
  your_event_mask As Long
  do_not_propagate_mask As Long
  override_redirect As Boolean
  screenp As Pointer
End Struct

' 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

' Status XGetWindowAttributes(Display *display, Window w, XWindowAttributes *window_attributes_return)
' Returns the current attributes for the specified window to an XWindowAttributes structure.
Private Extern XGetWindowAttributes(display As Pointer, w As Long, window_attr As XWindowAttributes) As Integer

' XCloseDisplay(Display *display)
' Closes the connection to the X server for the display specified in the Display structure and destroys all windows.
Private Extern XCloseDisplay(display As Pointer)


Public Sub Main()

 Dim disp As Pointer
 Dim attr As New XWindowAttributes

' Connessione al server X con impostazione di default:
 disp = XOpenDisplay(0)
 If disp == 0 Then Error.raise("Errore !")

 XGetWindowAttributes(disp, num_ID_della_finestra, attr)
 
' Mostra le dimensioni in pixel della finestra del programma, specificata dal suo ID nella funzione esterna precedente:
 Print attr.width, attr.height

' Chiude la libreria X11:
 XCloseDisplay(disp)

End


Riferimenti