2000-03-08 19:38:31 -08:00
/*
2009-01-06 01:08:48 -08:00
* Copyright ( C ) 1997 - 2009 , Michael Jennings
1999-09-21 19:34:13 -07:00
*
2000-03-08 19:38:31 -08:00
* Permission is hereby granted , free of charge , to any person obtaining a copy
* of this software and associated documentation files ( the " Software " ) , to
* deal in the Software without restriction , including without limitation the
* rights to use , copy , modify , merge , publish , distribute , sublicense , and / or
* sell copies of the Software , and to permit persons to whom the Software is
* furnished to do so , subject to the following conditions :
1999-08-17 18:12:47 -07:00
*
2000-03-08 19:38:31 -08:00
* The above copyright notice and this permission notice shall be included in
* all copies of the Software , its documentation and marketing & publicity
* materials , and acknowledgment shall be given in the documentation , materials
* and software packages that this Software was used .
1999-08-17 18:12:47 -07:00
*
2000-03-08 19:38:31 -08:00
* THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR
* IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY ,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL
* THE AUTHORS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER LIABILITY , WHETHER
* IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE .
1999-08-17 18:12:47 -07:00
*/
static const char cvs_ident [ ] = " $Id$ " ;
# include "config.h"
# include "feature.h"
# include <stdlib.h>
# include <unistd.h>
# include <errno.h>
# include <limits.h>
2000-11-14 17:30:02 -08:00
# ifdef HAVE_X11_SUNKEYSYM_H
# include <X11 / Sunkeysym.h>
# endif
1999-08-17 18:12:47 -07:00
# include "actions.h"
2000-02-15 19:37:34 -08:00
# include "buttons.h"
1999-08-17 18:12:47 -07:00
# include "command.h"
# include "e.h"
# include "events.h"
1999-09-21 19:34:13 -07:00
# include "font.h"
2000-03-14 19:17:45 -08:00
# include "misc.h"
1999-10-07 15:18:14 -07:00
# include "startup.h"
1999-08-17 18:12:47 -07:00
# include "options.h"
# include "pixmap.h"
# include "screen.h"
# include "scrollbar.h"
# include "term.h"
# include "windows.h"
2002-05-13 15:47:08 -07:00
# ifdef ESCREEN
# include "screamcfg.h"
# endif
1999-08-17 18:12:47 -07:00
# ifdef META8_OPTION
2002-05-04 07:25:30 -07:00
unsigned char meta_char = 033 ; /* Alt-key prefix */
1999-08-17 18:12:47 -07:00
# endif
unsigned long PrivateModes = PrivMode_Default ;
unsigned long SavedModes = PrivMode_Default ;
2002-05-04 07:25:30 -07:00
char * def_colorName [ ] = {
" rgb:0/0/0 " , /* 0: black (#000000) */
1999-08-17 18:12:47 -07:00
/* low-intensity colors */
2002-05-04 07:25:30 -07:00
" rgb:cc/00/00 " , /* 1: red */
" rgb:00/cc/00 " , /* 2: green */
" rgb:cc/cc/00 " , /* 3: yellow */
" rgb:00/00/cc " , /* 4: blue */
" rgb:cc/00/cc " , /* 5: magenta */
" rgb:00/cc/cc " , /* 6: cyan */
" rgb:aa/aa/aa " , /* 7: white */
1999-08-17 18:12:47 -07:00
/* high-intensity colors */
2002-05-04 07:25:30 -07:00
" rgb:33/33/33 " , /* 8: bright black */
" rgb:ff/00/00 " , /* 1/9: bright red */
" rgb:00/ff/00 " , /* 2/10: bright green */
" rgb:ff/ff/00 " , /* 3/11: bright yellow */
" rgb:00/00/ff " , /* 4/12: bright blue */
" rgb:ff/00/ff " , /* 5/13: bright magenta */
" rgb:00/ff/ff " , /* 6/14: bright cyan */
" rgb:ff/ff/ff " , /* 7/15: bright white */
2005-04-18 15:04:07 -07:00
/* 6x6x6 color cube generated with color-cube-gen.pl */
" rgb:00/00/00 " ,
" rgb:00/00/2a " ,
" rgb:00/00/55 " ,
" rgb:00/00/7f " ,
" rgb:00/00/aa " ,
" rgb:00/00/d4 " ,
" rgb:00/2a/00 " ,
" rgb:00/2a/2a " ,
" rgb:00/2a/55 " ,
" rgb:00/2a/7f " ,
" rgb:00/2a/aa " ,
" rgb:00/2a/d4 " ,
" rgb:00/55/00 " ,
" rgb:00/55/2a " ,
" rgb:00/55/55 " ,
" rgb:00/55/7f " ,
" rgb:00/55/aa " ,
" rgb:00/55/d4 " ,
" rgb:00/7f/00 " ,
" rgb:00/7f/2a " ,
" rgb:00/7f/55 " ,
" rgb:00/7f/7f " ,
" rgb:00/7f/aa " ,
" rgb:00/7f/d4 " ,
" rgb:00/aa/00 " ,
" rgb:00/aa/2a " ,
" rgb:00/aa/55 " ,
" rgb:00/aa/7f " ,
" rgb:00/aa/aa " ,
" rgb:00/aa/d4 " ,
" rgb:00/d4/00 " ,
" rgb:00/d4/2a " ,
" rgb:00/d4/55 " ,
" rgb:00/d4/7f " ,
" rgb:00/d4/aa " ,
" rgb:00/d4/d4 " ,
" rgb:2a/00/00 " ,
" rgb:2a/00/2a " ,
" rgb:2a/00/55 " ,
" rgb:2a/00/7f " ,
" rgb:2a/00/aa " ,
" rgb:2a/00/d4 " ,
" rgb:2a/2a/00 " ,
" rgb:2a/2a/2a " ,
" rgb:2a/2a/55 " ,
" rgb:2a/2a/7f " ,
" rgb:2a/2a/aa " ,
" rgb:2a/2a/d4 " ,
" rgb:2a/55/00 " ,
" rgb:2a/55/2a " ,
" rgb:2a/55/55 " ,
" rgb:2a/55/7f " ,
" rgb:2a/55/aa " ,
" rgb:2a/55/d4 " ,
" rgb:2a/7f/00 " ,
" rgb:2a/7f/2a " ,
" rgb:2a/7f/55 " ,
" rgb:2a/7f/7f " ,
" rgb:2a/7f/aa " ,
" rgb:2a/7f/d4 " ,
" rgb:2a/aa/00 " ,
" rgb:2a/aa/2a " ,
" rgb:2a/aa/55 " ,
" rgb:2a/aa/7f " ,
" rgb:2a/aa/aa " ,
" rgb:2a/aa/d4 " ,
" rgb:2a/d4/00 " ,
" rgb:2a/d4/2a " ,
" rgb:2a/d4/55 " ,
" rgb:2a/d4/7f " ,
" rgb:2a/d4/aa " ,
" rgb:2a/d4/d4 " ,
" rgb:55/00/00 " ,
" rgb:55/00/2a " ,
" rgb:55/00/55 " ,
" rgb:55/00/7f " ,
" rgb:55/00/aa " ,
" rgb:55/00/d4 " ,
" rgb:55/2a/00 " ,
" rgb:55/2a/2a " ,
" rgb:55/2a/55 " ,
" rgb:55/2a/7f " ,
" rgb:55/2a/aa " ,
" rgb:55/2a/d4 " ,
" rgb:55/55/00 " ,
" rgb:55/55/2a " ,
" rgb:55/55/55 " ,
" rgb:55/55/7f " ,
" rgb:55/55/aa " ,
" rgb:55/55/d4 " ,
" rgb:55/7f/00 " ,
" rgb:55/7f/2a " ,
" rgb:55/7f/55 " ,
" rgb:55/7f/7f " ,
" rgb:55/7f/aa " ,
" rgb:55/7f/d4 " ,
" rgb:55/aa/00 " ,
" rgb:55/aa/2a " ,
" rgb:55/aa/55 " ,
" rgb:55/aa/7f " ,
" rgb:55/aa/aa " ,
" rgb:55/aa/d4 " ,
" rgb:55/d4/00 " ,
" rgb:55/d4/2a " ,
" rgb:55/d4/55 " ,
" rgb:55/d4/7f " ,
" rgb:55/d4/aa " ,
" rgb:55/d4/d4 " ,
" rgb:7f/00/00 " ,
" rgb:7f/00/2a " ,
" rgb:7f/00/55 " ,
" rgb:7f/00/7f " ,
" rgb:7f/00/aa " ,
" rgb:7f/00/d4 " ,
" rgb:7f/2a/00 " ,
" rgb:7f/2a/2a " ,
" rgb:7f/2a/55 " ,
" rgb:7f/2a/7f " ,
" rgb:7f/2a/aa " ,
" rgb:7f/2a/d4 " ,
" rgb:7f/55/00 " ,
" rgb:7f/55/2a " ,
" rgb:7f/55/55 " ,
" rgb:7f/55/7f " ,
" rgb:7f/55/aa " ,
" rgb:7f/55/d4 " ,
" rgb:7f/7f/00 " ,
" rgb:7f/7f/2a " ,
" rgb:7f/7f/55 " ,
" rgb:7f/7f/7f " ,
" rgb:7f/7f/aa " ,
" rgb:7f/7f/d4 " ,
" rgb:7f/aa/00 " ,
" rgb:7f/aa/2a " ,
" rgb:7f/aa/55 " ,
" rgb:7f/aa/7f " ,
" rgb:7f/aa/aa " ,
" rgb:7f/aa/d4 " ,
" rgb:7f/d4/00 " ,
" rgb:7f/d4/2a " ,
" rgb:7f/d4/55 " ,
" rgb:7f/d4/7f " ,
" rgb:7f/d4/aa " ,
" rgb:7f/d4/d4 " ,
" rgb:aa/00/00 " ,
" rgb:aa/00/2a " ,
" rgb:aa/00/55 " ,
" rgb:aa/00/7f " ,
" rgb:aa/00/aa " ,
" rgb:aa/00/d4 " ,
" rgb:aa/2a/00 " ,
" rgb:aa/2a/2a " ,
" rgb:aa/2a/55 " ,
" rgb:aa/2a/7f " ,
" rgb:aa/2a/aa " ,
" rgb:aa/2a/d4 " ,
" rgb:aa/55/00 " ,
" rgb:aa/55/2a " ,
" rgb:aa/55/55 " ,
" rgb:aa/55/7f " ,
" rgb:aa/55/aa " ,
" rgb:aa/55/d4 " ,
" rgb:aa/7f/00 " ,
" rgb:aa/7f/2a " ,
" rgb:aa/7f/55 " ,
" rgb:aa/7f/7f " ,
" rgb:aa/7f/aa " ,
" rgb:aa/7f/d4 " ,
" rgb:aa/aa/00 " ,
" rgb:aa/aa/2a " ,
" rgb:aa/aa/55 " ,
" rgb:aa/aa/7f " ,
" rgb:aa/aa/aa " ,
" rgb:aa/aa/d4 " ,
" rgb:aa/d4/00 " ,
" rgb:aa/d4/2a " ,
" rgb:aa/d4/55 " ,
" rgb:aa/d4/7f " ,
" rgb:aa/d4/aa " ,
" rgb:aa/d4/d4 " ,
" rgb:d4/00/00 " ,
" rgb:d4/00/2a " ,
" rgb:d4/00/55 " ,
" rgb:d4/00/7f " ,
" rgb:d4/00/aa " ,
" rgb:d4/00/d4 " ,
" rgb:d4/2a/00 " ,
" rgb:d4/2a/2a " ,
" rgb:d4/2a/55 " ,
" rgb:d4/2a/7f " ,
" rgb:d4/2a/aa " ,
" rgb:d4/2a/d4 " ,
" rgb:d4/55/00 " ,
" rgb:d4/55/2a " ,
" rgb:d4/55/55 " ,
" rgb:d4/55/7f " ,
" rgb:d4/55/aa " ,
" rgb:d4/55/d4 " ,
" rgb:d4/7f/00 " ,
" rgb:d4/7f/2a " ,
" rgb:d4/7f/55 " ,
" rgb:d4/7f/7f " ,
" rgb:d4/7f/aa " ,
" rgb:d4/7f/d4 " ,
" rgb:d4/aa/00 " ,
" rgb:d4/aa/2a " ,
" rgb:d4/aa/55 " ,
" rgb:d4/aa/7f " ,
" rgb:d4/aa/aa " ,
" rgb:d4/aa/d4 " ,
" rgb:d4/d4/00 " ,
" rgb:d4/d4/2a " ,
" rgb:d4/d4/55 " ,
" rgb:d4/d4/7f " ,
" rgb:d4/d4/aa " ,
" rgb:d4/d4/d4 " ,
/* grayscale */
" rgb:08/08/08 " ,
" rgb:12/12/12 " ,
" rgb:1c/1c/1c " ,
" rgb:26/26/26 " ,
" rgb:30/30/30 " ,
" rgb:3a/3a/3a " ,
" rgb:44/44/44 " ,
" rgb:4e/4e/4e " ,
" rgb:58/58/58 " ,
" rgb:62/62/62 " ,
" rgb:6c/6c/6c " ,
" rgb:76/76/76 " ,
" rgb:80/80/80 " ,
" rgb:8a/8a/8a " ,
" rgb:94/94/94 " ,
" rgb:9e/9e/9e " ,
" rgb:a8/a8/a8 " ,
" rgb:b2/b2/b2 " ,
" rgb:bc/bc/bc " ,
" rgb:c6/c6/c6 " ,
" rgb:d0/d0/d0 " ,
" rgb:da/da/da " ,
" rgb:e4/e4/e4 " ,
" rgb:ee/ee/ee " ,
/* fg/bg */
" rgb:aa/aa/aa " , " rgb:0/0/0 " ,
1999-08-17 18:12:47 -07:00
# ifndef NO_CURSORCOLOR
2002-05-04 07:25:30 -07:00
NULL , NULL , /* cursorColor, cursorColor2 */
2005-04-18 18:57:24 -07:00
# endif /* NO_CURSORCOLOR */
1999-08-17 18:12:47 -07:00
# ifndef NO_BOLDUNDERLINE
2002-10-22 20:03:27 -07:00
NULL , NULL , /* colorBD, colorUL */
2005-04-18 18:57:24 -07:00
# endif /* NO_BOLDUNDERLINE */
2002-10-22 20:03:27 -07:00
# ifdef ESCREEN
NULL , NULL , /* ES_COLOR_CURRENT, ES_COLOR_ACTIVE */
# endif
NULL , NULL /* pointerColor, borderColor */
1999-08-17 18:12:47 -07:00
} ;
char * rs_color [ NRS_COLORS ] ;
2002-10-22 20:03:27 -07:00
Pixel PixColors [ NRS_COLORS + EXTRA_COLORS ] ;
1999-12-02 18:31:33 -08:00
unsigned int MetaMask = 0 , AltMask = 0 , NumLockMask = 0 ;
unsigned int modmasks [ ] = { Mod1Mask , Mod2Mask , Mod3Mask , Mod4Mask , Mod5Mask } ;
2000-03-01 19:31:41 -08:00
/* This function queries X to see which modifier keys (specifically Alt, Meta, and NumLock,
since that ' s really all we care about ) are bound to the 5 modifier masks . It then sets
the variables MetaMask , AltMask , and NumLockMask to the appropriate modifier mask ( e . g . ,
Mod1Mask ) . That way , we can use MetaMask in lookup_key ( ) instead of using a specific
ModMask . This function also handles fallbacks , so that if there is no Meta key , the Alt
key will be used as Meta , and vice versa . get_modifiers ( ) is called once on startup and
after each MappingNotify event . */
1999-12-02 18:31:33 -08:00
void
get_modifiers ( void )
{
2002-05-04 07:25:30 -07:00
unsigned short i ;
XModifierKeymap * modmap ;
KeyCode * kc ;
modmap = XGetModifierMapping ( Xdisplay ) ;
kc = modmap - > modifiermap ;
/* For each of the 5 modifier masks... */
for ( i = Mod5MapIndex ; i > = Mod1MapIndex ; i - - ) {
unsigned short j ;
register unsigned short k , l ;
k = i * modmap - > max_keypermod ;
l = i - Mod1MapIndex ;
/* Find each key bound to it... */
for ( j = 0 ; j < modmap - > max_keypermod ; j + + , k + + ) {
unsigned char match = 0 ;
if ( kc [ k ] = = 0 ) {
break ;
}
/* Check to see if it's one that we care about. */
switch ( XKeycodeToKeysym ( Xdisplay , kc [ k ] , 0 ) ) {
2005-04-18 18:57:24 -07:00
case XK_Meta_L :
case XK_Meta_R :
D_X11 ( ( " Found Meta key as mod %d \n " , l + 1 ) ) ;
match = MetaMask = modmasks [ l ] ;
break ;
case XK_Alt_L :
case XK_Alt_R :
D_X11 ( ( " Found Alt key as mod %d \n " , l + 1 ) ) ;
match = AltMask = modmasks [ l ] ;
break ;
case XK_Num_Lock :
D_X11 ( ( " Found NumLock key as mod %d \n " , l + 1 ) ) ;
match = NumLockMask = modmasks [ l ] ;
break ;
default :
break ;
2002-05-04 07:25:30 -07:00
}
if ( match ) {
break ;
}
}
1999-12-02 18:31:33 -08:00
}
2002-05-04 07:25:30 -07:00
XFreeModifiermap ( modmap ) ;
/* Fallbacks. */
if ( MetaMask = = 0 ) {
if ( AltMask ! = 0 ) {
D_X11 ( ( " Defaulted Meta key to match Alt mask \n " ) ) ;
MetaMask = AltMask ;
} else {
D_X11 ( ( " Defaulted Meta key to mod 1 \n " ) ) ;
MetaMask = Mod1Mask ;
}
}
if ( AltMask = = 0 ) {
D_X11 ( ( " Defaulted Alt key to match Meta mask \n " ) ) ;
AltMask = MetaMask ; /* MetaMask will always be defined at this point. */
}
/* See if the user wants to override any of those */
if ( rs_meta_mod ) {
MetaMask = modmasks [ rs_meta_mod - 1 ] ;
}
if ( rs_alt_mod ) {
AltMask = modmasks [ rs_alt_mod - 1 ] ;
}
if ( rs_numlock_mod ) {
NumLockMask = modmasks [ rs_numlock_mod - 1 ] ;
1999-12-02 18:31:33 -08:00
}
}
1999-08-17 18:12:47 -07:00
2000-09-01 15:14:17 -07:00
/* To handle buffer overflows properly, we must malloc a buffer. Free it when done. */
1999-09-14 16:22:06 -07:00
# ifdef USE_XIM
# define LK_RET() do {if (kbuf_alloced) FREE(kbuf); return;} while (0)
# else
# define LK_RET() return
# endif
2000-03-01 19:31:41 -08:00
/* This function is called for every keypress event we receive. Its job is to convert
the keypress into its corresponding action . It is responsible for calling the action
bindings routine to see if there is an action binding for that keysym ; if there is ,
this routine will exit . If not , it continues . It then uses the keysym to determine
the action or escape sequence which should result from the keypress . Actions are
performed and the event discarded . Escape sequences are generated and sent to the
child process . */
1999-08-17 18:12:47 -07:00
void
lookup_key ( XEvent * ev )
{
2002-05-13 15:47:08 -07:00
# ifdef ESCREEN
static int escreen_escape = 0 ;
# endif
2002-05-04 07:25:30 -07:00
static int numlock_state = 0 ;
int ctrl , meta , shft , len ;
KeySym keysym ;
2002-06-02 17:24:22 -07:00
1999-08-17 18:12:47 -07:00
# ifdef USE_XIM
2002-05-04 07:25:30 -07:00
int valid_keysym = 0 ;
static unsigned char short_buf [ 256 ] ;
unsigned char * kbuf = short_buf ;
int kbuf_alloced = 0 ;
1999-09-14 16:22:06 -07:00
# else
2002-05-04 07:25:30 -07:00
static unsigned char kbuf [ KBUFSZ ] ;
1999-08-17 18:12:47 -07:00
# endif
# ifdef GREEK_SUPPORT
2002-05-04 07:25:30 -07:00
static short greek_mode = 0 ;
1999-08-17 18:12:47 -07:00
# endif
2002-05-04 07:25:30 -07:00
/* Quick boolean variables tell us which modifier keys were pressed. */
shft = ( ev - > xkey . state & ShiftMask ) ;
ctrl = ( ev - > xkey . state & ControlMask ) ;
meta = ( ev - > xkey . state & MetaMask ) ;
/* The num lock key toggles application keypad
mode . Num lock on , app . keypad mode off . */
if ( numlock_state | | ( ev - > xkey . state & NumLockMask ) ) {
numlock_state = ( ev - > xkey . state & NumLockMask ) ;
PrivMode ( ( ! numlock_state ) , PrivMode_aplKP ) ;
}
1999-08-17 18:12:47 -07:00
# ifdef USE_XIM
2010-08-25 18:34:13 -07:00
if ( xim_input_context ) {
2002-05-04 07:25:30 -07:00
Status status_return ;
kbuf [ 0 ] = ' \0 ' ;
/* Lookup the string equivalent in terms of the XIM input context. */
len = XmbLookupString ( xim_input_context , & ev - > xkey , ( char * ) kbuf , sizeof ( short_buf ) , & keysym , & status_return ) ;
D_TTY ( ( " XmbLookupString() gave us len %d, keysym \" %s \" (0x%04x), and buffer \" %s \" based on the XIM input context %010p \n " ,
len , XKeysymToString ( keysym ) , keysym , safe_print_string ( kbuf , len ) , xim_input_context ) ) ;
/* Whoops, it's too long. Allocate a new buffer and repeat the call. */
if ( status_return = = XBufferOverflow ) {
kbuf = ( unsigned char * ) MALLOC ( len + 1 ) ;
kbuf_alloced = 1 ;
len = XmbLookupString ( xim_input_context , & ev - > xkey , ( char * ) kbuf , len , & keysym , & status_return ) ;
2005-04-18 18:57:24 -07:00
D_TTY ( ( " XmbLookupString() gave us len %d, keysym \" %s \" (0x%04x), and buffer \" %s \" based on the XIM input context %010p \n " , len , XKeysymToString ( keysym ) , keysym , safe_print_string ( kbuf , len ) , xim_input_context ) ) ;
2002-05-04 07:25:30 -07:00
}
valid_keysym = ( status_return = = XLookupKeySym ) | | ( status_return = = XLookupBoth ) ;
} else {
/* No XIM input context. Do it the normal way. */
len = XLookupString ( & ev - > xkey , ( char * ) kbuf , sizeof ( short_buf ) , & keysym , NULL ) ;
2005-04-18 18:57:24 -07:00
D_TTY ( ( " XLookupString() gave us len %d, keysym \" %s \" (0x%04x), and buffer \" %s \" \n " , len , XKeysymToString ( keysym ) , keysym ,
safe_print_string ( kbuf , len ) ) ) ;
2002-05-04 07:25:30 -07:00
valid_keysym = 1 ;
1999-09-14 16:22:06 -07:00
}
2002-05-04 07:25:30 -07:00
# else /* USE_XIM */
/* Translate the key event into its corresponding string according to X. This also gets us a keysym. */
len = XLookupString ( & ev - > xkey , ( char * ) kbuf , sizeof ( kbuf ) , & keysym , NULL ) ;
2005-04-18 18:57:24 -07:00
D_TTY ( ( " XLookupString() gave us len %d, keysym \" %s \" (0x%04x), and buffer \" %s \" \n " , len , XKeysymToString ( keysym ) , keysym ,
safe_print_string ( kbuf , len ) ) ) ;
2002-05-04 07:25:30 -07:00
/* If there is no string and it's a Latin2-7 character, replace it with the Latin1 character instead. */
if ( ! len & & ( keysym > = 0x0100 ) & & ( keysym < 0x0900 ) ) {
len = 1 ;
kbuf [ 0 ] = ( keysym & 0xff ) ;
}
1999-08-17 18:12:47 -07:00
# endif /* USE_XIM */
2002-05-13 15:47:08 -07:00
# ifdef ESCREEN
2002-06-02 17:24:22 -07:00
# ifdef NS_HAVE_SCREEN
2002-05-13 16:19:30 -07:00
if ( escreen_escape ) {
if ( kbuf [ 0 ] ) {
escreen_escape = 0 ;
if ( kbuf [ 0 ] < 128 )
( void ) ns_parse_screen_key ( TermWin . screen , kbuf [ 0 ] ) ;
LK_RET ( ) ;
}
} else if ( TermWin . screen & & TermWin . screen - > escape = = kbuf [ 0 ] ) {
escreen_escape = 1 ;
LK_RET ( ) ;
}
2002-06-02 17:24:22 -07:00
# endif
2002-05-13 15:47:08 -07:00
# endif
1999-09-08 10:57:06 -07:00
# ifdef USE_XIM
2002-05-04 07:25:30 -07:00
/* Don't do anything without a valid keysym. */
if ( valid_keysym ) {
1999-09-08 10:57:06 -07:00
# endif
2002-05-04 07:25:30 -07:00
/* Check for a corresponding action binding. If there is one, we're done with this event. */
if ( action_dispatch ( ev , keysym ) ) {
LK_RET ( ) ;
}
if ( len ) {
/* Only home for keypresses with length. */
2003-08-24 08:09:32 -07:00
if ( BITFIELD_IS_SET ( vt_options , VT_OPTIONS_HOME_ON_INPUT ) ) {
2002-05-04 07:25:30 -07:00
TermWin . view_start = 0 ;
}
}
/* This is a special mode that reports all extended keysyms (above 0xff00) to the application
as escape sequences . Very few applications use it , but it can be a handy thing to have . */
2003-08-24 08:09:32 -07:00
if ( ( BITFIELD_IS_SET ( vt_options , VT_OPTIONS_REPORT_AS_KEYSYMS ) ) & & ( keysym > = 0xff00 ) ) {
2002-05-04 07:25:30 -07:00
len = sprintf ( ( char * ) kbuf , " \033 [k%X;%X~ " , ( unsigned int ) ( ev - > xkey . state & 0xff ) , ( unsigned int ) ( keysym & 0xff ) ) ;
tt_write ( kbuf , len ) ;
LK_RET ( ) ;
}
1999-08-17 18:12:47 -07:00
# ifdef HOTKEY
2002-05-04 07:25:30 -07:00
/* Ctrl-> and Ctrl-< should change font sizes. (Meta if HOTKEY has been changed to Meta.) */
if ( HOTKEY ) {
if ( keysym = = ks_bigfont ) {
change_font ( 0 , BIGGER_FONT ) ;
LK_RET ( ) ;
} else if ( keysym = = ks_smallfont ) {
change_font ( 0 , SMALLER_FONT ) ;
LK_RET ( ) ;
}
}
1999-08-17 18:12:47 -07:00
# endif
2010-08-10 11:08:44 -07:00
# if defined(HAVE_X11_SUNKEYSYM_H)
2002-05-04 07:25:30 -07:00
switch ( keysym ) {
2005-04-18 18:57:24 -07:00
case SunXK_Copy :
case SunXK_Cut :
2010-08-10 11:08:44 -07:00
selection_copy ( props [ PROP_CLIPBOARD ] ) ;
2005-04-18 18:57:24 -07:00
LK_RET ( ) ;
break ;
case SunXK_Paste :
2010-08-10 11:08:44 -07:00
selection_paste ( props [ PROP_CLIPBOARD ] ) ;
2005-04-18 18:57:24 -07:00
LK_RET ( ) ;
break ;
case SunXK_Front :
xterm_seq ( ESCSEQ_XTERM_TAKEOVER , " " ) ;
LK_RET ( ) ;
break ;
default :
break ;
2002-05-04 07:25:30 -07:00
}
2000-11-14 17:30:02 -08:00
# endif
2002-05-04 07:25:30 -07:00
if ( shft ) {
/* Shift + F1 - F10 generates F11 - F20 */
if ( keysym > = XK_F1 & & keysym < = XK_F10 ) {
keysym + = ( XK_F11 - XK_F1 ) ;
shft = 0 ;
} else if ( ! ctrl & & ! meta & & ( PrivateModes & PrivMode_ShiftKeys ) ) {
switch ( keysym ) {
2005-04-18 18:57:24 -07:00
case XK_Prior : /* Shift-PgUp scrolls up a page */
if ( TermWin . saveLines ) {
scr_page ( UP , ( TermWin . nrow - CONTEXT_LINES ) ) ;
LK_RET ( ) ;
}
break ;
case XK_Next : /* Shift-PgDn scrolls down a page */
if ( TermWin . saveLines ) {
scr_page ( DN , ( TermWin . nrow - CONTEXT_LINES ) ) ;
LK_RET ( ) ;
}
break ;
case XK_Insert : /* Shift-Ins pastes the current selection. */
selection_paste ( XA_PRIMARY ) ;
LK_RET ( ) ;
break ;
case XK_KP_Add : /* Shift-Plus on the keypad increases the font size */
change_font ( 0 , BIGGER_FONT ) ;
LK_RET ( ) ;
break ;
case XK_KP_Subtract : /* Shift-Minus on the keypad decreases the font size */
change_font ( 0 , SMALLER_FONT ) ;
LK_RET ( ) ;
break ;
2002-05-04 07:25:30 -07:00
}
}
}
1999-08-17 18:12:47 -07:00
# ifdef UNSHIFTED_SCROLLKEYS
2002-05-04 07:25:30 -07:00
/* Allow PgUp/PgDn by themselves to scroll. Not recommended. */
else if ( ! ctrl & & ! meta ) {
switch ( keysym ) {
2005-04-18 18:57:24 -07:00
case XK_Prior :
if ( TermWin . saveLines ) {
scr_page ( UP , TermWin . nrow - CONTEXT_LINES ) ;
LK_RET ( ) ;
}
break ;
case XK_Next :
if ( TermWin . saveLines ) {
scr_page ( DN , TermWin . nrow - CONTEXT_LINES ) ;
LK_RET ( ) ;
}
break ;
2002-05-04 07:25:30 -07:00
}
}
1999-08-17 18:12:47 -07:00
# endif
2002-05-13 15:47:08 -07:00
2002-05-04 07:25:30 -07:00
switch ( keysym ) {
2005-04-18 18:57:24 -07:00
case XK_Print : /* Print the screen contents out to the print pipe */
1999-08-17 18:12:47 -07:00
# if DEBUG >= DEBUG_SELECTION
2005-04-18 18:57:24 -07:00
if ( DEBUG_LEVEL > = DEBUG_SELECTION ) {
scr_dump_to_file ( " /tmp/Eterm_screen_dump.log " ) ;
} else
1999-08-17 18:12:47 -07:00
# endif
# ifdef PRINTPIPE
2005-04-18 18:57:24 -07:00
scr_printscreen ( ctrl | shft ) ;
1999-08-17 18:12:47 -07:00
# endif
2005-04-18 18:57:24 -07:00
LK_RET ( ) ;
break ;
1999-08-17 18:12:47 -07:00
2005-04-18 18:57:24 -07:00
case XK_Mode_switch :
1999-08-17 18:12:47 -07:00
# ifdef GREEK_SUPPORT
2005-04-18 18:57:24 -07:00
greek_mode = ! greek_mode ;
if ( greek_mode ) {
xterm_seq ( ESCSEQ_XTERM_TITLE , ( greek_getmode ( ) = = GREEK_ELOT928 ? " [Greek: iso] " : " [Greek: ibm] " ) ) ;
greek_reset ( ) ;
} else
xterm_seq ( ESCSEQ_XTERM_TITLE , APL_NAME " - " VERSION ) ;
LK_RET ( ) ;
1999-08-17 18:12:47 -07:00
# endif
2005-04-18 18:57:24 -07:00
break ;
2002-05-04 07:25:30 -07:00
}
2000-05-31 22:24:47 -07:00
2002-05-04 07:25:30 -07:00
/* At this point, all the keystrokes that have special meaning to us have been handled.
If we ' re in pause mode , this is a keystroke asking us to exit . Otherwise , return here . */
if ( paused ) {
if ( keysym & & len ) {
exit ( 0 ) ;
}
LK_RET ( ) ;
}
/* Process extended keysyms. This is where the conversion to escape sequences happens. */
2005-08-16 07:50:49 -07:00
if ( keysym > = 0xff00 & & keysym < = 0xffff ) {
1999-08-17 18:12:47 -07:00
# ifdef KEYSYM_ATTRIBUTE
2002-05-04 07:25:30 -07:00
/* The "keysym" attribute in the config file gets handled here. */
2010-08-25 18:34:13 -07:00
if ( ! ( shft | ctrl ) & & KeySym_map [ keysym - 0xff00 ] ) {
1999-08-17 18:12:47 -07:00
2002-05-04 07:25:30 -07:00
const unsigned char * tmpbuf ;
unsigned int len ;
1999-08-17 18:12:47 -07:00
2002-05-04 07:25:30 -07:00
tmpbuf = ( KeySym_map [ keysym - 0xff00 ] ) ;
len = * tmpbuf + + ;
1999-08-17 18:12:47 -07:00
2002-05-04 07:25:30 -07:00
/* escape prefix */
if ( meta
1999-08-17 18:12:47 -07:00
# ifdef META8_OPTION
2002-05-04 07:25:30 -07:00
& & ( meta_char = = 033 )
1999-08-17 18:12:47 -07:00
# endif
2002-05-04 07:25:30 -07:00
) {
const unsigned char ch = ' \033 ' ;
tt_write ( & ch , 1 ) ;
}
tt_write ( tmpbuf , len ) ;
LK_RET ( ) ;
} else
1999-08-17 18:12:47 -07:00
# endif
2002-05-04 07:25:30 -07:00
/* This is a big-ass switch statement that handles all the special keysyms */
switch ( keysym ) {
2005-04-18 18:57:24 -07:00
case XK_BackSpace :
len = 1 ;
1999-08-17 18:12:47 -07:00
# ifdef FORCE_BACKSPACE
2005-04-18 18:57:24 -07:00
kbuf [ 0 ] = ( ! ( shft | ctrl ) ? ' \b ' : ' \177 ' ) ;
1999-08-17 18:12:47 -07:00
# elif defined(FORCE_DELETE)
2005-04-18 18:57:24 -07:00
kbuf [ 0 ] = ( ( shft | ctrl ) ? ' \b ' : ' \177 ' ) ;
1999-08-17 18:12:47 -07:00
# else
2005-04-18 18:57:24 -07:00
kbuf [ 0 ] = ( ( ( PrivateModes & PrivMode_BackSpace ) ? ! ( shft | ctrl ) : ( shft | ctrl ) ) ? ' \b ' : ' \177 ' ) ;
1999-08-17 18:12:47 -07:00
# endif
2000-12-29 14:59:13 -08:00
# ifdef MULTI_CHARSET
2005-04-18 18:57:24 -07:00
if ( ( BITFIELD_IS_SET ( eterm_options , ETERM_OPTIONS_MBYTE_CURSOR ) ) & & scr_multi2 ( ) ) {
memmove ( kbuf + len , kbuf , len ) ;
len * = 2 ;
}
2000-12-29 14:59:13 -08:00
# endif /* MULTI_CHARSET */
2005-04-18 18:57:24 -07:00
break ;
1999-08-17 18:12:47 -07:00
2005-04-18 18:57:24 -07:00
/* Tab key is normal unless it's shift-tab. */
case XK_Tab :
case XK_ISO_Left_Tab :
if ( shft ) {
len = 3 ;
strcpy ( kbuf , " \033 [Z " ) ;
}
break ;
1999-08-17 18:12:47 -07:00
# ifdef XK_KP_Home
2005-04-18 18:57:24 -07:00
case XK_KP_Home :
/* allow shift to override */
if ( ( PrivateModes & PrivMode_aplKP ) ? ! shft : shft ) {
len = 3 ;
strcpy ( kbuf , " \033 Ow " ) ;
break ;
}
/* -> else FALL THROUGH */
1999-08-17 18:12:47 -07:00
# endif
2005-04-18 18:57:24 -07:00
case XK_Home :
len = strlen ( strcpy ( kbuf , KS_HOME ) ) ;
break ;
1999-08-17 18:12:47 -07:00
# ifdef XK_KP_Left
2005-04-18 18:57:24 -07:00
case XK_KP_Left : /* \033Ot or standard cursor key */
case XK_KP_Up : /* \033Ox or standard cursor key */
case XK_KP_Right : /* \033Ov or standard cursor key */
case XK_KP_Down : /* \033Or or standard cursor key */
if ( ( PrivateModes & PrivMode_aplKP ) ? ! shft : shft ) {
len = 3 ;
strcpy ( kbuf , " \033 OZ " ) ; /* The Z is replaced by t, x, v, or r */
kbuf [ 2 ] = ( " txvr " [ keysym - XK_KP_Left ] ) ;
break ;
} else {
keysym = XK_Left + ( keysym - XK_KP_Left ) ;
}
/* Continue on with the normal cursor keys... */
1999-08-17 18:12:47 -07:00
# endif
2005-04-18 18:57:24 -07:00
case XK_Left : /* "\033[D" */
case XK_Up : /* "\033[A" */
case XK_Right : /* "\033[C" */
case XK_Down : /* "\033[B" */
len = 3 ;
strcpy ( kbuf , " \033 [@ " ) ;
kbuf [ 2 ] = ( " DACB " [ keysym - XK_Left ] ) ;
if ( PrivateModes & PrivMode_aplCUR ) {
kbuf [ 1 ] = ' O ' ;
} else if ( shft ) { /* do Shift first */
kbuf [ 2 ] = ( " dacb " [ keysym - XK_Left ] ) ;
} else if ( ctrl ) {
kbuf [ 1 ] = ' O ' ;
kbuf [ 2 ] = ( " dacb " [ keysym - XK_Left ] ) ;
}
2000-12-29 14:59:13 -08:00
# ifdef MULTI_CHARSET
2005-04-18 18:57:24 -07:00
if ( ( BITFIELD_IS_SET ( eterm_options , ETERM_OPTIONS_MBYTE_CURSOR ) )
& & ( ( keysym = = XK_Left & & scr_multi2 ( ) )
| | ( keysym = = XK_Right & & scr_multi1 ( ) ) ) ) {
memmove ( kbuf + len , kbuf , len ) ;
len * = 2 ;
}
2000-12-29 14:59:13 -08:00
# endif /* MULTI_CHARSET */
2005-04-18 18:57:24 -07:00
break ;
2000-03-01 19:31:41 -08:00
2005-04-18 18:57:24 -07:00
/* Keypad and normal PgUp/PgDn */
1999-08-17 18:12:47 -07:00
# ifndef UNSHIFTED_SCROLLKEYS
# ifdef XK_KP_Prior
2005-04-18 18:57:24 -07:00
case XK_KP_Prior :
/* allow shift to override */
if ( ( PrivateModes & PrivMode_aplKP ) ? ! shft : shft ) {
len = 3 ;
strcpy ( kbuf , " \033 Oy " ) ;
break ;
}
/* -> else FALL THROUGH */
2002-05-04 07:25:30 -07:00
# endif /* XK_KP_Prior */
2005-04-18 18:57:24 -07:00
case XK_Prior :
len = 4 ;
strcpy ( kbuf , " \033 [5~ " ) ;
break ;
1999-08-17 18:12:47 -07:00
# ifdef XK_KP_Next
2005-04-18 18:57:24 -07:00
case XK_KP_Next :
/* allow shift to override */
if ( ( PrivateModes & PrivMode_aplKP ) ? ! shft : shft ) {
len = 3 ;
strcpy ( kbuf , " \033 Os " ) ;
break ;
}
/* -> else FALL THROUGH */
2002-05-04 07:25:30 -07:00
# endif /* XK_KP_Next */
2005-04-18 18:57:24 -07:00
case XK_Next :
len = 4 ;
strcpy ( kbuf , " \033 [6~ " ) ;
break ;
1999-08-17 18:12:47 -07:00
# endif /* UNSHIFTED_SCROLLKEYS */
2000-03-01 19:31:41 -08:00
2005-04-18 18:57:24 -07:00
/* End key */
1999-08-17 18:12:47 -07:00
# ifdef XK_KP_End
2005-04-18 18:57:24 -07:00
case XK_KP_End :
/* allow shift to override */
if ( ( PrivateModes & PrivMode_aplKP ) ? ! shft : shft ) {
len = 3 ;
strcpy ( kbuf , " \033 Oq " ) ;
break ;
}
/* -> else FALL THROUGH */
1999-08-17 18:12:47 -07:00
# endif /* XK_KP_End */
2005-04-18 18:57:24 -07:00
case XK_End :
len = strlen ( strcpy ( kbuf , KS_END ) ) ;
break ;
1999-08-17 18:12:47 -07:00
2005-04-18 18:57:24 -07:00
case XK_Select :
len = 4 ;
strcpy ( kbuf , " \033 [4~ " ) ;
break ;
1999-08-17 18:12:47 -07:00
2000-03-01 19:31:41 -08:00
# ifdef DXK_Remove
2005-04-18 18:57:24 -07:00
case DXK_Remove :
1999-08-17 18:12:47 -07:00
# endif
2005-04-18 18:57:24 -07:00
case XK_Execute :
len = 4 ;
strcpy ( kbuf , " \033 [3~ " ) ;
break ;
2000-01-17 13:29:27 -08:00
# ifdef XK_KP_Insert
2005-04-18 18:57:24 -07:00
case XK_KP_Insert :
if ( ( PrivateModes & PrivMode_aplKP ) ? ! shft : shft ) {
len = 3 ;
strcpy ( kbuf , " \033 Op " ) ;
break ;
}
2000-01-17 13:29:27 -08:00
# endif
2005-04-18 18:57:24 -07:00
case XK_Insert :
len = 4 ;
strcpy ( kbuf , " \033 [2~ " ) ;
break ;
1999-08-17 18:12:47 -07:00
2000-01-17 13:29:27 -08:00
# ifdef XK_KP_Delete
2005-04-18 18:57:24 -07:00
case XK_KP_Delete :
if ( ( PrivateModes & PrivMode_aplKP ) ? ! shft : shft ) {
len = 3 ;
strcpy ( kbuf , " \033 On " ) ;
break ;
}
2000-01-17 13:29:27 -08:00
# endif
2005-04-18 18:57:24 -07:00
case XK_Delete :
2000-01-17 13:29:27 -08:00
# ifdef KS_DELETE
2005-04-18 18:57:24 -07:00
len = strlen ( strcpy ( kbuf , KS_DELETE ) ) ;
2000-12-29 14:59:13 -08:00
# ifdef MULTI_CHARSET
2005-04-18 18:57:24 -07:00
if ( ( BITFIELD_IS_SET ( eterm_options , ETERM_OPTIONS_MBYTE_CURSOR ) ) & & scr_multi1 ( ) ) {
memmove ( kbuf + len , kbuf , len ) ;
len * = 2 ;
}
2000-12-29 14:59:13 -08:00
# endif /* MULTI_CHARSET */
2000-01-17 13:29:27 -08:00
# endif
2005-04-18 18:57:24 -07:00
break ;
case XK_Menu :
len = 5 ;
strcpy ( kbuf , " \033 [29~ " ) ;
break ;
case XK_Find :
len = 4 ;
strcpy ( kbuf , " \033 [1~ " ) ;
break ;
case XK_Help :
len = 5 ;
strcpy ( kbuf , " \033 [28~ " ) ;
break ;
case XK_KP_Enter :
/* allow shift to override */
if ( ( PrivateModes & PrivMode_aplKP ) ? ! shft : shft ) {
len = 3 ;
strcpy ( kbuf , " \033 OM " ) ;
} else {
len = 1 ;
kbuf [ 0 ] = ' \r ' ;
}
break ;
1999-08-17 18:12:47 -07:00
# ifdef XK_KP_Begin
2005-04-18 18:57:24 -07:00
case XK_KP_Begin :
len = 3 ;
strcpy ( kbuf , " \033 Ou " ) ;
break ;
1999-08-17 18:12:47 -07:00
# endif /* XK_KP_Begin */
2005-04-18 18:57:24 -07:00
case XK_KP_F1 : /* "\033OP" */
case XK_KP_F2 : /* "\033OQ" */
case XK_KP_F3 : /* "\033OR" */
case XK_KP_F4 : /* "\033OS" */
len = 3 ;
strcpy ( kbuf , " \033 OP " ) ;
kbuf [ 2 ] + = ( keysym - XK_KP_F1 ) ;
break ;
case XK_KP_Multiply : /* "\033Oj" : "*" */
case XK_KP_Add : /* "\033Ok" : "+" */
case XK_KP_Separator : /* "\033Ol" : "," */
case XK_KP_Subtract : /* "\033Om" : "-" */
case XK_KP_Decimal : /* "\033On" : "." */
case XK_KP_Divide : /* "\033Oo" : "/" */
case XK_KP_0 : /* "\033Op" : "0" */
case XK_KP_1 : /* "\033Oq" : "1" */
case XK_KP_2 : /* "\033Or" : "2" */
case XK_KP_3 : /* "\033Os" : "3" */
case XK_KP_4 : /* "\033Ot" : "4" */
case XK_KP_5 : /* "\033Ou" : "5" */
case XK_KP_6 : /* "\033Ov" : "6" */
case XK_KP_7 : /* "\033Ow" : "7" */
case XK_KP_8 : /* "\033Ox" : "8" */
case XK_KP_9 : /* "\033Oy" : "9" */
/* allow shift to override */
if ( ( PrivateModes & PrivMode_aplKP ) ? ! shft : shft ) {
len = 3 ;
strcpy ( kbuf , " \033 Oj " ) ;
kbuf [ 2 ] + = ( keysym - XK_KP_Multiply ) ;
} else {
len = 1 ;
kbuf [ 0 ] = ( ' * ' + ( keysym - XK_KP_Multiply ) ) ;
}
break ;
1999-08-17 18:12:47 -07:00
# define FKEY(n,fkey) do { \
len = 5 ; \
1999-10-27 11:10:40 -07:00
sprintf ( ( char * ) kbuf , " \033 [%02d~ " , ( int ) ( ( n ) + ( keysym - fkey ) ) ) ; \
1999-08-17 18:12:47 -07:00
} while ( 0 ) ;
2005-04-18 18:57:24 -07:00
case XK_F1 : /* "\033[11~" */
case XK_F2 : /* "\033[12~" */
case XK_F3 : /* "\033[13~" */
case XK_F4 : /* "\033[14~" */
case XK_F5 : /* "\033[15~" */
FKEY ( 11 , XK_F1 ) ;
break ;
case XK_F6 : /* "\033[17~" */
case XK_F7 : /* "\033[18~" */
case XK_F8 : /* "\033[19~" */
case XK_F9 : /* "\033[20~" */
case XK_F10 : /* "\033[21~" */
FKEY ( 17 , XK_F6 ) ;
break ;
case XK_F11 : /* "\033[23~" */
case XK_F12 : /* "\033[24~" */
case XK_F13 : /* "\033[25~" */
case XK_F14 : /* "\033[26~" */
FKEY ( 23 , XK_F11 ) ;
break ;
case XK_F15 : /* "\033[28~" */
case XK_F16 : /* "\033[29~" */
FKEY ( 28 , XK_F15 ) ;
break ;
case XK_F17 : /* "\033[31~" */
case XK_F18 : /* "\033[32~" */
case XK_F19 : /* "\033[33~" */
case XK_F20 : /* "\033[34~" */
case XK_F21 : /* "\033[35~" */
case XK_F22 : /* "\033[36~" */
case XK_F23 : /* "\033[37~" */
case XK_F24 : /* "\033[38~" */
case XK_F25 : /* "\033[39~" */
case XK_F26 : /* "\033[40~" */
case XK_F27 : /* "\033[41~" */
case XK_F28 : /* "\033[42~" */
case XK_F29 : /* "\033[43~" */
case XK_F30 : /* "\033[44~" */
case XK_F31 : /* "\033[45~" */
case XK_F32 : /* "\033[46~" */
case XK_F33 : /* "\033[47~" */
case XK_F34 : /* "\033[48~" */
case XK_F35 : /* "\033[49~" */
FKEY ( 31 , XK_F17 ) ;
break ;
1999-08-17 18:12:47 -07:00
# undef FKEY
2002-05-04 07:25:30 -07:00
}
1999-08-17 18:12:47 -07:00
# ifdef META8_OPTION
2002-05-04 07:25:30 -07:00
if ( meta & & ( meta_char = = 0x80 ) & & len > 0 ) {
kbuf [ len - 1 ] | = 0x80 ;
}
1999-08-17 18:12:47 -07:00
# endif
2002-05-04 07:25:30 -07:00
} else if ( ctrl & & keysym = = XK_minus ) {
len = 1 ;
kbuf [ 0 ] = ' \037 ' ; /* Ctrl-Minus generates ^_ (31) */
} else {
1999-08-17 18:12:47 -07:00
# ifdef META8_OPTION
2002-05-04 07:25:30 -07:00
/* set 8-bit on */
if ( meta & & ( meta_char = = 0x80 ) ) {
1999-08-17 18:12:47 -07:00
2002-05-04 07:25:30 -07:00
unsigned char * ch ;
1999-08-17 18:12:47 -07:00
2002-05-04 07:25:30 -07:00
for ( ch = kbuf ; ch < kbuf + len ; ch + + )
* ch | = 0x80 ;
meta = 0 ;
}
1999-08-17 18:12:47 -07:00
# endif
# ifdef GREEK_SUPPORT
2002-05-04 07:25:30 -07:00
if ( greek_mode )
len = greek_xlat ( kbuf , len ) ;
1999-08-17 18:12:47 -07:00
# endif
2002-05-04 07:25:30 -07:00
}
1999-08-17 18:12:47 -07:00
# ifdef USE_XIM
2002-05-04 07:25:30 -07:00
}
1999-08-17 18:12:47 -07:00
# endif
2002-05-04 07:25:30 -07:00
/* All processed. If there's still no string, we're done. */
if ( len < = 0 ) {
LK_RET ( ) ;
}
/*
* these modifications only affect the static keybuffer
* pass Shift / Control indicators for function keys ending with ` ~ '
*
* eg ,
* Prior = " ESC[5~ "
* Shift + Prior = " ESC[5$ "
* Ctrl + Prior = " ESC[5^ "
* Ctrl + Shift + Prior = " ESC[5@ "
*/
if ( kbuf [ 0 ] = = ' \033 ' & & kbuf [ 1 ] = = ' [ ' & & kbuf [ len - 1 ] = = ' ~ ' ) {
kbuf [ len - 1 ] = ( shft ? ( ctrl ? ' @ ' : ' $ ' ) : ( ctrl ? ' ^ ' : ' ~ ' ) ) ;
}
/* escape prefix */
if ( meta
1999-08-17 18:12:47 -07:00
# ifdef META8_OPTION
2002-05-04 07:25:30 -07:00
& & ( meta_char = = 033 )
1999-08-17 18:12:47 -07:00
# endif
2002-05-04 07:25:30 -07:00
) {
1999-08-17 18:12:47 -07:00
2002-05-04 07:25:30 -07:00
const unsigned char ch = ' \033 ' ;
1999-08-17 18:12:47 -07:00
2002-05-04 07:25:30 -07:00
tt_write ( & ch , 1 ) ;
}
2005-04-18 18:57:24 -07:00
D_TTY ( ( " After handling: len %d, keysym \" %s \" (0x%04x), and buffer \" %s \" \n " , len , XKeysymToString ( keysym ) , keysym ,
safe_print_string ( kbuf , len ) ) ) ;
2002-05-04 07:25:30 -07:00
tt_write ( kbuf , len ) ; /* Send the resulting string to the child process */
1999-09-14 18:37:01 -07:00
2002-05-04 07:25:30 -07:00
LK_RET ( ) ;
1999-08-17 18:12:47 -07:00
}
# ifdef PRINTPIPE
2000-03-01 19:31:41 -08:00
/* Open the print pipe. */
1999-08-17 18:12:47 -07:00
FILE *
popen_printer ( void )
{
2002-05-04 07:25:30 -07:00
FILE * stream ;
if ( ( ( my_ruid ! = my_euid ) | | ( my_rgid ! = my_egid ) ) & & ( strcmp ( rs_print_pipe , PRINTPIPE ) ) ) {
2006-02-13 11:52:45 -08:00
libast_print_warning ( " Running setuid/setgid. Refusing to use custom printpipe. \n " ) ;
2002-05-04 07:25:30 -07:00
RESET_AND_ASSIGN ( rs_print_pipe , STRDUP ( PRINTPIPE ) ) ;
}
2010-08-25 18:34:13 -07:00
if ( ! ( stream = ( FILE * ) popen ( rs_print_pipe , " w " ) ) ) {
2006-02-13 11:52:45 -08:00
libast_print_error ( " Can't open printer pipe \" %s \" -- %s \n " , rs_print_pipe , strerror ( errno ) ) ;
2002-05-04 07:25:30 -07:00
}
return stream ;
1999-08-17 18:12:47 -07:00
}
2000-03-01 19:31:41 -08:00
/* Close the print pipe. */
1999-08-17 18:12:47 -07:00
int
pclose_printer ( FILE * stream )
{
2002-05-04 07:25:30 -07:00
fflush ( stream ) ;
return pclose ( stream ) ;
1999-08-17 18:12:47 -07:00
}
2000-03-01 19:31:41 -08:00
/* Print everything until we hit a \e[4i sequence. */
1999-08-17 18:12:47 -07:00
void
process_print_pipe ( void )
{
2002-05-04 07:25:30 -07:00
const char * const escape_seq = " \033 [4i " ;
int index ;
FILE * fd ;
2010-08-25 18:34:13 -07:00
if ( ( fd = popen_printer ( ) ) ) {
2002-05-04 07:25:30 -07:00
for ( index = 0 ; index < 4 ; /* nil */ ) {
unsigned char ch = cmd_getc ( ) ;
2004-02-11 11:03:37 -08:00
if ( ch = = escape_seq [ index ] ) {
2002-05-04 07:25:30 -07:00
index + + ;
2004-02-11 11:03:37 -08:00
} else if ( index ) {
int i ;
2002-05-04 07:25:30 -07:00
2004-02-11 11:03:37 -08:00
for ( i = 0 ; index > 0 ; i + + , index - - ) {
fputc ( escape_seq [ i ] , fd ) ;
}
}
if ( index = = 0 ) {
2002-05-04 07:25:30 -07:00
fputc ( ch , fd ) ;
2004-02-11 11:03:37 -08:00
}
2002-05-04 07:25:30 -07:00
}
pclose_printer ( fd ) ;
1999-08-17 18:12:47 -07:00
}
}
# endif /* PRINTPIPE */
2000-03-01 19:31:41 -08:00
/* This routine processes escape sequences; i.e., when a \033 character is encountered in the
input stream , this function is called to process it . First , we get the next character off
the input stream ( the one after the ESC ) and store it in ch . Then we proceed based on what
ch is . Some escape sequences are only ESC followed by a single character , so the
processing of those ends here . Others are longer and get passed on to other functions from
this one . */
1999-08-17 18:12:47 -07:00
void
process_escape_seq ( void )
{
2002-05-04 07:25:30 -07:00
unsigned char ch = cmd_getc ( ) ;
switch ( ch ) {
2005-04-18 18:57:24 -07:00
case ' # ' :
if ( cmd_getc ( ) = = ' 8 ' )
scr_E ( ) ;
break ;
case ' ( ' :
scr_charset_set ( 0 , cmd_getc ( ) ) ;
break ;
case ' ) ' :
scr_charset_set ( 1 , cmd_getc ( ) ) ;
break ;
case ' * ' :
scr_charset_set ( 2 , cmd_getc ( ) ) ;
break ;
case ' + ' :
scr_charset_set ( 3 , cmd_getc ( ) ) ;
break ;
1999-08-17 18:12:47 -07:00
# ifdef MULTI_CHARSET
2005-04-18 18:57:24 -07:00
case ' $ ' :
scr_charset_set ( - 2 , cmd_getc ( ) ) ;
break ;
1999-08-17 18:12:47 -07:00
# endif
2005-04-18 18:57:24 -07:00
case ' 7 ' :
scr_cursor ( SAVE ) ;
break ;
case ' 8 ' :
scr_cursor ( RESTORE ) ;
break ;
case ' = ' :
case ' > ' :
PrivMode ( ( ch = = ' = ' ) , PrivMode_aplKP ) ;
break ;
case ' @ ' :
( void ) cmd_getc ( ) ;
break ;
case ' D ' :
scr_index ( UP ) ;
break ;
case ' E ' :
scr_add_lines ( ( unsigned char * ) " \n \r " , 1 , 2 ) ;
break ;
case ' G ' :
if ( ( ch = cmd_getc ( ) ) = = ' Q ' ) { /* query graphics */
tt_printf ( ( unsigned char * ) " \033 G0 \n " ) ; /* no graphics */
} else {
do {
ch = cmd_getc ( ) ;
} while ( ch ! = ' : ' ) ;
}
break ;
case ' H ' :
scr_set_tab ( 1 ) ;
break ;
case ' M ' :
scr_index ( DN ) ;
break ;
case ' Z ' :
2005-08-31 23:16:49 -07:00
# ifndef NO_ENQ_ANS
2005-04-18 18:57:24 -07:00
tt_printf ( ( unsigned char * ) ESCZ_ANSWER ) ;
2005-08-31 23:16:49 -07:00
# endif
2005-04-18 18:57:24 -07:00
break ;
case ' [ ' :
process_csi_seq ( ) ;
break ;
case ' ] ' :
process_xterm_seq ( ) ;
break ;
case ' c ' :
scr_poweron ( ) ;
break ;
case ' n ' :
scr_charset_choose ( 2 ) ;
break ;
case ' o ' :
scr_charset_choose ( 3 ) ;
break ;
2002-05-04 07:25:30 -07:00
}
1999-08-17 18:12:47 -07:00
}
2000-03-01 19:31:41 -08:00
/* This function handles Code Sequence Introducer (CSI) escape sequences. At this point,
we ' ve read " \ e[ " from the input stream . CSI sequences take an arbitrary number of
parameters and are used almost exclusively for terminal window navigation and
manipulation . */
1999-08-17 18:12:47 -07:00
void
process_csi_seq ( void )
{
2002-05-04 07:25:30 -07:00
unsigned char ch ;
unsigned char priv = 0 ;
unsigned int nargs = 0 ;
int arg [ ESC_ARGS ] = { 0 , 0 } ;
int ignore = 0 ;
1999-08-17 18:12:47 -07:00
2002-05-04 07:25:30 -07:00
ch = cmd_getc ( ) ; /* Get the next character */
if ( ch > = ' < ' & & ch < = ' ? ' ) {
priv = ch ; /* DEC private mode sequence. Get next character. */
ch = cmd_getc ( ) ;
1999-08-17 18:12:47 -07:00
}
2002-05-04 07:25:30 -07:00
/* Read semicolon-delimited numerical arguments, if any. */
do {
int n ;
for ( n = 0 ; isdigit ( ch ) ; ch = cmd_getc ( ) )
n = n * 10 + ( ch - ' 0 ' ) ;
if ( nargs < ESC_ARGS )
arg [ nargs + + ] = n ;
if ( ch = = ' \b ' ) {
scr_backspace ( ) ;
} else if ( ch = = 033 ) {
cmd_ungetc ( ) ; /* New escape sequence starting in the middle of one. Punt. */
return ;
} else if ( ch < ' ' ) {
2002-06-08 08:44:08 -07:00
scr_add_lines ( & ch , 0 , 1 ) ; /* Insert verbatim non-printable character (NPC) */
2002-05-04 07:25:30 -07:00
return ;
}
if ( ch = = ' - ' ) /* HACK: Ignore this sequence, but finish reading */
ignore = 1 ; /* xterm ignores more than this, but we need this for vim */
if ( ch < ' @ ' )
ch = cmd_getc ( ) ; /* Separator. Go to next digit or operation. */
} while ( ch > = ' ' & & ch < ' @ ' ) ;
if ( ch = = 033 ) {
cmd_ungetc ( ) ;
return ;
} else if ( ch < ' ' )
return ; /* An NPC. Punt. */
if ( ignore )
return ;
switch ( ch ) {
2005-04-18 18:57:24 -07:00
case ' @ ' :
scr_insdel_chars ( ( arg [ 0 ] ? arg [ 0 ] : 1 ) , INSERT ) ;
break ;
case ' A ' :
case ' e ' : /* Cursor up n lines "\e[<n>A" */
scr_gotorc ( ( arg [ 0 ] ? - arg [ 0 ] : - 1 ) , 0 , RELATIVE ) ;
break ;
case ' B ' : /* Cursor down n lines "\e[<n>B" */
scr_gotorc ( ( arg [ 0 ] ? + arg [ 0 ] : + 1 ) , 0 , RELATIVE ) ;
break ;
case ' C ' :
case ' a ' : /* Cursor right n columns "\e[<n>C" */
scr_gotorc ( 0 , ( arg [ 0 ] ? + arg [ 0 ] : + 1 ) , RELATIVE ) ;
break ;
case ' D ' : /* Cursor left n columns "\e[<n>D" */
scr_gotorc ( 0 , ( arg [ 0 ] ? - arg [ 0 ] : - 1 ) , RELATIVE ) ;
break ;
case ' E ' : /* Cursor down n lines and to first column "\e[<n>E" */
scr_gotorc ( ( arg [ 0 ] ? + arg [ 0 ] : + 1 ) , 0 , R_RELATIVE ) ;
break ;
case ' F ' : /* Cursor up n lines and to first column "\e[<n>F" */
scr_gotorc ( ( arg [ 0 ] ? - arg [ 0 ] : - 1 ) , 0 , R_RELATIVE ) ;
break ;
case ' G ' :
case ' ` ' : /* Cursor to column n "\e[<n>G" */
scr_gotorc ( 0 , ( arg [ 0 ] ? arg [ 0 ] - 1 : + 1 ) , R_RELATIVE ) ;
break ;
case ' H ' :
case ' f ' : /* Cursor to row r, column c "\e[<r>;<c>H" */
switch ( nargs ) {
case 0 :
scr_gotorc ( 0 , 0 , 0 ) ;
break ;
case 1 :
scr_gotorc ( ( arg [ 0 ] ? arg [ 0 ] - 1 : 0 ) , 0 , 0 ) ;
break ;
default :
scr_gotorc ( arg [ 0 ] - 1 , arg [ 1 ] - 1 , 0 ) ;
break ;
}
break ;
case ' I ' : /* Tab right n tab stops "\e[<n>I" */
scr_tab ( arg [ 0 ] ? + arg [ 0 ] : + 1 ) ;
break ;
case ' J ' : /* Clear part or all of screen, depending on n "\e[<n>J" */
scr_erase_screen ( arg [ 0 ] ) ;
break ;
case ' K ' : /* Clear part or all of line, depending on n "\e[<n>K" */
scr_erase_line ( arg [ 0 ] ) ;
break ;
case ' L ' :
scr_insdel_lines ( ( arg [ 0 ] ? arg [ 0 ] : 1 ) , INSERT ) ;
break ;
case ' M ' :
scr_insdel_lines ( ( arg [ 0 ] ? arg [ 0 ] : 1 ) , DELETE ) ;
break ;
case ' P ' :
scr_insdel_chars ( ( arg [ 0 ] ? arg [ 0 ] : 1 ) , DELETE ) ;
break ;
case ' W ' :
switch ( arg [ 0 ] ) {
case 0 :
scr_set_tab ( 1 ) ;
break ; /* = ESC H */
case 2 :
scr_set_tab ( 0 ) ;
break ; /* = ESC [ 0 g */
case 5 :
scr_set_tab ( - 1 ) ;
break ; /* = ESC [ 3 g */
}
break ;
case ' X ' :
scr_insdel_chars ( ( arg [ 0 ] ? arg [ 0 ] : 1 ) , ERASE ) ;
break ;
case ' Z ' : /* Tab left n tab stops "\e[<n>Z" */
scr_tab ( arg [ 0 ] ? - arg [ 0 ] : - 1 ) ;
break ;
case ' c ' :
/* TODO: A different response should be sent depending on the value of
priv and of arg [ 0 ] , but what should those reponses be ? */
1999-08-17 18:12:47 -07:00
# ifndef NO_VT100_ANS
2005-04-18 18:57:24 -07:00
tt_printf ( ( unsigned char * ) VT100_ANS ) ;
1999-08-17 18:12:47 -07:00
# endif
2005-04-18 18:57:24 -07:00
break ;
case ' d ' : /* Cursor to row n "\e[<n>d" */
scr_gotorc ( ( arg [ 0 ] ? arg [ 0 ] - 1 : + 1 ) , 0 , C_RELATIVE ) ;
break ;
case ' g ' :
switch ( arg [ 0 ] ) {
case 0 :
scr_set_tab ( 0 ) ;
break ; /* delete tab */
case 3 :
scr_set_tab ( - 1 ) ;
break ; /* clear all tabs */
}
break ;
2001-07-03 18:02:37 -07:00
# ifdef PRINTPIPE
2005-04-18 18:57:24 -07:00
case ' i ' :
switch ( arg [ 0 ] ) {
case 0 :
scr_printscreen ( 0 ) ; /* Print screen "\e[0i" */
break ;
case 5 :
process_print_pipe ( ) ; /* Start printing to print pipe "\e[5i" */
break ;
}
break ;
2001-07-03 18:02:37 -07:00
# endif
2005-04-18 18:57:24 -07:00
case ' m ' :
process_sgr_mode ( nargs , arg ) ;
break ;
case ' n ' : /* request for information */
switch ( arg [ 0 ] ) {
case 5 :
tt_printf ( ( unsigned char * ) " \033 [0n " ) ;
break ; /* ready */
case 6 :
scr_report_position ( ) ;
break ;
1999-08-17 18:12:47 -07:00
# if defined (ENABLE_DISPLAY_ANSWER)
2005-04-18 18:57:24 -07:00
case 7 :
tt_write ( ( unsigned char * ) display_name , strlen ( display_name ) ) ;
tt_write ( " \n " , 1 ) ;
break ;
1999-08-17 18:12:47 -07:00
# endif
2005-04-18 18:57:24 -07:00
case 8 :
xterm_seq ( ESCSEQ_XTERM_TITLE , APL_NAME " - " VERSION ) ;
break ;
case 9 :
1999-08-17 18:12:47 -07:00
# ifdef PIXMAP_OFFSET
2005-04-18 18:57:24 -07:00
if ( image_mode_is ( image_bg , MODE_TRANS ) ) {
char tbuff [ 70 ] ;
char shading = 0 ;
unsigned long tint = 0xffffff ;
2002-05-04 07:25:30 -07:00
2005-04-18 18:57:24 -07:00
if ( images [ image_bg ] . current - > iml - > mod ) {
shading = images [ image_bg ] . current - > iml - > mod - > brightness / 0xff * 100 ;
}
if ( images [ image_bg ] . current - > iml - > rmod ) {
tint = ( tint & 0x00ffff ) | ( ( images [ image_bg ] . current - > iml - > rmod - > brightness & 0xff ) < < 16 ) ;
}
if ( images [ image_bg ] . current - > iml - > gmod ) {
tint = ( tint & 0xff00ff ) | ( ( images [ image_bg ] . current - > iml - > gmod - > brightness & 0xff ) < < 8 ) ;
}
if ( images [ image_bg ] . current - > iml - > bmod ) {
tint = ( tint & 0xffff00 ) | ( images [ image_bg ] . current - > iml - > bmod - > brightness & 0xff ) ;
}
snprintf ( tbuff , sizeof ( tbuff ) , APL_NAME " - " VERSION " : Transparent - %d%% shading - 0x%06lx tint mask " ,
shading , tint ) ;
xterm_seq ( ESCSEQ_XTERM_TITLE , tbuff ) ;
} else
1999-08-17 18:12:47 -07:00
# endif
# ifdef PIXMAP_SUPPORT
2005-04-18 18:57:24 -07:00
{
char * tbuff ;
unsigned short len ;
if ( background_is_pixmap ( ) ) {
const char * fname ;
imlib_context_set_image ( images [ image_bg ] . current - > iml - > im ) ;
fname = imlib_image_get_filename ( ) ;
len = strlen ( fname ) + sizeof ( APL_NAME ) + sizeof ( VERSION ) + 5 ;
tbuff = MALLOC ( len ) ;
snprintf ( tbuff , len , APL_NAME " - " VERSION " : %s " , fname ) ;
xterm_seq ( ESCSEQ_XTERM_TITLE , tbuff ) ;
FREE ( tbuff ) ;
} else {
xterm_seq ( ESCSEQ_XTERM_TITLE , APL_NAME " - " VERSION " : No Pixmap " ) ;
}
2002-05-04 07:25:30 -07:00
}
1999-08-17 18:12:47 -07:00
# endif /* PIXMAP_SUPPORT */
2005-04-18 18:57:24 -07:00
break ;
}
break ;
case ' r ' : /* set top and bottom margins */
if ( priv ! = ' ? ' ) {
if ( nargs < 2 | | arg [ 0 ] > = arg [ 1 ] )
scr_scroll_region ( 0 , 10000 ) ;
else
scr_scroll_region ( arg [ 0 ] - 1 , arg [ 1 ] - 1 ) ;
break ;
}
/* drop */
case ' t ' :
if ( priv ! = ' ? ' ) {
process_window_mode ( nargs , arg ) ;
2002-05-04 07:25:30 -07:00
break ;
2005-04-18 18:57:24 -07:00
}
/* drop */
case ' s ' :
if ( ch = = ' s ' & & ! nargs ) {
scr_cursor ( SAVE ) ;
break ;
}
/* drop */
case ' h ' :
case ' l ' :
process_terminal_mode ( ch , priv , nargs , arg ) ;
break ;
case ' u ' :
if ( ! nargs ) {
scr_cursor ( RESTORE ) ;
}
break ;
2002-05-04 07:25:30 -07:00
}
1999-08-17 18:12:47 -07:00
}
/* process xterm text parameters sequences `ESC ] Ps ; Pt BEL' */
void
process_xterm_seq ( void )
{
2002-05-04 07:25:30 -07:00
unsigned char ch , string [ STRING_MAX ] ;
int arg ;
1999-08-17 18:12:47 -07:00
ch = cmd_getc ( ) ;
2002-05-04 07:25:30 -07:00
if ( isdigit ( ch ) ) {
for ( arg = 0 ; isdigit ( ch ) ; ch = cmd_getc ( ) ) {
arg = arg * 10 + ( ch - ' 0 ' ) ;
}
} else if ( ch = = ' ; ' ) {
arg = 0 ;
} else {
arg = ch ;
ch = cmd_getc ( ) ;
1999-08-17 18:12:47 -07:00
}
2002-05-04 07:25:30 -07:00
if ( arg = = ' R ' ) {
stored_palette ( RESTORE ) ;
redraw_image ( image_bg ) ;
set_colorfgbg ( ) ;
scr_touch ( ) ;
scr_refresh ( DEFAULT_REFRESH ) ;
return ;
} else if ( arg = = ' P ' ) {
unsigned char i , idx ;
idx = ( ( ch < = ' 9 ' ) ? ( ch - ' 0 ' ) : ( tolower ( ch ) - ' a ' + 10 ) ) + minColor ;
string [ 0 ] = ' # ' ;
string [ 7 ] = 0 ;
for ( i = 1 ; i < 7 ; i + + ) {
string [ i ] = cmd_getc ( ) ;
}
set_window_color ( idx , string ) ;
return ;
} else if ( ch = = ' ; ' ) {
unsigned long n = 0 ;
while ( ( ch = cmd_getc ( ) ) ! = 007 ) {
if ( ch ) {
if ( ch = = ' \t ' )
ch = ' ' ; /* translate '\t' to space */
2005-04-18 15:04:07 -07:00
else if ( ch < ' ' ) {
2005-04-18 18:57:24 -07:00
if ( ch = = 27 & & ( ch = cmd_getc ( ) ) = = ' \\ ' ) /* ESC \ (ST) is String Terminator in Xterm */
break ;
2002-05-04 07:25:30 -07:00
return ; /* control character - exit */
2005-04-18 18:57:24 -07:00
}
2002-05-04 07:25:30 -07:00
if ( n < sizeof ( string ) - 1 )
string [ n + + ] = ch ;
}
}
string [ n ] = ' \0 ' ;
xterm_seq ( arg , ( char * ) string ) ;
1999-08-17 18:12:47 -07:00
2002-05-04 07:25:30 -07:00
} else {
unsigned long n = 0 ;
for ( ; ch ! = ' \033 ' ; ch = cmd_getc ( ) ) {
if ( ch ) {
if ( ch = = ' \t ' )
ch = ' ' ; /* translate '\t' to space */
else if ( ch < ' ' )
return ; /* control character - exit */
if ( n < sizeof ( string ) - 1 )
string [ n + + ] = ch ;
}
}
string [ n ] = ' \0 ' ;
if ( ( ch = cmd_getc ( ) ) ! = ' \\ ' ) {
return ;
}
switch ( arg ) {
2005-04-18 18:57:24 -07:00
case ' l ' :
xterm_seq ( ESCSEQ_XTERM_TITLE , ( char * ) string ) ;
break ;
case ' L ' :
xterm_seq ( ESCSEQ_XTERM_ICONNAME , ( char * ) string ) ;
break ;
case ' I ' :
set_icon_pixmap ( ( char * ) string , NULL ) ;
break ;
default :
break ;
2002-05-04 07:25:30 -07:00
}
1999-08-17 18:12:47 -07:00
}
}
/* Process window manipulations */
void
process_window_mode ( unsigned int nargs , int args [ ] )
{
2003-02-24 17:59:53 -08:00
2002-05-04 07:25:30 -07:00
register unsigned int i ;
int x , y ;
Screen * scr ;
Window dummy_child ;
int dummy_x , dummy_y ;
unsigned int dummy_border , dummy_depth ;
2004-07-14 13:18:30 -07:00
char buff [ 1024 ] ;
2005-04-18 18:57:24 -07:00
2004-07-14 13:18:30 -07:00
# ifdef ENABLE_NAME_REPORTING_ESCAPES
char * name ;
# endif
2002-05-04 07:25:30 -07:00
if ( ! nargs )
return ;
scr = ScreenOfDisplay ( Xdisplay , Xscreen ) ;
if ( ! scr )
return ;
for ( i = 0 ; i < nargs ; i + + ) {
switch ( args [ i ] ) {
2005-04-18 18:57:24 -07:00
case 1 :
XMapRaised ( Xdisplay , TermWin . parent ) ;
break ;
case 2 :
XIconifyWindow ( Xdisplay , TermWin . parent , Xscreen ) ;
break ;
case 3 :
if ( i + 2 > = nargs )
return ; /* Make sure there are 2 args left */
x = args [ + + i ] ;
y = args [ + + i ] ;
if ( ( ( unsigned int ) x > ( unsigned int ) scr - > width ) | | ( ( unsigned int ) y > ( unsigned int ) scr - > height ) )
return ; /* Don't move off-screen */
XMoveWindow ( Xdisplay , TermWin . parent , x , y ) ;
break ;
case 4 :
if ( i + 2 > = nargs )
return ; /* Make sure there are 2 args left */
y = args [ + + i ] ;
x = args [ + + i ] ;
BOUND ( y , szHint . min_height , scr - > height ) ;
BOUND ( x , szHint . min_width , scr - > width ) ;
XResizeWindow ( Xdisplay , TermWin . parent , x , y ) ;
break ;
case 5 :
XRaiseWindow ( Xdisplay , TermWin . parent ) ;
break ;
case 6 :
XLowerWindow ( Xdisplay , TermWin . parent ) ;
break ;
case 7 :
XClearWindow ( Xdisplay , TermWin . vt ) ;
XSync ( Xdisplay , False ) ;
scr_touch ( ) ;
scr_refresh ( DEFAULT_REFRESH ) ;
break ;
case 8 :
if ( i + 2 > = nargs )
return ; /* Make sure there are 2 args left */
y = args [ + + i ] ;
x = args [ + + i ] ;
BOUND ( y , 1 , scr - > height / TermWin . fheight ) ;
BOUND ( x , 1 , scr - > width / TermWin . fwidth ) ;
XResizeWindow ( Xdisplay , TermWin . parent ,
Width2Pixel ( x ) + 2 * TermWin . internalBorder + ( scrollbar_is_visible ( ) ? scrollbar_trough_width ( ) : 0 ) ,
Height2Pixel ( y ) + 2 * TermWin . internalBorder ) ;
break ;
case 11 :
break ;
case 13 :
XTranslateCoordinates ( Xdisplay , TermWin . parent , Xroot , 0 , 0 , & x , & y , & dummy_child ) ;
snprintf ( buff , sizeof ( buff ) , " \033 [3;%d;%dt " , x , y ) ;
tt_write ( ( unsigned char * ) buff , strlen ( buff ) ) ;
break ;
case 14 :
/* Store current width and height in x and y */
XGetGeometry ( Xdisplay , TermWin . parent , & dummy_child , & dummy_x , & dummy_y , ( unsigned int * ) ( & x ) ,
( unsigned int * ) ( & y ) , & dummy_border , & dummy_depth ) ;
snprintf ( buff , sizeof ( buff ) , " \033 [4;%d;%dt " , y , x ) ;
tt_write ( ( unsigned char * ) buff , strlen ( buff ) ) ;
break ;
case 18 :
snprintf ( buff , sizeof ( buff ) , " \033 [8;%d;%dt " , TERM_WINDOW_GET_REPORTED_ROWS ( ) , TERM_WINDOW_GET_REPORTED_COLS ( ) ) ;
tt_write ( ( unsigned char * ) buff , strlen ( buff ) ) ;
break ;
2004-04-20 12:41:38 -07:00
# ifdef ENABLE_NAME_REPORTING_ESCAPES
2005-04-18 18:57:24 -07:00
case 20 :
XGetIconName ( Xdisplay , TermWin . parent , & name ) ;
snprintf ( buff , sizeof ( buff ) , " \033 ]L%s \033 \\ " , name ) ;
tt_write ( ( unsigned char * ) buff , strlen ( buff ) ) ;
XFree ( name ) ;
break ;
case 21 :
XFetchName ( Xdisplay , TermWin . parent , & name ) ;
snprintf ( buff , sizeof ( buff ) , " \033 ]l%s \033 \\ " , name ) ;
tt_write ( ( unsigned char * ) buff , strlen ( buff ) ) ;
XFree ( name ) ;
break ;
2004-04-20 12:41:38 -07:00
# endif
2005-04-18 18:57:24 -07:00
default :
break ;
2002-05-04 07:25:30 -07:00
}
1999-08-17 18:12:47 -07:00
}
}
/* process DEC private mode sequences `ESC [ ? Ps mode' */
/*
* mode can only have the following values :
* ' l ' = low
* ' h ' = high
* ' s ' = save
* ' r ' = restore
* ' t ' = toggle
*/
void
process_terminal_mode ( int mode , int priv , unsigned int nargs , int arg [ ] )
{
2002-05-04 07:25:30 -07:00
unsigned int i ;
int state ; /* This gets set by the PrivCases macro */
if ( nargs = = 0 )
return ;
/* make lo/hi boolean */
switch ( mode ) {
2005-04-18 18:57:24 -07:00
case ' l ' :
mode = 0 ;
break ;
case ' h ' :
mode = 1 ;
break ;
2002-05-04 07:25:30 -07:00
}
switch ( priv ) {
2005-04-18 18:57:24 -07:00
case 0 :
if ( mode & & mode ! = 1 )
return ; /* only do high/low */
for ( i = 0 ; i < nargs ; i + + )
switch ( arg [ i ] ) {
case 4 :
scr_insert_mode ( mode ) ;
break ;
/* case 38: TEK mode */
}
break ;
2002-05-04 07:25:30 -07:00
2005-04-18 18:57:24 -07:00
case ' ? ' :
for ( i = 0 ; i < nargs ; i + + )
switch ( arg [ i ] ) {
case 1 : /* application cursor keys */
PrivCases ( PrivMode_aplCUR ) ;
break ;
2002-05-04 07:25:30 -07:00
2005-04-18 18:57:24 -07:00
/* case 2: - reset charsets to USASCII */
2002-05-04 07:25:30 -07:00
2005-04-18 18:57:24 -07:00
case 3 : /* 80/132 */
PrivCases ( PrivMode_132 ) ;
if ( PrivateModes & PrivMode_132OK )
set_width ( state ? 132 : 80 ) ;
break ;
2002-05-04 07:25:30 -07:00
2005-04-18 18:57:24 -07:00
/* case 4: - smooth scrolling */
2002-05-04 07:25:30 -07:00
2005-04-18 18:57:24 -07:00
case 5 : /* reverse video */
PrivCases ( PrivMode_rVideo ) ;
scr_rvideo_mode ( state ) ;
break ;
2002-05-04 07:25:30 -07:00
2005-04-18 18:57:24 -07:00
case 6 : /* relative/absolute origins */
PrivCases ( PrivMode_relOrigin ) ;
scr_relative_origin ( state ) ;
break ;
2002-05-04 07:25:30 -07:00
2005-04-18 18:57:24 -07:00
case 7 : /* autowrap */
PrivCases ( PrivMode_Autowrap ) ;
scr_autowrap ( state ) ;
break ;
2002-05-04 07:25:30 -07:00
2005-04-18 18:57:24 -07:00
/* case 8: - auto repeat, can't do on a per window basis */
2002-05-04 07:25:30 -07:00
2005-04-18 18:57:24 -07:00
case 9 : /* X10 mouse reporting */
PrivCases ( PrivMode_MouseX10 ) ;
/* orthogonal */
if ( PrivateModes & PrivMode_MouseX10 )
PrivateModes & = ~ ( PrivMode_MouseX11 ) ;
break ;
2002-05-04 07:25:30 -07:00
2005-04-18 18:57:24 -07:00
case 25 : /* visible/invisible cursor */
PrivCases ( PrivMode_VisibleCursor ) ;
scr_cursor_visible ( state ) ;
break ;
2002-05-04 07:25:30 -07:00
2005-04-18 18:57:24 -07:00
case 30 :
PrivCases ( PrivMode_scrollbar ) ;
map_scrollbar ( state ) ;
break ;
2002-05-04 07:25:30 -07:00
2005-04-18 18:57:24 -07:00
case 35 :
PrivCases ( PrivMode_ShiftKeys ) ;
break ;
2002-05-04 07:25:30 -07:00
2005-04-18 18:57:24 -07:00
case 40 : /* 80 <--> 132 mode */
PrivCases ( PrivMode_132OK ) ;
break ;
2002-05-04 07:25:30 -07:00
2005-04-18 18:57:24 -07:00
case 47 : /* secondary screen */
PrivCases ( PrivMode_Screen ) ;
scr_change_screen ( state ) ;
break ;
2002-05-04 07:25:30 -07:00
2005-04-18 18:57:24 -07:00
case 66 : /* application key pad */
PrivCases ( PrivMode_aplKP ) ;
break ;
2002-05-04 07:25:30 -07:00
2005-04-18 18:57:24 -07:00
case 67 :
PrivCases ( PrivMode_BackSpace ) ;
break ;
case 1000 : /* X11 mouse reporting */
PrivCases ( PrivMode_MouseX11 ) ;
/* orthogonal */
if ( PrivateModes & PrivMode_MouseX11 )
PrivateModes & = ~ ( PrivMode_MouseX10 ) ;
break ;
1999-08-17 18:12:47 -07:00
#if 0
2005-04-18 18:57:24 -07:00
case 1001 :
break ; /* X11 mouse highlighting */
1999-08-17 18:12:47 -07:00
# endif
2002-06-02 17:24:22 -07:00
2005-04-18 18:57:24 -07:00
case 1010 : /* Scroll to bottom on TTY output */
if ( BITFIELD_IS_SET ( vt_options , VT_OPTIONS_HOME_ON_OUTPUT ) )
BITFIELD_CLEAR ( vt_options , VT_OPTIONS_HOME_ON_OUTPUT ) ;
else
BITFIELD_SET ( vt_options , VT_OPTIONS_HOME_ON_OUTPUT ) ;
break ;
case 1012 : /* Scroll to bottom on TTY input */
if ( BITFIELD_IS_SET ( vt_options , VT_OPTIONS_HOME_ON_INPUT ) )
BITFIELD_CLEAR ( vt_options , VT_OPTIONS_HOME_ON_INPUT ) ;
else
BITFIELD_SET ( vt_options , VT_OPTIONS_HOME_ON_INPUT ) ;
break ;
2002-05-04 07:25:30 -07:00
2005-04-18 18:57:24 -07:00
case 1047 : /* Alternate screen & clear */
PrivCases ( PrivMode_Screen ) ;
if ( ! state ) {
/* Only clear the screen before switching from
secondary to primary . */
scr_erase_screen ( 2 ) ;
}
scr_change_screen ( state ) ;
break ;
case 1048 : /* Save/restore cursor pos */
PrivCases ( PrivMode_Screen ) ;
scr_cursor ( state ? SAVE : RESTORE ) ;
break ;
case 1049 : /* Alternate screen & cursor */
PrivCases ( PrivMode_Screen ) ;
scr_cursor ( state ? SAVE : RESTORE ) ;
if ( ! state ) {
/* Only clear the screen before switching from
secondary to primary . */
scr_erase_screen ( 2 ) ;
}
scr_change_screen ( state ) ;
break ;
}
break ;
2002-05-04 07:25:30 -07:00
}
1999-08-17 18:12:47 -07:00
}
/* process sgr sequences */
void
process_sgr_mode ( unsigned int nargs , int arg [ ] )
{
2002-05-04 07:25:30 -07:00
unsigned int i ;
if ( nargs = = 0 ) {
scr_rendition ( 0 , ~ RS_None ) ;
return ;
1999-08-17 18:12:47 -07:00
}
2002-05-04 07:25:30 -07:00
for ( i = 0 ; i < nargs ; i + + )
switch ( arg [ i ] ) {
2005-04-18 18:57:24 -07:00
case 0 :
scr_rendition ( 0 , ~ RS_None ) ;
break ;
case 1 :
scr_rendition ( 1 , RS_Bold ) ;
break ;
case 2 :
scr_rendition ( 1 , RS_Dim ) ;
break ;
case 3 :
scr_rendition ( 1 , RS_Italic ) ;
break ;
case 4 :
scr_rendition ( 1 , RS_Uline ) ;
break ;
case 5 :
scr_rendition ( 1 , RS_Blink ) ;
break ;
case 6 :
scr_rendition ( 1 , RS_Overscore ) ;
break ;
case 7 :
scr_rendition ( 1 , RS_RVid ) ;
break ;
case 8 :
scr_rendition ( 1 , RS_Conceal ) ;
break ;
case 22 :
scr_rendition ( 0 , RS_Bold ) ;
scr_rendition ( 0 , RS_Dim ) ;
break ;
case 24 :
scr_rendition ( 0 , RS_Uline ) ;
break ;
case 25 :
scr_rendition ( 0 , RS_Blink ) ;
scr_rendition ( 0 , RS_Overscore ) ;
break ;
case 27 :
scr_rendition ( 0 , RS_RVid ) ;
break ;
/* set fg color */
case 30 :
case 31 :
case 32 :
case 33 :
case 34 :
case 35 :
case 36 :
case 37 :
scr_color ( minColor + ( arg [ i ] - 30 ) , RS_Bold ) ;
break ;
case 38 :
if ( arg [ i + 1 ] = = 5 ) {
i + = 2 ;
if ( arg [ i ] > = 0 & & arg [ i ] < 256 )
scr_color ( arg [ i ] , RS_Bold ) ;
}
break ;
/* default fg */
case 39 :
scr_color ( restoreFG , RS_Bold ) ;
break ;
/* set bg color */
case 40 :
case 41 :
case 42 :
case 43 :
case 44 :
case 45 :
case 46 :
case 47 :
scr_color ( minColor + ( arg [ i ] - 40 ) , RS_Blink ) ;
break ;
case 48 :
if ( arg [ i + 1 ] = = 5 ) {
i + = 2 ;
if ( arg [ i ] > = 0 & & arg [ i ] < 256 )
scr_color ( arg [ i ] , RS_Blink ) ;
}
break ;
/* default bg */
case 49 :
scr_color ( restoreBG , RS_Blink ) ;
break ;
/* set fg color - bright */
case 90 :
case 91 :
case 92 :
case 93 :
case 94 :
case 95 :
case 96 :
case 97 :
scr_color ( minBright + ( arg [ i ] - 90 ) , RS_Bold ) ;
break ;
/* default fg */
case 99 :
scr_color ( restoreFG , RS_Bold ) ;
break ;
/* set bg color - bright */
case 100 :
case 101 :
case 102 :
case 103 :
case 104 :
case 105 :
case 106 :
case 107 :
scr_color ( minBright + ( arg [ i ] - 100 ) , RS_Blink ) ;
break ;
/* default bg */
case 109 :
scr_color ( restoreBG , RS_Blink ) ;
break ;
2003-07-29 19:50:13 -07:00
2002-05-04 07:25:30 -07:00
}
1999-08-17 18:12:47 -07:00
}
/* find if fg/bg matches any of the normal (low-intensity) colors */
void
set_colorfgbg ( void )
{
2002-05-04 07:25:30 -07:00
unsigned int i ;
static char * colorfgbg_env = NULL ;
char * p ;
int fg = - 1 , bg = - 1 ;
if ( ! colorfgbg_env ) {
colorfgbg_env = ( char * ) MALLOC ( 30 ) ;
strcpy ( colorfgbg_env , " COLORFGBG=default;default;bg " ) ;
}
for ( i = BlackColor ; i < = WhiteColor ; i + + ) {
if ( PixColors [ fgColor ] = = PixColors [ i ] ) {
fg = ( i - BlackColor ) ;
break ;
}
1999-08-17 18:12:47 -07:00
}
2002-05-04 07:25:30 -07:00
for ( i = BlackColor ; i < = WhiteColor ; i + + ) {
if ( PixColors [ bgColor ] = = PixColors [ i ] ) {
bg = ( i - BlackColor ) ;
break ;
}
1999-08-17 18:12:47 -07:00
}
2002-05-04 07:25:30 -07:00
p = strchr ( colorfgbg_env , ' = ' ) ;
p + + ;
if ( fg > = 0 )
sprintf ( p , " %d; " , fg ) ;
else
strcpy ( p , " default; " ) ;
p = strchr ( p , ' \0 ' ) ;
if ( bg > = 0 )
sprintf ( p ,
1999-08-17 18:12:47 -07:00
# ifdef PIXMAP_SUPPORT
2002-05-04 07:25:30 -07:00
" default; "
1999-08-17 18:12:47 -07:00
# endif
2002-05-04 07:25:30 -07:00
" %d " , bg ) ;
else
strcpy ( p , " default " ) ;
putenv ( colorfgbg_env ) ;
colorfgbg = DEFAULT_RSTYLE ;
for ( i = minColor ; i < = maxColor ; i + + ) {
if ( PixColors [ fgColor ] = = PixColors [ i ]
1999-08-17 18:12:47 -07:00
# ifndef NO_BOLDUNDERLINE
2002-05-04 07:25:30 -07:00
& & PixColors [ fgColor ] = = PixColors [ colorBD ]
# endif /* NO_BOLDUNDERLINE */
/* if we wanted boldFont to have precedence */
# if 0 /* ifndef NO_BOLDFONT */
& & TermWin . boldFont = = NULL
# endif /* NO_BOLDFONT */
)
colorfgbg = SET_FGCOLOR ( colorfgbg , i ) ;
if ( PixColors [ bgColor ] = = PixColors [ i ] )
colorfgbg = SET_BGCOLOR ( colorfgbg , i ) ;
}
1999-08-17 18:12:47 -07:00
}
2000-05-31 22:24:47 -07:00
void
1999-08-17 18:12:47 -07:00
set_title ( const char * str )
{
2002-05-04 07:25:30 -07:00
static char * name = NULL ;
1999-08-17 18:12:47 -07:00
2002-05-04 07:25:30 -07:00
if ( ! str ) {
str = APL_NAME " - " VERSION ;
}
if ( name = = NULL | | strcmp ( name , str ) ) {
if ( name ! = NULL ) {
FREE ( name ) ;
}
2003-02-24 17:59:53 -08:00
D_X11 ( ( " Setting window title to \" %s \" \n " , str ) ) ;
XStoreName ( Xdisplay , TermWin . parent , str ) ;
name = STRDUP ( str ) ;
1999-12-28 02:05:43 -08:00
}
1999-08-17 18:12:47 -07:00
}
2000-05-31 22:24:47 -07:00
void
1999-10-11 11:37:55 -07:00
set_icon_name ( const char * str )
1999-08-17 18:12:47 -07:00
{
2002-05-04 07:25:30 -07:00
static char * name = NULL ;
if ( ! str )
str = APL_NAME " - " VERSION ;
if ( name = = NULL | | strcmp ( name , str ) ) {
if ( name ! = NULL ) {
FREE ( name ) ;
}
2003-02-24 17:59:53 -08:00
D_X11 ( ( " Setting window icon name to \" %s \" \n " , str ) ) ;
XSetIconName ( Xdisplay , TermWin . parent , str ) ;
name = STRDUP ( str ) ;
1999-12-28 02:05:43 -08:00
}
1999-08-17 18:12:47 -07:00
}
2000-05-31 22:24:47 -07:00
void
append_to_title ( const char * str )
{
2002-05-04 07:25:30 -07:00
char * name , * buff ;
2010-08-23 10:55:09 -07:00
REQUIRE ( str ! = NULL ) ;
2002-05-04 07:25:30 -07:00
XFetchName ( Xdisplay , TermWin . parent , & name ) ;
2010-08-25 18:34:13 -07:00
if ( name ) {
2002-05-04 07:25:30 -07:00
buff = ( char * ) MALLOC ( strlen ( name ) + strlen ( str ) + 1 ) ;
strcpy ( buff , name ) ;
strcat ( buff , str ) ;
set_title ( buff ) ;
FREE ( buff ) ;
}
2000-05-31 22:24:47 -07:00
}
void
append_to_icon_name ( const char * str )
{
2002-05-04 07:25:30 -07:00
char * name , * buff ;
2010-08-23 10:55:09 -07:00
REQUIRE ( str ! = NULL ) ;
2002-05-04 07:25:30 -07:00
XGetIconName ( Xdisplay , TermWin . parent , & name ) ;
2010-08-25 18:34:13 -07:00
if ( name ) {
2002-05-04 07:25:30 -07:00
buff = ( char * ) MALLOC ( strlen ( name ) + strlen ( str ) + 1 ) ;
strcpy ( buff , name ) ;
strcat ( buff , str ) ;
set_icon_name ( buff ) ;
FREE ( buff ) ;
}
2000-05-31 22:24:47 -07:00
}
1999-08-17 18:12:47 -07:00
/*
* XTerm escape sequences : ESC ] Ps ; Pt BEL
2001-07-03 18:02:37 -07:00
* 0 = change icon name and window title
* 1 = change icon name
1999-08-17 18:12:47 -07:00
* 2 = change title
2001-07-03 18:02:37 -07:00
* 3 = set text property on window
2005-04-18 15:04:07 -07:00
* 4 = set any of 256 colors
1999-08-17 18:12:47 -07:00
* 46 = change logfile ( not implemented )
* 50 = change font
*
* rxvt / Eterm extensions :
* 5 = Hostile takeover ( grab focus and raise )
* 6 = Transparency mode stuff
* 10 = menu
* 20 = bg pixmap
* 39 = change default fg color
* 49 = change default bg color
*/
void
xterm_seq ( int op , const char * str )
{
2002-05-04 07:25:30 -07:00
XColor xcol ;
char * nstr , * tnstr , * valptr ;
unsigned char eterm_seq_op ;
2005-04-18 15:04:07 -07:00
unsigned int i ;
2002-05-04 07:25:30 -07:00
XWMHints * wm_hints ;
2002-06-02 17:24:22 -07:00
1999-08-17 18:12:47 -07:00
# ifdef PIXMAP_SUPPORT
2002-05-04 07:25:30 -07:00
unsigned char changed = 0 , scaled = 0 , which = 0 ;
char * color , * mod , * orig_tnstr ;
1999-08-17 18:12:47 -07:00
# endif
2002-05-04 07:25:30 -07:00
if ( ! str )
return ;
1999-08-17 18:12:47 -07:00
2002-05-04 07:25:30 -07:00
tnstr = STRDUP ( str ) ;
1999-08-17 18:12:47 -07:00
# ifdef PIXMAP_SUPPORT
2002-05-04 07:25:30 -07:00
orig_tnstr = tnstr ;
1999-08-17 18:12:47 -07:00
# endif
2002-05-04 07:25:30 -07:00
switch ( op ) {
2005-04-18 18:57:24 -07:00
case ESCSEQ_XTERM_NAME : /* 0 */
set_title ( str ) ; /* drop */
case ESCSEQ_XTERM_ICONNAME : /* 1 */
set_icon_name ( str ) ;
break ;
case ESCSEQ_XTERM_TITLE : /* 2 */
set_title ( str ) ;
break ;
case ESCSEQ_XTERM_PROP : /* 3 */
2010-08-25 18:34:13 -07:00
if ( ! ( nstr = ( char * ) strsep ( & tnstr , " ; " ) ) ) {
2005-04-18 18:57:24 -07:00
break ;
}
2010-08-25 18:34:13 -07:00
if ( ( valptr = strchr ( nstr , ' = ' ) ) ) {
2005-04-18 18:57:24 -07:00
* ( valptr + + ) = 0 ;
}
set_text_property ( TermWin . parent , nstr , valptr ) ;
break ;
case ESCSEQ_XTERM_CHANGE_COLOR : /* Changing existing colors 256 */
2010-08-25 18:34:13 -07:00
while ( ( nstr = ( char * ) strsep ( & tnstr , " ; " ) ) ) {
2005-04-18 18:57:24 -07:00
i = ( unsigned int ) strtoul ( nstr , ( char * * ) NULL , 0 ) ;
2002-05-13 16:19:30 -07:00
nstr = ( char * ) strsep ( & tnstr , " ; " ) ;
2010-08-25 18:34:13 -07:00
if ( ( i < 256 ) & & ( nstr ) ) {
2005-04-18 18:57:24 -07:00
D_COLORS ( ( " Changing color : [%d] -> %s \n " , i , nstr ) ) ;
set_window_color ( i , nstr ) ;
}
}
break ;
case ESCSEQ_XTERM_TAKEOVER : /* 5 */
XSetInputFocus ( Xdisplay , TermWin . parent , RevertToParent , CurrentTime ) ;
XRaiseWindow ( Xdisplay , TermWin . parent ) ;
break ;
case ESCSEQ_XTERM_ETERMSEQ : /* 6 */
/* Eterm proprietary escape sequences. See technical reference for details. */
D_CMD ( ( " Got ESCSEQ_XTERM_ETERMSEQ sequence \n " ) ) ;
nstr = ( char * ) strsep ( & tnstr , " ; " ) ;
eterm_seq_op = ( unsigned char ) strtol ( nstr , ( char * * ) NULL , 10 ) ;
D_CMD ( ( " ESCSEQ_XTERM_ETERMSEQ operation is %d \n " , eterm_seq_op ) ) ;
/* Yes, there is order to the numbers for this stuff. And here it is:
0 - 9 Image Class / Mode Configuration
10 - 19 Scrollbar / Buttonbar / Menu Configuration
20 - 39 Miscellaneous Toggles
40 - 49 Foreground / Background Color Configuration
50 - 69 Window / Window Manager Configuration / Interaction
70 + Internal Eterm Operations
*/
switch ( eterm_seq_op ) {
# ifdef PIXMAP_SUPPORT
case 0 :
nstr = ( char * ) strsep ( & tnstr , " ; " ) ;
if ( nstr ) {
if ( BOOL_OPT_ISTRUE ( nstr ) ) {
D_CMD ( ( " Request to enable transparency. \n " ) ) ;
2002-05-04 07:25:30 -07:00
/* *INDENT-OFF* */
FOREACH_IMAGE (
if ( ! image_mode_is ( idx , MODE_TRANS ) & & image_mode_is ( idx , ALLOW_TRANS ) ) {
image_set_mode ( idx , MODE_TRANS ) ;
if ( images [ idx ] . current - > pmap - > pixmap ! = None ) {
imlib_free_pixmap_and_mask ( images [ idx ] . current - > pmap - > pixmap ) ;
}
images [ idx ] . current - > pmap - > pixmap = None ;
}
) ;
/* *INDENT-ON* */
2005-04-18 18:57:24 -07:00
} else if ( BOOL_OPT_ISFALSE ( nstr ) ) {
D_CMD ( ( " Request to disable transparency. \n " ) ) ;
2002-05-04 07:25:30 -07:00
/* *INDENT-OFF* */
FOREACH_IMAGE (
if ( image_mode_is ( idx , MODE_TRANS ) ) {
if ( image_mode_is ( idx , ALLOW_IMAGE ) ) {
image_set_mode ( idx , MODE_IMAGE ) ;
} else {
image_set_mode ( idx , MODE_SOLID ) ;
}
}
) ;
/* *INDENT-ON* */
2005-04-18 18:57:24 -07:00
} else {
D_CMD ( ( " Bad boolean value in transparency request. \n " ) ) ;
break ;
}
2002-05-13 16:19:30 -07:00
} else {
2005-04-18 18:57:24 -07:00
D_CMD ( ( " Request to toggle transparency. \n " ) ) ;
2002-05-04 07:25:30 -07:00
/* *INDENT-OFF* */
FOREACH_IMAGE (
if ( ! image_mode_is ( idx , MODE_TRANS ) & & image_mode_is ( idx , ALLOW_TRANS ) ) {
image_set_mode ( idx , MODE_TRANS ) ;
if ( images [ idx ] . current - > pmap - > pixmap ! = None ) {
imlib_free_pixmap_and_mask ( images [ idx ] . current - > pmap - > pixmap ) ;
}
images [ idx ] . current - > pmap - > pixmap = None ;
} else if ( image_mode_is ( idx , MODE_TRANS ) ) {
if ( image_mode_is ( idx , ALLOW_IMAGE ) ) {
image_set_mode ( idx , MODE_IMAGE ) ;
} else {
image_set_mode ( idx , MODE_SOLID ) ;
}
}
) ;
/* *INDENT-ON* */
}
2005-04-18 18:57:24 -07:00
redraw_all_images ( ) ;
break ;
case 1 :
changed = 0 ;
for ( ; 1 ; ) {
2010-08-25 18:34:13 -07:00
if ( ! ( color = ( char * ) strsep ( & tnstr , " ; " ) ) ) {
2002-05-04 07:25:30 -07:00
break ;
}
2005-04-18 18:57:24 -07:00
which = image_max ;
FOREACH_IMAGE ( if ( ! strcasecmp ( color , ( get_image_type ( idx ) + 6 ) ) ) {
which = idx ; break ; }
) ;
if ( which ! = image_max ) {
2010-08-25 18:34:13 -07:00
if ( ! ( color = ( char * ) strsep ( & tnstr , " ; " ) ) ) {
2005-04-18 18:57:24 -07:00
break ;
}
} else {
which = image_bg ;
}
2010-08-25 18:34:13 -07:00
if ( ! ( mod = ( char * ) strsep ( & tnstr , " ; " ) ) ) {
2005-04-18 18:57:24 -07:00
break ;
}
if ( ! strcasecmp ( mod , " clear " ) ) {
imlib_t * iml = images [ which ] . current - > iml ;
2002-05-04 07:25:30 -07:00
2005-04-18 18:57:24 -07:00
D_CMD ( ( " Clearing the %s color modifier of the %s image \n " , color , get_image_type ( which ) ) ) ;
if ( ! strcasecmp ( color , " image " ) ) {
FREE ( iml - > mod ) ;
} else if ( ! strcasecmp ( color , " red " ) ) {
FREE ( iml - > rmod ) ;
} else if ( ! strcasecmp ( color , " green " ) ) {
FREE ( iml - > gmod ) ;
} else if ( ! strcasecmp ( color , " blue " ) ) {
FREE ( iml - > bmod ) ;
}
# ifdef PIXMAP_OFFSET
if ( image_mode_is ( which , MODE_TRANS ) & & ( desktop_pixmap ! = None ) ) {
free_desktop_pixmap ( ) ;
} else if ( image_mode_is ( which , MODE_VIEWPORT ) & & ( viewport_pixmap ! = None ) ) {
LIBAST_X_FREE_PIXMAP ( viewport_pixmap ) ;
viewport_pixmap = None ; /* Force the re-read */
}
# endif
changed = 1 ;
continue ;
2002-05-04 07:25:30 -07:00
}
2010-08-25 18:34:13 -07:00
if ( ! ( valptr = ( char * ) strsep ( & tnstr , " ; " ) ) ) {
2005-04-18 18:57:24 -07:00
break ;
}
D_CMD ( ( " Modifying the %s attribute of the %s color modifier of the %s image to be %s \n " ,
mod , color , get_image_type ( which ) , valptr ) ) ;
changed = 1 ;
2000-05-02 16:46:08 -07:00
# ifdef PIXMAP_OFFSET
2002-05-04 07:25:30 -07:00
if ( image_mode_is ( which , MODE_TRANS ) & & ( desktop_pixmap ! = None ) ) {
free_desktop_pixmap ( ) ;
} else if ( image_mode_is ( which , MODE_VIEWPORT ) & & ( viewport_pixmap ! = None ) ) {
LIBAST_X_FREE_PIXMAP ( viewport_pixmap ) ;
2002-06-08 08:44:08 -07:00
viewport_pixmap = None ; /* Force the re-read */
2002-05-04 07:25:30 -07:00
}
2000-05-02 16:46:08 -07:00
# endif
2005-04-18 18:57:24 -07:00
if ( ! strcasecmp ( color , " image " ) ) {
imlib_t * iml = images [ which ] . current - > iml ;
2002-05-04 07:25:30 -07:00
2010-08-25 18:34:13 -07:00
if ( ! iml - > mod ) {
2005-04-18 18:57:24 -07:00
iml - > mod = create_colormod ( ) ;
}
if ( ! BEG_STRCASECMP ( mod , " brightness " ) ) {
iml - > mod - > brightness = ( int ) strtol ( valptr , ( char * * ) NULL , 0 ) ;
} else if ( ! BEG_STRCASECMP ( mod , " contrast " ) ) {
iml - > mod - > contrast = ( int ) strtol ( valptr , ( char * * ) NULL , 0 ) ;
} else if ( ! BEG_STRCASECMP ( mod , " gamma " ) ) {
iml - > mod - > gamma = ( int ) strtol ( valptr , ( char * * ) NULL , 0 ) ;
}
update_cmod ( iml - > mod ) ;
reload_image ( iml ) ;
update_cmod_tables ( iml ) ;
2002-05-04 07:25:30 -07:00
2005-04-18 18:57:24 -07:00
} else if ( ! strcasecmp ( color , " red " ) ) {
imlib_t * iml = images [ which ] . current - > iml ;
2002-05-04 07:25:30 -07:00
2010-08-25 18:34:13 -07:00
if ( ! iml - > rmod ) {
2005-04-18 18:57:24 -07:00
iml - > rmod = create_colormod ( ) ;
}
if ( ! BEG_STRCASECMP ( mod , " brightness " ) ) {
iml - > rmod - > brightness = ( int ) strtol ( valptr , ( char * * ) NULL , 0 ) ;
} else if ( ! BEG_STRCASECMP ( mod , " contrast " ) ) {
iml - > rmod - > contrast = ( int ) strtol ( valptr , ( char * * ) NULL , 0 ) ;
} else if ( ! BEG_STRCASECMP ( mod , " gamma " ) ) {
iml - > rmod - > gamma = ( int ) strtol ( valptr , ( char * * ) NULL , 0 ) ;
}
update_cmod ( iml - > rmod ) ;
reload_image ( iml ) ;
update_cmod_tables ( iml ) ;
2002-05-04 07:25:30 -07:00
2005-04-18 18:57:24 -07:00
} else if ( ! strcasecmp ( color , " green " ) ) {
imlib_t * iml = images [ which ] . current - > iml ;
2002-05-04 07:25:30 -07:00
2010-08-25 18:34:13 -07:00
if ( ! iml - > gmod ) {
2005-04-18 18:57:24 -07:00
iml - > gmod = create_colormod ( ) ;
}
if ( ! BEG_STRCASECMP ( mod , " brightness " ) ) {
iml - > gmod - > brightness = ( int ) strtol ( valptr , ( char * * ) NULL , 0 ) ;
} else if ( ! BEG_STRCASECMP ( mod , " contrast " ) ) {
iml - > gmod - > contrast = ( int ) strtol ( valptr , ( char * * ) NULL , 0 ) ;
} else if ( ! BEG_STRCASECMP ( mod , " gamma " ) ) {
iml - > gmod - > gamma = ( int ) strtol ( valptr , ( char * * ) NULL , 0 ) ;
}
update_cmod ( iml - > gmod ) ;
reload_image ( iml ) ;
update_cmod_tables ( iml ) ;
2002-05-04 07:25:30 -07:00
2005-04-18 18:57:24 -07:00
} else if ( ! strcasecmp ( color , " blue " ) ) {
imlib_t * iml = images [ which ] . current - > iml ;
2002-05-04 07:25:30 -07:00
2010-08-25 18:34:13 -07:00
if ( ! iml - > bmod ) {
2005-04-18 18:57:24 -07:00
iml - > bmod = create_colormod ( ) ;
}
if ( ! BEG_STRCASECMP ( mod , " bright " ) ) {
iml - > bmod - > brightness = ( int ) strtol ( valptr , ( char * * ) NULL , 0 ) ;
} else if ( ! BEG_STRCASECMP ( mod , " contrast " ) ) {
iml - > bmod - > contrast = ( int ) strtol ( valptr , ( char * * ) NULL , 0 ) ;
} else if ( ! BEG_STRCASECMP ( mod , " gamma " ) ) {
iml - > bmod - > gamma = ( int ) strtol ( valptr , ( char * * ) NULL , 0 ) ;
}
update_cmod ( iml - > bmod ) ;
reload_image ( iml ) ;
update_cmod_tables ( iml ) ;
2002-05-04 07:25:30 -07:00
}
}
2005-04-18 18:57:24 -07:00
if ( changed ) {
redraw_all_images ( ) ;
}
2002-05-04 07:25:30 -07:00
break ;
2005-04-18 18:57:24 -07:00
case 2 :
changed = 0 ;
which = image_max ;
2010-08-25 18:34:13 -07:00
if ( ! ( nstr = ( char * ) strsep ( & tnstr , " ; " ) ) | | ! ( valptr = ( char * ) strsep ( & tnstr , " ; " ) ) ) {
2002-05-04 07:25:30 -07:00
break ;
}
2005-04-18 18:57:24 -07:00
FOREACH_IMAGE ( if ( ! strcasecmp ( valptr , ( get_image_type ( idx ) + 6 ) ) ) {
which = idx ; break ; }
) ;
if ( which ! = image_max ) {
2010-08-25 18:34:13 -07:00
if ( ! ( valptr = ( char * ) strsep ( & tnstr , " ; " ) ) ) {
2005-04-18 18:57:24 -07:00
break ;
2002-05-04 07:25:30 -07:00
}
} else {
2005-04-18 18:57:24 -07:00
which = image_bg ;
2002-05-04 07:25:30 -07:00
}
2005-04-18 18:57:24 -07:00
D_PIXMAP ( ( " Operation == \" %s \" , which == %d, value == \" %s \" \n " , nstr , ( int ) which , valptr ) ) ;
if ( ! strcasecmp ( nstr , " shade " ) ) {
imlib_t * iml = images [ which ] . current - > iml ;
int s ;
s = ( int ) strtol ( valptr , ( char * * ) NULL , 0 ) ;
s = ( ( 100 - s ) < < 8 ) / 100 ;
if ( s = = 0x100 ) {
2010-08-25 18:34:13 -07:00
if ( iml - > mod ) {
2005-04-18 18:57:24 -07:00
if ( iml - > mod - > brightness ! = 0x100 ) {
iml - > mod - > brightness = 0x100 ;
changed = 1 ;
}
if ( iml - > mod - > contrast = = 0x100 & & iml - > mod - > gamma = = 0x100 ) {
FREE ( iml - > mod ) ;
2002-05-04 07:25:30 -07:00
}
}
2005-04-18 18:57:24 -07:00
} else {
2010-08-25 18:34:13 -07:00
if ( ! iml - > mod ) {
2005-04-18 18:57:24 -07:00
iml - > mod = create_colormod ( ) ;
}
if ( iml - > mod - > brightness ! = s ) {
iml - > mod - > brightness = s ;
2002-05-04 07:25:30 -07:00
changed = 1 ;
}
}
2005-04-18 18:57:24 -07:00
} else if ( ! strcasecmp ( nstr , " tint " ) ) {
imlib_t * iml = images [ which ] . current - > iml ;
unsigned long t , r , g , b ;
if ( ! isdigit ( * valptr ) ) {
t = get_tint_by_color_name ( valptr ) ;
} else {
t = ( unsigned long ) strtoul ( valptr , ( char * * ) NULL , 0 ) ;
D_PIXMAP ( ( " Got numerical tint 0x%06x \n " , t ) ) ;
2002-05-04 07:25:30 -07:00
}
2005-04-18 18:57:24 -07:00
r = ( t & 0xff0000 ) > > 16 ;
if ( r = = 0xff ) {
2010-08-25 18:34:13 -07:00
if ( iml - > rmod ) {
2005-04-18 18:57:24 -07:00
if ( iml - > rmod - > brightness ! = 0x100 ) {
iml - > rmod - > brightness = 0x100 ;
changed = 1 ;
if ( iml - > rmod - > contrast = = 0x100 & & iml - > rmod - > gamma = = 0x100 ) {
FREE ( iml - > rmod ) ;
}
2002-05-04 07:25:30 -07:00
}
}
2005-04-18 18:57:24 -07:00
} else {
2010-08-25 18:34:13 -07:00
if ( ! iml - > rmod ) {
2005-04-18 18:57:24 -07:00
iml - > rmod = create_colormod ( ) ;
}
if ( iml - > rmod - > brightness ! = ( int ) r ) {
iml - > rmod - > brightness = r ;
changed = 1 ;
}
2002-05-04 07:25:30 -07:00
}
2005-04-18 18:57:24 -07:00
g = ( t & 0xff00 ) > > 8 ;
if ( g = = 0xff ) {
2010-08-25 18:34:13 -07:00
if ( iml - > gmod ) {
2005-04-18 18:57:24 -07:00
if ( iml - > gmod - > brightness ! = 0x100 ) {
iml - > gmod - > brightness = 0x100 ;
changed = 1 ;
if ( iml - > gmod - > contrast = = 0x100 & & iml - > gmod - > gamma = = 0x100 ) {
FREE ( iml - > gmod ) ;
}
}
}
} else {
2010-08-25 18:34:13 -07:00
if ( ! iml - > gmod ) {
2005-04-18 18:57:24 -07:00
iml - > gmod = create_colormod ( ) ;
}
if ( iml - > gmod - > brightness ! = ( int ) g ) {
iml - > gmod - > brightness = g ;
changed = 1 ;
}
2002-05-04 07:25:30 -07:00
}
2005-04-18 18:57:24 -07:00
b = t & 0xff ;
if ( b = = 0xff ) {
2010-08-25 18:34:13 -07:00
if ( iml - > bmod ) {
2005-04-18 18:57:24 -07:00
if ( iml - > bmod - > brightness ! = 0x100 ) {
iml - > bmod - > brightness = 0x100 ;
changed = 1 ;
if ( iml - > bmod - > contrast = = 0x100 & & iml - > bmod - > gamma = = 0x100 ) {
FREE ( iml - > bmod ) ;
}
}
}
} else {
2010-08-25 18:34:13 -07:00
if ( ! iml - > bmod ) {
2005-04-18 18:57:24 -07:00
iml - > bmod = create_colormod ( ) ;
iml - > bmod - > contrast = iml - > bmod - > gamma = 0x100 ;
}
if ( iml - > bmod - > brightness ! = ( int ) b ) {
iml - > bmod - > brightness = b ;
changed = 1 ;
}
2002-05-04 07:25:30 -07:00
}
}
2005-04-18 18:57:24 -07:00
if ( changed ) {
if ( image_mode_is ( which , MODE_TRANS ) ) {
free_desktop_pixmap ( ) ;
}
redraw_image ( which ) ;
2002-05-04 07:25:30 -07:00
}
break ;
2005-04-18 18:57:24 -07:00
case 3 :
# ifdef PIXMAP_OFFSET
get_desktop_window ( ) ;
if ( desktop_window = = None ) {
FOREACH_IMAGE ( if ( image_mode_is ( idx , MODE_TRANS ) ) {
image_set_mode ( idx , MODE_IMAGE ) ; image_allow_mode ( idx , ALLOW_IMAGE ) ; }
) ;
break ;
}
get_desktop_pixmap ( ) ;
redraw_images_by_mode ( MODE_TRANS | MODE_VIEWPORT ) ;
2000-05-02 16:46:08 -07:00
# endif
2005-04-18 18:57:24 -07:00
break ;
1999-08-17 18:12:47 -07:00
# endif
2005-04-18 18:57:24 -07:00
case 10 :
nstr = ( char * ) strsep ( & tnstr , " ; " ) ;
if ( nstr & & * nstr ) {
if ( ! strcasecmp ( nstr , " xterm " ) ) {
1999-08-17 18:12:47 -07:00
# ifdef XTERM_SCROLLBAR
2005-04-18 18:57:24 -07:00
scrollbar_change_type ( SCROLLBAR_XTERM ) ;
1999-08-17 18:12:47 -07:00
# else
2006-02-13 11:52:45 -08:00
libast_print_error ( " Support for xterm scrollbars was not compiled in. Sorry. \n " ) ;
1999-08-17 18:12:47 -07:00
# endif
2005-04-18 18:57:24 -07:00
} else if ( ! strcasecmp ( nstr , " next " ) ) {
1999-08-17 18:12:47 -07:00
# ifdef NEXT_SCROLLBAR
2005-04-18 18:57:24 -07:00
scrollbar_change_type ( SCROLLBAR_NEXT ) ;
1999-08-17 18:12:47 -07:00
# else
2006-02-13 11:52:45 -08:00
libast_print_error ( " Support for NeXT scrollbars was not compiled in. Sorry. \n " ) ;
1999-08-17 18:12:47 -07:00
# endif
2005-04-18 18:57:24 -07:00
} else if ( ! strcasecmp ( nstr , " motif " ) ) {
1999-08-17 18:12:47 -07:00
# ifdef MOTIF_SCROLLBAR
2005-04-18 18:57:24 -07:00
scrollbar_change_type ( SCROLLBAR_MOTIF ) ;
1999-08-17 18:12:47 -07:00
# else
2006-02-13 11:52:45 -08:00
libast_print_error ( " Support for motif scrollbars was not compiled in. Sorry. \n " ) ;
1999-08-17 18:12:47 -07:00
# endif
2005-04-18 18:57:24 -07:00
} else {
2006-02-13 11:52:45 -08:00
libast_print_error ( " Unrecognized scrollbar type \" %s \" . \n " , nstr ) ;
2005-04-18 18:57:24 -07:00
}
2002-05-04 07:25:30 -07:00
}
2005-04-18 18:57:24 -07:00
nstr = ( char * ) strsep ( & tnstr , " ; " ) ;
if ( nstr & & * nstr ) {
scrollbar_change_width ( ( unsigned short ) strtoul ( nstr , ( char * * ) NULL , 0 ) ) ;
}
break ;
case 11 :
nstr = ( char * ) strsep ( & tnstr , " ; " ) ;
OPT_SET_OR_TOGGLE ( nstr , eterm_options , ETERM_OPTIONS_SCROLLBAR_RIGHT ) ;
scr_touch ( ) ;
2002-05-04 07:25:30 -07:00
parent_resize ( ) ;
2005-04-18 18:57:24 -07:00
break ;
case 12 :
nstr = ( char * ) strsep ( & tnstr , " ; " ) ;
OPT_SET_OR_TOGGLE ( nstr , eterm_options , ETERM_OPTIONS_SCROLLBAR_FLOATING ) ;
scrollbar_reposition_and_always_draw ( ) ;
break ;
case 13 :
nstr = ( char * ) strsep ( & tnstr , " ; " ) ;
OPT_SET_OR_TOGGLE ( nstr , eterm_options , ETERM_OPTIONS_SCROLLBAR_POPUP ) ;
break ;
case 14 :
nstr = ( char * ) strsep ( & tnstr , " ; " ) ;
if ( ! ( nstr ) | | ! ( * ( nstr ) ) ) {
bbar_show_all ( - 1 ) ;
parent_resize ( ) ;
} else if ( BOOL_OPT_ISTRUE ( nstr ) ) {
bbar_show_all ( 1 ) ;
parent_resize ( ) ;
} else if ( BOOL_OPT_ISFALSE ( nstr ) ) {
bbar_show_all ( 0 ) ;
parent_resize ( ) ;
}
break ;
case 20 :
nstr = ( char * ) strsep ( & tnstr , " ; " ) ;
OPT_SET_OR_TOGGLE ( nstr , vt_options , VT_OPTIONS_VISUAL_BELL ) ;
break ;
1999-08-17 18:12:47 -07:00
# ifdef MAPALERT_OPTION
2005-04-18 18:57:24 -07:00
case 21 :
nstr = ( char * ) strsep ( & tnstr , " ; " ) ;
OPT_SET_OR_TOGGLE ( nstr , vt_options , VT_OPTIONS_MAP_ALERT ) ;
break ;
1999-08-17 18:12:47 -07:00
# endif
2005-04-18 18:57:24 -07:00
case 22 :
nstr = ( char * ) strsep ( & tnstr , " ; " ) ;
OPT_SET_OR_TOGGLE ( nstr , eterm_options , ETERM_OPTIONS_XTERM_SELECT ) ;
break ;
case 23 :
nstr = ( char * ) strsep ( & tnstr , " ; " ) ;
OPT_SET_OR_TOGGLE ( nstr , eterm_options , ETERM_OPTIONS_SELECT_WHOLE_LINE ) ;
break ;
case 24 :
nstr = ( char * ) strsep ( & tnstr , " ; " ) ;
FOREACH_IMAGE ( if ( ! image_mode_is ( idx , MODE_VIEWPORT ) & & image_mode_is ( idx , ALLOW_VIEWPORT ) ) {
image_set_mode ( idx , MODE_VIEWPORT ) ; }
) ;
redraw_images_by_mode ( MODE_VIEWPORT ) ;
break ;
case 25 :
nstr = ( char * ) strsep ( & tnstr , " ; " ) ;
OPT_SET_OR_TOGGLE ( nstr , eterm_options , ETERM_OPTIONS_SELECT_TRAILING_SPACES ) ;
break ;
case 26 :
nstr = ( char * ) strsep ( & tnstr , " ; " ) ;
OPT_SET_OR_TOGGLE ( nstr , vt_options , VT_OPTIONS_REPORT_AS_KEYSYMS ) ;
break ;
case 27 :
nstr = ( char * ) strsep ( & tnstr , " ; " ) ;
OPT_SET_OR_TOGGLE ( nstr , eterm_options , ETERM_OPTIONS_NO_INPUT ) ;
wm_hints = XGetWMHints ( Xdisplay , TermWin . parent ) ;
wm_hints - > flags | = InputHint ;
wm_hints - > input = ( ( BITFIELD_IS_SET ( eterm_options , ETERM_OPTIONS_NO_INPUT ) ) ? False : True ) ;
XSetWMHints ( Xdisplay , TermWin . parent , wm_hints ) ;
XFree ( wm_hints ) ;
break ;
2008-05-14 14:54:45 -07:00
case 28 :
nstr = ( char * ) strsep ( & tnstr , " ; " ) ;
OPT_SET_OR_TOGGLE ( nstr , vt_options , VT_OPTIONS_URG_ALERT ) ;
break ;
2005-04-18 18:57:24 -07:00
case 40 :
nstr = ( char * ) strsep ( & tnstr , " ; " ) ;
if ( nstr ) {
if ( XParseColor ( Xdisplay , cmap , nstr , & xcol ) & & XAllocColor ( Xdisplay , cmap , & xcol ) ) {
PixColors [ fgColor ] = xcol . pixel ;
scr_refresh ( DEFAULT_REFRESH ) ;
}
2002-05-04 07:25:30 -07:00
}
2005-04-18 18:57:24 -07:00
break ;
case 41 :
nstr = ( char * ) strsep ( & tnstr , " ; " ) ;
if ( nstr ) {
if ( XParseColor ( Xdisplay , cmap , nstr , & xcol ) & & XAllocColor ( Xdisplay , cmap , & xcol ) ) {
PixColors [ bgColor ] = xcol . pixel ;
scr_refresh ( DEFAULT_REFRESH ) ;
}
2002-05-04 07:25:30 -07:00
}
2005-04-18 18:57:24 -07:00
break ;
case 50 :
/* Change desktops */
nstr = ( char * ) strsep ( & tnstr , " ; " ) ;
if ( nstr & & * nstr ) {
XClientMessageEvent xev ;
rs_desktop = ( int ) strtol ( nstr , ( char * * ) NULL , 0 ) ;
xev . type = ClientMessage ;
xev . window = TermWin . parent ;
xev . message_type = props [ PROP_DESKTOP ] ;
xev . format = 32 ;
xev . data . l [ 0 ] = rs_desktop ;
XChangeProperty ( Xdisplay , TermWin . parent , xev . message_type , XA_CARDINAL , 32 ,
PropModeReplace , ( unsigned char * ) & rs_desktop , 1 ) ;
XSendEvent ( Xdisplay , Xroot , False , SubstructureNotifyMask , ( XEvent * ) & xev ) ;
}
break ;
case 51 :
/* Change opacity */
nstr = ( char * ) strsep ( & tnstr , " ; " ) ;
if ( nstr & & * nstr ) {
XClientMessageEvent xev ;
spif_uint32_t tmp ;
tmp = ( int ) strtol ( nstr , ( char * * ) NULL , 0 ) ;
if ( tmp < 0x100 ) {
rs_opacity = tmp | ( tmp < < 24 ) | ( tmp < < 16 ) | ( tmp < < 8 ) ;
} else {
rs_opacity = 0xffffffff ;
}
xev . type = ClientMessage ;
xev . window = TermWin . parent ;
xev . message_type = props [ PROP_EWMH_OPACITY ] ;
xev . format = 32 ;
xev . data . l [ 0 ] = rs_opacity ;
XChangeProperty ( Xdisplay , TermWin . parent , xev . message_type , XA_CARDINAL , 32 ,
PropModeReplace , ( unsigned char * ) & rs_opacity , 1 ) ;
XChangeProperty ( Xdisplay , TermWin . vt , xev . message_type , XA_CARDINAL , 32 ,
PropModeReplace , ( unsigned char * ) & rs_opacity , 1 ) ;
XSendEvent ( Xdisplay , Xroot , False , SubstructureNotifyMask , ( XEvent * ) ( & xev ) ) ;
}
break ;
2004-12-14 15:24:33 -08:00
2005-04-18 18:57:24 -07:00
case 72 :
/* Search scrollback buffer for a string. NULL to clear. */
nstr = ( char * ) strsep ( & tnstr , " ; " ) ;
if ( nstr & & * nstr ) {
scr_search_scrollback ( nstr ) ;
2002-05-04 07:25:30 -07:00
} else {
2005-04-18 18:57:24 -07:00
scr_search_scrollback ( NULL ) ;
2002-05-04 07:25:30 -07:00
}
2005-04-18 18:57:24 -07:00
break ;
2004-12-14 15:24:33 -08:00
2005-04-18 18:57:24 -07:00
case 80 :
/* Set debugging level */
nstr = ( char * ) strsep ( & tnstr , " ; " ) ;
if ( nstr & & * nstr ) {
DEBUG_LEVEL = ( unsigned int ) strtoul ( nstr , ( char * * ) NULL , 0 ) ;
}
break ;
2002-05-04 07:25:30 -07:00
2005-04-18 18:57:24 -07:00
default :
break ;
}
break ;
2002-05-04 07:25:30 -07:00
Sun Mar 2 23:40:39 2003 Michael Jennings (mej)
Fixed a bug with foreground/background color change pointed out by
Thomas <arnognul@tiscali.se>.
Also added support for all the other OSC color change sequences (at
least those for the colors that Eterm uses). The sequences are of
the form "\e];n;color[;color[...]]\a", where n is between 10 and 19.
You can specify up to (20 - n) semicolon-separated colors representing
the following attributes in order: foreground, background, cursor,
mouse pointer, mouse pointer background (*), Tek foreground (*), Tek
background (*), highlight color (*), bold color, and underline color.
Attributes marked with a (*) are ignored by Eterm and may be left
empty, but their trailing semicolons must be present for xterm
compatibility.
For example, to set a white foreground, black background, yellow text
cursor, green mouse cursor, #ffaa00 for bold, and cyan for underline,
you could use either of the following:
echo -e "\e]10;white;black;yellow;green;;;;;#ffaa00;cyan\007"
or
echo -e "\e]10;white\007"
echo -e "\e]11;black\007"
echo -e "\e]12;yellow\007"
echo -e "\e]13;green\007"
echo -e "\e]18;#ffaa00\007"
echo -e "\e]19;cyan\007"
Note that the setting of bold and underline colors using 18 and 19 are
Eterm extensions.
SVN revision: 6739
2003-03-02 20:53:35 -08:00
# ifdef XTERM_COLOR_CHANGE
2005-04-18 18:57:24 -07:00
case ESCSEQ_XTERM_FGCOLOR : /* 10 */
2010-08-25 18:34:13 -07:00
if ( ( nstr = ( char * ) strsep ( & tnstr , " ; " ) ) ) {
2005-04-18 18:57:24 -07:00
set_window_color ( fgColor , nstr ) ;
}
/* drop */
case ESCSEQ_XTERM_BGCOLOR : /* 11 */
2010-08-25 18:34:13 -07:00
if ( ( nstr = ( char * ) strsep ( & tnstr , " ; " ) ) ) {
2005-04-18 18:57:24 -07:00
set_window_color ( bgColor , nstr ) ;
}
/* drop */
case ESCSEQ_XTERM_CURSOR_COLOR : /* 12 */
2010-08-25 18:34:13 -07:00
if ( ( nstr = ( char * ) strsep ( & tnstr , " ; " ) ) ) {
Sun Mar 2 23:40:39 2003 Michael Jennings (mej)
Fixed a bug with foreground/background color change pointed out by
Thomas <arnognul@tiscali.se>.
Also added support for all the other OSC color change sequences (at
least those for the colors that Eterm uses). The sequences are of
the form "\e];n;color[;color[...]]\a", where n is between 10 and 19.
You can specify up to (20 - n) semicolon-separated colors representing
the following attributes in order: foreground, background, cursor,
mouse pointer, mouse pointer background (*), Tek foreground (*), Tek
background (*), highlight color (*), bold color, and underline color.
Attributes marked with a (*) are ignored by Eterm and may be left
empty, but their trailing semicolons must be present for xterm
compatibility.
For example, to set a white foreground, black background, yellow text
cursor, green mouse cursor, #ffaa00 for bold, and cyan for underline,
you could use either of the following:
echo -e "\e]10;white;black;yellow;green;;;;;#ffaa00;cyan\007"
or
echo -e "\e]10;white\007"
echo -e "\e]11;black\007"
echo -e "\e]12;yellow\007"
echo -e "\e]13;green\007"
echo -e "\e]18;#ffaa00\007"
echo -e "\e]19;cyan\007"
Note that the setting of bold and underline colors using 18 and 19 are
Eterm extensions.
SVN revision: 6739
2003-03-02 20:53:35 -08:00
# ifndef NO_CURSORCOLOR
2005-04-18 18:57:24 -07:00
set_window_color ( cursorColor , nstr ) ;
Sun Mar 2 23:40:39 2003 Michael Jennings (mej)
Fixed a bug with foreground/background color change pointed out by
Thomas <arnognul@tiscali.se>.
Also added support for all the other OSC color change sequences (at
least those for the colors that Eterm uses). The sequences are of
the form "\e];n;color[;color[...]]\a", where n is between 10 and 19.
You can specify up to (20 - n) semicolon-separated colors representing
the following attributes in order: foreground, background, cursor,
mouse pointer, mouse pointer background (*), Tek foreground (*), Tek
background (*), highlight color (*), bold color, and underline color.
Attributes marked with a (*) are ignored by Eterm and may be left
empty, but their trailing semicolons must be present for xterm
compatibility.
For example, to set a white foreground, black background, yellow text
cursor, green mouse cursor, #ffaa00 for bold, and cyan for underline,
you could use either of the following:
echo -e "\e]10;white;black;yellow;green;;;;;#ffaa00;cyan\007"
or
echo -e "\e]10;white\007"
echo -e "\e]11;black\007"
echo -e "\e]12;yellow\007"
echo -e "\e]13;green\007"
echo -e "\e]18;#ffaa00\007"
echo -e "\e]19;cyan\007"
Note that the setting of bold and underline colors using 18 and 19 are
Eterm extensions.
SVN revision: 6739
2003-03-02 20:53:35 -08:00
# endif
2005-04-18 18:57:24 -07:00
}
/* drop */
case ESCSEQ_XTERM_PTR_FGCOLOR : /* 13 */
2010-08-25 18:34:13 -07:00
if ( ( nstr = ( char * ) strsep ( & tnstr , " ; " ) ) ) {
2005-04-18 18:57:24 -07:00
set_pointer_colors ( nstr , NULL ) ;
}
/* drop */
case ESCSEQ_XTERM_PTR_BGCOLOR : /* 14 */
2010-08-25 18:34:13 -07:00
if ( ( nstr = ( char * ) strsep ( & tnstr , " ; " ) ) ) {
2005-04-18 18:57:24 -07:00
/* UNSUPPORTED */
}
/* drop */
case ESCSEQ_XTERM_TEK_FGCOLOR : /* 15 */
2010-08-25 18:34:13 -07:00
if ( ( nstr = ( char * ) strsep ( & tnstr , " ; " ) ) ) {
2005-04-18 18:57:24 -07:00
/* UNSUPPORTED */
}
/* drop */
case ESCSEQ_XTERM_TEK_BGCOLOR : /* 16 */
2010-08-25 18:34:13 -07:00
if ( ( nstr = ( char * ) strsep ( & tnstr , " ; " ) ) ) {
2005-04-18 18:57:24 -07:00
/* UNSUPPORTED */
}
/* drop */
case ESCSEQ_XTERM_HILIGHT_COLOR : /* 17 */
2010-08-25 18:34:13 -07:00
if ( ( nstr = ( char * ) strsep ( & tnstr , " ; " ) ) ) {
2005-04-18 18:57:24 -07:00
/* UNSUPPORTED */
}
/* drop */
case ESCSEQ_XTERM_BOLD_COLOR : /* 18 */
2010-08-25 18:34:13 -07:00
if ( ( nstr = ( char * ) strsep ( & tnstr , " ; " ) ) ) {
2005-04-18 18:57:24 -07:00
set_window_color ( colorBD , nstr ) ;
}
/* drop */
case ESCSEQ_XTERM_ULINE_COLOR : /* 19 */
2010-08-25 18:34:13 -07:00
if ( ( nstr = ( char * ) strsep ( & tnstr , " ; " ) ) ) {
2005-04-18 18:57:24 -07:00
set_window_color ( colorUL , nstr ) ;
}
2003-01-27 14:35:58 -08:00
# endif
2005-04-18 18:57:24 -07:00
break ;
2003-01-27 14:35:58 -08:00
2005-04-18 18:57:24 -07:00
case ESCSEQ_XTERM_PIXMAP : /* 20 */
1999-08-17 18:12:47 -07:00
# ifdef PIXMAP_SUPPORT
2005-04-18 18:57:24 -07:00
FOREACH_IMAGE ( if ( ! image_mode_is ( idx , MODE_IMAGE ) & & image_mode_is ( idx , ALLOW_IMAGE ) ) {
image_set_mode ( idx , MODE_IMAGE ) ; }
) ;
if ( ! strcmp ( str , " ; " ) ) {
image_set_mode ( image_bg , MODE_SOLID ) ;
bg_needs_update = 1 ;
} else {
nstr = ( char * ) strsep ( & tnstr , " ; " ) ;
if ( nstr ) {
if ( * nstr ) {
set_pixmap_scale ( " " , images [ image_bg ] . current - > pmap ) ;
bg_needs_update = 1 ;
load_image ( nstr , images [ image_bg ] . current ) ;
}
while ( ( nstr = ( char * ) strsep ( & tnstr , " ; " ) ) & & * nstr ) {
changed + = set_pixmap_scale ( nstr , images [ image_bg ] . current - > pmap ) ;
scaled = 1 ;
}
} else {
image_set_mode ( image_bg , MODE_SOLID ) ;
bg_needs_update = 1 ;
}
}
if ( ( changed ) | | ( bg_needs_update ) ) {
redraw_image ( image_bg ) ;
}
1999-08-17 18:12:47 -07:00
# endif /* PIXMAP_SUPPORT */
2005-04-18 18:57:24 -07:00
break ;
1999-08-17 18:12:47 -07:00
2005-04-18 18:57:24 -07:00
case ESCSEQ_XTERM_DUMPSCREEN : /* 30 */
Sun Mar 2 23:40:39 2003 Michael Jennings (mej)
Fixed a bug with foreground/background color change pointed out by
Thomas <arnognul@tiscali.se>.
Also added support for all the other OSC color change sequences (at
least those for the colors that Eterm uses). The sequences are of
the form "\e];n;color[;color[...]]\a", where n is between 10 and 19.
You can specify up to (20 - n) semicolon-separated colors representing
the following attributes in order: foreground, background, cursor,
mouse pointer, mouse pointer background (*), Tek foreground (*), Tek
background (*), highlight color (*), bold color, and underline color.
Attributes marked with a (*) are ignored by Eterm and may be left
empty, but their trailing semicolons must be present for xterm
compatibility.
For example, to set a white foreground, black background, yellow text
cursor, green mouse cursor, #ffaa00 for bold, and cyan for underline,
you could use either of the following:
echo -e "\e]10;white;black;yellow;green;;;;;#ffaa00;cyan\007"
or
echo -e "\e]10;white\007"
echo -e "\e]11;black\007"
echo -e "\e]12;yellow\007"
echo -e "\e]13;green\007"
echo -e "\e]18;#ffaa00\007"
echo -e "\e]19;cyan\007"
Note that the setting of bold and underline colors using 18 and 19 are
Eterm extensions.
SVN revision: 6739
2003-03-02 20:53:35 -08:00
#if 0
2005-04-18 18:57:24 -07:00
nstr = ( char * ) strsep ( & tnstr , " ; " ) ;
if ( nstr & & * nstr ) {
scr_dump_to_file ( nstr ) ;
}
break ;
Sun Mar 2 23:40:39 2003 Michael Jennings (mej)
Fixed a bug with foreground/background color change pointed out by
Thomas <arnognul@tiscali.se>.
Also added support for all the other OSC color change sequences (at
least those for the colors that Eterm uses). The sequences are of
the form "\e];n;color[;color[...]]\a", where n is between 10 and 19.
You can specify up to (20 - n) semicolon-separated colors representing
the following attributes in order: foreground, background, cursor,
mouse pointer, mouse pointer background (*), Tek foreground (*), Tek
background (*), highlight color (*), bold color, and underline color.
Attributes marked with a (*) are ignored by Eterm and may be left
empty, but their trailing semicolons must be present for xterm
compatibility.
For example, to set a white foreground, black background, yellow text
cursor, green mouse cursor, #ffaa00 for bold, and cyan for underline,
you could use either of the following:
echo -e "\e]10;white;black;yellow;green;;;;;#ffaa00;cyan\007"
or
echo -e "\e]10;white\007"
echo -e "\e]11;black\007"
echo -e "\e]12;yellow\007"
echo -e "\e]13;green\007"
echo -e "\e]18;#ffaa00\007"
echo -e "\e]19;cyan\007"
Note that the setting of bold and underline colors using 18 and 19 are
Eterm extensions.
SVN revision: 6739
2003-03-02 20:53:35 -08:00
# endif
2005-04-18 18:57:24 -07:00
case ESCSEQ_XTERM_RESTOREFG : /* 39 */
1999-08-17 18:12:47 -07:00
# ifdef XTERM_COLOR_CHANGE
2005-04-18 18:57:24 -07:00
set_window_color ( fgColor , str ) ;
1999-08-17 18:12:47 -07:00
# endif
2005-04-18 18:57:24 -07:00
break ;
case ESCSEQ_XTERM_RESTOREBG : /* 40 */
1999-08-17 18:12:47 -07:00
# ifdef XTERM_COLOR_CHANGE
2005-04-18 18:57:24 -07:00
set_window_color ( bgColor , str ) ;
1999-08-17 18:12:47 -07:00
# endif
2005-04-18 18:57:24 -07:00
break ;
case ESCSEQ_XTERM_LOGFILE : /* 46 */
nstr = ( char * ) strsep ( & tnstr , " ; " ) ;
if ( nstr & & * nstr & & BOOL_OPT_ISTRUE ( nstr ) ) {
/* Logging on */
} else {
/* Logging off */
}
break ;
case ESCSEQ_XTERM_FONT : /* 50 */
change_font ( 0 , str ) ;
break ;
default :
D_CMD ( ( " Unsupported xterm escape sequence operator: 0x%02x \n " , op ) ) ;
break ;
2002-05-04 07:25:30 -07:00
}
1999-08-17 18:12:47 -07:00
# ifdef PIXMAP_SUPPORT
2002-05-04 07:25:30 -07:00
FREE ( orig_tnstr ) ;
1999-08-17 18:12:47 -07:00
# endif
}