From fbe6b38edcdbf8b4df4120f1bc23cc5676ce21dd Mon Sep 17 00:00:00 2001 From: John Colvin Date: Sat, 27 Apr 2019 12:01:06 -0500 Subject: [PATCH] simplify ensure_onscreen code (since end of cycle approaches, disable by default with config) --- .../spark/view/Extensions/WindowExtensions.cs | 29 ++++++++++++------- src/lib/config/protos/toggles.proto | 7 +++++ 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/client/spark/view/Extensions/WindowExtensions.cs b/src/client/spark/view/Extensions/WindowExtensions.cs index dd2608223..dbe54c3ae 100644 --- a/src/client/spark/view/Extensions/WindowExtensions.cs +++ b/src/client/spark/view/Extensions/WindowExtensions.cs @@ -1,18 +1,15 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using mbts.ui.native; +using mbts.ui.shell; +using System; using System.Runtime.InteropServices; -using System.Text; using System.Windows; using System.Windows.Interop; using System.Windows.Media; -using mbts.ui.native; -using mbts.ui.shell; -namespace mbts.ui -{ - public static class WindowExtensions - { +namespace mbts.ui { + static class WindowExtensions { + static readonly bool _ensure_onscreen_with_work_area_rect = config.Configuration.get().enabled; + public static Rect bounds(this Window window) { return new Rect(window.Left, window.Top, window.ActualWidth, window.ActualHeight); } @@ -111,6 +108,18 @@ namespace mbts.ui MONITORINFO minfo = new MONITORINFO(); minfo.cbSize = Marshal.SizeOf(minfo); if (NativeMethods.GetMonitorInfo(hmonitor, ref minfo)) { + if (_ensure_onscreen_with_work_area_rect) { + var work_area_rect = new Rect(minfo.rcWork.Left, minfo.rcWork.Top, minfo.rcWork.Width, minfo.rcWork.Height); + var transform = get_transform_from_device(window); + work_area_rect.Transform(transform); + double y_off = (window.Top + window.Height) - work_area_rect.Bottom; + if (y_off > 0) + window.Top -= y_off; + double x_off = (window.Left + window.Width) - work_area_rect.Right; + if (x_off > 0) + window.Left -= x_off; + return; + } // if the screen and workarea upper left and lower right coords are the same, there is no // taskbar on this screen var no_taskbar_on_screen = (minfo.rcMonitor.Top == minfo.rcWork.Top && minfo.rcMonitor.Left == minfo.rcWork.Left && diff --git a/src/lib/config/protos/toggles.proto b/src/lib/config/protos/toggles.proto index 85063637b..c66a3fe8d 100644 --- a/src/lib/config/protos/toggles.proto +++ b/src/lib/config/protos/toggles.proto @@ -34,4 +34,11 @@ message VolumeAtPrice{ message FixNestedScrolling { optional bool enabled = 1 [default = true]; +} + +message EnsureOnScreenWithWorkAreaRect { + // Defaulting to false bc this is near the end of the cycle (04/27/2019), + // and the new ensure_onscreen code has only been tested with a single monitor arrangement. + // Should verify that the code works with every monitor arrangement before enabling by default. + optional bool enabled = 1 [default = false]; } \ No newline at end of file