… | |
… | |
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. |
… | |
… | |
48 | # include <termios.h> |
48 | # include <termios.h> |
49 | #endif |
49 | #endif |
50 | |
50 | |
51 | vector<rxvt_term *> rxvt_term::termlist; |
51 | vector<rxvt_term *> rxvt_term::termlist; |
52 | |
52 | |
|
|
53 | // used to tell global functions which terminal instance is "active" |
|
|
54 | rxvt_t rxvt_current_term; |
|
|
55 | |
53 | static char curlocale[128], savelocale[128]; |
56 | static char curlocale[128], savelocale[128]; |
54 | |
57 | |
55 | bool |
58 | bool |
56 | rxvt_set_locale (const char *locale) |
59 | rxvt_set_locale (const char *locale) NOTHROW |
57 | { |
60 | { |
58 | if (!locale || !strncmp (locale, curlocale, 128)) |
61 | if (!locale || !strncmp (locale, curlocale, 128)) |
59 | return false; |
62 | return false; |
60 | |
63 | |
61 | strncpy (curlocale, locale, 128); |
64 | strncpy (curlocale, locale, 128); |
62 | setlocale (LC_CTYPE, curlocale); |
65 | setlocale (LC_CTYPE, curlocale); |
63 | return true; |
66 | return true; |
64 | } |
67 | } |
65 | |
68 | |
66 | bool |
69 | void |
67 | rxvt_push_locale (const char *locale) |
70 | rxvt_push_locale (const char *locale) NOTHROW |
68 | { |
71 | { |
69 | strcpy (savelocale, curlocale); |
72 | strcpy (savelocale, curlocale); |
70 | rxvt_set_locale (locale); |
73 | rxvt_set_locale (locale); |
71 | } |
74 | } |
72 | |
75 | |
73 | void |
76 | void |
74 | rxvt_pop_locale () |
77 | rxvt_pop_locale () NOTHROW |
75 | { |
78 | { |
76 | rxvt_set_locale (savelocale); |
79 | rxvt_set_locale (savelocale); |
77 | } |
80 | } |
78 | |
81 | |
79 | #if ENABLE_COMBINING |
82 | #if ENABLE_COMBINING |
… | |
… | |
146 | rootwin_ev (this, &rxvt_term::rootwin_cb), |
149 | rootwin_ev (this, &rxvt_term::rootwin_cb), |
147 | #endif |
150 | #endif |
148 | #ifdef HAVE_SCROLLBARS |
151 | #ifdef HAVE_SCROLLBARS |
149 | scrollbar_ev (this, &rxvt_term::x_cb), |
152 | scrollbar_ev (this, &rxvt_term::x_cb), |
150 | #endif |
153 | #endif |
151 | #ifdef MENUBAR |
|
|
152 | menubar_ev (this, &rxvt_term::x_cb), |
|
|
153 | #endif |
|
|
154 | #ifdef CURSOR_BLINK |
154 | #ifdef CURSOR_BLINK |
155 | cursor_blink_ev (this, &rxvt_term::cursor_blink_cb), |
155 | cursor_blink_ev (this, &rxvt_term::cursor_blink_cb), |
156 | #endif |
156 | #endif |
157 | #ifdef TEXT_BLINK |
157 | #ifdef TEXT_BLINK |
158 | text_blink_ev (this, &rxvt_term::text_blink_cb), |
158 | text_blink_ev (this, &rxvt_term::text_blink_cb), |
… | |
… | |
172 | #ifdef USE_XIM |
172 | #ifdef USE_XIM |
173 | im_ev (this, &rxvt_term::im_cb), |
173 | im_ev (this, &rxvt_term::im_cb), |
174 | #endif |
174 | #endif |
175 | termwin_ev (this, &rxvt_term::x_cb), |
175 | termwin_ev (this, &rxvt_term::x_cb), |
176 | vt_ev (this, &rxvt_term::x_cb), |
176 | vt_ev (this, &rxvt_term::x_cb), |
|
|
177 | child_ev (this, &rxvt_term::child_cb), |
177 | check_ev (this, &rxvt_term::check_cb), |
178 | check_ev (this, &rxvt_term::check_cb), |
178 | flush_ev (this, &rxvt_term::flush_cb), |
179 | flush_ev (this, &rxvt_term::flush_cb), |
179 | destroy_ev (this, &rxvt_term::destroy_cb), |
180 | destroy_ev (this, &rxvt_term::destroy_cb), |
180 | pty_ev (this, &rxvt_term::pty_cb), |
181 | pty_ev (this, &rxvt_term::pty_cb), |
181 | incr_ev (this, &rxvt_term::incr_cb) |
182 | incr_ev (this, &rxvt_term::incr_cb) |
… | |
… | |
184 | |
185 | |
185 | termlist.push_back (this); |
186 | termlist.push_back (this); |
186 | |
187 | |
187 | #ifdef KEYSYM_RESOURCE |
188 | #ifdef KEYSYM_RESOURCE |
188 | keyboard = new keyboard_manager; |
189 | keyboard = new keyboard_manager; |
189 | |
|
|
190 | if (!keyboard) |
|
|
191 | rxvt_fatal ("out of memory, aborting.\n"); |
|
|
192 | #endif |
190 | #endif |
193 | } |
191 | } |
194 | |
192 | |
195 | // clean up the most important stuff, do *not* call x or free mem etc. |
193 | // clean up the most important stuff, do *not* call x or free mem etc. |
196 | // for use before an emergency exit |
194 | // for use before an emergency exit |
197 | void rxvt_term::emergency_cleanup () |
195 | void rxvt_term::emergency_cleanup () |
198 | { |
196 | { |
199 | if (cmd_pid) |
197 | if (cmd_pid) |
200 | kill (-cmd_pid, SIGHUP); |
198 | kill (-cmd_pid, SIGHUP); |
201 | |
199 | |
202 | #ifdef UTMP_SUPPORT |
200 | delete pty; pty = 0; |
203 | privileged_utmp (RESTORE); |
|
|
204 | #endif |
|
|
205 | |
|
|
206 | pty.put (); |
|
|
207 | } |
201 | } |
208 | |
202 | |
209 | rxvt_term::~rxvt_term () |
203 | rxvt_term::~rxvt_term () |
210 | { |
204 | { |
211 | PERL_INVOKE ((this, HOOK_DESTROY, DT_END)); |
|
|
212 | |
|
|
213 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
205 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
214 | |
206 | |
215 | emergency_cleanup (); |
207 | emergency_cleanup (); |
216 | |
208 | |
217 | #if ENABLE_STYLES |
209 | #if ENABLE_STYLES |
… | |
… | |
227 | |
219 | |
228 | selection_clear (); |
220 | selection_clear (); |
229 | |
221 | |
230 | #ifdef USE_XIM |
222 | #ifdef USE_XIM |
231 | im_destroy (); |
223 | im_destroy (); |
232 | #endif |
|
|
233 | #ifdef MENUBAR |
|
|
234 | if (menubarGC) XFreeGC (disp, menubarGC); |
|
|
235 | #endif |
224 | #endif |
236 | #ifdef XTERM_SCROLLBAR |
225 | #ifdef XTERM_SCROLLBAR |
237 | if (xscrollbarGC) XFreeGC (disp, xscrollbarGC); |
226 | if (xscrollbarGC) XFreeGC (disp, xscrollbarGC); |
238 | if (ShadowGC) XFreeGC (disp, ShadowGC); |
227 | if (ShadowGC) XFreeGC (disp, ShadowGC); |
239 | #endif |
228 | #endif |
… | |
… | |
250 | if (upArrow) XFreePixmap (disp, upArrow); |
239 | if (upArrow) XFreePixmap (disp, upArrow); |
251 | if (downArrow) XFreePixmap (disp, downArrow); |
240 | if (downArrow) XFreePixmap (disp, downArrow); |
252 | if (upArrowHi) XFreePixmap (disp, upArrowHi); |
241 | if (upArrowHi) XFreePixmap (disp, upArrowHi); |
253 | if (downArrowHi) XFreePixmap (disp, downArrowHi); |
242 | if (downArrowHi) XFreePixmap (disp, downArrowHi); |
254 | #endif |
243 | #endif |
255 | #if defined(MENUBAR) || defined(RXVT_SCROLLBAR) |
244 | #ifdef RXVT_SCROLLBAR |
256 | if (topShadowGC) XFreeGC (disp, topShadowGC); |
245 | if (topShadowGC) XFreeGC (disp, topShadowGC); |
257 | if (botShadowGC) XFreeGC (disp, botShadowGC); |
246 | if (botShadowGC) XFreeGC (disp, botShadowGC); |
258 | if (scrollbarGC) XFreeGC (disp, scrollbarGC); |
247 | if (scrollbarGC) XFreeGC (disp, scrollbarGC); |
259 | #endif |
248 | #endif |
260 | if (gc) XFreeGC (disp, gc); |
249 | if (gc) XFreeGC (disp, gc); |
261 | |
250 | |
262 | #if defined(MENUBAR) && (MENUBAR_MAX > 1) |
|
|
263 | delete menuBar.drawable; |
|
|
264 | //if (menuBar.win) |
|
|
265 | // XDestroyWindow (disp, menuBar.win); |
|
|
266 | #endif |
|
|
267 | delete drawable; |
251 | delete drawable; |
268 | // destroy all windows |
252 | // destroy all windows |
269 | if (parent[0]) |
253 | if (parent[0]) |
270 | XDestroyWindow (disp, parent[0]); |
254 | XDestroyWindow (disp, parent[0]); |
271 | } |
255 | } |
272 | |
256 | |
273 | // TODO: free pixcolours, colours should become part of rxvt_display |
257 | // TODO: free pixcolours, colours should become part of rxvt_display |
274 | |
|
|
275 | delete pix_colors_focused; |
258 | delete pix_colors_focused; |
276 | #if OFF_FOCUS_FADING |
259 | #if OFF_FOCUS_FADING |
277 | delete pix_colors_unfocused; |
260 | delete pix_colors_unfocused; |
278 | #endif |
261 | #endif |
279 | |
262 | |
… | |
… | |
301 | #ifdef KEYSYM_RESOURCE |
284 | #ifdef KEYSYM_RESOURCE |
302 | delete keyboard; |
285 | delete keyboard; |
303 | #endif |
286 | #endif |
304 | } |
287 | } |
305 | |
288 | |
|
|
289 | // child has exited, usually destroys |
306 | void |
290 | void |
307 | rxvt_term::child_exit () |
291 | rxvt_term::child_cb (child_watcher &w, int status) |
308 | { |
292 | { |
|
|
293 | HOOK_INVOKE ((this, HOOK_CHILD_EXIT, DT_INT, status, DT_END)); |
|
|
294 | |
309 | cmd_pid = 0; |
295 | cmd_pid = 0; |
310 | |
296 | |
311 | if (!OPTION (Opt_hold)) |
297 | if (!OPTION (Opt_hold)) |
312 | destroy (); |
298 | destroy (); |
313 | } |
299 | } |
… | |
… | |
316 | rxvt_term::destroy () |
302 | rxvt_term::destroy () |
317 | { |
303 | { |
318 | if (destroy_ev.active) |
304 | if (destroy_ev.active) |
319 | return; |
305 | return; |
320 | |
306 | |
|
|
307 | if (HOOK_INVOKE ((this, HOOK_DESTROY, DT_END))) |
|
|
308 | return; |
|
|
309 | |
321 | #if ENABLE_OVERLAY |
310 | #if ENABLE_OVERLAY |
322 | scr_overlay_off (); |
311 | scr_overlay_off (); |
323 | #endif |
312 | #endif |
324 | |
313 | |
325 | if (display) |
314 | if (display) |
… | |
… | |
327 | #if USE_XIM |
316 | #if USE_XIM |
328 | im_ev.stop (display); |
317 | im_ev.stop (display); |
329 | #endif |
318 | #endif |
330 | #if HAVE_SCROLLBARS |
319 | #if HAVE_SCROLLBARS |
331 | scrollbar_ev.stop (display); |
320 | scrollbar_ev.stop (display); |
332 | #endif |
|
|
333 | #if MENUBAR |
|
|
334 | menubar_ev.stop (display); |
|
|
335 | #endif |
321 | #endif |
336 | #if TRANSPARENT |
322 | #if TRANSPARENT |
337 | rootwin_ev.stop (display); |
323 | rootwin_ev.stop (display); |
338 | #endif |
324 | #endif |
339 | incr_ev.stop (); |
325 | incr_ev.stop (); |
… | |
… | |
363 | } |
349 | } |
364 | |
350 | |
365 | void |
351 | void |
366 | rxvt_term::destroy_cb (time_watcher &w) |
352 | rxvt_term::destroy_cb (time_watcher &w) |
367 | { |
353 | { |
368 | SET_R (this); |
354 | make_current (); |
369 | |
355 | |
370 | delete this; |
356 | delete this; |
371 | } |
357 | } |
372 | |
358 | |
373 | /*----------------------------------------------------------------------*/ |
359 | /*----------------------------------------------------------------------*/ |
… | |
… | |
464 | /*----------------------------------------------------------------------*/ |
450 | /*----------------------------------------------------------------------*/ |
465 | bool |
451 | bool |
466 | rxvt_term::init (int argc, const char *const *argv) |
452 | rxvt_term::init (int argc, const char *const *argv) |
467 | { |
453 | { |
468 | SET_R (this); |
454 | SET_R (this); |
469 | |
|
|
470 | set_locale (""); |
455 | set_locale (""); |
|
|
456 | set_environ (envv); // few things in X do not call setlocale :( |
471 | |
457 | |
472 | if (!init_vars ()) |
458 | if (!init_vars ()) |
473 | return false; |
459 | return false; |
474 | |
460 | |
475 | init_secondary (); |
461 | init_secondary (); |
… | |
… | |
478 | |
464 | |
479 | #ifdef KEYSYM_RESOURCE |
465 | #ifdef KEYSYM_RESOURCE |
480 | keyboard->register_done (); |
466 | keyboard->register_done (); |
481 | #endif |
467 | #endif |
482 | |
468 | |
483 | #if MENUBAR_MAX |
469 | #if ENABLE_PERL |
484 | menubar_read (rs[Rs_menu]); |
470 | if (!rs[Rs_perl_ext_1]) |
|
|
471 | rs[Rs_perl_ext_1] = "default"; |
|
|
472 | |
|
|
473 | if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) |
|
|
474 | || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) |
|
|
475 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
|
|
476 | { |
|
|
477 | rxvt_perl.init (this); |
|
|
478 | HOOK_INVOKE ((this, HOOK_INIT, DT_END)); |
|
|
479 | } |
485 | #endif |
480 | #endif |
|
|
481 | |
486 | #ifdef HAVE_SCROLLBARS |
482 | #ifdef HAVE_SCROLLBARS |
487 | if (OPTION (Opt_scrollBar)) |
483 | if (OPTION (Opt_scrollBar)) |
488 | scrollBar.setIdle (); /* set existence for size calculations */ |
484 | scrollBar.setIdle (); /* set existence for size calculations */ |
489 | #endif |
485 | #endif |
490 | |
486 | |
491 | #if ENABLE_PERL |
487 | pty = rxvt_new_ptytty (); |
492 | if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) |
|
|
493 | || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) |
|
|
494 | || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) |
|
|
495 | { |
|
|
496 | rxvt_perl.init (); |
|
|
497 | PERL_INVOKE ((this, HOOK_INIT, DT_END)); |
|
|
498 | } |
|
|
499 | #endif |
|
|
500 | |
488 | |
501 | create_windows (argc, argv); |
489 | create_windows (argc, argv); |
502 | |
490 | |
503 | dDisp; |
491 | dDisp; |
504 | |
492 | |
505 | init_xlocale (); |
493 | init_xlocale (); |
506 | |
494 | |
507 | scr_reset (); /* initialize screen */ |
495 | scr_reset (); // initialize screen |
508 | |
496 | |
509 | #if 0 |
497 | #if 0 |
510 | XSynchronize (disp, True); |
498 | XSynchronize (disp, True); |
511 | #endif |
499 | #endif |
512 | |
500 | |
513 | #ifdef HAVE_SCROLLBARS |
501 | #ifdef HAVE_SCROLLBARS |
514 | if (OPTION (Opt_scrollBar)) |
502 | if (OPTION (Opt_scrollBar)) |
515 | resize_scrollbar (); /* create and map scrollbar */ |
503 | resize_scrollbar (); /* create and map scrollbar */ |
516 | #endif |
504 | #endif |
517 | #if (MENUBAR_MAX) |
|
|
518 | if (menubar_visible ()) |
|
|
519 | XMapWindow (disp, menuBar.win); |
|
|
520 | #endif |
|
|
521 | #ifdef TRANSPARENT |
505 | #ifdef TRANSPARENT |
522 | if (OPTION (Opt_transparent)) |
506 | if (OPTION (Opt_transparent)) |
523 | { |
507 | { |
524 | XSelectInput (disp, display->root, PropertyChangeMask); |
508 | XSelectInput (disp, display->root, PropertyChangeMask); |
525 | check_our_parents (); |
509 | check_our_parents (); |
526 | rootwin_ev.start (display, display->root); |
510 | rootwin_ev.start (display, display->root); |
527 | } |
511 | } |
528 | #endif |
512 | #endif |
529 | |
513 | |
|
|
514 | set_colorfgbg (); |
|
|
515 | |
|
|
516 | init_command (cmd_argv); |
|
|
517 | |
|
|
518 | free (cmd_argv); |
|
|
519 | |
|
|
520 | if (pty->pty >= 0) |
|
|
521 | pty_ev.start (pty->pty, EVENT_READ); |
|
|
522 | |
|
|
523 | check_ev.start (); |
|
|
524 | |
|
|
525 | HOOK_INVOKE ((this, HOOK_START, DT_END)); |
|
|
526 | |
530 | XMapWindow (disp, vt); |
527 | XMapWindow (disp, vt); |
531 | XMapWindow (disp, parent[0]); |
528 | XMapWindow (disp, parent[0]); |
532 | |
529 | |
533 | set_colorfgbg (); |
|
|
534 | |
|
|
535 | init_command (cmd_argv); |
|
|
536 | |
|
|
537 | free (cmd_argv); |
|
|
538 | |
|
|
539 | pty_ev.start (pty.pty, EVENT_READ); |
|
|
540 | |
|
|
541 | check_ev.start (); |
|
|
542 | |
|
|
543 | PERL_INVOKE ((this, HOOK_START, DT_END)); |
|
|
544 | |
|
|
545 | return true; |
530 | return true; |
546 | } |
531 | } |
547 | |
532 | |
548 | static struct sig_handlers |
533 | static struct sig_handlers |
549 | { |
534 | { |
550 | sig_watcher sw_chld, sw_term, sw_int; |
535 | sig_watcher sw_term, sw_int; |
551 | |
536 | |
552 | void sig_chld (sig_watcher &w) |
|
|
553 | { |
|
|
554 | // we are being called for every SIGCHLD, find the corresponding term |
|
|
555 | int pid; |
|
|
556 | |
|
|
557 | while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) |
|
|
558 | for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) |
|
|
559 | if (pid == (*t)->cmd_pid) |
|
|
560 | { |
|
|
561 | (*t)->child_exit (); |
|
|
562 | break; |
|
|
563 | } |
|
|
564 | } |
|
|
565 | |
|
|
566 | /* |
537 | /* |
567 | * Catch a fatal signal and tidy up before quitting |
538 | * Catch a fatal signal and tidy up before quitting |
568 | */ |
539 | */ |
569 | void |
540 | void |
570 | sig_term (sig_watcher &w) |
541 | sig_term (sig_watcher &w) |
… | |
… | |
576 | signal (w.signum, SIG_DFL); |
547 | signal (w.signum, SIG_DFL); |
577 | kill (getpid (), w.signum); |
548 | kill (getpid (), w.signum); |
578 | } |
549 | } |
579 | |
550 | |
580 | sig_handlers () |
551 | sig_handlers () |
581 | : sw_chld (this, &sig_handlers::sig_chld), |
|
|
582 | sw_term (this, &sig_handlers::sig_term), |
552 | : sw_term (this, &sig_handlers::sig_term), |
583 | sw_int (this, &sig_handlers::sig_term) |
553 | sw_int (this, &sig_handlers::sig_term) |
584 | { |
554 | { |
585 | } |
555 | } |
586 | } sig_handlers; |
556 | } sig_handlers; |
587 | |
557 | |
|
|
558 | char **rxvt_environ; // startup environment |
|
|
559 | |
588 | void |
560 | void |
589 | rxvt_init () |
561 | rxvt_init () |
590 | { |
562 | { |
591 | /* |
563 | uid_t uid = getuid (); |
592 | * Save and then give up any super-user privileges |
564 | gid_t gid = getgid (); |
593 | * If we need privileges in any area then we must specifically request it. |
565 | |
594 | * We should only need to be root in these cases: |
566 | // before doing anything else, check for setuid/setgid operation, |
595 | * 1. write utmp entries on some systems |
567 | // start the helper process and drop privileges |
596 | * 2. chown tty on some systems |
568 | if (uid != geteuid () |
597 | */ |
569 | || gid != getegid ()) |
598 | rxvt_privileges (SAVE); |
570 | { |
599 | rxvt_privileges (IGNORE); |
571 | #if PTYTTY_HELPER |
|
|
572 | rxvt_ptytty_server (); |
|
|
573 | #else |
|
|
574 | rxvt_warn ("running setuid/setgid without pty helper compiled in, continuing unprivileged.\n"); |
|
|
575 | #endif |
|
|
576 | |
|
|
577 | // drop privileges |
|
|
578 | #if HAVE_SETRESUID |
|
|
579 | setresgid (gid, gid, gid); |
|
|
580 | setresuid (uid, uid, uid); |
|
|
581 | #elif HAVE_SETREUID |
|
|
582 | setregid (gid, gid); |
|
|
583 | setreuid (uid, uid); |
|
|
584 | #elif HAVE_SETUID |
|
|
585 | setgid (gid); |
|
|
586 | setuid (uid); |
|
|
587 | #endif |
|
|
588 | |
|
|
589 | if (uid != geteuid () |
|
|
590 | || gid != getegid ()) |
|
|
591 | rxvt_fatal ("unable to drop privileges, aborting.\n"); |
|
|
592 | } |
|
|
593 | |
|
|
594 | rxvt_environ = environ; |
600 | |
595 | |
601 | signal (SIGHUP, SIG_IGN); |
596 | signal (SIGHUP, SIG_IGN); |
602 | signal (SIGPIPE, SIG_IGN); |
597 | signal (SIGPIPE, SIG_IGN); |
603 | |
598 | |
604 | sig_handlers.sw_chld.start (SIGCHLD); |
|
|
605 | sig_handlers.sw_term.start (SIGTERM); |
599 | sig_handlers.sw_term.start (SIGTERM); |
606 | sig_handlers.sw_int.start (SIGINT); |
600 | sig_handlers.sw_int.start (SIGINT); |
607 | |
601 | |
608 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
602 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
609 | /* signal (SIGURG, SIG_DFL); */ |
603 | /* signal (SIGURG, SIG_DFL); */ |
610 | |
604 | |
611 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
605 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
612 | // TODO: handle this with exceptions and tolerate the memory loss |
606 | // TODO: handle this with exceptions and tolerate the memory loss |
613 | XSetIOErrorHandler (rxvt_xioerror_handler); |
607 | XSetIOErrorHandler (rxvt_xioerror_handler); |
|
|
608 | |
|
|
609 | XrmInitialize (); |
614 | } |
610 | } |
615 | |
611 | |
616 | /* ------------------------------------------------------------------------- * |
612 | /* ------------------------------------------------------------------------- * |
617 | * MEMORY ALLOCATION WRAPPERS * |
613 | * MEMORY ALLOCATION WRAPPERS * |
618 | * ------------------------------------------------------------------------- */ |
614 | * ------------------------------------------------------------------------- */ |
… | |
… | |
636 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
632 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
637 | |
633 | |
638 | return p; |
634 | return p; |
639 | } |
635 | } |
640 | |
636 | |
641 | void * |
637 | void * |
642 | rxvt_realloc (void *ptr, size_t size) |
638 | rxvt_realloc (void *ptr, size_t size) |
643 | { |
639 | { |
644 | void *p = realloc (ptr, size); |
640 | void *p = realloc (ptr, size); |
645 | |
641 | |
646 | if (!p) |
642 | if (!p) |
647 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
643 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
648 | |
644 | |
649 | return p; |
645 | return p; |
650 | } |
646 | } |
651 | |
|
|
652 | /* ------------------------------------------------------------------------- * |
|
|
653 | * PRIVILEGED OPERATIONS * |
|
|
654 | * ------------------------------------------------------------------------- */ |
|
|
655 | /* take care of suid/sgid super-user (root) privileges */ |
|
|
656 | void |
|
|
657 | rxvt_privileges (rxvt_privaction action) |
|
|
658 | { |
|
|
659 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
660 | static uid_t euid; |
|
|
661 | static gid_t egid; |
|
|
662 | #endif |
|
|
663 | |
|
|
664 | #if ! defined(__CYGWIN32__) |
|
|
665 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
|
|
666 | /* setreuid () is the poor man's setuid (), seteuid () */ |
|
|
667 | # define seteuid(a) setreuid(-1, (a)) |
|
|
668 | # define setegid(a) setregid(-1, (a)) |
|
|
669 | # define HAVE_SETEUID |
|
|
670 | # endif |
|
|
671 | # ifdef HAVE_SETEUID |
|
|
672 | switch (action) |
|
|
673 | { |
|
|
674 | case IGNORE: |
|
|
675 | /* |
|
|
676 | * change effective uid/gid - not real uid/gid - so we can switch |
|
|
677 | * back to root later, as required |
|
|
678 | */ |
|
|
679 | seteuid (getuid ()); |
|
|
680 | setegid (getgid ()); |
|
|
681 | break; |
|
|
682 | case SAVE: |
|
|
683 | euid = geteuid (); |
|
|
684 | egid = getegid (); |
|
|
685 | break; |
|
|
686 | case RESTORE: |
|
|
687 | seteuid (euid); |
|
|
688 | setegid (egid); |
|
|
689 | break; |
|
|
690 | } |
|
|
691 | # else |
|
|
692 | switch (action) |
|
|
693 | { |
|
|
694 | case IGNORE: |
|
|
695 | setuid (getuid ()); |
|
|
696 | setgid (getgid ()); |
|
|
697 | /* FALLTHROUGH */ |
|
|
698 | case SAVE: |
|
|
699 | /* FALLTHROUGH */ |
|
|
700 | case RESTORE: |
|
|
701 | break; |
|
|
702 | } |
|
|
703 | # endif |
|
|
704 | #endif |
|
|
705 | } |
|
|
706 | |
|
|
707 | #ifdef UTMP_SUPPORT |
|
|
708 | void |
|
|
709 | rxvt_term::privileged_utmp (rxvt_privaction action) |
|
|
710 | { |
|
|
711 | if (OPTION (Opt_utmpInhibit) |
|
|
712 | || !pty.name || !*pty.name) |
|
|
713 | return; |
|
|
714 | |
|
|
715 | rxvt_privileges (RESTORE); |
|
|
716 | |
|
|
717 | if (action == SAVE) |
|
|
718 | makeutent (pty.name, rs[Rs_display_name]); |
|
|
719 | else |
|
|
720 | cleanutent (); |
|
|
721 | |
|
|
722 | rxvt_privileges (IGNORE); |
|
|
723 | } |
|
|
724 | #endif |
|
|
725 | |
647 | |
726 | /*----------------------------------------------------------------------*/ |
648 | /*----------------------------------------------------------------------*/ |
727 | /* |
649 | /* |
728 | * window size/position calculcations for XSizeHint and other storage. |
650 | * window size/position calculcations for XSizeHint and other storage. |
729 | * if width/height are non-zero then override calculated width/height |
651 | * if width/height are non-zero then override calculated width/height |
730 | */ |
652 | */ |
731 | void |
653 | void |
732 | rxvt_term::window_calc (unsigned int newwidth, unsigned int newheight) |
654 | rxvt_term::window_calc (unsigned int newwidth, unsigned int newheight) |
733 | { |
655 | { |
734 | short recalc_x, recalc_y; |
656 | short recalc_x, recalc_y; |
735 | int x, y, sb_w, mb_h, flags; |
657 | int x, y, sb_w, flags; |
736 | unsigned int w, h; |
658 | unsigned int w, h; |
737 | unsigned int max_width, max_height; |
659 | unsigned int max_width, max_height; |
738 | dDisp; |
660 | dDisp; |
739 | |
661 | |
740 | D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
662 | D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
… | |
… | |
801 | max_width = MAX_COLS * fwidth; |
723 | max_width = MAX_COLS * fwidth; |
802 | max_height = MAX_ROWS * fheight; |
724 | max_height = MAX_ROWS * fheight; |
803 | |
725 | |
804 | szHint.base_width = szHint.base_height = 2 * int_bwidth; |
726 | szHint.base_width = szHint.base_height = 2 * int_bwidth; |
805 | |
727 | |
806 | sb_w = mb_h = 0; |
728 | sb_w = 0; |
807 | window_vt_x = window_vt_y = int_bwidth; |
729 | window_vt_x = window_vt_y = int_bwidth; |
808 | |
730 | |
809 | if (scrollbar_visible ()) |
731 | if (scrollBar.state) |
810 | { |
732 | { |
811 | sb_w = scrollbar_TotalWidth (); |
733 | sb_w = scrollbar_TotalWidth (); |
812 | szHint.base_width += sb_w; |
734 | szHint.base_width += sb_w; |
813 | if (!OPTION (Opt_scrollBar_right)) |
735 | if (!OPTION (Opt_scrollBar_right)) |
814 | window_vt_x += sb_w; |
736 | window_vt_x += sb_w; |
815 | } |
737 | } |
816 | |
738 | |
817 | if (menubar_visible ()) |
|
|
818 | { |
|
|
819 | mb_h = menuBar_TotalHeight (); |
|
|
820 | szHint.base_height += mb_h; |
|
|
821 | window_vt_y += mb_h; |
|
|
822 | } |
|
|
823 | |
|
|
824 | szHint.width_inc = fwidth; |
739 | szHint.width_inc = fwidth; |
825 | szHint.height_inc = fheight; |
740 | szHint.height_inc = fheight; |
826 | szHint.min_width = szHint.base_width + szHint.width_inc; |
741 | szHint.min_width = szHint.base_width + szHint.width_inc; |
827 | szHint.min_height = szHint.base_height + szHint.height_inc; |
742 | szHint.min_height = szHint.base_height + szHint.height_inc; |
828 | |
743 | |
… | |
… | |
846 | { |
761 | { |
847 | min_it (height, max_height); |
762 | min_it (height, max_height); |
848 | szHint.height = szHint.base_height + height; |
763 | szHint.height = szHint.base_height + height; |
849 | } |
764 | } |
850 | |
765 | |
851 | if (scrollbar_visible () && OPTION (Opt_scrollBar_right)) |
766 | if (scrollBar.state && OPTION (Opt_scrollBar_right)) |
852 | window_sb_x = szHint.width - sb_w; |
767 | window_sb_x = szHint.width - sb_w; |
853 | |
768 | |
854 | if (recalc_x) |
769 | if (recalc_x) |
855 | szHint.x += DisplayWidth (disp, display->screen) - szHint.width - 2 * ext_bwidth; |
770 | szHint.x += DisplayWidth (disp, display->screen) - szHint.width - 2 * ext_bwidth; |
856 | if (recalc_y) |
771 | if (recalc_y) |
… | |
… | |
870 | * Called after a window size change. |
785 | * Called after a window size change. |
871 | */ |
786 | */ |
872 | void |
787 | void |
873 | rxvt_term::tt_winch () |
788 | rxvt_term::tt_winch () |
874 | { |
789 | { |
875 | if (pty.pty < 0) |
790 | if (pty->pty < 0) |
876 | return; |
791 | return; |
877 | |
792 | |
878 | struct winsize ws; |
793 | struct winsize ws; |
879 | |
794 | |
880 | ws.ws_col = ncol; |
795 | ws.ws_col = ncol; |
881 | ws.ws_row = nrow; |
796 | ws.ws_row = nrow; |
882 | ws.ws_xpixel = width; |
797 | ws.ws_xpixel = width; |
883 | ws.ws_ypixel = height; |
798 | ws.ws_ypixel = height; |
884 | (void)ioctl (pty.pty, TIOCSWINSZ, &ws); |
799 | (void)ioctl (pty->pty, TIOCSWINSZ, &ws); |
885 | |
800 | |
886 | #if 0 |
801 | #if 0 |
887 | // TIOCSWINSZ⎈ is supposed to do this automatically and correctly |
802 | // TIOCSWINSZ⎈ is supposed to do this automatically and correctly |
888 | if (cmd_pid) /* force through to the command */ |
803 | if (cmd_pid) /* force through to the command */ |
889 | kill (-cmd_pid, SIGWINCH); |
804 | kill (-cmd_pid, SIGWINCH); |
… | |
… | |
1026 | i = atoi (color); |
941 | i = atoi (color); |
1027 | |
942 | |
1028 | if (i >= 8 && i <= 15) |
943 | if (i >= 8 && i <= 15) |
1029 | { /* bright colors */ |
944 | { /* bright colors */ |
1030 | i -= 8; |
945 | i -= 8; |
1031 | # ifndef NO_BRIGHTCOLOR |
|
|
1032 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
946 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
1033 | SET_PIXCOLOR (idx); |
947 | SET_PIXCOLOR (idx); |
1034 | goto done; |
948 | goto done; |
1035 | # endif |
|
|
1036 | } |
949 | } |
1037 | |
950 | |
1038 | if (i >= 0 && i <= 7) |
951 | if (i >= 0 && i <= 7) |
1039 | { /* normal colors */ |
952 | { /* normal colors */ |
1040 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
953 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
… | |
… | |
1213 | |
1126 | |
1214 | fix_screen = ncol != prev_ncol || nrow != prev_nrow; |
1127 | fix_screen = ncol != prev_ncol || nrow != prev_nrow; |
1215 | |
1128 | |
1216 | if (fix_screen || newwidth != old_width || newheight != old_height) |
1129 | if (fix_screen || newwidth != old_width || newheight != old_height) |
1217 | { |
1130 | { |
1218 | if (scrollbar_visible ()) |
1131 | if (scrollBar.state) |
1219 | { |
1132 | { |
1220 | XMoveResizeWindow (disp, scrollBar.win, |
1133 | XMoveResizeWindow (disp, scrollBar.win, |
1221 | window_sb_x, 0, |
1134 | window_sb_x, 0, |
1222 | scrollbar_TotalWidth (), szHint.height); |
1135 | scrollbar_TotalWidth (), szHint.height); |
1223 | resize_scrollbar (); |
1136 | resize_scrollbar (); |
1224 | } |
1137 | } |
1225 | |
|
|
1226 | if (menubar_visible ()) |
|
|
1227 | XMoveResizeWindow (disp, menuBar.win, |
|
|
1228 | window_vt_x, 0, |
|
|
1229 | width, menuBar_TotalHeight ()); |
|
|
1230 | |
1138 | |
1231 | XMoveResizeWindow (disp, vt, |
1139 | XMoveResizeWindow (disp, vt, |
1232 | window_vt_x, window_vt_y, |
1140 | window_vt_x, window_vt_y, |
1233 | width, height); |
1141 | width, height); |
1234 | |
1142 | |
… | |
… | |
1418 | XRectangle rect, status_rect, needed_rect; |
1326 | XRectangle rect, status_rect, needed_rect; |
1419 | unsigned long fg, bg; |
1327 | unsigned long fg, bg; |
1420 | const char *p; |
1328 | const char *p; |
1421 | char **s; |
1329 | char **s; |
1422 | XIMStyles *xim_styles; |
1330 | XIMStyles *xim_styles; |
|
|
1331 | |
|
|
1332 | set_environ (envv); |
1423 | |
1333 | |
1424 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1334 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1425 | return false; |
1335 | return false; |
1426 | |
1336 | |
1427 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
1337 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
… | |
… | |
1593 | int i; |
1503 | int i; |
1594 | const char *p; |
1504 | const char *p; |
1595 | char **s; |
1505 | char **s; |
1596 | char buf[IMBUFSIZ]; |
1506 | char buf[IMBUFSIZ]; |
1597 | |
1507 | |
1598 | SET_R (this); |
1508 | make_current (); |
1599 | |
1509 | |
1600 | im_destroy (); |
1510 | im_destroy (); |
1601 | |
1511 | |
1602 | D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); |
1512 | D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); |
1603 | if (Input_Context) |
1513 | if (Input_Context) |
… | |
… | |
1680 | XFree (preedit_attr); |
1590 | XFree (preedit_attr); |
1681 | XFree (status_attr); |
1591 | XFree (status_attr); |
1682 | } |
1592 | } |
1683 | #endif /* USE_XIM */ |
1593 | #endif /* USE_XIM */ |
1684 | |
1594 | |
1685 | /*----------------------------------------------------------------------*/ |
|
|
1686 | rxvt_t rxvt_current_term; |
|
|
1687 | |
|
|
1688 | /*----------------------- end-of-file (C source) -----------------------*/ |
1595 | /*----------------------- end-of-file (C source) -----------------------*/ |