Re: FVWM: Pointer Focus (was Re: "active focus" applications)

From: Barry A. Warsaw <bwarsaw_at_anthem.cnri.reston.va.us>
Date: Sat, 26 Oct 1996 19:12:36 -0400

>>>>> "SR" == Scott Raney <raney_at_metacard.com> writes:

    SR> As best I remember (or can determine from the Tk
    SR> documentation) the focus comand only works with child windows
    SR> within a toplevel window: if your application opens a dialog
    SR> box on a pointer focus system, you *must* move the mouse into
    SR> the dialog before you can star using it.

You must be reading some old Tk documentation. This is certainly not
the case any more. FTR: I'm using Tk 4.1 and Python 1.4 (although
that shouldn't matter).

    SR> I think this is wrong, at least as I understand pointer focus.
    SR> Maybe you're thinking of sloppy focus or something. Pointer
    SR> focus is where the window with the mouse cursor in it has the
    SR> keyboard focus. There are no exceptions to this rule, and
    SR> warping the cursor is the only way an application can ensure
    SR> that one of its windows gets the focus.

This is just not true. An application can manage focus internally
among its top-level windows, essentially redirecting focus to any of
their top-level windows (and of course to any widget within those
windows), as long as the pointer is in any one of the application's
windows. I've appended a very simple Python/Tkinter application to
prove it.

Save this code in a file called Focus.py, and run it by typing `python
Focus.py' in your shell. It will pop up a window with two buttons in
it. Of course, make sure your FVWM is set up to do
focus-follows-mouse, and put the pointer into this window. Now, hit
TAB until the `Dialog...' button is highlighted, then hit space. A
second top-level window will pop up, and focus will be directed into
it. Notice that FVWM does the Right Thing in that the dialog's border
is highlighted. Notice further that the pointer has never left the
first window and no grab is in effect. TAB until the `Done' button is
highlighted, and hit space. The dialog will withdraw and the first
window will regain focus.

    SR> Maybe within a dialog window this is true, but since Tk
    SR> doesn't support modal dialogs, it's stuck recommending "grabs"
    SR> as a standard UI technique (see Chapter 24 of Ousterhout's Tcl
    SR> book).

You should check out the latest release of Tk. I haven't got the
manpages here at home, but I don't think this is true with Tk 4.1.

-Barry

-------------------- snip snip --------------------Focus.py
import sys
from Tkinter import *

class Dialog:
    def __init__(self, master, num):
        self.__master = master
        self.__win = Toplevel(master)
        label = Label(self.__win, text=`num`)
        label.pack()
        btn = Button(self.__win, text='Done', command=self.done)
        btn.pack()
        self.__win.focus_set()

    def done(self):
        # must transfer focus before destroying the widget
        self.__master.focus_set()
        self.__win.destroy()

class App:
    __num = 1

    def __init__(self):
        self.__master = Tk()
        btn = Button(self.__master, text='Dialog...', command=self.popup)
        btn.pack()
        quit = Button(self.__master, text='Quit', command=self.quit)
        quit.pack()

    def go(self):
        self.__master.mainloop()

    def quit(self):
        sys.exit(0)

    def popup(self):
        d = Dialog(self.__master, self.__num)
        self.__num = self.__num + 1

if __name__ == '__main__':
    app = App()
    app.go()
--
Visit the official FVWM web page at <URL:http://www.hpc.uh.edu/fvwm/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to majordomo_at_hpc.uh.edu.
To report problems, send mail to fvwm-owner_at_hpc.uh.edu.
Received on Sat Oct 26 1996 - 18:19:07 BST

This archive was generated by hypermail 2.3.0 : Mon Aug 29 2016 - 19:37:59 BST