-/* 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
* - 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() */
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];
w = e.width;
lh = ascent + descent;
if (w > max_w) max_w = w;
- lines++;
token = 0;
}
free (string2);
- if (! wire) glEnable (GL_DEPTH_TEST);
+ if (! wire)
+ {
+ glEnable (GL_DEPTH_TEST);
+ glEnable (GL_LIGHTING);
+ glEnable (GL_BLEND);
+ }
return polys;
}
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");
}
{
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();
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);
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 */
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);
# 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;
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)