PropertyNotify event.window is null
See original GitHub issueI’m using this code snippet based on your post here
main.js
var x11 = require('x11');
x11.createClient(function (err, display) {
var X = display.client;
X.ChangeWindowAttributes(display.screen[0].root, {eventMask: x11.eventMask.PropertyChange});
X.on('event', function (ev) {
if (ev.name === 'PropertyNotify') {
X.GetAtomName(ev.atom, function (err, name) {
if (name === '_NET_ACTIVE_WINDOW') {
X.GetProperty(0, ev.window, ev.atom, X.atoms.WINDOW, 0, 4, function (err, prop) {
console.log('New active window:' + prop.data.readUInt32LE(0));
});
}
});
}
});
});
However, it seems that ev.window
is null, as well as prop
:
cj@lighthouse:~/workspace/moodring$ node main.js
/home/cj/workspace/moodring/main.js:10
console.log('New active window:' + prop.data.readUInt32LE(0));
^
TypeError: Cannot read property 'data' of undefined
at /home/cj/workspace/moodring/main.js:10:64
at ReadFixedRequest.callback (/home/cj/workspace/moodring/node_modules/x11/lib/xcore.js:490:39)
at ReadFixedRequest.execute (/home/cj/workspace/moodring/node_modules/x11/lib/unpackstream.js:41:10)
at UnpackStream.resume (/home/cj/workspace/moodring/node_modules/x11/lib/unpackstream.js:165:30)
at UnpackStream.write (/home/cj/workspace/moodring/node_modules/x11/lib/unpackstream.js:102:10)
at Socket.<anonymous> (/home/cj/workspace/moodring/node_modules/x11/lib/xcore.js:88:21)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
What’s the proper way to listen for changes in the active (focused) window? I’m running Ubuntu 16.04 with Unity.
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
How do I capture minimize and maximize events in XWindows?
The program shapes the events into what I consider the important states of a window, that is, maximized (occupying the whole screen), ...
Read more >web.mit.edu/ghudson/dev/nokrb/third/metacity/src/d...
HAVE_RENDER */ /* Create the leader window here. Set its properties and * use the timestamp from one of the PropertyNotify events *...
Read more >XGetWindowProperty - X.Org
The XListProperties function returns a pointer to an array of atom properties that are defined for the specified window or returns NULL if...
Read more >window.event is null when dispatching an event with ... - MSDN
When I use dispatchEvent from the webbrowser control the handler is executed but window.event is null causing a javascript error.
Read more >desktop_window_tree_host_x11.cc - Google Git
#include "ui/events/devices/x11/device_data_manager_x11.h" ... return host ? host->window()->GetProperty(kHostForRootWindow) : NULL;.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@santigimeno that works perfectly, thank you so much! and thank you @sidorares for your help as well.
I’m quite new to node.js but I will be using both libraries (node-x11 and x11-prop) extensively and I’m happy to contribute to both as I learn more. Regards
Back to the OP issue. @SpecialBlend, it’s normal the wid you get is the
root
as thePropertyNotify
the event comes from theroot
window. To get the active windowwid
you need to get the_NET_ACTIVE_WINDOW
property and then use that wid to get WM_CLASS, WM_NAME, etc. As an example, something like this would work: (I’m using https://github.com/santigimeno/node-x11-prop, that is just a fancy wrapper overGetProperty()
):