Tk Source Code

View Ticket
Login
Ticket UUID: bad3050fe02b8a09168cdbee3b6a0707df287fdc
Title: Doc "wm protocol . WM_DELETE_WINDOW": description suggests, that predefined handler exists.
Type: Bug Version: 8.6.12
Submitter: oehhar Created on: 2021-11-30 13:28:53
Subsystem: 99. Other Assigned To: marc_culler
Priority: 5 Medium Severity: Cosmetic
Status: Closed Last Modified: 2021-12-06 14:29:06
Resolution: Fixed Closed By: oehhar
    Closed on: 2021-12-06 14:29:06
Description:

The documentation of "wm protocol" states:

Tk always defines a protocol handler for WM_DELETE_WINDOW, even if you have not asked for one with *wm protocol*. If a WM_DELETE_WINDOW message arrives when you have not defined a handler, then Tk handles the message by destroying the window for which it was received.

---

Reading this description, I understand that there is always a handler proc for WM_DELETE_WINDOW. This handler is not seen for me on Windows:

% wm protocol .
--> no response
% wm protocol . WM_DELETE_WINDOW
--> no response

I would appreciate to change the wording, that if no handler is defined, the window is destroyed. If there is a handler, it is not destroyed automatically.

My test script:

toplevel .t
wm protocol .t WM_DELETE_WINDOW a
proc a args {puts "a<$args>"}

Then press the close button of the toplevel .t. The procedure is executed (printing "a<>" to the console), but the window is not closed.

I would appreciate if a native speaker looks about the wording. I may just be wrong and anything is already clear.

Thank you all, Harald

User Comments: oehhar added on 2021-12-06 14:29:06:
Great work, thank you two! Harald

marc_culler (claiming to be Marc Culler) added on 2021-12-06 14:06:21:
I merged the changes to the man page, and I will close this ticket now.

fvogel added on 2021-12-05 08:39:03:

Thanks!

I have built the man page in this branch to check formatting and everything is fine. I have made an additional commit to fix a typo and to precise explicitely that wm protocol does not return the default handler for WM_DELETE_WINDOW, see [f88c489d9c]. If this is fine for you, the light is green for merging I think.


marc_culler (claiming to be Marc Culler) added on 2021-12-04 21:51:31:
OK.  It is in the wm_protocol_man branch.

fvogel added on 2021-12-04 09:48:15:
Marc, your text is totally fine for me. Can you proceed with the update in the man page perhaps? I'm asking because I'm not readily seeing where exactly to merge your proposal with the existing text, and you will certainly do a better job than I would. Thanks!

marc_culler (claiming to be Marc Culler) added on 2021-12-02 03:52:42:
Reopening - I somehow closed it by accident.

marc_culler (claiming to be Marc Culler) added on 2021-12-01 14:49:04:

Here is my suggestion:

A window manager protocol is a type of message sent from a window manager to a Tk application outside of the normal event processing system. The main example is the WM_DELETE_WINDOW protocol. Messages of this type are sent when the user clicks the close widget in the title bar of a window, but they may also be sent by the window manager without any user action. Window manager protocols have handlers which can be installed with the wm_protocol command. As a rule, if no handler has been installed for a protocol with the wm_protocol command then all messages within that protocol are ignored. The WM_DELETE_WINDOW protocol is an exception to this rule. Tk always installs a handler for the WM_DELETE_WINDOW protocol, which responds by destroying the window. The wm_protocol command can be used to replace this default handler by one which responds differently.

The list of available window manager protocols depends on the window manager, but all window managers supported by Tk provide WM_DELETE_WINDOW.


oehhar added on 2021-12-01 10:16:25:

What do you think of the following text:

- WM_DELETE_WINDOW is invoked when the window should be closed by a user action, for example by pressing the X-Button in the title bar of the window - The default action is to destroy the window. The default action is invoked, if no protocol handler is defined. If a protocol handler is defined, the default action is not invoked.

Thank you, Harald


fvogel added on 2021-12-01 07:56:40:
Well, manuals can always be further improved. What better text could you propose to lake this point clearer?

oehhar added on 2021-12-01 07:31:00:

Thank you for your light, so it is just me.

Ticket closed, thank you, Harald


fvogel added on 2021-11-30 20:45:15:

I think the code here sheds light on this in TkWmProtocolEventProc() (this is the Win code, there is the same code for the other two platforms).

> Reading this description, I understand that there is always a handler
> proc for WM_DELETE_WINDOW. This handler is not seen for me on Windows

The default when no handler is defined through wm protocol is to destroy the window. However no handler is defined (through wm protocol), therefore I think it's consistent that wm protocol returns the empty string in this case.

> Then press the close button of the toplevel .t.
> The procedure is executed (printing "a<>" to the console), but the
>  window is not closed.

Again consistent IMO. When there is a handler defined through wm protocol, this handler is executed. If this handler does not destroy the window (such as your example proc "a"), then why not, it's fine. The default handler (which destroys the window) is not executed since there is a defined handler. Still fine.