naelstrof / maim

maim (make image) takes screenshots of your desktop. It has options to take only a region, and relies on slop to query for regions. maim is supposed to be an improved scrot.
Other
2.15k stars 78 forks source link

Occasionally quits with "cancelled by keystroke or right-click" even with no keystroke or right click #247

Closed amagee closed 2 years ago

amagee commented 2 years ago

If I run maim -s > out.png, about half the time it will exit immediately with output

Failed to detect a compositor, OpenGL hardware-acceleration disabled...
Selection was cancelled by keystroke or right-click.

even though I didn't make any keystrokes or touch the mouse. Other times it works fine.

This is on Ubuntu 21.04 with i3 window manager. The problem is present both on the maim version present in the ubuntu repositories (5.6.3) and in maim built from source (5.7.4).

I am unable to reproduce the problem in Gnome, but I am unable to get keyboard cancellation to work at all in Gnome.

amagee commented 2 years ago

I had a further look into this and it seems there is no issue with the software, but actually I just have an issue with my keyboard.

I put the following print statement into slop:

diff --git a/src/keyboard.cpp b/src/keyboard.cpp
index cd91d94..1014504 100644
--- a/src/keyboard.cpp
+++ b/src/keyboard.cpp
@@ -39,6 +39,7 @@ void slop::Keyboard::update() {
     keycode = XKeysymToKeycode( x11->display, XK_space );
     keys[ keycode / 8 ] = keys[ keycode / 8 ] & ~( 1 << ( keycode % 8 ) );
     keyDown = false;
+    std::cerr << (int) keys[4] << " " << (int) deltaState[4] << "\n";
     for ( int i=0;i<32;i++ ) {
         if ( deltaState[i] == keys[i] ) {
             continue;

When it behaves properly, I see output like

16 16
16 16
16 16
16 16
0 16
0 0
0 0
... zeroes forever

as expected.

When it exits immediately, I instead see this

16 16
16 16
0 16
0 0
16 0

which as far as I understand, means that the keyboard is actually sending another Enter keypress to the system.

To verify this I tried on a different keyboard and was unable to reproduce.

foxpy commented 2 years ago

I am unable to reproduce the problem in Gnome, but I am unable to get keyboard cancellation to work at all in Gnome.

This sounds like another issue waiting for our attention, don't you think so?

amagee commented 2 years ago

Yes I guess you're right. I forgot about it since I don't actually use Gnome, I just started it to help diagnose this issue.

Let me know if there's any more useful info I can provide that would help with the Gnome issue.

foxpy commented 2 years ago

I don't actually use Gnome

I don't use it, too :D

Let me know if there's any more useful info I can provide

To be honest I can't think of anything. You can try debugging with the same approach you took, if you have some free time for that of course.

foxpy commented 2 years ago

Actually, there is one important question. Does gnome use wayland session on your installation? maim is not supposed to work under wayland.

amagee commented 2 years ago

Ok yeah so it turns out my Gnome setup does use Wayland, so if that's not supported there's not really anything more to worry about here.

It seems like XQueryKeymap just returns all zeros when used in Wayland.

foxpy commented 2 years ago

=)