[squeak-dev] Algernon modification to register as an eventListener into HandMorph

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Algernon modification to register as an eventListener into HandMorph

Balázs Kósi
Hi,

Algernon uses Hernan Tylim's MultipleFocusHolder code to capture
keyboard events [1].
I made a small modification [2] to use the event listener facilities
in HandMorph instead.
But I had to change HandMorph >> sendListenEvent:to: to get it work [3].
In my version we dispatch the original event to the listeners, not
copies of it, so we can set the wasHandled flag.
This may cause problems in the other users [4], and may against its design.
What do you think?

Thanks, Balázs

[1] MultipleFocusHolder code overrides some methods changed after its
release; and it's released under LGPL, afaik.
[2] Saved it into the Algernon repository:
http://www.squeaksource.com/Algernon.html as Algernon-kb.13.mcz
[3] The change from ar's code:

sendListenEvent: anEvent to: listenerGroup
        "Send the event to the given group of listeners"
        listenerGroup ifNil:[^self].
        listenerGroup do:[:listener|
                listener ifNotNil:[listener handleListenEvent: anEvent copy]].

to:

sendListenEvent: anEvent to: listenerGroup
        "Send the event to the given group of listeners"
       
        listenerGroup ifNil: [ ^self ].
        listenerGroup do: [ :listener |
                listener ifNotNil: [
                        listener handleListenEvent: anEvent ] ]

[4] In my image they are EventRecorderMorph and RemoteHandMorph, and
they both store the last event they handled.
These can be fixed pretty easily, imho.

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Algernon modification to register as an eventListener into HandMorph

Igor Stasenko
2008/5/18 Balázs Kósi <[hidden email]>:

> Hi,
>
> Algernon uses Hernan Tylim's MultipleFocusHolder code to capture
> keyboard events [1].
> I made a small modification [2] to use the event listener facilities
> in HandMorph instead.
> But I had to change HandMorph >> sendListenEvent:to: to get it work [3].
> In my version we dispatch the original event to the listeners, not
> copies of it, so we can set the wasHandled flag.
> This may cause problems in the other users [4], and may against its design.
> What do you think?
>
> Thanks, Balázs
>
> [1] MultipleFocusHolder code overrides some methods changed after its
> release; and it's released under LGPL, afaik.
> [2] Saved it into the Algernon repository:
> http://www.squeaksource.com/Algernon.html as Algernon-kb.13.mcz
> [3] The change from ar's code:
>
> sendListenEvent: anEvent to: listenerGroup
>        "Send the event to the given group of listeners"
>        listenerGroup ifNil:[^self].
>        listenerGroup do:[:listener|
>                listener ifNotNil:[listener handleListenEvent: anEvent copy]].
>
> to:
>
> sendListenEvent: anEvent to: listenerGroup
>        "Send the event to the given group of listeners"
>
>        listenerGroup ifNil: [ ^self ].
>        listenerGroup do: [ :listener |
>                listener ifNotNil: [
>                        listener handleListenEvent: anEvent ] ]
>
> [4] In my image they are EventRecorderMorph and RemoteHandMorph, and
> they both store the last event they handled.
> These can be fixed pretty easily, imho.
>
Well, i think its more logical to do copy of events in
EventRecorderMorph  and RemoteHandMorph
instead of HandMorph class. Really why such special event handlers
like above, which collecting events, should rely on different class to
receive a copy of events, instead of making copy themselves?

>



--
Best regards,
Igor Stasenko AKA sig.


Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Re: Algernon modification to register as an eventListener into HandMorph

Andreas.Raab
Igor Stasenko wrote:
> Well, i think its more logical to do copy of events in
> EventRecorderMorph  and RemoteHandMorph
> instead of HandMorph class. Really why such special event handlers
> like above, which collecting events, should rely on different class to
> receive a copy of events, instead of making copy themselves?

Robustness. I didn't even know that EventRecorderMorph and
RemoteHandMorph kept the last events and I have no idea whether that can
cause problems or not. Creating copies for the listeners (which are
different from filters btw; listeners are assumed to be passive and
consequently copying the event only serves the purpose to decouple the
listener processing from the internal processing later) makes the whole
mechanism more robust at very little cost. New clients simply cannot
break later processing by accidentally modifying the event. You have to
understand that this is a *very* low-level hook into the system - making
an error in your code *will* completely screw the environment so a
little caution is in order I think.

Cheers,
   - Andreas

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: Algernon modification to register as an eventListener into HandMorph

Balázs Kósi
Hi,

> (which are different from filters btw; listeners are assumed to be passive
> and consequently copying the event only serves the purpose
> to decouple the listener processing from the internal processing later)
Does Andreas refer here to something that is implemented, or just that
I'm abusing the concept Listener?
If the latter, what do you think about creating an explicit group for
filters, using a separate
dispatcher method? [1]
Or is there a much better place for intercepting events?

Thanks, Balázs

[1] E.g create eventFilters ivar and accessors analog to
eventListeners ivar and accessors,
and #sendFilterEvent:to method analog to #sendListenEvent:to.

Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Re: Algernon modification to register as an eventListener into HandMorph

Andreas.Raab
Balázs Kósi wrote:
> Does Andreas refer here to something that is implemented, or just that
> I'm abusing the concept Listener?

All I'm saying is that when I wrote this I thought about the use case of
passive observation, not of the use case of filtering. Whether that's an
"abuse" or an "extension" of what's currently there is open for debate.

Cheers,
   - Andreas

> If the latter, what do you think about creating an explicit group for
> filters, using a separate
> dispatcher method? [1]
> Or is there a much better place for intercepting events?
>
> Thanks, Balázs
>
> [1] E.g create eventFilters ivar and accessors analog to
> eventListeners ivar and accessors,
> and #sendFilterEvent:to method analog to #sendListenEvent:to.
>
>


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: Algernon modification to register as an eventListener into HandMorph

Balázs Kósi
I've made Algernon [1] to explicitly register as a filter.
This solution still overrides a HandMorph method [2].
For now, this is ok for my purposes, we will see if Algernon
maintainers may pick it up.

Thanks for all your help!

Cheers, Balázs

[1] http://www.squeaksource.com/Algernon/Algernon-kb.15.mcz
[2] namely #handleEvent:
It just adds a line after notifiying listeners:

        self sendFilterEvent: evt to: self eventFilters.