… | |
… | |
11 | * Copyright (c) 1997 mj olesen <olesen@me.QueensU.CA> |
11 | * Copyright (c) 1997 mj olesen <olesen@me.QueensU.CA> |
12 | * - extensive modifications |
12 | * - extensive modifications |
13 | * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> |
13 | * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> |
14 | * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> |
14 | * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> |
15 | * - extensive modifications |
15 | * - extensive modifications |
16 | * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> |
16 | * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com> |
17 | * |
17 | * |
18 | * This program is free software; you can redistribute it and/or modify |
18 | * This program is free software; you can redistribute it and/or modify |
19 | * it under the terms of the GNU General Public License as published by |
19 | * it under the terms of the GNU General Public License as published by |
20 | * the Free Software Foundation; either version 2 of the License, or |
20 | * the Free Software Foundation; either version 2 of the License, or |
21 | * (at your option) any later version. |
21 | * (at your option) any later version. |
… | |
… | |
30 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
30 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
31 | *---------------------------------------------------------------------*/ |
31 | *---------------------------------------------------------------------*/ |
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 "keyboard.h" |
|
|
36 | #include "rxvtperl.h" |
|
|
37 | |
|
|
38 | #include <limits> |
36 | |
39 | |
37 | #include <csignal> |
40 | #include <csignal> |
38 | #include <cstring> |
41 | #include <cstring> |
39 | |
42 | |
40 | #ifdef TTY_GID_SUPPORT |
43 | #ifdef TTY_GID_SUPPORT |
… | |
… | |
43 | |
46 | |
44 | #ifdef HAVE_TERMIOS_H |
47 | #ifdef HAVE_TERMIOS_H |
45 | # include <termios.h> |
48 | # include <termios.h> |
46 | #endif |
49 | #endif |
47 | |
50 | |
48 | #ifdef KEYSYM_RESOURCE |
51 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
49 | # include "keyboard.h" |
52 | static uid_t saved_euid; |
|
|
53 | static gid_t saved_egid; |
50 | #endif |
54 | #endif |
|
|
55 | |
|
|
56 | bool |
|
|
57 | rxvt_tainted () |
|
|
58 | { |
|
|
59 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
60 | return getuid () != saved_euid || getgid () != saved_egid; |
|
|
61 | #else |
|
|
62 | return false; |
|
|
63 | #endif |
|
|
64 | } |
51 | |
65 | |
52 | vector<rxvt_term *> rxvt_term::termlist; |
66 | vector<rxvt_term *> rxvt_term::termlist; |
53 | |
67 | |
54 | static char curlocale[128]; |
68 | static char curlocale[128], savelocale[128]; |
55 | |
69 | |
56 | bool |
70 | bool |
57 | rxvt_set_locale (const char *locale) |
71 | rxvt_set_locale (const char *locale) |
58 | { |
72 | { |
59 | if (!locale || !strncmp (locale, curlocale, 128)) |
73 | if (!locale || !strncmp (locale, curlocale, 128)) |
60 | return false; |
74 | return false; |
61 | |
75 | |
62 | strncpy (curlocale, locale, 128); |
76 | strncpy (curlocale, locale, 128); |
63 | setlocale (LC_CTYPE, curlocale); |
77 | setlocale (LC_CTYPE, curlocale); |
64 | return true; |
78 | return true; |
|
|
79 | } |
|
|
80 | |
|
|
81 | void |
|
|
82 | rxvt_push_locale (const char *locale) |
|
|
83 | { |
|
|
84 | strcpy (savelocale, curlocale); |
|
|
85 | rxvt_set_locale (locale); |
|
|
86 | } |
|
|
87 | |
|
|
88 | void |
|
|
89 | rxvt_pop_locale () |
|
|
90 | { |
|
|
91 | rxvt_set_locale (savelocale); |
|
|
92 | } |
|
|
93 | |
|
|
94 | void |
|
|
95 | rxvt_term::make_current () const |
|
|
96 | { |
|
|
97 | SET_R (this); |
|
|
98 | rxvt_set_locale (locale); |
|
|
99 | set_environ (envv); |
65 | } |
100 | } |
66 | |
101 | |
67 | #if ENABLE_COMBINING |
102 | #if ENABLE_COMBINING |
68 | class rxvt_composite_vec rxvt_composite; |
103 | class rxvt_composite_vec rxvt_composite; |
69 | |
104 | |
… | |
… | |
158 | pointer_ev (this, &rxvt_term::pointer_cb), |
193 | pointer_ev (this, &rxvt_term::pointer_cb), |
159 | #endif |
194 | #endif |
160 | #ifdef USE_XIM |
195 | #ifdef USE_XIM |
161 | im_ev (this, &rxvt_term::im_cb), |
196 | im_ev (this, &rxvt_term::im_cb), |
162 | #endif |
197 | #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), |
|
|
166 | termwin_ev (this, &rxvt_term::x_cb), |
198 | termwin_ev (this, &rxvt_term::x_cb), |
167 | vt_ev (this, &rxvt_term::x_cb), |
199 | vt_ev (this, &rxvt_term::x_cb), |
168 | check_ev (this, &rxvt_term::check_cb), |
200 | check_ev (this, &rxvt_term::check_cb), |
169 | flush_ev (this, &rxvt_term::flush_cb), |
201 | flush_ev (this, &rxvt_term::flush_cb), |
170 | destroy_ev (this, &rxvt_term::destroy_cb), |
202 | destroy_ev (this, &rxvt_term::destroy_cb), |
… | |
… | |
197 | pty.put (); |
229 | pty.put (); |
198 | } |
230 | } |
199 | |
231 | |
200 | rxvt_term::~rxvt_term () |
232 | rxvt_term::~rxvt_term () |
201 | { |
233 | { |
|
|
234 | HOOK_INVOKE ((this, HOOK_DESTROY, DT_END)); |
|
|
235 | |
202 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
236 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
203 | |
237 | |
204 | emergency_cleanup (); |
238 | emergency_cleanup (); |
205 | |
239 | |
206 | #if ENABLE_STYLES |
240 | #if ENABLE_STYLES |
207 | for (int i = RS_styleCount; --i; ) |
241 | for (int i = RS_styleCount; --i; ) |
208 | if (TermWin.fontset[i] != TermWin.fontset[0]) |
242 | if (fontset[i] != fontset[0]) |
209 | delete TermWin.fontset[i]; |
243 | delete fontset[i]; |
210 | #endif |
244 | #endif |
211 | delete TermWin.fontset[0]; |
245 | delete fontset[0]; |
212 | |
246 | |
213 | if (display) |
247 | if (display) |
214 | { |
248 | { |
215 | dDisp; |
249 | dDisp; |
216 | |
250 | |
… | |
… | |
244 | #if defined(MENUBAR) || defined(RXVT_SCROLLBAR) |
278 | #if defined(MENUBAR) || defined(RXVT_SCROLLBAR) |
245 | if (topShadowGC) XFreeGC (disp, topShadowGC); |
279 | if (topShadowGC) XFreeGC (disp, topShadowGC); |
246 | if (botShadowGC) XFreeGC (disp, botShadowGC); |
280 | if (botShadowGC) XFreeGC (disp, botShadowGC); |
247 | if (scrollbarGC) XFreeGC (disp, scrollbarGC); |
281 | if (scrollbarGC) XFreeGC (disp, scrollbarGC); |
248 | #endif |
282 | #endif |
249 | if (TermWin.gc) XFreeGC (disp, TermWin.gc); |
283 | if (gc) XFreeGC (disp, gc); |
250 | |
284 | |
251 | #if defined(MENUBAR) && (MENUBAR_MAX > 1) |
285 | #if defined(MENUBAR) && (MENUBAR_MAX > 1) |
252 | delete menuBar.drawable; |
286 | delete menuBar.drawable; |
253 | //if (menuBar.win) |
287 | //if (menuBar.win) |
254 | // XDestroyWindow (disp, menuBar.win); |
288 | // XDestroyWindow (disp, menuBar.win); |
255 | #endif |
289 | #endif |
256 | delete TermWin.drawable; |
290 | delete drawable; |
257 | // destroy all windows |
291 | // destroy all windows |
258 | if (TermWin.parent[0]) |
292 | if (parent[0]) |
259 | XDestroyWindow (disp, TermWin.parent[0]); |
293 | XDestroyWindow (disp, parent[0]); |
260 | } |
294 | } |
261 | |
295 | |
262 | // TODO: free pixcolours, colours should become part of rxvt_display |
296 | // TODO: free pixcolours, colours should become part of rxvt_display |
263 | |
|
|
264 | delete pix_colors_focused; |
297 | delete pix_colors_focused; |
265 | #ifdef OFF_FOCUS_FADING |
298 | #if OFF_FOCUS_FADING |
266 | delete pix_colors_unfocused; |
299 | delete pix_colors_unfocused; |
267 | #endif |
300 | #endif |
268 | |
301 | |
269 | displays.put (display); |
302 | displays.put (display); |
270 | |
303 | |
… | |
… | |
291 | delete keyboard; |
324 | delete keyboard; |
292 | #endif |
325 | #endif |
293 | } |
326 | } |
294 | |
327 | |
295 | void |
328 | void |
|
|
329 | rxvt_term::child_exit () |
|
|
330 | { |
|
|
331 | cmd_pid = 0; |
|
|
332 | |
|
|
333 | if (!OPTION (Opt_hold)) |
|
|
334 | destroy (); |
|
|
335 | } |
|
|
336 | |
|
|
337 | void |
296 | rxvt_term::destroy () |
338 | rxvt_term::destroy () |
297 | { |
339 | { |
298 | if (destroy_ev.active) |
340 | if (destroy_ev.active) |
299 | return; |
341 | return; |
300 | |
342 | |
… | |
… | |
343 | } |
385 | } |
344 | |
386 | |
345 | void |
387 | void |
346 | rxvt_term::destroy_cb (time_watcher &w) |
388 | rxvt_term::destroy_cb (time_watcher &w) |
347 | { |
389 | { |
348 | SET_R (this); |
390 | make_current (); |
349 | |
391 | |
350 | delete this; |
392 | delete this; |
351 | } |
393 | } |
352 | |
394 | |
353 | /*----------------------------------------------------------------------*/ |
395 | /*----------------------------------------------------------------------*/ |
… | |
… | |
418 | { |
460 | { |
419 | if (GET_R->allowedxerror == -1) |
461 | if (GET_R->allowedxerror == -1) |
420 | GET_R->allowedxerror = event->error_code; |
462 | GET_R->allowedxerror = event->error_code; |
421 | else |
463 | else |
422 | { |
464 | { |
423 | //TODO: GET_R is most likely not the terminal which caused the error |
465 | // GET_R is most likely not the terminal which caused the error, |
424 | //TODO: maybe just output the error and continue? |
466 | // so just output the error and continue |
425 | #if ENABLE_FRILLS |
467 | #if ENABLE_FRILLS |
426 | print_x_error (display, event); |
468 | print_x_error (display, event); |
427 | #else |
469 | #else |
428 | old_xerror_handler (display, event); |
470 | old_xerror_handler (display, event); |
429 | #endif |
471 | #endif |
… | |
… | |
439 | DisplayString (display)); |
481 | DisplayString (display)); |
440 | rxvt_emergency_cleanup (); |
482 | rxvt_emergency_cleanup (); |
441 | _exit (EXIT_FAILURE); |
483 | _exit (EXIT_FAILURE); |
442 | } |
484 | } |
443 | |
485 | |
444 | /* |
|
|
445 | * Catch a fatal signal and tidy up before quitting |
|
|
446 | */ |
|
|
447 | void |
|
|
448 | rxvt_term::sig_term (sig_watcher &w) |
|
|
449 | { |
|
|
450 | #ifdef DEBUG_CMD |
|
|
451 | rxvt_warn ("caught signal %d, exiting.\n", w.signum); |
|
|
452 | #endif |
|
|
453 | rxvt_emergency_cleanup (); |
|
|
454 | signal (w.signum, SIG_DFL); |
|
|
455 | kill (getpid (), w.signum); |
|
|
456 | } |
|
|
457 | |
|
|
458 | /*----------------------------------------------------------------------*/ |
486 | /*----------------------------------------------------------------------*/ |
459 | /* rxvt_init () */ |
|
|
460 | bool |
487 | bool |
461 | rxvt_term::init (int argc, const char *const *argv) |
488 | rxvt_term::init (int argc, const char *const *argv) |
462 | { |
489 | { |
463 | SET_R (this); |
490 | SET_R (this); |
464 | |
|
|
465 | set_locale (""); |
491 | set_locale (""); |
|
|
492 | set_environ (envv); // few things in X do not call setlocale :( |
466 | |
493 | |
467 | if (!init_vars ()) |
494 | if (!init_vars ()) |
468 | return false; |
495 | return false; |
469 | |
496 | |
470 | init_secondary (); |
497 | init_secondary (); |
… | |
… | |
477 | |
504 | |
478 | #if MENUBAR_MAX |
505 | #if MENUBAR_MAX |
479 | menubar_read (rs[Rs_menu]); |
506 | menubar_read (rs[Rs_menu]); |
480 | #endif |
507 | #endif |
481 | #ifdef HAVE_SCROLLBARS |
508 | #ifdef HAVE_SCROLLBARS |
482 | if (options & Opt_scrollBar) |
509 | if (OPTION (Opt_scrollBar)) |
483 | scrollBar.setIdle (); /* set existence for size calculations */ |
510 | scrollBar.setIdle (); /* set existence for size calculations */ |
484 | #endif |
511 | #endif |
485 | |
512 | |
|
|
513 | #if ENABLE_PERL |
|
|
514 | if (!rs[Rs_perl_ext_1]) |
|
|
515 | rs[Rs_perl_ext_1] = "default"; |
|
|
516 | |
|
|
517 | if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) |
|
|
518 | || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) |
|
|
519 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
|
|
520 | { |
|
|
521 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
522 | // ignore some perl-related arguments if some bozo installed us set[ug]id |
|
|
523 | if (rxvt_tainted ()) |
|
|
524 | { |
|
|
525 | if ((rs[Rs_perl_lib] && *rs[Rs_perl_lib]) |
|
|
526 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
|
|
527 | { |
|
|
528 | rxvt_warn ("running with elevated privileges: ignoring perl-lib and perl-eval.\n"); |
|
|
529 | rs[Rs_perl_lib] = 0; |
|
|
530 | rs[Rs_perl_eval] = 0; |
|
|
531 | } |
|
|
532 | } |
|
|
533 | #endif |
|
|
534 | rxvt_perl.init (); |
|
|
535 | setlocale (LC_CTYPE, curlocale); // perl init destroys current locale |
|
|
536 | HOOK_INVOKE ((this, HOOK_INIT, DT_END)); |
|
|
537 | } |
|
|
538 | #endif |
|
|
539 | |
486 | create_windows (argc, argv); |
540 | create_windows (argc, argv); |
487 | |
541 | |
488 | dDisp; |
542 | dDisp; |
489 | |
543 | |
490 | init_xlocale (); |
544 | init_xlocale (); |
491 | |
545 | |
492 | scr_reset (); /* initialize screen */ |
546 | scr_reset (); // initialize screen |
493 | |
547 | |
494 | #if 0 |
548 | #if 0 |
495 | XSynchronize (disp, True); |
549 | XSynchronize (disp, True); |
496 | #endif |
550 | #endif |
497 | |
551 | |
498 | #ifdef HAVE_SCROLLBARS |
552 | #ifdef HAVE_SCROLLBARS |
499 | if (options & Opt_scrollBar) |
553 | if (OPTION (Opt_scrollBar)) |
500 | resize_scrollbar (); /* create and map scrollbar */ |
554 | resize_scrollbar (); /* create and map scrollbar */ |
501 | #endif |
555 | #endif |
502 | #if (MENUBAR_MAX) |
556 | #if (MENUBAR_MAX) |
503 | if (menubar_visible ()) |
557 | if (menubar_visible ()) |
504 | XMapWindow (disp, menuBar.win); |
558 | XMapWindow (disp, menuBar.win); |
505 | #endif |
559 | #endif |
506 | #ifdef TRANSPARENT |
560 | #ifdef TRANSPARENT |
507 | if (options & Opt_transparent) |
561 | if (OPTION (Opt_transparent)) |
508 | { |
562 | { |
509 | XSelectInput (disp, display->root, PropertyChangeMask); |
563 | XSelectInput (disp, display->root, PropertyChangeMask); |
510 | check_our_parents (); |
564 | check_our_parents (); |
511 | rootwin_ev.start (display, display->root); |
565 | rootwin_ev.start (display, display->root); |
512 | } |
566 | } |
513 | #endif |
567 | #endif |
514 | |
568 | |
515 | XMapWindow (disp, TermWin.vt); |
569 | XMapWindow (disp, vt); |
516 | XMapWindow (disp, TermWin.parent[0]); |
570 | XMapWindow (disp, parent[0]); |
517 | |
571 | |
518 | set_colorfgbg (); |
572 | set_colorfgbg (); |
519 | |
573 | |
520 | init_command (cmd_argv); |
574 | init_command (cmd_argv); |
521 | |
575 | |
522 | free (cmd_argv); |
576 | free (cmd_argv); |
523 | |
577 | |
|
|
578 | if (pty.pty >= 0) |
524 | pty_ev.start (pty.pty, EVENT_READ); |
579 | pty_ev.start (pty.pty, EVENT_READ); |
525 | |
580 | |
526 | check_ev.start (); |
581 | check_ev.start (); |
527 | |
582 | |
|
|
583 | HOOK_INVOKE ((this, HOOK_START, DT_END)); |
|
|
584 | |
528 | return true; |
585 | return true; |
529 | } |
586 | } |
530 | |
587 | |
|
|
588 | static struct sig_handlers |
|
|
589 | { |
|
|
590 | sig_watcher sw_chld, sw_term, sw_int; |
|
|
591 | |
|
|
592 | void sig_chld (sig_watcher &w) |
|
|
593 | { |
|
|
594 | // we are being called for every SIGCHLD, find the corresponding term |
|
|
595 | int pid; |
|
|
596 | |
|
|
597 | while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) |
|
|
598 | for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) |
|
|
599 | if (pid == (*t)->cmd_pid) |
|
|
600 | { |
|
|
601 | (*t)->child_exit (); |
|
|
602 | break; |
|
|
603 | } |
|
|
604 | } |
|
|
605 | |
|
|
606 | /* |
|
|
607 | * Catch a fatal signal and tidy up before quitting |
|
|
608 | */ |
|
|
609 | void |
|
|
610 | sig_term (sig_watcher &w) |
|
|
611 | { |
|
|
612 | #ifdef DEBUG_CMD |
|
|
613 | rxvt_warn ("caught signal %d, exiting.\n", w.signum); |
|
|
614 | #endif |
|
|
615 | rxvt_emergency_cleanup (); |
|
|
616 | signal (w.signum, SIG_DFL); |
|
|
617 | kill (getpid (), w.signum); |
|
|
618 | } |
|
|
619 | |
|
|
620 | sig_handlers () |
|
|
621 | : sw_chld (this, &sig_handlers::sig_chld), |
|
|
622 | sw_term (this, &sig_handlers::sig_term), |
|
|
623 | sw_int (this, &sig_handlers::sig_term) |
|
|
624 | { |
|
|
625 | } |
|
|
626 | } sig_handlers; |
|
|
627 | |
|
|
628 | char **rxvt_environ; // startup environment |
|
|
629 | |
531 | void |
630 | void |
532 | rxvt_init () |
631 | rxvt_init () |
533 | { |
632 | { |
|
|
633 | rxvt_environ = environ; |
|
|
634 | |
534 | /* |
635 | /* |
535 | * Save and then give up any super-user privileges |
636 | * Save and then give up any super-user privileges |
536 | * If we need privileges in any area then we must specifically request it. |
637 | * If we need privileges in any area then we must specifically request it. |
537 | * We should only need to be root in these cases: |
638 | * We should only need to be root in these cases: |
538 | * 1. write utmp entries on some systems |
639 | * 1. write utmp entries on some systems |
… | |
… | |
542 | rxvt_privileges (IGNORE); |
643 | rxvt_privileges (IGNORE); |
543 | |
644 | |
544 | signal (SIGHUP, SIG_IGN); |
645 | signal (SIGHUP, SIG_IGN); |
545 | signal (SIGPIPE, SIG_IGN); |
646 | signal (SIGPIPE, SIG_IGN); |
546 | |
647 | |
|
|
648 | sig_handlers.sw_chld.start (SIGCHLD); |
|
|
649 | sig_handlers.sw_term.start (SIGTERM); |
|
|
650 | sig_handlers.sw_int.start (SIGINT); |
|
|
651 | |
547 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
652 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
548 | /* signal (SIGURG, SIG_DFL); */ |
653 | /* signal (SIGURG, SIG_DFL); */ |
549 | |
654 | |
550 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
655 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
551 | // TODO: handle this with exceptions and tolerate the memory loss |
656 | // TODO: handle this with exceptions and tolerate the memory loss |
552 | XSetIOErrorHandler (rxvt_xioerror_handler); |
657 | XSetIOErrorHandler (rxvt_xioerror_handler); |
553 | } |
|
|
554 | |
658 | |
555 | /* ------------------------------------------------------------------------- * |
659 | XrmInitialize (); |
556 | * SIGNAL HANDLING & EXIT HANDLER * |
|
|
557 | * ------------------------------------------------------------------------- */ |
|
|
558 | /* |
|
|
559 | * Catch a SIGCHLD signal and exit if the direct child has died |
|
|
560 | */ |
|
|
561 | |
|
|
562 | void |
|
|
563 | rxvt_term::sig_chld (sig_watcher &w) |
|
|
564 | { |
|
|
565 | // we are being called for every SIGCHLD, not just ours |
|
|
566 | int pid; |
|
|
567 | |
|
|
568 | while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) |
|
|
569 | for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++) |
|
|
570 | if (pid == (*t)->cmd_pid) |
|
|
571 | { |
|
|
572 | (*t)->destroy (); |
|
|
573 | break; |
|
|
574 | } |
|
|
575 | } |
660 | } |
576 | |
661 | |
577 | /* ------------------------------------------------------------------------- * |
662 | /* ------------------------------------------------------------------------- * |
578 | * MEMORY ALLOCATION WRAPPERS * |
663 | * MEMORY ALLOCATION WRAPPERS * |
579 | * ------------------------------------------------------------------------- */ |
664 | * ------------------------------------------------------------------------- */ |
… | |
… | |
586 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
671 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
587 | |
672 | |
588 | return p; |
673 | return p; |
589 | } |
674 | } |
590 | |
675 | |
591 | /* INTPROTO */ |
676 | void * |
592 | void * |
|
|
593 | rxvt_calloc (size_t number, size_t size) |
677 | rxvt_calloc (size_t number, size_t size) |
594 | { |
678 | { |
595 | void *p = calloc (number, size); |
679 | void *p = calloc (number, size); |
596 | |
680 | |
597 | if (!p) |
681 | if (!p) |
598 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
682 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
599 | |
683 | |
600 | return p; |
684 | return p; |
601 | } |
685 | } |
602 | |
686 | |
603 | /* INTPROTO */ |
|
|
604 | void * |
687 | void * |
605 | rxvt_realloc (void *ptr, size_t size) |
688 | rxvt_realloc (void *ptr, size_t size) |
606 | { |
689 | { |
607 | void *p = realloc (ptr, size); |
690 | void *p = realloc (ptr, size); |
608 | |
691 | |
… | |
… | |
617 | * ------------------------------------------------------------------------- */ |
700 | * ------------------------------------------------------------------------- */ |
618 | /* take care of suid/sgid super-user (root) privileges */ |
701 | /* take care of suid/sgid super-user (root) privileges */ |
619 | void |
702 | void |
620 | rxvt_privileges (rxvt_privaction action) |
703 | rxvt_privileges (rxvt_privaction action) |
621 | { |
704 | { |
622 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
623 | static uid_t euid; |
|
|
624 | static gid_t egid; |
|
|
625 | #endif |
|
|
626 | |
|
|
627 | #if ! defined(__CYGWIN32__) |
705 | #if ! defined(__CYGWIN32__) |
628 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
706 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
629 | /* setreuid () is the poor man's setuid (), seteuid () */ |
707 | /* setreuid () is the poor man's setuid (), seteuid () */ |
630 | # define seteuid(a) setreuid(-1, (a)) |
708 | # define seteuid(a) setreuid(-1, (a)) |
631 | # define setegid(a) setregid(-1, (a)) |
709 | # define setegid(a) setregid(-1, (a)) |
… | |
… | |
637 | case IGNORE: |
715 | case IGNORE: |
638 | /* |
716 | /* |
639 | * change effective uid/gid - not real uid/gid - so we can switch |
717 | * change effective uid/gid - not real uid/gid - so we can switch |
640 | * back to root later, as required |
718 | * back to root later, as required |
641 | */ |
719 | */ |
|
|
720 | setegid (getgid ()); |
642 | seteuid (getuid ()); |
721 | seteuid (getuid ()); |
643 | setegid (getgid ()); |
|
|
644 | break; |
722 | break; |
645 | case SAVE: |
723 | case SAVE: |
646 | euid = geteuid (); |
|
|
647 | egid = getegid (); |
724 | saved_egid = getegid (); |
|
|
725 | saved_euid = geteuid (); |
648 | break; |
726 | break; |
649 | case RESTORE: |
727 | case RESTORE: |
650 | seteuid (euid); |
|
|
651 | setegid (egid); |
728 | setegid (saved_egid); |
|
|
729 | seteuid (saved_euid); |
652 | break; |
730 | break; |
653 | } |
731 | } |
654 | # else |
732 | # else |
655 | switch (action) |
733 | switch (action) |
656 | { |
734 | { |
657 | case IGNORE: |
735 | case IGNORE: |
|
|
736 | setgid (getgid ()); |
658 | setuid (getuid ()); |
737 | setuid (getuid ()); |
659 | setgid (getgid ()); |
|
|
660 | /* FALLTHROUGH */ |
738 | /* FALLTHROUGH */ |
661 | case SAVE: |
739 | case SAVE: |
662 | /* FALLTHROUGH */ |
740 | /* FALLTHROUGH */ |
663 | case RESTORE: |
741 | case RESTORE: |
664 | break; |
742 | break; |
… | |
… | |
669 | |
747 | |
670 | #ifdef UTMP_SUPPORT |
748 | #ifdef UTMP_SUPPORT |
671 | void |
749 | void |
672 | rxvt_term::privileged_utmp (rxvt_privaction action) |
750 | rxvt_term::privileged_utmp (rxvt_privaction action) |
673 | { |
751 | { |
674 | if ((options & Opt_utmpInhibit) |
752 | if (OPTION (Opt_utmpInhibit) |
675 | || !pty.name || !*pty.name) |
753 | || !pty.name || !*pty.name) |
676 | return; |
754 | return; |
677 | |
755 | |
678 | rxvt_privileges (RESTORE); |
756 | rxvt_privileges (RESTORE); |
679 | |
757 | |
… | |
… | |
690 | /* |
768 | /* |
691 | * window size/position calculcations for XSizeHint and other storage. |
769 | * window size/position calculcations for XSizeHint and other storage. |
692 | * if width/height are non-zero then override calculated width/height |
770 | * if width/height are non-zero then override calculated width/height |
693 | */ |
771 | */ |
694 | void |
772 | void |
695 | rxvt_term::window_calc (unsigned int width, unsigned int height) |
773 | rxvt_term::window_calc (unsigned int newwidth, unsigned int newheight) |
696 | { |
774 | { |
697 | short recalc_x, recalc_y; |
775 | short recalc_x, recalc_y; |
698 | int x, y, sb_w, mb_h, flags; |
776 | int x, y, sb_w, mb_h, flags; |
699 | unsigned int w, h; |
777 | unsigned int w, h; |
700 | unsigned int max_width, max_height; |
778 | unsigned int max_width, max_height; |
701 | dDisp; |
779 | dDisp; |
702 | |
780 | |
703 | D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
781 | D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
704 | TermWin.ncol, TermWin.nrow, szHint.width, |
782 | ncol, nrow, szHint.width, szHint.height)); |
705 | szHint.height)); |
783 | |
706 | szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; |
784 | szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; |
707 | szHint.win_gravity = NorthWestGravity; |
785 | szHint.win_gravity = NorthWestGravity; |
708 | /* szHint.min_aspect.x = szHint.min_aspect.y = 1; */ |
786 | /* szHint.min_aspect.x = szHint.min_aspect.y = 1; */ |
709 | |
787 | |
710 | recalc_x = recalc_y = 0; |
788 | recalc_x = recalc_y = 0; |
711 | flags = 0; |
789 | flags = 0; |
|
|
790 | |
712 | if (!parsed_geometry) |
791 | if (!parsed_geometry) |
713 | { |
792 | { |
714 | parsed_geometry = 1; |
793 | parsed_geometry = 1; |
|
|
794 | |
715 | if (rs[Rs_geometry]) |
795 | if (rs[Rs_geometry]) |
716 | flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h); |
796 | flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h); |
|
|
797 | |
717 | if (flags & WidthValue) |
798 | if (flags & WidthValue) |
718 | { |
799 | { |
719 | TermWin.ncol = BOUND_POSITIVE_INT16 (w); |
800 | ncol = clamp (w, 0, std::numeric_limits<int16_t>::max ()); |
720 | szHint.flags |= USSize; |
801 | szHint.flags |= USSize; |
721 | } |
802 | } |
|
|
803 | |
722 | if (flags & HeightValue) |
804 | if (flags & HeightValue) |
723 | { |
805 | { |
724 | TermWin.nrow = BOUND_POSITIVE_INT16 (h); |
806 | nrow = clamp (h, 0, std::numeric_limits<int16_t>::max ()); |
725 | szHint.flags |= USSize; |
807 | szHint.flags |= USSize; |
726 | } |
808 | } |
|
|
809 | |
727 | if (flags & XValue) |
810 | if (flags & XValue) |
728 | { |
811 | { |
729 | szHint.x = x; |
812 | szHint.x = x; |
730 | szHint.flags |= USPosition; |
813 | szHint.flags |= USPosition; |
|
|
814 | |
731 | if (flags & XNegative) |
815 | if (flags & XNegative) |
732 | { |
816 | { |
733 | recalc_x = 1; |
817 | recalc_x = 1; |
734 | szHint.win_gravity = NorthEastGravity; |
818 | szHint.win_gravity = NorthEastGravity; |
735 | } |
819 | } |
736 | } |
820 | } |
|
|
821 | |
737 | if (flags & YValue) |
822 | if (flags & YValue) |
738 | { |
823 | { |
739 | szHint.y = y; |
824 | szHint.y = y; |
740 | szHint.flags |= USPosition; |
825 | szHint.flags |= USPosition; |
|
|
826 | |
741 | if (flags & YNegative) |
827 | if (flags & YNegative) |
742 | { |
828 | { |
743 | recalc_y = 1; |
829 | recalc_y = 1; |
|
|
830 | |
744 | if (szHint.win_gravity == NorthEastGravity) |
831 | if (szHint.win_gravity == NorthEastGravity) |
745 | szHint.win_gravity = SouthEastGravity; |
832 | szHint.win_gravity = SouthEastGravity; |
746 | else |
833 | else |
747 | szHint.win_gravity = SouthWestGravity; |
834 | szHint.win_gravity = SouthWestGravity; |
748 | } |
835 | } |
749 | } |
836 | } |
750 | } |
837 | } |
751 | |
838 | |
752 | /* TODO: BOUNDS */ |
839 | /* TODO: BOUNDS */ |
753 | TermWin.width = TermWin.ncol * TermWin.fwidth; |
840 | width = ncol * fwidth; |
754 | TermWin.height = TermWin.nrow * TermWin.fheight; |
841 | height = nrow * fheight; |
755 | max_width = MAX_COLS * TermWin.fwidth; |
842 | max_width = MAX_COLS * fwidth; |
756 | max_height = MAX_ROWS * TermWin.fheight; |
843 | max_height = MAX_ROWS * fheight; |
757 | |
844 | |
758 | szHint.base_width = szHint.base_height = 2 * TermWin.int_bwidth; |
845 | szHint.base_width = szHint.base_height = 2 * int_bwidth; |
759 | |
846 | |
760 | sb_w = mb_h = 0; |
847 | sb_w = mb_h = 0; |
761 | window_vt_x = window_vt_y = TermWin.int_bwidth; |
848 | window_vt_x = window_vt_y = int_bwidth; |
762 | |
849 | |
763 | if (scrollbar_visible ()) |
850 | if (scrollbar_visible ()) |
764 | { |
851 | { |
765 | sb_w = scrollbar_TotalWidth (); |
852 | sb_w = scrollbar_TotalWidth (); |
766 | szHint.base_width += sb_w; |
853 | szHint.base_width += sb_w; |
767 | if (!(options & Opt_scrollBar_right)) |
854 | if (!OPTION (Opt_scrollBar_right)) |
768 | window_vt_x += sb_w; |
855 | window_vt_x += sb_w; |
769 | } |
856 | } |
770 | |
857 | |
771 | if (menubar_visible ()) |
858 | if (menubar_visible ()) |
772 | { |
859 | { |
773 | mb_h = menuBar_TotalHeight (); |
860 | mb_h = menuBar_TotalHeight (); |
774 | szHint.base_height += mb_h; |
861 | szHint.base_height += mb_h; |
775 | window_vt_y += mb_h; |
862 | window_vt_y += mb_h; |
776 | } |
863 | } |
777 | |
864 | |
778 | szHint.width_inc = TermWin.fwidth; |
865 | szHint.width_inc = fwidth; |
779 | szHint.height_inc = TermWin.fheight; |
866 | szHint.height_inc = fheight; |
780 | szHint.min_width = szHint.base_width + szHint.width_inc; |
867 | szHint.min_width = szHint.base_width + szHint.width_inc; |
781 | szHint.min_height = szHint.base_height + szHint.height_inc; |
868 | szHint.min_height = szHint.base_height + szHint.height_inc; |
782 | |
869 | |
783 | if (width && width - szHint.base_width < max_width) |
870 | if (newwidth && newwidth - szHint.base_width < max_width) |
784 | { |
871 | { |
785 | szHint.width = width; |
872 | szHint.width = newwidth; |
786 | TermWin.width = width - szHint.base_width; |
873 | width = newwidth - szHint.base_width; |
787 | } |
874 | } |
788 | else |
875 | else |
789 | { |
876 | { |
790 | MIN_IT (TermWin.width, max_width); |
877 | min_it (width, max_width); |
791 | szHint.width = szHint.base_width + TermWin.width; |
878 | szHint.width = szHint.base_width + width; |
792 | } |
879 | } |
793 | |
880 | |
794 | if (height && height - szHint.base_height < max_height) |
881 | if (newheight && newheight - szHint.base_height < max_height) |
795 | { |
882 | { |
796 | szHint.height = height; |
883 | szHint.height = newheight; |
797 | TermWin.height = height - szHint.base_height; |
884 | height = newheight - szHint.base_height; |
798 | } |
885 | } |
799 | else |
886 | else |
800 | { |
887 | { |
801 | MIN_IT (TermWin.height, max_height); |
888 | min_it (height, max_height); |
802 | szHint.height = szHint.base_height + TermWin.height; |
889 | szHint.height = szHint.base_height + height; |
803 | } |
890 | } |
804 | |
891 | |
805 | if (scrollbar_visible () && (options & Opt_scrollBar_right)) |
892 | if (scrollbar_visible () && OPTION (Opt_scrollBar_right)) |
806 | window_sb_x = szHint.width - sb_w; |
893 | window_sb_x = szHint.width - sb_w; |
807 | |
894 | |
808 | if (recalc_x) |
895 | if (recalc_x) |
809 | szHint.x += (DisplayWidth (disp, display->screen) |
896 | szHint.x += DisplayWidth (disp, display->screen) - szHint.width - 2 * ext_bwidth; |
810 | - szHint.width - 2 * TermWin.ext_bwidth); |
|
|
811 | if (recalc_y) |
897 | if (recalc_y) |
812 | szHint.y += (DisplayHeight (disp, display->screen) |
898 | szHint.y += DisplayHeight (disp, display->screen) - szHint.height - 2 * ext_bwidth; |
813 | - szHint.height - 2 * TermWin.ext_bwidth); |
|
|
814 | |
899 | |
815 | TermWin.ncol = TermWin.width / TermWin.fwidth; |
900 | ncol = width / fwidth; |
816 | TermWin.nrow = TermWin.height / TermWin.fheight; |
901 | nrow = height / fheight; |
817 | D_SIZE ((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
902 | D_SIZE ((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
818 | TermWin.ncol, TermWin.nrow, szHint.width, |
903 | ncol, nrow, szHint.width, |
819 | szHint.height)); |
904 | szHint.height)); |
820 | return; |
905 | return; |
821 | } |
906 | } |
822 | |
907 | |
823 | /*----------------------------------------------------------------------*/ |
908 | /*----------------------------------------------------------------------*/ |
… | |
… | |
831 | if (pty.pty < 0) |
916 | if (pty.pty < 0) |
832 | return; |
917 | return; |
833 | |
918 | |
834 | struct winsize ws; |
919 | struct winsize ws; |
835 | |
920 | |
836 | ws.ws_col = TermWin.ncol; |
921 | ws.ws_col = ncol; |
837 | ws.ws_row = TermWin.nrow; |
922 | ws.ws_row = nrow; |
838 | ws.ws_xpixel = TermWin.width; |
923 | ws.ws_xpixel = width; |
839 | ws.ws_ypixel = TermWin.height; |
924 | ws.ws_ypixel = height; |
840 | (void)ioctl (pty.pty, TIOCSWINSZ, &ws); |
925 | (void)ioctl (pty.pty, TIOCSWINSZ, &ws); |
841 | |
926 | |
842 | #if 0 |
927 | #if 0 |
843 | // TIOCSWINSZ⎈ is supposed to do this automatically and correctly |
928 | // TIOCSWINSZ⎈ is supposed to do this automatically and correctly |
844 | if (cmd_pid) /* force through to the command */ |
929 | if (cmd_pid) /* force through to the command */ |
845 | kill (cmd_pid, SIGWINCH); |
930 | kill (-cmd_pid, SIGWINCH); |
846 | #endif |
931 | #endif |
847 | } |
932 | } |
848 | |
933 | |
849 | /*----------------------------------------------------------------------*/ |
934 | /*----------------------------------------------------------------------*/ |
850 | /* set_fonts () - load and set the various fonts |
935 | /* set_fonts () - load and set the various fonts |
851 | /* |
936 | * |
852 | * init = 1 - initialize |
937 | * init = 1 - initialize |
853 | * |
938 | * |
854 | * fontname == FONT_UP - switch to bigger font |
939 | * fontname == FONT_UP - switch to bigger font |
855 | * fontname == FONT_DN - switch to smaller font |
940 | * fontname == FONT_DN - switch to smaller font |
856 | */ |
941 | */ |
… | |
… | |
868 | return false; |
953 | return false; |
869 | } |
954 | } |
870 | |
955 | |
871 | #if ENABLE_STYLES |
956 | #if ENABLE_STYLES |
872 | for (int i = RS_styleCount; --i; ) |
957 | for (int i = RS_styleCount; --i; ) |
873 | if (TermWin.fontset[i] != TermWin.fontset[0]) |
958 | if (fontset[i] != fontset[0]) |
874 | delete TermWin.fontset[i]; |
959 | delete fontset[i]; |
875 | #endif |
960 | #endif |
876 | |
961 | |
877 | delete TermWin.fontset[0]; |
962 | delete fontset[0]; |
878 | TermWin.fontset[0] = fs; |
963 | fontset[0] = fs; |
879 | |
964 | |
880 | prop = (*fs)[1]->properties (); |
965 | prop = (*fs)[1]->properties (); |
881 | prop.height += TermWin.lineSpace; |
966 | prop.height += lineSpace; |
882 | fs->set_prop (prop); |
967 | fs->set_prop (prop); |
883 | |
968 | |
884 | TermWin.fwidth = prop.width; |
969 | fwidth = prop.width; |
885 | TermWin.fheight = prop.height; |
970 | fheight = prop.height; |
886 | TermWin.fweight = prop.weight; |
971 | fbase = prop.ascent; |
887 | TermWin.fslant = prop.slant; |
|
|
888 | TermWin.fbase = (*fs)[1]->ascent; |
|
|
889 | |
972 | |
890 | for (int style = 1; style < 4; style++) |
973 | for (int style = 1; style < 4; style++) |
891 | { |
974 | { |
892 | #if ENABLE_STYLES |
975 | #if ENABLE_STYLES |
893 | const char *res = rs[Rs_font + style]; |
976 | const char *res = rs[Rs_font + style]; |
894 | |
977 | |
895 | if (res && !*res) |
978 | if (res && !*res) |
896 | TermWin.fontset[style] = TermWin.fontset[0]; |
979 | fontset[style] = fontset[0]; |
897 | else |
980 | else |
898 | { |
981 | { |
899 | TermWin.fontset[style] = fs = new rxvt_fontset (this); |
982 | fontset[style] = fs = new rxvt_fontset (this); |
900 | rxvt_fontprop prop2 = prop; |
983 | rxvt_fontprop prop2 = prop; |
901 | |
984 | |
902 | if (res) |
985 | if (res) |
903 | prop2.weight = prop2.slant = rxvt_fontprop::unset; |
986 | prop2.weight = prop2.slant = rxvt_fontprop::unset; |
904 | else |
987 | else |
905 | { |
988 | { |
906 | res = TermWin.fontset[0]->fontdesc; |
989 | res = fontset[0]->fontdesc; |
907 | |
990 | |
908 | if (SET_STYLE (0, style) & RS_Bold) prop2.weight = rxvt_fontprop::bold; |
991 | if (SET_STYLE (0, style) & RS_Bold) prop2.weight = rxvt_fontprop::bold; |
909 | if (SET_STYLE (0, style) & RS_Italic) prop2.slant = rxvt_fontprop::italic; |
992 | if (SET_STYLE (0, style) & RS_Italic) prop2.slant = rxvt_fontprop::italic; |
910 | } |
993 | } |
911 | |
994 | |
912 | fs->populate (res); |
995 | fs->populate (res); |
913 | fs->set_prop (prop2); |
996 | fs->set_prop (prop2); |
914 | } |
997 | } |
915 | #else |
998 | #else |
916 | TermWin.fontset[style] = TermWin.fontset[0]; |
999 | fontset[style] = fontset[0]; |
917 | #endif |
1000 | #endif |
918 | } |
1001 | } |
919 | |
1002 | |
920 | if (TermWin.parent[0]) |
1003 | if (parent[0]) |
921 | { |
1004 | { |
922 | resize_all_windows (0, 0, 0); |
1005 | resize_all_windows (0, 0, 0); |
923 | scr_remap_chars (); |
1006 | scr_remap_chars (); |
924 | scr_touch (true); |
1007 | scr_touch (true); |
925 | } |
1008 | } |
… | |
… | |
927 | return true; |
1010 | return true; |
928 | } |
1011 | } |
929 | |
1012 | |
930 | void rxvt_term::set_string_property (Atom prop, const char *str, int len) |
1013 | void rxvt_term::set_string_property (Atom prop, const char *str, int len) |
931 | { |
1014 | { |
932 | // TODO: SMART_WINDOW_TITLE |
|
|
933 | XChangeProperty (display->display, TermWin.parent[0], |
1015 | XChangeProperty (display->display, parent[0], |
934 | prop, XA_STRING, 8, PropModeReplace, |
1016 | prop, XA_STRING, 8, PropModeReplace, |
935 | (const unsigned char *)str, len >= 0 ? len : strlen (str)); |
1017 | (const unsigned char *)str, len >= 0 ? len : strlen (str)); |
936 | } |
1018 | } |
937 | |
1019 | |
938 | void rxvt_term::set_utf8_property (Atom prop, const char *str, int len) |
1020 | void rxvt_term::set_utf8_property (Atom prop, const char *str, int len) |
939 | { |
1021 | { |
940 | // TODO: SMART_WINDOW_TITLE |
|
|
941 | wchar_t *ws = rxvt_mbstowcs (str, len); |
1022 | wchar_t *ws = rxvt_mbstowcs (str, len); |
942 | char *s = rxvt_wcstoutf8 (ws); |
1023 | char *s = rxvt_wcstoutf8 (ws); |
943 | |
1024 | |
944 | XChangeProperty (display->display, TermWin.parent[0], |
1025 | XChangeProperty (display->display, parent[0], |
945 | prop, xa[XA_UTF8_STRING], 8, PropModeReplace, |
1026 | prop, xa[XA_UTF8_STRING], 8, PropModeReplace, |
946 | (const unsigned char *)s, strlen (s)); |
1027 | (const unsigned char *)s, strlen (s)); |
947 | |
1028 | |
948 | free (s); |
1029 | free (s); |
949 | free (ws); |
1030 | free (ws); |
… | |
… | |
954 | /* xterm sequences - title, iconName, color (exptl) */ |
1035 | /* xterm sequences - title, iconName, color (exptl) */ |
955 | void |
1036 | void |
956 | rxvt_term::set_title (const char *str) |
1037 | rxvt_term::set_title (const char *str) |
957 | { |
1038 | { |
958 | set_string_property (XA_WM_NAME, str); |
1039 | set_string_property (XA_WM_NAME, str); |
959 | #if ENABLE_FRILLS |
1040 | #if ENABLE_EWMH |
960 | set_utf8_property (xa[XA_NET_WM_NAME], str); |
1041 | set_utf8_property (xa[XA_NET_WM_NAME], str); |
961 | #endif |
1042 | #endif |
962 | } |
1043 | } |
963 | |
1044 | |
964 | void |
1045 | void |
965 | rxvt_term::set_icon_name (const char *str) |
1046 | rxvt_term::set_icon_name (const char *str) |
966 | { |
1047 | { |
967 | set_string_property (XA_WM_ICON_NAME, str); |
1048 | set_string_property (XA_WM_ICON_NAME, str); |
968 | #if ENABLE_FRILLS |
1049 | #if ENABLE_EWMH |
969 | set_utf8_property (xa[XA_NET_WM_ICON_NAME], str); |
1050 | set_utf8_property (xa[XA_NET_WM_ICON_NAME], str); |
970 | #endif |
1051 | #endif |
971 | } |
1052 | } |
972 | |
1053 | |
973 | #ifdef XTERM_COLOR_CHANGE |
1054 | #ifdef XTERM_COLOR_CHANGE |
… | |
… | |
986 | i = atoi (color); |
1067 | i = atoi (color); |
987 | |
1068 | |
988 | if (i >= 8 && i <= 15) |
1069 | if (i >= 8 && i <= 15) |
989 | { /* bright colors */ |
1070 | { /* bright colors */ |
990 | i -= 8; |
1071 | i -= 8; |
991 | # ifndef NO_BRIGHTCOLOR |
|
|
992 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
1072 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
993 | SET_PIXCOLOR (idx); |
1073 | SET_PIXCOLOR (idx); |
994 | goto Done; |
1074 | goto done; |
995 | # endif |
|
|
996 | } |
1075 | } |
997 | |
1076 | |
998 | if (i >= 0 && i <= 7) |
1077 | if (i >= 0 && i <= 7) |
999 | { /* normal colors */ |
1078 | { /* normal colors */ |
1000 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
1079 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
1001 | SET_PIXCOLOR (idx); |
1080 | SET_PIXCOLOR (idx); |
1002 | goto Done; |
1081 | goto done; |
1003 | } |
1082 | } |
1004 | } |
1083 | } |
1005 | |
1084 | |
1006 | if (!rXParseAllocColor (&xcol, color)) |
1085 | if (!rXParseAllocColor (&xcol, color)) |
1007 | return; |
1086 | return; |
… | |
… | |
1027 | pix_colors_focused[idx] = xcol; |
1106 | pix_colors_focused[idx] = xcol; |
1028 | SET_PIXCOLOR (idx); |
1107 | SET_PIXCOLOR (idx); |
1029 | |
1108 | |
1030 | /* XSetWindowAttributes attr; */ |
1109 | /* XSetWindowAttributes attr; */ |
1031 | /* Cursor cursor; */ |
1110 | /* Cursor cursor; */ |
1032 | Done: |
1111 | done: |
|
|
1112 | |
1033 | #ifdef OFF_FOCUS_FADING |
1113 | #if OFF_FOCUS_FADING |
1034 | if (rs[Rs_fade]) |
1114 | if (rs[Rs_fade]) |
1035 | pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade])); |
1115 | pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade]), pix_colors[Color_fade]); |
1036 | #endif |
1116 | #endif |
1037 | |
1117 | |
1038 | /*TODO: handle Color_BD, scrollbar background, etc. */ |
1118 | /*TODO: handle Color_BD, scrollbar background, etc. */ |
1039 | |
1119 | |
1040 | recolour_cursor (); |
1120 | recolour_cursor (); |
… | |
… | |
1111 | |
1191 | |
1112 | /* -------------------------------------------------------------------- * |
1192 | /* -------------------------------------------------------------------- * |
1113 | * - WINDOW RESIZING - * |
1193 | * - WINDOW RESIZING - * |
1114 | * -------------------------------------------------------------------- */ |
1194 | * -------------------------------------------------------------------- */ |
1115 | void |
1195 | void |
1116 | rxvt_term::resize_all_windows (unsigned int width, unsigned int height, int ignoreparent) |
1196 | rxvt_term::resize_all_windows (unsigned int newwidth, unsigned int newheight, int ignoreparent) |
1117 | { |
1197 | { |
1118 | int fix_screen; |
1198 | int fix_screen; |
1119 | #ifdef SMART_RESIZE |
|
|
1120 | int old_width = szHint.width, old_height = szHint.height; |
1199 | int old_width = szHint.width, old_height = szHint.height; |
1121 | #endif |
|
|
1122 | dDisp; |
1200 | dDisp; |
1123 | |
1201 | |
1124 | window_calc (width, height); |
1202 | window_calc (newwidth, newheight); |
1125 | XSetWMNormalHints (disp, TermWin.parent[0], &szHint); |
1203 | XSetWMNormalHints (disp, parent[0], &szHint); |
1126 | |
1204 | |
1127 | if (!ignoreparent) |
1205 | if (!ignoreparent) |
1128 | { |
1206 | { |
1129 | #ifdef SMART_RESIZE |
1207 | #ifdef SMART_RESIZE |
1130 | /* |
1208 | /* |
… | |
… | |
1134 | int x, y, x1, y1; |
1212 | int x, y, x1, y1; |
1135 | int dx, dy; |
1213 | int dx, dy; |
1136 | unsigned int unused_w1, unused_h1, unused_b1, unused_d1; |
1214 | unsigned int unused_w1, unused_h1, unused_b1, unused_d1; |
1137 | Window unused_cr; |
1215 | Window unused_cr; |
1138 | |
1216 | |
1139 | XTranslateCoordinates (disp, TermWin.parent[0], display->root, |
1217 | XTranslateCoordinates (disp, parent[0], display->root, |
1140 | 0, 0, &x, &y, &unused_cr); |
1218 | 0, 0, &x, &y, &unused_cr); |
1141 | XGetGeometry (disp, TermWin.parent[0], &unused_cr, &x1, &y1, |
1219 | XGetGeometry (disp, parent[0], &unused_cr, &x1, &y1, |
1142 | &unused_w1, &unused_h1, &unused_b1, &unused_d1); |
1220 | &unused_w1, &unused_h1, &unused_b1, &unused_d1); |
1143 | /* |
1221 | /* |
1144 | * if display->root isn't the parent window, a WM will probably have offset |
1222 | * if display->root isn't the parent window, a WM will probably have offset |
1145 | * our position for handles and decorations. Counter it |
1223 | * our position for handles and decorations. Counter it |
1146 | */ |
1224 | */ |
… | |
… | |
1163 | if (y < y1) /* top half */ |
1241 | if (y < y1) /* top half */ |
1164 | dy = 0; |
1242 | dy = 0; |
1165 | else if (y == y1) /* exact center */ |
1243 | else if (y == y1) /* exact center */ |
1166 | dy /= 2; |
1244 | dy /= 2; |
1167 | |
1245 | |
1168 | XMoveResizeWindow (disp, TermWin.parent[0], x + dx, y + dy, |
1246 | XMoveResizeWindow (disp, parent[0], x + dx, y + dy, |
1169 | szHint.width, szHint.height); |
1247 | szHint.width, szHint.height); |
1170 | #else |
1248 | #else |
1171 | XResizeWindow (disp, TermWin.parent[0], szHint.width, szHint.height); |
1249 | XResizeWindow (disp, parent[0], szHint.width, szHint.height); |
1172 | #endif |
1250 | #endif |
1173 | } |
1251 | } |
1174 | |
1252 | |
1175 | fix_screen = TermWin.ncol != prev_ncol || TermWin.nrow != prev_nrow; |
1253 | fix_screen = ncol != prev_ncol || nrow != prev_nrow; |
1176 | |
1254 | |
1177 | if (fix_screen || width != old_width || height != old_height) |
1255 | if (fix_screen || newwidth != old_width || newheight != old_height) |
1178 | { |
1256 | { |
1179 | if (scrollbar_visible ()) |
1257 | if (scrollbar_visible ()) |
1180 | { |
1258 | { |
1181 | XMoveResizeWindow (disp, scrollBar.win, |
1259 | XMoveResizeWindow (disp, scrollBar.win, |
1182 | window_sb_x, 0, |
1260 | window_sb_x, 0, |
… | |
… | |
1185 | } |
1263 | } |
1186 | |
1264 | |
1187 | if (menubar_visible ()) |
1265 | if (menubar_visible ()) |
1188 | XMoveResizeWindow (disp, menuBar.win, |
1266 | XMoveResizeWindow (disp, menuBar.win, |
1189 | window_vt_x, 0, |
1267 | window_vt_x, 0, |
1190 | TermWin_TotalWidth (), menuBar_TotalHeight ()); |
1268 | width, menuBar_TotalHeight ()); |
1191 | |
1269 | |
1192 | XMoveResizeWindow (disp, TermWin.vt, |
1270 | XMoveResizeWindow (disp, vt, |
1193 | window_vt_x, window_vt_y, |
1271 | window_vt_x, window_vt_y, |
1194 | TermWin_TotalWidth (), TermWin_TotalHeight ()); |
1272 | width, height); |
1195 | |
1273 | |
1196 | scr_clear (); |
1274 | scr_clear (); |
1197 | #ifdef XPM_BACKGROUND |
1275 | #ifdef XPM_BACKGROUND |
1198 | resize_pixmap (); |
1276 | resize_pixmap (); |
1199 | #endif |
1277 | #endif |
… | |
… | |
1205 | int old_ncol = prev_ncol; |
1283 | int old_ncol = prev_ncol; |
1206 | |
1284 | |
1207 | /* scr_reset only works on the primary screen */ |
1285 | /* scr_reset only works on the primary screen */ |
1208 | if (old_height) /* this is not the first time through */ |
1286 | if (old_height) /* this is not the first time through */ |
1209 | { |
1287 | { |
1210 | unsigned int ncol = TermWin.ncol; |
1288 | unsigned int ocol = ncol; |
1211 | TermWin.ncol = prev_ncol; // save b/c scr_blank_screen_mem uses this |
1289 | ncol = prev_ncol; // save b/c scr_blank_screen_mem uses this |
1212 | curr_screen = scr_change_screen (PRIMARY); |
1290 | curr_screen = scr_change_screen (PRIMARY); |
1213 | TermWin.ncol = ncol; |
1291 | ncol = ocol; |
1214 | } |
1292 | } |
1215 | |
1293 | |
1216 | scr_reset (); |
1294 | scr_reset (); |
1217 | |
1295 | |
1218 | if (curr_screen >= 0) /* this is not the first time through */ |
1296 | if (curr_screen >= 0) /* this is not the first time through */ |
1219 | { |
1297 | { |
1220 | scr_change_screen (curr_screen); |
1298 | scr_change_screen (curr_screen); |
1221 | selection_check (old_ncol != TermWin.ncol ? 4 : 0); |
1299 | selection_check (old_ncol != ncol ? 4 : 0); |
1222 | } |
1300 | } |
1223 | } |
1301 | } |
1224 | |
1302 | |
1225 | old_width = szHint.width; |
1303 | old_width = szHint.width; |
1226 | old_height = szHint.height; |
1304 | old_height = szHint.height; |
1227 | |
1305 | |
1228 | #ifdef XPM_BACKGROUND |
1306 | #ifdef XPM_BACKGROUND |
1229 | if (TermWin.pixmap) |
1307 | if (pixmap) |
1230 | scr_touch (false); |
1308 | scr_touch (false); |
1231 | #endif |
1309 | #endif |
1232 | |
1310 | |
1233 | #ifdef USE_XIM |
1311 | #ifdef USE_XIM |
1234 | IMSetStatusPosition (); |
1312 | IMSetStatusPosition (); |
… | |
… | |
1238 | /* |
1316 | /* |
1239 | * Set the width/height of the vt window in characters. Units are pixels. |
1317 | * Set the width/height of the vt window in characters. Units are pixels. |
1240 | * good for toggling 80/132 columns |
1318 | * good for toggling 80/132 columns |
1241 | */ |
1319 | */ |
1242 | void |
1320 | void |
1243 | rxvt_term::set_widthheight (unsigned int width, unsigned int height) |
1321 | rxvt_term::set_widthheight (unsigned int newwidth, unsigned int newheight) |
1244 | { |
1322 | { |
1245 | XWindowAttributes wattr; |
1323 | XWindowAttributes wattr; |
1246 | |
1324 | |
1247 | if (width == 0 || height == 0) |
1325 | if (newwidth == 0 || newheight == 0) |
1248 | { |
1326 | { |
1249 | XGetWindowAttributes (display->display, display->root, &wattr); |
1327 | XGetWindowAttributes (display->display, display->root, &wattr); |
|
|
1328 | |
1250 | if (width == 0) |
1329 | if (newwidth == 0) |
1251 | width = wattr.width - szHint.base_width; |
1330 | newwidth = wattr.width - szHint.base_width; |
1252 | if (height == 0) |
1331 | if (newheight == 0) |
1253 | height = wattr.height - szHint.base_height; |
1332 | newheight = wattr.height - szHint.base_height; |
1254 | } |
|
|
1255 | |
|
|
1256 | if (width != TermWin.width || height != TermWin.height) |
|
|
1257 | { |
1333 | } |
|
|
1334 | |
|
|
1335 | if (newwidth != width || newheight != height) |
|
|
1336 | { |
1258 | width += szHint.base_width; |
1337 | newwidth += szHint.base_width; |
1259 | height += szHint.base_height; |
1338 | newheight += szHint.base_height; |
1260 | resize_all_windows (width, height, 0); |
1339 | resize_all_windows (newwidth, newheight, 0); |
1261 | } |
1340 | } |
1262 | } |
1341 | } |
1263 | |
1342 | |
1264 | /* -------------------------------------------------------------------- * |
1343 | /* -------------------------------------------------------------------- * |
1265 | * - X INPUT METHOD ROUTINES - * |
1344 | * - X INPUT METHOD ROUTINES - * |
… | |
… | |
1275 | |
1354 | |
1276 | void |
1355 | void |
1277 | rxvt_term::im_set_size (XRectangle &size) |
1356 | rxvt_term::im_set_size (XRectangle &size) |
1278 | { |
1357 | { |
1279 | // the int_bwidth terms make no sense to me |
1358 | // the int_bwidth terms make no sense to me |
1280 | size.x = TermWin.int_bwidth; |
1359 | size.x = int_bwidth; |
1281 | size.y = TermWin.int_bwidth; |
1360 | size.y = int_bwidth; |
1282 | size.width = Width2Pixel (TermWin.ncol) + TermWin.int_bwidth; |
1361 | size.width = Width2Pixel (ncol) + int_bwidth; |
1283 | size.height = Height2Pixel (TermWin.nrow) + TermWin.int_bwidth; |
1362 | size.height = Height2Pixel (nrow) + int_bwidth; |
1284 | } |
1363 | } |
1285 | |
1364 | |
1286 | void |
1365 | void |
1287 | rxvt_term::im_set_preedit_area (XRectangle &preedit_rect, |
1366 | rxvt_term::im_set_preedit_area (XRectangle &preedit_rect, |
1288 | XRectangle &status_rect, |
1367 | XRectangle &status_rect, |
1289 | const XRectangle &needed_rect) |
1368 | const XRectangle &needed_rect) |
1290 | { |
1369 | { |
1291 | preedit_rect.x = needed_rect.width; |
1370 | preedit_rect.x = needed_rect.width; |
1292 | preedit_rect.y = 0; |
1371 | preedit_rect.y = 0; |
1293 | preedit_rect.width = Width2Pixel (TermWin.ncol) - needed_rect.width + 1; |
1372 | preedit_rect.width = Width2Pixel (ncol) - needed_rect.width + 1; |
1294 | preedit_rect.height = TermWin.fheight; |
1373 | preedit_rect.height = fheight; |
1295 | |
1374 | |
1296 | status_rect.x = 0; |
1375 | status_rect.x = 0; |
1297 | status_rect.y = 0; |
1376 | status_rect.y = 0; |
1298 | status_rect.width = needed_rect.width ? needed_rect.width : Width2Pixel (TermWin.ncol) + 1; |
1377 | status_rect.width = needed_rect.width ? needed_rect.width : Width2Pixel (ncol) + 1; |
1299 | status_rect.height = TermWin.fheight; |
1378 | status_rect.height = fheight; |
1300 | } |
1379 | } |
1301 | |
1380 | |
1302 | /* Checking whether input method is running. */ |
1381 | /* Checking whether input method is running. */ |
1303 | bool |
1382 | bool |
1304 | rxvt_term::IMisRunning () |
1383 | rxvt_term::IMisRunning () |
… | |
… | |
1332 | { |
1411 | { |
1333 | XPoint nspot; |
1412 | XPoint nspot; |
1334 | XVaNestedList preedit_attr; |
1413 | XVaNestedList preedit_attr; |
1335 | |
1414 | |
1336 | if (!Input_Context |
1415 | if (!Input_Context |
1337 | || !TermWin.focus |
1416 | || !focus |
1338 | || !(input_style & XIMPreeditPosition)) |
1417 | || !(input_style & XIMPreeditPosition)) |
1339 | return; |
1418 | return; |
1340 | |
1419 | |
1341 | im_set_position (nspot); |
1420 | im_set_position (nspot); |
1342 | |
1421 | |
… | |
… | |
1378 | XRectangle rect, status_rect, needed_rect; |
1457 | XRectangle rect, status_rect, needed_rect; |
1379 | unsigned long fg, bg; |
1458 | unsigned long fg, bg; |
1380 | const char *p; |
1459 | const char *p; |
1381 | char **s; |
1460 | char **s; |
1382 | XIMStyles *xim_styles; |
1461 | XIMStyles *xim_styles; |
|
|
1462 | |
|
|
1463 | set_environ (envv); |
1383 | |
1464 | |
1384 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1465 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1385 | return false; |
1466 | return false; |
1386 | |
1467 | |
1387 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
1468 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
… | |
… | |
1462 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
1543 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
1463 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
1544 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
1464 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
1545 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
1465 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
1546 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
1466 | "*", |
1547 | "*", |
1467 | TermWin.fheight, |
1548 | fheight, |
1468 | TermWin.fheight + 1, TermWin.fheight - 1, |
1549 | fheight + 1, fheight - 1, |
1469 | TermWin.fheight - 2, TermWin.fheight + 2); |
1550 | fheight - 2, fheight + 2); |
1470 | |
1551 | |
1471 | fs = XCreateFontSet (display->display, rs[Rs_imFont] ? rs[Rs_imFont] : pat, |
1552 | fs = XCreateFontSet (display->display, rs[Rs_imFont] ? rs[Rs_imFont] : pat, |
1472 | &missing_charset_list, &missing_charset_count, &def_string); |
1553 | &missing_charset_list, &missing_charset_count, &def_string); |
1473 | |
1554 | |
1474 | if (missing_charset_list) |
1555 | if (missing_charset_list) |
… | |
… | |
1520 | NULL); |
1601 | NULL); |
1521 | } |
1602 | } |
1522 | |
1603 | |
1523 | Input_Context = XCreateIC (xim, |
1604 | Input_Context = XCreateIC (xim, |
1524 | XNInputStyle, input_style, |
1605 | XNInputStyle, input_style, |
1525 | XNClientWindow, TermWin.vt, |
1606 | XNClientWindow, vt, |
1526 | XNFocusWindow, TermWin.parent[0], |
1607 | XNFocusWindow, parent[0], |
1527 | preedit_attr ? XNPreeditAttributes : NULL, |
1608 | preedit_attr ? XNPreeditAttributes : NULL, |
1528 | preedit_attr, |
1609 | preedit_attr, |
1529 | status_attr ? XNStatusAttributes : NULL, |
1610 | status_attr ? XNStatusAttributes : NULL, |
1530 | status_attr, NULL); |
1611 | status_attr, NULL); |
1531 | |
1612 | |
… | |
… | |
1548 | } |
1629 | } |
1549 | |
1630 | |
1550 | void |
1631 | void |
1551 | rxvt_term::im_cb () |
1632 | rxvt_term::im_cb () |
1552 | { |
1633 | { |
1553 | int i, found, had_im; |
1634 | int i; |
1554 | const char *p; |
1635 | const char *p; |
1555 | char **s; |
1636 | char **s; |
1556 | char buf[IMBUFSIZ]; |
1637 | char buf[IMBUFSIZ]; |
1557 | |
1638 | |
1558 | SET_R (this); |
1639 | make_current (); |
1559 | |
1640 | |
1560 | im_destroy (); |
1641 | im_destroy (); |
1561 | |
1642 | |
1562 | D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); |
1643 | D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); |
1563 | if (Input_Context) |
1644 | if (Input_Context) |
… | |
… | |
1615 | { |
1696 | { |
1616 | XRectangle preedit_rect, status_rect, *needed_rect; |
1697 | XRectangle preedit_rect, status_rect, *needed_rect; |
1617 | XVaNestedList preedit_attr, status_attr; |
1698 | XVaNestedList preedit_attr, status_attr; |
1618 | |
1699 | |
1619 | if (!Input_Context |
1700 | if (!Input_Context |
1620 | || !TermWin.focus |
1701 | || !focus |
1621 | || !(input_style & XIMPreeditArea) |
1702 | || !(input_style & XIMPreeditArea) |
1622 | || !IMisRunning ()) |
1703 | || !IMisRunning ()) |
1623 | return; |
1704 | return; |
1624 | |
1705 | |
1625 | /* Getting the necessary width of preedit area */ |
1706 | /* Getting the necessary width of preedit area */ |