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.322 by root, Tue Mar 30 23:00:35 2010 UTC vs.
Revision 1.334 by sf-exg, Fri Oct 22 16:49:26 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 }
382 char mesg[BUFSIZ]; 385 char mesg[BUFSIZ];
383 char number[32]; 386 char number[32];
384 char *mtype = "XlibMessage"; 387 char *mtype = "XlibMessage";
385 XGetErrorText(dpy, event->error_code, buffer, BUFSIZ); 388 XGetErrorText(dpy, event->error_code, buffer, BUFSIZ);
386 XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ); 389 XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ);
387 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");
388 rxvt_warn ("%s: %s\n", mesg, buffer); 391 rxvt_warn ("%s: %s\n", mesg, buffer);
389 XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d", mesg, BUFSIZ); 392 XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d", mesg, BUFSIZ);
390 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->request_code); 393 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->request_code);
391 sprintf(number, "%d", event->request_code); 394 sprintf(number, "%d", event->request_code);
392 XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ); 395 XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ);
393 rxvt_warn ("(which is %s)\n", buffer); 396 rxvt_warn ("(which is %s)\n", buffer);
394 if (event->request_code >= 128) { 397 if (event->request_code >= 128) {
395 XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d", 398 XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d",
396 mesg, BUFSIZ); 399 mesg, BUFSIZ);
397 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->minor_code); 400 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->minor_code);
398 } 401 }
399 if ((event->error_code == BadWindow) || 402 if ((event->error_code == BadWindow) ||
400 (event->error_code == BadPixmap) || 403 (event->error_code == BadPixmap) ||
401 (event->error_code == BadCursor) || 404 (event->error_code == BadCursor) ||
402 (event->error_code == BadFont) || 405 (event->error_code == BadFont) ||
403 (event->error_code == BadDrawable) || 406 (event->error_code == BadDrawable) ||
404 (event->error_code == BadColor) || 407 (event->error_code == BadColor) ||
405 (event->error_code == BadGC) || 408 (event->error_code == BadGC) ||
406 (event->error_code == BadIDChoice) || 409 (event->error_code == BadIDChoice) ||
407 (event->error_code == BadValue) || 410 (event->error_code == BadValue) ||
408 (event->error_code == BadAtom)) { 411 (event->error_code == BadAtom)) {
409 if (event->error_code == BadValue) 412 if (event->error_code == BadValue)
410 XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x", 413 XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x",
411 mesg, BUFSIZ); 414 mesg, BUFSIZ);
412 else if (event->error_code == BadAtom) 415 else if (event->error_code == BadAtom)
413 XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x", 416 XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x",
414 mesg, BUFSIZ); 417 mesg, BUFSIZ);
415 else 418 else
416 XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x", 419 XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x",
417 mesg, BUFSIZ); 420 mesg, BUFSIZ);
418 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->resourceid); 421 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->resourceid);
419 } 422 }
420 XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d", 423 XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d",
421 mesg, BUFSIZ); 424 mesg, BUFSIZ);
422 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->serial); 425 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->serial);
423} 426}
424#endif 427#endif
425 428
426int 429int
473 rxvt_emergency_cleanup (); 476 rxvt_emergency_cleanup ();
474 w.stop (); 477 w.stop ();
475 kill (getpid (), w.signum); 478 kill (getpid (), w.signum);
476} 479}
477 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
478char **rxvt_environ; // startup environment 545char **rxvt_environ; // startup environment
479 546
480void 547void
481rxvt_init () 548rxvt_init ()
482{ 549{
550 assert (("fontMask must not overlap other RS masks",
551 0 == (RS_fontMask & (RS_Sel | RS_baseattrMask | RS_customMask | RS_bgMask | RS_fgMask))));
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 ptytty::init (); 559 ptytty::init ();
484 560
485 if (!ev_default_loop (0)) 561 if (!ev_default_loop ())
486 rxvt_fatal ("cannot initialise libev (bad value for LIBEV_METHODS?)\n"); 562 rxvt_fatal ("cannot initialise libev (bad value for LIBEV_METHODS?)\n");
487 563
488 rxvt_environ = environ; 564 rxvt_environ = environ;
489 565
490 signal (SIGHUP, SIG_IGN); 566 signal (SIGHUP, SIG_IGN);
491 signal (SIGPIPE, SIG_IGN); 567 signal (SIGPIPE, SIG_IGN);
492 568
493 sig_handlers.sw_term.start (SIGTERM); ev_unref (); 569 sig_handlers.sw_term.start (SIGTERM); ev_unref ();
494 sig_handlers.sw_int.start (SIGINT); ev_unref (); 570 sig_handlers.sw_int.start (SIGINT); ev_unref ();
495
496 /* need to trap SIGURG for SVR4 (Unixware) rlogin */
497 /* signal (SIGURG, SIG_DFL); */
498 571
499 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 572 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
500 // TODO: handle this with exceptions and tolerate the memory loss 573 // TODO: handle this with exceptions and tolerate the memory loss
501 XSetIOErrorHandler (rxvt_xioerror_handler); 574 XSetIOErrorHandler (rxvt_xioerror_handler);
502 575
688#endif 761#endif
689 762
690 delete fontset[0]; 763 delete fontset[0];
691 fontset[0] = fs; 764 fontset[0] = fs;
692 765
693 prop = fs->get (0, 1)->properties (); 766 prop = (*fs)[rxvt_fontset::firstFont]->properties ();
694 prop.height += lineSpace; 767 prop.height += lineSpace;
695 prop.width += letterSpace; 768 prop.width += letterSpace;
696 769
697 fs->set_prop (prop, false); 770 fs->set_prop (prop, false);
698 771
750 prop, XA_STRING, 8, PropModeReplace, 823 prop, XA_STRING, 8, PropModeReplace,
751 (const unsigned char *)str, len >= 0 ? len : strlen (str)); 824 (const unsigned char *)str, len >= 0 ? len : strlen (str));
752} 825}
753 826
754void 827void
828rxvt_term::set_mbstring_property (Atom prop, const char *str, int len)
829{
830 XTextProperty ct;
831
832 if (XmbTextListToTextProperty (dpy, (char **)&str, 1, XStdICCTextStyle, &ct) >= 0)
833 {
834 XSetTextProperty (dpy, parent[0], &ct, prop);
835 XFree (ct.value);
836 }
837}
838
839void
755rxvt_term::set_utf8_property (Atom prop, const char *str, int len) 840rxvt_term::set_utf8_property (Atom prop, const char *str, int len)
756{ 841{
757 wchar_t *ws = rxvt_mbstowcs (str, len); 842 wchar_t *ws = rxvt_mbstowcs (str, len);
758 char *s = rxvt_wcstoutf8 (ws); 843 char *s = rxvt_wcstoutf8 (ws);
759 844
769/*----------------------------------------------------------------------*/ 854/*----------------------------------------------------------------------*/
770/* xterm sequences - title, iconName, color (exptl) */ 855/* xterm sequences - title, iconName, color (exptl) */
771void 856void
772rxvt_term::set_title (const char *str) 857rxvt_term::set_title (const char *str)
773{ 858{
774 set_string_property (XA_WM_NAME, str); 859 set_mbstring_property (XA_WM_NAME, str);
775#if ENABLE_EWMH 860#if ENABLE_EWMH
776 set_utf8_property (xa[XA_NET_WM_NAME], str); 861 set_utf8_property (xa[XA_NET_WM_NAME], str);
777#endif 862#endif
778} 863}
779 864
780void 865void
781rxvt_term::set_icon_name (const char *str) 866rxvt_term::set_icon_name (const char *str)
782{ 867{
783 set_string_property (XA_WM_ICON_NAME, str); 868 set_mbstring_property (XA_WM_ICON_NAME, str);
784#if ENABLE_EWMH 869#if ENABLE_EWMH
785 set_utf8_property (xa[XA_NET_WM_ICON_NAME], str); 870 set_utf8_property (xa[XA_NET_WM_ICON_NAME], str);
786#endif 871#endif
787} 872}
788 873
1541void 1626void
1542rxvt_term::get_window_origin (int &x, int &y) 1627rxvt_term::get_window_origin (int &x, int &y)
1543{ 1628{
1544 Window cr; 1629 Window cr;
1545 XTranslateCoordinates (dpy, parent[0], display->root, 0, 0, &x, &y, &cr); 1630 XTranslateCoordinates (dpy, parent[0], display->root, 0, 0, &x, &y, &cr);
1546/* fprintf (stderr, "origin is %+d%+d\n", x, y);*/
1547} 1631}
1548 1632
1549Pixmap 1633Pixmap
1550rxvt_term::get_pixmap_property (int prop_id) 1634rxvt_term::get_pixmap_property (int prop_id)
1551{ 1635{
1565 1649
1566 return None; 1650 return None;
1567} 1651}
1568 1652
1569#ifdef HAVE_BG_PIXMAP 1653#ifdef HAVE_BG_PIXMAP
1570# if TRACE_PIXMAPS
1571# undef update_background
1572void
1573rxvt_term::trace_update_background (const char *file, int line)
1574{
1575 fprintf (stderr, "%s:%d:update_background()\n", file, line);
1576 update_background ();
1577}
1578# endif
1579 1654
1580void 1655void
1581rxvt_term::update_background () 1656rxvt_term::update_background ()
1582{ 1657{
1583 if (update_background_ev.is_active ()) 1658 if (update_background_ev.is_active ())

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines