[gnome-applets] [stickynotes] fix clicking on desktop to hide stickynotes, bugs #614250 & #510933.



commit 1adb9753475b6eb2d158b848c21a2e0b6e8cd798
Author: Neil Bird <neilbird src gnome org>
Date:   Sun Jul 25 13:06:35 2010 +0100

    [stickynotes] fix clicking on desktop to hide stickynotes, bugs #614250 & #510933.
    
    This fix also adds a preference to control whether such hiding happens or not.
    Docs. not yet updated.

 stickynotes/stickynotes.schemas.in         |   12 +++++++
 stickynotes/stickynotes.ui                 |   17 ++++++++++
 stickynotes/stickynotes_applet.c           |   12 ++++++-
 stickynotes/stickynotes_applet.h           |    1 +
 stickynotes/stickynotes_applet_callbacks.c |   48 ++++++++++++++++++++++++++-
 5 files changed, 87 insertions(+), 3 deletions(-)
---
diff --git a/stickynotes/stickynotes.schemas.in b/stickynotes/stickynotes.schemas.in
index 58beba0..c31891e 100644
--- a/stickynotes/stickynotes.schemas.in
+++ b/stickynotes/stickynotes.schemas.in
@@ -134,6 +134,18 @@
 </schema>
 
 <schema>
+	<key>/schemas/apps/stickynotes_applet/settings/desktop_hide</key>
+	<applyto>/apps/stickynotes_applet/settings/desktop_hide</applyto>
+	<owner>stickynotes_applet</owner>
+	<type>bool</type>
+	<default>true</default>
+	<locale name="C">
+		<short>Whether to hide all notes when the desktop is selected</short>
+		<long>If this option is enabled, selecting the desktop in any way will automatically hide all the open notes.</long>
+	</locale>
+</schema>
+
+<schema>
 	<key>/schemas/apps/stickynotes_applet/settings/confirm_deletion</key>
 	<applyto>/apps/stickynotes_applet/settings/confirm_deletion</applyto>
 	<owner>stickynotes_applet</owner>
diff --git a/stickynotes/stickynotes.ui b/stickynotes/stickynotes.ui
index 3df4289..14bcdf3 100644
--- a/stickynotes/stickynotes.ui
+++ b/stickynotes/stickynotes.ui
@@ -374,6 +374,23 @@
                         <property name="column_spacing">12</property>
                         <property name="row_spacing">6</property>
                         <child>
+                          <object class="GtkCheckButton" id="desktop_hide_check">
+                            <property name="label" translatable="yes">Hide notes when the des_ktop is clicked on</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">True</property>
+                            <property name="tooltip_text" translatable="yes">Choose whether to hide all notes when selecting on the desktop</property>
+                            <property name="use_underline">True</property>
+                            <property name="draw_indicator">True</property>
+                          </object>
+                          <packing>
+                            <property name="right_attach">2</property>
+                            <property name="top_attach">3</property>
+                            <property name="bottom_attach">4</property>
+                            <property name="y_options"></property>
+                          </packing>
+                        </child>
+                        <child>
                           <object class="GtkCheckButton" id="force_default_check">
                             <property name="label" translatable="yes">Force _default color and font on notes</property>
                             <property name="visible">True</property>
diff --git a/stickynotes/stickynotes_applet.c b/stickynotes/stickynotes_applet.c
index f3fe776..b653247 100644
--- a/stickynotes/stickynotes_applet.c
+++ b/stickynotes/stickynotes_applet.c
@@ -231,6 +231,9 @@ void stickynotes_applet_init_prefs(void)
 	stickynotes->w_prefs_force = GTK_WIDGET (&GTK_CHECK_BUTTON (
 				        gtk_builder_get_object (stickynotes->builder,
 					"force_default_check"))->toggle_button);
+	stickynotes->w_prefs_desktop = GTK_WIDGET (&GTK_CHECK_BUTTON (
+				        gtk_builder_get_object (stickynotes->builder,
+					"desktop_hide_check"))->toggle_button);
 
 	g_signal_connect (G_OBJECT (stickynotes->w_prefs), "response",
 			G_CALLBACK (preferences_response_cb), NULL);
@@ -257,6 +260,8 @@ void stickynotes_applet_init_prefs(void)
 			"toggled", G_CALLBACK (preferences_save_cb), NULL);
 	g_signal_connect_swapped (G_OBJECT (stickynotes->w_prefs_force),
 			"toggled", G_CALLBACK (preferences_save_cb), NULL);
+	g_signal_connect_swapped (G_OBJECT (stickynotes->w_prefs_desktop),
+			"toggled", G_CALLBACK (preferences_save_cb), NULL);
 
 	{
 		GtkSizeGroup *group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
@@ -438,7 +443,7 @@ void
 stickynotes_applet_update_prefs (void)
 {
 	int height;
-	gboolean sys_color, sys_font, sticky, force_default;
+	gboolean sys_color, sys_font, sticky, force_default, desktop_hide;
 	char *font_str;
 	char *color_str, *font_color_str;
 	GdkColor color, font_color;
@@ -461,6 +466,8 @@ stickynotes_applet_update_prefs (void)
 			GCONF_PATH "/settings/force_default", NULL);
 	font_str = gconf_client_get_string (stickynotes->gconf,
 			GCONF_PATH "/defaults/font", NULL);
+	desktop_hide = gconf_client_get_bool (stickynotes->gconf,
+			GCONF_PATH "/settings/desktop_hide", NULL);
 
 	if (!font_str)
 	{
@@ -500,6 +507,9 @@ stickynotes_applet_update_prefs (void)
 	gtk_toggle_button_set_active (
 			GTK_TOGGLE_BUTTON (stickynotes->w_prefs_force),
 			force_default);
+	gtk_toggle_button_set_active (
+			GTK_TOGGLE_BUTTON (stickynotes->w_prefs_desktop),
+			desktop_hide);
 
 	gtk_color_button_set_color (
 			GTK_COLOR_BUTTON (stickynotes->w_prefs_color), &color);
diff --git a/stickynotes/stickynotes_applet.h b/stickynotes/stickynotes_applet.h
index ddc2028..549e899 100644
--- a/stickynotes/stickynotes_applet.h
+++ b/stickynotes/stickynotes_applet.h
@@ -53,6 +53,7 @@ typedef struct
 	GtkWidget *w_prefs_sys_font;
 	GtkWidget *w_prefs_sticky;
 	GtkWidget *w_prefs_force;
+	GtkWidget *w_prefs_desktop;
 
 	GList *notes;			/* Linked-List of all the sticky notes */
 	GList *applets;			/* Linked-List of all the applets */
diff --git a/stickynotes/stickynotes_applet_callbacks.c b/stickynotes/stickynotes_applet_callbacks.c
index bffa3ad..24622b2 100644
--- a/stickynotes/stickynotes_applet_callbacks.c
+++ b/stickynotes/stickynotes_applet_callbacks.c
@@ -144,7 +144,10 @@ static GdkFilterReturn desktop_window_event_filter (GdkXEvent *xevent,
 						    GdkEvent  *event,
 						    gpointer   data)
 {
-	if ((((XEvent*)xevent)->xany.type == PropertyNotify) &&
+	gboolean desktop_hide = gconf_client_get_bool (stickynotes->gconf,
+			GCONF_PATH "/settings/desktop_hide", NULL);
+	if (desktop_hide  &&
+	    (((XEvent*)xevent)->xany.type == PropertyNotify) &&
 	    (((XEvent*)xevent)->xproperty.atom == gdk_x11_get_xatom_by_name ("_NET_WM_USER_TIME"))) {
 		stickynote_show_notes (FALSE);
 	}
@@ -155,14 +158,48 @@ void install_check_click_on_desktop (void)
 {
 	Window desktop_window;
 	GdkWindow *window;
+	Atom user_time_window;
+	Atom user_time;
 
 	if (!get_desktop_window (&desktop_window)) {
 		return;
 	}
 
+	/* Access the desktop window */
 	window = gdk_window_foreign_new (desktop_window);
-	gdk_window_set_events (window, GDK_PROPERTY_CHANGE_MASK);
 
+	/* It may contain an atom to tell us which other window to monitor */
+	user_time_window = gdk_x11_get_xatom_by_name ("_NET_WM_USER_TIME_WINDOW");
+	user_time = gdk_x11_get_xatom_by_name ("_NET_WM_USER_TIME");
+	if (user_time != None  &&  user_time_window != None)
+	{
+		/* Looks like the atoms are there */
+		Atom actual_type;
+		int  actual_format;
+		long nitems;
+		long bytes;
+		Window *data;
+
+		/* We only use this extra property if the actual user-time property's missing */
+		int  status = XGetWindowProperty( GDK_DISPLAY(), desktop_window, user_time,
+					0, 4, False, AnyPropertyType, &actual_type, &actual_format,
+					&nitems, &bytes, (unsigned char **)&data );
+		if (actual_type == None)
+		{
+			/* No user-time property, so look for the user-time-window */
+			status = XGetWindowProperty( GDK_DISPLAY(), desktop_window, user_time_window,
+					0, 4, False, AnyPropertyType, &actual_type, &actual_format,
+					&nitems, &bytes, (unsigned char **)&data );
+			if (actual_type != None)
+			{
+				/* We have another window to monitor */
+				desktop_window = *data;
+				window = gdk_window_foreign_new (desktop_window);
+			}
+		}
+	}
+
+	gdk_window_set_events (window, GDK_PROPERTY_CHANGE_MASK);
 	gdk_window_add_filter (window, desktop_window_event_filter, NULL);
 }
 
@@ -400,6 +437,8 @@ preferences_save_cb (gpointer data)
 			GTK_TOGGLE_BUTTON (stickynotes->w_prefs_sticky));
 	gboolean force_default = gtk_toggle_button_get_active (
 			GTK_TOGGLE_BUTTON (stickynotes->w_prefs_force));
+	gboolean desktop_hide = gtk_toggle_button_get_active (
+			GTK_TOGGLE_BUTTON (stickynotes->w_prefs_desktop));
 
 	if (gconf_client_key_is_writable (stickynotes->gconf,
 				GCONF_PATH "/defaults/width", NULL))
@@ -428,6 +467,11 @@ preferences_save_cb (gpointer data)
 		gconf_client_set_bool (stickynotes->gconf,
 				GCONF_PATH "/settings/force_default",
 				force_default, NULL);
+	if (gconf_client_key_is_writable (stickynotes->gconf,
+				GCONF_PATH "/settings/desktop_hide", NULL))
+		gconf_client_set_bool (stickynotes->gconf,
+				GCONF_PATH "/settings/desktop_hide",
+				desktop_hide, NULL);
 }
 
 /* Preferences Callback : Change color. */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]