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

Enhancing Multi-Screen Support with Dynamic Screen Detection and Multi-Screen Window List #170

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion Core/AppWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using System.Runtime.Caching;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using ManagedWinapi.Windows;

namespace Switcheroo.Core
Expand Down Expand Up @@ -118,7 +119,19 @@ public AppWindow Owner
.Select(w => new AppWindow(w.HWnd));
}
}

public bool IsCurrentScreenWindow()
{
Screen WindowScreen = Screen.FromHandle(HWnd);
Screen MouseScreen = Screen.FromPoint(Cursor.Position);
if (WindowScreen.DeviceName == MouseScreen.DeviceName)
{
return true;
}
else
{
return false;
}
}
public bool IsAltTabWindow()
{
if (!Visible) return false;
Expand Down
4 changes: 2 additions & 2 deletions Core/WindowFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ namespace Switcheroo.Core
{
public class WindowFinder
{
public List<AppWindow> GetWindows()
public List<AppWindow> GetWindows(bool CrrentScreenOnly)
{
return AppWindow.AllToplevelWindows
.Where(a => a.IsAltTabWindow())
.Where(a => a.IsAltTabWindow() && (CrrentScreenOnly ? a.IsCurrentScreenWindow() : true))
.ToList();
}
}
Expand Down
15 changes: 12 additions & 3 deletions Switcheroo/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private static async Task<Version> GetLatestVersion()
/// </summary>
private void LoadData(InitialFocus focus)
{
_unfilteredWindowList = new WindowFinder().GetWindows().Select(window => new AppWindowViewModel(window)).ToList();
_unfilteredWindowList = new WindowFinder().GetWindows(Settings.Default.ShowOnlyCursorScreenWindows).Select(window => new AppWindowViewModel(window)).ToList();

var firstWindow = _unfilteredWindowList.FirstOrDefault();

Expand Down Expand Up @@ -334,8 +334,17 @@ private void CenterWindow()
SizeToContent = SizeToContent.WidthAndHeight;

// Position the window in the center of the screen
Left = (SystemParameters.PrimaryScreenWidth/2) - (ActualWidth/2);
Top = (SystemParameters.PrimaryScreenHeight/2) - (ActualHeight/2);
if (Settings.Default.ShowInCursorScreen)
{
Screen MouseScreen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
Left = MouseScreen.Bounds.X + (MouseScreen.Bounds.Width / 2) - (ActualWidth / 2);
Top = (MouseScreen.Bounds.Height / 2) - (ActualHeight / 2);
}
else
{
Left = (SystemParameters.PrimaryScreenWidth / 2) - (ActualWidth / 2);
Top = (SystemParameters.PrimaryScreenHeight / 2) - (ActualHeight / 2);
}
}

/// <summary>
Expand Down
6 changes: 5 additions & 1 deletion Switcheroo/OptionsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Switcheroo Options" ResizeMode="NoResize" SizeToContent="WidthAndHeight"
ShowInTaskbar="False" WindowStyle="ToolWindow" Background="{x:Static SystemColors.WindowBrush}" Height="380"
ShowInTaskbar="False" WindowStyle="ToolWindow" Background="{x:Static SystemColors.WindowBrush}" Height="455.818"
MaxWidth="350">
<Window.Resources>
</Window.Resources>
Expand All @@ -29,6 +29,10 @@
Use <Span FontFamily="Consolas" FontWeight="Bold">Ctrl + Alt + Tab</Span> for displaying Switcheroo with search activated, or
press <Span FontFamily="Consolas" FontWeight="Bold">Alt + S</Span> when the Switcheroo overlay appears.
</TextBlock>
<CheckBox x:Name="CurrentScreenWindows" Margin="5,5,5,1" Content="Dynamic Screen Detection"/>
<TextBlock Margin="25,0,5,10" FontSize="10" Foreground="DimGray" TextWrapping="Wrap" Text="Automatically displays the software on the screen where the user's cursor is located."/>
<CheckBox x:Name="ShowInCurrentScreen" Margin="5,5,5,1" Content="Multi-Screen Window List"/>
<TextBlock Margin="25,0,5,10" FontSize="10" Foreground="DimGray" TextWrapping="Wrap" Text="Displays a list of windows available on the screen where the user's cursor is located for improved user experience."/>
<CheckBox x:Name="RunAsAdministrator" Margin="5,5,5,1" Content="Run as Administrator *"/>
<TextBlock Margin="25,0,5,10" FontSize="10" Foreground="DimGray" TextWrapping="Wrap">
This is needed if you want <Span FontFamily="Consolas" FontWeight="Bold">Alt + Tab</Span> to work when programs
Expand Down
4 changes: 4 additions & 0 deletions Switcheroo/OptionsWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public OptionsWindow()
AutoSwitch.IsChecked = Settings.Default.AutoSwitch;
AutoSwitch.IsEnabled = Settings.Default.AltTabHook;
RunAsAdministrator.IsChecked = Settings.Default.RunAsAdmin;
ShowInCurrentScreen.IsChecked = Settings.Default.ShowInCursorScreen;
CurrentScreenWindows.IsChecked = Settings.Default.ShowOnlyCursorScreenWindows;
}

private void Cancel_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -107,6 +109,8 @@ private void Ok_Click(object sender, RoutedEventArgs e)
Settings.Default.AltTabHook = AltTabCheckBox.IsChecked.GetValueOrDefault();
Settings.Default.AutoSwitch = AutoSwitch.IsChecked.GetValueOrDefault();
Settings.Default.RunAsAdmin = RunAsAdministrator.IsChecked.GetValueOrDefault();
Settings.Default.ShowInCursorScreen = ShowInCurrentScreen.IsChecked.GetValueOrDefault();
Settings.Default.ShowOnlyCursorScreenWindows = CurrentScreenWindows.IsChecked.GetValueOrDefault();
Settings.Default.Save();

if (closeOptionsWindow)
Expand Down
26 changes: 25 additions & 1 deletion Switcheroo/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Switcheroo/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,11 @@
<Setting Name="EnableHotKey" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="ShowInCursorScreen" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="ShowOnlyCursorScreenWindows" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>
6 changes: 6 additions & 0 deletions Switcheroo/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
<setting name="EnableHotKey" serializeAs="String">
<value>True</value>
</setting>
<setting name="ShowInCursorScreen" serializeAs="String">
<value>False</value>
</setting>
<setting name="ShowOnlyCursorScreenWindows" serializeAs="String">
<value>False</value>
</setting>
</Switcheroo.Properties.Settings>
</userSettings>
<startup>
Expand Down