0

I'm trying to make a GNOME extension that functions similarly to a dock, except it shows you status info (time, battery, etc). What I'm stuck on here is, how do I get the info to show up when the cursor enters a specific pixel area? Like, if the screen is 1600x900 pixels (just an example), it should activate when x>1550 and 800>y>850. That's not the actual pixel range, but something in that general area. My question is, how can I make it so that it checks often for whether or not the cursor is in that area? I could just do a while loop, but I think that would be resource-heavy and there must be a better way. Is there? So far I've looked both at other extensions as well as online for APIs, but it seems that I can't find anything that could be of use. I saw this one thing about a mainloop which looked promising, but I didn't really understand it.

Thanks in advance!

Bruce Wayne
  • 25
  • 1
  • 5

1 Answers1

0

Note, you can't use an infinite while loop since it would block the shell; you have to use the mainloop.

You can use the pointerWatcher (more convenient since they added idle monitor detection):
https://gitlab.gnome.org/GNOME/gnome-shell/blob/master/js/ui/pointerWatcher.js

Example:

let PointerWatcher = imports.ui.pointerWatcher;

let watcher = new PointerWatcher.PointerWatcher();

let watch = watcher.addWatch(50, (x, y) => {
    let m = Main.layoutManager.currentMonitor;

    if ((m.height - y) < 200 && (m.width - x) < 200) {
        Main.notify("asdf");
    }
});

// watch.remove();

There is also that Meta.Barrier thing. Might look into.

zagortenay333
  • 259
  • 3
  • 8