Conocer Id, Nombre De La Ventana Y PID De Los Programas Con Las Funciones Externas De X11


Objetivo: Conocer Id, Nombre De La Ventana Y PID De Los Programas Con Las Funciones Externas De X11
Hola amigos,
dejo este código para obtener con las funciones externas del API de X11 el numero identificativo, el nombre visible de la ventana de los programas activos, y el PID de estos programas.
Private Const MAX_PROPERTY_VALUE_LEN As Integer = 4096

Library "libX11:6.3.0"

Private Const XA_CARDINAL As Integer = 6
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(display$ As String) 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, datPID As Pointer
Dim x_num_Atom, rootW, tipo, formato As Integer
Dim err, n_fin, bytes_succ, i As Integer
Dim stId, stPid As Stream
Dim b As Byte
Dim pid As Integer
Dim id As String


disp = XOpenDisplay(Null)
If IsNull(disp) Then Error.Raise("Impossible abrir el server display X !")

rootW = XDefaultRootWindow(disp)

x_num_Atom = XInternAtom(disp, "_NET_CLIENT_LIST", 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("Impossible obtener datos de la función 'XGetWindowProperty' !")

If XA_WINDOW <> tipo Then Error.Raise("Tipo inválido de propiedad '_NET_CLIENT_LIST' !")

Print "Id", Null, "PID", "Nombre ventana\n"

p = Alloc(32)

stId = Memory dati For Read

For b = 1 To n_fin * 2

Read #stId, i

If i > 0 Then
XGetWMName(disp, i, p)
id = Hex(i)
x_num_Atom = XInternAtom(disp, "_NET_WM_PID", False)
err = XGetWindowProperty(disp, i, x_num_Atom, 0, MAX_PROPERTY_VALUE_LEN / 4, False, XA_CARDINAL, VarPtr(tipo), VarPtr(formato), VarPtr(n_fin), VarPtr(bytes_succ), VarPtr(datPID))
If err <> 0 Then Error.Raise("Impossible obtener datos de la función 'XGetWindowProperty' !")

If IsNull(datPID) = False Then
stPid = Memory datPID For Read
Read #stPid, pid
Endif
Print id, Null, pid, String@(Pointer@(p))
Endif

Next

' ...terminando:
stPid.Close
stId.Close
Free(p)
XCloseDisplay(disp)

End

última edición por vuott el Domingo, 09 Noviembre 2014, 23:01; editado 6 veces
Perfil MP  
Objetivo: Re: Conocer Id, Nombre De La Ventana Y PID De Los Programas Con Las Funciones Externas De X11
Muy interesante, gracias Vuott.

Perfil MP  
Objetivo: Re: Conocer Id, Nombre De La Ventana Y PID De Los Programas Con Las Funciones Externas De X11
shordi escribió: [Ver mensaje]
Muy interesante, gracias Vuott.


Gracias a ti, shordi.
Has visto ? En este caso tambien el código usa "Memory Stream" y "Punteros" !

Perfil MP  

Página 1 de 1


  
No puede crear mensajes
No puede responder temas
No puede editar sus mensajes
No puede borrar sus mensajes
No puede votar en encuestas
No puede adjuntar archivos
Puede descargar archivos
No puede publicar eventos en el calendario

   

Está utilizando la versión (Lo-Fi). Para ver la versión completa del foro, haga clic aquí.

Powered by Icy Phoenix based on phpBB
Design by DiDiDaDo

Página generada en:: 0.5358s (PHP: -61% SQL: 161%)
Consultas SQL: 45 - Debug off - GZIP Activado