--- rxvt-unicode/src/main.C 2008/01/19 00:24:53 1.300 +++ rxvt-unicode/src/main.C 2010/04/03 16:30:39 1.326 @@ -13,7 +13,7 @@ * Copyright (c) 1997,1998 Oezguer Kesim * Copyright (c) 1998-2001 Geoff Wing * - extensive modifications - * Copyright (c) 2003-2007 Marc Lehmann + * Copyright (c) 2003-2008 Marc Lehmann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -103,7 +103,7 @@ cc = (*this)[cc->c1]; } - // check to see wether this combination already exists otherwise + // check to see whether this combination already exists otherwise for (cc = v.end (); cc-- > v.begin (); ) { if (cc->c1 == c1 && cc->c2 == c2) @@ -174,9 +174,7 @@ #if ENABLE_TRANSPARENCY || ENABLE_PERL rootwin_ev.set (this), #endif -#ifdef HAVE_SCROLLBARS scrollbar_ev.set (this), -#endif #ifdef USE_XIM im_ev.set (this), #endif @@ -231,38 +229,22 @@ #ifdef HAVE_BG_PIXMAP bgPixmap.destroy (); #endif +#ifdef HAVE_AFTERIMAGE + if (asv) + destroy_asvisual (asv, 0); + if (asimman) + destroy_image_manager (asimman, 0); +#endif if (display) { selection_clear (); + selection_clear (true); #ifdef USE_XIM im_destroy (); #endif -#ifdef XTERM_SCROLLBAR - if (xscrollbarGC) XFreeGC (dpy, xscrollbarGC); - if (ShadowGC) XFreeGC (dpy, ShadowGC); -#endif -#ifdef PLAIN_SCROLLBAR - if (pscrollbarGC) XFreeGC (dpy, pscrollbarGC); -#endif -#ifdef NEXT_SCROLLBAR - if (blackGC) XFreeGC (dpy, blackGC); - if (whiteGC) XFreeGC (dpy, whiteGC); - if (grayGC) XFreeGC (dpy, grayGC); - if (darkGC) XFreeGC (dpy, darkGC); - if (stippleGC) XFreeGC (dpy, stippleGC); - if (dimple) XFreePixmap (dpy, dimple); - if (upArrow) XFreePixmap (dpy, upArrow); - if (downArrow) XFreePixmap (dpy, downArrow); - if (upArrowHi) XFreePixmap (dpy, upArrowHi); - if (downArrowHi) XFreePixmap (dpy, downArrowHi); -#endif -#ifdef RXVT_SCROLLBAR - if (topShadowGC) XFreeGC (dpy, topShadowGC); - if (botShadowGC) XFreeGC (dpy, botShadowGC); - if (scrollbarGC) XFreeGC (dpy, scrollbarGC); -#endif + scrollBar.destroy (); if (gc) XFreeGC (dpy, gc); delete drawable; @@ -292,6 +274,7 @@ free (allocated [i]); free (selection.text); + free (selection.clip_text); // TODO: manage env vars in child only(!) free (env_display); free (env_term); @@ -339,9 +322,7 @@ #if USE_XIM im_ev.stop (display); #endif -#if HAVE_SCROLLBARS scrollbar_ev.stop (display); -#endif #if ENABLE_TRANSPARENCY || ENABLE_PERL rootwin_ev.stop (display); #endif @@ -411,33 +392,33 @@ XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ); rxvt_warn ("(which is %s)\n", buffer); if (event->request_code >= 128) { - XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d", - mesg, BUFSIZ); + XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d", + mesg, BUFSIZ); rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->minor_code); } if ((event->error_code == BadWindow) || - (event->error_code == BadPixmap) || - (event->error_code == BadCursor) || - (event->error_code == BadFont) || - (event->error_code == BadDrawable) || - (event->error_code == BadColor) || - (event->error_code == BadGC) || - (event->error_code == BadIDChoice) || - (event->error_code == BadValue) || - (event->error_code == BadAtom)) { - if (event->error_code == BadValue) - XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x", - mesg, BUFSIZ); - else if (event->error_code == BadAtom) - XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x", - mesg, BUFSIZ); - else - XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x", - mesg, BUFSIZ); - rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->resourceid); + (event->error_code == BadPixmap) || + (event->error_code == BadCursor) || + (event->error_code == BadFont) || + (event->error_code == BadDrawable) || + (event->error_code == BadColor) || + (event->error_code == BadGC) || + (event->error_code == BadIDChoice) || + (event->error_code == BadValue) || + (event->error_code == BadAtom)) { + if (event->error_code == BadValue) + XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x", + mesg, BUFSIZ); + else if (event->error_code == BadAtom) + XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x", + mesg, BUFSIZ); + else + XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x", + mesg, BUFSIZ); + rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->resourceid); } XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d", - mesg, BUFSIZ); + mesg, BUFSIZ); rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->serial); } #endif @@ -470,125 +451,6 @@ _exit (EXIT_FAILURE); } -/*----------------------------------------------------------------------*/ -void -rxvt_term::init (int argc, const char *const *argv, stringvec *envv) -{ - this->envv = envv; - - SET_R (this); - set_locale (""); - set_environ (envv); // few things in X do not call setlocale :( - - init_vars (); - - init_secondary (); - - const char **cmd_argv = init_resources (argc, argv); - -#ifdef KEYSYM_RESOURCE - keyboard->register_done (); -#endif - -#ifdef HAVE_SCROLLBARS - if (option (Opt_scrollBar)) - scrollBar.setIdle (); /* set existence for size calculations */ -#endif - - pty = ptytty::create (); - - create_windows (argc, argv); - - init_xlocale (); - - scr_reset (); // initialize screen - -#if 0 - XSynchronize (dpy, True); -#endif - -#ifdef HAVE_SCROLLBARS - if (option (Opt_scrollBar)) - resize_scrollbar (); /* create and map scrollbar */ -#endif -#ifdef HAVE_BG_PIXMAP - { - bgPixmap.set_target (this); - bgPixmap.invalidate (); - -#ifdef ENABLE_TRANSPARENCY - if (option (Opt_transparent)) - { - 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]); - - if (rs [Rs_shade]) - bgPixmap.set_shade (rs [Rs_shade]); - - bgPixmap.set_root_pixmap (); - XSelectInput (dpy, display->root, PropertyChangeMask); - rootwin_ev.start (display, display->root); - } -#endif - -#ifdef BG_IMAGE_FROM_FILE - if (rs[Rs_backgroundPixmap]) - { - const char *p = rs[Rs_backgroundPixmap]; - - if ((p = strchr (p, ';')) != 0) - { - p++; - bgPixmap.set_geometry (p); - } - else - bgPixmap.set_defaultGeometry (); - - if (bgPixmap.set_file (rs[Rs_backgroundPixmap])) - if (!bgPixmap.window_position_sensitive ()) - update_background (); - } -#endif - } -#endif - -#if ENABLE_PERL - rootwin_ev.start (display, display->root); -#endif - - set_colorfgbg (); - - init_command (cmd_argv); - - free (cmd_argv); - - if (pty->pty >= 0) - pty_ev.start (pty->pty, ev::READ); - - HOOK_INVOKE ((this, HOOK_START, DT_END)); - -#if ENABLE_XEMBED - if (rs[Rs_embed]) - { - long info[2] = { 0, XEMBED_MAPPED }; - - XChangeProperty (dpy, parent[0], xa[XA_XEMBED_INFO], xa[XA_XEMBED_INFO], - 32, PropModeReplace, (unsigned char *)&info, 2); - } -#endif - - XMapWindow (dpy, vt); - XMapWindow (dpy, parent[0]); - - refresh_check (); -} - static struct sig_handlers { ev::sig sw_term, sw_int; @@ -650,7 +512,7 @@ rxvt_term::window_calc (unsigned int newwidth, unsigned int newheight) { short recalc_x, recalc_y; - int x, y, sb_w, flags; + int x, y, flags; unsigned int w, h; unsigned int max_width, max_height; @@ -670,13 +532,19 @@ if (flags & WidthValue) { - ncol = clamp (w, 0, std::numeric_limits::max ()); + if (!w) + rxvt_fatal ("illegal window geometry (width and height must be non-zero), aborting.\n"); + + ncol = clamp (w, 1, std::numeric_limits::max ()); szHint.flags |= USSize; } if (flags & HeightValue) { - nrow = clamp (h, 0, std::numeric_limits::max ()); + if (!h) + rxvt_fatal ("illegal window geometry (width and height must be non-zero), aborting.\n"); + + nrow = clamp (h, 1, std::numeric_limits::max ()); szHint.flags |= USSize; } @@ -717,12 +585,11 @@ szHint.base_width = szHint.base_height = 2 * int_bwidth; - sb_w = 0; window_vt_x = window_vt_y = int_bwidth; if (scrollBar.state) { - sb_w = scrollbar_TotalWidth (); + int sb_w = scrollBar.total_width (); szHint.base_width += sb_w; if (!option (Opt_scrollBar_right)) @@ -756,16 +623,13 @@ szHint.height = szHint.base_height + height; } - if (scrollBar.state && option (Opt_scrollBar_right)) - window_sb_x = szHint.width - sb_w; - if (recalc_x) szHint.x += DisplayWidth (dpy, display->screen) - szHint.width - 2 * ext_bwidth; if (recalc_y) szHint.y += DisplayHeight (dpy, display->screen) - szHint.height - 2 * ext_bwidth; - ncol = width / fwidth; + ncol = width / fwidth; nrow = height / fheight; } @@ -786,7 +650,7 @@ ws.ws_row = nrow; ws.ws_xpixel = width; ws.ws_ypixel = height; - (void)ioctl (pty->pty, TIOCSWINSZ, &ws); + ioctl (pty->pty, TIOCSWINSZ, &ws); #if 0 // TIOCSWINSZ is supposed to do this automatically and correctly @@ -826,8 +690,9 @@ delete fontset[0]; fontset[0] = fs; - prop = (*fs)[1]->properties (); + prop = (*fs)[rxvt_fontset::firstFont]->properties (); prop.height += lineSpace; + prop.width += letterSpace; fs->set_prop (prop, false); @@ -926,7 +791,6 @@ { #ifdef XTERM_COLOR_CHANGE rxvt_color xcol; - int i; if (color == NULL || *color == '\0') return; @@ -938,7 +802,7 @@ /* handle color aliases */ if (isdigit (*color)) { - i = atoi (color); + int i = atoi (color); if (i >= 8 && i <= 15) { @@ -1052,8 +916,15 @@ window_calc (newwidth, newheight); - if (!HOOK_INVOKE ((this, HOOK_RESIZE_ALL_WINDOWS, DT_INT, newwidth, DT_INT, newheight, DT_END))) - XSetWMNormalHints (dpy, parent[0], &szHint); + bool set_hint = !HOOK_INVOKE ((this, HOOK_RESIZE_ALL_WINDOWS, DT_INT, newwidth, DT_INT, newheight, DT_END)); + + // to avoid races between us and the wm, we clear the incremental size hints around the xresizewindow + if (set_hint) + { + szHint.flags &= ~(PBaseSize | PResizeInc); + XSetWMNormalHints (dpy, parent[0], &szHint); + szHint.flags |= PBaseSize | PResizeInc; + } if (!ignoreparent) { @@ -1103,17 +974,15 @@ #endif } + if (set_hint) + XSetWMNormalHints (dpy, parent[0], &szHint); + fix_screen = ncol != prev_ncol || nrow != prev_nrow; if (fix_screen || newwidth != old_width || newheight != old_height) { if (scrollBar.state) - { - XMoveResizeWindow (dpy, scrollBar.win, - window_sb_x, 0, - scrollbar_TotalWidth (), szHint.height); - resize_scrollbar (); - } + scrollBar.resize (); XMoveResizeWindow (dpy, vt, window_vt_x, window_vt_y, @@ -1123,16 +992,11 @@ if (bgPixmap.window_size_sensitive ()) update_background (); #endif - - scr_clear (); } if (fix_screen || old_height == 0) scr_reset (); - // TODO, with nvidia-8178, resizes kill the alpha channel, report if not fixed in newer version - //scr_touch (false); - #ifdef HAVE_BG_PIXMAP // TODO: this don't seem to have any effect - do we still need it ? If so - in which case exactly ? // if (bgPixmap.pixmap) @@ -1213,18 +1077,17 @@ bool rxvt_term::IMisRunning () { - char *p; Atom atom; Window win; char server[IMBUFSIZ]; /* get current locale modifier */ - if ((p = XSetLocaleModifiers (NULL)) != NULL) + if (char *p = XSetLocaleModifiers (0)) { strcpy (server, "@server="); - strncat (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */ + strncat (server, p + 4, IMBUFSIZ - 9); /* skip "@im=" */ - if ((p = strchr (server + 1, '@')) != NULL) /* first one only */ + if (p = strchr (server + 1, '@')) /* first one only */ *p = '\0'; atom = XInternAtom (dpy, server, False); @@ -1301,7 +1164,7 @@ if (text) { - void *str; + wchar_t *str; if (!text->encoding_is_wchar && text->string.multi_byte) { @@ -1309,14 +1172,14 @@ if (term->rs[Rs_imLocale]) SET_LOCALE (term->rs[Rs_imLocale]); - str = rxvt_temp_buf ((text->length + 1) * sizeof (wchar_t)); - mbstowcs ((wchar_t *)str, text->string.multi_byte, text->length + 1); + str = rxvt_temp_buf (text->length + 1); + mbstowcs (str, text->string.multi_byte, text->length + 1); if (term->rs[Rs_imLocale]) SET_LOCALE (term->locale); } else - str = (void *)text->string.wide_char; + str = text->string.wide_char; HOOK_INVOKE ((term, HOOK_XIM_PREEDIT_DRAW, DT_INT, call_data->caret,