… | |
… | |
48 | # include <termios.h> |
48 | # include <termios.h> |
49 | #endif |
49 | #endif |
50 | |
50 | |
51 | vector<rxvt_term *> rxvt_term::termlist; |
51 | vector<rxvt_term *> rxvt_term::termlist; |
52 | |
52 | |
|
|
53 | // used to tell global functions which terminal instance is "active" |
|
|
54 | rxvt_t rxvt_current_term; |
|
|
55 | |
53 | static char curlocale[128], savelocale[128]; |
56 | static char curlocale[128], savelocale[128]; |
54 | |
57 | |
55 | bool |
58 | bool |
56 | rxvt_set_locale (const char *locale) |
59 | rxvt_set_locale (const char *locale) NOTHROW |
57 | { |
60 | { |
58 | if (!locale || !strncmp (locale, curlocale, 128)) |
61 | if (!locale || !strncmp (locale, curlocale, 128)) |
59 | return false; |
62 | return false; |
60 | |
63 | |
61 | strncpy (curlocale, locale, 128); |
64 | strncpy (curlocale, locale, 128); |
62 | setlocale (LC_CTYPE, curlocale); |
65 | setlocale (LC_CTYPE, curlocale); |
63 | return true; |
66 | return true; |
64 | } |
67 | } |
65 | |
68 | |
66 | void |
69 | void |
67 | rxvt_push_locale (const char *locale) |
70 | rxvt_push_locale (const char *locale) NOTHROW |
68 | { |
71 | { |
69 | strcpy (savelocale, curlocale); |
72 | strcpy (savelocale, curlocale); |
70 | rxvt_set_locale (locale); |
73 | rxvt_set_locale (locale); |
71 | } |
74 | } |
72 | |
75 | |
73 | void |
76 | void |
74 | rxvt_pop_locale () |
77 | rxvt_pop_locale () NOTHROW |
75 | { |
78 | { |
76 | rxvt_set_locale (savelocale); |
79 | rxvt_set_locale (savelocale); |
77 | } |
80 | } |
78 | |
81 | |
79 | #if ENABLE_COMBINING |
82 | #if ENABLE_COMBINING |
… | |
… | |
166 | #ifdef POINTER_BLANK |
169 | #ifdef POINTER_BLANK |
167 | pointer_ev (this, &rxvt_term::pointer_cb), |
170 | pointer_ev (this, &rxvt_term::pointer_cb), |
168 | #endif |
171 | #endif |
169 | #ifdef USE_XIM |
172 | #ifdef USE_XIM |
170 | im_ev (this, &rxvt_term::im_cb), |
173 | im_ev (this, &rxvt_term::im_cb), |
|
|
174 | #endif |
|
|
175 | #ifndef NO_BELL |
|
|
176 | bell_ev (this, &rxvt_term::bell_cb), |
171 | #endif |
177 | #endif |
172 | termwin_ev (this, &rxvt_term::x_cb), |
178 | termwin_ev (this, &rxvt_term::x_cb), |
173 | vt_ev (this, &rxvt_term::x_cb), |
179 | vt_ev (this, &rxvt_term::x_cb), |
174 | child_ev (this, &rxvt_term::child_cb), |
180 | child_ev (this, &rxvt_term::child_cb), |
175 | check_ev (this, &rxvt_term::check_cb), |
181 | check_ev (this, &rxvt_term::check_cb), |
… | |
… | |
182 | |
188 | |
183 | termlist.push_back (this); |
189 | termlist.push_back (this); |
184 | |
190 | |
185 | #ifdef KEYSYM_RESOURCE |
191 | #ifdef KEYSYM_RESOURCE |
186 | keyboard = new keyboard_manager; |
192 | keyboard = new keyboard_manager; |
187 | |
|
|
188 | if (!keyboard) |
|
|
189 | rxvt_fatal ("out of memory, aborting.\n"); |
|
|
190 | #endif |
193 | #endif |
191 | } |
194 | } |
192 | |
195 | |
193 | // clean up the most important stuff, do *not* call x or free mem etc. |
196 | // clean up the most important stuff, do *not* call x or free mem etc. |
194 | // for use before an emergency exit |
197 | // for use before an emergency exit |
… | |
… | |
200 | delete pty; pty = 0; |
203 | delete pty; pty = 0; |
201 | } |
204 | } |
202 | |
205 | |
203 | rxvt_term::~rxvt_term () |
206 | rxvt_term::~rxvt_term () |
204 | { |
207 | { |
205 | HOOK_INVOKE ((this, HOOK_DESTROY, DT_END)); |
|
|
206 | |
|
|
207 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
208 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
208 | |
209 | |
209 | emergency_cleanup (); |
210 | emergency_cleanup (); |
210 | |
211 | |
211 | #if ENABLE_STYLES |
212 | #if ENABLE_STYLES |
… | |
… | |
302 | |
303 | |
303 | void |
304 | void |
304 | rxvt_term::destroy () |
305 | rxvt_term::destroy () |
305 | { |
306 | { |
306 | if (destroy_ev.active) |
307 | if (destroy_ev.active) |
|
|
308 | return; |
|
|
309 | |
|
|
310 | if (HOOK_INVOKE ((this, HOOK_DESTROY, DT_END))) |
307 | return; |
311 | return; |
308 | |
312 | |
309 | #if ENABLE_OVERLAY |
313 | #if ENABLE_OVERLAY |
310 | scr_overlay_off (); |
314 | scr_overlay_off (); |
311 | #endif |
315 | #endif |
… | |
… | |
446 | _exit (EXIT_FAILURE); |
450 | _exit (EXIT_FAILURE); |
447 | } |
451 | } |
448 | |
452 | |
449 | /*----------------------------------------------------------------------*/ |
453 | /*----------------------------------------------------------------------*/ |
450 | bool |
454 | bool |
451 | rxvt_term::init (int argc, const char *const *argv) |
455 | rxvt_term::init (int argc, const char *const *argv, stringvec *envv) |
452 | { |
456 | { |
|
|
457 | this->envv = envv; |
|
|
458 | |
453 | SET_R (this); |
459 | SET_R (this); |
454 | set_locale (""); |
460 | set_locale (""); |
455 | set_environ (envv); // few things in X do not call setlocale :( |
461 | set_environ (envv); // few things in X do not call setlocale :( |
456 | |
462 | |
457 | if (!init_vars ()) |
463 | if (!init_vars ()) |
… | |
… | |
463 | |
469 | |
464 | #ifdef KEYSYM_RESOURCE |
470 | #ifdef KEYSYM_RESOURCE |
465 | keyboard->register_done (); |
471 | keyboard->register_done (); |
466 | #endif |
472 | #endif |
467 | |
473 | |
468 | #if ENABLE_PERL |
|
|
469 | if (!rs[Rs_perl_ext_1]) |
|
|
470 | rs[Rs_perl_ext_1] = "default"; |
|
|
471 | |
|
|
472 | if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) |
|
|
473 | || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) |
|
|
474 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
|
|
475 | { |
|
|
476 | rxvt_perl.init (this); |
|
|
477 | HOOK_INVOKE ((this, HOOK_INIT, DT_END)); |
|
|
478 | } |
|
|
479 | #endif |
|
|
480 | |
|
|
481 | #ifdef HAVE_SCROLLBARS |
474 | #ifdef HAVE_SCROLLBARS |
482 | if (OPTION (Opt_scrollBar)) |
475 | if (OPTION (Opt_scrollBar)) |
483 | scrollBar.setIdle (); /* set existence for size calculations */ |
476 | scrollBar.setIdle (); /* set existence for size calculations */ |
484 | #endif |
477 | #endif |
485 | |
478 | |
486 | pty = rxvt_new_ptytty (); |
479 | pty = ptytty::create (); |
487 | |
480 | |
488 | create_windows (argc, argv); |
481 | create_windows (argc, argv); |
489 | |
482 | |
490 | dDisp; |
483 | dDisp; |
491 | |
484 | |
… | |
… | |
508 | check_our_parents (); |
501 | check_our_parents (); |
509 | rootwin_ev.start (display, display->root); |
502 | rootwin_ev.start (display, display->root); |
510 | } |
503 | } |
511 | #endif |
504 | #endif |
512 | |
505 | |
|
|
506 | set_colorfgbg (); |
|
|
507 | |
|
|
508 | init_command (cmd_argv); |
|
|
509 | |
|
|
510 | free (cmd_argv); |
|
|
511 | |
|
|
512 | if (pty->pty >= 0) |
|
|
513 | pty_ev.start (pty->pty, EVENT_READ); |
|
|
514 | |
|
|
515 | check_ev.start (); |
|
|
516 | |
|
|
517 | HOOK_INVOKE ((this, HOOK_START, DT_END)); |
|
|
518 | |
513 | XMapWindow (disp, vt); |
519 | XMapWindow (disp, vt); |
514 | XMapWindow (disp, parent[0]); |
520 | XMapWindow (disp, parent[0]); |
515 | |
|
|
516 | set_colorfgbg (); |
|
|
517 | |
|
|
518 | init_command (cmd_argv); |
|
|
519 | |
|
|
520 | free (cmd_argv); |
|
|
521 | |
|
|
522 | if (pty->pty >= 0) |
|
|
523 | pty_ev.start (pty->pty, EVENT_READ); |
|
|
524 | |
|
|
525 | check_ev.start (); |
|
|
526 | |
|
|
527 | HOOK_INVOKE ((this, HOOK_START, DT_END)); |
|
|
528 | |
521 | |
529 | return true; |
522 | return true; |
530 | } |
523 | } |
531 | |
524 | |
532 | static struct sig_handlers |
525 | static struct sig_handlers |
… | |
… | |
537 | * Catch a fatal signal and tidy up before quitting |
530 | * Catch a fatal signal and tidy up before quitting |
538 | */ |
531 | */ |
539 | void |
532 | void |
540 | sig_term (sig_watcher &w) |
533 | sig_term (sig_watcher &w) |
541 | { |
534 | { |
542 | #ifdef DEBUG_CMD |
|
|
543 | rxvt_warn ("caught signal %d, exiting.\n", w.signum); |
|
|
544 | #endif |
|
|
545 | rxvt_emergency_cleanup (); |
535 | rxvt_emergency_cleanup (); |
546 | signal (w.signum, SIG_DFL); |
536 | signal (w.signum, SIG_DFL); |
547 | kill (getpid (), w.signum); |
537 | kill (getpid (), w.signum); |
548 | } |
538 | } |
549 | |
539 | |
… | |
… | |
557 | char **rxvt_environ; // startup environment |
547 | char **rxvt_environ; // startup environment |
558 | |
548 | |
559 | void |
549 | void |
560 | rxvt_init () |
550 | rxvt_init () |
561 | { |
551 | { |
562 | uid_t uid = getuid (); |
552 | ptytty::init (); |
563 | gid_t gid = getgid (); |
|
|
564 | |
|
|
565 | // before doing anything else, check for setuid/setgid operation, |
|
|
566 | // start the helper process and drop privileges |
|
|
567 | if (uid != geteuid () |
|
|
568 | || gid != getegid ()) |
|
|
569 | { |
|
|
570 | #if PTYTTY_HELPER |
|
|
571 | rxvt_ptytty_server (); |
|
|
572 | #else |
|
|
573 | rxvt_warn ("running setuid/setgid without pty helper compiled in, continuing unprivileged.\n"); |
|
|
574 | #endif |
|
|
575 | |
|
|
576 | // drop privileges |
|
|
577 | #if HAVE_SETRESUID |
|
|
578 | setresgid (gid, gid, gid); |
|
|
579 | setresuid (uid, uid, uid); |
|
|
580 | #elif HAVE_SETREUID |
|
|
581 | setregid (gid, gid); |
|
|
582 | setreuid (uid, uid); |
|
|
583 | #elif HAVE_SETUID |
|
|
584 | setgid (gid); |
|
|
585 | setuid (uid); |
|
|
586 | #endif |
|
|
587 | |
|
|
588 | if (uid != geteuid () |
|
|
589 | || gid != getegid ()) |
|
|
590 | rxvt_fatal ("unable to drop privileges, aborting.\n"); |
|
|
591 | } |
|
|
592 | |
553 | |
593 | rxvt_environ = environ; |
554 | rxvt_environ = environ; |
594 | |
555 | |
595 | signal (SIGHUP, SIG_IGN); |
556 | signal (SIGHUP, SIG_IGN); |
596 | signal (SIGPIPE, SIG_IGN); |
557 | signal (SIGPIPE, SIG_IGN); |
… | |
… | |
631 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
592 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
632 | |
593 | |
633 | return p; |
594 | return p; |
634 | } |
595 | } |
635 | |
596 | |
636 | void * |
597 | void * |
637 | rxvt_realloc (void *ptr, size_t size) |
598 | rxvt_realloc (void *ptr, size_t size) |
638 | { |
599 | { |
639 | void *p = realloc (ptr, size); |
600 | void *p = realloc (ptr, size); |
640 | |
601 | |
641 | if (!p) |
602 | if (!p) |
… | |
… | |
655 | short recalc_x, recalc_y; |
616 | short recalc_x, recalc_y; |
656 | int x, y, sb_w, flags; |
617 | int x, y, sb_w, flags; |
657 | unsigned int w, h; |
618 | unsigned int w, h; |
658 | unsigned int max_width, max_height; |
619 | unsigned int max_width, max_height; |
659 | dDisp; |
620 | dDisp; |
660 | |
|
|
661 | D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
|
|
662 | ncol, nrow, szHint.width, szHint.height)); |
|
|
663 | |
621 | |
664 | szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; |
622 | szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; |
665 | szHint.win_gravity = NorthWestGravity; |
623 | szHint.win_gravity = NorthWestGravity; |
666 | /* szHint.min_aspect.x = szHint.min_aspect.y = 1; */ |
624 | /* szHint.min_aspect.x = szHint.min_aspect.y = 1; */ |
667 | |
625 | |
… | |
… | |
770 | if (recalc_y) |
728 | if (recalc_y) |
771 | szHint.y += DisplayHeight (disp, display->screen) - szHint.height - 2 * ext_bwidth; |
729 | szHint.y += DisplayHeight (disp, display->screen) - szHint.height - 2 * ext_bwidth; |
772 | |
730 | |
773 | ncol = width / fwidth; |
731 | ncol = width / fwidth; |
774 | nrow = height / fheight; |
732 | nrow = height / fheight; |
775 | D_SIZE ((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
|
|
776 | ncol, nrow, szHint.width, |
|
|
777 | szHint.height)); |
|
|
778 | return; |
|
|
779 | } |
733 | } |
780 | |
734 | |
781 | /*----------------------------------------------------------------------*/ |
735 | /*----------------------------------------------------------------------*/ |
782 | /* |
736 | /* |
783 | * Tell the teletype handler what size the window is. |
737 | * Tell the teletype handler what size the window is. |
… | |
… | |
1067 | * -------------------------------------------------------------------- */ |
1021 | * -------------------------------------------------------------------- */ |
1068 | void |
1022 | void |
1069 | rxvt_term::resize_all_windows (unsigned int newwidth, unsigned int newheight, int ignoreparent) |
1023 | rxvt_term::resize_all_windows (unsigned int newwidth, unsigned int newheight, int ignoreparent) |
1070 | { |
1024 | { |
1071 | int fix_screen; |
1025 | int fix_screen; |
1072 | int old_width = szHint.width, old_height = szHint.height; |
1026 | int old_width = szHint.width; |
|
|
1027 | int old_height = szHint.height; |
1073 | dDisp; |
1028 | dDisp; |
1074 | |
1029 | |
1075 | window_calc (newwidth, newheight); |
1030 | window_calc (newwidth, newheight); |
1076 | XSetWMNormalHints (disp, parent[0], &szHint); |
1031 | XSetWMNormalHints (disp, parent[0], &szHint); |
1077 | |
1032 | |
… | |
… | |
1099 | { |
1054 | { |
1100 | x -= x1; |
1055 | x -= x1; |
1101 | y -= y1; |
1056 | y -= y1; |
1102 | } |
1057 | } |
1103 | |
1058 | |
1104 | x1 = (DisplayWidth (disp, display->screen) - old_width) / 2; |
1059 | x1 = (DisplayWidth (disp, display->screen) - old_width ) / 2; |
1105 | y1 = (DisplayHeight (disp, display->screen) - old_height) / 2; |
1060 | y1 = (DisplayHeight (disp, display->screen) - old_height) / 2; |
1106 | dx = old_width - szHint.width; |
1061 | dx = old_width - szHint.width; |
1107 | dy = old_height - szHint.height; |
1062 | dy = old_height - szHint.height; |
1108 | |
1063 | |
1109 | /* Check position of the center of the window */ |
1064 | /* Check position of the center of the window */ |
1110 | if (x < x1) /* left half */ |
1065 | if (x < x1) /* left half */ |
1111 | dx = 0; |
1066 | dx = 0; |
… | |
… | |
1144 | resize_pixmap (); |
1099 | resize_pixmap (); |
1145 | #endif |
1100 | #endif |
1146 | } |
1101 | } |
1147 | |
1102 | |
1148 | if (fix_screen || old_height == 0) |
1103 | if (fix_screen || old_height == 0) |
1149 | { |
|
|
1150 | int curr_screen = -1; |
|
|
1151 | int old_ncol = prev_ncol; |
|
|
1152 | |
|
|
1153 | /* scr_reset only works on the primary screen */ |
|
|
1154 | if (old_height) /* this is not the first time through */ |
|
|
1155 | { |
|
|
1156 | unsigned int ocol = ncol; |
|
|
1157 | ncol = prev_ncol; // save b/c scr_blank_screen_mem uses this |
|
|
1158 | curr_screen = scr_change_screen (PRIMARY); |
|
|
1159 | ncol = ocol; |
|
|
1160 | } |
|
|
1161 | |
|
|
1162 | scr_reset (); |
1104 | scr_reset (); |
1163 | |
|
|
1164 | if (curr_screen >= 0) /* this is not the first time through */ |
|
|
1165 | { |
|
|
1166 | scr_change_screen (curr_screen); |
|
|
1167 | selection_check (old_ncol != ncol ? 4 : 0); |
|
|
1168 | } |
|
|
1169 | } |
|
|
1170 | |
|
|
1171 | old_width = szHint.width; |
|
|
1172 | old_height = szHint.height; |
|
|
1173 | |
1105 | |
1174 | #ifdef XPM_BACKGROUND |
1106 | #ifdef XPM_BACKGROUND |
1175 | if (pixmap) |
1107 | if (pixmap) |
1176 | scr_touch (false); |
1108 | scr_touch (false); |
1177 | #endif |
1109 | #endif |
… | |
… | |
1331 | set_environ (envv); |
1263 | set_environ (envv); |
1332 | |
1264 | |
1333 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1265 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1334 | return false; |
1266 | return false; |
1335 | |
1267 | |
1336 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
|
|
1337 | input_method = display->get_xim (locale, modifiers); |
1268 | input_method = display->get_xim (locale, modifiers); |
1338 | if (input_method == NULL) |
1269 | if (input_method == NULL) |
1339 | return false; |
1270 | return false; |
1340 | |
1271 | |
1341 | xim = input_method->xim; |
1272 | xim = input_method->xim; |
… | |
… | |
1487 | rxvt_warn ("failed to create input context, continuing without XIM.\n"); |
1418 | rxvt_warn ("failed to create input context, continuing without XIM.\n"); |
1488 | im_destroy (); |
1419 | im_destroy (); |
1489 | return false; |
1420 | return false; |
1490 | } |
1421 | } |
1491 | |
1422 | |
|
|
1423 | if (!XGetICValues (Input_Context, XNFilterEvents, &vt_emask_xim, NULL)) |
|
|
1424 | vt_select_input (); |
|
|
1425 | |
1492 | if (input_style & XIMPreeditArea) |
1426 | if (input_style & XIMPreeditArea) |
1493 | IMSetStatusPosition (); |
1427 | IMSetStatusPosition (); |
1494 | |
1428 | |
1495 | D_MAIN ((stderr, "rxvt_IM_get_IC () - successful connection")); |
|
|
1496 | return true; |
1429 | return true; |
1497 | } |
1430 | } |
1498 | |
1431 | |
1499 | void |
1432 | void |
1500 | rxvt_term::im_cb () |
1433 | rxvt_term::im_cb () |
… | |
… | |
1506 | |
1439 | |
1507 | make_current (); |
1440 | make_current (); |
1508 | |
1441 | |
1509 | im_destroy (); |
1442 | im_destroy (); |
1510 | |
1443 | |
1511 | D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); |
|
|
1512 | if (Input_Context) |
1444 | if (Input_Context) |
1513 | return; |
1445 | return; |
1514 | |
1446 | |
1515 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
1447 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
1516 | if (rs[Rs_imLocale]) |
1448 | if (rs[Rs_imLocale]) |
… | |
… | |
1589 | XFree (preedit_attr); |
1521 | XFree (preedit_attr); |
1590 | XFree (status_attr); |
1522 | XFree (status_attr); |
1591 | } |
1523 | } |
1592 | #endif /* USE_XIM */ |
1524 | #endif /* USE_XIM */ |
1593 | |
1525 | |
1594 | /*----------------------------------------------------------------------*/ |
|
|
1595 | rxvt_t rxvt_current_term; |
|
|
1596 | |
|
|
1597 | /*----------------------- end-of-file (C source) -----------------------*/ |
1526 | /*----------------------- end-of-file (C source) -----------------------*/ |