1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*--------------------------------*-C-*---------------------------------*; |
2 | * File: main.c |
2 | * File: main.c |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * |
4 | * |
5 | * All portions of code are copyright by their respective author/s. |
5 | * All portions of code are copyright by their respective author/s. |
6 | * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> |
6 | * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> |
… | |
… | |
90 | text_blink_ev (this, &rxvt_term::text_blink_cb), |
90 | text_blink_ev (this, &rxvt_term::text_blink_cb), |
91 | #endif |
91 | #endif |
92 | #ifdef POINTER_BLANK |
92 | #ifdef POINTER_BLANK |
93 | pointer_ev (this, &rxvt_term::pointer_cb), |
93 | pointer_ev (this, &rxvt_term::pointer_cb), |
94 | #endif |
94 | #endif |
|
|
95 | #ifdef USE_XIM |
|
|
96 | im_ev (this, &rxvt_term::im_cb), |
|
|
97 | #endif |
95 | check_ev (this, &rxvt_term::check_cb), |
98 | check_ev (this, &rxvt_term::check_cb), |
96 | destroy_ev (this, &rxvt_term::destroy_cb), |
99 | destroy_ev (this, &rxvt_term::destroy_cb), |
97 | pty_ev (this, &rxvt_term::pty_cb), |
100 | pty_ev (this, &rxvt_term::pty_cb), |
98 | incr_ev (this, &rxvt_term::incr_cb), |
101 | incr_ev (this, &rxvt_term::incr_cb) |
99 | #ifdef USE_XIM |
|
|
100 | im_ev (this, &rxvt_term::im_cb) |
|
|
101 | #endif |
|
|
102 | { |
102 | { |
103 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
103 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
104 | } |
104 | } |
105 | |
105 | |
106 | rxvt_term::~rxvt_term () |
106 | rxvt_term::~rxvt_term () |
107 | { |
107 | { |
108 | if (cmd_fd >= 0) |
108 | if (cmd_fd >= 0) |
109 | close (cmd_fd); |
109 | close (cmd_fd); |
110 | |
110 | |
|
|
111 | #ifndef NO_SETOWNER_TTYDEV |
|
|
112 | privileged_ttydev (RESTORE); |
|
|
113 | #endif |
|
|
114 | #ifdef UTMP_SUPPORT |
|
|
115 | privileged_utmp (RESTORE); |
|
|
116 | #endif |
|
|
117 | |
|
|
118 | delete TermWin.fontset; |
|
|
119 | |
|
|
120 | if (display) |
|
|
121 | if (TermWin.parent[0]) |
|
|
122 | XDestroyWindow (display->display, TermWin.parent[0]); |
|
|
123 | |
|
|
124 | // TODO: free pixcolours, colours should become part of rxvt_display |
|
|
125 | |
|
|
126 | delete PixColors; |
|
|
127 | |
|
|
128 | displays.put (display); |
|
|
129 | |
111 | scr_release (); |
130 | scr_release (); |
112 | |
131 | |
|
|
132 | free (env_windowid); |
|
|
133 | free (env_display); |
|
|
134 | free (env_term); |
|
|
135 | free (env_colorfgbg); |
113 | free (locale); |
136 | free (locale); |
114 | free (codeset); |
137 | free (codeset); |
115 | |
138 | |
116 | #ifndef NO_SETOWNER_TTYDEV |
139 | delete envv; |
117 | privileged_ttydev (RESTORE); |
140 | delete argv; |
118 | #endif |
|
|
119 | #ifdef UTMP_SUPPORT |
|
|
120 | privileged_utmp (RESTORE); |
|
|
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 | } |
141 | } |
130 | |
142 | |
131 | void |
143 | void |
132 | rxvt_term::destroy () |
144 | rxvt_term::destroy () |
133 | { |
145 | { |
134 | if (display) |
146 | if (display) |
135 | { |
147 | { |
136 | if (TermWin.parent[0]) |
|
|
137 | XDestroyWindow (display->display, TermWin.parent[0]); |
|
|
138 | |
|
|
139 | rootwin_ev.stop (display); |
148 | rootwin_ev.stop (display); |
140 | termwin_ev.stop (display); |
149 | termwin_ev.stop (display); |
141 | vt_ev.stop (display); |
150 | vt_ev.stop (display); |
142 | |
|
|
143 | #ifdef USE_XIM |
151 | #ifdef USE_XIM |
144 | im_destroy (); |
152 | im_destroy (); |
145 | im_ev.stop (display); |
153 | im_ev.stop (display); |
146 | #endif |
154 | #endif |
147 | #ifdef HAVE_SCROLLBARS |
155 | #ifdef HAVE_SCROLLBARS |
… | |
… | |
174 | |
182 | |
175 | delete this; |
183 | delete this; |
176 | } |
184 | } |
177 | |
185 | |
178 | /*----------------------------------------------------------------------*/ |
186 | /*----------------------------------------------------------------------*/ |
179 | /* rxvt_init() */ |
187 | /* rxvt_init () */ |
180 | /* LIBPROTO */ |
188 | /* LIBPROTO */ |
181 | rxvt_t |
189 | rxvt_t |
182 | rxvt_init (int argc, const char *const *argv) |
190 | rxvt_init (int argc, const char *const *argv) |
183 | { |
191 | { |
184 | SET_R (new rxvt_term); |
192 | SET_R (new rxvt_term); |
… | |
… | |
190 | } |
198 | } |
191 | |
199 | |
192 | return GET_R; |
200 | return GET_R; |
193 | } |
201 | } |
194 | |
202 | |
195 | static int (*old_xerror_handler)(Display *dpy, XErrorEvent *event); |
203 | static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event); |
196 | |
204 | |
197 | void |
205 | void |
198 | rxvt_init_signals () |
206 | rxvt_init_signals () |
199 | { |
207 | { |
200 | /* install exit handler for cleanup */ |
208 | /* install exit handler for cleanup */ |
201 | #if 0 |
209 | #if 0 |
202 | #ifdef HAVE_ATEXIT |
210 | #ifdef HAVE_ATEXIT |
203 | atexit(rxvt_clean_exit); |
211 | atexit (rxvt_clean_exit); |
204 | #else |
212 | #else |
205 | #endif |
213 | #endif |
206 | #endif |
214 | #endif |
207 | |
215 | |
208 | struct sigaction sa; |
216 | struct sigaction sa; |
… | |
… | |
258 | #ifdef RXVT_GRAPHICS |
266 | #ifdef RXVT_GRAPHICS |
259 | Gr_reset (); /* reset graphics */ |
267 | Gr_reset (); /* reset graphics */ |
260 | #endif |
268 | #endif |
261 | |
269 | |
262 | #if 0 |
270 | #if 0 |
263 | #ifdef DEBUG_X |
|
|
264 | XSynchronize(display->display, True); |
271 | XSynchronize (display->display, True); |
265 | #endif |
|
|
266 | #endif |
272 | #endif |
267 | |
273 | |
268 | #ifdef HAVE_SCROLLBARS |
274 | #ifdef HAVE_SCROLLBARS |
269 | if (Options & Opt_scrollBar) |
275 | if (Options & Opt_scrollBar) |
270 | resize_scrollbar (); /* create and map scrollbar */ |
276 | resize_scrollbar (); /* create and map scrollbar */ |
271 | #endif |
277 | #endif |
272 | #if (MENUBAR_MAX) |
278 | #if (MENUBAR_MAX) |
273 | if (menubar_visible(r)) |
279 | if (menubar_visible (r)) |
274 | XMapWindow (display->display, menuBar.win); |
280 | XMapWindow (display->display, menuBar.win); |
275 | #endif |
281 | #endif |
276 | #ifdef TRANSPARENT |
282 | #ifdef TRANSPARENT |
277 | if (Options & Opt_transparent) |
283 | if (Options & Opt_transparent) |
278 | { |
284 | { |
… | |
… | |
284 | rootwin_ev.start (display, display->root); |
290 | rootwin_ev.start (display, display->root); |
285 | |
291 | |
286 | XMapWindow (display->display, TermWin.vt); |
292 | XMapWindow (display->display, TermWin.vt); |
287 | XMapWindow (display->display, TermWin.parent[0]); |
293 | XMapWindow (display->display, TermWin.parent[0]); |
288 | |
294 | |
289 | init_env (); |
|
|
290 | init_command (cmd_argv); |
295 | init_command (cmd_argv); |
291 | |
296 | |
292 | pty_ev.start (cmd_fd, EVENT_READ); |
297 | pty_ev.start (cmd_fd, EVENT_READ); |
293 | |
298 | |
294 | check_ev.start (); |
299 | check_ev.start (); |
… | |
… | |
303 | * Catch a SIGCHLD signal and exit if the direct child has died |
308 | * Catch a SIGCHLD signal and exit if the direct child has died |
304 | */ |
309 | */ |
305 | /* ARGSUSED */ |
310 | /* ARGSUSED */ |
306 | /* EXTPROTO */ |
311 | /* EXTPROTO */ |
307 | RETSIGTYPE |
312 | RETSIGTYPE |
308 | rxvt_Child_signal(int sig __attribute__ ((unused))) |
313 | rxvt_Child_signal (int sig __attribute__ ((unused))) |
309 | { |
314 | { |
310 | int pid, save_errno = errno; |
315 | int pid, save_errno = errno; |
311 | while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR) |
316 | while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR) |
312 | ; |
317 | ; |
313 | errno = save_errno; |
318 | errno = save_errno; |
… | |
… | |
321 | /* |
326 | /* |
322 | * Catch a fatal signal and tidy up before quitting |
327 | * Catch a fatal signal and tidy up before quitting |
323 | */ |
328 | */ |
324 | /* EXTPROTO */ |
329 | /* EXTPROTO */ |
325 | RETSIGTYPE |
330 | RETSIGTYPE |
326 | rxvt_Exit_signal(int sig) |
331 | rxvt_Exit_signal (int sig) |
327 | { |
332 | { |
328 | signal (sig, SIG_DFL); |
333 | signal (sig, SIG_DFL); |
329 | #ifdef DEBUG_CMD |
334 | #ifdef DEBUG_CMD |
330 | rxvt_print_error ("signal %d", sig); |
335 | rxvt_print_error ("signal %d", sig); |
331 | #endif |
336 | #endif |
332 | rxvt_clean_exit(); |
337 | rxvt_clean_exit (); |
333 | kill (getpid (), sig); |
338 | kill (getpid (), sig); |
334 | } |
339 | } |
335 | |
340 | |
336 | /* INTPROTO */ |
341 | /* INTPROTO */ |
337 | int |
342 | int |
… | |
… | |
365 | /* ------------------------------------------------------------------------- * |
370 | /* ------------------------------------------------------------------------- * |
366 | * MEMORY ALLOCATION WRAPPERS * |
371 | * MEMORY ALLOCATION WRAPPERS * |
367 | * ------------------------------------------------------------------------- */ |
372 | * ------------------------------------------------------------------------- */ |
368 | /* EXTPROTO */ |
373 | /* EXTPROTO */ |
369 | void * |
374 | void * |
370 | rxvt_malloc(size_t size) |
375 | rxvt_malloc (size_t size) |
371 | { |
376 | { |
372 | void *p; |
377 | void *p; |
373 | |
378 | |
374 | p = malloc(size); |
379 | p = malloc (size); |
375 | if (p) |
380 | if (p) |
376 | return p; |
381 | return p; |
377 | |
382 | |
378 | fprintf(stderr, APL_NAME ": memory allocation failure. Aborting"); |
383 | fprintf (stderr, APL_NAME ": memory allocation failure. Aborting"); |
379 | rxvt_clean_exit(); |
384 | rxvt_clean_exit (); |
380 | exit(EXIT_FAILURE); |
385 | exit (EXIT_FAILURE); |
381 | /* NOTREACHED */ |
386 | /* NOTREACHED */ |
382 | } |
387 | } |
383 | |
388 | |
384 | /* EXTPROTO */ |
389 | /* EXTPROTO */ |
385 | void * |
390 | void * |
386 | rxvt_calloc(size_t number, size_t size) |
391 | rxvt_calloc (size_t number, size_t size) |
387 | { |
392 | { |
388 | void *p; |
393 | void *p; |
389 | |
394 | |
390 | p = calloc(number, size); |
395 | p = calloc (number, size); |
391 | if (p) |
396 | if (p) |
392 | return p; |
397 | return p; |
393 | |
398 | |
394 | fprintf(stderr, APL_NAME ": memory allocation failure. Aborting"); |
399 | fprintf (stderr, APL_NAME ": memory allocation failure. Aborting"); |
395 | rxvt_clean_exit(); |
400 | rxvt_clean_exit (); |
396 | exit(EXIT_FAILURE); |
401 | exit (EXIT_FAILURE); |
397 | /* NOTREACHED */ |
402 | /* NOTREACHED */ |
398 | } |
403 | } |
399 | |
404 | |
400 | /* EXTPROTO */ |
405 | /* EXTPROTO */ |
401 | void * |
406 | void * |
402 | rxvt_realloc(void *ptr, size_t size) |
407 | rxvt_realloc (void *ptr, size_t size) |
403 | { |
408 | { |
404 | void *p; |
409 | void *p; |
405 | |
410 | |
406 | if (ptr) |
411 | if (ptr) |
407 | p = realloc(ptr, size); |
412 | p = realloc (ptr, size); |
408 | else |
413 | else |
409 | p = malloc(size); |
414 | p = malloc (size); |
410 | if (p) |
415 | if (p) |
411 | return p; |
416 | return p; |
412 | |
417 | |
413 | fprintf(stderr, APL_NAME ": memory allocation failure. Aborting"); |
418 | fprintf (stderr, APL_NAME ": memory allocation failure. Aborting"); |
414 | rxvt_clean_exit(); |
419 | rxvt_clean_exit (); |
415 | exit(EXIT_FAILURE); |
420 | exit (EXIT_FAILURE); |
416 | /* NOTREACHED */ |
421 | /* NOTREACHED */ |
417 | } |
422 | } |
418 | |
423 | |
419 | /* ------------------------------------------------------------------------- * |
424 | /* ------------------------------------------------------------------------- * |
420 | * PRIVILEGED OPERATIONS * |
425 | * PRIVILEGED OPERATIONS * |
… | |
… | |
423 | void |
428 | void |
424 | rxvt_term::privileges (int mode) |
429 | rxvt_term::privileges (int mode) |
425 | { |
430 | { |
426 | #if ! defined(__CYGWIN32__) |
431 | #if ! defined(__CYGWIN32__) |
427 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
432 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
428 | /* setreuid() is the poor man's setuid(), seteuid() */ |
433 | /* setreuid () is the poor man's setuid (), seteuid () */ |
429 | # define seteuid(a) setreuid(-1, (a)) |
434 | # define seteuid(a) setreuid(-1, (a)) |
430 | # define setegid(a) setregid(-1, (a)) |
435 | # define setegid(a) setregid(-1, (a)) |
431 | # define HAVE_SETEUID |
436 | # define HAVE_SETEUID |
432 | # endif |
437 | # endif |
433 | # ifdef HAVE_SETEUID |
438 | # ifdef HAVE_SETEUID |
… | |
… | |
436 | case IGNORE: |
441 | case IGNORE: |
437 | /* |
442 | /* |
438 | * change effective uid/gid - not real uid/gid - so we can switch |
443 | * change effective uid/gid - not real uid/gid - so we can switch |
439 | * back to root later, as required |
444 | * back to root later, as required |
440 | */ |
445 | */ |
441 | seteuid(getuid()); |
446 | seteuid (getuid ()); |
442 | setegid(getgid()); |
447 | setegid (getgid ()); |
443 | break; |
448 | break; |
444 | case SAVE: |
449 | case SAVE: |
445 | euid = geteuid(); |
450 | euid = geteuid (); |
446 | egid = getegid(); |
451 | egid = getegid (); |
447 | break; |
452 | break; |
448 | case RESTORE: |
453 | case RESTORE: |
449 | seteuid(euid); |
454 | seteuid (euid); |
450 | setegid(egid); |
455 | setegid (egid); |
451 | break; |
456 | break; |
452 | } |
457 | } |
453 | # else |
458 | # else |
454 | switch (mode) |
459 | switch (mode) |
455 | { |
460 | { |
456 | case IGNORE: |
461 | case IGNORE: |
457 | setuid(getuid()); |
462 | setuid (getuid ()); |
458 | setgid(getgid()); |
463 | setgid (getgid ()); |
459 | /* FALLTHROUGH */ |
464 | /* FALLTHROUGH */ |
460 | case SAVE: |
465 | case SAVE: |
461 | /* FALLTHROUGH */ |
466 | /* FALLTHROUGH */ |
462 | case RESTORE: |
467 | case RESTORE: |
463 | break; |
468 | break; |
… | |
… | |
468 | |
473 | |
469 | #ifdef UTMP_SUPPORT |
474 | #ifdef UTMP_SUPPORT |
470 | void |
475 | void |
471 | rxvt_term::privileged_utmp (char action) |
476 | rxvt_term::privileged_utmp (char action) |
472 | { |
477 | { |
473 | D_MAIN((stderr, "rxvt_privileged_utmp(%c); waiting for: %c (pid: %d)", |
478 | D_MAIN ((stderr, "rxvt_privileged_utmp (%c); waiting for: %c (pid: %d)", |
474 | action, next_utmp_action, getpid())); |
479 | action, next_utmp_action, getpid ())); |
475 | if (next_utmp_action != action || (action != SAVE && action != RESTORE) |
480 | if (next_utmp_action != action || (action != SAVE && action != RESTORE) |
476 | || (Options & Opt_utmpInhibit) |
481 | || (Options & Opt_utmpInhibit) |
477 | || ttydev == NULL || *ttydev == '\0') |
482 | || ttydev == NULL || *ttydev == '\0') |
478 | return; |
483 | return; |
479 | |
484 | |
… | |
… | |
494 | |
499 | |
495 | #ifndef NO_SETOWNER_TTYDEV |
500 | #ifndef NO_SETOWNER_TTYDEV |
496 | void |
501 | void |
497 | rxvt_term::privileged_ttydev (char action) |
502 | rxvt_term::privileged_ttydev (char action) |
498 | { |
503 | { |
499 | D_MAIN((stderr, |
504 | D_MAIN ((stderr, |
500 | "privileged_ttydev (%c); waiting for: %c (pid: %d)", |
505 | "privileged_ttydev (%c); waiting for: %c (pid: %d)", |
501 | action, next_tty_action, getpid())); |
506 | action, next_tty_action, getpid ())); |
502 | if (next_tty_action != action || (action != SAVE && action != RESTORE) |
507 | if (next_tty_action != action || (action != SAVE && action != RESTORE) |
503 | || ttydev == NULL || *ttydev == '\0') |
508 | || ttydev == NULL || *ttydev == '\0') |
504 | return; |
509 | return; |
505 | |
510 | |
506 | privileges (RESTORE); |
511 | privileges (RESTORE); |
507 | |
512 | |
508 | if (action == SAVE) |
513 | if (action == SAVE) |
509 | { |
514 | { |
510 | next_tty_action = RESTORE; |
515 | next_tty_action = RESTORE; |
511 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
516 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
512 | /* store original tty status for restoration rxvt_clean_exit() -- rgg 04/12/95 */ |
517 | /* store original tty status for restoration rxvt_clean_exit () -- rgg 04/12/95 */ |
513 | if (lstat(ttydev, &ttyfd_stat) < 0) /* you lose out */ |
518 | if (lstat (ttydev, &ttyfd_stat) < 0) /* you lose out */ |
514 | next_tty_action = IGNORE; |
519 | next_tty_action = IGNORE; |
515 | else |
520 | else |
516 | # endif |
521 | # endif |
517 | |
522 | |
518 | { |
523 | { |
519 | chown(ttydev, getuid(), ttygid); /* fail silently */ |
524 | chown (ttydev, getuid (), ttygid); /* fail silently */ |
520 | chmod(ttydev, ttymode); |
525 | chmod (ttydev, ttymode); |
521 | # ifdef HAVE_REVOKE |
526 | # ifdef HAVE_REVOKE |
522 | revoke(ttydev); |
527 | revoke (ttydev); |
523 | # endif |
528 | # endif |
524 | |
529 | |
525 | } |
530 | } |
526 | } |
531 | } |
527 | else |
532 | else |
528 | { /* action == RESTORE */ |
533 | { /* action == RESTORE */ |
529 | next_tty_action = IGNORE; |
534 | next_tty_action = IGNORE; |
530 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
535 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
531 | chmod(ttydev, ttyfd_stat.st_mode); |
536 | chmod (ttydev, ttyfd_stat.st_mode); |
532 | chown(ttydev, ttyfd_stat.st_uid, ttyfd_stat.st_gid); |
537 | chown (ttydev, ttyfd_stat.st_uid, ttyfd_stat.st_gid); |
533 | # else |
538 | # else |
534 | chmod(ttydev, |
539 | chmod (ttydev, |
535 | (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)); |
540 | (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)); |
536 | chown(ttydev, 0, 0); |
541 | chown (ttydev, 0, 0); |
537 | # endif |
542 | # endif |
538 | |
543 | |
539 | } |
544 | } |
540 | |
545 | |
541 | privileges (IGNORE); |
546 | privileges (IGNORE); |
542 | |
547 | |
543 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
548 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
544 | D_MAIN((stderr, "%s \"%s\": mode %03o, uid %d, gid %d", |
549 | D_MAIN ((stderr, "%s \"%s\": mode %03o, uid %d, gid %d", |
545 | action == RESTORE ? "Restoring" : (action == |
550 | action == RESTORE ? "Restoring" : (action == |
546 | SAVE ? "Saving" : |
551 | SAVE ? "Saving" : |
547 | "UNKNOWN ERROR for"), ttydev, |
552 | "UNKNOWN ERROR for"), ttydev, |
548 | ttyfd_stat.st_mode, ttyfd_stat.st_uid, |
553 | ttyfd_stat.st_mode, ttyfd_stat.st_uid, |
549 | ttyfd_stat.st_gid)); |
554 | ttyfd_stat.st_gid)); |
… | |
… | |
562 | short recalc_x, recalc_y; |
567 | short recalc_x, recalc_y; |
563 | int x, y, sb_w, mb_h, flags; |
568 | int x, y, sb_w, mb_h, flags; |
564 | unsigned int w, h; |
569 | unsigned int w, h; |
565 | unsigned int max_width, max_height; |
570 | unsigned int max_width, max_height; |
566 | |
571 | |
567 | D_SIZE((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
572 | D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
568 | TermWin.ncol, TermWin.nrow, szHint.width, |
573 | TermWin.ncol, TermWin.nrow, szHint.width, |
569 | szHint.height)); |
574 | szHint.height)); |
570 | szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; |
575 | szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; |
571 | szHint.win_gravity = NorthWestGravity; |
576 | szHint.win_gravity = NorthWestGravity; |
572 | /* szHint.min_aspect.x = szHint.min_aspect.y = 1; */ |
577 | /* szHint.min_aspect.x = szHint.min_aspect.y = 1; */ |
… | |
… | |
575 | flags = 0; |
580 | flags = 0; |
576 | if (!parsed_geometry) |
581 | if (!parsed_geometry) |
577 | { |
582 | { |
578 | parsed_geometry = 1; |
583 | parsed_geometry = 1; |
579 | if (rs[Rs_geometry]) |
584 | if (rs[Rs_geometry]) |
580 | flags = XParseGeometry(rs[Rs_geometry], &x, &y, &w, &h); |
585 | flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h); |
581 | if (flags & WidthValue) |
586 | if (flags & WidthValue) |
582 | { |
587 | { |
583 | TermWin.ncol = BOUND_POSITIVE_INT16(w); |
588 | TermWin.ncol = BOUND_POSITIVE_INT16 (w); |
584 | szHint.flags |= USSize; |
589 | szHint.flags |= USSize; |
585 | } |
590 | } |
586 | if (flags & HeightValue) |
591 | if (flags & HeightValue) |
587 | { |
592 | { |
588 | TermWin.nrow = BOUND_POSITIVE_INT16(h); |
593 | TermWin.nrow = BOUND_POSITIVE_INT16 (h); |
589 | szHint.flags |= USSize; |
594 | szHint.flags |= USSize; |
590 | } |
595 | } |
591 | if (flags & XValue) |
596 | if (flags & XValue) |
592 | { |
597 | { |
593 | szHint.x = x; |
598 | szHint.x = x; |
… | |
… | |
622 | |
627 | |
623 | sb_w = mb_h = 0; |
628 | sb_w = mb_h = 0; |
624 | window_vt_x = window_vt_y = 0; |
629 | window_vt_x = window_vt_y = 0; |
625 | if (scrollbar_visible ()) |
630 | if (scrollbar_visible ()) |
626 | { |
631 | { |
627 | sb_w = scrollbar_TotalWidth(); |
632 | sb_w = scrollbar_TotalWidth (); |
628 | szHint.base_width += sb_w; |
633 | szHint.base_width += sb_w; |
629 | if (!(Options & Opt_scrollBar_right)) |
634 | if (! (Options & Opt_scrollBar_right)) |
630 | window_vt_x = sb_w; |
635 | window_vt_x = sb_w; |
631 | } |
636 | } |
632 | if (menubar_visible ()) |
637 | if (menubar_visible ()) |
633 | { |
638 | { |
634 | mb_h = menuBar_TotalHeight(); |
639 | mb_h = menuBar_TotalHeight (); |
635 | szHint.base_height += mb_h; |
640 | szHint.base_height += mb_h; |
636 | window_vt_y = mb_h; |
641 | window_vt_y = mb_h; |
637 | } |
642 | } |
638 | szHint.width_inc = TermWin.fwidth; |
643 | szHint.width_inc = TermWin.fwidth; |
639 | szHint.height_inc = TermWin.fheight; |
644 | szHint.height_inc = TermWin.fheight; |
… | |
… | |
645 | szHint.width = width; |
650 | szHint.width = width; |
646 | TermWin.width = width - szHint.base_width; |
651 | TermWin.width = width - szHint.base_width; |
647 | } |
652 | } |
648 | else |
653 | else |
649 | { |
654 | { |
650 | MIN_IT(TermWin.width, max_width); |
655 | MIN_IT (TermWin.width, max_width); |
651 | szHint.width = szHint.base_width + TermWin.width; |
656 | szHint.width = szHint.base_width + TermWin.width; |
652 | } |
657 | } |
653 | if (height && height - szHint.base_height < max_height) |
658 | if (height && height - szHint.base_height < max_height) |
654 | { |
659 | { |
655 | szHint.height = height; |
660 | szHint.height = height; |
656 | TermWin.height = height - szHint.base_height; |
661 | TermWin.height = height - szHint.base_height; |
657 | } |
662 | } |
658 | else |
663 | else |
659 | { |
664 | { |
660 | MIN_IT(TermWin.height, max_height); |
665 | MIN_IT (TermWin.height, max_height); |
661 | szHint.height = szHint.base_height + TermWin.height; |
666 | szHint.height = szHint.base_height + TermWin.height; |
662 | } |
667 | } |
663 | if (scrollbar_visible () && (Options & Opt_scrollBar_right)) |
668 | if (scrollbar_visible () && (Options & Opt_scrollBar_right)) |
664 | window_sb_x = szHint.width - sb_w; |
669 | window_sb_x = szHint.width - sb_w; |
665 | |
670 | |
… | |
… | |
670 | szHint.y += (DisplayHeight (display->display, DefaultScreen (display->display)) |
675 | szHint.y += (DisplayHeight (display->display, DefaultScreen (display->display)) |
671 | - szHint.height - 2 * TermWin.ext_bwidth); |
676 | - szHint.height - 2 * TermWin.ext_bwidth); |
672 | |
677 | |
673 | TermWin.ncol = TermWin.width / TermWin.fwidth; |
678 | TermWin.ncol = TermWin.width / TermWin.fwidth; |
674 | TermWin.nrow = TermWin.height / TermWin.fheight; |
679 | TermWin.nrow = TermWin.height / TermWin.fheight; |
675 | D_SIZE((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
680 | D_SIZE ((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
676 | TermWin.ncol, TermWin.nrow, szHint.width, |
681 | TermWin.ncol, TermWin.nrow, szHint.width, |
677 | szHint.height)); |
682 | szHint.height)); |
678 | return; |
683 | return; |
679 | } |
684 | } |
680 | |
685 | |
… | |
… | |
696 | ws.ws_xpixel = ws.ws_ypixel = 0; |
701 | ws.ws_xpixel = ws.ws_ypixel = 0; |
697 | #ifndef DEBUG_SIZE |
702 | #ifndef DEBUG_SIZE |
698 | (void)ioctl (cmd_fd, TIOCSWINSZ, &ws); |
703 | (void)ioctl (cmd_fd, TIOCSWINSZ, &ws); |
699 | #else |
704 | #else |
700 | if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0) |
705 | if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0) |
701 | D_SIZE((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); |
706 | D_SIZE ((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); |
702 | # ifdef SIGWINCH |
707 | # ifdef SIGWINCH |
703 | else if (cmd_pid) /* force through to the command */ |
708 | else if (cmd_pid) /* force through to the command */ |
704 | kill (cmd_pid, SIGWINCH); |
709 | kill (cmd_pid, SIGWINCH); |
705 | # endif |
710 | # endif |
706 | #endif |
711 | #endif |
707 | } |
712 | } |
708 | |
713 | |
709 | /*----------------------------------------------------------------------*/ |
714 | /*----------------------------------------------------------------------*/ |
710 | /* rxvt_change_font() - Switch to a new font */ |
715 | /* rxvt_change_font () - Switch to a new font */ |
711 | /* |
716 | /* |
712 | * init = 1 - initialize |
717 | * init = 1 - initialize |
713 | * |
718 | * |
714 | * fontname == FONT_UP - switch to bigger font |
719 | * fontname == FONT_UP - switch to bigger font |
715 | * fontname == FONT_DN - switch to smaller font |
720 | * fontname == FONT_DN - switch to smaller font |
… | |
… | |
727 | /* xterm sequences - title, iconName, color (exptl) */ |
732 | /* xterm sequences - title, iconName, color (exptl) */ |
728 | void |
733 | void |
729 | rxvt_term::set_title (const char *str) |
734 | rxvt_term::set_title (const char *str) |
730 | { |
735 | { |
731 | #ifndef SMART_WINDOW_TITLE |
736 | #ifndef SMART_WINDOW_TITLE |
732 | XStoreName(display->display, TermWin.parent[0], str); |
737 | XStoreName (display->display, TermWin.parent[0], str); |
733 | #else |
738 | #else |
734 | char *name; |
739 | char *name; |
735 | |
740 | |
736 | if (XFetchName(display->display, TermWin.parent[0], &name) == 0) |
741 | if (XFetchName (display->display, TermWin.parent[0], &name) == 0) |
737 | name = NULL; |
742 | name = NULL; |
738 | if (name == NULL || STRCMP(name, str)) |
743 | if (name == NULL || STRCMP (name, str)) |
739 | XStoreName(display->display, TermWin.parent[0], str); |
744 | XStoreName (display->display, TermWin.parent[0], str); |
740 | if (name) |
745 | if (name) |
741 | XFree(name); |
746 | XFree (name); |
742 | #endif |
747 | #endif |
743 | } |
748 | } |
744 | |
749 | |
745 | void |
750 | void |
746 | rxvt_term::set_iconName (const char *str) |
751 | rxvt_term::set_iconName (const char *str) |
747 | { |
752 | { |
748 | #ifndef SMART_WINDOW_TITLE |
753 | #ifndef SMART_WINDOW_TITLE |
749 | XSetIconName(display->display, TermWin.parent[0], str); |
754 | XSetIconName (display->display, TermWin.parent[0], str); |
750 | #else |
755 | #else |
751 | char *name; |
756 | char *name; |
752 | |
757 | |
753 | if (XGetIconName(display->display, TermWin.parent[0], &name)) |
758 | if (XGetIconName (display->display, TermWin.parent[0], &name)) |
754 | name = NULL; |
759 | name = NULL; |
755 | if (name == NULL || STRCMP(name, str)) |
760 | if (name == NULL || STRCMP (name, str)) |
756 | XSetIconName(display->display, TermWin.parent[0], str); |
761 | XSetIconName (display->display, TermWin.parent[0], str); |
757 | if (name) |
762 | if (name) |
758 | XFree(name); |
763 | XFree (name); |
759 | #endif |
764 | #endif |
760 | } |
765 | } |
761 | |
766 | |
762 | #ifdef XTERM_COLOR_CHANGE |
767 | #ifdef XTERM_COLOR_CHANGE |
763 | void |
768 | void |
… | |
… | |
768 | |
773 | |
769 | if (color == NULL || *color == '\0') |
774 | if (color == NULL || *color == '\0') |
770 | return; |
775 | return; |
771 | |
776 | |
772 | /* handle color aliases */ |
777 | /* handle color aliases */ |
773 | if (isdigit(*color)) |
778 | if (isdigit (*color)) |
774 | { |
779 | { |
775 | i = atoi(color); |
780 | i = atoi (color); |
776 | if (i >= 8 && i <= 15) |
781 | if (i >= 8 && i <= 15) |
777 | { /* bright colors */ |
782 | { /* bright colors */ |
778 | i -= 8; |
783 | i -= 8; |
779 | # ifndef NO_BRIGHTCOLOR |
784 | # ifndef NO_BRIGHTCOLOR |
780 | PixColors[idx] = PixColors[minBrightCOLOR + i]; |
785 | PixColors[idx] = PixColors[minBrightCOLOR + i]; |
781 | SET_PIXCOLOR(idx); |
786 | SET_PIXCOLOR (idx); |
782 | goto Done; |
787 | goto Done; |
783 | # endif |
788 | # endif |
784 | |
789 | |
785 | } |
790 | } |
786 | if (i >= 0 && i <= 7) |
791 | if (i >= 0 && i <= 7) |
787 | { /* normal colors */ |
792 | { /* normal colors */ |
788 | PixColors[idx] = PixColors[minCOLOR + i]; |
793 | PixColors[idx] = PixColors[minCOLOR + i]; |
789 | SET_PIXCOLOR(idx); |
794 | SET_PIXCOLOR (idx); |
790 | goto Done; |
795 | goto Done; |
791 | } |
796 | } |
792 | } |
797 | } |
793 | if (!rXParseAllocColor (& xcol, color)) |
798 | if (!rXParseAllocColor (& xcol, color)) |
794 | return; |
799 | return; |
… | |
… | |
803 | if (PixColors[idx] == PixColors[i]) |
808 | if (PixColors[idx] == PixColors[i]) |
804 | break; |
809 | break; |
805 | if (i > Color_White) |
810 | if (i > Color_White) |
806 | { |
811 | { |
807 | /* fprintf (stderr, "XFreeColors: PixColors [%d] = %lu\n", idx, PixColors [idx]); */ |
812 | /* fprintf (stderr, "XFreeColors: PixColors [%d] = %lu\n", idx, PixColors [idx]); */ |
808 | XFreeColors(display->display, XCMAP, (PixColors + idx), 1, |
813 | XFreeColors (display->display, XCMAP, (PixColors + idx), 1, |
809 | DisplayPlanes(display->display, display->screen)); |
814 | DisplayPlanes (display->display, display->screen)); |
810 | } |
815 | } |
811 | # endif |
816 | # endif |
812 | |
817 | |
813 | PixColors[idx] = xcol; |
818 | PixColors[idx] = xcol; |
814 | SET_PIXCOLOR(idx); |
819 | SET_PIXCOLOR (idx); |
815 | |
820 | |
816 | /* XSetWindowAttributes attr; */ |
821 | /* XSetWindowAttributes attr; */ |
817 | /* Cursor cursor; */ |
822 | /* Cursor cursor; */ |
818 | Done: |
823 | Done: |
819 | if (idx == Color_bg && !(Options & Opt_transparent)) |
824 | if (idx == Color_bg && ! (Options & Opt_transparent)) |
820 | XSetWindowBackground(display->display, TermWin.vt, |
825 | XSetWindowBackground (display->display, TermWin.vt, |
821 | PixColors[Color_bg]); |
826 | PixColors[Color_bg]); |
822 | |
827 | |
823 | /* handle Color_BD, scrollbar background, etc. */ |
828 | /* handle Color_BD, scrollbar background, etc. */ |
824 | |
829 | |
825 | set_colorfgbg (); |
830 | set_colorfgbg (); |
… | |
… | |
839 | rxvt_color xcol[2]; |
844 | rxvt_color xcol[2]; |
840 | |
845 | |
841 | xcol[0] = PixColors[Color_pointer]; |
846 | xcol[0] = PixColors[Color_pointer]; |
842 | xcol[1] = PixColors[Color_bg]; |
847 | xcol[1] = PixColors[Color_bg]; |
843 | XQueryColors (display->display, XCMAP, xcol, 2); |
848 | XQueryColors (display->display, XCMAP, xcol, 2); |
844 | XRecolorCursor (display->display, TermWin_cursor, &(xcol[0]), &(xcol[1])); |
849 | XRecolorCursor (display->display, TermWin_cursor, & (xcol[0]), & (xcol[1])); |
845 | #endif |
850 | #endif |
846 | } |
851 | } |
847 | |
852 | |
848 | /*----------------------------------------------------------------------*/ |
853 | /*----------------------------------------------------------------------*/ |
849 | /* |
854 | /* |
… | |
… | |
852 | void |
857 | void |
853 | rxvt_term::set_colorfgbg () |
858 | rxvt_term::set_colorfgbg () |
854 | { |
859 | { |
855 | unsigned int i; |
860 | unsigned int i; |
856 | const char *xpmb = "\0"; |
861 | const char *xpmb = "\0"; |
857 | char fstr[sizeof("default") + 1], bstr[sizeof("default") + 1]; |
862 | char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1]; |
858 | |
863 | |
859 | env_colorfgbg = |
864 | env_colorfgbg = |
860 | (char *)rxvt_malloc(sizeof("COLORFGBG=default;default;bg") + 1); |
865 | (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1); |
861 | STRCPY(fstr, "default"); |
866 | STRCPY (fstr, "default"); |
862 | STRCPY(bstr, "default"); |
867 | STRCPY (bstr, "default"); |
863 | for (i = Color_Black; i <= Color_White; i++) |
868 | for (i = Color_Black; i <= Color_White; i++) |
864 | if (PixColors[Color_fg] == PixColors[i]) |
869 | if (PixColors[Color_fg] == PixColors[i]) |
865 | { |
870 | { |
866 | sprintf(fstr, "%d", (i - Color_Black)); |
871 | sprintf (fstr, "%d", (i - Color_Black)); |
867 | break; |
872 | break; |
868 | } |
873 | } |
869 | for (i = Color_Black; i <= Color_White; i++) |
874 | for (i = Color_Black; i <= Color_White; i++) |
870 | if (PixColors[Color_bg] == PixColors[i]) |
875 | if (PixColors[Color_bg] == PixColors[i]) |
871 | { |
876 | { |
872 | sprintf(bstr, "%d", (i - Color_Black)); |
877 | sprintf (bstr, "%d", (i - Color_Black)); |
873 | #ifdef XPM_BACKGROUND |
878 | #ifdef XPM_BACKGROUND |
874 | xpmb = "default;"; |
879 | xpmb = "default;"; |
875 | #endif |
880 | #endif |
876 | break; |
881 | break; |
877 | } |
882 | } |
|
|
883 | |
878 | sprintf(env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); |
884 | sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); |
879 | putenv(env_colorfgbg); |
|
|
880 | |
885 | |
881 | #ifndef NO_BRIGHTCOLOR |
886 | #ifndef NO_BRIGHTCOLOR |
882 | colorfgbg = DEFAULT_RSTYLE; |
887 | colorfgbg = DEFAULT_RSTYLE; |
883 | for (i = minCOLOR; i <= maxCOLOR; i++) |
888 | for (i = minCOLOR; i <= maxCOLOR; i++) |
884 | { |
889 | { |
885 | if (PixColors[Color_fg] == PixColors[i]) |
890 | if (PixColors[Color_fg] == PixColors[i]) |
886 | colorfgbg = SET_FGCOLOR(colorfgbg, i); |
891 | colorfgbg = SET_FGCOLOR (colorfgbg, i); |
887 | if (PixColors[Color_bg] == PixColors[i]) |
892 | if (PixColors[Color_bg] == PixColors[i]) |
888 | colorfgbg = SET_BGCOLOR(colorfgbg, i); |
893 | colorfgbg = SET_BGCOLOR (colorfgbg, i); |
889 | } |
894 | } |
890 | #endif |
895 | #endif |
891 | } |
896 | } |
892 | |
897 | |
893 | /*----------------------------------------------------------------------*/ |
898 | /*----------------------------------------------------------------------*/ |
… | |
… | |
899 | int |
904 | int |
900 | rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) |
905 | rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) |
901 | { |
906 | { |
902 | if (!screen_in_out->set (display, colour)) |
907 | if (!screen_in_out->set (display, colour)) |
903 | { |
908 | { |
904 | rxvt_print_error("can't allocate colour: %s", colour); |
909 | rxvt_print_error ("can't allocate colour: %s", colour); |
905 | return false; |
910 | return false; |
906 | } |
911 | } |
907 | |
912 | |
908 | return true; |
913 | return true; |
909 | } |
914 | } |
… | |
… | |
1015 | TermWin.ncol = prev_ncol; // save b/c scr_blank_screen_mem uses this |
1020 | TermWin.ncol = prev_ncol; // save b/c scr_blank_screen_mem uses this |
1016 | curr_screen = scr_change_screen (PRIMARY); |
1021 | curr_screen = scr_change_screen (PRIMARY); |
1017 | TermWin.ncol = ncol; |
1022 | TermWin.ncol = ncol; |
1018 | } |
1023 | } |
1019 | |
1024 | |
1020 | scr_reset(); |
1025 | scr_reset (); |
1021 | |
1026 | |
1022 | if (curr_screen >= 0) /* this is not the first time through */ |
1027 | if (curr_screen >= 0) /* this is not the first time through */ |
1023 | { |
1028 | { |
1024 | scr_change_screen (curr_screen); |
1029 | scr_change_screen (curr_screen); |
1025 | selection_check (old_ncol != TermWin.ncol ? 4 : 0); |
1030 | selection_check (old_ncol != TermWin.ncol ? 4 : 0); |
… | |
… | |
1043 | { |
1048 | { |
1044 | XWindowAttributes wattr; |
1049 | XWindowAttributes wattr; |
1045 | |
1050 | |
1046 | if (width == 0 || height == 0) |
1051 | if (width == 0 || height == 0) |
1047 | { |
1052 | { |
1048 | XGetWindowAttributes(display->display, display->root, &wattr); |
1053 | XGetWindowAttributes (display->display, display->root, &wattr); |
1049 | if (width == 0) |
1054 | if (width == 0) |
1050 | width = wattr.width - szHint.base_width; |
1055 | width = wattr.width - szHint.base_width; |
1051 | if (height == 0) |
1056 | if (height == 0) |
1052 | height = wattr.height - szHint.base_height; |
1057 | height = wattr.height - szHint.base_height; |
1053 | } |
1058 | } |
… | |
… | |
1067 | void |
1072 | void |
1068 | rxvt_term::im_set_size (XRectangle *size) |
1073 | rxvt_term::im_set_size (XRectangle *size) |
1069 | { |
1074 | { |
1070 | size->x = TermWin.int_bwidth; |
1075 | size->x = TermWin.int_bwidth; |
1071 | size->y = TermWin.int_bwidth; |
1076 | size->y = TermWin.int_bwidth; |
1072 | size->width = Width2Pixel(TermWin.ncol); |
1077 | size->width = Width2Pixel (TermWin.ncol); |
1073 | size->height = Height2Pixel(TermWin.nrow); |
1078 | size->height = Height2Pixel (TermWin.nrow); |
1074 | } |
1079 | } |
1075 | |
1080 | |
1076 | void |
1081 | void |
1077 | rxvt_term::im_set_color (unsigned long *fg, unsigned long *bg) |
1082 | rxvt_term::im_set_color (unsigned long *fg, unsigned long *bg) |
1078 | { |
1083 | { |
… | |
… | |
1088 | Atom atom; |
1093 | Atom atom; |
1089 | Window win; |
1094 | Window win; |
1090 | char server[IMBUFSIZ]; |
1095 | char server[IMBUFSIZ]; |
1091 | |
1096 | |
1092 | /* get current locale modifier */ |
1097 | /* get current locale modifier */ |
1093 | if ((p = XSetLocaleModifiers(NULL)) != NULL) |
1098 | if ((p = XSetLocaleModifiers (NULL)) != NULL) |
1094 | { |
1099 | { |
1095 | STRCPY(server, "@server="); |
1100 | STRCPY (server, "@server="); |
1096 | STRNCAT(server, &(p[4]), IMBUFSIZ - 9); /* skip "@im=" */ |
1101 | STRNCAT (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */ |
1097 | if ((p = STRCHR(server + 1, '@')) != NULL) /* first one only */ |
1102 | if ((p = STRCHR (server + 1, '@')) != NULL) /* first one only */ |
1098 | *p = '\0'; |
1103 | *p = '\0'; |
1099 | |
1104 | |
1100 | atom = XInternAtom(display->display, server, False); |
1105 | atom = XInternAtom (display->display, server, False); |
1101 | win = XGetSelectionOwner(display->display, atom); |
1106 | win = XGetSelectionOwner (display->display, atom); |
1102 | if (win != None) |
1107 | if (win != None) |
1103 | return True; |
1108 | return True; |
1104 | } |
1109 | } |
1105 | return False; |
1110 | return False; |
1106 | } |
1111 | } |
… | |
… | |
1110 | { |
1115 | { |
1111 | XPoint spot; |
1116 | XPoint spot; |
1112 | XVaNestedList preedit_attr; |
1117 | XVaNestedList preedit_attr; |
1113 | |
1118 | |
1114 | if (Input_Context == NULL |
1119 | if (Input_Context == NULL |
1115 | || !TermWin.focus || !(input_style & XIMPreeditPosition) |
1120 | || !TermWin.focus || ! (input_style & XIMPreeditPosition) |
1116 | || !(event_type == KeyPress |
1121 | || ! (event_type == KeyPress |
1117 | || event_type == Expose |
1122 | || event_type == Expose |
1118 | || event_type == NoExpose |
1123 | || event_type == NoExpose |
1119 | || event_type == SelectionNotify |
1124 | || event_type == SelectionNotify |
1120 | || event_type == ButtonRelease || event_type == FocusIn) |
1125 | || event_type == ButtonRelease || event_type == FocusIn) |
1121 | || !IMisRunning ()) |
1126 | || !IMisRunning ()) |
1122 | return; |
1127 | return; |
1123 | |
1128 | |
1124 | im_set_position (&spot); |
1129 | im_set_position (&spot); |
1125 | |
1130 | |
1126 | preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL); |
1131 | preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); |
1127 | XSetICValues(Input_Context, XNPreeditAttributes, preedit_attr, NULL); |
1132 | XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); |
1128 | XFree(preedit_attr); |
1133 | XFree (preedit_attr); |
1129 | } |
1134 | } |
1130 | |
1135 | |
1131 | void |
1136 | void |
1132 | rxvt_term::im_set_preedit_area (XRectangle * preedit_rect, XRectangle * status_rect, |
1137 | rxvt_term::im_set_preedit_area (XRectangle * preedit_rect, XRectangle * status_rect, |
1133 | XRectangle * needed_rect) |
1138 | XRectangle * needed_rect) |
1134 | { |
1139 | { |
1135 | int mbh, vtx = 0; |
1140 | int mbh, vtx = 0; |
1136 | |
1141 | |
1137 | if (scrollbar_visible () && !(Options & Opt_scrollBar_right)) |
1142 | if (scrollbar_visible () && ! (Options & Opt_scrollBar_right)) |
1138 | vtx = scrollbar_TotalWidth(); |
1143 | vtx = scrollbar_TotalWidth (); |
1139 | |
1144 | |
1140 | mbh = menubar_visible () ? menuBar_TotalHeight() : 0; |
1145 | mbh = menubar_visible () ? menuBar_TotalHeight () : 0; |
1141 | mbh -= TermWin.lineSpace; |
1146 | mbh -= TermWin.lineSpace; |
1142 | |
1147 | |
1143 | preedit_rect->x = needed_rect->width + vtx; |
1148 | preedit_rect->x = needed_rect->width + vtx; |
1144 | preedit_rect->y = Height2Pixel(TermWin.nrow - 1) + mbh; |
1149 | preedit_rect->y = Height2Pixel (TermWin.nrow - 1) + mbh; |
1145 | |
1150 | |
1146 | preedit_rect->width = Width2Pixel(TermWin.ncol + 1) - needed_rect->width + vtx; |
1151 | preedit_rect->width = Width2Pixel (TermWin.ncol + 1) - needed_rect->width + vtx; |
1147 | preedit_rect->height = Height2Pixel(1); |
1152 | preedit_rect->height = Height2Pixel (1); |
1148 | |
1153 | |
1149 | status_rect->x = vtx; |
1154 | status_rect->x = vtx; |
1150 | status_rect->y = Height2Pixel(TermWin.nrow - 1) + mbh; |
1155 | status_rect->y = Height2Pixel (TermWin.nrow - 1) + mbh; |
1151 | |
1156 | |
1152 | status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel(TermWin.ncol + 1); |
1157 | status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel (TermWin.ncol + 1); |
1153 | status_rect->height = Height2Pixel(1); |
1158 | status_rect->height = Height2Pixel (1); |
1154 | } |
1159 | } |
1155 | |
1160 | |
1156 | void |
1161 | void |
1157 | rxvt_term::im_destroy () |
1162 | rxvt_term::im_destroy () |
1158 | { |
1163 | { |
… | |
… | |
1184 | const char *p; |
1189 | const char *p; |
1185 | char **s; |
1190 | char **s; |
1186 | XIMStyles *xim_styles; |
1191 | XIMStyles *xim_styles; |
1187 | XVaNestedList preedit_attr, status_attr; |
1192 | XVaNestedList preedit_attr, status_attr; |
1188 | |
1193 | |
1189 | if (!((p = XSetLocaleModifiers (modifiers)) && *p)) |
1194 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1190 | return false; |
1195 | return false; |
1191 | |
1196 | |
1192 | D_MAIN((stderr, "rxvt_IM_get_IC()")); |
1197 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
1193 | input_method = display->get_xim (locale, modifiers); |
1198 | input_method = display->get_xim (locale, modifiers); |
1194 | if (input_method == NULL) |
1199 | if (input_method == NULL) |
1195 | return false; |
1200 | return false; |
1196 | |
1201 | |
1197 | xim = input_method->xim; |
1202 | xim = input_method->xim; |
… | |
… | |
1203 | display->put_xim (input_method); |
1208 | display->put_xim (input_method); |
1204 | return false; |
1209 | return false; |
1205 | } |
1210 | } |
1206 | |
1211 | |
1207 | p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root"; |
1212 | p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root"; |
1208 | s = rxvt_splitcommastring(p); |
1213 | s = rxvt_splitcommastring (p); |
1209 | for (i = found = 0; !found && s[i]; i++) |
1214 | for (i = found = 0; !found && s[i]; i++) |
1210 | { |
1215 | { |
1211 | if (!STRCMP(s[i], "OverTheSpot")) |
1216 | if (!STRCMP (s[i], "OverTheSpot")) |
1212 | input_style = (XIMPreeditPosition | XIMStatusNothing); |
1217 | input_style = (XIMPreeditPosition | XIMStatusNothing); |
1213 | else if (!STRCMP(s[i], "OffTheSpot")) |
1218 | else if (!STRCMP (s[i], "OffTheSpot")) |
1214 | input_style = (XIMPreeditArea | XIMStatusArea); |
1219 | input_style = (XIMPreeditArea | XIMStatusArea); |
1215 | else if (!STRCMP(s[i], "Root")) |
1220 | else if (!STRCMP (s[i], "Root")) |
1216 | input_style = (XIMPreeditNothing | XIMStatusNothing); |
1221 | input_style = (XIMPreeditNothing | XIMStatusNothing); |
1217 | |
1222 | |
1218 | for (j = 0; j < xim_styles->count_styles; j++) |
1223 | for (j = 0; j < xim_styles->count_styles; j++) |
1219 | if (input_style == xim_styles->supported_styles[j]) |
1224 | if (input_style == xim_styles->supported_styles[j]) |
1220 | { |
1225 | { |
… | |
… | |
1241 | { |
1246 | { |
1242 | im_set_size (&rect); |
1247 | im_set_size (&rect); |
1243 | im_set_position (&spot); |
1248 | im_set_position (&spot); |
1244 | im_set_color (&fg, &bg); |
1249 | im_set_color (&fg, &bg); |
1245 | |
1250 | |
1246 | preedit_attr = XVaCreateNestedList(0, XNArea, &rect, |
1251 | preedit_attr = XVaCreateNestedList (0, XNArea, &rect, |
1247 | XNSpotLocation, &spot, |
1252 | XNSpotLocation, &spot, |
1248 | XNForeground, fg, XNBackground, bg, |
1253 | XNForeground, fg, XNBackground, bg, |
1249 | //XNFontSet, TermWin.fontset, |
1254 | //XNFontSet, TermWin.fontset, |
1250 | NULL); |
1255 | NULL); |
1251 | } |
1256 | } |
… | |
… | |
1259 | */ |
1264 | */ |
1260 | needed_rect.width = 0; |
1265 | needed_rect.width = 0; |
1261 | |
1266 | |
1262 | im_set_preedit_area (&rect, &status_rect, &needed_rect); |
1267 | im_set_preedit_area (&rect, &status_rect, &needed_rect); |
1263 | |
1268 | |
1264 | preedit_attr = XVaCreateNestedList(0, XNArea, &rect, |
1269 | preedit_attr = XVaCreateNestedList (0, XNArea, &rect, |
1265 | XNForeground, fg, XNBackground, bg, |
1270 | XNForeground, fg, XNBackground, bg, |
1266 | //XNFontSet, TermWin.fontset, |
1271 | //XNFontSet, TermWin.fontset, |
1267 | NULL); |
1272 | NULL); |
1268 | status_attr = XVaCreateNestedList(0, XNArea, &status_rect, |
1273 | status_attr = XVaCreateNestedList (0, XNArea, &status_rect, |
1269 | XNForeground, fg, XNBackground, bg, |
1274 | XNForeground, fg, XNBackground, bg, |
1270 | //XNFontSet, TermWin.fontset, |
1275 | //XNFontSet, TermWin.fontset, |
1271 | NULL); |
1276 | NULL); |
1272 | } |
1277 | } |
1273 | |
1278 | |
1274 | Input_Context = XCreateIC(xim, XNInputStyle, input_style, |
1279 | Input_Context = XCreateIC (xim, XNInputStyle, input_style, |
1275 | XNClientWindow, TermWin.parent[0], |
1280 | XNClientWindow, TermWin.parent[0], |
1276 | XNFocusWindow, TermWin.parent[0], |
1281 | XNFocusWindow, TermWin.parent[0], |
1277 | preedit_attr ? XNPreeditAttributes : NULL, |
1282 | preedit_attr ? XNPreeditAttributes : NULL, |
1278 | preedit_attr, |
1283 | preedit_attr, |
1279 | status_attr ? XNStatusAttributes : NULL, |
1284 | status_attr ? XNStatusAttributes : NULL, |
1280 | status_attr, NULL); |
1285 | status_attr, NULL); |
1281 | if (preedit_attr) XFree(preedit_attr); |
1286 | if (preedit_attr) XFree (preedit_attr); |
1282 | if (status_attr) XFree(status_attr); |
1287 | if (status_attr) XFree (status_attr); |
1283 | |
1288 | |
1284 | if (Input_Context == NULL) |
1289 | if (Input_Context == NULL) |
1285 | { |
1290 | { |
1286 | rxvt_print_error("failed to create input context"); |
1291 | rxvt_print_error ("failed to create input context"); |
1287 | display->put_xim (input_method); |
1292 | display->put_xim (input_method); |
1288 | return false; |
1293 | return false; |
1289 | } |
1294 | } |
1290 | |
1295 | |
1291 | if (input_style & XIMPreeditArea) |
1296 | if (input_style & XIMPreeditArea) |
1292 | IMSetStatusPosition (); |
1297 | IMSetStatusPosition (); |
1293 | |
1298 | |
1294 | D_MAIN((stderr, "rxvt_IM_get_IC() - successful connection")); |
1299 | D_MAIN ((stderr, "rxvt_IM_get_IC () - successful connection")); |
1295 | return true; |
1300 | return true; |
1296 | } |
1301 | } |
1297 | |
1302 | |
1298 | void |
1303 | void |
1299 | rxvt_term::im_cb () |
1304 | rxvt_term::im_cb () |
… | |
… | |
1303 | char **s; |
1308 | char **s; |
1304 | char buf[IMBUFSIZ]; |
1309 | char buf[IMBUFSIZ]; |
1305 | |
1310 | |
1306 | im_destroy (); |
1311 | im_destroy (); |
1307 | |
1312 | |
1308 | D_MAIN((stderr, "rxvt_IMInstantiateCallback()")); |
1313 | D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); |
1309 | if (Input_Context) |
1314 | if (Input_Context) |
1310 | return; |
1315 | return; |
1311 | |
1316 | |
1312 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
1317 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
1313 | if (rs[Rs_imLocale]) |
1318 | if (rs[Rs_imLocale]) |
1314 | setlocale (LC_CTYPE, rs[Rs_imLocale]); |
1319 | rxvt_set_locale (rs[Rs_imLocale]); |
1315 | #endif |
1320 | #endif |
1316 | |
1321 | |
1317 | p = rs[Rs_inputMethod]; |
1322 | p = rs[Rs_inputMethod]; |
1318 | if (p && *p) |
1323 | if (p && *p) |
1319 | { |
1324 | { |
… | |
… | |
1332 | break; |
1337 | break; |
1333 | } |
1338 | } |
1334 | } |
1339 | } |
1335 | } |
1340 | } |
1336 | for (i = 0; s[i]; i++) |
1341 | for (i = 0; s[i]; i++) |
1337 | free(s[i]); |
1342 | free (s[i]); |
1338 | free(s); |
1343 | free (s); |
1339 | |
1344 | |
1340 | if (found) |
1345 | if (found) |
1341 | goto done; |
1346 | goto done; |
1342 | } |
1347 | } |
1343 | |
1348 | |
… | |
… | |
1350 | goto done; |
1355 | goto done; |
1351 | |
1356 | |
1352 | done: |
1357 | done: |
1353 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
1358 | #if defined(HAVE_XSETLOCALE) || defined(HAVE_SETLOCALE) |
1354 | if (rs[Rs_imLocale]) |
1359 | if (rs[Rs_imLocale]) |
1355 | setlocale (LC_CTYPE, locale); |
1360 | rxvt_set_locale (locale); |
1356 | #endif |
1361 | #endif |
1357 | } |
1362 | } |
1358 | |
1363 | |
1359 | void |
1364 | void |
1360 | rxvt_term::IMSetStatusPosition () |
1365 | rxvt_term::IMSetStatusPosition () |
1361 | { |
1366 | { |
1362 | XRectangle preedit_rect, status_rect, *needed_rect; |
1367 | XRectangle preedit_rect, status_rect, *needed_rect; |
1363 | XVaNestedList preedit_attr, status_attr; |
1368 | XVaNestedList preedit_attr, status_attr; |
1364 | |
1369 | |
1365 | if (Input_Context == NULL |
1370 | if (Input_Context == NULL |
1366 | || !TermWin.focus || !(input_style & XIMPreeditArea) |
1371 | || !TermWin.focus || ! (input_style & XIMPreeditArea) |
1367 | || !IMisRunning ()) |
1372 | || !IMisRunning ()) |
1368 | return; |
1373 | return; |
1369 | |
1374 | |
1370 | /* Getting the necessary width of preedit area */ |
1375 | /* Getting the necessary width of preedit area */ |
1371 | status_attr = XVaCreateNestedList(0, XNAreaNeeded, &needed_rect, NULL); |
1376 | status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL); |
1372 | XGetICValues(Input_Context, XNStatusAttributes, status_attr, NULL); |
1377 | XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL); |
1373 | XFree(status_attr); |
1378 | XFree (status_attr); |
1374 | |
1379 | |
1375 | im_set_preedit_area (&preedit_rect, &status_rect, needed_rect); |
1380 | im_set_preedit_area (&preedit_rect, &status_rect, needed_rect); |
1376 | |
1381 | |
1377 | preedit_attr = XVaCreateNestedList(0, XNArea, &preedit_rect, NULL); |
1382 | preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL); |
1378 | status_attr = XVaCreateNestedList(0, XNArea, &status_rect, NULL); |
1383 | status_attr = XVaCreateNestedList (0, XNArea, &status_rect, NULL); |
1379 | |
1384 | |
1380 | XSetICValues(Input_Context, |
1385 | XSetICValues (Input_Context, |
1381 | XNPreeditAttributes, preedit_attr, |
1386 | XNPreeditAttributes, preedit_attr, |
1382 | XNStatusAttributes, status_attr, NULL); |
1387 | XNStatusAttributes, status_attr, NULL); |
1383 | |
1388 | |
1384 | XFree(preedit_attr); |
1389 | XFree (preedit_attr); |
1385 | XFree(status_attr); |
1390 | XFree (status_attr); |
1386 | } |
1391 | } |
1387 | #endif /* USE_XIM */ |
1392 | #endif /* USE_XIM */ |
1388 | |
1393 | |
1389 | /*----------------------------------------------------------------------*/ |
1394 | /*----------------------------------------------------------------------*/ |
1390 | rxvt_t rxvt_current_term; |
1395 | rxvt_t rxvt_current_term; |