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.20 by pcg, Fri Jan 16 16:34:56 2004 UTC vs.
Revision 1.28 by pcg, Mon Feb 9 22:45:29 2004 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines