Created
July 16, 2011 09:51
-
-
Save joemccann/1086216 to your computer and use it in GitHub Desktop.
Save Titanium Desktop app location on screen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Calling this function while loading the app... | |
*/ | |
function titaniumWindowSize() { | |
var window = Titanium.UI.getMainWindow(); | |
var bounds = {}; | |
try { | |
var arr = Titanium.App.Properties.getList('bounds'); | |
bounds.x = +arr[0]; | |
bounds.y = +arr[1]; | |
bounds.width = +arr[2]; | |
bounds.height = +arr[3]; | |
} catch (e) { | |
var _w = screen.availWidth; | |
var _h = screen.availHeight; | |
// I need to know the screen insets to refine the following bounds. | |
bounds.x = 50; | |
bounds.y = 50; | |
bounds.width = _w-100; | |
bounds.height = _h-100; | |
} | |
window.setBounds(bounds); | |
window.addEventListener(Titanium.MOVED, function() { | |
titaniumSaveWindowLocation(); | |
}); | |
window.addEventListener(Titanium.RESIZED, function() { | |
titaniumSaveWindowLocation(); | |
}); | |
} | |
function titaniumSaveWindowLocation() { | |
var window = Titanium.UI.getMainWindow(); | |
var bounds = window.getBounds(); // These bounds are relative to the current monitor not to the main one. | |
var arr = [''+bounds.x, ''+bounds.y, ''+bounds.width, ''+bounds.height]; | |
Titanium.App.Properties.setList('bounds',arr); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment