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.114 by root, Tue Sep 7 06:19:45 2004 UTC vs.
Revision 1.143 by root, Sun Feb 20 00:09:25 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;
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 //TODO: GET_R is most likely not the terminal which caused the error
423 //TODO: maybe 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
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;
831 } 926 }
832 927
833 return true; 928 return true;
834} 929}
835 930
931void rxvt_term::set_string_property (Atom prop, const char *str, int len)
932{
933 // TODO: SMART_WINDOW_TITLE
934 XChangeProperty (display->display, TermWin.parent[0],
935 prop, XA_STRING, 8, PropModeReplace,
936 (const unsigned char *)str, len >= 0 ? len : strlen (str));
937}
938
939void rxvt_term::set_utf8_property (Atom prop, const char *str, int len)
940{
941 // TODO: SMART_WINDOW_TITLE
942 wchar_t *ws = rxvt_mbstowcs (str, len);
943 char *s = rxvt_wcstoutf8 (ws);
944
945 XChangeProperty (display->display, TermWin.parent[0],
946 prop, xa[XA_UTF8_STRING], 8, PropModeReplace,
947 (const unsigned char *)s, strlen (s));
948
949 free (s);
950 free (ws);
951}
952
836/*----------------------------------------------------------------------*/ 953/*----------------------------------------------------------------------*/
837/*----------------------------------------------------------------------*/ 954/*----------------------------------------------------------------------*/
838/* xterm sequences - title, iconName, color (exptl) */ 955/* xterm sequences - title, iconName, color (exptl) */
839void 956void
840rxvt_term::set_title (const char *str) 957rxvt_term::set_title (const char *str)
841{ 958{
842#ifdef SMART_WINDOW_TITLE 959 set_string_property (XA_WM_NAME, str);
843 char *name; 960#if ENABLE_FRILLS
844 961 set_utf8_property (xa[XA_NET_WM_NAME], str);
845 if (!XFetchName (display->display, TermWin.parent[0], &name))
846 name = NULL;
847
848 if (name == NULL || strcmp (name, str))
849#endif
850 XStoreName (display->display, TermWin.parent[0], str);
851
852#ifdef SMART_WINDOW_TITLE
853 if (name)
854 XFree (name);
855#endif 962#endif
856} 963}
857 964
858void 965void
859rxvt_term::set_icon_name (const char *str) 966rxvt_term::set_icon_name (const char *str)
860{ 967{
861#ifdef SMART_WINDOW_TITLE 968 set_string_property (XA_WM_ICON_NAME, str);
862 char *name; 969#if ENABLE_FRILLS
863 970 set_utf8_property (xa[XA_NET_WM_ICON_NAME], str);
864 if (!XGetIconName (display->display, TermWin.parent[0], &name))
865 name = NULL;
866
867 if (name == NULL || strcmp (name, str))
868#endif
869 XSetIconName (display->display, TermWin.parent[0], str);
870
871#ifdef SMART_WINDOW_TITLE
872 if (name)
873 XFree (name);
874#endif 971#endif
875} 972}
876 973
877#ifdef XTERM_COLOR_CHANGE 974#ifdef XTERM_COLOR_CHANGE
878void 975void
886 983
887 /* handle color aliases */ 984 /* handle color aliases */
888 if (isdigit (*color)) 985 if (isdigit (*color))
889 { 986 {
890 i = atoi (color); 987 i = atoi (color);
988
891 if (i >= 8 && i <= 15) 989 if (i >= 8 && i <= 15)
892 { /* bright colors */ 990 { /* bright colors */
893 i -= 8; 991 i -= 8;
894# ifndef NO_BRIGHTCOLOR 992# ifndef NO_BRIGHTCOLOR
895 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; 993 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i];
896 SET_PIXCOLOR (idx); 994 SET_PIXCOLOR (idx);
897 goto Done; 995 goto Done;
898# endif 996# endif
899
900 } 997 }
998
901 if (i >= 0 && i <= 7) 999 if (i >= 0 && i <= 7)
902 { /* normal colors */ 1000 { /* normal colors */
903 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; 1001 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i];
904 SET_PIXCOLOR (idx); 1002 SET_PIXCOLOR (idx);
905 goto Done; 1003 goto Done;
906 } 1004 }
907 } 1005 }
908 1006
909 if (!rXParseAllocColor (& xcol, color)) 1007 if (!rXParseAllocColor (&xcol, color))
910 return; 1008 return;
911 1009
912 /* XStoreColor (display->display, display->cmap, XColor*); */ 1010 /* XStoreColor (display->display, display->cmap, XColor*); */
913 1011
914 /* 1012 /*
997 1095
998 sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); 1096 sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr);
999} 1097}
1000 1098
1001/*----------------------------------------------------------------------*/ 1099/*----------------------------------------------------------------------*/
1002/*
1003 * Colour determination for low colour displays, routine from
1004 * Hans de Goede <hans@highrise.nl>
1005 */
1006 1100
1007int 1101int
1008rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) 1102rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour)
1009{ 1103{
1010 if (!screen_in_out->set (display, colour)) 1104 if (!screen_in_out->set (display, colour))
1021 * -------------------------------------------------------------------- */ 1115 * -------------------------------------------------------------------- */
1022void 1116void
1023rxvt_term::resize_all_windows (unsigned int width, unsigned int height, int ignoreparent) 1117rxvt_term::resize_all_windows (unsigned int width, unsigned int height, int ignoreparent)
1024{ 1118{
1025 int fix_screen; 1119 int fix_screen;
1026
1027#ifdef SMART_RESIZE 1120#ifdef SMART_RESIZE
1028 int old_width = szHint.width, old_height = szHint.height; 1121 int old_width = szHint.width, old_height = szHint.height;
1029#endif 1122#endif
1123 dDisp;
1030 1124
1031 window_calc (width, height); 1125 window_calc (width, height);
1032 XSetWMNormalHints (display->display, TermWin.parent[0], &szHint); 1126 XSetWMNormalHints (disp, TermWin.parent[0], &szHint);
1033 1127
1034 if (!ignoreparent) 1128 if (!ignoreparent)
1035 { 1129 {
1036#ifdef SMART_RESIZE 1130#ifdef SMART_RESIZE
1037 /* 1131 /*
1041 int x, y, x1, y1; 1135 int x, y, x1, y1;
1042 int dx, dy; 1136 int dx, dy;
1043 unsigned int unused_w1, unused_h1, unused_b1, unused_d1; 1137 unsigned int unused_w1, unused_h1, unused_b1, unused_d1;
1044 Window unused_cr; 1138 Window unused_cr;
1045 1139
1046 XTranslateCoordinates (display->display, TermWin.parent[0], display->root, 1140 XTranslateCoordinates (disp, TermWin.parent[0], display->root,
1047 0, 0, &x, &y, &unused_cr); 1141 0, 0, &x, &y, &unused_cr);
1048 XGetGeometry (display->display, TermWin.parent[0], &unused_cr, &x1, &y1, 1142 XGetGeometry (disp, TermWin.parent[0], &unused_cr, &x1, &y1,
1049 &unused_w1, &unused_h1, &unused_b1, &unused_d1); 1143 &unused_w1, &unused_h1, &unused_b1, &unused_d1);
1050 /* 1144 /*
1051 * if display->root isn't the parent window, a WM will probably have offset 1145 * if display->root isn't the parent window, a WM will probably have offset
1052 * our position for handles and decorations. Counter it 1146 * our position for handles and decorations. Counter it
1053 */ 1147 */
1055 { 1149 {
1056 x -= x1; 1150 x -= x1;
1057 y -= y1; 1151 y -= y1;
1058 } 1152 }
1059 1153
1060 x1 = (DisplayWidth (display->display, display->screen) - old_width) / 2; 1154 x1 = (DisplayWidth (disp, display->screen) - old_width) / 2;
1061 y1 = (DisplayHeight (display->display, display->screen) - old_height) / 2; 1155 y1 = (DisplayHeight (disp, display->screen) - old_height) / 2;
1062 dx = old_width - szHint.width; 1156 dx = old_width - szHint.width;
1063 dy = old_height - szHint.height; 1157 dy = old_height - szHint.height;
1064 1158
1065 /* Check position of the center of the window */ 1159 /* Check position of the center of the window */
1066 if (x < x1) /* left half */ 1160 if (x < x1) /* left half */
1070 if (y < y1) /* top half */ 1164 if (y < y1) /* top half */
1071 dy = 0; 1165 dy = 0;
1072 else if (y == y1) /* exact center */ 1166 else if (y == y1) /* exact center */
1073 dy /= 2; 1167 dy /= 2;
1074 1168
1075 XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy, 1169 XMoveResizeWindow (disp, TermWin.parent[0], x + dx, y + dy,
1076 szHint.width, szHint.height); 1170 szHint.width, szHint.height);
1077#else 1171#else
1078 XResizeWindow (display->display, TermWin.parent[0], szHint.width, szHint.height); 1172 XResizeWindow (disp, TermWin.parent[0], szHint.width, szHint.height);
1079#endif 1173#endif
1080 } 1174 }
1081 1175
1082 fix_screen = TermWin.ncol != prev_ncol || TermWin.nrow != prev_nrow; 1176 fix_screen = TermWin.ncol != prev_ncol || TermWin.nrow != prev_nrow;
1083 1177
1084 if (fix_screen || width != old_width || height != old_height) 1178 if (fix_screen || width != old_width || height != old_height)
1085 { 1179 {
1086 if (scrollbar_visible ()) 1180 if (scrollbar_visible ())
1087 { 1181 {
1088 XMoveResizeWindow (display->display, scrollBar.win, 1182 XMoveResizeWindow (disp, scrollBar.win,
1089 window_sb_x, 0, 1183 window_sb_x, 0,
1090 scrollbar_TotalWidth (), szHint.height); 1184 scrollbar_TotalWidth (), szHint.height);
1091 resize_scrollbar (); 1185 resize_scrollbar ();
1092 } 1186 }
1093 1187
1094 if (menubar_visible ()) 1188 if (menubar_visible ())
1095 XMoveResizeWindow (display->display, menuBar.win, 1189 XMoveResizeWindow (disp, menuBar.win,
1096 window_vt_x, 0, 1190 window_vt_x, 0,
1097 TermWin_TotalWidth (), menuBar_TotalHeight ()); 1191 TermWin_TotalWidth (), menuBar_TotalHeight ());
1098 1192
1099 XMoveResizeWindow (display->display, TermWin.vt, 1193 XMoveResizeWindow (disp, TermWin.vt,
1100 window_vt_x, window_vt_y, 1194 window_vt_x, window_vt_y,
1101 TermWin_TotalWidth (), TermWin_TotalHeight ()); 1195 TermWin_TotalWidth (), TermWin_TotalHeight ());
1196
1102 scr_clear (); 1197 scr_clear ();
1103#ifdef XPM_BACKGROUND 1198#ifdef XPM_BACKGROUND
1104 resize_pixmap (); 1199 resize_pixmap ();
1105#endif 1200#endif
1106 } 1201 }
1129 } 1224 }
1130 1225
1131 old_width = szHint.width; 1226 old_width = szHint.width;
1132 old_height = szHint.height; 1227 old_height = szHint.height;
1133 1228
1229#ifdef XPM_BACKGROUND
1230 if (TermWin.pixmap)
1231 scr_touch (false);
1232#endif
1233
1134#ifdef USE_XIM 1234#ifdef USE_XIM
1135 IMSetStatusPosition (); 1235 IMSetStatusPosition ();
1136#endif 1236#endif
1137} 1237}
1138 1238
1146 XWindowAttributes wattr; 1246 XWindowAttributes wattr;
1147 1247
1148 if (width == 0 || height == 0) 1248 if (width == 0 || height == 0)
1149 { 1249 {
1150 XGetWindowAttributes (display->display, display->root, &wattr); 1250 XGetWindowAttributes (display->display, display->root, &wattr);
1251
1151 if (width == 0) 1252 if (width == 0)
1152 width = wattr.width - szHint.base_width; 1253 width = wattr.width - szHint.base_width;
1153 if (height == 0) 1254 if (height == 0)
1154 height = wattr.height - szHint.base_height; 1255 height = wattr.height - szHint.base_height;
1155 } 1256 }
1299 { 1400 {
1300 im_destroy (); 1401 im_destroy ();
1301 return false; 1402 return false;
1302 } 1403 }
1303 1404
1304 p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root,None"; 1405 const char *pet[] = { rs[Rs_preeditType], "OverTheSpot,OffTheSpot,Root,None" };
1406
1407 for (int pi = 0; pi < 2; pi++)
1408 {
1409 p = pet[pi];
1410
1411 if (!p)
1412 continue;
1413
1305 s = rxvt_splitcommastring (p); 1414 s = rxvt_splitcommastring (p);
1306 1415
1307 for (i = found = 0; !found && s[i]; i++) 1416 for (i = found = 0; !found && s[i]; i++)
1308 { 1417 {
1309 if (!strcmp (s[i], "OverTheSpot")) 1418 if (!strcmp (s[i], "OverTheSpot"))
1310 input_style = (XIMPreeditPosition | XIMStatusNothing); 1419 input_style = (XIMPreeditPosition | XIMStatusNothing);
1311 else if (!strcmp (s[i], "OffTheSpot")) 1420 else if (!strcmp (s[i], "OffTheSpot"))
1312 input_style = (XIMPreeditArea | XIMStatusArea); 1421 input_style = (XIMPreeditArea | XIMStatusArea);
1313 else if (!strcmp (s[i], "Root")) 1422 else if (!strcmp (s[i], "Root"))
1314 input_style = (XIMPreeditNothing | XIMStatusNothing); 1423 input_style = (XIMPreeditNothing | XIMStatusNothing);
1315 else if (!strcmp (s[i], "None")) 1424 else if (!strcmp (s[i], "None"))
1316 input_style = (XIMPreeditNone | XIMStatusNone); 1425 input_style = (XIMPreeditNone | XIMStatusNone);
1317 1426
1318 for (j = 0; j < xim_styles->count_styles; j++) 1427 for (j = 0; j < xim_styles->count_styles; j++)
1319 if (input_style == xim_styles->supported_styles[j]) 1428 if (input_style == xim_styles->supported_styles[j])
1320 { 1429 {
1430 rxvt_freecommastring (s);
1431
1321 found = 1; 1432 found = 1;
1322 break; 1433 goto foundpet;
1434 }
1435
1323 } 1436 }
1324 }
1325 1437
1326 for (i = 0; s[i]; i++) 1438 rxvt_freecommastring (s);
1327 free (s[i]); 1439 }
1328 1440
1329 free (s); 1441foundpet:
1442
1330 XFree (xim_styles); 1443 XFree (xim_styles);
1331 1444
1332 if (!found) 1445 if (!found)
1333 { 1446 {
1334 im_destroy (); 1447 im_destroy ();
1355 "*", 1468 "*",
1356 TermWin.fheight, 1469 TermWin.fheight,
1357 TermWin.fheight + 1, TermWin.fheight - 1, 1470 TermWin.fheight + 1, TermWin.fheight - 1,
1358 TermWin.fheight - 2, TermWin.fheight + 2); 1471 TermWin.fheight - 2, TermWin.fheight + 2);
1359 1472
1360 fs = XCreateFontSet (display->display, pat, 1473 fs = XCreateFontSet (display->display, rs[Rs_imFont] ? rs[Rs_imFont] : pat,
1361 &missing_charset_list, &missing_charset_count, &def_string); 1474 &missing_charset_list, &missing_charset_count, &def_string);
1362 1475
1363 if (missing_charset_list) 1476 if (missing_charset_list)
1364 XFreeStringList (missing_charset_list); 1477 XFreeStringList (missing_charset_list);
1365 1478
1442 int i, found, had_im; 1555 int i, found, had_im;
1443 const char *p; 1556 const char *p;
1444 char **s; 1557 char **s;
1445 char buf[IMBUFSIZ]; 1558 char buf[IMBUFSIZ];
1446 1559
1560 SET_R (this);
1561
1447 im_destroy (); 1562 im_destroy ();
1448 1563
1449 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); 1564 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()"));
1450 if (Input_Context) 1565 if (Input_Context)
1451 return; 1566 return;
1459 if (p && *p) 1574 if (p && *p)
1460 { 1575 {
1461 bool found = false; 1576 bool found = false;
1462 1577
1463 s = rxvt_splitcommastring (p); 1578 s = rxvt_splitcommastring (p);
1579
1464 for (i = 0; s[i]; i++) 1580 for (i = 0; s[i]; i++)
1465 { 1581 {
1466 if (*s[i]) 1582 if (*s[i])
1467 { 1583 {
1468 strcpy (buf, "@im="); 1584 strcpy (buf, "@im=");
1472 found = true; 1588 found = true;
1473 break; 1589 break;
1474 } 1590 }
1475 } 1591 }
1476 } 1592 }
1477 for (i = 0; s[i]; i++) 1593
1478 free (s[i]); 1594 rxvt_freecommastring (s);
1479 free (s);
1480 1595
1481 if (found) 1596 if (found)
1482 goto done; 1597 goto done;
1483 } 1598 }
1484 1599

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines