Advertisement
Guest User

Untitled

a guest
Sep 15th, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var displayManager = {
  2.     active: false,
  3.     autolaunch: false,
  4.     url: '',
  5.     validationPassed: false,
  6.  
  7.     displaysRunning: false,
  8.     displayWindows: [],
  9.  
  10.     screenManager: {},
  11.     primaryScreen: {},
  12.     displayScreens: [],
  13.     displaySequence: [0,1],
  14.  
  15.     init: function(){
  16.         this.active = prefs.getBoolPref('live.displayOnWinTV');
  17.         this.autolaunch = prefs.getBoolPref('live.displayOnWinTVAutomatically');
  18.         this.url = prefs.getCharPref('live.displayOnWinTVLink');
  19.         this.screenManager = Components.classes["@mozilla.org/gfx/screenmanager;1"].getService(Components.interfaces.nsIScreenManager);
  20.  
  21.         this.locateScreens();
  22.         this.validate();
  23.  
  24.         //sort launch sequence depending on settings, or launch positions based by an array containing selected indexes, sequence array
  25.  
  26.         //display buttons vs shuffle button for ordering, button laid out depending on positions in the screens array?
  27.     },
  28.  
  29.     locateScreens: function(){
  30.         //locate primary screen
  31.         this.screenManager.primaryScreen.GetRect(left,top,width,height);
  32.         this.primaryScreen = {left: left.value, top: top.value, width: width.value, height: height.value};
  33.         jslog('primary : ' + dumpobj(this.primaryScreen));
  34.  
  35.         this.searchRight(this.primaryScreen);
  36.         this.searchLeft(this.primaryScreen);
  37.         this.searchUp(this.primaryScreen);
  38.         this.searchDown(this.primaryScreen);
  39.  
  40.         jslog('============================================================');
  41.         jslog('display screens: ' + dumpobj(this.displayScreens));
  42.     },
  43.  
  44.     searchUp: function(currentScreen){
  45.         //if going up from only a single screen, forced to use a giant rect horizontally and fetch anything above
  46.         jslog('searching up');
  47.  
  48.         topTmp = parseInt(currentScreen.top);
  49.         heightTmp = parseInt(currentScreen.height);
  50.         resultOffset = topTmp - heightTmp;
  51.  
  52.         screen = this.screenManager.screenForRect(leftConst, resultOffset, widthConst, currentScreen.height );
  53.         screen.GetRect(left,top,width,height);
  54.  
  55.         jslog('new screen: ' + left.value + ' ' + top.value + ' ' + width.value + ' ' + height.value + ' ');
  56.  
  57.         if(!this.checkIfExists(left, top, width, height)){  //////pass display screen instead of values
  58.             jslog('pushing a screen');
  59.             var displayScreen = {left: left.value, top: top.value, width: width.value, height: height.value};
  60.             this.displayScreens.push(displayScreen); //add order property for sequence?
  61.             this.searchRight(displayScreen);
  62.             this.searchLeft(displayScreen);
  63.             this.searchUp(displayScreen); // not sure if array could be empty at the position?
  64.         }
  65.     },
  66.  
  67.     searchDown: function(currentScreen){
  68.         //if going up from only a single screen, forced to use a giant rect horizontally and fetch anything above
  69.         jslog('searching down');
  70.  
  71.         topTmp = parseInt(currentScreen.top);
  72.         heightTmp = parseInt(currentScreen.height);
  73.         resultOffset = topTmp + heightTmp;
  74.  
  75.         screen = this.screenManager.screenForRect(leftConst, resultOffset, widthConst, currentScreen.height );
  76.         screen.GetRect(left,top,width,height);
  77.  
  78.         jslog('new screen: ' + left.value + ' ' + top.value + ' ' + width.value + ' ' + height.value + ' ');
  79.  
  80.         if(!this.checkIfExists(left, top, width, height)){  //////pass display screen instead of values
  81.             jslog('pushing a screen');
  82.             var displayScreen = {left: left.value, top: top.value, width: width.value, height: height.value};
  83.             this.displayScreens.push(displayScreen); //add order property for sequence?
  84.             this.searchRight(displayScreen);
  85.             this.searchLeft(displayScreen);
  86.             this.searchDown(displayScreen); // not sure if array could be empty at the position?
  87.         }
  88.     },
  89.  
  90.     searchRight: function(currentScreen){
  91.         jslog('searching right');
  92.  
  93.         leftTmp = parseInt(currentScreen.left);
  94.         widthTmp = parseInt(currentScreen.width);
  95.         resultOffset = leftTmp + widthTmp;
  96.  
  97.         screen = this.screenManager.screenForRect(resultOffset, currentScreen.top, currentScreen.width, currentScreen.height );
  98.         screen.GetRect(left,top,width,height);
  99.  
  100.         jslog('new screen: ' + left.value + ' ' + top.value + ' ' + width.value + ' ' + height.value + ' ');
  101.  
  102.         if(!this.checkIfExists(left, top, width, height)){
  103.             jslog('pushing a screen');
  104.             var displayScreen = {left: left.value, top: top.value, width: width.value, height: height.value};
  105.             this.displayScreens.push(displayScreen); //add order property for sequence?
  106.             this.searchRight(displayScreen); // not sure if array could be empty at the position?
  107.         }
  108.     },
  109.  
  110.     searchLeft: function(currentScreen){
  111.         jslog('searching left');
  112.  
  113.         leftTmp = parseInt(currentScreen.left);
  114.         widthTmp = parseInt(currentScreen.width);
  115.         resultOffset = leftTmp - widthTmp;
  116.  
  117.         screen = this.screenManager.screenForRect(resultOffset, currentScreen.top, currentScreen.width, currentScreen.height );
  118.         screen.GetRect(left,top,width,height);
  119.  
  120.         jslog('new screen: ' + left.value + ' ' + top.value + ' ' + width.value + ' ' + height.value + ' ');
  121.  
  122.         if(!this.checkIfExists(left, top, width, height)){
  123.             jslog('pushing a screen');
  124.             var displayScreen = {left: left.value, top: top.value, width: width.value, height: height.value};
  125.             this.displayScreens.push(displayScreen); //add order property for sequence?
  126.             this.searchLeft(displayScreen); // not sure if array could be empty at the position?
  127.         }
  128.     },
  129.  
  130.     checkIfExists: function(left, top, width, height){
  131.         var result;
  132.  
  133.         result = this.isScreenEqual(left, top, width, height, this.primaryScreen);
  134.  
  135.         for(var i=0; i<this.displayScreens.length; i++){
  136.             if(this.isScreenEqual(left, top, width, height, this.displayScreens[i])){
  137.                 result = true;
  138.             }
  139.         }
  140.         return result;
  141.     },
  142.  
  143.     isScreenEqual: function(left, top, width, height, screen2){
  144.         if(left.value == screen2.left && top.value == screen2.top
  145.             && width.value == screen2.width && height.value == screen2.height){
  146.             return true;
  147.         }
  148.         return false;
  149.     },
  150.  
  151.     launchDisplays: function(){ //open live displays depending on config
  152.  
  153.         if(this.validationPassed){
  154.             for(var i=0; i < this.displayScreens.length; i++){ // i < num Displays eventually
  155.                 this.displayWindows.push( window.open(this.url, "Live Display"+i, "chrome"));
  156.                 this.displayWindows[i].moveTo(this.displayScreens[i].left,this.displayScreens[i].top);
  157.                 this.displayWindows[i].fullScreen = true;
  158.             }
  159.             this.displaysRunning = true;
  160.         }
  161.  
  162.         //sequence launch
  163.         /*        if(this.validationPassed){
  164.          for(var i=0; i < this.displayScreens.length; i++){ // i < num Displays eventually
  165.          this.displayWindows.push( window.open(this.url, "Live Display"+i, "chrome"));
  166.          this.displayWindows[i].moveTo(this.displayScreens[this.displaySequence[i]].left,0);
  167.          this.displayWindows[i].fullScreen = true;
  168.          }
  169.          this.displaysRunning = true;
  170.          }*/
  171.     },
  172.  
  173.     closeDisplays: function(){
  174.         for(var i=0; i < this.displayWindows.length; i++){
  175.             this.displayWindows[0].close();
  176.             this.displayWindows[0] = null;
  177.             this.displayWindows.shift();
  178.         }
  179.         this.displaysRunning = false;
  180.     },
  181.  
  182.     toggleDisplays: function(){
  183.         this.displaysRunning ? this.closeDisplays() : this.launchDisplays();
  184.     },
  185.  
  186.     validate: function(){
  187.         if(this.active && getOS()=='Windows' && this.url!='' && this.screenManager.numberOfScreens > 1){
  188.             this.validationPassed = true;
  189.         }
  190.     }
  191. }
  192.  
  193. var screen;
  194.  
  195. var left = {},
  196.     top = {},
  197.     width = {},
  198.     height = {};
  199.  
  200. var leftConst = -10000;
  201. var widthConst = 20000;
  202. var leftTmp;
  203. var topTmp;
  204. var widthTmp;
  205. var heightTmp;
  206. var resultOffset;
  207.  
  208.  
  209.  
  210.  
  211.  
  212. window.addEventListener('load', displayManager.init(), false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement