diff --git a/lib/window.js b/lib/window.js index 33a83c6..070f4e7 100644 --- a/lib/window.js +++ b/lib/window.js @@ -86,6 +86,7 @@ function Window(app, args) this.on('event', function(ev) { var ntkev = ev; // todo: clone ntkev.window = this; + ntkev.target = this; var eventName = xevents.eventName[ev.type]; if (eventName) { // TODO cleanup @@ -135,6 +136,14 @@ function Window(app, args) self.y = ev.y; }); + this.on('map', function(ev) { + this._mapped = true; + }); + + this.on('unmap', function(ev) { + this._mapped = false; + }); + if (typeof this.width !== 'undefined') { this._readyPromiseResolve(); } @@ -157,6 +166,52 @@ Window.prototype.resize = function(w, h) { return this; } +const changeAttributesPropNames = 'backgroundPixmap backgroundPixel borderPixmap borderPixel bitGravity winGravity backingStore backingPlanes backingPixel overrideRedirect saveUnder eventMask doNotPropagateMask colormap cursor'; + +Window.prototype.setState = function(newState) { + if (!this._mapped && newState.visible) { + this.map(); + } + if (newState.visible === false && this._mapped) { + this.unmap(); + } + + // 'x y width height borderWidth stackMode sibling' + console.log(this.y, newState.y) + const configureProps = {}; + let needConfigureWindow = false; + if (newState.x !== void(0) && this.x !== newState.x) { + needConfigureWindow = true; + configureProps.x = newState.x + } + if (newState.y !== void(0) && this.y !== newState.y) { + needConfigureWindow = true; + configureProps.y = newState.y; + } + if (newState.width !== void(0) && this.width !== newState.width) { + needConfigureWindow = true; + configureProps.width = newState.width; + } + if (newState.height !== void(0) && this.height !== newState.height) { + needConfigureWindow = true; + newState.height = configureProps.height; + } + if (needConfigureWindow) { + console.log(configureProps) + this.X.ConfigureWindow(this.id, configureProps); + } + + //const changeAttributesProps = {}; + //let needChangeAttributes = false; + //this.X.ChangeWindowAttributes(this.id, changeAttributesProps); + // todo others +} + + +Window.prototype.inspect = function() { + return `[Window ${this.id}]`; +} + Window.prototype.move = function(x, y) { this.X.MoveWindow(this.id, x, y); return this; @@ -177,9 +232,9 @@ Window.prototype.setMouseHintOnly = function(isOn) { this.eventMask |= x11.eventMask.PointerMotionHint; } else if (!isOn && (this.eventMask & x11.eventMask.PointerMotionHint )) { this.eventMask -= x11.eventMask.PointerMotionHint; - } else + } else { return this; - + } this.X.ChangeWindowAttributes(this.id, { eventMask: this.eventMask}, function() {}); return this; }