mirror of
https://github.com/YaLTeR/niri.git
synced 2024-08-17 08:11:00 +03:00
Compare commits
10 Commits
db6ad71673
...
8b13521f23
Author | SHA1 | Date | |
---|---|---|---|
|
8b13521f23 | ||
|
a283c34dbb | ||
|
3d6040ceab | ||
|
c498ffcc34 | ||
|
7bcb649d7a | ||
|
176de91342 | ||
|
13911640b0 | ||
|
5da2ad89dd | ||
|
f76b3bb794 | ||
|
b12396d8a1 |
@ -58,8 +58,8 @@ pub struct Config {
|
||||
|
||||
#[derive(knuffel::Decode, Debug, Default, PartialEq)]
|
||||
pub struct Input {
|
||||
#[knuffel(child, default)]
|
||||
pub keyboard: Keyboard,
|
||||
#[knuffel(children(name = "keyboard"), default)]
|
||||
pub keyboards: Vec<Keyboard>,
|
||||
#[knuffel(child, default)]
|
||||
pub touchpad: Touchpad,
|
||||
#[knuffel(child, default)]
|
||||
@ -80,8 +80,28 @@ pub struct Input {
|
||||
pub workspace_auto_back_and_forth: bool,
|
||||
}
|
||||
|
||||
#[derive(knuffel::Decode, Debug, PartialEq, Eq)]
|
||||
impl Input {
|
||||
pub fn fallback_keyboard(&self) -> Keyboard {
|
||||
self.keyboards
|
||||
.iter()
|
||||
.find(|keyboard| keyboard.name.is_none())
|
||||
.cloned()
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn keyboard_named<K: AsRef<str>>(&self, name: K) -> Keyboard {
|
||||
self.keyboards
|
||||
.iter()
|
||||
.find(|keyboard| keyboard.name.as_deref() == Some(name.as_ref()))
|
||||
.cloned()
|
||||
.unwrap_or_else(|| self.fallback_keyboard())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(knuffel::Decode, Debug, PartialEq, Eq, Clone)]
|
||||
pub struct Keyboard {
|
||||
#[knuffel(argument, unwrap(argument))]
|
||||
pub name: Option<String>,
|
||||
#[knuffel(child, default)]
|
||||
pub xkb: Xkb,
|
||||
// The defaults were chosen to match wlroots and sway.
|
||||
@ -96,6 +116,7 @@ pub struct Keyboard {
|
||||
impl Default for Keyboard {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
name: None,
|
||||
xkb: Default::default(),
|
||||
repeat_delay: 600,
|
||||
repeat_rate: 25,
|
||||
@ -142,7 +163,7 @@ pub enum CenterFocusedColumn {
|
||||
OnOverflow,
|
||||
}
|
||||
|
||||
#[derive(knuffel::DecodeScalar, Debug, Default, PartialEq, Eq)]
|
||||
#[derive(knuffel::DecodeScalar, Debug, Default, PartialEq, Eq, Clone)]
|
||||
pub enum TrackLayout {
|
||||
/// The layout change is global.
|
||||
#[default]
|
||||
@ -995,6 +1016,8 @@ pub enum Action {
|
||||
MoveColumnRight,
|
||||
MoveColumnToFirst,
|
||||
MoveColumnToLast,
|
||||
MoveColumnLeftOrToMonitorLeft,
|
||||
MoveColumnRightOrToMonitorRight,
|
||||
MoveWindowDown,
|
||||
MoveWindowUp,
|
||||
MoveWindowDownOrToWorkspaceDown,
|
||||
@ -1075,6 +1098,10 @@ impl From<niri_ipc::Action> for Action {
|
||||
niri_ipc::Action::MoveColumnRight => Self::MoveColumnRight,
|
||||
niri_ipc::Action::MoveColumnToFirst => Self::MoveColumnToFirst,
|
||||
niri_ipc::Action::MoveColumnToLast => Self::MoveColumnToLast,
|
||||
niri_ipc::Action::MoveColumnLeftOrToMonitorLeft => Self::MoveColumnLeftOrToMonitorLeft,
|
||||
niri_ipc::Action::MoveColumnRightOrToMonitorRight => {
|
||||
Self::MoveColumnRightOrToMonitorRight
|
||||
}
|
||||
niri_ipc::Action::MoveWindowDown => Self::MoveWindowDown,
|
||||
niri_ipc::Action::MoveWindowUp => Self::MoveWindowUp,
|
||||
niri_ipc::Action::MoveWindowDownOrToWorkspaceDown => {
|
||||
@ -2522,6 +2549,16 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
keyboard "test_keyboard" {
|
||||
repeat-delay 500
|
||||
repeat-rate 30
|
||||
track-layout "window"
|
||||
xkb {
|
||||
layout "us,ru"
|
||||
options "grp:win_space_toggle"
|
||||
}
|
||||
}
|
||||
|
||||
touchpad {
|
||||
tap
|
||||
dwt
|
||||
@ -2684,16 +2721,30 @@ mod tests {
|
||||
"##,
|
||||
Config {
|
||||
input: Input {
|
||||
keyboard: Keyboard {
|
||||
xkb: Xkb {
|
||||
layout: "us,ru".to_owned(),
|
||||
options: Some("grp:win_space_toggle".to_owned()),
|
||||
keyboards: vec![
|
||||
Keyboard {
|
||||
xkb: Xkb {
|
||||
layout: "us,ru".to_owned(),
|
||||
options: Some("grp:win_space_toggle".to_owned()),
|
||||
..Default::default()
|
||||
},
|
||||
repeat_delay: 600,
|
||||
repeat_rate: 25,
|
||||
track_layout: TrackLayout::Window,
|
||||
..Default::default()
|
||||
},
|
||||
repeat_delay: 600,
|
||||
repeat_rate: 25,
|
||||
track_layout: TrackLayout::Window,
|
||||
},
|
||||
Keyboard {
|
||||
xkb: Xkb {
|
||||
layout: "us,ru".to_owned(),
|
||||
options: Some("grp:win_space_toggle".to_owned()),
|
||||
..Default::default()
|
||||
},
|
||||
repeat_delay: 500,
|
||||
repeat_rate: 30,
|
||||
track_layout: TrackLayout::Window,
|
||||
name: Some("test_keyboard".to_owned()),
|
||||
},
|
||||
],
|
||||
touchpad: Touchpad {
|
||||
off: false,
|
||||
tap: true,
|
||||
@ -3100,7 +3151,7 @@ mod tests {
|
||||
#[test]
|
||||
fn default_repeat_params() {
|
||||
let config = Config::parse("config.kdl", "").unwrap();
|
||||
assert_eq!(config.input.keyboard.repeat_delay, 600);
|
||||
assert_eq!(config.input.keyboard.repeat_rate, 25);
|
||||
assert_eq!(config.input.fallback_keyboard().repeat_delay, 600);
|
||||
assert_eq!(config.input.fallback_keyboard().repeat_rate, 25);
|
||||
}
|
||||
}
|
||||
|
@ -152,6 +152,10 @@ pub enum Action {
|
||||
MoveColumnToFirst,
|
||||
/// Move the focused column to the end of the workspace.
|
||||
MoveColumnToLast,
|
||||
/// Move the focused column to the left or to the monitor to the left.
|
||||
MoveColumnLeftOrToMonitorLeft,
|
||||
/// Move the focused column to the right or to the monitor to the right.
|
||||
MoveColumnRightOrToMonitorRight,
|
||||
/// Move the focused window down in a column.
|
||||
MoveWindowDown,
|
||||
/// Move the focused window up in a column.
|
||||
|
@ -287,7 +287,12 @@ impl State {
|
||||
Some(pos + target_geo.loc.to_f64())
|
||||
}
|
||||
|
||||
fn on_keyboard<I: InputBackend>(&mut self, event: I::KeyboardKeyEvent) {
|
||||
fn on_keyboard<I: InputBackend>(&mut self, event: I::KeyboardKeyEvent)
|
||||
where
|
||||
I::Device: 'static,
|
||||
{
|
||||
self.apply_keyboard_config::<I>(&event);
|
||||
|
||||
let comp_mod = self.backend.mod_key();
|
||||
|
||||
let serial = SERIAL_COUNTER.next_serial();
|
||||
@ -383,6 +388,57 @@ impl State {
|
||||
self.niri.bind_repeat_timer = Some(token);
|
||||
}
|
||||
|
||||
fn apply_keyboard_config<I: InputBackend>(&mut self, event: &I::KeyboardKeyEvent)
|
||||
where
|
||||
I::Device: 'static,
|
||||
{
|
||||
let device = event.device();
|
||||
|
||||
let keyboard_config =
|
||||
if let Some(input_device) = (&device as &dyn Any).downcast_ref::<input::Device>() {
|
||||
if let Some(cached) = self.niri.keyboard_device_cache.get(input_device).cloned() {
|
||||
cached
|
||||
} else {
|
||||
let keyboard_config = self
|
||||
.niri
|
||||
.config
|
||||
.borrow()
|
||||
.input
|
||||
.keyboard_named(device.name());
|
||||
|
||||
self.niri
|
||||
.keyboard_device_cache
|
||||
.insert(input_device.clone(), keyboard_config.clone());
|
||||
|
||||
keyboard_config
|
||||
}
|
||||
} else {
|
||||
self.niri.config.borrow().input.fallback_keyboard()
|
||||
};
|
||||
|
||||
if keyboard_config != self.niri.current_keyboard {
|
||||
let keyboard = self.niri.seat.get_keyboard().unwrap();
|
||||
|
||||
if keyboard_config.xkb != self.niri.current_keyboard.xkb {
|
||||
if let Err(err) = keyboard.set_xkb_config(self, keyboard_config.xkb.to_xkb_config())
|
||||
{
|
||||
warn!("error updating xkb config: {err:?}");
|
||||
}
|
||||
}
|
||||
|
||||
if keyboard_config.repeat_rate != self.niri.current_keyboard.repeat_rate
|
||||
|| keyboard_config.repeat_delay != self.niri.current_keyboard.repeat_delay
|
||||
{
|
||||
keyboard.change_repeat_info(
|
||||
keyboard_config.repeat_rate.into(),
|
||||
keyboard_config.repeat_delay.into(),
|
||||
);
|
||||
}
|
||||
|
||||
self.niri.current_keyboard = keyboard_config;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_bind(&mut self, bind: Bind) {
|
||||
let Some(cooldown) = bind.cooldown else {
|
||||
self.do_action(bind.action, bind.allow_when_locked);
|
||||
@ -571,6 +627,40 @@ impl State {
|
||||
// FIXME: granular
|
||||
self.niri.queue_redraw_all();
|
||||
}
|
||||
Action::MoveColumnLeftOrToMonitorLeft => {
|
||||
if let Some(output) = self.niri.output_left() {
|
||||
if self.niri.layout.move_column_left_or_to_output(&output)
|
||||
&& !self.maybe_warp_cursor_to_focus_centered()
|
||||
{
|
||||
self.move_cursor_to_output(&output);
|
||||
} else {
|
||||
self.maybe_warp_cursor_to_focus();
|
||||
}
|
||||
} else {
|
||||
self.niri.layout.move_left();
|
||||
self.maybe_warp_cursor_to_focus();
|
||||
}
|
||||
|
||||
// FIXME: granular
|
||||
self.niri.queue_redraw_all();
|
||||
}
|
||||
Action::MoveColumnRightOrToMonitorRight => {
|
||||
if let Some(output) = self.niri.output_right() {
|
||||
if self.niri.layout.move_column_right_or_to_output(&output)
|
||||
&& !self.maybe_warp_cursor_to_focus_centered()
|
||||
{
|
||||
self.move_cursor_to_output(&output);
|
||||
} else {
|
||||
self.maybe_warp_cursor_to_focus();
|
||||
}
|
||||
} else {
|
||||
self.niri.layout.move_right();
|
||||
self.maybe_warp_cursor_to_focus();
|
||||
}
|
||||
|
||||
// FIXME: granular
|
||||
self.niri.queue_redraw_all();
|
||||
}
|
||||
Action::MoveWindowDown => {
|
||||
self.niri.layout.move_down();
|
||||
self.maybe_warp_cursor_to_focus();
|
||||
|
@ -1196,6 +1196,36 @@ impl<W: LayoutElement> Layout<W> {
|
||||
monitor.move_column_to_last();
|
||||
}
|
||||
|
||||
pub fn move_column_left_or_to_output(&mut self, output: &Output) -> bool {
|
||||
if let Some(monitor) = self.active_monitor() {
|
||||
let workspace = monitor.active_workspace();
|
||||
let curr_idx = workspace.active_column_idx;
|
||||
|
||||
if !workspace.columns.is_empty() && curr_idx != 0 {
|
||||
monitor.move_left();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
self.move_column_to_output(output);
|
||||
true
|
||||
}
|
||||
|
||||
pub fn move_column_right_or_to_output(&mut self, output: &Output) -> bool {
|
||||
if let Some(monitor) = self.active_monitor() {
|
||||
let workspace = monitor.active_workspace();
|
||||
let curr_idx = workspace.active_column_idx;
|
||||
|
||||
if !workspace.columns.is_empty() && curr_idx != workspace.columns.len() - 1 {
|
||||
monitor.move_right();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
self.move_column_to_output(output);
|
||||
true
|
||||
}
|
||||
|
||||
pub fn move_down(&mut self) {
|
||||
let Some(monitor) = self.active_monitor() else {
|
||||
return;
|
||||
@ -2797,6 +2827,8 @@ mod tests {
|
||||
MoveColumnRight,
|
||||
MoveColumnToFirst,
|
||||
MoveColumnToLast,
|
||||
MoveColumnLeftOrToMonitorLeft(#[proptest(strategy = "1..=2u8")] u8),
|
||||
MoveColumnRightOrToMonitorRight(#[proptest(strategy = "1..=2u8")] u8),
|
||||
MoveWindowDown,
|
||||
MoveWindowUp,
|
||||
MoveWindowDownOrToWorkspaceDown,
|
||||
@ -3154,6 +3186,22 @@ mod tests {
|
||||
Op::MoveColumnRight => layout.move_right(),
|
||||
Op::MoveColumnToFirst => layout.move_column_to_first(),
|
||||
Op::MoveColumnToLast => layout.move_column_to_last(),
|
||||
Op::MoveColumnLeftOrToMonitorLeft(id) => {
|
||||
let name = format!("output{id}");
|
||||
let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
|
||||
return;
|
||||
};
|
||||
|
||||
layout.move_column_left_or_to_output(&output);
|
||||
}
|
||||
Op::MoveColumnRightOrToMonitorRight(id) => {
|
||||
let name = format!("output{id}");
|
||||
let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
|
||||
return;
|
||||
};
|
||||
|
||||
layout.move_column_right_or_to_output(&output);
|
||||
}
|
||||
Op::MoveWindowDown => layout.move_down(),
|
||||
Op::MoveWindowUp => layout.move_up(),
|
||||
Op::MoveWindowDownOrToWorkspaceDown => layout.move_down_or_to_workspace_down(),
|
||||
@ -3384,6 +3432,8 @@ mod tests {
|
||||
Op::FocusWindowOrWorkspaceDown,
|
||||
Op::MoveColumnLeft,
|
||||
Op::MoveColumnRight,
|
||||
Op::MoveColumnLeftOrToMonitorLeft(0),
|
||||
Op::MoveColumnRightOrToMonitorRight(1),
|
||||
Op::ConsumeWindowIntoColumn,
|
||||
Op::ExpelWindowFromColumn,
|
||||
Op::CenterColumn,
|
||||
@ -3563,6 +3613,8 @@ mod tests {
|
||||
Op::FocusWindowOrWorkspaceDown,
|
||||
Op::MoveColumnLeft,
|
||||
Op::MoveColumnRight,
|
||||
Op::MoveColumnLeftOrToMonitorLeft(0),
|
||||
Op::MoveColumnRightOrToMonitorRight(1),
|
||||
Op::ConsumeWindowIntoColumn,
|
||||
Op::ExpelWindowFromColumn,
|
||||
Op::CenterColumn,
|
||||
|
28
src/niri.rs
28
src/niri.rs
@ -191,7 +191,9 @@ pub struct Niri {
|
||||
// When false, we're idling with monitors powered off.
|
||||
pub monitors_active: bool,
|
||||
|
||||
pub current_keyboard: niri_config::Keyboard,
|
||||
pub devices: HashSet<input::Device>,
|
||||
pub keyboard_device_cache: HashMap<input::Device, niri_config::Keyboard>,
|
||||
pub tablets: HashMap<input::Device, TabletData>,
|
||||
pub touch: HashSet<input::Device>,
|
||||
|
||||
@ -855,7 +857,7 @@ impl State {
|
||||
}
|
||||
}
|
||||
|
||||
if self.niri.config.borrow().input.keyboard.track_layout == TrackLayout::Window {
|
||||
if self.niri.current_keyboard.track_layout == TrackLayout::Window {
|
||||
let current_layout =
|
||||
keyboard.with_xkb_state(self, |context| context.active_layout());
|
||||
|
||||
@ -955,19 +957,23 @@ impl State {
|
||||
self.niri.cursor_texture_cache.clear();
|
||||
}
|
||||
|
||||
let default_keyboard = config.input.fallback_keyboard();
|
||||
|
||||
let current_keyboard = self.niri.current_keyboard.clone();
|
||||
|
||||
// We need &mut self to reload the xkb config, so just store it here.
|
||||
if config.input.keyboard.xkb != old_config.input.keyboard.xkb {
|
||||
reload_xkb = Some(config.input.keyboard.xkb.clone());
|
||||
if default_keyboard.xkb != current_keyboard.xkb {
|
||||
reload_xkb = Some(default_keyboard.xkb.clone());
|
||||
}
|
||||
|
||||
// Reload the repeat info.
|
||||
if config.input.keyboard.repeat_rate != old_config.input.keyboard.repeat_rate
|
||||
|| config.input.keyboard.repeat_delay != old_config.input.keyboard.repeat_delay
|
||||
if default_keyboard.repeat_rate != current_keyboard.repeat_rate
|
||||
|| default_keyboard.repeat_delay != current_keyboard.repeat_delay
|
||||
{
|
||||
let keyboard = self.niri.seat.get_keyboard().unwrap();
|
||||
keyboard.change_repeat_info(
|
||||
config.input.keyboard.repeat_rate.into(),
|
||||
config.input.keyboard.repeat_delay.into(),
|
||||
default_keyboard.repeat_rate.into(),
|
||||
default_keyboard.repeat_delay.into(),
|
||||
);
|
||||
}
|
||||
|
||||
@ -1574,9 +1580,9 @@ impl Niri {
|
||||
|
||||
let mut seat: Seat<State> = seat_state.new_wl_seat(&display_handle, backend.seat_name());
|
||||
seat.add_keyboard(
|
||||
config_.input.keyboard.xkb.to_xkb_config(),
|
||||
config_.input.keyboard.repeat_delay.into(),
|
||||
config_.input.keyboard.repeat_rate.into(),
|
||||
config_.input.fallback_keyboard().xkb.to_xkb_config(),
|
||||
config_.input.fallback_keyboard().repeat_delay.into(),
|
||||
config_.input.fallback_keyboard().repeat_rate.into(),
|
||||
)
|
||||
.unwrap();
|
||||
seat.add_pointer();
|
||||
@ -1692,7 +1698,9 @@ impl Niri {
|
||||
root_surface: HashMap::new(),
|
||||
monitors_active: true,
|
||||
|
||||
current_keyboard: Default::default(),
|
||||
devices: HashSet::new(),
|
||||
keyboard_device_cache: HashMap::new(),
|
||||
tablets: HashMap::new(),
|
||||
touch: HashSet::new(),
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user