2
* Copyright © 2006 Novell, Inc.
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.
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.
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.
19
* Author: David Reveman <davidr@novell.com>
22
#include "gtk-window-decorator.h"
24
/* TODO: Trash all of this and use a window property
25
* instead - much much cleaner!
29
shadow_property_changed (WnckScreen *s)
31
GdkDisplay *display = gdk_display_get_default ();
32
Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
33
GdkScreen *screen = gdk_display_get_default_screen (display);
34
Window root = GDK_WINDOW_XWINDOW (gdk_screen_get_root_window (screen));
37
unsigned long n, left;
38
unsigned char *prop_data;
39
gboolean changed = FALSE;
40
XTextProperty shadow_color_xtp;
42
result = XGetWindowProperty (xdisplay, root, compiz_shadow_info_atom,
43
0, 32768, 0, XA_INTEGER, &actual,
44
&format, &n, &left, &prop_data);
46
if (result != Success)
51
long *data = (long *) prop_data;
52
gdouble aradius = data[0];
53
gdouble aopacity = data[1];
54
gint ax_off = data[2];
55
gint ay_off = data[3];
57
gdouble iradius = data[4];
58
gdouble iopacity = data[5];
59
gint ix_off = data[6];
60
gint iy_off = data[7];
61
/* Radius and Opacity are multiplied by 1000 to keep precision,
62
* divide by that much to get our real radius and opacity
69
changed = aradius != settings->active_shadow_radius ||
70
aopacity != settings->active_shadow_opacity ||
71
ax_off != settings->active_shadow_offset_x ||
72
ay_off != settings->active_shadow_offset_y ||
73
iradius != settings->inactive_shadow_radius ||
74
iopacity != settings->inactive_shadow_opacity ||
75
ix_off != settings->inactive_shadow_offset_x ||
76
iy_off != settings->inactive_shadow_offset_y;
78
settings->active_shadow_radius = (gdouble) MAX (0.0, MIN (aradius, 48.0));
79
settings->active_shadow_opacity = (gdouble) MAX (0.0, MIN (aopacity, 6.0));
80
settings->active_shadow_offset_x = (gint) MAX (-16, MIN (ax_off, 16));
81
settings->active_shadow_offset_y = (gint) MAX (-16, MIN (ay_off, 16));
82
settings->inactive_shadow_radius = (gdouble) MAX (0.0, MIN (iradius, 48.0));
83
settings->inactive_shadow_opacity = (gdouble) MAX (0.0, MIN (iopacity, 6.0));
84
settings->inactive_shadow_offset_x = (gint) MAX (-16, MIN (ix_off, 16));
85
settings->inactive_shadow_offset_y = (gint) MAX (-16, MIN (iy_off, 16));
90
result = XGetTextProperty (xdisplay, root, &shadow_color_xtp,
91
compiz_shadow_color_atom);
93
if (shadow_color_xtp.value)
98
XTextPropertyToStringList (&shadow_color_xtp, &t_data, &ret_count);
104
if (sscanf (t_data[0], "#%2x%2x%2x%2x",
105
&c[0], &c[1], &c[2], &c[3]) == 4)
107
settings->active_shadow_color[0] = c[0] << 8 | c[0];
108
settings->active_shadow_color[1] = c[1] << 8 | c[1];
109
settings->active_shadow_color[2] = c[2] << 8 | c[2];
113
if (sscanf (t_data[1], "#%2x%2x%2x%2x",
114
&c[0], &c[1], &c[2], &c[3]) == 4)
116
settings->inactive_shadow_color[0] = c[0] << 8 | c[0];
117
settings->inactive_shadow_color[1] = c[1] << 8 | c[1];
118
settings->inactive_shadow_color[2] = c[2] << 8 | c[2];
123
XFree (shadow_color_xtp.value);
125
XFreeStringList (t_data);
133
use_tooltips_changed (GConfClient *client)
135
gboolean new_use_tooltips;
136
gboolean use_tooltips = settings->use_tooltips;
138
new_use_tooltips = gconf_client_get_bool (client,
142
if (new_use_tooltips != use_tooltips)
144
settings->use_tooltips = new_use_tooltips;
152
mutter_draggable_border_width_changed (GConfClient *client)
155
int width = settings->mutter_draggable_border_width;
157
new_width = gconf_client_get_int (client,
158
MUTTER_DRAGGABLE_BORDER_WIDTH_KEY,
161
if (new_width != width)
163
settings->mutter_draggable_border_width = new_width;
171
mutter_attach_modal_dialogs_changed (GConfClient *client)
174
gboolean attach = settings->mutter_attach_modal_dialogs;
176
new_attach = gconf_client_get_bool (client,
177
MUTTER_ATTACH_MODAL_DIALOGS_KEY,
180
if (new_attach != attach)
182
settings->mutter_attach_modal_dialogs = new_attach;
190
blur_settings_changed (GConfClient *client)
193
int new_type = settings->blur_type;
195
if (cmdline_options & CMDLINE_BLUR)
198
type = gconf_client_get_string (client,
204
if (strcmp (type, "titlebar") == 0)
205
new_type = BLUR_TYPE_TITLEBAR;
206
else if (strcmp (type, "all") == 0)
207
new_type = BLUR_TYPE_ALL;
208
else if (strcmp (type, "none") == 0)
209
new_type = BLUR_TYPE_NONE;
214
if (new_type != settings->blur_type)
216
settings->blur_type = new_type;
224
theme_changed (GConfClient *client)
228
gboolean use_meta_theme;
230
if (cmdline_options & CMDLINE_THEME)
233
use_meta_theme = gconf_client_get_bool (client,
241
theme = gconf_client_get_string (client,
247
meta_theme_set_current (theme, TRUE);
248
if (!meta_theme_get_current ())
249
use_meta_theme = FALSE;
255
use_meta_theme = FALSE;
261
theme_draw_window_decoration = meta_draw_window_decoration;
262
theme_calc_decoration_size = meta_calc_decoration_size;
263
theme_update_border_extents = meta_update_border_extents;
264
theme_get_event_window_position = meta_get_event_window_position;
265
theme_get_button_position = meta_get_button_position;
266
theme_get_title_scale = meta_get_title_scale;
267
theme_get_shadow = meta_get_shadow;
271
theme_draw_window_decoration = draw_window_decoration;
272
theme_calc_decoration_size = calc_decoration_size;
273
theme_update_border_extents = update_border_extents;
274
theme_get_event_window_position = get_event_window_position;
275
theme_get_button_position = get_button_position;
276
theme_get_title_scale = get_title_scale;
277
theme_get_shadow = cairo_get_shadow;
282
theme_draw_window_decoration = draw_window_decoration;
283
theme_calc_decoration_size = calc_decoration_size;
284
theme_update_border_extents = update_border_extents;
285
theme_get_event_window_position = get_event_window_position;
286
theme_get_button_position = get_button_position;
287
theme_get_title_scale = get_title_scale;
288
theme_get_shadow = cairo_get_shadow;
296
theme_opacity_changed (GConfClient *client)
300
gboolean shade_opacity, changed = FALSE;
303
opacity = gconf_client_get_float (client,
304
META_THEME_OPACITY_KEY,
307
if (!(cmdline_options & CMDLINE_OPACITY) &&
308
opacity != settings->meta_opacity)
310
settings->meta_opacity = opacity;
316
shade_opacity = gconf_client_get_bool (client,
317
META_THEME_SHADE_OPACITY_KEY,
320
if (!(cmdline_options & CMDLINE_OPACITY_SHADE) &&
321
shade_opacity != settings->meta_shade_opacity)
323
settings->meta_shade_opacity = shade_opacity;
328
opacity = gconf_client_get_float (client,
329
META_THEME_ACTIVE_OPACITY_KEY,
332
if (!(cmdline_options & CMDLINE_ACTIVE_OPACITY) &&
333
opacity != settings->meta_active_opacity)
335
settings->meta_active_opacity = opacity;
342
gconf_client_get_bool (client,
343
META_THEME_ACTIVE_SHADE_OPACITY_KEY,
346
if (!(cmdline_options & CMDLINE_ACTIVE_OPACITY_SHADE) &&
347
shade_opacity != settings->meta_active_shade_opacity)
349
settings->meta_active_shade_opacity = shade_opacity;
362
button_layout_changed (GConfClient *client)
366
gchar *button_layout;
368
button_layout = gconf_client_get_string (client,
369
META_BUTTON_LAYOUT_KEY,
374
meta_update_button_layout (button_layout);
376
settings->meta_button_layout_set = TRUE;
378
g_free (button_layout);
383
if (settings->meta_button_layout_set)
385
settings->meta_button_layout_set = FALSE;
394
set_frame_scale (decor_frame_t *frame,
399
gwd_decor_frame_ref (frame);
401
if (frame->titlebar_font)
402
pango_font_description_free (frame->titlebar_font);
404
frame->titlebar_font = pango_font_description_from_string (font_str);
406
scale = (*theme_get_title_scale) (frame);
408
pango_font_description_set_size (frame->titlebar_font,
409
MAX (pango_font_description_get_size (frame->titlebar_font) * scale, 1));
411
gwd_decor_frame_unref (frame);
415
set_frames_scales (gpointer key,
419
decor_frame_t *frame = (decor_frame_t *) value;
420
gchar *font_str = (gchar *) user_data;
422
gwd_decor_frame_ref (frame);
424
set_frame_scale (frame, font_str);
426
gwd_decor_frame_unref (frame);
430
titlebar_font_changed (GConfClient *client)
434
str = gconf_client_get_string (client,
435
COMPIZ_TITLEBAR_FONT_KEY,
438
str = g_strdup ("Sans Bold 12");
442
g_free (settings->font);
443
settings->font = g_strdup (str);
446
gwd_frames_foreach (set_frames_scales, (gpointer) settings->font);
453
titlebar_click_action_changed (GConfClient *client,
460
*action_value = default_value;
462
action = gconf_client_get_string (client, key, NULL);
465
if (strcmp (action, "toggle_shade") == 0)
466
*action_value = CLICK_ACTION_SHADE;
467
else if (strcmp (action, "toggle_maximize") == 0)
468
*action_value = CLICK_ACTION_MAXIMIZE;
469
else if (strcmp (action, "minimize") == 0)
470
*action_value = CLICK_ACTION_MINIMIZE;
471
else if (strcmp (action, "raise") == 0)
472
*action_value = CLICK_ACTION_RAISE;
473
else if (strcmp (action, "lower") == 0)
474
*action_value = CLICK_ACTION_LOWER;
475
else if (strcmp (action, "menu") == 0)
476
*action_value = CLICK_ACTION_MENU;
477
else if (strcmp (action, "none") == 0)
478
*action_value = CLICK_ACTION_NONE;
485
wheel_action_changed (GConfClient *client)
489
settings->wheel_action = WHEEL_ACTION_DEFAULT;
491
action = gconf_client_get_string (client, WHEEL_ACTION_KEY, NULL);
494
if (strcmp (action, "shade") == 0)
495
settings->wheel_action = WHEEL_ACTION_SHADE;
496
else if (strcmp (action, "none") == 0)
497
settings->wheel_action = WHEEL_ACTION_NONE;
504
value_changed (GConfClient *client,
509
gboolean changed = FALSE;
511
if (strcmp (key, COMPIZ_USE_SYSTEM_FONT_KEY) == 0)
513
if (gconf_client_get_bool (client,
514
COMPIZ_USE_SYSTEM_FONT_KEY,
515
NULL) != settings->use_system_font)
517
settings->use_system_font = !settings->use_system_font;
521
else if (strcmp (key, COMPIZ_TITLEBAR_FONT_KEY) == 0)
523
titlebar_font_changed (client);
524
changed = !settings->use_system_font;
526
else if (strcmp (key, COMPIZ_DOUBLE_CLICK_TITLEBAR_KEY) == 0)
528
titlebar_click_action_changed (client, key,
529
&settings->double_click_action,
530
DOUBLE_CLICK_ACTION_DEFAULT);
532
else if (strcmp (key, COMPIZ_MIDDLE_CLICK_TITLEBAR_KEY) == 0)
534
titlebar_click_action_changed (client, key,
535
&settings->middle_click_action,
536
MIDDLE_CLICK_ACTION_DEFAULT);
538
else if (strcmp (key, COMPIZ_RIGHT_CLICK_TITLEBAR_KEY) == 0)
540
titlebar_click_action_changed (client, key,
541
&settings->right_click_action,
542
RIGHT_CLICK_ACTION_DEFAULT);
544
else if (strcmp (key, WHEEL_ACTION_KEY) == 0)
546
wheel_action_changed (client);
548
else if (strcmp (key, BLUR_TYPE_KEY) == 0)
550
if (blur_settings_changed (client))
553
else if (strcmp (key, USE_META_THEME_KEY) == 0 ||
554
strcmp (key, META_THEME_KEY) == 0)
556
if (theme_changed (client))
559
else if (strcmp (key, META_BUTTON_LAYOUT_KEY) == 0)
561
if (button_layout_changed (client))
564
else if (strcmp (key, META_THEME_OPACITY_KEY) == 0 ||
565
strcmp (key, META_THEME_SHADE_OPACITY_KEY) == 0 ||
566
strcmp (key, META_THEME_ACTIVE_OPACITY_KEY) == 0 ||
567
strcmp (key, META_THEME_ACTIVE_SHADE_OPACITY_KEY) == 0)
569
if (theme_opacity_changed (client))
572
else if (strcmp (key, MUTTER_DRAGGABLE_BORDER_WIDTH_KEY) == 0)
574
if (mutter_draggable_border_width_changed (client))
577
else if (strcmp (key, MUTTER_ATTACH_MODAL_DIALOGS_KEY) == 0)
579
if (mutter_attach_modal_dialogs_changed (client))
582
else if (strcmp (key, USE_TOOLTIPS_KEY) == 0)
584
if (use_tooltips_changed (client))
589
decorations_changed (data);
594
init_settings (WnckScreen *screen)
599
gconf = gconf_client_get_default ();
601
gconf_client_add_dir (gconf,
603
GCONF_CLIENT_PRELOAD_ONELEVEL,
606
gconf_client_add_dir (gconf,
608
GCONF_CLIENT_PRELOAD_ONELEVEL,
611
gconf_client_add_dir (gconf,
613
GCONF_CLIENT_PRELOAD_ONELEVEL,
616
g_signal_connect (G_OBJECT (gconf),
618
G_CALLBACK (value_changed),
620
settings->use_system_font = gconf_client_get_bool (gconf,
621
COMPIZ_USE_SYSTEM_FONT_KEY,
623
theme_changed (gconf);
624
theme_opacity_changed (gconf);
625
button_layout_changed (gconf);
626
titlebar_font_changed (gconf);
628
titlebar_click_action_changed (gconf,
629
COMPIZ_DOUBLE_CLICK_TITLEBAR_KEY,
630
&settings->double_click_action,
631
DOUBLE_CLICK_ACTION_DEFAULT);
632
titlebar_click_action_changed (gconf,
633
COMPIZ_MIDDLE_CLICK_TITLEBAR_KEY,
634
&settings->middle_click_action,
635
MIDDLE_CLICK_ACTION_DEFAULT);
636
titlebar_click_action_changed (gconf,
637
COMPIZ_RIGHT_CLICK_TITLEBAR_KEY,
638
&settings->right_click_action,
639
RIGHT_CLICK_ACTION_DEFAULT);
640
wheel_action_changed (gconf);
641
blur_settings_changed (gconf);
643
mutter_draggable_border_width_changed (gconf);
644
mutter_attach_modal_dialogs_changed (gconf);
645
use_tooltips_changed (gconf);
647
g_object_unref (gconf);
650
shadow_property_changed (screen);