From cfeff7d08f87bd36e843e717df49293a872d3ef1 Mon Sep 17 00:00:00 2001 From: Kirottu Date: Tue, 25 Apr 2023 21:45:01 +0300 Subject: [PATCH] Icons and back match for Randr --- plugins/randr/src/lib.rs | 20 +++++++++++++++++--- plugins/randr/src/randr/mod.rs | 11 +++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/plugins/randr/src/lib.rs b/plugins/randr/src/lib.rs index d6dd314..f524238 100644 --- a/plugins/randr/src/lib.rs +++ b/plugins/randr/src/lib.rs @@ -52,6 +52,11 @@ pub fn handler(_match: Match, state: &mut State) -> HandleResult { HandleResult::Refresh(true) } InnerState::Position(mon) => { + if _match.id.unwrap() == u64::MAX { + state.inner = InnerState::None; + return HandleResult::Refresh(false); + } + let rel_id = (_match.id.unwrap() >> 32) as u32; let action = _match.id.unwrap() as u32; @@ -84,7 +89,7 @@ pub fn get_matches(input: RString, state: &mut State) -> RVec { format!("{}x{} at {}x{}", mon.width, mon.height, mon.x, mon.y).into(), ), use_pango: false, - icon: ROption::RNone, + icon: ROption::RSome("object-flip-horizontal".into()), id: ROption::RSome(mon.id), }) .collect::>(), @@ -110,7 +115,7 @@ pub fn get_matches(input: RString, state: &mut State) -> RVec { title: format!("{} {}", configure.to_string(), _mon.name).into(), description: ROption::RNone, use_pango: false, - icon: ROption::RNone, + icon: ROption::RSome(configure.icon().into()), // Store 2 32 bit IDs in the single 64 bit integer, a bit of a hack id: ROption::RSome(_mon.id << 32 | Into::::into(configure)), }) @@ -125,9 +130,18 @@ pub fn get_matches(input: RString, state: &mut State) -> RVec { title: "Reset position".into(), description: ROption::RNone, use_pango: false, - icon: ROption::RNone, + icon: ROption::RSome(Configure::Zero.icon().into()), id: ROption::RSome((&Configure::Zero).into()), }); + + vec.push(Match { + title: "Back".into(), + description: ROption::RSome("Return to the previous menu".into()), + use_pango: false, + icon: ROption::RSome("edit-undo".into()), + id: ROption::RSome(u64::MAX), + }); + vec } } diff --git a/plugins/randr/src/randr/mod.rs b/plugins/randr/src/randr/mod.rs index 69e4bfa..182205a 100644 --- a/plugins/randr/src/randr/mod.rs +++ b/plugins/randr/src/randr/mod.rs @@ -34,6 +34,17 @@ impl<'a> Configure<'a> { _ => unreachable!(), } } + + pub fn icon(&self) -> &'static str { + match self { + Configure::Mirror(_) => "edit-copy", + Configure::LeftOf(_) => "go-previous", + Configure::RightOf(_) => "go-next", + Configure::Below(_) => "go-down", + Configure::Above(_) => "go-up", + Configure::Zero => "go-home", + } + } } impl<'a> ToString for Configure<'a> {