// Receives keyboard events until a valid shortcut is found, to set it as entry text. // func onKeyGrabReceived(_ *gtk.Window, event *gdk.Event, data *textGrabData) { key := &gdk.EventKey{Event: event} if !gtk.AcceleratorValid(key.KeyVal(), gdk.ModifierType(key.State())) { return } data.entry.SetSensitive(true) data.win.HandlerDisconnect(data.cbID) data.cbID = 0 // This lets us ignore all ignorable modifier keys, including NumLock and many others. :) // The logic is: keep only the important modifiers that were pressed for this event. state := gdk.ModifierType(key.State()) & gtk.AcceleratorGetDefaultModMask() accel := gtk.AcceleratorName(key.KeyVal(), state) data.entry.SetText(accel) }
// onKeyGrabReceived is called when a grabbed keyboard events is received. // func (widget *Shortkeys) onKeyGrabReceived(win *gtk.Window, event *gdk.Event) { key := &gdk.EventKey{Event: event} if !gtk.AcceleratorValid(key.KeyVal(), gdk.ModifierType(key.State())) { return } // This lets us ignore all ignorable modifier keys, including NumLock and many others. :) // The logic is: keep only the important modifiers that were pressed for this event. state := gdk.ModifierType(key.State()) & gtk.AcceleratorGetDefaultModMask() accel := gtk.AcceleratorName(key.KeyVal(), state) if accel != "Escape" { // TODO: FIX widget.updateShortkey(accel) } else { widget.updateDisplay() } widget.onKeyGrabFinish() }