diff --git a/lib/xcore.js b/lib/xcore.js index cf073e4..17eb9ed 100644 --- a/lib/xcore.js +++ b/lib/xcore.js @@ -119,6 +119,7 @@ XClient.prototype.init = function(stream) this.startHandshake(); this._closing = false; + this._unusedIds = []; } // TODO: close() = set 'closing' flag, watch it in replies and writeQueue, terminate if empty @@ -247,12 +248,17 @@ XClient.prototype.importRequestsFromTemplates = function(target, reqs) XClient.prototype.AllocID = function() { - // TODO: handle overflow (XCMiscGetXIDRange from XC_MISC ext) - // TODO: unused id buffer - this.display.rsrc_id++; - return (this.display.rsrc_id << this.display.rsrc_shift) + this.display.resource_base; -} + if (this._unusedIds.length > 0) { + return this._unusedIds.pop(); + } + // TODO: handle overflow (XCMiscGetXIDRange from XC_MISC ext) + this.display.rsrc_id++; + return (this.display.rsrc_id << this.display.rsrc_shift) + this.display.resource_base; +}; +XClient.prototype.ReleaseID = function(id) { + this._unusedIds.push(id); +}; // TODO: move core events unpackers to corereqs.js XClient.prototype.unpackEvent = function(type, seq, extra, code, raw, headerBuf)