Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

The basic idea is like tiling window manager with a fixed identical grid system.

I don't want windows piled up in a same desktop(workspace).

We can have a huge virtual desktop like setting up 4x4(=16) workspaces, and place a new window in each workspace every time when the window launchs. Using Unity-Expo, it behaves like zoomed tiled windows/desktop.

If there is a vacant workspace, newly launched window is pushed there, and if workspaces are full, it piled up on some already used workspace, etc.

Of course, I know there is the unity ScaleWindows/WindowPicker, but it's simply a picker or expose of piled-up windows, and they appear very differently in the scaled level and location each time depending on situations.

Anyone knows the way to achieve this, or any plugin available?

Thanks.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

ok, I developed one by myself.

this depends on wmctrl and linq.js

var log = console.log;
var exec = require('child_process').exec;
var spawn = require('child_process').spawn;

var lq = require('linq');
var wlist = [];
var wIDlist0 = lq.empty();
var wIDlist = lq.empty();
var wIDlistD = lq.empty();
var wIDlistE = lq.empty();

var sw;
var sh;
var tw;
var th;

var nx;
var ny;
var nxy;

var vx;
var vy;
var wused = [];

var firstrun = true;

var c1 = exec("xrandr | grep Screen | awk '{ print $8 }'", function (err, stdout, stderr)
{
    sw = stdout * 1;

    var c2 = exec("xrandr | grep Screen | awk '{ print $10 }'  | cut -d ',' -f1", function (err, stdout, stderr)
    {
        sh = stdout * 1;

        var c3 = exec("wmctrl -d | awk '{ print $4 }' | cut -d 'x' -f1", function (err, stdout, stderr)
        {
            tw = stdout * 1;

            var c4 = exec("wmctrl -d | awk '{ print $4 }' | cut -d 'x' -f2", function (err, stdout, stderr)
            {
                th = stdout * 1;

                console.log(sw);
                console.log(sh);
                console.log(tw);
                console.log(th);

                nx = tw / sw;
                ny = th / sh;
                nxy = nx * ny;
                console.log(nx);
                console.log(ny);
                console.log(nxy);

                main();

            })


        })


    })


})

var main = function ()
{
    setInterval(f1, 250);

}

var f1 = function ()
{
    var c5 = exec("wmctrl -d | awk '{ print $6 }' | cut -d ',' -f1", function (err, stdout, stderr)
    {
        vx = stdout * 1;

        var c6 = exec("wmctrl -d | awk '{ print $6 }' | cut -d ',' -f2", function (err, stdout, stderr)
        {
            vy = stdout * 1;

            f2();
        })


    })

    var f2 = function ()
    {
        var listWindows = spawn('wmctrl', ['-l', '-G', '-x']);

        listWindows.stdout.on('data', function (data)
        {

            wIDlist = lq.empty();
            // wlist = [];

            var dataS = '' + data;
            var wlistA = dataS.split('\n');

            lq.from(wlistA)
                .forEach(function (x)
                {
                    // log(x);
                    var sA = x.split(/\s+/g);

                    var id = sA[0];

                    if (sA[1] == '0')
                        if (sA[6] != 'N/A')
                        {
                            //   log(x);
                            wIDlist = wIDlist.union([id]);
                            wlist[id] = [sA[2], sA[3], sA[4], sA[5]];
                        }

                });

            wIDlistD = wIDlist.except(wIDlist0);

            wIDlistE = wIDlist.except(wIDlistD);

            wIDlist0 = wIDlist;

            log(wIDlistD.toArray());
            var wcount = wIDlistD.toLookup().count();
            log(wcount);
            log('------------------');


            if (firstrun)
            {
                wcount = 0;
                firstrun = false;
            }

            if (wcount > 0)   //new windows
            {
                //-------------------
                for (var i = 1; i <= nxy; i++)
                {
                    wused[i] = false;
                }

                wIDlistE.forEach(function (id)
                {
                    var g = wlist[id];
                    var x = g[0] * 1;//  log(x);
                    var y = g[1] * 1;//log(y);
                    var w = g[2] * 1;//log(w);
                    var h = g[3] * 1;//log(h);

                    var cx = (vx + x + w / 2 + tw) % tw;
                    var cy = (vy + y + h / 2 + th) % th;

                    var wx = Math.floor(cx / sw);
                    var wy = Math.floor(cy / sh);

                    console.log('@@-----------');
                    console.log('@@' + wx);
                    console.log('@@' + wy);

                    var n = wy * ny + wx + 1;

                    wused[n] = true;

                });

                var filled = true;
                for (var j = 1; j <= nxy; j++)
                {
                    log(wused[j]);
                    if (wused[j] == false)
                        filled = false;
                }
//-------------
                if (filled == false)
                {
                    wIDlistD.forEach(function (id)
                    {
                        var loop = true;
                        var i = 1;
                        while (loop)
                        {
                            if (wused[i] == false)
                            {
                                wused[i] = true;

                                var x1 = (i - 1) % nx;
                                log('!!!' + x1);
                                var y1 = Math.floor((i - 1) / nx);
                                log('!!!' + y1);

                                var px = (x1 * sw + 200 - vx + tw) % tw;
                                var py = (y1 * sh + 200 - vy + th) % th;
                                log(px);
                                log(py);


                                var c = spawn('wmctrl', ['-ir', id, '-e', '0' + ',' + px + ',' + py + ',' + '-1' + ',' + '-1']);
                                c.stdout.on('data', function (data)
                                {
                                    log(data);

                                });

                                c.stderr.on('data', function (data)
                                {
                                    log('stderr: ' + data);
                                });

                                c.on('exit', function (code)
                                {
                                    log('child process exited with code ' + code);
                                });


                                var x2 = x1 * sw;
                                var y2 = y1 * sh;
                                log('@@@@@@')
                                log(x2);
                                log(y2);
                                var c2 = spawn('wmctrl', ['-o', '' + x2 + ',' + y2  ]);
                                c2.stdout.on('data', function (data)
                                {
                                    log(data);
                                });

                                c2.stderr.on('data', function (data)
                                {
                                    log('stderr: ' + data);
                                });

                                c2.on('exit', function (code)
                                {
                                    log('child process exited with code ' + code);
                                });
                                loop = false;
                            }
                            else
                            {
                                if (i == nxy)
                                    loop = false
                                else
                                    i++
                            }
                        }


                    });



                }


            }


        });

        listWindows.stderr.on('data', function (data)
        {
            log('stderr: ' + data);
        });

        listWindows.on('exit', function (code)
        {
            log('child process exited with code ' + code);
        });
    }


}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.