sway-tools
Version:
Some tools and a library for controlling sway
51 lines (50 loc) • 1.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Sway = void 0;
const cp = require("child_process");
const util = require("util");
const shelljs = require("shelljs");
const path = require("path");
const exec = util.promisify(cp.execFile);
class Sway {
constructor() {
this.commands = [];
}
async getOutputs() {
const json = shelljs.exec('swaymsg -r -t get_outputs', {
async: false,
silent: true,
});
return JSON.parse(json);
}
async getTree() {
const json = shelljs.exec('swaymsg -t get_tree', {
async: false,
silent: true,
});
return JSON.parse(json);
}
focus() {
this.commands.push('focus');
return this;
}
output(output) {
this.commands.push('output');
this.commands.push(`"${output.make} ${output.model} ${output.serial}"`);
return this;
}
bg(file, mode) {
this.commands.push('bg');
this.commands.push(`"${file}"`);
this.commands.push(mode);
return this;
}
async exec() {
await exec('swaymsg', this.commands);
this.commands = [];
}
}
exports.Sway = Sway;
if (require.main.filename === path.join(__dirname, __filename)) {
console.dir({ x: require.main.filename, y: __filename });
}