1package gui
2
3import "github.com/coyim/gotk3adapter/gdki"
4
5// shift, control, super, hyper, meta,
6
7func hasState(evk gdki.EventKey, s gdki.ModifierType) bool {
8	return evk.State()&uint(s) != 0
9}
10
11func hasShift(evk gdki.EventKey) bool {
12	return hasState(evk, gdki.GDK_SHIFT_MASK)
13}
14
15// Used to indicate scroll lock or caps lock
16func hasLock(evk gdki.EventKey) bool {
17	return hasState(evk, gdki.GDK_LOCK_MASK)
18}
19
20func hasControl(evk gdki.EventKey) bool {
21	return hasState(evk, gdki.GDK_CONTROL_MASK)
22}
23
24func hasSuper(evk gdki.EventKey) bool {
25	return hasState(evk, gdki.GDK_SUPER_MASK)
26}
27
28func hasHyper(evk gdki.EventKey) bool {
29	return hasState(evk, gdki.GDK_HYPER_MASK)
30}
31
32func hasMeta(evk gdki.EventKey) bool {
33	return hasState(evk, gdki.GDK_META_MASK)
34}
35
36func hasControlingModifier(evk gdki.EventKey) bool {
37	return hasShift(evk) ||
38		hasControl(evk) ||
39		hasSuper(evk) ||
40		hasHyper(evk) ||
41		hasMeta(evk)
42}
43
44func hasEnter(evk gdki.EventKey) bool {
45	return evk.KeyVal() == gdki.KEY_Return ||
46		evk.KeyVal() == gdki.KEY_KP_Enter
47}
48
49func isShiftEnter(evk gdki.EventKey) bool {
50	return hasShift(evk) && hasEnter(evk)
51}
52
53func isNormalEnter(evk gdki.EventKey) bool {
54	return !hasControlingModifier(evk) && hasEnter(evk)
55}
56
57func isInsertEnter(evk gdki.EventKey, shiftEnterSends bool) bool {
58	if shiftEnterSends {
59		return isNormalEnter(evk)
60	}
61	return isShiftEnter(evk)
62}
63
64func isSend(evk gdki.EventKey, shiftEnterSends bool) bool {
65	if !shiftEnterSends {
66		return isNormalEnter(evk)
67	}
68	return isShiftEnter(evk)
69}
70