emacstool.c 15.4 KB
Newer Older
Joseph Arceneaux's avatar
Joseph Arceneaux committed
1
/*
2
   Copyright (C) 1986, 1988, 1990, 1991, 2001, 2002, 2003, 2004,
Glenn Morris's avatar
Glenn Morris committed
3
                 2005, 2006, 2007, 2008  Free Software Foundation, Inc.
David J. MacKenzie's avatar
David J. MacKenzie committed
4

5
This file is part of GNU Emacs.
David J. MacKenzie's avatar
David J. MacKenzie committed
6

7 8
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
9
the Free Software Foundation; either version 3, or (at your option)
10
any later version.
David J. MacKenzie's avatar
David J. MacKenzie committed
11

12 13 14 15 16 17 18
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
Lute Kamstra's avatar
Lute Kamstra committed
19 20
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.  */
David J. MacKenzie's avatar
David J. MacKenzie committed
21 22

/*
Jim Blandy's avatar
Jim Blandy committed
23
 * For Emacs in SunView/Sun-Windows: (supported by Sun Unix v3.2 or greater)
Pavel Janík's avatar
Pavel Janík committed
24
 * Insert a notifier filter-function to convert all useful input
Joseph Arceneaux's avatar
Joseph Arceneaux committed
25 26
 * to "key" sequences that emacs can understand.  See: Emacstool(1).
 *
Jim Blandy's avatar
Jim Blandy committed
27
 * Author: Jeff Peck, Sun Microsystems, Inc. <peck@eng.sun.com>
Joseph Arceneaux's avatar
Joseph Arceneaux committed
28 29 30
 *
 * Original Idea: Ian Batten
 * Updated 15-Mar-88, Jeff Peck: set IN_EMACSTOOL, TERM, TERMCAP
Jim Blandy's avatar
Jim Blandy committed
31 32 33 34 35 36 37 38 39 40
 * Updated 10-Sep-88, Jeff Peck: add XVIEW and JLE support
 * Updated  8-Oct-90, Jeff Peck: add Meta-bit for Xview
 * Updated  6-Mar-91, Jeff Peck: Hack to detect -Wt invocation
 *	[note, TTYSW limitation means you must Click-To-Type in Openwin]
 *	[fixed in OW3 or use local/tty.o]
 *	for better results, this should move to using TERMSW.
 * Updated 10-Mar-91, Jeff Peck, et al: support for TERMSW (TTERM)
 *	allows point-to-type even in OW2
 *
 * 	[note: xvetool should be started with the "-nw" flag for emacs!]
Joseph Arceneaux's avatar
Joseph Arceneaux committed
41 42
 */

Jim Blandy's avatar
Jim Blandy committed
43 44 45 46 47 48 49 50 51
#ifdef XVIEW
#include <xview/xview.h>
#include <xview/panel.h>
#include <xview/attr.h>
#include <xview/tty.h>
#include <xview/ttysw.h>		/* private defines */
#include <xview/termsw.h>		/* -DTTERM */
#include <xview/font.h>			/* for testing */
#else
Joseph Arceneaux's avatar
Joseph Arceneaux committed
52 53
#include <suntool/sunview.h>
#include <suntool/tty.h>
Jim Blandy's avatar
Jim Blandy committed
54 55 56 57 58 59 60
#include <suntool/ttysw.h>
#endif XVIEW

#ifdef JLE
# include <locale.h>
#endif JLE

Joseph Arceneaux's avatar
Joseph Arceneaux committed
61 62 63 64 65 66 67 68
#include <stdio.h>
#include <sys/file.h>

#define BUFFER_SIZE 128               /* Size of all the buffers */

/* define WANT_CAPS_LOCK to make f-key T1 (aka F1) behave as CapsLock */
#define WANT_CAPS_LOCK
#ifdef WANT_CAPS_LOCK
69
int caps_lock;		/* toggle indicator for f-key T1 caps lock */
Joseph Arceneaux's avatar
Joseph Arceneaux committed
70 71 72 73 74 75 76 77 78 79
static char *Caps = "[CAPS] ";		/* Caps Lock prefix string */
#define CAPS_LEN 7			/* strlen (Caps) */
#endif

static char *mouse_prefix = "\030\000";	/* C-x C-@ */
static int   m_prefix_length = 2;       /* mouse_prefix length */

static char *key_prefix = "\030*";  	/* C-x *   */
static int   k_prefix_length = 2;       /* key_prefix length */

Jim Blandy's avatar
Jim Blandy committed
80 81 82 83
#ifdef JLE
static char *emacs_name = "nemacs";	/* default run command */
static char *title = "NEmacstool - ";	/* initial title */
#else
Joseph Arceneaux's avatar
Joseph Arceneaux committed
84 85
static char *emacs_name = "emacs";	/* default run command */
static char *title = "Emacstool - ";	/* initial title */
Jim Blandy's avatar
Jim Blandy committed
86 87 88 89
#endif JLE

static char buffer[BUFFER_SIZE];	/* send to ttysw_input */
static char *bold_name = 0;	 	/* for -bold option */
Joseph Arceneaux's avatar
Joseph Arceneaux committed
90 91

Frame frame;                            /* Base frame for system */
Jim Blandy's avatar
Jim Blandy committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106

#ifndef TTERM
#define SWTYPE TTY
Tty tty_win;				/* Where emacs is reading */
#else
#define SWTYPE TERMSW
Termsw tty_win;				/* Termsw does follow-mouse */
#endif TTERM

#ifdef XVIEW
Xv_Window tty_view;			/* Where the events are in Xview*/
#else
Tty tty_view;				/* SunView place filler */
#endif XVIEW

Joseph Arceneaux's avatar
Joseph Arceneaux committed
107
int font_width, font_height;            /* For translating pixels to chars */
Jim Blandy's avatar
Jim Blandy committed
108
int left_margin = 0;		/* default window -- frame offset */
Joseph Arceneaux's avatar
Joseph Arceneaux committed
109 110 111 112 113 114

int console_fd = 0;		/* for debugging: setenv DEBUGEMACSTOOL */
FILE *console;			/* for debugging: setenv DEBUGEMACSTOOL */

Icon frame_icon;
/* make an icon_image for the default frame_icon */
Pavel Janík's avatar
Pavel Janík committed
115
static short default_image[258] =
Joseph Arceneaux's avatar
Joseph Arceneaux committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
{
#include <images/terminal.icon>
};
mpr_static(icon_image, 64, 64, 1, default_image);

/*
 * Assign a value to a set of keys
 */
int
button_value (event)
     Event *event;
{
  int retval = 0;
  /*
   * Code up the current situation:
   *
   * 1 = MS_LEFT;
   * 2 = MS_MIDDLE;
   * 4 = MS_RIGHT;
   * 8 = SHIFT;
   * 16 = CONTROL;
   * 32 = META;
   * 64 = DOUBLE;
   * 128 = UP;
   */

  if (MS_LEFT   == (event_id (event))) retval = 1;
  if (MS_MIDDLE == (event_id (event))) retval = 2;
  if (MS_RIGHT  == (event_id (event))) retval = 4;

  if (event_shift_is_down (event)) retval += 8;
  if (event_ctrl_is_down  (event)) retval += 16;
  if (event_meta_is_down  (event)) retval += 32;
  if (event_is_up         (event)) retval += 128;
  return retval;
}

/*
 *  Variables to store the time of the previous mouse event that was
 *  sent to emacs.
 *
Karl Heuer's avatar
Karl Heuer committed
157
 *  The theory is that to time double clicks while ignoring UP buttons,
Joseph Arceneaux's avatar
Joseph Arceneaux committed
158 159 160
 *  we must keep track of the accumulated time.
 *
 *  If someone writes a SUN-SET-INPUT-MASK for emacstool,
Pavel Janík's avatar
Pavel Janík committed
161
 *  That could be used to selectively disable UP events,
Joseph Arceneaux's avatar
Joseph Arceneaux committed
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
 *  and then this cruft wouldn't be necessary.
 */
static long prev_event_sec = 0;
static long prev_event_usec = 0;

/*
 *  Give the time difference in milliseconds, where one second
 *  is considered infinite.
 */
int
time_delta (now_sec, now_usec, prev_sec, prev_usec)
     long now_sec, now_usec, prev_sec, prev_usec;
{
  long sec_delta = now_sec - prev_sec;
  long usec_delta = now_usec - prev_usec;
Pavel Janík's avatar
Pavel Janík committed
177

Joseph Arceneaux's avatar
Joseph Arceneaux committed
178 179 180 181
  if (usec_delta < 0) {		/* "borrow" a second */
    usec_delta += 1000000;
    --sec_delta;
  }
Pavel Janík's avatar
Pavel Janík committed
182 183

  if (sec_delta >= 10)
Joseph Arceneaux's avatar
Joseph Arceneaux committed
184 185 186 187 188 189 190 191 192
    return (9999);		/* Infinity */
  else
    return ((sec_delta * 1000) + (usec_delta / 1000));
}


/*
 * Filter function to translate selected input events for emacs
 * Mouse button events become ^X^@(button x-col y-line time-delta) .
193
 * Function keys: ESC-*{c}{lrt} l,r,t for Left, Right, Top;
Joseph Arceneaux's avatar
Joseph Arceneaux committed
194 195 196 197
 * {c} encodes the keynumber as a character [a-o]
 */
static Notify_value
input_event_filter_function (window, event, arg, type)
Jim Blandy's avatar
Jim Blandy committed
198 199 200
#ifdef XVIEW
     Xv_Window window;
#else
Joseph Arceneaux's avatar
Joseph Arceneaux committed
201
     Window window;
Jim Blandy's avatar
Jim Blandy committed
202
#endif XVIEW
Joseph Arceneaux's avatar
Joseph Arceneaux committed
203 204 205 206 207 208 209 210 211 212
     Event *event;
     Notify_arg arg;
     Notify_event_type type;
{
  struct timeval time_stamp;

  if (console_fd) fprintf(console, "Event: %d\n", event_id(event));

  /* UP L1 is the STOP key */
  if (event_id(event) == WIN_STOP) {
Jim Blandy's avatar
Jim Blandy committed
213
    ttysw_input(tty_win, "\007\007\007\007\007\007\007", 7);
Joseph Arceneaux's avatar
Joseph Arceneaux committed
214 215 216 217 218
    return NOTIFY_IGNORED;
  }

  /* UP L5 & L7 is Expose & Open, let them pass to sunview */
  if (event_id(event) == KEY_LEFT(5) || event_id(event) == KEY_LEFT(7))
Pavel Janík's avatar
Pavel Janík committed
219
    if(event_is_up (event))
Joseph Arceneaux's avatar
Joseph Arceneaux committed
220 221 222 223 224
      return notify_next_event_func (window, event, arg, type);
    else return NOTIFY_IGNORED;

  if (event_is_button (event)) { 	      /* do Mouse Button events */
/* Commented out so that we send mouse up events too.
Pavel Janík's avatar
Pavel Janík committed
225
   if (event_is_up (event))
Joseph Arceneaux's avatar
Joseph Arceneaux committed
226 227 228
      return notify_next_event_func (window, event, arg, type);
*/
    time_stamp = event_time (event);
Jim Blandy's avatar
Jim Blandy committed
229
    ttysw_input (tty_win, mouse_prefix, m_prefix_length);
Pavel Janík's avatar
Pavel Janík committed
230
    sprintf (buffer, "(%d %d %d %d)\015",
Joseph Arceneaux's avatar
Joseph Arceneaux committed
231
	     button_value (event),
Jim Blandy's avatar
Jim Blandy committed
232
	     (event_x (event) - left_margin) / font_width,
Joseph Arceneaux's avatar
Joseph Arceneaux committed
233 234 235 236
	     event_y (event) / font_height,
	     time_delta (time_stamp.tv_sec, time_stamp.tv_usec,
			 prev_event_sec, prev_event_usec)
	     );
Jim Blandy's avatar
Jim Blandy committed
237
    ttysw_input (tty_win, buffer, strlen(buffer));
Joseph Arceneaux's avatar
Joseph Arceneaux committed
238 239 240 241
    prev_event_sec = time_stamp.tv_sec;
    prev_event_usec = time_stamp.tv_usec;
    return NOTIFY_IGNORED;
  }
Pavel Janík's avatar
Pavel Janík committed
242

Joseph Arceneaux's avatar
Joseph Arceneaux committed
243 244 245 246
  { /* Do the function key events */
    int d;
    char c = (char) 0;
    if ((event_is_key_left  (event)) ?
Pavel Janík's avatar
Pavel Janík committed
247
	((d = event_id(event) - KEY_LEFT(1)   + 'a'), c='l') :
Joseph Arceneaux's avatar
Joseph Arceneaux committed
248
	((event_is_key_right (event)) ?
Pavel Janík's avatar
Pavel Janík committed
249
	 ((d = event_id(event) - KEY_RIGHT(1) + 'a'), c='r') :
Joseph Arceneaux's avatar
Joseph Arceneaux committed
250 251 252 253 254 255 256 257 258 259
	 ((event_is_key_top   (event)) ?
	  ((d = event_id(event) - KEY_TOP(1)  + 'a'), c='t') : 0)))
      {
	if (event_is_up(event)) return NOTIFY_IGNORED;
	if (event_shift_is_down (event)) c = c -  32;
	/* this will give a non-{lrt} for unshifted keys */
	if (event_ctrl_is_down  (event)) c = c -  64;
	if (event_meta_is_down  (event)) c = c + 128;
#ifdef WANT_CAPS_LOCK
/* set a toggle and relabel window so T1 can act like caps-lock */
Pavel Janík's avatar
Pavel Janík committed
260
	if (event_id(event) == KEY_TOP(1))
Joseph Arceneaux's avatar
Joseph Arceneaux committed
261 262
	  {
	    /* make a frame label with and without CAPS */
Pavel Janík's avatar
Pavel Janík committed
263
	    strcpy (buffer, Caps);
Joseph Arceneaux's avatar
Joseph Arceneaux committed
264 265 266
	    title = &buffer[CAPS_LEN];
	    strncpy (title, (char *)window_get (frame, FRAME_LABEL),
		     BUFFER_SIZE - CAPS_LEN);
Pavel Janík's avatar
Pavel Janík committed
267
	    buffer[BUFFER_SIZE] = (char) 0;
Joseph Arceneaux's avatar
Joseph Arceneaux committed
268 269 270 271 272 273 274
	    if (strncmp (title, Caps, CAPS_LEN) == 0)
	      title += CAPS_LEN; 		 /* already Caps */
	    caps_lock =  (caps_lock ? 0 : CAPS_LEN);
	    window_set(frame, FRAME_LABEL, (title -= caps_lock), 0);
	    return NOTIFY_IGNORED;
	  }
#endif
Jim Blandy's avatar
Jim Blandy committed
275
	ttysw_input (tty_win, key_prefix, k_prefix_length);
Joseph Arceneaux's avatar
Joseph Arceneaux committed
276
	sprintf (buffer, "%c%c", d, c);
Jim Blandy's avatar
Jim Blandy committed
277
	ttysw_input(tty_win, buffer, strlen(buffer));
Joseph Arceneaux's avatar
Joseph Arceneaux committed
278 279 280 281

	return NOTIFY_IGNORED;
      }
  }
Pavel Janík's avatar
Pavel Janík committed
282
  if ((event_is_ascii(event) || event_is_meta(event))
Joseph Arceneaux's avatar
Joseph Arceneaux committed
283 284 285 286 287 288 289
      && event_is_up(event)) return NOTIFY_IGNORED;
#ifdef WANT_CAPS_LOCK
/* shift alpha chars to upper case if toggle is set */
  if ((caps_lock) && event_is_ascii(event)
      && (event_id(event) >= 'a') && (event_id(event) <= 'z'))
    event_set_id(event, (event_id(event) - 32));
/* crufty, but it works for now. is there an UPCASE(event)? */
Jim Blandy's avatar
Jim Blandy committed
290 291 292 293 294 295 296
#endif
#ifndef NO_META_BIT
/* under Openwindows/X, the meta bit is not set in the key event,
 * emacs expects this so we add it in here:
 */
  if (event_is_ascii(event) && event_meta_is_down(event))
    event_set_id(event, 128 | event_id(event));
Joseph Arceneaux's avatar
Joseph Arceneaux committed
297 298 299 300 301 302 303 304 305
#endif
  return notify_next_event_func (window, event, arg, type);
}

main (argc, argv)
     int argc;
     char **argv;
{
  int error_code;	/* Error codes */
Pavel Janík's avatar
Pavel Janík committed
306

Jim Blandy's avatar
Jim Blandy committed
307 308 309 310
#ifdef JLE
  setlocale(LC_ALL, "");
#endif JLE

Joseph Arceneaux's avatar
Joseph Arceneaux committed
311 312 313 314 315
  if(getenv("DEBUGEMACSTOOL"))
    console = fdopen (console_fd = open("/dev/console",O_WRONLY), "w");

  putenv("IN_EMACSTOOL=t");	/* notify subprocess that it is in emacstool */

Jim Blandy's avatar
Jim Blandy committed
316
  if (putenv("TERM=sun") != 0)	/* TTY_WIN will be a TERM=sun window */
Joseph Arceneaux's avatar
Joseph Arceneaux committed
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
    {fprintf (stderr, "%s: Could not set TERM=sun, using `%s'\n",
	     argv[0], (char *)getenv("TERM")) ;};
  /*
   * If TERMCAP starts with a slash, it is the pathname of the
   * termcap file, not an entry extracted from it, so KEEP it!
   * Otherwise, it may not relate to the new TERM, so Nuke-It.
   * If there is no TERMCAP environment variable, don't make one.
   */
  {
    char *termcap ;	/* Current TERMCAP value */
    termcap = (char *)getenv("TERMCAP") ;
    if (termcap && (*termcap != '/'))
      {
	if (putenv("TERMCAP=") != 0)
	  {fprintf (stderr, "%s: Could not clear TERMCAP\n", argv[0]) ;} ;
      } ;
  } ;
Pavel Janík's avatar
Pavel Janík committed
334

Joseph Arceneaux's avatar
Joseph Arceneaux committed
335
  /* find command to run as subprocess in window */
Jim Blandy's avatar
Jim Blandy committed
336
  if (!(argv[0] = (char *)getenv("EMACSTOOL")))	/*  Set emacs command name */
Pavel Janík's avatar
Pavel Janík committed
337
      argv[0] = emacs_name;
Jim Blandy's avatar
Jim Blandy committed
338
  /* Emacstool recognizes two special args: -rc <file> and -bold <bold-name> */
Joseph Arceneaux's avatar
Joseph Arceneaux committed
339
  for (argc = 1; argv[argc]; argc++)		/* Use last one on line */
Jim Blandy's avatar
Jim Blandy committed
340 341 342 343 344 345 346 347 348 349
    {
      if(!(strcmp ("-rc", argv[argc])))		/* Override if -rc given */
	{int i = argc;
	 argv[argc--]=0;		/* kill the -rc argument */
	 if (argv[i+1]) {	/* move to argv[0] and squeeze the rest */
	   argv[0]=argv[i+1];
	   for (; argv[i+2]; (argv[i]=argv[i+2],argv[++i]=0));
	 }
       }

Pavel Janík's avatar
Pavel Janík committed
350
      if (!(strcmp ("-bold", argv[argc])))
Jim Blandy's avatar
Jim Blandy committed
351 352 353 354 355 356 357 358
	  {int i = argc;
	   argv[argc--]=0;		/* kill the -bold argument */
	   if (argv[i+1]) {	/* move to bold_name and squeeze the rest */
	       bold_name = argv[i+1];
	       for (; argv[i+2]; (argv[i]=argv[i+2],argv[++i]=0));
	   }
       }
  };
Joseph Arceneaux's avatar
Joseph Arceneaux committed
359 360 361 362 363

  strcpy (buffer, title);
  strncat (buffer, argv[0],		 /* append run command name */
	   (BUFFER_SIZE - (strlen (buffer)) - (strlen (argv[0]))) - 1);

Jim Blandy's avatar
Jim Blandy committed
364 365 366 367 368 369 370 371 372 373 374 375
  error_code = interpose_on_window(argc,argv);
  if (error_code != 0) {		/* Barf */
      fprintf (stderr, "notify_interpose_event_func returns %d.\n", error_code);
      exit (1);
  }

#ifdef XVIEW
  xv_main_loop (frame);                  /* And away we go */
#else
  window_main_loop (frame);
#endif XVIEW
}
Joseph Arceneaux's avatar
Joseph Arceneaux committed
376

Jim Blandy's avatar
Jim Blandy committed
377 378 379 380 381 382
#ifdef XVIEW
int interpose_on_window(argc,argv)
    int argc;
    char **argv;
{
#ifndef TTERM
Karl Heuer's avatar
Karl Heuer committed
383
    int i, font_width_adjust = 1; /* hackery, and heuristics */
Jim Blandy's avatar
Jim Blandy committed
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
    /* if -Wt is not supplied, then font comes out as lucida-14 (width=8)
     * rather than the screen.r.12 (width=7) typically used
     * this hack attempts to workaround it.
     * could use a env var EMACSTOOL_DEFAULT_FONT_WIDTH instead */
    for (i = 1; argv[i]; i++) {
	if (!(strcmp ("-Wt", argv[i])))
	    {font_width_adjust = 0;
	     if (console_fd) fprintf(console, "-Wt = %d\n", font_width_adjust);
	     break;}
    }
#endif TTERM
    /* initialize Xview, and strip window args */
    xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, 0);

    /* do this first, so arglist can override it */
    frame_icon = icon_create (ICON_LABEL, "Emacstool",
			      ICON_IMAGE, &icon_image,
			      0);

    /* Build a frame to run in */
    frame = xv_create ((Xv_Window)NULL, FRAME,
		       FRAME_LABEL, buffer,
		       FRAME_ICON, frame_icon,
		       0);

    /* Create a tty with emacs in it */
    tty_win = xv_create (frame, SWTYPE, WIN_IS_CLIENT_PANE,
Pavel Janík's avatar
Pavel Janík committed
411
			 TTY_QUIT_ON_CHILD_DEATH, TRUE,
Jim Blandy's avatar
Jim Blandy committed
412
			 TTY_BOLDSTYLE, TTYSW_BOLD_INVERT,
Pavel Janík's avatar
Pavel Janík committed
413
			 TTY_ARGV, argv,
Joseph Arceneaux's avatar
Joseph Arceneaux committed
414 415
			 0);

Jim Blandy's avatar
Jim Blandy committed
416 417 418 419
    if (bold_name) {
	(void)xv_set(tty_win, TTY_BOLDSTYLE_NAME, bold_name, 0);
    }

Joseph Arceneaux's avatar
Joseph Arceneaux committed
420
    {
Jim Blandy's avatar
Jim Blandy committed
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
	Xv_font font;		/* declare temp font variable */
	font = (Xv_font)xv_get (tty_win, XV_FONT);
	font_height = (int)xv_get (font, FONT_DEFAULT_CHAR_HEIGHT);
	font_width  = (int)xv_get (font, FONT_DEFAULT_CHAR_WIDTH);
    }
    if (console_fd) fprintf(console, "Width = %d\n", font_width);

#ifndef TTERM
    font_width -= font_width_adjust; /* A guess! font bug in ttysw*/
#else
    /* make the termsw act as a tty */
    xv_set(tty_win, TERMSW_MODE, TTYSW_MODE_TYPE, 0);
    /* termsw has variable offset depending on scrollbar size/location */
    left_margin = (int)xv_get (tty_win, TEXTSW_LEFT_MARGIN);
#endif TTERM

    tty_view = (Xv_Window) xv_get (tty_win, OPENWIN_NTH_VIEW, 0);
    xv_set(tty_view,
Pavel Janík's avatar
Pavel Janík committed
439
	   WIN_CONSUME_EVENTS,
Jim Blandy's avatar
Jim Blandy committed
440 441
	   WIN_MOUSE_BUTTONS, WIN_UP_EVENTS,
	   ACTION_ADJUST, ACTION_MENU,
Pavel Janík's avatar
Pavel Janík committed
442
	   WIN_ASCII_EVENTS,
Jim Blandy's avatar
Jim Blandy committed
443 444 445 446
	   WIN_LEFT_KEYS, WIN_TOP_KEYS, WIN_RIGHT_KEYS,
	   0,
	   0);
    /* Interpose my event function */
Pavel Janík's avatar
Pavel Janík committed
447
    return (int) notify_interpose_event_func
Jim Blandy's avatar
Jim Blandy committed
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
	(tty_view, input_event_filter_function, NOTIFY_SAFE);
}
#else
int interpose_on_window (argc, argv)
 int argc;
 char **argv;
{
    /* do this first, so arglist can override it */
    frame_icon = icon_create (ICON_LABEL, "Emacstool",
			      ICON_IMAGE, &icon_image,
			      0);

    /* Build a frame to run in */
    frame = window_create ((Window)NULL, FRAME,
			   FRAME_LABEL, buffer,
			   FRAME_ICON, frame_icon,
			   FRAME_ARGC_PTR_ARGV, &argc, argv,
			   0);

    /* Create a tty with emacs in it */
Pavel Janík's avatar
Pavel Janík committed
468 469
    tty_win = window_create (frame, TTY,
			     TTY_QUIT_ON_CHILD_DEATH, TRUE,
Jim Blandy's avatar
Jim Blandy committed
470
			     TTY_BOLDSTYLE, TTYSW_BOLD_INVERT,
Pavel Janík's avatar
Pavel Janík committed
471
			     TTY_ARGV, argv,
Jim Blandy's avatar
Jim Blandy committed
472 473 474 475
			     0);

    if (bold_name) {
	(void)window_set(tty_win, TTY_BOLDSTYLE_NAME, bold_name, 0);
Joseph Arceneaux's avatar
Joseph Arceneaux committed
476 477
    }

Jim Blandy's avatar
Jim Blandy committed
478 479 480 481 482 483 484
    /* ttysw uses pf_default, one must set WIN_FONT explicitly */
                       window_set (tty_win, WIN_FONT, pf_default(), 0);
    font_height = (int)window_get (tty_win, WIN_ROW_HEIGHT);
    font_width  = (int)window_get (tty_win, WIN_COLUMN_WIDTH);

    tty_view = tty_win;
    window_set(tty_view,
Pavel Janík's avatar
Pavel Janík committed
485
	       WIN_CONSUME_PICK_EVENTS,
Jim Blandy's avatar
Jim Blandy committed
486 487 488 489
	       WIN_STOP,
	       WIN_MOUSE_BUTTONS, WIN_UP_EVENTS,
	       /* LOC_WINENTER, LOC_WINEXIT, LOC_MOVE, */
	       0,
Pavel Janík's avatar
Pavel Janík committed
490
	       WIN_CONSUME_KBD_EVENTS,
Jim Blandy's avatar
Jim Blandy committed
491
	       WIN_STOP,
Pavel Janík's avatar
Pavel Janík committed
492
	       WIN_ASCII_EVENTS,
Jim Blandy's avatar
Jim Blandy committed
493 494 495 496 497
	       WIN_LEFT_KEYS, WIN_TOP_KEYS, WIN_RIGHT_KEYS,
	       /* WIN_UP_ASCII_EVENTS, */
	       0,
	       0);
    /* Interpose my event function */
Pavel Janík's avatar
Pavel Janík committed
498
    return (int) notify_interpose_event_func
Jim Blandy's avatar
Jim Blandy committed
499
	(tty_view, input_event_filter_function, NOTIFY_SAFE);
Joseph Arceneaux's avatar
Joseph Arceneaux committed
500
}
Jim Blandy's avatar
Jim Blandy committed
501
#endif XVIEW
Miles Bader's avatar
Miles Bader committed
502 503 504

/* arch-tag: 7a2e7105-c059-418a-b3d9-5b5de96abb4e
   (do not change this comment) */