1 | /*--------------------------------*-C-*---------------------------------*; |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: main.c |
2 | * File: main.C |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * |
4 | * |
5 | * All portions of code are copyright by their respective author/s. |
5 | * All portions of code are copyright by their respective author/s. |
6 | * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> |
6 | * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> |
7 | * - original version |
7 | * - original version |
… | |
… | |
44 | # include <termios.h> |
44 | # include <termios.h> |
45 | #endif |
45 | #endif |
46 | |
46 | |
47 | #include <cstring> |
47 | #include <cstring> |
48 | |
48 | |
|
|
49 | vector<rxvt_term *> rxvt_term::termlist; |
|
|
50 | |
49 | static char curlocale[128]; |
51 | static char curlocale[128]; |
50 | |
52 | |
51 | void |
53 | bool |
52 | rxvt_set_locale (const char *locale) |
54 | rxvt_set_locale (const char *locale) |
53 | { |
55 | { |
54 | if (locale && STRNCMP (locale, curlocale, 128)) |
56 | if (!locale || !strncmp (locale, curlocale, 128)) |
55 | { |
57 | return false; |
|
|
58 | |
56 | STRNCPY (curlocale, locale, 128); |
59 | strncpy (curlocale, locale, 128); |
57 | setlocale (LC_CTYPE, curlocale); |
60 | setlocale (LC_CTYPE, curlocale); |
58 | } |
61 | return true; |
59 | } |
62 | } |
60 | |
63 | |
61 | #if ENABLE_COMBINING |
64 | #if ENABLE_COMBINING |
62 | class rxvt_composite_vec rxvt_composite; |
65 | class rxvt_composite_vec rxvt_composite; |
63 | |
66 | |
… | |
… | |
125 | void * |
128 | void * |
126 | rxvt_term::operator new (size_t s) |
129 | rxvt_term::operator new (size_t s) |
127 | { |
130 | { |
128 | void *p = malloc (s); |
131 | void *p = malloc (s); |
129 | |
132 | |
130 | MEMSET (p, 0, s); |
133 | memset (p, 0, s); |
131 | return p; |
134 | return p; |
132 | } |
135 | } |
133 | |
136 | |
134 | void |
137 | void |
135 | rxvt_term::operator delete (void *p, size_t s) |
138 | rxvt_term::operator delete (void *p, size_t s) |
… | |
… | |
137 | free (p); |
140 | free (p); |
138 | } |
141 | } |
139 | |
142 | |
140 | rxvt_term::rxvt_term () |
143 | rxvt_term::rxvt_term () |
141 | : |
144 | : |
|
|
145 | #if TRANSPARENT |
142 | 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 |
143 | termwin_ev (this, &rxvt_term::x_cb), |
175 | termwin_ev (this, &rxvt_term::x_cb), |
144 | vt_ev (this, &rxvt_term::x_cb), |
176 | vt_ev (this, &rxvt_term::x_cb), |
145 | #ifdef HAVE_SCROLLBARS |
|
|
146 | scrollbar_ev (this, &rxvt_term::x_cb), |
|
|
147 | #endif |
|
|
148 | #ifdef MENUBAR |
|
|
149 | menubar_ev (this, &rxvt_term::x_cb), |
|
|
150 | #endif |
|
|
151 | #ifdef CURSOR_BLINK |
|
|
152 | cursor_blink_ev (this, &rxvt_term::cursor_blink_cb), |
|
|
153 | #endif |
|
|
154 | #ifdef TEXT_BLINK |
|
|
155 | text_blink_ev (this, &rxvt_term::text_blink_cb), |
|
|
156 | #endif |
|
|
157 | #ifdef POINTER_BLANK |
|
|
158 | pointer_ev (this, &rxvt_term::pointer_cb), |
|
|
159 | #endif |
|
|
160 | #ifdef USE_XIM |
|
|
161 | im_ev (this, &rxvt_term::im_cb), |
|
|
162 | #endif |
|
|
163 | check_ev (this, &rxvt_term::check_cb), |
177 | check_ev (this, &rxvt_term::check_cb), |
|
|
178 | flush_ev (this, &rxvt_term::flush_cb), |
164 | destroy_ev (this, &rxvt_term::destroy_cb), |
179 | destroy_ev (this, &rxvt_term::destroy_cb), |
165 | pty_ev (this, &rxvt_term::pty_cb), |
180 | pty_ev (this, &rxvt_term::pty_cb), |
166 | incr_ev (this, &rxvt_term::incr_cb) |
181 | incr_ev (this, &rxvt_term::incr_cb) |
167 | { |
182 | { |
168 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
183 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
|
|
184 | |
|
|
185 | termlist.push_back (this); |
169 | } |
186 | } |
170 | |
187 | |
171 | rxvt_term::~rxvt_term () |
188 | rxvt_term::~rxvt_term () |
172 | { |
189 | { |
|
|
190 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
|
|
191 | |
173 | if (cmd_fd >= 0) |
192 | if (cmd_pid) |
174 | close (cmd_fd); |
193 | kill (-cmd_pid, SIGHUP); |
175 | |
194 | |
176 | #ifndef NO_SETOWNER_TTYDEV |
195 | pty.put (); |
177 | privileged_ttydev (RESTORE); |
196 | |
178 | #endif |
|
|
179 | #ifdef UTMP_SUPPORT |
197 | #ifdef UTMP_SUPPORT |
180 | privileged_utmp (RESTORE); |
198 | privileged_utmp (RESTORE); |
181 | #endif |
199 | #endif |
182 | |
200 | |
183 | delete TermWin.fontset; |
201 | delete TermWin.fontset; |
184 | |
202 | |
185 | if (display) |
203 | if (display) |
186 | { |
204 | { |
187 | selection_clear (); |
205 | selection_clear (); |
188 | |
206 | |
|
|
207 | #ifdef USE_XIM |
|
|
208 | im_destroy (); |
|
|
209 | #endif |
189 | #ifdef MENUBAR |
210 | #ifdef MENUBAR |
190 | if (menubarGC) XFreeGC (display->display, menubarGC); |
211 | if (menubarGC) XFreeGC (display->display, menubarGC); |
191 | #endif |
212 | #endif |
192 | #ifdef XTERM_SCROLLBAR |
213 | #ifdef XTERM_SCROLLBAR |
193 | if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC); |
214 | if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC); |
194 | if (ShadowGC) XFreeGC (display->display, ShadowGC); |
215 | if (ShadowGC) XFreeGC (display->display, ShadowGC); |
195 | #endif |
216 | #endif |
… | |
… | |
226 | XDestroyWindow (display->display, TermWin.parent[0]); |
247 | XDestroyWindow (display->display, TermWin.parent[0]); |
227 | } |
248 | } |
228 | |
249 | |
229 | // TODO: free pixcolours, colours should become part of rxvt_display |
250 | // TODO: free pixcolours, colours should become part of rxvt_display |
230 | |
251 | |
231 | delete PixColors; |
252 | delete pix_colors_focused; |
|
|
253 | #ifdef OFF_FOCUS_FADING |
|
|
254 | delete pix_colors_unfocused; |
|
|
255 | #endif |
232 | |
256 | |
233 | displays.put (display); |
257 | displays.put (display); |
234 | |
258 | |
235 | scr_release (); |
259 | scr_release (); |
236 | |
260 | |
… | |
… | |
254 | } |
278 | } |
255 | |
279 | |
256 | void |
280 | void |
257 | rxvt_term::destroy () |
281 | rxvt_term::destroy () |
258 | { |
282 | { |
|
|
283 | if (destroy_ev.active) |
|
|
284 | return; |
|
|
285 | |
|
|
286 | #if ENABLE_OVERLAY |
|
|
287 | scr_overlay_off (); |
|
|
288 | #endif |
|
|
289 | |
259 | if (display) |
290 | if (display) |
260 | { |
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 |
261 | rootwin_ev.stop (display); |
302 | rootwin_ev.stop (display); |
|
|
303 | #endif |
|
|
304 | incr_ev.stop (); |
262 | termwin_ev.stop (display); |
305 | termwin_ev.stop (display); |
263 | vt_ev.stop (display); |
306 | vt_ev.stop (display); |
264 | #ifdef USE_XIM |
|
|
265 | im_destroy (); |
|
|
266 | im_ev.stop (display); |
|
|
267 | #endif |
|
|
268 | #ifdef HAVE_SCROLLBARS |
|
|
269 | scrollbar_ev.stop (display); |
|
|
270 | #endif |
|
|
271 | #ifdef MENUBAR |
|
|
272 | menubar_ev.stop (display); |
|
|
273 | #endif |
|
|
274 | } |
307 | } |
275 | |
308 | |
276 | check_ev.stop (); |
309 | check_ev.stop (); |
277 | pty_ev.stop (); |
310 | pty_ev.stop (); |
278 | #ifdef CURSOR_BLINK |
311 | #ifdef CURSOR_BLINK |
279 | cursor_blink_ev.stop (); |
312 | cursor_blink_ev.stop (); |
280 | #endif |
313 | #endif |
281 | #ifdef TEXT_BLINK |
314 | #ifdef TEXT_BLINK |
282 | text_blink_ev.stop (); |
315 | text_blink_ev.stop (); |
283 | #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 |
284 | #ifdef POINTER_BLANK |
323 | #ifdef POINTER_BLANK |
285 | pointer_ev.stop (); |
324 | pointer_ev.stop (); |
286 | #endif |
325 | #endif |
287 | |
326 | |
288 | destroy_ev.start (0); |
327 | destroy_ev.start (0); |
… | |
… | |
304 | SET_R (this); |
343 | SET_R (this); |
305 | |
344 | |
306 | if (!init_vars ()) |
345 | if (!init_vars ()) |
307 | return false; |
346 | return false; |
308 | |
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 |
309 | /* |
413 | /* |
310 | * Save and then give up any super-user privileges |
414 | * Save and then give up any super-user privileges |
311 | * 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. |
312 | * We should only need to be root in these cases: |
416 | * We should only need to be root in these cases: |
313 | * 1. write utmp entries on some systems |
417 | * 1. write utmp entries on some systems |
314 | * 2. chown tty on some systems |
418 | * 2. chown tty on some systems |
315 | */ |
419 | */ |
316 | privileges (SAVE); |
420 | rxvt_privileges (SAVE); |
317 | privileges (IGNORE); |
421 | rxvt_privileges (IGNORE); |
318 | |
|
|
319 | init_secondary (); |
|
|
320 | |
|
|
321 | const char **cmd_argv = init_resources (argc, argv); |
|
|
322 | |
|
|
323 | set_locale (""); |
|
|
324 | |
|
|
325 | #if MENUBAR_MAX |
|
|
326 | menubar_read (rs[Rs_menu]); |
|
|
327 | #endif |
|
|
328 | #ifdef HAVE_SCROLLBARS |
|
|
329 | if (Options & Opt_scrollBar) |
|
|
330 | scrollBar.setIdle (); /* set existence for size calculations */ |
|
|
331 | #endif |
|
|
332 | |
|
|
333 | create_windows (argc, argv); |
|
|
334 | |
|
|
335 | init_xlocale (); |
|
|
336 | |
|
|
337 | scr_reset (); /* initialize screen */ |
|
|
338 | |
|
|
339 | #if 0 |
|
|
340 | XSynchronize (display->display, True); |
|
|
341 | #endif |
|
|
342 | |
|
|
343 | #ifdef HAVE_SCROLLBARS |
|
|
344 | if (Options & Opt_scrollBar) |
|
|
345 | resize_scrollbar (); /* create and map scrollbar */ |
|
|
346 | #endif |
|
|
347 | #if (MENUBAR_MAX) |
|
|
348 | if (menubar_visible ()) |
|
|
349 | XMapWindow (display->display, menuBar.win); |
|
|
350 | #endif |
|
|
351 | #ifdef TRANSPARENT |
|
|
352 | if (Options & Opt_transparent) |
|
|
353 | { |
|
|
354 | XSelectInput (display->display, display->root, PropertyChangeMask); |
|
|
355 | check_our_parents (); |
|
|
356 | } |
|
|
357 | #endif |
|
|
358 | |
|
|
359 | rootwin_ev.start (display, display->root); |
|
|
360 | |
|
|
361 | XMapWindow (display->display, TermWin.vt); |
|
|
362 | XMapWindow (display->display, TermWin.parent[0]); |
|
|
363 | |
|
|
364 | init_command (cmd_argv); |
|
|
365 | |
|
|
366 | pty_ev.start (cmd_fd, EVENT_READ); |
|
|
367 | |
|
|
368 | check_ev.start (); |
|
|
369 | |
|
|
370 | return true; |
|
|
371 | } |
|
|
372 | |
|
|
373 | static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event); |
|
|
374 | |
|
|
375 | void |
|
|
376 | rxvt_init_signals () |
|
|
377 | { |
|
|
378 | /* install exit handler for cleanup */ |
|
|
379 | #if 0 |
|
|
380 | #ifdef HAVE_ATEXIT |
|
|
381 | atexit (rxvt_clean_exit); |
|
|
382 | #else |
|
|
383 | #endif |
|
|
384 | #endif |
|
|
385 | |
422 | |
386 | struct sigaction sa; |
423 | struct sigaction sa; |
387 | |
424 | |
388 | sigfillset (&sa.sa_mask); |
425 | sigfillset (&sa.sa_mask); |
389 | sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; |
426 | sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; |
… | |
… | |
405 | * SIGNAL HANDLING & EXIT HANDLER * |
442 | * SIGNAL HANDLING & EXIT HANDLER * |
406 | * ------------------------------------------------------------------------- */ |
443 | * ------------------------------------------------------------------------- */ |
407 | /* |
444 | /* |
408 | * Catch a SIGCHLD signal and exit if the direct child has died |
445 | * Catch a SIGCHLD signal and exit if the direct child has died |
409 | */ |
446 | */ |
|
|
447 | |
|
|
448 | void rxvt_term::child_exited (int pid) |
|
|
449 | { |
|
|
450 | for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++) |
|
|
451 | if (pid == (*t)->cmd_pid) |
|
|
452 | { |
|
|
453 | (*t)->destroy (); |
|
|
454 | break; |
|
|
455 | } |
|
|
456 | } |
|
|
457 | |
410 | /* ARGSUSED */ |
458 | /* ARGSUSED */ |
411 | /* EXTPROTO */ |
459 | /* INTPROTO */ |
412 | RETSIGTYPE |
460 | RETSIGTYPE |
413 | rxvt_Child_signal (int sig __attribute__ ((unused))) |
461 | rxvt_Child_signal (int sig __attribute__ ((unused))) |
414 | { |
462 | { |
415 | int pid, save_errno = errno; |
463 | int pid, save_errno = errno; |
|
|
464 | |
416 | while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR) |
465 | while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) |
417 | ; |
466 | rxvt_term::child_exited (pid); |
|
|
467 | |
418 | errno = save_errno; |
468 | errno = save_errno; |
419 | |
|
|
420 | #if 0 |
|
|
421 | if (pid == cmd_pid) |
|
|
422 | exit (EXIT_SUCCESS); |
|
|
423 | #endif |
|
|
424 | } |
469 | } |
425 | |
470 | |
426 | /* |
471 | /* |
427 | * Catch a fatal signal and tidy up before quitting |
472 | * Catch a fatal signal and tidy up before quitting |
428 | */ |
473 | */ |
429 | /* EXTPROTO */ |
474 | /* INTPROTO */ |
430 | RETSIGTYPE |
475 | RETSIGTYPE |
431 | rxvt_Exit_signal (int sig) |
476 | rxvt_Exit_signal (int sig) |
432 | { |
477 | { |
433 | signal (sig, SIG_DFL); |
478 | signal (sig, SIG_DFL); |
434 | #ifdef DEBUG_CMD |
479 | #ifdef DEBUG_CMD |
… | |
… | |
456 | /*----------------------------------------------------------------------*/ |
501 | /*----------------------------------------------------------------------*/ |
457 | /* |
502 | /* |
458 | * Exit gracefully, clearing the utmp entry and restoring tty attributes |
503 | * Exit gracefully, clearing the utmp entry and restoring tty attributes |
459 | * 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 |
460 | */ |
505 | */ |
461 | /* EXTPROTO */ |
506 | /* INTPROTO */ |
462 | void |
507 | void |
463 | rxvt_clean_exit () |
508 | rxvt_clean_exit () |
464 | { |
509 | { |
465 | // TODO: rxvtd should clean up all ressources |
510 | // TODO: rxvtd should clean up all ressources |
466 | if (GET_R) |
511 | if (GET_R) |
… | |
… | |
468 | } |
513 | } |
469 | |
514 | |
470 | /* ------------------------------------------------------------------------- * |
515 | /* ------------------------------------------------------------------------- * |
471 | * MEMORY ALLOCATION WRAPPERS * |
516 | * MEMORY ALLOCATION WRAPPERS * |
472 | * ------------------------------------------------------------------------- */ |
517 | * ------------------------------------------------------------------------- */ |
473 | /* EXTPROTO */ |
518 | /* INTPROTO */ |
474 | void * |
519 | void * |
475 | rxvt_malloc (size_t size) |
520 | rxvt_malloc (size_t size) |
476 | { |
521 | { |
477 | void *p; |
522 | void *p; |
478 | |
523 | |
479 | p = malloc (size); |
524 | p = malloc (size); |
480 | if (p) |
525 | if (p) |
481 | return p; |
526 | return p; |
482 | |
527 | |
483 | fprintf (stderr, RESNAME ": memory allocation failure. Aborting"); |
528 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
484 | rxvt_clean_exit (); |
|
|
485 | exit (EXIT_FAILURE); |
|
|
486 | /* NOTREACHED */ |
529 | /* NOTREACHED */ |
487 | } |
530 | } |
488 | |
531 | |
489 | /* EXTPROTO */ |
532 | /* INTPROTO */ |
490 | void * |
533 | void * |
491 | rxvt_calloc (size_t number, size_t size) |
534 | rxvt_calloc (size_t number, size_t size) |
492 | { |
535 | { |
493 | void *p; |
536 | void *p; |
494 | |
537 | |
495 | p = calloc (number, size); |
538 | p = calloc (number, size); |
496 | if (p) |
539 | if (p) |
497 | return p; |
540 | return p; |
498 | |
541 | |
499 | fprintf (stderr, RESNAME ": memory allocation failure. Aborting"); |
542 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
500 | rxvt_clean_exit (); |
|
|
501 | exit (EXIT_FAILURE); |
|
|
502 | /* NOTREACHED */ |
543 | /* NOTREACHED */ |
503 | } |
544 | } |
504 | |
545 | |
505 | /* EXTPROTO */ |
546 | /* INTPROTO */ |
506 | void * |
547 | void * |
507 | rxvt_realloc (void *ptr, size_t size) |
548 | rxvt_realloc (void *ptr, size_t size) |
508 | { |
549 | { |
509 | void *p; |
550 | void *p; |
510 | |
551 | |
511 | if (ptr) |
552 | if (ptr) |
512 | p = realloc (ptr, size); |
553 | p = realloc (ptr, size); |
513 | else |
554 | else |
514 | p = malloc (size); |
555 | p = malloc (size); |
|
|
556 | |
515 | if (p) |
557 | if (p) |
516 | return p; |
558 | return p; |
517 | |
559 | |
518 | fprintf (stderr, RESNAME ": memory allocation failure. Aborting"); |
560 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
519 | rxvt_clean_exit (); |
|
|
520 | exit (EXIT_FAILURE); |
|
|
521 | /* NOTREACHED */ |
561 | /* NOTREACHED */ |
522 | } |
562 | } |
523 | |
563 | |
524 | /* ------------------------------------------------------------------------- * |
564 | /* ------------------------------------------------------------------------- * |
525 | * PRIVILEGED OPERATIONS * |
565 | * PRIVILEGED OPERATIONS * |
526 | * ------------------------------------------------------------------------- */ |
566 | * ------------------------------------------------------------------------- */ |
527 | /* take care of suid/sgid super-user (root) privileges */ |
567 | /* take care of suid/sgid super-user (root) privileges */ |
528 | void |
568 | void |
529 | rxvt_term::privileges (int mode) |
569 | rxvt_privileges (rxvt_privaction action) |
530 | { |
570 | { |
|
|
571 | #if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) |
|
|
572 | static uid_t euid; |
|
|
573 | static gid_t egid; |
|
|
574 | #endif |
|
|
575 | |
531 | #if ! defined(__CYGWIN32__) |
576 | #if ! defined(__CYGWIN32__) |
532 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
577 | # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) |
533 | /* setreuid () is the poor man's setuid (), seteuid () */ |
578 | /* setreuid () is the poor man's setuid (), seteuid () */ |
534 | # define seteuid(a) setreuid(-1, (a)) |
579 | # define seteuid(a) setreuid(-1, (a)) |
535 | # define setegid(a) setregid(-1, (a)) |
580 | # define setegid(a) setregid(-1, (a)) |
536 | # define HAVE_SETEUID |
581 | # define HAVE_SETEUID |
537 | # endif |
582 | # endif |
538 | # ifdef HAVE_SETEUID |
583 | # ifdef HAVE_SETEUID |
539 | switch (mode) |
584 | switch (action) |
540 | { |
585 | { |
541 | case IGNORE: |
586 | case IGNORE: |
542 | /* |
587 | /* |
543 | * 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 |
544 | * back to root later, as required |
589 | * back to root later, as required |
… | |
… | |
554 | seteuid (euid); |
599 | seteuid (euid); |
555 | setegid (egid); |
600 | setegid (egid); |
556 | break; |
601 | break; |
557 | } |
602 | } |
558 | # else |
603 | # else |
559 | switch (mode) |
604 | switch (action) |
560 | { |
605 | { |
561 | case IGNORE: |
606 | case IGNORE: |
562 | setuid (getuid ()); |
607 | setuid (getuid ()); |
563 | setgid (getgid ()); |
608 | setgid (getgid ()); |
564 | /* FALLTHROUGH */ |
609 | /* FALLTHROUGH */ |
… | |
… | |
571 | #endif |
616 | #endif |
572 | } |
617 | } |
573 | |
618 | |
574 | #ifdef UTMP_SUPPORT |
619 | #ifdef UTMP_SUPPORT |
575 | void |
620 | void |
576 | rxvt_term::privileged_utmp (char action) |
621 | rxvt_term::privileged_utmp (rxvt_privaction action) |
577 | { |
622 | { |
578 | D_MAIN ((stderr, "rxvt_privileged_utmp (%c); waiting for: %c (pid: %d)", |
|
|
579 | action, next_utmp_action, getpid ())); |
|
|
580 | if (next_utmp_action != action || (action != SAVE && action != RESTORE) |
|
|
581 | || (Options & Opt_utmpInhibit) |
623 | if ((options & Opt_utmpInhibit) |
582 | || ttydev == NULL || *ttydev == '\0') |
624 | || !pty.name || !*pty.name) |
583 | return; |
625 | return; |
584 | |
626 | |
585 | privileges (RESTORE); |
627 | rxvt_privileges (RESTORE); |
|
|
628 | |
586 | if (action == SAVE) |
629 | if (action == SAVE) |
587 | { |
|
|
588 | next_utmp_action = RESTORE; |
|
|
589 | makeutent (ttydev, rs[Rs_display_name]); |
630 | makeutent (pty.name, rs[Rs_display_name]); |
590 | } |
|
|
591 | else |
631 | else |
592 | { /* action == RESTORE */ |
|
|
593 | next_utmp_action = IGNORE; |
|
|
594 | cleanutent (); |
632 | cleanutent (); |
595 | } |
633 | |
596 | privileges (IGNORE); |
634 | rxvt_privileges (IGNORE); |
597 | } |
|
|
598 | #endif |
|
|
599 | |
|
|
600 | #ifndef NO_SETOWNER_TTYDEV |
|
|
601 | void |
|
|
602 | rxvt_term::privileged_ttydev (char action) |
|
|
603 | { |
|
|
604 | D_MAIN ((stderr, |
|
|
605 | "privileged_ttydev (%c); waiting for: %c (pid: %d)", |
|
|
606 | action, next_tty_action, getpid ())); |
|
|
607 | if (next_tty_action != action || (action != SAVE && action != RESTORE) |
|
|
608 | || ttydev == NULL || *ttydev == '\0') |
|
|
609 | return; |
|
|
610 | |
|
|
611 | privileges (RESTORE); |
|
|
612 | |
|
|
613 | if (action == SAVE) |
|
|
614 | { |
|
|
615 | next_tty_action = RESTORE; |
|
|
616 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
|
|
617 | /* store original tty status for restoration rxvt_clean_exit () -- rgg 04/12/95 */ |
|
|
618 | if (lstat (ttydev, &ttyfd_stat) < 0) /* you lose out */ |
|
|
619 | next_tty_action = IGNORE; |
|
|
620 | else |
|
|
621 | # endif |
|
|
622 | |
|
|
623 | { |
|
|
624 | chown (ttydev, getuid (), ttygid); /* fail silently */ |
|
|
625 | chmod (ttydev, ttymode); |
|
|
626 | # ifdef HAVE_REVOKE |
|
|
627 | revoke (ttydev); |
|
|
628 | # endif |
|
|
629 | |
|
|
630 | } |
|
|
631 | } |
|
|
632 | else |
|
|
633 | { /* action == RESTORE */ |
|
|
634 | next_tty_action = IGNORE; |
|
|
635 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
|
|
636 | chmod (ttydev, ttyfd_stat.st_mode); |
|
|
637 | chown (ttydev, ttyfd_stat.st_uid, ttyfd_stat.st_gid); |
|
|
638 | # else |
|
|
639 | chmod (ttydev, |
|
|
640 | (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)); |
|
|
641 | chown (ttydev, 0, 0); |
|
|
642 | # endif |
|
|
643 | |
|
|
644 | } |
|
|
645 | |
|
|
646 | privileges (IGNORE); |
|
|
647 | |
|
|
648 | # ifndef RESET_TTY_TO_COMMON_DEFAULTS |
|
|
649 | D_MAIN ((stderr, "%s \"%s\": mode %03o, uid %d, gid %d", |
|
|
650 | action == RESTORE ? "Restoring" : (action == |
|
|
651 | SAVE ? "Saving" : |
|
|
652 | "UNKNOWN ERROR for"), ttydev, |
|
|
653 | ttyfd_stat.st_mode, ttyfd_stat.st_uid, |
|
|
654 | ttyfd_stat.st_gid)); |
|
|
655 | # endif |
|
|
656 | } |
635 | } |
657 | #endif |
636 | #endif |
658 | |
637 | |
659 | /*----------------------------------------------------------------------*/ |
638 | /*----------------------------------------------------------------------*/ |
660 | /* |
639 | /* |
… | |
… | |
725 | max_height = MAX_ROWS * TermWin.fheight; |
704 | max_height = MAX_ROWS * TermWin.fheight; |
726 | |
705 | |
727 | szHint.base_width = szHint.base_height = 2 * TermWin.int_bwidth; |
706 | szHint.base_width = szHint.base_height = 2 * TermWin.int_bwidth; |
728 | |
707 | |
729 | sb_w = mb_h = 0; |
708 | sb_w = mb_h = 0; |
730 | window_vt_x = window_vt_y = 0; |
709 | window_vt_x = window_vt_y = TermWin.int_bwidth; |
|
|
710 | |
731 | if (scrollbar_visible ()) |
711 | if (scrollbar_visible ()) |
732 | { |
712 | { |
733 | sb_w = scrollbar_TotalWidth (); |
713 | sb_w = scrollbar_TotalWidth (); |
734 | szHint.base_width += sb_w; |
714 | szHint.base_width += sb_w; |
735 | if (! (Options & Opt_scrollBar_right)) |
715 | if (!(options & Opt_scrollBar_right)) |
736 | window_vt_x = sb_w; |
716 | window_vt_x += sb_w; |
737 | } |
717 | } |
|
|
718 | |
738 | if (menubar_visible ()) |
719 | if (menubar_visible ()) |
739 | { |
720 | { |
740 | mb_h = menuBar_TotalHeight (); |
721 | mb_h = menuBar_TotalHeight (); |
741 | szHint.base_height += mb_h; |
722 | szHint.base_height += mb_h; |
742 | window_vt_y = mb_h; |
723 | window_vt_y += mb_h; |
743 | } |
724 | } |
|
|
725 | |
744 | szHint.width_inc = TermWin.fwidth; |
726 | szHint.width_inc = TermWin.fwidth; |
745 | szHint.height_inc = TermWin.fheight; |
727 | szHint.height_inc = TermWin.fheight; |
746 | szHint.min_width = szHint.base_width + szHint.width_inc; |
728 | szHint.min_width = szHint.base_width + szHint.width_inc; |
747 | szHint.min_height = szHint.base_height + szHint.height_inc; |
729 | szHint.min_height = szHint.base_height + szHint.height_inc; |
748 | |
730 | |
… | |
… | |
754 | else |
736 | else |
755 | { |
737 | { |
756 | MIN_IT (TermWin.width, max_width); |
738 | MIN_IT (TermWin.width, max_width); |
757 | szHint.width = szHint.base_width + TermWin.width; |
739 | szHint.width = szHint.base_width + TermWin.width; |
758 | } |
740 | } |
|
|
741 | |
759 | if (height && height - szHint.base_height < max_height) |
742 | if (height && height - szHint.base_height < max_height) |
760 | { |
743 | { |
761 | szHint.height = height; |
744 | szHint.height = height; |
762 | TermWin.height = height - szHint.base_height; |
745 | TermWin.height = height - szHint.base_height; |
763 | } |
746 | } |
764 | else |
747 | else |
765 | { |
748 | { |
766 | MIN_IT (TermWin.height, max_height); |
749 | MIN_IT (TermWin.height, max_height); |
767 | szHint.height = szHint.base_height + TermWin.height; |
750 | szHint.height = szHint.base_height + TermWin.height; |
768 | } |
751 | } |
|
|
752 | |
769 | if (scrollbar_visible () && (Options & Opt_scrollBar_right)) |
753 | if (scrollbar_visible () && (options & Opt_scrollBar_right)) |
770 | window_sb_x = szHint.width - sb_w; |
754 | window_sb_x = szHint.width - sb_w; |
771 | |
755 | |
772 | if (recalc_x) |
756 | if (recalc_x) |
773 | szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) |
757 | szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) |
774 | - szHint.width - 2 * TermWin.ext_bwidth); |
758 | - szHint.width - 2 * TermWin.ext_bwidth); |
… | |
… | |
790 | * Called after a window size change. |
774 | * Called after a window size change. |
791 | */ |
775 | */ |
792 | void |
776 | void |
793 | rxvt_term::tt_winch () |
777 | rxvt_term::tt_winch () |
794 | { |
778 | { |
|
|
779 | if (pty.pty < 0) |
|
|
780 | return; |
|
|
781 | |
795 | struct winsize ws; |
782 | struct winsize ws; |
796 | |
|
|
797 | if (cmd_fd < 0) |
|
|
798 | return; |
|
|
799 | |
783 | |
800 | ws.ws_col = TermWin.ncol; |
784 | ws.ws_col = TermWin.ncol; |
801 | ws.ws_row = TermWin.nrow; |
785 | ws.ws_row = TermWin.nrow; |
802 | ws.ws_xpixel = ws.ws_ypixel = 0; |
786 | ws.ws_xpixel = TermWin.width; |
803 | #ifndef DEBUG_SIZE |
787 | ws.ws_ypixel = TermWin.height; |
804 | (void)ioctl (cmd_fd, TIOCSWINSZ, &ws); |
788 | (void)ioctl (pty.pty, TIOCSWINSZ, &ws); |
805 | #else |
789 | |
806 | if (ioctl (cmd_fd, TIOCSWINSZ, &ws) < 0) |
790 | #if 0 |
807 | D_SIZE ((stderr, "Failed to send TIOCSWINSZ to fd %d", fd)); |
791 | // TIOCSWINSZ⎈ is supposed to do this automatically and correctly |
808 | # ifdef SIGWINCH |
|
|
809 | else if (cmd_pid) /* force through to the command */ |
792 | if (cmd_pid) /* force through to the command */ |
810 | kill (cmd_pid, SIGWINCH); |
793 | kill (cmd_pid, SIGWINCH); |
811 | # endif |
|
|
812 | #endif |
794 | #endif |
813 | } |
795 | } |
814 | |
796 | |
815 | /*----------------------------------------------------------------------*/ |
797 | /*----------------------------------------------------------------------*/ |
816 | /* rxvt_change_font () - Switch to a new font */ |
798 | /* rxvt_change_font () - Switch to a new font */ |
… | |
… | |
848 | resize_all_windows (0, 0, 0); |
830 | resize_all_windows (0, 0, 0); |
849 | scr_remap_chars (); |
831 | scr_remap_chars (); |
850 | scr_touch (true); |
832 | scr_touch (true); |
851 | } |
833 | } |
852 | |
834 | |
|
|
835 | for (unicode_t ch = 0x20; ch <= 0x7f; ch++) |
|
|
836 | TermWin.ascii_map [ch - 0x20] = fs->find_font (ch); |
|
|
837 | |
853 | return true; |
838 | return true; |
854 | } |
839 | } |
855 | } |
840 | } |
856 | |
841 | |
857 | return false; |
842 | return false; |
… | |
… | |
867 | /*----------------------------------------------------------------------*/ |
852 | /*----------------------------------------------------------------------*/ |
868 | /* xterm sequences - title, iconName, color (exptl) */ |
853 | /* xterm sequences - title, iconName, color (exptl) */ |
869 | void |
854 | void |
870 | rxvt_term::set_title (const char *str) |
855 | rxvt_term::set_title (const char *str) |
871 | { |
856 | { |
872 | #ifndef SMART_WINDOW_TITLE |
857 | #ifdef SMART_WINDOW_TITLE |
873 | XStoreName (display->display, TermWin.parent[0], str); |
|
|
874 | #else |
|
|
875 | char *name; |
858 | char *name; |
876 | |
859 | |
877 | if (!XFetchName (display->display, TermWin.parent[0], &name)) |
860 | if (!XFetchName (display->display, TermWin.parent[0], &name)) |
878 | name = NULL; |
861 | name = NULL; |
879 | |
862 | |
880 | if (name == NULL || STRCMP (name, str)) |
863 | if (name == NULL || strcmp (name, str)) |
|
|
864 | #endif |
881 | XStoreName (display->display, TermWin.parent[0], str); |
865 | XStoreName (display->display, TermWin.parent[0], str); |
882 | |
866 | |
|
|
867 | #ifdef SMART_WINDOW_TITLE |
883 | if (name) |
868 | if (name) |
884 | XFree (name); |
869 | XFree (name); |
885 | #endif |
870 | #endif |
886 | } |
871 | } |
887 | |
872 | |
888 | void |
873 | void |
889 | rxvt_term::set_icon_name (const char *str) |
874 | rxvt_term::set_icon_name (const char *str) |
890 | { |
875 | { |
891 | #ifndef SMART_WINDOW_TITLE |
876 | #ifdef SMART_WINDOW_TITLE |
892 | XSetIconName (display->display, TermWin.parent[0], str); |
|
|
893 | #else |
|
|
894 | char *name; |
877 | char *name; |
895 | |
878 | |
896 | if (!XGetIconName (display->display, TermWin.parent[0], &name)) |
879 | if (!XGetIconName (display->display, TermWin.parent[0], &name)) |
897 | name = NULL; |
880 | name = NULL; |
898 | |
881 | |
899 | if (name == NULL || STRCMP (name, str)) |
882 | if (name == NULL || strcmp (name, str)) |
|
|
883 | #endif |
900 | XSetIconName (display->display, TermWin.parent[0], str); |
884 | XSetIconName (display->display, TermWin.parent[0], str); |
901 | |
885 | |
|
|
886 | #ifdef SMART_WINDOW_TITLE |
902 | if (name) |
887 | if (name) |
903 | XFree (name); |
888 | XFree (name); |
904 | #endif |
889 | #endif |
905 | } |
890 | } |
906 | |
891 | |
… | |
… | |
920 | i = atoi (color); |
905 | i = atoi (color); |
921 | if (i >= 8 && i <= 15) |
906 | if (i >= 8 && i <= 15) |
922 | { /* bright colors */ |
907 | { /* bright colors */ |
923 | i -= 8; |
908 | i -= 8; |
924 | # ifndef NO_BRIGHTCOLOR |
909 | # ifndef NO_BRIGHTCOLOR |
925 | PixColors[idx] = PixColors[minBrightCOLOR + i]; |
910 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
926 | SET_PIXCOLOR (idx); |
911 | SET_PIXCOLOR (idx); |
927 | goto Done; |
912 | goto Done; |
928 | # endif |
913 | # endif |
929 | |
914 | |
930 | } |
915 | } |
931 | if (i >= 0 && i <= 7) |
916 | if (i >= 0 && i <= 7) |
932 | { /* normal colors */ |
917 | { /* normal colors */ |
933 | PixColors[idx] = PixColors[minCOLOR + i]; |
918 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
934 | SET_PIXCOLOR (idx); |
919 | SET_PIXCOLOR (idx); |
935 | goto Done; |
920 | goto Done; |
936 | } |
921 | } |
937 | } |
922 | } |
|
|
923 | |
938 | if (!rXParseAllocColor (& xcol, color)) |
924 | if (!rXParseAllocColor (& xcol, color)) |
939 | return; |
925 | return; |
|
|
926 | |
940 | /* XStoreColor (display->display, XCMAP, XColor*); */ |
927 | /* XStoreColor (display->display, display->cmap, XColor*); */ |
941 | |
928 | |
942 | /* |
929 | /* |
943 | * 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, |
944 | * so just keep gobbling up the colormap |
931 | * so just keep gobbling up the colormap |
945 | */ |
932 | */ |
946 | # if 0 |
933 | # if 0 |
947 | for (i = Color_Black; i <= Color_White; i++) |
934 | for (i = Color_Black; i <= Color_White; i++) |
948 | if (PixColors[idx] == PixColors[i]) |
935 | if (pix_colors[idx] == pix_colors[i]) |
949 | break; |
936 | break; |
950 | if (i > Color_White) |
937 | if (i > Color_White) |
951 | { |
938 | { |
952 | /* fprintf (stderr, "XFreeColors: PixColors [%d] = %lu\n", idx, PixColors [idx]); */ |
939 | /* fprintf (stderr, "XFreeColors: pix_colors [%d] = %lu\n", idx, pix_colors [idx]); */ |
953 | XFreeColors (display->display, XCMAP, (PixColors + idx), 1, |
940 | XFreeColors (display->display, display->cmap, (pix_colors + idx), 1, |
954 | DisplayPlanes (display->display, display->screen)); |
941 | DisplayPlanes (display->display, display->screen)); |
955 | } |
942 | } |
956 | # endif |
943 | # endif |
957 | |
944 | |
958 | PixColors[idx] = xcol; |
945 | pix_colors_focused[idx] = xcol; |
959 | SET_PIXCOLOR (idx); |
946 | SET_PIXCOLOR (idx); |
960 | |
947 | |
961 | /* XSetWindowAttributes attr; */ |
948 | /* XSetWindowAttributes attr; */ |
962 | /* Cursor cursor; */ |
949 | /* Cursor cursor; */ |
963 | 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 |
964 | if (idx == Color_bg && ! (Options & Opt_transparent)) |
954 | if (idx == Color_bg && ! (options & Opt_transparent)) |
965 | XSetWindowBackground (display->display, TermWin.vt, |
955 | XSetWindowBackground (display->display, TermWin.vt, pix_colors[Color_bg]); |
966 | PixColors[Color_bg]); |
|
|
967 | |
956 | |
968 | /* handle Color_BD, scrollbar background, etc. */ |
957 | /* handle Color_BD, scrollbar background, etc. */ |
969 | |
958 | |
970 | set_colorfgbg (); |
959 | set_colorfgbg (); |
971 | recolour_cursor (); |
960 | recolour_cursor (); |
972 | /* the only reasonable way to enforce a clean update */ |
961 | scr_touch (true); |
973 | scr_poweron (); |
|
|
974 | } |
962 | } |
975 | |
963 | |
976 | #else |
964 | #else |
977 | # define set_window_color (idx,color) ((void)0) |
965 | # define set_window_color (idx,color) ((void)0) |
978 | #endif /* XTERM_COLOR_CHANGE */ |
966 | #endif /* XTERM_COLOR_CHANGE */ |
979 | |
967 | |
980 | void |
968 | void |
981 | rxvt_term::recolour_cursor () |
969 | rxvt_term::recolour_cursor () |
982 | { |
970 | { |
983 | #if TODO |
|
|
984 | rxvt_color xcol[2]; |
971 | XColor xcol[2]; |
985 | |
972 | |
986 | xcol[0] = PixColors[Color_pointer]; |
973 | xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) ? pix_colors_focused[Color_pointer_fg] : pix_colors_focused[Color_fg]; |
987 | xcol[1] = PixColors[Color_bg]; |
974 | xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) ? pix_colors_focused[Color_pointer_bg] : pix_colors_focused[Color_bg]; |
988 | XQueryColors (display->display, XCMAP, xcol, 2); |
975 | XQueryColors (display->display, display->cmap, xcol, 2); |
989 | XRecolorCursor (display->display, TermWin_cursor, & (xcol[0]), & (xcol[1])); |
976 | XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1); |
990 | #endif |
|
|
991 | } |
977 | } |
992 | |
978 | |
993 | /*----------------------------------------------------------------------*/ |
979 | /*----------------------------------------------------------------------*/ |
994 | /* |
980 | /* |
995 | * find if fg/bg matches any of the normal (low-intensity) colors |
981 | * find if fg/bg matches any of the normal (low-intensity) colors |
… | |
… | |
1001 | const char *xpmb = "\0"; |
987 | const char *xpmb = "\0"; |
1002 | char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1]; |
988 | char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1]; |
1003 | |
989 | |
1004 | env_colorfgbg = |
990 | env_colorfgbg = |
1005 | (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1); |
991 | (char *)rxvt_malloc (sizeof ("COLORFGBG=default;default;bg") + 1); |
1006 | STRCPY (fstr, "default"); |
992 | strcpy (fstr, "default"); |
1007 | STRCPY (bstr, "default"); |
993 | strcpy (bstr, "default"); |
1008 | for (i = Color_Black; i <= Color_White; i++) |
994 | for (i = Color_Black; i <= Color_White; i++) |
1009 | if (PixColors[Color_fg] == PixColors[i]) |
995 | if (pix_colors[Color_fg] == pix_colors[i]) |
1010 | { |
996 | { |
1011 | sprintf (fstr, "%d", (i - Color_Black)); |
997 | sprintf (fstr, "%d", (i - Color_Black)); |
1012 | break; |
998 | break; |
1013 | } |
999 | } |
1014 | for (i = Color_Black; i <= Color_White; i++) |
1000 | for (i = Color_Black; i <= Color_White; i++) |
1015 | if (PixColors[Color_bg] == PixColors[i]) |
1001 | if (pix_colors[Color_bg] == pix_colors[i]) |
1016 | { |
1002 | { |
1017 | sprintf (bstr, "%d", (i - Color_Black)); |
1003 | sprintf (bstr, "%d", (i - Color_Black)); |
1018 | #ifdef XPM_BACKGROUND |
1004 | #ifdef XPM_BACKGROUND |
1019 | xpmb = "default;"; |
1005 | xpmb = "default;"; |
1020 | #endif |
1006 | #endif |
… | |
… | |
1025 | |
1011 | |
1026 | #ifndef NO_BRIGHTCOLOR |
1012 | #ifndef NO_BRIGHTCOLOR |
1027 | colorfgbg = DEFAULT_RSTYLE; |
1013 | colorfgbg = DEFAULT_RSTYLE; |
1028 | for (i = minCOLOR; i <= maxCOLOR; i++) |
1014 | for (i = minCOLOR; i <= maxCOLOR; i++) |
1029 | { |
1015 | { |
1030 | if (PixColors[Color_fg] == PixColors[i]) |
1016 | if (pix_colors[Color_fg] == pix_colors[i]) |
1031 | colorfgbg = SET_FGCOLOR (colorfgbg, i); |
1017 | colorfgbg = SET_FGCOLOR (colorfgbg, i); |
1032 | if (PixColors[Color_bg] == PixColors[i]) |
1018 | if (pix_colors[Color_bg] == pix_colors[i]) |
1033 | colorfgbg = SET_BGCOLOR (colorfgbg, i); |
1019 | colorfgbg = SET_BGCOLOR (colorfgbg, i); |
1034 | } |
1020 | } |
1035 | #endif |
1021 | #endif |
1036 | } |
1022 | } |
1037 | |
1023 | |
… | |
… | |
1065 | int old_width = szHint.width, old_height = szHint.height; |
1051 | int old_width = szHint.width, old_height = szHint.height; |
1066 | #endif |
1052 | #endif |
1067 | |
1053 | |
1068 | window_calc (width, height); |
1054 | window_calc (width, height); |
1069 | XSetWMNormalHints (display->display, TermWin.parent[0], &szHint); |
1055 | XSetWMNormalHints (display->display, TermWin.parent[0], &szHint); |
|
|
1056 | |
1070 | if (!ignoreparent) |
1057 | if (!ignoreparent) |
1071 | { |
1058 | { |
1072 | #ifdef SMART_RESIZE |
1059 | #ifdef SMART_RESIZE |
1073 | /* |
1060 | /* |
1074 | * resize by Marius Gedminas <marius.gedminas@uosis.mif.vu.lt> |
1061 | * resize by Marius Gedminas <marius.gedminas@uosis.mif.vu.lt> |
… | |
… | |
1109 | dy /= 2; |
1096 | dy /= 2; |
1110 | |
1097 | |
1111 | XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy, |
1098 | XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy, |
1112 | szHint.width, szHint.height); |
1099 | szHint.width, szHint.height); |
1113 | #else |
1100 | #else |
1114 | XResizeWindow (display->display, TermWin.parent[0], szHint.width, |
1101 | XResizeWindow (display->display, TermWin.parent[0], szHint.width, szHint.height); |
1115 | szHint.height); |
|
|
1116 | #endif |
1102 | #endif |
1117 | |
|
|
1118 | } |
1103 | } |
1119 | |
1104 | |
1120 | fix_screen = (TermWin.ncol != prev_ncol |
1105 | fix_screen = TermWin.ncol != prev_ncol || TermWin.nrow != prev_nrow; |
1121 | || TermWin.nrow != prev_nrow); |
|
|
1122 | |
1106 | |
1123 | if (fix_screen || width != old_width || height != old_height) |
1107 | if (fix_screen || width != old_width || height != old_height) |
1124 | { |
1108 | { |
1125 | if (scrollbar_visible ()) |
1109 | if (scrollbar_visible ()) |
1126 | { |
1110 | { |
1127 | XMoveResizeWindow (display->display, scrollBar.win, window_sb_x, |
1111 | XMoveResizeWindow (display->display, scrollBar.win, |
|
|
1112 | window_sb_x, 0, |
1128 | 0, scrollbar_TotalWidth (), szHint.height); |
1113 | scrollbar_TotalWidth (), szHint.height); |
1129 | resize_scrollbar (); |
1114 | resize_scrollbar (); |
1130 | } |
1115 | } |
1131 | |
1116 | |
1132 | if (menubar_visible ()) |
1117 | if (menubar_visible ()) |
1133 | XMoveResizeWindow (display->display, menuBar.win, window_vt_x, |
1118 | XMoveResizeWindow (display->display, menuBar.win, |
|
|
1119 | window_vt_x, 0, |
1134 | 0, TermWin_TotalWidth (), menuBar_TotalHeight ()); |
1120 | TermWin_TotalWidth (), menuBar_TotalHeight ()); |
1135 | |
1121 | |
1136 | XMoveResizeWindow (display->display, TermWin.vt, window_vt_x, |
1122 | XMoveResizeWindow (display->display, TermWin.vt, |
1137 | window_vt_y, TermWin_TotalWidth (), |
1123 | window_vt_x, window_vt_y, |
1138 | TermWin_TotalHeight ()); |
1124 | TermWin_TotalWidth (), TermWin_TotalHeight ()); |
1139 | scr_clear (height != old_height); |
1125 | scr_clear (); |
1140 | #ifdef XPM_BACKGROUND |
1126 | #ifdef XPM_BACKGROUND |
1141 | resize_pixmap (); |
1127 | resize_pixmap (); |
1142 | #endif |
1128 | #endif |
1143 | |
|
|
1144 | } |
1129 | } |
1145 | |
1130 | |
1146 | if (fix_screen || old_height == 0) |
1131 | if (fix_screen || old_height == 0) |
1147 | { |
1132 | { |
1148 | int curr_screen = -1; |
1133 | int curr_screen = -1; |
… | |
… | |
1189 | if (width == 0) |
1174 | if (width == 0) |
1190 | width = wattr.width - szHint.base_width; |
1175 | width = wattr.width - szHint.base_width; |
1191 | if (height == 0) |
1176 | if (height == 0) |
1192 | height = wattr.height - szHint.base_height; |
1177 | height = wattr.height - szHint.base_height; |
1193 | } |
1178 | } |
|
|
1179 | |
1194 | if (width != TermWin.width || height != TermWin.height) |
1180 | if (width != TermWin.width || height != TermWin.height) |
1195 | { |
1181 | { |
1196 | width += szHint.base_width; |
1182 | width += szHint.base_width; |
1197 | height += szHint.base_height; |
1183 | height += szHint.base_height; |
1198 | resize_all_windows (width, height, 0); |
1184 | resize_all_windows (width, height, 0); |
… | |
… | |
1203 | * - X INPUT METHOD ROUTINES - * |
1189 | * - X INPUT METHOD ROUTINES - * |
1204 | * -------------------------------------------------------------------- */ |
1190 | * -------------------------------------------------------------------- */ |
1205 | #ifdef USE_XIM |
1191 | #ifdef USE_XIM |
1206 | |
1192 | |
1207 | 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 |
1208 | rxvt_term::im_set_size (XRectangle *size) |
1201 | rxvt_term::im_set_size (XRectangle &size) |
1209 | { |
1202 | { |
|
|
1203 | // the int_bwidth terms make no sense to me |
1210 | size->x = TermWin.int_bwidth; |
1204 | size.x = TermWin.int_bwidth; |
1211 | size->y = TermWin.int_bwidth; |
1205 | size.y = TermWin.int_bwidth; |
1212 | size->width = Width2Pixel (TermWin.ncol); |
1206 | size.width = Width2Pixel (TermWin.ncol) + TermWin.int_bwidth; |
1213 | size->height = Height2Pixel (TermWin.nrow); |
1207 | size.height = Height2Pixel (TermWin.nrow) + TermWin.int_bwidth; |
1214 | } |
1208 | } |
1215 | |
1209 | |
1216 | void |
1210 | void |
1217 | 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) |
1218 | { |
1214 | { |
1219 | *fg = PixColors[Color_fg]; |
1215 | preedit_rect.x = needed_rect.width; |
1220 | *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; |
1221 | } |
1224 | } |
1222 | |
1225 | |
1223 | /* Checking whether input method is running. */ |
1226 | /* Checking whether input method is running. */ |
1224 | bool |
1227 | bool |
1225 | rxvt_term::IMisRunning () |
1228 | rxvt_term::IMisRunning () |
1226 | { |
1229 | { |
1227 | char *p; |
1230 | char *p; |
1228 | Atom atom; |
1231 | Atom atom; |
1229 | Window win; |
1232 | Window win; |
1230 | char server[IMBUFSIZ]; |
1233 | char server[IMBUFSIZ]; |
1231 | |
1234 | |
1232 | /* get current locale modifier */ |
1235 | /* get current locale modifier */ |
1233 | if ((p = XSetLocaleModifiers (NULL)) != NULL) |
1236 | if ((p = XSetLocaleModifiers (NULL)) != NULL) |
1234 | { |
1237 | { |
1235 | STRCPY (server, "@server="); |
1238 | strcpy (server, "@server="); |
1236 | STRNCAT (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */ |
1239 | strncat (server, & (p[4]), IMBUFSIZ - 9); /* skip "@im=" */ |
|
|
1240 | |
1237 | if ((p = STRCHR (server + 1, '@')) != NULL) /* first one only */ |
1241 | if ((p = strchr (server + 1, '@')) != NULL) /* first one only */ |
1238 | *p = '\0'; |
1242 | *p = '\0'; |
1239 | |
1243 | |
1240 | atom = XInternAtom (display->display, server, False); |
1244 | atom = XInternAtom (display->display, server, False); |
1241 | win = XGetSelectionOwner (display->display, atom); |
1245 | win = XGetSelectionOwner (display->display, atom); |
|
|
1246 | |
1242 | if (win != None) |
1247 | if (win != None) |
1243 | return True; |
1248 | return True; |
1244 | } |
1249 | } |
|
|
1250 | |
1245 | return False; |
1251 | return False; |
1246 | } |
1252 | } |
1247 | |
1253 | |
1248 | void |
1254 | void |
1249 | rxvt_term::IMSendSpot () |
1255 | rxvt_term::IMSendSpot () |
1250 | { |
1256 | { |
1251 | XPoint spot; |
1257 | XPoint spot; |
1252 | XVaNestedList preedit_attr; |
1258 | XVaNestedList preedit_attr; |
1253 | |
1259 | |
1254 | if (Input_Context == NULL |
1260 | if (!Input_Context |
|
|
1261 | || !TermWin.focus |
1255 | || !TermWin.focus || ! (input_style & XIMPreeditPosition) |
1262 | || !(input_style & XIMPreeditPosition) |
|
|
1263 | #if 0 |
1256 | || ! (event_type == KeyPress |
1264 | || !(event_type == KeyPress |
1257 | || event_type == Expose |
1265 | || event_type == Expose |
1258 | || event_type == NoExpose |
1266 | || event_type == NoExpose |
1259 | || event_type == SelectionNotify |
1267 | || event_type == SelectionNotify |
1260 | || event_type == ButtonRelease || event_type == FocusIn) |
1268 | || event_type == ButtonRelease || event_type == FocusIn) |
|
|
1269 | #endif |
1261 | || !IMisRunning ()) |
1270 | || !IMisRunning ()) |
1262 | return; |
1271 | return; |
1263 | |
1272 | |
1264 | im_set_position (&spot); |
1273 | im_set_position (spot); |
1265 | |
1274 | |
1266 | preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); |
1275 | preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); |
1267 | XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); |
1276 | XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); |
1268 | XFree (preedit_attr); |
1277 | XFree (preedit_attr); |
1269 | } |
1278 | } |
1270 | |
1279 | |
1271 | void |
1280 | void |
1272 | rxvt_term::im_set_preedit_area (XRectangle * preedit_rect, XRectangle * status_rect, |
|
|
1273 | XRectangle * needed_rect) |
|
|
1274 | { |
|
|
1275 | int mbh, vtx = 0; |
|
|
1276 | |
|
|
1277 | if (scrollbar_visible () && ! (Options & Opt_scrollBar_right)) |
|
|
1278 | vtx = scrollbar_TotalWidth (); |
|
|
1279 | |
|
|
1280 | mbh = menubar_visible () ? menuBar_TotalHeight () : 0; |
|
|
1281 | mbh -= TermWin.lineSpace; |
|
|
1282 | |
|
|
1283 | preedit_rect->x = needed_rect->width + vtx; |
|
|
1284 | preedit_rect->y = Height2Pixel (TermWin.nrow - 1) + mbh; |
|
|
1285 | |
|
|
1286 | preedit_rect->width = Width2Pixel (TermWin.ncol + 1) - needed_rect->width + vtx; |
|
|
1287 | preedit_rect->height = Height2Pixel (1); |
|
|
1288 | |
|
|
1289 | status_rect->x = vtx; |
|
|
1290 | status_rect->y = Height2Pixel (TermWin.nrow - 1) + mbh; |
|
|
1291 | |
|
|
1292 | status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel (TermWin.ncol + 1); |
|
|
1293 | status_rect->height = Height2Pixel (1); |
|
|
1294 | } |
|
|
1295 | |
|
|
1296 | void |
|
|
1297 | rxvt_term::im_destroy () |
1281 | rxvt_term::im_destroy () |
1298 | { |
1282 | { |
1299 | if (Input_Context) |
1283 | if (Input_Context) |
1300 | { |
1284 | { |
1301 | XDestroyIC (Input_Context); |
1285 | XDestroyIC (Input_Context); |
1302 | Input_Context = NULL; |
1286 | Input_Context = 0; |
1303 | } |
1287 | } |
1304 | |
1288 | |
1305 | if (input_method) |
1289 | if (input_method) |
1306 | { |
1290 | { |
1307 | display->put_xim (input_method); |
1291 | display->put_xim (input_method); |
… | |
… | |
1314 | * open a suitable preedit type |
1298 | * open a suitable preedit type |
1315 | */ |
1299 | */ |
1316 | bool |
1300 | bool |
1317 | rxvt_term::IM_get_IC (const char *modifiers) |
1301 | rxvt_term::IM_get_IC (const char *modifiers) |
1318 | { |
1302 | { |
1319 | int i, j, found; |
1303 | int i, j, found; |
1320 | XIM xim; |
1304 | XIM xim; |
1321 | XPoint spot; |
1305 | XPoint spot; |
1322 | XRectangle rect, status_rect, needed_rect; |
1306 | XRectangle rect, status_rect, needed_rect; |
1323 | unsigned long fg, bg; |
1307 | unsigned long fg, bg; |
1324 | const char *p; |
1308 | const char *p; |
1325 | char **s; |
1309 | char **s; |
1326 | XIMStyles *xim_styles; |
1310 | XIMStyles *xim_styles; |
1327 | XVaNestedList preedit_attr, status_attr; |
|
|
1328 | |
1311 | |
1329 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1312 | if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) |
1330 | return false; |
1313 | return false; |
1331 | |
1314 | |
1332 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
1315 | D_MAIN ((stderr, "rxvt_IM_get_IC ()")); |
… | |
… | |
1338 | |
1321 | |
1339 | xim_styles = NULL; |
1322 | xim_styles = NULL; |
1340 | if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) |
1323 | if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) |
1341 | || !xim_styles || !xim_styles->count_styles) |
1324 | || !xim_styles || !xim_styles->count_styles) |
1342 | { |
1325 | { |
1343 | display->put_xim (input_method); |
1326 | im_destroy (); |
1344 | return false; |
1327 | return false; |
1345 | } |
1328 | } |
1346 | |
1329 | |
1347 | p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root"; |
1330 | p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root"; |
1348 | s = rxvt_splitcommastring (p); |
1331 | s = rxvt_splitcommastring (p); |
|
|
1332 | |
1349 | for (i = found = 0; !found && s[i]; i++) |
1333 | for (i = found = 0; !found && s[i]; i++) |
1350 | { |
1334 | { |
1351 | if (!STRCMP (s[i], "OverTheSpot")) |
1335 | if (!strcmp (s[i], "OverTheSpot")) |
1352 | input_style = (XIMPreeditPosition | XIMStatusNothing); |
1336 | input_style = (XIMPreeditPosition | XIMStatusNothing); |
1353 | else if (!STRCMP (s[i], "OffTheSpot")) |
1337 | else if (!strcmp (s[i], "OffTheSpot")) |
1354 | input_style = (XIMPreeditArea | XIMStatusArea); |
1338 | input_style = (XIMPreeditArea | XIMStatusArea); |
1355 | else if (!STRCMP (s[i], "Root")) |
1339 | else if (!strcmp (s[i], "Root")) |
1356 | input_style = (XIMPreeditNothing | XIMStatusNothing); |
1340 | input_style = (XIMPreeditNothing | XIMStatusNothing); |
1357 | |
1341 | |
1358 | for (j = 0; j < xim_styles->count_styles; j++) |
1342 | for (j = 0; j < xim_styles->count_styles; j++) |
1359 | if (input_style == xim_styles->supported_styles[j]) |
1343 | if (input_style == xim_styles->supported_styles[j]) |
1360 | { |
1344 | { |
… | |
… | |
1369 | free (s); |
1353 | free (s); |
1370 | XFree (xim_styles); |
1354 | XFree (xim_styles); |
1371 | |
1355 | |
1372 | if (!found) |
1356 | if (!found) |
1373 | { |
1357 | { |
1374 | display->put_xim (input_method); |
1358 | im_destroy (); |
1375 | return false; |
1359 | return false; |
1376 | } |
1360 | } |
1377 | |
1361 | |
1378 | 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 | } |
1379 | |
1396 | |
1380 | if (input_style & XIMPreeditPosition) |
1397 | if (input_style & XIMPreeditPosition) |
1381 | { |
1398 | { |
1382 | im_set_size (&rect); |
1399 | im_set_size (rect); |
1383 | im_set_position (&spot); |
1400 | im_set_position (spot); |
1384 | im_set_color (&fg, &bg); |
1401 | im_set_color (fg, bg); |
1385 | |
1402 | |
1386 | preedit_attr = XVaCreateNestedList (0, XNArea, &rect, |
1403 | preedit_attr = XVaCreateNestedList (0, |
|
|
1404 | XNForeground, fg, |
|
|
1405 | XNBackground, bg, |
|
|
1406 | XNArea, &rect, |
1387 | XNSpotLocation, &spot, |
1407 | XNSpotLocation, &spot, |
1388 | XNForeground, fg, XNBackground, bg, |
|
|
1389 | //XNFontSet, TermWin.fontset, |
1408 | XNFontSet, fs, |
1390 | NULL); |
1409 | NULL); |
1391 | } |
1410 | } |
1392 | else if (input_style & XIMPreeditArea) |
1411 | else if (input_style & XIMPreeditArea) |
1393 | { |
1412 | { |
1394 | im_set_color (&fg, &bg); |
1413 | im_set_color (fg, bg); |
1395 | |
1414 | |
1396 | /* |
1415 | /* |
1397 | * The necessary width of preedit area is unknown |
1416 | * The necessary width of preedit area is unknown |
1398 | * until create input context. |
1417 | * until create input context. |
1399 | */ |
1418 | */ |
1400 | needed_rect.width = 0; |
1419 | needed_rect.width = 0; |
1401 | |
|
|
1402 | im_set_preedit_area (&rect, &status_rect, &needed_rect); |
1420 | im_set_preedit_area (rect, status_rect, needed_rect); |
1403 | |
1421 | |
1404 | preedit_attr = XVaCreateNestedList (0, XNArea, &rect, |
1422 | preedit_attr = XVaCreateNestedList (0, |
|
|
1423 | XNForeground, fg, |
1405 | 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, |
1406 | //XNFontSet, TermWin.fontset, |
1432 | XNFontSet, fs, |
1407 | NULL); |
1433 | NULL); |
1408 | status_attr = XVaCreateNestedList (0, XNArea, &status_rect, |
|
|
1409 | XNForeground, fg, XNBackground, bg, |
|
|
1410 | //XNFontSet, TermWin.fontset, |
|
|
1411 | NULL); |
|
|
1412 | } |
1434 | } |
1413 | |
1435 | |
1414 | Input_Context = XCreateIC (xim, XNInputStyle, input_style, |
1436 | Input_Context = XCreateIC (xim, |
|
|
1437 | XNInputStyle, input_style, |
1415 | XNClientWindow, TermWin.parent[0], |
1438 | XNClientWindow, TermWin.vt, |
1416 | XNFocusWindow, TermWin.parent[0], |
1439 | XNFocusWindow, TermWin.parent[0], |
1417 | preedit_attr ? XNPreeditAttributes : NULL, |
1440 | preedit_attr ? XNPreeditAttributes : NULL, |
1418 | preedit_attr, |
1441 | preedit_attr, |
1419 | status_attr ? XNStatusAttributes : NULL, |
1442 | status_attr ? XNStatusAttributes : NULL, |
1420 | status_attr, NULL); |
1443 | status_attr, NULL); |
|
|
1444 | |
1421 | if (preedit_attr) XFree (preedit_attr); |
1445 | if (preedit_attr) XFree (preedit_attr); |
1422 | if (status_attr) XFree (status_attr); |
1446 | if (status_attr) XFree (status_attr); |
|
|
1447 | if (fs) XFreeFontSet (display->display, fs); |
1423 | |
1448 | |
1424 | if (Input_Context == NULL) |
1449 | if (Input_Context == NULL) |
1425 | { |
1450 | { |
1426 | rxvt_warn ("failed to create input context, continuing without XIM.\n"); |
1451 | rxvt_warn ("failed to create input context, continuing without XIM.\n"); |
1427 | display->put_xim (input_method); |
1452 | im_destroy (); |
1428 | return false; |
1453 | return false; |
1429 | } |
1454 | } |
1430 | |
1455 | |
1431 | if (input_style & XIMPreeditArea) |
1456 | if (input_style & XIMPreeditArea) |
1432 | IMSetStatusPosition (); |
1457 | IMSetStatusPosition (); |
… | |
… | |
1462 | s = rxvt_splitcommastring (p); |
1487 | s = rxvt_splitcommastring (p); |
1463 | for (i = 0; s[i]; i++) |
1488 | for (i = 0; s[i]; i++) |
1464 | { |
1489 | { |
1465 | if (*s[i]) |
1490 | if (*s[i]) |
1466 | { |
1491 | { |
1467 | STRCPY (buf, "@im="); |
1492 | strcpy (buf, "@im="); |
1468 | STRNCAT (buf, s[i], IMBUFSIZ - 5); |
1493 | strncat (buf, s[i], IMBUFSIZ - 5); |
1469 | if (IM_get_IC (buf)) |
1494 | if (IM_get_IC (buf)) |
1470 | { |
1495 | { |
1471 | found = true; |
1496 | found = true; |
1472 | break; |
1497 | break; |
1473 | } |
1498 | } |
… | |
… | |
1497 | } |
1522 | } |
1498 | |
1523 | |
1499 | void |
1524 | void |
1500 | rxvt_term::IMSetStatusPosition () |
1525 | rxvt_term::IMSetStatusPosition () |
1501 | { |
1526 | { |
1502 | XRectangle preedit_rect, status_rect, *needed_rect; |
1527 | XRectangle preedit_rect, status_rect, *needed_rect; |
1503 | XVaNestedList preedit_attr, status_attr; |
1528 | XVaNestedList preedit_attr, status_attr; |
1504 | |
1529 | |
1505 | if (Input_Context == NULL |
1530 | if (!Input_Context |
|
|
1531 | || !TermWin.focus |
1506 | || !TermWin.focus || ! (input_style & XIMPreeditArea) |
1532 | || !(input_style & XIMPreeditArea) |
1507 | || !IMisRunning ()) |
1533 | || !IMisRunning ()) |
1508 | return; |
1534 | return; |
1509 | |
1535 | |
1510 | /* Getting the necessary width of preedit area */ |
1536 | /* Getting the necessary width of preedit area */ |
1511 | status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL); |
1537 | status_attr = XVaCreateNestedList (0, XNAreaNeeded, &needed_rect, NULL); |
1512 | XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL); |
1538 | XGetICValues (Input_Context, XNStatusAttributes, status_attr, NULL); |
1513 | XFree (status_attr); |
1539 | XFree (status_attr); |
1514 | |
1540 | |
1515 | 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); |
1516 | |
1543 | |
1517 | preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL); |
1544 | preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL); |
1518 | status_attr = XVaCreateNestedList (0, XNArea, &status_rect, NULL); |
1545 | status_attr = XVaCreateNestedList (0, XNArea, &status_rect, NULL); |
1519 | |
1546 | |
1520 | XSetICValues (Input_Context, |
1547 | XSetICValues (Input_Context, |
1521 | XNPreeditAttributes, preedit_attr, |
1548 | XNPreeditAttributes, preedit_attr, |
1522 | XNStatusAttributes, status_attr, NULL); |
1549 | XNStatusAttributes, status_attr, NULL); |
1523 | |
1550 | |
1524 | XFree (preedit_attr); |
1551 | XFree (preedit_attr); |
1525 | XFree (status_attr); |
1552 | XFree (status_attr); |
1526 | } |
1553 | } |
1527 | #endif /* USE_XIM */ |
1554 | #endif /* USE_XIM */ |