-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Sonny Piers <[email protected]>
- Loading branch information
1 parent
92dcc5f
commit 9a621df
Showing
5 changed files
with
148 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using Gtk 4.0; | ||
using Adw 1; | ||
|
||
Adw.StatusPage { | ||
title: _("Gamepad"); | ||
description: _("Respond to gamepads and controllers input"); | ||
icon-name: "gamepad-symbolic"; | ||
|
||
Box { | ||
orientation: vertical; | ||
halign: center; | ||
spacing: 24; | ||
|
||
Stack stack { | ||
Label { | ||
label: _("Press Run"); | ||
|
||
styles [ | ||
"title-2" | ||
] | ||
} | ||
|
||
StackPage { | ||
name: "connect"; | ||
|
||
child: Label { | ||
label: _("Please connect a controller"); | ||
|
||
styles [ | ||
"title-2" | ||
] | ||
}; | ||
} | ||
|
||
StackPage { | ||
name: "watch"; | ||
|
||
child: Box { | ||
orientation: vertical; | ||
spacing: 6; | ||
|
||
Label { | ||
label: _("Press buttons on the controller and watch the Console"); | ||
|
||
styles [ | ||
"title-2" | ||
] | ||
} | ||
|
||
Button button_rumble { | ||
label: _("Rumble"); | ||
halign: center; | ||
} | ||
}; | ||
} | ||
} | ||
|
||
LinkButton { | ||
label: _("API Reference"); | ||
uri: "https://gnome.pages.gitlab.gnome.org/libmanette/"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import Manette from "gi://Manette"; | ||
|
||
const stack = workbench.builder.get_object("stack"); | ||
const button_rumble = workbench.builder.get_object("button_rumble"); | ||
|
||
const devices = new Set(); | ||
|
||
stack.visible_child_name = "connect"; | ||
button_rumble.connect("clicked", () => { | ||
for (const device of devices) { | ||
if (device.has_rumble()) { | ||
device.rumble(1000, 1500, 200); | ||
} | ||
} | ||
}); | ||
|
||
function onDevice(device) { | ||
console.log("Device connected:", device.get_name()); | ||
|
||
// Face and Shoulder Buttons | ||
device.connect("button-press-event", (device, event) => { | ||
const [success, button] = event.get_button(); | ||
console.log( | ||
`${device.get_name()}: press ${success ? button : event.get_hardware_code()}`, | ||
); | ||
}); | ||
|
||
// Face and Shoulder Buttons | ||
device.connect("button-release-event", (device, event) => { | ||
const [success, button] = event.get_button(); | ||
console.log( | ||
`${device.get_name()}: release ${success ? button : event.get_hardware_code()}`, | ||
); | ||
}); | ||
|
||
// D-pads | ||
device.connect("hat-axis-event", (device, event) => { | ||
const [, hat_axis, hat_value] = event.get_hat(); | ||
console.log(`${device.get_name()}: moved axis ${hat_axis} to ${hat_value}`); | ||
}); | ||
|
||
// Analog Axis - Triggers and Joysticks | ||
device.connect("absolute-axis-event", (device, event) => { | ||
const [, axis, value] = event.get_absolute(); | ||
if (Math.abs(value) > 0.2) | ||
console.log(`${device.get_name()}: moved axis ${axis} to ${value}`); | ||
}); | ||
|
||
devices.add(device); | ||
stack.visible_child_name = "watch"; | ||
} | ||
|
||
function onDeviceDisconnected(device) { | ||
console.log("Device Disconnected:", device.get_name()); | ||
|
||
devices.delete(device); | ||
stack.visible_child_name = devices.size < 1 ? "connect" : "watch"; | ||
} | ||
|
||
const monitor = new Manette.Monitor(); | ||
const monitor_iter = monitor.iterate(); | ||
|
||
let has_next; | ||
let device; | ||
do { | ||
[has_next, device] = monitor_iter.next(); | ||
if (device !== null) onDevice(device); | ||
} while (has_next); | ||
|
||
monitor.connect("device-connected", (_self, device) => onDevice(device)); | ||
monitor.connect("device-disconnected", (_self, device) => | ||
onDeviceDisconnected(device), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "Gamepad", | ||
"category": "controls", | ||
"description": "Respond to gamepads and controllers input", | ||
"panels": ["code", "preview"], | ||
"autorun": true, | ||
"flatpak-finish-args": ["--device=input"] | ||
} |