ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/init.C
(Generate patch)

Comparing rxvt-unicode/src/init.C (file contents):
Revision 1.320 by sf-exg, Thu Jan 19 15:08:55 2012 UTC vs.
Revision 1.342 by root, Mon Dec 15 02:04:02 2014 UTC

14 * - extensive modifications 14 * - extensive modifications
15 * Copyright (c) 2003-2008 Marc Lehmann <schmorp@schmorp.de> 15 * Copyright (c) 2003-2008 Marc Lehmann <schmorp@schmorp.de>
16 * 16 *
17 * This program is free software; you can redistribute it and/or modify 17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by 18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or 19 * the Free Software Foundation; either version 3 of the License, or
20 * (at your option) any later version. 20 * (at your option) any later version.
21 * 21 *
22 * This program is distributed in the hope that it will be useful, 22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
76#include <netinet/in.h> 76#include <netinet/in.h>
77#include <arpa/inet.h> 77#include <arpa/inet.h>
78#include <net/if.h> 78#include <net/if.h>
79#include <net/if_arp.h> 79#include <net/if_arp.h>
80 80
81static char * 81static char * ecb_cold
82rxvt_network_display (const char *display) 82rxvt_network_display (const char *display)
83{ 83{
84 char buffer[1024], *rval = NULL; 84 char buffer[1024], *rval = NULL;
85 struct ifconf ifc; 85 struct ifconf ifc;
86 struct ifreq *ifr; 86 struct ifreq *ifr;
519#endif 519#endif
520 COLOR_SCROLLBAR, 520 COLOR_SCROLLBAR,
521#ifdef RXVT_SCROLLBAR 521#ifdef RXVT_SCROLLBAR
522 COLOR_SCROLLTROUGH, 522 COLOR_SCROLLTROUGH,
523#endif 523#endif
524#if ENABLE_TRANSPARENCY 524#if BG_IMAGE_FROM_ROOT
525 NULL, 525 NULL,
526#endif 526#endif
527#if OFF_FOCUS_FADING 527#if OFF_FOCUS_FADING
528 "rgb:00/00/00", 528 "rgb:00/00/00",
529#endif 529#endif
588 xa = display->xa; 588 xa = display->xa;
589 589
590 set (display); 590 set (display);
591 extract_resources (); 591 extract_resources ();
592 592
593#if XFT 593#if ENABLE_FRILLS
594 if (rs[Rs_depth]) 594 if (rs[Rs_visual])
595 select_visual (strtol (rs[Rs_depth], 0, 0)); 595 select_visual (strtol (rs[Rs_visual], 0, 0));
596 else if (rs[Rs_depth])
597 select_depth (strtol (rs[Rs_depth], 0, 0));
596#endif 598#endif
597 599
598 for (int i = NUM_RESOURCES; i--; ) 600 for (int i = NUM_RESOURCES; i--; )
599 if (rs [i] == resval_undef) 601 if (rs [i] == resval_undef)
600 rs [i] = 0; 602 rs [i] = 0;
657 if (rs[Rs_pointerBlankDelay] && (i = atoi (rs[Rs_pointerBlankDelay])) >= 0) 659 if (rs[Rs_pointerBlankDelay] && (i = atoi (rs[Rs_pointerBlankDelay])) >= 0)
658 pointerBlankDelay = i; 660 pointerBlankDelay = i;
659 else 661 else
660 pointerBlankDelay = 2; 662 pointerBlankDelay = 2;
661#endif 663#endif
664
665 if (rs[Rs_multiClickTime] && (i = atoi (rs[Rs_multiClickTime])) >= 0)
666 multiClickTime = i;
667 else
668 multiClickTime = 500;
669
670 cursor_type = option (Opt_cursorUnderline) ? 1 : 0;
662 671
663 /* no point having a scrollbar without having any scrollback! */ 672 /* no point having a scrollbar without having any scrollback! */
664 if (!saveLines) 673 if (!saveLines)
665 set_option (Opt_scrollBar, 0); 674 set_option (Opt_scrollBar, 0);
666 675
739 envv->push_back (0); 748 envv->push_back (0);
740 749
741 this->argv = argv; 750 this->argv = argv;
742 this->envv = envv; 751 this->envv = envv;
743 752
753 env = new char *[this->envv->size ()];
754 for (int i = 0; i < this->envv->size (); i++)
755 env[i] = this->envv->at (i);
756
744 init2 (argv->size () - 1, argv->begin ()); 757 init2 (argv->size () - 1, argv->begin ());
745} 758}
746 759
747void 760void
748rxvt_term::init (int argc, const char *const *argv, const char *const *envv) 761rxvt_term::init (int argc, const char *const *argv, const char *const *envv)
766void 779void
767rxvt_term::init2 (int argc, const char *const *argv) 780rxvt_term::init2 (int argc, const char *const *argv)
768{ 781{
769 SET_R (this); 782 SET_R (this);
770 set_locale (""); 783 set_locale ("");
771 set_environ (envv); // a few things in X do not call setlocale :( 784 set_environ (env); // a few things in X do not call setlocale :(
772 785
773 init_vars (); 786 init_vars ();
774 787
775 const char **cmd_argv = init_resources (argc, argv); 788 const char **cmd_argv = init_resources (argc, argv);
776 789
791 if (option (Opt_scrollBar)) 804 if (option (Opt_scrollBar))
792 scrollBar.state = SB_STATE_IDLE; /* set existence for size calculations */ 805 scrollBar.state = SB_STATE_IDLE; /* set existence for size calculations */
793 806
794 pty = ptytty::create (); 807 pty = ptytty::create ();
795 808
796#ifdef HAVE_AFTERIMAGE
797 set_application_name ((char *)rs[Rs_name]);
798 set_output_threshold (OUTPUT_LEVEL_WARNING);
799#endif
800
801 // must be called before create_windows, because the latter may call set_icon
802#ifdef HAVE_PIXBUF
803 g_type_init ();
804#endif
805
806 create_windows (argc, argv); 809 create_windows (argc, argv);
807 810
808 init_xlocale (); 811 init_xlocale ();
809 812
810 scr_poweron (); // initialize screen 813 scr_poweron (); // initialize screen
813 XSynchronize (dpy, True); 816 XSynchronize (dpy, True);
814#endif 817#endif
815 818
816 if (option (Opt_scrollBar)) 819 if (option (Opt_scrollBar))
817 scrollBar.resize (); /* create and map scrollbar */ 820 scrollBar.resize (); /* create and map scrollbar */
821
818#ifdef HAVE_BG_PIXMAP 822#ifdef HAVE_BG_PIXMAP
819 {
820 bg_init (); 823 bg_init ();
821
822#ifdef ENABLE_TRANSPARENCY
823 if (option (Opt_transparent))
824 {
825 bg_set_transparent ();
826
827 if (rs [Rs_blurradius])
828 bg_set_blur (rs [Rs_blurradius]);
829
830 if (ISSET_PIXCOLOR (Color_tint))
831 bg_set_tint (pix_colors_focused [Color_tint]);
832
833 if (rs [Rs_shade])
834 bg_set_shade (rs [Rs_shade]);
835
836 bg_set_root_pixmap ();
837 XSelectInput (dpy, display->root, PropertyChangeMask);
838 rootwin_ev.start (display, display->root);
839 }
840#endif
841
842#ifdef BG_IMAGE_FROM_FILE
843 if (rs[Rs_backgroundPixmap])
844 if (bg_set_file (rs[Rs_backgroundPixmap]))
845 if (!bg_window_position_sensitive ())
846 update_background ();
847#endif
848 }
849#endif 824#endif
850 825
851#if ENABLE_PERL 826#if ENABLE_PERL
852 rootwin_ev.start (display, display->root); 827 rootwin_ev.start (display, display->root);
853#endif 828#endif
981 956
982/*----------------------------------------------------------------------*/ 957/*----------------------------------------------------------------------*/
983void 958void
984rxvt_term::set_locale (const char *locale) 959rxvt_term::set_locale (const char *locale)
985{ 960{
986 set_environ (envv); 961 set_environ (env);
987 962
988 free (this->locale); 963 free (this->locale);
989 this->locale = setlocale (LC_CTYPE, locale); 964 this->locale = setlocale (LC_CTYPE, locale);
990 965
991 if (!this->locale) 966 if (!this->locale)
1019} 994}
1020 995
1021void 996void
1022rxvt_term::init_xlocale () 997rxvt_term::init_xlocale ()
1023{ 998{
1024 set_environ (envv); 999 set_environ (env);
1025 1000
1026#ifdef USE_XIM 1001#if USE_XIM
1027 if (!locale) 1002 if (!locale)
1028 rxvt_warn ("setting locale failed, continuing without locale support.\n"); 1003 rxvt_warn ("setting locale failed, continuing without locale support.\n");
1029 else 1004 else
1030 { 1005 {
1031 set_string_property (xa[XA_WM_LOCALE_NAME], locale); 1006 set_string_property (xa[XA_WM_LOCALE_NAME], locale);
1081 run_command (argv); 1056 run_command (argv);
1082} 1057}
1083 1058
1084/*----------------------------------------------------------------------*/ 1059/*----------------------------------------------------------------------*/
1085void 1060void
1086rxvt_term::get_colours () 1061rxvt_term::get_colors ()
1087{ 1062{
1088 int i; 1063 int i;
1089 1064
1090#ifdef OFF_FOCUS_FADING 1065#ifdef OFF_FOCUS_FADING
1091 pix_colors = pix_colors_focused; 1066 pix_colors = pix_colors_focused;
1092#endif 1067#endif
1093 1068
1094 for (i = 0; i < (depth <= 2 ? 2 : NRS_COLORS); i++) 1069 for (i = 0; i < NRS_COLORS; i++)
1095 {
1096 const char *name = rs[Rs_color + i]; 1070 if (const char *name = rs[Rs_color + i])
1097
1098 if (!name)
1099 continue;
1100
1101 rxvt_color xcol;
1102
1103 if (!set_color (xcol, name)) 1071 set_color (pix_colors [i], name);
1104 {
1105#ifndef XTERM_REVERSE_VIDEO
1106 if (i < 2 && option (Opt_reverseVideo))
1107 name = def_colorName [1 - i];
1108 else
1109#endif
1110 name = def_colorName [i];
1111
1112 if (!name)
1113 continue;
1114
1115 if (!set_color (xcol, name))
1116 {
1117 switch (i)
1118 {
1119 case Color_fg:
1120 case Color_bg:
1121 rxvt_warn ("unable to get foreground/background colour, continuing.\n");
1122 name = "";
1123 break;
1124#ifndef NO_CURSORCOLOR
1125 case Color_cursor2:
1126#endif
1127 case Color_pointer_fg:
1128 name = rs[Rs_color + Color_fg];
1129 xcol.set (this, name);
1130 break;
1131 default:
1132 name = rs[Rs_color + Color_bg];
1133 xcol.set (this, name);
1134 break;
1135 }
1136 }
1137 }
1138
1139 pix_colors[i] = xcol;
1140 rs[Rs_color + i] = name;
1141 }
1142
1143 if (depth <= 2)
1144 {
1145 if (!rs[Rs_color + Color_pointer_fg]) alias_color (Color_pointer_fg, Color_fg);
1146 if (!rs[Rs_color + Color_pointer_bg]) alias_color (Color_pointer_bg, Color_bg);
1147 if (!rs[Rs_color + Color_border] ) alias_color (Color_border, Color_fg);
1148 }
1149 1072
1150 /* 1073 /*
1151 * get scrollBar shadow colors 1074 * get scrollBar shadow colors
1152 * 1075 *
1153 * The calculations of topShadow/bottomShadow values are adapted 1076 * The calculations of topShadow/bottomShadow values are adapted
1154 * from the fvwm window manager. 1077 * from the fvwm window manager.
1155 */ 1078 */
1156#ifdef RXVT_SCROLLBAR 1079#ifdef RXVT_SCROLLBAR
1157 if (depth <= 2)
1158 {
1159 /* Monochrome */
1160 alias_color (Color_scroll, Color_fg);
1161 alias_color (Color_topShadow, Color_bg);
1162 alias_color (Color_bottomShadow, Color_bg);
1163 }
1164 else
1165 {
1166 pix_colors [Color_scroll].fade (this, 50, pix_colors [Color_bottomShadow]); 1080 pix_colors [Color_scroll].fade (this, 50, pix_colors [Color_bottomShadow]);
1167 1081
1168 rgba cscroll; 1082 rgba cscroll;
1169 pix_colors [Color_scroll].get (cscroll); 1083 pix_colors [Color_scroll].get (cscroll);
1170 1084
1171 /* topShadowColor */ 1085 /* topShadowColor */
1172 if (!pix_colors[Color_topShadow].set (this, 1086 if (!pix_colors[Color_topShadow].set (this,
1173 rgba ( 1087 rgba (
1174 min ((int)rgba::MAX_CC, max (cscroll.r / 5, cscroll.r) * 7 / 5), 1088 min ((int)rgba::MAX_CC, max (cscroll.r / 5, cscroll.r) * 7 / 5),
1175 min ((int)rgba::MAX_CC, max (cscroll.g / 5, cscroll.g) * 7 / 5), 1089 min ((int)rgba::MAX_CC, max (cscroll.g / 5, cscroll.g) * 7 / 5),
1176 min ((int)rgba::MAX_CC, max (cscroll.b / 5, cscroll.b) * 7 / 5), 1090 min ((int)rgba::MAX_CC, max (cscroll.b / 5, cscroll.b) * 7 / 5),
1177 cscroll.a) 1091 cscroll.a)
1178 )) 1092 ))
1179 alias_color (Color_topShadow, Color_White); 1093 alias_color (Color_topShadow, Color_White);
1180 }
1181#endif 1094#endif
1182 1095
1183#ifdef OFF_FOCUS_FADING 1096#ifdef OFF_FOCUS_FADING
1184 for (i = 0; i < (depth <= 2 ? 2 : NRS_COLORS); i++) 1097 for (i = 0; i < NRS_COLORS; i++)
1185 update_fade_color (i); 1098 update_fade_color (i, true);
1186#endif 1099#endif
1187} 1100}
1188 1101
1189/*----------------------------------------------------------------------*/ 1102/*----------------------------------------------------------------------*/
1190/* color aliases, fg/bg bright-bold */ 1103/* color aliases, fg/bg bright-bold */
1239 for (j = map->max_keypermod; j--; k++) 1152 for (j = map->max_keypermod; j--; k++)
1240 { 1153 {
1241 if (kc[k] == 0) 1154 if (kc[k] == 0)
1242 break; 1155 break;
1243 1156
1244 switch (XKeycodeToKeysym (dpy, kc[k], 0)) 1157 switch (rxvt_XKeycodeToKeysym (dpy, kc[k], 0))
1245 { 1158 {
1246 case XK_Num_Lock: 1159 case XK_Num_Lock:
1247 ModNumLockMask = modmasks[i - 1]; 1160 ModNumLockMask = modmasks[i - 1];
1248 continue; 1161 continue;
1249 1162
1294} 1207}
1295 1208
1296void 1209void
1297rxvt_term::set_icon (const char *file) 1210rxvt_term::set_icon (const char *file)
1298{ 1211{
1299#ifdef HAVE_AFTERIMAGE
1300 init_asv ();
1301
1302 ASImage *im = file2ASImage (file, 0xFFFFFFFF, SCREEN_GAMMA, 0, NULL);
1303 if (!im)
1304 {
1305 rxvt_warn ("Loading image icon failed, continuing without.\n");
1306 return;
1307 }
1308
1309 unsigned int w = im->width;
1310 unsigned int h = im->height;
1311
1312 if (!IN_RANGE_INC (w, 1, 16383) || !IN_RANGE_INC (h, 1, 16383))
1313 {
1314 rxvt_warn ("Icon image too big, continuing without.\n");
1315 destroy_asimage (&im);
1316 return;
1317 }
1318
1319 ASImage *result = scale_asimage (asv, im,
1320 w, h, ASA_ARGB32,
1321 100, ASIMAGE_QUALITY_DEFAULT);
1322 destroy_asimage (&im);
1323
1324 if (!result)
1325 {
1326 rxvt_warn ("Icon image transformation to ARGB failed, continuing without.\n");
1327 return;
1328 }
1329
1330 long *buffer = (long *)malloc ((2 + w * h) * sizeof (long));
1331 if (buffer)
1332 {
1333 ARGB32 *asbuf = result->alt.argb32;
1334 buffer [0] = w;
1335 buffer [1] = h;
1336
1337 for (unsigned int i = 0; i < w * h; ++i)
1338 buffer [i + 2] = asbuf [i];
1339
1340 XChangeProperty (dpy, parent, xa[XA_NET_WM_ICON], XA_CARDINAL, 32,
1341 PropModeReplace, (const unsigned char *) buffer, 2 + w * h);
1342 free (buffer);
1343 }
1344 else
1345 rxvt_warn ("Memory allocation for icon hint failed, continuing without.\n");
1346
1347 destroy_asimage (&result);
1348#endif
1349
1350#ifdef HAVE_PIXBUF 1212#if HAVE_PIXBUF
1351 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (file, NULL); 1213 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (file, NULL);
1352 if (!pixbuf) 1214 if (!pixbuf)
1353 { 1215 {
1354 rxvt_warn ("Loading image icon failed, continuing without.\n"); 1216 rxvt_warn ("Loading image icon failed, continuing without.\n");
1355 return; 1217 return;
1420 Window top, parent; 1282 Window top, parent;
1421 1283
1422 dLocal (Display *, dpy); 1284 dLocal (Display *, dpy);
1423 1285
1424 /* grab colors before netscape does */ 1286 /* grab colors before netscape does */
1425 get_colours (); 1287 get_colors ();
1426 1288
1427 if (!set_fonts ()) 1289 if (!set_fonts ())
1428 rxvt_fatal ("unable to load base fontset, please specify a valid one using -fn, aborting.\n"); 1290 rxvt_fatal ("unable to load base fontset, please specify a valid one using -fn, aborting.\n");
1429 1291
1430 parent = display->root; 1292 parent = display->root;
1483 classHint.res_name = (char *)rs[Rs_name]; 1345 classHint.res_name = (char *)rs[Rs_name];
1484 classHint.res_class = (char *)RESCLASS; 1346 classHint.res_class = (char *)RESCLASS;
1485 1347
1486 wmHint.flags = InputHint | StateHint | WindowGroupHint; 1348 wmHint.flags = InputHint | StateHint | WindowGroupHint;
1487 wmHint.input = True; 1349 wmHint.input = True;
1488 wmHint.initial_state = option (Opt_iconic) ? IconicState : NormalState; 1350 wmHint.initial_state = option (Opt_iconic) ? IconicState
1351 : option (Opt_dockapp) ? WithdrawnState
1352 : NormalState;
1489 wmHint.window_group = top; 1353 wmHint.window_group = top;
1490 1354
1491 XmbSetWMProperties (dpy, top, NULL, NULL, (char **)argv, argc, 1355 XmbSetWMProperties (dpy, top, NULL, NULL, (char **)argv, argc,
1492 &szHint, &wmHint, &classHint); 1356 &szHint, &wmHint, &classHint);
1493#if ENABLE_EWMH 1357#if ENABLE_EWMH
1495 * set up icon hint 1359 * set up icon hint
1496 * rs [Rs_iconfile] is path to icon 1360 * rs [Rs_iconfile] is path to icon
1497 */ 1361 */
1498 1362
1499 if (rs [Rs_iconfile]) 1363 if (rs [Rs_iconfile])
1500 {
1501 set_icon (rs [Rs_iconfile]); 1364 set_icon (rs [Rs_iconfile]);
1502 }
1503#endif 1365#endif
1504 1366
1505#if ENABLE_FRILLS 1367#if ENABLE_FRILLS
1506 if (mwmhints.flags) 1368 if (mwmhints.flags)
1507 XChangeProperty (dpy, top, xa[XA_MOTIF_WM_HINTS], xa[XA_MOTIF_WM_HINTS], 32, 1369 XChangeProperty (dpy, top, xa[XA_MOTIF_WM_HINTS], xa[XA_MOTIF_WM_HINTS], 32,
1583 if (rs[Rs_fade]) 1445 if (rs[Rs_fade])
1584 pix_colors = pix_colors_unfocused; 1446 pix_colors = pix_colors_unfocused;
1585#endif 1447#endif
1586 1448
1587 pointer_unblank (); 1449 pointer_unblank ();
1588 scr_recolour (); 1450 scr_recolor ();
1589} 1451}
1590 1452
1591/*----------------------------------------------------------------------*/ 1453/*----------------------------------------------------------------------*/
1592/* 1454/*
1593 * Run the command in a subprocess and return a file descriptor for the 1455 * Run the command in a subprocess and return a file descriptor for the

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines