Send the Stack to the Center of the screen.

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Send the Stack to the Center of the screen.

Post by Klaus » Wed Dec 13, 2023 11:30 am

Hi Richmond,
produces "0,25,2560,1346" for my 27" retina iMac, while a screenshot of the same monitor displays at 5120,2880
yes, and that is correct behaviour! :)

The monitor HAS in fact a resolution of 5120x2880 (= 2560*2/1440*2) pixels but RETINA means the pixels are "doubled"
for display, so you can actually read text on screen, which would be too small otherwise.
However a screenshot will take ALL pixels into account. That is the meaning of RETINA!

Open the "system settings: monitor" on your iMac and play with the different options, seeing is beliving! :)

Best

Klaus

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Send the Stack to the Center of the screen.

Post by richmond62 » Wed Dec 13, 2023 11:49 am

The most important thing about my post was NOT the "funny" way my Retina monitor behaves, it was about how the effective working screenRect is NOT the effective working screenRect at all.

If LC cannot detect the 'fatness' of the MacOS Dock (or any screen 'furniture' on Windows or Linux) then effective working screenRect is not much use at all: I cannot predict how many panels. docks, whatevers or their bigness an end-user has "cluttering" their monitor, and unless LC can detect these a standalone cannot scale itself to take these into account.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Send the Stack to the Center of the screen.

Post by Klaus » Wed Dec 13, 2023 12:00 pm

Yes, but that was ONE of the questions you raised! 8)

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Send the Stack to the Center of the screen.

Post by Klaus » Wed Dec 13, 2023 12:04 pm

All this works correctly on my Mac Mini late 2014, macOS 12.7.1, Apple 27" monitor, LC 9.6.11:
the screenrect -> 0,0,2560,1440
the working screenrect -> 0,25,2560,1364
the effective working screenrect -> 0,25,2560,1364

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Send the Stack to the Center of the screen.

Post by richmond62 » Wed Dec 13, 2023 12:08 pm

OK: size a stack to the working screenRect and see if it "frees" the dock:
-
Screenshot 2023-12-13 at 13.07.29.png
-
Because I get this:
-
Screenshot 2023-12-13 at 12.15.01.png

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Send the Stack to the Center of the screen.

Post by Klaus » Wed Dec 13, 2023 1:01 pm

You also have to subtract the height of the window title bar, which is 30 pixel.
But yes, even then the stack goes behind the dock!
Bildschirmfoto 2023-12-13 um 12.59.36.png
Bildschirmfoto 2023-12-13 um 12.59.36.png (27.55 KiB) Viewed 229097 times
Maybe you should create a bug report.

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1209
Joined: Thu Apr 11, 2013 11:27 am

Re: Send the Stack to the Center of the screen.

Post by LCMark » Wed Dec 13, 2023 1:09 pm

The screenLoc returns the center of the screenRect, not the working screenRect - the menubar and docks are different heights so they won't be the same.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Send the Stack to the Center of the screen.

Post by Klaus » Wed Dec 13, 2023 1:12 pm

LCMark wrote:
Wed Dec 13, 2023 1:09 pm
The screenLoc returns the center of the screenRect, not the working screenRect...
Yes. :-)
LCMark wrote:
Wed Dec 13, 2023 1:09 pm
... the menubar and docks are different heights so they won't be the same.
Yes, too. :-)
But what is the meaning of that in this context?

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Send the Stack to the Center of the screen.

Post by richmond62 » Wed Dec 13, 2023 1:24 pm

Damage control should not consist of evasion.

Doing this:

Code: Select all

on mouseUp
   set the itemDelimiter to ","
   put item 4 of the effective working screenRect into UD
   put item 3 of the screenRect into LR
   set the height of Stack "screen Stretch" to UD
   set the width of Stack "screen Stretch" to LR
   set the loc of stack "screen Stretch" to the screenLoc
end mouseUp
"Settles" my stack just below the MacOS Menu bar (as it should):
-
Screenshot 2023-12-13 at 14.22.17.png
-
Actually, if I really wanted to be picky I would argue it is NOT doing a very good job as 7 pixels of the grab-bar at the top of the stack are obscured by the MacOS Menu bar:
-
Screenshot 2023-12-13 at 14.29.40.png
-
HOWEVER: the stack is still of such a height that it has part of it obscured behind the MacOS Dock (no, I am not going to post that image for the 3rd time).

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Send the Stack to the Center of the screen.

Post by richmond62 » Wed Dec 13, 2023 1:42 pm

Having 'pruned' my MacOS Dock so I could make it larger it becomes clear that LC CANNOT detect anything relating to the Dock at all:
-
Screenshot 2023-12-13 at 14.38.24.png
-
If one compares that with my earlier screeshot it is clear that the stack has more of it obscured by the larger Dock now.

So this in the Dictionary under screenRect:

"Adding the working adjective to either form returns the virtual co-ordinates of each screen's working-area. The working-area of a screen is defined to be the area not covered by OS furniture (such as the task bar on Windows, and the Dock and Menubar on Mac OS X)."

(My emphasis)

Is simply wrong and has little value.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Send the Stack to the Center of the screen.

Post by bn » Wed Dec 13, 2023 1:54 pm

What happens if you do from the message box

Code: Select all

set the rect of this stack to the effective working screenRect
That works for me.

Kind regards
Bernd

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1209
Joined: Thu Apr 11, 2013 11:27 am

Re: Send the Stack to the Center of the screen.

Post by LCMark » Wed Dec 13, 2023 1:58 pm

richmond62 wrote:
Wed Dec 13, 2023 1:24 pm
Damage control should not consist of evasion.
And this means what exactly @richmond?
Doing this:

Code: Select all

on mouseUp
   set the itemDelimiter to ","
   put item 4 of the effective working screenRect into UD
   put item 3 of the screenRect into LR
   set the height of Stack "screen Stretch" to UD
   set the width of Stack "screen Stretch" to LR
   set the loc of stack "screen Stretch" to the screenLoc
end mouseUp
This is doing precisely what you are asking it to.
Actually, if I really wanted to be picky I would argue it is NOT doing a very good job as 7 pixels of the grab-bar at the top of the stack are obscured by the MacOS Menu bar:
Well, you could argue that - and that would be fine if your code wasn't wrong (for what you are *actually* wanting to do).

----

I hadn't actually meant to post my comment as it was unfinished - I had to go and deal with something else and was going to come back to this later and inadvertently hit submit instead of save draft.

However I was going to go on to say that this is (partly) why the proposed code is not having the desired effect - the center point you are using to place the window is not the center point of the working screenRect.

Further (the other part of the partly), you need to take into account Klaus's comment about taking into account the titlebar height of the window.

Like the rect/width/height of a stack, the loc is computed relative to the stack window's content area - i.e. the area of the stack in which you can draw things, not the area taken up when the OS has added its own 'furniture' such as titlebars and such.

Fortunately though, all the rect-related properties of a stack (rect/width/height/topLeft/topRight/bottomLeft/bottomRight/location) all take the 'effective' adjective which does the computations relative to the rect of the OS window the stack is appearing in.

So if you want a stack *and* its OS's furniture to fill the entire working area of the screen then you can do it in a single line:

Code: Select all

set the effective rect of stack "screen Stretch"  to the working screenRect
If you want a stack's center to be at the center of the working screenRect then that does take a little more work (as, to be fair, this is probably not *that* useful):

Code: Select all

// This sets the center of the actual window (i.e. including window furniture) to the center of the working area of the screen
set the effective loc of stack "screen Stretch" to \
        item 1 of the working screenRect + item 3 of working screenRect div 2, \
        item 2 of the working screenRect + item 4 of the working screenRect div 2

// This sets the center of the window's content area (i.e. the bit where LC content is rendered) to the center of the working area of the screen
set the loc of stack "screen Stretch" to \
        item 1 of the working screenRect + item 3 of working screenRect div 2, \
        item 2 of the working screenRect + item 4 of the working screenRect div 2
As an aside 'the effective working screenRect' is a mobile device thing - on those platforms the 'effective' takes into account any on-screen keyboard if it is visible; adding 'effective' has no effect on desktop platforms.

The above should work on all three desktop platforms (with the small caveat that exceptionally exotic Linux window managers might not provide the necessary information to compute the OS furniture placement and sizes of windows and the desktop - but I strongly suspect these days that they are very rare and unlikely to be encountered).

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Send the Stack to the Center of the screen.

Post by richmond62 » Wed Dec 13, 2023 2:01 pm

What happenns if you do from the message box
-
1. Hides grab bar behind the Mac Menu bar:
-
Screenshot 2023-12-13 at 14.58.45.png
-
2. Dock still obscures some of the bottom of the stack:
-
Screenshot 2023-12-13 at 14.58.39.png
-
MacOS 12.7.2

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Send the Stack to the Center of the screen.

Post by richmond62 » Wed Dec 13, 2023 2:04 pm

the center point you are using to place the window is not the center point of the working screenRect
OK: Let's see:
-
Screenshot 2023-12-13 at 15.06.29.png
-
It DID make the stack the height it should be so that none of it was obscured behind the MacOS Dock, BUT it set the top of it a bit lower down the screen than it should have:
-
Screenshot 2023-12-13 at 15.09.49.png
-
The grab bar visible just below the MacOS Menu bar and behind my "screen Stretch" stack is my revMenubar stack.

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1209
Joined: Thu Apr 11, 2013 11:27 am

Re: Send the Stack to the Center of the screen.

Post by LCMark » Wed Dec 13, 2023 2:18 pm

The grab bar visible just below the MacOS Menu bar and behind my "screen Stretch" stack is my revMenubar stack.
Yes - but that's what you have asked for!

As I previously stated, to fill the working area of the screen with a stack's window (taking into account titlebar etc.), it is sufficient to use just the single line:

Code: Select all

set the effective rect of stack "screen Stretch" to the working screenRect
The second line you have there is setting the center of the content area of stack (i.e. no account taken of the window furniture) to the center of the screen (no account taken of the desktop furniture). Thus undoing at least part of what you wanted to achieve in the first place.

Post Reply

Return to “Talking LiveCode”