diff src/event-msw.c @ 1204:e22b0213b713

[xemacs-hg @ 2003-01-12 11:07:58 by michaels] modules/ChangeLog: 2002-12-16 Ben Wing <ben@xemacs.org> * postgresql/postgresql.c: remove ifdef USE_KKCC. src/ChangeLog: 2003-01-08 Mike Sperber <mike@xemacs.org> * console.h (CDFW_CONSOLE): Don't lead to a crash if we're dealing with a dead window/frame/device/console. 2002-12-20 Mike Sperber <mike@xemacs.org> * ui-gtk.c: Fix typo from Ben's patch: emacs_ffi_data is a typedef, not a struct. emacs_gtk_object_data is a typedef, not a struct. * gtk-glue.c (gdk_event_to_emacs_event): Fix typos from Ben's patch: le -> emacs_event + rearrange the code. * event-gtk.c (gtk_event_to_emacs_event): Fix typos from Ben's patch: ..._UNDERLYING_GDK_EVENT -> ..._GDK_EVENT, ev -> key_event. * device-gtk.c: Fix typo from Ben's patch: x_keysym_map_hash_table -> x_keysym_map_hashtable. 2002-12-19 Mike Sperber <mike@xemacs.org> * menubar-x.c (set_frame_menubar): Initialize protect_me field of popup_data. 2002-12-16 Ben Wing <ben@xemacs.org> Major cleanup of KKCC, etc. KKCC, pdump-related: -- descriptions are written for all objects. this required some changes in the format of some objects, e.g. extents, popup-data, coding system, lstream, lcrecord-list. -- KKCC now handles weakness in markers, hash tables, elsewhere correctly (formerly, you'd eventually get a stack overflow due to endlessly expanding markers). -- textual changes: lrecord_description -> memory_description, struct_description -> sized_memory_description. -- extensive comment describing descriptions and pdump. -- redo XD_UNION so it works inline and change its format to provide sufficient info for pdump. implement XD_UNION in pdump. also add XD_UNION_DYNAMIC_SIZE, which works like XD_UNION except for when auto-computing structure sizes. -- add support for XD_INDIRECT in description offsets (used by extents). -- add support for "description maps", allowing for indirect descriptions that are retrieved from an object at run-time. this generalizes XD_CODING_SYSTEM_END, XD_SPECIFIER_END, etc., which have now been eliminated. -- add a fifth field "flags" to memory_description, to support flags that can be specified for this particular line. Currently defined flags are XD_FLAG_NO_KKCC (KKCC should ignore this entry; useful for the weakness above in markers, etc.), XD_FLAG_NO_PDUMP (pdump should ignore this entry), XD_FLAG_UNION_DEFAULT_ENTRY (in union maps, this specifies a "default" entry for all remaining values), and XD_FLAG_FREE_LISP_OBJECT (for use with lcrecord-lists). -- clean up the kkcc-itis in events, so that the differences between event data as separate objects and as a union are now minimized to a small number of places. with the new XD_UNION, we no longer need event data as separate objects, so this code is no longer ifdef USE_KKCC, but instead ifdef EVENT_DATA_AS_OBJECTS, not used by default. make sure that we explicitly free the separate event data objects when no longer in use, to maintain the invariant the event processing causes no consing. -- also remove other USE_KKCC ifdefs when not necessary. -- allow for KKCC compilation under MS Windows. -- fix README.kkcc. -- dump_add_root_object -> dump_add_root_lisp_object. -- implement dump_add_root_block and use this to handle dump_add_opaque. -- factor out some code duplicated in kkcc and pdump. Other allocation/object-related: -- change various *slots.h so MARKED_SLOT() call no longer includes semicolon. -- free_marker() takes a Lisp_Object not a direct pointer. -- make bit vectors lcrecords, like vectors, and eliminate code that essentially duplicated the lcrecord handling. -- additional asserts in FREE_FIXED_TYPE, formerly duplicated in the various callers of this. -- all lcrecord allocation functions now zero out the returned lcrecords. unnecessary calls to zero_lcrecord removed. add long comment describing these functions. -- extract out process and coding system slots, like for buffers, frames, etc. -- lcrecords now set the type of items sitting on the free list to lcrecord_type_free. -- changes to the way that gap arrays are allocated, for kkcc's benefit -- now, one single memory block with a stretchy array on the end, instead of a separate block holding the array. Error-checking-related: -- now can compile with C++ under MS Windows. clean up compile errors discovered that way. (a few were real problems) -- add C++ error-checking code to verify problems with mismatched GCPRO/UNGCPRO. (there were a few in the kkcc code.) add long comment about how to catch insufficient GCPRO (yes, it's possible using C++). -- add debug_p4(), a simple object printer, when debug_print() doesn't work. -- add dp() and db() as short synonyms of debug_print(), debug_backtrace(). -- `print' tries EXTREMELY hard to avoid core dumping when printing when crashing or from debug_print(), and tries as hard as it reasonably can in other situations. -- Correct the message output upon crashing to be more up-to-date. Event-related: -- document event-matches-key-specifier-p better. -- generalize the dispatch queues formerly duplicated in the various event implementations. add event methods to drain pending events. generalize and clean up QUIT handling, removing event-specific quit processing. allow arbitrary keystrokes, not just ASCII, to be the QUIT char. among other things, this should fix some longstanding bugs in X quit handling. long comment describing the various event queues. -- implement delaying of XFlush() if there are pending expose events. SOMEONE PLEASE TRY THIS OUT. -- Fix `xemacs -batch -l dunnet' under Cygwin. Try to fix under MS Windows but not quite there yet. Other: -- class -> class_ and no more C++ games with this item. new -> new_ in the lwlib code, so far not elsewhere. -- use `struct htentry' not `struct hentry' in elhash.c to avoid debugger confusion with hash.c. -- new macros ALIST_LOOP_3, ALIST_LOOP_4. * README.kkcc: * alloc.c: * alloc.c (deadbeef_memory): * alloc.c (allocate_lisp_storage): * alloc.c (copy_lisp_object): * alloc.c (ALLOCATE_FIXED_TYPE_1): * alloc.c (FREE_FIXED_TYPE): * alloc.c (make_vector_internal): * alloc.c (make_bit_vector_internal): * alloc.c (make_key_data): * alloc.c (make_button_data): * alloc.c (make_motion_data): * alloc.c (make_process_data): * alloc.c (make_timeout_data): * alloc.c (make_magic_data): * alloc.c (make_magic_eval_data): * alloc.c (make_eval_data): * alloc.c (make_misc_user_data): * alloc.c (struct string_chars_block): * alloc.c (mark_lcrecord_list): * alloc.c (make_lcrecord_list): * alloc.c (alloc_managed_lcrecord): * alloc.c (free_managed_lcrecord): * alloc.c (alloc_automanaged_lcrecord): * alloc.c (staticpro_1): * alloc.c (staticpro): * alloc.c (lispdesc_indirect_count_1): * alloc.c (lispdesc_indirect_description_1): * alloc.c (lispdesc_one_description_line_size): * alloc.c (lispdesc_structure_size): * alloc.c (mark_object_maybe_checking_free): * alloc.c (mark_with_description): * alloc.c (mark_struct_contents): * alloc.c (mark_object): * alloc.c (tick_lcrecord_stats): * alloc.c (free_cons): * alloc.c (free_key_data): * alloc.c (free_button_data): * alloc.c (free_motion_data): * alloc.c (free_process_data): * alloc.c (free_timeout_data): * alloc.c (free_magic_data): * alloc.c (free_magic_eval_data): * alloc.c (free_eval_data): * alloc.c (free_misc_user_data): * alloc.c (free_marker): * alloc.c (compact_string_chars): * alloc.c (gc_sweep): * alloc.c (garbage_collect_1): * alloc.c (Fgarbage_collect): * alloc.c (common_init_alloc_early): * alloc.c (init_alloc_early): * alloc.c (init_alloc_once_early): * buffer.c: * buffer.c (mark_buffer): * buffer.c (MARKED_SLOT): * buffer.c (cleanup_buffer_undo_lists): * buffer.c (Fget_file_buffer): * buffer.h (MARKED_SLOT): * bufslots.h: * bytecode.c: * callint.c: * casetab.c: * chartab.c: * chartab.c (symbol_to_char_table_type): * cmdloop.c: * cmdloop.c (Fcommand_loop_1): * config.h.in (new): * conslots.h: * console-gtk-impl.h (struct gtk_frame): * console-impl.h: * console-impl.h (struct console): * console-impl.h (MARKED_SLOT): * console-impl.h (CONSOLE_QUIT_EVENT): * console-msw-impl.h (XM_BUMPQUEUE): * console-msw.c (write_string_to_mswindows_debugging_output): * console-msw.h: * console-stream-impl.h: * console-stream-impl.h (struct stream_console): * console-stream.c: * console-stream.c (stream_init_console): * console-stream.h: * console-tty.c: * console-tty.h: * console-x.h: * console.c: * console.c (mark_console): * console.c (MARKED_SLOT): * console.c (allocate_console): * console.c (get_console_variant): * console.c (create_console): * console.c (delete_console_internal): * console.c (Fset_input_mode): * console.c (Fcurrent_input_mode): * console.c (common_init_complex_vars_of_console): * console.h: * console.h (console_variant): * console.h (device_metrics): * data.c: * data.c (Faref): * data.c (Faset): * data.c (decode_weak_list_type): * database.c: * debug.c (xemacs_debug_loop): * debug.c (FROB): * debug.c (Fadd_debug_class_to_check): * debug.c (Fdelete_debug_class_to_check): * debug.c (Fset_debug_classes_to_check): * debug.c (Fset_debug_class_types_to_check): * debug.c (Fdebug_types_being_checked): * debug.h (DASSERT): * device-gtk.c: * device-impl.h (struct device): * device-impl.h (MARKED_SLOT): * device-msw.c: * device-x.c: * device-x.c (x_init_device_class): * device-x.c (x_comp_visual_info): * device-x.c (x_try_best_visual_class): * device-x.c (x_init_device): * device-x.c (construct_name_list): * device-x.c (x_get_resource_prefix): * device-x.c (Fx_get_resource): * device-x.c (Fx_display_visual_class): * device.c: * device.c (MARKED_SLOT): * device.c (allocate_device): * device.c (Fmake_device): * device.c (delete_device_internal): * device.c (Fset_device_class): * device.h: * devslots.h: * devslots.h (MARKED_SLOT): * dialog-msw.c: * dired-msw.c (mswindows_ls_sort_fcn): * dired-msw.c (mswindows_get_files): * dired-msw.c (mswindows_format_file): * doprnt.c (parse_doprnt_spec): * dumper.c: * dumper.c (struct): * dumper.c (dump_add_root_block): * dumper.c (dump_add_root_struct_ptr): * dumper.c (dump_add_root_lisp_object): * dumper.c (pdump_struct_list_elt): * dumper.c (pdump_get_entry_list): * dumper.c (pdump_backtrace): * dumper.c (pdump_bump_depth): * dumper.c (pdump_register_sub): * dumper.c (pdump_register_object): * dumper.c (pdump_register_struct_contents): * dumper.c (pdump_register_struct): * dumper.c (pdump_store_new_pointer_offsets): * dumper.c (pdump_dump_data): * dumper.c (pdump_reloc_one): * dumper.c (pdump_allocate_offset): * dumper.c (pdump_scan_by_alignment): * dumper.c (pdump_dump_root_blocks): * dumper.c (pdump_dump_rtables): * dumper.c (pdump_dump_root_lisp_objects): * dumper.c (pdump): * dumper.c (pdump_load_finish): * dumper.c (pdump_file_get): * dumper.c (pdump_resource_get): * dumper.c (pdump_load): * editfns.c (save_excursion_restore): * editfns.c (user_login_name): * editfns.c (save_restriction_restore): * elhash.c: * elhash.c (htentry): * elhash.c (struct Lisp_Hash_Table): * elhash.c (HTENTRY_CLEAR_P): * elhash.c (LINEAR_PROBING_LOOP): * elhash.c (check_hash_table_invariants): * elhash.c (mark_hash_table): * elhash.c (hash_table_equal): * elhash.c (print_hash_table_data): * elhash.c (free_hentries): * elhash.c (make_general_lisp_hash_table): * elhash.c (decode_hash_table_weakness): * elhash.c (decode_hash_table_test): * elhash.c (Fcopy_hash_table): * elhash.c (resize_hash_table): * elhash.c (pdump_reorganize_hash_table): * elhash.c (find_htentry): * elhash.c (Fgethash): * elhash.c (Fputhash): * elhash.c (remhash_1): * elhash.c (Fremhash): * elhash.c (Fclrhash): * elhash.c (copy_compress_hentries): * elhash.c (elisp_maphash_unsafe): * elhash.c (finish_marking_weak_hash_tables): * elhash.c (prune_weak_hash_tables): * elhash.h: * emacs.c: * emacs.c (main_1): * emacs.c (main): * emacs.c (shut_down_emacs): * emodules.h (dump_add_root_lisp_object): * eval.c: * eval.c (unwind_to_catch): * eval.c (maybe_signal_error_1): * eval.c (maybe_signal_continuable_error_1): * eval.c (maybe_signal_error): * eval.c (maybe_signal_continuable_error): * eval.c (maybe_signal_error_2): * eval.c (maybe_signal_continuable_error_2): * eval.c (maybe_signal_ferror): * eval.c (maybe_signal_continuable_ferror): * eval.c (maybe_signal_ferror_with_frob): * eval.c (maybe_signal_continuable_ferror_with_frob): * eval.c (maybe_syntax_error): * eval.c (maybe_sferror): * eval.c (maybe_invalid_argument): * eval.c (maybe_invalid_constant): * eval.c (maybe_invalid_operation): * eval.c (maybe_invalid_change): * eval.c (maybe_invalid_state): * eval.c (Feval): * eval.c (call_trapping_problems): * eval.c (call_with_suspended_errors): * eval.c (warn_when_safe_lispobj): * eval.c (warn_when_safe): * eval.c (vars_of_eval): * event-Xt.c: * event-Xt.c (maybe_define_x_key_as_self_inserting_character): * event-Xt.c (x_to_emacs_keysym): * event-Xt.c (x_event_to_emacs_event): * event-Xt.c (emacs_Xt_enqueue_focus_event): * event-Xt.c (emacs_Xt_format_magic_event): * event-Xt.c (emacs_Xt_compare_magic_event): * event-Xt.c (emacs_Xt_hash_magic_event): * event-Xt.c (emacs_Xt_handle_magic_event): * event-Xt.c (Xt_timeout_to_emacs_event): * event-Xt.c (Xt_process_to_emacs_event): * event-Xt.c (signal_special_Xt_user_event): * event-Xt.c (emacs_Xt_next_event): * event-Xt.c (emacs_Xt_event_handler): * event-Xt.c (emacs_Xt_drain_queue): * event-Xt.c (emacs_Xt_event_pending_p): * event-Xt.c (check_if_pending_expose_event): * event-Xt.c (reinit_vars_of_event_Xt): * event-Xt.c (vars_of_event_Xt): * event-gtk.c: * event-gtk.c (IS_MODIFIER_KEY): * event-gtk.c (emacs_gtk_format_magic_event): * event-gtk.c (emacs_gtk_compare_magic_event): * event-gtk.c (emacs_gtk_hash_magic_event): * event-gtk.c (emacs_gtk_handle_magic_event): * event-gtk.c (gtk_to_emacs_keysym): * event-gtk.c (gtk_timeout_to_emacs_event): * event-gtk.c (gtk_process_to_emacs_event): * event-gtk.c (dragndrop_data_received): * event-gtk.c (signal_special_gtk_user_event): * event-gtk.c (emacs_gtk_next_event): * event-gtk.c (gtk_event_to_emacs_event): * event-gtk.c (generic_event_handler): * event-gtk.c (emacs_shell_event_handler): * event-gtk.c (emacs_gtk_drain_queue): * event-gtk.c (emacs_gtk_event_pending_p): * event-gtk.c (reinit_vars_of_event_gtk): * event-gtk.c (vars_of_event_gtk): * event-msw.c: * event-msw.c (struct winsock_stream): * event-msw.c (winsock_reader): * event-msw.c (winsock_writer): * event-msw.c (mswindows_enqueue_dispatch_event): * event-msw.c (mswindows_enqueue_misc_user_event): * event-msw.c (mswindows_enqueue_magic_event): * event-msw.c (mswindows_enqueue_process_event): * event-msw.c (mswindows_enqueue_mouse_button_event): * event-msw.c (mswindows_enqueue_keypress_event): * event-msw.c (mswindows_dequeue_dispatch_event): * event-msw.c (emacs_mswindows_drain_queue): * event-msw.c (mswindows_need_event_in_modal_loop): * event-msw.c (mswindows_need_event): * event-msw.c (mswindows_wm_timer_callback): * event-msw.c (dde_eval_string): * event-msw.c (Fdde_alloc_advise_item): * event-msw.c (mswindows_dde_callback): * event-msw.c (mswindows_wnd_proc): * event-msw.c (remove_timeout_mapper): * event-msw.c (emacs_mswindows_remove_timeout): * event-msw.c (emacs_mswindows_event_pending_p): * event-msw.c (emacs_mswindows_format_magic_event): * event-msw.c (emacs_mswindows_compare_magic_event): * event-msw.c (emacs_mswindows_hash_magic_event): * event-msw.c (emacs_mswindows_handle_magic_event): * event-msw.c (emacs_mswindows_select_console): * event-msw.c (emacs_mswindows_unselect_console): * event-msw.c (reinit_vars_of_event_mswindows): * event-msw.c (vars_of_event_mswindows): * event-stream.c: * event-stream.c (mark_command_builder): * event-stream.c (reset_command_builder_event_chain): * event-stream.c (allocate_command_builder): * event-stream.c (copy_command_builder): * event-stream.c (command_builder_append_event): * event-stream.c (event_stream_event_pending_p): * event-stream.c (event_stream_force_event_pending): * event-stream.c (maybe_read_quit_event): * event-stream.c (event_stream_drain_queue): * event-stream.c (remove_quit_p_event): * event-stream.c (event_stream_quit_p): * event-stream.c (echo_key_event): * event-stream.c (maybe_kbd_translate): * event-stream.c (execute_help_form): * event-stream.c (event_stream_generate_wakeup): * event-stream.c (enqueue_dispatch_event): * event-stream.c (enqueue_magic_eval_event): * event-stream.c (Fenqueue_eval_event): * event-stream.c (enqueue_misc_user_event): * event-stream.c (enqueue_misc_user_event_pos): * event-stream.c (next_event_internal): * event-stream.c (Fnext_event): * event-stream.c (Faccept_process_output): * event-stream.c (execute_internal_event): * event-stream.c (munge_keymap_translate): * event-stream.c (command_builder_find_leaf_no_mule_processing): * event-stream.c (command_builder_find_leaf): * event-stream.c (lookup_command_event): * event-stream.c (is_scrollbar_event): * event-stream.c (execute_command_event): * event-stream.c (Fdispatch_event): * event-stream.c (Fread_key_sequence): * event-stream.c (dribble_out_event): * event-stream.c (vars_of_event_stream): * event-tty.c (tty_timeout_to_emacs_event): * event-tty.c (emacs_tty_next_event): * event-tty.c (emacs_tty_drain_queue): * event-tty.c (reinit_vars_of_event_tty): * event-unixoid.c: * event-unixoid.c (find_tty_or_stream_console_from_fd): * event-unixoid.c (read_event_from_tty_or_stream_desc): * event-unixoid.c (drain_tty_devices): * event-unixoid.c (poll_fds_for_input): * events.c: * events.c (deinitialize_event): * events.c (zero_event): * events.c (mark_event): * events.c (print_event_1): * events.c (print_event): * events.c (event_equal): * events.c (event_hash): * events.c (Fmake_event): * events.c (Fdeallocate_event): * events.c (Fcopy_event): * events.c (map_event_chain_remove): * events.c (character_to_event): * events.c (event_to_character): * events.c (Fevent_to_character): * events.c (format_event_object): * events.c (upshift_event): * events.c (downshift_event): * events.c (event_upshifted_p): * events.c (Fevent_live_p): * events.c (Fevent_type): * events.c (Fevent_timestamp): * events.c (CHECK_EVENT_TYPE): * events.c (CHECK_EVENT_TYPE2): * events.c (CHECK_EVENT_TYPE3): * events.c (Fevent_key): * events.c (Fevent_button): * events.c (Fevent_modifier_bits): * events.c (event_x_y_pixel_internal): * events.c (event_pixel_translation): * events.c (Fevent_process): * events.c (Fevent_function): * events.c (Fevent_object): * events.c (Fevent_properties): * events.c (syms_of_events): * events.c (vars_of_events): * events.h: * events.h (struct event_stream): * events.h (struct Lisp_Key_Data): * events.h (KEY_DATA_KEYSYM): * events.h (EVENT_KEY_KEYSYM): * events.h (struct Lisp_Button_Data): * events.h (EVENT_BUTTON_BUTTON): * events.h (struct Lisp_Motion_Data): * events.h (EVENT_MOTION_X): * events.h (struct Lisp_Process_Data): * events.h (EVENT_PROCESS_PROCESS): * events.h (struct Lisp_Timeout_Data): * events.h (EVENT_TIMEOUT_INTERVAL_ID): * events.h (struct Lisp_Eval_Data): * events.h (EVENT_EVAL_FUNCTION): * events.h (struct Lisp_Misc_User_Data): * events.h (EVENT_MISC_USER_FUNCTION): * events.h (struct Lisp_Magic_Eval_Data): * events.h (EVENT_MAGIC_EVAL_INTERNAL_FUNCTION): * events.h (struct Lisp_Magic_Data): * events.h (EVENT_MAGIC_UNDERLYING): * events.h (EVENT_MAGIC_GDK_EVENT): * events.h (struct Lisp_Event): * events.h (XEVENT_CHANNEL): * events.h (SET_EVENT_TIMESTAMP_ZERO): * events.h (SET_EVENT_CHANNEL): * events.h (SET_EVENT_NEXT): * events.h (XSET_EVENT_TYPE): * events.h (struct command_builder): * extents.c: * extents.c (gap_array_adjust_markers): * extents.c (gap_array_recompute_derived_values): * extents.c (gap_array_move_gap): * extents.c (gap_array_make_gap): * extents.c (gap_array_insert_els): * extents.c (gap_array_delete_els): * extents.c (gap_array_make_marker): * extents.c (gap_array_delete_marker): * extents.c (gap_array_move_marker): * extents.c (make_gap_array): * extents.c (free_gap_array): * extents.c (extent_list_num_els): * extents.c (extent_list_insert): * extents.c (mark_extent_auxiliary): * extents.c (allocate_extent_auxiliary): * extents.c (decode_extent_at_flag): * extents.c (verify_extent_mapper): * extents.c (symbol_to_glyph_layout): * extents.c (syms_of_extents): * faces.c: * file-coding.c: * file-coding.c (struct_detector_category_description =): * file-coding.c (detector_category_dynarr_description_1): * file-coding.c (struct_detector_description =): * file-coding.c (detector_dynarr_description_1): * file-coding.c (MARKED_SLOT): * file-coding.c (mark_coding_system): * file-coding.c (coding_system_extra_description_map): * file-coding.c (coding_system_description): * file-coding.c (allocate_coding_system): * file-coding.c (symbol_to_eol_type): * file-coding.c (Fcoding_system_aliasee): * file-coding.c (set_coding_stream_coding_system): * file-coding.c (struct convert_eol_coding_system): * file-coding.c (struct undecided_coding_system): * file-coding.c (undecided_mark_coding_stream): * file-coding.c (coding_category_symbol_to_id): * file-coding.c (struct gzip_coding_system): * file-coding.c (coding_system_type_create): * file-coding.h: * file-coding.h (struct Lisp_Coding_System): * file-coding.h (CODING_SYSTEM_SLOT_DECLARATION): * file-coding.h (coding_system_variant): * file-coding.h (struct coding_system_methods): * file-coding.h (DEFINE_CODING_SYSTEM_TYPE_WITH_DATA): * file-coding.h (INITIALIZE_CODING_SYSTEM_TYPE_WITH_DATA): * file-coding.h (struct coding_stream): * fileio.c (Fsubstitute_in_file_name): * floatfns.c: * fns.c: * fns.c (base64_encode_1): * frame-gtk.c: * frame-gtk.c (Fgtk_start_drag_internal): * frame-impl.h (struct frame): * frame-impl.h (MARKED_SLOT): * frame-msw.c: * frame-x.c: * frame-x.c (Fcde_start_drag_internal): * frame-x.c (Foffix_start_drag_internal): * frame.c: * frame.c (MARKED_SLOT): * frame.c (allocate_frame_core): * frame.c (delete_frame_internal): * frame.c (Fmouse_position_as_motion_event): * frameslots.h: * frameslots.h (MARKED_SLOT_ARRAY): * free-hook.c: * glyphs-msw.c (mswindows_widget_instantiate): * glyphs-x.c: * glyphs-x.c (convert_EImage_to_XImage): * glyphs.c: * glyphs.c (process_image_string_instantiator): * glyphs.c (mark_image_instance): * glyphs.c (allocate_image_instance): * glyphs.c (unmap_subwindow): * glyphs.c (map_subwindow): * glyphs.c (syms_of_glyphs): * glyphs.c (specifier_type_create_image): * glyphs.h: * glyphs.h (struct text_image_instance): * glyphs.h (struct Lisp_Image_Instance): * gmalloc.c: * gmalloc.c ("C"): * gpmevent.c (Freceive_gpm_event): * gpmevent.c (gpm_next_event_cb): * gpmevent.c (vars_of_gpmevent): * gtk-glue.c (gdk_event_to_emacs_event): * gtk-xemacs.c (gtk_xemacs_class_init): * gui-msw.c: * gui-msw.c (mswindows_handle_gui_wm_command): * gui-msw.c (mswindows_translate_menu_or_dialog_item): * gui-x.c: * gui-x.c (mark_popup_data): * gui-x.c (snarf_widget_value_mapper): * gui-x.c (gcpro_popup_callbacks): * gui-x.c (ungcpro_popup_callbacks): * gui-x.c (free_popup_widget_value_tree): * gui-x.c (popup_selection_callback): * gui-x.h: * gui-x.h (struct popup_data): * gui.c: * gui.c (allocate_gui_item): * gutter.c (decode_gutter_position): * hash.c (NULL_ENTRY): * indent.c (vmotion_1): * indent.c (vmotion_pixels): * input-method-motif.c (res): * input-method-xlib.c (IMInstantiateCallback): * input-method-xlib.c (XIM_init_device): * input-method-xlib.c (res): * intl-encap-win32.c: * intl-encap-win32.c (qxeSHGetDataFromIDList): * intl-win32.c: * intl-win32.c (mswindows_multibyte_cp_type): * intl-win32.c (struct mswindows_multibyte_coding_system): * keymap.c: * keymap.c (make_key_description): * keymap.c (keymap_store): * keymap.c (get_keyelt): * keymap.c (keymap_lookup_1): * keymap.c (define_key_parser): * keymap.c (key_desc_list_to_event): * keymap.c (event_matches_key_specifier_p): * keymap.c (meta_prefix_char_p): * keymap.c (ensure_meta_prefix_char_keymapp): * keymap.c (Fdefine_key): * keymap.c (struct raw_lookup_key_mapper_closure): * keymap.c (raw_lookup_key): * keymap.c (raw_lookup_key_mapper): * keymap.c (lookup_keys): * keymap.c (lookup_events): * keymap.c (Flookup_key): * keymap.c (struct map_keymap_unsorted_closure): * keymap.c (map_keymap_unsorted_mapper): * keymap.c (map_keymap_sorted): * keymap.c (map_keymap_mapper): * keymap.c (map_keymap): * keymap.c (accessible_keymaps_mapper_1): * keymap.c (Faccessible_keymaps): * keymap.c (Fsingle_key_description): * keymap.c (raw_keys_to_keys): * keymap.c (format_raw_keys): * keymap.c (where_is_recursive_mapper): * keymap.c (where_is_internal): * keymap.c (describe_map_mapper_shadow_search): * keymap.c (keymap_lookup_inherited_mapper): * keymap.c (describe_map_mapper): * keymap.h (event_matches_key_specifier_p): * lisp.h: * lisp.h (this): * lisp.h (RETURN_NOT_REACHED): * lisp.h (struct Lisp_Vector): * lisp.h (struct Lisp_Bit_Vector): * lisp.h (UNGCPRO_1): * lisp.h (NUNGCPRO): * lisp.h (NNUNGCPRO): * lisp.h (DECLARE_INLINE_HEADER): * lrecord.h: * lrecord.h (struct lrecord_header): * lrecord.h (struct lcrecord_header): * lrecord.h (lrecord_type): * lrecord.h (struct lrecord_implementation): * lrecord.h (RECORD_DUMPABLE): * lrecord.h (memory_description_type): * lrecord.h (data_description_entry_flags): * lrecord.h (struct memory_description): * lrecord.h (struct sized_memory_description): * lrecord.h (XD_INDIRECT): * lrecord.h (XD_IS_INDIRECT): * lrecord.h (XD_DYNARR_DESC): * lrecord.h (DEFINE_BASIC_LRECORD_IMPLEMENTATION): * lrecord.h (MAKE_LRECORD_IMPLEMENTATION): * lrecord.h (MAKE_EXTERNAL_LRECORD_IMPLEMENTATION): * lrecord.h (alloc_lcrecord_type): * lstream.c: * lstream.c (Lstream_new): * lstream.c (lisp_buffer_marker): * lstream.h: * lstream.h (lstream_implementation): * lstream.h (DEFINE_LSTREAM_IMPLEMENTATION): * lstream.h (DEFINE_LSTREAM_IMPLEMENTATION_WITH_DATA): * marker.c: * marker.c (copy_marker_1): * mem-limits.h: * menubar-gtk.c: * menubar-gtk.c (gtk_popup_menu): * menubar-msw.c: * menubar-msw.c (mswindows_popup_menu): * menubar-x.c (make_dummy_xbutton_event): * menubar-x.c (command_builder_operate_menu_accelerator): * menubar-x.c (menu_accelerator_safe_compare): * menubar-x.c (menu_accelerator_safe_mod_compare): * mule-charset.c: * mule-charset.c (make_charset): * mule-charset.c (Fcharset_property): * mule-coding.c: * mule-coding.c (ccs_description_1): * mule-coding.c (ccs_description =): * mule-coding.c (ccsd_description_1): * mule-coding.c (ccsd_description =): * nt.c (getpwnam): * nt.c (init_mswindows_environment): * nt.c (get_cached_volume_information): * nt.c (mswindows_is_executable): * nt.c (read_unc_volume): * nt.c (mswindows_access): * nt.c (mswindows_link): * nt.c (mswindows_fstat): * nt.c (mswindows_stat): * nt.c (mswindows_executable_type): * nt.c (Fmswindows_short_file_name): * nt.c (Fmswindows_long_file_name): * objects-impl.h (struct Lisp_Color_Instance): * objects-impl.h (struct Lisp_Font_Instance): * objects-tty.c: * objects-x.c (allocate_nearest_color): * objects.c: * objects.c (Fmake_color_instance): * objects.c (Fmake_font_instance): * objects.c (font_instantiate): * opaque.c: * opaque.c (make_opaque): * opaque.c (make_opaque_ptr): * opaque.c (reinit_opaque_early): * opaque.c (init_opaque_once_early): * print.c: * print.c (printing_badness): * print.c (printing_major_badness): * print.c (print_internal): * print.c (debug_p4): * print.c (dp): * print.c (debug_backtrace): * process-nt.c (nt_create_process): * process-nt.c (get_internet_address): * process-unix.c: * process-unix.c (struct unix_process_data): * process-unix.c (get_internet_address): * process-unix.c (unix_alloc_process_data): * process-unix.c (unix_create_process): * process-unix.c (try_to_initialize_subtty): * process-unix.c (unix_kill_child_process): * process-unix.c (process_type_create_unix): * process.c: * process.c (mark_process): * process.c (MARKED_SLOT): * process.c (make_process_internal): * process.c (Fprocess_tty_name): * process.c (decode_signal): * process.h: * procimpl.h: * procimpl.h (struct process_methods): * procimpl.h (struct Lisp_Process): * rangetab.c: * realpath.c (readlink_and_correct_case): * redisplay-x.c (x_window_output_end): * redisplay-x.c (x_redraw_exposed_area): * redisplay-x.c (x_clear_frame): * redisplay.c: * redisplay.h: * redisplay.h (struct rune_dglyph): * redisplay.h (struct rune): * scrollbar.c: * scrollbar.c (create_scrollbar_instance): * specifier.c: * specifier.c (specifier_empty_extra_description_1): * specifier.c (make_specifier_internal): * specifier.c (decode_locale_type): * specifier.c (decode_how_to_add_specification): * specifier.h: * specifier.h (struct specifier_methods): * specifier.h (DEFINE_SPECIFIER_TYPE_WITH_DATA): * specifier.h (INITIALIZE_SPECIFIER_TYPE_WITH_DATA): * symbols.c: * symbols.c (Fsetplist): * symbols.c (default_value): * symbols.c (decode_magic_handler_type): * symbols.c (handler_type_from_function_symbol): * symbols.c (Fdefvaralias): * symbols.c (init_symbols_once_early): * symbols.c (reinit_symbols_early): * symsinit.h: * sysdep.c (sys_subshell): * sysdep.c (tty_init_sys_modes_on_device): * syswindows.h: * text.c (dfc_convert_to_external_format): * text.c (dfc_convert_to_internal_format): * text.c (reinit_eistring_early): * text.c (init_eistring_once_early): * text.c (reinit_vars_of_text): * text.h: * text.h (INC_IBYTEPTR_FMT): * text.h (DEC_IBYTEPTR_FMT): * toolbar.c: * toolbar.c (decode_toolbar_position): * tooltalk.c: * ui-gtk.c: * unexnt.c: * unexnt.c (_start): * unexnt.c (unexec): * unexnt.c (get_section_info): * unicode.c: * unicode.c (vars_of_unicode): * window.c: * window.c (allocate_window): * window.c (new_window_mirror): * window.c (update_mirror_internal): * winslots.h:
author michaels
date Sun, 12 Jan 2003 11:08:22 +0000
parents 184461bc8de4
children f0af455e89d9
line wrap: on
line diff
--- a/src/event-msw.c	Sun Jan 12 11:04:30 2003 +0000
+++ b/src/event-msw.c	Sun Jan 12 11:08:22 2003 +0000
@@ -73,6 +73,7 @@
 #include "sysdep.h"
 #include "window.h"
 
+#include "console-stream-impl.h"
 #include "console-msw-impl.h"
 #include "objects-msw-impl.h"
 
@@ -94,21 +95,12 @@
 #include "systime.h"
 #include "syswait.h"
 
-#ifdef CYGWIN
-#include "console-tty.h"
-#endif
-
 #ifdef HAVE_MENUBARS
 #define ADJR_MENUFLAG TRUE
 #else
 #define ADJR_MENUFLAG FALSE
 #endif
 
-/* Fake key modifier which is attached to a quit char event.
-   Removed upon dequeueing an event */
-#define FAKE_MOD_QUIT (1 << 20)
-#define FAKE_MOD_QUIT_CRITICAL (1 << 21)
-
 /* Timer ID used for button2 emulation */
 #define BUTTON_2_TIMER_ID 1
 
@@ -147,23 +139,18 @@
 #endif
 
 /*
- * Two separate queues, for efficiency, one (_u_) for user events, and
- * another (_s_) for non-user ones. We always return events out of the
- * first one until it is empty and only then proceed with the second
- * one.
+ * We use an additional queue, as well as the normal dispatch queue, for
+ * efficiency, the normal one for user events, and another (_s_) for non-user
+ * ones. We always return events out of the first one until it is empty and
+ * only then proceed with the second one.
  */
-static Lisp_Object mswindows_u_dispatch_event_queue, mswindows_u_dispatch_event_queue_tail;
-static Lisp_Object mswindows_s_dispatch_event_queue, mswindows_s_dispatch_event_queue_tail;
+static Lisp_Object mswindows_s_dispatch_event_queue;
+static Lisp_Object mswindows_s_dispatch_event_queue_tail;
 
 /* Brush for painting widgets */
 static HBRUSH widget_brush = 0;
 static LONG	last_widget_brushed = 0;
 
-/* Count of quit chars currently in the queue */
-/* Incremented in WM_[SYS]KEYDOWN handler in the mswindows_wnd_proc()
-   Decremented in mswindows_dequeue_dispatch_event() */
-int mswindows_quit_chars_count = 0;
-
 /* These are Lisp integers; see DEFVARS in this file for description. */
 int mswindows_dynamic_frame_resize;
 int mswindows_alt_by_itself_activates_menu;
@@ -690,7 +677,7 @@
   OVERLAPPED ov;		/* Overlapped I/O structure		     */
   void *buffer;			/* Buffer.                                   */
   DWORD bufsize;		/* Number of bytes last read		     */
-  DWORD charbpos;			/* Position in buffer for next fetch	     */
+  DWORD charbpos;		/* Position in buffer for next fetch	     */
   unsigned int error_p :1;	/* I/O Error seen			     */
   unsigned int eof_p :1;	/* EOF Error seen			     */
   unsigned int pending_p :1;	/* There is a pending I/O operation	     */
@@ -737,7 +724,8 @@
 	}
       else
 	{
-	  if (!GetOverlappedResult ((HANDLE)str->s, &str->ov, &str->bufsize, TRUE))
+	  if (!GetOverlappedResult ((HANDLE)str->s, &str->ov, &str->bufsize,
+				    TRUE))
 	    {
 	      if (GetLastError() == ERROR_HANDLE_EOF)
 		str->bufsize = 0;
@@ -783,7 +771,8 @@
       else
 	{
 	  DWORD dw_unused;
-	  if (!GetOverlappedResult ((HANDLE)str->s, &str->ov, &dw_unused, TRUE))
+	  if (!GetOverlappedResult ((HANDLE)str->s, &str->ov, &dw_unused,
+				    TRUE))
 	    str->error_p = 1;
 	  str->pending_p = 0;
 	}
@@ -927,12 +916,12 @@
 void
 mswindows_enqueue_dispatch_event (Lisp_Object event)
 {
-  int user_p = mswindows_user_event_p (XEVENT(event));
-  enqueue_event (event,
-		 user_p ? &mswindows_u_dispatch_event_queue :
-		 &mswindows_s_dispatch_event_queue,
-		 user_p ? &mswindows_u_dispatch_event_queue_tail :
-		 &mswindows_s_dispatch_event_queue_tail);
+  int user_p = mswindows_user_event_p (XEVENT (event));
+  if (user_p)
+    enqueue_dispatch_event (event);
+  else
+    enqueue_event (event, &mswindows_s_dispatch_event_queue,
+		   &mswindows_s_dispatch_event_queue_tail);
 
   /* Avoid blocking on WaitMessage */
   qxePostMessage (NULL, XM_BUMPQUEUE, 0, 0);
@@ -940,9 +929,6 @@
 
 /*
  * Add a misc-user event to the dispatch queue.
- *
- * Stuff it into our own dispatch queue, so we have something
- * to return from next_event callback.
  */
 void
 mswindows_enqueue_misc_user_event (Lisp_Object channel, Lisp_Object function,
@@ -950,22 +936,11 @@
 {
   Lisp_Object event = Fmake_event (Qnil, Qnil);
 
-#ifdef USE_KKCC
-
   XSET_EVENT_TYPE (event, misc_user_event);
   XSET_EVENT_CHANNEL (event, channel);
   XSET_EVENT_TIMESTAMP (event, GetTickCount());
-  XSET_MISC_USER_DATA_FUNCTION (XEVENT_DATA (event), function);
-  XSET_MISC_USER_DATA_OBJECT (XEVENT_DATA (event), object);
-#else /* not USE_KKCC */
-  Lisp_Event *e = XEVENT (event);
-
-  e->event_type = misc_user_event;
-  e->channel = channel;
-  e->timestamp = GetTickCount ();
-  e->event.misc.function = function;
-  e->event.misc.object = object;
-#endif /* not USE_KKCC */
+  XSET_EVENT_MISC_USER_FUNCTION (event, function);
+  XSET_EVENT_MISC_USER_OBJECT (event, object);
 
   mswindows_enqueue_dispatch_event (event);
 }
@@ -975,19 +950,10 @@
 {
   Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
 
-#ifdef USE_KKCC
-  XSET_EVENT_CHANNEL (emacs_event, (hwnd ? mswindows_find_frame (hwnd) : Qnil));
+  XSET_EVENT_CHANNEL (emacs_event, hwnd ? mswindows_find_frame (hwnd) : Qnil);
   XSET_EVENT_TIMESTAMP (emacs_event, GetMessageTime ());
   XSET_EVENT_TYPE (emacs_event, magic_event);
-  XSET_MAGIC_DATA_MSWINDOWS_EVENT (XEVENT_DATA(emacs_event), msg);
-#else /* not USE_KKCC */
-  Lisp_Event *event = XEVENT (emacs_event);
-
-  event->channel = hwnd ? mswindows_find_frame (hwnd) : Qnil;
-  event->timestamp = GetMessageTime();
-  event->event_type = magic_event;
-  EVENT_MSWINDOWS_MAGIC_TYPE (event) = msg;
-#endif /* not USE_KKCC */
+  XSET_EVENT_MAGIC_MSWINDOWS_EVENT (emacs_event, msg);
 
   mswindows_enqueue_dispatch_event (emacs_event);
 }
@@ -996,19 +962,11 @@
 mswindows_enqueue_process_event (Lisp_Process *p)
 {
   Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
-  Lisp_Event *event = XEVENT (emacs_event);
   Lisp_Object process = wrap_process (p);
 
-
-#ifdef USE_KKCC
   XSET_EVENT_TYPE (emacs_event, process_event);
-  XSET_EVENT_TIMESTAMP (emacs_event, GetTickCount());
-  XSET_PROCESS_DATA_PROCESS (XEVENT_DATA (emacs_event), process);
-#else /* not USE_KKCC */
-  event->event_type = process_event;
-  event->timestamp  = GetTickCount ();
-  event->event.process.process = process;
-#endif /* not USE_KKCC */
+  XSET_EVENT_TIMESTAMP (emacs_event, GetTickCount ());
+  XSET_EVENT_PROCESS_PROCESS (emacs_event, process);
 
   mswindows_enqueue_dispatch_event (emacs_event);
 }
@@ -1025,47 +983,27 @@
      recognition will fail */
 
   Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
-  Lisp_Event *event = XEVENT (emacs_event);
 
   mswindows_handle_sticky_modifiers (0, 0, downp, 0);
 
   if (downp)
     {
-#ifdef USE_KKCC
       XSET_EVENT_TYPE (emacs_event, button_press_event);
-#else /* not USE_KKCC */
-      event->event_type = button_press_event;
-#endif /* not USE_KKCC */
     }
   else
     {
-#ifdef USE_KKCC
       XSET_EVENT_TYPE (emacs_event, button_release_event);
-#else /* not USE_KKCC */
-      event->event_type = button_release_event;
-#endif /* not USE_KKCC */
     }
 
-#ifdef USE_KKCC
   XSET_EVENT_CHANNEL (emacs_event, mswindows_find_frame (hwnd));
   XSET_EVENT_TIMESTAMP (emacs_event, when);
-  XSET_BUTTON_DATA_BUTTON (XEVENT_DATA (emacs_event), 
+  XSET_EVENT_BUTTON_BUTTON (emacs_event, 
 	 (msg==WM_LBUTTONDOWN || msg==WM_LBUTTONUP) ? 1 :
 	 ((msg==WM_RBUTTONDOWN || msg==WM_RBUTTONUP) ? 3 : 2));
-  XSET_BUTTON_DATA_X (XEVENT_DATA (emacs_event), where.x);
-  XSET_BUTTON_DATA_Y (XEVENT_DATA (emacs_event), where.y);
-  XSET_BUTTON_DATA_MODIFIERS (XEVENT_DATA (emacs_event),
-			      mswindows_modifier_state (NULL, mods, 0));
-#else /* not USE_KKCC */
-  event->channel = mswindows_find_frame (hwnd);
-  event->timestamp = when;
-  event->event.button.button =
-    (msg==WM_LBUTTONDOWN || msg==WM_LBUTTONUP) ? 1 :
-    ((msg==WM_RBUTTONDOWN || msg==WM_RBUTTONUP) ? 3 : 2);
-  event->event.button.x = where.x;
-  event->event.button.y = where.y;
-  event->event.button.modifiers = mswindows_modifier_state (NULL, mods, 0);
-#endif /* not USE_KKCC */
+  XSET_EVENT_BUTTON_X (emacs_event, where.x);
+  XSET_EVENT_BUTTON_Y (emacs_event, where.y);
+  XSET_EVENT_BUTTON_MODIFIERS (emacs_event,
+			       mswindows_modifier_state (NULL, mods, 0));
 
   if (downp)
     {
@@ -1091,21 +1029,11 @@
 {
   Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
 
-#ifdef USE_KKCC
   XSET_EVENT_CHANNEL (emacs_event,  mswindows_find_console(hwnd));
   XSET_EVENT_TIMESTAMP (emacs_event, GetMessageTime());
   XSET_EVENT_TYPE (emacs_event, key_press_event);
-  XSET_KEY_DATA_KEYSYM (XEVENT_DATA (emacs_event), keysym);
-  XSET_KEY_DATA_MODIFIERS (XEVENT_DATA (emacs_event), mods);
-#else /* not USE_KKCC */
-  Lisp_Event *event = XEVENT(emacs_event);
-
-  event->channel = mswindows_find_console(hwnd);
-  event->timestamp = GetMessageTime();
-  event->event_type = key_press_event;
-  event->event.key.keysym = keysym;
-  event->event.key.modifiers = mods;
-#endif /* not USE_KKCC */
+  XSET_EVENT_KEY_KEYSYM (emacs_event, keysym);
+  XSET_EVENT_KEY_MODIFIERS (emacs_event, mods);
   mswindows_enqueue_dispatch_event (emacs_event);
   return emacs_event;
 }
@@ -1117,92 +1045,14 @@
 static Lisp_Object
 mswindows_dequeue_dispatch_event (void)
 {
-  Lisp_Object event;
-  Lisp_Event *sevt;
-
-  assert (!NILP(mswindows_u_dispatch_event_queue) ||
-	  !NILP(mswindows_s_dispatch_event_queue));
-
-  event = dequeue_event (
-			 NILP(mswindows_u_dispatch_event_queue) ?
-			 &mswindows_s_dispatch_event_queue :
-			 &mswindows_u_dispatch_event_queue,
-			 NILP(mswindows_u_dispatch_event_queue) ?
-			 &mswindows_s_dispatch_event_queue_tail :
-			 &mswindows_u_dispatch_event_queue_tail);
-
-#ifdef USE_KKCC
-  if (XEVENT_TYPE (event) == key_press_event
-      && (XKEY_DATA_MODIFIERS (XEVENT_DATA(event)) & FAKE_MOD_QUIT))
-    XSET_KEY_DATA_MODIFIERS (XEVENT_DATA (event), 
-			    XKEY_DATA_MODIFIERS (XEVENT_DATA (event)) &
-						 ~(FAKE_MOD_QUIT | FAKE_MOD_QUIT_CRITICAL));
-#else /* not USE_KKCC */
-  sevt = XEVENT (event);
-  if (sevt->event_type == key_press_event
-      && (sevt->event.key.modifiers & FAKE_MOD_QUIT))
-    sevt->event.key.modifiers &=
-      ~(FAKE_MOD_QUIT | FAKE_MOD_QUIT_CRITICAL);
-#endif /* not USE_KKCC */
-
-  return event;
-}
-
-/*
- * Remove and return the first emacs event on the dispatch queue that matches
- * the supplied event.
- * Timeout event matches if interval_id is equal to that of the given event.
- * Keypress event matches if logical AND between modifiers bitmask of the
- * event in the queue and that of the given event is non-zero.
- * For all other event types, this function aborts.
- */
-
-Lisp_Object
-mswindows_cancel_dispatch_event (Lisp_Event *match)
-{
-  Lisp_Object event;
-  Lisp_Object previous_event = Qnil;
-  int user_p = mswindows_user_event_p (match);
-  Lisp_Object *head = user_p ? &mswindows_u_dispatch_event_queue :
-    &mswindows_s_dispatch_event_queue;
-  Lisp_Object *tail = user_p ? &mswindows_u_dispatch_event_queue_tail :
-    &mswindows_s_dispatch_event_queue_tail;
-
-  assert (match->event_type == timeout_event
-	  || match->event_type == key_press_event);
-
-  EVENT_CHAIN_LOOP (event, *head)
-    {
-      Lisp_Event *e = XEVENT (event);
-#ifdef USE_KKCC
-      if ((EVENT_TYPE (e) == EVENT_TYPE (match)) &&
-	  ((EVENT_TYPE (e) == timeout_event) ?
-	   (XTIMEOUT_DATA_INTERVAL_ID (EVENT_DATA (e)) ==
-	    XTIMEOUT_DATA_INTERVAL_ID (EVENT_DATA (match))) :
-	   ((XKEY_DATA_MODIFIERS (EVENT_DATA (e)) &
-	     XKEY_DATA_MODIFIERS (EVENT_DATA (match))) != 0)))
-#else /* not USE_KKCC */
-      if ((e->event_type == match->event_type) &&
-	  ((e->event_type == timeout_event) ?
-	   (e->event.timeout.interval_id == match->event.timeout.interval_id) :
-	   /* Must be key_press_event */
-	   ((e->event.key.modifiers & match->event.key.modifiers) != 0)))
-#endif /* not USE_KKCC */
-	{
-	  if (NILP (previous_event))
-	    dequeue_event (head, tail);
-	  else
-	    {
-	      XSET_EVENT_NEXT (previous_event, XEVENT_NEXT (event));
-	      if (EQ (*tail, event))
-		*tail = previous_event;
-	    }
-
-	  return event;
-	}
-      previous_event = event;
-    }
-  return Qnil;
+  assert (!NILP (dispatch_event_queue) ||
+	  !NILP (mswindows_s_dispatch_event_queue));
+
+  if (!NILP (dispatch_event_queue))
+    return dequeue_dispatch_event ();
+  else
+    return dequeue_event (&mswindows_s_dispatch_event_queue,
+			  &mswindows_s_dispatch_event_queue_tail);
 }
 
 #ifndef CYGWIN
@@ -1458,6 +1308,23 @@
     }
 }
 
+static void
+emacs_mswindows_drain_queue (void)
+{
+  mswindows_drain_windows_queue ();
+#ifdef HAVE_TTY
+  drain_tty_devices ();
+#endif
+}
+
+static int
+emacs_mswindows_quit_check_disallowed_p (void)
+{
+  /* Quit cannot happen in modal loop: all program
+     input is dedicated to Windows. */
+  return mswindows_in_modal_loop;
+}
+
 /*
  * This is a special flavor of the mswindows_need_event function,
  * used while in event pump. Actually, there is only kind of events
@@ -1481,7 +1348,7 @@
   MSG msg;
 
   /* Check if already have one */
-  if (!NILP (mswindows_u_dispatch_event_queue)
+  if (!NILP (dispatch_event_queue)
       || !NILP (mswindows_s_dispatch_event_queue))
     return;
 
@@ -1489,12 +1356,14 @@
   if (!badly_p)
     return;
 
-  /* We do not check the _u_ queue, because timers go to _s_ */
+  /* We do not check the user queue, because timers go to _s_ */
   while (NILP (mswindows_s_dispatch_event_queue))
     {
       /* We'll deadlock if go waiting */
       if (mswindows_pending_timers_count == 0)
- invalid_operation ("Deadlock due to an attempt to call next-event in a wrong context", Qunbound);
+	invalid_operation
+	  ("Deadlock due to an attempt to call next-event in a wrong context",
+	   Qunbound);
 
       /* Fetch and dispatch any pending timers */
       if (qxeGetMessage (&msg, NULL, WM_TIMER, WM_TIMER) > 0)
@@ -1512,7 +1381,7 @@
 static void
 mswindows_need_event (int badly_p)
 {
-  while (NILP (mswindows_u_dispatch_event_queue)
+  while (NILP (dispatch_event_queue)
 	 && NILP (mswindows_s_dispatch_event_queue))
     {
 #ifdef CYGWIN
@@ -1555,14 +1424,15 @@
 	    {
 #ifdef HAVE_TTY
 	      /* Look for a TTY event */
-	      for (i = 0; i < MAXDESC-1; i++)
+	      for (i = 0; i < MAXDESC; i++)
 		{
 		  /* To avoid race conditions (among other things, an infinite
 		     loop when called from Fdiscard_input()), we must return
 		     user events ahead of process events. */
 		  if (FD_ISSET (i, &temp_mask) && FD_ISSET (i, &tty_only_mask))
 		    {
-		      struct console *c = tty_find_console_from_fd (i);
+		      struct console *c =
+			find_tty_or_stream_console_from_fd (i);
 		      Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
 		      Lisp_Event *event = XEVENT (emacs_event);
 		      
@@ -1576,14 +1446,14 @@
 		}
 #endif
 	      /* Look for a process event */
-	      for (i = 0; i < MAXDESC-1; i++)
+	      for (i = 0; i < MAXDESC; i++)
 		{
 		  if (FD_ISSET (i, &temp_mask))
 		    {
 		      if (FD_ISSET (i, &process_only_mask))
 			{
 			  Lisp_Process *p =
-			    get_process_from_usid (FD_TO_USID(i));
+			    get_process_from_usid (FD_TO_USID (i));
 
 			  mswindows_enqueue_process_event (p);
 			}
@@ -1605,12 +1475,12 @@
 	  if (errno != EINTR)
 	    {
 	      /* something bad happened */
-	      assert(0);
+	      assert (0);
 	    }
 	}
       else
 	{
-	  assert(0);
+	  assert (0);
 	}
 #else /* not CYGWIN */
       /* Now try getting a message or process event */
@@ -1747,42 +1617,84 @@
       else
 	{
 	  int ix = active - WAIT_OBJECT_0;
-	  /* First, try to find which process' output has signaled */
-	  Lisp_Process *p =
-	    get_process_from_usid (HANDLE_TO_USID
-				   (mswindows_waitable_handles[ix]));
-	  if (p != NULL)
-	    {
-	      /* Found a signaled process input handle */
-	      mswindows_enqueue_process_event (p);
-	    }
-	  else
+
+	  /* look for a stream console event; see
+	     emacs_mswindows_select_console below. */
+	  LIST_LOOP_3 (porca_troia, Vconsole_list, vcontail)
 	    {
-	      /* None. This means that the process handle itself has signaled.
-		 Remove the handle from the wait vector, and make status_notify
-		 note the exited process.  First find the process object if 
-	         possible. */
-	      LIST_LOOP_3 (vaffanculo, Vprocess_list, vproctail)
-		if (get_nt_process_handle (XPROCESS (vaffanculo)) ==
-		    mswindows_waitable_handles [ix])
-		  break;
-	      mswindows_waitable_handles [ix] =
-		mswindows_waitable_handles [--mswindows_waitable_count];
-	      kick_status_notify ();
-	      /* We need to return a process event here so that
-		 (1) accept-process-output will return when called on this
-		 process, and (2) status notifications will happen in
-		 accept-process-output, sleep-for, and sit-for. */
-	      if (!NILP (vproctail))
-		  mswindows_enqueue_process_event (XPROCESS (vaffanculo));
+	      struct console *con = XCONSOLE (porca_troia);
+
+	      if (CONSOLE_STREAM_P (con))
+		{
+		  Lisp_Object instr = CONSOLE_STREAM_DATA (con)->instream;
+		  if (!NILP (instr) && !UNBOUNDP (instr) &&
+		      get_ntpipe_input_stream_waitable (XLSTREAM (instr)) ==
+		      mswindows_waitable_handles [ix])
+		    {
+		      Ichar ch = Lstream_get_ichar (XLSTREAM (instr));
+		      if (ch < 0)
+			{
+			  /* deleting the console might not be safe right now
+			     ... */
+			  enqueue_magic_eval_event (io_error_delete_console,
+						    porca_troia);
+			  /* but we definitely need to unselect it to avoid
+			     infinite loops reading EOF's */
+			  Fconsole_disable_input (porca_troia);
+			  mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
+			}
+		      else
+			{
+			  Lisp_Object event = Fmake_event (Qnil, Qnil);
+			  /* Here we really do want to set the
+			     use_console_meta_flag because the char is from the
+			     TTY. */
+			  character_to_event (ch, XEVENT (event), con, 1, 1);
+			  XSET_EVENT_CHANNEL (event, porca_troia);
+			  enqueue_dispatch_event (event);
+			}
+		      break;
+		    }
+		}
+	    }
+
+	  if (NILP (vcontail))
+	    { /* no stream console event, look for process event */
+	      /* First, try to find which process' output has signaled */
+	      Lisp_Process *p =
+		get_process_from_usid (HANDLE_TO_USID
+				       (mswindows_waitable_handles[ix]));
+	      if (p != NULL)
+		/* Found a signaled process input handle */
+		mswindows_enqueue_process_event (p);
 	      else
 		{
-		  /* abort (); */
-		  /* #### FUCKME!  When can this happen?  I hit this abort()
-		     when I tried enabling it. */
-		  /* Have to return something: there may be no accompanying
-		     process event */
-		  mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
+		  /* None. This means that the process handle itself has
+		     signaled.  Remove the handle from the wait vector, and
+		     make status_notify note the exited process.  First
+		     find the process object if possible. */
+		  LIST_LOOP_3 (vaffanculo, Vprocess_list, vproctail)
+		    if (get_nt_process_handle (XPROCESS (vaffanculo)) ==
+			mswindows_waitable_handles [ix])
+		      break;
+		  mswindows_waitable_handles [ix] =
+		    mswindows_waitable_handles [--mswindows_waitable_count];
+		  kick_status_notify ();
+		  /* We need to return a process event here so that (1)
+		     accept-process-output will return when called on this
+		     process, and (2) status notifications will happen in
+		     accept-process-output, sleep-for, and sit-for. */
+		  if (!NILP (vproctail))
+		    mswindows_enqueue_process_event (XPROCESS (vaffanculo));
+		  else
+		    {
+		      /* abort (); */
+		      /* #### FUCKME!  When can this happen?  I hit this
+			 abort() when I tried enabling it. */
+		      /* Have to return something: there may be no
+			 accompanying process event */
+		      mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
+		    }
 		}
 	    }
 	}
@@ -1801,26 +1713,16 @@
 mswindows_wm_timer_callback (HWND hwnd, UINT umsg, UINT id_timer, DWORD dwtime)
 {
   Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
-  Lisp_Event *event = XEVENT (emacs_event);
 
   if (KillTimer (NULL, id_timer))
     --mswindows_pending_timers_count;
 
-#ifdef USE_KKCC
   XSET_EVENT_CHANNEL (emacs_event, Qnil);
   XSET_EVENT_TIMESTAMP (emacs_event, dwtime);
   XSET_EVENT_TYPE (emacs_event, timeout_event);
-  XSET_TIMEOUT_DATA_INTERVAL_ID (XEVENT_DATA(emacs_event), id_timer);
-  XSET_TIMEOUT_DATA_FUNCTION (XEVENT_DATA(emacs_event), Qnil);
-  XSET_TIMEOUT_DATA_OBJECT (XEVENT_DATA(emacs_event), Qnil);
-#else /* not USE_KKCC */
-  event->channel = Qnil;
-  event->timestamp = dwtime;
-  event->event_type = timeout_event;
-  event->event.timeout.interval_id = id_timer;
-  event->event.timeout.function = Qnil;
-  event->event.timeout.object = Qnil;
-#endif /* not USE_KKCC */
+  XSET_EVENT_TIMEOUT_INTERVAL_ID (emacs_event, id_timer);
+  XSET_EVENT_TIMEOUT_FUNCTION (emacs_event, Qnil);
+  XSET_EVENT_TIMEOUT_OBJECT (emacs_event, Qnil);
 
   mswindows_enqueue_dispatch_event (emacs_event);
 }
@@ -1901,7 +1803,7 @@
   GCPRO1 (obj);
   obj = Feval (XCAR (obj));
 
-  RETURN_UNGCPRO(obj);
+  RETURN_UNGCPRO (obj);
 }
 
 /* Evaluate the supplied string as a sequence of Lisp forms, wrapped in
@@ -1966,7 +1868,7 @@
   Fput(token, QHSZ, make_float ((int)hsz));
   Vdde_advise_items = Fcons (token, Vdde_advise_items);
 
-  RETURN_UNGCPRO(token);
+  RETURN_UNGCPRO (token);
 }
 
 DEFUN("dde-free-advise-item", Fdde_free_advise_item, 1, 1, 0, /*
@@ -2262,29 +2164,17 @@
 	    };
 	  assert (!NILP (event->channel));
 
-#ifdef USE_KKCC
 	  SET_EVENT_TIMESTAMP (event, GetTickCount());
 	  SET_EVENT_TYPE (event, misc_user_event);
-	  XSET_MISC_USER_DATA_BUTTON (EVENT_DATA (event), 1);
-	  XSET_MISC_USER_DATA_MODIFIERS (EVENT_DATA (event), 0);
-	  XSET_MISC_USER_DATA_X (EVENT_DATA (event), -1);
-	  XSET_MISC_USER_DATA_Y (EVENT_DATA (event), -1);
-	  XSET_MISC_USER_DATA_FUNCTION (EVENT_DATA (event),
+	  SET_EVENT_MISC_USER_BUTTON (event, 1);
+	  SET_EVENT_MISC_USER_MODIFIERS (event, 0);
+	  SET_EVENT_MISC_USER_X (event, -1);
+	  SET_EVENT_MISC_USER_Y (event, -1);
+	  SET_EVENT_MISC_USER_FUNCTION (event,
 					Qdragdrop_drop_dispatch);
-	  XSET_MISC_USER_DATA_OBJECT (EVENT_DATA (event),
+	  SET_EVENT_MISC_USER_OBJECT (event,
 				      Fcons (Qdragdrop_URL,
 					    Fcons (l_dndlist, Qnil)));
-#else /* not USE_KKCC */
-	  event->timestamp = GetTickCount();
-	  event->event_type = misc_user_event;
-	  event->event.misc.button = 1;
-	  event->event.misc.modifiers = 0;
-	  event->event.misc.x = -1;
-	  event->event.misc.y = -1;
-	  event->event.misc.function = Qdragdrop_drop_dispatch;
-	  event->event.misc.object = Fcons (Qdragdrop_URL,
-					    Fcons (l_dndlist, Qnil));
-#endif /* not USE_KKCC */
 	  mswindows_enqueue_dispatch_event (emacs_event);
 	  UNGCPRO;
 	  return (HDDEDATA) DDE_FACK;
@@ -2630,8 +2520,9 @@
 LRESULT WINAPI
 mswindows_wnd_proc (HWND hwnd, UINT message_, WPARAM wParam, LPARAM lParam)
 {
-  /* Note: Remember to initialize emacs_event and event before use.
-     This code calls code that can GC. You must GCPRO before calling such code. */
+  /* Note: Remember to initialize emacs_event and event before use.  This
+     code calls code that can GC. You must GCPRO before calling such
+     code. */
   Lisp_Object emacs_event = Qnil;
   Lisp_Object fobj = Qnil;
 
@@ -2801,11 +2692,11 @@
 	  }
 	else	/* Normal keys & modifiers */
 	  {
-	    Ichar quit_ch =
-	      CONSOLE_QUIT_CHAR (XCONSOLE (mswindows_find_console (hwnd)));
 	    POINT pnt = { LOWORD (GetMessagePos()), HIWORD (GetMessagePos()) };
 	    MSG msg, tranmsg;
+#ifdef HAVE_MENUBARS
 	    int potential_accelerator = 0;
+#endif
 	    int got_accelerator = 0;
 	    /* No need to gcpro because the event is already on a
                queue when we retrieve it. */
@@ -2901,27 +2792,9 @@
 		  }
 #endif /* DEBUG_XEMACS */
 
-		/* If a quit char with no modifiers other than control and
-		   shift, then mark it with a fake modifier, which is removed
-		   upon dequeueing the event */
-		if (((quit_ch < ' ' && (mods & XEMACS_MOD_CONTROL)
-		      && DOWNCASE (0, quit_ch + 'a' - 1) ==
-		      DOWNCASE (0, ch))
-		     || (quit_ch >= ' ' && !(mods & XEMACS_MOD_CONTROL)
-			 && DOWNCASE (0, quit_ch) ==
-			 DOWNCASE (0, ch)))
-		    && ((mods_with_shift &
-			 ~(XEMACS_MOD_CONTROL | XEMACS_MOD_SHIFT))
-			== 0))
-		  {
-		    mods_with_quit |= FAKE_MOD_QUIT;
-		    if (mods_with_shift & XEMACS_MOD_SHIFT)
-		      mods_with_quit |= FAKE_MOD_QUIT_CRITICAL;
-		    mswindows_quit_chars_count++;
-		  }
 #ifdef HAVE_MENUBARS
-		else if (potential_accelerator && !got_accelerator &&
-			 mswindows_char_is_accelerator (frame, ch))
+		if (potential_accelerator && !got_accelerator &&
+		    mswindows_char_is_accelerator (frame, ch))
 		  {
 		    got_accelerator = 1;
 		    break;
@@ -3012,8 +2885,8 @@
 				   (received_keys + (tounret - 1) * 2, 2),
 				   C_STRING_ALLOCA, intchar,
 				   Qmswindows_unicode);
-				XEVENT (lastev)->event.key.alt_keychars[i] =
-				  itext_ichar (intchar);
+				XSET_EVENT_KEY_ALT_KEYCHARS
+				  (lastev, i, itext_ichar (intchar));
 			      }
 			  }
 			else
@@ -3050,8 +2923,8 @@
 				   mswindows_locale_to_code_page (lcid),
 				   NULL);
 
-				XEVENT (lastev)->event.key.alt_keychars[i] =
-				  itext_ichar (intchar);
+				XSET_EVENT_KEY_ALT_KEYCHARS
+				  (lastev, i, itext_ichar (intchar));
 				xfree (intchar);
 			      }
 			  }
@@ -3067,7 +2940,7 @@
 			else
 			  altch = 0;
 
-			XEVENT (lastev)->event.key.alt_keychars[i] = altch;
+			XSET_EVENT_KEY_ALT_KEYCHARS (lastev, i, altch);
 		      }
 		  }
 	      }
@@ -3319,23 +3192,13 @@
 	  emacs_event = Fmake_event (Qnil, Qnil);
 	  event = XEVENT(emacs_event);
 
-#ifdef USE_KKCC
 	  XSET_EVENT_CHANNEL (emacs_event,  mswindows_find_frame(hwnd));
 	  XSET_EVENT_TIMESTAMP (emacs_event, GetMessageTime());
 	  XSET_EVENT_TYPE (emacs_event, pointer_motion_event);
-	  XSET_MOTION_DATA_X (XEVENT_DATA (emacs_event),MAKEPOINTS (lParam).x);
-	  XSET_MOTION_DATA_Y (XEVENT_DATA (emacs_event),MAKEPOINTS (lParam).y);
-	  XSET_MOTION_DATA_MODIFIERS (XEVENT_DATA(emacs_event),
+	  XSET_EVENT_MOTION_X (emacs_event,MAKEPOINTS (lParam).x);
+	  XSET_EVENT_MOTION_Y (emacs_event,MAKEPOINTS (lParam).y);
+	  XSET_EVENT_MOTION_MODIFIERS (emacs_event,
                                 mswindows_modifier_state (NULL, wParam, 0));
-#else /* not USE_KKCC */	  
-	  event->channel = mswindows_find_frame (hwnd);
-	  event->timestamp = GetMessageTime ();
-	  event->event_type = pointer_motion_event;
-	  event->event.motion.x = MAKEPOINTS (lParam).x;
-	  event->event.motion.y = MAKEPOINTS (lParam).y;
-	  event->event.motion.modifiers =
-	    mswindows_modifier_state (NULL, wParam, 0);
-#endif /* not USE_KKCC */
 
 	  mswindows_enqueue_dispatch_event (emacs_event);
 	}
@@ -3856,28 +3719,16 @@
 	if (!DragQueryPoint ((HDROP) wParam, &point))
 	  point.x = point.y = -1; /* outside client area */
 
-#ifdef USE_KKCC
 	XSET_EVENT_TYPE (emacs_event, misc_user_event);
 	XSET_EVENT_CHANNEL (emacs_event,  mswindows_find_frame(hwnd));
 	XSET_EVENT_TIMESTAMP (emacs_event, GetMessageTime());
-	XSET_MISC_USER_DATA_BUTTON (XEVENT_DATA (emacs_event), 1);
-	XSET_MISC_USER_DATA_MODIFIERS (XEVENT_DATA (emacs_event),
+	XSET_EVENT_MISC_USER_BUTTON (emacs_event, 1);
+	XSET_EVENT_MISC_USER_MODIFIERS (emacs_event,
               mswindows_modifier_state (NULL, (DWORD) -1, 0));
-	XSET_MISC_USER_DATA_X (XEVENT_DATA (emacs_event), point.x);
-	XSET_MISC_USER_DATA_Y (XEVENT_DATA (emacs_event), point.y);
-	XSET_MISC_USER_DATA_FUNCTION (XEVENT_DATA (emacs_event),
+	XSET_EVENT_MISC_USER_X (emacs_event, point.x);
+	XSET_EVENT_MISC_USER_Y (emacs_event, point.y);
+	XSET_EVENT_MISC_USER_FUNCTION (emacs_event,
 					Qdragdrop_drop_dispatch);
-#else /* not USE_KKCC */
-	event->event_type = misc_user_event;
-	event->channel = mswindows_find_frame (hwnd);
-	event->timestamp = GetMessageTime();
-	event->event.misc.button = 1;		/* #### Should try harder */
-	event->event.misc.modifiers = mswindows_modifier_state (NULL,
-								(DWORD) -1, 0);
-	event->event.misc.x = point.x;
-	event->event.misc.y = point.y;
-	event->event.misc.function = Qdragdrop_drop_dispatch;
-#endif /* not USE_KKCC */
 
 	filecount = qxeDragQueryFile ((HDROP) wParam, 0xffffffff, NULL, 0);
 	for (i = 0; i < filecount; i++)
@@ -4053,12 +3904,8 @@
 
 	DragFinish ((HDROP) wParam);
 
-#ifdef USE_KKCC
-	XSET_MISC_USER_DATA_OBJECT (EVENT_DATA (event),
+	SET_EVENT_MISC_USER_OBJECT (event,
 				    Fcons (Qdragdrop_URL, l_dndlist));
-#else /* not USE_KKCC */
-	event->event.misc.object = Fcons (Qdragdrop_URL, l_dndlist);
-#endif /* not USE_KKCC */
 	mswindows_enqueue_dispatch_event (emacs_event);
 	UNGCPRO;
       }
@@ -4501,27 +4348,30 @@
 		   (TIMERPROC) mswindows_wm_timer_callback);
 }
 
+static int
+remove_timeout_mapper (Lisp_Object ev, void *data)
+{
+  if (XEVENT_TYPE (ev) == timeout_event)
+    {
+      if ((int) data == XEVENT_TIMEOUT_INTERVAL_ID (ev))
+	return 1;
+    }
+
+  return 0;
+}
+
 static void
 emacs_mswindows_remove_timeout (int id)
 {
-  Lisp_Event match_against;
-  Lisp_Object emacs_event;
-
   if (KillTimer (NULL, id))
     --mswindows_pending_timers_count;
 
   /* If there is a dispatch event generated by this
      timeout in the queue, we have to remove it too. */
-#ifdef USE_KKCC
-  SET_EVENT_TYPE(&match_against, timeout_event);
-  XSET_TIMEOUT_DATA_INTERVAL_ID (EVENT_DATA (&match_against), id);
-#else /* not USE_KKCC */
-  match_against.event_type = timeout_event;
-  match_against.event.timeout.interval_id = id;
-#endif /* not USE_KKCC */
-  emacs_event = mswindows_cancel_dispatch_event (&match_against);
-  if (!NILP (emacs_event))
-    Fdeallocate_event(emacs_event);
+  map_event_chain_remove (remove_timeout_mapper,
+			  &mswindows_s_dispatch_event_queue,
+			  &mswindows_s_dispatch_event_queue_tail,
+			  (void *) id, MECR_DEALLOCATE_EVENT);
 }
 
 /* If `user_p' is false, then return whether there are any win32, timeout,
@@ -4537,7 +4387,7 @@
 emacs_mswindows_event_pending_p (int user_p)
 {
   mswindows_need_event (0);
-  return (!NILP (mswindows_u_dispatch_event_queue)
+  return (!NILP (dispatch_event_queue)
 	  || (!user_p && !NILP (mswindows_s_dispatch_event_queue)));
 }
 
@@ -4563,11 +4413,7 @@
 {
 #define FROB(msg) case msg: write_c_string (pstream, "type=" #msg); break
 
-#ifdef USE_KKCC
-  switch (XMAGIC_DATA_MSWINDOWS_EVENT (EVENT_DATA(emacs_event)))
-#else /* not USE_KKCC */
-  switch (EVENT_MSWINDOWS_MAGIC_TYPE (emacs_event))
-#endif /* not USE_KKCC */
+  switch (EVENT_MAGIC_MSWINDOWS_EVENT (emacs_event))
     {
       FROB (XM_BUMPQUEUE);
       FROB (WM_PAINT);
@@ -4590,23 +4436,14 @@
 static int
 emacs_mswindows_compare_magic_event (Lisp_Event *e1, Lisp_Event *e2)
 {
-#ifdef USE_KKCC
-  return (XMAGIC_DATA_MSWINDOWS_EVENT (EVENT_DATA (e1)) ==
-	  XMAGIC_DATA_MSWINDOWS_EVENT (EVENT_DATA (e2)));
-#else /* not USE_KKCC */
-  return (e1->event.magic.underlying_mswindows_event ==
-	  e2->event.magic.underlying_mswindows_event);
-#endif /* not USE_KKCC */
+  return (EVENT_MAGIC_MSWINDOWS_EVENT (e1) ==
+	  EVENT_MAGIC_MSWINDOWS_EVENT (e2));
 }
 
 static Hashcode
 emacs_mswindows_hash_magic_event (Lisp_Event *e)
 {
-#ifdef USE_KKCC
-  return (XMAGIC_DATA_MSWINDOWS_EVENT (EVENT_DATA (e)));
-#else /* not USE_KKCC */
-  return e->event.magic.underlying_mswindows_event;
-#endif /* not USE_KKCC */
+  return (EVENT_MAGIC_MSWINDOWS_EVENT (e));
 }
 
 /*
@@ -4615,11 +4452,7 @@
 static void
 emacs_mswindows_handle_magic_event (Lisp_Event *emacs_event)
 {
-#ifdef USE_KKCC
-  switch (XMAGIC_DATA_MSWINDOWS_EVENT (EVENT_DATA(emacs_event)))
-#else /* not USE_KKCC */
-  switch (EVENT_MSWINDOWS_MAGIC_TYPE (emacs_event))
-#endif /* not USE_KKCC */
+  switch (EVENT_MAGIC_MSWINDOWS_EVENT (emacs_event))
     {
     case XM_BUMPQUEUE:
       break;
@@ -4637,12 +4470,8 @@
       {
 	Lisp_Object frame = EVENT_CHANNEL (emacs_event);
 	struct frame *f = XFRAME (frame);
-#ifdef USE_KKCC
-	int in_p = (XMAGIC_DATA_MSWINDOWS_EVENT (EVENT_DATA(emacs_event))
+	int in_p = (EVENT_MAGIC_MSWINDOWS_EVENT (emacs_event)
 		    == WM_SETFOCUS);
-#else /* not USE_KKCC */
-	int in_p = (EVENT_MSWINDOWS_MAGIC_TYPE (emacs_event) == WM_SETFOCUS);
-#endif /* not USE_KKCC */
 	Lisp_Object conser;
 	struct gcpro gcpro1;
 
@@ -4665,11 +4494,7 @@
     case XM_UNMAPFRAME:
       {
 	Lisp_Object frame = EVENT_CHANNEL (emacs_event);
-#ifdef USE_KKCC
-	va_run_hook_with_args (XMAGIC_DATA_MSWINDOWS_EVENT (EVENT_DATA(emacs_event))
-#else /* not USE_KKCC */
-	va_run_hook_with_args (EVENT_MSWINDOWS_MAGIC_TYPE (emacs_event)
-#endif /* not USE_KKCC */
+	va_run_hook_with_args (EVENT_MAGIC_MSWINDOWS_EVENT (emacs_event)
 			       == XM_MAPFRAME ?
 			       Qmap_frame_hook : Qunmap_frame_hook,
 			       1, frame);
@@ -4806,6 +4631,30 @@
     return; /* mswindows consoles are automatically selected */
 
   event_stream_unixoid_select_console (con);
+#else
+#if 0
+  /* This is an attempt to get `xemacs -batch -l dunnet' to work.
+     Doesn't currently work and fucks other things up. */
+  if (CONSOLE_STREAM_P (con) &&
+      !UNBOUNDP (CONSOLE_STREAM_DATA (con)->instream))
+    {
+      HANDLE h =
+	(HANDLE) _get_osfhandle (fileno (CONSOLE_STREAM_DATA (con)->in));
+      if (PeekNamedPipe (h, 0, 0, 0, 0, 0))
+	{
+	  Lisp_Object lstr = make_ntpipe_input_stream (h, 0);
+	  HANDLE hwait = get_ntpipe_input_stream_waitable (XLSTREAM (lstr));
+
+	  if (!add_waitable_handle (hwait))
+	    invalid_operation ("Too many active processes",
+			       wrap_console (con));
+	  CONSOLE_STREAM_DATA (con)->instream = lstr;
+	}
+      else
+	/* Unable to select on this stream */
+	CONSOLE_STREAM_DATA (con)->instream = Qunbound;
+    }
+#endif /* 0 */
 #endif
 }
 
@@ -4817,56 +4666,21 @@
     return; /* mswindows consoles are automatically selected */
 
   event_stream_unixoid_unselect_console (con);
-#endif
-}
-
-static void
-emacs_mswindows_quit_p (void)
-{
-  /* Quit cannot happen in modal loop: all program
-     input is dedicated to Windows. */
-  if (mswindows_in_modal_loop)
-    return;
-
-  mswindows_quit_chars_count = 0;
-  /* Drain windows queue.  This sets up number of quit characters in
-     the queue. */
-  mswindows_drain_windows_queue ();
-
-  if (mswindows_quit_chars_count > 0)
+#else
+#if 0 /* see above */
+  if (CONSOLE_STREAM_P (con) &&
+      !UNBOUNDP (CONSOLE_STREAM_DATA (con)->instream))
     {
-      /* Yes there's a hidden one... Throw it away */
-      Lisp_Event match_against;
-      Lisp_Object emacs_event;
-      int critical_p = 0;
-
-#ifdef USE_KKCC
-      SET_EVENT_TYPE (&match_against, key_press_event);
-      XSET_KEY_DATA_MODIFIERS (EVENT_DATA (&match_against), FAKE_MOD_QUIT);
-#else /* not USE_KKCC */
-      match_against.event_type = key_press_event;
-      match_against.event.key.modifiers = FAKE_MOD_QUIT;
-#endif /* not USE_KKCC */
-
-      while (mswindows_quit_chars_count > 0)
-	{
-	  emacs_event = mswindows_cancel_dispatch_event (&match_against);
-	  assert (!NILP (emacs_event));
-
-#ifdef USE_KKCC
-	  if (XKEY_DATA_MODIFIERS (XEVENT_DATA(emacs_event)) &
-#else /* not USE_KKCC */
-	  if (XEVENT (emacs_event)->event.key.modifiers &
-#endif /* not USE_KKCC */
-	      FAKE_MOD_QUIT_CRITICAL)
-	    critical_p = 1;
-
-	  Fdeallocate_event (emacs_event);
-	  mswindows_quit_chars_count--;
-	}
-
-      Vquit_flag = critical_p ? Qcritical : Qt;
+      Lisp_Object instr = CONSOLE_STREAM_DATA (con)->instream;
+      HANDLE hwait;
+
+      assert (!NILP (instr));
+      hwait = get_ntpipe_input_stream_waitable (XLSTREAM (instr));
+
+      remove_waitable_handle (hwait);
     }
+#endif /* 0 */
+#endif
 }
 
 static void
@@ -5334,10 +5148,9 @@
   mswindows_in_modal_loop = 0;
   mswindows_pending_timers_count = 0;
 
-  mswindows_event_stream = xnew (struct event_stream);
+  mswindows_event_stream = xnew_and_zero (struct event_stream);
 
   mswindows_event_stream->event_pending_p 	= emacs_mswindows_event_pending_p;
-  mswindows_event_stream->force_event_pending = 0;
   mswindows_event_stream->next_event_cb		= emacs_mswindows_next_event;
   mswindows_event_stream->handle_magic_event_cb = emacs_mswindows_handle_magic_event;
   mswindows_event_stream->format_magic_event_cb = emacs_mswindows_format_magic_event;
@@ -5345,7 +5158,8 @@
   mswindows_event_stream->hash_magic_event_cb   = emacs_mswindows_hash_magic_event;
   mswindows_event_stream->add_timeout_cb 	= emacs_mswindows_add_timeout;
   mswindows_event_stream->remove_timeout_cb 	= emacs_mswindows_remove_timeout;
-  mswindows_event_stream->quit_p_cb		= emacs_mswindows_quit_p;
+  mswindows_event_stream->drain_queue_cb	= emacs_mswindows_drain_queue;
+  mswindows_event_stream->quit_check_disallowed_p_cb = emacs_mswindows_quit_check_disallowed_p;
   mswindows_event_stream->select_console_cb 	= emacs_mswindows_select_console;
   mswindows_event_stream->unselect_console_cb	= emacs_mswindows_unselect_console;
   mswindows_event_stream->select_process_cb 	= emacs_mswindows_select_process;
@@ -5363,15 +5177,10 @@
 {
   reinit_vars_of_event_mswindows ();
 
-  mswindows_u_dispatch_event_queue = Qnil;
-  staticpro (&mswindows_u_dispatch_event_queue);
-  mswindows_u_dispatch_event_queue_tail = Qnil;
-  dump_add_root_object (&mswindows_u_dispatch_event_queue_tail);
-
   mswindows_s_dispatch_event_queue = Qnil;
   staticpro (&mswindows_s_dispatch_event_queue);
   mswindows_s_dispatch_event_queue_tail = Qnil;
-  dump_add_root_object (&mswindows_s_dispatch_event_queue_tail);
+  dump_add_root_lisp_object (&mswindows_s_dispatch_event_queue_tail);
 
   mswindows_error_caught_in_modal_loop = 0;