Hey folks, I'm having some trouble with the native dialogs add-on, namely the al_show_native_message_box function.
Below is a minimal example that exhibits the problem:
Steps to reproduce the problem:
1) compile and run
2) press "P" to trigger the message box
3) click yes or no -> ok, message box closes
4) now press "P" again
5) click yes or no -> message box closes and immediately reopens from this point on
I'm on Debian, using GTK 3.22 and Allegro 5.2.2, and compiling with g++ and clang++, both of which show the same behaviour.
So, the obvious question is: What am I doing wrong here?
I was able to reproduce the issue in Ubuntu 16.04.
One thing that stands out to me is that you're getting the keyboard states manually, rather than registering them via al_register_event_source().
After register keyboard events and checking for said events outside of the timer event, the issue is no longer present. Check it out:
Thanks for your input, Eric. Unfortunately I need precisely timed keyboard input in my project, and I haven't found a viable way of doing that with ALLEGRO_EVENT_KEY_DOWN/UP/CHAR yet. Is there maybe another work-around?
That aside, do you think this is a bug? If so, I'll open an issue on github, and perhaps a mod could move this thread to the Development board.
It seems to me that the keyboard state is stuck on a key being down upon showing the dialog. When I reproduce the issue with your original code and get to the point where the dialog repeats itself, if I return focus onto the window and press "P" again and then click one of the dialog buttons, the dialog closes properly.
So it seems that the keyboard state is getting stuck. I don't know if it's the result of an internal bug or whether or implementation is screwy... Go ahead and open an issue on GitHub and wait to see what others have to say.
Edit
I found a workaround. Each time you check for a key being down, but before showing the dialog, uninstall and then reinstall the keyboard. Let me know if it works for you:
Another Edit
The above can also be accomplished using al_clear_keyboard_state(), but it's currently a part of the unstable API. You have to define ALLEGRO_UNSTABLE before including the Allegro header files to use the unstable API.
Yes! That does the trick. Thanks a lot!
Was just reading up on al_clear_keyboard_state() as well, but it's only been added in 5.2.3. So I'll probably stick with the first version, since it might be a while before the new stuff finds its way into the various distros that have Allegro in their repos.
I'm glad it works for you.
Also, I wouldn't worry too much about newer versions of Allegro finding their way into various distributions, as it's not difficult to manually build Allegro from source. The gist of it is as follows:
sudo apt-get install -y libgl1-mesa-dev libglu1-mesa-dev cmake build-essential make libxcursor-dev cmake g++ freeglut3-dev libxcursor-dev libpng12-dev libjpeg-dev libfreetype6-dev libgtk2.0-dev libasound2-dev libpulse-dev libopenal-dev libflac-dev libdumb1-dev libvorbis-dev libphysfs-dev
git clone https://github.com/liballeg/allegro5
cd allegro5
mkdir build
cd build
cmake ..
make
sudo make install
sudo ldconfig