RickStrahl / SetResolution

Quickly set Windows Display Resolution via Command Line
Other
124 stars 5 forks source link

Cannot change orientation #4

Closed portal08 closed 8 months ago

portal08 commented 1 year ago

What I'm doing wrong? I use the following command to try to rotate the monitor 90 degrees:

SetResolution.exe SET -w 1920 -h 1080 -o 1 -m2

I get "Couldn't find a matching Display Mode."

If I omit the '-o 1' it sets resolution just fine. Any ideas? Thanks

afarouk commented 5 months ago

Hi, We notice that you have closed this issue as 'not planned'. Is it possible to reopen this issue? We tried using this and had the same result. We tried to look into the source code and notice that there seems to be a type for 'Orientation', while everything else is just int, and the parser is parsing the -o argument into type 'Orientation', etc. If I understand it correctly, this should be unnecessary and we just need to parse orientation into an int (like other arguments), and that should work. However, I am from Java and not familiar with CSharp and may have misunderstood the code.

You tool is very helpful for us, so thanks for the work you have done already.

--Alamgir

RickStrahl commented 5 months ago

The -o argument is parsed into an enum which translates to an int value that is set. I'm setting it here in SetDisplaySettings()

mode.dmDisplayOrientation = (uint)set.Orientation;

The value is getting set - the API call however is not respecting it it looks like.

When I try to set the orientation to anything other than zero it tells me I'm using an invalid mode, which is correct as my monitor doesn't support changing orientation.

afarouk commented 5 months ago

I may have found the solution or answer. The microsoft API seems to require all values including the orientation for every command. If it is not included, it defaults to 0 (or landscape). Then... based on the landscape orientation, it gives an error claiming that the resolution is not available (1080x1920), which is correct IF the orientation is landscape. If we set the orientation to 1 (portrait), then the command works fine and the resolution is changed.

In short, we have to specify the orientation in every command, even though it happens to be the current orientation.

So, neither your code nor microsoft has any bugs, but it is an ugly API that ignores current orientation and assumes the default when orientation is not provided. You can update your documentation, if you have time. Also, since we are switching orientation in our monitors quite frequently, I would be happy to do any testing for you.

Once again, thank you for your efforts.

afarouk commented 5 months ago

In the case of the original issue, he has to specify orientation as 0 (as he found out), and that is the correct behavior.

RickStrahl commented 5 months ago

That is correct - you always have to specify the orientation as that's part of the command. The tool doesn't read the current orientation so we can't assume that orientation. It would also be hard to make consistent.

The default is landscape since 99% of monitors run in that mode - so the Microsoft and our default is senisible.

Bottom line you have to be explicit, except if you're expecting the default.