--- rxvt-unicode/src/init.C 2010/06/15 13:34:52 1.270 +++ rxvt-unicode/src/init.C 2010/10/13 23:04:57 1.283 @@ -560,24 +560,6 @@ set_option (Opt_buffered); } -static void -init_secondary () -{ - int i; - - if ((i = open ("/dev/null", O_RDONLY)) < 0) - { - dup2 (STDERR_FILENO, STDIN_FILENO); - } - else if (i != STDIN_FILENO) - { - dup2 (i, STDIN_FILENO); - close (i); - } - - dup2 (STDERR_FILENO, STDOUT_FILENO); -} - /*----------------------------------------------------------------------*/ const char ** rxvt_term::init_resources (int argc, const char *const *argv) @@ -652,6 +634,11 @@ set_output_threshold (OUTPUT_LEVEL_WARNING); #endif +#ifdef HAVE_PIXBUF + g_type_init (); + gdk_pixbuf_xlib_init (dpy, display->screen); +#endif + #if ENABLE_PERL if (!rs[Rs_perl_ext_1]) rs[Rs_perl_ext_1] = "default"; @@ -792,8 +779,6 @@ init_vars (); - init_secondary (); - const char **cmd_argv = init_resources (argc, argv); #ifdef KEYSYM_RESOURCE @@ -837,10 +822,9 @@ { bgPixmap.set_transparent (); -#ifdef HAVE_AFTERIMAGE if (rs [Rs_blurradius]) bgPixmap.set_blur_radius (rs [Rs_blurradius]); -#endif + if (ISSET_PIXCOLOR (Color_tint)) bgPixmap.set_tint (pix_colors_focused [Color_tint]); @@ -1301,6 +1285,118 @@ ModMetaMask = modmasks[i - 1]; } +void +rxvt_term::set_icon (const char *file) +{ +#ifdef HAVE_AFTERIMAGE + init_asv (); + + ASImage *im = file2ASImage (file, 0xFFFFFFFF, SCREEN_GAMMA, 0, NULL); + if (!im) + { + rxvt_warn ("Loading image icon failed, continuing without.\n"); + return; + } + + unsigned int w = im->width; + unsigned int h = im->height; + + if (!IN_RANGE_INC (w, 1, 16383) || !IN_RANGE_INC (h, 1, 16383)) + { + rxvt_warn ("Icon image too big, continuing without.\n"); + destroy_asimage (&im); + return; + } + + ASImage *result = scale_asimage (asv, im, + w, h, ASA_ARGB32, + 100, ASIMAGE_QUALITY_DEFAULT); + destroy_asimage (&im); + + if (!result) + { + rxvt_warn ("Icon image transformation to ARGB failed, continuing without.\n"); + return; + } + + long *buffer = (long *)malloc ((2 + w * h) * sizeof (long)); + if (buffer) + { + ARGB32 *asbuf = result->alt.argb32; + buffer [0] = w; + buffer [1] = h; + + for (unsigned int i = 0; i < w * h; ++i) + buffer [i + 2] = asbuf [i]; + + XChangeProperty (dpy, parent[0], xa[XA_NET_WM_ICON], XA_CARDINAL, 32, + PropModeReplace, (const unsigned char *) buffer, 2 + w * h); + free (buffer); + } + else + rxvt_warn ("Memory allocation for icon hint failed, continuing without.\n"); + + destroy_asimage (&result); +#endif + +#ifdef HAVE_PIXBUF + GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (file, NULL); + if (!pixbuf) + { + rxvt_warn ("Loading image icon failed, continuing without.\n"); + return; + } + + unsigned int w = gdk_pixbuf_get_width (pixbuf); + unsigned int h = gdk_pixbuf_get_height (pixbuf); + + if (!IN_RANGE_INC (w, 1, 16383) || !IN_RANGE_INC (h, 1, 16383)) + { + rxvt_warn ("Icon image too big, continuing without.\n"); + g_object_unref (pixbuf); + return; + } + + if (long *buffer = (long *)malloc ((2 + w * h) * sizeof (long))) + { + int rowstride = gdk_pixbuf_get_rowstride (pixbuf); + unsigned char *row = gdk_pixbuf_get_pixels (pixbuf); + int channels = gdk_pixbuf_get_n_channels (pixbuf); + + buffer [0] = w; + buffer [1] = h; + for (int i = 0; i < h; i++) + { + for (int j = 0; j < w; j++) + { + unsigned char *pixel = row + j * channels; + long value; + + if (channels == 4) + value = pixel[3]; + else + value = (unsigned char)0x00ff; + + value = (value << 8) + pixel[0]; + value = (value << 8) + pixel[1]; + value = (value << 8) + pixel[2]; + buffer[(i * w + j) + 2] = value; + } + + row += rowstride; + } + + XChangeProperty (dpy, parent[0], xa[XA_NET_WM_ICON], XA_CARDINAL, 32, + PropModeReplace, (const unsigned char *) buffer, 2 + w * h); + free (buffer); + } + else + rxvt_warn ("Memory allocation for icon hint failed, continuing without.\n"); + + g_object_unref (pixbuf); +#endif +} + /*----------------------------------------------------------------------*/ /* rxvt_Create_Windows () - Open and map the window */ void @@ -1390,54 +1486,15 @@ XmbSetWMProperties (dpy, top, NULL, NULL, (char **)argv, argc, &szHint, &wmHint, &classHint); #if ENABLE_EWMH -# ifdef HAVE_AFTERIMAGE /* * set up icon hint - * rs [Rs_iconfile] is path to icon, asv has been created in init_resources + * rs [Rs_iconfile] is path to icon */ if (rs [Rs_iconfile]) { - init_asv (); - - ASImage *im = file2ASImage (rs [Rs_iconfile], 0xFFFFFFFF, SCREEN_GAMMA, 0, NULL); - if (asv && im) - { - int w = im->width; - int h = im->height; - long *buffer = (long *)malloc ((2 + w * h) * sizeof (long)); - ASImage *result = scale_asimage (asv, im, - w, h, ASA_ARGB32, - 100, ASIMAGE_QUALITY_DEFAULT); - destroy_asimage (&im); - - if (buffer && result) - { - ARGB32 *asbuf = result->alt.argb32; - buffer [0] = w; - buffer [1] = h; - - for (unsigned int i = 0; i < w * h; ++i) - buffer [i + 2] = asbuf [i]; - - destroy_asimage (&result); - XChangeProperty (dpy, top, xa[XA_NET_WM_ICON], XA_CARDINAL, 32, - PropModeReplace, (const unsigned char *) buffer, 2 + w * h); - free (buffer); - } - else - { - if (!buffer) - rxvt_warn ("Memory allocation for icon hint failed, continuing without.\n"); - - if (!result) - rxvt_warn ("Icon image transformation to ARGB failed, continuing without.\n"); - } - } - else - rxvt_warn ("Loading image icon failed, continuing without.\n"); + set_icon (rs [Rs_iconfile]); } -# endif #endif #if ENABLE_FRILLS @@ -1526,160 +1583,6 @@ scr_recolour (); } -/* ------------------------------------------------------------------------- * - * GET TTY CURRENT STATE * - * ------------------------------------------------------------------------- */ -void -rxvt_get_ttymode (struct termios *tio) -{ - /* - * standard System V termios interface - */ - // does not work as stdin is not a tty - // if (tcgetattr (STDIN_FILENO, tio) < 0) - if (1) - { - // return error - use system defaults, - // where possible, and zero elsewhere - memset (tio, 0, sizeof (struct termios)); - if (VDISABLE) - for (int i = 0; i < NCCS; i++) - tio->c_cc[i] = VDISABLE; - - tio->c_cc[VINTR] = CINTR; - tio->c_cc[VQUIT] = CQUIT; - tio->c_cc[VERASE] = CERASE; -#ifdef VERASE2 - tio->c_cc[VERASE2] = CERASE2; -#endif - tio->c_cc[VKILL] = CKILL; - tio->c_cc[VSTART] = CSTART; - tio->c_cc[VSTOP] = CSTOP; - tio->c_cc[VSUSP] = CSUSP; -# ifdef VDSUSP - tio->c_cc[VDSUSP] = CDSUSP; -# endif -# ifdef VREPRINT - tio->c_cc[VREPRINT] = CRPRNT; -# endif -# ifdef VDISCRD - tio->c_cc[VDISCRD] = CFLUSH; -# endif -# ifdef VWERSE - tio->c_cc[VWERSE] = CWERASE; -# endif -# ifdef VLNEXT - tio->c_cc[VLNEXT] = CLNEXT; -# endif - } - - tio->c_cc[VEOF] = CEOF; -# if VMIN != VEOF - tio->c_cc[VMIN] = 1; -# endif -# if VTIME != VEOL - tio->c_cc[VTIME] = 0; -# endif - - /* input modes */ - tio->c_iflag = (BRKINT | IGNPAR | ICRNL -# ifdef IMAXBEL - | IMAXBEL -# endif - | IXON); - - /* output modes */ - tio->c_oflag = (OPOST | ONLCR); - - /* control modes */ - tio->c_cflag = (CS8 | CREAD); - - /* line discipline modes */ - tio->c_lflag = (ISIG | ICANON | IEXTEN | ECHO -# if defined (ECHOCTL) && defined (ECHOKE) - | ECHOCTL | ECHOKE -# endif - | ECHOE | ECHOK); - - /* - * Debugging - */ -#ifdef DEBUG_TTYMODE - /* c_iflag bits */ - fprintf (stderr, "Input flags\n"); - - /* cpp token stringize doesn't work on all machines */ -# define FOO(flag,name) \ - if ((tio->c_iflag) & flag) \ - fprintf (stderr, "%s ", name) - - /* c_iflag bits */ - FOO (IGNBRK, "IGNBRK"); - FOO (BRKINT, "BRKINT"); - FOO (IGNPAR, "IGNPAR"); - FOO (PARMRK, "PARMRK"); - FOO (INPCK, "INPCK"); - FOO (ISTRIP, "ISTRIP"); - FOO (INLCR, "INLCR"); - FOO (IGNCR, "IGNCR"); - FOO (ICRNL, "ICRNL"); - FOO (IXON, "IXON"); - FOO (IXOFF, "IXOFF"); -# ifdef IUCLC - FOO (IUCLC, "IUCLC"); -# endif -# ifdef IXANY - FOO (IXANY, "IXANY"); -# endif -# ifdef IMAXBEL - FOO (IMAXBEL, "IMAXBEL"); -# endif - - fprintf (stderr, "\n"); - -# undef FOO -# define FOO(entry, name) \ - fprintf (stderr, "%-8s = %#04o\n", name, tio->c_cc [entry]) - - FOO (VINTR, "VINTR"); - FOO (VQUIT, "VQUIT"); - FOO (VERASE, "VERASE"); - FOO (VKILL, "VKILL"); - FOO (VEOF, "VEOF"); - FOO (VEOL, "VEOL"); -# ifdef VEOL2 - FOO (VEOL2, "VEOL2"); -# endif -# ifdef VSWTC - FOO (VSWTC, "VSWTC"); -# endif -# ifdef VSWTCH - FOO (VSWTCH, "VSWTCH"); -# endif - FOO (VSTART, "VSTART"); - FOO (VSTOP, "VSTOP"); - FOO (VSUSP, "VSUSP"); -# ifdef VDSUSP - FOO (VDSUSP, "VDSUSP"); -# endif -# ifdef VREPRINT - FOO (VREPRINT, "VREPRINT"); -# endif -# ifdef VDISCRD - FOO (VDISCRD, "VDISCRD"); -# endif -# ifdef VWERSE - FOO (VWERSE, "VWERSE"); -# endif -# ifdef VLNEXT - FOO (VLNEXT, "VLNEXT"); -# endif - - fprintf (stderr, "\n"); -# undef FOO -#endif /* DEBUG_TTYMODE */ -} - /*----------------------------------------------------------------------*/ /* * Run the command in a subprocess and return a file descriptor for the @@ -1708,7 +1611,7 @@ if (!pty->get ()) rxvt_fatal ("can't initialize pseudo-tty, aborting.\n"); - rxvt_get_ttymode (&tio); + struct termios tio = def_tio; #ifndef NO_BACKSPACE_KEY if (rs[Rs_backspace_key][0] && !rs[Rs_backspace_key][1]) @@ -1813,7 +1716,7 @@ signal (SIGHUP, SIG_DFL); signal (SIGPIPE, SIG_DFL); /* - * mimick login's behavior by disabling the job control signals + * mimic login's behavior by disabling the job control signals * a shell that wants them can turn them back on */ #ifdef SIGTSTP