Skip to content
Snippets Groups Projects
95_desktop-effects-integration.patch 52.7 KiB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 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 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 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 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 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 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
Description: Add desktop effects tab to the appearance capplet
Author: ?

Index: gnome-control-center-2.30.0/capplets/appearance/appearance-effects.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gnome-control-center-2.30.0/capplets/appearance/appearance-effects.c	2010-04-10 00:21:01.152659047 +0100
@@ -0,0 +1,1089 @@
+/*
+ * Copyright (C) 2007 Canonical
+ * Written by Michael Vogt <mvo@ubuntu.com>
+ * and Mirco Müller <mirco@ubuntu.com>
+ * All Rights Reserved
+ *
+ * Based on desktop-effects.c:
+ *   Desktop Effects. A preference panel for compiz.
+ *   Copyright (C) 2006   Red Hat, Inc.
+ * Author: Soren Sandmann (sandmann@redhat.com) *
+ *
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <glib.h>
+#include <glib/gstdio.h>
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+#include <gdk/gdkx.h>
+#include <X11/extensions/Xcomposite.h>
+#include <math.h>
+#include <stdlib.h>
+
+#include "appearance.h"
+#include "appearance-effects.h"
+
+#include "gconf-property-editor.h"
+
+typedef enum {
+	COMPIZ,
+	METACITY
+} WindowManager;
+
+#define WINDOW_MANAGER_KEY "/desktop/gnome/session/required_components/windowmanager"
+#define REVERT_COUNT	   40
+#define SECONDS_WE_WILL_WAIT_FOR_COMPIZ_TO_START 8
+#define PLUGIN_LIST_KEY	   "/apps/compiz/general/allscreens/options/active_plugins"
+#define NUM_WORKSPACES	   "/apps/metacity/general/num_workspaces"
+
+/* helper structure to pass pager data around */
+typedef struct _TraversalChunk {
+	GConfClient *client;
+	GArray	    *numRowsArray;
+	gint	    rows;
+} TraversalChunk;
+
+/* possible effects level */
+enum {
+	NO_EFFECTS, 
+	NORMAL_EFFECTS, 
+	EXTRA_EFFECTS, 
+	CUSTOM_EFFECTS
+};
+
+/* radio-button names in ui-file */
+static const char *effect_choices[] =  {
+	"no_effects_button",
+	"normal_effects_button", 
+	"extra_effects_button",
+	"custom_effects_button"
+};
+
+/* plugin-set for extra-effects level */
+static const gchar* extra_effects[] = {
+	"shift",
+	"wobbly",
+	NULL
+};
+
+static gboolean
+check_graphics_driver (void)
+{
+	return system ("jockey-gtk --check-composite") == 0;
+}
+
+static gboolean
+check_simple_ccsm (void)
+{
+	return g_file_test ("/usr/bin/simple-ccsm", G_FILE_TEST_IS_EXECUTABLE);
+}
+
+static void
+run_simple_ccsm (GtkButton *widget,
+	  gpointer  data)
+{
+	g_spawn_command_line_async ("/usr/bin/simple-ccsm", NULL);
+}
+
+static GSList *
+get_plugins (AppearanceData *app,
+	     GError	    **err)
+{
+	return gconf_client_get_list (app->client,
+				      PLUGIN_LIST_KEY,
+				      GCONF_VALUE_STRING,
+				      err);
+}
+
+static gboolean
+contains_string (GSList	     *plugins,
+		 const gchar *needle)
+{
+	GSList *slist;
+
+	for (slist = plugins; slist != NULL; slist = slist->next)
+	{
+		const char *s = slist->data;
+
+		if (s && strcmp (s, needle) == 0)
+			return TRUE;
+	}
+
+	return FALSE;
+}
+
+
+static void
+show_info (const char *text)
+{
+	GtkWidget *dialog;
+
+	dialog = gtk_message_dialog_new (NULL,
+					 GTK_DIALOG_MODAL,
+					 GTK_MESSAGE_INFO,
+					 GTK_BUTTONS_OK,
+					 "%s",
+					 text);
+
+	gtk_dialog_run (GTK_DIALOG (dialog));
+	gtk_widget_destroy (dialog);
+}
+
+static gchar*
+get_string_value (GConfClient* client,
+		  const gchar* key)
+{
+	gchar  *value = NULL;
+	GError *error = NULL;
+
+	g_assert (client != NULL);
+	g_assert (key    != NULL);
+
+	value = gconf_client_get_string (client, key, &error);
+	if (error)
+		return NULL;
+
+	return value;
+}
+
+static gint
+get_int_value (GConfClient* client,
+	       const gchar* key)
+{
+	gint	value = 0;
+	GError*	error = NULL;
+
+	g_assert (client != NULL);
+	g_assert (key    != NULL);
+
+	value = gconf_client_get_int (client, key, &error);
+	if (error)
+		return 0;
+
+	return value;
+}
+
+static void
+check_for_wnck_entry (gpointer data,
+		      gpointer user_data)
+{
+	gchar		*appletId	= (gchar*) data;
+	TraversalChunk	*chunk		= (TraversalChunk*) user_data;
+	GString		*propertyPath	= NULL;
+	gchar		*value		= NULL;
+	gint		rows		= 0;
+	gint		position	= 0;
+
+	/* get bonobo-id of applet */
+	propertyPath = g_string_new ("/apps/panel/applets/");
+	propertyPath = g_string_append (propertyPath, appletId);
+	propertyPath = g_string_append (propertyPath, "/bonobo_iid");
+	value = get_string_value (chunk->client, propertyPath->str);
+
+	/* just exit if no bonobo-id was found */
+	if (!value)
+	{
+		g_string_free (propertyPath, TRUE);
+		return;
+	}
+
+	/* test if it is actually a switcher */
+	if (!g_ascii_strncasecmp (value,
+				  "OAFIID:GNOME_WorkspaceSwitcherApplet",
+				  36))
+	{
+		/* assemble new gconf-path for num_rows gconf-key */
+		g_string_free (propertyPath, TRUE);
+		propertyPath = g_string_new ("/apps/panel/applets/");
+		propertyPath = g_string_append (propertyPath, appletId);
+		propertyPath = g_string_append (propertyPath, "/position");
+
+		/* get the value of position */
+		position = get_int_value (chunk->client, propertyPath->str);
+
+		if (position > 1)
+		{
+			/* assemble new gconf-path for num_rows gconf-key */
+			g_string_free (propertyPath, TRUE);
+			propertyPath = g_string_new ("/apps/panel/applets/");
+			propertyPath = g_string_append (propertyPath, appletId);
+			propertyPath = g_string_append (propertyPath,
+							"/prefs/num_rows");
+
+			/* get the value of rows */
+			rows = get_int_value (chunk->client, propertyPath->str);
+
+			if (!chunk->numRowsArray)
+				chunk->numRowsArray = g_array_new (TRUE,
+								   TRUE,
+								   sizeof (gint));
+
+			g_array_append_val (chunk->numRowsArray, rows);
+		}
+	}
+
+	g_string_free (propertyPath, TRUE);
+}
+
+gboolean
+set_int_value (GConfClient *client,
+               const gchar *key,
+               gint        value)
+{
+	gboolean result = FALSE;
+	GError   *error = NULL;
+
+	g_assert (client != NULL);
+	g_assert (key    != NULL);
+
+	result = gconf_client_set_int (client,
+				       key,
+				       value,
+				       &error);
+
+	if (error)
+		return FALSE;
+
+	return result;
+}
+
+static void
+set_wnck_entry (gpointer data,
+                gpointer user_data)
+{
+	gchar		*appletId	= (gchar*) data;
+	TraversalChunk	*chunk		= (TraversalChunk*) user_data;
+	GString		*propertyPath	= NULL;
+	gchar		*value		= NULL;
+	gint		position	= 0;
+
+	/* get bonobo-id of applet */
+	propertyPath = g_string_new ("/apps/panel/applets/");
+	propertyPath = g_string_append (propertyPath, appletId);
+	propertyPath = g_string_append (propertyPath, "/bonobo_iid");
+	value = get_string_value (chunk->client, propertyPath->str);
+
+	/* just exit if no bonobo-id was found */
+	if (!value)
+	{
+		g_string_free (propertyPath, TRUE);
+		return;
+	}
+
+	/* test if it is actually a switcher */
+	if (!g_ascii_strncasecmp (value,
+				  "OAFIID:GNOME_WorkspaceSwitcherApplet",
+				  36))
+	{
+		/* assemble new gconf-path for applets position gconf-key */
+		g_string_free (propertyPath, TRUE);
+		propertyPath = g_string_new ("/apps/panel/applets/");
+		propertyPath = g_string_append (propertyPath, appletId);
+		propertyPath = g_string_append (propertyPath, "/position");
+
+		/* get the value of position */
+		position = get_int_value (chunk->client, propertyPath->str);
+
+		/* not the best way to test, if this applet is really active */
+		if (position > 1)
+		{
+			/* assemble new gconf-path for num_rows gconf-key */
+			g_string_free (propertyPath, TRUE);
+			propertyPath = g_string_new ("/apps/panel/applets/");
+			propertyPath = g_string_append (propertyPath, appletId);
+			propertyPath = g_string_append (propertyPath,
+							"/prefs/num_rows");
+
+			/* set the value of rows */
+			set_int_value (chunk->client,
+				       propertyPath->str,
+				       chunk->rows);
+		}
+	}
+
+	/* cleanup */
+	g_string_free (propertyPath, TRUE);
+}
+
+static gint
+get_pager_num_rows (GConfClient *client)
+{
+	GSList         *idList = NULL;
+	TraversalChunk *chunk  = NULL;
+	gint           rows    = 0;
+
+	/* get ids of all used applets */
+	idList = gconf_client_get_list (client,
+					"/apps/panel/general/applet_id_list",
+					GCONF_VALUE_STRING,
+					NULL);
+
+	if (!idList)
+		return 1;
+
+	/* create and initialize helper-structure */
+	chunk = g_new0 (TraversalChunk, 1);
+	if (!chunk)
+	{
+		g_slist_free (idList);
+		return 1;
+	}
+
+	chunk->client = client;
+
+	/* search list of applets for wnck-applet */
+	g_slist_foreach (idList,
+			 check_for_wnck_entry,
+			 (gpointer) chunk);
+
+	if (chunk->numRowsArray == NULL)
+		rows = 1;
+	else
+		rows = g_array_index (chunk->numRowsArray, gint, 0);
+
+	/* clean up */
+	g_slist_free (idList);
+    if (chunk->numRowsArray)
+		g_array_free (chunk->numRowsArray, TRUE);
+	g_free (chunk);
+
+	return rows;
+}
+
+/* sets the number of rows of the first pager-applet found */
+void static
+set_pager_num_rows (GConfClient *client,
+                    gint        rows)
+{
+	GSList         *idList = NULL;
+	TraversalChunk *chunk  = NULL;
+
+	/* get ids of all used applets */
+	idList = gconf_client_get_list (client,
+					"/apps/panel/general/applet_id_list",
+					GCONF_VALUE_STRING,
+					NULL);
+
+	/* if nothing is found at least return 1 to avoid a div. by 0 later */
+	if (!idList)
+		return;
+
+	/* create and initialize helper-structure */
+	chunk = g_new0 (TraversalChunk, 1);
+	if (!chunk)
+	{
+		g_slist_free (idList);
+		return;
+	}
+
+	chunk->client = client;
+	chunk->rows = rows;
+
+	/* search list of applets for wnck-applet */
+	g_slist_foreach (idList,
+			 set_wnck_entry,
+			 (gpointer) chunk);
+
+	/* clean up */
+	g_slist_free (idList);
+    if (chunk->numRowsArray)
+		g_array_free (chunk->numRowsArray, TRUE);
+	g_free (chunk);
+}
+
+static void
+apply_settings (AppearanceData	*app,
+		gboolean	effects_enabled)
+{
+        const char *str = effects_enabled? "compiz" : "metacity";
+	char	   *session_file;
+	gint	   vsize;
+	gint	   hsize;
+	gint	   workspaces;
+	gint	   rows;
+
+	gconf_client_set_string (app->client,
+				 WINDOW_MANAGER_KEY,
+				 str,
+				 NULL);
+
+	session_file = g_build_filename (g_get_home_dir (),
+					 ".gnome2",
+					 "session",
+					 NULL);
+
+	g_unlink (session_file);
+	g_free (session_file);
+
+	/* here the whole logic for mapping any N:M workspace-layout from
+	 * metacity to compiz or vice versa is handled, currently only
+	 * implemented for one-screen setups */
+	if (effects_enabled)
+	{
+		workspaces = get_int_value (app->client,
+				            "/apps/metacity/general/num_workspaces");
+		rows = get_pager_num_rows (app->client);
+		set_int_value (app->client,
+			       "/apps/compiz/general/screen0/options/vsize",
+			       rows);
+		set_int_value (app->client,
+			       "/apps/compiz/general/screen0/options/hsize",
+			       (gint) ceilf ((gfloat) workspaces / (gfloat) rows));
+		set_pager_num_rows (app->client, 1);
+	}
+	else if (app->compiz_was_running)
+	{
+		vsize = get_int_value (app->client,
+				       "/apps/compiz/general/screen0/options/vsize");
+		hsize = get_int_value (app->client,
+				       "/apps/compiz/general/screen0/options/hsize");
+		set_int_value (app->client,
+			       "/apps/metacity/general/num_workspaces",
+			       vsize * hsize);
+		set_pager_num_rows (app->client, vsize);
+	}
+}
+
+static void
+set_busy (GtkWidget *widget,
+	  gboolean  busy)
+{
+	GdkCursor *cursor;
+
+	if (busy)
+		cursor = gdk_cursor_new (GDK_WATCH);
+	else
+		cursor = NULL;
+
+	gdk_window_set_cursor (widget->window, cursor);
+
+	if (cursor)
+		gdk_cursor_unref (cursor);
+
+	gdk_flush ();
+}
+
+
+gchar*
+get_current_window_manager (void)
+{
+	Window	*xwindow;
+	Atom	type;
+	gint	format;
+	gulong	nitems;
+	gulong	bytes_after;
+	gchar  *name;
+
+	XGetWindowProperty (GDK_DISPLAY (),
+			    GDK_ROOT_WINDOW (),
+			    XInternAtom (GDK_DISPLAY (),
+			    		 "_NET_SUPPORTING_WM_CHECK",
+			    		 False),
+			    0,
+			    G_MAXLONG,
+			    False,
+			    XA_WINDOW,
+			    &type,
+			    &format,
+			    &nitems,
+			    &bytes_after,
+			    (guchar **) &xwindow);
+
+	if (type != XA_WINDOW)
+		return NULL;
+
+	gdk_error_trap_push ();
+	XSelectInput (GDK_DISPLAY (),
+		      *xwindow,
+		      StructureNotifyMask | PropertyChangeMask);
+	XSync (GDK_DISPLAY (), False);
+
+	if (gdk_error_trap_pop ())
+	{
+		XFree (xwindow);
+		return NULL;
+	}
+
+	name = NULL;
+
+	gdk_error_trap_push ();
+          
+	XGetWindowProperty (GDK_DISPLAY (),
+			    *xwindow,
+			    XInternAtom (GDK_DISPLAY (),
+					 "_NET_WM_NAME",
+					 False),
+			    0,
+			    G_MAXLONG,
+			    False,
+			    XInternAtom (GDK_DISPLAY (),
+					 "UTF8_STRING",
+					 False),
+			    &type,
+			    &format,
+			    &nitems,
+			    &bytes_after,
+			    (guchar **)&name);
+          
+	gdk_display_sync (GDK_DISPLAY ());
+	gdk_error_trap_pop ();
+	XFree (xwindow);
+	return name;
+}
+
+static gboolean
+compiz_started (void)
+{
+	gboolean result;
+	gchar *wm = get_current_window_manager ();
+
+	result = wm && strcmp (wm, "compiz") == 0;
+	g_free (wm);
+
+	return result;
+}
+
+typedef struct TimedDialogInfo {
+	AppearanceData	*app;
+	GTimer		*timer;
+	GtkWidget	*button;
+} TimedDialogInfo;
+
+static WindowManager
+current_configured_wm (AppearanceData *app,
+		       GError	      **err)
+{
+	GError *tmp = NULL;
+
+	const char *str = gconf_client_get_string (app->client,
+						   WINDOW_MANAGER_KEY,
+						   &tmp);
+
+	if (tmp)
+	{
+		g_propagate_error (err, tmp);
+		return METACITY;
+	}
+
+	if (str && strcmp (str, "compiz") == 0)
+		return COMPIZ;
+	else
+		return METACITY;
+}
+
+static void
+show_error (const GError *err)
+{
+	GtkWidget *dialog;
+
+	if (!err)
+		return;
+
+	dialog = gtk_message_dialog_new (NULL,
+					 GTK_DIALOG_DESTROY_WITH_PARENT,
+					 GTK_MESSAGE_WARNING,
+					 GTK_BUTTONS_OK,
+					 "%s",
+					 err->message);
+
+	gtk_window_set_title (GTK_WINDOW (dialog), "");
+
+	gtk_dialog_run (GTK_DIALOG (dialog));
+	gtk_widget_destroy (dialog);
+}
+
+struct TimeoutData {
+	int	  time;
+	GtkLabel  *label;
+	GtkDialog *dialog;
+	gboolean  timed_out;
+};
+
+static gboolean
+free_at_idle (gpointer data)
+{
+	g_free (data);
+	return FALSE;
+}
+
+static char*
+idle_free (char *str)
+{
+	g_idle_add (free_at_idle, str);
+	return str;
+}
+
+static char *
+timeout_string (int time)
+{
+	char *str = g_strdup_printf (ngettext ("Testing the new settings. If you don't respond in %d second the previous settings will be restored.", "Testing the new settings. If you don't respond in %d seconds the previous settings will be restored.", time), time);
+
+	return idle_free (str);
+}
+
+static gboolean
+save_timeout_callback (gpointer data)
+{
+	struct TimeoutData *timeData = data;
+
+	timeData->time--;
+
+	if (timeData->time == 0)
+	{
+		gtk_dialog_response (timeData->dialog, GTK_RESPONSE_NO);
+		timeData->timed_out = TRUE;
+		return FALSE;
+	}
+
+	gtk_label_set_text (timeData->label, timeout_string (timeData->time));
+
+	return TRUE;
+}
+
+static gboolean
+run_timed_dialog (AppearanceData *app)
+{
+	GtkWidget	   *dialog;
+	GtkWidget	   *hbox;
+	GtkWidget	   *vbox;
+	GtkWidget	   *label;
+	GtkWidget	   *label_sec;
+	GtkWidget	   *image;
+	int		   res;
+	struct TimeoutData timeout_data;
+	guint		   timeout;
+
+	dialog = gtk_dialog_new ();
+	gtk_window_set_transient_for (GTK_WINDOW (dialog),
+				      GTK_WINDOW (app->dialog));
+	gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
+	gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+	gtk_container_set_border_width (GTK_CONTAINER (dialog), 12);
+	gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
+	gtk_window_set_title (GTK_WINDOW (dialog), _("Keep Settings"));
+	gtk_window_set_position (GTK_WINDOW(dialog), GTK_WIN_POS_CENTER_ALWAYS);
+
+	label = gtk_label_new (NULL);
+	gtk_label_set_markup (GTK_LABEL (label),
+			      idle_free (g_strdup_printf ("<b>%s</b>",
+							  _("Do you want to keep these settings?"))));
+	image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_QUESTION,
+					  GTK_ICON_SIZE_DIALOG);
+	gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
+
+	gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+	gtk_label_set_selectable (GTK_LABEL (label), TRUE);
+	gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+
+	label_sec = gtk_label_new (timeout_string (REVERT_COUNT));
+	gtk_label_set_line_wrap (GTK_LABEL (label_sec), TRUE);
+	gtk_label_set_selectable (GTK_LABEL (label_sec), TRUE);
+	gtk_misc_set_alignment (GTK_MISC (label_sec), 0.0, 0.5);
+
+	hbox = gtk_hbox_new (FALSE, 6);
+	vbox = gtk_vbox_new (FALSE, 6);
+
+	gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
+	gtk_box_pack_start (GTK_BOX (vbox), label_sec, TRUE, TRUE, 0);
+	gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
+	gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
+	gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
+			    hbox,
+			    FALSE,
+			    FALSE,
+			    0);
+	gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+				_("Use _previous settings"),
+				GTK_RESPONSE_NO,
+				_("_Keep settings"),
+				GTK_RESPONSE_YES,
+				NULL);
+
+	gtk_widget_show_all (hbox);
+
+	timeout_data.time = REVERT_COUNT;
+	timeout_data.label = GTK_LABEL (label_sec);
+	timeout_data.dialog = GTK_DIALOG (dialog);
+	timeout_data.timed_out = FALSE;
+
+	timeout = gdk_threads_add_timeout (1000, save_timeout_callback, &timeout_data);
+	res = gtk_dialog_run (GTK_DIALOG (dialog));
+
+	if (!timeout_data.timed_out)
+		g_source_remove (timeout);
+
+	gtk_widget_destroy (dialog);
+
+	return (res == GTK_RESPONSE_YES);
+}
+
+static gboolean
+show_dialog_timeout (gpointer data)
+{
+	TimedDialogInfo	*info = data;
+	gboolean	has_compiz;
+
+	gtk_window_present (GTK_WINDOW (info->app->dialog));
+
+	has_compiz = compiz_started ();
+
+	if (has_compiz ||
+	    g_timer_elapsed (info->timer,
+	    		     NULL) > SECONDS_WE_WILL_WAIT_FOR_COMPIZ_TO_START)
+	{
+		if (has_compiz)
+		{
+			set_busy (info->app->dialog, FALSE);
+
+			if (run_timed_dialog (info->app))
+				apply_settings (info->app,
+						info->app->desktop_effects_level >= 1);
+			else
+				gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (info->button),
+							      TRUE);
+		}
+		else
+		{
+			GtkWidget *dialog;
+
+			gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (info->button),
+						      TRUE);
+
+			set_busy (info->app->dialog, FALSE);
+
+			dialog = gtk_message_dialog_new ((GtkWindow*) info->app->dialog,
+							 GTK_DIALOG_DESTROY_WITH_PARENT,
+							 GTK_MESSAGE_WARNING,
+							 GTK_BUTTONS_OK,
+							 _("Desktop effects could not be enabled"));
+
+			gtk_window_set_title (GTK_WINDOW (dialog), "");
+			gtk_dialog_run (GTK_DIALOG (dialog));
+			gtk_widget_destroy (dialog);
+		}
+
+		gtk_widget_set_sensitive (info->app->dialog, TRUE);
+
+		g_timer_destroy (info->timer);
+		g_free (info);
+
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+static gboolean
+start_compiz (AppearanceData *app,
+	      GError **err)
+{
+	if (!g_spawn_command_line_async ("compiz --replace", err))
+		return FALSE;
+
+	app->compiz_running = TRUE;
+
+	return TRUE;
+}
+
+static gboolean
+start_metacity (AppearanceData *app, GError **err)
+{
+	if (!g_spawn_command_line_async ("metacity --replace", err))
+		return FALSE;
+
+	app->compiz_running = FALSE;
+
+	return TRUE;
+}
+
+static gboolean
+has_composite ()
+{
+	int dummy1;
+	int dummy2;
+
+	if (XCompositeQueryExtension (GDK_DISPLAY (), &dummy1, &dummy2))
+		return TRUE;
+
+	return FALSE;
+}
+
+static void
+show_alert (const char *text)
+{
+	GtkWidget *dialog;
+
+	dialog = gtk_message_dialog_new (NULL,
+					 GTK_DIALOG_MODAL,
+					 GTK_MESSAGE_ERROR,
+					 GTK_BUTTONS_OK,
+					 "%s",					 
+					 text);
+
+	gtk_dialog_run (GTK_DIALOG (dialog));
+}
+
+static gboolean
+are_effects_enabled (AppearanceData* app,
+		     const gchar**   effects_list)
+{
+	int	 i;
+	gboolean res = TRUE;
+	GError	 *tmp = NULL;
+	GSList	 *plugins;
+
+	plugins = get_plugins (app, &tmp);
+	for (i = 0; effects_list[i] != NULL; i++)
+		res &= contains_string (plugins, effects_list[i]);
+
+	return res;
+}
+
+static gboolean
+reset_plugins (AppearanceData *app)
+{
+	GError *error = NULL;
+
+	return gconf_client_unset (app->client, PLUGIN_LIST_KEY, &error);
+}
+
+static gboolean
+are_normal_effects_enabled (AppearanceData *app)
+{
+   gboolean res = TRUE;
+   GError *err = NULL;
+   GSList *plugins, *default_plugins;
+
+   default_plugins = gconf_value_get_list ( gconf_client_get_default_from_schema (app->client,  PLUGIN_LIST_KEY, &err));
+
+   err = NULL;
+   plugins = get_plugins (app, &err);
+   for(;default_plugins; default_plugins = g_slist_next(default_plugins))
+      res &= contains_string(plugins, gconf_value_get_string(default_plugins->data));
+
+   return res;
+}
+
+static gboolean
+are_extra_effects_enabled (AppearanceData *app)
+{
+   return (are_effects_enabled (app, extra_effects) && 
+	   are_normal_effects_enabled (app));
+}
+
+static gint
+get_effects_level (AppearanceData *data)
+{
+	if (data->compiz_running)
+	{
+	        if (are_extra_effects_enabled (data))
+		        return EXTRA_EFFECTS;
+		else if (are_normal_effects_enabled (data))
+			return NORMAL_EFFECTS;
+		else
+			return CUSTOM_EFFECTS;
+        }
+        else
+		return NO_EFFECTS;       
+}
+
+static gboolean
+enable_normal_effects (AppearanceData* app)
+{
+   return reset_plugins (app);
+}
+
+static gboolean
+enable_extra_effects (AppearanceData* app)
+{
+	GError	*err = NULL;
+	GSList	*plugins = NULL;
+	int	i;
+
+	reset_plugins (app);
+
+	plugins = get_plugins (app, &err);
+	for (i = 0; extra_effects[i] != NULL; i++)
+		plugins = g_slist_append (plugins,
+					  (gchar*) extra_effects[i]);
+
+	err = NULL;
+	gconf_client_set_list (app->client,
+			       PLUGIN_LIST_KEY,
+			       GCONF_VALUE_STRING,
+			       plugins,
+			       &err);
+
+	return TRUE;
+}
+
+static void
+on_effects_toggle (GtkWidget *widget,
+		   gpointer  user_data)
+{
+	AppearanceData	*appdata = user_data;
+	GtkWidget	*previously_selected_button;
+	static gint	old_effects_level;
+	static gboolean	do_init = TRUE;
+	gint		i;
+	GError		*err = NULL;
+
+	if (do_init == TRUE)
+	{
+		old_effects_level = get_effects_level (appdata);
+		do_init = FALSE;
+	}
+
+	if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) 
+		return;
+
+	previously_selected_button = appearance_capplet_get_widget (appdata,
+							   								effect_choices [old_effects_level]);
+
+	/* Look for the button which has been selected */
+	for (i = 0; i < G_N_ELEMENTS (effect_choices); i++) 
+	{
+		if (widget == appearance_capplet_get_widget (appdata,
+						   							effect_choices [i]))
+			break;
+	}
+
+	appdata->desktop_effects_level = i;
+
+	if (appdata->desktop_effects_level >= 1)
+	{		
+		if (old_effects_level == 0 && check_graphics_driver())
+		{
+			show_info (_("Please run \"Appearance/Desktop Effects\" again after restarting "
+				     "the computer, when the new graphics driver is active."));
+			g_signal_handlers_block_by_func (widget,
+							 on_effects_toggle,
+							 appdata);
+			gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (appearance_capplet_get_widget (appdata,
+						      			effect_choices [old_effects_level])),
+						      			TRUE);
+			g_signal_handlers_unblock_by_func (widget,
+							   on_effects_toggle,
+							   appdata);
+			return;
+		}
+
+		if (!has_composite ())
+		{
+			show_alert ("The Composite extension is not available");
+			return;
+		}
+
+		if (old_effects_level == 0)
+			start_compiz (appdata, &err);
+