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.310 by root, Wed Feb 27 01:05:55 2008 UTC vs.
Revision 1.331 by sf-exg, Mon Jul 26 22:07:38 2010 UTC

35#include "keyboard.h" 35#include "keyboard.h"
36#include "rxvtperl.h" 36#include "rxvtperl.h"
37 37
38#include <limits> 38#include <limits>
39 39
40#include <cassert>
40#include <csignal> 41#include <csignal>
41#include <cstring> 42#include <cstring>
42 43
43#include <termios.h> 44#include <termios.h>
44 45
101 { 102 {
102 if (cc->c2 == c2) return c1; 103 if (cc->c2 == c2) return c1;
103 cc = (*this)[cc->c1]; 104 cc = (*this)[cc->c1];
104 } 105 }
105 106
106 // check to see wether this combination already exists otherwise 107 // check to see whether this combination already exists otherwise
107 for (cc = v.end (); cc-- > v.begin (); ) 108 for (cc = v.end (); cc-- > v.begin (); )
108 { 109 {
109 if (cc->c1 == c1 && cc->c2 == c2) 110 if (cc->c1 == c1 && cc->c2 == c2)
110 return COMPOSE_LO + (cc - v.begin ()); 111 return COMPOSE_LO + (cc - v.begin ());
111 } 112 }
227 delete fontset[0]; 228 delete fontset[0];
228 229
229#ifdef HAVE_BG_PIXMAP 230#ifdef HAVE_BG_PIXMAP
230 bgPixmap.destroy (); 231 bgPixmap.destroy ();
231#endif 232#endif
233#ifdef HAVE_AFTERIMAGE
234 if (asv)
235 destroy_asvisual (asv, 0);
236 if (asimman)
237 destroy_image_manager (asimman, 0);
238#endif
232 239
233 if (display) 240 if (display)
234 { 241 {
235 selection_clear (); 242 selection_clear ();
243 selection_clear (true);
236 244
237#ifdef USE_XIM 245#ifdef USE_XIM
238 im_destroy (); 246 im_destroy ();
239#endif 247#endif
240 scrollBar.destroy (); 248 scrollBar.destroy ();
265 /* clear all resources */ 273 /* clear all resources */
266 for (int i = 0; i < allocated.size (); i++) 274 for (int i = 0; i < allocated.size (); i++)
267 free (allocated [i]); 275 free (allocated [i]);
268 276
269 free (selection.text); 277 free (selection.text);
278 free (selection.clip_text);
270 // TODO: manage env vars in child only(!) 279 // TODO: manage env vars in child only(!)
271 free (env_display); 280 free (env_display);
272 free (env_term); 281 free (env_term);
273 free (locale); 282 free (locale);
274 free (v_buffer); 283 free (v_buffer);
374 char mesg[BUFSIZ]; 383 char mesg[BUFSIZ];
375 char number[32]; 384 char number[32];
376 char *mtype = "XlibMessage"; 385 char *mtype = "XlibMessage";
377 XGetErrorText(dpy, event->error_code, buffer, BUFSIZ); 386 XGetErrorText(dpy, event->error_code, buffer, BUFSIZ);
378 XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ); 387 XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ);
379 rxvt_warn ("An X Error occured, trying to continue after report.\n"); 388 rxvt_warn ("An X Error occurred, trying to continue after report.\n");
380 rxvt_warn ("%s: %s\n", mesg, buffer); 389 rxvt_warn ("%s: %s\n", mesg, buffer);
381 XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d", mesg, BUFSIZ); 390 XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d", mesg, BUFSIZ);
382 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->request_code); 391 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->request_code);
383 sprintf(number, "%d", event->request_code); 392 sprintf(number, "%d", event->request_code);
384 XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ); 393 XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ);
385 rxvt_warn ("(which is %s)\n", buffer); 394 rxvt_warn ("(which is %s)\n", buffer);
386 if (event->request_code >= 128) { 395 if (event->request_code >= 128) {
387 XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d", 396 XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d",
388 mesg, BUFSIZ); 397 mesg, BUFSIZ);
389 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->minor_code); 398 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->minor_code);
390 } 399 }
391 if ((event->error_code == BadWindow) || 400 if ((event->error_code == BadWindow) ||
392 (event->error_code == BadPixmap) || 401 (event->error_code == BadPixmap) ||
393 (event->error_code == BadCursor) || 402 (event->error_code == BadCursor) ||
394 (event->error_code == BadFont) || 403 (event->error_code == BadFont) ||
395 (event->error_code == BadDrawable) || 404 (event->error_code == BadDrawable) ||
396 (event->error_code == BadColor) || 405 (event->error_code == BadColor) ||
397 (event->error_code == BadGC) || 406 (event->error_code == BadGC) ||
398 (event->error_code == BadIDChoice) || 407 (event->error_code == BadIDChoice) ||
399 (event->error_code == BadValue) || 408 (event->error_code == BadValue) ||
400 (event->error_code == BadAtom)) { 409 (event->error_code == BadAtom)) {
401 if (event->error_code == BadValue) 410 if (event->error_code == BadValue)
402 XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x", 411 XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x",
403 mesg, BUFSIZ); 412 mesg, BUFSIZ);
404 else if (event->error_code == BadAtom) 413 else if (event->error_code == BadAtom)
405 XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x", 414 XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x",
406 mesg, BUFSIZ); 415 mesg, BUFSIZ);
407 else 416 else
408 XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x", 417 XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x",
409 mesg, BUFSIZ); 418 mesg, BUFSIZ);
410 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->resourceid); 419 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->resourceid);
411 } 420 }
412 XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d", 421 XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d",
413 mesg, BUFSIZ); 422 mesg, BUFSIZ);
414 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->serial); 423 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->serial);
415} 424}
416#endif 425#endif
417 426
418int 427int
470char **rxvt_environ; // startup environment 479char **rxvt_environ; // startup environment
471 480
472void 481void
473rxvt_init () 482rxvt_init ()
474{ 483{
484 assert (("fontMask must not overlap other RS masks",
485 0 == (RS_fontMask & (RS_Sel | RS_baseattrMask | RS_customMask | RS_bgMask | RS_fgMask))));
486
487 // get rid of stdin/stdout as we don't need them, to free resources
488 dup2 (STDERR_FILENO, STDIN_FILENO);
489 dup2 (STDERR_FILENO, STDOUT_FILENO);
490
475 ptytty::init (); 491 ptytty::init ();
476 492
477 if (!ev_default_loop (0)) 493 if (!ev_default_loop (0))
478 rxvt_fatal ("cannot initialise libev (bad value for LIBEV_METHODS?)\n"); 494 rxvt_fatal ("cannot initialise libev (bad value for LIBEV_METHODS?)\n");
479 495
482 signal (SIGHUP, SIG_IGN); 498 signal (SIGHUP, SIG_IGN);
483 signal (SIGPIPE, SIG_IGN); 499 signal (SIGPIPE, SIG_IGN);
484 500
485 sig_handlers.sw_term.start (SIGTERM); ev_unref (); 501 sig_handlers.sw_term.start (SIGTERM); ev_unref ();
486 sig_handlers.sw_int.start (SIGINT); ev_unref (); 502 sig_handlers.sw_int.start (SIGINT); ev_unref ();
487
488 /* need to trap SIGURG for SVR4 (Unixware) rlogin */
489 /* signal (SIGURG, SIG_DFL); */
490 503
491 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 504 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
492 // TODO: handle this with exceptions and tolerate the memory loss 505 // TODO: handle this with exceptions and tolerate the memory loss
493 XSetIOErrorHandler (rxvt_xioerror_handler); 506 XSetIOErrorHandler (rxvt_xioerror_handler);
494 507
619 szHint.x += DisplayWidth (dpy, display->screen) - szHint.width - 2 * ext_bwidth; 632 szHint.x += DisplayWidth (dpy, display->screen) - szHint.width - 2 * ext_bwidth;
620 633
621 if (recalc_y) 634 if (recalc_y)
622 szHint.y += DisplayHeight (dpy, display->screen) - szHint.height - 2 * ext_bwidth; 635 szHint.y += DisplayHeight (dpy, display->screen) - szHint.height - 2 * ext_bwidth;
623 636
624 ncol = width / fwidth; 637 ncol = width / fwidth;
625 nrow = height / fheight; 638 nrow = height / fheight;
626} 639}
627 640
628/*----------------------------------------------------------------------*/ 641/*----------------------------------------------------------------------*/
629/* 642/*
640 653
641 ws.ws_col = ncol; 654 ws.ws_col = ncol;
642 ws.ws_row = nrow; 655 ws.ws_row = nrow;
643 ws.ws_xpixel = width; 656 ws.ws_xpixel = width;
644 ws.ws_ypixel = height; 657 ws.ws_ypixel = height;
645 (void)ioctl (pty->pty, TIOCSWINSZ, &ws); 658 ioctl (pty->pty, TIOCSWINSZ, &ws);
646 659
647#if 0 660#if 0
648 // TIOCSWINSZ is supposed to do this automatically and correctly 661 // TIOCSWINSZ is supposed to do this automatically and correctly
649 if (cmd_pid) /* force through to the command */ 662 if (cmd_pid) /* force through to the command */
650 kill (-cmd_pid, SIGWINCH); 663 kill (-cmd_pid, SIGWINCH);
680#endif 693#endif
681 694
682 delete fontset[0]; 695 delete fontset[0];
683 fontset[0] = fs; 696 fontset[0] = fs;
684 697
685 prop = (*fs)[1]->properties (); 698 prop = (*fs)[rxvt_fontset::firstFont]->properties ();
686 prop.height += lineSpace; 699 prop.height += lineSpace;
700 prop.width += letterSpace;
687 701
688 fs->set_prop (prop, false); 702 fs->set_prop (prop, false);
689 703
690 fwidth = prop.width; 704 fwidth = prop.width;
691 fheight = prop.height; 705 fheight = prop.height;
741 prop, XA_STRING, 8, PropModeReplace, 755 prop, XA_STRING, 8, PropModeReplace,
742 (const unsigned char *)str, len >= 0 ? len : strlen (str)); 756 (const unsigned char *)str, len >= 0 ? len : strlen (str));
743} 757}
744 758
745void 759void
760rxvt_term::set_mbstring_property (Atom prop, const char *str, int len)
761{
762 XTextProperty ct;
763
764 if (XmbTextListToTextProperty (dpy, (char **)&str, 1, XStdICCTextStyle, &ct) >= 0)
765 {
766 XSetTextProperty (dpy, parent[0], &ct, prop);
767 XFree (ct.value);
768 }
769}
770
771void
746rxvt_term::set_utf8_property (Atom prop, const char *str, int len) 772rxvt_term::set_utf8_property (Atom prop, const char *str, int len)
747{ 773{
748 wchar_t *ws = rxvt_mbstowcs (str, len); 774 wchar_t *ws = rxvt_mbstowcs (str, len);
749 char *s = rxvt_wcstoutf8 (ws); 775 char *s = rxvt_wcstoutf8 (ws);
750 776
760/*----------------------------------------------------------------------*/ 786/*----------------------------------------------------------------------*/
761/* xterm sequences - title, iconName, color (exptl) */ 787/* xterm sequences - title, iconName, color (exptl) */
762void 788void
763rxvt_term::set_title (const char *str) 789rxvt_term::set_title (const char *str)
764{ 790{
765 set_string_property (XA_WM_NAME, str); 791 set_mbstring_property (XA_WM_NAME, str);
766#if ENABLE_EWMH 792#if ENABLE_EWMH
767 set_utf8_property (xa[XA_NET_WM_NAME], str); 793 set_utf8_property (xa[XA_NET_WM_NAME], str);
768#endif 794#endif
769} 795}
770 796
771void 797void
772rxvt_term::set_icon_name (const char *str) 798rxvt_term::set_icon_name (const char *str)
773{ 799{
774 set_string_property (XA_WM_ICON_NAME, str); 800 set_mbstring_property (XA_WM_ICON_NAME, str);
775#if ENABLE_EWMH 801#if ENABLE_EWMH
776 set_utf8_property (xa[XA_NET_WM_ICON_NAME], str); 802 set_utf8_property (xa[XA_NET_WM_ICON_NAME], str);
777#endif 803#endif
778} 804}
779 805
905 int old_width = szHint.width; 931 int old_width = szHint.width;
906 int old_height = szHint.height; 932 int old_height = szHint.height;
907 933
908 window_calc (newwidth, newheight); 934 window_calc (newwidth, newheight);
909 935
910 if (!HOOK_INVOKE ((this, HOOK_RESIZE_ALL_WINDOWS, DT_INT, newwidth, DT_INT, newheight, DT_END))) 936 bool set_hint = !HOOK_INVOKE ((this, HOOK_RESIZE_ALL_WINDOWS, DT_INT, newwidth, DT_INT, newheight, DT_END));
937
938 // to avoid races between us and the wm, we clear the incremental size hints around the xresizewindow
939 if (set_hint)
940 {
941 szHint.flags &= ~(PBaseSize | PResizeInc);
911 XSetWMNormalHints (dpy, parent[0], &szHint); 942 XSetWMNormalHints (dpy, parent[0], &szHint);
943 szHint.flags |= PBaseSize | PResizeInc;
944 }
912 945
913 if (!ignoreparent) 946 if (!ignoreparent)
914 { 947 {
915#ifdef SMART_RESIZE 948#ifdef SMART_RESIZE
916 /* 949 /*
956#else 989#else
957 XResizeWindow (dpy, parent[0], szHint.width, szHint.height); 990 XResizeWindow (dpy, parent[0], szHint.width, szHint.height);
958#endif 991#endif
959 } 992 }
960 993
994 if (set_hint)
995 XSetWMNormalHints (dpy, parent[0], &szHint);
996
961 fix_screen = ncol != prev_ncol || nrow != prev_nrow; 997 fix_screen = ncol != prev_ncol || nrow != prev_nrow;
962 998
963 if (fix_screen || newwidth != old_width || newheight != old_height) 999 if (fix_screen || newwidth != old_width || newheight != old_height)
964 { 1000 {
965 if (scrollBar.state) 1001 if (scrollBar.state)
971 1007
972#ifdef HAVE_BG_PIXMAP 1008#ifdef HAVE_BG_PIXMAP
973 if (bgPixmap.window_size_sensitive ()) 1009 if (bgPixmap.window_size_sensitive ())
974 update_background (); 1010 update_background ();
975#endif 1011#endif
976
977 scr_clear ();
978 } 1012 }
979 1013
980 if (fix_screen || old_height == 0) 1014 if (fix_screen || old_height == 0)
981 scr_reset (); 1015 scr_reset ();
982
983 // TODO, with nvidia-8178, resizes kill the alpha channel, report if not fixed in newer version
984 //scr_touch (false);
985 1016
986#ifdef HAVE_BG_PIXMAP 1017#ifdef HAVE_BG_PIXMAP
987// TODO: this don't seem to have any effect - do we still need it ? If so - in which case exactly ? 1018// TODO: this don't seem to have any effect - do we still need it ? If so - in which case exactly ?
988// if (bgPixmap.pixmap) 1019// if (bgPixmap.pixmap)
989// scr_touch (false); 1020// scr_touch (false);
1061 1092
1062/* Checking whether input method is running. */ 1093/* Checking whether input method is running. */
1063bool 1094bool
1064rxvt_term::IMisRunning () 1095rxvt_term::IMisRunning ()
1065{ 1096{
1066 char *p;
1067 Atom atom; 1097 Atom atom;
1068 Window win; 1098 Window win;
1069 char server[IMBUFSIZ]; 1099 char server[IMBUFSIZ];
1070 1100
1071 /* get current locale modifier */ 1101 /* get current locale modifier */
1072 if ((p = XSetLocaleModifiers (NULL)) != NULL) 1102 if (char *p = XSetLocaleModifiers (0))
1073 { 1103 {
1074 strcpy (server, "@server="); 1104 strcpy (server, "@server=");
1075 strncat (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */ 1105 strncat (server, p + 4, IMBUFSIZ - 9); /* skip "@im=" */
1076 1106
1077 if ((p = strchr (server + 1, '@')) != NULL) /* first one only */ 1107 if (p = strchr (server + 1, '@')) /* first one only */
1078 *p = '\0'; 1108 *p = '\0';
1079 1109
1080 atom = XInternAtom (dpy, server, False); 1110 atom = XInternAtom (dpy, server, False);
1081 win = XGetSelectionOwner (dpy, atom); 1111 win = XGetSelectionOwner (dpy, atom);
1082 1112
1149 1179
1150 term->make_current (); 1180 term->make_current ();
1151 1181
1152 if (text) 1182 if (text)
1153 { 1183 {
1154 void *str; 1184 wchar_t *str;
1155 1185
1156 if (!text->encoding_is_wchar && text->string.multi_byte) 1186 if (!text->encoding_is_wchar && text->string.multi_byte)
1157 { 1187 {
1158 // of course, X makes it ugly again 1188 // of course, X makes it ugly again
1159 if (term->rs[Rs_imLocale]) 1189 if (term->rs[Rs_imLocale])
1160 SET_LOCALE (term->rs[Rs_imLocale]); 1190 SET_LOCALE (term->rs[Rs_imLocale]);
1161 1191
1162 str = rxvt_temp_buf ((text->length + 1) * sizeof (wchar_t)); 1192 str = rxvt_temp_buf<wchar_t> (text->length + 1);
1163 mbstowcs ((wchar_t *)str, text->string.multi_byte, text->length + 1); 1193 mbstowcs (str, text->string.multi_byte, text->length + 1);
1164 1194
1165 if (term->rs[Rs_imLocale]) 1195 if (term->rs[Rs_imLocale])
1166 SET_LOCALE (term->locale); 1196 SET_LOCALE (term->locale);
1167 } 1197 }
1168 else 1198 else
1169 str = (void *)text->string.wide_char; 1199 str = text->string.wide_char;
1170 1200
1171 HOOK_INVOKE ((term, HOOK_XIM_PREEDIT_DRAW, 1201 HOOK_INVOKE ((term, HOOK_XIM_PREEDIT_DRAW,
1172 DT_INT, call_data->caret, 1202 DT_INT, call_data->caret,
1173 DT_INT, call_data->chg_first, 1203 DT_INT, call_data->chg_first,
1174 DT_INT, call_data->chg_length, 1204 DT_INT, call_data->chg_length,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines