1
/* $Id: mice.c 16256 2005-07-20 16:15:09Z 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/xubuntu/preview.h>
34
#include <engines/xubuntu/slide.h>
38
#define COLOR "#EFEFEF"
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;
147
sx = mice->step * mice->base_width;
150
for (lp = mice->windows; lp != NULL; lp = lp->next)
152
mice_window = MICE_WINDOW (lp->data);
153
gdk_draw_drawable (mice_window->window,
162
mice->step = (mice->step + 1 ) % STEPS;
167
mice_timeout (gpointer user_data)
169
Mice *mice = MICE (user_data);
171
if (!mice->dialog_active)
179
mice_setup (XfsmSplashEngine *engine,
182
MiceWindow *mice_window;
183
GdkGCValues gc_values;
193
Mice *mice = MICE (engine->user_data);
199
gdk_color_parse (COLOR, &color);
200
cursor = gdk_cursor_new (GDK_WATCH);
202
/* load slide pixbuf */
203
pixbuf = gdk_pixbuf_from_pixdata (&slide, FALSE, NULL);
204
pw = gdk_pixbuf_get_width (pixbuf);
205
ph = gdk_pixbuf_get_height (pixbuf);
207
mice->base_width = pw / STEPS;
208
mice->base_height = ph;
212
nscreens = gdk_display_get_n_screens (engine->display);
213
for (n = 0; n < nscreens; ++n)
215
screen = gdk_display_get_screen (engine->display, n);
216
nmonitors = gdk_screen_get_n_monitors (screen);
217
root = gdk_screen_get_root_window (screen);
220
cmap = gdk_drawable_get_colormap (root);
221
gdk_rgb_find_color (cmap, &color);
223
/* create graphics context for this screen */
224
gc_values.function = GDK_COPY;
225
gc_values.graphics_exposures = FALSE;
226
gc_values.foreground = color;
227
gc = gdk_gc_new_with_values (root, &gc_values, GDK_GC_FUNCTION
228
| GDK_GC_EXPOSURES | GDK_GC_FOREGROUND);
230
/* create pixmap for this screen */
231
pixmap = gdk_pixmap_new (root, pw, ph, -1);
232
gdk_draw_rectangle (pixmap, gc, TRUE, 0, 0, pw, ph);
233
gdk_draw_pixbuf (pixmap, gc, pixbuf, 0, 0, 0, 0,
234
pw, ph, GDK_RGB_DITHER_NONE, 0, 0);
236
for (m = 0; m < nmonitors; ++m)
238
mice_window = mice_window_new (screen, m, pixmap, gc,
239
&color, cursor, mice);
240
mice->windows = g_list_append (mice->windows, mice_window);
242
if (screen == engine->primary_screen && m == engine->primary_monitor)
243
mice->mainwin = mice_window;
246
/* cleanup for this screen */
247
g_object_unref (pixmap);
251
/* show all windows and connect filters */
252
for (lp = mice->windows; lp != NULL; lp = lp->next)
254
mice_window = MICE_WINDOW (lp->data);
255
gdk_window_show (mice_window->window);
256
gdk_window_add_filter (mice_window->window, mice_filter, mice_window);
260
mice->timeout_id = g_timeout_add (100, mice_timeout, mice);
263
g_object_unref (pixbuf);
264
gdk_cursor_unref (cursor);
269
mice_next (XfsmSplashEngine *engine, const gchar *text)
271
/* nothing to be done here */
276
mice_run (XfsmSplashEngine *engine,
279
Mice *mice = MICE (engine->user_data);
280
MiceWindow *mainwin = mice->mainwin;
281
GtkRequisition requisition;
287
mice->dialog_active = TRUE;
289
gdk_window_get_origin (mainwin->window, &wx, &wy);
290
gdk_drawable_get_size (mainwin->window, &ww, &wh);
291
gtk_window_set_screen (GTK_WINDOW (dialog),
292
gdk_drawable_get_screen (mainwin->window));
293
gtk_widget_size_request (dialog, &requisition);
294
x = wx + (ww - requisition.width) / 2;
295
y = wy + (wh - requisition.height) / 2;
296
gtk_window_move (GTK_WINDOW (dialog), x, y);
297
result = gtk_dialog_run (GTK_DIALOG (dialog));
299
mice->dialog_active = FALSE;
306
mice_destroy (XfsmSplashEngine *engine)
308
MiceWindow *mice_window;
309
Mice *mice = MICE (engine->user_data);
312
for (lp = mice->windows; lp != NULL; lp = lp->next)
314
mice_window = MICE_WINDOW (lp->data);
315
gdk_window_remove_filter (mice_window->window, mice_filter, mice);
316
gdk_window_destroy (mice_window->window);
317
g_object_unref (mice_window->pixmap);
318
g_object_unref (mice_window->gc);
319
g_free (mice_window);
322
g_source_remove (mice->timeout_id);
323
g_list_free (mice->windows);
329
engine_init (XfsmSplashEngine *engine)
333
mice = g_new0 (Mice, 1);
335
engine->user_data = mice;
336
engine->setup = mice_setup;
337
engine->next = mice_next;
338
engine->run = mice_run;
339
engine->destroy = mice_destroy;
345
config_preview (XfsmSplashConfig *config)
347
return gdk_pixbuf_from_pixdata (&preview, FALSE, NULL);
352
config_init (XfsmSplashConfig *config)
354
config->name = g_strdup (_("Xubuntu"));
355
config->description = g_strdup (_("Mice2 Splash Engine"));
356
config->version = g_strdup (VERSION);
357
config->author = g_strdup ("Benedikt Meurer");
358
config->homepage = g_strdup ("http://www.xfce.org/");
360
config->preview = config_preview;