From 1adb9753475b6eb2d158b848c21a2e0b6e8cd798 Mon Sep 17 00:00:00 2001 From: Neil Bird Date: Sun, 25 Jul 2010 13:06:35 +0100 Subject: [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 58beba0d4..c31891ed1 100644 --- a/stickynotes/stickynotes.schemas.in +++ b/stickynotes/stickynotes.schemas.in @@ -133,6 +133,18 @@ + + /schemas/apps/stickynotes_applet/settings/desktop_hide + /apps/stickynotes_applet/settings/desktop_hide + stickynotes_applet + bool + true + + Whether to hide all notes when the desktop is selected + If this option is enabled, selecting the desktop in any way will automatically hide all the open notes. + + + /schemas/apps/stickynotes_applet/settings/confirm_deletion /apps/stickynotes_applet/settings/confirm_deletion diff --git a/stickynotes/stickynotes.ui b/stickynotes/stickynotes.ui index 3df4289f9..14bcdf3f7 100644 --- a/stickynotes/stickynotes.ui +++ b/stickynotes/stickynotes.ui @@ -373,6 +373,23 @@ 2 12 6 + + + Hide notes when the des_ktop is clicked on + True + True + True + Choose whether to hide all notes when selecting on the desktop + True + True + + + 2 + 3 + 4 + + + Force _default color and font on notes diff --git a/stickynotes/stickynotes_applet.c b/stickynotes/stickynotes_applet.c index f3fe77670..b653247e9 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 (>K_CHECK_BUTTON ( gtk_builder_get_object (stickynotes->builder, "force_default_check"))->toggle_button); + stickynotes->w_prefs_desktop = GTK_WIDGET (>K_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 ddc2028ad..549e89913 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 bffa3adcd..24622b2ed 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. */ -- cgit v1.2.3