Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-10

Video: Color Picker ... and a question

7 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Anthony Walter

I wrote a class to support for global hotkeys on both Linux and Windows.

http://cache.getlazarus.org/video/colormix.mp4

In the video a color picker is activated anywhere when you press a global hotkey allow you to freeze the screen and use the mouse pick a color from any pixel on your display.

BUT there was a huge problem:

It seems near impossible for an app on my Ubuntu with Unity distro (and possibly other Linux distros) to bring an application to the foreground without direct interaction from the user.

Just to be clear, I was completely unable to programatically activate my app and send it to the front. I had to reset to a nasty cheat to get what you see in the video working (my app isn't actually activated after the pick color hotkey is pressed).

So my question is, on a Linux system using recent Gtk libraries, what is the definitive way to take the focus away from another application, show my application window, and bring it to the foreground in an active and focused state?

Application.BringToFront didn't work for me on my system. gtk_window_present didn't work for me on my system. A lot of other things didn't work.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20151018/3533f3dd/attachment-0001.html>

Reply by email

Michael Van Canneyt
to Anthony Walter
Anthony Walter wrote 23 lines
I wrote a class to support for global hotkeys on both Linux and Windows. http://cache.getlazarus.org/video/colormix.mp4 In the video a color picker is activated anywhere when you press a global hotkey allow you to freeze the screen and use the mouse pick a color from any pixel on your display. BUT there was a huge problem: It seems near impossible for an app on my Ubuntu with Unity distro (and possibly other Linux distros) to bring an application to the foreground without direct interaction from the user. Just to be clear, I was completely unable to programatically activate my app and send it to the front. I had to reset to a nasty cheat to get what you see in the video working (my app isn't actually activated after the pick color hotkey is pressed). So my question is, on a Linux system using recent Gtk libraries, what is the definitive way to take the focus away from another application, show my application window, and bring it to the foreground in an active and focused state?

Roughly said:
There is none that is guaranteed to work. You are at the mercy of the window manager. To my knowledge only the window manager, and it alone, can implement such shortcut keys.

Michael.

Reply by email

Anthony Walter
to Michael Van Canneyt

Michael, I apologize if I wasn't clear. The problems wasn't shortcut keys, rather it is showing an application window and bringing it to the foreground when your application isn't the active graphical application.

That is to say, for example, suppose you had a timer set to 3 minutes. Is there a way to activate your application and bring it to the foreground when the timer expires? How can applications bring themselves to the foreground on recent Gtk based desktops?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20151018/42c3105e/attachment.html>

Reply by email

Michael Van Canneyt
to Anthony Walter
Anthony Walter wrote
Michael, I apologize if I wasn't clear. The problems wasn't shortcut keys, rather it is showing an application window and bringing it to the foreground when your application isn't the active graphical application.

I understood. And that is what I answered to.

The fact that only the window manager can implement such a shortcut is a consequence from this.

Michael.

Reply by email

Ondrej Pokorny
to Anthony Walter: Michael, I apologize if I wasn't clear. The problems wasn't shortcut keys, rather it is…
Anthony Walter wrote 9 lines
Michael, I apologize if I wasn't clear. The problems wasn't shortcut keys, rather it is showing an application window and bringing it to the foreground when your application isn't the active graphical application. That is to say, for example, suppose you had a timer set to 3 minutes. Is there a way to activate your application and bring it to the foreground when the timer expires? How can applications bring themselves to the foreground on recent Gtk based desktops?

That would be interesting also for the "single Lazarus IDE" I developed recently. I was able to do it on Windows but not Linux/Gtk2. On Linux Lazarus IDE doesn't come up in the front, it only highlights the application bar button. But as Michael said, it's only possible if the window manager allows it.

Ondrej

Reply by email

Anthony Walter
to Ondrej Pokorny

Thanks for the replies. I'll continue to search for workarounds on Linux/Gtk and if I find anything useful I'll post about it and also add it to my github library.

And in case anyone is interested, here is the Linux/Gtk system I wrote to handle global hotkeys (which works perfectly):

https://github.com/sysrpl/Cross.Codebot/blob/master/source/codebot.input.hotkeys.pas

Ondrej, notice the dotted namespaces ... thanks for your CodeTools contributions.

And by the way, what's the status of integrating my patch for Unity's tray icon problems?

https://github.com/sysrpl/Lazarus.UnityAppIndicators -------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20151018/6fa7ffca/attachment.html>

Reply by email

Graeme Geldenhuys
to Anthony Walter: Michael, I apologize if I wasn't clear. The problems wasn't shortcut keys, rather it is…
Anthony Walter wrote
rather it is showing an application window and bringing it to the foreground when your application isn't the active graphical application.

Unlike Windows, X11 applications do not have much say in anything related to an application window (size, position, modal etc). They are at the mercy of the Window Manager. Applications under X11 simply request (ask for) position, size, modal, focus etc, but it is no guarantee they will get it, it is up to the Window Manager to decide if those requests are successful or not.

Generally, X11 is a lot less annoying than Windows, so you don't (easily) get pop-to-front, system modal etc ability. Such functionality is considered rude, and why X11 frowns upon it. That is life, and I find it refreshing.

Some desktop environments will flash the taskbar icon - if a taskbar exists in the desktop applications will use a
notification window, or System Tray icon to draw attention. Anything more, and it is the luck of the draw - no guarantee.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email