Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create script to launch a set of terminals in a workspace #29

Open
Tyriar opened this issue Dec 9, 2015 · 6 comments
Open

Create script to launch a set of terminals in a workspace #29

Tyriar opened this issue Dec 9, 2015 · 6 comments

Comments

@Tyriar
Copy link
Owner

Tyriar commented Dec 9, 2015

http://askubuntu.com/a/614205

@Tyriar
Copy link
Owner Author

Tyriar commented Dec 11, 2015

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
Copy link
Owner Author

Tyriar commented Dec 11, 2015

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

@Tyriar
Copy link
Owner Author

Tyriar commented Dec 11, 2015

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
Copy link
Owner Author

Tyriar commented Dec 11, 2015

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
Copy link
Owner Author

Tyriar commented Dec 11, 2015

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

wmctrl -r :ACTIVE: -b add,maximized_vert

@Tyriar
Copy link
Owner Author

Tyriar commented Dec 11, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant