Recent

Author Topic: GetForegroundWindow returns always 0 on Ubuntu 16.04 gtk2  (Read 4761 times)

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
GetForegroundWindow returns always 0 on Ubuntu 16.04 gtk2
« 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
« Last Edit: August 07, 2017, 05:32:43 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: GetForegroundWindow returns always 0 on Ubuntu 16.04 gtk2
« Reply #1 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.
Specialize a type, not a var.

ludolaz

  • Newbie
  • Posts: 5
Re: GetForegroundWindow returns always 0 on Ubuntu 16.04 gtk2
« Reply #2 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

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: GetForegroundWindow returns always 0 on Ubuntu 16.04 gtk2
« Reply #3 on: August 07, 2017, 05:28:15 pm »
hello,
i have found this message 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) ? 


« Last Edit: August 07, 2017, 05:36:37 pm by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: GetForegroundWindow returns always 0 on Ubuntu 16.04 gtk2
« Reply #4 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...
« Last Edit: August 07, 2017, 06:09:27 pm by Thaddy »
Specialize a type, not a var.

 

TinyPortal © 2005-2018