Forum > Linux

XGetWindowProperty and PPCuchar property

(1/1)

Dibo:
Hi,

I'm writing plugin for Skype on linux. I found the sample code in C++, but I'm not good with pointers and I'm stuck. I have this:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button1Click(Sender: TObject);  var    aDis: PDisplay;    aRootWin: TWindow;    aSkypeInst: TAtom;    aStatus: cint;    type_ret: TAtom;    format_ret: integer;    nitems_ret: culong;    bytes_after_ret: culong;    prop: PPcuchar;  begin    aDis := xlib.XOpenDisplay(nil);    try      aRootWin := XDefaultRootWindow(aDis);      aSkypeInst := XInternAtom(aDis, '_SKYPE_INSTANCE', True);      if aSkypeInst = 0 then begin        Log('Skype instance not found');        Exit;      end;      aStatus := XGetWindowProperty(aDis, aRootWin, aSkypeInst, 0, 1, False, XA_WINDOW, @type_ret,  @format_ret, @nitems_ret, @bytes_after_ret, prop);      XFree(prop);    finally      XFlush(aDis);    end;  end;
If Skype running. function return this values:

Status: 0
TypeRet: 33
format_ret: 32
nitems_ret: 1
bytes_after_ret: 0

... and when I turn off Skype, all params are 0. So it looks like I'm going the right way. But I don't know how to get value from last param. He have type PPCuchar (It's pointer to array with items?). It should give skype window ID (TWindow). This is documentation of this function:
http://tronche.com/gui/x/xlib/window-information/XGetWindowProperty.html

Regards

theo:
Maybe this function helps. Result should be in "Value". Don't know if this works on 64bit.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function GetProp(Dpy: PDisplay; Win: TWindow; Prop: TAtom; out Value: Cardinal; Offset: Cardinal): Boolean;var  ActualTypeReturn: TAtom;  ActualFormatReturn: LongInt;  NItemsReturn, BytesAfterReturn: Cardinal;  Ptr: PByte;begin  Result := XGetWindowProperty(Dpy, Win, Prop, Offset, 1, LongBool(0), AnyPropertyType, @ActualTypeReturn, @ActualFormatReturn, @NItemsReturn, @BytesAfterReturn, @Ptr) = Success;  if Result then  try    if (ActualTypeReturn = None) or (ActualFormatReturn <> 32) or not Assigned(Ptr) then      Result := False;    if Result then Value := PCardinal(Ptr)^;  finally    if Assigned(Ptr) then XFree(Ptr);  end;end; 

Dibo:
Hm, this return me a big number: 98566204. It don't look like PID. Actually I do not know what I should get.

This is C code:

--- Code: C  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Window skype_win = (Window)-1; status = XGetWindowProperty(disp, root, skype_inst, 0, 1, False, XA_WINDOW, &type_ret, &format_ret, &nitems_ret, &bytes_after_ret, &prop);skype_win = * (const unsigned long *) prop & 0xffffffff;XFree(prop); And this is python :P

--- Code: Python  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---        for prop in self.win['root'].list_properties():  if self.display.get_atom_name(prop) == "_SKYPE_INSTANCE":    fullprop = self.win['root'].get_full_property(prop, 0)    skypewinid = fullprop.value[0]    print "Info: Skype is running with id", skypewinid    self.win['skype'] = self.display.create_resource_object('window', skypewinid) 
Ehh, It is too difficult for me ...

felipemdc:
The format of the property is returned in format_ret: 32.

From some Docs I found in the internet:

If the returned format is 8, the returned data is represented as a char array. If the returned format is 16, the returned data is represented as a short array and should be cast to that type to obtain the elements. If the returned format is 32, the returned data is represented as a long array and should be cast to that type to obtain the elements.

So this should work:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses xlib, x, xatom, xutil; procedure TForm1.Button1Click(Sender: TObject);var  aDis: PDisplay;  aRootWin: TWindow;  aSkypeInst: TAtom;  aStatus: cint;  type_ret: TAtom;  format_ret: integer;  nitems_ret: culong;  bytes_after_ret: culong;  prop: Pcuchar;  myprop: PCardinal;  SkypeWinID: TWindow;begin  aDis := xlib.XOpenDisplay(nil);  try    aRootWin := XDefaultRootWindow(aDis);    aSkypeInst := XInternAtom(aDis, '_SKYPE_INSTANCE', True);    if aSkypeInst = 0 then begin      Log('Skype instance not found');      Exit;    end;    aStatus := XGetWindowProperty(aDis, aRootWin, aSkypeInst, 0, 1, False, XA_WINDOW, @type_ret,  @format_ret, @nitems_ret, @bytes_after_ret, @prop);    myprop := PCardinal(prop);    SkypeWinID := TWindow(myprop^);    XFree(prop);  finally    XFlush(aDis);  end;end;   

Dibo:
Thanks! I'm at the stage when skype ask user for permission to access my program. So, it's alive! :)

Navigation

[0] Message Index

Go to full version