Mercurial > hg > xemacs-beta
annotate src/event-Xt.c @ 5127:a9c41067dd88 ben-lisp-object
more cleanups, terminology clarification, lots of doc work
-------------------- ChangeLog entries follow: --------------------
man/ChangeLog addition:
2010-03-05 Ben Wing <ben@xemacs.org>
* internals/internals.texi (Introduction to Allocation):
* internals/internals.texi (Integers and Characters):
* internals/internals.texi (Allocation from Frob Blocks):
* internals/internals.texi (lrecords):
* internals/internals.texi (Low-level allocation):
Rewrite section on allocation of Lisp objects to reflect the new
reality. Remove references to nonexistent XSETINT and XSETCHAR.
modules/ChangeLog addition:
2010-03-05 Ben Wing <ben@xemacs.org>
* postgresql/postgresql.c (allocate_pgconn):
* postgresql/postgresql.c (allocate_pgresult):
* postgresql/postgresql.h (struct Lisp_PGconn):
* postgresql/postgresql.h (struct Lisp_PGresult):
* ldap/eldap.c (allocate_ldap):
* ldap/eldap.h (struct Lisp_LDAP):
Same changes as in src/ dir. See large log there in ChangeLog,
but basically:
ALLOC_LISP_OBJECT -> ALLOC_NORMAL_LISP_OBJECT
LISP_OBJECT_HEADER -> NORMAL_LISP_OBJECT_HEADER
../hlo/src/ChangeLog addition:
2010-03-05 Ben Wing <ben@xemacs.org>
* alloc.c:
* alloc.c (old_alloc_sized_lcrecord):
* alloc.c (very_old_free_lcrecord):
* alloc.c (copy_lisp_object):
* alloc.c (zero_sized_lisp_object):
* alloc.c (zero_nonsized_lisp_object):
* alloc.c (lisp_object_storage_size):
* alloc.c (free_normal_lisp_object):
* alloc.c (FREE_FIXED_TYPE_WHEN_NOT_IN_GC):
* alloc.c (ALLOC_FROB_BLOCK_LISP_OBJECT):
* alloc.c (Fcons):
* alloc.c (noseeum_cons):
* alloc.c (make_float):
* alloc.c (make_bignum):
* alloc.c (make_bignum_bg):
* alloc.c (make_ratio):
* alloc.c (make_ratio_bg):
* alloc.c (make_ratio_rt):
* alloc.c (make_bigfloat):
* alloc.c (make_bigfloat_bf):
* alloc.c (size_vector):
* alloc.c (make_compiled_function):
* alloc.c (Fmake_symbol):
* alloc.c (allocate_extent):
* alloc.c (allocate_event):
* 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 (Fmake_marker):
* alloc.c (noseeum_make_marker):
* alloc.c (size_string_direct_data):
* alloc.c (make_uninit_string):
* alloc.c (make_string_nocopy):
* alloc.c (mark_lcrecord_list):
* alloc.c (alloc_managed_lcrecord):
* alloc.c (free_managed_lcrecord):
* alloc.c (sweep_lcrecords_1):
* alloc.c (malloced_storage_size):
* buffer.c (allocate_buffer):
* buffer.c (compute_buffer_usage):
* buffer.c (DEFVAR_BUFFER_LOCAL_1):
* buffer.c (nuke_all_buffer_slots):
* buffer.c (common_init_complex_vars_of_buffer):
* buffer.h (struct buffer_text):
* buffer.h (struct buffer):
* bytecode.c:
* bytecode.c (make_compiled_function_args):
* bytecode.c (size_compiled_function_args):
* bytecode.h (struct compiled_function_args):
* casetab.c (allocate_case_table):
* casetab.h (struct Lisp_Case_Table):
* charset.h (struct Lisp_Charset):
* chartab.c (fill_char_table):
* chartab.c (Fmake_char_table):
* chartab.c (make_char_table_entry):
* chartab.c (copy_char_table_entry):
* chartab.c (Fcopy_char_table):
* chartab.c (put_char_table):
* chartab.h (struct Lisp_Char_Table_Entry):
* chartab.h (struct Lisp_Char_Table):
* console-gtk-impl.h (struct gtk_device):
* console-gtk-impl.h (struct gtk_frame):
* console-impl.h (struct console):
* console-msw-impl.h (struct Lisp_Devmode):
* console-msw-impl.h (struct mswindows_device):
* console-msw-impl.h (struct msprinter_device):
* console-msw-impl.h (struct mswindows_frame):
* console-msw-impl.h (struct mswindows_dialog_id):
* console-stream-impl.h (struct stream_console):
* console-stream.c (stream_init_console):
* console-tty-impl.h (struct tty_console):
* console-tty-impl.h (struct tty_device):
* console-tty.c (allocate_tty_console_struct):
* console-x-impl.h (struct x_device):
* console-x-impl.h (struct x_frame):
* console.c (allocate_console):
* console.c (nuke_all_console_slots):
* console.c (DEFVAR_CONSOLE_LOCAL_1):
* console.c (common_init_complex_vars_of_console):
* data.c (make_weak_list):
* data.c (make_weak_box):
* data.c (make_ephemeron):
* database.c:
* database.c (struct Lisp_Database):
* database.c (allocate_database):
* database.c (finalize_database):
* device-gtk.c (allocate_gtk_device_struct):
* device-impl.h (struct device):
* device-msw.c:
* device-msw.c (mswindows_init_device):
* device-msw.c (msprinter_init_device):
* device-msw.c (finalize_devmode):
* device-msw.c (allocate_devmode):
* device-tty.c (allocate_tty_device_struct):
* device-x.c (allocate_x_device_struct):
* device.c:
* device.c (nuke_all_device_slots):
* device.c (allocate_device):
* dialog-msw.c (handle_question_dialog_box):
* elhash.c:
* elhash.c (struct Lisp_Hash_Table):
* elhash.c (finalize_hash_table):
* elhash.c (make_general_lisp_hash_table):
* elhash.c (Fcopy_hash_table):
* elhash.h (htentry):
* emacs.c (main_1):
* eval.c:
* eval.c (size_multiple_value):
* event-stream.c (finalize_command_builder):
* event-stream.c (allocate_command_builder):
* event-stream.c (free_command_builder):
* event-stream.c (event_stream_generate_wakeup):
* event-stream.c (event_stream_resignal_wakeup):
* event-stream.c (event_stream_disable_wakeup):
* event-stream.c (event_stream_wakeup_pending_p):
* events.h (struct Lisp_Timeout):
* events.h (struct command_builder):
* extents-impl.h:
* extents-impl.h (struct extent_auxiliary):
* extents-impl.h (struct extent_info):
* extents-impl.h (set_extent_no_chase_aux_field):
* extents-impl.h (set_extent_no_chase_normal_field):
* extents.c:
* extents.c (gap_array_marker):
* extents.c (gap_array):
* extents.c (extent_list_marker):
* extents.c (extent_list):
* extents.c (stack_of_extents):
* extents.c (gap_array_make_marker):
* extents.c (extent_list_make_marker):
* extents.c (allocate_extent_list):
* extents.c (SLOT):
* extents.c (mark_extent_auxiliary):
* extents.c (allocate_extent_auxiliary):
* extents.c (attach_extent_auxiliary):
* extents.c (size_gap_array):
* extents.c (finalize_extent_info):
* extents.c (allocate_extent_info):
* extents.c (uninit_buffer_extents):
* extents.c (allocate_soe):
* extents.c (copy_extent):
* extents.c (vars_of_extents):
* extents.h:
* faces.c (allocate_face):
* faces.h (struct Lisp_Face):
* faces.h (struct face_cachel):
* file-coding.c:
* file-coding.c (finalize_coding_system):
* file-coding.c (sizeof_coding_system):
* file-coding.c (Fcopy_coding_system):
* file-coding.h (struct Lisp_Coding_System):
* file-coding.h (MARKED_SLOT):
* fns.c (size_bit_vector):
* font-mgr.c:
* font-mgr.c (finalize_fc_pattern):
* font-mgr.c (print_fc_pattern):
* font-mgr.c (Ffc_pattern_p):
* font-mgr.c (Ffc_pattern_create):
* font-mgr.c (Ffc_name_parse):
* font-mgr.c (Ffc_name_unparse):
* font-mgr.c (Ffc_pattern_duplicate):
* font-mgr.c (Ffc_pattern_add):
* font-mgr.c (Ffc_pattern_del):
* font-mgr.c (Ffc_pattern_get):
* font-mgr.c (fc_config_create_using):
* font-mgr.c (fc_strlist_to_lisp_using):
* font-mgr.c (fontset_to_list):
* font-mgr.c (Ffc_config_p):
* font-mgr.c (Ffc_config_up_to_date):
* font-mgr.c (Ffc_config_build_fonts):
* font-mgr.c (Ffc_config_get_cache):
* font-mgr.c (Ffc_config_get_fonts):
* font-mgr.c (Ffc_config_set_current):
* font-mgr.c (Ffc_config_get_blanks):
* font-mgr.c (Ffc_config_get_rescan_interval):
* font-mgr.c (Ffc_config_set_rescan_interval):
* font-mgr.c (Ffc_config_app_font_add_file):
* font-mgr.c (Ffc_config_app_font_add_dir):
* font-mgr.c (Ffc_config_app_font_clear):
* font-mgr.c (size):
* font-mgr.c (Ffc_config_substitute):
* font-mgr.c (Ffc_font_render_prepare):
* font-mgr.c (Ffc_font_match):
* font-mgr.c (Ffc_font_sort):
* font-mgr.c (finalize_fc_config):
* font-mgr.c (print_fc_config):
* font-mgr.h:
* font-mgr.h (struct fc_pattern):
* font-mgr.h (XFC_PATTERN):
* font-mgr.h (struct fc_config):
* font-mgr.h (XFC_CONFIG):
* frame-gtk.c (allocate_gtk_frame_struct):
* frame-impl.h (struct frame):
* frame-msw.c (mswindows_init_frame_1):
* frame-x.c (allocate_x_frame_struct):
* frame.c (nuke_all_frame_slots):
* frame.c (allocate_frame_core):
* gc.c:
* gc.c (GC_CHECK_NOT_FREE):
* glyphs.c (finalize_image_instance):
* glyphs.c (allocate_image_instance):
* glyphs.c (Fcolorize_image_instance):
* glyphs.c (allocate_glyph):
* glyphs.c (unmap_subwindow_instance_cache_mapper):
* glyphs.c (register_ignored_expose):
* glyphs.h (struct Lisp_Image_Instance):
* glyphs.h (struct Lisp_Glyph):
* glyphs.h (struct glyph_cachel):
* glyphs.h (struct expose_ignore):
* gui.c (allocate_gui_item):
* gui.h (struct Lisp_Gui_Item):
* keymap.c (struct Lisp_Keymap):
* keymap.c (make_keymap):
* lisp.h:
* lisp.h (struct Lisp_String_Direct_Data):
* lisp.h (struct Lisp_String_Indirect_Data):
* lisp.h (struct Lisp_Vector):
* lisp.h (struct Lisp_Bit_Vector):
* lisp.h (DECLARE_INLINE_LISP_BIT_VECTOR):
* lisp.h (struct weak_box):
* lisp.h (struct ephemeron):
* lisp.h (struct weak_list):
* lrecord.h:
* lrecord.h (struct lrecord_implementation):
* lrecord.h (MC_ALLOC_CALL_FINALIZER):
* lrecord.h (struct lcrecord_list):
* lstream.c (finalize_lstream):
* lstream.c (sizeof_lstream):
* lstream.c (Lstream_new):
* lstream.c (Lstream_delete):
* lstream.h (struct lstream):
* marker.c:
* marker.c (finalize_marker):
* marker.c (compute_buffer_marker_usage):
* mule-charset.c:
* mule-charset.c (make_charset):
* mule-charset.c (compute_charset_usage):
* objects-impl.h (struct Lisp_Color_Instance):
* objects-impl.h (struct Lisp_Font_Instance):
* objects-tty-impl.h (struct tty_color_instance_data):
* objects-tty-impl.h (struct tty_font_instance_data):
* objects-tty.c (tty_initialize_color_instance):
* objects-tty.c (tty_initialize_font_instance):
* objects.c (finalize_color_instance):
* objects.c (Fmake_color_instance):
* objects.c (finalize_font_instance):
* objects.c (Fmake_font_instance):
* objects.c (reinit_vars_of_objects):
* opaque.c:
* opaque.c (sizeof_opaque):
* opaque.c (make_opaque_ptr):
* opaque.c (free_opaque_ptr):
* opaque.h:
* opaque.h (Lisp_Opaque):
* opaque.h (Lisp_Opaque_Ptr):
* print.c (printing_unreadable_lcrecord):
* print.c (external_object_printer):
* print.c (debug_p4):
* process.c (finalize_process):
* process.c (make_process_internal):
* procimpl.h (struct Lisp_Process):
* rangetab.c (Fmake_range_table):
* rangetab.c (Fcopy_range_table):
* rangetab.h (struct Lisp_Range_Table):
* scrollbar.c:
* scrollbar.c (create_scrollbar_instance):
* scrollbar.c (compute_scrollbar_instance_usage):
* scrollbar.h (struct scrollbar_instance):
* specifier.c (finalize_specifier):
* specifier.c (sizeof_specifier):
* specifier.c (set_specifier_caching):
* specifier.h (struct Lisp_Specifier):
* specifier.h (struct specifier_caching):
* symeval.h:
* symeval.h (SYMBOL_VALUE_MAGIC_P):
* symeval.h (DEFVAR_SYMVAL_FWD):
* symsinit.h:
* syntax.c (init_buffer_syntax_cache):
* syntax.h (struct syntax_cache):
* toolbar.c:
* toolbar.c (allocate_toolbar_button):
* toolbar.c (update_toolbar_button):
* toolbar.h (struct toolbar_button):
* tooltalk.c (struct Lisp_Tooltalk_Message):
* tooltalk.c (make_tooltalk_message):
* tooltalk.c (struct Lisp_Tooltalk_Pattern):
* tooltalk.c (make_tooltalk_pattern):
* ui-gtk.c:
* ui-gtk.c (allocate_ffi_data):
* ui-gtk.c (emacs_gtk_object_finalizer):
* ui-gtk.c (allocate_emacs_gtk_object_data):
* ui-gtk.c (allocate_emacs_gtk_boxed_data):
* ui-gtk.h:
* window-impl.h (struct window):
* window-impl.h (struct window_mirror):
* window.c (finalize_window):
* window.c (allocate_window):
* window.c (new_window_mirror):
* window.c (mark_window_as_deleted):
* window.c (make_dummy_parent):
* window.c (compute_window_mirror_usage):
* window.c (compute_window_usage):
Overall point of this change and previous ones in this repository:
(1) Introduce new, clearer terminology: everything other than int
or char is a "record" object, which comes in two types: "normal
objects" and "frob-block objects". Fix up all places that
referred to frob-block objects as "simple", "basic", etc.
(2) Provide an advertised interface for doing operations on Lisp
objects, including creating new types, that is clean and
consistent in its naming, uses the above-referenced terms and
avoids referencing "lrecords", "old lcrecords", etc., which should
hide under the surface.
(3) Make the size_in_bytes and finalizer methods take a
Lisp_Object rather than a void * for consistency with other methods.
(4) Separate finalizer method into finalizer and disksaver, so
that normal finalize methods don't have to worry about disksaving.
Other specifics:
(1) Renaming:
LISP_OBJECT_HEADER -> NORMAL_LISP_OBJECT_HEADER
ALLOC_LISP_OBJECT -> ALLOC_NORMAL_LISP_OBJECT
implementation->basic_p -> implementation->frob_block_p
ALLOCATE_FIXED_TYPE_AND_SET_IMPL -> ALLOC_FROB_BLOCK_LISP_OBJECT
*FCCONFIG*, wrap_fcconfig -> *FC_CONFIG*, wrap_fc_config
*FCPATTERN*, wrap_fcpattern -> *FC_PATTERN*, wrap_fc_pattern
(the last two changes make the naming of these macros consistent
with the naming of all other macros, since the objects are named
fc-config and fc-pattern with a hyphen)
(2) Lots of documentation fixes in lrecord.h.
(3) Eliminate macros for copying, freeing, zeroing objects, getting
their storage size. Instead, new functions:
zero_sized_lisp_object()
zero_nonsized_lisp_object()
lisp_object_storage_size()
free_normal_lisp_object()
(copy_lisp_object() already exists)
LISP_OBJECT_FROB_BLOCK_P() (actually a macro)
Eliminated:
free_lrecord()
zero_lrecord()
copy_lrecord()
copy_sized_lrecord()
old_copy_lcrecord()
old_copy_sized_lcrecord()
old_zero_lcrecord()
old_zero_sized_lcrecord()
LISP_OBJECT_STORAGE_SIZE()
COPY_SIZED_LISP_OBJECT()
COPY_SIZED_LCRECORD()
COPY_LISP_OBJECT()
ZERO_LISP_OBJECT()
FREE_LISP_OBJECT()
(4) Catch the remaining places where lrecord stuff was used directly
and use the advertised interface, e.g. alloc_sized_lrecord() ->
ALLOC_SIZED_LISP_OBJECT().
(5) Make certain statically-declared pseudo-objects
(buffer_local_flags, console_local_flags) have their lheader
initialized correctly, so things like copy_lisp_object() can work
on them. Make extent_auxiliary_defaults a proper heap object
Vextent_auxiliary_defaults, and make extent auxiliaries dumpable
so that this object can be dumped. allocate_extent_auxiliary()
now just creates the object, and attach_extent_auxiliary()
creates an extent auxiliary and attaches to an extent, like the
old allocate_extent_auxiliary().
(6) Create EXTENT_AUXILIARY_SLOTS macro, similar to the foo-slots.h
files but in a macro instead of a file. The purpose is to avoid
duplication when iterating over all the slots in an extent auxiliary.
Use it.
(7) In lstream.c, don't zero out object after allocation because
allocation routines take care of this.
(8) In marker.c, fix a mistake in computing marker overhead.
(9) In print.c, clean up printing_unreadable_lcrecord(),
external_object_printer() to avoid lots of ifdef NEW_GC's.
(10) Separate toolbar-button allocation into a separate
allocate_toolbar_button() function for use in the example code
in lrecord.h.
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Fri, 05 Mar 2010 04:08:17 -0600 |
parents | a7a237f818d9 |
children | 5502045ec510 8b2f75cecb89 |
rev | line source |
---|---|
428 | 1 /* The event_stream interface for X11 with Xt, and/or tty frames. |
2 Copyright (C) 1991-5, 1997 Free Software Foundation, Inc. | |
3 Copyright (C) 1995 Sun Microsystems, Inc. | |
5018
a7a237f818d9
add comment about simultaneous window-system consoles
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
4 Copyright (C) 1996, 2001, 2002, 2003, 2010 Ben Wing. |
428 | 5 |
6 This file is part of XEmacs. | |
7 | |
8 XEmacs is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
10 Free Software Foundation; either version 2, or (at your option) any | |
11 later version. | |
12 | |
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with XEmacs; see the file COPYING. If not, write to | |
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
21 Boston, MA 02111-1307, USA. */ | |
22 | |
23 /* Synched up with: Not in FSF. */ | |
24 | |
5018
a7a237f818d9
add comment about simultaneous window-system consoles
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
25 /* NOTE: It would be possible to fix things so that all of GTK, Windows, X, |
a7a237f818d9
add comment about simultaneous window-system consoles
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
26 TTY and stream can have consoles at the same time. We already do lots |
a7a237f818d9
add comment about simultaneous window-system consoles
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
27 of combinations. Basically, either call select() directly or some |
a7a237f818d9
add comment about simultaneous window-system consoles
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
28 interface onto it, and select() over all the filedescs, including the |
a7a237f818d9
add comment about simultaneous window-system consoles
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
29 X and GTK socket, and under Cygwin, the Windows device. Then for whichever |
a7a237f818d9
add comment about simultaneous window-system consoles
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
30 filedesc there's an event, call the appropriate window-system-specific |
a7a237f818d9
add comment about simultaneous window-system consoles
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
31 method to pull the event(s) and store onto the dispatch queue. --ben */ |
a7a237f818d9
add comment about simultaneous window-system consoles
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
32 |
428 | 33 #include <config.h> |
34 #include "lisp.h" | |
35 | |
36 #include "blocktype.h" | |
771 | 37 #include "charset.h" |
428 | 38 #include "console.h" |
872 | 39 #include "device-impl.h" |
800 | 40 #include "elhash.h" |
428 | 41 #include "events.h" |
800 | 42 #include "file-coding.h" |
872 | 43 #include "frame-impl.h" |
800 | 44 #include "glyphs.h" |
45 #include "lstream.h" | |
428 | 46 #include "process.h" |
47 #include "redisplay.h" | |
800 | 48 #include "window.h" |
49 | |
50 #include "console-tty.h" | |
51 | |
872 | 52 #include "console-x-impl.h" |
800 | 53 #include "objects-x.h" |
54 #include "../lwlib/lwlib.h" | |
55 #include "EmacsFrame.h" | |
56 | |
57 #include "sysproc.h" /* for MAXDESC */ | |
428 | 58 #include "systime.h" |
59 | |
60 #include "xintrinsicp.h" /* CoreP.h needs this */ | |
61 #include <X11/CoreP.h> /* Numerous places access the fields of | |
62 a core widget directly. We could | |
63 use XtGetValues(), but ... */ | |
64 #include <X11/ShellP.h> | |
65 | |
800 | 66 #if defined (HAVE_XIM) && defined (XIM_MOTIF) |
1315 | 67 #include "xmotif.h" |
428 | 68 #endif |
69 | |
70 #ifdef HAVE_DRAGNDROP | |
71 #include "dragdrop.h" | |
72 #endif | |
73 | |
1292 | 74 #ifdef WIN32_ANY |
75 extern int mswindows_is_blocking; | |
76 #endif | |
77 | |
2828 | 78 /* For Russian C-x processing. */ |
3171 | 79 Lisp_Object Vx_us_keymap_description; |
80 Fixnum Vx_us_keymap_first_keycode; | |
2699 | 81 |
1094 | 82 /* used in glyphs-x.c */ |
83 void enqueue_focus_event (Widget wants_it, Lisp_Object frame, int in_p); | |
428 | 84 static void handle_focus_event_1 (struct frame *f, int in_p); |
863 | 85 static void handle_focus_event_2 (Window w, struct frame *f, int in_p); |
428 | 86 |
87 static struct event_stream *Xt_event_stream; | |
88 | |
89 /* With the new event model, all events go through XtDispatchEvent() | |
90 and are picked up by an event handler that is added to each frame | |
91 widget. (This is how it's supposed to be.) In the old method, | |
92 Emacs sucks out events directly from XtNextEvent() and only | |
93 dispatches the events that it doesn't need to deal with. This | |
94 old way has lots of corresponding junk that is no longer | |
95 necessary: lwlib extensions, synthetic XAnyEvents, unnecessary | |
96 magic events, etc. */ | |
97 | |
98 /* The one and only one application context that Emacs uses. */ | |
99 XtAppContext Xt_app_con; | |
100 | |
101 /* Do we accept events sent by other clients? */ | |
102 int x_allow_sendevents; | |
103 | |
104 #ifdef DEBUG_XEMACS | |
458 | 105 Fixnum debug_x_events; |
428 | 106 #endif |
107 | |
108 static int process_events_occurred; | |
109 static int tty_events_occurred; | |
450 | 110 static Widget widget_with_focus; |
428 | 111 |
112 /* Mask of bits indicating the descriptors that we wait for input on */ | |
1268 | 113 extern SELECT_TYPE input_wait_mask, non_fake_input_wait_mask; |
114 extern SELECT_TYPE process_only_mask, tty_only_mask; | |
428 | 115 |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
116 /* #### This should be String, but G++ 4.3 doesn't apply the const |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
117 specifier the same way for String (typedef'd to char*) and char*. */ |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
118 static const char * x_fallback_resources[] = |
428 | 119 { |
120 /* This file is automatically generated from the app-defaults file | |
121 in ../etc/Emacs.ad. These resources are consulted only if no | |
122 app-defaults file is found at all. | |
123 */ | |
124 #include <Emacs.ad.h> | |
125 0 | |
126 }; | |
127 | |
128 static Lisp_Object x_keysym_to_emacs_keysym (KeySym keysym, int simple_p); | |
129 void emacs_Xt_mapping_action (Widget w, XEvent *event); | |
440 | 130 void debug_process_finalization (Lisp_Process *p); |
428 | 131 void emacs_Xt_event_handler (Widget wid, XtPointer closure, XEvent *event, |
132 Boolean *continue_to_dispatch); | |
133 | |
134 static int last_quit_check_signal_tick_count; | |
135 | |
136 Lisp_Object Qsans_modifiers; | |
137 | |
1268 | 138 #define THIS_IS_X |
139 #include "event-xlike-inc.c" | |
140 | |
428 | 141 |
142 /************************************************************************/ | |
143 /* keymap handling */ | |
144 /************************************************************************/ | |
145 | |
2828 | 146 /* See comment near character_to_event(). */ |
440 | 147 static void |
2828 | 148 maybe_define_x_key_as_self_inserting_character (KeySym keysym, |
149 Lisp_Object symbol) | |
440 | 150 { |
151 Lisp_Object character = x_keysym_to_character (keysym); | |
152 | |
153 if (CHARP (character)) | |
154 { | |
155 extern Lisp_Object Vcurrent_global_map; | |
2828 | 156 extern Lisp_Object Qcharacter_of_keysym; |
971 | 157 if (NILP (Flookup_key (Vcurrent_global_map, symbol, Qnil))) |
158 { | |
2828 | 159 Fput (symbol, Qcharacter_of_keysym, character); |
971 | 160 Fdefine_key (Vcurrent_global_map, symbol, Qself_insert_command); |
161 } | |
440 | 162 } |
163 } | |
164 | |
2828 | 165 void |
440 | 166 x_has_keysym (KeySym keysym, Lisp_Object hash_table, int with_modifiers) |
167 { | |
168 KeySym upper_lower[2]; | |
169 int j; | |
170 | |
171 if (keysym < 0x80) /* Optimize for ASCII keysyms */ | |
172 return; | |
442 | 173 |
174 /* If you execute: | |
175 xmodmap -e 'keysym NN = scaron' | |
440 | 176 and then press (Shift scaron), X11 will return the different |
442 | 177 keysym `Scaron', but `xmodmap -pke' might not even mention `Scaron'. |
178 So we "register" both `scaron' and `Scaron'. */ | |
179 #ifdef HAVE_XCONVERTCASE | |
440 | 180 XConvertCase (keysym, &upper_lower[0], &upper_lower[1]); |
442 | 181 #else |
182 upper_lower[0] = upper_lower[1] = keysym; | |
183 #endif | |
440 | 184 |
185 for (j = 0; j < (upper_lower[0] == upper_lower[1] ? 1 : 2); j++) | |
186 { | |
2828 | 187 Extbyte *name; |
440 | 188 keysym = upper_lower[j]; |
189 | |
190 name = XKeysymToString (keysym); | |
191 if (name) | |
192 { | |
193 /* X guarantees NAME to be in the Host Portable Character Encoding */ | |
194 Lisp_Object sym = x_keysym_to_emacs_keysym (keysym, 0); | |
195 Lisp_Object new_value = with_modifiers ? Qt : Qsans_modifiers; | |
196 Lisp_Object old_value = Fgethash (sym, hash_table, Qnil); | |
197 | |
198 if (! EQ (old_value, new_value) | |
199 && ! (EQ (old_value, Qsans_modifiers) && | |
200 EQ (new_value, Qt))) | |
201 { | |
202 maybe_define_x_key_as_self_inserting_character (keysym, sym); | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
203 Fputhash (build_extstring (name, Qbinary), new_value, |
2828 | 204 hash_table); |
440 | 205 Fputhash (sym, new_value, hash_table); |
206 } | |
207 } | |
208 } | |
209 } | |
210 | |
428 | 211 static void |
212 x_reset_key_mapping (struct device *d) | |
213 { | |
214 Display *display = DEVICE_X_DISPLAY (d); | |
215 struct x_device *xd = DEVICE_X_DATA (d); | |
216 KeySym *keysym, *keysym_end; | |
217 Lisp_Object hash_table; | |
218 int key_code_count, keysyms_per_code; | |
219 | |
220 if (xd->x_keysym_map) | |
221 XFree ((char *) xd->x_keysym_map); | |
222 XDisplayKeycodes (display, | |
223 &xd->x_keysym_map_min_code, | |
224 &xd->x_keysym_map_max_code); | |
225 key_code_count = xd->x_keysym_map_max_code - xd->x_keysym_map_min_code + 1; | |
226 xd->x_keysym_map = | |
227 XGetKeyboardMapping (display, xd->x_keysym_map_min_code, key_code_count, | |
228 &xd->x_keysym_map_keysyms_per_code); | |
229 | |
230 hash_table = xd->x_keysym_map_hash_table; | |
231 if (HASH_TABLEP (hash_table)) | |
232 Fclrhash (hash_table); | |
233 else | |
234 xd->x_keysym_map_hash_table = hash_table = | |
235 make_lisp_hash_table (128, HASH_TABLE_NON_WEAK, HASH_TABLE_EQUAL); | |
236 | |
237 for (keysym = xd->x_keysym_map, | |
238 keysyms_per_code = xd->x_keysym_map_keysyms_per_code, | |
239 keysym_end = keysym + (key_code_count * keysyms_per_code); | |
240 keysym < keysym_end; | |
241 keysym += keysyms_per_code) | |
242 { | |
243 int j; | |
244 | |
245 if (keysym[0] == NoSymbol) | |
246 continue; | |
247 | |
440 | 248 x_has_keysym (keysym[0], hash_table, 0); |
428 | 249 |
250 for (j = 1; j < keysyms_per_code; j++) | |
251 { | |
252 if (keysym[j] != keysym[0] && | |
253 keysym[j] != NoSymbol) | |
440 | 254 x_has_keysym (keysym[j], hash_table, 1); |
428 | 255 } |
256 } | |
257 } | |
258 | |
2828 | 259 static const Ascbyte * |
428 | 260 index_to_name (int indice) |
261 { | |
262 switch (indice) | |
263 { | |
264 case ShiftMapIndex: return "ModShift"; | |
265 case LockMapIndex: return "ModLock"; | |
266 case ControlMapIndex: return "ModControl"; | |
267 case Mod1MapIndex: return "Mod1"; | |
268 case Mod2MapIndex: return "Mod2"; | |
269 case Mod3MapIndex: return "Mod3"; | |
270 case Mod4MapIndex: return "Mod4"; | |
271 case Mod5MapIndex: return "Mod5"; | |
272 default: return "???"; | |
273 } | |
274 } | |
275 | |
2828 | 276 /* X bogusly doesn't define the interpretations of any bits besides |
277 ModControl, ModShift, and ModLock; so the Interclient Communication | |
278 Conventions Manual says that we have to bend over backwards to figure | |
279 out what the other modifier bits mean. According to ICCCM: | |
280 | |
281 - Any keycode which is assigned ModControl is a "control" key. | |
282 | |
283 - Any modifier bit which is assigned to a keycode which generates Meta_L | |
284 or Meta_R is the modifier bit meaning "meta". Likewise for Super, Hyper, | |
285 etc. | |
286 | |
287 - Any keypress event which contains ModControl in its state should be | |
288 interpreted as a "control" character. | |
289 | |
290 - Any keypress event which contains a modifier bit in its state which is | |
291 generated by a keycode whose corresponding keysym is Meta_L or Meta_R | |
292 should be interpreted as a "meta" character. Likewise for Super, Hyper, | |
293 etc. | |
294 | |
295 - It is illegal for a keysym to be associated with more than one modifier | |
296 bit. | |
297 | |
298 This means that the only thing that emacs can reasonably interpret as a | |
299 "meta" key is a key whose keysym is Meta_L or Meta_R, and which generates | |
300 one of the modifier bits Mod1-Mod5. | |
301 | |
302 Unfortunately, many keyboards don't have Meta keys in their default | |
303 configuration. So, if there are no Meta keys, but there are "Alt" keys, | |
304 emacs will interpret Alt as Meta. If there are both Meta and Alt keys, | |
305 then the Meta keys mean "Meta", and the Alt keys mean "Alt" (it used to | |
306 mean "Symbol," but that just confused the hell out of way too many people). | |
307 | |
308 This works with the default configurations of the 19 keyboard-types I've | |
309 checked. | |
310 | |
311 Emacs detects keyboard configurations which violate the above rules, and | |
312 gives a warning. */ | |
428 | 313 |
314 static void | |
315 x_reset_modifier_mapping (struct device *d) | |
316 { | |
317 Display *display = DEVICE_X_DISPLAY (d); | |
318 struct x_device *xd = DEVICE_X_DATA (d); | |
319 int modifier_index, modifier_key, column, mkpm; | |
320 int warned_about_overlapping_modifiers = 0; | |
321 int warned_about_predefined_modifiers = 0; | |
322 int warned_about_duplicate_modifiers = 0; | |
323 int meta_bit = 0; | |
324 int hyper_bit = 0; | |
325 int super_bit = 0; | |
326 int alt_bit = 0; | |
327 int mode_bit = 0; | |
328 | |
329 xd->lock_interpretation = 0; | |
330 | |
331 if (xd->x_modifier_keymap) | |
3949 | 332 { |
333 XFreeModifiermap (xd->x_modifier_keymap); | |
334 /* Set it to NULL in case we receive two MappingModifier events in a | |
335 row, and the second is processed during some CHECK_QUITs within | |
336 x_reset_key_mapping. If that happens, XFreeModifierMap will be | |
337 called twice on the same map, and we crash. */ | |
338 xd->x_modifier_keymap = NULL; | |
339 } | |
428 | 340 |
341 x_reset_key_mapping (d); | |
342 | |
343 xd->x_modifier_keymap = XGetModifierMapping (display); | |
344 | |
345 /* Boy, I really wish C had local functions... | |
346 */ | |
347 | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
348 #define modwarn(name,old,other) \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
349 warn_when_safe (Qkey_mapping, Qwarning, \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
350 "XEmacs: %s (0x%x) generates %s, which is generated by %s.", \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
351 name, code, index_to_name (old), other), \ |
428 | 352 warned_about_overlapping_modifiers = 1 |
353 | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
354 #define modbarf(name,other) \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
355 warn_when_safe (Qkey_mapping, Qwarning, \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
356 "XEmacs: %s (0x%x) generates %s, which is nonsensical.", \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
357 name, code, other), \ |
428 | 358 warned_about_predefined_modifiers = 1 |
359 | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
360 #define check_modifier(name,mask) \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
361 if ((1<<modifier_index) != mask) \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
362 warn_when_safe (Qkey_mapping, Qwarning, \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
363 "XEmacs: %s (0x%x) generates %s, which is nonsensical.", \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
364 name, code, index_to_name (modifier_index)), \ |
428 | 365 warned_about_predefined_modifiers = 1 |
366 | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
367 #define store_modifier(name,old) \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
368 if (old && old != modifier_index) \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
369 warn_when_safe (Qkey_mapping, Qwarning, \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
370 "XEmacs: %s (0x%x) generates both %s and %s, which is nonsensical.", \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
371 name, code, index_to_name (old), \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
372 index_to_name (modifier_index)), \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
373 warned_about_duplicate_modifiers = 1; \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
374 if (modifier_index == ShiftMapIndex) modbarf (name,"ModShift"); \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
375 else if (modifier_index == LockMapIndex) modbarf (name,"ModLock"); \ |
428 | 376 else if (modifier_index == ControlMapIndex) modbarf (name,"ModControl"); \ |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
377 else if (sym == XK_Mode_switch) \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
378 mode_bit = modifier_index; /* Mode_switch is special, see below... */ \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
379 else if (modifier_index == meta_bit && old != meta_bit) \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
380 modwarn (name, meta_bit, "Meta"); \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
381 else if (modifier_index == super_bit && old != super_bit) \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
382 modwarn (name, super_bit, "Super"); \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
383 else if (modifier_index == hyper_bit && old != hyper_bit) \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
384 modwarn (name, hyper_bit, "Hyper"); \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
385 else if (modifier_index == alt_bit && old != alt_bit) \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
386 modwarn (name, alt_bit, "Alt"); \ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
387 else \ |
428 | 388 old = modifier_index; |
389 | |
390 mkpm = xd->x_modifier_keymap->max_keypermod; | |
391 for (modifier_index = 0; modifier_index < 8; modifier_index++) | |
392 for (modifier_key = 0; modifier_key < mkpm; modifier_key++) { | |
393 KeySym last_sym = 0; | |
394 for (column = 0; column < 4; column += 2) { | |
395 KeyCode code = xd->x_modifier_keymap->modifiermap[modifier_index * mkpm | |
396 + modifier_key]; | |
397 KeySym sym = (code ? XKeycodeToKeysym (display, code, column) : 0); | |
398 if (sym == last_sym) continue; | |
399 last_sym = sym; | |
400 switch (sym) { | |
401 case XK_Mode_switch:store_modifier ("Mode_switch", mode_bit); break; | |
402 case XK_Meta_L: store_modifier ("Meta_L", meta_bit); break; | |
403 case XK_Meta_R: store_modifier ("Meta_R", meta_bit); break; | |
404 case XK_Super_L: store_modifier ("Super_L", super_bit); break; | |
405 case XK_Super_R: store_modifier ("Super_R", super_bit); break; | |
406 case XK_Hyper_L: store_modifier ("Hyper_L", hyper_bit); break; | |
407 case XK_Hyper_R: store_modifier ("Hyper_R", hyper_bit); break; | |
408 case XK_Alt_L: store_modifier ("Alt_L", alt_bit); break; | |
409 case XK_Alt_R: store_modifier ("Alt_R", alt_bit); break; | |
410 case XK_Control_L: check_modifier ("Control_L", ControlMask); break; | |
411 case XK_Control_R: check_modifier ("Control_R", ControlMask); break; | |
412 case XK_Shift_L: check_modifier ("Shift_L", ShiftMask); break; | |
413 case XK_Shift_R: check_modifier ("Shift_R", ShiftMask); break; | |
414 case XK_Shift_Lock: check_modifier ("Shift_Lock", LockMask); | |
415 xd->lock_interpretation = XK_Shift_Lock; break; | |
416 case XK_Caps_Lock: check_modifier ("Caps_Lock", LockMask); | |
417 xd->lock_interpretation = XK_Caps_Lock; break; | |
418 | |
419 /* It probably doesn't make any sense for a modifier bit to be | |
420 assigned to a key that is not one of the above, but OpenWindows | |
421 assigns modifier bits to a couple of random function keys for | |
422 no reason that I can discern, so printing a warning here would | |
423 be annoying. */ | |
424 } | |
425 } | |
426 } | |
427 #undef store_modifier | |
428 #undef check_modifier | |
429 #undef modwarn | |
430 #undef modbarf | |
431 | |
432 /* If there was no Meta key, then try using the Alt key instead. | |
433 If there is both a Meta key and an Alt key, then the Alt key | |
434 is not disturbed and remains an Alt key. */ | |
435 if (! meta_bit && alt_bit) | |
436 meta_bit = alt_bit, alt_bit = 0; | |
437 | |
438 /* mode_bit overrides everything, since it's processed down inside of | |
439 XLookupString() instead of by us. If Meta and Mode_switch both | |
440 generate the same modifier bit (which is an error), then we don't | |
441 interpret that bit as Meta, because we can't make XLookupString() | |
442 not interpret it as Mode_switch; and interpreting it as both would | |
443 be totally wrong. */ | |
444 if (mode_bit) | |
445 { | |
2828 | 446 const Ascbyte *warn = 0; |
428 | 447 if (mode_bit == meta_bit) warn = "Meta", meta_bit = 0; |
448 else if (mode_bit == hyper_bit) warn = "Hyper", hyper_bit = 0; | |
449 else if (mode_bit == super_bit) warn = "Super", super_bit = 0; | |
450 else if (mode_bit == alt_bit) warn = "Alt", alt_bit = 0; | |
451 if (warn) | |
452 { | |
453 warn_when_safe | |
454 (Qkey_mapping, Qwarning, | |
455 "XEmacs: %s is being used for both Mode_switch and %s.", | |
456 index_to_name (mode_bit), warn), | |
457 warned_about_overlapping_modifiers = 1; | |
458 } | |
459 } | |
460 #undef index_to_name | |
461 | |
462 xd->MetaMask = (meta_bit ? (1 << meta_bit) : 0); | |
463 xd->HyperMask = (hyper_bit ? (1 << hyper_bit) : 0); | |
464 xd->SuperMask = (super_bit ? (1 << super_bit) : 0); | |
465 xd->AltMask = (alt_bit ? (1 << alt_bit) : 0); | |
466 xd->ModeMask = (mode_bit ? (1 << mode_bit) : 0); /* unused */ | |
467 | |
468 | |
469 if (warned_about_overlapping_modifiers) | |
470 warn_when_safe (Qkey_mapping, Qwarning, "\n" | |
471 " Two distinct modifier keys (such as Meta and Hyper) cannot generate\n" | |
472 " the same modifier bit, because Emacs won't be able to tell which\n" | |
473 " modifier was actually held down when some other key is pressed. It\n" | |
474 " won't be able to tell Meta-x and Hyper-x apart, for example. Change\n" | |
475 " one of these keys to use some other modifier bit. If you intend for\n" | |
476 " these keys to have the same behavior, then change them to have the\n" | |
477 " same keysym as well as the same modifier bit."); | |
478 | |
479 if (warned_about_predefined_modifiers) | |
480 warn_when_safe (Qkey_mapping, Qwarning, "\n" | |
481 " The semantics of the modifier bits ModShift, ModLock, and ModControl\n" | |
482 " are predefined. It does not make sense to assign ModControl to any\n" | |
483 " keysym other than Control_L or Control_R, or to assign any modifier\n" | |
484 " bits to the \"control\" keysyms other than ModControl. You can't\n" | |
485 " turn a \"control\" key into a \"meta\" key (or vice versa) by simply\n" | |
486 " assigning the key a different modifier bit. You must also make that\n" | |
487 " key generate an appropriate keysym (Control_L, Meta_L, etc)."); | |
488 | |
489 /* No need to say anything more for warned_about_duplicate_modifiers. */ | |
490 | |
491 if (warned_about_overlapping_modifiers || warned_about_predefined_modifiers) | |
492 warn_when_safe (Qkey_mapping, Qwarning, "\n" | |
493 " The meanings of the modifier bits Mod1 through Mod5 are determined\n" | |
494 " by the keysyms used to control those bits. Mod1 does NOT always\n" | |
495 " mean Meta, although some non-ICCCM-compliant programs assume that."); | |
496 } | |
497 | |
498 void | |
499 x_init_modifier_mapping (struct device *d) | |
500 { | |
501 struct x_device *xd = DEVICE_X_DATA (d); | |
502 xd->x_keysym_map_hash_table = Qnil; | |
503 xd->x_keysym_map = NULL; | |
504 xd->x_modifier_keymap = NULL; | |
505 x_reset_modifier_mapping (d); | |
506 } | |
507 | |
508 static int | |
509 x_key_is_modifier_p (KeyCode keycode, struct device *d) | |
510 { | |
511 struct x_device *xd = DEVICE_X_DATA (d); | |
512 KeySym *syms; | |
513 int i; | |
514 | |
515 if (keycode < xd->x_keysym_map_min_code || | |
516 keycode > xd->x_keysym_map_max_code) | |
517 return 0; | |
518 | |
519 syms = &xd->x_keysym_map [(keycode - xd->x_keysym_map_min_code) * | |
520 xd->x_keysym_map_keysyms_per_code]; | |
521 for (i = 0; i < xd->x_keysym_map_keysyms_per_code; i++) | |
522 if (IsModifierKey (syms [i]) || | |
523 syms [i] == XK_Mode_switch) /* why doesn't IsModifierKey count this? */ | |
524 return 1; | |
525 return 0; | |
526 } | |
527 | |
528 /* key-handling code is always ugly. It just ends up working out | |
529 that way. | |
530 | |
531 Here are some pointers: | |
532 | |
533 -- DOWN_MASK indicates which modifiers should be treated as "down" | |
534 when the corresponding upstroke happens. It gets reset for | |
535 a particular modifier when that modifier goes up, and reset | |
536 for all modifiers when a non-modifier key is pressed. Example: | |
537 | |
538 I press Control-A-Shift and then release Control-A-Shift. | |
539 I want the Shift key to be sticky but not the Control key. | |
540 | |
541 -- LAST_DOWNKEY and RELEASE_TIME are used to keep track of | |
542 auto-repeat -- see below. | |
543 | |
544 -- If a modifier key is sticky, I can unstick it by pressing | |
545 the modifier key again. */ | |
546 | |
547 static void | |
548 x_handle_sticky_modifiers (XEvent *ev, struct device *d) | |
549 { | |
550 struct x_device *xd; | |
551 KeyCode keycode; | |
552 int type; | |
553 | |
554 if (!modifier_keys_are_sticky) /* Optimize for non-sticky modifiers */ | |
555 return; | |
556 | |
557 xd = DEVICE_X_DATA (d); | |
558 keycode = ev->xkey.keycode; | |
559 type = ev->type; | |
560 | |
561 if (keycode < xd->x_keysym_map_min_code || | |
562 keycode > xd->x_keysym_map_max_code) | |
563 return; | |
564 | |
565 if (! ((type == KeyPress || type == KeyRelease) && | |
566 x_key_is_modifier_p (keycode, d))) | |
567 { /* Not a modifier key */ | |
568 Bool key_event_p = (type == KeyPress || type == KeyRelease); | |
569 | |
444 | 570 if (type == ButtonPress |
571 || (type == KeyPress | |
572 && ((xd->last_downkey | |
573 && ((keycode != xd->last_downkey | |
574 || ev->xkey.time != xd->release_time))) | |
575 || (INTP (Vmodifier_keys_sticky_time) | |
576 && ev->xkey.time | |
577 > (xd->modifier_release_time | |
578 + XINT (Vmodifier_keys_sticky_time)))))) | |
428 | 579 { |
580 xd->need_to_add_mask = 0; | |
581 xd->last_downkey = 0; | |
582 } | |
444 | 583 else if (type == KeyPress && !xd->last_downkey) |
584 xd->last_downkey = keycode; | |
585 | |
428 | 586 if (type == KeyPress) |
587 xd->release_time = 0; | |
588 if (type == KeyPress || type == ButtonPress) | |
444 | 589 { |
590 xd->down_mask = 0; | |
591 xd->modifier_release_time = 0; | |
592 } | |
428 | 593 |
594 if (key_event_p) | |
595 ev->xkey.state |= xd->need_to_add_mask; | |
596 else | |
597 ev->xbutton.state |= xd->need_to_add_mask; | |
598 | |
599 if (type == KeyRelease && keycode == xd->last_downkey) | |
600 /* If I hold press-and-release the Control key and then press | |
601 and hold down the right arrow, I want it to auto-repeat | |
602 Control-Right. On the other hand, if I do the same but | |
603 manually press the Right arrow a bunch of times, I want | |
604 to see one Control-Right and then a bunch of Rights. | |
605 This means that we need to distinguish between an | |
606 auto-repeated key and a key pressed and released a bunch | |
607 of times. | |
608 | |
609 Naturally, the designers of the X spec didn't see fit | |
610 to provide an obvious way to distinguish these cases. | |
611 So we assume that if the release and the next press | |
612 occur at the same time, the key was actually auto- | |
613 repeated. Under Open-Windows, at least, this works. */ | |
444 | 614 xd->modifier_release_time = xd->release_time |
615 = key_event_p ? ev->xkey.time : ev->xbutton.time; | |
428 | 616 } |
617 else /* Modifier key pressed */ | |
618 { | |
619 int i; | |
620 KeySym *syms = &xd->x_keysym_map [(keycode - xd->x_keysym_map_min_code) * | |
621 xd->x_keysym_map_keysyms_per_code]; | |
622 | |
623 /* If a non-modifier key was pressed in the middle of a bunch | |
624 of modifiers, then it unsticks all the modifiers that were | |
625 previously pressed. We cannot unstick the modifiers until | |
626 now because we want to check for auto-repeat of the | |
627 non-modifier key. */ | |
628 | |
629 if (xd->last_downkey) | |
630 { | |
631 xd->last_downkey = 0; | |
632 xd->need_to_add_mask = 0; | |
633 } | |
634 | |
444 | 635 if (xd->modifier_release_time |
636 && INTP (Vmodifier_keys_sticky_time) | |
637 && (ev->xkey.time | |
638 > xd->modifier_release_time + XINT (Vmodifier_keys_sticky_time))) | |
639 { | |
640 xd->need_to_add_mask = 0; | |
641 xd->down_mask = 0; | |
642 } | |
643 | |
428 | 644 #define FROB(mask) \ |
645 do { \ | |
646 if (type == KeyPress) \ | |
647 { \ | |
648 /* If modifier key is already sticky, \ | |
649 then unstick it. Note that we do \ | |
650 not test down_mask to deal with the \ | |
651 unlikely but possible case that the \ | |
652 modifier key auto-repeats. */ \ | |
653 if (xd->need_to_add_mask & mask) \ | |
654 { \ | |
655 xd->need_to_add_mask &= ~mask; \ | |
656 xd->down_mask &= ~mask; \ | |
657 } \ | |
658 else \ | |
659 xd->down_mask |= mask; \ | |
660 } \ | |
661 else \ | |
662 { \ | |
663 if (xd->down_mask & mask) \ | |
664 { \ | |
665 xd->down_mask &= ~mask; \ | |
666 xd->need_to_add_mask |= mask; \ | |
667 } \ | |
668 } \ | |
444 | 669 xd->modifier_release_time = ev->xkey.time; \ |
428 | 670 } while (0) |
671 | |
672 for (i = 0; i < xd->x_keysym_map_keysyms_per_code; i++) | |
673 switch (syms[i]) | |
674 { | |
675 case XK_Control_L: case XK_Control_R: FROB (ControlMask); break; | |
676 case XK_Shift_L: case XK_Shift_R: FROB (ShiftMask); break; | |
677 case XK_Meta_L: case XK_Meta_R: FROB (xd->MetaMask); break; | |
678 case XK_Super_L: case XK_Super_R: FROB (xd->SuperMask); break; | |
679 case XK_Hyper_L: case XK_Hyper_R: FROB (xd->HyperMask); break; | |
680 case XK_Alt_L: case XK_Alt_R: FROB (xd->AltMask); break; | |
681 } | |
682 } | |
683 #undef FROB | |
684 } | |
685 | |
686 static void | |
687 clear_sticky_modifiers (struct device *d) | |
688 { | |
689 struct x_device *xd = DEVICE_X_DATA (d); | |
690 | |
691 xd->need_to_add_mask = 0; | |
692 xd->last_downkey = 0; | |
693 xd->release_time = 0; | |
694 xd->down_mask = 0; | |
695 } | |
696 | |
697 static int | |
698 keysym_obeys_caps_lock_p (KeySym sym, struct device *d) | |
699 { | |
700 struct x_device *xd = DEVICE_X_DATA (d); | |
701 /* Eeeeevil hack. Don't apply Caps_Lock to things that aren't alphabetic | |
702 characters, where "alphabetic" means something more than simply A-Z. | |
703 That is, if Caps_Lock is down, typing ESC doesn't produce Shift-ESC. | |
704 But if shift-lock is down, then it does. */ | |
705 if (xd->lock_interpretation == XK_Shift_Lock) | |
706 return 1; | |
707 | |
708 return | |
709 ((sym >= XK_A) && (sym <= XK_Z)) || | |
710 ((sym >= XK_a) && (sym <= XK_z)) || | |
711 ((sym >= XK_Agrave) && (sym <= XK_Odiaeresis)) || | |
712 ((sym >= XK_agrave) && (sym <= XK_odiaeresis)) || | |
713 ((sym >= XK_Ooblique) && (sym <= XK_Thorn)) || | |
714 ((sym >= XK_oslash) && (sym <= XK_thorn)); | |
715 } | |
716 | |
717 /* called from EmacsFrame.c (actually from Xt itself) when a | |
718 MappingNotify event is received. In its infinite wisdom, Xt | |
719 decided that Xt event handlers never get MappingNotify events. | |
720 O'Reilly Xt Programming Manual 9.1.2 says: | |
721 | |
722 MappingNotify is automatically handled by Xt, so it isn't passed | |
723 to event handlers and you don't need to worry about it. | |
724 | |
725 Of course, we DO worry about it, so we need a special translation. */ | |
726 void | |
2286 | 727 emacs_Xt_mapping_action (Widget UNUSED (w), XEvent *event) |
428 | 728 { |
729 struct device *d = get_device_from_display (event->xany.display); | |
730 | |
731 if (DEVICE_X_BEING_DELETED (d)) | |
732 return; | |
733 #if 0 | |
734 /* nyet. Now this is handled by Xt. */ | |
735 XRefreshKeyboardMapping (&event->xmapping); | |
736 #endif | |
737 /* xmodmap generates about a billion MappingKeyboard events, followed | |
738 by a single MappingModifier event, so it might be worthwhile to | |
739 take extra MappingKeyboard events out of the queue before requesting | |
740 the current keymap from the server. */ | |
741 switch (event->xmapping.request) | |
742 { | |
743 case MappingKeyboard: x_reset_key_mapping (d); break; | |
744 case MappingModifier: x_reset_modifier_mapping (d); break; | |
745 case MappingPointer: /* Do something here? */ break; | |
2500 | 746 default: ABORT(); |
428 | 747 } |
748 } | |
749 | |
750 | |
751 /************************************************************************/ | |
752 /* X to Emacs event conversion */ | |
753 /************************************************************************/ | |
754 | |
755 static Lisp_Object | |
756 x_keysym_to_emacs_keysym (KeySym keysym, int simple_p) | |
757 { | |
2828 | 758 Extbyte *name; |
759 DECLARE_EISTRING(einame); | |
760 | |
428 | 761 if (keysym >= XK_exclam && keysym <= XK_asciitilde) |
762 /* We must assume that the X keysym numbers for the ASCII graphic | |
763 characters are the same as their ASCII codes. */ | |
764 return make_char (keysym); | |
765 | |
766 switch (keysym) | |
767 { | |
768 /* These would be handled correctly by the default case, but by | |
769 special-casing them here we don't garbage a string or call | |
770 intern(). */ | |
771 case XK_BackSpace: return QKbackspace; | |
772 case XK_Tab: return QKtab; | |
773 case XK_Linefeed: return QKlinefeed; | |
774 case XK_Return: return QKreturn; | |
775 case XK_Escape: return QKescape; | |
776 case XK_space: return QKspace; | |
777 case XK_Delete: return QKdelete; | |
778 case 0: return Qnil; | |
779 default: | |
780 if (simple_p) return Qnil; | |
781 name = XKeysymToString (keysym); | |
782 if (!name || !name[0]) | |
783 /* This happens if there is a mismatch between the Xlib of | |
784 XEmacs and the Xlib of the X server... | |
785 | |
786 Let's hard-code in some knowledge of common keysyms introduced | |
787 in recent X11 releases. Snarfed from X11/keysymdef.h | |
788 | |
789 Probably we should add some stuff here for X11R6. */ | |
790 switch (keysym) | |
791 { | |
792 case 0xFF95: return KEYSYM ("kp-home"); | |
793 case 0xFF96: return KEYSYM ("kp-left"); | |
794 case 0xFF97: return KEYSYM ("kp-up"); | |
795 case 0xFF98: return KEYSYM ("kp-right"); | |
796 case 0xFF99: return KEYSYM ("kp-down"); | |
797 case 0xFF9A: return KEYSYM ("kp-prior"); | |
798 case 0xFF9B: return KEYSYM ("kp-next"); | |
799 case 0xFF9C: return KEYSYM ("kp-end"); | |
800 case 0xFF9D: return KEYSYM ("kp-begin"); | |
801 case 0xFF9E: return KEYSYM ("kp-insert"); | |
802 case 0xFF9F: return KEYSYM ("kp-delete"); | |
803 | |
804 case 0x1005FF10: return KEYSYM ("SunF36"); /* labeled F11 */ | |
805 case 0x1005FF11: return KEYSYM ("SunF37"); /* labeled F12 */ | |
806 default: | |
807 { | |
2828 | 808 Ascbyte buf [64]; |
428 | 809 sprintf (buf, "unknown-keysym-0x%X", (int) keysym); |
810 return KEYSYM (buf); | |
811 } | |
812 } | |
2828 | 813 |
428 | 814 /* If it's got a one-character name, that's good enough. */ |
815 if (!name[1]) | |
2828 | 816 return make_char ((Ichar)name[0]); |
817 | |
818 /* In theory the Host Portable Character Set is just ASCII, but | |
819 trusting X11 implementors to get that right is likely to lead to | |
820 tears. */ | |
821 eicpy_ext(einame, name, Qbinary); | |
428 | 822 |
823 /* If it's in the "Keyboard" character set, downcase it. | |
824 The case of those keysyms is too totally random for us to | |
825 force anyone to remember them. | |
2828 | 826 The case of the other character sets is significant, however. */ |
428 | 827 if ((((unsigned int) keysym) & (~0x1FF)) == ((unsigned int) 0xFE00)) |
828 { | |
2828 | 829 Ibyte *iname; |
830 eilwr(einame); | |
831 | |
832 for (iname = eidata(einame); *iname != '\0';) | |
833 { | |
834 if (*iname == '_') | |
835 { | |
836 *iname = '-'; | |
837 } | |
838 INC_IBYTEPTR(iname); | |
428 | 839 } |
840 } | |
2837 | 841 return KEYSYM ((const CIbyte *) eidata (einame)); |
428 | 842 } |
843 } | |
844 | |
845 static Lisp_Object | |
846 x_to_emacs_keysym (XKeyPressedEvent *event, int simple_p) | |
847 /* simple_p means don't try too hard (ASCII only) */ | |
848 { | |
849 KeySym keysym = 0; | |
850 | |
851 #ifdef HAVE_XIM | |
3072 | 852 int len = 0; |
442 | 853 /* Some implementations of XmbLookupString don't return |
854 XBufferOverflow correctly, so increase the size of the xim input | |
855 buffer from 64 to the more reasonable size 513, as Emacs has done. | |
856 From Kenichi Handa. */ | |
857 char buffer[513]; | |
428 | 858 char *bufptr = buffer; |
859 int bufsiz = sizeof (buffer); | |
860 Status status; | |
861 #ifdef XIM_XLIB | |
862 XIC xic = FRAME_X_XIC (x_any_window_to_frame | |
863 (get_device_from_display (event->display), | |
864 event->window)); | |
865 #endif /* XIM_XLIB */ | |
866 #endif /* HAVE_XIM */ | |
867 | |
868 /* We use XLookupString if we're not using XIM, or are using | |
869 XIM_XLIB but input context creation failed. */ | |
870 #if ! (defined (HAVE_XIM) && defined (XIM_MOTIF)) | |
871 #if defined (HAVE_XIM) && defined (XIM_XLIB) | |
872 if (!xic) | |
873 #endif /* XIM_XLIB */ | |
874 { | |
875 /* Apparently it's necessary to specify a dummy here (rather | |
876 than passing in 0) to avoid crashes on German IRIX */ | |
877 char dummy[256]; | |
878 XLookupString (event, dummy, 200, &keysym, 0); | |
879 return (IsModifierKey (keysym) || keysym == XK_Mode_switch ) | |
880 ? Qnil : x_keysym_to_emacs_keysym (keysym, simple_p); | |
881 } | |
882 #endif /* ! XIM_MOTIF */ | |
883 | |
884 #ifdef HAVE_XIM | |
885 Lookup_String: /* Come-From XBufferOverflow */ | |
886 #ifdef XIM_MOTIF | |
887 len = XmImMbLookupString (XtWindowToWidget (event->display, event->window), | |
888 event, bufptr, bufsiz, &keysym, &status); | |
889 #else /* XIM_XLIB */ | |
890 if (xic) | |
891 len = XmbLookupString (xic, event, bufptr, bufsiz, &keysym, &status); | |
1494 | 892 #endif /* XIM_MOTIF */ |
428 | 893 |
894 #ifdef DEBUG_XEMACS | |
442 | 895 if (debug_x_events > 0) |
428 | 896 { |
897 stderr_out (" status="); | |
898 #define print_status_when(S) if (status == S) stderr_out (#S) | |
899 print_status_when (XLookupKeySym); | |
900 print_status_when (XLookupBoth); | |
901 print_status_when (XLookupChars); | |
902 print_status_when (XLookupNone); | |
903 print_status_when (XBufferOverflow); | |
904 | |
905 if (status == XLookupKeySym || status == XLookupBoth) | |
906 stderr_out (" keysym=%s", XKeysymToString (keysym)); | |
907 if (status == XLookupChars || status == XLookupBoth) | |
908 { | |
3072 | 909 if (len > 1) |
428 | 910 { |
911 int j; | |
912 stderr_out (" chars=\""); | |
913 for (j=0; j<len; j++) | |
3142 | 914 { |
915 if (040 <= bufptr[j] && bufptr[j] >= 0177) | |
916 { | |
917 stderr_out ("%c", bufptr[j]); | |
918 } | |
919 else | |
920 { | |
921 stderr_out ("\\%o", (unsigned)(bufptr[j])); | |
922 } | |
923 } | |
428 | 924 stderr_out ("\""); |
925 } | |
926 else if (bufptr[0] <= 32 || bufptr[0] >= 127) | |
927 stderr_out (" char=0x%x", bufptr[0]); | |
928 else | |
929 stderr_out (" char=%c", bufptr[0]); | |
930 } | |
931 stderr_out ("\n"); | |
932 } | |
933 #endif /* DEBUG_XEMACS */ | |
934 | |
935 switch (status) | |
936 { | |
937 case XLookupKeySym: | |
938 case XLookupBoth: | |
939 return (IsModifierKey (keysym) || keysym == XK_Mode_switch ) | |
940 ? Qnil : x_keysym_to_emacs_keysym (keysym, simple_p); | |
941 | |
942 case XLookupChars: | |
943 { | |
944 /* Generate multiple emacs events */ | |
945 struct device *d = get_device_from_display (event->display); | |
867 | 946 Ichar ch; |
428 | 947 Lisp_Object instream, fb_instream; |
948 Lstream *istr; | |
949 struct gcpro gcpro1, gcpro2; | |
950 | |
440 | 951 fb_instream = make_fixed_buffer_input_stream (bufptr, len); |
952 | |
3142 | 953 /* [[ Use get_coding_system_for_text_file |
954 (Vcomposed_input_coding_system, 0) ]] | |
955 | |
956 Nope. If it is possible for the X libraries to have multiple IM | |
957 connections on different DISPLAYs active at once, this should be | |
958 a console-specific variable (like a TTY's coding system) but I've | |
959 seen no evidence that that is possible. Aidan Kehoe, | |
960 2005-12-17. */ | |
961 | |
428 | 962 instream = |
771 | 963 make_coding_input_stream |
3142 | 964 (XLSTREAM (fb_instream), Qkeyboard, CODING_DECODE, 0); |
428 | 965 |
966 istr = XLSTREAM (instream); | |
967 | |
968 GCPRO2 (instream, fb_instream); | |
867 | 969 while ((ch = Lstream_get_ichar (istr)) != EOF) |
428 | 970 { |
971 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil); | |
440 | 972 Lisp_Event *ev = XEVENT (emacs_event); |
428 | 973 ev->channel = DEVICE_CONSOLE (d); |
4780
2fd201d73a92
Call character_to_event on characters received from XIM, event-Xt.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
4528
diff
changeset
|
974 XSET_EVENT_TYPE (emacs_event, key_press_event); |
2fd201d73a92
Call character_to_event on characters received from XIM, event-Xt.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
4528
diff
changeset
|
975 /* Make sure space and linefeed and so on get the proper |
2fd201d73a92
Call character_to_event on characters received from XIM, event-Xt.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
4528
diff
changeset
|
976 keysyms. */ |
2fd201d73a92
Call character_to_event on characters received from XIM, event-Xt.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
4528
diff
changeset
|
977 character_to_event (ch, ev, XCONSOLE (ev->channel), |
2fd201d73a92
Call character_to_event on characters received from XIM, event-Xt.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
4528
diff
changeset
|
978 latin_1_maps_to_itself, 0); |
960 | 979 ev->timestamp = event->time; |
1204 | 980 enqueue_dispatch_event (emacs_event); |
428 | 981 } |
982 Lstream_close (istr); | |
983 UNGCPRO; | |
984 Lstream_delete (istr); | |
985 Lstream_delete (XLSTREAM (fb_instream)); | |
986 return Qnil; | |
987 } | |
988 case XLookupNone: return Qnil; | |
989 case XBufferOverflow: | |
2367 | 990 /* !!#### needs work */ |
851 | 991 bufptr = (char *) ALLOCA (len+1); |
428 | 992 bufsiz = len+1; |
993 goto Lookup_String; | |
994 } | |
801 | 995 return Qnil; /* not (usually) reached */ |
428 | 996 #endif /* HAVE_XIM */ |
997 } | |
998 | |
999 static void | |
1000 set_last_server_timestamp (struct device *d, XEvent *x_event) | |
1001 { | |
1002 Time t; | |
1003 switch (x_event->type) | |
1004 { | |
1005 case KeyPress: | |
1006 case KeyRelease: t = x_event->xkey.time; break; | |
1007 case ButtonPress: | |
1008 case ButtonRelease: t = x_event->xbutton.time; break; | |
1009 case EnterNotify: | |
1010 case LeaveNotify: t = x_event->xcrossing.time; break; | |
1011 case MotionNotify: t = x_event->xmotion.time; break; | |
1012 case PropertyNotify: t = x_event->xproperty.time; break; | |
1013 case SelectionClear: t = x_event->xselectionclear.time; break; | |
1014 case SelectionRequest: t = x_event->xselectionrequest.time; break; | |
1015 case SelectionNotify: t = x_event->xselection.time; break; | |
1016 default: return; | |
1017 } | |
1018 DEVICE_X_LAST_SERVER_TIMESTAMP (d) = t; | |
1019 } | |
1020 | |
1021 static int | |
440 | 1022 x_event_to_emacs_event (XEvent *x_event, Lisp_Event *emacs_event) |
428 | 1023 { |
1024 Display *display = x_event->xany.display; | |
1025 struct device *d = get_device_from_display (display); | |
1026 struct x_device *xd = DEVICE_X_DATA (d); | |
1027 | |
1028 if (DEVICE_X_BEING_DELETED (d)) | |
2828 | 1029 { |
1030 /* [[ Uh, is this 0 correct? ]] | |
1031 | |
1032 Yup--it means emacs_Xt_event_handler, the only place that calls | |
1033 this, doesn't queue the emacs_event dispatch, instead immediately | |
1034 deallocating it. */ | |
1035 return 0; | |
1036 } | |
428 | 1037 |
1038 set_last_server_timestamp (d, x_event); | |
1039 | |
1040 switch (x_event->type) | |
1041 { | |
1042 case KeyRelease: | |
934 | 1043 { |
1044 x_handle_sticky_modifiers (x_event, d); | |
1045 return 0; | |
1046 } | |
428 | 1047 case KeyPress: |
1048 case ButtonPress: | |
1049 case ButtonRelease: | |
1050 { | |
442 | 1051 int modifiers = 0; |
428 | 1052 int shift_p, lock_p; |
1053 Bool key_event_p = (x_event->type == KeyPress); | |
1054 unsigned int *state = | |
1055 key_event_p ? &x_event->xkey.state : &x_event->xbutton.state; | |
1056 | |
1057 /* If this is a synthetic KeyPress or Button event, and the user | |
1058 has expressed a disinterest in this security hole, then drop | |
1059 it on the floor. */ | |
1060 if ((key_event_p | |
1061 ? x_event->xkey.send_event | |
1062 : x_event->xbutton.send_event) | |
1063 #ifdef EXTERNAL_WIDGET | |
1064 /* ben: events get sent to an ExternalShell using XSendEvent. | |
1065 This is not a perfect solution. */ | |
1066 && !FRAME_X_EXTERNAL_WINDOW_P | |
1067 (x_any_window_to_frame (d, x_event->xany.window)) | |
1068 #endif | |
1069 && !x_allow_sendevents) | |
1070 return 0; | |
1071 | |
1072 DEVICE_X_MOUSE_TIMESTAMP (d) = | |
1073 DEVICE_X_GLOBAL_MOUSE_TIMESTAMP (d) = | |
1074 key_event_p ? x_event->xkey.time : x_event->xbutton.time; | |
1075 | |
1076 x_handle_sticky_modifiers (x_event, d); | |
1077 | |
442 | 1078 if (*state & ControlMask) modifiers |= XEMACS_MOD_CONTROL; |
1079 if (*state & xd->MetaMask) modifiers |= XEMACS_MOD_META; | |
1080 if (*state & xd->SuperMask) modifiers |= XEMACS_MOD_SUPER; | |
1081 if (*state & xd->HyperMask) modifiers |= XEMACS_MOD_HYPER; | |
1082 if (*state & xd->AltMask) modifiers |= XEMACS_MOD_ALT; | |
1083 { | |
1084 int numero_de_botao = -1; | |
1085 | |
1086 if (!key_event_p) | |
1087 numero_de_botao = x_event->xbutton.button; | |
1088 | |
1089 /* the button gets noted either in the button or the modifiers | |
1090 field, but not both. */ | |
1091 if (numero_de_botao != 1 && (*state & Button1Mask)) | |
1092 modifiers |= XEMACS_MOD_BUTTON1; | |
1093 if (numero_de_botao != 2 && (*state & Button2Mask)) | |
1094 modifiers |= XEMACS_MOD_BUTTON2; | |
1095 if (numero_de_botao != 3 && (*state & Button3Mask)) | |
1096 modifiers |= XEMACS_MOD_BUTTON3; | |
1097 if (numero_de_botao != 4 && (*state & Button4Mask)) | |
1098 modifiers |= XEMACS_MOD_BUTTON4; | |
1099 if (numero_de_botao != 5 && (*state & Button5Mask)) | |
1100 modifiers |= XEMACS_MOD_BUTTON5; | |
1101 } | |
428 | 1102 |
1103 /* Ignore the Caps_Lock key if: | |
1104 - any other modifiers are down, so that Caps_Lock doesn't | |
1105 turn C-x into C-X, which would suck. | |
1106 - the event was a mouse event. */ | |
1107 if (modifiers || ! key_event_p) | |
1108 *state &= (~LockMask); | |
1109 | |
1110 shift_p = *state & ShiftMask; | |
1111 lock_p = *state & LockMask; | |
1112 | |
1113 if (shift_p || lock_p) | |
442 | 1114 modifiers |= XEMACS_MOD_SHIFT; |
428 | 1115 |
1116 if (key_event_p) | |
1117 { | |
1118 Lisp_Object keysym; | |
1119 XKeyEvent *ev = &x_event->xkey; | |
1120 /* This used to compute the frame from the given X window and | |
1121 store it here, but we really don't care about the frame. */ | |
934 | 1122 SET_EVENT_CHANNEL (emacs_event, DEVICE_CONSOLE (d)); |
428 | 1123 keysym = x_to_emacs_keysym (&x_event->xkey, 0); |
1124 | |
1125 /* If the emacs keysym is nil, then that means that the X | |
1126 keysym was either a Modifier or NoSymbol, which | |
1127 probably means that we're in the midst of reading a | |
1128 Multi_key sequence, or a "dead" key prefix, or XIM | |
1129 input. Ignore it. */ | |
1130 if (NILP (keysym)) | |
1131 return 0; | |
1132 | |
3171 | 1133 /* If we have the map from keycodes to the US layout for our |
1134 keyboard available, store the US layout interpretation of | |
1135 that key in the event structure, in case a binding lookup | |
1136 fails and we want to fall back to the US layout binding. | |
1137 | |
1138 This _might_ be possible within an XKB framework, changing | |
1139 the keyboard to a US XKB layout for a moment at startup, | |
1140 storing the correspondance, and changing it back. But that | |
1141 won't work on non-XKB servers, it makes our already slow | |
1142 startup slower, and it's not clear that it's really any | |
1143 easier or more maintainable than storing a correspondence in | |
1144 Lisp. */ | |
1145 | |
1146 if (!NILP(Vx_us_keymap_description) && | |
1147 VECTORP(Vx_us_keymap_description) && | |
1148 ev->keycode >= (unsigned)Vx_us_keymap_first_keycode && | |
1149 ev->keycode | |
1150 < (unsigned)XVECTOR_LENGTH(Vx_us_keymap_description)) | |
1151 { | |
1152 Lisp_Object entr = XVECTOR_DATA(Vx_us_keymap_description) | |
1153 [ev->keycode - Vx_us_keymap_first_keycode]; | |
1154 Ichar alternate = '\0'; | |
1155 | |
1156 if (!NILP (entr)) | |
1157 { | |
1158 if (CHARP(entr)) | |
1159 { | |
1160 alternate = XCHAR(entr); | |
1161 } | |
1162 else if (VECTORP(entr)) | |
1163 { | |
1164 if (modifiers & XEMACS_MOD_SHIFT | |
1165 && XVECTOR_LENGTH(Vx_us_keymap_description) > 1) | |
1166 { | |
1167 entr = XVECTOR_DATA(entr)[1]; | |
1168 if (CHARP(entr)) | |
1169 { | |
1170 alternate = XCHAR(entr); | |
1171 } | |
1172 } | |
1173 else if (XVECTOR_LENGTH(Vx_us_keymap_description) | |
1174 > 0) | |
1175 { | |
1176 entr = XVECTOR_DATA(entr)[0]; | |
1177 if (CHARP(entr)) | |
1178 { | |
1179 alternate = XCHAR(entr); | |
1180 } | |
1181 } | |
1182 } | |
1183 if ('\0' != alternate) | |
1184 { | |
1185 SET_EVENT_KEY_ALT_KEYCHARS(emacs_event, KEYCHAR_QWERTY, | |
1186 alternate); | |
1187 } | |
1188 } | |
1189 } | |
1190 | |
428 | 1191 /* More Caps_Lock garbage: Caps_Lock should *only* add the |
1192 shift modifier to two-case keys (that is, A-Z and | |
1193 related characters). So at this point (after looking up | |
1194 the keysym) if the keysym isn't a dual-case alphabetic, | |
1195 and if the caps lock key was down but the shift key | |
1196 wasn't, then turn off the shift modifier. Gag barf */ | |
2828 | 1197 |
428 | 1198 /* #### type lossage: assuming equivalence of emacs and |
2828 | 1199 X keysyms |
1200 | |
1201 The right thing to do here is to have pass a third, pointer, | |
1202 argument to x_to_emacs_keysym, where it should store the | |
1203 intermediate KeySym it used to calculate the string XEmacs | |
1204 keysym. Then we can call keysym_obeys_caps_lock_p with | |
1205 exactly the right argument. */ | |
3171 | 1206 |
2828 | 1207 /* !!#### maybe fix for Mule |
1208 | |
1209 Hard, in the absence of a full case infrastructure for | |
1210 Mule characters. When | |
1211 (downcase (make-char 'cyrillic-iso8859-5 73)) | |
1212 works, we should revisit it. */ | |
1213 | |
428 | 1214 if (lock_p && !shift_p && |
1215 ! (CHAR_OR_CHAR_INTP (keysym) | |
1216 && keysym_obeys_caps_lock_p | |
1217 ((KeySym) XCHAR_OR_CHAR_INT (keysym), d))) | |
442 | 1218 modifiers &= (~XEMACS_MOD_SHIFT); |
428 | 1219 |
1220 /* If this key contains two distinct keysyms, that is, | |
1221 "shift" generates a different keysym than the | |
1222 non-shifted key, then don't apply the shift modifier | |
1223 bit: it's implicit. Otherwise, if there would be no | |
1224 other way to tell the difference between the shifted | |
1225 and unshifted version of this key, apply the shift bit. | |
1226 Non-graphics, like Backspace and F1 get the shift bit | |
1227 in the modifiers slot. Neither the characters "a", | |
1228 "A", "2", nor "@" normally have the shift bit set. | |
1229 However, "F1" normally does. */ | |
3171 | 1230 |
442 | 1231 if (modifiers & XEMACS_MOD_SHIFT) |
428 | 1232 { |
1233 int Mode_switch_p = *state & xd->ModeMask; | |
1234 KeySym bot = XLookupKeysym (ev, Mode_switch_p ? 2 : 0); | |
1235 KeySym top = XLookupKeysym (ev, Mode_switch_p ? 3 : 1); | |
1236 if (top && bot && top != bot) | |
442 | 1237 modifiers &= ~XEMACS_MOD_SHIFT; |
428 | 1238 } |
934 | 1239 set_event_type (emacs_event, key_press_event); |
1240 SET_EVENT_TIMESTAMP (emacs_event, ev->time); | |
1204 | 1241 SET_EVENT_KEY_MODIFIERS (emacs_event, modifiers); |
1242 SET_EVENT_KEY_KEYSYM (emacs_event, keysym); | |
428 | 1243 } |
1244 else /* Mouse press/release event */ | |
1245 { | |
1246 XButtonEvent *ev = &x_event->xbutton; | |
1247 struct frame *frame = x_window_to_frame (d, ev->window); | |
1248 | |
1249 if (! frame) | |
1250 return 0; /* not for us */ | |
934 | 1251 set_event_type (emacs_event, (x_event->type == ButtonPress) ? |
1252 button_press_event : button_release_event); | |
1204 | 1253 SET_EVENT_CHANNEL (emacs_event, wrap_frame (frame)); |
1254 | |
1255 SET_EVENT_BUTTON_MODIFIERS (emacs_event, modifiers); | |
934 | 1256 SET_EVENT_TIMESTAMP (emacs_event, ev->time); |
1204 | 1257 SET_EVENT_BUTTON_BUTTON (emacs_event, ev->button); |
1258 SET_EVENT_BUTTON_X (emacs_event, ev->x); | |
1259 SET_EVENT_BUTTON_Y (emacs_event, ev->y); | |
428 | 1260 /* because we don't seem to get a FocusIn event for button clicks |
1261 when a widget-glyph is selected we will assume that we want the | |
1262 focus if a button gets pressed. */ | |
1263 if (x_event->type == ButtonPress) | |
1264 handle_focus_event_1 (frame, 1); | |
1265 } | |
1266 } | |
1267 break; | |
1268 | |
1269 case MotionNotify: | |
1270 { | |
1271 XMotionEvent *ev = &x_event->xmotion; | |
1272 struct frame *frame = x_window_to_frame (d, ev->window); | |
442 | 1273 int modifiers = 0; |
428 | 1274 XMotionEvent event2; |
1275 | |
1276 if (! frame) | |
1277 return 0; /* not for us */ | |
1278 | |
1279 /* We use MotionHintMask, so we will get only one motion event | |
1280 until the next time we call XQueryPointer or the user | |
1281 clicks the mouse. So call XQueryPointer now (meaning that | |
1282 the event will be in sync with the server just before | |
1283 Fnext_event() returns). If the mouse is still in motion, | |
1284 then the server will immediately generate exactly one more | |
1285 motion event, which will be on the queue waiting for us | |
1286 next time around. */ | |
1287 event2 = *ev; | |
1288 if (XQueryPointer (event2.display, event2.window, | |
1289 &event2.root, &event2.subwindow, | |
1290 &event2.x_root, &event2.y_root, | |
1291 &event2.x, &event2.y, | |
1292 &event2.state)) | |
1293 ev = &event2; /* only one structure copy */ | |
1294 | |
1295 DEVICE_X_MOUSE_TIMESTAMP (d) = ev->time; | |
1204 | 1296 SET_EVENT_CHANNEL (emacs_event, wrap_frame (frame)); |
934 | 1297 set_event_type (emacs_event, pointer_motion_event); |
1298 SET_EVENT_TIMESTAMP (emacs_event, ev->time); | |
1204 | 1299 SET_EVENT_MOTION_X (emacs_event, ev->x); |
1300 SET_EVENT_MOTION_Y (emacs_event, ev->y); | |
442 | 1301 if (ev->state & ShiftMask) modifiers |= XEMACS_MOD_SHIFT; |
1302 if (ev->state & ControlMask) modifiers |= XEMACS_MOD_CONTROL; | |
1303 if (ev->state & xd->MetaMask) modifiers |= XEMACS_MOD_META; | |
1304 if (ev->state & xd->SuperMask) modifiers |= XEMACS_MOD_SUPER; | |
1305 if (ev->state & xd->HyperMask) modifiers |= XEMACS_MOD_HYPER; | |
1306 if (ev->state & xd->AltMask) modifiers |= XEMACS_MOD_ALT; | |
1307 if (ev->state & Button1Mask) modifiers |= XEMACS_MOD_BUTTON1; | |
1308 if (ev->state & Button2Mask) modifiers |= XEMACS_MOD_BUTTON2; | |
1309 if (ev->state & Button3Mask) modifiers |= XEMACS_MOD_BUTTON3; | |
1310 if (ev->state & Button4Mask) modifiers |= XEMACS_MOD_BUTTON4; | |
1311 if (ev->state & Button5Mask) modifiers |= XEMACS_MOD_BUTTON5; | |
428 | 1312 /* Currently ignores Shift_Lock but probably shouldn't |
1313 (but it definitely should ignore Caps_Lock). */ | |
1204 | 1314 SET_EVENT_MOTION_MODIFIERS (emacs_event, modifiers); |
428 | 1315 } |
1316 break; | |
1317 | |
1318 case ClientMessage: | |
1319 { | |
1320 /* Patch bogus TAKE_FOCUS messages from MWM; CurrentTime is | |
1321 passed as the timestamp of the TAKE_FOCUS, which the ICCCM | |
1322 explicitly prohibits. */ | |
1323 XClientMessageEvent *ev = &x_event->xclient; | |
4790
bc4f2511bbea
Remove support for the OffiX drag-and-drop protocol. See xemacs-patches
Jerry James <james@xemacs.org>
parents:
4780
diff
changeset
|
1324 |
428 | 1325 if (ev->message_type == DEVICE_XATOM_WM_PROTOCOLS (d) |
1326 && (Atom) (ev->data.l[0]) == DEVICE_XATOM_WM_TAKE_FOCUS (d) | |
1327 && (Atom) (ev->data.l[1]) == 0) | |
1328 { | |
1329 ev->data.l[1] = DEVICE_X_LAST_SERVER_TIMESTAMP (d); | |
1330 } | |
1331 } | |
1332 /* fall through */ | |
1333 | |
1334 default: /* it's a magic event */ | |
1335 { | |
1336 struct frame *frame; | |
1337 Window w; | |
934 | 1338 XEvent *x_event_copy; |
1339 SET_EVENT_TYPE (emacs_event, magic_event); | |
1204 | 1340 x_event_copy = &EVENT_MAGIC_X_EVENT (emacs_event); |
428 | 1341 |
1342 #define FROB(event_member, window_member) \ | |
1343 x_event_copy->event_member = x_event->event_member; \ | |
1344 w = x_event->event_member.window_member | |
1345 | |
1346 switch (x_event->type) | |
1347 { | |
1348 case SelectionRequest: FROB(xselectionrequest, owner); break; | |
1349 case SelectionClear: FROB(xselectionclear, window); break; | |
1350 case SelectionNotify: FROB(xselection, requestor); break; | |
1351 case PropertyNotify: FROB(xproperty, window); break; | |
1352 case ClientMessage: FROB(xclient, window); break; | |
1353 case ConfigureNotify: FROB(xconfigure, window); break; | |
1354 case Expose: | |
1355 case GraphicsExpose: FROB(xexpose, window); break; | |
1356 case MapNotify: | |
1357 case UnmapNotify: FROB(xmap, window); break; | |
1358 case EnterNotify: | |
1359 case LeaveNotify: FROB(xcrossing, window); break; | |
1360 case FocusIn: | |
1361 case FocusOut: FROB(xfocus, window); break; | |
1362 case VisibilityNotify: FROB(xvisibility, window); break; | |
442 | 1363 case CreateNotify: FROB(xcreatewindow, window); break; |
428 | 1364 default: |
1365 w = x_event->xany.window; | |
1366 *x_event_copy = *x_event; | |
1367 break; | |
1368 } | |
1369 #undef FROB | |
1370 frame = x_any_window_to_frame (d, w); | |
1371 | |
1372 if (!frame) | |
1373 return 0; | |
1374 | |
1204 | 1375 SET_EVENT_CHANNEL (emacs_event, wrap_frame (frame)); |
428 | 1376 break; |
1377 } | |
1378 } | |
1379 return 1; | |
1380 } | |
1381 | |
1382 | |
1383 | |
1384 /************************************************************************/ | |
1385 /* magic-event handling */ | |
1386 /************************************************************************/ | |
1387 | |
1388 static void | |
1389 handle_focus_event_1 (struct frame *f, int in_p) | |
1390 { | |
863 | 1391 handle_focus_event_2 (XtWindow (FRAME_X_TEXT_WIDGET (f)), f, in_p); |
1392 } | |
1393 | |
1394 static void | |
1395 handle_focus_event_2 (Window win, struct frame *f, int in_p) | |
1396 { | |
1397 /* Although this treats focus differently for all widgets (including | |
1398 the frame) it seems to work ok. */ | |
1399 Widget needs_it = XtWindowToWidget (FRAME_X_DISPLAY (f), win); | |
1400 | |
428 | 1401 #if XtSpecificationRelease > 5 |
450 | 1402 widget_with_focus = XtGetKeyboardFocusWidget (FRAME_X_TEXT_WIDGET (f)); |
428 | 1403 #endif |
1404 #ifdef HAVE_XIM | |
1405 XIM_focus_event (f, in_p); | |
1406 #endif /* HAVE_XIM */ | |
450 | 1407 |
428 | 1408 /* On focus change, clear all memory of sticky modifiers |
1409 to avoid non-intuitive behavior. */ | |
1410 clear_sticky_modifiers (XDEVICE (FRAME_DEVICE (f))); | |
1411 | |
1412 /* We don't want to handle the focus change now, because we might | |
1413 be in an accept-process-output, sleep-for, or sit-for. So | |
1414 we enqueue it. | |
1415 | |
1416 Actually, we half handle it: we handle it as far as changing the | |
1417 box cursor for redisplay, but we don't call any hooks or do any | |
1418 select-frame stuff until after the sit-for. | |
1419 | |
1420 Unfortunately native widgets break the model because they grab | |
1421 the keyboard focus and nothing sets it back again. I cannot find | |
1422 any reasonable way to do this elsewhere so we assert here that | |
1423 the keyboard focus is on the emacs text widget. Menus and dialogs | |
1424 do this in their selection callback, but we don't want that since | |
1425 a button having focus is legitimate. An edit field having focus | |
1426 is mandatory. Weirdly you get a FocusOut event when you click in | |
442 | 1427 a widget-glyph but you don't get a corresponding FocusIn when you |
428 | 1428 click in the frame. Why is this? */ |
438 | 1429 if (in_p |
1430 #if XtSpecificationRelease > 5 | |
863 | 1431 && needs_it != widget_with_focus |
428 | 1432 #endif |
1433 ) | |
1434 { | |
863 | 1435 lw_set_keyboard_focus (FRAME_X_SHELL_WIDGET (f), needs_it); |
428 | 1436 } |
450 | 1437 |
863 | 1438 /* If we are focusing on a native widget then record and exit. */ |
1439 if (needs_it != FRAME_X_TEXT_WIDGET (f)) { | |
1440 widget_with_focus = needs_it; | |
1441 return; | |
1442 } | |
1443 | |
450 | 1444 /* We have the focus now. See comment in |
1445 emacs_Xt_handle_widget_losing_focus (). */ | |
1446 if (in_p) | |
1447 widget_with_focus = NULL; | |
1448 | |
428 | 1449 /* do the generic event-stream stuff. */ |
1450 { | |
1451 Lisp_Object frm; | |
1452 Lisp_Object conser; | |
1453 struct gcpro gcpro1; | |
1454 | |
793 | 1455 frm = wrap_frame (f); |
428 | 1456 conser = Fcons (frm, Fcons (FRAME_DEVICE (f), in_p ? Qt : Qnil)); |
1457 GCPRO1 (conser); | |
1458 emacs_handle_focus_change_preliminary (conser); | |
1459 enqueue_magic_eval_event (emacs_handle_focus_change_final, | |
1460 conser); | |
1461 UNGCPRO; | |
1462 } | |
1463 } | |
1464 | |
863 | 1465 /* Create a synthetic X focus event. */ |
1111 | 1466 void emacs_Xt_enqueue_focus_event (Widget wants_it, Lisp_Object frame, |
1467 int in_p); | |
863 | 1468 void |
1111 | 1469 emacs_Xt_enqueue_focus_event (Widget wants_it, Lisp_Object frame, int in_p) |
863 | 1470 { |
1471 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil); | |
1472 Lisp_Event *ev = XEVENT (emacs_event); | |
960 | 1473 XEvent *x_event; |
1474 | |
1475 XSET_EVENT_TYPE (emacs_event, magic_event); | |
1204 | 1476 x_event = &EVENT_MAGIC_X_EVENT (ev); |
863 | 1477 |
1478 x_event->type = in_p ? FocusIn : FocusOut; | |
1479 x_event->xfocus.window = XtWindow (wants_it); | |
1480 | |
960 | 1481 SET_EVENT_CHANNEL (ev, frame); |
1204 | 1482 |
1483 enqueue_dispatch_event (emacs_event); | |
863 | 1484 } |
1485 | |
450 | 1486 /* The idea here is that when a widget glyph gets unmapped we don't |
1487 want the focus to stay with it if it has focus - because it may | |
863 | 1488 well just get deleted next and then we have lost the focus until the |
450 | 1489 user does something. So handle_focus_event_1 records the widget |
1490 with keyboard focus when FocusOut is processed, and then, when a | |
1491 widget gets unmapped, it calls this function to restore focus if | |
1492 appropriate. */ | |
853 | 1493 void emacs_Xt_handle_widget_losing_focus (struct frame *f, Widget losing_widget); |
450 | 1494 void |
853 | 1495 emacs_Xt_handle_widget_losing_focus (struct frame *f, Widget losing_widget) |
450 | 1496 { |
1497 if (losing_widget == widget_with_focus) | |
1498 { | |
1499 handle_focus_event_1 (f, 1); | |
1500 } | |
1501 } | |
1502 | |
428 | 1503 /* This is called from the external-widget code */ |
1504 | |
1505 void emacs_Xt_handle_focus_event (XEvent *event); | |
1506 void | |
1507 emacs_Xt_handle_focus_event (XEvent *event) | |
1508 { | |
1509 struct device *d = get_device_from_display (event->xany.display); | |
1510 struct frame *f; | |
1511 | |
1512 if (DEVICE_X_BEING_DELETED (d)) | |
1513 return; | |
1514 | |
1515 /* | |
1516 * It's curious that we're using x_any_window_to_frame() instead | |
1517 * of x_window_to_frame(). I don't know what the impact of this is. | |
1518 */ | |
1519 f = x_any_window_to_frame (d, event->xfocus.window); | |
1520 if (!f) | |
1521 /* focus events are sometimes generated just before | |
1522 a frame is destroyed. */ | |
1523 return; | |
1524 handle_focus_event_1 (f, event->type == FocusIn); | |
1525 } | |
1526 | |
1527 /* both MapNotify and VisibilityNotify can cause this | |
1528 JV is_visible has the same semantics as f->visible*/ | |
1529 static void | |
1530 change_frame_visibility (struct frame *f, int is_visible) | |
1531 { | |
793 | 1532 Lisp_Object frame = wrap_frame (f); |
1533 | |
428 | 1534 |
1535 if (!FRAME_VISIBLE_P (f) && is_visible) | |
1536 { | |
1537 FRAME_VISIBLE_P (f) = is_visible; | |
872 | 1538 /* [[ This improves the double flicker when uniconifying a frame |
428 | 1539 some. A lot of it is not showing a buffer which has changed |
1540 while the frame was iconified. To fix it further requires | |
872 | 1541 the good 'ol double redisplay structure. ]] -- comment is |
1542 invalid, obviously predates 19.12, when the double redisplay | |
1543 structure (i.e. current + desired) was put back in. --ben */ | |
428 | 1544 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f); |
1545 va_run_hook_with_args (Qmap_frame_hook, 1, frame); | |
1546 } | |
1547 else if (FRAME_VISIBLE_P (f) && !is_visible) | |
1548 { | |
1549 FRAME_VISIBLE_P (f) = 0; | |
1550 va_run_hook_with_args (Qunmap_frame_hook, 1, frame); | |
1551 } | |
1552 else if (FRAME_VISIBLE_P (f) * is_visible < 0) | |
1553 { | |
1554 FRAME_VISIBLE_P(f) = - FRAME_VISIBLE_P(f); | |
1555 if (FRAME_REPAINT_P(f)) | |
1556 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f); | |
1557 va_run_hook_with_args (Qmap_frame_hook, 1, frame); | |
1558 } | |
1559 } | |
1560 | |
1561 static void | |
593 | 1562 update_frame_iconify_status (struct frame *f) |
1563 { | |
1564 f->iconified = (x_frame_window_state (f) == IconicState); | |
1565 } | |
1566 | |
1567 static void | |
428 | 1568 handle_map_event (struct frame *f, XEvent *event) |
1569 { | |
593 | 1570 |
1571 /* It seems that, given the multiplicity of window managers and X | |
1572 implementations, plus the fact that X was designed without | |
1573 window managers or icons in mind and this was then grafted on | |
1574 with about the skill of a drunk freshman med student attempting | |
1575 surgery with a rusty razor blade, we cannot treat any off | |
1576 MapNotify/UnmapNotify/VisibilityNotify as more than vague hints | |
1577 as to the actual situation. | |
1578 | |
1579 So we should just query the actual status. Unfortunately, things | |
1580 are worse because (a) there aren't obvious ways to query some | |
1581 of these values (e.g. "totally visible"), and (b) there may be | |
1582 race conditions (see below). | |
1583 | |
638 | 1584 However, according to the ICCCM, there's a specific way to |
593 | 1585 ask the window manager whether the state is (a) visible, |
1586 (b) iconic, (c) withdrawn. It must be one of these three. | |
1587 We already use this call to check for the iconified state. | |
1588 I'd suggest we do the same for visible (i.e. NormalState), | |
1589 and scrap most of the nasty code below. | |
1590 | |
1591 --ben | |
1592 */ | |
1593 | |
1594 update_frame_iconify_status (f); | |
1595 | |
1596 /* #### Ben suggests rewriting the code below using | |
1597 x_frame_window_state (f). */ | |
1598 | |
428 | 1599 if (event->type == MapNotify) |
1600 { | |
1601 XWindowAttributes xwa; | |
1602 | |
1603 /* Bleagh!!!!!! Apparently some window managers (e.g. MWM) | |
1604 send synthetic MapNotify events when a window is first | |
1605 created, EVEN IF IT'S CREATED ICONIFIED OR INVISIBLE. | |
1606 Or something like that. We initially tried a different | |
1607 solution below, but that ran into a different window- | |
1608 manager bug. | |
1609 | |
1610 It seems that the only reliable way is to treat a | |
1611 MapNotify event as a "hint" that the window might or | |
1612 might not be visible, and check explicitly. */ | |
1613 | |
1614 XGetWindowAttributes (event->xany.display, event->xmap.window, | |
1615 &xwa); | |
1616 if (xwa.map_state != IsViewable) | |
593 | 1617 return; |
428 | 1618 |
1619 FRAME_X_TOTALLY_VISIBLE_P (f) = 1; | |
1620 #if 0 | |
1621 /* Bleagh again!!!! We initially tried the following hack | |
1622 around the MWM problem, but it turns out that TWM | |
1623 has a race condition when you un-iconify, where it maps | |
1624 the window and then tells the server that the window | |
1625 is un-iconified. Usually, XEmacs wakes up between | |
1626 those two occurrences, and thus thinks that un-iconified | |
1627 windows are still iconified. | |
1628 | |
1629 Ah, the joys of X. */ | |
1630 | |
1631 /* By Emacs definition, a frame that is iconified is not | |
1632 visible. Marking a frame as visible will automatically cause | |
1633 frame-iconified-p to return nil, regardless of whether the | |
1634 frame is actually iconified. Therefore, we have to ignore | |
1635 MapNotify events on iconified frames. (It's not obvious | |
1636 to me why these are being sent, but it happens at startup | |
1637 with frames that are initially iconified; perhaps they are | |
1638 synthetic MapNotify events coming from the window manager.) | |
1639 Note that `frame-iconified-p' queries the server | |
1640 to determine whether the frame is currently iconified, | |
1641 rather than consulting some internal (and likely | |
1642 inaccurate) state flag. Therefore, ignoring the MapNotify | |
1643 is correct. */ | |
793 | 1644 if (!FRAME_VISIBLE_P (f) && NILP (Fframe_iconified_p (wrap_frame (f)))) |
428 | 1645 #endif /* 0 */ |
1646 change_frame_visibility (f, 1); | |
1647 } | |
1648 else | |
1649 { | |
1650 FRAME_X_TOTALLY_VISIBLE_P (f) = 0; | |
1651 change_frame_visibility (f, 0); | |
1652 } | |
1653 } | |
1654 | |
1655 static void | |
1656 handle_client_message (struct frame *f, XEvent *event) | |
1657 { | |
1658 struct device *d = XDEVICE (FRAME_DEVICE (f)); | |
793 | 1659 Lisp_Object frame = wrap_frame (f); |
428 | 1660 |
1661 if (event->xclient.message_type == DEVICE_XATOM_WM_PROTOCOLS (d) && | |
1662 (Atom) (event->xclient.data.l[0]) == DEVICE_XATOM_WM_DELETE_WINDOW (d)) | |
1663 { | |
1664 /* WM_DELETE_WINDOW is a misc-user event, but other ClientMessages, | |
1665 such as WM_TAKE_FOCUS, are eval events. That's because delete-window | |
1666 was probably executed with a mouse click, while the others could | |
1667 have been sent as a result of mouse motion or some other implicit | |
1668 action. (Call this a "heuristic"...) The reason for caring about | |
1669 this is so that clicking on the close-box will make emacs prompt | |
1670 using a dialog box instead of the minibuffer if there are unsaved | |
1671 buffers. | |
1672 */ | |
1673 enqueue_misc_user_event (frame, Qeval, | |
1674 list3 (Qdelete_frame, frame, Qt)); | |
1675 } | |
1676 else if (event->xclient.message_type == DEVICE_XATOM_WM_PROTOCOLS (d) && | |
1677 (Atom) event->xclient.data.l[0] == DEVICE_XATOM_WM_TAKE_FOCUS (d)) | |
1678 { | |
1679 handle_focus_event_1 (f, 1); | |
1680 #if 0 | |
1681 /* If there is a dialog box up, focus on it. | |
1682 | |
1683 #### Actually, we're raising it too, which is wrong. We should | |
1684 #### just focus on it, but lwlib doesn't currently give us an | |
1685 #### easy way to do that. This should be fixed. | |
1686 */ | |
1687 unsigned long take_focus_timestamp = event->xclient.data.l[1]; | |
1688 Widget widget = lw_raise_all_pop_up_widgets (); | |
1689 if (widget) | |
1690 { | |
1691 /* kludge: raise_all returns bottommost widget, but we really | |
1692 want the topmost. So just raise it for now. */ | |
1693 XMapRaised (XtDisplay (widget), XtWindow (widget)); | |
1694 /* Grab the focus with the timestamp of the TAKE_FOCUS. */ | |
1695 XSetInputFocus (XtDisplay (widget), XtWindow (widget), | |
1696 RevertToParent, take_focus_timestamp); | |
1697 } | |
1698 #endif | |
1699 } | |
1700 } | |
1701 | |
448 | 1702 /* #### I'm struggling to understand how the X event loop really works. |
1703 Here is the problem: | |
1704 | |
1705 When widgets get mapped / changed etc the actual display updates | |
1706 are done asynchronously via X events being processed - this | |
1707 normally happens when XtAppProcessEvent() gets called. However, if | |
1708 we are executing lisp code or even doing redisplay we won't | |
1709 necessarily process X events for a very long time. This has the | |
1710 effect of widgets only getting updated when XEmacs only goes into | |
1711 idle, or some other event causes processing of the X event queue. | |
1712 | |
1713 XtAppProcessEvent can get called from the following places: | |
1714 | |
1715 emacs_Xt_next_event () - this is normal event processing, almost | |
1716 any non-X event will take precedence and this means that we | |
1717 cannot rely on it to do the right thing at the right time for | |
1718 widget display. | |
1719 | |
1204 | 1720 emacs_Xt_drain_queue () - this happens when SIGIO gets tripped, |
1721 processing the event queue allows C-g to be checked for. It gets | |
1722 called from emacs_Xt_event_pending_p (). #### Update this comment. | |
448 | 1723 |
1724 In order to solve this I have tried introducing a list primitive - | |
1725 dispatch-non-command-events - which forces processing of X events | |
1726 related to display. Unfortunately this has a number of problems, | |
1727 one is that it is possible for event_stream_event_pending_p to | |
1728 block for ever if there isn't actually an event. I guess this can | |
1729 happen if we drop the synthetic event for reason. It also relies on | |
1730 SIGIO processing which makes things rather fragile. | |
1731 | |
1732 People have seen behaviour whereby XEmacs blocks until you move the | |
1733 mouse. This seems to indicate that dispatch-non-command-events is | |
1734 blocking. It may be that in a SIGIO world forcing SIGIO processing | |
1735 does the wrong thing. | |
1736 */ | |
428 | 1737 static void |
853 | 1738 emacs_Xt_force_event_pending (struct frame *f) |
442 | 1739 { |
1740 XEvent event; | |
1741 | |
853 | 1742 Display *dpy = DEVICE_X_DISPLAY (XDEVICE (FRAME_DEVICE (f))); |
442 | 1743 event.xclient.type = ClientMessage; |
1744 event.xclient.display = dpy; | |
1745 event.xclient.message_type = XInternAtom (dpy, "BumpQueue", False); | |
1746 event.xclient.format = 32; | |
1747 event.xclient.window = 0; | |
1748 | |
1749 /* Send the drop message */ | |
1750 XSendEvent(dpy, XtWindow (FRAME_X_SHELL_WIDGET (f)), | |
1751 True, NoEventMask, &event); | |
448 | 1752 /* We rely on SIGIO and friends to realise we have generated an |
1753 event. */ | |
442 | 1754 } |
1755 | |
1756 static void | |
788 | 1757 emacs_Xt_format_magic_event (Lisp_Event *event, Lisp_Object pstream) |
1758 { | |
1759 Lisp_Object console = CDFW_CONSOLE (EVENT_CHANNEL (event)); | |
1760 if (CONSOLE_X_P (XCONSOLE (console))) | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
1761 write_ascstring |
1204 | 1762 (pstream, x_event_name ((EVENT_MAGIC_X_EVENT (event)).type)); |
788 | 1763 } |
1764 | |
1765 static int | |
1766 emacs_Xt_compare_magic_event (Lisp_Event *e1, Lisp_Event *e2) | |
1767 { | |
1768 if (CONSOLE_X_P (XCONSOLE (CDFW_CONSOLE (EVENT_CHANNEL (e1)))) && | |
1769 CONSOLE_X_P (XCONSOLE (CDFW_CONSOLE (EVENT_CHANNEL (e2))))) | |
1204 | 1770 return ((EVENT_MAGIC_X_EVENT (e1)).xany.serial == |
1771 (EVENT_MAGIC_X_EVENT (e2)).xany.serial); | |
788 | 1772 if (CONSOLE_X_P (XCONSOLE (CDFW_CONSOLE (EVENT_CHANNEL (e1)))) || |
1773 CONSOLE_X_P (XCONSOLE (CDFW_CONSOLE (EVENT_CHANNEL (e2))))) | |
1774 return 0; | |
1775 return 1; | |
1776 } | |
1777 | |
1778 static Hashcode | |
1779 emacs_Xt_hash_magic_event (Lisp_Event *e) | |
1780 { | |
1781 Lisp_Object console = CDFW_CONSOLE (EVENT_CHANNEL (e)); | |
1782 if (CONSOLE_X_P (XCONSOLE (console))) | |
1204 | 1783 return (EVENT_MAGIC_X_EVENT (e)).xany.serial; |
788 | 1784 return 0; |
1785 } | |
1786 | |
1787 static void | |
440 | 1788 emacs_Xt_handle_magic_event (Lisp_Event *emacs_event) |
428 | 1789 { |
1790 /* This function can GC */ | |
1204 | 1791 XEvent *event = &EVENT_MAGIC_X_EVENT (emacs_event); |
428 | 1792 struct frame *f = XFRAME (EVENT_CHANNEL (emacs_event)); |
1793 | |
1794 if (!FRAME_LIVE_P (f) || DEVICE_X_BEING_DELETED (XDEVICE (FRAME_DEVICE (f)))) | |
1795 return; | |
1796 | |
1797 switch (event->type) | |
1798 { | |
1799 case SelectionRequest: | |
1800 x_handle_selection_request (&event->xselectionrequest); | |
1801 break; | |
934 | 1802 |
428 | 1803 case SelectionClear: |
1804 x_handle_selection_clear (&event->xselectionclear); | |
1805 break; | |
934 | 1806 |
428 | 1807 case SelectionNotify: |
1808 x_handle_selection_notify (&event->xselection); | |
1809 break; | |
934 | 1810 |
428 | 1811 case PropertyNotify: |
1812 x_handle_property_notify (&event->xproperty); | |
1813 break; | |
934 | 1814 |
428 | 1815 case Expose: |
1816 if (!check_for_ignored_expose (f, event->xexpose.x, event->xexpose.y, | |
1318 | 1817 event->xexpose.width, |
1818 event->xexpose.height) | |
428 | 1819 && |
1820 !find_matching_subwindow (f, event->xexpose.x, event->xexpose.y, | |
1821 event->xexpose.width, event->xexpose.height)) | |
1318 | 1822 redisplay_redraw_exposed_area (f, event->xexpose.x, event->xexpose.y, |
1823 event->xexpose.width, | |
1824 event->xexpose.height); | |
428 | 1825 break; |
1826 | |
1827 case GraphicsExpose: /* This occurs when an XCopyArea's source area was | |
1828 obscured or not available. */ | |
1318 | 1829 redisplay_redraw_exposed_area (f, event->xexpose.x, event->xexpose.y, |
1830 event->xexpose.width, | |
1831 event->xexpose.height); | |
428 | 1832 break; |
1833 | |
1834 case MapNotify: | |
1835 case UnmapNotify: | |
1836 handle_map_event (f, event); | |
1837 break; | |
1838 | |
1839 case EnterNotify: | |
1840 if (event->xcrossing.detail != NotifyInferior) | |
1841 { | |
793 | 1842 Lisp_Object frame = wrap_frame (f); |
1843 | |
428 | 1844 /* FRAME_X_MOUSE_P (f) = 1; */ |
1845 va_run_hook_with_args (Qmouse_enter_frame_hook, 1, frame); | |
1846 } | |
1847 break; | |
1848 | |
1849 case LeaveNotify: | |
1850 if (event->xcrossing.detail != NotifyInferior) | |
1851 { | |
793 | 1852 Lisp_Object frame = wrap_frame (f); |
1853 | |
428 | 1854 /* FRAME_X_MOUSE_P (f) = 0; */ |
1855 va_run_hook_with_args (Qmouse_leave_frame_hook, 1, frame); | |
1856 } | |
1857 break; | |
1858 | |
1859 case FocusIn: | |
1860 case FocusOut: | |
1861 | |
1862 #ifdef EXTERNAL_WIDGET | |
1863 /* External widget lossage: Ben said: | |
1864 YUCK. The only way to make focus changes work properly is to | |
1865 completely ignore all FocusIn/FocusOut events and depend only | |
1866 on notifications from the ExternalClient widget. */ | |
1867 if (FRAME_X_EXTERNAL_WINDOW_P (f)) | |
1868 break; | |
1869 #endif | |
863 | 1870 handle_focus_event_2 (event->xfocus.window, f, event->type == FocusIn); |
428 | 1871 break; |
1872 | |
1873 case ClientMessage: | |
1874 handle_client_message (f, event); | |
1875 break; | |
1876 | |
1877 case VisibilityNotify: /* window visibility has changed */ | |
1878 if (event->xvisibility.window == XtWindow (FRAME_X_SHELL_WIDGET (f))) | |
1879 { | |
593 | 1880 /* See comment in handle_map_event */ |
1881 update_frame_iconify_status (f); | |
1882 | |
1883 /* #### Ben suggests rewriting the code below using | |
1884 x_frame_window_state (f). */ | |
428 | 1885 FRAME_X_TOTALLY_VISIBLE_P (f) = |
1886 (event->xvisibility.state == VisibilityUnobscured); | |
1887 /* Note that the fvwm pager only sends VisibilityNotify when | |
1888 changing pages. Is this all we need to do ? JV */ | |
1889 /* Nope. We must at least trigger a redisplay here. | |
1890 Since this case seems similar to MapNotify, I've | |
1891 factored out some code to change_frame_visibility(). | |
1892 This triggers the necessary redisplay and runs | |
1893 (un)map-frame-hook. - dkindred@cs.cmu.edu */ | |
1894 /* Changed it again to support the tristate visibility flag */ | |
1895 change_frame_visibility (f, (event->xvisibility.state | |
1896 != VisibilityFullyObscured) ? 1 : -1); | |
1897 } | |
1898 break; | |
1899 | |
1900 case ConfigureNotify: | |
1901 #ifdef HAVE_XIM | |
1902 XIM_SetGeometry (f); | |
1903 #endif | |
1904 break; | |
1905 | |
442 | 1906 case CreateNotify: |
1907 break; | |
1908 | |
428 | 1909 default: |
1910 break; | |
1911 } | |
1912 } | |
1913 | |
1914 | |
1915 /************************************************************************/ | |
1916 /* timeout events */ | |
1917 /************************************************************************/ | |
1918 | |
1919 static int timeout_id_tick; | |
1920 | |
1921 /* Xt interval id's might not fit into an int (they're pointers, as it | |
1922 happens), so we need to provide a conversion list. */ | |
1923 | |
1924 static struct Xt_timeout | |
1925 { | |
1926 int id; | |
1927 XtIntervalId interval_id; | |
1928 struct Xt_timeout *next; | |
1929 } *pending_timeouts, *completed_timeouts; | |
1930 | |
1931 static struct Xt_timeout_blocktype | |
1932 { | |
1933 Blocktype_declare (struct Xt_timeout); | |
1934 } *the_Xt_timeout_blocktype; | |
1935 | |
1936 /* called by XtAppNextEvent() */ | |
1937 static void | |
2286 | 1938 Xt_timeout_callback (XtPointer closure, XtIntervalId *UNUSED (id)) |
428 | 1939 { |
1940 struct Xt_timeout *timeout = (struct Xt_timeout *) closure; | |
1941 struct Xt_timeout *t2 = pending_timeouts; | |
1942 /* Remove this one from the list of pending timeouts */ | |
1943 if (t2 == timeout) | |
1944 pending_timeouts = pending_timeouts->next; | |
1945 else | |
1946 { | |
1947 while (t2->next && t2->next != timeout) t2 = t2->next; | |
1948 assert (t2->next); | |
1949 t2->next = t2->next->next; | |
1950 } | |
1951 /* Add this one to the list of completed timeouts */ | |
1952 timeout->next = completed_timeouts; | |
1953 completed_timeouts = timeout; | |
1954 } | |
1955 | |
1956 static int | |
1957 emacs_Xt_add_timeout (EMACS_TIME thyme) | |
1958 { | |
1959 struct Xt_timeout *timeout = Blocktype_alloc (the_Xt_timeout_blocktype); | |
1960 EMACS_TIME current_time; | |
1961 int milliseconds; | |
1962 | |
1963 timeout->id = timeout_id_tick++; | |
1964 timeout->next = pending_timeouts; | |
1965 pending_timeouts = timeout; | |
1966 EMACS_GET_TIME (current_time); | |
1967 EMACS_SUB_TIME (thyme, thyme, current_time); | |
1968 milliseconds = EMACS_SECS (thyme) * 1000 + | |
1969 EMACS_USECS (thyme) / 1000; | |
1970 if (milliseconds < 1) | |
1971 milliseconds = 1; | |
1972 timeout->interval_id = XtAppAddTimeOut (Xt_app_con, milliseconds, | |
1973 Xt_timeout_callback, | |
1974 (XtPointer) timeout); | |
1975 return timeout->id; | |
1976 } | |
1977 | |
1978 static void | |
1979 emacs_Xt_remove_timeout (int id) | |
1980 { | |
1981 struct Xt_timeout *timeout, *t2; | |
1982 | |
1983 timeout = NULL; | |
1984 | |
1985 /* Find the timeout on the list of pending ones, if it's still there. */ | |
1986 if (pending_timeouts) | |
1987 { | |
1988 if (id == pending_timeouts->id) | |
1989 { | |
1990 timeout = pending_timeouts; | |
1991 pending_timeouts = pending_timeouts->next; | |
1992 } | |
1993 else | |
1994 { | |
1995 t2 = pending_timeouts; | |
1996 while (t2->next && t2->next->id != id) t2 = t2->next; | |
1997 if ( t2->next) /*found it */ | |
1998 { | |
1999 timeout = t2->next; | |
2000 t2->next = t2->next->next; | |
2001 } | |
2002 } | |
2003 /* if it was pending, we have removed it from the list */ | |
2004 if (timeout) | |
2005 XtRemoveTimeOut (timeout->interval_id); | |
2006 } | |
2007 | |
2008 /* It could be that the Xt call back was already called but we didn't convert | |
2009 into an Emacs event yet */ | |
2010 if (!timeout && completed_timeouts) | |
2011 { | |
2012 /* Code duplication! */ | |
2013 if (id == completed_timeouts->id) | |
2014 { | |
2015 timeout = completed_timeouts; | |
2016 completed_timeouts = completed_timeouts->next; | |
2017 } | |
2018 else | |
2019 { | |
2020 t2 = completed_timeouts; | |
2021 while (t2->next && t2->next->id != id) t2 = t2->next; | |
2022 if ( t2->next) /*found it */ | |
2023 { | |
2024 timeout = t2->next; | |
2025 t2->next = t2->next->next; | |
2026 } | |
2027 } | |
2028 } | |
2029 | |
2030 /* If we found the thing on the lists of timeouts, | |
2031 and removed it, deallocate | |
2032 */ | |
2033 if (timeout) | |
2034 Blocktype_free (the_Xt_timeout_blocktype, timeout); | |
2035 } | |
2036 | |
2037 static void | |
440 | 2038 Xt_timeout_to_emacs_event (Lisp_Event *emacs_event) |
428 | 2039 { |
2040 struct Xt_timeout *timeout = completed_timeouts; | |
2041 assert (timeout); | |
2042 completed_timeouts = completed_timeouts->next; | |
934 | 2043 /* timeout events have nil as channel */ |
1204 | 2044 set_event_type (emacs_event, timeout_event); |
934 | 2045 SET_EVENT_TIMESTAMP_ZERO (emacs_event); /* #### wrong!! */ |
1204 | 2046 SET_EVENT_TIMEOUT_INTERVAL_ID (emacs_event, timeout->id); |
2047 SET_EVENT_TIMEOUT_FUNCTION (emacs_event, Qnil); | |
2048 SET_EVENT_TIMEOUT_OBJECT (emacs_event, Qnil); | |
428 | 2049 Blocktype_free (the_Xt_timeout_blocktype, timeout); |
2050 } | |
2051 | |
2052 | |
2053 /************************************************************************/ | |
2054 /* process and tty events */ | |
2055 /************************************************************************/ | |
2056 | |
2057 struct what_is_ready_closure | |
2058 { | |
2059 int fd; | |
2060 Lisp_Object what; | |
2061 XtInputId id; | |
2062 }; | |
2063 | |
2064 static Lisp_Object *filedesc_with_input; | |
2065 static struct what_is_ready_closure **filedesc_to_what_closure; | |
2066 | |
2067 static void | |
2068 init_what_input_once (void) | |
2069 { | |
2070 int i; | |
2071 | |
2072 filedesc_with_input = xnew_array (Lisp_Object, MAXDESC); | |
2073 filedesc_to_what_closure = | |
2074 xnew_array (struct what_is_ready_closure *, MAXDESC); | |
2075 | |
2076 for (i = 0; i < MAXDESC; i++) | |
2077 { | |
2078 filedesc_to_what_closure[i] = 0; | |
2079 filedesc_with_input[i] = Qnil; | |
2080 } | |
2081 | |
2082 process_events_occurred = 0; | |
2083 tty_events_occurred = 0; | |
2084 } | |
2085 | |
2086 static void | |
2087 mark_what_as_being_ready (struct what_is_ready_closure *closure) | |
2088 { | |
2089 if (NILP (filedesc_with_input[closure->fd])) | |
2090 { | |
2091 SELECT_TYPE temp_mask; | |
2092 FD_ZERO (&temp_mask); | |
2093 FD_SET (closure->fd, &temp_mask); | |
2094 /* Check to make sure there's *really* input available. | |
2095 Sometimes things seem to get confused and this gets called | |
2096 for the tty fd when there's really only input available | |
2097 on some process's fd. (It will subsequently get called | |
2098 for that process's fd, so returning without setting any | |
2099 flags will take care of it.) To see the problem, uncomment | |
2100 the stderr_out below, turn NORMAL_QUIT_CHECK_TIMEOUT_MSECS | |
2101 down to 25, do sh -c 'xemacs -nw -q -f shell 2>/tmp/log' | |
2102 and press return repeatedly. (Seen under AIX & Linux.) | |
2103 -dkindred@cs.cmu.edu */ | |
2104 if (!poll_fds_for_input (temp_mask)) | |
2105 { | |
2106 #if 0 | |
2107 stderr_out ("mark_what_as_being_ready: no input available (fd=%d)\n", | |
2108 closure->fd); | |
2109 #endif | |
2110 return; | |
2111 } | |
2112 filedesc_with_input[closure->fd] = closure->what; | |
2113 if (PROCESSP (closure->what)) | |
2114 /* Don't increment this if the current process is already marked | |
2115 * as having input. */ | |
2116 process_events_occurred++; | |
2117 else | |
2118 tty_events_occurred++; | |
2119 } | |
2120 } | |
2121 | |
2122 static void | |
2286 | 2123 Xt_what_callback (void *closure, int *UNUSED (source), XtInputId *UNUSED (id)) |
428 | 2124 { |
2125 /* If closure is 0, then we got a fake event from a signal handler. | |
2126 The only purpose of this is to make XtAppProcessEvent() stop | |
2127 blocking. */ | |
2128 if (closure) | |
2129 mark_what_as_being_ready ((struct what_is_ready_closure *) closure); | |
2130 else | |
2131 { | |
2132 fake_event_occurred++; | |
2133 drain_signal_event_pipe (); | |
2134 } | |
2135 } | |
2136 | |
2137 static void | |
2138 select_filedesc (int fd, Lisp_Object what) | |
2139 { | |
2140 struct what_is_ready_closure *closure; | |
2141 | |
2142 /* If somebody is trying to select something that's already selected | |
2143 for, then something went wrong. The generic routines ought to | |
2144 detect this and error before here. */ | |
2145 assert (!filedesc_to_what_closure[fd]); | |
2146 | |
2147 closure = xnew (struct what_is_ready_closure); | |
2148 closure->fd = fd; | |
2149 closure->what = what; | |
2150 closure->id = | |
2151 XtAppAddInput (Xt_app_con, fd, | |
2152 (XtPointer) (XtInputReadMask /* | XtInputExceptMask */), | |
2153 Xt_what_callback, closure); | |
2154 filedesc_to_what_closure[fd] = closure; | |
2155 } | |
2156 | |
2157 static void | |
2158 unselect_filedesc (int fd) | |
2159 { | |
2160 struct what_is_ready_closure *closure = filedesc_to_what_closure[fd]; | |
2161 | |
2162 assert (closure); | |
2163 if (!NILP (filedesc_with_input[fd])) | |
2164 { | |
2165 /* We are unselecting this process before we have drained the rest of | |
2166 the input from it, probably from status_notify() in the command loop. | |
2167 This can happen like so: | |
2168 | |
2169 - We are waiting in XtAppNextEvent() | |
2170 - Process generates output | |
2171 - Process is marked as being ready | |
2172 - Process dies, SIGCHLD gets generated before we return (!?) | |
2173 It could happen I guess. | |
2174 - sigchld_handler() marks process as dead | |
2175 - Somehow we end up getting a new KeyPress event on the queue | |
2176 at the same time (I'm really so sure how that happens but I'm | |
2177 not sure it can't either so let's assume it can...). | |
2178 - Key events have priority so we return that instead of the proc. | |
2179 - Before dispatching the lisp key event we call status_notify() | |
2180 - Which deselects the process that SIGCHLD marked as dead. | |
2181 | |
2182 Thus we never remove it from _with_input and turn it into a lisp | |
2183 event, so we need to do it here. But this does not mean that we're | |
2184 throwing away the last block of output - status_notify() has already | |
2185 taken care of running the proc filter or whatever. | |
2186 */ | |
2187 filedesc_with_input[fd] = Qnil; | |
2188 if (PROCESSP (closure->what)) | |
2189 { | |
2190 assert (process_events_occurred > 0); | |
2191 process_events_occurred--; | |
2192 } | |
2193 else | |
2194 { | |
2195 assert (tty_events_occurred > 0); | |
2196 tty_events_occurred--; | |
2197 } | |
2198 } | |
2199 XtRemoveInput (closure->id); | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
2200 xfree (closure); |
428 | 2201 filedesc_to_what_closure[fd] = 0; |
2202 } | |
2203 | |
2204 static void | |
853 | 2205 emacs_Xt_select_process (Lisp_Process *process, int doin, int doerr) |
428 | 2206 { |
853 | 2207 Lisp_Object proc; |
2208 int infd, errfd; | |
2209 | |
2210 event_stream_unixoid_select_process (process, doin, doerr, &infd, &errfd); | |
2211 | |
2212 proc = wrap_process (process); | |
2213 if (doin) | |
2214 select_filedesc (infd, proc); | |
2215 if (doerr) | |
2216 select_filedesc (errfd, proc); | |
2217 } | |
2218 | |
2219 static void | |
2220 emacs_Xt_unselect_process (Lisp_Process *process, int doin, int doerr) | |
2221 { | |
2222 int infd, errfd; | |
2223 | |
2224 event_stream_unixoid_unselect_process (process, doin, doerr, &infd, &errfd); | |
2225 | |
2226 if (doin) | |
2227 unselect_filedesc (infd); | |
2228 if (doerr) | |
2229 unselect_filedesc (errfd); | |
428 | 2230 } |
2231 | |
2232 static void | |
853 | 2233 emacs_Xt_create_io_streams (void *inhandle, void *outhandle, |
2234 void *errhandle, Lisp_Object *instream, | |
2235 Lisp_Object *outstream, | |
2236 Lisp_Object *errstream, | |
2237 USID *in_usid, | |
2238 USID *err_usid, | |
2239 int flags) | |
428 | 2240 { |
853 | 2241 event_stream_unixoid_create_io_streams |
2242 (inhandle, outhandle, errhandle, instream, outstream, | |
2243 errstream, in_usid, err_usid, flags); | |
2244 if (*in_usid != USID_ERROR) | |
2245 *in_usid = USID_DONTHASH; | |
2246 if (*err_usid != USID_ERROR) | |
2247 *err_usid = USID_DONTHASH; | |
428 | 2248 } |
2249 | |
853 | 2250 static void |
2251 emacs_Xt_delete_io_streams (Lisp_Object instream, | |
2252 Lisp_Object outstream, | |
2253 Lisp_Object errstream, | |
2254 USID *in_usid, | |
2255 USID *err_usid) | |
428 | 2256 { |
853 | 2257 event_stream_unixoid_delete_io_streams |
2258 (instream, outstream, errstream, in_usid, err_usid); | |
2259 *in_usid = USID_DONTHASH; | |
2260 *err_usid = USID_DONTHASH; | |
428 | 2261 } |
2262 | |
2263 /* This is called from GC when a process object is about to be freed. | |
2264 If we've still got pointers to it in this file, we're gonna lose hard. | |
2265 */ | |
2266 void | |
2286 | 2267 debug_process_finalization (Lisp_Process *UNUSED (p)) |
428 | 2268 { |
2269 #if 0 /* #### */ | |
2270 int i; | |
853 | 2271 Lisp_Object instr, outstr, errstr; |
2272 | |
2273 get_process_streams (p, &instr, &outstr, &errstr); | |
428 | 2274 /* if it still has fds, then it hasn't been killed yet. */ |
2275 assert (NILP(instr)); | |
2276 assert (NILP(outstr)); | |
853 | 2277 assert (NILP(errstr)); |
428 | 2278 /* Better not still be in the "with input" table; we know it's got no fds. */ |
2279 for (i = 0; i < MAXDESC; i++) | |
2280 { | |
2281 Lisp_Object process = filedesc_fds_with_input [i]; | |
2282 assert (!PROCESSP (process) || XPROCESS (process) != p); | |
2283 } | |
2284 #endif | |
2285 } | |
2286 | |
2287 static void | |
440 | 2288 Xt_process_to_emacs_event (Lisp_Event *emacs_event) |
428 | 2289 { |
2290 int i; | |
2291 | |
2292 assert (process_events_occurred > 0); | |
438 | 2293 |
428 | 2294 for (i = 0; i < MAXDESC; i++) |
2295 { | |
438 | 2296 Lisp_Object process = filedesc_with_input[i]; |
428 | 2297 if (PROCESSP (process)) |
438 | 2298 { |
2299 filedesc_with_input[i] = Qnil; | |
2300 process_events_occurred--; | |
2301 /* process events have nil as channel */ | |
934 | 2302 set_event_type (emacs_event, process_event); |
2303 SET_EVENT_TIMESTAMP_ZERO (emacs_event); /* #### */ | |
1204 | 2304 SET_EVENT_PROCESS_PROCESS (emacs_event, process); |
438 | 2305 return; |
2306 } | |
428 | 2307 } |
2500 | 2308 ABORT (); |
428 | 2309 } |
2310 | |
2311 static void | |
2312 emacs_Xt_select_console (struct console *con) | |
2313 { | |
2314 Lisp_Object console; | |
2315 int infd; | |
2316 | |
2317 if (CONSOLE_X_P (con)) | |
2318 return; /* X consoles are automatically selected for when we | |
2319 initialize them in Xt */ | |
2320 infd = event_stream_unixoid_select_console (con); | |
793 | 2321 console = wrap_console (con); |
428 | 2322 select_filedesc (infd, console); |
2323 } | |
2324 | |
2325 static void | |
2326 emacs_Xt_unselect_console (struct console *con) | |
2327 { | |
2328 int infd; | |
2329 | |
2330 if (CONSOLE_X_P (con)) | |
2331 return; /* X consoles are automatically selected for when we | |
2332 initialize them in Xt */ | |
2333 infd = event_stream_unixoid_unselect_console (con); | |
2334 unselect_filedesc (infd); | |
2335 } | |
2336 | |
2337 /* read an event from a tty, if one is available. Returns non-zero | |
2338 if an event was available. Note that when this function is | |
2339 called, there should always be a tty marked as ready for input. | |
2340 However, the input condition might actually be EOF, so there | |
2341 may not really be any input available. (In this case, | |
2342 read_event_from_tty_or_stream_desc() will arrange for the TTY device | |
2343 to be deleted.) */ | |
2344 | |
2345 static int | |
440 | 2346 Xt_tty_to_emacs_event (Lisp_Event *emacs_event) |
428 | 2347 { |
2348 int i; | |
2349 | |
2350 assert (tty_events_occurred > 0); | |
2351 for (i = 0; i < MAXDESC; i++) | |
2352 { | |
2353 Lisp_Object console = filedesc_with_input[i]; | |
2354 if (CONSOLEP (console)) | |
2355 { | |
2356 assert (tty_events_occurred > 0); | |
2357 tty_events_occurred--; | |
2358 filedesc_with_input[i] = Qnil; | |
771 | 2359 if (read_event_from_tty_or_stream_desc (emacs_event, |
2360 XCONSOLE (console))) | |
428 | 2361 return 1; |
2362 } | |
2363 } | |
2364 | |
2365 return 0; | |
2366 } | |
2367 | |
2368 | |
2369 /************************************************************************/ | |
2370 /* debugging functions to decipher an event */ | |
2371 /************************************************************************/ | |
2372 | |
2373 #ifdef DEBUG_XEMACS | |
2374 #include "xintrinsicp.h" /* only describe_event() needs this */ | |
2375 #include <X11/Xproto.h> /* only describe_event() needs this */ | |
2376 | |
2377 static void | |
788 | 2378 describe_event_window (Window window, Display *display, Lisp_Object pstream) |
428 | 2379 { |
2380 struct frame *f; | |
2381 Widget w; | |
788 | 2382 write_fmt_string (pstream, " window: 0x%lx", (unsigned long) window); |
428 | 2383 w = XtWindowToWidget (display, window); |
2384 if (w) | |
788 | 2385 write_fmt_string (pstream, " %s", |
2386 w->core.widget_class->core_class.class_name); | |
428 | 2387 f = x_any_window_to_frame (get_device_from_display (display), window); |
2388 if (f) | |
788 | 2389 write_fmt_string_lisp (pstream, " \"%s\"", 1, f->name); |
2390 write_fmt_string (pstream, "\n"); | |
428 | 2391 } |
2392 | |
442 | 2393 static const char * |
428 | 2394 XEvent_mode_to_string (int mode) |
2395 { | |
2396 switch (mode) | |
2397 { | |
2398 case NotifyNormal: return "Normal"; | |
2399 case NotifyGrab: return "Grab"; | |
2400 case NotifyUngrab: return "Ungrab"; | |
2401 case NotifyWhileGrabbed: return "WhileGrabbed"; | |
2402 default: return "???"; | |
2403 } | |
2404 } | |
2405 | |
442 | 2406 static const char * |
428 | 2407 XEvent_detail_to_string (int detail) |
2408 { | |
2409 switch (detail) | |
2410 { | |
2411 case NotifyAncestor: return "Ancestor"; | |
2412 case NotifyInferior: return "Inferior"; | |
2413 case NotifyNonlinear: return "Nonlinear"; | |
2414 case NotifyNonlinearVirtual: return "NonlinearVirtual"; | |
2415 case NotifyPointer: return "Pointer"; | |
2416 case NotifyPointerRoot: return "PointerRoot"; | |
2417 case NotifyDetailNone: return "DetailNone"; | |
2418 default: return "???"; | |
2419 } | |
2420 } | |
2421 | |
442 | 2422 static const char * |
428 | 2423 XEvent_visibility_to_string (int state) |
2424 { | |
2425 switch (state) | |
2426 { | |
2427 case VisibilityFullyObscured: return "FullyObscured"; | |
2428 case VisibilityPartiallyObscured: return "PartiallyObscured"; | |
2429 case VisibilityUnobscured: return "Unobscured"; | |
2430 default: return "???"; | |
2431 } | |
2432 } | |
2433 | |
2434 static void | |
788 | 2435 describe_event (XEvent *event, Lisp_Object pstream) |
428 | 2436 { |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4790
diff
changeset
|
2437 Ascbyte buf[100]; |
428 | 2438 struct device *d = get_device_from_display (event->xany.display); |
2439 | |
2440 sprintf (buf, "%s%s", x_event_name (event->type), | |
2441 event->xany.send_event ? " (send)" : ""); | |
788 | 2442 write_fmt_string (pstream, "%-30s", buf); |
428 | 2443 switch (event->type) |
2444 { | |
2445 case FocusIn: | |
2446 case FocusOut: | |
2447 { | |
2448 XFocusChangeEvent *ev = &event->xfocus; | |
788 | 2449 describe_event_window (ev->window, ev->display, pstream); |
2450 write_fmt_string (pstream, " mode: %s\n", | |
2451 XEvent_mode_to_string (ev->mode)); | |
2452 write_fmt_string (pstream, " detail: %s\n", | |
2453 XEvent_detail_to_string (ev->detail)); | |
428 | 2454 break; |
2455 } | |
2456 | |
2457 case KeyPress: | |
2458 { | |
2459 XKeyEvent *ev = &event->xkey; | |
2460 unsigned int state = ev->state; | |
2461 | |
788 | 2462 describe_event_window (ev->window, ev->display, pstream); |
2463 write_fmt_string (pstream, " subwindow: %ld\n", ev->subwindow); | |
2464 write_fmt_string (pstream, " state: "); | |
428 | 2465 /* Complete list of modifier key masks */ |
788 | 2466 if (state & ShiftMask) write_fmt_string (pstream, "Shift "); |
2467 if (state & LockMask) write_fmt_string (pstream, "Lock "); | |
2468 if (state & ControlMask) write_fmt_string (pstream, "Control "); | |
2469 if (state & Mod1Mask) write_fmt_string (pstream, "Mod1 "); | |
2470 if (state & Mod2Mask) write_fmt_string (pstream, "Mod2 "); | |
2471 if (state & Mod3Mask) write_fmt_string (pstream, "Mod3 "); | |
2472 if (state & Mod4Mask) write_fmt_string (pstream, "Mod4 "); | |
2473 if (state & Mod5Mask) write_fmt_string (pstream, "Mod5 "); | |
428 | 2474 |
2475 if (! state) | |
788 | 2476 write_fmt_string (pstream, "vanilla\n"); |
428 | 2477 else |
788 | 2478 write_fmt_string (pstream, "\n"); |
428 | 2479 if (x_key_is_modifier_p (ev->keycode, d)) |
788 | 2480 write_fmt_string (pstream, " Modifier key"); |
2481 write_fmt_string (pstream, " keycode: 0x%x\n", ev->keycode); | |
428 | 2482 } |
2483 break; | |
2484 | |
2485 case Expose: | |
442 | 2486 if (debug_x_events > 1) |
428 | 2487 { |
2488 XExposeEvent *ev = &event->xexpose; | |
788 | 2489 describe_event_window (ev->window, ev->display, pstream); |
2490 write_fmt_string (pstream, | |
2491 " region: x=%d y=%d width=%d height=%d\n", | |
428 | 2492 ev->x, ev->y, ev->width, ev->height); |
788 | 2493 write_fmt_string (pstream, " count: %d\n", ev->count); |
428 | 2494 } |
2495 else | |
788 | 2496 write_fmt_string (pstream, "\n"); |
428 | 2497 break; |
2498 | |
2499 case GraphicsExpose: | |
442 | 2500 if (debug_x_events > 1) |
428 | 2501 { |
2502 XGraphicsExposeEvent *ev = &event->xgraphicsexpose; | |
788 | 2503 describe_event_window (ev->drawable, ev->display, pstream); |
2504 write_fmt_string (pstream, " major: %s\n", | |
428 | 2505 (ev ->major_code == X_CopyArea ? "CopyArea" : |
2506 (ev->major_code == X_CopyPlane ? "CopyPlane" : "?"))); | |
788 | 2507 write_fmt_string (pstream, |
2508 " region: x=%d y=%d width=%d height=%d\n", | |
428 | 2509 ev->x, ev->y, ev->width, ev->height); |
788 | 2510 write_fmt_string (pstream, " count: %d\n", ev->count); |
428 | 2511 } |
2512 else | |
788 | 2513 write_fmt_string (pstream, "\n"); |
428 | 2514 break; |
2515 | |
2516 case EnterNotify: | |
2517 case LeaveNotify: | |
442 | 2518 if (debug_x_events > 1) |
428 | 2519 { |
2520 XCrossingEvent *ev = &event->xcrossing; | |
788 | 2521 describe_event_window (ev->window, ev->display, pstream); |
428 | 2522 #if 0 |
788 | 2523 write_fmt_string (pstream, " subwindow: 0x%x\n", ev->subwindow); |
2524 write_fmt_string (pstream, " pos: %d %d\n", ev->x, ev->y); | |
2525 write_fmt_string (pstream, " root pos: %d %d\n", ev->x_root, | |
2526 ev->y_root); | |
428 | 2527 #endif |
788 | 2528 write_fmt_string (pstream, " mode: %s\n", |
2529 XEvent_mode_to_string(ev->mode)); | |
2530 write_fmt_string (pstream, " detail: %s\n", | |
2531 XEvent_detail_to_string(ev->detail)); | |
2532 write_fmt_string (pstream, " focus: %d\n", ev->focus); | |
428 | 2533 #if 0 |
788 | 2534 write_fmt_string (pstream, " state: 0x%x\n", ev->state); |
428 | 2535 #endif |
2536 } | |
2537 else | |
788 | 2538 write_fmt_string (pstream, "\n"); |
428 | 2539 break; |
2540 | |
2541 case ConfigureNotify: | |
442 | 2542 if (debug_x_events > 1) |
428 | 2543 { |
2544 XConfigureEvent *ev = &event->xconfigure; | |
788 | 2545 describe_event_window (ev->window, ev->display, pstream); |
2546 write_fmt_string (pstream, " above: 0x%lx\n", ev->above); | |
2547 write_fmt_string (pstream, " size: %d %d %d %d\n", ev->x, ev->y, | |
428 | 2548 ev->width, ev->height); |
788 | 2549 write_fmt_string (pstream, " redirect: %d\n", |
2550 ev->override_redirect); | |
428 | 2551 } |
2552 else | |
788 | 2553 write_fmt_string (pstream, "\n"); |
428 | 2554 break; |
2555 | |
2556 case VisibilityNotify: | |
442 | 2557 if (debug_x_events > 1) |
428 | 2558 { |
2559 XVisibilityEvent *ev = &event->xvisibility; | |
788 | 2560 describe_event_window (ev->window, ev->display, pstream); |
2561 write_fmt_string (pstream, " state: %s\n", | |
2562 XEvent_visibility_to_string (ev->state)); | |
428 | 2563 } |
2564 else | |
788 | 2565 write_fmt_string (pstream, "\n"); |
428 | 2566 break; |
2567 | |
2568 case ClientMessage: | |
2569 { | |
2570 XClientMessageEvent *ev = &event->xclient; | |
2571 char *name = XGetAtomName (ev->display, ev->message_type); | |
788 | 2572 write_fmt_string (pstream, "%s", name); |
2573 if (!strcmp (name, "WM_PROTOCOLS")) | |
2574 { | |
2575 char *protname = XGetAtomName (ev->display, ev->data.l[0]); | |
2576 write_fmt_string (pstream, "(%s)", protname); | |
2577 XFree (protname); | |
2578 } | |
428 | 2579 XFree (name); |
788 | 2580 write_fmt_string (pstream, "\n"); |
428 | 2581 break; |
2582 } | |
2583 | |
2584 default: | |
788 | 2585 write_fmt_string (pstream, "\n"); |
428 | 2586 break; |
2587 } | |
2588 | |
2589 fflush (stdout); | |
2590 } | |
2591 | |
2592 #endif /* include describe_event definition */ | |
2593 | |
2594 | |
2595 /************************************************************************/ | |
2596 /* get the next event from Xt */ | |
2597 /************************************************************************/ | |
2598 | |
2599 /* This business exists because menu events "happen" when | |
2600 menubar_selection_callback() is called from somewhere deep | |
2601 within XtAppProcessEvent in emacs_Xt_next_event(). The | |
2602 callback needs to terminate the modal loop in that function | |
2603 or else it will continue waiting until another event is | |
2604 received. | |
2605 | |
2606 Same business applies to scrollbar events. */ | |
2607 | |
2608 void | |
2609 signal_special_Xt_user_event (Lisp_Object channel, Lisp_Object function, | |
2610 Lisp_Object object) | |
2611 { | |
2612 Lisp_Object event = Fmake_event (Qnil, Qnil); | |
2613 | |
934 | 2614 XSET_EVENT_TYPE (event, misc_user_event); |
2615 XSET_EVENT_CHANNEL (event, channel); | |
1204 | 2616 XSET_EVENT_MISC_USER_FUNCTION (event, function); |
2617 XSET_EVENT_MISC_USER_OBJECT (event, object); | |
2618 enqueue_dispatch_event (event); | |
428 | 2619 } |
2620 | |
2621 static void | |
440 | 2622 emacs_Xt_next_event (Lisp_Event *emacs_event) |
428 | 2623 { |
2624 we_didnt_get_an_event: | |
2625 | |
2626 while (NILP (dispatch_event_queue) && | |
2627 !completed_timeouts && | |
2628 !fake_event_occurred && | |
2629 !process_events_occurred && | |
2630 !tty_events_occurred) | |
2631 { | |
1268 | 2632 if (in_modal_loop) |
2633 { | |
2634 /* in_modal_loop gets set when we are in the process of | |
2635 dispatching an event (more specifically, when we are inside of | |
2636 a menu callback -- if we get here, it means we called a filter | |
2637 and the filter did something that tried to fetch an event, | |
2638 e.g. sit-for). In such a case, we cannot safely dispatch any | |
2639 more events. This is because those dispatching those events | |
2640 could cause lwlib to be entered reentranty, specifically if | |
2641 they are menu events. lwlib is not designed for this and will | |
2642 crash. We used to see this crash constantly as a result of | |
2643 QUIT checking, but QUIT will not now function in a modal loop. | |
2644 However, we can't just not process any events at all, because | |
2645 that will make sit-for etc. hang. So we go ahead and process | |
2646 the non-X kinds of events. */ | |
1292 | 2647 #ifdef WIN32_ANY |
2648 mswindows_is_blocking = 1; | |
2649 #endif | |
2650 XtAppProcessEvent (Xt_app_con, XtIMTimer | XtIMAlternateInput); | |
2651 #ifdef WIN32_ANY | |
2652 mswindows_is_blocking = 0; | |
2653 #endif | |
1268 | 2654 } |
428 | 2655 else |
2656 { | |
1268 | 2657 /* Stupid logic in XtAppProcessEvent() dictates that, if process |
2658 events and X events are both available, the process event gets | |
2659 taken first. This will cause an infinite loop if we're being | |
2660 called from Fdiscard_input(). | |
2661 */ | |
2662 | |
2663 if (XtAppPending (Xt_app_con) & XtIMXEvent) | |
2664 XtAppProcessEvent (Xt_app_con, XtIMXEvent); | |
2665 else | |
428 | 2666 { |
1268 | 2667 Lisp_Object devcons, concons; |
2668 | |
2669 /* We're about to block. Xt has a bug in it (big surprise, | |
2670 there) in that it blocks using select() and doesn't | |
2671 flush the Xlib output buffers (XNextEvent() does this | |
2672 automatically before blocking). So it's necessary | |
2673 for us to do this ourselves. If we don't do it, then | |
2674 display output may not be seen until the next time | |
2675 an X event is received. (This happens esp. with | |
2676 subprocess output that gets sent to a visible buffer.) | |
2677 | |
2678 #### The above comment may not have any validity. */ | |
2679 | |
2680 DEVICE_LOOP_NO_BREAK (devcons, concons) | |
2681 { | |
2682 struct device *d; | |
2683 d = XDEVICE (XCAR (devcons)); | |
2684 | |
2685 if (DEVICE_X_P (d) && DEVICE_X_DISPLAY (d)) | |
2686 /* emacs may be exiting */ | |
2687 XFlush (DEVICE_X_DISPLAY (d)); | |
2688 } | |
1292 | 2689 #ifdef WIN32_ANY |
2690 mswindows_is_blocking = 1; | |
2691 #endif | |
1268 | 2692 XtAppProcessEvent (Xt_app_con, XtIMAll); |
1292 | 2693 #ifdef WIN32_ANY |
2694 mswindows_is_blocking = 0; | |
2695 #endif | |
428 | 2696 } |
2697 } | |
2698 } | |
2699 | |
2700 if (!NILP (dispatch_event_queue)) | |
2701 { | |
2702 Lisp_Object event, event2; | |
793 | 2703 event2 = wrap_event (emacs_event); |
1204 | 2704 event = dequeue_dispatch_event (); |
428 | 2705 Fcopy_event (event, event2); |
2706 Fdeallocate_event (event); | |
2707 } | |
2708 else if (tty_events_occurred) | |
2709 { | |
2710 if (!Xt_tty_to_emacs_event (emacs_event)) | |
2711 goto we_didnt_get_an_event; | |
2712 } | |
2713 else if (completed_timeouts) | |
2714 Xt_timeout_to_emacs_event (emacs_event); | |
2715 else if (fake_event_occurred) | |
2716 { | |
2717 /* A dummy event, so that a cycle of the command loop will occur. */ | |
2718 fake_event_occurred = 0; | |
2719 /* eval events have nil as channel */ | |
934 | 2720 set_event_type (emacs_event, eval_event); |
1204 | 2721 SET_EVENT_EVAL_FUNCTION (emacs_event, Qidentity); |
2722 SET_EVENT_EVAL_OBJECT (emacs_event, Qnil); | |
428 | 2723 } |
2724 else /* if (process_events_occurred) */ | |
2725 Xt_process_to_emacs_event (emacs_event); | |
2726 | |
2727 /* No need to call XFilterEvent; Xt does it for us */ | |
2728 } | |
2729 | |
2730 void | |
2286 | 2731 emacs_Xt_event_handler (Widget UNUSED (wid), |
2732 XtPointer UNUSED (closure), | |
428 | 2733 XEvent *event, |
2286 | 2734 Boolean *UNUSED (continue_to_dispatch)) |
428 | 2735 { |
2736 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil); | |
2737 | |
2738 #ifdef DEBUG_XEMACS | |
442 | 2739 if (debug_x_events > 0) |
788 | 2740 describe_event (event, Qexternal_debugging_output); |
428 | 2741 #endif /* DEBUG_XEMACS */ |
2742 if (x_event_to_emacs_event (event, XEVENT (emacs_event))) | |
1204 | 2743 enqueue_dispatch_event (emacs_event); |
428 | 2744 else |
2745 Fdeallocate_event (emacs_event); | |
2746 } | |
2747 | |
2748 | |
2749 /************************************************************************/ | |
1204 | 2750 /* input pending */ |
428 | 2751 /************************************************************************/ |
2752 | |
2753 static void | |
1204 | 2754 emacs_Xt_drain_queue (void) |
428 | 2755 { |
2756 Lisp_Object devcons, concons; | |
1268 | 2757 if (!in_modal_loop) |
428 | 2758 { |
1268 | 2759 CONSOLE_LOOP (concons) |
428 | 2760 { |
1268 | 2761 struct console *con = XCONSOLE (XCAR (concons)); |
2762 if (!con->input_enabled) | |
2763 continue; | |
2764 | |
2765 CONSOLE_DEVICE_LOOP (devcons, con) | |
1204 | 2766 { |
1268 | 2767 struct device *d; |
2768 Display *display; | |
2769 d = XDEVICE (XCAR (devcons)); | |
2770 if (DEVICE_X_P (d) && DEVICE_X_DISPLAY (d)) | |
2771 { | |
2772 display = DEVICE_X_DISPLAY (d); | |
2773 while (XEventsQueued (display, QueuedAfterReading)) | |
2774 XtAppProcessEvent (Xt_app_con, XtIMXEvent); | |
2775 } | |
1204 | 2776 } |
428 | 2777 } |
1268 | 2778 /* |
2779 while (XtAppPending (Xt_app_con) & XtIMXEvent) | |
2780 XtAppProcessEvent (Xt_app_con, XtIMXEvent); | |
2781 */ | |
428 | 2782 } |
1268 | 2783 |
2784 #ifdef HAVE_TTY | |
1204 | 2785 drain_tty_devices (); |
428 | 2786 #endif |
2787 } | |
2788 | |
1204 | 2789 int |
2790 check_if_pending_expose_event (struct device *dev) | |
2791 { | |
2792 Display *d = DEVICE_X_DISPLAY (dev); | |
2793 Lisp_Object event; | |
2794 | |
2795 emacs_Xt_drain_queue (); | |
2796 | |
2797 EVENT_CHAIN_LOOP (event, dispatch_event_queue) | |
2798 if (XEVENT_TYPE (event) == magic_event) | |
2799 { | |
2800 XEvent *xev = &XEVENT_MAGIC_X_EVENT (event); | |
2801 if (xev->type == Expose && | |
2802 xev->xexpose.display == d) | |
2803 return 1; | |
2804 } | |
2805 | |
2806 return 0; | |
2807 } | |
2808 | |
442 | 2809 static int |
2810 emacs_Xt_current_event_timestamp (struct console *c) | |
2811 { | |
2812 /* semi-yuck. */ | |
2813 Lisp_Object devs = CONSOLE_DEVICE_LIST (c); | |
2814 | |
2815 if (NILP (devs)) | |
2816 return 0; | |
2817 else | |
2818 { | |
2819 struct device *d = XDEVICE (XCAR (devs)); | |
2820 return DEVICE_X_LAST_SERVER_TIMESTAMP (d); | |
2821 } | |
2822 } | |
2823 | |
428 | 2824 |
2825 /************************************************************************/ | |
2826 /* replacement for standard string-to-pixel converter */ | |
2827 /************************************************************************/ | |
2828 | |
2829 /* This was constructed by ripping off the standard string-to-pixel | |
2830 converter from Converters.c in the Xt source code and modifying | |
2831 appropriately. */ | |
2832 | |
2833 #if 0 | |
2834 | |
2835 /* This is exported by the Xt library (at least by mine). If this | |
2836 isn't the case somewhere, rename this appropriately and remove | |
2837 the '#if 0'. Note, however, that I got "unknown structure" | |
2838 errors when I tried this. */ | |
2839 XtConvertArgRec Const colorConvertArgs[] = { | |
440 | 2840 { XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.screen), |
2841 sizeof (Screen *) }, | |
2842 { XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.colormap), | |
2843 sizeof (Colormap) } | |
428 | 2844 }; |
2845 | |
2846 #endif | |
2847 | |
2848 #define done(type, value) \ | |
2849 if (toVal->addr != NULL) { \ | |
2850 if (toVal->size < sizeof(type)) { \ | |
2851 toVal->size = sizeof(type); \ | |
2852 return False; \ | |
2853 } \ | |
2854 *(type*)(toVal->addr) = (value); \ | |
2855 } else { \ | |
2856 static type static_val; \ | |
2857 static_val = (value); \ | |
2858 toVal->addr = (XPointer)&static_val; \ | |
2859 } \ | |
2860 toVal->size = sizeof(type); \ | |
2861 return True /* Caller supplies `;' */ | |
2862 | |
2863 /* JH: We use this because I think there's a possibility this | |
2864 is called before the device is properly set up, in which case | |
2865 I don't want to abort. */ | |
2866 extern struct device *get_device_from_display_1 (Display *dpy); | |
2867 | |
2868 static | |
2869 Boolean EmacsXtCvtStringToPixel ( | |
2870 Display *dpy, | |
2871 XrmValuePtr args, | |
2872 Cardinal *num_args, | |
2873 XrmValuePtr fromVal, | |
2874 XrmValuePtr toVal, | |
2875 XtPointer *closure_ret) | |
2876 { | |
2877 String str = (String)fromVal->addr; | |
2878 XColor screenColor; | |
2879 XColor exactColor; | |
2880 Screen *screen; | |
2881 Colormap colormap; | |
2882 Visual *visual; | |
2883 struct device *d; | |
2884 Status status; | |
2885 String params[1]; | |
2886 Cardinal num_params = 1; | |
2887 XtAppContext the_app_con = XtDisplayToApplicationContext (dpy); | |
2888 | |
2889 if (*num_args != 2) { | |
2890 XtAppWarningMsg(the_app_con, "wrongParameters", "cvtStringToPixel", | |
2891 "XtToolkitError", | |
2892 "String to pixel conversion needs screen and colormap arguments", | |
2893 (String *)NULL, (Cardinal *)NULL); | |
2894 return False; | |
2895 } | |
2896 | |
2897 screen = *((Screen **) args[0].addr); | |
2898 colormap = *((Colormap *) args[1].addr); | |
2899 | |
2900 /* The original uses the private function CompareISOLatin1(). | |
2901 Use XmuCompareISOLatin1() if you want, but I don't think it | |
2902 makes any difference here. */ | |
2903 if (strcmp(str, XtDefaultBackground) == 0) { | |
2904 *closure_ret = False; | |
2905 /* This refers to the display's "*reverseVideo" resource. | |
2906 These display resources aren't documented anywhere that | |
2907 I can find, so I'm going to ignore this. */ | |
2908 /* if (pd->rv) done(Pixel, BlackPixelOfScreen(screen)) else */ | |
2909 done(Pixel, WhitePixelOfScreen(screen)); | |
2910 } | |
2911 if (strcmp(str, XtDefaultForeground) == 0) { | |
2912 *closure_ret = False; | |
2913 /* if (pd->rv) done(Pixel, WhitePixelOfScreen(screen)) else */ | |
2914 done(Pixel, BlackPixelOfScreen(screen)); | |
2915 } | |
2916 | |
2917 /* Originally called XAllocNamedColor() here. */ | |
2918 if ((d = get_device_from_display_1(dpy))) { | |
2919 visual = DEVICE_X_VISUAL(d); | |
2920 if (colormap != DEVICE_X_COLORMAP(d)) { | |
442 | 2921 XtAppWarningMsg(the_app_con, "weirdColormap", "cvtStringToPixel", |
428 | 2922 "XtToolkitWarning", |
442 | 2923 "The colormap passed to cvtStringToPixel doesn't match the one registered to the device.\n", |
428 | 2924 NULL, 0); |
2925 status = XAllocNamedColor(dpy, colormap, (char*)str, &screenColor, &exactColor); | |
2926 } else { | |
2927 status = XParseColor (dpy, colormap, (char*)str, &screenColor); | |
2928 if (status) { | |
3094 | 2929 status = x_allocate_nearest_color (dpy, colormap, visual, &screenColor); |
428 | 2930 } |
2931 } | |
2932 } else { | |
2933 /* We haven't set up this device totally yet, so just punt */ | |
2934 status = XAllocNamedColor(dpy, colormap, (char*)str, &screenColor, &exactColor); | |
2935 } | |
2936 if (status == 0) { | |
2937 params[0] = str; | |
2938 /* Server returns a specific error code but Xlib discards it. Ugh */ | |
2939 if (XLookupColor(DisplayOfScreen(screen), colormap, (char*) str, | |
2940 &exactColor, &screenColor)) { | |
2941 XtAppWarningMsg(the_app_con, "noColormap", "cvtStringToPixel", | |
2942 "XtToolkitError", | |
2943 "Cannot allocate colormap entry for \"%s\"", | |
2944 params, &num_params); | |
2945 | |
2946 } else { | |
2947 XtAppWarningMsg(the_app_con, "badValue", "cvtStringToPixel", | |
2948 "XtToolkitError", | |
2949 "Color name \"%s\" is not defined", params, &num_params); | |
2950 } | |
2951 | |
2952 *closure_ret = False; | |
2953 return False; | |
2954 } else { | |
2955 *closure_ret = (char*)True; | |
2956 done(Pixel, screenColor.pixel); | |
2957 } | |
2958 } | |
2959 | |
2960 /* ARGSUSED */ | |
2961 static void EmacsFreePixel ( | |
2962 XtAppContext app, | |
2963 XrmValuePtr toVal, | |
2964 XtPointer closure, | |
2965 XrmValuePtr args, | |
2966 Cardinal *num_args) | |
2967 { | |
2968 if (*num_args != 2) { | |
2969 XtAppWarningMsg(app, "wrongParameters","freePixel","XtToolkitError", | |
2970 "Freeing a pixel requires screen and colormap arguments", | |
2971 (String *)NULL, (Cardinal *)NULL); | |
2972 return; | |
2973 } | |
2974 | |
2975 if (closure) { | |
2976 Screen *screen = *((Screen **) args[0].addr); | |
2977 Colormap colormap = *((Colormap *) args[1].addr); | |
2978 XFreeColors(DisplayOfScreen(screen), colormap, | |
2979 (unsigned long*)toVal->addr, 1, (unsigned long)0); | |
2980 } | |
2981 } | |
2982 | |
2983 | |
2984 /************************************************************************/ | |
442 | 2985 /* handle focus changes for native widgets */ |
2986 /************************************************************************/ | |
2987 static void | |
2988 emacs_Xt_event_widget_focus_in (Widget w, | |
2989 XEvent *event, | |
2286 | 2990 String *UNUSED (params), |
2991 Cardinal *UNUSED (num_params)) | |
442 | 2992 { |
853 | 2993 struct frame *f = |
442 | 2994 x_any_widget_or_parent_to_frame (get_device_from_display (event->xany.display), w); |
2995 | |
2996 XtSetKeyboardFocus (FRAME_X_SHELL_WIDGET (f), w); | |
2997 } | |
2998 | |
2999 static void | |
2286 | 3000 emacs_Xt_event_widget_focus_out (Widget UNUSED (w), |
3001 XEvent *UNUSED (event), | |
3002 String *UNUSED (params), | |
3003 Cardinal *UNUSED (num_params)) | |
442 | 3004 { |
3005 } | |
3006 | |
3007 static XtActionsRec widgetActionsList[] = | |
3008 { | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
3009 { (String) "widget-focus-in", emacs_Xt_event_widget_focus_in }, |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
3010 { (String) "widget-focus-out", emacs_Xt_event_widget_focus_out }, |
442 | 3011 }; |
3012 | |
3013 static void | |
3014 emacs_Xt_event_add_widget_actions (XtAppContext ctx) | |
3015 { | |
3016 XtAppAddActions (ctx, widgetActionsList, 2); | |
3017 } | |
3018 | |
3019 | |
3020 /************************************************************************/ | |
428 | 3021 /* initialization */ |
3022 /************************************************************************/ | |
3023 | |
3024 void | |
3025 syms_of_event_Xt (void) | |
3026 { | |
563 | 3027 DEFSYMBOL (Qsans_modifiers); |
3028 DEFSYMBOL (Qself_insert_command); | |
428 | 3029 } |
3030 | |
3031 void | |
3032 reinit_vars_of_event_Xt (void) | |
3033 { | |
1204 | 3034 Xt_event_stream = xnew_and_zero (struct event_stream); |
428 | 3035 Xt_event_stream->event_pending_p = emacs_Xt_event_pending_p; |
1204 | 3036 Xt_event_stream->force_event_pending_cb= emacs_Xt_force_event_pending; |
428 | 3037 Xt_event_stream->next_event_cb = emacs_Xt_next_event; |
3038 Xt_event_stream->handle_magic_event_cb = emacs_Xt_handle_magic_event; | |
788 | 3039 Xt_event_stream->format_magic_event_cb = emacs_Xt_format_magic_event; |
3040 Xt_event_stream->compare_magic_event_cb= emacs_Xt_compare_magic_event; | |
3041 Xt_event_stream->hash_magic_event_cb = emacs_Xt_hash_magic_event; | |
428 | 3042 Xt_event_stream->add_timeout_cb = emacs_Xt_add_timeout; |
3043 Xt_event_stream->remove_timeout_cb = emacs_Xt_remove_timeout; | |
3044 Xt_event_stream->select_console_cb = emacs_Xt_select_console; | |
3045 Xt_event_stream->unselect_console_cb = emacs_Xt_unselect_console; | |
3046 Xt_event_stream->select_process_cb = emacs_Xt_select_process; | |
3047 Xt_event_stream->unselect_process_cb = emacs_Xt_unselect_process; | |
1204 | 3048 Xt_event_stream->drain_queue_cb = emacs_Xt_drain_queue; |
853 | 3049 Xt_event_stream->create_io_streams_cb = emacs_Xt_create_io_streams; |
3050 Xt_event_stream->delete_io_streams_cb = emacs_Xt_delete_io_streams; | |
442 | 3051 Xt_event_stream->current_event_timestamp_cb = |
3052 emacs_Xt_current_event_timestamp; | |
428 | 3053 |
3054 the_Xt_timeout_blocktype = Blocktype_new (struct Xt_timeout_blocktype); | |
3055 | |
3056 last_quit_check_signal_tick_count = 0; | |
3057 | |
3058 /* this function only makes safe calls */ | |
3059 init_what_input_once (); | |
3060 } | |
3061 | |
3062 void | |
3063 vars_of_event_Xt (void) | |
3064 { | |
3065 DEFVAR_BOOL ("x-allow-sendevents", &x_allow_sendevents /* | |
3066 *Non-nil means to allow synthetic events. Nil means they are ignored. | |
3067 Beware: allowing emacs to process SendEvents opens a big security hole. | |
3068 */ ); | |
3069 x_allow_sendevents = 0; | |
3070 | |
3071 #ifdef DEBUG_XEMACS | |
442 | 3072 DEFVAR_INT ("debug-x-events", &debug_x_events /* |
428 | 3073 If non-zero, display debug information about X events that XEmacs sees. |
3074 Information is displayed on stderr. Currently defined values are: | |
3075 | |
3076 1 == non-verbose output | |
3077 2 == verbose output | |
3078 */ ); | |
442 | 3079 debug_x_events = 0; |
428 | 3080 #endif |
3171 | 3081 DEFVAR_LISP ("x-us-keymap-description", &Vx_us_keymap_description /* |
3082 X11-specific vector describing the current keyboard hardware, and how to map | |
3083 from its keycodes to those alphanumeric and punctuation characters that | |
3084 would be produced by it if a US layout were configured in software. | |
3085 | |
3086 We use this to make possible the usage of standard key bindings on keyboards | |
3087 where the keys that those bindings assume are not available; for example, on | |
3088 a Russian keyboard, one can type C-Cyrillic_che C-Cyrillic_a and have XEmacs | |
3089 use the binding for C-x C-f, rather than give an error message that | |
3090 C-Cyrillic_che C-Cyrillic_a is not bound. | |
3091 | |
3092 Entries are either nil, which means the corresponding key code does not map | |
3093 to a non-function key in the US layout, a single character, meaning it maps to | |
3094 that character, or a vector of two characters, the first indicating the | |
3095 unshifted mapping, the second the shifted mapping for the US layout. | |
3096 | |
3097 `x-us-keymap-first-keycode' tells XEmacs the keycode of the first entry in | |
3098 this vector. | |
3099 */ ); | |
3100 Vx_us_keymap_description = Qnil; | |
3101 | |
3102 DEFVAR_INT ("x-us-keymap-first-keycode", &Vx_us_keymap_first_keycode /* | |
3103 The X11 keycode that the first entry in `x-us-keymap-description' | |
3104 corresponds to. See the documentation for that variable. | |
3105 | |
3106 The X11 documentation for XDisplayKeycodes says this can never be less than | |
3107 8, but XEmacs doesn't enforce any limitation on what you set it to. | |
3108 */ ); | |
3109 Vx_us_keymap_first_keycode = 0; | |
428 | 3110 } |
3111 | |
3112 /* This mess is a hack that patches the shell widget to treat visual inheritance | |
3113 the same as colormap and depth inheritance */ | |
3114 | |
3115 static XtInitProc orig_shell_init_proc; | |
3116 | |
2956 | 3117 static void ShellVisualPatch(Widget wanted, Widget new_, |
428 | 3118 ArgList args, Cardinal *num_args) |
3119 { | |
3120 Widget p; | |
2956 | 3121 ShellWidget w = (ShellWidget) new_; |
428 | 3122 |
3123 /* first, call the original setup */ | |
2956 | 3124 (*orig_shell_init_proc)(wanted, new_, args, num_args); |
428 | 3125 |
3126 /* if the visual isn't explicitly set, grab it from the nearest shell ancestor */ | |
3127 if (w->shell.visual == CopyFromParent) { | |
3128 p = XtParent(w); | |
3129 while (p && !XtIsShell(p)) p = XtParent(p); | |
3130 if (p) w->shell.visual = ((ShellWidget)p)->shell.visual; | |
3131 } | |
3132 } | |
3133 | |
3134 void | |
3135 init_event_Xt_late (void) /* called when already initialized */ | |
3136 { | |
3137 timeout_id_tick = 1; | |
3138 pending_timeouts = 0; | |
3139 completed_timeouts = 0; | |
3140 | |
3141 event_stream = Xt_event_stream; | |
3142 | |
3143 XtToolkitInitialize (); | |
3144 Xt_app_con = XtCreateApplicationContext (); | |
3145 XtAppSetFallbackResources (Xt_app_con, (String *) x_fallback_resources); | |
3146 | |
442 | 3147 /* In select-x.c */ |
428 | 3148 x_selection_timeout = (XtAppGetSelectionTimeout (Xt_app_con) / 1000); |
3149 XSetErrorHandler (x_error_handler); | |
3150 XSetIOErrorHandler (x_IO_error_handler); | |
3151 | |
442 | 3152 #ifndef WIN32_NATIVE |
428 | 3153 XtAppAddInput (Xt_app_con, signal_event_pipe[0], |
3154 (XtPointer) (XtInputReadMask /* | XtInputExceptMask */), | |
3155 Xt_what_callback, 0); | |
3156 #endif | |
3157 | |
3158 XtAppSetTypeConverter (Xt_app_con, XtRString, XtRPixel, | |
3159 EmacsXtCvtStringToPixel, | |
3160 (XtConvertArgList) colorConvertArgs, | |
3161 2, XtCacheByDisplay, EmacsFreePixel); | |
3162 | |
3163 #ifdef XIM_XLIB | |
3164 XtAppSetTypeConverter (Xt_app_con, XtRString, XtRXimStyles, | |
3165 EmacsXtCvtStringToXIMStyles, | |
3166 NULL, 0, | |
3167 XtCacheByDisplay, EmacsFreeXIMStyles); | |
3168 #endif /* XIM_XLIB */ | |
442 | 3169 /* Add extra actions to native widgets to handle focus and friends. */ |
3170 emacs_Xt_event_add_widget_actions (Xt_app_con); | |
428 | 3171 |
3172 /* insert the visual inheritance patch/hack described above */ | |
3173 orig_shell_init_proc = shellClassRec.core_class.initialize; | |
3174 shellClassRec.core_class.initialize = ShellVisualPatch; | |
3175 | |
3176 } |