Saving stack locations in multi monitor setups

Bob Sneidar bobsneidar at iotecdigital.com
Fri Mar 9 12:20:57 EST 2018


Hi all. Here is a handy snippet for saving a stacks location, which is multi-monitor aware. It creates an array of key value pairs for any monitor resolution a stack is in when this function is called. The key is the monitor resolution and the value is the loc of the stack passed as pTargetStack. pTargetStack must be the stack name, or else the long stack name. In other words it must begin with the word "stack". 

I have gotten into the habit of always using long stack names and long IDs to deconflict multiple objects with the same names. 

on saveStackLocation pTargetStack
   put the stackloc of pTargetStack into aStackLoc
   put line (the screen of stack pTargetStack) of the screenRects into tScreenRect
   put item 3 of tScreenRect - item 1 of tScreenRect into item 1 of tRect
   put item 4 of tScreenRect - item 2 of tScreenRect into item 2 of tRect
   put the loc of pTargetStack into aStackLoc [tRect]
   set the stackloc of pTargetStack to aStackLoc
end saveStackLocation

function getStackLocation pTargetStack
   put the stackloc of pTargetStack into aStackLoc
   put line (the screen of stack pTargetStack) of the screenRects into tScreenRect   
   put item 3 of tScreenRect - item 1 of tScreenRect into item 1 of tRect
   put item 4 of tScreenRect - item 2 of tScreenRect into item 2 of tRect
   return aStackLoc [tRect]
end getStackLocation


So on closeStack call this function and on openStack call getStackLocation() and set the location of the stack. 

The reason for the math on the screen rect is because in a multi-monitor setup, the screenRects left for monitors to the right of another do NOT have 0,0 as the leftTop, but rather the left of the RIGHT monitor is the right of the LEFT monitor. I suppose it made sense to the developer at the time. 

Bob S





More information about the use-livecode mailing list