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.51 by pcg, Sat Mar 6 00:05:01 2004 UTC vs.
Revision 1.108 by root, Wed Aug 25 05:03:33 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);
58 } 61 return true;
59} 62}
60 63
64#if ENABLE_COMBINING
61class rxvt_composite_vec rxvt_composite; 65class rxvt_composite_vec rxvt_composite;
62 66
63text_t rxvt_composite_vec::compose (uint32_t c1, uint32_t c2) 67text_t rxvt_composite_vec::compose (unicode_t c1, unicode_t c2)
64{ 68{
65 compose_char *cc; 69 compose_char *cc;
66 70
67 // break compose chains, as stupid readline really likes to duplicate 71 // break compose chains, as stupid readline really likes to duplicate
68 // composing characters for some reason near the end of a line. 72 // composing characters for some reason near the end of a line.
94 v.push_back (compose_char (c1, c2)); 98 v.push_back (compose_char (c1, c2));
95 99
96 return v.size () - 1 + COMPOSE_LO; 100 return v.size () - 1 + COMPOSE_LO;
97} 101}
98 102
99int rxvt_composite_vec::expand (uint32_t c, wchar_t *r) 103int rxvt_composite_vec::expand (unicode_t c, wchar_t *r)
100{ 104{
101 compose_char *cc = (*this)[c]; 105 compose_char *cc = (*this)[c];
102 106
103 if (!cc) 107 if (!cc)
104 { 108 {
117 } 121 }
118 122
119 return len; 123 return len;
120 124
121} 125}
122 126#endif
123extern struct rxvt_composite_vec rxvt_composite;
124void *
125rxvt_term::operator new (size_t s)
126{
127 void *p = malloc (s);
128
129 MEMSET (p, 0, s);
130 return p;
131}
132
133void
134rxvt_term::operator delete (void *p, size_t s)
135{
136 free (p);
137}
138 127
139rxvt_term::rxvt_term () 128rxvt_term::rxvt_term ()
140 : 129 :
130#if TRANSPARENT
141 rootwin_ev (this, &rxvt_term::rootwin_cb), 131 rootwin_ev (this, &rxvt_term::rootwin_cb),
132#endif
133#ifdef HAVE_SCROLLBARS
134 scrollbar_ev (this, &rxvt_term::x_cb),
135#endif
136#ifdef MENUBAR
137 menubar_ev (this, &rxvt_term::x_cb),
138#endif
139#ifdef CURSOR_BLINK
140 cursor_blink_ev (this, &rxvt_term::cursor_blink_cb),
141#endif
142#ifdef TEXT_BLINK
143 text_blink_ev (this, &rxvt_term::text_blink_cb),
144#endif
145#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
146 cont_scroll_ev (this, &rxvt_term::cont_scroll_cb),
147#endif
148#ifdef SELECTION_SCROLLING
149 sel_scroll_ev (this, &rxvt_term::sel_scroll_cb),
150#endif
151#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
152 slip_wheel_ev (this, &rxvt_term::slip_wheel_cb),
153#endif
154#ifdef POINTER_BLANK
155 pointer_ev (this, &rxvt_term::pointer_cb),
156#endif
157#ifdef USE_XIM
158 im_ev (this, &rxvt_term::im_cb),
159#endif
142 termwin_ev (this, &rxvt_term::x_cb), 160 termwin_ev (this, &rxvt_term::x_cb),
143 vt_ev (this, &rxvt_term::x_cb), 161 vt_ev (this, &rxvt_term::x_cb),
144#ifdef HAVE_SCROLLBARS
145 scrollbar_ev (this, &rxvt_term::x_cb),
146#endif
147#ifdef MENUBAR
148 menubar_ev (this, &rxvt_term::x_cb),
149#endif
150#ifdef CURSOR_BLINK
151 cursor_blink_ev (this, &rxvt_term::cursor_blink_cb),
152#endif
153#ifdef TEXT_BLINK
154 text_blink_ev (this, &rxvt_term::text_blink_cb),
155#endif
156#ifdef POINTER_BLANK
157 pointer_ev (this, &rxvt_term::pointer_cb),
158#endif
159#ifdef USE_XIM
160 im_ev (this, &rxvt_term::im_cb),
161#endif
162 check_ev (this, &rxvt_term::check_cb), 162 check_ev (this, &rxvt_term::check_cb),
163 flush_ev (this, &rxvt_term::flush_cb),
163 destroy_ev (this, &rxvt_term::destroy_cb), 164 destroy_ev (this, &rxvt_term::destroy_cb),
164 pty_ev (this, &rxvt_term::pty_cb), 165 pty_ev (this, &rxvt_term::pty_cb),
165 incr_ev (this, &rxvt_term::incr_cb) 166 incr_ev (this, &rxvt_term::incr_cb)
166{ 167{
167 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; 168 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base;
169
170 termlist.push_back (this);
168} 171}
169 172
170rxvt_term::~rxvt_term () 173rxvt_term::~rxvt_term ()
171{ 174{
175 termlist.erase (find (termlist.begin (), termlist.end(), this));
176
172 if (cmd_fd >= 0) 177 if (cmd_pid)
173 close (cmd_fd); 178 kill (-cmd_pid, SIGHUP);
174 179
175#ifndef NO_SETOWNER_TTYDEV 180 pty.put ();
176 privileged_ttydev (RESTORE); 181
177#endif
178#ifdef UTMP_SUPPORT 182#ifdef UTMP_SUPPORT
179 privileged_utmp (RESTORE); 183 privileged_utmp (RESTORE);
180#endif 184#endif
181 185
186#if ENABLE_STYLES
187 for (int i = RS_styleCount; --i; )
188 if (TermWin.fontset[i] != TermWin.fontset[0])
189 delete TermWin.fontset[i];
190#endif
182 delete TermWin.fontset; 191 delete TermWin.fontset[0];
183 192
184 if (display) 193 if (display)
185 { 194 {
195 selection_clear ();
196
197#ifdef USE_XIM
198 im_destroy ();
199#endif
200#ifdef MENUBAR
201 if (menubarGC) XFreeGC (display->display, menubarGC);
202#endif
203#ifdef XTERM_SCROLLBAR
204 if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC);
205 if (ShadowGC) XFreeGC (display->display, ShadowGC);
206#endif
207#ifdef PLAIN_SCROLLBAR
208 if (pscrollbarGC) XFreeGC (display->display, pscrollbarGC);
209#endif
210#ifdef NEXT_SCROLLBAR
211 if (blackGC) XFreeGC (display->display, blackGC);
212 if (whiteGC) XFreeGC (display->display, whiteGC);
213 if (grayGC) XFreeGC (display->display, grayGC);
214 if (darkGC) XFreeGC (display->display, darkGC);
215 if (stippleGC) XFreeGC (display->display, stippleGC);
216 if (dimple) XFreePixmap (display->display, dimple);
217 if (upArrow) XFreePixmap (display->display, upArrow);
218 if (downArrow) XFreePixmap (display->display, downArrow);
219 if (upArrowHi) XFreePixmap (display->display, upArrowHi);
220 if (downArrowHi) XFreePixmap (display->display, downArrowHi);
221#endif
222#if defined(MENUBAR) || defined(RXVT_SCROLLBAR)
223 if (topShadowGC) XFreeGC (display->display, topShadowGC);
224 if (botShadowGC) XFreeGC (display->display, botShadowGC);
225 if (scrollbarGC) XFreeGC (display->display, scrollbarGC);
226#endif
227 if (TermWin.gc) XFreeGC (display->display, TermWin.gc);
228
186#if defined(MENUBAR) && (MENUBAR_MAX > 1) 229#if defined(MENUBAR) && (MENUBAR_MAX > 1)
187 delete menuBar.drawable; 230 delete menuBar.drawable;
188 //if (menuBar.win) 231 //if (menuBar.win)
189 // XDestroyWindow (display->display, menuBar.win); 232 // XDestroyWindow (display->display, menuBar.win);
190#endif 233#endif
194 XDestroyWindow (display->display, TermWin.parent[0]); 237 XDestroyWindow (display->display, TermWin.parent[0]);
195 } 238 }
196 239
197 // TODO: free pixcolours, colours should become part of rxvt_display 240 // TODO: free pixcolours, colours should become part of rxvt_display
198 241
199 delete PixColors; 242 delete pix_colors_focused;
243#ifdef OFF_FOCUS_FADING
244 delete pix_colors_unfocused;
245#endif
200 246
201 displays.put (display); 247 displays.put (display);
202 248
203 scr_release (); 249 scr_release ();
204 250
251 /* clear all resources */
252 for (int i = 0; i < allocated.size (); i++)
253 free (allocated[i]);
254
255 free (selection.text);
256 // TODO: manage env vars in child only(!)
205 free (env_windowid); 257 free (env_windowid);
206 free (env_display); 258 free (env_display);
207 free (env_term); 259 free (env_term);
208 free (env_colorfgbg); 260 free (env_colorfgbg);
209 free (locale); 261 free (locale);
262#if 0
210 free (codeset); 263 free (codeset);
264#endif
211 265
212 delete envv; 266 delete envv;
213 delete argv; 267 delete argv;
214} 268}
215 269
216void 270void
217rxvt_term::destroy () 271rxvt_term::destroy ()
218{ 272{
273 if (destroy_ev.active)
274 return;
275
276#if ENABLE_OVERLAY
277 scr_overlay_off ();
278#endif
279
219 if (display) 280 if (display)
220 { 281 {
282#if USE_XIM
283 im_ev.stop (display);
284#endif
285#if HAVE_SCROLLBARS
286 scrollbar_ev.stop (display);
287#endif
288#if MENUBAR
289 menubar_ev.stop (display);
290#endif
291#if TRANSPARENT
221 rootwin_ev.stop (display); 292 rootwin_ev.stop (display);
293#endif
294 incr_ev.stop ();
222 termwin_ev.stop (display); 295 termwin_ev.stop (display);
223 vt_ev.stop (display); 296 vt_ev.stop (display);
224#ifdef USE_XIM
225 im_destroy ();
226 im_ev.stop (display);
227#endif
228#ifdef HAVE_SCROLLBARS
229 scrollbar_ev.stop (display);
230#endif
231#ifdef MENUBAR
232 menubar_ev.stop (display);
233#endif
234 } 297 }
235 298
236 check_ev.stop (); 299 check_ev.stop ();
237 pty_ev.stop (); 300 pty_ev.stop ();
238#ifdef CURSOR_BLINK 301#ifdef CURSOR_BLINK
239 cursor_blink_ev.stop (); 302 cursor_blink_ev.stop ();
240#endif 303#endif
241#ifdef TEXT_BLINK 304#ifdef TEXT_BLINK
242 text_blink_ev.stop (); 305 text_blink_ev.stop ();
243#endif 306#endif
307#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
308 cont_scroll_ev.stop ();
309#endif
310#ifdef SELECTION_SCROLLING
311 sel_scroll_ev.stop ();
312#endif
244#ifdef POINTER_BLANK 313#ifdef POINTER_BLANK
245 pointer_ev.stop (); 314 pointer_ev.stop ();
246#endif 315#endif
247 316
248 destroy_ev.start (0); 317 destroy_ev.start (0);
256 delete this; 325 delete this;
257} 326}
258 327
259/*----------------------------------------------------------------------*/ 328/*----------------------------------------------------------------------*/
260/* rxvt_init () */ 329/* rxvt_init () */
261/* LIBPROTO */ 330bool
262rxvt_t
263rxvt_init (int argc, const char *const *argv) 331rxvt_term::init (int argc, const char *const *argv)
264{ 332{
265 SET_R (new rxvt_term); 333 SET_R (this);
266 334
267 if (!GET_R->init_vars () || !GET_R->init (argc, argv)) 335 if (!init_vars ())
268 { 336 return false;
269 delete GET_R; 337
270 SET_R (0); 338 init_secondary ();
339
340 const char **cmd_argv = init_resources (argc, argv);
341
342 set_locale ("");
343
344#if MENUBAR_MAX
345 menubar_read (rs[Rs_menu]);
346#endif
347#ifdef HAVE_SCROLLBARS
348 if (options & Opt_scrollBar)
349 scrollBar.setIdle (); /* set existence for size calculations */
350#endif
351
352 create_windows (argc, argv);
353
354 init_xlocale ();
355
356 scr_reset (); /* initialize screen */
357
358#if 0
359 XSynchronize (display->display, True);
360#endif
361
362#ifdef HAVE_SCROLLBARS
363 if (options & Opt_scrollBar)
364 resize_scrollbar (); /* create and map scrollbar */
365#endif
366#if (MENUBAR_MAX)
367 if (menubar_visible ())
368 XMapWindow (display->display, menuBar.win);
369#endif
370#ifdef TRANSPARENT
371 if (options & Opt_transparent)
271 } 372 {
373 XSelectInput (display->display, display->root, PropertyChangeMask);
374 check_our_parents ();
375 rootwin_ev.start (display, display->root);
376 }
377#endif
272 378
273 return GET_R; 379 XMapWindow (display->display, TermWin.vt);
380 XMapWindow (display->display, TermWin.parent[0]);
381
382 set_colorfgbg ();
383
384 init_command (cmd_argv);
385
386 pty_ev.start (pty.pty, EVENT_READ);
387
388 check_ev.start ();
389
390 return true;
274} 391}
275 392
276static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event); 393static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event);
277 394
278void 395void
279rxvt_init_signals () 396rxvt_init ()
280{ 397{
281 /* install exit handler for cleanup */ 398 /* install exit handler for cleanup */
282#if 0 399#if 0
283#ifdef HAVE_ATEXIT 400#ifdef HAVE_ATEXIT
284 atexit (rxvt_clean_exit); 401 atexit (rxvt_clean_exit);
285#else 402#else
286#endif 403#endif
287#endif 404#endif
405 /*
406 * Save and then give up any super-user privileges
407 * If we need privileges in any area then we must specifically request it.
408 * We should only need to be root in these cases:
409 * 1. write utmp entries on some systems
410 * 2. chown tty on some systems
411 */
412 rxvt_privileges (SAVE);
413 rxvt_privileges (IGNORE);
288 414
289 struct sigaction sa; 415 struct sigaction sa;
290 416
291 sigfillset (&sa.sa_mask); 417 sigfillset (&sa.sa_mask);
292 sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; 418 sa.sa_flags = SA_NOCLDSTOP | SA_RESTART;
302 428
303 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 429 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
304 //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); 430 //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler);
305} 431}
306 432
307bool
308rxvt_term::init (int argc, const char *const *argv)
309{
310 /*
311 * Save and then give up any super-user privileges
312 * If we need privileges in any area then we must specifically request it.
313 * We should only need to be root in these cases:
314 * 1. write utmp entries on some systems
315 * 2. chown tty on some systems
316 */
317 privileges (SAVE);
318 privileges (IGNORE);
319
320 init_secondary ();
321
322 const char **cmd_argv = init_resources (argc, argv);
323
324 set_locale ("");
325
326#if MENUBAR_MAX
327 menubar_read (rs[Rs_menu]);
328#endif
329#ifdef HAVE_SCROLLBARS
330 if (Options & Opt_scrollBar)
331 scrollBar.setIdle (); /* set existence for size calculations */
332#endif
333
334 create_windows (argc, argv);
335
336 init_xlocale ();
337
338 scr_reset (); /* initialize screen */
339
340#if 0
341 XSynchronize (display->display, True);
342#endif
343
344#ifdef HAVE_SCROLLBARS
345 if (Options & Opt_scrollBar)
346 resize_scrollbar (); /* create and map scrollbar */
347#endif
348#if (MENUBAR_MAX)
349 if (menubar_visible ())
350 XMapWindow (display->display, menuBar.win);
351#endif
352#ifdef TRANSPARENT
353 if (Options & Opt_transparent)
354 {
355 XSelectInput (display->display, display->root, PropertyChangeMask);
356 check_our_parents ();
357 }
358#endif
359
360 rootwin_ev.start (display, display->root);
361
362 XMapWindow (display->display, TermWin.vt);
363 XMapWindow (display->display, TermWin.parent[0]);
364
365 init_command (cmd_argv);
366
367 pty_ev.start (cmd_fd, EVENT_READ);
368
369 check_ev.start ();
370
371 return true;
372}
373
374/* ------------------------------------------------------------------------- * 433/* ------------------------------------------------------------------------- *
375 * SIGNAL HANDLING & EXIT HANDLER * 434 * SIGNAL HANDLING & EXIT HANDLER *
376 * ------------------------------------------------------------------------- */ 435 * ------------------------------------------------------------------------- */
377/* 436/*
378 * Catch a SIGCHLD signal and exit if the direct child has died 437 * Catch a SIGCHLD signal and exit if the direct child has died
379 */ 438 */
439
440void rxvt_term::child_exited (int pid)
441{
442 for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++)
443 if (pid == (*t)->cmd_pid)
444 {
445 (*t)->destroy ();
446 break;
447 }
448}
449
380/* ARGSUSED */ 450/* ARGSUSED */
381/* EXTPROTO */ 451/* INTPROTO */
382RETSIGTYPE 452RETSIGTYPE
383rxvt_Child_signal (int sig __attribute__ ((unused))) 453rxvt_Child_signal (int sig __attribute__ ((unused)))
384{ 454{
385 int pid, save_errno = errno; 455 int pid, save_errno = errno;
456
386 while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR) 457 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0)
387 ; 458 rxvt_term::child_exited (pid);
459
388 errno = save_errno; 460 errno = save_errno;
389
390#if 0
391 if (pid == cmd_pid)
392 exit (EXIT_SUCCESS);
393#endif
394} 461}
395 462
396/* 463/*
397 * Catch a fatal signal and tidy up before quitting 464 * Catch a fatal signal and tidy up before quitting
398 */ 465 */
399/* EXTPROTO */ 466/* INTPROTO */
400RETSIGTYPE 467RETSIGTYPE
401rxvt_Exit_signal (int sig) 468rxvt_Exit_signal (int sig)
402{ 469{
403 signal (sig, SIG_DFL); 470 signal (sig, SIG_DFL);
404#ifdef DEBUG_CMD 471#ifdef DEBUG_CMD
405 rxvt_print_error ("signal %d", sig); 472 rxvt_warn ("caught signal %d, exiting.\n", sig);
406#endif 473#endif
407 rxvt_clean_exit (); 474 rxvt_clean_exit ();
408 kill (getpid (), sig); 475 kill (getpid (), sig);
409} 476}
410 477
426/*----------------------------------------------------------------------*/ 493/*----------------------------------------------------------------------*/
427/* 494/*
428 * Exit gracefully, clearing the utmp entry and restoring tty attributes 495 * Exit gracefully, clearing the utmp entry and restoring tty attributes
429 * TODO: if debugging, this should free up any known resources if we can 496 * TODO: if debugging, this should free up any known resources if we can
430 */ 497 */
431/* EXTPROTO */ 498/* INTPROTO */
432void 499void
433rxvt_clean_exit () 500rxvt_clean_exit ()
434{ 501{
435 // TODO: rxvtd should clean up all ressources 502 // TODO: rxvtd should clean up all ressources
436 if (GET_R) 503 if (GET_R)
438} 505}
439 506
440/* ------------------------------------------------------------------------- * 507/* ------------------------------------------------------------------------- *
441 * MEMORY ALLOCATION WRAPPERS * 508 * MEMORY ALLOCATION WRAPPERS *
442 * ------------------------------------------------------------------------- */ 509 * ------------------------------------------------------------------------- */
443/* EXTPROTO */ 510/* INTPROTO */
444void * 511void *
445rxvt_malloc (size_t size) 512rxvt_malloc (size_t size)
446{ 513{
447 void *p; 514 void *p;
448 515
449 p = malloc (size); 516 p = malloc (size);
450 if (p) 517 if (p)
451 return p; 518 return p;
452 519
453 fprintf (stderr, RESNAME ": memory allocation failure. Aborting"); 520 rxvt_fatal ("memory allocation failure. aborting.\n");
454 rxvt_clean_exit ();
455 exit (EXIT_FAILURE);
456 /* NOTREACHED */ 521 /* NOTREACHED */
457} 522}
458 523
459/* EXTPROTO */ 524/* INTPROTO */
460void * 525void *
461rxvt_calloc (size_t number, size_t size) 526rxvt_calloc (size_t number, size_t size)
462{ 527{
463 void *p; 528 void *p;
464 529
465 p = calloc (number, size); 530 p = calloc (number, size);
466 if (p) 531 if (p)
467 return p; 532 return p;
468 533
469 fprintf (stderr, RESNAME ": memory allocation failure. Aborting"); 534 rxvt_fatal ("memory allocation failure. aborting.\n");
470 rxvt_clean_exit ();
471 exit (EXIT_FAILURE);
472 /* NOTREACHED */ 535 /* NOTREACHED */
473} 536}
474 537
475/* EXTPROTO */ 538/* INTPROTO */
476void * 539void *
477rxvt_realloc (void *ptr, size_t size) 540rxvt_realloc (void *ptr, size_t size)
478{ 541{
479 void *p; 542 void *p;
480 543
481 if (ptr) 544 if (ptr)
482 p = realloc (ptr, size); 545 p = realloc (ptr, size);
483 else 546 else
484 p = malloc (size); 547 p = malloc (size);
548
485 if (p) 549 if (p)
486 return p; 550 return p;
487 551
488 fprintf (stderr, RESNAME ": memory allocation failure. Aborting"); 552 rxvt_fatal ("memory allocation failure. aborting.\n");
489 rxvt_clean_exit ();
490 exit (EXIT_FAILURE);
491 /* NOTREACHED */ 553 /* NOTREACHED */
492} 554}
493 555
494/* ------------------------------------------------------------------------- * 556/* ------------------------------------------------------------------------- *
495 * PRIVILEGED OPERATIONS * 557 * PRIVILEGED OPERATIONS *
496 * ------------------------------------------------------------------------- */ 558 * ------------------------------------------------------------------------- */
497/* take care of suid/sgid super-user (root) privileges */ 559/* take care of suid/sgid super-user (root) privileges */
498void 560void
499rxvt_term::privileges (int mode) 561rxvt_privileges (rxvt_privaction action)
500{ 562{
563#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
564 static uid_t euid;
565 static gid_t egid;
566#endif
567
501#if ! defined(__CYGWIN32__) 568#if ! defined(__CYGWIN32__)
502# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) 569# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID)
503 /* setreuid () is the poor man's setuid (), seteuid () */ 570 /* setreuid () is the poor man's setuid (), seteuid () */
504# define seteuid(a) setreuid(-1, (a)) 571# define seteuid(a) setreuid(-1, (a))
505# define setegid(a) setregid(-1, (a)) 572# define setegid(a) setregid(-1, (a))
506# define HAVE_SETEUID 573# define HAVE_SETEUID
507# endif 574# endif
508# ifdef HAVE_SETEUID 575# ifdef HAVE_SETEUID
509 switch (mode) 576 switch (action)
510 { 577 {
511 case IGNORE: 578 case IGNORE:
512 /* 579 /*
513 * change effective uid/gid - not real uid/gid - so we can switch 580 * change effective uid/gid - not real uid/gid - so we can switch
514 * back to root later, as required 581 * back to root later, as required
524 seteuid (euid); 591 seteuid (euid);
525 setegid (egid); 592 setegid (egid);
526 break; 593 break;
527 } 594 }
528# else 595# else
529 switch (mode) 596 switch (action)
530 { 597 {
531 case IGNORE: 598 case IGNORE:
532 setuid (getuid ()); 599 setuid (getuid ());
533 setgid (getgid ()); 600 setgid (getgid ());
534 /* FALLTHROUGH */ 601 /* FALLTHROUGH */
541#endif 608#endif
542} 609}
543 610
544#ifdef UTMP_SUPPORT 611#ifdef UTMP_SUPPORT
545void 612void
546rxvt_term::privileged_utmp (char action) 613rxvt_term::privileged_utmp (rxvt_privaction action)
547{ 614{
548 D_MAIN ((stderr, "rxvt_privileged_utmp (%c); waiting for: %c (pid: %d)",
549 action, next_utmp_action, getpid ()));
550 if (next_utmp_action != action || (action != SAVE && action != RESTORE)
551 || (Options & Opt_utmpInhibit) 615 if ((options & Opt_utmpInhibit)
552 || ttydev == NULL || *ttydev == '\0') 616 || !pty.name || !*pty.name)
553 return; 617 return;
554 618
555 privileges (RESTORE); 619 rxvt_privileges (RESTORE);
620
556 if (action == SAVE) 621 if (action == SAVE)
557 {
558 next_utmp_action = RESTORE;
559 makeutent (ttydev, rs[Rs_display_name]); 622 makeutent (pty.name, rs[Rs_display_name]);
560 }
561 else 623 else
562 { /* action == RESTORE */
563 next_utmp_action = IGNORE;
564 cleanutent (); 624 cleanutent ();
565 } 625
566 privileges (IGNORE); 626 rxvt_privileges (IGNORE);
567}
568#endif
569
570#ifndef NO_SETOWNER_TTYDEV
571void
572rxvt_term::privileged_ttydev (char action)
573{
574 D_MAIN ((stderr,
575 "privileged_ttydev (%c); waiting for: %c (pid: %d)",
576 action, next_tty_action, getpid ()));
577 if (next_tty_action != action || (action != SAVE && action != RESTORE)
578 || ttydev == NULL || *ttydev == '\0')
579 return;
580
581 privileges (RESTORE);
582
583 if (action == SAVE)
584 {
585 next_tty_action = RESTORE;
586# ifndef RESET_TTY_TO_COMMON_DEFAULTS
587 /* store original tty status for restoration rxvt_clean_exit () -- rgg 04/12/95 */
588 if (lstat (ttydev, &ttyfd_stat) < 0) /* you lose out */
589 next_tty_action = IGNORE;
590 else
591# endif
592
593 {
594 chown (ttydev, getuid (), ttygid); /* fail silently */
595 chmod (ttydev, ttymode);
596# ifdef HAVE_REVOKE
597 revoke (ttydev);
598# endif
599
600 }
601 }
602 else
603 { /* action == RESTORE */
604 next_tty_action = IGNORE;
605# ifndef RESET_TTY_TO_COMMON_DEFAULTS
606 chmod (ttydev, ttyfd_stat.st_mode);
607 chown (ttydev, ttyfd_stat.st_uid, ttyfd_stat.st_gid);
608# else
609 chmod (ttydev,
610 (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH));
611 chown (ttydev, 0, 0);
612# endif
613
614 }
615
616 privileges (IGNORE);
617
618# ifndef RESET_TTY_TO_COMMON_DEFAULTS
619 D_MAIN ((stderr, "%s \"%s\": mode %03o, uid %d, gid %d",
620 action == RESTORE ? "Restoring" : (action ==
621 SAVE ? "Saving" :
622 "UNKNOWN ERROR for"), ttydev,
623 ttyfd_stat.st_mode, ttyfd_stat.st_uid,
624 ttyfd_stat.st_gid));
625# endif
626} 627}
627#endif 628#endif
628 629
629/*----------------------------------------------------------------------*/ 630/*----------------------------------------------------------------------*/
630/* 631/*
685 else 686 else
686 szHint.win_gravity = SouthWestGravity; 687 szHint.win_gravity = SouthWestGravity;
687 } 688 }
688 } 689 }
689 } 690 }
691
690 /* TODO: BOUNDS */ 692 /* TODO: BOUNDS */
691 TermWin.width = TermWin.ncol * TermWin.fwidth; 693 TermWin.width = TermWin.ncol * TermWin.fwidth;
692 TermWin.height = TermWin.nrow * TermWin.fheight; 694 TermWin.height = TermWin.nrow * TermWin.fheight;
693 max_width = MAX_COLS * TermWin.fwidth; 695 max_width = MAX_COLS * TermWin.fwidth;
694 max_height = MAX_ROWS * TermWin.fheight; 696 max_height = MAX_ROWS * TermWin.fheight;
695 697
696 szHint.base_width = szHint.base_height = 2 * TermWin.int_bwidth; 698 szHint.base_width = szHint.base_height = 2 * TermWin.int_bwidth;
697 699
698 sb_w = mb_h = 0; 700 sb_w = mb_h = 0;
699 window_vt_x = window_vt_y = 0; 701 window_vt_x = window_vt_y = TermWin.int_bwidth;
702
700 if (scrollbar_visible ()) 703 if (scrollbar_visible ())
701 { 704 {
702 sb_w = scrollbar_TotalWidth (); 705 sb_w = scrollbar_TotalWidth ();
703 szHint.base_width += sb_w; 706 szHint.base_width += sb_w;
704 if (! (Options & Opt_scrollBar_right)) 707 if (!(options & Opt_scrollBar_right))
705 window_vt_x = sb_w; 708 window_vt_x += sb_w;
706 } 709 }
710
707 if (menubar_visible ()) 711 if (menubar_visible ())
708 { 712 {
709 mb_h = menuBar_TotalHeight (); 713 mb_h = menuBar_TotalHeight ();
710 szHint.base_height += mb_h; 714 szHint.base_height += mb_h;
711 window_vt_y = mb_h; 715 window_vt_y += mb_h;
712 } 716 }
717
713 szHint.width_inc = TermWin.fwidth; 718 szHint.width_inc = TermWin.fwidth;
714 szHint.height_inc = TermWin.fheight; 719 szHint.height_inc = TermWin.fheight;
715 szHint.min_width = szHint.base_width + szHint.width_inc; 720 szHint.min_width = szHint.base_width + szHint.width_inc;
716 szHint.min_height = szHint.base_height + szHint.height_inc; 721 szHint.min_height = szHint.base_height + szHint.height_inc;
717 722
723 else 728 else
724 { 729 {
725 MIN_IT (TermWin.width, max_width); 730 MIN_IT (TermWin.width, max_width);
726 szHint.width = szHint.base_width + TermWin.width; 731 szHint.width = szHint.base_width + TermWin.width;
727 } 732 }
733
728 if (height && height - szHint.base_height < max_height) 734 if (height && height - szHint.base_height < max_height)
729 { 735 {
730 szHint.height = height; 736 szHint.height = height;
731 TermWin.height = height - szHint.base_height; 737 TermWin.height = height - szHint.base_height;
732 } 738 }
733 else 739 else
734 { 740 {
735 MIN_IT (TermWin.height, max_height); 741 MIN_IT (TermWin.height, max_height);
736 szHint.height = szHint.base_height + TermWin.height; 742 szHint.height = szHint.base_height + TermWin.height;
737 } 743 }
744
738 if (scrollbar_visible () && (Options & Opt_scrollBar_right)) 745 if (scrollbar_visible () && (options & Opt_scrollBar_right))
739 window_sb_x = szHint.width - sb_w; 746 window_sb_x = szHint.width - sb_w;
740 747
741 if (recalc_x) 748 if (recalc_x)
742 szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) 749 szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display))
743 - szHint.width - 2 * TermWin.ext_bwidth); 750 - szHint.width - 2 * TermWin.ext_bwidth);
759 * Called after a window size change. 766 * Called after a window size change.
760 */ 767 */
761void 768void
762rxvt_term::tt_winch () 769rxvt_term::tt_winch ()
763{ 770{
771 if (pty.pty < 0)
772 return;
773
764 struct winsize ws; 774 struct winsize ws;
765
766 if (cmd_fd < 0)
767 return;
768 775
769 ws.ws_col = TermWin.ncol; 776 ws.ws_col = TermWin.ncol;
770 ws.ws_row = TermWin.nrow; 777 ws.ws_row = TermWin.nrow;
771 ws.ws_xpixel = ws.ws_ypixel = 0; 778 ws.ws_xpixel = TermWin.width;
772#ifndef DEBUG_SIZE 779 ws.ws_ypixel = TermWin.height;
773 (void)ioctl (cmd_fd, TIOCSWINSZ, &ws); 780 (void)ioctl (pty.pty, TIOCSWINSZ, &ws);
774#else 781
775 if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0) 782#if 0
776 D_SIZE ((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); 783 // TIOCSWINSZ⎈ is supposed to do this automatically and correctly
777# ifdef SIGWINCH
778 else if (cmd_pid) /* force through to the command */ 784 if (cmd_pid) /* force through to the command */
779 kill (cmd_pid, SIGWINCH); 785 kill (cmd_pid, SIGWINCH);
780# endif
781#endif 786#endif
782} 787}
783 788
784/*----------------------------------------------------------------------*/ 789/*----------------------------------------------------------------------*/
785/* rxvt_change_font () - Switch to a new font */ 790/* set_fonts () - load and set the various fonts
786/* 791/*
787 * init = 1 - initialize 792 * init = 1 - initialize
788 * 793 *
789 * fontname == FONT_UP - switch to bigger font 794 * fontname == FONT_UP - switch to bigger font
790 * fontname == FONT_DN - switch to smaller font 795 * fontname == FONT_DN - switch to smaller font
791 */ 796 */
792bool 797bool
793rxvt_term::change_font (const char *fontname) 798rxvt_term::set_fonts ()
794{ 799{
795 if (fontname == FONT_UP)
796 {
797 // TODO
798 }
799 else if (fontname == FONT_DN)
800 {
801 // TODO
802 }
803 else
804 {
805 rxvt_fontset *fs = new rxvt_fontset (this); 800 rxvt_fontset *fs = new rxvt_fontset (this);
801 rxvt_fontprop prop;
806 802
807 if (fs && fs->populate (fontname ? fontname : "fixed")) 803 prop.width = prop.height = prop.weight = prop.slant
804 = rxvt_fontprop::unset;
805
806 if (!fs
807 || !fs->populate (rs[Rs_font] ? rs[Rs_font] : "fixed", prop)
808 || !fs->realize_font (1))
809 {
810 delete fs;
811 return false;
812 }
813
814#if ENABLE_STYLES
815 for (int i = RS_styleCount; --i; )
816 if (TermWin.fontset[i] != TermWin.fontset[0])
817 delete TermWin.fontset[i];
818#endif
819
820 delete TermWin.fontset[0];
821 TermWin.fontset[0] = fs;
822
823 fs->prop = prop = (*fs)[1]->properties ();
824
825 TermWin.fwidth = prop.width;
826 TermWin.fheight = prop.height;
827 TermWin.fweight = prop.weight;
828 TermWin.fslant = prop.slant;
829 TermWin.fbase = (*fs)[1]->ascent;
830
831 for (int style = 1; style < 4; style++)
832 {
833#if ENABLE_STYLES
834 const char *res = rs[Rs_font + style];
835
836 if (res && !*res)
837 TermWin.fontset[style] = TermWin.fontset[0];
838 else
808 { 839 {
809 delete TermWin.fontset; 840 TermWin.fontset[style] = fs = new rxvt_fontset (this);
810 TermWin.fontset = fs; 841 rxvt_fontprop prop2 = prop;
811 TermWin.fwidth = fs->base_font ()->width;
812 TermWin.fheight = fs->base_font ()->height;
813 TermWin.fbase = fs->base_font ()->ascent;
814 842
815 if (TermWin.parent[0]) 843 if (res)
844 prop2.weight = prop2.slant = rxvt_fontprop::unset;
845 else
816 { 846 {
817 resize_all_windows (0, 0, 0); 847 res = TermWin.fontset[0]->fontdesc;
818 scr_remap_chars (); 848
819 scr_touch (true); 849 if (SET_STYLE (0, style) & RS_Bold) prop2.weight = rxvt_fontprop::bold;
850 if (SET_STYLE (0, style) & RS_Italic) prop2.slant = rxvt_fontprop::italic;
820 } 851 }
821 852
822 return true; 853 fs->populate (res, prop2);
823 } 854 }
855#else
856 TermWin.fontset[style] = TermWin.fontset[0];
857#endif
858 }
859
860 if (TermWin.parent[0])
824 } 861 {
862 resize_all_windows (0, 0, 0);
863 scr_remap_chars ();
864 scr_touch (true);
865 }
825 866
826 return false; 867 return true;
827}
828
829bool
830rxvt_term::font_up_down (int n, int direction)
831{
832 return false;
833} 868}
834 869
835/*----------------------------------------------------------------------*/ 870/*----------------------------------------------------------------------*/
836/*----------------------------------------------------------------------*/ 871/*----------------------------------------------------------------------*/
837/* xterm sequences - title, iconName, color (exptl) */ 872/* xterm sequences - title, iconName, color (exptl) */
838void 873void
839rxvt_term::set_title (const char *str) 874rxvt_term::set_title (const char *str)
840{ 875{
841#ifndef SMART_WINDOW_TITLE 876#ifdef SMART_WINDOW_TITLE
842 XStoreName (display->display, TermWin.parent[0], str);
843#else
844 char *name; 877 char *name;
845 878
846 if (XFetchName (display->display, TermWin.parent[0], &name) == 0) 879 if (!XFetchName (display->display, TermWin.parent[0], &name))
847 name = NULL; 880 name = NULL;
881
848 if (name == NULL || STRCMP (name, str)) 882 if (name == NULL || strcmp (name, str))
883#endif
849 XStoreName (display->display, TermWin.parent[0], str); 884 XStoreName (display->display, TermWin.parent[0], str);
885
886#ifdef SMART_WINDOW_TITLE
850 if (name) 887 if (name)
851 XFree (name); 888 XFree (name);
852#endif 889#endif
853} 890}
854 891
855void 892void
856rxvt_term::set_iconName (const char *str) 893rxvt_term::set_icon_name (const char *str)
857{ 894{
858#ifndef SMART_WINDOW_TITLE 895#ifdef SMART_WINDOW_TITLE
859 XSetIconName (display->display, TermWin.parent[0], str);
860#else
861 char *name; 896 char *name;
862 897
863 if (XGetIconName (display->display, TermWin.parent[0], &name)) 898 if (!XGetIconName (display->display, TermWin.parent[0], &name))
864 name = NULL; 899 name = NULL;
900
865 if (name == NULL || STRCMP (name, str)) 901 if (name == NULL || strcmp (name, str))
902#endif
866 XSetIconName (display->display, TermWin.parent[0], str); 903 XSetIconName (display->display, TermWin.parent[0], str);
904
905#ifdef SMART_WINDOW_TITLE
867 if (name) 906 if (name)
868 XFree (name); 907 XFree (name);
869#endif 908#endif
870} 909}
871 910
885 i = atoi (color); 924 i = atoi (color);
886 if (i >= 8 && i <= 15) 925 if (i >= 8 && i <= 15)
887 { /* bright colors */ 926 { /* bright colors */
888 i -= 8; 927 i -= 8;
889# ifndef NO_BRIGHTCOLOR 928# ifndef NO_BRIGHTCOLOR
890 PixColors[idx] = PixColors[minBrightCOLOR + i]; 929 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i];
891 SET_PIXCOLOR (idx); 930 SET_PIXCOLOR (idx);
892 goto Done; 931 goto Done;
893# endif 932# endif
894 933
895 } 934 }
896 if (i >= 0 && i <= 7) 935 if (i >= 0 && i <= 7)
897 { /* normal colors */ 936 { /* normal colors */
898 PixColors[idx] = PixColors[minCOLOR + i]; 937 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i];
899 SET_PIXCOLOR (idx); 938 SET_PIXCOLOR (idx);
900 goto Done; 939 goto Done;
901 } 940 }
902 } 941 }
942
903 if (!rXParseAllocColor (& xcol, color)) 943 if (!rXParseAllocColor (& xcol, color))
904 return; 944 return;
945
905 /* XStoreColor (display->display, XCMAP, XColor*); */ 946 /* XStoreColor (display->display, display->cmap, XColor*); */
906 947
907 /* 948 /*
908 * FIXME: should free colors here, but no idea how to do it so instead, 949 * FIXME: should free colors here, but no idea how to do it so instead,
909 * so just keep gobbling up the colormap 950 * so just keep gobbling up the colormap
910 */ 951 */
911# if 0 952# if 0
912 for (i = Color_Black; i <= Color_White; i++) 953 for (i = Color_Black; i <= Color_White; i++)
913 if (PixColors[idx] == PixColors[i]) 954 if (pix_colors[idx] == pix_colors[i])
914 break; 955 break;
915 if (i > Color_White) 956 if (i > Color_White)
916 { 957 {
917 /* fprintf (stderr, "XFreeColors: PixColors [%d] = %lu\n", idx, PixColors [idx]); */ 958 /* fprintf (stderr, "XFreeColors: pix_colors [%d] = %lu\n", idx, pix_colors [idx]); */
918 XFreeColors (display->display, XCMAP, (PixColors + idx), 1, 959 XFreeColors (display->display, display->cmap, (pix_colors + idx), 1,
919 DisplayPlanes (display->display, display->screen)); 960 DisplayPlanes (display->display, display->screen));
920 } 961 }
921# endif 962# endif
922 963
923 PixColors[idx] = xcol; 964 pix_colors_focused[idx] = xcol;
924 SET_PIXCOLOR (idx); 965 SET_PIXCOLOR (idx);
925 966
926 /* XSetWindowAttributes attr; */ 967 /* XSetWindowAttributes attr; */
927 /* Cursor cursor; */ 968 /* Cursor cursor; */
928Done: 969Done:
929 if (idx == Color_bg && ! (Options & Opt_transparent)) 970#ifdef OFF_FOCUS_FADING
930 XSetWindowBackground (display->display, TermWin.vt, 971 if (rs[Rs_fade])
931 PixColors[Color_bg]); 972 pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade]));
973#endif
932 974
933 /* handle Color_BD, scrollbar background, etc. */ 975 /*TODO: handle Color_BD, scrollbar background, etc. */
934 976
935 set_colorfgbg ();
936 recolour_cursor (); 977 recolour_cursor ();
937 /* the only reasonable way to enforce a clean update */ 978 scr_recolour ();
938 scr_poweron ();
939} 979}
940 980
941#else 981#else
942# define set_window_color (idx,color) ((void)0) 982# define set_window_color (idx,color) ((void)0)
943#endif /* XTERM_COLOR_CHANGE */ 983#endif /* XTERM_COLOR_CHANGE */
944 984
945void 985void
946rxvt_term::recolour_cursor () 986rxvt_term::recolour_cursor ()
947{ 987{
948#if TODO
949 rxvt_color xcol[2]; 988 XColor xcol[2];
950 989
951 xcol[0] = PixColors[Color_pointer]; 990 xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg)
952 xcol[1] = PixColors[Color_bg]; 991 ? pix_colors_focused[Color_pointer_fg]
992 : pix_colors_focused[Color_fg];
993 xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg)
994 ? pix_colors_focused[Color_pointer_bg]
995 : pix_colors_focused[Color_bg];
996
953 XQueryColors (display->display, XCMAP, xcol, 2); 997 XQueryColors (display->display, display->cmap, xcol, 2);
954 XRecolorCursor (display->display, TermWin_cursor, & (xcol[0]), & (xcol[1])); 998 XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1);
955#endif
956} 999}
957 1000
958/*----------------------------------------------------------------------*/ 1001/*----------------------------------------------------------------------*/
959/* 1002/*
960 * find if fg/bg matches any of the normal (low-intensity) colors 1003 * find if fg/bg matches any of the normal (low-intensity) colors
961 */ 1004 */
962void 1005void
963rxvt_term::set_colorfgbg () 1006rxvt_term::set_colorfgbg ()
964{ 1007{
965 unsigned int i; 1008 unsigned int i;
966 const char *xpmb = "\0"; 1009 const char *xpmb = "\0";
967 char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1]; 1010 char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1];
968 1011
969 env_colorfgbg =
970 (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1); 1012 env_colorfgbg = (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1);
971 STRCPY (fstr, "default"); 1013 strcpy (fstr, "default");
972 STRCPY (bstr, "default"); 1014 strcpy (bstr, "default");
973 for (i = Color_Black; i <= Color_White; i++) 1015 for (i = Color_Black; i <= Color_White; i++)
974 if (PixColors[Color_fg] == PixColors[i]) 1016 if (pix_colors[Color_fg] == pix_colors[i])
975 { 1017 {
976 sprintf (fstr, "%d", (i - Color_Black)); 1018 sprintf (fstr, "%d", (i - Color_Black));
977 break; 1019 break;
978 } 1020 }
1021
979 for (i = Color_Black; i <= Color_White; i++) 1022 for (i = Color_Black; i <= Color_White; i++)
980 if (PixColors[Color_bg] == PixColors[i]) 1023 if (pix_colors[Color_bg] == pix_colors[i])
981 { 1024 {
982 sprintf (bstr, "%d", (i - Color_Black)); 1025 sprintf (bstr, "%d", (i - Color_Black));
983#ifdef XPM_BACKGROUND 1026#ifdef XPM_BACKGROUND
984 xpmb = "default;"; 1027 xpmb = "default;";
985#endif 1028#endif
986 break; 1029 break;
987 } 1030 }
988 1031
989 sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); 1032 sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr);
990
991#ifndef NO_BRIGHTCOLOR
992 colorfgbg = DEFAULT_RSTYLE;
993 for (i = minCOLOR; i <= maxCOLOR; i++)
994 {
995 if (PixColors[Color_fg] == PixColors[i])
996 colorfgbg = SET_FGCOLOR (colorfgbg, i);
997 if (PixColors[Color_bg] == PixColors[i])
998 colorfgbg = SET_BGCOLOR (colorfgbg, i);
999 }
1000#endif
1001} 1033}
1002 1034
1003/*----------------------------------------------------------------------*/ 1035/*----------------------------------------------------------------------*/
1004/* 1036/*
1005 * Colour determination for low colour displays, routine from 1037 * Colour determination for low colour displays, routine from
1009int 1041int
1010rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) 1042rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour)
1011{ 1043{
1012 if (!screen_in_out->set (display, colour)) 1044 if (!screen_in_out->set (display, colour))
1013 { 1045 {
1014 rxvt_print_error ("can't allocate colour: %s", colour); 1046 rxvt_warn ("can't get colour '%s', continuing without.\n", colour);
1015 return false; 1047 return false;
1016 } 1048 }
1017 1049
1018 return true; 1050 return true;
1019} 1051}
1030 int old_width = szHint.width, old_height = szHint.height; 1062 int old_width = szHint.width, old_height = szHint.height;
1031#endif 1063#endif
1032 1064
1033 window_calc (width, height); 1065 window_calc (width, height);
1034 XSetWMNormalHints (display->display, TermWin.parent[0], &szHint); 1066 XSetWMNormalHints (display->display, TermWin.parent[0], &szHint);
1067
1035 if (!ignoreparent) 1068 if (!ignoreparent)
1036 { 1069 {
1037#ifdef SMART_RESIZE 1070#ifdef SMART_RESIZE
1038 /* 1071 /*
1039 * resize by Marius Gedminas <marius.gedminas@uosis.mif.vu.lt> 1072 * resize by Marius Gedminas <marius.gedminas@uosis.mif.vu.lt>
1074 dy /= 2; 1107 dy /= 2;
1075 1108
1076 XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy, 1109 XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy,
1077 szHint.width, szHint.height); 1110 szHint.width, szHint.height);
1078#else 1111#else
1079 XResizeWindow (display->display, TermWin.parent[0], szHint.width, 1112 XResizeWindow (display->display, TermWin.parent[0], szHint.width, szHint.height);
1080 szHint.height);
1081#endif 1113#endif
1082
1083 } 1114 }
1084 1115
1085 fix_screen = (TermWin.ncol != prev_ncol 1116 fix_screen = TermWin.ncol != prev_ncol || TermWin.nrow != prev_nrow;
1086 || TermWin.nrow != prev_nrow);
1087 1117
1088 if (fix_screen || width != old_width || height != old_height) 1118 if (fix_screen || width != old_width || height != old_height)
1089 { 1119 {
1090 if (scrollbar_visible ()) 1120 if (scrollbar_visible ())
1091 { 1121 {
1092 XMoveResizeWindow (display->display, scrollBar.win, window_sb_x, 1122 XMoveResizeWindow (display->display, scrollBar.win,
1123 window_sb_x, 0,
1093 0, scrollbar_TotalWidth (), szHint.height); 1124 scrollbar_TotalWidth (), szHint.height);
1094 resize_scrollbar (); 1125 resize_scrollbar ();
1095 } 1126 }
1096 1127
1097 if (menubar_visible ()) 1128 if (menubar_visible ())
1098 XMoveResizeWindow (display->display, menuBar.win, window_vt_x, 1129 XMoveResizeWindow (display->display, menuBar.win,
1130 window_vt_x, 0,
1099 0, TermWin_TotalWidth (), menuBar_TotalHeight ()); 1131 TermWin_TotalWidth (), menuBar_TotalHeight ());
1100 1132
1101 XMoveResizeWindow (display->display, TermWin.vt, window_vt_x, 1133 XMoveResizeWindow (display->display, TermWin.vt,
1102 window_vt_y, TermWin_TotalWidth (), 1134 window_vt_x, window_vt_y,
1103 TermWin_TotalHeight ()); 1135 TermWin_TotalWidth (), TermWin_TotalHeight ());
1104 scr_clear (height != old_height); 1136 scr_clear ();
1105#ifdef XPM_BACKGROUND 1137#ifdef XPM_BACKGROUND
1106 resize_pixmap (); 1138 resize_pixmap ();
1107#endif 1139#endif
1108
1109 } 1140 }
1110 1141
1111 if (fix_screen || old_height == 0) 1142 if (fix_screen || old_height == 0)
1112 { 1143 {
1113 int curr_screen = -1; 1144 int curr_screen = -1;
1154 if (width == 0) 1185 if (width == 0)
1155 width = wattr.width - szHint.base_width; 1186 width = wattr.width - szHint.base_width;
1156 if (height == 0) 1187 if (height == 0)
1157 height = wattr.height - szHint.base_height; 1188 height = wattr.height - szHint.base_height;
1158 } 1189 }
1190
1159 if (width != TermWin.width || height != TermWin.height) 1191 if (width != TermWin.width || height != TermWin.height)
1160 { 1192 {
1161 width += szHint.base_width; 1193 width += szHint.base_width;
1162 height += szHint.base_height; 1194 height += szHint.base_height;
1163 resize_all_windows (width, height, 0); 1195 resize_all_windows (width, height, 0);
1168 * - X INPUT METHOD ROUTINES - * 1200 * - X INPUT METHOD ROUTINES - *
1169 * -------------------------------------------------------------------- */ 1201 * -------------------------------------------------------------------- */
1170#ifdef USE_XIM 1202#ifdef USE_XIM
1171 1203
1172void 1204void
1205rxvt_term::im_set_color (unsigned long &fg, unsigned long &bg)
1206{
1207 fg = pix_colors[Color_fg];
1208 bg = pix_colors[Color_bg];
1209}
1210
1211void
1173rxvt_term::im_set_size (XRectangle *size) 1212rxvt_term::im_set_size (XRectangle &size)
1174{ 1213{
1214 // the int_bwidth terms make no sense to me
1175 size->x = TermWin.int_bwidth; 1215 size.x = TermWin.int_bwidth;
1176 size->y = TermWin.int_bwidth; 1216 size.y = TermWin.int_bwidth;
1177 size->width = Width2Pixel (TermWin.ncol); 1217 size.width = Width2Pixel (TermWin.ncol) + TermWin.int_bwidth;
1178 size->height = Height2Pixel (TermWin.nrow); 1218 size.height = Height2Pixel (TermWin.nrow) + TermWin.int_bwidth;
1179} 1219}
1180 1220
1181void 1221void
1182rxvt_term::im_set_color (unsigned long *fg, unsigned long *bg) 1222rxvt_term::im_set_preedit_area (XRectangle &preedit_rect,
1223 XRectangle &status_rect,
1224 const XRectangle &needed_rect)
1183{ 1225{
1184 *fg = PixColors[Color_fg]; 1226 preedit_rect.x = needed_rect.width;
1185 *bg = PixColors[Color_bg]; 1227 preedit_rect.y = 0;
1228 preedit_rect.width = Width2Pixel (TermWin.ncol) - needed_rect.width + 1;
1229 preedit_rect.height = TermWin.fheight;
1230
1231 status_rect.x = 0;
1232 status_rect.y = 0;
1233 status_rect.width = needed_rect.width ? needed_rect.width : Width2Pixel (TermWin.ncol) + 1;
1234 status_rect.height = TermWin.fheight;
1186} 1235}
1187 1236
1188/* Checking whether input method is running. */ 1237/* Checking whether input method is running. */
1189bool 1238bool
1190rxvt_term::IMisRunning () 1239rxvt_term::IMisRunning ()
1191{ 1240{
1192 char *p; 1241 char *p;
1193 Atom atom; 1242 Atom atom;
1194 Window win; 1243 Window win;
1195 char server[IMBUFSIZ]; 1244 char server[IMBUFSIZ];
1196 1245
1197 /* get current locale modifier */ 1246 /* get current locale modifier */
1198 if ((p = XSetLocaleModifiers (NULL)) != NULL) 1247 if ((p = XSetLocaleModifiers (NULL)) != NULL)
1199 { 1248 {
1200 STRCPY (server, "@server="); 1249 strcpy (server, "@server=");
1201 STRNCAT (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */ 1250 strncat (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */
1251
1202 if ((p = STRCHR (server + 1, '@')) != NULL) /* first one only */ 1252 if ((p = strchr (server + 1, '@')) != NULL) /* first one only */
1203 *p = '\0'; 1253 *p = '\0';
1204 1254
1205 atom = XInternAtom (display->display, server, False); 1255 atom = XInternAtom (display->display, server, False);
1206 win = XGetSelectionOwner (display->display, atom); 1256 win = XGetSelectionOwner (display->display, atom);
1257
1207 if (win != None) 1258 if (win != None)
1208 return True; 1259 return True;
1209 } 1260 }
1261
1210 return False; 1262 return False;
1211} 1263}
1212 1264
1213void 1265void
1214rxvt_term::IMSendSpot () 1266rxvt_term::IMSendSpot ()
1215{ 1267{
1216 XPoint spot; 1268 XPoint spot;
1217 XVaNestedList preedit_attr; 1269 XVaNestedList preedit_attr;
1218 1270
1219 if (Input_Context == NULL 1271 if (!Input_Context
1272 || !TermWin.focus
1220 || !TermWin.focus || ! (input_style & XIMPreeditPosition) 1273 || !(input_style & XIMPreeditPosition)
1274#if 0
1221 || ! (event_type == KeyPress 1275 || !(event_type == KeyPress
1222 || event_type == Expose 1276 || event_type == Expose
1223 || event_type == NoExpose 1277 || event_type == NoExpose
1224 || event_type == SelectionNotify 1278 || event_type == SelectionNotify
1225 || event_type == ButtonRelease || event_type == FocusIn) 1279 || event_type == ButtonRelease || event_type == FocusIn)
1280#endif
1226 || !IMisRunning ()) 1281 || !IMisRunning ())
1227 return; 1282 return;
1228 1283
1229 im_set_position (&spot); 1284 im_set_position (spot);
1230 1285
1231 preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); 1286 preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL);
1232 XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); 1287 XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL);
1233 XFree (preedit_attr); 1288 XFree (preedit_attr);
1234} 1289}
1235 1290
1236void 1291void
1237rxvt_term::im_set_preedit_area (XRectangle * preedit_rect, XRectangle * status_rect,
1238 XRectangle * needed_rect)
1239{
1240 int mbh, vtx = 0;
1241
1242 if (scrollbar_visible () && ! (Options & Opt_scrollBar_right))
1243 vtx = scrollbar_TotalWidth ();
1244
1245 mbh = menubar_visible () ? menuBar_TotalHeight () : 0;
1246 mbh -= TermWin.lineSpace;
1247
1248 preedit_rect->x = needed_rect->width + vtx;
1249 preedit_rect->y = Height2Pixel (TermWin.nrow - 1) + mbh;
1250
1251 preedit_rect->width = Width2Pixel (TermWin.ncol + 1) - needed_rect->width + vtx;
1252 preedit_rect->height = Height2Pixel (1);
1253
1254 status_rect->x = vtx;
1255 status_rect->y = Height2Pixel (TermWin.nrow - 1) + mbh;
1256
1257 status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel (TermWin.ncol + 1);
1258 status_rect->height = Height2Pixel (1);
1259}
1260
1261void
1262rxvt_term::im_destroy () 1292rxvt_term::im_destroy ()
1263{ 1293{
1264 if (Input_Context) 1294 if (Input_Context)
1265 { 1295 {
1266 XDestroyIC (Input_Context); 1296 XDestroyIC (Input_Context);
1267 Input_Context = NULL; 1297 Input_Context = 0;
1268 } 1298 }
1269 1299
1270 if (input_method) 1300 if (input_method)
1271 { 1301 {
1272 display->put_xim (input_method); 1302 display->put_xim (input_method);
1279 * open a suitable preedit type 1309 * open a suitable preedit type
1280 */ 1310 */
1281bool 1311bool
1282rxvt_term::IM_get_IC (const char *modifiers) 1312rxvt_term::IM_get_IC (const char *modifiers)
1283{ 1313{
1284 int i, j, found; 1314 int i, j, found;
1285 XIM xim; 1315 XIM xim;
1286 XPoint spot; 1316 XPoint spot;
1287 XRectangle rect, status_rect, needed_rect; 1317 XRectangle rect, status_rect, needed_rect;
1288 unsigned long fg, bg; 1318 unsigned long fg, bg;
1289 const char *p; 1319 const char *p;
1290 char **s; 1320 char **s;
1291 XIMStyles *xim_styles; 1321 XIMStyles *xim_styles;
1292 XVaNestedList preedit_attr, status_attr;
1293 1322
1294 if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) 1323 if (! ((p = XSetLocaleModifiers (modifiers)) && *p))
1295 return false; 1324 return false;
1296 1325
1297 D_MAIN ((stderr, "rxvt_IM_get_IC ()")); 1326 D_MAIN ((stderr, "rxvt_IM_get_IC ()"));
1303 1332
1304 xim_styles = NULL; 1333 xim_styles = NULL;
1305 if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) 1334 if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL)
1306 || !xim_styles || !xim_styles->count_styles) 1335 || !xim_styles || !xim_styles->count_styles)
1307 { 1336 {
1308 display->put_xim (input_method); 1337 im_destroy ();
1309 return false; 1338 return false;
1310 } 1339 }
1311 1340
1312 p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root"; 1341 p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root";
1313 s = rxvt_splitcommastring (p); 1342 s = rxvt_splitcommastring (p);
1343
1314 for (i = found = 0; !found && s[i]; i++) 1344 for (i = found = 0; !found && s[i]; i++)
1315 { 1345 {
1316 if (!STRCMP (s[i], "OverTheSpot")) 1346 if (!strcmp (s[i], "OverTheSpot"))
1317 input_style = (XIMPreeditPosition | XIMStatusNothing); 1347 input_style = (XIMPreeditPosition | XIMStatusNothing);
1318 else if (!STRCMP (s[i], "OffTheSpot")) 1348 else if (!strcmp (s[i], "OffTheSpot"))
1319 input_style = (XIMPreeditArea | XIMStatusArea); 1349 input_style = (XIMPreeditArea | XIMStatusArea);
1320 else if (!STRCMP (s[i], "Root")) 1350 else if (!strcmp (s[i], "Root"))
1321 input_style = (XIMPreeditNothing | XIMStatusNothing); 1351 input_style = (XIMPreeditNothing | XIMStatusNothing);
1322 1352
1323 for (j = 0; j < xim_styles->count_styles; j++) 1353 for (j = 0; j < xim_styles->count_styles; j++)
1324 if (input_style == xim_styles->supported_styles[j]) 1354 if (input_style == xim_styles->supported_styles[j])
1325 { 1355 {
1334 free (s); 1364 free (s);
1335 XFree (xim_styles); 1365 XFree (xim_styles);
1336 1366
1337 if (!found) 1367 if (!found)
1338 { 1368 {
1339 display->put_xim (input_method); 1369 im_destroy ();
1340 return false; 1370 return false;
1341 } 1371 }
1342 1372
1343 preedit_attr = status_attr = NULL; 1373 XFontSet fs = 0;
1374 XVaNestedList preedit_attr = 0, status_attr = 0;
1375
1376 if (input_style & (XIMPreeditPosition | XIMPreeditArea))
1377 {
1378 // fake us a font-set, please
1379 char **missing_charset_list;
1380 int missing_charset_count;
1381 char *def_string;
1382 char pat[512];
1383
1384 sprintf (pat,
1385 "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
1386 "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
1387 "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
1388 "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
1389 "-*-*-*-R-*-*-%d-*-*-*-*-*-*,"
1390 "*",
1391 TermWin.fheight,
1392 TermWin.fheight + 1, TermWin.fheight - 1,
1393 TermWin.fheight - 2, TermWin.fheight + 2);
1394
1395 fs = XCreateFontSet (display->display, pat,
1396 &missing_charset_list, &missing_charset_count, &def_string);
1397
1398 if (missing_charset_list)
1399 XFreeStringList (missing_charset_list);
1400
1401 if (!fs)
1402 {
1403 input_style &= ~(XIMPreeditPosition | XIMPreeditArea);
1404 rxvt_warn ("unable to create fontset for input method, try \"-pt Root\". Continuing.\n");
1405 }
1406 }
1344 1407
1345 if (input_style & XIMPreeditPosition) 1408 if (input_style & XIMPreeditPosition)
1346 { 1409 {
1347 im_set_size (&rect); 1410 im_set_size (rect);
1348 im_set_position (&spot); 1411 im_set_position (spot);
1349 im_set_color (&fg, &bg); 1412 im_set_color (fg, bg);
1350 1413
1351 preedit_attr = XVaCreateNestedList (0, XNArea, &rect, 1414 preedit_attr = XVaCreateNestedList (0,
1415 XNForeground, fg,
1416 XNBackground, bg,
1417 XNArea, &rect,
1352 XNSpotLocation, &spot, 1418 XNSpotLocation, &spot,
1353 XNForeground, fg, XNBackground, bg,
1354 //XNFontSet, TermWin.fontset, 1419 XNFontSet, fs,
1355 NULL); 1420 NULL);
1356 } 1421 }
1357 else if (input_style & XIMPreeditArea) 1422 else if (input_style & XIMPreeditArea)
1358 { 1423 {
1359 im_set_color (&fg, &bg); 1424 im_set_color (fg, bg);
1360 1425
1361 /* 1426 /*
1362 * The necessary width of preedit area is unknown 1427 * The necessary width of preedit area is unknown
1363 * until create input context. 1428 * until create input context.
1364 */ 1429 */
1365 needed_rect.width = 0; 1430 needed_rect.width = 0;
1366
1367 im_set_preedit_area (&rect, &status_rect, &needed_rect); 1431 im_set_preedit_area (rect, status_rect, needed_rect);
1368 1432
1369 preedit_attr = XVaCreateNestedList (0, XNArea, &rect, 1433 preedit_attr = XVaCreateNestedList (0,
1434 XNForeground, fg,
1370 XNForeground, fg, XNBackground, bg, 1435 XNBackground, bg,
1436 XNArea, &rect,
1437 XNFontSet, fs,
1438 NULL);
1439 status_attr = XVaCreateNestedList (0,
1440 XNForeground, fg,
1441 XNBackground, bg,
1442 XNArea, &status_rect,
1371 //XNFontSet, TermWin.fontset, 1443 XNFontSet, fs,
1372 NULL); 1444 NULL);
1373 status_attr = XVaCreateNestedList (0, XNArea, &status_rect,
1374 XNForeground, fg, XNBackground, bg,
1375 //XNFontSet, TermWin.fontset,
1376 NULL);
1377 } 1445 }
1378 1446
1379 Input_Context = XCreateIC (xim, XNInputStyle, input_style, 1447 Input_Context = XCreateIC (xim,
1448 XNInputStyle, input_style,
1380 XNClientWindow, TermWin.parent[0], 1449 XNClientWindow, TermWin.vt,
1381 XNFocusWindow, TermWin.parent[0], 1450 XNFocusWindow, TermWin.parent[0],
1382 preedit_attr ? XNPreeditAttributes : NULL, 1451 preedit_attr ? XNPreeditAttributes : NULL,
1383 preedit_attr, 1452 preedit_attr,
1384 status_attr ? XNStatusAttributes : NULL, 1453 status_attr ? XNStatusAttributes : NULL,
1385 status_attr, NULL); 1454 status_attr, NULL);
1455
1386 if (preedit_attr) XFree (preedit_attr); 1456 if (preedit_attr) XFree (preedit_attr);
1387 if (status_attr) XFree (status_attr); 1457 if (status_attr) XFree (status_attr);
1458 if (fs) XFreeFontSet (display->display, fs);
1388 1459
1389 if (Input_Context == NULL) 1460 if (Input_Context == NULL)
1390 { 1461 {
1391 rxvt_print_error ("failed to create input context"); 1462 rxvt_warn ("failed to create input context, continuing without XIM.\n");
1392 display->put_xim (input_method); 1463 im_destroy ();
1393 return false; 1464 return false;
1394 } 1465 }
1395 1466
1396 if (input_style & XIMPreeditArea) 1467 if (input_style & XIMPreeditArea)
1397 IMSetStatusPosition (); 1468 IMSetStatusPosition ();
1427 s = rxvt_splitcommastring (p); 1498 s = rxvt_splitcommastring (p);
1428 for (i = 0; s[i]; i++) 1499 for (i = 0; s[i]; i++)
1429 { 1500 {
1430 if (*s[i]) 1501 if (*s[i])
1431 { 1502 {
1432 STRCPY (buf, "@im="); 1503 strcpy (buf, "@im=");
1433 STRNCAT (buf, s[i], IMBUFSIZ - 5); 1504 strncat (buf, s[i], IMBUFSIZ - 5);
1434 if (IM_get_IC (buf)) 1505 if (IM_get_IC (buf))
1435 { 1506 {
1436 found = true; 1507 found = true;
1437 break; 1508 break;
1438 } 1509 }
1462} 1533}
1463 1534
1464void 1535void
1465rxvt_term::IMSetStatusPosition () 1536rxvt_term::IMSetStatusPosition ()
1466{ 1537{
1467 XRectangle preedit_rect, status_rect, *needed_rect; 1538 XRectangle preedit_rect, status_rect, *needed_rect;
1468 XVaNestedList preedit_attr, status_attr; 1539 XVaNestedList preedit_attr, status_attr;
1469 1540
1470 if (Input_Context == NULL 1541 if (!Input_Context
1542 || !TermWin.focus
1471 || !TermWin.focus || ! (input_style & XIMPreeditArea) 1543 || !(input_style & XIMPreeditArea)
1472 || !IMisRunning ()) 1544 || !IMisRunning ())
1473 return; 1545 return;
1474 1546
1475 /* Getting the necessary width of preedit area */ 1547 /* Getting the necessary width of preedit area */
1476 status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL); 1548 status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL);
1477 XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL); 1549 XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL);
1478 XFree (status_attr); 1550 XFree (status_attr);
1479 1551
1480 im_set_preedit_area (&preedit_rect, &status_rect, needed_rect); 1552 im_set_preedit_area (preedit_rect, status_rect, *needed_rect);
1553 XFree (needed_rect);
1481 1554
1482 preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL); 1555 preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL);
1483 status_attr = XVaCreateNestedList (0, XNArea, &status_rect, NULL); 1556 status_attr = XVaCreateNestedList (0, XNArea, &status_rect, NULL);
1484 1557
1485 XSetICValues (Input_Context, 1558 XSetICValues (Input_Context,
1486 XNPreeditAttributes, preedit_attr, 1559 XNPreeditAttributes, preedit_attr,
1487 XNStatusAttributes, status_attr, NULL); 1560 XNStatusAttributes, status_attr, NULL);
1488 1561
1489 XFree (preedit_attr); 1562 XFree (preedit_attr);
1490 XFree (status_attr); 1563 XFree (status_attr);
1491} 1564}
1492#endif /* USE_XIM */ 1565#endif /* USE_XIM */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines