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

Layout coding: hiding a window #27

Closed
yohannd1 opened this issue Aug 16, 2020 · 6 comments · Fixed by #31
Closed

Layout coding: hiding a window #27

yohannd1 opened this issue Aug 16, 2020 · 6 comments · Fixed by #31

Comments

@yohannd1
Copy link

I've been trying to implement the monocle layout on penrose, and I'm stuck on how to hide windows.

The monocle layout - as far as I'm concerned - works this way: if a window is focused, it occupies the entire space reserved for the layout; and if it is not focused, it's just hidden.

I've tried to hide a window by setting its size to zero, but it doesn't seem to work. Would you happen to know what is happening?

Here's the function:

use penrose::client::Client;
use penrose::data_types::{Region, ResizeAction, WinId};
use penrose::layout::client_breakdown;

pub fn really_cool_layout(
    clients: &[&Client],
    focused: Option<WinId>,
    monitor_region: &Region,
    _: u32,
    _: f32,
) -> Vec<ResizeAction> {
    if let Some(fid) = focused {
        let (mx, my, mw, mh) = monitor_region.values();
        clients
            .iter()
            .map(|c| {
                let cid = c.id();
                if cid == fid {
                    (cid, Region::new(mx, my, mw, mh))
                } else {
                    (cid, Region::new(mx, my, 0, 0))
                }
            })
            .collect()
    } else {
        Vec::new()
    }
}
@sminez
Copy link
Owner

sminez commented Aug 16, 2020

I think the window sizes have to be strictly > 0 (though I might be wrong: the XCB docs are patchy to say the least!)

I do know that for the window manager check window (for setting ewmh props etc) I set the width and height to 1px each and that effectively hides the window. Might be worth trying that?

If not, then I suspect I'd need to modify the layout API / ResizeAction to allow for unmapping a window as opposed to positioning it. The 1px trick feels pretty hacky to be honest so it might be worth doing that anyway...something like this with None indicating that the window should be unmapped. (Changing to another layout should remap it back but I suppose that'd then be something we'd need to check for / track).

pub type ResizeAction = (WinId, Option<Region>)

@yohannd1
Copy link
Author

I tried changing the size to (1, 1) and I noticed a thing: it was already working before!

The problem actually is that the layout function doesn't seem to run when simply cycling though windows.

Nonetheless, I think the unmapping of windows might be better in the future. Apparently qutebrowser crashes when its screen size is as small as 0 or 1 (still investigating) and other applications might end up having the same bug.

@sminez
Copy link
Owner

sminez commented Aug 23, 2020

@YohananDiamond are you able to check if this is what you are after?

@yohannd1
Copy link
Author

The problem seems to be still here - I can focus other windows other than the first one, but they are on the background. But I noticed one thing: if I switch workspaces and go back, the window that was hidden is shown. Maybe the layout is not updating on focus change?

@sminez
Copy link
Owner

sminez commented Aug 23, 2020

Ah sorry, yes you need to set the layout config to trigger follow focus like this. You probably also want to do what I've done and allow client wrapping as well (default is to allow but you need to make sure you specify it when you create the config)

Layout functions by themselve can't determine when and how they are triggered: they only specify what to do with the clients when they are triggered. To be honest, at least for the default layouts I probably should provide some helper functions that bundle them with the appropriate LayoutConfig.

@yohannd1
Copy link
Author

Oh, okay. It's working now, thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants