<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://www.atitd.org/wiki/t7w/index.php?action=history&amp;feed=atom&amp;title=User%3AObol%2Fcommon_window.mac</id>
	<title>User:Obol/common window.mac - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://www.atitd.org/wiki/t7w/index.php?action=history&amp;feed=atom&amp;title=User%3AObol%2Fcommon_window.mac"/>
	<link rel="alternate" type="text/html" href="http://www.atitd.org/wiki/t7w/index.php?title=User:Obol/common_window.mac&amp;action=history"/>
	<updated>2026-07-05T15:20:05Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.2</generator>
	<entry>
		<id>http://www.atitd.org/wiki/t7w/index.php?title=User:Obol/common_window.mac&amp;diff=26176&amp;oldid=prev</id>
		<title>Obol at 17:33, 24 October 2015</title>
		<link rel="alternate" type="text/html" href="http://www.atitd.org/wiki/t7w/index.php?title=User:Obol/common_window.mac&amp;diff=26176&amp;oldid=prev"/>
		<updated>2015-10-24T17:33:52Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 17:33, 24 October 2015&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l238&quot; &gt;Line 238:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 238:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;       if currentX + width &amp;gt;= screen[0] then&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;       if currentX + width &amp;gt;= screen[0] then&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         currentX = 0;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         currentX = 0;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         currentY = currentY + yMax + &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;10&lt;/del&gt;;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;		&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;		-- increase the Y Gap&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         currentY = currentY + yMax + &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;15&lt;/ins&gt;;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         yMax = 0;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         yMax = 0;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;       end&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;       end&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l253&quot; &gt;Line 253:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 255:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     else&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     else&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;       currentX = currentX + width + 5;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;       currentX = currentX + width + 5;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;	  -- not correct place for this&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;	  --currentY = currentY + 5;  &lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     end&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     end&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l509&quot; &gt;Line 509:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 509:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   unpinManager(&amp;quot;Complete&amp;quot;, error);&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   unpinManager(&amp;quot;Complete&amp;quot;, error);&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;end&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;end&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Obol</name></author>
	</entry>
	<entry>
		<id>http://www.atitd.org/wiki/t7w/index.php?title=User:Obol/common_window.mac&amp;diff=26172&amp;oldid=prev</id>
		<title>Obol: Created page with &quot;&lt;pre&gt; -- common_window.inc -- -- Common functions for handling windows: opening, arranging, unpinning -- -- DO NOT INCLUDE THIS FILE! Include common.inc instead --  TOP_LEFT = 0;...&quot;</title>
		<link rel="alternate" type="text/html" href="http://www.atitd.org/wiki/t7w/index.php?title=User:Obol/common_window.mac&amp;diff=26172&amp;oldid=prev"/>
		<updated>2015-10-24T17:29:05Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;pre&amp;gt; -- common_window.inc -- -- Common functions for handling windows: opening, arranging, unpinning -- -- DO NOT INCLUDE THIS FILE! Include common.inc instead --  TOP_LEFT = 0;...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
-- common_window.inc&lt;br /&gt;
--&lt;br /&gt;
-- Common functions for handling windows: opening, arranging, unpinning&lt;br /&gt;
--&lt;br /&gt;
-- DO NOT INCLUDE THIS FILE! Include common.inc instead&lt;br /&gt;
--&lt;br /&gt;
&lt;br /&gt;
TOP_LEFT = 0;&lt;br /&gt;
TOP_RIGHT = 1;&lt;br /&gt;
BOTTOM_LEFT = 2;&lt;br /&gt;
BOTTOM_RIGHT = 3;&lt;br /&gt;
&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
-- stashWindow(sourceX, sourceY, corner, bounds)&lt;br /&gt;
--&lt;br /&gt;
-- Drags a window from a given location to a corner of the screen.&lt;br /&gt;
--&lt;br /&gt;
-- sourceX, sourceY -- location of anchor point to drag window&lt;br /&gt;
-- corner -- destination corner (TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT,&lt;br /&gt;
--           or BOTTOM_RIGHT)&lt;br /&gt;
-- bounds (optional) -- bounds of window&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
local stashBit = 0;&lt;br /&gt;
&lt;br /&gt;
function stashWindow(sourceX, sourceY, corner, bounds)&lt;br /&gt;
  if not sourceX or not sourceY or not corner then&lt;br /&gt;
    error(&amp;quot;Incorrect number of arguments for stashWindow()&amp;quot;);&lt;br /&gt;
  end&lt;br /&gt;
  stashBit = (stashBit + 2) % 4;&lt;br /&gt;
  if not bounds then&lt;br /&gt;
    srReadScreen();&lt;br /&gt;
    bounds = srGetWindowBorders(sourceX, sourceY);&lt;br /&gt;
  end&lt;br /&gt;
  local size = {};&lt;br /&gt;
  size[0] = bounds[2] - bounds[0];&lt;br /&gt;
  size[1] = bounds[3] - bounds[1];&lt;br /&gt;
  local screen = srGetWindowSize();&lt;br /&gt;
  local dest = {};&lt;br /&gt;
  dest[0] = screen[0] - size[0] + (sourceX - bounds[0]) - 5;&lt;br /&gt;
  if corner == TOP_LEFT or corner == BOTTOM_LEFT then&lt;br /&gt;
    dest[0] = sourceX - bounds[0] + 5;&lt;br /&gt;
  end&lt;br /&gt;
  dest[1] = screen[1] - size[1] + (sourceY - bounds[1]) - stashBit - 5;&lt;br /&gt;
  if corner == TOP_LEFT or corner == TOP_RIGHT then&lt;br /&gt;
    dest[1] = sourceY - bounds[1] + stashBit + 5;&lt;br /&gt;
  end&lt;br /&gt;
  safeDrag(sourceX, sourceY, dest[0], dest[1]);&lt;br /&gt;
  srSetMousePos(sourceX, sourceY);&lt;br /&gt;
  lsSleep(click_delay);&lt;br /&gt;
  return dest;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
-- stashAllWindows(corner)&lt;br /&gt;
--&lt;br /&gt;
-- Move all windows not in the same quadrant as corner into the given&lt;br /&gt;
-- corner.  Use this twice on different corners to make sure that you&lt;br /&gt;
-- grab all windows.&lt;br /&gt;
--&lt;br /&gt;
-- corner -- Destination corner&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
function stashAllWindows(corner)&lt;br /&gt;
  if not corner then&lt;br /&gt;
    error(&amp;quot;Incorrect number of arguments for stashAllWindows()&amp;quot;);&lt;br /&gt;
  end&lt;br /&gt;
  local top = (corner == TOP_LEFT or corner == TOP_RIGHT);&lt;br /&gt;
  local left = (corner == TOP_LEFT or corner == BOTTOM_LEFT);&lt;br /&gt;
  local screen = srGetWindowSize();&lt;br /&gt;
  local done = false;&lt;br /&gt;
  local stashes = {};&lt;br /&gt;
  srReadScreen();&lt;br /&gt;
  local anchors = findAllImages(&amp;quot;ThisIs.png&amp;quot;);&lt;br /&gt;
  while not done do&lt;br /&gt;
    done = true;&lt;br /&gt;
    for i=1,#anchors do&lt;br /&gt;
      if not wasStashed(anchors[i], stashes) then&lt;br /&gt;
	safeClick(anchors[i][0], anchors[i][1]);&lt;br /&gt;
	lsSleep(click_delay);&lt;br /&gt;
	local lastPos = stashWindow(anchors[i][0], anchors[i][1], corner);&lt;br /&gt;
	stashes[#stashes + 1] = lastPos;&lt;br /&gt;
	done = false;&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    lsSleep(tick_delay);&lt;br /&gt;
    srReadScreen();&lt;br /&gt;
    anchors = findAllImages(&amp;quot;ThisIs.png&amp;quot;);&lt;br /&gt;
    statusScreen(&amp;quot;Stashing Windows&amp;quot;);&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function wasStashed(pos, stashes)&lt;br /&gt;
  local result = false;&lt;br /&gt;
  for i=1,#stashes do&lt;br /&gt;
    local diffX = math.abs(stashes[i][0] - pos[0]);&lt;br /&gt;
    local diffY = math.abs(stashes[i][1] - pos[1]);&lt;br /&gt;
    if diffX &amp;lt; 20 and diffY &amp;lt; 20 then&lt;br /&gt;
      result = true;&lt;br /&gt;
      break;&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return result;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
-- openAndPin(x, y, timeout)&lt;br /&gt;
--&lt;br /&gt;
-- Click at the given position to open a window, then pin that window.&lt;br /&gt;
--&lt;br /&gt;
-- x, y -- position to click&lt;br /&gt;
-- timeout -- time to wait before giving up&lt;br /&gt;
--&lt;br /&gt;
-- Returns true on success.&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
function openAndPin(x, y, timeout)&lt;br /&gt;
  if not x or not y or not timeout then&lt;br /&gt;
    error(&amp;quot;Incorrect number of arguments for openAndPin()&amp;quot;);&lt;br /&gt;
  end&lt;br /&gt;
  local success = false;&lt;br /&gt;
  srReadScreen();&lt;br /&gt;
  local anchors = findAllImages(&amp;quot;ThisIs.png&amp;quot;);&lt;br /&gt;
  local startTime = lsGetTimer();&lt;br /&gt;
  safeBegin();&lt;br /&gt;
  srSetMousePos(x, y);&lt;br /&gt;
  lsSleep(50);&lt;br /&gt;
  srClickMouse(x, y, 1);&lt;br /&gt;
  lsDoFrame();&lt;br /&gt;
  statusScreen(&amp;quot;Clicking to open window&amp;quot;);&lt;br /&gt;
  local done = false;&lt;br /&gt;
  local anchor = nil;&lt;br /&gt;
  while not done do&lt;br /&gt;
    srReadScreen();&lt;br /&gt;
    local newAnchors = findAllImages(&amp;quot;ThisIs.png&amp;quot;);&lt;br /&gt;
    done = false;&lt;br /&gt;
    local limit = math.min(#anchors, #newAnchors);&lt;br /&gt;
    for i=1,limit do&lt;br /&gt;
      if anchors[i][0] ~= newAnchors[i][0]&lt;br /&gt;
	or anchors[i][1] ~= newAnchors[i][1]&lt;br /&gt;
      then&lt;br /&gt;
	anchor = newAnchors[i];&lt;br /&gt;
	done = true;&lt;br /&gt;
	break;&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if not done and #anchors ~= #newAnchors then&lt;br /&gt;
      done = true;&lt;br /&gt;
      anchor = newAnchors[#newAnchors];&lt;br /&gt;
    end&lt;br /&gt;
    if not done and lsGetTimer() &amp;gt; startTime + timeout then&lt;br /&gt;
      done = true;&lt;br /&gt;
    end&lt;br /&gt;
    anchors = newAnchors;&lt;br /&gt;
    statusScreen(&amp;quot;Waiting for window to open&amp;quot;);&lt;br /&gt;
    lsSleep(tick_delay);&lt;br /&gt;
  end&lt;br /&gt;
  if anchor then&lt;br /&gt;
    success = true;&lt;br /&gt;
    if not findImageInWindow(&amp;quot;UnPin.png&amp;quot;, x+5, y) then&lt;br /&gt;
      safeClick(anchor[0], anchor[1], 1);&lt;br /&gt;
      statusScreen(&amp;quot;Pinning window&amp;quot;);&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  return success;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
-- arrangeInGrid(cascade, waterGap)&lt;br /&gt;
--&lt;br /&gt;
-- Arrange all open windows into a grid on the screen. Stashes them first.&lt;br /&gt;
--&lt;br /&gt;
-- cascade (optional) -- arrange windows into an overlapping cascade&lt;br /&gt;
-- waterGap (optional) -- leave a gap at the top for getting water&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
function arrangeInGrid(cascade, waterGap)&lt;br /&gt;
  stashAllWindows(BOTTOM_LEFT);&lt;br /&gt;
  stashAllWindows(BOTTOM_RIGHT);&lt;br /&gt;
  arrangeStashed(cascade, waterGap);&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
-- arrangeStashed(cascade, waterGap)&lt;br /&gt;
--&lt;br /&gt;
-- Arrange all open windows into a grid on the screen. Assumes they&lt;br /&gt;
-- are pre-stashed.&lt;br /&gt;
--&lt;br /&gt;
-- cascade (optional) -- arrange windows into a overlapping cascade&lt;br /&gt;
-- waterGap (optional) -- leave a gap at the top for getting water&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
function arrangeStashed(cascade, waterGap, varWidth, varHeight)&lt;br /&gt;
  local screen = srGetWindowSize();&lt;br /&gt;
  local bottomRightX = screen[0] - 20;&lt;br /&gt;
  local bottomRightY = screen[1] - 20;&lt;br /&gt;
  screen[0] = screen[0] - lsGetWindowSize()[0];&lt;br /&gt;
  local currentX = 0;&lt;br /&gt;
  local currentY = 0;&lt;br /&gt;
  if waterGap then&lt;br /&gt;
    currentX = 10;&lt;br /&gt;
    currentY = 50;&lt;br /&gt;
  end&lt;br /&gt;
  local lastX = 0;&lt;br /&gt;
  local lastY = 0;&lt;br /&gt;
  local xMax = 0;&lt;br /&gt;
  local yMax = 0;&lt;br /&gt;
  srReadScreen();&lt;br /&gt;
  local window = findImageInWindow(&amp;quot;ThisIs.png&amp;quot;, bottomRightX, bottomRightY);&lt;br /&gt;
  while window and (window[0] &amp;gt; lastX or window[1] &amp;gt; lastY) do&lt;br /&gt;
    safeClick(window[0], window[1]);&lt;br /&gt;
    lsSleep(click_delay);&lt;br /&gt;
    srReadScreen();&lt;br /&gt;
    local bounds = srGetWindowBorders(window[0], window[1]);&lt;br /&gt;
    local width, height;&lt;br /&gt;
    if not varWidth then&lt;br /&gt;
      width = bounds[2] - bounds[0];&lt;br /&gt;
    else&lt;br /&gt;
      width = varWidth;&lt;br /&gt;
    end&lt;br /&gt;
    if not varHeight then&lt;br /&gt;
      height = bounds[3] - bounds[1];&lt;br /&gt;
    else&lt;br /&gt;
      height = varHeight;&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    if cascade then&lt;br /&gt;
      if currentY + height &amp;gt;= screen[1] then&lt;br /&gt;
        currentX = currentX + xMax;&lt;br /&gt;
        currentY = 0;&lt;br /&gt;
        xMax = 0;&lt;br /&gt;
      end&lt;br /&gt;
      if currentX + width &amp;gt;= screen[0] then&lt;br /&gt;
        error(&amp;quot;Cannot arrange these windows into a cascade.&amp;quot;);&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      if currentX + width &amp;gt;= screen[0] then&lt;br /&gt;
        currentX = 0;&lt;br /&gt;
        currentY = currentY + yMax + 10;&lt;br /&gt;
        yMax = 0;&lt;br /&gt;
      end&lt;br /&gt;
      if currentY + height &amp;gt;= screen[1] then&lt;br /&gt;
        error(&amp;quot;Cannot arrange these windows into a grid.&amp;quot;);&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    lastX = window[0] - bounds[0] + currentX;&lt;br /&gt;
    lastY = window[1] - bounds[1] + currentY;&lt;br /&gt;
    safeDrag(window[0], window[1], lastX, lastY);&lt;br /&gt;
    if cascade then&lt;br /&gt;
      currentX = currentX + 8;&lt;br /&gt;
      currentY = currentY + 24;&lt;br /&gt;
    else&lt;br /&gt;
      currentX = currentX + width + 5;&lt;br /&gt;
	  -- not correct place for this&lt;br /&gt;
	  --currentY = currentY + 5;  &lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    xMax = math.max(xMax, width);&lt;br /&gt;
    yMax = math.max(yMax, height);&lt;br /&gt;
    lsSleep(tick_delay);&lt;br /&gt;
    srReadScreen();&lt;br /&gt;
    window = findImageInWindow(&amp;quot;ThisIs.png&amp;quot;, bottomRightX, bottomRightY);&lt;br /&gt;
    statusScreen(&amp;quot;Arranging Windows&amp;quot;);&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
-- closeAllWindows(x, y, width, height)&lt;br /&gt;
--&lt;br /&gt;
-- Close all open windows.&lt;br /&gt;
--&lt;br /&gt;
-- x, y (optional) -- origin of box to search&lt;br /&gt;
-- width, height (optional) -- size of box to search&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
function closeAllWindows(x, y, width, height)&lt;br /&gt;
  if not x then&lt;br /&gt;
    x = 0;&lt;br /&gt;
  end&lt;br /&gt;
  if not y then&lt;br /&gt;
    y = 0;&lt;br /&gt;
  end&lt;br /&gt;
  if not width then&lt;br /&gt;
    width = srGetWindowSize()[0];&lt;br /&gt;
  end&lt;br /&gt;
  if not height then&lt;br /&gt;
    height = srGetWindowSize()[1];&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  local closeImages = {&amp;quot;ThisIs.png&amp;quot;, &amp;quot;UnPin.png&amp;quot;, &amp;quot;Ok.png&amp;quot;};&lt;br /&gt;
  local closeRight = {1, 1, nil};&lt;br /&gt;
&lt;br /&gt;
  local found = true;&lt;br /&gt;
  while found do&lt;br /&gt;
    found = false;&lt;br /&gt;
    for i=1,#closeImages do&lt;br /&gt;
      local image = closeImages[i];&lt;br /&gt;
      local right = closeRight[i];&lt;br /&gt;
      srReadScreen();&lt;br /&gt;
      local images = findAllImagesInRange(image, x, y, width, height);&lt;br /&gt;
      while #images &amp;gt;= 1 do&lt;br /&gt;
	done = true;&lt;br /&gt;
	safeClick(images[#images][0], images[#images][1], right);&lt;br /&gt;
	sleepWithStatus(200, &amp;quot;Closing Windows&amp;quot;);&lt;br /&gt;
	srReadScreen();&lt;br /&gt;
	images = findAllImagesInRange(image, x, y, width, height);&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
-- closeEmptyRegions()&lt;br /&gt;
--&lt;br /&gt;
-- Closes all empty windows on the screen&lt;br /&gt;
--&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
function closeEmptyRegions()&lt;br /&gt;
  allRegs = findAllTextRegions();&lt;br /&gt;
  if allRegs then&lt;br /&gt;
    for i = 1, #allRegs do&lt;br /&gt;
      local p = parseRegion(allRegs[i]);&lt;br /&gt;
      if p == nil then&lt;br /&gt;
        unpinRegion(allRegs[i]);&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
-- windowManager(title, message, allowCascade, allowWaterGap)&lt;br /&gt;
--&lt;br /&gt;
-- Run a window manager interface to let the user open, pin, arrange,&lt;br /&gt;
-- or clear windows.&lt;br /&gt;
--&lt;br /&gt;
-- title (optional) -- title of window&lt;br /&gt;
-- message (optional) -- extra instructions for the user&lt;br /&gt;
-- allowCascade (optional) -- allow the user to arrange in a cascade&lt;br /&gt;
-- allowWaterGap (optional) -- allow the user to add a water gap&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
pauseForFocus = false;&lt;br /&gt;
&lt;br /&gt;
function windowManager(title, message, allowCascade, allowWaterGap)&lt;br /&gt;
  if not title then&lt;br /&gt;
    title = &amp;quot;Window Manager&amp;quot;;&lt;br /&gt;
  end&lt;br /&gt;
  if not message then&lt;br /&gt;
    message = &amp;quot;Tap Ctrl to open and pin a window.&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
  local waterGap = false;&lt;br /&gt;
  local shift = false;&lt;br /&gt;
  local done = false;&lt;br /&gt;
  while not done do&lt;br /&gt;
    local y = 10;&lt;br /&gt;
    lsPrint(10, y, 0, 1.0, 1.0, 0xFFFFFFff, title);&lt;br /&gt;
    y = y + 50;&lt;br /&gt;
&lt;br /&gt;
    if lsButtonText(30, y, 0, 250, 0x80D080ff, &amp;quot;Form Grid&amp;quot;) then&lt;br /&gt;
      lsDoFrame();&lt;br /&gt;
      if pauseForFocus then&lt;br /&gt;
	askForWindow(focusMessage);&lt;br /&gt;
      end&lt;br /&gt;
      arrangeInGrid(false, waterGap);&lt;br /&gt;
    end&lt;br /&gt;
    y = y + 30;&lt;br /&gt;
&lt;br /&gt;
    if allowCascade then&lt;br /&gt;
      if lsButtonText(30, y, 0, 250, 0x80D080ff, &amp;quot;Form Cascade&amp;quot;) then&lt;br /&gt;
	lsDoFrame();&lt;br /&gt;
	if pauseForFocus then&lt;br /&gt;
	  askForWindow(focusMessage);&lt;br /&gt;
	end&lt;br /&gt;
	arrangeInGrid(true, waterGap);&lt;br /&gt;
      end&lt;br /&gt;
      y = y + 30;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if lsButtonText(30, y, 0, 250, 0x80D080ff, &amp;quot;Stash Windows&amp;quot;) then&lt;br /&gt;
      lsDoFrame();&lt;br /&gt;
      if pauseForFocus then&lt;br /&gt;
	askForWindow(focusMessage);&lt;br /&gt;
      end&lt;br /&gt;
      stashAllWindows(BOTTOM_RIGHT);&lt;br /&gt;
    end&lt;br /&gt;
    y = y + 30;&lt;br /&gt;
&lt;br /&gt;
    if lsButtonText(30, y, 0, 250, 0x80D080ff, &amp;quot;Un-Pin Windows&amp;quot;) then&lt;br /&gt;
      lsDoFrame();&lt;br /&gt;
      if pauseForFocus then&lt;br /&gt;
	askForWindow(focusMessage);&lt;br /&gt;
      end&lt;br /&gt;
      closeAllWindows();&lt;br /&gt;
    end&lt;br /&gt;
    y = y + 40;&lt;br /&gt;
&lt;br /&gt;
    pauseForFocus = lsCheckBox(30, y, 10, 0xffffffff, &amp;quot;Pause for Focus&amp;quot;,&lt;br /&gt;
			    pauseForFocus);&lt;br /&gt;
    y = y + 30;&lt;br /&gt;
    if allowWaterGap then&lt;br /&gt;
      waterGap = lsCheckBox(30, y, 10, 0xffffffff, &amp;quot;Leave Gap for Water&amp;quot;,&lt;br /&gt;
			    waterGap);&lt;br /&gt;
      y = y + 30;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    lsPrintWrapped(10, y, 0, lsScreenY - 20, 0.7, 0.7, 0xd0d0d0ff,&lt;br /&gt;
		   message);&lt;br /&gt;
    if lsButtonText(lsScreenX - 110, lsScreenY - 30, 0, 100,&lt;br /&gt;
		    0xffffffff, &amp;quot;End Script&amp;quot;) then&lt;br /&gt;
      error(quit_message);&lt;br /&gt;
    end&lt;br /&gt;
    while lsControlHeld() do&lt;br /&gt;
      checkBreak();&lt;br /&gt;
      shift = true;&lt;br /&gt;
    end&lt;br /&gt;
    if shift then&lt;br /&gt;
      shift = false;&lt;br /&gt;
      local x = 0;&lt;br /&gt;
      local y = 0;&lt;br /&gt;
      x, y = srMousePos();&lt;br /&gt;
      openAndPin(x, y, 500);&lt;br /&gt;
    end&lt;br /&gt;
    if lsButtonText(10, lsScreenY - 30, 0, 100, 0xFFFFFFff, &amp;quot;Done&amp;quot;) then&lt;br /&gt;
        done = true;&lt;br /&gt;
    end&lt;br /&gt;
    checkBreak();&lt;br /&gt;
    lsDoFrame();&lt;br /&gt;
    lsSleep(tick_delay);&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
-- unpinManager(title, message)&lt;br /&gt;
--&lt;br /&gt;
-- Interface to help the user clear away all windows when a macro completes.&lt;br /&gt;
--&lt;br /&gt;
-- title (optional)  -- title of window&lt;br /&gt;
-- message (optional) -- extra instructions for the user&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
function unpinManager(title, message)&lt;br /&gt;
  if not title then&lt;br /&gt;
    title = &amp;quot;Unpin Manager&amp;quot;;&lt;br /&gt;
  end&lt;br /&gt;
  if not message then&lt;br /&gt;
    message = &amp;quot;&amp;quot;;&lt;br /&gt;
  end&lt;br /&gt;
  while lsShiftHeld() and lsControlHeld() do&lt;br /&gt;
    lsPrintWrapped(10, 60, 0, lsScreenX - 20, 1, 1, 0x808080ff,&lt;br /&gt;
		  &amp;quot;Please release Ctrl+Shift&amp;quot;);&lt;br /&gt;
    lsSleep(tick_delay);&lt;br /&gt;
    lsDoFrame();&lt;br /&gt;
  end&lt;br /&gt;
  local done = false;&lt;br /&gt;
  while not done do&lt;br /&gt;
    lsPrint(10, 10, 0, 1.0, 1.0, 0xFFFFFFff, title);&lt;br /&gt;
    lsPrintWrapped(10, 60, 0, lsScreenX - 20, 0.7, 0.7,&lt;br /&gt;
		   0xd0d0d0ff, message);&lt;br /&gt;
    if lsButtonText(30, 160, 0, 250, 0x80D080ff, &amp;quot;Un-Pin Windows&amp;quot;) then&lt;br /&gt;
      lsDoFrame();&lt;br /&gt;
      if pauseForFocus then&lt;br /&gt;
	askForWindow(focusMessage);&lt;br /&gt;
      end&lt;br /&gt;
      closeAllWindows();&lt;br /&gt;
    end&lt;br /&gt;
    if lsButtonText(lsScreenX - 110, lsScreenY - 30, 0, 100,&lt;br /&gt;
		    0xffffffff, &amp;quot;Done&amp;quot;) then&lt;br /&gt;
      done = true;&lt;br /&gt;
    end&lt;br /&gt;
    if lsShiftHeld() and lsControlHeld() then&lt;br /&gt;
      done = true;&lt;br /&gt;
    end&lt;br /&gt;
    lsDoFrame();&lt;br /&gt;
    lsSleep(tick_delay);&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
-- unpinRegion(region)&lt;br /&gt;
--&lt;br /&gt;
-- Unpins a region&lt;br /&gt;
--&lt;br /&gt;
-- region - region object to unpin&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
function unpinRegion(region)&lt;br /&gt;
  if region then&lt;br /&gt;
    lsPrintln(&amp;quot;Unpinning at: &amp;quot; .. region[0] + region[2] - 15 .. &amp;quot;, &amp;quot; .. region[1] + region[3] + 15);&lt;br /&gt;
    safeClick(region[0] + region[2] - 15, region[1] + 15, 0);&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
-- unpinOnExit(f)&lt;br /&gt;
--&lt;br /&gt;
-- Execute function f and present an unpin manager window when it&lt;br /&gt;
-- completes or if an error is thrown.&lt;br /&gt;
--&lt;br /&gt;
-- f -- function to execute with no arguments&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
function unpinOnExit(f)&lt;br /&gt;
  if not f then&lt;br /&gt;
    error(&amp;quot;Incorrect number of arguments for f&amp;quot;);&lt;br /&gt;
  end&lt;br /&gt;
  local status, error = pcall(f);&lt;br /&gt;
  unpinManager(&amp;quot;Complete&amp;quot;, error);&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Obol</name></author>
	</entry>
</feed>