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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines