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.322 by sf-exg, Thu May 17 10:18:32 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 // must be called before create_windows, because the latter may call set_icon
797#ifdef HAVE_PIXBUF
798 g_type_init ();
799#endif
800
801 create_windows (argc, argv); 814 create_windows (argc, argv);
802 815
803 init_xlocale (); 816 init_xlocale ();
804 817
805 scr_poweron (); // initialize screen 818 scr_poweron (); // initialize screen
808 XSynchronize (dpy, True); 821 XSynchronize (dpy, True);
809#endif 822#endif
810 823
811 if (option (Opt_scrollBar)) 824 if (option (Opt_scrollBar))
812 scrollBar.resize (); /* create and map scrollbar */ 825 scrollBar.resize (); /* create and map scrollbar */
826
813#ifdef HAVE_BG_PIXMAP 827#ifdef HAVE_BG_PIXMAP
814 {
815 bg_init (); 828 bg_init ();
816
817#ifdef ENABLE_TRANSPARENCY
818 if (option (Opt_transparent))
819 {
820 bg_set_transparent ();
821
822 if (rs [Rs_blurradius])
823 bg_set_blur (rs [Rs_blurradius]);
824
825 if (ISSET_PIXCOLOR (Color_tint))
826 bg_set_tint (pix_colors_focused [Color_tint]);
827
828 if (rs [Rs_shade])
829 bg_set_shade (rs [Rs_shade]);
830
831 bg_set_root_pixmap ();
832 XSelectInput (dpy, display->root, PropertyChangeMask);
833 rootwin_ev.start (display, display->root);
834 }
835#endif
836
837#ifdef BG_IMAGE_FROM_FILE
838 if (rs[Rs_backgroundPixmap])
839 if (bg_image.set_file (rs[Rs_backgroundPixmap]))
840 if (!bg_window_position_sensitive ())
841 update_background ();
842#endif
843 }
844#endif 829#endif
845 830
846#if ENABLE_PERL 831#if ENABLE_PERL
847 rootwin_ev.start (display, display->root); 832 rootwin_ev.start (display, display->root);
848#endif 833#endif
976 961
977/*----------------------------------------------------------------------*/ 962/*----------------------------------------------------------------------*/
978void 963void
979rxvt_term::set_locale (const char *locale) 964rxvt_term::set_locale (const char *locale)
980{ 965{
981 set_environ (envv); 966 set_environ (env);
982 967
983 free (this->locale); 968 free (this->locale);
984 this->locale = setlocale (LC_CTYPE, locale); 969 this->locale = setlocale (LC_CTYPE, locale);
985 970
986 if (!this->locale) 971 if (!this->locale)
1014} 999}
1015 1000
1016void 1001void
1017rxvt_term::init_xlocale () 1002rxvt_term::init_xlocale ()
1018{ 1003{
1019 set_environ (envv); 1004 set_environ (env);
1020 1005
1021#ifdef USE_XIM 1006#if USE_XIM
1022 if (!locale) 1007 if (!locale)
1023 rxvt_warn ("setting locale failed, continuing without locale support.\n"); 1008 rxvt_warn ("setting locale failed, continuing without locale support.\n");
1024 else 1009 else
1025 { 1010 {
1026 set_string_property (xa[XA_WM_LOCALE_NAME], locale); 1011 set_string_property (xa[XA_WM_LOCALE_NAME], locale);
1076 run_command (argv); 1061 run_command (argv);
1077} 1062}
1078 1063
1079/*----------------------------------------------------------------------*/ 1064/*----------------------------------------------------------------------*/
1080void 1065void
1081rxvt_term::get_colours () 1066rxvt_term::get_colors ()
1082{ 1067{
1083 int i; 1068 int i;
1084 1069
1085#ifdef OFF_FOCUS_FADING 1070#ifdef OFF_FOCUS_FADING
1086 pix_colors = pix_colors_focused; 1071 pix_colors = pix_colors_focused;
1087#endif 1072#endif
1088 1073
1089 for (i = 0; i < (depth <= 2 ? 2 : NRS_COLORS); i++) 1074 for (i = 0; i < NRS_COLORS; i++)
1090 {
1091 const char *name = rs[Rs_color + i]; 1075 if (const char *name = rs[Rs_color + i])
1092
1093 if (!name)
1094 continue;
1095
1096 rxvt_color xcol;
1097
1098 if (!set_color (xcol, name)) 1076 set_color (pix_colors [i], name);
1099 {
1100#ifndef XTERM_REVERSE_VIDEO
1101 if (i < 2 && option (Opt_reverseVideo))
1102 name = def_colorName [1 - i];
1103 else
1104#endif
1105 name = def_colorName [i];
1106
1107 if (!name)
1108 continue;
1109
1110 if (!set_color (xcol, name))
1111 {
1112 switch (i)
1113 {
1114 case Color_fg:
1115 case Color_bg:
1116 rxvt_warn ("unable to get foreground/background colour, continuing.\n");
1117 name = "";
1118 break;
1119#ifndef NO_CURSORCOLOR
1120 case Color_cursor2:
1121#endif
1122 case Color_pointer_fg:
1123 name = rs[Rs_color + Color_fg];
1124 xcol.set (this, name);
1125 break;
1126 default:
1127 name = rs[Rs_color + Color_bg];
1128 xcol.set (this, name);
1129 break;
1130 }
1131 }
1132 }
1133
1134 pix_colors[i] = xcol;
1135 rs[Rs_color + i] = name;
1136 }
1137
1138 if (depth <= 2)
1139 {
1140 if (!rs[Rs_color + Color_pointer_fg]) alias_color (Color_pointer_fg, Color_fg);
1141 if (!rs[Rs_color + Color_pointer_bg]) alias_color (Color_pointer_bg, Color_bg);
1142 if (!rs[Rs_color + Color_border] ) alias_color (Color_border, Color_fg);
1143 }
1144 1077
1145 /* 1078 /*
1146 * get scrollBar shadow colors 1079 * get scrollBar shadow colors
1147 * 1080 *
1148 * The calculations of topShadow/bottomShadow values are adapted 1081 * The calculations of topShadow/bottomShadow values are adapted
1149 * from the fvwm window manager. 1082 * from the fvwm window manager.
1150 */ 1083 */
1151#ifdef RXVT_SCROLLBAR 1084#ifdef RXVT_SCROLLBAR
1152 if (depth <= 2)
1153 {
1154 /* Monochrome */
1155 alias_color (Color_scroll, Color_fg);
1156 alias_color (Color_topShadow, Color_bg);
1157 alias_color (Color_bottomShadow, Color_bg);
1158 }
1159 else
1160 {
1161 pix_colors [Color_scroll].fade (this, 50, pix_colors [Color_bottomShadow]); 1085 pix_colors [Color_scroll].fade (this, 50, pix_colors [Color_bottomShadow]);
1162 1086
1163 rgba cscroll; 1087 rgba cscroll;
1164 pix_colors [Color_scroll].get (cscroll); 1088 pix_colors [Color_scroll].get (cscroll);
1165 1089
1166 /* topShadowColor */ 1090 /* topShadowColor */
1167 if (!pix_colors[Color_topShadow].set (this, 1091 if (!pix_colors[Color_topShadow].set (this,
1168 rgba ( 1092 rgba (
1169 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),
1170 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),
1171 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),
1172 cscroll.a) 1096 cscroll.a)
1173 )) 1097 ))
1174 alias_color (Color_topShadow, Color_White); 1098 alias_color (Color_topShadow, Color_White);
1175 }
1176#endif 1099#endif
1177 1100
1178#ifdef OFF_FOCUS_FADING 1101#ifdef OFF_FOCUS_FADING
1179 for (i = 0; i < (depth <= 2 ? 2 : NRS_COLORS); i++) 1102 for (i = 0; i < NRS_COLORS; i++)
1180 update_fade_color (i); 1103 update_fade_color (i, true);
1181#endif 1104#endif
1182} 1105}
1183 1106
1184/*----------------------------------------------------------------------*/ 1107/*----------------------------------------------------------------------*/
1185/* color aliases, fg/bg bright-bold */ 1108/* color aliases, fg/bg bright-bold */
1234 for (j = map->max_keypermod; j--; k++) 1157 for (j = map->max_keypermod; j--; k++)
1235 { 1158 {
1236 if (kc[k] == 0) 1159 if (kc[k] == 0)
1237 break; 1160 break;
1238 1161
1239 switch (XKeycodeToKeysym (dpy, kc[k], 0)) 1162 switch (rxvt_XKeycodeToKeysym (dpy, kc[k], 0))
1240 { 1163 {
1241 case XK_Num_Lock: 1164 case XK_Num_Lock:
1242 ModNumLockMask = modmasks[i - 1]; 1165 ModNumLockMask = modmasks[i - 1];
1243 continue; 1166 continue;
1244 1167
1289} 1212}
1290 1213
1291void 1214void
1292rxvt_term::set_icon (const char *file) 1215rxvt_term::set_icon (const char *file)
1293{ 1216{
1294#ifdef HAVE_PIXBUF 1217#if HAVE_PIXBUF && ENABLE_EWMH
1295 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (file, NULL); 1218 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (file, NULL);
1296 if (!pixbuf) 1219 if (!pixbuf)
1297 { 1220 {
1298 rxvt_warn ("Loading image icon failed, continuing without.\n"); 1221 rxvt_warn ("Loading image icon failed, continuing without.\n");
1299 return; 1222 return;
1364 Window top, parent; 1287 Window top, parent;
1365 1288
1366 dLocal (Display *, dpy); 1289 dLocal (Display *, dpy);
1367 1290
1368 /* grab colors before netscape does */ 1291 /* grab colors before netscape does */
1369 get_colours (); 1292 get_colors ();
1370 1293
1371 if (!set_fonts ()) 1294 if (!set_fonts ())
1372 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");
1373 1296
1374 parent = display->root; 1297 parent = display->root;
1427 classHint.res_name = (char *)rs[Rs_name]; 1350 classHint.res_name = (char *)rs[Rs_name];
1428 classHint.res_class = (char *)RESCLASS; 1351 classHint.res_class = (char *)RESCLASS;
1429 1352
1430 wmHint.flags = InputHint | StateHint | WindowGroupHint; 1353 wmHint.flags = InputHint | StateHint | WindowGroupHint;
1431 wmHint.input = True; 1354 wmHint.input = True;
1432 wmHint.initial_state = option (Opt_iconic) ? IconicState : NormalState; 1355 wmHint.initial_state = option (Opt_iconic) ? IconicState
1356 : option (Opt_dockapp) ? WithdrawnState
1357 : NormalState;
1433 wmHint.window_group = top; 1358 wmHint.window_group = top;
1434 1359
1435 XmbSetWMProperties (dpy, top, NULL, NULL, (char **)argv, argc, 1360 XmbSetWMProperties (dpy, top, NULL, NULL, (char **)argv, argc,
1436 &szHint, &wmHint, &classHint); 1361 &szHint, &wmHint, &classHint);
1437#if ENABLE_EWMH 1362#if ENABLE_EWMH
1439 * set up icon hint 1364 * set up icon hint
1440 * rs [Rs_iconfile] is path to icon 1365 * rs [Rs_iconfile] is path to icon
1441 */ 1366 */
1442 1367
1443 if (rs [Rs_iconfile]) 1368 if (rs [Rs_iconfile])
1444 {
1445 set_icon (rs [Rs_iconfile]); 1369 set_icon (rs [Rs_iconfile]);
1446 }
1447#endif 1370#endif
1448 1371
1449#if ENABLE_FRILLS 1372#if ENABLE_FRILLS
1450 if (mwmhints.flags) 1373 if (mwmhints.flags)
1451 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,
1485 | ExposureMask | StructureNotifyMask); 1408 | ExposureMask | StructureNotifyMask);
1486 1409
1487 termwin_ev.start (display, top); 1410 termwin_ev.start (display, top);
1488 1411
1489 /* 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
1490 TermWin_cursor = XCreateFontCursor (dpy, XC_xterm); 1424 TermWin_cursor = XCreateFontCursor (dpy, shape);
1491 1425
1492 /* the vt window */ 1426 /* the vt window */
1493 vt = XCreateSimpleWindow (dpy, top, 1427 vt = XCreateSimpleWindow (dpy, top,
1494 window_vt_x, window_vt_y, 1428 window_vt_x, window_vt_y,
1495 vt_width, vt_height, 1429 vt_width, vt_height,
1527 if (rs[Rs_fade]) 1461 if (rs[Rs_fade])
1528 pix_colors = pix_colors_unfocused; 1462 pix_colors = pix_colors_unfocused;
1529#endif 1463#endif
1530 1464
1531 pointer_unblank (); 1465 pointer_unblank ();
1532 scr_recolour (); 1466 scr_recolor ();
1533} 1467}
1534 1468
1535/*----------------------------------------------------------------------*/ 1469/*----------------------------------------------------------------------*/
1536/* 1470/*
1537 * 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