… | |
… | |
450 | _exit (EXIT_FAILURE); |
450 | _exit (EXIT_FAILURE); |
451 | } |
451 | } |
452 | |
452 | |
453 | /*----------------------------------------------------------------------*/ |
453 | /*----------------------------------------------------------------------*/ |
454 | bool |
454 | bool |
455 | rxvt_term::init (int argc, const char *const *argv) |
455 | rxvt_term::init (int argc, const char *const *argv, stringvec *envv) |
456 | { |
456 | { |
|
|
457 | this->envv = envv; |
|
|
458 | |
457 | SET_R (this); |
459 | SET_R (this); |
458 | set_locale (""); |
460 | set_locale (""); |
459 | set_environ (envv); // few things in X do not call setlocale :( |
461 | set_environ (envv); // few things in X do not call setlocale :( |
460 | |
462 | |
461 | if (!init_vars ()) |
463 | if (!init_vars ()) |
… | |
… | |
472 | #ifdef HAVE_SCROLLBARS |
474 | #ifdef HAVE_SCROLLBARS |
473 | if (OPTION (Opt_scrollBar)) |
475 | if (OPTION (Opt_scrollBar)) |
474 | scrollBar.setIdle (); /* set existence for size calculations */ |
476 | scrollBar.setIdle (); /* set existence for size calculations */ |
475 | #endif |
477 | #endif |
476 | |
478 | |
477 | pty = rxvt_new_ptytty (); |
479 | pty = ptytty::create (); |
478 | |
480 | |
479 | create_windows (argc, argv); |
481 | create_windows (argc, argv); |
480 | |
482 | |
481 | dDisp; |
483 | dDisp; |
482 | |
484 | |
… | |
… | |
528 | * Catch a fatal signal and tidy up before quitting |
530 | * Catch a fatal signal and tidy up before quitting |
529 | */ |
531 | */ |
530 | void |
532 | void |
531 | sig_term (sig_watcher &w) |
533 | sig_term (sig_watcher &w) |
532 | { |
534 | { |
533 | #ifdef DEBUG_CMD |
|
|
534 | rxvt_warn ("caught signal %d, exiting.\n", w.signum); |
|
|
535 | #endif |
|
|
536 | rxvt_emergency_cleanup (); |
535 | rxvt_emergency_cleanup (); |
537 | signal (w.signum, SIG_DFL); |
536 | signal (w.signum, SIG_DFL); |
538 | kill (getpid (), w.signum); |
537 | kill (getpid (), w.signum); |
539 | } |
538 | } |
540 | |
539 | |
… | |
… | |
548 | char **rxvt_environ; // startup environment |
547 | char **rxvt_environ; // startup environment |
549 | |
548 | |
550 | void |
549 | void |
551 | rxvt_init () |
550 | rxvt_init () |
552 | { |
551 | { |
553 | uid_t uid = getuid (); |
552 | ptytty::init (); |
554 | gid_t gid = getgid (); |
|
|
555 | |
|
|
556 | // before doing anything else, check for setuid/setgid operation, |
|
|
557 | // start the helper process and drop privileges |
|
|
558 | if (uid != geteuid () |
|
|
559 | || gid != getegid ()) |
|
|
560 | { |
|
|
561 | #if PTYTTY_HELPER |
|
|
562 | rxvt_ptytty_server (); |
|
|
563 | #else |
|
|
564 | rxvt_warn ("running setuid/setgid without pty helper compiled in, continuing unprivileged.\n"); |
|
|
565 | #endif |
|
|
566 | |
|
|
567 | // drop privileges |
|
|
568 | #if HAVE_SETRESUID |
|
|
569 | setresgid (gid, gid, gid); |
|
|
570 | setresuid (uid, uid, uid); |
|
|
571 | #elif HAVE_SETREUID |
|
|
572 | setregid (gid, gid); |
|
|
573 | setreuid (uid, uid); |
|
|
574 | #elif HAVE_SETUID |
|
|
575 | setgid (gid); |
|
|
576 | setuid (uid); |
|
|
577 | #endif |
|
|
578 | |
|
|
579 | if (uid != geteuid () |
|
|
580 | || gid != getegid ()) |
|
|
581 | rxvt_fatal ("unable to drop privileges, aborting.\n"); |
|
|
582 | } |
|
|
583 | |
553 | |
584 | rxvt_environ = environ; |
554 | rxvt_environ = environ; |
585 | |
555 | |
586 | signal (SIGHUP, SIG_IGN); |
556 | signal (SIGHUP, SIG_IGN); |
587 | signal (SIGPIPE, SIG_IGN); |
557 | signal (SIGPIPE, SIG_IGN); |
… | |
… | |
646 | short recalc_x, recalc_y; |
616 | short recalc_x, recalc_y; |
647 | int x, y, sb_w, flags; |
617 | int x, y, sb_w, flags; |
648 | unsigned int w, h; |
618 | unsigned int w, h; |
649 | unsigned int max_width, max_height; |
619 | unsigned int max_width, max_height; |
650 | dDisp; |
620 | dDisp; |
651 | |
|
|
652 | D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
|
|
653 | ncol, nrow, szHint.width, szHint.height)); |
|
|
654 | |
621 | |
655 | szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; |
622 | szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; |
656 | szHint.win_gravity = NorthWestGravity; |
623 | szHint.win_gravity = NorthWestGravity; |
657 | /* szHint.min_aspect.x = szHint.min_aspect.y = 1; */ |
624 | /* szHint.min_aspect.x = szHint.min_aspect.y = 1; */ |
658 | |
625 | |
… | |
… | |
761 | if (recalc_y) |
728 | if (recalc_y) |
762 | szHint.y += DisplayHeight (disp, display->screen) - szHint.height - 2 * ext_bwidth; |
729 | szHint.y += DisplayHeight (disp, display->screen) - szHint.height - 2 * ext_bwidth; |
763 | |
730 | |
764 | ncol = width / fwidth; |
731 | ncol = width / fwidth; |
765 | nrow = height / fheight; |
732 | nrow = height / fheight; |
766 | D_SIZE ((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
|
|
767 | ncol, nrow, szHint.width, |
|
|
768 | szHint.height)); |
|
|
769 | return; |
|
|
770 | } |
733 | } |
771 | |
734 | |
772 | /*----------------------------------------------------------------------*/ |
735 | /*----------------------------------------------------------------------*/ |
773 | /* |
736 | /* |
774 | * Tell the teletype handler what size the window is. |
737 | * Tell the teletype handler what size the window is. |
… | |
… | |
1058 | * -------------------------------------------------------------------- */ |
1021 | * -------------------------------------------------------------------- */ |
1059 | void |
1022 | void |
1060 | 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) |
1061 | { |
1024 | { |
1062 | int fix_screen; |
1025 | int fix_screen; |
1063 | int old_width = szHint.width, old_height = szHint.height; |
1026 | int old_width = szHint.width; |
|
|
1027 | int old_height = szHint.height; |
1064 | dDisp; |
1028 | dDisp; |
1065 | |
1029 | |
1066 | window_calc (newwidth, newheight); |
1030 | window_calc (newwidth, newheight); |
1067 | XSetWMNormalHints (disp, parent[0], &szHint); |
1031 | XSetWMNormalHints (disp, parent[0], &szHint); |
1068 | |
1032 | |
… | |
… | |
1090 | { |
1054 | { |
1091 | x -= x1; |
1055 | x -= x1; |
1092 | y -= y1; |
1056 | y -= y1; |
1093 | } |
1057 | } |
1094 | |
1058 | |
1095 | x1 = (DisplayWidth (disp, display->screen) - old_width) / 2; |
1059 | x1 = (DisplayWidth (disp, display->screen) - old_width ) / 2; |
1096 | y1 = (DisplayHeight (disp, display->screen) - old_height) / 2; |
1060 | y1 = (DisplayHeight (disp, display->screen) - old_height) / 2; |
1097 | dx = old_width - szHint.width; |
1061 | dx = old_width - szHint.width; |
1098 | dy = old_height - szHint.height; |
1062 | dy = old_height - szHint.height; |
1099 | |
1063 | |
1100 | /* Check position of the center of the window */ |
1064 | /* Check position of the center of the window */ |
1101 | if (x < x1) /* left half */ |
1065 | if (x < x1) /* left half */ |
1102 | dx = 0; |
1066 | dx = 0; |
… | |
… | |
1135 | resize_pixmap (); |
1099 | resize_pixmap (); |
1136 | #endif |
1100 | #endif |
1137 | } |
1101 | } |
1138 | |
1102 | |
1139 | if (fix_screen || old_height == 0) |
1103 | if (fix_screen || old_height == 0) |
1140 | { |
|
|
1141 | int curr_screen = -1; |
|
|
1142 | int old_ncol = prev_ncol; |
|
|
1143 | |
|
|
1144 | /* scr_reset only works on the primary screen */ |
|
|
1145 | if (old_height) /* this is not the first time through */ |
|
|
1146 | { |
|
|
1147 | unsigned int ocol = ncol; |
|
|
1148 | ncol = prev_ncol; // save b/c scr_blank_screen_mem uses this |
|
|
1149 | curr_screen = scr_change_screen (PRIMARY); |
|
|
1150 | ncol = ocol; |
|
|
1151 | } |
|
|
1152 | |
|
|
1153 | scr_reset (); |
1104 | scr_reset (); |
1154 | |
|
|
1155 | if (curr_screen >= 0) /* this is not the first time through */ |
|
|
1156 | { |
|
|
1157 | scr_change_screen (curr_screen); |
|
|
1158 | selection_check (old_ncol != ncol ? 4 : 0); |
|
|
1159 | } |
|
|
1160 | } |
|
|
1161 | |
|
|
1162 | old_width = szHint.width; |
|
|
1163 | old_height = szHint.height; |
|
|
1164 | |
1105 | |
1165 | #ifdef XPM_BACKGROUND |
1106 | #ifdef XPM_BACKGROUND |
1166 | if (pixmap) |
1107 | if (pixmap) |
1167 | scr_touch (false); |
1108 | scr_touch (false); |
1168 | #endif |
1109 | #endif |
… | |
… | |
1322 | set_environ (envv); |
1263 | set_environ (envv); |
1323 | |
1264 | |
1324 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1265 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1325 | return false; |
1266 | return false; |
1326 | |
1267 | |
1327 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
|
|
1328 | input_method = display->get_xim (locale, modifiers); |
1268 | input_method = display->get_xim (locale, modifiers); |
1329 | if (input_method == NULL) |
1269 | if (input_method == NULL) |
1330 | return false; |
1270 | return false; |
1331 | |
1271 | |
1332 | xim = input_method->xim; |
1272 | xim = input_method->xim; |
… | |
… | |
1478 | rxvt_warn ("failed to create input context, continuing without XIM.\n"); |
1418 | rxvt_warn ("failed to create input context, continuing without XIM.\n"); |
1479 | im_destroy (); |
1419 | im_destroy (); |
1480 | return false; |
1420 | return false; |
1481 | } |
1421 | } |
1482 | |
1422 | |
|
|
1423 | if (!XGetICValues (Input_Context, XNFilterEvents, &vt_emask_xim, NULL)) |
|
|
1424 | vt_select_input (); |
|
|
1425 | |
1483 | if (input_style & XIMPreeditArea) |
1426 | if (input_style & XIMPreeditArea) |
1484 | IMSetStatusPosition (); |
1427 | IMSetStatusPosition (); |
1485 | |
1428 | |
1486 | D_MAIN ((stderr, "rxvt_IM_get_IC () - successful connection")); |
|
|
1487 | return true; |
1429 | return true; |
1488 | } |
1430 | } |
1489 | |
1431 | |
1490 | void |
1432 | void |
1491 | rxvt_term::im_cb () |
1433 | rxvt_term::im_cb () |
… | |
… | |
1497 | |
1439 | |
1498 | make_current (); |
1440 | make_current (); |
1499 | |
1441 | |
1500 | im_destroy (); |
1442 | im_destroy (); |
1501 | |
1443 | |
1502 | D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); |
|
|
1503 | if (Input_Context) |
1444 | if (Input_Context) |
1504 | return; |
1445 | return; |
1505 | |
1446 | |
1506 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
1447 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
1507 | if (rs[Rs_imLocale]) |
1448 | if (rs[Rs_imLocale]) |