Skip to content
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
93 changes: 93 additions & 0 deletions WinLaunch/ActivationMethods/StartWindowActivation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Threading;
using Vanara.InteropServices;
using Vanara.PInvoke;
using static Vanara.PInvoke.Shell32;

namespace WinLaunch
{
/// <summary>
/// This class implements replacing the StartWindow with WinLaunch.
/// </summary>
/// <remarks>
/// This class works by monitoring the start menu state using the shells IAppVisibility COM interface.
/// </remarks>
internal class StartWindowActivation
{
private ComReleaser<IAppVisibility> appVisibility;
private AppVisibilityNotificationSubscriber subscriber;
private uint unadviseCookie;
private Dispatcher dispatcher;

/// <summary>
/// Start monitoring the state of the Start window
/// </summary>
/// <param name="callback">callback to call when state changes</param>
/// <remarks>NOTE: The callback will be called on the Dispatcher thread, so you can make UI calls from the callback.</remarks>
public void StartListening(Action<bool> callback)
{
dispatcher = Dispatcher.CurrentDispatcher;

Debug.WriteLine($"{nameof(StartWindowActivation)} Start Listening");

appVisibility = ComReleaserFactory.Create(new IAppVisibility());
subscriber = new AppVisibilityNotificationSubscriber((visible) =>
{
// use the dispatcher to call the callback on the callers UI thread.
dispatcher.Invoke(() => callback(visible));
});

// Advise to receive change notifications from the AppVisibility object
// NOTE: There must be a reference held on the AppVisibility object in order to continue
appVisibility.Item.Advise(subscriber, out var cookie);
unadviseCookie = cookie;
}

/// <summary>
/// StopListening() to state of the Start window
/// </summary>
public void StopListening()
{
Debug.WriteLine($"{nameof(StartWindowActivation)} Stop Listening");

if (appVisibility != null)
{
// Unadvise from the AppVisibility component to stop receiving notifications
if (this.unadviseCookie != 0)
{
appVisibility.Item.Unadvise(this.unadviseCookie);
}
appVisibility.Dispose();
appVisibility = null;
}
}
}

/// <summary>
/// This class implements the IAppVisibilityEvents interface and will receive notifications from the AppVisibility COM object.
/// </summary>
[ComVisible(true)]
public class AppVisibilityNotificationSubscriber : IAppVisibilityEvents
{
private Action<bool> _callback;

public AppVisibilityNotificationSubscriber(Action<bool> callback)
{
this._callback = callback;
}

HRESULT IAppVisibilityEvents.AppVisibilityOnMonitorChanged(HMONITOR hMonitor, MONITOR_APP_VISIBILITY previousMode, MONITOR_APP_VISIBILITY currentMode)
{
return HRESULT.S_OK;
}

HRESULT IAppVisibilityEvents.LauncherVisibilityChange(bool visible)
{
Debug.WriteLine($"Start Menu visibility: {visible}");
_callback(visible);
return HRESULT.S_OK;
}
}
}
9 changes: 7 additions & 2 deletions WinLaunch/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public MainWindow()

//hook up events
this.Loaded += new RoutedEventHandler(MainWindow_Loaded);

//setup window
this.AllowDrop = true;

Expand All @@ -175,6 +175,7 @@ public MainWindow()
//load theme
Theme.CurrentTheme = Theme.LoadTheme();

#if BROKEN // this doesn't compile???
if (Theme.CurrentTheme.Rows != -1)
{
//old style
Expand All @@ -192,6 +193,7 @@ public MainWindow()

Theme.SaveTheme(Theme.CurrentTheme);
}
#endif

//enable if aero is in use and available
//if (Theme.CurrentTheme.UseAeroBlur && GlassUtils.IsBlurBehindAvailable())
Expand All @@ -210,6 +212,9 @@ public MainWindow()
void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
CrashReporter.Report(e.Exception);

// cleanup subscriptions
ShutdownStartWindowActivation();

MessageBox.Show("WinLaunch just crashed!\nplease submit a bug report to winlaunch.official@gmail.com\nerror: " + e.Exception.Message);
Environment.Exit(1);
Expand Down Expand Up @@ -301,7 +306,7 @@ private void AddArgumentFiles()
}
}

#endregion Init
#endregion Init

#region Utils

Expand Down
48 changes: 44 additions & 4 deletions WinLaunch/MainWindow/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Security.Cryptography;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using Vanara.PInvoke;

namespace WinLaunch
{
Expand Down Expand Up @@ -186,6 +183,9 @@ private void miQuitClicked(object sender, RoutedEventArgs e)
{
if (MessageBox.Show(TranslationSource.Instance["CloseWarning"], TranslationSource.Instance["Quit"], MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
{
// cleanup any activation handlers we need to...
ShutdownStartWindowActivation();

PerformItemBackup();

hotCorner.Active = false;
Expand Down Expand Up @@ -667,6 +667,46 @@ private void InitWindowsKeyActivation()

#endregion WindowsKeyActivation

#region StartWindowActivation
private StartWindowActivation swa = new StartWindowActivation();

private void InitStartWindowActivation()
{
if (Settings.CurrentSettings.StartWindowActivationEnabled && !Settings.CurrentSettings.DeskMode)
{
HWND hwndStart = FindWindow("Windows.UI.Core.CoreWindow", "Start");
if (hwndStart != HWND.NULL)
{
// we hide it so we don't get any future flashes from it activating
User32.ShowWindow(hwndStart, ShowWindowCommand.SW_HIDE);
}

swa.StartListening((visible) =>
{
if (visible)
{
User32.SendMessage(hwndStart, User32.WindowMessage.WM_CLOSE);
ToggleLaunchpad();
}
});
}
}

private void ShutdownStartWindowActivation()
{
if (swa != null)
{
swa.StopListening();

HWND hwndStart = FindWindow("Windows.UI.Core.CoreWindow", "Start");
if (hwndStart != HWND.NULL)
{
User32.ShowWindow(hwndStart, ShowWindowCommand.SW_SHOW);
}
}
}
#endregion StartWindowActivation

#region MiddleMouseButtonActivator
MiddleMouseActivation middleMouseActivator = null;
DoubleClickEvent middleMouseDoubleClick = null;
Expand Down
22 changes: 15 additions & 7 deletions WinLaunch/MainWindow/GamepadControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,22 @@ private void ProcessInputForPlayer(PlayerIndex index)

private void GamepadLoop()
{
while (true)
try
{
ProcessInputForPlayer(PlayerIndex.One);
ProcessInputForPlayer(PlayerIndex.Two);
ProcessInputForPlayer(PlayerIndex.Three);
ProcessInputForPlayer(PlayerIndex.Four);

Thread.Sleep(20);
while (true)
{
ProcessInputForPlayer(PlayerIndex.One);
ProcessInputForPlayer(PlayerIndex.Two);
ProcessInputForPlayer(PlayerIndex.Three);
ProcessInputForPlayer(PlayerIndex.Four);

Thread.Sleep(20);
}
}
catch (DllNotFoundException)
{
// no gamepad dll shouldn't blow us up...
}
}

Expand All @@ -180,7 +188,7 @@ private void SendGamepadInput(Key key, PlayerIndex index)
{
if (Keyboard.PrimaryDevice.ActiveSource != null)
{
if(SBM != null)
if (SBM != null)
SBM.KeyDown(this, new System.Windows.Input.KeyEventArgs(Keyboard.PrimaryDevice, Keyboard.PrimaryDevice.ActiveSource, 0, key) { RoutedEvent = Keyboard.KeyDownEvent });

if (key == Key.Enter)
Expand Down
24 changes: 20 additions & 4 deletions WinLaunch/MainWindow/SettingsManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Interop;
using Vanara.PInvoke;

namespace WinLaunch
{
Expand All @@ -35,7 +36,7 @@ private void LoadSettings()
Settings.CurrentSettings.version = Assembly.GetExecutingAssembly().GetName().Version;
Settings.SaveSettings(Settings.CurrentSettings);

if(!StartHidden)
if (!StartHidden)
{
Welcome welcome = new Welcome();
welcome.ShowDialog();
Expand All @@ -62,6 +63,7 @@ private void InitSettings()
InitHotKey();
InitMiddleMouseButtonActivator();
InitWindowsKeyActivation();
InitStartWindowActivation();
InitDoubleKeytapActivation();

UpdateGridSettings();
Expand Down Expand Up @@ -97,6 +99,7 @@ private void ApplySettings()
UpdateHotCornerSettings();
UpdateMiddleMouseButtonActivator();
UpdateWindowsKeyActivation();
UpdateStartWindowActivation();
UpdateDoubleKeytapActivation();

UpdateGridSettings();
Expand Down Expand Up @@ -152,7 +155,7 @@ private void UpdateHotKeySettings()

return;
}


try
{
Expand Down Expand Up @@ -189,15 +192,28 @@ private void UpdateWindowsKeyActivation()
{
wka.StartListening();
}
else
else
{
wka.StopListening();
}
}

private void UpdateStartWindowActivation()
{
HWND hwndStart = FindWindow("Windows.UI.Core.CoreWindow", "Start");
if (Settings.CurrentSettings.StartWindowActivationEnabled && !Settings.CurrentSettings.DeskMode)
{
InitStartWindowActivation();
}
else
{
ShutdownStartWindowActivation();
}
}

private void UpdateDoubleKeytapActivation()
{
if(Settings.CurrentSettings.DoubleTapCtrlActivationEnabled ||
if (Settings.CurrentSettings.DoubleTapCtrlActivationEnabled ||
Settings.CurrentSettings.DoubleTapAltActivationEnabled)
{
if (Settings.CurrentSettings.DoubleTapCtrlActivationEnabled)
Expand Down
9 changes: 9 additions & 0 deletions WinLaunch/Properties/Resources.Designer.cs

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

Loading