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.313 by root, Tue Nov 4 16:43:50 2008 UTC vs.
Revision 1.335 by root, Sun Oct 24 17:52:50 2010 UTC

30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 *---------------------------------------------------------------------*/ 31 *---------------------------------------------------------------------*/
32 32
33#include "../config.h" /* NECESSARY */ 33#include "../config.h" /* NECESSARY */
34#include "rxvt.h" /* NECESSARY */ 34#include "rxvt.h" /* NECESSARY */
35#include "init.h"
35#include "keyboard.h" 36#include "keyboard.h"
36#include "rxvtperl.h" 37#include "rxvtperl.h"
37 38
38#include <limits> 39#include <limits>
39 40
41#include <cassert>
40#include <csignal> 42#include <csignal>
41#include <cstring> 43#include <cstring>
42 44
43#include <termios.h> 45#include <termios.h>
44 46
49# ifdef HAVE_SETLOCALE 51# ifdef HAVE_SETLOCALE
50# include <clocale> 52# include <clocale>
51# endif 53# endif
52#endif 54#endif
53 55
56struct termios rxvt_term::def_tio;
54vector<rxvt_term *> rxvt_term::termlist; 57vector<rxvt_term *> rxvt_term::termlist;
55 58
56// used to tell global functions which terminal instance is "active" 59// used to tell global functions which terminal instance is "active"
57rxvt_t rxvt_current_term; 60rxvt_t rxvt_current_term;
58 61
101 { 104 {
102 if (cc->c2 == c2) return c1; 105 if (cc->c2 == c2) return c1;
103 cc = (*this)[cc->c1]; 106 cc = (*this)[cc->c1];
104 } 107 }
105 108
106 // check to see wether this combination already exists otherwise 109 // check to see whether this combination already exists otherwise
107 for (cc = v.end (); cc-- > v.begin (); ) 110 for (cc = v.end (); cc-- > v.begin (); )
108 { 111 {
109 if (cc->c1 == c1 && cc->c2 == c2) 112 if (cc->c1 == c1 && cc->c2 == c2)
110 return COMPOSE_LO + (cc - v.begin ()); 113 return COMPOSE_LO + (cc - v.begin ());
111 } 114 }
237#endif 240#endif
238 241
239 if (display) 242 if (display)
240 { 243 {
241 selection_clear (); 244 selection_clear ();
245 selection_clear (true);
242 246
243#ifdef USE_XIM 247#ifdef USE_XIM
244 im_destroy (); 248 im_destroy ();
245#endif 249#endif
246 scrollBar.destroy (); 250 scrollBar.destroy ();
271 /* clear all resources */ 275 /* clear all resources */
272 for (int i = 0; i < allocated.size (); i++) 276 for (int i = 0; i < allocated.size (); i++)
273 free (allocated [i]); 277 free (allocated [i]);
274 278
275 free (selection.text); 279 free (selection.text);
280 free (selection.clip_text);
276 // TODO: manage env vars in child only(!) 281 // TODO: manage env vars in child only(!)
277 free (env_display); 282 free (env_display);
278 free (env_term); 283 free (env_term);
279 free (locale); 284 free (locale);
280 free (v_buffer); 285 free (v_buffer);
380 char mesg[BUFSIZ]; 385 char mesg[BUFSIZ];
381 char number[32]; 386 char number[32];
382 char *mtype = "XlibMessage"; 387 char *mtype = "XlibMessage";
383 XGetErrorText(dpy, event->error_code, buffer, BUFSIZ); 388 XGetErrorText(dpy, event->error_code, buffer, BUFSIZ);
384 XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ); 389 XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ);
385 rxvt_warn ("An X Error occured, trying to continue after report.\n"); 390 rxvt_warn ("An X Error occurred, trying to continue after report.\n");
386 rxvt_warn ("%s: %s\n", mesg, buffer); 391 rxvt_warn ("%s: %s\n", mesg, buffer);
387 XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d", mesg, BUFSIZ); 392 XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d", mesg, BUFSIZ);
388 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->request_code); 393 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->request_code);
389 sprintf(number, "%d", event->request_code); 394 sprintf(number, "%d", event->request_code);
390 XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ); 395 XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ);
391 rxvt_warn ("(which is %s)\n", buffer); 396 rxvt_warn ("(which is %s)\n", buffer);
392 if (event->request_code >= 128) { 397 if (event->request_code >= 128) {
393 XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d", 398 XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d",
394 mesg, BUFSIZ); 399 mesg, BUFSIZ);
395 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->minor_code); 400 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->minor_code);
396 } 401 }
397 if ((event->error_code == BadWindow) || 402 if ((event->error_code == BadWindow) ||
398 (event->error_code == BadPixmap) || 403 (event->error_code == BadPixmap) ||
399 (event->error_code == BadCursor) || 404 (event->error_code == BadCursor) ||
400 (event->error_code == BadFont) || 405 (event->error_code == BadFont) ||
401 (event->error_code == BadDrawable) || 406 (event->error_code == BadDrawable) ||
402 (event->error_code == BadColor) || 407 (event->error_code == BadColor) ||
403 (event->error_code == BadGC) || 408 (event->error_code == BadGC) ||
404 (event->error_code == BadIDChoice) || 409 (event->error_code == BadIDChoice) ||
405 (event->error_code == BadValue) || 410 (event->error_code == BadValue) ||
406 (event->error_code == BadAtom)) { 411 (event->error_code == BadAtom)) {
407 if (event->error_code == BadValue) 412 if (event->error_code == BadValue)
408 XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x", 413 XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x",
409 mesg, BUFSIZ); 414 mesg, BUFSIZ);
410 else if (event->error_code == BadAtom) 415 else if (event->error_code == BadAtom)
411 XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x", 416 XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x",
412 mesg, BUFSIZ); 417 mesg, BUFSIZ);
413 else 418 else
414 XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x", 419 XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x",
415 mesg, BUFSIZ); 420 mesg, BUFSIZ);
416 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->resourceid); 421 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->resourceid);
417 } 422 }
418 XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d", 423 XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d",
419 mesg, BUFSIZ); 424 mesg, BUFSIZ);
420 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->serial); 425 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->serial);
421} 426}
422#endif 427#endif
423 428
424int 429int
471 rxvt_emergency_cleanup (); 476 rxvt_emergency_cleanup ();
472 w.stop (); 477 w.stop ();
473 kill (getpid (), w.signum); 478 kill (getpid (), w.signum);
474} 479}
475 480
481static void
482rxvt_get_ttymode (struct termios *tio)
483{
484 if (tcgetattr (STDIN_FILENO, tio) < 0)
485 memset (tio, 0, sizeof (struct termios));
486
487 for (int i = 0; i < NCCS; i++)
488 tio->c_cc[i] = VDISABLE;
489
490 tio->c_cc[VINTR] = CINTR;
491 tio->c_cc[VQUIT] = CQUIT;
492 tio->c_cc[VERASE] = CERASE;
493#ifdef VERASE2
494 tio->c_cc[VERASE2] = CERASE2;
495#endif
496 tio->c_cc[VKILL] = CKILL;
497 tio->c_cc[VEOF] = CEOF;
498 tio->c_cc[VSTART] = CSTART;
499 tio->c_cc[VSTOP] = CSTOP;
500 tio->c_cc[VSUSP] = CSUSP;
501# ifdef VDSUSP
502 tio->c_cc[VDSUSP] = CDSUSP;
503# endif
504# ifdef VREPRINT
505 tio->c_cc[VREPRINT] = CRPRNT;
506# endif
507# ifdef VDISCRD
508 tio->c_cc[VDISCRD] = CFLUSH;
509# endif
510# ifdef VWERSE
511 tio->c_cc[VWERSE] = CWERASE;
512# endif
513# ifdef VLNEXT
514 tio->c_cc[VLNEXT] = CLNEXT;
515# endif
516
517# if VMIN != VEOF
518 tio->c_cc[VMIN] = 1;
519# endif
520# if VTIME != VEOL
521 tio->c_cc[VTIME] = 0;
522# endif
523
524 /* input modes */
525 tio->c_iflag = (BRKINT | IGNPAR | ICRNL
526# ifdef IMAXBEL
527 | IMAXBEL
528# endif
529 | IXON);
530
531 /* output modes */
532 tio->c_oflag = (OPOST | ONLCR);
533
534 /* control modes */
535 tio->c_cflag = (CS8 | CREAD);
536
537 /* local modes */
538 tio->c_lflag = (ISIG | ICANON | IEXTEN | ECHO
539# if defined (ECHOCTL) && defined (ECHOKE)
540 | ECHOCTL | ECHOKE
541# endif
542 | ECHOE | ECHOK);
543}
544
476char **rxvt_environ; // startup environment 545char **rxvt_environ; // startup environment
477 546
478void 547void
479rxvt_init () 548rxvt_init ()
480{ 549{
481 ptytty::init (); 550 assert (("fontMask must not overlap other RS masks",
551 0 == (RS_fontMask & (RS_Sel | RS_baseattrMask | RS_customMask | RS_bgMask | RS_fgMask))));
482 552
553 rxvt_get_ttymode (&rxvt_term::def_tio);
554
555 // get rid of stdin/stdout as we don't need them, to free resources
556 dup2 (STDERR_FILENO, STDIN_FILENO);
557 dup2 (STDERR_FILENO, STDOUT_FILENO);
558
483 if (!ev_default_loop (0)) 559 if (!ev_default_loop ())
484 rxvt_fatal ("cannot initialise libev (bad value for LIBEV_METHODS?)\n"); 560 rxvt_fatal ("cannot initialise libev (bad value for LIBEV_METHODS?)\n");
485 561
486 rxvt_environ = environ; 562 rxvt_environ = environ;
487 563
488 signal (SIGHUP, SIG_IGN); 564 signal (SIGHUP, SIG_IGN);
489 signal (SIGPIPE, SIG_IGN); 565 signal (SIGPIPE, SIG_IGN);
490 566
491 sig_handlers.sw_term.start (SIGTERM); ev_unref (); 567 sig_handlers.sw_term.start (SIGTERM); ev_unref ();
492 sig_handlers.sw_int.start (SIGINT); ev_unref (); 568 sig_handlers.sw_int.start (SIGINT); ev_unref ();
493
494 /* need to trap SIGURG for SVR4 (Unixware) rlogin */
495 /* signal (SIGURG, SIG_DFL); */
496 569
497 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 570 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
498 // TODO: handle this with exceptions and tolerate the memory loss 571 // TODO: handle this with exceptions and tolerate the memory loss
499 XSetIOErrorHandler (rxvt_xioerror_handler); 572 XSetIOErrorHandler (rxvt_xioerror_handler);
500 573
646 719
647 ws.ws_col = ncol; 720 ws.ws_col = ncol;
648 ws.ws_row = nrow; 721 ws.ws_row = nrow;
649 ws.ws_xpixel = width; 722 ws.ws_xpixel = width;
650 ws.ws_ypixel = height; 723 ws.ws_ypixel = height;
651 (void)ioctl (pty->pty, TIOCSWINSZ, &ws); 724 ioctl (pty->pty, TIOCSWINSZ, &ws);
652 725
653#if 0 726#if 0
654 // TIOCSWINSZ is supposed to do this automatically and correctly 727 // TIOCSWINSZ is supposed to do this automatically and correctly
655 if (cmd_pid) /* force through to the command */ 728 if (cmd_pid) /* force through to the command */
656 kill (-cmd_pid, SIGWINCH); 729 kill (-cmd_pid, SIGWINCH);
686#endif 759#endif
687 760
688 delete fontset[0]; 761 delete fontset[0];
689 fontset[0] = fs; 762 fontset[0] = fs;
690 763
691 prop = (*fs)[1]->properties (); 764 prop = (*fs)[rxvt_fontset::firstFont]->properties ();
692 prop.height += lineSpace; 765 prop.height += lineSpace;
766 prop.width += letterSpace;
693 767
694 fs->set_prop (prop, false); 768 fs->set_prop (prop, false);
695 769
696 fwidth = prop.width; 770 fwidth = prop.width;
697 fheight = prop.height; 771 fheight = prop.height;
747 prop, XA_STRING, 8, PropModeReplace, 821 prop, XA_STRING, 8, PropModeReplace,
748 (const unsigned char *)str, len >= 0 ? len : strlen (str)); 822 (const unsigned char *)str, len >= 0 ? len : strlen (str));
749} 823}
750 824
751void 825void
826rxvt_term::set_mbstring_property (Atom prop, const char *str, int len)
827{
828 XTextProperty ct;
829
830 if (XmbTextListToTextProperty (dpy, (char **)&str, 1, XStdICCTextStyle, &ct) >= 0)
831 {
832 XSetTextProperty (dpy, parent[0], &ct, prop);
833 XFree (ct.value);
834 }
835}
836
837void
752rxvt_term::set_utf8_property (Atom prop, const char *str, int len) 838rxvt_term::set_utf8_property (Atom prop, const char *str, int len)
753{ 839{
754 wchar_t *ws = rxvt_mbstowcs (str, len); 840 wchar_t *ws = rxvt_mbstowcs (str, len);
755 char *s = rxvt_wcstoutf8 (ws); 841 char *s = rxvt_wcstoutf8 (ws);
756 842
766/*----------------------------------------------------------------------*/ 852/*----------------------------------------------------------------------*/
767/* xterm sequences - title, iconName, color (exptl) */ 853/* xterm sequences - title, iconName, color (exptl) */
768void 854void
769rxvt_term::set_title (const char *str) 855rxvt_term::set_title (const char *str)
770{ 856{
771 set_string_property (XA_WM_NAME, str); 857 set_mbstring_property (XA_WM_NAME, str);
772#if ENABLE_EWMH 858#if ENABLE_EWMH
773 set_utf8_property (xa[XA_NET_WM_NAME], str); 859 set_utf8_property (xa[XA_NET_WM_NAME], str);
774#endif 860#endif
775} 861}
776 862
777void 863void
778rxvt_term::set_icon_name (const char *str) 864rxvt_term::set_icon_name (const char *str)
779{ 865{
780 set_string_property (XA_WM_ICON_NAME, str); 866 set_mbstring_property (XA_WM_ICON_NAME, str);
781#if ENABLE_EWMH 867#if ENABLE_EWMH
782 set_utf8_property (xa[XA_NET_WM_ICON_NAME], str); 868 set_utf8_property (xa[XA_NET_WM_ICON_NAME], str);
783#endif 869#endif
784} 870}
785 871
969#else 1055#else
970 XResizeWindow (dpy, parent[0], szHint.width, szHint.height); 1056 XResizeWindow (dpy, parent[0], szHint.width, szHint.height);
971#endif 1057#endif
972 } 1058 }
973 1059
1060 if (set_hint)
1061 XSetWMNormalHints (dpy, parent[0], &szHint);
1062
974 fix_screen = ncol != prev_ncol || nrow != prev_nrow; 1063 fix_screen = ncol != prev_ncol || nrow != prev_nrow;
975 1064
976 if (fix_screen || newwidth != old_width || newheight != old_height) 1065 if (fix_screen || newwidth != old_width || newheight != old_height)
977 { 1066 {
978 if (scrollBar.state) 1067 if (scrollBar.state)
984 1073
985#ifdef HAVE_BG_PIXMAP 1074#ifdef HAVE_BG_PIXMAP
986 if (bgPixmap.window_size_sensitive ()) 1075 if (bgPixmap.window_size_sensitive ())
987 update_background (); 1076 update_background ();
988#endif 1077#endif
989
990 scr_clear ();
991 } 1078 }
992
993 if (set_hint)
994 XSetWMNormalHints (dpy, parent[0], &szHint);
995 1079
996 if (fix_screen || old_height == 0) 1080 if (fix_screen || old_height == 0)
997 scr_reset (); 1081 scr_reset ();
998
999 // TODO, with nvidia-8178, resizes kill the alpha channel, report if not fixed in newer version
1000 //scr_touch (false);
1001 1082
1002#ifdef HAVE_BG_PIXMAP 1083#ifdef HAVE_BG_PIXMAP
1003// TODO: this don't seem to have any effect - do we still need it ? If so - in which case exactly ? 1084// TODO: this don't seem to have any effect - do we still need it ? If so - in which case exactly ?
1004// if (bgPixmap.pixmap) 1085// if (bgPixmap.pixmap)
1005// scr_touch (false); 1086// scr_touch (false);
1077 1158
1078/* Checking whether input method is running. */ 1159/* Checking whether input method is running. */
1079bool 1160bool
1080rxvt_term::IMisRunning () 1161rxvt_term::IMisRunning ()
1081{ 1162{
1082 char *p;
1083 Atom atom; 1163 Atom atom;
1084 Window win; 1164 Window win;
1085 char server[IMBUFSIZ]; 1165 char server[IMBUFSIZ];
1086 1166
1087 /* get current locale modifier */ 1167 /* get current locale modifier */
1088 if ((p = XSetLocaleModifiers (NULL)) != NULL) 1168 if (char *p = XSetLocaleModifiers (0))
1089 { 1169 {
1090 strcpy (server, "@server="); 1170 strcpy (server, "@server=");
1091 strncat (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */ 1171 strncat (server, p + 4, IMBUFSIZ - 9); /* skip "@im=" */
1092 1172
1093 if ((p = strchr (server + 1, '@')) != NULL) /* first one only */ 1173 if (p = strchr (server + 1, '@')) /* first one only */
1094 *p = '\0'; 1174 *p = '\0';
1095 1175
1096 atom = XInternAtom (dpy, server, False); 1176 atom = XInternAtom (dpy, server, False);
1097 win = XGetSelectionOwner (dpy, atom); 1177 win = XGetSelectionOwner (dpy, atom);
1098 1178
1165 1245
1166 term->make_current (); 1246 term->make_current ();
1167 1247
1168 if (text) 1248 if (text)
1169 { 1249 {
1170 void *str; 1250 wchar_t *str;
1171 1251
1172 if (!text->encoding_is_wchar && text->string.multi_byte) 1252 if (!text->encoding_is_wchar && text->string.multi_byte)
1173 { 1253 {
1174 // of course, X makes it ugly again 1254 // of course, X makes it ugly again
1175 if (term->rs[Rs_imLocale]) 1255 if (term->rs[Rs_imLocale])
1176 SET_LOCALE (term->rs[Rs_imLocale]); 1256 SET_LOCALE (term->rs[Rs_imLocale]);
1177 1257
1178 str = rxvt_temp_buf ((text->length + 1) * sizeof (wchar_t)); 1258 str = rxvt_temp_buf<wchar_t> (text->length + 1);
1179 mbstowcs ((wchar_t *)str, text->string.multi_byte, text->length + 1); 1259 mbstowcs (str, text->string.multi_byte, text->length + 1);
1180 1260
1181 if (term->rs[Rs_imLocale]) 1261 if (term->rs[Rs_imLocale])
1182 SET_LOCALE (term->locale); 1262 SET_LOCALE (term->locale);
1183 } 1263 }
1184 else 1264 else
1185 str = (void *)text->string.wide_char; 1265 str = text->string.wide_char;
1186 1266
1187 HOOK_INVOKE ((term, HOOK_XIM_PREEDIT_DRAW, 1267 HOOK_INVOKE ((term, HOOK_XIM_PREEDIT_DRAW,
1188 DT_INT, call_data->caret, 1268 DT_INT, call_data->caret,
1189 DT_INT, call_data->chg_first, 1269 DT_INT, call_data->chg_first,
1190 DT_INT, call_data->chg_length, 1270 DT_INT, call_data->chg_length,
1544void 1624void
1545rxvt_term::get_window_origin (int &x, int &y) 1625rxvt_term::get_window_origin (int &x, int &y)
1546{ 1626{
1547 Window cr; 1627 Window cr;
1548 XTranslateCoordinates (dpy, parent[0], display->root, 0, 0, &x, &y, &cr); 1628 XTranslateCoordinates (dpy, parent[0], display->root, 0, 0, &x, &y, &cr);
1549/* fprintf (stderr, "origin is %+d%+d\n", x, y);*/
1550} 1629}
1551 1630
1552Pixmap 1631Pixmap
1553rxvt_term::get_pixmap_property (int prop_id) 1632rxvt_term::get_pixmap_property (int prop_id)
1554{ 1633{
1568 1647
1569 return None; 1648 return None;
1570} 1649}
1571 1650
1572#ifdef HAVE_BG_PIXMAP 1651#ifdef HAVE_BG_PIXMAP
1573# if TRACE_PIXMAPS
1574# undef update_background
1575void
1576rxvt_term::trace_update_background (const char *file, int line)
1577{
1578 fprintf (stderr, "%s:%d:update_background()\n", file, line);
1579 update_background ();
1580}
1581# endif
1582 1652
1583void 1653void
1584rxvt_term::update_background () 1654rxvt_term::update_background ()
1585{ 1655{
1586 if (update_background_ev.is_active ()) 1656 if (update_background_ev.is_active ())

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines