Fix crashes in `delete-terminal' caused by recursive calls or X displays with live...
[emacs.git] / src / termhooks.h
blob46fb0c453f5ab027729c08cd8d173297ee31fdfe
1 /* Parameters and display hooks for terminal devices.
2 Copyright (C) 1985, 1986, 1993, 1994, 2002, 2003, 2004,
3 2005, 2006 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
23 /* Miscellanea. */
25 struct glyph;
26 struct frame;
28 /* Only use prototypes when lisp.h has been included. */
29 #ifndef P_
30 #define P_(X) ()
31 #endif
34 enum scroll_bar_part {
35 scroll_bar_above_handle,
36 scroll_bar_handle,
37 scroll_bar_below_handle,
38 scroll_bar_up_arrow,
39 scroll_bar_down_arrow,
40 scroll_bar_to_top,
41 scroll_bar_to_bottom,
42 scroll_bar_end_scroll,
43 scroll_bar_move_ratio
47 /* Input queue declarations and hooks. */
49 /* Expedient hack: only provide the below definitions to files that
50 are prepared to handle lispy things. CONSP is defined iff lisp.h
51 has been included before this file. */
52 #ifdef CONSP
54 enum event_kind
56 NO_EVENT, /* nothing happened. This should never
57 actually appear in the event queue. */
59 ASCII_KEYSTROKE_EVENT, /* The ASCII code is in .code, perhaps
60 with modifiers applied.
61 .modifiers holds the state of the
62 modifier keys.
63 .frame_or_window is the frame in
64 which the key was typed.
65 .timestamp gives a timestamp (in
66 milliseconds) for the keystroke. */
67 MULTIBYTE_CHAR_KEYSTROKE_EVENT, /* The multibyte char code is in .code,
68 perhaps with modifiers applied.
69 The others are the same as
70 ASCII_KEYSTROKE_EVENT. */
71 NON_ASCII_KEYSTROKE_EVENT, /* .code is a number identifying the
72 function key. A code N represents
73 a key whose name is
74 function_key_names[N]; function_key_names
75 is a table in keyboard.c to which you
76 should feel free to add missing keys.
77 .modifiers holds the state of the
78 modifier keys.
79 .frame_or_window is the frame in
80 which the key was typed.
81 .timestamp gives a timestamp (in
82 milliseconds) for the keystroke. */
83 TIMER_EVENT, /* A timer fired. */
84 MOUSE_CLICK_EVENT, /* The button number is in .code; it must
85 be >= 0 and < NUM_MOUSE_BUTTONS, defined
86 below.
87 .modifiers holds the state of the
88 modifier keys.
89 .x and .y give the mouse position,
90 in characters, within the window.
91 .frame_or_window gives the frame
92 the mouse click occurred in.
93 .timestamp gives a timestamp (in
94 milliseconds) for the click. */
95 WHEEL_EVENT, /* A wheel event is generated by a
96 wheel on a mouse (e.g., MS
97 Intellimouse).
98 .modifiers holds the rotate
99 direction (up or down), and the
100 state of the modifier keys.
101 .x and .y give the mouse position,
102 in characters, within the window.
103 .frame_or_window gives the frame
104 the wheel event occurred in.
105 .timestamp gives a timestamp (in
106 milliseconds) for the event. */
107 #if defined (WINDOWSNT) || defined (MAC_OS)
108 LANGUAGE_CHANGE_EVENT, /* A LANGUAGE_CHANGE_EVENT is
109 generated on WINDOWSNT or Mac OS
110 when the keyboard layout or input
111 language is changed by the
112 user. */
113 #endif
114 SCROLL_BAR_CLICK_EVENT, /* .code gives the number of the mouse button
115 that was clicked.
116 .modifiers holds the state of the modifier
117 keys.
118 .part is a lisp symbol indicating which
119 part of the scroll bar got clicked.
120 .x gives the distance from the start of the
121 scroll bar of the click; .y gives the total
122 length of the scroll bar.
123 .frame_or_window gives the window
124 whose scroll bar was clicked in.
125 .timestamp gives a timestamp (in
126 milliseconds) for the click. */
127 #ifdef WINDOWSNT
128 W32_SCROLL_BAR_CLICK_EVENT, /* as for SCROLL_BAR_CLICK, but only generated
129 by MS-Windows scroll bar controls. */
130 #endif
131 SELECTION_REQUEST_EVENT, /* Another X client wants a selection from us.
132 See `struct selection_input_event'. */
133 SELECTION_CLEAR_EVENT, /* Another X client cleared our selection. */
134 BUFFER_SWITCH_EVENT, /* A process filter has switched buffers. */
135 DELETE_WINDOW_EVENT, /* An X client said "delete this window". */
136 MENU_BAR_EVENT, /* An event generated by the menu bar.
137 The frame_or_window field's cdr holds the
138 Lisp-level event value.
139 (Only the toolkit version uses these.) */
140 ICONIFY_EVENT, /* An X client iconified this window. */
141 DEICONIFY_EVENT, /* An X client deiconified this window. */
142 MENU_BAR_ACTIVATE_EVENT, /* A button press in the menu bar
143 (toolkit version only). */
144 DRAG_N_DROP_EVENT, /* A drag-n-drop event is generated when
145 files selected outside of Emacs are dropped
146 onto an Emacs window.
147 .modifiers holds the state of the
148 modifier keys.
149 .x and .y give the mouse position,
150 in characters, within the window.
151 .frame_or_window is the frame in
152 which the drop was made.
153 .arg is a platform-dependent
154 representation of the dropped items.
155 .timestamp gives a timestamp (in
156 milliseconds) for the click. */
157 USER_SIGNAL_EVENT, /* A user signal.
158 code is a number identifying it,
159 index into lispy_user_signals. */
161 /* Help events. Member `frame_or_window' of the input_event is the
162 frame on which the event occurred, and member `arg' contains
163 the help to show. */
164 HELP_EVENT,
166 /* An event from a tool-bar. Member `arg' of the input event
167 contains the tool-bar item selected. If `frame_or_window'
168 and `arg' are equal, this is a prefix event. */
169 TOOL_BAR_EVENT,
171 /* Queued from XTread_socket on FocusIn events. Translated into
172 `switch-frame' events in kbd_buffer_get_event, if necessary. */
173 FOCUS_IN_EVENT,
175 /* Generated when mouse moves over window not currently selected. */
176 SELECT_WINDOW_EVENT,
178 /* Queued from XTread_socket when session manager sends
179 save yourself before shutdown. */
180 SAVE_SESSION_EVENT,
182 #ifdef MAC_OS
183 /* Generated when an Apple event, a HICommand event, or a Services
184 menu event is received and the corresponding handler is
185 registered. Members `x' and `y' are for the event class and ID
186 symbols, respectively. Member `arg' is a Lisp object converted
187 from the received Apple event. Parameters for non-Apple events
188 are converted to those in Apple events. */
189 MAC_APPLE_EVENT
190 #endif
193 /* If a struct input_event has a kind which is SELECTION_REQUEST_EVENT
194 or SELECTION_CLEAR_EVENT, then its contents are really described
195 by `struct selection_input_event'; see xterm.h. */
197 /* The keyboard input buffer is an array of these structures. Each one
198 represents some sort of input event - a keystroke, a mouse click, or
199 a window system event. These get turned into their lispy forms when
200 they are removed from the event queue. */
202 struct input_event
204 /* What kind of event was this? */
205 enum event_kind kind;
207 /* For an ASCII_KEYSTROKE_EVENT and MULTIBYTE_CHAR_KEYSTROKE_EVENT,
208 this is the character.
209 For a NON_ASCII_KEYSTROKE_EVENT, this is the keysym code.
210 For a mouse event, this is the button number. */
211 /* In WindowsNT, for a mouse wheel event, this is the delta. */
212 int code;
213 enum scroll_bar_part part;
215 int modifiers; /* See enum below for interpretation. */
217 Lisp_Object x, y;
218 unsigned long timestamp;
220 /* This is padding just to put the frame_or_window field
221 past the size of struct selection_input_event. */
222 int *padding[2];
224 /* This field is copied into a vector while the event is in the queue,
225 so that garbage collections won't kill it. */
226 /* In a menu_bar_event, this is a cons cell whose car is the frame
227 and whose cdr is the Lisp object that is the event's value. */
228 /* This field is last so that struct selection_input_event
229 does not overlap with it. */
230 Lisp_Object frame_or_window;
232 /* Additional event argument. This is used for TOOL_BAR_EVENTs and
233 HELP_EVENTs and avoids calling Fcons during signal handling. */
234 Lisp_Object arg;
237 #define EVENT_INIT(event) bzero (&(event), sizeof (struct input_event))
239 /* Bits in the modifiers member of the input_event structure.
240 Note that reorder_modifiers assumes that the bits are in canonical
241 order.
243 The modifiers applied to mouse clicks are rather ornate. The
244 window-system-specific code should store mouse clicks with
245 up_modifier or down_modifier set. Having an explicit down modifier
246 simplifies some of window-system-independent code; without it, the
247 code would have to recognize down events by checking if the event
248 is a mouse click lacking the click and drag modifiers.
250 The window-system independent code turns all up_modifier events
251 bits into drag_modifier, click_modifier, double_modifier, or
252 triple_modifier events. The click_modifier has no written
253 representation in the names of the symbols used as event heads,
254 but it does appear in the Qevent_symbol_components property of the
255 event heads. */
256 enum {
257 up_modifier = 1, /* Only used on mouse buttons - always
258 turned into a click or a drag modifier
259 before lisp code sees the event. */
260 down_modifier = 2, /* Only used on mouse buttons. */
261 drag_modifier = 4, /* This is never used in the event
262 queue; it's only used internally by
263 the window-system-independent code. */
264 click_modifier= 8, /* See drag_modifier. */
265 double_modifier= 16, /* See drag_modifier. */
266 triple_modifier= 32, /* See drag_modifier. */
268 /* The next four modifier bits are used also in keyboard events at
269 the Lisp level.
271 It's probably not the greatest idea to use the 2^23 bit for any
272 modifier. It may or may not be the sign bit, depending on
273 VALBITS, so using it to represent a modifier key means that
274 characters thus modified have different integer equivalents
275 depending on the architecture they're running on. Oh, and
276 applying XINT to a character whose 2^23 bit is set sign-extends
277 it, so you get a bunch of bits in the mask you didn't want.
279 The CHAR_ macros are defined in lisp.h. */
280 alt_modifier = CHAR_ALT, /* Under X, the XK_Alt_[LR] keysyms. */
281 super_modifier= CHAR_SUPER, /* Under X, the XK_Super_[LR] keysyms. */
282 hyper_modifier= CHAR_HYPER, /* Under X, the XK_Hyper_[LR] keysyms. */
283 shift_modifier= CHAR_SHIFT,
284 ctrl_modifier = CHAR_CTL,
285 meta_modifier = CHAR_META /* Under X, the XK_Meta_[LR] keysyms. */
288 #endif /* CONSP */
291 /* Terminal-local parameters. */
292 struct terminal
294 /* Chain of all terminal devices. */
295 struct terminal *next_terminal;
297 /* Unique id for this terminal device. */
298 int id;
300 /* The number of frames that are on this terminal. */
301 int reference_count;
303 /* Nonzero while deleting this terminal. Used to protect against
304 recursive calls to delete_terminal_hook. */
305 int deleted;
307 /* The type of the terminal device. */
308 enum output_method type;
310 /* The name of the terminal device. Do not use this to identify the device. */
311 char *name;
313 #ifdef MULTI_KBOARD
314 /* The terminal's keyboard object. */
315 struct kboard *kboard;
316 #endif
318 /* Device-type dependent data shared amongst all frames on this terminal. */
319 union display_info
321 struct tty_display_info *tty; /* termchar.h */
322 struct x_display_info *x; /* xterm.h */
323 } display_info;
326 /* Coding-system to be used for encoding terminal output. This
327 structure contains information of a coding-system specified by
328 the function `set-terminal-coding-system'. Also see
329 `safe_terminal_coding' in coding.h. */
330 struct coding_system *terminal_coding;
332 /* Coding-system of what is sent from terminal keyboard. This
333 structure contains information of a coding-system specified by
334 the function `set-keyboard-coding-system'. */
335 struct coding_system *keyboard_coding;
337 /* Parameter alist of this terminal. */
338 Lisp_Object param_alist;
340 /* Terminal characteristics. */
341 /* XXX Are these really used on non-termcap displays? */
343 int must_write_spaces; /* Nonzero means spaces in the text must
344 actually be output; can't just skip over
345 some columns to leave them blank. */
346 int fast_clear_end_of_line; /* Nonzero means terminal has a `ce' string */
348 int line_ins_del_ok; /* Terminal can insert and delete lines */
349 int char_ins_del_ok; /* Terminal can insert and delete chars */
350 int scroll_region_ok; /* Terminal supports setting the scroll
351 window */
352 int scroll_region_cost; /* Cost of setting the scroll window,
353 measured in characters. */
354 int memory_below_frame; /* Terminal remembers lines scrolled
355 off bottom */
357 #if 0 /* These are not used anywhere. */
358 /* EMACS_INT baud_rate; */ /* Output speed in baud */
359 int min_padding_speed; /* Speed below which no padding necessary. */
360 int dont_calculate_costs; /* Nonzero means don't bother computing
361 various cost tables; we won't use them. */
362 #endif
365 /* Window-based redisplay interface for this device (0 for tty
366 devices). */
367 struct redisplay_interface *rif;
369 /* Frame-based redisplay interface. */
371 /* Text display hooks. */
373 void (*cursor_to_hook) P_ ((struct frame *f, int vpos, int hpos));
374 void (*raw_cursor_to_hook) P_ ((struct frame *, int, int));
376 void (*clear_to_end_hook) P_ ((struct frame *));
377 void (*clear_frame_hook) P_ ((struct frame *));
378 void (*clear_end_of_line_hook) P_ ((struct frame *, int));
380 void (*ins_del_lines_hook) P_ ((struct frame *f, int, int));
382 void (*insert_glyphs_hook) P_ ((struct frame *f, struct glyph *s, int n));
383 void (*write_glyphs_hook) P_ ((struct frame *f, struct glyph *s, int n));
384 void (*delete_glyphs_hook) P_ ((struct frame *, int));
386 void (*ring_bell_hook) P_ ((struct frame *f));
388 void (*reset_terminal_modes_hook) P_ ((struct terminal *));
389 void (*set_terminal_modes_hook) P_ ((struct terminal *));
391 void (*update_begin_hook) P_ ((struct frame *));
392 void (*update_end_hook) P_ ((struct frame *));
393 void (*set_terminal_window_hook) P_ ((struct frame *, int));
395 /* Multi-frame and mouse support hooks. */
397 /* Return the current position of the mouse.
399 Set *f to the frame the mouse is in, or zero if the mouse is in no
400 Emacs frame. If it is set to zero, all the other arguments are
401 garbage.
403 If the motion started in a scroll bar, set *bar_window to the
404 scroll bar's window, *part to the part the mouse is currently over,
405 *x to the position of the mouse along the scroll bar, and *y to the
406 overall length of the scroll bar.
408 Otherwise, set *bar_window to Qnil, and *x and *y to the column and
409 row of the character cell the mouse is over.
411 Set *time to the time the mouse was at the returned position.
413 This should clear mouse_moved until the next motion
414 event arrives. */
415 void (*mouse_position_hook) P_ ((struct frame **f, int,
416 Lisp_Object *bar_window,
417 enum scroll_bar_part *part,
418 Lisp_Object *x,
419 Lisp_Object *y,
420 unsigned long *time));
422 /* The window system handling code should set this if the mouse has
423 moved since the last call to the mouse_position_hook. Calling that
424 hook should clear this. */
425 int mouse_moved;
427 /* When a frame's focus redirection is changed, this hook tells the
428 window system code to re-decide where to put the highlight. Under
429 X, this means that Emacs lies about where the focus is. */
430 void (*frame_rehighlight_hook) P_ ((struct frame *));
432 /* If we're displaying frames using a window system that can stack
433 frames on top of each other, this hook allows you to bring a frame
434 to the front, or bury it behind all the other windows. If this
435 hook is zero, that means the terminal we're displaying on doesn't
436 support overlapping frames, so there's no need to raise or lower
437 anything.
439 If RAISE is non-zero, F is brought to the front, before all other
440 windows. If RAISE is zero, F is sent to the back, behind all other
441 windows. */
442 void (*frame_raise_lower_hook) P_ ((struct frame *f, int raise));
445 /* Scroll bar hooks. */
447 /* The representation of scroll bars is determined by the code which
448 implements them, except for one thing: they must be represented by
449 lisp objects. This allows us to place references to them in
450 Lisp_Windows without worrying about those references becoming
451 dangling references when the scroll bar is destroyed.
453 The window-system-independent portion of Emacs just refers to
454 scroll bars via their windows, and never looks inside the scroll bar
455 representation; it always uses hook functions to do all the
456 scroll bar manipulation it needs.
458 The `vertical_scroll_bar' field of a Lisp_Window refers to that
459 window's scroll bar, or is nil if the window doesn't have a
460 scroll bar.
462 The `scroll_bars' and `condemned_scroll_bars' fields of a Lisp_Frame
463 are free for use by the scroll bar implementation in any way it sees
464 fit. They are marked by the garbage collector. */
467 /* Set the vertical scroll bar for WINDOW to have its upper left corner
468 at (TOP, LEFT), and be LENGTH rows high. Set its handle to
469 indicate that we are displaying PORTION characters out of a total
470 of WHOLE characters, starting at POSITION. If WINDOW doesn't yet
471 have a scroll bar, create one for it. */
472 void (*set_vertical_scroll_bar_hook) P_ ((struct window *window,
473 int portion, int whole,
474 int position));
477 /* The following three hooks are used when we're doing a thorough
478 redisplay of the frame. We don't explicitly know which scroll bars
479 are going to be deleted, because keeping track of when windows go
480 away is a real pain - can you say set-window-configuration?
481 Instead, we just assert at the beginning of redisplay that *all*
482 scroll bars are to be removed, and then save scroll bars from the
483 fiery pit when we actually redisplay their window. */
485 /* Arrange for all scroll bars on FRAME to be removed at the next call
486 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
487 `*redeem_scroll_bar_hook' is applied to its window before the judgement.
489 This should be applied to each frame each time its window tree is
490 redisplayed, even if it is not displaying scroll bars at the moment;
491 if the HAS_SCROLL_BARS flag has just been turned off, only calling
492 this and the judge_scroll_bars_hook will get rid of them.
494 If non-zero, this hook should be safe to apply to any frame,
495 whether or not it can support scroll bars, and whether or not it is
496 currently displaying them. */
497 void (*condemn_scroll_bars_hook) P_ ((struct frame *frame));
499 /* Unmark WINDOW's scroll bar for deletion in this judgement cycle.
500 Note that it's okay to redeem a scroll bar that is not condemned. */
501 void (*redeem_scroll_bar_hook) P_ ((struct window *window));
503 /* Remove all scroll bars on FRAME that haven't been saved since the
504 last call to `*condemn_scroll_bars_hook'.
506 This should be applied to each frame after each time its window
507 tree is redisplayed, even if it is not displaying scroll bars at the
508 moment; if the HAS_SCROLL_BARS flag has just been turned off, only
509 calling this and condemn_scroll_bars_hook will get rid of them.
511 If non-zero, this hook should be safe to apply to any frame,
512 whether or not it can support scroll bars, and whether or not it is
513 currently displaying them. */
514 void (*judge_scroll_bars_hook) P_ ((struct frame *FRAME));
517 /* Called to read input events.
519 TERMINAL indicates which terminal device to read from. Input
520 events should be read into BUF, the size of which is given in
521 SIZE. EXPECTED is non-zero if the caller suspects that new input
522 is available.
524 A positive return value indicates that that many input events
525 where read into BUF.
526 Zero means no events were immediately available.
527 A value of -1 means a transient read error, while -2 indicates
528 that the device was closed (hangup), and it should be deleted.
530 XXX Please note that a non-zero value of EXPECTED only means that
531 there is available input on at least one of the currently opened
532 terminal devices -- but not necessarily on this device.
533 Therefore, in most cases EXPECTED should be simply ignored.
535 XXX This documentation needs to be updated. */
536 int (*read_socket_hook) P_ ((struct terminal *terminal,
537 int expected,
538 struct input_event *hold_quit));
540 /* Called when a frame's display becomes entirely up to date. */
541 void (*frame_up_to_date_hook) P_ ((struct frame *));
544 /* Called to delete the device-specific portions of a frame that is
545 on this terminal device. */
546 void (*delete_frame_hook) P_ ((struct frame *));
548 /* Called after the last frame on this terminal is deleted, or when
549 the display device was closed (hangup).
551 If this is NULL, then the generic delete_terminal is called
552 instead. Otherwise the hook must call delete_terminal itself.
554 The hook must check for and close any live frames that are still
555 on the terminal. Fdelete_frame ensures that there are no live
556 frames on the terminal when it calls this hook, so infinite
557 recursion is prevented. */
558 void (*delete_terminal_hook) P_ ((struct terminal *));
562 /* Chain of all terminal devices currently in use. */
563 extern struct terminal *terminal_list;
565 #define FRAME_MUST_WRITE_SPACES(f) ((f)->terminal->must_write_spaces)
566 #define FRAME_FAST_CLEAR_END_OF_LINE(f) ((f)->terminal->fast_clear_end_of_line)
567 #define FRAME_LINE_INS_DEL_OK(f) ((f)->terminal->line_ins_del_ok)
568 #define FRAME_CHAR_INS_DEL_OK(f) ((f)->terminal->char_ins_del_ok)
569 #define FRAME_SCROLL_REGION_OK(f) ((f)->terminal->scroll_region_ok)
570 #define FRAME_SCROLL_REGION_COST(f) ((f)->terminal->scroll_region_cost)
571 #define FRAME_MEMORY_BELOW_FRAME(f) ((f)->terminal->memory_below_frame)
573 #define FRAME_TERMINAL_CODING(f) ((f)->terminal->terminal_coding)
574 #define FRAME_KEYBOARD_CODING(f) ((f)->terminal->keyboard_coding)
576 #define TERMINAL_TERMINAL_CODING(d) ((d)->terminal_coding)
577 #define TERMINAL_KEYBOARD_CODING(d) ((d)->keyboard_coding)
579 #define FRAME_RIF(f) ((f)->terminal->rif)
581 #define FRAME_TERMINAL(f) ((f)->terminal)
583 /* FRAME_WINDOW_P tests whether the frame is a window, and is
584 defined to be the predicate for the window system being used. */
586 #ifdef HAVE_X_WINDOWS
587 #define FRAME_WINDOW_P(f) FRAME_X_P (f)
588 #endif
589 #ifdef HAVE_NTGUI
590 #define FRAME_WINDOW_P(f) FRAME_W32_P (f)
591 #endif
592 #ifdef MAC_OS
593 #define FRAME_WINDOW_P(f) FRAME_MAC_P (f)
594 #endif
595 #ifndef FRAME_WINDOW_P
596 #define FRAME_WINDOW_P(f) (0)
597 #endif
599 /* Return true if the terminal device is not suspended. */
600 #define TERMINAL_ACTIVE_P(d) ((d)->type != output_termcap || (d)->display_info.tty->input)
602 extern Lisp_Object get_terminal_param P_ ((struct terminal *, Lisp_Object));
603 extern struct terminal *get_terminal P_ ((Lisp_Object terminal, int));
604 extern struct terminal *create_terminal P_ ((void));
605 extern void delete_terminal P_ ((struct terminal *));
607 /* The initial terminal device, created by initial_term_init. */
608 extern struct terminal *initial_terminal;
610 /* arch-tag: 33a00ecc-52b5-4186-a410-8801ac9f087d
611 (do not change this comment) */