Ottenere informazioni relative allo schermo mediante la funzione ioctl()

Da Gambas-it.org - Wikipedia.

Con la funzione esterna "ioctl()" di C è possibile anche ottenere alcune in formazioni relative allo schermo, come ad esempio le sue "reali" dimensioni.
In particolare mediante la funzione esterna "ioctl()" si leggerà il file device "/dev/fb*" [nota 1] e si caricheranno i valori nella Struttura "fb_var_screeninfo", dalla quale si leggeranno i membri "height" e "width".
Mostriamo un esempio pratico:

Library "libc:6"

Public Struct fb_var_screeninfo
  xres As Integer
  yres As Integer
  xres_virtual As Integer
  yres_virtual As Integer
  xoffset As Integer
  yoffset As Integer
  bits_per_pixel As Integer
  grayscale As Integer
  red_offset As Integer
  red_length As Integer
  red_msb_right As Integer
  green_offset As Integer
  green_length As Integer
  green_msb_right As Integer
  blue_offset As Integer
  blue_length As Integer
  blue_msb_right As Integer
  transp_offset As Integer
  transp_length As Integer
  transp_msb_right As Integer
  nonstd As Integer
  activate As Integer
  height As Integer
  width As Integer
  accel_flags As Integer
  pixclock As Integer
  left_margin As Integer
  right_margin As Integer
  upper_margin As Integer
  lower_margin As Integer
  hsync_len As Integer
  vsync_len As Integer
  sync As Integer
  vmode As Integer
  rotate As Integer
  colorspace As Integer
  reserved[4] As Integer
End Struct

Private Const FBIOGET_VSCREENINFO As Integer = &4600

' int ioctl (int __fd, unsigned long int __request, ...)
' Perform the I/O control operation specified by REQUEST on FD.
Private Extern ioctl(__fd As Integer, __request As Long, var As Fb_var_screeninfo) As Integer


Public Sub Main()

 Dim fl As File
 Dim si As New Fb_var_screeninfo

 fl = Open "/dev/fb0" For Read
 
 ioctl(fl.Handle, FBIOGET_VSCREENINFO, si)
 
 Print "Informazioni dello schermo:\n"
 Print "Risoluzione: "; si.xres; "x"; si.yres; " pixel"
 Print "Bit per pixel: "; si.bits_per_pixel
 Print "Altezza: mm\e[1m"; si.height, " \e[0mLarghezza: mm\e[1m"; si.width
 
 fl.Close

End


Note