Author: jruchaud Date: 2015-04-30 13:45:21 +0000 (Thu, 30 Apr 2015) New Revision: 1307 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/1307 Log: Fix atom :-) Modified: wit/js/services/UserActivityService.js Modified: wit/js/services/UserActivityService.js =================================================================== --- wit/js/services/UserActivityService.js 2015-04-30 09:50:31 UTC (rev 1306) +++ wit/js/services/UserActivityService.js 2015-04-30 13:45:21 UTC (rev 1307) @@ -67,7 +67,7 @@ } return rst; -} +}; /** * Offers an api for services interesting in activity change detection @@ -99,15 +99,13 @@ var X = display.client; X.ChangeWindowAttributes(display.screen[0].root, { - eventMask:x11.eventMask.PropertyChange + eventMask: x11.eventMask.PropertyChange }); // Init windows session with the currently active window +// addWindowSession(X, display.screen[0].root); - addWindowSession(X, display.screen[0].root); - // Listen to client display events to identify when the currently active window has change - X.on('event', onActiveWindowChange.bind(null, X)); }); @@ -134,19 +132,19 @@ if (name == '_NET_ACTIVE_WINDOW') { - registerWindowEvents(X, ev.wid); - addWindowSession(X, ev.wid); + registerWindowEvents(X, ev); + addWindowSession(X, ev); } else if (name == '_NET_WM_NAME') { - updateWindowSession(ev.wid); + updateWindowSession(X, ev); } }); } }; -var registerWindowEvents = function (X, parentId) { - getActiveWindowId(X, parentId) +var registerWindowEvents = function (X, ev) { + getActiveWindowId(X, ev) .then(function (wid) { X.ChangeWindowAttributes(wid, { eventMask:x11.eventMask.PropertyChange @@ -157,10 +155,10 @@ /** * Create a new window session */ -var addWindowSession = function (X, parentId) { +var addWindowSession = function (X, ev) { var crt = crtSession; - return getActiveWindowId(X, parentId) + return getActiveWindowId(X, ev) .then(getWindowName) .then(createNewSession) .then(setupActivityDetection.bind(null, crt)); @@ -171,8 +169,8 @@ * but it's title has changed. * Trace it by creating a new session with the same shape attributes than the previous one */ -var updateWindowSession = function (wid) { - return getWindowName(wid) +var updateWindowSession = function (X, ev) { + return getWindowName(ev.wid) .then(function (windowName) { // Let's create a new seesion but with same color attributes than the last one, @@ -185,36 +183,44 @@ }); }; -var getActiveWindowId = function (X, parentId) { +var getActiveWindowId = function (X, ev) { return new Promise(function (resolve, reject) { - X.GetProperty(0, parentId, _NET_ACTIVE_WINDOW, X.atoms.WINDOW, 0, 4, function(err, prop) { + if (!ev.wid) return reject(); + + X.GetProperty(0, ev.wid, ev.atom, X.atoms.WINDOW, 0, 4, function(err, prop) { if (err || !prop.data.length) { - console.log("Couldn't retrieve active window property"); reject(); } else { - resolve(prop.data.readUInt32LE(0)); + var wid = prop.data.readUInt32LE(0); + + if (wid) { + resolve(wid); + + } else { + console.log("Couldn't retrieve active window property"); + reject(); + } } }); }); -} +}; var getWindowName = function (windowId) { return new Promise(function (resolve, reject) { - + + if (!windowId) return reject(); + xprop({prop:'_NET_WM_NAME', id:windowId}, function(err, properties) { if (err) { - console.log("Couldn't retrieve window name for id :", windowId); reject(); } else { - resolve(properties.length && properties[0].value); - } }); });
participants (1)
-
jruchaud@users.nuiton.org