~ubuntu-branches/ubuntu/hardy/xfce4-session/hardy-proposed

« back to all changes in this revision

Viewing changes to engines/xubuntu/xubuntu.c

  • Committer: Bazaar Package Importer
  • Author(s): Jani Monoses
  • Date: 2006-05-16 10:49:46 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20060516104946-6s50ihaqpeuxpe2r
Tags: 4.3.90.1svn+r21697-0ubuntu1
* Upstream svn snapshot (translation updates and bugfixes, including 
  correct handling of autostart .desktop files - LP #42350, add thunar
  to default session)
* Provide the Xubuntu splash screen in addition to, not instead of
  the Xfce default one. Use new steel color theme for splash
* Copy the nice logout dialog icons from the Human theme
* Bump version and depends to 4.3.90.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: mice.c 16256 2005-07-20 16:15:09Z benny $ */
 
2
/*-
 
3
 * Copyright (c) 2003-2004 Benedikt Meurer <benny@xfce.org>
 
4
 * All rights reserved.
 
5
 *
 
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)
 
9
 * any later version.
 
10
 *                                                                              
 
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.
 
15
 *                                                                              
 
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
 
19
 * 02111-1307, USA.
 
20
 */
 
21
 
 
22
#ifdef HAVE_CONFIG_H
 
23
#include <config.h>
 
24
#endif
 
25
 
 
26
#include <X11/Xlib.h>
 
27
 
 
28
#include <gdk-pixbuf/gdk-pixdata.h>
 
29
#include <gmodule.h>
 
30
 
 
31
#include <libxfsm/xfsm-splash-engine.h>
 
32
 
 
33
#include <engines/xubuntu/preview.h>
 
34
#include <engines/xubuntu/slide.h>
 
35
 
 
36
 
 
37
#define BORDER  2
 
38
#define COLOR   "#EFEFEF"
 
39
#define STEPS   11 
 
40
 
 
41
 
 
42
#define MICE_WINDOW(obj)  ((MiceWindow *)(obj))
 
43
#define MICE(obj)         ((Mice *)(obj))
 
44
 
 
45
 
 
46
typedef struct _MiceWindow MiceWindow;
 
47
typedef struct _Mice       Mice;
 
48
 
 
49
 
 
50
struct _MiceWindow
 
51
{
 
52
  GdkWindow *window;
 
53
  GdkPixmap *pixmap;
 
54
  GdkGC     *gc;
 
55
  int        x;
 
56
  int        y;
 
57
  Mice      *mice;
 
58
};
 
59
 
 
60
 
 
61
struct _Mice
 
62
{
 
63
  gboolean     dialog_active;
 
64
  GList       *windows;
 
65
  MiceWindow  *mainwin;
 
66
  int          base_width;
 
67
  int          base_height;
 
68
  int          step;
 
69
  int          direction;
 
70
  guint        timeout_id;
 
71
};
 
72
 
 
73
 
 
74
static GdkFilterReturn
 
75
mice_filter (GdkXEvent *xevent, GdkEvent *event, gpointer user_data)
 
76
{
 
77
  MiceWindow *mice_window = MICE_WINDOW (user_data);
 
78
  XVisibilityEvent *xvisev = (XVisibilityEvent *) xevent;
 
79
 
 
80
  switch (xvisev->type)
 
81
    {
 
82
    case VisibilityNotify:
 
83
      if (!mice_window->mice->dialog_active)
 
84
        {
 
85
          gdk_window_raise (mice_window->window);
 
86
          return GDK_FILTER_REMOVE;
 
87
        }
 
88
      break;
 
89
    }
 
90
 
 
91
  return GDK_FILTER_CONTINUE;
 
92
}
 
93
 
 
94
 
 
95
static MiceWindow*
 
96
mice_window_new (GdkScreen      *screen,
 
97
                 int             monitor,
 
98
                 GdkPixmap      *pixmap,
 
99
                 GdkGC          *gc,
 
100
                 const GdkColor *color,
 
101
                 GdkCursor      *cursor,
 
102
                 Mice           *mice)
 
103
{
 
104
  GdkRectangle  geometry;
 
105
  GdkWindowAttr attr;
 
106
  MiceWindow   *mice_window;
 
107
 
 
108
  gdk_screen_get_monitor_geometry (screen, monitor, &geometry);
 
109
 
 
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));
 
114
 
 
115
  /* init win attributes */
 
116
  attr.x = geometry.x;
 
117
  attr.y = geometry.y;
 
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;
 
125
 
 
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);
 
129
 
 
130
  gdk_window_set_background (mice_window->window, color);
 
131
 
 
132
  /* center pixmap */
 
133
  mice_window->x = (geometry.width - mice->base_width) / 2;
 
134
  mice_window->y = (geometry.height - mice->base_height) / 2;
 
135
 
 
136
  return mice_window;
 
137
}
 
138
 
 
139
 
 
140
static void
 
141
mice_step (Mice *mice)
 
142
{
 
143
  MiceWindow *mice_window;
 
144
  GList      *lp;
 
145
  int         sx;
 
146
  int         sy;
 
147
  sx = mice->step * mice->base_width;
 
148
  sy = 0;
 
149
 
 
150
  for (lp = mice->windows; lp != NULL; lp = lp->next)
 
151
    {
 
152
      mice_window = MICE_WINDOW (lp->data);
 
153
      gdk_draw_drawable (mice_window->window,
 
154
                         mice_window->gc,
 
155
                         mice_window->pixmap,
 
156
                         sx, sy,
 
157
                         mice_window->x,
 
158
                         mice_window->y,
 
159
                         mice->base_width,
 
160
                         mice->base_height);
 
161
    }
 
162
  mice->step = (mice->step + 1 ) % STEPS;  
 
163
}
 
164
 
 
165
 
 
166
static gboolean
 
167
mice_timeout (gpointer user_data)
 
168
{
 
169
  Mice *mice = MICE (user_data);
 
170
 
 
171
  if (!mice->dialog_active)
 
172
    mice_step (mice);
 
173
 
 
174
  return TRUE;
 
175
}
 
176
 
 
177
 
 
178
static void
 
179
mice_setup (XfsmSplashEngine *engine,
 
180
            XfsmSplashRc     *rc)
 
181
{
 
182
  MiceWindow   *mice_window;
 
183
  GdkGCValues   gc_values;
 
184
  GdkColormap  *cmap;
 
185
  GdkWindow    *root;
 
186
  GdkPixmap    *pixmap;
 
187
  GdkPixbuf    *pixbuf;
 
188
  GdkColor      color;
 
189
  GdkCursor    *cursor;
 
190
  GdkScreen    *screen;
 
191
  GdkGC        *gc;
 
192
  GList        *lp;
 
193
  Mice         *mice = MICE (engine->user_data);
 
194
  int           pw, ph;
 
195
  int           nscreens;
 
196
  int           nmonitors;
 
197
  int           n, m;
 
198
 
 
199
  gdk_color_parse (COLOR, &color);
 
200
  cursor = gdk_cursor_new (GDK_WATCH);
 
201
 
 
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);
 
206
 
 
207
  mice->base_width = pw / STEPS;
 
208
  mice->base_height = ph;
 
209
  mice->step = 0;
 
210
  mice->direction = 1;
 
211
 
 
212
  nscreens = gdk_display_get_n_screens (engine->display);
 
213
  for (n = 0; n < nscreens; ++n)
 
214
    {
 
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);
 
218
 
 
219
      /* allocate color */
 
220
      cmap = gdk_drawable_get_colormap (root);
 
221
      gdk_rgb_find_color (cmap, &color);
 
222
 
 
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);
 
229
 
 
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);
 
235
 
 
236
      for (m = 0; m < nmonitors; ++m)
 
237
        {
 
238
          mice_window = mice_window_new (screen, m, pixmap, gc,
 
239
                                         &color, cursor, mice);
 
240
          mice->windows = g_list_append (mice->windows, mice_window);
 
241
 
 
242
          if (screen == engine->primary_screen && m == engine->primary_monitor)
 
243
            mice->mainwin = mice_window;
 
244
        }
 
245
 
 
246
      /* cleanup for this screen */
 
247
      g_object_unref (pixmap);
 
248
      g_object_unref (gc);
 
249
    }
 
250
 
 
251
  /* show all windows and connect filters */
 
252
  for (lp = mice->windows; lp != NULL; lp = lp->next)
 
253
    {
 
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);
 
257
    }
 
258
 
 
259
  /* start timer */
 
260
  mice->timeout_id = g_timeout_add (100, mice_timeout, mice);
 
261
 
 
262
  /* cleanup */
 
263
  g_object_unref (pixbuf);
 
264
  gdk_cursor_unref (cursor);
 
265
}
 
266
 
 
267
 
 
268
static void
 
269
mice_next (XfsmSplashEngine *engine, const gchar *text)
 
270
{
 
271
  /* nothing to be done here */
 
272
}
 
273
 
 
274
 
 
275
static int
 
276
mice_run (XfsmSplashEngine *engine,
 
277
          GtkWidget        *dialog)
 
278
{
 
279
  Mice *mice = MICE (engine->user_data);
 
280
  MiceWindow *mainwin = mice->mainwin;
 
281
  GtkRequisition requisition;
 
282
  int result;
 
283
  int x, y;
 
284
  int wx, wy;
 
285
  int ww, wh;
 
286
 
 
287
  mice->dialog_active = TRUE;
 
288
 
 
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));
 
298
 
 
299
  mice->dialog_active = FALSE;
 
300
 
 
301
  return result;
 
302
}
 
303
 
 
304
 
 
305
static void
 
306
mice_destroy (XfsmSplashEngine *engine)
 
307
{
 
308
  MiceWindow *mice_window;
 
309
  Mice       *mice = MICE (engine->user_data);
 
310
  GList      *lp;
 
311
 
 
312
  for (lp = mice->windows; lp != NULL; lp = lp->next)
 
313
    {
 
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);
 
320
    }
 
321
 
 
322
  g_source_remove (mice->timeout_id);
 
323
  g_list_free (mice->windows);
 
324
  g_free (mice);
 
325
}
 
326
 
 
327
 
 
328
G_MODULE_EXPORT void
 
329
engine_init (XfsmSplashEngine *engine)
 
330
{
 
331
  Mice *mice;
 
332
 
 
333
  mice = g_new0 (Mice, 1);
 
334
 
 
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;
 
340
}
 
341
 
 
342
 
 
343
 
 
344
static GdkPixbuf*
 
345
config_preview (XfsmSplashConfig *config)
 
346
{
 
347
  return gdk_pixbuf_from_pixdata (&preview, FALSE, NULL);
 
348
}
 
349
 
 
350
 
 
351
G_MODULE_EXPORT void
 
352
config_init (XfsmSplashConfig *config)
 
353
{
 
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/");
 
359
 
 
360
  config->preview     = config_preview;
 
361
}
 
362
 
 
363