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.51 by pcg, Sat Mar 6 00:05:01 2004 UTC vs.
Revision 1.66 by pcg, Thu Apr 8 20:31:45 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>
7 * - original version 7 * - original version
44# include <termios.h> 44# include <termios.h>
45#endif 45#endif
46 46
47#include <cstring> 47#include <cstring>
48 48
49vector<rxvt_term *> rxvt_term::termlist;
50
49static char curlocale[128]; 51static char curlocale[128];
50 52
51void 53bool
52rxvt_set_locale (const char *locale) 54rxvt_set_locale (const char *locale)
53{ 55{
54 if (locale && STRNCMP (locale, curlocale, 128)) 56 if (!locale || !STRNCMP (locale, curlocale, 128))
55 { 57 return false;
58
56 STRNCPY (curlocale, locale, 128); 59 STRNCPY (curlocale, locale, 128);
57 setlocale (LC_CTYPE, curlocale); 60 setlocale (LC_CTYPE, curlocale);
58 } 61 return true;
59} 62}
60 63
64#if ENABLE_COMBINING
61class rxvt_composite_vec rxvt_composite; 65class rxvt_composite_vec rxvt_composite;
62 66
63text_t rxvt_composite_vec::compose (uint32_t c1, uint32_t c2) 67text_t rxvt_composite_vec::compose (unicode_t c1, unicode_t c2)
64{ 68{
65 compose_char *cc; 69 compose_char *cc;
66 70
67 // break compose chains, as stupid readline really likes to duplicate 71 // break compose chains, as stupid readline really likes to duplicate
68 // composing characters for some reason near the end of a line. 72 // composing characters for some reason near the end of a line.
94 v.push_back (compose_char (c1, c2)); 98 v.push_back (compose_char (c1, c2));
95 99
96 return v.size () - 1 + COMPOSE_LO; 100 return v.size () - 1 + COMPOSE_LO;
97} 101}
98 102
99int rxvt_composite_vec::expand (uint32_t c, wchar_t *r) 103int rxvt_composite_vec::expand (unicode_t c, wchar_t *r)
100{ 104{
101 compose_char *cc = (*this)[c]; 105 compose_char *cc = (*this)[c];
102 106
103 if (!cc) 107 if (!cc)
104 { 108 {
117 } 121 }
118 122
119 return len; 123 return len;
120 124
121} 125}
126#endif
122 127
123extern struct rxvt_composite_vec rxvt_composite;
124void * 128void *
125rxvt_term::operator new (size_t s) 129rxvt_term::operator new (size_t s)
126{ 130{
127 void *p = malloc (s); 131 void *p = malloc (s);
128 132
163 destroy_ev (this, &rxvt_term::destroy_cb), 167 destroy_ev (this, &rxvt_term::destroy_cb),
164 pty_ev (this, &rxvt_term::pty_cb), 168 pty_ev (this, &rxvt_term::pty_cb),
165 incr_ev (this, &rxvt_term::incr_cb) 169 incr_ev (this, &rxvt_term::incr_cb)
166{ 170{
167 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; 171 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base;
172
173 termlist.push_back (this);
168} 174}
169 175
170rxvt_term::~rxvt_term () 176rxvt_term::~rxvt_term ()
171{ 177{
178 termlist.erase (find (termlist.begin (), termlist.end(), this));
179
172 if (cmd_fd >= 0) 180 if (cmd_fd >= 0)
173 close (cmd_fd); 181 close (cmd_fd);
174 182
175#ifndef NO_SETOWNER_TTYDEV 183#ifndef NO_SETOWNER_TTYDEV
176 privileged_ttydev (RESTORE); 184 privileged_ttydev (RESTORE);
181 189
182 delete TermWin.fontset; 190 delete TermWin.fontset;
183 191
184 if (display) 192 if (display)
185 { 193 {
194 selection_clear ();
195
196#ifdef MENUBAR
197 if (menubarGC) XFreeGC (display->display, menubarGC);
198#endif
199#ifdef XTERM_SCROLLBAR
200 if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC);
201 if (ShadowGC) XFreeGC (display->display, ShadowGC);
202#endif
203#ifdef PLAIN_SCROLLBAR
204 if (pscrollbarGC) XFreeGC (display->display, pscrollbarGC);
205#endif
206#ifdef NEXT_SCROLLBAR
207 if (blackGC) XFreeGC (display->display, blackGC);
208 if (whiteGC) XFreeGC (display->display, whiteGC);
209 if (grayGC) XFreeGC (display->display, grayGC);
210 if (darkGC) XFreeGC (display->display, darkGC);
211 if (stippleGC) XFreeGC (display->display, stippleGC);
212 if (dimple) XFreePixmap (display->display, dimple);
213 if (upArrow) XFreePixmap (display->display, upArrow);
214 if (downArrow) XFreePixmap (display->display, downArrow);
215 if (upArrowHi) XFreePixmap (display->display, upArrowHi);
216 if (downArrowHi) XFreePixmap (display->display, downArrowHi);
217#endif
218#if defined(MENUBAR) || defined(RXVT_SCROLLBAR)
219 if (topShadowGC) XFreeGC (display->display, topShadowGC);
220 if (botShadowGC) XFreeGC (display->display, botShadowGC);
221 if (scrollbarGC) XFreeGC (display->display, scrollbarGC);
222#endif
223 if (TermWin.gc) XFreeGC (display->display, TermWin.gc);
224
186#if defined(MENUBAR) && (MENUBAR_MAX > 1) 225#if defined(MENUBAR) && (MENUBAR_MAX > 1)
187 delete menuBar.drawable; 226 delete menuBar.drawable;
188 //if (menuBar.win) 227 //if (menuBar.win)
189 // XDestroyWindow (display->display, menuBar.win); 228 // XDestroyWindow (display->display, menuBar.win);
190#endif 229#endif
200 239
201 displays.put (display); 240 displays.put (display);
202 241
203 scr_release (); 242 scr_release ();
204 243
244 /* clear all resources */
245 for (int i = 0; i < allocated.size (); i++)
246 free (allocated[i]);
247
248 free (selection.text);
249 // TODO: manage env vars in child only(!)
205 free (env_windowid); 250 free (env_windowid);
206 free (env_display); 251 free (env_display);
207 free (env_term); 252 free (env_term);
208 free (env_colorfgbg); 253 free (env_colorfgbg);
209 free (locale); 254 free (locale);
255#if 0
210 free (codeset); 256 free (codeset);
257#endif
211 258
212 delete envv; 259 delete envv;
213 delete argv; 260 delete argv;
214} 261}
215 262
256 delete this; 303 delete this;
257} 304}
258 305
259/*----------------------------------------------------------------------*/ 306/*----------------------------------------------------------------------*/
260/* rxvt_init () */ 307/* rxvt_init () */
261/* LIBPROTO */
262rxvt_t
263rxvt_init (int argc, const char *const *argv)
264{
265 SET_R (new rxvt_term);
266
267 if (!GET_R->init_vars () || !GET_R->init (argc, argv))
268 {
269 delete GET_R;
270 SET_R (0);
271 }
272
273 return GET_R;
274}
275
276static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event);
277
278void
279rxvt_init_signals ()
280{
281 /* install exit handler for cleanup */
282#if 0
283#ifdef HAVE_ATEXIT
284 atexit (rxvt_clean_exit);
285#else
286#endif
287#endif
288
289 struct sigaction sa;
290
291 sigfillset (&sa.sa_mask);
292 sa.sa_flags = SA_NOCLDSTOP | SA_RESTART;
293 sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0);
294 sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0);
295 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0);
296 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0);
297 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0);
298 sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0);
299
300 /* need to trap SIGURG for SVR4 (Unixware) rlogin */
301 /* signal (SIGURG, SIG_DFL); */
302
303 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
304 //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler);
305}
306
307bool 308bool
308rxvt_term::init (int argc, const char *const *argv) 309rxvt_term::init (int argc, const char *const *argv)
309{ 310{
311 SET_R (this);
312
313 if (!init_vars ())
314 return false;
315
310 /* 316 /*
311 * Save and then give up any super-user privileges 317 * Save and then give up any super-user privileges
312 * If we need privileges in any area then we must specifically request it. 318 * If we need privileges in any area then we must specifically request it.
313 * We should only need to be root in these cases: 319 * We should only need to be root in these cases:
314 * 1. write utmp entries on some systems 320 * 1. write utmp entries on some systems
369 check_ev.start (); 375 check_ev.start ();
370 376
371 return true; 377 return true;
372} 378}
373 379
380static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event);
381
382void
383rxvt_init_signals ()
384{
385 /* install exit handler for cleanup */
386#if 0
387#ifdef HAVE_ATEXIT
388 atexit (rxvt_clean_exit);
389#else
390#endif
391#endif
392
393 struct sigaction sa;
394
395 sigfillset (&sa.sa_mask);
396 sa.sa_flags = SA_NOCLDSTOP | SA_RESTART;
397 sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0);
398 sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0);
399 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0);
400 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0);
401 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0);
402 sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0);
403
404 /* need to trap SIGURG for SVR4 (Unixware) rlogin */
405 /* signal (SIGURG, SIG_DFL); */
406
407 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
408 //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler);
409}
410
374/* ------------------------------------------------------------------------- * 411/* ------------------------------------------------------------------------- *
375 * SIGNAL HANDLING & EXIT HANDLER * 412 * SIGNAL HANDLING & EXIT HANDLER *
376 * ------------------------------------------------------------------------- */ 413 * ------------------------------------------------------------------------- */
377/* 414/*
378 * Catch a SIGCHLD signal and exit if the direct child has died 415 * Catch a SIGCHLD signal and exit if the direct child has died
379 */ 416 */
417
418void rxvt_term::child_exited (int pid)
419{
420 for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++)
421 if (pid == (*t)->cmd_pid)
422 {
423 (*t)->destroy ();
424 break;
425 }
426}
427
380/* ARGSUSED */ 428/* ARGSUSED */
381/* EXTPROTO */ 429/* EXTPROTO */
382RETSIGTYPE 430RETSIGTYPE
383rxvt_Child_signal (int sig __attribute__ ((unused))) 431rxvt_Child_signal (int sig __attribute__ ((unused)))
384{ 432{
385 int pid, save_errno = errno; 433 int pid, save_errno = errno;
434
386 while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR) 435 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0)
387 ; 436 rxvt_term::child_exited (pid);
437
388 errno = save_errno; 438 errno = save_errno;
389
390#if 0
391 if (pid == cmd_pid)
392 exit (EXIT_SUCCESS);
393#endif
394} 439}
395 440
396/* 441/*
397 * Catch a fatal signal and tidy up before quitting 442 * Catch a fatal signal and tidy up before quitting
398 */ 443 */
400RETSIGTYPE 445RETSIGTYPE
401rxvt_Exit_signal (int sig) 446rxvt_Exit_signal (int sig)
402{ 447{
403 signal (sig, SIG_DFL); 448 signal (sig, SIG_DFL);
404#ifdef DEBUG_CMD 449#ifdef DEBUG_CMD
405 rxvt_print_error ("signal %d", sig); 450 rxvt_warn ("caught signal %d, exiting.\n", sig);
406#endif 451#endif
407 rxvt_clean_exit (); 452 rxvt_clean_exit ();
408 kill (getpid (), sig); 453 kill (getpid (), sig);
409} 454}
410 455
685 else 730 else
686 szHint.win_gravity = SouthWestGravity; 731 szHint.win_gravity = SouthWestGravity;
687 } 732 }
688 } 733 }
689 } 734 }
735
690 /* TODO: BOUNDS */ 736 /* TODO: BOUNDS */
691 TermWin.width = TermWin.ncol * TermWin.fwidth; 737 TermWin.width = TermWin.ncol * TermWin.fwidth;
692 TermWin.height = TermWin.nrow * TermWin.fheight; 738 TermWin.height = TermWin.nrow * TermWin.fheight;
693 max_width = MAX_COLS * TermWin.fwidth; 739 max_width = MAX_COLS * TermWin.fwidth;
694 max_height = MAX_ROWS * TermWin.fheight; 740 max_height = MAX_ROWS * TermWin.fheight;
836/*----------------------------------------------------------------------*/ 882/*----------------------------------------------------------------------*/
837/* xterm sequences - title, iconName, color (exptl) */ 883/* xterm sequences - title, iconName, color (exptl) */
838void 884void
839rxvt_term::set_title (const char *str) 885rxvt_term::set_title (const char *str)
840{ 886{
841#ifndef SMART_WINDOW_TITLE 887#ifdef SMART_WINDOW_TITLE
842 XStoreName (display->display, TermWin.parent[0], str);
843#else
844 char *name; 888 char *name;
845 889
846 if (XFetchName (display->display, TermWin.parent[0], &name) == 0) 890 if (!XFetchName (display->display, TermWin.parent[0], &name))
847 name = NULL; 891 name = NULL;
892
848 if (name == NULL || STRCMP (name, str)) 893 if (name == NULL || STRCMP (name, str))
894#endif
849 XStoreName (display->display, TermWin.parent[0], str); 895 XStoreName (display->display, TermWin.parent[0], str);
896
897#ifdef SMART_WINDOW_TITLE
850 if (name) 898 if (name)
851 XFree (name); 899 XFree (name);
852#endif 900#endif
853} 901}
854 902
855void 903void
856rxvt_term::set_iconName (const char *str) 904rxvt_term::set_icon_name (const char *str)
857{ 905{
858#ifndef SMART_WINDOW_TITLE 906#ifdef SMART_WINDOW_TITLE
859 XSetIconName (display->display, TermWin.parent[0], str);
860#else
861 char *name; 907 char *name;
862 908
863 if (XGetIconName (display->display, TermWin.parent[0], &name)) 909 if (!XGetIconName (display->display, TermWin.parent[0], &name))
864 name = NULL; 910 name = NULL;
911
865 if (name == NULL || STRCMP (name, str)) 912 if (name == NULL || STRCMP (name, str))
913#endif
866 XSetIconName (display->display, TermWin.parent[0], str); 914 XSetIconName (display->display, TermWin.parent[0], str);
915
916#ifdef SMART_WINDOW_TITLE
867 if (name) 917 if (name)
868 XFree (name); 918 XFree (name);
869#endif 919#endif
870} 920}
871 921
898 PixColors[idx] = PixColors[minCOLOR + i]; 948 PixColors[idx] = PixColors[minCOLOR + i];
899 SET_PIXCOLOR (idx); 949 SET_PIXCOLOR (idx);
900 goto Done; 950 goto Done;
901 } 951 }
902 } 952 }
953
903 if (!rXParseAllocColor (& xcol, color)) 954 if (!rXParseAllocColor (& xcol, color))
904 return; 955 return;
956
905 /* XStoreColor (display->display, XCMAP, XColor*); */ 957 /* XStoreColor (display->display, XCMAP, XColor*); */
906 958
907 /* 959 /*
908 * FIXME: should free colors here, but no idea how to do it so instead, 960 * FIXME: should free colors here, but no idea how to do it so instead,
909 * so just keep gobbling up the colormap 961 * so just keep gobbling up the colormap
932 984
933 /* handle Color_BD, scrollbar background, etc. */ 985 /* handle Color_BD, scrollbar background, etc. */
934 986
935 set_colorfgbg (); 987 set_colorfgbg ();
936 recolour_cursor (); 988 recolour_cursor ();
937 /* the only reasonable way to enforce a clean update */ 989 scr_touch (true);
938 scr_poweron ();
939} 990}
940 991
941#else 992#else
942# define set_window_color (idx,color) ((void)0) 993# define set_window_color (idx,color) ((void)0)
943#endif /* XTERM_COLOR_CHANGE */ 994#endif /* XTERM_COLOR_CHANGE */
944 995
945void 996void
946rxvt_term::recolour_cursor () 997rxvt_term::recolour_cursor ()
947{ 998{
948#if TODO
949 rxvt_color xcol[2]; 999 XColor xcol[2];
950 1000
951 xcol[0] = PixColors[Color_pointer]; 1001 xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) ? PixColors[Color_pointer_fg] : PixColors[Color_fg];
952 xcol[1] = PixColors[Color_bg]; 1002 xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) ? PixColors[Color_pointer_bg] : PixColors[Color_bg];
953 XQueryColors (display->display, XCMAP, xcol, 2); 1003 XQueryColors (display->display, XCMAP, xcol, 2);
954 XRecolorCursor (display->display, TermWin_cursor, & (xcol[0]), & (xcol[1])); 1004 XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1);
955#endif
956} 1005}
957 1006
958/*----------------------------------------------------------------------*/ 1007/*----------------------------------------------------------------------*/
959/* 1008/*
960 * find if fg/bg matches any of the normal (low-intensity) colors 1009 * find if fg/bg matches any of the normal (low-intensity) colors
1009int 1058int
1010rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) 1059rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour)
1011{ 1060{
1012 if (!screen_in_out->set (display, colour)) 1061 if (!screen_in_out->set (display, colour))
1013 { 1062 {
1014 rxvt_print_error ("can't allocate colour: %s", colour); 1063 rxvt_warn ("can't get colour '%s', continuing without.\n", colour);
1015 return false; 1064 return false;
1016 } 1065 }
1017 1066
1018 return true; 1067 return true;
1019} 1068}
1386 if (preedit_attr) XFree (preedit_attr); 1435 if (preedit_attr) XFree (preedit_attr);
1387 if (status_attr) XFree (status_attr); 1436 if (status_attr) XFree (status_attr);
1388 1437
1389 if (Input_Context == NULL) 1438 if (Input_Context == NULL)
1390 { 1439 {
1391 rxvt_print_error ("failed to create input context"); 1440 rxvt_warn ("failed to create input context, continuing without XIM.\n");
1392 display->put_xim (input_method); 1441 display->put_xim (input_method);
1393 return false; 1442 return false;
1394 } 1443 }
1395 1444
1396 if (input_style & XIMPreeditArea) 1445 if (input_style & XIMPreeditArea)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines