kasper / phoenix

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

Call function on drag click with modifier key #353

Open l16r opened 2 months ago

l16r commented 2 months ago

I want to implement functionality that allows the window to be moved without clicking the title bar. My idea is to register a drag click while hovering over a window and a modifier key (e.g. "command") being pressed and then move the window position relative to the mouse position in comparison to the start. The behavior is similar to the one implement by dwm. However, I don't want to require any key to be pressed other than the command modifier key. Trying to achieve this behavior in the following manner does not work:

Key.on("command", [], () => console.log("command"))

And how can I connect this to the mouseDidLeftDrag event?

kasper commented 1 month ago

Hi @l16r! Sorry for the delay. You cannot bind an empty set of keys. So unfortunately, you will need to specify some key in addition to the command modifier.

For combining the drag event, you can do something like this:

Key.on('command', 'q', () => {
  Event.on('mouseDidLeftDrag', () => {
    // Move window
  });
});
mafredri commented 1 month ago

@l16r if it helps, feel free to use my implementation for inspiration: https://github.com/mafredri/phoenix-config/blob/af7ee9657a14eb70cb69652ccd1849faf327dc09/src/phoenix.ts#L26-L146

It works like this:

I never polished it, so it has some rough edges but works pretty well most of the time.

(Behavior is triggered by mouse movement only, no press or drag.)