… | |
… | |
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 |
… | |
… | |
128 | void * |
128 | void * |
129 | rxvt_term::operator new (size_t s) |
129 | rxvt_term::operator new (size_t s) |
130 | { |
130 | { |
131 | void *p = malloc (s); |
131 | void *p = malloc (s); |
132 | |
132 | |
133 | MEMSET (p, 0, s); |
133 | memset (p, 0, s); |
134 | return p; |
134 | return p; |
135 | } |
135 | } |
136 | |
136 | |
137 | void |
137 | void |
138 | rxvt_term::operator delete (void *p, size_t s) |
138 | rxvt_term::operator delete (void *p, size_t s) |
… | |
… | |
140 | free (p); |
140 | free (p); |
141 | } |
141 | } |
142 | |
142 | |
143 | rxvt_term::rxvt_term () |
143 | rxvt_term::rxvt_term () |
144 | : |
144 | : |
|
|
145 | #if TRANSPARENT |
145 | rootwin_ev (this, &rxvt_term::rootwin_cb), |
146 | rootwin_ev (this, &rxvt_term::rootwin_cb), |
|
|
147 | #endif |
|
|
148 | #ifdef HAVE_SCROLLBARS |
|
|
149 | scrollbar_ev (this, &rxvt_term::x_cb), |
|
|
150 | #endif |
|
|
151 | #ifdef MENUBAR |
|
|
152 | menubar_ev (this, &rxvt_term::x_cb), |
|
|
153 | #endif |
|
|
154 | #ifdef CURSOR_BLINK |
|
|
155 | cursor_blink_ev (this, &rxvt_term::cursor_blink_cb), |
|
|
156 | #endif |
|
|
157 | #ifdef TEXT_BLINK |
|
|
158 | text_blink_ev (this, &rxvt_term::text_blink_cb), |
|
|
159 | #endif |
|
|
160 | #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING |
|
|
161 | cont_scroll_ev (this, &rxvt_term::cont_scroll_cb), |
|
|
162 | #endif |
|
|
163 | #ifdef SELECTION_SCROLLING |
|
|
164 | sel_scroll_ev (this, &rxvt_term::sel_scroll_cb), |
|
|
165 | #endif |
|
|
166 | #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) |
|
|
167 | slip_wheel_ev (this, &rxvt_term::slip_wheel_cb), |
|
|
168 | #endif |
|
|
169 | #ifdef POINTER_BLANK |
|
|
170 | pointer_ev (this, &rxvt_term::pointer_cb), |
|
|
171 | #endif |
|
|
172 | #ifdef USE_XIM |
|
|
173 | im_ev (this, &rxvt_term::im_cb), |
|
|
174 | #endif |
146 | termwin_ev (this, &rxvt_term::x_cb), |
175 | termwin_ev (this, &rxvt_term::x_cb), |
147 | vt_ev (this, &rxvt_term::x_cb), |
176 | vt_ev (this, &rxvt_term::x_cb), |
148 | #ifdef HAVE_SCROLLBARS |
|
|
149 | scrollbar_ev (this, &rxvt_term::x_cb), |
|
|
150 | #endif |
|
|
151 | #ifdef MENUBAR |
|
|
152 | menubar_ev (this, &rxvt_term::x_cb), |
|
|
153 | #endif |
|
|
154 | #ifdef CURSOR_BLINK |
|
|
155 | cursor_blink_ev (this, &rxvt_term::cursor_blink_cb), |
|
|
156 | #endif |
|
|
157 | #ifdef TEXT_BLINK |
|
|
158 | text_blink_ev (this, &rxvt_term::text_blink_cb), |
|
|
159 | #endif |
|
|
160 | #ifdef POINTER_BLANK |
|
|
161 | pointer_ev (this, &rxvt_term::pointer_cb), |
|
|
162 | #endif |
|
|
163 | #ifdef USE_XIM |
|
|
164 | im_ev (this, &rxvt_term::im_cb), |
|
|
165 | #endif |
|
|
166 | check_ev (this, &rxvt_term::check_cb), |
177 | check_ev (this, &rxvt_term::check_cb), |
|
|
178 | flush_ev (this, &rxvt_term::flush_cb), |
167 | destroy_ev (this, &rxvt_term::destroy_cb), |
179 | destroy_ev (this, &rxvt_term::destroy_cb), |
168 | pty_ev (this, &rxvt_term::pty_cb), |
180 | pty_ev (this, &rxvt_term::pty_cb), |
169 | incr_ev (this, &rxvt_term::incr_cb) |
181 | incr_ev (this, &rxvt_term::incr_cb) |
170 | { |
182 | { |
171 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
183 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
… | |
… | |
175 | |
187 | |
176 | rxvt_term::~rxvt_term () |
188 | rxvt_term::~rxvt_term () |
177 | { |
189 | { |
178 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
190 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
179 | |
191 | |
180 | if (cmd_fd >= 0) |
192 | if (cmd_pid) |
181 | close (cmd_fd); |
193 | kill (-cmd_pid, SIGHUP); |
182 | |
194 | |
183 | #ifndef NO_SETOWNER_TTYDEV |
195 | pty.put (); |
184 | privileged_ttydev (RESTORE); |
196 | |
185 | #endif |
|
|
186 | #ifdef UTMP_SUPPORT |
197 | #ifdef UTMP_SUPPORT |
187 | privileged_utmp (RESTORE); |
198 | privileged_utmp (RESTORE); |
188 | #endif |
199 | #endif |
189 | |
200 | |
190 | delete TermWin.fontset; |
201 | delete TermWin.fontset; |
191 | |
202 | |
192 | if (display) |
203 | if (display) |
193 | { |
204 | { |
194 | selection_clear (); |
205 | selection_clear (); |
195 | |
206 | |
|
|
207 | #ifdef USE_XIM |
|
|
208 | im_destroy (); |
|
|
209 | #endif |
196 | #ifdef MENUBAR |
210 | #ifdef MENUBAR |
197 | if (menubarGC) XFreeGC (display->display, menubarGC); |
211 | if (menubarGC) XFreeGC (display->display, menubarGC); |
198 | #endif |
212 | #endif |
199 | #ifdef XTERM_SCROLLBAR |
213 | #ifdef XTERM_SCROLLBAR |
200 | if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC); |
214 | if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC); |
201 | if (ShadowGC) XFreeGC (display->display, ShadowGC); |
215 | if (ShadowGC) XFreeGC (display->display, ShadowGC); |
202 | #endif |
216 | #endif |
… | |
… | |
233 | XDestroyWindow (display->display, TermWin.parent[0]); |
247 | XDestroyWindow (display->display, TermWin.parent[0]); |
234 | } |
248 | } |
235 | |
249 | |
236 | // TODO: free pixcolours, colours should become part of rxvt_display |
250 | // TODO: free pixcolours, colours should become part of rxvt_display |
237 | |
251 | |
238 | delete PixColors; |
252 | delete pix_colors_focused; |
|
|
253 | #ifdef OFF_FOCUS_FADING |
|
|
254 | delete pix_colors_unfocused; |
|
|
255 | #endif |
239 | |
256 | |
240 | displays.put (display); |
257 | displays.put (display); |
241 | |
258 | |
242 | scr_release (); |
259 | scr_release (); |
243 | |
260 | |
… | |
… | |
261 | } |
278 | } |
262 | |
279 | |
263 | void |
280 | void |
264 | rxvt_term::destroy () |
281 | rxvt_term::destroy () |
265 | { |
282 | { |
|
|
283 | if (destroy_ev.active) |
|
|
284 | return; |
|
|
285 | |
|
|
286 | #if ENABLE_OVERLAY |
|
|
287 | scr_overlay_off (); |
|
|
288 | #endif |
|
|
289 | |
266 | if (display) |
290 | if (display) |
267 | { |
291 | { |
|
|
292 | #if USE_XIM |
|
|
293 | im_ev.stop (display); |
|
|
294 | #endif |
|
|
295 | #if HAVE_SCROLLBARS |
|
|
296 | scrollbar_ev.stop (display); |
|
|
297 | #endif |
|
|
298 | #if MENUBAR |
|
|
299 | menubar_ev.stop (display); |
|
|
300 | #endif |
|
|
301 | #if TRANSPARENT |
268 | rootwin_ev.stop (display); |
302 | rootwin_ev.stop (display); |
|
|
303 | #endif |
|
|
304 | incr_ev.stop (); |
269 | termwin_ev.stop (display); |
305 | termwin_ev.stop (display); |
270 | vt_ev.stop (display); |
306 | vt_ev.stop (display); |
271 | #ifdef USE_XIM |
|
|
272 | im_destroy (); |
|
|
273 | im_ev.stop (display); |
|
|
274 | #endif |
|
|
275 | #ifdef HAVE_SCROLLBARS |
|
|
276 | scrollbar_ev.stop (display); |
|
|
277 | #endif |
|
|
278 | #ifdef MENUBAR |
|
|
279 | menubar_ev.stop (display); |
|
|
280 | #endif |
|
|
281 | } |
307 | } |
282 | |
308 | |
283 | check_ev.stop (); |
309 | check_ev.stop (); |
284 | pty_ev.stop (); |
310 | pty_ev.stop (); |
285 | #ifdef CURSOR_BLINK |
311 | #ifdef CURSOR_BLINK |
286 | cursor_blink_ev.stop (); |
312 | cursor_blink_ev.stop (); |
287 | #endif |
313 | #endif |
288 | #ifdef TEXT_BLINK |
314 | #ifdef TEXT_BLINK |
289 | text_blink_ev.stop (); |
315 | text_blink_ev.stop (); |
290 | #endif |
316 | #endif |
|
|
317 | #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING |
|
|
318 | cont_scroll_ev.stop (); |
|
|
319 | #endif |
|
|
320 | #ifdef SELECTION_SCROLLING |
|
|
321 | sel_scroll_ev.stop (); |
|
|
322 | #endif |
291 | #ifdef POINTER_BLANK |
323 | #ifdef POINTER_BLANK |
292 | pointer_ev.stop (); |
324 | pointer_ev.stop (); |
293 | #endif |
325 | #endif |
294 | |
326 | |
295 | destroy_ev.start (0); |
327 | destroy_ev.start (0); |
… | |
… | |
311 | SET_R (this); |
343 | SET_R (this); |
312 | |
344 | |
313 | if (!init_vars ()) |
345 | if (!init_vars ()) |
314 | return false; |
346 | return false; |
315 | |
347 | |
|
|
348 | init_secondary (); |
|
|
349 | |
|
|
350 | const char **cmd_argv = init_resources (argc, argv); |
|
|
351 | |
|
|
352 | set_locale (""); |
|
|
353 | |
|
|
354 | #if MENUBAR_MAX |
|
|
355 | menubar_read (rs[Rs_menu]); |
|
|
356 | #endif |
|
|
357 | #ifdef HAVE_SCROLLBARS |
|
|
358 | if (options & Opt_scrollBar) |
|
|
359 | scrollBar.setIdle (); /* set existence for size calculations */ |
|
|
360 | #endif |
|
|
361 | |
|
|
362 | create_windows (argc, argv); |
|
|
363 | |
|
|
364 | init_xlocale (); |
|
|
365 | |
|
|
366 | scr_reset (); /* initialize screen */ |
|
|
367 | |
|
|
368 | #if 0 |
|
|
369 | XSynchronize (display->display, True); |
|
|
370 | #endif |
|
|
371 | |
|
|
372 | #ifdef HAVE_SCROLLBARS |
|
|
373 | if (options & Opt_scrollBar) |
|
|
374 | resize_scrollbar (); /* create and map scrollbar */ |
|
|
375 | #endif |
|
|
376 | #if (MENUBAR_MAX) |
|
|
377 | if (menubar_visible ()) |
|
|
378 | XMapWindow (display->display, menuBar.win); |
|
|
379 | #endif |
|
|
380 | #ifdef TRANSPARENT |
|
|
381 | if (options & Opt_transparent) |
|
|
382 | { |
|
|
383 | XSelectInput (display->display, display->root, PropertyChangeMask); |
|
|
384 | check_our_parents (); |
|
|
385 | rootwin_ev.start (display, display->root); |
|
|
386 | } |
|
|
387 | #endif |
|
|
388 | |
|
|
389 | XMapWindow (display->display, TermWin.vt); |
|
|
390 | XMapWindow (display->display, TermWin.parent[0]); |
|
|
391 | |
|
|
392 | init_command (cmd_argv); |
|
|
393 | |
|
|
394 | pty_ev.start (pty.pty, EVENT_READ); |
|
|
395 | |
|
|
396 | check_ev.start (); |
|
|
397 | |
|
|
398 | return true; |
|
|
399 | } |
|
|
400 | |
|
|
401 | static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event); |
|
|
402 | |
|
|
403 | void |
|
|
404 | rxvt_init () |
|
|
405 | { |
|
|
406 | /* install exit handler for cleanup */ |
|
|
407 | #if 0 |
|
|
408 | #ifdef HAVE_ATEXIT |
|
|
409 | atexit (rxvt_clean_exit); |
|
|
410 | #else |
|
|
411 | #endif |
|
|
412 | #endif |
316 | /* |
413 | /* |
317 | * Save and then give up any super-user privileges |
414 | * Save and then give up any super-user privileges |
318 | * If we need privileges in any area then we must specifically request it. |
415 | * If we need privileges in any area then we must specifically request it. |
319 | * We should only need to be root in these cases: |
416 | * We should only need to be root in these cases: |
320 | * 1. write utmp entries on some systems |
417 | * 1. write utmp entries on some systems |
321 | * 2. chown tty on some systems |
418 | * 2. chown tty on some systems |
322 | */ |
419 | */ |
323 | privileges (SAVE); |
420 | rxvt_privileges (SAVE); |
324 | privileges (IGNORE); |
421 | rxvt_privileges (IGNORE); |
325 | |
|
|
326 | init_secondary (); |
|
|
327 | |
|
|
328 | const char **cmd_argv = init_resources (argc, argv); |
|
|
329 | |
|
|
330 | set_locale (""); |
|
|
331 | |
|
|
332 | #if MENUBAR_MAX |
|
|
333 | menubar_read (rs[Rs_menu]); |
|
|
334 | #endif |
|
|
335 | #ifdef HAVE_SCROLLBARS |
|
|
336 | if (Options & Opt_scrollBar) |
|
|
337 | scrollBar.setIdle (); /* set existence for size calculations */ |
|
|
338 | #endif |
|
|
339 | |
|
|
340 | create_windows (argc, argv); |
|
|
341 | |
|
|
342 | init_xlocale (); |
|
|
343 | |
|
|
344 | scr_reset (); /* initialize screen */ |
|
|
345 | |
|
|
346 | #if 0 |
|
|
347 | XSynchronize (display->display, True); |
|
|
348 | #endif |
|
|
349 | |
|
|
350 | #ifdef HAVE_SCROLLBARS |
|
|
351 | if (Options & Opt_scrollBar) |
|
|
352 | resize_scrollbar (); /* create and map scrollbar */ |
|
|
353 | #endif |
|
|
354 | #if (MENUBAR_MAX) |
|
|
355 | if (menubar_visible ()) |
|
|
356 | XMapWindow (display->display, menuBar.win); |
|
|
357 | #endif |
|
|
358 | #ifdef TRANSPARENT |
|
|
359 | if (Options & Opt_transparent) |
|
|
360 | { |
|
|
361 | XSelectInput (display->display, display->root, PropertyChangeMask); |
|
|
362 | check_our_parents (); |
|
|
363 | } |
|
|
364 | #endif |
|
|
365 | |
|
|
366 | rootwin_ev.start (display, display->root); |
|
|
367 | |
|
|
368 | XMapWindow (display->display, TermWin.vt); |
|
|
369 | XMapWindow (display->display, TermWin.parent[0]); |
|
|
370 | |
|
|
371 | init_command (cmd_argv); |
|
|
372 | |
|
|
373 | pty_ev.start (cmd_fd, EVENT_READ); |
|
|
374 | |
|
|
375 | check_ev.start (); |
|
|
376 | |
|
|
377 | return true; |
|
|
378 | } |
|
|
379 | |
|
|
380 | static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event); |
|
|
381 | |
|
|
382 | void |
|
|
383 | rxvt_init_signals () |
|
|
384 | { |
|
|
385 | /* install exit handler for cleanup */ |
|
|
386 | #if 0 |
|
|
387 | #ifdef HAVE_ATEXIT |
|
|
388 | atexit (rxvt_clean_exit); |
|
|
389 | #else |
|
|
390 | #endif |
|
|
391 | #endif |
|
|
392 | |
422 | |
393 | struct sigaction sa; |
423 | struct sigaction sa; |
394 | |
424 | |
395 | sigfillset (&sa.sa_mask); |
425 | sigfillset (&sa.sa_mask); |
396 | sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; |
426 | sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; |
… | |
… | |
424 | break; |
454 | break; |
425 | } |
455 | } |
426 | } |
456 | } |
427 | |
457 | |
428 | /* ARGSUSED */ |
458 | /* ARGSUSED */ |
429 | /* EXTPROTO */ |
459 | /* INTPROTO */ |
430 | RETSIGTYPE |
460 | RETSIGTYPE |
431 | rxvt_Child_signal (int sig __attribute__ ((unused))) |
461 | rxvt_Child_signal (int sig __attribute__ ((unused))) |
432 | { |
462 | { |
433 | int pid, save_errno = errno; |
463 | int pid, save_errno = errno; |
434 | |
464 | |
… | |
… | |
439 | } |
469 | } |
440 | |
470 | |
441 | /* |
471 | /* |
442 | * Catch a fatal signal and tidy up before quitting |
472 | * Catch a fatal signal and tidy up before quitting |
443 | */ |
473 | */ |
444 | /* EXTPROTO */ |
474 | /* INTPROTO */ |
445 | RETSIGTYPE |
475 | RETSIGTYPE |
446 | rxvt_Exit_signal (int sig) |
476 | rxvt_Exit_signal (int sig) |
447 | { |
477 | { |
448 | signal (sig, SIG_DFL); |
478 | signal (sig, SIG_DFL); |
449 | #ifdef DEBUG_CMD |
479 | #ifdef DEBUG_CMD |
… | |
… | |
471 | /*----------------------------------------------------------------------*/ |
501 | /*----------------------------------------------------------------------*/ |
472 | /* |
502 | /* |
473 | * Exit gracefully, clearing the utmp entry and restoring tty attributes |
503 | * Exit gracefully, clearing the utmp entry and restoring tty attributes |
474 | * TODO: if debugging, this should free up any known resources if we can |
504 | * TODO: if debugging, this should free up any known resources if we can |
475 | */ |
505 | */ |
476 | /* EXTPROTO */ |
506 | /* INTPROTO */ |
477 | void |
507 | void |
478 | rxvt_clean_exit () |
508 | rxvt_clean_exit () |
479 | { |
509 | { |
480 | // TODO: rxvtd should clean up all ressources |
510 | // TODO: rxvtd should clean up all ressources |
481 | if (GET_R) |
511 | if (GET_R) |
… | |
… | |
483 | } |
513 | } |
484 | |
514 | |
485 | /* ------------------------------------------------------------------------- * |
515 | /* ------------------------------------------------------------------------- * |
486 | * MEMORY ALLOCATION WRAPPERS * |
516 | * MEMORY ALLOCATION WRAPPERS * |
487 | * ------------------------------------------------------------------------- */ |
517 | * ------------------------------------------------------------------------- */ |
488 | /* EXTPROTO */ |
518 | /* INTPROTO */ |
489 | void * |
519 | void * |
490 | rxvt_malloc (size_t size) |
520 | rxvt_malloc (size_t size) |
491 | { |
521 | { |
492 | void *p; |
522 | void *p; |
493 | |
523 | |
494 | p = malloc (size); |
524 | p = malloc (size); |
495 | if (p) |
525 | if (p) |
496 | return p; |
526 | return p; |
497 | |
527 | |
498 | fprintf (stderr, RESNAME ": memory allocation failure. Aborting"); |
528 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
499 | rxvt_clean_exit (); |
|
|
500 | exit (EXIT_FAILURE); |
|
|
501 | /* NOTREACHED */ |
529 | /* NOTREACHED */ |
502 | } |
530 | } |
503 | |
531 | |
504 | /* EXTPROTO */ |
532 | /* INTPROTO */ |
505 | void * |
533 | void * |
506 | rxvt_calloc (size_t number, size_t size) |
534 | rxvt_calloc (size_t number, size_t size) |
507 | { |
535 | { |
508 | void *p; |
536 | void *p; |
509 | |
537 | |
510 | p = calloc (number, size); |
538 | p = calloc (number, size); |
511 | if (p) |
539 | if (p) |
512 | return p; |
540 | return p; |
513 | |
541 | |
514 | fprintf (stderr, RESNAME ": memory allocation failure. Aborting"); |
542 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
515 | rxvt_clean_exit (); |
|
|
516 | exit (EXIT_FAILURE); |
|
|
517 | /* NOTREACHED */ |
543 | /* NOTREACHED */ |
518 | } |
544 | } |
519 | |
545 | |
520 | /* EXTPROTO */ |
546 | /* INTPROTO */ |
521 | void * |
547 | void * |
522 | rxvt_realloc (void *ptr, size_t size) |
548 | rxvt_realloc (void *ptr, size_t size) |
523 | { |
549 | { |
524 | void *p; |
550 | void *p; |
525 | |
551 | |
526 | if (ptr) |
552 | if (ptr) |
527 | p = realloc (ptr, size); |
553 | p = realloc (ptr, size); |
528 | else |
554 | else |
529 | p = malloc (size); |
555 | p = malloc (size); |
|
|
556 | |
530 | if (p) |
557 | if (p) |
531 | return p; |
558 | return p; |
532 | |
559 | |
533 | fprintf (stderr, RESNAME ": memory allocation failure. Aborting"); |
560 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
534 | rxvt_clean_exit (); |
|
|
535 | exit (EXIT_FAILURE); |
|
|
536 | /* NOTREACHED */ |
561 | /* NOTREACHED */ |
537 | } |
562 | } |
538 | |
563 | |
539 | /* ------------------------------------------------------------------------- * |
564 | /* ------------------------------------------------------------------------- * |
540 | * PRIVILEGED OPERATIONS * |
565 | * PRIVILEGED OPERATIONS * |
541 | * ------------------------------------------------------------------------- */ |
566 | * ------------------------------------------------------------------------- */ |
542 | /* take care of suid/sgid super-user (root) privileges */ |
567 | /* take care of suid/sgid super-user (root) privileges */ |
543 | void |
568 | void |
544 | rxvt_term::privileges (int mode) |
569 | rxvt_privileges (rxvt_privaction action) |
545 | { |
570 | { |
|
|
571 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
572 | static uid_t euid; |
|
|
573 | static gid_t egid; |
|
|
574 | #endif |
|
|
575 | |
546 | #if ! defined(__CYGWIN32__) |
576 | #if ! defined(__CYGWIN32__) |
547 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
577 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
548 | /* setreuid () is the poor man's setuid (), seteuid () */ |
578 | /* setreuid () is the poor man's setuid (), seteuid () */ |
549 | # define seteuid(a) setreuid(-1, (a)) |
579 | # define seteuid(a) setreuid(-1, (a)) |
550 | # define setegid(a) setregid(-1, (a)) |
580 | # define setegid(a) setregid(-1, (a)) |
551 | # define HAVE_SETEUID |
581 | # define HAVE_SETEUID |
552 | # endif |
582 | # endif |
553 | # ifdef HAVE_SETEUID |
583 | # ifdef HAVE_SETEUID |
554 | switch (mode) |
584 | switch (action) |
555 | { |
585 | { |
556 | case IGNORE: |
586 | case IGNORE: |
557 | /* |
587 | /* |
558 | * change effective uid/gid - not real uid/gid - so we can switch |
588 | * change effective uid/gid - not real uid/gid - so we can switch |
559 | * back to root later, as required |
589 | * back to root later, as required |
… | |
… | |
569 | seteuid (euid); |
599 | seteuid (euid); |
570 | setegid (egid); |
600 | setegid (egid); |
571 | break; |
601 | break; |
572 | } |
602 | } |
573 | # else |
603 | # else |
574 | switch (mode) |
604 | switch (action) |
575 | { |
605 | { |
576 | case IGNORE: |
606 | case IGNORE: |
577 | setuid (getuid ()); |
607 | setuid (getuid ()); |
578 | setgid (getgid ()); |
608 | setgid (getgid ()); |
579 | /* FALLTHROUGH */ |
609 | /* FALLTHROUGH */ |
… | |
… | |
586 | #endif |
616 | #endif |
587 | } |
617 | } |
588 | |
618 | |
589 | #ifdef UTMP_SUPPORT |
619 | #ifdef UTMP_SUPPORT |
590 | void |
620 | void |
591 | rxvt_term::privileged_utmp (char action) |
621 | rxvt_term::privileged_utmp (rxvt_privaction action) |
592 | { |
622 | { |
593 | D_MAIN ((stderr, "rxvt_privileged_utmp (%c); waiting for: %c (pid: %d)", |
|
|
594 | action, next_utmp_action, getpid ())); |
|
|
595 | if (next_utmp_action != action || (action != SAVE && action != RESTORE) |
|
|
596 | || (Options & Opt_utmpInhibit) |
623 | if ((options & Opt_utmpInhibit) |
597 | || ttydev == NULL || *ttydev == '\0') |
624 | || !pty.name || !*pty.name) |
598 | return; |
625 | return; |
599 | |
626 | |
600 | privileges (RESTORE); |
627 | rxvt_privileges (RESTORE); |
|
|
628 | |
601 | if (action == SAVE) |
629 | if (action == SAVE) |
602 | { |
|
|
603 | next_utmp_action = RESTORE; |
|
|
604 | makeutent (ttydev, rs[Rs_display_name]); |
630 | makeutent (pty.name, rs[Rs_display_name]); |
605 | } |
|
|
606 | else |
631 | else |
607 | { /* action == RESTORE */ |
|
|
608 | next_utmp_action = IGNORE; |
|
|
609 | cleanutent (); |
632 | cleanutent (); |
610 | } |
633 | |
611 | privileges (IGNORE); |
634 | rxvt_privileges (IGNORE); |
612 | } |
|
|
613 | #endif |
|
|
614 | |
|
|
615 | #ifndef NO_SETOWNER_TTYDEV |
|
|
616 | void |
|
|
617 | rxvt_term::privileged_ttydev (char action) |
|
|
618 | { |
|
|
619 | D_MAIN ((stderr, |
|
|
620 | "privileged_ttydev (%c); waiting for: %c (pid: %d)", |
|
|
621 | action, next_tty_action, getpid ())); |
|
|
622 | if (next_tty_action != action || (action != SAVE && action != RESTORE) |
|
|
623 | || ttydev == NULL || *ttydev == '\0') |
|
|
624 | return; |
|
|
625 | |
|
|
626 | privileges (RESTORE); |
|
|
627 | |
|
|
628 | if (action == SAVE) |
|
|
629 | { |
|
|
630 | next_tty_action = RESTORE; |
|
|
631 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
|
|
632 | /* store original tty status for restoration rxvt_clean_exit () -- rgg 04/12/95 */ |
|
|
633 | if (lstat (ttydev, &ttyfd_stat) < 0) /* you lose out */ |
|
|
634 | next_tty_action = IGNORE; |
|
|
635 | else |
|
|
636 | # endif |
|
|
637 | |
|
|
638 | { |
|
|
639 | chown (ttydev, getuid (), ttygid); /* fail silently */ |
|
|
640 | chmod (ttydev, ttymode); |
|
|
641 | # ifdef HAVE_REVOKE |
|
|
642 | revoke (ttydev); |
|
|
643 | # endif |
|
|
644 | |
|
|
645 | } |
|
|
646 | } |
|
|
647 | else |
|
|
648 | { /* action == RESTORE */ |
|
|
649 | next_tty_action = IGNORE; |
|
|
650 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
|
|
651 | chmod (ttydev, ttyfd_stat.st_mode); |
|
|
652 | chown (ttydev, ttyfd_stat.st_uid, ttyfd_stat.st_gid); |
|
|
653 | # else |
|
|
654 | chmod (ttydev, |
|
|
655 | (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)); |
|
|
656 | chown (ttydev, 0, 0); |
|
|
657 | # endif |
|
|
658 | |
|
|
659 | } |
|
|
660 | |
|
|
661 | privileges (IGNORE); |
|
|
662 | |
|
|
663 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
|
|
664 | D_MAIN ((stderr, "%s \"%s\": mode %03o, uid %d, gid %d", |
|
|
665 | action == RESTORE ? "Restoring" : (action == |
|
|
666 | SAVE ? "Saving" : |
|
|
667 | "UNKNOWN ERROR for"), ttydev, |
|
|
668 | ttyfd_stat.st_mode, ttyfd_stat.st_uid, |
|
|
669 | ttyfd_stat.st_gid)); |
|
|
670 | # endif |
|
|
671 | } |
635 | } |
672 | #endif |
636 | #endif |
673 | |
637 | |
674 | /*----------------------------------------------------------------------*/ |
638 | /*----------------------------------------------------------------------*/ |
675 | /* |
639 | /* |
… | |
… | |
740 | max_height = MAX_ROWS * TermWin.fheight; |
704 | max_height = MAX_ROWS * TermWin.fheight; |
741 | |
705 | |
742 | szHint.base_width = szHint.base_height = 2 * TermWin.int_bwidth; |
706 | szHint.base_width = szHint.base_height = 2 * TermWin.int_bwidth; |
743 | |
707 | |
744 | sb_w = mb_h = 0; |
708 | sb_w = mb_h = 0; |
745 | window_vt_x = window_vt_y = 0; |
709 | window_vt_x = window_vt_y = TermWin.int_bwidth; |
746 | |
710 | |
747 | if (scrollbar_visible ()) |
711 | if (scrollbar_visible ()) |
748 | { |
712 | { |
749 | sb_w = scrollbar_TotalWidth (); |
713 | sb_w = scrollbar_TotalWidth (); |
750 | szHint.base_width += sb_w; |
714 | szHint.base_width += sb_w; |
751 | if (! (Options & Opt_scrollBar_right)) |
715 | if (!(options & Opt_scrollBar_right)) |
752 | window_vt_x = sb_w; |
716 | window_vt_x += sb_w; |
753 | } |
717 | } |
754 | |
718 | |
755 | if (menubar_visible ()) |
719 | if (menubar_visible ()) |
756 | { |
720 | { |
757 | mb_h = menuBar_TotalHeight (); |
721 | mb_h = menuBar_TotalHeight (); |
758 | szHint.base_height += mb_h; |
722 | szHint.base_height += mb_h; |
759 | window_vt_y = mb_h; |
723 | window_vt_y += mb_h; |
760 | } |
724 | } |
761 | |
725 | |
762 | szHint.width_inc = TermWin.fwidth; |
726 | szHint.width_inc = TermWin.fwidth; |
763 | szHint.height_inc = TermWin.fheight; |
727 | szHint.height_inc = TermWin.fheight; |
764 | szHint.min_width = szHint.base_width + szHint.width_inc; |
728 | szHint.min_width = szHint.base_width + szHint.width_inc; |
… | |
… | |
784 | { |
748 | { |
785 | MIN_IT (TermWin.height, max_height); |
749 | MIN_IT (TermWin.height, max_height); |
786 | szHint.height = szHint.base_height + TermWin.height; |
750 | szHint.height = szHint.base_height + TermWin.height; |
787 | } |
751 | } |
788 | |
752 | |
789 | if (scrollbar_visible () && (Options & Opt_scrollBar_right)) |
753 | if (scrollbar_visible () && (options & Opt_scrollBar_right)) |
790 | window_sb_x = szHint.width - sb_w; |
754 | window_sb_x = szHint.width - sb_w; |
791 | |
755 | |
792 | if (recalc_x) |
756 | if (recalc_x) |
793 | szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) |
757 | szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) |
794 | - szHint.width - 2 * TermWin.ext_bwidth); |
758 | - szHint.width - 2 * TermWin.ext_bwidth); |
… | |
… | |
810 | * Called after a window size change. |
774 | * Called after a window size change. |
811 | */ |
775 | */ |
812 | void |
776 | void |
813 | rxvt_term::tt_winch () |
777 | rxvt_term::tt_winch () |
814 | { |
778 | { |
|
|
779 | if (pty.pty < 0) |
|
|
780 | return; |
|
|
781 | |
815 | struct winsize ws; |
782 | struct winsize ws; |
816 | |
|
|
817 | if (cmd_fd < 0) |
|
|
818 | return; |
|
|
819 | |
783 | |
820 | ws.ws_col = TermWin.ncol; |
784 | ws.ws_col = TermWin.ncol; |
821 | ws.ws_row = TermWin.nrow; |
785 | ws.ws_row = TermWin.nrow; |
822 | ws.ws_xpixel = ws.ws_ypixel = 0; |
786 | ws.ws_xpixel = TermWin.width; |
823 | #ifndef DEBUG_SIZE |
787 | ws.ws_ypixel = TermWin.height; |
824 | (void)ioctl (cmd_fd, TIOCSWINSZ, &ws); |
788 | (void)ioctl (pty.pty, TIOCSWINSZ, &ws); |
825 | #else |
789 | |
826 | if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0) |
790 | #if 0 |
827 | D_SIZE ((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); |
791 | // TIOCSWINSZ⎈ is supposed to do this automatically and correctly |
828 | # ifdef SIGWINCH |
|
|
829 | else if (cmd_pid) /* force through to the command */ |
792 | if (cmd_pid) /* force through to the command */ |
830 | kill (cmd_pid, SIGWINCH); |
793 | kill (cmd_pid, SIGWINCH); |
831 | # endif |
|
|
832 | #endif |
794 | #endif |
833 | } |
795 | } |
834 | |
796 | |
835 | /*----------------------------------------------------------------------*/ |
797 | /*----------------------------------------------------------------------*/ |
836 | /* rxvt_change_font () - Switch to a new font */ |
798 | /* rxvt_change_font () - Switch to a new font */ |
… | |
… | |
868 | resize_all_windows (0, 0, 0); |
830 | resize_all_windows (0, 0, 0); |
869 | scr_remap_chars (); |
831 | scr_remap_chars (); |
870 | scr_touch (true); |
832 | scr_touch (true); |
871 | } |
833 | } |
872 | |
834 | |
|
|
835 | for (unicode_t ch = 0x20; ch <= 0x7f; ch++) |
|
|
836 | TermWin.ascii_map [ch - 0x20] = fs->find_font (ch); |
|
|
837 | |
873 | return true; |
838 | return true; |
874 | } |
839 | } |
875 | } |
840 | } |
876 | |
841 | |
877 | return false; |
842 | return false; |
… | |
… | |
893 | char *name; |
858 | char *name; |
894 | |
859 | |
895 | if (!XFetchName (display->display, TermWin.parent[0], &name)) |
860 | if (!XFetchName (display->display, TermWin.parent[0], &name)) |
896 | name = NULL; |
861 | name = NULL; |
897 | |
862 | |
898 | if (name == NULL || STRCMP (name, str)) |
863 | if (name == NULL || strcmp (name, str)) |
899 | #endif |
864 | #endif |
900 | XStoreName (display->display, TermWin.parent[0], str); |
865 | XStoreName (display->display, TermWin.parent[0], str); |
901 | |
866 | |
902 | #ifdef SMART_WINDOW_TITLE |
867 | #ifdef SMART_WINDOW_TITLE |
903 | if (name) |
868 | if (name) |
… | |
… | |
912 | char *name; |
877 | char *name; |
913 | |
878 | |
914 | if (!XGetIconName (display->display, TermWin.parent[0], &name)) |
879 | if (!XGetIconName (display->display, TermWin.parent[0], &name)) |
915 | name = NULL; |
880 | name = NULL; |
916 | |
881 | |
917 | if (name == NULL || STRCMP (name, str)) |
882 | if (name == NULL || strcmp (name, str)) |
918 | #endif |
883 | #endif |
919 | XSetIconName (display->display, TermWin.parent[0], str); |
884 | XSetIconName (display->display, TermWin.parent[0], str); |
920 | |
885 | |
921 | #ifdef SMART_WINDOW_TITLE |
886 | #ifdef SMART_WINDOW_TITLE |
922 | if (name) |
887 | if (name) |
… | |
… | |
940 | i = atoi (color); |
905 | i = atoi (color); |
941 | if (i >= 8 && i <= 15) |
906 | if (i >= 8 && i <= 15) |
942 | { /* bright colors */ |
907 | { /* bright colors */ |
943 | i -= 8; |
908 | i -= 8; |
944 | # ifndef NO_BRIGHTCOLOR |
909 | # ifndef NO_BRIGHTCOLOR |
945 | PixColors[idx] = PixColors[minBrightCOLOR + i]; |
910 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
946 | SET_PIXCOLOR (idx); |
911 | SET_PIXCOLOR (idx); |
947 | goto Done; |
912 | goto Done; |
948 | # endif |
913 | # endif |
949 | |
914 | |
950 | } |
915 | } |
951 | if (i >= 0 && i <= 7) |
916 | if (i >= 0 && i <= 7) |
952 | { /* normal colors */ |
917 | { /* normal colors */ |
953 | PixColors[idx] = PixColors[minCOLOR + i]; |
918 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
954 | SET_PIXCOLOR (idx); |
919 | SET_PIXCOLOR (idx); |
955 | goto Done; |
920 | goto Done; |
956 | } |
921 | } |
957 | } |
922 | } |
958 | |
923 | |
959 | if (!rXParseAllocColor (& xcol, color)) |
924 | if (!rXParseAllocColor (& xcol, color)) |
960 | return; |
925 | return; |
961 | |
926 | |
962 | /* XStoreColor (display->display, XCMAP, XColor*); */ |
927 | /* XStoreColor (display->display, display->cmap, XColor*); */ |
963 | |
928 | |
964 | /* |
929 | /* |
965 | * FIXME: should free colors here, but no idea how to do it so instead, |
930 | * FIXME: should free colors here, but no idea how to do it so instead, |
966 | * so just keep gobbling up the colormap |
931 | * so just keep gobbling up the colormap |
967 | */ |
932 | */ |
968 | # if 0 |
933 | # if 0 |
969 | for (i = Color_Black; i <= Color_White; i++) |
934 | for (i = Color_Black; i <= Color_White; i++) |
970 | if (PixColors[idx] == PixColors[i]) |
935 | if (pix_colors[idx] == pix_colors[i]) |
971 | break; |
936 | break; |
972 | if (i > Color_White) |
937 | if (i > Color_White) |
973 | { |
938 | { |
974 | /* fprintf (stderr, "XFreeColors: PixColors [%d] = %lu\n", idx, PixColors [idx]); */ |
939 | /* fprintf (stderr, "XFreeColors: pix_colors [%d] = %lu\n", idx, pix_colors [idx]); */ |
975 | XFreeColors (display->display, XCMAP, (PixColors + idx), 1, |
940 | XFreeColors (display->display, display->cmap, (pix_colors + idx), 1, |
976 | DisplayPlanes (display->display, display->screen)); |
941 | DisplayPlanes (display->display, display->screen)); |
977 | } |
942 | } |
978 | # endif |
943 | # endif |
979 | |
944 | |
980 | PixColors[idx] = xcol; |
945 | pix_colors_focused[idx] = xcol; |
981 | SET_PIXCOLOR (idx); |
946 | SET_PIXCOLOR (idx); |
982 | |
947 | |
983 | /* XSetWindowAttributes attr; */ |
948 | /* XSetWindowAttributes attr; */ |
984 | /* Cursor cursor; */ |
949 | /* Cursor cursor; */ |
985 | Done: |
950 | Done: |
|
|
951 | #ifdef OFF_FOCUS_FADING |
|
|
952 | pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade])); |
|
|
953 | #endif |
986 | if (idx == Color_bg && ! (Options & Opt_transparent)) |
954 | if (idx == Color_bg && ! (options & Opt_transparent)) |
987 | XSetWindowBackground (display->display, TermWin.vt, |
955 | XSetWindowBackground (display->display, TermWin.vt, pix_colors[Color_bg]); |
988 | PixColors[Color_bg]); |
|
|
989 | |
956 | |
990 | /* handle Color_BD, scrollbar background, etc. */ |
957 | /* handle Color_BD, scrollbar background, etc. */ |
991 | |
958 | |
992 | set_colorfgbg (); |
959 | set_colorfgbg (); |
993 | recolour_cursor (); |
960 | recolour_cursor (); |
… | |
… | |
1001 | void |
968 | void |
1002 | rxvt_term::recolour_cursor () |
969 | rxvt_term::recolour_cursor () |
1003 | { |
970 | { |
1004 | XColor xcol[2]; |
971 | XColor xcol[2]; |
1005 | |
972 | |
1006 | xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) ? PixColors[Color_pointer_fg] : PixColors[Color_fg]; |
973 | xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) ? pix_colors_focused[Color_pointer_fg] : pix_colors_focused[Color_fg]; |
1007 | xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) ? PixColors[Color_pointer_bg] : PixColors[Color_bg]; |
974 | xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) ? pix_colors_focused[Color_pointer_bg] : pix_colors_focused[Color_bg]; |
1008 | XQueryColors (display->display, XCMAP, xcol, 2); |
975 | XQueryColors (display->display, display->cmap, xcol, 2); |
1009 | XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1); |
976 | XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1); |
1010 | } |
977 | } |
1011 | |
978 | |
1012 | /*----------------------------------------------------------------------*/ |
979 | /*----------------------------------------------------------------------*/ |
1013 | /* |
980 | /* |
… | |
… | |
1020 | const char *xpmb = "\0"; |
987 | const char *xpmb = "\0"; |
1021 | char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1]; |
988 | char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1]; |
1022 | |
989 | |
1023 | env_colorfgbg = |
990 | env_colorfgbg = |
1024 | (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1); |
991 | (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1); |
1025 | STRCPY (fstr, "default"); |
992 | strcpy (fstr, "default"); |
1026 | STRCPY (bstr, "default"); |
993 | strcpy (bstr, "default"); |
1027 | for (i = Color_Black; i <= Color_White; i++) |
994 | for (i = Color_Black; i <= Color_White; i++) |
1028 | if (PixColors[Color_fg] == PixColors[i]) |
995 | if (pix_colors[Color_fg] == pix_colors[i]) |
1029 | { |
996 | { |
1030 | sprintf (fstr, "%d", (i - Color_Black)); |
997 | sprintf (fstr, "%d", (i - Color_Black)); |
1031 | break; |
998 | break; |
1032 | } |
999 | } |
1033 | for (i = Color_Black; i <= Color_White; i++) |
1000 | for (i = Color_Black; i <= Color_White; i++) |
1034 | if (PixColors[Color_bg] == PixColors[i]) |
1001 | if (pix_colors[Color_bg] == pix_colors[i]) |
1035 | { |
1002 | { |
1036 | sprintf (bstr, "%d", (i - Color_Black)); |
1003 | sprintf (bstr, "%d", (i - Color_Black)); |
1037 | #ifdef XPM_BACKGROUND |
1004 | #ifdef XPM_BACKGROUND |
1038 | xpmb = "default;"; |
1005 | xpmb = "default;"; |
1039 | #endif |
1006 | #endif |
… | |
… | |
1044 | |
1011 | |
1045 | #ifndef NO_BRIGHTCOLOR |
1012 | #ifndef NO_BRIGHTCOLOR |
1046 | colorfgbg = DEFAULT_RSTYLE; |
1013 | colorfgbg = DEFAULT_RSTYLE; |
1047 | for (i = minCOLOR; i <= maxCOLOR; i++) |
1014 | for (i = minCOLOR; i <= maxCOLOR; i++) |
1048 | { |
1015 | { |
1049 | if (PixColors[Color_fg] == PixColors[i]) |
1016 | if (pix_colors[Color_fg] == pix_colors[i]) |
1050 | colorfgbg = SET_FGCOLOR (colorfgbg, i); |
1017 | colorfgbg = SET_FGCOLOR (colorfgbg, i); |
1051 | if (PixColors[Color_bg] == PixColors[i]) |
1018 | if (pix_colors[Color_bg] == pix_colors[i]) |
1052 | colorfgbg = SET_BGCOLOR (colorfgbg, i); |
1019 | colorfgbg = SET_BGCOLOR (colorfgbg, i); |
1053 | } |
1020 | } |
1054 | #endif |
1021 | #endif |
1055 | } |
1022 | } |
1056 | |
1023 | |
… | |
… | |
1207 | if (width == 0) |
1174 | if (width == 0) |
1208 | width = wattr.width - szHint.base_width; |
1175 | width = wattr.width - szHint.base_width; |
1209 | if (height == 0) |
1176 | if (height == 0) |
1210 | height = wattr.height - szHint.base_height; |
1177 | height = wattr.height - szHint.base_height; |
1211 | } |
1178 | } |
|
|
1179 | |
1212 | if (width != TermWin.width || height != TermWin.height) |
1180 | if (width != TermWin.width || height != TermWin.height) |
1213 | { |
1181 | { |
1214 | width += szHint.base_width; |
1182 | width += szHint.base_width; |
1215 | height += szHint.base_height; |
1183 | height += szHint.base_height; |
1216 | resize_all_windows (width, height, 0); |
1184 | resize_all_windows (width, height, 0); |
… | |
… | |
1221 | * - X INPUT METHOD ROUTINES - * |
1189 | * - X INPUT METHOD ROUTINES - * |
1222 | * -------------------------------------------------------------------- */ |
1190 | * -------------------------------------------------------------------- */ |
1223 | #ifdef USE_XIM |
1191 | #ifdef USE_XIM |
1224 | |
1192 | |
1225 | void |
1193 | void |
|
|
1194 | rxvt_term::im_set_color (unsigned long &fg, unsigned long &bg) |
|
|
1195 | { |
|
|
1196 | fg = pix_colors[Color_fg]; |
|
|
1197 | bg = pix_colors[Color_bg]; |
|
|
1198 | } |
|
|
1199 | |
|
|
1200 | void |
1226 | rxvt_term::im_set_size (XRectangle *size) |
1201 | rxvt_term::im_set_size (XRectangle &size) |
1227 | { |
1202 | { |
|
|
1203 | // the int_bwidth terms make no sense to me |
1228 | size->x = TermWin.int_bwidth; |
1204 | size.x = TermWin.int_bwidth; |
1229 | size->y = TermWin.int_bwidth; |
1205 | size.y = TermWin.int_bwidth; |
1230 | size->width = Width2Pixel (TermWin.ncol); |
1206 | size.width = Width2Pixel (TermWin.ncol) + TermWin.int_bwidth; |
1231 | size->height = Height2Pixel (TermWin.nrow); |
1207 | size.height = Height2Pixel (TermWin.nrow) + TermWin.int_bwidth; |
1232 | } |
1208 | } |
1233 | |
1209 | |
1234 | void |
1210 | void |
1235 | rxvt_term::im_set_color (unsigned long *fg, unsigned long *bg) |
1211 | rxvt_term::im_set_preedit_area (XRectangle &preedit_rect, |
|
|
1212 | XRectangle &status_rect, |
|
|
1213 | const XRectangle &needed_rect) |
1236 | { |
1214 | { |
1237 | *fg = PixColors[Color_fg]; |
1215 | preedit_rect.x = needed_rect.width; |
1238 | *bg = PixColors[Color_bg]; |
1216 | preedit_rect.y = 0; |
|
|
1217 | preedit_rect.width = Width2Pixel (TermWin.ncol) - needed_rect.width + 1; |
|
|
1218 | preedit_rect.height = TermWin.fheight; |
|
|
1219 | |
|
|
1220 | status_rect.x = 0; |
|
|
1221 | status_rect.y = 0; |
|
|
1222 | status_rect.width = needed_rect.width ? needed_rect.width : Width2Pixel (TermWin.ncol) + 1; |
|
|
1223 | status_rect.height = TermWin.fheight; |
1239 | } |
1224 | } |
1240 | |
1225 | |
1241 | /* Checking whether input method is running. */ |
1226 | /* Checking whether input method is running. */ |
1242 | bool |
1227 | bool |
1243 | rxvt_term::IMisRunning () |
1228 | rxvt_term::IMisRunning () |
1244 | { |
1229 | { |
1245 | char *p; |
1230 | char *p; |
1246 | Atom atom; |
1231 | Atom atom; |
1247 | Window win; |
1232 | Window win; |
1248 | char server[IMBUFSIZ]; |
1233 | char server[IMBUFSIZ]; |
1249 | |
1234 | |
1250 | /* get current locale modifier */ |
1235 | /* get current locale modifier */ |
1251 | if ((p = XSetLocaleModifiers (NULL)) != NULL) |
1236 | if ((p = XSetLocaleModifiers (NULL)) != NULL) |
1252 | { |
1237 | { |
1253 | STRCPY (server, "@server="); |
1238 | strcpy (server, "@server="); |
1254 | STRNCAT (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */ |
1239 | strncat (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */ |
|
|
1240 | |
1255 | if ((p = STRCHR (server + 1, '@')) != NULL) /* first one only */ |
1241 | if ((p = strchr (server + 1, '@')) != NULL) /* first one only */ |
1256 | *p = '\0'; |
1242 | *p = '\0'; |
1257 | |
1243 | |
1258 | atom = XInternAtom (display->display, server, False); |
1244 | atom = XInternAtom (display->display, server, False); |
1259 | win = XGetSelectionOwner (display->display, atom); |
1245 | win = XGetSelectionOwner (display->display, atom); |
|
|
1246 | |
1260 | if (win != None) |
1247 | if (win != None) |
1261 | return True; |
1248 | return True; |
1262 | } |
1249 | } |
|
|
1250 | |
1263 | return False; |
1251 | return False; |
1264 | } |
1252 | } |
1265 | |
1253 | |
1266 | void |
1254 | void |
1267 | rxvt_term::IMSendSpot () |
1255 | rxvt_term::IMSendSpot () |
1268 | { |
1256 | { |
1269 | XPoint spot; |
1257 | XPoint spot; |
1270 | XVaNestedList preedit_attr; |
1258 | XVaNestedList preedit_attr; |
1271 | |
1259 | |
1272 | if (Input_Context == NULL |
1260 | if (!Input_Context |
|
|
1261 | || !TermWin.focus |
1273 | || !TermWin.focus || ! (input_style & XIMPreeditPosition) |
1262 | || !(input_style & XIMPreeditPosition) |
|
|
1263 | #if 0 |
1274 | || ! (event_type == KeyPress |
1264 | || !(event_type == KeyPress |
1275 | || event_type == Expose |
1265 | || event_type == Expose |
1276 | || event_type == NoExpose |
1266 | || event_type == NoExpose |
1277 | || event_type == SelectionNotify |
1267 | || event_type == SelectionNotify |
1278 | || event_type == ButtonRelease || event_type == FocusIn) |
1268 | || event_type == ButtonRelease || event_type == FocusIn) |
|
|
1269 | #endif |
1279 | || !IMisRunning ()) |
1270 | || !IMisRunning ()) |
1280 | return; |
1271 | return; |
1281 | |
1272 | |
1282 | im_set_position (&spot); |
1273 | im_set_position (spot); |
1283 | |
1274 | |
1284 | preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); |
1275 | preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); |
1285 | XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); |
1276 | XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); |
1286 | XFree (preedit_attr); |
1277 | XFree (preedit_attr); |
1287 | } |
1278 | } |
1288 | |
1279 | |
1289 | void |
1280 | void |
1290 | rxvt_term::im_set_preedit_area (XRectangle * preedit_rect, XRectangle * status_rect, |
|
|
1291 | XRectangle * needed_rect) |
|
|
1292 | { |
|
|
1293 | int mbh, vtx = 0; |
|
|
1294 | |
|
|
1295 | if (scrollbar_visible () && ! (Options & Opt_scrollBar_right)) |
|
|
1296 | vtx = scrollbar_TotalWidth (); |
|
|
1297 | |
|
|
1298 | mbh = menubar_visible () ? menuBar_TotalHeight () : 0; |
|
|
1299 | mbh -= TermWin.lineSpace; |
|
|
1300 | |
|
|
1301 | preedit_rect->x = needed_rect->width + vtx; |
|
|
1302 | preedit_rect->y = Height2Pixel (TermWin.nrow - 1) + mbh; |
|
|
1303 | |
|
|
1304 | preedit_rect->width = Width2Pixel (TermWin.ncol + 1) - needed_rect->width + vtx; |
|
|
1305 | preedit_rect->height = Height2Pixel (1); |
|
|
1306 | |
|
|
1307 | status_rect->x = vtx; |
|
|
1308 | status_rect->y = Height2Pixel (TermWin.nrow - 1) + mbh; |
|
|
1309 | |
|
|
1310 | status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel (TermWin.ncol + 1); |
|
|
1311 | status_rect->height = Height2Pixel (1); |
|
|
1312 | } |
|
|
1313 | |
|
|
1314 | void |
|
|
1315 | rxvt_term::im_destroy () |
1281 | rxvt_term::im_destroy () |
1316 | { |
1282 | { |
1317 | if (Input_Context) |
1283 | if (Input_Context) |
1318 | { |
1284 | { |
1319 | XDestroyIC (Input_Context); |
1285 | XDestroyIC (Input_Context); |
1320 | Input_Context = NULL; |
1286 | Input_Context = 0; |
1321 | } |
1287 | } |
1322 | |
1288 | |
1323 | if (input_method) |
1289 | if (input_method) |
1324 | { |
1290 | { |
1325 | display->put_xim (input_method); |
1291 | display->put_xim (input_method); |
… | |
… | |
1332 | * open a suitable preedit type |
1298 | * open a suitable preedit type |
1333 | */ |
1299 | */ |
1334 | bool |
1300 | bool |
1335 | rxvt_term::IM_get_IC (const char *modifiers) |
1301 | rxvt_term::IM_get_IC (const char *modifiers) |
1336 | { |
1302 | { |
1337 | int i, j, found; |
1303 | int i, j, found; |
1338 | XIM xim; |
1304 | XIM xim; |
1339 | XPoint spot; |
1305 | XPoint spot; |
1340 | XRectangle rect, status_rect, needed_rect; |
1306 | XRectangle rect, status_rect, needed_rect; |
1341 | unsigned long fg, bg; |
1307 | unsigned long fg, bg; |
1342 | const char *p; |
1308 | const char *p; |
1343 | char **s; |
1309 | char **s; |
1344 | XIMStyles *xim_styles; |
1310 | XIMStyles *xim_styles; |
1345 | XVaNestedList preedit_attr, status_attr; |
|
|
1346 | |
1311 | |
1347 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1312 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1348 | return false; |
1313 | return false; |
1349 | |
1314 | |
1350 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
1315 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
… | |
… | |
1356 | |
1321 | |
1357 | xim_styles = NULL; |
1322 | xim_styles = NULL; |
1358 | if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) |
1323 | if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) |
1359 | || !xim_styles || !xim_styles->count_styles) |
1324 | || !xim_styles || !xim_styles->count_styles) |
1360 | { |
1325 | { |
1361 | display->put_xim (input_method); |
1326 | im_destroy (); |
1362 | return false; |
1327 | return false; |
1363 | } |
1328 | } |
1364 | |
1329 | |
1365 | p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root"; |
1330 | p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root"; |
1366 | s = rxvt_splitcommastring (p); |
1331 | s = rxvt_splitcommastring (p); |
|
|
1332 | |
1367 | for (i = found = 0; !found && s[i]; i++) |
1333 | for (i = found = 0; !found && s[i]; i++) |
1368 | { |
1334 | { |
1369 | if (!STRCMP (s[i], "OverTheSpot")) |
1335 | if (!strcmp (s[i], "OverTheSpot")) |
1370 | input_style = (XIMPreeditPosition | XIMStatusNothing); |
1336 | input_style = (XIMPreeditPosition | XIMStatusNothing); |
1371 | else if (!STRCMP (s[i], "OffTheSpot")) |
1337 | else if (!strcmp (s[i], "OffTheSpot")) |
1372 | input_style = (XIMPreeditArea | XIMStatusArea); |
1338 | input_style = (XIMPreeditArea | XIMStatusArea); |
1373 | else if (!STRCMP (s[i], "Root")) |
1339 | else if (!strcmp (s[i], "Root")) |
1374 | input_style = (XIMPreeditNothing | XIMStatusNothing); |
1340 | input_style = (XIMPreeditNothing | XIMStatusNothing); |
1375 | |
1341 | |
1376 | for (j = 0; j < xim_styles->count_styles; j++) |
1342 | for (j = 0; j < xim_styles->count_styles; j++) |
1377 | if (input_style == xim_styles->supported_styles[j]) |
1343 | if (input_style == xim_styles->supported_styles[j]) |
1378 | { |
1344 | { |
… | |
… | |
1387 | free (s); |
1353 | free (s); |
1388 | XFree (xim_styles); |
1354 | XFree (xim_styles); |
1389 | |
1355 | |
1390 | if (!found) |
1356 | if (!found) |
1391 | { |
1357 | { |
1392 | display->put_xim (input_method); |
1358 | im_destroy (); |
1393 | return false; |
1359 | return false; |
1394 | } |
1360 | } |
1395 | |
1361 | |
1396 | preedit_attr = status_attr = NULL; |
1362 | XFontSet fs = 0; |
|
|
1363 | XVaNestedList preedit_attr = 0, status_attr = 0; |
|
|
1364 | |
|
|
1365 | if (input_style & (XIMPreeditPosition | XIMPreeditArea)) |
|
|
1366 | { |
|
|
1367 | // fake us a font-set, please |
|
|
1368 | char **missing_charset_list; |
|
|
1369 | int missing_charset_count; |
|
|
1370 | char *def_string; |
|
|
1371 | char pat[512]; |
|
|
1372 | |
|
|
1373 | sprintf (pat, |
|
|
1374 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
|
|
1375 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
|
|
1376 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
|
|
1377 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
|
|
1378 | "-*-*-*-R-*-*-%d-*-*-*-*-*-*," |
|
|
1379 | "*", |
|
|
1380 | TermWin.fheight, |
|
|
1381 | TermWin.fheight + 1, TermWin.fheight - 1, |
|
|
1382 | TermWin.fheight - 2, TermWin.fheight + 2); |
|
|
1383 | |
|
|
1384 | fs = XCreateFontSet (display->display, pat, |
|
|
1385 | &missing_charset_list, &missing_charset_count, &def_string); |
|
|
1386 | |
|
|
1387 | if (missing_charset_list) |
|
|
1388 | XFreeStringList (missing_charset_list); |
|
|
1389 | |
|
|
1390 | if (!fs) |
|
|
1391 | { |
|
|
1392 | input_style &= ~(XIMPreeditPosition | XIMPreeditArea); |
|
|
1393 | rxvt_warn ("unable to create fontset for input method, try \"-pt Root\". Continuing.\n"); |
|
|
1394 | } |
|
|
1395 | } |
1397 | |
1396 | |
1398 | if (input_style & XIMPreeditPosition) |
1397 | if (input_style & XIMPreeditPosition) |
1399 | { |
1398 | { |
1400 | im_set_size (&rect); |
1399 | im_set_size (rect); |
1401 | im_set_position (&spot); |
1400 | im_set_position (spot); |
1402 | im_set_color (&fg, &bg); |
1401 | im_set_color (fg, bg); |
1403 | |
1402 | |
1404 | preedit_attr = XVaCreateNestedList (0, XNArea, &rect, |
1403 | preedit_attr = XVaCreateNestedList (0, |
|
|
1404 | XNForeground, fg, |
|
|
1405 | XNBackground, bg, |
|
|
1406 | XNArea, &rect, |
1405 | XNSpotLocation, &spot, |
1407 | XNSpotLocation, &spot, |
1406 | XNForeground, fg, XNBackground, bg, |
|
|
1407 | //XNFontSet, TermWin.fontset, |
1408 | XNFontSet, fs, |
1408 | NULL); |
1409 | NULL); |
1409 | } |
1410 | } |
1410 | else if (input_style & XIMPreeditArea) |
1411 | else if (input_style & XIMPreeditArea) |
1411 | { |
1412 | { |
1412 | im_set_color (&fg, &bg); |
1413 | im_set_color (fg, bg); |
1413 | |
1414 | |
1414 | /* |
1415 | /* |
1415 | * The necessary width of preedit area is unknown |
1416 | * The necessary width of preedit area is unknown |
1416 | * until create input context. |
1417 | * until create input context. |
1417 | */ |
1418 | */ |
1418 | needed_rect.width = 0; |
1419 | needed_rect.width = 0; |
1419 | |
|
|
1420 | im_set_preedit_area (&rect, &status_rect, &needed_rect); |
1420 | im_set_preedit_area (rect, status_rect, needed_rect); |
1421 | |
1421 | |
1422 | preedit_attr = XVaCreateNestedList (0, XNArea, &rect, |
1422 | preedit_attr = XVaCreateNestedList (0, |
|
|
1423 | XNForeground, fg, |
1423 | XNForeground, fg, XNBackground, bg, |
1424 | XNBackground, bg, |
|
|
1425 | XNArea, &rect, |
|
|
1426 | XNFontSet, fs, |
|
|
1427 | NULL); |
|
|
1428 | status_attr = XVaCreateNestedList (0, |
|
|
1429 | XNForeground, fg, |
|
|
1430 | XNBackground, bg, |
|
|
1431 | XNArea, &status_rect, |
1424 | //XNFontSet, TermWin.fontset, |
1432 | XNFontSet, fs, |
1425 | NULL); |
1433 | NULL); |
1426 | status_attr = XVaCreateNestedList (0, XNArea, &status_rect, |
|
|
1427 | XNForeground, fg, XNBackground, bg, |
|
|
1428 | //XNFontSet, TermWin.fontset, |
|
|
1429 | NULL); |
|
|
1430 | } |
1434 | } |
1431 | |
1435 | |
1432 | Input_Context = XCreateIC (xim, XNInputStyle, input_style, |
1436 | Input_Context = XCreateIC (xim, |
|
|
1437 | XNInputStyle, input_style, |
1433 | XNClientWindow, TermWin.parent[0], |
1438 | XNClientWindow, TermWin.vt, |
1434 | XNFocusWindow, TermWin.parent[0], |
1439 | XNFocusWindow, TermWin.parent[0], |
1435 | preedit_attr ? XNPreeditAttributes : NULL, |
1440 | preedit_attr ? XNPreeditAttributes : NULL, |
1436 | preedit_attr, |
1441 | preedit_attr, |
1437 | status_attr ? XNStatusAttributes : NULL, |
1442 | status_attr ? XNStatusAttributes : NULL, |
1438 | status_attr, NULL); |
1443 | status_attr, NULL); |
|
|
1444 | |
1439 | if (preedit_attr) XFree (preedit_attr); |
1445 | if (preedit_attr) XFree (preedit_attr); |
1440 | if (status_attr) XFree (status_attr); |
1446 | if (status_attr) XFree (status_attr); |
|
|
1447 | if (fs) XFreeFontSet (display->display, fs); |
1441 | |
1448 | |
1442 | if (Input_Context == NULL) |
1449 | if (Input_Context == NULL) |
1443 | { |
1450 | { |
1444 | rxvt_warn ("failed to create input context, continuing without XIM.\n"); |
1451 | rxvt_warn ("failed to create input context, continuing without XIM.\n"); |
1445 | display->put_xim (input_method); |
1452 | im_destroy (); |
1446 | return false; |
1453 | return false; |
1447 | } |
1454 | } |
1448 | |
1455 | |
1449 | if (input_style & XIMPreeditArea) |
1456 | if (input_style & XIMPreeditArea) |
1450 | IMSetStatusPosition (); |
1457 | IMSetStatusPosition (); |
… | |
… | |
1480 | s = rxvt_splitcommastring (p); |
1487 | s = rxvt_splitcommastring (p); |
1481 | for (i = 0; s[i]; i++) |
1488 | for (i = 0; s[i]; i++) |
1482 | { |
1489 | { |
1483 | if (*s[i]) |
1490 | if (*s[i]) |
1484 | { |
1491 | { |
1485 | STRCPY (buf, "@im="); |
1492 | strcpy (buf, "@im="); |
1486 | STRNCAT (buf, s[i], IMBUFSIZ - 5); |
1493 | strncat (buf, s[i], IMBUFSIZ - 5); |
1487 | if (IM_get_IC (buf)) |
1494 | if (IM_get_IC (buf)) |
1488 | { |
1495 | { |
1489 | found = true; |
1496 | found = true; |
1490 | break; |
1497 | break; |
1491 | } |
1498 | } |
… | |
… | |
1515 | } |
1522 | } |
1516 | |
1523 | |
1517 | void |
1524 | void |
1518 | rxvt_term::IMSetStatusPosition () |
1525 | rxvt_term::IMSetStatusPosition () |
1519 | { |
1526 | { |
1520 | XRectangle preedit_rect, status_rect, *needed_rect; |
1527 | XRectangle preedit_rect, status_rect, *needed_rect; |
1521 | XVaNestedList preedit_attr, status_attr; |
1528 | XVaNestedList preedit_attr, status_attr; |
1522 | |
1529 | |
1523 | if (Input_Context == NULL |
1530 | if (!Input_Context |
|
|
1531 | || !TermWin.focus |
1524 | || !TermWin.focus || ! (input_style & XIMPreeditArea) |
1532 | || !(input_style & XIMPreeditArea) |
1525 | || !IMisRunning ()) |
1533 | || !IMisRunning ()) |
1526 | return; |
1534 | return; |
1527 | |
1535 | |
1528 | /* Getting the necessary width of preedit area */ |
1536 | /* Getting the necessary width of preedit area */ |
1529 | status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL); |
1537 | status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL); |
1530 | XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL); |
1538 | XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL); |
1531 | XFree (status_attr); |
1539 | XFree (status_attr); |
1532 | |
1540 | |
1533 | im_set_preedit_area (&preedit_rect, &status_rect, needed_rect); |
1541 | im_set_preedit_area (preedit_rect, status_rect, *needed_rect); |
|
|
1542 | XFree (needed_rect); |
1534 | |
1543 | |
1535 | preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL); |
1544 | preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL); |
1536 | status_attr = XVaCreateNestedList (0, XNArea, &status_rect, NULL); |
1545 | status_attr = XVaCreateNestedList (0, XNArea, &status_rect, NULL); |
1537 | |
1546 | |
1538 | XSetICValues (Input_Context, |
1547 | XSetICValues (Input_Context, |
1539 | XNPreeditAttributes, preedit_attr, |
1548 | XNPreeditAttributes, preedit_attr, |
1540 | XNStatusAttributes, status_attr, NULL); |
1549 | XNStatusAttributes, status_attr, NULL); |
1541 | |
1550 | |
1542 | XFree (preedit_attr); |
1551 | XFree (preedit_attr); |
1543 | XFree (status_attr); |
1552 | XFree (status_attr); |
1544 | } |
1553 | } |
1545 | #endif /* USE_XIM */ |
1554 | #endif /* USE_XIM */ |