Skip to content

Commit

Permalink
add setState that wraps ConfigureWindow + ChangeWindowAttributes
Browse files Browse the repository at this point in the history
  • Loading branch information
sidorares committed Apr 10, 2017
1 parent d3ecd2a commit 52da560
Showing 1 changed file with 57 additions and 2 deletions.
59 changes: 57 additions & 2 deletions lib/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit 52da560

Please sign in to comment.