… | |
… | |
10 | * Copyright (c) 1996 Chuck Blake <cblake@BBN.COM> |
10 | * Copyright (c) 1996 Chuck Blake <cblake@BBN.COM> |
11 | * Copyright (c) 1997 mj olesen <olesen@me.queensu.ca> |
11 | * Copyright (c) 1997 mj olesen <olesen@me.queensu.ca> |
12 | * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> |
12 | * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> |
13 | * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> |
13 | * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> |
14 | * - extensive modifications |
14 | * - extensive modifications |
15 | * Copyright (c) 2003-2008 Marc Lehmann <pcg@goof.com> |
15 | * Copyright (c) 2003-2008 Marc Lehmann <schmorp@schmorp.de> |
16 | * |
16 | * |
17 | * This program is free software; you can redistribute it and/or modify |
17 | * This program is free software; you can redistribute it and/or modify |
18 | * it under the terms of the GNU General Public License as published by |
18 | * it under the terms of the GNU General Public License as published by |
19 | * the Free Software Foundation; either version 2 of the License, or |
19 | * the Free Software Foundation; either version 2 of the License, or |
20 | * (at your option) any later version. |
20 | * (at your option) any later version. |
… | |
… | |
143 | |
143 | |
144 | return rval; |
144 | return rval; |
145 | } |
145 | } |
146 | #endif |
146 | #endif |
147 | |
147 | |
148 | const char *const def_colorName[] = |
148 | static const char *const def_colorName[] = |
149 | { |
149 | { |
150 | COLOR_FOREGROUND, |
150 | COLOR_FOREGROUND, |
151 | COLOR_BACKGROUND, |
151 | COLOR_BACKGROUND, |
152 | /* low-intensity colors */ |
152 | /* low-intensity colors */ |
153 | "rgb:00/00/00", // 0: black (Black) |
153 | "rgb:00/00/00", // 0: black (Black) |
… | |
… | |
632 | #ifdef HAVE_AFTERIMAGE |
632 | #ifdef HAVE_AFTERIMAGE |
633 | set_application_name ((char *)rs[Rs_name]); |
633 | set_application_name ((char *)rs[Rs_name]); |
634 | set_output_threshold (OUTPUT_LEVEL_WARNING); |
634 | set_output_threshold (OUTPUT_LEVEL_WARNING); |
635 | #endif |
635 | #endif |
636 | |
636 | |
|
|
637 | #ifdef HAVE_PIXBUF |
|
|
638 | g_type_init (); |
|
|
639 | #endif |
|
|
640 | |
637 | #if ENABLE_PERL |
641 | #if ENABLE_PERL |
638 | if (!rs[Rs_perl_ext_1]) |
642 | if (!rs[Rs_perl_ext_1]) |
639 | rs[Rs_perl_ext_1] = "default"; |
643 | rs[Rs_perl_ext_1] = "default"; |
640 | |
644 | |
641 | if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) |
645 | if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) |
… | |
… | |
807 | |
811 | |
808 | if (option (Opt_scrollBar)) |
812 | if (option (Opt_scrollBar)) |
809 | scrollBar.resize (); /* create and map scrollbar */ |
813 | scrollBar.resize (); /* create and map scrollbar */ |
810 | #ifdef HAVE_BG_PIXMAP |
814 | #ifdef HAVE_BG_PIXMAP |
811 | { |
815 | { |
812 | bgPixmap.set_target (this); |
816 | bg_init (); |
813 | bgPixmap.invalidate (); |
|
|
814 | |
817 | |
815 | #ifdef ENABLE_TRANSPARENCY |
818 | #ifdef ENABLE_TRANSPARENCY |
816 | if (option (Opt_transparent)) |
819 | if (option (Opt_transparent)) |
817 | { |
820 | { |
818 | bgPixmap.set_transparent (); |
821 | bg_set_transparent (); |
819 | |
822 | |
820 | #ifdef HAVE_AFTERIMAGE |
|
|
821 | if (rs [Rs_blurradius]) |
823 | if (rs [Rs_blurradius]) |
822 | bgPixmap.set_blur_radius (rs [Rs_blurradius]); |
824 | bg_set_blur (rs [Rs_blurradius]); |
823 | #endif |
825 | |
824 | if (ISSET_PIXCOLOR (Color_tint)) |
826 | if (ISSET_PIXCOLOR (Color_tint)) |
825 | bgPixmap.set_tint (pix_colors_focused [Color_tint]); |
827 | bg_set_tint (pix_colors_focused [Color_tint]); |
826 | |
828 | |
827 | if (rs [Rs_shade]) |
829 | if (rs [Rs_shade]) |
828 | bgPixmap.set_shade (rs [Rs_shade]); |
830 | bg_set_shade (rs [Rs_shade]); |
829 | |
831 | |
830 | bgPixmap.set_root_pixmap (); |
832 | bg_set_root_pixmap (); |
831 | XSelectInput (dpy, display->root, PropertyChangeMask); |
833 | XSelectInput (dpy, display->root, PropertyChangeMask); |
832 | rootwin_ev.start (display, display->root); |
834 | rootwin_ev.start (display, display->root); |
833 | } |
835 | } |
834 | #endif |
836 | #endif |
835 | |
837 | |
… | |
… | |
839 | const char *p = rs[Rs_backgroundPixmap]; |
841 | const char *p = rs[Rs_backgroundPixmap]; |
840 | |
842 | |
841 | if ((p = strchr (p, ';')) != 0) |
843 | if ((p = strchr (p, ';')) != 0) |
842 | { |
844 | { |
843 | p++; |
845 | p++; |
844 | bgPixmap.set_geometry (p); |
846 | bg_set_geometry (p); |
845 | } |
847 | } |
846 | else |
848 | else |
847 | bgPixmap.set_defaultGeometry (); |
849 | bg_set_default_geometry (); |
848 | |
850 | |
849 | if (bgPixmap.set_file (rs[Rs_backgroundPixmap])) |
851 | if (bg_set_file (rs[Rs_backgroundPixmap])) |
850 | if (!bgPixmap.window_position_sensitive ()) |
852 | if (!bg_window_position_sensitive ()) |
851 | update_background (); |
853 | update_background (); |
852 | } |
854 | } |
853 | #endif |
855 | #endif |
854 | } |
856 | } |
855 | #endif |
857 | #endif |
… | |
… | |
872 | #if ENABLE_XEMBED |
874 | #if ENABLE_XEMBED |
873 | if (rs[Rs_embed]) |
875 | if (rs[Rs_embed]) |
874 | { |
876 | { |
875 | long info[2] = { 0, XEMBED_MAPPED }; |
877 | long info[2] = { 0, XEMBED_MAPPED }; |
876 | |
878 | |
877 | XChangeProperty (dpy, parent[0], xa[XA_XEMBED_INFO], xa[XA_XEMBED_INFO], |
879 | XChangeProperty (dpy, parent, xa[XA_XEMBED_INFO], xa[XA_XEMBED_INFO], |
878 | 32, PropModeReplace, (unsigned char *)&info, 2); |
880 | 32, PropModeReplace, (unsigned char *)&info, 2); |
879 | } |
881 | } |
880 | #endif |
882 | #endif |
881 | |
883 | |
882 | XMapWindow (dpy, vt); |
884 | XMapWindow (dpy, vt); |
883 | XMapWindow (dpy, parent[0]); |
885 | XMapWindow (dpy, parent); |
884 | |
886 | |
885 | refresh_check (); |
887 | refresh_check (); |
886 | } |
888 | } |
887 | |
889 | |
888 | /*----------------------------------------------------------------------*/ |
890 | /*----------------------------------------------------------------------*/ |
889 | void |
891 | void |
890 | rxvt_term::init_env () |
892 | rxvt_term::init_env () |
891 | { |
893 | { |
892 | int i; |
|
|
893 | char *val; |
894 | char *val; |
894 | |
895 | |
895 | #ifdef DISPLAY_IS_IP |
896 | #ifdef DISPLAY_IS_IP |
896 | /* Fixup display_name for export over pty to any interested terminal |
897 | /* Fixup display_name for export over pty to any interested terminal |
897 | * clients via "ESC[7n" (e.g. shells). Note we use the pure IP number |
898 | * clients via "ESC[7n" (e.g. shells). Note we use the pure IP number |
… | |
… | |
911 | val = XDisplayString (dpy); |
912 | val = XDisplayString (dpy); |
912 | |
913 | |
913 | if (rs[Rs_display_name] == NULL) |
914 | if (rs[Rs_display_name] == NULL) |
914 | rs[Rs_display_name] = val; /* use broken `:0' value */ |
915 | rs[Rs_display_name] = val; /* use broken `:0' value */ |
915 | |
916 | |
916 | i = strlen (val); |
|
|
917 | env_display = (char *)rxvt_malloc (i + 9); |
917 | env_display = (char *)rxvt_malloc (strlen (val) + 9); |
918 | |
918 | |
919 | sprintf (env_display, "DISPLAY=%s", val); |
919 | sprintf (env_display, "DISPLAY=%s", val); |
920 | |
920 | |
921 | sprintf (env_windowid, "WINDOWID=%lu", (unsigned long)parent[0]); |
921 | sprintf (env_windowid, "WINDOWID=%lu", (unsigned long)parent); |
922 | |
922 | |
923 | /* add entries to the environment: |
923 | /* add entries to the environment: |
924 | * @ DISPLAY: in case we started with -display |
924 | * @ DISPLAY: in case we started with -display |
925 | * @ WINDOWID: X window id number of the window |
925 | * @ WINDOWID: X window id number of the window |
926 | * @ COLORTERM: terminal sub-name and also indicates its color |
926 | * @ COLORTERM: terminal sub-name and also indicates its color |
… | |
… | |
1279 | |
1279 | |
1280 | if (i) |
1280 | if (i) |
1281 | ModMetaMask = modmasks[i - 1]; |
1281 | ModMetaMask = modmasks[i - 1]; |
1282 | } |
1282 | } |
1283 | |
1283 | |
|
|
1284 | void |
|
|
1285 | rxvt_term::set_icon (const char *file) |
|
|
1286 | { |
|
|
1287 | #ifdef HAVE_AFTERIMAGE |
|
|
1288 | init_asv (); |
|
|
1289 | |
|
|
1290 | ASImage *im = file2ASImage (file, 0xFFFFFFFF, SCREEN_GAMMA, 0, NULL); |
|
|
1291 | if (!im) |
|
|
1292 | { |
|
|
1293 | rxvt_warn ("Loading image icon failed, continuing without.\n"); |
|
|
1294 | return; |
|
|
1295 | } |
|
|
1296 | |
|
|
1297 | unsigned int w = im->width; |
|
|
1298 | unsigned int h = im->height; |
|
|
1299 | |
|
|
1300 | if (!IN_RANGE_INC (w, 1, 16383) || !IN_RANGE_INC (h, 1, 16383)) |
|
|
1301 | { |
|
|
1302 | rxvt_warn ("Icon image too big, continuing without.\n"); |
|
|
1303 | destroy_asimage (&im); |
|
|
1304 | return; |
|
|
1305 | } |
|
|
1306 | |
|
|
1307 | ASImage *result = scale_asimage (asv, im, |
|
|
1308 | w, h, ASA_ARGB32, |
|
|
1309 | 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
1310 | destroy_asimage (&im); |
|
|
1311 | |
|
|
1312 | if (!result) |
|
|
1313 | { |
|
|
1314 | rxvt_warn ("Icon image transformation to ARGB failed, continuing without.\n"); |
|
|
1315 | return; |
|
|
1316 | } |
|
|
1317 | |
|
|
1318 | long *buffer = (long *)malloc ((2 + w * h) * sizeof (long)); |
|
|
1319 | if (buffer) |
|
|
1320 | { |
|
|
1321 | ARGB32 *asbuf = result->alt.argb32; |
|
|
1322 | buffer [0] = w; |
|
|
1323 | buffer [1] = h; |
|
|
1324 | |
|
|
1325 | for (unsigned int i = 0; i < w * h; ++i) |
|
|
1326 | buffer [i + 2] = asbuf [i]; |
|
|
1327 | |
|
|
1328 | XChangeProperty (dpy, parent, xa[XA_NET_WM_ICON], XA_CARDINAL, 32, |
|
|
1329 | PropModeReplace, (const unsigned char *) buffer, 2 + w * h); |
|
|
1330 | free (buffer); |
|
|
1331 | } |
|
|
1332 | else |
|
|
1333 | rxvt_warn ("Memory allocation for icon hint failed, continuing without.\n"); |
|
|
1334 | |
|
|
1335 | destroy_asimage (&result); |
|
|
1336 | #endif |
|
|
1337 | |
|
|
1338 | #ifdef HAVE_PIXBUF |
|
|
1339 | GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (file, NULL); |
|
|
1340 | if (!pixbuf) |
|
|
1341 | { |
|
|
1342 | rxvt_warn ("Loading image icon failed, continuing without.\n"); |
|
|
1343 | return; |
|
|
1344 | } |
|
|
1345 | |
|
|
1346 | unsigned int w = gdk_pixbuf_get_width (pixbuf); |
|
|
1347 | unsigned int h = gdk_pixbuf_get_height (pixbuf); |
|
|
1348 | |
|
|
1349 | if (!IN_RANGE_INC (w, 1, 16383) || !IN_RANGE_INC (h, 1, 16383)) |
|
|
1350 | { |
|
|
1351 | rxvt_warn ("Icon image too big, continuing without.\n"); |
|
|
1352 | g_object_unref (pixbuf); |
|
|
1353 | return; |
|
|
1354 | } |
|
|
1355 | |
|
|
1356 | if (long *buffer = (long *)malloc ((2 + w * h) * sizeof (long))) |
|
|
1357 | { |
|
|
1358 | int rowstride = gdk_pixbuf_get_rowstride (pixbuf); |
|
|
1359 | unsigned char *row = gdk_pixbuf_get_pixels (pixbuf); |
|
|
1360 | int channels = gdk_pixbuf_get_n_channels (pixbuf); |
|
|
1361 | |
|
|
1362 | buffer [0] = w; |
|
|
1363 | buffer [1] = h; |
|
|
1364 | for (int i = 0; i < h; i++) |
|
|
1365 | { |
|
|
1366 | for (int j = 0; j < w; j++) |
|
|
1367 | { |
|
|
1368 | unsigned char *pixel = row + j * channels; |
|
|
1369 | long value; |
|
|
1370 | |
|
|
1371 | if (channels == 4) |
|
|
1372 | value = pixel[3]; |
|
|
1373 | else |
|
|
1374 | value = (unsigned char)0x00ff; |
|
|
1375 | |
|
|
1376 | value = (value << 8) + pixel[0]; |
|
|
1377 | value = (value << 8) + pixel[1]; |
|
|
1378 | value = (value << 8) + pixel[2]; |
|
|
1379 | buffer[(i * w + j) + 2] = value; |
|
|
1380 | } |
|
|
1381 | |
|
|
1382 | row += rowstride; |
|
|
1383 | } |
|
|
1384 | |
|
|
1385 | XChangeProperty (dpy, parent, xa[XA_NET_WM_ICON], XA_CARDINAL, 32, |
|
|
1386 | PropModeReplace, (const unsigned char *) buffer, 2 + w * h); |
|
|
1387 | free (buffer); |
|
|
1388 | } |
|
|
1389 | else |
|
|
1390 | rxvt_warn ("Memory allocation for icon hint failed, continuing without.\n"); |
|
|
1391 | |
|
|
1392 | g_object_unref (pixbuf); |
|
|
1393 | #endif |
|
|
1394 | } |
|
|
1395 | |
1284 | /*----------------------------------------------------------------------*/ |
1396 | /*----------------------------------------------------------------------*/ |
1285 | /* rxvt_Create_Windows () - Open and map the window */ |
1397 | /* Open and map the window */ |
1286 | void |
1398 | void |
1287 | rxvt_term::create_windows (int argc, const char *const *argv) |
1399 | rxvt_term::create_windows (int argc, const char *const *argv) |
1288 | { |
1400 | { |
1289 | XClassHint classHint; |
1401 | XClassHint classHint; |
1290 | XWMHints wmHint; |
1402 | XWMHints wmHint; |
… | |
… | |
1336 | } |
1448 | } |
1337 | #endif |
1449 | #endif |
1338 | |
1450 | |
1339 | window_calc (0, 0); |
1451 | window_calc (0, 0); |
1340 | |
1452 | |
1341 | /* sub-window placement & size in rxvt_resize_subwindows () */ |
1453 | /* sub-window placement & size in rxvt_term::resize_all_windows () */ |
1342 | attributes.background_pixel = pix_colors_focused [Color_border]; |
1454 | attributes.background_pixel = pix_colors_focused [Color_border]; |
1343 | attributes.border_pixel = pix_colors_focused [Color_border]; |
1455 | attributes.border_pixel = pix_colors_focused [Color_border]; |
1344 | attributes.colormap = cmap; |
1456 | attributes.colormap = cmap; |
1345 | |
1457 | |
1346 | top = XCreateWindow (dpy, parent, |
1458 | top = XCreateWindow (dpy, parent, |
… | |
… | |
1349 | ext_bwidth, |
1461 | ext_bwidth, |
1350 | depth, InputOutput, visual, |
1462 | depth, InputOutput, visual, |
1351 | CWColormap | CWBackPixel | CWBorderPixel | CWOverrideRedirect, |
1463 | CWColormap | CWBackPixel | CWBorderPixel | CWOverrideRedirect, |
1352 | &attributes); |
1464 | &attributes); |
1353 | |
1465 | |
1354 | this->parent[0] = top; |
1466 | this->parent = top; |
1355 | |
1467 | |
1356 | old_width = szHint.width; |
1468 | old_width = szHint.width; |
1357 | old_height = szHint.height; |
1469 | old_height = szHint.height; |
1358 | |
1470 | |
1359 | set_title (rs [Rs_title]); |
1471 | set_title (rs [Rs_title]); |
… | |
… | |
1368 | wmHint.window_group = top; |
1480 | wmHint.window_group = top; |
1369 | |
1481 | |
1370 | XmbSetWMProperties (dpy, top, NULL, NULL, (char **)argv, argc, |
1482 | XmbSetWMProperties (dpy, top, NULL, NULL, (char **)argv, argc, |
1371 | &szHint, &wmHint, &classHint); |
1483 | &szHint, &wmHint, &classHint); |
1372 | #if ENABLE_EWMH |
1484 | #if ENABLE_EWMH |
1373 | # ifdef HAVE_AFTERIMAGE |
|
|
1374 | /* |
1485 | /* |
1375 | * set up icon hint |
1486 | * set up icon hint |
1376 | * rs [Rs_iconfile] is path to icon |
1487 | * rs [Rs_iconfile] is path to icon |
1377 | */ |
1488 | */ |
1378 | |
1489 | |
1379 | if (rs [Rs_iconfile]) |
1490 | if (rs [Rs_iconfile]) |
1380 | { |
1491 | { |
1381 | init_asv (); |
1492 | set_icon (rs [Rs_iconfile]); |
1382 | |
|
|
1383 | ASImage *im = file2ASImage (rs [Rs_iconfile], 0xFFFFFFFF, SCREEN_GAMMA, 0, NULL); |
|
|
1384 | if (im) |
|
|
1385 | { |
|
|
1386 | int w = im->width; |
|
|
1387 | int h = im->height; |
|
|
1388 | ASImage *result = scale_asimage (asv, im, |
|
|
1389 | w, h, ASA_ARGB32, |
|
|
1390 | 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
1391 | destroy_asimage (&im); |
|
|
1392 | |
|
|
1393 | if (result) |
|
|
1394 | { |
|
|
1395 | long *buffer = (long *)malloc ((2 + w * h) * sizeof (long)); |
|
|
1396 | if (buffer) |
|
|
1397 | { |
|
|
1398 | ARGB32 *asbuf = result->alt.argb32; |
|
|
1399 | buffer [0] = w; |
|
|
1400 | buffer [1] = h; |
|
|
1401 | |
|
|
1402 | for (unsigned int i = 0; i < w * h; ++i) |
|
|
1403 | buffer [i + 2] = asbuf [i]; |
|
|
1404 | |
|
|
1405 | XChangeProperty (dpy, top, xa[XA_NET_WM_ICON], XA_CARDINAL, 32, |
|
|
1406 | PropModeReplace, (const unsigned char *) buffer, 2 + w * h); |
|
|
1407 | free (buffer); |
|
|
1408 | } |
|
|
1409 | else |
|
|
1410 | rxvt_warn ("Memory allocation for icon hint failed, continuing without.\n"); |
|
|
1411 | |
|
|
1412 | destroy_asimage (&result); |
|
|
1413 | } |
|
|
1414 | else |
|
|
1415 | rxvt_warn ("Icon image transformation to ARGB failed, continuing without.\n"); |
|
|
1416 | } |
|
|
1417 | else |
|
|
1418 | rxvt_warn ("Loading image icon failed, continuing without.\n"); |
|
|
1419 | } |
1493 | } |
1420 | # endif |
|
|
1421 | #endif |
1494 | #endif |
1422 | |
1495 | |
1423 | #if ENABLE_FRILLS |
1496 | #if ENABLE_FRILLS |
1424 | if (mwmhints.flags) |
1497 | if (mwmhints.flags) |
1425 | XChangeProperty (dpy, top, xa[XA_MOTIF_WM_HINTS], xa[XA_MOTIF_WM_HINTS], 32, |
1498 | XChangeProperty (dpy, top, xa[XA_MOTIF_WM_HINTS], xa[XA_MOTIF_WM_HINTS], 32, |
… | |
… | |
1431 | #if ENABLE_EWMH |
1504 | #if ENABLE_EWMH |
1432 | xa[XA_NET_WM_PING], |
1505 | xa[XA_NET_WM_PING], |
1433 | #endif |
1506 | #endif |
1434 | }; |
1507 | }; |
1435 | |
1508 | |
1436 | XSetWMProtocols (dpy, top, protocols, sizeof (protocols) / sizeof (protocols[0])); |
1509 | XSetWMProtocols (dpy, top, protocols, ARRAY_LENGTH(protocols)); |
1437 | |
1510 | |
1438 | #if ENABLE_FRILLS |
1511 | #if ENABLE_FRILLS |
1439 | if (rs[Rs_transient_for]) |
1512 | if (rs[Rs_transient_for]) |
1440 | XSetTransientForHint (dpy, top, (Window)strtol (rs[Rs_transient_for], 0, 0)); |
1513 | XSetTransientForHint (dpy, top, (Window)strtol (rs[Rs_transient_for], 0, 0)); |
1441 | #endif |
1514 | #endif |