~showard314/ubuntu/karmic/r-base/remove_start_comments

« back to all changes in this revision

Viewing changes to src/modules/X11/devX11.c

  • Committer: Bazaar Package Importer
  • Author(s): Dirk Eddelbuettel
  • Date: 2009-01-19 12:40:24 UTC
  • mfrom: (5.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090119124024-abxsf4e0y7713w9m
Tags: 2.8.1-2
debian/control: Add another Build-Depends: exclusion for the 
'kfreebsd-i386 kfreebsd-amd64 hurd-i386' architecture to openjdk-6-jdk.
Thanks to Petr Salinger for the heads-up.               (Closes: 512324)

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
# endif */
71
71
#endif
72
72
 
 
73
typedef int (*X11IOhandler)(Display *);
 
74
 
73
75
#include "devX11.h"
74
76
 
75
77
#include <Rmodules/RX11.h>
99
101
         * with only one copy for all x11 devices */
100
102
 
101
103
static Display *display;                        /* Display */
 
104
static char dspname[101]="";
102
105
static int screen;                              /* Screen */
103
106
static Window rootwin;                          /* Root Window */
104
107
static Visual *visual;                          /* Visual */
1077
1080
    return 0;
1078
1081
}
1079
1082
 
 
1083
static int R_X11IOErrSimple(Display *dsp)
 
1084
{
 
1085
    char *dn = XDisplayName(dspname);
 
1086
    strcpy(dspname, "");
 
1087
    error(_("X11 I/O error while opening X11 connection to '%s'"), dn);
 
1088
    return 0; /* but should never get here */
 
1089
}
 
1090
 
1080
1091
static int R_X11IOErr(Display *dsp)
1081
1092
{
1082
1093
    int fd = ConnectionNumber(display);
1089
1100
    /*
1090
1101
    XCloseDisplay(display);
1091
1102
    displayOpen = FALSE;
 
1103
    strcpy(dspname, "");
1092
1104
    */
1093
1105
    error(_("X11 fatal IO error: please save work and shut down R"));
1094
1106
    return 0; /* but should never get here */
1245
1257
    /* initialize the X11 device driver data structures. */
1246
1258
 
1247
1259
    if (!displayOpen) {
 
1260
        /* Bill Dunlap sees an error when tunneling to a non-existent
 
1261
           X11 connection that BDR cannot reproduce.  We leave a handler set
 
1262
           if we get an error, but that is rare.
 
1263
        */
 
1264
        X11IOhandler old;
 
1265
        strncpy(dspname, p, 101);
 
1266
        dspname[100] = '\0';
 
1267
        old = XSetIOErrorHandler(R_X11IOErrSimple);
1248
1268
        if ((display = XOpenDisplay(p)) == NULL) {
 
1269
            XSetIOErrorHandler(old);
1249
1270
            warning(_("unable to open connection to X11 display '%s'"), p);
1250
1271
            return FALSE;
1251
1272
        }
 
1273
        XSetIOErrorHandler(old);
1252
1274
        DisplayOpened = TRUE;
1253
1275
        Rf_setX11Display(display, gamma_fac, colormodel, maxcube, TRUE);
1254
1276
        displayOpen = TRUE;
1255
1277
        if(xd->handleOwnEvents == FALSE)
1256
1278
            addInputHandler(R_InputHandlers, ConnectionNumber(display),
1257
1279
                            R_ProcessX11Events, XActivity);
1258
 
    }
 
1280
    } else if(strcmp(p, dspname))
 
1281
        warning(_("ignoring 'display' argument as an X11 device is already open"));
1259
1282
    whitepixel = GetX11Pixel(R_RED(canvascolor), R_GREEN(canvascolor),
1260
1283
                             R_BLUE(canvascolor));
1261
1284
    blackpixel = GetX11Pixel(0, 0, 0);
1325
1348
 
1326
1349
                app_con = XtCreateApplicationContext();
1327
1350
                XtAppSetFallbackResources(app_con, x_fallback_resources);
1328
 
                xtdpy = XtOpenDisplay(app_con, dsp, "r_x11", "R_x11",
 
1351
                xtdpy = XtOpenDisplay(app_con, dspname, "r_x11", "R_x11",
1329
1352
                                      NULL, 0, &zero, NULL);
1330
 
                toplevel = XtAppCreateShell(NULL, "R_x11",
1331
 
                                            applicationShellWidgetClass,
1332
 
                                            xtdpy, NULL, 0);
1333
 
                XtGetApplicationResources(toplevel, (XtPointer) &xdev,
1334
 
                                          x_resources,
1335
 
                                          x_resource_count,
1336
 
                                          NULL, 0);
1337
 
                if (xdev.geometry != NULL) {
1338
 
                    char gstr[40];
1339
 
                    int bitmask;
1340
 
 
1341
 
                    sprintf(gstr, "%dx%d+%d+%d", hint->width,
1342
 
                            hint->height, hint->x, hint->y);
1343
 
                    bitmask = XWMGeometry(display, DefaultScreen(display),
1344
 
                                          xdev.geometry, gstr,
1345
 
                                          1,
1346
 
                                          hint,
1347
 
                                          &hint->x, &hint->y,
1348
 
                                          &hint->width, &hint->height,
1349
 
                                          &hint->win_gravity);
1350
 
 
1351
 
                    if (bitmask & (XValue | YValue))
1352
 
                        hint->flags |= USPosition;
1353
 
                    if (bitmask & (WidthValue | HeightValue))
1354
 
                        hint->flags |= USSize;
1355
 
                    /* Restore user-specified settings */
1356
 
                    if(xpos != NA_INTEGER)
1357
 
                        hint->x = (xpos >= 0) ? xpos :
1358
 
                            DisplayWidth(display, screen) - iw + xpos;
1359
 
                    if(ypos != NA_INTEGER)
1360
 
                        hint->y = (ypos >= 0)? ypos :
1361
 
                            DisplayHeight(display, screen) - iw - ypos;
1362
 
                    if(!ISNA(w)) hint->width = iw;
1363
 
                    if(!ISNA(h)) hint->height = ih;
 
1353
                if(xtdpy) {
 
1354
                    toplevel = XtAppCreateShell(NULL, "R_x11",
 
1355
                                                applicationShellWidgetClass,
 
1356
                                                xtdpy, NULL, 0);
 
1357
                    XtGetApplicationResources(toplevel, (XtPointer) &xdev,
 
1358
                                              x_resources,
 
1359
                                              x_resource_count,
 
1360
                                              NULL, 0);
 
1361
                    if (xdev.geometry != NULL) {
 
1362
                        char gstr[40];
 
1363
                        int bitmask;
 
1364
 
 
1365
                        sprintf(gstr, "%dx%d+%d+%d", hint->width,
 
1366
                                hint->height, hint->x, hint->y);
 
1367
                        bitmask = XWMGeometry(display, DefaultScreen(display),
 
1368
                                              xdev.geometry, gstr,
 
1369
                                              1,
 
1370
                                              hint,
 
1371
                                              &hint->x, &hint->y,
 
1372
                                              &hint->width, &hint->height,
 
1373
                                              &hint->win_gravity);
 
1374
 
 
1375
                        if (bitmask & (XValue | YValue))
 
1376
                            hint->flags |= USPosition;
 
1377
                        if (bitmask & (WidthValue | HeightValue))
 
1378
                            hint->flags |= USSize;
 
1379
                        /* Restore user-specified settings */
 
1380
                        if(xpos != NA_INTEGER)
 
1381
                            hint->x = (xpos >= 0) ? xpos :
 
1382
                                DisplayWidth(display, screen) - iw + xpos;
 
1383
                        if(ypos != NA_INTEGER)
 
1384
                            hint->y = (ypos >= 0)? ypos :
 
1385
                                DisplayHeight(display, screen) - iw - ypos;
 
1386
                        if(!ISNA(w)) hint->width = iw;
 
1387
                        if(!ISNA(h)) hint->height = ih;
 
1388
                    }
 
1389
                    XtDestroyWidget(toplevel);
 
1390
                    XtCloseDisplay(xtdpy);
 
1391
                } else {
 
1392
                    warning(_("unable to obtain information on display '%s'"),
 
1393
                            dsp);
1364
1394
                }
1365
 
                XtDestroyWidget(toplevel);
1366
 
                XtCloseDisplay(xtdpy);
1367
1395
                XtDestroyApplicationContext(app_con);
1368
1396
            }
1369
1397
#endif
2526
2554
    R_CheckDeviceAvailable();
2527
2555
    BEGIN_SUSPEND_INTERRUPTS {
2528
2556
        /* Allocate and initialize the device driver data */
2529
 
        if (!(dev = (pDevDesc) calloc(1, sizeof(NewDevDesc)))) return;
 
2557
        if (!(dev = (pDevDesc) calloc(1, sizeof(DevDesc)))) return;
2530
2558
        if (!X11DeviceDriver(dev, display, width, height,
2531
2559
                             ps, gamma, colormodel, maxcubesize,
2532
2560
                             bgcolor, canvascolor, sfonts, res,
2821
2849
    }
2822
2850
#ifdef HAVE_TIFF
2823
2851
    else if(xd->type == TIFF) {
2824
 
        if (xd->npages > 1) BM_Close_bitmap(xd);
 
2852
        if (xd->npages > 1) {
 
2853
            xd->npages--;
 
2854
            BM_Close_bitmap(xd);
 
2855
            xd->npages++;
 
2856
        }
2825
2857
    }
2826
2858
#endif
2827
2859
#ifdef HAVE_CAIRO_SVG
2950
2982
            char buf[PATH_MAX];
2951
2983
            snprintf(buf, PATH_MAX, xd->filename, xd->npages);
2952
2984
            res = cairo_surface_write_to_png(xd->cs, R_ExpandFileName(buf));
 
2985
            if (res != CAIRO_STATUS_SUCCESS)
 
2986
                warning("cairo error '%s'", cairo_status_to_string(res));
2953
2987
        }
2954
2988
    }
2955
2989
    if (xd->fp) fclose(xd->fp);
3135
3169
    BEGIN_SUSPEND_INTERRUPTS {
3136
3170
        pDevDesc dev;
3137
3171
        /* Allocate and initialize the device driver data */
3138
 
        if (!(dev = (pDevDesc) calloc(1, sizeof(NewDevDesc)))) return 0;
 
3172
        if (!(dev = (pDevDesc) calloc(1, sizeof(DevDesc)))) return 0;
3139
3173
        if (!BMDeviceDriver(dev, devtable[type].gtype, filename, quality,
3140
3174
                            width, height, pointsize,
3141
3175
                            bgcolor, res, antialias)) {
3160
3194
static int in_R_X11_access(void)
3161
3195
{
3162
3196
    char *p;
 
3197
    X11IOhandler old;
3163
3198
 
3164
3199
    if (displayOpen) return TRUE;
3165
3200
    if(!(p = getenv("DISPLAY"))) return FALSE;
 
3201
    /* Bill Dunlap sees an error when tunneling to a non-existent
 
3202
       X11 connection that BDR cannot reproduce.  We leave a handler set
 
3203
       if we get an error, but that is rare.
 
3204
    */
 
3205
    old = XSetIOErrorHandler(R_X11IOErrSimple);
3166
3206
    if ((display = XOpenDisplay(NULL)) == NULL) {
 
3207
        XSetIOErrorHandler(old);
3167
3208
        return FALSE;
3168
3209
    } else {
3169
3210
        XCloseDisplay(display);
 
3211
        XSetIOErrorHandler(old);
3170
3212
        return TRUE;
3171
3213
    }
3172
3214
}
3238
3280
    }
3239
3281
    XDeleteProperty(display, clpwin, pty);
3240
3282
    XFree(buffer);
3241
 
    if (!displayOpen) XCloseDisplay(display);
 
3283
    if (!displayOpen) {
 
3284
        XCloseDisplay(display);
 
3285
        strcpy(dspname, "");
 
3286
    }
3242
3287
    return res;
3243
3288
}
3244
3289