On May 18, 2009, at 4:12 PM, Stefan Monnier wrote: >> Precisely for this reason is the patch not sufficient. > > I do not understand. > >> When there is a hidden frame, and you delete the only other >> existing frame, >> we end up in a situation where there is no key window to receive >> the event, >> and all events (including menu items) are simply dropped. > > Could you explain concretely why it's a problem. Well, if you have only hidden frames this way, you will receive no key events: (progn (make-frame-invisible (selected-frame) t) (make-frame) (delete-frame (selected-frame) t)) The Lisp level doesn't even see menu events. A little more investigation shows that we get the event in keyDown:, but we discard it in this code: if (![[self window] isKeyWindow]) { /* XXX: There is an occasional condition in which, when Emacs display updates a different frame from the current one, and temporarily selects it, then processes some interrupt-driven input (dispnew.c:3878), OS will send the event to the correct NSWindow, but for some reason that window has its first responder set to the NSView most recently updated (I guess), which is not the correct one. */ if ([[theEvent window] isKindOfClass: [EmacsWindow class]]) [(EmacsView *)[[theEvent window] delegate] keyDown: theEvent]; return; } The outer if condition is true, presumably for the weird reason stated in the comment. The inner if condition is false, so the event doesn't get passed on, and we just discard it. Sticking the "return" into the inner if helps. Of course I'm not so sure if that is the right fix. Even with this workaround/fix, now we're back to the other problem with this bit of code: (progn (make-frame-invisible (selected-frame) t) (make-frame) (delete-frame (selected-frame) t) (make-frame) (sit-for 0) (delete-frame (selected-frame) t)) This will leave a frame visible, i.e. in the last `delete-frame', the frame is deleted, but the other one is made visible. That happens because the FRAME_VISIBLE_P check in do_switch_frame does not return nil for frames that are actually supposed to be hidden. It shouldn't do that... f->visible and f->async_visible are both 1, even at the beginning of do_switch_frame. I don't understand why. Note that this does NOT happen if you run it without the `sit-for' call, e.g. in a single `progn' form. Ideas?