How to tell if a newt window is maximized?

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

How to tell if a newt window is maximized?

GiGurra
On windows:

Is there any way to tell if a decorated newt window (created with GlWindow.create(....)) is maximized on a monitor?
I cant just ask if size + decoration == screen size because windows adds some wierd padding to the reported size when in a "maximized" state.

Tell me if you need more info, but an "isMaximized()" method would be really good here
Reply | Threaded
Open this post in threaded view
|

Re: How to tell if a newt window is maximized?

gouessej
Administrator
Hi

At first, NEWT is cross-platform, your problem is the same on any operating system, it is not windows-specific.

There is a method to set the top level size (including insets):
http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/newt/opengl/GLWindow.html#setTopLevelSize(int,%20int)

You can get the size of the insets here:
http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/newt/opengl/GLWindow.html#getInsets()

In my humble opinion, just get the screen size (look at my source code, in the main class, I do it without AWT) and use it with GLWindow.setTopLevelSize().
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: How to tell if a newt window is maximized?

Sven Gothel
Administrator
In reply to this post by GiGurra
On 02/22/2012 09:52 PM, GiGurra [via jogamp] wrote:

>
>
> On windows:
>
> Is there any way to tell if a decorated newt window (created with
> GlWindow.create(....)) is maximized on a monitor?
> I cant just ask if size + decoration == screen size because windows adds
> some wierd padding to the reported size when in a "maximized" state.
>
> Tell me if you need more info, but an "isMaximized()" method would be really
> good here
So you don't want to query 'isFullscreen()' - ok.

- The NEWT window size (getWidth()/getHeight() reflects
  client area excluding insets (window decorations),
  see API doc.

- You can get the decoration size of a visible window:
 'InsetsImmutable getInsets()'

- You can get the Screen's size:
  getScreen().getWidth() ...

- You can make your own query:
  if( screen.getWidth() <= window.getWidth() + insets.getTotalWidth() &&
      .. same for Height ..
    ) then I am maximized :)

~Sven


signature.asc (910 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to tell if a newt window is maximized?

Sven Gothel
Administrator
In reply to this post by GiGurra
On 02/23/2012 10:24 AM, Sven Gothel wrote:

> On 02/22/2012 09:52 PM, GiGurra [via jogamp] wrote:
>>
>>
>> On windows:
>>
>> Is there any way to tell if a decorated newt window (created with
>> GlWindow.create(....)) is maximized on a monitor?
>> I cant just ask if size + decoration == screen size because windows adds
>> some wierd padding to the reported size when in a "maximized" state.
>>
>> Tell me if you need more info, but an "isMaximized()" method would be really
>> good here
Sorry .. so you knew that already - good :)

No, I don't think we should pollute the API with all possible queries
and as demonstrated - you can do it easily.

As Julien mentioned I have polluted the API with 'setTopLevel..()'
methods already .. and I should have not, since those things just let
people ask for more redundancy, which is hard to maintain.

If you or others really want such API entries
wich are *already* possible to implement,
please file a bug report 'enhancement' and let's see how many folks
would love to have such functions .. -> democracy.

If something is *not* possible to implement
I love to add reasonable features right away, ofc.
However, it's always best to have an bug report.
Then you may like to add it yourself (after it's discussed a bit
and I pull from your repository.

~Sven

>
> So you don't want to query 'isFullscreen()' - ok.
>
> - The NEWT window size (getWidth()/getHeight() reflects
>   client area excluding insets (window decorations),
>   see API doc.
>
> - You can get the decoration size of a visible window:
>  'InsetsImmutable getInsets()'
>
> - You can get the Screen's size:
>   getScreen().getWidth() ...
>
> - You can make your own query:
>   if( screen.getWidth() <= window.getWidth() + insets.getTotalWidth() &&
>       .. same for Height ..
>     ) then I am maximized :)
>
> ~Sven


signature.asc (910 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to tell if a newt window is maximized?

gouessej
Administrator
setTopLevelSize was necessary because it would be tricky to set the size of the whole window by predicting the size of the insets after the resizing operation. However, I think that's enough. We should not add helpers requiring to make very dirty things to work. isMaximized() would have to compare the size of the window to the size of the current screen. What would happen if the window is displayed partially on one screen and on another one at the same time?
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: How to tell if a newt window is maximized?

GiGurra
In reply to this post by gouessej
Thats all good an well, but maybe I was not clear on this.
If you have a decorated maximized window, then the total insets + glwindow sizes will NOT be the same as the screen size.
Therefor, there is no way of detecting whether a window is maximized or not.

I do NOT need a way to set a window maximized, I merely need to detect if it is maximized, and windows adds extra padding to window sizes when maximized (more than just insets + size).

If you dont believe me I can create a quick application to show it for you.

Why is this interesting/important? Because I am building an application where I toggle decorated/undecorated to position windows on several screens. Therefor I need to be able to position maximized windows also OK. (I use the decorated variant to position it, then toggle to undecorated and save position to a config file - and it's important for the end users to also have this ability).

Worst case I'll need to make my own jni binding to do this in C, but I'd be much happier if I didnt have to add another dll dependency to my project. But the short answer is that getsize and insets do not return correct numbers when a window is maximized.
Reply | Threaded
Open this post in threaded view
|

Re: How to tell if a newt window is maximized?

Sven Gothel
Administrator
On 02/23/2012 06:32 PM, GiGurra [via jogamp] wrote:
>
>
> Thats all good an well, but maybe I was not clear on this.
> If you have a decorated maximized window, then the total insets + glwindow
> sizes will NOT be the same as the screen size.
> Therefor, there is no way of detecting whether a window is maximized or not.
>

You refer to the 'maximize windows button'
of the window decoration right ?

Whats the delta on the diff. platforms ?

And do you have an idea why this is ?

~Sven


signature.asc (910 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to tell if a newt window is maximized?

GiGurra
I dont know the exact delta on diff platforms :). But when I get home tonight I can give you a printout of what my windows 7 system reports.

But this delta is to do with how the system manages windows, it's not caused by JOGL (which is why I believe swing etc provides ways of querying whether a window is maximized or not). You would get the same delta if you write a C application which queries window size and position(for example using the FindWindow fcn on windows) on a maximized instance of Notepad.

Therefor it is important at least for me to be able to query specifically if a window is maximized. SetTopLevelX is of no use on the other hand since the same effect can be achieved with setSize/setPosition based on glWindow size, position and insets.
Reply | Threaded
Open this post in threaded view
|

Re: How to tell if a newt window is maximized?

GiGurra
Also, another reason why the maximized flag is important, is that the size of a maximized window will vary depending on if you have the start menu visible or not. To prove my statements above, I wrote the following small C code.

#include <stdio.h>
#include <stdlib.h>
#include "windows.h"

int main(void) {

        const HWND window = FindWindowA("Notepad", NULL);
        if (window != NULL) {
                RECT rect;
                GetWindowRect(window, &rect);
                printf("\n x: %ld", rect.left);
                printf("\n y: %ld", rect.top);
                printf("\n w: %ld", rect.right - rect.left);
                printf("\n h: %ld", rect.bottom - rect.top);
        }

        return EXIT_SUCCESS;
}
Reply | Threaded
Open this post in threaded view
|

Re: How to tell if a newt window is maximized?

Sven Gothel
Administrator
On 02/24/2012 10:57 AM, GiGurra [via jogamp] wrote:
>
>
> Also, another reason why the maximized flag is important, is that the size of
> a maximized window will vary depending on if you have the start menu visible
> or not.

Right - same is true for all platforms.
You made your point, thx.

Since you are familiar w/ the Windows GDI API it seems,
can you provide code snippest for the MINIMIZED / MAXIMIZED window queries ?

Would you like to add this feature to NEWT (at least partially) ?

Instead of adding a bunch of new methods, how about:

  Enum WindowState { MIN, MAX, ... }
  WindowState getWindowState();

Please complete enums .. and change it as you see fit.

Brainstorming:
History of NEWT already caused a bunch of Window state query methods,
so I dunno whats best .. add more, or 'renovate' those API.
If the latter is true we may add already handled states (decoration,
fullscreen, visible) to the above WindowState.
For compatibility - we can keep the dedicated methods ..

~Sven

> To prove my statements above, I wrote the following small C code.
>
> #include <stdio.h>
> #include <stdlib.h>
> #include "windows.h"
>
> int main(void) {
>
> const HWND window = FindWindowA("Notepad", NULL);
> if (window != NULL) {
> RECT rect;
> GetWindowRect(window, &rect);
> printf("\n x: %ld", rect.left);
> printf("\n y: %ld", rect.top);
> printf("\n w: %ld", rect.right - rect.left);
> printf("\n h: %ld", rect.bottom - rect.top);
> }
>
> return EXIT_SUCCESS;
> }


signature.asc (910 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to tell if a newt window is maximized?

GiGurra
Well Im really not familiar with windows window apis, I just looked that function up on google a time ago when I had to write a program that automatically repositioned some windows and changed their z order ;).

Would I like to add this feature to NEWT? Hmm.. Well I have no idea how I go about doing this in practice :). Can I reach you guys on msn or skype or similar IM (or maybe some active irc channel?). I'll likely need a bit of help doing this hehe.

No idea how I go about querying whether a window is maximized, but I'm sure I can look it up for windows at least. For other platforms I don't think I'm the right person to do it.

You can reach me on msn (ancient_banana_tmuk-----AT------hotmail.com, this is not an email address, just for msn purposes). (or maybe as admins you can see my email address I registered with on this forum?)

A quick google found these fcns on windows:
GetWindowPlacement can tell you if a window is maximized
and
ShowWindow can maximize a window