… | |
… | |
51 | static char curlocale[128]; |
51 | static char curlocale[128]; |
52 | |
52 | |
53 | bool |
53 | bool |
54 | rxvt_set_locale (const char *locale) |
54 | rxvt_set_locale (const char *locale) |
55 | { |
55 | { |
56 | if (!locale || !STRNCMP (locale, curlocale, 128)) |
56 | if (!locale || !strncmp (locale, curlocale, 128)) |
57 | return false; |
57 | return false; |
58 | |
58 | |
59 | STRNCPY (curlocale, locale, 128); |
59 | strncpy (curlocale, locale, 128); |
60 | setlocale (LC_CTYPE, curlocale); |
60 | setlocale (LC_CTYPE, curlocale); |
61 | return true; |
61 | return true; |
62 | } |
62 | } |
63 | |
63 | |
64 | #if ENABLE_COMBINING |
64 | #if ENABLE_COMBINING |
… | |
… | |
123 | return len; |
123 | return len; |
124 | |
124 | |
125 | } |
125 | } |
126 | #endif |
126 | #endif |
127 | |
127 | |
128 | void * |
|
|
129 | rxvt_term::operator new (size_t s) |
|
|
130 | { |
|
|
131 | void *p = malloc (s); |
|
|
132 | |
|
|
133 | MEMSET (p, 0, s); |
|
|
134 | return p; |
|
|
135 | } |
|
|
136 | |
|
|
137 | void |
|
|
138 | rxvt_term::operator delete (void *p, size_t s) |
|
|
139 | { |
|
|
140 | free (p); |
|
|
141 | } |
|
|
142 | |
|
|
143 | rxvt_term::rxvt_term () |
128 | rxvt_term::rxvt_term () |
144 | : |
129 | : |
145 | #if TRANSPARENT |
130 | #if TRANSPARENT |
146 | rootwin_ev (this, &rxvt_term::rootwin_cb), |
131 | rootwin_ev (this, &rxvt_term::rootwin_cb), |
147 | #endif |
132 | #endif |
… | |
… | |
170 | pointer_ev (this, &rxvt_term::pointer_cb), |
155 | pointer_ev (this, &rxvt_term::pointer_cb), |
171 | #endif |
156 | #endif |
172 | #ifdef USE_XIM |
157 | #ifdef USE_XIM |
173 | im_ev (this, &rxvt_term::im_cb), |
158 | im_ev (this, &rxvt_term::im_cb), |
174 | #endif |
159 | #endif |
|
|
160 | sw_term (this, &rxvt_term::sig_term), |
|
|
161 | sw_chld (this, &rxvt_term::sig_chld), |
175 | termwin_ev (this, &rxvt_term::x_cb), |
162 | termwin_ev (this, &rxvt_term::x_cb), |
176 | vt_ev (this, &rxvt_term::x_cb), |
163 | vt_ev (this, &rxvt_term::x_cb), |
177 | check_ev (this, &rxvt_term::check_cb), |
164 | check_ev (this, &rxvt_term::check_cb), |
178 | flush_ev (this, &rxvt_term::flush_cb), |
165 | flush_ev (this, &rxvt_term::flush_cb), |
179 | destroy_ev (this, &rxvt_term::destroy_cb), |
166 | destroy_ev (this, &rxvt_term::destroy_cb), |
… | |
… | |
187 | |
174 | |
188 | rxvt_term::~rxvt_term () |
175 | rxvt_term::~rxvt_term () |
189 | { |
176 | { |
190 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
177 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
191 | |
178 | |
192 | if (cmd_fd >= 0) |
179 | if (cmd_pid) |
193 | close (cmd_fd); |
180 | kill (-cmd_pid, SIGHUP); |
194 | |
181 | |
195 | #ifndef NO_SETOWNER_TTYDEV |
182 | pty.put (); |
196 | privileged_ttydev (RESTORE); |
183 | |
197 | #endif |
|
|
198 | #ifdef UTMP_SUPPORT |
184 | #ifdef UTMP_SUPPORT |
199 | privileged_utmp (RESTORE); |
185 | privileged_utmp (RESTORE); |
200 | #endif |
186 | #endif |
201 | |
187 | |
|
|
188 | #if ENABLE_STYLES |
|
|
189 | for (int i = RS_styleCount; --i; ) |
|
|
190 | if (TermWin.fontset[i] != TermWin.fontset[0]) |
|
|
191 | delete TermWin.fontset[i]; |
|
|
192 | #endif |
202 | delete TermWin.fontset; |
193 | delete TermWin.fontset[0]; |
203 | |
194 | |
204 | if (display) |
195 | if (display) |
205 | { |
196 | { |
206 | selection_clear (); |
197 | selection_clear (); |
207 | |
198 | |
208 | #ifdef USE_XIM |
199 | #ifdef USE_XIM |
209 | im_destroy (); |
200 | im_destroy (); |
210 | #endif |
201 | #endif |
211 | #ifdef MENUBAR |
202 | #ifdef MENUBAR |
212 | if (menubarGC) XFreeGC (display->display, menubarGC); |
203 | if (menubarGC) XFreeGC (display->display, menubarGC); |
213 | #endif |
204 | #endif |
214 | #ifdef XTERM_SCROLLBAR |
205 | #ifdef XTERM_SCROLLBAR |
215 | if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC); |
206 | if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC); |
216 | if (ShadowGC) XFreeGC (display->display, ShadowGC); |
207 | if (ShadowGC) XFreeGC (display->display, ShadowGC); |
217 | #endif |
208 | #endif |
… | |
… | |
248 | XDestroyWindow (display->display, TermWin.parent[0]); |
239 | XDestroyWindow (display->display, TermWin.parent[0]); |
249 | } |
240 | } |
250 | |
241 | |
251 | // TODO: free pixcolours, colours should become part of rxvt_display |
242 | // TODO: free pixcolours, colours should become part of rxvt_display |
252 | |
243 | |
253 | delete PixColorsFocused; |
244 | delete pix_colors_focused; |
254 | #ifdef OFF_FOCUS_FADING |
245 | #ifdef OFF_FOCUS_FADING |
255 | delete PixColorsUnFocused; |
246 | delete pix_colors_unfocused; |
256 | #endif |
247 | #endif |
257 | |
248 | |
258 | displays.put (display); |
249 | displays.put (display); |
259 | |
250 | |
260 | scr_release (); |
251 | scr_release (); |
… | |
… | |
268 | free (env_windowid); |
259 | free (env_windowid); |
269 | free (env_display); |
260 | free (env_display); |
270 | free (env_term); |
261 | free (env_term); |
271 | free (env_colorfgbg); |
262 | free (env_colorfgbg); |
272 | free (locale); |
263 | free (locale); |
273 | #if 0 |
264 | free (v_buffer); |
274 | free (codeset); |
265 | free (incr_buf); |
275 | #endif |
|
|
276 | |
266 | |
277 | delete envv; |
267 | delete envv; |
278 | delete argv; |
268 | delete argv; |
279 | } |
269 | } |
280 | |
270 | |
281 | void |
271 | void |
282 | rxvt_term::destroy () |
272 | rxvt_term::destroy () |
283 | { |
273 | { |
284 | if (destroy_ev.active) |
274 | if (destroy_ev.active) |
285 | return; |
275 | return; |
|
|
276 | |
|
|
277 | #if ENABLE_OVERLAY |
|
|
278 | scr_overlay_off (); |
|
|
279 | #endif |
286 | |
280 | |
287 | if (display) |
281 | if (display) |
288 | { |
282 | { |
289 | #if USE_XIM |
283 | #if USE_XIM |
290 | im_ev.stop (display); |
284 | im_ev.stop (display); |
… | |
… | |
340 | SET_R (this); |
334 | SET_R (this); |
341 | |
335 | |
342 | if (!init_vars ()) |
336 | if (!init_vars ()) |
343 | return false; |
337 | return false; |
344 | |
338 | |
|
|
339 | init_secondary (); |
|
|
340 | |
|
|
341 | const char **cmd_argv = init_resources (argc, argv); |
|
|
342 | |
|
|
343 | set_locale (""); |
|
|
344 | |
|
|
345 | #if MENUBAR_MAX |
|
|
346 | menubar_read (rs[Rs_menu]); |
|
|
347 | #endif |
|
|
348 | #ifdef HAVE_SCROLLBARS |
|
|
349 | if (options & Opt_scrollBar) |
|
|
350 | scrollBar.setIdle (); /* set existence for size calculations */ |
|
|
351 | #endif |
|
|
352 | |
|
|
353 | create_windows (argc, argv); |
|
|
354 | |
|
|
355 | init_xlocale (); |
|
|
356 | |
|
|
357 | scr_reset (); /* initialize screen */ |
|
|
358 | |
|
|
359 | #if 0 |
|
|
360 | XSynchronize (display->display, True); |
|
|
361 | #endif |
|
|
362 | |
|
|
363 | #ifdef HAVE_SCROLLBARS |
|
|
364 | if (options & Opt_scrollBar) |
|
|
365 | resize_scrollbar (); /* create and map scrollbar */ |
|
|
366 | #endif |
|
|
367 | #if (MENUBAR_MAX) |
|
|
368 | if (menubar_visible ()) |
|
|
369 | XMapWindow (display->display, menuBar.win); |
|
|
370 | #endif |
|
|
371 | #ifdef TRANSPARENT |
|
|
372 | if (options & Opt_transparent) |
|
|
373 | { |
|
|
374 | XSelectInput (display->display, display->root, PropertyChangeMask); |
|
|
375 | check_our_parents (); |
|
|
376 | rootwin_ev.start (display, display->root); |
|
|
377 | } |
|
|
378 | #endif |
|
|
379 | |
|
|
380 | XMapWindow (display->display, TermWin.vt); |
|
|
381 | XMapWindow (display->display, TermWin.parent[0]); |
|
|
382 | |
|
|
383 | set_colorfgbg (); |
|
|
384 | |
|
|
385 | init_command (cmd_argv); |
|
|
386 | |
|
|
387 | pty_ev.start (pty.pty, EVENT_READ); |
|
|
388 | |
|
|
389 | check_ev.start (); |
|
|
390 | |
|
|
391 | return true; |
|
|
392 | } |
|
|
393 | |
|
|
394 | static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event); |
|
|
395 | |
|
|
396 | void |
|
|
397 | rxvt_init () |
|
|
398 | { |
345 | /* |
399 | /* |
346 | * Save and then give up any super-user privileges |
400 | * Save and then give up any super-user privileges |
347 | * If we need privileges in any area then we must specifically request it. |
401 | * If we need privileges in any area then we must specifically request it. |
348 | * We should only need to be root in these cases: |
402 | * We should only need to be root in these cases: |
349 | * 1. write utmp entries on some systems |
403 | * 1. write utmp entries on some systems |
350 | * 2. chown tty on some systems |
404 | * 2. chown tty on some systems |
351 | */ |
405 | */ |
352 | privileges (SAVE); |
406 | rxvt_privileges (SAVE); |
353 | privileges (IGNORE); |
407 | rxvt_privileges (IGNORE); |
354 | |
408 | |
355 | init_secondary (); |
409 | signal (SIGHUP, SIG_IGN); |
356 | |
410 | signal (SIGPIPE, SIG_IGN); |
357 | const char **cmd_argv = init_resources (argc, argv); |
|
|
358 | |
|
|
359 | set_locale (""); |
|
|
360 | |
|
|
361 | #if MENUBAR_MAX |
|
|
362 | menubar_read (rs[Rs_menu]); |
|
|
363 | #endif |
|
|
364 | #ifdef HAVE_SCROLLBARS |
|
|
365 | if (Options & Opt_scrollBar) |
|
|
366 | scrollBar.setIdle (); /* set existence for size calculations */ |
|
|
367 | #endif |
|
|
368 | |
|
|
369 | create_windows (argc, argv); |
|
|
370 | |
|
|
371 | init_xlocale (); |
|
|
372 | |
|
|
373 | scr_reset (); /* initialize screen */ |
|
|
374 | |
|
|
375 | #if 0 |
|
|
376 | XSynchronize (display->display, True); |
|
|
377 | #endif |
|
|
378 | |
|
|
379 | #ifdef HAVE_SCROLLBARS |
|
|
380 | if (Options & Opt_scrollBar) |
|
|
381 | resize_scrollbar (); /* create and map scrollbar */ |
|
|
382 | #endif |
|
|
383 | #if (MENUBAR_MAX) |
|
|
384 | if (menubar_visible ()) |
|
|
385 | XMapWindow (display->display, menuBar.win); |
|
|
386 | #endif |
|
|
387 | #ifdef TRANSPARENT |
|
|
388 | if (Options & Opt_transparent) |
|
|
389 | { |
|
|
390 | XSelectInput (display->display, display->root, PropertyChangeMask); |
|
|
391 | check_our_parents (); |
|
|
392 | rootwin_ev.start (display, display->root); |
|
|
393 | } |
|
|
394 | #endif |
|
|
395 | |
|
|
396 | XMapWindow (display->display, TermWin.vt); |
|
|
397 | XMapWindow (display->display, TermWin.parent[0]); |
|
|
398 | |
|
|
399 | init_command (cmd_argv); |
|
|
400 | |
|
|
401 | pty_ev.start (cmd_fd, EVENT_READ); |
|
|
402 | |
|
|
403 | check_ev.start (); |
|
|
404 | |
|
|
405 | return true; |
|
|
406 | } |
|
|
407 | |
|
|
408 | static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event); |
|
|
409 | |
|
|
410 | void |
|
|
411 | rxvt_init_signals () |
|
|
412 | { |
|
|
413 | /* install exit handler for cleanup */ |
|
|
414 | #if 0 |
|
|
415 | #ifdef HAVE_ATEXIT |
|
|
416 | atexit (rxvt_clean_exit); |
|
|
417 | #else |
|
|
418 | #endif |
|
|
419 | #endif |
|
|
420 | |
|
|
421 | struct sigaction sa; |
|
|
422 | |
|
|
423 | sigfillset (&sa.sa_mask); |
|
|
424 | sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; |
|
|
425 | sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0); |
|
|
426 | sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0); |
|
|
427 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0); |
|
|
428 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0); |
|
|
429 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0); |
|
|
430 | sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0); |
|
|
431 | |
411 | |
432 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
412 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
433 | /* signal (SIGURG, SIG_DFL); */ |
413 | /* signal (SIGURG, SIG_DFL); */ |
434 | |
414 | |
435 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
415 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
|
|
416 | // TODO: handle this with exceptions and tolerate the memory loss |
436 | //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); |
417 | //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); |
437 | } |
418 | } |
438 | |
419 | |
439 | /* ------------------------------------------------------------------------- * |
420 | /* ------------------------------------------------------------------------- * |
440 | * SIGNAL HANDLING & EXIT HANDLER * |
421 | * SIGNAL HANDLING & EXIT HANDLER * |
441 | * ------------------------------------------------------------------------- */ |
422 | * ------------------------------------------------------------------------- */ |
442 | /* |
423 | /* |
443 | * Catch a SIGCHLD signal and exit if the direct child has died |
424 | * Catch a SIGCHLD signal and exit if the direct child has died |
444 | */ |
425 | */ |
445 | |
426 | |
446 | void rxvt_term::child_exited (int pid) |
427 | void |
|
|
428 | rxvt_term::sig_chld (sig_watcher &w) |
447 | { |
429 | { |
448 | for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++) |
430 | // we are being called for every SIGCHLD, not just ours |
449 | if (pid == (*t)->cmd_pid) |
431 | int pid; |
450 | { |
|
|
451 | (*t)->destroy (); |
|
|
452 | break; |
|
|
453 | } |
|
|
454 | } |
|
|
455 | |
|
|
456 | /* ARGSUSED */ |
|
|
457 | /* EXTPROTO */ |
|
|
458 | RETSIGTYPE |
|
|
459 | rxvt_Child_signal (int sig __attribute__ ((unused))) |
|
|
460 | { |
|
|
461 | int pid, save_errno = errno; |
|
|
462 | |
432 | |
463 | while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) |
433 | while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) |
464 | rxvt_term::child_exited (pid); |
434 | for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++) |
465 | |
435 | if (pid == (*t)->cmd_pid) |
466 | errno = save_errno; |
436 | { |
467 | } |
437 | (*t)->destroy (); |
468 | |
438 | break; |
469 | /* |
439 | } |
470 | * Catch a fatal signal and tidy up before quitting |
|
|
471 | */ |
|
|
472 | /* EXTPROTO */ |
|
|
473 | RETSIGTYPE |
|
|
474 | rxvt_Exit_signal (int sig) |
|
|
475 | { |
|
|
476 | signal (sig, SIG_DFL); |
|
|
477 | #ifdef DEBUG_CMD |
|
|
478 | rxvt_warn ("caught signal %d, exiting.\n", sig); |
|
|
479 | #endif |
|
|
480 | rxvt_clean_exit (); |
|
|
481 | kill (getpid (), sig); |
|
|
482 | } |
|
|
483 | |
|
|
484 | /* INTPROTO */ |
|
|
485 | int |
|
|
486 | rxvt_xerror_handler (Display *display, XErrorEvent *event) |
|
|
487 | { |
|
|
488 | if (GET_R->allowedxerror == -1) |
|
|
489 | GET_R->allowedxerror = event->error_code; |
|
|
490 | else |
|
|
491 | { |
|
|
492 | old_xerror_handler (display, event); |
|
|
493 | GET_R->destroy (); |
|
|
494 | } |
|
|
495 | |
|
|
496 | return 0; |
|
|
497 | } |
440 | } |
498 | |
441 | |
499 | /*----------------------------------------------------------------------*/ |
442 | /*----------------------------------------------------------------------*/ |
500 | /* |
443 | /* |
501 | * Exit gracefully, clearing the utmp entry and restoring tty attributes |
444 | * Exit gracefully, clearing the utmp entry and restoring tty attributes |
502 | * TODO: if debugging, this should free up any known resources if we can |
445 | * TODO: if debugging, this should free up any known resources if we can |
503 | */ |
446 | */ |
504 | /* EXTPROTO */ |
|
|
505 | void |
447 | void |
506 | rxvt_clean_exit () |
448 | rxvt_destroy_all () |
507 | { |
449 | { |
508 | // TODO: rxvtd should clean up all ressources |
450 | // TODO: rxvtd should clean up all ressources |
509 | if (GET_R) |
451 | for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) |
|
|
452 | (*t)->destroy (); |
|
|
453 | } |
|
|
454 | |
|
|
455 | /* |
|
|
456 | * Catch a fatal signal and tidy up before quitting |
|
|
457 | */ |
|
|
458 | void |
|
|
459 | rxvt_term::sig_term (sig_watcher &w) |
|
|
460 | { |
|
|
461 | #ifdef DEBUG_CMD |
|
|
462 | rxvt_warn ("caught signal %d, exiting.\n", w.signum); |
|
|
463 | #endif |
|
|
464 | rxvt_destroy_all (); |
|
|
465 | signal (w.signum, SIG_DFL); |
|
|
466 | kill (getpid (), w.signum); |
|
|
467 | } |
|
|
468 | |
|
|
469 | /* INTPROTO */ |
|
|
470 | int |
|
|
471 | rxvt_xerror_handler (Display *display, XErrorEvent *event) |
|
|
472 | { |
|
|
473 | if (GET_R->allowedxerror == -1) |
|
|
474 | GET_R->allowedxerror = event->error_code; |
|
|
475 | else |
|
|
476 | { |
|
|
477 | old_xerror_handler (display, event); |
510 | GET_R->destroy (); |
478 | GET_R->destroy (); |
|
|
479 | } |
|
|
480 | |
|
|
481 | return 0; |
511 | } |
482 | } |
512 | |
483 | |
513 | /* ------------------------------------------------------------------------- * |
484 | /* ------------------------------------------------------------------------- * |
514 | * MEMORY ALLOCATION WRAPPERS * |
485 | * MEMORY ALLOCATION WRAPPERS * |
515 | * ------------------------------------------------------------------------- */ |
486 | * ------------------------------------------------------------------------- */ |
516 | /* EXTPROTO */ |
487 | void * |
517 | void * |
|
|
518 | rxvt_malloc (size_t size) |
488 | rxvt_malloc (size_t size) |
519 | { |
489 | { |
520 | void *p; |
|
|
521 | |
|
|
522 | p = malloc (size); |
490 | void *p = malloc (size); |
|
|
491 | |
523 | if (p) |
492 | if (!p) |
|
|
493 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
|
|
494 | |
524 | return p; |
495 | return p; |
525 | |
|
|
526 | fprintf (stderr, RESNAME ": memory allocation failure. Aborting"); |
|
|
527 | rxvt_clean_exit (); |
|
|
528 | exit (EXIT_FAILURE); |
|
|
529 | /* NOTREACHED */ |
|
|
530 | } |
496 | } |
531 | |
497 | |
532 | /* EXTPROTO */ |
498 | /* INTPROTO */ |
533 | void * |
499 | void * |
534 | rxvt_calloc (size_t number, size_t size) |
500 | rxvt_calloc (size_t number, size_t size) |
535 | { |
501 | { |
536 | void *p; |
|
|
537 | |
|
|
538 | p = calloc (number, size); |
502 | void *p = calloc (number, size); |
|
|
503 | |
539 | if (p) |
504 | if (!p) |
|
|
505 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
|
|
506 | |
540 | return p; |
507 | return p; |
541 | |
|
|
542 | fprintf (stderr, RESNAME ": memory allocation failure. Aborting"); |
|
|
543 | rxvt_clean_exit (); |
|
|
544 | exit (EXIT_FAILURE); |
|
|
545 | /* NOTREACHED */ |
|
|
546 | } |
508 | } |
547 | |
509 | |
548 | /* EXTPROTO */ |
510 | /* INTPROTO */ |
549 | void * |
511 | void * |
550 | rxvt_realloc (void *ptr, size_t size) |
512 | rxvt_realloc (void *ptr, size_t size) |
551 | { |
513 | { |
552 | void *p; |
|
|
553 | |
|
|
554 | if (ptr) |
|
|
555 | p = realloc (ptr, size); |
514 | void *p = realloc (ptr, size); |
556 | else |
515 | |
557 | p = malloc (size); |
|
|
558 | if (p) |
516 | if (!p) |
|
|
517 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
|
|
518 | |
559 | return p; |
519 | return p; |
560 | |
|
|
561 | fprintf (stderr, RESNAME ": memory allocation failure. Aborting"); |
|
|
562 | rxvt_clean_exit (); |
|
|
563 | exit (EXIT_FAILURE); |
|
|
564 | /* NOTREACHED */ |
|
|
565 | } |
520 | } |
566 | |
521 | |
567 | /* ------------------------------------------------------------------------- * |
522 | /* ------------------------------------------------------------------------- * |
568 | * PRIVILEGED OPERATIONS * |
523 | * PRIVILEGED OPERATIONS * |
569 | * ------------------------------------------------------------------------- */ |
524 | * ------------------------------------------------------------------------- */ |
570 | /* take care of suid/sgid super-user (root) privileges */ |
525 | /* take care of suid/sgid super-user (root) privileges */ |
571 | void |
526 | void |
572 | rxvt_term::privileges (int mode) |
527 | rxvt_privileges (rxvt_privaction action) |
573 | { |
528 | { |
|
|
529 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
530 | static uid_t euid; |
|
|
531 | static gid_t egid; |
|
|
532 | #endif |
|
|
533 | |
574 | #if ! defined(__CYGWIN32__) |
534 | #if ! defined(__CYGWIN32__) |
575 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
535 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
576 | /* setreuid () is the poor man's setuid (), seteuid () */ |
536 | /* setreuid () is the poor man's setuid (), seteuid () */ |
577 | # define seteuid(a) setreuid(-1, (a)) |
537 | # define seteuid(a) setreuid(-1, (a)) |
578 | # define setegid(a) setregid(-1, (a)) |
538 | # define setegid(a) setregid(-1, (a)) |
579 | # define HAVE_SETEUID |
539 | # define HAVE_SETEUID |
580 | # endif |
540 | # endif |
581 | # ifdef HAVE_SETEUID |
541 | # ifdef HAVE_SETEUID |
582 | switch (mode) |
542 | switch (action) |
583 | { |
543 | { |
584 | case IGNORE: |
544 | case IGNORE: |
585 | /* |
545 | /* |
586 | * change effective uid/gid - not real uid/gid - so we can switch |
546 | * change effective uid/gid - not real uid/gid - so we can switch |
587 | * back to root later, as required |
547 | * back to root later, as required |
… | |
… | |
597 | seteuid (euid); |
557 | seteuid (euid); |
598 | setegid (egid); |
558 | setegid (egid); |
599 | break; |
559 | break; |
600 | } |
560 | } |
601 | # else |
561 | # else |
602 | switch (mode) |
562 | switch (action) |
603 | { |
563 | { |
604 | case IGNORE: |
564 | case IGNORE: |
605 | setuid (getuid ()); |
565 | setuid (getuid ()); |
606 | setgid (getgid ()); |
566 | setgid (getgid ()); |
607 | /* FALLTHROUGH */ |
567 | /* FALLTHROUGH */ |
… | |
… | |
614 | #endif |
574 | #endif |
615 | } |
575 | } |
616 | |
576 | |
617 | #ifdef UTMP_SUPPORT |
577 | #ifdef UTMP_SUPPORT |
618 | void |
578 | void |
619 | rxvt_term::privileged_utmp (char action) |
579 | rxvt_term::privileged_utmp (rxvt_privaction action) |
620 | { |
580 | { |
621 | D_MAIN ((stderr, "rxvt_privileged_utmp (%c); waiting for: %c (pid: %d)", |
|
|
622 | action, next_utmp_action, getpid ())); |
|
|
623 | if (next_utmp_action != action || (action != SAVE && action != RESTORE) |
|
|
624 | || (Options & Opt_utmpInhibit) |
581 | if ((options & Opt_utmpInhibit) |
625 | || ttydev == NULL || *ttydev == '\0') |
582 | || !pty.name || !*pty.name) |
626 | return; |
583 | return; |
627 | |
584 | |
628 | privileges (RESTORE); |
585 | rxvt_privileges (RESTORE); |
|
|
586 | |
629 | if (action == SAVE) |
587 | if (action == SAVE) |
630 | { |
|
|
631 | next_utmp_action = RESTORE; |
|
|
632 | makeutent (ttydev, rs[Rs_display_name]); |
588 | makeutent (pty.name, rs[Rs_display_name]); |
633 | } |
|
|
634 | else |
589 | else |
635 | { /* action == RESTORE */ |
|
|
636 | next_utmp_action = IGNORE; |
|
|
637 | cleanutent (); |
590 | cleanutent (); |
638 | } |
591 | |
639 | privileges (IGNORE); |
592 | rxvt_privileges (IGNORE); |
640 | } |
|
|
641 | #endif |
|
|
642 | |
|
|
643 | #ifndef NO_SETOWNER_TTYDEV |
|
|
644 | void |
|
|
645 | rxvt_term::privileged_ttydev (char action) |
|
|
646 | { |
|
|
647 | D_MAIN ((stderr, |
|
|
648 | "privileged_ttydev (%c); waiting for: %c (pid: %d)", |
|
|
649 | action, next_tty_action, getpid ())); |
|
|
650 | if (next_tty_action != action || (action != SAVE && action != RESTORE) |
|
|
651 | || ttydev == NULL || *ttydev == '\0') |
|
|
652 | return; |
|
|
653 | |
|
|
654 | privileges (RESTORE); |
|
|
655 | |
|
|
656 | if (action == SAVE) |
|
|
657 | { |
|
|
658 | next_tty_action = RESTORE; |
|
|
659 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
|
|
660 | /* store original tty status for restoration rxvt_clean_exit () -- rgg 04/12/95 */ |
|
|
661 | if (lstat (ttydev, &ttyfd_stat) < 0) /* you lose out */ |
|
|
662 | next_tty_action = IGNORE; |
|
|
663 | else |
|
|
664 | # endif |
|
|
665 | |
|
|
666 | { |
|
|
667 | chown (ttydev, getuid (), ttygid); /* fail silently */ |
|
|
668 | chmod (ttydev, ttymode); |
|
|
669 | # ifdef HAVE_REVOKE |
|
|
670 | revoke (ttydev); |
|
|
671 | # endif |
|
|
672 | |
|
|
673 | } |
|
|
674 | } |
|
|
675 | else |
|
|
676 | { /* action == RESTORE */ |
|
|
677 | next_tty_action = IGNORE; |
|
|
678 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
|
|
679 | chmod (ttydev, ttyfd_stat.st_mode); |
|
|
680 | chown (ttydev, ttyfd_stat.st_uid, ttyfd_stat.st_gid); |
|
|
681 | # else |
|
|
682 | chmod (ttydev, |
|
|
683 | (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)); |
|
|
684 | chown (ttydev, 0, 0); |
|
|
685 | # endif |
|
|
686 | |
|
|
687 | } |
|
|
688 | |
|
|
689 | privileges (IGNORE); |
|
|
690 | |
|
|
691 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
|
|
692 | D_MAIN ((stderr, "%s \"%s\": mode %03o, uid %d, gid %d", |
|
|
693 | action == RESTORE ? "Restoring" : (action == |
|
|
694 | SAVE ? "Saving" : |
|
|
695 | "UNKNOWN ERROR for"), ttydev, |
|
|
696 | ttyfd_stat.st_mode, ttyfd_stat.st_uid, |
|
|
697 | ttyfd_stat.st_gid)); |
|
|
698 | # endif |
|
|
699 | } |
593 | } |
700 | #endif |
594 | #endif |
701 | |
595 | |
702 | /*----------------------------------------------------------------------*/ |
596 | /*----------------------------------------------------------------------*/ |
703 | /* |
597 | /* |
… | |
… | |
774 | |
668 | |
775 | if (scrollbar_visible ()) |
669 | if (scrollbar_visible ()) |
776 | { |
670 | { |
777 | sb_w = scrollbar_TotalWidth (); |
671 | sb_w = scrollbar_TotalWidth (); |
778 | szHint.base_width += sb_w; |
672 | szHint.base_width += sb_w; |
779 | if (!(Options & Opt_scrollBar_right)) |
673 | if (!(options & Opt_scrollBar_right)) |
780 | window_vt_x += sb_w; |
674 | window_vt_x += sb_w; |
781 | } |
675 | } |
782 | |
676 | |
783 | if (menubar_visible ()) |
677 | if (menubar_visible ()) |
784 | { |
678 | { |
… | |
… | |
812 | { |
706 | { |
813 | MIN_IT (TermWin.height, max_height); |
707 | MIN_IT (TermWin.height, max_height); |
814 | szHint.height = szHint.base_height + TermWin.height; |
708 | szHint.height = szHint.base_height + TermWin.height; |
815 | } |
709 | } |
816 | |
710 | |
817 | if (scrollbar_visible () && (Options & Opt_scrollBar_right)) |
711 | if (scrollbar_visible () && (options & Opt_scrollBar_right)) |
818 | window_sb_x = szHint.width - sb_w; |
712 | window_sb_x = szHint.width - sb_w; |
819 | |
713 | |
820 | if (recalc_x) |
714 | if (recalc_x) |
821 | szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) |
715 | szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) |
822 | - szHint.width - 2 * TermWin.ext_bwidth); |
716 | - szHint.width - 2 * TermWin.ext_bwidth); |
… | |
… | |
838 | * Called after a window size change. |
732 | * Called after a window size change. |
839 | */ |
733 | */ |
840 | void |
734 | void |
841 | rxvt_term::tt_winch () |
735 | rxvt_term::tt_winch () |
842 | { |
736 | { |
|
|
737 | if (pty.pty < 0) |
|
|
738 | return; |
|
|
739 | |
843 | struct winsize ws; |
740 | struct winsize ws; |
844 | |
|
|
845 | if (cmd_fd < 0) |
|
|
846 | return; |
|
|
847 | |
741 | |
848 | ws.ws_col = TermWin.ncol; |
742 | ws.ws_col = TermWin.ncol; |
849 | ws.ws_row = TermWin.nrow; |
743 | ws.ws_row = TermWin.nrow; |
850 | ws.ws_xpixel = ws.ws_ypixel = 0; |
744 | ws.ws_xpixel = TermWin.width; |
851 | #ifndef DEBUG_SIZE |
745 | ws.ws_ypixel = TermWin.height; |
852 | (void)ioctl (cmd_fd, TIOCSWINSZ, &ws); |
746 | (void)ioctl (pty.pty, TIOCSWINSZ, &ws); |
853 | #else |
747 | |
854 | if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0) |
748 | #if 0 |
855 | D_SIZE ((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); |
749 | // TIOCSWINSZ⎈ is supposed to do this automatically and correctly |
856 | # ifdef SIGWINCH |
|
|
857 | else if (cmd_pid) /* force through to the command */ |
750 | if (cmd_pid) /* force through to the command */ |
858 | kill (cmd_pid, SIGWINCH); |
751 | kill (cmd_pid, SIGWINCH); |
859 | # endif |
|
|
860 | #endif |
752 | #endif |
861 | } |
753 | } |
862 | |
754 | |
863 | /*----------------------------------------------------------------------*/ |
755 | /*----------------------------------------------------------------------*/ |
864 | /* rxvt_change_font () - Switch to a new font */ |
756 | /* set_fonts () - load and set the various fonts |
865 | /* |
757 | /* |
866 | * init = 1 - initialize |
758 | * init = 1 - initialize |
867 | * |
759 | * |
868 | * fontname == FONT_UP - switch to bigger font |
760 | * fontname == FONT_UP - switch to bigger font |
869 | * fontname == FONT_DN - switch to smaller font |
761 | * fontname == FONT_DN - switch to smaller font |
870 | */ |
762 | */ |
871 | bool |
763 | bool |
872 | rxvt_term::change_font (const char *fontname) |
764 | rxvt_term::set_fonts () |
873 | { |
765 | { |
874 | if (fontname == FONT_UP) |
|
|
875 | { |
|
|
876 | // TODO |
|
|
877 | } |
|
|
878 | else if (fontname == FONT_DN) |
|
|
879 | { |
|
|
880 | // TODO |
|
|
881 | } |
|
|
882 | else |
|
|
883 | { |
|
|
884 | rxvt_fontset *fs = new rxvt_fontset (this); |
766 | rxvt_fontset *fs = new rxvt_fontset (this); |
|
|
767 | rxvt_fontprop prop; |
885 | |
768 | |
886 | if (fs && fs->populate (fontname ? fontname : "fixed")) |
769 | if (!fs |
|
|
770 | || !fs->populate (rs[Rs_font] ? rs[Rs_font] : "fixed") |
|
|
771 | || !fs->realize_font (1)) |
|
|
772 | { |
|
|
773 | delete fs; |
|
|
774 | return false; |
|
|
775 | } |
|
|
776 | |
|
|
777 | #if ENABLE_STYLES |
|
|
778 | for (int i = RS_styleCount; --i; ) |
|
|
779 | if (TermWin.fontset[i] != TermWin.fontset[0]) |
|
|
780 | delete TermWin.fontset[i]; |
|
|
781 | #endif |
|
|
782 | |
|
|
783 | delete TermWin.fontset[0]; |
|
|
784 | TermWin.fontset[0] = fs; |
|
|
785 | |
|
|
786 | prop = (*fs)[1]->properties (); |
|
|
787 | fs->set_prop (prop); |
|
|
788 | |
|
|
789 | TermWin.fwidth = prop.width; |
|
|
790 | TermWin.fheight = prop.height; |
|
|
791 | TermWin.fweight = prop.weight; |
|
|
792 | TermWin.fslant = prop.slant; |
|
|
793 | TermWin.fbase = (*fs)[1]->ascent; |
|
|
794 | |
|
|
795 | for (int style = 1; style < 4; style++) |
|
|
796 | { |
|
|
797 | #if ENABLE_STYLES |
|
|
798 | const char *res = rs[Rs_font + style]; |
|
|
799 | |
|
|
800 | if (res && !*res) |
|
|
801 | TermWin.fontset[style] = TermWin.fontset[0]; |
|
|
802 | else |
887 | { |
803 | { |
888 | delete TermWin.fontset; |
804 | TermWin.fontset[style] = fs = new rxvt_fontset (this); |
889 | TermWin.fontset = fs; |
805 | rxvt_fontprop prop2 = prop; |
890 | TermWin.fwidth = fs->base_font ()->width; |
|
|
891 | TermWin.fheight = fs->base_font ()->height; |
|
|
892 | TermWin.fbase = fs->base_font ()->ascent; |
|
|
893 | |
806 | |
894 | if (TermWin.parent[0]) |
807 | if (res) |
|
|
808 | prop2.weight = prop2.slant = rxvt_fontprop::unset; |
|
|
809 | else |
895 | { |
810 | { |
896 | resize_all_windows (0, 0, 0); |
811 | res = TermWin.fontset[0]->fontdesc; |
897 | scr_remap_chars (); |
812 | |
898 | scr_touch (true); |
813 | if (SET_STYLE (0, style) & RS_Bold) prop2.weight = rxvt_fontprop::bold; |
|
|
814 | if (SET_STYLE (0, style) & RS_Italic) prop2.slant = rxvt_fontprop::italic; |
899 | } |
815 | } |
900 | |
816 | |
901 | for (unicode_t ch = 0x20; ch <= 0x7f; ch++) |
817 | fs->populate (res); |
902 | TermWin.ascii_map [ch - 0x20] = fs->find_font (ch); |
818 | fs->set_prop (prop2); |
903 | |
|
|
904 | return true; |
|
|
905 | } |
819 | } |
|
|
820 | #else |
|
|
821 | TermWin.fontset[style] = TermWin.fontset[0]; |
|
|
822 | #endif |
|
|
823 | } |
|
|
824 | |
|
|
825 | if (TermWin.parent[0]) |
906 | } |
826 | { |
|
|
827 | resize_all_windows (0, 0, 0); |
|
|
828 | scr_remap_chars (); |
|
|
829 | scr_touch (true); |
|
|
830 | } |
907 | |
831 | |
908 | return false; |
832 | return true; |
909 | } |
833 | } |
910 | |
834 | |
911 | bool |
835 | void rxvt_term::set_string_property (Atom prop, const char *str, int len) |
912 | rxvt_term::font_up_down (int n, int direction) |
|
|
913 | { |
836 | { |
914 | return false; |
837 | // TODO: SMART_WINDOW_TITLE |
|
|
838 | XChangeProperty (display->display, TermWin.parent[0], |
|
|
839 | prop, XA_STRING, 8, PropModeReplace, |
|
|
840 | (const unsigned char *)str, len >= 0 ? len : strlen (str)); |
|
|
841 | } |
|
|
842 | |
|
|
843 | void rxvt_term::set_utf8_property (Atom prop, const char *str, int len) |
|
|
844 | { |
|
|
845 | // TODO: SMART_WINDOW_TITLE |
|
|
846 | wchar_t *ws = rxvt_mbstowcs (str, len); |
|
|
847 | char *s = rxvt_wcstoutf8 (ws); |
|
|
848 | |
|
|
849 | XChangeProperty (display->display, TermWin.parent[0], |
|
|
850 | prop, xa[XA_UTF8_STRING], 8, PropModeReplace, |
|
|
851 | (const unsigned char *)s, strlen (s)); |
|
|
852 | |
|
|
853 | free (s); |
|
|
854 | free (ws); |
915 | } |
855 | } |
916 | |
856 | |
917 | /*----------------------------------------------------------------------*/ |
857 | /*----------------------------------------------------------------------*/ |
918 | /*----------------------------------------------------------------------*/ |
858 | /*----------------------------------------------------------------------*/ |
919 | /* xterm sequences - title, iconName, color (exptl) */ |
859 | /* xterm sequences - title, iconName, color (exptl) */ |
920 | void |
860 | void |
921 | rxvt_term::set_title (const char *str) |
861 | rxvt_term::set_title (const char *str) |
922 | { |
862 | { |
923 | #ifdef SMART_WINDOW_TITLE |
863 | set_string_property (XA_WM_NAME, str); |
924 | char *name; |
864 | #if ENABLE_FRILLS |
925 | |
865 | set_utf8_property (xa[XA_NET_WM_NAME], str); |
926 | if (!XFetchName (display->display, TermWin.parent[0], &name)) |
|
|
927 | name = NULL; |
|
|
928 | |
|
|
929 | if (name == NULL || STRCMP (name, str)) |
|
|
930 | #endif |
|
|
931 | XStoreName (display->display, TermWin.parent[0], str); |
|
|
932 | |
|
|
933 | #ifdef SMART_WINDOW_TITLE |
|
|
934 | if (name) |
|
|
935 | XFree (name); |
|
|
936 | #endif |
866 | #endif |
937 | } |
867 | } |
938 | |
868 | |
939 | void |
869 | void |
940 | rxvt_term::set_icon_name (const char *str) |
870 | rxvt_term::set_icon_name (const char *str) |
941 | { |
871 | { |
942 | #ifdef SMART_WINDOW_TITLE |
872 | set_string_property (XA_WM_ICON_NAME, str); |
943 | char *name; |
873 | #if ENABLE_FRILLS |
944 | |
874 | set_utf8_property (xa[XA_NET_WM_ICON_NAME], str); |
945 | if (!XGetIconName (display->display, TermWin.parent[0], &name)) |
|
|
946 | name = NULL; |
|
|
947 | |
|
|
948 | if (name == NULL || STRCMP (name, str)) |
|
|
949 | #endif |
|
|
950 | XSetIconName (display->display, TermWin.parent[0], str); |
|
|
951 | |
|
|
952 | #ifdef SMART_WINDOW_TITLE |
|
|
953 | if (name) |
|
|
954 | XFree (name); |
|
|
955 | #endif |
875 | #endif |
956 | } |
876 | } |
957 | |
877 | |
958 | #ifdef XTERM_COLOR_CHANGE |
878 | #ifdef XTERM_COLOR_CHANGE |
959 | void |
879 | void |
… | |
… | |
971 | i = atoi (color); |
891 | i = atoi (color); |
972 | if (i >= 8 && i <= 15) |
892 | if (i >= 8 && i <= 15) |
973 | { /* bright colors */ |
893 | { /* bright colors */ |
974 | i -= 8; |
894 | i -= 8; |
975 | # ifndef NO_BRIGHTCOLOR |
895 | # ifndef NO_BRIGHTCOLOR |
976 | PixColorsFocused[idx] = PixColorsFocused[minBrightCOLOR + i]; |
896 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
977 | SET_PIXCOLOR (idx); |
897 | SET_PIXCOLOR (idx); |
978 | goto Done; |
898 | goto Done; |
979 | # endif |
899 | # endif |
980 | |
900 | |
981 | } |
901 | } |
982 | if (i >= 0 && i <= 7) |
902 | if (i >= 0 && i <= 7) |
983 | { /* normal colors */ |
903 | { /* normal colors */ |
984 | PixColorsFocused[idx] = PixColorsFocused[minCOLOR + i]; |
904 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
985 | SET_PIXCOLOR (idx); |
905 | SET_PIXCOLOR (idx); |
986 | goto Done; |
906 | goto Done; |
987 | } |
907 | } |
988 | } |
908 | } |
989 | |
909 | |
… | |
… | |
996 | * FIXME: should free colors here, but no idea how to do it so instead, |
916 | * FIXME: should free colors here, but no idea how to do it so instead, |
997 | * so just keep gobbling up the colormap |
917 | * so just keep gobbling up the colormap |
998 | */ |
918 | */ |
999 | # if 0 |
919 | # if 0 |
1000 | for (i = Color_Black; i <= Color_White; i++) |
920 | for (i = Color_Black; i <= Color_White; i++) |
1001 | if (PixColors[idx] == PixColors[i]) |
921 | if (pix_colors[idx] == pix_colors[i]) |
1002 | break; |
922 | break; |
1003 | if (i > Color_White) |
923 | if (i > Color_White) |
1004 | { |
924 | { |
1005 | /* fprintf (stderr, "XFreeColors: PixColors [%d] = %lu\n", idx, PixColors [idx]); */ |
925 | /* fprintf (stderr, "XFreeColors: pix_colors [%d] = %lu\n", idx, pix_colors [idx]); */ |
1006 | XFreeColors (display->display, display->cmap, (PixColors + idx), 1, |
926 | XFreeColors (display->display, display->cmap, (pix_colors + idx), 1, |
1007 | DisplayPlanes (display->display, display->screen)); |
927 | DisplayPlanes (display->display, display->screen)); |
1008 | } |
928 | } |
1009 | # endif |
929 | # endif |
1010 | |
930 | |
1011 | PixColorsFocused[idx] = xcol; |
931 | pix_colors_focused[idx] = xcol; |
1012 | SET_PIXCOLOR (idx); |
932 | SET_PIXCOLOR (idx); |
1013 | |
933 | |
1014 | /* XSetWindowAttributes attr; */ |
934 | /* XSetWindowAttributes attr; */ |
1015 | /* Cursor cursor; */ |
935 | /* Cursor cursor; */ |
1016 | Done: |
936 | Done: |
1017 | #ifdef OFF_FOCUS_FADING |
937 | #ifdef OFF_FOCUS_FADING |
|
|
938 | if (rs[Rs_fade]) |
1018 | PixColorsUnFocused[idx] = PixColorsFocused[idx].fade (display, atoi (rs[Rs_fade])); |
939 | pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade])); |
1019 | #endif |
940 | #endif |
1020 | if (idx == Color_bg && ! (Options & Opt_transparent)) |
|
|
1021 | XSetWindowBackground (display->display, TermWin.vt, PixColors[Color_bg]); |
|
|
1022 | |
941 | |
1023 | /* handle Color_BD, scrollbar background, etc. */ |
942 | /*TODO: handle Color_BD, scrollbar background, etc. */ |
1024 | |
943 | |
1025 | set_colorfgbg (); |
|
|
1026 | recolour_cursor (); |
944 | recolour_cursor (); |
1027 | scr_touch (true); |
945 | scr_recolour (); |
1028 | } |
946 | } |
1029 | |
947 | |
1030 | #else |
948 | #else |
1031 | # define set_window_color (idx,color) ((void)0) |
949 | # define set_window_color (idx,color) ((void)0) |
1032 | #endif /* XTERM_COLOR_CHANGE */ |
950 | #endif /* XTERM_COLOR_CHANGE */ |
… | |
… | |
1034 | void |
952 | void |
1035 | rxvt_term::recolour_cursor () |
953 | rxvt_term::recolour_cursor () |
1036 | { |
954 | { |
1037 | XColor xcol[2]; |
955 | XColor xcol[2]; |
1038 | |
956 | |
1039 | xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) ? PixColorsFocused[Color_pointer_fg] : PixColorsFocused[Color_fg]; |
957 | xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) |
1040 | xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) ? PixColorsFocused[Color_pointer_bg] : PixColorsFocused[Color_bg]; |
958 | ? pix_colors_focused[Color_pointer_fg] |
|
|
959 | : pix_colors_focused[Color_fg]; |
|
|
960 | xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) |
|
|
961 | ? pix_colors_focused[Color_pointer_bg] |
|
|
962 | : pix_colors_focused[Color_bg]; |
|
|
963 | |
1041 | XQueryColors (display->display, display->cmap, xcol, 2); |
964 | XQueryColors (display->display, display->cmap, xcol, 2); |
1042 | XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1); |
965 | XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1); |
1043 | } |
966 | } |
1044 | |
967 | |
1045 | /*----------------------------------------------------------------------*/ |
968 | /*----------------------------------------------------------------------*/ |
… | |
… | |
1047 | * find if fg/bg matches any of the normal (low-intensity) colors |
970 | * find if fg/bg matches any of the normal (low-intensity) colors |
1048 | */ |
971 | */ |
1049 | void |
972 | void |
1050 | rxvt_term::set_colorfgbg () |
973 | rxvt_term::set_colorfgbg () |
1051 | { |
974 | { |
1052 | unsigned int i; |
975 | unsigned int i; |
1053 | const char *xpmb = "\0"; |
976 | const char *xpmb = "\0"; |
1054 | char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1]; |
977 | char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1]; |
1055 | |
978 | |
1056 | env_colorfgbg = |
|
|
1057 | (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1); |
979 | env_colorfgbg = (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1); |
1058 | STRCPY (fstr, "default"); |
980 | strcpy (fstr, "default"); |
1059 | STRCPY (bstr, "default"); |
981 | strcpy (bstr, "default"); |
1060 | for (i = Color_Black; i <= Color_White; i++) |
982 | for (i = Color_Black; i <= Color_White; i++) |
1061 | if (PixColors[Color_fg] == PixColors[i]) |
983 | if (pix_colors[Color_fg] == pix_colors[i]) |
1062 | { |
984 | { |
1063 | sprintf (fstr, "%d", (i - Color_Black)); |
985 | sprintf (fstr, "%d", (i - Color_Black)); |
1064 | break; |
986 | break; |
1065 | } |
987 | } |
|
|
988 | |
1066 | for (i = Color_Black; i <= Color_White; i++) |
989 | for (i = Color_Black; i <= Color_White; i++) |
1067 | if (PixColors[Color_bg] == PixColors[i]) |
990 | if (pix_colors[Color_bg] == pix_colors[i]) |
1068 | { |
991 | { |
1069 | sprintf (bstr, "%d", (i - Color_Black)); |
992 | sprintf (bstr, "%d", (i - Color_Black)); |
1070 | #ifdef XPM_BACKGROUND |
993 | #ifdef XPM_BACKGROUND |
1071 | xpmb = "default;"; |
994 | xpmb = "default;"; |
1072 | #endif |
995 | #endif |
1073 | break; |
996 | break; |
1074 | } |
997 | } |
1075 | |
998 | |
1076 | sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); |
999 | sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); |
1077 | |
|
|
1078 | #ifndef NO_BRIGHTCOLOR |
|
|
1079 | colorfgbg = DEFAULT_RSTYLE; |
|
|
1080 | for (i = minCOLOR; i <= maxCOLOR; i++) |
|
|
1081 | { |
|
|
1082 | if (PixColors[Color_fg] == PixColors[i]) |
|
|
1083 | colorfgbg = SET_FGCOLOR (colorfgbg, i); |
|
|
1084 | if (PixColors[Color_bg] == PixColors[i]) |
|
|
1085 | colorfgbg = SET_BGCOLOR (colorfgbg, i); |
|
|
1086 | } |
|
|
1087 | #endif |
|
|
1088 | } |
1000 | } |
1089 | |
1001 | |
1090 | /*----------------------------------------------------------------------*/ |
1002 | /*----------------------------------------------------------------------*/ |
1091 | /* |
|
|
1092 | * Colour determination for low colour displays, routine from |
|
|
1093 | * Hans de Goede <hans@highrise.nl> |
|
|
1094 | */ |
|
|
1095 | |
1003 | |
1096 | int |
1004 | int |
1097 | rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) |
1005 | rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) |
1098 | { |
1006 | { |
1099 | if (!screen_in_out->set (display, colour)) |
1007 | if (!screen_in_out->set (display, colour)) |
… | |
… | |
1255 | * - X INPUT METHOD ROUTINES - * |
1163 | * - X INPUT METHOD ROUTINES - * |
1256 | * -------------------------------------------------------------------- */ |
1164 | * -------------------------------------------------------------------- */ |
1257 | #ifdef USE_XIM |
1165 | #ifdef USE_XIM |
1258 | |
1166 | |
1259 | void |
1167 | void |
|
|
1168 | rxvt_term::im_set_color (unsigned long &fg, unsigned long &bg) |
|
|
1169 | { |
|
|
1170 | fg = pix_colors[Color_fg]; |
|
|
1171 | bg = pix_colors[Color_bg]; |
|
|
1172 | } |
|
|
1173 | |
|
|
1174 | void |
1260 | rxvt_term::im_set_size (XRectangle *size) |
1175 | rxvt_term::im_set_size (XRectangle &size) |
1261 | { |
1176 | { |
|
|
1177 | // the int_bwidth terms make no sense to me |
1262 | size->x = TermWin.int_bwidth; |
1178 | size.x = TermWin.int_bwidth; |
1263 | size->y = TermWin.int_bwidth; |
1179 | size.y = TermWin.int_bwidth; |
1264 | size->width = Width2Pixel (TermWin.ncol); |
1180 | size.width = Width2Pixel (TermWin.ncol) + TermWin.int_bwidth; |
1265 | size->height = Height2Pixel (TermWin.nrow); |
1181 | size.height = Height2Pixel (TermWin.nrow) + TermWin.int_bwidth; |
1266 | } |
1182 | } |
1267 | |
1183 | |
1268 | void |
1184 | void |
1269 | rxvt_term::im_set_color (unsigned long *fg, unsigned long *bg) |
1185 | rxvt_term::im_set_preedit_area (XRectangle &preedit_rect, |
|
|
1186 | XRectangle &status_rect, |
|
|
1187 | const XRectangle &needed_rect) |
1270 | { |
1188 | { |
1271 | *fg = PixColors[Color_fg]; |
1189 | preedit_rect.x = needed_rect.width; |
1272 | *bg = PixColors[Color_bg]; |
1190 | preedit_rect.y = 0; |
|
|
1191 | preedit_rect.width = Width2Pixel (TermWin.ncol) - needed_rect.width + 1; |
|
|
1192 | preedit_rect.height = TermWin.fheight; |
|
|
1193 | |
|
|
1194 | status_rect.x = 0; |
|
|
1195 | status_rect.y = 0; |
|
|
1196 | status_rect.width = needed_rect.width ? needed_rect.width : Width2Pixel (TermWin.ncol) + 1; |
|
|
1197 | status_rect.height = TermWin.fheight; |
1273 | } |
1198 | } |
1274 | |
1199 | |
1275 | /* Checking whether input method is running. */ |
1200 | /* Checking whether input method is running. */ |
1276 | bool |
1201 | bool |
1277 | rxvt_term::IMisRunning () |
1202 | rxvt_term::IMisRunning () |
1278 | { |
1203 | { |
1279 | char *p; |
1204 | char *p; |
1280 | Atom atom; |
1205 | Atom atom; |
1281 | Window win; |
1206 | Window win; |
1282 | char server[IMBUFSIZ]; |
1207 | char server[IMBUFSIZ]; |
1283 | |
1208 | |
1284 | /* get current locale modifier */ |
1209 | /* get current locale modifier */ |
1285 | if ((p = XSetLocaleModifiers (NULL)) != NULL) |
1210 | if ((p = XSetLocaleModifiers (NULL)) != NULL) |
1286 | { |
1211 | { |
1287 | STRCPY (server, "@server="); |
1212 | strcpy (server, "@server="); |
1288 | STRNCAT (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */ |
1213 | strncat (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */ |
|
|
1214 | |
1289 | if ((p = STRCHR (server + 1, '@')) != NULL) /* first one only */ |
1215 | if ((p = strchr (server + 1, '@')) != NULL) /* first one only */ |
1290 | *p = '\0'; |
1216 | *p = '\0'; |
1291 | |
1217 | |
1292 | atom = XInternAtom (display->display, server, False); |
1218 | atom = XInternAtom (display->display, server, False); |
1293 | win = XGetSelectionOwner (display->display, atom); |
1219 | win = XGetSelectionOwner (display->display, atom); |
|
|
1220 | |
1294 | if (win != None) |
1221 | if (win != None) |
1295 | return True; |
1222 | return True; |
1296 | } |
1223 | } |
|
|
1224 | |
1297 | return False; |
1225 | return False; |
1298 | } |
1226 | } |
1299 | |
1227 | |
1300 | void |
1228 | void |
1301 | rxvt_term::IMSendSpot () |
1229 | rxvt_term::IMSendSpot () |
1302 | { |
1230 | { |
1303 | XPoint spot; |
1231 | XPoint nspot; |
1304 | XVaNestedList preedit_attr; |
1232 | XVaNestedList preedit_attr; |
1305 | |
1233 | |
1306 | if (Input_Context == NULL |
1234 | if (!Input_Context |
|
|
1235 | || !TermWin.focus |
1307 | || !TermWin.focus || ! (input_style & XIMPreeditPosition) |
1236 | || !(input_style & XIMPreeditPosition)) |
1308 | || ! (event_type == KeyPress |
|
|
1309 | || event_type == Expose |
|
|
1310 | || event_type == NoExpose |
|
|
1311 | || event_type == SelectionNotify |
|
|
1312 | || event_type == ButtonRelease || event_type == FocusIn) |
|
|
1313 | || !IMisRunning ()) |
|
|
1314 | return; |
1237 | return; |
1315 | |
1238 | |
1316 | im_set_position (&spot); |
1239 | im_set_position (nspot); |
|
|
1240 | |
|
|
1241 | if (nspot.x == spot.x && nspot.y == spot.y) |
|
|
1242 | return; |
|
|
1243 | |
|
|
1244 | spot = nspot; |
1317 | |
1245 | |
1318 | preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); |
1246 | preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); |
1319 | XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); |
1247 | XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); |
1320 | XFree (preedit_attr); |
1248 | XFree (preedit_attr); |
1321 | } |
1249 | } |
1322 | |
1250 | |
1323 | void |
1251 | void |
1324 | rxvt_term::im_set_preedit_area (XRectangle * preedit_rect, XRectangle * status_rect, |
|
|
1325 | XRectangle * needed_rect) |
|
|
1326 | { |
|
|
1327 | int mbh, vtx = 0; |
|
|
1328 | |
|
|
1329 | if (scrollbar_visible () && ! (Options & Opt_scrollBar_right)) |
|
|
1330 | vtx = scrollbar_TotalWidth (); |
|
|
1331 | |
|
|
1332 | mbh = menubar_visible () ? menuBar_TotalHeight () : 0; |
|
|
1333 | mbh -= TermWin.lineSpace; |
|
|
1334 | |
|
|
1335 | preedit_rect->x = needed_rect->width + vtx; |
|
|
1336 | preedit_rect->y = Height2Pixel (TermWin.nrow - 1) + mbh; |
|
|
1337 | |
|
|
1338 | preedit_rect->width = Width2Pixel (TermWin.ncol + 1) - needed_rect->width + vtx; |
|
|
1339 | preedit_rect->height = Height2Pixel (1); |
|
|
1340 | |
|
|
1341 | status_rect->x = vtx; |
|
|
1342 | status_rect->y = Height2Pixel (TermWin.nrow - 1) + mbh; |
|
|
1343 | |
|
|
1344 | status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel (TermWin.ncol + 1); |
|
|
1345 | status_rect->height = Height2Pixel (1); |
|
|
1346 | } |
|
|
1347 | |
|
|
1348 | void |
|
|
1349 | rxvt_term::im_destroy () |
1252 | rxvt_term::im_destroy () |
1350 | { |
1253 | { |
1351 | if (Input_Context) |
|
|
1352 | { |
|
|
1353 | XDestroyIC (Input_Context); |
|
|
1354 | Input_Context = NULL; |
|
|
1355 | } |
|
|
1356 | |
|
|
1357 | if (input_method) |
1254 | if (input_method) |
1358 | { |
1255 | { |
|
|
1256 | if (Input_Context && input_method->xim) |
|
|
1257 | XDestroyIC (Input_Context); |
|
|
1258 | |
1359 | display->put_xim (input_method); |
1259 | display->put_xim (input_method); |
1360 | input_method = 0; |
1260 | input_method = 0; |
1361 | } |
1261 | } |
|
|
1262 | |
|
|
1263 | Input_Context = 0; |
1362 | } |
1264 | } |
1363 | |
1265 | |
1364 | /* |
1266 | /* |
1365 | * Try to open a XIM with the current modifiers, then see if we can |
1267 | * Try to open a XIM with the current modifiers, then see if we can |
1366 | * open a suitable preedit type |
1268 | * open a suitable preedit type |
1367 | */ |
1269 | */ |
1368 | bool |
1270 | bool |
1369 | rxvt_term::IM_get_IC (const char *modifiers) |
1271 | rxvt_term::IM_get_IC (const char *modifiers) |
1370 | { |
1272 | { |
1371 | int i, j, found; |
1273 | int i, j, found; |
1372 | XIM xim; |
1274 | XIM xim; |
1373 | XPoint spot; |
1275 | XPoint spot; |
1374 | XRectangle rect, status_rect, needed_rect; |
1276 | XRectangle rect, status_rect, needed_rect; |
1375 | unsigned long fg, bg; |
1277 | unsigned long fg, bg; |
1376 | const char *p; |
1278 | const char *p; |
1377 | char **s; |
1279 | char **s; |
1378 | XIMStyles *xim_styles; |
1280 | XIMStyles *xim_styles; |
1379 | XVaNestedList preedit_attr, status_attr; |
|
|
1380 | |
1281 | |
1381 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1282 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1382 | return false; |
1283 | return false; |
1383 | |
1284 | |
1384 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
1285 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
1385 | input_method = display->get_xim (locale, modifiers); |
1286 | input_method = display->get_xim (locale, modifiers); |
1386 | if (input_method == NULL) |
1287 | if (input_method == NULL) |
1387 | return false; |
1288 | return false; |
1388 | |
1289 | |
1389 | xim = input_method->xim; |
1290 | xim = input_method->xim; |
|
|
1291 | spot.x = spot.y = -1; |
1390 | |
1292 | |
1391 | xim_styles = NULL; |
1293 | xim_styles = NULL; |
1392 | if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) |
1294 | if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) |
1393 | || !xim_styles || !xim_styles->count_styles) |
1295 | || !xim_styles || !xim_styles->count_styles) |
1394 | { |
1296 | { |
1395 | display->put_xim (input_method); |
1297 | im_destroy (); |
1396 | return false; |
1298 | return false; |
1397 | } |
1299 | } |
1398 | |
1300 | |
1399 | p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root"; |
1301 | const char *pet[] = { rs[Rs_preeditType], "OverTheSpot,OffTheSpot,Root,None" }; |
|
|
1302 | |
|
|
1303 | for (int pi = 0; pi < 2; pi++) |
|
|
1304 | { |
|
|
1305 | p = pet[pi]; |
|
|
1306 | |
|
|
1307 | if (!p) |
|
|
1308 | continue; |
|
|
1309 | |
1400 | s = rxvt_splitcommastring (p); |
1310 | s = rxvt_splitcommastring (p); |
|
|
1311 | |
1401 | for (i = found = 0; !found && s[i]; i++) |
1312 | for (i = found = 0; !found && s[i]; i++) |
1402 | { |
1313 | { |
1403 | if (!STRCMP (s[i], "OverTheSpot")) |
1314 | if (!strcmp (s[i], "OverTheSpot")) |
1404 | input_style = (XIMPreeditPosition | XIMStatusNothing); |
1315 | input_style = (XIMPreeditPosition | XIMStatusNothing); |
1405 | else if (!STRCMP (s[i], "OffTheSpot")) |
1316 | else if (!strcmp (s[i], "OffTheSpot")) |
1406 | input_style = (XIMPreeditArea | XIMStatusArea); |
1317 | input_style = (XIMPreeditArea | XIMStatusArea); |
1407 | else if (!STRCMP (s[i], "Root")) |
1318 | else if (!strcmp (s[i], "Root")) |
1408 | input_style = (XIMPreeditNothing | XIMStatusNothing); |
1319 | input_style = (XIMPreeditNothing | XIMStatusNothing); |
|
|
1320 | else if (!strcmp (s[i], "None")) |
|
|
1321 | input_style = (XIMPreeditNone | XIMStatusNone); |
1409 | |
1322 | |
1410 | for (j = 0; j < xim_styles->count_styles; j++) |
1323 | for (j = 0; j < xim_styles->count_styles; j++) |
1411 | if (input_style == xim_styles->supported_styles[j]) |
1324 | if (input_style == xim_styles->supported_styles[j]) |
1412 | { |
1325 | { |
|
|
1326 | rxvt_freecommastring (s); |
|
|
1327 | |
1413 | found = 1; |
1328 | found = 1; |
1414 | break; |
1329 | goto foundpet; |
|
|
1330 | } |
|
|
1331 | |
1415 | } |
1332 | } |
1416 | } |
|
|
1417 | |
1333 | |
1418 | for (i = 0; s[i]; i++) |
1334 | rxvt_freecommastring (s); |
1419 | free (s[i]); |
1335 | } |
1420 | |
1336 | |
1421 | free (s); |
1337 | foundpet: |
|
|
1338 | |
1422 | XFree (xim_styles); |
1339 | XFree (xim_styles); |
1423 | |
1340 | |
1424 | if (!found) |
1341 | if (!found) |
1425 | { |
1342 | { |
1426 | display->put_xim (input_method); |
1343 | im_destroy (); |
1427 | return false; |
1344 | return false; |
1428 | } |
1345 | } |
1429 | |
1346 | |
1430 | preedit_attr = status_attr = NULL; |
1347 | XFontSet fs = 0; |
|
|
1348 | XVaNestedList preedit_attr = 0, status_attr = 0; |
|
|
1349 | |
|
|
1350 | if (input_style & (XIMPreeditPosition | XIMPreeditArea)) |
|
|
1351 | { |
|
|
1352 | // fake us a font-set, please |
|
|
1353 | char **missing_charset_list; |
|
|
1354 | int missing_charset_count; |
|
|
1355 | char *def_string; |
|
|
1356 | char pat[512]; |
|
|
1357 | |
|
|
1358 | sprintf (pat, |
|
|
1359 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
|
|
1360 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
|
|
1361 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
|
|
1362 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
|
|
1363 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
|
|
1364 | "*", |
|
|
1365 | TermWin.fheight, |
|
|
1366 | TermWin.fheight + 1, TermWin.fheight - 1, |
|
|
1367 | TermWin.fheight - 2, TermWin.fheight + 2); |
|
|
1368 | |
|
|
1369 | fs = XCreateFontSet (display->display, pat, |
|
|
1370 | &missing_charset_list, &missing_charset_count, &def_string); |
|
|
1371 | |
|
|
1372 | if (missing_charset_list) |
|
|
1373 | XFreeStringList (missing_charset_list); |
|
|
1374 | |
|
|
1375 | if (!fs) |
|
|
1376 | { |
|
|
1377 | input_style &= ~(XIMPreeditPosition | XIMPreeditArea); |
|
|
1378 | rxvt_warn ("unable to create fontset for input method, try \"-pt Root\". Continuing.\n"); |
|
|
1379 | } |
|
|
1380 | } |
1431 | |
1381 | |
1432 | if (input_style & XIMPreeditPosition) |
1382 | if (input_style & XIMPreeditPosition) |
1433 | { |
1383 | { |
1434 | im_set_size (&rect); |
1384 | im_set_size (rect); |
1435 | im_set_position (&spot); |
1385 | im_set_position (spot); |
1436 | im_set_color (&fg, &bg); |
1386 | im_set_color (fg, bg); |
1437 | |
1387 | |
1438 | preedit_attr = XVaCreateNestedList (0, XNArea, &rect, |
1388 | preedit_attr = XVaCreateNestedList (0, |
|
|
1389 | XNForeground, fg, |
|
|
1390 | XNBackground, bg, |
|
|
1391 | XNArea, &rect, |
1439 | XNSpotLocation, &spot, |
1392 | XNSpotLocation, &spot, |
1440 | XNForeground, fg, XNBackground, bg, |
|
|
1441 | //XNFontSet, TermWin.fontset, |
1393 | XNFontSet, fs, |
1442 | NULL); |
1394 | NULL); |
1443 | } |
1395 | } |
1444 | else if (input_style & XIMPreeditArea) |
1396 | else if (input_style & XIMPreeditArea) |
1445 | { |
1397 | { |
1446 | im_set_color (&fg, &bg); |
1398 | im_set_color (fg, bg); |
1447 | |
1399 | |
1448 | /* |
1400 | /* |
1449 | * The necessary width of preedit area is unknown |
1401 | * The necessary width of preedit area is unknown |
1450 | * until create input context. |
1402 | * until create input context. |
1451 | */ |
1403 | */ |
1452 | needed_rect.width = 0; |
1404 | needed_rect.width = 0; |
1453 | |
|
|
1454 | im_set_preedit_area (&rect, &status_rect, &needed_rect); |
1405 | im_set_preedit_area (rect, status_rect, needed_rect); |
1455 | |
1406 | |
1456 | preedit_attr = XVaCreateNestedList (0, XNArea, &rect, |
1407 | preedit_attr = XVaCreateNestedList (0, |
|
|
1408 | XNForeground, fg, |
1457 | XNForeground, fg, XNBackground, bg, |
1409 | XNBackground, bg, |
|
|
1410 | XNArea, &rect, |
|
|
1411 | XNFontSet, fs, |
|
|
1412 | NULL); |
|
|
1413 | status_attr = XVaCreateNestedList (0, |
|
|
1414 | XNForeground, fg, |
|
|
1415 | XNBackground, bg, |
|
|
1416 | XNArea, &status_rect, |
1458 | //XNFontSet, TermWin.fontset, |
1417 | XNFontSet, fs, |
1459 | NULL); |
1418 | NULL); |
1460 | status_attr = XVaCreateNestedList (0, XNArea, &status_rect, |
|
|
1461 | XNForeground, fg, XNBackground, bg, |
|
|
1462 | //XNFontSet, TermWin.fontset, |
|
|
1463 | NULL); |
|
|
1464 | } |
1419 | } |
1465 | |
1420 | |
1466 | Input_Context = XCreateIC (xim, XNInputStyle, input_style, |
1421 | Input_Context = XCreateIC (xim, |
|
|
1422 | XNInputStyle, input_style, |
1467 | XNClientWindow, TermWin.parent[0], |
1423 | XNClientWindow, TermWin.vt, |
1468 | XNFocusWindow, TermWin.parent[0], |
1424 | XNFocusWindow, TermWin.parent[0], |
1469 | preedit_attr ? XNPreeditAttributes : NULL, |
1425 | preedit_attr ? XNPreeditAttributes : NULL, |
1470 | preedit_attr, |
1426 | preedit_attr, |
1471 | status_attr ? XNStatusAttributes : NULL, |
1427 | status_attr ? XNStatusAttributes : NULL, |
1472 | status_attr, NULL); |
1428 | status_attr, NULL); |
|
|
1429 | |
1473 | if (preedit_attr) XFree (preedit_attr); |
1430 | if (preedit_attr) XFree (preedit_attr); |
1474 | if (status_attr) XFree (status_attr); |
1431 | if (status_attr) XFree (status_attr); |
|
|
1432 | if (fs) XFreeFontSet (display->display, fs); |
1475 | |
1433 | |
1476 | if (Input_Context == NULL) |
1434 | if (Input_Context == NULL) |
1477 | { |
1435 | { |
1478 | rxvt_warn ("failed to create input context, continuing without XIM.\n"); |
1436 | rxvt_warn ("failed to create input context, continuing without XIM.\n"); |
1479 | display->put_xim (input_method); |
1437 | im_destroy (); |
1480 | return false; |
1438 | return false; |
1481 | } |
1439 | } |
1482 | |
1440 | |
1483 | if (input_style & XIMPreeditArea) |
1441 | if (input_style & XIMPreeditArea) |
1484 | IMSetStatusPosition (); |
1442 | IMSetStatusPosition (); |
… | |
… | |
1510 | if (p && *p) |
1468 | if (p && *p) |
1511 | { |
1469 | { |
1512 | bool found = false; |
1470 | bool found = false; |
1513 | |
1471 | |
1514 | s = rxvt_splitcommastring (p); |
1472 | s = rxvt_splitcommastring (p); |
|
|
1473 | |
1515 | for (i = 0; s[i]; i++) |
1474 | for (i = 0; s[i]; i++) |
1516 | { |
1475 | { |
1517 | if (*s[i]) |
1476 | if (*s[i]) |
1518 | { |
1477 | { |
1519 | STRCPY (buf, "@im="); |
1478 | strcpy (buf, "@im="); |
1520 | STRNCAT (buf, s[i], IMBUFSIZ - 5); |
1479 | strncat (buf, s[i], IMBUFSIZ - 5); |
1521 | if (IM_get_IC (buf)) |
1480 | if (IM_get_IC (buf)) |
1522 | { |
1481 | { |
1523 | found = true; |
1482 | found = true; |
1524 | break; |
1483 | break; |
1525 | } |
1484 | } |
1526 | } |
1485 | } |
1527 | } |
1486 | } |
1528 | for (i = 0; s[i]; i++) |
1487 | |
1529 | free (s[i]); |
1488 | rxvt_freecommastring (s); |
1530 | free (s); |
|
|
1531 | |
1489 | |
1532 | if (found) |
1490 | if (found) |
1533 | goto done; |
1491 | goto done; |
1534 | } |
1492 | } |
1535 | |
1493 | |
… | |
… | |
1549 | } |
1507 | } |
1550 | |
1508 | |
1551 | void |
1509 | void |
1552 | rxvt_term::IMSetStatusPosition () |
1510 | rxvt_term::IMSetStatusPosition () |
1553 | { |
1511 | { |
1554 | XRectangle preedit_rect, status_rect, *needed_rect; |
1512 | XRectangle preedit_rect, status_rect, *needed_rect; |
1555 | XVaNestedList preedit_attr, status_attr; |
1513 | XVaNestedList preedit_attr, status_attr; |
1556 | |
1514 | |
1557 | if (Input_Context == NULL |
1515 | if (!Input_Context |
|
|
1516 | || !TermWin.focus |
1558 | || !TermWin.focus || ! (input_style & XIMPreeditArea) |
1517 | || !(input_style & XIMPreeditArea) |
1559 | || !IMisRunning ()) |
1518 | || !IMisRunning ()) |
1560 | return; |
1519 | return; |
1561 | |
1520 | |
1562 | /* Getting the necessary width of preedit area */ |
1521 | /* Getting the necessary width of preedit area */ |
1563 | status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL); |
1522 | status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL); |
1564 | XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL); |
1523 | XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL); |
1565 | XFree (status_attr); |
1524 | XFree (status_attr); |
1566 | |
1525 | |
1567 | im_set_preedit_area (&preedit_rect, &status_rect, needed_rect); |
1526 | im_set_preedit_area (preedit_rect, status_rect, *needed_rect); |
|
|
1527 | XFree (needed_rect); |
1568 | |
1528 | |
1569 | preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL); |
1529 | preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL); |
1570 | status_attr = XVaCreateNestedList (0, XNArea, &status_rect, NULL); |
1530 | status_attr = XVaCreateNestedList (0, XNArea, &status_rect, NULL); |
1571 | |
1531 | |
1572 | XSetICValues (Input_Context, |
1532 | XSetICValues (Input_Context, |
1573 | XNPreeditAttributes, preedit_attr, |
1533 | XNPreeditAttributes, preedit_attr, |
1574 | XNStatusAttributes, status_attr, NULL); |
1534 | XNStatusAttributes, status_attr, NULL); |
1575 | |
1535 | |
1576 | XFree (preedit_attr); |
1536 | XFree (preedit_attr); |
1577 | XFree (status_attr); |
1537 | XFree (status_attr); |
1578 | } |
1538 | } |
1579 | #endif /* USE_XIM */ |
1539 | #endif /* USE_XIM */ |