1 /* Parameters and display hooks for terminal devices.
2
3 Copyright (C) 1985-1986, 1993-1994, 2001-2021 Free Software Foundation,
4 Inc.
5
6 This file is part of GNU Emacs.
7
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or (at
11 your option) any later version.
12
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
20
21 #ifndef EMACS_TERMHOOKS_H
22 #define EMACS_TERMHOOKS_H
23
24 /* Miscellanea. */
25
26 #include "lisp.h"
27 #include "dispextern.h"
28 #include "systime.h" /* for Time */
29
30 struct glyph;
31
32 INLINE_HEADER_BEGIN
33
34 enum scroll_bar_part {
35 scroll_bar_nowhere,
36 scroll_bar_above_handle,
37 scroll_bar_handle,
38 scroll_bar_below_handle,
39 scroll_bar_up_arrow,
40 scroll_bar_down_arrow,
41 scroll_bar_to_top,
42 scroll_bar_to_bottom,
43 scroll_bar_end_scroll,
44 scroll_bar_move_ratio,
45 scroll_bar_before_handle,
46 scroll_bar_horizontal_handle,
47 scroll_bar_after_handle,
48 scroll_bar_left_arrow,
49 scroll_bar_right_arrow,
50 scroll_bar_to_leftmost,
51 scroll_bar_to_rightmost
52 };
53
54 /* Output method of a terminal (and frames on this terminal, respectively). */
55
56 enum output_method
57 {
58 output_initial,
59 output_termcap,
60 output_x_window,
61 output_msdos_raw,
62 output_w32,
63 output_ns
64 };
65
66 /* Input queue declarations and hooks. */
67
68 enum event_kind
69 {
70 NO_EVENT, /* nothing happened. This should never
71 actually appear in the event queue. */
72
73 ASCII_KEYSTROKE_EVENT, /* The ASCII code is in .code, perhaps
74 with modifiers applied.
75 .modifiers holds the state of the
76 modifier keys.
77 .frame_or_window is the frame in
78 which the key was typed.
79 .timestamp gives a timestamp (in
80 milliseconds) for the keystroke. */
81 MULTIBYTE_CHAR_KEYSTROKE_EVENT, /* The multibyte char code is in .code,
82 perhaps with modifiers applied.
83 The others are the same as
84 ASCII_KEYSTROKE_EVENT. */
85 NON_ASCII_KEYSTROKE_EVENT, /* .code is a number identifying the
86 function key. A code N represents
87 a key whose name is
88 function_key_names[N]; function_key_names
89 is a table in keyboard.c to which you
90 should feel free to add missing keys.
91 .modifiers holds the state of the
92 modifier keys.
93 .frame_or_window is the frame in
94 which the key was typed.
95 .timestamp gives a timestamp (in
96 milliseconds) for the keystroke. */
97 TIMER_EVENT, /* A timer fired. */
98 MOUSE_CLICK_EVENT, /* The button number is in .code; it must
99 be >= 0 and < NUM_MOUSE_BUTTONS, defined
100 below.
101 .modifiers holds the state of the
102 modifier keys.
103 .x and .y give the mouse position,
104 in characters, within the window.
105 .frame_or_window gives the frame
106 the mouse click occurred in.
107 .timestamp gives a timestamp (in
108 milliseconds) for the click. */
109 WHEEL_EVENT, /* A wheel event is generated by a
110 wheel on a mouse (e.g., MS
111 Intellimouse).
112 .modifiers holds the rotate
113 direction (up or down), and the
114 state of the modifier keys.
115 .x and .y give the mouse position,
116 in characters, within the window.
117 .frame_or_window gives the frame
118 the wheel event occurred in.
119 .timestamp gives a timestamp (in
120 milliseconds) for the event.
121 .arg may contain the number of
122 lines to scroll. */
123 HORIZ_WHEEL_EVENT, /* A wheel event generated by a second
124 horizontal wheel that is present on some
125 mice. See WHEEL_EVENT. */
126 #ifdef HAVE_NTGUI
127 LANGUAGE_CHANGE_EVENT, /* A LANGUAGE_CHANGE_EVENT is
128 generated when HAVE_NTGUI or on Mac OS
129 when the keyboard layout or input
130 language is changed by the
131 user. */
132 #endif
133 SCROLL_BAR_CLICK_EVENT, /* .code gives the number of the mouse button
134 that was clicked.
135 .modifiers holds the state of the modifier
136 keys.
137 .part is a lisp symbol indicating which
138 part of the scroll bar got clicked.
139 .x gives the distance from the start of the
140 scroll bar of the click; .y gives the total
141 length of the scroll bar.
142 .frame_or_window gives the window
143 whose scroll bar was clicked in.
144 .timestamp gives a timestamp (in
145 milliseconds) for the click. */
146 HORIZONTAL_SCROLL_BAR_CLICK_EVENT, /* .code gives the number of the mouse button
147 that was clicked.
148 .modifiers holds the state of the modifier
149 keys.
150 .part is a lisp symbol indicating which
151 part of the scroll bar got clicked.
152 .x gives the distance from the start of the
153 scroll bar of the click; .y gives the total
154 length of the scroll bar.
155 .frame_or_window gives the window
156 whose scroll bar was clicked in.
157 .timestamp gives a timestamp (in
158 milliseconds) for the click. */
159 SELECTION_REQUEST_EVENT, /* Another X client wants a selection from us.
160 See `struct selection_input_event'. */
161 SELECTION_CLEAR_EVENT, /* Another X client cleared our selection. */
162 BUFFER_SWITCH_EVENT, /* A process filter has switched buffers. */
163 DELETE_WINDOW_EVENT, /* An X client said "delete this window". */
164 #ifdef HAVE_NTGUI
165 END_SESSION_EVENT, /* The user is logging out or shutting down. */
166 #endif
167 MENU_BAR_EVENT, /* An event generated by the menu bar.
168 The frame_or_window field's cdr holds the
169 Lisp-level event value.
170 (Only the toolkit version uses these.) */
171 ICONIFY_EVENT, /* An X client iconified this window. */
172 DEICONIFY_EVENT, /* An X client deiconified this window. */
173 MENU_BAR_ACTIVATE_EVENT, /* A button press in the menu bar
174 (toolkit version only). */
175 DRAG_N_DROP_EVENT, /* A drag-n-drop event is generated when
176 files selected outside of Emacs are dropped
177 onto an Emacs window.
178 .modifiers holds the state of the
179 modifier keys.
180 .x and .y give the mouse position,
181 in characters, within the window.
182 .frame_or_window is the frame in
183 which the drop was made.
184 .arg is a platform-dependent
185 representation of the dropped items.
186 .timestamp gives a timestamp (in
187 milliseconds) for the click. */
188 USER_SIGNAL_EVENT, /* A user signal.
189 code is a number identifying it,
190 index into lispy_user_signals. */
191
192 /* Help events. Member `frame_or_window' of the input_event is the
193 frame on which the event occurred, and member `arg' contains
194 the help to show. */
195 HELP_EVENT,
196
197 /* An event from a tab-bar. Member `arg' of the input event
198 contains the tab-bar item selected. If `frame_or_window'
199 and `arg' are equal, this is a prefix event. */
200 TAB_BAR_EVENT,
201
202 /* An event from a tool-bar. Member `arg' of the input event
203 contains the tool-bar item selected. If `frame_or_window'
204 and `arg' are equal, this is a prefix event. */
205 TOOL_BAR_EVENT,
206
207 /* Queued from XTread_socket on FocusIn events. Translated into
208 `switch-frame' events in kbd_buffer_get_event, if necessary. */
209 FOCUS_IN_EVENT,
210
211 FOCUS_OUT_EVENT,
212
213 /* Generated when a frame is moved. */
214 MOVE_FRAME_EVENT,
215
216 /* Generated when mouse moves over window not currently selected. */
217 SELECT_WINDOW_EVENT,
218
219 /* Queued from XTread_socket when session manager sends
220 save yourself before shutdown. */
221 SAVE_SESSION_EVENT
222
223 #ifdef HAVE_GPM
224 , GPM_CLICK_EVENT
225 #endif
226
227 #ifdef HAVE_DBUS
228 , DBUS_EVENT
229 #endif
230
231 #ifdef THREADS_ENABLED
232 , THREAD_EVENT
233 #endif
234
235 , CONFIG_CHANGED_EVENT
236
237 #ifdef HAVE_NTGUI
238 /* Generated when an APPCOMMAND event is received, in response to
239 Multimedia or Internet buttons on some keyboards.
240 Such keys are available as normal function keys on X through the
241 Xkeyboard extension.
242 On Windows, some of them get mapped to normal function key events,
243 but others need to be handled by APPCOMMAND. Handling them all as
244 APPCOMMAND events means they can be disabled
245 (w32-pass-multimedia-buttons-to-system), important on Windows since
246 the system never sees these keys if Emacs claims to handle them.
247 On X, the window manager seems to grab the keys it wants
248 first, so this is not a problem there. */
249 , MULTIMEDIA_KEY_EVENT
250 #endif
251
252 #ifdef HAVE_NS
253 /* Generated when native multi-keystroke input method is used to modify
254 tentative or indicative text display. */
255 , NS_TEXT_EVENT
256 /* Non-key system events (e.g. application menu events) */
257 , NS_NONKEY_EVENT
258 #endif
259
260 #ifdef HAVE_XWIDGETS
261 /* events generated by xwidgets*/
262 , XWIDGET_EVENT
263 #endif
264
265 #ifdef USE_FILE_NOTIFY
266 /* File or directory was changed. */
267 , FILE_NOTIFY_EVENT
268 #endif
269
270 };
271
272 /* Bit width of an enum event_kind tag at the start of structs and unions. */
273 enum { EVENT_KIND_WIDTH = 16 };
274
275 /* If a struct input_event has a kind which is SELECTION_REQUEST_EVENT
276 or SELECTION_CLEAR_EVENT, then its contents are really described
277 by `struct selection_input_event'; see xterm.h. */
278
279 /* The keyboard input buffer is an array of these structures. Each one
280 represents some sort of input event - a keystroke, a mouse click, or
281 a window system event. These get turned into their lispy forms when
282 they are removed from the event queue. */
283
284 struct input_event
285 {
286 /* What kind of event was this? */
287 ENUM_BF (event_kind) kind : EVENT_KIND_WIDTH;
288
289 /* Used in scroll back click events. */
290 ENUM_BF (scroll_bar_part) part : 16;
291
292 /* For an ASCII_KEYSTROKE_EVENT and MULTIBYTE_CHAR_KEYSTROKE_EVENT,
293 this is the character.
294 For a NON_ASCII_KEYSTROKE_EVENT, this is the keysym code.
295 For a mouse event, this is the button number. */
296 unsigned code;
297
298 /* See enum below for interpretation. */
299 unsigned modifiers;
300
301 /* One would prefer C integers, but HELP_EVENT uses these to
302 record frame or window object and a help form, respectively. */
303 Lisp_Object x, y;
304
305 /* Usually a time as reported by window system-specific event loop.
306 For a HELP_EVENT, this is the position within the object (stored
307 in ARG below) where the help was found. */
308 Time timestamp;
309
310 /* This field is copied into a vector while the event is in
311 the queue, so that garbage collections won't kill it. */
312 Lisp_Object frame_or_window;
313
314 /* This additional argument is used in attempt to avoid extra consing
315 when building events. Unfortunately some events have to pass much
316 more data than it's reasonable to pack directly into this structure. */
317 Lisp_Object arg;
318 };
319
320 #define EVENT_INIT(event) memset (&(event), 0, sizeof (struct input_event))
321
322 /* Bits in the modifiers member of the input_event structure.
323 Note that reorder_modifiers assumes that the bits are in canonical
324 order.
325
326 The modifiers applied to mouse clicks are rather ornate. The
327 window-system-specific code should store mouse clicks with
328 up_modifier or down_modifier set. Having an explicit down modifier
329 simplifies some of window-system-independent code; without it, the
330 code would have to recognize down events by checking if the event
331 is a mouse click lacking the click and drag modifiers.
332
333 The window-system independent code turns all up_modifier events
334 bits into drag_modifier, click_modifier, double_modifier, or
335 triple_modifier events. The click_modifier has no written
336 representation in the names of the symbols used as event heads,
337 but it does appear in the Qevent_symbol_components property of the
338 event heads. */
339 enum {
340 up_modifier = 1, /* Only used on mouse buttons - always
341 turned into a click or a drag modifier
342 before lisp code sees the event. */
343 down_modifier = 2, /* Only used on mouse buttons. */
344 drag_modifier = 4, /* This is never used in the event
345 queue; it's only used internally by
346 the window-system-independent code. */
347 click_modifier= 8, /* See drag_modifier. */
348 double_modifier= 16, /* See drag_modifier. */
349 triple_modifier= 32, /* See drag_modifier. */
350
351 /* The next four modifier bits are used also in keyboard events at
352 the Lisp level.
353
354 It's probably not the greatest idea to use the 2^28 bit for any
355 modifier. It may or may not be the sign bit, depending on
356 FIXNUM_BITS, so using it to represent a modifier key means that
357 characters thus modified have different integer equivalents
358 depending on the architecture they're running on. Oh, and
359 applying XFIXNUM to a character whose 2^28 bit is set might sign-extend
360 it, so you get a bunch of bits in the mask you didn't want.
361
362 The CHAR_ macros are defined in lisp.h. */
363 alt_modifier = CHAR_ALT, /* Under X, the XK_Alt_[LR] keysyms. */
364 super_modifier= CHAR_SUPER, /* Under X, the XK_Super_[LR] keysyms. */
365 hyper_modifier= CHAR_HYPER, /* Under X, the XK_Hyper_[LR] keysyms. */
366 shift_modifier= CHAR_SHIFT,
367 ctrl_modifier = CHAR_CTL,
368 meta_modifier = CHAR_META /* Under X, the XK_Meta_[LR] keysyms. */
369 };
370
371 #ifdef HAVE_GPM
372 #include <gpm.h>
373 extern int handle_one_term_event (struct tty_display_info *, Gpm_Event *, struct input_event *);
374 #ifndef HAVE_WINDOW_SYSTEM
375 extern void term_mouse_moveto (int, int);
376 #endif
377
378 /* The device for which we have enabled gpm support. */
379 extern struct tty_display_info *gpm_tty;
380 #endif
381
382 /* Terminal-local parameters. */
383 struct terminal
384 {
385 /* This is for Lisp; the terminal code does not refer to it. */
386 union vectorlike_header header;
387
388 /* Parameter alist of this terminal. */
389 Lisp_Object param_alist;
390
391 /* List of charsets supported by the terminal. It is set by
392 Fset_terminal_coding_system_internal along with
393 the member terminal_coding. */
394 Lisp_Object charset_list;
395
396 /* This is an association list containing the X selections that
397 Emacs might own on this terminal. Each element has the form
398 (SELECTION-NAME SELECTION-VALUE SELECTION-TIMESTAMP FRAME)
399 SELECTION-NAME is a lisp symbol, whose name is the name of an X Atom.
400 SELECTION-VALUE is the value that emacs owns for that selection.
401 It may be any kind of Lisp object.
402 SELECTION-TIMESTAMP is the time at which emacs began owning this
403 selection, as a cons of two 16-bit numbers (making a 32 bit
404 time.)
405 FRAME is the frame for which we made the selection. If there is
406 an entry in this alist, then it can be assumed that Emacs owns
407 that selection.
408 The only (eq) parts of this list that are visible from Lisp are
409 the selection-values. */
410 Lisp_Object Vselection_alist;
411
412 /* If a char-table, this maps characters to terminal glyph codes.
413 If t, the mapping is not available. If nil, it is not known
414 whether the mapping is available. */
415 Lisp_Object glyph_code_table;
416
417 /* All earlier fields should be Lisp_Objects and are traced
418 by the GC. All fields afterwards are ignored by the GC. */
419
420 /* Chain of all terminal devices. */
421 struct terminal *next_terminal;
422
423 /* Unique id for this terminal device. */
424 int id;
425
426 /* The number of frames that are on this terminal. */
427 int reference_count;
428
429 /* The type of the terminal device. */
430 enum output_method type;
431
432 /* The name of the terminal device. Do not use this to uniquely
433 identify a terminal; the same device may be opened multiple
434 times. */
435 char *name;
436
437 /* The terminal's keyboard object. */
438 struct kboard *kboard;
439
440 #ifdef HAVE_WINDOW_SYSTEM
441 /* Cache of images. */
442 struct image_cache *image_cache;
443 #endif /* HAVE_WINDOW_SYSTEM */
444
445 /* Device-type dependent data shared amongst all frames on this terminal. */
446 union display_info
447 {
448 struct tty_display_info *tty; /* termchar.h */
449 struct x_display_info *x; /* xterm.h */
450 struct w32_display_info *w32; /* w32term.h */
451 struct ns_display_info *ns; /* nsterm.h */
452 } display_info;
453
454
455 /* Coding-system to be used for encoding terminal output. This
456 structure contains information of a coding-system specified by
457 the function `set-terminal-coding-system'. Also see
458 `safe_terminal_coding' in coding.h. */
459 struct coding_system *terminal_coding;
460
461 /* Coding-system of what is sent from terminal keyboard. This
462 structure contains information of a coding-system specified by
463 the function `set-keyboard-coding-system'. */
464 struct coding_system *keyboard_coding;
465
466 /* Window-based redisplay interface for this device (0 for tty
467 devices). */
468 struct redisplay_interface *rif;
469
470 /* Frame-based redisplay interface. */
471
472 /* Text display hooks. */
473
474 void (*cursor_to_hook) (struct frame *f, int vpos, int hpos);
475 void (*raw_cursor_to_hook) (struct frame *, int, int);
476
477 void (*clear_to_end_hook) (struct frame *);
478 void (*clear_frame_hook) (struct frame *);
479 void (*clear_end_of_line_hook) (struct frame *, int);
480
481 void (*ins_del_lines_hook) (struct frame *f, int, int);
482
483 void (*insert_glyphs_hook) (struct frame *f, struct glyph *s, int n);
484 void (*write_glyphs_hook) (struct frame *f, struct glyph *s, int n);
485 void (*delete_glyphs_hook) (struct frame *, int);
486
487 void (*ring_bell_hook) (struct frame *f);
488 void (*toggle_invisible_pointer_hook) (struct frame *f, bool invisible);
489
490 void (*reset_terminal_modes_hook) (struct terminal *);
491 void (*set_terminal_modes_hook) (struct terminal *);
492
493 void (*update_begin_hook) (struct frame *);
494 void (*update_end_hook) (struct frame *);
495 void (*set_terminal_window_hook) (struct frame *, int);
496
497 /* Decide if color named COLOR_NAME is valid for the display
498 associated with the frame F; if so, return the RGB values in
499 COLOR_DEF. If ALLOC (and MAKEINDEX for NS), allocate a new
500 colormap cell.
501
502 If MAKEINDEX (on NS), set COLOR_DEF pixel to ARGB. */
503 bool (*defined_color_hook) (struct frame *f, const char *color_name,
504 Emacs_Color *color_def,
505 bool alloc,
506 bool makeIndex);
507
508 /* Multi-frame and mouse support hooks. */
509
510 /* Graphical window systems are expected to define all of the
511 following hooks with the possible exception of:
512
513 * query_colors
514 * activate_menubar_hook
515 * change_tool_bar_height_hook
516 * set_bitmap_icon_hook
517 * buffer_flipping_unblocked_hook
518
519 */
520
521 /* This hook is called to store the frame's background color into
522 BGCOLOR. */
523 void (*query_frame_background_color) (struct frame *f, Emacs_Color *bgcolor);
524
525 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI)
526 /* On frame F, translate pixel colors to RGB values for the NCOLORS
527 colors in COLORS. Use cached information, if available. */
528
529 void (*query_colors) (struct frame *f, Emacs_Color *colors, int ncolors);
530 #endif
531 /* Return the current position of the mouse.
532
533 Set *f to the frame the mouse is in, or zero if the mouse is in no
534 Emacs frame. If it is set to zero, all the other arguments are
535 garbage.
536
537 If the motion started in a scroll bar, set *bar_window to the
538 scroll bar's window, *part to the part the mouse is currently over,
539 *x to the position of the mouse along the scroll bar, and *y to the
540 overall length of the scroll bar.
541
542 Otherwise, set *bar_window to Qnil, and *x and *y to the column and
543 row of the character cell the mouse is over.
544
545 Set *time to the time the mouse was at the returned position. */
546 void (*mouse_position_hook) (struct frame **f, int,
547 Lisp_Object *bar_window,
548 enum scroll_bar_part *part,
549 Lisp_Object *x,
550 Lisp_Object *y,
551 Time *);
552
553 /* This hook is called to get the focus frame. */
554 Lisp_Object (*get_focus_frame) (struct frame *f);
555
556 /* This hook is called to shift frame focus. */
557 void (*focus_frame_hook) (struct frame *f, bool noactivate);
558
559 /* When a frame's focus redirection is changed, this hook tells the
560 window system code to re-decide where to put the highlight. Under
561 X, this means that Emacs lies about where the focus is. */
562 void (*frame_rehighlight_hook) (struct frame *);
563
564 /* If we're displaying frames using a window system that can stack
565 frames on top of each other, this hook allows you to bring a frame
566 to the front, or bury it behind all the other windows. If this
567 hook is zero, that means the terminal we're displaying on doesn't
568 support overlapping frames, so there's no need to raise or lower
569 anything.
570
571 If RAISE_FLAG, F is brought to the front, before all other
572 windows. If !RAISE_FLAG, F is sent to the back, behind all other
573 windows. */
574 void (*frame_raise_lower_hook) (struct frame *f, bool raise_flag);
575
576 /* This hook is called to make the frame F visible if VISIBLE is
577 true, or invisible otherwise. */
578 void (*frame_visible_invisible_hook) (struct frame *f, bool visible);
579
580 /* If the value of the frame parameter changed, this hook is called.
581 For example, if going from fullscreen to not fullscreen this hook
582 may do something OS dependent, like extended window manager hints on X11. */
583 void (*fullscreen_hook) (struct frame *f);
584
585 /* This hook is called to iconify the frame. */
586 void (*iconify_frame_hook) (struct frame *f);
587
588 /* This hook is called to change the size of frame F's native
589 (underlying) window. If CHANGE_GRAVITY, change to top-left-corner
590 window gravity for this size change and subsequent size changes.
591 Otherwise we leave the window gravity unchanged. */
592 void (*set_window_size_hook) (struct frame *f, bool change_gravity,
593 int width, int height, bool pixelwise);
594
595 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
596 to really change the position, and 0 when calling from
597 *_make_frame_visible (in that case, XOFF and YOFF are the current
598 position values). It is -1 when calling from gui_set_frame_parameters,
599 which means, do adjust for borders but don't change the gravity. */
600
601 void (*set_frame_offset_hook) (struct frame *f, register int xoff,
602 register int yoff, int change_gravity);
603
604 /* This hook is called to set the frame's transparency. */
605 void (*set_frame_alpha_hook) (struct frame *f);
606
607 /* This hook is called to set a new font for the frame. */
608 Lisp_Object (*set_new_font_hook) (struct frame *f, Lisp_Object font_object,
609 int fontset);
610
611 /* This hook is called to set the GUI window icon of F using FILE. */
612 bool (*set_bitmap_icon_hook) (struct frame *f, Lisp_Object file);
613
614 /* This hook is called to set the name of the GUI window of F by
615 redisplay unless another name was explicitly requested. */
616 void (*implicit_set_name_hook) (struct frame *f, Lisp_Object arg,
617 Lisp_Object oldval);
618
619 /* This hook is called to display menus. */
620 Lisp_Object (*menu_show_hook) (struct frame *f, int x, int y, int menuflags,
621 Lisp_Object title, const char **error_name);
622
623 #ifdef HAVE_EXT_MENU_BAR
624 /* This hook is called to activate the menu bar. */
625 void (*activate_menubar_hook) (struct frame *f);
626 #endif
627
628 /* This hook is called to display popup dialog. */
629 Lisp_Object (*popup_dialog_hook) (struct frame *f, Lisp_Object header,
630 Lisp_Object contents);
631
632 /* This hook is called to change the frame's (internal) tab-bar. */
633 void (*change_tab_bar_height_hook) (struct frame *f, int height);
634
635 /* This hook is called to change the frame's (internal) tool-bar. */
636 void (*change_tool_bar_height_hook) (struct frame *f, int height);
637
638 /* Scroll bar hooks. */
639
640 /* The representation of scroll bars is determined by the code which
641 implements them, except for one thing: they must be represented by
642 lisp objects. This allows us to place references to them in
643 Lisp_Windows without worrying about those references becoming
644 dangling references when the scroll bar is destroyed.
645
646 The window-system-independent portion of Emacs just refers to
647 scroll bars via their windows, and never looks inside the scroll bar
648 representation; it always uses hook functions to do all the
649 scroll bar manipulation it needs.
650
651 The `vertical_scroll_bar' field of a Lisp_Window refers to that
652 window's scroll bar, or is nil if the window doesn't have a
653 scroll bar.
654
655 The `scroll_bars' and `condemned_scroll_bars' fields of a Lisp_Frame
656 are free for use by the scroll bar implementation in any way it sees
657 fit. They are marked by the garbage collector. */
658
659
660 /* Set the vertical scroll bar for WINDOW to have its upper left corner
661 at (TOP, LEFT), and be LENGTH rows high. Set its handle to
662 indicate that we are displaying PORTION characters out of a total
663 of WHOLE characters, starting at POSITION. If WINDOW doesn't yet
664 have a scroll bar, create one for it. */
665 void (*set_vertical_scroll_bar_hook) (struct window *window,
666 int portion, int whole,
667 int position);
668
669
670 /* Set the horizontal scroll bar for WINDOW to have its upper left
671 corner at (TOP, LEFT), and be LENGTH rows high. Set its handle to
672 indicate that we are displaying PORTION characters out of a total
673 of WHOLE characters, starting at POSITION. If WINDOW doesn't yet
674 have a scroll bar, create one for it. */
675 void (*set_horizontal_scroll_bar_hook) (struct window *window,
676 int portion, int whole,
677 int position);
678
679 /* Set the default scroll bar width on FRAME. */
680 void (*set_scroll_bar_default_width_hook) (struct frame *frame);
681
682 /* Set the default scroll bar height on FRAME. */
683 void (*set_scroll_bar_default_height_hook) (struct frame *frame);
684
685 /* The following three hooks are used when we're doing a thorough
686 redisplay of the frame. We don't explicitly know which scroll bars
687 are going to be deleted, because keeping track of when windows go
688 away is a real pain - can you say set-window-configuration?
689 Instead, we just assert at the beginning of redisplay that *all*
690 scroll bars are to be removed, and then save scroll bars from the
691 fiery pit when we actually redisplay their window. */
692
693 /* Arrange for all scroll bars on FRAME to be removed at the next call
694 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
695 `*redeem_scroll_bar_hook' is applied to its window before the judgment.
696
697 This should be applied to each frame each time its window tree is
698 redisplayed, even if it is not displaying scroll bars at the moment;
699 if the HAS_SCROLL_BARS flag has just been turned off, only calling
700 this and the judge_scroll_bars_hook will get rid of them.
701
702 If non-zero, this hook should be safe to apply to any frame,
703 whether or not it can support scroll bars, and whether or not it is
704 currently displaying them. */
705 void (*condemn_scroll_bars_hook) (struct frame *frame);
706
707 /* Unmark WINDOW's scroll bar for deletion in this judgment cycle.
708 Note that it's okay to redeem a scroll bar that is not condemned. */
709 void (*redeem_scroll_bar_hook) (struct window *window);
710
711 /* Remove all scroll bars on FRAME that haven't been saved since the
712 last call to `*condemn_scroll_bars_hook'.
713
714 This should be applied to each frame after each time its window
715 tree is redisplayed, even if it is not displaying scroll bars at the
716 moment; if the HAS_SCROLL_BARS flag has just been turned off, only
717 calling this and condemn_scroll_bars_hook will get rid of them.
718
719 If non-zero, this hook should be safe to apply to any frame,
720 whether or not it can support scroll bars, and whether or not it is
721 currently displaying them. */
722 void (*judge_scroll_bars_hook) (struct frame *FRAME);
723
724
725 /* Called to read input events.
726
727 TERMINAL indicates which terminal device to read from. Input
728 events should be read into HOLD_QUIT.
729
730 A positive return value N indicates that N input events
731 were read into BUF.
732 Zero means no events were immediately available.
733 A value of -1 means a transient read error, while -2 indicates
734 that the device was closed (hangup), and it should be deleted. */
735 int (*read_socket_hook) (struct terminal *terminal,
736 struct input_event *hold_quit);
737
738 /* Called when a frame's display becomes entirely up to date. */
739 void (*frame_up_to_date_hook) (struct frame *);
740
741 /* Called when buffer flipping becomes unblocked after having
742 previously been blocked. Redisplay always blocks buffer flips
743 while it runs. */
744 void (*buffer_flipping_unblocked_hook) (struct frame *);
745
746 /* Retrieve the string resource specified by NAME with CLASS from
747 database RDB. */
748 const char * (*get_string_resource_hook) (void *rdb,
749 const char *name,
750 const char *class);
751
752 /* Image hooks */
753 #ifdef HAVE_WINDOW_SYSTEM
754 /* Free the pixmap PIXMAP on F. */
755 void (*free_pixmap) (struct frame *f, Emacs_Pixmap pixmap);
756
757 #endif
758
759 /* Deletion hooks */
760
761 /* Called to delete the device-specific portions of a frame that is
762 on this terminal device. */
763 void (*delete_frame_hook) (struct frame *);
764
765 /* Called after the last frame on this terminal is deleted, or when
766 the display device was closed (hangup).
767
768 If this is NULL, then the generic delete_terminal is called
769 instead. Otherwise the hook must call delete_terminal itself.
770
771 The hook must check for and close any live frames that are still
772 on the terminal. delete_frame ensures that there are no live
773 frames on the terminal when it calls this hook, so infinite
774 recursion is prevented. */
775 void (*delete_terminal_hook) (struct terminal *);
776 } GCALIGNED_STRUCT;
777
778 INLINE bool
TERMINALP(Lisp_Object a)779 TERMINALP (Lisp_Object a)
780 {
781 return PSEUDOVECTORP (a, PVEC_TERMINAL);
782 }
783
784 INLINE struct terminal *
XTERMINAL(Lisp_Object a)785 XTERMINAL (Lisp_Object a)
786 {
787 eassert (TERMINALP (a));
788 return XUNTAG (a, Lisp_Vectorlike, struct terminal);
789 }
790
791 /* Most code should use these functions to set Lisp fields in struct
792 terminal. */
793 INLINE void
tset_charset_list(struct terminal * t,Lisp_Object val)794 tset_charset_list (struct terminal *t, Lisp_Object val)
795 {
796 t->charset_list = val;
797 }
798 INLINE void
tset_selection_alist(struct terminal * t,Lisp_Object val)799 tset_selection_alist (struct terminal *t, Lisp_Object val)
800 {
801 t->Vselection_alist = val;
802 }
803
804 /* Chain of all terminal devices currently in use. */
805 extern struct terminal *terminal_list;
806
807 #define FRAME_MUST_WRITE_SPACES(f) (FRAME_TTY (f)->must_write_spaces)
808 #define FRAME_LINE_INS_DEL_OK(f) (FRAME_TTY (f)->line_ins_del_ok)
809 #define FRAME_CHAR_INS_DEL_OK(f) (FRAME_TTY (f)->char_ins_del_ok)
810 #define FRAME_SCROLL_REGION_OK(f) (FRAME_TTY (f)->scroll_region_ok)
811 #define FRAME_SCROLL_REGION_COST(f) (FRAME_TTY (f)->scroll_region_cost)
812 #define FRAME_MEMORY_BELOW_FRAME(f) (FRAME_TTY (f)->memory_below_frame)
813
814 #define FRAME_TERMINAL_CODING(f) ((f)->terminal->terminal_coding)
815 #define FRAME_KEYBOARD_CODING(f) ((f)->terminal->keyboard_coding)
816
817 #define TERMINAL_TERMINAL_CODING(d) ((d)->terminal_coding)
818 #define TERMINAL_KEYBOARD_CODING(d) ((d)->keyboard_coding)
819
820 #define FRAME_RIF(f) ((f)->terminal->rif)
821
822 #define FRAME_TERMINAL(f) ((f)->terminal)
823
824 /* Return true if the terminal device is not suspended. */
825 #define TERMINAL_ACTIVE_P(d) \
826 (((d)->type != output_termcap && (d)->type != output_msdos_raw) \
827 || (d)->display_info.tty->input)
828
829 /* Return font cache data for the specified terminal. The historical
830 name is grossly misleading, actually it is (NAME . FONT-LIST-CACHE). */
831 #if defined (HAVE_X_WINDOWS)
832 #define TERMINAL_FONT_CACHE(t) \
833 (t->type == output_x_window ? t->display_info.x->name_list_element : Qnil)
834 #elif defined (HAVE_NTGUI)
835 #define TERMINAL_FONT_CACHE(t) \
836 (t->type == output_w32 ? t->display_info.w32->name_list_element : Qnil)
837 #elif defined (HAVE_NS)
838 #define TERMINAL_FONT_CACHE(t) \
839 (t->type == output_ns ? t->display_info.ns->name_list_element : Qnil)
840 #endif
841
842 extern struct terminal *decode_live_terminal (Lisp_Object);
843 extern struct terminal *decode_tty_terminal (Lisp_Object);
844 extern struct terminal *get_named_terminal (const char *);
845 extern struct terminal *create_terminal (enum output_method,
846 struct redisplay_interface *);
847 extern void delete_terminal (struct terminal *);
848 extern void delete_terminal_internal (struct terminal *);
849 extern Lisp_Object terminal_glyph_code (struct terminal *, int);
850
851 /* The initial terminal device, created by initial_term_init. */
852 extern struct terminal *initial_terminal;
853
854 extern unsigned char *encode_terminal_code (struct glyph *, int,
855 struct coding_system *);
856
857 #ifdef HAVE_GPM
858 extern void close_gpm (int gpm_fd);
859 #endif
860
861 #ifdef WINDOWSNT
862 extern int cursorX (struct tty_display_info *);
863 extern int cursorY (struct tty_display_info *);
864 #else
865 #define cursorX(t) curX(t)
866 #define cursorY(t) curY(t)
867 #endif
868
869 INLINE_HEADER_END
870
871 #endif /* EMACS_TERMHOOKS_H */
872