Individuare l'ID ed il nome della finestra attiva mediante le funzioni del API di X11
Da Gambas-it.org - Wikipedia.
Versione del 26 ott 2014 alle 12:17 di Vuott (Discussione | contributi) (Creata pagina con 'La libreria '''X11''' ci consente anche di individuare il numero identificativo (''ID'') ed il nome della finestra attualmente attiva. Sarà necessario richiamare la libreria...')
La libreria X11 ci consente anche di individuare il numero identificativo (ID) ed il nome della finestra attualmente attiva.
Sarà necessario richiamare la libreria del sistema X (nella sua attuale versione): "libX11.so.6.3.0"
Mostriamo di seguito un possibile breve codice al riguardo:
Private Const MAX_PROPERTY_VALUE_LEN As Integer = 4096 Library "libX11:6.3.0" Private Const XA_WINDOW As Integer = 33 ' Display *XOpenDisplay(display_name) ' Opens a connection to the X server that controls a display. Private Extern XOpenDisplay(displayP As Pointer) As Pointer ' XCloseDisplay (display) ' Closes a display or disconnect from the X server. Private Extern XCloseDisplay(displayP As Pointer) ' Window XDefaultRootWindow(display) ' Return the root window for the default screen. Private Extern XDefaultRootWindow(displayP As Pointer) As Integer ' Atom XInternAtom(display, atom_name, only_if_exists) ' Returns the atom identifier associated with the specified atom_name string. Private Extern XInternAtom(displayP As Pointer, atom_name As String, only_if_exists As Boolean) As Integer ' int XGetWindowProperty(display, w, property, long_offset, long_length, delete, req_type, actual_type_return, actual_format_return, nitems_return, bytes_after_return, prop_return) ' Returns the actual type of the property; the actual format of the property. Private Extern XGetWindowProperty(displayP As Pointer, wI As Integer, py As Integer, lo As Long, ll As Long, d As Boolean, rt As Integer, at As Pointer, af As Pointer, ni As Pointer, ba As Pointer, pr As Pointer) As Integer ' XGetWMName(display, w, text_prop_return) ' Calls XGetTextProperty() to obtain the WM_NAME property. Private Extern XGetWMName(displayP As Pointer, w As Integer, text_prop_return As Pointer) As Integer Public Sub Main() Dim disp, dati, p As Pointer Dim x_num_Atom, rootW, tipo, formato As Integer Dim err, n_fin, bytes_succ, i As Integer Dim st As Stream Dim b As Byte disp = XOpenDisplay(0) If IsNull(disp) Then Error.Raise("Impossibile aprire lo schermo !") rootW = XDefaultRootWindow(disp) x_num_Atom = XInternAtom(disp, "_NET_ACTIVE_WINDOW", False) err = XGetWindowProperty(disp, rootW, x_num_Atom, 0, MAX_PROPERTY_VALUE_LEN / 4, False, XA_WINDOW, VarPtr(tipo), VarPtr(formato), VarPtr(n_fin), VarPtr(bytes_succ), VarPtr(dati)) If err <> 0 Then Error.Raise("Impossibile ottenere dati dalla funzione 'XGetWindowProperty' !") If XA_WINDOW <> tipo Then Error.Raise("Tipo invalido di proprietà '_NET_ACTIVE_WINDOW' !") Print "Id", Null, "Nome della finestra attiva\n" p = Alloc(32) st = Memory dati For Read
Read #st, i XGetWMName(disp, i, p) Print Hex(i), Null, String@(Pointer@(p)) ' Va in chiusura: st.Close Free(p) XCloseDisplay(disp) End