mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 09:25:38 +00:00
app/internal/window,app/internal/xkb: [Wayland] report modifiers for pointer events
Updates #120 Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -708,6 +708,7 @@ func gio_onTouchDown(data unsafe.Pointer, touch *C.struct_wl_touch, serial, t C.
|
|||||||
Position: w.lastTouch,
|
Position: w.lastTouch,
|
||||||
PointerID: pointer.ID(id),
|
PointerID: pointer.ID(id),
|
||||||
Time: time.Duration(t) * time.Millisecond,
|
Time: time.Duration(t) * time.Millisecond,
|
||||||
|
Modifiers: w.disp.xkb.Modifiers(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -723,6 +724,7 @@ func gio_onTouchUp(data unsafe.Pointer, touch *C.struct_wl_touch, serial, t C.ui
|
|||||||
Position: w.lastTouch,
|
Position: w.lastTouch,
|
||||||
PointerID: pointer.ID(id),
|
PointerID: pointer.ID(id),
|
||||||
Time: time.Duration(t) * time.Millisecond,
|
Time: time.Duration(t) * time.Millisecond,
|
||||||
|
Modifiers: w.disp.xkb.Modifiers(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -740,6 +742,7 @@ func gio_onTouchMotion(data unsafe.Pointer, touch *C.struct_wl_touch, t C.uint32
|
|||||||
Source: pointer.Touch,
|
Source: pointer.Touch,
|
||||||
PointerID: pointer.ID(id),
|
PointerID: pointer.ID(id),
|
||||||
Time: time.Duration(t) * time.Millisecond,
|
Time: time.Duration(t) * time.Millisecond,
|
||||||
|
Modifiers: w.disp.xkb.Modifiers(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -826,11 +829,12 @@ func gio_onPointerButton(data unsafe.Pointer, p *C.struct_wl_pointer, serial, t,
|
|||||||
w.flushScroll()
|
w.flushScroll()
|
||||||
w.resetFling()
|
w.resetFling()
|
||||||
w.w.Event(pointer.Event{
|
w.w.Event(pointer.Event{
|
||||||
Type: typ,
|
Type: typ,
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Buttons: w.pointerBtns,
|
Buttons: w.pointerBtns,
|
||||||
Position: w.lastPos,
|
Position: w.lastPos,
|
||||||
Time: time.Duration(t) * time.Millisecond,
|
Time: time.Duration(t) * time.Millisecond,
|
||||||
|
Modifiers: w.disp.xkb.Modifiers(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1289,12 +1293,13 @@ func (w *window) flushScroll() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.w.Event(pointer.Event{
|
w.w.Event(pointer.Event{
|
||||||
Type: pointer.Move,
|
Type: pointer.Move,
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Buttons: w.pointerBtns,
|
Buttons: w.pointerBtns,
|
||||||
Position: w.lastPos,
|
Position: w.lastPos,
|
||||||
Scroll: total,
|
Scroll: total,
|
||||||
Time: w.scroll.time,
|
Time: w.scroll.time,
|
||||||
|
Modifiers: w.disp.xkb.Modifiers(),
|
||||||
})
|
})
|
||||||
if w.scroll.steps == (image.Point{}) {
|
if w.scroll.steps == (image.Point{}) {
|
||||||
w.fling.xExtrapolation.SampleDelta(w.scroll.time, -w.scroll.dist.X)
|
w.fling.xExtrapolation.SampleDelta(w.scroll.time, -w.scroll.dist.X)
|
||||||
@@ -1311,11 +1316,12 @@ func (w *window) onPointerMotion(x, y C.wl_fixed_t, t C.uint32_t) {
|
|||||||
Y: fromFixed(y) * float32(w.scale),
|
Y: fromFixed(y) * float32(w.scale),
|
||||||
}
|
}
|
||||||
w.w.Event(pointer.Event{
|
w.w.Event(pointer.Event{
|
||||||
Type: pointer.Move,
|
Type: pointer.Move,
|
||||||
Position: w.lastPos,
|
Position: w.lastPos,
|
||||||
Buttons: w.pointerBtns,
|
Buttons: w.pointerBtns,
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
Time: time.Duration(t) * time.Millisecond,
|
Time: time.Duration(t) * time.Millisecond,
|
||||||
|
Modifiers: w.disp.xkb.Modifiers(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -133,6 +133,23 @@ func (x *Context) LoadKeymap(format int, fd int, size int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *Context) Modifiers() key.Modifiers {
|
||||||
|
var mods key.Modifiers
|
||||||
|
if C.xkb_state_mod_name_is_active(x.state, (*C.char)(unsafe.Pointer(&_XKB_MOD_NAME_CTRL[0])), C.XKB_STATE_MODS_EFFECTIVE) == 1 {
|
||||||
|
mods |= key.ModCtrl
|
||||||
|
}
|
||||||
|
if C.xkb_state_mod_name_is_active(x.state, (*C.char)(unsafe.Pointer(&_XKB_MOD_NAME_SHIFT[0])), C.XKB_STATE_MODS_EFFECTIVE) == 1 {
|
||||||
|
mods |= key.ModShift
|
||||||
|
}
|
||||||
|
if C.xkb_state_mod_name_is_active(x.state, (*C.char)(unsafe.Pointer(&_XKB_MOD_NAME_ALT[0])), C.XKB_STATE_MODS_EFFECTIVE) == 1 {
|
||||||
|
mods |= key.ModAlt
|
||||||
|
}
|
||||||
|
if C.xkb_state_mod_name_is_active(x.state, (*C.char)(unsafe.Pointer(&_XKB_MOD_NAME_LOGO[0])), C.XKB_STATE_MODS_EFFECTIVE) == 1 {
|
||||||
|
mods |= key.ModSuper
|
||||||
|
}
|
||||||
|
return mods
|
||||||
|
}
|
||||||
|
|
||||||
func (x *Context) DispatchKey(keyCode uint32) (events []event.Event) {
|
func (x *Context) DispatchKey(keyCode uint32) (events []event.Event) {
|
||||||
if x.state == nil {
|
if x.state == nil {
|
||||||
return
|
return
|
||||||
@@ -143,24 +160,15 @@ func (x *Context) DispatchKey(keyCode uint32) (events []event.Event) {
|
|||||||
}
|
}
|
||||||
sym := C.xkb_state_key_get_one_sym(x.state, kc)
|
sym := C.xkb_state_key_get_one_sym(x.state, kc)
|
||||||
if name, ok := convertKeysym(sym); ok {
|
if name, ok := convertKeysym(sym); ok {
|
||||||
cmd := key.Event{Name: name}
|
cmd := key.Event{
|
||||||
|
Name: name,
|
||||||
|
Modifiers: x.Modifiers(),
|
||||||
|
}
|
||||||
// Ensure that a physical backtab key is translated to
|
// Ensure that a physical backtab key is translated to
|
||||||
// Shift-Tab.
|
// Shift-Tab.
|
||||||
if sym == C.XKB_KEY_ISO_Left_Tab {
|
if sym == C.XKB_KEY_ISO_Left_Tab {
|
||||||
cmd.Modifiers |= key.ModShift
|
cmd.Modifiers |= key.ModShift
|
||||||
}
|
}
|
||||||
if C.xkb_state_mod_name_is_active(x.state, (*C.char)(unsafe.Pointer(&_XKB_MOD_NAME_CTRL[0])), C.XKB_STATE_MODS_EFFECTIVE) == 1 {
|
|
||||||
cmd.Modifiers |= key.ModCtrl
|
|
||||||
}
|
|
||||||
if C.xkb_state_mod_name_is_active(x.state, (*C.char)(unsafe.Pointer(&_XKB_MOD_NAME_SHIFT[0])), C.XKB_STATE_MODS_EFFECTIVE) == 1 {
|
|
||||||
cmd.Modifiers |= key.ModShift
|
|
||||||
}
|
|
||||||
if C.xkb_state_mod_name_is_active(x.state, (*C.char)(unsafe.Pointer(&_XKB_MOD_NAME_ALT[0])), C.XKB_STATE_MODS_EFFECTIVE) == 1 {
|
|
||||||
cmd.Modifiers |= key.ModAlt
|
|
||||||
}
|
|
||||||
if C.xkb_state_mod_name_is_active(x.state, (*C.char)(unsafe.Pointer(&_XKB_MOD_NAME_LOGO[0])), C.XKB_STATE_MODS_EFFECTIVE) == 1 {
|
|
||||||
cmd.Modifiers |= key.ModSuper
|
|
||||||
}
|
|
||||||
events = append(events, cmd)
|
events = append(events, cmd)
|
||||||
}
|
}
|
||||||
C.xkb_compose_state_feed(x.compState, sym)
|
C.xkb_compose_state_feed(x.compState, sym)
|
||||||
|
|||||||
Reference in New Issue
Block a user