… | |
… | |
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 |
… | |
… | |
122 | |
122 | |
123 | return len; |
123 | return len; |
124 | |
124 | |
125 | } |
125 | } |
126 | #endif |
126 | #endif |
127 | |
|
|
128 | void * |
|
|
129 | rxvt_term::operator new (size_t s) |
|
|
130 | { |
|
|
131 | void *p = malloc (s); |
|
|
132 | |
|
|
133 | MEMSET (p, 0, s); |
|
|
134 | return p; |
|
|
135 | } |
|
|
136 | |
|
|
137 | void |
|
|
138 | rxvt_term::operator delete (void *p, size_t s) |
|
|
139 | { |
|
|
140 | free (p); |
|
|
141 | } |
|
|
142 | |
127 | |
143 | rxvt_term::rxvt_term () |
128 | rxvt_term::rxvt_term () |
144 | : |
129 | : |
145 | #if TRANSPARENT |
130 | #if TRANSPARENT |
146 | rootwin_ev (this, &rxvt_term::rootwin_cb), |
131 | rootwin_ev (this, &rxvt_term::rootwin_cb), |
… | |
… | |
187 | |
172 | |
188 | rxvt_term::~rxvt_term () |
173 | rxvt_term::~rxvt_term () |
189 | { |
174 | { |
190 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
175 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
191 | |
176 | |
192 | if (cmd_fd >= 0) |
177 | if (cmd_pid) |
193 | close (cmd_fd); |
178 | kill (-cmd_pid, SIGHUP); |
194 | |
179 | |
195 | #ifndef NO_SETOWNER_TTYDEV |
180 | pty.put (); |
196 | privileged_ttydev (RESTORE); |
181 | |
197 | #endif |
|
|
198 | #ifdef UTMP_SUPPORT |
182 | #ifdef UTMP_SUPPORT |
199 | privileged_utmp (RESTORE); |
183 | privileged_utmp (RESTORE); |
200 | #endif |
184 | #endif |
201 | |
185 | |
|
|
186 | #if ENABLE_STYLES |
|
|
187 | for (int i = RS_styleCount; --i; ) |
|
|
188 | if (TermWin.fontset[i] != TermWin.fontset[0]) |
|
|
189 | delete TermWin.fontset[i]; |
|
|
190 | #endif |
202 | delete TermWin.fontset; |
191 | delete TermWin.fontset[0]; |
203 | |
192 | |
204 | if (display) |
193 | if (display) |
205 | { |
194 | { |
206 | selection_clear (); |
195 | selection_clear (); |
207 | |
196 | |
208 | #ifdef USE_XIM |
197 | #ifdef USE_XIM |
209 | im_destroy (); |
198 | im_destroy (); |
210 | #endif |
199 | #endif |
211 | #ifdef MENUBAR |
200 | #ifdef MENUBAR |
212 | if (menubarGC) XFreeGC (display->display, menubarGC); |
201 | if (menubarGC) XFreeGC (display->display, menubarGC); |
213 | #endif |
202 | #endif |
214 | #ifdef XTERM_SCROLLBAR |
203 | #ifdef XTERM_SCROLLBAR |
215 | if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC); |
204 | if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC); |
216 | if (ShadowGC) XFreeGC (display->display, ShadowGC); |
205 | if (ShadowGC) XFreeGC (display->display, ShadowGC); |
217 | #endif |
206 | #endif |
… | |
… | |
248 | XDestroyWindow (display->display, TermWin.parent[0]); |
237 | XDestroyWindow (display->display, TermWin.parent[0]); |
249 | } |
238 | } |
250 | |
239 | |
251 | // TODO: free pixcolours, colours should become part of rxvt_display |
240 | // TODO: free pixcolours, colours should become part of rxvt_display |
252 | |
241 | |
253 | delete PixColorsFocused; |
242 | delete pix_colors_focused; |
254 | #ifdef OFF_FOCUS_FADING |
243 | #ifdef OFF_FOCUS_FADING |
255 | delete PixColorsUnFocused; |
244 | delete pix_colors_unfocused; |
256 | #endif |
245 | #endif |
257 | |
246 | |
258 | displays.put (display); |
247 | displays.put (display); |
259 | |
248 | |
260 | scr_release (); |
249 | scr_release (); |
… | |
… | |
282 | rxvt_term::destroy () |
271 | rxvt_term::destroy () |
283 | { |
272 | { |
284 | if (destroy_ev.active) |
273 | if (destroy_ev.active) |
285 | return; |
274 | return; |
286 | |
275 | |
|
|
276 | #if ENABLE_OVERLAY |
|
|
277 | scr_overlay_off (); |
|
|
278 | #endif |
|
|
279 | |
287 | if (display) |
280 | if (display) |
288 | { |
281 | { |
289 | #if USE_XIM |
282 | #if USE_XIM |
290 | im_ev.stop (display); |
283 | im_ev.stop (display); |
291 | #endif |
284 | #endif |
… | |
… | |
340 | SET_R (this); |
333 | SET_R (this); |
341 | |
334 | |
342 | if (!init_vars ()) |
335 | if (!init_vars ()) |
343 | return false; |
336 | return false; |
344 | |
337 | |
|
|
338 | init_secondary (); |
|
|
339 | |
|
|
340 | const char **cmd_argv = init_resources (argc, argv); |
|
|
341 | |
|
|
342 | set_locale (""); |
|
|
343 | |
|
|
344 | #if MENUBAR_MAX |
|
|
345 | menubar_read (rs[Rs_menu]); |
|
|
346 | #endif |
|
|
347 | #ifdef HAVE_SCROLLBARS |
|
|
348 | if (options & Opt_scrollBar) |
|
|
349 | scrollBar.setIdle (); /* set existence for size calculations */ |
|
|
350 | #endif |
|
|
351 | |
|
|
352 | create_windows (argc, argv); |
|
|
353 | |
|
|
354 | init_xlocale (); |
|
|
355 | |
|
|
356 | scr_reset (); /* initialize screen */ |
|
|
357 | |
|
|
358 | #if 0 |
|
|
359 | XSynchronize (display->display, True); |
|
|
360 | #endif |
|
|
361 | |
|
|
362 | #ifdef HAVE_SCROLLBARS |
|
|
363 | if (options & Opt_scrollBar) |
|
|
364 | resize_scrollbar (); /* create and map scrollbar */ |
|
|
365 | #endif |
|
|
366 | #if (MENUBAR_MAX) |
|
|
367 | if (menubar_visible ()) |
|
|
368 | XMapWindow (display->display, menuBar.win); |
|
|
369 | #endif |
|
|
370 | #ifdef TRANSPARENT |
|
|
371 | if (options & Opt_transparent) |
|
|
372 | { |
|
|
373 | XSelectInput (display->display, display->root, PropertyChangeMask); |
|
|
374 | check_our_parents (); |
|
|
375 | rootwin_ev.start (display, display->root); |
|
|
376 | } |
|
|
377 | #endif |
|
|
378 | |
|
|
379 | XMapWindow (display->display, TermWin.vt); |
|
|
380 | XMapWindow (display->display, TermWin.parent[0]); |
|
|
381 | |
|
|
382 | set_colorfgbg (); |
|
|
383 | |
|
|
384 | init_command (cmd_argv); |
|
|
385 | |
|
|
386 | pty_ev.start (pty.pty, EVENT_READ); |
|
|
387 | |
|
|
388 | check_ev.start (); |
|
|
389 | |
|
|
390 | return true; |
|
|
391 | } |
|
|
392 | |
|
|
393 | static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event); |
|
|
394 | |
|
|
395 | void |
|
|
396 | rxvt_init () |
|
|
397 | { |
|
|
398 | /* install exit handler for cleanup */ |
|
|
399 | #if 0 |
|
|
400 | #ifdef HAVE_ATEXIT |
|
|
401 | atexit (rxvt_clean_exit); |
|
|
402 | #else |
|
|
403 | #endif |
|
|
404 | #endif |
345 | /* |
405 | /* |
346 | * Save and then give up any super-user privileges |
406 | * Save and then give up any super-user privileges |
347 | * If we need privileges in any area then we must specifically request it. |
407 | * If we need privileges in any area then we must specifically request it. |
348 | * We should only need to be root in these cases: |
408 | * We should only need to be root in these cases: |
349 | * 1. write utmp entries on some systems |
409 | * 1. write utmp entries on some systems |
350 | * 2. chown tty on some systems |
410 | * 2. chown tty on some systems |
351 | */ |
411 | */ |
352 | privileges (SAVE); |
412 | rxvt_privileges (SAVE); |
353 | privileges (IGNORE); |
413 | 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 | |
414 | |
421 | struct sigaction sa; |
415 | struct sigaction sa; |
422 | |
416 | |
423 | sigfillset (&sa.sa_mask); |
417 | sigfillset (&sa.sa_mask); |
424 | sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; |
418 | sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; |
… | |
… | |
452 | break; |
446 | break; |
453 | } |
447 | } |
454 | } |
448 | } |
455 | |
449 | |
456 | /* ARGSUSED */ |
450 | /* ARGSUSED */ |
457 | /* EXTPROTO */ |
451 | /* INTPROTO */ |
458 | RETSIGTYPE |
452 | RETSIGTYPE |
459 | rxvt_Child_signal (int sig __attribute__ ((unused))) |
453 | rxvt_Child_signal (int sig __attribute__ ((unused))) |
460 | { |
454 | { |
461 | int pid, save_errno = errno; |
455 | int pid, save_errno = errno; |
462 | |
456 | |
… | |
… | |
467 | } |
461 | } |
468 | |
462 | |
469 | /* |
463 | /* |
470 | * Catch a fatal signal and tidy up before quitting |
464 | * Catch a fatal signal and tidy up before quitting |
471 | */ |
465 | */ |
472 | /* EXTPROTO */ |
466 | /* INTPROTO */ |
473 | RETSIGTYPE |
467 | RETSIGTYPE |
474 | rxvt_Exit_signal (int sig) |
468 | rxvt_Exit_signal (int sig) |
475 | { |
469 | { |
476 | signal (sig, SIG_DFL); |
470 | signal (sig, SIG_DFL); |
477 | #ifdef DEBUG_CMD |
471 | #ifdef DEBUG_CMD |
… | |
… | |
499 | /*----------------------------------------------------------------------*/ |
493 | /*----------------------------------------------------------------------*/ |
500 | /* |
494 | /* |
501 | * Exit gracefully, clearing the utmp entry and restoring tty attributes |
495 | * Exit gracefully, clearing the utmp entry and restoring tty attributes |
502 | * TODO: if debugging, this should free up any known resources if we can |
496 | * TODO: if debugging, this should free up any known resources if we can |
503 | */ |
497 | */ |
504 | /* EXTPROTO */ |
498 | /* INTPROTO */ |
505 | void |
499 | void |
506 | rxvt_clean_exit () |
500 | rxvt_clean_exit () |
507 | { |
501 | { |
508 | // TODO: rxvtd should clean up all ressources |
502 | // TODO: rxvtd should clean up all ressources |
509 | if (GET_R) |
503 | if (GET_R) |
… | |
… | |
511 | } |
505 | } |
512 | |
506 | |
513 | /* ------------------------------------------------------------------------- * |
507 | /* ------------------------------------------------------------------------- * |
514 | * MEMORY ALLOCATION WRAPPERS * |
508 | * MEMORY ALLOCATION WRAPPERS * |
515 | * ------------------------------------------------------------------------- */ |
509 | * ------------------------------------------------------------------------- */ |
516 | /* EXTPROTO */ |
510 | /* INTPROTO */ |
517 | void * |
511 | void * |
518 | rxvt_malloc (size_t size) |
512 | rxvt_malloc (size_t size) |
519 | { |
513 | { |
520 | void *p; |
514 | void *p; |
521 | |
515 | |
522 | p = malloc (size); |
516 | p = malloc (size); |
523 | if (p) |
517 | if (p) |
524 | return p; |
518 | return p; |
525 | |
519 | |
526 | fprintf (stderr, RESNAME ": memory allocation failure. Aborting"); |
520 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
527 | rxvt_clean_exit (); |
|
|
528 | exit (EXIT_FAILURE); |
|
|
529 | /* NOTREACHED */ |
521 | /* NOTREACHED */ |
530 | } |
522 | } |
531 | |
523 | |
532 | /* EXTPROTO */ |
524 | /* INTPROTO */ |
533 | void * |
525 | void * |
534 | rxvt_calloc (size_t number, size_t size) |
526 | rxvt_calloc (size_t number, size_t size) |
535 | { |
527 | { |
536 | void *p; |
528 | void *p; |
537 | |
529 | |
538 | p = calloc (number, size); |
530 | p = calloc (number, size); |
539 | if (p) |
531 | if (p) |
540 | return p; |
532 | return p; |
541 | |
533 | |
542 | fprintf (stderr, RESNAME ": memory allocation failure. Aborting"); |
534 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
543 | rxvt_clean_exit (); |
|
|
544 | exit (EXIT_FAILURE); |
|
|
545 | /* NOTREACHED */ |
535 | /* NOTREACHED */ |
546 | } |
536 | } |
547 | |
537 | |
548 | /* EXTPROTO */ |
538 | /* INTPROTO */ |
549 | void * |
539 | void * |
550 | rxvt_realloc (void *ptr, size_t size) |
540 | rxvt_realloc (void *ptr, size_t size) |
551 | { |
541 | { |
552 | void *p; |
542 | void *p; |
553 | |
543 | |
554 | if (ptr) |
544 | if (ptr) |
555 | p = realloc (ptr, size); |
545 | p = realloc (ptr, size); |
556 | else |
546 | else |
557 | p = malloc (size); |
547 | p = malloc (size); |
|
|
548 | |
558 | if (p) |
549 | if (p) |
559 | return p; |
550 | return p; |
560 | |
551 | |
561 | fprintf (stderr, RESNAME ": memory allocation failure. Aborting"); |
552 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
562 | rxvt_clean_exit (); |
|
|
563 | exit (EXIT_FAILURE); |
|
|
564 | /* NOTREACHED */ |
553 | /* NOTREACHED */ |
565 | } |
554 | } |
566 | |
555 | |
567 | /* ------------------------------------------------------------------------- * |
556 | /* ------------------------------------------------------------------------- * |
568 | * PRIVILEGED OPERATIONS * |
557 | * PRIVILEGED OPERATIONS * |
569 | * ------------------------------------------------------------------------- */ |
558 | * ------------------------------------------------------------------------- */ |
570 | /* take care of suid/sgid super-user (root) privileges */ |
559 | /* take care of suid/sgid super-user (root) privileges */ |
571 | void |
560 | void |
572 | rxvt_term::privileges (int mode) |
561 | rxvt_privileges (rxvt_privaction action) |
573 | { |
562 | { |
|
|
563 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
564 | static uid_t euid; |
|
|
565 | static gid_t egid; |
|
|
566 | #endif |
|
|
567 | |
574 | #if ! defined(__CYGWIN32__) |
568 | #if ! defined(__CYGWIN32__) |
575 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
569 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
576 | /* setreuid () is the poor man's setuid (), seteuid () */ |
570 | /* setreuid () is the poor man's setuid (), seteuid () */ |
577 | # define seteuid(a) setreuid(-1, (a)) |
571 | # define seteuid(a) setreuid(-1, (a)) |
578 | # define setegid(a) setregid(-1, (a)) |
572 | # define setegid(a) setregid(-1, (a)) |
579 | # define HAVE_SETEUID |
573 | # define HAVE_SETEUID |
580 | # endif |
574 | # endif |
581 | # ifdef HAVE_SETEUID |
575 | # ifdef HAVE_SETEUID |
582 | switch (mode) |
576 | switch (action) |
583 | { |
577 | { |
584 | case IGNORE: |
578 | case IGNORE: |
585 | /* |
579 | /* |
586 | * change effective uid/gid - not real uid/gid - so we can switch |
580 | * change effective uid/gid - not real uid/gid - so we can switch |
587 | * back to root later, as required |
581 | * back to root later, as required |
… | |
… | |
597 | seteuid (euid); |
591 | seteuid (euid); |
598 | setegid (egid); |
592 | setegid (egid); |
599 | break; |
593 | break; |
600 | } |
594 | } |
601 | # else |
595 | # else |
602 | switch (mode) |
596 | switch (action) |
603 | { |
597 | { |
604 | case IGNORE: |
598 | case IGNORE: |
605 | setuid (getuid ()); |
599 | setuid (getuid ()); |
606 | setgid (getgid ()); |
600 | setgid (getgid ()); |
607 | /* FALLTHROUGH */ |
601 | /* FALLTHROUGH */ |
… | |
… | |
614 | #endif |
608 | #endif |
615 | } |
609 | } |
616 | |
610 | |
617 | #ifdef UTMP_SUPPORT |
611 | #ifdef UTMP_SUPPORT |
618 | void |
612 | void |
619 | rxvt_term::privileged_utmp (char action) |
613 | rxvt_term::privileged_utmp (rxvt_privaction action) |
620 | { |
614 | { |
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) |
615 | if ((options & Opt_utmpInhibit) |
625 | || ttydev == NULL || *ttydev == '\0') |
616 | || !pty.name || !*pty.name) |
626 | return; |
617 | return; |
627 | |
618 | |
628 | privileges (RESTORE); |
619 | rxvt_privileges (RESTORE); |
|
|
620 | |
629 | if (action == SAVE) |
621 | if (action == SAVE) |
630 | { |
|
|
631 | next_utmp_action = RESTORE; |
|
|
632 | makeutent (ttydev, rs[Rs_display_name]); |
622 | makeutent (pty.name, rs[Rs_display_name]); |
633 | } |
|
|
634 | else |
623 | else |
635 | { /* action == RESTORE */ |
|
|
636 | next_utmp_action = IGNORE; |
|
|
637 | cleanutent (); |
624 | cleanutent (); |
638 | } |
625 | |
639 | privileges (IGNORE); |
626 | 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 | } |
627 | } |
700 | #endif |
628 | #endif |
701 | |
629 | |
702 | /*----------------------------------------------------------------------*/ |
630 | /*----------------------------------------------------------------------*/ |
703 | /* |
631 | /* |
… | |
… | |
774 | |
702 | |
775 | if (scrollbar_visible ()) |
703 | if (scrollbar_visible ()) |
776 | { |
704 | { |
777 | sb_w = scrollbar_TotalWidth (); |
705 | sb_w = scrollbar_TotalWidth (); |
778 | szHint.base_width += sb_w; |
706 | szHint.base_width += sb_w; |
779 | if (!(Options & Opt_scrollBar_right)) |
707 | if (!(options & Opt_scrollBar_right)) |
780 | window_vt_x += sb_w; |
708 | window_vt_x += sb_w; |
781 | } |
709 | } |
782 | |
710 | |
783 | if (menubar_visible ()) |
711 | if (menubar_visible ()) |
784 | { |
712 | { |
… | |
… | |
812 | { |
740 | { |
813 | MIN_IT (TermWin.height, max_height); |
741 | MIN_IT (TermWin.height, max_height); |
814 | szHint.height = szHint.base_height + TermWin.height; |
742 | szHint.height = szHint.base_height + TermWin.height; |
815 | } |
743 | } |
816 | |
744 | |
817 | if (scrollbar_visible () && (Options & Opt_scrollBar_right)) |
745 | if (scrollbar_visible () && (options & Opt_scrollBar_right)) |
818 | window_sb_x = szHint.width - sb_w; |
746 | window_sb_x = szHint.width - sb_w; |
819 | |
747 | |
820 | if (recalc_x) |
748 | if (recalc_x) |
821 | szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) |
749 | szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) |
822 | - szHint.width - 2 * TermWin.ext_bwidth); |
750 | - szHint.width - 2 * TermWin.ext_bwidth); |
… | |
… | |
838 | * Called after a window size change. |
766 | * Called after a window size change. |
839 | */ |
767 | */ |
840 | void |
768 | void |
841 | rxvt_term::tt_winch () |
769 | rxvt_term::tt_winch () |
842 | { |
770 | { |
|
|
771 | if (pty.pty < 0) |
|
|
772 | return; |
|
|
773 | |
843 | struct winsize ws; |
774 | struct winsize ws; |
844 | |
|
|
845 | if (cmd_fd < 0) |
|
|
846 | return; |
|
|
847 | |
775 | |
848 | ws.ws_col = TermWin.ncol; |
776 | ws.ws_col = TermWin.ncol; |
849 | ws.ws_row = TermWin.nrow; |
777 | ws.ws_row = TermWin.nrow; |
850 | ws.ws_xpixel = ws.ws_ypixel = 0; |
778 | ws.ws_xpixel = TermWin.width; |
851 | #ifndef DEBUG_SIZE |
779 | ws.ws_ypixel = TermWin.height; |
852 | (void)ioctl (cmd_fd, TIOCSWINSZ, &ws); |
780 | (void)ioctl (pty.pty, TIOCSWINSZ, &ws); |
853 | #else |
781 | |
854 | if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0) |
782 | #if 0 |
855 | D_SIZE ((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); |
783 | // TIOCSWINSZ⎈ is supposed to do this automatically and correctly |
856 | # ifdef SIGWINCH |
|
|
857 | else if (cmd_pid) /* force through to the command */ |
784 | if (cmd_pid) /* force through to the command */ |
858 | kill (cmd_pid, SIGWINCH); |
785 | kill (cmd_pid, SIGWINCH); |
859 | # endif |
|
|
860 | #endif |
786 | #endif |
861 | } |
787 | } |
862 | |
788 | |
863 | /*----------------------------------------------------------------------*/ |
789 | /*----------------------------------------------------------------------*/ |
864 | /* rxvt_change_font () - Switch to a new font */ |
790 | /* set_fonts () - load and set the various fonts |
865 | /* |
791 | /* |
866 | * init = 1 - initialize |
792 | * init = 1 - initialize |
867 | * |
793 | * |
868 | * fontname == FONT_UP - switch to bigger font |
794 | * fontname == FONT_UP - switch to bigger font |
869 | * fontname == FONT_DN - switch to smaller font |
795 | * fontname == FONT_DN - switch to smaller font |
870 | */ |
796 | */ |
871 | bool |
797 | bool |
872 | rxvt_term::change_font (const char *fontname) |
798 | rxvt_term::set_fonts () |
873 | { |
799 | { |
874 | if (fontname == FONT_UP) |
|
|
875 | { |
|
|
876 | // TODO |
|
|
877 | } |
|
|
878 | else if (fontname == FONT_DN) |
|
|
879 | { |
|
|
880 | // TODO |
|
|
881 | } |
|
|
882 | else |
|
|
883 | { |
|
|
884 | rxvt_fontset *fs = new rxvt_fontset (this); |
800 | rxvt_fontset *fs = new rxvt_fontset (this); |
|
|
801 | rxvt_fontprop prop; |
885 | |
802 | |
886 | if (fs && fs->populate (fontname ? fontname : "fixed")) |
803 | prop.width = prop.height = prop.weight = prop.slant |
|
|
804 | = rxvt_fontprop::unset; |
|
|
805 | |
|
|
806 | if (!fs |
|
|
807 | || !fs->populate (rs[Rs_font] ? rs[Rs_font] : "fixed", prop) |
|
|
808 | || !fs->realize_font (1)) |
|
|
809 | { |
|
|
810 | delete fs; |
|
|
811 | return false; |
|
|
812 | } |
|
|
813 | |
|
|
814 | #if ENABLE_STYLES |
|
|
815 | for (int i = RS_styleCount; --i; ) |
|
|
816 | if (TermWin.fontset[i] != TermWin.fontset[0]) |
|
|
817 | delete TermWin.fontset[i]; |
|
|
818 | #endif |
|
|
819 | |
|
|
820 | delete TermWin.fontset[0]; |
|
|
821 | TermWin.fontset[0] = fs; |
|
|
822 | |
|
|
823 | fs->prop = prop = (*fs)[1]->properties (); |
|
|
824 | |
|
|
825 | TermWin.fwidth = prop.width; |
|
|
826 | TermWin.fheight = prop.height; |
|
|
827 | TermWin.fweight = prop.weight; |
|
|
828 | TermWin.fslant = prop.slant; |
|
|
829 | TermWin.fbase = (*fs)[1]->ascent; |
|
|
830 | |
|
|
831 | for (int style = 1; style < 4; style++) |
|
|
832 | { |
|
|
833 | #if ENABLE_STYLES |
|
|
834 | const char *res = rs[Rs_font + style]; |
|
|
835 | |
|
|
836 | if (res && !*res) |
|
|
837 | TermWin.fontset[style] = TermWin.fontset[0]; |
|
|
838 | else |
887 | { |
839 | { |
888 | delete TermWin.fontset; |
840 | TermWin.fontset[style] = fs = new rxvt_fontset (this); |
889 | TermWin.fontset = fs; |
841 | rxvt_fontprop prop2 = prop; |
890 | TermWin.fwidth = fs->base_font ()->width; |
|
|
891 | TermWin.fheight = fs->base_font ()->height; |
|
|
892 | TermWin.fbase = fs->base_font ()->ascent; |
|
|
893 | |
842 | |
894 | if (TermWin.parent[0]) |
843 | if (res) |
|
|
844 | prop2.weight = prop2.slant = rxvt_fontprop::unset; |
|
|
845 | else |
895 | { |
846 | { |
896 | resize_all_windows (0, 0, 0); |
847 | res = TermWin.fontset[0]->fontdesc; |
897 | scr_remap_chars (); |
848 | |
898 | scr_touch (true); |
849 | if (SET_STYLE (0, style) & RS_Bold) prop2.weight = rxvt_fontprop::bold; |
|
|
850 | if (SET_STYLE (0, style) & RS_Italic) prop2.slant = rxvt_fontprop::italic; |
899 | } |
851 | } |
900 | |
852 | |
901 | for (unicode_t ch = 0x20; ch <= 0x7f; ch++) |
853 | fs->populate (res, prop2); |
902 | TermWin.ascii_map [ch - 0x20] = fs->find_font (ch); |
|
|
903 | |
|
|
904 | return true; |
|
|
905 | } |
854 | } |
|
|
855 | #else |
|
|
856 | TermWin.fontset[style] = TermWin.fontset[0]; |
|
|
857 | #endif |
|
|
858 | } |
|
|
859 | |
|
|
860 | if (TermWin.parent[0]) |
906 | } |
861 | { |
|
|
862 | resize_all_windows (0, 0, 0); |
|
|
863 | scr_remap_chars (); |
|
|
864 | scr_touch (true); |
|
|
865 | } |
907 | |
866 | |
908 | return false; |
867 | return true; |
909 | } |
|
|
910 | |
|
|
911 | bool |
|
|
912 | rxvt_term::font_up_down (int n, int direction) |
|
|
913 | { |
|
|
914 | return false; |
|
|
915 | } |
868 | } |
916 | |
869 | |
917 | /*----------------------------------------------------------------------*/ |
870 | /*----------------------------------------------------------------------*/ |
918 | /*----------------------------------------------------------------------*/ |
871 | /*----------------------------------------------------------------------*/ |
919 | /* xterm sequences - title, iconName, color (exptl) */ |
872 | /* xterm sequences - title, iconName, color (exptl) */ |
… | |
… | |
924 | char *name; |
877 | char *name; |
925 | |
878 | |
926 | if (!XFetchName (display->display, TermWin.parent[0], &name)) |
879 | if (!XFetchName (display->display, TermWin.parent[0], &name)) |
927 | name = NULL; |
880 | name = NULL; |
928 | |
881 | |
929 | if (name == NULL || STRCMP (name, str)) |
882 | if (name == NULL || strcmp (name, str)) |
930 | #endif |
883 | #endif |
931 | XStoreName (display->display, TermWin.parent[0], str); |
884 | XStoreName (display->display, TermWin.parent[0], str); |
932 | |
885 | |
933 | #ifdef SMART_WINDOW_TITLE |
886 | #ifdef SMART_WINDOW_TITLE |
934 | if (name) |
887 | if (name) |
… | |
… | |
943 | char *name; |
896 | char *name; |
944 | |
897 | |
945 | if (!XGetIconName (display->display, TermWin.parent[0], &name)) |
898 | if (!XGetIconName (display->display, TermWin.parent[0], &name)) |
946 | name = NULL; |
899 | name = NULL; |
947 | |
900 | |
948 | if (name == NULL || STRCMP (name, str)) |
901 | if (name == NULL || strcmp (name, str)) |
949 | #endif |
902 | #endif |
950 | XSetIconName (display->display, TermWin.parent[0], str); |
903 | XSetIconName (display->display, TermWin.parent[0], str); |
951 | |
904 | |
952 | #ifdef SMART_WINDOW_TITLE |
905 | #ifdef SMART_WINDOW_TITLE |
953 | if (name) |
906 | if (name) |
… | |
… | |
971 | i = atoi (color); |
924 | i = atoi (color); |
972 | if (i >= 8 && i <= 15) |
925 | if (i >= 8 && i <= 15) |
973 | { /* bright colors */ |
926 | { /* bright colors */ |
974 | i -= 8; |
927 | i -= 8; |
975 | # ifndef NO_BRIGHTCOLOR |
928 | # ifndef NO_BRIGHTCOLOR |
976 | PixColorsFocused[idx] = PixColorsFocused[minBrightCOLOR + i]; |
929 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
977 | SET_PIXCOLOR (idx); |
930 | SET_PIXCOLOR (idx); |
978 | goto Done; |
931 | goto Done; |
979 | # endif |
932 | # endif |
980 | |
933 | |
981 | } |
934 | } |
982 | if (i >= 0 && i <= 7) |
935 | if (i >= 0 && i <= 7) |
983 | { /* normal colors */ |
936 | { /* normal colors */ |
984 | PixColorsFocused[idx] = PixColorsFocused[minCOLOR + i]; |
937 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
985 | SET_PIXCOLOR (idx); |
938 | SET_PIXCOLOR (idx); |
986 | goto Done; |
939 | goto Done; |
987 | } |
940 | } |
988 | } |
941 | } |
989 | |
942 | |
… | |
… | |
996 | * FIXME: should free colors here, but no idea how to do it so instead, |
949 | * FIXME: should free colors here, but no idea how to do it so instead, |
997 | * so just keep gobbling up the colormap |
950 | * so just keep gobbling up the colormap |
998 | */ |
951 | */ |
999 | # if 0 |
952 | # if 0 |
1000 | for (i = Color_Black; i <= Color_White; i++) |
953 | for (i = Color_Black; i <= Color_White; i++) |
1001 | if (PixColors[idx] == PixColors[i]) |
954 | if (pix_colors[idx] == pix_colors[i]) |
1002 | break; |
955 | break; |
1003 | if (i > Color_White) |
956 | if (i > Color_White) |
1004 | { |
957 | { |
1005 | /* fprintf (stderr, "XFreeColors: PixColors [%d] = %lu\n", idx, PixColors [idx]); */ |
958 | /* fprintf (stderr, "XFreeColors: pix_colors [%d] = %lu\n", idx, pix_colors [idx]); */ |
1006 | XFreeColors (display->display, display->cmap, (PixColors + idx), 1, |
959 | XFreeColors (display->display, display->cmap, (pix_colors + idx), 1, |
1007 | DisplayPlanes (display->display, display->screen)); |
960 | DisplayPlanes (display->display, display->screen)); |
1008 | } |
961 | } |
1009 | # endif |
962 | # endif |
1010 | |
963 | |
1011 | PixColorsFocused[idx] = xcol; |
964 | pix_colors_focused[idx] = xcol; |
1012 | SET_PIXCOLOR (idx); |
965 | SET_PIXCOLOR (idx); |
1013 | |
966 | |
1014 | /* XSetWindowAttributes attr; */ |
967 | /* XSetWindowAttributes attr; */ |
1015 | /* Cursor cursor; */ |
968 | /* Cursor cursor; */ |
1016 | Done: |
969 | Done: |
1017 | #ifdef OFF_FOCUS_FADING |
970 | #ifdef OFF_FOCUS_FADING |
|
|
971 | if (rs[Rs_fade]) |
1018 | PixColorsUnFocused[idx] = PixColorsFocused[idx].fade (display, atoi (rs[Rs_fade])); |
972 | pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade])); |
1019 | #endif |
973 | #endif |
1020 | if (idx == Color_bg && ! (Options & Opt_transparent)) |
|
|
1021 | XSetWindowBackground (display->display, TermWin.vt, PixColors[Color_bg]); |
|
|
1022 | |
974 | |
1023 | /* handle Color_BD, scrollbar background, etc. */ |
975 | /*TODO: handle Color_BD, scrollbar background, etc. */ |
1024 | |
976 | |
1025 | set_colorfgbg (); |
|
|
1026 | recolour_cursor (); |
977 | recolour_cursor (); |
1027 | scr_touch (true); |
978 | scr_recolour (); |
1028 | } |
979 | } |
1029 | |
980 | |
1030 | #else |
981 | #else |
1031 | # define set_window_color (idx,color) ((void)0) |
982 | # define set_window_color (idx,color) ((void)0) |
1032 | #endif /* XTERM_COLOR_CHANGE */ |
983 | #endif /* XTERM_COLOR_CHANGE */ |
… | |
… | |
1034 | void |
985 | void |
1035 | rxvt_term::recolour_cursor () |
986 | rxvt_term::recolour_cursor () |
1036 | { |
987 | { |
1037 | XColor xcol[2]; |
988 | XColor xcol[2]; |
1038 | |
989 | |
1039 | xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) ? PixColorsFocused[Color_pointer_fg] : PixColorsFocused[Color_fg]; |
990 | xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) |
1040 | xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) ? PixColorsFocused[Color_pointer_bg] : PixColorsFocused[Color_bg]; |
991 | ? pix_colors_focused[Color_pointer_fg] |
|
|
992 | : pix_colors_focused[Color_fg]; |
|
|
993 | xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) |
|
|
994 | ? pix_colors_focused[Color_pointer_bg] |
|
|
995 | : pix_colors_focused[Color_bg]; |
|
|
996 | |
1041 | XQueryColors (display->display, display->cmap, xcol, 2); |
997 | XQueryColors (display->display, display->cmap, xcol, 2); |
1042 | XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1); |
998 | XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1); |
1043 | } |
999 | } |
1044 | |
1000 | |
1045 | /*----------------------------------------------------------------------*/ |
1001 | /*----------------------------------------------------------------------*/ |
… | |
… | |
1047 | * find if fg/bg matches any of the normal (low-intensity) colors |
1003 | * find if fg/bg matches any of the normal (low-intensity) colors |
1048 | */ |
1004 | */ |
1049 | void |
1005 | void |
1050 | rxvt_term::set_colorfgbg () |
1006 | rxvt_term::set_colorfgbg () |
1051 | { |
1007 | { |
1052 | unsigned int i; |
1008 | unsigned int i; |
1053 | const char *xpmb = "\0"; |
1009 | const char *xpmb = "\0"; |
1054 | char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1]; |
1010 | char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1]; |
1055 | |
1011 | |
1056 | env_colorfgbg = |
|
|
1057 | (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1); |
1012 | env_colorfgbg = (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1); |
1058 | STRCPY (fstr, "default"); |
1013 | strcpy (fstr, "default"); |
1059 | STRCPY (bstr, "default"); |
1014 | strcpy (bstr, "default"); |
1060 | for (i = Color_Black; i <= Color_White; i++) |
1015 | for (i = Color_Black; i <= Color_White; i++) |
1061 | if (PixColors[Color_fg] == PixColors[i]) |
1016 | if (pix_colors[Color_fg] == pix_colors[i]) |
1062 | { |
1017 | { |
1063 | sprintf (fstr, "%d", (i - Color_Black)); |
1018 | sprintf (fstr, "%d", (i - Color_Black)); |
1064 | break; |
1019 | break; |
1065 | } |
1020 | } |
|
|
1021 | |
1066 | for (i = Color_Black; i <= Color_White; i++) |
1022 | for (i = Color_Black; i <= Color_White; i++) |
1067 | if (PixColors[Color_bg] == PixColors[i]) |
1023 | if (pix_colors[Color_bg] == pix_colors[i]) |
1068 | { |
1024 | { |
1069 | sprintf (bstr, "%d", (i - Color_Black)); |
1025 | sprintf (bstr, "%d", (i - Color_Black)); |
1070 | #ifdef XPM_BACKGROUND |
1026 | #ifdef XPM_BACKGROUND |
1071 | xpmb = "default;"; |
1027 | xpmb = "default;"; |
1072 | #endif |
1028 | #endif |
1073 | break; |
1029 | break; |
1074 | } |
1030 | } |
1075 | |
1031 | |
1076 | sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); |
1032 | sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); |
1077 | |
|
|
1078 | #ifndef NO_BRIGHTCOLOR |
|
|
1079 | colorfgbg = DEFAULT_RSTYLE; |
|
|
1080 | for (i = minCOLOR; i <= maxCOLOR; i++) |
|
|
1081 | { |
|
|
1082 | if (PixColors[Color_fg] == PixColors[i]) |
|
|
1083 | colorfgbg = SET_FGCOLOR (colorfgbg, i); |
|
|
1084 | if (PixColors[Color_bg] == PixColors[i]) |
|
|
1085 | colorfgbg = SET_BGCOLOR (colorfgbg, i); |
|
|
1086 | } |
|
|
1087 | #endif |
|
|
1088 | } |
1033 | } |
1089 | |
1034 | |
1090 | /*----------------------------------------------------------------------*/ |
1035 | /*----------------------------------------------------------------------*/ |
1091 | /* |
1036 | /* |
1092 | * Colour determination for low colour displays, routine from |
1037 | * Colour determination for low colour displays, routine from |
… | |
… | |
1255 | * - X INPUT METHOD ROUTINES - * |
1200 | * - X INPUT METHOD ROUTINES - * |
1256 | * -------------------------------------------------------------------- */ |
1201 | * -------------------------------------------------------------------- */ |
1257 | #ifdef USE_XIM |
1202 | #ifdef USE_XIM |
1258 | |
1203 | |
1259 | void |
1204 | void |
|
|
1205 | rxvt_term::im_set_color (unsigned long &fg, unsigned long &bg) |
|
|
1206 | { |
|
|
1207 | fg = pix_colors[Color_fg]; |
|
|
1208 | bg = pix_colors[Color_bg]; |
|
|
1209 | } |
|
|
1210 | |
|
|
1211 | void |
1260 | rxvt_term::im_set_size (XRectangle *size) |
1212 | rxvt_term::im_set_size (XRectangle &size) |
1261 | { |
1213 | { |
|
|
1214 | // the int_bwidth terms make no sense to me |
1262 | size->x = TermWin.int_bwidth; |
1215 | size.x = TermWin.int_bwidth; |
1263 | size->y = TermWin.int_bwidth; |
1216 | size.y = TermWin.int_bwidth; |
1264 | size->width = Width2Pixel (TermWin.ncol); |
1217 | size.width = Width2Pixel (TermWin.ncol) + TermWin.int_bwidth; |
1265 | size->height = Height2Pixel (TermWin.nrow); |
1218 | size.height = Height2Pixel (TermWin.nrow) + TermWin.int_bwidth; |
1266 | } |
1219 | } |
1267 | |
1220 | |
1268 | void |
1221 | void |
1269 | rxvt_term::im_set_color (unsigned long *fg, unsigned long *bg) |
1222 | rxvt_term::im_set_preedit_area (XRectangle &preedit_rect, |
|
|
1223 | XRectangle &status_rect, |
|
|
1224 | const XRectangle &needed_rect) |
1270 | { |
1225 | { |
1271 | *fg = PixColors[Color_fg]; |
1226 | preedit_rect.x = needed_rect.width; |
1272 | *bg = PixColors[Color_bg]; |
1227 | preedit_rect.y = 0; |
|
|
1228 | preedit_rect.width = Width2Pixel (TermWin.ncol) - needed_rect.width + 1; |
|
|
1229 | preedit_rect.height = TermWin.fheight; |
|
|
1230 | |
|
|
1231 | status_rect.x = 0; |
|
|
1232 | status_rect.y = 0; |
|
|
1233 | status_rect.width = needed_rect.width ? needed_rect.width : Width2Pixel (TermWin.ncol) + 1; |
|
|
1234 | status_rect.height = TermWin.fheight; |
1273 | } |
1235 | } |
1274 | |
1236 | |
1275 | /* Checking whether input method is running. */ |
1237 | /* Checking whether input method is running. */ |
1276 | bool |
1238 | bool |
1277 | rxvt_term::IMisRunning () |
1239 | rxvt_term::IMisRunning () |
1278 | { |
1240 | { |
1279 | char *p; |
1241 | char *p; |
1280 | Atom atom; |
1242 | Atom atom; |
1281 | Window win; |
1243 | Window win; |
1282 | char server[IMBUFSIZ]; |
1244 | char server[IMBUFSIZ]; |
1283 | |
1245 | |
1284 | /* get current locale modifier */ |
1246 | /* get current locale modifier */ |
1285 | if ((p = XSetLocaleModifiers (NULL)) != NULL) |
1247 | if ((p = XSetLocaleModifiers (NULL)) != NULL) |
1286 | { |
1248 | { |
1287 | STRCPY (server, "@server="); |
1249 | strcpy (server, "@server="); |
1288 | STRNCAT (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */ |
1250 | strncat (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */ |
|
|
1251 | |
1289 | if ((p = STRCHR (server + 1, '@')) != NULL) /* first one only */ |
1252 | if ((p = strchr (server + 1, '@')) != NULL) /* first one only */ |
1290 | *p = '\0'; |
1253 | *p = '\0'; |
1291 | |
1254 | |
1292 | atom = XInternAtom (display->display, server, False); |
1255 | atom = XInternAtom (display->display, server, False); |
1293 | win = XGetSelectionOwner (display->display, atom); |
1256 | win = XGetSelectionOwner (display->display, atom); |
|
|
1257 | |
1294 | if (win != None) |
1258 | if (win != None) |
1295 | return True; |
1259 | return True; |
1296 | } |
1260 | } |
|
|
1261 | |
1297 | return False; |
1262 | return False; |
1298 | } |
1263 | } |
1299 | |
1264 | |
1300 | void |
1265 | void |
1301 | rxvt_term::IMSendSpot () |
1266 | rxvt_term::IMSendSpot () |
1302 | { |
1267 | { |
1303 | XPoint spot; |
1268 | XPoint spot; |
1304 | XVaNestedList preedit_attr; |
1269 | XVaNestedList preedit_attr; |
1305 | |
1270 | |
1306 | if (Input_Context == NULL |
1271 | if (!Input_Context |
|
|
1272 | || !TermWin.focus |
1307 | || !TermWin.focus || ! (input_style & XIMPreeditPosition) |
1273 | || !(input_style & XIMPreeditPosition) |
|
|
1274 | #if 0 |
1308 | || ! (event_type == KeyPress |
1275 | || !(event_type == KeyPress |
1309 | || event_type == Expose |
1276 | || event_type == Expose |
1310 | || event_type == NoExpose |
1277 | || event_type == NoExpose |
1311 | || event_type == SelectionNotify |
1278 | || event_type == SelectionNotify |
1312 | || event_type == ButtonRelease || event_type == FocusIn) |
1279 | || event_type == ButtonRelease || event_type == FocusIn) |
|
|
1280 | #endif |
1313 | || !IMisRunning ()) |
1281 | || !IMisRunning ()) |
1314 | return; |
1282 | return; |
1315 | |
1283 | |
1316 | im_set_position (&spot); |
1284 | im_set_position (spot); |
1317 | |
1285 | |
1318 | preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); |
1286 | preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); |
1319 | XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); |
1287 | XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); |
1320 | XFree (preedit_attr); |
1288 | XFree (preedit_attr); |
1321 | } |
1289 | } |
1322 | |
1290 | |
1323 | void |
1291 | 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 () |
1292 | rxvt_term::im_destroy () |
1350 | { |
1293 | { |
1351 | if (Input_Context) |
1294 | if (Input_Context) |
1352 | { |
1295 | { |
1353 | XDestroyIC (Input_Context); |
1296 | XDestroyIC (Input_Context); |
1354 | Input_Context = NULL; |
1297 | Input_Context = 0; |
1355 | } |
1298 | } |
1356 | |
1299 | |
1357 | if (input_method) |
1300 | if (input_method) |
1358 | { |
1301 | { |
1359 | display->put_xim (input_method); |
1302 | display->put_xim (input_method); |
… | |
… | |
1366 | * open a suitable preedit type |
1309 | * open a suitable preedit type |
1367 | */ |
1310 | */ |
1368 | bool |
1311 | bool |
1369 | rxvt_term::IM_get_IC (const char *modifiers) |
1312 | rxvt_term::IM_get_IC (const char *modifiers) |
1370 | { |
1313 | { |
1371 | int i, j, found; |
1314 | int i, j, found; |
1372 | XIM xim; |
1315 | XIM xim; |
1373 | XPoint spot; |
1316 | XPoint spot; |
1374 | XRectangle rect, status_rect, needed_rect; |
1317 | XRectangle rect, status_rect, needed_rect; |
1375 | unsigned long fg, bg; |
1318 | unsigned long fg, bg; |
1376 | const char *p; |
1319 | const char *p; |
1377 | char **s; |
1320 | char **s; |
1378 | XIMStyles *xim_styles; |
1321 | XIMStyles *xim_styles; |
1379 | XVaNestedList preedit_attr, status_attr; |
|
|
1380 | |
1322 | |
1381 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1323 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1382 | return false; |
1324 | return false; |
1383 | |
1325 | |
1384 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
1326 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
… | |
… | |
1390 | |
1332 | |
1391 | xim_styles = NULL; |
1333 | xim_styles = NULL; |
1392 | if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) |
1334 | if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) |
1393 | || !xim_styles || !xim_styles->count_styles) |
1335 | || !xim_styles || !xim_styles->count_styles) |
1394 | { |
1336 | { |
1395 | display->put_xim (input_method); |
1337 | im_destroy (); |
1396 | return false; |
1338 | return false; |
1397 | } |
1339 | } |
1398 | |
1340 | |
1399 | p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root"; |
1341 | p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root"; |
1400 | s = rxvt_splitcommastring (p); |
1342 | s = rxvt_splitcommastring (p); |
|
|
1343 | |
1401 | for (i = found = 0; !found && s[i]; i++) |
1344 | for (i = found = 0; !found && s[i]; i++) |
1402 | { |
1345 | { |
1403 | if (!STRCMP (s[i], "OverTheSpot")) |
1346 | if (!strcmp (s[i], "OverTheSpot")) |
1404 | input_style = (XIMPreeditPosition | XIMStatusNothing); |
1347 | input_style = (XIMPreeditPosition | XIMStatusNothing); |
1405 | else if (!STRCMP (s[i], "OffTheSpot")) |
1348 | else if (!strcmp (s[i], "OffTheSpot")) |
1406 | input_style = (XIMPreeditArea | XIMStatusArea); |
1349 | input_style = (XIMPreeditArea | XIMStatusArea); |
1407 | else if (!STRCMP (s[i], "Root")) |
1350 | else if (!strcmp (s[i], "Root")) |
1408 | input_style = (XIMPreeditNothing | XIMStatusNothing); |
1351 | input_style = (XIMPreeditNothing | XIMStatusNothing); |
1409 | |
1352 | |
1410 | for (j = 0; j < xim_styles->count_styles; j++) |
1353 | for (j = 0; j < xim_styles->count_styles; j++) |
1411 | if (input_style == xim_styles->supported_styles[j]) |
1354 | if (input_style == xim_styles->supported_styles[j]) |
1412 | { |
1355 | { |
… | |
… | |
1421 | free (s); |
1364 | free (s); |
1422 | XFree (xim_styles); |
1365 | XFree (xim_styles); |
1423 | |
1366 | |
1424 | if (!found) |
1367 | if (!found) |
1425 | { |
1368 | { |
1426 | display->put_xim (input_method); |
1369 | im_destroy (); |
1427 | return false; |
1370 | return false; |
1428 | } |
1371 | } |
1429 | |
1372 | |
1430 | preedit_attr = status_attr = NULL; |
1373 | XFontSet fs = 0; |
|
|
1374 | XVaNestedList preedit_attr = 0, status_attr = 0; |
|
|
1375 | |
|
|
1376 | if (input_style & (XIMPreeditPosition | XIMPreeditArea)) |
|
|
1377 | { |
|
|
1378 | // fake us a font-set, please |
|
|
1379 | char **missing_charset_list; |
|
|
1380 | int missing_charset_count; |
|
|
1381 | char *def_string; |
|
|
1382 | char pat[512]; |
|
|
1383 | |
|
|
1384 | sprintf (pat, |
|
|
1385 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
|
|
1386 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
|
|
1387 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
|
|
1388 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
|
|
1389 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
|
|
1390 | "*", |
|
|
1391 | TermWin.fheight, |
|
|
1392 | TermWin.fheight + 1, TermWin.fheight - 1, |
|
|
1393 | TermWin.fheight - 2, TermWin.fheight + 2); |
|
|
1394 | |
|
|
1395 | fs = XCreateFontSet (display->display, pat, |
|
|
1396 | &missing_charset_list, &missing_charset_count, &def_string); |
|
|
1397 | |
|
|
1398 | if (missing_charset_list) |
|
|
1399 | XFreeStringList (missing_charset_list); |
|
|
1400 | |
|
|
1401 | if (!fs) |
|
|
1402 | { |
|
|
1403 | input_style &= ~(XIMPreeditPosition | XIMPreeditArea); |
|
|
1404 | rxvt_warn ("unable to create fontset for input method, try \"-pt Root\". Continuing.\n"); |
|
|
1405 | } |
|
|
1406 | } |
1431 | |
1407 | |
1432 | if (input_style & XIMPreeditPosition) |
1408 | if (input_style & XIMPreeditPosition) |
1433 | { |
1409 | { |
1434 | im_set_size (&rect); |
1410 | im_set_size (rect); |
1435 | im_set_position (&spot); |
1411 | im_set_position (spot); |
1436 | im_set_color (&fg, &bg); |
1412 | im_set_color (fg, bg); |
1437 | |
1413 | |
1438 | preedit_attr = XVaCreateNestedList (0, XNArea, &rect, |
1414 | preedit_attr = XVaCreateNestedList (0, |
|
|
1415 | XNForeground, fg, |
|
|
1416 | XNBackground, bg, |
|
|
1417 | XNArea, &rect, |
1439 | XNSpotLocation, &spot, |
1418 | XNSpotLocation, &spot, |
1440 | XNForeground, fg, XNBackground, bg, |
|
|
1441 | //XNFontSet, TermWin.fontset, |
1419 | XNFontSet, fs, |
1442 | NULL); |
1420 | NULL); |
1443 | } |
1421 | } |
1444 | else if (input_style & XIMPreeditArea) |
1422 | else if (input_style & XIMPreeditArea) |
1445 | { |
1423 | { |
1446 | im_set_color (&fg, &bg); |
1424 | im_set_color (fg, bg); |
1447 | |
1425 | |
1448 | /* |
1426 | /* |
1449 | * The necessary width of preedit area is unknown |
1427 | * The necessary width of preedit area is unknown |
1450 | * until create input context. |
1428 | * until create input context. |
1451 | */ |
1429 | */ |
1452 | needed_rect.width = 0; |
1430 | needed_rect.width = 0; |
1453 | |
|
|
1454 | im_set_preedit_area (&rect, &status_rect, &needed_rect); |
1431 | im_set_preedit_area (rect, status_rect, needed_rect); |
1455 | |
1432 | |
1456 | preedit_attr = XVaCreateNestedList (0, XNArea, &rect, |
1433 | preedit_attr = XVaCreateNestedList (0, |
|
|
1434 | XNForeground, fg, |
1457 | XNForeground, fg, XNBackground, bg, |
1435 | XNBackground, bg, |
|
|
1436 | XNArea, &rect, |
|
|
1437 | XNFontSet, fs, |
|
|
1438 | NULL); |
|
|
1439 | status_attr = XVaCreateNestedList (0, |
|
|
1440 | XNForeground, fg, |
|
|
1441 | XNBackground, bg, |
|
|
1442 | XNArea, &status_rect, |
1458 | //XNFontSet, TermWin.fontset, |
1443 | XNFontSet, fs, |
1459 | NULL); |
1444 | NULL); |
1460 | status_attr = XVaCreateNestedList (0, XNArea, &status_rect, |
|
|
1461 | XNForeground, fg, XNBackground, bg, |
|
|
1462 | //XNFontSet, TermWin.fontset, |
|
|
1463 | NULL); |
|
|
1464 | } |
1445 | } |
1465 | |
1446 | |
1466 | Input_Context = XCreateIC (xim, XNInputStyle, input_style, |
1447 | Input_Context = XCreateIC (xim, |
|
|
1448 | XNInputStyle, input_style, |
1467 | XNClientWindow, TermWin.parent[0], |
1449 | XNClientWindow, TermWin.vt, |
1468 | XNFocusWindow, TermWin.parent[0], |
1450 | XNFocusWindow, TermWin.parent[0], |
1469 | preedit_attr ? XNPreeditAttributes : NULL, |
1451 | preedit_attr ? XNPreeditAttributes : NULL, |
1470 | preedit_attr, |
1452 | preedit_attr, |
1471 | status_attr ? XNStatusAttributes : NULL, |
1453 | status_attr ? XNStatusAttributes : NULL, |
1472 | status_attr, NULL); |
1454 | status_attr, NULL); |
|
|
1455 | |
1473 | if (preedit_attr) XFree (preedit_attr); |
1456 | if (preedit_attr) XFree (preedit_attr); |
1474 | if (status_attr) XFree (status_attr); |
1457 | if (status_attr) XFree (status_attr); |
|
|
1458 | if (fs) XFreeFontSet (display->display, fs); |
1475 | |
1459 | |
1476 | if (Input_Context == NULL) |
1460 | if (Input_Context == NULL) |
1477 | { |
1461 | { |
1478 | rxvt_warn ("failed to create input context, continuing without XIM.\n"); |
1462 | rxvt_warn ("failed to create input context, continuing without XIM.\n"); |
1479 | display->put_xim (input_method); |
1463 | im_destroy (); |
1480 | return false; |
1464 | return false; |
1481 | } |
1465 | } |
1482 | |
1466 | |
1483 | if (input_style & XIMPreeditArea) |
1467 | if (input_style & XIMPreeditArea) |
1484 | IMSetStatusPosition (); |
1468 | IMSetStatusPosition (); |
… | |
… | |
1514 | s = rxvt_splitcommastring (p); |
1498 | s = rxvt_splitcommastring (p); |
1515 | for (i = 0; s[i]; i++) |
1499 | for (i = 0; s[i]; i++) |
1516 | { |
1500 | { |
1517 | if (*s[i]) |
1501 | if (*s[i]) |
1518 | { |
1502 | { |
1519 | STRCPY (buf, "@im="); |
1503 | strcpy (buf, "@im="); |
1520 | STRNCAT (buf, s[i], IMBUFSIZ - 5); |
1504 | strncat (buf, s[i], IMBUFSIZ - 5); |
1521 | if (IM_get_IC (buf)) |
1505 | if (IM_get_IC (buf)) |
1522 | { |
1506 | { |
1523 | found = true; |
1507 | found = true; |
1524 | break; |
1508 | break; |
1525 | } |
1509 | } |
… | |
… | |
1549 | } |
1533 | } |
1550 | |
1534 | |
1551 | void |
1535 | void |
1552 | rxvt_term::IMSetStatusPosition () |
1536 | rxvt_term::IMSetStatusPosition () |
1553 | { |
1537 | { |
1554 | XRectangle preedit_rect, status_rect, *needed_rect; |
1538 | XRectangle preedit_rect, status_rect, *needed_rect; |
1555 | XVaNestedList preedit_attr, status_attr; |
1539 | XVaNestedList preedit_attr, status_attr; |
1556 | |
1540 | |
1557 | if (Input_Context == NULL |
1541 | if (!Input_Context |
|
|
1542 | || !TermWin.focus |
1558 | || !TermWin.focus || ! (input_style & XIMPreeditArea) |
1543 | || !(input_style & XIMPreeditArea) |
1559 | || !IMisRunning ()) |
1544 | || !IMisRunning ()) |
1560 | return; |
1545 | return; |
1561 | |
1546 | |
1562 | /* Getting the necessary width of preedit area */ |
1547 | /* Getting the necessary width of preedit area */ |
1563 | status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL); |
1548 | status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL); |
1564 | XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL); |
1549 | XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL); |
1565 | XFree (status_attr); |
1550 | XFree (status_attr); |
1566 | |
1551 | |
1567 | im_set_preedit_area (&preedit_rect, &status_rect, needed_rect); |
1552 | im_set_preedit_area (preedit_rect, status_rect, *needed_rect); |
|
|
1553 | XFree (needed_rect); |
1568 | |
1554 | |
1569 | preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL); |
1555 | preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL); |
1570 | status_attr = XVaCreateNestedList (0, XNArea, &status_rect, NULL); |
1556 | status_attr = XVaCreateNestedList (0, XNArea, &status_rect, NULL); |
1571 | |
1557 | |
1572 | XSetICValues (Input_Context, |
1558 | XSetICValues (Input_Context, |
1573 | XNPreeditAttributes, preedit_attr, |
1559 | XNPreeditAttributes, preedit_attr, |
1574 | XNStatusAttributes, status_attr, NULL); |
1560 | XNStatusAttributes, status_attr, NULL); |
1575 | |
1561 | |
1576 | XFree (preedit_attr); |
1562 | XFree (preedit_attr); |
1577 | XFree (status_attr); |
1563 | XFree (status_attr); |
1578 | } |
1564 | } |
1579 | #endif /* USE_XIM */ |
1565 | #endif /* USE_XIM */ |