mika76 / mamesaver

Mamesaver is a mame emulated screensaver - get all the good ol' games playing their demo modes while you procrastinate and enjoy!
https://mika76.github.io/mamesaver/
MIT License
37 stars 10 forks source link

Detect best primary monitor for running mame #20

Closed andyvans closed 6 years ago

andyvans commented 6 years ago
  1. Instead of using the primary monitor for MAME, detect the best monitor to run MAME on by picking the monitor with the greatest Y axis. This is because MAME games are usually 4x3 or 3x4, but screens are largely 16x9.
  2. Remove an unused function in CaptureScreen.
mika76 commented 6 years ago

Awesome man, I'll try it out this morning...

mika76 commented 6 years ago

Hey @andyvans - The mame game works like a bomb 💣 - but the splash screen is still not stretching...

andyvans commented 6 years ago

Hey @mika76 what resolutions are your monitors?

All the details should be in log file in %temp%\mamesaver\logs. I suspect I need to grab the right amount of the source/destination Rect when they have different ratios.

mika76 commented 6 years ago

Argh! Sorry I totally forgot to post the log

Here's the relevant bits...

2018-08-29 09:57:23.876 +02:00 [INF] Mamesaver started with args /S
2018-08-29 09:57:23.919 +02:00 [INF] Invoking MAME with arguments: -showconfig
2018-08-29 09:57:23.937 +02:00 [INF] Initialised primary MAME screen
2018-08-29 09:57:23.977 +02:00 [INF] Source screen found \\.\DISPLAY2 {X=-1920,Y=0,Width=1920,Height=1080}
2018-08-29 09:57:23.977 +02:00 [INF] Destination screen found \\.\DISPLAY1 {X=0,Y=0,Width=1440,Height=900}
2018-08-29 09:57:27.013 +02:00 [INF] Running game Moon Patrol 1982 Irem on display \\.\DISPLAY2
2018-08-29 09:57:27.048 +02:00 [INF] Invoking MAME with arguments: -showconfig
2018-08-29 09:57:27.149 +02:00 [INF] Invoking MAME with arguments: mpatrol -skip_gameinfo -nowindow -noswitchres -sleep -triplebuffer -sound none -screen "\\.\DISPLAY2" -artpath D:\MAME\artwork;C:\Users\mmiha\AppData\Local\Temp\Mamesaver\Layouts
2018-08-29 09:58:10.418 +02:00 [INF] Closing screen \\.\DISPLAY1
2018-08-29 09:58:10.429 +02:00 [INF] Closing primary MAME screen \\.\DISPLAY2
2018-08-29 09:58:10.554 +02:00 [INF] Closing screen \\.\DISPLAY2
2018-08-29 09:58:10.561 +02:00 [DBG] BlankScreen Dispose()
2018-08-29 09:58:10.561 +02:00 [DBG] MameScreen Dispose()
2018-08-29 09:58:10.561 +02:00 [DBG] BlankScreen Dispose()
2018-08-29 09:58:10.563 +02:00 [DBG] MameScreen Dispose()
2018-08-29 09:58:10.569 +02:00 [DBG] LayoutBuilder Dispose()
2018-08-29 09:58:15.450 +02:00 [DBG] MameScreen Dispose()

Basically I have a laptop 1920x1080 and a screen (same res) - I change the screen to 1440x900 and then try it - the splash opens small (not covering the whole screen) but mame works fine now...

mika76 commented 6 years ago

PS: Would probably be a good idea to log the chosen configs before running the screen saver...

andyvans commented 6 years ago

Hmm. I can't reproduce this. Are you saying that the splash screen on the 1440x900 monitor doesn't cover the entire screen at first, but then resizes once mame starts?

mika76 commented 6 years ago

Interestingly it looks like this on both screens:

20180829141745

I assume it's not opening full screen on the larger resolution but then getting cloned to the larger resolution...

mika76 commented 6 years ago

PS: I accepted a PR from @nullpainter so you might want to merge from master...

nullpainter commented 6 years ago

It's not anything silly to do with a high pixel density display, is it @andyvans? That logo isn't even centred...

mika76 commented 6 years ago

I can try a debug it maybe tomorrow if I have time in case you still can't re-create...

andyvans commented 6 years ago

Hi @mika76. I think I have a solution. It is related to the high dpi screen you have. Windows tells lies to non-highdpi aware applications. That is why the screen is small.

mika76 commented 6 years ago

Hey @andyvans thanks - I'll give it a try as soon as I can...

mika76 commented 6 years ago

Just tried the last commit - same result - not covering the whole screen...

andyvans commented 6 years ago

Ok. Thanks. I will have a go with a high dpi screen in the weekend.

mika76 commented 6 years ago

I cloned your repo so will try debug myself and see if I can help out - only thing is I'm kinda busy today and travelling tonight so might only get to it over the weekend. Will keep you posted...

mika76 commented 6 years ago

I managed to have a quick look and I think I might know what is causing the issue (config wise not code wise)

I have a laptop to which I've connected a screen. The external screen is set to the Main Display and is the one that I drop the resolution of to 1600x or 1400x. If I change the Main Display to be the laptop (larger res) screen then all works fine.

I assume there is some issue in CaptureScreen and what handle it's getting for the DesktopWindow maybe?

mika76 commented 6 years ago

This might come in useful: https://stackoverflow.com/questions/28261311/multiple-screen-capture-with-msdn-library or https://www.codeproject.com/Articles/546006/Screen-Capture-on-Multiple-Monitors

mika76 commented 6 years ago

I just can't seem to figure it out - but an interesting anecodote is that if I change the BackgroundForm.FormBorderStyle from None to something else like Sizeable then it seems to fill the screen (albeit with the border which looks crap)

mika76 commented 6 years ago

So setting the border to it's normal Sizeable and then using SetWindowLong to a compatible style seems to get us most of the way - I just have not been able to get rid of the caption AND the border...

mika76 commented 6 years ago

Hey @andyvans I merged #22 but I see this has now caused a conflict - sorry about that - I was trying to get to the bottom of the small window mystery and thought I'd merge after that but now I've caused a problem. Would you mind updating?

mika76 commented 6 years ago

The most interesting of article so far about this issue: https://stackoverflow.com/questions/22874211/setwindowpos-and-multiple-monitors-with-different-resolutions

andyvans commented 6 years ago

@mika76 done. I had a go the in weekend, but still cannot reproduce the issue. I think it is because the only high dpi monitor I have is only my laptop.

andyvans commented 6 years ago

And I just fixed the logging of the dpi details. It now shows

2018-09-03 09:53:04.531 +12:00 [INF] Blank screen resized \\.\DISPLAY2 {X=-1920,Y=0,Width=1920,Height=1080} xDpi 96 yDpi 96 2018-09-03 09:53:04.550 +12:00 [INF] Blank screen resized \\.\DISPLAY1 {X=0,Y=0,Width=1920,Height=1080} xDpi 96 yDpi 96

andyvans commented 6 years ago

Regarding that SO post above, perhaps the window first needs to be moved to the selected screen and then resized. Not sure. Just an idea

andyvans commented 6 years ago

Basically I have a laptop 1920x1080 and a screen (same res) - I change the screen to 1440x900 and then try

@mika76 do you only see the problem when running screens at non-native resolutions? Was this because you enjoy 1440x900 🤢 or you were testing the cloning at different resolutions?

nullpainter commented 6 years ago

Also, was the issue still present after rebooting / logging off? I've been able to replicate it, but haven't investigated yet if it is a persistent or temporary issue.

FWIW, my primary monitor isn't high DPI but my laptop is.

andyvans commented 6 years ago

@mika76 Give the latest a go (commit id 80255c6). While you may see some temporary window resizing, I think it sorts itself out now and runs in full screen.

mika76 commented 6 years ago

Hey @andyvans unfortunately the last commit didn't do anything different. But I think I figured it out...

diff --git a/Mamesaver/BackgroundForm.Designer.cs b/Mamesaver/BackgroundForm.Designer.cs
index 5b32aad..e3f0de5 100644
--- a/Mamesaver/BackgroundForm.Designer.cs
+++ b/Mamesaver/BackgroundForm.Designer.cs
@@ -103,9 +103,7 @@ namespace Mamesaver
             this.ShowIcon = false;
             this.ShowInTaskbar = false;
             this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
-            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
             this.TopMost = true;
-            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
             ((System.ComponentModel.ISupportInitialize)(this.mameLogo)).EndInit();
             this.ResumeLayout(false);

It seems by removing the FormWindowState.Maximized it solved the issue - I removed the startup position as well since SetWindowPos does the work for you.

andyvans commented 6 years ago

Cool. Good spotting. I had added that change to my branch

mika76 commented 6 years ago

Fantastic - Mamesaver is looking and working so nice now 😄