mjolnirapp / mjolnir

Lightweight automation and productivity app for OS X
5.2k stars 128 forks source link

Add app/window/screen events #72

Closed thesoftwarephilosopher closed 10 years ago

thesoftwarephilosopher commented 10 years ago

App events:

Window events:

Screen events:

thesoftwarephilosopher commented 10 years ago

Regarding app lifetimes, it may be easier to use kEventAppLaunched and kEventAppTerminated than the way Zephyros does this.

thesoftwarephilosopher commented 10 years ago

Changing the milestone for this issue, there's no good reason to have it in 1.0 just yet.

creese commented 10 years ago

With just WindowCreated and WindowClosed, we should be able to create a nice one-workspace clone of http://xmonad.org.

flaub commented 10 years ago

+1

thesoftwarephilosopher commented 10 years ago

The difficulty here is in order to observe window-related events we must first register a permanent observer (AXObserverCreate) for the app (pid_t) whose windows these may be; there's no way to register for a such an event independent of the application it may originate from. This involves a lot of ugly bookkeeping that I'd like to avoid putting into the core of the app if at all possible. But the only alternative solution seems to be asking the user to keep track of all current and future apps and maintain observers for them throughout their lifetimes, which also isn't reasonable.

thesoftwarephilosopher commented 10 years ago

If anyone has an alternative API to point me to, or any other ideas, your input will be greatly appreciated.

thesoftwarephilosopher commented 10 years ago

Solved.

mengelbrecht commented 10 years ago

Is there already an API to use to get notified of launched Applications?

thesoftwarephilosopher commented 10 years ago

@mgee It's coming soon.

mengelbrecht commented 10 years ago

Nice! Looking forward to it :-).

thesoftwarephilosopher commented 10 years ago

This feature depends on #254.

thesoftwarephilosopher commented 10 years ago

I've got a better idea of how to implement this now.

thesoftwarephilosopher commented 10 years ago

Working on this now.

thesoftwarephilosopher commented 10 years ago

Thinking of making this a generic module like listener to reduce code duplication. Then all the events would be listed in tables in their relevant module, like listener.new(application.event.launched, function()...end):start()

thesoftwarephilosopher commented 10 years ago

I need to do this on a night when I have a fresh mind and no distractions. Tonight I had neither. :/

iakshay commented 10 years ago

Would be great, if we can get these events – https://github.com/jigish/slate/wiki/Events

How about some thing like Event.on(application.event.launched, function() end)

Maybe battery.watcher could also be integrated into this module.

muescha commented 10 years ago

add key pressed/key released events

benefit:

thesoftwarephilosopher commented 10 years ago

@muescha That was done in eventtap which is coming in 1.1

muescha commented 10 years ago

i would prefer the @iakshay syntax Event.on over an eventtap naming.

thesoftwarephilosopher commented 10 years ago

@muescha For input events, the eventtap module is pretty much set in stone at this point. This issue is for other events, which need more thought.

muescha commented 10 years ago

but then it looks more consistent if it have always the same syntax and fits your idea for making a generic module for listener (or Event)

thesoftwarephilosopher commented 10 years ago

Moving to mjolnir-io/ext#14.

nathankot commented 10 years ago

this would be the final piece of the puzzle for https://github.com/nathankot/mjolnir.tiling :smile: although can't seem to find mjolnir-io/ext ??

tmandry commented 9 years ago

+1, @sdegutis can you link to the issue?

iakshay commented 9 years ago

+1 for events

szymonkaliski commented 9 years ago

Yeah, I'd love that too, shouldn't we reopen this?

maxrothman commented 9 years ago

@sdegutis :+1: as well, also can't find mjolnir-io/ext.

thesoftwarephilosopher commented 9 years ago

I'm currently working on events.

nathankot commented 9 years ago

@sdegutis thanks for the update :smile:

svalaskevicius commented 9 years ago

awesome! looking forward for event driven tiling WM on osx :) (in fact, the only thing keeping me from using osx is not having xmonad there)

nathankot commented 9 years ago

@svalaskevicius I hope we convert you eventually :stuck_out_tongue:

svalaskevicius commented 9 years ago

@nathankot thanks :) just to check - is the current implementation of tiling plugin working already or is it blocked by this issue.. and is there maybe a screencast of it in action? I've tried looking for it but couldn't find any. (should I have asked this elsewhere?)

nathankot commented 9 years ago

@svalaskevicius yep it works, but doesn't respond to new windows being added (so you'll have to re-tile manually), the tiling project is young so don't think there are videos out in the wild but could do one of my workflow if you want?

svalaskevicius commented 9 years ago

it would be definitely interesting to see! - it's usually one of the first things I look for when I hear of a new tiling WM :)

creese commented 9 years ago

@nathankot The last time I checked, the tiling project did not work for multiple monitors. Has that issue been addressed?

nathankot commented 9 years ago

@creese don't use multiple screens myself but this may have fixed it: https://github.com/nathankot/mjolnir.tiling/issues/9 , if not , please make a new issue at mjolnir.tiling ;)

simichaels commented 9 years ago

Any progress on event handling so far?

thesoftwarephilosopher commented 9 years ago

They're basically finished in the Swift window manager I was writing. Main problem is there's no UI in that one yet.

szymonkaliski commented 9 years ago

Hmmm, but is everything else working? I for one don't need a UI to use it... Is it mjolnir compatible? I'd love to use some modules we already have...

thesoftwarephilosopher commented 9 years ago

@szymonkaliski It's all working, but I haven't finished porting all the functions (it's so tedious). It's probably already Mjolnir-compatible, but if not, it could easily be made to be so. I have two versions: one that uses Lua very similarly to Hammerspoon (a Mjolnir fork), and one that's meant to be one you write in pure Swift (in Xcode), and compile into an app that you can run. Since the work was split in two repos, each repo might have an API function or two that the other doesn't, so I'm not entirely which has what. Anyway, I plan to spend an hour or so today cleaning that up and making both repos presentable, and writing down the current status of each in their own READMEs. There'll likely still be some work needed to port some API functions over from Mjolnir, and if that's the case, I'd love some help.

thesoftwarephilosopher commented 9 years ago

Oh right, I remember what I planned for the Swift-only version: it would be a framework that you could just import, and you'd just make a new Swift app that embeds and links to this framework, and uses it in applicationDidFinishLaunching. That way, everyone could re-contribute to the framework itself, while keeping their "config" (i.e. the program putting the framework to good use) separate.

thesoftwarephilosopher commented 9 years ago

@szymonkaliski turned it into a framework at https://github.com/sdegutis/WindowManager fwiw

cmsj commented 9 years ago

FWIW, I expect that the Hammerspoon modules for app/window/screen events would port over pretty easily. The code is at:

app events: https://github.com/Hammerspoon/hammerspoon/blob/master/extensions/application/watcher.m window events: https://github.com/Hammerspoon/hammerspoon/tree/master/extensions/uielement screen events: https://github.com/Hammerspoon/hammerspoon/blob/master/extensions/screen/watcher.m

(some of this stuff was inherited from Mjolnir's various modules anyway, so it may not all need to be ported over :)

szymonkaliski commented 9 years ago

@sdegutis https://github.com/sdegutis/WindowManager looks very cool, I hope I'll have some time to play with it soon!