… | |
… | |
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 ()) |
… | |
… | |
468 | #ifdef HAVE_SCROLLBARS |
474 | #ifdef HAVE_SCROLLBARS |
469 | if (OPTION (Opt_scrollBar)) |
475 | if (OPTION (Opt_scrollBar)) |
470 | scrollBar.setIdle (); /* set existence for size calculations */ |
476 | scrollBar.setIdle (); /* set existence for size calculations */ |
471 | #endif |
477 | #endif |
472 | |
478 | |
473 | #if ENABLE_PERL |
479 | pty = ptytty::create (); |
474 | if (!rs[Rs_perl_ext_1]) |
|
|
475 | rs[Rs_perl_ext_1] = "default"; |
|
|
476 | |
|
|
477 | if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) |
|
|
478 | || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) |
|
|
479 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
|
|
480 | { |
|
|
481 | rxvt_perl.init (this); |
|
|
482 | HOOK_INVOKE ((this, HOOK_INIT, DT_END)); |
|
|
483 | } |
|
|
484 | #endif |
|
|
485 | |
|
|
486 | pty = rxvt_new_ptytty (); |
|
|
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 |
… | |
… | |
557 | char **rxvt_environ; // startup environment |
550 | char **rxvt_environ; // startup environment |
558 | |
551 | |
559 | void |
552 | void |
560 | rxvt_init () |
553 | rxvt_init () |
561 | { |
554 | { |
562 | uid_t uid = getuid (); |
555 | 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 | |
556 | |
593 | rxvt_environ = environ; |
557 | rxvt_environ = environ; |
594 | |
558 | |
595 | signal (SIGHUP, SIG_IGN); |
559 | signal (SIGHUP, SIG_IGN); |
596 | signal (SIGPIPE, SIG_IGN); |
560 | signal (SIGPIPE, SIG_IGN); |
… | |
… | |
631 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
595 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
632 | |
596 | |
633 | return p; |
597 | return p; |
634 | } |
598 | } |
635 | |
599 | |
636 | void * |
600 | void * |
637 | rxvt_realloc (void *ptr, size_t size) |
601 | rxvt_realloc (void *ptr, size_t size) |
638 | { |
602 | { |
639 | void *p = realloc (ptr, size); |
603 | void *p = realloc (ptr, size); |
640 | |
604 | |
641 | if (!p) |
605 | if (!p) |
… | |
… | |
1067 | * -------------------------------------------------------------------- */ |
1031 | * -------------------------------------------------------------------- */ |
1068 | void |
1032 | void |
1069 | rxvt_term::resize_all_windows (unsigned int newwidth, unsigned int newheight, int ignoreparent) |
1033 | rxvt_term::resize_all_windows (unsigned int newwidth, unsigned int newheight, int ignoreparent) |
1070 | { |
1034 | { |
1071 | int fix_screen; |
1035 | int fix_screen; |
1072 | int old_width = szHint.width, old_height = szHint.height; |
1036 | int old_width = szHint.width; |
|
|
1037 | int old_height = szHint.height; |
1073 | dDisp; |
1038 | dDisp; |
1074 | |
1039 | |
1075 | window_calc (newwidth, newheight); |
1040 | window_calc (newwidth, newheight); |
1076 | XSetWMNormalHints (disp, parent[0], &szHint); |
1041 | XSetWMNormalHints (disp, parent[0], &szHint); |
1077 | |
1042 | |
… | |
… | |
1099 | { |
1064 | { |
1100 | x -= x1; |
1065 | x -= x1; |
1101 | y -= y1; |
1066 | y -= y1; |
1102 | } |
1067 | } |
1103 | |
1068 | |
1104 | x1 = (DisplayWidth (disp, display->screen) - old_width) / 2; |
1069 | x1 = (DisplayWidth (disp, display->screen) - old_width ) / 2; |
1105 | y1 = (DisplayHeight (disp, display->screen) - old_height) / 2; |
1070 | y1 = (DisplayHeight (disp, display->screen) - old_height) / 2; |
1106 | dx = old_width - szHint.width; |
1071 | dx = old_width - szHint.width; |
1107 | dy = old_height - szHint.height; |
1072 | dy = old_height - szHint.height; |
1108 | |
1073 | |
1109 | /* Check position of the center of the window */ |
1074 | /* Check position of the center of the window */ |
1110 | if (x < x1) /* left half */ |
1075 | if (x < x1) /* left half */ |
1111 | dx = 0; |
1076 | dx = 0; |
… | |
… | |
1144 | resize_pixmap (); |
1109 | resize_pixmap (); |
1145 | #endif |
1110 | #endif |
1146 | } |
1111 | } |
1147 | |
1112 | |
1148 | if (fix_screen || old_height == 0) |
1113 | 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 (); |
1114 | 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 | |
1115 | |
1174 | #ifdef XPM_BACKGROUND |
1116 | #ifdef XPM_BACKGROUND |
1175 | if (pixmap) |
1117 | if (pixmap) |
1176 | scr_touch (false); |
1118 | scr_touch (false); |
1177 | #endif |
1119 | #endif |
… | |
… | |
1486 | { |
1428 | { |
1487 | rxvt_warn ("failed to create input context, continuing without XIM.\n"); |
1429 | rxvt_warn ("failed to create input context, continuing without XIM.\n"); |
1488 | im_destroy (); |
1430 | im_destroy (); |
1489 | return false; |
1431 | return false; |
1490 | } |
1432 | } |
|
|
1433 | |
|
|
1434 | if (!XGetICValues (Input_Context, XNFilterEvents, &vt_emask_xim, NULL)) |
|
|
1435 | vt_select_input (); |
1491 | |
1436 | |
1492 | if (input_style & XIMPreeditArea) |
1437 | if (input_style & XIMPreeditArea) |
1493 | IMSetStatusPosition (); |
1438 | IMSetStatusPosition (); |
1494 | |
1439 | |
1495 | D_MAIN ((stderr, "rxvt_IM_get_IC () - successful connection")); |
1440 | D_MAIN ((stderr, "rxvt_IM_get_IC () - successful connection")); |
… | |
… | |
1589 | XFree (preedit_attr); |
1534 | XFree (preedit_attr); |
1590 | XFree (status_attr); |
1535 | XFree (status_attr); |
1591 | } |
1536 | } |
1592 | #endif /* USE_XIM */ |
1537 | #endif /* USE_XIM */ |
1593 | |
1538 | |
1594 | /*----------------------------------------------------------------------*/ |
|
|
1595 | rxvt_t rxvt_current_term; |
|
|
1596 | |
|
|
1597 | /*----------------------- end-of-file (C source) -----------------------*/ |
1539 | /*----------------------- end-of-file (C source) -----------------------*/ |