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