Ejemplo n.º 1
0
	function pair(winId,windows) {
		if (frozen || windows.length ==1 || winId == chrome.windows.WINDOW_ID_NONE)
			return;		
            
	    var runner = new TaskRunner();
										
        var pos = 0;
        if (windows[1].id == winId){
            pos = 1;
        }
			
			/* Approach 1 */
			/* Original approach.
			  
			this.frozen = true;
			chrome.windows.update(windows[1 - pos].id , {focused: true , state:"normal"});
			chrome.windows.update(windows[pos].id , {focused: true , state:"normal"});
			
			setTimeout(function() {
                display.frozen = false; 
          },1000); // Un-freeze after 1000ms
          */
          
        runner.step(function() { // Refresh the latest status of window
            var condition = [];
            var updatedWindows = [];
            
            for (var i = 0 ; i < windows.length ; i++) {              
                (function(win) {		
                    var deferred = $.Deferred();
                    condition.push(deferred);
                    chrome.windows.get(win.id,{},function(w) {
                        updatedWindows.push(w);
                        deferred.resolve();	
                    });
                })(windows[i]);
            }

            $.when.apply(null,condition).done(function() {
                runner.next(updatedWindows);
            });
            
        });
        
        runner.step(function(updatedWindows) {
            var stop = false;
            for (var i = 0 ; i < updatedWindows.length;i++) {
                if (updatedWindows[i].state == "minimized") {
                    stop = true;
                    break;
                }
            }
            
            if (stop) {
                runner.stop()
            } else {
                runner.next();
            }
        });
		
        runner.step(function() {	
            
            
			/* Approach 2 */
			/* This method works better in Ubuntu/Unity */

			freeze(1000);

			/* Within Ubuntu/Unity , using alt-tab switching between two managed windows.
			 * The launcher icon will vibrate. It is annonying. Trying to freeze for a while.
			 * 
			 */
            
			chrome.windows.update(windows[1 - pos].id , {focused: true},function() {
				chrome.windows.update(windows[pos].id , {focused: true},function() {
				});
			});

			/* Remarks: Do not set state to "normal". If the window is maximized, it will force to rollback to previous
			 * size. It is quite annoying.  

			 */	
        });
        
        runner.run(function() {
        });
        
	};
Ejemplo n.º 2
0
    function arrange(target,options,callback) {
        var windows = options.windows,
             viewport = options.viewport,
             os = options.os,
             updatedWindows = [], // Result of processed windows
             recalculated = false,
             runner = new TaskRunner(),
             rects ; // The rectangles of window.

        rects = split(target,options); // The rectangles of window.
//        console.log("arrange",target,rects);
       
        runner.step(function() {
            // Call resize in parallel.
            // Nested call do not work well on Windows and the response time may be slow					
            // p.s Nested call can not resolve the alignment / overlapping problem in Ubuntu/Unity

            var condition = [];
            updatedWindows = [];
            for (var i = 1 ; i >= 0 ; i--) {
                var updateInfo = {};
                $.extend(updateInfo,rects[i].toData());
                
                if (i === 0)
                    updateInfo.focused = true;
                
                (function(win) {		
                    var deferred = $.Deferred();
                    condition.push(deferred);
                    resize({window : win,
                            updateInfo : updateInfo,
                            os : os
                            },function(win) {
                               updatedWindows.push(win);
                               deferred.resolve();	
                            });
                })(windows[i]);
            }

            $.when.apply(null,condition).done(function() {
                runner.next();
            });
            
        });     

        runner.run(function() {
            // Calculate the result
            var updatedWindowsRect = []; // The rect object of the updated window
            $(updatedWindows).each(function(idx,win) {
                var r = new Rect(win);
                updatedWindowsRect.push(r);
            });
            
            var intersected = updatedWindowsRect[0].intersect(updatedWindowsRect[1]);
            var imperfect = false; // The result is imperfect
            var accept = true; // TRUE if the result is accepted event it is imperfect. Call the callback function.
            
            if (intersected.size() > 0 ) { // Prove that it is intersected!
                imperfect = true;
                //unite = updatedWindowsRect[0].unite(updatedWindowsRect[1]);
            }
            
            callback({
                imperfect : imperfect,
                rects : updatedWindowsRect
            });
        });
        
    }