From http://www.jwz.org/xscreensaver/xscreensaver-5.35.tar.gz
[xscreensaver] / hacks / glx / fps-gl.c
index 46757708c937c6bb3698b543b3cdb30553a6dd83..eb6b6de5fbe4fdfb92ea7c623c7474338cbc3dfd 100644 (file)
@@ -1,4 +1,4 @@
-/* fps, Copyright (c) 2001-2014 Jamie Zawinski <jwz@jwz.org>
+/* fps, Copyright (c) 2001-2015 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
@@ -38,6 +38,7 @@ extern void check_gl_error (const char *type);
 typedef struct {
   texture_font_data *texfont;
   int line_height;
+  Bool top_p;
 } gl_fps_data;
 
 
@@ -45,8 +46,11 @@ static void
 xlockmore_gl_fps_init (fps_state *st)
 {
   gl_fps_data *data = (gl_fps_data *) calloc (1, sizeof(*data));
+  int ascent, descent;
+  data->top_p = get_boolean_resource (st->dpy, "fpsTop", "FPSTop");
   data->texfont = load_texture_font (st->dpy, "fpsFont");
-  texture_string_width (data->texfont, "M", &data->line_height);
+  texture_string_metrics (data->texfont, "M", 0, &ascent, &descent);
+  data->line_height = ascent + descent;
   st->gl_fps_data = data;
 }
 
@@ -80,19 +84,15 @@ xlockmore_gl_draw_fps (ModeInfo *mi)
       XWindowAttributes xgwa;
       int lines = 1;
       const char *s;
-      int y = st->y;
 
       XGetWindowAttributes (st->dpy, st->window, &xgwa);
       for (s = st->string; *s; s++) 
         if (*s == '\n') lines++;
 
-      if (y < 0)
-        y = xgwa.height + y - (lines * data->line_height);
-      y += lines * data->line_height;
-
       glColor3f (1, 1, 1);
       print_texture_label (st->dpy, data->texfont,
                            xgwa.width, xgwa.height,
-                           2, st->string);
+                           (data->top_p ? 1 : 2),
+                           st->string);
     }
 }