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.32 by pcg, Fri Feb 13 12:16:21 2004 UTC vs.
Revision 1.54 by pcg, Mon Mar 15 00:08:11 2004 UTC

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.
55 STRNCPY (curlocale, locale, 128); 56 STRNCPY (curlocale, locale, 128);
56 setlocale (LC_CTYPE, curlocale); 57 setlocale (LC_CTYPE, curlocale);
57 } 58 }
58} 59}
59 60
61#if ENABLE_COMBINING
62class rxvt_composite_vec rxvt_composite;
63
64text_t rxvt_composite_vec::compose (unicode_t c1, unicode_t c2)
65{
66 compose_char *cc;
67
68 // break compose chains, as stupid readline really likes to duplicate
69 // composing characters for some reason near the end of a line.
70 cc = (*this)[c1];
71 while (cc)
72 {
73 if (cc->c2 == c2) return c1;
74 cc = (*this)[cc->c1];
75 }
76
77 // check to see wether this combination already exists otherwise
78 for (cc = v.end (); cc-- > v.begin (); )
79 {
80 if (cc->c1 == c1 && cc->c2 == c2)
81 return COMPOSE_LO + (cc - v.begin ());
82 }
83
84 // allocate a new combination
85 if (v.size () == COMPOSE_HI - COMPOSE_LO + 1)
86 {
87 static int seen;
88
89 if (!seen++)
90 fprintf (stderr, "too many unrepresentable composite characters, try --enable-unicode3\n");
91
92 return REPLACEMENT_CHAR;
93 }
94
95 v.push_back (compose_char (c1, c2));
96
97 return v.size () - 1 + COMPOSE_LO;
98}
99
100int rxvt_composite_vec::expand (unicode_t c, wchar_t *r)
101{
102 compose_char *cc = (*this)[c];
103
104 if (!cc)
105 {
106 if (r) *r = c;
107 return 1;
108 }
109
110 int len = expand (cc->c1, r);
111
112 if (r) r += len;
113
114 if (cc->c2 != NOCHAR)
115 {
116 len++;
117 if (r) *r++ = cc->c2;
118 }
119
120 return len;
121
122}
123#endif
124
60void * 125void *
61rxvt_term::operator new (size_t s) 126rxvt_term::operator new (size_t s)
62{ 127{
63 void *p = malloc (s); 128 void *p = malloc (s);
64 129
79 vt_ev (this, &rxvt_term::x_cb), 144 vt_ev (this, &rxvt_term::x_cb),
80#ifdef HAVE_SCROLLBARS 145#ifdef HAVE_SCROLLBARS
81 scrollbar_ev (this, &rxvt_term::x_cb), 146 scrollbar_ev (this, &rxvt_term::x_cb),
82#endif 147#endif
83#ifdef MENUBAR 148#ifdef MENUBAR
84 menubar_ev (this, &rxvt_term::x_cb), fixme 149 menubar_ev (this, &rxvt_term::x_cb),
85#endif 150#endif
86#ifdef CURSOR_BLINK 151#ifdef CURSOR_BLINK
87 cursor_blink_ev (this, &rxvt_term::cursor_blink_cb), 152 cursor_blink_ev (this, &rxvt_term::cursor_blink_cb),
88#endif 153#endif
89#ifdef TEXT_BLINK 154#ifdef TEXT_BLINK
90 text_blink_ev (this, &rxvt_term::text_blink_cb), 155 text_blink_ev (this, &rxvt_term::text_blink_cb),
91#endif 156#endif
92#ifdef POINTER_BLANK 157#ifdef POINTER_BLANK
93 pointer_ev (this, &rxvt_term::pointer_cb), 158 pointer_ev (this, &rxvt_term::pointer_cb),
159#endif
160#ifdef USE_XIM
161 im_ev (this, &rxvt_term::im_cb),
94#endif 162#endif
95 check_ev (this, &rxvt_term::check_cb), 163 check_ev (this, &rxvt_term::check_cb),
96 destroy_ev (this, &rxvt_term::destroy_cb), 164 destroy_ev (this, &rxvt_term::destroy_cb),
97 pty_ev (this, &rxvt_term::pty_cb), 165 pty_ev (this, &rxvt_term::pty_cb),
98 incr_ev (this, &rxvt_term::incr_cb), 166 incr_ev (this, &rxvt_term::incr_cb)
99#ifdef USE_XIM
100 im_ev (this, &rxvt_term::im_cb)
101#endif
102{ 167{
103 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; 168 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base;
104} 169}
105 170
106rxvt_term::~rxvt_term () 171rxvt_term::~rxvt_term ()
107{ 172{
108 if (cmd_fd >= 0) 173 if (cmd_fd >= 0)
109 close (cmd_fd); 174 close (cmd_fd);
110 175
176#ifndef NO_SETOWNER_TTYDEV
177 privileged_ttydev (RESTORE);
178#endif
179#ifdef UTMP_SUPPORT
180 privileged_utmp (RESTORE);
181#endif
182
183 delete TermWin.fontset;
184
185 if (display)
186 {
187#if defined(MENUBAR) && (MENUBAR_MAX > 1)
188 delete menuBar.drawable;
189 //if (menuBar.win)
190 // XDestroyWindow (display->display, menuBar.win);
191#endif
192 delete TermWin.drawable;
193 // destroy all windows
194 if (TermWin.parent[0])
195 XDestroyWindow (display->display, TermWin.parent[0]);
196 }
197
198 // TODO: free pixcolours, colours should become part of rxvt_display
199
200 delete PixColors;
201
202 displays.put (display);
203
111 scr_release (); 204 scr_release ();
112 205
206 free (env_windowid);
207 free (env_display);
208 free (env_term);
209 free (env_colorfgbg);
113 free (locale); 210 free (locale);
114 free (codeset); 211 free (codeset);
115 212
116#ifndef NO_SETOWNER_TTYDEV 213 delete envv;
117 privileged_ttydev (RESTORE); 214 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} 215}
130 216
131void 217void
132rxvt_term::destroy () 218rxvt_term::destroy ()
133{ 219{
134 if (display) 220 if (display)
135 { 221 {
136 if (TermWin.parent[0])
137 XDestroyWindow (display->display, TermWin.parent[0]);
138
139 rootwin_ev.stop (display); 222 rootwin_ev.stop (display);
140 termwin_ev.stop (display); 223 termwin_ev.stop (display);
141 vt_ev.stop (display); 224 vt_ev.stop (display);
142
143#ifdef USE_XIM 225#ifdef USE_XIM
144 im_destroy (); 226 im_destroy ();
145 im_ev.stop (display); 227 im_ev.stop (display);
146#endif 228#endif
147#ifdef HAVE_SCROLLBARS 229#ifdef HAVE_SCROLLBARS
240 322
241 const char **cmd_argv = init_resources (argc, argv); 323 const char **cmd_argv = init_resources (argc, argv);
242 324
243 set_locale (""); 325 set_locale ("");
244 326
245#if (MENUBAR_MAX) 327#if MENUBAR_MAX
246 menubar_read (rs[Rs_menu]); 328 menubar_read (rs[Rs_menu]);
247#endif 329#endif
248#ifdef HAVE_SCROLLBARS 330#ifdef HAVE_SCROLLBARS
249 if (Options & Opt_scrollBar) 331 if (Options & Opt_scrollBar)
250 scrollBar.setIdle (); /* set existence for size calculations */ 332 scrollBar.setIdle (); /* set existence for size calculations */
253 create_windows (argc, argv); 335 create_windows (argc, argv);
254 336
255 init_xlocale (); 337 init_xlocale ();
256 338
257 scr_reset (); /* initialize screen */ 339 scr_reset (); /* initialize screen */
258#ifdef RXVT_GRAPHICS
259 Gr_reset (); /* reset graphics */
260#endif
261 340
262#if 0 341#if 0
263#ifdef DEBUG_X
264 XSynchronize (display->display, True); 342 XSynchronize (display->display, True);
265#endif
266#endif 343#endif
267 344
268#ifdef HAVE_SCROLLBARS 345#ifdef HAVE_SCROLLBARS
269 if (Options & Opt_scrollBar) 346 if (Options & Opt_scrollBar)
270 resize_scrollbar (); /* create and map scrollbar */ 347 resize_scrollbar (); /* create and map scrollbar */
271#endif 348#endif
272#if (MENUBAR_MAX) 349#if (MENUBAR_MAX)
273 if (menubar_visible (r)) 350 if (menubar_visible ())
274 XMapWindow (display->display, menuBar.win); 351 XMapWindow (display->display, menuBar.win);
275#endif 352#endif
276#ifdef TRANSPARENT 353#ifdef TRANSPARENT
277 if (Options & Opt_transparent) 354 if (Options & Opt_transparent)
278 { 355 {
284 rootwin_ev.start (display, display->root); 361 rootwin_ev.start (display, display->root);
285 362
286 XMapWindow (display->display, TermWin.vt); 363 XMapWindow (display->display, TermWin.vt);
287 XMapWindow (display->display, TermWin.parent[0]); 364 XMapWindow (display->display, TermWin.parent[0]);
288 365
289 init_env ();
290 init_command (cmd_argv); 366 init_command (cmd_argv);
291 367
292 pty_ev.start (cmd_fd, EVENT_READ); 368 pty_ev.start (cmd_fd, EVENT_READ);
293 369
294 check_ev.start (); 370 check_ev.start ();
373 449
374 p = malloc (size); 450 p = malloc (size);
375 if (p) 451 if (p)
376 return p; 452 return p;
377 453
378 fprintf (stderr, APL_NAME ": memory allocation failure. Aborting"); 454 fprintf (stderr, RESNAME ": memory allocation failure. Aborting");
379 rxvt_clean_exit (); 455 rxvt_clean_exit ();
380 exit (EXIT_FAILURE); 456 exit (EXIT_FAILURE);
381 /* NOTREACHED */ 457 /* NOTREACHED */
382} 458}
383 459
389 465
390 p = calloc (number, size); 466 p = calloc (number, size);
391 if (p) 467 if (p)
392 return p; 468 return p;
393 469
394 fprintf (stderr, APL_NAME ": memory allocation failure. Aborting"); 470 fprintf (stderr, RESNAME ": memory allocation failure. Aborting");
395 rxvt_clean_exit (); 471 rxvt_clean_exit ();
396 exit (EXIT_FAILURE); 472 exit (EXIT_FAILURE);
397 /* NOTREACHED */ 473 /* NOTREACHED */
398} 474}
399 475
408 else 484 else
409 p = malloc (size); 485 p = malloc (size);
410 if (p) 486 if (p)
411 return p; 487 return p;
412 488
413 fprintf (stderr, APL_NAME ": memory allocation failure. Aborting"); 489 fprintf (stderr, RESNAME ": memory allocation failure. Aborting");
414 rxvt_clean_exit (); 490 rxvt_clean_exit ();
415 exit (EXIT_FAILURE); 491 exit (EXIT_FAILURE);
416 /* NOTREACHED */ 492 /* NOTREACHED */
417} 493}
418 494
610 else 686 else
611 szHint.win_gravity = SouthWestGravity; 687 szHint.win_gravity = SouthWestGravity;
612 } 688 }
613 } 689 }
614 } 690 }
691
615 /* TODO: BOUNDS */ 692 /* TODO: BOUNDS */
616 TermWin.width = TermWin.ncol * TermWin.fwidth; 693 TermWin.width = TermWin.ncol * TermWin.fwidth;
617 TermWin.height = TermWin.nrow * TermWin.fheight; 694 TermWin.height = TermWin.nrow * TermWin.fheight;
618 max_width = MAX_COLS * TermWin.fwidth; 695 max_width = MAX_COLS * TermWin.fwidth;
619 max_height = MAX_ROWS * TermWin.fheight; 696 max_height = MAX_ROWS * TermWin.fheight;
712 * init = 1 - initialize 789 * init = 1 - initialize
713 * 790 *
714 * fontname == FONT_UP - switch to bigger font 791 * fontname == FONT_UP - switch to bigger font
715 * fontname == FONT_DN - switch to smaller font 792 * fontname == FONT_DN - switch to smaller font
716 */ 793 */
717void 794bool
718rxvt_term::change_font (int init, const char *fontname) 795rxvt_term::change_font (const char *fontname)
719{} 796{
797 if (fontname == FONT_UP)
798 {
799 // TODO
800 }
801 else if (fontname == FONT_DN)
802 {
803 // TODO
804 }
805 else
806 {
807 rxvt_fontset *fs = new rxvt_fontset (this);
720 808
721void 809 if (fs && fs->populate (fontname ? fontname : "fixed"))
810 {
811 delete TermWin.fontset;
812 TermWin.fontset = fs;
813 TermWin.fwidth = fs->base_font ()->width;
814 TermWin.fheight = fs->base_font ()->height;
815 TermWin.fbase = fs->base_font ()->ascent;
816
817 if (TermWin.parent[0])
818 {
819 resize_all_windows (0, 0, 0);
820 scr_remap_chars ();
821 scr_touch (true);
822 }
823
824 return true;
825 }
826 }
827
828 return false;
829}
830
831bool
722rxvt_term::font_up_down (int n, int direction) 832rxvt_term::font_up_down (int n, int direction)
723{} 833{
834 return false;
835}
724 836
725/*----------------------------------------------------------------------*/ 837/*----------------------------------------------------------------------*/
726/*----------------------------------------------------------------------*/ 838/*----------------------------------------------------------------------*/
727/* xterm sequences - title, iconName, color (exptl) */ 839/* xterm sequences - title, iconName, color (exptl) */
728void 840void
729rxvt_term::set_title (const char *str) 841rxvt_term::set_title (const char *str)
730{ 842{
731#ifndef SMART_WINDOW_TITLE 843#ifndef SMART_WINDOW_TITLE
732 XStoreName (display->display, TermWin.parent[0], str); 844 XStoreName (display->display, TermWin.parent[0], str);
733#else 845#else
734 char *name; 846 char *name;
735 847
736 if (XFetchName (display->display, TermWin.parent[0], &name) == 0) 848 if (XFetchName (display->display, TermWin.parent[0], &name) == 0)
737 name = NULL; 849 name = NULL;
738 if (name == NULL || STRCMP (name, str)) 850 if (name == NULL || STRCMP (name, str))
739 XStoreName (display->display, TermWin.parent[0], str); 851 XStoreName (display->display, TermWin.parent[0], str);
746rxvt_term::set_iconName (const char *str) 858rxvt_term::set_iconName (const char *str)
747{ 859{
748#ifndef SMART_WINDOW_TITLE 860#ifndef SMART_WINDOW_TITLE
749 XSetIconName (display->display, TermWin.parent[0], str); 861 XSetIconName (display->display, TermWin.parent[0], str);
750#else 862#else
751 char *name; 863 char *name;
752 864
753 if (XGetIconName (display->display, TermWin.parent[0], &name)) 865 if (XGetIconName (display->display, TermWin.parent[0], &name))
754 name = NULL; 866 name = NULL;
755 if (name == NULL || STRCMP (name, str)) 867 if (name == NULL || STRCMP (name, str))
756 XSetIconName (display->display, TermWin.parent[0], str); 868 XSetIconName (display->display, TermWin.parent[0], str);
761 873
762#ifdef XTERM_COLOR_CHANGE 874#ifdef XTERM_COLOR_CHANGE
763void 875void
764rxvt_term::set_window_color (int idx, const char *color) 876rxvt_term::set_window_color (int idx, const char *color)
765{ 877{
766 rxvt_color xcol; 878 rxvt_color xcol;
767 int i; 879 int i;
768 880
769 if (color == NULL || *color == '\0') 881 if (color == NULL || *color == '\0')
770 return; 882 return;
771 883
772 /* handle color aliases */ 884 /* handle color aliases */
873#ifdef XPM_BACKGROUND 985#ifdef XPM_BACKGROUND
874 xpmb = "default;"; 986 xpmb = "default;";
875#endif 987#endif
876 break; 988 break;
877 } 989 }
990
878 sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); 991 sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr);
879 putenv (env_colorfgbg);
880 992
881#ifndef NO_BRIGHTCOLOR 993#ifndef NO_BRIGHTCOLOR
882 colorfgbg = DEFAULT_RSTYLE; 994 colorfgbg = DEFAULT_RSTYLE;
883 for (i = minCOLOR; i <= maxCOLOR; i++) 995 for (i = minCOLOR; i <= maxCOLOR; i++)
884 { 996 {
989 0, TermWin_TotalWidth (), menuBar_TotalHeight ()); 1101 0, TermWin_TotalWidth (), menuBar_TotalHeight ());
990 1102
991 XMoveResizeWindow (display->display, TermWin.vt, window_vt_x, 1103 XMoveResizeWindow (display->display, TermWin.vt, window_vt_x,
992 window_vt_y, TermWin_TotalWidth (), 1104 window_vt_y, TermWin_TotalWidth (),
993 TermWin_TotalHeight ()); 1105 TermWin_TotalHeight ());
994#ifdef RXVT_GRAPHICS 1106 scr_clear (height != old_height);
995 if (old_height)
996 Gr_Resize (old_width - szHint.base_width,
997 old_height - szHint.base_height);
998#endif
999 scr_clear ();
1000#ifdef XPM_BACKGROUND 1107#ifdef XPM_BACKGROUND
1001 resize_pixmap (); 1108 resize_pixmap ();
1002#endif 1109#endif
1003 1110
1004 } 1111 }
1309 if (Input_Context) 1416 if (Input_Context)
1310 return; 1417 return;
1311 1418
1312#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) 1419#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
1313 if (rs[Rs_imLocale]) 1420 if (rs[Rs_imLocale])
1314 setlocale (LC_CTYPE, rs[Rs_imLocale]); 1421 SET_LOCALE (rs[Rs_imLocale]);
1315#endif 1422#endif
1316 1423
1317 p = rs[Rs_inputMethod]; 1424 p = rs[Rs_inputMethod];
1318 if (p && *p) 1425 if (p && *p)
1319 { 1426 {
1350 goto done; 1457 goto done;
1351 1458
1352done: 1459done:
1353#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) 1460#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
1354 if (rs[Rs_imLocale]) 1461 if (rs[Rs_imLocale])
1355 setlocale (LC_CTYPE, locale); 1462 SET_LOCALE (locale);
1356#endif 1463#endif
1357} 1464}
1358 1465
1359void 1466void
1360rxvt_term::IMSetStatusPosition () 1467rxvt_term::IMSetStatusPosition ()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines