~townsend/compiz-core/fix-window-monitor-hotplug

« back to all changes in this revision

Viewing changes to .pc/fix_1007754.patch/gtk/window-decorator/wnck.c

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2012-11-12 13:56:29 UTC
  • mfrom: (0.168.20)
  • Revision ID: package-import@ubuntu.com-20121112135629-96rj38mdc28b1piq
Tags: 1:0.9.7.8+bzr3121-0ubuntu1
* New upstream stable branch snapshot.
  - Includes all the previous cherry-picked fixes
  - Fix crash when imgsvg is loaded, due to missing symbol 
    (decor_apply_gravity from libdecoration). (LP: #956986)
  - Fix multiple window placement bugs (LP: #974242) (LP: #976032)
  - Fix window handle leak causing gradual degradation in desktop 
    performance (LP: #1050610)
  - Some decoration pixmaps get leaked on window resize, due to race 
    conditions between gtk-window-decorator and the decor plugin.
    (LP: #1057263)
  - Avoid a NULL dereference and give a useful error message instead.
    (LP: #944653)
  - Fix leakage of destroyed_pixmaps_table, containing pointers to freed 
    decor_t's which could result in a freed GHashTable being passed into 
    g_hash_table_remove and causing a crash. (LP: #1060171)
* debian/patches/compiz-package-gles2.patch:
  - Drop the NEWS file, update decor.cpp part to build with new upstream
    code.
* debian/patches/revert_fix_933776_955035.patch:
  - Cherry-pick the revert from upstream since the bug fix is not 
    suitable for SRU as is
* debian/patches/revert_fix_994841.patch:
  - Cherry-pick also this revert as non-SRU material, not relevant 
    to users
* debian/libdecoration0.symbols:
  - Update with latest symbols

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2006 Novell, Inc.
3
 
 *
4
 
 * This library is free software; you can redistribute it and/or
5
 
 * modify it under the terms of the GNU Lesser General Public
6
 
 * License as published by the Free Software Foundation; either
7
 
 * version 2 of the License, or (at your option) any later version.
8
 
 *
9
 
 * This library is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 
 * Lesser General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU Lesser General Public
15
 
 * License along with this library; if not, write to the
16
 
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
 
 * Boston, MA 02111-1307, USA.
18
 
 *
19
 
 * Author: David Reveman <davidr@novell.com>
20
 
 *
21
 
 * 2D Mode: Copyright © 2010 Sam Spilsbury <smspillaz@gmail.com>
22
 
 * Frames Management: Copright © 2011 Canonical Ltd.
23
 
 *        Authored By: Sam Spilsbury <sam.spilsbury@canonical.com>
24
 
 */
25
 
 
26
 
#include "gtk-window-decorator.h"
27
 
 
28
 
const gchar *
29
 
get_frame_type (WnckWindow *win)
30
 
{
31
 
    WnckWindowType wnck_type = wnck_window_get_window_type (win);
32
 
 
33
 
    switch (wnck_type)
34
 
    {
35
 
        case WNCK_WINDOW_NORMAL:
36
 
            return "normal";
37
 
        case WNCK_WINDOW_DIALOG:
38
 
        {
39
 
            Atom          actual;
40
 
            int           result, format;
41
 
            unsigned long n, left;
42
 
            unsigned char *data;
43
 
 
44
 
            result = XGetWindowProperty (gdk_x11_get_default_xdisplay (), wnck_window_get_xid (win),
45
 
                                         net_wm_state_atom,
46
 
                                         0L, 1024L, FALSE, XA_ATOM, &actual, &format,
47
 
                                         &n, &left, &data);
48
 
 
49
 
            if (result == Success && data)
50
 
            {
51
 
                Atom *a = (Atom *) data;
52
 
 
53
 
                while (n--)
54
 
                    if (*a++ == net_wm_state_modal_atom)
55
 
                    {
56
 
                        XFree ((void *) data);
57
 
                        return "modal_dialog";
58
 
                    }
59
 
 
60
 
 
61
 
            }
62
 
 
63
 
            return "dialog";
64
 
        }
65
 
        case WNCK_WINDOW_MENU:
66
 
            return "menu";
67
 
        case WNCK_WINDOW_UTILITY:
68
 
            return "utility";
69
 
        default:
70
 
            return "bare";
71
 
    }
72
 
 
73
 
    return "normal";
74
 
}
75
 
 
76
 
static void
77
 
window_name_changed (WnckWindow *win)
78
 
{
79
 
    decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
80
 
 
81
 
    if (d->decorated)
82
 
    {
83
 
        if (!request_update_window_decoration_size (win))
84
 
            queue_decor_draw (d);
85
 
    }
86
 
}
87
 
 
88
 
static void
89
 
window_geometry_changed (WnckWindow *win)
90
 
{
91
 
    decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
92
 
 
93
 
    if (d->decorated)
94
 
    {
95
 
        int width, height;
96
 
 
97
 
        wnck_window_get_client_window_geometry (win, NULL, NULL,
98
 
                                                &width, &height);
99
 
 
100
 
        if (width != d->client_width || height != d->client_height)
101
 
        {
102
 
            d->client_width  = width;
103
 
            d->client_height = height;
104
 
 
105
 
            request_update_window_decoration_size (win);
106
 
            update_event_windows (win);
107
 
        }
108
 
    }
109
 
}
110
 
 
111
 
static void
112
 
window_icon_changed (WnckWindow *win)
113
 
{
114
 
    decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
115
 
 
116
 
    if (d->decorated)
117
 
    {
118
 
        update_window_decoration_icon (win);
119
 
        queue_decor_draw (d);
120
 
    }
121
 
}
122
 
 
123
 
static void
124
 
window_state_changed (WnckWindow *win)
125
 
{
126
 
    decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
127
 
 
128
 
    if (d->decorated)
129
 
    {
130
 
        update_window_decoration_state (win);
131
 
        if (!request_update_window_decoration_size (win))
132
 
            queue_decor_draw (d);
133
 
 
134
 
        update_event_windows (win);
135
 
    }
136
 
}
137
 
 
138
 
static void
139
 
window_actions_changed (WnckWindow *win)
140
 
{
141
 
    decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
142
 
 
143
 
    if (d->decorated)
144
 
    {
145
 
        update_window_decoration_actions (win);
146
 
        if (!request_update_window_decoration_size (win))
147
 
            queue_decor_draw (d);
148
 
 
149
 
        update_event_windows (win);
150
 
    }
151
 
}
152
 
 
153
 
void
154
 
update_frames_border_extents (gpointer key,
155
 
                              gpointer value,
156
 
                              gpointer user_data)
157
 
{
158
 
    decor_frame_t *frame = (decor_frame_t *) value;
159
 
 
160
 
    (*theme_update_border_extents) (frame);
161
 
}
162
 
 
163
 
void
164
 
decorations_changed (WnckScreen *screen)
165
 
{
166
 
    GdkDisplay *gdkdisplay;
167
 
    GdkScreen  *gdkscreen;
168
 
    GList      *windows;
169
 
    Window     select;
170
 
 
171
 
    gdkdisplay = gdk_display_get_default ();
172
 
    gdkscreen  = gdk_display_get_default_screen (gdkdisplay);
173
 
 
174
 
    gwd_frames_foreach (set_frames_scales, (gpointer) settings->font);
175
 
 
176
 
    update_titlebar_font ();
177
 
    gwd_process_frames (update_frames_border_extents,
178
 
                        window_type_frames,
179
 
                        WINDOW_TYPE_FRAMES_NUM,
180
 
                        NULL);
181
 
    update_shadow ();
182
 
 
183
 
    update_default_decorations (gdkscreen);
184
 
 
185
 
    if (minimal)
186
 
        return;
187
 
 
188
 
    /* Update all normal windows */
189
 
 
190
 
    windows = wnck_screen_get_windows (screen);
191
 
    while (windows != NULL)
192
 
    {
193
 
        decor_t *d = g_object_get_data (G_OBJECT (windows->data), "decor");
194
 
 
195
 
        if (d->decorated)
196
 
        {
197
 
 
198
 
#ifdef USE_METACITY
199
 
            if (d->draw == draw_window_decoration ||
200
 
                d->draw == meta_draw_window_decoration)
201
 
                d->draw = theme_draw_window_decoration;
202
 
#endif
203
 
 
204
 
        }
205
 
 
206
 
        update_window_decoration (WNCK_WINDOW (windows->data));
207
 
        windows = windows->next;
208
 
    }
209
 
 
210
 
    /* Update switcher window */
211
 
 
212
 
    if (switcher_window &&
213
 
        get_window_prop (switcher_window->prop_xid,
214
 
                         select_window_atom, &select))
215
 
    {
216
 
        decor_t *d = switcher_window;
217
 
        /* force size update */
218
 
        d->context = NULL;
219
 
        d->width = d->height = 0;
220
 
 
221
 
        update_switcher_window (d->prop_xid, select);
222
 
    }
223
 
}
224
 
 
225
 
void
226
 
restack_window (WnckWindow *win,
227
 
                int        stack_mode)
228
 
{
229
 
    Display    *xdisplay;
230
 
    GdkDisplay *gdkdisplay;
231
 
    GdkScreen  *screen;
232
 
    Window     xroot;
233
 
    XEvent     ev;
234
 
 
235
 
    gdkdisplay = gdk_display_get_default ();
236
 
    xdisplay   = GDK_DISPLAY_XDISPLAY (gdkdisplay);
237
 
    screen     = gdk_display_get_default_screen (gdkdisplay);
238
 
    xroot      = RootWindowOfScreen (gdk_x11_screen_get_xscreen (screen));
239
 
 
240
 
    if (action_menu_mapped)
241
 
    {
242
 
        gtk_object_destroy (GTK_OBJECT (action_menu));
243
 
        action_menu_mapped = FALSE;
244
 
        action_menu = NULL;
245
 
        return;
246
 
    }
247
 
 
248
 
    ev.xclient.type    = ClientMessage;
249
 
    ev.xclient.display = xdisplay;
250
 
 
251
 
    ev.xclient.serial     = 0;
252
 
    ev.xclient.send_event = TRUE;
253
 
 
254
 
    ev.xclient.window       = wnck_window_get_xid (win);
255
 
    ev.xclient.message_type = restack_window_atom;
256
 
    ev.xclient.format       = 32;
257
 
 
258
 
    ev.xclient.data.l[0] = 2;
259
 
    ev.xclient.data.l[1] = None;
260
 
    ev.xclient.data.l[2] = stack_mode;
261
 
    ev.xclient.data.l[3] = 0;
262
 
    ev.xclient.data.l[4] = 0;
263
 
 
264
 
    XSendEvent (xdisplay, xroot, FALSE,
265
 
                SubstructureRedirectMask | SubstructureNotifyMask,
266
 
                &ev);
267
 
 
268
 
    XSync (xdisplay, FALSE);
269
 
}
270
 
 
271
 
 
272
 
void
273
 
add_frame_window (WnckWindow *win,
274
 
                  Window     frame,
275
 
                  Bool       mode)
276
 
{
277
 
    Display              *xdisplay;
278
 
    XSetWindowAttributes attr;
279
 
    gulong               xid = wnck_window_get_xid (win);
280
 
    decor_t              *d = g_object_get_data (G_OBJECT (win), "decor");
281
 
    gint                 i, j;
282
 
 
283
 
    xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
284
 
 
285
 
    /* If we have already done this, there is no need to do it again, except
286
 
     * if the property changed.
287
 
     *
288
 
     * The reason this check is here is because sometimes the PropertyNotify X
289
 
     * event can come a bit after the property on the window is actually set
290
 
     * which might result in this function being called twice - once by
291
 
     * wnck through window_opened and once through our X event handler
292
 
     * event_filter_func
293
 
     */
294
 
 
295
 
    if (d->created && mode && d->frame_window)
296
 
        return;
297
 
 
298
 
    d->active = wnck_window_is_active (win);
299
 
    d->win = win;
300
 
    d->frame = gwd_get_decor_frame (get_frame_type (win));
301
 
    d->last_pos_entered = NULL;
302
 
 
303
 
    attr.event_mask = ButtonPressMask | EnterWindowMask |
304
 
                      LeaveWindowMask | ExposureMask;
305
 
    attr.override_redirect = TRUE;
306
 
 
307
 
    gdk_error_trap_push ();
308
 
 
309
 
    if (mode)
310
 
    {
311
 
        GdkColormap *colormap;
312
 
 
313
 
        d->frame_window = create_gdk_window (frame);
314
 
        d->decor_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
315
 
 
316
 
        colormap = get_colormap_for_drawable (GDK_DRAWABLE (d->frame_window));
317
 
 
318
 
        d->decor_image = gtk_image_new ();
319
 
 
320
 
        gtk_widget_set_colormap (d->decor_window, colormap);
321
 
        gtk_widget_set_colormap (d->decor_image, colormap);
322
 
 
323
 
        d->decor_event_box = gtk_event_box_new ();
324
 
        gtk_event_box_set_visible_window (GTK_EVENT_BOX (d->decor_event_box),
325
 
                                          FALSE);
326
 
        gtk_widget_set_events (d->decor_event_box, GDK_BUTTON_PRESS_MASK |
327
 
                                                   GDK_BUTTON_RELEASE_MASK |
328
 
                                                   GDK_POINTER_MOTION_MASK);
329
 
 
330
 
        g_signal_connect (G_OBJECT (d->decor_event_box), "button-press-event",
331
 
                          G_CALLBACK (frame_handle_button_press),
332
 
                          (gpointer) (d));
333
 
 
334
 
        g_signal_connect (G_OBJECT (d->decor_event_box), "button-release-event",
335
 
                          G_CALLBACK (frame_handle_button_release),
336
 
                          (gpointer) (d));
337
 
 
338
 
        g_signal_connect (G_OBJECT (d->decor_event_box), "motion-notify-event",
339
 
                          G_CALLBACK (frame_handle_motion),
340
 
                          (gpointer) (d));
341
 
 
342
 
        gtk_container_add (GTK_CONTAINER (d->decor_event_box), d->decor_image);
343
 
        gtk_event_box_set_above_child (GTK_EVENT_BOX (d->decor_event_box), TRUE);
344
 
        gtk_widget_show_all (d->decor_event_box);
345
 
        gtk_window_set_decorated (GTK_WINDOW (d->decor_window), FALSE);
346
 
        gtk_window_set_default_size (GTK_WINDOW (d->decor_window), 1000, 1000);
347
 
        gtk_container_add (GTK_CONTAINER (d->decor_window), d->decor_event_box);
348
 
 
349
 
        /* Assumed realization happens here */
350
 
 
351
 
        g_signal_connect (G_OBJECT (d->decor_window), "realize",
352
 
                          G_CALLBACK (frame_window_realized), (gpointer) d);
353
 
 
354
 
        gtk_widget_show_all (d->decor_window);
355
 
        gtk_widget_show (d->decor_window);
356
 
 
357
 
        g_object_set_data (G_OBJECT (d->frame_window),
358
 
                           "client_wnck_window", win);
359
 
    }
360
 
    else
361
 
    {
362
 
        d->frame_window = NULL;
363
 
 
364
 
        for (i = 0; i < 3; i++)
365
 
        {
366
 
            for (j = 0; j < 3; j++)
367
 
            {
368
 
                d->event_windows[i][j].window =
369
 
                XCreateWindow (xdisplay,
370
 
                               frame,
371
 
                               0, 0, 1, 1, 0,
372
 
                               CopyFromParent, CopyFromParent, CopyFromParent,
373
 
                               CWOverrideRedirect | CWEventMask, &attr);
374
 
 
375
 
                if (cursor[i][j].cursor)
376
 
                    XDefineCursor (xdisplay, d->event_windows[i][j].window,
377
 
                    cursor[i][j].cursor);
378
 
            }
379
 
        }
380
 
 
381
 
        attr.event_mask |= ButtonReleaseMask;
382
 
 
383
 
        for (i = 0; i < BUTTON_NUM; i++)
384
 
        {
385
 
            d->button_windows[i].window =
386
 
            XCreateWindow (xdisplay,
387
 
                           frame,
388
 
                           0, 0, 1, 1, 0,
389
 
                           CopyFromParent, CopyFromParent, CopyFromParent,
390
 
                           CWOverrideRedirect | CWEventMask, &attr);
391
 
 
392
 
            d->button_states[i] = 0;
393
 
        }
394
 
    }
395
 
 
396
 
    gdk_display_sync (gdk_display_get_default ());
397
 
    if (!gdk_error_trap_pop ())
398
 
    {
399
 
        if (get_mwm_prop (xid) & (MWM_DECOR_ALL | MWM_DECOR_TITLE))
400
 
            d->decorated = TRUE;
401
 
 
402
 
        for (i = 0; i < 3; i++)
403
 
            for (j = 0; j < 3; j++)
404
 
            {
405
 
                Window win = d->event_windows[i][j].window;
406
 
                g_hash_table_insert (frame_table,
407
 
                                     GINT_TO_POINTER (win),
408
 
                                     GINT_TO_POINTER (xid));
409
 
            }
410
 
 
411
 
        for (i = 0; i < BUTTON_NUM; i++)
412
 
            g_hash_table_insert (frame_table,
413
 
                                 GINT_TO_POINTER (d->button_windows[i].window),
414
 
                                 GINT_TO_POINTER (xid));
415
 
 
416
 
        if (d->frame_window)
417
 
        {
418
 
            g_hash_table_insert (frame_table,
419
 
                                 GINT_TO_POINTER (frame),
420
 
                                 GINT_TO_POINTER (xid));
421
 
        }
422
 
        update_window_decoration_state (win);
423
 
        update_window_decoration_actions (win);
424
 
        update_window_decoration_icon (win);
425
 
        request_update_window_decoration_size (win);
426
 
 
427
 
        update_event_windows (win);
428
 
    }
429
 
    else
430
 
    {
431
 
        for (i = 0; i < 3; i++)
432
 
            for (j = 0; j < 3; j++)
433
 
                d->event_windows[i][j].window = None;
434
 
    }
435
 
 
436
 
    d->created = TRUE;
437
 
}
438
 
 
439
 
void
440
 
remove_frame_window (WnckWindow *win)
441
 
{
442
 
    decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
443
 
    Display *xdisplay;
444
 
 
445
 
    xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
446
 
 
447
 
    if (d->pixmap)
448
 
    {
449
 
        g_object_unref (G_OBJECT (d->pixmap));
450
 
        d->pixmap = NULL;
451
 
    }
452
 
 
453
 
    if (d->buffer_pixmap)
454
 
    {
455
 
        g_object_unref (G_OBJECT (d->buffer_pixmap));
456
 
        d->buffer_pixmap = NULL;
457
 
    }
458
 
 
459
 
    if (d->cr)
460
 
    {
461
 
        cairo_destroy (d->cr);
462
 
        d->cr = NULL;
463
 
    }
464
 
 
465
 
    if (d->picture && !d->frame_window)
466
 
    {
467
 
        XRenderFreePicture (xdisplay, d->picture);
468
 
        d->picture = 0;
469
 
    }
470
 
 
471
 
    if (d->name)
472
 
    {
473
 
        g_free (d->name);
474
 
        d->name = NULL;
475
 
    }
476
 
 
477
 
    if (d->layout)
478
 
    {
479
 
        g_object_unref (G_OBJECT (d->layout));
480
 
        d->layout = NULL;
481
 
    }
482
 
 
483
 
    if (d->icon)
484
 
    {
485
 
        cairo_pattern_destroy (d->icon);
486
 
        d->icon = NULL;
487
 
    }
488
 
 
489
 
    if (d->icon_pixmap)
490
 
    {
491
 
        g_object_unref (G_OBJECT (d->icon_pixmap));
492
 
        d->icon_pixmap = NULL;
493
 
    }
494
 
 
495
 
    if (d->icon_pixbuf)
496
 
    {
497
 
        g_object_unref (G_OBJECT (d->icon_pixbuf));
498
 
        d->icon_pixbuf = NULL;
499
 
    }
500
 
 
501
 
    if (d->force_quit_dialog)
502
 
    {
503
 
        GtkWidget *dialog = d->force_quit_dialog;
504
 
 
505
 
        d->force_quit_dialog = NULL;
506
 
        gtk_widget_destroy (dialog);
507
 
    }
508
 
 
509
 
    if (d->frame_window)
510
 
    {
511
 
        gdk_window_destroy (d->frame_window);
512
 
        d->frame_window = NULL;
513
 
    }
514
 
 
515
 
    if (d->decor_image)
516
 
    {
517
 
        g_object_unref (d->decor_image);
518
 
        d->decor_image = NULL;
519
 
    }
520
 
 
521
 
    if (d->decor_event_box)
522
 
    {
523
 
        g_object_unref (d->decor_event_box);
524
 
        d->decor_event_box = NULL;
525
 
    }
526
 
 
527
 
    if (d->decor_window)
528
 
    {
529
 
        g_object_unref (d->decor_window);
530
 
        d->decor_window = NULL;
531
 
    }
532
 
 
533
 
    if (d->frame)
534
 
    {
535
 
        gwd_decor_frame_unref (d->frame);
536
 
        d->frame = NULL;
537
 
    }
538
 
 
539
 
    gdk_error_trap_push ();
540
 
    XDeleteProperty (xdisplay, wnck_window_get_xid (win), win_decor_atom);
541
 
    gdk_display_sync (gdk_display_get_default ());
542
 
    gdk_error_trap_pop ();
543
 
 
544
 
    d->width  = 0;
545
 
    d->height = 0;
546
 
 
547
 
    d->decorated = FALSE;
548
 
 
549
 
    d->state   = 0;
550
 
    d->actions = 0;
551
 
 
552
 
    d->context = NULL;
553
 
    d->shadow  = NULL;
554
 
 
555
 
    draw_list = g_slist_remove (draw_list, d);
556
 
}
557
 
 
558
 
void
559
 
connect_window (WnckWindow *win)
560
 
{
561
 
    g_signal_connect_object (win, "name_changed",
562
 
                             G_CALLBACK (window_name_changed),
563
 
                             0, 0);
564
 
    g_signal_connect_object (win, "geometry_changed",
565
 
                             G_CALLBACK (window_geometry_changed),
566
 
                             0, 0);
567
 
    g_signal_connect_object (win, "icon_changed",
568
 
                             G_CALLBACK (window_icon_changed),
569
 
                             0, 0);
570
 
    g_signal_connect_object (win, "state_changed",
571
 
                             G_CALLBACK (window_state_changed),
572
 
                             0, 0);
573
 
    g_signal_connect_object (win, "actions_changed",
574
 
                             G_CALLBACK (window_actions_changed),
575
 
                             0, 0);
576
 
}
577
 
 
578
 
static void
579
 
active_window_changed (WnckScreen *screen)
580
 
{
581
 
    WnckWindow *win;
582
 
    decor_t    *d;
583
 
 
584
 
    win = wnck_screen_get_previously_active_window (screen);
585
 
    if (win)
586
 
    {
587
 
        d = g_object_get_data (G_OBJECT (win), "decor");
588
 
        if (d)
589
 
        {
590
 
            d->active = wnck_window_is_active (win);
591
 
 
592
 
            decor_frame_t *frame = d->decorated ? d->frame : gwd_get_decor_frame (get_frame_type (win));
593
 
 
594
 
            if ((d->state & META_MAXIMIZED) == META_MAXIMIZED)
595
 
            {
596
 
                if (!d->frame_window)
597
 
                {
598
 
                   if (d->active)
599
 
                   {
600
 
                       d->context = &frame->max_window_context_active;
601
 
                       d->shadow  = frame->max_border_shadow_active;
602
 
                   }
603
 
                   else
604
 
                   {
605
 
                       d->context = &frame->max_window_context_inactive;
606
 
                       d->shadow  = frame->max_border_shadow_inactive;
607
 
                   }
608
 
                }
609
 
                else
610
 
                {
611
 
                   d->shadow  = d->frame->max_border_no_shadow;
612
 
                }
613
 
            }
614
 
            else
615
 
            {
616
 
               if (!d->frame_window)
617
 
               {
618
 
                   if (d->active)
619
 
                   {
620
 
                       d->context = &frame->window_context_active;
621
 
                       d->shadow  = frame->border_shadow_active;
622
 
                   }
623
 
                   else
624
 
                   {
625
 
                       d->context = &frame->window_context_inactive;
626
 
                       d->shadow  = frame->border_shadow_inactive;
627
 
                   }
628
 
               }
629
 
               else
630
 
               {
631
 
                   d->shadow  = d->frame->border_no_shadow;
632
 
               }
633
 
            }
634
 
 
635
 
            if (!d->decorated)
636
 
                gwd_decor_frame_unref (frame);
637
 
 
638
 
            /* We need to update the decoration size here
639
 
            * since the shadow size might have changed and
640
 
            * in that case the decoration will be redrawn,
641
 
            * however if the shadow size doesn't change
642
 
            * then we need to redraw the decoration anyways
643
 
            * since the image would have changed */
644
 
            if (d->win != NULL &&
645
 
                !request_update_window_decoration_size (d->win) &&
646
 
                d->decorated &&
647
 
                d->pixmap)
648
 
                queue_decor_draw (d);
649
 
 
650
 
        }
651
 
    }
652
 
 
653
 
    win = wnck_screen_get_active_window (screen);
654
 
    if (win)
655
 
    {
656
 
        d = g_object_get_data (G_OBJECT (win), "decor");
657
 
        if (d)
658
 
        {
659
 
            d->active = wnck_window_is_active (win);
660
 
 
661
 
            decor_frame_t *frame = d->decorated ? d->frame : gwd_get_decor_frame (get_frame_type (win));
662
 
 
663
 
            if ((d->state & META_MAXIMIZED) == META_MAXIMIZED)
664
 
            {
665
 
                if (!d->frame_window)
666
 
                {
667
 
                   if (d->active)
668
 
                   {
669
 
                       d->context = &frame->max_window_context_active;
670
 
                       d->shadow  = frame->max_border_shadow_active;
671
 
                   }
672
 
                   else
673
 
                   {
674
 
                       d->context = &frame->max_window_context_inactive;
675
 
                       d->shadow  = frame->max_border_shadow_inactive;
676
 
                   }
677
 
                }
678
 
                else
679
 
                {
680
 
                   d->shadow  = frame->max_border_no_shadow;
681
 
                }
682
 
            }
683
 
            else
684
 
            {
685
 
                if (!d->frame_window)
686
 
                {
687
 
                   if (d->active)
688
 
                   {
689
 
                       d->context = &frame->window_context_active;
690
 
                       d->shadow  = frame->border_shadow_active;
691
 
                   }
692
 
                   else
693
 
                   {
694
 
                       d->context = &frame->window_context_inactive;
695
 
                       d->shadow  = frame->border_shadow_inactive;
696
 
                   }
697
 
                }
698
 
                else
699
 
                {
700
 
                   d->shadow =  frame->border_no_shadow;
701
 
                }
702
 
            }
703
 
 
704
 
            if (!d->decorated)
705
 
                gwd_decor_frame_unref (frame);
706
 
 
707
 
            /* We need to update the decoration size here
708
 
            * since the shadow size might have changed and
709
 
            * in that case the decoration will be redrawn,
710
 
            * however if the shadow size doesn't change
711
 
            * then we need to redraw the decoration anyways
712
 
            * since the image would have changed */
713
 
            if (d->win != NULL &&
714
 
                !request_update_window_decoration_size (d->win) &&
715
 
                d->decorated &&
716
 
                d->pixmap)
717
 
                queue_decor_draw (d);
718
 
 
719
 
        }
720
 
    }
721
 
}
722
 
 
723
 
void
724
 
window_opened (WnckScreen *screen,
725
 
               WnckWindow *win)
726
 
{
727
 
    decor_t      *d;
728
 
    Window       window;
729
 
    gulong       xid;
730
 
    unsigned int i, j;
731
 
 
732
 
    static event_callback callback[3][3] = {
733
 
        { top_left_event,    top_event,    top_right_event    },
734
 
        { left_event,        title_event,  right_event        },
735
 
        { bottom_left_event, bottom_event, bottom_right_event }
736
 
    };
737
 
    static event_callback button_callback[BUTTON_NUM] = {
738
 
        close_button_event,
739
 
        max_button_event,
740
 
        min_button_event,
741
 
        menu_button_event,
742
 
        shade_button_event,
743
 
        above_button_event,
744
 
        stick_button_event,
745
 
        unshade_button_event,
746
 
        unabove_button_event,
747
 
        unstick_button_event
748
 
    };
749
 
 
750
 
    d = calloc (1, sizeof (decor_t));
751
 
    if (!d)
752
 
        return;
753
 
 
754
 
    for (i = 0; i < 3; i++)
755
 
        for (j = 0; j < 3; j++)
756
 
            d->event_windows[i][j].callback = callback[i][j];
757
 
 
758
 
    for (i = 0; i < BUTTON_NUM; i++)
759
 
        d->button_windows[i].callback = button_callback[i];
760
 
 
761
 
    wnck_window_get_client_window_geometry (win, NULL, NULL,
762
 
                                            &d->client_width,
763
 
                                            &d->client_height);
764
 
 
765
 
    d->draw = theme_draw_window_decoration;
766
 
 
767
 
    d->created = FALSE;
768
 
    d->pixmap = NULL;
769
 
    d->cr = NULL;
770
 
    d->buffer_pixmap = NULL;
771
 
    d->picture = None;
772
 
 
773
 
    connect_window (win);
774
 
 
775
 
    g_object_set_data (G_OBJECT (win), "decor", d);
776
 
 
777
 
    xid = wnck_window_get_xid (win);
778
 
 
779
 
    if (get_window_prop (xid, frame_input_window_atom, &window))
780
 
    {
781
 
        add_frame_window (win, window, FALSE);
782
 
    }
783
 
    else if (get_window_prop (xid, frame_output_window_atom, &window))
784
 
    {
785
 
        add_frame_window (win, window, TRUE);
786
 
    }
787
 
}
788
 
 
789
 
void
790
 
window_closed (WnckScreen *screen,
791
 
               WnckWindow *win)
792
 
{
793
 
    decor_t *d = g_object_get_data (G_OBJECT (win), "decor");
794
 
 
795
 
    if (d)
796
 
    {
797
 
        remove_frame_window (win);
798
 
        g_object_set_data (G_OBJECT (win), "decor", NULL);
799
 
        g_free (d);
800
 
    }
801
 
}
802
 
 
803
 
void
804
 
connect_screen (WnckScreen *screen)
805
 
{
806
 
    GList *windows;
807
 
 
808
 
    g_signal_connect_object (G_OBJECT (screen), "active_window_changed",
809
 
                             G_CALLBACK (active_window_changed),
810
 
                             0, 0);
811
 
    g_signal_connect_object (G_OBJECT (screen), "window_opened",
812
 
                             G_CALLBACK (window_opened),
813
 
                             0, 0);
814
 
    g_signal_connect_object (G_OBJECT (screen), "window_closed",
815
 
                             G_CALLBACK (window_closed),
816
 
                             0, 0);
817
 
 
818
 
    windows = wnck_screen_get_windows (screen);
819
 
    while (windows != NULL)
820
 
    {
821
 
        window_opened (screen, windows->data);
822
 
        windows = windows->next;
823
 
    }
824
 
}