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

Add support for multiple desktops based on Windows settings #151

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ian-h-chamberlain
Copy link

Closes #99

Include windows cloaked by the shell, but exclude "invisible" windows. This seems to result in pretty much the expected list of windows across all desktops instead of just the current one.

We read the Windows registry to decide whether to filter windows on other desktops or not, based on the corresponding multitasking setting.

NOTE: I will probably file a separate issue for this and try to implement it as well, but I realized it might make sense to have a corresponding setting for Alt+`; the behavior now is to follow the same setting, but macOS always limits it to the current desktop, so being able to toggle it independently would be nice. AFAIK there would be no corresponding Windows setting for this one.

Include windows cloaked by the shell, but exclude "invisible" windows.
This seems to result in pretty much the expected list of windows across
all desktops instead of just the current one.
Windows already has a setting for the Alt-tab switcher to include
virtual desktops, so we can just use that instead of a config.
@sigoden
Copy link
Owner

sigoden commented Nov 17, 2024

@ian-h-chamberlain

Add two configuration items.

[switch-windows]

#  Only switch windows in the current desktop
only_current_desktop = yes

[switch-apps]

# Only switch apps in the current desktop, yes/no/auto
# If auto, follow the system setting (Settings > System > Multitasking -> Virtual Desktops)
only_current_desktop = auto
pub struct Config {
    ...
    pub switch_windows_only_current_desktop: bool,
    ...
    pub switch_apps_only_current_desktop: Option<bool<,
}

Why add is_invisible_window?

We already have is_visible_window fn, Can you give an example of situations where is_visible_window fn is not enough, and is_invisible_window fn must also be used?

@ian-h-chamberlain
Copy link
Author

We already have is_visible_window fn, Can you give an example of situations where is_visible_window fn is not enough, and is_invisible_window fn must also be used?

There are a handful of programs that appear as "invisible", which Windows does not appear to include in its own task switcher:

$ cargo r --package inspect-windows |& grep 'visible:✓invisible:✓cloak:'
visible:✓invisible:✓cloak:0iconic: topmost:✓    1512x48      65726: 0:
visible:✓invisible:✓cloak:0iconic: topmost:         0x0     197330: 131464:
visible:✓invisible:✓cloak:0iconic: topmost:         0x0     131464: 0:
visible:✓invisible:✓cloak:2iconic: topmost:         0x0     197164:Windows Shell Experience Host 0:
visible:✓invisible:✓cloak:1iconic: topmost:         0x0      65906: 0:
visible:✓invisible:✓cloak:1iconic: topmost:      1497x2      65898: 0:
visible:✓invisible:✓cloak:1iconic: topmost:         0x0      65870: 0:
visible:✓invisible:✓cloak:1iconic: topmost:         0x0      65868: 0:
visible:✓invisible:✓cloak:1iconic: topmost:         0x0      65866: 0:
visible:✓invisible:✓cloak:1iconic: topmost:         0x0      65864: 0:
visible:✓invisible:✓cloak:0iconic: topmost:    1512x827      65808:Program Manager 0:

In particular, Windows Shell Experience here (I have also seen Calculator sometimes?) was showing up in the task switcher app list, but it really shouldn't be. This also has a side effect of filtering out Program Manager automatically, I think. I got the details about this from reading https://stackoverflow.com/a/7292674 which may have some additional useful info in general for this app.

I will work on adding the new configs and push my changes once I have it working.

@sigoden
Copy link
Owner

sigoden commented Nov 18, 2024

It seems that is_invisible_window makes sence.

Why not merge it into the is_visible_window function? It's strange to have two functions is_visible_window and is_invisible_window.

Since we have is_invisible_window, we can safely remove the following code:

let title = get_window_title(hwnd);
if !title.is_empty() && title != "Program Manager" {

@ian-h-chamberlain ian-h-chamberlain marked this pull request as ready for review November 18, 2024 04:22
Comment on lines +79 to +85
trace!("registry configured alt-tab filter: {alt_tab_filter}");

alt_tab_filter != 0
});

let cloak_type = get_window_cloak_type(hwnd);
trace!("only_current_desktop: {only_current_desktop:?}, cloak_type={cloak_type:?}");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please delete these two traces!

This function is called by enum_windows, and it generates a large amount of log entries each time
It is also impossible to distinguish which window they come from, so logging it have litte value.

Comment on lines 247 to +250
let mut owner_hwnds = vec![];
for hwnd in hwnds.iter().cloned() {
let mut valid = is_visible_window(hwnd)
&& !is_cloaked_window(hwnd)
&& !is_cloaked_window(hwnd, only_current_desktop)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should solve the value of only_current_desktop with the registry key before the loop.

Reading the registry key in a loop is not a good practice.

if !title.is_empty() && title != "Program Manager" {
valid_hwnds.push((hwnd, title))
}
valid_hwnds.push((hwnd, title))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to check the title for Program Manager, but we should keep checking title.is_empty just in case.

            if !title.is_empty() {
                valid_hwnds.push((hwnd, title))
            }

src/utils/window.rs Show resolved Hide resolved
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 this pull request may close these issues.

Feature Request: Option in [switch-apps] to get apps from all desktops
2 participants