Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
static gint
gdk_x11_screen_get_height_mm (GdkScreen *screen)
{
  g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);

  return HeightMMOfScreen (GDK_X11_SCREEN (screen)->xscreen);
}
Ejemplo n.º 3
0
/* 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;
    }
Ejemplo n.º 4
0
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);
}
Ejemplo n.º 5
0
static gint
gdk_x11_screen_get_height_mm (GdkScreen *screen)
{
  return HeightMMOfScreen (GDK_X11_SCREEN (screen)->xscreen);
}
Ejemplo n.º 6
0
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);
}
Ejemplo n.º 7
0
int XHeightMMOfScreen(Screen *s) { return (HeightMMOfScreen(s)); }
Ejemplo n.º 8
0
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;
        }
    }
}