Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cycle_client no longer works in a hook #65

Closed
crypt17 opened this issue Sep 16, 2020 · 6 comments
Closed

cycle_client no longer works in a hook #65

crypt17 opened this issue Sep 16, 2020 · 6 comments
Labels
invalid This doesn't seem right

Comments

@crypt17
Copy link

crypt17 commented Sep 16, 2020

Describe the bug
between now and yesterday calling the cycle_client function from a remove client hook seems to have become a no op

To Reproduce
Steps to reproduce the behavior:
with the hook in place open multiple windows and then close them.

The expected behaviour is that the focus would change in the given direction but at present the focus remains the same regardless of the value passed to cycle_client. Neither Forward or backward make any change.

Additional context
This is the hook that I am using. Even if it is reduced to just the cycle_client command it has no effect now bt was working yesterday 15/9

struct MyHook {}
impl Hook for MyHook {
    fn remove_client(&mut self, _wm: &mut WindowManager, _id: WinId) {
        // check if we need to do something
        // if not bail else move down
        let ws = match _wm.workspace(&Selector::Focused) {
            Some(ws) => ws,
            None => return 
        };

        let the_len =  ws.len();
        
        if the_len < 2 { return; }

        let cref = _wm.client(&Selector::Focused).unwrap();
        let end_id = match _wm.client(&Selector::Index(the_len-1)) {
            Some(c) => c.id(),
            None => return
        };


         // check if this is the last item
         if cref.id() == end_id {
             return;
         }

        // swap down

        _wm.cycle_client(Direction::Backward);
    }
}
@crypt17 crypt17 added the bug Something isn't working label Sep 16, 2020
@sminez
Copy link
Owner

sminez commented Sep 16, 2020

Are you able to give me the hash that this was last working on? It would also really help if you can put some logging into your hook and determine exactly when it is exiting. Looking over the code you have provided there are quite a few places where you could be exiting early.

@crypt17
Copy link
Author

crypt17 commented Sep 16, 2020 via email

@sminez
Copy link
Owner

sminez commented Sep 19, 2020

@crypt17 I've rewritten your hook a bit to make it easier to reason about and added some simple print logging to trace the execution:

struct RmClientHook {}
impl Hook for RmClientHook {
    fn remove_client(&mut self, wm: &mut WindowManager, _: WinId) {
        if let Some(ws) = wm.workspace(&Selector::Focused) {
            println!("have focused workspace: {}", ws.name());
            if ws.len() > 1 {
                println!("more than one client (n={})", ws.len());
                let last = wm.client(&Selector::Index(ws.len() - 1));
                if last != wm.client(&Selector::Focused) {
                    println!("new focused is not last");
                    wm.cycle_client(Backward);
                }
            }
        }
    }
}

From what I can see, this is firing (yours was as well) and cycle_client is being called. cycle_client is also doing the right thing. When using a layout that does not trigger on a focus change it works fine but it results in an infinite loop of cycling clients for the example paper layout config. Working around that is something that you'll need to handle in your hook if this is how you are wanting to implement it.

@sminez sminez closed this as completed Sep 19, 2020
@sminez sminez added invalid This doesn't seem right and removed bug Something isn't working labels Sep 19, 2020
@crypt17
Copy link
Author

crypt17 commented Sep 20, 2020 via email

@crypt17
Copy link
Author

crypt17 commented Sep 20, 2020 via email

@sminez
Copy link
Owner

sminez commented Sep 22, 2020

This behaviour is a breaking change for layouts that follow focus. It will not be added to core. If you want to implement it as am extension as already discussed then feel free to do so.

Repository owner locked and limited conversation to collaborators Sep 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants