~focus-follows-mouse/ubuntu/precise/compiz/fix-883383

« back to all changes in this revision

Viewing changes to .pc/103_git_fix_gtk_w_d.patch/gtk/window-decorator/gtk-window-decorator.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2011-03-22 21:45:34 UTC
  • mfrom: (0.168.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110322214534-l6i6ds54os5uoqt1
Tags: 1:0.9.4git20110322-0ubuntu1
* New upstream bug fix snapshot:
  - Application windows can sometimes fail to display and will
    mask regions of the screen (LP: #709461)
  - Compiz switcher Alt-Tab order is not predictable - should
    maintain LIFO ordering in application switcher (LP: #175874)
  - after compiz crashed, gnome-panel isn't mapped again (LP: #711378)
  - invisible windows border problem (LP: #710271)
  - Compiz thinks you are clicking in an edge window when you
    are not (LP: #734250)
  - Add test case for invisible window regressions (LP: #736876)
  - often can't alt-click-dnd to move the focussed dialog (LP: #711911)
  - When windows open for the first time they should not hide (LP: #723878)
  - Unity Grid is broken for multi-monitor setups (LP: #709221)
  - Pixmaps trashed during animations when window is unmapped (LP: #733331)
  - Windows have blank decorations when rapidly closing and
    reopening (LP: #733328)
  - Unity is not restored on unity/compiz crash: compiz doesn't register
    properly with gnome-session (LP: #716462)
* remove the patch taken from upstream
* refresh u-w-d patch with latest upstream work
* debian/compiz-core.install:
  - image move to the final destination
* debian/patches/100_bump_core.h.patch:
  - bump for ABI breakage
* debian/compiz-decorator:
  - use gtk-window-decorator and not unity-window-decorator as it's really
    crashy for now (will probably redo an upload tomorrow with a fixed
    decorator)

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 © 2009 Sam Spilsbury <smspillaz@gmail.com>
22
 
 * Frames Management: Copright © 2010 Canonical Ltd.
23
 
 *        Authored By: Sam Spilsbury <sam.spilsbury@canonical.com>
24
 
 */
25
 
 
26
 
#include "gtk-window-decorator.h"
27
 
 
28
 
gboolean minimal = FALSE;
29
 
 
30
 
#define SWITCHER_SPACE 40
31
 
 
32
 
guint cmdline_options = 0;
33
 
 
34
 
GdkPixmap *decor_normal_pixmap = NULL;
35
 
GdkPixmap *decor_active_pixmap = NULL;
36
 
 
37
 
Atom frame_input_window_atom;
38
 
Atom frame_output_window_atom;
39
 
Atom win_decor_atom;
40
 
Atom win_blur_decor_atom;
41
 
Atom wm_move_resize_atom;
42
 
Atom restack_window_atom;
43
 
Atom select_window_atom;
44
 
Atom mwm_hints_atom;
45
 
Atom switcher_fg_atom;
46
 
Atom compiz_shadow_info_atom;
47
 
Atom compiz_shadow_color_atom;
48
 
Atom toolkit_action_atom;
49
 
Atom toolkit_action_window_menu_atom;
50
 
Atom toolkit_action_force_quit_dialog_atom;
51
 
 
52
 
Time dm_sn_timestamp;
53
 
 
54
 
struct _cursor cursor[3][3] = {
55
 
    { C (top_left_corner),    C (top_side),    C (top_right_corner)    },
56
 
    { C (left_side),          C (left_ptr),    C (right_side)          },
57
 
    { C (bottom_left_corner), C (bottom_side), C (bottom_right_corner) }
58
 
};
59
 
 
60
 
struct _pos pos[3][3] = {
61
 
    {
62
 
        {  0,  0, 10, 21,   0, 0, 0, 0, 0, 1 },
63
 
        { 10,  0, -8,  6,   0, 0, 1, 0, 0, 1 },
64
 
        {  2,  0, 10, 21,   1, 0, 0, 0, 0, 1 }
65
 
    }, {
66
 
        {  0, 10,  6, 11,   0, 0, 0, 1, 1, 0 },
67
 
        {  6,  6,  0, 15,   0, 0, 1, 0, 0, 1 },
68
 
        {  6, 10,  6, 11,   1, 0, 0, 1, 1, 0 }
69
 
    }, {
70
 
        {  0, 17, 10, 10,   0, 1, 0, 0, 1, 0 },
71
 
        { 10, 21, -8,  6,   0, 1, 1, 0, 1, 0 },
72
 
        {  2, 17, 10, 10,   1, 1, 0, 0, 1, 0 }
73
 
    }
74
 
}, bpos[] = {
75
 
    { 0, 6, 16, 16,   1, 0, 0, 0, 0, 0 },
76
 
    { 0, 6, 16, 16,   1, 0, 0, 0, 0, 0 },
77
 
    { 0, 6, 16, 16,   1, 0, 0, 0, 0, 0 },
78
 
    { 6, 2, 16, 16,   0, 0, 0, 0, 0, 0 }
79
 
};
80
 
 
81
 
const gchar * window_type_frames[WINDOW_TYPE_FRAMES_NUM] = {
82
 
    "normal", "dialog", "menu", "utility"
83
 
};
84
 
 
85
 
char *program_name;
86
 
 
87
 
GtkWidget     *switcher_label;
88
 
 
89
 
GHashTable    *frame_table;
90
 
GtkWidget     *action_menu = NULL;
91
 
gboolean      action_menu_mapped = FALSE;
92
 
decor_color_t _title_color[2];
93
 
gint         double_click_timeout = 250;
94
 
 
95
 
GtkWidget     *tip_window;
96
 
GtkWidget     *tip_label;
97
 
GTimeVal             tooltip_last_popdown = { 0, 0 };
98
 
gint         tooltip_timer_tag = 0;
99
 
 
100
 
GSList *draw_list = NULL;
101
 
guint  draw_idle_id = 0;
102
 
 
103
 
Window    switcher_selected_window = None;
104
 
decor_t   *switcher_window = NULL;
105
 
 
106
 
XRenderPictFormat *xformat_rgba;
107
 
XRenderPictFormat *xformat_rgb;
108
 
 
109
 
decor_settings_t *settings;
110
 
 
111
 
int
112
 
main (int argc, char *argv[])
113
 
{
114
 
    GdkDisplay    *gdkdisplay;
115
 
    Display       *xdisplay;
116
 
    GdkScreen     *gdkscreen;
117
 
    WnckScreen    *screen;
118
 
    gint          i, j, status;
119
 
    gboolean      replace = FALSE;
120
 
    unsigned int  nchildren;
121
 
    Window        root_ret, parent_ret;
122
 
    Window        *children = NULL;
123
 
    GList         *windows, *win;
124
 
    decor_frame_t *default_p, *bare_p, *switcher_p;
125
 
 
126
 
#ifdef USE_METACITY
127
 
    char       *meta_theme = NULL;
128
 
    MetaTheme  *theme = NULL;
129
 
#endif
130
 
 
131
 
    program_name = argv[0];
132
 
 
133
 
    settings = malloc (sizeof (decor_settings_t));
134
 
 
135
 
    if (!settings)
136
 
        return 1;
137
 
 
138
 
    gtk_init (&argc, &argv);
139
 
 
140
 
    bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
141
 
    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
142
 
    textdomain (GETTEXT_PACKAGE);
143
 
 
144
 
    settings->blur_type = BLUR_TYPE_NONE;
145
 
    settings->use_system_font = FALSE;
146
 
 
147
 
    settings->shadow_radius   = SHADOW_RADIUS;
148
 
    settings->shadow_opacity  = SHADOW_OPACITY;
149
 
    settings->shadow_color[0] = SHADOW_COLOR_RED;
150
 
    settings->shadow_color[1] = SHADOW_COLOR_GREEN;
151
 
    settings->shadow_color[2] = SHADOW_COLOR_BLUE;
152
 
    settings->shadow_offset_x = SHADOW_OFFSET_X;
153
 
    settings->shadow_offset_y = SHADOW_OFFSET_Y;
154
 
    settings->decoration_alpha = 0.5;
155
 
 
156
 
#ifdef USE_METACITY
157
 
 
158
 
    settings->meta_opacity              = META_OPACITY;
159
 
    settings->meta_shade_opacity        = META_SHADE_OPACITY;
160
 
    settings->meta_active_opacity       = META_ACTIVE_OPACITY;
161
 
    settings->meta_active_shade_opacity = META_ACTIVE_SHADE_OPACITY;
162
 
 
163
 
    settings->meta_button_layout_set = FALSE;
164
 
#endif
165
 
 
166
 
    settings->font = strdup ("Sans Bold 12");
167
 
 
168
 
    for (i = 0; i < argc; i++)
169
 
    {
170
 
        if (strcmp (argv[i], "--minimal") == 0)
171
 
        {
172
 
            minimal = TRUE;
173
 
        }
174
 
        else if (strcmp (argv[i], "--replace") == 0)
175
 
        {
176
 
            replace = TRUE;
177
 
        }
178
 
        else if (strcmp (argv[i], "--blur") == 0)
179
 
        {
180
 
            if (argc > ++i)
181
 
            {
182
 
                if (strcmp (argv[i], "titlebar") == 0)
183
 
                    settings->blur_type = BLUR_TYPE_TITLEBAR;
184
 
                else if (strcmp (argv[i], "all") == 0)
185
 
                    settings->blur_type = BLUR_TYPE_ALL;
186
 
            }
187
 
            cmdline_options |= CMDLINE_BLUR;
188
 
        }
189
 
 
190
 
#ifdef USE_METACITY
191
 
        else if (strcmp (argv[i], "--opacity") == 0)
192
 
        {
193
 
            if (argc > ++i)
194
 
                settings->meta_opacity = atof (argv[i]);
195
 
            cmdline_options |= CMDLINE_OPACITY;
196
 
        }
197
 
        else if (strcmp (argv[i], "--no-opacity-shade") == 0)
198
 
        {
199
 
            settings->meta_shade_opacity = FALSE;
200
 
            cmdline_options |= CMDLINE_OPACITY_SHADE;
201
 
        }
202
 
        else if (strcmp (argv[i], "--active-opacity") == 0)
203
 
        {
204
 
            if (argc > ++i)
205
 
                settings->meta_active_opacity = atof (argv[i]);
206
 
            cmdline_options |= CMDLINE_ACTIVE_OPACITY;
207
 
        }
208
 
        else if (strcmp (argv[i], "--no-active-opacity-shade") == 0)
209
 
        {
210
 
            settings->meta_active_shade_opacity = FALSE;
211
 
            cmdline_options |= CMDLINE_ACTIVE_OPACITY_SHADE;
212
 
        }
213
 
        else if (strcmp (argv[i], "--metacity-theme") == 0)
214
 
        {
215
 
            if (argc > ++i)
216
 
                meta_theme = argv[i];
217
 
            cmdline_options |= CMDLINE_THEME;
218
 
        }
219
 
#endif
220
 
 
221
 
        else if (strcmp (argv[i], "--help") == 0)
222
 
        {
223
 
            fprintf (stderr, "%s "
224
 
                     "[--minimal] "
225
 
                     "[--replace] "
226
 
                     "[--blur none|titlebar|all] "
227
 
 
228
 
#ifdef USE_METACITY
229
 
                     "[--opacity OPACITY] "
230
 
                     "[--no-opacity-shade] "
231
 
                     "[--active-opacity OPACITY] "
232
 
                     "[--no-active-opacity-shade] "
233
 
                     "[--metacity-theme THEME] "
234
 
#endif
235
 
 
236
 
                     "[--help]"
237
 
 
238
 
                     "\n", program_name);
239
 
            return 0;
240
 
        }
241
 
    }
242
 
 
243
 
    gdkdisplay = gdk_display_get_default ();
244
 
    xdisplay   = gdk_x11_display_get_xdisplay (gdkdisplay);
245
 
    gdkscreen  = gdk_display_get_default_screen (gdkdisplay);
246
 
 
247
 
    frame_input_window_atom  = XInternAtom (xdisplay,
248
 
                                            DECOR_INPUT_FRAME_ATOM_NAME, FALSE);
249
 
    frame_output_window_atom = XInternAtom (xdisplay,
250
 
                                            DECOR_OUTPUT_FRAME_ATOM_NAME, FALSE);
251
 
 
252
 
    win_decor_atom      = XInternAtom (xdisplay, DECOR_WINDOW_ATOM_NAME, FALSE);
253
 
    win_blur_decor_atom = XInternAtom (xdisplay, DECOR_BLUR_ATOM_NAME, FALSE);
254
 
    wm_move_resize_atom = XInternAtom (xdisplay, "_NET_WM_MOVERESIZE", FALSE);
255
 
    restack_window_atom = XInternAtom (xdisplay, "_NET_RESTACK_WINDOW", FALSE);
256
 
    select_window_atom  = XInternAtom (xdisplay, DECOR_SWITCH_WINDOW_ATOM_NAME,
257
 
                                       FALSE);
258
 
    mwm_hints_atom      = XInternAtom (xdisplay, "_MOTIF_WM_HINTS", FALSE);
259
 
    switcher_fg_atom    = XInternAtom (xdisplay,
260
 
                                       DECOR_SWITCH_FOREGROUND_COLOR_ATOM_NAME,
261
 
                                       FALSE);
262
 
    
263
 
    compiz_shadow_info_atom  = XInternAtom (xdisplay, "_COMPIZ_NET_CM_SHADOW_PROPERTIES", FALSE);
264
 
    compiz_shadow_color_atom = XInternAtom (xdisplay, "_COMPIZ_NET_CM_SHADOW_COLOR", FALSE);
265
 
 
266
 
    toolkit_action_atom                   =
267
 
        XInternAtom (xdisplay, "_COMPIZ_TOOLKIT_ACTION", FALSE);
268
 
    toolkit_action_window_menu_atom       =
269
 
        XInternAtom (xdisplay, "_COMPIZ_TOOLKIT_ACTION_WINDOW_MENU", FALSE);
270
 
    toolkit_action_force_quit_dialog_atom =
271
 
        XInternAtom (xdisplay, "_COMPIZ_TOOLKIT_ACTION_FORCE_QUIT_DIALOG",
272
 
                     FALSE);
273
 
 
274
 
    status = decor_acquire_dm_session (xdisplay,
275
 
                                       gdk_screen_get_number (gdkscreen),
276
 
                                       "gwd", replace, &dm_sn_timestamp);
277
 
    if (status != DECOR_ACQUIRE_STATUS_SUCCESS)
278
 
    {
279
 
        if (status == DECOR_ACQUIRE_STATUS_FAILED)
280
 
        {
281
 
            fprintf (stderr,
282
 
                     "%s: Could not acquire decoration manager "
283
 
                     "selection on screen %d display \"%s\"\n",
284
 
                     program_name, gdk_screen_get_number (gdkscreen),
285
 
                     DisplayString (xdisplay));
286
 
        }
287
 
        else if (status == DECOR_ACQUIRE_STATUS_OTHER_DM_RUNNING)
288
 
        {
289
 
            fprintf (stderr,
290
 
                     "%s: Screen %d on display \"%s\" already "
291
 
                     "has a decoration manager; try using the "
292
 
                     "--replace option to replace the current "
293
 
                     "decoration manager.\n",
294
 
                     program_name, gdk_screen_get_number (gdkscreen),
295
 
                     DisplayString (xdisplay));
296
 
        }
297
 
 
298
 
        return 1;
299
 
    }
300
 
 
301
 
    screen = wnck_screen_get_default ();
302
 
 
303
 
    initialize_decorations ();
304
 
 
305
 
    if (!init_settings (screen))
306
 
    {
307
 
        free (settings);
308
 
        fprintf (stderr, "%s: Failed to get necessary gtk settings\n", argv[0]);
309
 
        return 1;
310
 
    }
311
 
 
312
 
    theme_draw_window_decoration    = draw_window_decoration;
313
 
    theme_calc_decoration_size      = calc_decoration_size;
314
 
    theme_update_border_extents     = update_border_extents;
315
 
    theme_get_event_window_position = get_event_window_position;
316
 
    theme_get_button_position       = get_button_position;
317
 
    theme_get_title_scale           = get_title_scale;
318
 
 
319
 
#ifdef USE_METACITY
320
 
    if (meta_theme)
321
 
    {
322
 
        meta_theme_set_current (meta_theme, TRUE);
323
 
 
324
 
        theme = meta_theme_get_current ();
325
 
 
326
 
        if (!theme)
327
 
            g_warning ("specified a theme that does not exist! falling back to cairo decoration\n");
328
 
    }
329
 
    else
330
 
        theme = meta_theme_get_current ();
331
 
 
332
 
    if (theme)
333
 
    {
334
 
        theme_draw_window_decoration    = meta_draw_window_decoration;
335
 
        theme_calc_decoration_size          = meta_calc_decoration_size;
336
 
        theme_update_border_extents         = meta_update_border_extents;
337
 
        theme_get_event_window_position = meta_get_event_window_position;
338
 
        theme_get_button_position           = meta_get_button_position;
339
 
        theme_get_title_scale       = meta_get_title_scale;
340
 
    }
341
 
#endif
342
 
 
343
 
    for (i = 0; i < 3; i++)
344
 
    {
345
 
        for (j = 0; j < 3; j++)
346
 
        {
347
 
            if (cursor[i][j].shape != XC_left_ptr)
348
 
                cursor[i][j].cursor =
349
 
                    XCreateFontCursor (xdisplay, cursor[i][j].shape);
350
 
        }
351
 
    }
352
 
 
353
 
    xformat_rgba = XRenderFindStandardFormat (xdisplay, PictStandardARGB32);
354
 
    xformat_rgb  = XRenderFindStandardFormat (xdisplay, PictStandardRGB24);
355
 
 
356
 
    frame_table = g_hash_table_new (NULL, NULL);
357
 
 
358
 
    if (!create_tooltip_window ())
359
 
    {
360
 
        free (settings);
361
 
        fprintf (stderr, "%s, Couldn't create tooltip window\n", argv[0]);
362
 
        return 1;
363
 
    }
364
 
 
365
 
    wnck_set_client_type (WNCK_CLIENT_TYPE_PAGER);
366
 
 
367
 
    gdk_window_add_filter (NULL,
368
 
                           selection_event_filter_func,
369
 
                           NULL);
370
 
 
371
 
    if (!minimal)
372
 
    {
373
 
        GdkWindow *root = create_foreign_window (gdk_x11_get_default_root_xwindow ());
374
 
 
375
 
        gdk_window_add_filter (NULL,
376
 
                               event_filter_func,
377
 
                               NULL);
378
 
                               
379
 
        XQueryTree (xdisplay, gdk_x11_get_default_root_xwindow (),
380
 
                    &root_ret, &parent_ret, &children, &nchildren);
381
 
 
382
 
        for (i = 0; i < nchildren; i++)
383
 
        {
384
 
            GdkWindow *toplevel = create_foreign_window  (children[i]);
385
 
 
386
 
            /* Need property notify on all windows */
387
 
 
388
 
            gdk_window_set_events (toplevel,
389
 
                                   gdk_window_get_events (toplevel) |
390
 
                                   GDK_PROPERTY_CHANGE_MASK);
391
 
        }
392
 
 
393
 
        /* Need MapNotify on new windows */
394
 
        gdk_window_set_events (root, gdk_window_get_events (root) |
395
 
                               GDK_STRUCTURE_MASK |
396
 
                               GDK_PROPERTY_CHANGE_MASK |
397
 
                               GDK_VISIBILITY_NOTIFY_MASK |
398
 
                               GDK_SUBSTRUCTURE_MASK);
399
 
 
400
 
        connect_screen (screen);
401
 
    }
402
 
 
403
 
    /* Keep the default, bare and switcher decorations around
404
 
     * since otherwise they will be spuriously recreated */
405
 
 
406
 
    default_p = gwd_get_decor_frame ("default");
407
 
    bare_p = gwd_get_decor_frame ("bare");
408
 
    switcher_p = gwd_get_decor_frame ("switcher");
409
 
 
410
 
    decor_set_dm_check_hint (xdisplay, gdk_screen_get_number (gdkscreen),
411
 
                             WINDOW_DECORATION_TYPE_PIXMAP |
412
 
                             WINDOW_DECORATION_TYPE_WINDOW);
413
 
 
414
 
    update_default_decorations (gdkscreen);
415
 
 
416
 
    gtk_main ();
417
 
 
418
 
    win = windows = wnck_screen_get_windows (screen);
419
 
 
420
 
    while (win != NULL)
421
 
    {
422
 
        WnckWindow *w = (WnckWindow *) win->data;
423
 
 
424
 
        window_closed (screen, w);
425
 
 
426
 
        win = g_list_next (win);
427
 
    }
428
 
 
429
 
    g_list_free (windows);
430
 
 
431
 
    if (tip_label)
432
 
        gtk_widget_destroy (GTK_WIDGET (tip_label));
433
 
 
434
 
    if (tip_window)
435
 
        gtk_widget_destroy (GTK_WIDGET (tip_window));
436
 
 
437
 
    gwd_decor_frame_unref (default_p);
438
 
    gwd_decor_frame_unref (bare_p);
439
 
    gwd_decor_frame_unref (switcher_p);
440
 
 
441
 
    g_free (settings->font);
442
 
 
443
 
    free (settings);
444
 
 
445
 
    return 0;
446
 
}