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.345 by sf-exg, Tue Oct 13 08:10:43 2015 UTC

11 * Copyright (c) 1997 mj olesen <olesen@me.queensu.ca> 11 * Copyright (c) 1997 mj olesen <olesen@me.queensu.ca>
12 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> 12 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de>
13 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> 13 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com>
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 * Copyright (c) 2015 Emanuele Giaquinta <e.giaquinta@glauco.it>
16 * 17 *
17 * This program is free software; you can redistribute it and/or modify 18 * 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 19 * 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 20 * the Free Software Foundation; either version 3 of the License, or
20 * (at your option) any later version. 21 * (at your option) any later version.
21 * 22 *
22 * This program is distributed in the hope that it will be useful, 23 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of 24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42 43
43#include <signal.h> 44#include <signal.h>
44 45
45#include <fcntl.h> 46#include <fcntl.h>
46 47
48#ifdef HAVE_XMU
49# include <X11/Xmu/CurUtil.h>
50#endif
51
47#ifdef HAVE_XSETLOCALE 52#ifdef HAVE_XSETLOCALE
48# define X_LOCALE 53# define X_LOCALE
49# include <X11/Xlocale.h> 54# include <X11/Xlocale.h>
50#else 55#else
51# include <locale.h> 56# include <locale.h>
76#include <netinet/in.h> 81#include <netinet/in.h>
77#include <arpa/inet.h> 82#include <arpa/inet.h>
78#include <net/if.h> 83#include <net/if.h>
79#include <net/if_arp.h> 84#include <net/if_arp.h>
80 85
81static char * 86static char * ecb_cold
82rxvt_network_display (const char *display) 87rxvt_network_display (const char *display)
83{ 88{
84 char buffer[1024], *rval = NULL; 89 char buffer[1024], *rval = NULL;
85 struct ifconf ifc; 90 struct ifconf ifc;
86 struct ifreq *ifr; 91 struct ifreq *ifr;
519#endif 524#endif
520 COLOR_SCROLLBAR, 525 COLOR_SCROLLBAR,
521#ifdef RXVT_SCROLLBAR 526#ifdef RXVT_SCROLLBAR
522 COLOR_SCROLLTROUGH, 527 COLOR_SCROLLTROUGH,
523#endif 528#endif
524#if ENABLE_TRANSPARENCY 529#if BG_IMAGE_FROM_ROOT
525 NULL, 530 NULL,
526#endif 531#endif
527#if OFF_FOCUS_FADING 532#if OFF_FOCUS_FADING
528 "rgb:00/00/00", 533 "rgb:00/00/00",
529#endif 534#endif
588 xa = display->xa; 593 xa = display->xa;
589 594
590 set (display); 595 set (display);
591 extract_resources (); 596 extract_resources ();
592 597
593#if XFT 598#if ENABLE_FRILLS
594 if (rs[Rs_depth]) 599 if (rs[Rs_visual])
595 select_visual (strtol (rs[Rs_depth], 0, 0)); 600 select_visual (strtol (rs[Rs_visual], 0, 0));
601 else if (rs[Rs_depth])
602 select_depth (strtol (rs[Rs_depth], 0, 0));
596#endif 603#endif
597 604
598 for (int i = NUM_RESOURCES; i--; ) 605 for (int i = NUM_RESOURCES; i--; )
599 if (rs [i] == resval_undef) 606 if (rs [i] == resval_undef)
600 rs [i] = 0; 607 rs [i] = 0;
657 if (rs[Rs_pointerBlankDelay] && (i = atoi (rs[Rs_pointerBlankDelay])) >= 0) 664 if (rs[Rs_pointerBlankDelay] && (i = atoi (rs[Rs_pointerBlankDelay])) >= 0)
658 pointerBlankDelay = i; 665 pointerBlankDelay = i;
659 else 666 else
660 pointerBlankDelay = 2; 667 pointerBlankDelay = 2;
661#endif 668#endif
669
670 if (rs[Rs_multiClickTime] && (i = atoi (rs[Rs_multiClickTime])) >= 0)
671 multiClickTime = i;
672 else
673 multiClickTime = 500;
674
675 cursor_type = option (Opt_cursorUnderline) ? 1 : 0;
662 676
663 /* no point having a scrollbar without having any scrollback! */ 677 /* no point having a scrollbar without having any scrollback! */
664 if (!saveLines) 678 if (!saveLines)
665 set_option (Opt_scrollBar, 0); 679 set_option (Opt_scrollBar, 0);
666 680
739 envv->push_back (0); 753 envv->push_back (0);
740 754
741 this->argv = argv; 755 this->argv = argv;
742 this->envv = envv; 756 this->envv = envv;
743 757
758 env = new char *[this->envv->size ()];
759 for (int i = 0; i < this->envv->size (); i++)
760 env[i] = this->envv->at (i);
761
744 init2 (argv->size () - 1, argv->begin ()); 762 init2 (argv->size () - 1, argv->begin ());
745} 763}
746 764
747void 765void
748rxvt_term::init (int argc, const char *const *argv, const char *const *envv) 766rxvt_term::init (int argc, const char *const *argv, const char *const *envv)
766void 784void
767rxvt_term::init2 (int argc, const char *const *argv) 785rxvt_term::init2 (int argc, const char *const *argv)
768{ 786{
769 SET_R (this); 787 SET_R (this);
770 set_locale (""); 788 set_locale ("");
771 set_environ (envv); // a few things in X do not call setlocale :( 789 set_environ (env); // a few things in X do not call setlocale :(
772 790
773 init_vars (); 791 init_vars ();
774 792
775 const char **cmd_argv = init_resources (argc, argv); 793 const char **cmd_argv = init_resources (argc, argv);
776 794
791 if (option (Opt_scrollBar)) 809 if (option (Opt_scrollBar))
792 scrollBar.state = SB_STATE_IDLE; /* set existence for size calculations */ 810 scrollBar.state = SB_STATE_IDLE; /* set existence for size calculations */
793 811
794 pty = ptytty::create (); 812 pty = ptytty::create ();
795 813
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); 814 create_windows (argc, argv);
807 815
808 init_xlocale (); 816 init_xlocale ();
809 817
810 scr_poweron (); // initialize screen 818 scr_poweron (); // initialize screen
813 XSynchronize (dpy, True); 821 XSynchronize (dpy, True);
814#endif 822#endif
815 823
816 if (option (Opt_scrollBar)) 824 if (option (Opt_scrollBar))
817 scrollBar.resize (); /* create and map scrollbar */ 825 scrollBar.resize (); /* create and map scrollbar */
826
818#ifdef HAVE_BG_PIXMAP 827#ifdef HAVE_BG_PIXMAP
819 {
820 bg_init (); 828 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 829#endif
850 830
851#if ENABLE_PERL 831#if ENABLE_PERL
852 rootwin_ev.start (display, display->root); 832 rootwin_ev.start (display, display->root);
853#endif 833#endif
981 961
982/*----------------------------------------------------------------------*/ 962/*----------------------------------------------------------------------*/
983void 963void
984rxvt_term::set_locale (const char *locale) 964rxvt_term::set_locale (const char *locale)
985{ 965{
986 set_environ (envv); 966 set_environ (env);
987 967
988 free (this->locale); 968 free (this->locale);
989 this->locale = setlocale (LC_CTYPE, locale); 969 this->locale = setlocale (LC_CTYPE, locale);
990 970
991 if (!this->locale) 971 if (!this->locale)
1019} 999}
1020 1000
1021void 1001void
1022rxvt_term::init_xlocale () 1002rxvt_term::init_xlocale ()
1023{ 1003{
1024 set_environ (envv); 1004 set_environ (env);
1025 1005
1026#ifdef USE_XIM 1006#if USE_XIM
1027 if (!locale) 1007 if (!locale)
1028 rxvt_warn ("setting locale failed, continuing without locale support.\n"); 1008 rxvt_warn ("setting locale failed, continuing without locale support.\n");
1029 else 1009 else
1030 { 1010 {
1031 set_string_property (xa[XA_WM_LOCALE_NAME], locale); 1011 set_string_property (xa[XA_WM_LOCALE_NAME], locale);
1081 run_command (argv); 1061 run_command (argv);
1082} 1062}
1083 1063
1084/*----------------------------------------------------------------------*/ 1064/*----------------------------------------------------------------------*/
1085void 1065void
1086rxvt_term::get_colours () 1066rxvt_term::get_colors ()
1087{ 1067{
1088 int i; 1068 int i;
1089 1069
1090#ifdef OFF_FOCUS_FADING 1070#ifdef OFF_FOCUS_FADING
1091 pix_colors = pix_colors_focused; 1071 pix_colors = pix_colors_focused;
1092#endif 1072#endif
1093 1073
1094 for (i = 0; i < (depth <= 2 ? 2 : NRS_COLORS); i++) 1074 for (i = 0; i < NRS_COLORS; i++)
1095 {
1096 const char *name = rs[Rs_color + i]; 1075 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)) 1076 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 1077
1150 /* 1078 /*
1151 * get scrollBar shadow colors 1079 * get scrollBar shadow colors
1152 * 1080 *
1153 * The calculations of topShadow/bottomShadow values are adapted 1081 * The calculations of topShadow/bottomShadow values are adapted
1154 * from the fvwm window manager. 1082 * from the fvwm window manager.
1155 */ 1083 */
1156#ifdef RXVT_SCROLLBAR 1084#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]); 1085 pix_colors [Color_scroll].fade (this, 50, pix_colors [Color_bottomShadow]);
1167 1086
1168 rgba cscroll; 1087 rgba cscroll;
1169 pix_colors [Color_scroll].get (cscroll); 1088 pix_colors [Color_scroll].get (cscroll);
1170 1089
1171 /* topShadowColor */ 1090 /* topShadowColor */
1172 if (!pix_colors[Color_topShadow].set (this, 1091 if (!pix_colors[Color_topShadow].set (this,
1173 rgba ( 1092 rgba (
1174 min ((int)rgba::MAX_CC, max (cscroll.r / 5, cscroll.r) * 7 / 5), 1093 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), 1094 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), 1095 min ((int)rgba::MAX_CC, max (cscroll.b / 5, cscroll.b) * 7 / 5),
1177 cscroll.a) 1096 cscroll.a)
1178 )) 1097 ))
1179 alias_color (Color_topShadow, Color_White); 1098 alias_color (Color_topShadow, Color_White);
1180 }
1181#endif 1099#endif
1182 1100
1183#ifdef OFF_FOCUS_FADING 1101#ifdef OFF_FOCUS_FADING
1184 for (i = 0; i < (depth <= 2 ? 2 : NRS_COLORS); i++) 1102 for (i = 0; i < NRS_COLORS; i++)
1185 update_fade_color (i); 1103 update_fade_color (i, true);
1186#endif 1104#endif
1187} 1105}
1188 1106
1189/*----------------------------------------------------------------------*/ 1107/*----------------------------------------------------------------------*/
1190/* color aliases, fg/bg bright-bold */ 1108/* color aliases, fg/bg bright-bold */
1239 for (j = map->max_keypermod; j--; k++) 1157 for (j = map->max_keypermod; j--; k++)
1240 { 1158 {
1241 if (kc[k] == 0) 1159 if (kc[k] == 0)
1242 break; 1160 break;
1243 1161
1244 switch (XKeycodeToKeysym (dpy, kc[k], 0)) 1162 switch (rxvt_XKeycodeToKeysym (dpy, kc[k], 0))
1245 { 1163 {
1246 case XK_Num_Lock: 1164 case XK_Num_Lock:
1247 ModNumLockMask = modmasks[i - 1]; 1165 ModNumLockMask = modmasks[i - 1];
1248 continue; 1166 continue;
1249 1167
1294} 1212}
1295 1213
1296void 1214void
1297rxvt_term::set_icon (const char *file) 1215rxvt_term::set_icon (const char *file)
1298{ 1216{
1299#ifdef HAVE_AFTERIMAGE 1217#if HAVE_PIXBUF && ENABLE_EWMH
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
1351 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (file, NULL); 1218 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (file, NULL);
1352 if (!pixbuf) 1219 if (!pixbuf)
1353 { 1220 {
1354 rxvt_warn ("Loading image icon failed, continuing without.\n"); 1221 rxvt_warn ("Loading image icon failed, continuing without.\n");
1355 return; 1222 return;
1420 Window top, parent; 1287 Window top, parent;
1421 1288
1422 dLocal (Display *, dpy); 1289 dLocal (Display *, dpy);
1423 1290
1424 /* grab colors before netscape does */ 1291 /* grab colors before netscape does */
1425 get_colours (); 1292 get_colors ();
1426 1293
1427 if (!set_fonts ()) 1294 if (!set_fonts ())
1428 rxvt_fatal ("unable to load base fontset, please specify a valid one using -fn, aborting.\n"); 1295 rxvt_fatal ("unable to load base fontset, please specify a valid one using -fn, aborting.\n");
1429 1296
1430 parent = display->root; 1297 parent = display->root;
1483 classHint.res_name = (char *)rs[Rs_name]; 1350 classHint.res_name = (char *)rs[Rs_name];
1484 classHint.res_class = (char *)RESCLASS; 1351 classHint.res_class = (char *)RESCLASS;
1485 1352
1486 wmHint.flags = InputHint | StateHint | WindowGroupHint; 1353 wmHint.flags = InputHint | StateHint | WindowGroupHint;
1487 wmHint.input = True; 1354 wmHint.input = True;
1488 wmHint.initial_state = option (Opt_iconic) ? IconicState : NormalState; 1355 wmHint.initial_state = option (Opt_iconic) ? IconicState
1356 : option (Opt_dockapp) ? WithdrawnState
1357 : NormalState;
1489 wmHint.window_group = top; 1358 wmHint.window_group = top;
1490 1359
1491 XmbSetWMProperties (dpy, top, NULL, NULL, (char **)argv, argc, 1360 XmbSetWMProperties (dpy, top, NULL, NULL, (char **)argv, argc,
1492 &szHint, &wmHint, &classHint); 1361 &szHint, &wmHint, &classHint);
1493#if ENABLE_EWMH 1362#if ENABLE_EWMH
1495 * set up icon hint 1364 * set up icon hint
1496 * rs [Rs_iconfile] is path to icon 1365 * rs [Rs_iconfile] is path to icon
1497 */ 1366 */
1498 1367
1499 if (rs [Rs_iconfile]) 1368 if (rs [Rs_iconfile])
1500 {
1501 set_icon (rs [Rs_iconfile]); 1369 set_icon (rs [Rs_iconfile]);
1502 }
1503#endif 1370#endif
1504 1371
1505#if ENABLE_FRILLS 1372#if ENABLE_FRILLS
1506 if (mwmhints.flags) 1373 if (mwmhints.flags)
1507 XChangeProperty (dpy, top, xa[XA_MOTIF_WM_HINTS], xa[XA_MOTIF_WM_HINTS], 32, 1374 XChangeProperty (dpy, top, xa[XA_MOTIF_WM_HINTS], xa[XA_MOTIF_WM_HINTS], 32,
1541 | ExposureMask | StructureNotifyMask); 1408 | ExposureMask | StructureNotifyMask);
1542 1409
1543 termwin_ev.start (display, top); 1410 termwin_ev.start (display, top);
1544 1411
1545 /* vt cursor: Black-on-White is standard, but this is more popular */ 1412 /* vt cursor: Black-on-White is standard, but this is more popular */
1413 unsigned int shape = XC_xterm;
1414
1415#ifdef HAVE_XMU
1416 if (rs[Rs_pointerShape])
1417 {
1418 int stmp = XmuCursorNameToIndex (rs[Rs_pointerShape]);
1419 if (stmp >= 0)
1420 shape = stmp;
1421 }
1422#endif
1423
1546 TermWin_cursor = XCreateFontCursor (dpy, XC_xterm); 1424 TermWin_cursor = XCreateFontCursor (dpy, shape);
1547 1425
1548 /* the vt window */ 1426 /* the vt window */
1549 vt = XCreateSimpleWindow (dpy, top, 1427 vt = XCreateSimpleWindow (dpy, top,
1550 window_vt_x, window_vt_y, 1428 window_vt_x, window_vt_y,
1551 vt_width, vt_height, 1429 vt_width, vt_height,
1583 if (rs[Rs_fade]) 1461 if (rs[Rs_fade])
1584 pix_colors = pix_colors_unfocused; 1462 pix_colors = pix_colors_unfocused;
1585#endif 1463#endif
1586 1464
1587 pointer_unblank (); 1465 pointer_unblank ();
1588 scr_recolour (); 1466 scr_recolor ();
1589} 1467}
1590 1468
1591/*----------------------------------------------------------------------*/ 1469/*----------------------------------------------------------------------*/
1592/* 1470/*
1593 * Run the command in a subprocess and return a file descriptor for the 1471 * Run the command in a subprocess and return a file descriptor for the

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines