-
-
Notifications
You must be signed in to change notification settings - Fork 679
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
Allow window dragging when maximized (from title bar) #36
Comments
WindowChrome has all the functionality of a standard window, except for snap layouts. Dragging does not work because of this https://github.com/lepoco/wpfui/blob/main/WPFUI/Styles/Controls/Window.xaml#L50 Increase it to 40-50 and it will work, but the Titlebar buttons will become inactive. To fix that, you need to add this for each button Btw, snap layout, I do not know how it is implemented, but I think it is buggy. |
@MajorXAML good callout on the caption height and WindowChrome however I think this is a bit more complicated. The style comment indicates the caption height being set to 1 is a workaround to some theming issues, (I think) related to using wpfui/WPFUI/Styles/Controls/Window.xaml Line 35 in 2ff8a5c
Additionally, we have to contend with the Since Edit: fixed some line links |
Sorry for the comment spam but just wanted to add while fresh in my mind -- There may be some hacky Win32 voodoo we could try strictly when the mouse drags on the |
I've already tried a bit of Win32 parkour with SnapLayout, and I don't really like these sloppy workarounds. I think it's best to dig in here and try to get something out |
After doing a bit more digging it seems like we can set the Not sure if it makes more sense to subscribe to
In this case, I was specifically avoiding calling This actually works pretty good for the maximize-->drag functionality. As you can see in the implementation, we have to change the WindowStyle to The only snag I have with this is seeing like a frame or two of jank -- I can't quite put my finger on what's causing it, but it seems it's either the rendering while the WindowStyle is set to Edit: adding gif to show working POC, unfortunately this doesn't capture the frame of jank And here's a quick screen cap of the resize jank frame: |
Implement window dragging when maximized (fix #36)
@Aelarion When dragged from the edge in the multi-monitor setup it throws the application to the side. |
Also, double-click stopped working sometimes |
@pomianowski hmm, I tried this across 2 side by side monitors, I'm not able to reproduce the issue. I also am not sure how double clicking would be effected, I can't reproduce that issue either. Unless there's somewhere that the MouseMove event is stepping on the MouseDown event I think definitely an issue to address though is this line: wpfui/WPFUI/Controls/TitleBar.cs Line 484 in a0795c3
I didn't consider this before but in a multi-monitor setup, where the "top" screen coordinates might be negative, this would cause monitor jumping. Definitely can fix setting to Can you just try that workaround to see if it helps with the window jumping? It's the only thing I can think of, other than maybe the wpfui/WPFUI/Controls/TitleBar.cs Line 483 in a0795c3
|
Just tried scaling my monitor DPI way up to 150%, yup that was the problem. That's my own fault for not RTFM'ing on I will work on a fix for this -- essentially would just need to account for the scaling and multiple the final |
@Aelarion, I think this is due to the rather non-standard size and asymmetrical arrangement, DPI can also be a problem because it was already troublesome with SnapLayout |
Just troubleshooting with DPI scaling, I can get this working, the only issue I see is in .NET Framework 4.6 Can you see if this works for you? The asymmetrical window arrangement will have to be a separate issue I tackle -- just want to get the basic math stuff right first. private void RootGrid_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton != MouseButtonState.Pressed || ParentWindow == null) return;
if (IsMaximized)
{
var dpiXProperty = typeof(SystemParameters).GetProperty("DpiX", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
var dpiYProperty = typeof(SystemParameters).GetProperty("Dpi", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
var dpiX = (int)dpiXProperty.GetValue(null, null);
var dpiY = (int)dpiYProperty.GetValue(null, null);
//var dpi = VisualTreeHelper.GetDpi(ParentWindow); --> not available in .NET 4.6
var screenPoint = PointToScreen(e.MouseDevice.GetPosition(this));
screenPoint.X *= (96.0 / dpiX);
screenPoint.Y *= (96.0 / dpiY);
// TODO: refine the Left value to be more accurate
// - This calculation is good enough using the center
// of the titlebar, however this isn't quite accurate for
// how the OS operates.
// - It should be set as a % (e.g. screen X / maximized width),
// then offset from the left to line up more naturally.
//ParentWindow.Left = dpi.DpiScaleX * (screenPoint.X - (ParentWindow.RestoreBounds.Width * 0.5));
//ParentWindow.Top = dpi.DpiScaleY * screenPoint.Y;
ParentWindow.Left = screenPoint.X - (ParentWindow.RestoreBounds.Width * 0.5);
ParentWindow.Top = screenPoint.Y;
// style has to be quickly swapped to avoid restore animation delay
var style = ParentWindow.WindowStyle;
ParentWindow.WindowStyle = WindowStyle.None;
ParentWindow.WindowState = WindowState.Normal;
ParentWindow.WindowStyle = style;
ParentWindow.DragMove();
}
} EDIT: fixed typo for DPI Y property ("Dpi" not "DpiY") |
It begins to seem to me that this class has too much responsibility, can you set up a separate class to manage DPI and screen stuff? |
@pomianowski agreed, will do when I get some more time tonight. Can you just confirm when you have time to test that the above code works for the window jumping issue you were seeing? |
Hey @Aelarion, the DPI tweaks you added greatly improve the window drag behavior. In any case, double-click still randomly does not work. I don't always get the error, but if I have one Demo app open in the debugger and open a second instance of the application outside of Visual Studio, the second instance easily generates this bug. I think the app sometimes catches (click + drag + click) instead of (click + click), thus triggering the swipe and ignoring the double-click maximization. Or (click + click (hold) + drag), as a result, it maximizes and restores immediately. |
@pomianowski glad to hear it! On the double click issue that would definitely make sense (click + drag). I don't want to overstep my bounds but I think maybe we should open a separate issue for the double click / drag clash, seems like maybe we have an opportunity to clean up some logic in the event handlers. |
@Aelarion sure, please send your DPI correction in new PR and I will make a new issue related to double click. |
This is a standard feature in windows app.
Main window should be able to be moved when it's maximized as a standard Windows application.
When the drag starts, the window should automaticaly return to its last "normal" size.
The text was updated successfully, but these errors were encountered: