Re: [Gtk2hs-users] DrawWindow in CVS HEAD now contains drawWindowGetPointer

On Tue, Feb 22, 2005 at 10:23:27AM +0000, Axel Simon wrote:
> On Mon, 2005-02-21 at 17:05 -0800, John Velman wrote:
> > I've tinkered a bit with this, but onMotionNotify wants a DrawingArea, and
> > drawWindowGetPointer wants a DrawWindow, and as far as I can tell, neither
> > is an instance of the other. It's not at all clear to me how
> > the Just branch of drawWindowGetPointer ever gets called.
>
> Ok, I admit I haven't quite digested your message yet. But this
> paragraph caught my attention: DrawingArea contains a DrawWindow (like
> nearly every widget) which you can get by calling
> drawingAreaGetDrawWindow.
>
> I'll look through your message later,
> Axel.
>
Yes. But now looking again at GTK+ scribble and the behavior I'm seeing,
it seems to me that the DrawingArea should be the "target" of xxGetPointer,
rather than the DrawWindow. I admit I'm confused!
Thanks,
John Velman
>
>
>
> -------------------------------------------------------
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT Products from real users.
> Discover which products truly live up to the hype. Start reading now.
> http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
> _______________________________________________
> Gtk2hs-users mailing list
> Gtk2hs-users@...
> https://lists.sourceforge.net/lists/listinfo/gtk2hs-users
>
>

On Thu, Feb 17, 2005 at 12:15:22AM +0000, Axel Simon wrote:
> John,
>
> I added the function you need to the CVS HEAD. If you're willing to use
> cvs, then I hope you're all set.
>
> Please let us know if there are any problems.
>
> Axel.
>
Axel,
Thanks! I grabbed DrawWindow from CVS, put it in place of the previous one
in my source tree, and compiled successfully.
My application runs, and drawWindowGetPointer is invoked. I think my
remaining problems are my own, but if I can't figure out what I'm doing
wrong I'll call for help!
Best,
John Velman

Axel,
As I said previously, I have compiled and installed DrawWindow from CVS.
I have a program that seems to do what I want with mouse positions (as far
as it goes, anyway): It returns exactly one mouse position after it
finishes computations associated with the previous mouse position. But
I've done some seemingly strange things to get it to work this way.
Here are some 'facts?' based on experiment:
If I set the onMotionNotify hint to False in the widget setup code, the
handler gets called humungous numbers of times whenever the mouse quivers.
This is expected, of course.
When I set the hint for onMotionNotify to True in the widget setup code,
and register no other callbacks for mouse motion, my handler _never_ gets
called. This is unexpected, and isn't in accord with my reading of the
GTK+ tutorial "Scribble" program example.
After a lot of fooling around I conclude that hint has to be false at least
once for the onMotionNotify handler to be called at all. The only way I
see of changing the value of hint is by using either onMotionNotify, or
afterMotionNotify.
So here is my incredibly clever solution:
I set hint to True when setting up my handler for onMotionNotify. This
handler returns False.
I then set up a handler for afterMotionNotify, and call it with the hint
set to False, thus:
onMotionNotify canvas True (handleMotion canvas)
afterMotionNotify canvas False (handleAfterMotion canvas)
"handleAfterMotion" doesn't do anything except to return True.
"handleMotion" does the following:
handleMotion :: DrawingArea -> Event -> IO Bool
handleMotion canvas event = do
putStrLn ("Motion notify: sent =" ++ show(sent event))
putStrLn (" time =" ++ show(time event))
putStrLn (" x =" ++ show(x event))
putStrLn (" y =" ++ show(y event))
putStrLn (" xroot =" ++ show(xRoot event))
putStrLn (" yroot =" ++ show(yRoot event))
putStrLn (" modif =" ++ show(modif event))
putStrLn (" isHint =" ++ show(isHint event))
dw <- drawingAreaGetDrawWindow canvas
getBusyFor 1
mousepos <- drawWindowGetPointer dw
handleMousePos mousepos
return False
Here,
getBusyFor t
is a quick and clumsy function that simply tests to see
if the time interval t, in seconds, has elapsed.
handleMousePos mousepos is:
handleMousePos Nothing = do
putStrLn "drawWindowGetPointer yield: Nothing "
return ()
handleMousePos (Just (same, x, y, modif)) = do
putStrLn (" drawWindowGetPoint yield" )
putStrLn (" x =" ++ show x )
putStrLn (" y =" ++ show y )
putStrLn (" modif =" ++ show modif)
return ()
When I run this program, it works like this:
handleMotion is called "like clockwork" :-) every second when the mouse
moves anywhere in 'canvas'. There is no backlog of calls to handleMotion.
(on the other hand, if I comment out afterMotionNotify, set the
onMotionNotify hint to False, and set the handleMotion return value to
True, I get a humungous backlog of calls after the mouse motion is over, as
expected.)
The "Nothing" branch of handleMousePos is also called every second.
The "Just" branch of handleMousePos never gets called.
This, together with the comments for drawWindowGetPointerin the DrawWindow
source seem to imply that drawWindowGetPointer thinks the mouse is residing
someplace other than the dw passed to it, derived from the drawing area.
I've tinkered a bit with this, but onMotionNotify wants a DrawingArea, and
drawWindowGetPointer wants a DrawWindow, and as far as I can tell, neither
is an instance of the other. It's not at all clear to me how
the Just branch of drawWindowGetPointer ever gets called.
I hope this is clear! There should be a simpler way to get the desired
result, but I sure can't see it.
Thanks,
John Velman

On Mon, 2005-02-21 at 17:05 -0800, John Velman wrote:
> I've tinkered a bit with this, but onMotionNotify wants a DrawingArea, and
> drawWindowGetPointer wants a DrawWindow, and as far as I can tell, neither
> is an instance of the other. It's not at all clear to me how
> the Just branch of drawWindowGetPointer ever gets called.
Ok, I admit I haven't quite digested your message yet. But this
paragraph caught my attention: DrawingArea contains a DrawWindow (like
nearly every widget) which you can get by calling
drawingAreaGetDrawWindow.
I'll look through your message later,
Axel.

On Tue, Feb 22, 2005 at 10:23:27AM +0000, Axel Simon wrote:
> On Mon, 2005-02-21 at 17:05 -0800, John Velman wrote:
> > I've tinkered a bit with this, but onMotionNotify wants a DrawingArea, and
> > drawWindowGetPointer wants a DrawWindow, and as far as I can tell, neither
> > is an instance of the other. It's not at all clear to me how
> > the Just branch of drawWindowGetPointer ever gets called.
>
> Ok, I admit I haven't quite digested your message yet. But this
> paragraph caught my attention: DrawingArea contains a DrawWindow (like
> nearly every widget) which you can get by calling
> drawingAreaGetDrawWindow.
>
> I'll look through your message later,
> Axel.
>
Yes. But now looking again at GTK+ scribble and the behavior I'm seeing,
it seems to me that the DrawingArea should be the "target" of xxGetPointer,
rather than the DrawWindow. I admit I'm confused!
Thanks,
John Velman
>
>
>
> -------------------------------------------------------
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT Products from real users.
> Discover which products truly live up to the hype. Start reading now.
> http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
> _______________________________________________
> Gtk2hs-users mailing list
> Gtk2hs-users@...
> https://lists.sourceforge.net/lists/listinfo/gtk2hs-users
>
>