void rxvt_init () { ptytty::init (); if (!ev_default_loop (0)) rxvt_fatal ("cannot initialise libev (bad value for LIBEV_METHODS?)\n"); rxvt_environ = environ; signal (SIGHUP, SIG_IGN); signal (SIGPIPE, SIG_IGN); sig_handlers.sw_term.start (SIGTERM); ev_unref (); sig_handlers.sw_int.start (SIGINT); ev_unref (); /* need to trap SIGURG for SVR4 (Unixware) rlogin */ /* signal (SIGURG, SIG_DFL); */ old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); // TODO: handle this with exceptions and tolerate the memory loss XSetIOErrorHandler (rxvt_xioerror_handler); XrmInitialize (); }
int scrollBar_t::show_xterm (int update) { int xsb = 0; int sbwidth = width - 1; if ((init & SB_STYLE_XTERM) == 0) { XGCValues gcvalue; init |= SB_STYLE_XTERM; gcvalue.stipple = XCreateBitmapFromData (term->dpy, win, (char *)x_stp_bits, x_stp_width, x_stp_height); if (!gcvalue.stipple) rxvt_fatal ("can't create bitmap\n"); gcvalue.fill_style = FillOpaqueStippled; gcvalue.foreground = term->pix_colors_focused[Color_scroll]; gcvalue.background = term->pix_colors_focused[Color_bg]; xscrollbarGC = XCreateGC (term->dpy, win, GCForeground | GCBackground | GCFillStyle | GCStipple, &gcvalue); gcvalue.foreground = term->pix_colors_focused[Color_border]; ShadowGC = XCreateGC (term->dpy, win, GCForeground, &gcvalue); } xsb = term->option (Opt_scrollBar_right) ? 1 : 0; if (update) { if (last_top < top) XClearArea (term->dpy, win, xsb, last_top, sbwidth, (top - last_top), False); if (bot < last_bot) XClearArea (term->dpy, win, xsb, bot, sbwidth, (last_bot - bot), False); } else XClearWindow (term->dpy, win); /* scrollbar slider */ XFillRectangle (term->dpy, win, xscrollbarGC, xsb + 1, top, sbwidth - 2, bot - top); XDrawLine (term->dpy, win, ShadowGC, xsb ? 0 : sbwidth, beg, xsb ? 0 : sbwidth, end); return 1; }
// a wrapper for register_keymap, // so that outside codes don't have to know so much details. // // the string 'trans' is copied to an internal managed buffer, // so the caller can free memory of 'trans' at any time. void keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const char *trans) { keysym_t *key = new keysym_t; wchar_t *wc = rxvt_mbstowcs (trans); char *translation = rxvt_wcstoutf8 (wc); free (wc); if (key && translation) { key->keysym = keysym; key->state = state; key->range = 1; key->str = translation; key->type = keysym_t::STRING; if (strncmp (translation, "list", 4) == 0 && translation [4]) { char *middle = strchr (translation + 5, translation [4]); char *suffix = strrchr (translation + 5, translation [4]); if (suffix && middle && suffix > middle + 1) { key->type = keysym_t::LIST; key->range = suffix - middle - 1; memmove (translation, translation + 4, strlen (translation + 4) + 1); } else rxvt_warn ("cannot parse list-type keysym '%s', treating as normal keysym.\n", translation); } else if (strncmp (translation, "builtin:", 8) == 0) key->type = keysym_t::BUILTIN; register_keymap (key); } else { delete key; free ((void *)translation); rxvt_fatal ("out of memory, aborting.\n"); } }
/* * window size/position calculations for XSizeHint and other storage. * if width/height are non-zero then override calculated width/height */ void rxvt_term::window_calc (unsigned int newwidth, unsigned int newheight) { short recalc_x, recalc_y; int x, y, flags; unsigned int w, h; unsigned int max_width, max_height; szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; szHint.win_gravity = NorthWestGravity; /* szHint.min_aspect.x = szHint.min_aspect.y = 1; */ recalc_x = recalc_y = 0; flags = 0; if (!parsed_geometry) { parsed_geometry = 1; if (rs[Rs_geometry]) flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h); if (flags & WidthValue) { if (!w) rxvt_fatal ("illegal window geometry (width and height must be non-zero), aborting.\n"); ncol = clamp (w, 1, std::numeric_limits<int16_t>::max ()); szHint.flags |= USSize; } if (flags & HeightValue) { if (!h) rxvt_fatal ("illegal window geometry (width and height must be non-zero), aborting.\n"); nrow = clamp (h, 1, std::numeric_limits<int16_t>::max ()); szHint.flags |= USSize; } if (flags & XValue) { szHint.x = x; szHint.flags |= USPosition; if (flags & XNegative) { recalc_x = 1; szHint.win_gravity = NorthEastGravity; } } if (flags & YValue) { szHint.y = y; szHint.flags |= USPosition; if (flags & YNegative) { recalc_y = 1; if (szHint.win_gravity == NorthEastGravity) szHint.win_gravity = SouthEastGravity; else szHint.win_gravity = SouthWestGravity; } } } /* TODO: BOUNDS */ width = ncol * fwidth; height = nrow * fheight; max_width = MAX_COLS * fwidth; max_height = MAX_ROWS * fheight; szHint.base_width = szHint.base_height = 2 * int_bwidth; window_vt_x = window_vt_y = int_bwidth; if (scrollBar.state) { int sb_w = scrollBar.total_width (); szHint.base_width += sb_w; if (!option (Opt_scrollBar_right)) window_vt_x += sb_w; } szHint.width_inc = fwidth; szHint.height_inc = fheight; szHint.min_width = szHint.base_width + szHint.width_inc; szHint.min_height = szHint.base_height + szHint.height_inc; if (newwidth && newwidth - szHint.base_width < max_width) { szHint.width = newwidth; width = newwidth - szHint.base_width; } else { min_it (width, max_width); szHint.width = szHint.base_width + width; } if (newheight && newheight - szHint.base_height < max_height) { szHint.height = newheight; height = newheight - szHint.base_height; } else { min_it (height, max_height); szHint.height = szHint.base_height + height; } 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; nrow = height / fheight; }