Do we need a mouse trap?

Peter Achten peter88@cs.kun.nl
Thu, 04 Mar 1999 11:12:59 +0100


Hello Adrian,

At 10:26 AM 3/3/99 +0000, you wrote:
>I seem to be having a few problems getting mouse handling to work
>using ObjectIO 1.0.1 for PowerPC/MacOS. I suspect there might be
>a bug in ObjectIO (or else I just don't understand how to use it
>properly).
>
>The problem seems to be that I get multiple MouseMove and
>MouseDrag up calls, even if the mouse state hasn't changed.
>Is this supposed to happen?
>
>Anyway, for my purposes I only want to know if the mouse state has
>changed, so I implemented the code sequences at the bottom of this
>message, which appear to fix the problem for MouseMove, but not
>MouseDrag. The only explanation I can think of is that MouseDrags
>don't get scrutinised by the mouse filter.
>
>What makes me suspicious about the bug hypothesis is that this is
>such a basic utility I find it hard to believe nobody has noticed this
>before, unless I'm the only person using ObjectIO 1.0.1 on a Mac
>(which I doubt). How can anybody get their programs to work if this
>really is a bug in ObjectIO?  
>
>Has anybody else encountered this problem?
>Does anybody know what I'm doing wrong or have a fix?

I have looked at your program and compiled it myself with the ObjectIO 1.0.1 library. In the program code you state that the window attributes should contain the line:

>// Put this in the initial list of WindowAttributes
>WindowMouse (\ms -> True) Able (mouse_trap user_mousefunc windowId)

What you didn't write is that it is *vital* to also add the following line in the same window attribute list:
WindowId windowId

The reason is that the function setWindowMouseStateFilter requires the Id of the window which mouse filter should be altered. I suspect you forgot this, because if you do add it, everything works fine. 

>Worse still, the multitude of MouseDrags pretty soon causes my
>test program to crash with a Heap Full error, which indicates a
>severe space leak somewhere. I've noticed that the Life Game example
>also crashes if you drag for too long. This could be another bug in
>ObjectIO, or perhaps my program is building lots of unreduced thunks?
It is actually the latter: when dragging the mouse in the Life Game example, the list of cells is lazily incremented. Your program runs nicely, using a heap of less than 4K after each garbage collection.

>If the latter explanation is correct I could probably fix the leak
>with appropriate strictness annotations. I haven't tried yet because
>I'm confused on a few points regarding the effect of strictness
>annotations in Clean and I don't want my programs to be any stricter
>than necessary (but that's a subject for another message).

Hope this will help you,

greetings,

Peter