annotate src/event-gtk.c @ 826:6728e641994e

[xemacs-hg @ 2002-05-05 11:30:15 by ben] syntax cache, 8-bit-format, lots of code cleanup README.packages: Update info about --package-path. i.c: Create an inheritable event and pass it on to XEmacs, so that ^C can be handled properly. Intercept ^C and signal the event. "Stop Build" in VC++ now works. bytecomp-runtime.el: Doc string changes. compat.el: Some attempts to redo this to make it truly useful and fix the "multiple versions interacting with each other" problem. Not yet done. Currently doesn't work. files.el: Use with-obsolete-variable to avoid warnings in new revert-buffer code. xemacs.mak: Split up CFLAGS into a version without flags specifying the C library. The problem seems to be that minitar depends on zlib, which depends specifically on libc.lib, not on any of the other C libraries. Unless you compile with libc.lib, you get errors -- specifically, no _errno in the other libraries, which must make it something other than an int. (#### But this doesn't seem to obtain in XEmacs, which also uses zlib, and can be linked with any of the C libraries. Maybe zlib is used differently and doesn't need errno, or maybe XEmacs provides an int errno; ... I don't understand. Makefile.in.in: Fix so that packages are around when testing. abbrev.c, alloc.c, buffer.c, buffer.h, bytecode.c, callint.c, casefiddle.c, casetab.c, casetab.h, charset.h, chartab.c, chartab.h, cmds.c, console-msw.h, console-stream.c, console-x.c, console.c, console.h, data.c, device-msw.c, device.c, device.h, dialog-msw.c, dialog-x.c, dired-msw.c, dired.c, doc.c, doprnt.c, dumper.c, editfns.c, elhash.c, emacs.c, eval.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, events.c, events.h, extents.c, extents.h, faces.c, file-coding.c, file-coding.h, fileio.c, fns.c, font-lock.c, frame-gtk.c, frame-msw.c, frame-x.c, frame.c, frame.h, glade.c, glyphs-gtk.c, glyphs-msw.c, glyphs-msw.h, glyphs-x.c, glyphs.c, glyphs.h, gui-msw.c, gui-x.c, gui.h, gutter.h, hash.h, indent.c, insdel.c, intl-win32.c, intl.c, keymap.c, lisp-disunion.h, lisp-union.h, lisp.h, lread.c, lrecord.h, lstream.c, lstream.h, marker.c, menubar-gtk.c, menubar-msw.c, menubar-x.c, menubar.c, minibuf.c, mule-ccl.c, mule-charset.c, mule-coding.c, mule-wnnfns.c, nas.c, objects-msw.c, objects-x.c, opaque.c, postgresql.c, print.c, process-nt.c, process-unix.c, process.c, process.h, profile.c, rangetab.c, redisplay-gtk.c, redisplay-msw.c, redisplay-output.c, redisplay-x.c, redisplay.c, redisplay.h, regex.c, regex.h, scrollbar-msw.c, search.c, select-x.c, specifier.c, specifier.h, symbols.c, symsinit.h, syntax.c, syntax.h, syswindows.h, tests.c, text.c, text.h, tooltalk.c, ui-byhand.c, ui-gtk.c, unicode.c, win32.c, window.c: Another big Ben patch. -- FUNCTIONALITY CHANGES: add partial support for 8-bit-fixed, 16-bit-fixed, and 32-bit-fixed formats. not quite done yet. (in particular, needs functions to actually convert the buffer.) NOTE: lots of changes to regex.c here. also, many new *_fmt() inline funs that take an Internal_Format argument. redo syntax cache code. make the cache per-buffer; keep the cache valid across calls to functions that use it. also keep it valid across insertions/deletions and extent changes, as much as is possible. eliminate the junky regex-reentrancy code by passing in the relevant lisp info to the regex routines as local vars. add general mechanism in extents code for signalling extent changes. fix numerous problems with the case-table implementation; yoshiki never properly transferred many algorithms from old-style to new-style case tables. redo char tables to support a default argument, so that mapping only occurs over changed args. change many chartab functions to accept Lisp_Object instead of Lisp_Char_Table *. comment out the code in font-lock.c by default, because font-lock.el no longer uses it. we should consider eliminating it entirely. Don't output bell as ^G in console-stream when not a TTY. add -mswindows-termination-handle to interface with i.c, so we can properly kill a build. add more error-checking to buffer/string macros. add some additional buffer_or_string_() funs. -- INTERFACE CHANGES AFFECTING MORE CODE: switch the arguments of write_c_string and friends to be consistent with write_fmt_string, which must have printcharfun first. change BI_* macros to BYTE_* for increased clarity; similarly for bi_* local vars. change VOID_TO_LISP to be a one-argument function. eliminate no-longer-needed CVOID_TO_LISP. -- char/string macro changes: rename MAKE_CHAR() to make_emchar() for slightly less confusion with make_char(). (The former generates an Emchar, the latter a Lisp object. Conceivably we should rename make_char() -> wrap_char() and similarly for make_int(), make_float().) Similar changes for other *CHAR* macros -- we now consistently use names with `emchar' whenever we are working with Emchars. Any remaining name with just `char' always refers to a Lisp object. rename macros with XSTRING_* to string_* except for those that reference actual fields in the Lisp_String object, following conventions used elsewhere. rename set_string_{data,length} macros (the only ones to work with a Lisp_String_* instead of a Lisp_Object) to set_lispstringp_* to make the difference clear. try to be consistent about caps vs. lowercase in macro/inline-fun names for chars and such, which wasn't the case before. we now reserve caps either for XFOO_ macros that reference object fields (e.g. XSTRING_DATA) or for things that have non-function semantics, e.g. directly modifying an arg (BREAKUP_EMCHAR) or evaluating an arg (any arg) more than once. otherwise, use lowercase. here is a summary of most of the macros/inline funs changed by all of the above changes: BYTE_*_P -> byte_*_p XSTRING_BYTE -> string_byte set_string_data/length -> set_lispstringp_data/length XSTRING_CHAR_LENGTH -> string_char_length XSTRING_CHAR -> string_emchar INTBYTE_FIRST_BYTE_P -> intbyte_first_byte_p INTBYTE_LEADING_BYTE_P -> intbyte_leading_byte_p charptr_copy_char -> charptr_copy_emchar LEADING_BYTE_* -> leading_byte_* CHAR_* -> EMCHAR_* *_CHAR_* -> *_EMCHAR_* *_CHAR -> *_EMCHAR CHARSET_BY_ -> charset_by_* BYTE_SHIFT_JIS* -> byte_shift_jis* BYTE_BIG5* -> byte_big5* REP_BYTES_BY_FIRST_BYTE -> rep_bytes_by_first_byte char_to_unicode -> emchar_to_unicode valid_char_p -> valid_emchar_p Change intbyte_strcmp -> qxestrcmp_c (duplicated functionality). -- INTERFACE CHANGES AFFECTING LESS CODE: use DECLARE_INLINE_HEADER in various places. remove '#ifdef emacs' from XEmacs-only files. eliminate CHAR_TABLE_VALUE(), which duplicated the functionality of get_char_table(). add BUFFER_TEXT_LOOP to simplify iterations over buffer text. define typedefs for signed and unsigned types of fixed sizes (INT_32_BIT, UINT_32_BIT, etc.). create ALIGN_FOR_TYPE as a higher-level interface onto ALIGN_SIZE; fix code to use it. add charptr_emchar_len to return the text length of the character pointed to by a ptr; use it in place of charcount_to_bytecount(..., 1). add emchar_len to return the text length of a given character. add types Bytexpos and Charxpos to generalize Bytebpos/Bytecount and Charbpos/Charcount, in code (particularly, the extents code and redisplay code) that works with either kind of index. rename redisplay struct params with names such as `charbpos' to e.g. `charpos' when they are e.g. a Charxpos, not a Charbpos. eliminate xxDEFUN in place of DEFUN; no longer necessary with changes awhile back to doc.c. split up big ugly combined list of EXFUNs in lisp.h on a file-by-file basis, since other prototypes are similarly split. rewrite some "*_UNSAFE" macros as inline funs and eliminate the _UNSAFE suffix. move most string code from lisp.h to text.h; the string code and text.h code is now intertwined in such a fashion that they need to be in the same place and partially interleaved. (you can't create forward references for inline funs) automated/lisp-tests.el, automated/symbol-tests.el, automated/test-harness.el: Fix test harness to output FAIL messages to stderr when in batch mode. Fix up some problems in lisp-tests/symbol-tests that were causing spurious failures.
author ben
date Sun, 05 May 2002 11:33:57 +0000
parents 285f13b079f3
children 2b6fa2618f76
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1 /* The event_stream interface for X11 with gtk, and/or tty frames.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2 Copyright (C) 1991-5, 1997 Free Software Foundation, Inc.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
3 Copyright (C) 1995 Sun Microsystems, Inc.
788
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
4 Copyright (C) 1996, 2001, 2002 Ben Wing.
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
5 Copyright (C) 2000 William Perry.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
6
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
7 This file is part of XEmacs.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
8
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
9 XEmacs is free software; you can redistribute it and/or modify it
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
10 under the terms of the GNU General Public License as published by the
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
11 Free Software Foundation; either version 2, or (at your option) any
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
12 later version.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
13
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
17 for more details.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
18
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
20 along with XEmacs; see the file COPYING. If not, write to
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
22 Boston, MA 02111-1307, USA. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
23
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
24 /* This file is heavily based upon event-Xt.c */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
25
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
26 /* Synched up with: Not in FSF. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
27
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
28 #include <config.h>
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
29 #include "lisp.h"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
30
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
31 #include "console-gtk.h"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
32
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
33 #include "blocktype.h"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
34 #include "buffer.h"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
35 #include "commands.h"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
36 #include "console.h"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
37 #include "console-tty.h"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
38 #include "events.h"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
39 #include "frame.h"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
40 #include "objects-gtk.h"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
41 #include "process.h"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
42 #include "redisplay.h"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
43 #include "elhash.h"
809
285f13b079f3 [xemacs-hg @ 2002-04-07 16:01:30 by wmperry]
wmperry
parents: 800
diff changeset
44 #include "window.h"
285f13b079f3 [xemacs-hg @ 2002-04-07 16:01:30 by wmperry]
wmperry
parents: 800
diff changeset
45 #include "device.h"
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
46
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
47 #include "gtk-xemacs.h"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
48
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
49 #include "systime.h"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
50 #include "sysproc.h" /* for MAXDESC */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
51
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
52 #include "lstream.h"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
53 #include "file-coding.h"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
54
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
55 #include <gdk/gdkkeysyms.h>
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
56
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
57 #ifdef HAVE_DRAGNDROP
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
58 #include "dragdrop.h"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
59 #endif
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
60
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
61 #if defined (HAVE_OFFIX_DND)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
62 #include "offix.h"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
63 #endif
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
64
778
2923009caf47 [xemacs-hg @ 2002-03-16 10:38:59 by ben]
ben
parents: 771
diff changeset
65 #include <gdk/gdkx.h>
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
66
778
2923009caf47 [xemacs-hg @ 2002-03-16 10:38:59 by ben]
ben
parents: 771
diff changeset
67 #include "event-gtk.h"
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
68
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
69 static struct event_stream *gtk_event_stream;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
70
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
71 /* Do we accept events sent by other clients? */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
72 int gtk_allow_sendevents;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
73
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
74 static int process_events_occurred;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
75 static int tty_events_occurred;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
76
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
77 /* Mask of bits indicating the descriptors that we wait for input on */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
78 extern SELECT_TYPE input_wait_mask, process_only_mask, tty_only_mask;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
79
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
80 static Lisp_Object gtk_keysym_to_emacs_keysym ();
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
81 void debug_process_finalization (struct Lisp_Process *p);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
82 gboolean emacs_gtk_event_handler (GtkWidget *wid /* unused */,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
83 GdkEvent *event,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
84 gpointer closure /* unused */);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
85
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
86 static int last_quit_check_signal_tick_count;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
87
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
88 Lisp_Object Qkey_mapping;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
89 Lisp_Object Qsans_modifiers;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
90
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
91 static void enqueue_gtk_dispatch_event (Lisp_Object event);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
92
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
93 #define IS_MODIFIER_KEY(keysym) \
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
94 ((((keysym) >= GDK_Shift_L) && ((keysym) <= GDK_Hyper_R)) \
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
95 || ((keysym) == GDK_Mode_switch) \
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
96 || ((keysym) == GDK_Num_Lock))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
97
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
98
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
99
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
100 /************************************************************************/
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
101 /* magic-event handling */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
102 /************************************************************************/
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
103 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
104 handle_focus_event_1 (struct frame *f, int in_p)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
105 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
106 /* We don't want to handle the focus change now, because we might
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
107 be in an accept-process-output, sleep-for, or sit-for. So
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
108 we enqueue it.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
109
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
110 Actually, we half handle it: we handle it as far as changing the
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
111 box cursor for redisplay, but we don't call any hooks or do any
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
112 select-frame stuff until after the sit-for.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
113 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
114
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
115 if (in_p)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
116 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
117 GTK_WIDGET_SET_FLAGS (FRAME_GTK_TEXT_WIDGET (f), GTK_HAS_FOCUS);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
118 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
119 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
120 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
121 GTK_WIDGET_UNSET_FLAGS (FRAME_GTK_TEXT_WIDGET (f), GTK_HAS_FOCUS);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
122 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
123 gtk_widget_grab_focus (FRAME_GTK_TEXT_WIDGET (f));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
124 gtk_widget_draw_focus (FRAME_GTK_TEXT_WIDGET (f));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
125
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
126 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
127 Lisp_Object frm;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
128 Lisp_Object conser;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
129 struct gcpro gcpro1;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
130
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 790
diff changeset
131 frm = wrap_frame (f);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
132 conser = Fcons (frm, Fcons (FRAME_DEVICE (f), in_p ? Qt : Qnil));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
133 GCPRO1 (conser);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
134
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
135 emacs_handle_focus_change_preliminary (conser);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
136 enqueue_magic_eval_event (emacs_handle_focus_change_final,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
137 conser);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
138 UNGCPRO;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
139 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
140 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
141
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
142 /* both GDK_MAP and GDK_VISIBILITY_NOTIFY can cause this
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
143 JV is_visible has the same semantics as f->visible*/
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
144 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
145 change_frame_visibility (struct frame *f, int is_visible)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
146 {
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 790
diff changeset
147 Lisp_Object frame = wrap_frame (f);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
148
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
149
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
150 if (!FRAME_VISIBLE_P (f) && is_visible)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
151 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
152 FRAME_VISIBLE_P (f) = is_visible;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
153 /* This improves the double flicker when uniconifying a frame
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
154 some. A lot of it is not showing a buffer which has changed
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
155 while the frame was iconified. To fix it further requires
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
156 the good 'ol double redisplay structure. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
157 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
158 va_run_hook_with_args (Qmap_frame_hook, 1, frame);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
159 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
160 else if (FRAME_VISIBLE_P (f) && !is_visible)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
161 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
162 FRAME_VISIBLE_P (f) = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
163 va_run_hook_with_args (Qunmap_frame_hook, 1, frame);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
164 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
165 else if (FRAME_VISIBLE_P (f) * is_visible < 0)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
166 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
167 FRAME_VISIBLE_P(f) = - FRAME_VISIBLE_P(f);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
168 if (FRAME_REPAINT_P (f))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
169 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
170 va_run_hook_with_args (Qmap_frame_hook, 1, frame);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
171 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
172 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
173
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
174 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
175 handle_map_event (struct frame *f, GdkEvent *event)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
176 {
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 790
diff changeset
177 Lisp_Object frame = wrap_frame (f);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
178
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
179 if (event->any.type == GDK_MAP)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
180 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
181 FRAME_GTK_TOTALLY_VISIBLE_P (f) = 1;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
182 change_frame_visibility (f, 1);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
183 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
184 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
185 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
186 FRAME_GTK_TOTALLY_VISIBLE_P (f) = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
187 change_frame_visibility (f, 0);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
188 /* Calling Fframe_iconified_p is the only way we have to
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
189 correctly update FRAME_ICONIFIED_P */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
190 Fframe_iconified_p (frame);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
191 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
192 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
193
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
194 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
195 handle_client_message (struct frame *f, GdkEvent *event)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
196 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
197 /* The event-Xt code used to handle WM_DELETE_WINDOW here, but we
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
198 handle that directly in frame-gtk.c */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
199
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
200 if (event->client.message_type == gdk_atom_intern ("WM_PROTOCOLS", 0) &&
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
201 (GdkAtom) event->client.data.l[0] == gdk_atom_intern ("WM_TAKE_FOCUS", 0))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
202 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
203 handle_focus_event_1 (f, 1);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
204 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
205 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
206
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
207 static void
788
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
208 emacs_gtk_format_magic_event (Lisp_Event *emacs_event, Lisp_Object pstream)
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
209 {
789
06b73d289047 [xemacs-hg @ 2002-03-21 15:13:41 by wmperry]
wmperry
parents: 788
diff changeset
210 Lisp_Object console = CDFW_CONSOLE (EVENT_CHANNEL (emacs_event));
788
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
211 if (CONSOLE_GTK_P (XCONSOLE (console)))
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 809
diff changeset
212 write_c_string
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 809
diff changeset
213 (pstream,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 809
diff changeset
214 gtk_event_name (emacs_event->event.magic.underlying_gdk_event.type));
788
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
215 }
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
216
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
217 static int
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
218 emacs_gtk_compare_magic_event (Lisp_Event *e1, Lisp_Event *e2)
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
219 {
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
220 if (CONSOLE_GTK_P (XCONSOLE (CDFW_CONSOLE (EVENT_CHANNEL (e1)))) &&
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
221 CONSOLE_GTK_P (XCONSOLE (CDFW_CONSOLE (EVENT_CHANNEL (e2)))))
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
222 return (!memcmp (&e1->event.magic.underlying_gdk_event,
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
223 &e2->event.magic.underlying_gdk_event,
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
224 sizeof (GdkEvent)));
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
225 if (CONSOLE_GTK_P (XCONSOLE (CDFW_CONSOLE (EVENT_CHANNEL (e1)))) ||
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
226 CONSOLE_GTK_P (XCONSOLE (CDFW_CONSOLE (EVENT_CHANNEL (e2)))))
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
227 return 0;
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
228 return 1;
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
229 }
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
230
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
231 static Hashcode
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
232 emacs_gtk_hash_magic_event (Lisp_Event *e)
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
233 {
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
234 Lisp_Object console = CDFW_CONSOLE (EVENT_CHANNEL (e));
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
235 if (CONSOLE_GTK_P (XCONSOLE (console)))
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
236 return memory_hash (&e->event.magic.underlying_gdk_event,
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
237 sizeof (GdkEvent));
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
238 return 0;
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
239 }
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
240
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
241 static void
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
242 emacs_gtk_handle_magic_event (struct Lisp_Event *emacs_event)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
243 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
244 /* This function can GC */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
245 GdkEvent *event = &emacs_event->event.magic.underlying_gdk_event;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
246 struct frame *f = XFRAME (EVENT_CHANNEL (emacs_event));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
247
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
248 if (!FRAME_LIVE_P (f))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
249 return;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
250
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
251 switch (event->any.type)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
252 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
253 case GDK_CLIENT_EVENT:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
254 handle_client_message (f, event);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
255 break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
256
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
257 case GDK_FOCUS_CHANGE:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
258 handle_focus_event_1 (f, event->focus_change.in);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
259 break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
260
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
261 case GDK_MAP:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
262 case GDK_UNMAP:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
263 handle_map_event (f, event);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
264 break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
265
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
266 case GDK_ENTER_NOTIFY:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
267 if (event->crossing.detail != GDK_NOTIFY_INFERIOR)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
268 {
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 790
diff changeset
269 Lisp_Object frame = wrap_frame (f);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
270
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
271 /* FRAME_X_MOUSE_P (f) = 1; */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
272 va_run_hook_with_args (Qmouse_enter_frame_hook, 1, frame);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
273 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
274 break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
275
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
276 case GDK_LEAVE_NOTIFY:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
277 if (event->crossing.detail != GDK_NOTIFY_INFERIOR)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
278 {
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 790
diff changeset
279 Lisp_Object frame = wrap_frame (f);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
280
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
281 /* FRAME_X_MOUSE_P (f) = 0; */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
282 va_run_hook_with_args (Qmouse_leave_frame_hook, 1, frame);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
283 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
284 break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
285
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
286 case GDK_VISIBILITY_NOTIFY: /* window visiblity has changed */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
287 if (event->visibility.window == GET_GTK_WIDGET_WINDOW (FRAME_GTK_SHELL_WIDGET (f)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
288 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
289 FRAME_GTK_TOTALLY_VISIBLE_P (f) =
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
290 (event->visibility.state == GDK_VISIBILITY_UNOBSCURED);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
291 /* Note that the fvwm pager only sends VisibilityNotify when
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
292 changing pages. Is this all we need to do ? JV */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
293 /* Nope. We must at least trigger a redisplay here.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
294 Since this case seems similar to MapNotify, I've
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
295 factored out some code to change_frame_visibility().
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
296 This triggers the necessary redisplay and runs
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
297 (un)map-frame-hook. - dkindred@cs.cmu.edu */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
298 /* Changed it again to support the tristate visibility flag */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
299 change_frame_visibility (f, (event->visibility.state
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
300 != GDK_VISIBILITY_FULLY_OBSCURED) ? 1 : -1);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
301 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
302 break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
303
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
304 default:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
305 break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
306 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
307 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
308
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
309 /************************************************************************/
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
310 /* Gtk to Emacs event conversion */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
311 /************************************************************************/
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
312
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
313 static int
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
314 keysym_obeys_caps_lock_p (guint sym, struct device *d)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
315 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
316 struct gtk_device *gd = DEVICE_GTK_DATA (d);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
317 /* Eeeeevil hack. Don't apply Caps_Lock to things that aren't alphabetic
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
318 characters, where "alphabetic" means something more than simply A-Z.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
319 That is, if Caps_Lock is down, typing ESC doesn't produce Shift-ESC.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
320 But if shift-lock is down, then it does. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
321 if (gd->lock_interpretation == GDK_Shift_Lock)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
322 return 1;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
323
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
324 return
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
325 ((sym >= GDK_A) && (sym <= GDK_Z)) ||
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
326 ((sym >= GDK_a) && (sym <= GDK_z)) ||
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
327 ((sym >= GDK_Agrave) && (sym <= GDK_Odiaeresis)) ||
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
328 ((sym >= GDK_agrave) && (sym <= GDK_odiaeresis)) ||
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
329 ((sym >= GDK_Ooblique) && (sym <= GDK_Thorn)) ||
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
330 ((sym >= GDK_oslash) && (sym <= GDK_thorn));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
331 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
332
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
333 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
334 set_last_server_timestamp (struct device *d, GdkEvent *gdk_event)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
335 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
336 guint32 t;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
337 switch (gdk_event->type)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
338 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
339 case GDK_KEY_PRESS:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
340 case GDK_KEY_RELEASE: t = gdk_event->key.time; break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
341 case GDK_BUTTON_PRESS:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
342 case GDK_2BUTTON_PRESS:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
343 case GDK_3BUTTON_PRESS:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
344 case GDK_BUTTON_RELEASE: t = gdk_event->button.time; break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
345 case GDK_ENTER_NOTIFY:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
346 case GDK_LEAVE_NOTIFY: t = gdk_event->crossing.time; break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
347 case GDK_MOTION_NOTIFY: t = gdk_event->motion.time; break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
348 case GDK_PROPERTY_NOTIFY: t = gdk_event->property.time; break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
349 case GDK_SELECTION_CLEAR:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
350 case GDK_SELECTION_REQUEST:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
351 case GDK_SELECTION_NOTIFY: t = gdk_event->selection.time; break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
352 default: return;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
353 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
354 DEVICE_GTK_LAST_SERVER_TIMESTAMP (d) = t;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
355 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
356
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
357 static Lisp_Object
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
358 gtk_keysym_to_emacs_keysym (guint keysym, int simple_p)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
359 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
360 char *name;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
361 if (keysym >= GDK_exclam && keysym <= GDK_asciitilde)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
362 /* We must assume that the X keysym numbers for the ASCII graphic
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
363 characters are the same as their ASCII codes. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
364 return make_char (keysym);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
365
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
366 switch (keysym)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
367 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
368 /* These would be handled correctly by the default case, but by
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
369 special-casing them here we don't garbage a string or call
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
370 intern(). */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
371 case GDK_BackSpace: return QKbackspace;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
372 case GDK_Tab: return QKtab;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
373 case GDK_Linefeed: return QKlinefeed;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
374 case GDK_Return: return QKreturn;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
375 case GDK_Escape: return QKescape;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
376 case GDK_space: return QKspace;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
377 case GDK_Delete: return QKdelete;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
378 case 0: return Qnil;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
379 default:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
380 if (simple_p) return Qnil;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
381 /* !!#### not Mule-ized */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
382 name = gdk_keyval_name (keysym);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
383 if (!name || !name[0])
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
384 /* This happens if there is a mismatch between the Xlib of
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
385 XEmacs and the Xlib of the X server...
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
386
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
387 Let's hard-code in some knowledge of common keysyms introduced
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
388 in recent X11 releases. Snarfed from X11/keysymdef.h
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
389
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
390 Probably we should add some stuff here for X11R6. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
391 switch (keysym)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
392 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
393 case 0xFF95: return KEYSYM ("kp-home");
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
394 case 0xFF96: return KEYSYM ("kp-left");
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
395 case 0xFF97: return KEYSYM ("kp-up");
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
396 case 0xFF98: return KEYSYM ("kp-right");
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
397 case 0xFF99: return KEYSYM ("kp-down");
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
398 case 0xFF9A: return KEYSYM ("kp-prior");
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
399 case 0xFF9B: return KEYSYM ("kp-next");
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
400 case 0xFF9C: return KEYSYM ("kp-end");
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
401 case 0xFF9D: return KEYSYM ("kp-begin");
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
402 case 0xFF9E: return KEYSYM ("kp-insert");
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
403 case 0xFF9F: return KEYSYM ("kp-delete");
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
404
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
405 case 0x1005FF10: return KEYSYM ("SunF36"); /* labeled F11 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
406 case 0x1005FF11: return KEYSYM ("SunF37"); /* labeled F12 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
407 default:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
408 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
409 char buf [64];
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
410 sprintf (buf, "unknown-keysym-0x%X", (int) keysym);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
411 return KEYSYM (buf);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
412 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
413 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
414 /* If it's got a one-character name, that's good enough. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
415 if (!name[1])
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
416 return make_char (name[0]);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
417
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
418 /* If it's in the "Keyboard" character set, downcase it.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
419 The case of those keysyms is too totally random for us to
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
420 force anyone to remember them.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
421 The case of the other character sets is significant, however.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
422 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
423 if ((((unsigned int) keysym) & (~0x1FF)) == ((unsigned int) 0xFE00))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
424 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
425 char buf [255];
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
426 char *s1, *s2;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
427 for (s1 = name, s2 = buf; *s1; s1++, s2++) {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
428 if (*s1 == '_') {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
429 *s2 = '-';
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
430 } else {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
431 *s2 = tolower (* (unsigned char *) s1);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
432 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
433 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
434 *s2 = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
435 return KEYSYM (buf);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
436 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
437 return KEYSYM (name);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
438 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
439 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
440
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
441 static Lisp_Object
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
442 gtk_to_emacs_keysym (struct device *d, GdkEventKey *event, int simple_p)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
443 /* simple_p means don't try too hard (ASCII only) */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
444 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
445 if (event->length != 1)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
446 {
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
447 /* Generate multiple emacs events */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
448 Emchar ch;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
449 Lisp_Object instream, fb_instream;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
450 Lstream *istr;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
451 struct gcpro gcpro1, gcpro2;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
452
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
453 fb_instream =
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
454 make_fixed_buffer_input_stream ((unsigned char *) event->string, event->length);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
455
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
456 /* #### Use get_coding_system_for_text_file
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
457 (Vcomposed_input_coding_system, 0) */
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
458 instream =
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
459 make_coding_input_stream (XLSTREAM (fb_instream),
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
460 Qundecided, CODING_DECODE, 0);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
461
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
462 istr = XLSTREAM (instream);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
463
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
464 GCPRO2 (instream, fb_instream);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
465 while ((ch = Lstream_get_emchar (istr)) != EOF)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
466 {
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
467 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
468 struct Lisp_Event *ev = XEVENT (emacs_event);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
469 ev->channel = DEVICE_CONSOLE (d);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
470 ev->event_type = key_press_event;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
471 ev->timestamp = event->time;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
472 ev->event.key.modifiers = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
473 ev->event.key.keysym = make_char (ch);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
474 enqueue_gtk_dispatch_event (emacs_event);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
475 }
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
476 Lstream_close (istr);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
477 UNGCPRO;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
478 Lstream_delete (istr);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
479 Lstream_delete (XLSTREAM (fb_instream));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
480 if (IS_MODIFIER_KEY (event->keyval) || (event->keyval == GDK_Mode_switch))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
481 return (Qnil);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
482 return (gtk_keysym_to_emacs_keysym (event->keyval, simple_p));
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
483 }
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
484 else
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
485 {
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
486 if (IS_MODIFIER_KEY (event->keyval) || (event->keyval == GDK_Mode_switch))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
487 return (Qnil);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
488 return (gtk_keysym_to_emacs_keysym (event->keyval, simple_p));
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
489 }
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
490 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
491
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
492
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
493 /************************************************************************/
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
494 /* timeout events */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
495 /************************************************************************/
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
496
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
497 static int timeout_id_tick;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
498
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
499 struct GTK_timeout {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
500 int id;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
501 guint timeout_id;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
502 struct GTK_timeout *next;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
503 } *pending_timeouts, *completed_timeouts;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
504
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
505 struct GTK_timeout_blocktype
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
506 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
507 Blocktype_declare (struct GTK_timeout);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
508 } *the_GTK_timeout_blocktype;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
509
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
510 /* called by the gtk main loop */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
511 static gint
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
512 gtk_timeout_callback (gpointer closure)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
513 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
514 struct GTK_timeout *timeout = (struct GTK_timeout *) closure;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
515 struct GTK_timeout *t2 = pending_timeouts;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
516
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
517 /* Remove this one from the list of pending timeouts */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
518 if (t2 == timeout)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
519 pending_timeouts = pending_timeouts->next;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
520 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
521 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
522 while (t2->next && t2->next != timeout) t2 = t2->next;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
523 assert (t2->next);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
524 t2->next = t2->next->next;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
525 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
526 /* Add this one to the list of completed timeouts */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
527 timeout->next = completed_timeouts;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
528 completed_timeouts = timeout;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
529 return(FALSE);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
530 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
531
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
532 static int
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
533 emacs_gtk_add_timeout (EMACS_TIME thyme)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
534 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
535 struct GTK_timeout *timeout = Blocktype_alloc (the_GTK_timeout_blocktype);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
536 EMACS_TIME current_time;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
537 int milliseconds;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
538
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
539 timeout->id = timeout_id_tick++;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
540 timeout->next = pending_timeouts;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
541 pending_timeouts = timeout;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
542 EMACS_GET_TIME (current_time);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
543 EMACS_SUB_TIME (thyme, thyme, current_time);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
544 milliseconds = EMACS_SECS (thyme) * 1000 +
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
545 EMACS_USECS (thyme) / 1000;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
546 if (milliseconds < 1)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
547 milliseconds = 1;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
548 timeout->timeout_id = gtk_timeout_add (milliseconds,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
549 gtk_timeout_callback,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
550 (gpointer) timeout);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
551 return timeout->id;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
552 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
553
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
554 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
555 emacs_gtk_remove_timeout (int id)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
556 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
557 struct GTK_timeout *timeout, *t2;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
558
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
559 timeout = NULL;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
560
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
561 /* Find the timeout on the list of pending ones, if it's still there. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
562 if (pending_timeouts)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
563 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
564 if (id == pending_timeouts->id)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
565 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
566 timeout = pending_timeouts;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
567 pending_timeouts = pending_timeouts->next;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
568 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
569 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
570 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
571 t2 = pending_timeouts;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
572 while (t2->next && t2->next->id != id) t2 = t2->next;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
573 if ( t2->next) /*found it */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
574 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
575 timeout = t2->next;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
576 t2->next = t2->next->next;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
577 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
578 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
579 /* if it was pending, we have removed it from the list */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
580 if (timeout)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
581 gtk_timeout_remove (timeout->timeout_id);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
582 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
583
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
584 /* It could be that the call back was already called but we didn't convert
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
585 into an Emacs event yet */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
586 if (!timeout && completed_timeouts)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
587 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
588 /* Code duplication! */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
589 if (id == completed_timeouts->id)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
590 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
591 timeout = completed_timeouts;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
592 completed_timeouts = completed_timeouts->next;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
593 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
594 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
595 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
596 t2 = completed_timeouts;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
597 while (t2->next && t2->next->id != id) t2 = t2->next;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
598 if ( t2->next) /*found it */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
599 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
600 timeout = t2->next;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
601 t2->next = t2->next->next;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
602 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
603 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
604 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
605
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
606 /* If we found the thing on the lists of timeouts,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
607 and removed it, deallocate
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
608 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
609 if (timeout)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
610 Blocktype_free (the_GTK_timeout_blocktype, timeout);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
611 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
612
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
613 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
614 gtk_timeout_to_emacs_event (struct Lisp_Event *emacs_event)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
615 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
616 struct GTK_timeout *timeout = completed_timeouts;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
617 assert (timeout);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
618 completed_timeouts = completed_timeouts->next;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
619 emacs_event->event_type = timeout_event;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
620 /* timeout events have nil as channel */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
621 emacs_event->timestamp = 0; /* #### wrong!! */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
622 emacs_event->event.timeout.interval_id = timeout->id;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
623 Blocktype_free (the_GTK_timeout_blocktype, timeout);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
624 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
625
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
626
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
627 /************************************************************************/
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
628 /* process and tty events */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
629 /************************************************************************/
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
630
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
631 struct what_is_ready_closure
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
632 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
633 int fd;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
634 Lisp_Object what;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
635 gint id;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
636 };
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
637
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
638 static Lisp_Object *filedesc_with_input;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
639 static struct what_is_ready_closure **filedesc_to_what_closure;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
640
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
641 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
642 init_what_input_once (void)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
643 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
644 int i;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
645
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
646 filedesc_with_input = xnew_array (Lisp_Object, MAXDESC);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
647 filedesc_to_what_closure =
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
648 xnew_array (struct what_is_ready_closure *, MAXDESC);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
649
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
650 for (i = 0; i < MAXDESC; i++)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
651 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
652 filedesc_to_what_closure[i] = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
653 filedesc_with_input[i] = Qnil;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
654 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
655
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
656 process_events_occurred = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
657 tty_events_occurred = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
658 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
659
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
660 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
661 mark_what_as_being_ready (struct what_is_ready_closure *closure)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
662 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
663 if (NILP (filedesc_with_input[closure->fd]))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
664 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
665 SELECT_TYPE temp_mask;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
666 FD_ZERO (&temp_mask);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
667 FD_SET (closure->fd, &temp_mask);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
668 /* Check to make sure there's *really* input available.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
669 Sometimes things seem to get confused and this gets called
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
670 for the tty fd when there's really only input available
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
671 on some process's fd. (It will subsequently get called
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
672 for that process's fd, so returning without setting any
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
673 flags will take care of it.) To see the problem, uncomment
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
674 the stderr_out below, turn NORMAL_QUIT_CHECK_TIMEOUT_MSECS
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
675 down to 25, do sh -c 'xemacs -nw -q -f shell 2>/tmp/log'
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
676 and press return repeatedly. (Seen under AIX & Linux.)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
677 -dkindred@cs.cmu.edu */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
678 if (!poll_fds_for_input (temp_mask))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
679 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
680 #if 0
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
681 stderr_out ("mark_what_as_being_ready: no input available (fd=%d)\n",
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
682 closure->fd);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
683 #endif
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
684 return;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
685 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
686 filedesc_with_input[closure->fd] = closure->what;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
687 if (PROCESSP (closure->what))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
688 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
689 /* Don't increment this if the current process is already marked
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
690 * as having input. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
691 process_events_occurred++;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
692 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
693 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
694 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
695 tty_events_occurred++;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
696 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
697 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
698 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
699
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
700 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
701 gtk_what_callback (gpointer closure, gint source, GdkInputCondition why)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
702 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
703 /* If closure is 0, then we got a fake event from a signal handler.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
704 The only purpose of this is to make XtAppProcessEvent() stop
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
705 blocking. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
706 if (closure)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
707 mark_what_as_being_ready ((struct what_is_ready_closure *) closure);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
708 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
709 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
710 fake_event_occurred++;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
711 drain_signal_event_pipe ();
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
712 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
713 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
714
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
715 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
716 select_filedesc (int fd, Lisp_Object what)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
717 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
718 struct what_is_ready_closure *closure;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
719
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
720 /* If somebody is trying to select something that's already selected
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
721 for, then something went wrong. The generic routines ought to
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
722 detect this and error before here. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
723 assert (!filedesc_to_what_closure[fd]);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
724
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
725 closure = xnew (struct what_is_ready_closure);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
726 closure->fd = fd;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
727 closure->what = what;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
728 closure->id = gdk_input_add (fd, GDK_INPUT_READ,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
729 (GdkInputFunction) gtk_what_callback, closure);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
730 filedesc_to_what_closure[fd] = closure;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
731 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
732
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
733 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
734 unselect_filedesc (int fd)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
735 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
736 struct what_is_ready_closure *closure = filedesc_to_what_closure[fd];
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
737
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
738 assert (closure);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
739 if (!NILP (filedesc_with_input[fd]))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
740 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
741 /* We are unselecting this process before we have drained the rest of
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
742 the input from it, probably from status_notify() in the command loop.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
743 This can happen like so:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
744
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
745 - We are waiting in XtAppNextEvent()
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
746 - Process generates output
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
747 - Process is marked as being ready
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
748 - Process dies, SIGCHLD gets generated before we return (!?)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
749 It could happen I guess.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
750 - sigchld_handler() marks process as dead
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
751 - Somehow we end up getting a new KeyPress event on the queue
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
752 at the same time (I'm really so sure how that happens but I'm
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
753 not sure it can't either so let's assume it can...).
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
754 - Key events have priority so we return that instead of the proc.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
755 - Before dispatching the lisp key event we call status_notify()
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
756 - Which deselects the process that SIGCHLD marked as dead.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
757
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
758 Thus we never remove it from _with_input and turn it into a lisp
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
759 event, so we need to do it here. But this does not mean that we're
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
760 throwing away the last block of output - status_notify() has already
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
761 taken care of running the proc filter or whatever.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
762 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
763 filedesc_with_input[fd] = Qnil;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
764 if (PROCESSP (closure->what))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
765 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
766 assert (process_events_occurred > 0);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
767 process_events_occurred--;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
768 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
769 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
770 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
771 assert (tty_events_occurred > 0);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
772 tty_events_occurred--;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
773 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
774 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
775 gdk_input_remove (closure->id);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
776 xfree (closure);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
777 filedesc_to_what_closure[fd] = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
778 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
779
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
780 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
781 emacs_gtk_select_process (struct Lisp_Process *p)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
782 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
783 Lisp_Object process;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
784 int infd = event_stream_unixoid_select_process (p);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
785
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 790
diff changeset
786 process = wrap_process (p);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
787 select_filedesc (infd, process);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
788 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
789
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
790 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
791 emacs_gtk_unselect_process (struct Lisp_Process *p)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
792 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
793 int infd = event_stream_unixoid_unselect_process (p);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
794
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
795 unselect_filedesc (infd);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
796 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
797
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
798 static USID
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
799 emacs_gtk_create_stream_pair (void* inhandle, void* outhandle,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
800 Lisp_Object* instream, Lisp_Object* outstream, int flags)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
801 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
802 USID u = event_stream_unixoid_create_stream_pair
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
803 (inhandle, outhandle, instream, outstream, flags);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
804 if (u != USID_ERROR)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
805 u = USID_DONTHASH;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
806 return u;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
807 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
808
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
809 static USID
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
810 emacs_gtk_delete_stream_pair (Lisp_Object instream, Lisp_Object outstream)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
811 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
812 event_stream_unixoid_delete_stream_pair (instream, outstream);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
813 return USID_DONTHASH;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
814 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
815
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
816 /* This is called from GC when a process object is about to be freed.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
817 If we've still got pointers to it in this file, we're gonna lose hard.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
818 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
819 void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
820 debug_process_finalization (struct Lisp_Process *p)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
821 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
822 #if 0 /* #### */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
823 int i;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
824 Lisp_Object instr, outstr;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
825
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
826 get_process_streams (p, &instr, &outstr);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
827 /* if it still has fds, then it hasn't been killed yet. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
828 assert (NILP(instr));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
829 assert (NILP(outstr));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
830 /* Better not still be in the "with input" table; we know it's got no fds. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
831 for (i = 0; i < MAXDESC; i++)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
832 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
833 Lisp_Object process = filedesc_fds_with_input [i];
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
834 assert (!PROCESSP (process) || XPROCESS (process) != p);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
835 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
836 #endif
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
837 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
838
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
839 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
840 gtk_process_to_emacs_event (struct Lisp_Event *emacs_event)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
841 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
842 int i;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
843 Lisp_Object process;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
844
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
845 assert (process_events_occurred > 0);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
846 for (i = 0; i < MAXDESC; i++)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
847 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
848 process = filedesc_with_input[i];
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
849 if (PROCESSP (process))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
850 break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
851 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
852 assert (i < MAXDESC);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
853 filedesc_with_input[i] = Qnil;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
854 process_events_occurred--;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
855 /* process events have nil as channel */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
856 emacs_event->event_type = process_event;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
857 emacs_event->timestamp = 0; /* #### */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
858 emacs_event->event.process.process = process;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
859 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
860
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
861 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
862 emacs_gtk_select_console (struct console *con)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
863 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
864 Lisp_Object console;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
865 int infd;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
866
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
867 if (CONSOLE_GTK_P (con))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
868 return; /* Gtk consoles are automatically selected for when we initialize them */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
869 infd = event_stream_unixoid_select_console (con);
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 790
diff changeset
870 console = wrap_console (con);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
871 select_filedesc (infd, console);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
872 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
873
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
874 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
875 emacs_gtk_unselect_console (struct console *con)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
876 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
877 Lisp_Object console;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
878 int infd;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
879
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
880 if (CONSOLE_GTK_P (con))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
881 return; /* X consoles are automatically selected for when we initialize them */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
882 infd = event_stream_unixoid_unselect_console (con);
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 790
diff changeset
883 console = wrap_console (con);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
884 unselect_filedesc (infd);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
885 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
886
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
887 /* read an event from a tty, if one is available. Returns non-zero
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
888 if an event was available. Note that when this function is
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
889 called, there should always be a tty marked as ready for input.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
890 However, the input condition might actually be EOF, so there
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
891 may not really be any input available. (In this case,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
892 read_event_from_tty_or_stream_desc() will arrange for the TTY device
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
893 to be deleted.) */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
894
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
895 static int
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
896 gtk_tty_to_emacs_event (struct Lisp_Event *emacs_event)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
897 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
898 int i;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
899
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
900 assert (tty_events_occurred > 0);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
901 for (i = 0; i < MAXDESC; i++)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
902 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
903 Lisp_Object console = filedesc_with_input[i];
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
904 if (CONSOLEP (console))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
905 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
906 assert (tty_events_occurred > 0);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
907 tty_events_occurred--;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
908 filedesc_with_input[i] = Qnil;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
909 if (read_event_from_tty_or_stream_desc (emacs_event,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
910 XCONSOLE (console)))
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
911 return 1;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
912 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
913 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
914
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
915 return 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
916 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
917
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
918
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
919 /************************************************************************/
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
920 /* Drag 'n Drop handling */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
921 /************************************************************************/
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
922 #ifdef HAVE_DRAGNDROP
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
923 #define TARGET_URI_LIST 0x00
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
924 #define TARGET_TEXT_PLAIN 0x01
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
925 #define TARGET_FILE_NAME 0x02
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
926 #define TARGET_NETSCAPE 0x03
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
927
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
928 static GdkAtom preferred_targets[10];
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
929
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
930 void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
931 dragndrop_data_received (GtkWidget *widget,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
932 GdkDragContext *context,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
933 gint x,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
934 gint y,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
935 GtkSelectionData *data,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
936 guint info,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
937 guint time)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
938 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
939 Lisp_Object event = Fmake_event (Qnil, Qnil);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
940 struct device *d = gtk_any_window_to_device (widget->window);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
941 struct frame *f = gtk_any_widget_or_parent_to_frame (d, widget);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
942 struct Lisp_Event *ev = XEVENT (event);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
943 Lisp_Object l_type = Qnil, l_data = Qnil;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
944 Lisp_Object l_dndlist = Qnil, l_item = Qnil;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
945 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
946
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
947 GCPRO4 (l_type, l_data, l_dndlist, l_item);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
948
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
949 ev->event_type = misc_user_event;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
950 ev->timestamp = time;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
951
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 790
diff changeset
952 ev->channel = wrap_frame (f);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
953
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
954 ev->event.misc.x = x;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
955 ev->event.misc.y = y;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
956
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
957 if (data->type == preferred_targets[TARGET_URI_LIST])
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
958 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
959 /* newline-separated list of URLs */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
960 int start, end;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
961 const char *string_data = (char *) data->data;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
962
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
963 l_type = Qdragdrop_URL;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
964
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
965 for (start = 0, end = 0; string_data && string_data[end]; end++)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
966 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
967 if ((string_data[end] == '\r') && (string_data[end+1] == '\n'))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
968 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
969 l_item = make_string (&string_data[start], end - start);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
970 l_dndlist = Fcons (l_item, l_dndlist);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
971 ++end;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
972 start = ++end;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
973 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
974 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
975 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
976 else if (data->type == preferred_targets[TARGET_TEXT_PLAIN])
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
977 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
978 /* Arbitrary string */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
979 l_type = Qdragdrop_MIME;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
980 l_dndlist = list1 (list3 (list1 (build_string ("text/plain")),
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
981 build_string ("8_bit"),
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
982 make_ext_string (data->data,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
983 strlen ((char *)data->data),
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
984 Qctext)));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
985 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
986 else if (data->type == preferred_targets[TARGET_FILE_NAME])
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
987 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
988 /* Random filename */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
989 char *hurl = dnd_url_hexify_string (data->data, "file:");
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
990
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 589
diff changeset
991 l_dndlist = list1 (make_string ((Intbyte *)hurl, strlen (hurl)));
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
992 l_type = Qdragdrop_URL;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
993
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
994 xfree (hurl);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
995 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
996 else if (data->type == preferred_targets[TARGET_NETSCAPE])
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
997 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
998 /* Single URL */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
999 l_dndlist = list1 (make_string ((Extbyte *)data->data,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1000 strlen ((char *)data->data)));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1001 l_type = Qdragdrop_URL;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1002 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1003 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1004 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1005 /* Unknown type - what to do?
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1006 We just pass it up to lisp - we already have a mime type.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1007 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1008 l_type = Qdragdrop_MIME;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1009 l_dndlist = list1 (list3 (list1 (build_string (gdk_atom_name (data->type))),
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1010 build_string ("8bit"),
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1011 make_ext_string ((Extbyte *) data->data,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1012 data->length, Qbinary)));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1013 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1014
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1015 ev->event.misc.function = Qdragdrop_drop_dispatch;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1016 ev->event.misc.object = Fcons (l_type, l_dndlist);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1017
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1018 UNGCPRO;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1019
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1020 gtk_drag_finish (context, TRUE, FALSE, time);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1021 enqueue_gtk_dispatch_event (event);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1022 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1023
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1024 gboolean
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1025 dragndrop_dropped (GtkWidget *widget,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1026 GdkDragContext *drag_context,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1027 gint x,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1028 gint y,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1029 guint time,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1030 gpointer user_data)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1031 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1032 /* Netscape drops things like:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1033 STRING
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1034 _SGI_ICON
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1035 _SGI_ICON_TYPE
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1036 SGI_FILE
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1037 FILE_NAME
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1038 _NETSCAPE_URL
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1039
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1040 gmc drops things like
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1041 application/x-mc-desktop-icon
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1042 text/uri-list
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1043 text/plain
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1044 _NETSCAPE_URL
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1045
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1046 We prefer:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1047 text/uri-list
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1048 text/plain
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1049 FILE_NAME
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1050 _NETSCAPE_URL
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1051 first one
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1052 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1053 GdkAtom found = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1054 GList *list = drag_context->targets;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1055
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1056 int i;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1057
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1058 if (!preferred_targets[0])
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1059 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1060 preferred_targets[TARGET_URI_LIST] = gdk_atom_intern ("text/uri-list", FALSE);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1061 preferred_targets[TARGET_TEXT_PLAIN] = gdk_atom_intern ("text/plain", FALSE);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1062 preferred_targets[TARGET_FILE_NAME] = gdk_atom_intern ("FILE_NAME", FALSE);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1063 preferred_targets[TARGET_NETSCAPE] = gdk_atom_intern ("_NETSCAPE_URL", FALSE);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1064 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1065
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1066 #if 0
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1067 stderr_out ("Drop info available in the following formats: \n");
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1068 while (list)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1069 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1070 stderr_out ("\t%s\n", gdk_atom_name ((GdkAtom)list->data));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1071 list = list->next;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1072 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1073 list = drag_context->targets;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1074 #endif
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1075
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1076 while (list && !found)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1077 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1078 for (i = 0; preferred_targets[i] && !found; i++)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1079 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1080 if ((GdkAtom) list->data == preferred_targets[i])
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1081 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1082 found = (GdkAtom) list->data;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1083 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1084 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1085 list = list->next;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1086 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1087
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1088 if (!found)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1089 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1090 found = (GdkAtom) drag_context->targets->data;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1091 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1092
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1093 gtk_drag_get_data (GTK_WIDGET (user_data), drag_context, found, time);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1094 return (TRUE);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1095 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1096 #endif /* HAVE_DRAGNDROP */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1097
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1098
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1099 /************************************************************************/
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1100 /* get the next event from gtk */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1101 /************************************************************************/
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1102
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1103 static Lisp_Object dispatch_event_queue, dispatch_event_queue_tail;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1104
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1105 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1106 enqueue_gtk_dispatch_event (Lisp_Object event)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1107 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1108 enqueue_event (event, &dispatch_event_queue, &dispatch_event_queue_tail);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1109 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1110
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1111 static Lisp_Object
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1112 dequeue_gtk_dispatch_event (void)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1113 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1114 return dequeue_event (&dispatch_event_queue, &dispatch_event_queue_tail);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1115 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1116
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1117 /* This business exists because menu events "happen" when
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1118 menubar_selection_callback() is called from somewhere deep
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1119 within XtAppProcessEvent in emacs_Xt_next_event(). The
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1120 callback needs to terminate the modal loop in that function
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1121 or else it will continue waiting until another event is
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1122 received.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1123
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1124 Same business applies to scrollbar events. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1125
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1126 void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1127 signal_special_gtk_user_event (Lisp_Object channel, Lisp_Object function,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1128 Lisp_Object object)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1129 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1130 Lisp_Object event = Fmake_event (Qnil, Qnil);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1131
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1132 XEVENT (event)->event_type = misc_user_event;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1133 XEVENT (event)->channel = channel;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1134 XEVENT (event)->event.eval.function = function;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1135 XEVENT (event)->event.eval.object = object;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1136
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1137 enqueue_gtk_dispatch_event (event);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1138 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1139
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1140 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1141 emacs_gtk_next_event (struct Lisp_Event *emacs_event)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1142 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1143 we_didnt_get_an_event:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1144
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1145 while (NILP (dispatch_event_queue) &&
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1146 !completed_timeouts &&
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1147 !fake_event_occurred &&
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1148 !process_events_occurred &&
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1149 !tty_events_occurred)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1150 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1151 gtk_main_iteration();
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1152 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1153
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1154 if (!NILP (dispatch_event_queue))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1155 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1156 Lisp_Object event, event2;
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 790
diff changeset
1157 event2 = wrap_event (emacs_event);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1158 event = dequeue_gtk_dispatch_event ();
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1159 Fcopy_event (event, event2);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1160 Fdeallocate_event (event);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1161 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1162 else if (tty_events_occurred)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1163 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1164 if (!gtk_tty_to_emacs_event (emacs_event))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1165 goto we_didnt_get_an_event;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1166 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1167 else if (completed_timeouts)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1168 gtk_timeout_to_emacs_event (emacs_event);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1169 else if (fake_event_occurred)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1170 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1171 /* A dummy event, so that a cycle of the command loop will occur. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1172 fake_event_occurred = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1173 /* eval events have nil as channel */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1174 emacs_event->event_type = eval_event;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1175 emacs_event->event.eval.function = Qidentity;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1176 emacs_event->event.eval.object = Qnil;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1177 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1178 else /* if (process_events_occurred) */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1179 gtk_process_to_emacs_event (emacs_event);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1180 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1181
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1182 int
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1183 gtk_event_to_emacs_event (struct frame *frame, GdkEvent *gdk_event, struct Lisp_Event *emacs_event)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1184 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1185 struct device *d = NULL;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1186 struct gtk_device *gd = NULL;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1187 gboolean accept_any_window = FALSE;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1188
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1189 if (!frame)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1190 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1191 frame = XFRAME (Fselected_frame (Vdefault_gtk_device));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1192 accept_any_window = TRUE;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1193 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1194
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1195 d = XDEVICE (FRAME_DEVICE (frame));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1196 gd = DEVICE_GTK_DATA (d);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1197
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1198 set_last_server_timestamp (d, gdk_event);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1199
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1200 switch (gdk_event->type)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1201 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1202 /* XEmacs handles double and triple clicking on its own, and if
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1203 we capture these events, it royally confuses the code in
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1204 ../lisp/mouse.el */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1205 case GDK_2BUTTON_PRESS:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1206 case GDK_3BUTTON_PRESS:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1207 return (0);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1208
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1209 case GDK_BUTTON_PRESS:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1210 case GDK_BUTTON_RELEASE:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1211 /* We need to ignore button events outside our main window or
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1212 things get ugly. The standard scrollbars in Gtk try to be
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1213 nice and pass the button press events up to the parent
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1214 widget. This causes us no end of grief though. Effects
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1215 range from setting point to the wrong place to selecting
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1216 new windows. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1217 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1218 GdkWindow *w = gdk_window_at_pointer (NULL, NULL);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1219
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1220 /* If you press mouse button and drag it around, and release
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1221 it outside the window, you will get a NULL GdkWindow at
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1222 pointer. We need to forward these events on to XEmacs so
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1223 that the mouse selection voodoo works.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1224 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1225 if (w && (w != gdk_window_lookup (GDK_ROOT_WINDOW ())))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1226 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1227 GdkEvent ev;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1228 GtkWidget *wid = NULL;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1229
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1230 ev.any.window = w;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1231 wid = gtk_get_event_widget (&ev);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1232
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1233 if (!GTK_IS_XEMACS (wid) && !accept_any_window)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1234 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1235 return (0);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1236 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1237 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1238 if (!accept_any_window)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1239 gtk_widget_grab_focus (FRAME_GTK_TEXT_WIDGET (frame));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1240 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1241 /* Fall through */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1242 case GDK_KEY_PRESS:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1243 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1244 unsigned int modifiers = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1245 int shift_p, lock_p;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1246 gboolean key_event_p = (gdk_event->type == GDK_KEY_PRESS);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1247 unsigned int *state =
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1248 key_event_p ? &gdk_event->key.state : &gdk_event->button.state;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1249
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1250 /* If this is a synthetic KeyPress or Button event, and the user
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1251 has expressed a disinterest in this security hole, then drop
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1252 it on the floor. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1253 /* #### BILL!!! Should this be a generic check for ANY synthetic
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1254 event? */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1255 if ((gdk_event->any.send_event) && !gtk_allow_sendevents)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1256 return 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1257
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1258 DEVICE_GTK_MOUSE_TIMESTAMP (d) =
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1259 DEVICE_GTK_GLOBAL_MOUSE_TIMESTAMP (d) =
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1260 key_event_p ? gdk_event->key.time : gdk_event->button.time;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1261
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1262 if (*state & GDK_CONTROL_MASK) modifiers |= XEMACS_MOD_CONTROL;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1263 if (*state & gd->MetaMask) modifiers |= XEMACS_MOD_META;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1264 if (*state & gd->SuperMask) modifiers |= XEMACS_MOD_SUPER;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1265 if (*state & gd->HyperMask) modifiers |= XEMACS_MOD_HYPER;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1266 if (*state & gd->AltMask) modifiers |= XEMACS_MOD_ALT;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1267
589
37fe04af1590 [xemacs-hg @ 2001-05-31 02:00:29 by wmperry]
wmperry
parents: 563
diff changeset
1268 {
37fe04af1590 [xemacs-hg @ 2001-05-31 02:00:29 by wmperry]
wmperry
parents: 563
diff changeset
1269 int numero_de_botao = -1;
37fe04af1590 [xemacs-hg @ 2001-05-31 02:00:29 by wmperry]
wmperry
parents: 563
diff changeset
1270
37fe04af1590 [xemacs-hg @ 2001-05-31 02:00:29 by wmperry]
wmperry
parents: 563
diff changeset
1271 if (!key_event_p)
37fe04af1590 [xemacs-hg @ 2001-05-31 02:00:29 by wmperry]
wmperry
parents: 563
diff changeset
1272 numero_de_botao = gdk_event->button.button;
37fe04af1590 [xemacs-hg @ 2001-05-31 02:00:29 by wmperry]
wmperry
parents: 563
diff changeset
1273
37fe04af1590 [xemacs-hg @ 2001-05-31 02:00:29 by wmperry]
wmperry
parents: 563
diff changeset
1274 /* the button gets noted either in the button or the modifiers
37fe04af1590 [xemacs-hg @ 2001-05-31 02:00:29 by wmperry]
wmperry
parents: 563
diff changeset
1275 field, but not both. */
37fe04af1590 [xemacs-hg @ 2001-05-31 02:00:29 by wmperry]
wmperry
parents: 563
diff changeset
1276 if (numero_de_botao != 1 && (*state & GDK_BUTTON1_MASK))
37fe04af1590 [xemacs-hg @ 2001-05-31 02:00:29 by wmperry]
wmperry
parents: 563
diff changeset
1277 modifiers |= XEMACS_MOD_BUTTON1;
37fe04af1590 [xemacs-hg @ 2001-05-31 02:00:29 by wmperry]
wmperry
parents: 563
diff changeset
1278 if (numero_de_botao != 2 && (*state & GDK_BUTTON2_MASK))
37fe04af1590 [xemacs-hg @ 2001-05-31 02:00:29 by wmperry]
wmperry
parents: 563
diff changeset
1279 modifiers |= XEMACS_MOD_BUTTON2;
37fe04af1590 [xemacs-hg @ 2001-05-31 02:00:29 by wmperry]
wmperry
parents: 563
diff changeset
1280 if (numero_de_botao != 3 && (*state & GDK_BUTTON3_MASK))
37fe04af1590 [xemacs-hg @ 2001-05-31 02:00:29 by wmperry]
wmperry
parents: 563
diff changeset
1281 modifiers |= XEMACS_MOD_BUTTON3;
37fe04af1590 [xemacs-hg @ 2001-05-31 02:00:29 by wmperry]
wmperry
parents: 563
diff changeset
1282 if (numero_de_botao != 4 && (*state & GDK_BUTTON4_MASK))
37fe04af1590 [xemacs-hg @ 2001-05-31 02:00:29 by wmperry]
wmperry
parents: 563
diff changeset
1283 modifiers |= XEMACS_MOD_BUTTON4;
37fe04af1590 [xemacs-hg @ 2001-05-31 02:00:29 by wmperry]
wmperry
parents: 563
diff changeset
1284 if (numero_de_botao != 5 && (*state & GDK_BUTTON5_MASK))
37fe04af1590 [xemacs-hg @ 2001-05-31 02:00:29 by wmperry]
wmperry
parents: 563
diff changeset
1285 modifiers |= XEMACS_MOD_BUTTON5;
37fe04af1590 [xemacs-hg @ 2001-05-31 02:00:29 by wmperry]
wmperry
parents: 563
diff changeset
1286 }
37fe04af1590 [xemacs-hg @ 2001-05-31 02:00:29 by wmperry]
wmperry
parents: 563
diff changeset
1287
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1288 /* Ignore the Caps_Lock key if:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1289 - any other modifiers are down, so that Caps_Lock doesn't
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1290 turn C-x into C-X, which would suck.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1291 - the event was a mouse event. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1292 if (modifiers || ! key_event_p)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1293 *state &= (~GDK_LOCK_MASK);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1294
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1295 shift_p = *state & GDK_SHIFT_MASK;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1296 lock_p = *state & GDK_LOCK_MASK;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1297
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1298 if (shift_p || lock_p)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1299 modifiers |= XEMACS_MOD_SHIFT;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1300
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1301 if (key_event_p)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1302 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1303 GdkEventKey *key_event = &gdk_event->key;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1304 Lisp_Object keysym;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1305
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1306 /* This used to compute the frame from the given X window and
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1307 store it here, but we really don't care about the frame. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1308 emacs_event->channel = DEVICE_CONSOLE (d);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1309
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1310 /* Keysym mucking has already been done inside the
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1311 GdkEventKey parsing */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1312 keysym = gtk_to_emacs_keysym (d, key_event, 0);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1313
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1314 /* If the emacs keysym is nil, then that means that the X
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1315 keysym was either a Modifier or NoSymbol, which
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1316 probably means that we're in the midst of reading a
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1317 Multi_key sequence, or a "dead" key prefix, or XIM
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1318 input. Ignore it. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1319 if (NILP (keysym))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1320 return 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1321
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1322 /* More Caps_Lock garbage: Caps_Lock should *only* add the
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1323 shift modifier to two-case keys (that is, A-Z and
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1324 related characters). So at this point (after looking up
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1325 the keysym) if the keysym isn't a dual-case alphabetic,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1326 and if the caps lock key was down but the shift key
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1327 wasn't, then turn off the shift modifier. Gag barf */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1328 /* #### type lossage: assuming equivalence of emacs and
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1329 X keysyms */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1330 /* !!#### maybe fix for Mule */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1331 if (lock_p && !shift_p &&
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1332 ! (CHAR_OR_CHAR_INTP (keysym)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1333 && keysym_obeys_caps_lock_p
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1334 ((guint) XCHAR_OR_CHAR_INT (keysym), d)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1335 modifiers &= (~XEMACS_MOD_SHIFT);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1336
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1337 /* If this key contains two distinct keysyms, that is,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1338 "shift" generates a different keysym than the
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1339 non-shifted key, then don't apply the shift modifier
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1340 bit: it's implicit. Otherwise, if there would be no
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1341 other way to tell the difference between the shifted
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1342 and unshifted version of this key, apply the shift bit.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1343 Non-graphics, like Backspace and F1 get the shift bit
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1344 in the modifiers slot. Neither the characters "a",
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1345 "A", "2", nor "@" normally have the shift bit set.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1346 However, "F1" normally does. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1347 if (modifiers & XEMACS_MOD_SHIFT)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1348 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1349 if (CHAR_OR_CHAR_INTP (keysym))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1350 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1351 modifiers &= ~XEMACS_MOD_SHIFT;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1352 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1353 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1354
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1355 emacs_event->event_type = key_press_event;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1356 emacs_event->timestamp = key_event->time;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1357 emacs_event->event.key.modifiers = modifiers;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1358 emacs_event->event.key.keysym = keysym;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1359 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1360 else /* Mouse press/release event */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1361 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1362 GdkEventButton *button_event = &gdk_event->button;
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 790
diff changeset
1363 emacs_event->channel = wrap_frame (frame);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1364
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1365 emacs_event->event_type = (button_event->type == GDK_BUTTON_RELEASE) ?
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1366 button_release_event : button_press_event;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1367
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1368 emacs_event->event.button.modifiers = modifiers;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1369 emacs_event->timestamp = button_event->time;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1370 emacs_event->event.button.button = button_event->button;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1371 emacs_event->event.button.x = button_event->x;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1372 emacs_event->event.button.y = button_event->y;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1373 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1374 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1375 break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1376 case GDK_KEY_RELEASE:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1377 return 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1378 break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1379 case GDK_MOTION_NOTIFY:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1380 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1381 GdkEventMotion *ev = &gdk_event->motion;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1382 unsigned int modifiers = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1383 gint x,y;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1384 GdkModifierType mask;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1385
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1386 /* We use MOTION_HINT_MASK, so we will get only one motion
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1387 event until the next time we call gdk_window_get_pointer or
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1388 the user clicks the mouse. So call gdk_window_get_pointer
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1389 now (meaning that the event will be in sync with the server
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1390 just before Fnext_event() returns). If the mouse is still
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1391 in motion, then the server will immediately generate
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1392 exactly one more motion event, which will be on the queue
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1393 waiting for us next time around. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1394 gdk_window_get_pointer (ev->window, &x, &y, &mask);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1395
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1396 DEVICE_GTK_MOUSE_TIMESTAMP (d) = ev->time;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1397
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 790
diff changeset
1398 emacs_event->channel = wrap_frame (frame);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1399 emacs_event->event_type = pointer_motion_event;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1400 emacs_event->timestamp = ev->time;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1401 emacs_event->event.motion.x = x;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1402 emacs_event->event.motion.y = y;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1403 if (mask & GDK_SHIFT_MASK) modifiers |= XEMACS_MOD_SHIFT;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1404 if (mask & GDK_CONTROL_MASK) modifiers |= XEMACS_MOD_CONTROL;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1405 if (mask & gd->MetaMask) modifiers |= XEMACS_MOD_META;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1406 if (mask & gd->SuperMask) modifiers |= XEMACS_MOD_SUPER;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1407 if (mask & gd->HyperMask) modifiers |= XEMACS_MOD_HYPER;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1408 if (mask & gd->AltMask) modifiers |= XEMACS_MOD_ALT;
589
37fe04af1590 [xemacs-hg @ 2001-05-31 02:00:29 by wmperry]
wmperry
parents: 563
diff changeset
1409 if (mask & GDK_BUTTON1_MASK) modifiers |= XEMACS_MOD_BUTTON1;
37fe04af1590 [xemacs-hg @ 2001-05-31 02:00:29 by wmperry]
wmperry
parents: 563
diff changeset
1410 if (mask & GDK_BUTTON2_MASK) modifiers |= XEMACS_MOD_BUTTON2;
37fe04af1590 [xemacs-hg @ 2001-05-31 02:00:29 by wmperry]
wmperry
parents: 563
diff changeset
1411 if (mask & GDK_BUTTON3_MASK) modifiers |= XEMACS_MOD_BUTTON3;
37fe04af1590 [xemacs-hg @ 2001-05-31 02:00:29 by wmperry]
wmperry
parents: 563
diff changeset
1412 if (mask & GDK_BUTTON4_MASK) modifiers |= XEMACS_MOD_BUTTON4;
37fe04af1590 [xemacs-hg @ 2001-05-31 02:00:29 by wmperry]
wmperry
parents: 563
diff changeset
1413 if (mask & GDK_BUTTON5_MASK) modifiers |= XEMACS_MOD_BUTTON5;
37fe04af1590 [xemacs-hg @ 2001-05-31 02:00:29 by wmperry]
wmperry
parents: 563
diff changeset
1414
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1415 /* Currently ignores Shift_Lock but probably shouldn't
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1416 (but it definitely should ignore Caps_Lock). */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1417 emacs_event->event.motion.modifiers = modifiers;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1418 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1419 break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1420
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1421 default: /* it's a magic event */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1422 return (0);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1423 break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1424 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1425 return 1;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1426 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1427
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1428 static const char *event_name (GdkEvent *);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1429
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1430 static gboolean
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1431 generic_event_handler (GtkWidget *widget, GdkEvent *event)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1432 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1433 Lisp_Object emacs_event = Qnil;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1434 if (!GTK_IS_XEMACS (widget))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1435 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1436 stderr_out ("Got a %s event for a non-XEmacs widget\n",event_name (event));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1437 return (FALSE);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1438 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1439
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1440 emacs_event = Fmake_event (Qnil, Qnil);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1441
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1442 if (gtk_event_to_emacs_event (GTK_XEMACS_FRAME (widget), event, XEVENT (emacs_event)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1443 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1444 enqueue_gtk_dispatch_event (emacs_event);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1445 return (TRUE);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1446 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1447 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1448 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1449 Fdeallocate_event (emacs_event);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1450 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1451 return (FALSE);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1452 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1453
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1454 gint emacs_gtk_key_event_handler(GtkWidget *widget, GdkEventKey *event)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1455 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1456 return (generic_event_handler (widget, (GdkEvent *) event));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1457 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1458
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1459 gint emacs_gtk_button_event_handler(GtkWidget *widget, GdkEventButton *event)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1460 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1461 return (generic_event_handler (widget, (GdkEvent *) event));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1462 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1463
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1464 gint emacs_gtk_motion_event_handler (GtkWidget *widget, GdkEventMotion *event)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1465 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1466 return (generic_event_handler (widget, (GdkEvent *) event));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1467 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1468
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1469 gboolean
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1470 emacs_shell_event_handler (GtkWidget *wid /* unused */,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1471 GdkEvent *event,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1472 gpointer closure)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1473 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1474 struct frame *frame = (struct frame *) closure;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1475 Lisp_Object lisp_event = Fmake_event (Qnil, Qnil);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1476 struct Lisp_Event *emacs_event = XEVENT (lisp_event);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1477 GdkEvent *gdk_event_copy = &emacs_event->event.magic.underlying_gdk_event;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1478 struct device *d = XDEVICE (FRAME_DEVICE (frame));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1479 gboolean ignore_p = FALSE;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1480
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1481 set_last_server_timestamp (d, event);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1482
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1483 #define FROB(event_member) gdk_event_copy->event_member = event->event_member
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1484
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1485 switch (event->type)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1486 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1487 case GDK_SELECTION_REQUEST:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1488 case GDK_SELECTION_CLEAR:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1489 case GDK_SELECTION_NOTIFY: FROB(selection); break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1490 case GDK_PROPERTY_NOTIFY: FROB(property); break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1491 case GDK_CLIENT_EVENT: FROB(client); break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1492 case GDK_MAP:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1493 case GDK_UNMAP: FROB(any); break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1494 case GDK_CONFIGURE: FROB(configure); break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1495 case GDK_ENTER_NOTIFY:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1496 case GDK_LEAVE_NOTIFY: FROB(crossing); break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1497 case GDK_FOCUS_CHANGE: FROB(focus_change); break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1498 case GDK_VISIBILITY_NOTIFY: FROB(visibility); break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1499 default:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1500 ignore_p = TRUE;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1501 /* Hrmm... do we really want to swallow all the other events as magic? */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1502 *gdk_event_copy = *event;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1503 break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1504 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1505 #undef FROB
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1506
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1507 emacs_event->event_type = magic_event;
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 790
diff changeset
1508 emacs_event->channel = wrap_frame (frame);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1509
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1510 if (ignore_p)
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 790
diff changeset
1511 {
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1512 stderr_out ("Ignoring event... (%s)\n", event_name (event));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1513 Fdeallocate_event (lisp_event);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1514 return (FALSE);
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 790
diff changeset
1515 }
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1516 else
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 790
diff changeset
1517 {
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1518 enqueue_gtk_dispatch_event (lisp_event);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1519 return (TRUE);
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 790
diff changeset
1520 }
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1521 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1522
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1523
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1524 /************************************************************************/
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1525 /* input pending / C-g checking */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1526 /************************************************************************/
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1527 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1528 gtk_check_for_quit_char (struct device *d);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1529
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1530 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1531 check_for_tty_quit_char (struct device *d)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1532 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1533 SELECT_TYPE temp_mask;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1534 int infd = DEVICE_INFD (d);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1535 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1536 Emchar quit_char = CONSOLE_QUIT_CHAR (con);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1537
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1538 FD_ZERO (&temp_mask);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1539 FD_SET (infd, &temp_mask);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1540
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1541 while (1)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1542 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1543 Lisp_Object event;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1544 Emchar the_char;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1545
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1546 if (!poll_fds_for_input (temp_mask))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1547 return;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1548
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1549 event = Fmake_event (Qnil, Qnil);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1550 if (!read_event_from_tty_or_stream_desc (XEVENT (event), con))
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1551 /* EOF, or something ... */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1552 return;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1553 /* #### bogus. quit-char should be allowed to be any sort
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1554 of event. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1555 the_char = event_to_character (XEVENT (event), 1, 0, 0);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1556 if (the_char >= 0 && the_char == quit_char)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1557 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1558 Vquit_flag = Qt;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1559 /* do not queue the C-g. See above. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1560 return;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1561 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1562
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1563 /* queue the read event to be read for real later. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1564 enqueue_gtk_dispatch_event (event);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1565 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1566 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1567
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1568 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1569 emacs_gtk_quit_p (void)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1570 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1571 Lisp_Object devcons, concons;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1572
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1573 CONSOLE_LOOP (concons)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1574 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1575 struct console *con = XCONSOLE (XCAR (concons));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1576 if (!con->input_enabled)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1577 continue;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1578
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1579 CONSOLE_DEVICE_LOOP (devcons, con)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1580 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1581 struct device *d;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1582 d = XDEVICE (XCAR (devcons));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1583
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1584 if (DEVICE_GTK_P (d))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1585 /* emacs may be exiting */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1586 gtk_check_for_quit_char (d);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1587 else if (DEVICE_TTY_P (d))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1588 check_for_tty_quit_char (d);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1589 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1590 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1591 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1592
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1593 #include <gdk/gdkx.h>
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1594
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1595 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1596 drain_gtk_queue (void)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1597
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1598 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1599 /* We can't just spin through here and wait for GTKs idea of the
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1600 event queue to get empty, or the queue never gets drained. The
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1601 situation is as follows. A process event gets signalled, we put
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1602 it on the queue, then we go into Fnext_event(), which calls
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1603 drain_gtk_queue(). But gtk_events_pending() will always return
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1604 TRUE if there are file-descriptor (aka our process) events
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1605 pending. Using GDK_events_pending() only shows us windowing
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1606 system events.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1607 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1608 if (GDK_DISPLAY ())
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1609 while (gdk_events_pending ())
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1610 gtk_main_iteration ();
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1611 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1612
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1613 static int
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1614 emacs_gtk_event_pending_p (int user_p)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1615 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1616 Lisp_Object event;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1617 int tick_count_val;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1618
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1619 /* If `user_p' is false, then this function returns whether there are any
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1620 X, timeout, or fd events pending (that is, whether emacs_gtk_next_event()
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1621 would return immediately without blocking).
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1622
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1623 if `user_p' is true, then this function returns whether there are any
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1624 *user generated* events available (that is, whether there are keyboard
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1625 or mouse-click events ready to be read). This also implies that
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1626 emacs_Xt_next_event() would not block.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1627
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1628 In a non-SIGIO world, this also checks whether the user has typed ^G,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1629 since this is a convenient place to do so. We don't need to do this
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1630 in a SIGIO world, since input causes an interrupt.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1631 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1632
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1633 /* This function used to simply check whether there were any X
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1634 events (or if user_p was 1, it iterated over all the pending
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1635 X events using XCheckIfEvent(), looking for keystrokes and
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1636 button events). That worked in the old cheesoid event loop,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1637 which didn't go through XtAppDispatchEvent(), but it doesn't
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1638 work any more -- X events may not result in anything. For
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1639 example, a button press in a blank part of the menubar appears
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1640 as an X event but will not result in any Emacs events (a
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1641 button press that activates the menubar results in an Emacs
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1642 event through the stop_next_event mechanism).
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1643
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1644 The only accurate way of determining whether these X events
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1645 translate into Emacs events is to go ahead and dispatch them
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1646 until there's something on the dispatch queue. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1647
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1648 /* See if there are any user events already on the queue. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1649 EVENT_CHAIN_LOOP (event, dispatch_event_queue)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1650 if (!user_p || command_event_p (event))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1651 return 1;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1652
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1653 /* See if there's any TTY input available.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1654 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1655 if (poll_fds_for_input (tty_only_mask))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1656 return 1;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1657
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1658 if (!user_p)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1659 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1660 /* If not user_p and there are any timer or file-desc events
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1661 pending, we know there will be an event so we're through. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1662 /* XtInputMask pending_value; */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1663
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1664 /* Note that formerly we just checked the value of XtAppPending()
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1665 to determine if there was file-desc input. This doesn't
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1666 work any more with the signal_event_pipe; XtAppPending()
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1667 will says "yes" in this case but there isn't really any
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1668 input. Another way of fixing this problem is for the
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1669 signal_event_pipe to generate actual input in the form
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1670 of an identity eval event or something. (#### maybe this
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1671 actually happens?) */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1672
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1673 if (poll_fds_for_input (process_only_mask))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1674 return 1;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1675
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1676 /* #### Is there any way to do this in Gtk? I don't think there
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1677 is a 'peek' for events */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1678 #if 0
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1679 pending_value = XtAppPending (Xt_app_con);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1680
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1681 if (pending_value & XtIMTimer)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1682 return 1;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1683 #endif
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1684 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1685
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1686 /* XtAppPending() can be super-slow, esp. over a network connection.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1687 Quantify results have indicated that in some cases the
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1688 call to detect_input_pending() completely dominates the
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1689 running time of redisplay(). Fortunately, in a SIGIO world
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1690 we can more quickly determine whether there are any X events:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1691 if an event has happened since the last time we checked, then
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1692 a SIGIO will have happened. On a machine with broken SIGIO,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1693 we'll still be in an OK state -- the sigio_happened flag
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1694 will get set at least once a second, so we'll be no more than
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1695 one second behind reality. (In general it's OK if we
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1696 erroneously report no input pending when input is actually
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1697 pending() -- preemption is just a bit less efficient, that's
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1698 all. It's bad bad bad if you err the other way -- you've
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1699 promised that `next-event' won't block but it actually will,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1700 and some action might get delayed until the next time you
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1701 hit a key.)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1702 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1703
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1704 /* quit_check_signal_tick_count is volatile so try to avoid race conditions
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1705 by using a temporary variable */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1706 tick_count_val = quit_check_signal_tick_count;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1707 if (last_quit_check_signal_tick_count != tick_count_val)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1708 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1709 last_quit_check_signal_tick_count = tick_count_val;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1710
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1711 /* We need to drain the entire queue now -- if we only
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1712 drain part of it, we may later on end up with events
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1713 actually pending but detect_input_pending() returning
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1714 false because there wasn't another SIGIO. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1715
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1716 drain_gtk_queue ();
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1717
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1718 EVENT_CHAIN_LOOP (event, dispatch_event_queue)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1719 if (!user_p || command_event_p (event))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1720 return 1;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1721 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1722
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1723 return 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1724 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1725
790
755d0acc05ea [xemacs-hg @ 2002-03-21 15:47:19 by wmperry]
wmperry
parents: 789
diff changeset
1726 static void
755d0acc05ea [xemacs-hg @ 2002-03-21 15:47:19 by wmperry]
wmperry
parents: 789
diff changeset
1727 emacs_gtk_force_event_pending (struct frame* f)
755d0acc05ea [xemacs-hg @ 2002-03-21 15:47:19 by wmperry]
wmperry
parents: 789
diff changeset
1728 {
755d0acc05ea [xemacs-hg @ 2002-03-21 15:47:19 by wmperry]
wmperry
parents: 789
diff changeset
1729 #if 0
755d0acc05ea [xemacs-hg @ 2002-03-21 15:47:19 by wmperry]
wmperry
parents: 789
diff changeset
1730 stderr_out ("Force event pending called on frame %p!\n", f);
755d0acc05ea [xemacs-hg @ 2002-03-21 15:47:19 by wmperry]
wmperry
parents: 789
diff changeset
1731 #endif
755d0acc05ea [xemacs-hg @ 2002-03-21 15:47:19 by wmperry]
wmperry
parents: 789
diff changeset
1732 }
755d0acc05ea [xemacs-hg @ 2002-03-21 15:47:19 by wmperry]
wmperry
parents: 789
diff changeset
1733
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1734
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1735 /************************************************************************/
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1736 /* initialization */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1737 /************************************************************************/
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1738
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1739 void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1740 syms_of_event_gtk (void)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1741 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 464
diff changeset
1742 DEFSYMBOL (Qkey_mapping);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 464
diff changeset
1743 DEFSYMBOL (Qsans_modifiers);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1744 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1745
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1746 void reinit_vars_of_event_gtk (void)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1747 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1748 gtk_event_stream = xnew (struct event_stream);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1749 gtk_event_stream->event_pending_p = emacs_gtk_event_pending_p;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1750 gtk_event_stream->next_event_cb = emacs_gtk_next_event;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1751 gtk_event_stream->handle_magic_event_cb= emacs_gtk_handle_magic_event;
788
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
1752 gtk_event_stream->format_magic_event_cb= emacs_gtk_format_magic_event;
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
1753 gtk_event_stream->compare_magic_event_cb= emacs_gtk_compare_magic_event;
026c5bf9c134 [xemacs-hg @ 2002-03-21 07:29:57 by ben]
ben
parents: 778
diff changeset
1754 gtk_event_stream->hash_magic_event_cb = emacs_gtk_hash_magic_event;
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1755 gtk_event_stream->add_timeout_cb = emacs_gtk_add_timeout;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1756 gtk_event_stream->remove_timeout_cb = emacs_gtk_remove_timeout;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1757 gtk_event_stream->select_console_cb = emacs_gtk_select_console;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1758 gtk_event_stream->unselect_console_cb = emacs_gtk_unselect_console;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1759 gtk_event_stream->select_process_cb = emacs_gtk_select_process;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1760 gtk_event_stream->unselect_process_cb = emacs_gtk_unselect_process;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1761 gtk_event_stream->quit_p_cb = emacs_gtk_quit_p;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1762 gtk_event_stream->create_stream_pair_cb= emacs_gtk_create_stream_pair;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1763 gtk_event_stream->delete_stream_pair_cb= emacs_gtk_delete_stream_pair;
790
755d0acc05ea [xemacs-hg @ 2002-03-21 15:47:19 by wmperry]
wmperry
parents: 789
diff changeset
1764 gtk_event_stream->force_event_pending = emacs_gtk_force_event_pending;
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1765
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1766 the_GTK_timeout_blocktype = Blocktype_new (struct GTK_timeout_blocktype);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1767
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1768 /* this function only makes safe calls */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1769 init_what_input_once ();
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1770 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1771
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1772 void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1773 vars_of_event_gtk (void)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1774 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1775 reinit_vars_of_event_gtk ();
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1776
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1777 dispatch_event_queue = Qnil;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1778 staticpro (&dispatch_event_queue);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1779 dispatch_event_queue_tail = Qnil;
464
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 462
diff changeset
1780 staticpro (&dispatch_event_queue_tail);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1781
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1782 DEFVAR_BOOL ("gtk-allow-sendevents", &gtk_allow_sendevents /*
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1783 *Non-nil means to allow synthetic events. Nil means they are ignored.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1784 Beware: allowing emacs to process SendEvents opens a big security hole.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1785 */ );
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1786 gtk_allow_sendevents = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1787
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1788 last_quit_check_signal_tick_count = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1789 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1790
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1791 void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1792 init_event_gtk_late (void) /* called when already initialized */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1793 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1794 timeout_id_tick = 1;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1795 pending_timeouts = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1796 completed_timeouts = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1797
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1798 event_stream = gtk_event_stream;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1799
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1800 #if 0
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1801 /* Shut GDK the hell up */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1802 gdk_error_trap_push ();
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1803 #endif
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1804
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1805 gdk_input_add (signal_event_pipe[0], GDK_INPUT_READ,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1806 (GdkInputFunction) gtk_what_callback, NULL);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1807 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1808
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1809 /* Bogus utility routines */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1810 static const char *event_name (GdkEvent *ev)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1811 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1812 return (gtk_event_name (ev->any.type));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1813 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1814
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1815 /* This is down at the bottom of the file so I can avoid polluting the
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1816 generic code with this X specific CRAP! */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1817
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1818 #include <gdk/gdkx.h>
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1819 #include <X11/keysym.h>
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1820 /* #### BILL!!! Fix this please! */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1821
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1822
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1823 /************************************************************************/
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1824 /* keymap handling */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1825 /************************************************************************/
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1826
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1827 /* X bogusly doesn't define the interpretations of any bits besides
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1828 ModControl, ModShift, and ModLock; so the Interclient Communication
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1829 Conventions Manual says that we have to bend over backwards to figure
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1830 out what the other modifier bits mean. According to ICCCM:
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1831
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1832 - Any keycode which is assigned ModControl is a "control" key.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1833
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1834 - Any modifier bit which is assigned to a keycode which generates Meta_L
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1835 or Meta_R is the modifier bit meaning "meta". Likewise for Super, Hyper,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1836 etc.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1837
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1838 - Any keypress event which contains ModControl in its state should be
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1839 interpreted as a "control" character.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1840
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1841 - Any keypress event which contains a modifier bit in its state which is
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1842 generated by a keycode whose corresponding keysym is Meta_L or Meta_R
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1843 should be interpreted as a "meta" character. Likewise for Super, Hyper,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1844 etc.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1845
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1846 - It is illegal for a keysym to be associated with more than one modifier
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1847 bit.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1848
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1849 This means that the only thing that emacs can reasonably interpret as a
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1850 "meta" key is a key whose keysym is Meta_L or Meta_R, and which generates
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1851 one of the modifier bits Mod1-Mod5.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1852
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1853 Unfortunately, many keyboards don't have Meta keys in their default
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1854 configuration. So, if there are no Meta keys, but there are "Alt" keys,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1855 emacs will interpret Alt as Meta. If there are both Meta and Alt keys,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1856 then the Meta keys mean "Meta", and the Alt keys mean "Alt" (it used to
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1857 mean "Symbol," but that just confused the hell out of way too many people).
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1858
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1859 This works with the default configurations of the 19 keyboard-types I've
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1860 checked.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1861
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1862 Emacs detects keyboard configurations which violate the above rules, and
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1863 prints an error message on the standard-error-output. (Perhaps it should
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1864 use a pop-up-window instead.)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1865 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1866
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1867 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1868 gtk_reset_key_mapping (struct device *d)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1869 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1870 Display *display = GDK_DISPLAY ();
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1871 struct gtk_device *xd = DEVICE_GTK_DATA (d);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1872 XModifierKeymap *map = (XModifierKeymap *) xd->x_keysym_map;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1873 KeySym *keysym, *keysym_end;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1874 Lisp_Object hashtable;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1875 int key_code_count, keysyms_per_code;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1876
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1877 if (map)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1878 XFree ((char *) map);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1879 XDisplayKeycodes (display,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1880 &xd->x_keysym_map_min_code,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1881 &xd->x_keysym_map_max_code);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1882 key_code_count = xd->x_keysym_map_max_code - xd->x_keysym_map_min_code + 1;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1883 map = (XModifierKeymap *)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1884 XGetKeyboardMapping (display, xd->x_keysym_map_min_code, key_code_count,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1885 &xd->x_keysym_map_keysyms_per_code);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1886
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1887 xd->x_keysym_map = (void *)map;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1888 hashtable = xd->x_keysym_map_hashtable;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1889 if (HASH_TABLEP (hashtable))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1890 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1891 Fclrhash (hashtable);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1892 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1893 else
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1894 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1895 xd->x_keysym_map_hashtable = hashtable =
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1896 make_lisp_hash_table (128, HASH_TABLE_NON_WEAK, HASH_TABLE_EQUAL);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1897 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1898
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1899 for (keysym = (KeySym *) map,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1900 keysyms_per_code = xd->x_keysym_map_keysyms_per_code,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1901 keysym_end = keysym + (key_code_count * keysyms_per_code);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1902 keysym < keysym_end;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1903 keysym += keysyms_per_code)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1904 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1905 int j;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1906
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1907 if (keysym[0] == NoSymbol)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1908 continue;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1909
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1910 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1911 Extbyte *name = XKeysymToString (keysym[0]);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1912 Lisp_Object sym = gtk_keysym_to_emacs_keysym (keysym[0], 0);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1913 if (name)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1914 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1915 Fputhash (build_ext_string (name, Qnative), Qsans_modifiers,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1916 hashtable);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1917 Fputhash (sym, Qsans_modifiers, hashtable);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1918 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1919 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1920
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1921 for (j = 1; j < keysyms_per_code; j++)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1922 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1923 if (keysym[j] != keysym[0] &&
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1924 keysym[j] != NoSymbol)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1925 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1926 Extbyte *name = XKeysymToString (keysym[j]);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1927 Lisp_Object sym = gtk_keysym_to_emacs_keysym (keysym[j], 0);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1928 if (name && NILP (Fgethash (sym, hashtable, Qnil)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1929 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1930 Fputhash (build_ext_string (name, Qnative), Qt, hashtable);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1931 Fputhash (sym, Qt, hashtable);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1932 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1933 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1934 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1935 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1936 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1937
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1938 static const char *
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1939 index_to_name (int indice)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1940 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1941 switch (indice)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1942 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1943 case ShiftMapIndex: return "ModShift";
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1944 case LockMapIndex: return "ModLock";
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1945 case ControlMapIndex: return "ModControl";
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1946 case Mod1MapIndex: return "Mod1";
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1947 case Mod2MapIndex: return "Mod2";
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1948 case Mod3MapIndex: return "Mod3";
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1949 case Mod4MapIndex: return "Mod4";
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1950 case Mod5MapIndex: return "Mod5";
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1951 default: return "???";
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1952 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1953 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1954
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1955 /* Boy, I really wish C had local functions... */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1956 struct c_doesnt_have_closures /* #### not yet used */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1957 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1958 int warned_about_overlapping_modifiers;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1959 int warned_about_predefined_modifiers;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1960 int warned_about_duplicate_modifiers;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1961 int meta_bit;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1962 int hyper_bit;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1963 int super_bit;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1964 int alt_bit;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1965 int mode_bit;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1966 };
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1967
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1968 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1969 gtk_reset_modifier_mapping (struct device *d)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1970 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1971 Display *display = GDK_DISPLAY ();
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1972 struct gtk_device *xd = DEVICE_GTK_DATA (d);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1973 int modifier_index, modifier_key, column, mkpm;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1974 int warned_about_overlapping_modifiers = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1975 /* int warned_about_predefined_modifiers = 0; */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1976 /* int warned_about_duplicate_modifiers = 0; */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1977 int meta_bit = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1978 int hyper_bit = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1979 int super_bit = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1980 int alt_bit = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1981 int mode_bit = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1982 XModifierKeymap *map = (XModifierKeymap *) xd->x_modifier_keymap;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1983
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1984 xd->lock_interpretation = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1985
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1986 if (map)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1987 XFreeModifiermap (map);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1988
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1989 gtk_reset_key_mapping (d);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1990
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1991 xd->x_modifier_keymap = map = XGetModifierMapping (display);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1992
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1993 /* Boy, I really wish C had local functions...
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1994 */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1995
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1996 /* The call to warn_when_safe must be on the same line as the string or
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1997 make-msgfile won't pick it up properly (the newline doesn't confuse
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1998 it, but the backslash does). */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
1999
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2000 #define store_modifier(name,old) \
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2001 old = modifier_index;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2002
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2003 mkpm = map->max_keypermod;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2004 for (modifier_index = 0; modifier_index < 8; modifier_index++)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2005 for (modifier_key = 0; modifier_key < mkpm; modifier_key++) {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2006 KeySym last_sym = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2007 for (column = 0; column < 4; column += 2) {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2008 KeyCode code = map->modifiermap[modifier_index * mkpm
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2009 + modifier_key];
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2010 KeySym sym = (code ? XKeycodeToKeysym (display, code, column) : 0);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2011 if (sym == last_sym) continue;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2012 last_sym = sym;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2013 switch (sym) {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2014 case XK_Mode_switch:store_modifier ("Mode_switch", mode_bit); break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2015 case XK_Meta_L: store_modifier ("Meta_L", meta_bit); break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2016 case XK_Meta_R: store_modifier ("Meta_R", meta_bit); break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2017 case XK_Super_L: store_modifier ("Super_L", super_bit); break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2018 case XK_Super_R: store_modifier ("Super_R", super_bit); break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2019 case XK_Hyper_L: store_modifier ("Hyper_L", hyper_bit); break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2020 case XK_Hyper_R: store_modifier ("Hyper_R", hyper_bit); break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2021 case XK_Alt_L: store_modifier ("Alt_L", alt_bit); break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2022 case XK_Alt_R: store_modifier ("Alt_R", alt_bit); break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2023 #if 0
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2024 case XK_Control_L: check_modifier ("Control_L", ControlMask); break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2025 case XK_Control_R: check_modifier ("Control_R", ControlMask); break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2026 case XK_Shift_L: check_modifier ("Shift_L", ShiftMask); break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2027 case XK_Shift_R: check_modifier ("Shift_R", ShiftMask); break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2028 #endif
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2029 case XK_Shift_Lock: /* check_modifier ("Shift_Lock", LockMask); */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2030 xd->lock_interpretation = XK_Shift_Lock; break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2031 case XK_Caps_Lock: /* check_modifier ("Caps_Lock", LockMask); */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2032 xd->lock_interpretation = XK_Caps_Lock; break;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2033
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2034 /* It probably doesn't make any sense for a modifier bit to be
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2035 assigned to a key that is not one of the above, but OpenWindows
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2036 assigns modifier bits to a couple of random function keys for
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2037 no reason that I can discern, so printing a warning here would
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2038 be annoying. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2039 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2040 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2041 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2042 #undef store_modifier
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2043 #undef check_modifier
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2044 #undef modwarn
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2045 #undef modbarf
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2046
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2047 /* If there was no Meta key, then try using the Alt key instead.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2048 If there is both a Meta key and an Alt key, then the Alt key
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2049 is not disturbed and remains an Alt key. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2050 if (! meta_bit && alt_bit)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2051 meta_bit = alt_bit, alt_bit = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2052
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2053 /* mode_bit overrides everything, since it's processed down inside of
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2054 XLookupString() instead of by us. If Meta and Mode_switch both
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2055 generate the same modifier bit (which is an error), then we don't
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2056 interpret that bit as Meta, because we can't make XLookupString()
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2057 not interpret it as Mode_switch; and interpreting it as both would
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2058 be totally wrong. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2059 if (mode_bit)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2060 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2061 const char *warn = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2062 if (mode_bit == meta_bit) warn = "Meta", meta_bit = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2063 else if (mode_bit == hyper_bit) warn = "Hyper", hyper_bit = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2064 else if (mode_bit == super_bit) warn = "Super", super_bit = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2065 else if (mode_bit == alt_bit) warn = "Alt", alt_bit = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2066 if (warn)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2067 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2068 warn_when_safe
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2069 (Qkey_mapping, Qwarning,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2070 "XEmacs: %s is being used for both Mode_switch and %s.",
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2071 index_to_name (mode_bit), warn),
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2072 warned_about_overlapping_modifiers = 1;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2073 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2074 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2075 #undef index_to_name
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2076
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2077 xd->MetaMask = (meta_bit ? (1 << meta_bit) : 0);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2078 xd->HyperMask = (hyper_bit ? (1 << hyper_bit) : 0);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2079 xd->SuperMask = (super_bit ? (1 << super_bit) : 0);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2080 xd->AltMask = (alt_bit ? (1 << alt_bit) : 0);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2081 xd->ModeMask = (mode_bit ? (1 << mode_bit) : 0); /* unused */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2082
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2083 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2084
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2085 void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2086 gtk_init_modifier_mapping (struct device *d)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2087 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2088 struct gtk_device *gd = DEVICE_GTK_DATA (d);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2089 gd->x_keysym_map_hashtable = Qnil;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2090 gd->x_keysym_map = NULL;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2091 gd->x_modifier_keymap = NULL;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2092 gtk_reset_modifier_mapping (d);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2093 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2094
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2095 #if 0
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2096 static int
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2097 gtk_key_is_modifier_p (KeyCode keycode, struct device *d)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2098 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2099 struct gtk_device *xd = DEVICE_GTK_DATA (d);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2100 KeySym *syms;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2101 KeySym *map = (KeySym *) xd->x_keysym_map;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2102 int i;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2103
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2104 if (keycode < xd->x_keysym_map_min_code ||
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2105 keycode > xd->x_keysym_map_max_code)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2106 return 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2107
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2108 syms = &map [(keycode - xd->x_keysym_map_min_code) *
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2109 xd->x_keysym_map_keysyms_per_code];
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2110 for (i = 0; i < xd->x_keysym_map_keysyms_per_code; i++)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2111 if (IsModifierKey (syms [i]) ||
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2112 syms [i] == XK_Mode_switch) /* why doesn't IsModifierKey count this? */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2113 return 1;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2114 return 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2115 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2116 #endif
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2117
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2118 struct _quit_predicate_closure {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2119 struct device *device;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2120 Bool *critical;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2121 };
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2122
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2123 static Bool
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2124 quit_char_predicate (Display *display, XEvent *event, XPointer data)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2125 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2126 struct _quit_predicate_closure *cl = (struct _quit_predicate_closure *) data;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2127 struct device *d = cl->device;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2128 struct frame *f = NULL;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2129 struct gtk_device *gd = DEVICE_GTK_DATA (d);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2130 char c, quit_char;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2131 Bool *critical = cl->critical;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2132 Lisp_Object keysym;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2133 GdkWindow *window = gdk_window_lookup (event->xany.window);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2134 guint32 keycode = 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2135 GdkEventKey gdk_event;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2136
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2137 if (window)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2138 f = gtk_any_window_to_frame (d, window);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2139
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2140 if (critical)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2141 *critical = False;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2142
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2143 if ((event->type != KeyPress) ||
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2144 (! window) ||
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2145 (! f) ||
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2146 (event->xkey.state
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2147 & (gd->MetaMask | gd->HyperMask | gd->SuperMask | gd->AltMask)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2148 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2149 return 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2150 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2151
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2152 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2153 char dummy[256];
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2154 XLookupString (&(event->xkey), dummy, 200, (KeySym *)&keycode, 0);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2155 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2156
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2157 memset (&gdk_event, 0, sizeof (gdk_event));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2158 gdk_event.type = GDK_KEY_PRESS;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2159 gdk_event.window = window;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2160 gdk_event.keyval = keycode;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2161 gdk_event.state = event->xkey.state;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2162
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2163 /* This duplicates some code that exists elsewhere, but it's relatively
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2164 fast and doesn't cons. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2165 keysym = gtk_to_emacs_keysym (d, &gdk_event, 1);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2166 if (NILP (keysym)) return 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2167 if (CHAR_OR_CHAR_INTP (keysym))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2168 c = XCHAR_OR_CHAR_INT (keysym);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2169 /* Highly doubtful that these are the quit character, but... */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2170 else if (EQ (keysym, QKbackspace)) c = '\b';
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2171 else if (EQ (keysym, QKtab)) c = '\t';
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2172 else if (EQ (keysym, QKlinefeed)) c = '\n';
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2173 else if (EQ (keysym, QKreturn)) c = '\r';
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2174 else if (EQ (keysym, QKescape)) c = 27;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2175 else if (EQ (keysym, QKspace)) c = ' ';
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2176 else if (EQ (keysym, QKdelete)) c = 127;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2177 else return 0;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2178
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2179 if (event->xkey.state & gd->MetaMask) c |= 0x80;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2180 if ((event->xkey.state & ControlMask) && !(c >= 'A' && c <= 'Z'))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2181 c &= 0x1F; /* unshifted control characters */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2182 quit_char = CONSOLE_QUIT_CHAR (XCONSOLE (DEVICE_CONSOLE (d)));
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2183
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2184 if (c == quit_char)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2185 return True;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2186 /* If we've got Control-Shift-G instead of Control-G, that means
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2187 we have a critical_quit. Caps_Lock is its own modifier, so it
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2188 won't cause ^G to act differently than before. */
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2189 if (event->xkey.state & ControlMask) c &= 0x1F;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2190 if (c == quit_char)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2191 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2192 if (critical) *critical = True;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2193 return True;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2194 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2195 return False;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2196 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2197
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2198 static void
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2199 gtk_check_for_quit_char (struct device *d)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2200 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2201 XEvent event;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2202 int queued;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2203 Bool critical_quit = False;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2204 struct _quit_predicate_closure closure;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2205
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2206 XEventsQueued (GDK_DISPLAY (), QueuedAfterReading);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2207
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2208 closure.device = d;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2209 closure.critical = &critical_quit;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2210
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2211 queued = XCheckIfEvent (GDK_DISPLAY (), &event, quit_char_predicate, (char *) &closure);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2212
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2213 if (queued)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2214 {
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2215 Vquit_flag = (critical_quit ? Qcritical : Qt);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2216 }
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents:
diff changeset
2217 }