From 2a13e736e4792a8b1fb0cca202f2d3e97e42dba0 Mon Sep 17 00:00:00 2001 From: Ottatop Date: Thu, 28 Sep 2023 10:17:28 -0500 Subject: [PATCH] Add xkbconfig to API --- api/lua/input.lua | 26 ++++++++++++++++++++++++++ api/lua/msg.lua | 4 +++- src/config/api/msg.rs | 14 ++++++++++++++ src/state/api_handlers.rs | 22 ++++++++++++++++++++++ 4 files changed, 65 insertions(+), 1 deletion(-) diff --git a/api/lua/input.lua b/api/lua/input.lua index 599b891..bbe9914 100644 --- a/api/lua/input.lua +++ b/api/lua/input.lua @@ -26,6 +26,13 @@ local buttons = { back = 0x116, } +---@class XkbConfig +---@field rules string? +---@field model string? +---@field layout string? +---@field variant string? +---@field options string? + ---Input management. --- ---This module provides utilities to set keybinds. @@ -114,4 +121,23 @@ function input_module.mousebind(modifiers, button, edge, action) }) end +---Set the xkbconfig for your input device. +--- +---Fields not present will be set to their default values. +--- +---### Example +---```lua +---input.set_xkb_config({ +--- layout = "us,fr,ge", +--- options = "ctrl:swapcaps,caps:shift" +---}) +---``` +--- +---@param xkb_config XkbConfig +function input_module.set_xkb_config(xkb_config) + SendMsg({ + SetXkbConfig = xkb_config, + }) +end + return input_module diff --git a/api/lua/msg.lua b/api/lua/msg.lua index d3b0a14..982944f 100644 --- a/api/lua/msg.lua +++ b/api/lua/msg.lua @@ -19,7 +19,6 @@ -- ---@field Spawn { command: string[], callback_id: integer? }? ---@field SetEnv { key: string, value: string }? ----@field Request Request? --Tags ---@field ToggleTag { tag_id: TagId }? ---@field SwitchToTag { tag_id: TagId }? @@ -29,6 +28,9 @@ --Outputs ---@field ConnectForAllOutputs { callback_id: integer }? ---@field SetOutputLocation { output_name: OutputName, x: integer?, y: integer? }? +--Input +---@field SetXkbConfig XkbConfig? +---@field Request Request? ---@alias Msg _Msg | "Quit" diff --git a/src/config/api/msg.rs b/src/config/api/msg.rs index 11ef8c3..96a1ff2 100644 --- a/src/config/api/msg.rs +++ b/src/config/api/msg.rs @@ -134,6 +134,20 @@ pub enum Msg { /// Quit the compositor. Quit, + // Input management + SetXkbConfig { + #[serde(default)] + rules: Option, + #[serde(default)] + variant: Option, + #[serde(default)] + layout: Option, + #[serde(default)] + model: Option, + #[serde(default)] + options: Option, + }, + Request { request_id: RequestId, request: Request, diff --git a/src/state/api_handlers.rs b/src/state/api_handlers.rs index e90dcc2..406e09b 100644 --- a/src/state/api_handlers.rs +++ b/src/state/api_handlers.rs @@ -4,6 +4,7 @@ use async_process::Stdio; use futures_lite::AsyncBufReadExt; use smithay::{ desktop::space::SpaceElement, + input::keyboard::XkbConfig, reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::ResizeEdge, utils::{Point, Rectangle, SERIAL_COUNTER}, wayland::{compositor, shell::xdg::XdgToplevelSurfaceData}, @@ -349,6 +350,27 @@ impl State { self.loop_signal.stop(); } + Msg::SetXkbConfig { + rules, + variant, + layout, + model, + options, + } => { + let new_config = XkbConfig { + rules: &rules.unwrap_or_default(), + model: &model.unwrap_or_default(), + layout: &layout.unwrap_or_default(), + variant: &variant.unwrap_or_default(), + options, + }; + if let Some(kb) = self.seat.get_keyboard() { + if let Err(err) = kb.set_xkb_config(self, new_config) { + tracing::error!("Failed to set xkbconfig: {err}"); + } + } + } + Msg::Request { request_id, request,