From 1802fc02267818a38104b0d00dd15d4d330f1e3b Mon Sep 17 00:00:00 2001 From: halfmexican Date: Mon, 5 Jun 2023 11:20:30 -0500 Subject: [PATCH 01/17] add main.json --- src/Library/demos/Gamepads/main.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/Library/demos/Gamepads/main.json diff --git a/src/Library/demos/Gamepads/main.json b/src/Library/demos/Gamepads/main.json new file mode 100644 index 000000000..4c79bc75b --- /dev/null +++ b/src/Library/demos/Gamepads/main.json @@ -0,0 +1,7 @@ +{ + "name": "Gamepads", + "category": "controls", + "description": "Libmanette provides access to video game controllers", + "panels": ["Code", "preview"], + "autorun": true +} From 737a71b74a25d8c219436f56ff9c6eb36bbd25f1 Mon Sep 17 00:00:00 2001 From: halfmexican Date: Mon, 5 Jun 2023 11:20:40 -0500 Subject: [PATCH 02/17] add main.js --- src/Library/demos/Gamepads/main.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/Library/demos/Gamepads/main.js diff --git a/src/Library/demos/Gamepads/main.js b/src/Library/demos/Gamepads/main.js new file mode 100644 index 000000000..bfebebbc6 --- /dev/null +++ b/src/Library/demos/Gamepads/main.js @@ -0,0 +1,12 @@ +import Gtk from "gi://Gtk"; +import Manette from "gi://Manette"; + +const monitor = Manette.Monitor.new(); + +monitor.connect("device-connected", (monitor, connected_device) => { + console.log(connected_device.get_name()); +}); + +monitor.connect("device-disconnected", (monitor, disconnected_device) => { + console.log(disconnected_device.get_name()); +}); From 800f651941a3da00ffa8d1c3c3e6825171817259 Mon Sep 17 00:00:00 2001 From: halfmexican Date: Mon, 5 Jun 2023 11:20:50 -0500 Subject: [PATCH 03/17] add main.blp --- src/Library/demos/Gamepads/main.blp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/Library/demos/Gamepads/main.blp diff --git a/src/Library/demos/Gamepads/main.blp b/src/Library/demos/Gamepads/main.blp new file mode 100644 index 000000000..9fb6e62d2 --- /dev/null +++ b/src/Library/demos/Gamepads/main.blp @@ -0,0 +1,19 @@ +using Gtk 4.0; +using Adw 1; + +Adw.StatusPage { + title: _("Gamepads"); + description: _("A controller is needed for this demo"); + icon-name: "gamepad-symbolic"; + + Box { + orientation: vertical; + + LinkButton { + label: "API Reference"; + uri: ""; + margin-top: 24; + } + } +} + From 0f2aee0ae9ae4b7cabca76553131f656d0071797 Mon Sep 17 00:00:00 2001 From: halfmexican Date: Mon, 5 Jun 2023 12:40:27 -0500 Subject: [PATCH 04/17] attempt to iterate over devices --- src/Library/demos/Gamepads/main.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Library/demos/Gamepads/main.js b/src/Library/demos/Gamepads/main.js index bfebebbc6..597a664aa 100644 --- a/src/Library/demos/Gamepads/main.js +++ b/src/Library/demos/Gamepads/main.js @@ -3,10 +3,19 @@ import Manette from "gi://Manette"; const monitor = Manette.Monitor.new(); -monitor.connect("device-connected", (monitor, connected_device) => { - console.log(connected_device.get_name()); +monitor.connect("device-connected", (monitor, device) => { + console.log("A new device is connected:", device); }); -monitor.connect("device-disconnected", (monitor, disconnected_device) => { - console.log(disconnected_device.get_name()); +monitor.connect("device-disconnected", (monitor, device) => { + console.log("A device is disconnected:", device); }); + +const monitorIter = monitor.iterate(); + +// Iterate over the devices and log their details +let [has_next, device] = monitorIter.next(); +while (device !== null) { + console.log("Device:", device); + [has_next, device] = monitorIter.next(); +} From 993c26b6ddbefa9cfbf065ef7e9118f87a5e0822 Mon Sep 17 00:00:00 2001 From: halfmexican Date: Mon, 5 Jun 2023 12:40:46 -0500 Subject: [PATCH 05/17] fix typo in main.json --- src/Library/demos/Gamepads/main.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Library/demos/Gamepads/main.json b/src/Library/demos/Gamepads/main.json index 4c79bc75b..b34affa7d 100644 --- a/src/Library/demos/Gamepads/main.json +++ b/src/Library/demos/Gamepads/main.json @@ -2,6 +2,6 @@ "name": "Gamepads", "category": "controls", "description": "Libmanette provides access to video game controllers", - "panels": ["Code", "preview"], + "panels": ["code", "preview"], "autorun": true } From 8eea5827d457da59a031cc79678da9c4e9269bfe Mon Sep 17 00:00:00 2001 From: halfmexican Date: Tue, 6 Jun 2023 14:00:28 -0500 Subject: [PATCH 06/17] use template literal --- src/Library/demos/Gamepads/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Library/demos/Gamepads/main.js b/src/Library/demos/Gamepads/main.js index 597a664aa..4d204ac8b 100644 --- a/src/Library/demos/Gamepads/main.js +++ b/src/Library/demos/Gamepads/main.js @@ -4,11 +4,11 @@ import Manette from "gi://Manette"; const monitor = Manette.Monitor.new(); monitor.connect("device-connected", (monitor, device) => { - console.log("A new device is connected:", device); + console.log("Device added: " + device.get_name()); }); monitor.connect("device-disconnected", (monitor, device) => { - console.log("A device is disconnected:", device); + console.log("Device removed: " + device.get_name()); }); const monitorIter = monitor.iterate(); From d07a8c410943d76d329c3ab674944e6997695ac4 Mon Sep 17 00:00:00 2001 From: halfmexican Date: Tue, 6 Jun 2023 14:00:53 -0500 Subject: [PATCH 07/17] use template literal --- src/Library/demos/Gamepads/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Library/demos/Gamepads/main.js b/src/Library/demos/Gamepads/main.js index 4d204ac8b..59535f289 100644 --- a/src/Library/demos/Gamepads/main.js +++ b/src/Library/demos/Gamepads/main.js @@ -4,11 +4,11 @@ import Manette from "gi://Manette"; const monitor = Manette.Monitor.new(); monitor.connect("device-connected", (monitor, device) => { - console.log("Device added: " + device.get_name()); + console.log(`Device added: ${device.get_name()}`); }); monitor.connect("device-disconnected", (monitor, device) => { - console.log("Device removed: " + device.get_name()); + console.log(`Device removed: ${device.get_name()}`); }); const monitorIter = monitor.iterate(); From 9c2472baf7fc9ff5a3d813e8e8c738bd62df59c0 Mon Sep 17 00:00:00 2001 From: halfmexican Date: Wed, 7 Jun 2023 13:06:50 -0500 Subject: [PATCH 08/17] add note and button --- src/Library/demos/Gamepads/main.blp | 7 +++++++ src/Library/demos/Gamepads/main.js | 23 ++++++++++------------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/Library/demos/Gamepads/main.blp b/src/Library/demos/Gamepads/main.blp index 9fb6e62d2..990fe3e0a 100644 --- a/src/Library/demos/Gamepads/main.blp +++ b/src/Library/demos/Gamepads/main.blp @@ -8,6 +8,13 @@ Adw.StatusPage { Box { orientation: vertical; + halign: center; + + Button continue_button { + styles ["pill"] + label: _("Continue"); + sensitive: false; + } LinkButton { label: "API Reference"; diff --git a/src/Library/demos/Gamepads/main.js b/src/Library/demos/Gamepads/main.js index 59535f289..add2ab4e0 100644 --- a/src/Library/demos/Gamepads/main.js +++ b/src/Library/demos/Gamepads/main.js @@ -1,21 +1,18 @@ +/*To use USB devices in your app you will need to set the --device=all permission. + Workbench doesn't have such permission by default so to run this example you have to */ import Gtk from "gi://Gtk"; import Manette from "gi://Manette"; +const continue_button = workbench.builder.get_object("continue_button"); const monitor = Manette.Monitor.new(); - -monitor.connect("device-connected", (monitor, device) => { - console.log(`Device added: ${device.get_name()}`); -}); - -monitor.connect("device-disconnected", (monitor, device) => { - console.log(`Device removed: ${device.get_name()}`); -}); - -const monitorIter = monitor.iterate(); +const monitor_iter = monitor.iterate(); // Iterate over the devices and log their details -let [has_next, device] = monitorIter.next(); +let [has_next, device] = monitor_iter.next(); while (device !== null) { - console.log("Device:", device); - [has_next, device] = monitorIter.next(); + console.log("Device:", device.get_name()); + [has_next, device] = monitor_iter.next(); + + continue_button.sensitive = true; + continue_button.add_css_class("suggested-action"); } From 1368d4730848de11fc69e723d80c025623b227e7 Mon Sep 17 00:00:00 2001 From: halfmexican Date: Thu, 8 Jun 2023 13:59:40 -0500 Subject: [PATCH 09/17] update main.blp --- src/Library/demos/Gamepads/main.blp | 36 +++++++++++++++-------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/Library/demos/Gamepads/main.blp b/src/Library/demos/Gamepads/main.blp index 990fe3e0a..8e2ce39fe 100644 --- a/src/Library/demos/Gamepads/main.blp +++ b/src/Library/demos/Gamepads/main.blp @@ -1,26 +1,28 @@ using Gtk 4.0; using Adw 1; -Adw.StatusPage { - title: _("Gamepads"); - description: _("A controller is needed for this demo"); - icon-name: "gamepad-symbolic"; +Stack stack { + visible-child: status_page; - Box { - orientation: vertical; - halign: center; + Adw.StatusPage status_page { + title: _("Please connect a gamepad"); + description: _("A controller is needed for this demo"); + icon-name: "gamepad-symbolic"; - Button continue_button { - styles ["pill"] - label: _("Continue"); - sensitive: false; - } + Box { + orientation: vertical; + halign: center; + + Gtk.Image indicator { + styles ["pill"] + icon-name: "sentiment-dissatisfied-symbolic"; + } - LinkButton { - label: "API Reference"; - uri: ""; - margin-top: 24; + LinkButton { + label: "API Reference"; + uri: ""; + margin-top: 24; + } } } } - From 7d7b70493317316d493705f0fc3ca15b63c7d9e7 Mon Sep 17 00:00:00 2001 From: halfmexican Date: Thu, 8 Jun 2023 13:59:58 -0500 Subject: [PATCH 10/17] add facebutton and d-pad support --- src/Library/demos/Gamepads/main.js | 31 +++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/Library/demos/Gamepads/main.js b/src/Library/demos/Gamepads/main.js index add2ab4e0..1aab02e03 100644 --- a/src/Library/demos/Gamepads/main.js +++ b/src/Library/demos/Gamepads/main.js @@ -1,18 +1,39 @@ /*To use USB devices in your app you will need to set the --device=all permission. - Workbench doesn't have such permission by default so to run this example you have to */ + Workbench doesn't have such permission by default so to run this example you have to run the command + flatpak override re.sonny.Workbench --device=all */ + import Gtk from "gi://Gtk"; import Manette from "gi://Manette"; -const continue_button = workbench.builder.get_object("continue_button"); +const status_page = workbench.builder.get_object("status_page"); + const monitor = Manette.Monitor.new(); const monitor_iter = monitor.iterate(); // Iterate over the devices and log their details let [has_next, device] = monitor_iter.next(); + while (device !== null) { console.log("Device:", device.get_name()); - [has_next, device] = monitor_iter.next(); - continue_button.sensitive = true; - continue_button.add_css_class("suggested-action"); + status_page.title = _("Controller connected"); + status_page.description = ""; + + // Face and Shoulder Buttons + device.connect("button-press-event", (device, event) => { + console.log( + `Device: ${device.get_name()} pressed ${event.get_hardware_code()}`, + ); + }); + + // D-pads + device.connect("hat-axis-event", (device, event) => { + let [, hat_axis, hat_value] = event.get_hat(); + + console.log( + `Device: ${device.get_name()} moved axis ${hat_axis} to ${hat_value}`, + ); + }); + + [has_next, device] = monitor_iter.next(); } From 3cb577eada97bb32d360c24abca53046cfbe3f67 Mon Sep 17 00:00:00 2001 From: halfmexican Date: Thu, 8 Jun 2023 14:01:26 -0500 Subject: [PATCH 11/17] add libmanette as a module in our flatpak manifest --- re.sonny.Workbench.Devel.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/re.sonny.Workbench.Devel.json b/re.sonny.Workbench.Devel.json index 45b07b1f8..fd27b806c 100644 --- a/re.sonny.Workbench.Devel.json +++ b/re.sonny.Workbench.Devel.json @@ -71,6 +71,18 @@ } ] }, + { + "name": "libmanette", + "buildsystem": "meson", + "config-opts": ["-Dgudev=disabled"], + "builddir": true, + "sources": [ + { + "type": "git", + "url": "https://gitlab.gnome.org/GNOME/libmanette.git" + } + ] + }, { "name": "vls", "buildsystem": "meson", From 271e72a50b2052c4153016e658b76f89e00775ce Mon Sep 17 00:00:00 2001 From: halfmexican Date: Thu, 8 Jun 2023 14:03:43 -0500 Subject: [PATCH 12/17] remove icon --- src/Library/demos/Gamepads/main.blp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Library/demos/Gamepads/main.blp b/src/Library/demos/Gamepads/main.blp index 8e2ce39fe..f95357dcb 100644 --- a/src/Library/demos/Gamepads/main.blp +++ b/src/Library/demos/Gamepads/main.blp @@ -13,11 +13,6 @@ Stack stack { orientation: vertical; halign: center; - Gtk.Image indicator { - styles ["pill"] - icon-name: "sentiment-dissatisfied-symbolic"; - } - LinkButton { label: "API Reference"; uri: ""; From 586c8a05268f70be1c26ad090a7d7df008823eb4 Mon Sep 17 00:00:00 2001 From: halfmexican Date: Thu, 8 Jun 2023 14:15:17 -0500 Subject: [PATCH 13/17] add analog axis support --- src/Library/demos/Gamepads/main.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Library/demos/Gamepads/main.js b/src/Library/demos/Gamepads/main.js index 1aab02e03..c10ff22a8 100644 --- a/src/Library/demos/Gamepads/main.js +++ b/src/Library/demos/Gamepads/main.js @@ -35,5 +35,14 @@ while (device !== null) { ); }); + // Analog Axis + device.connect("absolute-axis-event", (device, event) => { + let [, axis, value] = event.get_absolute(); + if (Math.abs(value) > 0.03) + console.log( + `Device: ${device.get_name()} moved axis ${axis} to ${value}`, + ); + }); + [has_next, device] = monitor_iter.next(); } From 3010e605b48c7ce0436e4bce50736c4ee0142d57 Mon Sep 17 00:00:00 2001 From: halfmexican Date: Thu, 8 Jun 2023 14:25:12 -0500 Subject: [PATCH 14/17] add link to docs --- src/Library/demos/Gamepads/main.blp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Library/demos/Gamepads/main.blp b/src/Library/demos/Gamepads/main.blp index f95357dcb..999e3674a 100644 --- a/src/Library/demos/Gamepads/main.blp +++ b/src/Library/demos/Gamepads/main.blp @@ -15,7 +15,7 @@ Stack stack { LinkButton { label: "API Reference"; - uri: ""; + uri: "https://gnome.pages.gitlab.gnome.org/libmanette/"; margin-top: 24; } } From 0f62bbed472efa3cffed94e97b5a22ffaf032f2a Mon Sep 17 00:00:00 2001 From: halfmexican Date: Thu, 8 Jun 2023 14:31:36 -0500 Subject: [PATCH 15/17] main.js: use const and update comments --- src/Library/demos/Gamepads/main.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Library/demos/Gamepads/main.js b/src/Library/demos/Gamepads/main.js index c10ff22a8..61a394b64 100644 --- a/src/Library/demos/Gamepads/main.js +++ b/src/Library/demos/Gamepads/main.js @@ -1,4 +1,4 @@ -/*To use USB devices in your app you will need to set the --device=all permission. +/* IMPORTANT: To use USB devices in your app you will need to set the --device=all permission. Workbench doesn't have such permission by default so to run this example you have to run the command flatpak override re.sonny.Workbench --device=all */ @@ -28,17 +28,16 @@ while (device !== null) { // D-pads device.connect("hat-axis-event", (device, event) => { - let [, hat_axis, hat_value] = event.get_hat(); - + const [, hat_axis, hat_value] = event.get_hat(); console.log( `Device: ${device.get_name()} moved axis ${hat_axis} to ${hat_value}`, ); }); - // Analog Axis + // Analog Axis - Triggers and Joysticks device.connect("absolute-axis-event", (device, event) => { - let [, axis, value] = event.get_absolute(); - if (Math.abs(value) > 0.03) + const [, axis, value] = event.get_absolute(); + if (Math.abs(value) > 0.2) console.log( `Device: ${device.get_name()} moved axis ${axis} to ${value}`, ); From a9eea8e55fb9c410964cc101f93d4528a4b90916 Mon Sep 17 00:00:00 2001 From: halfmexican Date: Thu, 8 Jun 2023 14:34:51 -0500 Subject: [PATCH 16/17] main.json:update description --- src/Library/demos/Gamepads/main.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Library/demos/Gamepads/main.json b/src/Library/demos/Gamepads/main.json index b34affa7d..c83d9d477 100644 --- a/src/Library/demos/Gamepads/main.json +++ b/src/Library/demos/Gamepads/main.json @@ -1,7 +1,7 @@ { "name": "Gamepads", "category": "controls", - "description": "Libmanette provides access to video game controllers", + "description": "Use Libmanette to access controllers and gamepads", "panels": ["code", "preview"], - "autorun": true + "autorun": false } From 0659daa96127a81da6dd04032f1fa578db0820b9 Mon Sep 17 00:00:00 2001 From: halfmexican Date: Thu, 8 Jun 2023 20:21:16 -0500 Subject: [PATCH 17/17] add rumble --- src/Library/demos/Gamepads/main.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Library/demos/Gamepads/main.js b/src/Library/demos/Gamepads/main.js index 61a394b64..51df3cfff 100644 --- a/src/Library/demos/Gamepads/main.js +++ b/src/Library/demos/Gamepads/main.js @@ -24,6 +24,10 @@ while (device !== null) { console.log( `Device: ${device.get_name()} pressed ${event.get_hardware_code()}`, ); + + if (device.has_rumble()) { + device.rumble(1000, 1500, 200); + } }); // D-pads