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.39 by pcg, Sat Feb 21 22:14:00 2004 UTC vs.
Revision 1.70 by root, Mon Jul 26 18:01:19 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 PixColors;
128 248
129 displays.put (display); 249 displays.put (display);
130 250
131 scr_release (); 251 scr_release ();
132 252
253 /* clear all resources */
254 for (int i = 0; i < allocated.size (); i++)
255 free (allocated[i]);
256
257 free (selection.text);
258 // TODO: manage env vars in child only(!)
133 free (env_windowid); 259 free (env_windowid);
134 free (env_display); 260 free (env_display);
135 free (env_term); 261 free (env_term);
136 free (env_colorfgbg); 262 free (env_colorfgbg);
137 free (locale); 263 free (locale);
264#if 0
138 free (codeset); 265 free (codeset);
266#endif
139 267
140 delete envv; 268 delete envv;
141 delete argv; 269 delete argv;
142} 270}
143 271
167 cursor_blink_ev.stop (); 295 cursor_blink_ev.stop ();
168#endif 296#endif
169#ifdef TEXT_BLINK 297#ifdef TEXT_BLINK
170 text_blink_ev.stop (); 298 text_blink_ev.stop ();
171#endif 299#endif
300#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
301 cont_scroll_ev.stop ();
302#endif
303#ifdef SELECTION_SCROLLING
304 sel_scroll_ev.stop ();
305#endif
172#ifdef POINTER_BLANK 306#ifdef POINTER_BLANK
173 pointer_ev.stop (); 307 pointer_ev.stop ();
174#endif 308#endif
175 309
176 destroy_ev.start (0); 310 destroy_ev.start (0);
184 delete this; 318 delete this;
185} 319}
186 320
187/*----------------------------------------------------------------------*/ 321/*----------------------------------------------------------------------*/
188/* rxvt_init () */ 322/* 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 323bool
236rxvt_term::init (int argc, const char *const *argv) 324rxvt_term::init (int argc, const char *const *argv)
237{ 325{
326 SET_R (this);
327
328 if (!init_vars ())
329 return false;
330
238 /* 331 /*
239 * Save and then give up any super-user privileges 332 * Save and then give up any super-user privileges
240 * If we need privileges in any area then we must specifically request it. 333 * If we need privileges in any area then we must specifically request it.
241 * We should only need to be root in these cases: 334 * We should only need to be root in these cases:
242 * 1. write utmp entries on some systems 335 * 1. write utmp entries on some systems
249 342
250 const char **cmd_argv = init_resources (argc, argv); 343 const char **cmd_argv = init_resources (argc, argv);
251 344
252 set_locale (""); 345 set_locale ("");
253 346
254#if (MENUBAR_MAX) 347#if MENUBAR_MAX
255 menubar_read (rs[Rs_menu]); 348 menubar_read (rs[Rs_menu]);
256#endif 349#endif
257#ifdef HAVE_SCROLLBARS 350#ifdef HAVE_SCROLLBARS
258 if (Options & Opt_scrollBar) 351 if (Options & Opt_scrollBar)
259 scrollBar.setIdle (); /* set existence for size calculations */ 352 scrollBar.setIdle (); /* set existence for size calculations */
262 create_windows (argc, argv); 355 create_windows (argc, argv);
263 356
264 init_xlocale (); 357 init_xlocale ();
265 358
266 scr_reset (); /* initialize screen */ 359 scr_reset (); /* initialize screen */
267#ifdef RXVT_GRAPHICS
268 Gr_reset (); /* reset graphics */
269#endif
270 360
271#if 0 361#if 0
272 XSynchronize (display->display, True); 362 XSynchronize (display->display, True);
273#endif 363#endif
274 364
275#ifdef HAVE_SCROLLBARS 365#ifdef HAVE_SCROLLBARS
276 if (Options & Opt_scrollBar) 366 if (Options & Opt_scrollBar)
277 resize_scrollbar (); /* create and map scrollbar */ 367 resize_scrollbar (); /* create and map scrollbar */
278#endif 368#endif
279#if (MENUBAR_MAX) 369#if (MENUBAR_MAX)
280 if (menubar_visible (r)) 370 if (menubar_visible ())
281 XMapWindow (display->display, menuBar.win); 371 XMapWindow (display->display, menuBar.win);
282#endif 372#endif
283#ifdef TRANSPARENT 373#ifdef TRANSPARENT
284 if (Options & Opt_transparent) 374 if (Options & Opt_transparent)
285 { 375 {
298 pty_ev.start (cmd_fd, EVENT_READ); 388 pty_ev.start (cmd_fd, EVENT_READ);
299 389
300 check_ev.start (); 390 check_ev.start ();
301 391
302 return true; 392 return true;
393}
394
395static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event);
396
397void
398rxvt_init_signals ()
399{
400 /* install exit handler for cleanup */
401#if 0
402#ifdef HAVE_ATEXIT
403 atexit (rxvt_clean_exit);
404#else
405#endif
406#endif
407
408 struct sigaction sa;
409
410 sigfillset (&sa.sa_mask);
411 sa.sa_flags = SA_NOCLDSTOP | SA_RESTART;
412 sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0);
413 sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0);
414 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0);
415 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0);
416 sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0);
417 sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0);
418
419 /* need to trap SIGURG for SVR4 (Unixware) rlogin */
420 /* signal (SIGURG, SIG_DFL); */
421
422 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
423 //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler);
303} 424}
304 425
305/* ------------------------------------------------------------------------- * 426/* ------------------------------------------------------------------------- *
306 * SIGNAL HANDLING & EXIT HANDLER * 427 * SIGNAL HANDLING & EXIT HANDLER *
307 * ------------------------------------------------------------------------- */ 428 * ------------------------------------------------------------------------- */
308/* 429/*
309 * Catch a SIGCHLD signal and exit if the direct child has died 430 * Catch a SIGCHLD signal and exit if the direct child has died
310 */ 431 */
432
433void rxvt_term::child_exited (int pid)
434{
435 for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++)
436 if (pid == (*t)->cmd_pid)
437 {
438 (*t)->destroy ();
439 break;
440 }
441}
442
311/* ARGSUSED */ 443/* ARGSUSED */
312/* EXTPROTO */ 444/* EXTPROTO */
313RETSIGTYPE 445RETSIGTYPE
314rxvt_Child_signal (int sig __attribute__ ((unused))) 446rxvt_Child_signal (int sig __attribute__ ((unused)))
315{ 447{
316 int pid, save_errno = errno; 448 int pid, save_errno = errno;
449
317 while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR) 450 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0)
318 ; 451 rxvt_term::child_exited (pid);
452
319 errno = save_errno; 453 errno = save_errno;
320
321#if 0
322 if (pid == cmd_pid)
323 exit (EXIT_SUCCESS);
324#endif
325} 454}
326 455
327/* 456/*
328 * Catch a fatal signal and tidy up before quitting 457 * Catch a fatal signal and tidy up before quitting
329 */ 458 */
331RETSIGTYPE 460RETSIGTYPE
332rxvt_Exit_signal (int sig) 461rxvt_Exit_signal (int sig)
333{ 462{
334 signal (sig, SIG_DFL); 463 signal (sig, SIG_DFL);
335#ifdef DEBUG_CMD 464#ifdef DEBUG_CMD
336 rxvt_print_error ("signal %d", sig); 465 rxvt_warn ("caught signal %d, exiting.\n", sig);
337#endif 466#endif
338 rxvt_clean_exit (); 467 rxvt_clean_exit ();
339 kill (getpid (), sig); 468 kill (getpid (), sig);
340} 469}
341 470
379 508
380 p = malloc (size); 509 p = malloc (size);
381 if (p) 510 if (p)
382 return p; 511 return p;
383 512
384 fprintf (stderr, APL_NAME ": memory allocation failure. Aborting"); 513 fprintf (stderr, RESNAME ": memory allocation failure. Aborting");
385 rxvt_clean_exit (); 514 rxvt_clean_exit ();
386 exit (EXIT_FAILURE); 515 exit (EXIT_FAILURE);
387 /* NOTREACHED */ 516 /* NOTREACHED */
388} 517}
389 518
395 524
396 p = calloc (number, size); 525 p = calloc (number, size);
397 if (p) 526 if (p)
398 return p; 527 return p;
399 528
400 fprintf (stderr, APL_NAME ": memory allocation failure. Aborting"); 529 fprintf (stderr, RESNAME ": memory allocation failure. Aborting");
401 rxvt_clean_exit (); 530 rxvt_clean_exit ();
402 exit (EXIT_FAILURE); 531 exit (EXIT_FAILURE);
403 /* NOTREACHED */ 532 /* NOTREACHED */
404} 533}
405 534
414 else 543 else
415 p = malloc (size); 544 p = malloc (size);
416 if (p) 545 if (p)
417 return p; 546 return p;
418 547
419 fprintf (stderr, APL_NAME ": memory allocation failure. Aborting"); 548 fprintf (stderr, RESNAME ": memory allocation failure. Aborting");
420 rxvt_clean_exit (); 549 rxvt_clean_exit ();
421 exit (EXIT_FAILURE); 550 exit (EXIT_FAILURE);
422 /* NOTREACHED */ 551 /* NOTREACHED */
423} 552}
424 553
616 else 745 else
617 szHint.win_gravity = SouthWestGravity; 746 szHint.win_gravity = SouthWestGravity;
618 } 747 }
619 } 748 }
620 } 749 }
750
621 /* TODO: BOUNDS */ 751 /* TODO: BOUNDS */
622 TermWin.width = TermWin.ncol * TermWin.fwidth; 752 TermWin.width = TermWin.ncol * TermWin.fwidth;
623 TermWin.height = TermWin.nrow * TermWin.fheight; 753 TermWin.height = TermWin.nrow * TermWin.fheight;
624 max_width = MAX_COLS * TermWin.fwidth; 754 max_width = MAX_COLS * TermWin.fwidth;
625 max_height = MAX_ROWS * TermWin.fheight; 755 max_height = MAX_ROWS * TermWin.fheight;
626 756
627 szHint.base_width = szHint.base_height = 2 * TermWin.int_bwidth; 757 szHint.base_width = szHint.base_height = 2 * TermWin.int_bwidth;
628 758
629 sb_w = mb_h = 0; 759 sb_w = mb_h = 0;
630 window_vt_x = window_vt_y = 0; 760 window_vt_x = window_vt_y = TermWin.int_bwidth;
761
631 if (scrollbar_visible ()) 762 if (scrollbar_visible ())
632 { 763 {
633 sb_w = scrollbar_TotalWidth (); 764 sb_w = scrollbar_TotalWidth ();
634 szHint.base_width += sb_w; 765 szHint.base_width += sb_w;
635 if (! (Options & Opt_scrollBar_right)) 766 if (!(Options & Opt_scrollBar_right))
636 window_vt_x = sb_w; 767 window_vt_x += sb_w;
637 } 768 }
769
638 if (menubar_visible ()) 770 if (menubar_visible ())
639 { 771 {
640 mb_h = menuBar_TotalHeight (); 772 mb_h = menuBar_TotalHeight ();
641 szHint.base_height += mb_h; 773 szHint.base_height += mb_h;
642 window_vt_y = mb_h; 774 window_vt_y += mb_h;
643 } 775 }
776
644 szHint.width_inc = TermWin.fwidth; 777 szHint.width_inc = TermWin.fwidth;
645 szHint.height_inc = TermWin.fheight; 778 szHint.height_inc = TermWin.fheight;
646 szHint.min_width = szHint.base_width + szHint.width_inc; 779 szHint.min_width = szHint.base_width + szHint.width_inc;
647 szHint.min_height = szHint.base_height + szHint.height_inc; 780 szHint.min_height = szHint.base_height + szHint.height_inc;
648 781
654 else 787 else
655 { 788 {
656 MIN_IT (TermWin.width, max_width); 789 MIN_IT (TermWin.width, max_width);
657 szHint.width = szHint.base_width + TermWin.width; 790 szHint.width = szHint.base_width + TermWin.width;
658 } 791 }
792
659 if (height && height - szHint.base_height < max_height) 793 if (height && height - szHint.base_height < max_height)
660 { 794 {
661 szHint.height = height; 795 szHint.height = height;
662 TermWin.height = height - szHint.base_height; 796 TermWin.height = height - szHint.base_height;
663 } 797 }
664 else 798 else
665 { 799 {
666 MIN_IT (TermWin.height, max_height); 800 MIN_IT (TermWin.height, max_height);
667 szHint.height = szHint.base_height + TermWin.height; 801 szHint.height = szHint.base_height + TermWin.height;
668 } 802 }
803
669 if (scrollbar_visible () && (Options & Opt_scrollBar_right)) 804 if (scrollbar_visible () && (Options & Opt_scrollBar_right))
670 window_sb_x = szHint.width - sb_w; 805 window_sb_x = szHint.width - sb_w;
671 806
672 if (recalc_x) 807 if (recalc_x)
673 szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) 808 szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display))
718 * init = 1 - initialize 853 * init = 1 - initialize
719 * 854 *
720 * fontname == FONT_UP - switch to bigger font 855 * fontname == FONT_UP - switch to bigger font
721 * fontname == FONT_DN - switch to smaller font 856 * fontname == FONT_DN - switch to smaller font
722 */ 857 */
723void 858bool
724rxvt_term::change_font (int init, const char *fontname) 859rxvt_term::change_font (const char *fontname)
725{} 860{
861 if (fontname == FONT_UP)
862 {
863 // TODO
864 }
865 else if (fontname == FONT_DN)
866 {
867 // TODO
868 }
869 else
870 {
871 rxvt_fontset *fs = new rxvt_fontset (this);
726 872
727void 873 if (fs && fs->populate (fontname ? fontname : "fixed"))
874 {
875 delete TermWin.fontset;
876 TermWin.fontset = fs;
877 TermWin.fwidth = fs->base_font ()->width;
878 TermWin.fheight = fs->base_font ()->height;
879 TermWin.fbase = fs->base_font ()->ascent;
880
881 if (TermWin.parent[0])
882 {
883 resize_all_windows (0, 0, 0);
884 scr_remap_chars ();
885 scr_touch (true);
886 }
887
888 return true;
889 }
890 }
891
892 return false;
893}
894
895bool
728rxvt_term::font_up_down (int n, int direction) 896rxvt_term::font_up_down (int n, int direction)
729{} 897{
898 return false;
899}
730 900
731/*----------------------------------------------------------------------*/ 901/*----------------------------------------------------------------------*/
732/*----------------------------------------------------------------------*/ 902/*----------------------------------------------------------------------*/
733/* xterm sequences - title, iconName, color (exptl) */ 903/* xterm sequences - title, iconName, color (exptl) */
734void 904void
735rxvt_term::set_title (const char *str) 905rxvt_term::set_title (const char *str)
736{ 906{
737#ifndef SMART_WINDOW_TITLE 907#ifdef SMART_WINDOW_TITLE
738 XStoreName (display->display, TermWin.parent[0], str); 908 char *name;
739#else
740 char *name;
741 909
742 if (XFetchName (display->display, TermWin.parent[0], &name) == 0) 910 if (!XFetchName (display->display, TermWin.parent[0], &name))
743 name = NULL; 911 name = NULL;
912
744 if (name == NULL || STRCMP (name, str)) 913 if (name == NULL || STRCMP (name, str))
914#endif
745 XStoreName (display->display, TermWin.parent[0], str); 915 XStoreName (display->display, TermWin.parent[0], str);
916
917#ifdef SMART_WINDOW_TITLE
746 if (name) 918 if (name)
747 XFree (name); 919 XFree (name);
748#endif 920#endif
749} 921}
750 922
751void 923void
752rxvt_term::set_iconName (const char *str) 924rxvt_term::set_icon_name (const char *str)
753{ 925{
754#ifndef SMART_WINDOW_TITLE 926#ifdef SMART_WINDOW_TITLE
755 XSetIconName (display->display, TermWin.parent[0], str); 927 char *name;
756#else
757 char *name;
758 928
759 if (XGetIconName (display->display, TermWin.parent[0], &name)) 929 if (!XGetIconName (display->display, TermWin.parent[0], &name))
760 name = NULL; 930 name = NULL;
931
761 if (name == NULL || STRCMP (name, str)) 932 if (name == NULL || STRCMP (name, str))
933#endif
762 XSetIconName (display->display, TermWin.parent[0], str); 934 XSetIconName (display->display, TermWin.parent[0], str);
935
936#ifdef SMART_WINDOW_TITLE
763 if (name) 937 if (name)
764 XFree (name); 938 XFree (name);
765#endif 939#endif
766} 940}
767 941
768#ifdef XTERM_COLOR_CHANGE 942#ifdef XTERM_COLOR_CHANGE
769void 943void
770rxvt_term::set_window_color (int idx, const char *color) 944rxvt_term::set_window_color (int idx, const char *color)
771{ 945{
772 rxvt_color xcol; 946 rxvt_color xcol;
773 int i; 947 int i;
774 948
775 if (color == NULL || *color == '\0') 949 if (color == NULL || *color == '\0')
776 return; 950 return;
777 951
778 /* handle color aliases */ 952 /* handle color aliases */
794 PixColors[idx] = PixColors[minCOLOR + i]; 968 PixColors[idx] = PixColors[minCOLOR + i];
795 SET_PIXCOLOR (idx); 969 SET_PIXCOLOR (idx);
796 goto Done; 970 goto Done;
797 } 971 }
798 } 972 }
973
799 if (!rXParseAllocColor (& xcol, color)) 974 if (!rXParseAllocColor (& xcol, color))
800 return; 975 return;
976
801 /* XStoreColor (display->display, XCMAP, XColor*); */ 977 /* XStoreColor (display->display, XCMAP, XColor*); */
802 978
803 /* 979 /*
804 * FIXME: should free colors here, but no idea how to do it so instead, 980 * FIXME: should free colors here, but no idea how to do it so instead,
805 * so just keep gobbling up the colormap 981 * so just keep gobbling up the colormap
828 1004
829 /* handle Color_BD, scrollbar background, etc. */ 1005 /* handle Color_BD, scrollbar background, etc. */
830 1006
831 set_colorfgbg (); 1007 set_colorfgbg ();
832 recolour_cursor (); 1008 recolour_cursor ();
833 /* the only reasonable way to enforce a clean update */ 1009 scr_touch (true);
834 scr_poweron ();
835} 1010}
836 1011
837#else 1012#else
838# define set_window_color (idx,color) ((void)0) 1013# define set_window_color (idx,color) ((void)0)
839#endif /* XTERM_COLOR_CHANGE */ 1014#endif /* XTERM_COLOR_CHANGE */
840 1015
841void 1016void
842rxvt_term::recolour_cursor () 1017rxvt_term::recolour_cursor ()
843{ 1018{
844#if TODO
845 rxvt_color xcol[2]; 1019 XColor xcol[2];
846 1020
847 xcol[0] = PixColors[Color_pointer]; 1021 xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) ? PixColors[Color_pointer_fg] : PixColors[Color_fg];
848 xcol[1] = PixColors[Color_bg]; 1022 xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) ? PixColors[Color_pointer_bg] : PixColors[Color_bg];
849 XQueryColors (display->display, XCMAP, xcol, 2); 1023 XQueryColors (display->display, XCMAP, xcol, 2);
850 XRecolorCursor (display->display, TermWin_cursor, & (xcol[0]), & (xcol[1])); 1024 XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1);
851#endif
852} 1025}
853 1026
854/*----------------------------------------------------------------------*/ 1027/*----------------------------------------------------------------------*/
855/* 1028/*
856 * find if fg/bg matches any of the normal (low-intensity) colors 1029 * find if fg/bg matches any of the normal (low-intensity) colors
905int 1078int
906rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) 1079rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour)
907{ 1080{
908 if (!screen_in_out->set (display, colour)) 1081 if (!screen_in_out->set (display, colour))
909 { 1082 {
910 rxvt_print_error ("can't allocate colour: %s", colour); 1083 rxvt_warn ("can't get colour '%s', continuing without.\n", colour);
911 return false; 1084 return false;
912 } 1085 }
913 1086
914 return true; 1087 return true;
915} 1088}
926 int old_width = szHint.width, old_height = szHint.height; 1099 int old_width = szHint.width, old_height = szHint.height;
927#endif 1100#endif
928 1101
929 window_calc (width, height); 1102 window_calc (width, height);
930 XSetWMNormalHints (display->display, TermWin.parent[0], &szHint); 1103 XSetWMNormalHints (display->display, TermWin.parent[0], &szHint);
1104
931 if (!ignoreparent) 1105 if (!ignoreparent)
932 { 1106 {
933#ifdef SMART_RESIZE 1107#ifdef SMART_RESIZE
934 /* 1108 /*
935 * resize by Marius Gedminas <marius.gedminas@uosis.mif.vu.lt> 1109 * resize by Marius Gedminas <marius.gedminas@uosis.mif.vu.lt>
970 dy /= 2; 1144 dy /= 2;
971 1145
972 XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy, 1146 XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy,
973 szHint.width, szHint.height); 1147 szHint.width, szHint.height);
974#else 1148#else
975 XResizeWindow (display->display, TermWin.parent[0], szHint.width, 1149 XResizeWindow (display->display, TermWin.parent[0], szHint.width, szHint.height);
976 szHint.height);
977#endif 1150#endif
978
979 } 1151 }
980 1152
981 fix_screen = (TermWin.ncol != prev_ncol 1153 fix_screen = TermWin.ncol != prev_ncol || TermWin.nrow != prev_nrow;
982 || TermWin.nrow != prev_nrow);
983 1154
984 if (fix_screen || width != old_width || height != old_height) 1155 if (fix_screen || width != old_width || height != old_height)
985 { 1156 {
986 if (scrollbar_visible ()) 1157 if (scrollbar_visible ())
987 { 1158 {
988 XMoveResizeWindow (display->display, scrollBar.win, window_sb_x, 1159 XMoveResizeWindow (display->display, scrollBar.win,
1160 window_sb_x, 0,
989 0, scrollbar_TotalWidth (), szHint.height); 1161 scrollbar_TotalWidth (), szHint.height);
990 resize_scrollbar (); 1162 resize_scrollbar ();
991 } 1163 }
992 1164
993 if (menubar_visible ()) 1165 if (menubar_visible ())
994 XMoveResizeWindow (display->display, menuBar.win, window_vt_x, 1166 XMoveResizeWindow (display->display, menuBar.win,
1167 window_vt_x, 0,
995 0, TermWin_TotalWidth (), menuBar_TotalHeight ()); 1168 TermWin_TotalWidth (), menuBar_TotalHeight ());
996 1169
997 XMoveResizeWindow (display->display, TermWin.vt, window_vt_x, 1170 XMoveResizeWindow (display->display, TermWin.vt,
998 window_vt_y, TermWin_TotalWidth (), 1171 window_vt_x, window_vt_y,
999 TermWin_TotalHeight ()); 1172 TermWin_TotalWidth (), TermWin_TotalHeight ());
1000#ifdef RXVT_GRAPHICS
1001 if (old_height)
1002 Gr_Resize (old_width - szHint.base_width,
1003 old_height - szHint.base_height);
1004#endif
1005 scr_clear (); 1173 scr_clear ();
1006#ifdef XPM_BACKGROUND 1174#ifdef XPM_BACKGROUND
1007 resize_pixmap (); 1175 resize_pixmap ();
1008#endif 1176#endif
1009
1010 } 1177 }
1011 1178
1012 if (fix_screen || old_height == 0) 1179 if (fix_screen || old_height == 0)
1013 { 1180 {
1014 int curr_screen = -1; 1181 int curr_screen = -1;
1287 if (preedit_attr) XFree (preedit_attr); 1454 if (preedit_attr) XFree (preedit_attr);
1288 if (status_attr) XFree (status_attr); 1455 if (status_attr) XFree (status_attr);
1289 1456
1290 if (Input_Context == NULL) 1457 if (Input_Context == NULL)
1291 { 1458 {
1292 rxvt_print_error ("failed to create input context"); 1459 rxvt_warn ("failed to create input context, continuing without XIM.\n");
1293 display->put_xim (input_method); 1460 display->put_xim (input_method);
1294 return false; 1461 return false;
1295 } 1462 }
1296 1463
1297 if (input_style & XIMPreeditArea) 1464 if (input_style & XIMPreeditArea)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines