diff --git a/CHANGELOG.md b/CHANGELOG.md index b792b7c..916046f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Changed - Added support for changing the preview color. +- Added support for edges. ### Changed - Update Wayland dependencies to fix coredump. diff --git a/README.md b/README.md index b723a7a..854fa13 100644 --- a/README.md +++ b/README.md @@ -46,12 +46,20 @@ enter_command = [ "notify-send", "enter" ] exit_command = [ "notify-send", "exit" ] # Locations of the hot corners. -# Options: top_left, top_right, bottom_right, and bottom_left. +# Options: +# - for corners: top_left, top_right, bottom_right, and bottom_left; +# - for edges: top, bottom, right, left. locations = ["bottom_right", "bottom_left"] # default -# Size of the hot corners in pixels. +# Size of the hot corners in pixels, for edges the size means the width +# for vertical edges, and height for horizontal edges. The other dimension +# will be the width/height of your display - the set margin. size = 10 # default +# Margin on the sides of the hot edges, only applicable to edge locations. +# See the comment with sizes attribute above. +margin = 20 # default + # Timeout in milliseconds before command is triggered. timeout_ms = 250 # default diff --git a/src/config.rs b/src/config.rs index 0acb6b9..7eccbfe 100644 --- a/src/config.rs +++ b/src/config.rs @@ -18,6 +18,10 @@ fn default_size() -> u8 { 10 } +fn default_margin() -> i8 { + 20 +} + fn default_timeout_ms() -> u16 { 250 } @@ -66,6 +70,8 @@ pub struct CornerConfig { pub locations: Vec, #[serde(default = "default_size")] pub size: u8, + #[serde(default = "default_margin")] + pub margin: i8, #[serde(default = "default_timeout_ms")] pub timeout_ms: u16, #[serde(default = "default_color", deserialize_with = "from_hex")] @@ -84,6 +90,10 @@ pub enum Location { TopRight, BottomRight, BottomLeft, + Left, + Right, + Top, + Bottom, } type Config = HashMap; diff --git a/src/wayland.rs b/src/wayland.rs index 0c3952a..8bfc25b 100644 --- a/src/wayland.rs +++ b/src/wayland.rs @@ -239,14 +239,23 @@ impl Wayland { .locations .iter() .map(|location| { - match location { + let anchor = match location { Location::TopLeft => Anchor::Top | Anchor::Left, Location::TopRight => Anchor::Top | Anchor::Right, Location::BottomRight => Anchor::Bottom | Anchor::Right, Location::BottomLeft => Anchor::Bottom | Anchor::Left, - } - }) - .map(|anchor| { + Location::Left => { + Anchor::Left | Anchor::Top | Anchor::Bottom + } + Location::Right => { + Anchor::Right | Anchor::Top | Anchor::Bottom + } + Location::Top => Anchor::Top | Anchor::Left | Anchor::Right, + Location::Bottom => { + Anchor::Bottom | Anchor::Left | Anchor::Right + } + }; + info!("Adding anchorpoint {:?}", anchor); let surface = environment.create_surface().detach(); @@ -257,7 +266,36 @@ impl Wayland { "waycorner".to_owned(), ); let size = corner_config.size.into(); - layer_surface.set_size(size, size); + let margin = corner_config.margin.into(); + layer_surface.set_size( + match location { + Location::Top | Location::Bottom => 0, + _ => size, + }, + match location { + Location::Left | Location::Right => 0, + _ => size, + }, + ); + layer_surface.set_margin( + // top, right, bottom, left + match location { + Location::Left | Location::Right => margin, + _ => 0, + }, + match location { + Location::Top | Location::Bottom => margin, + _ => 0, + }, + match location { + Location::Left | Location::Right => margin, + _ => 0, + }, + match location { + Location::Top | Location::Bottom => margin, + _ => 0, + }, + ); layer_surface.set_anchor(anchor); // Ignore exclusive zones. layer_surface.set_exclusive_zone(-1); @@ -319,7 +357,7 @@ impl Wayland { 0, width.try_into().unwrap(), height.try_into().unwrap(), - (4 * height).try_into().unwrap(), + (4 * width).try_into().unwrap(), Format::Argb8888, ); surface_handle.attach(Some(&buffer), 0, 0);