prefs.c 77.5 KB
Newer Older
1 2
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */

3 4 5
/* Metacity preferences */

/* 
6
 * Copyright (C) 2001 Havoc Pennington, Copyright (C) 2002 Red Hat Inc.
7
 * Copyright (C) 2006 Elijah Newren
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */

#include <config.h>
#include "prefs.h"
27
#include "ui.h"
28
#include "util.h"
29
#ifdef HAVE_GCONF
30
#include <gconf/gconf-client.h>
31
#endif
32
#include <string.h>
33
#include <stdlib.h>
34

35
#define MAX_REASONABLE_WORKSPACES 36
36 37 38 39 40

#define MAX_COMMANDS (32 + NUM_EXTRA_COMMANDS)
#define NUM_EXTRA_COMMANDS 2
#define SCREENSHOT_COMMAND_IDX (MAX_COMMANDS - 2)
#define WIN_SCREENSHOT_COMMAND_IDX (MAX_COMMANDS - 1)
41

42 43 44
/* If you add a key, it needs updating in init() and in the gconf
 * notify listener and of course in the .schemas file
 */
45
#define KEY_MOUSE_BUTTON_MODS "/apps/metacity/general/mouse_button_modifier"
46
#define KEY_FOCUS_MODE "/apps/metacity/general/focus_mode"
47
#define KEY_FOCUS_NEW_WINDOWS "/apps/metacity/general/focus_new_windows"
48
#define KEY_RAISE_ON_CLICK "/apps/metacity/general/raise_on_click"
49
#define KEY_ACTION_DOUBLE_CLICK_TITLEBAR "/apps/metacity/general/action_double_click_titlebar"
Havoc Pennington's avatar
Havoc Pennington committed
50 51
#define KEY_AUTO_RAISE "/apps/metacity/general/auto_raise"
#define KEY_AUTO_RAISE_DELAY "/apps/metacity/general/auto_raise_delay"
52
#define KEY_THEME "/apps/metacity/general/theme"
53
#define KEY_USE_SYSTEM_FONT  "/apps/metacity/general/titlebar_uses_system_font"
54
#define KEY_TITLEBAR_FONT "/apps/metacity/general/titlebar_font"
55
#define KEY_NUM_WORKSPACES "/apps/metacity/general/num_workspaces"
56
#define KEY_APPLICATION_BASED "/apps/metacity/general/application_based"
57
#define KEY_DISABLE_WORKAROUNDS "/apps/metacity/general/disable_workarounds"
Havoc Pennington's avatar
Havoc Pennington committed
58
#define KEY_BUTTON_LAYOUT "/apps/metacity/general/button_layout"
59
#define KEY_REDUCED_RESOURCES "/apps/metacity/general/reduced_resources"
60
#define KEY_GNOME_ACCESSIBILITY "/desktop/gnome/interface/accessibility"
61

62
#define KEY_COMMAND_PREFIX "/apps/metacity/keybinding_commands/command_"
63 64 65

#define KEY_TERMINAL_COMMAND "/desktop/gnome/applications/terminal/exec"

66 67
#define KEY_SCREEN_BINDINGS_PREFIX "/apps/metacity/global_keybindings"
#define KEY_WINDOW_BINDINGS_PREFIX "/apps/metacity/window_keybindings"
68
#define KEY_LIST_BINDINGS_SUFFIX "_list"
69

70 71
#define KEY_WORKSPACE_NAME_PREFIX "/apps/metacity/workspace_names/name_"

72 73 74
#define KEY_VISUAL_BELL "/apps/metacity/general/visual_bell"
#define KEY_AUDIBLE_BELL "/apps/metacity/general/audible_bell"
#define KEY_VISUAL_BELL_TYPE "/apps/metacity/general/visual_bell_type"
75 76
#define KEY_CURSOR_THEME "/desktop/gnome/peripherals/mouse/cursor_theme"
#define KEY_CURSOR_SIZE "/desktop/gnome/peripherals/mouse/cursor_size"
Søren Sandmann's avatar
Søren Sandmann committed
77
#define KEY_COMPOSITING_MANAGER "/apps/metacity/general/compositing_manager"
78

79
#ifdef HAVE_GCONF
80
static GConfClient *default_client = NULL;
81 82
static GList *changes = NULL;
static guint changed_idle;
83 84 85
#endif
static GList *listeners = NULL;

86
static gboolean use_system_font = FALSE;
87
static PangoFontDescription *titlebar_font = NULL;
88
static MetaVirtualModifier mouse_button_mods = Mod1Mask;
89
static MetaFocusMode focus_mode = META_FOCUS_MODE_CLICK;
90
static MetaFocusNewWindows focus_new_windows = META_FOCUS_NEW_WINDOWS_SMART;
91
static gboolean raise_on_click = TRUE;
92
static char* current_theme = NULL;
93
static int num_workspaces = 4;
94
static MetaActionDoubleClickTitlebar action_double_click_titlebar =
95
    META_ACTION_DOUBLE_CLICK_TITLEBAR_TOGGLE_MAXIMIZE;
96
static gboolean application_based = FALSE;
97
static gboolean disable_workarounds = FALSE;
Havoc Pennington's avatar
Havoc Pennington committed
98 99
static gboolean auto_raise = FALSE;
static gboolean auto_raise_delay = 500;
100
static gboolean provide_visual_bell = FALSE;
101
static gboolean bell_is_audible = TRUE;
102
static gboolean reduced_resources = FALSE;
103
static gboolean gnome_accessibility = FALSE;
104 105
static char *cursor_theme = NULL;
static int   cursor_size = 24;
Søren Sandmann's avatar
Søren Sandmann committed
106
static gboolean compositing_manager = FALSE;
107

108
static MetaVisualBellType visual_bell_type = META_VISUAL_BELL_FULLSCREEN_FLASH;
Havoc Pennington's avatar
Havoc Pennington committed
109 110 111 112 113 114 115 116 117 118 119 120 121 122
static MetaButtonLayout button_layout = {
  {
    META_BUTTON_FUNCTION_MENU,
    META_BUTTON_FUNCTION_LAST,
    META_BUTTON_FUNCTION_LAST,
    META_BUTTON_FUNCTION_LAST
  },
  {
    META_BUTTON_FUNCTION_MINIMIZE,
    META_BUTTON_FUNCTION_MAXIMIZE,
    META_BUTTON_FUNCTION_CLOSE,
    META_BUTTON_FUNCTION_LAST
  }
};
123

124
/* The screenshot commands are at the end */
125 126
static char *commands[MAX_COMMANDS] = { NULL, };

127 128
static char *terminal_command = NULL;

129 130
static char *workspace_names[MAX_REASONABLE_WORKSPACES] = { NULL, };

131
#ifdef HAVE_GCONF
132
static gboolean update_use_system_font    (gboolean    value);
133
static gboolean update_titlebar_font      (const char *value);
134
static gboolean update_mouse_button_mods  (const char *value);
135
static gboolean update_focus_mode         (const char *value);
136
static gboolean update_focus_new_windows  (const char *value);
137
static gboolean update_raise_on_click     (gboolean    value);
138
static gboolean update_theme              (const char *value);
139 140
static gboolean update_visual_bell        (gboolean v1, gboolean v2);
static gboolean update_visual_bell_type   (const char *value);
141
static gboolean update_num_workspaces     (int         value);
142
static gboolean update_application_based  (gboolean    value);
143
static gboolean update_disable_workarounds (gboolean   value);
144
static gboolean update_action_double_click_titlebar (const char *value);
Havoc Pennington's avatar
Havoc Pennington committed
145 146
static gboolean update_auto_raise          (gboolean   value);
static gboolean update_auto_raise_delay    (int        value);
Havoc Pennington's avatar
Havoc Pennington committed
147
static gboolean update_button_layout      (const char *value);
148 149 150 151
static gboolean update_window_binding     (const char *name,
                                           const char *value);
static gboolean update_screen_binding     (const char *name,
                                           const char *value);
152 153 154 155 156 157 158
static gboolean find_and_update_list_binding (MetaKeyPref *bindings,
                                              const char  *name,
                                              GSList      *value);
static gboolean update_window_list_binding (const char *name,
                                            GSList      *value);
static gboolean update_screen_list_binding (const char *name,
                                            GSList      *value);
159 160
static gboolean update_command            (const char  *name,
                                           const char  *value);
161
static gboolean update_terminal_command   (const char *value);
162 163
static gboolean update_workspace_name     (const char  *name,
                                           const char  *value);
164
static gboolean update_reduced_resources  (gboolean     value);
165
static gboolean update_gnome_accessibility  (gboolean     value);
166 167
static gboolean update_cursor_theme       (const char *value);
static gboolean update_cursor_size        (int size);
Søren Sandmann's avatar
Søren Sandmann committed
168
static gboolean update_compositing_manager (gboolean	value);
169 170 171 172 173 174

static void change_notify (GConfClient    *client,
                           guint           cnxn_id,
                           GConfEntry     *entry,
                           gpointer        user_data);

175
static char* gconf_key_for_workspace_name (int i);
176

177 178
static void queue_changed (MetaPreference  pref);
#endif /* HAVE_GCONF */
179 180
static gboolean update_binding            (MetaKeyPref *binding,
                                           const char  *value);
181

182 183 184 185 186 187 188 189 190 191
typedef enum
  {
    META_LIST_OF_STRINGS,
    META_LIST_OF_GCONFVALUE_STRINGS
  } MetaStringListType;

static gboolean update_list_binding       (MetaKeyPref *binding,
                                           GSList      *value,
                                           MetaStringListType type_of_value);

192 193 194 195 196
static void     init_bindings             (void);
static void     init_commands             (void);
static void     init_workspace_names      (void);

       
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
typedef struct
{
  MetaPrefsChangedFunc func;
  gpointer data;
} MetaPrefsListener;

void
meta_prefs_add_listener (MetaPrefsChangedFunc func,
                         gpointer             data)
{
  MetaPrefsListener *l;

  l = g_new (MetaPrefsListener, 1);
  l->func = func;
  l->data = data;

  listeners = g_list_prepend (listeners, l);
}

void
meta_prefs_remove_listener (MetaPrefsChangedFunc func,
                            gpointer             data)
{
  GList *tmp;

  tmp = listeners;
  while (tmp != NULL)
    {
      MetaPrefsListener *l = tmp->data;

      if (l->func == func &&
          l->data == data)
        {
          g_free (l);
          listeners = g_list_delete_link (listeners, tmp);

          return;
        }
      
      tmp = tmp->next;
    }

  meta_bug ("Did not find listener to remove\n");
}

242
#ifdef HAVE_GCONF
243 244 245 246 247 248
static void
emit_changed (MetaPreference pref)
{
  GList *tmp;
  GList *copy;

249 250
  meta_topic (META_DEBUG_PREFS, "Notifying listeners that pref %s changed\n",
              meta_preference_to_string (pref));
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
  
  copy = g_list_copy (listeners);
  
  tmp = copy;
  while (tmp != NULL)
    {
      MetaPrefsListener *l = tmp->data;

      (* l->func) (pref, l->data);
      
      tmp = tmp->next;
    }

  g_list_free (copy);
}
266
#endif /* HAVE_GCONF */
267

268
#ifdef HAVE_GCONF
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
static gboolean
changed_idle_handler (gpointer data)
{
  GList *tmp;
  GList *copy;

  changed_idle = 0;
  
  copy = g_list_copy (changes); /* reentrancy paranoia */

  g_list_free (changes);
  changes = NULL;
  
  tmp = copy;
  while (tmp != NULL)
    {
      MetaPreference pref = GPOINTER_TO_INT (tmp->data);

      emit_changed (pref);
      
      tmp = tmp->next;
    }

  g_list_free (copy);
  
  return FALSE;
}
296
#endif /* HAVE_GCONF */
297

298
#ifdef HAVE_GCONF
299 300 301
static void
queue_changed (MetaPreference pref)
{
302 303
  meta_topic (META_DEBUG_PREFS, "Queueing change of pref %s\n",
              meta_preference_to_string (pref));  
304 305 306 307
  
  if (g_list_find (changes, GINT_TO_POINTER (pref)) == NULL)
    changes = g_list_prepend (changes, GINT_TO_POINTER (pref));
  else
308 309
    meta_topic (META_DEBUG_PREFS, "Change of pref %s was already pending\n",
                meta_preference_to_string (pref));
310 311

  /* add idle at priority below the gconf notify idle */
312
  if (changed_idle == 0)
313
    changed_idle = g_idle_add_full (META_PRIORITY_PREFS_NOTIFY,
314
                                    changed_idle_handler, NULL, NULL);
315
}
316
#endif /* HAVE_GCONF */
317

318
#ifdef HAVE_GCONF
319 320 321 322 323
static void
cleanup_error (GError **error)
{
  if (*error)
    {
324
      meta_warning ("%s\n", (*error)->message);
325 326 327 328 329
      
      g_error_free (*error);
      *error = NULL;
    }
}
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352

/* get_bool returns TRUE if *val is filled in, FALSE otherwise */
static gboolean
get_bool (const char *key, gboolean *val)
{
  GError     *err = NULL;
  GConfValue *value;
  gboolean    filled_in = FALSE;

  value = gconf_client_get (default_client, key, &err);
  cleanup_error (&err);
  if (value)
    {
      if (value->type == GCONF_VALUE_BOOL)
        {
          *val = gconf_value_get_bool (value);
          filled_in = TRUE;
        }
      gconf_value_free (value);
    }

  return filled_in;
}
353
#endif /* HAVE_GCONF */
354 355 356 357

void
meta_prefs_init (void)
{
358
#ifdef HAVE_GCONF
359 360 361
  GError *err = NULL;
  char *str_val;
  int int_val;
362
  gboolean bool_val, bool_val_2;
363 364
  gboolean update_visual;
  gboolean update_audible;
365
  
366
  if (default_client != NULL)
367 368 369
    return;
  
  /* returns a reference which we hold forever */
370
  default_client = gconf_client_get_default ();
371

372
  gconf_client_add_dir (default_client, "/apps/metacity",
373 374 375 376
                        GCONF_CLIENT_PRELOAD_RECURSIVE,
                        &err);
  cleanup_error (&err);

377 378 379 380 381
  gconf_client_add_dir (default_client, "/desktop/gnome/applications/terminal",
                        GCONF_CLIENT_PRELOAD_RECURSIVE,
                        &err);
  cleanup_error (&err);

382 383 384 385 386
  gconf_client_add_dir (default_client, KEY_GNOME_ACCESSIBILITY,
                        GCONF_CLIENT_PRELOAD_RECURSIVE,
                        &err);
  cleanup_error (&err);

387 388 389 390 391
  gconf_client_add_dir (default_client, "/desktop/gnome/peripherals/mouse",
                        GCONF_CLIENT_PRELOAD_RECURSIVE,
                        &err);
  cleanup_error (&err);

392 393 394 395 396 397
  str_val = gconf_client_get_string (default_client, KEY_MOUSE_BUTTON_MODS,
                                     &err);
  cleanup_error (&err);
  update_mouse_button_mods (str_val);
  g_free (str_val);
  
398
  str_val = gconf_client_get_string (default_client, KEY_FOCUS_MODE,
399 400 401 402 403
                                     &err);
  cleanup_error (&err);
  update_focus_mode (str_val);
  g_free (str_val);  

404 405 406 407 408 409
  str_val = gconf_client_get_string (default_client, KEY_FOCUS_NEW_WINDOWS,
                                     &err);
  cleanup_error (&err);
  update_focus_new_windows (str_val);
  g_free (str_val);  

410 411
  if (get_bool (KEY_RAISE_ON_CLICK, &bool_val))
    update_raise_on_click (bool_val);
412
  
413 414 415 416 417 418 419
  str_val = gconf_client_get_string (default_client,
                                     KEY_ACTION_DOUBLE_CLICK_TITLEBAR,
				     &err);
  cleanup_error (&err);
  update_action_double_click_titlebar (str_val);
  g_free (str_val);

420 421
  if (get_bool (KEY_AUTO_RAISE, &bool_val))
    update_auto_raise (bool_val);
Havoc Pennington's avatar
Havoc Pennington committed
422

423 424 425 426 427 428
  /* FIXME: Since auto_raise_delay of 0 is valid and gconf_client_get_int
   * silently returns that value when KEY_AUTO_RAISE_DELAY doesn't exist,
   * we should be using gconf_client_get() instead if we cared about
   * careful error checking of the key-doesn't-exist case.  Since this
   * setting is crap, though, I'm adding a FIXME instead of fixing it.  ;-)
   */
Havoc Pennington's avatar
Havoc Pennington committed
429 430 431 432 433 434
  int_val = gconf_client_get_int (default_client, KEY_AUTO_RAISE_DELAY,
				  &err);
  cleanup_error (&err);
  update_auto_raise_delay (int_val);
  

435
  str_val = gconf_client_get_string (default_client, KEY_THEME,
436 437 438 439 440
                                     &err);
  cleanup_error (&err);
  update_theme (str_val);
  g_free (str_val);
  
441 442 443 444 445
  /* If the keys aren't set in the database, we use essentially
   * bogus values instead of any kind of default. This is
   * just lazy. But they keys ought to be set, anyhow.
   */
  
446 447
  if (get_bool (KEY_USE_SYSTEM_FONT, &bool_val))
    update_use_system_font (bool_val);
448
  
449
  str_val = gconf_client_get_string (default_client, KEY_TITLEBAR_FONT,
450 451 452 453 454
                                     &err);
  cleanup_error (&err);
  update_titlebar_font (str_val);
  g_free (str_val);

455
  int_val = gconf_client_get_int (default_client, KEY_NUM_WORKSPACES,
456 457 458
                                  &err);
  cleanup_error (&err);
  update_num_workspaces (int_val);
459

460 461
  if (get_bool (KEY_APPLICATION_BASED, &bool_val))
    update_application_based (bool_val);
462

463 464
  if (get_bool (KEY_DISABLE_WORKAROUNDS, &bool_val))
    update_disable_workarounds (bool_val);
Havoc Pennington's avatar
Havoc Pennington committed
465 466 467 468 469 470

  str_val = gconf_client_get_string (default_client, KEY_BUTTON_LAYOUT,
                                     &err);
  cleanup_error (&err);
  update_button_layout (str_val);
  g_free (str_val);
471

472 473
  bool_val = provide_visual_bell;
  bool_val_2 = bell_is_audible;
474 475
  update_visual = get_bool (KEY_VISUAL_BELL,  &bool_val);
  update_audible = get_bool (KEY_AUDIBLE_BELL, &bool_val_2);
476 477
  if (update_visual || update_audible)
    update_visual_bell (bool_val, bool_val_2);
Søren Sandmann's avatar
Søren Sandmann committed
478 479 480 481 482

  bool_val = compositing_manager;
  if (get_bool (KEY_COMPOSITING_MANAGER, &bool_val))
    update_compositing_manager (bool_val);
  
483 484 485 486 487 488
  str_val = gconf_client_get_string (default_client, KEY_VISUAL_BELL_TYPE,
                                     &err);
  cleanup_error (&err);
  update_visual_bell_type (str_val);
  g_free (str_val);

489 490
  if (get_bool (KEY_REDUCED_RESOURCES, &bool_val))
    update_reduced_resources (bool_val);
491 492 493 494 495 496

  str_val = gconf_client_get_string (default_client, KEY_TERMINAL_COMMAND,
                                     &err);
  cleanup_error (&err);
  update_terminal_command (str_val);
  g_free (str_val);
497

498 499
  if (get_bool (KEY_GNOME_ACCESSIBILITY, &bool_val))
    update_gnome_accessibility (bool_val);
500 501 502 503 504 505 506 507 508 509 510

  str_val = gconf_client_get_string (default_client, KEY_CURSOR_THEME,
                                     &err);
  cleanup_error (&err);
  update_cursor_theme (str_val);
  g_free (str_val);

  int_val = gconf_client_get_int (default_client, KEY_CURSOR_SIZE,
                                  &err);
  cleanup_error (&err);
  update_cursor_size (int_val);
511 512 513 514 515 516 517 518
#else  /* HAVE_GCONF */
  /* Set defaults for some values that can't be set at initialization time of
   * the static globals.  In the case of the theme, note that there is code
   * elsewhere that will do everything possible to fallback to an existing theme
   * if the one here does not exist.
   */
  titlebar_font = pango_font_description_from_string ("Sans Bold 10");
  current_theme = g_strdup ("Atlanta");
519 520
#endif /* HAVE_GCONF */
  
521 522
  /* Load keybindings prefs */
  init_bindings ();
523 524 525

  /* commands */
  init_commands ();
526 527 528

  /* workspace names */
  init_workspace_names ();
529 530

#ifdef HAVE_GCONF
531
  gconf_client_notify_add (default_client, "/apps/metacity",
532 533 534 535
                           change_notify,
                           NULL,
                           NULL,
                           &err);
536 537 538 539 540
  gconf_client_notify_add (default_client, KEY_TERMINAL_COMMAND,
                           change_notify,
                           NULL,
                           NULL,
                           &err);
541 542 543 544 545
  gconf_client_notify_add (default_client, KEY_GNOME_ACCESSIBILITY,
                           change_notify,
                           NULL,
                           NULL,
                           &err);
546 547 548 549 550
  gconf_client_notify_add (default_client, "/desktop/gnome/peripherals/mouse",
                           change_notify,
                           NULL,
                           NULL,
                           &err);
551

552
  cleanup_error (&err);  
553
#endif /* HAVE_GCONF */
554 555
}

556
#ifdef HAVE_GCONF
557

558 559 560 561 562 563 564 565 566 567 568
static void
change_notify (GConfClient    *client,
               guint           cnxn_id,
               GConfEntry     *entry,
               gpointer        user_data)
{
  const char *key;
  GConfValue *value;
  
  key = gconf_entry_get_key (entry);
  value = gconf_entry_get_value (entry);
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585

  if (strcmp (key, KEY_MOUSE_BUTTON_MODS) == 0)
    {
      const char *str;

      if (value && value->type != GCONF_VALUE_STRING)
        {
          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                        KEY_MOUSE_BUTTON_MODS);
          goto out;
        }
      
      str = value ? gconf_value_get_string (value) : NULL;

      if (update_mouse_button_mods (str))
        queue_changed (META_PREF_MOUSE_BUTTON_MODS);
    }
Havoc Pennington's avatar
Havoc Pennington committed
586
  else if (strcmp (key, KEY_FOCUS_MODE) == 0)
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601
    {
      const char *str;

      if (value && value->type != GCONF_VALUE_STRING)
        {
          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                        KEY_FOCUS_MODE);
          goto out;
        }
      
      str = value ? gconf_value_get_string (value) : NULL;

      if (update_focus_mode (str))
        queue_changed (META_PREF_FOCUS_MODE);
    }
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617
  else if (strcmp (key, KEY_FOCUS_NEW_WINDOWS) == 0)
    {
      const char *str;

      if (value && value->type != GCONF_VALUE_STRING)
        {
          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                        KEY_FOCUS_NEW_WINDOWS);
          goto out;
        }
      
      str = value ? gconf_value_get_string (value) : NULL;

      if (update_focus_new_windows (str))
        queue_changed (META_PREF_FOCUS_NEW_WINDOWS);
    }
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633
  else if (strcmp (key, KEY_RAISE_ON_CLICK) == 0)
    {
      gboolean b;

      if (value && value->type != GCONF_VALUE_BOOL)
        {
          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                        KEY_RAISE_ON_CLICK);
          goto out;
        }

      b = value ? gconf_value_get_bool (value) : TRUE;
      
      if (update_raise_on_click (b))
        queue_changed (META_PREF_RAISE_ON_CLICK);
    }
Havoc Pennington's avatar
Havoc Pennington committed
634
  else if (strcmp (key, KEY_THEME) == 0)
635 636 637 638 639 640 641 642 643 644 645 646
    {
      const char *str;

      if (value && value->type != GCONF_VALUE_STRING)
        {
          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                        KEY_THEME);
          goto out;
        }
      
      str = value ? gconf_value_get_string (value) : NULL;

647
      if (update_theme (str))
648 649
        queue_changed (META_PREF_THEME);
    }
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
  else if (strcmp (key, KEY_TITLEBAR_FONT) == 0)
    {
      const char *str;

      if (value && value->type != GCONF_VALUE_STRING)
        {
          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                        KEY_TITLEBAR_FONT);
          goto out;
        }
      
      str = value ? gconf_value_get_string (value) : NULL;

      if (update_titlebar_font (str))
        queue_changed (META_PREF_TITLEBAR_FONT);
    }
666
  else if (strcmp (key, KEY_USE_SYSTEM_FONT) == 0)
667 668 669 670 671 672
    {
      gboolean b;

      if (value && value->type != GCONF_VALUE_BOOL)
        {
          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
673
                        KEY_USE_SYSTEM_FONT);
674 675 676 677 678 679 680 681 682
          goto out;
        }

      b = value ? gconf_value_get_bool (value) : TRUE;
      
      /* There's no external pref for this, it just affects whether
       * get_titlebar_font returns NULL, so that's what we queue
       * the change on
       */
683
      if (update_use_system_font (b))
684 685
        queue_changed (META_PREF_TITLEBAR_FONT);
    }
686 687 688 689 690 691 692 693 694 695 696
  else if (strcmp (key, KEY_NUM_WORKSPACES) == 0)
    {
      int d;

      if (value && value->type != GCONF_VALUE_INT)
        {
          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                        KEY_NUM_WORKSPACES);
          goto out;
        }

697
      d = value ? gconf_value_get_int (value) : num_workspaces;
698 699 700 701

      if (update_num_workspaces (d))
        queue_changed (META_PREF_NUM_WORKSPACES);
    }
702 703 704
  else if (strcmp (key, KEY_APPLICATION_BASED) == 0)
    {
      gboolean b;
705

706 707 708 709 710 711 712 713 714 715 716 717
      if (value && value->type != GCONF_VALUE_BOOL)
        {
          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                        KEY_APPLICATION_BASED);
          goto out;
        }

      b = value ? gconf_value_get_bool (value) : application_based;

      if (update_application_based (b))
        queue_changed (META_PREF_APPLICATION_BASED);
    }
718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733
  else if (strcmp (key, KEY_DISABLE_WORKAROUNDS) == 0)
    {
      gboolean b;

      if (value && value->type != GCONF_VALUE_BOOL)
        {
          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                        KEY_APPLICATION_BASED);
          goto out;
        }

      b = value ? gconf_value_get_bool (value) : disable_workarounds;

      if (update_disable_workarounds (b))
        queue_changed (META_PREF_DISABLE_WORKAROUNDS);
    }
734
  else if (g_str_has_prefix (key, KEY_WINDOW_BINDINGS_PREFIX))
735
    {
736
      if (g_str_has_suffix (key, KEY_LIST_BINDINGS_SUFFIX))
737
        {
738 739 740 741 742 743 744 745 746 747 748 749 750
          GSList *list;

          if (value && value->type != GCONF_VALUE_LIST)
            {
              meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                            key);
              goto out;
            }

          list = value ? gconf_value_get_list (value) : NULL;

          if (update_window_list_binding (key, list))
             queue_changed (META_PREF_WINDOW_KEYBINDINGS);
751
        }
752 753 754
      else
        {
          const char *str;
755

756 757 758 759 760 761
          if (value && value->type != GCONF_VALUE_STRING)
            {
              meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                            key);
              goto out;
            }
762

763 764 765 766 767
          str = value ? gconf_value_get_string (value) : NULL;

          if (update_window_binding (key, str))
             queue_changed (META_PREF_WINDOW_KEYBINDINGS);
        }
768
    }
769
  else if (g_str_has_prefix (key, KEY_SCREEN_BINDINGS_PREFIX))
770
    {
771 772 773
      if (g_str_has_suffix (key, KEY_LIST_BINDINGS_SUFFIX))
        {
          GSList *list;
774

775 776 777 778 779 780 781 782 783 784 785 786 787
          if (value && value->type != GCONF_VALUE_LIST)
            {
              meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                            key);
              goto out;
            }

          list = value ? gconf_value_get_list (value) : NULL;

          if (update_screen_list_binding (key, list))
             queue_changed (META_PREF_SCREEN_KEYBINDINGS);
         }
      else
788
        {
789
          const char *str;
790

791 792 793 794 795 796 797 798
          if (value && value->type != GCONF_VALUE_STRING)
            {
               meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                            key);
               goto out;
            }

          str = value ? gconf_value_get_string (value) : NULL;
799

800 801 802
          if (update_screen_binding (key, str))
             queue_changed (META_PREF_SCREEN_KEYBINDINGS);
        }
803
    }
804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819
  else if (strcmp (key, KEY_ACTION_DOUBLE_CLICK_TITLEBAR) == 0)
    {
      const char *str;

      if (value && value->type != GCONF_VALUE_STRING)
        {
          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                        key);
          goto out;
        }

      str = value ? gconf_value_get_string (value) : NULL;

      if (update_action_double_click_titlebar (str))
        queue_changed (META_PREF_ACTION_DOUBLE_CLICK_TITLEBAR);
    }
Havoc Pennington's avatar
Havoc Pennington committed
820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850
  else if (strcmp (key, KEY_AUTO_RAISE) == 0)
    {
      gboolean b;

      if (value && value->type != GCONF_VALUE_BOOL)
        {
          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                        KEY_AUTO_RAISE);
          goto out;
        }

      b = value ? gconf_value_get_bool (value) : auto_raise;

      if (update_auto_raise (b))
        queue_changed (META_PREF_AUTO_RAISE);
    }
  else if (strcmp (key, KEY_AUTO_RAISE_DELAY) == 0)
    {
      int d;

      if (value && value->type != GCONF_VALUE_INT)
        {
          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                        KEY_AUTO_RAISE_DELAY);
          goto out;
        }        
      
      d = value ? gconf_value_get_int (value) : 0;

      if (update_auto_raise_delay (d))
        queue_changed (META_PREF_AUTO_RAISE_DELAY);
851 852
    
    }
853
  else if (g_str_has_prefix (key, KEY_COMMAND_PREFIX))
854 855 856 857 858 859 860 861 862 863 864 865 866 867
    {
      const char *str;

      if (value && value->type != GCONF_VALUE_STRING)
        {
          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                        key);
          goto out;
        }

      str = value ? gconf_value_get_string (value) : NULL;

      if (update_command (key, str))
        queue_changed (META_PREF_COMMANDS);
Havoc Pennington's avatar
Havoc Pennington committed
868
    }
869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884
  else if (strcmp (key, KEY_TERMINAL_COMMAND) == 0)
    {
      const char *str;

      if (value && value->type != GCONF_VALUE_STRING)
        {
          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                        KEY_TERMINAL_COMMAND);
          goto out;
        }
      
      str = value ? gconf_value_get_string (value) : NULL;

      if (update_terminal_command (str))
        queue_changed (META_PREF_TERMINAL_COMMAND);
    }
885
  else if (g_str_has_prefix (key, KEY_WORKSPACE_NAME_PREFIX))
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900
    {
      const char *str;

      if (value && value->type != GCONF_VALUE_STRING)
        {
          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                        key);
          goto out;
        }

      str = value ? gconf_value_get_string (value) : NULL;

      if (update_workspace_name (key, str))
        queue_changed (META_PREF_WORKSPACE_NAMES);
    }
Havoc Pennington's avatar
Havoc Pennington committed
901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916
  else if (strcmp (key, KEY_BUTTON_LAYOUT) == 0)
    {
      const char *str;
      
      if (value && value->type != GCONF_VALUE_STRING)
        {
          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                        KEY_BUTTON_LAYOUT);
          goto out;
        }
      
      str = value ? gconf_value_get_string (value) : NULL;

      if (update_button_layout (str))
        queue_changed (META_PREF_BUTTON_LAYOUT);
    }
917 918 919 920
  else if (strcmp (key, KEY_VISUAL_BELL) == 0)
    {
      gboolean b;

921 922 923 924 925 926 927
      if (value && value->type != GCONF_VALUE_BOOL)
        {
          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                        key);
          goto out;
        }

928 929 930 931 932 933 934 935
      b = value ? gconf_value_get_bool (value) : provide_visual_bell;      
      if (update_visual_bell (b, bell_is_audible))
	queue_changed (META_PREF_VISUAL_BELL);	    
    }
  else if (strcmp (key, KEY_AUDIBLE_BELL) == 0)
    {
      gboolean b;

936 937 938 939 940 941 942
      if (value && value->type != GCONF_VALUE_BOOL)
        {
          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                        key);
          goto out;
        }

943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961
      b = value ? gconf_value_get_bool (value) : bell_is_audible;      
      if (update_visual_bell (provide_visual_bell, b))
	queue_changed (META_PREF_AUDIBLE_BELL);
    }
  else if (strcmp (key, KEY_VISUAL_BELL_TYPE) == 0)
    {
      const char * str;

      if (value && value->type != GCONF_VALUE_STRING)
        {
          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                        KEY_VISUAL_BELL_TYPE);
          goto out;
        }
      
      str = value ? gconf_value_get_string (value) : NULL;
      if (update_visual_bell_type (str))
	queue_changed (META_PREF_VISUAL_BELL_TYPE);
    }
962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977
  else if (strcmp (key, KEY_REDUCED_RESOURCES) == 0)
    {
      gboolean b;

      if (value && value->type != GCONF_VALUE_BOOL)
        {
          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                        KEY_REDUCED_RESOURCES);
          goto out;
        }

      b = value ? gconf_value_get_bool (value) : reduced_resources;

      if (update_reduced_resources (b))
        queue_changed (META_PREF_REDUCED_RESOURCES);
    }
978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993
  else if (strcmp (key, KEY_GNOME_ACCESSIBILITY) == 0)
    {
      gboolean b;

      if (value && value->type != GCONF_VALUE_BOOL)
        {
          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                       KEY_GNOME_ACCESSIBILITY);
          goto out;
        }

      b = value ? gconf_value_get_bool (value) : gnome_accessibility;

      if (update_gnome_accessibility (b))
        queue_changed (META_PREF_GNOME_ACCESSIBILITY);
    }
994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025
  else if (strcmp (key, KEY_CURSOR_THEME) == 0)
    {
      const char *str;

      if (value && value->type != GCONF_VALUE_STRING)
        {
          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                       KEY_CURSOR_THEME);
          goto out;
        }

      str = value ? gconf_value_get_string (value) : NULL;

      if (update_cursor_theme (str))
	queue_changed (META_PREF_CURSOR_THEME);
    }
  else if (strcmp (key, KEY_CURSOR_SIZE) == 0)
    {
      int d;

      if (value && value->type != GCONF_VALUE_INT)
        {
          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                       KEY_CURSOR_SIZE);
          goto out;
        }

      d = value ? gconf_value_get_int (value) : 24;

      if (update_cursor_size (d))
	queue_changed (META_PREF_CURSOR_SIZE);
    }
Søren Sandmann's avatar
Søren Sandmann committed
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
  else if (strcmp (key, KEY_COMPOSITING_MANAGER) == 0)
    {
      gboolean b;

      if (value && value->type != GCONF_VALUE_BOOL)
        {
          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
                       KEY_COMPOSITING_MANAGER);
          goto out;
        }

      b = value ? gconf_value_get_bool (value) : compositing_manager;

      if (update_compositing_manager (b))
        queue_changed (META_PREF_COMPOSITING_MANAGER);
    }
1042 1043
  else
    {
1044 1045
      meta_topic (META_DEBUG_PREFS, "Key %s doesn't mean anything to Metacity\n",
                  key);
1046 1047
    }
  
1048 1049
 out:
  /* nothing */
1050
  return; /* AIX compiler wants something after a label like out: */
1051
}
1052
#endif /* HAVE_GCONF */
1053

1054
#ifdef HAVE_GCONF
1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083
static gboolean
update_mouse_button_mods (const char *value)
{
  MetaVirtualModifier old_mods = mouse_button_mods;
  
  if (value != NULL)
    {
      MetaVirtualModifier mods;
  
      meta_topic (META_DEBUG_KEYBINDINGS,
                  "Mouse button modifier has new gconf value \"%s\"\n",
                  value ? value : "none");
  
      if (meta_ui_parse_modifier (value, &mods))
        {
          mouse_button_mods = mods;
        }
      else
        {
          meta_topic (META_DEBUG_KEYBINDINGS,
                      "Failed to parse new gconf value\n");
          
          meta_warning (_("\"%s\" found in configuration database is not a valid value for mouse button modifier\n"),
                        value);
        }
    }

  return old_mods != mouse_button_mods;
}
1084
#endif /* HAVE_GCONF */
1085

1086
#ifdef HAVE_GCONF
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100
static gboolean
update_focus_mode (const char *value)
{
  MetaFocusMode old_mode = focus_mode;
  
  if (value != NULL)
    {
      if (g_ascii_strcasecmp (value, "click") == 0)
        focus_mode = META_FOCUS_MODE_CLICK;
      else if (g_ascii_strcasecmp (value, "sloppy") == 0)
        focus_mode = META_FOCUS_MODE_SLOPPY;
      else if (g_ascii_strcasecmp (value, "mouse") == 0)
        focus_mode = META_FOCUS_MODE_MOUSE;
      else
1101
        meta_warning (_("GConf key '%s' is set to an invalid value\n"),
1102 1103 1104 1105 1106
                      KEY_FOCUS_MODE);
    }

  return (old_mode != focus_mode);
}
1107
#endif /* HAVE_GCONF */
1108

1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129
#ifdef HAVE_GCONF
static gboolean
update_focus_new_windows (const char *value)
{
  MetaFocusNewWindows old_mode = focus_new_windows;
  
  if (value != NULL)
    {
      if (g_ascii_strcasecmp (value, "smart") == 0)
        focus_new_windows = META_FOCUS_NEW_WINDOWS_SMART;
      else if (g_ascii_strcasecmp (value, "strict") == 0)
        focus_new_windows = META_FOCUS_NEW_WINDOWS_STRICT;
      else
        meta_warning (_("GConf key '%s' is set to an invalid value\n"),
                      KEY_FOCUS_NEW_WINDOWS);
    }

  return (old_mode != focus_new_windows);
}
#endif /* HAVE_GCONF */

1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141
#ifdef HAVE_GCONF
static gboolean
update_raise_on_click (gboolean value)
{
  gboolean old = raise_on_click;

  raise_on_click = value;

  return old != value;
}
#endif /* HAVE_GCONF */

1142
#ifdef HAVE_GCONF
1143 1144 1145
static gboolean
update_theme (const char *value)
{
1146
  char *old_theme;
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173
  gboolean changed;
  
  old_theme = current_theme;
  
  if (value != NULL && *value)
    {
      current_theme = g_strdup (value);
    }

  changed = TRUE;
  if ((old_theme && current_theme &&
       strcmp (old_theme, current_theme) == 0) ||
      (old_theme == NULL && current_theme == NULL))
    changed = FALSE;

  if (old_theme != current_theme)
    g_free (old_theme);

  if (current_theme == NULL)
    {
      /* Fallback crackrock */
      current_theme = g_strdup ("Atlanta");
      changed = TRUE;
    }
  
  return changed;
}
1174
#endif /* HAVE_GCONF */
1175 1176 1177 1178 1179 1180 1181

MetaVirtualModifier
meta_prefs_get_mouse_button_mods  (void)
{
  return mouse_button_mods;
}

1182 1183 1184 1185 1186 1187
MetaFocusMode
meta_prefs_get_focus_mode (void)
{
  return focus_mode;
}

1188 1189 1190 1191 1192 1193
MetaFocusNewWindows
meta_prefs_get_focus_new_windows (void)
{
  return focus_new_windows;
}

1194 1195 1196 1197 1198 1199 1200 1201 1202
gboolean
meta_prefs_get_raise_on_click (void)