~tsdh/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
3 3

[PATCH swayr] Add workspace=__visible__ criteria

Michal Sojka <michal.sojka@cvut.cz>
Details
Message ID
<20240910104736.10760-1-michal.sojka@cvut.cz>
DKIM signature
pass
Download raw message
Patch: +32 -5
---
 README.md             |  2 +-
 swayr/src/criteria.rs | 35 +++++++++++++++++++++++++++++++----
 2 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md
index 3e63d1b..a51c1f7 100644
--- a/README.md
+++ b/README.md
@@ -272,7 +272,7 @@ Swayr supports most of the criteria querys defined by Sway, see section
* `class=<regex | __focused__>` 
* `instance=<regex | __focused__>`
* `title=<regex | __focused__>`
* `workspace=<regex | __focused__>`
* `workspace=<regex | __focused__ | __visible__ >`
* `con_mark=<regex>`
* `con_id=<uint | __focused__>`
* `shell=<"xdg_shell" | "xwayland" | __focused__>`
diff --git a/swayr/src/criteria.rs b/swayr/src/criteria.rs
index 53a0cb9..73b6c8c 100644
--- a/swayr/src/criteria.rs
+++ b/swayr/src/criteria.rs
@@ -25,6 +25,13 @@ pub enum RegexOrFocused {
    Focused,
}

#[derive(Debug)]
pub enum RegexOrFocusedOrVisible {
    Regex(Regex),
    Focused,
    Visible,
}

#[derive(Debug)]
pub enum I64OrFocused {
    I64(i64),
@@ -54,7 +61,7 @@ pub enum Criterion {
    ConMark(Regex),
    ConId(I64OrFocused),
    Pid(i32),
    Workspace(RegexOrFocused),
    Workspace(RegexOrFocusedOrVisible),
    Shell(ShellTypeOrFocused),
    Floating,
    Tiling,
@@ -83,6 +90,10 @@ peg::parser! {
        rule regex_or_focused() -> RegexOrFocused =
            "__focused__" { RegexOrFocused::Focused }
          / s:string_literal() { RegexOrFocused::Regex(regex_from_str(&s)) }
        rule regex_or_focused_or_visible() -> RegexOrFocusedOrVisible =
            "__focused__" { RegexOrFocusedOrVisible::Focused }
          / "__visible__" { RegexOrFocusedOrVisible::Visible }
          / s:string_literal() { RegexOrFocusedOrVisible::Regex(regex_from_str(&s)) }

        rule i64_focused() -> I64OrFocused =
            "__focused__" { I64OrFocused::Focused }
@@ -108,7 +119,7 @@ peg::parser! {
        rule pid() -> Criterion = "pid" space() "=" space()
            n:i32_literal() { Criterion::Pid(n) }
        rule workspace() -> Criterion = "workspace" space() "=" space()
            rof:regex_or_focused() { Criterion::Workspace(rof) }
            rof:regex_or_focused_or_visible() { Criterion::Workspace(rof) }
        rule shell_type_or_focused() -> ShellTypeOrFocused =
            "\"xdg_shell\"" {ShellTypeOrFocused::ShellType(s::ShellType::XdgShell)}
          / "\"xwayland\""  {ShellTypeOrFocused::ShellType(s::ShellType::Xwayland)}
@@ -263,14 +274,14 @@ fn eval_criterion<'a>(
        Criterion::ConMark(rx) => w.node.marks.iter().any(|m| rx.is_match(m)),
        Criterion::Pid(pid) => w.node.pid == Some(*pid),
        Criterion::Workspace(val) => match val {
            RegexOrFocused::Regex(rx) => {
            RegexOrFocusedOrVisible::Regex(rx) => {
                let ws_name = w
                    .tree
                    .get_parent_node_of_type(w.node.id, ipc::Type::Workspace)
                    .map(|ws| ws.get_name().to_owned());
                is_some_and_rx_matches(ws_name.as_ref(), rx)
            }
            RegexOrFocused::Focused => match focused {
            RegexOrFocusedOrVisible::Focused => match focused {
                Some(win) => are_some_and_equal(
                    w.tree.get_parent_node_of_type(
                        w.node.id,
@@ -283,6 +294,22 @@ fn eval_criterion<'a>(
                ),
                None => false,
            },
            RegexOrFocusedOrVisible::Visible => {
                if let Some(ws) = w
                    .tree
                    .get_parent_node_of_type(w.node.id, ipc::Type::Workspace)
                {
                    if let Some(output) =
                        w.tree.get_parent_node_of_type(ws.id, ipc::Type::Output)
                    {
                        return output
                            .focus
                            .first()
                            .is_some_and(|&visible| visible == ws.id);
                    }
                }
                return false;
            }
        },
        Criterion::Floating => w.node.is_floating(),
        Criterion::Tiling => !w.node.is_floating(),
-- 
2.46.0

[swayr/patches/arch.yml] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<D42JNQYXS4S4.1XROMT31G59Z4@fra02>
In-Reply-To
<20240910104736.10760-1-michal.sojka@cvut.cz> (view parent)
DKIM signature
missing
Download raw message
swayr/patches/arch.yml: SUCCESS in 1m10s

[Add workspace=__visible__ criteria][0] from [Michal Sojka][1]

[0]: https://lists.sr.ht/~tsdh/public-inbox/patches/54976
[1]: michal.sojka@cvut.cz

✓ #1324199 SUCCESS swayr/patches/arch.yml https://builds.sr.ht/~tsdh/job/1324199

[PATCH swayr v2] Add workspace=__visible__ criteria

Michal Sojka <michal.sojka@cvut.cz>
Details
Message ID
<20240910110334.12313-1-michal.sojka@cvut.cz>
In-Reply-To
<D42JNQYXS4S4.1XROMT31G59Z4@fra02> (view parent)
DKIM signature
pass
Download raw message
Patch: +32 -5
---
Changelog:
v2: Removed clippy warning

 README.md             |  2 +-
 swayr/src/criteria.rs | 35 +++++++++++++++++++++++++++++++----
 2 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md
index 3e63d1b..a51c1f7 100644
--- a/README.md
+++ b/README.md
@@ -272,7 +272,7 @@ Swayr supports most of the criteria querys defined by Sway, see section
* `class=<regex | __focused__>` 
* `instance=<regex | __focused__>`
* `title=<regex | __focused__>`
* `workspace=<regex | __focused__>`
* `workspace=<regex | __focused__ | __visible__ >`
* `con_mark=<regex>`
* `con_id=<uint | __focused__>`
* `shell=<"xdg_shell" | "xwayland" | __focused__>`
diff --git a/swayr/src/criteria.rs b/swayr/src/criteria.rs
index 53a0cb9..a90b882 100644
--- a/swayr/src/criteria.rs
+++ b/swayr/src/criteria.rs
@@ -25,6 +25,13 @@ pub enum RegexOrFocused {
    Focused,
}

#[derive(Debug)]
pub enum RegexOrFocusedOrVisible {
    Regex(Regex),
    Focused,
    Visible,
}

#[derive(Debug)]
pub enum I64OrFocused {
    I64(i64),
@@ -54,7 +61,7 @@ pub enum Criterion {
    ConMark(Regex),
    ConId(I64OrFocused),
    Pid(i32),
    Workspace(RegexOrFocused),
    Workspace(RegexOrFocusedOrVisible),
    Shell(ShellTypeOrFocused),
    Floating,
    Tiling,
@@ -83,6 +90,10 @@ peg::parser! {
        rule regex_or_focused() -> RegexOrFocused =
            "__focused__" { RegexOrFocused::Focused }
          / s:string_literal() { RegexOrFocused::Regex(regex_from_str(&s)) }
        rule regex_or_focused_or_visible() -> RegexOrFocusedOrVisible =
            "__focused__" { RegexOrFocusedOrVisible::Focused }
          / "__visible__" { RegexOrFocusedOrVisible::Visible }
          / s:string_literal() { RegexOrFocusedOrVisible::Regex(regex_from_str(&s)) }

        rule i64_focused() -> I64OrFocused =
            "__focused__" { I64OrFocused::Focused }
@@ -108,7 +119,7 @@ peg::parser! {
        rule pid() -> Criterion = "pid" space() "=" space()
            n:i32_literal() { Criterion::Pid(n) }
        rule workspace() -> Criterion = "workspace" space() "=" space()
            rof:regex_or_focused() { Criterion::Workspace(rof) }
            rof:regex_or_focused_or_visible() { Criterion::Workspace(rof) }
        rule shell_type_or_focused() -> ShellTypeOrFocused =
            "\"xdg_shell\"" {ShellTypeOrFocused::ShellType(s::ShellType::XdgShell)}
          / "\"xwayland\""  {ShellTypeOrFocused::ShellType(s::ShellType::Xwayland)}
@@ -263,14 +274,14 @@ fn eval_criterion<'a>(
        Criterion::ConMark(rx) => w.node.marks.iter().any(|m| rx.is_match(m)),
        Criterion::Pid(pid) => w.node.pid == Some(*pid),
        Criterion::Workspace(val) => match val {
            RegexOrFocused::Regex(rx) => {
            RegexOrFocusedOrVisible::Regex(rx) => {
                let ws_name = w
                    .tree
                    .get_parent_node_of_type(w.node.id, ipc::Type::Workspace)
                    .map(|ws| ws.get_name().to_owned());
                is_some_and_rx_matches(ws_name.as_ref(), rx)
            }
            RegexOrFocused::Focused => match focused {
            RegexOrFocusedOrVisible::Focused => match focused {
                Some(win) => are_some_and_equal(
                    w.tree.get_parent_node_of_type(
                        w.node.id,
@@ -283,6 +294,22 @@ fn eval_criterion<'a>(
                ),
                None => false,
            },
            RegexOrFocusedOrVisible::Visible => {
                if let Some(ws) = w
                    .tree
                    .get_parent_node_of_type(w.node.id, ipc::Type::Workspace)
                {
                    if let Some(output) =
                        w.tree.get_parent_node_of_type(ws.id, ipc::Type::Output)
                    {
                        return output
                            .focus
                            .first()
                            .is_some_and(|&visible| visible == ws.id);
                    }
                }
                false
            }
        },
        Criterion::Floating => w.node.is_floating(),
        Criterion::Tiling => !w.node.is_floating(),
-- 
2.46.0

Re: [PATCH swayr v2] Add workspace=__visible__ criteria

Details
Message ID
<87a5gf4r5v.fsf@gnu.org>
In-Reply-To
<20240910110334.12313-1-michal.sojka@cvut.cz> (view parent)
DKIM signature
pass
Download raw message
Hi Michal,

looks good to me.  Applied and pushed!

Thanks,
  Tassilo
Reply to thread Export thread (mbox)