From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 3245EBB91 for ; Wed, 26 Jan 2005 10:18:11 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j0Q9IAS7002679 for ; Wed, 26 Jan 2005 10:18:10 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA29402 for ; Wed, 26 Jan 2005 10:18:10 +0100 (MET) Received: from laurie.fmf.uni-lj.si (BSN-77-186-71.dsl.siol.net [193.77.186.71]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j0Q9I3a5032240 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Wed, 26 Jan 2005 10:18:10 +0100 Received: from localhost ([127.0.0.1]) by laurie.fmf.uni-lj.si with esmtp (Exim 4.43) id 1CtjJE-0004Re-8l for caml-list@inria.fr; Wed, 26 Jan 2005 10:17:56 +0100 Message-ID: <41F76043.9070600@andrej.com> Date: Wed, 26 Jan 2005 10:17:55 +0100 From: Andrej Bauer User-Agent: Debian Thunderbird 1.0 (X11/20050116) X-Accept-Language: en-us, en MIME-Version: 1.0 To: caml-list@inria.fr Subject: What the Graphics module is missing X-Enigmail-Version: 0.90.0.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-2 Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 41F76052.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 41F7604B.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; andrej:01 andrej:01 wrote:01 ocaml:01 polling:01 keypresses:01 ocaml:01 multitasking:98 graphics:02 graphics:02 confusing:02 seems:03 module:03 module:03 solved:03 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.0 X-Spam-Level: I recently wrote a simple single-window application in ocaml. For artistic purposes I wanted it to give it a "raw" look (think VT100), so I did want to use an existing library. The Graphics module seemed like a good solution. However, I think the Graphics module is missing a function that empties the event queue. Suppose my program is doing something and while it is doing it, it periodically polls for user interface events (think "cooperative multitasking" from 1980's). In particular, I polled for mouse down and mouse up events. Later on, when the program is not doing anything, it makes sense to have it wait for an event (rather than burn CPU by busy-waiting and polling). BUT, since there is no way to empty the event queue, as far as I can tell, the events that were polled during the first part will still be sitting in the queue. The program will react to them, again, and the effect is that some things may happen twice instead of once, which of course is annoying. (Note that keypresses _can_ be emptied from the queue because there is the Graphics.keypressed function, but really one should be able to empty the whole queue.) If the above description is confusing, imagine the following scenario: in certain cases you want to empty the event queue in order to prevent the user from doing a dangerous thing. For example, if you are going to ask him "are you sure you want to format the hard disk?" then you better empty the queue, lest the user pressed 'y' before he saw the question. This would all be very easily solved if the ocaml people added an "empty_queue" function to the Graphics module. I looked at the source code and it seems it would be easy to do. Pretty please. Or am I missing something obvious? Andrej Bauer