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