1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: command.c |
2 | * File: command.c |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * $Id: command.C,v 1.12 2003/12/05 04:05:13 pcg Exp $ |
4 | * $Id: command.C,v 1.17 2003/12/18 00:29:29 pcg Exp $ |
5 | * |
5 | * |
6 | * All portions of code are copyright by their respective author/s. |
6 | * All portions of code are copyright by their respective author/s. |
7 | * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> |
7 | * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> |
8 | * - original version |
8 | * - original version |
9 | * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com> |
9 | * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com> |
… | |
… | |
61 | unsigned int newlen; |
61 | unsigned int newlen; |
62 | KeySym keysym; |
62 | KeySym keysym; |
63 | #ifdef DEBUG_CMD |
63 | #ifdef DEBUG_CMD |
64 | static int debug_key = 1; /* accessible by a debugger only */ |
64 | static int debug_key = 1; /* accessible by a debugger only */ |
65 | #endif |
65 | #endif |
66 | #ifdef USE_XIM |
|
|
67 | int valid_keysym; |
66 | int valid_keysym; |
68 | #endif |
|
|
69 | unsigned char *kbuf = R->kbuf; |
67 | unsigned char *kbuf = R->kbuf; |
70 | |
68 | |
71 | /* |
69 | /* |
72 | * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an |
70 | * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an |
73 | * escape sequence to toggle the Keypad. |
71 | * escape sequence to toggle the Keypad. |
… | |
… | |
75 | * Always permit `shift' to override the current setting |
73 | * Always permit `shift' to override the current setting |
76 | */ |
74 | */ |
77 | shft = (ev->state & ShiftMask); |
75 | shft = (ev->state & ShiftMask); |
78 | ctrl = (ev->state & ControlMask); |
76 | ctrl = (ev->state & ControlMask); |
79 | meta = (ev->state & R->ModMetaMask); |
77 | meta = (ev->state & R->ModMetaMask); |
|
|
78 | |
80 | if (R->numlock_state || (ev->state & R->ModNumLockMask)) { |
79 | if (R->numlock_state || (ev->state & R->ModNumLockMask)) |
|
|
80 | { |
81 | R->numlock_state = (ev->state & R->ModNumLockMask); |
81 | R->numlock_state = (ev->state & R->ModNumLockMask); |
82 | PrivMode((!R->numlock_state), PrivMode_aplKP); |
82 | PrivMode((!R->numlock_state), PrivMode_aplKP); |
83 | } |
83 | } |
|
|
84 | |
|
|
85 | kbuf[0] = 0; |
|
|
86 | |
84 | #ifdef USE_XIM |
87 | #ifdef USE_XIM |
85 | if (R->Input_Context != NULL) { |
88 | if (R->Input_Context) |
|
|
89 | { |
86 | Status status_return; |
90 | Status status_return; |
87 | |
91 | |
88 | kbuf[0] = '\0'; |
|
|
89 | #ifdef X_HAVE_UTF8_STRING |
92 | #ifdef X_HAVE_UTF8_STRING |
90 | len = Xutf8LookupString(R->Input_Context, ev, (char *)kbuf, |
93 | len = Xutf8LookupString (R->Input_Context, ev, (char *)kbuf, |
91 | KBUFSZ, &keysym, &status_return); |
94 | KBUFSZ, &keysym, &status_return); |
92 | #else |
95 | #else |
|
|
96 | wchar_t wkbuf[KBUFSZ + 1]; |
|
|
97 | |
|
|
98 | // assume wchar_t == unicode or better |
93 | len = XmbLookupString(R->Input_Context, ev, (char *)kbuf, |
99 | len = XwcLookupString (R->Input_Context, ev, wkbuf, |
94 | KBUFSZ, &keysym, &status_return); |
100 | KBUFSZ, &keysym, &status_return); |
|
|
101 | |
|
|
102 | if (status_return == XLookupChars |
|
|
103 | || status_return == XLookupBoth) |
|
|
104 | { |
|
|
105 | wkbuf[len] = 0; |
|
|
106 | len = wcstombs ((char *)kbuf, wkbuf, KBUFSZ); |
|
|
107 | } |
|
|
108 | else |
|
|
109 | len = 0; |
95 | #endif |
110 | #endif |
96 | valid_keysym = ((status_return == XLookupKeySym) |
111 | valid_keysym = status_return == XLookupKeySym |
97 | || (status_return == XLookupBoth)); |
112 | || status_return == XLookupBoth; |
|
|
113 | } |
98 | } else { |
114 | else |
|
|
115 | #endif |
|
|
116 | { |
99 | len = XLookupString(ev, (char *)kbuf, KBUFSZ, &keysym, |
117 | len = XLookupString (ev, (char *)kbuf, KBUFSZ, &keysym, &R->compose); |
100 | &R->compose); |
|
|
101 | valid_keysym = 1; |
118 | valid_keysym = !len; |
102 | } |
119 | } |
103 | #else /* USE_XIM */ |
|
|
104 | len = XLookupString(ev, (char *)kbuf, KBUFSZ, &keysym, |
|
|
105 | &R->compose); |
|
|
106 | /* |
|
|
107 | * map unmapped Latin[2-4]/Katakana/Arabic/Cyrillic/Greek entries -> Latin1 |
|
|
108 | * good for installations with correct fonts, but without XLOCALE |
|
|
109 | */ |
|
|
110 | if (!len) { |
|
|
111 | if ((keysym >= 0x0100) && (keysym < 0x0800)) { |
|
|
112 | kbuf[0] = (keysym & 0xFF); |
|
|
113 | kbuf[1] = '\0'; |
|
|
114 | len = 1; |
|
|
115 | } else |
|
|
116 | kbuf[0] = '\0'; |
|
|
117 | } |
|
|
118 | #endif /* USE_XIM */ |
|
|
119 | |
120 | |
120 | #ifdef USE_XIM |
|
|
121 | if (valid_keysym) |
121 | if (valid_keysym) |
122 | #endif |
|
|
123 | { |
122 | { |
124 | /* for some backwards compatibility */ |
123 | /* for some backwards compatibility */ |
125 | #if defined(HOTKEY_CTRL) || defined(HOTKEY_META) |
124 | #if defined(HOTKEY_CTRL) || defined(HOTKEY_META) |
126 | # ifdef HOTKEY_CTRL |
125 | # ifdef HOTKEY_CTRL |
127 | if (ctrl) { |
126 | if (ctrl) |
128 | # else |
127 | # else |
129 | if (meta) { |
128 | if (meta) |
130 | # endif |
129 | # endif |
|
|
130 | { |
131 | if (keysym == R->ks_bigfont) { |
131 | if (keysym == R->ks_bigfont) |
|
|
132 | { |
132 | rxvt_change_font(aR_ 0, FONT_UP); |
133 | rxvt_change_font(aR_ 0, FONT_UP); |
133 | return; |
134 | return; |
|
|
135 | } |
134 | } else if (keysym == R->ks_smallfont) { |
136 | else if (keysym == R->ks_smallfont) |
|
|
137 | { |
135 | rxvt_change_font(aR_ 0, FONT_DN); |
138 | rxvt_change_font(aR_ 0, FONT_DN); |
136 | return; |
139 | return; |
137 | } |
140 | } |
138 | } |
141 | } |
139 | #endif |
142 | #endif |
140 | |
143 | |
141 | if (R->TermWin.saveLines) { |
144 | if (R->TermWin.saveLines) { |
142 | #ifdef UNSHIFTED_SCROLLKEYS |
145 | #ifdef UNSHIFTED_SCROLLKEYS |
143 | if (!ctrl && !meta) { |
146 | if (!ctrl && !meta) { |
… | |
… | |
237 | /* escape prefix */ |
240 | /* escape prefix */ |
238 | if (meta) |
241 | if (meta) |
239 | # ifdef META8_OPTION |
242 | # ifdef META8_OPTION |
240 | if (R->meta_char == C0_ESC) |
243 | if (R->meta_char == C0_ESC) |
241 | # endif |
244 | # endif |
242 | R->tt_write(&ch, 1); |
245 | R->tt_write (&ch, 1); |
243 | R->tt_write(kbuf0, l); |
246 | R->tt_write (kbuf0, l); |
244 | return; |
247 | return; |
245 | } else |
248 | } else |
246 | #endif |
249 | #endif |
247 | { |
250 | { |
248 | newlen = 1; |
251 | newlen = 1; |
… | |
… | |
572 | if (R->greek_mode) |
575 | if (R->greek_mode) |
573 | len = greek_xlat(kbuf, len); |
576 | len = greek_xlat(kbuf, len); |
574 | #endif |
577 | #endif |
575 | /* nil */ ; |
578 | /* nil */ ; |
576 | } |
579 | } |
577 | } |
580 | } |
578 | |
581 | |
579 | if (len <= 0) |
582 | if (len <= 0) |
580 | return; /* not mapped */ |
583 | return; /* not mapped */ |
581 | |
584 | |
582 | if (R->Options & Opt_scrollTtyKeypress) |
585 | if (R->Options & Opt_scrollTtyKeypress) |
… | |
… | |
772 | if (n > 0) |
775 | if (n > 0) |
773 | { |
776 | { |
774 | cmdbuf_endp += n; |
777 | cmdbuf_endp += n; |
775 | return true; |
778 | return true; |
776 | } |
779 | } |
777 | else if (n < 0 && errno == EAGAIN) |
780 | else if (n < 0 && errno != EAGAIN) |
|
|
781 | destroy (); |
|
|
782 | |
778 | return false; |
783 | return false; |
779 | |
|
|
780 | destroy (); |
|
|
781 | } |
784 | } |
782 | |
785 | |
783 | void |
786 | void |
784 | rxvt_term::pty_cb (io_watcher &w, short revents) |
787 | rxvt_term::pty_cb (io_watcher &w, short revents) |
785 | { |
788 | { |
… | |
… | |
1155 | { |
1158 | { |
1156 | int i, want_timeout; |
1159 | int i, want_timeout; |
1157 | Window unused_root, unused_child; |
1160 | Window unused_root, unused_child; |
1158 | int unused_root_x, unused_root_y; |
1161 | int unused_root_x, unused_root_y; |
1159 | unsigned int unused_mask; |
1162 | unsigned int unused_mask; |
1160 | struct timeval tp; |
|
|
1161 | |
1163 | |
1162 | #ifdef DEBUG_X |
1164 | #ifdef DEBUG_X |
1163 | const char *const eventnames[] = |
1165 | const char *const eventnames[] = |
1164 | { /* mason - this matches my system */ |
1166 | { /* mason - this matches my system */ |
1165 | "", |
1167 | "", |
… | |
… | |
1196 | "SelectionNotify", |
1198 | "SelectionNotify", |
1197 | "ColormapNotify", |
1199 | "ColormapNotify", |
1198 | "ClientMessage", |
1200 | "ClientMessage", |
1199 | "MappingNotify" |
1201 | "MappingNotify" |
1200 | }; |
1202 | }; |
|
|
1203 | #endif |
|
|
1204 | |
|
|
1205 | #ifdef DEBUG_X |
|
|
1206 | struct timeval tp; |
1201 | struct tm *ltt; |
1207 | struct tm *ltt; |
1202 | #endif |
|
|
1203 | |
|
|
1204 | /* |
|
|
1205 | * check if we need to get the time for any timeouts |
|
|
1206 | */ |
|
|
1207 | |
|
|
1208 | for (i = NUM_TIMEOUTS; i--; ) |
|
|
1209 | if (R->timeout[i].tv_sec) { |
|
|
1210 | want_timeout = 1; |
|
|
1211 | break; |
|
|
1212 | } |
|
|
1213 | |
|
|
1214 | #ifndef DEBUG_X |
|
|
1215 | if (want_timeout) |
|
|
1216 | #endif |
|
|
1217 | (void)gettimeofday(&tp, NULL); |
1208 | (void)gettimeofday(&tp, NULL); |
1218 | |
|
|
1219 | #ifdef DEBUG_X |
|
|
1220 | ltt = localtime(&(tp.tv_sec)); |
1209 | ltt = localtime(&(tp.tv_sec)); |
1221 | D_X((stderr, "Event: %-16s %-7s %08lx (%4d-%02d-%02d %02d:%02d:%02d.%.6ld) %s %lu", eventnames[ev->type], (ev->xany.window == R->TermWin.parent[0] ? "parent" : (ev->xany.window == R->TermWin.vt ? "vt" : (ev->xany.window == R->scrollBar.win ? "scroll" : (ev->xany.window == R->menuBar.win ? "menubar" : "UNKNOWN")))), (ev->xany.window == R->TermWin.parent[0] ? R->TermWin.parent[0] : (ev->xany.window == R->TermWin.vt ? R->TermWin.vt : (ev->xany.window == R->scrollBar.win ? R->scrollBar.win : (ev->xany.window == R->menuBar.win ? R->menuBar.win : 0)))), ltt->tm_year + 1900, ltt->tm_mon + 1, ltt->tm_mday, ltt->tm_hour, ltt->tm_min, ltt->tm_sec, tp.tv_usec, ev->xany.send_event ? "S" : " ", ev->xany.serial)); |
1210 | D_X((stderr, "Event: %-16s %-7s %08lx (%4d-%02d-%02d %02d:%02d:%02d.%.6ld) %s %lu", eventnames[ev->type], (ev->xany.window == R->TermWin.parent[0] ? "parent" : (ev->xany.window == R->TermWin.vt ? "vt" : (ev->xany.window == R->scrollBar.win ? "scroll" : (ev->xany.window == R->menuBar.win ? "menubar" : "UNKNOWN")))), (ev->xany.window == R->TermWin.parent[0] ? R->TermWin.parent[0] : (ev->xany.window == R->TermWin.vt ? R->TermWin.vt : (ev->xany.window == R->scrollBar.win ? R->scrollBar.win : (ev->xany.window == R->menuBar.win ? R->menuBar.win : 0)))), ltt->tm_year + 1900, ltt->tm_mon + 1, ltt->tm_mday, ltt->tm_hour, ltt->tm_min, ltt->tm_sec, tp.tv_usec, ev->xany.send_event ? "S" : " ", ev->xany.serial)); |
1222 | #endif |
1211 | #endif |
1223 | |
|
|
1224 | /* X event timeouts */ |
|
|
1225 | if (want_timeout) |
|
|
1226 | for (i = NUM_TIMEOUTS; i--; ) { |
|
|
1227 | if (R->timeout[i].tv_sec == 0) |
|
|
1228 | continue; |
|
|
1229 | if ((tp.tv_sec < R->timeout[i].tv_sec) |
|
|
1230 | || (tp.tv_sec == R->timeout[i].tv_sec |
|
|
1231 | && tp.tv_usec < R->timeout[i].tv_usec)) |
|
|
1232 | continue; |
|
|
1233 | R->timeout[i].tv_sec = 0; |
|
|
1234 | switch(i) { |
|
|
1235 | case TIMEOUT_INCR: |
|
|
1236 | rxvt_print_error("data loss: timeout on INCR selection paste"); |
|
|
1237 | R->selection_wait = Sel_none; |
|
|
1238 | break; |
|
|
1239 | default: |
|
|
1240 | break; |
|
|
1241 | } |
|
|
1242 | } |
|
|
1243 | |
1212 | |
1244 | switch (ev->type) { |
1213 | switch (ev->type) { |
1245 | case KeyPress: |
1214 | case KeyPress: |
1246 | rxvt_lookup_key(aR_ (XKeyEvent *)ev); |
1215 | rxvt_lookup_key(aR_ (XKeyEvent *)ev); |
1247 | break; |
1216 | break; |
… | |
… | |
2625 | |
2594 | |
2626 | case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */ |
2595 | case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */ |
2627 | arg[0] = -arg[0]; |
2596 | arg[0] = -arg[0]; |
2628 | /* FALLTHROUGH */ |
2597 | /* FALLTHROUGH */ |
2629 | case CSI_SU: /* 8.3.148: (1) SCROLL UP */ |
2598 | case CSI_SU: /* 8.3.148: (1) SCROLL UP */ |
2630 | rxvt_scroll_text(aR_ R->screen.tscroll, R->screen.bscroll, arg[0], 0); |
2599 | R->scr_scroll_text (R->screen.tscroll, R->screen.bscroll, arg[0], 0); |
2631 | break; |
2600 | break; |
2632 | |
2601 | |
2633 | case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */ |
2602 | case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */ |
2634 | R->tt_write((const unsigned char *)VT100_ANS, |
2603 | R->tt_write((const unsigned char *)VT100_ANS, |
2635 | (unsigned int)(sizeof(VT100_ANS) - 1)); |
2604 | (unsigned int)(sizeof(VT100_ANS) - 1)); |