Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var displayManager = {
- active: false,
- autolaunch: false,
- url: '',
- validationPassed: false,
- displaysRunning: false,
- displayWindows: [],
- screenManager: {},
- primaryScreen: {},
- displayScreens: [],
- displaySequence: [0,1],
- init: function(){
- this.active = prefs.getBoolPref('live.displayOnWinTV');
- this.autolaunch = prefs.getBoolPref('live.displayOnWinTVAutomatically');
- this.url = prefs.getCharPref('live.displayOnWinTVLink');
- this.screenManager = Components.classes["@mozilla.org/gfx/screenmanager;1"].getService(Components.interfaces.nsIScreenManager);
- this.locateScreens();
- this.validate();
- //sort launch sequence depending on settings, or launch positions based by an array containing selected indexes, sequence array
- //display buttons vs shuffle button for ordering, button laid out depending on positions in the screens array?
- },
- locateScreens: function(){
- //locate primary screen
- this.screenManager.primaryScreen.GetRect(left,top,width,height);
- this.primaryScreen = {left: left.value, top: top.value, width: width.value, height: height.value};
- jslog('primary : ' + dumpobj(this.primaryScreen));
- this.searchRight(this.primaryScreen);
- this.searchLeft(this.primaryScreen);
- this.searchUp(this.primaryScreen);
- this.searchDown(this.primaryScreen);
- jslog('============================================================');
- jslog('display screens: ' + dumpobj(this.displayScreens));
- },
- searchUp: function(currentScreen){
- //if going up from only a single screen, forced to use a giant rect horizontally and fetch anything above
- jslog('searching up');
- topTmp = parseInt(currentScreen.top);
- heightTmp = parseInt(currentScreen.height);
- resultOffset = topTmp - heightTmp;
- screen = this.screenManager.screenForRect(leftConst, resultOffset, widthConst, currentScreen.height );
- screen.GetRect(left,top,width,height);
- jslog('new screen: ' + left.value + ' ' + top.value + ' ' + width.value + ' ' + height.value + ' ');
- if(!this.checkIfExists(left, top, width, height)){ //////pass display screen instead of values
- jslog('pushing a screen');
- var displayScreen = {left: left.value, top: top.value, width: width.value, height: height.value};
- this.displayScreens.push(displayScreen); //add order property for sequence?
- this.searchRight(displayScreen);
- this.searchLeft(displayScreen);
- this.searchUp(displayScreen); // not sure if array could be empty at the position?
- }
- },
- searchDown: function(currentScreen){
- //if going up from only a single screen, forced to use a giant rect horizontally and fetch anything above
- jslog('searching down');
- topTmp = parseInt(currentScreen.top);
- heightTmp = parseInt(currentScreen.height);
- resultOffset = topTmp + heightTmp;
- screen = this.screenManager.screenForRect(leftConst, resultOffset, widthConst, currentScreen.height );
- screen.GetRect(left,top,width,height);
- jslog('new screen: ' + left.value + ' ' + top.value + ' ' + width.value + ' ' + height.value + ' ');
- if(!this.checkIfExists(left, top, width, height)){ //////pass display screen instead of values
- jslog('pushing a screen');
- var displayScreen = {left: left.value, top: top.value, width: width.value, height: height.value};
- this.displayScreens.push(displayScreen); //add order property for sequence?
- this.searchRight(displayScreen);
- this.searchLeft(displayScreen);
- this.searchDown(displayScreen); // not sure if array could be empty at the position?
- }
- },
- searchRight: function(currentScreen){
- jslog('searching right');
- leftTmp = parseInt(currentScreen.left);
- widthTmp = parseInt(currentScreen.width);
- resultOffset = leftTmp + widthTmp;
- screen = this.screenManager.screenForRect(resultOffset, currentScreen.top, currentScreen.width, currentScreen.height );
- screen.GetRect(left,top,width,height);
- jslog('new screen: ' + left.value + ' ' + top.value + ' ' + width.value + ' ' + height.value + ' ');
- if(!this.checkIfExists(left, top, width, height)){
- jslog('pushing a screen');
- var displayScreen = {left: left.value, top: top.value, width: width.value, height: height.value};
- this.displayScreens.push(displayScreen); //add order property for sequence?
- this.searchRight(displayScreen); // not sure if array could be empty at the position?
- }
- },
- searchLeft: function(currentScreen){
- jslog('searching left');
- leftTmp = parseInt(currentScreen.left);
- widthTmp = parseInt(currentScreen.width);
- resultOffset = leftTmp - widthTmp;
- screen = this.screenManager.screenForRect(resultOffset, currentScreen.top, currentScreen.width, currentScreen.height );
- screen.GetRect(left,top,width,height);
- jslog('new screen: ' + left.value + ' ' + top.value + ' ' + width.value + ' ' + height.value + ' ');
- if(!this.checkIfExists(left, top, width, height)){
- jslog('pushing a screen');
- var displayScreen = {left: left.value, top: top.value, width: width.value, height: height.value};
- this.displayScreens.push(displayScreen); //add order property for sequence?
- this.searchLeft(displayScreen); // not sure if array could be empty at the position?
- }
- },
- checkIfExists: function(left, top, width, height){
- var result;
- result = this.isScreenEqual(left, top, width, height, this.primaryScreen);
- for(var i=0; i<this.displayScreens.length; i++){
- if(this.isScreenEqual(left, top, width, height, this.displayScreens[i])){
- result = true;
- }
- }
- return result;
- },
- isScreenEqual: function(left, top, width, height, screen2){
- if(left.value == screen2.left && top.value == screen2.top
- && width.value == screen2.width && height.value == screen2.height){
- return true;
- }
- return false;
- },
- launchDisplays: function(){ //open live displays depending on config
- if(this.validationPassed){
- for(var i=0; i < this.displayScreens.length; i++){ // i < num Displays eventually
- this.displayWindows.push( window.open(this.url, "Live Display"+i, "chrome"));
- this.displayWindows[i].moveTo(this.displayScreens[i].left,this.displayScreens[i].top);
- this.displayWindows[i].fullScreen = true;
- }
- this.displaysRunning = true;
- }
- //sequence launch
- /* if(this.validationPassed){
- for(var i=0; i < this.displayScreens.length; i++){ // i < num Displays eventually
- this.displayWindows.push( window.open(this.url, "Live Display"+i, "chrome"));
- this.displayWindows[i].moveTo(this.displayScreens[this.displaySequence[i]].left,0);
- this.displayWindows[i].fullScreen = true;
- }
- this.displaysRunning = true;
- }*/
- },
- closeDisplays: function(){
- for(var i=0; i < this.displayWindows.length; i++){
- this.displayWindows[0].close();
- this.displayWindows[0] = null;
- this.displayWindows.shift();
- }
- this.displaysRunning = false;
- },
- toggleDisplays: function(){
- this.displaysRunning ? this.closeDisplays() : this.launchDisplays();
- },
- validate: function(){
- if(this.active && getOS()=='Windows' && this.url!='' && this.screenManager.numberOfScreens > 1){
- this.validationPassed = true;
- }
- }
- }
- var screen;
- var left = {},
- top = {},
- width = {},
- height = {};
- var leftConst = -10000;
- var widthConst = 20000;
- var leftTmp;
- var topTmp;
- var widthTmp;
- var heightTmp;
- var resultOffset;
- window.addEventListener('load', displayManager.init(), false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement