1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*--------------------------------*-C-*---------------------------------*; |
2 | * File: main.c |
2 | * File: main.c |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * |
4 | * |
5 | * All portions of code are copyright by their respective author/s. |
5 | * All portions of code are copyright by their respective author/s. |
6 | * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> |
6 | * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> |
… | |
… | |
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 | * |
17 | * |
17 | * 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 |
18 | * 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 |
19 | * the Free Software Foundation; either version 2 of the License, or |
20 | * the Free Software Foundation; either version 2 of the License, or |
20 | * (at your option) any later version. |
21 | * (at your option) any later version. |
… | |
… | |
79 | vt_ev (this, &rxvt_term::x_cb), |
80 | vt_ev (this, &rxvt_term::x_cb), |
80 | #ifdef HAVE_SCROLLBARS |
81 | #ifdef HAVE_SCROLLBARS |
81 | scrollbar_ev (this, &rxvt_term::x_cb), |
82 | scrollbar_ev (this, &rxvt_term::x_cb), |
82 | #endif |
83 | #endif |
83 | #ifdef MENUBAR |
84 | #ifdef MENUBAR |
84 | menubar_ev (this, &rxvt_term::x_cb), fixme |
85 | menubar_ev (this, &rxvt_term::x_cb), |
85 | #endif |
86 | #endif |
86 | #ifdef CURSOR_BLINK |
87 | #ifdef CURSOR_BLINK |
87 | cursor_blink_ev (this, &rxvt_term::cursor_blink_cb), |
88 | cursor_blink_ev (this, &rxvt_term::cursor_blink_cb), |
88 | #endif |
89 | #endif |
89 | #ifdef TEXT_BLINK |
90 | #ifdef TEXT_BLINK |
90 | text_blink_ev (this, &rxvt_term::text_blink_cb), |
91 | text_blink_ev (this, &rxvt_term::text_blink_cb), |
91 | #endif |
92 | #endif |
92 | #ifdef POINTER_BLANK |
93 | #ifdef POINTER_BLANK |
93 | pointer_ev (this, &rxvt_term::pointer_cb), |
94 | pointer_ev (this, &rxvt_term::pointer_cb), |
|
|
95 | #endif |
|
|
96 | #ifdef USE_XIM |
|
|
97 | im_ev (this, &rxvt_term::im_cb), |
94 | #endif |
98 | #endif |
95 | check_ev (this, &rxvt_term::check_cb), |
99 | check_ev (this, &rxvt_term::check_cb), |
96 | destroy_ev (this, &rxvt_term::destroy_cb), |
100 | destroy_ev (this, &rxvt_term::destroy_cb), |
97 | pty_ev (this, &rxvt_term::pty_cb), |
101 | pty_ev (this, &rxvt_term::pty_cb), |
98 | incr_ev (this, &rxvt_term::incr_cb), |
102 | incr_ev (this, &rxvt_term::incr_cb) |
99 | #ifdef USE_XIM |
|
|
100 | im_ev (this, &rxvt_term::im_cb) |
|
|
101 | #endif |
|
|
102 | { |
103 | { |
103 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
104 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
104 | } |
105 | } |
105 | |
106 | |
106 | rxvt_term::~rxvt_term () |
107 | rxvt_term::~rxvt_term () |
107 | { |
108 | { |
108 | if (cmd_fd >= 0) |
109 | if (cmd_fd >= 0) |
109 | close (cmd_fd); |
110 | close (cmd_fd); |
110 | |
111 | |
|
|
112 | #ifndef NO_SETOWNER_TTYDEV |
|
|
113 | privileged_ttydev (RESTORE); |
|
|
114 | #endif |
|
|
115 | #ifdef UTMP_SUPPORT |
|
|
116 | privileged_utmp (RESTORE); |
|
|
117 | #endif |
|
|
118 | |
|
|
119 | delete TermWin.fontset; |
|
|
120 | |
|
|
121 | if (display) |
|
|
122 | { |
|
|
123 | #if defined(MENUBAR) && (MENUBAR_MAX > 1) |
|
|
124 | delete menuBar.drawable; |
|
|
125 | //if (menuBar.win) |
|
|
126 | // XDestroyWindow (display->display, menuBar.win); |
|
|
127 | #endif |
|
|
128 | delete TermWin.drawable; |
|
|
129 | // destroy all windows |
|
|
130 | if (TermWin.parent[0]) |
|
|
131 | XDestroyWindow (display->display, TermWin.parent[0]); |
|
|
132 | } |
|
|
133 | |
|
|
134 | // TODO: free pixcolours, colours should become part of rxvt_display |
|
|
135 | |
|
|
136 | delete PixColors; |
|
|
137 | |
|
|
138 | displays.put (display); |
|
|
139 | |
111 | scr_release (); |
140 | scr_release (); |
112 | |
141 | |
|
|
142 | free (env_windowid); |
|
|
143 | free (env_display); |
|
|
144 | free (env_term); |
|
|
145 | free (env_colorfgbg); |
113 | free (locale); |
146 | free (locale); |
114 | free (codeset); |
147 | free (codeset); |
115 | |
148 | |
116 | #ifndef NO_SETOWNER_TTYDEV |
149 | delete envv; |
117 | privileged_ttydev (RESTORE); |
150 | delete argv; |
118 | #endif |
|
|
119 | #ifdef UTMP_SUPPORT |
|
|
120 | privileged_utmp (RESTORE); |
|
|
121 | #endif |
|
|
122 | |
|
|
123 | // TODO: free pixcolours, colours should become part of rxvt_display |
|
|
124 | |
|
|
125 | delete PixColors; |
|
|
126 | delete TermWin.fontset; |
|
|
127 | |
|
|
128 | displays.put (display); |
|
|
129 | } |
151 | } |
130 | |
152 | |
131 | void |
153 | void |
132 | rxvt_term::destroy () |
154 | rxvt_term::destroy () |
133 | { |
155 | { |
134 | if (display) |
156 | if (display) |
135 | { |
157 | { |
136 | if (TermWin.parent[0]) |
|
|
137 | XDestroyWindow (display->display, TermWin.parent[0]); |
|
|
138 | |
|
|
139 | rootwin_ev.stop (display); |
158 | rootwin_ev.stop (display); |
140 | termwin_ev.stop (display); |
159 | termwin_ev.stop (display); |
141 | vt_ev.stop (display); |
160 | vt_ev.stop (display); |
142 | |
|
|
143 | #ifdef USE_XIM |
161 | #ifdef USE_XIM |
144 | im_destroy (); |
162 | im_destroy (); |
145 | im_ev.stop (display); |
163 | im_ev.stop (display); |
146 | #endif |
164 | #endif |
147 | #ifdef HAVE_SCROLLBARS |
165 | #ifdef HAVE_SCROLLBARS |
… | |
… | |
240 | |
258 | |
241 | const char **cmd_argv = init_resources (argc, argv); |
259 | const char **cmd_argv = init_resources (argc, argv); |
242 | |
260 | |
243 | set_locale (""); |
261 | set_locale (""); |
244 | |
262 | |
245 | #if (MENUBAR_MAX) |
263 | #if MENUBAR_MAX |
246 | menubar_read (rs[Rs_menu]); |
264 | menubar_read (rs[Rs_menu]); |
247 | #endif |
265 | #endif |
248 | #ifdef HAVE_SCROLLBARS |
266 | #ifdef HAVE_SCROLLBARS |
249 | if (Options & Opt_scrollBar) |
267 | if (Options & Opt_scrollBar) |
250 | scrollBar.setIdle (); /* set existence for size calculations */ |
268 | scrollBar.setIdle (); /* set existence for size calculations */ |
… | |
… | |
253 | create_windows (argc, argv); |
271 | create_windows (argc, argv); |
254 | |
272 | |
255 | init_xlocale (); |
273 | init_xlocale (); |
256 | |
274 | |
257 | scr_reset (); /* initialize screen */ |
275 | scr_reset (); /* initialize screen */ |
258 | #ifdef RXVT_GRAPHICS |
|
|
259 | Gr_reset (); /* reset graphics */ |
|
|
260 | #endif |
|
|
261 | |
276 | |
262 | #if 0 |
277 | #if 0 |
263 | #ifdef DEBUG_X |
|
|
264 | XSynchronize (display->display, True); |
278 | XSynchronize (display->display, True); |
265 | #endif |
|
|
266 | #endif |
279 | #endif |
267 | |
280 | |
268 | #ifdef HAVE_SCROLLBARS |
281 | #ifdef HAVE_SCROLLBARS |
269 | if (Options & Opt_scrollBar) |
282 | if (Options & Opt_scrollBar) |
270 | resize_scrollbar (); /* create and map scrollbar */ |
283 | resize_scrollbar (); /* create and map scrollbar */ |
271 | #endif |
284 | #endif |
272 | #if (MENUBAR_MAX) |
285 | #if (MENUBAR_MAX) |
273 | if (menubar_visible (r)) |
286 | if (menubar_visible ()) |
274 | XMapWindow (display->display, menuBar.win); |
287 | XMapWindow (display->display, menuBar.win); |
275 | #endif |
288 | #endif |
276 | #ifdef TRANSPARENT |
289 | #ifdef TRANSPARENT |
277 | if (Options & Opt_transparent) |
290 | if (Options & Opt_transparent) |
278 | { |
291 | { |
… | |
… | |
284 | rootwin_ev.start (display, display->root); |
297 | rootwin_ev.start (display, display->root); |
285 | |
298 | |
286 | XMapWindow (display->display, TermWin.vt); |
299 | XMapWindow (display->display, TermWin.vt); |
287 | XMapWindow (display->display, TermWin.parent[0]); |
300 | XMapWindow (display->display, TermWin.parent[0]); |
288 | |
301 | |
289 | init_env (); |
|
|
290 | init_command (cmd_argv); |
302 | init_command (cmd_argv); |
291 | |
303 | |
292 | pty_ev.start (cmd_fd, EVENT_READ); |
304 | pty_ev.start (cmd_fd, EVENT_READ); |
293 | |
305 | |
294 | check_ev.start (); |
306 | check_ev.start (); |
… | |
… | |
712 | * init = 1 - initialize |
724 | * init = 1 - initialize |
713 | * |
725 | * |
714 | * fontname == FONT_UP - switch to bigger font |
726 | * fontname == FONT_UP - switch to bigger font |
715 | * fontname == FONT_DN - switch to smaller font |
727 | * fontname == FONT_DN - switch to smaller font |
716 | */ |
728 | */ |
717 | void |
729 | bool |
718 | rxvt_term::change_font (int init, const char *fontname) |
730 | rxvt_term::change_font (const char *fontname) |
719 | {} |
731 | { |
|
|
732 | if (fontname == FONT_UP) |
|
|
733 | { |
|
|
734 | // TODO |
|
|
735 | } |
|
|
736 | else if (fontname == FONT_DN) |
|
|
737 | { |
|
|
738 | // TODO |
|
|
739 | } |
|
|
740 | else |
|
|
741 | { |
|
|
742 | rxvt_fontset *fs = new rxvt_fontset (this); |
720 | |
743 | |
721 | void |
744 | if (fs && fs->populate (fontname ? fontname : "fixed")) |
|
|
745 | { |
|
|
746 | delete TermWin.fontset; |
|
|
747 | TermWin.fontset = fs; |
|
|
748 | TermWin.fwidth = fs->base_font ()->width; |
|
|
749 | TermWin.fheight = fs->base_font ()->height; |
|
|
750 | TermWin.fbase = fs->base_font ()->ascent; |
|
|
751 | |
|
|
752 | if (TermWin.parent[0]) |
|
|
753 | { |
|
|
754 | resize_all_windows (0, 0, 0); |
|
|
755 | scr_remap_chars (); |
|
|
756 | scr_touch (true); |
|
|
757 | } |
|
|
758 | |
|
|
759 | return true; |
|
|
760 | } |
|
|
761 | } |
|
|
762 | |
|
|
763 | return false; |
|
|
764 | } |
|
|
765 | |
|
|
766 | bool |
722 | rxvt_term::font_up_down (int n, int direction) |
767 | rxvt_term::font_up_down (int n, int direction) |
723 | {} |
768 | { |
|
|
769 | return false; |
|
|
770 | } |
724 | |
771 | |
725 | /*----------------------------------------------------------------------*/ |
772 | /*----------------------------------------------------------------------*/ |
726 | /*----------------------------------------------------------------------*/ |
773 | /*----------------------------------------------------------------------*/ |
727 | /* xterm sequences - title, iconName, color (exptl) */ |
774 | /* xterm sequences - title, iconName, color (exptl) */ |
728 | void |
775 | void |
729 | rxvt_term::set_title (const char *str) |
776 | rxvt_term::set_title (const char *str) |
730 | { |
777 | { |
731 | #ifndef SMART_WINDOW_TITLE |
778 | #ifndef SMART_WINDOW_TITLE |
732 | XStoreName (display->display, TermWin.parent[0], str); |
779 | XStoreName (display->display, TermWin.parent[0], str); |
733 | #else |
780 | #else |
734 | char *name; |
781 | char *name; |
735 | |
782 | |
736 | if (XFetchName (display->display, TermWin.parent[0], &name) == 0) |
783 | if (XFetchName (display->display, TermWin.parent[0], &name) == 0) |
737 | name = NULL; |
784 | name = NULL; |
738 | if (name == NULL || STRCMP (name, str)) |
785 | if (name == NULL || STRCMP (name, str)) |
739 | XStoreName (display->display, TermWin.parent[0], str); |
786 | XStoreName (display->display, TermWin.parent[0], str); |
… | |
… | |
746 | rxvt_term::set_iconName (const char *str) |
793 | rxvt_term::set_iconName (const char *str) |
747 | { |
794 | { |
748 | #ifndef SMART_WINDOW_TITLE |
795 | #ifndef SMART_WINDOW_TITLE |
749 | XSetIconName (display->display, TermWin.parent[0], str); |
796 | XSetIconName (display->display, TermWin.parent[0], str); |
750 | #else |
797 | #else |
751 | char *name; |
798 | char *name; |
752 | |
799 | |
753 | if (XGetIconName (display->display, TermWin.parent[0], &name)) |
800 | if (XGetIconName (display->display, TermWin.parent[0], &name)) |
754 | name = NULL; |
801 | name = NULL; |
755 | if (name == NULL || STRCMP (name, str)) |
802 | if (name == NULL || STRCMP (name, str)) |
756 | XSetIconName (display->display, TermWin.parent[0], str); |
803 | XSetIconName (display->display, TermWin.parent[0], str); |
… | |
… | |
761 | |
808 | |
762 | #ifdef XTERM_COLOR_CHANGE |
809 | #ifdef XTERM_COLOR_CHANGE |
763 | void |
810 | void |
764 | rxvt_term::set_window_color (int idx, const char *color) |
811 | rxvt_term::set_window_color (int idx, const char *color) |
765 | { |
812 | { |
766 | rxvt_color xcol; |
813 | rxvt_color xcol; |
767 | int i; |
814 | int i; |
768 | |
815 | |
769 | if (color == NULL || *color == '\0') |
816 | if (color == NULL || *color == '\0') |
770 | return; |
817 | return; |
771 | |
818 | |
772 | /* handle color aliases */ |
819 | /* handle color aliases */ |
… | |
… | |
873 | #ifdef XPM_BACKGROUND |
920 | #ifdef XPM_BACKGROUND |
874 | xpmb = "default;"; |
921 | xpmb = "default;"; |
875 | #endif |
922 | #endif |
876 | break; |
923 | break; |
877 | } |
924 | } |
|
|
925 | |
878 | sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); |
926 | sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); |
879 | putenv (env_colorfgbg); |
|
|
880 | |
927 | |
881 | #ifndef NO_BRIGHTCOLOR |
928 | #ifndef NO_BRIGHTCOLOR |
882 | colorfgbg = DEFAULT_RSTYLE; |
929 | colorfgbg = DEFAULT_RSTYLE; |
883 | for (i = minCOLOR; i <= maxCOLOR; i++) |
930 | for (i = minCOLOR; i <= maxCOLOR; i++) |
884 | { |
931 | { |
… | |
… | |
989 | 0, TermWin_TotalWidth (), menuBar_TotalHeight ()); |
1036 | 0, TermWin_TotalWidth (), menuBar_TotalHeight ()); |
990 | |
1037 | |
991 | XMoveResizeWindow (display->display, TermWin.vt, window_vt_x, |
1038 | XMoveResizeWindow (display->display, TermWin.vt, window_vt_x, |
992 | window_vt_y, TermWin_TotalWidth (), |
1039 | window_vt_y, TermWin_TotalWidth (), |
993 | TermWin_TotalHeight ()); |
1040 | TermWin_TotalHeight ()); |
994 | #ifdef RXVT_GRAPHICS |
|
|
995 | if (old_height) |
|
|
996 | Gr_Resize (old_width - szHint.base_width, |
|
|
997 | old_height - szHint.base_height); |
|
|
998 | #endif |
|
|
999 | scr_clear (); |
1041 | scr_clear (); |
1000 | #ifdef XPM_BACKGROUND |
1042 | #ifdef XPM_BACKGROUND |
1001 | resize_pixmap (); |
1043 | resize_pixmap (); |
1002 | #endif |
1044 | #endif |
1003 | |
1045 | |
… | |
… | |
1309 | if (Input_Context) |
1351 | if (Input_Context) |
1310 | return; |
1352 | return; |
1311 | |
1353 | |
1312 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
1354 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
1313 | if (rs[Rs_imLocale]) |
1355 | if (rs[Rs_imLocale]) |
1314 | setlocale (LC_CTYPE, rs[Rs_imLocale]); |
1356 | SET_LOCALE (rs[Rs_imLocale]); |
1315 | #endif |
1357 | #endif |
1316 | |
1358 | |
1317 | p = rs[Rs_inputMethod]; |
1359 | p = rs[Rs_inputMethod]; |
1318 | if (p && *p) |
1360 | if (p && *p) |
1319 | { |
1361 | { |
… | |
… | |
1350 | goto done; |
1392 | goto done; |
1351 | |
1393 | |
1352 | done: |
1394 | done: |
1353 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
1395 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
1354 | if (rs[Rs_imLocale]) |
1396 | if (rs[Rs_imLocale]) |
1355 | setlocale (LC_CTYPE, locale); |
1397 | SET_LOCALE (locale); |
1356 | #endif |
1398 | #endif |
1357 | } |
1399 | } |
1358 | |
1400 | |
1359 | void |
1401 | void |
1360 | rxvt_term::IMSetStatusPosition () |
1402 | rxvt_term::IMSetStatusPosition () |