Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!das-news.harvard.edu!news2.near.net!MathWorks.Com!europa.eng.gtefsd.com!howland.reston.ans.net!EU.net!Germany.EU.net!donald!hmm
From: hmm@heeg.de (Hans-Martin Mosner)
Subject: Re: Absolute mouse position? (reformulated)
Message-ID: <CvEoyI.K2q@heeg.de>
Organization: Georg Heeg Objektorientierte Systeme, Dortmund, FRG
References: <KASPER.94Aug29100824@white.iesd.auc.dk> <ABcJjOkiT2@rrg.msk.su> <KASPER.94Aug31080225@white.iesd.auc.dk>
Date: Wed, 31 Aug 1994 15:42:18 GMT
Lines: 36

In article <KASPER.94Aug31080225@white.iesd.auc.dk> kasper@iesd.auc.dk (Kasper Osterbye) writes:
>I am running Smalltalk/Objectworks 4.1 on a Sun sparc, under OpenWindows.
>
>I need to get the mouse in absolute screen coordinates.
You're right that you won't get the coordinates through the evnts, because
the mouse is not over one of the Smalltalk windows.
But there's some trick that you can use to cheat:
Use the #dragShape:... method in Screen to get the global mouse position.
The trick is to let the user drag an invisible shape while any mouse
button is down. If the mouse button is really down and not grabbed by
another window, the system just seems to hang until the user releases
the button. If the mouse button was not down, the method returns with
the current mouse position immediately. Here's a small code fragment:

| point w |
(Delay forSeconds: 2) wait.	"so the user can move outside any window"
point := Screen default
	dragShape: (Mask extent: 1@1)
	offset: 0@0
	gridPhase: 0@0
	gridSpacing: 1@1
	boundedBy: nil
	whileButton: 0		"wait until no button is pressed"
	isDown: true.
"Then open a window at that point to prove that you got the right point"
w := Window openNewIn: (point extent: 100@100) withType: #popUp.
(Delay forSeconds: 1) wait.	"let the window be seen"
w close.			"don't litter the screen with garbage windows"


Hans-Martin
-- 
+--- Hans-Martin Mosner ---------------- <hmm@heeg.de> ---+
| These opinions are entirely ficticious.  Any similarity |
| to real opinions is purely coincidental and unintended. |
+---------------------------------------------------------+
