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.76 by root, Wed Aug 4 03:29:28 2004 UTC vs.
Revision 1.114 by root, Tue Sep 7 06:19:45 2004 UTC

51static char curlocale[128]; 51static char curlocale[128];
52 52
53bool 53bool
54rxvt_set_locale (const char *locale) 54rxvt_set_locale (const char *locale)
55{ 55{
56 if (!locale || !STRNCMP (locale, curlocale, 128)) 56 if (!locale || !strncmp (locale, curlocale, 128))
57 return false; 57 return false;
58 58
59 STRNCPY (curlocale, locale, 128); 59 strncpy (curlocale, locale, 128);
60 setlocale (LC_CTYPE, curlocale); 60 setlocale (LC_CTYPE, curlocale);
61 return true; 61 return true;
62} 62}
63 63
64#if ENABLE_COMBINING 64#if ENABLE_COMBINING
123 return len; 123 return len;
124 124
125} 125}
126#endif 126#endif
127 127
128void *
129rxvt_term::operator new (size_t s)
130{
131 void *p = malloc (s);
132
133 MEMSET (p, 0, s);
134 return p;
135}
136
137void
138rxvt_term::operator delete (void *p, size_t s)
139{
140 free (p);
141}
142
143rxvt_term::rxvt_term () 128rxvt_term::rxvt_term ()
144 : 129 :
130#if TRANSPARENT
145 rootwin_ev (this, &rxvt_term::rootwin_cb), 131 rootwin_ev (this, &rxvt_term::rootwin_cb),
132#endif
133#ifdef HAVE_SCROLLBARS
134 scrollbar_ev (this, &rxvt_term::x_cb),
135#endif
136#ifdef MENUBAR
137 menubar_ev (this, &rxvt_term::x_cb),
138#endif
139#ifdef CURSOR_BLINK
140 cursor_blink_ev (this, &rxvt_term::cursor_blink_cb),
141#endif
142#ifdef TEXT_BLINK
143 text_blink_ev (this, &rxvt_term::text_blink_cb),
144#endif
145#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
146 cont_scroll_ev (this, &rxvt_term::cont_scroll_cb),
147#endif
148#ifdef SELECTION_SCROLLING
149 sel_scroll_ev (this, &rxvt_term::sel_scroll_cb),
150#endif
151#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
152 slip_wheel_ev (this, &rxvt_term::slip_wheel_cb),
153#endif
154#ifdef POINTER_BLANK
155 pointer_ev (this, &rxvt_term::pointer_cb),
156#endif
157#ifdef USE_XIM
158 im_ev (this, &rxvt_term::im_cb),
159#endif
160 sw_term (this, &rxvt_term::sig_term),
161 sw_chld (this, &rxvt_term::sig_chld),
146 termwin_ev (this, &rxvt_term::x_cb), 162 termwin_ev (this, &rxvt_term::x_cb),
147 vt_ev (this, &rxvt_term::x_cb), 163 vt_ev (this, &rxvt_term::x_cb),
148#ifdef HAVE_SCROLLBARS
149 scrollbar_ev (this, &rxvt_term::x_cb),
150#endif
151#ifdef MENUBAR
152 menubar_ev (this, &rxvt_term::x_cb),
153#endif
154#ifdef CURSOR_BLINK
155 cursor_blink_ev (this, &rxvt_term::cursor_blink_cb),
156#endif
157#ifdef TEXT_BLINK
158 text_blink_ev (this, &rxvt_term::text_blink_cb),
159#endif
160#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
161 cont_scroll_ev (this, &rxvt_term::cont_scroll_cb),
162#endif
163#ifdef SELECTION_SCROLLING
164 sel_scroll_ev (this, &rxvt_term::sel_scroll_cb),
165#endif
166#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
167 slip_wheel_ev (this, &rxvt_term::slip_wheel_cb),
168#endif
169#ifdef POINTER_BLANK
170 pointer_ev (this, &rxvt_term::pointer_cb),
171#endif
172#ifdef USE_XIM
173 im_ev (this, &rxvt_term::im_cb),
174#endif
175 check_ev (this, &rxvt_term::check_cb), 164 check_ev (this, &rxvt_term::check_cb),
176 flush_ev (this, &rxvt_term::flush_cb), 165 flush_ev (this, &rxvt_term::flush_cb),
177 destroy_ev (this, &rxvt_term::destroy_cb), 166 destroy_ev (this, &rxvt_term::destroy_cb),
178 pty_ev (this, &rxvt_term::pty_cb), 167 pty_ev (this, &rxvt_term::pty_cb),
179 incr_ev (this, &rxvt_term::incr_cb) 168 incr_ev (this, &rxvt_term::incr_cb)
185 174
186rxvt_term::~rxvt_term () 175rxvt_term::~rxvt_term ()
187{ 176{
188 termlist.erase (find (termlist.begin (), termlist.end(), this)); 177 termlist.erase (find (termlist.begin (), termlist.end(), this));
189 178
190 if (cmd_fd >= 0) 179 if (cmd_pid)
191 close (cmd_fd); 180 kill (-cmd_pid, SIGHUP);
192 181
193#ifndef NO_SETOWNER_TTYDEV 182 pty.put ();
194 privileged_ttydev (RESTORE); 183
195#endif
196#ifdef UTMP_SUPPORT 184#ifdef UTMP_SUPPORT
197 privileged_utmp (RESTORE); 185 privileged_utmp (RESTORE);
198#endif 186#endif
199 187
188#if ENABLE_STYLES
189 for (int i = RS_styleCount; --i; )
190 if (TermWin.fontset[i] != TermWin.fontset[0])
191 delete TermWin.fontset[i];
192#endif
200 delete TermWin.fontset; 193 delete TermWin.fontset[0];
201 194
202 if (display) 195 if (display)
203 { 196 {
204 selection_clear (); 197 selection_clear ();
205 198
199#ifdef USE_XIM
200 im_destroy ();
201#endif
206#ifdef MENUBAR 202#ifdef MENUBAR
207 if (menubarGC) XFreeGC (display->display, menubarGC); 203 if (menubarGC) XFreeGC (display->display, menubarGC);
208#endif 204#endif
209#ifdef XTERM_SCROLLBAR 205#ifdef XTERM_SCROLLBAR
210 if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC); 206 if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC);
211 if (ShadowGC) XFreeGC (display->display, ShadowGC); 207 if (ShadowGC) XFreeGC (display->display, ShadowGC);
212#endif 208#endif
243 XDestroyWindow (display->display, TermWin.parent[0]); 239 XDestroyWindow (display->display, TermWin.parent[0]);
244 } 240 }
245 241
246 // TODO: free pixcolours, colours should become part of rxvt_display 242 // TODO: free pixcolours, colours should become part of rxvt_display
247 243
248 delete PixColorsFocused; 244 delete pix_colors_focused;
249#ifdef OFF_FOCUS_FADING 245#ifdef OFF_FOCUS_FADING
250 delete PixColorsUnFocused; 246 delete pix_colors_unfocused;
251#endif 247#endif
252 248
253 displays.put (display); 249 displays.put (display);
254 250
255 scr_release (); 251 scr_release ();
274} 270}
275 271
276void 272void
277rxvt_term::destroy () 273rxvt_term::destroy ()
278{ 274{
275 if (destroy_ev.active)
276 return;
277
278#if ENABLE_OVERLAY
279 scr_overlay_off ();
280#endif
281
279 if (display) 282 if (display)
280 { 283 {
284#if USE_XIM
285 im_ev.stop (display);
286#endif
287#if HAVE_SCROLLBARS
288 scrollbar_ev.stop (display);
289#endif
290#if MENUBAR
291 menubar_ev.stop (display);
292#endif
293#if TRANSPARENT
281 rootwin_ev.stop (display); 294 rootwin_ev.stop (display);
295#endif
296 incr_ev.stop ();
282 termwin_ev.stop (display); 297 termwin_ev.stop (display);
283 vt_ev.stop (display); 298 vt_ev.stop (display);
284#ifdef USE_XIM
285 im_destroy ();
286 im_ev.stop (display);
287#endif
288#ifdef HAVE_SCROLLBARS
289 scrollbar_ev.stop (display);
290#endif
291#ifdef MENUBAR
292 menubar_ev.stop (display);
293#endif
294 } 299 }
295 300
296 check_ev.stop (); 301 check_ev.stop ();
297 pty_ev.stop (); 302 pty_ev.stop ();
298#ifdef CURSOR_BLINK 303#ifdef CURSOR_BLINK
330 SET_R (this); 335 SET_R (this);
331 336
332 if (!init_vars ()) 337 if (!init_vars ())
333 return false; 338 return false;
334 339
340 init_secondary ();
341
342 const char **cmd_argv = init_resources (argc, argv);
343
344 set_locale ("");
345
346#if MENUBAR_MAX
347 menubar_read (rs[Rs_menu]);
348#endif
349#ifdef HAVE_SCROLLBARS
350 if (options & Opt_scrollBar)
351 scrollBar.setIdle (); /* set existence for size calculations */
352#endif
353
354 create_windows (argc, argv);
355
356 init_xlocale ();
357
358 scr_reset (); /* initialize screen */
359
360#if 0
361 XSynchronize (display->display, True);
362#endif
363
364#ifdef HAVE_SCROLLBARS
365 if (options & Opt_scrollBar)
366 resize_scrollbar (); /* create and map scrollbar */
367#endif
368#if (MENUBAR_MAX)
369 if (menubar_visible ())
370 XMapWindow (display->display, menuBar.win);
371#endif
372#ifdef TRANSPARENT
373 if (options & Opt_transparent)
374 {
375 XSelectInput (display->display, display->root, PropertyChangeMask);
376 check_our_parents ();
377 rootwin_ev.start (display, display->root);
378 }
379#endif
380
381 XMapWindow (display->display, TermWin.vt);
382 XMapWindow (display->display, TermWin.parent[0]);
383
384 set_colorfgbg ();
385
386 init_command (cmd_argv);
387
388 pty_ev.start (pty.pty, EVENT_READ);
389
390 check_ev.start ();
391
392 return true;
393}
394
395static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event);
396
397void
398rxvt_init ()
399{
335 /* 400 /*
336 * Save and then give up any super-user privileges 401 * Save and then give up any super-user privileges
337 * If we need privileges in any area then we must specifically request it. 402 * If we need privileges in any area then we must specifically request it.
338 * We should only need to be root in these cases: 403 * We should only need to be root in these cases:
339 * 1. write utmp entries on some systems 404 * 1. write utmp entries on some systems
340 * 2. chown tty on some systems 405 * 2. chown tty on some systems
341 */ 406 */
342 privileges (SAVE); 407 rxvt_privileges (SAVE);
343 privileges (IGNORE); 408 rxvt_privileges (IGNORE);
344 409
345 init_secondary (); 410 signal (SIGHUP, SIG_IGN);
346 411 signal (SIGPIPE, SIG_IGN);
347 const char **cmd_argv = init_resources (argc, argv);
348
349 set_locale ("");
350
351#if MENUBAR_MAX
352 menubar_read (rs[Rs_menu]);
353#endif
354#ifdef HAVE_SCROLLBARS
355 if (Options & Opt_scrollBar)
356 scrollBar.setIdle (); /* set existence for size calculations */
357#endif
358
359 create_windows (argc, argv);
360
361 init_xlocale ();
362
363 scr_reset (); /* initialize screen */
364
365#if 0
366 XSynchronize (display->display, True);
367#endif
368
369#ifdef HAVE_SCROLLBARS
370 if (Options & Opt_scrollBar)
371 resize_scrollbar (); /* create and map scrollbar */
372#endif
373#if (MENUBAR_MAX)
374 if (menubar_visible ())
375 XMapWindow (display->display, menuBar.win);
376#endif
377#ifdef TRANSPARENT
378 if (Options & Opt_transparent)
379 {
380 XSelectInput (display->display, display->root, PropertyChangeMask);
381 check_our_parents ();
382 }
383#endif
384
385 rootwin_ev.start (display, display->root);
386
387 XMapWindow (display->display, TermWin.vt);
388 XMapWindow (display->display, TermWin.parent[0]);
389
390 init_command (cmd_argv);
391
392 pty_ev.start (cmd_fd, EVENT_READ);
393
394 check_ev.start ();
395
396 return true;
397}
398
399static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event);
400
401void
402rxvt_init_signals ()
403{
404 /* install exit handler for cleanup */
405#if 0
406#ifdef HAVE_ATEXIT
407 atexit (rxvt_clean_exit);
408#else
409#endif
410#endif
411
412 struct sigaction sa;
413
414 sigfillset (&sa.sa_mask);
415 sa.sa_flags = SA_NOCLDSTOP | SA_RESTART;
416 sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0);
417 sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0);
418 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0);
419 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0);
420 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0);
421 sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0);
422 412
423 /* need to trap SIGURG for SVR4 (Unixware) rlogin */ 413 /* need to trap SIGURG for SVR4 (Unixware) rlogin */
424 /* signal (SIGURG, SIG_DFL); */ 414 /* signal (SIGURG, SIG_DFL); */
425 415
426 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 416 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
417 // TODO: handle this with exceptions and tolerate the memory loss
427 //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); 418 //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler);
428} 419}
429 420
430/* ------------------------------------------------------------------------- * 421/* ------------------------------------------------------------------------- *
431 * SIGNAL HANDLING & EXIT HANDLER * 422 * SIGNAL HANDLING & EXIT HANDLER *
432 * ------------------------------------------------------------------------- */ 423 * ------------------------------------------------------------------------- */
433/* 424/*
434 * Catch a SIGCHLD signal and exit if the direct child has died 425 * Catch a SIGCHLD signal and exit if the direct child has died
435 */ 426 */
436 427
437void rxvt_term::child_exited (int pid) 428void
429rxvt_term::sig_chld (sig_watcher &w)
438{ 430{
439 for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++) 431 // we are being called for every SIGCHLD, not just ours
440 if (pid == (*t)->cmd_pid) 432 int pid;
441 {
442 (*t)->destroy ();
443 break;
444 }
445}
446
447/* ARGSUSED */
448/* EXTPROTO */
449RETSIGTYPE
450rxvt_Child_signal (int sig __attribute__ ((unused)))
451{
452 int pid, save_errno = errno;
453 433
454 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) 434 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0)
455 rxvt_term::child_exited (pid); 435 for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++)
456 436 if (pid == (*t)->cmd_pid)
457 errno = save_errno; 437 {
458} 438 (*t)->destroy ();
459 439 break;
460/* 440 }
461 * Catch a fatal signal and tidy up before quitting
462 */
463/* EXTPROTO */
464RETSIGTYPE
465rxvt_Exit_signal (int sig)
466{
467 signal (sig, SIG_DFL);
468#ifdef DEBUG_CMD
469 rxvt_warn ("caught signal %d, exiting.\n", sig);
470#endif
471 rxvt_clean_exit ();
472 kill (getpid (), sig);
473}
474
475/* INTPROTO */
476int
477rxvt_xerror_handler (Display *display, XErrorEvent *event)
478{
479 if (GET_R->allowedxerror == -1)
480 GET_R->allowedxerror = event->error_code;
481 else
482 {
483 old_xerror_handler (display, event);
484 GET_R->destroy ();
485 }
486
487 return 0;
488} 441}
489 442
490/*----------------------------------------------------------------------*/ 443/*----------------------------------------------------------------------*/
491/* 444/*
492 * Exit gracefully, clearing the utmp entry and restoring tty attributes 445 * Exit gracefully, clearing the utmp entry and restoring tty attributes
493 * TODO: if debugging, this should free up any known resources if we can 446 * TODO: if debugging, this should free up any known resources if we can
494 */ 447 */
495/* EXTPROTO */
496void 448void
497rxvt_clean_exit () 449rxvt_destroy_all ()
498{ 450{
499 // TODO: rxvtd should clean up all ressources 451 // TODO: rxvtd should clean up all ressources
500 if (GET_R) 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);
501 GET_R->destroy (); 479 GET_R->destroy ();
480 }
481
482 return 0;
502} 483}
503 484
504/* ------------------------------------------------------------------------- * 485/* ------------------------------------------------------------------------- *
505 * MEMORY ALLOCATION WRAPPERS * 486 * MEMORY ALLOCATION WRAPPERS *
506 * ------------------------------------------------------------------------- */ 487 * ------------------------------------------------------------------------- */
507/* EXTPROTO */ 488void *
508void *
509rxvt_malloc (size_t size) 489rxvt_malloc (size_t size)
510{ 490{
511 void *p;
512
513 p = malloc (size); 491 void *p = malloc (size);
492
514 if (p) 493 if (!p)
494 rxvt_fatal ("memory allocation failure. aborting.\n");
495
515 return p; 496 return p;
516
517 fprintf (stderr, RESNAME ": memory allocation failure. Aborting");
518 rxvt_clean_exit ();
519 exit (EXIT_FAILURE);
520 /* NOTREACHED */
521} 497}
522 498
523/* EXTPROTO */ 499/* INTPROTO */
524void * 500void *
525rxvt_calloc (size_t number, size_t size) 501rxvt_calloc (size_t number, size_t size)
526{ 502{
527 void *p;
528
529 p = calloc (number, size); 503 void *p = calloc (number, size);
504
530 if (p) 505 if (!p)
506 rxvt_fatal ("memory allocation failure. aborting.\n");
507
531 return p; 508 return p;
532
533 fprintf (stderr, RESNAME ": memory allocation failure. Aborting");
534 rxvt_clean_exit ();
535 exit (EXIT_FAILURE);
536 /* NOTREACHED */
537} 509}
538 510
539/* EXTPROTO */ 511/* INTPROTO */
540void * 512void *
541rxvt_realloc (void *ptr, size_t size) 513rxvt_realloc (void *ptr, size_t size)
542{ 514{
543 void *p;
544
545 if (ptr)
546 p = realloc (ptr, size); 515 void *p = realloc (ptr, size);
547 else 516
548 p = malloc (size);
549 if (p) 517 if (!p)
518 rxvt_fatal ("memory allocation failure. aborting.\n");
519
550 return p; 520 return p;
551
552 fprintf (stderr, RESNAME ": memory allocation failure. Aborting");
553 rxvt_clean_exit ();
554 exit (EXIT_FAILURE);
555 /* NOTREACHED */
556} 521}
557 522
558/* ------------------------------------------------------------------------- * 523/* ------------------------------------------------------------------------- *
559 * PRIVILEGED OPERATIONS * 524 * PRIVILEGED OPERATIONS *
560 * ------------------------------------------------------------------------- */ 525 * ------------------------------------------------------------------------- */
561/* take care of suid/sgid super-user (root) privileges */ 526/* take care of suid/sgid super-user (root) privileges */
562void 527void
563rxvt_term::privileges (int mode) 528rxvt_privileges (rxvt_privaction action)
564{ 529{
530#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
531 static uid_t euid;
532 static gid_t egid;
533#endif
534
565#if ! defined(__CYGWIN32__) 535#if ! defined(__CYGWIN32__)
566# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) 536# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID)
567 /* setreuid () is the poor man's setuid (), seteuid () */ 537 /* setreuid () is the poor man's setuid (), seteuid () */
568# define seteuid(a) setreuid(-1, (a)) 538# define seteuid(a) setreuid(-1, (a))
569# define setegid(a) setregid(-1, (a)) 539# define setegid(a) setregid(-1, (a))
570# define HAVE_SETEUID 540# define HAVE_SETEUID
571# endif 541# endif
572# ifdef HAVE_SETEUID 542# ifdef HAVE_SETEUID
573 switch (mode) 543 switch (action)
574 { 544 {
575 case IGNORE: 545 case IGNORE:
576 /* 546 /*
577 * change effective uid/gid - not real uid/gid - so we can switch 547 * change effective uid/gid - not real uid/gid - so we can switch
578 * back to root later, as required 548 * back to root later, as required
588 seteuid (euid); 558 seteuid (euid);
589 setegid (egid); 559 setegid (egid);
590 break; 560 break;
591 } 561 }
592# else 562# else
593 switch (mode) 563 switch (action)
594 { 564 {
595 case IGNORE: 565 case IGNORE:
596 setuid (getuid ()); 566 setuid (getuid ());
597 setgid (getgid ()); 567 setgid (getgid ());
598 /* FALLTHROUGH */ 568 /* FALLTHROUGH */
605#endif 575#endif
606} 576}
607 577
608#ifdef UTMP_SUPPORT 578#ifdef UTMP_SUPPORT
609void 579void
610rxvt_term::privileged_utmp (char action) 580rxvt_term::privileged_utmp (rxvt_privaction action)
611{ 581{
612 D_MAIN ((stderr, "rxvt_privileged_utmp (%c); waiting for: %c (pid: %d)",
613 action, next_utmp_action, getpid ()));
614 if (next_utmp_action != action || (action != SAVE && action != RESTORE)
615 || (Options & Opt_utmpInhibit) 582 if ((options & Opt_utmpInhibit)
616 || ttydev == NULL || *ttydev == '\0') 583 || !pty.name || !*pty.name)
617 return; 584 return;
618 585
619 privileges (RESTORE); 586 rxvt_privileges (RESTORE);
587
620 if (action == SAVE) 588 if (action == SAVE)
621 {
622 next_utmp_action = RESTORE;
623 makeutent (ttydev, rs[Rs_display_name]); 589 makeutent (pty.name, rs[Rs_display_name]);
624 }
625 else 590 else
626 { /* action == RESTORE */
627 next_utmp_action = IGNORE;
628 cleanutent (); 591 cleanutent ();
629 } 592
630 privileges (IGNORE); 593 rxvt_privileges (IGNORE);
631}
632#endif
633
634#ifndef NO_SETOWNER_TTYDEV
635void
636rxvt_term::privileged_ttydev (char action)
637{
638 D_MAIN ((stderr,
639 "privileged_ttydev (%c); waiting for: %c (pid: %d)",
640 action, next_tty_action, getpid ()));
641 if (next_tty_action != action || (action != SAVE && action != RESTORE)
642 || ttydev == NULL || *ttydev == '\0')
643 return;
644
645 privileges (RESTORE);
646
647 if (action == SAVE)
648 {
649 next_tty_action = RESTORE;
650# ifndef RESET_TTY_TO_COMMON_DEFAULTS
651 /* store original tty status for restoration rxvt_clean_exit () -- rgg 04/12/95 */
652 if (lstat (ttydev, &ttyfd_stat) < 0) /* you lose out */
653 next_tty_action = IGNORE;
654 else
655# endif
656
657 {
658 chown (ttydev, getuid (), ttygid); /* fail silently */
659 chmod (ttydev, ttymode);
660# ifdef HAVE_REVOKE
661 revoke (ttydev);
662# endif
663
664 }
665 }
666 else
667 { /* action == RESTORE */
668 next_tty_action = IGNORE;
669# ifndef RESET_TTY_TO_COMMON_DEFAULTS
670 chmod (ttydev, ttyfd_stat.st_mode);
671 chown (ttydev, ttyfd_stat.st_uid, ttyfd_stat.st_gid);
672# else
673 chmod (ttydev,
674 (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH));
675 chown (ttydev, 0, 0);
676# endif
677
678 }
679
680 privileges (IGNORE);
681
682# ifndef RESET_TTY_TO_COMMON_DEFAULTS
683 D_MAIN ((stderr, "%s \"%s\": mode %03o, uid %d, gid %d",
684 action == RESTORE ? "Restoring" : (action ==
685 SAVE ? "Saving" :
686 "UNKNOWN ERROR for"), ttydev,
687 ttyfd_stat.st_mode, ttyfd_stat.st_uid,
688 ttyfd_stat.st_gid));
689# endif
690} 594}
691#endif 595#endif
692 596
693/*----------------------------------------------------------------------*/ 597/*----------------------------------------------------------------------*/
694/* 598/*
765 669
766 if (scrollbar_visible ()) 670 if (scrollbar_visible ())
767 { 671 {
768 sb_w = scrollbar_TotalWidth (); 672 sb_w = scrollbar_TotalWidth ();
769 szHint.base_width += sb_w; 673 szHint.base_width += sb_w;
770 if (!(Options & Opt_scrollBar_right)) 674 if (!(options & Opt_scrollBar_right))
771 window_vt_x += sb_w; 675 window_vt_x += sb_w;
772 } 676 }
773 677
774 if (menubar_visible ()) 678 if (menubar_visible ())
775 { 679 {
803 { 707 {
804 MIN_IT (TermWin.height, max_height); 708 MIN_IT (TermWin.height, max_height);
805 szHint.height = szHint.base_height + TermWin.height; 709 szHint.height = szHint.base_height + TermWin.height;
806 } 710 }
807 711
808 if (scrollbar_visible () && (Options & Opt_scrollBar_right)) 712 if (scrollbar_visible () && (options & Opt_scrollBar_right))
809 window_sb_x = szHint.width - sb_w; 713 window_sb_x = szHint.width - sb_w;
810 714
811 if (recalc_x) 715 if (recalc_x)
812 szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) 716 szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display))
813 - szHint.width - 2 * TermWin.ext_bwidth); 717 - szHint.width - 2 * TermWin.ext_bwidth);
829 * Called after a window size change. 733 * Called after a window size change.
830 */ 734 */
831void 735void
832rxvt_term::tt_winch () 736rxvt_term::tt_winch ()
833{ 737{
738 if (pty.pty < 0)
739 return;
740
834 struct winsize ws; 741 struct winsize ws;
835
836 if (cmd_fd < 0)
837 return;
838 742
839 ws.ws_col = TermWin.ncol; 743 ws.ws_col = TermWin.ncol;
840 ws.ws_row = TermWin.nrow; 744 ws.ws_row = TermWin.nrow;
841 ws.ws_xpixel = ws.ws_ypixel = 0; 745 ws.ws_xpixel = TermWin.width;
842#ifndef DEBUG_SIZE 746 ws.ws_ypixel = TermWin.height;
843 (void)ioctl (cmd_fd, TIOCSWINSZ, &ws); 747 (void)ioctl (pty.pty, TIOCSWINSZ, &ws);
844#else 748
845 if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0) 749#if 0
846 D_SIZE ((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); 750 // TIOCSWINSZ⎈ is supposed to do this automatically and correctly
847# ifdef SIGWINCH
848 else if (cmd_pid) /* force through to the command */ 751 if (cmd_pid) /* force through to the command */
849 kill (cmd_pid, SIGWINCH); 752 kill (cmd_pid, SIGWINCH);
850# endif
851#endif 753#endif
852} 754}
853 755
854/*----------------------------------------------------------------------*/ 756/*----------------------------------------------------------------------*/
855/* rxvt_change_font () - Switch to a new font */ 757/* set_fonts () - load and set the various fonts
856/* 758/*
857 * init = 1 - initialize 759 * init = 1 - initialize
858 * 760 *
859 * fontname == FONT_UP - switch to bigger font 761 * fontname == FONT_UP - switch to bigger font
860 * fontname == FONT_DN - switch to smaller font 762 * fontname == FONT_DN - switch to smaller font
861 */ 763 */
862bool 764bool
863rxvt_term::change_font (const char *fontname) 765rxvt_term::set_fonts ()
864{ 766{
865 if (fontname == FONT_UP)
866 {
867 // TODO
868 }
869 else if (fontname == FONT_DN)
870 {
871 // TODO
872 }
873 else
874 {
875 rxvt_fontset *fs = new rxvt_fontset (this); 767 rxvt_fontset *fs = new rxvt_fontset (this);
768 rxvt_fontprop prop;
876 769
877 if (fs && fs->populate (fontname ? fontname : "fixed")) 770 if (!fs
771 || !fs->populate (rs[Rs_font] ? rs[Rs_font] : "fixed")
772 || !fs->realize_font (1))
773 {
774 delete fs;
775 return false;
776 }
777
778#if ENABLE_STYLES
779 for (int i = RS_styleCount; --i; )
780 if (TermWin.fontset[i] != TermWin.fontset[0])
781 delete TermWin.fontset[i];
782#endif
783
784 delete TermWin.fontset[0];
785 TermWin.fontset[0] = fs;
786
787 prop = (*fs)[1]->properties ();
788 fs->set_prop (prop);
789
790 TermWin.fwidth = prop.width;
791 TermWin.fheight = prop.height;
792 TermWin.fweight = prop.weight;
793 TermWin.fslant = prop.slant;
794 TermWin.fbase = (*fs)[1]->ascent;
795
796 for (int style = 1; style < 4; style++)
797 {
798#if ENABLE_STYLES
799 const char *res = rs[Rs_font + style];
800
801 if (res && !*res)
802 TermWin.fontset[style] = TermWin.fontset[0];
803 else
878 { 804 {
879 delete TermWin.fontset; 805 TermWin.fontset[style] = fs = new rxvt_fontset (this);
880 TermWin.fontset = fs; 806 rxvt_fontprop prop2 = prop;
881 TermWin.fwidth = fs->base_font ()->width;
882 TermWin.fheight = fs->base_font ()->height;
883 TermWin.fbase = fs->base_font ()->ascent;
884 807
885 if (TermWin.parent[0]) 808 if (res)
809 prop2.weight = prop2.slant = rxvt_fontprop::unset;
810 else
886 { 811 {
887 resize_all_windows (0, 0, 0); 812 res = TermWin.fontset[0]->fontdesc;
888 scr_remap_chars (); 813
889 scr_touch (true); 814 if (SET_STYLE (0, style) & RS_Bold) prop2.weight = rxvt_fontprop::bold;
815 if (SET_STYLE (0, style) & RS_Italic) prop2.slant = rxvt_fontprop::italic;
890 } 816 }
891 817
892 for (unicode_t ch = 0x20; ch <= 0x7f; ch++) 818 fs->populate (res);
893 TermWin.ascii_map [ch - 0x20] = fs->find_font (ch); 819 fs->set_prop (prop2);
894
895 return true;
896 } 820 }
821#else
822 TermWin.fontset[style] = TermWin.fontset[0];
823#endif
824 }
825
826 if (TermWin.parent[0])
897 } 827 {
828 resize_all_windows (0, 0, 0);
829 scr_remap_chars ();
830 scr_touch (true);
831 }
898 832
899 return false; 833 return true;
900}
901
902bool
903rxvt_term::font_up_down (int n, int direction)
904{
905 return false;
906} 834}
907 835
908/*----------------------------------------------------------------------*/ 836/*----------------------------------------------------------------------*/
909/*----------------------------------------------------------------------*/ 837/*----------------------------------------------------------------------*/
910/* xterm sequences - title, iconName, color (exptl) */ 838/* xterm sequences - title, iconName, color (exptl) */
915 char *name; 843 char *name;
916 844
917 if (!XFetchName (display->display, TermWin.parent[0], &name)) 845 if (!XFetchName (display->display, TermWin.parent[0], &name))
918 name = NULL; 846 name = NULL;
919 847
920 if (name == NULL || STRCMP (name, str)) 848 if (name == NULL || strcmp (name, str))
921#endif 849#endif
922 XStoreName (display->display, TermWin.parent[0], str); 850 XStoreName (display->display, TermWin.parent[0], str);
923 851
924#ifdef SMART_WINDOW_TITLE 852#ifdef SMART_WINDOW_TITLE
925 if (name) 853 if (name)
934 char *name; 862 char *name;
935 863
936 if (!XGetIconName (display->display, TermWin.parent[0], &name)) 864 if (!XGetIconName (display->display, TermWin.parent[0], &name))
937 name = NULL; 865 name = NULL;
938 866
939 if (name == NULL || STRCMP (name, str)) 867 if (name == NULL || strcmp (name, str))
940#endif 868#endif
941 XSetIconName (display->display, TermWin.parent[0], str); 869 XSetIconName (display->display, TermWin.parent[0], str);
942 870
943#ifdef SMART_WINDOW_TITLE 871#ifdef SMART_WINDOW_TITLE
944 if (name) 872 if (name)
962 i = atoi (color); 890 i = atoi (color);
963 if (i >= 8 && i <= 15) 891 if (i >= 8 && i <= 15)
964 { /* bright colors */ 892 { /* bright colors */
965 i -= 8; 893 i -= 8;
966# ifndef NO_BRIGHTCOLOR 894# ifndef NO_BRIGHTCOLOR
967 PixColorsFocused[idx] = PixColorsFocused[minBrightCOLOR + i]; 895 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i];
968 SET_PIXCOLOR (idx); 896 SET_PIXCOLOR (idx);
969 goto Done; 897 goto Done;
970# endif 898# endif
971 899
972 } 900 }
973 if (i >= 0 && i <= 7) 901 if (i >= 0 && i <= 7)
974 { /* normal colors */ 902 { /* normal colors */
975 PixColorsFocused[idx] = PixColorsFocused[minCOLOR + i]; 903 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i];
976 SET_PIXCOLOR (idx); 904 SET_PIXCOLOR (idx);
977 goto Done; 905 goto Done;
978 } 906 }
979 } 907 }
980 908
987 * FIXME: should free colors here, but no idea how to do it so instead, 915 * FIXME: should free colors here, but no idea how to do it so instead,
988 * so just keep gobbling up the colormap 916 * so just keep gobbling up the colormap
989 */ 917 */
990# if 0 918# if 0
991 for (i = Color_Black; i <= Color_White; i++) 919 for (i = Color_Black; i <= Color_White; i++)
992 if (PixColors[idx] == PixColors[i]) 920 if (pix_colors[idx] == pix_colors[i])
993 break; 921 break;
994 if (i > Color_White) 922 if (i > Color_White)
995 { 923 {
996 /* fprintf (stderr, "XFreeColors: PixColors [%d] = %lu\n", idx, PixColors [idx]); */ 924 /* fprintf (stderr, "XFreeColors: pix_colors [%d] = %lu\n", idx, pix_colors [idx]); */
997 XFreeColors (display->display, display->cmap, (PixColors + idx), 1, 925 XFreeColors (display->display, display->cmap, (pix_colors + idx), 1,
998 DisplayPlanes (display->display, display->screen)); 926 DisplayPlanes (display->display, display->screen));
999 } 927 }
1000# endif 928# endif
1001 929
1002 PixColorsFocused[idx] = xcol; 930 pix_colors_focused[idx] = xcol;
1003 SET_PIXCOLOR (idx); 931 SET_PIXCOLOR (idx);
1004 932
1005 /* XSetWindowAttributes attr; */ 933 /* XSetWindowAttributes attr; */
1006 /* Cursor cursor; */ 934 /* Cursor cursor; */
1007Done: 935Done:
1008#ifdef OFF_FOCUS_FADING 936#ifdef OFF_FOCUS_FADING
937 if (rs[Rs_fade])
1009 PixColorsUnFocused[idx] = PixColorsFocused[idx].fade (display, atoi (rs[Rs_fade])); 938 pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade]));
1010#endif 939#endif
1011 if (idx == Color_bg && ! (Options & Opt_transparent))
1012 XSetWindowBackground (display->display, TermWin.vt, PixColors[Color_bg]);
1013 940
1014 /* handle Color_BD, scrollbar background, etc. */ 941 /*TODO: handle Color_BD, scrollbar background, etc. */
1015 942
1016 set_colorfgbg ();
1017 recolour_cursor (); 943 recolour_cursor ();
1018 scr_touch (true); 944 scr_recolour ();
1019} 945}
1020 946
1021#else 947#else
1022# define set_window_color (idx,color) ((void)0) 948# define set_window_color (idx,color) ((void)0)
1023#endif /* XTERM_COLOR_CHANGE */ 949#endif /* XTERM_COLOR_CHANGE */
1025void 951void
1026rxvt_term::recolour_cursor () 952rxvt_term::recolour_cursor ()
1027{ 953{
1028 XColor xcol[2]; 954 XColor xcol[2];
1029 955
1030 xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) ? PixColorsFocused[Color_pointer_fg] : PixColorsFocused[Color_fg]; 956 xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg)
1031 xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) ? PixColorsFocused[Color_pointer_bg] : PixColorsFocused[Color_bg]; 957 ? pix_colors_focused[Color_pointer_fg]
958 : pix_colors_focused[Color_fg];
959 xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg)
960 ? pix_colors_focused[Color_pointer_bg]
961 : pix_colors_focused[Color_bg];
962
1032 XQueryColors (display->display, display->cmap, xcol, 2); 963 XQueryColors (display->display, display->cmap, xcol, 2);
1033 XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1); 964 XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1);
1034} 965}
1035 966
1036/*----------------------------------------------------------------------*/ 967/*----------------------------------------------------------------------*/
1038 * find if fg/bg matches any of the normal (low-intensity) colors 969 * find if fg/bg matches any of the normal (low-intensity) colors
1039 */ 970 */
1040void 971void
1041rxvt_term::set_colorfgbg () 972rxvt_term::set_colorfgbg ()
1042{ 973{
1043 unsigned int i; 974 unsigned int i;
1044 const char *xpmb = "\0"; 975 const char *xpmb = "\0";
1045 char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1]; 976 char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1];
1046 977
1047 env_colorfgbg =
1048 (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1); 978 env_colorfgbg = (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1);
1049 STRCPY (fstr, "default"); 979 strcpy (fstr, "default");
1050 STRCPY (bstr, "default"); 980 strcpy (bstr, "default");
1051 for (i = Color_Black; i <= Color_White; i++) 981 for (i = Color_Black; i <= Color_White; i++)
1052 if (PixColors[Color_fg] == PixColors[i]) 982 if (pix_colors[Color_fg] == pix_colors[i])
1053 { 983 {
1054 sprintf (fstr, "%d", (i - Color_Black)); 984 sprintf (fstr, "%d", (i - Color_Black));
1055 break; 985 break;
1056 } 986 }
987
1057 for (i = Color_Black; i <= Color_White; i++) 988 for (i = Color_Black; i <= Color_White; i++)
1058 if (PixColors[Color_bg] == PixColors[i]) 989 if (pix_colors[Color_bg] == pix_colors[i])
1059 { 990 {
1060 sprintf (bstr, "%d", (i - Color_Black)); 991 sprintf (bstr, "%d", (i - Color_Black));
1061#ifdef XPM_BACKGROUND 992#ifdef XPM_BACKGROUND
1062 xpmb = "default;"; 993 xpmb = "default;";
1063#endif 994#endif
1064 break; 995 break;
1065 } 996 }
1066 997
1067 sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); 998 sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr);
1068
1069#ifndef NO_BRIGHTCOLOR
1070 colorfgbg = DEFAULT_RSTYLE;
1071 for (i = minCOLOR; i <= maxCOLOR; i++)
1072 {
1073 if (PixColors[Color_fg] == PixColors[i])
1074 colorfgbg = SET_FGCOLOR (colorfgbg, i);
1075 if (PixColors[Color_bg] == PixColors[i])
1076 colorfgbg = SET_BGCOLOR (colorfgbg, i);
1077 }
1078#endif
1079} 999}
1080 1000
1081/*----------------------------------------------------------------------*/ 1001/*----------------------------------------------------------------------*/
1082/* 1002/*
1083 * Colour determination for low colour displays, routine from 1003 * Colour determination for low colour displays, routine from
1231 if (width == 0) 1151 if (width == 0)
1232 width = wattr.width - szHint.base_width; 1152 width = wattr.width - szHint.base_width;
1233 if (height == 0) 1153 if (height == 0)
1234 height = wattr.height - szHint.base_height; 1154 height = wattr.height - szHint.base_height;
1235 } 1155 }
1156
1236 if (width != TermWin.width || height != TermWin.height) 1157 if (width != TermWin.width || height != TermWin.height)
1237 { 1158 {
1238 width += szHint.base_width; 1159 width += szHint.base_width;
1239 height += szHint.base_height; 1160 height += szHint.base_height;
1240 resize_all_windows (width, height, 0); 1161 resize_all_windows (width, height, 0);
1245 * - X INPUT METHOD ROUTINES - * 1166 * - X INPUT METHOD ROUTINES - *
1246 * -------------------------------------------------------------------- */ 1167 * -------------------------------------------------------------------- */
1247#ifdef USE_XIM 1168#ifdef USE_XIM
1248 1169
1249void 1170void
1171rxvt_term::im_set_color (unsigned long &fg, unsigned long &bg)
1172{
1173 fg = pix_colors[Color_fg];
1174 bg = pix_colors[Color_bg];
1175}
1176
1177void
1250rxvt_term::im_set_size (XRectangle *size) 1178rxvt_term::im_set_size (XRectangle &size)
1251{ 1179{
1180 // the int_bwidth terms make no sense to me
1252 size->x = TermWin.int_bwidth; 1181 size.x = TermWin.int_bwidth;
1253 size->y = TermWin.int_bwidth; 1182 size.y = TermWin.int_bwidth;
1254 size->width = Width2Pixel (TermWin.ncol); 1183 size.width = Width2Pixel (TermWin.ncol) + TermWin.int_bwidth;
1255 size->height = Height2Pixel (TermWin.nrow); 1184 size.height = Height2Pixel (TermWin.nrow) + TermWin.int_bwidth;
1256} 1185}
1257 1186
1258void 1187void
1259rxvt_term::im_set_color (unsigned long *fg, unsigned long *bg) 1188rxvt_term::im_set_preedit_area (XRectangle &preedit_rect,
1189 XRectangle &status_rect,
1190 const XRectangle &needed_rect)
1260{ 1191{
1261 *fg = PixColors[Color_fg]; 1192 preedit_rect.x = needed_rect.width;
1262 *bg = PixColors[Color_bg]; 1193 preedit_rect.y = 0;
1194 preedit_rect.width = Width2Pixel (TermWin.ncol) - needed_rect.width + 1;
1195 preedit_rect.height = TermWin.fheight;
1196
1197 status_rect.x = 0;
1198 status_rect.y = 0;
1199 status_rect.width = needed_rect.width ? needed_rect.width : Width2Pixel (TermWin.ncol) + 1;
1200 status_rect.height = TermWin.fheight;
1263} 1201}
1264 1202
1265/* Checking whether input method is running. */ 1203/* Checking whether input method is running. */
1266bool 1204bool
1267rxvt_term::IMisRunning () 1205rxvt_term::IMisRunning ()
1268{ 1206{
1269 char *p; 1207 char *p;
1270 Atom atom; 1208 Atom atom;
1271 Window win; 1209 Window win;
1272 char server[IMBUFSIZ]; 1210 char server[IMBUFSIZ];
1273 1211
1274 /* get current locale modifier */ 1212 /* get current locale modifier */
1275 if ((p = XSetLocaleModifiers (NULL)) != NULL) 1213 if ((p = XSetLocaleModifiers (NULL)) != NULL)
1276 { 1214 {
1277 STRCPY (server, "@server="); 1215 strcpy (server, "@server=");
1278 STRNCAT (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */ 1216 strncat (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */
1217
1279 if ((p = STRCHR (server + 1, '@')) != NULL) /* first one only */ 1218 if ((p = strchr (server + 1, '@')) != NULL) /* first one only */
1280 *p = '\0'; 1219 *p = '\0';
1281 1220
1282 atom = XInternAtom (display->display, server, False); 1221 atom = XInternAtom (display->display, server, False);
1283 win = XGetSelectionOwner (display->display, atom); 1222 win = XGetSelectionOwner (display->display, atom);
1223
1284 if (win != None) 1224 if (win != None)
1285 return True; 1225 return True;
1286 } 1226 }
1227
1287 return False; 1228 return False;
1288} 1229}
1289 1230
1290void 1231void
1291rxvt_term::IMSendSpot () 1232rxvt_term::IMSendSpot ()
1292{ 1233{
1293 XPoint spot; 1234 XPoint nspot;
1294 XVaNestedList preedit_attr; 1235 XVaNestedList preedit_attr;
1295 1236
1296 if (Input_Context == NULL 1237 if (!Input_Context
1238 || !TermWin.focus
1297 || !TermWin.focus || ! (input_style & XIMPreeditPosition) 1239 || !(input_style & XIMPreeditPosition))
1298 || ! (event_type == KeyPress
1299 || event_type == Expose
1300 || event_type == NoExpose
1301 || event_type == SelectionNotify
1302 || event_type == ButtonRelease || event_type == FocusIn)
1303 || !IMisRunning ())
1304 return; 1240 return;
1305 1241
1306 im_set_position (&spot); 1242 im_set_position (nspot);
1243
1244 if (nspot.x == spot.x && nspot.y == spot.y)
1245 return;
1246
1247 spot = nspot;
1307 1248
1308 preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); 1249 preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL);
1309 XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); 1250 XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL);
1310 XFree (preedit_attr); 1251 XFree (preedit_attr);
1311} 1252}
1312 1253
1313void 1254void
1314rxvt_term::im_set_preedit_area (XRectangle * preedit_rect, XRectangle * status_rect,
1315 XRectangle * needed_rect)
1316{
1317 int mbh, vtx = 0;
1318
1319 if (scrollbar_visible () && ! (Options & Opt_scrollBar_right))
1320 vtx = scrollbar_TotalWidth ();
1321
1322 mbh = menubar_visible () ? menuBar_TotalHeight () : 0;
1323 mbh -= TermWin.lineSpace;
1324
1325 preedit_rect->x = needed_rect->width + vtx;
1326 preedit_rect->y = Height2Pixel (TermWin.nrow - 1) + mbh;
1327
1328 preedit_rect->width = Width2Pixel (TermWin.ncol + 1) - needed_rect->width + vtx;
1329 preedit_rect->height = Height2Pixel (1);
1330
1331 status_rect->x = vtx;
1332 status_rect->y = Height2Pixel (TermWin.nrow - 1) + mbh;
1333
1334 status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel (TermWin.ncol + 1);
1335 status_rect->height = Height2Pixel (1);
1336}
1337
1338void
1339rxvt_term::im_destroy () 1255rxvt_term::im_destroy ()
1340{ 1256{
1341 if (Input_Context)
1342 {
1343 XDestroyIC (Input_Context);
1344 Input_Context = NULL;
1345 }
1346
1347 if (input_method) 1257 if (input_method)
1348 { 1258 {
1259 if (Input_Context && input_method->xim)
1260 XDestroyIC (Input_Context);
1261
1349 display->put_xim (input_method); 1262 display->put_xim (input_method);
1350 input_method = 0; 1263 input_method = 0;
1351 } 1264 }
1265
1266 Input_Context = 0;
1352} 1267}
1353 1268
1354/* 1269/*
1355 * Try to open a XIM with the current modifiers, then see if we can 1270 * Try to open a XIM with the current modifiers, then see if we can
1356 * open a suitable preedit type 1271 * open a suitable preedit type
1357 */ 1272 */
1358bool 1273bool
1359rxvt_term::IM_get_IC (const char *modifiers) 1274rxvt_term::IM_get_IC (const char *modifiers)
1360{ 1275{
1361 int i, j, found; 1276 int i, j, found;
1362 XIM xim; 1277 XIM xim;
1363 XPoint spot; 1278 XPoint spot;
1364 XRectangle rect, status_rect, needed_rect; 1279 XRectangle rect, status_rect, needed_rect;
1365 unsigned long fg, bg; 1280 unsigned long fg, bg;
1366 const char *p; 1281 const char *p;
1367 char **s; 1282 char **s;
1368 XIMStyles *xim_styles; 1283 XIMStyles *xim_styles;
1369 XVaNestedList preedit_attr, status_attr;
1370 1284
1371 if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) 1285 if (! ((p = XSetLocaleModifiers (modifiers)) && *p))
1372 return false; 1286 return false;
1373 1287
1374 D_MAIN ((stderr, "rxvt_IM_get_IC ()")); 1288 D_MAIN ((stderr, "rxvt_IM_get_IC ()"));
1375 input_method = display->get_xim (locale, modifiers); 1289 input_method = display->get_xim (locale, modifiers);
1376 if (input_method == NULL) 1290 if (input_method == NULL)
1377 return false; 1291 return false;
1378 1292
1379 xim = input_method->xim; 1293 xim = input_method->xim;
1294 spot.x = spot.y = -1;
1380 1295
1381 xim_styles = NULL; 1296 xim_styles = NULL;
1382 if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) 1297 if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL)
1383 || !xim_styles || !xim_styles->count_styles) 1298 || !xim_styles || !xim_styles->count_styles)
1384 { 1299 {
1385 display->put_xim (input_method); 1300 im_destroy ();
1386 return false; 1301 return false;
1387 } 1302 }
1388 1303
1389 p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root"; 1304 p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root,None";
1390 s = rxvt_splitcommastring (p); 1305 s = rxvt_splitcommastring (p);
1306
1391 for (i = found = 0; !found && s[i]; i++) 1307 for (i = found = 0; !found && s[i]; i++)
1392 { 1308 {
1393 if (!STRCMP (s[i], "OverTheSpot")) 1309 if (!strcmp (s[i], "OverTheSpot"))
1394 input_style = (XIMPreeditPosition | XIMStatusNothing); 1310 input_style = (XIMPreeditPosition | XIMStatusNothing);
1395 else if (!STRCMP (s[i], "OffTheSpot")) 1311 else if (!strcmp (s[i], "OffTheSpot"))
1396 input_style = (XIMPreeditArea | XIMStatusArea); 1312 input_style = (XIMPreeditArea | XIMStatusArea);
1397 else if (!STRCMP (s[i], "Root")) 1313 else if (!strcmp (s[i], "Root"))
1398 input_style = (XIMPreeditNothing | XIMStatusNothing); 1314 input_style = (XIMPreeditNothing | XIMStatusNothing);
1315 else if (!strcmp (s[i], "None"))
1316 input_style = (XIMPreeditNone | XIMStatusNone);
1399 1317
1400 for (j = 0; j < xim_styles->count_styles; j++) 1318 for (j = 0; j < xim_styles->count_styles; j++)
1401 if (input_style == xim_styles->supported_styles[j]) 1319 if (input_style == xim_styles->supported_styles[j])
1402 { 1320 {
1403 found = 1; 1321 found = 1;
1411 free (s); 1329 free (s);
1412 XFree (xim_styles); 1330 XFree (xim_styles);
1413 1331
1414 if (!found) 1332 if (!found)
1415 { 1333 {
1416 display->put_xim (input_method); 1334 im_destroy ();
1417 return false; 1335 return false;
1418 } 1336 }
1419 1337
1420 preedit_attr = status_attr = NULL; 1338 XFontSet fs = 0;
1339 XVaNestedList preedit_attr = 0, status_attr = 0;
1340
1341 if (input_style & (XIMPreeditPosition | XIMPreeditArea))
1342 {
1343 // fake us a font-set, please
1344 char **missing_charset_list;
1345 int missing_charset_count;
1346 char *def_string;
1347 char pat[512];
1348
1349 sprintf (pat,
1350 "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
1351 "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
1352 "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
1353 "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
1354 "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
1355 "*",
1356 TermWin.fheight,
1357 TermWin.fheight + 1, TermWin.fheight - 1,
1358 TermWin.fheight - 2, TermWin.fheight + 2);
1359
1360 fs = XCreateFontSet (display->display, pat,
1361 &missing_charset_list, &missing_charset_count, &def_string);
1362
1363 if (missing_charset_list)
1364 XFreeStringList (missing_charset_list);
1365
1366 if (!fs)
1367 {
1368 input_style &= ~(XIMPreeditPosition | XIMPreeditArea);
1369 rxvt_warn ("unable to create fontset for input method, try \"-pt Root\". Continuing.\n");
1370 }
1371 }
1421 1372
1422 if (input_style & XIMPreeditPosition) 1373 if (input_style & XIMPreeditPosition)
1423 { 1374 {
1424 im_set_size (&rect); 1375 im_set_size (rect);
1425 im_set_position (&spot); 1376 im_set_position (spot);
1426 im_set_color (&fg, &bg); 1377 im_set_color (fg, bg);
1427 1378
1428 preedit_attr = XVaCreateNestedList (0, XNArea, &rect, 1379 preedit_attr = XVaCreateNestedList (0,
1380 XNForeground, fg,
1381 XNBackground, bg,
1382 XNArea, &rect,
1429 XNSpotLocation, &spot, 1383 XNSpotLocation, &spot,
1430 XNForeground, fg, XNBackground, bg,
1431 //XNFontSet, TermWin.fontset, 1384 XNFontSet, fs,
1432 NULL); 1385 NULL);
1433 } 1386 }
1434 else if (input_style & XIMPreeditArea) 1387 else if (input_style & XIMPreeditArea)
1435 { 1388 {
1436 im_set_color (&fg, &bg); 1389 im_set_color (fg, bg);
1437 1390
1438 /* 1391 /*
1439 * The necessary width of preedit area is unknown 1392 * The necessary width of preedit area is unknown
1440 * until create input context. 1393 * until create input context.
1441 */ 1394 */
1442 needed_rect.width = 0; 1395 needed_rect.width = 0;
1443
1444 im_set_preedit_area (&rect, &status_rect, &needed_rect); 1396 im_set_preedit_area (rect, status_rect, needed_rect);
1445 1397
1446 preedit_attr = XVaCreateNestedList (0, XNArea, &rect, 1398 preedit_attr = XVaCreateNestedList (0,
1399 XNForeground, fg,
1447 XNForeground, fg, XNBackground, bg, 1400 XNBackground, bg,
1401 XNArea, &rect,
1402 XNFontSet, fs,
1403 NULL);
1404 status_attr = XVaCreateNestedList (0,
1405 XNForeground, fg,
1406 XNBackground, bg,
1407 XNArea, &status_rect,
1448 //XNFontSet, TermWin.fontset, 1408 XNFontSet, fs,
1449 NULL); 1409 NULL);
1450 status_attr = XVaCreateNestedList (0, XNArea, &status_rect,
1451 XNForeground, fg, XNBackground, bg,
1452 //XNFontSet, TermWin.fontset,
1453 NULL);
1454 } 1410 }
1455 1411
1456 Input_Context = XCreateIC (xim, XNInputStyle, input_style, 1412 Input_Context = XCreateIC (xim,
1413 XNInputStyle, input_style,
1457 XNClientWindow, TermWin.parent[0], 1414 XNClientWindow, TermWin.vt,
1458 XNFocusWindow, TermWin.parent[0], 1415 XNFocusWindow, TermWin.parent[0],
1459 preedit_attr ? XNPreeditAttributes : NULL, 1416 preedit_attr ? XNPreeditAttributes : NULL,
1460 preedit_attr, 1417 preedit_attr,
1461 status_attr ? XNStatusAttributes : NULL, 1418 status_attr ? XNStatusAttributes : NULL,
1462 status_attr, NULL); 1419 status_attr, NULL);
1420
1463 if (preedit_attr) XFree (preedit_attr); 1421 if (preedit_attr) XFree (preedit_attr);
1464 if (status_attr) XFree (status_attr); 1422 if (status_attr) XFree (status_attr);
1423 if (fs) XFreeFontSet (display->display, fs);
1465 1424
1466 if (Input_Context == NULL) 1425 if (Input_Context == NULL)
1467 { 1426 {
1468 rxvt_warn ("failed to create input context, continuing without XIM.\n"); 1427 rxvt_warn ("failed to create input context, continuing without XIM.\n");
1469 display->put_xim (input_method); 1428 im_destroy ();
1470 return false; 1429 return false;
1471 } 1430 }
1472 1431
1473 if (input_style & XIMPreeditArea) 1432 if (input_style & XIMPreeditArea)
1474 IMSetStatusPosition (); 1433 IMSetStatusPosition ();
1504 s = rxvt_splitcommastring (p); 1463 s = rxvt_splitcommastring (p);
1505 for (i = 0; s[i]; i++) 1464 for (i = 0; s[i]; i++)
1506 { 1465 {
1507 if (*s[i]) 1466 if (*s[i])
1508 { 1467 {
1509 STRCPY (buf, "@im="); 1468 strcpy (buf, "@im=");
1510 STRNCAT (buf, s[i], IMBUFSIZ - 5); 1469 strncat (buf, s[i], IMBUFSIZ - 5);
1511 if (IM_get_IC (buf)) 1470 if (IM_get_IC (buf))
1512 { 1471 {
1513 found = true; 1472 found = true;
1514 break; 1473 break;
1515 } 1474 }
1539} 1498}
1540 1499
1541void 1500void
1542rxvt_term::IMSetStatusPosition () 1501rxvt_term::IMSetStatusPosition ()
1543{ 1502{
1544 XRectangle preedit_rect, status_rect, *needed_rect; 1503 XRectangle preedit_rect, status_rect, *needed_rect;
1545 XVaNestedList preedit_attr, status_attr; 1504 XVaNestedList preedit_attr, status_attr;
1546 1505
1547 if (Input_Context == NULL 1506 if (!Input_Context
1507 || !TermWin.focus
1548 || !TermWin.focus || ! (input_style & XIMPreeditArea) 1508 || !(input_style & XIMPreeditArea)
1549 || !IMisRunning ()) 1509 || !IMisRunning ())
1550 return; 1510 return;
1551 1511
1552 /* Getting the necessary width of preedit area */ 1512 /* Getting the necessary width of preedit area */
1553 status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL); 1513 status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL);
1554 XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL); 1514 XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL);
1555 XFree (status_attr); 1515 XFree (status_attr);
1556 1516
1557 im_set_preedit_area (&preedit_rect, &status_rect, needed_rect); 1517 im_set_preedit_area (preedit_rect, status_rect, *needed_rect);
1518 XFree (needed_rect);
1558 1519
1559 preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL); 1520 preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL);
1560 status_attr = XVaCreateNestedList (0, XNArea, &status_rect, NULL); 1521 status_attr = XVaCreateNestedList (0, XNArea, &status_rect, NULL);
1561 1522
1562 XSetICValues (Input_Context, 1523 XSetICValues (Input_Context,
1563 XNPreeditAttributes, preedit_attr, 1524 XNPreeditAttributes, preedit_attr,
1564 XNStatusAttributes, status_attr, NULL); 1525 XNStatusAttributes, status_attr, NULL);
1565 1526
1566 XFree (preedit_attr); 1527 XFree (preedit_attr);
1567 XFree (status_attr); 1528 XFree (status_attr);
1568} 1529}
1569#endif /* USE_XIM */ 1530#endif /* USE_XIM */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines