GJS freezes, program stops responding, error states Gtk4 EventController GestureClick returns incorrect state- Gdk.ModifierType on mouse button press in X11
System information
Ubuntu 22.04, Fedora 36, Rolling Archlinux updated to latest.
What is your version of GJS? 1.72.2 on ArchLinux 1.72.0 on Ubuntu 22.04 1.72.2 on Fedora 36
If the bug is related to GNOME Shell, what is your version of GNOME Shell? 42.2 or 42.4
Bug information
Steps to reproduce
Set up an event controller gesture click to detect mouse button 1 press On button press query the event for state GJS stalls and the program stops working. The program just freezes, other than the error message below, no crash. I just have to terminate the program.
ONLY happens on X11 with the above distributions. Works perfectly on Wayland. Works on X11 on Manjaro.
#!/usr/bin/env gjs
imports.gi.versions.Gtk = "4.0";
const { Gio, Gtk } = imports.gi;
class ImageViewerWindow {
constructor(app) {
this._app = app;
this._window = null;
}
_buildUI() {
this._window = new Gtk.ApplicationWindow({
application: this._app,
defaultHeight: 600,
defaultWidth: 800
});
this._buttonClick = Gtk.GestureClick.new();
this._buttonClick.set_button(0);
this._buttonClick.set_propagation_phase(Gtk.PropagationPhase.BUBBLE);
this._window.add_controller(this._buttonClick);
this._buttonClick.connect('pressed', (actor, n_press, x, y) => {
let button = actor.get_current_button();
let state = this._buttonClick.get_current_event().get_modifier_state();
let anotherstate = this._buttonClick.get_current_event_state();
log(state);
log(anotherstate);
});
}
getWidget() {
this._buildUI();
return this._window;
}
}
const application = new Gtk.Application({
application_id: 'org.gnome.Sandbox.MenuExample',
flags: Gio.ApplicationFlags.FLAGS_NONE
});
application.connect('activate', app => {
let activeWindow = app.activeWindow;
if (!activeWindow) {
let imageViewerWindow = new ImageViewerWindow(app);
activeWindow = imageViewerWindow.getWidget();
}
activeWindow.present();
});
application.run(null);
Current behaviour
Program just stops responding and freezes, application has to be killed.
(gjs:5520): Gjs-CRITICAL **: 17:43:42.235: JS ERROR: Error: 0x10 is not a valid value for flags GdkModifierType
It seems a Hex number is returned on X11 instead of an Integer denoting the number.
In Wayland, the calls return 0x00 if no modifier key is pressed; 0x01 if SHIFT key is pressed; 0x04 if CTRL key is pressed, and 0x08 if ALT key is pressed.
It seems bit 4 is set on X11 making it an invalid value.
Is this a problem with GJS introspection?
This was also posted on discourse.gnome.org here with no clear resolution.
Expected behaviour
Should work and report the correct Gdk.ModifierState in X11 just like it does on Wayland.