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.318 by root, Sat May 30 08:51:23 2009 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 }
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{
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
481 ptytty::init (); 559 ptytty::init ();
482 560
483 if (!ev_default_loop (0)) 561 if (!ev_default_loop ())
484 rxvt_fatal ("cannot initialise libev (bad value for LIBEV_METHODS?)\n"); 562 rxvt_fatal ("cannot initialise libev (bad value for LIBEV_METHODS?)\n");
485 563
486 rxvt_environ = environ; 564 rxvt_environ = environ;
487 565
488 signal (SIGHUP, SIG_IGN); 566 signal (SIGHUP, SIG_IGN);
489 signal (SIGPIPE, SIG_IGN); 567 signal (SIGPIPE, SIG_IGN);
490 568
491 sig_handlers.sw_term.start (SIGTERM); ev_unref (); 569 sig_handlers.sw_term.start (SIGTERM); ev_unref ();
492 sig_handlers.sw_int.start (SIGINT); ev_unref (); 570 sig_handlers.sw_int.start (SIGINT); ev_unref ();
493
494 /* need to trap SIGURG for SVR4 (Unixware) rlogin */
495 /* signal (SIGURG, SIG_DFL); */
496 571
497 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 572 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
498 // TODO: handle this with exceptions and tolerate the memory loss 573 // TODO: handle this with exceptions and tolerate the memory loss
499 XSetIOErrorHandler (rxvt_xioerror_handler); 574 XSetIOErrorHandler (rxvt_xioerror_handler);
500 575
686#endif 761#endif
687 762
688 delete fontset[0]; 763 delete fontset[0];
689 fontset[0] = fs; 764 fontset[0] = fs;
690 765
691 prop = (*fs)[1]->properties (); 766 prop = (*fs)[rxvt_fontset::firstFont]->properties ();
692 prop.height += lineSpace; 767 prop.height += lineSpace;
693 prop.width += letterSpace; 768 prop.width += letterSpace;
694 769
695 fs->set_prop (prop, false); 770 fs->set_prop (prop, false);
696 771
748 prop, XA_STRING, 8, PropModeReplace, 823 prop, XA_STRING, 8, PropModeReplace,
749 (const unsigned char *)str, len >= 0 ? len : strlen (str)); 824 (const unsigned char *)str, len >= 0 ? len : strlen (str));
750} 825}
751 826
752void 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
753rxvt_term::set_utf8_property (Atom prop, const char *str, int len) 840rxvt_term::set_utf8_property (Atom prop, const char *str, int len)
754{ 841{
755 wchar_t *ws = rxvt_mbstowcs (str, len); 842 wchar_t *ws = rxvt_mbstowcs (str, len);
756 char *s = rxvt_wcstoutf8 (ws); 843 char *s = rxvt_wcstoutf8 (ws);
757 844
767/*----------------------------------------------------------------------*/ 854/*----------------------------------------------------------------------*/
768/* xterm sequences - title, iconName, color (exptl) */ 855/* xterm sequences - title, iconName, color (exptl) */
769void 856void
770rxvt_term::set_title (const char *str) 857rxvt_term::set_title (const char *str)
771{ 858{
772 set_string_property (XA_WM_NAME, str); 859 set_mbstring_property (XA_WM_NAME, str);
773#if ENABLE_EWMH 860#if ENABLE_EWMH
774 set_utf8_property (xa[XA_NET_WM_NAME], str); 861 set_utf8_property (xa[XA_NET_WM_NAME], str);
775#endif 862#endif
776} 863}
777 864
778void 865void
779rxvt_term::set_icon_name (const char *str) 866rxvt_term::set_icon_name (const char *str)
780{ 867{
781 set_string_property (XA_WM_ICON_NAME, str); 868 set_mbstring_property (XA_WM_ICON_NAME, str);
782#if ENABLE_EWMH 869#if ENABLE_EWMH
783 set_utf8_property (xa[XA_NET_WM_ICON_NAME], str); 870 set_utf8_property (xa[XA_NET_WM_ICON_NAME], str);
784#endif 871#endif
785} 872}
786 873
993 } 1080 }
994 1081
995 if (fix_screen || old_height == 0) 1082 if (fix_screen || old_height == 0)
996 scr_reset (); 1083 scr_reset ();
997 1084
998 // TODO, with nvidia-8178, resizes kill the alpha channel, report if not fixed in newer version
999 //scr_touch (false);
1000
1001#ifdef HAVE_BG_PIXMAP 1085#ifdef HAVE_BG_PIXMAP
1002// TODO: this don't seem to have any effect - do we still need it ? If so - in which case exactly ? 1086// TODO: this don't seem to have any effect - do we still need it ? If so - in which case exactly ?
1003// if (bgPixmap.pixmap) 1087// if (bgPixmap.pixmap)
1004// scr_touch (false); 1088// scr_touch (false);
1005#endif 1089#endif
1163 1247
1164 term->make_current (); 1248 term->make_current ();
1165 1249
1166 if (text) 1250 if (text)
1167 { 1251 {
1168 void *str; 1252 wchar_t *str;
1169 1253
1170 if (!text->encoding_is_wchar && text->string.multi_byte) 1254 if (!text->encoding_is_wchar && text->string.multi_byte)
1171 { 1255 {
1172 // of course, X makes it ugly again 1256 // of course, X makes it ugly again
1173 if (term->rs[Rs_imLocale]) 1257 if (term->rs[Rs_imLocale])
1174 SET_LOCALE (term->rs[Rs_imLocale]); 1258 SET_LOCALE (term->rs[Rs_imLocale]);
1175 1259
1176 str = rxvt_temp_buf ((text->length + 1) * sizeof (wchar_t)); 1260 str = rxvt_temp_buf<wchar_t> (text->length + 1);
1177 mbstowcs ((wchar_t *)str, text->string.multi_byte, text->length + 1); 1261 mbstowcs (str, text->string.multi_byte, text->length + 1);
1178 1262
1179 if (term->rs[Rs_imLocale]) 1263 if (term->rs[Rs_imLocale])
1180 SET_LOCALE (term->locale); 1264 SET_LOCALE (term->locale);
1181 } 1265 }
1182 else 1266 else
1183 str = (void *)text->string.wide_char; 1267 str = text->string.wide_char;
1184 1268
1185 HOOK_INVOKE ((term, HOOK_XIM_PREEDIT_DRAW, 1269 HOOK_INVOKE ((term, HOOK_XIM_PREEDIT_DRAW,
1186 DT_INT, call_data->caret, 1270 DT_INT, call_data->caret,
1187 DT_INT, call_data->chg_first, 1271 DT_INT, call_data->chg_first,
1188 DT_INT, call_data->chg_length, 1272 DT_INT, call_data->chg_length,
1542void 1626void
1543rxvt_term::get_window_origin (int &x, int &y) 1627rxvt_term::get_window_origin (int &x, int &y)
1544{ 1628{
1545 Window cr; 1629 Window cr;
1546 XTranslateCoordinates (dpy, parent[0], display->root, 0, 0, &x, &y, &cr); 1630 XTranslateCoordinates (dpy, parent[0], display->root, 0, 0, &x, &y, &cr);
1547/* fprintf (stderr, "origin is %+d%+d\n", x, y);*/
1548} 1631}
1549 1632
1550Pixmap 1633Pixmap
1551rxvt_term::get_pixmap_property (int prop_id) 1634rxvt_term::get_pixmap_property (int prop_id)
1552{ 1635{
1566 1649
1567 return None; 1650 return None;
1568} 1651}
1569 1652
1570#ifdef HAVE_BG_PIXMAP 1653#ifdef HAVE_BG_PIXMAP
1571# if TRACE_PIXMAPS
1572# undef update_background
1573void
1574rxvt_term::trace_update_background (const char *file, int line)
1575{
1576 fprintf (stderr, "%s:%d:update_background()\n", file, line);
1577 update_background ();
1578}
1579# endif
1580 1654
1581void 1655void
1582rxvt_term::update_background () 1656rxvt_term::update_background ()
1583{ 1657{
1584 if (update_background_ev.is_active ()) 1658 if (update_background_ev.is_active ())

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines