kasper / phoenix

A lightweight macOS window and app manager scriptable with JavaScript
https://kasper.github.io/phoenix/
Other
4.36k stars 128 forks source link

Window dragging events (start/drag/stop) #276

Closed rcarmo closed 2 years ago

rcarmo commented 3 years ago

This is a follow-up to #262 as a feature request, since I've been spending some time trying to use the mouse drag events (which only work horizontally, but that's besides the point) but can't find a working strategy for detecting window dragging accurately.

Iterating through all windows is fallible when there are overlaps, and trying to figure out if the mouse is dragging atop the titlebar of a window by coordinates alone is... highly fallible as well.

kasper commented 3 years ago

@rcarmo Any reason of not using the windowDidMove event which is triggered if any window moved?

rcarmo commented 3 years ago

Well, duh. Other than documentation, I guess not. It's really not that easy to figure out how to do some things, I just scrolled past it.

kasper commented 3 years ago

Noted. My plan definitely is to improve the documentation when I have some time and I’m looking into adding https://docusaurus.io to the mix.

rcarmo commented 3 years ago

Well, I can try to donate a few snippets to get things started. Code examples are probably the best accelerator to actually spot what can be done.

kasper commented 3 years ago

There’s more examples here: https://github.com/kasper/phoenix/wiki

rcarmo commented 3 years ago

In the meantime I started playing around with this:


class Drag {
  constructor() {
    this.active = false
    this.event = null
    this.overlay = Modal.build({
        text: "foo",
        icon: App.get('Phoenix').icon(),
        appearance: HINT_APPEARANCE,
        duration: 0
    })
  } // constructor

  move(window) {
    window.log()
    this.overlay.attach(window)
    this.overlay.show()
  }

  toggle() {
    if(this.active) {
      Phoenix.notify("off")
      this.active = false
      this.event.disable()
      this.overlay.close()
    } else {
      Phoenix.notify("on")
      this.active = true
      var self = this;
      this.event = new Event("windowDidMove", (win) => {
        self.move(win)
      })
    }
  } // toggle
}

const DragManager = new Drag()

Key.on("space", ["option", "shift"], () => DragManager.toggle());

...and it has a few issues. Of course I get every single move event (including when I move windows with hotkeys) and I still have to try to correlate that with mouse events and figure out if the mouse is over the moving window and with. button down (which I've yet to do), but it is a start.