… | |
… | |
32 | |
32 | |
33 | #include "../config.h" /* NECESSARY */ |
33 | #include "../config.h" /* NECESSARY */ |
34 | #include "rxvt.h" /* NECESSARY */ |
34 | #include "rxvt.h" /* NECESSARY */ |
35 | #include "main.intpro" /* PROTOS for internal routines */ |
35 | #include "main.intpro" /* PROTOS for internal routines */ |
36 | |
36 | |
37 | #include <signal.h> |
37 | #include <csignal> |
|
|
38 | #include <cstring> |
38 | |
39 | |
39 | #ifdef TTY_GID_SUPPORT |
40 | #ifdef TTY_GID_SUPPORT |
40 | # include <grp.h> |
41 | # include <grp.h> |
41 | #endif |
42 | #endif |
42 | |
43 | |
43 | #ifdef HAVE_TERMIOS_H |
44 | #ifdef HAVE_TERMIOS_H |
44 | # include <termios.h> |
45 | # include <termios.h> |
45 | #endif |
46 | #endif |
46 | |
47 | |
47 | #include <cstring> |
48 | #ifdef KEYSYM_RESOURCE |
|
|
49 | # include "keyboard.h" |
|
|
50 | #endif |
48 | |
51 | |
49 | vector<rxvt_term *> rxvt_term::termlist; |
52 | vector<rxvt_term *> rxvt_term::termlist; |
50 | |
53 | |
51 | static char curlocale[128]; |
54 | static char curlocale[128]; |
52 | |
55 | |
… | |
… | |
155 | pointer_ev (this, &rxvt_term::pointer_cb), |
158 | pointer_ev (this, &rxvt_term::pointer_cb), |
156 | #endif |
159 | #endif |
157 | #ifdef USE_XIM |
160 | #ifdef USE_XIM |
158 | im_ev (this, &rxvt_term::im_cb), |
161 | im_ev (this, &rxvt_term::im_cb), |
159 | #endif |
162 | #endif |
|
|
163 | sw_term (this, &rxvt_term::sig_term), |
|
|
164 | sw_int (this, &rxvt_term::sig_term), |
|
|
165 | sw_chld (this, &rxvt_term::sig_chld), |
160 | termwin_ev (this, &rxvt_term::x_cb), |
166 | termwin_ev (this, &rxvt_term::x_cb), |
161 | vt_ev (this, &rxvt_term::x_cb), |
167 | vt_ev (this, &rxvt_term::x_cb), |
162 | check_ev (this, &rxvt_term::check_cb), |
168 | check_ev (this, &rxvt_term::check_cb), |
163 | flush_ev (this, &rxvt_term::flush_cb), |
169 | flush_ev (this, &rxvt_term::flush_cb), |
164 | destroy_ev (this, &rxvt_term::destroy_cb), |
170 | destroy_ev (this, &rxvt_term::destroy_cb), |
… | |
… | |
166 | incr_ev (this, &rxvt_term::incr_cb) |
172 | incr_ev (this, &rxvt_term::incr_cb) |
167 | { |
173 | { |
168 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
174 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
169 | |
175 | |
170 | termlist.push_back (this); |
176 | termlist.push_back (this); |
171 | } |
|
|
172 | |
177 | |
173 | rxvt_term::~rxvt_term () |
178 | #ifdef KEYSYM_RESOURCE |
174 | { |
179 | keyboard = new keyboard_manager; |
175 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
|
|
176 | |
180 | |
|
|
181 | if (!keyboard) |
|
|
182 | rxvt_fatal ("out of memory, aborting.\n"); |
|
|
183 | #endif |
|
|
184 | } |
|
|
185 | |
|
|
186 | // clean up the most important stuff, do *not* call x or free mem etc. |
|
|
187 | // for use before an emergency exit |
|
|
188 | void rxvt_term::emergency_cleanup () |
|
|
189 | { |
177 | if (cmd_pid) |
190 | if (cmd_pid) |
178 | kill (-cmd_pid, SIGHUP); |
191 | kill (-cmd_pid, SIGHUP); |
179 | |
192 | |
180 | pty.put (); |
|
|
181 | |
|
|
182 | #ifdef UTMP_SUPPORT |
193 | #ifdef UTMP_SUPPORT |
183 | privileged_utmp (RESTORE); |
194 | privileged_utmp (RESTORE); |
184 | #endif |
195 | #endif |
|
|
196 | |
|
|
197 | pty.put (); |
|
|
198 | } |
|
|
199 | |
|
|
200 | rxvt_term::~rxvt_term () |
|
|
201 | { |
|
|
202 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
|
|
203 | |
|
|
204 | emergency_cleanup (); |
185 | |
205 | |
186 | #if ENABLE_STYLES |
206 | #if ENABLE_STYLES |
187 | for (int i = RS_styleCount; --i; ) |
207 | for (int i = RS_styleCount; --i; ) |
188 | if (TermWin.fontset[i] != TermWin.fontset[0]) |
208 | if (TermWin.fontset[i] != TermWin.fontset[0]) |
189 | delete TermWin.fontset[i]; |
209 | delete TermWin.fontset[i]; |
190 | #endif |
210 | #endif |
191 | delete TermWin.fontset[0]; |
211 | delete TermWin.fontset[0]; |
192 | |
212 | |
193 | if (display) |
213 | if (display) |
194 | { |
214 | { |
|
|
215 | dDisp; |
|
|
216 | |
195 | selection_clear (); |
217 | selection_clear (); |
196 | |
218 | |
197 | #ifdef USE_XIM |
219 | #ifdef USE_XIM |
198 | im_destroy (); |
220 | im_destroy (); |
199 | #endif |
221 | #endif |
200 | #ifdef MENUBAR |
222 | #ifdef MENUBAR |
201 | if (menubarGC) XFreeGC (display->display, menubarGC); |
223 | if (menubarGC) XFreeGC (disp, menubarGC); |
202 | #endif |
224 | #endif |
203 | #ifdef XTERM_SCROLLBAR |
225 | #ifdef XTERM_SCROLLBAR |
204 | if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC); |
226 | if (xscrollbarGC) XFreeGC (disp, xscrollbarGC); |
205 | if (ShadowGC) XFreeGC (display->display, ShadowGC); |
227 | if (ShadowGC) XFreeGC (disp, ShadowGC); |
206 | #endif |
228 | #endif |
207 | #ifdef PLAIN_SCROLLBAR |
229 | #ifdef PLAIN_SCROLLBAR |
208 | if (pscrollbarGC) XFreeGC (display->display, pscrollbarGC); |
230 | if (pscrollbarGC) XFreeGC (disp, pscrollbarGC); |
209 | #endif |
231 | #endif |
210 | #ifdef NEXT_SCROLLBAR |
232 | #ifdef NEXT_SCROLLBAR |
211 | if (blackGC) XFreeGC (display->display, blackGC); |
233 | if (blackGC) XFreeGC (disp, blackGC); |
212 | if (whiteGC) XFreeGC (display->display, whiteGC); |
234 | if (whiteGC) XFreeGC (disp, whiteGC); |
213 | if (grayGC) XFreeGC (display->display, grayGC); |
235 | if (grayGC) XFreeGC (disp, grayGC); |
214 | if (darkGC) XFreeGC (display->display, darkGC); |
236 | if (darkGC) XFreeGC (disp, darkGC); |
215 | if (stippleGC) XFreeGC (display->display, stippleGC); |
237 | if (stippleGC) XFreeGC (disp, stippleGC); |
216 | if (dimple) XFreePixmap (display->display, dimple); |
238 | if (dimple) XFreePixmap (disp, dimple); |
217 | if (upArrow) XFreePixmap (display->display, upArrow); |
239 | if (upArrow) XFreePixmap (disp, upArrow); |
218 | if (downArrow) XFreePixmap (display->display, downArrow); |
240 | if (downArrow) XFreePixmap (disp, downArrow); |
219 | if (upArrowHi) XFreePixmap (display->display, upArrowHi); |
241 | if (upArrowHi) XFreePixmap (disp, upArrowHi); |
220 | if (downArrowHi) XFreePixmap (display->display, downArrowHi); |
242 | if (downArrowHi) XFreePixmap (disp, downArrowHi); |
221 | #endif |
243 | #endif |
222 | #if defined(MENUBAR) || defined(RXVT_SCROLLBAR) |
244 | #if defined(MENUBAR) || defined(RXVT_SCROLLBAR) |
223 | if (topShadowGC) XFreeGC (display->display, topShadowGC); |
245 | if (topShadowGC) XFreeGC (disp, topShadowGC); |
224 | if (botShadowGC) XFreeGC (display->display, botShadowGC); |
246 | if (botShadowGC) XFreeGC (disp, botShadowGC); |
225 | if (scrollbarGC) XFreeGC (display->display, scrollbarGC); |
247 | if (scrollbarGC) XFreeGC (disp, scrollbarGC); |
226 | #endif |
248 | #endif |
227 | if (TermWin.gc) XFreeGC (display->display, TermWin.gc); |
249 | if (TermWin.gc) XFreeGC (disp, TermWin.gc); |
228 | |
250 | |
229 | #if defined(MENUBAR) && (MENUBAR_MAX > 1) |
251 | #if defined(MENUBAR) && (MENUBAR_MAX > 1) |
230 | delete menuBar.drawable; |
252 | delete menuBar.drawable; |
231 | //if (menuBar.win) |
253 | //if (menuBar.win) |
232 | // XDestroyWindow (display->display, menuBar.win); |
254 | // XDestroyWindow (disp, menuBar.win); |
233 | #endif |
255 | #endif |
234 | delete TermWin.drawable; |
256 | delete TermWin.drawable; |
235 | // destroy all windows |
257 | // destroy all windows |
236 | if (TermWin.parent[0]) |
258 | if (TermWin.parent[0]) |
237 | XDestroyWindow (display->display, TermWin.parent[0]); |
259 | XDestroyWindow (disp, TermWin.parent[0]); |
238 | } |
260 | } |
239 | |
261 | |
240 | // TODO: free pixcolours, colours should become part of rxvt_display |
262 | // TODO: free pixcolours, colours should become part of rxvt_display |
241 | |
263 | |
242 | delete pix_colors_focused; |
264 | delete pix_colors_focused; |
… | |
… | |
248 | |
270 | |
249 | scr_release (); |
271 | scr_release (); |
250 | |
272 | |
251 | /* clear all resources */ |
273 | /* clear all resources */ |
252 | for (int i = 0; i < allocated.size (); i++) |
274 | for (int i = 0; i < allocated.size (); i++) |
253 | free (allocated[i]); |
275 | free (allocated [i]); |
254 | |
276 | |
255 | free (selection.text); |
277 | free (selection.text); |
256 | // TODO: manage env vars in child only(!) |
278 | // TODO: manage env vars in child only(!) |
257 | free (env_windowid); |
279 | free (env_windowid); |
258 | free (env_display); |
280 | free (env_display); |
259 | free (env_term); |
281 | free (env_term); |
260 | free (env_colorfgbg); |
282 | free (env_colorfgbg); |
261 | free (locale); |
283 | free (locale); |
262 | #if 0 |
284 | free (v_buffer); |
263 | free (codeset); |
285 | free (incr_buf); |
264 | #endif |
|
|
265 | |
286 | |
266 | delete envv; |
287 | delete envv; |
267 | delete argv; |
288 | delete argv; |
|
|
289 | |
|
|
290 | #ifdef KEYSYM_RESOURCE |
|
|
291 | delete keyboard; |
|
|
292 | #endif |
268 | } |
293 | } |
269 | |
294 | |
270 | void |
295 | void |
271 | rxvt_term::destroy () |
296 | rxvt_term::destroy () |
272 | { |
297 | { |
… | |
… | |
324 | |
349 | |
325 | delete this; |
350 | delete this; |
326 | } |
351 | } |
327 | |
352 | |
328 | /*----------------------------------------------------------------------*/ |
353 | /*----------------------------------------------------------------------*/ |
|
|
354 | /* |
|
|
355 | * Exit gracefully, clearing the utmp entry and restoring tty attributes |
|
|
356 | * TODO: if debugging, this should free up any known resources if we can |
|
|
357 | */ |
|
|
358 | static XErrorHandler old_xerror_handler; |
|
|
359 | |
|
|
360 | static void |
|
|
361 | rxvt_emergency_cleanup () |
|
|
362 | { |
|
|
363 | for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) |
|
|
364 | (*t)->emergency_cleanup (); |
|
|
365 | } |
|
|
366 | |
|
|
367 | int |
|
|
368 | rxvt_xerror_handler (Display *display, XErrorEvent *event) |
|
|
369 | { |
|
|
370 | if (GET_R->allowedxerror == -1) |
|
|
371 | GET_R->allowedxerror = event->error_code; |
|
|
372 | else |
|
|
373 | { |
|
|
374 | //TODO: GET_R is most likely not the terminal which caused the error |
|
|
375 | //TODO: maybe just output the error and continue? |
|
|
376 | old_xerror_handler (display, event); |
|
|
377 | GET_R->destroy (); |
|
|
378 | } |
|
|
379 | |
|
|
380 | return 0; |
|
|
381 | } |
|
|
382 | |
|
|
383 | int |
|
|
384 | rxvt_xioerror_handler (Display *display) |
|
|
385 | { |
|
|
386 | rxvt_warn ("X connection to '%s' broken, unable to recover, exiting.\n", |
|
|
387 | DisplayString (display)); |
|
|
388 | rxvt_emergency_cleanup (); |
|
|
389 | _exit (EXIT_FAILURE); |
|
|
390 | } |
|
|
391 | |
|
|
392 | /* |
|
|
393 | * Catch a fatal signal and tidy up before quitting |
|
|
394 | */ |
|
|
395 | void |
|
|
396 | rxvt_term::sig_term (sig_watcher &w) |
|
|
397 | { |
|
|
398 | #ifdef DEBUG_CMD |
|
|
399 | rxvt_warn ("caught signal %d, exiting.\n", w.signum); |
|
|
400 | #endif |
|
|
401 | rxvt_emergency_cleanup (); |
|
|
402 | signal (w.signum, SIG_DFL); |
|
|
403 | kill (getpid (), w.signum); |
|
|
404 | } |
|
|
405 | |
|
|
406 | /*----------------------------------------------------------------------*/ |
329 | /* rxvt_init () */ |
407 | /* rxvt_init () */ |
330 | bool |
408 | bool |
331 | rxvt_term::init (int argc, const char *const *argv) |
409 | rxvt_term::init (int argc, const char *const *argv) |
332 | { |
410 | { |
333 | SET_R (this); |
411 | SET_R (this); |
334 | |
412 | |
|
|
413 | set_locale (""); |
|
|
414 | |
335 | if (!init_vars ()) |
415 | if (!init_vars ()) |
336 | return false; |
416 | return false; |
337 | |
417 | |
338 | init_secondary (); |
418 | init_secondary (); |
339 | |
419 | |
340 | const char **cmd_argv = init_resources (argc, argv); |
420 | const char **cmd_argv = init_resources (argc, argv); |
341 | |
421 | |
342 | set_locale (""); |
422 | #ifdef KEYSYM_RESOURCE |
|
|
423 | keyboard->register_done (); |
|
|
424 | #endif |
343 | |
425 | |
344 | #if MENUBAR_MAX |
426 | #if MENUBAR_MAX |
345 | menubar_read (rs[Rs_menu]); |
427 | menubar_read (rs[Rs_menu]); |
346 | #endif |
428 | #endif |
347 | #ifdef HAVE_SCROLLBARS |
429 | #ifdef HAVE_SCROLLBARS |
… | |
… | |
349 | scrollBar.setIdle (); /* set existence for size calculations */ |
431 | scrollBar.setIdle (); /* set existence for size calculations */ |
350 | #endif |
432 | #endif |
351 | |
433 | |
352 | create_windows (argc, argv); |
434 | create_windows (argc, argv); |
353 | |
435 | |
|
|
436 | dDisp; |
|
|
437 | |
354 | init_xlocale (); |
438 | init_xlocale (); |
355 | |
439 | |
356 | scr_reset (); /* initialize screen */ |
440 | scr_reset (); /* initialize screen */ |
357 | |
441 | |
358 | #if 0 |
442 | #if 0 |
359 | XSynchronize (display->display, True); |
443 | XSynchronize (disp, True); |
360 | #endif |
444 | #endif |
361 | |
445 | |
362 | #ifdef HAVE_SCROLLBARS |
446 | #ifdef HAVE_SCROLLBARS |
363 | if (options & Opt_scrollBar) |
447 | if (options & Opt_scrollBar) |
364 | resize_scrollbar (); /* create and map scrollbar */ |
448 | resize_scrollbar (); /* create and map scrollbar */ |
365 | #endif |
449 | #endif |
366 | #if (MENUBAR_MAX) |
450 | #if (MENUBAR_MAX) |
367 | if (menubar_visible ()) |
451 | if (menubar_visible ()) |
368 | XMapWindow (display->display, menuBar.win); |
452 | XMapWindow (disp, menuBar.win); |
369 | #endif |
453 | #endif |
370 | #ifdef TRANSPARENT |
454 | #ifdef TRANSPARENT |
371 | if (options & Opt_transparent) |
455 | if (options & Opt_transparent) |
372 | { |
456 | { |
373 | XSelectInput (display->display, display->root, PropertyChangeMask); |
457 | XSelectInput (disp, display->root, PropertyChangeMask); |
374 | check_our_parents (); |
458 | check_our_parents (); |
375 | rootwin_ev.start (display, display->root); |
459 | rootwin_ev.start (display, display->root); |
376 | } |
460 | } |
377 | #endif |
461 | #endif |
378 | |
462 | |
379 | XMapWindow (display->display, TermWin.vt); |
463 | XMapWindow (disp, TermWin.vt); |
380 | XMapWindow (display->display, TermWin.parent[0]); |
464 | XMapWindow (disp, TermWin.parent[0]); |
381 | |
465 | |
382 | set_colorfgbg (); |
466 | set_colorfgbg (); |
383 | |
467 | |
384 | init_command (cmd_argv); |
468 | init_command (cmd_argv); |
385 | |
469 | |
|
|
470 | free (cmd_argv); |
|
|
471 | |
386 | pty_ev.start (pty.pty, EVENT_READ); |
472 | pty_ev.start (pty.pty, EVENT_READ); |
387 | |
473 | |
388 | check_ev.start (); |
474 | check_ev.start (); |
389 | |
475 | |
390 | return true; |
476 | return true; |
391 | } |
477 | } |
392 | |
478 | |
393 | static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event); |
|
|
394 | |
|
|
395 | void |
479 | void |
396 | rxvt_init () |
480 | rxvt_init () |
397 | { |
481 | { |
398 | /* install exit handler for cleanup */ |
|
|
399 | #if 0 |
|
|
400 | #ifdef HAVE_ATEXIT |
|
|
401 | atexit (rxvt_clean_exit); |
|
|
402 | #else |
|
|
403 | #endif |
|
|
404 | #endif |
|
|
405 | /* |
482 | /* |
406 | * Save and then give up any super-user privileges |
483 | * Save and then give up any super-user privileges |
407 | * If we need privileges in any area then we must specifically request it. |
484 | * If we need privileges in any area then we must specifically request it. |
408 | * We should only need to be root in these cases: |
485 | * We should only need to be root in these cases: |
409 | * 1. write utmp entries on some systems |
486 | * 1. write utmp entries on some systems |
410 | * 2. chown tty on some systems |
487 | * 2. chown tty on some systems |
411 | */ |
488 | */ |
412 | rxvt_privileges (SAVE); |
489 | rxvt_privileges (SAVE); |
413 | rxvt_privileges (IGNORE); |
490 | rxvt_privileges (IGNORE); |
414 | |
491 | |
415 | struct sigaction sa; |
492 | signal (SIGHUP, SIG_IGN); |
416 | |
493 | signal (SIGPIPE, SIG_IGN); |
417 | sigfillset (&sa.sa_mask); |
|
|
418 | sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; |
|
|
419 | sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0); |
|
|
420 | sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0); |
|
|
421 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0); |
|
|
422 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0); |
|
|
423 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0); |
|
|
424 | sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0); |
|
|
425 | |
494 | |
426 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
495 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
427 | /* signal (SIGURG, SIG_DFL); */ |
496 | /* signal (SIGURG, SIG_DFL); */ |
428 | |
497 | |
429 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
498 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
|
|
499 | // TODO: handle this with exceptions and tolerate the memory loss |
430 | //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); |
500 | XSetIOErrorHandler (rxvt_xioerror_handler); |
431 | } |
501 | } |
432 | |
502 | |
433 | /* ------------------------------------------------------------------------- * |
503 | /* ------------------------------------------------------------------------- * |
434 | * SIGNAL HANDLING & EXIT HANDLER * |
504 | * SIGNAL HANDLING & EXIT HANDLER * |
435 | * ------------------------------------------------------------------------- */ |
505 | * ------------------------------------------------------------------------- */ |
436 | /* |
506 | /* |
437 | * Catch a SIGCHLD signal and exit if the direct child has died |
507 | * Catch a SIGCHLD signal and exit if the direct child has died |
438 | */ |
508 | */ |
439 | |
509 | |
440 | void rxvt_term::child_exited (int pid) |
510 | void |
|
|
511 | rxvt_term::sig_chld (sig_watcher &w) |
441 | { |
512 | { |
442 | for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++) |
513 | // we are being called for every SIGCHLD, not just ours |
443 | if (pid == (*t)->cmd_pid) |
514 | int pid; |
444 | { |
|
|
445 | (*t)->destroy (); |
|
|
446 | break; |
|
|
447 | } |
|
|
448 | } |
|
|
449 | |
|
|
450 | /* ARGSUSED */ |
|
|
451 | /* INTPROTO */ |
|
|
452 | RETSIGTYPE |
|
|
453 | rxvt_Child_signal (int sig __attribute__ ((unused))) |
|
|
454 | { |
|
|
455 | int pid, save_errno = errno; |
|
|
456 | |
515 | |
457 | while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) |
516 | while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) |
458 | rxvt_term::child_exited (pid); |
517 | for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++) |
459 | |
518 | if (pid == (*t)->cmd_pid) |
460 | errno = save_errno; |
519 | { |
461 | } |
520 | (*t)->destroy (); |
462 | |
521 | break; |
463 | /* |
522 | } |
464 | * Catch a fatal signal and tidy up before quitting |
|
|
465 | */ |
|
|
466 | /* INTPROTO */ |
|
|
467 | RETSIGTYPE |
|
|
468 | rxvt_Exit_signal (int sig) |
|
|
469 | { |
|
|
470 | signal (sig, SIG_DFL); |
|
|
471 | #ifdef DEBUG_CMD |
|
|
472 | rxvt_warn ("caught signal %d, exiting.\n", sig); |
|
|
473 | #endif |
|
|
474 | rxvt_clean_exit (); |
|
|
475 | kill (getpid (), sig); |
|
|
476 | } |
|
|
477 | |
|
|
478 | /* INTPROTO */ |
|
|
479 | int |
|
|
480 | rxvt_xerror_handler (Display *display, XErrorEvent *event) |
|
|
481 | { |
|
|
482 | if (GET_R->allowedxerror == -1) |
|
|
483 | GET_R->allowedxerror = event->error_code; |
|
|
484 | else |
|
|
485 | { |
|
|
486 | old_xerror_handler (display, event); |
|
|
487 | GET_R->destroy (); |
|
|
488 | } |
|
|
489 | |
|
|
490 | return 0; |
|
|
491 | } |
|
|
492 | |
|
|
493 | /*----------------------------------------------------------------------*/ |
|
|
494 | /* |
|
|
495 | * Exit gracefully, clearing the utmp entry and restoring tty attributes |
|
|
496 | * TODO: if debugging, this should free up any known resources if we can |
|
|
497 | */ |
|
|
498 | /* INTPROTO */ |
|
|
499 | void |
|
|
500 | rxvt_clean_exit () |
|
|
501 | { |
|
|
502 | // TODO: rxvtd should clean up all ressources |
|
|
503 | if (GET_R) |
|
|
504 | GET_R->destroy (); |
|
|
505 | } |
523 | } |
506 | |
524 | |
507 | /* ------------------------------------------------------------------------- * |
525 | /* ------------------------------------------------------------------------- * |
508 | * MEMORY ALLOCATION WRAPPERS * |
526 | * MEMORY ALLOCATION WRAPPERS * |
509 | * ------------------------------------------------------------------------- */ |
527 | * ------------------------------------------------------------------------- */ |
510 | /* INTPROTO */ |
528 | void * |
511 | void * |
|
|
512 | rxvt_malloc (size_t size) |
529 | rxvt_malloc (size_t size) |
513 | { |
530 | { |
514 | void *p; |
|
|
515 | |
|
|
516 | p = malloc (size); |
531 | void *p = malloc (size); |
|
|
532 | |
517 | if (p) |
533 | if (!p) |
518 | return p; |
|
|
519 | |
|
|
520 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
534 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
521 | /* NOTREACHED */ |
535 | |
|
|
536 | return p; |
522 | } |
537 | } |
523 | |
538 | |
524 | /* INTPROTO */ |
539 | /* INTPROTO */ |
525 | void * |
540 | void * |
526 | rxvt_calloc (size_t number, size_t size) |
541 | rxvt_calloc (size_t number, size_t size) |
527 | { |
542 | { |
528 | void *p; |
|
|
529 | |
|
|
530 | p = calloc (number, size); |
543 | void *p = calloc (number, size); |
|
|
544 | |
531 | if (p) |
545 | if (!p) |
532 | return p; |
|
|
533 | |
|
|
534 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
546 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
535 | /* NOTREACHED */ |
547 | |
|
|
548 | return p; |
536 | } |
549 | } |
537 | |
550 | |
538 | /* INTPROTO */ |
551 | /* INTPROTO */ |
539 | void * |
552 | void * |
540 | rxvt_realloc (void *ptr, size_t size) |
553 | rxvt_realloc (void *ptr, size_t size) |
541 | { |
554 | { |
542 | void *p; |
|
|
543 | |
|
|
544 | if (ptr) |
|
|
545 | p = realloc (ptr, size); |
555 | void *p = realloc (ptr, size); |
546 | else |
|
|
547 | p = malloc (size); |
|
|
548 | |
556 | |
549 | if (p) |
557 | if (!p) |
550 | return p; |
|
|
551 | |
|
|
552 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
558 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
553 | /* NOTREACHED */ |
559 | |
|
|
560 | return p; |
554 | } |
561 | } |
555 | |
562 | |
556 | /* ------------------------------------------------------------------------- * |
563 | /* ------------------------------------------------------------------------- * |
557 | * PRIVILEGED OPERATIONS * |
564 | * PRIVILEGED OPERATIONS * |
558 | * ------------------------------------------------------------------------- */ |
565 | * ------------------------------------------------------------------------- */ |
… | |
… | |
633 | * if width/height are non-zero then override calculated width/height |
640 | * if width/height are non-zero then override calculated width/height |
634 | */ |
641 | */ |
635 | void |
642 | void |
636 | rxvt_term::window_calc (unsigned int width, unsigned int height) |
643 | rxvt_term::window_calc (unsigned int width, unsigned int height) |
637 | { |
644 | { |
638 | short recalc_x, recalc_y; |
645 | short recalc_x, recalc_y; |
639 | int x, y, sb_w, mb_h, flags; |
646 | int x, y, sb_w, mb_h, flags; |
640 | unsigned int w, h; |
647 | unsigned int w, h; |
641 | unsigned int max_width, max_height; |
648 | unsigned int max_width, max_height; |
|
|
649 | dDisp; |
642 | |
650 | |
643 | D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
651 | D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
644 | TermWin.ncol, TermWin.nrow, szHint.width, |
652 | TermWin.ncol, TermWin.nrow, szHint.width, |
645 | szHint.height)); |
653 | szHint.height)); |
646 | szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; |
654 | szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; |
… | |
… | |
744 | |
752 | |
745 | if (scrollbar_visible () && (options & Opt_scrollBar_right)) |
753 | if (scrollbar_visible () && (options & Opt_scrollBar_right)) |
746 | window_sb_x = szHint.width - sb_w; |
754 | window_sb_x = szHint.width - sb_w; |
747 | |
755 | |
748 | if (recalc_x) |
756 | if (recalc_x) |
749 | szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) |
757 | szHint.x += (DisplayWidth (disp, display->screen) |
750 | - szHint.width - 2 * TermWin.ext_bwidth); |
758 | - szHint.width - 2 * TermWin.ext_bwidth); |
751 | if (recalc_y) |
759 | if (recalc_y) |
752 | szHint.y += (DisplayHeight (display->display, DefaultScreen (display->display)) |
760 | szHint.y += (DisplayHeight (disp, display->screen) |
753 | - szHint.height - 2 * TermWin.ext_bwidth); |
761 | - szHint.height - 2 * TermWin.ext_bwidth); |
754 | |
762 | |
755 | TermWin.ncol = TermWin.width / TermWin.fwidth; |
763 | TermWin.ncol = TermWin.width / TermWin.fwidth; |
756 | TermWin.nrow = TermWin.height / TermWin.fheight; |
764 | TermWin.nrow = TermWin.height / TermWin.fheight; |
757 | D_SIZE ((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
765 | D_SIZE ((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
… | |
… | |
798 | rxvt_term::set_fonts () |
806 | rxvt_term::set_fonts () |
799 | { |
807 | { |
800 | rxvt_fontset *fs = new rxvt_fontset (this); |
808 | rxvt_fontset *fs = new rxvt_fontset (this); |
801 | rxvt_fontprop prop; |
809 | rxvt_fontprop prop; |
802 | |
810 | |
803 | prop.width = prop.height = prop.weight = prop.slant |
|
|
804 | = rxvt_fontprop::unset; |
|
|
805 | |
|
|
806 | if (!fs |
811 | if (!fs |
807 | || !fs->populate (rs[Rs_font] ? rs[Rs_font] : "fixed", prop) |
812 | || !fs->populate (rs[Rs_font] ? rs[Rs_font] : "fixed") |
808 | || !fs->realize_font (1)) |
813 | || !fs->realize_font (1)) |
809 | { |
814 | { |
810 | delete fs; |
815 | delete fs; |
811 | return false; |
816 | return false; |
812 | } |
817 | } |
… | |
… | |
818 | #endif |
823 | #endif |
819 | |
824 | |
820 | delete TermWin.fontset[0]; |
825 | delete TermWin.fontset[0]; |
821 | TermWin.fontset[0] = fs; |
826 | TermWin.fontset[0] = fs; |
822 | |
827 | |
823 | fs->prop = prop = (*fs)[1]->properties (); |
828 | prop = (*fs)[1]->properties (); |
|
|
829 | prop.height += TermWin.lineSpace; |
|
|
830 | fs->set_prop (prop); |
824 | |
831 | |
825 | TermWin.fwidth = prop.width; |
832 | TermWin.fwidth = prop.width; |
826 | TermWin.fheight = prop.height; |
833 | TermWin.fheight = prop.height; |
827 | TermWin.fweight = prop.weight; |
834 | TermWin.fweight = prop.weight; |
828 | TermWin.fslant = prop.slant; |
835 | TermWin.fslant = prop.slant; |
… | |
… | |
848 | |
855 | |
849 | if (SET_STYLE (0, style) & RS_Bold) prop2.weight = rxvt_fontprop::bold; |
856 | if (SET_STYLE (0, style) & RS_Bold) prop2.weight = rxvt_fontprop::bold; |
850 | if (SET_STYLE (0, style) & RS_Italic) prop2.slant = rxvt_fontprop::italic; |
857 | if (SET_STYLE (0, style) & RS_Italic) prop2.slant = rxvt_fontprop::italic; |
851 | } |
858 | } |
852 | |
859 | |
853 | fs->populate (res, prop2); |
860 | fs->populate (res); |
|
|
861 | fs->set_prop (prop2); |
854 | } |
862 | } |
855 | #else |
863 | #else |
856 | TermWin.fontset[style] = TermWin.fontset[0]; |
864 | TermWin.fontset[style] = TermWin.fontset[0]; |
857 | #endif |
865 | #endif |
858 | } |
866 | } |
… | |
… | |
865 | } |
873 | } |
866 | |
874 | |
867 | return true; |
875 | return true; |
868 | } |
876 | } |
869 | |
877 | |
|
|
878 | void rxvt_term::set_string_property (Atom prop, const char *str, int len) |
|
|
879 | { |
|
|
880 | // TODO: SMART_WINDOW_TITLE |
|
|
881 | XChangeProperty (display->display, TermWin.parent[0], |
|
|
882 | prop, XA_STRING, 8, PropModeReplace, |
|
|
883 | (const unsigned char *)str, len >= 0 ? len : strlen (str)); |
|
|
884 | } |
|
|
885 | |
|
|
886 | void rxvt_term::set_utf8_property (Atom prop, const char *str, int len) |
|
|
887 | { |
|
|
888 | // TODO: SMART_WINDOW_TITLE |
|
|
889 | wchar_t *ws = rxvt_mbstowcs (str, len); |
|
|
890 | char *s = rxvt_wcstoutf8 (ws); |
|
|
891 | |
|
|
892 | XChangeProperty (display->display, TermWin.parent[0], |
|
|
893 | prop, xa[XA_UTF8_STRING], 8, PropModeReplace, |
|
|
894 | (const unsigned char *)s, strlen (s)); |
|
|
895 | |
|
|
896 | free (s); |
|
|
897 | free (ws); |
|
|
898 | } |
|
|
899 | |
870 | /*----------------------------------------------------------------------*/ |
900 | /*----------------------------------------------------------------------*/ |
871 | /*----------------------------------------------------------------------*/ |
901 | /*----------------------------------------------------------------------*/ |
872 | /* xterm sequences - title, iconName, color (exptl) */ |
902 | /* xterm sequences - title, iconName, color (exptl) */ |
873 | void |
903 | void |
874 | rxvt_term::set_title (const char *str) |
904 | rxvt_term::set_title (const char *str) |
875 | { |
905 | { |
876 | #ifdef SMART_WINDOW_TITLE |
906 | set_string_property (XA_WM_NAME, str); |
877 | char *name; |
907 | #if ENABLE_FRILLS |
878 | |
908 | set_utf8_property (xa[XA_NET_WM_NAME], str); |
879 | if (!XFetchName (display->display, TermWin.parent[0], &name)) |
|
|
880 | name = NULL; |
|
|
881 | |
|
|
882 | if (name == NULL || strcmp (name, str)) |
|
|
883 | #endif |
|
|
884 | XStoreName (display->display, TermWin.parent[0], str); |
|
|
885 | |
|
|
886 | #ifdef SMART_WINDOW_TITLE |
|
|
887 | if (name) |
|
|
888 | XFree (name); |
|
|
889 | #endif |
909 | #endif |
890 | } |
910 | } |
891 | |
911 | |
892 | void |
912 | void |
893 | rxvt_term::set_icon_name (const char *str) |
913 | rxvt_term::set_icon_name (const char *str) |
894 | { |
914 | { |
895 | #ifdef SMART_WINDOW_TITLE |
915 | set_string_property (XA_WM_ICON_NAME, str); |
896 | char *name; |
916 | #if ENABLE_FRILLS |
897 | |
917 | set_utf8_property (xa[XA_NET_WM_ICON_NAME], str); |
898 | if (!XGetIconName (display->display, TermWin.parent[0], &name)) |
|
|
899 | name = NULL; |
|
|
900 | |
|
|
901 | if (name == NULL || strcmp (name, str)) |
|
|
902 | #endif |
|
|
903 | XSetIconName (display->display, TermWin.parent[0], str); |
|
|
904 | |
|
|
905 | #ifdef SMART_WINDOW_TITLE |
|
|
906 | if (name) |
|
|
907 | XFree (name); |
|
|
908 | #endif |
918 | #endif |
909 | } |
919 | } |
910 | |
920 | |
911 | #ifdef XTERM_COLOR_CHANGE |
921 | #ifdef XTERM_COLOR_CHANGE |
912 | void |
922 | void |
… | |
… | |
920 | |
930 | |
921 | /* handle color aliases */ |
931 | /* handle color aliases */ |
922 | if (isdigit (*color)) |
932 | if (isdigit (*color)) |
923 | { |
933 | { |
924 | i = atoi (color); |
934 | i = atoi (color); |
|
|
935 | |
925 | if (i >= 8 && i <= 15) |
936 | if (i >= 8 && i <= 15) |
926 | { /* bright colors */ |
937 | { /* bright colors */ |
927 | i -= 8; |
938 | i -= 8; |
928 | # ifndef NO_BRIGHTCOLOR |
939 | # ifndef NO_BRIGHTCOLOR |
929 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
940 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
930 | SET_PIXCOLOR (idx); |
941 | SET_PIXCOLOR (idx); |
931 | goto Done; |
942 | goto Done; |
932 | # endif |
943 | # endif |
933 | |
|
|
934 | } |
944 | } |
|
|
945 | |
935 | if (i >= 0 && i <= 7) |
946 | if (i >= 0 && i <= 7) |
936 | { /* normal colors */ |
947 | { /* normal colors */ |
937 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
948 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
938 | SET_PIXCOLOR (idx); |
949 | SET_PIXCOLOR (idx); |
939 | goto Done; |
950 | goto Done; |
940 | } |
951 | } |
941 | } |
952 | } |
942 | |
953 | |
943 | if (!rXParseAllocColor (& xcol, color)) |
954 | if (!rXParseAllocColor (&xcol, color)) |
944 | return; |
955 | return; |
945 | |
956 | |
946 | /* XStoreColor (display->display, display->cmap, XColor*); */ |
957 | /* XStoreColor (display->display, display->cmap, XColor*); */ |
947 | |
958 | |
948 | /* |
959 | /* |
… | |
… | |
1031 | |
1042 | |
1032 | sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); |
1043 | sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); |
1033 | } |
1044 | } |
1034 | |
1045 | |
1035 | /*----------------------------------------------------------------------*/ |
1046 | /*----------------------------------------------------------------------*/ |
1036 | /* |
|
|
1037 | * Colour determination for low colour displays, routine from |
|
|
1038 | * Hans de Goede <hans@highrise.nl> |
|
|
1039 | */ |
|
|
1040 | |
1047 | |
1041 | int |
1048 | int |
1042 | rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) |
1049 | rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) |
1043 | { |
1050 | { |
1044 | if (!screen_in_out->set (display, colour)) |
1051 | if (!screen_in_out->set (display, colour)) |
… | |
… | |
1055 | * -------------------------------------------------------------------- */ |
1062 | * -------------------------------------------------------------------- */ |
1056 | void |
1063 | void |
1057 | rxvt_term::resize_all_windows (unsigned int width, unsigned int height, int ignoreparent) |
1064 | rxvt_term::resize_all_windows (unsigned int width, unsigned int height, int ignoreparent) |
1058 | { |
1065 | { |
1059 | int fix_screen; |
1066 | int fix_screen; |
1060 | |
|
|
1061 | #ifdef SMART_RESIZE |
1067 | #ifdef SMART_RESIZE |
1062 | int old_width = szHint.width, old_height = szHint.height; |
1068 | int old_width = szHint.width, old_height = szHint.height; |
1063 | #endif |
1069 | #endif |
|
|
1070 | dDisp; |
1064 | |
1071 | |
1065 | window_calc (width, height); |
1072 | window_calc (width, height); |
1066 | XSetWMNormalHints (display->display, TermWin.parent[0], &szHint); |
1073 | XSetWMNormalHints (disp, TermWin.parent[0], &szHint); |
1067 | |
1074 | |
1068 | if (!ignoreparent) |
1075 | if (!ignoreparent) |
1069 | { |
1076 | { |
1070 | #ifdef SMART_RESIZE |
1077 | #ifdef SMART_RESIZE |
1071 | /* |
1078 | /* |
… | |
… | |
1075 | int x, y, x1, y1; |
1082 | int x, y, x1, y1; |
1076 | int dx, dy; |
1083 | int dx, dy; |
1077 | unsigned int unused_w1, unused_h1, unused_b1, unused_d1; |
1084 | unsigned int unused_w1, unused_h1, unused_b1, unused_d1; |
1078 | Window unused_cr; |
1085 | Window unused_cr; |
1079 | |
1086 | |
1080 | XTranslateCoordinates (display->display, TermWin.parent[0], display->root, |
1087 | XTranslateCoordinates (disp, TermWin.parent[0], display->root, |
1081 | 0, 0, &x, &y, &unused_cr); |
1088 | 0, 0, &x, &y, &unused_cr); |
1082 | XGetGeometry (display->display, TermWin.parent[0], &unused_cr, &x1, &y1, |
1089 | XGetGeometry (disp, TermWin.parent[0], &unused_cr, &x1, &y1, |
1083 | &unused_w1, &unused_h1, &unused_b1, &unused_d1); |
1090 | &unused_w1, &unused_h1, &unused_b1, &unused_d1); |
1084 | /* |
1091 | /* |
1085 | * if display->root isn't the parent window, a WM will probably have offset |
1092 | * if display->root isn't the parent window, a WM will probably have offset |
1086 | * our position for handles and decorations. Counter it |
1093 | * our position for handles and decorations. Counter it |
1087 | */ |
1094 | */ |
… | |
… | |
1089 | { |
1096 | { |
1090 | x -= x1; |
1097 | x -= x1; |
1091 | y -= y1; |
1098 | y -= y1; |
1092 | } |
1099 | } |
1093 | |
1100 | |
1094 | x1 = (DisplayWidth (display->display, display->screen) - old_width) / 2; |
1101 | x1 = (DisplayWidth (disp, display->screen) - old_width) / 2; |
1095 | y1 = (DisplayHeight (display->display, display->screen) - old_height) / 2; |
1102 | y1 = (DisplayHeight (disp, display->screen) - old_height) / 2; |
1096 | dx = old_width - szHint.width; |
1103 | dx = old_width - szHint.width; |
1097 | dy = old_height - szHint.height; |
1104 | dy = old_height - szHint.height; |
1098 | |
1105 | |
1099 | /* Check position of the center of the window */ |
1106 | /* Check position of the center of the window */ |
1100 | if (x < x1) /* left half */ |
1107 | if (x < x1) /* left half */ |
… | |
… | |
1104 | if (y < y1) /* top half */ |
1111 | if (y < y1) /* top half */ |
1105 | dy = 0; |
1112 | dy = 0; |
1106 | else if (y == y1) /* exact center */ |
1113 | else if (y == y1) /* exact center */ |
1107 | dy /= 2; |
1114 | dy /= 2; |
1108 | |
1115 | |
1109 | XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy, |
1116 | XMoveResizeWindow (disp, TermWin.parent[0], x + dx, y + dy, |
1110 | szHint.width, szHint.height); |
1117 | szHint.width, szHint.height); |
1111 | #else |
1118 | #else |
1112 | XResizeWindow (display->display, TermWin.parent[0], szHint.width, szHint.height); |
1119 | XResizeWindow (disp, TermWin.parent[0], szHint.width, szHint.height); |
1113 | #endif |
1120 | #endif |
1114 | } |
1121 | } |
1115 | |
1122 | |
1116 | fix_screen = TermWin.ncol != prev_ncol || TermWin.nrow != prev_nrow; |
1123 | fix_screen = TermWin.ncol != prev_ncol || TermWin.nrow != prev_nrow; |
1117 | |
1124 | |
1118 | if (fix_screen || width != old_width || height != old_height) |
1125 | if (fix_screen || width != old_width || height != old_height) |
1119 | { |
1126 | { |
1120 | if (scrollbar_visible ()) |
1127 | if (scrollbar_visible ()) |
1121 | { |
1128 | { |
1122 | XMoveResizeWindow (display->display, scrollBar.win, |
1129 | XMoveResizeWindow (disp, scrollBar.win, |
1123 | window_sb_x, 0, |
1130 | window_sb_x, 0, |
1124 | scrollbar_TotalWidth (), szHint.height); |
1131 | scrollbar_TotalWidth (), szHint.height); |
1125 | resize_scrollbar (); |
1132 | resize_scrollbar (); |
1126 | } |
1133 | } |
1127 | |
1134 | |
1128 | if (menubar_visible ()) |
1135 | if (menubar_visible ()) |
1129 | XMoveResizeWindow (display->display, menuBar.win, |
1136 | XMoveResizeWindow (disp, menuBar.win, |
1130 | window_vt_x, 0, |
1137 | window_vt_x, 0, |
1131 | TermWin_TotalWidth (), menuBar_TotalHeight ()); |
1138 | TermWin_TotalWidth (), menuBar_TotalHeight ()); |
1132 | |
1139 | |
1133 | XMoveResizeWindow (display->display, TermWin.vt, |
1140 | XMoveResizeWindow (disp, TermWin.vt, |
1134 | window_vt_x, window_vt_y, |
1141 | window_vt_x, window_vt_y, |
1135 | TermWin_TotalWidth (), TermWin_TotalHeight ()); |
1142 | TermWin_TotalWidth (), TermWin_TotalHeight ()); |
|
|
1143 | |
1136 | scr_clear (); |
1144 | scr_clear (); |
1137 | #ifdef XPM_BACKGROUND |
1145 | #ifdef XPM_BACKGROUND |
1138 | resize_pixmap (); |
1146 | resize_pixmap (); |
1139 | #endif |
1147 | #endif |
1140 | } |
1148 | } |
… | |
… | |
1163 | } |
1171 | } |
1164 | |
1172 | |
1165 | old_width = szHint.width; |
1173 | old_width = szHint.width; |
1166 | old_height = szHint.height; |
1174 | old_height = szHint.height; |
1167 | |
1175 | |
|
|
1176 | #ifdef XPM_BACKGROUND |
|
|
1177 | if (TermWin.pixmap) |
|
|
1178 | scr_touch (false); |
|
|
1179 | #endif |
|
|
1180 | |
1168 | #ifdef USE_XIM |
1181 | #ifdef USE_XIM |
1169 | IMSetStatusPosition (); |
1182 | IMSetStatusPosition (); |
1170 | #endif |
1183 | #endif |
1171 | } |
1184 | } |
1172 | |
1185 | |
… | |
… | |
1263 | } |
1276 | } |
1264 | |
1277 | |
1265 | void |
1278 | void |
1266 | rxvt_term::IMSendSpot () |
1279 | rxvt_term::IMSendSpot () |
1267 | { |
1280 | { |
1268 | XPoint spot; |
1281 | XPoint nspot; |
1269 | XVaNestedList preedit_attr; |
1282 | XVaNestedList preedit_attr; |
1270 | |
1283 | |
1271 | if (!Input_Context |
1284 | if (!Input_Context |
1272 | || !TermWin.focus |
1285 | || !TermWin.focus |
1273 | || !(input_style & XIMPreeditPosition) |
1286 | || !(input_style & XIMPreeditPosition)) |
1274 | #if 0 |
|
|
1275 | || !(event_type == KeyPress |
|
|
1276 | || event_type == Expose |
|
|
1277 | || event_type == NoExpose |
|
|
1278 | || event_type == SelectionNotify |
|
|
1279 | || event_type == ButtonRelease || event_type == FocusIn) |
|
|
1280 | #endif |
|
|
1281 | || !IMisRunning ()) |
|
|
1282 | return; |
1287 | return; |
1283 | |
1288 | |
1284 | im_set_position (spot); |
1289 | im_set_position (nspot); |
|
|
1290 | |
|
|
1291 | if (nspot.x == spot.x && nspot.y == spot.y) |
|
|
1292 | return; |
|
|
1293 | |
|
|
1294 | spot = nspot; |
1285 | |
1295 | |
1286 | preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); |
1296 | preedit_attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); |
1287 | XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); |
1297 | XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); |
1288 | XFree (preedit_attr); |
1298 | XFree (preedit_attr); |
1289 | } |
1299 | } |
1290 | |
1300 | |
1291 | void |
1301 | void |
1292 | rxvt_term::im_destroy () |
1302 | rxvt_term::im_destroy () |
1293 | { |
1303 | { |
1294 | if (Input_Context) |
|
|
1295 | { |
|
|
1296 | XDestroyIC (Input_Context); |
|
|
1297 | Input_Context = 0; |
|
|
1298 | } |
|
|
1299 | |
|
|
1300 | if (input_method) |
1304 | if (input_method) |
1301 | { |
1305 | { |
|
|
1306 | if (Input_Context && input_method->xim) |
|
|
1307 | XDestroyIC (Input_Context); |
|
|
1308 | |
1302 | display->put_xim (input_method); |
1309 | display->put_xim (input_method); |
1303 | input_method = 0; |
1310 | input_method = 0; |
1304 | } |
1311 | } |
|
|
1312 | |
|
|
1313 | Input_Context = 0; |
1305 | } |
1314 | } |
1306 | |
1315 | |
1307 | /* |
1316 | /* |
1308 | * Try to open a XIM with the current modifiers, then see if we can |
1317 | * Try to open a XIM with the current modifiers, then see if we can |
1309 | * open a suitable preedit type |
1318 | * open a suitable preedit type |
… | |
… | |
1327 | input_method = display->get_xim (locale, modifiers); |
1336 | input_method = display->get_xim (locale, modifiers); |
1328 | if (input_method == NULL) |
1337 | if (input_method == NULL) |
1329 | return false; |
1338 | return false; |
1330 | |
1339 | |
1331 | xim = input_method->xim; |
1340 | xim = input_method->xim; |
|
|
1341 | spot.x = spot.y = -1; |
1332 | |
1342 | |
1333 | xim_styles = NULL; |
1343 | xim_styles = NULL; |
1334 | if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) |
1344 | if (XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL) |
1335 | || !xim_styles || !xim_styles->count_styles) |
1345 | || !xim_styles || !xim_styles->count_styles) |
1336 | { |
1346 | { |
1337 | im_destroy (); |
1347 | im_destroy (); |
1338 | return false; |
1348 | return false; |
1339 | } |
1349 | } |
1340 | |
1350 | |
1341 | p = rs[Rs_preeditType] ? rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root"; |
1351 | const char *pet[] = { rs[Rs_preeditType], "OverTheSpot,OffTheSpot,Root,None" }; |
|
|
1352 | |
|
|
1353 | for (int pi = 0; pi < 2; pi++) |
|
|
1354 | { |
|
|
1355 | p = pet[pi]; |
|
|
1356 | |
|
|
1357 | if (!p) |
|
|
1358 | continue; |
|
|
1359 | |
1342 | s = rxvt_splitcommastring (p); |
1360 | s = rxvt_splitcommastring (p); |
1343 | |
1361 | |
1344 | for (i = found = 0; !found && s[i]; i++) |
1362 | for (i = found = 0; !found && s[i]; i++) |
1345 | { |
1363 | { |
1346 | if (!strcmp (s[i], "OverTheSpot")) |
1364 | if (!strcmp (s[i], "OverTheSpot")) |
1347 | input_style = (XIMPreeditPosition | XIMStatusNothing); |
1365 | input_style = (XIMPreeditPosition | XIMStatusNothing); |
1348 | else if (!strcmp (s[i], "OffTheSpot")) |
1366 | else if (!strcmp (s[i], "OffTheSpot")) |
1349 | input_style = (XIMPreeditArea | XIMStatusArea); |
1367 | input_style = (XIMPreeditArea | XIMStatusArea); |
1350 | else if (!strcmp (s[i], "Root")) |
1368 | else if (!strcmp (s[i], "Root")) |
1351 | input_style = (XIMPreeditNothing | XIMStatusNothing); |
1369 | input_style = (XIMPreeditNothing | XIMStatusNothing); |
|
|
1370 | else if (!strcmp (s[i], "None")) |
|
|
1371 | input_style = (XIMPreeditNone | XIMStatusNone); |
1352 | |
1372 | |
1353 | for (j = 0; j < xim_styles->count_styles; j++) |
1373 | for (j = 0; j < xim_styles->count_styles; j++) |
1354 | if (input_style == xim_styles->supported_styles[j]) |
1374 | if (input_style == xim_styles->supported_styles[j]) |
1355 | { |
1375 | { |
|
|
1376 | rxvt_freecommastring (s); |
|
|
1377 | |
1356 | found = 1; |
1378 | found = 1; |
1357 | break; |
1379 | goto foundpet; |
|
|
1380 | } |
|
|
1381 | |
1358 | } |
1382 | } |
1359 | } |
|
|
1360 | |
1383 | |
1361 | for (i = 0; s[i]; i++) |
1384 | rxvt_freecommastring (s); |
1362 | free (s[i]); |
1385 | } |
1363 | |
1386 | |
1364 | free (s); |
1387 | foundpet: |
|
|
1388 | |
1365 | XFree (xim_styles); |
1389 | XFree (xim_styles); |
1366 | |
1390 | |
1367 | if (!found) |
1391 | if (!found) |
1368 | { |
1392 | { |
1369 | im_destroy (); |
1393 | im_destroy (); |
… | |
… | |
1390 | "*", |
1414 | "*", |
1391 | TermWin.fheight, |
1415 | TermWin.fheight, |
1392 | TermWin.fheight + 1, TermWin.fheight - 1, |
1416 | TermWin.fheight + 1, TermWin.fheight - 1, |
1393 | TermWin.fheight - 2, TermWin.fheight + 2); |
1417 | TermWin.fheight - 2, TermWin.fheight + 2); |
1394 | |
1418 | |
1395 | fs = XCreateFontSet (display->display, pat, |
1419 | fs = XCreateFontSet (display->display, rs[Rs_imFont] ? rs[Rs_imFont] : pat, |
1396 | &missing_charset_list, &missing_charset_count, &def_string); |
1420 | &missing_charset_list, &missing_charset_count, &def_string); |
1397 | |
1421 | |
1398 | if (missing_charset_list) |
1422 | if (missing_charset_list) |
1399 | XFreeStringList (missing_charset_list); |
1423 | XFreeStringList (missing_charset_list); |
1400 | |
1424 | |
… | |
… | |
1494 | if (p && *p) |
1518 | if (p && *p) |
1495 | { |
1519 | { |
1496 | bool found = false; |
1520 | bool found = false; |
1497 | |
1521 | |
1498 | s = rxvt_splitcommastring (p); |
1522 | s = rxvt_splitcommastring (p); |
|
|
1523 | |
1499 | for (i = 0; s[i]; i++) |
1524 | for (i = 0; s[i]; i++) |
1500 | { |
1525 | { |
1501 | if (*s[i]) |
1526 | if (*s[i]) |
1502 | { |
1527 | { |
1503 | strcpy (buf, "@im="); |
1528 | strcpy (buf, "@im="); |
… | |
… | |
1507 | found = true; |
1532 | found = true; |
1508 | break; |
1533 | break; |
1509 | } |
1534 | } |
1510 | } |
1535 | } |
1511 | } |
1536 | } |
1512 | for (i = 0; s[i]; i++) |
1537 | |
1513 | free (s[i]); |
1538 | rxvt_freecommastring (s); |
1514 | free (s); |
|
|
1515 | |
1539 | |
1516 | if (found) |
1540 | if (found) |
1517 | goto done; |
1541 | goto done; |
1518 | } |
1542 | } |
1519 | |
1543 | |