termhooks.h 10.9 KB
Newer Older
Jim Blandy's avatar
Jim Blandy committed
1 2
/* Hooks by which low level terminal operations
   can be made to call other routines.
3
   Copyright (C) 1985, 1986, 1992, 1993 Free Software Foundation, Inc.
Jim Blandy's avatar
Jim Blandy committed
4 5 6 7 8

This file is part of GNU Emacs.

GNU Emacs is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Jim Blandy's avatar
Jim Blandy committed
9
the Free Software Foundation; either version 2, or (at your option)
Jim Blandy's avatar
Jim Blandy committed
10 11 12 13 14 15 16 17 18 19 20
any later version.

GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Emacs; see the file COPYING.  If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */

21 22 23 24 25 26 27 28

/* Miscellanea.   */

/* If nonzero, send all terminal output characters to this stream also.  */
extern FILE *termscript;


/* Text display hooks.  */
Jim Blandy's avatar
Jim Blandy committed
29 30 31 32 33

extern int (*cursor_to_hook) ();
extern int (*raw_cursor_to_hook) ();

extern int (*clear_to_end_hook) ();
Jim Blandy's avatar
Jim Blandy committed
34
extern int (*clear_frame_hook) ();
Jim Blandy's avatar
Jim Blandy committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
extern int (*clear_end_of_line_hook) ();

extern int (*ins_del_lines_hook) ();

extern int (*change_line_highlight_hook) ();
extern int (*reassert_line_highlight_hook) ();

extern int (*insert_glyphs_hook) ();
extern int (*write_glyphs_hook) ();
extern int (*delete_glyphs_hook) ();

extern int (*ring_bell_hook) ();

extern int (*reset_terminal_modes_hook) ();
extern int (*set_terminal_modes_hook) ();
extern int (*update_begin_hook) ();
extern int (*update_end_hook) ();
extern int (*set_terminal_window_hook) ();

54 55 56


/* Multi-frame and mouse support hooks.  */
Jim Blandy's avatar
Jim Blandy committed
57

58 59 60 61 62 63 64
enum scrollbar_part {
  scrollbar_above_handle,
  scrollbar_handle,
  scrollbar_below_handle
};

/* Return the current position of the mouse.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81

   Set *f to the frame the mouse is in, or zero if the mouse is in no
   Emacs frame.  If it is set to zero, all the other arguments are
   garbage.

   If the motion started in a scrollbar, set *bar_window to the
   scrollbar's window, *part to the part the mouse is currently over,
   *x to the position of the mouse along the scrollbar, and *y to the
   overall length of the scrollbar.

   Otherwise, set *bar_window to Qnil, and *x and *y to the column and
   row of the character cell the mouse is over.

   Set *time to the time the mouse was at the returned position.

   This should clear mouse_moved until the next motion
   event arrives.  */
Jim Blandy's avatar
Jim Blandy committed
82
extern void (*mouse_position_hook) ( /* FRAME_PTR *f,
83
					Lisp_Object *bar_window,
84
					enum scrollbar_part *part,
Jim Blandy's avatar
Jim Blandy committed
85 86
					Lisp_Object *x,
					Lisp_Object *y,
Jim Blandy's avatar
Jim Blandy committed
87
					unsigned long *time */ );
Jim Blandy's avatar
Jim Blandy committed
88 89 90 91 92

/* The window system handling code should set this if the mouse has
   moved since the last call to the mouse_position_hook.  Calling that
   hook should clear this.  */
extern int mouse_moved;
Jim Blandy's avatar
Jim Blandy committed
93

Jim Blandy's avatar
Jim Blandy committed
94
/* When a frame's focus redirection is changed, this hook tells the
Jim Blandy's avatar
Jim Blandy committed
95
   window system code to re-decide where to put the highlight.  Under
Jim Blandy's avatar
Jim Blandy committed
96
   X, this means that Emacs lies about where the focus is.  */
Jim Blandy's avatar
Jim Blandy committed
97
extern void (*frame_rehighlight_hook) ( /* void */ );
Jim Blandy's avatar
Jim Blandy committed
98

99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130


/* Scrollbar hooks.  */

/* The representation of scrollbars is determined by the code which
   implements them, except for one thing: they must be represented by
   lisp objects.  This allows us to place references to them in
   Lisp_Windows without worrying about those references becoming
   dangling references when the scrollbar is destroyed.

   The window-system-independent portion of Emacs just refers to
   scrollbars via their windows, and never looks inside the scrollbar
   representation; it always uses hook functions to do all the
   scrollbar manipulation it needs.

   The `vertical_scrollbar' field of a Lisp_Window refers to that
   window's scrollbar, or is nil if the window doesn't have a
   scrollbar.

   The `scrollbars' and `condemned_scrollbars' fields of a Lisp_Frame
   are free for use by the scrollbar implementation in any way it sees
   fit.  They are marked by the garbage collector.  */


/* Set the vertical scrollbar for WINDOW to have its upper left corner
   at (TOP, LEFT), and be LENGTH rows high.  Set its handle to
   indicate that we are displaying PORTION characters out of a total
   of WHOLE characters, starting at POSITION.  If WINDOW doesn't yet
   have a scrollbar, create one for it.  */
extern void (*set_vertical_scrollbar_hook)
            ( /* struct window *window,
	         int portion, int whole, int position */ );
131 132 133 134 135 136 137 138 139 140 141 142


/* The following three hooks are used when we're doing a thorough
   redisplay of the frame.  We don't explicitly know which scrollbars
   are going to be deleted, because keeping track of when windows go
   away is a real pain - can you say set-window-configuration?
   Instead, we just assert at the beginning of redisplay that *all*
   scrollbars are to be removed, and then save scrollbars from the
   firey pit when we actually redisplay their window.  */

/* Arrange for all scrollbars on FRAME to be removed at the next call
   to `*judge_scrollbars_hook'.  A scrollbar may be spared if
143 144 145 146 147 148
   `*redeem_scrollbar_hook' is applied to its window before the judgement. 

   This should be applied to each frame each time its window tree is
   redisplayed, even if it is not displaying scrollbars at the moment;
   if the HAS_SCROLLBARS flag has just been turned off, only calling
   this and the judge_scrollbars_hook will get rid of them.
149

150 151 152 153 154 155 156 157
   If non-zero, this hook should be safe to apply to any frame,
   whether or not it can support scrollbars, and whether or not it is
   currently displaying them.  */
extern void (*condemn_scrollbars_hook)( /* FRAME_PTR *frame */ );

/* Unmark WINDOW's scrollbar for deletion in this judgement cycle.
   Note that it's okay to redeem a scrollbar that is not condemned.  */
extern void (*redeem_scrollbar_hook)( /* struct window *window */ );
158 159

/* Remove all scrollbars on FRAME that haven't been saved since the
160 161 162 163 164 165
   last call to `*condemn_scrollbars_hook'.  

   This should be applied to each frame after each time its window
   tree is redisplayed, even if it is not displaying scrollbars at the
   moment; if the HAS_SCROLLBARS flag has just been turned off, only
   calling this and condemn_scrollbars_hook will get rid of them.
166

167 168 169 170
   If non-zero, this hook should be safe to apply to any frame,
   whether or not it can support scrollbars, and whether or not it is
   currently displaying them.  */
extern void (*judge_scrollbars_hook)( /* FRAME_PTR *FRAME */ );
171

172 173

/* Input queue declarations and hooks.  */
174

175
extern int (*read_socket_hook) ();
Jim Blandy's avatar
Jim Blandy committed
176 177 178

/* Expedient hack: only provide the below definitions to files that
   are prepared to handle lispy things.  XINT is defined iff lisp.h
Jim Blandy's avatar
Jim Blandy committed
179 180
   has been included before this file.  */
#ifdef XINT
Jim Blandy's avatar
Jim Blandy committed
181 182 183 184 185 186 187 188 189 190 191 192

/* The keyboard input buffer is an array of these structures.  Each one
   represents some sort of input event - a keystroke, a mouse click, or
   a window system event.  These get turned into their lispy forms when
   they are removed from the event queue.  */

struct input_event {

  /* What kind of event was this?  */
  enum {
    no_event,			/* nothing happened.  This should never
				   actually appear in the event queue.  */
Jim Blandy's avatar
Jim Blandy committed
193
    ascii_keystroke,		/* The ASCII code is in .code.
194 195
				   .frame_or_window is the frame in
				   which the key was typed.
Jim Blandy's avatar
Jim Blandy committed
196 197
				   Note that this includes meta-keys, and
				   the modifiers field of the event
Jim Blandy's avatar
Jim Blandy committed
198 199 200
				   is unused.
				   .timestamp gives a timestamp (in
				   milliseconds) for the keystroke.  */
Jim Blandy's avatar
Jim Blandy committed
201 202 203 204 205 206 207
    non_ascii_keystroke,	/* .code is a number identifying the
				   function key.  A code N represents
				   a key whose name is
				   function_key_names[N]; function_key_names
				   is a table in keyboard.c to which you
				   should feel free to add missing keys.
				   .modifiers holds the state of the
Jim Blandy's avatar
Jim Blandy committed
208
				   modifier keys.
209 210
				   .frame_or_window is the frame in
				   which the key was typed.
Jim Blandy's avatar
Jim Blandy committed
211 212
				   .timestamp gives a timestamp (in
				   milliseconds) for the keystroke.  */
213 214 215
    mouse_click,		/* The button number is in .code; it must
				   be >= 0 and < NUM_MOUSE_BUTTONS, defined
				   below.
Jim Blandy's avatar
Jim Blandy committed
216 217 218
				   .modifiers holds the state of the
				   modifier keys.
				   .x and .y give the mouse position,
Jim Blandy's avatar
Jim Blandy committed
219
				   in characters, within the window.
220 221
				   .frame_or_window gives the frame
				   the mouse click occurred in.
Jim Blandy's avatar
Jim Blandy committed
222 223
				   .timestamp gives a timestamp (in
				   milliseconds) for the click.  */
224 225 226 227
    scrollbar_click,		/* .code gives the number of the mouse button
				   that was clicked.
				   .modifiers holds the state of the modifier
				   keys.
Jim Blandy's avatar
Jim Blandy committed
228
				   .part is a lisp symbol indicating which
229 230 231 232
				   part of the scrollbar got clicked.
				   .x gives the distance from the start of the
				   scroll bar of the click; .y gives the total
				   length of the scroll bar.
233 234
				   .frame_or_window gives the window
				   whose scrollbar was clicked in.
Jim Blandy's avatar
Jim Blandy committed
235 236 237 238 239
				   .timestamp gives a timestamp (in
				   milliseconds) for the click.  */
  } kind;
  
  Lisp_Object code;
240
  enum scrollbar_part part;
241 242 243 244 245

  /* This field is copied into a vector while the event is in the queue,
     so that garbage collections won't kill it.  */
  Lisp_Object frame_or_window;

Jim Blandy's avatar
Jim Blandy committed
246
  int modifiers;		/* See enum below for interpretation.  */
Jim Blandy's avatar
Jim Blandy committed
247

Jim Blandy's avatar
Jim Blandy committed
248
  Lisp_Object x, y;
Jim Blandy's avatar
Jim Blandy committed
249
  unsigned long timestamp;
Jim Blandy's avatar
Jim Blandy committed
250 251
};

252 253 254 255
/* This is used in keyboard.c, to tell how many buttons we will need
   to track the positions of.  */
#define NUM_MOUSE_BUTTONS (5)

256 257
/* Bits in the modifiers member of the input_event structure.
   Note that reorder_modifiers assumes that the bits are in canonical
258 259 260 261
   order.  

   The modifiers applied to mouse clicks are rather ornate.  The
   window-system-specific code should store mouse clicks with
Jim Blandy's avatar
Jim Blandy committed
262 263 264 265 266 267 268 269 270 271
   up_modifier or down_modifier set.  Having an explicit down modifier
   simplifies some of window-system-independent code; without it, the
   code would have to recognize down events by checking if the event
   is a mouse click lacking the click and drag modifiers.

   The window-system independent code turns all up_modifier events
   bits into either drag_modifier or click_modifier events.  The
   click_modifier has no written representation in the names of the
   symbols used as event heads, but it does appear in the
   Qevent_symbol_components property of the event heads.  */
Jim Blandy's avatar
Jim Blandy committed
272
enum {
273 274 275
  up_modifier	=   1,		/* Only used on mouse buttons - always
				   turned into a click or a drag modifier
				   before lisp code sees the event.  */
276 277 278 279 280 281
  alt_modifier	=   2,		/* Under X, the XK_Alt_[LR] keysyms.  */
  ctrl_modifier	=   4,
  hyper_modifier=   8,		/* Under X, the XK_Hyper_[LR] keysyms.  */
  meta_modifier	=  16,		/* Under X, the XK_Meta_[LR] keysyms.  */
  shift_modifier=  32,
  super_modifier=  64,		/* Under X, the XK_Super_[LR] keysyms.  */
282 283 284 285 286
  down_modifier = 128,		/* Only used on mouse buttons.  */
  drag_modifier = 256,		/* This is never used in the event
				   queue; it's only used internally by
				   the window-system-independent code.  */
  click_modifier= 512,		/* See drag_modifier.  */
Jim Blandy's avatar
Jim Blandy committed
287 288 289 290 291
  last_modifier			/* This should always be one more than the
				   highest modifier bit defined.  */
};

#endif