garrigue / lablgtk

LablGTK 2 and 3: an interface to the GIMP Tool Kit
https://garrigue.github.io/lablgtk
Other
89 stars 40 forks source link

GdkEvent.Key.state always indicates MOD2 #172

Open ildar opened 8 months ago

ildar commented 8 months ago

I'm using lablgtk with GTK+2 on X11.

I've modified events.ml example and it shows that every key_press event's state has `MOD2.

I've checked with xkbwatch and it shows that mod2 is off as expected.

How I help with debugging that?

Thanks in advance.

garrigue commented 8 months ago

That's quite mysterious. I tried doing the same kind of experiment on MacOS, but MOD2 (which is mapped to the command key) only appears when it is pressed. This may be a Gtk issue.

ildar commented 8 months ago

Well, running this:

(**************************************************************************) (* Lablgtk - Examples *) (* *) (* This code is in the public domain. *) (* You may freely copy parts of it in your application. *) (* *) (**************************************************************************) (* $Id$ *) (* This is a direct translation to Gtk2. This is actually meaningless, as the new text widget lets you obtain an iterator from coordinates, but this just demonstrates the use of [#event#send]. *) (* Old comment by Benjamin: I cannot translate this program directly to Gtk 2. The event generation causes segfault and starts some drag-n-drop op. The default signal for left button has probably changed.*) (* I don't see segfaults, just Gtk-criticals. Seems the default handler for button 3 is still called, and I see no way to disable that. But this is not really relevant to [#event#send]. *) let string_of_event x = match GdkEvent.get_type x with | `NOTHING -> "nothing" | `DELETE -> "delete" | `DESTROY -> "destroy" | `EXPOSE -> "expose" | `MOTION_NOTIFY -> "motion-notify" | `BUTTON_PRESS -> "button-press" | `TWO_BUTTON_PRESS -> "2 button-press" | `THREE_BUTTON_PRESS -> "3 button-press" | `BUTTON_RELEASE -> "button-release" | `KEY_PRESS -> "key-press" | `KEY_RELEASE -> "key-release" | `ENTER_NOTIFY -> "enter-notfiy" | `LEAVE_NOTIFY -> "leave-notify" | `FOCUS_CHANGE -> "focus-change" | `CONFIGURE -> "configure" | `MAP -> "map" | `UNMAP -> "unmap" | `PROPERTY_NOTIFY -> "property-notify" | `SELECTION_CLEAR -> "selection-clear" | `SELECTION_REQUEST -> "selection-request" | `SELECTION_NOTIFY -> "selection-notify" | `PROXIMITY_IN -> "proximity-in" | `PROXIMITY_OUT -> "proximiy-out" | `DRAG_ENTER -> "drag-enter" | `DRAG_LEAVE -> "drag-leave" | `DRAG_MOTION -> "drag-motion" | `DRAG_STATUS -> "drag-status" | `DROP_START -> "drop-start" | `DROP_FINISHED -> "drop-finish" | `CLIENT_EVENT -> "client-event" | `VISIBILITY_NOTIFY -> "visibility-notify" | `NO_EXPOSE-> "no-expose" | `SCROLL -> "scroll" | `WINDOW_STATE -> "window-state" | `SETTING -> "setting" | `OWNER_CHANGE -> "owner-change" | `GRAB_BROKEN -> "grab-broken" | `DAMAGE -> "damage" | `TOUCH_BEGIN -> "touch-begin" | `TOUCH_UPDATE -> "touch-update" | `TOUCH_END -> "touch-end" | `TOUCH_CANCEL -> "touch-cancel" | `TOUCHPAD_SWIPE -> "touchpad-swipe" | `TOUCHPAD_PINCH -> "touchpad-pinch" let rec string_of_event_key_state_list l = match l with | [] -> "[]" | [ `BUTTON1 ] -> "`BUTTON1" | [ `BUTTON2 ] -> "`BUTTON2" | [ `BUTTON3 ] -> "`BUTTON3" | [ `BUTTON4 ] -> "`BUTTON4" | [ `BUTTON5 ] -> "`BUTTON5" | [ `CONTROL ] -> "`CONTROL" | [ `HYPER ] -> "`HYPER" | [ `LOCK ] -> "`LOCK" | [ `META ] -> "`META" | [ `MOD1 ] -> "`MOD1" | [ `MOD2 ] -> "`MOD2" | [ `MOD3 ] -> "`MOD3" | [ `MOD4 ] -> "`MOD4" | [ `MOD5 ] -> "`MOD5" | [ `RELEASE ] -> "`RELEASE" | [ `SHIFT ] -> "`SHIFT" | [ `SUPER ] -> "`SUPER" | hd::tl -> String.concat (string_of_event_key_state_list [ hd ]) [string_of_event_key_state_list tl] let _ = GMain.init (); let window = GWindow.window ~width:200 ~height:200 () in window#connect#destroy ~callback:GMain.quit ; window#event#add [`ALL_EVENTS]; window#event#connect#key_press (fun x -> prerr_string ">> before "; prerr_endline (string_of_event x); prerr_endline (string_of_event_key_state_list @@ GdkEvent.Key.state x); false); let text = GText.view ~packing:window#add () in let buffer = text#buffer in text#event#connect#button_press ~callback: begin fun ev -> GdkEvent.Button.button ev = 3 && GdkEvent.get_type ev = `BUTTON_PRESS && begin let pos = buffer#get_iter_at_mark `INSERT in GdkEvent.Button.set_button ev 1; text#event#send (ev :> GdkEvent.any); Printf.printf "Position is %d.\n" pos#offset; flush stdout; buffer#move_mark `INSERT ~where:pos; GtkSignal.stop_emit (); true end end; window#show (); GMain.main ()

I see this:

> before key-press
`MOD2
> before key-press
`MOD2
ildar commented 8 months ago

I couldn't find the original C GTK code to check.

garrigue commented 8 months ago

I tried your code, and only the correct modifiers appear. So this looks like a problem in the version of gtk you are using.