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.54 by pcg, Mon Mar 15 00:08:11 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
61#if ENABLE_COMBINING 64#if ENABLE_COMBINING
62class rxvt_composite_vec rxvt_composite; 65class rxvt_composite_vec rxvt_composite;
63 66
164 destroy_ev (this, &rxvt_term::destroy_cb), 167 destroy_ev (this, &rxvt_term::destroy_cb),
165 pty_ev (this, &rxvt_term::pty_cb), 168 pty_ev (this, &rxvt_term::pty_cb),
166 incr_ev (this, &rxvt_term::incr_cb) 169 incr_ev (this, &rxvt_term::incr_cb)
167{ 170{
168 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; 171 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base;
172
173 termlist.push_back (this);
169} 174}
170 175
171rxvt_term::~rxvt_term () 176rxvt_term::~rxvt_term ()
172{ 177{
178 termlist.erase (find (termlist.begin (), termlist.end(), this));
179
173 if (cmd_fd >= 0) 180 if (cmd_fd >= 0)
174 close (cmd_fd); 181 close (cmd_fd);
175 182
176#ifndef NO_SETOWNER_TTYDEV 183#ifndef NO_SETOWNER_TTYDEV
177 privileged_ttydev (RESTORE); 184 privileged_ttydev (RESTORE);
182 189
183 delete TermWin.fontset; 190 delete TermWin.fontset;
184 191
185 if (display) 192 if (display)
186 { 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
187#if defined(MENUBAR) && (MENUBAR_MAX > 1) 225#if defined(MENUBAR) && (MENUBAR_MAX > 1)
188 delete menuBar.drawable; 226 delete menuBar.drawable;
189 //if (menuBar.win) 227 //if (menuBar.win)
190 // XDestroyWindow (display->display, menuBar.win); 228 // XDestroyWindow (display->display, menuBar.win);
191#endif 229#endif
201 239
202 displays.put (display); 240 displays.put (display);
203 241
204 scr_release (); 242 scr_release ();
205 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(!)
206 free (env_windowid); 250 free (env_windowid);
207 free (env_display); 251 free (env_display);
208 free (env_term); 252 free (env_term);
209 free (env_colorfgbg); 253 free (env_colorfgbg);
210 free (locale); 254 free (locale);
255#if 0
211 free (codeset); 256 free (codeset);
257#endif
212 258
213 delete envv; 259 delete envv;
214 delete argv; 260 delete argv;
215} 261}
216 262
257 delete this; 303 delete this;
258} 304}
259 305
260/*----------------------------------------------------------------------*/ 306/*----------------------------------------------------------------------*/
261/* rxvt_init () */ 307/* rxvt_init () */
262/* LIBPROTO */
263rxvt_t
264rxvt_init (int argc, const char *const *argv)
265{
266 SET_R (new rxvt_term);
267
268 if (!GET_R->init_vars () || !GET_R->init (argc, argv))
269 {
270 delete GET_R;
271 SET_R (0);
272 }
273
274 return GET_R;
275}
276
277static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event);
278
279void
280rxvt_init_signals ()
281{
282 /* install exit handler for cleanup */
283#if 0
284#ifdef HAVE_ATEXIT
285 atexit (rxvt_clean_exit);
286#else
287#endif
288#endif
289
290 struct sigaction sa;
291
292 sigfillset (&sa.sa_mask);
293 sa.sa_flags = SA_NOCLDSTOP | SA_RESTART;
294 sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0);
295 sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0);
296 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0);
297 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0);
298 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0);
299 sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0);
300
301 /* need to trap SIGURG for SVR4 (Unixware) rlogin */
302 /* signal (SIGURG, SIG_DFL); */
303
304 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
305 //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler);
306}
307
308bool 308bool
309rxvt_term::init (int argc, const char *const *argv) 309rxvt_term::init (int argc, const char *const *argv)
310{ 310{
311 SET_R (this);
312
313 if (!init_vars ())
314 return false;
315
311 /* 316 /*
312 * Save and then give up any super-user privileges 317 * Save and then give up any super-user privileges
313 * 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.
314 * We should only need to be root in these cases: 319 * We should only need to be root in these cases:
315 * 1. write utmp entries on some systems 320 * 1. write utmp entries on some systems
370 check_ev.start (); 375 check_ev.start ();
371 376
372 return true; 377 return true;
373} 378}
374 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
375/* ------------------------------------------------------------------------- * 411/* ------------------------------------------------------------------------- *
376 * SIGNAL HANDLING & EXIT HANDLER * 412 * SIGNAL HANDLING & EXIT HANDLER *
377 * ------------------------------------------------------------------------- */ 413 * ------------------------------------------------------------------------- */
378/* 414/*
379 * 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
380 */ 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
381/* ARGSUSED */ 428/* ARGSUSED */
382/* EXTPROTO */ 429/* EXTPROTO */
383RETSIGTYPE 430RETSIGTYPE
384rxvt_Child_signal (int sig __attribute__ ((unused))) 431rxvt_Child_signal (int sig __attribute__ ((unused)))
385{ 432{
386 int pid, save_errno = errno; 433 int pid, save_errno = errno;
434
387 while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR) 435 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0)
388 ; 436 rxvt_term::child_exited (pid);
437
389 errno = save_errno; 438 errno = save_errno;
390
391#if 0
392 if (pid == cmd_pid)
393 exit (EXIT_SUCCESS);
394#endif
395} 439}
396 440
397/* 441/*
398 * Catch a fatal signal and tidy up before quitting 442 * Catch a fatal signal and tidy up before quitting
399 */ 443 */
401RETSIGTYPE 445RETSIGTYPE
402rxvt_Exit_signal (int sig) 446rxvt_Exit_signal (int sig)
403{ 447{
404 signal (sig, SIG_DFL); 448 signal (sig, SIG_DFL);
405#ifdef DEBUG_CMD 449#ifdef DEBUG_CMD
406 rxvt_print_error ("signal %d", sig); 450 rxvt_warn ("caught signal %d, exiting.\n", sig);
407#endif 451#endif
408 rxvt_clean_exit (); 452 rxvt_clean_exit ();
409 kill (getpid (), sig); 453 kill (getpid (), sig);
410} 454}
411 455
838/*----------------------------------------------------------------------*/ 882/*----------------------------------------------------------------------*/
839/* xterm sequences - title, iconName, color (exptl) */ 883/* xterm sequences - title, iconName, color (exptl) */
840void 884void
841rxvt_term::set_title (const char *str) 885rxvt_term::set_title (const char *str)
842{ 886{
843#ifndef SMART_WINDOW_TITLE 887#ifdef SMART_WINDOW_TITLE
844 XStoreName (display->display, TermWin.parent[0], str);
845#else
846 char *name; 888 char *name;
847 889
848 if (XFetchName (display->display, TermWin.parent[0], &name) == 0) 890 if (!XFetchName (display->display, TermWin.parent[0], &name))
849 name = NULL; 891 name = NULL;
892
850 if (name == NULL || STRCMP (name, str)) 893 if (name == NULL || STRCMP (name, str))
894#endif
851 XStoreName (display->display, TermWin.parent[0], str); 895 XStoreName (display->display, TermWin.parent[0], str);
896
897#ifdef SMART_WINDOW_TITLE
852 if (name) 898 if (name)
853 XFree (name); 899 XFree (name);
854#endif 900#endif
855} 901}
856 902
857void 903void
858rxvt_term::set_iconName (const char *str) 904rxvt_term::set_icon_name (const char *str)
859{ 905{
860#ifndef SMART_WINDOW_TITLE 906#ifdef SMART_WINDOW_TITLE
861 XSetIconName (display->display, TermWin.parent[0], str);
862#else
863 char *name; 907 char *name;
864 908
865 if (XGetIconName (display->display, TermWin.parent[0], &name)) 909 if (!XGetIconName (display->display, TermWin.parent[0], &name))
866 name = NULL; 910 name = NULL;
911
867 if (name == NULL || STRCMP (name, str)) 912 if (name == NULL || STRCMP (name, str))
913#endif
868 XSetIconName (display->display, TermWin.parent[0], str); 914 XSetIconName (display->display, TermWin.parent[0], str);
915
916#ifdef SMART_WINDOW_TITLE
869 if (name) 917 if (name)
870 XFree (name); 918 XFree (name);
871#endif 919#endif
872} 920}
873 921
900 PixColors[idx] = PixColors[minCOLOR + i]; 948 PixColors[idx] = PixColors[minCOLOR + i];
901 SET_PIXCOLOR (idx); 949 SET_PIXCOLOR (idx);
902 goto Done; 950 goto Done;
903 } 951 }
904 } 952 }
953
905 if (!rXParseAllocColor (& xcol, color)) 954 if (!rXParseAllocColor (& xcol, color))
906 return; 955 return;
956
907 /* XStoreColor (display->display, XCMAP, XColor*); */ 957 /* XStoreColor (display->display, XCMAP, XColor*); */
908 958
909 /* 959 /*
910 * 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,
911 * so just keep gobbling up the colormap 961 * so just keep gobbling up the colormap
934 984
935 /* handle Color_BD, scrollbar background, etc. */ 985 /* handle Color_BD, scrollbar background, etc. */
936 986
937 set_colorfgbg (); 987 set_colorfgbg ();
938 recolour_cursor (); 988 recolour_cursor ();
939 /* the only reasonable way to enforce a clean update */ 989 scr_touch (true);
940 scr_poweron ();
941} 990}
942 991
943#else 992#else
944# define set_window_color (idx,color) ((void)0) 993# define set_window_color (idx,color) ((void)0)
945#endif /* XTERM_COLOR_CHANGE */ 994#endif /* XTERM_COLOR_CHANGE */
946 995
947void 996void
948rxvt_term::recolour_cursor () 997rxvt_term::recolour_cursor ()
949{ 998{
950#if TODO
951 rxvt_color xcol[2]; 999 XColor xcol[2];
952 1000
953 xcol[0] = PixColors[Color_pointer]; 1001 xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) ? PixColors[Color_pointer_fg] : PixColors[Color_fg];
954 xcol[1] = PixColors[Color_bg]; 1002 xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) ? PixColors[Color_pointer_bg] : PixColors[Color_bg];
955 XQueryColors (display->display, XCMAP, xcol, 2); 1003 XQueryColors (display->display, XCMAP, xcol, 2);
956 XRecolorCursor (display->display, TermWin_cursor, & (xcol[0]), & (xcol[1])); 1004 XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1);
957#endif
958} 1005}
959 1006
960/*----------------------------------------------------------------------*/ 1007/*----------------------------------------------------------------------*/
961/* 1008/*
962 * 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
1011int 1058int
1012rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) 1059rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour)
1013{ 1060{
1014 if (!screen_in_out->set (display, colour)) 1061 if (!screen_in_out->set (display, colour))
1015 { 1062 {
1016 rxvt_print_error ("can't allocate colour: %s", colour); 1063 rxvt_warn ("can't get colour '%s', continuing without.\n", colour);
1017 return false; 1064 return false;
1018 } 1065 }
1019 1066
1020 return true; 1067 return true;
1021} 1068}
1388 if (preedit_attr) XFree (preedit_attr); 1435 if (preedit_attr) XFree (preedit_attr);
1389 if (status_attr) XFree (status_attr); 1436 if (status_attr) XFree (status_attr);
1390 1437
1391 if (Input_Context == NULL) 1438 if (Input_Context == NULL)
1392 { 1439 {
1393 rxvt_print_error ("failed to create input context"); 1440 rxvt_warn ("failed to create input context, continuing without XIM.\n");
1394 display->put_xim (input_method); 1441 display->put_xim (input_method);
1395 return false; 1442 return false;
1396 } 1443 }
1397 1444
1398 if (input_style & XIMPreeditArea) 1445 if (input_style & XIMPreeditArea)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines