diff options
author | Davyd Madeley <davyd@madeley.id.au> | 2005-01-05 12:31:40 +0000 |
---|---|---|
committer | Davyd Madeley <davyd@src.gnome.org> | 2005-01-05 12:31:40 +0000 |
commit | 4eac243e3280d4039d46d7bf36548b1c0ba34571 (patch) | |
tree | aed23e1461ba899b162861c96a8f7f0f54411a4d | |
parent | b41184fa19245c9eba7f9370b6aec8569c9cbd15 (diff) |
Revamp of stickynotes, stage 2. Stickynotes can now deal with workspaces
2005-01-05 Davyd Madeley <davyd@madeley.id.au>
* GNOME_StickyNotesApplet.xml:
* stickynotes.c:
* stickynotes_callbacks.c:
* stickynotes.glade:
* stickynotes.schemas.in:
* stickynotes_applet.[ch]:
* stickynotes_applet_callbacks.c: Revamp of stickynotes, stage 2.
Stickynotes can now deal with workspaces as well as many other
things. Currently usable but many niggles left to sort out.
* util.[ch]: Some Xstuff to do what we're doing with libwnck instead
here but ifdefed out, so that I don't lose them.
-rw-r--r-- | stickynotes/ChangeLog | 15 | ||||
-rw-r--r-- | stickynotes/GNOME_StickyNotesApplet.xml | 3 | ||||
-rw-r--r-- | stickynotes/stickynotes.c | 15 | ||||
-rw-r--r-- | stickynotes/stickynotes.glade | 81 | ||||
-rw-r--r-- | stickynotes/stickynotes.schemas.in | 12 | ||||
-rw-r--r-- | stickynotes/stickynotes_applet.c | 178 | ||||
-rw-r--r-- | stickynotes/stickynotes_applet.h | 7 | ||||
-rw-r--r-- | stickynotes/stickynotes_applet_callbacks.c | 176 | ||||
-rw-r--r-- | stickynotes/stickynotes_callbacks.c | 2 | ||||
-rw-r--r-- | stickynotes/util.c | 109 | ||||
-rw-r--r-- | stickynotes/util.h | 4 |
11 files changed, 402 insertions, 200 deletions
diff --git a/stickynotes/ChangeLog b/stickynotes/ChangeLog index d51b6ea39..cd323f768 100644 --- a/stickynotes/ChangeLog +++ b/stickynotes/ChangeLog @@ -1,3 +1,18 @@ +2005-01-05 Davyd Madeley <davyd@madeley.id.au> + + * GNOME_StickyNotesApplet.xml: + * stickynotes.c: + * stickynotes_callbacks.c: + * stickynotes.glade: + * stickynotes.schemas.in: + * stickynotes_applet.[ch]: + * stickynotes_applet_callbacks.c: Revamp of stickynotes, stage 2. + Stickynotes can now deal with workspaces as well as many other + things. Currently usable but many niggles left to sort out. + + * util.[ch]: Some Xstuff to do what we're doing with libwnck instead + here but ifdefed out, so that I don't lose them. + 2005-01-04 Elijah Newren <newren@gmail.com> * stickynotes.c (stickynote_load): create all new windows before diff --git a/stickynotes/GNOME_StickyNotesApplet.xml b/stickynotes/GNOME_StickyNotesApplet.xml index 66c44fd79..8ec900ae4 100644 --- a/stickynotes/GNOME_StickyNotesApplet.xml +++ b/stickynotes/GNOME_StickyNotesApplet.xml @@ -1,11 +1,8 @@ <Root> <popups> <popup name="button3"> - <menuitem name="create" verb="create" _label="_New Note" pixtype="stock" pixname="gtk-new"/> <separator/> - <menuitem name="show" verb="show" _label="_Show Notes" type="toggle" id="show"/> <menuitem name="lock" verb="lock" _label="_Lock Notes" type="toggle" id="lock"/> - <separator/> <menuitem name="destroy_all" verb="destroy_all" _label="_Delete Notes" pixtype="stock" pixname="gtk-delete"/> <separator/> <menuitem name="preferences" verb="preferences" _label="_Preferences" pixtype="stock" pixname="gtk-preferences"/> diff --git a/stickynotes/stickynotes.c b/stickynotes/stickynotes.c index 1ac586121..d0a93f9dc 100644 --- a/stickynotes/stickynotes.c +++ b/stickynotes/stickynotes.c @@ -172,6 +172,7 @@ StickyNote * stickynote_new(GdkScreen *screen) gtk_window_set_decorated (GTK_WINDOW (note->w_window), FALSE); gtk_window_set_skip_taskbar_hint (GTK_WINDOW (note->w_window), TRUE); gtk_window_set_skip_pager_hint (GTK_WINDOW (note->w_window), TRUE); + gtk_window_set_keep_above (GTK_WINDOW (note->w_window), TRUE); gtk_widget_show_all (note->w_window); @@ -525,9 +526,13 @@ void stickynotes_save(void) xid = GDK_WINDOW_XID (note->w_window->window); wnck_win = wnck_window_get (xid); - if (wnck_win) + if (!gconf_client_get_bool (stickynotes->gconf, + GCONF_PATH "/settings/sticky", NULL) + && wnck_win) workspace = 1 + wnck_workspace_get_number ( wnck_window_get_workspace (wnck_win)); + else + workspace = 0; /* Retreive the title of the note */ const gchar *title = gtk_label_get_text(GTK_LABEL(note->w_title)); @@ -693,6 +698,7 @@ void stickynotes_load(GdkScreen *screen) tmp2 = new_nodes; wnck_screen = wnck_screen_get_default (); wnck_screen_force_update (wnck_screen); + while (tmp1) { StickyNote *note = tmp1->data; node = tmp2->data; @@ -705,13 +711,14 @@ void stickynotes_load(GdkScreen *screen) workspace_str = xmlGetProp (node, "workspace"); if (workspace_str) { - WnckWindow *wnck_win; - gulong xid; - WnckWorkspace *wnck_ws; workspace = atoi (workspace_str); if (workspace > 0) { + WnckWorkspace *wnck_ws; + gulong xid; + WnckWindow *wnck_win; + wnck_ws = wnck_screen_get_workspace ( wnck_screen, workspace - 1); diff --git a/stickynotes/stickynotes.glade b/stickynotes/stickynotes.glade index a655930bd..e638778bb 100644 --- a/stickynotes/stickynotes.glade +++ b/stickynotes/stickynotes.glade @@ -446,87 +446,6 @@ <property name="column_spacing">12</property> <child> - <widget class="GtkLabel" id="click_label"> - <property name="visible">True</property> - <property name="label" translatable="yes">Clic_k:</property> - <property name="use_underline">True</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="mnemonic_widget">click_behavior_menu</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkOptionMenu" id="click_behavior_menu"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="history">0</property> - - <child> - <widget class="GtkMenu" id="menu2"> - - <child> - <widget class="GtkImageMenuItem" id="new_note"> - <property name="visible">True</property> - <property name="label" translatable="yes">Create a new note</property> - <property name="use_underline">True</property> - - <child internal-child="image"> - <widget class="GtkImage" id="image8"> - <property name="visible">True</property> - <property name="stock">gtk-new</property> - <property name="icon_size">1</property> - <property name="xalign">0.5</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - </child> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="show_hide_all_notes"> - <property name="visible">True</property> - <property name="label" translatable="yes">Show/Hide all notes</property> - <property name="use_underline">True</property> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="lock_unlock_all_notes"> - <property name="visible">True</property> - <property name="label" translatable="yes">Lock/Unlock all notes</property> - <property name="use_underline">True</property> - </widget> - </child> - </widget> - </child> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="y_options"></property> - </packing> - </child> - - <child> <widget class="GtkCheckButton" id="sticky_check"> <property name="visible">True</property> <property name="tooltip" translatable="yes">Choose if notes are visible on all workspaces</property> diff --git a/stickynotes/stickynotes.schemas.in b/stickynotes/stickynotes.schemas.in index c34a4c684..1746b1fb7 100644 --- a/stickynotes/stickynotes.schemas.in +++ b/stickynotes/stickynotes.schemas.in @@ -110,18 +110,6 @@ </schema> <schema> - <key>/schemas/apps/stickynotes_applet/settings/click_behavior</key> - <applyto>/apps/stickynotes_applet/settings/click_behavior</applyto> - <owner>stickynotes_applet</owner> - <type>int</type> - <default>0</default> - <locale name="C"> - <short>Default click behavior of the applet</short> - <long>Occurs when the applet is either left-clicked or "enter" is pressed. The options are "0" for "New Note", "1" for "Show/Hide All Notes", and "2" for "Lock/Unlock All Notes".</long> - </locale> -</schema> - -<schema> <key>/schemas/apps/stickynotes_applet/settings/use_system_color</key> <applyto>/apps/stickynotes_applet/settings/use_system_color</applyto> <owner>stickynotes_applet</owner> diff --git a/stickynotes/stickynotes_applet.c b/stickynotes/stickynotes_applet.c index 996bf832d..8c113f88e 100644 --- a/stickynotes/stickynotes_applet.c +++ b/stickynotes/stickynotes_applet.c @@ -27,7 +27,6 @@ StickyNotes *stickynotes = NULL; /* Popup menu on the applet */ static const BonoboUIVerb stickynotes_applet_menu_verbs[] = { - BONOBO_UI_UNSAFE_VERB ("create", menu_create_cb), BONOBO_UI_UNSAFE_VERB ("destroy_all", menu_destroy_all_cb), BONOBO_UI_UNSAFE_VERB ("preferences", menu_preferences_cb), BONOBO_UI_UNSAFE_VERB ("help", menu_help_cb), @@ -194,18 +193,33 @@ void stickynotes_applet_init_icons(void) void stickynotes_applet_init_prefs(void) { - stickynotes->prefs = glade_xml_new(GLADE_PATH, "preferences_dialog", NULL); - - stickynotes->w_prefs = glade_xml_get_widget(stickynotes->prefs, "preferences_dialog"); - stickynotes->w_prefs_width = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(glade_xml_get_widget(stickynotes->prefs, "width_spin"))); - stickynotes->w_prefs_height= gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(glade_xml_get_widget(stickynotes->prefs, "height_spin"))); - stickynotes->w_prefs_color = glade_xml_get_widget(stickynotes->prefs, "default_color"); - stickynotes->w_prefs_sys_color = GTK_WIDGET(>K_CHECK_BUTTON(glade_xml_get_widget(stickynotes->prefs, "sys_color_check"))->toggle_button); - stickynotes->w_prefs_font = glade_xml_get_widget(stickynotes->prefs, "default_font"); - stickynotes->w_prefs_sys_font = GTK_WIDGET(>K_CHECK_BUTTON(glade_xml_get_widget(stickynotes->prefs, "sys_font_check"))->toggle_button); - stickynotes->w_prefs_click = glade_xml_get_widget(stickynotes->prefs, "click_behavior_menu"); - stickynotes->w_prefs_sticky = GTK_WIDGET(>K_CHECK_BUTTON(glade_xml_get_widget(stickynotes->prefs, "sticky_check"))->toggle_button); - stickynotes->w_prefs_force = GTK_WIDGET(>K_CHECK_BUTTON(glade_xml_get_widget(stickynotes->prefs, "force_default_check"))->toggle_button); + stickynotes->prefs = glade_xml_new (GLADE_PATH, "preferences_dialog", + NULL); + + stickynotes->w_prefs = glade_xml_get_widget (stickynotes->prefs, + "preferences_dialog"); + stickynotes->w_prefs_width = gtk_spin_button_get_adjustment ( + GTK_SPIN_BUTTON (glade_xml_get_widget ( + stickynotes->prefs, "width_spin"))); + stickynotes->w_prefs_height = gtk_spin_button_get_adjustment ( + GTK_SPIN_BUTTON (glade_xml_get_widget ( + stickynotes->prefs, "height_spin"))); + stickynotes->w_prefs_color = glade_xml_get_widget (stickynotes->prefs, + "default_color"); + stickynotes->w_prefs_sys_color = GTK_WIDGET (>K_CHECK_BUTTON ( + glade_xml_get_widget (stickynotes->prefs, + "sys_color_check"))->toggle_button); + stickynotes->w_prefs_font = glade_xml_get_widget (stickynotes->prefs, + "default_font"); + stickynotes->w_prefs_sys_font = GTK_WIDGET (>K_CHECK_BUTTON ( + glade_xml_get_widget (stickynotes->prefs, + "sys_font_check"))->toggle_button); + stickynotes->w_prefs_sticky = GTK_WIDGET (>K_CHECK_BUTTON ( + glade_xml_get_widget (stickynotes->prefs, + "sticky_check"))->toggle_button); + stickynotes->w_prefs_force = GTK_WIDGET (>K_CHECK_BUTTON ( + glade_xml_get_widget (stickynotes->prefs, + "force_default_check"))->toggle_button); g_signal_connect (G_OBJECT (stickynotes->w_prefs), "response", G_CALLBACK (preferences_response_cb), NULL); @@ -226,8 +240,6 @@ void stickynotes_applet_init_prefs(void) "color-set", G_CALLBACK (preferences_color_cb), NULL); g_signal_connect (G_OBJECT (stickynotes->w_prefs_font), "font-set", G_CALLBACK (preferences_font_cb), NULL); - g_signal_connect_swapped (G_OBJECT (stickynotes->w_prefs_click), - "changed", G_CALLBACK (preferences_save_cb), NULL); g_signal_connect_swapped (G_OBJECT (stickynotes->w_prefs_sticky), "toggled", G_CALLBACK (preferences_save_cb), NULL); g_signal_connect_swapped (G_OBJECT (stickynotes->w_prefs_force), @@ -239,39 +251,60 @@ void stickynotes_applet_init_prefs(void) gtk_size_group_add_widget(group, glade_xml_get_widget(stickynotes->prefs, "width_label")); gtk_size_group_add_widget(group, glade_xml_get_widget(stickynotes->prefs, "height_label")); gtk_size_group_add_widget(group, glade_xml_get_widget(stickynotes->prefs, "color_label")); - gtk_size_group_add_widget(group, glade_xml_get_widget(stickynotes->prefs, "click_label")); g_object_unref(group); } - if (!gconf_client_key_is_writable(stickynotes->gconf, GCONF_PATH "/defaults/width", NULL)) { - gtk_widget_set_sensitive(glade_xml_get_widget(stickynotes->prefs, "width_label"), FALSE); - gtk_widget_set_sensitive(glade_xml_get_widget(stickynotes->prefs, "width_spin"), FALSE); - } - if (!gconf_client_key_is_writable(stickynotes->gconf, GCONF_PATH "/defaults/height", NULL)) { - gtk_widget_set_sensitive(glade_xml_get_widget(stickynotes->prefs, "height_label"), FALSE); - gtk_widget_set_sensitive(glade_xml_get_widget(stickynotes->prefs, "height_spin"), FALSE); + if (!gconf_client_key_is_writable(stickynotes->gconf, + GCONF_PATH "/defaults/width", NULL)) + { + gtk_widget_set_sensitive (glade_xml_get_widget ( + stickynotes->prefs, "width_label"), + FALSE); + gtk_widget_set_sensitive (glade_xml_get_widget ( + stickynotes->prefs, "width_spin"), + FALSE); } - if (!gconf_client_key_is_writable(stickynotes->gconf, GCONF_PATH "/defaults/color", NULL)) { - gtk_widget_set_sensitive(glade_xml_get_widget(stickynotes->prefs, "color_label"), FALSE); - gtk_widget_set_sensitive(stickynotes->w_prefs_color, FALSE); + if (!gconf_client_key_is_writable (stickynotes->gconf, + GCONF_PATH "/defaults/height", NULL)) + { + gtk_widget_set_sensitive (glade_xml_get_widget ( + stickynotes->prefs, "height_label"), + FALSE); + gtk_widget_set_sensitive (glade_xml_get_widget ( + stickynotes->prefs, "height_spin"), + FALSE); } - if (!gconf_client_key_is_writable(stickynotes->gconf, GCONF_PATH "/settings/use_system_color", NULL)) - gtk_widget_set_sensitive(stickynotes->w_prefs_sys_color, FALSE); - if (!gconf_client_key_is_writable(stickynotes->gconf, GCONF_PATH "/defaults/font", NULL)) { - gtk_widget_set_sensitive(glade_xml_get_widget(stickynotes->prefs, "font_label"), FALSE); - gtk_widget_set_sensitive(stickynotes->w_prefs_font, FALSE); + if (!gconf_client_key_is_writable (stickynotes->gconf, + GCONF_PATH "/defaults/color", NULL)) + { + gtk_widget_set_sensitive (glade_xml_get_widget ( + stickynotes->prefs, "color_label"), + FALSE); + gtk_widget_set_sensitive (stickynotes->w_prefs_color, FALSE); } - if (!gconf_client_key_is_writable(stickynotes->gconf, GCONF_PATH "/settings/use_system_font", NULL)) - gtk_widget_set_sensitive(stickynotes->w_prefs_sys_font, FALSE); - if (!gconf_client_key_is_writable(stickynotes->gconf, GCONF_PATH "/settings/click_behavior", NULL)) { - gtk_widget_set_sensitive(glade_xml_get_widget(stickynotes->prefs, "click_label"), FALSE); - gtk_widget_set_sensitive(stickynotes->w_prefs_click, FALSE); + if (!gconf_client_key_is_writable (stickynotes->gconf, + GCONF_PATH "/settings/use_system_color", NULL)) + gtk_widget_set_sensitive (stickynotes->w_prefs_sys_color, + FALSE); + if (!gconf_client_key_is_writable (stickynotes->gconf, + GCONF_PATH "/defaults/font", NULL)) + { + gtk_widget_set_sensitive (glade_xml_get_widget ( + stickynotes->prefs, "font_label"), + FALSE); + gtk_widget_set_sensitive (stickynotes->w_prefs_font, FALSE); } - if (!gconf_client_key_is_writable(stickynotes->gconf, GCONF_PATH "/settings/sticky", NULL)) - gtk_widget_set_sensitive(stickynotes->w_prefs_sticky, FALSE); - if (!gconf_client_key_is_writable(stickynotes->gconf, GCONF_PATH "/settings/force_default", NULL)) - gtk_widget_set_sensitive(stickynotes->w_prefs_force, FALSE); + if (!gconf_client_key_is_writable (stickynotes->gconf, + GCONF_PATH "/settings/use_system_font", NULL)) + gtk_widget_set_sensitive (stickynotes->w_prefs_sys_font, + FALSE); + if (!gconf_client_key_is_writable (stickynotes->gconf, + GCONF_PATH "/settings/sticky", NULL)) + gtk_widget_set_sensitive (stickynotes->w_prefs_sticky, FALSE); + if (!gconf_client_key_is_writable (stickynotes->gconf, + GCONF_PATH "/settings/force_default", NULL)) + gtk_widget_set_sensitive (stickynotes->w_prefs_force, FALSE); stickynotes_applet_update_prefs(); } @@ -292,6 +325,10 @@ StickyNotesApplet * stickynotes_applet_new(PanelApplet *panel_applet) applet->prelighted = FALSE; applet->pressed = FALSE; + applet->popup_menu = NULL; + applet->menu_tip = NULL; + applet->menu_show = NULL; + /* Expand the applet for Fitts' law complience. */ panel_applet_set_flags(panel_applet, PANEL_APPLET_EXPAND_MINOR); @@ -428,9 +465,6 @@ void stickynotes_applet_update_prefs(void) gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(stickynotes->w_prefs_sys_font), sys_font); - gtk_option_menu_set_history ( - GTK_OPTION_MENU (stickynotes->w_prefs_click), - click_behavior); gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (stickynotes->w_prefs_sticky), sticky); @@ -495,40 +529,34 @@ void stickynotes_applet_update_menus(void) } } -void stickynotes_applet_update_tooltips(void) +void +stickynotes_applet_update_tooltips (void) { - gint num = g_list_length(stickynotes->notes); - gchar *tooltip = g_strdup_printf(ngettext("%s\n%d note", "%s\n%d notes", num), _("Sticky Notes"), num); + int i; + int num; + char *tooltip, *no_notes; + StickyNotesApplet *applet; + GList *l; + + num = g_list_length (stickynotes->notes); + + no_notes = g_strdup_printf (ngettext ("%d note", "%d notes", num), num); + tooltip = g_strdup_printf ("%s\n%s", _("Sticky Notes"), no_notes); - gint i; - for (i = 0; i < g_list_length(stickynotes->applets); i++) { - StickyNotesApplet *applet = g_list_nth_data(stickynotes->applets, i); - gtk_tooltips_set_tip(stickynotes->tooltips, applet->w_applet, tooltip, NULL); + for (l = stickynotes->applets; l; l = l->next) + { + applet = l->data; + gtk_tooltips_set_tip (stickynotes->tooltips, + applet->w_applet, tooltip, NULL); + + if (applet->menu_tip) + gtk_label_set_text (GTK_LABEL (gtk_bin_get_child ( + GTK_BIN (applet->menu_tip))), + no_notes); + if (applet->menu_show) + gtk_widget_set_sensitive (applet->menu_show, num); } - g_free(tooltip); -} - -void stickynotes_applet_do_default_action(GdkScreen *screen) -{ - StickyNotesDefaultAction click_behavior = gconf_client_get_int(stickynotes->gconf, GCONF_PATH "/settings/click_behavior", NULL); - - gboolean visible = gconf_client_get_bool(stickynotes->gconf, GCONF_PATH "/settings/visible", NULL); - gboolean locked = gconf_client_get_bool(stickynotes->gconf, GCONF_PATH "/settings/locked", NULL); - - switch (click_behavior) { - case STICKYNOTES_NEW: - stickynotes_add(screen); - break; - - case STICKYNOTES_SET_VISIBLE: - if (gconf_client_key_is_writable(stickynotes->gconf, GCONF_PATH "/settings/visible", NULL)) - gconf_client_set_bool(stickynotes->gconf, GCONF_PATH "/settings/visible", !visible, NULL); - break; - - case STICKYNOTES_SET_LOCKED: - if (gconf_client_key_is_writable(stickynotes->gconf, GCONF_PATH "/settings/locked", NULL)) - gconf_client_set_bool(stickynotes->gconf, GCONF_PATH "/settings/locked", !locked, NULL); - break; - } + g_free (tooltip); + g_free (no_notes); } diff --git a/stickynotes/stickynotes_applet.h b/stickynotes/stickynotes_applet.h index e19df2393..b0ddb8df1 100644 --- a/stickynotes/stickynotes_applet.h +++ b/stickynotes/stickynotes_applet.h @@ -48,7 +48,6 @@ typedef struct GtkWidget *w_prefs_sys_color; GtkWidget *w_prefs_font; GtkWidget *w_prefs_sys_font; - GtkWidget *w_prefs_click; GtkWidget *w_prefs_sticky; GtkWidget *w_prefs_force; @@ -60,7 +59,6 @@ typedef struct GConfClient *gconf; /* GConf Client */ GtkTooltips *tooltips; /* Tooltips */ - } StickyNotes; /* Sticky Notes Icons */ @@ -85,7 +83,10 @@ typedef struct gint panel_size; PanelAppletOrient panel_orient; - + + GtkWidget *popup_menu; /* Popup Menu */ + GtkWidget *menu_tip; + GtkWidget *menu_show; } StickyNotesApplet; typedef enum diff --git a/stickynotes/stickynotes_applet_callbacks.c b/stickynotes/stickynotes_applet_callbacks.c index 8033f2761..c8b2b2441 100644 --- a/stickynotes/stickynotes_applet_callbacks.c +++ b/stickynotes/stickynotes_applet_callbacks.c @@ -23,34 +23,173 @@ #include <libgnome/gnome-help.h> -/* Applet Callback : Mouse button press on the applet. */ -gboolean applet_button_cb(GtkWidget *widget, GdkEventButton *event, StickyNotesApplet *applet) +static void +position_menu (GtkMenu *menu, gint *x, gint *y, + gboolean *push_in, gpointer user_data) { - if (event->type == GDK_BUTTON_PRESS && event->button == 1) - applet->pressed = TRUE; + GtkWidget *widget = GTK_WIDGET (user_data); + GdkScreen *screen; + gint twidth, theight, tx, ty; + GtkTextDirection direction; + GdkRectangle monitor; + gint monitor_num; + + g_return_if_fail (menu != NULL); + g_return_if_fail (x != NULL); + g_return_if_fail (y != NULL); + + if (push_in) *push_in = FALSE; + + direction = gtk_widget_get_direction (widget); + + twidth = GTK_WIDGET (menu)->requisition.width; + theight = GTK_WIDGET (menu)->requisition.height; - else if (event->type == GDK_BUTTON_RELEASE && event->button == 1) { - stickynotes_applet_do_default_action(gtk_widget_get_screen(applet->w_applet)); - applet->pressed = FALSE; + screen = gtk_widget_get_screen (GTK_WIDGET (menu)); + monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window); + if (monitor_num < 0) monitor_num = 0; + gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor); + + if (!gdk_window_get_origin (widget->window, &tx, &ty)) { + g_warning ("Menu not on screen"); + return; } + tx += widget->allocation.x; + ty += widget->allocation.y; + + if (direction == GTK_TEXT_DIR_RTL) + tx += widget->allocation.width - twidth; + + if ((ty + widget->allocation.height + theight) <= + monitor.y + monitor.height) + ty += widget->allocation.height; + else if ((ty - theight) >= monitor.y) + ty -= theight; + else if (monitor.y + monitor.height - + (ty + widget->allocation.height) > ty) + ty += widget->allocation.height; else - return FALSE; + ty -= theight; + + *x = CLAMP (tx, monitor.x, + MAX (monitor.x, monitor.x + monitor.width - twidth)); + *y = ty; + gtk_menu_set_monitor (menu, monitor_num); +} - stickynotes_applet_update_icon(applet); +static void +popup_add_note (StickyNotesApplet *applet, GtkWidget *item) +{ + g_print ("popup_add_note()\n"); + stickynotes_add (gtk_widget_get_screen (applet->w_applet)); +} + +static void +popup_toggle_show_notes (StickyNotesApplet *applet, GtkWidget *item) +{ + gboolean visible; - return TRUE; + g_print ("popup_toggle_show_notes()\n"); + + visible = gconf_client_get_bool (stickynotes->gconf, + GCONF_PATH "/settings/visible", NULL); + if (gconf_client_key_is_writable (stickynotes->gconf, + GCONF_PATH "/settings/visible", NULL)) + gconf_client_set_bool (stickynotes->gconf, + GCONF_PATH "/settings/visible", !visible, NULL); } -/* Applet Callback : Keypress on the applet. */ -gboolean applet_key_cb(GtkWidget *widget, GdkEventKey *event, StickyNotesApplet *applet) +static void +stickynote_applet_ensure_popup (StickyNotesApplet *applet) { - if (event->type == GDK_KEY_PRESS && event->keyval == GDK_Return) - stickynotes_applet_do_default_action(gtk_widget_get_screen(applet->w_applet)); - else - return FALSE; + GtkWidget *item; + GtkWidget *image; + + if (applet->popup_menu) + return; + + applet->popup_menu = gtk_menu_new (); + + /* menu item - no# notes */ + item = gtk_menu_item_new_with_label ("???"); + applet->menu_tip = item; + gtk_widget_set_sensitive (item, FALSE); + gtk_widget_show (item); + gtk_container_add (GTK_CONTAINER (applet->popup_menu), item); + + /* separator */ + item = gtk_separator_menu_item_new (); + gtk_widget_show (item); + gtk_container_add (GTK_CONTAINER (applet->popup_menu), item); - return TRUE; + /* menu item - New Note */ + item = gtk_image_menu_item_new_with_mnemonic (_("_New Note")); + image = gtk_image_new_from_stock (GTK_STOCK_NEW, GTK_ICON_SIZE_MENU); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); + g_signal_connect_swapped (item, "activate", + G_CALLBACK (popup_add_note), applet); + gtk_widget_show (image); + gtk_widget_show (item); + gtk_container_add (GTK_CONTAINER (applet->popup_menu), item); + + /* menu item - Show Notes */ + item = gtk_check_menu_item_new_with_mnemonic (_("_Show Notes")); + applet->menu_show = item; + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), + gconf_client_get_bool (stickynotes->gconf, + GCONF_PATH "/settings/visible", NULL)); + g_signal_connect_swapped (item, "toggled", + G_CALLBACK (popup_toggle_show_notes), applet); + gtk_widget_show (item); + gtk_container_add (GTK_CONTAINER (applet->popup_menu), item); + + stickynotes_applet_update_tooltips (); +} + +/* Applet Callback : Mouse button press on the applet. */ +gboolean +applet_button_cb (GtkWidget *widget, + GdkEventButton *event, + StickyNotesApplet *applet) +{ + if (event->button == 1) + { + stickynote_applet_ensure_popup (applet); + if (applet->popup_menu) + { + gtk_menu_popup (GTK_MENU (applet->popup_menu), + NULL, NULL, + position_menu, applet->w_applet, + event->button, event->time); + } + return TRUE; + } + return FALSE; +} + +/* Applet Callback : Keypress on the applet. */ +gboolean +applet_key_cb (GtkWidget *widget, + GdkEventKey *event, + StickyNotesApplet *applet) +{ + switch (event->keyval) + { + case GDK_KP_Space: + case GDK_space: + case GDK_KP_Enter: + case GDK_Return: + stickynote_applet_ensure_popup (applet); + if (applet->popup_menu) { + gtk_menu_popup (GTK_MENU (applet->popup_menu), + NULL, NULL, + position_menu, applet->w_applet, + 0, event->time); + } + return TRUE; + } + return FALSE; } /* Applet Callback : Cross (enter or leave) the applet. */ @@ -315,7 +454,6 @@ void preferences_save_cb(gpointer data) gint height = gtk_adjustment_get_value(stickynotes->w_prefs_height); gboolean sys_color = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stickynotes->w_prefs_sys_color)); gboolean sys_font = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stickynotes->w_prefs_sys_font)); - gint click_behavior = gtk_option_menu_get_history(GTK_OPTION_MENU(stickynotes->w_prefs_click)); gboolean sticky = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stickynotes->w_prefs_sticky)); gboolean force_default = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(stickynotes->w_prefs_force)); @@ -327,8 +465,6 @@ void preferences_save_cb(gpointer data) gconf_client_set_bool(stickynotes->gconf, GCONF_PATH "/settings/use_system_color", sys_color, NULL); if (gconf_client_key_is_writable(stickynotes->gconf, GCONF_PATH "/settings/use_system_font", NULL)) gconf_client_set_bool(stickynotes->gconf, GCONF_PATH "/settings/use_system_font", sys_font, NULL); - if (gconf_client_key_is_writable(stickynotes->gconf, GCONF_PATH "/settings/click_behavior", NULL)) - gconf_client_set_int(stickynotes->gconf, GCONF_PATH "/settings/click_behavior", click_behavior, NULL); if (gconf_client_key_is_writable(stickynotes->gconf, GCONF_PATH "/settings/sticky", NULL)) gconf_client_set_bool(stickynotes->gconf, GCONF_PATH "/settings/sticky", sticky, NULL); if (gconf_client_key_is_writable(stickynotes->gconf, GCONF_PATH "/settings/force_default", NULL)) diff --git a/stickynotes/stickynotes_callbacks.c b/stickynotes/stickynotes_callbacks.c index a0023c695..1ee5159c7 100644 --- a/stickynotes/stickynotes_callbacks.c +++ b/stickynotes/stickynotes_callbacks.c @@ -70,10 +70,8 @@ gboolean stickynote_move_cb(GtkWidget *widget, GdkEventButton *event, StickyNote /* Sticky Window Callback : Skip taskbar and pager when exposing the widow */ gboolean stickynote_expose_cb(GtkWidget *widget, GdkEventExpose *event, StickyNote *note) { - /* gtk_window_set_skip_taskbar_hint(GTK_WINDOW(note->w_window), TRUE); gtk_window_set_skip_pager_hint(GTK_WINDOW(note->w_window), TRUE); - */ return FALSE; } diff --git a/stickynotes/util.c b/stickynotes/util.c index 0ef97066e..d7b0aad13 100644 --- a/stickynotes/util.c +++ b/stickynotes/util.c @@ -21,6 +21,12 @@ #include <time.h> #include <util.h> +#include <X11/Xlib.h> +#include <X11/Xatom.h> +#include <gtk/gtk.h> +#include <gdk/gdk.h> +#include <gdk/gdkx.h> + /* Returns the current date in a customizable form, the default * looks like this: "Nov 30, '78" */ gchar * get_current_date(const gchar *format) @@ -40,3 +46,106 @@ gchar * get_current_date(const gchar *format) return date; } + +#if 0 +/* These are some unrequired X functions that are instead being implemented * + * with libwnck. They are here just because I don't want to lose them */ +static Atom +xstuff_atom_get (const char *atom_name) +{ + static GHashTable *atom_hash; + Display *xdisplay; + Atom retval; + + g_return_val_if_fail (atom_name != NULL, None); + + xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); + + if (!atom_hash) + atom_hash = g_hash_table_new_full ( + g_str_hash, g_str_equal, g_free, NULL); + + retval = GPOINTER_TO_UINT (g_hash_table_lookup (atom_hash, atom_name)); + if (!retval) { + retval = XInternAtom (xdisplay, atom_name, FALSE); + + if (retval != None) + g_hash_table_insert (atom_hash, g_strdup (atom_name), + GUINT_TO_POINTER (retval)); + } + + return retval; +} + +int +xstuff_get_current_workspace (GtkWindow *window) +{ + Window root_window; + Atom type = None; + gulong nitems; + gulong bytes_after; + gulong *num; + int format; + int result; + int retval; + Display *gdk_display; + + root_window = GDK_WINDOW_XWINDOW (gdk_screen_get_root_window ( + gtk_widget_get_screen (GTK_WIDGET (window)))); + root_window = GDK_WINDOW_XWINDOW (GTK_WIDGET (window)->window); + gdk_display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); + + gdk_error_trap_push (); + result = XGetWindowProperty (gdk_display, + root_window, + xstuff_atom_get ("_NET_CURRENT_DESKTOP"), + 0, G_MAXLONG, + False, XA_CARDINAL, + &type, &format, &nitems, + &bytes_after, (gpointer) &num); + if (gdk_error_trap_pop () || result != Success) + return -1; + + if (type != XA_CARDINAL) { + XFree (num); + return -1; + } + + retval = *num; + + XFree (num); + + return retval; +} + +void +xstuff_change_workspace (GtkWindow *window, + int new_space) +{ + XEvent xev; + Window xwindow; + Display *gdk_display; + Screen *screen; + + gdk_display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); + xwindow = GDK_WINDOW_XWINDOW (GDK_WINDOW (GTK_WIDGET (window)->window)); + screen = GDK_SCREEN_XSCREEN (gtk_widget_get_screen (GTK_WIDGET (window))); + + xev.xclient.type = ClientMessage; + xev.xclient.serial = 0; + xev.xclient.send_event = True; + xev.xclient.display = gdk_display; + xev.xclient.window = xwindow; + xev.xclient.message_type = _wnck_atom_get ("_NET_WM_DESKTOP"); + xev.xclient.format = 32; + xev.xclient.data.l[0] = new_space; + xev.xclient.data.l[1] = 0; + xev.xclient.data.l[2] = 0; + + XSendEvent (gdk_display, + RootWindowOfScreen (screen), + False, + SubstructureRedirectMask | SubstructureNotifyMask, + &xev); +} +#endif diff --git a/stickynotes/util.h b/stickynotes/util.h index 786b29fa5..6ffe823af 100644 --- a/stickynotes/util.h +++ b/stickynotes/util.h @@ -21,7 +21,11 @@ #define __UTIL_H__ #include <glib.h> +#include <gtk/gtk.h> gchar * get_current_date(const gchar *format); +void xstuff_change_workspace (GtkWindow *window, + int new_space); +int xstuff_get_current_workspace (GtkWindow *window); #endif /* #ifndef __UTIL_H__ */ |