Xref: utzoo comp.windows.news:2568 comp.windows.open-look:1170 Newsgroups: comp.windows.news,comp.windows.open-look Path: utzoo!utgpu!watserv1!watcgl!mud.waterloo.edu!bmacinty From: bmacinty@mud.waterloo.edu (Blair MacIntyre) Subject: Re: Getting focus notification in TNT2.0 Beta Message-ID: <1991Apr10.001945.9456@watcgl.waterloo.edu> Sender: news@watcgl.waterloo.edu (USENET News System) Organization: Computer Graphics Laboratory, University of Waterloo, Ontario, Canada References: <1991Apr9.062834.19405@watcgl.waterloo.edu> Date: Wed, 10 Apr 1991 00:19:45 GMT Lines: 72 In article <1991Apr9.062834.19405@watcgl.waterloo.edu>, bmacinty@mud.waterloo.edu (Me) wrote: > I'm writing a window class (subclass of ClassBaseWindow) and I want > to be notified when the window gets/loses the focus. > > I've been trying various things for most of the evening (and night) > and cannot seem to get it to work. I got a number of replies, the first of which came mear hours after I posted my message. From: fritz@triguy.East.Sun.COM (Steve Fritzinger - SE Sun Washington) ------------------ Try using /Keyable? and the Key methods in ClassCanvas. Take a look at page 55 in the Beta TNT manual. Here's a code fragment that works for me. /FooCanvas ClassCanvas [] classbegin /Keyable? true def % Called whenever canvas gets focus. Event name is either % /AcceptFocus or /RestoreFocus. /KeyStart { % event => [/StandardKey] true pop [/StandardKey] true } def % Called for each key stroke. Event name = key pressed. /StandardKey { % event => - % What ever you want to do with the event. } def % Called when canvas loses focus. /KeyStop { % event => - pop } def classend def ------------------ He also replied to my subsequent mail with this piece of advice, which I'm passing on because I think it may be helpful to others ... From: fritz@triguy.East.Sun.COM (Steve Fritzinger - SE Sun Washington) ------------------ It takes a little playing around to get used to the way TNT does things. Basically, TNT works at a much higher and more abstract level then X toolkits usually do. This is a perfect example. You really don't care about TrackCrossing events, or any of the other underlaying implementation stuff, you just want something to happen when you get or lose focus. So when you define /KeyStart you're telling the server "Do this when I get focus. Take care of creating and expressing any events you need to, I don't care. Don't bother me with implementation details." So TNT let's you say what should be done, without worrying about how to know when to do it. No more event masks, or interests lists, just application specific code. By the way, TNT is out of beta and in now available. It fixes several obvious bugs and has some performance improvements. Also if you haven't yet, you should dissect the rap demo. That 700 lines of code is a gold mine of great ideas. ------------------ -- Blair MacIntyre, Computer Graphics Lab Dept. of Computer Science, University of Waterloo, Waterloo, ON, Canada, N2L3G1 {bmacintyre@{watcgl|violet|watdragon}}.{waterloo.edu|uwaterloo.ca}