… | |
… | |
32 | |
32 | |
33 | #include "../config.h" /* NECESSARY */ |
33 | #include "../config.h" /* NECESSARY */ |
34 | #include "rxvt.h" /* NECESSARY */ |
34 | #include "rxvt.h" /* NECESSARY */ |
35 | #include "main.intpro" /* PROTOS for internal routines */ |
35 | #include "main.intpro" /* PROTOS for internal routines */ |
36 | |
36 | |
37 | #include <signal.h> |
37 | #include <csignal> |
|
|
38 | #include <cstring> |
38 | |
39 | |
39 | #ifdef TTY_GID_SUPPORT |
40 | #ifdef TTY_GID_SUPPORT |
40 | # include <grp.h> |
41 | # include <grp.h> |
41 | #endif |
42 | #endif |
42 | |
43 | |
43 | #ifdef HAVE_TERMIOS_H |
44 | #ifdef HAVE_TERMIOS_H |
44 | # include <termios.h> |
45 | # include <termios.h> |
45 | #endif |
46 | #endif |
46 | |
47 | |
47 | #include <cstring> |
48 | #ifdef KEYSYM_RESOURCE |
|
|
49 | # include "keyboard.h" |
|
|
50 | #endif |
48 | |
51 | |
49 | vector<rxvt_term *> rxvt_term::termlist; |
52 | vector<rxvt_term *> rxvt_term::termlist; |
50 | |
53 | |
51 | static char curlocale[128]; |
54 | static char curlocale[128]; |
52 | |
55 | |
… | |
… | |
123 | return len; |
126 | return len; |
124 | |
127 | |
125 | } |
128 | } |
126 | #endif |
129 | #endif |
127 | |
130 | |
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 | |
|
|
143 | rxvt_term::rxvt_term () |
131 | rxvt_term::rxvt_term () |
144 | : |
132 | : |
145 | #if TRANSPARENT |
133 | #if TRANSPARENT |
146 | rootwin_ev (this, &rxvt_term::rootwin_cb), |
134 | rootwin_ev (this, &rxvt_term::rootwin_cb), |
147 | #endif |
135 | #endif |
… | |
… | |
170 | pointer_ev (this, &rxvt_term::pointer_cb), |
158 | pointer_ev (this, &rxvt_term::pointer_cb), |
171 | #endif |
159 | #endif |
172 | #ifdef USE_XIM |
160 | #ifdef USE_XIM |
173 | im_ev (this, &rxvt_term::im_cb), |
161 | im_ev (this, &rxvt_term::im_cb), |
174 | #endif |
162 | #endif |
|
|
163 | sw_term (this, &rxvt_term::sig_term), |
|
|
164 | sw_int (this, &rxvt_term::sig_term), |
|
|
165 | sw_chld (this, &rxvt_term::sig_chld), |
175 | termwin_ev (this, &rxvt_term::x_cb), |
166 | termwin_ev (this, &rxvt_term::x_cb), |
176 | vt_ev (this, &rxvt_term::x_cb), |
167 | vt_ev (this, &rxvt_term::x_cb), |
177 | check_ev (this, &rxvt_term::check_cb), |
168 | check_ev (this, &rxvt_term::check_cb), |
178 | flush_ev (this, &rxvt_term::flush_cb), |
169 | flush_ev (this, &rxvt_term::flush_cb), |
179 | destroy_ev (this, &rxvt_term::destroy_cb), |
170 | destroy_ev (this, &rxvt_term::destroy_cb), |
… | |
… | |
181 | incr_ev (this, &rxvt_term::incr_cb) |
172 | incr_ev (this, &rxvt_term::incr_cb) |
182 | { |
173 | { |
183 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
174 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
184 | |
175 | |
185 | termlist.push_back (this); |
176 | termlist.push_back (this); |
|
|
177 | |
|
|
178 | #ifdef KEYSYM_RESOURCE |
|
|
179 | keyboard = new keyboard_manager; |
|
|
180 | |
|
|
181 | if (!keyboard) |
|
|
182 | rxvt_fatal ("out of memory, aborting.\n"); |
|
|
183 | #endif |
186 | } |
184 | } |
187 | |
185 | |
188 | rxvt_term::~rxvt_term () |
186 | rxvt_term::~rxvt_term () |
189 | { |
187 | { |
190 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
188 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
191 | |
189 | |
192 | if (cmd_pid) |
190 | if (cmd_pid) |
193 | kill (-cmd_pid, SIGHUP); |
191 | kill (-cmd_pid, SIGHUP); |
194 | |
192 | |
195 | pty.put (); |
|
|
196 | |
|
|
197 | #ifdef UTMP_SUPPORT |
193 | #ifdef UTMP_SUPPORT |
198 | privileged_utmp (RESTORE); |
194 | privileged_utmp (RESTORE); |
199 | #endif |
195 | #endif |
200 | |
196 | |
|
|
197 | pty.put (); |
|
|
198 | |
|
|
199 | #if ENABLE_STYLES |
|
|
200 | for (int i = RS_styleCount; --i; ) |
|
|
201 | if (TermWin.fontset[i] != TermWin.fontset[0]) |
|
|
202 | delete TermWin.fontset[i]; |
|
|
203 | #endif |
201 | delete TermWin.fontset; |
204 | delete TermWin.fontset[0]; |
202 | |
205 | |
203 | if (display) |
206 | if (display) |
204 | { |
207 | { |
205 | selection_clear (); |
208 | selection_clear (); |
206 | |
209 | |
… | |
… | |
267 | free (env_windowid); |
270 | free (env_windowid); |
268 | free (env_display); |
271 | free (env_display); |
269 | free (env_term); |
272 | free (env_term); |
270 | free (env_colorfgbg); |
273 | free (env_colorfgbg); |
271 | free (locale); |
274 | free (locale); |
272 | #if 0 |
275 | free (v_buffer); |
273 | free (codeset); |
276 | free (incr_buf); |
274 | #endif |
|
|
275 | |
277 | |
276 | delete envv; |
278 | delete envv; |
277 | delete argv; |
279 | delete argv; |
|
|
280 | |
|
|
281 | #ifdef KEYSYM_RESOURCE |
|
|
282 | delete keyboard; |
|
|
283 | #endif |
278 | } |
284 | } |
279 | |
285 | |
280 | void |
286 | void |
281 | rxvt_term::destroy () |
287 | rxvt_term::destroy () |
282 | { |
288 | { |
… | |
… | |
340 | bool |
346 | bool |
341 | rxvt_term::init (int argc, const char *const *argv) |
347 | rxvt_term::init (int argc, const char *const *argv) |
342 | { |
348 | { |
343 | SET_R (this); |
349 | SET_R (this); |
344 | |
350 | |
|
|
351 | set_locale (""); |
|
|
352 | |
345 | if (!init_vars ()) |
353 | if (!init_vars ()) |
346 | return false; |
354 | return false; |
347 | |
355 | |
348 | init_secondary (); |
356 | init_secondary (); |
349 | |
357 | |
350 | const char **cmd_argv = init_resources (argc, argv); |
358 | const char **cmd_argv = init_resources (argc, argv); |
351 | |
359 | |
352 | set_locale (""); |
360 | #ifdef KEYSYM_RESOURCE |
|
|
361 | keyboard->register_done (); |
|
|
362 | #endif |
353 | |
363 | |
354 | #if MENUBAR_MAX |
364 | #if MENUBAR_MAX |
355 | menubar_read (rs[Rs_menu]); |
365 | menubar_read (rs[Rs_menu]); |
356 | #endif |
366 | #endif |
357 | #ifdef HAVE_SCROLLBARS |
367 | #ifdef HAVE_SCROLLBARS |
… | |
… | |
387 | #endif |
397 | #endif |
388 | |
398 | |
389 | XMapWindow (display->display, TermWin.vt); |
399 | XMapWindow (display->display, TermWin.vt); |
390 | XMapWindow (display->display, TermWin.parent[0]); |
400 | XMapWindow (display->display, TermWin.parent[0]); |
391 | |
401 | |
|
|
402 | set_colorfgbg (); |
|
|
403 | |
392 | init_command (cmd_argv); |
404 | init_command (cmd_argv); |
393 | |
405 | |
|
|
406 | free (cmd_argv); |
|
|
407 | |
394 | pty_ev.start (pty.pty, EVENT_READ); |
408 | pty_ev.start (pty.pty, EVENT_READ); |
395 | |
409 | |
396 | check_ev.start (); |
410 | check_ev.start (); |
397 | |
411 | |
398 | return true; |
412 | return true; |
… | |
… | |
401 | static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event); |
415 | static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event); |
402 | |
416 | |
403 | void |
417 | void |
404 | rxvt_init () |
418 | rxvt_init () |
405 | { |
419 | { |
406 | /* install exit handler for cleanup */ |
|
|
407 | #if 0 |
|
|
408 | #ifdef HAVE_ATEXIT |
|
|
409 | atexit (rxvt_clean_exit); |
|
|
410 | #else |
|
|
411 | #endif |
|
|
412 | #endif |
|
|
413 | /* |
420 | /* |
414 | * Save and then give up any super-user privileges |
421 | * Save and then give up any super-user privileges |
415 | * If we need privileges in any area then we must specifically request it. |
422 | * If we need privileges in any area then we must specifically request it. |
416 | * We should only need to be root in these cases: |
423 | * We should only need to be root in these cases: |
417 | * 1. write utmp entries on some systems |
424 | * 1. write utmp entries on some systems |
418 | * 2. chown tty on some systems |
425 | * 2. chown tty on some systems |
419 | */ |
426 | */ |
420 | rxvt_privileges (SAVE); |
427 | rxvt_privileges (SAVE); |
421 | rxvt_privileges (IGNORE); |
428 | rxvt_privileges (IGNORE); |
422 | |
429 | |
423 | struct sigaction sa; |
430 | signal (SIGHUP, SIG_IGN); |
424 | |
431 | signal (SIGPIPE, SIG_IGN); |
425 | sigfillset (&sa.sa_mask); |
|
|
426 | sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; |
|
|
427 | sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0); |
|
|
428 | sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0); |
|
|
429 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0); |
|
|
430 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0); |
|
|
431 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0); |
|
|
432 | sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0); |
|
|
433 | |
432 | |
434 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
433 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
435 | /* signal (SIGURG, SIG_DFL); */ |
434 | /* signal (SIGURG, SIG_DFL); */ |
436 | |
435 | |
437 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
436 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
|
|
437 | // TODO: handle this with exceptions and tolerate the memory loss |
438 | //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); |
438 | //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); |
439 | } |
439 | } |
440 | |
440 | |
441 | /* ------------------------------------------------------------------------- * |
441 | /* ------------------------------------------------------------------------- * |
442 | * SIGNAL HANDLING & EXIT HANDLER * |
442 | * SIGNAL HANDLING & EXIT HANDLER * |
443 | * ------------------------------------------------------------------------- */ |
443 | * ------------------------------------------------------------------------- */ |
444 | /* |
444 | /* |
445 | * Catch a SIGCHLD signal and exit if the direct child has died |
445 | * Catch a SIGCHLD signal and exit if the direct child has died |
446 | */ |
446 | */ |
447 | |
447 | |
448 | void rxvt_term::child_exited (int pid) |
448 | void |
|
|
449 | rxvt_term::sig_chld (sig_watcher &w) |
449 | { |
450 | { |
450 | for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++) |
451 | // we are being called for every SIGCHLD, not just ours |
451 | if (pid == (*t)->cmd_pid) |
452 | int pid; |
452 | { |
|
|
453 | (*t)->destroy (); |
|
|
454 | break; |
|
|
455 | } |
|
|
456 | } |
|
|
457 | |
|
|
458 | /* ARGSUSED */ |
|
|
459 | /* INTPROTO */ |
|
|
460 | RETSIGTYPE |
|
|
461 | rxvt_Child_signal (int sig __attribute__ ((unused))) |
|
|
462 | { |
|
|
463 | int pid, save_errno = errno; |
|
|
464 | |
453 | |
465 | while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) |
454 | while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) |
466 | rxvt_term::child_exited (pid); |
455 | for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++) |
467 | |
456 | if (pid == (*t)->cmd_pid) |
468 | errno = save_errno; |
457 | { |
469 | } |
458 | (*t)->destroy (); |
470 | |
459 | break; |
471 | /* |
460 | } |
472 | * Catch a fatal signal and tidy up before quitting |
|
|
473 | */ |
|
|
474 | /* INTPROTO */ |
|
|
475 | RETSIGTYPE |
|
|
476 | rxvt_Exit_signal (int sig) |
|
|
477 | { |
|
|
478 | signal (sig, SIG_DFL); |
|
|
479 | #ifdef DEBUG_CMD |
|
|
480 | rxvt_warn ("caught signal %d, exiting.\n", sig); |
|
|
481 | #endif |
|
|
482 | rxvt_clean_exit (); |
|
|
483 | kill (getpid (), sig); |
|
|
484 | } |
|
|
485 | |
|
|
486 | /* INTPROTO */ |
|
|
487 | int |
|
|
488 | rxvt_xerror_handler (Display *display, XErrorEvent *event) |
|
|
489 | { |
|
|
490 | if (GET_R->allowedxerror == -1) |
|
|
491 | GET_R->allowedxerror = event->error_code; |
|
|
492 | else |
|
|
493 | { |
|
|
494 | old_xerror_handler (display, event); |
|
|
495 | GET_R->destroy (); |
|
|
496 | } |
|
|
497 | |
|
|
498 | return 0; |
|
|
499 | } |
461 | } |
500 | |
462 | |
501 | /*----------------------------------------------------------------------*/ |
463 | /*----------------------------------------------------------------------*/ |
502 | /* |
464 | /* |
503 | * Exit gracefully, clearing the utmp entry and restoring tty attributes |
465 | * Exit gracefully, clearing the utmp entry and restoring tty attributes |
504 | * TODO: if debugging, this should free up any known resources if we can |
466 | * TODO: if debugging, this should free up any known resources if we can |
505 | */ |
467 | */ |
|
|
468 | void |
|
|
469 | rxvt_destroy_all () |
|
|
470 | { |
|
|
471 | // TODO: rxvtd should clean up all ressources |
|
|
472 | for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) |
|
|
473 | (*t)->destroy (); |
|
|
474 | } |
|
|
475 | |
|
|
476 | /* |
|
|
477 | * Catch a fatal signal and tidy up before quitting |
|
|
478 | */ |
|
|
479 | void |
|
|
480 | rxvt_term::sig_term (sig_watcher &w) |
|
|
481 | { |
|
|
482 | #ifdef DEBUG_CMD |
|
|
483 | rxvt_warn ("caught signal %d, exiting.\n", w.signum); |
|
|
484 | #endif |
|
|
485 | rxvt_destroy_all (); |
|
|
486 | signal (w.signum, SIG_DFL); |
|
|
487 | kill (getpid (), w.signum); |
|
|
488 | } |
|
|
489 | |
506 | /* INTPROTO */ |
490 | /* INTPROTO */ |
507 | void |
491 | int |
508 | rxvt_clean_exit () |
492 | rxvt_xerror_handler (Display *display, XErrorEvent *event) |
509 | { |
493 | { |
510 | // TODO: rxvtd should clean up all ressources |
494 | if (GET_R->allowedxerror == -1) |
511 | if (GET_R) |
495 | GET_R->allowedxerror = event->error_code; |
|
|
496 | else |
|
|
497 | { |
|
|
498 | old_xerror_handler (display, event); |
512 | GET_R->destroy (); |
499 | GET_R->destroy (); |
|
|
500 | } |
|
|
501 | |
|
|
502 | return 0; |
513 | } |
503 | } |
514 | |
504 | |
515 | /* ------------------------------------------------------------------------- * |
505 | /* ------------------------------------------------------------------------- * |
516 | * MEMORY ALLOCATION WRAPPERS * |
506 | * MEMORY ALLOCATION WRAPPERS * |
517 | * ------------------------------------------------------------------------- */ |
507 | * ------------------------------------------------------------------------- */ |
518 | /* INTPROTO */ |
508 | void * |
519 | void * |
|
|
520 | rxvt_malloc (size_t size) |
509 | rxvt_malloc (size_t size) |
521 | { |
510 | { |
522 | void *p; |
|
|
523 | |
|
|
524 | p = malloc (size); |
511 | void *p = malloc (size); |
|
|
512 | |
525 | if (p) |
513 | if (!p) |
526 | return p; |
|
|
527 | |
|
|
528 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
514 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
529 | /* NOTREACHED */ |
515 | |
|
|
516 | return p; |
530 | } |
517 | } |
531 | |
518 | |
532 | /* INTPROTO */ |
519 | /* INTPROTO */ |
533 | void * |
520 | void * |
534 | rxvt_calloc (size_t number, size_t size) |
521 | rxvt_calloc (size_t number, size_t size) |
535 | { |
522 | { |
536 | void *p; |
|
|
537 | |
|
|
538 | p = calloc (number, size); |
523 | void *p = calloc (number, size); |
|
|
524 | |
539 | if (p) |
525 | if (!p) |
540 | return p; |
|
|
541 | |
|
|
542 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
526 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
543 | /* NOTREACHED */ |
527 | |
|
|
528 | return p; |
544 | } |
529 | } |
545 | |
530 | |
546 | /* INTPROTO */ |
531 | /* INTPROTO */ |
547 | void * |
532 | void * |
548 | rxvt_realloc (void *ptr, size_t size) |
533 | rxvt_realloc (void *ptr, size_t size) |
549 | { |
534 | { |
550 | void *p; |
|
|
551 | |
|
|
552 | if (ptr) |
|
|
553 | p = realloc (ptr, size); |
535 | void *p = realloc (ptr, size); |
554 | else |
|
|
555 | p = malloc (size); |
|
|
556 | |
536 | |
557 | if (p) |
537 | if (!p) |
558 | return p; |
|
|
559 | |
|
|
560 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
538 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
561 | /* NOTREACHED */ |
539 | |
|
|
540 | return p; |
562 | } |
541 | } |
563 | |
542 | |
564 | /* ------------------------------------------------------------------------- * |
543 | /* ------------------------------------------------------------------------- * |
565 | * PRIVILEGED OPERATIONS * |
544 | * PRIVILEGED OPERATIONS * |
566 | * ------------------------------------------------------------------------- */ |
545 | * ------------------------------------------------------------------------- */ |
… | |
… | |
793 | kill (cmd_pid, SIGWINCH); |
772 | kill (cmd_pid, SIGWINCH); |
794 | #endif |
773 | #endif |
795 | } |
774 | } |
796 | |
775 | |
797 | /*----------------------------------------------------------------------*/ |
776 | /*----------------------------------------------------------------------*/ |
798 | /* rxvt_change_font () - Switch to a new font */ |
777 | /* set_fonts () - load and set the various fonts |
799 | /* |
778 | /* |
800 | * init = 1 - initialize |
779 | * init = 1 - initialize |
801 | * |
780 | * |
802 | * fontname == FONT_UP - switch to bigger font |
781 | * fontname == FONT_UP - switch to bigger font |
803 | * fontname == FONT_DN - switch to smaller font |
782 | * fontname == FONT_DN - switch to smaller font |
804 | */ |
783 | */ |
805 | bool |
784 | bool |
806 | rxvt_term::change_font (const char *fontname) |
785 | rxvt_term::set_fonts () |
807 | { |
786 | { |
808 | if (fontname == FONT_UP) |
|
|
809 | { |
|
|
810 | // TODO |
|
|
811 | } |
|
|
812 | else if (fontname == FONT_DN) |
|
|
813 | { |
|
|
814 | // TODO |
|
|
815 | } |
|
|
816 | else |
|
|
817 | { |
|
|
818 | rxvt_fontset *fs = new rxvt_fontset (this); |
787 | rxvt_fontset *fs = new rxvt_fontset (this); |
|
|
788 | rxvt_fontprop prop; |
819 | |
789 | |
820 | if (fs && fs->populate (fontname ? fontname : "fixed")) |
790 | if (!fs |
|
|
791 | || !fs->populate (rs[Rs_font] ? rs[Rs_font] : "fixed") |
|
|
792 | || !fs->realize_font (1)) |
|
|
793 | { |
|
|
794 | delete fs; |
|
|
795 | return false; |
|
|
796 | } |
|
|
797 | |
|
|
798 | #if ENABLE_STYLES |
|
|
799 | for (int i = RS_styleCount; --i; ) |
|
|
800 | if (TermWin.fontset[i] != TermWin.fontset[0]) |
|
|
801 | delete TermWin.fontset[i]; |
|
|
802 | #endif |
|
|
803 | |
|
|
804 | delete TermWin.fontset[0]; |
|
|
805 | TermWin.fontset[0] = fs; |
|
|
806 | |
|
|
807 | prop = (*fs)[1]->properties (); |
|
|
808 | prop.height += TermWin.lineSpace; |
|
|
809 | fs->set_prop (prop); |
|
|
810 | |
|
|
811 | TermWin.fwidth = prop.width; |
|
|
812 | TermWin.fheight = prop.height; |
|
|
813 | TermWin.fweight = prop.weight; |
|
|
814 | TermWin.fslant = prop.slant; |
|
|
815 | TermWin.fbase = (*fs)[1]->ascent; |
|
|
816 | |
|
|
817 | for (int style = 1; style < 4; style++) |
|
|
818 | { |
|
|
819 | #if ENABLE_STYLES |
|
|
820 | const char *res = rs[Rs_font + style]; |
|
|
821 | |
|
|
822 | if (res && !*res) |
|
|
823 | TermWin.fontset[style] = TermWin.fontset[0]; |
|
|
824 | else |
821 | { |
825 | { |
822 | delete TermWin.fontset; |
826 | TermWin.fontset[style] = fs = new rxvt_fontset (this); |
823 | TermWin.fontset = fs; |
827 | rxvt_fontprop prop2 = prop; |
824 | TermWin.fwidth = fs->base_font ()->width; |
|
|
825 | TermWin.fheight = fs->base_font ()->height; |
|
|
826 | TermWin.fbase = fs->base_font ()->ascent; |
|
|
827 | |
828 | |
828 | if (TermWin.parent[0]) |
829 | if (res) |
|
|
830 | prop2.weight = prop2.slant = rxvt_fontprop::unset; |
|
|
831 | else |
829 | { |
832 | { |
830 | resize_all_windows (0, 0, 0); |
833 | res = TermWin.fontset[0]->fontdesc; |
831 | scr_remap_chars (); |
834 | |
832 | scr_touch (true); |
835 | if (SET_STYLE (0, style) & RS_Bold) prop2.weight = rxvt_fontprop::bold; |
|
|
836 | if (SET_STYLE (0, style) & RS_Italic) prop2.slant = rxvt_fontprop::italic; |
833 | } |
837 | } |
834 | |
838 | |
835 | for (unicode_t ch = 0x20; ch <= 0x7f; ch++) |
839 | fs->populate (res); |
836 | TermWin.ascii_map [ch - 0x20] = fs->find_font (ch); |
840 | fs->set_prop (prop2); |
837 | |
|
|
838 | return true; |
|
|
839 | } |
841 | } |
|
|
842 | #else |
|
|
843 | TermWin.fontset[style] = TermWin.fontset[0]; |
|
|
844 | #endif |
|
|
845 | } |
|
|
846 | |
|
|
847 | if (TermWin.parent[0]) |
840 | } |
848 | { |
|
|
849 | resize_all_windows (0, 0, 0); |
|
|
850 | scr_remap_chars (); |
|
|
851 | scr_touch (true); |
|
|
852 | } |
841 | |
853 | |
842 | return false; |
854 | return true; |
843 | } |
855 | } |
844 | |
856 | |
845 | bool |
857 | void rxvt_term::set_string_property (Atom prop, const char *str, int len) |
846 | rxvt_term::font_up_down (int n, int direction) |
|
|
847 | { |
858 | { |
848 | return false; |
859 | // TODO: SMART_WINDOW_TITLE |
|
|
860 | XChangeProperty (display->display, TermWin.parent[0], |
|
|
861 | prop, XA_STRING, 8, PropModeReplace, |
|
|
862 | (const unsigned char *)str, len >= 0 ? len : strlen (str)); |
|
|
863 | } |
|
|
864 | |
|
|
865 | void rxvt_term::set_utf8_property (Atom prop, const char *str, int len) |
|
|
866 | { |
|
|
867 | // TODO: SMART_WINDOW_TITLE |
|
|
868 | wchar_t *ws = rxvt_mbstowcs (str, len); |
|
|
869 | char *s = rxvt_wcstoutf8 (ws); |
|
|
870 | |
|
|
871 | XChangeProperty (display->display, TermWin.parent[0], |
|
|
872 | prop, xa[XA_UTF8_STRING], 8, PropModeReplace, |
|
|
873 | (const unsigned char *)s, strlen (s)); |
|
|
874 | |
|
|
875 | free (s); |
|
|
876 | free (ws); |
849 | } |
877 | } |
850 | |
878 | |
851 | /*----------------------------------------------------------------------*/ |
879 | /*----------------------------------------------------------------------*/ |
852 | /*----------------------------------------------------------------------*/ |
880 | /*----------------------------------------------------------------------*/ |
853 | /* xterm sequences - title, iconName, color (exptl) */ |
881 | /* xterm sequences - title, iconName, color (exptl) */ |
854 | void |
882 | void |
855 | rxvt_term::set_title (const char *str) |
883 | rxvt_term::set_title (const char *str) |
856 | { |
884 | { |
857 | #ifdef SMART_WINDOW_TITLE |
885 | set_string_property (XA_WM_NAME, str); |
858 | char *name; |
886 | #if ENABLE_FRILLS |
859 | |
887 | set_utf8_property (xa[XA_NET_WM_NAME], str); |
860 | if (!XFetchName (display->display, TermWin.parent[0], &name)) |
|
|
861 | name = NULL; |
|
|
862 | |
|
|
863 | if (name == NULL || strcmp (name, str)) |
|
|
864 | #endif |
|
|
865 | XStoreName (display->display, TermWin.parent[0], str); |
|
|
866 | |
|
|
867 | #ifdef SMART_WINDOW_TITLE |
|
|
868 | if (name) |
|
|
869 | XFree (name); |
|
|
870 | #endif |
888 | #endif |
871 | } |
889 | } |
872 | |
890 | |
873 | void |
891 | void |
874 | rxvt_term::set_icon_name (const char *str) |
892 | rxvt_term::set_icon_name (const char *str) |
875 | { |
893 | { |
876 | #ifdef SMART_WINDOW_TITLE |
894 | set_string_property (XA_WM_ICON_NAME, str); |
877 | char *name; |
895 | #if ENABLE_FRILLS |
878 | |
896 | set_utf8_property (xa[XA_NET_WM_ICON_NAME], str); |
879 | if (!XGetIconName (display->display, TermWin.parent[0], &name)) |
|
|
880 | name = NULL; |
|
|
881 | |
|
|
882 | if (name == NULL || strcmp (name, str)) |
|
|
883 | #endif |
|
|
884 | XSetIconName (display->display, TermWin.parent[0], str); |
|
|
885 | |
|
|
886 | #ifdef SMART_WINDOW_TITLE |
|
|
887 | if (name) |
|
|
888 | XFree (name); |
|
|
889 | #endif |
897 | #endif |
890 | } |
898 | } |
891 | |
899 | |
892 | #ifdef XTERM_COLOR_CHANGE |
900 | #ifdef XTERM_COLOR_CHANGE |
893 | void |
901 | void |
… | |
… | |
947 | |
955 | |
948 | /* XSetWindowAttributes attr; */ |
956 | /* XSetWindowAttributes attr; */ |
949 | /* Cursor cursor; */ |
957 | /* Cursor cursor; */ |
950 | Done: |
958 | Done: |
951 | #ifdef OFF_FOCUS_FADING |
959 | #ifdef OFF_FOCUS_FADING |
|
|
960 | if (rs[Rs_fade]) |
952 | pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade])); |
961 | pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade])); |
953 | #endif |
962 | #endif |
954 | if (idx == Color_bg && ! (options & Opt_transparent)) |
|
|
955 | XSetWindowBackground (display->display, TermWin.vt, pix_colors[Color_bg]); |
|
|
956 | |
963 | |
957 | /* handle Color_BD, scrollbar background, etc. */ |
964 | /*TODO: handle Color_BD, scrollbar background, etc. */ |
958 | |
965 | |
959 | set_colorfgbg (); |
|
|
960 | recolour_cursor (); |
966 | recolour_cursor (); |
961 | scr_touch (true); |
967 | scr_recolour (); |
962 | } |
968 | } |
963 | |
969 | |
964 | #else |
970 | #else |
965 | # define set_window_color (idx,color) ((void)0) |
971 | # define set_window_color (idx,color) ((void)0) |
966 | #endif /* XTERM_COLOR_CHANGE */ |
972 | #endif /* XTERM_COLOR_CHANGE */ |
… | |
… | |
968 | void |
974 | void |
969 | rxvt_term::recolour_cursor () |
975 | rxvt_term::recolour_cursor () |
970 | { |
976 | { |
971 | XColor xcol[2]; |
977 | XColor xcol[2]; |
972 | |
978 | |
973 | xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) ? pix_colors_focused[Color_pointer_fg] : pix_colors_focused[Color_fg]; |
979 | xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) |
974 | xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) ? pix_colors_focused[Color_pointer_bg] : pix_colors_focused[Color_bg]; |
980 | ? pix_colors_focused[Color_pointer_fg] |
|
|
981 | : pix_colors_focused[Color_fg]; |
|
|
982 | xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) |
|
|
983 | ? pix_colors_focused[Color_pointer_bg] |
|
|
984 | : pix_colors_focused[Color_bg]; |
|
|
985 | |
975 | XQueryColors (display->display, display->cmap, xcol, 2); |
986 | XQueryColors (display->display, display->cmap, xcol, 2); |
976 | XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1); |
987 | XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1); |
977 | } |
988 | } |
978 | |
989 | |
979 | /*----------------------------------------------------------------------*/ |
990 | /*----------------------------------------------------------------------*/ |
… | |
… | |
981 | * find if fg/bg matches any of the normal (low-intensity) colors |
992 | * find if fg/bg matches any of the normal (low-intensity) colors |
982 | */ |
993 | */ |
983 | void |
994 | void |
984 | rxvt_term::set_colorfgbg () |
995 | rxvt_term::set_colorfgbg () |
985 | { |
996 | { |
986 | unsigned int i; |
997 | unsigned int i; |
987 | const char *xpmb = "\0"; |
998 | const char *xpmb = "\0"; |
988 | char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1]; |
999 | char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1]; |
989 | |
1000 | |
990 | env_colorfgbg = |
|
|
991 | (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1); |
1001 | env_colorfgbg = (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1); |
992 | strcpy (fstr, "default"); |
1002 | strcpy (fstr, "default"); |
993 | strcpy (bstr, "default"); |
1003 | strcpy (bstr, "default"); |
994 | for (i = Color_Black; i <= Color_White; i++) |
1004 | for (i = Color_Black; i <= Color_White; i++) |
995 | if (pix_colors[Color_fg] == pix_colors[i]) |
1005 | if (pix_colors[Color_fg] == pix_colors[i]) |
996 | { |
1006 | { |
997 | sprintf (fstr, "%d", (i - Color_Black)); |
1007 | sprintf (fstr, "%d", (i - Color_Black)); |
998 | break; |
1008 | break; |
999 | } |
1009 | } |
|
|
1010 | |
1000 | for (i = Color_Black; i <= Color_White; i++) |
1011 | for (i = Color_Black; i <= Color_White; i++) |
1001 | if (pix_colors[Color_bg] == pix_colors[i]) |
1012 | if (pix_colors[Color_bg] == pix_colors[i]) |
1002 | { |
1013 | { |
1003 | sprintf (bstr, "%d", (i - Color_Black)); |
1014 | sprintf (bstr, "%d", (i - Color_Black)); |
1004 | #ifdef XPM_BACKGROUND |
1015 | #ifdef XPM_BACKGROUND |
… | |
… | |
1006 | #endif |
1017 | #endif |
1007 | break; |
1018 | break; |
1008 | } |
1019 | } |
1009 | |
1020 | |
1010 | sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); |
1021 | sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); |
1011 | |
|
|
1012 | #ifndef NO_BRIGHTCOLOR |
|
|
1013 | colorfgbg = DEFAULT_RSTYLE; |
|
|
1014 | for (i = minCOLOR; i <= maxCOLOR; i++) |
|
|
1015 | { |
|
|
1016 | if (pix_colors[Color_fg] == pix_colors[i]) |
|
|
1017 | colorfgbg = SET_FGCOLOR (colorfgbg, i); |
|
|
1018 | if (pix_colors[Color_bg] == pix_colors[i]) |
|
|
1019 | colorfgbg = SET_BGCOLOR (colorfgbg, i); |
|
|
1020 | } |
|
|
1021 | #endif |
|
|
1022 | } |
1022 | } |
1023 | |
1023 | |
1024 | /*----------------------------------------------------------------------*/ |
1024 | /*----------------------------------------------------------------------*/ |
1025 | /* |
|
|
1026 | * Colour determination for low colour displays, routine from |
|
|
1027 | * Hans de Goede <hans@highrise.nl> |
|
|
1028 | */ |
|
|
1029 | |
1025 | |
1030 | int |
1026 | int |
1031 | rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) |
1027 | rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) |
1032 | { |
1028 | { |
1033 | if (!screen_in_out->set (display, colour)) |
1029 | if (!screen_in_out->set (display, colour)) |
… | |
… | |
1120 | TermWin_TotalWidth (), menuBar_TotalHeight ()); |
1116 | TermWin_TotalWidth (), menuBar_TotalHeight ()); |
1121 | |
1117 | |
1122 | XMoveResizeWindow (display->display, TermWin.vt, |
1118 | XMoveResizeWindow (display->display, TermWin.vt, |
1123 | window_vt_x, window_vt_y, |
1119 | window_vt_x, window_vt_y, |
1124 | TermWin_TotalWidth (), TermWin_TotalHeight ()); |
1120 | TermWin_TotalWidth (), TermWin_TotalHeight ()); |
|
|
1121 | |
1125 | scr_clear (); |
1122 | scr_clear (); |
1126 | #ifdef XPM_BACKGROUND |
1123 | #ifdef XPM_BACKGROUND |
1127 | resize_pixmap (); |
1124 | resize_pixmap (); |
1128 | #endif |
1125 | #endif |
1129 | } |
1126 | } |
… | |
… | |
1152 | } |
1149 | } |
1153 | |
1150 | |
1154 | old_width = szHint.width; |
1151 | old_width = szHint.width; |
1155 | old_height = szHint.height; |
1152 | old_height = szHint.height; |
1156 | |
1153 | |
|
|
1154 | #ifdef XPM_BACKGROUND |
|
|
1155 | if (TermWin.pixmap) |
|
|
1156 | scr_touch (false); |
|
|
1157 | #endif |
|
|
1158 | |
1157 | #ifdef USE_XIM |
1159 | #ifdef USE_XIM |
1158 | IMSetStatusPosition (); |
1160 | IMSetStatusPosition (); |
1159 | #endif |
1161 | #endif |
1160 | } |
1162 | } |
1161 | |
1163 | |
… | |
… | |
1252 | } |
1254 | } |
1253 | |
1255 | |
1254 | void |
1256 | void |
1255 | rxvt_term::IMSendSpot () |
1257 | rxvt_term::IMSendSpot () |
1256 | { |
1258 | { |
1257 | XPoint spot; |
1259 | XPoint nspot; |
1258 | XVaNestedList preedit_attr; |
1260 | XVaNestedList preedit_attr; |
1259 | |
1261 | |
1260 | if (!Input_Context |
1262 | if (!Input_Context |
1261 | || !TermWin.focus |
1263 | || !TermWin.focus |
1262 | || !(input_style & XIMPreeditPosition) |
1264 | || !(input_style & XIMPreeditPosition)) |
1263 | #if 0 |
|
|
1264 | || !(event_type == KeyPress |
|
|
1265 | || event_type == Expose |
|
|
1266 | || event_type == NoExpose |
|
|
1267 | || event_type == SelectionNotify |
|
|
1268 | || event_type == ButtonRelease || event_type == FocusIn) |
|
|
1269 | #endif |
|
|
1270 | || !IMisRunning ()) |
|
|
1271 | return; |
1265 | return; |
1272 | |
1266 | |
1273 | im_set_position (spot); |
1267 | im_set_position (nspot); |
|
|
1268 | |
|
|
1269 | if (nspot.x == spot.x && nspot.y == spot.y) |
|
|
1270 | return; |
|
|
1271 | |
|
|
1272 | spot = nspot; |
1274 | |
1273 | |
1275 | preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); |
1274 | preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); |
1276 | XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); |
1275 | XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); |
1277 | XFree (preedit_attr); |
1276 | XFree (preedit_attr); |
1278 | } |
1277 | } |
1279 | |
1278 | |
1280 | void |
1279 | void |
1281 | rxvt_term::im_destroy () |
1280 | rxvt_term::im_destroy () |
1282 | { |
1281 | { |
1283 | if (Input_Context) |
|
|
1284 | { |
|
|
1285 | XDestroyIC (Input_Context); |
|
|
1286 | Input_Context = 0; |
|
|
1287 | } |
|
|
1288 | |
|
|
1289 | if (input_method) |
1282 | if (input_method) |
1290 | { |
1283 | { |
|
|
1284 | if (Input_Context && input_method->xim) |
|
|
1285 | XDestroyIC (Input_Context); |
|
|
1286 | |
1291 | display->put_xim (input_method); |
1287 | display->put_xim (input_method); |
1292 | input_method = 0; |
1288 | input_method = 0; |
1293 | } |
1289 | } |
|
|
1290 | |
|
|
1291 | Input_Context = 0; |
1294 | } |
1292 | } |
1295 | |
1293 | |
1296 | /* |
1294 | /* |
1297 | * Try to open a XIM with the current modifiers, then see if we can |
1295 | * Try to open a XIM with the current modifiers, then see if we can |
1298 | * open a suitable preedit type |
1296 | * open a suitable preedit type |
… | |
… | |
1316 | input_method = display->get_xim (locale, modifiers); |
1314 | input_method = display->get_xim (locale, modifiers); |
1317 | if (input_method == NULL) |
1315 | if (input_method == NULL) |
1318 | return false; |
1316 | return false; |
1319 | |
1317 | |
1320 | xim = input_method->xim; |
1318 | xim = input_method->xim; |
|
|
1319 | spot.x = spot.y = -1; |
1321 | |
1320 | |
1322 | xim_styles = NULL; |
1321 | xim_styles = NULL; |
1323 | if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) |
1322 | if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) |
1324 | || !xim_styles || !xim_styles->count_styles) |
1323 | || !xim_styles || !xim_styles->count_styles) |
1325 | { |
1324 | { |
1326 | im_destroy (); |
1325 | im_destroy (); |
1327 | return false; |
1326 | return false; |
1328 | } |
1327 | } |
1329 | |
1328 | |
1330 | p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root"; |
1329 | const char *pet[] = { rs[Rs_preeditType], "OverTheSpot,OffTheSpot,Root,None" }; |
|
|
1330 | |
|
|
1331 | for (int pi = 0; pi < 2; pi++) |
|
|
1332 | { |
|
|
1333 | p = pet[pi]; |
|
|
1334 | |
|
|
1335 | if (!p) |
|
|
1336 | continue; |
|
|
1337 | |
1331 | s = rxvt_splitcommastring (p); |
1338 | s = rxvt_splitcommastring (p); |
1332 | |
1339 | |
1333 | for (i = found = 0; !found && s[i]; i++) |
1340 | for (i = found = 0; !found && s[i]; i++) |
1334 | { |
1341 | { |
1335 | if (!strcmp (s[i], "OverTheSpot")) |
1342 | if (!strcmp (s[i], "OverTheSpot")) |
1336 | input_style = (XIMPreeditPosition | XIMStatusNothing); |
1343 | input_style = (XIMPreeditPosition | XIMStatusNothing); |
1337 | else if (!strcmp (s[i], "OffTheSpot")) |
1344 | else if (!strcmp (s[i], "OffTheSpot")) |
1338 | input_style = (XIMPreeditArea | XIMStatusArea); |
1345 | input_style = (XIMPreeditArea | XIMStatusArea); |
1339 | else if (!strcmp (s[i], "Root")) |
1346 | else if (!strcmp (s[i], "Root")) |
1340 | input_style = (XIMPreeditNothing | XIMStatusNothing); |
1347 | input_style = (XIMPreeditNothing | XIMStatusNothing); |
|
|
1348 | else if (!strcmp (s[i], "None")) |
|
|
1349 | input_style = (XIMPreeditNone | XIMStatusNone); |
1341 | |
1350 | |
1342 | for (j = 0; j < xim_styles->count_styles; j++) |
1351 | for (j = 0; j < xim_styles->count_styles; j++) |
1343 | if (input_style == xim_styles->supported_styles[j]) |
1352 | if (input_style == xim_styles->supported_styles[j]) |
1344 | { |
1353 | { |
|
|
1354 | rxvt_freecommastring (s); |
|
|
1355 | |
1345 | found = 1; |
1356 | found = 1; |
1346 | break; |
1357 | goto foundpet; |
|
|
1358 | } |
|
|
1359 | |
1347 | } |
1360 | } |
1348 | } |
|
|
1349 | |
1361 | |
1350 | for (i = 0; s[i]; i++) |
1362 | rxvt_freecommastring (s); |
1351 | free (s[i]); |
1363 | } |
1352 | |
1364 | |
1353 | free (s); |
1365 | foundpet: |
|
|
1366 | |
1354 | XFree (xim_styles); |
1367 | XFree (xim_styles); |
1355 | |
1368 | |
1356 | if (!found) |
1369 | if (!found) |
1357 | { |
1370 | { |
1358 | im_destroy (); |
1371 | im_destroy (); |
… | |
… | |
1379 | "*", |
1392 | "*", |
1380 | TermWin.fheight, |
1393 | TermWin.fheight, |
1381 | TermWin.fheight + 1, TermWin.fheight - 1, |
1394 | TermWin.fheight + 1, TermWin.fheight - 1, |
1382 | TermWin.fheight - 2, TermWin.fheight + 2); |
1395 | TermWin.fheight - 2, TermWin.fheight + 2); |
1383 | |
1396 | |
1384 | fs = XCreateFontSet (display->display, pat, |
1397 | fs = XCreateFontSet (display->display, rs[Rs_imFont] ? rs[Rs_imFont] : pat, |
1385 | &missing_charset_list, &missing_charset_count, &def_string); |
1398 | &missing_charset_list, &missing_charset_count, &def_string); |
1386 | |
1399 | |
1387 | if (missing_charset_list) |
1400 | if (missing_charset_list) |
1388 | XFreeStringList (missing_charset_list); |
1401 | XFreeStringList (missing_charset_list); |
1389 | |
1402 | |
… | |
… | |
1483 | if (p && *p) |
1496 | if (p && *p) |
1484 | { |
1497 | { |
1485 | bool found = false; |
1498 | bool found = false; |
1486 | |
1499 | |
1487 | s = rxvt_splitcommastring (p); |
1500 | s = rxvt_splitcommastring (p); |
|
|
1501 | |
1488 | for (i = 0; s[i]; i++) |
1502 | for (i = 0; s[i]; i++) |
1489 | { |
1503 | { |
1490 | if (*s[i]) |
1504 | if (*s[i]) |
1491 | { |
1505 | { |
1492 | strcpy (buf, "@im="); |
1506 | strcpy (buf, "@im="); |
… | |
… | |
1496 | found = true; |
1510 | found = true; |
1497 | break; |
1511 | break; |
1498 | } |
1512 | } |
1499 | } |
1513 | } |
1500 | } |
1514 | } |
1501 | for (i = 0; s[i]; i++) |
1515 | |
1502 | free (s[i]); |
1516 | rxvt_freecommastring (s); |
1503 | free (s); |
|
|
1504 | |
1517 | |
1505 | if (found) |
1518 | if (found) |
1506 | goto done; |
1519 | goto done; |
1507 | } |
1520 | } |
1508 | |
1521 | |