~dbarth/compiz/reworked-fix-744104

« back to all changes in this revision

Viewing changes to unity/unity_window_decorator/src/settings.c

  • Committer: David Barth
  • Date: 2011-04-05 20:20:54 UTC
  • Revision ID: david.barth@canonical.com-20110405202054-fnh0y5t2s228mf4k
re-integrate the unity-window-decorator, for real this time

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "gtk-window-decorator.h"
 
2
 
 
3
/* TODO: Trash all of this and use a window property
 
4
 * instead - much much cleaner!
 
5
 */
 
6
 
 
7
void
 
8
shadow_property_changed (WnckScreen *s)
 
9
{
 
10
    GdkDisplay *display = gdk_display_get_default ();
 
11
    Display    *xdisplay = GDK_DISPLAY_XDISPLAY (display);
 
12
    GdkScreen  *screen = gdk_display_get_default_screen (display);
 
13
    Window     root = GDK_WINDOW_XWINDOW (gdk_screen_get_root_window (screen));
 
14
    Atom actual;
 
15
    int  result, format;
 
16
    unsigned long n, left;
 
17
    unsigned char *prop_data;
 
18
    gboolean      changed = FALSE;
 
19
    XTextProperty shadow_color_xtp;
 
20
 
 
21
    result = XGetWindowProperty (xdisplay, root, compiz_shadow_info_atom,
 
22
                                 0, 32768, 0, XA_INTEGER, &actual,
 
23
                                 &format, &n, &left, &prop_data);
 
24
 
 
25
    if (result != Success)
 
26
        return;
 
27
 
 
28
    if (n == 4)
 
29
    {
 
30
        long *data      = (long *) prop_data;
 
31
        gdouble radius  = data[0];
 
32
        gdouble opacity = data[1];
 
33
        gint x_off      = data[2];
 
34
        gint y_off      = data[3];
 
35
 
 
36
        /* Radius and Opacity are multiplied by 1000 to keep precision,
 
37
         * divide by that much to get our real radius and opacity
 
38
         */
 
39
        radius /= 1000;
 
40
        opacity /= 1000;
 
41
 
 
42
        changed = radius != shadow_radius   ||
 
43
                  opacity != shadow_opacity ||
 
44
                  x_off != shadow_offset_x  ||
 
45
                  y_off != shadow_offset_y;
 
46
 
 
47
        shadow_radius = (gdouble) MAX (0.0, MIN (radius, 48.0));
 
48
        shadow_opacity = (gdouble) MAX (0.0, MIN (opacity, 6.0));
 
49
        shadow_offset_x = (gint) MAX (-16, MIN (x_off, 16));
 
50
        shadow_offset_y = (gint) MAX (-16, MIN (y_off, 16));
 
51
    }
 
52
 
 
53
    XFree (prop_data);
 
54
 
 
55
    result = XGetTextProperty (xdisplay, root, &shadow_color_xtp,
 
56
                               compiz_shadow_color_atom);
 
57
 
 
58
    if (shadow_color_xtp.value)
 
59
    {
 
60
        int  ret_count = 0;
 
61
        char **t_data = NULL;
 
62
 
 
63
        XTextPropertyToStringList (&shadow_color_xtp, &t_data, &ret_count);
 
64
 
 
65
        if (ret_count == 1)
 
66
        {
 
67
            int c[4];
 
68
 
 
69
            if (sscanf (t_data[0], "#%2x%2x%2x%2x",
 
70
                        &c[0], &c[1], &c[2], &c[3]) == 4)
 
71
            {
 
72
                shadow_color[0] = c[0] << 8 | c[0];
 
73
                shadow_color[1] = c[1] << 8 | c[1];
 
74
                shadow_color[2] = c[2] << 8 | c[2];
 
75
                changed = TRUE;
 
76
            }
 
77
        }
 
78
 
 
79
        XFree (shadow_color_xtp.value);
 
80
        if (t_data)
 
81
            XFreeStringList (t_data);
 
82
    }
 
83
 
 
84
    if (changed)
 
85
        decorations_changed (s);
 
86
}
 
87
 
 
88
#ifdef USE_GCONF_UNITY_WINDOW_DECORATOR
 
89
static gboolean
 
90
blur_settings_changed (GConfClient *client)
 
91
{
 
92
    gchar *type;
 
93
    int   new_type = blur_type;
 
94
 
 
95
    if (cmdline_options & CMDLINE_BLUR)
 
96
        return FALSE;
 
97
 
 
98
    type = gconf_client_get_string (client,
 
99
                                    BLUR_TYPE_KEY,
 
100
                                    NULL);
 
101
 
 
102
    if (type)
 
103
    {
 
104
        if (strcmp (type, "titlebar") == 0)
 
105
            new_type = BLUR_TYPE_TITLEBAR;
 
106
        else if (strcmp (type, "all") == 0)
 
107
            new_type = BLUR_TYPE_ALL;
 
108
        else if (strcmp (type, "none") == 0)
 
109
            new_type = BLUR_TYPE_NONE;
 
110
 
 
111
        g_free (type);
 
112
    }
 
113
 
 
114
    if (new_type != blur_type)
 
115
    {
 
116
        blur_type = new_type;
 
117
        return TRUE;
 
118
    }
 
119
 
 
120
    return FALSE;
 
121
}
 
122
 
 
123
static gboolean
 
124
theme_changed (GConfClient *client)
 
125
{
 
126
 
 
127
#ifdef USE_METACITY
 
128
    gboolean use_meta_theme;
 
129
 
 
130
    if (cmdline_options & CMDLINE_THEME)
 
131
        return FALSE;
 
132
 
 
133
    use_meta_theme = gconf_client_get_bool (client,
 
134
                                            USE_META_THEME_KEY,
 
135
                                            NULL);
 
136
 
 
137
    if (use_meta_theme)
 
138
    {
 
139
        gchar *theme;
 
140
 
 
141
        theme = gconf_client_get_string (client,
 
142
                                         META_THEME_KEY,
 
143
                                         NULL);
 
144
 
 
145
        if (theme)
 
146
        {
 
147
            meta_theme_set_current (theme, TRUE);
 
148
            if (!meta_theme_get_current ())
 
149
                use_meta_theme = FALSE;
 
150
 
 
151
            g_free (theme);
 
152
        }
 
153
        else
 
154
        {
 
155
            use_meta_theme = FALSE;
 
156
        }
 
157
    }
 
158
 
 
159
    if (use_meta_theme)
 
160
    {
 
161
        theme_draw_window_decoration    = meta_draw_window_decoration;
 
162
        theme_calc_decoration_size      = meta_calc_decoration_size;
 
163
        theme_update_border_extents     = meta_update_border_extents;
 
164
        theme_get_event_window_position = meta_get_event_window_position;
 
165
        theme_get_button_position       = meta_get_button_position;
 
166
        theme_update_shadow             = meta_update_shadow;
 
167
        theme_get_shadow                = meta_get_shadow;
 
168
    }
 
169
    else
 
170
    {
 
171
        theme_draw_window_decoration    = draw_window_decoration;
 
172
        theme_calc_decoration_size      = calc_decoration_size;
 
173
        theme_update_border_extents     = update_border_extents;
 
174
        theme_get_event_window_position = get_event_window_position;
 
175
        theme_get_button_position       = get_button_position;
 
176
        theme_update_shadow             = cairo_update_shadow;
 
177
        theme_get_shadow                = get_shadow;
 
178
    }
 
179
 
 
180
    return TRUE;
 
181
#else
 
182
    theme_draw_window_decoration    = draw_window_decoration;
 
183
    theme_calc_decoration_size      = calc_decoration_size;
 
184
    theme_update_border_extents     = update_border_extents;
 
185
    theme_get_event_window_position = get_event_window_position;
 
186
    theme_get_button_position       = get_button_position;
 
187
 
 
188
    return FALSE;
 
189
#endif
 
190
 
 
191
}
 
192
 
 
193
static gboolean
 
194
theme_opacity_changed (GConfClient *client)
 
195
{
 
196
 
 
197
#ifdef USE_METACITY
 
198
    gboolean shade_opacity, changed = FALSE;
 
199
    gdouble  opacity;
 
200
 
 
201
    opacity = gconf_client_get_float (client,
 
202
                                      META_THEME_OPACITY_KEY,
 
203
                                      NULL);
 
204
 
 
205
    if (!(cmdline_options & CMDLINE_OPACITY) &&
 
206
        opacity != meta_opacity)
 
207
    {
 
208
        meta_opacity = opacity;
 
209
        changed = TRUE;
 
210
    }
 
211
 
 
212
    if (opacity < 1.0)
 
213
    {
 
214
        shade_opacity = gconf_client_get_bool (client,
 
215
                                               META_THEME_SHADE_OPACITY_KEY,
 
216
                                               NULL);
 
217
 
 
218
        if (!(cmdline_options & CMDLINE_OPACITY_SHADE) &&
 
219
            shade_opacity != meta_shade_opacity)
 
220
        {
 
221
            meta_shade_opacity = shade_opacity;
 
222
            changed = TRUE;
 
223
        }
 
224
    }
 
225
 
 
226
    opacity = gconf_client_get_float (client,
 
227
                                      META_THEME_ACTIVE_OPACITY_KEY,
 
228
                                      NULL);
 
229
 
 
230
    if (!(cmdline_options & CMDLINE_ACTIVE_OPACITY) &&
 
231
        opacity != meta_active_opacity)
 
232
    {
 
233
        meta_active_opacity = opacity;
 
234
        changed = TRUE;
 
235
    }
 
236
 
 
237
    if (opacity < 1.0)
 
238
    {
 
239
        shade_opacity =
 
240
            gconf_client_get_bool (client,
 
241
                                   META_THEME_ACTIVE_SHADE_OPACITY_KEY,
 
242
                                   NULL);
 
243
 
 
244
        if (!(cmdline_options & CMDLINE_ACTIVE_OPACITY_SHADE) &&
 
245
            shade_opacity != meta_active_shade_opacity)
 
246
        {
 
247
            meta_active_shade_opacity = shade_opacity;
 
248
            changed = TRUE;
 
249
        }
 
250
    }
 
251
 
 
252
    return changed;
 
253
#else
 
254
    return FALSE;
 
255
#endif
 
256
 
 
257
}
 
258
 
 
259
static gboolean
 
260
button_layout_changed (GConfClient *client)
 
261
{
 
262
 
 
263
#ifdef USE_METACITY
 
264
    gchar *button_layout;
 
265
 
 
266
    button_layout = gconf_client_get_string (client,
 
267
                                             META_BUTTON_LAYOUT_KEY,
 
268
                                             NULL);
 
269
 
 
270
    if (button_layout)
 
271
    {
 
272
        meta_update_button_layout (button_layout);
 
273
 
 
274
        meta_button_layout_set = TRUE;
 
275
 
 
276
        g_free (button_layout);
 
277
 
 
278
        return TRUE;
 
279
    }
 
280
 
 
281
    if (meta_button_layout_set)
 
282
    {
 
283
        meta_button_layout_set = FALSE;
 
284
        return TRUE;
 
285
    }
 
286
#endif
 
287
 
 
288
    return FALSE;
 
289
}
 
290
 
 
291
static void
 
292
titlebar_font_changed (GConfClient *client)
 
293
{
 
294
    gchar *str;
 
295
 
 
296
    str = gconf_client_get_string (client,
 
297
                                   COMPIZ_TITLEBAR_FONT_KEY,
 
298
                                   NULL);
 
299
    if (!str)
 
300
        str = g_strdup ("Sans Bold 12");
 
301
 
 
302
    if (titlebar_font)
 
303
        pango_font_description_free (titlebar_font);
 
304
 
 
305
    titlebar_font = pango_font_description_from_string (str);
 
306
 
 
307
    g_free (str);
 
308
}
 
309
 
 
310
static void
 
311
titlebar_click_action_changed (GConfClient *client,
 
312
                               const gchar *key,
 
313
                               int         *action_value,
 
314
                               int          default_value)
 
315
{
 
316
    gchar *action;
 
317
 
 
318
    *action_value = default_value;
 
319
 
 
320
    action = gconf_client_get_string (client, key, NULL);
 
321
    if (action)
 
322
    {
 
323
        if (strcmp (action, "toggle_shade") == 0)
 
324
            *action_value = CLICK_ACTION_SHADE;
 
325
        else if (strcmp (action, "toggle_maximize") == 0)
 
326
            *action_value = CLICK_ACTION_MAXIMIZE;
 
327
        else if (strcmp (action, "minimize") == 0)
 
328
            *action_value = CLICK_ACTION_MINIMIZE;
 
329
        else if (strcmp (action, "raise") == 0)
 
330
            *action_value = CLICK_ACTION_RAISE;
 
331
        else if (strcmp (action, "lower") == 0)
 
332
            *action_value = CLICK_ACTION_LOWER;
 
333
        else if (strcmp (action, "menu") == 0)
 
334
            *action_value = CLICK_ACTION_MENU;
 
335
        else if (strcmp (action, "none") == 0)
 
336
            *action_value = CLICK_ACTION_NONE;
 
337
 
 
338
        g_free (action);
 
339
    }
 
340
}
 
341
 
 
342
static void
 
343
wheel_action_changed (GConfClient *client)
 
344
{
 
345
    gchar *action;
 
346
 
 
347
    wheel_action = WHEEL_ACTION_DEFAULT;
 
348
 
 
349
    action = gconf_client_get_string (client, WHEEL_ACTION_KEY, NULL);
 
350
    if (action)
 
351
    {
 
352
        if (strcmp (action, "shade") == 0)
 
353
            wheel_action = WHEEL_ACTION_SHADE;
 
354
        else if (strcmp (action, "none") == 0)
 
355
            wheel_action = WHEEL_ACTION_NONE;
 
356
 
 
357
        g_free (action);
 
358
    }
 
359
}
 
360
 
 
361
static void
 
362
value_changed (GConfClient *client,
 
363
               const gchar *key,
 
364
               GConfValue  *value,
 
365
               void        *data)
 
366
{
 
367
    gboolean changed = FALSE;
 
368
 
 
369
    if (strcmp (key, COMPIZ_USE_SYSTEM_FONT_KEY) == 0)
 
370
    {
 
371
        if (gconf_client_get_bool (client,
 
372
                                   COMPIZ_USE_SYSTEM_FONT_KEY,
 
373
                                   NULL) != use_system_font)
 
374
        {
 
375
            use_system_font = !use_system_font;
 
376
            changed = TRUE;
 
377
        }
 
378
    }
 
379
    else if (strcmp (key, COMPIZ_TITLEBAR_FONT_KEY) == 0)
 
380
    {
 
381
        titlebar_font_changed (client);
 
382
        changed = !use_system_font;
 
383
    }
 
384
    else if (strcmp (key, COMPIZ_DOUBLE_CLICK_TITLEBAR_KEY) == 0)
 
385
    {
 
386
        titlebar_click_action_changed (client, key,
 
387
                                       &double_click_action,
 
388
                                       DOUBLE_CLICK_ACTION_DEFAULT);
 
389
    }
 
390
    else if (strcmp (key, COMPIZ_MIDDLE_CLICK_TITLEBAR_KEY) == 0)
 
391
    {
 
392
        titlebar_click_action_changed (client, key,
 
393
                                       &middle_click_action,
 
394
                                       MIDDLE_CLICK_ACTION_DEFAULT);
 
395
    }
 
396
    else if (strcmp (key, COMPIZ_RIGHT_CLICK_TITLEBAR_KEY) == 0)
 
397
    {
 
398
        titlebar_click_action_changed (client, key,
 
399
                                       &right_click_action,
 
400
                                       RIGHT_CLICK_ACTION_DEFAULT);
 
401
    }
 
402
    else if (strcmp (key, WHEEL_ACTION_KEY) == 0)
 
403
    {
 
404
        wheel_action_changed (client);
 
405
    }
 
406
    else if (strcmp (key, BLUR_TYPE_KEY) == 0)
 
407
    {
 
408
        if (blur_settings_changed (client))
 
409
            changed = TRUE;
 
410
    }
 
411
    else if (strcmp (key, USE_META_THEME_KEY) == 0 ||
 
412
             strcmp (key, META_THEME_KEY) == 0)
 
413
    {
 
414
        if (theme_changed (client))
 
415
            changed = TRUE;
 
416
    }
 
417
    else if (strcmp (key, META_BUTTON_LAYOUT_KEY) == 0)
 
418
    {
 
419
        if (button_layout_changed (client))
 
420
            changed = TRUE;
 
421
    }
 
422
    else if (strcmp (key, META_THEME_OPACITY_KEY)              == 0 ||
 
423
             strcmp (key, META_THEME_SHADE_OPACITY_KEY)        == 0 ||
 
424
             strcmp (key, META_THEME_ACTIVE_OPACITY_KEY)       == 0 ||
 
425
             strcmp (key, META_THEME_ACTIVE_SHADE_OPACITY_KEY) == 0)
 
426
    {
 
427
        if (theme_opacity_changed (client))
 
428
            changed = TRUE;
 
429
    }
 
430
 
 
431
    if (changed)
 
432
        decorations_changed (data);
 
433
}
 
434
#endif
 
435
 
 
436
gboolean
 
437
init_settings (WnckScreen *screen)
 
438
{
 
439
    GtkSettings    *settings;
 
440
    GdkScreen      *gdkscreen;
 
441
    GdkColormap    *colormap;
 
442
    AtkObject      *switcher_label_obj;
 
443
 
 
444
#ifdef USE_GCONF_UNITY_WINDOW_DECORATOR
 
445
    GConfClient    *gconf;
 
446
 
 
447
    gconf = gconf_client_get_default ();
 
448
 
 
449
    gconf_client_add_dir (gconf,
 
450
                          GCONF_DIR,
 
451
                          GCONF_CLIENT_PRELOAD_ONELEVEL,
 
452
                          NULL);
 
453
 
 
454
    gconf_client_add_dir (gconf,
 
455
                          METACITY_GCONF_DIR,
 
456
                          GCONF_CLIENT_PRELOAD_ONELEVEL,
 
457
                          NULL);
 
458
 
 
459
    g_signal_connect (G_OBJECT (gconf),
 
460
                      "value_changed",
 
461
                      G_CALLBACK (value_changed),
 
462
                      screen);
 
463
#endif
 
464
 
 
465
    style_window_rgba = gtk_window_new (GTK_WINDOW_POPUP);
 
466
 
 
467
    gdkscreen = gdk_display_get_default_screen (gdk_display_get_default ());
 
468
    colormap = gdk_screen_get_rgba_colormap (gdkscreen);
 
469
    if (colormap)
 
470
        gtk_widget_set_colormap (style_window_rgba, colormap);
 
471
 
 
472
    gtk_widget_realize (style_window_rgba);
 
473
 
 
474
    switcher_label = gtk_label_new ("");
 
475
    switcher_label_obj = gtk_widget_get_accessible (switcher_label);
 
476
    atk_object_set_role (switcher_label_obj, ATK_ROLE_STATUSBAR);
 
477
    gtk_container_add (GTK_CONTAINER (style_window_rgba), switcher_label);
 
478
 
 
479
    gtk_widget_set_size_request (style_window_rgba, 0, 0);
 
480
    gtk_window_move (GTK_WINDOW (style_window_rgba), -100, -100);
 
481
    gtk_widget_show_all (style_window_rgba);
 
482
 
 
483
    g_signal_connect_object (style_window_rgba, "style-set",
 
484
                             G_CALLBACK (style_changed),
 
485
                             0, 0);
 
486
 
 
487
    settings = gtk_widget_get_settings (style_window_rgba);
 
488
 
 
489
    g_object_get (G_OBJECT (settings), "gtk-double-click-time",
 
490
                  &double_click_timeout, NULL);
 
491
 
 
492
    pango_context = gtk_widget_create_pango_context (style_window_rgba);
 
493
 
 
494
    style_window_rgb = gtk_window_new (GTK_WINDOW_POPUP);
 
495
 
 
496
    gdkscreen = gdk_display_get_default_screen (gdk_display_get_default ());
 
497
    colormap = gdk_screen_get_rgb_colormap (gdkscreen);
 
498
    if (colormap)
 
499
        gtk_widget_set_colormap (style_window_rgb, colormap);
 
500
 
 
501
    gtk_widget_realize (style_window_rgb);
 
502
 
 
503
    switcher_label = gtk_label_new ("");
 
504
    switcher_label_obj = gtk_widget_get_accessible (switcher_label);
 
505
    atk_object_set_role (switcher_label_obj, ATK_ROLE_STATUSBAR);
 
506
    gtk_container_add (GTK_CONTAINER (style_window_rgb), switcher_label);
 
507
 
 
508
    gtk_widget_set_size_request (style_window_rgb, 0, 0);
 
509
    gtk_window_move (GTK_WINDOW (style_window_rgb), -100, -100);
 
510
    gtk_widget_show_all (style_window_rgb);
 
511
 
 
512
    g_signal_connect_object (style_window_rgb, "style-set",
 
513
                             G_CALLBACK (style_changed),
 
514
                             0, 0);
 
515
 
 
516
    settings = gtk_widget_get_settings (style_window_rgb);
 
517
 
 
518
    g_object_get (G_OBJECT (settings), "gtk-double-click-time",
 
519
                  &double_click_timeout, NULL);
 
520
 
 
521
    pango_context = gtk_widget_create_pango_context (style_window_rgb);
 
522
 
 
523
#ifdef USE_GCONF_UNITY_WINDOW_DECORATOR
 
524
    use_system_font = gconf_client_get_bool (gconf,
 
525
                                             COMPIZ_USE_SYSTEM_FONT_KEY,
 
526
                                             NULL);
 
527
    theme_changed (gconf);
 
528
    theme_opacity_changed (gconf);
 
529
    button_layout_changed (gconf);
 
530
#endif
 
531
 
 
532
    update_style (style_window_rgba);
 
533
    update_style (style_window_rgb);
 
534
#ifdef USE_GCONF_UNITY_WINDOW_DECORATOR
 
535
    titlebar_font_changed (gconf);
 
536
#endif
 
537
 
 
538
    update_titlebar_font ();
 
539
 
 
540
#ifdef USE_GCONF_UNITY_WINDOW_DECORATOR
 
541
    titlebar_click_action_changed (gconf,
 
542
                                   COMPIZ_DOUBLE_CLICK_TITLEBAR_KEY,
 
543
                                   &double_click_action,
 
544
                                   DOUBLE_CLICK_ACTION_DEFAULT);
 
545
    titlebar_click_action_changed (gconf,
 
546
                                   COMPIZ_MIDDLE_CLICK_TITLEBAR_KEY,
 
547
                                   &middle_click_action,
 
548
                                   MIDDLE_CLICK_ACTION_DEFAULT);
 
549
    titlebar_click_action_changed (gconf,
 
550
                                   COMPIZ_RIGHT_CLICK_TITLEBAR_KEY,
 
551
                                   &right_click_action,
 
552
                                   RIGHT_CLICK_ACTION_DEFAULT);
 
553
    wheel_action_changed (gconf);
 
554
    blur_settings_changed (gconf);
 
555
#endif
 
556
 
 
557
    (*theme_update_border_extents) (text_height);
 
558
 
 
559
    shadow_property_changed (screen);
 
560
 
 
561
    update_shadow ();
 
562
 
 
563
    return TRUE;
 
564
}