Recent

Author Topic: Bring window of another application on top of all other application windows  (Read 581 times)

Ricco42

  • Newbie
  • Posts: 4
Hi guys,

I try to bring a specific window of another application on top of all other application windows if I press a button in my application.
My OS is Ubuntu 20.04.3 LTS.

My code highlights the other application in the Bottom Panel and if it was minimized it restores the window but it is not on top of all other application windows.

Code: Pascal  [Select][+][-]
  1. [...]
  2. uses
  3.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  4.   xlib, x, ctypes, DateUtils;
  5. [...]
  6.  
  7. procedure TForm1.Button4Click(Sender: TObject);
  8. var display: PDisplay;
  9.     fenster: TWindow;
  10.     root:TWindow;
  11.     standard_bildschirm:cint;
  12.     myevent:TXEvent;
  13. begin
  14.  fenster:=$36000fc;
  15.  
  16.  display := XOpenDisplay(nil);
  17.  if (display = nil) then ShowMessage('Display Zugriff fehlgeschlagen :(');
  18.  
  19.  standard_bildschirm:=DefaultScreen(display);
  20.  
  21.  root:=RootWindow(display,standard_bildschirm);
  22.  
  23.  myevent._type:=ClientMessage;
  24.  myevent.xclient.message_type:=XInternAtom(display,'_NET_ACTIVE_WINDOW',false);
  25.  myevent.xclient.window:=fenster;
  26.  myevent.xclient.format:=32;
  27.  
  28.  XSendEvent(display,
  29.             root,
  30.             False,
  31.             VisibilityChangeMask
  32.             OR StructureNotifyMask
  33.             OR SubstructureRedirectMask
  34.             OR FocusChangeMask
  35.             OR PropertyChangeMask,
  36.             @myevent);
  37.  
  38.  XMapWindow(display,fenster);
  39.  
  40.  XFlush(display);
  41.  
  42.  XCloseDisplay(display);
  43.  
  44. end;
  45.  

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2044
  • Fifty shades of code.
    • Delphi & FreePascal
There is no need to crosspost on same forum, you could have asked within other topic that a mod moves it for you (if they wouldnt do on their own)

At least on Windows OS it would violate the OS specific Window rules.
"Bringing a Window on top of all others" via external 3rd party would cause troubles, imagine more than one app is running and do such, which Window will win?
If such rule is same on your OS, or to be more specific your Window-Manager, that I can not tell.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

dbannon

  • Hero Member
  • *****
  • Posts: 2787
    • tomboy-ng, a rewrite of the classic Tomboy
wmctrl is a command line tool, installed by default on many Linuxes, available on almost all others.

You can call it (as a process) from within your app and it will bring in any window you can identify to the forground. If you use Workspaces, it will move windows between workspaces for you too.

Davo

Code: Pascal  [Select][+][-]
  1. function TSearchForm.MoveWindowHere(WTitle: string): boolean;
  2. {$ifdef LINUX}
  3. var
  4.     AProcess: TProcess;
  5.     List : TStringList = nil;    {$endif}
  6. begin
  7.     Result := False;
  8.     AProcess := TProcess.Create(nil);
  9.     AProcess.Executable:= 'wmctrl';
  10.     AProcess.Parameters.Add('-R' + WTitle);
  11.     AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];
  12.     try
  13.         AProcess.Execute;
  14.         Result := (AProcess.ExitStatus = 0);        // says at least one packet got back
  15.     except on
  16.         E: EProcess do debugln('Is wmctrl available ? Cannot move ' + WTitle);
  17.     end;
  18.     List := TStringList.Create;
  19.     List.LoadFromStream(AProcess.Output);       // just to clear it away.
  20.     List.Free;
  21.     AProcess.Free;
  22. end;    
   

I have a feeling it has a problem with Wayland, not sure ....
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Ricco42

  • Newbie
  • Posts: 4
@KodeZwerg: Sorry for crossposting.


@dbannon: Thanks, works  :)

 

TinyPortal © 2005-2018