ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/main.C
(Generate patch)

Comparing rxvt-unicode/src/main.C (file contents):
Revision 1.150 by root, Wed Dec 21 14:19:19 2005 UTC vs.
Revision 1.189 by root, Thu Jan 19 09:47:15 2006 UTC

11 * Copyright (c) 1997 mj olesen <olesen@me.QueensU.CA> 11 * Copyright (c) 1997 mj olesen <olesen@me.QueensU.CA>
12 * - extensive modifications 12 * - extensive modifications
13 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> 13 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de>
14 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> 14 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com>
15 * - extensive modifications 15 * - extensive modifications
16 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> 16 * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com>
17 * 17 *
18 * This program is free software; you can redistribute it and/or modify 18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by 19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or 20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version. 21 * (at your option) any later version.
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 *---------------------------------------------------------------------*/ 31 *---------------------------------------------------------------------*/
32 32
33#include "../config.h" /* NECESSARY */ 33#include "../config.h" /* NECESSARY */
34#include "rxvt.h" /* NECESSARY */ 34#include "rxvt.h" /* NECESSARY */
35#include "keyboard.h"
36#include "rxvtperl.h"
37
38#include <limits>
35 39
36#include <csignal> 40#include <csignal>
37#include <cstring> 41#include <cstring>
38 42
39#ifdef TTY_GID_SUPPORT 43#ifdef TTY_GID_SUPPORT
42 46
43#ifdef HAVE_TERMIOS_H 47#ifdef HAVE_TERMIOS_H
44# include <termios.h> 48# include <termios.h>
45#endif 49#endif
46 50
47#ifdef KEYSYM_RESOURCE
48# include "keyboard.h"
49#endif
50
51vector<rxvt_term *> rxvt_term::termlist; 51vector<rxvt_term *> rxvt_term::termlist;
52 52
53static char curlocale[128]; 53static char curlocale[128], savelocale[128];
54 54
55bool 55bool
56rxvt_set_locale (const char *locale) 56rxvt_set_locale (const char *locale)
57{ 57{
58 if (!locale || !strncmp (locale, curlocale, 128)) 58 if (!locale || !strncmp (locale, curlocale, 128))
59 return false; 59 return false;
60 60
61 strncpy (curlocale, locale, 128); 61 strncpy (curlocale, locale, 128);
62 setlocale (LC_CTYPE, curlocale); 62 setlocale (LC_CTYPE, curlocale);
63 return true; 63 return true;
64}
65
66void
67rxvt_push_locale (const char *locale)
68{
69 strcpy (savelocale, curlocale);
70 rxvt_set_locale (locale);
71}
72
73void
74rxvt_pop_locale ()
75{
76 rxvt_set_locale (savelocale);
64} 77}
65 78
66#if ENABLE_COMBINING 79#if ENABLE_COMBINING
67class rxvt_composite_vec rxvt_composite; 80class rxvt_composite_vec rxvt_composite;
68 81
133 rootwin_ev (this, &rxvt_term::rootwin_cb), 146 rootwin_ev (this, &rxvt_term::rootwin_cb),
134#endif 147#endif
135#ifdef HAVE_SCROLLBARS 148#ifdef HAVE_SCROLLBARS
136 scrollbar_ev (this, &rxvt_term::x_cb), 149 scrollbar_ev (this, &rxvt_term::x_cb),
137#endif 150#endif
138#ifdef MENUBAR
139 menubar_ev (this, &rxvt_term::x_cb),
140#endif
141#ifdef CURSOR_BLINK 151#ifdef CURSOR_BLINK
142 cursor_blink_ev (this, &rxvt_term::cursor_blink_cb), 152 cursor_blink_ev (this, &rxvt_term::cursor_blink_cb),
143#endif 153#endif
144#ifdef TEXT_BLINK 154#ifdef TEXT_BLINK
145 text_blink_ev (this, &rxvt_term::text_blink_cb), 155 text_blink_ev (this, &rxvt_term::text_blink_cb),
159#ifdef USE_XIM 169#ifdef USE_XIM
160 im_ev (this, &rxvt_term::im_cb), 170 im_ev (this, &rxvt_term::im_cb),
161#endif 171#endif
162 termwin_ev (this, &rxvt_term::x_cb), 172 termwin_ev (this, &rxvt_term::x_cb),
163 vt_ev (this, &rxvt_term::x_cb), 173 vt_ev (this, &rxvt_term::x_cb),
174 child_ev (this, &rxvt_term::child_cb),
164 check_ev (this, &rxvt_term::check_cb), 175 check_ev (this, &rxvt_term::check_cb),
165 flush_ev (this, &rxvt_term::flush_cb), 176 flush_ev (this, &rxvt_term::flush_cb),
166 destroy_ev (this, &rxvt_term::destroy_cb), 177 destroy_ev (this, &rxvt_term::destroy_cb),
167 pty_ev (this, &rxvt_term::pty_cb), 178 pty_ev (this, &rxvt_term::pty_cb),
168 incr_ev (this, &rxvt_term::incr_cb) 179 incr_ev (this, &rxvt_term::incr_cb)
184void rxvt_term::emergency_cleanup () 195void rxvt_term::emergency_cleanup ()
185{ 196{
186 if (cmd_pid) 197 if (cmd_pid)
187 kill (-cmd_pid, SIGHUP); 198 kill (-cmd_pid, SIGHUP);
188 199
189#ifdef UTMP_SUPPORT 200 delete pty; pty = 0;
190 privileged_utmp (RESTORE);
191#endif
192
193 pty.put ();
194} 201}
195 202
196rxvt_term::~rxvt_term () 203rxvt_term::~rxvt_term ()
197{ 204{
205 HOOK_INVOKE ((this, HOOK_DESTROY, DT_END));
206
198 termlist.erase (find (termlist.begin (), termlist.end(), this)); 207 termlist.erase (find (termlist.begin (), termlist.end(), this));
199 208
200 emergency_cleanup (); 209 emergency_cleanup ();
201 210
202#if ENABLE_STYLES 211#if ENABLE_STYLES
212 221
213 selection_clear (); 222 selection_clear ();
214 223
215#ifdef USE_XIM 224#ifdef USE_XIM
216 im_destroy (); 225 im_destroy ();
217#endif
218#ifdef MENUBAR
219 if (menubarGC) XFreeGC (disp, menubarGC);
220#endif 226#endif
221#ifdef XTERM_SCROLLBAR 227#ifdef XTERM_SCROLLBAR
222 if (xscrollbarGC) XFreeGC (disp, xscrollbarGC); 228 if (xscrollbarGC) XFreeGC (disp, xscrollbarGC);
223 if (ShadowGC) XFreeGC (disp, ShadowGC); 229 if (ShadowGC) XFreeGC (disp, ShadowGC);
224#endif 230#endif
235 if (upArrow) XFreePixmap (disp, upArrow); 241 if (upArrow) XFreePixmap (disp, upArrow);
236 if (downArrow) XFreePixmap (disp, downArrow); 242 if (downArrow) XFreePixmap (disp, downArrow);
237 if (upArrowHi) XFreePixmap (disp, upArrowHi); 243 if (upArrowHi) XFreePixmap (disp, upArrowHi);
238 if (downArrowHi) XFreePixmap (disp, downArrowHi); 244 if (downArrowHi) XFreePixmap (disp, downArrowHi);
239#endif 245#endif
240#if defined(MENUBAR) || defined(RXVT_SCROLLBAR) 246#ifdef RXVT_SCROLLBAR
241 if (topShadowGC) XFreeGC (disp, topShadowGC); 247 if (topShadowGC) XFreeGC (disp, topShadowGC);
242 if (botShadowGC) XFreeGC (disp, botShadowGC); 248 if (botShadowGC) XFreeGC (disp, botShadowGC);
243 if (scrollbarGC) XFreeGC (disp, scrollbarGC); 249 if (scrollbarGC) XFreeGC (disp, scrollbarGC);
244#endif 250#endif
245 if (gc) XFreeGC (disp, gc); 251 if (gc) XFreeGC (disp, gc);
246 252
247#if defined(MENUBAR) && (MENUBAR_MAX > 1)
248 delete menuBar.drawable;
249 //if (menuBar.win)
250 // XDestroyWindow (disp, menuBar.win);
251#endif
252 delete drawable; 253 delete drawable;
253 // destroy all windows 254 // destroy all windows
254 if (parent[0]) 255 if (parent[0])
255 XDestroyWindow (disp, parent[0]); 256 XDestroyWindow (disp, parent[0]);
256 } 257 }
257 258
258 // TODO: free pixcolours, colours should become part of rxvt_display 259 // TODO: free pixcolours, colours should become part of rxvt_display
259
260 delete pix_colors_focused; 260 delete pix_colors_focused;
261#if OFF_FOCUS_FADING 261#if OFF_FOCUS_FADING
262 delete pix_colors_unfocused; 262 delete pix_colors_unfocused;
263#endif 263#endif
264 264
286#ifdef KEYSYM_RESOURCE 286#ifdef KEYSYM_RESOURCE
287 delete keyboard; 287 delete keyboard;
288#endif 288#endif
289} 289}
290 290
291// child has exited, usually destroys
292void
293rxvt_term::child_cb (child_watcher &w, int status)
294{
295 HOOK_INVOKE ((this, HOOK_CHILD_EXIT, DT_INT, status, DT_END));
296
297 cmd_pid = 0;
298
299 if (!OPTION (Opt_hold))
300 destroy ();
301}
302
291void 303void
292rxvt_term::destroy () 304rxvt_term::destroy ()
293{ 305{
294 if (destroy_ev.active) 306 if (destroy_ev.active)
295 return; 307 return;
303#if USE_XIM 315#if USE_XIM
304 im_ev.stop (display); 316 im_ev.stop (display);
305#endif 317#endif
306#if HAVE_SCROLLBARS 318#if HAVE_SCROLLBARS
307 scrollbar_ev.stop (display); 319 scrollbar_ev.stop (display);
308#endif
309#if MENUBAR
310 menubar_ev.stop (display);
311#endif 320#endif
312#if TRANSPARENT 321#if TRANSPARENT
313 rootwin_ev.stop (display); 322 rootwin_ev.stop (display);
314#endif 323#endif
315 incr_ev.stop (); 324 incr_ev.stop ();
339} 348}
340 349
341void 350void
342rxvt_term::destroy_cb (time_watcher &w) 351rxvt_term::destroy_cb (time_watcher &w)
343{ 352{
344 SET_R (this); 353 make_current ();
345 354
346 delete this; 355 delete this;
347} 356}
348 357
349/*----------------------------------------------------------------------*/ 358/*----------------------------------------------------------------------*/
440/*----------------------------------------------------------------------*/ 449/*----------------------------------------------------------------------*/
441bool 450bool
442rxvt_term::init (int argc, const char *const *argv) 451rxvt_term::init (int argc, const char *const *argv)
443{ 452{
444 SET_R (this); 453 SET_R (this);
445
446 set_locale (""); 454 set_locale ("");
455 set_environ (envv); // few things in X do not call setlocale :(
447 456
448 if (!init_vars ()) 457 if (!init_vars ())
449 return false; 458 return false;
450 459
451 init_secondary (); 460 init_secondary ();
454 463
455#ifdef KEYSYM_RESOURCE 464#ifdef KEYSYM_RESOURCE
456 keyboard->register_done (); 465 keyboard->register_done ();
457#endif 466#endif
458 467
459#if MENUBAR_MAX
460 menubar_read (rs[Rs_menu]);
461#endif
462#ifdef HAVE_SCROLLBARS 468#ifdef HAVE_SCROLLBARS
463 if (options & Opt_scrollBar) 469 if (OPTION (Opt_scrollBar))
464 scrollBar.setIdle (); /* set existence for size calculations */ 470 scrollBar.setIdle (); /* set existence for size calculations */
465#endif 471#endif
466 472
473#if ENABLE_PERL
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
467 create_windows (argc, argv); 488 create_windows (argc, argv);
468 489
469 dDisp; 490 dDisp;
470 491
471 init_xlocale (); 492 init_xlocale ();
472 493
473 scr_reset (); /* initialize screen */ 494 scr_reset (); // initialize screen
474 495
475#if 0 496#if 0
476 XSynchronize (disp, True); 497 XSynchronize (disp, True);
477#endif 498#endif
478 499
479#ifdef HAVE_SCROLLBARS 500#ifdef HAVE_SCROLLBARS
480 if (options & Opt_scrollBar) 501 if (OPTION (Opt_scrollBar))
481 resize_scrollbar (); /* create and map scrollbar */ 502 resize_scrollbar (); /* create and map scrollbar */
482#endif 503#endif
483#if (MENUBAR_MAX)
484 if (menubar_visible ())
485 XMapWindow (disp, menuBar.win);
486#endif
487#ifdef TRANSPARENT 504#ifdef TRANSPARENT
488 if (options & Opt_transparent) 505 if (OPTION (Opt_transparent))
489 { 506 {
490 XSelectInput (disp, display->root, PropertyChangeMask); 507 XSelectInput (disp, display->root, PropertyChangeMask);
491 check_our_parents (); 508 check_our_parents ();
492 rootwin_ev.start (display, display->root); 509 rootwin_ev.start (display, display->root);
493 } 510 }
500 517
501 init_command (cmd_argv); 518 init_command (cmd_argv);
502 519
503 free (cmd_argv); 520 free (cmd_argv);
504 521
522 if (pty->pty >= 0)
505 pty_ev.start (pty.pty, EVENT_READ); 523 pty_ev.start (pty->pty, EVENT_READ);
506 524
507 check_ev.start (); 525 check_ev.start ();
508 526
527 HOOK_INVOKE ((this, HOOK_START, DT_END));
528
509 return true; 529 return true;
510} 530}
511 531
512static struct sig_handlers 532static struct sig_handlers
513{ 533{
514 sig_watcher sw_chld, sw_term, sw_int; 534 sig_watcher sw_term, sw_int;
515 535
516 void sig_chld (sig_watcher &w)
517 {
518 // we are being called for every SIGCHLD, find the corresponding term
519 int pid;
520
521 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0)
522 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
523 if (pid == (*t)->cmd_pid)
524 {
525 (*t)->destroy ();
526 break;
527 }
528 }
529
530 /* 536 /*
531 * Catch a fatal signal and tidy up before quitting 537 * Catch a fatal signal and tidy up before quitting
532 */ 538 */
533 void 539 void
534 sig_term (sig_watcher &w) 540 sig_term (sig_watcher &w)
540 signal (w.signum, SIG_DFL); 546 signal (w.signum, SIG_DFL);
541 kill (getpid (), w.signum); 547 kill (getpid (), w.signum);
542 } 548 }
543 549
544 sig_handlers () 550 sig_handlers ()
545 : sw_chld (this, &sig_handlers::sig_chld),
546 sw_term (this, &sig_handlers::sig_term), 551 : sw_term (this, &sig_handlers::sig_term),
547 sw_int (this, &sig_handlers::sig_term) 552 sw_int (this, &sig_handlers::sig_term)
548 { 553 {
549 } 554 }
550} sig_handlers; 555} sig_handlers;
551 556
557char **rxvt_environ; // startup environment
558
552void 559void
553rxvt_init () 560rxvt_init ()
554{ 561{
555 /* 562 uid_t uid = getuid ();
556 * Save and then give up any super-user privileges 563 gid_t gid = getgid ();
557 * If we need privileges in any area then we must specifically request it. 564
558 * We should only need to be root in these cases: 565 // before doing anything else, check for setuid/setgid operation,
559 * 1. write utmp entries on some systems 566 // start the helper process and drop privileges
560 * 2. chown tty on some systems 567 if (uid != geteuid ()
561 */ 568 || gid != getegid ())
562 rxvt_privileges (SAVE); 569 {
563 rxvt_privileges (IGNORE); 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
593 rxvt_environ = environ;
564 594
565 signal (SIGHUP, SIG_IGN); 595 signal (SIGHUP, SIG_IGN);
566 signal (SIGPIPE, SIG_IGN); 596 signal (SIGPIPE, SIG_IGN);
567 597
568 sig_handlers.sw_chld.start (SIGCHLD);
569 sig_handlers.sw_term.start (SIGTERM); 598 sig_handlers.sw_term.start (SIGTERM);
570 sig_handlers.sw_int.start (SIGINT); 599 sig_handlers.sw_int.start (SIGINT);
571 600
572 /* need to trap SIGURG for SVR4 (Unixware) rlogin */ 601 /* need to trap SIGURG for SVR4 (Unixware) rlogin */
573 /* signal (SIGURG, SIG_DFL); */ 602 /* signal (SIGURG, SIG_DFL); */
574 603
575 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 604 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
576 // TODO: handle this with exceptions and tolerate the memory loss 605 // TODO: handle this with exceptions and tolerate the memory loss
577 XSetIOErrorHandler (rxvt_xioerror_handler); 606 XSetIOErrorHandler (rxvt_xioerror_handler);
607
608 XrmInitialize ();
578} 609}
579 610
580/* ------------------------------------------------------------------------- * 611/* ------------------------------------------------------------------------- *
581 * MEMORY ALLOCATION WRAPPERS * 612 * MEMORY ALLOCATION WRAPPERS *
582 * ------------------------------------------------------------------------- */ 613 * ------------------------------------------------------------------------- */
611 rxvt_fatal ("memory allocation failure. aborting.\n"); 642 rxvt_fatal ("memory allocation failure. aborting.\n");
612 643
613 return p; 644 return p;
614} 645}
615 646
616/* ------------------------------------------------------------------------- *
617 * PRIVILEGED OPERATIONS *
618 * ------------------------------------------------------------------------- */
619/* take care of suid/sgid super-user (root) privileges */
620void
621rxvt_privileges (rxvt_privaction action)
622{
623#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
624 static uid_t euid;
625 static gid_t egid;
626#endif
627
628#if ! defined(__CYGWIN32__)
629# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID)
630 /* setreuid () is the poor man's setuid (), seteuid () */
631# define seteuid(a) setreuid(-1, (a))
632# define setegid(a) setregid(-1, (a))
633# define HAVE_SETEUID
634# endif
635# ifdef HAVE_SETEUID
636 switch (action)
637 {
638 case IGNORE:
639 /*
640 * change effective uid/gid - not real uid/gid - so we can switch
641 * back to root later, as required
642 */
643 seteuid (getuid ());
644 setegid (getgid ());
645 break;
646 case SAVE:
647 euid = geteuid ();
648 egid = getegid ();
649 break;
650 case RESTORE:
651 seteuid (euid);
652 setegid (egid);
653 break;
654 }
655# else
656 switch (action)
657 {
658 case IGNORE:
659 setuid (getuid ());
660 setgid (getgid ());
661 /* FALLTHROUGH */
662 case SAVE:
663 /* FALLTHROUGH */
664 case RESTORE:
665 break;
666 }
667# endif
668#endif
669}
670
671#ifdef UTMP_SUPPORT
672void
673rxvt_term::privileged_utmp (rxvt_privaction action)
674{
675 if ((options & Opt_utmpInhibit)
676 || !pty.name || !*pty.name)
677 return;
678
679 rxvt_privileges (RESTORE);
680
681 if (action == SAVE)
682 makeutent (pty.name, rs[Rs_display_name]);
683 else
684 cleanutent ();
685
686 rxvt_privileges (IGNORE);
687}
688#endif
689
690/*----------------------------------------------------------------------*/ 647/*----------------------------------------------------------------------*/
691/* 648/*
692 * window size/position calculcations for XSizeHint and other storage. 649 * window size/position calculcations for XSizeHint and other storage.
693 * if width/height are non-zero then override calculated width/height 650 * if width/height are non-zero then override calculated width/height
694 */ 651 */
695void 652void
696rxvt_term::window_calc (unsigned int newwidth, unsigned int newheight) 653rxvt_term::window_calc (unsigned int newwidth, unsigned int newheight)
697{ 654{
698 short recalc_x, recalc_y; 655 short recalc_x, recalc_y;
699 int x, y, sb_w, mb_h, flags; 656 int x, y, sb_w, flags;
700 unsigned int w, h; 657 unsigned int w, h;
701 unsigned int max_width, max_height; 658 unsigned int max_width, max_height;
702 dDisp; 659 dDisp;
703 660
704 D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", 661 D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d",
718 if (rs[Rs_geometry]) 675 if (rs[Rs_geometry])
719 flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h); 676 flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h);
720 677
721 if (flags & WidthValue) 678 if (flags & WidthValue)
722 { 679 {
723 ncol = clamp (w, 0, MAX_POSITIVE_INT16); 680 ncol = clamp (w, 0, std::numeric_limits<int16_t>::max ());
724 szHint.flags |= USSize; 681 szHint.flags |= USSize;
725 } 682 }
726 683
727 if (flags & HeightValue) 684 if (flags & HeightValue)
728 { 685 {
729 nrow = clamp (h, 0, MAX_POSITIVE_INT16); 686 nrow = clamp (h, 0, std::numeric_limits<int16_t>::max ());
730 szHint.flags |= USSize; 687 szHint.flags |= USSize;
731 } 688 }
732 689
733 if (flags & XValue) 690 if (flags & XValue)
734 { 691 {
765 max_width = MAX_COLS * fwidth; 722 max_width = MAX_COLS * fwidth;
766 max_height = MAX_ROWS * fheight; 723 max_height = MAX_ROWS * fheight;
767 724
768 szHint.base_width = szHint.base_height = 2 * int_bwidth; 725 szHint.base_width = szHint.base_height = 2 * int_bwidth;
769 726
770 sb_w = mb_h = 0; 727 sb_w = 0;
771 window_vt_x = window_vt_y = int_bwidth; 728 window_vt_x = window_vt_y = int_bwidth;
772 729
773 if (scrollbar_visible ()) 730 if (scrollBar.state)
774 { 731 {
775 sb_w = scrollbar_TotalWidth (); 732 sb_w = scrollbar_TotalWidth ();
776 szHint.base_width += sb_w; 733 szHint.base_width += sb_w;
777 if (!(options & Opt_scrollBar_right)) 734 if (!OPTION (Opt_scrollBar_right))
778 window_vt_x += sb_w; 735 window_vt_x += sb_w;
779 }
780
781 if (menubar_visible ())
782 {
783 mb_h = menuBar_TotalHeight ();
784 szHint.base_height += mb_h;
785 window_vt_y += mb_h;
786 } 736 }
787 737
788 szHint.width_inc = fwidth; 738 szHint.width_inc = fwidth;
789 szHint.height_inc = fheight; 739 szHint.height_inc = fheight;
790 szHint.min_width = szHint.base_width + szHint.width_inc; 740 szHint.min_width = szHint.base_width + szHint.width_inc;
810 { 760 {
811 min_it (height, max_height); 761 min_it (height, max_height);
812 szHint.height = szHint.base_height + height; 762 szHint.height = szHint.base_height + height;
813 } 763 }
814 764
815 if (scrollbar_visible () && (options & Opt_scrollBar_right)) 765 if (scrollBar.state && OPTION (Opt_scrollBar_right))
816 window_sb_x = szHint.width - sb_w; 766 window_sb_x = szHint.width - sb_w;
817 767
818 if (recalc_x) 768 if (recalc_x)
819 szHint.x += DisplayWidth (disp, display->screen) - szHint.width - 2 * ext_bwidth; 769 szHint.x += DisplayWidth (disp, display->screen) - szHint.width - 2 * ext_bwidth;
820 if (recalc_y) 770 if (recalc_y)
834 * Called after a window size change. 784 * Called after a window size change.
835 */ 785 */
836void 786void
837rxvt_term::tt_winch () 787rxvt_term::tt_winch ()
838{ 788{
839 if (pty.pty < 0) 789 if (pty->pty < 0)
840 return; 790 return;
841 791
842 struct winsize ws; 792 struct winsize ws;
843 793
844 ws.ws_col = ncol; 794 ws.ws_col = ncol;
845 ws.ws_row = nrow; 795 ws.ws_row = nrow;
846 ws.ws_xpixel = width; 796 ws.ws_xpixel = width;
847 ws.ws_ypixel = height; 797 ws.ws_ypixel = height;
848 (void)ioctl (pty.pty, TIOCSWINSZ, &ws); 798 (void)ioctl (pty->pty, TIOCSWINSZ, &ws);
849 799
850#if 0 800#if 0
851 // TIOCSWINSZ⎈ is supposed to do this automatically and correctly 801 // TIOCSWINSZ⎈ is supposed to do this automatically and correctly
852 if (cmd_pid) /* force through to the command */ 802 if (cmd_pid) /* force through to the command */
853 kill (-cmd_pid, SIGWINCH); 803 kill (-cmd_pid, SIGWINCH);
889 prop.height += lineSpace; 839 prop.height += lineSpace;
890 fs->set_prop (prop); 840 fs->set_prop (prop);
891 841
892 fwidth = prop.width; 842 fwidth = prop.width;
893 fheight = prop.height; 843 fheight = prop.height;
894 fweight = prop.weight; 844 fbase = prop.ascent;
895 fslant = prop.slant;
896 fbase = (*fs)[1]->ascent;
897 845
898 for (int style = 1; style < 4; style++) 846 for (int style = 1; style < 4; style++)
899 { 847 {
900#if ENABLE_STYLES 848#if ENABLE_STYLES
901 const char *res = rs[Rs_font + style]; 849 const char *res = rs[Rs_font + style];
935 return true; 883 return true;
936} 884}
937 885
938void rxvt_term::set_string_property (Atom prop, const char *str, int len) 886void rxvt_term::set_string_property (Atom prop, const char *str, int len)
939{ 887{
940 // TODO: SMART_WINDOW_TITLE
941 XChangeProperty (display->display, parent[0], 888 XChangeProperty (display->display, parent[0],
942 prop, XA_STRING, 8, PropModeReplace, 889 prop, XA_STRING, 8, PropModeReplace,
943 (const unsigned char *)str, len >= 0 ? len : strlen (str)); 890 (const unsigned char *)str, len >= 0 ? len : strlen (str));
944} 891}
945 892
946void rxvt_term::set_utf8_property (Atom prop, const char *str, int len) 893void rxvt_term::set_utf8_property (Atom prop, const char *str, int len)
947{ 894{
948 // TODO: SMART_WINDOW_TITLE
949 wchar_t *ws = rxvt_mbstowcs (str, len); 895 wchar_t *ws = rxvt_mbstowcs (str, len);
950 char *s = rxvt_wcstoutf8 (ws); 896 char *s = rxvt_wcstoutf8 (ws);
951 897
952 XChangeProperty (display->display, parent[0], 898 XChangeProperty (display->display, parent[0],
953 prop, xa[XA_UTF8_STRING], 8, PropModeReplace, 899 prop, xa[XA_UTF8_STRING], 8, PropModeReplace,
994 i = atoi (color); 940 i = atoi (color);
995 941
996 if (i >= 8 && i <= 15) 942 if (i >= 8 && i <= 15)
997 { /* bright colors */ 943 { /* bright colors */
998 i -= 8; 944 i -= 8;
999# ifndef NO_BRIGHTCOLOR
1000 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; 945 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i];
1001 SET_PIXCOLOR (idx); 946 SET_PIXCOLOR (idx);
1002 goto done; 947 goto done;
1003# endif
1004 } 948 }
1005 949
1006 if (i >= 0 && i <= 7) 950 if (i >= 0 && i <= 7)
1007 { /* normal colors */ 951 { /* normal colors */
1008 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; 952 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i];
1181 1125
1182 fix_screen = ncol != prev_ncol || nrow != prev_nrow; 1126 fix_screen = ncol != prev_ncol || nrow != prev_nrow;
1183 1127
1184 if (fix_screen || newwidth != old_width || newheight != old_height) 1128 if (fix_screen || newwidth != old_width || newheight != old_height)
1185 { 1129 {
1186 if (scrollbar_visible ()) 1130 if (scrollBar.state)
1187 { 1131 {
1188 XMoveResizeWindow (disp, scrollBar.win, 1132 XMoveResizeWindow (disp, scrollBar.win,
1189 window_sb_x, 0, 1133 window_sb_x, 0,
1190 scrollbar_TotalWidth (), szHint.height); 1134 scrollbar_TotalWidth (), szHint.height);
1191 resize_scrollbar (); 1135 resize_scrollbar ();
1192 } 1136 }
1193 1137
1194 if (menubar_visible ())
1195 XMoveResizeWindow (disp, menuBar.win,
1196 window_vt_x, 0,
1197 TermWin_TotalWidth (), menuBar_TotalHeight ());
1198
1199 XMoveResizeWindow (disp, vt, 1138 XMoveResizeWindow (disp, vt,
1200 window_vt_x, window_vt_y, 1139 window_vt_x, window_vt_y,
1201 TermWin_TotalWidth (), TermWin_TotalHeight ()); 1140 width, height);
1202 1141
1203 scr_clear (); 1142 scr_clear ();
1204#ifdef XPM_BACKGROUND 1143#ifdef XPM_BACKGROUND
1205 resize_pixmap (); 1144 resize_pixmap ();
1206#endif 1145#endif
1386 XRectangle rect, status_rect, needed_rect; 1325 XRectangle rect, status_rect, needed_rect;
1387 unsigned long fg, bg; 1326 unsigned long fg, bg;
1388 const char *p; 1327 const char *p;
1389 char **s; 1328 char **s;
1390 XIMStyles *xim_styles; 1329 XIMStyles *xim_styles;
1330
1331 set_environ (envv);
1391 1332
1392 if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) 1333 if (! ((p = XSetLocaleModifiers (modifiers)) && *p))
1393 return false; 1334 return false;
1394 1335
1395 D_MAIN ((stderr, "rxvt_IM_get_IC ()")); 1336 D_MAIN ((stderr, "rxvt_IM_get_IC ()"));
1561 int i; 1502 int i;
1562 const char *p; 1503 const char *p;
1563 char **s; 1504 char **s;
1564 char buf[IMBUFSIZ]; 1505 char buf[IMBUFSIZ];
1565 1506
1566 SET_R (this); 1507 make_current ();
1567 1508
1568 im_destroy (); 1509 im_destroy ();
1569 1510
1570 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); 1511 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()"));
1571 if (Input_Context) 1512 if (Input_Context)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines