1
/* $Id: mice.c 4711 2004-11-01 16:10:55Z benny $ */
3
* Copyright (c) 2003-2004 Benedikt Meurer <benny@xfce.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2, or (at your option)
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28
#include <gdk-pixbuf/gdk-pixdata.h>
31
#include <libxfsm/xfsm-splash-engine.h>
33
#include <engines/mice/preview.h>
34
#include <engines/mice/slide.h>
38
#define COLOR "#DAE7FE"
42
#define MICE_WINDOW(obj) ((MiceWindow *)(obj))
43
#define MICE(obj) ((Mice *)(obj))
46
typedef struct _MiceWindow MiceWindow;
47
typedef struct _Mice Mice;
63
gboolean dialog_active;
74
static GdkFilterReturn
75
mice_filter (GdkXEvent *xevent, GdkEvent *event, gpointer user_data)
77
MiceWindow *mice_window = MICE_WINDOW (user_data);
78
XVisibilityEvent *xvisev = (XVisibilityEvent *) xevent;
82
case VisibilityNotify:
83
if (!mice_window->mice->dialog_active)
85
gdk_window_raise (mice_window->window);
86
return GDK_FILTER_REMOVE;
91
return GDK_FILTER_CONTINUE;
96
mice_window_new (GdkScreen *screen,
100
const GdkColor *color,
104
GdkRectangle geometry;
106
MiceWindow *mice_window;
108
gdk_screen_get_monitor_geometry (screen, monitor, &geometry);
110
mice_window = g_new0 (MiceWindow, 1);
111
mice_window->mice = mice;
112
mice_window->pixmap = GDK_PIXMAP (g_object_ref (pixmap));
113
mice_window->gc = GDK_GC (g_object_ref (gc));
115
/* init win attributes */
118
attr.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
119
attr.width = geometry.width;
120
attr.height = geometry.height;
121
attr.wclass = GDK_INPUT_OUTPUT;
122
attr.window_type = GDK_WINDOW_TEMP;
123
attr.cursor = cursor;
124
attr.override_redirect = TRUE;
126
mice_window->window = gdk_window_new (gdk_screen_get_root_window (screen),
127
&attr, GDK_WA_X | GDK_WA_Y
128
| GDK_WA_NOREDIR | GDK_WA_CURSOR);
130
gdk_window_set_background (mice_window->window, color);
133
mice_window->x = (geometry.width - mice->base_width) / 2;
134
mice_window->y = (geometry.height - mice->base_height) / 2;
141
mice_step (Mice *mice)
143
MiceWindow *mice_window;
148
sx = mice->step * mice->base_width;
151
for (lp = mice->windows; lp != NULL; lp = lp->next)
153
mice_window = MICE_WINDOW (lp->data);
154
gdk_draw_drawable (mice_window->window,
164
if (mice->step == 0 && mice->direction < 0)
169
else if (mice->step == STEPS - 1 && mice->direction > 0)
172
mice->direction = -1;
176
mice->step += mice->direction;
182
mice_timeout (gpointer user_data)
184
Mice *mice = MICE (user_data);
186
if (!mice->dialog_active)
194
mice_setup (XfsmSplashEngine *engine,
197
MiceWindow *mice_window;
198
GdkGCValues gc_values;
208
Mice *mice = MICE (engine->user_data);
214
gdk_color_parse (COLOR, &color);
215
cursor = gdk_cursor_new (GDK_WATCH);
217
/* load slide pixbuf */
218
pixbuf = gdk_pixbuf_from_pixdata (&slide, FALSE, NULL);
219
pw = gdk_pixbuf_get_width (pixbuf);
220
ph = gdk_pixbuf_get_height (pixbuf);
222
mice->base_width = pw / STEPS;
223
mice->base_height = ph;
227
nscreens = gdk_display_get_n_screens (engine->display);
228
for (n = 0; n < nscreens; ++n)
230
screen = gdk_display_get_screen (engine->display, n);
231
nmonitors = gdk_screen_get_n_monitors (screen);
232
root = gdk_screen_get_root_window (screen);
235
cmap = gdk_drawable_get_colormap (root);
236
gdk_rgb_find_color (cmap, &color);
238
/* create graphics context for this screen */
239
gc_values.function = GDK_COPY;
240
gc_values.graphics_exposures = FALSE;
241
gc_values.foreground = color;
242
gc = gdk_gc_new_with_values (root, &gc_values, GDK_GC_FUNCTION
243
| GDK_GC_EXPOSURES | GDK_GC_FOREGROUND);
245
/* create pixmap for this screen */
246
pixmap = gdk_pixmap_new (root, pw, ph, -1);
247
gdk_draw_rectangle (pixmap, gc, TRUE, 0, 0, pw, ph);
248
gdk_draw_pixbuf (pixmap, gc, pixbuf, 0, 0, 0, 0,
249
pw, ph, GDK_RGB_DITHER_NONE, 0, 0);
251
for (m = 0; m < nmonitors; ++m)
253
mice_window = mice_window_new (screen, m, pixmap, gc,
254
&color, cursor, mice);
255
mice->windows = g_list_append (mice->windows, mice_window);
257
if (screen == engine->primary_screen && m == engine->primary_monitor)
258
mice->mainwin = mice_window;
261
/* cleanup for this screen */
262
g_object_unref (pixmap);
266
/* show all windows and connect filters */
267
for (lp = mice->windows; lp != NULL; lp = lp->next)
269
mice_window = MICE_WINDOW (lp->data);
270
gdk_window_show (mice_window->window);
271
gdk_window_add_filter (mice_window->window, mice_filter, mice_window);
275
mice->timeout_id = g_timeout_add (100, mice_timeout, mice);
278
g_object_unref (pixbuf);
279
gdk_cursor_unref (cursor);
284
mice_next (XfsmSplashEngine *engine, const gchar *text)
286
/* nothing to be done here */
291
mice_run (XfsmSplashEngine *engine,
294
Mice *mice = MICE (engine->user_data);
295
MiceWindow *mainwin = mice->mainwin;
296
GtkRequisition requisition;
302
mice->dialog_active = TRUE;
304
gdk_window_get_origin (mainwin->window, &wx, &wy);
305
gdk_drawable_get_size (mainwin->window, &ww, &wh);
306
gtk_window_set_screen (GTK_WINDOW (dialog),
307
gdk_drawable_get_screen (mainwin->window));
308
gtk_widget_size_request (dialog, &requisition);
309
x = wx + (ww - requisition.width) / 2;
310
y = wy + (wh - requisition.height) / 2;
311
gtk_window_move (GTK_WINDOW (dialog), x, y);
312
result = gtk_dialog_run (GTK_DIALOG (dialog));
314
mice->dialog_active = FALSE;
321
mice_destroy (XfsmSplashEngine *engine)
323
MiceWindow *mice_window;
324
Mice *mice = MICE (engine->user_data);
327
for (lp = mice->windows; lp != NULL; lp = lp->next)
329
mice_window = MICE_WINDOW (lp->data);
330
gdk_window_remove_filter (mice_window->window, mice_filter, mice);
331
gdk_window_destroy (mice_window->window);
332
g_object_unref (mice_window->pixmap);
333
g_object_unref (mice_window->gc);
334
g_free (mice_window);
337
g_source_remove (mice->timeout_id);
338
g_list_free (mice->windows);
344
engine_init (XfsmSplashEngine *engine)
348
mice = g_new0 (Mice, 1);
350
engine->user_data = mice;
351
engine->setup = mice_setup;
352
engine->next = mice_next;
353
engine->run = mice_run;
354
engine->destroy = mice_destroy;
360
config_preview (XfsmSplashConfig *config)
362
return gdk_pixbuf_from_pixdata (&preview, FALSE, NULL);
367
config_init (XfsmSplashConfig *config)
369
config->name = g_strdup ("Mice");
370
config->description = g_strdup ("Mice Splash Engine");
371
config->version = g_strdup (VERSION);
372
config->author = g_strdup ("Benedikt Meurer");
373
config->homepage = g_strdup ("http://www.xfce.org/");
375
config->preview = config_preview;