28
28
#define DEFAULT_MIN_SPEED 0.001
29
29
#define DEFAULT_MAX_SPEED 0.02
31
char *progclass = "Halftone";
47
XrmOptionDescRec options [] = {
48
{ "-delay", ".delay", XrmoptionSepArg, 0 },
49
{ "-count", ".count", XrmoptionSepArg, 0 },
50
{ "-minmass", ".minMass", XrmoptionSepArg, 0 },
51
{ "-maxmass", ".maxMass", XrmoptionSepArg, 0 },
52
{ "-minspeed", ".minSpeed", XrmoptionSepArg, 0 },
53
{ "-maxspeed", ".maxSpeed", XrmoptionSepArg, 0 },
54
{ "-spacing", ".spacing", XrmoptionSepArg, 0 },
55
{ "-sizefactor", ".sizeFactor", XrmoptionSepArg, 0 },
56
{ "-colors", ".colors", XrmoptionSepArg, 0 },
57
{ "-cycle-speed", ".cycleSpeed", XrmoptionSepArg, 0 },
104
78
if (halftone->buffer_width != -1 &&
105
79
halftone->buffer_height != -1)
107
XFreePixmap(halftone->display, halftone->buffer);
108
XFreeGC(halftone->display, halftone->buffer_gc);
81
if (halftone->buffer == halftone->window)
82
XFreePixmap(halftone->dpy, halftone->buffer);
83
XFreeGC(halftone->dpy, halftone->buffer_gc);
111
86
halftone->buffer_width = attrs->width;
112
87
halftone->buffer_height = attrs->height;
113
halftone->buffer = XCreatePixmap(halftone->display, halftone->window, halftone->buffer_width, halftone->buffer_height, attrs->depth);
88
#ifdef HAVE_COCOA /* Don't second-guess Quartz's double-buffering */
89
halftone->buffer = halftone->window;
91
halftone->buffer = XCreatePixmap(halftone->dpy, halftone->window, halftone->buffer_width, halftone->buffer_height, attrs->depth);
115
halftone->buffer_gc = XCreateGC(halftone->display, halftone->buffer, GCForeground|GCBackground, &gc_values);
94
halftone->buffer_gc = XCreateGC(halftone->dpy, halftone->buffer, 0, &gc_values);
151
131
halftone = (halftone_screen *) calloc (1, sizeof(halftone_screen));
153
halftone->display = display;
154
134
halftone->window = window;
156
halftone->gc = XCreateGC (halftone->display, halftone->window, GCForeground | GCBackground, &gc_values);
136
halftone->delay = get_integer_resource (dpy, "delay", "Integer");
137
halftone->delay = (halftone->delay < 0 ? DEFAULT_DELAY : halftone->delay);
139
halftone->gc = XCreateGC (halftone->dpy, halftone->window, 0, &gc_values);
158
141
halftone->buffer_width = -1;
159
142
halftone->buffer_height = -1;
160
143
halftone->dots = NULL;
162
145
/* Read command line arguments and set all settings. */
163
count = get_integer_resource ("count", "Count");
146
count = get_integer_resource (dpy, "count", "Count");
164
147
halftone->gravity_point_count = count < 1 ? DEFAULT_COUNT : count;
166
spacing = get_integer_resource ("spacing", "Integer");
149
spacing = get_integer_resource (dpy, "spacing", "Integer");
167
150
halftone->spacing = spacing < 1 ? DEFAULT_SPACING : spacing;
169
factor = get_float_resource ("sizeFactor", "Double");
152
factor = get_float_resource (dpy, "sizeFactor", "Double");
170
153
halftone->max_dot_size =
171
154
(factor < 0 ? DEFAULT_SIZE_FACTOR : factor) * halftone->spacing;
173
min_mass = get_float_resource ("minMass", "Double");
156
min_mass = get_float_resource (dpy, "minMass", "Double");
174
157
min_mass = min_mass < 0 ? DEFAULT_MIN_MASS : min_mass;
176
max_mass = get_float_resource ("maxMass", "Double");
159
max_mass = get_float_resource (dpy, "maxMass", "Double");
177
160
max_mass = max_mass < 0 ? DEFAULT_MAX_MASS : max_mass;
178
161
max_mass = max_mass < min_mass ? min_mass : max_mass;
180
min_speed = get_float_resource ("minSpeed", "Double");
163
min_speed = get_float_resource (dpy, "minSpeed", "Double");
181
164
min_speed = min_speed < 0 ? DEFAULT_MIN_SPEED : min_speed;
183
max_speed = get_float_resource ("maxSpeed", "Double");
166
max_speed = get_float_resource (dpy, "maxSpeed", "Double");
184
167
max_speed = max_speed < 0 ? DEFAULT_MAX_SPEED : max_speed;
185
168
max_speed = max_speed < min_speed ? min_speed : max_speed;
205
188
/* Set up the dots. */
206
XGetWindowAttributes(halftone->display, halftone->window, &attrs);
189
XGetWindowAttributes(halftone->dpy, halftone->window, &attrs);
208
halftone->ncolors = get_integer_resource ("colors", "Colors");
191
halftone->ncolors = get_integer_resource (dpy, "colors", "Colors");
209
192
if (halftone->ncolors < 4) halftone->ncolors = 4;
210
193
halftone->colors = (XColor *) calloc(halftone->ncolors, sizeof(XColor));
211
make_smooth_colormap (display, attrs.visual, attrs.colormap,
194
make_smooth_colormap (dpy, attrs.visual, attrs.colormap,
212
195
halftone->colors, &halftone->ncolors,
214
197
halftone->color0 = 0;
215
198
halftone->color1 = halftone->ncolors / 2;
216
halftone->cycle_speed = get_integer_resource ("cycleSpeed", "CycleSpeed");
199
halftone->cycle_speed = get_integer_resource (dpy, "cycleSpeed", "CycleSpeed");
217
200
halftone->color_tick = 0;
219
202
update_buffer(halftone, &attrs);
233
static void fill_circle(Display *display, Window window, GC gc, int x, int y, int size)
216
static void fill_circle(Display *dpy, Window window, GC gc, int x, int y, int size)
235
218
int start_x = x - (size / 2);
236
219
int start_y = y - (size / 2);
240
223
int angle2 = 360 * 64; /* A full circle */
242
XFillArc (display, window, gc,
225
XFillArc (dpy, window, gc,
243
226
start_x, start_y, width, height,
258
241
/* Fill buffer with background color */
259
XSetForeground (halftone->display, halftone->buffer_gc,
242
XSetForeground (halftone->dpy, halftone->buffer_gc,
260
243
halftone->colors[halftone->color0].pixel);
261
XFillRectangle(halftone->display, halftone->buffer, halftone->buffer_gc, 0, 0, halftone->buffer_width, halftone->buffer_height);
244
XFillRectangle(halftone->dpy, halftone->buffer, halftone->buffer_gc, 0, 0, halftone->buffer_width, halftone->buffer_height);
263
246
/* Draw dots on buffer */
264
XSetForeground (halftone->display, halftone->buffer_gc,
247
XSetForeground (halftone->dpy, halftone->buffer_gc,
265
248
halftone->colors[halftone->color1].pixel);
267
250
if (halftone->color_tick++ >= halftone->cycle_speed)
274
257
for (x = 0; x < halftone->dots_width; x++)
275
258
for (y = 0; y < halftone->dots_height; y++)
276
fill_circle(halftone->display, halftone->buffer, halftone->buffer_gc,
259
fill_circle(halftone->dpy, halftone->buffer, halftone->buffer_gc,
277
260
x_offset + x * halftone->spacing, y_offset + y * halftone->spacing,
278
261
halftone->max_dot_size * halftone->dots[x + y * halftone->dots_width]);
280
263
/* Copy buffer to window */
281
XCopyArea(halftone->display, halftone->buffer, halftone->window, halftone->gc, 0, 0, halftone->buffer_width, halftone->buffer_height, 0, 0);
264
if (halftone->buffer != halftone->window)
265
XCopyArea(halftone->dpy, halftone->buffer, halftone->window, halftone->gc, 0, 0, halftone->buffer_width, halftone->buffer_height, 0, 0);
284
268
static double calculate_gravity(halftone_screen *halftone, int x, int y)
348
void screenhack (Display *display, Window window)
350
halftone_screen *halftone = init_halftone(display, window);
351
int delay = get_integer_resource ("delay", "Integer");
352
delay = (delay < 0 ? DEFAULT_DELAY : delay);
356
repaint_halftone(halftone);
357
update_halftone(halftone);
358
screenhack_handle_events (display);
333
halftone_draw (Display *dpy, Window window, void *closure)
335
halftone_screen *halftone = (halftone_screen *) closure;
337
repaint_halftone(halftone);
338
update_halftone(halftone);
340
return halftone->delay;
345
halftone_reshape (Display *dpy, Window window, void *closure,
346
unsigned int w, unsigned int h)
351
halftone_event (Display *dpy, Window window, void *closure, XEvent *event)
357
halftone_free (Display *dpy, Window window, void *closure)
359
halftone_screen *halftone = (halftone_screen *) closure;
364
static const char *halftone_defaults [] = {
365
".background: Black",
379
static XrmOptionDescRec halftone_options [] = {
380
{ "-delay", ".delay", XrmoptionSepArg, 0 },
381
{ "-count", ".count", XrmoptionSepArg, 0 },
382
{ "-minmass", ".minMass", XrmoptionSepArg, 0 },
383
{ "-maxmass", ".maxMass", XrmoptionSepArg, 0 },
384
{ "-minspeed", ".minSpeed", XrmoptionSepArg, 0 },
385
{ "-maxspeed", ".maxSpeed", XrmoptionSepArg, 0 },
386
{ "-spacing", ".spacing", XrmoptionSepArg, 0 },
387
{ "-sizefactor", ".sizeFactor", XrmoptionSepArg, 0 },
388
{ "-colors", ".colors", XrmoptionSepArg, 0 },
389
{ "-cycle-speed", ".cycleSpeed", XrmoptionSepArg, 0 },
394
XSCREENSAVER_MODULE ("Halftone", halftone)