Lazarus

Programming => Widgetset => GTK => Topic started by: Jurassic Pork on August 07, 2017, 05:27:17 am

Title: GetForegroundWindow returns always 0 on Ubuntu 16.04 gtk2
Post by: Jurassic Pork on August 07, 2017, 05:27:17 am
hello,
i try to get the window handle of the active window on X gtk2 Ubuntu with the function GetForegroundWindow . I get always 0 .
The problem seems to be in the function TGtk2WidgetSet.X11GetActiveWindow of  file gtk2widgetset.inc :
The function XGetWindowProperty return 0 in the ActualFormatReturn variable which is not good ( <> 32 ) .
Code: Pascal  [Select][+][-]
  1.   Valid:=XGetWindowProperty(Display, RootWin, WMAtom, 0, 1, False,
  2.                                  AnyPropertyType, @ActualTypeReturn,
  3.                                  @ActualFormatReturn, @NItemsReturn,
  4.                                  @BytesAfterReturn, @Ptr)=0;
  5.   if Valid then
  6.   try
  7.     if (ActualTypeReturn = None) or (ActualFormatReturn <> 32) or not Assigned(Ptr) then
  8.       Valid := False;
  9.     if Valid then ResultWindow := PWindow(Ptr)^;
  10.   finally
  11.     if Assigned(Ptr) then XFree(Ptr);
  12.   end;  

Lazarus 1.8RC3 Lubuntu 16.04 64 bits   GTk2 .

What is wrong ?  %)

Friendly, J.P
Title: Re: GetForegroundWindow returns always 0 on Ubuntu 16.04 gtk2
Post by: Thaddy on August 07, 2017, 10:06:16 am
The Active window needs GetActiveWindow, not GetForegroundWindow.

Also note I can not replicate the issue on Raspbian/GTK2  with trunk/trunk: I obtain valid handles.
Title: Re: GetForegroundWindow returns always 0 on Ubuntu 16.04 gtk2
Post by: ludolaz on August 07, 2017, 01:59:24 pm
Hi
GetActiveWindow doesn't works : you get the active window of your thread, never working with an other process (always return 0)
Only GetForegroundWindow can return handle for active window, not depending of the process.
It works good... Except if you're working with ubuntu 16.04 Lazarus 1.6 x64 :-(
ludo
Title: Re: GetForegroundWindow returns always 0 on Ubuntu 16.04 gtk2
Post by: Jurassic Pork on August 07, 2017, 05:28:15 pm
hello,
i have found this message (https://forum.lazarus.freepascal.org/index.php/topic,10148.msg50163.html#msg50163) from  felipemdc
So i change the beginning of the function  TGtk2WidgetSet.X11GetActiveWindow
replace this :
Code: Pascal  [Select][+][-]
  1. ActualFormatReturn: LongInt;
  2. NItemsReturn, BytesAfterReturn: Cardinal;
  3. Ptr: PByte;
by this :
Code: Pascal  [Select][+][-]
  1. ActualFormatReturn: integer;
  2.   NItemsReturn, BytesAfterReturn: culong;
  3.   Ptr: Pcuchar;  
and now it works !!!    ::)     but is it good in all linux O.S ? (32 or 64 bits) ? 


Title: Re: GetForegroundWindow returns always 0 on Ubuntu 16.04 gtk2
Post by: Thaddy on August 07, 2017, 06:07:10 pm
It probably works and PByte is a bug if the code did not include the terminating zero (X11 documentation XGetWindowProperty), hence PChar works UNLESS the pchar is nil: The documentation specifies that even empty there is a zero char...
TinyPortal © 2005-2018