mirror of
https://github.com/YaLTeR/niri.git
synced 2024-09-11 20:37:25 +03:00
Compare commits
3 Commits
09f3f98cbc
...
008601a5ee
Author | SHA1 | Date | |
---|---|---|---|
|
008601a5ee | ||
|
519611c6c8 | ||
|
65ebd4c8aa |
42
Cargo.lock
generated
42
Cargo.lock
generated
@ -985,6 +985,12 @@ dependencies = [
|
||||
"linux-raw-sys 0.6.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dyn-clone"
|
||||
version = "1.0.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125"
|
||||
|
||||
[[package]]
|
||||
name = "edid-rs"
|
||||
version = "0.1.0"
|
||||
@ -2294,6 +2300,7 @@ name = "niri-ipc"
|
||||
version = "0.1.7"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"schemars",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
@ -3307,6 +3314,30 @@ version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b53b0a5db882a8e2fdaae0a43f7b39e7e9082389e978398bdf223a55b581248"
|
||||
|
||||
[[package]]
|
||||
name = "schemars"
|
||||
version = "0.8.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09c024468a378b7e36765cd36702b7a90cc3cba11654f6685c8f233408e89e92"
|
||||
dependencies = [
|
||||
"dyn-clone",
|
||||
"schemars_derive",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "schemars_derive"
|
||||
version = "0.8.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b1eee588578aff73f856ab961cd2f79e36bc45d7ded33a7562adba4667aecc0e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"serde_derive_internals",
|
||||
"syn 2.0.67",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "scoped-tls"
|
||||
version = "1.0.1"
|
||||
@ -3345,6 +3376,17 @@ dependencies = [
|
||||
"syn 2.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive_internals"
|
||||
version = "0.29.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.67",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.120"
|
||||
|
@ -48,8 +48,8 @@ pub struct Config {
|
||||
pub environment: Environment,
|
||||
#[knuffel(children(name = "window-rule"))]
|
||||
pub window_rules: Vec<WindowRule>,
|
||||
#[knuffel(child, default)]
|
||||
pub binds: Binds,
|
||||
#[knuffel(children(name = "binds"))]
|
||||
pub binds: Vec<Binds>,
|
||||
#[knuffel(child, default)]
|
||||
pub debug: DebugConfig,
|
||||
#[knuffel(children(name = "workspace"))]
|
||||
@ -906,8 +906,8 @@ pub struct BorderRule {
|
||||
pub inactive_gradient: Option<Gradient>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, PartialEq)]
|
||||
pub struct Binds(pub Vec<Bind>);
|
||||
#[derive(Debug, Default, PartialEq, Clone)]
|
||||
pub struct Binds(pub String, pub Vec<Bind>);
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Bind {
|
||||
@ -1041,6 +1041,7 @@ pub enum Action {
|
||||
MoveWorkspaceToMonitorRight,
|
||||
MoveWorkspaceToMonitorDown,
|
||||
MoveWorkspaceToMonitorUp,
|
||||
BindingMode(#[knuffel(argument, str)] String),
|
||||
}
|
||||
|
||||
impl From<niri_ipc::Action> for Action {
|
||||
@ -2193,7 +2194,11 @@ where
|
||||
node: &knuffel::ast::SpannedNode<S>,
|
||||
ctx: &mut knuffel::decode::Context<S>,
|
||||
) -> Result<Self, DecodeError<S>> {
|
||||
expect_only_children(node, ctx);
|
||||
let mode_name = node
|
||||
.arguments
|
||||
.first()
|
||||
.map(|e| knuffel::DecodeScalar::decode(e, ctx))
|
||||
.unwrap_or_else(|| Ok(String::from("default")))?;
|
||||
|
||||
let mut seen_keys = HashSet::new();
|
||||
|
||||
@ -2243,7 +2248,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Self(binds))
|
||||
Ok(Self(mode_name, binds))
|
||||
}
|
||||
}
|
||||
|
||||
@ -2921,100 +2926,105 @@ mod tests {
|
||||
open_on_output: None,
|
||||
},
|
||||
],
|
||||
binds: Binds(vec![
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(Keysym::t),
|
||||
modifiers: Modifiers::COMPOSITOR,
|
||||
binds: vec![Binds(
|
||||
"default".to_string(),
|
||||
vec![
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(Keysym::t),
|
||||
modifiers: Modifiers::COMPOSITOR,
|
||||
},
|
||||
action: Action::Spawn(vec!["alacritty".to_owned()]),
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: true,
|
||||
},
|
||||
action: Action::Spawn(vec!["alacritty".to_owned()]),
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: true,
|
||||
},
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(Keysym::q),
|
||||
modifiers: Modifiers::COMPOSITOR,
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(Keysym::q),
|
||||
modifiers: Modifiers::COMPOSITOR,
|
||||
},
|
||||
action: Action::CloseWindow,
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
},
|
||||
action: Action::CloseWindow,
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
},
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(Keysym::h),
|
||||
modifiers: Modifiers::COMPOSITOR | Modifiers::SHIFT,
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(Keysym::h),
|
||||
modifiers: Modifiers::COMPOSITOR | Modifiers::SHIFT,
|
||||
},
|
||||
action: Action::FocusMonitorLeft,
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
},
|
||||
action: Action::FocusMonitorLeft,
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
},
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(Keysym::l),
|
||||
modifiers: Modifiers::COMPOSITOR | Modifiers::SHIFT | Modifiers::CTRL,
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(Keysym::l),
|
||||
modifiers: Modifiers::COMPOSITOR
|
||||
| Modifiers::SHIFT
|
||||
| Modifiers::CTRL,
|
||||
},
|
||||
action: Action::MoveWindowToMonitorRight,
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
},
|
||||
action: Action::MoveWindowToMonitorRight,
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
},
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(Keysym::comma),
|
||||
modifiers: Modifiers::COMPOSITOR,
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(Keysym::comma),
|
||||
modifiers: Modifiers::COMPOSITOR,
|
||||
},
|
||||
action: Action::ConsumeWindowIntoColumn,
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
},
|
||||
action: Action::ConsumeWindowIntoColumn,
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
},
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(Keysym::_1),
|
||||
modifiers: Modifiers::COMPOSITOR,
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(Keysym::_1),
|
||||
modifiers: Modifiers::COMPOSITOR,
|
||||
},
|
||||
action: Action::FocusWorkspace(WorkspaceReference::Index(1)),
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
},
|
||||
action: Action::FocusWorkspace(WorkspaceReference::Index(1)),
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
},
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(Keysym::_1),
|
||||
modifiers: Modifiers::COMPOSITOR | Modifiers::SHIFT,
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(Keysym::_1),
|
||||
modifiers: Modifiers::COMPOSITOR | Modifiers::SHIFT,
|
||||
},
|
||||
action: Action::FocusWorkspace(WorkspaceReference::Name(
|
||||
"workspace-1".to_string(),
|
||||
)),
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
},
|
||||
action: Action::FocusWorkspace(WorkspaceReference::Name(
|
||||
"workspace-1".to_string(),
|
||||
)),
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
},
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(Keysym::e),
|
||||
modifiers: Modifiers::COMPOSITOR | Modifiers::SHIFT,
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(Keysym::e),
|
||||
modifiers: Modifiers::COMPOSITOR | Modifiers::SHIFT,
|
||||
},
|
||||
action: Action::Quit(true),
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
},
|
||||
action: Action::Quit(true),
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
},
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::WheelScrollDown,
|
||||
modifiers: Modifiers::COMPOSITOR,
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::WheelScrollDown,
|
||||
modifiers: Modifiers::COMPOSITOR,
|
||||
},
|
||||
action: Action::FocusWorkspaceDown,
|
||||
repeat: true,
|
||||
cooldown: Some(Duration::from_millis(150)),
|
||||
allow_when_locked: false,
|
||||
},
|
||||
action: Action::FocusWorkspaceDown,
|
||||
repeat: true,
|
||||
cooldown: Some(Duration::from_millis(150)),
|
||||
allow_when_locked: false,
|
||||
},
|
||||
]),
|
||||
],
|
||||
)],
|
||||
debug: DebugConfig {
|
||||
render_drm_device: Some(PathBuf::from("/dev/dri/renderD129")),
|
||||
..Default::default()
|
||||
@ -3109,4 +3119,20 @@ mod tests {
|
||||
assert_eq!(config.input.keyboard.repeat_delay, 600);
|
||||
assert_eq!(config.input.keyboard.repeat_rate, 25);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn binding_modes() {
|
||||
Config::parse(
|
||||
"",
|
||||
r##"
|
||||
binds {
|
||||
A { binding-mode "test"; }
|
||||
}
|
||||
binds "test" {
|
||||
B { binding-mode "default"; }
|
||||
}
|
||||
"##,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,10 @@ repository.workspace = true
|
||||
|
||||
[dependencies]
|
||||
clap = { workspace = true, optional = true }
|
||||
schemars = { version = "0.8.21", optional = true }
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
|
||||
[features]
|
||||
clap = ["dep:clap"]
|
||||
json-schema = ["dep:schemars"]
|
||||
|
@ -11,6 +11,7 @@ pub use socket::{Socket, SOCKET_PATH_ENV};
|
||||
|
||||
/// Request from client to niri.
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub enum Request {
|
||||
/// Request the version string for the running niri instance.
|
||||
Version,
|
||||
@ -37,6 +38,8 @@ pub enum Request {
|
||||
FocusedOutput,
|
||||
/// Respond with an error (for testing error handling).
|
||||
ReturnError,
|
||||
/// Request name of the current binding mode.
|
||||
BindingMode,
|
||||
}
|
||||
|
||||
/// Reply from niri to client.
|
||||
@ -51,6 +54,7 @@ pub type Reply = Result<Response, String>;
|
||||
|
||||
/// Successful response from niri to client.
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub enum Response {
|
||||
/// A request that does not need a response was handled successfully.
|
||||
Handled,
|
||||
@ -68,6 +72,8 @@ pub enum Response {
|
||||
Workspaces(Vec<Workspace>),
|
||||
/// Information about the focused output.
|
||||
FocusedOutput(Option<Output>),
|
||||
/// Name of the current binding mode.
|
||||
BindingMode(String),
|
||||
}
|
||||
|
||||
/// Actions that niri can perform.
|
||||
@ -77,6 +83,7 @@ pub enum Response {
|
||||
#[cfg_attr(feature = "clap", derive(clap::Parser))]
|
||||
#[cfg_attr(feature = "clap", command(subcommand_value_name = "ACTION"))]
|
||||
#[cfg_attr(feature = "clap", command(subcommand_help_heading = "Actions"))]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub enum Action {
|
||||
/// Exit niri.
|
||||
Quit {
|
||||
@ -278,6 +285,7 @@ pub enum Action {
|
||||
|
||||
/// Change in window or column size.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub enum SizeChange {
|
||||
/// Set the size in logical pixels.
|
||||
SetFixed(i32),
|
||||
@ -291,6 +299,7 @@ pub enum SizeChange {
|
||||
|
||||
/// Workspace reference (index or name) to operate on.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub enum WorkspaceReferenceArg {
|
||||
/// Index of the workspace.
|
||||
Index(u8),
|
||||
@ -300,6 +309,7 @@ pub enum WorkspaceReferenceArg {
|
||||
|
||||
/// Layout to switch to.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub enum LayoutSwitchTarget {
|
||||
/// The next configured layout.
|
||||
Next,
|
||||
@ -314,6 +324,7 @@ pub enum LayoutSwitchTarget {
|
||||
#[cfg_attr(feature = "clap", derive(clap::Parser))]
|
||||
#[cfg_attr(feature = "clap", command(subcommand_value_name = "ACTION"))]
|
||||
#[cfg_attr(feature = "clap", command(subcommand_help_heading = "Actions"))]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub enum OutputAction {
|
||||
/// Turn off the output.
|
||||
Off,
|
||||
@ -362,6 +373,7 @@ pub enum OutputAction {
|
||||
|
||||
/// Output mode to set.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub enum ModeToSet {
|
||||
/// Niri will pick the mode automatically.
|
||||
Automatic,
|
||||
@ -371,6 +383,7 @@ pub enum ModeToSet {
|
||||
|
||||
/// Output mode as set in the config file.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub struct ConfiguredMode {
|
||||
/// Width in physical pixels.
|
||||
pub width: u16,
|
||||
@ -382,6 +395,7 @@ pub struct ConfiguredMode {
|
||||
|
||||
/// Output scale to set.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub enum ScaleToSet {
|
||||
/// Niri will pick the scale automatically.
|
||||
Automatic,
|
||||
@ -394,6 +408,7 @@ pub enum ScaleToSet {
|
||||
#[cfg_attr(feature = "clap", derive(clap::Subcommand))]
|
||||
#[cfg_attr(feature = "clap", command(subcommand_value_name = "POSITION"))]
|
||||
#[cfg_attr(feature = "clap", command(subcommand_help_heading = "Position Values"))]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub enum PositionToSet {
|
||||
/// Position the output automatically.
|
||||
#[cfg_attr(feature = "clap", command(name = "auto"))]
|
||||
@ -406,6 +421,7 @@ pub enum PositionToSet {
|
||||
/// Output position as set in the config file.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
|
||||
#[cfg_attr(feature = "clap", derive(clap::Args))]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub struct ConfiguredPosition {
|
||||
/// Logical X position.
|
||||
pub x: i32,
|
||||
@ -415,6 +431,7 @@ pub struct ConfiguredPosition {
|
||||
|
||||
/// Connected output.
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub struct Output {
|
||||
/// Name of the output.
|
||||
pub name: String,
|
||||
@ -442,6 +459,7 @@ pub struct Output {
|
||||
|
||||
/// Output mode.
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub struct Mode {
|
||||
/// Width in physical pixels.
|
||||
pub width: u16,
|
||||
@ -455,6 +473,7 @@ pub struct Mode {
|
||||
|
||||
/// Logical output in the compositor's coordinate space.
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub struct LogicalOutput {
|
||||
/// Logical X position.
|
||||
pub x: i32,
|
||||
@ -473,6 +492,7 @@ pub struct LogicalOutput {
|
||||
/// Output transform, which goes counter-clockwise.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub enum Transform {
|
||||
/// Untransformed.
|
||||
Normal,
|
||||
@ -500,6 +520,7 @@ pub enum Transform {
|
||||
|
||||
/// Toplevel window.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub struct Window {
|
||||
/// Title, if set.
|
||||
pub title: Option<String>,
|
||||
@ -509,6 +530,7 @@ pub struct Window {
|
||||
|
||||
/// Output configuration change result.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub enum OutputConfigChanged {
|
||||
/// The target output was connected and the change was applied.
|
||||
Applied,
|
||||
@ -518,6 +540,7 @@ pub enum OutputConfigChanged {
|
||||
|
||||
/// A workspace.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub struct Workspace {
|
||||
/// Index of the workspace on its monitor.
|
||||
///
|
||||
|
@ -90,4 +90,6 @@ pub enum Msg {
|
||||
Version,
|
||||
/// Request an error from the running niri instance.
|
||||
RequestError,
|
||||
/// Get the binding mode name.
|
||||
BindingMode,
|
||||
}
|
||||
|
157
src/input/mod.rs
157
src/input/mod.rs
@ -314,7 +314,7 @@ impl State {
|
||||
serial,
|
||||
time,
|
||||
|this, mods, keysym| {
|
||||
let bindings = &this.niri.config.borrow().binds;
|
||||
let bindings = &this.niri.binding_mode;
|
||||
let key_code = event.key_code();
|
||||
let modified = keysym.modified_sym();
|
||||
let raw = keysym.raw_latin_sym_or_raw_current_sym();
|
||||
@ -1077,6 +1077,11 @@ impl State {
|
||||
}
|
||||
}
|
||||
}
|
||||
Action::BindingMode(name) => {
|
||||
if let Some(mode) = self.niri.config.borrow().binds.iter().find(|e| e.0 == name) {
|
||||
self.niri.binding_mode = mode.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1500,13 +1505,11 @@ impl State {
|
||||
let horizontal = horizontal_amount_v120.unwrap_or(0.);
|
||||
let ticks = self.niri.horizontal_wheel_tracker.accumulate(horizontal);
|
||||
if ticks != 0 {
|
||||
let config = self.niri.config.borrow();
|
||||
let bindings = &config.binds;
|
||||
let bindings = &self.niri.binding_mode;
|
||||
let bind_left =
|
||||
find_configured_bind(bindings, comp_mod, Trigger::WheelScrollLeft, mods);
|
||||
let bind_right =
|
||||
find_configured_bind(bindings, comp_mod, Trigger::WheelScrollRight, mods);
|
||||
drop(config);
|
||||
|
||||
if let Some(right) = bind_right {
|
||||
for _ in 0..ticks {
|
||||
@ -1523,13 +1526,11 @@ impl State {
|
||||
let vertical = vertical_amount_v120.unwrap_or(0.);
|
||||
let ticks = self.niri.vertical_wheel_tracker.accumulate(vertical);
|
||||
if ticks != 0 {
|
||||
let config = self.niri.config.borrow();
|
||||
let bindings = &config.binds;
|
||||
let bindings = &self.niri.binding_mode;
|
||||
let bind_up =
|
||||
find_configured_bind(bindings, comp_mod, Trigger::WheelScrollUp, mods);
|
||||
let bind_down =
|
||||
find_configured_bind(bindings, comp_mod, Trigger::WheelScrollDown, mods);
|
||||
drop(config);
|
||||
|
||||
if let Some(down) = bind_down {
|
||||
for _ in 0..ticks {
|
||||
@ -1566,8 +1567,7 @@ impl State {
|
||||
.horizontal_finger_scroll_tracker
|
||||
.accumulate(horizontal);
|
||||
if ticks != 0 {
|
||||
let config = self.niri.config.borrow();
|
||||
let bindings = &config.binds;
|
||||
let bindings = &self.niri.binding_mode;
|
||||
let bind_left =
|
||||
find_configured_bind(bindings, comp_mod, Trigger::TouchpadScrollLeft, mods);
|
||||
let bind_right = find_configured_bind(
|
||||
@ -1576,7 +1576,6 @@ impl State {
|
||||
Trigger::TouchpadScrollRight,
|
||||
mods,
|
||||
);
|
||||
drop(config);
|
||||
|
||||
if let Some(right) = bind_right {
|
||||
for _ in 0..ticks {
|
||||
@ -1596,13 +1595,11 @@ impl State {
|
||||
.vertical_finger_scroll_tracker
|
||||
.accumulate(vertical);
|
||||
if ticks != 0 {
|
||||
let config = self.niri.config.borrow();
|
||||
let bindings = &config.binds;
|
||||
let bindings = &self.niri.binding_mode;
|
||||
let bind_up =
|
||||
find_configured_bind(bindings, comp_mod, Trigger::TouchpadScrollUp, mods);
|
||||
let bind_down =
|
||||
find_configured_bind(bindings, comp_mod, Trigger::TouchpadScrollDown, mods);
|
||||
drop(config);
|
||||
|
||||
if let Some(down) = bind_down {
|
||||
for _ in 0..ticks {
|
||||
@ -2290,7 +2287,7 @@ fn find_configured_bind(
|
||||
modifiers |= Modifiers::COMPOSITOR;
|
||||
}
|
||||
|
||||
for bind in &bindings.0 {
|
||||
for bind in &bindings.1 {
|
||||
if bind.key.trigger != trigger {
|
||||
continue;
|
||||
}
|
||||
@ -2539,7 +2536,7 @@ pub fn mods_with_binds(
|
||||
};
|
||||
|
||||
let mut rv = HashSet::new();
|
||||
for bind in &binds.0 {
|
||||
for bind in &binds.1 {
|
||||
if !triggers.iter().any(|trigger| bind.key.trigger == *trigger) {
|
||||
continue;
|
||||
}
|
||||
@ -2589,16 +2586,19 @@ mod tests {
|
||||
#[test]
|
||||
fn bindings_suppress_keys() {
|
||||
let close_keysym = Keysym::q;
|
||||
let bindings = Binds(vec![Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(close_keysym),
|
||||
modifiers: Modifiers::COMPOSITOR | Modifiers::CTRL,
|
||||
},
|
||||
action: Action::CloseWindow,
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
}]);
|
||||
let bindings = Binds(
|
||||
String::from("default"),
|
||||
vec![Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(close_keysym),
|
||||
modifiers: Modifiers::COMPOSITOR | Modifiers::CTRL,
|
||||
},
|
||||
action: Action::CloseWindow,
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
}],
|
||||
);
|
||||
|
||||
let comp_mod = CompositorMod::Super;
|
||||
let mut suppressed_keys = HashSet::new();
|
||||
@ -2722,58 +2722,61 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn comp_mod_handling() {
|
||||
let bindings = Binds(vec![
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(Keysym::q),
|
||||
modifiers: Modifiers::COMPOSITOR,
|
||||
let bindings = Binds(
|
||||
String::from("default"),
|
||||
vec![
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(Keysym::q),
|
||||
modifiers: Modifiers::COMPOSITOR,
|
||||
},
|
||||
action: Action::CloseWindow,
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
},
|
||||
action: Action::CloseWindow,
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
},
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(Keysym::h),
|
||||
modifiers: Modifiers::SUPER,
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(Keysym::h),
|
||||
modifiers: Modifiers::SUPER,
|
||||
},
|
||||
action: Action::FocusColumnLeft,
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
},
|
||||
action: Action::FocusColumnLeft,
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
},
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(Keysym::j),
|
||||
modifiers: Modifiers::empty(),
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(Keysym::j),
|
||||
modifiers: Modifiers::empty(),
|
||||
},
|
||||
action: Action::FocusWindowDown,
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
},
|
||||
action: Action::FocusWindowDown,
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
},
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(Keysym::k),
|
||||
modifiers: Modifiers::COMPOSITOR | Modifiers::SUPER,
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(Keysym::k),
|
||||
modifiers: Modifiers::COMPOSITOR | Modifiers::SUPER,
|
||||
},
|
||||
action: Action::FocusWindowUp,
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
},
|
||||
action: Action::FocusWindowUp,
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
},
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(Keysym::l),
|
||||
modifiers: Modifiers::SUPER | Modifiers::ALT,
|
||||
Bind {
|
||||
key: Key {
|
||||
trigger: Trigger::Keysym(Keysym::l),
|
||||
modifiers: Modifiers::SUPER | Modifiers::ALT,
|
||||
},
|
||||
action: Action::FocusColumnRight,
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
},
|
||||
action: Action::FocusColumnRight,
|
||||
repeat: true,
|
||||
cooldown: None,
|
||||
allow_when_locked: false,
|
||||
},
|
||||
]);
|
||||
],
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
find_configured_bind(
|
||||
@ -2786,7 +2789,7 @@ mod tests {
|
||||
}
|
||||
)
|
||||
.as_ref(),
|
||||
Some(&bindings.0[0])
|
||||
Some(&bindings.1[0])
|
||||
);
|
||||
assert_eq!(
|
||||
find_configured_bind(
|
||||
@ -2809,7 +2812,7 @@ mod tests {
|
||||
}
|
||||
)
|
||||
.as_ref(),
|
||||
Some(&bindings.0[1])
|
||||
Some(&bindings.1[1])
|
||||
);
|
||||
assert_eq!(
|
||||
find_configured_bind(
|
||||
@ -2841,7 +2844,7 @@ mod tests {
|
||||
ModifiersState::default(),
|
||||
)
|
||||
.as_ref(),
|
||||
Some(&bindings.0[2])
|
||||
Some(&bindings.1[2])
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
@ -2855,7 +2858,7 @@ mod tests {
|
||||
}
|
||||
)
|
||||
.as_ref(),
|
||||
Some(&bindings.0[3])
|
||||
Some(&bindings.1[3])
|
||||
);
|
||||
assert_eq!(
|
||||
find_configured_bind(
|
||||
@ -2879,7 +2882,7 @@ mod tests {
|
||||
}
|
||||
)
|
||||
.as_ref(),
|
||||
Some(&bindings.0[4])
|
||||
Some(&bindings.1[4])
|
||||
);
|
||||
assert_eq!(
|
||||
find_configured_bind(
|
||||
|
@ -20,6 +20,7 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> {
|
||||
},
|
||||
Msg::Workspaces => Request::Workspaces,
|
||||
Msg::RequestError => Request::ReturnError,
|
||||
Msg::BindingMode => Request::BindingMode,
|
||||
};
|
||||
|
||||
let socket = Socket::connect().context("error connecting to the niri socket")?;
|
||||
@ -238,6 +239,19 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> {
|
||||
println!("{is_active}{idx}{name}");
|
||||
}
|
||||
}
|
||||
Msg::BindingMode => {
|
||||
let Response::BindingMode(response) = response else {
|
||||
bail!("unexpected response: expected BindingMode, got {response:?}");
|
||||
};
|
||||
|
||||
if json {
|
||||
let response =
|
||||
serde_json::to_string(&response).context("error formatting response")?;
|
||||
println!("{response}");
|
||||
return Ok(());
|
||||
}
|
||||
println!("{response}");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -235,6 +235,16 @@ async fn process(ctx: &ClientCtx, request: Request) -> Reply {
|
||||
let output = result.map_err(|_| String::from("error getting active output info"))?;
|
||||
Response::FocusedOutput(output)
|
||||
}
|
||||
Request::BindingMode => {
|
||||
let (tx, rx) = async_channel::bounded(1);
|
||||
ctx.event_loop.insert_idle(move |state| {
|
||||
let workspaces = state.niri.binding_mode.0.clone();
|
||||
let _ = tx.send_blocking(workspaces);
|
||||
});
|
||||
let result = rx.recv().await;
|
||||
let mode = result.map_err(|_| String::from("error getting workspace info"))?;
|
||||
Response::BindingMode(mode.clone())
|
||||
}
|
||||
};
|
||||
|
||||
Ok(response)
|
||||
|
25
src/niri.rs
25
src/niri.rs
@ -152,6 +152,8 @@ const FRAME_CALLBACK_THROTTLE: Option<Duration> = Some(Duration::from_millis(995
|
||||
pub struct Niri {
|
||||
pub config: Rc<RefCell<Config>>,
|
||||
|
||||
pub binding_mode: niri_config::Binds,
|
||||
|
||||
/// Output config from the config file.
|
||||
///
|
||||
/// This does not include transient output config changes done via IPC. It is only used when
|
||||
@ -992,9 +994,9 @@ impl State {
|
||||
if config.binds != old_config.binds {
|
||||
self.niri.hotkey_overlay.on_hotkey_config_updated();
|
||||
self.niri.mods_with_wheel_binds =
|
||||
mods_with_wheel_binds(self.backend.mod_key(), &config.binds);
|
||||
mods_with_wheel_binds(self.backend.mod_key(), &self.niri.binding_mode);
|
||||
self.niri.mods_with_finger_scroll_binds =
|
||||
mods_with_finger_scroll_binds(self.backend.mod_key(), &config.binds);
|
||||
mods_with_finger_scroll_binds(self.backend.mod_key(), &self.niri.binding_mode);
|
||||
}
|
||||
|
||||
if config.window_rules != old_config.window_rules {
|
||||
@ -1477,6 +1479,13 @@ impl Niri {
|
||||
let config_ = config.borrow();
|
||||
let config_file_output_config = config_.outputs.clone();
|
||||
|
||||
let binding_mode = config_
|
||||
.binds
|
||||
.iter()
|
||||
.find(|e| e.0 == "default")
|
||||
.cloned()
|
||||
.unwrap_or_else(|| niri_config::Binds(String::from("default"), vec![]));
|
||||
|
||||
let layout = Layout::new(&config_);
|
||||
|
||||
let compositor_state = CompositorState::new_v6::<State>(&display_handle);
|
||||
@ -1585,14 +1594,14 @@ impl Niri {
|
||||
let cursor_manager =
|
||||
CursorManager::new(&config_.cursor.xcursor_theme, config_.cursor.xcursor_size);
|
||||
|
||||
let mods_with_wheel_binds = mods_with_wheel_binds(backend.mod_key(), &config_.binds);
|
||||
let mods_with_wheel_binds = mods_with_wheel_binds(backend.mod_key(), &binding_mode);
|
||||
let mods_with_finger_scroll_binds =
|
||||
mods_with_finger_scroll_binds(backend.mod_key(), &config_.binds);
|
||||
mods_with_finger_scroll_binds(backend.mod_key(), &binding_mode);
|
||||
|
||||
let screenshot_ui = ScreenshotUi::new(config.clone());
|
||||
let config_error_notification = ConfigErrorNotification::new(config.clone());
|
||||
|
||||
let mut hotkey_overlay = HotkeyOverlay::new(config.clone(), backend.mod_key());
|
||||
let mut hotkey_overlay = HotkeyOverlay::new(backend.mod_key());
|
||||
if !config_.hotkey_overlay.skip_at_startup {
|
||||
hotkey_overlay.show();
|
||||
}
|
||||
@ -1674,6 +1683,7 @@ impl Niri {
|
||||
drop(config_);
|
||||
Self {
|
||||
config,
|
||||
binding_mode,
|
||||
config_file_output_config,
|
||||
|
||||
event_loop,
|
||||
@ -2880,7 +2890,10 @@ impl Niri {
|
||||
}
|
||||
|
||||
// Draw the hotkey overlay on top.
|
||||
if let Some(element) = self.hotkey_overlay.render(renderer, output) {
|
||||
if let Some(element) = self
|
||||
.hotkey_overlay
|
||||
.render(renderer, output, &self.binding_mode.1)
|
||||
{
|
||||
elements.push(element.into());
|
||||
}
|
||||
|
||||
|
@ -2,9 +2,8 @@ use std::cell::RefCell;
|
||||
use std::cmp::max;
|
||||
use std::collections::HashMap;
|
||||
use std::iter::zip;
|
||||
use std::rc::Rc;
|
||||
|
||||
use niri_config::{Action, Config, Key, Modifiers, Trigger};
|
||||
use niri_config::{Action, Bind, Key, Modifiers, Trigger};
|
||||
use pangocairo::cairo::{self, ImageSurface};
|
||||
use pangocairo::pango::{AttrColor, AttrInt, AttrList, AttrString, FontDescription, Weight};
|
||||
use smithay::backend::renderer::element::Kind;
|
||||
@ -29,7 +28,6 @@ const TITLE: &str = "Important Hotkeys";
|
||||
|
||||
pub struct HotkeyOverlay {
|
||||
is_open: bool,
|
||||
config: Rc<RefCell<Config>>,
|
||||
comp_mod: CompositorMod,
|
||||
buffers: RefCell<HashMap<WeakOutput, RenderedOverlay>>,
|
||||
}
|
||||
@ -39,10 +37,9 @@ pub struct RenderedOverlay {
|
||||
}
|
||||
|
||||
impl HotkeyOverlay {
|
||||
pub fn new(config: Rc<RefCell<Config>>, comp_mod: CompositorMod) -> Self {
|
||||
pub fn new(comp_mod: CompositorMod) -> Self {
|
||||
Self {
|
||||
is_open: false,
|
||||
config,
|
||||
comp_mod,
|
||||
buffers: RefCell::new(HashMap::new()),
|
||||
}
|
||||
@ -78,6 +75,7 @@ impl HotkeyOverlay {
|
||||
&self,
|
||||
renderer: &mut R,
|
||||
output: &Output,
|
||||
binds: &[Bind],
|
||||
) -> Option<PrimaryGpuTextureRenderElement> {
|
||||
if !self.is_open {
|
||||
return None;
|
||||
@ -101,7 +99,7 @@ impl HotkeyOverlay {
|
||||
|
||||
let rendered = buffers.entry(weak).or_insert_with(|| {
|
||||
let renderer = renderer.as_gles_renderer();
|
||||
render(renderer, &self.config.borrow(), self.comp_mod, scale)
|
||||
render(renderer, binds, self.comp_mod, scale)
|
||||
.unwrap_or_else(|_| RenderedOverlay { buffer: None })
|
||||
});
|
||||
let buffer = rendered.buffer.as_ref()?;
|
||||
@ -127,7 +125,7 @@ impl HotkeyOverlay {
|
||||
|
||||
fn render(
|
||||
renderer: &mut GlesRenderer,
|
||||
config: &Config,
|
||||
binds: &[niri_config::Bind],
|
||||
comp_mod: CompositorMod,
|
||||
scale: f64,
|
||||
) -> anyhow::Result<RenderedOverlay> {
|
||||
@ -143,8 +141,6 @@ fn render(
|
||||
// target_size.h -= margin * 2;
|
||||
// anyhow::ensure!(target_size.w > 0 && target_size.h > 0);
|
||||
|
||||
let binds = &config.binds.0;
|
||||
|
||||
// Collect actions that we want to show.
|
||||
let mut actions = vec![&Action::ShowHotkeyOverlay];
|
||||
|
||||
@ -232,9 +228,7 @@ fn render(
|
||||
let strings = actions
|
||||
.into_iter()
|
||||
.map(|action| {
|
||||
let key = config
|
||||
.binds
|
||||
.0
|
||||
let key = binds
|
||||
.iter()
|
||||
.find(|bind| bind.action == *action)
|
||||
.map(|bind| key_name(comp_mod, &bind.key))
|
||||
|
Loading…
Reference in New Issue
Block a user