[Goodies-commits] r3354 - xfce4-notes-plugin/trunk/panel-plugin
Mike Massonnet
mmassonnet at xfce.org
Thu Oct 11 00:02:44 CEST 2007
Author: mmassonnet
Date: 2007-10-10 22:02:44 +0000 (Wed, 10 Oct 2007)
New Revision: 3354
Modified:
xfce4-notes-plugin/trunk/panel-plugin/notes.c
xfce4-notes-plugin/trunk/panel-plugin/notes.h
xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c
Log:
* panel-plugin/notes.c(notes_window_show): Deiconify the window (in
a certain case it will break the window is left iconified).
* panel-plugin/notes.c(notes_note_save_data): Save the data only if
the NotesNote->timeout is set.
* panel-plugin/panel-plugin.c(notes_plugin_new),
panel-plugin/panel-plugin.c(notes_plugin_destroy_timeout),
panel-plugin/panel-plugin.c(notes_plugin_button_pressed),
panel-plugin/panel-plugin.c(notes_plugin_button_released),
panel-plugin/panel-plugin.c(notes_plugin_show_hide_windows),
panel-plugin/panel-plugin.c(notes_plugin_menu_popup): Change the
behavior of the panel button to show all/hide all windows on
click, and display the popup menu on timeout while the button is
left pressed.
* panel-plugin/panel-plugin.c(notes_plugin_menu_destroy): Check the
menu pointer to dettach it.
* panel_plugin/panel-plugin.c(notes_plugin_message_received): Call
function notes_plugin_show_hide_windows() by default.
Modified: xfce4-notes-plugin/trunk/panel-plugin/notes.c
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/notes.c 2007-10-10 22:02:34 UTC (rev 3353)
+++ xfce4-notes-plugin/trunk/panel-plugin/notes.c 2007-10-10 22:02:44 UTC (rev 3354)
@@ -969,6 +969,8 @@
GTK_WIDGET_UNSET_FLAGS (notes_window->notebook,
GTK_CAN_FOCUS);
gtk_widget_show (notes_window->window);
+
+ gtk_window_deiconify (GTK_WINDOW (notes_window->window));
}
gboolean
@@ -1405,6 +1407,14 @@
gboolean
notes_note_save_data (NotesNote *notes_note)
{
+ if (notes_note->timeout == 0)
+ return TRUE;
+ else
+ {
+ g_source_remove (notes_note->timeout);
+ notes_note->timeout = 0;
+ }
+
DBG ("Save note `%s'", notes_note->name);
GtkTextBuffer *buffer;
Modified: xfce4-notes-plugin/trunk/panel-plugin/notes.h
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/notes.h 2007-10-10 22:02:34 UTC (rev 3353)
+++ xfce4-notes-plugin/trunk/panel-plugin/notes.h 2007-10-10 22:02:44 UTC (rev 3354)
@@ -32,6 +32,7 @@
GSList *windows;
gchar *config_file;
gchar *notes_path;
+ guint timeout;
GtkWidget *btn_panel;
GtkWidget *icon_panel;
Modified: xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c 2007-10-10 22:02:34 UTC (rev 3353)
+++ xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c 2007-10-10 22:02:44 UTC (rev 3354)
@@ -35,6 +35,8 @@
static NotesPlugin *notes_plugin_new (XfcePanelPlugin *panel_plugin);
+static gboolean notes_plugin_set_size (NotesPlugin *notes_plugin,
+ int size);
static void notes_plugin_load_data (NotesPlugin *notes_plugin);
static inline void notes_plugin_save_data (NotesPlugin *notes_plugin);
@@ -43,11 +45,17 @@
static void notes_plugin_free (NotesPlugin *notes_plugin);
-static gboolean notes_plugin_set_size (NotesPlugin *notes_plugin,
- int size);
+static void notes_plugin_destroy_timeout (NotesPlugin *notes_plugin);
+
+static gboolean notes_plugin_button_pressed (NotesPlugin *notes_plugin,
+ GdkEventButton *event);
+static gboolean notes_plugin_button_released (NotesPlugin *notes_plugin,
+ GdkEventButton *event);
+static void notes_plugin_show_hide_windows (NotesPlugin *notes_plugin);
+
static void notes_plugin_menu_new (NotesPlugin *notes_plugin);
-static void notes_plugin_menu_popup (NotesPlugin *notes_plugin);
+static gboolean notes_plugin_menu_popup (NotesPlugin *notes_plugin);
static void notes_plugin_menu_position (GtkMenu *menu,
gint *x0,
@@ -106,9 +114,13 @@
G_CALLBACK (notes_plugin_free),
notes_plugin);
g_signal_connect_swapped (notes_plugin->btn_panel,
- "clicked",
- G_CALLBACK (notes_plugin_menu_popup),
+ "button-press-event",
+ G_CALLBACK (notes_plugin_button_pressed),
notes_plugin);
+ g_signal_connect_swapped (notes_plugin->btn_panel,
+ "button-release-event",
+ G_CALLBACK (notes_plugin_button_released),
+ notes_plugin);
xfce_panel_plugin_add_action_widget (panel_plugin, notes_plugin->btn_panel);
notes_plugin_set_selection (notes_plugin);
@@ -117,6 +129,22 @@
return notes_plugin;
}
+static gboolean
+notes_plugin_set_size (NotesPlugin *notes_plugin,
+ int size)
+{
+ DBG ("Set size to %d", size);
+
+ gtk_widget_set_size_request (notes_plugin->btn_panel, size, size);
+ size = size - 2 - (2 * MAX (notes_plugin->btn_panel->style->xthickness,
+ notes_plugin->btn_panel->style->ythickness));
+ GdkPixbuf *pixbuf = xfce_themed_icon_load ("xfce4-notes-plugin", size);
+ gtk_image_set_from_pixbuf (GTK_IMAGE (notes_plugin->icon_panel), pixbuf);
+ g_object_unref (G_OBJECT (pixbuf));
+
+ return TRUE;
+}
+
static void
notes_plugin_load_data (NotesPlugin *notes_plugin)
{
@@ -151,22 +179,6 @@
while (G_LIKELY (NULL != window_name));
}
-static gboolean
-notes_plugin_set_size (NotesPlugin *notes_plugin,
- int size)
-{
- DBG ("Set size to %d", size);
-
- gtk_widget_set_size_request (notes_plugin->btn_panel, size, size);
- size = size - 2 - (2 * MAX (notes_plugin->btn_panel->style->xthickness,
- notes_plugin->btn_panel->style->ythickness));
- GdkPixbuf *pixbuf = xfce_themed_icon_load ("xfce4-notes-plugin", size);
- gtk_image_set_from_pixbuf (GTK_IMAGE (notes_plugin->icon_panel), pixbuf);
- g_object_unref (G_OBJECT (pixbuf));
-
- return TRUE;
-}
-
static inline void
notes_plugin_save_data (NotesPlugin *notes_plugin)
{
@@ -193,6 +205,69 @@
}
static void
+notes_plugin_destroy_timeout (NotesPlugin *notes_plugin)
+{
+ notes_plugin->timeout = 0;
+}
+
+static gboolean
+notes_plugin_button_pressed (NotesPlugin *notes_plugin,
+ GdkEventButton *event)
+{
+ if (G_LIKELY (event->button != 1 || event->state & GDK_CONTROL_MASK))
+ return FALSE;
+
+ if (notes_plugin->timeout == 0)
+ notes_plugin->timeout =
+ g_timeout_add_full (G_PRIORITY_DEFAULT,
+ 225,
+ (GSourceFunc)notes_plugin_menu_popup,
+ notes_plugin,
+ (GDestroyNotify)notes_plugin_destroy_timeout);
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notes_plugin->btn_panel), TRUE);
+
+ return TRUE;
+}
+
+static gboolean
+notes_plugin_button_released (NotesPlugin *notes_plugin,
+ GdkEventButton *event)
+{
+ if (G_LIKELY (event->button != 1))
+ return FALSE;
+
+ if (G_LIKELY (notes_plugin->timeout > 0))
+ g_source_remove (notes_plugin->timeout);
+
+ if (GTK_BUTTON (notes_plugin->btn_panel)->in_button)
+ notes_plugin_show_hide_windows (notes_plugin);
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notes_plugin->btn_panel), FALSE);
+
+ return FALSE;
+}
+
+static void
+notes_plugin_show_hide_windows (NotesPlugin *notes_plugin)
+{
+ gboolean visible = FALSE;
+ gint i = 0;
+ NotesWindow *notes_window;
+
+ while (NULL != (notes_window = (NotesWindow *)g_slist_nth_data (notes_plugin->windows, i++)))
+ {
+ if (!(visible = GTK_WIDGET_VISIBLE (notes_window->window)))
+ break;
+ }
+
+ if (visible)
+ g_slist_foreach (notes_plugin->windows, (GFunc)notes_window_hide, NULL);
+ else
+ g_slist_foreach (notes_plugin->windows, (GFunc)notes_window_show, NULL);
+}
+
+static void
notes_plugin_menu_new (NotesPlugin *notes_plugin)
{
guint i = 0;
@@ -243,20 +318,20 @@
gtk_widget_show_all (notes_plugin->menu);
}
-static void
+static gboolean
notes_plugin_menu_popup (NotesPlugin *notes_plugin)
{
- if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (notes_plugin->btn_panel)))
- {
- notes_plugin_menu_new (notes_plugin);
- gtk_menu_popup (GTK_MENU (notes_plugin->menu),
- NULL,
- NULL,
- (GtkMenuPositionFunc) notes_plugin_menu_position,
- notes_plugin->panel_plugin,
- 0,
- gtk_get_current_event_time ());
- }
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notes_plugin->btn_panel), TRUE);
+ notes_plugin_menu_new (notes_plugin);
+ gtk_menu_popup (GTK_MENU (notes_plugin->menu),
+ NULL,
+ NULL,
+ (GtkMenuPositionFunc) notes_plugin_menu_position,
+ notes_plugin->panel_plugin,
+ 0,
+ gtk_get_current_event_time ());
+
+ return FALSE;
}
static void
@@ -316,7 +391,8 @@
notes_plugin_menu_destroy (NotesPlugin *notes_plugin)
{
DBG ("Dettach window menu");
- gtk_menu_detach (GTK_MENU (notes_plugin->menu));
+ if (G_LIKELY (GTK_IS_MENU (notes_plugin->menu)))
+ gtk_menu_detach (GTK_MENU (notes_plugin->menu));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notes_plugin->btn_panel), FALSE);
}
@@ -326,7 +402,7 @@
-/* Handle user messages from xfce4-popup-notes command */
+/* Handle user messages */
static gboolean
notes_plugin_message_received (GtkWidget *widget,
@@ -338,15 +414,13 @@
DBG ("Message received");
if (G_LIKELY (ev->data_format == 8 && *(ev->data.b) != '\0'))
{
+ DBG ("`%s'", ev->data.b);
if (!g_ascii_strcasecmp (XFCE_NOTES_MESSAGE, ev->data.b))
{
- DBG ("`%s'", ev->data.b);
- xfce_panel_plugin_set_panel_hidden (notes_plugin->panel_plugin,
- FALSE);
- while (gtk_events_pending ())
- gtk_main_iteration ();
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (notes_plugin->btn_panel),
- TRUE);
+ notes_plugin_show_hide_windows (notes_plugin);
+ /*GdkEventButton ev_btn;
+ ev_btn.button = 1;
+ notes_plugin_button_pressed (notes_plugin, &ev_btn);*/
return TRUE;
}
}
More information about the Goodies-commits
mailing list