From http://www.jwz.org/xscreensaver/xscreensaver-5.39.tar.gz
[xscreensaver] / hacks / fps.c
index 2aa0174377756afeaea6754ada674ff93a8b4a44..a24f62315f98879d8d7b792290be78c830446bd6 100644 (file)
@@ -1,4 +1,4 @@
-/* fps, Copyright (c) 2001-2008 Jamie Zawinski <jwz@jwz.org>
+/* fps, Copyright (c) 2001-2018 Jamie Zawinski <jwz@jwz.org>
  * Draw a frames-per-second display (Xlib and OpenGL).
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
@@ -14,6 +14,7 @@
 # include "config.h"
 #endif /* HAVE_CONFIG_H */
 
+#include <time.h>
 #include "screenhackI.h"
 #include "fpsI.h"
 
@@ -23,11 +24,16 @@ fps_init (Display *dpy, Window window)
   fps_state *st;
   const char *font;
   XFontStruct *f;
-  int first, last;
+  Bool top_p;
+  XWindowAttributes xgwa;
 
   if (! get_boolean_resource (dpy, "doFPS", "DoFPS"))
     return 0;
 
+  if (!strcasecmp (progname, "BSOD")) return 0;  /* Never worked right */
+
+  top_p = get_boolean_resource (dpy, "fpsTop", "FPSTop");
+
   st = (fps_state *) calloc (1, sizeof(*st));
 
   st->dpy = dpy;
@@ -36,15 +42,12 @@ fps_init (Display *dpy, Window window)
 
   font = get_string_resource (dpy, "fpsFont", "Font");
 
-  if (!font) font = "-*-courier-bold-r-normal-*-180-*";
-  f = XLoadQueryFont (dpy, font);
-  if (!f) f = XLoadQueryFont (dpy, "fixed");
-
-  first = f->min_char_or_byte2;
-  last = f->max_char_or_byte2;
+  if (!font)
+    font = "-*-courier-bold-r-normal-*-*-180-*-*-*-*-*-*"; /* also texfont.c */
+  f = load_font_retry (dpy, font);
+  if (!f) abort();
 
   {
-    XWindowAttributes xgwa;
     XGCValues gcv;
     XGetWindowAttributes (dpy, window, &xgwa);
     gcv.font = f->fid;
@@ -59,9 +62,20 @@ fps_init (Display *dpy, Window window)
   st->font = f;
   st->x = 10;
   st->y = 10;
-  if (get_boolean_resource (dpy, "fpsTop", "FPSTop"))
+  if (top_p)
     st->y = - (st->font->ascent + st->font->descent + 10);
 
+# ifdef USE_IPHONE
+  /* Don't hide the FPS display under the iPhone X bezel.
+     #### This is the worst of all possible ways to do this!  But how else?
+   */
+  if (xgwa.width == 2436 || xgwa.height == 2436)
+    {
+      st->x += 48;
+      st->y += 48 * (top_p ? -1 : 1);
+    }
+# endif
+
   strcpy (st->string, "FPS: ... ");
 
   return st;
@@ -85,7 +99,7 @@ fps_slept (fps_state *st, unsigned long usecs)
 
 
 double
-fps_compute (fps_state *st, unsigned long polys)
+fps_compute (fps_state *st, unsigned long polys, double depth)
 {
   if (! st) return 0;  /* too early? */
 
@@ -153,6 +167,18 @@ fps_compute (fps_state *st, unsigned long polys)
           else
             sprintf (st->string + strlen(st->string), "%lu%s ", polys, s);
         }
+
+      if (depth >= 0.0)
+        {
+          unsigned long L = strlen (st->string);
+          char *s = st->string + L;
+          strcat (s, "\nDepth: ");
+          sprintf (s + strlen(s), "%.1f", depth);
+          L = strlen (s);
+          /* Remove trailing ".0" in case depth is not a fraction. */
+          if (s[L-2] == '.' && s[L-1] == '0')
+            s[L-2] = 0;
+        }
     }
 
   return st->last_fps;
@@ -190,7 +216,7 @@ string_width (XFontStruct *f, const char *c, int *height_ret)
 }
 
 
-/* This function is used only in Xlib mode.  For GL mode, see glx/fps-glx.c.
+/* This function is used only in Xlib mode.  For GL mode, see glx/fps-gl.c.
  */
 void
 fps_draw (fps_state *st)
@@ -233,7 +259,7 @@ fps_draw (fps_state *st)
       s = strchr (string, '\n');
       if (! s) s = string + strlen(string);
       XDrawString (st->dpy, st->window, st->draw_gc,
-                   x, y, string, s - string);
+                   x, y, string, (int) (s - string));
       string = s;
       string++;
       lines--;