Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

keyboard bindings

Layle3c403f41a9f2
diff --git a/README.md b/README.md
index 8f5838d..dbebde3 100644
--- a/README.md
+++ b/README.md
@@ -104,6 +104,8 @@ On Wii, the pointer source is picked automatically based on what the connected g
Bindings, pointer source, sensitivity and axis inversion are configurable in `gecko` under `Settings > Controller Bindings`, persisted in the `[input]` section of `config.toml` (see [`other/example.conf`](other/example.conf) for every option). `tinyapp` uses the default bindings and points with the mouse. Pass `--pointer gyro|stick|touchpad|auto` to override.
+Keyboard and player-window hotkeys are configurable the same way under `Settings > Keyboard Bindings`, persisted in the `[keyboard]` section of `config.toml`. The keyboard and hotkey tables below are the defaults.
+
> [!NOTE]
> DualSense motion sensors and rumble on Linux require hidraw permissions. Install the `steam-devices` package (or an equivalent udev rule for `054c:0ce6`) and replug the controller. Without it the pad still works, but falls back to buttons and sticks only.
@@ -161,16 +163,18 @@ Bindings, pointer source, sensitivity and axis inversion are configurable in `ge
`gecko` player window:
-| Key | Action |
-| ----- | --------------------------------------------------------------------- |
-| `F10` | Toggle borderless fullscreen |
-| `F11` | Toggle the FPS and emulation speed overlay |
-| `F12` | Screenshot the emulated framebuffer to `<gecko exe dir>/screenshots/` |
+| Key | Action |
+| ------- | --------------------------------------------------------------------- |
+| `Space` | Pause / resume emulation |
+| `Tab` | Toggle the speed limit (run uncapped) |
+| `F10` | Toggle borderless fullscreen |
+| `F11` | Toggle the FPS and emulation speed overlay |
+| `F12` | Screenshot the emulated framebuffer to `<gecko exe dir>/screenshots/` |
</details>
<details>
-<summary>Keyboard bindings (hardcoded)</summary>
+<summary>Keyboard bindings</summary>
#### GameCube
diff --git a/crates/app/src/app.rs b/crates/app/src/app.rs
index 125907e..0798384 100644
--- a/crates/app/src/app.rs
+++ b/crates/app/src/app.rs
@@ -4,6 +4,7 @@ use std::sync::Arc;
use std::time::{Duration, Instant};
use backend_wgpu::capture;
+use iced::keyboard::key::Code;
use iced::theme::Mode;
use iced::widget::{Stack, button, column, container, row, scrollable, stack, text};
use iced::{Background, Border, Color, Element, Length, Padding, Subscription, Task, Theme, window};
@@ -11,11 +12,12 @@ use iced::{Background, Border, Color, Element, Length, Padding, Subscription, Ta
use crate::cache::{self, LibraryCache};
use crate::config::{self, Config};
use crate::game::{CpuMode, Format, Game, Platform, ThemePreference};
+use crate::keybinds::{self, KeyTarget};
use crate::library::{self, ScanProgress};
use crate::player::{self, PlayerState, PlayerStatus};
use crate::theme::{self, Palette};
use crate::update::{self, Outcome};
-use crate::widgets::input_settings::{self, BindTarget, InputTab, InvertTarget};
+use crate::widgets::input_settings::{self, BindTarget, InputTab, InvertTarget, KeyboardTab};
use crate::widgets::{game_row, menubar, overlay, search_bar, statusbar};
const REPO_URL: &str = "https://github.com/ioncodes/gecko";
@@ -51,6 +53,7 @@ pub enum Message {
MenuAbout,
AboutClose,
MenuInputSettings,
+ MenuKeyboardSettings,
InputClose,
InputTab(InputTab),
InputCapture(BindTarget),
@@ -61,6 +64,11 @@ pub enum Message {
InputToggleStickDpad,
InputToggleInvert(InvertTarget),
InputReset,
+ KeyboardClose,
+ KeyboardTab(KeyboardTab),
+ KeyboardCapture(KeyTarget),
+ KeyboardCaptured(Code),
+ KeyboardReset,
OpenUrl(String),
CheckForUpdates,
UpdateChecked(Outcome),
@@ -123,6 +131,9 @@ pub struct App {
input_tab: InputTab,
input_capture: Option<BindTarget>,
input_capture_baseline: u32,
+ keyboard_open: bool,
+ keyboard_tab: KeyboardTab,
+ key_capture: Option<KeyTarget>,
input_pad_name: Option<String>,
system_mode: Mode,
palette: Palette,
@@ -158,6 +169,9 @@ impl App {
input_tab: InputTab::Gc,
input_capture: None,
input_capture_baseline: 0,
+ keyboard_open: false,
+ keyboard_tab: KeyboardTab::Gc,
+ key_capture: None,
input_pad_name: None,
system_mode: Mode::Light,
palette,
@@ -210,6 +224,10 @@ impl App {
subs.push(iced::time::every(Duration::from_millis(100)).map(|_| Message::InputTick));
}
+ if self.keyboard_open && self.key_capture.is_some() {
+ subs.push(iced::event::listen_with(self::capture_key_event));
+ }
+
Subscription::batch(subs)
}
@@ -424,6 +442,7 @@ impl App {
Message::MenuInputSettings => {
self.input_open = true;
self.input_capture = None;
+ self.keyboard_open = false;
self.input_pad_name = self::pad_state().1;
Task::none()
}
@@ -446,6 +465,22 @@ impl App {
}
Task::none()
}
+ Message::MenuKeyboardSettings => {
+ self.keyboard_open = true;
+ self.key_capture = None;
+ self.input_open = false;
+ Task::none()
+ }
+ Message::KeyboardClose => {
+ self.keyboard_open = false;
+ self.key_capture = None;
+ Task::none()
+ }
+ Message::KeyboardTab(tab) => {
+ self.keyboard_tab = tab;
+ self.key_capture = None;
+ Task::none()
+ }
Message::InputTick => {
let (buttons, name) = self::pad_state();
self.input_pad_name = name;
@@ -501,6 +536,30 @@ impl App {
self.persist_config();
Task::none()
}
+ Message::KeyboardCapture(target) => {
+ self.key_capture = if self.key_capture == Some(target) {
+ None
+ } else {
+ Some(target)
+ };
+ Task::none()
+ }
+ Message::KeyboardCaptured(code) => {
+ if let Some(target) = self.key_capture
+ && let Some(name) = keybinds::key_name(code)
+ {
+ *keybinds::field(&mut self.config.keyboard, target) = Some(name.to_owned());
+ self.key_capture = None;
+ self.persist_config();
+ }
+ Task::none()
+ }
+ Message::KeyboardReset => {
+ self.config.keyboard = keybinds::KeyboardConfig::default();
+ self.key_capture = None;
+ self.persist_config();
+ Task::none()
+ }
Message::AboutClose => {
self.about_open = false;
Task::none()
@@ -708,6 +767,13 @@ impl App {
]
.into();
}
+ if self.keyboard_open {
+ root_element = stack![
+ root_element,
+ input_settings::keyboard_overlay(palette, &self.config.keyboard, self.keyboard_tab, self.key_capture)
+ ]
+ .into();
+ }
root_element
}
@@ -984,6 +1050,14 @@ fn pad_state() -> (Option<u32>, Option<String>) {
(buttons, name)
}
+fn capture_key_event(event: iced::Event, _status: iced::event::Status, _window: window::Id) -> Option<Message> {
+ if let iced::Event::Keyboard(iced::keyboard::Event::KeyPressed { physical_key, .. }) = event {
+ player::physical_to_code(&physical_key).map(Message::KeyboardCaptured)
+ } else {
+ None
+ }
+}
+
fn about_overlay(palette: &Palette) -> Element<'static, Message> {
let surface = palette.surface;
let surface_2 = palette.surface_2;
diff --git a/crates/app/src/config.rs b/crates/app/src/config.rs
index 7661a04..b667eb9 100644
--- a/crates/app/src/config.rs
+++ b/crates/app/src/config.rs
@@ -3,6 +3,7 @@ use std::path::{Path, PathBuf};
use serde::{Deserialize, Serialize};
use crate::game::{CpuMode, ThemePreference};
+use crate::keybinds::KeyboardConfig;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(default)]
@@ -24,6 +25,7 @@ pub struct Config {
#[serde(default = "self::default_sram_enabled")]
pub sram_enabled: bool,
pub input: hostinput::InputConfig,
+ pub keyboard: KeyboardConfig,
}
fn default_skip_ipl() -> bool {
@@ -58,6 +60,7 @@ impl Default for Config {
memcard_enabled: self::default_memcard_enabled(),
sram_enabled: self::default_sram_enabled(),
input: hostinput::InputConfig::default(),
+ keyboard: KeyboardConfig::default(),
}
}
}
diff --git a/crates/app/src/keybinds.rs b/crates/app/src/keybinds.rs
new file mode 100644
index 0000000..dd9f9d3
--- /dev/null
+++ b/crates/app/src/keybinds.rs
@@ -0,0 +1,504 @@
+use iced::keyboard::key::Code;
+use serde::{Deserialize, Serialize};
+
+#[derive(Debug, Clone, Default, Serialize, Deserialize)]
+#[serde(default)]
+pub struct KeyboardConfig {
+ pub gc: GcKeysConfig,
+ pub wii: WiiKeysConfig,
+ pub hotkeys: HotkeysConfig,
+}
+
+#[derive(Debug, Clone, Default, Serialize, Deserialize)]
+#[serde(default)]
+pub struct GcKeysConfig {
+ pub stick_up: Option<String>,
+ pub stick_down: Option<String>,
+ pub stick_left: Option<String>,
+ pub stick_right: Option<String>,
+ pub a: Option<String>,
+ pub b: Option<String>,
+ pub x: Option<String>,
+ pub y: Option<String>,
+ pub start: Option<String>,
+ pub l: Option<String>,
+ pub r: Option<String>,
+ pub z: Option<String>,
+ pub dpad_up: Option<String>,
+ pub dpad_down: Option<String>,
+ pub dpad_left: Option<String>,
+ pub dpad_right: Option<String>,
+}
+
+#[derive(Debug, Clone, Default, Serialize, Deserialize)]
+#[serde(default)]
+pub struct WiiKeysConfig {
+ pub one: Option<String>,
+ pub two: Option<String>,
+ pub plus: Option<String>,
+ pub minus: Option<String>,
+ pub home: Option<String>,
+ pub dpad_up: Option<String>,
+ pub dpad_down: Option<String>,
+ pub dpad_left: Option<String>,
+ pub dpad_right: Option<String>,
+ pub shake: Option<String>,
+ pub nunchuk_up: Option<String>,
+ pub nunchuk_down: Option<String>,
+ pub nunchuk_left: Option<String>,
+ pub nunchuk_right: Option<String>,
+ pub nunchuk_z: Option<String>,
+ pub nunchuk_c: Option<String>,
+}
+
+#[derive(Debug, Clone, Default, Serialize, Deserialize)]
+#[serde(default)]
+pub struct HotkeysConfig {
+ pub pause: Option<String>,
+ pub uncapped: Option<String>,
+ pub fullscreen: Option<String>,
+ pub overlay: Option<String>,
+ pub screenshot: Option<String>,
+}
+
+#[derive(Debug, Clone, Copy)]
+pub struct GcKeys {
+ pub stick_up: Code,
+ pub stick_down: Code,
+ pub stick_left: Code,
+ pub stick_right: Code,
+ pub a: Code,
+ pub b: Code,
+ pub x: Code,
+ pub y: Code,
+ pub start: Code,
+ pub l: Code,
+ pub r: Code,
+ pub z: Code,
+ pub dpad_up: Code,
+ pub dpad_down: Code,
+ pub dpad_left: Code,
+ pub dpad_right: Code,
+}
+
+impl Default for GcKeys {
+ fn default() -> Self {
+ Self {
+ stick_up: Code::ArrowUp,
+ stick_down: Code::ArrowDown,
+ stick_left: Code::ArrowLeft,
+ stick_right: Code::ArrowRight,
+ a: Code::KeyX,
+ b: Code::KeyZ,
+ x: Code::KeyC,
+ y: Code::KeyV,
+ start: Code::Enter,
+ l: Code::KeyA,
+ r: Code::KeyS,
+ z: Code::KeyD,
+ dpad_up: Code::KeyI,
+ dpad_down: Code::KeyK,
+ dpad_left: Code::KeyJ,
+ dpad_right: Code::KeyL,
+ }
+ }
+}
+
+#[derive(Debug, Clone, Copy)]
+pub struct WiiKeys {
+ pub one: Code,
+ pub two: Code,
+ pub plus: Code,
+ pub minus: Code,
+ pub home: Code,
+ pub dpad_up: Code,
+ pub dpad_down: Code,
+ pub dpad_left: Code,
+ pub dpad_right: Code,
+ pub shake: Code,
+ pub nunchuk_up: Code,
+ pub nunchuk_down: Code,
+ pub nunchuk_left: Code,
+ pub nunchuk_right: Code,
+ pub nunchuk_z: Code,
+ pub nunchuk_c: Code,
+}
+
+impl Default for WiiKeys {
+ fn default() -> Self {
+ Self {
+ one: Code::Digit1,
+ two: Code::Digit2,
+ plus: Code::Equal,
+ minus: Code::Minus,
+ home: Code::Home,
+ dpad_up: Code::ArrowUp,
+ dpad_down: Code::ArrowDown,
+ dpad_left: Code::ArrowLeft,
+ dpad_right: Code::ArrowRight,
+ shake: Code::ShiftLeft,
+ nunchuk_up: Code::KeyW,
+ nunchuk_down: Code::KeyS,
+ nunchuk_left: Code::KeyA,
+ nunchuk_right: Code::KeyD,
+ nunchuk_z: Code::KeyQ,
+ nunchuk_c: Code::KeyE,
+ }
+ }
+}
+
+#[derive(Debug, Clone, Copy)]
+pub struct Hotkeys {
+ pub pause: Code,
+ pub uncapped: Code,
+ pub fullscreen: Code,
+ pub overlay: Code,
+ pub screenshot: Code,
+}
+
+impl Default for Hotkeys {
+ fn default() -> Self {
+ Self {
+ pause: Code::Space,
+ uncapped: Code::Tab,
+ fullscreen: Code::F10,
+ overlay: Code::F11,
+ screenshot: Code::F12,
+ }
+ }
+}
+
+#[derive(Debug, Clone, Copy, Default)]
+pub struct Keymap {
+ pub gc: GcKeys,
+ pub wii: WiiKeys,
+ pub hotkeys: Hotkeys,
+}
+
+#[derive(Debug, Clone, Copy)]
+pub enum Hotkey {
+ Pause,
+ Uncapped,
+ Fullscreen,
+ Overlay,
+ Screenshot,
+}
+
+impl Hotkeys {
+ pub fn lookup(&self, key: Code) -> Option<Hotkey> {
+ if key == self.pause {
+ Some(Hotkey::Pause)
+ } else if key == self.uncapped {
+ Some(Hotkey::Uncapped)
+ } else if key == self.fullscreen {
+ Some(Hotkey::Fullscreen)
+ } else if key == self.overlay {
+ Some(Hotkey::Overlay)
+ } else if key == self.screenshot {
+ Some(Hotkey::Screenshot)
+ } else {
+ None
+ }
+ }
+}
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum KeyTarget {
+ GcStickUp,
+ GcStickDown,
+ GcStickLeft,
+ GcStickRight,
+ GcA,
+ GcB,
+ GcX,
+ GcY,
+ GcStart,
+ GcL,
+ GcR,
+ GcZ,
+ GcDpadUp,
+ GcDpadDown,
+ GcDpadLeft,
+ GcDpadRight,
+ WiiOne,
+ WiiTwo,
+ WiiPlus,
+ WiiMinus,
+ WiiHome,
+ WiiDpadUp,
+ WiiDpadDown,
+ WiiDpadLeft,
+ WiiDpadRight,
+ WiiShake,
+ NunchukUp,
+ NunchukDown,
+ NunchukLeft,
+ NunchukRight,
+ NunchukZ,
+ NunchukC,
+ HotkeyPause,
+ HotkeyUncapped,
+ HotkeyFullscreen,
+ HotkeyOverlay,
+ HotkeyScreenshot,
+}
+
+pub const GC_KEY_TARGETS: &[(KeyTarget, &str)] = &[
+ (KeyTarget::GcStickUp, "Stick Up"),
+ (KeyTarget::GcStickDown, "Stick Down"),
+ (KeyTarget::GcStickLeft, "Stick Left"),
+ (KeyTarget::GcStickRight, "Stick Right"),
+ (KeyTarget::GcA, "A"),
+ (KeyTarget::GcB, "B"),
+ (KeyTarget::GcX, "X"),
+ (KeyTarget::GcY, "Y"),
+ (KeyTarget::GcStart, "Start"),
+ (KeyTarget::GcL, "L"),
+ (KeyTarget::GcR, "R"),
+ (KeyTarget::GcZ, "Z"),
+ (KeyTarget::GcDpadUp, "D-Pad Up"),
+ (KeyTarget::GcDpadDown, "D-Pad Down"),
+ (KeyTarget::GcDpadLeft, "D-Pad Left"),
+ (KeyTarget::GcDpadRight, "D-Pad Right"),
+];
+
+pub const WII_KEY_TARGETS: &[(KeyTarget, &str)] = &[
+ (KeyTarget::WiiDpadUp, "D-Pad Up"),
+ (KeyTarget::WiiDpadDown, "D-Pad Down"),
+ (KeyTarget::WiiDpadLeft, "D-Pad Left"),
+ (KeyTarget::WiiDpadRight, "D-Pad Right"),
+ (KeyTarget::WiiOne, "1"),
+ (KeyTarget::WiiTwo, "2"),
+ (KeyTarget::WiiPlus, "Plus"),
+ (KeyTarget::WiiMinus, "Minus"),
+ (KeyTarget::WiiHome, "Home"),
+ (KeyTarget::WiiShake, "Shake"),
+ (KeyTarget::NunchukUp, "Nunchuk Up"),
+ (KeyTarget::NunchukDown, "Nunchuk Down"),
+ (KeyTarget::NunchukLeft, "Nunchuk Left"),
+ (KeyTarget::NunchukRight, "Nunchuk Right"),
+ (KeyTarget::NunchukZ, "Nunchuk Z"),
+ (KeyTarget::NunchukC, "Nunchuk C"),
+];
+
+pub const HOTKEY_TARGETS: &[(KeyTarget, &str)] = &[
+ (KeyTarget::HotkeyPause, "Pause"),
+ (KeyTarget::HotkeyUncapped, "Uncapped"),
+ (KeyTarget::HotkeyFullscreen, "Fullscreen"),
+ (KeyTarget::HotkeyOverlay, "Overlay"),
+ (KeyTarget::HotkeyScreenshot, "Screenshot"),
+];
+
+pub fn field(config: &mut KeyboardConfig, target: KeyTarget) -> &mut Option<String> {
+ match target {
+ KeyTarget::GcStickUp => &mut config.gc.stick_up,
+ KeyTarget::GcStickDown => &mut config.gc.stick_down,
+ KeyTarget::GcStickLeft => &mut config.gc.stick_left,
+ KeyTarget::GcStickRight => &mut config.gc.stick_right,
+ KeyTarget::GcA => &mut config.gc.a,
+ KeyTarget::GcB => &mut config.gc.b,
+ KeyTarget::GcX => &mut config.gc.x,
+ KeyTarget::GcY => &mut config.gc.y,
+ KeyTarget::GcStart => &mut config.gc.start,
+ KeyTarget::GcL => &mut config.gc.l,
+ KeyTarget::GcR => &mut config.gc.r,
+ KeyTarget::GcZ => &mut config.gc.z,
+ KeyTarget::GcDpadUp => &mut config.gc.dpad_up,
+ KeyTarget::GcDpadDown => &mut config.gc.dpad_down,
+ KeyTarget::GcDpadLeft => &mut config.gc.dpad_left,
+ KeyTarget::GcDpadRight => &mut config.gc.dpad_right,
+ KeyTarget::WiiOne => &mut config.wii.one,
+ KeyTarget::WiiTwo => &mut config.wii.two,
+ KeyTarget::WiiPlus => &mut config.wii.plus,
+ KeyTarget::WiiMinus => &mut config.wii.minus,
+ KeyTarget::WiiHome => &mut config.wii.home,
+ KeyTarget::WiiDpadUp => &mut config.wii.dpad_up,
+ KeyTarget::WiiDpadDown => &mut config.wii.dpad_down,
+ KeyTarget::WiiDpadLeft => &mut config.wii.dpad_left,
+ KeyTarget::WiiDpadRight => &mut config.wii.dpad_right,
+ KeyTarget::WiiShake => &mut config.wii.shake,
+ KeyTarget::NunchukUp => &mut config.wii.nunchuk_up,
+ KeyTarget::NunchukDown => &mut config.wii.nunchuk_down,
+ KeyTarget::NunchukLeft => &mut config.wii.nunchuk_left,
+ KeyTarget::NunchukRight => &mut config.wii.nunchuk_right,
+ KeyTarget::NunchukZ => &mut config.wii.nunchuk_z,
+ KeyTarget::NunchukC => &mut config.wii.nunchuk_c,
+ KeyTarget::HotkeyPause => &mut config.hotkeys.pause,
+ KeyTarget::HotkeyUncapped => &mut config.hotkeys.uncapped,
+ KeyTarget::HotkeyFullscreen => &mut config.hotkeys.fullscreen,
+ KeyTarget::HotkeyOverlay => &mut config.hotkeys.overlay,
+ KeyTarget::HotkeyScreenshot => &mut config.hotkeys.screenshot,
+ }
+}
+
+impl Keymap {
+ pub fn code(&self, target: KeyTarget) -> Code {
+ match target {
+ KeyTarget::GcStickUp => self.gc.stick_up,
+ KeyTarget::GcStickDown => self.gc.stick_down,
+ KeyTarget::GcStickLeft => self.gc.stick_left,
+ KeyTarget::GcStickRight => self.gc.stick_right,
+ KeyTarget::GcA => self.gc.a,
+ KeyTarget::GcB => self.gc.b,
+ KeyTarget::GcX => self.gc.x,
+ KeyTarget::GcY => self.gc.y,
+ KeyTarget::GcStart => self.gc.start,
+ KeyTarget::GcL => self.gc.l,
+ KeyTarget::GcR => self.gc.r,
+ KeyTarget::GcZ => self.gc.z,
+ KeyTarget::GcDpadUp => self.gc.dpad_up,
+ KeyTarget::GcDpadDown => self.gc.dpad_down,
+ KeyTarget::GcDpadLeft => self.gc.dpad_left,
+ KeyTarget::GcDpadRight => self.gc.dpad_right,
+ KeyTarget::WiiOne => self.wii.one,
+ KeyTarget::WiiTwo => self.wii.two,
+ KeyTarget::WiiPlus => self.wii.plus,
+ KeyTarget::WiiMinus => self.wii.minus,
+ KeyTarget::WiiHome => self.wii.home,
+ KeyTarget::WiiDpadUp => self.wii.dpad_up,
+ KeyTarget::WiiDpadDown => self.wii.dpad_down,
+ KeyTarget::WiiDpadLeft => self.wii.dpad_left,
+ KeyTarget::WiiDpadRight => self.wii.dpad_right,
+ KeyTarget::WiiShake => self.wii.shake,
+ KeyTarget::NunchukUp => self.wii.nunchuk_up,
+ KeyTarget::NunchukDown => self.wii.nunchuk_down,
+ KeyTarget::NunchukLeft => self.wii.nunchuk_left,
+ KeyTarget::NunchukRight => self.wii.nunchuk_right,
+ KeyTarget::NunchukZ => self.wii.nunchuk_z,
+ KeyTarget::NunchukC => self.wii.nunchuk_c,
+ KeyTarget::HotkeyPause => self.hotkeys.pause,
+ KeyTarget::HotkeyUncapped => self.hotkeys.uncapped,
+ KeyTarget::HotkeyFullscreen => self.hotkeys.fullscreen,
+ KeyTarget::HotkeyOverlay => self.hotkeys.overlay,
+ KeyTarget::HotkeyScreenshot => self.hotkeys.screenshot,
+ }
+ }
+}
+
+impl KeyboardConfig {
+ pub fn resolve(&self) -> Keymap {
+ let mut keymap = Keymap::default();
+
+ self::set(&mut keymap.gc.stick_up, &self.gc.stick_up);
+ self::set(&mut keymap.gc.stick_down, &self.gc.stick_down);
+ self::set(&mut keymap.gc.stick_left, &self.gc.stick_left);
+ self::set(&mut keymap.gc.stick_right, &self.gc.stick_right);
+ self::set(&mut keymap.gc.a, &self.gc.a);
+ self::set(&mut keymap.gc.b, &self.gc.b);
+ self::set(&mut keymap.gc.x, &self.gc.x);
+ self::set(&mut keymap.gc.y, &self.gc.y);
+ self::set(&mut keymap.gc.start, &self.gc.start);
+ self::set(&mut keymap.gc.l, &self.gc.l);
+ self::set(&mut keymap.gc.r, &self.gc.r);
+ self::set(&mut keymap.gc.z, &self.gc.z);
+ self::set(&mut keymap.gc.dpad_up, &self.gc.dpad_up);
+ self::set(&mut keymap.gc.dpad_down, &self.gc.dpad_down);
+ self::set(&mut keymap.gc.dpad_left, &self.gc.dpad_left);
+ self::set(&mut keymap.gc.dpad_right, &self.gc.dpad_right);
+
+ self::set(&mut keymap.wii.one, &self.wii.one);
+ self::set(&mut keymap.wii.two, &self.wii.two);
+ self::set(&mut keymap.wii.plus, &self.wii.plus);
+ self::set(&mut keymap.wii.minus, &self.wii.minus);
+ self::set(&mut keymap.wii.home, &self.wii.home);
+ self::set(&mut keymap.wii.dpad_up, &self.wii.dpad_up);
+ self::set(&mut keymap.wii.dpad_down, &self.wii.dpad_down);
+ self::set(&mut keymap.wii.dpad_left, &self.wii.dpad_left);
+ self::set(&mut keymap.wii.dpad_right, &self.wii.dpad_right);
+ self::set(&mut keymap.wii.shake, &self.wii.shake);
+ self::set(&mut keymap.wii.nunchuk_up, &self.wii.nunchuk_up);
+ self::set(&mut keymap.wii.nunchuk_down, &self.wii.nunchuk_down);
+ self::set(&mut keymap.wii.nunchuk_left, &self.wii.nunchuk_left);
+ self::set(&mut keymap.wii.nunchuk_right, &self.wii.nunchuk_right);
+ self::set(&mut keymap.wii.nunchuk_z, &self.wii.nunchuk_z);
+ self::set(&mut keymap.wii.nunchuk_c, &self.wii.nunchuk_c);
+
+ self::set(&mut keymap.hotkeys.pause, &self.hotkeys.pause);
+ self::set(&mut keymap.hotkeys.uncapped, &self.hotkeys.uncapped);
+ self::set(&mut keymap.hotkeys.fullscreen, &self.hotkeys.fullscreen);
+ self::set(&mut keymap.hotkeys.overlay, &self.hotkeys.overlay);
+ self::set(&mut keymap.hotkeys.screenshot, &self.hotkeys.screenshot);
+
+ keymap
+ }
+}
+
+fn set(slot: &mut Code, name: &Option<String>) {
+ let Some(name) = name.as_deref() else {
+ return;
+ };
+
+ match self::parse_key(name) {
+ Some(code) => *slot = code,
+ None => tracing::warn!(key = name, "unknown key name in config, keeping default"),
+ }
+}
+
+pub fn key_label(code: Code) -> String {
+ match self::key_name(code) {
+ Some(name) => self::title_case(name),
+ None => "Unsupported".to_owned(),
+ }
+}
+
+fn title_case(name: &str) -> String {
+ name.split('_')
+ .map(|word| {
+ let mut chars = word.chars();
+ match chars.next() {
+ Some(first) => first.to_uppercase().collect::<String>() + chars.as_str(),
+ None => String::new(),
+ }
+ })
+ .collect::<Vec<_>>()
+ .join(" ")
+}
+
+macro_rules! key_names {
+ ($($variant:ident => $name:literal),* $(,)?) => {
+ pub fn key_name(code: Code) -> Option<&'static str> {
+ match code {
+ $( Code::$variant => Some($name), )*
+ _ => None,
+ }
+ }
+
+ pub fn parse_key(name: &str) -> Option<Code> {
+ match name {
+ $( $name => Some(Code::$variant), )*
+ _ => None,
+ }
+ }
+ };
+}
+
+key_names! {
+ KeyA => "a", KeyB => "b", KeyC => "c", KeyD => "d", KeyE => "e", KeyF => "f",
+ KeyG => "g", KeyH => "h", KeyI => "i", KeyJ => "j", KeyK => "k", KeyL => "l",
+ KeyM => "m", KeyN => "n", KeyO => "o", KeyP => "p", KeyQ => "q", KeyR => "r",
+ KeyS => "s", KeyT => "t", KeyU => "u", KeyV => "v", KeyW => "w", KeyX => "x",
+ KeyY => "y", KeyZ => "z",
+ Digit0 => "0", Digit1 => "1", Digit2 => "2", Digit3 => "3", Digit4 => "4",
+ Digit5 => "5", Digit6 => "6", Digit7 => "7", Digit8 => "8", Digit9 => "9",
+ ArrowUp => "up", ArrowDown => "down", ArrowLeft => "left", ArrowRight => "right",
+ Space => "space", Enter => "enter", Tab => "tab", Escape => "escape",
+ Backspace => "backspace", Delete => "delete", Insert => "insert",
+ Home => "home", End => "end", PageUp => "page_up", PageDown => "page_down",
+ CapsLock => "caps_lock",
+ ShiftLeft => "shift_left", ShiftRight => "shift_right",
+ ControlLeft => "ctrl_left", ControlRight => "ctrl_right",
+ AltLeft => "alt_left", AltRight => "alt_right",
+ SuperLeft => "super_left", SuperRight => "super_right",
+ Minus => "minus", Equal => "equal", Comma => "comma", Period => "period",
+ Slash => "slash", Semicolon => "semicolon", Quote => "quote",
+ Backquote => "backquote", Backslash => "backslash",
+ BracketLeft => "bracket_left", BracketRight => "bracket_right",
+ F1 => "f1", F2 => "f2", F3 => "f3", F4 => "f4", F5 => "f5", F6 => "f6",
+ F7 => "f7", F8 => "f8", F9 => "f9", F10 => "f10", F11 => "f11", F12 => "f12",
+ Numpad0 => "numpad_0", Numpad1 => "numpad_1", Numpad2 => "numpad_2",
+ Numpad3 => "numpad_3", Numpad4 => "numpad_4", Numpad5 => "numpad_5",
+ Numpad6 => "numpad_6", Numpad7 => "numpad_7", Numpad8 => "numpad_8",
+ Numpad9 => "numpad_9", NumpadEnter => "numpad_enter", NumpadAdd => "numpad_add",
+ NumpadSubtract => "numpad_subtract", NumpadMultiply => "numpad_multiply",
+ NumpadDivide => "numpad_divide", NumpadDecimal => "numpad_decimal",
+}
diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs
index 698956a..eea925b 100644
--- a/crates/app/src/main.rs
+++ b/crates/app/src/main.rs
@@ -2,6 +2,7 @@ mod app;
mod cache;
mod config;
mod game;
+mod keybinds;
mod library;
mod player;
mod theme;
diff --git a/crates/app/src/player.rs b/crates/app/src/player.rs
index 2bbb7b5..c1fa697 100644
--- a/crates/app/src/player.rs
+++ b/crates/app/src/player.rs
@@ -4,5 +4,5 @@ mod input;
mod state;
mod widget;
-pub use state::{PlayerState, PlayerStatus};
+pub use state::{PlayerState, PlayerStatus, physical_to_code};
pub use widget::shader_widget;
diff --git a/crates/app/src/player/input.rs b/crates/app/src/player/input.rs
index fa491b4..fe5f0e9 100644
--- a/crates/app/src/player/input.rs
+++ b/crates/app/src/player/input.rs
@@ -2,6 +2,8 @@ use gecko::flipper::si::pad::{self, PadStatus, STICK_CENTER, STICK_MAX, STICK_MI
use gecko::hollywood::ipc::usb as wiimote;
use iced::keyboard::key::Code;
+use crate::keybinds::{GcKeys, WiiKeys};
+
#[inline(always)]
fn set_bit<T: std::ops::BitOrAssign + std::ops::BitAndAssign + std::ops::Not<Output = T> + Copy>(
bits: &mut T,
@@ -15,69 +17,97 @@ fn set_bit<T: std::ops::BitOrAssign + std::ops::BitAndAssign + std::ops::Not<Out
}
}
-pub fn update_pad(pad: &mut PadStatus, key: Code, pressed: bool) {
- match key {
- Code::ArrowUp => pad.stick_y = if pressed { STICK_MAX } else { STICK_CENTER },
- Code::ArrowDown => pad.stick_y = if pressed { STICK_MIN } else { STICK_CENTER },
- Code::ArrowLeft => pad.stick_x = if pressed { STICK_MIN } else { STICK_CENTER },
- Code::ArrowRight => pad.stick_x = if pressed { STICK_MAX } else { STICK_CENTER },
-
- Code::KeyX => self::set_bit(&mut pad.buttons, pad::A, pressed),
- Code::KeyZ => self::set_bit(&mut pad.buttons, pad::B, pressed),
- Code::KeyC => self::set_bit(&mut pad.buttons, pad::X, pressed),
- Code::KeyV => self::set_bit(&mut pad.buttons, pad::Y, pressed),
- Code::Enter => self::set_bit(&mut pad.buttons, pad::START, pressed),
-
- Code::KeyA => {
- self::set_bit(&mut pad.buttons, pad::L, pressed);
- pad.trigger_left = if pressed { TRIGGER_MAX } else { TRIGGER_MIN };
- }
- Code::KeyS => {
- self::set_bit(&mut pad.buttons, pad::R, pressed);
- pad.trigger_right = if pressed { TRIGGER_MAX } else { TRIGGER_MIN };
- }
- Code::KeyD => self::set_bit(&mut pad.buttons, pad::Z, pressed),
-
- Code::KeyI => self::set_bit(&mut pad.buttons, pad::DPAD_UP, pressed),
- Code::KeyK => self::set_bit(&mut pad.buttons, pad::DPAD_DOWN, pressed),
- Code::KeyJ => self::set_bit(&mut pad.buttons, pad::DPAD_LEFT, pressed),
- Code::KeyL => self::set_bit(&mut pad.buttons, pad::DPAD_RIGHT, pressed),
-
- _ => {}
+pub fn update_pad(pad: &mut PadStatus, keys: &GcKeys, key: Code, pressed: bool) {
+ if key == keys.stick_up {
+ pad.stick_y = if pressed { STICK_MAX } else { STICK_CENTER };
+ } else if key == keys.stick_down {
+ pad.stick_y = if pressed { STICK_MIN } else { STICK_CENTER };
+ } else if key == keys.stick_left {
+ pad.stick_x = if pressed { STICK_MIN } else { STICK_CENTER };
+ } else if key == keys.stick_right {
+ pad.stick_x = if pressed { STICK_MAX } else { STICK_CENTER };
+ } else if key == keys.a {
+ self::set_bit(&mut pad.buttons, pad::A, pressed);
+ } else if key == keys.b {
+ self::set_bit(&mut pad.buttons, pad::B, pressed);
+ } else if key == keys.x {
+ self::set_bit(&mut pad.buttons, pad::X, pressed);
+ } else if key == keys.y {
+ self::set_bit(&mut pad.buttons, pad::Y, pressed);
+ } else if key == keys.start {
+ self::set_bit(&mut pad.buttons, pad::START, pressed);
+ } else if key == keys.l {
+ self::set_bit(&mut pad.buttons, pad::L, pressed);
+ pad.trigger_left = if pressed { TRIGGER_MAX } else { TRIGGER_MIN };
+ } else if key == keys.r {
+ self::set_bit(&mut pad.buttons, pad::R, pressed);
+ pad.trigger_right = if pressed { TRIGGER_MAX } else { TRIGGER_MIN };
+ } else if key == keys.z {
+ self::set_bit(&mut pad.buttons, pad::Z, pressed);
+ } else if key == keys.dpad_up {
+ self::set_bit(&mut pad.buttons, pad::DPAD_UP, pressed);
+ } else if key == keys.dpad_down {
+ self::set_bit(&mut pad.buttons, pad::DPAD_DOWN, pressed);
+ } else if key == keys.dpad_left {
+ self::set_bit(&mut pad.buttons, pad::DPAD_LEFT, pressed);
+ } else if key == keys.dpad_right {
+ self::set_bit(&mut pad.buttons, pad::DPAD_RIGHT, pressed);
}
}
-pub fn update_wiimote_keys(buttons: &mut u16, key: Code, pressed: bool) {
- let mask = match key {
- Code::Digit1 => wiimote::BTN_ONE,
- Code::Digit2 => wiimote::BTN_TWO,
- Code::Home => wiimote::BTN_HOME,
- Code::Minus => wiimote::BTN_MINUS,
- Code::Equal => wiimote::BTN_PLUS,
- Code::ArrowUp => wiimote::BTN_UP,
- Code::ArrowDown => wiimote::BTN_DOWN,
- Code::ArrowLeft => wiimote::BTN_LEFT,
- Code::ArrowRight => wiimote::BTN_RIGHT,
- _ => return,
+pub fn update_wiimote_keys(buttons: &mut u16, keys: &WiiKeys, key: Code, pressed: bool) {
+ let mask = if key == keys.one {
+ wiimote::BTN_ONE
+ } else if key == keys.two {
+ wiimote::BTN_TWO
+ } else if key == keys.home {
+ wiimote::BTN_HOME
+ } else if key == keys.minus {
+ wiimote::BTN_MINUS
+ } else if key == keys.plus {
+ wiimote::BTN_PLUS
+ } else if key == keys.dpad_up {
+ wiimote::BTN_UP
+ } else if key == keys.dpad_down {
+ wiimote::BTN_DOWN
+ } else if key == keys.dpad_left {
+ wiimote::BTN_LEFT
+ } else if key == keys.dpad_right {
+ wiimote::BTN_RIGHT
+ } else {
+ return;
};
+
self::set_bit(buttons, mask, pressed);
}
-pub fn update_wiimote_motion_keys(shake: &mut bool, key: Code, pressed: bool) {
- if matches!(key, Code::ShiftLeft) {
+pub fn update_wiimote_motion_keys(shake: &mut bool, keys: &WiiKeys, key: Code, pressed: bool) {
+ if key == keys.shake {
*shake = pressed;
}
}
-pub fn update_nunchuk_keys(buttons: &mut u8, stick_x: &mut u8, stick_y: &mut u8, key: Code, pressed: bool) {
+pub fn update_nunchuk_keys(
+ buttons: &mut u8,
+ stick_x: &mut u8,
+ stick_y: &mut u8,
+ keys: &WiiKeys,
+ key: Code,
+ pressed: bool,
+) {
use wiimote::{NUNCHUK_STICK_CENTER as C, NUNCHUK_STICK_MAX as MAX, NUNCHUK_STICK_MIN as MIN};
- match key {
- Code::KeyW => *stick_y = if pressed { MAX } else { C },
- Code::KeyS => *stick_y = if pressed { MIN } else { C },
- Code::KeyA => *stick_x = if pressed { MIN } else { C },
- Code::KeyD => *stick_x = if pressed { MAX } else { C },
- Code::KeyQ => self::set_bit(buttons, wiimote::NUNCHUK_BTN_Z, pressed),
- Code::KeyE => self::set_bit(buttons, wiimote::NUNCHUK_BTN_C, pressed),
- _ => {}
+
+ if key == keys.nunchuk_up {
+ *stick_y = if pressed { MAX } else { C };
+ } else if key == keys.nunchuk_down {
+ *stick_y = if pressed { MIN } else { C };
+ } else if key == keys.nunchuk_left {
+ *stick_x = if pressed { MIN } else { C };
+ } else if key == keys.nunchuk_right {
+ *stick_x = if pressed { MAX } else { C };
+ } else if key == keys.nunchuk_z {
+ self::set_bit(buttons, wiimote::NUNCHUK_BTN_Z, pressed);
+ } else if key == keys.nunchuk_c {
+ self::set_bit(buttons, wiimote::NUNCHUK_BTN_C, pressed);
}
}
diff --git a/crates/app/src/player/state.rs b/crates/app/src/player/state.rs
index fb5d15c..0169ade 100644
--- a/crates/app/src/player/state.rs
+++ b/crates/app/src/player/state.rs
@@ -15,6 +15,7 @@ use iced::mouse::Button as MouseButton;
use crate::config::{self, Config, DSP_COEF_FILE, DSP_ROM_FILE, IPL_FILE, MEMCARD_A_FILE, SRAM_FILE};
use crate::game::{Format, Game, Platform};
+use crate::keybinds::{Hotkey, Keymap};
use crate::player::{audio, emu_thread, input};
struct BootParams {
@@ -44,6 +45,7 @@ pub struct PlayerState {
aspect: TargetAspect,
upscale: u32,
input: Arc<Mutex<HostInput>>,
+ keymap: Keymap,
platform: Platform,
boot_error: Option<String>,
first_frame: Arc<AtomicBool>,
@@ -100,6 +102,7 @@ impl PlayerState {
aspect,
upscale: config.upscale,
input: Arc::new(Mutex::new(neutral)),
+ keymap: config.keyboard.resolve(),
platform: game.platform,
boot_error,
first_frame: Arc::new(AtomicBool::new(false)),
@@ -149,7 +152,7 @@ impl PlayerState {
pub fn handle_keyboard(&self, key: Code, pressed: bool) {
let mut input_guard = self.input.lock().unwrap();
match &mut *input_guard {
- HostInput::Gc(pad) => input::update_pad(pad, key, pressed),
+ HostInput::Gc(pad) => input::update_pad(pad, &self.keymap.gc, key, pressed),
HostInput::Wii {
wiimote_buttons,
wiimote_shake,
@@ -158,13 +161,24 @@ impl PlayerState {
nunchuk_stick_y,
..
} => {
- input::update_wiimote_keys(wiimote_buttons, key, pressed);
- input::update_wiimote_motion_keys(wiimote_shake, key, pressed);
- input::update_nunchuk_keys(nunchuk_buttons, nunchuk_stick_x, nunchuk_stick_y, key, pressed);
+ input::update_wiimote_keys(wiimote_buttons, &self.keymap.wii, key, pressed);
+ input::update_wiimote_motion_keys(wiimote_shake, &self.keymap.wii, key, pressed);
+ input::update_nunchuk_keys(
+ nunchuk_buttons,
+ nunchuk_stick_x,
+ nunchuk_stick_y,
+ &self.keymap.wii,
+ key,
+ pressed,
+ );
}
}
}
+ pub fn hotkey(&self, key: Code) -> Option<Hotkey> {
+ self.keymap.hotkeys.lookup(key)
+ }
+
pub fn handle_mouse_button(&self, button: MouseButton, pressed: bool) {
let mask = match button {
MouseButton::Left => usb::BTN_A,
diff --git a/crates/app/src/player/widget.rs b/crates/app/src/player/widget.rs
index 0c6ac91..a3f20da 100644
--- a/crates/app/src/player/widget.rs
+++ b/crates/app/src/player/widget.rs
@@ -1,11 +1,11 @@
use std::sync::Arc;
use iced::advanced::graphics::Viewport;
-use iced::keyboard::key::Code;
use iced::widget::shader::{self, Pipeline, Primitive, Program, Shader};
use iced::{Rectangle, mouse, window};
use crate::app::Message;
+use crate::keybinds::Hotkey;
use crate::player::state::{self, PlayerState};
pub fn shader_widget(state: Arc<PlayerState>, window: window::Id) -> Shader<Message, PlayerProgram> {
@@ -14,6 +14,16 @@ pub fn shader_widget(state: Arc<PlayerState>, window: window::Id) -> Shader<Mess
.height(iced::Length::Fill)
}
+fn hotkey_message(hotkey: Hotkey, window: window::Id) -> Message {
+ match hotkey {
+ Hotkey::Pause => Message::PlayerTogglePause(window),
+ Hotkey::Uncapped => Message::PlayerToggleUncapped(window),
+ Hotkey::Fullscreen => Message::PlayerToggleFullscreen(window),
+ Hotkey::Overlay => Message::PlayerToggleOverlay(window),
+ Hotkey::Screenshot => Message::PlayerScreenshot(window),
+ }
+}
+
pub struct PlayerProgram {
state: Arc<PlayerState>,
window: window::Id,
@@ -43,15 +53,13 @@ impl Program<Message> for PlayerProgram {
} => {
let hotkey = match state::physical_to_code(physical_key) {
Some(_) if *repeat => None,
- Some(Code::Space) => Some(Message::PlayerTogglePause(self.window)),
- Some(Code::Tab) => Some(Message::PlayerToggleUncapped(self.window)),
- Some(Code::F10) => Some(Message::PlayerToggleFullscreen(self.window)),
- Some(Code::F11) => Some(Message::PlayerToggleOverlay(self.window)),
- Some(Code::F12) => Some(Message::PlayerScreenshot(self.window)),
- Some(code) => {
- self.state.handle_keyboard(code, true);
- None
- }
+ Some(code) => match self.state.hotkey(code) {
+ Some(hotkey) => Some(self::hotkey_message(hotkey, self.window)),
+ None => {
+ self.state.handle_keyboard(code, true);
+ None
+ }
+ },
None => None,
};
diff --git a/crates/app/src/widgets/input_settings.rs b/crates/app/src/widgets/input_settings.rs
index ee536a0..1043917 100644
--- a/crates/app/src/widgets/input_settings.rs
+++ b/crates/app/src/widgets/input_settings.rs
@@ -6,6 +6,7 @@ use iced::widget::{button, column, container, pick_list, row, text};
use iced::{Alignment, Background, Border, Color, Element, Length, Padding};
use crate::app::Message;
+use crate::keybinds::{self, KeyTarget, KeyboardConfig, Keymap};
use crate::theme::Palette;
use crate::widgets::overlay;
@@ -15,6 +16,13 @@ pub enum InputTab {
Wii,
}
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum KeyboardTab {
+ Gc,
+ Wii,
+ Hotkeys,
+}
+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BindTarget {
GcA,
@@ -384,6 +392,82 @@ pub fn overlay(
overlay::modal(palette, 360.0, 20.0, Message::InputClose, card_col.into())
}
+pub fn keyboard_overlay(
+ palette: &Palette,
+ keyboard: &KeyboardConfig,
+ tab: KeyboardTab,
+ capture: Option<KeyTarget>,
+) -> Element<'static, Message> {
+ let status = text("Click a binding, then press a key")
+ .size(11)
+ .color(palette.text_mute);
+
+ let header = column![text("Keyboard Bindings").size(16).color(palette.text), status,].spacing(2);
+
+ let tabs = row![
+ self::chip(
+ palette,
+ "GameCube",
+ Message::KeyboardTab(KeyboardTab::Gc),
+ tab == KeyboardTab::Gc
+ ),
+ self::chip(
+ palette,
+ "Wii",
+ Message::KeyboardTab(KeyboardTab::Wii),
+ tab == KeyboardTab::Wii
+ ),
+ self::chip(
+ palette,
+ "Hotkeys",
+ Message::KeyboardTab(KeyboardTab::Hotkeys),
+ tab == KeyboardTab::Hotkeys
+ ),
+ ]
+ .spacing(6);
+
+ let keymap = keyboard.resolve();
+
+ let targets: &[(KeyTarget, &str)] = match tab {
+ KeyboardTab::Gc => keybinds::GC_KEY_TARGETS,
+ KeyboardTab::Wii => keybinds::WII_KEY_TARGETS,
+ KeyboardTab::Hotkeys => keybinds::HOTKEY_TARGETS,
+ };
+
+ let mut body = column![].spacing(4);
+ for (target, label) in targets {
+ body = body.push(self::key_binding_row(palette, label, *target, &keymap, capture));
+ }
+
+ let footer = row![
+ self::chip(palette, "Reset to Defaults", Message::KeyboardReset, false),
+ container(text("")).width(Length::Fill),
+ self::chip(palette, "Close", Message::KeyboardClose, false),
+ ]
+ .align_y(Alignment::Center);
+
+ let card_col = column![header, tabs, body, footer].spacing(14);
+
+ overlay::modal(palette, 360.0, 20.0, Message::KeyboardClose, card_col.into())
+}
+
+fn key_binding_row(
+ palette: &Palette,
+ label: &'static str,
+ target: KeyTarget,
+ keymap: &Keymap,
+ capture: Option<KeyTarget>,
+) -> Element<'static, Message> {
+ let capturing = capture == Some(target);
+ let value = if capturing {
+ "press a key".to_owned()
+ } else {
+ keybinds::key_label(keymap.code(target))
+ };
+
+ self::bind_row(palette, label, value, Message::KeyboardCapture(target), capturing)
+}
+
fn control_style(
surface: Color,
surface_2: Color,
@@ -415,6 +499,16 @@ fn binding_row(
value: String,
target: BindTarget,
capturing: bool,
+) -> Element<'static, Message> {
+ self::bind_row(palette, label, value, Message::InputCapture(target), capturing)
+}
+
+fn bind_row(
+ palette: &Palette,
+ label: &str,
+ value: String,
+ on_press: Message,
+ capturing: bool,
) -> Element<'static, Message> {
let value_color = if capturing { palette.accent } else { palette.text_dim };
let border = if capturing { palette.accent } else { palette.border_2 };
@@ -426,7 +520,7 @@ fn binding_row(
)
.width(Length::Fixed(180.0))
.padding(Padding::from([4, 10]))
- .on_press(Message::InputCapture(target))
+ .on_press(on_press)
.style(self::control_style(
palette.surface,
palette.surface_2,
@@ -435,7 +529,7 @@ fn binding_row(
));
row![
- container(text(label).size(13).color(palette.text)).width(Length::Fixed(130.0)),
+ container(text(label.to_owned()).size(13).color(palette.text)).width(Length::Fixed(130.0)),
bind,
]
.spacing(6)
diff --git a/crates/app/src/widgets/menubar.rs b/crates/app/src/widgets/menubar.rs
index cebc165..afc9b18 100644
--- a/crates/app/src/widgets/menubar.rs
+++ b/crates/app/src/widgets/menubar.rs
@@ -325,6 +325,12 @@ fn settings_menu(
Message::MenuInputSettings,
None,
)),
+ Item::new(self::menu_item(
+ palette,
+ "Keyboard Bindings",
+ Message::MenuKeyboardSettings,
+ None,
+ )),
])
.max_width(240.0)
.offset(4.0)
diff --git a/other/example.conf b/other/example.conf
index 2795513..03c9a29 100644
--- a/other/example.conf
+++ b/other/example.conf
@@ -52,3 +52,56 @@ invert_stick_dpad_y = false
invert_pointer_x = false
invert_pointer_y = false
deadzone = 0.12
+
+[keyboard]
+
+# Key names: a-z, 0-9, up, down, left, right, space, enter, tab, escape,
+# backspace, delete, insert, home, end, page_up, page_down, caps_lock,
+# shift_left, shift_right, ctrl_left, ctrl_right, alt_left, alt_right,
+# super_left, super_right, minus, equal, comma, period, slash, semicolon,
+# quote, backquote, backslash, bracket_left, bracket_right, f1-f12,
+# numpad_0-numpad_9, numpad_enter, numpad_add, numpad_subtract,
+# numpad_multiply, numpad_divide, numpad_decimal
+
+[keyboard.gc]
+stick_up = "up"
+stick_down = "down"
+stick_left = "left"
+stick_right = "right"
+a = "x"
+b = "z"
+x = "c"
+y = "v"
+start = "enter"
+l = "a"
+r = "s"
+z = "d"
+dpad_up = "i"
+dpad_down = "k"
+dpad_left = "j"
+dpad_right = "l"
+
+[keyboard.wii]
+one = "1"
+two = "2"
+plus = "equal"
+minus = "minus"
+home = "home"
+dpad_up = "up"
+dpad_down = "down"
+dpad_left = "left"
+dpad_right = "right"
+shake = "shift_left"
+nunchuk_up = "w"
+nunchuk_down = "s"
+nunchuk_left = "a"
+nunchuk_right = "d"
+nunchuk_z = "q"
+nunchuk_c = "e"
+
+[keyboard.hotkeys]
+pause = "space"
+uncapped = "tab"
+fullscreen = "f10"
+overlay = "f11"
+screenshot = "f12"