Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

library: add Libmanette entry #309

Closed
wants to merge 17 commits into from
12 changes: 12 additions & 0 deletions re.sonny.Workbench.Devel.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@
}
]
},
{
"name": "libmanette",
"buildsystem": "meson",
"config-opts": ["-Dgudev=disabled"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the config-opts what fixed it in flatpak?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"builddir": true,
"sources": [
{
"type": "git",
"url": "https://gitlab.gnome.org/GNOME/libmanette.git"
}
]
},
{
"name": "vls",
"buildsystem": "meson",
Expand Down
23 changes: 23 additions & 0 deletions src/Library/demos/Gamepads/main.blp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Gtk 4.0;
using Adw 1;

Stack stack {
visible-child: status_page;

Adw.StatusPage status_page {
title: _("Please connect a gamepad");
description: _("A controller is needed for this demo");
icon-name: "gamepad-symbolic";

Box {
orientation: vertical;
halign: center;

LinkButton {
label: "API Reference";
uri: "https://gnome.pages.gitlab.gnome.org/libmanette/";
margin-top: 24;
}
}
}
}
51 changes: 51 additions & 0 deletions src/Library/demos/Gamepads/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* 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 */

import Gtk from "gi://Gtk";
import Manette from "gi://Manette";

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());

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()}`,
);

if (device.has_rumble()) {
device.rumble(1000, 1500, 200);
}
});

// D-pads
device.connect("hat-axis-event", (device, event) => {
const [, hat_axis, hat_value] = event.get_hat();
console.log(
`Device: ${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: ${device.get_name()} moved axis ${axis} to ${value}`,
);
});

[has_next, device] = monitor_iter.next();
}
7 changes: 7 additions & 0 deletions src/Library/demos/Gamepads/main.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "Gamepads",
"category": "controls",
"description": "Use Libmanette to access controllers and gamepads",
"panels": ["code", "preview"],
"autorun": false
}