ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/main.C
(Generate patch)

Comparing rxvt-unicode/src/main.C (file contents):
Revision 1.391 by sf-exg, Mon Oct 6 11:11:19 2014 UTC vs.
Revision 1.400 by sf-exg, Tue Jun 28 21:56:17 2016 UTC

11 * Copyright (c) 1997 mj olesen <olesen@me.QueensU.CA> 11 * Copyright (c) 1997 mj olesen <olesen@me.QueensU.CA>
12 * - extensive modifications 12 * - extensive modifications
13 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> 13 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de>
14 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> 14 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com>
15 * - extensive modifications 15 * - extensive modifications
16 * Copyright (c) 2003-2010 Marc Lehmann <schmorp@schmorp.de> 16 * Copyright (c) 2003-2014 Marc Lehmann <schmorp@schmorp.de>
17 * Copyright (c) 2015 Emanuele Giaquinta <e.giaquinta@glauco.it>
17 * 18 *
18 * This program is free software; you can redistribute it and/or modify 19 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by 20 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 3 of the License, or 21 * the Free Software Foundation; either version 3 of the License, or
21 * (at your option) any later version. 22 * (at your option) any later version.
254 for (int i = 0; i < TOTAL_COLORS; i++) 255 for (int i = 0; i < TOTAL_COLORS; i++)
255 if (ISSET_PIXCOLOR (i)) 256 if (ISSET_PIXCOLOR (i))
256 { 257 {
257 pix_colors_focused [i].free (this); 258 pix_colors_focused [i].free (this);
258#if OFF_FOCUS_FADING 259#if OFF_FOCUS_FADING
260 if (rs[Rs_fade])
259 pix_colors_unfocused [i].free (this); 261 pix_colors_unfocused [i].free (this);
260#endif 262#endif
261 } 263 }
262 264
263 clear (); 265 clear ();
264 266
277 free (locale); 279 free (locale);
278 free (v_buffer); 280 free (v_buffer);
279 281
280 delete selection_req; 282 delete selection_req;
281 283
282 if (memcmp (env, envv->begin (), envv->size () * sizeof (char *))) 284 if (env && memcmp (env, envv->begin (), envv->size () * sizeof (char *)))
283 rxvt_warn ("env has been modified, probably as a result of a lib calling setenv.\n"); 285 rxvt_warn ("env has been modified, probably as a result of a lib calling setenv.\n");
284 286
285 delete env; 287 delete [] env;
286 288
287 delete envv; 289 delete envv;
288 delete argv; 290 delete argv;
289 291
290#ifdef KEYSYM_RESOURCE 292#ifdef KEYSYM_RESOURCE
291 delete keyboard; 293 delete keyboard;
292#endif 294#endif
293#ifndef NO_RESOURCES 295#ifndef NO_RESOURCES
294 XrmDestroyDatabase (option_db); 296 XrmDestroyDatabase (option_db);
295#endif 297#endif
298
299 SET_R ((rxvt_term *)0);
296} 300}
297 301
298// child has exited, usually destroys 302// child has exited, usually destroys
299void 303void
300rxvt_term::child_cb (ev::child &w, int status) 304rxvt_term::child_cb (ev::child &w, int status)
388 392
389#if !ENABLE_MINIMAL 393#if !ENABLE_MINIMAL
390static void ecb_cold 394static void ecb_cold
391print_x_error (Display *dpy, XErrorEvent *event) 395print_x_error (Display *dpy, XErrorEvent *event)
392{ 396{
393 char buffer[BUFSIZ]; 397 char buffer[BUFSIZ];
394 char mesg[BUFSIZ]; 398 char mesg[BUFSIZ];
395 char number[32]; 399 char number[32];
396 400
397 rxvt_warn ("An X Error occurred, trying to continue after report.\n"); 401 rxvt_warn ("An X Error occurred, trying to continue after report.\n");
398 402
399 XGetErrorDatabaseText (dpy, "XlibMessage", "ErrorSerial", "Error Serial #%d", mesg, BUFSIZ); 403 XGetErrorDatabaseText (dpy, "XlibMessage", "ErrorSerial", "Error Serial #%d", mesg, BUFSIZ);
400 snprintf (buffer, BUFSIZ, "+ %s\n", mesg); rxvt_warn (buffer, event->serial); 404 snprintf (buffer, BUFSIZ, "+ %s\n", mesg); rxvt_warn (buffer, event->serial);
401 405
402 XGetErrorText (dpy, event->error_code, buffer, BUFSIZ); 406 XGetErrorText (dpy, event->error_code, buffer, BUFSIZ);
403 XGetErrorDatabaseText (dpy, "XlibMessage", "XError", "X Error", mesg, BUFSIZ); 407 XGetErrorDatabaseText (dpy, "XlibMessage", "XError", "X Error", mesg, BUFSIZ);
404 rxvt_warn ("+ %s: %s\n", mesg, buffer); 408 rxvt_warn ("+ %s: %s\n", mesg, buffer);
405 409
406 XGetErrorDatabaseText (dpy, "XlibMessage", "MajorCode", "Request Major code %d", mesg, BUFSIZ); 410 XGetErrorDatabaseText (dpy, "XlibMessage", "MajorCode", "Request Major code %d", mesg, BUFSIZ);
407 snprintf (buffer, BUFSIZ, "+ %s\n", mesg); rxvt_warn (buffer, event->request_code); 411 snprintf (buffer, BUFSIZ, "+ %s\n", mesg); rxvt_warn (buffer, event->request_code);
408 412
409 if (event->request_code >= 128) 413 if (event->request_code >= 128)
410 { 414 {
411#if 0 415#if 0
412 /* XListExtensions and probably query extensions hangs when there are multiple queues errors */ 416 /* XListExtensions and probably query extensions hangs when there are multiple queues errors */
413 int nexts; 417 int nexts;
414 char **exts = XListExtensions (dpy, &nexts); 418 char **exts = XListExtensions (dpy, &nexts);
415 419
416 while (nexts) 420 while (nexts)
417 { 421 {
418 char *extname = exts [nexts - 1]; 422 char *extname = exts [nexts - 1];
419 int major, first_event, first_error; 423 int major, first_event, first_error;
420 424
421 if (XQueryExtension (dpy, extname, &major, &first_event, &first_error) && major == event->request_code) 425 if (XQueryExtension (dpy, extname, &major, &first_event, &first_error) && major == event->request_code)
422 { 426 {
423 XGetErrorDatabaseText (dpy, "XlibMessage", "MinorCode", "Request Minor code %d", mesg, BUFSIZ); 427 XGetErrorDatabaseText (dpy, "XlibMessage", "MinorCode", "Request Minor code %d", mesg, BUFSIZ);
424 rxvt_warn ("+ (which is extension %s minor code %d)\n", extname, event->minor_code); 428 rxvt_warn ("+ (which is extension %s minor code %d)\n", extname, event->minor_code);
425 429
426 snprintf (buffer, BUFSIZ, "%s.%d", extname, event->minor_code); 430 snprintf (buffer, BUFSIZ, "%s.%d", extname, event->minor_code);
427 XGetErrorDatabaseText (dpy, "XRequest", buffer, "an unregistered minor code", buffer, BUFSIZ); 431 XGetErrorDatabaseText (dpy, "XRequest", buffer, "an unregistered minor code", buffer, BUFSIZ);
428 rxvt_warn ("+ (which is %s)\n", buffer); 432 rxvt_warn ("+ (which is %s)\n", buffer);
429 433
430 break; 434 break;
431 } 435 }
432 436
433 printf ("nextss %d %s\n", nexts, extname);//D 437 printf ("nextss %d %s\n", nexts, extname);//D
434 --nexts; 438 --nexts;
435 ++exts; 439 ++exts;
436 } 440 }
437#else 441#else
438 int nexts = 0; 442 int nexts = 0;
439 char **exts = 0; 443 char **exts = 0;
440#endif 444#endif
441 445
442 if (!nexts) 446 if (!nexts)
443 { 447 {
444 rxvt_warn ("+ (which is an unknown extension)\n", buffer); 448 rxvt_warn ("+ (which is an unknown extension)\n", buffer);
445 449
446 XGetErrorDatabaseText (dpy, "XlibMessage", "MinorCode", "Request Minor code %d", mesg, BUFSIZ); 450 XGetErrorDatabaseText (dpy, "XlibMessage", "MinorCode", "Request Minor code %d", mesg, BUFSIZ);
447 snprintf (buffer, BUFSIZ, "+ %s\n", mesg); rxvt_warn (buffer, event->minor_code); 451 snprintf (buffer, BUFSIZ, "+ %s\n", mesg); rxvt_warn (buffer, event->minor_code);
448 452
449#if 0 453#if 0
450 sprintf (number, "RENDER.%d", event->minor_code); 454 sprintf (number, "RENDER.%d", event->minor_code);
451 XGetErrorDatabaseText (dpy, "XRequest", number, "", buffer, BUFSIZ); 455 XGetErrorDatabaseText (dpy, "XRequest", number, "", buffer, BUFSIZ);
452 rxvt_warn ("+ (which is %s)\n", buffer); 456 rxvt_warn ("+ (which is %s)\n", buffer);
453#endif 457#endif
454 } 458 }
455 459
456 XFreeExtensionList (exts); 460 XFreeExtensionList (exts);
457 } 461 }
458 else 462 else
459 { 463 {
460 sprintf (number, "%d", event->request_code); 464 sprintf (number, "%d", event->request_code);
461 XGetErrorDatabaseText (dpy, "XRequest", number, "", buffer, BUFSIZ); 465 XGetErrorDatabaseText (dpy, "XRequest", number, "", buffer, BUFSIZ);
462 rxvt_warn ("+ (which is %s)\n", buffer); 466 rxvt_warn ("+ (which is %s)\n", buffer);
463 } 467 }
464 468
465 if (event->error_code == BadWindow 469 if (event->error_code == BadWindow
466 || event->error_code == BadPixmap 470 || event->error_code == BadPixmap
467 || event->error_code == BadCursor 471 || event->error_code == BadCursor
468 || event->error_code == BadFont 472 || event->error_code == BadFont
469 || event->error_code == BadDrawable 473 || event->error_code == BadDrawable
470 || event->error_code == BadColor 474 || event->error_code == BadColor
471 || event->error_code == BadGC 475 || event->error_code == BadGC
472 || event->error_code == BadIDChoice 476 || event->error_code == BadIDChoice
473 || event->error_code == BadValue 477 || event->error_code == BadValue
474 || event->error_code == BadAtom) 478 || event->error_code == BadAtom)
475 { 479 {
476 if (event->error_code == BadValue) 480 if (event->error_code == BadValue)
477 XGetErrorDatabaseText (dpy, "XlibMessage", "Value", "Value 0x%x", mesg, BUFSIZ); 481 XGetErrorDatabaseText (dpy, "XlibMessage", "Value", "Value 0x%x", mesg, BUFSIZ);
478 else if (event->error_code == BadAtom) 482 else if (event->error_code == BadAtom)
479 XGetErrorDatabaseText (dpy, "XlibMessage", "AtomID", "AtomID 0x%x", mesg, BUFSIZ); 483 XGetErrorDatabaseText (dpy, "XlibMessage", "AtomID", "AtomID 0x%x", mesg, BUFSIZ);
480 else 484 else
481 XGetErrorDatabaseText (dpy, "XlibMessage", "ResourceID", "ResourceID 0x%x", mesg, BUFSIZ); 485 XGetErrorDatabaseText (dpy, "XlibMessage", "ResourceID", "ResourceID 0x%x", mesg, BUFSIZ);
482 486
483 snprintf (buffer, BUFSIZ, "+ %s\n", mesg); rxvt_warn (buffer, event->resourceid); 487 snprintf (buffer, BUFSIZ, "+ %s\n", mesg); rxvt_warn (buffer, event->resourceid);
484 } 488 }
485} 489}
486#endif 490#endif
487 491
488int ecb_cold 492int ecb_cold
489rxvt_xerror_handler (Display *display, XErrorEvent *event) 493rxvt_xerror_handler (Display *display, XErrorEvent *event)
490{ 494{
491 if (GET_R->allowedxerror == -1) 495 if (GET_R && GET_R->allowedxerror == -1)
492 GET_R->allowedxerror = event->error_code; 496 GET_R->allowedxerror = event->error_code;
493 else 497 else
494 { 498 {
495 // GET_R is most likely not the terminal which caused the error, 499 // GET_R is most likely not the terminal which caused the error,
496 // so just output the error and continue 500 // so just output the error and continue
939 943
940void 944void
941rxvt_term::set_window_color (int idx, const char *color) 945rxvt_term::set_window_color (int idx, const char *color)
942{ 946{
943#ifdef XTERM_COLOR_CHANGE 947#ifdef XTERM_COLOR_CHANGE
944 rxvt_color xcol;
945
946 if (color == NULL || *color == '\0') 948 if (color == NULL || *color == '\0')
947 return; 949 return;
948 950
949 color = strdup (color); 951 color = strdup (color);
950 allocated.push_back ((void *)color); 952 allocated.push_back ((void *)color);
956 int i = atoi (color); 958 int i = atoi (color);
957 959
958 if (i >= 8 && i <= 15) 960 if (i >= 8 && i <= 15)
959 { 961 {
960 /* bright colors */ 962 /* bright colors */
961 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i - 8]; 963 alias_color (idx, minBrightCOLOR + i - 8);
962 goto done; 964 goto done;
963 } 965 }
964 966
965 if (i >= 0 && i <= 7) 967 if (i >= 0 && i <= 7)
966 { 968 {
967 /* normal colors */ 969 /* normal colors */
968 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; 970 alias_color (idx, minCOLOR + i);
969 goto done; 971 goto done;
970 } 972 }
971 } 973 }
972 974
973 set_color (xcol, color); 975 pix_colors_focused[idx].free (this);
974 976 set_color (pix_colors_focused[idx], color);
975 /*
976 * FIXME: should free colors here, but no idea how to do it so instead,
977 * so just keep gobbling up the colormap
978 */
979
980 pix_colors_focused[idx] = xcol;
981 977
982done: 978done:
983 /*TODO: handle Color_BD, scrollbar background, etc. */ 979 /*TODO: handle Color_BD, scrollbar background, etc. */
984 980
985 update_fade_color (idx); 981 update_fade_color (idx);
986 recolour_cursor (); 982 recolor_cursor ();
987 scr_recolour (); 983 scr_recolor ();
988#endif /* XTERM_COLOR_CHANGE */ 984#endif /* XTERM_COLOR_CHANGE */
989} 985}
990 986
991void 987void
992rxvt_term::recolour_cursor () 988rxvt_term::recolor_cursor ()
993{ 989{
994 XColor fg, bg; 990 XColor fg, bg;
995 991
996 (ISSET_PIXCOLOR (Color_pointer_fg) 992 (ISSET_PIXCOLOR (Color_pointer_fg)
997 ? pix_colors_focused[Color_pointer_fg] 993 ? pix_colors_focused[Color_pointer_fg]
1052} 1048}
1053 1049
1054void 1050void
1055rxvt_term::alias_color (int dst, int src) 1051rxvt_term::alias_color (int dst, int src)
1056{ 1052{
1053 pix_colors[dst].free (this);
1057 pix_colors[dst].set (this, rs[Rs_color + dst] = rs[Rs_color + src]); 1054 pix_colors[dst].set (this, rs[Rs_color + dst] = rs[Rs_color + src]);
1058} 1055}
1056
1057#ifdef SMART_RESIZE
1058static unsigned int
1059get_parent_bw (Display *dpy, Window w)
1060{
1061 int idummy;
1062 unsigned int udummy;
1063 Window wdummy, parent;
1064 Window *children;
1065 unsigned int nchildren, border_width;
1066
1067 XQueryTree (dpy, w, &wdummy, &parent, &children, &nchildren);
1068 XFree (children);
1069 XGetGeometry (dpy, parent, &wdummy, &idummy, &idummy,
1070 &udummy, &udummy, &border_width, &udummy);
1071
1072 return border_width;
1073}
1074#endif
1059 1075
1060/* -------------------------------------------------------------------- * 1076/* -------------------------------------------------------------------- *
1061 * - WINDOW RESIZING - * 1077 * - WINDOW RESIZING - *
1062 * -------------------------------------------------------------------- */ 1078 * -------------------------------------------------------------------- */
1063void 1079void
1099 * if display->root isn't the parent window, a WM will probably have offset 1115 * if display->root isn't the parent window, a WM will probably have offset
1100 * our position for handles and decorations. Counter it 1116 * our position for handles and decorations. Counter it
1101 */ 1117 */
1102 if (x1 != x || y1 != y) 1118 if (x1 != x || y1 != y)
1103 { 1119 {
1104 x -= x1; 1120 unsigned int border_width = get_parent_bw (dpy, parent);
1105 y -= y1; 1121
1122 x -= x1 + border_width;
1123 y -= y1 + border_width;
1106 } 1124 }
1107 1125
1108 x1 = (DisplayWidth (dpy, display->screen) - old_width ) / 2; 1126 x1 = (DisplayWidth (dpy, display->screen) - old_width ) / 2;
1109 y1 = (DisplayHeight (dpy, display->screen) - old_height) / 2; 1127 y1 = (DisplayHeight (dpy, display->screen) - old_height) / 2;
1110 dx = old_width - szHint.width; 1128 dx = old_width - szHint.width;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines