Recent

Author Topic: XGetWindowProperty and PPCuchar property  (Read 8366 times)

Dibo

  • Hero Member
  • *****
  • Posts: 1048
XGetWindowProperty and PPCuchar property
« on: August 12, 2010, 01:05:17 pm »
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  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);  
  2. var  
  3.   aDis: PDisplay;  
  4.   aRootWin: TWindow;  
  5.   aSkypeInst: TAtom;  
  6.   aStatus: cint;  
  7.   type_ret: TAtom;  
  8.   format_ret: integer;  
  9.   nitems_ret: culong;  
  10.   bytes_after_ret: culong;  
  11.   prop: PPcuchar;  
  12. begin  
  13.   aDis := xlib.XOpenDisplay(nil);  
  14.   try  
  15.     aRootWin := XDefaultRootWindow(aDis);  
  16.     aSkypeInst := XInternAtom(aDis, '_SKYPE_INSTANCE', True);  
  17.     if aSkypeInst = 0 then begin  
  18.       Log('Skype instance not found');  
  19.       Exit;  
  20.     end;  
  21.     aStatus := XGetWindowProperty(aDis, aRootWin, aSkypeInst, 0, 1, False, XA_WINDOW, @type_ret,  @format_ret, @nitems_ret, @bytes_after_ret, prop);  
  22.     XFree(prop);  
  23.   finally  
  24.     XFlush(aDis);  
  25.   end;  
  26. 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
« Last Edit: August 13, 2010, 06:38:20 pm by Dibo »

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: XGetWindowProperty and PPCuchar property
« Reply #1 on: August 12, 2010, 01:37:08 pm »
Maybe this function helps. Result should be in "Value". Don't know if this works on 64bit.

Code: Pascal  [Select][+][-]
  1. function GetProp(Dpy: PDisplay; Win: TWindow; Prop: TAtom; out Value: Cardinal; Offset: Cardinal): Boolean;
  2. var
  3.   ActualTypeReturn: TAtom;
  4.   ActualFormatReturn: LongInt;
  5.   NItemsReturn, BytesAfterReturn: Cardinal;
  6.   Ptr: PByte;
  7. begin
  8.   Result := XGetWindowProperty(Dpy, Win, Prop, Offset, 1, LongBool(0), AnyPropertyType, @ActualTypeReturn, @ActualFormatReturn, @NItemsReturn, @BytesAfterReturn, @Ptr) = Success;
  9.   if Result then
  10.   try
  11.     if (ActualTypeReturn = None) or (ActualFormatReturn <> 32) or not Assigned(Ptr) then
  12.       Result := False;
  13.     if Result then Value := PCardinal(Ptr)^;
  14.   finally
  15.     if Assigned(Ptr) then XFree(Ptr);
  16.   end;
  17. end;
  18.  

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Re: XGetWindowProperty and PPCuchar property
« Reply #2 on: August 12, 2010, 03:36:24 pm »
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  [Select][+][-]
  1. Window skype_win = (Window)-1;
  2.  
  3. status = XGetWindowProperty(disp, root, skype_inst, 0, 1, False, XA_WINDOW, &type_ret, &format_ret, &nitems_ret, &bytes_after_ret, &prop);
  4. skype_win = * (const unsigned long *) prop & 0xffffffff;
  5. XFree(prop);
  6.  
And this is python :P
Code: Python  [Select][+][-]
  1.        
  2. for prop in self.win['root'].list_properties():
  3.   if self.display.get_atom_name(prop) == "_SKYPE_INSTANCE":
  4.     fullprop = self.win['root'].get_full_property(prop, 0)
  5.     skypewinid = fullprop.value[0]
  6.     print "Info: Skype is running with id", skypewinid
  7.     self.win['skype'] = self.display.create_resource_object('window', skypewinid)
  8.  

Ehh, It is too difficult for me ...

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: XGetWindowProperty and PPCuchar property
« Reply #3 on: August 12, 2010, 03:48:46 pm »
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  [Select][+][-]
  1. uses xlib, x, xatom, xutil;
  2.  
  3. procedure TForm1.Button1Click(Sender: TObject);
  4. var
  5.   aDis: PDisplay;
  6.   aRootWin: TWindow;
  7.   aSkypeInst: TAtom;
  8.   aStatus: cint;
  9.   type_ret: TAtom;
  10.   format_ret: integer;
  11.   nitems_ret: culong;
  12.   bytes_after_ret: culong;
  13.   prop: Pcuchar;
  14.   myprop: PCardinal;
  15.   SkypeWinID: TWindow;
  16. begin
  17.   aDis := xlib.XOpenDisplay(nil);
  18.   try
  19.     aRootWin := XDefaultRootWindow(aDis);
  20.     aSkypeInst := XInternAtom(aDis, '_SKYPE_INSTANCE', True);
  21.     if aSkypeInst = 0 then begin
  22.       Log('Skype instance not found');
  23.       Exit;
  24.     end;
  25.     aStatus := XGetWindowProperty(aDis, aRootWin, aSkypeInst, 0, 1, False, XA_WINDOW, @type_ret,  @format_ret, @nitems_ret, @bytes_after_ret, @prop);
  26.     myprop := PCardinal(prop);
  27.     SkypeWinID := TWindow(myprop^);
  28.     XFree(prop);
  29.   finally
  30.     XFlush(aDis);
  31.   end;
  32. end;  
  33.  

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Re: XGetWindowProperty and PPCuchar property
« Reply #4 on: August 12, 2010, 08:17:27 pm »
Thanks! I'm at the stage when skype ask user for permission to access my program. So, it's alive! :)

 

TinyPortal © 2005-2018