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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines