zealdocs / zeal

Offline documentation browser inspired by Dash
https://zealdocs.org
GNU General Public License v3.0
11.51k stars 782 forks source link

Global hotkey is bugged on Kubuntu #308

Open g3ar opened 9 years ago

g3ar commented 9 years ago

I have a little feature request here. Right now zeal have only "Show Zeal" hotkey. It would be nice to have "Hide Zeal" to hide it or "Toggle Zeal" to switch Show/Hide states. Thanks.

trollixx commented 9 years ago

Actually it is Show/Hide hot key. So you can use it to toggle Zeal windows visibility. I guess the current label is not very clear.

g3ar commented 9 years ago

I'm using Kubuntu 14.04. It's shows by hotkey but doesn't hide.

trollixx commented 9 years ago

I've just tried Zeal on Kubuntu 14.04.2 and the global hotkey support is really broken there. I'll try to investigate the issue, but it's not my exact area of competence. Perhaps, we could make use of KGlobalAccel on Linux.

andrecbarros commented 9 years ago

I know that you deprecated "-q" option on command line, may I ask you to hold back on it ?

Besides that I use and like it, it is also a "fast fix" to the problem of global hotkey, as all modern OS allows us to bind keys to actions. On my case, I did bind "Ctrl+Alt+Space" to zeal -q "" and patched zeal with the code down below.

Minimize is not really a problem as it is also possible to bind a key sequence to minimize applications independently of which one, what seems to me a more rational behavior.

Thank you for this great application, love it.

Regards André

-- src/main.cpp.orig    2015-03-30 07:13:26.000000000 -0300
+++ src/main.cpp    2015-05-03 11:50:50.708268946 -0300
@@ -190,9 +190,11 @@
         socket->connectToServer(Zeal::Core::Application::localServerName());

         if (socket->waitForConnected(500)) {
-            QDataStream out(socket.data());
-            out << clParams.query;
+            if (! clParams.query.isEmpty ()) {
+                QDataStream out(socket.data());
+                out << clParams.query;
+            }
             socket->flush();
             return 0;
         }
     }
trollixx commented 9 years ago

@andrecbarros You can simply do zeal <term> instead of zeal -q <term>, there's no difference in how these two cases are handled by Zeal.

Could you elaborate on your patch? I am not sure why you need it.

Unfortunately, global hot keys are more or less bugged on all X11 platforms. Our XCB code has a problem, but I have no idea where exactly yet.

andrecbarros commented 9 years ago

You are right, it is not really needed.

Again, thank you for this great app.

Best regards, André

trollixx commented 9 years ago

@g3ar I've tried again to build 0.1 branch on Kubuntu 14.04 and it worked fine for me. There's still a rare XCB related issue when Zeal window does not disappear sometimes, but it's not Kubuntu specific. Could you please check if it works for you now?

trollixx commented 9 years ago

Further investigation has showed, that the problem comes from the way XCB handles grabbed keys. Unfortunately, pressing a grabbed key sequence takes keyboard focus from the Zeal main window, and quickly returns it back. As the result sequential deactivation and activation events are triggered. And then we catch XCB keypress event either after window becomes active (in most cases) or in between those two events, when our window technically is not active. The probability if either situation depends on many factors, like user's desktop environment, current system load, etc. For example, it's really hard to reproduce the issue on AwesomeWM, but it occurs 9 times out of 10 on Kubuntu, and maybe 5 out of 10 on Unity.

I don't see an easy workaround for this issue, and I am considering changing the whole workflow for the 0.2 release. #153 suggests one of the possible solutions, so the global hot key would be used only to show Zeal.

jahd2602 commented 9 years ago

Confirmed on Linux Mint 17 KDE Qiana (based on Ubuntu 14.04.1 LTS, Trusty Tahr)