dotfiles icon indicating copy to clipboard operation
dotfiles copied to clipboard

Create script to launch a set of terminals in a workspace

Open Tyriar opened this issue 8 years ago • 6 comments

http://askubuntu.com/a/614205

Tyriar avatar Dec 09 '15 18:12 Tyriar

Ugly script to do just this:

~/setwindow gnome-terminal 0 0 25 100 && \
  ~/setwindow gnome-terminal $(expr $(xwininfo -root | grep Width | sed 's/\s*Width:\s*//') / 4) 0 25 100 && \
  ~/setwindow gnome-terminal $(expr $(expr $(xwininfo -root | grep Width | sed 's/\s*Width:\s*//') / 4) \* 2) 0 25 100 && \
  ~/setwindow gnome-terminal $(expr $(expr $(xwininfo -root | grep Width | sed 's/\s*Width:\s*//') / 4) \* 3) 0 25 100

~/setwindow via http://askubuntu.com/questions/613973/how-can-i-start-up-an-application-with-a-pre-defined-window-size-and-position/614205#614205

#!/usr/bin/env python3
import subprocess
import time
import sys

app = sys.argv[1]

get = lambda x: subprocess.check_output(["/bin/bash", "-c", x]).decode("utf-8")
ws1 = get("wmctrl -lp"); t = 0
subprocess.Popen(["/bin/bash", "-c", app])

while t < 30:      
    ws2 = [w.split()[0:3] for w in get("wmctrl -lp").splitlines() if not w in ws1]
    procs = [[(p, w[0]) for p in get("ps -e ww").splitlines() \
              if app in p and w[2] in p] for w in ws2]
    if len(procs) > 0:
        w_id = procs[0][0][1]
        cmd1 = "wmctrl -ir "+w_id+" -b remove,maximized_horz"
        cmd2 = "wmctrl -ir "+w_id+" -b remove,maximized_vert"
        cmd3 = "xdotool windowsize --sync "+procs[0][0][1]+" "+sys.argv[4]+"% "+sys.argv[5]+"%"
        cmd4 = "xdotool windowmove "+procs[0][0][1]+" "+sys.argv[2]+" "+sys.argv[3]
        for cmd in [cmd1, cmd2, cmd3, cmd4]:   
            subprocess.call(["/bin/bash", "-c", cmd])
        break
    time.sleep(0.5)
    t = t+1

Tyriar avatar Dec 11 '15 18:12 Tyriar

Get work area: xprop -root | grep WORKAREA Get monitor resolutions: xrandr | grep *+

Tyriar avatar Dec 11 '15 20:12 Tyriar

Get monitor resolutions and x/y positions:

screens=$(xrandr | grep " connected" | sed 's/.*connected\(\sprimary\|\)\s//' | sed 's/\s.*//')
for x in $screens
do
  echo "> [$x]"
done

Tyriar avatar Dec 11 '15 20:12 Tyriar

nodejs for getting res and x/y:

~/setwindow

#!/usr/bin/env python3
import subprocess
import time
import sys

app = sys.argv[1]

get = lambda x: subprocess.check_output(["/bin/bash", "-c", x]).decode("utf-8")
ws1 = get("wmctrl -lp"); t = 0
subprocess.Popen(["/bin/bash", "-c", app])

while t < 30:      
    ws2 = [w.split()[0:3] for w in get("wmctrl -lp").splitlines() if not w in ws1]
    procs = [[(p, w[0]) for p in get("ps -e ww").splitlines() \
              if app in p and w[2] in p] for w in ws2]
    if len(procs) > 0:
        w_id = procs[0][0][1]
        cmd1 = "wmctrl -ir "+w_id+" -b remove,maximized_horz"
        cmd2 = "wmctrl -ir "+w_id+" -b remove,maximized_vert"
        cmd3 = "xdotool windowsize --sync "+procs[0][0][1]+" "+sys.argv[4]+" "+sys.argv[5]
        cmd4 = "xdotool windowmove "+procs[0][0][1]+" "+sys.argv[2]+" "+sys.argv[3]
        for cmd in [cmd1, cmd2, cmd4, cmd3]:   
            subprocess.call(["/bin/bash", "-c", cmd])
        break
    time.sleep(0.5)
    t = t+1

monitor-size.js

var exec = require('child_process').exec;

module.exports = function (callback) {
  exec('xrandr', function (err, stdout) {
    if (err) {
      throw err;
    }

    var monitors = [];
    var lines = stdout.split('\n');
    lines.forEach(function (line) {
      // Format of line: <width>x<height>+<x>+<y>
      var match = line.match('[0-9]+x[0-9]+\\+[0-9]+\\+[0-9]+');
      if (match !== null) {
        monitors.push({
          resolution: {
            width: parseInt(match[0].split('x')[0], 10),
            height: parseInt(match[0].split('x')[1].split('+')[0], 10)
          },
          x: parseInt(match[0].split('x')[1].split('+')[1], 10),
          y: parseInt(match[0].split('x')[1].split('+')[2], 10)
        });
      }
    });
    callback(monitors);
  });
};

open-term.js

var exec = require('child_process').execSync;

var monitorSize = require('./monitor-size');

monitorSize(function (monitors) {
  console.log(monitors);
  monitors.forEach(function (m) {
    var cmd = '~/setwindow gnome-terminal ' + m.x + ' ' + m.y + ' ' + (m.resolution.width / 2 + 1) + ' ' + m.resolution.height;
    console.log(cmd);
    exec(cmd, function (err, stdout) {
      if (err) {
        throw err;
      }
    });
    exec('wmctrl -r :ACTIVE: -b toggle,maximized_vert', function (err, stdout) {
      if (err) {
        throw err;
      }
    });
    cmd = '~/setwindow gnome-terminal ' + (m.x + m.resolution.width / 2 + 1) + ' ' + m.y + ' ' + m.resolution.width / 2 + ' ' + m.resolution.height;
    console.log(cmd);
    exec(cmd, function (err, stdout) {
      if (err) {
        throw err;
      }
    });
    exec('wmctrl -r :ACTIVE: -b toggle,maximized_vert', function (err, stdout) {
      if (err) {
        throw err;
      }
    });
  });
})

Tyriar avatar Dec 11 '15 22:12 Tyriar

wmctrl can snap, as opposed to just resize which leaves gaps/window borders:

wmctrl -r :ACTIVE: -b add,maximized_vert

Tyriar avatar Dec 11 '15 23:12 Tyriar

http://ubuntuguide.net/enable-windows-7-aero-snap-function-with-compiz-in-ubuntu

Tyriar avatar Dec 11 '15 23:12 Tyriar