1
+ import Gtk from "gi://Gtk?version=4.0" ;
1
2
import Manette from "gi://Manette" ;
2
3
3
- const stack = workbench . builder . get_object ( "stack" ) ;
4
+ const stack = workbench . builder . get_object < Gtk . Stack > ( "stack" ) ;
4
5
const button_rumble = workbench . builder . get_object ( "button_rumble" ) ;
5
6
6
- const devices = new Set ( ) ;
7
+ const devices = new Set < Manette . Device > ( ) ;
7
8
8
9
stack . visible_child_name = "connect" ;
9
10
button_rumble . connect ( "clicked" , ( ) => {
@@ -14,22 +15,26 @@ button_rumble.connect("clicked", () => {
14
15
}
15
16
} ) ;
16
17
17
- function onDevice ( device ) {
18
+ function onDevice ( device : Manette . Device ) {
18
19
console . log ( "Device connected:" , device . get_name ( ) ) ;
19
20
20
21
// Face and Shoulder Buttons
21
22
device . connect ( "button-press-event" , ( device , event ) => {
22
23
const [ success , button ] = event . get_button ( ) ;
23
24
console . log (
24
- `${ device . get_name ( ) } : press ${ success ? button : event . get_hardware_code ( ) } ` ,
25
+ `${ device . get_name ( ) } : press ${
26
+ success ? button : event . get_hardware_code ( )
27
+ } `,
25
28
) ;
26
29
} ) ;
27
30
28
31
// Face and Shoulder Buttons
29
32
device . connect ( "button-release-event" , ( device , event ) => {
30
33
const [ success , button ] = event . get_button ( ) ;
31
34
console . log (
32
- `${ device . get_name ( ) } : release ${ success ? button : event . get_hardware_code ( ) } ` ,
35
+ `${ device . get_name ( ) } : release ${
36
+ success ? button : event . get_hardware_code ( )
37
+ } `,
33
38
) ;
34
39
} ) ;
35
40
@@ -42,8 +47,9 @@ function onDevice(device) {
42
47
// Analog Axis - Triggers and Joysticks
43
48
device . connect ( "absolute-axis-event" , ( device , event ) => {
44
49
const [ , axis , value ] = event . get_absolute ( ) ;
45
- if ( Math . abs ( value ) > 0.2 )
50
+ if ( Math . abs ( value ) > 0.2 ) {
46
51
console . log ( `${ device . get_name ( ) } : moved axis ${ axis } to ${ value } ` ) ;
52
+ }
47
53
} ) ;
48
54
49
55
devices . add ( device ) ;
@@ -60,14 +66,14 @@ function onDeviceDisconnected(device) {
60
66
const monitor = new Manette . Monitor ( ) ;
61
67
const monitor_iter = monitor . iterate ( ) ;
62
68
63
- let has_next ;
64
- let device ;
69
+ let has_next : boolean , device : Manette . Device | null ;
65
70
do {
66
71
[ has_next , device ] = monitor_iter . next ( ) ;
67
72
if ( device !== null ) onDevice ( device ) ;
68
73
} while ( has_next ) ;
69
74
70
75
monitor . connect ( "device-connected" , ( _self , device ) => onDevice ( device ) ) ;
71
- monitor . connect ( "device-disconnected" , ( _self , device ) =>
72
- onDeviceDisconnected ( device ) ,
76
+ monitor . connect (
77
+ "device-disconnected" ,
78
+ ( _self , device ) => onDeviceDisconnected ( device ) ,
73
79
) ;
0 commit comments