… | |
… | |
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" |
35 | |
37 | |
36 | #include <limits> |
38 | #include <limits> |
37 | |
39 | |
38 | #include <csignal> |
40 | #include <csignal> |
39 | #include <cstring> |
41 | #include <cstring> |
… | |
… | |
44 | |
46 | |
45 | #ifdef HAVE_TERMIOS_H |
47 | #ifdef HAVE_TERMIOS_H |
46 | # include <termios.h> |
48 | # include <termios.h> |
47 | #endif |
49 | #endif |
48 | |
50 | |
49 | #ifdef KEYSYM_RESOURCE |
|
|
50 | # include "keyboard.h" |
|
|
51 | #endif |
|
|
52 | |
|
|
53 | vector<rxvt_term *> rxvt_term::termlist; |
51 | vector<rxvt_term *> rxvt_term::termlist; |
54 | |
52 | |
55 | static char curlocale[128]; |
53 | static char curlocale[128], savelocale[128]; |
56 | |
54 | |
57 | bool |
55 | bool |
58 | rxvt_set_locale (const char *locale) |
56 | rxvt_set_locale (const char *locale) |
59 | { |
57 | { |
60 | if (!locale || !strncmp (locale, curlocale, 128)) |
58 | if (!locale || !strncmp (locale, curlocale, 128)) |
61 | return false; |
59 | return false; |
62 | |
60 | |
63 | strncpy (curlocale, locale, 128); |
61 | strncpy (curlocale, locale, 128); |
64 | setlocale (LC_CTYPE, curlocale); |
62 | setlocale (LC_CTYPE, curlocale); |
65 | return true; |
63 | return true; |
|
|
64 | } |
|
|
65 | |
|
|
66 | bool |
|
|
67 | rxvt_push_locale (const char *locale) |
|
|
68 | { |
|
|
69 | strcpy (savelocale, curlocale); |
|
|
70 | rxvt_set_locale (locale); |
|
|
71 | } |
|
|
72 | |
|
|
73 | void |
|
|
74 | rxvt_pop_locale () |
|
|
75 | { |
|
|
76 | rxvt_set_locale (savelocale); |
66 | } |
77 | } |
67 | |
78 | |
68 | #if ENABLE_COMBINING |
79 | #if ENABLE_COMBINING |
69 | class rxvt_composite_vec rxvt_composite; |
80 | class rxvt_composite_vec rxvt_composite; |
70 | |
81 | |
… | |
… | |
195 | pty.put (); |
206 | pty.put (); |
196 | } |
207 | } |
197 | |
208 | |
198 | rxvt_term::~rxvt_term () |
209 | rxvt_term::~rxvt_term () |
199 | { |
210 | { |
|
|
211 | HOOK_INVOKE ((this, HOOK_DESTROY, DT_END)); |
|
|
212 | |
200 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
213 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
201 | |
214 | |
202 | emergency_cleanup (); |
215 | emergency_cleanup (); |
203 | |
216 | |
204 | #if ENABLE_STYLES |
217 | #if ENABLE_STYLES |
… | |
… | |
261 | |
274 | |
262 | delete pix_colors_focused; |
275 | delete pix_colors_focused; |
263 | #if OFF_FOCUS_FADING |
276 | #if OFF_FOCUS_FADING |
264 | delete pix_colors_unfocused; |
277 | delete pix_colors_unfocused; |
265 | #endif |
278 | #endif |
|
|
279 | #if USE_XGETDEFAULT |
|
|
280 | XrmDestroyDatabase (xrmdatabase); |
|
|
281 | #endif |
266 | |
282 | |
267 | displays.put (display); |
283 | displays.put (display); |
268 | |
284 | |
269 | scr_release (); |
285 | scr_release (); |
270 | |
286 | |
… | |
… | |
293 | void |
309 | void |
294 | rxvt_term::child_exit () |
310 | rxvt_term::child_exit () |
295 | { |
311 | { |
296 | cmd_pid = 0; |
312 | cmd_pid = 0; |
297 | |
313 | |
298 | if (!(options & Opt_hold)) |
314 | if (!OPTION (Opt_hold)) |
299 | destroy (); |
315 | destroy (); |
300 | } |
316 | } |
301 | |
317 | |
302 | void |
318 | void |
303 | rxvt_term::destroy () |
319 | rxvt_term::destroy () |
… | |
… | |
469 | |
485 | |
470 | #if MENUBAR_MAX |
486 | #if MENUBAR_MAX |
471 | menubar_read (rs[Rs_menu]); |
487 | menubar_read (rs[Rs_menu]); |
472 | #endif |
488 | #endif |
473 | #ifdef HAVE_SCROLLBARS |
489 | #ifdef HAVE_SCROLLBARS |
474 | if (options & Opt_scrollBar) |
490 | if (OPTION (Opt_scrollBar)) |
475 | scrollBar.setIdle (); /* set existence for size calculations */ |
491 | scrollBar.setIdle (); /* set existence for size calculations */ |
|
|
492 | #endif |
|
|
493 | |
|
|
494 | #if ENABLE_PERL |
|
|
495 | if (!rs[Rs_perl_ext_1]) |
|
|
496 | rs[Rs_perl_ext_1] = "default"; |
|
|
497 | |
|
|
498 | if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) |
|
|
499 | || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) |
|
|
500 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
|
|
501 | { |
|
|
502 | rxvt_perl.init (); |
|
|
503 | HOOK_INVOKE ((this, HOOK_INIT, DT_END)); |
|
|
504 | } |
476 | #endif |
505 | #endif |
477 | |
506 | |
478 | create_windows (argc, argv); |
507 | create_windows (argc, argv); |
479 | |
508 | |
480 | dDisp; |
509 | dDisp; |
… | |
… | |
486 | #if 0 |
515 | #if 0 |
487 | XSynchronize (disp, True); |
516 | XSynchronize (disp, True); |
488 | #endif |
517 | #endif |
489 | |
518 | |
490 | #ifdef HAVE_SCROLLBARS |
519 | #ifdef HAVE_SCROLLBARS |
491 | if (options & Opt_scrollBar) |
520 | if (OPTION (Opt_scrollBar)) |
492 | resize_scrollbar (); /* create and map scrollbar */ |
521 | resize_scrollbar (); /* create and map scrollbar */ |
493 | #endif |
522 | #endif |
494 | #if (MENUBAR_MAX) |
523 | #if (MENUBAR_MAX) |
495 | if (menubar_visible ()) |
524 | if (menubar_visible ()) |
496 | XMapWindow (disp, menuBar.win); |
525 | XMapWindow (disp, menuBar.win); |
497 | #endif |
526 | #endif |
498 | #ifdef TRANSPARENT |
527 | #ifdef TRANSPARENT |
499 | if (options & Opt_transparent) |
528 | if (OPTION (Opt_transparent)) |
500 | { |
529 | { |
501 | XSelectInput (disp, display->root, PropertyChangeMask); |
530 | XSelectInput (disp, display->root, PropertyChangeMask); |
502 | check_our_parents (); |
531 | check_our_parents (); |
503 | rootwin_ev.start (display, display->root); |
532 | rootwin_ev.start (display, display->root); |
504 | } |
533 | } |
… | |
… | |
511 | |
540 | |
512 | init_command (cmd_argv); |
541 | init_command (cmd_argv); |
513 | |
542 | |
514 | free (cmd_argv); |
543 | free (cmd_argv); |
515 | |
544 | |
|
|
545 | if (pty.pty >= 0) |
516 | pty_ev.start (pty.pty, EVENT_READ); |
546 | pty_ev.start (pty.pty, EVENT_READ); |
517 | |
547 | |
518 | check_ev.start (); |
548 | check_ev.start (); |
|
|
549 | |
|
|
550 | HOOK_INVOKE ((this, HOOK_START, DT_END)); |
519 | |
551 | |
520 | return true; |
552 | return true; |
521 | } |
553 | } |
522 | |
554 | |
523 | static struct sig_handlers |
555 | static struct sig_handlers |
… | |
… | |
584 | /* signal (SIGURG, SIG_DFL); */ |
616 | /* signal (SIGURG, SIG_DFL); */ |
585 | |
617 | |
586 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
618 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
587 | // TODO: handle this with exceptions and tolerate the memory loss |
619 | // TODO: handle this with exceptions and tolerate the memory loss |
588 | XSetIOErrorHandler (rxvt_xioerror_handler); |
620 | XSetIOErrorHandler (rxvt_xioerror_handler); |
|
|
621 | |
|
|
622 | #ifdef USE_XGETDEFAULT |
|
|
623 | XrmInitialize (); |
|
|
624 | #endif |
589 | } |
625 | } |
590 | |
626 | |
591 | /* ------------------------------------------------------------------------- * |
627 | /* ------------------------------------------------------------------------- * |
592 | * MEMORY ALLOCATION WRAPPERS * |
628 | * MEMORY ALLOCATION WRAPPERS * |
593 | * ------------------------------------------------------------------------- */ |
629 | * ------------------------------------------------------------------------- */ |
… | |
… | |
681 | |
717 | |
682 | #ifdef UTMP_SUPPORT |
718 | #ifdef UTMP_SUPPORT |
683 | void |
719 | void |
684 | rxvt_term::privileged_utmp (rxvt_privaction action) |
720 | rxvt_term::privileged_utmp (rxvt_privaction action) |
685 | { |
721 | { |
686 | if ((options & Opt_utmpInhibit) |
722 | if (OPTION (Opt_utmpInhibit) |
687 | || !pty.name || !*pty.name) |
723 | || !pty.name || !*pty.name) |
688 | return; |
724 | return; |
689 | |
725 | |
690 | rxvt_privileges (RESTORE); |
726 | rxvt_privileges (RESTORE); |
691 | |
727 | |
… | |
… | |
783 | |
819 | |
784 | if (scrollbar_visible ()) |
820 | if (scrollbar_visible ()) |
785 | { |
821 | { |
786 | sb_w = scrollbar_TotalWidth (); |
822 | sb_w = scrollbar_TotalWidth (); |
787 | szHint.base_width += sb_w; |
823 | szHint.base_width += sb_w; |
788 | if (!(options & Opt_scrollBar_right)) |
824 | if (!OPTION (Opt_scrollBar_right)) |
789 | window_vt_x += sb_w; |
825 | window_vt_x += sb_w; |
790 | } |
826 | } |
791 | |
827 | |
792 | if (menubar_visible ()) |
828 | if (menubar_visible ()) |
793 | { |
829 | { |
… | |
… | |
821 | { |
857 | { |
822 | min_it (height, max_height); |
858 | min_it (height, max_height); |
823 | szHint.height = szHint.base_height + height; |
859 | szHint.height = szHint.base_height + height; |
824 | } |
860 | } |
825 | |
861 | |
826 | if (scrollbar_visible () && (options & Opt_scrollBar_right)) |
862 | if (scrollbar_visible () && OPTION (Opt_scrollBar_right)) |
827 | window_sb_x = szHint.width - sb_w; |
863 | window_sb_x = szHint.width - sb_w; |
828 | |
864 | |
829 | if (recalc_x) |
865 | if (recalc_x) |
830 | szHint.x += DisplayWidth (disp, display->screen) - szHint.width - 2 * ext_bwidth; |
866 | szHint.x += DisplayWidth (disp, display->screen) - szHint.width - 2 * ext_bwidth; |
831 | if (recalc_y) |
867 | if (recalc_y) |
… | |
… | |
900 | prop.height += lineSpace; |
936 | prop.height += lineSpace; |
901 | fs->set_prop (prop); |
937 | fs->set_prop (prop); |
902 | |
938 | |
903 | fwidth = prop.width; |
939 | fwidth = prop.width; |
904 | fheight = prop.height; |
940 | fheight = prop.height; |
905 | fbase = (*fs)[1]->ascent; |
941 | fbase = prop.ascent; |
906 | |
942 | |
907 | for (int style = 1; style < 4; style++) |
943 | for (int style = 1; style < 4; style++) |
908 | { |
944 | { |
909 | #if ENABLE_STYLES |
945 | #if ENABLE_STYLES |
910 | const char *res = rs[Rs_font + style]; |
946 | const char *res = rs[Rs_font + style]; |
… | |
… | |
944 | return true; |
980 | return true; |
945 | } |
981 | } |
946 | |
982 | |
947 | void rxvt_term::set_string_property (Atom prop, const char *str, int len) |
983 | void rxvt_term::set_string_property (Atom prop, const char *str, int len) |
948 | { |
984 | { |
949 | // TODO: SMART_WINDOW_TITLE |
|
|
950 | XChangeProperty (display->display, parent[0], |
985 | XChangeProperty (display->display, parent[0], |
951 | prop, XA_STRING, 8, PropModeReplace, |
986 | prop, XA_STRING, 8, PropModeReplace, |
952 | (const unsigned char *)str, len >= 0 ? len : strlen (str)); |
987 | (const unsigned char *)str, len >= 0 ? len : strlen (str)); |
953 | } |
988 | } |
954 | |
989 | |
955 | void rxvt_term::set_utf8_property (Atom prop, const char *str, int len) |
990 | void rxvt_term::set_utf8_property (Atom prop, const char *str, int len) |
956 | { |
991 | { |
957 | // TODO: SMART_WINDOW_TITLE |
|
|
958 | wchar_t *ws = rxvt_mbstowcs (str, len); |
992 | wchar_t *ws = rxvt_mbstowcs (str, len); |
959 | char *s = rxvt_wcstoutf8 (ws); |
993 | char *s = rxvt_wcstoutf8 (ws); |
960 | |
994 | |
961 | XChangeProperty (display->display, parent[0], |
995 | XChangeProperty (display->display, parent[0], |
962 | prop, xa[XA_UTF8_STRING], 8, PropModeReplace, |
996 | prop, xa[XA_UTF8_STRING], 8, PropModeReplace, |
… | |
… | |
1003 | i = atoi (color); |
1037 | i = atoi (color); |
1004 | |
1038 | |
1005 | if (i >= 8 && i <= 15) |
1039 | if (i >= 8 && i <= 15) |
1006 | { /* bright colors */ |
1040 | { /* bright colors */ |
1007 | i -= 8; |
1041 | i -= 8; |
1008 | # ifndef NO_BRIGHTCOLOR |
|
|
1009 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
1042 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
1010 | SET_PIXCOLOR (idx); |
1043 | SET_PIXCOLOR (idx); |
1011 | goto done; |
1044 | goto done; |
1012 | # endif |
|
|
1013 | } |
1045 | } |
1014 | |
1046 | |
1015 | if (i >= 0 && i <= 7) |
1047 | if (i >= 0 && i <= 7) |
1016 | { /* normal colors */ |
1048 | { /* normal colors */ |
1017 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
1049 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
… | |
… | |
1201 | } |
1233 | } |
1202 | |
1234 | |
1203 | if (menubar_visible ()) |
1235 | if (menubar_visible ()) |
1204 | XMoveResizeWindow (disp, menuBar.win, |
1236 | XMoveResizeWindow (disp, menuBar.win, |
1205 | window_vt_x, 0, |
1237 | window_vt_x, 0, |
1206 | TermWin_TotalWidth (), menuBar_TotalHeight ()); |
1238 | width, menuBar_TotalHeight ()); |
1207 | |
1239 | |
1208 | XMoveResizeWindow (disp, vt, |
1240 | XMoveResizeWindow (disp, vt, |
1209 | window_vt_x, window_vt_y, |
1241 | window_vt_x, window_vt_y, |
1210 | TermWin_TotalWidth (), TermWin_TotalHeight ()); |
1242 | width, height); |
1211 | |
1243 | |
1212 | scr_clear (); |
1244 | scr_clear (); |
1213 | #ifdef XPM_BACKGROUND |
1245 | #ifdef XPM_BACKGROUND |
1214 | resize_pixmap (); |
1246 | resize_pixmap (); |
1215 | #endif |
1247 | #endif |