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.273 by sf-exg, Mon Jul 26 22:07:38 2010 UTC vs.
Revision 1.304 by sf-exg, Tue Dec 6 10:27:15 2011 UTC

10 * Copyright (c) 1996 Chuck Blake <cblake@BBN.COM> 10 * Copyright (c) 1996 Chuck Blake <cblake@BBN.COM>
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 <pcg@goof.com> 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 2 of the License, or
20 * (at your option) any later version. 20 * (at your option) any later version.
55 55
56#ifdef HAVE_NL_LANGINFO 56#ifdef HAVE_NL_LANGINFO
57# include <langinfo.h> 57# include <langinfo.h>
58#endif 58#endif
59 59
60#ifdef HAVE_STARTUP_NOTIFICATION
61# define SN_API_NOT_YET_FROZEN
62# include <libsn/sn-launchee.h>
63#endif
64
60#ifdef DISPLAY_IS_IP 65#ifdef DISPLAY_IS_IP
61/* On Solaris link with -lsocket and -lnsl */ 66/* On Solaris link with -lsocket and -lnsl */
62#include <sys/types.h> 67#include <sys/types.h>
63#include <sys/socket.h> 68#include <sys/socket.h>
64 69
143 148
144 return rval; 149 return rval;
145} 150}
146#endif 151#endif
147 152
148const char *const def_colorName[] = 153static const char *const def_colorName[] =
149 { 154 {
150 COLOR_FOREGROUND, 155 COLOR_FOREGROUND,
151 COLOR_BACKGROUND, 156 COLOR_BACKGROUND,
152 /* low-intensity colors */ 157 /* low-intensity colors */
153 "rgb:00/00/00", // 0: black (Black) 158 "rgb:00/00/00", // 0: black (Black)
563/*----------------------------------------------------------------------*/ 568/*----------------------------------------------------------------------*/
564const char ** 569const char **
565rxvt_term::init_resources (int argc, const char *const *argv) 570rxvt_term::init_resources (int argc, const char *const *argv)
566{ 571{
567 int i, r_argc; 572 int i, r_argc;
568 const char **cmd_argv, **r_argv; 573 const char **cmd_argv;
569 574
570 /* 575 /*
571 * Look for -e option. Find => split and make cmd_argv[] of command args 576 * Look for -e option. Find => split and make cmd_argv[] of command args
572 */ 577 */
573 for (r_argc = 0; r_argc < argc; r_argc++) 578 for (r_argc = 0; r_argc < argc; r_argc++)
586 cmd_argv[i] = (const char *)argv[i + r_argc + 1]; 591 cmd_argv[i] = (const char *)argv[i + r_argc + 1];
587 592
588 cmd_argv[i] = NULL; 593 cmd_argv[i] = NULL;
589 } 594 }
590 595
591 r_argv = (const char **)rxvt_malloc (sizeof (char *) * (r_argc + 1));
592
593 for (i = 0; i < r_argc; i++)
594 r_argv[i] = (const char *)argv[i];
595
596 r_argv[i] = NULL;
597
598 rs[Rs_name] = rxvt_basename (argv[0]); 596 rs[Rs_name] = rxvt_basename (argv[0]);
599 597
600 /* 598 /*
601 * Open display, get options/resources and create the window 599 * Open display, get options/resources and create the window
602 */ 600 */
603 601
604 if ((rs[Rs_display_name] = getenv ("DISPLAY")) == NULL) 602 if ((rs[Rs_display_name] = getenv ("DISPLAY")) == NULL)
605 rs[Rs_display_name] = ":0"; 603 rs[Rs_display_name] = ":0";
606 604
607 get_options (r_argc, r_argv); 605 get_options (r_argc, argv);
608 606
609 if (!(display = displays.get (rs[Rs_display_name]))) 607 if (!(display = displays.get (rs[Rs_display_name])))
610 {
611 free (r_argv);
612 rxvt_fatal ("can't open display %s, aborting.\n", rs[Rs_display_name]); 608 rxvt_fatal ("can't open display %s, aborting.\n", rs[Rs_display_name]);
613 }
614 609
615 // using a local pointer decreases code size a lot 610 // using a local pointer decreases code size a lot
616 xa = display->xa; 611 xa = display->xa;
617 612
618 set (display); 613 set (display);
621#if XFT 616#if XFT
622 if (rs[Rs_depth]) 617 if (rs[Rs_depth])
623 select_visual (strtol (rs[Rs_depth], 0, 0)); 618 select_visual (strtol (rs[Rs_depth], 0, 0));
624#endif 619#endif
625 620
626 free (r_argv);
627
628 for (int i = NUM_RESOURCES; i--; ) 621 for (int i = NUM_RESOURCES; i--; )
629 if (rs [i] == resval_undef) 622 if (rs [i] == resval_undef)
630 rs [i] = 0; 623 rs [i] = 0;
631 624
632#ifdef HAVE_AFTERIMAGE
633 set_application_name ((char *)rs[Rs_name]);
634 set_output_threshold (OUTPUT_LEVEL_WARNING);
635#endif
636
637#if ENABLE_PERL 625#if ENABLE_PERL
638 if (!rs[Rs_perl_ext_1]) 626 if (!rs[Rs_perl_ext_1])
639 rs[Rs_perl_ext_1] = "default"; 627 rs[Rs_perl_ext_1] = "default";
640 628
641 if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) 629 if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1])
644 { 632 {
645 rxvt_perl.init (this); 633 rxvt_perl.init (this);
646 HOOK_INVOKE ((this, HOOK_INIT, DT_END)); 634 HOOK_INVOKE ((this, HOOK_INIT, DT_END));
647 } 635 }
648#endif 636#endif
637
638 // must be called after initialising the perl interpreter as it
639 // may invoke the `on_register_command' hook
640 extract_keysym_resources ();
649 641
650 /* 642 /*
651 * set any defaults not already set 643 * set any defaults not already set
652 */ 644 */
653 if (cmd_argv && cmd_argv[0]) 645 if (cmd_argv && cmd_argv[0])
789 if (chdir (path)) 781 if (chdir (path))
790 rxvt_fatal ("unable to change into specified shell working directory, aborting.\n"); 782 rxvt_fatal ("unable to change into specified shell working directory, aborting.\n");
791 } 783 }
792 784
793 if (option (Opt_scrollBar)) 785 if (option (Opt_scrollBar))
794 scrollBar.state = STATE_IDLE; /* set existence for size calculations */ 786 scrollBar.state = SB_STATE_IDLE; /* set existence for size calculations */
795 787
796 pty = ptytty::create (); 788 pty = ptytty::create ();
789
790#ifdef HAVE_AFTERIMAGE
791 set_application_name ((char *)rs[Rs_name]);
792 set_output_threshold (OUTPUT_LEVEL_WARNING);
793#endif
794
795 // must be called before create_windows, because the latter may call set_icon
796#ifdef HAVE_PIXBUF
797 g_type_init ();
798#endif
797 799
798 create_windows (argc, argv); 800 create_windows (argc, argv);
799 801
800 init_xlocale (); 802 init_xlocale ();
801 803
807 809
808 if (option (Opt_scrollBar)) 810 if (option (Opt_scrollBar))
809 scrollBar.resize (); /* create and map scrollbar */ 811 scrollBar.resize (); /* create and map scrollbar */
810#ifdef HAVE_BG_PIXMAP 812#ifdef HAVE_BG_PIXMAP
811 { 813 {
812 bgPixmap.set_target (this); 814 bg_init ();
813 bgPixmap.invalidate ();
814 815
815#ifdef ENABLE_TRANSPARENCY 816#ifdef ENABLE_TRANSPARENCY
816 if (option (Opt_transparent)) 817 if (option (Opt_transparent))
817 { 818 {
818 bgPixmap.set_transparent (); 819 bg_set_transparent ();
819 820
820#ifdef HAVE_AFTERIMAGE
821 if (rs [Rs_blurradius]) 821 if (rs [Rs_blurradius])
822 bgPixmap.set_blur_radius (rs [Rs_blurradius]); 822 bg_set_blur (rs [Rs_blurradius]);
823#endif 823
824 if (ISSET_PIXCOLOR (Color_tint)) 824 if (ISSET_PIXCOLOR (Color_tint))
825 bgPixmap.set_tint (pix_colors_focused [Color_tint]); 825 bg_set_tint (pix_colors_focused [Color_tint]);
826 826
827 if (rs [Rs_shade]) 827 if (rs [Rs_shade])
828 bgPixmap.set_shade (rs [Rs_shade]); 828 bg_set_shade (rs [Rs_shade]);
829 829
830 bgPixmap.set_root_pixmap (); 830 bg_set_root_pixmap ();
831 XSelectInput (dpy, display->root, PropertyChangeMask); 831 XSelectInput (dpy, display->root, PropertyChangeMask);
832 rootwin_ev.start (display, display->root); 832 rootwin_ev.start (display, display->root);
833 } 833 }
834#endif 834#endif
835 835
836#ifdef BG_IMAGE_FROM_FILE 836#ifdef BG_IMAGE_FROM_FILE
837 if (rs[Rs_backgroundPixmap]) 837 if (rs[Rs_backgroundPixmap])
838 { 838 {
839 const char *p = rs[Rs_backgroundPixmap];
840
841 if ((p = strchr (p, ';')) != 0)
842 {
843 p++;
844 bgPixmap.set_geometry (p);
845 }
846 else
847 bgPixmap.set_defaultGeometry ();
848
849 if (bgPixmap.set_file (rs[Rs_backgroundPixmap])) 839 if (bg_set_file (rs[Rs_backgroundPixmap]))
850 if (!bgPixmap.window_position_sensitive ()) 840 if (!bg_window_position_sensitive ())
851 update_background (); 841 update_background ();
852 } 842 }
853#endif 843#endif
854 } 844 }
855#endif 845#endif
872#if ENABLE_XEMBED 862#if ENABLE_XEMBED
873 if (rs[Rs_embed]) 863 if (rs[Rs_embed])
874 { 864 {
875 long info[2] = { 0, XEMBED_MAPPED }; 865 long info[2] = { 0, XEMBED_MAPPED };
876 866
877 XChangeProperty (dpy, parent[0], xa[XA_XEMBED_INFO], xa[XA_XEMBED_INFO], 867 XChangeProperty (dpy, parent, xa[XA_XEMBED_INFO], xa[XA_XEMBED_INFO],
878 32, PropModeReplace, (unsigned char *)&info, 2); 868 32, PropModeReplace, (unsigned char *)&info, 2);
879 } 869 }
880#endif 870#endif
881 871
872#if HAVE_STARTUP_NOTIFICATION
873 SnDisplay *snDisplay;
874 SnLauncheeContext *snContext;
875
876 snDisplay = sn_display_new (dpy, NULL, NULL);
877 snContext = sn_launchee_context_new_from_environment (snDisplay, DefaultScreen (dpy));
878
879 /* Tell the window manager that this window is part of the startup context */
880 if (snContext)
881 sn_launchee_context_setup_window (snContext, parent);
882#endif
883
882 XMapWindow (dpy, vt); 884 XMapWindow (dpy, vt);
883 XMapWindow (dpy, parent[0]); 885 XMapWindow (dpy, parent);
886
887#if HAVE_STARTUP_NOTIFICATION
888 if (snContext)
889 {
890 /* Mark the startup process as complete */
891 sn_launchee_context_complete (snContext);
892
893 sn_launchee_context_unref (snContext);
894 }
895
896 sn_display_unref (snDisplay);
897#endif
884 898
885 refresh_check (); 899 refresh_check ();
886} 900}
887 901
888/*----------------------------------------------------------------------*/ 902/*----------------------------------------------------------------------*/
889void 903void
890rxvt_term::init_env () 904rxvt_term::init_env ()
891{ 905{
892 int i;
893 char *val; 906 char *val;
894 907
895#ifdef DISPLAY_IS_IP 908#ifdef DISPLAY_IS_IP
896 /* Fixup display_name for export over pty to any interested terminal 909 /* Fixup display_name for export over pty to any interested terminal
897 * clients via "ESC[7n" (e.g. shells). Note we use the pure IP number 910 * clients via "ESC[7n" (e.g. shells). Note we use the pure IP number
911 val = XDisplayString (dpy); 924 val = XDisplayString (dpy);
912 925
913 if (rs[Rs_display_name] == NULL) 926 if (rs[Rs_display_name] == NULL)
914 rs[Rs_display_name] = val; /* use broken `:0' value */ 927 rs[Rs_display_name] = val; /* use broken `:0' value */
915 928
916 i = strlen (val);
917 env_display = (char *)rxvt_malloc (i + 9); 929 env_display = (char *)rxvt_malloc (strlen (val) + 9);
918 930
919 sprintf (env_display, "DISPLAY=%s", val); 931 sprintf (env_display, "DISPLAY=%s", val);
920 932
921 sprintf (env_windowid, "WINDOWID=%lu", (unsigned long)parent[0]); 933 sprintf (env_windowid, "WINDOWID=%lu", (unsigned long)parent);
922 934
923 /* add entries to the environment: 935 /* add entries to the environment:
924 * @ DISPLAY: in case we started with -display 936 * @ DISPLAY: in case we started with -display
925 * @ WINDOWID: X window id number of the window 937 * @ WINDOWID: X window id number of the window
926 * @ COLORTERM: terminal sub-name and also indicates its color 938 * @ COLORTERM: terminal sub-name and also indicates its color
1279 1291
1280 if (i) 1292 if (i)
1281 ModMetaMask = modmasks[i - 1]; 1293 ModMetaMask = modmasks[i - 1];
1282} 1294}
1283 1295
1296void
1297rxvt_term::set_icon (const char *file)
1298{
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
1351 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (file, NULL);
1352 if (!pixbuf)
1353 {
1354 rxvt_warn ("Loading image icon failed, continuing without.\n");
1355 return;
1356 }
1357
1358 unsigned int w = gdk_pixbuf_get_width (pixbuf);
1359 unsigned int h = gdk_pixbuf_get_height (pixbuf);
1360
1361 if (!IN_RANGE_INC (w, 1, 16383) || !IN_RANGE_INC (h, 1, 16383))
1362 {
1363 rxvt_warn ("Icon image too big, continuing without.\n");
1364 g_object_unref (pixbuf);
1365 return;
1366 }
1367
1368 if (long *buffer = (long *)malloc ((2 + w * h) * sizeof (long)))
1369 {
1370 int rowstride = gdk_pixbuf_get_rowstride (pixbuf);
1371 unsigned char *row = gdk_pixbuf_get_pixels (pixbuf);
1372 int channels = gdk_pixbuf_get_n_channels (pixbuf);
1373
1374 buffer [0] = w;
1375 buffer [1] = h;
1376 for (int i = 0; i < h; i++)
1377 {
1378 for (int j = 0; j < w; j++)
1379 {
1380 unsigned char *pixel = row + j * channels;
1381 long value;
1382
1383 if (channels == 4)
1384 value = pixel[3];
1385 else
1386 value = (unsigned char)0x00ff;
1387
1388 value = (value << 8) + pixel[0];
1389 value = (value << 8) + pixel[1];
1390 value = (value << 8) + pixel[2];
1391 buffer[(i * w + j) + 2] = value;
1392 }
1393
1394 row += rowstride;
1395 }
1396
1397 XChangeProperty (dpy, parent, xa[XA_NET_WM_ICON], XA_CARDINAL, 32,
1398 PropModeReplace, (const unsigned char *) buffer, 2 + w * h);
1399 free (buffer);
1400 }
1401 else
1402 rxvt_warn ("Memory allocation for icon hint failed, continuing without.\n");
1403
1404 g_object_unref (pixbuf);
1405#endif
1406}
1407
1284/*----------------------------------------------------------------------*/ 1408/*----------------------------------------------------------------------*/
1285/* rxvt_Create_Windows () - Open and map the window */ 1409/* Open and map the window */
1286void 1410void
1287rxvt_term::create_windows (int argc, const char *const *argv) 1411rxvt_term::create_windows (int argc, const char *const *argv)
1288{ 1412{
1289 XClassHint classHint; 1413 XClassHint classHint;
1290 XWMHints wmHint; 1414 XWMHints wmHint;
1336 } 1460 }
1337#endif 1461#endif
1338 1462
1339 window_calc (0, 0); 1463 window_calc (0, 0);
1340 1464
1341 /* sub-window placement & size in rxvt_resize_subwindows () */ 1465 /* sub-window placement & size in rxvt_term::resize_all_windows () */
1342 attributes.background_pixel = pix_colors_focused [Color_border]; 1466 attributes.background_pixel = pix_colors_focused [Color_border];
1343 attributes.border_pixel = pix_colors_focused [Color_border]; 1467 attributes.border_pixel = pix_colors_focused [Color_border];
1344 attributes.colormap = cmap; 1468 attributes.colormap = cmap;
1345 1469
1346 top = XCreateWindow (dpy, parent, 1470 top = XCreateWindow (dpy, parent,
1349 ext_bwidth, 1473 ext_bwidth,
1350 depth, InputOutput, visual, 1474 depth, InputOutput, visual,
1351 CWColormap | CWBackPixel | CWBorderPixel | CWOverrideRedirect, 1475 CWColormap | CWBackPixel | CWBorderPixel | CWOverrideRedirect,
1352 &attributes); 1476 &attributes);
1353 1477
1354 this->parent[0] = top; 1478 this->parent = top;
1355 1479
1356 old_width = szHint.width; 1480 old_width = szHint.width;
1357 old_height = szHint.height; 1481 old_height = szHint.height;
1358 1482
1359 set_title (rs [Rs_title]); 1483 set_title (rs [Rs_title]);
1368 wmHint.window_group = top; 1492 wmHint.window_group = top;
1369 1493
1370 XmbSetWMProperties (dpy, top, NULL, NULL, (char **)argv, argc, 1494 XmbSetWMProperties (dpy, top, NULL, NULL, (char **)argv, argc,
1371 &szHint, &wmHint, &classHint); 1495 &szHint, &wmHint, &classHint);
1372#if ENABLE_EWMH 1496#if ENABLE_EWMH
1373# ifdef HAVE_AFTERIMAGE
1374 /* 1497 /*
1375 * set up icon hint 1498 * set up icon hint
1376 * rs [Rs_iconfile] is path to icon, asv has been created in init_resources 1499 * rs [Rs_iconfile] is path to icon
1377 */ 1500 */
1378 1501
1379 if (rs [Rs_iconfile]) 1502 if (rs [Rs_iconfile])
1380 { 1503 {
1381 init_asv (); 1504 set_icon (rs [Rs_iconfile]);
1382
1383 ASImage *im = file2ASImage (rs [Rs_iconfile], 0xFFFFFFFF, SCREEN_GAMMA, 0, NULL);
1384 if (asv && im)
1385 {
1386 int w = im->width;
1387 int h = im->height;
1388 long *buffer = (long *)malloc ((2 + w * h) * sizeof (long));
1389 ASImage *result = scale_asimage (asv, im,
1390 w, h, ASA_ARGB32,
1391 100, ASIMAGE_QUALITY_DEFAULT);
1392 destroy_asimage (&im);
1393
1394 if (buffer && result)
1395 {
1396 ARGB32 *asbuf = result->alt.argb32;
1397 buffer [0] = w;
1398 buffer [1] = h;
1399
1400 for (unsigned int i = 0; i < w * h; ++i)
1401 buffer [i + 2] = asbuf [i];
1402
1403 destroy_asimage (&result);
1404 XChangeProperty (dpy, top, xa[XA_NET_WM_ICON], XA_CARDINAL, 32,
1405 PropModeReplace, (const unsigned char *) buffer, 2 + w * h);
1406 free (buffer);
1407 }
1408 else
1409 {
1410 if (!buffer)
1411 rxvt_warn ("Memory allocation for icon hint failed, continuing without.\n");
1412
1413 if (!result)
1414 rxvt_warn ("Icon image transformation to ARGB failed, continuing without.\n");
1415 }
1416 }
1417 else
1418 rxvt_warn ("Loading image icon failed, continuing without.\n");
1419 } 1505 }
1420# endif
1421#endif 1506#endif
1422 1507
1423#if ENABLE_FRILLS 1508#if ENABLE_FRILLS
1424 if (mwmhints.flags) 1509 if (mwmhints.flags)
1425 XChangeProperty (dpy, top, xa[XA_MOTIF_WM_HINTS], xa[XA_MOTIF_WM_HINTS], 32, 1510 XChangeProperty (dpy, top, xa[XA_MOTIF_WM_HINTS], xa[XA_MOTIF_WM_HINTS], 32,
1431#if ENABLE_EWMH 1516#if ENABLE_EWMH
1432 xa[XA_NET_WM_PING], 1517 xa[XA_NET_WM_PING],
1433#endif 1518#endif
1434 }; 1519 };
1435 1520
1436 XSetWMProtocols (dpy, top, protocols, sizeof (protocols) / sizeof (protocols[0])); 1521 XSetWMProtocols (dpy, top, protocols, ecb_array_length (protocols));
1437 1522
1438#if ENABLE_FRILLS 1523#if ENABLE_FRILLS
1439 if (rs[Rs_transient_for]) 1524 if (rs[Rs_transient_for])
1440 XSetTransientForHint (dpy, top, (Window)strtol (rs[Rs_transient_for], 0, 0)); 1525 XSetTransientForHint (dpy, top, (Window)strtol (rs[Rs_transient_for], 0, 0));
1441#endif 1526#endif
1502 pix_colors = pix_colors_unfocused; 1587 pix_colors = pix_colors_unfocused;
1503#endif 1588#endif
1504 1589
1505 pointer_unblank (); 1590 pointer_unblank ();
1506 scr_recolour (); 1591 scr_recolour ();
1507}
1508
1509/* ------------------------------------------------------------------------- *
1510 * GET TTY CURRENT STATE *
1511 * ------------------------------------------------------------------------- */
1512static void
1513rxvt_get_ttymode (struct termios *tio)
1514{
1515 /*
1516 * standard System V termios interface
1517 */
1518 // does not work as stdin is not a tty
1519 // if (tcgetattr (STDIN_FILENO, tio) < 0)
1520 if (1)
1521 {
1522 // return error - use system defaults,
1523 // where possible, and zero elsewhere
1524 memset (tio, 0, sizeof (struct termios));
1525 if (VDISABLE)
1526 for (int i = 0; i < NCCS; i++)
1527 tio->c_cc[i] = VDISABLE;
1528
1529 tio->c_cc[VINTR] = CINTR;
1530 tio->c_cc[VQUIT] = CQUIT;
1531 tio->c_cc[VERASE] = CERASE;
1532#ifdef VERASE2
1533 tio->c_cc[VERASE2] = CERASE2;
1534#endif
1535 tio->c_cc[VKILL] = CKILL;
1536 tio->c_cc[VSTART] = CSTART;
1537 tio->c_cc[VSTOP] = CSTOP;
1538 tio->c_cc[VSUSP] = CSUSP;
1539# ifdef VDSUSP
1540 tio->c_cc[VDSUSP] = CDSUSP;
1541# endif
1542# ifdef VREPRINT
1543 tio->c_cc[VREPRINT] = CRPRNT;
1544# endif
1545# ifdef VDISCRD
1546 tio->c_cc[VDISCRD] = CFLUSH;
1547# endif
1548# ifdef VWERSE
1549 tio->c_cc[VWERSE] = CWERASE;
1550# endif
1551# ifdef VLNEXT
1552 tio->c_cc[VLNEXT] = CLNEXT;
1553# endif
1554 }
1555
1556 tio->c_cc[VEOF] = CEOF;
1557# if VMIN != VEOF
1558 tio->c_cc[VMIN] = 1;
1559# endif
1560# if VTIME != VEOL
1561 tio->c_cc[VTIME] = 0;
1562# endif
1563
1564 /* input modes */
1565 tio->c_iflag = (BRKINT | IGNPAR | ICRNL
1566# ifdef IMAXBEL
1567 | IMAXBEL
1568# endif
1569 | IXON);
1570
1571 /* output modes */
1572 tio->c_oflag = (OPOST | ONLCR);
1573
1574 /* control modes */
1575 tio->c_cflag = (CS8 | CREAD);
1576
1577 /* line discipline modes */
1578 tio->c_lflag = (ISIG | ICANON | IEXTEN | ECHO
1579# if defined (ECHOCTL) && defined (ECHOKE)
1580 | ECHOCTL | ECHOKE
1581# endif
1582 | ECHOE | ECHOK);
1583
1584 /*
1585 * Debugging
1586 */
1587#ifdef DEBUG_TTYMODE
1588 /* c_iflag bits */
1589 fprintf (stderr, "Input flags\n");
1590
1591 /* cpp token stringize doesn't work on all machines <sigh> */
1592# define FOO(flag,name) \
1593 if ((tio->c_iflag) & flag) \
1594 fprintf (stderr, "%s ", name)
1595
1596 /* c_iflag bits */
1597 FOO (IGNBRK, "IGNBRK");
1598 FOO (BRKINT, "BRKINT");
1599 FOO (IGNPAR, "IGNPAR");
1600 FOO (PARMRK, "PARMRK");
1601 FOO (INPCK, "INPCK");
1602 FOO (ISTRIP, "ISTRIP");
1603 FOO (INLCR, "INLCR");
1604 FOO (IGNCR, "IGNCR");
1605 FOO (ICRNL, "ICRNL");
1606 FOO (IXON, "IXON");
1607 FOO (IXOFF, "IXOFF");
1608# ifdef IUCLC
1609 FOO (IUCLC, "IUCLC");
1610# endif
1611# ifdef IXANY
1612 FOO (IXANY, "IXANY");
1613# endif
1614# ifdef IMAXBEL
1615 FOO (IMAXBEL, "IMAXBEL");
1616# endif
1617
1618 fprintf (stderr, "\n");
1619
1620# undef FOO
1621# define FOO(entry, name) \
1622 fprintf (stderr, "%-8s = %#04o\n", name, tio->c_cc [entry])
1623
1624 FOO (VINTR, "VINTR");
1625 FOO (VQUIT, "VQUIT");
1626 FOO (VERASE, "VERASE");
1627 FOO (VKILL, "VKILL");
1628 FOO (VEOF, "VEOF");
1629 FOO (VEOL, "VEOL");
1630# ifdef VEOL2
1631 FOO (VEOL2, "VEOL2");
1632# endif
1633# ifdef VSWTC
1634 FOO (VSWTC, "VSWTC");
1635# endif
1636# ifdef VSWTCH
1637 FOO (VSWTCH, "VSWTCH");
1638# endif
1639 FOO (VSTART, "VSTART");
1640 FOO (VSTOP, "VSTOP");
1641 FOO (VSUSP, "VSUSP");
1642# ifdef VDSUSP
1643 FOO (VDSUSP, "VDSUSP");
1644# endif
1645# ifdef VREPRINT
1646 FOO (VREPRINT, "VREPRINT");
1647# endif
1648# ifdef VDISCRD
1649 FOO (VDISCRD, "VDISCRD");
1650# endif
1651# ifdef VWERSE
1652 FOO (VWERSE, "VWERSE");
1653# endif
1654# ifdef VLNEXT
1655 FOO (VLNEXT, "VLNEXT");
1656# endif
1657
1658 fprintf (stderr, "\n");
1659# undef FOO
1660#endif /* DEBUG_TTYMODE */
1661} 1592}
1662 1593
1663/*----------------------------------------------------------------------*/ 1594/*----------------------------------------------------------------------*/
1664/* 1595/*
1665 * Run the command in a subprocess and return a file descriptor for the 1596 * Run the command in a subprocess and return a file descriptor for the
1686 else 1617 else
1687#endif 1618#endif
1688 if (!pty->get ()) 1619 if (!pty->get ())
1689 rxvt_fatal ("can't initialize pseudo-tty, aborting.\n"); 1620 rxvt_fatal ("can't initialize pseudo-tty, aborting.\n");
1690 1621
1691 rxvt_get_ttymode (&tio); 1622 struct termios tio = def_tio;
1692 1623
1693#ifndef NO_BACKSPACE_KEY 1624#ifndef NO_BACKSPACE_KEY
1694 if (rs[Rs_backspace_key][0] && !rs[Rs_backspace_key][1]) 1625 if (rs[Rs_backspace_key][0] && !rs[Rs_backspace_key][1])
1695 tio.c_cc[VERASE] = rs[Rs_backspace_key][0]; 1626 tio.c_cc[VERASE] = rs[Rs_backspace_key][0];
1696 else if (strcmp (rs[Rs_backspace_key], "DEC") == 0) 1627 else if (strcmp (rs[Rs_backspace_key], "DEC") == 0)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines