ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/main.C
(Generate patch)

Comparing rxvt-unicode/src/main.C (file contents):
Revision 1.123 by root, Mon Dec 20 16:44:31 2004 UTC vs.
Revision 1.139 by root, Wed Feb 16 21:37:10 2005 UTC

30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 *---------------------------------------------------------------------*/ 31 *---------------------------------------------------------------------*/
32 32
33#include "../config.h" /* NECESSARY */ 33#include "../config.h" /* NECESSARY */
34#include "rxvt.h" /* NECESSARY */ 34#include "rxvt.h" /* NECESSARY */
35#include "main.intpro" /* PROTOS for internal routines */
36 35
37#include <csignal> 36#include <csignal>
37#include <cstring>
38 38
39#ifdef TTY_GID_SUPPORT 39#ifdef TTY_GID_SUPPORT
40# include <grp.h> 40# include <grp.h>
41#endif 41#endif
42 42
43#ifdef HAVE_TERMIOS_H 43#ifdef HAVE_TERMIOS_H
44# include <termios.h> 44# include <termios.h>
45#endif 45#endif
46 46
47#include <cstring> 47#ifdef KEYSYM_RESOURCE
48# include "keyboard.h"
49#endif
48 50
49vector<rxvt_term *> rxvt_term::termlist; 51vector<rxvt_term *> rxvt_term::termlist;
50 52
51static char curlocale[128]; 53static char curlocale[128];
52 54
156#endif 158#endif
157#ifdef USE_XIM 159#ifdef USE_XIM
158 im_ev (this, &rxvt_term::im_cb), 160 im_ev (this, &rxvt_term::im_cb),
159#endif 161#endif
160 sw_term (this, &rxvt_term::sig_term), 162 sw_term (this, &rxvt_term::sig_term),
163 sw_int (this, &rxvt_term::sig_term),
161 sw_chld (this, &rxvt_term::sig_chld), 164 sw_chld (this, &rxvt_term::sig_chld),
162 termwin_ev (this, &rxvt_term::x_cb), 165 termwin_ev (this, &rxvt_term::x_cb),
163 vt_ev (this, &rxvt_term::x_cb), 166 vt_ev (this, &rxvt_term::x_cb),
164 check_ev (this, &rxvt_term::check_cb), 167 check_ev (this, &rxvt_term::check_cb),
165 flush_ev (this, &rxvt_term::flush_cb), 168 flush_ev (this, &rxvt_term::flush_cb),
168 incr_ev (this, &rxvt_term::incr_cb) 171 incr_ev (this, &rxvt_term::incr_cb)
169{ 172{
170 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; 173 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base;
171 174
172 termlist.push_back (this); 175 termlist.push_back (this);
173}
174 176
175rxvt_term::~rxvt_term () 177#ifdef KEYSYM_RESOURCE
176{ 178 keyboard = new keyboard_manager;
177 termlist.erase (find (termlist.begin (), termlist.end(), this));
178 179
180 if (!keyboard)
181 rxvt_fatal ("out of memory, aborting.\n");
182#endif
183}
184
185// clean up the most important stuff, do *not* call x or free mem etc.
186// for use before an emergency exit
187void rxvt_term::emergency_cleanup ()
188{
179 if (cmd_pid) 189 if (cmd_pid)
180 kill (-cmd_pid, SIGHUP); 190 kill (-cmd_pid, SIGHUP);
181 191
182 pty.put ();
183
184#ifdef UTMP_SUPPORT 192#ifdef UTMP_SUPPORT
185 privileged_utmp (RESTORE); 193 privileged_utmp (RESTORE);
186#endif 194#endif
195
196 pty.put ();
197}
198
199rxvt_term::~rxvt_term ()
200{
201 termlist.erase (find (termlist.begin (), termlist.end(), this));
202
203 emergency_cleanup ();
187 204
188#if ENABLE_STYLES 205#if ENABLE_STYLES
189 for (int i = RS_styleCount; --i; ) 206 for (int i = RS_styleCount; --i; )
190 if (TermWin.fontset[i] != TermWin.fontset[0]) 207 if (TermWin.fontset[i] != TermWin.fontset[0])
191 delete TermWin.fontset[i]; 208 delete TermWin.fontset[i];
192#endif 209#endif
193 delete TermWin.fontset[0]; 210 delete TermWin.fontset[0];
194 211
195 if (display) 212 if (display)
196 { 213 {
214 dDisp;
215
197 selection_clear (); 216 selection_clear ();
198 217
199#ifdef USE_XIM 218#ifdef USE_XIM
200 im_destroy (); 219 im_destroy ();
201#endif 220#endif
202#ifdef MENUBAR 221#ifdef MENUBAR
203 if (menubarGC) XFreeGC (display->display, menubarGC); 222 if (menubarGC) XFreeGC (disp, menubarGC);
204#endif 223#endif
205#ifdef XTERM_SCROLLBAR 224#ifdef XTERM_SCROLLBAR
206 if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC); 225 if (xscrollbarGC) XFreeGC (disp, xscrollbarGC);
207 if (ShadowGC) XFreeGC (display->display, ShadowGC); 226 if (ShadowGC) XFreeGC (disp, ShadowGC);
208#endif 227#endif
209#ifdef PLAIN_SCROLLBAR 228#ifdef PLAIN_SCROLLBAR
210 if (pscrollbarGC) XFreeGC (display->display, pscrollbarGC); 229 if (pscrollbarGC) XFreeGC (disp, pscrollbarGC);
211#endif 230#endif
212#ifdef NEXT_SCROLLBAR 231#ifdef NEXT_SCROLLBAR
213 if (blackGC) XFreeGC (display->display, blackGC); 232 if (blackGC) XFreeGC (disp, blackGC);
214 if (whiteGC) XFreeGC (display->display, whiteGC); 233 if (whiteGC) XFreeGC (disp, whiteGC);
215 if (grayGC) XFreeGC (display->display, grayGC); 234 if (grayGC) XFreeGC (disp, grayGC);
216 if (darkGC) XFreeGC (display->display, darkGC); 235 if (darkGC) XFreeGC (disp, darkGC);
217 if (stippleGC) XFreeGC (display->display, stippleGC); 236 if (stippleGC) XFreeGC (disp, stippleGC);
218 if (dimple) XFreePixmap (display->display, dimple); 237 if (dimple) XFreePixmap (disp, dimple);
219 if (upArrow) XFreePixmap (display->display, upArrow); 238 if (upArrow) XFreePixmap (disp, upArrow);
220 if (downArrow) XFreePixmap (display->display, downArrow); 239 if (downArrow) XFreePixmap (disp, downArrow);
221 if (upArrowHi) XFreePixmap (display->display, upArrowHi); 240 if (upArrowHi) XFreePixmap (disp, upArrowHi);
222 if (downArrowHi) XFreePixmap (display->display, downArrowHi); 241 if (downArrowHi) XFreePixmap (disp, downArrowHi);
223#endif 242#endif
224#if defined(MENUBAR) || defined(RXVT_SCROLLBAR) 243#if defined(MENUBAR) || defined(RXVT_SCROLLBAR)
225 if (topShadowGC) XFreeGC (display->display, topShadowGC); 244 if (topShadowGC) XFreeGC (disp, topShadowGC);
226 if (botShadowGC) XFreeGC (display->display, botShadowGC); 245 if (botShadowGC) XFreeGC (disp, botShadowGC);
227 if (scrollbarGC) XFreeGC (display->display, scrollbarGC); 246 if (scrollbarGC) XFreeGC (disp, scrollbarGC);
228#endif 247#endif
229 if (TermWin.gc) XFreeGC (display->display, TermWin.gc); 248 if (TermWin.gc) XFreeGC (disp, TermWin.gc);
230 249
231#if defined(MENUBAR) && (MENUBAR_MAX > 1) 250#if defined(MENUBAR) && (MENUBAR_MAX > 1)
232 delete menuBar.drawable; 251 delete menuBar.drawable;
233 //if (menuBar.win) 252 //if (menuBar.win)
234 // XDestroyWindow (display->display, menuBar.win); 253 // XDestroyWindow (disp, menuBar.win);
235#endif 254#endif
236 delete TermWin.drawable; 255 delete TermWin.drawable;
237 // destroy all windows 256 // destroy all windows
238 if (TermWin.parent[0]) 257 if (TermWin.parent[0]
258#if ENABLE_FRILLS
259 && !rs[Rs_embed]
260#endif
261 )
239 XDestroyWindow (display->display, TermWin.parent[0]); 262 XDestroyWindow (disp, TermWin.parent[0]);
240 } 263 }
241 264
242 // TODO: free pixcolours, colours should become part of rxvt_display 265 // TODO: free pixcolours, colours should become part of rxvt_display
243 266
244 delete pix_colors_focused; 267 delete pix_colors_focused;
250 273
251 scr_release (); 274 scr_release ();
252 275
253 /* clear all resources */ 276 /* clear all resources */
254 for (int i = 0; i < allocated.size (); i++) 277 for (int i = 0; i < allocated.size (); i++)
255 free (allocated[i]); 278 free (allocated [i]);
256 279
257 free (selection.text); 280 free (selection.text);
258 // TODO: manage env vars in child only(!) 281 // TODO: manage env vars in child only(!)
259 free (env_windowid); 282 free (env_windowid);
260 free (env_display); 283 free (env_display);
264 free (v_buffer); 287 free (v_buffer);
265 free (incr_buf); 288 free (incr_buf);
266 289
267 delete envv; 290 delete envv;
268 delete argv; 291 delete argv;
292
293#ifdef KEYSYM_RESOURCE
294 delete keyboard;
295#endif
269} 296}
270 297
271void 298void
272rxvt_term::destroy () 299rxvt_term::destroy ()
273{ 300{
325 352
326 delete this; 353 delete this;
327} 354}
328 355
329/*----------------------------------------------------------------------*/ 356/*----------------------------------------------------------------------*/
357/*
358 * Exit gracefully, clearing the utmp entry and restoring tty attributes
359 * TODO: if debugging, this should free up any known resources if we can
360 */
361static XErrorHandler old_xerror_handler;
362
363static void
364rxvt_emergency_cleanup ()
365{
366 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
367 (*t)->emergency_cleanup ();
368}
369
370#if ENABLE_FRILLS
371static void
372print_x_error (Display *dpy, XErrorEvent *event)
373{
374 char buffer[BUFSIZ];
375 char mesg[BUFSIZ];
376 char number[32];
377 char *mtype = "XlibMessage";
378 XGetErrorText(dpy, event->error_code, buffer, BUFSIZ);
379 XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ);
380 rxvt_warn ("An X Error occured, trying to continue after report.\n");
381 rxvt_warn ("%s: %s\n", mesg, buffer);
382 XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d", mesg, BUFSIZ);
383 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->request_code);
384 sprintf(number, "%d", event->request_code);
385 XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ);
386 rxvt_warn ("(which is %s)\n", buffer);
387 if (event->request_code >= 128) {
388 XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d",
389 mesg, BUFSIZ);
390 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->minor_code);
391 }
392 if ((event->error_code == BadWindow) ||
393 (event->error_code == BadPixmap) ||
394 (event->error_code == BadCursor) ||
395 (event->error_code == BadFont) ||
396 (event->error_code == BadDrawable) ||
397 (event->error_code == BadColor) ||
398 (event->error_code == BadGC) ||
399 (event->error_code == BadIDChoice) ||
400 (event->error_code == BadValue) ||
401 (event->error_code == BadAtom)) {
402 if (event->error_code == BadValue)
403 XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x",
404 mesg, BUFSIZ);
405 else if (event->error_code == BadAtom)
406 XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x",
407 mesg, BUFSIZ);
408 else
409 XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x",
410 mesg, BUFSIZ);
411 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->resourceid);
412 }
413 XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d",
414 mesg, BUFSIZ);
415 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->serial);
416}
417#endif
418
419int
420rxvt_xerror_handler (Display *display, XErrorEvent *event)
421{
422 if (GET_R->allowedxerror == -1)
423 GET_R->allowedxerror = event->error_code;
424 else
425 {
426 //TODO: GET_R is most likely not the terminal which caused the error
427 //TODO: maybe just output the error and continue?
428#if ENABLE_FRILLS
429 print_x_error (display, event);
430#else
431 old_xerror_handler (display, event);
432#endif
433 }
434
435 return 0;
436}
437
438int
439rxvt_xioerror_handler (Display *display)
440{
441 rxvt_warn ("X connection to '%s' broken, unable to recover, exiting.\n",
442 DisplayString (display));
443 rxvt_emergency_cleanup ();
444 _exit (EXIT_FAILURE);
445}
446
447/*
448 * Catch a fatal signal and tidy up before quitting
449 */
450void
451rxvt_term::sig_term (sig_watcher &w)
452{
453#ifdef DEBUG_CMD
454 rxvt_warn ("caught signal %d, exiting.\n", w.signum);
455#endif
456 rxvt_emergency_cleanup ();
457 signal (w.signum, SIG_DFL);
458 kill (getpid (), w.signum);
459}
460
461/*----------------------------------------------------------------------*/
330/* rxvt_init () */ 462/* rxvt_init () */
331bool 463bool
332rxvt_term::init (int argc, const char *const *argv) 464rxvt_term::init (int argc, const char *const *argv)
333{ 465{
334 SET_R (this); 466 SET_R (this);
335 467
468 set_locale ("");
469
336 if (!init_vars ()) 470 if (!init_vars ())
337 return false; 471 return false;
338 472
339 init_secondary (); 473 init_secondary ();
340 474
341 const char **cmd_argv = init_resources (argc, argv); 475 const char **cmd_argv = init_resources (argc, argv);
342 476
343 set_locale (""); 477#ifdef KEYSYM_RESOURCE
478 keyboard->register_done ();
479#endif
344 480
345#if MENUBAR_MAX 481#if MENUBAR_MAX
346 menubar_read (rs[Rs_menu]); 482 menubar_read (rs[Rs_menu]);
347#endif 483#endif
348#ifdef HAVE_SCROLLBARS 484#ifdef HAVE_SCROLLBARS
350 scrollBar.setIdle (); /* set existence for size calculations */ 486 scrollBar.setIdle (); /* set existence for size calculations */
351#endif 487#endif
352 488
353 create_windows (argc, argv); 489 create_windows (argc, argv);
354 490
491 dDisp;
492
355 init_xlocale (); 493 init_xlocale ();
356 494
357 scr_reset (); /* initialize screen */ 495 scr_reset (); /* initialize screen */
358 496
359#if 0 497#if 0
360 XSynchronize (display->display, True); 498 XSynchronize (disp, True);
361#endif 499#endif
362 500
363#ifdef HAVE_SCROLLBARS 501#ifdef HAVE_SCROLLBARS
364 if (options & Opt_scrollBar) 502 if (options & Opt_scrollBar)
365 resize_scrollbar (); /* create and map scrollbar */ 503 resize_scrollbar (); /* create and map scrollbar */
366#endif 504#endif
367#if (MENUBAR_MAX) 505#if (MENUBAR_MAX)
368 if (menubar_visible ()) 506 if (menubar_visible ())
369 XMapWindow (display->display, menuBar.win); 507 XMapWindow (disp, menuBar.win);
370#endif 508#endif
371#ifdef TRANSPARENT 509#ifdef TRANSPARENT
372 if (options & Opt_transparent) 510 if (options & Opt_transparent)
373 { 511 {
374 XSelectInput (display->display, display->root, PropertyChangeMask); 512 XSelectInput (disp, display->root, PropertyChangeMask);
375 check_our_parents (); 513 check_our_parents ();
376 rootwin_ev.start (display, display->root); 514 rootwin_ev.start (display, display->root);
377 } 515 }
378#endif 516#endif
379 517
380 XMapWindow (display->display, TermWin.vt); 518 XMapWindow (disp, TermWin.vt);
381 XMapWindow (display->display, TermWin.parent[0]); 519 XMapWindow (disp, TermWin.parent[0]);
382 520
383 set_colorfgbg (); 521 set_colorfgbg ();
384 522
385 init_command (cmd_argv); 523 init_command (cmd_argv);
386 524
525 free (cmd_argv);
526
387 pty_ev.start (pty.pty, EVENT_READ); 527 pty_ev.start (pty.pty, EVENT_READ);
388 528
389 check_ev.start (); 529 check_ev.start ();
390 530
391 return true; 531 return true;
392} 532}
393
394static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event);
395 533
396void 534void
397rxvt_init () 535rxvt_init ()
398{ 536{
399 /* 537 /*
412 /* need to trap SIGURG for SVR4 (Unixware) rlogin */ 550 /* need to trap SIGURG for SVR4 (Unixware) rlogin */
413 /* signal (SIGURG, SIG_DFL); */ 551 /* signal (SIGURG, SIG_DFL); */
414 552
415 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 553 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
416 // TODO: handle this with exceptions and tolerate the memory loss 554 // TODO: handle this with exceptions and tolerate the memory loss
417 //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); 555 XSetIOErrorHandler (rxvt_xioerror_handler);
418} 556}
419 557
420/* ------------------------------------------------------------------------- * 558/* ------------------------------------------------------------------------- *
421 * SIGNAL HANDLING & EXIT HANDLER * 559 * SIGNAL HANDLING & EXIT HANDLER *
422 * ------------------------------------------------------------------------- */ 560 * ------------------------------------------------------------------------- */
437 (*t)->destroy (); 575 (*t)->destroy ();
438 break; 576 break;
439 } 577 }
440} 578}
441 579
442/*----------------------------------------------------------------------*/
443/*
444 * Exit gracefully, clearing the utmp entry and restoring tty attributes
445 * TODO: if debugging, this should free up any known resources if we can
446 */
447void
448rxvt_destroy_all ()
449{
450 // TODO: rxvtd should clean up all ressources
451 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
452 (*t)->destroy ();
453}
454
455/*
456 * Catch a fatal signal and tidy up before quitting
457 */
458void
459rxvt_term::sig_term (sig_watcher &w)
460{
461#ifdef DEBUG_CMD
462 rxvt_warn ("caught signal %d, exiting.\n", w.signum);
463#endif
464 rxvt_destroy_all ();
465 signal (w.signum, SIG_DFL);
466 kill (getpid (), w.signum);
467}
468
469/* INTPROTO */
470int
471rxvt_xerror_handler (Display *display, XErrorEvent *event)
472{
473 if (GET_R->allowedxerror == -1)
474 GET_R->allowedxerror = event->error_code;
475 else
476 {
477 old_xerror_handler (display, event);
478 GET_R->destroy ();
479 }
480
481 return 0;
482}
483
484/* ------------------------------------------------------------------------- * 580/* ------------------------------------------------------------------------- *
485 * MEMORY ALLOCATION WRAPPERS * 581 * MEMORY ALLOCATION WRAPPERS *
486 * ------------------------------------------------------------------------- */ 582 * ------------------------------------------------------------------------- */
487void * 583void *
488rxvt_malloc (size_t size) 584rxvt_malloc (size_t size)
493 rxvt_fatal ("memory allocation failure. aborting.\n"); 589 rxvt_fatal ("memory allocation failure. aborting.\n");
494 590
495 return p; 591 return p;
496} 592}
497 593
498/* INTPROTO */
499void * 594void *
500rxvt_calloc (size_t number, size_t size) 595rxvt_calloc (size_t number, size_t size)
501{ 596{
502 void *p = calloc (number, size); 597 void *p = calloc (number, size);
503 598
505 rxvt_fatal ("memory allocation failure. aborting.\n"); 600 rxvt_fatal ("memory allocation failure. aborting.\n");
506 601
507 return p; 602 return p;
508} 603}
509 604
510/* INTPROTO */
511void * 605void *
512rxvt_realloc (void *ptr, size_t size) 606rxvt_realloc (void *ptr, size_t size)
513{ 607{
514 void *p = realloc (ptr, size); 608 void *p = realloc (ptr, size);
515 609
599 * if width/height are non-zero then override calculated width/height 693 * if width/height are non-zero then override calculated width/height
600 */ 694 */
601void 695void
602rxvt_term::window_calc (unsigned int width, unsigned int height) 696rxvt_term::window_calc (unsigned int width, unsigned int height)
603{ 697{
604 short recalc_x, recalc_y; 698 short recalc_x, recalc_y;
605 int x, y, sb_w, mb_h, flags; 699 int x, y, sb_w, mb_h, flags;
606 unsigned int w, h; 700 unsigned int w, h;
607 unsigned int max_width, max_height; 701 unsigned int max_width, max_height;
702 dDisp;
608 703
609 D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", 704 D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d",
610 TermWin.ncol, TermWin.nrow, szHint.width, 705 TermWin.ncol, TermWin.nrow, szHint.width,
611 szHint.height)); 706 szHint.height));
612 szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; 707 szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity;
618 if (!parsed_geometry) 713 if (!parsed_geometry)
619 { 714 {
620 parsed_geometry = 1; 715 parsed_geometry = 1;
621 if (rs[Rs_geometry]) 716 if (rs[Rs_geometry])
622 flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h); 717 flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h);
718
623 if (flags & WidthValue) 719 if (flags & WidthValue)
624 { 720 {
625 TermWin.ncol = BOUND_POSITIVE_INT16 (w); 721 TermWin.ncol = BOUND_POSITIVE_INT16 (w);
626 szHint.flags |= USSize; 722 szHint.flags |= USSize;
627 } 723 }
724
628 if (flags & HeightValue) 725 if (flags & HeightValue)
629 { 726 {
630 TermWin.nrow = BOUND_POSITIVE_INT16 (h); 727 TermWin.nrow = BOUND_POSITIVE_INT16 (h);
631 szHint.flags |= USSize; 728 szHint.flags |= USSize;
632 } 729 }
730
633 if (flags & XValue) 731 if (flags & XValue)
634 { 732 {
635 szHint.x = x; 733 szHint.x = x;
636 szHint.flags |= USPosition; 734 szHint.flags |= USPosition;
637 if (flags & XNegative) 735 if (flags & XNegative)
638 { 736 {
639 recalc_x = 1; 737 recalc_x = 1;
640 szHint.win_gravity = NorthEastGravity; 738 szHint.win_gravity = NorthEastGravity;
641 } 739 }
642 } 740 }
741
643 if (flags & YValue) 742 if (flags & YValue)
644 { 743 {
645 szHint.y = y; 744 szHint.y = y;
646 szHint.flags |= USPosition; 745 szHint.flags |= USPosition;
647 if (flags & YNegative) 746 if (flags & YNegative)
710 809
711 if (scrollbar_visible () && (options & Opt_scrollBar_right)) 810 if (scrollbar_visible () && (options & Opt_scrollBar_right))
712 window_sb_x = szHint.width - sb_w; 811 window_sb_x = szHint.width - sb_w;
713 812
714 if (recalc_x) 813 if (recalc_x)
715 szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) 814 szHint.x += (DisplayWidth (disp, display->screen)
716 - szHint.width - 2 * TermWin.ext_bwidth); 815 - szHint.width - 2 * TermWin.ext_bwidth);
717 if (recalc_y) 816 if (recalc_y)
718 szHint.y += (DisplayHeight (display->display, DefaultScreen (display->display)) 817 szHint.y += (DisplayHeight (disp, display->screen)
719 - szHint.height - 2 * TermWin.ext_bwidth); 818 - szHint.height - 2 * TermWin.ext_bwidth);
720 819
721 TermWin.ncol = TermWin.width / TermWin.fwidth; 820 TermWin.ncol = TermWin.width / TermWin.fwidth;
722 TermWin.nrow = TermWin.height / TermWin.fheight; 821 TermWin.nrow = TermWin.height / TermWin.fheight;
723 D_SIZE ((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", 822 D_SIZE ((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d",
782 881
783 delete TermWin.fontset[0]; 882 delete TermWin.fontset[0];
784 TermWin.fontset[0] = fs; 883 TermWin.fontset[0] = fs;
785 884
786 prop = (*fs)[1]->properties (); 885 prop = (*fs)[1]->properties ();
886 prop.height += TermWin.lineSpace;
787 fs->set_prop (prop); 887 fs->set_prop (prop);
788 888
789 TermWin.fwidth = prop.width; 889 TermWin.fwidth = prop.width;
790 TermWin.fheight = prop.height; 890 TermWin.fheight = prop.height;
791 TermWin.fweight = prop.weight; 891 TermWin.fweight = prop.weight;
887 987
888 /* handle color aliases */ 988 /* handle color aliases */
889 if (isdigit (*color)) 989 if (isdigit (*color))
890 { 990 {
891 i = atoi (color); 991 i = atoi (color);
992
892 if (i >= 8 && i <= 15) 993 if (i >= 8 && i <= 15)
893 { /* bright colors */ 994 { /* bright colors */
894 i -= 8; 995 i -= 8;
895# ifndef NO_BRIGHTCOLOR 996# ifndef NO_BRIGHTCOLOR
896 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; 997 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i];
897 SET_PIXCOLOR (idx); 998 SET_PIXCOLOR (idx);
898 goto Done; 999 goto Done;
899# endif 1000# endif
900
901 } 1001 }
1002
902 if (i >= 0 && i <= 7) 1003 if (i >= 0 && i <= 7)
903 { /* normal colors */ 1004 { /* normal colors */
904 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; 1005 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i];
905 SET_PIXCOLOR (idx); 1006 SET_PIXCOLOR (idx);
906 goto Done; 1007 goto Done;
907 } 1008 }
908 } 1009 }
909 1010
910 if (!rXParseAllocColor (& xcol, color)) 1011 if (!rXParseAllocColor (&xcol, color))
911 return; 1012 return;
912 1013
913 /* XStoreColor (display->display, display->cmap, XColor*); */ 1014 /* XStoreColor (display->display, display->cmap, XColor*); */
914 1015
915 /* 1016 /*
1018 * -------------------------------------------------------------------- */ 1119 * -------------------------------------------------------------------- */
1019void 1120void
1020rxvt_term::resize_all_windows (unsigned int width, unsigned int height, int ignoreparent) 1121rxvt_term::resize_all_windows (unsigned int width, unsigned int height, int ignoreparent)
1021{ 1122{
1022 int fix_screen; 1123 int fix_screen;
1023
1024#ifdef SMART_RESIZE 1124#ifdef SMART_RESIZE
1025 int old_width = szHint.width, old_height = szHint.height; 1125 int old_width = szHint.width, old_height = szHint.height;
1026#endif 1126#endif
1127 dDisp;
1027 1128
1028 window_calc (width, height); 1129 window_calc (width, height);
1029 XSetWMNormalHints (display->display, TermWin.parent[0], &szHint); 1130 XSetWMNormalHints (disp, TermWin.parent[0], &szHint);
1030 1131
1031 if (!ignoreparent) 1132 if (!ignoreparent)
1032 { 1133 {
1033#ifdef SMART_RESIZE 1134#ifdef SMART_RESIZE
1034 /* 1135 /*
1038 int x, y, x1, y1; 1139 int x, y, x1, y1;
1039 int dx, dy; 1140 int dx, dy;
1040 unsigned int unused_w1, unused_h1, unused_b1, unused_d1; 1141 unsigned int unused_w1, unused_h1, unused_b1, unused_d1;
1041 Window unused_cr; 1142 Window unused_cr;
1042 1143
1043 XTranslateCoordinates (display->display, TermWin.parent[0], display->root, 1144 XTranslateCoordinates (disp, TermWin.parent[0], display->root,
1044 0, 0, &x, &y, &unused_cr); 1145 0, 0, &x, &y, &unused_cr);
1045 XGetGeometry (display->display, TermWin.parent[0], &unused_cr, &x1, &y1, 1146 XGetGeometry (disp, TermWin.parent[0], &unused_cr, &x1, &y1,
1046 &unused_w1, &unused_h1, &unused_b1, &unused_d1); 1147 &unused_w1, &unused_h1, &unused_b1, &unused_d1);
1047 /* 1148 /*
1048 * if display->root isn't the parent window, a WM will probably have offset 1149 * if display->root isn't the parent window, a WM will probably have offset
1049 * our position for handles and decorations. Counter it 1150 * our position for handles and decorations. Counter it
1050 */ 1151 */
1052 { 1153 {
1053 x -= x1; 1154 x -= x1;
1054 y -= y1; 1155 y -= y1;
1055 } 1156 }
1056 1157
1057 x1 = (DisplayWidth (display->display, display->screen) - old_width) / 2; 1158 x1 = (DisplayWidth (disp, display->screen) - old_width) / 2;
1058 y1 = (DisplayHeight (display->display, display->screen) - old_height) / 2; 1159 y1 = (DisplayHeight (disp, display->screen) - old_height) / 2;
1059 dx = old_width - szHint.width; 1160 dx = old_width - szHint.width;
1060 dy = old_height - szHint.height; 1161 dy = old_height - szHint.height;
1061 1162
1062 /* Check position of the center of the window */ 1163 /* Check position of the center of the window */
1063 if (x < x1) /* left half */ 1164 if (x < x1) /* left half */
1067 if (y < y1) /* top half */ 1168 if (y < y1) /* top half */
1068 dy = 0; 1169 dy = 0;
1069 else if (y == y1) /* exact center */ 1170 else if (y == y1) /* exact center */
1070 dy /= 2; 1171 dy /= 2;
1071 1172
1072 XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy, 1173 XMoveResizeWindow (disp, TermWin.parent[0], x + dx, y + dy,
1073 szHint.width, szHint.height); 1174 szHint.width, szHint.height);
1074#else 1175#else
1075 XResizeWindow (display->display, TermWin.parent[0], szHint.width, szHint.height); 1176 XResizeWindow (disp, TermWin.parent[0], szHint.width, szHint.height);
1076#endif 1177#endif
1077 } 1178 }
1078 1179
1079 fix_screen = TermWin.ncol != prev_ncol || TermWin.nrow != prev_nrow; 1180 fix_screen = TermWin.ncol != prev_ncol || TermWin.nrow != prev_nrow;
1080 1181
1081 if (fix_screen || width != old_width || height != old_height) 1182 if (fix_screen || width != old_width || height != old_height)
1082 { 1183 {
1083 if (scrollbar_visible ()) 1184 if (scrollbar_visible ())
1084 { 1185 {
1085 XMoveResizeWindow (display->display, scrollBar.win, 1186 XMoveResizeWindow (disp, scrollBar.win,
1086 window_sb_x, 0, 1187 window_sb_x, 0,
1087 scrollbar_TotalWidth (), szHint.height); 1188 scrollbar_TotalWidth (), szHint.height);
1088 resize_scrollbar (); 1189 resize_scrollbar ();
1089 } 1190 }
1090 1191
1091 if (menubar_visible ()) 1192 if (menubar_visible ())
1092 XMoveResizeWindow (display->display, menuBar.win, 1193 XMoveResizeWindow (disp, menuBar.win,
1093 window_vt_x, 0, 1194 window_vt_x, 0,
1094 TermWin_TotalWidth (), menuBar_TotalHeight ()); 1195 TermWin_TotalWidth (), menuBar_TotalHeight ());
1095 1196
1096 XMoveResizeWindow (display->display, TermWin.vt, 1197 XMoveResizeWindow (disp, TermWin.vt,
1097 window_vt_x, window_vt_y, 1198 window_vt_x, window_vt_y,
1098 TermWin_TotalWidth (), TermWin_TotalHeight ()); 1199 TermWin_TotalWidth (), TermWin_TotalHeight ());
1200
1099 scr_clear (); 1201 scr_clear ();
1100#ifdef XPM_BACKGROUND 1202#ifdef XPM_BACKGROUND
1101 resize_pixmap (); 1203 resize_pixmap ();
1102#endif 1204#endif
1103 } 1205 }
1125 } 1227 }
1126 } 1228 }
1127 1229
1128 old_width = szHint.width; 1230 old_width = szHint.width;
1129 old_height = szHint.height; 1231 old_height = szHint.height;
1232
1233#ifdef XPM_BACKGROUND
1234 if (TermWin.pixmap)
1235 scr_touch (false);
1236#endif
1130 1237
1131#ifdef USE_XIM 1238#ifdef USE_XIM
1132 IMSetStatusPosition (); 1239 IMSetStatusPosition ();
1133#endif 1240#endif
1134} 1241}
1364 "*", 1471 "*",
1365 TermWin.fheight, 1472 TermWin.fheight,
1366 TermWin.fheight + 1, TermWin.fheight - 1, 1473 TermWin.fheight + 1, TermWin.fheight - 1,
1367 TermWin.fheight - 2, TermWin.fheight + 2); 1474 TermWin.fheight - 2, TermWin.fheight + 2);
1368 1475
1369 fs = XCreateFontSet (display->display, pat, 1476 fs = XCreateFontSet (display->display, rs[Rs_imFont] ? rs[Rs_imFont] : pat,
1370 &missing_charset_list, &missing_charset_count, &def_string); 1477 &missing_charset_list, &missing_charset_count, &def_string);
1371 1478
1372 if (missing_charset_list) 1479 if (missing_charset_list)
1373 XFreeStringList (missing_charset_list); 1480 XFreeStringList (missing_charset_list);
1374 1481
1450{ 1557{
1451 int i, found, had_im; 1558 int i, found, had_im;
1452 const char *p; 1559 const char *p;
1453 char **s; 1560 char **s;
1454 char buf[IMBUFSIZ]; 1561 char buf[IMBUFSIZ];
1562
1563 SET_R (this);
1455 1564
1456 im_destroy (); 1565 im_destroy ();
1457 1566
1458 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); 1567 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()"));
1459 if (Input_Context) 1568 if (Input_Context)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines