Recent

Author Topic: Register global hotkey  (Read 1430 times)

LemonParty

  • Sr. Member
  • ****
  • Posts: 393
Register global hotkey
« on: November 08, 2025, 09:05:25 pm »
Is there a library to register global hotkeys in Linux?
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

Thaddy

  • Hero Member
  • *****
  • Posts: 18728
  • To Europe: simply sell USA bonds: dollar collapses
Re: Register global hotkey
« Reply #1 on: November 09, 2025, 12:46:46 pm »
This differs per linux version.
Qt has QxtGlobalShortcut
X11 has some features for it. XGrabKey.
You can use xdotool
There is no single solution I am aware of and I am having trouble with WayLand(again)
« Last Edit: November 09, 2025, 01:01:16 pm by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

regs

  • Jr. Member
  • **
  • Posts: 97
Re: Register global hotkey
« Reply #2 on: December 28, 2025, 11:09:44 am »
I was making one for X11 and without Wayland support of course, as it still doesn't have this functionality.
https://github.com/regs01/LazGlobalHotKey

And if you are leoburn5 on Github you might check and confirm fixes for Windows.

Thaddy

  • Hero Member
  • *****
  • Posts: 18728
  • To Europe: simply sell USA bonds: dollar collapses
Re: Register global hotkey
« Reply #3 on: December 28, 2025, 11:21:00 am »
I made one in the related thread for X this year. Does not work well with Gnome, though. That seems to have its own mind about hotkey management. Works good with Xfce. Plain X-windows and also uses GTK2.
In Qt6 it is very easy and works on Wayland.
It is my intention to move to Qt permanently, given the status of GTK2 development and support. Lazarus should drop GTK2 as default.

Note that moving to Qt does not solve the general problem that it differs per distribution: Wayland expects a distribution to write its own keyboard management. Wayland itself does not have any.
« Last Edit: December 28, 2025, 11:25:48 am by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...


regs

  • Jr. Member
  • **
  • Posts: 97
Re: Register global hotkey
« Reply #5 on: December 31, 2025, 03:35:47 am »
Lazarus should drop GTK2 as default.
Strongly disagree. GTK2 is a powerhorse. Let alone poor high DPI support in Qt6 itself. And not everyone using Qt environments.

Thaddy

  • Hero Member
  • *****
  • Posts: 18728
  • To Europe: simply sell USA bonds: dollar collapses
Re: Register global hotkey
« Reply #6 on: December 31, 2025, 10:20:12 am »
GTK2 is already dropped by most distro's in case you are living underground or on mars.
There is no support for it either.
« Last Edit: December 31, 2025, 10:28:54 am by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

El Salvador

  • Full Member
  • ***
  • Posts: 141
Re: Register global hotkey
« Reply #7 on: December 31, 2025, 12:44:32 pm »
Qt has QxtGlobalShortcut

In QT*, I'm using QNativeEventFilter and XGrabKey(). Simpler and more immediate. But no Wayland. https://github.com/salvadorbs/AsuiteComps/blob/main/library/platform/unix/Hotkeys.Manager.Platform.pas

regs

  • Jr. Member
  • **
  • Posts: 97
Re: Register global hotkey
« Reply #8 on: January 11, 2026, 03:50:13 am »
GTK2 is already dropped by most distro's in case you are living underground or on mars.
There is no support for it either.
I don't know a single distro that has it dropped. But I presume there might be some from Red Hat for obvious reasons, but no more. Any way, until GTK have proper scaling and theming GTK2 is only way for GTK DEs. And I don't like mix, it doesn't look good. Also GTK3/4 by nature has issues with X11 protocols, like KeyPress events and XTestFakeKeyEvent. That is crucial for accessibility and input assistance. So GTK2 still should be here. May be eventually after moving to GTK4 GTK3 could be dropped, but not GTK2.
« Last Edit: January 11, 2026, 03:56:06 am by regs »

Thaddy

  • Hero Member
  • *****
  • Posts: 18728
  • To Europe: simply sell USA bonds: dollar collapses
Re: Register global hotkey
« Reply #9 on: January 11, 2026, 07:30:07 am »
@regs

Examples:
https://artixlinux.org/news.php
https://gtk.org
https://www.phoronix.com/news/RHEL-10-No-GTK2
https://lists.debian.org/debian-devel/2026/01/msg00090.html
Gtk no longer supports it themselves.
And that is the reason most distro's have dropped it or will drop it:
It is abandonware.

https://chat.deepseek.com/share/t4i8q26fsnucytwv7t for a discussion

A summary from Copilot says the same:
What this means for Lazarus / FPC developers

GTK2 is now:

- **Unmaintained upstream**
- **Being removed from major distros**
- **A security risk**
- **A packaging burden**

For Lazarus specifically, this means:

- GTK2 widgetset will become increasingly difficult to ship.
- GTK3 and Qt5/Qt6 are the only viable long‑term targets.
- Wayland‑based desktops will further complicate GTK2 use.

The latter point is already a real issue!
I am actively migrating to Qt6 with the remark that I only recently realized I was being an ostrich with my head in the ground myself. Gone are the Wayland problems.

It really isn't a good idea to develop against the gtk2 widgetset for new software.
Myself, I was also late to realize that, basically when I had to install GTK2 from Universe on Ubuntu and the notes from the Debian developers.
« Last Edit: January 11, 2026, 08:09:48 am by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

robert rozee

  • Sr. Member
  • ****
  • Posts: 295
Re: Register global hotkey
« Reply #10 on: January 21, 2026, 11:50:20 pm »
[...]
Gtk no longer supports it themselves.
And that is the reason most distro's have dropped it or will drop it:
It is abandonware.
[...]

abandonware... or bug-free and feature complete? i can think of many examples of software that has remained static for many years simply because it is totally functional and usable, without need for any further 'tinkering'.

could GTK2 not be one such piece of software - that works adequately, interfaces with X11 without any significant issue, and would not benefit from further development work? as for the need to interface with Wayland, from where i sit Wayland seems to be still at the 'experimental' stage, has numerous incompatibilities, and well short of being 'production ready'. when will Wayland be production ready - who knows? it could be another decade.


"most distro's have dropped it or will drop it": this is a tricky assertion, that would be true even if only ONE distro had 'dropped' GTK2 and at the same time it was certain that at an indeterminate future time GTK2 would be surpassed (or functionally incorporated) within GTK3/4/etc.

your statement is a bit like those advertisements we so often see reading:
"Buy Now. Up To 90% Off In-Store Today"

wow, a 90% discount, surely that is an absolute bargain?! but wait a minute, the statement could still hold true even if the store had just a single item (such as an empty paper bag) with 90% off and NO other items with more than 90% off. a rewriting of the statement is "nothing in store will be discounted by MORE than 90%" - a far less attractive proposition to lure the customer in.

likewise, your assertion that "most distro's have dropped it [GTK2] or will drop it" is equivalent to saying "eventually GTK2 will be replaced by something else, although that happening may be years (or even decades) away".

in a sane world, i could see a 'selector' helper being devised, that hooks up a GUI application at run-time with either of GTK2, GTK3/4/etc, or Qt5/6/etc, the choice being dependent on what interface the GUI application tries to access.


cheers,
rob   :-)
« Last Edit: January 21, 2026, 11:54:34 pm by robert rozee »

cdbc

  • Hero Member
  • *****
  • Posts: 2600
    • http://www.cdbc.dk
Re: Register global hotkey
« Reply #11 on: January 22, 2026, 12:24:59 am »
Hi
I just read today on our PCLinuxOS forum, that "GTK2 is still in the repo, as long as it runs -- the slightest problem and it's out, 'cause we cannot recompile it anymore."
The world might just be heading in the direction pointed out by Thaddy...
Me personally, I'm with Qt4/5/6 for a long time now, but I've recently begun exploring "fpGUI" from Graeme's github... I must say it looks very promising and I like it \o/\ö/\o/
Just my "Nickel's Worth"
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

Thaddy

  • Hero Member
  • *****
  • Posts: 18728
  • To Europe: simply sell USA bonds: dollar collapses
Re: Register global hotkey
« Reply #12 on: January 22, 2026, 06:28:54 am »
@robert rozee

Did you check the positions taken by the major distro's? I did.
GTK2 is at the most available but always marked as deprecated.

As cdbc concluded, also his favourite distro pclinux has that policy. As has Debian, Ubuntu, Fedora...
Rather naïve to ignore what the real world does. It is abandon ware.
« Last Edit: January 22, 2026, 06:32:17 am by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

zeljko

  • Hero Member
  • *****
  • Posts: 1826
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Register global hotkey
« Reply #13 on: January 25, 2026, 12:00:40 am »
@regs

Examples:
https://artixlinux.org/news.php
https://gtk.org
https://www.phoronix.com/news/RHEL-10-No-GTK2
https://lists.debian.org/debian-devel/2026/01/msg00090.html
Gtk no longer supports it themselves.
And that is the reason most distro's have dropped it or will drop it:
It is abandonware.

https://chat.deepseek.com/share/t4i8q26fsnucytwv7t for a discussion

A summary from Copilot says the same:
What this means for Lazarus / FPC developers

GTK2 is now:

- **Unmaintained upstream**
- **Being removed from major distros**
- **A security risk**
- **A packaging burden**

For Lazarus specifically, this means:

- GTK2 widgetset will become increasingly difficult to ship.
- GTK3 and Qt5/Qt6 are the only viable long‑term targets.
- Wayland‑based desktops will further complicate GTK2 use.

The latter point is already a real issue!
I am actively migrating to Qt6 with the remark that I only recently realized I was being an ostrich with my head in the ground myself. Gone are the Wayland problems.

It really isn't a good idea to develop against the gtk2 widgetset for new software.
Myself, I was also late to realize that, basically when I had to install GTK2 from Universe on Ubuntu and the notes from the Debian developers.

That's pretty correct way. Qt6 is the way to go (Qt5 does not have wayland updates anymore, so good for x11 only), but Qt6 is activelly developed for wayland. Also, yes, gtk3 supports both, yet unfinished, but not useable for heavy and complex apps, especially on wayland. Haven't tried gtk4 yet on wayland, and gtk4 changed api a lot, even some classes dissappeared, so really don't know if it ever will be added as ws on lazarus. Qt6 is the only ws on linux which will keep lazarus alive on linux in coming years. Check gtk2 in 5 yrs, even gtk3 won't be in new distros at that time.

 

TinyPortal © 2005-2018