Skip to content

Instantly share code, notes, and snippets.

@joemccann
Created July 16, 2011 09:51
Show Gist options
  • Save joemccann/1086216 to your computer and use it in GitHub Desktop.
Save joemccann/1086216 to your computer and use it in GitHub Desktop.
Save Titanium Desktop app location on screen
/*
* 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