… | |
… | |
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 | |
… | |
… | |
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 |
160 | sw_term (this, &rxvt_term::sig_term), |
163 | sw_term (this, &rxvt_term::sig_term), |
|
|
164 | sw_int (this, &rxvt_term::sig_term), |
161 | sw_chld (this, &rxvt_term::sig_chld), |
165 | sw_chld (this, &rxvt_term::sig_chld), |
162 | termwin_ev (this, &rxvt_term::x_cb), |
166 | termwin_ev (this, &rxvt_term::x_cb), |
163 | vt_ev (this, &rxvt_term::x_cb), |
167 | vt_ev (this, &rxvt_term::x_cb), |
164 | check_ev (this, &rxvt_term::check_cb), |
168 | check_ev (this, &rxvt_term::check_cb), |
165 | flush_ev (this, &rxvt_term::flush_cb), |
169 | flush_ev (this, &rxvt_term::flush_cb), |
… | |
… | |
168 | incr_ev (this, &rxvt_term::incr_cb) |
172 | incr_ev (this, &rxvt_term::incr_cb) |
169 | { |
173 | { |
170 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
174 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
171 | |
175 | |
172 | termlist.push_back (this); |
176 | termlist.push_back (this); |
173 | } |
|
|
174 | |
177 | |
175 | rxvt_term::~rxvt_term () |
178 | #ifdef KEYSYM_RESOURCE |
176 | { |
179 | keyboard = new keyboard_manager; |
177 | termlist.erase (find (termlist.begin (), termlist.end(), this)); |
|
|
178 | |
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 | { |
179 | if (cmd_pid) |
190 | if (cmd_pid) |
180 | kill (-cmd_pid, SIGHUP); |
191 | kill (-cmd_pid, SIGHUP); |
181 | |
192 | |
182 | pty.put (); |
|
|
183 | |
|
|
184 | #ifdef UTMP_SUPPORT |
193 | #ifdef UTMP_SUPPORT |
185 | privileged_utmp (RESTORE); |
194 | privileged_utmp (RESTORE); |
186 | #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 (); |
187 | |
205 | |
188 | #if ENABLE_STYLES |
206 | #if ENABLE_STYLES |
189 | for (int i = RS_styleCount; --i; ) |
207 | for (int i = RS_styleCount; --i; ) |
190 | if (TermWin.fontset[i] != TermWin.fontset[0]) |
208 | if (TermWin.fontset[i] != TermWin.fontset[0]) |
191 | delete TermWin.fontset[i]; |
209 | delete TermWin.fontset[i]; |
192 | #endif |
210 | #endif |
193 | delete TermWin.fontset[0]; |
211 | delete TermWin.fontset[0]; |
194 | |
212 | |
195 | if (display) |
213 | if (display) |
196 | { |
214 | { |
|
|
215 | dDisp; |
|
|
216 | |
197 | selection_clear (); |
217 | selection_clear (); |
198 | |
218 | |
199 | #ifdef USE_XIM |
219 | #ifdef USE_XIM |
200 | im_destroy (); |
220 | im_destroy (); |
201 | #endif |
221 | #endif |
202 | #ifdef MENUBAR |
222 | #ifdef MENUBAR |
203 | if (menubarGC) XFreeGC (display->display, menubarGC); |
223 | if (menubarGC) XFreeGC (disp, menubarGC); |
204 | #endif |
224 | #endif |
205 | #ifdef XTERM_SCROLLBAR |
225 | #ifdef XTERM_SCROLLBAR |
206 | if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC); |
226 | if (xscrollbarGC) XFreeGC (disp, xscrollbarGC); |
207 | if (ShadowGC) XFreeGC (display->display, ShadowGC); |
227 | if (ShadowGC) XFreeGC (disp, ShadowGC); |
208 | #endif |
228 | #endif |
209 | #ifdef PLAIN_SCROLLBAR |
229 | #ifdef PLAIN_SCROLLBAR |
210 | if (pscrollbarGC) XFreeGC (display->display, pscrollbarGC); |
230 | if (pscrollbarGC) XFreeGC (disp, pscrollbarGC); |
211 | #endif |
231 | #endif |
212 | #ifdef NEXT_SCROLLBAR |
232 | #ifdef NEXT_SCROLLBAR |
213 | if (blackGC) XFreeGC (display->display, blackGC); |
233 | if (blackGC) XFreeGC (disp, blackGC); |
214 | if (whiteGC) XFreeGC (display->display, whiteGC); |
234 | if (whiteGC) XFreeGC (disp, whiteGC); |
215 | if (grayGC) XFreeGC (display->display, grayGC); |
235 | if (grayGC) XFreeGC (disp, grayGC); |
216 | if (darkGC) XFreeGC (display->display, darkGC); |
236 | if (darkGC) XFreeGC (disp, darkGC); |
217 | if (stippleGC) XFreeGC (display->display, stippleGC); |
237 | if (stippleGC) XFreeGC (disp, stippleGC); |
218 | if (dimple) XFreePixmap (display->display, dimple); |
238 | if (dimple) XFreePixmap (disp, dimple); |
219 | if (upArrow) XFreePixmap (display->display, upArrow); |
239 | if (upArrow) XFreePixmap (disp, upArrow); |
220 | if (downArrow) XFreePixmap (display->display, downArrow); |
240 | if (downArrow) XFreePixmap (disp, downArrow); |
221 | if (upArrowHi) XFreePixmap (display->display, upArrowHi); |
241 | if (upArrowHi) XFreePixmap (disp, upArrowHi); |
222 | if (downArrowHi) XFreePixmap (display->display, downArrowHi); |
242 | if (downArrowHi) XFreePixmap (disp, downArrowHi); |
223 | #endif |
243 | #endif |
224 | #if defined(MENUBAR) || defined(RXVT_SCROLLBAR) |
244 | #if defined(MENUBAR) || defined(RXVT_SCROLLBAR) |
225 | if (topShadowGC) XFreeGC (display->display, topShadowGC); |
245 | if (topShadowGC) XFreeGC (disp, topShadowGC); |
226 | if (botShadowGC) XFreeGC (display->display, botShadowGC); |
246 | if (botShadowGC) XFreeGC (disp, botShadowGC); |
227 | if (scrollbarGC) XFreeGC (display->display, scrollbarGC); |
247 | if (scrollbarGC) XFreeGC (disp, scrollbarGC); |
228 | #endif |
248 | #endif |
229 | if (TermWin.gc) XFreeGC (display->display, TermWin.gc); |
249 | if (TermWin.gc) XFreeGC (disp, TermWin.gc); |
230 | |
250 | |
231 | #if defined(MENUBAR) && (MENUBAR_MAX > 1) |
251 | #if defined(MENUBAR) && (MENUBAR_MAX > 1) |
232 | delete menuBar.drawable; |
252 | delete menuBar.drawable; |
233 | //if (menuBar.win) |
253 | //if (menuBar.win) |
234 | // XDestroyWindow (display->display, menuBar.win); |
254 | // XDestroyWindow (disp, menuBar.win); |
235 | #endif |
255 | #endif |
236 | delete TermWin.drawable; |
256 | delete TermWin.drawable; |
237 | // destroy all windows |
257 | // destroy all windows |
238 | if (TermWin.parent[0]) |
258 | if (TermWin.parent[0]) |
239 | XDestroyWindow (display->display, TermWin.parent[0]); |
259 | XDestroyWindow (disp, TermWin.parent[0]); |
240 | } |
260 | } |
241 | |
261 | |
242 | // TODO: free pixcolours, colours should become part of rxvt_display |
262 | // TODO: free pixcolours, colours should become part of rxvt_display |
243 | |
263 | |
244 | delete pix_colors_focused; |
264 | delete pix_colors_focused; |
… | |
… | |
250 | |
270 | |
251 | scr_release (); |
271 | scr_release (); |
252 | |
272 | |
253 | /* clear all resources */ |
273 | /* clear all resources */ |
254 | for (int i = 0; i < allocated.size (); i++) |
274 | for (int i = 0; i < allocated.size (); i++) |
255 | free (allocated[i]); |
275 | free (allocated [i]); |
256 | |
276 | |
257 | free (selection.text); |
277 | free (selection.text); |
258 | // TODO: manage env vars in child only(!) |
278 | // TODO: manage env vars in child only(!) |
259 | free (env_windowid); |
279 | free (env_windowid); |
260 | free (env_display); |
280 | free (env_display); |
… | |
… | |
264 | free (v_buffer); |
284 | free (v_buffer); |
265 | free (incr_buf); |
285 | free (incr_buf); |
266 | |
286 | |
267 | delete envv; |
287 | delete envv; |
268 | delete argv; |
288 | delete argv; |
|
|
289 | |
|
|
290 | #ifdef KEYSYM_RESOURCE |
|
|
291 | delete keyboard; |
|
|
292 | #endif |
269 | } |
293 | } |
270 | |
294 | |
271 | void |
295 | void |
272 | rxvt_term::destroy () |
296 | rxvt_term::destroy () |
273 | { |
297 | { |
… | |
… | |
325 | |
349 | |
326 | delete this; |
350 | delete this; |
327 | } |
351 | } |
328 | |
352 | |
329 | /*----------------------------------------------------------------------*/ |
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 | #if ENABLE_FRILLS |
|
|
368 | static void |
|
|
369 | print_x_error (Display *dpy, XErrorEvent *event) |
|
|
370 | { |
|
|
371 | char buffer[BUFSIZ]; |
|
|
372 | char mesg[BUFSIZ]; |
|
|
373 | char number[32]; |
|
|
374 | char *mtype = "XlibMessage"; |
|
|
375 | XGetErrorText(dpy, event->error_code, buffer, BUFSIZ); |
|
|
376 | XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ); |
|
|
377 | rxvt_warn ("An X Error occured, trying to continue after report.\n"); |
|
|
378 | rxvt_warn ("%s: %s\n", mesg, buffer); |
|
|
379 | XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d", mesg, BUFSIZ); |
|
|
380 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->request_code); |
|
|
381 | sprintf(number, "%d", event->request_code); |
|
|
382 | XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ); |
|
|
383 | rxvt_warn ("(which is %s)\n", buffer); |
|
|
384 | if (event->request_code >= 128) { |
|
|
385 | XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d", |
|
|
386 | mesg, BUFSIZ); |
|
|
387 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->minor_code); |
|
|
388 | } |
|
|
389 | if ((event->error_code == BadWindow) || |
|
|
390 | (event->error_code == BadPixmap) || |
|
|
391 | (event->error_code == BadCursor) || |
|
|
392 | (event->error_code == BadFont) || |
|
|
393 | (event->error_code == BadDrawable) || |
|
|
394 | (event->error_code == BadColor) || |
|
|
395 | (event->error_code == BadGC) || |
|
|
396 | (event->error_code == BadIDChoice) || |
|
|
397 | (event->error_code == BadValue) || |
|
|
398 | (event->error_code == BadAtom)) { |
|
|
399 | if (event->error_code == BadValue) |
|
|
400 | XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x", |
|
|
401 | mesg, BUFSIZ); |
|
|
402 | else if (event->error_code == BadAtom) |
|
|
403 | XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x", |
|
|
404 | mesg, BUFSIZ); |
|
|
405 | else |
|
|
406 | XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x", |
|
|
407 | mesg, BUFSIZ); |
|
|
408 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->resourceid); |
|
|
409 | } |
|
|
410 | XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d", |
|
|
411 | mesg, BUFSIZ); |
|
|
412 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->serial); |
|
|
413 | } |
|
|
414 | #endif |
|
|
415 | |
|
|
416 | int |
|
|
417 | rxvt_xerror_handler (Display *display, XErrorEvent *event) |
|
|
418 | { |
|
|
419 | if (GET_R->allowedxerror == -1) |
|
|
420 | GET_R->allowedxerror = event->error_code; |
|
|
421 | else |
|
|
422 | { |
|
|
423 | //TODO: GET_R is most likely not the terminal which caused the error |
|
|
424 | //TODO: maybe just output the error and continue? |
|
|
425 | #if ENABLE_FRILLS |
|
|
426 | print_x_error (display, event); |
|
|
427 | #else |
|
|
428 | old_xerror_handler (display, event); |
|
|
429 | #endif |
|
|
430 | } |
|
|
431 | |
|
|
432 | return 0; |
|
|
433 | } |
|
|
434 | |
|
|
435 | int |
|
|
436 | rxvt_xioerror_handler (Display *display) |
|
|
437 | { |
|
|
438 | rxvt_warn ("X connection to '%s' broken, unable to recover, exiting.\n", |
|
|
439 | DisplayString (display)); |
|
|
440 | rxvt_emergency_cleanup (); |
|
|
441 | _exit (EXIT_FAILURE); |
|
|
442 | } |
|
|
443 | |
|
|
444 | /* |
|
|
445 | * Catch a fatal signal and tidy up before quitting |
|
|
446 | */ |
|
|
447 | void |
|
|
448 | rxvt_term::sig_term (sig_watcher &w) |
|
|
449 | { |
|
|
450 | #ifdef DEBUG_CMD |
|
|
451 | rxvt_warn ("caught signal %d, exiting.\n", w.signum); |
|
|
452 | #endif |
|
|
453 | rxvt_emergency_cleanup (); |
|
|
454 | signal (w.signum, SIG_DFL); |
|
|
455 | kill (getpid (), w.signum); |
|
|
456 | } |
|
|
457 | |
|
|
458 | /*----------------------------------------------------------------------*/ |
330 | /* rxvt_init () */ |
459 | /* rxvt_init () */ |
331 | bool |
460 | bool |
332 | rxvt_term::init (int argc, const char *const *argv) |
461 | rxvt_term::init (int argc, const char *const *argv) |
333 | { |
462 | { |
334 | SET_R (this); |
463 | SET_R (this); |
335 | |
464 | |
|
|
465 | set_locale (""); |
|
|
466 | |
336 | if (!init_vars ()) |
467 | if (!init_vars ()) |
337 | return false; |
468 | return false; |
338 | |
469 | |
339 | init_secondary (); |
470 | init_secondary (); |
340 | |
471 | |
341 | const char **cmd_argv = init_resources (argc, argv); |
472 | const char **cmd_argv = init_resources (argc, argv); |
342 | |
473 | |
343 | set_locale (""); |
474 | #ifdef KEYSYM_RESOURCE |
|
|
475 | keyboard->register_done (); |
|
|
476 | #endif |
344 | |
477 | |
345 | #if MENUBAR_MAX |
478 | #if MENUBAR_MAX |
346 | menubar_read (rs[Rs_menu]); |
479 | menubar_read (rs[Rs_menu]); |
347 | #endif |
480 | #endif |
348 | #ifdef HAVE_SCROLLBARS |
481 | #ifdef HAVE_SCROLLBARS |
… | |
… | |
350 | scrollBar.setIdle (); /* set existence for size calculations */ |
483 | scrollBar.setIdle (); /* set existence for size calculations */ |
351 | #endif |
484 | #endif |
352 | |
485 | |
353 | create_windows (argc, argv); |
486 | create_windows (argc, argv); |
354 | |
487 | |
|
|
488 | dDisp; |
|
|
489 | |
355 | init_xlocale (); |
490 | init_xlocale (); |
356 | |
491 | |
357 | scr_reset (); /* initialize screen */ |
492 | scr_reset (); /* initialize screen */ |
358 | |
493 | |
359 | #if 0 |
494 | #if 0 |
360 | XSynchronize (display->display, True); |
495 | XSynchronize (disp, True); |
361 | #endif |
496 | #endif |
362 | |
497 | |
363 | #ifdef HAVE_SCROLLBARS |
498 | #ifdef HAVE_SCROLLBARS |
364 | if (options & Opt_scrollBar) |
499 | if (options & Opt_scrollBar) |
365 | resize_scrollbar (); /* create and map scrollbar */ |
500 | resize_scrollbar (); /* create and map scrollbar */ |
366 | #endif |
501 | #endif |
367 | #if (MENUBAR_MAX) |
502 | #if (MENUBAR_MAX) |
368 | if (menubar_visible ()) |
503 | if (menubar_visible ()) |
369 | XMapWindow (display->display, menuBar.win); |
504 | XMapWindow (disp, menuBar.win); |
370 | #endif |
505 | #endif |
371 | #ifdef TRANSPARENT |
506 | #ifdef TRANSPARENT |
372 | if (options & Opt_transparent) |
507 | if (options & Opt_transparent) |
373 | { |
508 | { |
374 | XSelectInput (display->display, display->root, PropertyChangeMask); |
509 | XSelectInput (disp, display->root, PropertyChangeMask); |
375 | check_our_parents (); |
510 | check_our_parents (); |
376 | rootwin_ev.start (display, display->root); |
511 | rootwin_ev.start (display, display->root); |
377 | } |
512 | } |
378 | #endif |
513 | #endif |
379 | |
514 | |
380 | XMapWindow (display->display, TermWin.vt); |
515 | XMapWindow (disp, TermWin.vt); |
381 | XMapWindow (display->display, TermWin.parent[0]); |
516 | XMapWindow (disp, TermWin.parent[0]); |
382 | |
517 | |
383 | set_colorfgbg (); |
518 | set_colorfgbg (); |
384 | |
519 | |
385 | init_command (cmd_argv); |
520 | init_command (cmd_argv); |
386 | |
521 | |
|
|
522 | free (cmd_argv); |
|
|
523 | |
387 | pty_ev.start (pty.pty, EVENT_READ); |
524 | pty_ev.start (pty.pty, EVENT_READ); |
388 | |
525 | |
389 | check_ev.start (); |
526 | check_ev.start (); |
390 | |
527 | |
391 | return true; |
528 | return true; |
392 | } |
529 | } |
393 | |
|
|
394 | static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event); |
|
|
395 | |
530 | |
396 | void |
531 | void |
397 | rxvt_init () |
532 | rxvt_init () |
398 | { |
533 | { |
399 | /* |
534 | /* |
… | |
… | |
412 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
547 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
413 | /* signal (SIGURG, SIG_DFL); */ |
548 | /* signal (SIGURG, SIG_DFL); */ |
414 | |
549 | |
415 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
550 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
416 | // TODO: handle this with exceptions and tolerate the memory loss |
551 | // TODO: handle this with exceptions and tolerate the memory loss |
417 | //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); |
552 | XSetIOErrorHandler (rxvt_xioerror_handler); |
418 | } |
553 | } |
419 | |
554 | |
420 | /* ------------------------------------------------------------------------- * |
555 | /* ------------------------------------------------------------------------- * |
421 | * SIGNAL HANDLING & EXIT HANDLER * |
556 | * SIGNAL HANDLING & EXIT HANDLER * |
422 | * ------------------------------------------------------------------------- */ |
557 | * ------------------------------------------------------------------------- */ |
… | |
… | |
435 | if (pid == (*t)->cmd_pid) |
570 | if (pid == (*t)->cmd_pid) |
436 | { |
571 | { |
437 | (*t)->destroy (); |
572 | (*t)->destroy (); |
438 | break; |
573 | break; |
439 | } |
574 | } |
440 | } |
|
|
441 | |
|
|
442 | /*----------------------------------------------------------------------*/ |
|
|
443 | /* |
|
|
444 | * Exit gracefully, clearing the utmp entry and restoring tty attributes |
|
|
445 | * TODO: if debugging, this should free up any known resources if we can |
|
|
446 | */ |
|
|
447 | void |
|
|
448 | rxvt_destroy_all () |
|
|
449 | { |
|
|
450 | // TODO: rxvtd should clean up all ressources |
|
|
451 | for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) |
|
|
452 | (*t)->destroy (); |
|
|
453 | } |
|
|
454 | |
|
|
455 | /* |
|
|
456 | * Catch a fatal signal and tidy up before quitting |
|
|
457 | */ |
|
|
458 | void |
|
|
459 | rxvt_term::sig_term (sig_watcher &w) |
|
|
460 | { |
|
|
461 | #ifdef DEBUG_CMD |
|
|
462 | rxvt_warn ("caught signal %d, exiting.\n", w.signum); |
|
|
463 | #endif |
|
|
464 | rxvt_destroy_all (); |
|
|
465 | signal (w.signum, SIG_DFL); |
|
|
466 | kill (getpid (), w.signum); |
|
|
467 | } |
|
|
468 | |
|
|
469 | /* INTPROTO */ |
|
|
470 | int |
|
|
471 | rxvt_xerror_handler (Display *display, XErrorEvent *event) |
|
|
472 | { |
|
|
473 | if (GET_R->allowedxerror == -1) |
|
|
474 | GET_R->allowedxerror = event->error_code; |
|
|
475 | else |
|
|
476 | { |
|
|
477 | old_xerror_handler (display, event); |
|
|
478 | GET_R->destroy (); |
|
|
479 | } |
|
|
480 | |
|
|
481 | return 0; |
|
|
482 | } |
575 | } |
483 | |
576 | |
484 | /* ------------------------------------------------------------------------- * |
577 | /* ------------------------------------------------------------------------- * |
485 | * MEMORY ALLOCATION WRAPPERS * |
578 | * MEMORY ALLOCATION WRAPPERS * |
486 | * ------------------------------------------------------------------------- */ |
579 | * ------------------------------------------------------------------------- */ |
… | |
… | |
599 | * if width/height are non-zero then override calculated width/height |
692 | * if width/height are non-zero then override calculated width/height |
600 | */ |
693 | */ |
601 | void |
694 | void |
602 | rxvt_term::window_calc (unsigned int width, unsigned int height) |
695 | rxvt_term::window_calc (unsigned int width, unsigned int height) |
603 | { |
696 | { |
604 | short recalc_x, recalc_y; |
697 | short recalc_x, recalc_y; |
605 | int x, y, sb_w, mb_h, flags; |
698 | int x, y, sb_w, mb_h, flags; |
606 | unsigned int w, h; |
699 | unsigned int w, h; |
607 | unsigned int max_width, max_height; |
700 | unsigned int max_width, max_height; |
|
|
701 | dDisp; |
608 | |
702 | |
609 | D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
703 | D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
610 | TermWin.ncol, TermWin.nrow, szHint.width, |
704 | TermWin.ncol, TermWin.nrow, szHint.width, |
611 | szHint.height)); |
705 | szHint.height)); |
612 | szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; |
706 | szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; |
… | |
… | |
710 | |
804 | |
711 | if (scrollbar_visible () && (options & Opt_scrollBar_right)) |
805 | if (scrollbar_visible () && (options & Opt_scrollBar_right)) |
712 | window_sb_x = szHint.width - sb_w; |
806 | window_sb_x = szHint.width - sb_w; |
713 | |
807 | |
714 | if (recalc_x) |
808 | if (recalc_x) |
715 | szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) |
809 | szHint.x += (DisplayWidth (disp, display->screen) |
716 | - szHint.width - 2 * TermWin.ext_bwidth); |
810 | - szHint.width - 2 * TermWin.ext_bwidth); |
717 | if (recalc_y) |
811 | if (recalc_y) |
718 | szHint.y += (DisplayHeight (display->display, DefaultScreen (display->display)) |
812 | szHint.y += (DisplayHeight (disp, display->screen) |
719 | - szHint.height - 2 * TermWin.ext_bwidth); |
813 | - szHint.height - 2 * TermWin.ext_bwidth); |
720 | |
814 | |
721 | TermWin.ncol = TermWin.width / TermWin.fwidth; |
815 | TermWin.ncol = TermWin.width / TermWin.fwidth; |
722 | TermWin.nrow = TermWin.height / TermWin.fheight; |
816 | TermWin.nrow = TermWin.height / TermWin.fheight; |
723 | D_SIZE ((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
817 | D_SIZE ((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
… | |
… | |
782 | |
876 | |
783 | delete TermWin.fontset[0]; |
877 | delete TermWin.fontset[0]; |
784 | TermWin.fontset[0] = fs; |
878 | TermWin.fontset[0] = fs; |
785 | |
879 | |
786 | prop = (*fs)[1]->properties (); |
880 | prop = (*fs)[1]->properties (); |
|
|
881 | prop.height += TermWin.lineSpace; |
787 | fs->set_prop (prop); |
882 | fs->set_prop (prop); |
788 | |
883 | |
789 | TermWin.fwidth = prop.width; |
884 | TermWin.fwidth = prop.width; |
790 | TermWin.fheight = prop.height; |
885 | TermWin.fheight = prop.height; |
791 | TermWin.fweight = prop.weight; |
886 | TermWin.fweight = prop.weight; |
… | |
… | |
887 | |
982 | |
888 | /* handle color aliases */ |
983 | /* handle color aliases */ |
889 | if (isdigit (*color)) |
984 | if (isdigit (*color)) |
890 | { |
985 | { |
891 | i = atoi (color); |
986 | i = atoi (color); |
|
|
987 | |
892 | if (i >= 8 && i <= 15) |
988 | if (i >= 8 && i <= 15) |
893 | { /* bright colors */ |
989 | { /* bright colors */ |
894 | i -= 8; |
990 | i -= 8; |
895 | # ifndef NO_BRIGHTCOLOR |
991 | # ifndef NO_BRIGHTCOLOR |
896 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
992 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
897 | SET_PIXCOLOR (idx); |
993 | SET_PIXCOLOR (idx); |
898 | goto Done; |
994 | goto Done; |
899 | # endif |
995 | # endif |
900 | |
|
|
901 | } |
996 | } |
|
|
997 | |
902 | if (i >= 0 && i <= 7) |
998 | if (i >= 0 && i <= 7) |
903 | { /* normal colors */ |
999 | { /* normal colors */ |
904 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
1000 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
905 | SET_PIXCOLOR (idx); |
1001 | SET_PIXCOLOR (idx); |
906 | goto Done; |
1002 | goto Done; |
907 | } |
1003 | } |
908 | } |
1004 | } |
909 | |
1005 | |
910 | if (!rXParseAllocColor (& xcol, color)) |
1006 | if (!rXParseAllocColor (&xcol, color)) |
911 | return; |
1007 | return; |
912 | |
1008 | |
913 | /* XStoreColor (display->display, display->cmap, XColor*); */ |
1009 | /* XStoreColor (display->display, display->cmap, XColor*); */ |
914 | |
1010 | |
915 | /* |
1011 | /* |
… | |
… | |
1018 | * -------------------------------------------------------------------- */ |
1114 | * -------------------------------------------------------------------- */ |
1019 | void |
1115 | void |
1020 | rxvt_term::resize_all_windows (unsigned int width, unsigned int height, int ignoreparent) |
1116 | rxvt_term::resize_all_windows (unsigned int width, unsigned int height, int ignoreparent) |
1021 | { |
1117 | { |
1022 | int fix_screen; |
1118 | int fix_screen; |
1023 | |
|
|
1024 | #ifdef SMART_RESIZE |
1119 | #ifdef SMART_RESIZE |
1025 | int old_width = szHint.width, old_height = szHint.height; |
1120 | int old_width = szHint.width, old_height = szHint.height; |
1026 | #endif |
1121 | #endif |
|
|
1122 | dDisp; |
1027 | |
1123 | |
1028 | window_calc (width, height); |
1124 | window_calc (width, height); |
1029 | XSetWMNormalHints (display->display, TermWin.parent[0], &szHint); |
1125 | XSetWMNormalHints (disp, TermWin.parent[0], &szHint); |
1030 | |
1126 | |
1031 | if (!ignoreparent) |
1127 | if (!ignoreparent) |
1032 | { |
1128 | { |
1033 | #ifdef SMART_RESIZE |
1129 | #ifdef SMART_RESIZE |
1034 | /* |
1130 | /* |
… | |
… | |
1038 | int x, y, x1, y1; |
1134 | int x, y, x1, y1; |
1039 | int dx, dy; |
1135 | int dx, dy; |
1040 | unsigned int unused_w1, unused_h1, unused_b1, unused_d1; |
1136 | unsigned int unused_w1, unused_h1, unused_b1, unused_d1; |
1041 | Window unused_cr; |
1137 | Window unused_cr; |
1042 | |
1138 | |
1043 | XTranslateCoordinates (display->display, TermWin.parent[0], display->root, |
1139 | XTranslateCoordinates (disp, TermWin.parent[0], display->root, |
1044 | 0, 0, &x, &y, &unused_cr); |
1140 | 0, 0, &x, &y, &unused_cr); |
1045 | XGetGeometry (display->display, TermWin.parent[0], &unused_cr, &x1, &y1, |
1141 | XGetGeometry (disp, TermWin.parent[0], &unused_cr, &x1, &y1, |
1046 | &unused_w1, &unused_h1, &unused_b1, &unused_d1); |
1142 | &unused_w1, &unused_h1, &unused_b1, &unused_d1); |
1047 | /* |
1143 | /* |
1048 | * if display->root isn't the parent window, a WM will probably have offset |
1144 | * if display->root isn't the parent window, a WM will probably have offset |
1049 | * our position for handles and decorations. Counter it |
1145 | * our position for handles and decorations. Counter it |
1050 | */ |
1146 | */ |
… | |
… | |
1052 | { |
1148 | { |
1053 | x -= x1; |
1149 | x -= x1; |
1054 | y -= y1; |
1150 | y -= y1; |
1055 | } |
1151 | } |
1056 | |
1152 | |
1057 | x1 = (DisplayWidth (display->display, display->screen) - old_width) / 2; |
1153 | x1 = (DisplayWidth (disp, display->screen) - old_width) / 2; |
1058 | y1 = (DisplayHeight (display->display, display->screen) - old_height) / 2; |
1154 | y1 = (DisplayHeight (disp, display->screen) - old_height) / 2; |
1059 | dx = old_width - szHint.width; |
1155 | dx = old_width - szHint.width; |
1060 | dy = old_height - szHint.height; |
1156 | dy = old_height - szHint.height; |
1061 | |
1157 | |
1062 | /* Check position of the center of the window */ |
1158 | /* Check position of the center of the window */ |
1063 | if (x < x1) /* left half */ |
1159 | if (x < x1) /* left half */ |
… | |
… | |
1067 | if (y < y1) /* top half */ |
1163 | if (y < y1) /* top half */ |
1068 | dy = 0; |
1164 | dy = 0; |
1069 | else if (y == y1) /* exact center */ |
1165 | else if (y == y1) /* exact center */ |
1070 | dy /= 2; |
1166 | dy /= 2; |
1071 | |
1167 | |
1072 | XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy, |
1168 | XMoveResizeWindow (disp, TermWin.parent[0], x + dx, y + dy, |
1073 | szHint.width, szHint.height); |
1169 | szHint.width, szHint.height); |
1074 | #else |
1170 | #else |
1075 | XResizeWindow (display->display, TermWin.parent[0], szHint.width, szHint.height); |
1171 | XResizeWindow (disp, TermWin.parent[0], szHint.width, szHint.height); |
1076 | #endif |
1172 | #endif |
1077 | } |
1173 | } |
1078 | |
1174 | |
1079 | fix_screen = TermWin.ncol != prev_ncol || TermWin.nrow != prev_nrow; |
1175 | fix_screen = TermWin.ncol != prev_ncol || TermWin.nrow != prev_nrow; |
1080 | |
1176 | |
1081 | if (fix_screen || width != old_width || height != old_height) |
1177 | if (fix_screen || width != old_width || height != old_height) |
1082 | { |
1178 | { |
1083 | if (scrollbar_visible ()) |
1179 | if (scrollbar_visible ()) |
1084 | { |
1180 | { |
1085 | XMoveResizeWindow (display->display, scrollBar.win, |
1181 | XMoveResizeWindow (disp, scrollBar.win, |
1086 | window_sb_x, 0, |
1182 | window_sb_x, 0, |
1087 | scrollbar_TotalWidth (), szHint.height); |
1183 | scrollbar_TotalWidth (), szHint.height); |
1088 | resize_scrollbar (); |
1184 | resize_scrollbar (); |
1089 | } |
1185 | } |
1090 | |
1186 | |
1091 | if (menubar_visible ()) |
1187 | if (menubar_visible ()) |
1092 | XMoveResizeWindow (display->display, menuBar.win, |
1188 | XMoveResizeWindow (disp, menuBar.win, |
1093 | window_vt_x, 0, |
1189 | window_vt_x, 0, |
1094 | TermWin_TotalWidth (), menuBar_TotalHeight ()); |
1190 | TermWin_TotalWidth (), menuBar_TotalHeight ()); |
1095 | |
1191 | |
1096 | XMoveResizeWindow (display->display, TermWin.vt, |
1192 | XMoveResizeWindow (disp, TermWin.vt, |
1097 | window_vt_x, window_vt_y, |
1193 | window_vt_x, window_vt_y, |
1098 | TermWin_TotalWidth (), TermWin_TotalHeight ()); |
1194 | TermWin_TotalWidth (), TermWin_TotalHeight ()); |
|
|
1195 | |
1099 | scr_clear (); |
1196 | scr_clear (); |
1100 | #ifdef XPM_BACKGROUND |
1197 | #ifdef XPM_BACKGROUND |
1101 | resize_pixmap (); |
1198 | resize_pixmap (); |
1102 | #endif |
1199 | #endif |
1103 | } |
1200 | } |
… | |
… | |
1125 | } |
1222 | } |
1126 | } |
1223 | } |
1127 | |
1224 | |
1128 | old_width = szHint.width; |
1225 | old_width = szHint.width; |
1129 | old_height = szHint.height; |
1226 | old_height = szHint.height; |
|
|
1227 | |
|
|
1228 | #ifdef XPM_BACKGROUND |
|
|
1229 | if (TermWin.pixmap) |
|
|
1230 | scr_touch (false); |
|
|
1231 | #endif |
1130 | |
1232 | |
1131 | #ifdef USE_XIM |
1233 | #ifdef USE_XIM |
1132 | IMSetStatusPosition (); |
1234 | IMSetStatusPosition (); |
1133 | #endif |
1235 | #endif |
1134 | } |
1236 | } |
… | |
… | |
1364 | "*", |
1466 | "*", |
1365 | TermWin.fheight, |
1467 | TermWin.fheight, |
1366 | TermWin.fheight + 1, TermWin.fheight - 1, |
1468 | TermWin.fheight + 1, TermWin.fheight - 1, |
1367 | TermWin.fheight - 2, TermWin.fheight + 2); |
1469 | TermWin.fheight - 2, TermWin.fheight + 2); |
1368 | |
1470 | |
1369 | fs = XCreateFontSet (display->display, pat, |
1471 | fs = XCreateFontSet (display->display, rs[Rs_imFont] ? rs[Rs_imFont] : pat, |
1370 | &missing_charset_list, &missing_charset_count, &def_string); |
1472 | &missing_charset_list, &missing_charset_count, &def_string); |
1371 | |
1473 | |
1372 | if (missing_charset_list) |
1474 | if (missing_charset_list) |
1373 | XFreeStringList (missing_charset_list); |
1475 | XFreeStringList (missing_charset_list); |
1374 | |
1476 | |
… | |
… | |
1450 | { |
1552 | { |
1451 | int i, found, had_im; |
1553 | int i, found, had_im; |
1452 | const char *p; |
1554 | const char *p; |
1453 | char **s; |
1555 | char **s; |
1454 | char buf[IMBUFSIZ]; |
1556 | char buf[IMBUFSIZ]; |
|
|
1557 | |
|
|
1558 | SET_R (this); |
1455 | |
1559 | |
1456 | im_destroy (); |
1560 | im_destroy (); |
1457 | |
1561 | |
1458 | D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); |
1562 | D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); |
1459 | if (Input_Context) |
1563 | if (Input_Context) |