sidorares / node-x11

X11 node.js network protocol client
MIT License
517 stars 72 forks source link

NOT GOING INSIDE x.on('event', #128

Open himanshuoodles opened 8 years ago

himanshuoodles commented 8 years ago

This is the code i get from you and when i run on mac it working fine but not going in side x.on('event' var x11 = require('x11');

x11.createClient(function(err, display) {
                  var X = display.client;
                  X.InternAtom(false, '_NET_WM_PID', function(err, pidAtom ) {
                               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, display.screen[0].root, ev.atom, X.atoms.WINDOW, 0, 4, function(err, prop) {
                                                                var active = prop.data.readUInt32LE(0);
                                                                X.GetProperty(0, active, pidAtom, X.atoms.CARDINAL, 0, 4, function(err, prop) {
                                                                              console.log('PID:', prop.data.readUInt32LE(0));
                                                                              });
                                                                });
                                                  }
                                                  });
                                    }
                                    });
                               });
                  });

screen shot 2016-05-25 at 6 26 33 am

i am not enter in step 4

screen shot 2016-05-25 at 6 26 39 am

sidorares commented 8 years ago

Try to launch second x11 application while your script is running ( for example, type xeyes in terminal ) and switch focus to / from that application.

himanshuoodles commented 8 years ago

Basically, what i meant to say is that the event ( PropertyNotify ) is not getting fired when i switch active windows.

However, it the event fires when i switch focus to / from xeyes . What does xeyes has to do with it?

I understood the earlier issue of not having X server but now when i have the X server, why isn't the Client responding to events from the server?

Am I missing something here?

himanshuoodles commented 8 years ago

so whats the advantage of it . I am making an app which will detect active current focus window it give everything in windows but in MAC it is not working good . Is x11 is not sufficient to use for MAC system in node webkit ? . and If it is sufficient plz tell now to do so by your plugin .

sidorares commented 8 years ago

this depends on integration between X and cocoa ( which is not great ). Your example is even more complicated because it involves window manager - it's separate process that is responsible for changing _NET_ACTIVE_WINDOW property of root window, and window manager ( in your example it's probably opt/X11/bin/quartz-wm ) does not care about non-X apps

sidorares commented 8 years ago

so whats the advantage of it

X over more "native" (in osx - Cocoa / Quartz )?

It's more portable and currently "native" for unixes. If you intend to use on osx only there is n advantage. Also X clients are easy to connect remotely over network (from computer with potentially no real hardware display)

sidorares commented 8 years ago

this is a good introduction to what X is - http://magcius.github.io/xplain/article/

himanshuoodles commented 8 years ago

nice link but @sidorares can you give me an example or docs of x11 which gives active window detail in MAC .that would we very helpful

sidorares commented 8 years ago

x11 know nothing about osx windows. You may have some luck with AppleWM extension ( node-x11 partially implements it )

sidorares commented 8 years ago

this prints you some events from AppleWM, but it looks that at most you'll get notifications when your x11 windows are shown:

var x11 = require('../../lib');

x11.createClient(function(err, display) {
    var X = display.client;
    X.require('apple-wm', function(err, AppleWM) {
         AppleWM.SelectInput(AppleWM.NotifyMask.All)
         X.on('event', function(ev) {
           console.log("Event", ev); //df();
         });
    });
});

See http://www.xfree86.org/4.6.0/AppleWM.3.html