static void ResourcesUpdate(Widget w, XPContext pcontext, Dimension * pwidth, Dimension * pheight) { XmPrintShellWidget print_shell = (XmPrintShellWidget) w ; String string_resolution ; XRectangle imageable_area ; /*** Get the resolution so that unit Type conversion works */ string_resolution = XpGetOneAttribute(XtDisplay(w), pcontext, XPDocAttr, "default-printer-resolution") ; print_shell->print.print_resolution = atoi(string_resolution); XFree(string_resolution); if (!print_shell->print.print_resolution) /* compute from the X screen resolution */ print_shell->print.print_resolution = (254 * WidthOfScreen(XtScreen(w)) + 5 * WidthMMOfScreen(XtScreen(w))) / (10 * WidthMMOfScreen(XtScreen(w))) ; /* get our size from the print server now */ XpGetPageDimensions(XtDisplay(w), pcontext, pwidth, pheight, &imageable_area); print_shell->print.min_x = imageable_area.x ; print_shell->print.min_y = imageable_area.y ; print_shell->print.max_x = imageable_area.x + imageable_area.width ; print_shell->print.max_y = imageable_area.y + imageable_area.height ; }
int TkGetDoublePixels( Tcl_Interp *interp, /* Use this for error reporting. */ Tk_Window tkwin, /* Window whose screen determines conversion * from centimeters and other absolute * units. */ const char *string, /* String describing a number of pixels. */ double *doublePtr) /* Place to store converted result. */ { char *end; double d; d = strtod((char *) string, &end); if (end == string) { goto error; } while ((*end != '\0') && isspace(UCHAR(*end))) { end++; } switch (*end) { case 0: break; case 'c': d *= 10*WidthOfScreen(Tk_Screen(tkwin)); d /= WidthMMOfScreen(Tk_Screen(tkwin)); end++; break; case 'i': d *= 25.4*WidthOfScreen(Tk_Screen(tkwin)); d /= WidthMMOfScreen(Tk_Screen(tkwin)); end++; break; case 'm': d *= WidthOfScreen(Tk_Screen(tkwin)); d /= WidthMMOfScreen(Tk_Screen(tkwin)); end++; break; case 'p': d *= (25.4/72.0)*WidthOfScreen(Tk_Screen(tkwin)); d /= WidthMMOfScreen(Tk_Screen(tkwin)); end++; break; default: goto error; } while ((*end != '\0') && isspace(UCHAR(*end))) { end++; } if (*end != 0) { goto error; } *doublePtr = d; return TCL_OK; error: Tcl_SetObjResult(interp, Tcl_ObjPrintf( "bad screen distance \"%s\"", string)); Tcl_SetErrorCode(interp, "TK", "VALUE", "FRACTIONAL_PIXELS", NULL); return TCL_ERROR; }
static gint gdk_x11_screen_get_width_mm (GdkScreen *screen) { g_return_val_if_fail (GDK_IS_SCREEN (screen), 0); return WidthMMOfScreen (GDK_X11_SCREEN (screen)->xscreen); }
static gint xfce_xsettings_helper_screen_dpi (XfceXSettingsScreen *screen) { Screen *xscreen; gint width_mm, width_dpi; gint height_mm, height_dpi; gint dpi = DPI_FALLBACK; xscreen = ScreenOfDisplay (screen->xdisplay, screen->screen_num); if (G_LIKELY (xscreen != NULL)) { width_mm = WidthMMOfScreen (xscreen); height_mm = HeightMMOfScreen (xscreen); if (G_LIKELY (width_mm > 0 && height_mm > 0)) { width_dpi = 25.4 * WidthOfScreen (xscreen) / width_mm; height_dpi = 25.4 * HeightOfScreen (xscreen) / height_mm; /* both values need to be reasonable */ if (width_dpi > DPI_LOW_REASONABLE && width_dpi < DPI_HIGH_REASONABLE && height_dpi > DPI_LOW_REASONABLE && height_dpi < DPI_HIGH_REASONABLE) { /* gnome takes the average between the two, however the * minimin seems to result in sharper font in more cases */ dpi = MIN (width_dpi, height_dpi); } } } xfsettings_dbg_filtered (XFSD_DEBUG_XSETTINGS, "calculated dpi of %d for screen %d", dpi, screen->screen_num); return dpi; }
/* * GetDpi - return Dots-per-inch of the screen * * calculate the pixel density in dots per inch on the current widget * screen * */ static float GetDpi(HTMLWidget hw) { Screen *s = XtScreen(hw); float dpi; dpi = 25.4 * WidthOfScreen(s) / WidthMMOfScreen(s); if (dpi<1.0 || dpi>10000.0) dpi = 72.0; return dpi; }
int Tk_GetScreenMM( Tcl_Interp *interp, /* Use this for error reporting. */ Tk_Window tkwin, /* Window whose screen determines conversion * from centimeters and other absolute * units. */ const char *string, /* String describing a screen distance. */ double *doublePtr) /* Place to store converted result. */ { char *end; double d; d = strtod(string, &end); if (end == string) { error: Tcl_AppendResult(interp, "bad screen distance \"", string, "\"", NULL); return TCL_ERROR; } while ((*end != '\0') && isspace(UCHAR(*end))) { end++; } switch (*end) { case 0: d /= WidthOfScreen(Tk_Screen(tkwin)); d *= WidthMMOfScreen(Tk_Screen(tkwin)); break; case 'c': d *= 10; end++; break; case 'i': d *= 25.4; end++; break; case 'm': end++; break; case 'p': d *= 25.4/72.0; end++; break; default: goto error; } while ((*end != '\0') && isspace(UCHAR(*end))) { end++; } if (*end != 0) { goto error; } *doublePtr = d; return TCL_OK; }
int Tk_GetMMFromObj( Tcl_Interp *interp, /* Used for error reporting if not NULL. */ Tk_Window tkwin, Tcl_Obj *objPtr, /* The object from which to get mms. */ double *doublePtr) /* Place to store resulting millimeters. */ { int result; double d; MMRep *mmPtr; static double bias[] = { 10.0, 25.4, 1.0, 0.35278 /*25.4 / 72.0*/ }; if (objPtr->typePtr != &mmObjType) { result = SetMMFromAny(interp, objPtr); if (result != TCL_OK) { return result; } } mmPtr = (MMRep *) objPtr->internalRep.twoPtrValue.ptr1; if (mmPtr->tkwin != tkwin) { d = mmPtr->value; if (mmPtr->units == -1) { d /= WidthOfScreen(Tk_Screen(tkwin)); d *= WidthMMOfScreen(Tk_Screen(tkwin)); } else { d *= bias[mmPtr->units]; } mmPtr->tkwin = tkwin; mmPtr->returnValue = d; } *doublePtr = mmPtr->returnValue; return TCL_OK; }
static int win_choose_font (ClientData cd, Tcl_Interp *interp, int argc, char **argv) { char *deffont; Tk_Window parent; int i, oldMode; CHOOSEFONT cf; LOGFONT lf; HDC hdc; HFONT hfont; char facebuf[LF_FACESIZE]; TEXTMETRIC tm; int pointsize; char *s; Tcl_DString resultStr; /* used to translate result in UTF8 in Tcl/Tk8.1 */ deffont = NULL; parent = Tk_MainWindow (interp); for (i = 1; i < argc; i += 2) { if (i + 1 >= argc) { Tcl_ResetResult (interp); Tcl_AppendStringsToObj (Tcl_GetObjResult (interp), "value for \"", argv[i], "\" missing", (char *) NULL); return TCL_ERROR; } if (strcmp (argv[i], "-default") == 0) deffont = argv[i + 1]; else if (strcmp (argv[i], "-parent") == 0) { parent = Tk_NameToWindow (interp, argv[i + 1], Tk_MainWindow (interp)); if (parent == NULL) return TCL_ERROR; } else { Tcl_ResetResult (interp); Tcl_AppendStringsToObj (Tcl_GetObjResult (interp), "unknown option \"", argv[i], "\"", (char *) NULL); return TCL_ERROR; } } memset (&cf, 0, sizeof (CHOOSEFONT)); cf.lStructSize = sizeof (CHOOSEFONT); if (Tk_WindowId (parent) == None) Tk_MakeWindowExist (parent); cf.hwndOwner = Tk_GetHWND (Tk_WindowId (parent)); cf.lpLogFont = &lf; cf.Flags = CF_SCREENFONTS | CF_FORCEFONTEXIST; memset (&lf, 0, sizeof (LOGFONT)); if (deffont != NULL) { Tk_Font tkfont; const TkFontAttributes *fa; tkfont = Tk_GetFont (interp, parent, deffont); if (tkfont == NULL) return TCL_ERROR; cf.Flags |= CF_INITTOLOGFONTSTRUCT; /* In order to initialize LOGFONT, we need to extract the real font attributes from the Tk internal font information. */ fa = &((TkFont *) tkfont)->fa; /* This code is taken from TkpGetFontFromAttributes. It converts a TkFontAttributes structure into a LOGFONT structure. */ #if (TCL_MAJOR_VERSION >= 8) && (TCL_MINOR_VERSION >= 1) lf.lfHeight = - fa->size; #else lf.lfHeight = - fa->pointsize; #endif if (lf.lfHeight < 0) lf.lfHeight = MulDiv (lf.lfHeight, 254 * WidthOfScreen (Tk_Screen (parent)), 720 * WidthMMOfScreen (Tk_Screen (parent))); lf.lfWeight = fa->weight == TK_FW_NORMAL ? FW_NORMAL : FW_BOLD; lf.lfItalic = fa->slant; lf.lfUnderline = fa->underline; lf.lfStrikeOut = fa->overstrike; lf.lfCharSet = DEFAULT_CHARSET; lf.lfOutPrecision = OUT_DEFAULT_PRECIS; lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; lf.lfQuality = DEFAULT_QUALITY; lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; if (fa->family == NULL) lf.lfFaceName[0] = '\0'; else strncpy (lf.lfFaceName, fa->family, sizeof (lf.lfFaceName)); Tk_FreeFont (tkfont); } oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL); if (! ChooseFont (&cf)) { DWORD code; code = CommDlgExtendedError (); if (code == 0) { /* The user pressed cancel. */ Tcl_ResetResult (interp); return TCL_OK; } else { char buf[200]; sprintf (buf, "Windows common dialog error 0x%lx", (unsigned long) code); Tcl_ResetResult (interp); #if (TCL_MAJOR_VERSION >= 8) && (TCL_MINOR_VERSION >= 1) Tcl_ExternalToUtfDString(NULL, buf, -1, &resultStr); #else Tcl_InitDString(&resultStr); Tcl_DStingAppend(&resultStr, buf, -1); #endif Tcl_AppendStringsToObj (Tcl_GetObjResult (interp), Tcl_DStringValue(&resultStr), (char *) NULL); Tcl_DStringFree(&resultStr); return TCL_ERROR; } } Tcl_SetServiceMode(oldMode); /* We now have a LOGFONT structure. We store it into a device context, and then extract enough information to build a Tk font specification. With luck, when Tk interprets the font specification it will wind up with the font that the user expects to see. Some of this code is taken from AllocFont. */ hfont = CreateFontIndirect (&lf); if (hfont == NULL) { /* This should be impossible. */ #if (TCL_MAJOR_VERSION >= 8) && (TCL_MINOR_VERSION >= 1) Tcl_ExternalToUtfDString(NULL, "CreateFontIndirect failed on chosen font", -1, &resultStr); #else Tcl_InitDString(&resultStr); Tcl_DStingAppend(&resultStr, "CreateFontIndirect failed on chosen font", -1); #endif Tcl_SetResult (interp, Tcl_DStringValue(&resultStr), TCL_STATIC); Tcl_DStringFree(&resultStr); return TCL_ERROR; } hdc = GetDC (cf.hwndOwner); hfont = SelectObject (hdc, hfont); GetTextFace (hdc, sizeof (facebuf), facebuf); GetTextMetrics (hdc, &tm); Tcl_ResetResult (interp); #if (TCL_MAJOR_VERSION >= 8) && (TCL_MINOR_VERSION >= 1) Tcl_ExternalToUtfDString(NULL, facebuf, -1, &resultStr); #else Tcl_InitDString(&resultStr); Tcl_DStingAppend(&resultStr,facebuf,-1); #endif if (Tcl_ListObjAppendElement (interp, Tcl_GetObjResult (interp), Tcl_NewStringObj (Tcl_DStringValue(&resultStr), -1)) != TCL_OK) { Tcl_DStringFree(&resultStr); return TCL_ERROR; } Tcl_DStringFree(&resultStr); pointsize = MulDiv (tm.tmHeight - tm.tmInternalLeading, 720 * WidthMMOfScreen (Tk_Screen (parent)), 254 * WidthOfScreen (Tk_Screen (parent))); if (Tcl_ListObjAppendElement (interp, Tcl_GetObjResult (interp), Tcl_NewIntObj (pointsize)) != TCL_OK) { return TCL_ERROR; } if (tm.tmWeight > FW_MEDIUM) s = "bold"; else s = "normal"; #if (TCL_MAJOR_VERSION >= 8) && (TCL_MINOR_VERSION >= 1) Tcl_ExternalToUtfDString(NULL, s, -1, &resultStr); #else Tcl_InitDString(&resultStr); Tcl_DStingAppend(&resultStr, s, -1); #endif if (Tcl_ListObjAppendElement (interp, Tcl_GetObjResult (interp), Tcl_NewStringObj (Tcl_DStringValue(&resultStr), -1)) != TCL_OK) { Tcl_DStringFree(&resultStr); return TCL_ERROR; } Tcl_DStringFree(&resultStr); if (tm.tmItalic) s = "italic"; else s = "roman"; #if (TCL_MAJOR_VERSION >= 8) && (TCL_MINOR_VERSION >= 1) Tcl_ExternalToUtfDString(NULL, s, -1, &resultStr); #else Tcl_InitDString(&resultStr); Tcl_DStingAppend(&resultStr, s, -1); #endif if (Tcl_ListObjAppendElement (interp, Tcl_GetObjResult (interp), Tcl_NewStringObj (Tcl_DStringValue(&resultStr), -1)) != TCL_OK) { Tcl_DStringFree(&resultStr); return TCL_ERROR; } Tcl_DStringFree(&resultStr); if (tm.tmUnderlined) { #if (TCL_MAJOR_VERSION >= 8) && (TCL_MINOR_VERSION >= 1) Tcl_ExternalToUtfDString(NULL, "underline", -1, &resultStr); #else Tcl_InitDString(&resultStr); Tcl_DStingAppend(&resultStr,"underline",-1); #endif if (Tcl_ListObjAppendElement (interp, Tcl_GetObjResult (interp), Tcl_NewStringObj (Tcl_DStringValue(&resultStr), -1)) != TCL_OK) { Tcl_DStringFree(&resultStr); return TCL_ERROR; } Tcl_DStringFree(&resultStr); } if (tm.tmStruckOut) { #if (TCL_MAJOR_VERSION >= 8) && (TCL_MINOR_VERSION >= 1) Tcl_ExternalToUtfDString(NULL, "overstrike", -1, &resultStr); #else Tcl_InitDString(&resultStr); Tcl_DStingAppend(&resultStr, "overstrike", -1); #endif if (Tcl_ListObjAppendElement (interp, Tcl_GetObjResult (interp), Tcl_NewStringObj (Tcl_DStringValue(&resultStr), -1)) != TCL_OK) { Tcl_DStringFree(&resultStr); return TCL_ERROR; } Tcl_DStringFree(&resultStr); } hfont = SelectObject (hdc, hfont); ReleaseDC (cf.hwndOwner, hdc); DeleteObject (hfont); return TCL_OK; }
int main(int argc, char **argv) { AppInfo app; XEvent event; memset(&app, 0, sizeof(app)); progclass = "SshAskpass"; app.toplevelShell = XtAppInitialize(&(app.appContext), progclass, NULL, 0, &argc, argv, defaults, NULL, 0); app.argc = argc; app.argv = argv; app.dpy = XtDisplay(app.toplevelShell); app.screen = DefaultScreenOfDisplay(app.dpy); app.rootWindow = RootWindowOfScreen(app.screen); app.black = BlackPixel(app.dpy, DefaultScreen(app.dpy)); app.white = WhitePixel(app.dpy, DefaultScreen(app.dpy)); app.colormap = DefaultColormapOfScreen(app.screen); app.resourceDb = XtDatabase(app.dpy); XtGetApplicationNameAndClass(app.dpy, &progname, &progclass); app.appName = progname; app.appClass = progclass; /* For resources.c. */ db = app.resourceDb; /* Seconds after which keyboard/pointer grab fail. */ app.grabFailTimeout = 5; /* Number of seconds to wait between grab attempts. */ app.grabRetryInterval = 1; app.pid = getpid(); { struct rlimit resourceLimit; int status; status = getrlimit(RLIMIT_CORE, &resourceLimit); if (-1 == status) { fprintf(stderr, "%s[%ld]: getrlimit failed (%s)\n", app.appName, (long) app.pid, strerror(errno)); exit(EXIT_STATUS_ERROR); } resourceLimit.rlim_cur = 0; status = setrlimit(RLIMIT_CORE, &resourceLimit); if (-1 == status) { fprintf(stderr, "%s[%ld]: setrlimit failed (%s)\n", app.appName, (long) app.pid, strerror(errno)); exit(EXIT_STATUS_ERROR); } } app.xResolution = WidthOfScreen(app.screen) * 1000 / WidthMMOfScreen(app.screen); app.yResolution = HeightOfScreen(app.screen) * 1000 / HeightMMOfScreen(app.screen); createDialog(&app); createGCs(&app); app.eventMask = 0; app.eventMask |= ExposureMask; app.eventMask |= ButtonPressMask; app.eventMask |= ButtonReleaseMask; app.eventMask |= Button1MotionMask; app.eventMask |= KeyPressMask; createDialogWindow(&app); XMapWindow(app.dpy, app.dialog->dialogWindow); if (app.inputTimeout > 0) { app.inputTimeoutActive = True; app.inputTimeoutTimerId = XtAppAddTimeOut(app.appContext, app.inputTimeout, handleInputTimeout, (XtPointer) &app); } while(True) { XtAppNextEvent(app.appContext, &event); switch (event.type) { case Expose: grabServer(&app); grabKeyboard(&app); grabPointer(&app); if (event.xexpose.count) { break; } paintDialog(&app); break; case ButtonPress: case ButtonRelease: handleButtonPress(&app, &event); break; case MotionNotify: handlePointerMotion(&app, &event); case KeyPress: handleKeyPress(&app, &event); break; case ClientMessage: if ((32 == event.xclient.format) && ((unsigned long) event.xclient.data.l[0] == app.wmDeleteWindowAtom)) { cancelAction(&app); } break; default: break; } } fprintf(stderr, "%s[%ld]: This should not happen.\n", app.appName, (long) app.pid); return(EXIT_STATUS_ANOMALY); }
void TkpComputeMenuButtonGeometry( TkMenuButton *mbPtr) /* Widget record for menu button. */ { int width, height, mm, pixels; int avgWidth, txtWidth, txtHeight; int haveImage = 0, haveText = 0; Tk_FontMetrics fm; mbPtr->inset = mbPtr->highlightWidth + mbPtr->borderWidth; width = 0; height = 0; txtWidth = 0; txtHeight = 0; avgWidth = 0; if (mbPtr->image != None) { Tk_SizeOfImage(mbPtr->image, &width, &height); haveImage = 1; } else if (mbPtr->bitmap != None) { Tk_SizeOfBitmap(mbPtr->display, mbPtr->bitmap, &width, &height); haveImage = 1; } if (haveImage == 0 || mbPtr->compound != COMPOUND_NONE) { Tk_FreeTextLayout(mbPtr->textLayout); mbPtr->textLayout = Tk_ComputeTextLayout(mbPtr->tkfont, mbPtr->text, -1, mbPtr->wrapLength, mbPtr->justify, 0, &mbPtr->textWidth, &mbPtr->textHeight); txtWidth = mbPtr->textWidth; txtHeight = mbPtr->textHeight; avgWidth = Tk_TextWidth(mbPtr->tkfont, "0", 1); Tk_GetFontMetrics(mbPtr->tkfont, &fm); haveText = (txtWidth != 0 && txtHeight != 0); } /* * If the menubutton is compound (ie, it shows both an image and text), * the new geometry is a combination of the image and text geometry. We * only honor the compound bit if the menubutton has both text and an * image, because otherwise it is not really a compound menubutton. */ if (mbPtr->compound != COMPOUND_NONE && haveImage && haveText) { switch ((enum compound) mbPtr->compound) { case COMPOUND_TOP: case COMPOUND_BOTTOM: /* * Image is above or below text. */ height += txtHeight + mbPtr->padY; width = (width > txtWidth ? width : txtWidth); break; case COMPOUND_LEFT: case COMPOUND_RIGHT: /* * Image is left or right of text. */ width += txtWidth + mbPtr->padX; height = (height > txtHeight ? height : txtHeight); break; case COMPOUND_CENTER: /* * Image and text are superimposed. */ width = (width > txtWidth ? width : txtWidth); height = (height > txtHeight ? height : txtHeight); break; case COMPOUND_NONE: break; } if (mbPtr->width > 0) { width = mbPtr->width; } if (mbPtr->height > 0) { height = mbPtr->height; } width += 2*mbPtr->padX; height += 2*mbPtr->padY; } else { if (haveImage) { if (mbPtr->width > 0) { width = mbPtr->width; } if (mbPtr->height > 0) { height = mbPtr->height; } } else { width = txtWidth; height = txtHeight; if (mbPtr->width > 0) { width = mbPtr->width * avgWidth; } if (mbPtr->height > 0) { height = mbPtr->height * fm.linespace; } } } if (! haveImage) { width += 2*mbPtr->padX; height += 2*mbPtr->padY; } if (mbPtr->indicatorOn) { mm = WidthMMOfScreen(Tk_Screen(mbPtr->tkwin)); pixels = WidthOfScreen(Tk_Screen(mbPtr->tkwin)); mbPtr->indicatorHeight= (INDICATOR_HEIGHT * pixels)/(10*mm); mbPtr->indicatorWidth = (INDICATOR_WIDTH * pixels)/(10*mm) + 2*mbPtr->indicatorHeight; width += mbPtr->indicatorWidth; } else { mbPtr->indicatorHeight = 0; mbPtr->indicatorWidth = 0; } Tk_GeometryRequest(mbPtr->tkwin, (int) (width + 2*mbPtr->inset), (int) (height + 2*mbPtr->inset)); Tk_SetInternalBorder(mbPtr->tkwin, mbPtr->inset); }
main() { int llx,lly,urx,ury,width,height, scrwidth,scrheight,scrwidthmm,scrheightmm; float xres,yres; char buf[LBUF]; Display *dpy; int scr; unsigned long black,white; GC gcpix,gcwin; Window win; Pixmap pix; XEvent ev; DPSContext dps; /* open display */ if ((dpy=XOpenDisplay(NULL))==NULL) { fprintf(stderr,"Cannot connect to display %s\n", XDisplayName(NULL)); exit(-1); } scr = DefaultScreen(dpy); black = BlackPixel(dpy,scr); white = WhitePixel(dpy,scr); /* determine BoundingBox */ llx = LLX_DEFAULT; lly = LLY_DEFAULT; urx = URX_DEFAULT; ury = URY_DEFAULT; fgets(buf,LBUF,stdin); if (strstr(buf,"EPS")!=NULL) { while(fgets(buf,LBUF,stdin)!=NULL) { if (buf[0]!='%' || buf[1]!='%') continue; if (strstr(buf,"%%BoundingBox:")==buf) { if (strstr(buf,"(atend)")==NULL) { sscanf(&buf[14],"%d %d %d %d", &llx,&lly,&urx,&ury); } break; } else if (strstr(buf,"%%EndComments")==buf) { break; } else if (strstr(buf,"%%EndProlog")==buf) { break; } } } /* width and height in pixels */ scrwidth = WidthOfScreen(DefaultScreenOfDisplay(dpy)); scrheight = HeightOfScreen(DefaultScreenOfDisplay(dpy)); scrwidthmm = WidthMMOfScreen(DefaultScreenOfDisplay(dpy)); scrheightmm = HeightMMOfScreen(DefaultScreenOfDisplay(dpy)); xres = (int)(25.4*scrwidth/scrwidthmm)/72.0; yres = (int)(25.4*scrheight/scrheightmm)/72.0; if (xres*(urx-llx)>scrwidth || yres*(ury-lly)>scrheight) { xres = (scrwidth-32.0)/(urx-llx); yres = (scrheight-32.0)/(ury-lly); xres = yres = (xres<yres)?xres:yres; } width = (urx-llx)*xres; height = (ury-lly)*yres; /* create pixmap and its gc */ pix = XCreatePixmap(dpy,DefaultRootWindow(dpy),width,height, DefaultDepth(dpy,scr)); gcpix = XCreateGC(dpy,pix,0,NULL); /* create and set Display PostScript context for pixmap */ dps = XDPSCreateSimpleContext(dpy,pix,gcpix,0,height, DPSDefaultTextBackstop,DPSDefaultErrorProc,NULL); if (dps==NULL) { fprintf(stderr,"Cannot create DPS context\n"); exit(-1); } DPSPrintf(dps,"\n resyncstart\n"); DPSSetContext(dps); DPSFlushContext(dps); DPSWaitContext(dps); /* paint white background */ DPSPrintf(dps, "gsave\n" "1 setgray\n" "0 0 %d %d rectfill\n" "grestore\n", urx-llx,ury-lly); /* translate */ DPSPrintf(dps,"%d %d translate\n",-llx,-lly); /* read PostScript from standard input and render in pixmap */ DPSPrintf(dps,"/showpage {} def\n"); while (fgets(buf,LBUF,stdin)!=NULL) DPSWritePostScript(dps,buf,strlen(buf)); DPSFlushContext(dps); DPSWaitContext(dps); /* create and map window */ win = XCreateSimpleWindow(dpy,DefaultRootWindow(dpy), 100,100,width,height,1,black,white); XSetStandardProperties(dpy,win,"EPS Pixmap","EPSpix", None,NULL,0,NULL); XMapWindow(dpy,win); /* copy pixmap to window; in pixmap, black=0 and white=1 */ gcwin = XCreateGC(dpy,win,0,NULL); XCopyArea(dpy,pix,win,gcwin,0,0,width,height,0,0); /* main event loop */ XSelectInput(dpy,win, KeyPressMask | ExposureMask); while(True) { XNextEvent(dpy,&ev); if (ev.type==Expose) { while (XCheckTypedEvent(dpy,Expose,&ev)); XCopyArea(dpy,pix,win,gcwin,0,0,width,height,0,0); } else if (ev.type==KeyPress) { break; } } /* clean up */ DPSDestroySpace(DPSSpaceFromContext(dps)); XFreePixmap(dpy,pix); XFreeGC(dpy,gcpix); XFreeGC(dpy,gcwin); }
static int GetPixelsFromObjEx( Tcl_Interp *interp, /* Used for error reporting if not NULL. */ Tk_Window tkwin, Tcl_Obj *objPtr, /* The object from which to get pixels. */ int *intPtr, double *dblPtr) /* Places to store resulting pixels. */ { int result, fresh; double d; PixelRep *pixelPtr; static double bias[] = { 1.0, 10.0, 25.4, 0.35278 /*25.4 / 72.0*/ }; /* * Special hacks where the type of the object is known to be something * that is just numeric and cannot require distance conversion. This pokes * holes in Tcl's abstractions, but they are just for optimization, not * semantics. */ if (objPtr->typePtr != &pixelObjType) { ThreadSpecificData *typeCache = GetTypeCache(); if (objPtr->typePtr == typeCache->doubleTypePtr) { (void) Tcl_GetDoubleFromObj(interp, objPtr, &d); if (dblPtr != NULL) { *dblPtr = d; } *intPtr = (int) (d<0 ? d-0.5 : d+0.5); return TCL_OK; } else if (objPtr->typePtr == typeCache->intTypePtr) { (void) Tcl_GetIntFromObj(interp, objPtr, intPtr); if (dblPtr) { *dblPtr = (double) (*intPtr); } return TCL_OK; } } retry: fresh = (objPtr->typePtr != &pixelObjType); if (fresh) { result = SetPixelFromAny(interp, objPtr); if (result != TCL_OK) { return result; } } if (SIMPLE_PIXELREP(objPtr)) { *intPtr = GET_SIMPLEPIXEL(objPtr); if (dblPtr) { *dblPtr = (double) (*intPtr); } } else { pixelPtr = GET_COMPLEXPIXEL(objPtr); if ((!fresh) && (pixelPtr->tkwin != tkwin)) { /* * In the case of exo-screen conversions of non-pixels, we force a * recomputation from the string. */ FreePixelInternalRep(objPtr); goto retry; } if ((pixelPtr->tkwin != tkwin) || dblPtr) { d = pixelPtr->value; if (pixelPtr->units >= 0) { d *= bias[pixelPtr->units] * WidthOfScreen(Tk_Screen(tkwin)); d /= WidthMMOfScreen(Tk_Screen(tkwin)); } pixelPtr->returnValue = (int) (d<0 ? d-0.5 : d+0.5); pixelPtr->tkwin = tkwin; if (dblPtr) { *dblPtr = d; } } *intPtr = pixelPtr->returnValue; } return TCL_OK; }
int XWidthMMOfScreen(Screen *s) { return (WidthMMOfScreen(s)); }
double XDPSPixelsPerPoint(Screen *screen) { return (float) WidthOfScreen(screen) * mmPerPoint / (float) WidthMMOfScreen(screen); }
/* This function gets the X Display and global info about it. Everything is stored in our object and will be cleaned when the object is disposed. Note here that caps for supported format are generated without any window or image creation */ GstXContext * ximageutil_xcontext_get (GstElement * parent, const gchar * display_name) { GstXContext *xcontext = NULL; XPixmapFormatValues *px_formats = NULL; gint nb_formats = 0, i; xcontext = g_new0 (GstXContext, 1); xcontext->disp = XOpenDisplay (display_name); GST_DEBUG_OBJECT (parent, "opened display %p", xcontext->disp); if (!xcontext->disp) { g_free (xcontext); return NULL; } xcontext->screen = DefaultScreenOfDisplay (xcontext->disp); xcontext->visual = DefaultVisualOfScreen (xcontext->screen); xcontext->root = RootWindowOfScreen (xcontext->screen); xcontext->white = WhitePixelOfScreen (xcontext->screen); xcontext->black = BlackPixelOfScreen (xcontext->screen); xcontext->depth = DefaultDepthOfScreen (xcontext->screen); xcontext->width = WidthOfScreen (xcontext->screen); xcontext->height = HeightOfScreen (xcontext->screen); xcontext->widthmm = WidthMMOfScreen (xcontext->screen); xcontext->heightmm = HeightMMOfScreen (xcontext->screen); xcontext->caps = NULL; GST_DEBUG_OBJECT (parent, "X reports %dx%d pixels and %d mm x %d mm", xcontext->width, xcontext->height, xcontext->widthmm, xcontext->heightmm); ximageutil_calculate_pixel_aspect_ratio (xcontext); /* We get supported pixmap formats at supported depth */ px_formats = XListPixmapFormats (xcontext->disp, &nb_formats); if (!px_formats) { XCloseDisplay (xcontext->disp); g_free (xcontext); return NULL; } /* We get bpp value corresponding to our running depth */ for (i = 0; i < nb_formats; i++) { if (px_formats[i].depth == xcontext->depth) xcontext->bpp = px_formats[i].bits_per_pixel; } XFree (px_formats); xcontext->endianness = (ImageByteOrder (xcontext->disp) == LSBFirst) ? G_LITTLE_ENDIAN : G_BIG_ENDIAN; #ifdef HAVE_XSHM /* Search for XShm extension support */ if (XShmQueryExtension (xcontext->disp) && ximageutil_check_xshm_calls (xcontext)) { xcontext->use_xshm = TRUE; GST_DEBUG ("ximageutil is using XShm extension"); } else { xcontext->use_xshm = FALSE; GST_DEBUG ("ximageutil is not using XShm extension"); } #endif /* HAVE_XSHM */ /* our caps system handles 24/32bpp RGB as big-endian. */ if ((xcontext->bpp == 24 || xcontext->bpp == 32) && xcontext->endianness == G_LITTLE_ENDIAN) { xcontext->endianness = G_BIG_ENDIAN; xcontext->r_mask_output = GUINT32_TO_BE (xcontext->visual->red_mask); xcontext->g_mask_output = GUINT32_TO_BE (xcontext->visual->green_mask); xcontext->b_mask_output = GUINT32_TO_BE (xcontext->visual->blue_mask); if (xcontext->bpp == 24) { xcontext->r_mask_output >>= 8; xcontext->g_mask_output >>= 8; xcontext->b_mask_output >>= 8; }
static gint gdk_x11_screen_get_width_mm (GdkScreen *screen) { return WidthMMOfScreen (GDK_X11_SCREEN (screen)->xscreen); }
static void init_no_multihead (GdkX11Screen *x11_screen, gboolean *changed) { GdkX11Display *x11_display = GDK_X11_DISPLAY (x11_screen->display); GdkX11Monitor *monitor; GdkRectangle geometry; int width_mm, height_mm; int width, height; int i; for (i = 0; i < x11_display->monitors->len; i++) { monitor = x11_display->monitors->pdata[i]; monitor->add = FALSE; monitor->remove = TRUE; } monitor = find_monitor_by_output (x11_display, 0); if (monitor) monitor->remove = FALSE; else { monitor = g_object_new (gdk_x11_monitor_get_type (), "display", x11_display, NULL); monitor->output = 0; monitor->add = TRUE; g_ptr_array_add (x11_display->monitors, monitor); } width_mm = WidthMMOfScreen (x11_screen->xscreen); height_mm = HeightMMOfScreen (x11_screen->xscreen); width = WidthOfScreen (x11_screen->xscreen); height = HeightOfScreen (x11_screen->xscreen); gdk_monitor_get_geometry (GDK_MONITOR (monitor), &geometry); if (0 != geometry.x || 0 != geometry.y || width != geometry.width || height != geometry.height || width_mm != gdk_monitor_get_width_mm (GDK_MONITOR (monitor)) || height_mm != gdk_monitor_get_height_mm (GDK_MONITOR (monitor))) *changed = TRUE; gdk_monitor_set_position (GDK_MONITOR (monitor), 0, 0); gdk_monitor_set_size (GDK_MONITOR (monitor), width, height); g_object_notify (G_OBJECT (monitor), "workarea"); gdk_monitor_set_physical_size (GDK_MONITOR (monitor), width_mm, height_mm); gdk_monitor_set_scale_factor (GDK_MONITOR (monitor), x11_screen->surface_scale); if (x11_display->primary_monitor != 0) *changed = TRUE; x11_display->primary_monitor = 0; for (i = x11_display->monitors->len - 1; i >= 0; i--) { monitor = x11_display->monitors->pdata[i]; if (monitor->add) { gdk_display_monitor_added (GDK_DISPLAY (x11_display), GDK_MONITOR (monitor)); *changed = TRUE; } else if (monitor->remove) { g_object_ref (monitor); g_ptr_array_remove (x11_display->monitors, monitor); gdk_display_monitor_removed (GDK_DISPLAY (x11_display), GDK_MONITOR (monitor)); g_object_unref (monitor); *changed = TRUE; } } }