ntk 3.8.0 → 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/window.js +33 -0
- package/package.json +1 -1
package/lib/window.js
CHANGED
|
@@ -1099,6 +1099,39 @@ export default class Window extends Drawable {
|
|
|
1099
1099
|
});
|
|
1100
1100
|
}
|
|
1101
1101
|
|
|
1102
|
+
/**
|
|
1103
|
+
* Write a property — the counterpart of getProperty, and the general form
|
|
1104
|
+
* of setTitle/setClass/setSizeHints. Strings are written as UTF8_STRING,
|
|
1105
|
+
* arrays of numbers as 32-bit lists; `type` names the property type atom
|
|
1106
|
+
* ('ATOM', 'CARDINAL', 'WINDOW', 'UTF8_STRING', 'STRING'), which is what
|
|
1107
|
+
* EWMH properties are picky about.
|
|
1108
|
+
*
|
|
1109
|
+
* wnd.setProperty('_NET_WM_NAME', 'a title');
|
|
1110
|
+
* wnd.setProperty('_NET_CLIENT_LIST', ids, { type: 'WINDOW' });
|
|
1111
|
+
*
|
|
1112
|
+
* @param {string} name atom name of the property
|
|
1113
|
+
* @param {string|number[]|Buffer} value
|
|
1114
|
+
* @param {object} [options] `{ type, format }`
|
|
1115
|
+
*/
|
|
1116
|
+
async setProperty(name, value, options = {}) {
|
|
1117
|
+
const isList = Array.isArray(value);
|
|
1118
|
+
const { type = isList ? 'CARDINAL' : 'UTF8_STRING', format = isList ? 32 : 8 } =
|
|
1119
|
+
options;
|
|
1120
|
+
const [property, typeAtom] = await Promise.all([this.atom(name), this.atom(type)]);
|
|
1121
|
+
let data = value;
|
|
1122
|
+
if (isList) {
|
|
1123
|
+
const words = new Uint32Array(value);
|
|
1124
|
+
data = Buffer.from(words.buffer, words.byteOffset, words.byteLength);
|
|
1125
|
+
} else if (typeof value === 'string') {
|
|
1126
|
+
data = Buffer.from(value, type === 'STRING' ? 'latin1' : 'utf8');
|
|
1127
|
+
}
|
|
1128
|
+
if (this._destroyed) return this;
|
|
1129
|
+
safeRelease(this.X, () => {
|
|
1130
|
+
this.X.ChangeProperty(0, this.id, property, typeAtom, format, data);
|
|
1131
|
+
});
|
|
1132
|
+
return this;
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1102
1135
|
/**
|
|
1103
1136
|
* Intern an atom by name. node-x11 caches them per connection, so asking
|
|
1104
1137
|
* again for one already interned costs no round trip.
|