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