simulating Mousewheel

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

simulating Mousewheel

Ch Lamprecht
Running Pharo on an IBM Thinkpad with a trackpoint input device, I was a bit
disappointed, that the autoscroll feature does not work in Pharo (pressing
Button-2 and moving the mouse pointer should scroll the window below the mouse
pointer).
I took it as an exercise and the attached code does what I want, but it does not
feel right (like not at the the right 'level'): Is there a place in the Morph
hierarchy where such behavior changes could be plugged in?
Or did I overlook a preference setting ;) ?

Cheers, Chris



Object subclass: #InputEventFetcher
        instanceVariableNames: 'eventHandlers fetcherProcess inputSemaphore mousewheel ycoord'
        classVariableNames: 'Default'
        poolDictionaries: 'EventSensorConstants'
        category: 'Kernel-Processes'

InputEventFetcher>> signalEvent: eventBuffer
        "Signal the event buffer to all registered event handlers.
        Handlers need make sure to copy the buffer or extract the data otherwise, as the buffer will be reused."

        self simulateMousewheel: eventBuffer.

        self eventHandlers do: [:handler |
                handler handleEvent: eventBuffer]

InputEventFetcher>> simulateMousewheel: eventBuffer
        "MOusewheel up:   2 time 30 0 2 0 0 1
         MOusewheel down: 2 time 31 0 2 0 0 1
        "

        | ycur keysym up down |
        keysym := nil.
        up := 30.
        down := 31.
        (eventBuffer at: 1) = 1
                ifTrue:
                        [ "mouse event"
                        ((eventBuffer at: 5) anyMask: 1)
                                ifTrue:
                                        [ "yellow button down"
                                        mousewheel
                                                ifFalse:
                                                        [ "first time: do nothing"
                                                        mousewheel := true.
                                                        ycoord := eventBuffer at: 4 ]
                                                ifTrue:
                                                        [ "handle movement"
                                                        ycur := eventBuffer at: 4.
                                                        ycur - ycoord > 1
                                                                ifTrue:
                                                                        [ keysym := down.
                                                                        ycoord := ycur ].
                                                        ycur - ycoord < -1
                                                                ifTrue:
                                                                        [ keysym := up.
                                                                        ycoord := ycur ].
                                                        keysym isNil
                                                                ifTrue:
                                                                        [ "make it a Null event"
                                                                        eventBuffer at: 1 put: 0 ]
                                                                ifFalse:
                                                                        [ eventBuffer at: 1 put: 2.
                                                                        eventBuffer at: 3 put: keysym.
                                                                        eventBuffer
                                                                                replaceFrom: 4
                                                                                to: 8
                                                                                with: #(0 2 0 0 1) ] ] ]
                                ifFalse:
                                        [ "yellowbutton up"
                                        mousewheel := false ] ].
        ^ eventBuffer
_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: simulating Mousewheel

Stéphane Ducasse
Thanks chris.
I never got the time to sit and read all the changes mike did for the inputEvent logic
so my knowledge is bad in that area.
Now I was wondering when your mouse wheel turns to get button down events?

in any case this is great to share that with us because once we will have fixed the obvious
and ugly we will have to fix the non-obvious and ugly to finally get started building beauty :)


BTW
                "mouse event"
                ((eventBuffer at: 5) anyMask: 1)

                do you know if it would be possible to have
                eventBuffer isMouseEvent instead of the above?
       
Stef


> Running Pharo on an IBM Thinkpad with a trackpoint input device, I was a bit
> disappointed, that the autoscroll feature does not work in Pharo (pressing
> Button-2 and moving the mouse pointer should scroll the window below the mouse
> pointer).
> I took it as an exercise and the attached code does what I want, but it does not
> feel right (like not at the the right 'level'): Is there a place in the Morph hierarchy where such behavior changes could be plugged in?
> Or did I overlook a preference setting ;) ?

:)


>
> Cheers, Chris
>
>
> Object subclass: #InputEventFetcher
> instanceVariableNames: 'eventHandlers fetcherProcess inputSemaphore mousewheel ycoord'
> classVariableNames: 'Default'
> poolDictionaries: 'EventSensorConstants'
> category: 'Kernel-Processes'
>
> InputEventFetcher>> signalEvent: eventBuffer
> "Signal the event buffer to all registered event handlers.
> Handlers need make sure to copy the buffer or extract the data otherwise, as the buffer will be reused."
>
> self simulateMousewheel: eventBuffer.
>
> self eventHandlers do: [:handler |
> handler handleEvent: eventBuffer]
>
> InputEventFetcher>> simulateMousewheel: eventBuffer
> "MOusewheel up:   2 time 30 0 2 0 0 1
> MOusewheel down: 2 time 31 0 2 0 0 1
> "
>
> | ycur keysym up down |
> keysym := nil.
> up := 30.
> down := 31.
> (eventBuffer at: 1) = 1
> ifTrue:
> [ "mouse event"
> ((eventBuffer at: 5) anyMask: 1)
> ifTrue:
> [ "yellow button down"
> mousewheel
> ifFalse:
> [ "first time: do nothing"
> mousewheel := true.
> ycoord := eventBuffer at: 4 ]
> ifTrue:
> [ "handle movement"
> ycur := eventBuffer at: 4.
> ycur - ycoord > 1
> ifTrue:
> [ keysym := down.
> ycoord := ycur ].
> ycur - ycoord < -1
> ifTrue:
> [ keysym := up.
> ycoord := ycur ].
> keysym isNil
> ifTrue:
> [ "make it a Null event"
> eventBuffer at: 1 put: 0 ]
> ifFalse:
> [ eventBuffer at: 1 put: 2.
> eventBuffer at: 3 put: keysym.
> eventBuffer
> replaceFrom: 4
> to: 8
> with: #(0 2 0 0 1) ] ] ]
> ifFalse:
> [ "yellowbutton up"
> mousewheel := false ] ].
> ^ eventBuffer_______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: simulating Mousewheel

Ch Lamprecht
Stéphane Ducasse schrieb:
> Thanks chris. I never got the time to sit and read all the changes mike did
> for the inputEvent logic so my knowledge is bad in that area. Now I was
> wondering when your mouse wheel turns to get button down events?

Hello,

See comment on MouseWheelEvent class - thats why I thought mapping to
(ctrl+up/down arrow) is the pharo way to do it. Also that's what I can see
coming in (examining InputEventFetcher) on WinXP when I use a mousewheel.
I think MouseWheel is not cross platform compatible. Linux/X11 uses Buttons 4-5
instead.



>
> BTW "mouse event" ((eventBuffer at: 5) anyMask: 1)
>
> do you know if it would be possible to have eventBuffer isMouseEvent instead
> of the above?



unfortunately the object assigned to eventBuffer is an ordinary Array containing
'raw' event information. ( Described in comment on InputEventFetcher ). That
is why I thought, there could be a place to make such things configurable on a
higher level (dealing with event objects rather than raw data).
Btw. I got confused with the Button colours: Comments should refer to blue
Button not yellow.

Thanks, Chris

>  Stef
>
>
>> Running Pharo on an IBM Thinkpad with a trackpoint input device, I was a
>> bit disappointed, that the autoscroll feature does not work in Pharo
>> (pressing Button-2 and moving the mouse pointer should scroll the window
>> below the mouse pointer). I took it as an exercise and the attached code
>> does what I want, but it does not feel right (like not at the the right
>> 'level'): Is there a place in the Morph hierarchy where such behavior
>> changes could be plugged in? Or did I overlook a preference setting ;) ?
>
> :)
>
>
>> Cheers, Chris
>>
>>
>> Object subclass: #InputEventFetcher instanceVariableNames: 'eventHandlers
>> fetcherProcess inputSemaphore mousewheel ycoord' classVariableNames:
>> 'Default' poolDictionaries: 'EventSensorConstants' category:
>> 'Kernel-Processes'
>>
>> InputEventFetcher>> signalEvent: eventBuffer "Signal the event buffer to
>> all registered event handlers. Handlers need make sure to copy the buffer
>> or extract the data otherwise, as the buffer will be reused."
>>
>> self simulateMousewheel: eventBuffer.
>>
>> self eventHandlers do: [:handler | handler handleEvent: eventBuffer]
>>
>> InputEventFetcher>> simulateMousewheel: eventBuffer "MOusewheel up:   2
>> time 30 0 2 0 0 1 MOusewheel down: 2 time 31 0 2 0 0 1 "
>>
>> | ycur keysym up down | keysym := nil. up := 30. down := 31. (eventBuffer
>> at: 1) = 1 ifTrue: [ "mouse event" ((eventBuffer at: 5) anyMask: 1) ifTrue:
>>  [ "yellow button down" mousewheel ifFalse: [ "first time: do nothing"
>> mousewheel := true. ycoord := eventBuffer at: 4 ] ifTrue: [ "handle
>> movement" ycur := eventBuffer at: 4. ycur - ycoord > 1 ifTrue: [ keysym :=
>> down. ycoord := ycur ]. ycur - ycoord < -1 ifTrue: [ keysym := up. ycoord
>> := ycur ]. keysym isNil ifTrue: [ "make it a Null event" eventBuffer at: 1
>> put: 0 ] ifFalse: [ eventBuffer at: 1 put: 2. eventBuffer at: 3 put:
>> keysym. eventBuffer replaceFrom: 4 to: 8 with: #(0 2 0 0 1) ] ] ] ifFalse:
>> [ "yellowbutton up" mousewheel := false ] ]. ^
>> eventBuffer_______________________________________________ Pharo-project
>> mailing list [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
>
> _______________________________________________ Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: simulating Mousewheel

Stéphane Ducasse
Thanks
We should definitively invest in this part of the infrastructure.
I wanted to know on your machine the mouse wheel does not work
because on mac in the latest version I can use it.

Stef

On Feb 20, 2010, at 11:55 AM, Ch Lamprecht wrote:

> Stéphane Ducasse schrieb:
>> Thanks chris. I never got the time to sit and read all the changes mike did
>> for the inputEvent logic so my knowledge is bad in that area. Now I was
>> wondering when your mouse wheel turns to get button down events?
>
> Hello,
>
> See comment on MouseWheelEvent class - thats why I thought mapping to
> (ctrl+up/down arrow) is the pharo way to do it. Also that's what I can see
> coming in (examining InputEventFetcher) on WinXP when I use a mousewheel.
> I think MouseWheel is not cross platform compatible. Linux/X11 uses Buttons 4-5
> instead.
>
>
>
>>
>> BTW "mouse event" ((eventBuffer at: 5) anyMask: 1)
>>
>> do you know if it would be possible to have eventBuffer isMouseEvent instead
>> of the above?
>
>
>
> unfortunately the object assigned to eventBuffer is an ordinary Array containing
> 'raw' event information. ( Described in comment on InputEventFetcher ). That
> is why I thought, there could be a place to make such things configurable on a
> higher level (dealing with event objects rather than raw data).
> Btw. I got confused with the Button colours: Comments should refer to blue
> Button not yellow.
>
> Thanks, Chris
>
>> Stef
>>
>>
>>> Running Pharo on an IBM Thinkpad with a trackpoint input device, I was a
>>> bit disappointed, that the autoscroll feature does not work in Pharo
>>> (pressing Button-2 and moving the mouse pointer should scroll the window
>>> below the mouse pointer). I took it as an exercise and the attached code
>>> does what I want, but it does not feel right (like not at the the right
>>> 'level'): Is there a place in the Morph hierarchy where such behavior
>>> changes could be plugged in? Or did I overlook a preference setting ;) ?
>>
>> :)
>>
>>
>>> Cheers, Chris
>>>
>>>
>>> Object subclass: #InputEventFetcher instanceVariableNames: 'eventHandlers
>>> fetcherProcess inputSemaphore mousewheel ycoord' classVariableNames:
>>> 'Default' poolDictionaries: 'EventSensorConstants' category:
>>> 'Kernel-Processes'
>>>
>>> InputEventFetcher>> signalEvent: eventBuffer "Signal the event buffer to
>>> all registered event handlers. Handlers need make sure to copy the buffer
>>> or extract the data otherwise, as the buffer will be reused."
>>>
>>> self simulateMousewheel: eventBuffer.
>>>
>>> self eventHandlers do: [:handler | handler handleEvent: eventBuffer]
>>>
>>> InputEventFetcher>> simulateMousewheel: eventBuffer "MOusewheel up:   2
>>> time 30 0 2 0 0 1 MOusewheel down: 2 time 31 0 2 0 0 1 "
>>>
>>> | ycur keysym up down | keysym := nil. up := 30. down := 31. (eventBuffer
>>> at: 1) = 1 ifTrue: [ "mouse event" ((eventBuffer at: 5) anyMask: 1) ifTrue:
>>> [ "yellow button down" mousewheel ifFalse: [ "first time: do nothing"
>>> mousewheel := true. ycoord := eventBuffer at: 4 ] ifTrue: [ "handle
>>> movement" ycur := eventBuffer at: 4. ycur - ycoord > 1 ifTrue: [ keysym :=
>>> down. ycoord := ycur ]. ycur - ycoord < -1 ifTrue: [ keysym := up. ycoord
>>> := ycur ]. keysym isNil ifTrue: [ "make it a Null event" eventBuffer at: 1
>>> put: 0 ] ifFalse: [ eventBuffer at: 1 put: 2. eventBuffer at: 3 put:
>>> keysym. eventBuffer replaceFrom: 4 to: 8 with: #(0 2 0 0 1) ] ] ] ifFalse:
>>> [ "yellowbutton up" mousewheel := false ] ]. ^
>>> eventBuffer_______________________________________________ Pharo-project
>>> mailing list [hidden email]
>>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>
>>
>> _______________________________________________ Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: simulating Mousewheel

Ch Lamprecht
Stéphane Ducasse schrieb:
> Thanks
> We should definitively invest in this part of the infrastructure.
> I wanted to know on your machine the mouse wheel does not work
> because on mac in the latest version I can use it.
>
> Stef
>

Oh,

sorry, I did not explain my problem clearly: I am working on a laptop with no
mousewheel available.
I trap Button-2 drag events and transform them to (ctrl+up/down arrow) events,
which is what Pharo processes as mousewheel.

Scrolling by Button-2 drag is what applications like Acrobat reader or Firefox
do as well. And Thinkpad Laptops offer a system wide setting to do this with all
the scrollable Windows. Unfortunately they do it on a system level without
sending events to the application, so it does not work with Morphic.

Cheers, Chris

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project