From 6633f72dd736428d1f397c70ca6043c35dd6fb23 Mon Sep 17 00:00:00 2001 From: flashwave Date: Fri, 26 Aug 2022 01:55:31 +0200 Subject: [PATCH] v1.3.0 - 2020-01-12 --- TopMostFriend/Program.cs | 33 ++++++++++++++++++------ TopMostFriend/Properties/AssemblyInfo.cs | 6 ++--- TopMostFriend/SettingsWindow.cs | 17 +++++++----- 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/TopMostFriend/Program.cs b/TopMostFriend/Program.cs index 7153c0c..1a4eb80 100644 --- a/TopMostFriend/Program.cs +++ b/TopMostFriend/Program.cs @@ -34,6 +34,8 @@ namespace TopMostFriend { public const string LIST_BACKGROUND_PATH_SETTING = @"ListBackgroundPath"; public const string LIST_BACKGROUND_LAYOUT_SETTING = @"ListBackgroundLayout"; public const string ALWAYS_ADMIN_SETTING = @"RunAsAdministrator"; + public const string TOGGLE_BALLOON_SETTING = @"ShowNotificationOnHotKey"; + public static readonly bool ToggleBalloonDefault = Environment.OSVersion.Version.Major < 10; [STAThread] public static void Main(string[] args) { @@ -60,6 +62,9 @@ namespace TopMostFriend { Settings.SetDefault(FOREGROUND_HOTKEY_SETTING, 0); Settings.SetDefault(ALWAYS_ADMIN_SETTING, false); + // Defaulting to false on Windows 10 because it uses the stupid, annoying and intrusive new Android style notification system + // This would fucking piledrive the notification history and also just be annoying in general because intrusive + Settings.SetDefault(TOGGLE_BALLOON_SETTING, ToggleBalloonDefault); if (Settings.Get(ALWAYS_ADMIN_SETTING) && !IsElevated()) { Elevate(); @@ -205,7 +210,7 @@ namespace TopMostFriend { return (flags.ToInt32() & Win32.WS_EX_TOPMOST) > 0; } - public static void SetTopMost(IntPtr hWnd, bool state) { + public static bool SetTopMost(IntPtr hWnd, bool state) { Win32.SetWindowPos( hWnd, new IntPtr(state ? Win32.HWND_TOPMOST : Win32.HWND_NOTOPMOST), 0, 0, 0, 0, Win32.SWP_NOMOVE | Win32.SWP_NOSIZE | Win32.SWP_SHOWWINDOW @@ -225,19 +230,34 @@ namespace TopMostFriend { if (result == DialogResult.Yes) Elevate($@"--hwnd={hWnd}"); - return; + return false; } if (state) Win32.SwitchToThisWindow(hWnd, false); + + return true; } public static void ToggleForegroundWindow() { - ToggleWindow(Win32.GetForegroundWindow()); + IntPtr hWnd = Win32.GetForegroundWindow(); + + if (ToggleWindow(hWnd)) { + if (Settings.Get(TOGGLE_BALLOON_SETTING, false)) { + string title = Win32.GetWindowTextString(hWnd); + + SysIcon.ShowBalloonTip( + 500, + IsTopMost(hWnd) ? @"Always on top" : @"No longer always on top", + string.IsNullOrEmpty(title) ? @"Window has no title." : title, + ToolTipIcon.Info + ); + } + } } - public static void ToggleWindow(IntPtr hWnd) { - SetTopMost(hWnd, !IsTopMost(hWnd)); + public static bool ToggleWindow(IntPtr hWnd) { + return SetTopMost(hWnd, !IsTopMost(hWnd)); } private static Icon GetWindowIcon(IntPtr hWnd) { @@ -291,9 +311,6 @@ namespace TopMostFriend { } private static void SysIcon_MouseDown(object sender, MouseEventArgs e) { - if (e.Button.HasFlag(MouseButtons.Left)) - ToggleForegroundWindow(); - if (e.Button.HasFlag(MouseButtons.Right)) RefreshWindowList(); } diff --git a/TopMostFriend/Properties/AssemblyInfo.cs b/TopMostFriend/Properties/AssemblyInfo.cs index ae6c9c4..16009c3 100644 --- a/TopMostFriend/Properties/AssemblyInfo.cs +++ b/TopMostFriend/Properties/AssemblyInfo.cs @@ -9,7 +9,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyDescription("Provides a dingus that lets you make anything topmost.")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("flashwave")] -[assembly: AssemblyProduct("TopMostFriend.Properties")] +[assembly: AssemblyProduct("TopMostFriend")] [assembly: AssemblyCopyright("flashwave 2020")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("1.2.0.0")] -[assembly: AssemblyFileVersion("1.2.0.0")] +[assembly: AssemblyVersion("1.3.0.0")] +[assembly: AssemblyFileVersion("1.3.0.0")] diff --git a/TopMostFriend/SettingsWindow.cs b/TopMostFriend/SettingsWindow.cs index d6add69..4d27bd3 100644 --- a/TopMostFriend/SettingsWindow.cs +++ b/TopMostFriend/SettingsWindow.cs @@ -1,9 +1,5 @@ using System; -using System.Collections.Generic; using System.Drawing; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; using System.Windows.Forms; namespace TopMostFriend { @@ -28,6 +24,7 @@ namespace TopMostFriend { public readonly CheckBox FgModShift; public readonly CheckBox FlAlwaysAdmin; + public readonly CheckBox FlToggleNotification; public SettingsWindow() { Text = @"Top Most Friend Settings"; @@ -35,7 +32,7 @@ namespace TopMostFriend { StartPosition = FormStartPosition.CenterScreen; FormBorderStyle = FormBorderStyle.FixedSingle; AutoScaleMode = AutoScaleMode.Dpi; - ClientSize = new Size(410, 163); + ClientSize = new Size(410, 183); MinimizeBox = MaximizeBox = false; MinimumSize = MaximumSize = Size; @@ -72,7 +69,7 @@ namespace TopMostFriend { GroupBox flagsGroup = new GroupBox { Text = @"Flags", Location = new Point(6, 76), - Size = new Size(Width - 18, 50), + Size = new Size(Width - 18, 70), }; Controls.AddRange(new Control[] { @@ -140,8 +137,14 @@ namespace TopMostFriend { Checked = Settings.Get(Program.ALWAYS_ADMIN_SETTING, false), AutoSize = true, }; + FlToggleNotification = new CheckBox { + Text = @"Show notification when using toggle hotkey", + Location = new Point(10, 40), + Checked = Settings.Get(Program.TOGGLE_BALLOON_SETTING, Program.ToggleBalloonDefault), + AutoSize = true, + }; - flagsGroup.Controls.Add(FlAlwaysAdmin); + flagsGroup.Controls.AddRange(new[] { FlAlwaysAdmin, FlToggleNotification }); } private void FgReset_Click(object sender, EventArgs e) {