]> git.hungrycats.org Git - xscreensaver/blobdiff - hacks/glx/sonar.c
From https://www.jwz.org/xscreensaver/xscreensaver-6.09.tar.gz
[xscreensaver] / hacks / glx / sonar.c
index 42bcdc8e7d6cc4ddb3d8afff039dff1535c00f2a..80f3fc686f182b2fbe15dbb9295edcd250485ca0 100644 (file)
@@ -1,4 +1,4 @@
-/* sonar, Copyright (c) 1998-2015 Jamie Zawinski and Stephen Martin
+/* sonar, Copyright (c) 1998-2020 Jamie Zawinski and Stephen Martin
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
@@ -51,7 +51,7 @@
  *   - plot IM contacts or Facebook friends and their last-activity times.
  */
 
-#define DEF_FONT "-*-courier-bold-r-normal-*-*-480-*-*-*-*-iso8859-1"
+#define DEF_FONT        "monospace bold 48"
 #define DEF_SPEED        "1.0"
 #define DEF_SWEEP_SIZE   "0.3"
 #define DEF_FONT_SIZE    "12"
                        THREAD_DEFAULTS_XLOCK
 
 
-# define refresh_sonar 0
 # define release_sonar 0
-#undef countof
-#define countof(x) (sizeof((x))/sizeof((*x)))
 
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>   /* for setuid() */
@@ -350,11 +347,13 @@ draw_text (ModeInfo *mi, const char *string, GLfloat r, GLfloat th,
   int wire = MI_IS_WIREFRAME(mi);
   int polys = 0;
   GLfloat font_scale = 0.001 * (size > 0 ? size : font_size) / 14.0;
-  int lines = 0, max_w = 0, lh = 0;
+  int max_w = 0, lh = 0;
   char *string2 = strdup (string);
   char *token = string2;
   char *line;
 
+  if (MI_WIDTH(mi) > 2560) font_scale /= 2;  /* Retina displays */
+
   if (size <= 0)   /* if size not specified, draw in yellow with alpha */
     {
       GLfloat color[4];
@@ -377,7 +376,6 @@ draw_text (ModeInfo *mi, const char *string, GLfloat r, GLfloat th,
       w = e.width;
       lh = ascent + descent;
       if (w > max_w) max_w = w;
-      lines++;
       token = 0;
     }
 
@@ -438,7 +436,12 @@ draw_text (ModeInfo *mi, const char *string, GLfloat r, GLfloat th,
 
   free (string2);
 
-  if (! wire) glEnable (GL_DEPTH_TEST);
+  if (! wire)
+    {
+      glEnable (GL_DEPTH_TEST);
+      glEnable (GL_LIGHTING);
+      glEnable (GL_BLEND);
+    }
 
   return polys;
 }
@@ -622,17 +625,20 @@ static void
 update_sensor_data (sonar_configuration *sp)
 {
   sonar_bogie *new_list = sp->ssd->scan_cb (sp->ssd);
-  sonar_bogie *b2;
+  sonar_bogie *b2, *next;
 
   /* If a bogie exists in 'new_list' but not 'pending', add it.
      If a bogie exists in both, update it in 'pending'.
    */
-  for (b2 = new_list; b2; b2 = b2->next)
+  for (b2 = new_list, next = b2 ? b2->next : 0; 
+       b2; 
+       b2 = next, next = next ? next->next : 0)
     {
       if (debug_p > 2)
         fprintf (stderr, "%s:   updated: %s (%5.2f %5.2f %5.2f)\n", 
                  progname, b2->name, b2->r, b2->th, b2->ttl);
       copy_and_insert_bogie (sp->ssd, b2, &sp->pending);
+      sonar_free_bogie (sp->ssd, b2);
     }
   if (debug_p > 2) fprintf (stderr, "\n");
 }
@@ -785,8 +791,15 @@ reshape_sonar (ModeInfo *mi, int width, int height)
 {
   sonar_configuration *sp = &sps[MI_SCREEN(mi)];
   GLfloat h = (GLfloat) height / (GLfloat) width;
+  int y = 0;
+
+  if (width > height * 5) {   /* tiny window: show middle */
+    height = width * 9/16;
+    y = -height/2;
+    h = height / (GLfloat) width;
+  }
 
-  glViewport (0, 0, (GLint) width, (GLint) height);
+  glViewport (0, y, (GLint) width, (GLint) height);
 
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
@@ -817,14 +830,12 @@ sonar_handle_event (ModeInfo *mi, XEvent *event)
   return False;
 }
 
-static void free_sonar (ModeInfo *mi);
-
 ENTRYPOINT void 
 init_sonar (ModeInfo *mi)
 {
   sonar_configuration *sp;
 
-  MI_INIT (mi, sps, free_sonar);
+  MI_INIT (mi, sps);
   sp = &sps[MI_SCREEN(mi)];
   sp->glx_context = init_GL(mi);
 
@@ -925,8 +936,9 @@ init_sensor (ModeInfo *mi)
     sp->ssd = sonar_init_ping (MI_DISPLAY (mi), &sp->error, &sp->desc,
                                ping_arg, ping_timeout, resolve_p, times_p,
                                debug_p);
-  else
-    setuid(getuid()); /* Disavow privs if not pinging. */
+
+  /* Might have done this already, but disavow in simulation mode too. */
+  if (setuid(getuid()) == -1) abort();
 
   sp->start_time = double_time ();  /* for error message timing */
 
@@ -1035,7 +1047,7 @@ draw_sonar (ModeInfo *mi)
   if (!sp->glx_context)
     return;
 
-  glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(sp->glx_context));
+  glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *sp->glx_context);
 
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
@@ -1218,16 +1230,19 @@ draw_sonar (ModeInfo *mi)
 # endif /* TEST_ASYNC_NETDB */
 }
 
-static void
+ENTRYPOINT void
 free_sonar (ModeInfo *mi)
 {
-#if 0
   sonar_configuration *sp = &sps[MI_SCREEN(mi)];
   sonar_bogie *b = sp->displayed;
+
+  if (!sp->glx_context) return;
+  glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *sp->glx_context);
+
   while (b)
     {
       sonar_bogie *next = b->next;
-      free_bogie (sp->ssd, b);
+      sonar_free_bogie (sp->ssd, b);
       b = next;
     }
   sp->displayed = 0;
@@ -1236,15 +1251,24 @@ free_sonar (ModeInfo *mi)
   while (b)
     {
       sonar_bogie *next = b->next;
-      free_bogie (sp->ssd, b);
+      sonar_free_bogie (sp->ssd, b);
       b = next;
     }
   sp->pending = 0;
 
-  sp->ssd->free_data_cb (sp->ssd, sp->ssd->closure);
-  free (sp->ssd);
-  sp->ssd = 0;
-#endif
+  if (sp->ssd) {
+    sp->ssd->free_data_cb (sp->ssd, sp->ssd->closure);
+    free (sp->ssd);
+    sp->ssd = 0;
+  }
+
+  if (sp->trackball) gltrackball_free (sp->trackball);
+  if (sp->rot) free_rotator (sp->rot);
+  if (sp->texfont) free_texture_font (sp->texfont);
+  glDeleteLists (sp->table_list, 1);
+  glDeleteLists (sp->screen_list, 1);
+  glDeleteLists (sp->grid_list, 1);
+  glDeleteLists (sp->sweep_list, 1);
 }
 
 XSCREENSAVER_MODULE ("Sonar", sonar)