… | |
… | |
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] |
|
|
259 | #if ENABLE_FRILLS |
|
|
260 | && !rs[Rs_embed] |
|
|
261 | #endif |
|
|
262 | ) |
239 | XDestroyWindow (display->display, TermWin.parent[0]); |
263 | XDestroyWindow (disp, TermWin.parent[0]); |
240 | } |
264 | } |
241 | |
265 | |
242 | // TODO: free pixcolours, colours should become part of rxvt_display |
266 | // TODO: free pixcolours, colours should become part of rxvt_display |
243 | |
267 | |
244 | delete pix_colors_focused; |
268 | delete pix_colors_focused; |
… | |
… | |
250 | |
274 | |
251 | scr_release (); |
275 | scr_release (); |
252 | |
276 | |
253 | /* clear all resources */ |
277 | /* clear all resources */ |
254 | for (int i = 0; i < allocated.size (); i++) |
278 | for (int i = 0; i < allocated.size (); i++) |
255 | free (allocated[i]); |
279 | free (allocated [i]); |
256 | |
280 | |
257 | free (selection.text); |
281 | free (selection.text); |
258 | // TODO: manage env vars in child only(!) |
282 | // TODO: manage env vars in child only(!) |
259 | free (env_windowid); |
283 | free (env_windowid); |
260 | free (env_display); |
284 | free (env_display); |
261 | free (env_term); |
285 | free (env_term); |
262 | free (env_colorfgbg); |
286 | free (env_colorfgbg); |
263 | free (locale); |
287 | free (locale); |
264 | #if 0 |
288 | free (v_buffer); |
265 | free (codeset); |
289 | free (incr_buf); |
266 | #endif |
|
|
267 | |
290 | |
268 | delete envv; |
291 | delete envv; |
269 | delete argv; |
292 | delete argv; |
|
|
293 | |
|
|
294 | #ifdef KEYSYM_RESOURCE |
|
|
295 | delete keyboard; |
|
|
296 | #endif |
270 | } |
297 | } |
271 | |
298 | |
272 | void |
299 | void |
273 | rxvt_term::destroy () |
300 | rxvt_term::destroy () |
274 | { |
301 | { |
… | |
… | |
326 | |
353 | |
327 | delete this; |
354 | delete this; |
328 | } |
355 | } |
329 | |
356 | |
330 | /*----------------------------------------------------------------------*/ |
357 | /*----------------------------------------------------------------------*/ |
|
|
358 | /* |
|
|
359 | * Exit gracefully, clearing the utmp entry and restoring tty attributes |
|
|
360 | * TODO: if debugging, this should free up any known resources if we can |
|
|
361 | */ |
|
|
362 | static XErrorHandler old_xerror_handler; |
|
|
363 | |
|
|
364 | static void |
|
|
365 | rxvt_emergency_cleanup () |
|
|
366 | { |
|
|
367 | for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) |
|
|
368 | (*t)->emergency_cleanup (); |
|
|
369 | } |
|
|
370 | |
|
|
371 | #if ENABLE_FRILLS |
|
|
372 | static void |
|
|
373 | print_x_error (Display *dpy, XErrorEvent *event) |
|
|
374 | { |
|
|
375 | char buffer[BUFSIZ]; |
|
|
376 | char mesg[BUFSIZ]; |
|
|
377 | char number[32]; |
|
|
378 | char *mtype = "XlibMessage"; |
|
|
379 | XGetErrorText(dpy, event->error_code, buffer, BUFSIZ); |
|
|
380 | XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ); |
|
|
381 | rxvt_warn ("An X Error occured, trying to continue after report.\n"); |
|
|
382 | rxvt_warn ("%s: %s\n", mesg, buffer); |
|
|
383 | XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d", mesg, BUFSIZ); |
|
|
384 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->request_code); |
|
|
385 | sprintf(number, "%d", event->request_code); |
|
|
386 | XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ); |
|
|
387 | rxvt_warn ("(which is %s)\n", buffer); |
|
|
388 | if (event->request_code >= 128) { |
|
|
389 | XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d", |
|
|
390 | mesg, BUFSIZ); |
|
|
391 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->minor_code); |
|
|
392 | } |
|
|
393 | if ((event->error_code == BadWindow) || |
|
|
394 | (event->error_code == BadPixmap) || |
|
|
395 | (event->error_code == BadCursor) || |
|
|
396 | (event->error_code == BadFont) || |
|
|
397 | (event->error_code == BadDrawable) || |
|
|
398 | (event->error_code == BadColor) || |
|
|
399 | (event->error_code == BadGC) || |
|
|
400 | (event->error_code == BadIDChoice) || |
|
|
401 | (event->error_code == BadValue) || |
|
|
402 | (event->error_code == BadAtom)) { |
|
|
403 | if (event->error_code == BadValue) |
|
|
404 | XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x", |
|
|
405 | mesg, BUFSIZ); |
|
|
406 | else if (event->error_code == BadAtom) |
|
|
407 | XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x", |
|
|
408 | mesg, BUFSIZ); |
|
|
409 | else |
|
|
410 | XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x", |
|
|
411 | mesg, BUFSIZ); |
|
|
412 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->resourceid); |
|
|
413 | } |
|
|
414 | XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d", |
|
|
415 | mesg, BUFSIZ); |
|
|
416 | rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->serial); |
|
|
417 | } |
|
|
418 | #endif |
|
|
419 | |
|
|
420 | int |
|
|
421 | rxvt_xerror_handler (Display *display, XErrorEvent *event) |
|
|
422 | { |
|
|
423 | if (GET_R->allowedxerror == -1) |
|
|
424 | GET_R->allowedxerror = event->error_code; |
|
|
425 | else |
|
|
426 | { |
|
|
427 | //TODO: GET_R is most likely not the terminal which caused the error |
|
|
428 | //TODO: maybe just output the error and continue? |
|
|
429 | #if ENABLE_FRILLS |
|
|
430 | print_x_error (display, event); |
|
|
431 | #else |
|
|
432 | old_xerror_handler (display, event); |
|
|
433 | #endif |
|
|
434 | } |
|
|
435 | |
|
|
436 | return 0; |
|
|
437 | } |
|
|
438 | |
|
|
439 | int |
|
|
440 | rxvt_xioerror_handler (Display *display) |
|
|
441 | { |
|
|
442 | rxvt_warn ("X connection to '%s' broken, unable to recover, exiting.\n", |
|
|
443 | DisplayString (display)); |
|
|
444 | rxvt_emergency_cleanup (); |
|
|
445 | _exit (EXIT_FAILURE); |
|
|
446 | } |
|
|
447 | |
|
|
448 | /* |
|
|
449 | * Catch a fatal signal and tidy up before quitting |
|
|
450 | */ |
|
|
451 | void |
|
|
452 | rxvt_term::sig_term (sig_watcher &w) |
|
|
453 | { |
|
|
454 | #ifdef DEBUG_CMD |
|
|
455 | rxvt_warn ("caught signal %d, exiting.\n", w.signum); |
|
|
456 | #endif |
|
|
457 | rxvt_emergency_cleanup (); |
|
|
458 | signal (w.signum, SIG_DFL); |
|
|
459 | kill (getpid (), w.signum); |
|
|
460 | } |
|
|
461 | |
|
|
462 | /*----------------------------------------------------------------------*/ |
331 | /* rxvt_init () */ |
463 | /* rxvt_init () */ |
332 | bool |
464 | bool |
333 | rxvt_term::init (int argc, const char *const *argv) |
465 | rxvt_term::init (int argc, const char *const *argv) |
334 | { |
466 | { |
335 | SET_R (this); |
467 | SET_R (this); |
336 | |
468 | |
|
|
469 | set_locale (""); |
|
|
470 | |
337 | if (!init_vars ()) |
471 | if (!init_vars ()) |
338 | return false; |
472 | return false; |
339 | |
473 | |
340 | init_secondary (); |
474 | init_secondary (); |
341 | |
475 | |
342 | const char **cmd_argv = init_resources (argc, argv); |
476 | const char **cmd_argv = init_resources (argc, argv); |
343 | |
477 | |
344 | set_locale (""); |
478 | #ifdef KEYSYM_RESOURCE |
|
|
479 | keyboard->register_done (); |
|
|
480 | #endif |
345 | |
481 | |
346 | #if MENUBAR_MAX |
482 | #if MENUBAR_MAX |
347 | menubar_read (rs[Rs_menu]); |
483 | menubar_read (rs[Rs_menu]); |
348 | #endif |
484 | #endif |
349 | #ifdef HAVE_SCROLLBARS |
485 | #ifdef HAVE_SCROLLBARS |
… | |
… | |
351 | scrollBar.setIdle (); /* set existence for size calculations */ |
487 | scrollBar.setIdle (); /* set existence for size calculations */ |
352 | #endif |
488 | #endif |
353 | |
489 | |
354 | create_windows (argc, argv); |
490 | create_windows (argc, argv); |
355 | |
491 | |
|
|
492 | dDisp; |
|
|
493 | |
356 | init_xlocale (); |
494 | init_xlocale (); |
357 | |
495 | |
358 | scr_reset (); /* initialize screen */ |
496 | scr_reset (); /* initialize screen */ |
359 | |
497 | |
360 | #if 1 |
498 | #if 0 |
361 | XSynchronize (display->display, True); |
499 | XSynchronize (disp, True); |
362 | #endif |
500 | #endif |
363 | |
501 | |
364 | #ifdef HAVE_SCROLLBARS |
502 | #ifdef HAVE_SCROLLBARS |
365 | if (options & Opt_scrollBar) |
503 | if (options & Opt_scrollBar) |
366 | resize_scrollbar (); /* create and map scrollbar */ |
504 | resize_scrollbar (); /* create and map scrollbar */ |
367 | #endif |
505 | #endif |
368 | #if (MENUBAR_MAX) |
506 | #if (MENUBAR_MAX) |
369 | if (menubar_visible ()) |
507 | if (menubar_visible ()) |
370 | XMapWindow (display->display, menuBar.win); |
508 | XMapWindow (disp, menuBar.win); |
371 | #endif |
509 | #endif |
372 | #ifdef TRANSPARENT |
510 | #ifdef TRANSPARENT |
373 | if (options & Opt_transparent) |
511 | if (options & Opt_transparent) |
374 | { |
512 | { |
375 | XSelectInput (display->display, display->root, PropertyChangeMask); |
513 | XSelectInput (disp, display->root, PropertyChangeMask); |
376 | check_our_parents (); |
514 | check_our_parents (); |
377 | rootwin_ev.start (display, display->root); |
515 | rootwin_ev.start (display, display->root); |
378 | } |
516 | } |
379 | #endif |
517 | #endif |
380 | |
518 | |
381 | XMapWindow (display->display, TermWin.vt); |
519 | XMapWindow (disp, TermWin.vt); |
382 | XMapWindow (display->display, TermWin.parent[0]); |
520 | XMapWindow (disp, TermWin.parent[0]); |
383 | |
521 | |
384 | set_colorfgbg (); |
522 | set_colorfgbg (); |
385 | |
523 | |
386 | init_command (cmd_argv); |
524 | init_command (cmd_argv); |
387 | |
525 | |
|
|
526 | free (cmd_argv); |
|
|
527 | |
388 | pty_ev.start (pty.pty, EVENT_READ); |
528 | pty_ev.start (pty.pty, EVENT_READ); |
389 | |
529 | |
390 | check_ev.start (); |
530 | check_ev.start (); |
391 | |
531 | |
392 | return true; |
532 | return true; |
393 | } |
533 | } |
394 | |
|
|
395 | static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event); |
|
|
396 | |
534 | |
397 | void |
535 | void |
398 | rxvt_init () |
536 | rxvt_init () |
399 | { |
537 | { |
400 | /* |
538 | /* |
… | |
… | |
413 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
551 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
414 | /* signal (SIGURG, SIG_DFL); */ |
552 | /* signal (SIGURG, SIG_DFL); */ |
415 | |
553 | |
416 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
554 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
417 | // TODO: handle this with exceptions and tolerate the memory loss |
555 | // TODO: handle this with exceptions and tolerate the memory loss |
418 | //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); |
556 | XSetIOErrorHandler (rxvt_xioerror_handler); |
419 | } |
557 | } |
420 | |
558 | |
421 | /* ------------------------------------------------------------------------- * |
559 | /* ------------------------------------------------------------------------- * |
422 | * SIGNAL HANDLING & EXIT HANDLER * |
560 | * SIGNAL HANDLING & EXIT HANDLER * |
423 | * ------------------------------------------------------------------------- */ |
561 | * ------------------------------------------------------------------------- */ |
… | |
… | |
436 | if (pid == (*t)->cmd_pid) |
574 | if (pid == (*t)->cmd_pid) |
437 | { |
575 | { |
438 | (*t)->destroy (); |
576 | (*t)->destroy (); |
439 | break; |
577 | break; |
440 | } |
578 | } |
441 | } |
|
|
442 | |
|
|
443 | /*----------------------------------------------------------------------*/ |
|
|
444 | /* |
|
|
445 | * Exit gracefully, clearing the utmp entry and restoring tty attributes |
|
|
446 | * TODO: if debugging, this should free up any known resources if we can |
|
|
447 | */ |
|
|
448 | void |
|
|
449 | rxvt_destroy_all () |
|
|
450 | { |
|
|
451 | // TODO: rxvtd should clean up all ressources |
|
|
452 | for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) |
|
|
453 | (*t)->destroy (); |
|
|
454 | } |
|
|
455 | |
|
|
456 | /* |
|
|
457 | * Catch a fatal signal and tidy up before quitting |
|
|
458 | */ |
|
|
459 | void |
|
|
460 | rxvt_term::sig_term (sig_watcher &w) |
|
|
461 | { |
|
|
462 | #ifdef DEBUG_CMD |
|
|
463 | rxvt_warn ("caught signal %d, exiting.\n", w.signum); |
|
|
464 | #endif |
|
|
465 | rxvt_destroy_all (); |
|
|
466 | signal (w.signum, SIG_DFL); |
|
|
467 | kill (getpid (), w.signum); |
|
|
468 | } |
|
|
469 | |
|
|
470 | /* INTPROTO */ |
|
|
471 | int |
|
|
472 | rxvt_xerror_handler (Display *display, XErrorEvent *event) |
|
|
473 | { |
|
|
474 | if (GET_R->allowedxerror == -1) |
|
|
475 | GET_R->allowedxerror = event->error_code; |
|
|
476 | else |
|
|
477 | { |
|
|
478 | old_xerror_handler (display, event); |
|
|
479 | GET_R->destroy (); |
|
|
480 | } |
|
|
481 | |
|
|
482 | return 0; |
|
|
483 | } |
579 | } |
484 | |
580 | |
485 | /* ------------------------------------------------------------------------- * |
581 | /* ------------------------------------------------------------------------- * |
486 | * MEMORY ALLOCATION WRAPPERS * |
582 | * MEMORY ALLOCATION WRAPPERS * |
487 | * ------------------------------------------------------------------------- */ |
583 | * ------------------------------------------------------------------------- */ |
… | |
… | |
600 | * if width/height are non-zero then override calculated width/height |
696 | * if width/height are non-zero then override calculated width/height |
601 | */ |
697 | */ |
602 | void |
698 | void |
603 | rxvt_term::window_calc (unsigned int width, unsigned int height) |
699 | rxvt_term::window_calc (unsigned int width, unsigned int height) |
604 | { |
700 | { |
605 | short recalc_x, recalc_y; |
701 | short recalc_x, recalc_y; |
606 | int x, y, sb_w, mb_h, flags; |
702 | int x, y, sb_w, mb_h, flags; |
607 | unsigned int w, h; |
703 | unsigned int w, h; |
608 | unsigned int max_width, max_height; |
704 | unsigned int max_width, max_height; |
|
|
705 | dDisp; |
609 | |
706 | |
610 | D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
707 | D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
611 | TermWin.ncol, TermWin.nrow, szHint.width, |
708 | TermWin.ncol, TermWin.nrow, szHint.width, |
612 | szHint.height)); |
709 | szHint.height)); |
613 | szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; |
710 | szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; |
… | |
… | |
619 | if (!parsed_geometry) |
716 | if (!parsed_geometry) |
620 | { |
717 | { |
621 | parsed_geometry = 1; |
718 | parsed_geometry = 1; |
622 | if (rs[Rs_geometry]) |
719 | if (rs[Rs_geometry]) |
623 | flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h); |
720 | flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h); |
|
|
721 | |
624 | if (flags & WidthValue) |
722 | if (flags & WidthValue) |
625 | { |
723 | { |
626 | TermWin.ncol = BOUND_POSITIVE_INT16 (w); |
724 | TermWin.ncol = BOUND_POSITIVE_INT16 (w); |
627 | szHint.flags |= USSize; |
725 | szHint.flags |= USSize; |
628 | } |
726 | } |
|
|
727 | |
629 | if (flags & HeightValue) |
728 | if (flags & HeightValue) |
630 | { |
729 | { |
631 | TermWin.nrow = BOUND_POSITIVE_INT16 (h); |
730 | TermWin.nrow = BOUND_POSITIVE_INT16 (h); |
632 | szHint.flags |= USSize; |
731 | szHint.flags |= USSize; |
633 | } |
732 | } |
|
|
733 | |
634 | if (flags & XValue) |
734 | if (flags & XValue) |
635 | { |
735 | { |
636 | szHint.x = x; |
736 | szHint.x = x; |
637 | szHint.flags |= USPosition; |
737 | szHint.flags |= USPosition; |
638 | if (flags & XNegative) |
738 | if (flags & XNegative) |
639 | { |
739 | { |
640 | recalc_x = 1; |
740 | recalc_x = 1; |
641 | szHint.win_gravity = NorthEastGravity; |
741 | szHint.win_gravity = NorthEastGravity; |
642 | } |
742 | } |
643 | } |
743 | } |
|
|
744 | |
644 | if (flags & YValue) |
745 | if (flags & YValue) |
645 | { |
746 | { |
646 | szHint.y = y; |
747 | szHint.y = y; |
647 | szHint.flags |= USPosition; |
748 | szHint.flags |= USPosition; |
648 | if (flags & YNegative) |
749 | if (flags & YNegative) |
… | |
… | |
711 | |
812 | |
712 | if (scrollbar_visible () && (options & Opt_scrollBar_right)) |
813 | if (scrollbar_visible () && (options & Opt_scrollBar_right)) |
713 | window_sb_x = szHint.width - sb_w; |
814 | window_sb_x = szHint.width - sb_w; |
714 | |
815 | |
715 | if (recalc_x) |
816 | if (recalc_x) |
716 | szHint.x += (DisplayWidth (display->display, DefaultScreen (display->display)) |
817 | szHint.x += (DisplayWidth (disp, display->screen) |
717 | - szHint.width - 2 * TermWin.ext_bwidth); |
818 | - szHint.width - 2 * TermWin.ext_bwidth); |
718 | if (recalc_y) |
819 | if (recalc_y) |
719 | szHint.y += (DisplayHeight (display->display, DefaultScreen (display->display)) |
820 | szHint.y += (DisplayHeight (disp, display->screen) |
720 | - szHint.height - 2 * TermWin.ext_bwidth); |
821 | - szHint.height - 2 * TermWin.ext_bwidth); |
721 | |
822 | |
722 | TermWin.ncol = TermWin.width / TermWin.fwidth; |
823 | TermWin.ncol = TermWin.width / TermWin.fwidth; |
723 | TermWin.nrow = TermWin.height / TermWin.fheight; |
824 | TermWin.nrow = TermWin.height / TermWin.fheight; |
724 | D_SIZE ((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
825 | D_SIZE ((stderr, "> Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", |
… | |
… | |
783 | |
884 | |
784 | delete TermWin.fontset[0]; |
885 | delete TermWin.fontset[0]; |
785 | TermWin.fontset[0] = fs; |
886 | TermWin.fontset[0] = fs; |
786 | |
887 | |
787 | prop = (*fs)[1]->properties (); |
888 | prop = (*fs)[1]->properties (); |
|
|
889 | prop.height += TermWin.lineSpace; |
788 | fs->set_prop (prop); |
890 | fs->set_prop (prop); |
789 | |
891 | |
790 | TermWin.fwidth = prop.width; |
892 | TermWin.fwidth = prop.width; |
791 | TermWin.fheight = prop.height; |
893 | TermWin.fheight = prop.height; |
792 | TermWin.fweight = prop.weight; |
894 | TermWin.fweight = prop.weight; |
… | |
… | |
831 | } |
933 | } |
832 | |
934 | |
833 | return true; |
935 | return true; |
834 | } |
936 | } |
835 | |
937 | |
|
|
938 | void rxvt_term::set_string_property (Atom prop, const char *str, int len) |
|
|
939 | { |
|
|
940 | // TODO: SMART_WINDOW_TITLE |
|
|
941 | XChangeProperty (display->display, TermWin.parent[0], |
|
|
942 | prop, XA_STRING, 8, PropModeReplace, |
|
|
943 | (const unsigned char *)str, len >= 0 ? len : strlen (str)); |
|
|
944 | } |
|
|
945 | |
|
|
946 | void rxvt_term::set_utf8_property (Atom prop, const char *str, int len) |
|
|
947 | { |
|
|
948 | // TODO: SMART_WINDOW_TITLE |
|
|
949 | wchar_t *ws = rxvt_mbstowcs (str, len); |
|
|
950 | char *s = rxvt_wcstoutf8 (ws); |
|
|
951 | |
|
|
952 | XChangeProperty (display->display, TermWin.parent[0], |
|
|
953 | prop, xa[XA_UTF8_STRING], 8, PropModeReplace, |
|
|
954 | (const unsigned char *)s, strlen (s)); |
|
|
955 | |
|
|
956 | free (s); |
|
|
957 | free (ws); |
|
|
958 | } |
|
|
959 | |
836 | /*----------------------------------------------------------------------*/ |
960 | /*----------------------------------------------------------------------*/ |
837 | /*----------------------------------------------------------------------*/ |
961 | /*----------------------------------------------------------------------*/ |
838 | /* xterm sequences - title, iconName, color (exptl) */ |
962 | /* xterm sequences - title, iconName, color (exptl) */ |
839 | void |
963 | void |
840 | rxvt_term::set_title (const char *str) |
964 | rxvt_term::set_title (const char *str) |
841 | { |
965 | { |
842 | #ifdef SMART_WINDOW_TITLE |
966 | set_string_property (XA_WM_NAME, str); |
843 | char *name; |
967 | #if ENABLE_FRILLS |
844 | |
968 | set_utf8_property (xa[XA_NET_WM_NAME], str); |
845 | if (!XFetchName (display->display, TermWin.parent[0], &name)) |
|
|
846 | name = NULL; |
|
|
847 | |
|
|
848 | if (name == NULL || strcmp (name, str)) |
|
|
849 | #endif |
|
|
850 | XStoreName (display->display, TermWin.parent[0], str); |
|
|
851 | |
|
|
852 | #ifdef SMART_WINDOW_TITLE |
|
|
853 | if (name) |
|
|
854 | XFree (name); |
|
|
855 | #endif |
969 | #endif |
856 | } |
970 | } |
857 | |
971 | |
858 | void |
972 | void |
859 | rxvt_term::set_icon_name (const char *str) |
973 | rxvt_term::set_icon_name (const char *str) |
860 | { |
974 | { |
861 | #ifdef SMART_WINDOW_TITLE |
975 | set_string_property (XA_WM_ICON_NAME, str); |
862 | char *name; |
976 | #if ENABLE_FRILLS |
863 | |
977 | set_utf8_property (xa[XA_NET_WM_ICON_NAME], str); |
864 | if (!XGetIconName (display->display, TermWin.parent[0], &name)) |
|
|
865 | name = NULL; |
|
|
866 | |
|
|
867 | if (name == NULL || strcmp (name, str)) |
|
|
868 | #endif |
|
|
869 | XSetIconName (display->display, TermWin.parent[0], str); |
|
|
870 | |
|
|
871 | #ifdef SMART_WINDOW_TITLE |
|
|
872 | if (name) |
|
|
873 | XFree (name); |
|
|
874 | #endif |
978 | #endif |
875 | } |
979 | } |
876 | |
980 | |
877 | #ifdef XTERM_COLOR_CHANGE |
981 | #ifdef XTERM_COLOR_CHANGE |
878 | void |
982 | void |
… | |
… | |
886 | |
990 | |
887 | /* handle color aliases */ |
991 | /* handle color aliases */ |
888 | if (isdigit (*color)) |
992 | if (isdigit (*color)) |
889 | { |
993 | { |
890 | i = atoi (color); |
994 | i = atoi (color); |
|
|
995 | |
891 | if (i >= 8 && i <= 15) |
996 | if (i >= 8 && i <= 15) |
892 | { /* bright colors */ |
997 | { /* bright colors */ |
893 | i -= 8; |
998 | i -= 8; |
894 | # ifndef NO_BRIGHTCOLOR |
999 | # ifndef NO_BRIGHTCOLOR |
895 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
1000 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
896 | SET_PIXCOLOR (idx); |
1001 | SET_PIXCOLOR (idx); |
897 | goto Done; |
1002 | goto Done; |
898 | # endif |
1003 | # endif |
899 | |
|
|
900 | } |
1004 | } |
|
|
1005 | |
901 | if (i >= 0 && i <= 7) |
1006 | if (i >= 0 && i <= 7) |
902 | { /* normal colors */ |
1007 | { /* normal colors */ |
903 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
1008 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
904 | SET_PIXCOLOR (idx); |
1009 | SET_PIXCOLOR (idx); |
905 | goto Done; |
1010 | goto Done; |
906 | } |
1011 | } |
907 | } |
1012 | } |
908 | |
1013 | |
909 | if (!rXParseAllocColor (& xcol, color)) |
1014 | if (!rXParseAllocColor (&xcol, color)) |
910 | return; |
1015 | return; |
911 | |
1016 | |
912 | /* XStoreColor (display->display, display->cmap, XColor*); */ |
1017 | /* XStoreColor (display->display, display->cmap, XColor*); */ |
913 | |
1018 | |
914 | /* |
1019 | /* |
… | |
… | |
997 | |
1102 | |
998 | sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); |
1103 | sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); |
999 | } |
1104 | } |
1000 | |
1105 | |
1001 | /*----------------------------------------------------------------------*/ |
1106 | /*----------------------------------------------------------------------*/ |
1002 | /* |
|
|
1003 | * Colour determination for low colour displays, routine from |
|
|
1004 | * Hans de Goede <hans@highrise.nl> |
|
|
1005 | */ |
|
|
1006 | |
1107 | |
1007 | int |
1108 | int |
1008 | rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) |
1109 | rxvt_term::rXParseAllocColor (rxvt_color *screen_in_out, const char *colour) |
1009 | { |
1110 | { |
1010 | if (!screen_in_out->set (display, colour)) |
1111 | if (!screen_in_out->set (display, colour)) |
… | |
… | |
1021 | * -------------------------------------------------------------------- */ |
1122 | * -------------------------------------------------------------------- */ |
1022 | void |
1123 | void |
1023 | rxvt_term::resize_all_windows (unsigned int width, unsigned int height, int ignoreparent) |
1124 | rxvt_term::resize_all_windows (unsigned int width, unsigned int height, int ignoreparent) |
1024 | { |
1125 | { |
1025 | int fix_screen; |
1126 | int fix_screen; |
1026 | |
|
|
1027 | #ifdef SMART_RESIZE |
1127 | #ifdef SMART_RESIZE |
1028 | int old_width = szHint.width, old_height = szHint.height; |
1128 | int old_width = szHint.width, old_height = szHint.height; |
1029 | #endif |
1129 | #endif |
|
|
1130 | dDisp; |
1030 | |
1131 | |
1031 | window_calc (width, height); |
1132 | window_calc (width, height); |
1032 | XSetWMNormalHints (display->display, TermWin.parent[0], &szHint); |
1133 | XSetWMNormalHints (disp, TermWin.parent[0], &szHint); |
1033 | |
1134 | |
1034 | if (!ignoreparent) |
1135 | if (!ignoreparent) |
1035 | { |
1136 | { |
1036 | #ifdef SMART_RESIZE |
1137 | #ifdef SMART_RESIZE |
1037 | /* |
1138 | /* |
… | |
… | |
1041 | int x, y, x1, y1; |
1142 | int x, y, x1, y1; |
1042 | int dx, dy; |
1143 | int dx, dy; |
1043 | unsigned int unused_w1, unused_h1, unused_b1, unused_d1; |
1144 | unsigned int unused_w1, unused_h1, unused_b1, unused_d1; |
1044 | Window unused_cr; |
1145 | Window unused_cr; |
1045 | |
1146 | |
1046 | XTranslateCoordinates (display->display, TermWin.parent[0], display->root, |
1147 | XTranslateCoordinates (disp, TermWin.parent[0], display->root, |
1047 | 0, 0, &x, &y, &unused_cr); |
1148 | 0, 0, &x, &y, &unused_cr); |
1048 | XGetGeometry (display->display, TermWin.parent[0], &unused_cr, &x1, &y1, |
1149 | XGetGeometry (disp, TermWin.parent[0], &unused_cr, &x1, &y1, |
1049 | &unused_w1, &unused_h1, &unused_b1, &unused_d1); |
1150 | &unused_w1, &unused_h1, &unused_b1, &unused_d1); |
1050 | /* |
1151 | /* |
1051 | * if display->root isn't the parent window, a WM will probably have offset |
1152 | * if display->root isn't the parent window, a WM will probably have offset |
1052 | * our position for handles and decorations. Counter it |
1153 | * our position for handles and decorations. Counter it |
1053 | */ |
1154 | */ |
… | |
… | |
1055 | { |
1156 | { |
1056 | x -= x1; |
1157 | x -= x1; |
1057 | y -= y1; |
1158 | y -= y1; |
1058 | } |
1159 | } |
1059 | |
1160 | |
1060 | x1 = (DisplayWidth (display->display, display->screen) - old_width) / 2; |
1161 | x1 = (DisplayWidth (disp, display->screen) - old_width) / 2; |
1061 | y1 = (DisplayHeight (display->display, display->screen) - old_height) / 2; |
1162 | y1 = (DisplayHeight (disp, display->screen) - old_height) / 2; |
1062 | dx = old_width - szHint.width; |
1163 | dx = old_width - szHint.width; |
1063 | dy = old_height - szHint.height; |
1164 | dy = old_height - szHint.height; |
1064 | |
1165 | |
1065 | /* Check position of the center of the window */ |
1166 | /* Check position of the center of the window */ |
1066 | if (x < x1) /* left half */ |
1167 | if (x < x1) /* left half */ |
… | |
… | |
1070 | if (y < y1) /* top half */ |
1171 | if (y < y1) /* top half */ |
1071 | dy = 0; |
1172 | dy = 0; |
1072 | else if (y == y1) /* exact center */ |
1173 | else if (y == y1) /* exact center */ |
1073 | dy /= 2; |
1174 | dy /= 2; |
1074 | |
1175 | |
1075 | XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy, |
1176 | XMoveResizeWindow (disp, TermWin.parent[0], x + dx, y + dy, |
1076 | szHint.width, szHint.height); |
1177 | szHint.width, szHint.height); |
1077 | #else |
1178 | #else |
1078 | XResizeWindow (display->display, TermWin.parent[0], szHint.width, szHint.height); |
1179 | XResizeWindow (disp, TermWin.parent[0], szHint.width, szHint.height); |
1079 | #endif |
1180 | #endif |
1080 | } |
1181 | } |
1081 | |
1182 | |
1082 | fix_screen = TermWin.ncol != prev_ncol || TermWin.nrow != prev_nrow; |
1183 | fix_screen = TermWin.ncol != prev_ncol || TermWin.nrow != prev_nrow; |
1083 | |
1184 | |
1084 | if (fix_screen || width != old_width || height != old_height) |
1185 | if (fix_screen || width != old_width || height != old_height) |
1085 | { |
1186 | { |
1086 | if (scrollbar_visible ()) |
1187 | if (scrollbar_visible ()) |
1087 | { |
1188 | { |
1088 | XMoveResizeWindow (display->display, scrollBar.win, |
1189 | XMoveResizeWindow (disp, scrollBar.win, |
1089 | window_sb_x, 0, |
1190 | window_sb_x, 0, |
1090 | scrollbar_TotalWidth (), szHint.height); |
1191 | scrollbar_TotalWidth (), szHint.height); |
1091 | resize_scrollbar (); |
1192 | resize_scrollbar (); |
1092 | } |
1193 | } |
1093 | |
1194 | |
1094 | if (menubar_visible ()) |
1195 | if (menubar_visible ()) |
1095 | XMoveResizeWindow (display->display, menuBar.win, |
1196 | XMoveResizeWindow (disp, menuBar.win, |
1096 | window_vt_x, 0, |
1197 | window_vt_x, 0, |
1097 | TermWin_TotalWidth (), menuBar_TotalHeight ()); |
1198 | TermWin_TotalWidth (), menuBar_TotalHeight ()); |
1098 | |
1199 | |
1099 | XMoveResizeWindow (display->display, TermWin.vt, |
1200 | XMoveResizeWindow (disp, TermWin.vt, |
1100 | window_vt_x, window_vt_y, |
1201 | window_vt_x, window_vt_y, |
1101 | TermWin_TotalWidth (), TermWin_TotalHeight ()); |
1202 | TermWin_TotalWidth (), TermWin_TotalHeight ()); |
|
|
1203 | |
1102 | scr_clear (); |
1204 | scr_clear (); |
1103 | #ifdef XPM_BACKGROUND |
1205 | #ifdef XPM_BACKGROUND |
1104 | resize_pixmap (); |
1206 | resize_pixmap (); |
1105 | #endif |
1207 | #endif |
1106 | } |
1208 | } |
… | |
… | |
1128 | } |
1230 | } |
1129 | } |
1231 | } |
1130 | |
1232 | |
1131 | old_width = szHint.width; |
1233 | old_width = szHint.width; |
1132 | old_height = szHint.height; |
1234 | old_height = szHint.height; |
|
|
1235 | |
|
|
1236 | #ifdef XPM_BACKGROUND |
|
|
1237 | if (TermWin.pixmap) |
|
|
1238 | scr_touch (false); |
|
|
1239 | #endif |
1133 | |
1240 | |
1134 | #ifdef USE_XIM |
1241 | #ifdef USE_XIM |
1135 | IMSetStatusPosition (); |
1242 | IMSetStatusPosition (); |
1136 | #endif |
1243 | #endif |
1137 | } |
1244 | } |
… | |
… | |
1367 | "*", |
1474 | "*", |
1368 | TermWin.fheight, |
1475 | TermWin.fheight, |
1369 | TermWin.fheight + 1, TermWin.fheight - 1, |
1476 | TermWin.fheight + 1, TermWin.fheight - 1, |
1370 | TermWin.fheight - 2, TermWin.fheight + 2); |
1477 | TermWin.fheight - 2, TermWin.fheight + 2); |
1371 | |
1478 | |
1372 | fs = XCreateFontSet (display->display, pat, |
1479 | fs = XCreateFontSet (display->display, rs[Rs_imFont] ? rs[Rs_imFont] : pat, |
1373 | &missing_charset_list, &missing_charset_count, &def_string); |
1480 | &missing_charset_list, &missing_charset_count, &def_string); |
1374 | |
1481 | |
1375 | if (missing_charset_list) |
1482 | if (missing_charset_list) |
1376 | XFreeStringList (missing_charset_list); |
1483 | XFreeStringList (missing_charset_list); |
1377 | |
1484 | |
… | |
… | |
1453 | { |
1560 | { |
1454 | int i, found, had_im; |
1561 | int i, found, had_im; |
1455 | const char *p; |
1562 | const char *p; |
1456 | char **s; |
1563 | char **s; |
1457 | char buf[IMBUFSIZ]; |
1564 | char buf[IMBUFSIZ]; |
|
|
1565 | |
|
|
1566 | SET_R (this); |
1458 | |
1567 | |
1459 | im_destroy (); |
1568 | im_destroy (); |
1460 | |
1569 | |
1461 | D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); |
1570 | D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); |
1462 | if (Input_Context) |
1571 | if (Input_Context) |