Comparing version 0.2.0 to 0.3.0
10
log.js
@@ -1,2 +0,2 @@ | ||
// Generated by LiveScript 1.4.0 | ||
// Generated by LiveScript 1.5.0 | ||
(function(){ | ||
@@ -9,4 +9,8 @@ var me, slice$ = [].slice; | ||
function log(){ | ||
var args, d, t; | ||
args = slice$.call(arguments); | ||
var args, res$, i$, to$, d, t; | ||
res$ = []; | ||
for (i$ = 0, to$ = arguments.length; i$ < to$; ++i$) { | ||
res$.push(arguments[i$]); | ||
} | ||
args = res$; | ||
d = new Date(Date.now()); | ||
@@ -13,0 +17,0 @@ t = d.getDate() + "/" + (1 + d.getMonth()) + " " + d.toLocaleTimeString(); |
{ | ||
"name": "xawt", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "A command-line tool to run shell commands whenever the active window focus changes", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -8,4 +8,4 @@ # xawt - X11 active window trigger | ||
I use it to prevent too many idling virtualbox guests from surreptitiously | ||
stealing cpu cycles. | ||
I use it to prevent too many idling applications from surreptitiously | ||
stealing cpu cycles, but you may find it useful in other ways. | ||
@@ -12,0 +12,0 @@ ## install globally and run |
@@ -22,8 +22,14 @@ // Generated by LiveScript 1.5.0 | ||
Xaw.on('changed', function(it){ | ||
var ref$, ref1$; | ||
log.debug('changed', it); | ||
clearPendings('in', it.previous); | ||
clearPendings('out', it.current); | ||
clearPendings('in', (ref$ = it.previous) != null ? ref$.wid : void 8); | ||
clearPendings('out', (ref1$ = it.current) != null ? ref1$.wid : void 8); | ||
doActions('out', it.previous); | ||
return doActions('in', it.current); | ||
}); | ||
Xaw.on('closed', function(it){ | ||
log.debug('closed', it); | ||
clearPendings('in', it); | ||
return clearPendings('out', it); | ||
}); | ||
function addPending(act, wid, key){ | ||
@@ -40,5 +46,5 @@ var secs, t; | ||
} | ||
function clearPendings(direction, state){ | ||
function clearPendings(direction, wid){ | ||
var id, ref$, p, ref1$, results$ = []; | ||
if (state == null) { | ||
if (wid == null) { | ||
return; | ||
@@ -48,3 +54,3 @@ } | ||
p = ref$[id]; | ||
if (p.act.direction === direction && p.wid === state.wid) { | ||
if (p.act.direction === direction && p.wid === wid) { | ||
log.debug("clear pending[" + id + "]"); | ||
@@ -100,5 +106,2 @@ clearTimeout(p.timeout); | ||
} | ||
if (state == null) { | ||
return log.debug("window " + wid + " has closed -- aborting"); | ||
} | ||
return runCommand(p.act, wid); | ||
@@ -105,0 +108,0 @@ }); |
@@ -1,4 +0,4 @@ | ||
// Generated by LiveScript 1.4.0 | ||
// Generated by LiveScript 1.5.0 | ||
(function(){ | ||
var Assert, Asyn, Evem, X11, root, state, x, me; | ||
var Assert, Asyn, Evem, X11, candidateForCloseWids, root, state, x, me; | ||
Assert = require('assert'); | ||
@@ -8,2 +8,3 @@ Asyn = require('async'); | ||
X11 = require('x11'); | ||
candidateForCloseWids = {}; | ||
module.exports = me = import$(clone$(new Evem()), { | ||
@@ -13,5 +14,2 @@ getWindowState: function(wid, cb){ | ||
var title; | ||
if ((xerr != null ? xerr.error : void 8) === 3) { | ||
return cb(); | ||
} | ||
if (xerr) { | ||
@@ -42,3 +40,3 @@ return cb(wrapXerr("x.GetProperty WM_NAME failed (wid=" + wid + ")", xerr)); | ||
x.ChangeWindowAttributes(root, { | ||
eventMask: X11.eventMask.PropertyChange | ||
eventMask: X11.eventMask.PropertyChange + X11.eventMask.SubstructureNotify | ||
}); | ||
@@ -78,2 +76,3 @@ return getActiveWid(function(err, wid){ | ||
} | ||
candidateForCloseWids[wid] = true; | ||
return cb(null, wid); | ||
@@ -83,33 +82,56 @@ }); | ||
function worker(task, cb){ | ||
if (task.atom !== x.atoms._NET_ACTIVE_WINDOW) { | ||
return cb(); | ||
} | ||
return getActiveWid(function(err, wid){ | ||
var pwid; | ||
if (err || !wid) { | ||
return cb(err); | ||
} | ||
Assert(state.current.wid, 'state.current.wid'); | ||
if (wid === state.current.wid) { | ||
var wid, ref$; | ||
switch (task.name) { | ||
case 'PropertyNotify': | ||
if (task.atom !== x.atoms._NET_ACTIVE_WINDOW) { | ||
return cb(); | ||
} | ||
return me.getWindowState(pwid = state.current.wid, function(err, prev){ | ||
if (err) { | ||
return getActiveWid(function(err, wid){ | ||
var ref$; | ||
if (err || !wid) { | ||
return cb(err); | ||
} | ||
state.previous = prev; | ||
if (wid === ((ref$ = state.current) != null ? ref$.wid : void 8)) { | ||
return cb(); | ||
} | ||
return me.getWindowState(wid, function(err, cur){ | ||
var pwid; | ||
if (err) { | ||
return cb(err); | ||
} | ||
state.current = cur; | ||
me.emit('changed', state); | ||
return cb(); | ||
if (state.current) { | ||
return me.getWindowState(pwid = state.current.wid, function(err, prev){ | ||
state.current = cur; | ||
if (err) { | ||
return cb(err); | ||
} | ||
state.previous = prev; | ||
me.emit('changed', state); | ||
return cb(); | ||
}); | ||
} else { | ||
state.current = cur; | ||
state.previous = null; | ||
me.emit('changed', state); | ||
return cb(); | ||
} | ||
}); | ||
}); | ||
}); | ||
case 'UnmapNotify': | ||
if (!candidateForCloseWids[wid = task.wid]) { | ||
return cb(); | ||
} | ||
delete candidateForCloseWids[wid]; | ||
if (((ref$ = state.current) != null ? ref$.wid : void 8) === wid) { | ||
state.current = null; | ||
} | ||
me.emit('closed', wid); | ||
return cb(); | ||
default: | ||
return cb(); | ||
} | ||
} | ||
function wrapXerr(msg, xerr){ | ||
var ref$; | ||
return ref$ = clone$(new Error(msg + ". " + xerr.message)), ref$.xerr = xerr, ref$; | ||
return ref$ = clone$(new Error(msg + ". " + xerr.message + " [" + xerr.error + "]")), ref$.xerr = xerr, ref$; | ||
} | ||
@@ -116,0 +138,0 @@ function import$(obj, src){ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17088
389