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

Comparing rxvt-unicode/src/main.C (file contents):
Revision 1.42 by pcg, Sun Feb 22 10:38:11 2004 UTC vs.
Revision 1.73 by root, Fri Jul 30 14:59:12 2004 UTC

1/*--------------------------------*-C-*---------------------------------*; 1/*--------------------------------*-C-*---------------------------------*
2 * File: main.c 2 * File: main.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> 6 * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk>
7 * - original version 7 * - original version
44# include <termios.h> 44# include <termios.h>
45#endif 45#endif
46 46
47#include <cstring> 47#include <cstring>
48 48
49vector<rxvt_term *> rxvt_term::termlist;
50
49static char curlocale[128]; 51static char curlocale[128];
50 52
51void 53bool
52rxvt_set_locale (const char *locale) 54rxvt_set_locale (const char *locale)
53{ 55{
54 if (locale && STRNCMP (locale, curlocale, 128)) 56 if (!locale || !STRNCMP (locale, curlocale, 128))
55 { 57 return false;
58
56 STRNCPY (curlocale, locale, 128); 59 STRNCPY (curlocale, locale, 128);
57 setlocale (LC_CTYPE, curlocale); 60 setlocale (LC_CTYPE, curlocale);
61 return true;
62}
63
64#if ENABLE_COMBINING
65class rxvt_composite_vec rxvt_composite;
66
67text_t rxvt_composite_vec::compose (unicode_t c1, unicode_t c2)
68{
69 compose_char *cc;
70
71 // break compose chains, as stupid readline really likes to duplicate
72 // composing characters for some reason near the end of a line.
73 cc = (*this)[c1];
74 while (cc)
58 } 75 {
76 if (cc->c2 == c2) return c1;
77 cc = (*this)[cc->c1];
78 }
79
80 // check to see wether this combination already exists otherwise
81 for (cc = v.end (); cc-- > v.begin (); )
82 {
83 if (cc->c1 == c1 && cc->c2 == c2)
84 return COMPOSE_LO + (cc - v.begin ());
85 }
86
87 // allocate a new combination
88 if (v.size () == COMPOSE_HI - COMPOSE_LO + 1)
89 {
90 static int seen;
91
92 if (!seen++)
93 fprintf (stderr, "too many unrepresentable composite characters, try --enable-unicode3\n");
94
95 return REPLACEMENT_CHAR;
96 }
97
98 v.push_back (compose_char (c1, c2));
99
100 return v.size () - 1 + COMPOSE_LO;
59} 101}
102
103int rxvt_composite_vec::expand (unicode_t c, wchar_t *r)
104{
105 compose_char *cc = (*this)[c];
106
107 if (!cc)
108 {
109 if (r) *r = c;
110 return 1;
111 }
112
113 int len = expand (cc->c1, r);
114
115 if (r) r += len;
116
117 if (cc->c2 != NOCHAR)
118 {
119 len++;
120 if (r) *r++ = cc->c2;
121 }
122
123 return len;
124
125}
126#endif
60 127
61void * 128void *
62rxvt_term::operator new (size_t s) 129rxvt_term::operator new (size_t s)
63{ 130{
64 void *p = malloc (s); 131 void *p = malloc (s);
80 vt_ev (this, &rxvt_term::x_cb), 147 vt_ev (this, &rxvt_term::x_cb),
81#ifdef HAVE_SCROLLBARS 148#ifdef HAVE_SCROLLBARS
82 scrollbar_ev (this, &rxvt_term::x_cb), 149 scrollbar_ev (this, &rxvt_term::x_cb),
83#endif 150#endif
84#ifdef MENUBAR 151#ifdef MENUBAR
85 menubar_ev (this, &rxvt_term::x_cb), fixme 152 menubar_ev (this, &rxvt_term::x_cb),
86#endif 153#endif
87#ifdef CURSOR_BLINK 154#ifdef CURSOR_BLINK
88 cursor_blink_ev (this, &rxvt_term::cursor_blink_cb), 155 cursor_blink_ev (this, &rxvt_term::cursor_blink_cb),
89#endif 156#endif
90#ifdef TEXT_BLINK 157#ifdef TEXT_BLINK
91 text_blink_ev (this, &rxvt_term::text_blink_cb), 158 text_blink_ev (this, &rxvt_term::text_blink_cb),
159#endif
160#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
161 cont_scroll_ev (this, &rxvt_term::cont_scroll_cb),
162#endif
163#ifdef SELECTION_SCROLLING
164 sel_scroll_ev (this, &rxvt_term::sel_scroll_cb),
165#endif
166#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
167 slip_wheel_ev (this, &rxvt_term::slip_wheel_cb),
92#endif 168#endif
93#ifdef POINTER_BLANK 169#ifdef POINTER_BLANK
94 pointer_ev (this, &rxvt_term::pointer_cb), 170 pointer_ev (this, &rxvt_term::pointer_cb),
95#endif 171#endif
96#ifdef USE_XIM 172#ifdef USE_XIM
100 destroy_ev (this, &rxvt_term::destroy_cb), 176 destroy_ev (this, &rxvt_term::destroy_cb),
101 pty_ev (this, &rxvt_term::pty_cb), 177 pty_ev (this, &rxvt_term::pty_cb),
102 incr_ev (this, &rxvt_term::incr_cb) 178 incr_ev (this, &rxvt_term::incr_cb)
103{ 179{
104 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; 180 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base;
181
182 termlist.push_back (this);
105} 183}
106 184
107rxvt_term::~rxvt_term () 185rxvt_term::~rxvt_term ()
108{ 186{
187 termlist.erase (find (termlist.begin (), termlist.end(), this));
188
109 if (cmd_fd >= 0) 189 if (cmd_fd >= 0)
110 close (cmd_fd); 190 close (cmd_fd);
111 191
112#ifndef NO_SETOWNER_TTYDEV 192#ifndef NO_SETOWNER_TTYDEV
113 privileged_ttydev (RESTORE); 193 privileged_ttydev (RESTORE);
117#endif 197#endif
118 198
119 delete TermWin.fontset; 199 delete TermWin.fontset;
120 200
121 if (display) 201 if (display)
202 {
203 selection_clear ();
204
205#ifdef MENUBAR
206 if (menubarGC) XFreeGC (display->display, menubarGC);
207#endif
208#ifdef XTERM_SCROLLBAR
209 if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC);
210 if (ShadowGC) XFreeGC (display->display, ShadowGC);
211#endif
212#ifdef PLAIN_SCROLLBAR
213 if (pscrollbarGC) XFreeGC (display->display, pscrollbarGC);
214#endif
215#ifdef NEXT_SCROLLBAR
216 if (blackGC) XFreeGC (display->display, blackGC);
217 if (whiteGC) XFreeGC (display->display, whiteGC);
218 if (grayGC) XFreeGC (display->display, grayGC);
219 if (darkGC) XFreeGC (display->display, darkGC);
220 if (stippleGC) XFreeGC (display->display, stippleGC);
221 if (dimple) XFreePixmap (display->display, dimple);
222 if (upArrow) XFreePixmap (display->display, upArrow);
223 if (downArrow) XFreePixmap (display->display, downArrow);
224 if (upArrowHi) XFreePixmap (display->display, upArrowHi);
225 if (downArrowHi) XFreePixmap (display->display, downArrowHi);
226#endif
227#if defined(MENUBAR) || defined(RXVT_SCROLLBAR)
228 if (topShadowGC) XFreeGC (display->display, topShadowGC);
229 if (botShadowGC) XFreeGC (display->display, botShadowGC);
230 if (scrollbarGC) XFreeGC (display->display, scrollbarGC);
231#endif
232 if (TermWin.gc) XFreeGC (display->display, TermWin.gc);
233
234#if defined(MENUBAR) && (MENUBAR_MAX > 1)
235 delete menuBar.drawable;
236 //if (menuBar.win)
237 // XDestroyWindow (display->display, menuBar.win);
238#endif
239 delete TermWin.drawable;
240 // destroy all windows
122 if (TermWin.parent[0]) 241 if (TermWin.parent[0])
123 XDestroyWindow (display->display, TermWin.parent[0]); 242 XDestroyWindow (display->display, TermWin.parent[0]);
243 }
124 244
125 // TODO: free pixcolours, colours should become part of rxvt_display 245 // TODO: free pixcolours, colours should become part of rxvt_display
126 246
127 delete PixColors; 247 delete PixColorsFocused;
248#ifdef OFF_FOCUS_FADING
249 delete PixColorsUnFocused;
250#endif
128 251
129 displays.put (display); 252 displays.put (display);
130 253
131 scr_release (); 254 scr_release ();
132 255
256 /* clear all resources */
257 for (int i = 0; i < allocated.size (); i++)
258 free (allocated[i]);
259
260 free (selection.text);
261 // TODO: manage env vars in child only(!)
133 free (env_windowid); 262 free (env_windowid);
134 free (env_display); 263 free (env_display);
135 free (env_term); 264 free (env_term);
136 free (env_colorfgbg); 265 free (env_colorfgbg);
137 free (locale); 266 free (locale);
267#if 0
138 free (codeset); 268 free (codeset);
269#endif
139 270
140 delete envv; 271 delete envv;
141 delete argv; 272 delete argv;
142} 273}
143 274
167 cursor_blink_ev.stop (); 298 cursor_blink_ev.stop ();
168#endif 299#endif
169#ifdef TEXT_BLINK 300#ifdef TEXT_BLINK
170 text_blink_ev.stop (); 301 text_blink_ev.stop ();
171#endif 302#endif
303#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
304 cont_scroll_ev.stop ();
305#endif
306#ifdef SELECTION_SCROLLING
307 sel_scroll_ev.stop ();
308#endif
172#ifdef POINTER_BLANK 309#ifdef POINTER_BLANK
173 pointer_ev.stop (); 310 pointer_ev.stop ();
174#endif 311#endif
175 312
176 destroy_ev.start (0); 313 destroy_ev.start (0);
184 delete this; 321 delete this;
185} 322}
186 323
187/*----------------------------------------------------------------------*/ 324/*----------------------------------------------------------------------*/
188/* rxvt_init () */ 325/* rxvt_init () */
189/* LIBPROTO */
190rxvt_t
191rxvt_init (int argc, const char *const *argv)
192{
193 SET_R (new rxvt_term);
194
195 if (!GET_R->init_vars () || !GET_R->init (argc, argv))
196 {
197 delete GET_R;
198 SET_R (0);
199 }
200
201 return GET_R;
202}
203
204static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event);
205
206void
207rxvt_init_signals ()
208{
209 /* install exit handler for cleanup */
210#if 0
211#ifdef HAVE_ATEXIT
212 atexit (rxvt_clean_exit);
213#else
214#endif
215#endif
216
217 struct sigaction sa;
218
219 sigfillset (&sa.sa_mask);
220 sa.sa_flags = SA_NOCLDSTOP | SA_RESTART;
221 sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0);
222 sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0);
223 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0);
224 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0);
225 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0);
226 sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0);
227
228 /* need to trap SIGURG for SVR4 (Unixware) rlogin */
229 /* signal (SIGURG, SIG_DFL); */
230
231 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
232 //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler);
233}
234
235bool 326bool
236rxvt_term::init (int argc, const char *const *argv) 327rxvt_term::init (int argc, const char *const *argv)
237{ 328{
329 SET_R (this);
330
331 if (!init_vars ())
332 return false;
333
238 /* 334 /*
239 * Save and then give up any super-user privileges 335 * Save and then give up any super-user privileges
240 * If we need privileges in any area then we must specifically request it. 336 * If we need privileges in any area then we must specifically request it.
241 * We should only need to be root in these cases: 337 * We should only need to be root in these cases:
242 * 1. write utmp entries on some systems 338 * 1. write utmp entries on some systems
249 345
250 const char **cmd_argv = init_resources (argc, argv); 346 const char **cmd_argv = init_resources (argc, argv);
251 347
252 set_locale (""); 348 set_locale ("");
253 349
254#if (MENUBAR_MAX) 350#if MENUBAR_MAX
255 menubar_read (rs[Rs_menu]); 351 menubar_read (rs[Rs_menu]);
256#endif 352#endif
257#ifdef HAVE_SCROLLBARS 353#ifdef HAVE_SCROLLBARS
258 if (Options & Opt_scrollBar) 354 if (Options & Opt_scrollBar)
259 scrollBar.setIdle (); /* set existence for size calculations */ 355 scrollBar.setIdle (); /* set existence for size calculations */
272#ifdef HAVE_SCROLLBARS 368#ifdef HAVE_SCROLLBARS
273 if (Options & Opt_scrollBar) 369 if (Options & Opt_scrollBar)
274 resize_scrollbar (); /* create and map scrollbar */ 370 resize_scrollbar (); /* create and map scrollbar */
275#endif 371#endif
276#if (MENUBAR_MAX) 372#if (MENUBAR_MAX)
277 if (menubar_visible (r)) 373 if (menubar_visible ())
278 XMapWindow (display->display, menuBar.win); 374 XMapWindow (display->display, menuBar.win);
279#endif 375#endif
280#ifdef TRANSPARENT 376#ifdef TRANSPARENT
281 if (Options & Opt_transparent) 377 if (Options & Opt_transparent)
282 { 378 {
295 pty_ev.start (cmd_fd, EVENT_READ); 391 pty_ev.start (cmd_fd, EVENT_READ);
296 392
297 check_ev.start (); 393 check_ev.start ();
298 394
299 return true; 395 return true;
396}
397
398static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event);
399
400void
401rxvt_init_signals ()
402{
403 /* install exit handler for cleanup */
404#if 0
405#ifdef HAVE_ATEXIT
406 atexit (rxvt_clean_exit);
407#else
408#endif
409#endif
410
411 struct sigaction sa;
412
413 sigfillset (&sa.sa_mask);
414 sa.sa_flags = SA_NOCLDSTOP | SA_RESTART;
415 sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0);
416 sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0);
417 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0);
418 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0);
419 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0);
420 sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0);
421
422 /* need to trap SIGURG for SVR4 (Unixware) rlogin */
423 /* signal (SIGURG, SIG_DFL); */
424
425 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
426 //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler);
300} 427}
301 428
302/* ------------------------------------------------------------------------- * 429/* ------------------------------------------------------------------------- *
303 * SIGNAL HANDLING & EXIT HANDLER * 430 * SIGNAL HANDLING & EXIT HANDLER *
304 * ------------------------------------------------------------------------- */ 431 * ------------------------------------------------------------------------- */
305/* 432/*
306 * Catch a SIGCHLD signal and exit if the direct child has died 433 * Catch a SIGCHLD signal and exit if the direct child has died
307 */ 434 */
435
436void rxvt_term::child_exited (int pid)
437{
438 for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++)
439 if (pid == (*t)->cmd_pid)
440 {
441 (*t)->destroy ();
442 break;
443 }
444}
445
308/* ARGSUSED */ 446/* ARGSUSED */
309/* EXTPROTO */ 447/* EXTPROTO */
310RETSIGTYPE 448RETSIGTYPE
311rxvt_Child_signal (int sig __attribute__ ((unused))) 449rxvt_Child_signal (int sig __attribute__ ((unused)))
312{ 450{
313 int pid, save_errno = errno; 451 int pid, save_errno = errno;
452
314 while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR) 453 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0)
315 ; 454 rxvt_term::child_exited (pid);
455
316 errno = save_errno; 456 errno = save_errno;
317
318#if 0
319 if (pid == cmd_pid)
320 exit (EXIT_SUCCESS);
321#endif
322} 457}
323 458
324/* 459/*
325 * Catch a fatal signal and tidy up before quitting 460 * Catch a fatal signal and tidy up before quitting
326 */ 461 */
328RETSIGTYPE 463RETSIGTYPE
329rxvt_Exit_signal (int sig) 464rxvt_Exit_signal (int sig)
330{ 465{
331 signal (sig, SIG_DFL); 466 signal (sig, SIG_DFL);
332#ifdef DEBUG_CMD 467#ifdef DEBUG_CMD
333 rxvt_print_error ("signal %d", sig); 468 rxvt_warn ("caught signal %d, exiting.\n", sig);
334#endif 469#endif
335 rxvt_clean_exit (); 470 rxvt_clean_exit ();
336 kill (getpid (), sig); 471 kill (getpid (), sig);
337} 472}
338 473
376 511
377 p = malloc (size); 512 p = malloc (size);
378 if (p) 513 if (p)
379 return p; 514 return p;
380 515
381 fprintf (stderr, APL_NAME ": memory allocation failure. Aborting"); 516 fprintf (stderr, RESNAME ": memory allocation failure. Aborting");
382 rxvt_clean_exit (); 517 rxvt_clean_exit ();
383 exit (EXIT_FAILURE); 518 exit (EXIT_FAILURE);
384 /* NOTREACHED */ 519 /* NOTREACHED */
385} 520}
386 521
392 527
393 p = calloc (number, size); 528 p = calloc (number, size);
394 if (p) 529 if (p)
395 return p; 530 return p;
396 531
397 fprintf (stderr, APL_NAME ": memory allocation failure. Aborting"); 532 fprintf (stderr, RESNAME ": memory allocation failure. Aborting");
398 rxvt_clean_exit (); 533 rxvt_clean_exit ();
399 exit (EXIT_FAILURE); 534 exit (EXIT_FAILURE);
400 /* NOTREACHED */ 535 /* NOTREACHED */
401} 536}
402 537
411 else 546 else
412 p = malloc (size); 547 p = malloc (size);
413 if (p) 548 if (p)
414 return p; 549 return p;
415 550
416 fprintf (stderr, APL_NAME ": memory allocation failure. Aborting"); 551 fprintf (stderr, RESNAME ": memory allocation failure. Aborting");
417 rxvt_clean_exit (); 552 rxvt_clean_exit ();
418 exit (EXIT_FAILURE); 553 exit (EXIT_FAILURE);
419 /* NOTREACHED */ 554 /* NOTREACHED */
420} 555}
421 556
613 else 748 else
614 szHint.win_gravity = SouthWestGravity; 749 szHint.win_gravity = SouthWestGravity;
615 } 750 }
616 } 751 }
617 } 752 }
753
618 /* TODO: BOUNDS */ 754 /* TODO: BOUNDS */
619 TermWin.width = TermWin.ncol * TermWin.fwidth; 755 TermWin.width = TermWin.ncol * TermWin.fwidth;
620 TermWin.height = TermWin.nrow * TermWin.fheight; 756 TermWin.height = TermWin.nrow * TermWin.fheight;
621 max_width = MAX_COLS * TermWin.fwidth; 757 max_width = MAX_COLS * TermWin.fwidth;
622 max_height = MAX_ROWS * TermWin.fheight; 758 max_height = MAX_ROWS * TermWin.fheight;
623 759
624 szHint.base_width = szHint.base_height = 2 * TermWin.int_bwidth; 760 szHint.base_width = szHint.base_height = 2 * TermWin.int_bwidth;
625 761
626 sb_w = mb_h = 0; 762 sb_w = mb_h = 0;
627 window_vt_x = window_vt_y = 0; 763 window_vt_x = window_vt_y = TermWin.int_bwidth;
764
628 if (scrollbar_visible ()) 765 if (scrollbar_visible ())
629 { 766 {
630 sb_w = scrollbar_TotalWidth (); 767 sb_w = scrollbar_TotalWidth ();
631 szHint.base_width += sb_w; 768 szHint.base_width += sb_w;
632 if (! (Options & Opt_scrollBar_right)) 769 if (!(Options & Opt_scrollBar_right))
633 window_vt_x = sb_w; 770 window_vt_x += sb_w;
634 } 771 }
772
635 if (menubar_visible ()) 773 if (menubar_visible ())
636 { 774 {
637 mb_h = menuBar_TotalHeight (); 775 mb_h = menuBar_TotalHeight ();
638 szHint.base_height += mb_h; 776 szHint.base_height += mb_h;
639 window_vt_y = mb_h; 777 window_vt_y += mb_h;
640 } 778 }
779
641 szHint.width_inc = TermWin.fwidth; 780 szHint.width_inc = TermWin.fwidth;
642 szHint.height_inc = TermWin.fheight; 781 szHint.height_inc = TermWin.fheight;
643 szHint.min_width = szHint.base_width + szHint.width_inc; 782 szHint.min_width = szHint.base_width + szHint.width_inc;
644 szHint.min_height = szHint.base_height + szHint.height_inc; 783 szHint.min_height = szHint.base_height + szHint.height_inc;
645 784
651 else 790 else
652 { 791 {
653 MIN_IT (TermWin.width, max_width); 792 MIN_IT (TermWin.width, max_width);
654 szHint.width = szHint.base_width + TermWin.width; 793 szHint.width = szHint.base_width + TermWin.width;
655 } 794 }
795
656 if (height && height - szHint.base_height < max_height) 796 if (height && height - szHint.base_height < max_height)
657 { 797 {
658 szHint.height = height; 798 szHint.height = height;
659 TermWin.height = height - szHint.base_height; 799 TermWin.height = height - szHint.base_height;
660 } 800 }
661 else 801 else
662 { 802 {
663 MIN_IT (TermWin.height, max_height); 803 MIN_IT (TermWin.height, max_height);
664 szHint.height = szHint.base_height + TermWin.height; 804 szHint.height = szHint.base_height + TermWin.height;
665 } 805 }
806
666 if (scrollbar_visible () && (Options & Opt_scrollBar_right)) 807 if (scrollbar_visible () && (Options & Opt_scrollBar_right))
667 window_sb_x = szHint.width - sb_w; 808 window_sb_x = szHint.width - sb_w;
668 809
669 if (recalc_x) 810 if (recalc_x)
670 szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) 811 szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display))
730 } 871 }
731 else 872 else
732 { 873 {
733 rxvt_fontset *fs = new rxvt_fontset (this); 874 rxvt_fontset *fs = new rxvt_fontset (this);
734 875
735 if (fs && fs->populate (fontname)) 876 if (fs && fs->populate (fontname ? fontname : "fixed"))
736 { 877 {
737 delete TermWin.fontset; 878 delete TermWin.fontset;
738 TermWin.fontset = fs; 879 TermWin.fontset = fs;
739 TermWin.fwidth = fs->base_font ()->width; 880 TermWin.fwidth = fs->base_font ()->width;
740 TermWin.fheight = fs->base_font ()->height; 881 TermWin.fheight = fs->base_font ()->height;
741 TermWin.fbase = fs->base_font ()->ascent; 882 TermWin.fbase = fs->base_font ()->ascent;
742 883
743 // TODO: screen needs to be told about new fonts
744
745 if (TermWin.parent[0]) 884 if (TermWin.parent[0])
746 { 885 {
747 resize_all_windows (0, 0, 0); 886 resize_all_windows (0, 0, 0);
748 scr_remap_chars (); 887 scr_remap_chars ();
749 scr_touch (true); 888 scr_touch (true);
766/*----------------------------------------------------------------------*/ 905/*----------------------------------------------------------------------*/
767/* xterm sequences - title, iconName, color (exptl) */ 906/* xterm sequences - title, iconName, color (exptl) */
768void 907void
769rxvt_term::set_title (const char *str) 908rxvt_term::set_title (const char *str)
770{ 909{
771#ifndef SMART_WINDOW_TITLE 910#ifdef SMART_WINDOW_TITLE
772 XStoreName (display->display, TermWin.parent[0], str); 911 char *name;
773#else
774 char *name;
775 912
776 if (XFetchName (display->display, TermWin.parent[0], &name) == 0) 913 if (!XFetchName (display->display, TermWin.parent[0], &name))
777 name = NULL; 914 name = NULL;
915
778 if (name == NULL || STRCMP (name, str)) 916 if (name == NULL || STRCMP (name, str))
917#endif
779 XStoreName (display->display, TermWin.parent[0], str); 918 XStoreName (display->display, TermWin.parent[0], str);
919
920#ifdef SMART_WINDOW_TITLE
780 if (name) 921 if (name)
781 XFree (name); 922 XFree (name);
782#endif 923#endif
783} 924}
784 925
785void 926void
786rxvt_term::set_iconName (const char *str) 927rxvt_term::set_icon_name (const char *str)
787{ 928{
788#ifndef SMART_WINDOW_TITLE 929#ifdef SMART_WINDOW_TITLE
789 XSetIconName (display->display, TermWin.parent[0], str); 930 char *name;
790#else
791 char *name;
792 931
793 if (XGetIconName (display->display, TermWin.parent[0], &name)) 932 if (!XGetIconName (display->display, TermWin.parent[0], &name))
794 name = NULL; 933 name = NULL;
934
795 if (name == NULL || STRCMP (name, str)) 935 if (name == NULL || STRCMP (name, str))
936#endif
796 XSetIconName (display->display, TermWin.parent[0], str); 937 XSetIconName (display->display, TermWin.parent[0], str);
938
939#ifdef SMART_WINDOW_TITLE
797 if (name) 940 if (name)
798 XFree (name); 941 XFree (name);
799#endif 942#endif
800} 943}
801 944
802#ifdef XTERM_COLOR_CHANGE 945#ifdef XTERM_COLOR_CHANGE
803void 946void
804rxvt_term::set_window_color (int idx, const char *color) 947rxvt_term::set_window_color (int idx, const char *color)
805{ 948{
806 rxvt_color xcol; 949 rxvt_color xcol;
807 int i; 950 int i;
808 951
809 if (color == NULL || *color == '\0') 952 if (color == NULL || *color == '\0')
810 return; 953 return;
811 954
812 /* handle color aliases */ 955 /* handle color aliases */
815 i = atoi (color); 958 i = atoi (color);
816 if (i >= 8 && i <= 15) 959 if (i >= 8 && i <= 15)
817 { /* bright colors */ 960 { /* bright colors */
818 i -= 8; 961 i -= 8;
819# ifndef NO_BRIGHTCOLOR 962# ifndef NO_BRIGHTCOLOR
820 PixColors[idx] = PixColors[minBrightCOLOR + i]; 963 PixColorsFocused[idx] = PixColorsFocused[minBrightCOLOR + i];
821 SET_PIXCOLOR (idx); 964 SET_PIXCOLOR (idx);
822 goto Done; 965 goto Done;
823# endif 966# endif
824 967
825 } 968 }
826 if (i >= 0 && i <= 7) 969 if (i >= 0 && i <= 7)
827 { /* normal colors */ 970 { /* normal colors */
828 PixColors[idx] = PixColors[minCOLOR + i]; 971 PixColorsFocused[idx] = PixColorsFocused[minCOLOR + i];
829 SET_PIXCOLOR (idx); 972 SET_PIXCOLOR (idx);
830 goto Done; 973 goto Done;
831 } 974 }
832 } 975 }
976
833 if (!rXParseAllocColor (& xcol, color)) 977 if (!rXParseAllocColor (& xcol, color))
834 return; 978 return;
979
835 /* XStoreColor (display->display, XCMAP, XColor*); */ 980 /* XStoreColor (display->display, XCMAP, XColor*); */
836 981
837 /* 982 /*
838 * FIXME: should free colors here, but no idea how to do it so instead, 983 * FIXME: should free colors here, but no idea how to do it so instead,
839 * so just keep gobbling up the colormap 984 * so just keep gobbling up the colormap
848 XFreeColors (display->display, XCMAP, (PixColors + idx), 1, 993 XFreeColors (display->display, XCMAP, (PixColors + idx), 1,
849 DisplayPlanes (display->display, display->screen)); 994 DisplayPlanes (display->display, display->screen));
850 } 995 }
851# endif 996# endif
852 997
853 PixColors[idx] = xcol; 998 PixColorsFocused[idx] = xcol;
854 SET_PIXCOLOR (idx); 999 SET_PIXCOLOR (idx);
855 1000
856 /* XSetWindowAttributes attr; */ 1001 /* XSetWindowAttributes attr; */
857 /* Cursor cursor; */ 1002 /* Cursor cursor; */
858Done: 1003Done:
1004#ifdef OFF_FOCUS_FADING
1005 PixColorsUnFocused[idx] = PixColorsFocused[idx].fade (display, atoi (rs[Rs_fade]));
1006#endif
859 if (idx == Color_bg && ! (Options & Opt_transparent)) 1007 if (idx == Color_bg && ! (Options & Opt_transparent))
860 XSetWindowBackground (display->display, TermWin.vt, 1008 XSetWindowBackground (display->display, TermWin.vt, PixColors[Color_bg]);
861 PixColors[Color_bg]);
862 1009
863 /* handle Color_BD, scrollbar background, etc. */ 1010 /* handle Color_BD, scrollbar background, etc. */
864 1011
865 set_colorfgbg (); 1012 set_colorfgbg ();
866 recolour_cursor (); 1013 recolour_cursor ();
867 /* the only reasonable way to enforce a clean update */ 1014 scr_touch (true);
868 scr_poweron ();
869} 1015}
870 1016
871#else 1017#else
872# define set_window_color (idx,color) ((void)0) 1018# define set_window_color (idx,color) ((void)0)
873#endif /* XTERM_COLOR_CHANGE */ 1019#endif /* XTERM_COLOR_CHANGE */
874 1020
875void 1021void
876rxvt_term::recolour_cursor () 1022rxvt_term::recolour_cursor ()
877{ 1023{
878#if TODO
879 rxvt_color xcol[2]; 1024 XColor xcol[2];
880 1025
881 xcol[0] = PixColors[Color_pointer]; 1026 xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) ? PixColorsFocused[Color_pointer_fg] : PixColorsFocused[Color_fg];
882 xcol[1] = PixColors[Color_bg]; 1027 xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) ? PixColorsFocused[Color_pointer_bg] : PixColorsFocused[Color_bg];
883 XQueryColors (display->display, XCMAP, xcol, 2); 1028 XQueryColors (display->display, XCMAP, xcol, 2);
884 XRecolorCursor (display->display, TermWin_cursor, & (xcol[0]), & (xcol[1])); 1029 XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1);
885#endif
886} 1030}
887 1031
888/*----------------------------------------------------------------------*/ 1032/*----------------------------------------------------------------------*/
889/* 1033/*
890 * find if fg/bg matches any of the normal (low-intensity) colors 1034 * find if fg/bg matches any of the normal (low-intensity) colors
939int 1083int
940rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) 1084rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour)
941{ 1085{
942 if (!screen_in_out->set (display, colour)) 1086 if (!screen_in_out->set (display, colour))
943 { 1087 {
944 rxvt_print_error ("can't allocate colour: %s", colour); 1088 rxvt_warn ("can't get colour '%s', continuing without.\n", colour);
945 return false; 1089 return false;
946 } 1090 }
947 1091
948 return true; 1092 return true;
949} 1093}
960 int old_width = szHint.width, old_height = szHint.height; 1104 int old_width = szHint.width, old_height = szHint.height;
961#endif 1105#endif
962 1106
963 window_calc (width, height); 1107 window_calc (width, height);
964 XSetWMNormalHints (display->display, TermWin.parent[0], &szHint); 1108 XSetWMNormalHints (display->display, TermWin.parent[0], &szHint);
1109
965 if (!ignoreparent) 1110 if (!ignoreparent)
966 { 1111 {
967#ifdef SMART_RESIZE 1112#ifdef SMART_RESIZE
968 /* 1113 /*
969 * resize by Marius Gedminas <marius.gedminas@uosis.mif.vu.lt> 1114 * resize by Marius Gedminas <marius.gedminas@uosis.mif.vu.lt>
1004 dy /= 2; 1149 dy /= 2;
1005 1150
1006 XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy, 1151 XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy,
1007 szHint.width, szHint.height); 1152 szHint.width, szHint.height);
1008#else 1153#else
1009 XResizeWindow (display->display, TermWin.parent[0], szHint.width, 1154 XResizeWindow (display->display, TermWin.parent[0], szHint.width, szHint.height);
1010 szHint.height);
1011#endif 1155#endif
1012
1013 } 1156 }
1014 1157
1015 fix_screen = (TermWin.ncol != prev_ncol 1158 fix_screen = TermWin.ncol != prev_ncol || TermWin.nrow != prev_nrow;
1016 || TermWin.nrow != prev_nrow);
1017 1159
1018 if (fix_screen || width != old_width || height != old_height) 1160 if (fix_screen || width != old_width || height != old_height)
1019 { 1161 {
1020 if (scrollbar_visible ()) 1162 if (scrollbar_visible ())
1021 { 1163 {
1022 XMoveResizeWindow (display->display, scrollBar.win, window_sb_x, 1164 XMoveResizeWindow (display->display, scrollBar.win,
1165 window_sb_x, 0,
1023 0, scrollbar_TotalWidth (), szHint.height); 1166 scrollbar_TotalWidth (), szHint.height);
1024 resize_scrollbar (); 1167 resize_scrollbar ();
1025 } 1168 }
1026 1169
1027 if (menubar_visible ()) 1170 if (menubar_visible ())
1028 XMoveResizeWindow (display->display, menuBar.win, window_vt_x, 1171 XMoveResizeWindow (display->display, menuBar.win,
1172 window_vt_x, 0,
1029 0, TermWin_TotalWidth (), menuBar_TotalHeight ()); 1173 TermWin_TotalWidth (), menuBar_TotalHeight ());
1030 1174
1031 XMoveResizeWindow (display->display, TermWin.vt, window_vt_x, 1175 XMoveResizeWindow (display->display, TermWin.vt,
1032 window_vt_y, TermWin_TotalWidth (), 1176 window_vt_x, window_vt_y,
1033 TermWin_TotalHeight ()); 1177 TermWin_TotalWidth (), TermWin_TotalHeight ());
1034 scr_clear (); 1178 scr_clear ();
1035#ifdef XPM_BACKGROUND 1179#ifdef XPM_BACKGROUND
1036 resize_pixmap (); 1180 resize_pixmap ();
1037#endif 1181#endif
1038
1039 } 1182 }
1040 1183
1041 if (fix_screen || old_height == 0) 1184 if (fix_screen || old_height == 0)
1042 { 1185 {
1043 int curr_screen = -1; 1186 int curr_screen = -1;
1316 if (preedit_attr) XFree (preedit_attr); 1459 if (preedit_attr) XFree (preedit_attr);
1317 if (status_attr) XFree (status_attr); 1460 if (status_attr) XFree (status_attr);
1318 1461
1319 if (Input_Context == NULL) 1462 if (Input_Context == NULL)
1320 { 1463 {
1321 rxvt_print_error ("failed to create input context"); 1464 rxvt_warn ("failed to create input context, continuing without XIM.\n");
1322 display->put_xim (input_method); 1465 display->put_xim (input_method);
1323 return false; 1466 return false;
1324 } 1467 }
1325 1468
1326 if (input_style & XIMPreeditArea) 1469 if (input_style & XIMPreeditArea)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines