ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/init.C
(Generate patch)

Comparing rxvt-unicode/src/init.C (file contents):
Revision 1.110 by root, Thu Feb 17 15:07:48 2005 UTC vs.
Revision 1.155 by root, Wed Jan 25 02:53:13 2006 UTC

9 * - extensive modifications 9 * - extensive modifications
10 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> 10 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com>
11 * - extensive modifications 11 * - extensive modifications
12 * Copyright (c) 1999 D J Hawkey Jr <hawkeyd@visi.com> 12 * Copyright (c) 1999 D J Hawkey Jr <hawkeyd@visi.com>
13 * - QNX support 13 * - QNX support
14 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> 14 * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com>
15 * 15 *
16 * This program is free software; you can redistribute it and/or modify 16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by 17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or 18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version. 19 * (at your option) any later version.
34#include "../config.h" /* NECESSARY */ 34#include "../config.h" /* NECESSARY */
35#include "rxvt.h" /* NECESSARY */ 35#include "rxvt.h" /* NECESSARY */
36#include "rxvtutil.h" 36#include "rxvtutil.h"
37#include "init.h" 37#include "init.h"
38 38
39#include <limits>
40
39#include <csignal> 41#include <csignal>
40 42
41const char *const def_colorName[] = 43const char *const def_colorName[] =
42 { 44 {
43 COLOR_FOREGROUND, 45 COLOR_FOREGROUND,
44 COLOR_BACKGROUND, 46 COLOR_BACKGROUND,
45 /* low-intensity colors */ 47 /* low-intensity colors */
46 "Black", /* 0: black (#000000) */ 48 "Black", /* 0: black (#000000) */
47#ifndef NO_BRIGHTCOLOR
48 "Red3", /* 1: red (#CD0000) */ 49 "Red3", /* 1: red (#CD0000) */
49 "Green3", /* 2: green (#00CD00) */ 50 "Green3", /* 2: green (#00CD00) */
50 "Yellow3", /* 3: yellow (#CDCD00) */ 51 "Yellow3", /* 3: yellow (#CDCD00) */
51 "Blue3", /* 4: blue (#0000CD) */ 52 "Blue3", /* 4: blue (#0000CD) */
52 "Magenta3", /* 5: magenta (#CD00CD) */ 53 "Magenta3", /* 5: magenta (#CD00CD) */
60# ifdef XTERM_COLORS 61# ifdef XTERM_COLORS
61 "Grey30", /* 8: bright black (#4D4D4D) */ 62 "Grey30", /* 8: bright black (#4D4D4D) */
62# else 63# else
63 "Grey25", /* 8: bright black (#404040) */ 64 "Grey25", /* 8: bright black (#404040) */
64# endif 65# endif
65#endif /* NO_BRIGHTCOLOR */
66 "Red", /* 1/9: bright red (#FF0000) */ 66 "Red", /* 1/9: bright red (#FF0000) */
67 "Green", /* 2/10: bright green (#00FF00) */ 67 "Green", /* 2/10: bright green (#00FF00) */
68 "Yellow", /* 3/11: bright yellow (#FFFF00) */ 68 "Yellow", /* 3/11: bright yellow (#FFFF00) */
69 "Blue", /* 4/12: bright blue (#0000FF) */ 69 "Blue", /* 4/12: bright blue (#0000FF) */
70 "Magenta", /* 5/13: bright magenta (#FF00FF) */ 70 "Magenta", /* 5/13: bright magenta (#FF00FF) */
169 COLOR_SCROLLTROUGH, 169 COLOR_SCROLLTROUGH,
170#endif /* KEEP_SCROLLCOLOR */ 170#endif /* KEEP_SCROLLCOLOR */
171#if TINTING 171#if TINTING
172 NULL, 172 NULL,
173#endif 173#endif
174 }; 174#if OFF_FOCUS_FADING
175 175 "black",
176const char *const xa_names[] =
177 {
178 "TEXT",
179 "COMPOUND_TEXT",
180 "UTF8_STRING",
181 "MULTIPLE",
182 "TARGETS",
183 "TIMESTAMP",
184 "VT_SELECTION",
185 "INCR",
186 "WM_DELETE_WINDOW",
187 "CLIPBOARD",
188#if ENABLE_FRILLS
189 "_NET_WM_PID",
190 "_MOTIF_WM_HINTS",
191 "_NET_WM_NAME",
192 "_NET_WM_ICON_NAME",
193#endif
194#if USE_XIM
195 "WM_LOCALE_NAME",
196#endif
197#ifdef TRANSPARENT
198 "_XROOTPMAP_ID",
199 "ESETROOT_PMAP_ID",
200#endif
201#ifdef OFFIX_DND
202 "DndProtocol",
203 "DndSelection",
204#endif 176#endif
205 }; 177 };
206 178
207bool 179bool
208rxvt_term::init_vars () 180rxvt_term::init_vars ()
209{ 181{
210 sw_term.start (SIGTERM); 182 pix_colors = //
211 sw_int.start (SIGINT);
212
213 pix_colors_focused = new rxvt_color [TOTAL_COLORS]; 183 pix_colors_focused = new rxvt_color [TOTAL_COLORS];
214#ifdef OFF_FOCUS_FADING 184#ifdef OFF_FOCUS_FADING
215 pix_colors_unfocused = new rxvt_color [TOTAL_COLORS]; 185 pix_colors_unfocused = new rxvt_color [TOTAL_COLORS];
216#endif 186#endif
217 pix_colors = pix_colors_focused;
218
219 if (pix_colors == NULL)
220 return false;
221 187
222#if defined(XPM_BACKGROUND) || defined(TRANSPARENT) 188#if defined(XPM_BACKGROUND) || defined(TRANSPARENT)
223 TermWin.pixmap = None; 189 pixmap = None;
224#endif 190#endif
225 191
226 MEvent.time = CurrentTime; 192 MEvent.time = CurrentTime;
227 MEvent.button = AnyButton; 193 MEvent.button = AnyButton;
228 options = DEFAULT_OPTIONS; 194 options = DEFAULT_OPTIONS;
229 want_refresh = 1; 195 want_refresh = 1;
230 priv_modes = SavedModes = PrivMode_Default; 196 priv_modes = SavedModes = PrivMode_Default;
231 TermWin.focus = 0;
232 TermWin.ncol = 80; 197 ncol = 80;
233 TermWin.nrow = 24; 198 nrow = 24;
234 TermWin.int_bwidth = INTERNALBORDERWIDTH; 199 int_bwidth = INTERNALBORDERWIDTH;
235 TermWin.ext_bwidth = EXTERNALBORDERWIDTH; 200 ext_bwidth = EXTERNALBORDERWIDTH;
236 TermWin.lineSpace = LINESPACE; 201 lineSpace = LINESPACE;
237 TermWin.saveLines = SAVELINES; 202 saveLines = SAVELINES;
238 numpix_colors = TOTAL_COLORS; 203 numpix_colors = TOTAL_COLORS;
239 204
240 refresh_limit = 1; 205 refresh_limit = 1;
241 refresh_type = SLOW_REFRESH; 206 refresh_type = SLOW_REFRESH;
242 prev_nrow = prev_ncol = 0;
243 207
244 oldcursor.row = oldcursor.col = -1; 208 oldcursor.row = oldcursor.col = -1;
245#ifdef XPM_BACKGROUND 209#ifdef XPM_BACKGROUND
246 /* bgPixmap.w = bgPixmap.h = 0; */ 210 /* bgPixmap.w = bgPixmap.h = 0; */
247 bgPixmap.x = bgPixmap.y = 50; 211 bgPixmap.x = bgPixmap.y = 50;
248 bgPixmap.pixmap = None; 212 bgPixmap.pixmap = None;
249#endif 213#endif
250 214
251 last_bot = last_state = -1; 215 last_bot = last_state = -1;
252
253#ifdef MENUBAR
254 menu_readonly = 1;
255# if ! (MENUBAR_MAX > 1)
256 CurrentBar = &BarList;
257# endif /* (MENUBAR_MAX > 1) */
258#endif
259 216
260 return true; 217 return true;
261} 218}
262 219
263void 220void
331 rs[Rs_name] = rxvt_r_basename (argv[0]); 288 rs[Rs_name] = rxvt_r_basename (argv[0]);
332 289
333 /* 290 /*
334 * Open display, get options/resources and create the window 291 * Open display, get options/resources and create the window
335 */ 292 */
293
336 if ((rs[Rs_display_name] = getenv ("DISPLAY")) == NULL) 294 if ((rs[Rs_display_name] = getenv ("DISPLAY")) == NULL)
337 rs[Rs_display_name] = ":0"; 295 rs[Rs_display_name] = ":0";
338 296
339 get_options (r_argc, r_argv); 297 get_options (r_argc, r_argv);
340 298
341#ifdef LOCAL_X_IS_UNIX
342 if (rs[Rs_display_name][0] == ':')
343 {
344 val = rxvt_malloc (5 + strlen (rs[Rs_display_name]));
345 strcpy (val, "unix");
346 strcat (val, rs[Rs_display_name]);
347 display = displays.get (val);
348 free (val);
349 }
350#endif
351
352 if (!display
353 && ! (display = displays.get (rs[Rs_display_name]))) 299 if (!(display = displays.get (rs[Rs_display_name])))
354 rxvt_fatal ("can't open display %s, aborting.\n", rs[Rs_display_name]); 300 rxvt_fatal ("can't open display %s, aborting.\n", rs[Rs_display_name]);
355 301
356 extract_resources (); 302 extract_resources ();
303
357 free (r_argv); 304 free (r_argv);
305
306#if ENABLE_PERL
307 if (!rs[Rs_perl_ext_1])
308 rs[Rs_perl_ext_1] = "default";
309
310 if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1])
311 || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2])
312 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval]))
313 {
314 rxvt_perl.init (this);
315 HOOK_INVOKE ((this, HOOK_INIT, DT_END));
316 }
317#endif
358 318
359 /* 319 /*
360 * set any defaults not already set 320 * set any defaults not already set
361 */ 321 */
362 if (cmd_argv && cmd_argv[0]) 322 if (cmd_argv && cmd_argv[0])
373 if (!rs[Rs_iconName]) 333 if (!rs[Rs_iconName])
374 rs[Rs_iconName] = rs[Rs_name]; 334 rs[Rs_iconName] = rs[Rs_name];
375 } 335 }
376 336
377 if (rs[Rs_saveLines] && (i = atoi (rs[Rs_saveLines])) >= 0) 337 if (rs[Rs_saveLines] && (i = atoi (rs[Rs_saveLines])) >= 0)
378 TermWin.saveLines = BOUND_POSITIVE_INT16 (i); 338 saveLines = min (i, MAX_SAVELINES);
379 339
380#if ENABLE_FRILLS 340#if ENABLE_FRILLS
381 if (rs[Rs_int_bwidth] && (i = atoi (rs[Rs_int_bwidth])) >= 0) 341 if (rs[Rs_int_bwidth] && (i = atoi (rs[Rs_int_bwidth])) >= 0)
382 TermWin.int_bwidth = min (i, 100); /* arbitrary limit */ 342 int_bwidth = min (i, std::numeric_limits<int16_t>::max ());
343
383 if (rs[Rs_ext_bwidth] && (i = atoi (rs[Rs_ext_bwidth])) >= 0) 344 if (rs[Rs_ext_bwidth] && (i = atoi (rs[Rs_ext_bwidth])) >= 0)
384 TermWin.ext_bwidth = min (i, 100); /* arbitrary limit */ 345 ext_bwidth = min (i, std::numeric_limits<int16_t>::max ());
346
385 if (rs[Rs_lineSpace] && (i = atoi (rs[Rs_lineSpace])) >= 0) 347 if (rs[Rs_lineSpace] && (i = atoi (rs[Rs_lineSpace])) >= 0)
386 TermWin.lineSpace = min (i, 100); /* arbitrary limit */ 348 lineSpace = min (i, std::numeric_limits<int16_t>::max ());
387#endif 349#endif
388 350
389#ifdef POINTER_BLANK 351#ifdef POINTER_BLANK
390 if (rs[Rs_pointerBlankDelay] && (i = atoi (rs[Rs_pointerBlankDelay])) >= 0) 352 if (rs[Rs_pointerBlankDelay] && (i = atoi (rs[Rs_pointerBlankDelay])) >= 0)
391 pointerBlankDelay = i; 353 pointerBlankDelay = i;
392 else 354 else
393 pointerBlankDelay = 2; 355 pointerBlankDelay = 2;
394#endif 356#endif
395 357
396 /* no point having a scrollbar without having any scrollback! */ 358 /* no point having a scrollbar without having any scrollback! */
397 if (!TermWin.saveLines) 359 if (!saveLines)
398 options &= ~Opt_scrollBar; 360 set_option (Opt_scrollBar, 0);
399 361
400#ifdef PRINTPIPE 362#ifdef PRINTPIPE
401 if (!rs[Rs_print_pipe]) 363 if (!rs[Rs_print_pipe])
402 rs[Rs_print_pipe] = PRINTPIPE; 364 rs[Rs_print_pipe] = PRINTPIPE;
403#endif 365#endif
446 setup_scrollbar (rs[Rs_scrollBar_align], rs[Rs_scrollstyle], rs[Rs_scrollBar_thickness]); 408 setup_scrollbar (rs[Rs_scrollBar_align], rs[Rs_scrollstyle], rs[Rs_scrollBar_thickness]);
447#endif 409#endif
448 410
449#ifdef XTERM_REVERSE_VIDEO 411#ifdef XTERM_REVERSE_VIDEO
450 /* this is how xterm implements reverseVideo */ 412 /* this is how xterm implements reverseVideo */
451 if (options & Opt_reverseVideo) 413 if (OPTION (Opt_reverseVideo))
452 { 414 {
453 if (!rs[Rs_color + Color_fg]) 415 if (!rs[Rs_color + Color_fg])
454 rs[Rs_color + Color_fg] = def_colorName[Color_bg]; 416 rs[Rs_color + Color_fg] = def_colorName[Color_bg];
455 if (!rs[Rs_color + Color_bg]) 417 if (!rs[Rs_color + Color_bg])
456 rs[Rs_color + Color_bg] = def_colorName[Color_fg]; 418 rs[Rs_color + Color_bg] = def_colorName[Color_fg];
461 if (!rs[Rs_color + i]) 423 if (!rs[Rs_color + i])
462 rs[Rs_color + i] = def_colorName[i]; 424 rs[Rs_color + i] = def_colorName[i];
463 425
464#ifndef XTERM_REVERSE_VIDEO 426#ifndef XTERM_REVERSE_VIDEO
465 /* this is how we implement reverseVideo */ 427 /* this is how we implement reverseVideo */
466 if (options & Opt_reverseVideo) 428 if (OPTION (Opt_reverseVideo))
467 SWAP_IT (rs[Rs_color + Color_fg], rs[Rs_color + Color_bg], const char *); 429 ::swap (rs[Rs_color + Color_fg], rs[Rs_color + Color_bg]);
468#endif 430#endif
469 431
470 /* convenient aliases for setting fg/bg to colors */ 432 /* convenient aliases for setting fg/bg to colors */
471 color_aliases (Color_fg); 433 color_aliases (Color_fg);
472 color_aliases (Color_bg); 434 color_aliases (Color_bg);
521 i = strlen (val); 483 i = strlen (val);
522 env_display = (char *)rxvt_malloc ((i + 9) * sizeof (char)); 484 env_display = (char *)rxvt_malloc ((i + 9) * sizeof (char));
523 485
524 sprintf (env_display, "DISPLAY=%s", val); 486 sprintf (env_display, "DISPLAY=%s", val);
525 487
526 /* avoiding the math library: 488 sprintf (env_windowid, "WINDOWID=%lu", (unsigned long)parent[0]);
527 * i = (int) (ceil (log10 ((unsigned int)TermWin.parent[0]))) */
528 for (i = 0, u = (unsigned int)TermWin.parent[0]; u; u /= 10, i++)
529 ;
530 MAX_IT (i, 1);
531 env_windowid = (char *)rxvt_malloc ((i + 10) * sizeof (char));
532
533 sprintf (env_windowid, "WINDOWID=%u",
534 (unsigned int)TermWin.parent[0]);
535 489
536 /* add entries to the environment: 490 /* add entries to the environment:
537 * @ DISPLAY: in case we started with -display 491 * @ DISPLAY: in case we started with -display
538 * @ WINDOWID: X window id number of the window 492 * @ WINDOWID: X window id number of the window
539 * @ COLORTERM: terminal sub-name and also indicates its color 493 * @ COLORTERM: terminal sub-name and also indicates its color
541 * @ TERMINFO: path to terminfo directory 495 * @ TERMINFO: path to terminfo directory
542 * @ COLORFGBG: fg;bg color codes 496 * @ COLORFGBG: fg;bg color codes
543 */ 497 */
544 putenv (env_display); 498 putenv (env_display);
545 putenv (env_windowid); 499 putenv (env_windowid);
500
546 if (env_colorfgbg) 501 if (env_colorfgbg)
547 putenv (env_colorfgbg); 502 putenv (env_colorfgbg);
548 503
549#ifdef RXVT_TERMINFO 504#ifdef RXVT_TERMINFO
550 putenv ("TERMINFO=" RXVT_TERMINFO); 505 putenv ("TERMINFO=" RXVT_TERMINFO);
578 * This should support all European type languages. 533 * This should support all European type languages.
579 */ 534 */
580void 535void
581rxvt_term::set_locale (const char *locale) 536rxvt_term::set_locale (const char *locale)
582{ 537{
538 set_environ (envv);
539
583#if HAVE_XSETLOCALE || HAVE_SETLOCALE 540#if HAVE_XSETLOCALE || HAVE_SETLOCALE
584 free (this->locale); 541 free (this->locale);
585 this->locale = setlocale (LC_CTYPE, locale); 542 this->locale = setlocale (LC_CTYPE, locale);
586 543
587 if (!this->locale) 544 if (!this->locale)
588 { 545 {
589 if (*locale) 546 if (*locale)
590 { 547 {
591 rxvt_warn ("unable to set locale \"%s\", using default locale instead.\n", locale); 548 rxvt_warn ("unable to set locale \"%s\", using C locale instead.\n", locale);
592 setlocale (LC_CTYPE, ""); 549 setlocale (LC_CTYPE, "C");
593 } 550 }
594 else 551 else
595 rxvt_warn ("default locale unavailable, check LC_* and LANG variables. Continuing.\n"); 552 rxvt_warn ("default locale unavailable, check LC_* and LANG variables. Continuing.\n");
596 553
597 this->locale = ""; 554 this->locale = "C";
598 } 555 }
599 556
600 557
601 this->locale = rxvt_strdup (this->locale); 558 this->locale = rxvt_strdup (this->locale);
602 SET_LOCALE (this->locale); 559 SET_LOCALE (this->locale);
617} 574}
618 575
619void 576void
620rxvt_term::init_xlocale () 577rxvt_term::init_xlocale ()
621{ 578{
579 set_environ (envv);
580
622#ifdef USE_XIM 581#ifdef USE_XIM
623 if (!locale) 582 if (!locale)
624 rxvt_warn ("setting locale failed, working without locale support.\n"); 583 rxvt_warn ("setting locale failed, working without locale support.\n");
625 else 584 else
626 { 585 {
648 * Initialize the command connection. 607 * Initialize the command connection.
649 * This should be called after the X server connection is established. 608 * This should be called after the X server connection is established.
650 */ 609 */
651 610
652#ifdef META8_OPTION 611#ifdef META8_OPTION
653 meta_char = (options & Opt_meta8 ? 0x80 : C0_ESC); 612 meta_char = OPTION (Opt_meta8) ? 0x80 : C0_ESC;
654#endif 613#endif
655 614
656 get_ourmods (); 615 get_ourmods ();
657 616
658 if (!(options & Opt_scrollTtyOutput)) 617 if (!OPTION (Opt_scrollTtyOutput))
659 priv_modes |= PrivMode_TtyOutputInh; 618 priv_modes |= PrivMode_TtyOutputInh;
660 if (options & Opt_scrollTtyKeypress) 619 if (OPTION (Opt_scrollTtyKeypress))
661 priv_modes |= PrivMode_Keypress; 620 priv_modes |= PrivMode_Keypress;
662 if (!(options & Opt_jumpScroll)) 621 if (!OPTION (Opt_jumpScroll))
663 priv_modes |= PrivMode_smoothScroll; 622 priv_modes |= PrivMode_smoothScroll;
664 623
665#ifndef NO_BACKSPACE_KEY 624#ifndef NO_BACKSPACE_KEY
666 if (strcmp (key_backspace, "DEC") == 0) 625 if (strcmp (key_backspace, "DEC") == 0)
667 priv_modes |= PrivMode_HaveBackSpace; 626 priv_modes |= PrivMode_HaveBackSpace;
668#endif 627#endif
669 628
670 /* add value for scrollBar */ 629 /* add value for scrollBar */
671 if (scrollbar_visible ()) 630 if (scrollBar.state)
672 { 631 {
673 priv_modes |= PrivMode_scrollBar; 632 priv_modes |= PrivMode_scrollBar;
674 SavedModes |= PrivMode_scrollBar; 633 SavedModes |= PrivMode_scrollBar;
675 } 634 }
676
677 if (menubar_visible ())
678 {
679 priv_modes |= PrivMode_menuBar;
680 SavedModes |= PrivMode_menuBar;
681 }
682
683#ifdef CURSOR_BLINK
684 if (options & Opt_cursorBlink)
685 (void)gettimeofday (&lastcursorchange, NULL);
686#endif
687 635
688 run_command (argv); 636 run_command (argv);
689} 637}
690 638
691/*----------------------------------------------------------------------*/ 639/*----------------------------------------------------------------------*/
706 continue; 654 continue;
707 655
708 if (!rXParseAllocColor (&xcol, rs[Rs_color + i])) 656 if (!rXParseAllocColor (&xcol, rs[Rs_color + i]))
709 { 657 {
710#ifndef XTERM_REVERSE_VIDEO 658#ifndef XTERM_REVERSE_VIDEO
711 if (i < 2 && (options & Opt_reverseVideo)) 659 if (i < 2 && OPTION (Opt_reverseVideo))
712 rs[Rs_color + i] = def_colorName[!i]; 660 rs[Rs_color + i] = def_colorName[!i];
713 else 661 else
714#endif 662#endif
715 rs[Rs_color + i] = def_colorName[i]; 663 rs[Rs_color + i] = def_colorName[i];
716 664
741 } 689 }
742 } 690 }
743 } 691 }
744 692
745 pix_colors[i] = xcol; 693 pix_colors[i] = xcol;
694 SET_PIXCOLOR (i);
695 }
696
746#ifdef OFF_FOCUS_FADING 697#ifdef OFF_FOCUS_FADING
747 if (rs[Rs_fade]) 698 if (rs[Rs_fade])
699 for (i = 0; i < (display->depth <= 2 ? 2 : NRS_COLORS); i++)
748 pix_colors_unfocused[i] = xcol.fade (display, atoi (rs[Rs_fade])); 700 pix_colors_unfocused[i] = pix_colors_focused[i].fade (display, atoi (rs[Rs_fade]), pix_colors[Color_fade]);
749#endif 701#endif
750 SET_PIXCOLOR (i);
751 }
752 702
753 if (display->depth <= 2) 703 if (display->depth <= 2)
754 { 704 {
755 if (!rs[Rs_color + Color_pointer_fg]) pix_colors[Color_pointer_fg] = pix_colors[Color_fg]; 705 if (!rs[Rs_color + Color_pointer_fg]) pix_colors[Color_pointer_fg] = pix_colors[Color_fg];
756 if (!rs[Rs_color + Color_pointer_bg]) pix_colors[Color_pointer_bg] = pix_colors[Color_bg]; 706 if (!rs[Rs_color + Color_pointer_bg]) pix_colors[Color_pointer_bg] = pix_colors[Color_bg];
757 if (!rs[Rs_color + Color_border] ) pix_colors[Color_border] = pix_colors[Color_fg]; 707 if (!rs[Rs_color + Color_border] ) pix_colors[Color_border] = pix_colors[Color_fg];
758 } 708 }
759 709
760 /* 710 /*
761 * get scrollBar/menuBar shadow colors 711 * get scrollBar shadow colors
762 * 712 *
763 * The calculations of topShadow/bottomShadow values are adapted 713 * The calculations of topShadow/bottomShadow values are adapted
764 * from the fvwm window manager. 714 * from the fvwm window manager.
765 */ 715 */
766#ifdef KEEP_SCROLLCOLOR 716#ifdef KEEP_SCROLLCOLOR
767 717
768 if (display->depth <= 2) 718 if (display->depth <= 2)
719 {
769 { /* Monochrome */ 720 /* Monochrome */
770 pix_colors[Color_scroll] = pix_colors[Color_fg]; 721 pix_colors[Color_scroll] = pix_colors[Color_fg];
771 pix_colors[Color_topShadow] = pix_colors[Color_bg]; 722 pix_colors[Color_topShadow] = pix_colors[Color_bg];
772 pix_colors[Color_bottomShadow] = pix_colors[Color_bg]; 723 pix_colors[Color_bottomShadow] = pix_colors[Color_bg];
773 } 724 }
774 else 725 else
810 int i = atoi (rs[Rs_color + idx]); 761 int i = atoi (rs[Rs_color + idx]);
811 762
812 if (i >= 8 && i <= 15) 763 if (i >= 8 && i <= 15)
813 { /* bright colors */ 764 { /* bright colors */
814 i -= 8; 765 i -= 8;
815#ifndef NO_BRIGHTCOLOR
816 rs[Rs_color + idx] = rs[Rs_color + minBrightCOLOR + i]; 766 rs[Rs_color + idx] = rs[Rs_color + minBrightCOLOR + i];
817 return; 767 return;
818#endif
819 } 768 }
820 769
821 if (i >= 0 && i <= 7) /* normal colors */ 770 if (i >= 0 && i <= 7) /* normal colors */
822 rs[Rs_color + idx] = rs[Rs_color + minCOLOR + i]; 771 rs[Rs_color + idx] = rs[Rs_color + minCOLOR + i];
823 } 772 }
918rxvt_term::create_windows (int argc, const char *const *argv) 867rxvt_term::create_windows (int argc, const char *const *argv)
919{ 868{
920 XClassHint classHint; 869 XClassHint classHint;
921 XWMHints wmHint; 870 XWMHints wmHint;
922#if ENABLE_FRILLS 871#if ENABLE_FRILLS
923 Atom prop = None;
924 MWMHints mwmhints; 872 MWMHints mwmhints;
925#endif 873#endif
926 XGCValues gcvalue; 874 XGCValues gcvalue;
927 long vt_emask;
928 XSetWindowAttributes attributes; 875 XSetWindowAttributes attributes;
929 XWindowAttributes gattr;
930 Window top; 876 Window top, parent;
931 dDisp; 877 dDisp;
932 878
933#ifdef USING_W11LIB 879 xa = display->xa;
934 /* enable W11 callbacks */
935 W11AddEventHandler (disp, rxvt_W11_process_x_event);
936#endif
937 880
938 assert (sizeof (xa_names) / sizeof (char *) == NUM_XA); 881 /* grab colors before netscape does */
939 XInternAtoms (disp, (char **)xa_names, NUM_XA, False, xa); 882 Get_Colours ();
940 883
941 if (options & Opt_transparent) 884 if (!set_fonts ())
942 { 885 rxvt_fatal ("unable to load base fontset, please specify a valid one using -fn, aborting.\n");
943 XGetWindowAttributes (disp, RootWindow (disp, display->screen), &gattr); 886
944 display->depth = gattr.depth; // doh //TODO, per-term not per-display? 887 parent = display->root;
945 } 888
889 attributes.override_redirect = !!OPTION (Opt_override_redirect);
946 890
947#if ENABLE_FRILLS 891#if ENABLE_FRILLS
948 if (options & Opt_borderLess) 892 if (OPTION (Opt_borderLess))
949 { 893 {
950 prop = XInternAtom(disp, "_MOTIF_WM_INFO", True); 894 if (XInternAtom (disp, "_MOTIF_WM_INFO", True) == None)
951
952 if (prop == None)
953 { 895 {
954 /* print_warning("Window Manager does not support MWM hints. Bypassing window manager control for borderless window.\n");*/ 896 /* print_warning("Window Manager does not support MWM hints. Bypassing window manager control for borderless window.\n");*/
955#ifdef PREFER_24BIT
956 attributes.override_redirect = TRUE; 897 attributes.override_redirect = TRUE;
957#endif
958 mwmhints.flags = 0; 898 mwmhints.flags = 0;
959 } 899 }
960 else 900 else
961 { 901 {
962 mwmhints.flags = MWM_HINTS_DECORATIONS; 902 mwmhints.flags = MWM_HINTS_DECORATIONS;
963 mwmhints.decorations = 0; 903 mwmhints.decorations = 0;
964 } 904 }
965 } 905 }
966 else 906 else
967 {
968 mwmhints.flags = 0; 907 mwmhints.flags = 0;
969 }
970#endif 908#endif
971 909
972 /* grab colors before netscape does */ 910#if ENABLE_XEMBED
973 Get_Colours ();
974
975 if (!set_fonts ())
976 rxvt_fatal ("unable to load base fontset, please specify a valid one using -fn, aborting.\n");
977
978#if ENABLE_FRILLS
979 if (rs[Rs_embed]) 911 if (rs[Rs_embed])
980 { 912 {
981 top = strtol (rs[Rs_embed], 0, 0);
982
983 XWindowAttributes wattr; 913 XWindowAttributes wattr;
914
915 parent = strtol (rs[Rs_embed], 0, 0);
916
984 XGetWindowAttributes (disp, top, &wattr); 917 if (!XGetWindowAttributes (disp, parent, &wattr))
918 rxvt_fatal ("invalid window-id specified with -embed, aborting.\n");
985 919
986 window_calc (wattr.width, wattr.height); 920 window_calc (wattr.width, wattr.height);
987
988#if 0
989 if (wattr.map_state == IsViewable)
990 {
991 TermWin.mapped = 1;
992 refresh_type = FAST_REFRESH;
993 XClearWindow (disp, top);
994 // TODO: make XMapNotify-event-code a function and call it
995 // TODO: how can I detetc visibility without unmpa/map?
996 // TODO: focusin etc.
997 }
998#else
999 // it'S easiets just to unmap/map to get all state correctly set-up
1000 XUnmapWindow (disp, top);
1001#endif
1002 }
1003 else
1004#endif
1005 { 921 }
922#endif
923
1006 window_calc (0, 0); 924 window_calc (0, 0);
1007 925
1008 /* sub-window placement & size in rxvt_resize_subwindows () */ 926 /* sub-window placement & size in rxvt_resize_subwindows () */
1009#ifdef PREFER_24BIT
1010 attributes.background_pixel = pix_colors_focused[Color_border]; 927 attributes.background_pixel = pix_colors_focused[Color_border];
1011 attributes.border_pixel = pix_colors_focused[Color_border]; 928 attributes.border_pixel = pix_colors_focused[Color_border];
1012 attributes.colormap = display->cmap; 929 attributes.colormap = display->cmap;
1013 top = XCreateWindow (disp, DefaultRootWindow (disp), 930
931 top = XCreateWindow (disp, parent,
1014 szHint.x, szHint.y, 932 szHint.x, szHint.y,
1015 szHint.width, szHint.height, 933 szHint.width, szHint.height,
1016 TermWin.ext_bwidth, 934 ext_bwidth,
1017 display->depth, InputOutput, 935 display->depth, InputOutput,
1018 display->visual, 936 display->visual,
1019 CWColormap | CWBackPixel | CWBorderPixel, &attributes); 937 CWColormap | CWBackPixel | CWBorderPixel | CWOverrideRedirect,
1020#else 938 &attributes);
1021 top = XCreateSimpleWindow (disp, DefaultRootWindow (disp),
1022 szHint.x, szHint.y,
1023 szHint.width, szHint.height,
1024 TermWin.ext_bwidth,
1025 pix_colors_focused[Color_border],
1026 pix_colors_focused[Color_border]);
1027#endif
1028 }
1029 939
1030 TermWin.parent[0] = top; 940 this->parent[0] = top;
1031 941
1032 old_width = szHint.width; 942 old_width = szHint.width;
1033 old_height = szHint.height; 943 old_height = szHint.height;
1034 944
1035 process_xterm_seq (XTerm_title, rs[Rs_title], CHAR_ST); 945 process_xterm_seq (XTerm_title, rs[Rs_title], CHAR_ST);
1036 process_xterm_seq (XTerm_iconName, rs[Rs_iconName], CHAR_ST); 946 process_xterm_seq (XTerm_iconName, rs[Rs_iconName], CHAR_ST);
1037 947
1038 classHint.res_name = (char *)rs[Rs_name]; 948 classHint.res_name = (char *)rs[Rs_name];
1039 classHint.res_class = (char *)RESCLASS; 949 classHint.res_class = (char *)RESCLASS;
1040 950
1041 wmHint.flags = InputHint | StateHint | WindowGroupHint; 951 wmHint.flags = InputHint | StateHint | WindowGroupHint;
1042 wmHint.input = True; 952 wmHint.input = True;
1043 wmHint.initial_state = options & Opt_iconic ? IconicState : NormalState; 953 wmHint.initial_state = OPTION (Opt_iconic) ? IconicState : NormalState;
1044 wmHint.window_group = top; 954 wmHint.window_group = top;
1045 955
1046 XSetWMProperties (disp, top, NULL, NULL, 956 XmbSetWMProperties (disp, top, NULL, NULL, (char **)argv, argc,
1047 (char **)argv, argc, &szHint, &wmHint, &classHint); 957 &szHint, &wmHint, &classHint);
1048
1049 /* Enable delete window protocol */
1050 XSetWMProtocols (disp, top, &xa[XA_WMDELETEWINDOW], 1);
1051 958
1052#if ENABLE_FRILLS 959#if ENABLE_FRILLS
960 if (mwmhints.flags)
961 XChangeProperty (disp, top, xa[XA_MOTIF_WM_HINTS], xa[XA_MOTIF_WM_HINTS], 32,
962 PropModeReplace, (unsigned char *)&mwmhints, PROP_MWM_HINTS_ELEMENTS);
963#endif
964
965 Atom protocols[] = {
966 xa[XA_WM_DELETE_WINDOW],
967#if ENABLE_EWMH
968 xa[XA_NET_WM_PING],
969#endif
970 };
971
972 XSetWMProtocols (disp, top, protocols, sizeof (protocols) / sizeof (protocols[0]));
973
974#if ENABLE_FRILLS
975 if (rs[Rs_transient_for])
976 XSetTransientForHint (disp, top, (Window)strtol (rs[Rs_transient_for], 0, 0));
977#endif
978
979#if ENABLE_EWMH
1053 long pid = getpid (); 980 long pid = getpid ();
1054 981
1055 XChangeProperty (disp, top, 982 XChangeProperty (disp, top,
1056 xa[XA_NET_WM_PID], XA_CARDINAL, 32, 983 xa[XA_NET_WM_PID], XA_CARDINAL, 32,
1057 PropModeReplace, (unsigned char *)&pid, 1); 984 PropModeReplace, (unsigned char *)&pid, 1);
985
986 // _NET_WM_WINDOW_TYPE is NORMAL, which is the default
1058#endif 987#endif
1059 988
1060 XSelectInput (disp, top, 989 XSelectInput (disp, top,
1061 KeyPressMask 990 KeyPressMask
1062#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ENABLE_FRILLS || ISO_14755 991#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ENABLE_FRILLS || ISO_14755
1063 | KeyReleaseMask 992 | KeyReleaseMask
1064#endif 993#endif
1065 | FocusChangeMask | VisibilityChangeMask 994 | FocusChangeMask | VisibilityChangeMask
1066 | ExposureMask
1067 | StructureNotifyMask); 995 | ExposureMask | StructureNotifyMask);
996
1068 termwin_ev.start (display, top); 997 termwin_ev.start (display, top);
1069
1070#if ENABLE_FRILLS
1071 if (mwmhints.flags)
1072 XChangeProperty (disp, top, xa[XA_MOTIF_WM_HINTS], xa[XA_MOTIF_WM_HINTS], 32,
1073 PropModeReplace, (unsigned char *)&mwmhints, PROP_MWM_HINTS_ELEMENTS);
1074#endif
1075 998
1076 /* vt cursor: Black-on-White is standard, but this is more popular */ 999 /* vt cursor: Black-on-White is standard, but this is more popular */
1077 TermWin_cursor = XCreateFontCursor (disp, XC_xterm); 1000 TermWin_cursor = XCreateFontCursor (disp, XC_xterm);
1078 1001
1079#if defined(HAVE_SCROLLBARS) || defined(MENUBAR) 1002#ifdef HAVE_SCROLLBARS
1080 /* cursor (menuBar/scrollBar): Black-on-White */ 1003 /* cursor scrollBar: Black-on-White */
1081 leftptr_cursor = XCreateFontCursor (disp, XC_left_ptr); 1004 leftptr_cursor = XCreateFontCursor (disp, XC_left_ptr);
1082#endif 1005#endif
1083 1006
1084 /* the vt window */ 1007 /* the vt window */
1085 TermWin.vt = XCreateSimpleWindow (disp, top, 1008 vt = XCreateSimpleWindow (disp, top,
1086 window_vt_x,
1087 window_vt_y, 1009 window_vt_x, window_vt_y,
1088 TermWin_TotalWidth (), 1010 width, height,
1089 TermWin_TotalHeight (),
1090 0, 1011 0,
1091 pix_colors_focused[Color_fg], 1012 pix_colors_focused[Color_fg],
1092 pix_colors_focused[Color_bg]); 1013 pix_colors_focused[Color_bg]);
1093#ifdef DEBUG_X
1094 XStoreName (disp, TermWin.vt, "vt window");
1095#endif
1096 1014
1097 attributes.bit_gravity = NorthWestGravity; 1015 attributes.bit_gravity = NorthWestGravity;
1098 XChangeWindowAttributes (disp, TermWin.vt, CWBitGravity, &attributes); 1016 XChangeWindowAttributes (disp, vt, CWBitGravity, &attributes);
1099 1017
1100 vt_emask = ExposureMask | ButtonPressMask | ButtonReleaseMask | PropertyChangeMask; 1018 vt_emask = ExposureMask | ButtonPressMask | ButtonReleaseMask | PropertyChangeMask;
1101 1019
1102 pointer_unblank (); 1020 if (OPTION (Opt_pointerBlank))
1103
1104#ifdef POINTER_BLANK
1105 if (options & Opt_pointerBlank)
1106 vt_emask |= PointerMotionMask; 1021 vt_emask |= PointerMotionMask;
1107 else 1022 else
1108#endif
1109 vt_emask |= Button1MotionMask | Button3MotionMask; 1023 vt_emask |= Button1MotionMask | Button3MotionMask;
1110 1024
1111 XSelectInput (disp, TermWin.vt, vt_emask); 1025 vt_select_input ();
1026
1112 vt_ev.start (display, TermWin.vt); 1027 vt_ev.start (display, vt);
1113
1114#if defined(MENUBAR) && (MENUBAR_MAX > 1)
1115 if (menuBar_height ())
1116 {
1117 menuBar.win = XCreateSimpleWindow (disp, top,
1118 window_vt_x, 0,
1119 TermWin_TotalWidth (),
1120 menuBar_TotalHeight (),
1121 0,
1122 pix_colors_focused[Color_fg],
1123 pix_colors_focused[Color_scroll]);
1124
1125#ifdef DEBUG_X
1126 XStoreName (disp, menuBar.win, "menubar");
1127#endif
1128
1129 menuBar.drawable = new rxvt_drawable (display, menuBar.win);
1130
1131 XDefineCursor (disp, menuBar.win,
1132 XCreateFontCursor (disp, XC_left_ptr));
1133
1134 XSelectInput (disp, menuBar.win,
1135 (ExposureMask | ButtonPressMask | ButtonReleaseMask | Button1MotionMask));
1136 menubar_ev.start (display, menuBar.win);
1137 }
1138#endif
1139 1028
1140#ifdef XPM_BACKGROUND 1029#ifdef XPM_BACKGROUND
1141 if (rs[Rs_backgroundPixmap] != NULL 1030 if (rs[Rs_backgroundPixmap] != NULL
1142 && ! (options & Opt_transparent)) 1031 && !OPTION (Opt_transparent))
1143 { 1032 {
1144 const char *p = rs[Rs_backgroundPixmap]; 1033 const char *p = rs[Rs_backgroundPixmap];
1145 1034
1146 if ((p = strchr (p, ';')) != NULL) 1035 if ((p = strchr (p, ';')) != NULL)
1147 { 1036 {
1153 scr_touch (true); 1042 scr_touch (true);
1154 } 1043 }
1155#endif 1044#endif
1156 1045
1157 /* graphics context for the vt window */ 1046 /* graphics context for the vt window */
1158 gcvalue.foreground = pix_colors[Color_fg]; 1047 gcvalue.foreground = pix_colors[Color_fg];
1159 gcvalue.background = pix_colors[Color_bg]; 1048 gcvalue.background = pix_colors[Color_bg];
1160 gcvalue.graphics_exposures = 1; 1049 gcvalue.graphics_exposures = 1;
1050
1161 TermWin.gc = XCreateGC (disp, TermWin.vt, 1051 gc = XCreateGC (disp, vt,
1162 GCForeground | GCBackground | GCGraphicsExposures, 1052 GCForeground | GCBackground | GCGraphicsExposures,
1163 &gcvalue); 1053 &gcvalue);
1164 1054
1165 TermWin.drawable = new rxvt_drawable (display, TermWin.vt); 1055 drawable = new rxvt_drawable (display, vt);
1166 1056
1167#if defined(MENUBAR) || defined(RXVT_SCROLLBAR) 1057#ifdef RXVT_SCROLLBAR
1168 gcvalue.foreground = pix_colors[Color_topShadow]; 1058 gcvalue.foreground = pix_colors[Color_topShadow];
1169 topShadowGC = XCreateGC (disp, TermWin.vt, GCForeground, &gcvalue); 1059 topShadowGC = XCreateGC (disp, vt, GCForeground, &gcvalue);
1170 gcvalue.foreground = pix_colors[Color_bottomShadow]; 1060 gcvalue.foreground = pix_colors[Color_bottomShadow];
1171 botShadowGC = XCreateGC (disp, TermWin.vt, GCForeground, &gcvalue); 1061 botShadowGC = XCreateGC (disp, vt, GCForeground, &gcvalue);
1172 gcvalue.foreground = pix_colors[ (display->depth <= 2 ? Color_fg : Color_scroll)]; 1062 gcvalue.foreground = pix_colors[ (display->depth <= 2 ? Color_fg : Color_scroll)];
1173 scrollbarGC = XCreateGC (disp, TermWin.vt, GCForeground, &gcvalue); 1063 scrollbarGC = XCreateGC (disp, vt, GCForeground, &gcvalue);
1174#endif 1064#endif
1175 1065
1176#ifdef OFF_FOCUS_FADING 1066#ifdef OFF_FOCUS_FADING
1177 // initially we are in unfocused state 1067 // initially we are in unfocused state
1178 if (rs[Rs_fade]) 1068 if (rs[Rs_fade])
1179 pix_colors = pix_colors_unfocused; 1069 pix_colors = pix_colors_unfocused;
1180#endif 1070#endif
1181 1071
1072 pointer_unblank ();
1182 scr_recolour (); 1073 scr_recolour ();
1183} 1074}
1184 1075
1185/* ------------------------------------------------------------------------- * 1076/* ------------------------------------------------------------------------- *
1186 * GET TTY CURRENT STATE * 1077 * GET TTY CURRENT STATE *
1192 /* 1083 /*
1193 * standard System V termios interface 1084 * standard System V termios interface
1194 */ 1085 */
1195 if (GET_TERMIOS (STDIN_FILENO, tio) < 0) 1086 if (GET_TERMIOS (STDIN_FILENO, tio) < 0)
1196 { 1087 {
1197 /* return error - use system defaults */ 1088 // return error - use system defaults,
1089 // where possible, and zero elsewhere
1090 memset (tio, 0, sizeof (ttymode_t));
1091
1198 tio->c_cc[VINTR] = CINTR; 1092 tio->c_cc[VINTR] = CINTR;
1199 tio->c_cc[VQUIT] = CQUIT; 1093 tio->c_cc[VQUIT] = CQUIT;
1200 tio->c_cc[VERASE] = CERASE; 1094 tio->c_cc[VERASE] = CERASE;
1095#ifdef VERASE2
1096 tio->c_cc[VERASE2] = CERASE2;
1097#endif
1201 tio->c_cc[VKILL] = CKILL; 1098 tio->c_cc[VKILL] = CKILL;
1202 tio->c_cc[VSTART] = CSTART; 1099 tio->c_cc[VSTART] = CSTART;
1203 tio->c_cc[VSTOP] = CSTOP; 1100 tio->c_cc[VSTOP] = CSTOP;
1204 tio->c_cc[VSUSP] = CSUSP; 1101 tio->c_cc[VSUSP] = CSUSP;
1205# ifdef VDSUSP 1102# ifdef VDSUSP
1206
1207 tio->c_cc[VDSUSP] = CDSUSP; 1103 tio->c_cc[VDSUSP] = CDSUSP;
1208# endif 1104# endif
1209# ifdef VREPRINT 1105# ifdef VREPRINT
1210
1211 tio->c_cc[VREPRINT] = CRPRNT; 1106 tio->c_cc[VREPRINT] = CRPRNT;
1212# endif 1107# endif
1213# ifdef VDISCRD 1108# ifdef VDISCRD
1214
1215 tio->c_cc[VDISCRD] = CFLUSH; 1109 tio->c_cc[VDISCRD] = CFLUSH;
1216# endif 1110# endif
1217# ifdef VWERSE 1111# ifdef VWERSE
1218
1219 tio->c_cc[VWERSE] = CWERASE; 1112 tio->c_cc[VWERSE] = CWERASE;
1220# endif 1113# endif
1221# ifdef VLNEXT 1114# ifdef VLNEXT
1222
1223 tio->c_cc[VLNEXT] = CLNEXT; 1115 tio->c_cc[VLNEXT] = CLNEXT;
1224# endif 1116# endif
1225
1226 } 1117 }
1118
1227 tio->c_cc[VEOF] = CEOF; 1119 tio->c_cc[VEOF] = CEOF;
1228 tio->c_cc[VEOL] = VDISABLE; 1120 tio->c_cc[VEOL] = VDISABLE;
1229# ifdef VEOL2 1121# ifdef VEOL2
1230
1231 tio->c_cc[VEOL2] = VDISABLE; 1122 tio->c_cc[VEOL2] = VDISABLE;
1232# endif 1123# endif
1233# ifdef VSWTC 1124# ifdef VSWTC
1234
1235 tio->c_cc[VSWTC] = VDISABLE; 1125 tio->c_cc[VSWTC] = VDISABLE;
1236# endif 1126# endif
1237# ifdef VSWTCH 1127# ifdef VSWTCH
1238
1239 tio->c_cc[VSWTCH] = VDISABLE; 1128 tio->c_cc[VSWTCH] = VDISABLE;
1240# endif 1129# endif
1241# if VMIN != VEOF 1130# if VMIN != VEOF
1242
1243 tio->c_cc[VMIN] = 1; 1131 tio->c_cc[VMIN] = 1;
1244# endif 1132# endif
1245# if VTIME != VEOL 1133# if VTIME != VEOL
1246
1247 tio->c_cc[VTIME] = 0; 1134 tio->c_cc[VTIME] = 0;
1248# endif 1135# endif
1249 1136
1250 if (erase != -1) 1137 if (erase != -1)
1251 tio->c_cc[VERASE] = (char)erase; 1138 tio->c_cc[VERASE] = (char)erase;
1279 if (ioctl (STDIN_FILENO, TIOCGETP, & (tio->sg)) < 0) 1166 if (ioctl (STDIN_FILENO, TIOCGETP, & (tio->sg)) < 0)
1280 { 1167 {
1281 tio->sg.sg_erase = CERASE; /* ^H */ 1168 tio->sg.sg_erase = CERASE; /* ^H */
1282 tio->sg.sg_kill = CKILL; /* ^U */ 1169 tio->sg.sg_kill = CKILL; /* ^U */
1283 } 1170 }
1171
1284 if (erase != -1) 1172 if (erase != -1)
1285 tio->sg.sg_erase = (char)erase; 1173 tio->sg.sg_erase = (char)erase;
1286 1174
1287 tio->sg.sg_flags = (CRMOD | ECHO | EVENP | ODDP); 1175 tio->sg.sg_flags = (CRMOD | ECHO | EVENP | ODDP);
1288 1176
1294 tio->tc.t_startc = CSTART; /* ^Q */ 1182 tio->tc.t_startc = CSTART; /* ^Q */
1295 tio->tc.t_stopc = CSTOP; /* ^S */ 1183 tio->tc.t_stopc = CSTOP; /* ^S */
1296 tio->tc.t_eofc = CEOF; /* ^D */ 1184 tio->tc.t_eofc = CEOF; /* ^D */
1297 tio->tc.t_brkc = -1; 1185 tio->tc.t_brkc = -1;
1298 } 1186 }
1187
1299 /* get local special chars */ 1188 /* get local special chars */
1300 if (ioctl (STDIN_FILENO, TIOCGLTC, & (tio->lc)) < 0) 1189 if (ioctl (STDIN_FILENO, TIOCGLTC, & (tio->lc)) < 0)
1301 { 1190 {
1302 tio->lc.t_suspc = CSUSP; /* ^Z */ 1191 tio->lc.t_suspc = CSUSP; /* ^Z */
1303 tio->lc.t_dsuspc = CDSUSP; /* ^Y */ 1192 tio->lc.t_dsuspc = CDSUSP; /* ^Y */
1307 tio->lc.t_lnextc = CLNEXT; /* ^V */ 1196 tio->lc.t_lnextc = CLNEXT; /* ^V */
1308 } 1197 }
1309 /* get line discipline */ 1198 /* get line discipline */
1310 ioctl (STDIN_FILENO, TIOCGETD, & (tio->line)); 1199 ioctl (STDIN_FILENO, TIOCGETD, & (tio->line));
1311# ifdef NTTYDISC 1200# ifdef NTTYDISC
1312
1313 tio->line = NTTYDISC; 1201 tio->line = NTTYDISC;
1314# endif /* NTTYDISC */ 1202# endif /* NTTYDISC */
1315 1203
1316 tio->local = (LCRTBS | LCRTERA | LCTLECH | LPASS8 | LCRTKIL); 1204 tio->local = (LCRTBS | LCRTERA | LCTLECH | LPASS8 | LCRTKIL);
1317#endif /* HAVE_TERMIOS_H */ 1205#endif /* HAVE_TERMIOS_H */
1340 FOO (IGNCR, "IGNCR"); 1228 FOO (IGNCR, "IGNCR");
1341 FOO (ICRNL, "ICRNL"); 1229 FOO (ICRNL, "ICRNL");
1342 FOO (IXON, "IXON"); 1230 FOO (IXON, "IXON");
1343 FOO (IXOFF, "IXOFF"); 1231 FOO (IXOFF, "IXOFF");
1344# ifdef IUCLC 1232# ifdef IUCLC
1345
1346 FOO (IUCLC, "IUCLC"); 1233 FOO (IUCLC, "IUCLC");
1347# endif 1234# endif
1348# ifdef IXANY 1235# ifdef IXANY
1349
1350 FOO (IXANY, "IXANY"); 1236 FOO (IXANY, "IXANY");
1351# endif 1237# endif
1352# ifdef IMAXBEL 1238# ifdef IMAXBEL
1353
1354 FOO (IMAXBEL, "IMAXBEL"); 1239 FOO (IMAXBEL, "IMAXBEL");
1355# endif 1240# endif
1356 1241
1357 fprintf (stderr, "\n"); 1242 fprintf (stderr, "\n");
1358 1243
1365 FOO (VERASE, "VERASE"); 1250 FOO (VERASE, "VERASE");
1366 FOO (VKILL, "VKILL"); 1251 FOO (VKILL, "VKILL");
1367 FOO (VEOF, "VEOF"); 1252 FOO (VEOF, "VEOF");
1368 FOO (VEOL, "VEOL"); 1253 FOO (VEOL, "VEOL");
1369# ifdef VEOL2 1254# ifdef VEOL2
1370
1371 FOO (VEOL2, "VEOL2"); 1255 FOO (VEOL2, "VEOL2");
1372# endif 1256# endif
1373# ifdef VSWTC 1257# ifdef VSWTC
1374
1375 FOO (VSWTC, "VSWTC"); 1258 FOO (VSWTC, "VSWTC");
1376# endif 1259# endif
1377# ifdef VSWTCH 1260# ifdef VSWTCH
1378
1379 FOO (VSWTCH, "VSWTCH"); 1261 FOO (VSWTCH, "VSWTCH");
1380# endif 1262# endif
1381
1382 FOO (VSTART, "VSTART"); 1263 FOO (VSTART, "VSTART");
1383 FOO (VSTOP, "VSTOP"); 1264 FOO (VSTOP, "VSTOP");
1384 FOO (VSUSP, "VSUSP"); 1265 FOO (VSUSP, "VSUSP");
1385# ifdef VDSUSP 1266# ifdef VDSUSP
1386
1387 FOO (VDSUSP, "VDSUSP"); 1267 FOO (VDSUSP, "VDSUSP");
1388# endif 1268# endif
1389# ifdef VREPRINT 1269# ifdef VREPRINT
1390
1391 FOO (VREPRINT, "VREPRINT"); 1270 FOO (VREPRINT, "VREPRINT");
1392# endif 1271# endif
1393# ifdef VDISCRD 1272# ifdef VDISCRD
1394
1395 FOO (VDISCRD, "VDISCRD"); 1273 FOO (VDISCRD, "VDISCRD");
1396# endif 1274# endif
1397# ifdef VWERSE 1275# ifdef VWERSE
1398
1399 FOO (VWERSE, "VWERSE"); 1276 FOO (VWERSE, "VWERSE");
1400# endif 1277# endif
1401# ifdef VLNEXT 1278# ifdef VLNEXT
1402
1403 FOO (VLNEXT, "VLNEXT"); 1279 FOO (VLNEXT, "VLNEXT");
1404# endif 1280# endif
1405 1281
1406 fprintf (stderr, "\n"); 1282 fprintf (stderr, "\n");
1407# undef FOO 1283# undef FOO
1419rxvt_term::run_command (const char *const *argv) 1295rxvt_term::run_command (const char *const *argv)
1420{ 1296{
1421#if ENABLE_FRILLS 1297#if ENABLE_FRILLS
1422 if (rs[Rs_pty_fd]) 1298 if (rs[Rs_pty_fd])
1423 { 1299 {
1424 pty.pty = atoi (rs[Rs_pty_fd]); 1300 pty->pty = atoi (rs[Rs_pty_fd]);
1425 fcntl (pty.pty, F_SETFL, O_NONBLOCK); 1301
1302 if (pty->pty >= 0)
1303 {
1304 if (getfd_hook)
1305 pty->pty = (*getfd_hook) (pty->pty);
1306
1307 if (pty->pty < 0 || fcntl (pty->pty, F_SETFL, O_NONBLOCK))
1308 rxvt_fatal ("unusable pty-fd filehandle, aborting.\n");
1309 }
1426 } 1310 }
1427 else 1311 else
1428#endif 1312#endif
1429 if (!pty.get ()) 1313 if (!pty->get ())
1430 rxvt_fatal ("can't initialize pseudo-tty, aborting.\n"); 1314 rxvt_fatal ("can't initialize pseudo-tty, aborting.\n");
1431 1315
1432 pty.set_utf8_mode (enc_utf8); 1316 pty->set_utf8_mode (enc_utf8);
1433 1317
1434 /* set initial window size */ 1318 /* set initial window size */
1435 tt_winch (); 1319 tt_winch ();
1436 1320
1437 int er; 1321 int er;
1450#if ENABLE_FRILLS 1334#if ENABLE_FRILLS
1451 if (rs[Rs_pty_fd]) 1335 if (rs[Rs_pty_fd])
1452 return; 1336 return;
1453#endif 1337#endif
1454 1338
1455 sw_chld.start (SIGCHLD);
1456
1457#ifndef __QNX__
1458 /* spin off the command interpreter */ 1339 /* spin off the command interpreter */
1459 switch (cmd_pid = fork ()) 1340 switch (cmd_pid = fork ())
1460 { 1341 {
1461 case -1: 1342 case -1:
1462 { 1343 {
1464 rxvt_fatal ("can't fork, aborting.\n"); 1345 rxvt_fatal ("can't fork, aborting.\n");
1465 } 1346 }
1466 case 0: 1347 case 0:
1467 init_env (); 1348 init_env ();
1468 1349
1469 if (!pty.make_controlling_tty ()) 1350 if (!pty->make_controlling_tty ())
1470 fprintf (stderr, "%s: could not obtain control of tty.", RESNAME); 1351 fprintf (stderr, "%s: could not obtain control of tty.", RESNAME);
1471 else 1352 else
1472 { 1353 {
1473 /* Reopen stdin, stdout and stderr over the tty file descriptor */ 1354 /* Reopen stdin, stdout and stderr over the tty file descriptor */
1474 dup2 (pty.tty, STDIN_FILENO); 1355 dup2 (pty->tty, STDIN_FILENO);
1475 dup2 (pty.tty, STDOUT_FILENO); 1356 dup2 (pty->tty, STDOUT_FILENO);
1476 dup2 (pty.tty, STDERR_FILENO); 1357 dup2 (pty->tty, STDERR_FILENO);
1477 1358
1478 // close all our file handles that we do no longer need 1359 // close all our file handles that we do no longer need
1479 for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++) 1360 for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++)
1480 { 1361 {
1481 if ((*t)->pty.pty > 2) close ((*t)->pty.pty); 1362 if ((*t)->pty->pty > 2) close ((*t)->pty->pty);
1482 if ((*t)->pty.tty > 2) close ((*t)->pty.tty); 1363 if ((*t)->pty->tty > 2) close ((*t)->pty->tty);
1483 } 1364 }
1484 1365
1485 run_child (argv); 1366 run_child (argv);
1486 fprintf (stderr, "%s: unable to exec child.", RESNAME); 1367 fprintf (stderr, "%s: unable to exec child.", RESNAME);
1487 } 1368 }
1488 1369
1489 _exit (EXIT_FAILURE); 1370 _exit (EXIT_FAILURE);
1490 1371
1491 default: 1372 default:
1492 { 1373 if (!OPTION (Opt_utmpInhibit))
1493#if defined(HAVE_STRUCT_UTMP) && defined(HAVE_TTYSLOT) 1374 pty->login (cmd_pid, OPTION (Opt_loginShell), rs[Rs_display_name]);
1494 int fdstdin;
1495 1375
1496 fdstdin = dup (STDIN_FILENO); 1376 pty->close_tty ();
1497 dup2 (pty.tty, STDIN_FILENO);
1498#endif
1499 1377
1500#ifdef UTMP_SUPPORT 1378 child_ev.start (cmd_pid);
1501 privileged_utmp (SAVE);
1502#endif
1503 1379
1504#if defined(HAVE_STRUCT_UTMP) && defined(HAVE_TTYSLOT) 1380 HOOK_INVOKE ((this, HOOK_CHILD_START, DT_INT, cmd_pid, DT_END));
1505
1506 dup2 (fdstdin, STDIN_FILENO);
1507 close (fdstdin);
1508#endif
1509 }
1510
1511 pty.close_tty (); /* keep STDERR_FILENO, pty.pty, display->fd () open */
1512 break; 1381 break;
1513 } 1382 }
1514#else /* __QNX__ uses qnxspawn () */
1515 fchmod (pty.tty, 0622);
1516 fcntl (pty.tty, F_SETFD, FD_CLOEXEC);
1517 fcntl (pty.pty, F_SETFD, FD_CLOEXEC);
1518
1519 if (run_child (argv) == -1)
1520 exit (EXIT_FAILURE);
1521#endif
1522} 1383}
1523 1384
1524/* ------------------------------------------------------------------------- * 1385/* ------------------------------------------------------------------------- *
1525 * CHILD PROCESS OPERATIONS * 1386 * CHILD PROCESS OPERATIONS *
1526 * ------------------------------------------------------------------------- */ 1387 * ------------------------------------------------------------------------- */
1533{ 1394{
1534 char *login; 1395 char *login;
1535 1396
1536 SET_TTYMODE (STDIN_FILENO, &tio); /* init terminal attributes */ 1397 SET_TTYMODE (STDIN_FILENO, &tio); /* init terminal attributes */
1537 1398
1538 if (options & Opt_console) 1399 if (OPTION (Opt_console))
1539 { /* be virtual console, fail silently */ 1400 { /* be virtual console, fail silently */
1540#ifdef TIOCCONS 1401#ifdef TIOCCONS
1541 unsigned int on = 1; 1402 unsigned int on = 1;
1542 1403
1543 ioctl (STDIN_FILENO, TIOCCONS, &on); 1404 ioctl (STDIN_FILENO, TIOCCONS, &on);
1570 // unblock signals (signals are blocked by iom.C 1431 // unblock signals (signals are blocked by iom.C
1571 sigset_t ss; 1432 sigset_t ss;
1572 sigemptyset (&ss); 1433 sigemptyset (&ss);
1573 sigprocmask (SIG_SETMASK, &ss, 0); 1434 sigprocmask (SIG_SETMASK, &ss, 0);
1574 1435
1575#ifndef __QNX__
1576 /* command interpreter path */ 1436 /* command interpreter path */
1577 if (argv != NULL) 1437 if (argv != NULL)
1578 { 1438 {
1579# ifdef DEBUG_CMD 1439# ifdef DEBUG_CMD
1580 int i; 1440 int i;
1586 execvp (argv[0], (char *const *)argv); 1446 execvp (argv[0], (char *const *)argv);
1587 /* no error message: STDERR is closed! */ 1447 /* no error message: STDERR is closed! */
1588 } 1448 }
1589 else 1449 else
1590 { 1450 {
1591 const char *argv0, *shell; 1451 const char *argv0, *shell;
1592 1452
1593 if ((shell = getenv ("SHELL")) == NULL || *shell == '\0') 1453 if ((shell = getenv ("SHELL")) == NULL || *shell == '\0')
1594 shell = "/bin/sh"; 1454 shell = "/bin/sh";
1595 1455
1596 argv0 = (const char *)rxvt_r_basename (shell); 1456 argv0 = (const char *)rxvt_r_basename (shell);
1597 1457
1598 if (options & Opt_loginShell) 1458 if (OPTION (Opt_loginShell))
1599 { 1459 {
1600 login = (char *)rxvt_malloc ((strlen (argv0) + 2) * sizeof (char)); 1460 login = (char *)rxvt_malloc ((strlen (argv0) + 2) * sizeof (char));
1601 1461
1602 login[0] = '-'; 1462 login[0] = '-';
1603 strcpy (&login[1], argv0); 1463 strcpy (&login[1], argv0);
1604 argv0 = login; 1464 argv0 = login;
1605 } 1465 }
1466
1606 execlp (shell, argv0, NULL); 1467 execlp (shell, argv0, NULL);
1607 /* no error message: STDERR is closed! */ 1468 /* no error message: STDERR is closed! */
1608 } 1469 }
1609 1470
1610#else /* __QNX__ uses qnxspawn () */
1611
1612 char iov_a[10] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
1613 char *command = NULL, fullcommand[_MAX_PATH];
1614 char **arg_v, *arg_a[2] = { NULL, NULL };
1615
1616 if (argv != NULL)
1617 {
1618 if (access (argv[0], X_OK) == -1)
1619 {
1620 if (strchr (argv[0], '/') == NULL)
1621 {
1622 searchenv (argv[0], "PATH", fullcommand);
1623
1624 if (fullcommand[0] != '\0')
1625 command = fullcommand;
1626 }
1627
1628 if (access (command, X_OK) == -1)
1629 return -1;
1630 }
1631 else
1632 command = argv[0];
1633
1634 arg_v = argv;
1635 }
1636 else
1637 {
1638 if ((command = getenv ("SHELL")) == NULL || *command == '\0')
1639 command = "/bin/sh";
1640
1641 arg_a[0] = my_basename (command);
1642
1643 if (options & Opt_loginShell)
1644 {
1645 login = rxvt_malloc ((strlen (arg_a[0]) + 2) * sizeof (char));
1646
1647 login[0] = '-';
1648 strcpy (&login[1], arg_a[0]);
1649 arg_a[0] = login;
1650 }
1651
1652 arg_v = arg_a;
1653 }
1654
1655 iov_a[0] = iov_a[1] = iov_a[2] = pty.tty;
1656 cmd_pid = qnx_spawn (0, 0, 0, -1, -1,
1657 _SPAWN_SETSID | _SPAWN_TCSETPGRP,
1658 command, arg_v, environ, iov_a, 0);
1659 if (login)
1660 free (login);
1661
1662 pty.close_tty ();
1663 return pty.pty;
1664#endif
1665
1666 return -1; 1471 return -1;
1667} 1472}
1668 1473
1669/*----------------------- end-of-file (C source) -----------------------*/ 1474/*----------------------- end-of-file (C source) -----------------------*/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines