… | |
… | |
51 | static char curlocale[128]; |
51 | static char curlocale[128]; |
52 | |
52 | |
53 | bool |
53 | bool |
54 | rxvt_set_locale (const char *locale) |
54 | rxvt_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 |
… | |
… | |
128 | void * |
128 | void * |
129 | rxvt_term::operator new (size_t s) |
129 | rxvt_term::operator new (size_t s) |
130 | { |
130 | { |
131 | void *p = malloc (s); |
131 | void *p = malloc (s); |
132 | |
132 | |
133 | MEMSET (p, 0, s); |
133 | memset (p, 0, s); |
134 | return p; |
134 | return p; |
135 | } |
135 | } |
136 | |
136 | |
137 | void |
137 | void |
138 | rxvt_term::operator delete (void *p, size_t s) |
138 | rxvt_term::operator delete (void *p, size_t s) |
… | |
… | |
187 | |
187 | |
188 | rxvt_term::~rxvt_term () |
188 | rxvt_term::~rxvt_term () |
189 | { |
189 | { |
190 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
190 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
191 | |
191 | |
192 | if (cmd_fd >= 0) |
192 | if (cmd_pid) |
193 | close (cmd_fd); |
193 | kill (-cmd_pid, SIGHUP); |
194 | |
194 | |
195 | #ifndef NO_SETOWNER_TTYDEV |
195 | pty.put (); |
196 | privileged_ttydev (RESTORE); |
196 | |
197 | #endif |
|
|
198 | #ifdef UTMP_SUPPORT |
197 | #ifdef UTMP_SUPPORT |
199 | privileged_utmp (RESTORE); |
198 | privileged_utmp (RESTORE); |
200 | #endif |
199 | #endif |
201 | |
200 | |
202 | delete TermWin.fontset; |
201 | delete TermWin.fontset; |
… | |
… | |
207 | |
206 | |
208 | #ifdef USE_XIM |
207 | #ifdef USE_XIM |
209 | im_destroy (); |
208 | im_destroy (); |
210 | #endif |
209 | #endif |
211 | #ifdef MENUBAR |
210 | #ifdef MENUBAR |
212 | if (menubarGC) XFreeGC (display->display, menubarGC); |
211 | if (menubarGC) XFreeGC (display->display, menubarGC); |
213 | #endif |
212 | #endif |
214 | #ifdef XTERM_SCROLLBAR |
213 | #ifdef XTERM_SCROLLBAR |
215 | if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC); |
214 | if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC); |
216 | if (ShadowGC) XFreeGC (display->display, ShadowGC); |
215 | if (ShadowGC) XFreeGC (display->display, ShadowGC); |
217 | #endif |
216 | #endif |
… | |
… | |
248 | XDestroyWindow (display->display, TermWin.parent[0]); |
247 | XDestroyWindow (display->display, TermWin.parent[0]); |
249 | } |
248 | } |
250 | |
249 | |
251 | // TODO: free pixcolours, colours should become part of rxvt_display |
250 | // TODO: free pixcolours, colours should become part of rxvt_display |
252 | |
251 | |
253 | delete PixColorsFocused; |
252 | delete pix_colors_focused; |
254 | #ifdef OFF_FOCUS_FADING |
253 | #ifdef OFF_FOCUS_FADING |
255 | delete PixColorsUnFocused; |
254 | delete pix_colors_unfocused; |
256 | #endif |
255 | #endif |
257 | |
256 | |
258 | displays.put (display); |
257 | displays.put (display); |
259 | |
258 | |
260 | scr_release (); |
259 | scr_release (); |
… | |
… | |
282 | rxvt_term::destroy () |
281 | rxvt_term::destroy () |
283 | { |
282 | { |
284 | if (destroy_ev.active) |
283 | if (destroy_ev.active) |
285 | return; |
284 | return; |
286 | |
285 | |
|
|
286 | #if ENABLE_OVERLAY |
|
|
287 | scr_overlay_off (); |
|
|
288 | #endif |
|
|
289 | |
287 | if (display) |
290 | if (display) |
288 | { |
291 | { |
289 | #if USE_XIM |
292 | #if USE_XIM |
290 | im_ev.stop (display); |
293 | im_ev.stop (display); |
291 | #endif |
294 | #endif |
… | |
… | |
340 | SET_R (this); |
343 | SET_R (this); |
341 | |
344 | |
342 | if (!init_vars ()) |
345 | if (!init_vars ()) |
343 | return false; |
346 | return false; |
344 | |
347 | |
|
|
348 | init_secondary (); |
|
|
349 | |
|
|
350 | const char **cmd_argv = init_resources (argc, argv); |
|
|
351 | |
|
|
352 | set_locale (""); |
|
|
353 | |
|
|
354 | #if MENUBAR_MAX |
|
|
355 | menubar_read (rs[Rs_menu]); |
|
|
356 | #endif |
|
|
357 | #ifdef HAVE_SCROLLBARS |
|
|
358 | if (options & Opt_scrollBar) |
|
|
359 | scrollBar.setIdle (); /* set existence for size calculations */ |
|
|
360 | #endif |
|
|
361 | |
|
|
362 | create_windows (argc, argv); |
|
|
363 | |
|
|
364 | init_xlocale (); |
|
|
365 | |
|
|
366 | scr_reset (); /* initialize screen */ |
|
|
367 | |
|
|
368 | #if 0 |
|
|
369 | XSynchronize (display->display, True); |
|
|
370 | #endif |
|
|
371 | |
|
|
372 | #ifdef HAVE_SCROLLBARS |
|
|
373 | if (options & Opt_scrollBar) |
|
|
374 | resize_scrollbar (); /* create and map scrollbar */ |
|
|
375 | #endif |
|
|
376 | #if (MENUBAR_MAX) |
|
|
377 | if (menubar_visible ()) |
|
|
378 | XMapWindow (display->display, menuBar.win); |
|
|
379 | #endif |
|
|
380 | #ifdef TRANSPARENT |
|
|
381 | if (options & Opt_transparent) |
|
|
382 | { |
|
|
383 | XSelectInput (display->display, display->root, PropertyChangeMask); |
|
|
384 | check_our_parents (); |
|
|
385 | rootwin_ev.start (display, display->root); |
|
|
386 | } |
|
|
387 | #endif |
|
|
388 | |
|
|
389 | XMapWindow (display->display, TermWin.vt); |
|
|
390 | XMapWindow (display->display, TermWin.parent[0]); |
|
|
391 | |
|
|
392 | init_command (cmd_argv); |
|
|
393 | |
|
|
394 | pty_ev.start (pty.pty, EVENT_READ); |
|
|
395 | |
|
|
396 | check_ev.start (); |
|
|
397 | |
|
|
398 | return true; |
|
|
399 | } |
|
|
400 | |
|
|
401 | static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event); |
|
|
402 | |
|
|
403 | void |
|
|
404 | rxvt_init () |
|
|
405 | { |
|
|
406 | /* install exit handler for cleanup */ |
|
|
407 | #if 0 |
|
|
408 | #ifdef HAVE_ATEXIT |
|
|
409 | atexit (rxvt_clean_exit); |
|
|
410 | #else |
|
|
411 | #endif |
|
|
412 | #endif |
345 | /* |
413 | /* |
346 | * Save and then give up any super-user privileges |
414 | * Save and then give up any super-user privileges |
347 | * If we need privileges in any area then we must specifically request it. |
415 | * If we need privileges in any area then we must specifically request it. |
348 | * We should only need to be root in these cases: |
416 | * We should only need to be root in these cases: |
349 | * 1. write utmp entries on some systems |
417 | * 1. write utmp entries on some systems |
350 | * 2. chown tty on some systems |
418 | * 2. chown tty on some systems |
351 | */ |
419 | */ |
352 | privileges (SAVE); |
420 | rxvt_privileges (SAVE); |
353 | privileges (IGNORE); |
421 | rxvt_privileges (IGNORE); |
354 | |
|
|
355 | init_secondary (); |
|
|
356 | |
|
|
357 | const char **cmd_argv = init_resources (argc, argv); |
|
|
358 | |
|
|
359 | set_locale (""); |
|
|
360 | |
|
|
361 | #if MENUBAR_MAX |
|
|
362 | menubar_read (rs[Rs_menu]); |
|
|
363 | #endif |
|
|
364 | #ifdef HAVE_SCROLLBARS |
|
|
365 | if (Options & Opt_scrollBar) |
|
|
366 | scrollBar.setIdle (); /* set existence for size calculations */ |
|
|
367 | #endif |
|
|
368 | |
|
|
369 | create_windows (argc, argv); |
|
|
370 | |
|
|
371 | init_xlocale (); |
|
|
372 | |
|
|
373 | scr_reset (); /* initialize screen */ |
|
|
374 | |
|
|
375 | #if 0 |
|
|
376 | XSynchronize (display->display, True); |
|
|
377 | #endif |
|
|
378 | |
|
|
379 | #ifdef HAVE_SCROLLBARS |
|
|
380 | if (Options & Opt_scrollBar) |
|
|
381 | resize_scrollbar (); /* create and map scrollbar */ |
|
|
382 | #endif |
|
|
383 | #if (MENUBAR_MAX) |
|
|
384 | if (menubar_visible ()) |
|
|
385 | XMapWindow (display->display, menuBar.win); |
|
|
386 | #endif |
|
|
387 | #ifdef TRANSPARENT |
|
|
388 | if (Options & Opt_transparent) |
|
|
389 | { |
|
|
390 | XSelectInput (display->display, display->root, PropertyChangeMask); |
|
|
391 | check_our_parents (); |
|
|
392 | rootwin_ev.start (display, display->root); |
|
|
393 | } |
|
|
394 | #endif |
|
|
395 | |
|
|
396 | XMapWindow (display->display, TermWin.vt); |
|
|
397 | XMapWindow (display->display, TermWin.parent[0]); |
|
|
398 | |
|
|
399 | init_command (cmd_argv); |
|
|
400 | |
|
|
401 | pty_ev.start (cmd_fd, EVENT_READ); |
|
|
402 | |
|
|
403 | check_ev.start (); |
|
|
404 | |
|
|
405 | return true; |
|
|
406 | } |
|
|
407 | |
|
|
408 | static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event); |
|
|
409 | |
|
|
410 | void |
|
|
411 | rxvt_init_signals () |
|
|
412 | { |
|
|
413 | /* install exit handler for cleanup */ |
|
|
414 | #if 0 |
|
|
415 | #ifdef HAVE_ATEXIT |
|
|
416 | atexit (rxvt_clean_exit); |
|
|
417 | #else |
|
|
418 | #endif |
|
|
419 | #endif |
|
|
420 | |
422 | |
421 | struct sigaction sa; |
423 | struct sigaction sa; |
422 | |
424 | |
423 | sigfillset (&sa.sa_mask); |
425 | sigfillset (&sa.sa_mask); |
424 | sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; |
426 | sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; |
… | |
… | |
452 | break; |
454 | break; |
453 | } |
455 | } |
454 | } |
456 | } |
455 | |
457 | |
456 | /* ARGSUSED */ |
458 | /* ARGSUSED */ |
457 | /* EXTPROTO */ |
459 | /* INTPROTO */ |
458 | RETSIGTYPE |
460 | RETSIGTYPE |
459 | rxvt_Child_signal (int sig __attribute__ ((unused))) |
461 | rxvt_Child_signal (int sig __attribute__ ((unused))) |
460 | { |
462 | { |
461 | int pid, save_errno = errno; |
463 | int pid, save_errno = errno; |
462 | |
464 | |
… | |
… | |
467 | } |
469 | } |
468 | |
470 | |
469 | /* |
471 | /* |
470 | * Catch a fatal signal and tidy up before quitting |
472 | * Catch a fatal signal and tidy up before quitting |
471 | */ |
473 | */ |
472 | /* EXTPROTO */ |
474 | /* INTPROTO */ |
473 | RETSIGTYPE |
475 | RETSIGTYPE |
474 | rxvt_Exit_signal (int sig) |
476 | rxvt_Exit_signal (int sig) |
475 | { |
477 | { |
476 | signal (sig, SIG_DFL); |
478 | signal (sig, SIG_DFL); |
477 | #ifdef DEBUG_CMD |
479 | #ifdef DEBUG_CMD |
… | |
… | |
499 | /*----------------------------------------------------------------------*/ |
501 | /*----------------------------------------------------------------------*/ |
500 | /* |
502 | /* |
501 | * Exit gracefully, clearing the utmp entry and restoring tty attributes |
503 | * Exit gracefully, clearing the utmp entry and restoring tty attributes |
502 | * TODO: if debugging, this should free up any known resources if we can |
504 | * TODO: if debugging, this should free up any known resources if we can |
503 | */ |
505 | */ |
504 | /* EXTPROTO */ |
506 | /* INTPROTO */ |
505 | void |
507 | void |
506 | rxvt_clean_exit () |
508 | rxvt_clean_exit () |
507 | { |
509 | { |
508 | // TODO: rxvtd should clean up all ressources |
510 | // TODO: rxvtd should clean up all ressources |
509 | if (GET_R) |
511 | if (GET_R) |
… | |
… | |
511 | } |
513 | } |
512 | |
514 | |
513 | /* ------------------------------------------------------------------------- * |
515 | /* ------------------------------------------------------------------------- * |
514 | * MEMORY ALLOCATION WRAPPERS * |
516 | * MEMORY ALLOCATION WRAPPERS * |
515 | * ------------------------------------------------------------------------- */ |
517 | * ------------------------------------------------------------------------- */ |
516 | /* EXTPROTO */ |
518 | /* INTPROTO */ |
517 | void * |
519 | void * |
518 | rxvt_malloc (size_t size) |
520 | rxvt_malloc (size_t size) |
519 | { |
521 | { |
520 | void *p; |
522 | void *p; |
521 | |
523 | |
522 | p = malloc (size); |
524 | p = malloc (size); |
523 | if (p) |
525 | if (p) |
524 | return p; |
526 | return p; |
525 | |
527 | |
526 | fprintf (stderr, RESNAME ": memory allocation failure. Aborting"); |
528 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
527 | rxvt_clean_exit (); |
|
|
528 | exit (EXIT_FAILURE); |
|
|
529 | /* NOTREACHED */ |
529 | /* NOTREACHED */ |
530 | } |
530 | } |
531 | |
531 | |
532 | /* EXTPROTO */ |
532 | /* INTPROTO */ |
533 | void * |
533 | void * |
534 | rxvt_calloc (size_t number, size_t size) |
534 | rxvt_calloc (size_t number, size_t size) |
535 | { |
535 | { |
536 | void *p; |
536 | void *p; |
537 | |
537 | |
538 | p = calloc (number, size); |
538 | p = calloc (number, size); |
539 | if (p) |
539 | if (p) |
540 | return p; |
540 | return p; |
541 | |
541 | |
542 | fprintf (stderr, RESNAME ": memory allocation failure. Aborting"); |
542 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
543 | rxvt_clean_exit (); |
|
|
544 | exit (EXIT_FAILURE); |
|
|
545 | /* NOTREACHED */ |
543 | /* NOTREACHED */ |
546 | } |
544 | } |
547 | |
545 | |
548 | /* EXTPROTO */ |
546 | /* INTPROTO */ |
549 | void * |
547 | void * |
550 | rxvt_realloc (void *ptr, size_t size) |
548 | rxvt_realloc (void *ptr, size_t size) |
551 | { |
549 | { |
552 | void *p; |
550 | void *p; |
553 | |
551 | |
554 | if (ptr) |
552 | if (ptr) |
555 | p = realloc (ptr, size); |
553 | p = realloc (ptr, size); |
556 | else |
554 | else |
557 | p = malloc (size); |
555 | p = malloc (size); |
|
|
556 | |
558 | if (p) |
557 | if (p) |
559 | return p; |
558 | return p; |
560 | |
559 | |
561 | fprintf (stderr, RESNAME ": memory allocation failure. Aborting"); |
560 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
562 | rxvt_clean_exit (); |
|
|
563 | exit (EXIT_FAILURE); |
|
|
564 | /* NOTREACHED */ |
561 | /* NOTREACHED */ |
565 | } |
562 | } |
566 | |
563 | |
567 | /* ------------------------------------------------------------------------- * |
564 | /* ------------------------------------------------------------------------- * |
568 | * PRIVILEGED OPERATIONS * |
565 | * PRIVILEGED OPERATIONS * |
569 | * ------------------------------------------------------------------------- */ |
566 | * ------------------------------------------------------------------------- */ |
570 | /* take care of suid/sgid super-user (root) privileges */ |
567 | /* take care of suid/sgid super-user (root) privileges */ |
571 | void |
568 | void |
572 | rxvt_term::privileges (int mode) |
569 | rxvt_privileges (rxvt_privaction action) |
573 | { |
570 | { |
|
|
571 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
572 | static uid_t euid; |
|
|
573 | static gid_t egid; |
|
|
574 | #endif |
|
|
575 | |
574 | #if ! defined(__CYGWIN32__) |
576 | #if ! defined(__CYGWIN32__) |
575 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
577 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
576 | /* setreuid () is the poor man's setuid (), seteuid () */ |
578 | /* setreuid () is the poor man's setuid (), seteuid () */ |
577 | # define seteuid(a) setreuid(-1, (a)) |
579 | # define seteuid(a) setreuid(-1, (a)) |
578 | # define setegid(a) setregid(-1, (a)) |
580 | # define setegid(a) setregid(-1, (a)) |
579 | # define HAVE_SETEUID |
581 | # define HAVE_SETEUID |
580 | # endif |
582 | # endif |
581 | # ifdef HAVE_SETEUID |
583 | # ifdef HAVE_SETEUID |
582 | switch (mode) |
584 | switch (action) |
583 | { |
585 | { |
584 | case IGNORE: |
586 | case IGNORE: |
585 | /* |
587 | /* |
586 | * change effective uid/gid - not real uid/gid - so we can switch |
588 | * change effective uid/gid - not real uid/gid - so we can switch |
587 | * back to root later, as required |
589 | * back to root later, as required |
… | |
… | |
597 | seteuid (euid); |
599 | seteuid (euid); |
598 | setegid (egid); |
600 | setegid (egid); |
599 | break; |
601 | break; |
600 | } |
602 | } |
601 | # else |
603 | # else |
602 | switch (mode) |
604 | switch (action) |
603 | { |
605 | { |
604 | case IGNORE: |
606 | case IGNORE: |
605 | setuid (getuid ()); |
607 | setuid (getuid ()); |
606 | setgid (getgid ()); |
608 | setgid (getgid ()); |
607 | /* FALLTHROUGH */ |
609 | /* FALLTHROUGH */ |
… | |
… | |
614 | #endif |
616 | #endif |
615 | } |
617 | } |
616 | |
618 | |
617 | #ifdef UTMP_SUPPORT |
619 | #ifdef UTMP_SUPPORT |
618 | void |
620 | void |
619 | rxvt_term::privileged_utmp (char action) |
621 | rxvt_term::privileged_utmp (rxvt_privaction action) |
620 | { |
622 | { |
621 | D_MAIN ((stderr, "rxvt_privileged_utmp (%c); waiting for: %c (pid: %d)", |
|
|
622 | action, next_utmp_action, getpid ())); |
|
|
623 | if (next_utmp_action != action || (action != SAVE && action != RESTORE) |
|
|
624 | || (Options & Opt_utmpInhibit) |
623 | if ((options & Opt_utmpInhibit) |
625 | || ttydev == NULL || *ttydev == '\0') |
624 | || !pty.name || !*pty.name) |
626 | return; |
625 | return; |
627 | |
626 | |
628 | privileges (RESTORE); |
627 | rxvt_privileges (RESTORE); |
|
|
628 | |
629 | if (action == SAVE) |
629 | if (action == SAVE) |
630 | { |
|
|
631 | next_utmp_action = RESTORE; |
|
|
632 | makeutent (ttydev, rs[Rs_display_name]); |
630 | makeutent (pty.name, rs[Rs_display_name]); |
633 | } |
|
|
634 | else |
631 | else |
635 | { /* action == RESTORE */ |
|
|
636 | next_utmp_action = IGNORE; |
|
|
637 | cleanutent (); |
632 | cleanutent (); |
638 | } |
633 | |
639 | privileges (IGNORE); |
634 | rxvt_privileges (IGNORE); |
640 | } |
|
|
641 | #endif |
|
|
642 | |
|
|
643 | #ifndef NO_SETOWNER_TTYDEV |
|
|
644 | void |
|
|
645 | rxvt_term::privileged_ttydev (char action) |
|
|
646 | { |
|
|
647 | D_MAIN ((stderr, |
|
|
648 | "privileged_ttydev (%c); waiting for: %c (pid: %d)", |
|
|
649 | action, next_tty_action, getpid ())); |
|
|
650 | if (next_tty_action != action || (action != SAVE && action != RESTORE) |
|
|
651 | || ttydev == NULL || *ttydev == '\0') |
|
|
652 | return; |
|
|
653 | |
|
|
654 | privileges (RESTORE); |
|
|
655 | |
|
|
656 | if (action == SAVE) |
|
|
657 | { |
|
|
658 | next_tty_action = RESTORE; |
|
|
659 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
|
|
660 | /* store original tty status for restoration rxvt_clean_exit () -- rgg 04/12/95 */ |
|
|
661 | if (lstat (ttydev, &ttyfd_stat) < 0) /* you lose out */ |
|
|
662 | next_tty_action = IGNORE; |
|
|
663 | else |
|
|
664 | # endif |
|
|
665 | |
|
|
666 | { |
|
|
667 | chown (ttydev, getuid (), ttygid); /* fail silently */ |
|
|
668 | chmod (ttydev, ttymode); |
|
|
669 | # ifdef HAVE_REVOKE |
|
|
670 | revoke (ttydev); |
|
|
671 | # endif |
|
|
672 | |
|
|
673 | } |
|
|
674 | } |
|
|
675 | else |
|
|
676 | { /* action == RESTORE */ |
|
|
677 | next_tty_action = IGNORE; |
|
|
678 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
|
|
679 | chmod (ttydev, ttyfd_stat.st_mode); |
|
|
680 | chown (ttydev, ttyfd_stat.st_uid, ttyfd_stat.st_gid); |
|
|
681 | # else |
|
|
682 | chmod (ttydev, |
|
|
683 | (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)); |
|
|
684 | chown (ttydev, 0, 0); |
|
|
685 | # endif |
|
|
686 | |
|
|
687 | } |
|
|
688 | |
|
|
689 | privileges (IGNORE); |
|
|
690 | |
|
|
691 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
|
|
692 | D_MAIN ((stderr, "%s \"%s\": mode %03o, uid %d, gid %d", |
|
|
693 | action == RESTORE ? "Restoring" : (action == |
|
|
694 | SAVE ? "Saving" : |
|
|
695 | "UNKNOWN ERROR for"), ttydev, |
|
|
696 | ttyfd_stat.st_mode, ttyfd_stat.st_uid, |
|
|
697 | ttyfd_stat.st_gid)); |
|
|
698 | # endif |
|
|
699 | } |
635 | } |
700 | #endif |
636 | #endif |
701 | |
637 | |
702 | /*----------------------------------------------------------------------*/ |
638 | /*----------------------------------------------------------------------*/ |
703 | /* |
639 | /* |
… | |
… | |
774 | |
710 | |
775 | if (scrollbar_visible ()) |
711 | if (scrollbar_visible ()) |
776 | { |
712 | { |
777 | sb_w = scrollbar_TotalWidth (); |
713 | sb_w = scrollbar_TotalWidth (); |
778 | szHint.base_width += sb_w; |
714 | szHint.base_width += sb_w; |
779 | if (!(Options & Opt_scrollBar_right)) |
715 | if (!(options & Opt_scrollBar_right)) |
780 | window_vt_x += sb_w; |
716 | window_vt_x += sb_w; |
781 | } |
717 | } |
782 | |
718 | |
783 | if (menubar_visible ()) |
719 | if (menubar_visible ()) |
784 | { |
720 | { |
… | |
… | |
812 | { |
748 | { |
813 | MIN_IT (TermWin.height, max_height); |
749 | MIN_IT (TermWin.height, max_height); |
814 | szHint.height = szHint.base_height + TermWin.height; |
750 | szHint.height = szHint.base_height + TermWin.height; |
815 | } |
751 | } |
816 | |
752 | |
817 | if (scrollbar_visible () && (Options & Opt_scrollBar_right)) |
753 | if (scrollbar_visible () && (options & Opt_scrollBar_right)) |
818 | window_sb_x = szHint.width - sb_w; |
754 | window_sb_x = szHint.width - sb_w; |
819 | |
755 | |
820 | if (recalc_x) |
756 | if (recalc_x) |
821 | szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) |
757 | szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) |
822 | - szHint.width - 2 * TermWin.ext_bwidth); |
758 | - szHint.width - 2 * TermWin.ext_bwidth); |
… | |
… | |
838 | * Called after a window size change. |
774 | * Called after a window size change. |
839 | */ |
775 | */ |
840 | void |
776 | void |
841 | rxvt_term::tt_winch () |
777 | rxvt_term::tt_winch () |
842 | { |
778 | { |
|
|
779 | if (pty.pty < 0) |
|
|
780 | return; |
|
|
781 | |
843 | struct winsize ws; |
782 | struct winsize ws; |
844 | |
|
|
845 | if (cmd_fd < 0) |
|
|
846 | return; |
|
|
847 | |
783 | |
848 | ws.ws_col = TermWin.ncol; |
784 | ws.ws_col = TermWin.ncol; |
849 | ws.ws_row = TermWin.nrow; |
785 | ws.ws_row = TermWin.nrow; |
850 | ws.ws_xpixel = ws.ws_ypixel = 0; |
786 | ws.ws_xpixel = TermWin.width; |
851 | #ifndef DEBUG_SIZE |
787 | ws.ws_ypixel = TermWin.height; |
852 | (void)ioctl (cmd_fd, TIOCSWINSZ, &ws); |
788 | (void)ioctl (pty.pty, TIOCSWINSZ, &ws); |
853 | #else |
789 | |
854 | if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0) |
790 | #if 0 |
855 | D_SIZE ((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); |
791 | // TIOCSWINSZ⎈ is supposed to do this automatically and correctly |
856 | # ifdef SIGWINCH |
|
|
857 | else if (cmd_pid) /* force through to the command */ |
792 | if (cmd_pid) /* force through to the command */ |
858 | kill (cmd_pid, SIGWINCH); |
793 | kill (cmd_pid, SIGWINCH); |
859 | # endif |
|
|
860 | #endif |
794 | #endif |
861 | } |
795 | } |
862 | |
796 | |
863 | /*----------------------------------------------------------------------*/ |
797 | /*----------------------------------------------------------------------*/ |
864 | /* rxvt_change_font () - Switch to a new font */ |
798 | /* rxvt_change_font () - Switch to a new font */ |
… | |
… | |
924 | char *name; |
858 | char *name; |
925 | |
859 | |
926 | if (!XFetchName (display->display, TermWin.parent[0], &name)) |
860 | if (!XFetchName (display->display, TermWin.parent[0], &name)) |
927 | name = NULL; |
861 | name = NULL; |
928 | |
862 | |
929 | if (name == NULL || STRCMP (name, str)) |
863 | if (name == NULL || strcmp (name, str)) |
930 | #endif |
864 | #endif |
931 | XStoreName (display->display, TermWin.parent[0], str); |
865 | XStoreName (display->display, TermWin.parent[0], str); |
932 | |
866 | |
933 | #ifdef SMART_WINDOW_TITLE |
867 | #ifdef SMART_WINDOW_TITLE |
934 | if (name) |
868 | if (name) |
… | |
… | |
943 | char *name; |
877 | char *name; |
944 | |
878 | |
945 | if (!XGetIconName (display->display, TermWin.parent[0], &name)) |
879 | if (!XGetIconName (display->display, TermWin.parent[0], &name)) |
946 | name = NULL; |
880 | name = NULL; |
947 | |
881 | |
948 | if (name == NULL || STRCMP (name, str)) |
882 | if (name == NULL || strcmp (name, str)) |
949 | #endif |
883 | #endif |
950 | XSetIconName (display->display, TermWin.parent[0], str); |
884 | XSetIconName (display->display, TermWin.parent[0], str); |
951 | |
885 | |
952 | #ifdef SMART_WINDOW_TITLE |
886 | #ifdef SMART_WINDOW_TITLE |
953 | if (name) |
887 | if (name) |
… | |
… | |
971 | i = atoi (color); |
905 | i = atoi (color); |
972 | if (i >= 8 && i <= 15) |
906 | if (i >= 8 && i <= 15) |
973 | { /* bright colors */ |
907 | { /* bright colors */ |
974 | i -= 8; |
908 | i -= 8; |
975 | # ifndef NO_BRIGHTCOLOR |
909 | # ifndef NO_BRIGHTCOLOR |
976 | PixColorsFocused[idx] = PixColorsFocused[minBrightCOLOR + i]; |
910 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
977 | SET_PIXCOLOR (idx); |
911 | SET_PIXCOLOR (idx); |
978 | goto Done; |
912 | goto Done; |
979 | # endif |
913 | # endif |
980 | |
914 | |
981 | } |
915 | } |
982 | if (i >= 0 && i <= 7) |
916 | if (i >= 0 && i <= 7) |
983 | { /* normal colors */ |
917 | { /* normal colors */ |
984 | PixColorsFocused[idx] = PixColorsFocused[minCOLOR + i]; |
918 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
985 | SET_PIXCOLOR (idx); |
919 | SET_PIXCOLOR (idx); |
986 | goto Done; |
920 | goto Done; |
987 | } |
921 | } |
988 | } |
922 | } |
989 | |
923 | |
… | |
… | |
996 | * FIXME: should free colors here, but no idea how to do it so instead, |
930 | * FIXME: should free colors here, but no idea how to do it so instead, |
997 | * so just keep gobbling up the colormap |
931 | * so just keep gobbling up the colormap |
998 | */ |
932 | */ |
999 | # if 0 |
933 | # if 0 |
1000 | for (i = Color_Black; i <= Color_White; i++) |
934 | for (i = Color_Black; i <= Color_White; i++) |
1001 | if (PixColors[idx] == PixColors[i]) |
935 | if (pix_colors[idx] == pix_colors[i]) |
1002 | break; |
936 | break; |
1003 | if (i > Color_White) |
937 | if (i > Color_White) |
1004 | { |
938 | { |
1005 | /* fprintf (stderr, "XFreeColors: PixColors [%d] = %lu\n", idx, PixColors [idx]); */ |
939 | /* fprintf (stderr, "XFreeColors: pix_colors [%d] = %lu\n", idx, pix_colors [idx]); */ |
1006 | XFreeColors (display->display, display->cmap, (PixColors + idx), 1, |
940 | XFreeColors (display->display, display->cmap, (pix_colors + idx), 1, |
1007 | DisplayPlanes (display->display, display->screen)); |
941 | DisplayPlanes (display->display, display->screen)); |
1008 | } |
942 | } |
1009 | # endif |
943 | # endif |
1010 | |
944 | |
1011 | PixColorsFocused[idx] = xcol; |
945 | pix_colors_focused[idx] = xcol; |
1012 | SET_PIXCOLOR (idx); |
946 | SET_PIXCOLOR (idx); |
1013 | |
947 | |
1014 | /* XSetWindowAttributes attr; */ |
948 | /* XSetWindowAttributes attr; */ |
1015 | /* Cursor cursor; */ |
949 | /* Cursor cursor; */ |
1016 | Done: |
950 | Done: |
1017 | #ifdef OFF_FOCUS_FADING |
951 | #ifdef OFF_FOCUS_FADING |
1018 | PixColorsUnFocused[idx] = PixColorsFocused[idx].fade (display, atoi (rs[Rs_fade])); |
952 | pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade])); |
1019 | #endif |
953 | #endif |
1020 | if (idx == Color_bg && ! (Options & Opt_transparent)) |
954 | if (idx == Color_bg && ! (options & Opt_transparent)) |
1021 | XSetWindowBackground (display->display, TermWin.vt, PixColors[Color_bg]); |
955 | XSetWindowBackground (display->display, TermWin.vt, pix_colors[Color_bg]); |
1022 | |
956 | |
1023 | /* handle Color_BD, scrollbar background, etc. */ |
957 | /* handle Color_BD, scrollbar background, etc. */ |
1024 | |
958 | |
1025 | set_colorfgbg (); |
959 | set_colorfgbg (); |
1026 | recolour_cursor (); |
960 | recolour_cursor (); |
… | |
… | |
1034 | void |
968 | void |
1035 | rxvt_term::recolour_cursor () |
969 | rxvt_term::recolour_cursor () |
1036 | { |
970 | { |
1037 | XColor xcol[2]; |
971 | XColor xcol[2]; |
1038 | |
972 | |
1039 | xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) ? PixColorsFocused[Color_pointer_fg] : PixColorsFocused[Color_fg]; |
973 | xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) ? pix_colors_focused[Color_pointer_fg] : pix_colors_focused[Color_fg]; |
1040 | xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) ? PixColorsFocused[Color_pointer_bg] : PixColorsFocused[Color_bg]; |
974 | xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) ? pix_colors_focused[Color_pointer_bg] : pix_colors_focused[Color_bg]; |
1041 | XQueryColors (display->display, display->cmap, xcol, 2); |
975 | XQueryColors (display->display, display->cmap, xcol, 2); |
1042 | XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1); |
976 | XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1); |
1043 | } |
977 | } |
1044 | |
978 | |
1045 | /*----------------------------------------------------------------------*/ |
979 | /*----------------------------------------------------------------------*/ |
… | |
… | |
1053 | const char *xpmb = "\0"; |
987 | const char *xpmb = "\0"; |
1054 | char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1]; |
988 | char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1]; |
1055 | |
989 | |
1056 | env_colorfgbg = |
990 | env_colorfgbg = |
1057 | (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1); |
991 | (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1); |
1058 | STRCPY (fstr, "default"); |
992 | strcpy (fstr, "default"); |
1059 | STRCPY (bstr, "default"); |
993 | strcpy (bstr, "default"); |
1060 | for (i = Color_Black; i <= Color_White; i++) |
994 | for (i = Color_Black; i <= Color_White; i++) |
1061 | if (PixColors[Color_fg] == PixColors[i]) |
995 | if (pix_colors[Color_fg] == pix_colors[i]) |
1062 | { |
996 | { |
1063 | sprintf (fstr, "%d", (i - Color_Black)); |
997 | sprintf (fstr, "%d", (i - Color_Black)); |
1064 | break; |
998 | break; |
1065 | } |
999 | } |
1066 | for (i = Color_Black; i <= Color_White; i++) |
1000 | for (i = Color_Black; i <= Color_White; i++) |
1067 | if (PixColors[Color_bg] == PixColors[i]) |
1001 | if (pix_colors[Color_bg] == pix_colors[i]) |
1068 | { |
1002 | { |
1069 | sprintf (bstr, "%d", (i - Color_Black)); |
1003 | sprintf (bstr, "%d", (i - Color_Black)); |
1070 | #ifdef XPM_BACKGROUND |
1004 | #ifdef XPM_BACKGROUND |
1071 | xpmb = "default;"; |
1005 | xpmb = "default;"; |
1072 | #endif |
1006 | #endif |
… | |
… | |
1077 | |
1011 | |
1078 | #ifndef NO_BRIGHTCOLOR |
1012 | #ifndef NO_BRIGHTCOLOR |
1079 | colorfgbg = DEFAULT_RSTYLE; |
1013 | colorfgbg = DEFAULT_RSTYLE; |
1080 | for (i = minCOLOR; i <= maxCOLOR; i++) |
1014 | for (i = minCOLOR; i <= maxCOLOR; i++) |
1081 | { |
1015 | { |
1082 | if (PixColors[Color_fg] == PixColors[i]) |
1016 | if (pix_colors[Color_fg] == pix_colors[i]) |
1083 | colorfgbg = SET_FGCOLOR (colorfgbg, i); |
1017 | colorfgbg = SET_FGCOLOR (colorfgbg, i); |
1084 | if (PixColors[Color_bg] == PixColors[i]) |
1018 | if (pix_colors[Color_bg] == pix_colors[i]) |
1085 | colorfgbg = SET_BGCOLOR (colorfgbg, i); |
1019 | colorfgbg = SET_BGCOLOR (colorfgbg, i); |
1086 | } |
1020 | } |
1087 | #endif |
1021 | #endif |
1088 | } |
1022 | } |
1089 | |
1023 | |
… | |
… | |
1255 | * - X INPUT METHOD ROUTINES - * |
1189 | * - X INPUT METHOD ROUTINES - * |
1256 | * -------------------------------------------------------------------- */ |
1190 | * -------------------------------------------------------------------- */ |
1257 | #ifdef USE_XIM |
1191 | #ifdef USE_XIM |
1258 | |
1192 | |
1259 | void |
1193 | void |
|
|
1194 | rxvt_term::im_set_color (unsigned long &fg, unsigned long &bg) |
|
|
1195 | { |
|
|
1196 | fg = pix_colors[Color_fg]; |
|
|
1197 | bg = pix_colors[Color_bg]; |
|
|
1198 | } |
|
|
1199 | |
|
|
1200 | void |
1260 | rxvt_term::im_set_size (XRectangle *size) |
1201 | rxvt_term::im_set_size (XRectangle &size) |
1261 | { |
1202 | { |
|
|
1203 | // the int_bwidth terms make no sense to me |
1262 | size->x = TermWin.int_bwidth; |
1204 | size.x = TermWin.int_bwidth; |
1263 | size->y = TermWin.int_bwidth; |
1205 | size.y = TermWin.int_bwidth; |
1264 | size->width = Width2Pixel (TermWin.ncol); |
1206 | size.width = Width2Pixel (TermWin.ncol) + TermWin.int_bwidth; |
1265 | size->height = Height2Pixel (TermWin.nrow); |
1207 | size.height = Height2Pixel (TermWin.nrow) + TermWin.int_bwidth; |
1266 | } |
1208 | } |
1267 | |
1209 | |
1268 | void |
1210 | void |
1269 | rxvt_term::im_set_color (unsigned long *fg, unsigned long *bg) |
1211 | rxvt_term::im_set_preedit_area (XRectangle &preedit_rect, |
|
|
1212 | XRectangle &status_rect, |
|
|
1213 | const XRectangle &needed_rect) |
1270 | { |
1214 | { |
1271 | *fg = PixColors[Color_fg]; |
1215 | preedit_rect.x = needed_rect.width; |
1272 | *bg = PixColors[Color_bg]; |
1216 | preedit_rect.y = 0; |
|
|
1217 | preedit_rect.width = Width2Pixel (TermWin.ncol) - needed_rect.width + 1; |
|
|
1218 | preedit_rect.height = TermWin.fheight; |
|
|
1219 | |
|
|
1220 | status_rect.x = 0; |
|
|
1221 | status_rect.y = 0; |
|
|
1222 | status_rect.width = needed_rect.width ? needed_rect.width : Width2Pixel (TermWin.ncol) + 1; |
|
|
1223 | status_rect.height = TermWin.fheight; |
1273 | } |
1224 | } |
1274 | |
1225 | |
1275 | /* Checking whether input method is running. */ |
1226 | /* Checking whether input method is running. */ |
1276 | bool |
1227 | bool |
1277 | rxvt_term::IMisRunning () |
1228 | rxvt_term::IMisRunning () |
1278 | { |
1229 | { |
1279 | char *p; |
1230 | char *p; |
1280 | Atom atom; |
1231 | Atom atom; |
1281 | Window win; |
1232 | Window win; |
1282 | char server[IMBUFSIZ]; |
1233 | char server[IMBUFSIZ]; |
1283 | |
1234 | |
1284 | /* get current locale modifier */ |
1235 | /* get current locale modifier */ |
1285 | if ((p = XSetLocaleModifiers (NULL)) != NULL) |
1236 | if ((p = XSetLocaleModifiers (NULL)) != NULL) |
1286 | { |
1237 | { |
1287 | STRCPY (server, "@server="); |
1238 | strcpy (server, "@server="); |
1288 | STRNCAT (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */ |
1239 | strncat (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */ |
|
|
1240 | |
1289 | if ((p = STRCHR (server + 1, '@')) != NULL) /* first one only */ |
1241 | if ((p = strchr (server + 1, '@')) != NULL) /* first one only */ |
1290 | *p = '\0'; |
1242 | *p = '\0'; |
1291 | |
1243 | |
1292 | atom = XInternAtom (display->display, server, False); |
1244 | atom = XInternAtom (display->display, server, False); |
1293 | win = XGetSelectionOwner (display->display, atom); |
1245 | win = XGetSelectionOwner (display->display, atom); |
|
|
1246 | |
1294 | if (win != None) |
1247 | if (win != None) |
1295 | return True; |
1248 | return True; |
1296 | } |
1249 | } |
|
|
1250 | |
1297 | return False; |
1251 | return False; |
1298 | } |
1252 | } |
1299 | |
1253 | |
1300 | void |
1254 | void |
1301 | rxvt_term::IMSendSpot () |
1255 | rxvt_term::IMSendSpot () |
1302 | { |
1256 | { |
1303 | XPoint spot; |
1257 | XPoint spot; |
1304 | XVaNestedList preedit_attr; |
1258 | XVaNestedList preedit_attr; |
1305 | |
1259 | |
1306 | if (Input_Context == NULL |
1260 | if (!Input_Context |
|
|
1261 | || !TermWin.focus |
1307 | || !TermWin.focus || ! (input_style & XIMPreeditPosition) |
1262 | || !(input_style & XIMPreeditPosition) |
|
|
1263 | #if 0 |
1308 | || ! (event_type == KeyPress |
1264 | || !(event_type == KeyPress |
1309 | || event_type == Expose |
1265 | || event_type == Expose |
1310 | || event_type == NoExpose |
1266 | || event_type == NoExpose |
1311 | || event_type == SelectionNotify |
1267 | || event_type == SelectionNotify |
1312 | || event_type == ButtonRelease || event_type == FocusIn) |
1268 | || event_type == ButtonRelease || event_type == FocusIn) |
|
|
1269 | #endif |
1313 | || !IMisRunning ()) |
1270 | || !IMisRunning ()) |
1314 | return; |
1271 | return; |
1315 | |
1272 | |
1316 | im_set_position (&spot); |
1273 | im_set_position (spot); |
1317 | |
1274 | |
1318 | preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); |
1275 | preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); |
1319 | XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); |
1276 | XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); |
1320 | XFree (preedit_attr); |
1277 | XFree (preedit_attr); |
1321 | } |
1278 | } |
1322 | |
1279 | |
1323 | void |
1280 | void |
1324 | rxvt_term::im_set_preedit_area (XRectangle * preedit_rect, XRectangle * status_rect, |
|
|
1325 | XRectangle * needed_rect) |
|
|
1326 | { |
|
|
1327 | int mbh, vtx = 0; |
|
|
1328 | |
|
|
1329 | if (scrollbar_visible () && ! (Options & Opt_scrollBar_right)) |
|
|
1330 | vtx = scrollbar_TotalWidth (); |
|
|
1331 | |
|
|
1332 | mbh = menubar_visible () ? menuBar_TotalHeight () : 0; |
|
|
1333 | mbh -= TermWin.lineSpace; |
|
|
1334 | |
|
|
1335 | preedit_rect->x = needed_rect->width + vtx; |
|
|
1336 | preedit_rect->y = Height2Pixel (TermWin.nrow - 1) + mbh; |
|
|
1337 | |
|
|
1338 | preedit_rect->width = Width2Pixel (TermWin.ncol + 1) - needed_rect->width + vtx; |
|
|
1339 | preedit_rect->height = Height2Pixel (1); |
|
|
1340 | |
|
|
1341 | status_rect->x = vtx; |
|
|
1342 | status_rect->y = Height2Pixel (TermWin.nrow - 1) + mbh; |
|
|
1343 | |
|
|
1344 | status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel (TermWin.ncol + 1); |
|
|
1345 | status_rect->height = Height2Pixel (1); |
|
|
1346 | } |
|
|
1347 | |
|
|
1348 | void |
|
|
1349 | rxvt_term::im_destroy () |
1281 | rxvt_term::im_destroy () |
1350 | { |
1282 | { |
1351 | if (Input_Context) |
1283 | if (Input_Context) |
1352 | { |
1284 | { |
1353 | XDestroyIC (Input_Context); |
1285 | XDestroyIC (Input_Context); |
1354 | Input_Context = NULL; |
1286 | Input_Context = 0; |
1355 | } |
1287 | } |
1356 | |
1288 | |
1357 | if (input_method) |
1289 | if (input_method) |
1358 | { |
1290 | { |
1359 | display->put_xim (input_method); |
1291 | display->put_xim (input_method); |
… | |
… | |
1366 | * open a suitable preedit type |
1298 | * open a suitable preedit type |
1367 | */ |
1299 | */ |
1368 | bool |
1300 | bool |
1369 | rxvt_term::IM_get_IC (const char *modifiers) |
1301 | rxvt_term::IM_get_IC (const char *modifiers) |
1370 | { |
1302 | { |
1371 | int i, j, found; |
1303 | int i, j, found; |
1372 | XIM xim; |
1304 | XIM xim; |
1373 | XPoint spot; |
1305 | XPoint spot; |
1374 | XRectangle rect, status_rect, needed_rect; |
1306 | XRectangle rect, status_rect, needed_rect; |
1375 | unsigned long fg, bg; |
1307 | unsigned long fg, bg; |
1376 | const char *p; |
1308 | const char *p; |
1377 | char **s; |
1309 | char **s; |
1378 | XIMStyles *xim_styles; |
1310 | XIMStyles *xim_styles; |
1379 | XVaNestedList preedit_attr, status_attr; |
|
|
1380 | |
1311 | |
1381 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1312 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1382 | return false; |
1313 | return false; |
1383 | |
1314 | |
1384 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
1315 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
… | |
… | |
1390 | |
1321 | |
1391 | xim_styles = NULL; |
1322 | xim_styles = NULL; |
1392 | if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) |
1323 | if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) |
1393 | || !xim_styles || !xim_styles->count_styles) |
1324 | || !xim_styles || !xim_styles->count_styles) |
1394 | { |
1325 | { |
1395 | display->put_xim (input_method); |
1326 | im_destroy (); |
1396 | return false; |
1327 | return false; |
1397 | } |
1328 | } |
1398 | |
1329 | |
1399 | p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root"; |
1330 | p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root"; |
1400 | s = rxvt_splitcommastring (p); |
1331 | s = rxvt_splitcommastring (p); |
|
|
1332 | |
1401 | for (i = found = 0; !found && s[i]; i++) |
1333 | for (i = found = 0; !found && s[i]; i++) |
1402 | { |
1334 | { |
1403 | if (!STRCMP (s[i], "OverTheSpot")) |
1335 | if (!strcmp (s[i], "OverTheSpot")) |
1404 | input_style = (XIMPreeditPosition | XIMStatusNothing); |
1336 | input_style = (XIMPreeditPosition | XIMStatusNothing); |
1405 | else if (!STRCMP (s[i], "OffTheSpot")) |
1337 | else if (!strcmp (s[i], "OffTheSpot")) |
1406 | input_style = (XIMPreeditArea | XIMStatusArea); |
1338 | input_style = (XIMPreeditArea | XIMStatusArea); |
1407 | else if (!STRCMP (s[i], "Root")) |
1339 | else if (!strcmp (s[i], "Root")) |
1408 | input_style = (XIMPreeditNothing | XIMStatusNothing); |
1340 | input_style = (XIMPreeditNothing | XIMStatusNothing); |
1409 | |
1341 | |
1410 | for (j = 0; j < xim_styles->count_styles; j++) |
1342 | for (j = 0; j < xim_styles->count_styles; j++) |
1411 | if (input_style == xim_styles->supported_styles[j]) |
1343 | if (input_style == xim_styles->supported_styles[j]) |
1412 | { |
1344 | { |
… | |
… | |
1421 | free (s); |
1353 | free (s); |
1422 | XFree (xim_styles); |
1354 | XFree (xim_styles); |
1423 | |
1355 | |
1424 | if (!found) |
1356 | if (!found) |
1425 | { |
1357 | { |
1426 | display->put_xim (input_method); |
1358 | im_destroy (); |
1427 | return false; |
1359 | return false; |
1428 | } |
1360 | } |
1429 | |
1361 | |
1430 | preedit_attr = status_attr = NULL; |
1362 | XFontSet fs = 0; |
|
|
1363 | XVaNestedList preedit_attr = 0, status_attr = 0; |
|
|
1364 | |
|
|
1365 | if (input_style & (XIMPreeditPosition | XIMPreeditArea)) |
|
|
1366 | { |
|
|
1367 | // fake us a font-set, please |
|
|
1368 | char **missing_charset_list; |
|
|
1369 | int missing_charset_count; |
|
|
1370 | char *def_string; |
|
|
1371 | char pat[512]; |
|
|
1372 | |
|
|
1373 | sprintf (pat, |
|
|
1374 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
|
|
1375 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
|
|
1376 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
|
|
1377 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
|
|
1378 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
|
|
1379 | "*", |
|
|
1380 | TermWin.fheight, |
|
|
1381 | TermWin.fheight + 1, TermWin.fheight - 1, |
|
|
1382 | TermWin.fheight - 2, TermWin.fheight + 2); |
|
|
1383 | |
|
|
1384 | fs = XCreateFontSet (display->display, pat, |
|
|
1385 | &missing_charset_list, &missing_charset_count, &def_string); |
|
|
1386 | |
|
|
1387 | if (missing_charset_list) |
|
|
1388 | XFreeStringList (missing_charset_list); |
|
|
1389 | |
|
|
1390 | if (!fs) |
|
|
1391 | { |
|
|
1392 | input_style &= ~(XIMPreeditPosition | XIMPreeditArea); |
|
|
1393 | rxvt_warn ("unable to create fontset for input method, try \"-pt Root\". Continuing.\n"); |
|
|
1394 | } |
|
|
1395 | } |
1431 | |
1396 | |
1432 | if (input_style & XIMPreeditPosition) |
1397 | if (input_style & XIMPreeditPosition) |
1433 | { |
1398 | { |
1434 | im_set_size (&rect); |
1399 | im_set_size (rect); |
1435 | im_set_position (&spot); |
1400 | im_set_position (spot); |
1436 | im_set_color (&fg, &bg); |
1401 | im_set_color (fg, bg); |
1437 | |
1402 | |
1438 | preedit_attr = XVaCreateNestedList (0, XNArea, &rect, |
1403 | preedit_attr = XVaCreateNestedList (0, |
|
|
1404 | XNForeground, fg, |
|
|
1405 | XNBackground, bg, |
|
|
1406 | XNArea, &rect, |
1439 | XNSpotLocation, &spot, |
1407 | XNSpotLocation, &spot, |
1440 | XNForeground, fg, XNBackground, bg, |
|
|
1441 | //XNFontSet, TermWin.fontset, |
1408 | XNFontSet, fs, |
1442 | NULL); |
1409 | NULL); |
1443 | } |
1410 | } |
1444 | else if (input_style & XIMPreeditArea) |
1411 | else if (input_style & XIMPreeditArea) |
1445 | { |
1412 | { |
1446 | im_set_color (&fg, &bg); |
1413 | im_set_color (fg, bg); |
1447 | |
1414 | |
1448 | /* |
1415 | /* |
1449 | * The necessary width of preedit area is unknown |
1416 | * The necessary width of preedit area is unknown |
1450 | * until create input context. |
1417 | * until create input context. |
1451 | */ |
1418 | */ |
1452 | needed_rect.width = 0; |
1419 | needed_rect.width = 0; |
1453 | |
|
|
1454 | im_set_preedit_area (&rect, &status_rect, &needed_rect); |
1420 | im_set_preedit_area (rect, status_rect, needed_rect); |
1455 | |
1421 | |
1456 | preedit_attr = XVaCreateNestedList (0, XNArea, &rect, |
1422 | preedit_attr = XVaCreateNestedList (0, |
|
|
1423 | XNForeground, fg, |
1457 | XNForeground, fg, XNBackground, bg, |
1424 | XNBackground, bg, |
|
|
1425 | XNArea, &rect, |
|
|
1426 | XNFontSet, fs, |
|
|
1427 | NULL); |
|
|
1428 | status_attr = XVaCreateNestedList (0, |
|
|
1429 | XNForeground, fg, |
|
|
1430 | XNBackground, bg, |
|
|
1431 | XNArea, &status_rect, |
1458 | //XNFontSet, TermWin.fontset, |
1432 | XNFontSet, fs, |
1459 | NULL); |
1433 | NULL); |
1460 | status_attr = XVaCreateNestedList (0, XNArea, &status_rect, |
|
|
1461 | XNForeground, fg, XNBackground, bg, |
|
|
1462 | //XNFontSet, TermWin.fontset, |
|
|
1463 | NULL); |
|
|
1464 | } |
1434 | } |
1465 | |
1435 | |
1466 | Input_Context = XCreateIC (xim, XNInputStyle, input_style, |
1436 | Input_Context = XCreateIC (xim, |
|
|
1437 | XNInputStyle, input_style, |
1467 | XNClientWindow, TermWin.parent[0], |
1438 | XNClientWindow, TermWin.vt, |
1468 | XNFocusWindow, TermWin.parent[0], |
1439 | XNFocusWindow, TermWin.parent[0], |
1469 | preedit_attr ? XNPreeditAttributes : NULL, |
1440 | preedit_attr ? XNPreeditAttributes : NULL, |
1470 | preedit_attr, |
1441 | preedit_attr, |
1471 | status_attr ? XNStatusAttributes : NULL, |
1442 | status_attr ? XNStatusAttributes : NULL, |
1472 | status_attr, NULL); |
1443 | status_attr, NULL); |
|
|
1444 | |
1473 | if (preedit_attr) XFree (preedit_attr); |
1445 | if (preedit_attr) XFree (preedit_attr); |
1474 | if (status_attr) XFree (status_attr); |
1446 | if (status_attr) XFree (status_attr); |
|
|
1447 | if (fs) XFreeFontSet (display->display, fs); |
1475 | |
1448 | |
1476 | if (Input_Context == NULL) |
1449 | if (Input_Context == NULL) |
1477 | { |
1450 | { |
1478 | rxvt_warn ("failed to create input context, continuing without XIM.\n"); |
1451 | rxvt_warn ("failed to create input context, continuing without XIM.\n"); |
1479 | display->put_xim (input_method); |
1452 | im_destroy (); |
1480 | return false; |
1453 | return false; |
1481 | } |
1454 | } |
1482 | |
1455 | |
1483 | if (input_style & XIMPreeditArea) |
1456 | if (input_style & XIMPreeditArea) |
1484 | IMSetStatusPosition (); |
1457 | IMSetStatusPosition (); |
… | |
… | |
1514 | s = rxvt_splitcommastring (p); |
1487 | s = rxvt_splitcommastring (p); |
1515 | for (i = 0; s[i]; i++) |
1488 | for (i = 0; s[i]; i++) |
1516 | { |
1489 | { |
1517 | if (*s[i]) |
1490 | if (*s[i]) |
1518 | { |
1491 | { |
1519 | STRCPY (buf, "@im="); |
1492 | strcpy (buf, "@im="); |
1520 | STRNCAT (buf, s[i], IMBUFSIZ - 5); |
1493 | strncat (buf, s[i], IMBUFSIZ - 5); |
1521 | if (IM_get_IC (buf)) |
1494 | if (IM_get_IC (buf)) |
1522 | { |
1495 | { |
1523 | found = true; |
1496 | found = true; |
1524 | break; |
1497 | break; |
1525 | } |
1498 | } |
… | |
… | |
1549 | } |
1522 | } |
1550 | |
1523 | |
1551 | void |
1524 | void |
1552 | rxvt_term::IMSetStatusPosition () |
1525 | rxvt_term::IMSetStatusPosition () |
1553 | { |
1526 | { |
1554 | XRectangle preedit_rect, status_rect, *needed_rect; |
1527 | XRectangle preedit_rect, status_rect, *needed_rect; |
1555 | XVaNestedList preedit_attr, status_attr; |
1528 | XVaNestedList preedit_attr, status_attr; |
1556 | |
1529 | |
1557 | if (Input_Context == NULL |
1530 | if (!Input_Context |
|
|
1531 | || !TermWin.focus |
1558 | || !TermWin.focus || ! (input_style & XIMPreeditArea) |
1532 | || !(input_style & XIMPreeditArea) |
1559 | || !IMisRunning ()) |
1533 | || !IMisRunning ()) |
1560 | return; |
1534 | return; |
1561 | |
1535 | |
1562 | /* Getting the necessary width of preedit area */ |
1536 | /* Getting the necessary width of preedit area */ |
1563 | status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL); |
1537 | status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL); |
1564 | XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL); |
1538 | XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL); |
1565 | XFree (status_attr); |
1539 | XFree (status_attr); |
1566 | |
1540 | |
1567 | im_set_preedit_area (&preedit_rect, &status_rect, needed_rect); |
1541 | im_set_preedit_area (preedit_rect, status_rect, *needed_rect); |
|
|
1542 | XFree (needed_rect); |
1568 | |
1543 | |
1569 | preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL); |
1544 | preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL); |
1570 | status_attr = XVaCreateNestedList (0, XNArea, &status_rect, NULL); |
1545 | status_attr = XVaCreateNestedList (0, XNArea, &status_rect, NULL); |
1571 | |
1546 | |
1572 | XSetICValues (Input_Context, |
1547 | XSetICValues (Input_Context, |
1573 | XNPreeditAttributes, preedit_attr, |
1548 | XNPreeditAttributes, preedit_attr, |
1574 | XNStatusAttributes, status_attr, NULL); |
1549 | XNStatusAttributes, status_attr, NULL); |
1575 | |
1550 | |
1576 | XFree (preedit_attr); |
1551 | XFree (preedit_attr); |
1577 | XFree (status_attr); |
1552 | XFree (status_attr); |
1578 | } |
1553 | } |
1579 | #endif /* USE_XIM */ |
1554 | #endif /* USE_XIM */ |