Skip to content

Commit 5ca10f2

Browse files
committed
Merge branch 'dev'
2 parents 95ae254 + cd47328 commit 5ca10f2

8 files changed

Lines changed: 62 additions & 8 deletions

File tree

src/bin/ctl/commands.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ pub enum KeyboardAction {
9999
Remove {
100100
layout: String,
101101
},
102+
SwapEscape {
103+
enabled: bool,
104+
},
102105
}
103106

104107
#[derive(Debug, Clone, Subcommand)]
@@ -211,6 +214,11 @@ pub enum InputAction {
211214
#[arg(short, long)]
212215
identifier: Option<String>,
213216
},
217+
LeftHanded {
218+
state: String,
219+
#[arg(short, long)]
220+
identifier: Option<String>,
221+
},
214222
}
215223

216224
#[derive(Debug, Clone, Subcommand)]
@@ -442,6 +450,7 @@ pub fn command_to_ipc(command: CommandKind) -> IpcCommand {
442450
KeyboardCommand::Add(KeyboardLayout::from(arg))
443451
}
444452
KeyboardAction::Remove { layout } => KeyboardCommand::Remove(layout),
453+
KeyboardAction::SwapEscape { enabled } => KeyboardCommand::SwapEscape(enabled),
445454
};
446455
IpcCommand::Keyboard(cmd)
447456
}
@@ -506,6 +515,10 @@ pub fn command_to_ipc(command: CommandKind) -> IpcCommand {
506515
InputAction::ScrollFactor { identifier, value } => {
507516
InputCommand::ScrollFactor { identifier, value }
508517
}
518+
InputAction::LeftHanded { identifier, state } => InputCommand::LeftHanded {
519+
identifier,
520+
enabled: state == "enabled" || state == "on",
521+
},
509522
};
510523
IpcCommand::Input(cmd)
511524
}

src/config/config_toml.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ pub struct InputConfig {
162162
pub accel_profile: Option<AccelProfile>,
163163
pub pointer_accel: Option<f64>,
164164
pub scroll_factor: Option<f64>,
165+
pub left_handed: Option<ToggleSetting>,
165166
}
166167

167168
impl Default for InputConfig {
@@ -172,10 +173,22 @@ impl Default for InputConfig {
172173
accel_profile: None,
173174
pointer_accel: None,
174175
scroll_factor: None,
176+
left_handed: None,
175177
}
176178
}
177179
}
178180

181+
impl std::fmt::Display for InputConfig {
182+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
183+
writeln!(f, "tap: {:?}", self.tap)?;
184+
writeln!(f, "natural_scroll: {:?}", self.natural_scroll)?;
185+
writeln!(f, "accel_profile: {:?}", self.accel_profile)?;
186+
writeln!(f, "pointer_accel: {:?}", self.pointer_accel)?;
187+
writeln!(f, "scroll_factor: {:?}", self.scroll_factor)?;
188+
write!(f, "left_handed: {:?}", self.left_handed)
189+
}
190+
}
191+
179192
/// Keyboard (XKB) layout configuration from the TOML `[keyboard]` section.
180193
#[derive(Debug, Deserialize, Clone, Serialize, Default)]
181194
#[serde(default)]

src/ipc/input.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@ pub fn handle_input_command(wm: &mut Wm, cmd: InputCommand) -> Response {
3434
}
3535
let info: Vec<String> = entries
3636
.iter()
37-
.map(|(id, cfg)| {
38-
format!(
39-
"[{}]\ntap: {:?}\nnatural_scroll: {:?}\naccel_profile: {:?}\npointer_accel: {:?}\nscroll_factor: {:?}",
40-
id, cfg.tap, cfg.natural_scroll, cfg.accel_profile, cfg.pointer_accel, cfg.scroll_factor,
41-
)
42-
})
37+
.map(|(id, cfg)| format!("[{}]\n{}", id, cfg))
4338
.collect();
4439
return Response::Message(info.join("\n\n"));
4540
}
@@ -103,6 +98,18 @@ pub fn handle_input_command(wm: &mut Wm, cmd: InputCommand) -> Response {
10398
let cfg = inputs.entry(identifier).or_default();
10499
cfg.scroll_factor = Some(value);
105100
}
101+
InputCommand::LeftHanded {
102+
identifier,
103+
enabled,
104+
} => {
105+
let identifier = identifier.unwrap_or_else(|| "*".to_string());
106+
let cfg = inputs.entry(identifier).or_default();
107+
cfg.left_handed = Some(if enabled {
108+
ToggleSetting::Enabled
109+
} else {
110+
ToggleSetting::Disabled
111+
});
112+
}
106113
}
107114
wm.g.dirty.input_config = true;
108115
Response::ok()

src/ipc/keyboard.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,9 @@ pub fn handle_keyboard_command(wm: &mut Wm, cmd: KeyboardCommand) -> Response {
6363
Err(e) => Response::err(e),
6464
}
6565
}
66+
KeyboardCommand::SwapEscape(enabled) => {
67+
keyboard_layout::set_swapescape(&mut ctx, enabled);
68+
Response::ok()
69+
}
6670
}
6771
}

src/ipc/scratchpad.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::floating::scratchpad::{
2-
collect_scratchpad_info, scratchpad_hide_all, scratchpad_hide_name, scratchpad_make, scratchpad_show_all,
3-
scratchpad_show_name, scratchpad_toggle, scratchpad_unmake,
2+
collect_scratchpad_info, scratchpad_hide_all, scratchpad_hide_name, scratchpad_make,
3+
scratchpad_show_all, scratchpad_show_name, scratchpad_toggle, scratchpad_unmake,
44
};
55
use crate::ipc_types::{Response, ScratchpadCommand};
66
use crate::types::WindowId;

src/ipc_types.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ pub enum KeyboardCommand {
228228
Set(Vec<KeyboardLayout>),
229229
Add(KeyboardLayout),
230230
Remove(String),
231+
SwapEscape(bool),
231232
}
232233

233234
#[derive(Debug, Clone, Decode, Encode, serde::Serialize, serde::Deserialize)]
@@ -285,6 +286,10 @@ pub enum InputCommand {
285286
identifier: Option<String>,
286287
value: f64,
287288
},
289+
LeftHanded {
290+
identifier: Option<String>,
291+
enabled: bool,
292+
},
288293
}
289294

290295
#[derive(Debug, Clone, Decode, Encode, serde::Serialize, serde::Deserialize)]

src/keyboard_layout.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,14 @@ pub fn set_keyboard_layouts(ctx: &mut WmCtx, layouts: Vec<KeyboardLayout>) {
166166
}
167167
}
168168

169+
pub fn set_swapescape(ctx: &mut WmCtx, enabled: bool) {
170+
let current = ctx.core().globals().keyboard_layout.current;
171+
ctx.core_mut().globals_mut().keyboard_layout.swapescape = enabled;
172+
if !ctx.core().globals().keyboard_layout.layouts.is_empty() {
173+
set_keyboard_layout(ctx, current);
174+
}
175+
}
176+
169177
/// Apply the initially configured keyboard layout (called during startup).
170178
pub fn init_keyboard_layout(ctx: &mut WmCtx) {
171179
if !ctx.core().globals().keyboard_layout.layouts.is_empty() {

src/wayland/input/drm.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ pub fn configure_device(
125125
let _ = device.config_accel_set_speed(pointer_accel.clamp(-1.0, 1.0));
126126
}
127127

128+
if let Some(left_handed) = config.left_handed {
129+
let _ = device.config_left_handed_set(left_handed == ToggleSetting::Enabled);
130+
}
131+
128132
// scroll_factor is applied at the compositor level in the axis handler,
129133
// not via libinput. Nothing to do here for it.
130134
}

0 commit comments

Comments
 (0)