diff --git a/src/App.config b/src/App.config
index 12a0b6d..2abc67e 100644
--- a/src/App.config
+++ b/src/App.config
@@ -34,9 +34,24 @@
5
-
- True
+
+ 5
+
+ True
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+ True
+
\ No newline at end of file
diff --git a/src/MainModel.cs b/src/MainModel.cs
index de5fc25..1d5cf10 100644
--- a/src/MainModel.cs
+++ b/src/MainModel.cs
@@ -92,6 +92,16 @@ public int EdgeTolerance
}
}
+ public int CornerTolerance
+ {
+ get => Properties.Settings.Default.CornerTolerance;
+ set
+ {
+ Properties.Settings.Default.CornerTolerance = value;
+ Properties.Settings.Default.Save();
+ }
+ }
+
public bool EnableCtrlMute
{
get => Properties.Settings.Default.EnableCtrlMute;
@@ -102,6 +112,46 @@ public bool EnableCtrlMute
}
}
+ public bool EnableTopEdge
+ {
+ get => Properties.Settings.Default.EnableTopEdge;
+ set
+ {
+ Properties.Settings.Default.EnableTopEdge = value;
+ Properties.Settings.Default.Save();
+ }
+ }
+
+ public bool EnableRightEdge
+ {
+ get => Properties.Settings.Default.EnableRightEdge;
+ set
+ {
+ Properties.Settings.Default.EnableRightEdge = value;
+ Properties.Settings.Default.Save();
+ }
+ }
+
+ public bool EnableBottomEdge
+ {
+ get => Properties.Settings.Default.EnableBottomEdge;
+ set
+ {
+ Properties.Settings.Default.EnableBottomEdge = value;
+ Properties.Settings.Default.Save();
+ }
+ }
+
+ public bool EnableLeftEdge
+ {
+ get => Properties.Settings.Default.EnableLeftEdge;
+ set
+ {
+ Properties.Settings.Default.EnableLeftEdge = value;
+ Properties.Settings.Default.Save();
+ }
+ }
+
public static string TaskBarIconPath => GetTaskbarIconPath();
private static string GetTaskbarIconPath()
diff --git a/src/MainViewModel.cs b/src/MainViewModel.cs
index bdaef01..d78001e 100644
--- a/src/MainViewModel.cs
+++ b/src/MainViewModel.cs
@@ -38,6 +38,7 @@ public TriggerMode Mode
{
mainModel.Mode = value;
OnPropertyChanged();
+ OnPropertyChanged(nameof(IsCornersModeSelected));
OnPropertyChanged(nameof(IsEdgesModeSelected));
}
}
@@ -56,6 +57,8 @@ public bool EnableTopLeft
}
}
+ public bool IsCornersModeSelected => Mode == TriggerMode.ScreenCorners;
+
public bool IsEdgesModeSelected => Mode == TriggerMode.ScreenEdges;
public bool EnableTopRight
@@ -110,6 +113,19 @@ public int EdgeTolerance
}
}
+ public int CornerTolerance
+ {
+ get => mainModel.CornerTolerance;
+ set
+ {
+ if (mainModel.CornerTolerance != value)
+ {
+ mainModel.CornerTolerance = value;
+ OnPropertyChanged();
+ }
+ }
+ }
+
public bool EnableCtrlMute
{
get => mainModel.EnableCtrlMute;
@@ -123,6 +139,58 @@ public bool EnableCtrlMute
}
}
+ public bool EnableTopEdge
+ {
+ get => mainModel.EnableTopEdge;
+ set
+ {
+ if (mainModel.EnableTopEdge != value)
+ {
+ mainModel.EnableTopEdge = value;
+ OnPropertyChanged();
+ }
+ }
+ }
+
+ public bool EnableRightEdge
+ {
+ get => mainModel.EnableRightEdge;
+ set
+ {
+ if (mainModel.EnableRightEdge != value)
+ {
+ mainModel.EnableRightEdge = value;
+ OnPropertyChanged();
+ }
+ }
+ }
+
+ public bool EnableBottomEdge
+ {
+ get => mainModel.EnableBottomEdge;
+ set
+ {
+ if (mainModel.EnableBottomEdge != value)
+ {
+ mainModel.EnableBottomEdge = value;
+ OnPropertyChanged();
+ }
+ }
+ }
+
+ public bool EnableLeftEdge
+ {
+ get => mainModel.EnableLeftEdge;
+ set
+ {
+ if (mainModel.EnableLeftEdge != value)
+ {
+ mainModel.EnableLeftEdge = value;
+ OnPropertyChanged();
+ }
+ }
+ }
+
public void Dispose()
{
SystemEvents.UserPreferenceChanged -= UserPreferenceChanged;
diff --git a/src/MainWindow.xaml b/src/MainWindow.xaml
index 5d5e5c0..9dbe112 100644
--- a/src/MainWindow.xaml
+++ b/src/MainWindow.xaml
@@ -30,17 +30,14 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
@@ -108,19 +105,24 @@
Margin="0,3,0,3"
IsChecked="{Binding Mode, ConverterParameter=TaskbarAlways, Converter={StaticResource EnumBooleanConverter}}"
GroupName="TriggerMode" />
-
+
+
+
-
+
+ Visibility="{Binding IsCornersModeSelected, Converter={StaticResource BooleanToVisibilityConverter}}">
-
-
+
-
-
@@ -157,8 +159,8 @@
-
-
-
+
+
@@ -212,9 +214,101 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 5
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+ True
+
\ No newline at end of file
diff --git a/src/TriggerMode.cs b/src/TriggerMode.cs
index 5d5eadf..69eea4d 100644
--- a/src/TriggerMode.cs
+++ b/src/TriggerMode.cs
@@ -15,6 +15,11 @@ public enum TriggerMode
///
TaskbarVisibleOnly,
+ ///
+ /// Uses screen corners for triggering volume control
+ ///
+ ScreenCorners,
+
///
/// Uses screen edges for triggering volume control
///
diff --git a/src/Windows/AudioController.cs b/src/Windows/AudioController.cs
index 2538819..f80278a 100644
--- a/src/Windows/AudioController.cs
+++ b/src/Windows/AudioController.cs
@@ -71,14 +71,31 @@ private static void ChangeVolume(Action action)
{
0 => CursorInfoTaskbarAlways.IsOnTaskbar(),
1 => CursorInfoTaskbarVisible.IsOnTaskbar(),
- 2 => CursorInfoEdges.IsOnScreenEdges(Properties.Settings.Default.EnableBottomLeft,
- Properties.Settings.Default.EnableTopLeft,
- Properties.Settings.Default.EnableTopRight,
- Properties.Settings.Default.EnableBottomRight,
- Properties.Settings.Default.EdgeTolerance),
+ 2 => AppliesForCorners(),
+ 3 => AppliesForEdges(),
_ => false,
};
+ private static bool AppliesForCorners()
+ {
+ return CursorInfoCorners.IsOnScreenCorners(
+ Properties.Settings.Default.EnableBottomLeft,
+ Properties.Settings.Default.EnableTopLeft,
+ Properties.Settings.Default.EnableTopRight,
+ Properties.Settings.Default.EnableBottomRight,
+ Properties.Settings.Default.CornerTolerance);
+ }
+
+ private static bool AppliesForEdges()
+ {
+ return CursorInfoEdges.IsOnScreenEdges(
+ Properties.Settings.Default.EnableTopEdge,
+ Properties.Settings.Default.EnableRightEdge,
+ Properties.Settings.Default.EnableBottomEdge,
+ Properties.Settings.Default.EnableLeftEdge,
+ Properties.Settings.Default.EdgeTolerance);
+ }
+
public void Dispose()
{
mouseHook.Terminate();
diff --git a/src/Windows/CursorInfoCorners.cs b/src/Windows/CursorInfoCorners.cs
new file mode 100644
index 0000000..75b3be8
--- /dev/null
+++ b/src/Windows/CursorInfoCorners.cs
@@ -0,0 +1,79 @@
+namespace VolumeScroller;
+
+using System.Windows.Forms;
+
+public static class CursorInfoCorners
+{
+ public static bool IsOnScreenCorners(bool bottomLeft, bool topLeft, bool topRight, bool bottomRight, int tolerance)
+ {
+ Point cursorPos = GetCursorPosition();
+
+ foreach (Screen screen in Screen.AllScreens)
+ {
+ Rectangle rect = screen.Bounds;
+
+ if (bottomLeft && IsNearBottomLeft(cursorPos, rect, tolerance))
+ return true;
+
+ if (topLeft && IsNearTopLeft(cursorPos, rect, tolerance))
+ return true;
+
+ if (topRight && IsNearTopRight(cursorPos, rect, tolerance))
+ return true;
+
+ if (bottomRight && IsNearBottomRight(cursorPos, rect, tolerance))
+ return true;
+ }
+
+ return false;
+ }
+
+ private static bool IsNearBottomLeft(Point cursorPos, Rectangle rect, int tolerance)
+ {
+ return cursorPos.X >= rect.Left &&
+ cursorPos.X <= rect.Left + tolerance &&
+ cursorPos.Y >= rect.Bottom - tolerance &&
+ cursorPos.Y <= rect.Bottom;
+ }
+
+ private static bool IsNearTopLeft(Point cursorPos, Rectangle rect, int tolerance)
+ {
+ return cursorPos.X >= rect.Left &&
+ cursorPos.X <= rect.Left + tolerance &&
+ cursorPos.Y >= rect.Top &&
+ cursorPos.Y <= rect.Top + tolerance;
+ }
+
+ private static bool IsNearTopRight(Point cursorPos, Rectangle rect, int tolerance)
+ {
+ return cursorPos.X >= rect.Right - tolerance &&
+ cursorPos.X <= rect.Right &&
+ cursorPos.Y >= rect.Top &&
+ cursorPos.Y <= rect.Top + tolerance;
+ }
+
+ private static bool IsNearBottomRight(Point cursorPos, Rectangle rect, int tolerance)
+ {
+ return cursorPos.X >= rect.Right - tolerance &&
+ cursorPos.X <= rect.Right &&
+ cursorPos.Y >= rect.Bottom - tolerance &&
+ cursorPos.Y <= rect.Bottom;
+ }
+
+ private static Point GetCursorPosition()
+ {
+ GetCursorPos(out POINT point);
+ return new Point(point.X, point.Y);
+ }
+
+ [DllImport("user32.dll", SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ private static extern bool GetCursorPos(out POINT lpPoint);
+
+ [StructLayout(LayoutKind.Sequential)]
+ private struct POINT
+ {
+ public int X;
+ public int Y;
+ }
+}
diff --git a/src/Windows/CursorInfoEdges.cs b/src/Windows/CursorInfoEdges.cs
index 8186ed3..7ec4e54 100644
--- a/src/Windows/CursorInfoEdges.cs
+++ b/src/Windows/CursorInfoEdges.cs
@@ -1,105 +1,79 @@
-namespace VolumeScroller;
+namespace VolumeScroller;
using System.Windows.Forms;
public static class CursorInfoEdges
{
- public static bool IsOnScreenEdges(bool bottomLeft, bool topLeft, bool topRight, bool bottomRight, int tolerance)
+ public static bool IsOnScreenEdges(bool top, bool right, bool bottom, bool left, int tolerance)
{
- // Get the current cursor position
Point cursorPos = GetCursorPosition();
- // Check all screens
foreach (Screen screen in Screen.AllScreens)
{
Rectangle rect = screen.Bounds;
- // Check if the cursor is near the enabled edges for this screen
- if (bottomLeft && IsNearBottomLeft(cursorPos, rect, tolerance))
- return true;
-
- if (topLeft && IsNearTopLeft(cursorPos, rect, tolerance))
- return true;
-
- if (topRight && IsNearTopRight(cursorPos, rect, tolerance))
- return true;
-
- if (bottomRight && IsNearBottomRight(cursorPos, rect, tolerance))
+ if (IsNearSelectedEdges(cursorPos, rect, top, right, bottom, left, tolerance))
return true;
}
return false;
}
- private static bool IsNearBottomLeft(Point cursorPos, Rectangle rect, int tolerance)
+ private static bool IsNearSelectedEdges(Point cursorPos, Rectangle rect, bool top, bool right, bool bottom, bool left, int tolerance)
{
- return cursorPos.X >= rect.Left &&
- cursorPos.X <= rect.Left + tolerance &&
- cursorPos.Y >= rect.Bottom - tolerance &&
- cursorPos.Y <= rect.Bottom;
- }
+ if (top)
+ {
+ bool nearTop = cursorPos.Y >= rect.Top &&
+ cursorPos.Y <= rect.Top + tolerance &&
+ cursorPos.X >= rect.Left &&
+ cursorPos.X <= rect.Right;
+ if (nearTop) return true;
+ }
- private static bool IsNearTopLeft(Point cursorPos, Rectangle rect, int tolerance)
- {
- return cursorPos.X >= rect.Left &&
- cursorPos.X <= rect.Left + tolerance &&
- cursorPos.Y >= rect.Top &&
- cursorPos.Y <= rect.Top + tolerance;
- }
+ if (right)
+ {
+ bool nearRight = cursorPos.X >= rect.Right - tolerance &&
+ cursorPos.X <= rect.Right &&
+ cursorPos.Y >= rect.Top &&
+ cursorPos.Y <= rect.Bottom;
+ if (nearRight) return true;
+ }
- private static bool IsNearTopRight(Point cursorPos, Rectangle rect, int tolerance)
- {
- return cursorPos.X >= rect.Right - tolerance &&
- cursorPos.X <= rect.Right &&
- cursorPos.Y >= rect.Top &&
- cursorPos.Y <= rect.Top + tolerance;
- }
+ if (bottom)
+ {
+ bool nearBottom = cursorPos.Y >= rect.Bottom - tolerance &&
+ cursorPos.Y <= rect.Bottom &&
+ cursorPos.X >= rect.Left &&
+ cursorPos.X <= rect.Right;
+ if (nearBottom) return true;
+ }
- private static bool IsNearBottomRight(Point cursorPos, Rectangle rect, int tolerance)
- {
- return cursorPos.X >= rect.Right - tolerance &&
- cursorPos.X <= rect.Right &&
- cursorPos.Y >= rect.Bottom - tolerance &&
- cursorPos.Y <= rect.Bottom;
+ if (left)
+ {
+ bool nearLeft = cursorPos.X >= rect.Left &&
+ cursorPos.X <= rect.Left + tolerance &&
+ cursorPos.Y >= rect.Top &&
+ cursorPos.Y <= rect.Bottom;
+ if (nearLeft) return true;
+ }
+
+ return false;
}
- static Point GetCursorPosition()
+ private static Point GetCursorPosition()
{
GetCursorPos(out POINT point);
return new Point(point.X, point.Y);
}
- delegate bool EnumWindowsProc(IntPtr hWnd, int lParam);
-
- [DllImport("USER32.DLL")]
- static extern bool EnumWindows(EnumWindowsProc enumFunc, int lParam);
-
- [DllImport("USER32.DLL")]
- static extern IntPtr GetShellWindow();
-
- [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
- static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
-
- [DllImport("user32.dll", SetLastError = true)]
- static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect);
-
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
- static extern bool GetCursorPos(out POINT lpPoint);
+ private static extern bool GetCursorPos(out POINT lpPoint);
[StructLayout(LayoutKind.Sequential)]
- struct POINT
+ private struct POINT
{
public int X;
public int Y;
}
-
- [StructLayout(LayoutKind.Sequential)]
- struct RECT
- {
- public int Left;
- public int Top;
- public int Right;
- public int Bottom;
- }
-}
\ No newline at end of file
+}