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.121 by root, Wed Dec 15 00:12:58 2004 UTC vs.
Revision 1.147 by root, Mon Nov 28 19:35:04 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 <signal.h> 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])
239 XDestroyWindow (display->display, TermWin.parent[0]); 258 XDestroyWindow (disp, TermWin.parent[0]);
240 } 259 }
241 260
242 // TODO: free pixcolours, colours should become part of rxvt_display 261 // TODO: free pixcolours, colours should become part of rxvt_display
243 262
244 delete pix_colors_focused; 263 delete pix_colors_focused;
245#ifdef OFF_FOCUS_FADING 264#if OFF_FOCUS_FADING
246 delete pix_colors_unfocused; 265 delete pix_colors_unfocused;
247#endif 266#endif
248 267
249 displays.put (display); 268 displays.put (display);
250 269
251 scr_release (); 270 scr_release ();
252 271
253 /* clear all resources */ 272 /* clear all resources */
254 for (int i = 0; i < allocated.size (); i++) 273 for (int i = 0; i < allocated.size (); i++)
255 free (allocated[i]); 274 free (allocated [i]);
256 275
257 free (selection.text); 276 free (selection.text);
258 // TODO: manage env vars in child only(!) 277 // TODO: manage env vars in child only(!)
259 free (env_windowid); 278 free (env_windowid);
260 free (env_display); 279 free (env_display);
264 free (v_buffer); 283 free (v_buffer);
265 free (incr_buf); 284 free (incr_buf);
266 285
267 delete envv; 286 delete envv;
268 delete argv; 287 delete argv;
288
289#ifdef KEYSYM_RESOURCE
290 delete keyboard;
291#endif
269} 292}
270 293
271void 294void
272rxvt_term::destroy () 295rxvt_term::destroy ()
273{ 296{
325 348
326 delete this; 349 delete this;
327} 350}
328 351
329/*----------------------------------------------------------------------*/ 352/*----------------------------------------------------------------------*/
353/*
354 * Exit gracefully, clearing the utmp entry and restoring tty attributes
355 * TODO: if debugging, this should free up any known resources if we can
356 */
357static XErrorHandler old_xerror_handler;
358
359static void
360rxvt_emergency_cleanup ()
361{
362 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
363 (*t)->emergency_cleanup ();
364}
365
366#if ENABLE_FRILLS
367static void
368print_x_error (Display *dpy, XErrorEvent *event)
369{
370 char buffer[BUFSIZ];
371 char mesg[BUFSIZ];
372 char number[32];
373 char *mtype = "XlibMessage";
374 XGetErrorText(dpy, event->error_code, buffer, BUFSIZ);
375 XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ);
376 rxvt_warn ("An X Error occured, trying to continue after report.\n");
377 rxvt_warn ("%s: %s\n", mesg, buffer);
378 XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d", mesg, BUFSIZ);
379 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->request_code);
380 sprintf(number, "%d", event->request_code);
381 XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ);
382 rxvt_warn ("(which is %s)\n", buffer);
383 if (event->request_code >= 128) {
384 XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d",
385 mesg, BUFSIZ);
386 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->minor_code);
387 }
388 if ((event->error_code == BadWindow) ||
389 (event->error_code == BadPixmap) ||
390 (event->error_code == BadCursor) ||
391 (event->error_code == BadFont) ||
392 (event->error_code == BadDrawable) ||
393 (event->error_code == BadColor) ||
394 (event->error_code == BadGC) ||
395 (event->error_code == BadIDChoice) ||
396 (event->error_code == BadValue) ||
397 (event->error_code == BadAtom)) {
398 if (event->error_code == BadValue)
399 XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x",
400 mesg, BUFSIZ);
401 else if (event->error_code == BadAtom)
402 XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x",
403 mesg, BUFSIZ);
404 else
405 XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x",
406 mesg, BUFSIZ);
407 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->resourceid);
408 }
409 XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d",
410 mesg, BUFSIZ);
411 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->serial);
412}
413#endif
414
415int
416rxvt_xerror_handler (Display *display, XErrorEvent *event)
417{
418 if (GET_R->allowedxerror == -1)
419 GET_R->allowedxerror = event->error_code;
420 else
421 {
422 // GET_R is most likely not the terminal which caused the error,
423 // so just output the error and continue
424#if ENABLE_FRILLS
425 print_x_error (display, event);
426#else
427 old_xerror_handler (display, event);
428#endif
429 }
430
431 return 0;
432}
433
434int
435rxvt_xioerror_handler (Display *display)
436{
437 rxvt_warn ("X connection to '%s' broken, unable to recover, exiting.\n",
438 DisplayString (display));
439 rxvt_emergency_cleanup ();
440 _exit (EXIT_FAILURE);
441}
442
443/*
444 * Catch a fatal signal and tidy up before quitting
445 */
446void
447rxvt_term::sig_term (sig_watcher &w)
448{
449#ifdef DEBUG_CMD
450 rxvt_warn ("caught signal %d, exiting.\n", w.signum);
451#endif
452 rxvt_emergency_cleanup ();
453 signal (w.signum, SIG_DFL);
454 kill (getpid (), w.signum);
455}
456
457/*----------------------------------------------------------------------*/
330/* rxvt_init () */ 458/* rxvt_init () */
331bool 459bool
332rxvt_term::init (int argc, const char *const *argv) 460rxvt_term::init (int argc, const char *const *argv)
333{ 461{
334 SET_R (this); 462 SET_R (this);
335 463
464 set_locale ("");
465
336 if (!init_vars ()) 466 if (!init_vars ())
337 return false; 467 return false;
338 468
339 init_secondary (); 469 init_secondary ();
340 470
341 const char **cmd_argv = init_resources (argc, argv); 471 const char **cmd_argv = init_resources (argc, argv);
342 472
343 set_locale (""); 473#ifdef KEYSYM_RESOURCE
474 keyboard->register_done ();
475#endif
344 476
345#if MENUBAR_MAX 477#if MENUBAR_MAX
346 menubar_read (rs[Rs_menu]); 478 menubar_read (rs[Rs_menu]);
347#endif 479#endif
348#ifdef HAVE_SCROLLBARS 480#ifdef HAVE_SCROLLBARS
350 scrollBar.setIdle (); /* set existence for size calculations */ 482 scrollBar.setIdle (); /* set existence for size calculations */
351#endif 483#endif
352 484
353 create_windows (argc, argv); 485 create_windows (argc, argv);
354 486
487 dDisp;
488
355 init_xlocale (); 489 init_xlocale ();
356 490
357 scr_reset (); /* initialize screen */ 491 scr_reset (); /* initialize screen */
358 492
359#if 0 493#if 0
360 XSynchronize (display->display, True); 494 XSynchronize (disp, True);
361#endif 495#endif
362 496
363#ifdef HAVE_SCROLLBARS 497#ifdef HAVE_SCROLLBARS
364 if (options & Opt_scrollBar) 498 if (options & Opt_scrollBar)
365 resize_scrollbar (); /* create and map scrollbar */ 499 resize_scrollbar (); /* create and map scrollbar */
366#endif 500#endif
367#if (MENUBAR_MAX) 501#if (MENUBAR_MAX)
368 if (menubar_visible ()) 502 if (menubar_visible ())
369 XMapWindow (display->display, menuBar.win); 503 XMapWindow (disp, menuBar.win);
370#endif 504#endif
371#ifdef TRANSPARENT 505#ifdef TRANSPARENT
372 if (options & Opt_transparent) 506 if (options & Opt_transparent)
373 { 507 {
374 XSelectInput (display->display, display->root, PropertyChangeMask); 508 XSelectInput (disp, display->root, PropertyChangeMask);
375 check_our_parents (); 509 check_our_parents ();
376 rootwin_ev.start (display, display->root); 510 rootwin_ev.start (display, display->root);
377 } 511 }
378#endif 512#endif
379 513
380 XMapWindow (display->display, TermWin.vt); 514 XMapWindow (disp, TermWin.vt);
381 XMapWindow (display->display, TermWin.parent[0]); 515 XMapWindow (disp, TermWin.parent[0]);
382 516
383 set_colorfgbg (); 517 set_colorfgbg ();
384 518
385 init_command (cmd_argv); 519 init_command (cmd_argv);
386 520
521 free (cmd_argv);
522
387 pty_ev.start (pty.pty, EVENT_READ); 523 pty_ev.start (pty.pty, EVENT_READ);
388 524
389 check_ev.start (); 525 check_ev.start ();
390 526
391 return true; 527 return true;
392} 528}
393
394static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event);
395 529
396void 530void
397rxvt_init () 531rxvt_init ()
398{ 532{
399 /* 533 /*
412 /* need to trap SIGURG for SVR4 (Unixware) rlogin */ 546 /* need to trap SIGURG for SVR4 (Unixware) rlogin */
413 /* signal (SIGURG, SIG_DFL); */ 547 /* signal (SIGURG, SIG_DFL); */
414 548
415 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 549 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
416 // TODO: handle this with exceptions and tolerate the memory loss 550 // TODO: handle this with exceptions and tolerate the memory loss
417 //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); 551 XSetIOErrorHandler (rxvt_xioerror_handler);
418} 552}
419 553
420/* ------------------------------------------------------------------------- * 554/* ------------------------------------------------------------------------- *
421 * SIGNAL HANDLING & EXIT HANDLER * 555 * SIGNAL HANDLING & EXIT HANDLER *
422 * ------------------------------------------------------------------------- */ 556 * ------------------------------------------------------------------------- */
437 (*t)->destroy (); 571 (*t)->destroy ();
438 break; 572 break;
439 } 573 }
440} 574}
441 575
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/* ------------------------------------------------------------------------- * 576/* ------------------------------------------------------------------------- *
485 * MEMORY ALLOCATION WRAPPERS * 577 * MEMORY ALLOCATION WRAPPERS *
486 * ------------------------------------------------------------------------- */ 578 * ------------------------------------------------------------------------- */
487void * 579void *
488rxvt_malloc (size_t size) 580rxvt_malloc (size_t size)
493 rxvt_fatal ("memory allocation failure. aborting.\n"); 585 rxvt_fatal ("memory allocation failure. aborting.\n");
494 586
495 return p; 587 return p;
496} 588}
497 589
498/* INTPROTO */
499void * 590void *
500rxvt_calloc (size_t number, size_t size) 591rxvt_calloc (size_t number, size_t size)
501{ 592{
502 void *p = calloc (number, size); 593 void *p = calloc (number, size);
503 594
505 rxvt_fatal ("memory allocation failure. aborting.\n"); 596 rxvt_fatal ("memory allocation failure. aborting.\n");
506 597
507 return p; 598 return p;
508} 599}
509 600
510/* INTPROTO */
511void * 601void *
512rxvt_realloc (void *ptr, size_t size) 602rxvt_realloc (void *ptr, size_t size)
513{ 603{
514 void *p = realloc (ptr, size); 604 void *p = realloc (ptr, size);
515 605
599 * if width/height are non-zero then override calculated width/height 689 * if width/height are non-zero then override calculated width/height
600 */ 690 */
601void 691void
602rxvt_term::window_calc (unsigned int width, unsigned int height) 692rxvt_term::window_calc (unsigned int width, unsigned int height)
603{ 693{
604 short recalc_x, recalc_y; 694 short recalc_x, recalc_y;
605 int x, y, sb_w, mb_h, flags; 695 int x, y, sb_w, mb_h, flags;
606 unsigned int w, h; 696 unsigned int w, h;
607 unsigned int max_width, max_height; 697 unsigned int max_width, max_height;
698 dDisp;
608 699
609 D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", 700 D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d",
610 TermWin.ncol, TermWin.nrow, szHint.width, 701 TermWin.ncol, TermWin.nrow, szHint.width,
611 szHint.height)); 702 szHint.height));
612 szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; 703 szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity;
618 if (!parsed_geometry) 709 if (!parsed_geometry)
619 { 710 {
620 parsed_geometry = 1; 711 parsed_geometry = 1;
621 if (rs[Rs_geometry]) 712 if (rs[Rs_geometry])
622 flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h); 713 flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h);
714
623 if (flags & WidthValue) 715 if (flags & WidthValue)
624 { 716 {
625 TermWin.ncol = BOUND_POSITIVE_INT16 (w); 717 TermWin.ncol = BOUND_POSITIVE_INT16 (w);
626 szHint.flags |= USSize; 718 szHint.flags |= USSize;
627 } 719 }
720
628 if (flags & HeightValue) 721 if (flags & HeightValue)
629 { 722 {
630 TermWin.nrow = BOUND_POSITIVE_INT16 (h); 723 TermWin.nrow = BOUND_POSITIVE_INT16 (h);
631 szHint.flags |= USSize; 724 szHint.flags |= USSize;
632 } 725 }
726
633 if (flags & XValue) 727 if (flags & XValue)
634 { 728 {
635 szHint.x = x; 729 szHint.x = x;
636 szHint.flags |= USPosition; 730 szHint.flags |= USPosition;
637 if (flags & XNegative) 731 if (flags & XNegative)
638 { 732 {
639 recalc_x = 1; 733 recalc_x = 1;
640 szHint.win_gravity = NorthEastGravity; 734 szHint.win_gravity = NorthEastGravity;
641 } 735 }
642 } 736 }
737
643 if (flags & YValue) 738 if (flags & YValue)
644 { 739 {
645 szHint.y = y; 740 szHint.y = y;
646 szHint.flags |= USPosition; 741 szHint.flags |= USPosition;
647 if (flags & YNegative) 742 if (flags & YNegative)
710 805
711 if (scrollbar_visible () && (options & Opt_scrollBar_right)) 806 if (scrollbar_visible () && (options & Opt_scrollBar_right))
712 window_sb_x = szHint.width - sb_w; 807 window_sb_x = szHint.width - sb_w;
713 808
714 if (recalc_x) 809 if (recalc_x)
715 szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) 810 szHint.x += (DisplayWidth (disp, display->screen)
716 - szHint.width - 2 * TermWin.ext_bwidth); 811 - szHint.width - 2 * TermWin.ext_bwidth);
717 if (recalc_y) 812 if (recalc_y)
718 szHint.y += (DisplayHeight (display->display, DefaultScreen (display->display)) 813 szHint.y += (DisplayHeight (disp, display->screen)
719 - szHint.height - 2 * TermWin.ext_bwidth); 814 - szHint.height - 2 * TermWin.ext_bwidth);
720 815
721 TermWin.ncol = TermWin.width / TermWin.fwidth; 816 TermWin.ncol = TermWin.width / TermWin.fwidth;
722 TermWin.nrow = TermWin.height / TermWin.fheight; 817 TermWin.nrow = TermWin.height / TermWin.fheight;
723 D_SIZE ((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", 818 D_SIZE ((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d",
746 (void)ioctl (pty.pty, TIOCSWINSZ, &ws); 841 (void)ioctl (pty.pty, TIOCSWINSZ, &ws);
747 842
748#if 0 843#if 0
749 // TIOCSWINSZ⎈ is supposed to do this automatically and correctly 844 // TIOCSWINSZ⎈ is supposed to do this automatically and correctly
750 if (cmd_pid) /* force through to the command */ 845 if (cmd_pid) /* force through to the command */
751 kill (cmd_pid, SIGWINCH); 846 kill (-cmd_pid, SIGWINCH);
752#endif 847#endif
753} 848}
754 849
755/*----------------------------------------------------------------------*/ 850/*----------------------------------------------------------------------*/
756/* set_fonts () - load and set the various fonts 851/* set_fonts () - load and set the various fonts
757/* 852 *
758 * init = 1 - initialize 853 * init = 1 - initialize
759 * 854 *
760 * fontname == FONT_UP - switch to bigger font 855 * fontname == FONT_UP - switch to bigger font
761 * fontname == FONT_DN - switch to smaller font 856 * fontname == FONT_DN - switch to smaller font
762 */ 857 */
782 877
783 delete TermWin.fontset[0]; 878 delete TermWin.fontset[0];
784 TermWin.fontset[0] = fs; 879 TermWin.fontset[0] = fs;
785 880
786 prop = (*fs)[1]->properties (); 881 prop = (*fs)[1]->properties ();
882 prop.height += TermWin.lineSpace;
787 fs->set_prop (prop); 883 fs->set_prop (prop);
788 884
789 TermWin.fwidth = prop.width; 885 TermWin.fwidth = prop.width;
790 TermWin.fheight = prop.height; 886 TermWin.fheight = prop.height;
791 TermWin.fweight = prop.weight; 887 TermWin.fweight = prop.weight;
859/* xterm sequences - title, iconName, color (exptl) */ 955/* xterm sequences - title, iconName, color (exptl) */
860void 956void
861rxvt_term::set_title (const char *str) 957rxvt_term::set_title (const char *str)
862{ 958{
863 set_string_property (XA_WM_NAME, str); 959 set_string_property (XA_WM_NAME, str);
864#if ENABLE_FRILLS 960#if ENABLE_EWMH
865 set_utf8_property (xa[XA_NET_WM_NAME], str); 961 set_utf8_property (xa[XA_NET_WM_NAME], str);
866#endif 962#endif
867} 963}
868 964
869void 965void
870rxvt_term::set_icon_name (const char *str) 966rxvt_term::set_icon_name (const char *str)
871{ 967{
872 set_string_property (XA_WM_ICON_NAME, str); 968 set_string_property (XA_WM_ICON_NAME, str);
873#if ENABLE_FRILLS 969#if ENABLE_EWMH
874 set_utf8_property (xa[XA_NET_WM_ICON_NAME], str); 970 set_utf8_property (xa[XA_NET_WM_ICON_NAME], str);
875#endif 971#endif
876} 972}
877 973
878#ifdef XTERM_COLOR_CHANGE 974#ifdef XTERM_COLOR_CHANGE
887 983
888 /* handle color aliases */ 984 /* handle color aliases */
889 if (isdigit (*color)) 985 if (isdigit (*color))
890 { 986 {
891 i = atoi (color); 987 i = atoi (color);
988
892 if (i >= 8 && i <= 15) 989 if (i >= 8 && i <= 15)
893 { /* bright colors */ 990 { /* bright colors */
894 i -= 8; 991 i -= 8;
895# ifndef NO_BRIGHTCOLOR 992# ifndef NO_BRIGHTCOLOR
896 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; 993 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i];
897 SET_PIXCOLOR (idx); 994 SET_PIXCOLOR (idx);
898 goto Done; 995 goto done;
899# endif 996# endif
900
901 } 997 }
998
902 if (i >= 0 && i <= 7) 999 if (i >= 0 && i <= 7)
903 { /* normal colors */ 1000 { /* normal colors */
904 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; 1001 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i];
905 SET_PIXCOLOR (idx); 1002 SET_PIXCOLOR (idx);
906 goto Done; 1003 goto done;
907 } 1004 }
908 } 1005 }
909 1006
910 if (!rXParseAllocColor (& xcol, color)) 1007 if (!rXParseAllocColor (&xcol, color))
911 return; 1008 return;
912 1009
913 /* XStoreColor (display->display, display->cmap, XColor*); */ 1010 /* XStoreColor (display->display, display->cmap, XColor*); */
914 1011
915 /* 1012 /*
931 pix_colors_focused[idx] = xcol; 1028 pix_colors_focused[idx] = xcol;
932 SET_PIXCOLOR (idx); 1029 SET_PIXCOLOR (idx);
933 1030
934 /* XSetWindowAttributes attr; */ 1031 /* XSetWindowAttributes attr; */
935 /* Cursor cursor; */ 1032 /* Cursor cursor; */
936Done: 1033done:
1034
937#ifdef OFF_FOCUS_FADING 1035#if OFF_FOCUS_FADING
938 if (rs[Rs_fade]) 1036 if (rs[Rs_fade])
939 pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade])); 1037 pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade]), pix_colors[Color_fade]);
940#endif 1038#endif
941 1039
942 /*TODO: handle Color_BD, scrollbar background, etc. */ 1040 /*TODO: handle Color_BD, scrollbar background, etc. */
943 1041
944 recolour_cursor (); 1042 recolour_cursor ();
998 1096
999 sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); 1097 sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr);
1000} 1098}
1001 1099
1002/*----------------------------------------------------------------------*/ 1100/*----------------------------------------------------------------------*/
1003/*
1004 * Colour determination for low colour displays, routine from
1005 * Hans de Goede <hans@highrise.nl>
1006 */
1007 1101
1008int 1102int
1009rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) 1103rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour)
1010{ 1104{
1011 if (!screen_in_out->set (display, colour)) 1105 if (!screen_in_out->set (display, colour))
1022 * -------------------------------------------------------------------- */ 1116 * -------------------------------------------------------------------- */
1023void 1117void
1024rxvt_term::resize_all_windows (unsigned int width, unsigned int height, int ignoreparent) 1118rxvt_term::resize_all_windows (unsigned int width, unsigned int height, int ignoreparent)
1025{ 1119{
1026 int fix_screen; 1120 int fix_screen;
1027
1028#ifdef SMART_RESIZE 1121#ifdef SMART_RESIZE
1029 int old_width = szHint.width, old_height = szHint.height; 1122 int old_width = szHint.width, old_height = szHint.height;
1030#endif 1123#endif
1124 dDisp;
1031 1125
1032 window_calc (width, height); 1126 window_calc (width, height);
1033 XSetWMNormalHints (display->display, TermWin.parent[0], &szHint); 1127 XSetWMNormalHints (disp, TermWin.parent[0], &szHint);
1034 1128
1035 if (!ignoreparent) 1129 if (!ignoreparent)
1036 { 1130 {
1037#ifdef SMART_RESIZE 1131#ifdef SMART_RESIZE
1038 /* 1132 /*
1042 int x, y, x1, y1; 1136 int x, y, x1, y1;
1043 int dx, dy; 1137 int dx, dy;
1044 unsigned int unused_w1, unused_h1, unused_b1, unused_d1; 1138 unsigned int unused_w1, unused_h1, unused_b1, unused_d1;
1045 Window unused_cr; 1139 Window unused_cr;
1046 1140
1047 XTranslateCoordinates (display->display, TermWin.parent[0], display->root, 1141 XTranslateCoordinates (disp, TermWin.parent[0], display->root,
1048 0, 0, &x, &y, &unused_cr); 1142 0, 0, &x, &y, &unused_cr);
1049 XGetGeometry (display->display, TermWin.parent[0], &unused_cr, &x1, &y1, 1143 XGetGeometry (disp, TermWin.parent[0], &unused_cr, &x1, &y1,
1050 &unused_w1, &unused_h1, &unused_b1, &unused_d1); 1144 &unused_w1, &unused_h1, &unused_b1, &unused_d1);
1051 /* 1145 /*
1052 * if display->root isn't the parent window, a WM will probably have offset 1146 * if display->root isn't the parent window, a WM will probably have offset
1053 * our position for handles and decorations. Counter it 1147 * our position for handles and decorations. Counter it
1054 */ 1148 */
1056 { 1150 {
1057 x -= x1; 1151 x -= x1;
1058 y -= y1; 1152 y -= y1;
1059 } 1153 }
1060 1154
1061 x1 = (DisplayWidth (display->display, display->screen) - old_width) / 2; 1155 x1 = (DisplayWidth (disp, display->screen) - old_width) / 2;
1062 y1 = (DisplayHeight (display->display, display->screen) - old_height) / 2; 1156 y1 = (DisplayHeight (disp, display->screen) - old_height) / 2;
1063 dx = old_width - szHint.width; 1157 dx = old_width - szHint.width;
1064 dy = old_height - szHint.height; 1158 dy = old_height - szHint.height;
1065 1159
1066 /* Check position of the center of the window */ 1160 /* Check position of the center of the window */
1067 if (x < x1) /* left half */ 1161 if (x < x1) /* left half */
1071 if (y < y1) /* top half */ 1165 if (y < y1) /* top half */
1072 dy = 0; 1166 dy = 0;
1073 else if (y == y1) /* exact center */ 1167 else if (y == y1) /* exact center */
1074 dy /= 2; 1168 dy /= 2;
1075 1169
1076 XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy, 1170 XMoveResizeWindow (disp, TermWin.parent[0], x + dx, y + dy,
1077 szHint.width, szHint.height); 1171 szHint.width, szHint.height);
1078#else 1172#else
1079 XResizeWindow (display->display, TermWin.parent[0], szHint.width, szHint.height); 1173 XResizeWindow (disp, TermWin.parent[0], szHint.width, szHint.height);
1080#endif 1174#endif
1081 } 1175 }
1082 1176
1083 fix_screen = TermWin.ncol != prev_ncol || TermWin.nrow != prev_nrow; 1177 fix_screen = TermWin.ncol != prev_ncol || TermWin.nrow != prev_nrow;
1084 1178
1085 if (fix_screen || width != old_width || height != old_height) 1179 if (fix_screen || width != old_width || height != old_height)
1086 { 1180 {
1087 if (scrollbar_visible ()) 1181 if (scrollbar_visible ())
1088 { 1182 {
1089 XMoveResizeWindow (display->display, scrollBar.win, 1183 XMoveResizeWindow (disp, scrollBar.win,
1090 window_sb_x, 0, 1184 window_sb_x, 0,
1091 scrollbar_TotalWidth (), szHint.height); 1185 scrollbar_TotalWidth (), szHint.height);
1092 resize_scrollbar (); 1186 resize_scrollbar ();
1093 } 1187 }
1094 1188
1095 if (menubar_visible ()) 1189 if (menubar_visible ())
1096 XMoveResizeWindow (display->display, menuBar.win, 1190 XMoveResizeWindow (disp, menuBar.win,
1097 window_vt_x, 0, 1191 window_vt_x, 0,
1098 TermWin_TotalWidth (), menuBar_TotalHeight ()); 1192 TermWin_TotalWidth (), menuBar_TotalHeight ());
1099 1193
1100 XMoveResizeWindow (display->display, TermWin.vt, 1194 XMoveResizeWindow (disp, TermWin.vt,
1101 window_vt_x, window_vt_y, 1195 window_vt_x, window_vt_y,
1102 TermWin_TotalWidth (), TermWin_TotalHeight ()); 1196 TermWin_TotalWidth (), TermWin_TotalHeight ());
1197
1103 scr_clear (); 1198 scr_clear ();
1104#ifdef XPM_BACKGROUND 1199#ifdef XPM_BACKGROUND
1105 resize_pixmap (); 1200 resize_pixmap ();
1106#endif 1201#endif
1107 } 1202 }
1130 } 1225 }
1131 1226
1132 old_width = szHint.width; 1227 old_width = szHint.width;
1133 old_height = szHint.height; 1228 old_height = szHint.height;
1134 1229
1230#ifdef XPM_BACKGROUND
1231 if (TermWin.pixmap)
1232 scr_touch (false);
1233#endif
1234
1135#ifdef USE_XIM 1235#ifdef USE_XIM
1136 IMSetStatusPosition (); 1236 IMSetStatusPosition ();
1137#endif 1237#endif
1138} 1238}
1139 1239
1147 XWindowAttributes wattr; 1247 XWindowAttributes wattr;
1148 1248
1149 if (width == 0 || height == 0) 1249 if (width == 0 || height == 0)
1150 { 1250 {
1151 XGetWindowAttributes (display->display, display->root, &wattr); 1251 XGetWindowAttributes (display->display, display->root, &wattr);
1252
1152 if (width == 0) 1253 if (width == 0)
1153 width = wattr.width - szHint.base_width; 1254 width = wattr.width - szHint.base_width;
1154 if (height == 0) 1255 if (height == 0)
1155 height = wattr.height - szHint.base_height; 1256 height = wattr.height - szHint.base_height;
1156 } 1257 }
1368 "*", 1469 "*",
1369 TermWin.fheight, 1470 TermWin.fheight,
1370 TermWin.fheight + 1, TermWin.fheight - 1, 1471 TermWin.fheight + 1, TermWin.fheight - 1,
1371 TermWin.fheight - 2, TermWin.fheight + 2); 1472 TermWin.fheight - 2, TermWin.fheight + 2);
1372 1473
1373 fs = XCreateFontSet (display->display, pat, 1474 fs = XCreateFontSet (display->display, rs[Rs_imFont] ? rs[Rs_imFont] : pat,
1374 &missing_charset_list, &missing_charset_count, &def_string); 1475 &missing_charset_list, &missing_charset_count, &def_string);
1375 1476
1376 if (missing_charset_list) 1477 if (missing_charset_list)
1377 XFreeStringList (missing_charset_list); 1478 XFreeStringList (missing_charset_list);
1378 1479
1450} 1551}
1451 1552
1452void 1553void
1453rxvt_term::im_cb () 1554rxvt_term::im_cb ()
1454{ 1555{
1455 int i, found, had_im; 1556 int i;
1456 const char *p; 1557 const char *p;
1457 char **s; 1558 char **s;
1458 char buf[IMBUFSIZ]; 1559 char buf[IMBUFSIZ];
1560
1561 SET_R (this);
1459 1562
1460 im_destroy (); 1563 im_destroy ();
1461 1564
1462 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); 1565 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()"));
1463 if (Input_Context) 1566 if (Input_Context)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines