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.28 by pcg, Mon Feb 9 22:45:29 2004 UTC vs.
Revision 1.33 by pcg, Fri Feb 13 13:28:17 2004 UTC

93 pointer_ev (this, &rxvt_term::pointer_cb), 93 pointer_ev (this, &rxvt_term::pointer_cb),
94#endif 94#endif
95 check_ev (this, &rxvt_term::check_cb), 95 check_ev (this, &rxvt_term::check_cb),
96 destroy_ev (this, &rxvt_term::destroy_cb), 96 destroy_ev (this, &rxvt_term::destroy_cb),
97 pty_ev (this, &rxvt_term::pty_cb), 97 pty_ev (this, &rxvt_term::pty_cb),
98 incr_ev (this, &rxvt_term::incr_cb) 98 incr_ev (this, &rxvt_term::incr_cb),
99#ifdef USE_XIM
100 im_ev (this, &rxvt_term::im_cb)
101#endif
99{ 102{
100 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; 103 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base;
101} 104}
102 105
103rxvt_term::~rxvt_term () 106rxvt_term::~rxvt_term ()
104{ 107{
108 if (cmd_fd >= 0)
109 close (cmd_fd);
110
105 scr_release (); 111 scr_release ();
106 112
113 free (env_windowid);
114 free (env_display);
115 free (env_term);
116 free (env_colorfgbg);
107 free (locale); 117 free (locale);
108 free (codeset); 118 free (codeset);
109 119
110#ifndef NO_SETOWNER_TTYDEV 120#ifndef NO_SETOWNER_TTYDEV
111 privileged_ttydev (RESTORE); 121 privileged_ttydev (RESTORE);
112#endif 122#endif
113#ifdef UTMP_SUPPORT 123#ifdef UTMP_SUPPORT
114 privileged_utmp (RESTORE); 124 privileged_utmp (RESTORE);
115#endif 125#endif
116#ifdef USE_XIM
117 if (Input_Context)
118 {
119 XDestroyIC (Input_Context);
120 Input_Context = NULL;
121 }
122#endif
123
124 if (TermWin.parent[0])
125 XDestroyWindow (display->display, TermWin.parent[0]);
126 126
127 // TODO: free pixcolours, colours should become part of rxvt_display 127 // TODO: free pixcolours, colours should become part of rxvt_display
128 128
129 delete PixColors; 129 delete PixColors;
130 delete TermWin.fontset;
130 131
131 if (cmd_fd >= 0) 132 displays.put (display);
132 close (cmd_fd);
133 133
134 delete envv;
135 delete argv;
136}
137
138void
139rxvt_term::destroy ()
140{
134 if (display) 141 if (display)
135 displays.release (display);
136}
137
138void
139rxvt_term::destroy ()
140{
141 if (display)
142 { 142 {
143 if (TermWin.parent[0])
144 XDestroyWindow (display->display, TermWin.parent[0]);
145
146 rootwin_ev.stop (display);
143 termwin_ev.stop (display); 147 termwin_ev.stop (display);
144 vt_ev.stop (display); 148 vt_ev.stop (display);
149
150#ifdef USE_XIM
151 im_destroy ();
152 im_ev.stop (display);
153#endif
145#ifdef HAVE_SCROLLBARS 154#ifdef HAVE_SCROLLBARS
146 scrollbar_ev.stop (display); 155 scrollbar_ev.stop (display);
147#endif 156#endif
148#ifdef MENUBAR 157#ifdef MENUBAR
149 menubar_ev.stop (display); 158 menubar_ev.stop (display);
172 181
173 delete this; 182 delete this;
174} 183}
175 184
176/*----------------------------------------------------------------------*/ 185/*----------------------------------------------------------------------*/
177/* rxvt_init() */ 186/* rxvt_init () */
178/* LIBPROTO */ 187/* LIBPROTO */
179rxvt_t 188rxvt_t
180rxvt_init (int argc, const char *const *argv) 189rxvt_init (int argc, const char *const *argv)
181{ 190{
182 SET_R (new rxvt_term); 191 SET_R (new rxvt_term);
188 } 197 }
189 198
190 return GET_R; 199 return GET_R;
191} 200}
192 201
193static int (*old_xerror_handler)(Display *dpy, XErrorEvent *event); 202static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event);
194 203
195void 204void
196rxvt_init_signals () 205rxvt_init_signals ()
197{ 206{
198 /* install exit handler for cleanup */ 207 /* install exit handler for cleanup */
199#if 0 208#if 0
200#ifdef HAVE_ATEXIT 209#ifdef HAVE_ATEXIT
201 atexit(rxvt_clean_exit); 210 atexit (rxvt_clean_exit);
202#else 211#else
203#endif 212#endif
204#endif 213#endif
205 214
206 struct sigaction sa; 215 struct sigaction sa;
257 Gr_reset (); /* reset graphics */ 266 Gr_reset (); /* reset graphics */
258#endif 267#endif
259 268
260#if 0 269#if 0
261#ifdef DEBUG_X 270#ifdef DEBUG_X
262 XSynchronize(display->display, True); 271 XSynchronize (display->display, True);
263#endif 272#endif
264#endif 273#endif
265 274
266#ifdef HAVE_SCROLLBARS 275#ifdef HAVE_SCROLLBARS
267 if (Options & Opt_scrollBar) 276 if (Options & Opt_scrollBar)
268 resize_scrollbar (); /* create and map scrollbar */ 277 resize_scrollbar (); /* create and map scrollbar */
269#endif 278#endif
270#if (MENUBAR_MAX) 279#if (MENUBAR_MAX)
271 if (menubar_visible(r)) 280 if (menubar_visible (r))
272 XMapWindow (display->display, menuBar.win); 281 XMapWindow (display->display, menuBar.win);
273#endif 282#endif
274#ifdef TRANSPARENT 283#ifdef TRANSPARENT
275 if (Options & Opt_transparent) 284 if (Options & Opt_transparent)
276 { 285 {
282 rootwin_ev.start (display, display->root); 291 rootwin_ev.start (display, display->root);
283 292
284 XMapWindow (display->display, TermWin.vt); 293 XMapWindow (display->display, TermWin.vt);
285 XMapWindow (display->display, TermWin.parent[0]); 294 XMapWindow (display->display, TermWin.parent[0]);
286 295
287 init_env ();
288 init_command (cmd_argv); 296 init_command (cmd_argv);
289 297
290 pty_ev.start (cmd_fd, EVENT_READ); 298 pty_ev.start (cmd_fd, EVENT_READ);
291 299
292 check_ev.start (); 300 check_ev.start ();
301 * Catch a SIGCHLD signal and exit if the direct child has died 309 * Catch a SIGCHLD signal and exit if the direct child has died
302 */ 310 */
303/* ARGSUSED */ 311/* ARGSUSED */
304/* EXTPROTO */ 312/* EXTPROTO */
305RETSIGTYPE 313RETSIGTYPE
306rxvt_Child_signal(int sig __attribute__ ((unused))) 314rxvt_Child_signal (int sig __attribute__ ((unused)))
307{ 315{
308 int pid, save_errno = errno; 316 int pid, save_errno = errno;
309 while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR) 317 while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR)
310 ; 318 ;
311 errno = save_errno; 319 errno = save_errno;
319/* 327/*
320 * Catch a fatal signal and tidy up before quitting 328 * Catch a fatal signal and tidy up before quitting
321 */ 329 */
322/* EXTPROTO */ 330/* EXTPROTO */
323RETSIGTYPE 331RETSIGTYPE
324rxvt_Exit_signal(int sig) 332rxvt_Exit_signal (int sig)
325{ 333{
326 signal(sig, SIG_DFL); 334 signal (sig, SIG_DFL);
327#ifdef DEBUG_CMD 335#ifdef DEBUG_CMD
328 rxvt_print_error("signal %d", sig); 336 rxvt_print_error ("signal %d", sig);
329#endif 337#endif
330 rxvt_clean_exit(); 338 rxvt_clean_exit ();
331 kill(getpid(), sig); 339 kill (getpid (), sig);
332} 340}
333 341
334/* INTPROTO */ 342/* INTPROTO */
335int 343int
336rxvt_xerror_handler (Display *display, XErrorEvent *event) 344rxvt_xerror_handler (Display *display, XErrorEvent *event)
353 */ 361 */
354/* EXTPROTO */ 362/* EXTPROTO */
355void 363void
356rxvt_clean_exit () 364rxvt_clean_exit ()
357{ 365{
366 // TODO: rxvtd should clean up all ressources
367 if (GET_R)
358 GET_R->destroy (); 368 GET_R->destroy ();
359} 369}
360 370
361/* ------------------------------------------------------------------------- * 371/* ------------------------------------------------------------------------- *
362 * MEMORY ALLOCATION WRAPPERS * 372 * MEMORY ALLOCATION WRAPPERS *
363 * ------------------------------------------------------------------------- */ 373 * ------------------------------------------------------------------------- */
364/* EXTPROTO */ 374/* EXTPROTO */
365void * 375void *
366rxvt_malloc(size_t size) 376rxvt_malloc (size_t size)
367{ 377{
368 void *p; 378 void *p;
369 379
370 p = malloc(size); 380 p = malloc (size);
371 if (p) 381 if (p)
372 return p; 382 return p;
373 383
374 fprintf(stderr, APL_NAME ": memory allocation failure. Aborting"); 384 fprintf (stderr, APL_NAME ": memory allocation failure. Aborting");
375 rxvt_clean_exit(); 385 rxvt_clean_exit ();
376 exit(EXIT_FAILURE); 386 exit (EXIT_FAILURE);
377 /* NOTREACHED */ 387 /* NOTREACHED */
378} 388}
379 389
380/* EXTPROTO */ 390/* EXTPROTO */
381void * 391void *
382rxvt_calloc(size_t number, size_t size) 392rxvt_calloc (size_t number, size_t size)
383{ 393{
384 void *p; 394 void *p;
385 395
386 p = calloc(number, size); 396 p = calloc (number, size);
387 if (p) 397 if (p)
388 return p; 398 return p;
389 399
390 fprintf(stderr, APL_NAME ": memory allocation failure. Aborting"); 400 fprintf (stderr, APL_NAME ": memory allocation failure. Aborting");
391 rxvt_clean_exit(); 401 rxvt_clean_exit ();
392 exit(EXIT_FAILURE); 402 exit (EXIT_FAILURE);
393 /* NOTREACHED */ 403 /* NOTREACHED */
394} 404}
395 405
396/* EXTPROTO */ 406/* EXTPROTO */
397void * 407void *
398rxvt_realloc(void *ptr, size_t size) 408rxvt_realloc (void *ptr, size_t size)
399{ 409{
400 void *p; 410 void *p;
401 411
402 if (ptr) 412 if (ptr)
403 p = realloc(ptr, size); 413 p = realloc (ptr, size);
404 else 414 else
405 p = malloc(size); 415 p = malloc (size);
406 if (p) 416 if (p)
407 return p; 417 return p;
408 418
409 fprintf(stderr, APL_NAME ": memory allocation failure. Aborting"); 419 fprintf (stderr, APL_NAME ": memory allocation failure. Aborting");
410 rxvt_clean_exit(); 420 rxvt_clean_exit ();
411 exit(EXIT_FAILURE); 421 exit (EXIT_FAILURE);
412 /* NOTREACHED */ 422 /* NOTREACHED */
413} 423}
414 424
415/* ------------------------------------------------------------------------- * 425/* ------------------------------------------------------------------------- *
416 * PRIVILEGED OPERATIONS * 426 * PRIVILEGED OPERATIONS *
419void 429void
420rxvt_term::privileges (int mode) 430rxvt_term::privileges (int mode)
421{ 431{
422#if ! defined(__CYGWIN32__) 432#if ! defined(__CYGWIN32__)
423# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) 433# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID)
424 /* setreuid() is the poor man's setuid(), seteuid() */ 434 /* setreuid () is the poor man's setuid (), seteuid () */
425# define seteuid(a) setreuid(-1, (a)) 435# define seteuid(a) setreuid(-1, (a))
426# define setegid(a) setregid(-1, (a)) 436# define setegid(a) setregid(-1, (a))
427# define HAVE_SETEUID 437# define HAVE_SETEUID
428# endif 438# endif
429# ifdef HAVE_SETEUID 439# ifdef HAVE_SETEUID
432 case IGNORE: 442 case IGNORE:
433 /* 443 /*
434 * change effective uid/gid - not real uid/gid - so we can switch 444 * change effective uid/gid - not real uid/gid - so we can switch
435 * back to root later, as required 445 * back to root later, as required
436 */ 446 */
437 seteuid(getuid()); 447 seteuid (getuid ());
438 setegid(getgid()); 448 setegid (getgid ());
439 break; 449 break;
440 case SAVE: 450 case SAVE:
441 euid = geteuid(); 451 euid = geteuid ();
442 egid = getegid(); 452 egid = getegid ();
443 break; 453 break;
444 case RESTORE: 454 case RESTORE:
445 seteuid(euid); 455 seteuid (euid);
446 setegid(egid); 456 setegid (egid);
447 break; 457 break;
448 } 458 }
449# else 459# else
450 switch (mode) 460 switch (mode)
451 { 461 {
452 case IGNORE: 462 case IGNORE:
453 setuid(getuid()); 463 setuid (getuid ());
454 setgid(getgid()); 464 setgid (getgid ());
455 /* FALLTHROUGH */ 465 /* FALLTHROUGH */
456 case SAVE: 466 case SAVE:
457 /* FALLTHROUGH */ 467 /* FALLTHROUGH */
458 case RESTORE: 468 case RESTORE:
459 break; 469 break;
464 474
465#ifdef UTMP_SUPPORT 475#ifdef UTMP_SUPPORT
466void 476void
467rxvt_term::privileged_utmp (char action) 477rxvt_term::privileged_utmp (char action)
468{ 478{
469 D_MAIN((stderr, "rxvt_privileged_utmp(%c); waiting for: %c (pid: %d)", 479 D_MAIN ((stderr, "rxvt_privileged_utmp (%c); waiting for: %c (pid: %d)",
470 action, next_utmp_action, getpid())); 480 action, next_utmp_action, getpid ()));
471 if (next_utmp_action != action || (action != SAVE && action != RESTORE) 481 if (next_utmp_action != action || (action != SAVE && action != RESTORE)
472 || (Options & Opt_utmpInhibit) 482 || (Options & Opt_utmpInhibit)
473 || ttydev == NULL || *ttydev == '\0') 483 || ttydev == NULL || *ttydev == '\0')
474 return; 484 return;
475 485
490 500
491#ifndef NO_SETOWNER_TTYDEV 501#ifndef NO_SETOWNER_TTYDEV
492void 502void
493rxvt_term::privileged_ttydev (char action) 503rxvt_term::privileged_ttydev (char action)
494{ 504{
495 D_MAIN((stderr, 505 D_MAIN ((stderr,
496 "privileged_ttydev (%c); waiting for: %c (pid: %d)", 506 "privileged_ttydev (%c); waiting for: %c (pid: %d)",
497 action, next_tty_action, getpid())); 507 action, next_tty_action, getpid ()));
498 if (next_tty_action != action || (action != SAVE && action != RESTORE) 508 if (next_tty_action != action || (action != SAVE && action != RESTORE)
499 || ttydev == NULL || *ttydev == '\0') 509 || ttydev == NULL || *ttydev == '\0')
500 return; 510 return;
501 511
502 privileges (RESTORE); 512 privileges (RESTORE);
503 513
504 if (action == SAVE) 514 if (action == SAVE)
505 { 515 {
506 next_tty_action = RESTORE; 516 next_tty_action = RESTORE;
507# ifndef RESET_TTY_TO_COMMON_DEFAULTS 517# ifndef RESET_TTY_TO_COMMON_DEFAULTS
508 /* store original tty status for restoration rxvt_clean_exit() -- rgg 04/12/95 */ 518 /* store original tty status for restoration rxvt_clean_exit () -- rgg 04/12/95 */
509 if (lstat(ttydev, &ttyfd_stat) < 0) /* you lose out */ 519 if (lstat (ttydev, &ttyfd_stat) < 0) /* you lose out */
510 next_tty_action = IGNORE; 520 next_tty_action = IGNORE;
511 else 521 else
512# endif 522# endif
513 523
514 { 524 {
515 chown(ttydev, getuid(), ttygid); /* fail silently */ 525 chown (ttydev, getuid (), ttygid); /* fail silently */
516 chmod(ttydev, ttymode); 526 chmod (ttydev, ttymode);
517# ifdef HAVE_REVOKE 527# ifdef HAVE_REVOKE
518 revoke(ttydev); 528 revoke (ttydev);
519# endif 529# endif
520 530
521 } 531 }
522 } 532 }
523 else 533 else
524 { /* action == RESTORE */ 534 { /* action == RESTORE */
525 next_tty_action = IGNORE; 535 next_tty_action = IGNORE;
526# ifndef RESET_TTY_TO_COMMON_DEFAULTS 536# ifndef RESET_TTY_TO_COMMON_DEFAULTS
527 chmod(ttydev, ttyfd_stat.st_mode); 537 chmod (ttydev, ttyfd_stat.st_mode);
528 chown(ttydev, ttyfd_stat.st_uid, ttyfd_stat.st_gid); 538 chown (ttydev, ttyfd_stat.st_uid, ttyfd_stat.st_gid);
529# else 539# else
530 chmod(ttydev, 540 chmod (ttydev,
531 (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)); 541 (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH));
532 chown(ttydev, 0, 0); 542 chown (ttydev, 0, 0);
533# endif 543# endif
534 544
535 } 545 }
536 546
537 privileges (IGNORE); 547 privileges (IGNORE);
538 548
539# ifndef RESET_TTY_TO_COMMON_DEFAULTS 549# ifndef RESET_TTY_TO_COMMON_DEFAULTS
540 D_MAIN((stderr, "%s \"%s\": mode %03o, uid %d, gid %d", 550 D_MAIN ((stderr, "%s \"%s\": mode %03o, uid %d, gid %d",
541 action == RESTORE ? "Restoring" : (action == 551 action == RESTORE ? "Restoring" : (action ==
542 SAVE ? "Saving" : 552 SAVE ? "Saving" :
543 "UNKNOWN ERROR for"), ttydev, 553 "UNKNOWN ERROR for"), ttydev,
544 ttyfd_stat.st_mode, ttyfd_stat.st_uid, 554 ttyfd_stat.st_mode, ttyfd_stat.st_uid,
545 ttyfd_stat.st_gid)); 555 ttyfd_stat.st_gid));
558 short recalc_x, recalc_y; 568 short recalc_x, recalc_y;
559 int x, y, sb_w, mb_h, flags; 569 int x, y, sb_w, mb_h, flags;
560 unsigned int w, h; 570 unsigned int w, h;
561 unsigned int max_width, max_height; 571 unsigned int max_width, max_height;
562 572
563 D_SIZE((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", 573 D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d",
564 TermWin.ncol, TermWin.nrow, szHint.width, 574 TermWin.ncol, TermWin.nrow, szHint.width,
565 szHint.height)); 575 szHint.height));
566 szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; 576 szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity;
567 szHint.win_gravity = NorthWestGravity; 577 szHint.win_gravity = NorthWestGravity;
568 /* szHint.min_aspect.x = szHint.min_aspect.y = 1; */ 578 /* szHint.min_aspect.x = szHint.min_aspect.y = 1; */
571 flags = 0; 581 flags = 0;
572 if (!parsed_geometry) 582 if (!parsed_geometry)
573 { 583 {
574 parsed_geometry = 1; 584 parsed_geometry = 1;
575 if (rs[Rs_geometry]) 585 if (rs[Rs_geometry])
576 flags = XParseGeometry(rs[Rs_geometry], &x, &y, &w, &h); 586 flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h);
577 if (flags & WidthValue) 587 if (flags & WidthValue)
578 { 588 {
579 TermWin.ncol = BOUND_POSITIVE_INT16(w); 589 TermWin.ncol = BOUND_POSITIVE_INT16 (w);
580 szHint.flags |= USSize; 590 szHint.flags |= USSize;
581 } 591 }
582 if (flags & HeightValue) 592 if (flags & HeightValue)
583 { 593 {
584 TermWin.nrow = BOUND_POSITIVE_INT16(h); 594 TermWin.nrow = BOUND_POSITIVE_INT16 (h);
585 szHint.flags |= USSize; 595 szHint.flags |= USSize;
586 } 596 }
587 if (flags & XValue) 597 if (flags & XValue)
588 { 598 {
589 szHint.x = x; 599 szHint.x = x;
618 628
619 sb_w = mb_h = 0; 629 sb_w = mb_h = 0;
620 window_vt_x = window_vt_y = 0; 630 window_vt_x = window_vt_y = 0;
621 if (scrollbar_visible ()) 631 if (scrollbar_visible ())
622 { 632 {
623 sb_w = scrollbar_TotalWidth(); 633 sb_w = scrollbar_TotalWidth ();
624 szHint.base_width += sb_w; 634 szHint.base_width += sb_w;
625 if (!(Options & Opt_scrollBar_right)) 635 if (! (Options & Opt_scrollBar_right))
626 window_vt_x = sb_w; 636 window_vt_x = sb_w;
627 } 637 }
628 if (menubar_visible ()) 638 if (menubar_visible ())
629 { 639 {
630 mb_h = menuBar_TotalHeight(); 640 mb_h = menuBar_TotalHeight ();
631 szHint.base_height += mb_h; 641 szHint.base_height += mb_h;
632 window_vt_y = mb_h; 642 window_vt_y = mb_h;
633 } 643 }
634 szHint.width_inc = TermWin.fwidth; 644 szHint.width_inc = TermWin.fwidth;
635 szHint.height_inc = TermWin.fheight; 645 szHint.height_inc = TermWin.fheight;
641 szHint.width = width; 651 szHint.width = width;
642 TermWin.width = width - szHint.base_width; 652 TermWin.width = width - szHint.base_width;
643 } 653 }
644 else 654 else
645 { 655 {
646 MIN_IT(TermWin.width, max_width); 656 MIN_IT (TermWin.width, max_width);
647 szHint.width = szHint.base_width + TermWin.width; 657 szHint.width = szHint.base_width + TermWin.width;
648 } 658 }
649 if (height && height - szHint.base_height < max_height) 659 if (height && height - szHint.base_height < max_height)
650 { 660 {
651 szHint.height = height; 661 szHint.height = height;
652 TermWin.height = height - szHint.base_height; 662 TermWin.height = height - szHint.base_height;
653 } 663 }
654 else 664 else
655 { 665 {
656 MIN_IT(TermWin.height, max_height); 666 MIN_IT (TermWin.height, max_height);
657 szHint.height = szHint.base_height + TermWin.height; 667 szHint.height = szHint.base_height + TermWin.height;
658 } 668 }
659 if (scrollbar_visible () && (Options & Opt_scrollBar_right)) 669 if (scrollbar_visible () && (Options & Opt_scrollBar_right))
660 window_sb_x = szHint.width - sb_w; 670 window_sb_x = szHint.width - sb_w;
661 671
666 szHint.y += (DisplayHeight (display->display, DefaultScreen (display->display)) 676 szHint.y += (DisplayHeight (display->display, DefaultScreen (display->display))
667 - szHint.height - 2 * TermWin.ext_bwidth); 677 - szHint.height - 2 * TermWin.ext_bwidth);
668 678
669 TermWin.ncol = TermWin.width / TermWin.fwidth; 679 TermWin.ncol = TermWin.width / TermWin.fwidth;
670 TermWin.nrow = TermWin.height / TermWin.fheight; 680 TermWin.nrow = TermWin.height / TermWin.fheight;
671 D_SIZE((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", 681 D_SIZE ((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d",
672 TermWin.ncol, TermWin.nrow, szHint.width, 682 TermWin.ncol, TermWin.nrow, szHint.width,
673 szHint.height)); 683 szHint.height));
674 return; 684 return;
675} 685}
676 686
692 ws.ws_xpixel = ws.ws_ypixel = 0; 702 ws.ws_xpixel = ws.ws_ypixel = 0;
693#ifndef DEBUG_SIZE 703#ifndef DEBUG_SIZE
694 (void)ioctl (cmd_fd, TIOCSWINSZ, &ws); 704 (void)ioctl (cmd_fd, TIOCSWINSZ, &ws);
695#else 705#else
696 if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0) 706 if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0)
697 D_SIZE((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); 707 D_SIZE ((stderr, "Failed to send TIOCSWINSZ to fd %d", fd));
698# ifdef SIGWINCH 708# ifdef SIGWINCH
699 else if (cmd_pid) /* force through to the command */ 709 else if (cmd_pid) /* force through to the command */
700 kill (cmd_pid, SIGWINCH); 710 kill (cmd_pid, SIGWINCH);
701# endif 711# endif
702#endif 712#endif
703} 713}
704 714
705/*----------------------------------------------------------------------*/ 715/*----------------------------------------------------------------------*/
706/* rxvt_change_font() - Switch to a new font */ 716/* rxvt_change_font () - Switch to a new font */
707/* 717/*
708 * init = 1 - initialize 718 * init = 1 - initialize
709 * 719 *
710 * fontname == FONT_UP - switch to bigger font 720 * fontname == FONT_UP - switch to bigger font
711 * fontname == FONT_DN - switch to smaller font 721 * fontname == FONT_DN - switch to smaller font
723/* xterm sequences - title, iconName, color (exptl) */ 733/* xterm sequences - title, iconName, color (exptl) */
724void 734void
725rxvt_term::set_title (const char *str) 735rxvt_term::set_title (const char *str)
726{ 736{
727#ifndef SMART_WINDOW_TITLE 737#ifndef SMART_WINDOW_TITLE
728 XStoreName(display->display, TermWin.parent[0], str); 738 XStoreName (display->display, TermWin.parent[0], str);
729#else 739#else
730 char *name; 740 char *name;
731 741
732 if (XFetchName(display->display, TermWin.parent[0], &name) == 0) 742 if (XFetchName (display->display, TermWin.parent[0], &name) == 0)
733 name = NULL; 743 name = NULL;
734 if (name == NULL || STRCMP(name, str)) 744 if (name == NULL || STRCMP (name, str))
735 XStoreName(display->display, TermWin.parent[0], str); 745 XStoreName (display->display, TermWin.parent[0], str);
736 if (name) 746 if (name)
737 XFree(name); 747 XFree (name);
738#endif 748#endif
739} 749}
740 750
741void 751void
742rxvt_term::set_iconName (const char *str) 752rxvt_term::set_iconName (const char *str)
743{ 753{
744#ifndef SMART_WINDOW_TITLE 754#ifndef SMART_WINDOW_TITLE
745 XSetIconName(display->display, TermWin.parent[0], str); 755 XSetIconName (display->display, TermWin.parent[0], str);
746#else 756#else
747 char *name; 757 char *name;
748 758
749 if (XGetIconName(display->display, TermWin.parent[0], &name)) 759 if (XGetIconName (display->display, TermWin.parent[0], &name))
750 name = NULL; 760 name = NULL;
751 if (name == NULL || STRCMP(name, str)) 761 if (name == NULL || STRCMP (name, str))
752 XSetIconName(display->display, TermWin.parent[0], str); 762 XSetIconName (display->display, TermWin.parent[0], str);
753 if (name) 763 if (name)
754 XFree(name); 764 XFree (name);
755#endif 765#endif
756} 766}
757 767
758#ifdef XTERM_COLOR_CHANGE 768#ifdef XTERM_COLOR_CHANGE
759void 769void
764 774
765 if (color == NULL || *color == '\0') 775 if (color == NULL || *color == '\0')
766 return; 776 return;
767 777
768 /* handle color aliases */ 778 /* handle color aliases */
769 if (isdigit(*color)) 779 if (isdigit (*color))
770 { 780 {
771 i = atoi(color); 781 i = atoi (color);
772 if (i >= 8 && i <= 15) 782 if (i >= 8 && i <= 15)
773 { /* bright colors */ 783 { /* bright colors */
774 i -= 8; 784 i -= 8;
775# ifndef NO_BRIGHTCOLOR 785# ifndef NO_BRIGHTCOLOR
776 PixColors[idx] = PixColors[minBrightCOLOR + i]; 786 PixColors[idx] = PixColors[minBrightCOLOR + i];
777 SET_PIXCOLOR(idx); 787 SET_PIXCOLOR (idx);
778 goto Done; 788 goto Done;
779# endif 789# endif
780 790
781 } 791 }
782 if (i >= 0 && i <= 7) 792 if (i >= 0 && i <= 7)
783 { /* normal colors */ 793 { /* normal colors */
784 PixColors[idx] = PixColors[minCOLOR + i]; 794 PixColors[idx] = PixColors[minCOLOR + i];
785 SET_PIXCOLOR(idx); 795 SET_PIXCOLOR (idx);
786 goto Done; 796 goto Done;
787 } 797 }
788 } 798 }
789 if (!rXParseAllocColor (& xcol, color)) 799 if (!rXParseAllocColor (& xcol, color))
790 return; 800 return;
799 if (PixColors[idx] == PixColors[i]) 809 if (PixColors[idx] == PixColors[i])
800 break; 810 break;
801 if (i > Color_White) 811 if (i > Color_White)
802 { 812 {
803 /* fprintf (stderr, "XFreeColors: PixColors [%d] = %lu\n", idx, PixColors [idx]); */ 813 /* fprintf (stderr, "XFreeColors: PixColors [%d] = %lu\n", idx, PixColors [idx]); */
804 XFreeColors(display->display, XCMAP, (PixColors + idx), 1, 814 XFreeColors (display->display, XCMAP, (PixColors + idx), 1,
805 DisplayPlanes(display->display, display->screen)); 815 DisplayPlanes (display->display, display->screen));
806 } 816 }
807# endif 817# endif
808 818
809 PixColors[idx] = xcol; 819 PixColors[idx] = xcol;
810 SET_PIXCOLOR(idx); 820 SET_PIXCOLOR (idx);
811 821
812 /* XSetWindowAttributes attr; */ 822 /* XSetWindowAttributes attr; */
813 /* Cursor cursor; */ 823 /* Cursor cursor; */
814Done: 824Done:
815 if (idx == Color_bg && !(Options & Opt_transparent)) 825 if (idx == Color_bg && ! (Options & Opt_transparent))
816 XSetWindowBackground(display->display, TermWin.vt, 826 XSetWindowBackground (display->display, TermWin.vt,
817 PixColors[Color_bg]); 827 PixColors[Color_bg]);
818 828
819 /* handle Color_BD, scrollbar background, etc. */ 829 /* handle Color_BD, scrollbar background, etc. */
820 830
821 set_colorfgbg (); 831 set_colorfgbg ();
835 rxvt_color xcol[2]; 845 rxvt_color xcol[2];
836 846
837 xcol[0] = PixColors[Color_pointer]; 847 xcol[0] = PixColors[Color_pointer];
838 xcol[1] = PixColors[Color_bg]; 848 xcol[1] = PixColors[Color_bg];
839 XQueryColors (display->display, XCMAP, xcol, 2); 849 XQueryColors (display->display, XCMAP, xcol, 2);
840 XRecolorCursor (display->display, TermWin_cursor, &(xcol[0]), &(xcol[1])); 850 XRecolorCursor (display->display, TermWin_cursor, & (xcol[0]), & (xcol[1]));
841#endif 851#endif
842} 852}
843 853
844/*----------------------------------------------------------------------*/ 854/*----------------------------------------------------------------------*/
845/* 855/*
848void 858void
849rxvt_term::set_colorfgbg () 859rxvt_term::set_colorfgbg ()
850{ 860{
851 unsigned int i; 861 unsigned int i;
852 const char *xpmb = "\0"; 862 const char *xpmb = "\0";
853 char fstr[sizeof("default") + 1], bstr[sizeof("default") + 1]; 863 char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1];
854 864
855 env_colorfgbg = 865 env_colorfgbg =
856 (char *)rxvt_malloc(sizeof("COLORFGBG=default;default;bg") + 1); 866 (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1);
857 STRCPY(fstr, "default"); 867 STRCPY (fstr, "default");
858 STRCPY(bstr, "default"); 868 STRCPY (bstr, "default");
859 for (i = Color_Black; i <= Color_White; i++) 869 for (i = Color_Black; i <= Color_White; i++)
860 if (PixColors[Color_fg] == PixColors[i]) 870 if (PixColors[Color_fg] == PixColors[i])
861 { 871 {
862 sprintf(fstr, "%d", (i - Color_Black)); 872 sprintf (fstr, "%d", (i - Color_Black));
863 break; 873 break;
864 } 874 }
865 for (i = Color_Black; i <= Color_White; i++) 875 for (i = Color_Black; i <= Color_White; i++)
866 if (PixColors[Color_bg] == PixColors[i]) 876 if (PixColors[Color_bg] == PixColors[i])
867 { 877 {
868 sprintf(bstr, "%d", (i - Color_Black)); 878 sprintf (bstr, "%d", (i - Color_Black));
869#ifdef XPM_BACKGROUND 879#ifdef XPM_BACKGROUND
870 xpmb = "default;"; 880 xpmb = "default;";
871#endif 881#endif
872 break; 882 break;
873 } 883 }
884
874 sprintf(env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); 885 sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr);
875 putenv(env_colorfgbg);
876 886
877#ifndef NO_BRIGHTCOLOR 887#ifndef NO_BRIGHTCOLOR
878 colorfgbg = DEFAULT_RSTYLE; 888 colorfgbg = DEFAULT_RSTYLE;
879 for (i = minCOLOR; i <= maxCOLOR; i++) 889 for (i = minCOLOR; i <= maxCOLOR; i++)
880 { 890 {
881 if (PixColors[Color_fg] == PixColors[i]) 891 if (PixColors[Color_fg] == PixColors[i])
882 colorfgbg = SET_FGCOLOR(colorfgbg, i); 892 colorfgbg = SET_FGCOLOR (colorfgbg, i);
883 if (PixColors[Color_bg] == PixColors[i]) 893 if (PixColors[Color_bg] == PixColors[i])
884 colorfgbg = SET_BGCOLOR(colorfgbg, i); 894 colorfgbg = SET_BGCOLOR (colorfgbg, i);
885 } 895 }
886#endif 896#endif
887} 897}
888 898
889/*----------------------------------------------------------------------*/ 899/*----------------------------------------------------------------------*/
895int 905int
896rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) 906rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour)
897{ 907{
898 if (!screen_in_out->set (display, colour)) 908 if (!screen_in_out->set (display, colour))
899 { 909 {
900 rxvt_print_error("can't allocate colour: %s", colour); 910 rxvt_print_error ("can't allocate colour: %s", colour);
901 return false; 911 return false;
902 } 912 }
903 913
904 return true; 914 return true;
905} 915}
1011 TermWin.ncol = prev_ncol; // save b/c scr_blank_screen_mem uses this 1021 TermWin.ncol = prev_ncol; // save b/c scr_blank_screen_mem uses this
1012 curr_screen = scr_change_screen (PRIMARY); 1022 curr_screen = scr_change_screen (PRIMARY);
1013 TermWin.ncol = ncol; 1023 TermWin.ncol = ncol;
1014 } 1024 }
1015 1025
1016 scr_reset(); 1026 scr_reset ();
1017 1027
1018 if (curr_screen >= 0) /* this is not the first time through */ 1028 if (curr_screen >= 0) /* this is not the first time through */
1019 { 1029 {
1020 scr_change_screen (curr_screen); 1030 scr_change_screen (curr_screen);
1021 selection_check (old_ncol != TermWin.ncol ? 4 : 0); 1031 selection_check (old_ncol != TermWin.ncol ? 4 : 0);
1039{ 1049{
1040 XWindowAttributes wattr; 1050 XWindowAttributes wattr;
1041 1051
1042 if (width == 0 || height == 0) 1052 if (width == 0 || height == 0)
1043 { 1053 {
1044 XGetWindowAttributes(display->display, display->root, &wattr); 1054 XGetWindowAttributes (display->display, display->root, &wattr);
1045 if (width == 0) 1055 if (width == 0)
1046 width = wattr.width - szHint.base_width; 1056 width = wattr.width - szHint.base_width;
1047 if (height == 0) 1057 if (height == 0)
1048 height = wattr.height - szHint.base_height; 1058 height = wattr.height - szHint.base_height;
1049 } 1059 }
1057 1067
1058/* -------------------------------------------------------------------- * 1068/* -------------------------------------------------------------------- *
1059 * - X INPUT METHOD ROUTINES - * 1069 * - X INPUT METHOD ROUTINES - *
1060 * -------------------------------------------------------------------- */ 1070 * -------------------------------------------------------------------- */
1061#ifdef USE_XIM 1071#ifdef USE_XIM
1072
1062void 1073void
1063rxvt_term::set_size (XRectangle *size) 1074rxvt_term::im_set_size (XRectangle *size)
1064{ 1075{
1065 size->x = TermWin.int_bwidth; 1076 size->x = TermWin.int_bwidth;
1066 size->y = TermWin.int_bwidth; 1077 size->y = TermWin.int_bwidth;
1067 size->width = Width2Pixel(TermWin.ncol); 1078 size->width = Width2Pixel (TermWin.ncol);
1068 size->height = Height2Pixel(TermWin.nrow); 1079 size->height = Height2Pixel (TermWin.nrow);
1069} 1080}
1070 1081
1071void 1082void
1072rxvt_term::set_color (unsigned long *fg, unsigned long *bg) 1083rxvt_term::im_set_color (unsigned long *fg, unsigned long *bg)
1073{ 1084{
1074 *fg = PixColors[Color_fg]; 1085 *fg = PixColors[Color_fg];
1075 *bg = PixColors[Color_bg]; 1086 *bg = PixColors[Color_bg];
1076} 1087}
1077 1088
1083 Atom atom; 1094 Atom atom;
1084 Window win; 1095 Window win;
1085 char server[IMBUFSIZ]; 1096 char server[IMBUFSIZ];
1086 1097
1087 /* get current locale modifier */ 1098 /* get current locale modifier */
1088 if ((p = XSetLocaleModifiers(NULL)) != NULL) 1099 if ((p = XSetLocaleModifiers (NULL)) != NULL)
1089 { 1100 {
1090 STRCPY(server, "@server="); 1101 STRCPY (server, "@server=");
1091 STRNCAT(server, &(p[4]), IMBUFSIZ - 9); /* skip "@im=" */ 1102 STRNCAT (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */
1092 if ((p = STRCHR(server + 1, '@')) != NULL) /* first one only */ 1103 if ((p = STRCHR (server + 1, '@')) != NULL) /* first one only */
1093 *p = '\0'; 1104 *p = '\0';
1094 1105
1095 atom = XInternAtom(display->display, server, False); 1106 atom = XInternAtom (display->display, server, False);
1096 win = XGetSelectionOwner(display->display, atom); 1107 win = XGetSelectionOwner (display->display, atom);
1097 if (win != None) 1108 if (win != None)
1098 return True; 1109 return True;
1099 } 1110 }
1100 return False; 1111 return False;
1101} 1112}
1105{ 1116{
1106 XPoint spot; 1117 XPoint spot;
1107 XVaNestedList preedit_attr; 1118 XVaNestedList preedit_attr;
1108 1119
1109 if (Input_Context == NULL 1120 if (Input_Context == NULL
1110 || !TermWin.focus || !(input_style & XIMPreeditPosition) 1121 || !TermWin.focus || ! (input_style & XIMPreeditPosition)
1111 || !(event_type == KeyPress 1122 || ! (event_type == KeyPress
1112 || event_type == Expose 1123 || event_type == Expose
1113 || event_type == NoExpose 1124 || event_type == NoExpose
1114 || event_type == SelectionNotify 1125 || event_type == SelectionNotify
1115 || event_type == ButtonRelease || event_type == FocusIn) 1126 || event_type == ButtonRelease || event_type == FocusIn)
1116 || !IMisRunning ()) 1127 || !IMisRunning ())
1117 return; 1128 return;
1118 1129
1119 set_position (&spot); 1130 im_set_position (&spot);
1120 1131
1121 preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL); 1132 preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL);
1122 XSetICValues(Input_Context, XNPreeditAttributes, preedit_attr, NULL); 1133 XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL);
1123 XFree(preedit_attr); 1134 XFree (preedit_attr);
1124} 1135}
1125 1136
1126void 1137void
1127rxvt_term::set_preedit_area (XRectangle * preedit_rect, XRectangle * status_rect, 1138rxvt_term::im_set_preedit_area (XRectangle * preedit_rect, XRectangle * status_rect,
1128 XRectangle * needed_rect) 1139 XRectangle * needed_rect)
1129{ 1140{
1130 int mbh, vtx = 0; 1141 int mbh, vtx = 0;
1131 1142
1132 if (scrollbar_visible () && !(Options & Opt_scrollBar_right)) 1143 if (scrollbar_visible () && ! (Options & Opt_scrollBar_right))
1133 vtx = scrollbar_TotalWidth(); 1144 vtx = scrollbar_TotalWidth ();
1134 1145
1135 mbh = menubar_visible () ? menuBar_TotalHeight() : 0; 1146 mbh = menubar_visible () ? menuBar_TotalHeight () : 0;
1136 mbh -= TermWin.lineSpace; 1147 mbh -= TermWin.lineSpace;
1137 1148
1138 preedit_rect->x = needed_rect->width + vtx; 1149 preedit_rect->x = needed_rect->width + vtx;
1139 preedit_rect->y = Height2Pixel(TermWin.nrow - 1) + mbh; 1150 preedit_rect->y = Height2Pixel (TermWin.nrow - 1) + mbh;
1140 1151
1141 preedit_rect->width = Width2Pixel(TermWin.ncol + 1) - needed_rect->width + vtx; 1152 preedit_rect->width = Width2Pixel (TermWin.ncol + 1) - needed_rect->width + vtx;
1142 preedit_rect->height = Height2Pixel(1); 1153 preedit_rect->height = Height2Pixel (1);
1143 1154
1144 status_rect->x = vtx; 1155 status_rect->x = vtx;
1145 status_rect->y = Height2Pixel(TermWin.nrow - 1) + mbh; 1156 status_rect->y = Height2Pixel (TermWin.nrow - 1) + mbh;
1146 1157
1147 status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel(TermWin.ncol + 1); 1158 status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel (TermWin.ncol + 1);
1148 status_rect->height = Height2Pixel(1); 1159 status_rect->height = Height2Pixel (1);
1149} 1160}
1150 1161
1151/* ARGSUSED */
1152/* EXTPROTO */
1153void 1162void
1154rxvt_IMDestroyCallback(XIM xim __attribute__ ((unused)), XPointer client_data 1163rxvt_term::im_destroy ()
1155 __attribute__ ((unused)), XPointer call_data
1156 __attribute__ ((unused)))
1157{ 1164{
1165 if (Input_Context)
1166 {
1167 XDestroyIC (Input_Context);
1158 GET_R->Input_Context = NULL; 1168 Input_Context = NULL;
1159 /* To avoid Segmentation Fault in C locale: Solaris only? */ 1169 }
1160 if (STRCMP (GET_R->locale, "C")) 1170
1161 XRegisterIMInstantiateCallback(GET_R->display->display, NULL, NULL, NULL, 1171 if (input_method)
1162 rxvt_IMInstantiateCallback, NULL); 1172 {
1173 display->put_xim (input_method);
1174 input_method = 0;
1175 }
1163} 1176}
1164 1177
1165/* 1178/*
1166 * Try to open a XIM with the current modifiers, then see if we can 1179 * Try to open a XIM with the current modifiers, then see if we can
1167 * open a suitable preedit type 1180 * open a suitable preedit type
1168 */ 1181 */
1169bool 1182bool
1170rxvt_term::IM_get_IC () 1183rxvt_term::IM_get_IC (const char *modifiers)
1171{ 1184{
1172 int i, j, found; 1185 int i, j, found;
1173 XIM xim; 1186 XIM xim;
1174 XPoint spot; 1187 XPoint spot;
1175 XRectangle rect, status_rect, needed_rect; 1188 XRectangle rect, status_rect, needed_rect;
1176 unsigned long fg, bg; 1189 unsigned long fg, bg;
1177 const char *p; 1190 const char *p;
1178 char **s; 1191 char **s;
1179 XIMStyles *xim_styles; 1192 XIMStyles *xim_styles;
1180 XVaNestedList preedit_attr, status_attr; 1193 XVaNestedList preedit_attr, status_attr;
1181 XIMCallback ximcallback;
1182 1194
1195 if (! ((p = XSetLocaleModifiers (modifiers)) && *p))
1196 return false;
1197
1183 D_MAIN((stderr, "rxvt_IM_get_IC()")); 1198 D_MAIN ((stderr, "rxvt_IM_get_IC ()"));
1184 xim = XOpenIM (display->display, NULL, NULL, NULL); 1199 input_method = display->get_xim (locale, modifiers);
1185 if (xim == NULL) 1200 if (input_method == NULL)
1186 return False; 1201 return false;
1202
1203 xim = input_method->xim;
1187 1204
1188 xim_styles = NULL; 1205 xim_styles = NULL;
1189 if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) 1206 if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL)
1190 || !xim_styles || !xim_styles->count_styles) 1207 || !xim_styles || !xim_styles->count_styles)
1191 { 1208 {
1192 XCloseIM(xim); 1209 display->put_xim (input_method);
1193 return False; 1210 return false;
1194 } 1211 }
1195 1212
1196 p = rs[Rs_preeditType] ? rs[Rs_preeditType] 1213 p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root";
1197 : "OverTheSpot,OffTheSpot,Root";
1198 s = rxvt_splitcommastring(p); 1214 s = rxvt_splitcommastring (p);
1199 for (i = found = 0; !found && s[i]; i++) 1215 for (i = found = 0; !found && s[i]; i++)
1200 { 1216 {
1201 if (!STRCMP(s[i], "OverTheSpot")) 1217 if (!STRCMP (s[i], "OverTheSpot"))
1202 input_style = (XIMPreeditPosition | XIMStatusNothing); 1218 input_style = (XIMPreeditPosition | XIMStatusNothing);
1203 else if (!STRCMP(s[i], "OffTheSpot")) 1219 else if (!STRCMP (s[i], "OffTheSpot"))
1204 input_style = (XIMPreeditArea | XIMStatusArea); 1220 input_style = (XIMPreeditArea | XIMStatusArea);
1205 else if (!STRCMP(s[i], "Root")) 1221 else if (!STRCMP (s[i], "Root"))
1206 input_style = (XIMPreeditNothing | XIMStatusNothing); 1222 input_style = (XIMPreeditNothing | XIMStatusNothing);
1207 1223
1208 for (j = 0; j < xim_styles->count_styles; j++) 1224 for (j = 0; j < xim_styles->count_styles; j++)
1209 if (input_style == xim_styles->supported_styles[j]) 1225 if (input_style == xim_styles->supported_styles[j])
1210 { 1226 {
1211 found = 1; 1227 found = 1;
1212 break; 1228 break;
1213 } 1229 }
1214 } 1230 }
1231
1215 for (i = 0; s[i]; i++) 1232 for (i = 0; s[i]; i++)
1216 free(s[i]); 1233 free (s[i]);
1234
1217 free(s); 1235 free (s);
1218 XFree(xim_styles); 1236 XFree (xim_styles);
1219 1237
1220 if (!found) 1238 if (!found)
1221 { 1239 {
1222 XCloseIM(xim); 1240 display->put_xim (input_method);
1223 return False; 1241 return false;
1224 } 1242 }
1225
1226 ximcallback.callback = rxvt_IMDestroyCallback;
1227
1228 /* XXX: not sure why we need this (as well as IC one below) */
1229 XSetIMValues(xim, XNDestroyCallback, &ximcallback, NULL);
1230 1243
1231 preedit_attr = status_attr = NULL; 1244 preedit_attr = status_attr = NULL;
1232 1245
1233 if (input_style & XIMPreeditPosition) 1246 if (input_style & XIMPreeditPosition)
1234 { 1247 {
1235 set_size (&rect); 1248 im_set_size (&rect);
1236 set_position (&spot); 1249 im_set_position (&spot);
1237 set_color (&fg, &bg); 1250 im_set_color (&fg, &bg);
1238 1251
1239 preedit_attr = XVaCreateNestedList(0, XNArea, &rect, 1252 preedit_attr = XVaCreateNestedList (0, XNArea, &rect,
1240 XNSpotLocation, &spot, 1253 XNSpotLocation, &spot,
1241 XNForeground, fg, XNBackground, bg, 1254 XNForeground, fg, XNBackground, bg,
1242 //XNFontSet, TermWin.fontset, 1255 //XNFontSet, TermWin.fontset,
1243 NULL); 1256 NULL);
1244 } 1257 }
1245 else if (input_style & XIMPreeditArea) 1258 else if (input_style & XIMPreeditArea)
1246 { 1259 {
1247 set_color (&fg, &bg); 1260 im_set_color (&fg, &bg);
1248 1261
1249 /* 1262 /*
1250 * The necessary width of preedit area is unknown 1263 * The necessary width of preedit area is unknown
1251 * until create input context. 1264 * until create input context.
1252 */ 1265 */
1253 needed_rect.width = 0; 1266 needed_rect.width = 0;
1254 1267
1255 set_preedit_area(&rect, &status_rect, &needed_rect); 1268 im_set_preedit_area (&rect, &status_rect, &needed_rect);
1256 1269
1257 preedit_attr = XVaCreateNestedList(0, XNArea, &rect, 1270 preedit_attr = XVaCreateNestedList (0, XNArea, &rect,
1258 XNForeground, fg, XNBackground, bg, 1271 XNForeground, fg, XNBackground, bg,
1259 //XNFontSet, TermWin.fontset, 1272 //XNFontSet, TermWin.fontset,
1260 NULL); 1273 NULL);
1261 status_attr = XVaCreateNestedList(0, XNArea, &status_rect, 1274 status_attr = XVaCreateNestedList (0, XNArea, &status_rect,
1262 XNForeground, fg, XNBackground, bg, 1275 XNForeground, fg, XNBackground, bg,
1263 //XNFontSet, TermWin.fontset, 1276 //XNFontSet, TermWin.fontset,
1264 NULL); 1277 NULL);
1265 } 1278 }
1279
1266 Input_Context = XCreateIC(xim, XNInputStyle, input_style, 1280 Input_Context = XCreateIC (xim, XNInputStyle, input_style,
1267 XNClientWindow, TermWin.parent[0], 1281 XNClientWindow, TermWin.parent[0],
1268 XNFocusWindow, TermWin.parent[0], 1282 XNFocusWindow, TermWin.parent[0],
1269 XNDestroyCallback, &ximcallback,
1270 preedit_attr ? XNPreeditAttributes : NULL, 1283 preedit_attr ? XNPreeditAttributes : NULL,
1271 preedit_attr, 1284 preedit_attr,
1272 status_attr ? XNStatusAttributes : NULL, 1285 status_attr ? XNStatusAttributes : NULL,
1273 status_attr, NULL); 1286 status_attr, NULL);
1274 if (preedit_attr) 1287 if (preedit_attr) XFree (preedit_attr);
1275 XFree(preedit_attr); 1288 if (status_attr) XFree (status_attr);
1276 if (status_attr) 1289
1277 XFree(status_attr);
1278 if (Input_Context == NULL) 1290 if (Input_Context == NULL)
1279 { 1291 {
1280 rxvt_print_error("failed to create input context"); 1292 rxvt_print_error ("failed to create input context");
1281 XCloseIM(xim); 1293 display->put_xim (input_method);
1282 return False; 1294 return false;
1283 } 1295 }
1296
1284 if (input_style & XIMPreeditArea) 1297 if (input_style & XIMPreeditArea)
1285 IMSetStatusPosition (); 1298 IMSetStatusPosition ();
1299
1286 D_MAIN((stderr, "rxvt_IM_get_IC() - successful connection")); 1300 D_MAIN ((stderr, "rxvt_IM_get_IC () - successful connection"));
1287 return True; 1301 return true;
1288} 1302}
1289 1303
1290/*
1291 * X manual pages and include files don't match on some systems:
1292 * some think this is an XIDProc and others an XIMProc so we can't
1293 * use the first argument - need to update this to be nice for
1294 * both types via some sort of configure detection
1295 */
1296/* ARGSUSED */
1297/* EXTPROTO */
1298void 1304void
1299rxvt_IMInstantiateCallback(Display * unused 1305rxvt_term::im_cb ()
1300 __attribute__ ((unused)), XPointer client_data
1301 __attribute__ ((unused)), XPointer call_data
1302 __attribute__ ((unused)))
1303{ 1306{
1304 int i, found, had_im; 1307 int i, found, had_im;
1305 const char *p; 1308 const char *p;
1306 char **s; 1309 char **s;
1307 char buf[IMBUFSIZ]; 1310 char buf[IMBUFSIZ];
1308 1311
1312 im_destroy ();
1313
1309 D_MAIN((stderr, "rxvt_IMInstantiateCallback()")); 1314 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()"));
1310 if (GET_R->Input_Context) 1315 if (Input_Context)
1311 return; 1316 return;
1312 1317
1313#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) 1318#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
1314 if (GET_R->rs[Rs_imLocale]) 1319 if (rs[Rs_imLocale])
1315 setlocale (LC_CTYPE, GET_R->rs[Rs_imLocale]); 1320 setlocale (LC_CTYPE, rs[Rs_imLocale]);
1316#endif 1321#endif
1317 1322
1318 p = GET_R->rs[Rs_inputMethod]; 1323 p = rs[Rs_inputMethod];
1319 if (p && *p) 1324 if (p && *p)
1320 { 1325 {
1321 bool found = false; 1326 bool found = false;
1322 1327
1323 s = rxvt_splitcommastring (p); 1328 s = rxvt_splitcommastring (p);
1325 { 1330 {
1326 if (*s[i]) 1331 if (*s[i])
1327 { 1332 {
1328 STRCPY (buf, "@im="); 1333 STRCPY (buf, "@im=");
1329 STRNCAT (buf, s[i], IMBUFSIZ - 5); 1334 STRNCAT (buf, s[i], IMBUFSIZ - 5);
1330 if ((p = XSetLocaleModifiers (buf)) && *p && GET_R->IM_get_IC ()) 1335 if (IM_get_IC (buf))
1331 { 1336 {
1332 found = true; 1337 found = true;
1333 break; 1338 break;
1334 } 1339 }
1335 } 1340 }
1336 } 1341 }
1337 for (i = 0; s[i]; i++) 1342 for (i = 0; s[i]; i++)
1338 free(s[i]); 1343 free (s[i]);
1339 free(s); 1344 free (s);
1340 1345
1341 if (found) 1346 if (found)
1342 goto done; 1347 goto done;
1343 } 1348 }
1344 1349
1345 /* try with XMODIFIERS env. var. */ 1350 /* try with XMODIFIERS env. var. */
1346 if ((p = XSetLocaleModifiers ("")) && *p 1351 if (IM_get_IC (""))
1347 && GET_R->IM_get_IC ())
1348 goto done; 1352 goto done;
1349 1353
1350 /* try with no modifiers base IF the user didn't specify an IM */ 1354 /* try with no modifiers base IF the user didn't specify an IM */
1351 if ((p = XSetLocaleModifiers ("@im=none")) && *p 1355 if (IM_get_IC ("@im=none"))
1352 && GET_R->IM_get_IC () == True)
1353 goto done; 1356 goto done;
1354 1357
1355done: 1358done:
1356#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) 1359#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
1357 if (GET_R->rs[Rs_imLocale]) 1360 if (rs[Rs_imLocale])
1358 setlocale (LC_CTYPE, GET_R->locale); 1361 setlocale (LC_CTYPE, locale);
1359#endif 1362#endif
1360} 1363}
1361 1364
1362void 1365void
1363rxvt_term::IMSetStatusPosition () 1366rxvt_term::IMSetStatusPosition ()
1364{ 1367{
1365 XRectangle preedit_rect, status_rect, *needed_rect; 1368 XRectangle preedit_rect, status_rect, *needed_rect;
1366 XVaNestedList preedit_attr, status_attr; 1369 XVaNestedList preedit_attr, status_attr;
1367 1370
1368 if (Input_Context == NULL 1371 if (Input_Context == NULL
1369 || !TermWin.focus || !(input_style & XIMPreeditArea) 1372 || !TermWin.focus || ! (input_style & XIMPreeditArea)
1370 || !IMisRunning ()) 1373 || !IMisRunning ())
1371 return; 1374 return;
1372 1375
1373 /* Getting the necessary width of preedit area */ 1376 /* Getting the necessary width of preedit area */
1374 status_attr = XVaCreateNestedList(0, XNAreaNeeded, &needed_rect, NULL); 1377 status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL);
1375 XGetICValues(Input_Context, XNStatusAttributes, status_attr, NULL); 1378 XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL);
1376 XFree(status_attr); 1379 XFree (status_attr);
1377 1380
1378 set_preedit_area(&preedit_rect, &status_rect, needed_rect); 1381 im_set_preedit_area (&preedit_rect, &status_rect, needed_rect);
1379 1382
1380 preedit_attr = XVaCreateNestedList(0, XNArea, &preedit_rect, NULL); 1383 preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL);
1381 status_attr = XVaCreateNestedList(0, XNArea, &status_rect, NULL); 1384 status_attr = XVaCreateNestedList (0, XNArea, &status_rect, NULL);
1382 1385
1383 XSetICValues(Input_Context, 1386 XSetICValues (Input_Context,
1384 XNPreeditAttributes, preedit_attr, 1387 XNPreeditAttributes, preedit_attr,
1385 XNStatusAttributes, status_attr, NULL); 1388 XNStatusAttributes, status_attr, NULL);
1386 1389
1387 XFree(preedit_attr); 1390 XFree (preedit_attr);
1388 XFree(status_attr); 1391 XFree (status_attr);
1389} 1392}
1390#endif /* USE_XIM */ 1393#endif /* USE_XIM */
1391 1394
1392/*----------------------------------------------------------------------*/ 1395/*----------------------------------------------------------------------*/
1393rxvt_t rxvt_current_term; 1396rxvt_t rxvt_current_term;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines