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.26 by pcg, Sun Feb 1 01:34:41 2004 UTC vs.
Revision 1.32 by pcg, Fri Feb 13 12:16:21 2004 UTC

72 free (p); 72 free (p);
73} 73}
74 74
75rxvt_term::rxvt_term () 75rxvt_term::rxvt_term ()
76 : 76 :
77 rootwin_ev (this, &rxvt_term::rootwin_cb),
78 termwin_ev (this, &rxvt_term::x_cb),
79 vt_ev (this, &rxvt_term::x_cb),
80#ifdef HAVE_SCROLLBARS
81 scrollbar_ev (this, &rxvt_term::x_cb),
82#endif
83#ifdef MENUBAR
84 menubar_ev (this, &rxvt_term::x_cb), fixme
85#endif
77#ifdef CURSOR_BLINK 86#ifdef CURSOR_BLINK
78 cursor_blink_ev (this, &rxvt_term::cursor_blink_cb), 87 cursor_blink_ev (this, &rxvt_term::cursor_blink_cb),
79#endif 88#endif
80#ifdef TEXT_BLINK 89#ifdef TEXT_BLINK
81 text_blink_ev (this, &rxvt_term::text_blink_cb), 90 text_blink_ev (this, &rxvt_term::text_blink_cb),
84 pointer_ev (this, &rxvt_term::pointer_cb), 93 pointer_ev (this, &rxvt_term::pointer_cb),
85#endif 94#endif
86 check_ev (this, &rxvt_term::check_cb), 95 check_ev (this, &rxvt_term::check_cb),
87 destroy_ev (this, &rxvt_term::destroy_cb), 96 destroy_ev (this, &rxvt_term::destroy_cb),
88 pty_ev (this, &rxvt_term::pty_cb), 97 pty_ev (this, &rxvt_term::pty_cb),
89 x_ev (this, &rxvt_term::x_cb),
90 incr_ev (this, &rxvt_term::incr_cb) 98 incr_ev (this, &rxvt_term::incr_cb),
99#ifdef USE_XIM
100 im_ev (this, &rxvt_term::im_cb)
101#endif
91{ 102{
92 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; 103 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base;
93} 104}
94 105
95rxvt_term::~rxvt_term () 106rxvt_term::~rxvt_term ()
96{ 107{
108 if (cmd_fd >= 0)
109 close (cmd_fd);
110
97 scr_release (); 111 scr_release ();
98 112
99 free (locale); 113 free (locale);
100 free (codeset); 114 free (codeset);
101 115
103 privileged_ttydev (RESTORE); 117 privileged_ttydev (RESTORE);
104#endif 118#endif
105#ifdef UTMP_SUPPORT 119#ifdef UTMP_SUPPORT
106 privileged_utmp (RESTORE); 120 privileged_utmp (RESTORE);
107#endif 121#endif
122
123 // TODO: free pixcolours, colours should become part of rxvt_display
124
125 delete PixColors;
126 delete TermWin.fontset;
127
128 displays.put (display);
129}
130
131void
132rxvt_term::destroy ()
133{
134 if (display)
135 {
136 if (TermWin.parent[0])
137 XDestroyWindow (display->display, TermWin.parent[0]);
138
139 rootwin_ev.stop (display);
140 termwin_ev.stop (display);
141 vt_ev.stop (display);
142
108#ifdef USE_XIM 143#ifdef USE_XIM
109 if (Input_Context != NULL) 144 im_destroy ();
145 im_ev.stop (display);
146#endif
147#ifdef HAVE_SCROLLBARS
148 scrollbar_ev.stop (display);
149#endif
150#ifdef MENUBAR
151 menubar_ev.stop (display);
152#endif
110 { 153 }
111 XDestroyIC (Input_Context);
112 Input_Context = NULL;
113 }
114#endif
115 154
116 if (cmd_fd >= 0)
117 close (cmd_fd);
118
119 if (Xfd >= 0)
120 XCloseDisplay (Xdisplay);
121
122 delete PixColors;
123}
124
125void
126rxvt_term::destroy ()
127{
128 check_ev.stop (); 155 check_ev.stop ();
129 pty_ev.stop (); 156 pty_ev.stop ();
130 x_ev.stop ();
131#ifdef CURSOR_BLINK 157#ifdef CURSOR_BLINK
132 cursor_blink_ev.stop (); 158 cursor_blink_ev.stop ();
133#endif 159#endif
134#ifdef TEXT_BLINK 160#ifdef TEXT_BLINK
135 text_blink_ev.stop (); 161 text_blink_ev.stop ();
148 174
149 delete this; 175 delete this;
150} 176}
151 177
152/*----------------------------------------------------------------------*/ 178/*----------------------------------------------------------------------*/
153/* rxvt_init() */ 179/* rxvt_init () */
154/* LIBPROTO */ 180/* LIBPROTO */
155rxvt_t 181rxvt_t
156rxvt_init (int argc, const char *const *argv) 182rxvt_init (int argc, const char *const *argv)
157{ 183{
158 SET_R (new rxvt_term); 184 SET_R (new rxvt_term);
164 } 190 }
165 191
166 return GET_R; 192 return GET_R;
167} 193}
168 194
195static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event);
196
169void 197void
170rxvt_init_signals () 198rxvt_init_signals ()
171{ 199{
172 /* install exit handler for cleanup */ 200 /* install exit handler for cleanup */
173#if 0 201#if 0
174#ifdef HAVE_ATEXIT 202#ifdef HAVE_ATEXIT
175 atexit(rxvt_clean_exit); 203 atexit (rxvt_clean_exit);
176#else 204#else
177#endif 205#endif
178#endif 206#endif
179 207
180 struct sigaction sa; 208 struct sigaction sa;
189 sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0); 217 sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0);
190 218
191 /* need to trap SIGURG for SVR4 (Unixware) rlogin */ 219 /* need to trap SIGURG for SVR4 (Unixware) rlogin */
192 /* signal (SIGURG, SIG_DFL); */ 220 /* signal (SIGURG, SIG_DFL); */
193 221
194 XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 222 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
195 //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); 223 //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler);
196} 224}
197 225
198bool 226bool
199rxvt_term::init (int argc, const char *const *argv) 227rxvt_term::init (int argc, const char *const *argv)
231 Gr_reset (); /* reset graphics */ 259 Gr_reset (); /* reset graphics */
232#endif 260#endif
233 261
234#if 0 262#if 0
235#ifdef DEBUG_X 263#ifdef DEBUG_X
236 XSynchronize(Xdisplay, True); 264 XSynchronize (display->display, True);
237#endif 265#endif
238#endif 266#endif
239 267
240#ifdef HAVE_SCROLLBARS 268#ifdef HAVE_SCROLLBARS
241 if (Options & Opt_scrollBar) 269 if (Options & Opt_scrollBar)
242 resize_scrollbar (); /* create and map scrollbar */ 270 resize_scrollbar (); /* create and map scrollbar */
243#endif 271#endif
244#if (MENUBAR_MAX) 272#if (MENUBAR_MAX)
245 if (menubar_visible(r)) 273 if (menubar_visible (r))
246 XMapWindow (Xdisplay, menuBar.win); 274 XMapWindow (display->display, menuBar.win);
247#endif 275#endif
248#ifdef TRANSPARENT 276#ifdef TRANSPARENT
249 if (Options & Opt_transparent) 277 if (Options & Opt_transparent)
250 { 278 {
251 XSelectInput (Xdisplay, Xroot, PropertyChangeMask); 279 XSelectInput (display->display, display->root, PropertyChangeMask);
252 check_our_parents (); 280 check_our_parents ();
253 } 281 }
254#endif 282#endif
283
284 rootwin_ev.start (display, display->root);
285
255 XMapWindow (Xdisplay, TermWin.vt); 286 XMapWindow (display->display, TermWin.vt);
256 XMapWindow (Xdisplay, TermWin.parent[0]); 287 XMapWindow (display->display, TermWin.parent[0]);
257 288
258 init_env (); 289 init_env ();
259 init_command (cmd_argv); 290 init_command (cmd_argv);
260 291
261 x_ev.start (Xfd, EVENT_READ);
262 pty_ev.start (cmd_fd, EVENT_READ); 292 pty_ev.start (cmd_fd, EVENT_READ);
263 293
264 check_ev.start (); 294 check_ev.start ();
265
266 process_x_events ();
267 295
268 return true; 296 return true;
269} 297}
270 298
271/* ------------------------------------------------------------------------- * 299/* ------------------------------------------------------------------------- *
275 * Catch a SIGCHLD signal and exit if the direct child has died 303 * Catch a SIGCHLD signal and exit if the direct child has died
276 */ 304 */
277/* ARGSUSED */ 305/* ARGSUSED */
278/* EXTPROTO */ 306/* EXTPROTO */
279RETSIGTYPE 307RETSIGTYPE
280rxvt_Child_signal(int sig __attribute__ ((unused))) 308rxvt_Child_signal (int sig __attribute__ ((unused)))
281{ 309{
282 int pid, save_errno = errno; 310 int pid, save_errno = errno;
283 while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR) 311 while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR)
284 ; 312 ;
285 errno = save_errno; 313 errno = save_errno;
293/* 321/*
294 * Catch a fatal signal and tidy up before quitting 322 * Catch a fatal signal and tidy up before quitting
295 */ 323 */
296/* EXTPROTO */ 324/* EXTPROTO */
297RETSIGTYPE 325RETSIGTYPE
298rxvt_Exit_signal(int sig) 326rxvt_Exit_signal (int sig)
299{ 327{
300 signal(sig, SIG_DFL); 328 signal (sig, SIG_DFL);
301#ifdef DEBUG_CMD 329#ifdef DEBUG_CMD
302 rxvt_print_error("signal %d", sig); 330 rxvt_print_error ("signal %d", sig);
303#endif 331#endif
304 rxvt_clean_exit(); 332 rxvt_clean_exit ();
305 kill(getpid(), sig); 333 kill (getpid (), sig);
306} 334}
307 335
308/* ARGSUSED */
309/* EXTPROTO */ 336/* INTPROTO */
310int 337int
311rxvt_xerror_handler(const Display * display 338rxvt_xerror_handler (Display *display, XErrorEvent *event)
312 __attribute__ ((unused)), const XErrorEvent * event)
313{ 339{
314 if (GET_R->allowedxerror == -1) 340 if (GET_R->allowedxerror == -1)
315 GET_R->allowedxerror = event->error_code; 341 GET_R->allowedxerror = event->error_code;
316 else 342 else
317 { 343 {
318 rxvt_print_error("XError: Request: %d . %d, Error: %d", 344 old_xerror_handler (display, event);
319 event->request_code, event->minor_code,
320 event->error_code);
321
322 GET_R->destroy (); 345 GET_R->destroy ();
323 } 346 }
324 347
325 return 0; 348 return 0;
326} 349}
332 */ 355 */
333/* EXTPROTO */ 356/* EXTPROTO */
334void 357void
335rxvt_clean_exit () 358rxvt_clean_exit ()
336{ 359{
360 // TODO: rxvtd should clean up all ressources
361 if (GET_R)
337 GET_R->destroy (); 362 GET_R->destroy ();
338} 363}
339 364
340/* ------------------------------------------------------------------------- * 365/* ------------------------------------------------------------------------- *
341 * MEMORY ALLOCATION WRAPPERS * 366 * MEMORY ALLOCATION WRAPPERS *
342 * ------------------------------------------------------------------------- */ 367 * ------------------------------------------------------------------------- */
343/* EXTPROTO */ 368/* EXTPROTO */
344void * 369void *
345rxvt_malloc(size_t size) 370rxvt_malloc (size_t size)
346{ 371{
347 void *p; 372 void *p;
348 373
349 p = malloc(size); 374 p = malloc (size);
350 if (p) 375 if (p)
351 return p; 376 return p;
352 377
353 fprintf(stderr, APL_NAME ": memory allocation failure. Aborting"); 378 fprintf (stderr, APL_NAME ": memory allocation failure. Aborting");
354 rxvt_clean_exit(); 379 rxvt_clean_exit ();
355 exit(EXIT_FAILURE); 380 exit (EXIT_FAILURE);
356 /* NOTREACHED */ 381 /* NOTREACHED */
357} 382}
358 383
359/* EXTPROTO */ 384/* EXTPROTO */
360void * 385void *
361rxvt_calloc(size_t number, size_t size) 386rxvt_calloc (size_t number, size_t size)
362{ 387{
363 void *p; 388 void *p;
364 389
365 p = calloc(number, size); 390 p = calloc (number, size);
366 if (p) 391 if (p)
367 return p; 392 return p;
368 393
369 fprintf(stderr, APL_NAME ": memory allocation failure. Aborting"); 394 fprintf (stderr, APL_NAME ": memory allocation failure. Aborting");
370 rxvt_clean_exit(); 395 rxvt_clean_exit ();
371 exit(EXIT_FAILURE); 396 exit (EXIT_FAILURE);
372 /* NOTREACHED */ 397 /* NOTREACHED */
373} 398}
374 399
375/* EXTPROTO */ 400/* EXTPROTO */
376void * 401void *
377rxvt_realloc(void *ptr, size_t size) 402rxvt_realloc (void *ptr, size_t size)
378{ 403{
379 void *p; 404 void *p;
380 405
381 if (ptr) 406 if (ptr)
382 p = realloc(ptr, size); 407 p = realloc (ptr, size);
383 else 408 else
384 p = malloc(size); 409 p = malloc (size);
385 if (p) 410 if (p)
386 return p; 411 return p;
387 412
388 fprintf(stderr, APL_NAME ": memory allocation failure. Aborting"); 413 fprintf (stderr, APL_NAME ": memory allocation failure. Aborting");
389 rxvt_clean_exit(); 414 rxvt_clean_exit ();
390 exit(EXIT_FAILURE); 415 exit (EXIT_FAILURE);
391 /* NOTREACHED */ 416 /* NOTREACHED */
392} 417}
393 418
394/* ------------------------------------------------------------------------- * 419/* ------------------------------------------------------------------------- *
395 * PRIVILEGED OPERATIONS * 420 * PRIVILEGED OPERATIONS *
398void 423void
399rxvt_term::privileges (int mode) 424rxvt_term::privileges (int mode)
400{ 425{
401#if ! defined(__CYGWIN32__) 426#if ! defined(__CYGWIN32__)
402# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) 427# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID)
403 /* setreuid() is the poor man's setuid(), seteuid() */ 428 /* setreuid () is the poor man's setuid (), seteuid () */
404# define seteuid(a) setreuid(-1, (a)) 429# define seteuid(a) setreuid(-1, (a))
405# define setegid(a) setregid(-1, (a)) 430# define setegid(a) setregid(-1, (a))
406# define HAVE_SETEUID 431# define HAVE_SETEUID
407# endif 432# endif
408# ifdef HAVE_SETEUID 433# ifdef HAVE_SETEUID
411 case IGNORE: 436 case IGNORE:
412 /* 437 /*
413 * change effective uid/gid - not real uid/gid - so we can switch 438 * change effective uid/gid - not real uid/gid - so we can switch
414 * back to root later, as required 439 * back to root later, as required
415 */ 440 */
416 seteuid(getuid()); 441 seteuid (getuid ());
417 setegid(getgid()); 442 setegid (getgid ());
418 break; 443 break;
419 case SAVE: 444 case SAVE:
420 euid = geteuid(); 445 euid = geteuid ();
421 egid = getegid(); 446 egid = getegid ();
422 break; 447 break;
423 case RESTORE: 448 case RESTORE:
424 seteuid(euid); 449 seteuid (euid);
425 setegid(egid); 450 setegid (egid);
426 break; 451 break;
427 } 452 }
428# else 453# else
429 switch (mode) 454 switch (mode)
430 { 455 {
431 case IGNORE: 456 case IGNORE:
432 setuid(getuid()); 457 setuid (getuid ());
433 setgid(getgid()); 458 setgid (getgid ());
434 /* FALLTHROUGH */ 459 /* FALLTHROUGH */
435 case SAVE: 460 case SAVE:
436 /* FALLTHROUGH */ 461 /* FALLTHROUGH */
437 case RESTORE: 462 case RESTORE:
438 break; 463 break;
443 468
444#ifdef UTMP_SUPPORT 469#ifdef UTMP_SUPPORT
445void 470void
446rxvt_term::privileged_utmp (char action) 471rxvt_term::privileged_utmp (char action)
447{ 472{
448 D_MAIN((stderr, "rxvt_privileged_utmp(%c); waiting for: %c (pid: %d)", 473 D_MAIN ((stderr, "rxvt_privileged_utmp (%c); waiting for: %c (pid: %d)",
449 action, next_utmp_action, getpid())); 474 action, next_utmp_action, getpid ()));
450 if (next_utmp_action != action || (action != SAVE && action != RESTORE) 475 if (next_utmp_action != action || (action != SAVE && action != RESTORE)
451 || (Options & Opt_utmpInhibit) 476 || (Options & Opt_utmpInhibit)
452 || ttydev == NULL || *ttydev == '\0') 477 || ttydev == NULL || *ttydev == '\0')
453 return; 478 return;
454 479
469 494
470#ifndef NO_SETOWNER_TTYDEV 495#ifndef NO_SETOWNER_TTYDEV
471void 496void
472rxvt_term::privileged_ttydev (char action) 497rxvt_term::privileged_ttydev (char action)
473{ 498{
474 D_MAIN((stderr, 499 D_MAIN ((stderr,
475 "privileged_ttydev (%c); waiting for: %c (pid: %d)", 500 "privileged_ttydev (%c); waiting for: %c (pid: %d)",
476 action, next_tty_action, getpid())); 501 action, next_tty_action, getpid ()));
477 if (next_tty_action != action || (action != SAVE && action != RESTORE) 502 if (next_tty_action != action || (action != SAVE && action != RESTORE)
478 || ttydev == NULL || *ttydev == '\0') 503 || ttydev == NULL || *ttydev == '\0')
479 return; 504 return;
480 505
481 privileges (RESTORE); 506 privileges (RESTORE);
482 507
483 if (action == SAVE) 508 if (action == SAVE)
484 { 509 {
485 next_tty_action = RESTORE; 510 next_tty_action = RESTORE;
486# ifndef RESET_TTY_TO_COMMON_DEFAULTS 511# ifndef RESET_TTY_TO_COMMON_DEFAULTS
487 /* store original tty status for restoration rxvt_clean_exit() -- rgg 04/12/95 */ 512 /* store original tty status for restoration rxvt_clean_exit () -- rgg 04/12/95 */
488 if (lstat(ttydev, &ttyfd_stat) < 0) /* you lose out */ 513 if (lstat (ttydev, &ttyfd_stat) < 0) /* you lose out */
489 next_tty_action = IGNORE; 514 next_tty_action = IGNORE;
490 else 515 else
491# endif 516# endif
492 517
493 { 518 {
494 chown(ttydev, getuid(), ttygid); /* fail silently */ 519 chown (ttydev, getuid (), ttygid); /* fail silently */
495 chmod(ttydev, ttymode); 520 chmod (ttydev, ttymode);
496# ifdef HAVE_REVOKE 521# ifdef HAVE_REVOKE
497 revoke(ttydev); 522 revoke (ttydev);
498# endif 523# endif
499 524
500 } 525 }
501 } 526 }
502 else 527 else
503 { /* action == RESTORE */ 528 { /* action == RESTORE */
504 next_tty_action = IGNORE; 529 next_tty_action = IGNORE;
505# ifndef RESET_TTY_TO_COMMON_DEFAULTS 530# ifndef RESET_TTY_TO_COMMON_DEFAULTS
506 chmod(ttydev, ttyfd_stat.st_mode); 531 chmod (ttydev, ttyfd_stat.st_mode);
507 chown(ttydev, ttyfd_stat.st_uid, ttyfd_stat.st_gid); 532 chown (ttydev, ttyfd_stat.st_uid, ttyfd_stat.st_gid);
508# else 533# else
509 chmod(ttydev, 534 chmod (ttydev,
510 (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)); 535 (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH));
511 chown(ttydev, 0, 0); 536 chown (ttydev, 0, 0);
512# endif 537# endif
513 538
514 } 539 }
515 540
516 privileges (IGNORE); 541 privileges (IGNORE);
517 542
518# ifndef RESET_TTY_TO_COMMON_DEFAULTS 543# ifndef RESET_TTY_TO_COMMON_DEFAULTS
519 D_MAIN((stderr, "%s \"%s\": mode %03o, uid %d, gid %d", 544 D_MAIN ((stderr, "%s \"%s\": mode %03o, uid %d, gid %d",
520 action == RESTORE ? "Restoring" : (action == 545 action == RESTORE ? "Restoring" : (action ==
521 SAVE ? "Saving" : 546 SAVE ? "Saving" :
522 "UNKNOWN ERROR for"), ttydev, 547 "UNKNOWN ERROR for"), ttydev,
523 ttyfd_stat.st_mode, ttyfd_stat.st_uid, 548 ttyfd_stat.st_mode, ttyfd_stat.st_uid,
524 ttyfd_stat.st_gid)); 549 ttyfd_stat.st_gid));
537 short recalc_x, recalc_y; 562 short recalc_x, recalc_y;
538 int x, y, sb_w, mb_h, flags; 563 int x, y, sb_w, mb_h, flags;
539 unsigned int w, h; 564 unsigned int w, h;
540 unsigned int max_width, max_height; 565 unsigned int max_width, max_height;
541 566
542 D_SIZE((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", 567 D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d",
543 TermWin.ncol, TermWin.nrow, szHint.width, 568 TermWin.ncol, TermWin.nrow, szHint.width,
544 szHint.height)); 569 szHint.height));
545 szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; 570 szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity;
546 szHint.win_gravity = NorthWestGravity; 571 szHint.win_gravity = NorthWestGravity;
547 /* szHint.min_aspect.x = szHint.min_aspect.y = 1; */ 572 /* szHint.min_aspect.x = szHint.min_aspect.y = 1; */
550 flags = 0; 575 flags = 0;
551 if (!parsed_geometry) 576 if (!parsed_geometry)
552 { 577 {
553 parsed_geometry = 1; 578 parsed_geometry = 1;
554 if (rs[Rs_geometry]) 579 if (rs[Rs_geometry])
555 flags = XParseGeometry(rs[Rs_geometry], &x, &y, &w, &h); 580 flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h);
556 if (flags & WidthValue) 581 if (flags & WidthValue)
557 { 582 {
558 TermWin.ncol = BOUND_POSITIVE_INT16(w); 583 TermWin.ncol = BOUND_POSITIVE_INT16 (w);
559 szHint.flags |= USSize; 584 szHint.flags |= USSize;
560 } 585 }
561 if (flags & HeightValue) 586 if (flags & HeightValue)
562 { 587 {
563 TermWin.nrow = BOUND_POSITIVE_INT16(h); 588 TermWin.nrow = BOUND_POSITIVE_INT16 (h);
564 szHint.flags |= USSize; 589 szHint.flags |= USSize;
565 } 590 }
566 if (flags & XValue) 591 if (flags & XValue)
567 { 592 {
568 szHint.x = x; 593 szHint.x = x;
597 622
598 sb_w = mb_h = 0; 623 sb_w = mb_h = 0;
599 window_vt_x = window_vt_y = 0; 624 window_vt_x = window_vt_y = 0;
600 if (scrollbar_visible ()) 625 if (scrollbar_visible ())
601 { 626 {
602 sb_w = scrollbar_TotalWidth(); 627 sb_w = scrollbar_TotalWidth ();
603 szHint.base_width += sb_w; 628 szHint.base_width += sb_w;
604 if (!(Options & Opt_scrollBar_right)) 629 if (! (Options & Opt_scrollBar_right))
605 window_vt_x = sb_w; 630 window_vt_x = sb_w;
606 } 631 }
607 if (menubar_visible ()) 632 if (menubar_visible ())
608 { 633 {
609 mb_h = menuBar_TotalHeight(); 634 mb_h = menuBar_TotalHeight ();
610 szHint.base_height += mb_h; 635 szHint.base_height += mb_h;
611 window_vt_y = mb_h; 636 window_vt_y = mb_h;
612 } 637 }
613 szHint.width_inc = TermWin.fwidth; 638 szHint.width_inc = TermWin.fwidth;
614 szHint.height_inc = TermWin.fheight; 639 szHint.height_inc = TermWin.fheight;
620 szHint.width = width; 645 szHint.width = width;
621 TermWin.width = width - szHint.base_width; 646 TermWin.width = width - szHint.base_width;
622 } 647 }
623 else 648 else
624 { 649 {
625 MIN_IT(TermWin.width, max_width); 650 MIN_IT (TermWin.width, max_width);
626 szHint.width = szHint.base_width + TermWin.width; 651 szHint.width = szHint.base_width + TermWin.width;
627 } 652 }
628 if (height && height - szHint.base_height < max_height) 653 if (height && height - szHint.base_height < max_height)
629 { 654 {
630 szHint.height = height; 655 szHint.height = height;
631 TermWin.height = height - szHint.base_height; 656 TermWin.height = height - szHint.base_height;
632 } 657 }
633 else 658 else
634 { 659 {
635 MIN_IT(TermWin.height, max_height); 660 MIN_IT (TermWin.height, max_height);
636 szHint.height = szHint.base_height + TermWin.height; 661 szHint.height = szHint.base_height + TermWin.height;
637 } 662 }
638 if (scrollbar_visible () && (Options & Opt_scrollBar_right)) 663 if (scrollbar_visible () && (Options & Opt_scrollBar_right))
639 window_sb_x = szHint.width - sb_w; 664 window_sb_x = szHint.width - sb_w;
640 665
641 if (recalc_x) 666 if (recalc_x)
642 szHint.x += (DisplayWidth (Xdisplay, DefaultScreen (Xdisplay)) 667 szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display))
643 - szHint.width - 2 * TermWin.ext_bwidth); 668 - szHint.width - 2 * TermWin.ext_bwidth);
644 if (recalc_y) 669 if (recalc_y)
645 szHint.y += (DisplayHeight (Xdisplay, DefaultScreen (Xdisplay)) 670 szHint.y += (DisplayHeight (display->display, DefaultScreen (display->display))
646 - szHint.height - 2 * TermWin.ext_bwidth); 671 - szHint.height - 2 * TermWin.ext_bwidth);
647 672
648 TermWin.ncol = TermWin.width / TermWin.fwidth; 673 TermWin.ncol = TermWin.width / TermWin.fwidth;
649 TermWin.nrow = TermWin.height / TermWin.fheight; 674 TermWin.nrow = TermWin.height / TermWin.fheight;
650 D_SIZE((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", 675 D_SIZE ((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d",
651 TermWin.ncol, TermWin.nrow, szHint.width, 676 TermWin.ncol, TermWin.nrow, szHint.width,
652 szHint.height)); 677 szHint.height));
653 return; 678 return;
654} 679}
655 680
671 ws.ws_xpixel = ws.ws_ypixel = 0; 696 ws.ws_xpixel = ws.ws_ypixel = 0;
672#ifndef DEBUG_SIZE 697#ifndef DEBUG_SIZE
673 (void)ioctl (cmd_fd, TIOCSWINSZ, &ws); 698 (void)ioctl (cmd_fd, TIOCSWINSZ, &ws);
674#else 699#else
675 if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0) 700 if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0)
676 D_SIZE((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); 701 D_SIZE ((stderr, "Failed to send TIOCSWINSZ to fd %d", fd));
677# ifdef SIGWINCH 702# ifdef SIGWINCH
678 else if (cmd_pid) /* force through to the command */ 703 else if (cmd_pid) /* force through to the command */
679 kill (cmd_pid, SIGWINCH); 704 kill (cmd_pid, SIGWINCH);
680# endif 705# endif
681#endif 706#endif
682} 707}
683 708
684/*----------------------------------------------------------------------*/ 709/*----------------------------------------------------------------------*/
685/* rxvt_change_font() - Switch to a new font */ 710/* rxvt_change_font () - Switch to a new font */
686/* 711/*
687 * init = 1 - initialize 712 * init = 1 - initialize
688 * 713 *
689 * fontname == FONT_UP - switch to bigger font 714 * fontname == FONT_UP - switch to bigger font
690 * fontname == FONT_DN - switch to smaller font 715 * fontname == FONT_DN - switch to smaller font
702/* xterm sequences - title, iconName, color (exptl) */ 727/* xterm sequences - title, iconName, color (exptl) */
703void 728void
704rxvt_term::set_title (const char *str) 729rxvt_term::set_title (const char *str)
705{ 730{
706#ifndef SMART_WINDOW_TITLE 731#ifndef SMART_WINDOW_TITLE
707 XStoreName(Xdisplay, TermWin.parent[0], str); 732 XStoreName (display->display, TermWin.parent[0], str);
708#else 733#else
709 char *name; 734 char *name;
710 735
711 if (XFetchName(Xdisplay, TermWin.parent[0], &name) == 0) 736 if (XFetchName (display->display, TermWin.parent[0], &name) == 0)
712 name = NULL; 737 name = NULL;
713 if (name == NULL || STRCMP(name, str)) 738 if (name == NULL || STRCMP (name, str))
714 XStoreName(Xdisplay, TermWin.parent[0], str); 739 XStoreName (display->display, TermWin.parent[0], str);
715 if (name) 740 if (name)
716 XFree(name); 741 XFree (name);
717#endif 742#endif
718} 743}
719 744
720void 745void
721rxvt_term::set_iconName (const char *str) 746rxvt_term::set_iconName (const char *str)
722{ 747{
723#ifndef SMART_WINDOW_TITLE 748#ifndef SMART_WINDOW_TITLE
724 XSetIconName(Xdisplay, TermWin.parent[0], str); 749 XSetIconName (display->display, TermWin.parent[0], str);
725#else 750#else
726 char *name; 751 char *name;
727 752
728 if (XGetIconName(Xdisplay, TermWin.parent[0], &name)) 753 if (XGetIconName (display->display, TermWin.parent[0], &name))
729 name = NULL; 754 name = NULL;
730 if (name == NULL || STRCMP(name, str)) 755 if (name == NULL || STRCMP (name, str))
731 XSetIconName(Xdisplay, TermWin.parent[0], str); 756 XSetIconName (display->display, TermWin.parent[0], str);
732 if (name) 757 if (name)
733 XFree(name); 758 XFree (name);
734#endif 759#endif
735} 760}
736 761
737#ifdef XTERM_COLOR_CHANGE 762#ifdef XTERM_COLOR_CHANGE
738void 763void
743 768
744 if (color == NULL || *color == '\0') 769 if (color == NULL || *color == '\0')
745 return; 770 return;
746 771
747 /* handle color aliases */ 772 /* handle color aliases */
748 if (isdigit(*color)) 773 if (isdigit (*color))
749 { 774 {
750 i = atoi(color); 775 i = atoi (color);
751 if (i >= 8 && i <= 15) 776 if (i >= 8 && i <= 15)
752 { /* bright colors */ 777 { /* bright colors */
753 i -= 8; 778 i -= 8;
754# ifndef NO_BRIGHTCOLOR 779# ifndef NO_BRIGHTCOLOR
755 PixColors[idx] = PixColors[minBrightCOLOR + i]; 780 PixColors[idx] = PixColors[minBrightCOLOR + i];
756 SET_PIXCOLOR(idx); 781 SET_PIXCOLOR (idx);
757 goto Done; 782 goto Done;
758# endif 783# endif
759 784
760 } 785 }
761 if (i >= 0 && i <= 7) 786 if (i >= 0 && i <= 7)
762 { /* normal colors */ 787 { /* normal colors */
763 PixColors[idx] = PixColors[minCOLOR + i]; 788 PixColors[idx] = PixColors[minCOLOR + i];
764 SET_PIXCOLOR(idx); 789 SET_PIXCOLOR (idx);
765 goto Done; 790 goto Done;
766 } 791 }
767 } 792 }
768 if (!rXParseAllocColor (& xcol, color)) 793 if (!rXParseAllocColor (& xcol, color))
769 return; 794 return;
770 /* XStoreColor (Xdisplay, XCMAP, XColor*); */ 795 /* XStoreColor (display->display, XCMAP, XColor*); */
771 796
772 /* 797 /*
773 * FIXME: should free colors here, but no idea how to do it so instead, 798 * FIXME: should free colors here, but no idea how to do it so instead,
774 * so just keep gobbling up the colormap 799 * so just keep gobbling up the colormap
775 */ 800 */
778 if (PixColors[idx] == PixColors[i]) 803 if (PixColors[idx] == PixColors[i])
779 break; 804 break;
780 if (i > Color_White) 805 if (i > Color_White)
781 { 806 {
782 /* fprintf (stderr, "XFreeColors: PixColors [%d] = %lu\n", idx, PixColors [idx]); */ 807 /* fprintf (stderr, "XFreeColors: PixColors [%d] = %lu\n", idx, PixColors [idx]); */
783 XFreeColors(Xdisplay, XCMAP, (PixColors + idx), 1, 808 XFreeColors (display->display, XCMAP, (PixColors + idx), 1,
784 DisplayPlanes(Xdisplay, Xscreen)); 809 DisplayPlanes (display->display, display->screen));
785 } 810 }
786# endif 811# endif
787 812
788 PixColors[idx] = xcol; 813 PixColors[idx] = xcol;
789 SET_PIXCOLOR(idx); 814 SET_PIXCOLOR (idx);
790 815
791 /* XSetWindowAttributes attr; */ 816 /* XSetWindowAttributes attr; */
792 /* Cursor cursor; */ 817 /* Cursor cursor; */
793Done: 818Done:
794 if (idx == Color_bg && !(Options & Opt_transparent)) 819 if (idx == Color_bg && ! (Options & Opt_transparent))
795 XSetWindowBackground(Xdisplay, TermWin.vt, 820 XSetWindowBackground (display->display, TermWin.vt,
796 PixColors[Color_bg]); 821 PixColors[Color_bg]);
797 822
798 /* handle Color_BD, scrollbar background, etc. */ 823 /* handle Color_BD, scrollbar background, etc. */
799 824
800 set_colorfgbg (); 825 set_colorfgbg ();
813#if TODO 838#if TODO
814 rxvt_color xcol[2]; 839 rxvt_color xcol[2];
815 840
816 xcol[0] = PixColors[Color_pointer]; 841 xcol[0] = PixColors[Color_pointer];
817 xcol[1] = PixColors[Color_bg]; 842 xcol[1] = PixColors[Color_bg];
818 XQueryColors (Xdisplay, XCMAP, xcol, 2); 843 XQueryColors (display->display, XCMAP, xcol, 2);
819 XRecolorCursor (Xdisplay, TermWin_cursor, &(xcol[0]), &(xcol[1])); 844 XRecolorCursor (display->display, TermWin_cursor, & (xcol[0]), & (xcol[1]));
820#endif 845#endif
821} 846}
822 847
823/*----------------------------------------------------------------------*/ 848/*----------------------------------------------------------------------*/
824/* 849/*
827void 852void
828rxvt_term::set_colorfgbg () 853rxvt_term::set_colorfgbg ()
829{ 854{
830 unsigned int i; 855 unsigned int i;
831 const char *xpmb = "\0"; 856 const char *xpmb = "\0";
832 char fstr[sizeof("default") + 1], bstr[sizeof("default") + 1]; 857 char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1];
833 858
834 env_colorfgbg = 859 env_colorfgbg =
835 (char *)rxvt_malloc(sizeof("COLORFGBG=default;default;bg") + 1); 860 (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1);
836 STRCPY(fstr, "default"); 861 STRCPY (fstr, "default");
837 STRCPY(bstr, "default"); 862 STRCPY (bstr, "default");
838 for (i = Color_Black; i <= Color_White; i++) 863 for (i = Color_Black; i <= Color_White; i++)
839 if (PixColors[Color_fg] == PixColors[i]) 864 if (PixColors[Color_fg] == PixColors[i])
840 { 865 {
841 sprintf(fstr, "%d", (i - Color_Black)); 866 sprintf (fstr, "%d", (i - Color_Black));
842 break; 867 break;
843 } 868 }
844 for (i = Color_Black; i <= Color_White; i++) 869 for (i = Color_Black; i <= Color_White; i++)
845 if (PixColors[Color_bg] == PixColors[i]) 870 if (PixColors[Color_bg] == PixColors[i])
846 { 871 {
847 sprintf(bstr, "%d", (i - Color_Black)); 872 sprintf (bstr, "%d", (i - Color_Black));
848#ifdef XPM_BACKGROUND 873#ifdef XPM_BACKGROUND
849 xpmb = "default;"; 874 xpmb = "default;";
850#endif 875#endif
851 break; 876 break;
852 } 877 }
853 sprintf(env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); 878 sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr);
854 putenv(env_colorfgbg); 879 putenv (env_colorfgbg);
855 880
856#ifndef NO_BRIGHTCOLOR 881#ifndef NO_BRIGHTCOLOR
857 colorfgbg = DEFAULT_RSTYLE; 882 colorfgbg = DEFAULT_RSTYLE;
858 for (i = minCOLOR; i <= maxCOLOR; i++) 883 for (i = minCOLOR; i <= maxCOLOR; i++)
859 { 884 {
860 if (PixColors[Color_fg] == PixColors[i]) 885 if (PixColors[Color_fg] == PixColors[i])
861 colorfgbg = SET_FGCOLOR(colorfgbg, i); 886 colorfgbg = SET_FGCOLOR (colorfgbg, i);
862 if (PixColors[Color_bg] == PixColors[i]) 887 if (PixColors[Color_bg] == PixColors[i])
863 colorfgbg = SET_BGCOLOR(colorfgbg, i); 888 colorfgbg = SET_BGCOLOR (colorfgbg, i);
864 } 889 }
865#endif 890#endif
866} 891}
867 892
868/*----------------------------------------------------------------------*/ 893/*----------------------------------------------------------------------*/
872 */ 897 */
873 898
874int 899int
875rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) 900rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour)
876{ 901{
877 if (!screen_in_out->set (this, colour)) 902 if (!screen_in_out->set (display, colour))
878 { 903 {
879 rxvt_print_error("can't allocate colour: %s", colour); 904 rxvt_print_error ("can't allocate colour: %s", colour);
880 return false; 905 return false;
881 } 906 }
882 907
883 return true; 908 return true;
884} 909}
894#ifdef SMART_RESIZE 919#ifdef SMART_RESIZE
895 int old_width = szHint.width, old_height = szHint.height; 920 int old_width = szHint.width, old_height = szHint.height;
896#endif 921#endif
897 922
898 window_calc (width, height); 923 window_calc (width, height);
899 XSetWMNormalHints (Xdisplay, TermWin.parent[0], &szHint); 924 XSetWMNormalHints (display->display, TermWin.parent[0], &szHint);
900 if (!ignoreparent) 925 if (!ignoreparent)
901 { 926 {
902#ifdef SMART_RESIZE 927#ifdef SMART_RESIZE
903 /* 928 /*
904 * resize by Marius Gedminas <marius.gedminas@uosis.mif.vu.lt> 929 * resize by Marius Gedminas <marius.gedminas@uosis.mif.vu.lt>
907 int x, y, x1, y1; 932 int x, y, x1, y1;
908 int dx, dy; 933 int dx, dy;
909 unsigned int unused_w1, unused_h1, unused_b1, unused_d1; 934 unsigned int unused_w1, unused_h1, unused_b1, unused_d1;
910 Window unused_cr; 935 Window unused_cr;
911 936
912 XTranslateCoordinates (Xdisplay, TermWin.parent[0], Xroot, 937 XTranslateCoordinates (display->display, TermWin.parent[0], display->root,
913 0, 0, &x, &y, &unused_cr); 938 0, 0, &x, &y, &unused_cr);
914 XGetGeometry (Xdisplay, TermWin.parent[0], &unused_cr, &x1, &y1, 939 XGetGeometry (display->display, TermWin.parent[0], &unused_cr, &x1, &y1,
915 &unused_w1, &unused_h1, &unused_b1, &unused_d1); 940 &unused_w1, &unused_h1, &unused_b1, &unused_d1);
916 /* 941 /*
917 * if Xroot isn't the parent window, a WM will probably have offset 942 * if display->root isn't the parent window, a WM will probably have offset
918 * our position for handles and decorations. Counter it 943 * our position for handles and decorations. Counter it
919 */ 944 */
920 if (x1 != x || y1 != y) 945 if (x1 != x || y1 != y)
921 { 946 {
922 x -= x1; 947 x -= x1;
923 y -= y1; 948 y -= y1;
924 } 949 }
925 950
926 x1 = (DisplayWidth (Xdisplay, Xscreen) - old_width) / 2; 951 x1 = (DisplayWidth (display->display, display->screen) - old_width) / 2;
927 y1 = (DisplayHeight (Xdisplay, Xscreen) - old_height) / 2; 952 y1 = (DisplayHeight (display->display, display->screen) - old_height) / 2;
928 dx = old_width - szHint.width; 953 dx = old_width - szHint.width;
929 dy = old_height - szHint.height; 954 dy = old_height - szHint.height;
930 955
931 /* Check position of the center of the window */ 956 /* Check position of the center of the window */
932 if (x < x1) /* left half */ 957 if (x < x1) /* left half */
936 if (y < y1) /* top half */ 961 if (y < y1) /* top half */
937 dy = 0; 962 dy = 0;
938 else if (y == y1) /* exact center */ 963 else if (y == y1) /* exact center */
939 dy /= 2; 964 dy /= 2;
940 965
941 XMoveResizeWindow (Xdisplay, TermWin.parent[0], x + dx, y + dy, 966 XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy,
942 szHint.width, szHint.height); 967 szHint.width, szHint.height);
943#else 968#else
944 XResizeWindow (Xdisplay, TermWin.parent[0], szHint.width, 969 XResizeWindow (display->display, TermWin.parent[0], szHint.width,
945 szHint.height); 970 szHint.height);
946#endif 971#endif
947 972
948 } 973 }
949 974
952 977
953 if (fix_screen || width != old_width || height != old_height) 978 if (fix_screen || width != old_width || height != old_height)
954 { 979 {
955 if (scrollbar_visible ()) 980 if (scrollbar_visible ())
956 { 981 {
957 XMoveResizeWindow (Xdisplay, scrollBar.win, window_sb_x, 982 XMoveResizeWindow (display->display, scrollBar.win, window_sb_x,
958 0, scrollbar_TotalWidth (), szHint.height); 983 0, scrollbar_TotalWidth (), szHint.height);
959 resize_scrollbar (); 984 resize_scrollbar ();
960 } 985 }
961 986
962 if (menubar_visible ()) 987 if (menubar_visible ())
963 XMoveResizeWindow (Xdisplay, menuBar.win, window_vt_x, 988 XMoveResizeWindow (display->display, menuBar.win, window_vt_x,
964 0, TermWin_TotalWidth (), menuBar_TotalHeight ()); 989 0, TermWin_TotalWidth (), menuBar_TotalHeight ());
965 990
966 XMoveResizeWindow (Xdisplay, TermWin.vt, window_vt_x, 991 XMoveResizeWindow (display->display, TermWin.vt, window_vt_x,
967 window_vt_y, TermWin_TotalWidth (), 992 window_vt_y, TermWin_TotalWidth (),
968 TermWin_TotalHeight ()); 993 TermWin_TotalHeight ());
969#ifdef RXVT_GRAPHICS 994#ifdef RXVT_GRAPHICS
970 if (old_height) 995 if (old_height)
971 Gr_Resize (old_width - szHint.base_width, 996 Gr_Resize (old_width - szHint.base_width,
990 TermWin.ncol = prev_ncol; // save b/c scr_blank_screen_mem uses this 1015 TermWin.ncol = prev_ncol; // save b/c scr_blank_screen_mem uses this
991 curr_screen = scr_change_screen (PRIMARY); 1016 curr_screen = scr_change_screen (PRIMARY);
992 TermWin.ncol = ncol; 1017 TermWin.ncol = ncol;
993 } 1018 }
994 1019
995 scr_reset(); 1020 scr_reset ();
996 1021
997 if (curr_screen >= 0) /* this is not the first time through */ 1022 if (curr_screen >= 0) /* this is not the first time through */
998 { 1023 {
999 scr_change_screen (curr_screen); 1024 scr_change_screen (curr_screen);
1000 selection_check (old_ncol != TermWin.ncol ? 4 : 0); 1025 selection_check (old_ncol != TermWin.ncol ? 4 : 0);
1018{ 1043{
1019 XWindowAttributes wattr; 1044 XWindowAttributes wattr;
1020 1045
1021 if (width == 0 || height == 0) 1046 if (width == 0 || height == 0)
1022 { 1047 {
1023 XGetWindowAttributes(Xdisplay, Xroot, &wattr); 1048 XGetWindowAttributes (display->display, display->root, &wattr);
1024 if (width == 0) 1049 if (width == 0)
1025 width = wattr.width - szHint.base_width; 1050 width = wattr.width - szHint.base_width;
1026 if (height == 0) 1051 if (height == 0)
1027 height = wattr.height - szHint.base_height; 1052 height = wattr.height - szHint.base_height;
1028 } 1053 }
1036 1061
1037/* -------------------------------------------------------------------- * 1062/* -------------------------------------------------------------------- *
1038 * - X INPUT METHOD ROUTINES - * 1063 * - X INPUT METHOD ROUTINES - *
1039 * -------------------------------------------------------------------- */ 1064 * -------------------------------------------------------------------- */
1040#ifdef USE_XIM 1065#ifdef USE_XIM
1066
1041void 1067void
1042rxvt_term::set_size (XRectangle *size) 1068rxvt_term::im_set_size (XRectangle *size)
1043{ 1069{
1044 size->x = TermWin.int_bwidth; 1070 size->x = TermWin.int_bwidth;
1045 size->y = TermWin.int_bwidth; 1071 size->y = TermWin.int_bwidth;
1046 size->width = Width2Pixel(TermWin.ncol); 1072 size->width = Width2Pixel (TermWin.ncol);
1047 size->height = Height2Pixel(TermWin.nrow); 1073 size->height = Height2Pixel (TermWin.nrow);
1048} 1074}
1049 1075
1050void 1076void
1051rxvt_term::set_color (unsigned long *fg, unsigned long *bg) 1077rxvt_term::im_set_color (unsigned long *fg, unsigned long *bg)
1052{ 1078{
1053 *fg = PixColors[Color_fg]; 1079 *fg = PixColors[Color_fg];
1054 *bg = PixColors[Color_bg]; 1080 *bg = PixColors[Color_bg];
1055} 1081}
1056 1082
1062 Atom atom; 1088 Atom atom;
1063 Window win; 1089 Window win;
1064 char server[IMBUFSIZ]; 1090 char server[IMBUFSIZ];
1065 1091
1066 /* get current locale modifier */ 1092 /* get current locale modifier */
1067 if ((p = XSetLocaleModifiers(NULL)) != NULL) 1093 if ((p = XSetLocaleModifiers (NULL)) != NULL)
1068 { 1094 {
1069 STRCPY(server, "@server="); 1095 STRCPY (server, "@server=");
1070 STRNCAT(server, &(p[4]), IMBUFSIZ - 9); /* skip "@im=" */ 1096 STRNCAT (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */
1071 if ((p = STRCHR(server + 1, '@')) != NULL) /* first one only */ 1097 if ((p = STRCHR (server + 1, '@')) != NULL) /* first one only */
1072 *p = '\0'; 1098 *p = '\0';
1073 1099
1074 atom = XInternAtom(Xdisplay, server, False); 1100 atom = XInternAtom (display->display, server, False);
1075 win = XGetSelectionOwner(Xdisplay, atom); 1101 win = XGetSelectionOwner (display->display, atom);
1076 if (win != None) 1102 if (win != None)
1077 return True; 1103 return True;
1078 } 1104 }
1079 return False; 1105 return False;
1080} 1106}
1084{ 1110{
1085 XPoint spot; 1111 XPoint spot;
1086 XVaNestedList preedit_attr; 1112 XVaNestedList preedit_attr;
1087 1113
1088 if (Input_Context == NULL 1114 if (Input_Context == NULL
1089 || !TermWin.focus || !(input_style & XIMPreeditPosition) 1115 || !TermWin.focus || ! (input_style & XIMPreeditPosition)
1090 || !(event_type == KeyPress 1116 || ! (event_type == KeyPress
1091 || event_type == Expose 1117 || event_type == Expose
1092 || event_type == NoExpose 1118 || event_type == NoExpose
1093 || event_type == SelectionNotify 1119 || event_type == SelectionNotify
1094 || event_type == ButtonRelease || event_type == FocusIn) 1120 || event_type == ButtonRelease || event_type == FocusIn)
1095 || !IMisRunning ()) 1121 || !IMisRunning ())
1096 return; 1122 return;
1097 1123
1098 set_position (&spot); 1124 im_set_position (&spot);
1099 1125
1100 preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL); 1126 preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL);
1101 XSetICValues(Input_Context, XNPreeditAttributes, preedit_attr, NULL); 1127 XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL);
1102 XFree(preedit_attr); 1128 XFree (preedit_attr);
1103} 1129}
1104 1130
1105void 1131void
1106rxvt_term::set_preedit_area (XRectangle * preedit_rect, XRectangle * status_rect, 1132rxvt_term::im_set_preedit_area (XRectangle * preedit_rect, XRectangle * status_rect,
1107 XRectangle * needed_rect) 1133 XRectangle * needed_rect)
1108{ 1134{
1109 int mbh, vtx = 0; 1135 int mbh, vtx = 0;
1110 1136
1111 if (scrollbar_visible () && !(Options & Opt_scrollBar_right)) 1137 if (scrollbar_visible () && ! (Options & Opt_scrollBar_right))
1112 vtx = scrollbar_TotalWidth(); 1138 vtx = scrollbar_TotalWidth ();
1113 1139
1114 mbh = menubar_visible () ? menuBar_TotalHeight() : 0; 1140 mbh = menubar_visible () ? menuBar_TotalHeight () : 0;
1115 mbh -= TermWin.lineSpace; 1141 mbh -= TermWin.lineSpace;
1116 1142
1117 preedit_rect->x = needed_rect->width + vtx; 1143 preedit_rect->x = needed_rect->width + vtx;
1118 preedit_rect->y = Height2Pixel(TermWin.nrow - 1) + mbh; 1144 preedit_rect->y = Height2Pixel (TermWin.nrow - 1) + mbh;
1119 1145
1120 preedit_rect->width = Width2Pixel(TermWin.ncol + 1) - needed_rect->width + vtx; 1146 preedit_rect->width = Width2Pixel (TermWin.ncol + 1) - needed_rect->width + vtx;
1121 preedit_rect->height = Height2Pixel(1); 1147 preedit_rect->height = Height2Pixel (1);
1122 1148
1123 status_rect->x = vtx; 1149 status_rect->x = vtx;
1124 status_rect->y = Height2Pixel(TermWin.nrow - 1) + mbh; 1150 status_rect->y = Height2Pixel (TermWin.nrow - 1) + mbh;
1125 1151
1126 status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel(TermWin.ncol + 1); 1152 status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel (TermWin.ncol + 1);
1127 status_rect->height = Height2Pixel(1); 1153 status_rect->height = Height2Pixel (1);
1128} 1154}
1129 1155
1130/* ARGSUSED */
1131/* EXTPROTO */
1132void 1156void
1133rxvt_IMDestroyCallback(XIM xim __attribute__ ((unused)), XPointer client_data 1157rxvt_term::im_destroy ()
1134 __attribute__ ((unused)), XPointer call_data
1135 __attribute__ ((unused)))
1136{ 1158{
1159 if (Input_Context)
1160 {
1161 XDestroyIC (Input_Context);
1137 GET_R->Input_Context = NULL; 1162 Input_Context = NULL;
1138 /* To avoid Segmentation Fault in C locale: Solaris only? */ 1163 }
1139 if (STRCMP (GET_R->locale, "C")) 1164
1140 XRegisterIMInstantiateCallback(GET_R->Xdisplay, NULL, NULL, NULL, 1165 if (input_method)
1141 rxvt_IMInstantiateCallback, NULL); 1166 {
1167 display->put_xim (input_method);
1168 input_method = 0;
1169 }
1142} 1170}
1143 1171
1144/* 1172/*
1145 * Try to open a XIM with the current modifiers, then see if we can 1173 * Try to open a XIM with the current modifiers, then see if we can
1146 * open a suitable preedit type 1174 * open a suitable preedit type
1147 */ 1175 */
1148bool 1176bool
1149rxvt_term::IM_get_IC () 1177rxvt_term::IM_get_IC (const char *modifiers)
1150{ 1178{
1151 int i, j, found; 1179 int i, j, found;
1152 XIM xim; 1180 XIM xim;
1153 XPoint spot; 1181 XPoint spot;
1154 XRectangle rect, status_rect, needed_rect; 1182 XRectangle rect, status_rect, needed_rect;
1155 unsigned long fg, bg; 1183 unsigned long fg, bg;
1156 const char *p; 1184 const char *p;
1157 char **s; 1185 char **s;
1158 XIMStyles *xim_styles; 1186 XIMStyles *xim_styles;
1159 XVaNestedList preedit_attr, status_attr; 1187 XVaNestedList preedit_attr, status_attr;
1160 XIMCallback ximcallback;
1161 1188
1189 if (! ((p = XSetLocaleModifiers (modifiers)) && *p))
1190 return false;
1191
1162 D_MAIN((stderr, "rxvt_IM_get_IC()")); 1192 D_MAIN ((stderr, "rxvt_IM_get_IC ()"));
1163 xim = XOpenIM (Xdisplay, NULL, NULL, NULL); 1193 input_method = display->get_xim (locale, modifiers);
1164 if (xim == NULL) 1194 if (input_method == NULL)
1165 return False; 1195 return false;
1196
1197 xim = input_method->xim;
1166 1198
1167 xim_styles = NULL; 1199 xim_styles = NULL;
1168 if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) 1200 if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL)
1169 || !xim_styles || !xim_styles->count_styles) 1201 || !xim_styles || !xim_styles->count_styles)
1170 { 1202 {
1171 XCloseIM(xim); 1203 display->put_xim (input_method);
1172 return False; 1204 return false;
1173 } 1205 }
1174 1206
1175 p = rs[Rs_preeditType] ? rs[Rs_preeditType] 1207 p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root";
1176 : "OverTheSpot,OffTheSpot,Root";
1177 s = rxvt_splitcommastring(p); 1208 s = rxvt_splitcommastring (p);
1178 for (i = found = 0; !found && s[i]; i++) 1209 for (i = found = 0; !found && s[i]; i++)
1179 { 1210 {
1180 if (!STRCMP(s[i], "OverTheSpot")) 1211 if (!STRCMP (s[i], "OverTheSpot"))
1181 input_style = (XIMPreeditPosition | XIMStatusNothing); 1212 input_style = (XIMPreeditPosition | XIMStatusNothing);
1182 else if (!STRCMP(s[i], "OffTheSpot")) 1213 else if (!STRCMP (s[i], "OffTheSpot"))
1183 input_style = (XIMPreeditArea | XIMStatusArea); 1214 input_style = (XIMPreeditArea | XIMStatusArea);
1184 else if (!STRCMP(s[i], "Root")) 1215 else if (!STRCMP (s[i], "Root"))
1185 input_style = (XIMPreeditNothing | XIMStatusNothing); 1216 input_style = (XIMPreeditNothing | XIMStatusNothing);
1186 1217
1187 for (j = 0; j < xim_styles->count_styles; j++) 1218 for (j = 0; j < xim_styles->count_styles; j++)
1188 if (input_style == xim_styles->supported_styles[j]) 1219 if (input_style == xim_styles->supported_styles[j])
1189 { 1220 {
1190 found = 1; 1221 found = 1;
1191 break; 1222 break;
1192 } 1223 }
1193 } 1224 }
1225
1194 for (i = 0; s[i]; i++) 1226 for (i = 0; s[i]; i++)
1195 free(s[i]); 1227 free (s[i]);
1228
1196 free(s); 1229 free (s);
1197 XFree(xim_styles); 1230 XFree (xim_styles);
1198 1231
1199 if (!found) 1232 if (!found)
1200 { 1233 {
1201 XCloseIM(xim); 1234 display->put_xim (input_method);
1202 return False; 1235 return false;
1203 } 1236 }
1204
1205 ximcallback.callback = rxvt_IMDestroyCallback;
1206
1207 /* XXX: not sure why we need this (as well as IC one below) */
1208 XSetIMValues(xim, XNDestroyCallback, &ximcallback, NULL);
1209 1237
1210 preedit_attr = status_attr = NULL; 1238 preedit_attr = status_attr = NULL;
1211 1239
1212 if (input_style & XIMPreeditPosition) 1240 if (input_style & XIMPreeditPosition)
1213 { 1241 {
1214 set_size (&rect); 1242 im_set_size (&rect);
1215 set_position (&spot); 1243 im_set_position (&spot);
1216 set_color (&fg, &bg); 1244 im_set_color (&fg, &bg);
1217 1245
1218 preedit_attr = XVaCreateNestedList(0, XNArea, &rect, 1246 preedit_attr = XVaCreateNestedList (0, XNArea, &rect,
1219 XNSpotLocation, &spot, 1247 XNSpotLocation, &spot,
1220 XNForeground, fg, XNBackground, bg, 1248 XNForeground, fg, XNBackground, bg,
1221 //XNFontSet, TermWin.fontset, 1249 //XNFontSet, TermWin.fontset,
1222 NULL); 1250 NULL);
1223 } 1251 }
1224 else if (input_style & XIMPreeditArea) 1252 else if (input_style & XIMPreeditArea)
1225 { 1253 {
1226 set_color (&fg, &bg); 1254 im_set_color (&fg, &bg);
1227 1255
1228 /* 1256 /*
1229 * The necessary width of preedit area is unknown 1257 * The necessary width of preedit area is unknown
1230 * until create input context. 1258 * until create input context.
1231 */ 1259 */
1232 needed_rect.width = 0; 1260 needed_rect.width = 0;
1233 1261
1234 set_preedit_area(&rect, &status_rect, &needed_rect); 1262 im_set_preedit_area (&rect, &status_rect, &needed_rect);
1235 1263
1236 preedit_attr = XVaCreateNestedList(0, XNArea, &rect, 1264 preedit_attr = XVaCreateNestedList (0, XNArea, &rect,
1237 XNForeground, fg, XNBackground, bg, 1265 XNForeground, fg, XNBackground, bg,
1238 //XNFontSet, TermWin.fontset, 1266 //XNFontSet, TermWin.fontset,
1239 NULL); 1267 NULL);
1240 status_attr = XVaCreateNestedList(0, XNArea, &status_rect, 1268 status_attr = XVaCreateNestedList (0, XNArea, &status_rect,
1241 XNForeground, fg, XNBackground, bg, 1269 XNForeground, fg, XNBackground, bg,
1242 //XNFontSet, TermWin.fontset, 1270 //XNFontSet, TermWin.fontset,
1243 NULL); 1271 NULL);
1244 } 1272 }
1273
1245 Input_Context = XCreateIC(xim, XNInputStyle, input_style, 1274 Input_Context = XCreateIC (xim, XNInputStyle, input_style,
1246 XNClientWindow, TermWin.parent[0], 1275 XNClientWindow, TermWin.parent[0],
1247 XNFocusWindow, TermWin.parent[0], 1276 XNFocusWindow, TermWin.parent[0],
1248 XNDestroyCallback, &ximcallback,
1249 preedit_attr ? XNPreeditAttributes : NULL, 1277 preedit_attr ? XNPreeditAttributes : NULL,
1250 preedit_attr, 1278 preedit_attr,
1251 status_attr ? XNStatusAttributes : NULL, 1279 status_attr ? XNStatusAttributes : NULL,
1252 status_attr, NULL); 1280 status_attr, NULL);
1253 if (preedit_attr) 1281 if (preedit_attr) XFree (preedit_attr);
1254 XFree(preedit_attr); 1282 if (status_attr) XFree (status_attr);
1255 if (status_attr) 1283
1256 XFree(status_attr);
1257 if (Input_Context == NULL) 1284 if (Input_Context == NULL)
1258 { 1285 {
1259 rxvt_print_error("failed to create input context"); 1286 rxvt_print_error ("failed to create input context");
1260 XCloseIM(xim); 1287 display->put_xim (input_method);
1261 return False; 1288 return false;
1262 } 1289 }
1290
1263 if (input_style & XIMPreeditArea) 1291 if (input_style & XIMPreeditArea)
1264 IMSetStatusPosition (); 1292 IMSetStatusPosition ();
1293
1265 D_MAIN((stderr, "rxvt_IM_get_IC() - successful connection")); 1294 D_MAIN ((stderr, "rxvt_IM_get_IC () - successful connection"));
1266 return True; 1295 return true;
1267} 1296}
1268 1297
1269/*
1270 * X manual pages and include files don't match on some systems:
1271 * some think this is an XIDProc and others an XIMProc so we can't
1272 * use the first argument - need to update this to be nice for
1273 * both types via some sort of configure detection
1274 */
1275/* ARGSUSED */
1276/* EXTPROTO */
1277void 1298void
1278rxvt_IMInstantiateCallback(Display * unused 1299rxvt_term::im_cb ()
1279 __attribute__ ((unused)), XPointer client_data
1280 __attribute__ ((unused)), XPointer call_data
1281 __attribute__ ((unused)))
1282{ 1300{
1283 int i, found, had_im; 1301 int i, found, had_im;
1284 const char *p; 1302 const char *p;
1285 char **s; 1303 char **s;
1286 char buf[IMBUFSIZ]; 1304 char buf[IMBUFSIZ];
1287 1305
1306 im_destroy ();
1307
1288 D_MAIN((stderr, "rxvt_IMInstantiateCallback()")); 1308 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()"));
1289 if (GET_R->Input_Context) 1309 if (Input_Context)
1290 return; 1310 return;
1291 1311
1292#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) 1312#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
1293 if (GET_R->rs[Rs_imLocale]) 1313 if (rs[Rs_imLocale])
1294 setlocale (LC_CTYPE, GET_R->rs[Rs_imLocale]); 1314 setlocale (LC_CTYPE, rs[Rs_imLocale]);
1295#endif 1315#endif
1296 1316
1297 p = GET_R->rs[Rs_inputMethod]; 1317 p = rs[Rs_inputMethod];
1298 if (p && *p) 1318 if (p && *p)
1299 { 1319 {
1300 bool found = false; 1320 bool found = false;
1301 1321
1302 s = rxvt_splitcommastring (p); 1322 s = rxvt_splitcommastring (p);
1304 { 1324 {
1305 if (*s[i]) 1325 if (*s[i])
1306 { 1326 {
1307 STRCPY (buf, "@im="); 1327 STRCPY (buf, "@im=");
1308 STRNCAT (buf, s[i], IMBUFSIZ - 5); 1328 STRNCAT (buf, s[i], IMBUFSIZ - 5);
1309 if ((p = XSetLocaleModifiers (buf)) && *p && GET_R->IM_get_IC ()) 1329 if (IM_get_IC (buf))
1310 { 1330 {
1311 found = true; 1331 found = true;
1312 break; 1332 break;
1313 } 1333 }
1314 } 1334 }
1315 } 1335 }
1316 for (i = 0; s[i]; i++) 1336 for (i = 0; s[i]; i++)
1317 free(s[i]); 1337 free (s[i]);
1318 free(s); 1338 free (s);
1319 1339
1320 if (found) 1340 if (found)
1321 goto done; 1341 goto done;
1322 } 1342 }
1323 1343
1324 /* try with XMODIFIERS env. var. */ 1344 /* try with XMODIFIERS env. var. */
1325 if ((p = XSetLocaleModifiers ("")) && *p 1345 if (IM_get_IC (""))
1326 && GET_R->IM_get_IC ())
1327 goto done; 1346 goto done;
1328 1347
1329 /* try with no modifiers base IF the user didn't specify an IM */ 1348 /* try with no modifiers base IF the user didn't specify an IM */
1330 if ((p = XSetLocaleModifiers ("@im=none")) && *p 1349 if (IM_get_IC ("@im=none"))
1331 && GET_R->IM_get_IC () == True)
1332 goto done; 1350 goto done;
1333 1351
1334done: 1352done:
1335#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) 1353#if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE)
1336 if (GET_R->rs[Rs_imLocale]) 1354 if (rs[Rs_imLocale])
1337 setlocale (LC_CTYPE, GET_R->locale); 1355 setlocale (LC_CTYPE, locale);
1338#endif 1356#endif
1339} 1357}
1340 1358
1341void 1359void
1342rxvt_term::IMSetStatusPosition () 1360rxvt_term::IMSetStatusPosition ()
1343{ 1361{
1344 XRectangle preedit_rect, status_rect, *needed_rect; 1362 XRectangle preedit_rect, status_rect, *needed_rect;
1345 XVaNestedList preedit_attr, status_attr; 1363 XVaNestedList preedit_attr, status_attr;
1346 1364
1347 if (Input_Context == NULL 1365 if (Input_Context == NULL
1348 || !TermWin.focus || !(input_style & XIMPreeditArea) 1366 || !TermWin.focus || ! (input_style & XIMPreeditArea)
1349 || !IMisRunning ()) 1367 || !IMisRunning ())
1350 return; 1368 return;
1351 1369
1352 /* Getting the necessary width of preedit area */ 1370 /* Getting the necessary width of preedit area */
1353 status_attr = XVaCreateNestedList(0, XNAreaNeeded, &needed_rect, NULL); 1371 status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL);
1354 XGetICValues(Input_Context, XNStatusAttributes, status_attr, NULL); 1372 XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL);
1355 XFree(status_attr); 1373 XFree (status_attr);
1356 1374
1357 set_preedit_area(&preedit_rect, &status_rect, needed_rect); 1375 im_set_preedit_area (&preedit_rect, &status_rect, needed_rect);
1358 1376
1359 preedit_attr = XVaCreateNestedList(0, XNArea, &preedit_rect, NULL); 1377 preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL);
1360 status_attr = XVaCreateNestedList(0, XNArea, &status_rect, NULL); 1378 status_attr = XVaCreateNestedList (0, XNArea, &status_rect, NULL);
1361 1379
1362 XSetICValues(Input_Context, 1380 XSetICValues (Input_Context,
1363 XNPreeditAttributes, preedit_attr, 1381 XNPreeditAttributes, preedit_attr,
1364 XNStatusAttributes, status_attr, NULL); 1382 XNStatusAttributes, status_attr, NULL);
1365 1383
1366 XFree(preedit_attr); 1384 XFree (preedit_attr);
1367 XFree(status_attr); 1385 XFree (status_attr);
1368} 1386}
1369#endif /* USE_XIM */ 1387#endif /* USE_XIM */
1370 1388
1371/*----------------------------------------------------------------------*/ 1389/*----------------------------------------------------------------------*/
1372rxvt_t rxvt_current_term; 1390rxvt_t rxvt_current_term;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines