Add support to disable event sound made by libcanberra-gtk-module.
authorHong Jen Yee (PCMan) <pcman.tw@gmail.com>
Fri, 30 Jul 2010 15:24:14 +0000 (23:24 +0800)
committerHong Jen Yee (PCMan) <pcman.tw@gmail.com>
Fri, 30 Jul 2010 15:24:14 +0000 (23:24 +0800)
src/lxappearance2.c
src/lxappearance2.h
src/other.c

index a7128fe..42ed5e9 100644 (file)
@@ -118,6 +118,11 @@ static void reload_all_programs()
     gdk_event_send_clientmessage_toall((GdkEvent *)&event);
 }
 
+static const char* bool2str(gboolean val)
+{
+    return val ? "TRUE" : "FALSE";
+}
+
 static void lxappearance_save_gtkrc()
 {
     static const char* tb_styles[]={
@@ -147,6 +152,10 @@ static void lxappearance_save_gtkrc()
         "gtk-toolbar-icon-size=%s\n"
         "gtk-cursor-theme-name=\"%s\"\n"
         "gtk-cursor-theme-size=%d\n"
+#if GTK_CHECK_VERSION(2, 14, 0)
+        "gtk-enable-event-sounds=%s\n"
+        "gtk-enable-input-feedback-sounds=%s\n"
+#endif
         "include \"%s/.gtkrc-2.0.mine\"\n",
         app.widget_theme,
         app.icon_theme,
@@ -155,6 +164,10 @@ static void lxappearance_save_gtkrc()
         tb_icon_sizes[app.toolbar_icon_size],
         app.cursor_theme,
         app.cursor_theme_size,
+#if GTK_CHECK_VERSION(2, 14, 0)
+        bool2str(app.enable_event_sound),
+        bool2str(app.enable_input_feedback),
+#endif
         g_get_home_dir());
 
     g_file_set_contents(file_path, content, -1, NULL);
@@ -196,6 +209,15 @@ static void lxappearance_save_lxsession()
     g_key_file_set_integer( kf, "GTK", "iGtk/ToolbarStyle", app.toolbar_style );
     g_key_file_set_integer( kf, "GTK", "iGtk/ToolbarIconSize", app.toolbar_icon_size );
 
+#if GTK_CHECK_VERSION(2, 14, 0)
+    g_key_file_set_integer( kf, "GTK", "iGtk/ToolbarStyle", app.toolbar_style );
+    g_key_file_set_integer( kf, "GTK", "iGtk/ToolbarIconSize", app.toolbar_icon_size );
+
+    /* "Net/SoundThemeName\0"      "gtk-sound-theme-name\0" */
+    g_key_file_set_integer( kf, "GTK", "iNet/EnableEventSounds", app.enable_event_sound);
+    g_key_file_set_integer( kf, "GTK", "iNet/EnableInputFeedbackSounds", app.enable_input_feedback);
+#endif
+
     buf = g_key_file_to_data( kf, &len, NULL );
     g_key_file_free(kf);
 
@@ -248,6 +270,10 @@ static void settings_init()
                 "gtk-cursor-theme-size", &app.cursor_theme_size,
                 "gtk-toolbar-style", &app.toolbar_style,
                 "gtk-toolbar-icon-size", &app.toolbar_icon_size,
+#if GTK_CHECK_VERSION(2, 14, 0)
+                "gtk-enable-event-sounds", &app.enable_event_sound,
+                "gtk-enable-input-feedback-sounds", &app.enable_input_feedback,
+#endif
                 NULL);
     /* try to figure out cursor theme used. */
     if(!app.cursor_theme || g_strcmp0(app.cursor_theme, "default") == 0)
index b2af84b..d9e9373 100644 (file)
@@ -56,6 +56,14 @@ struct _LXAppearance
     char* icon_sizes;
     int toolbar_style;
     int toolbar_icon_size;
+
+#if GTK_CHECK_VERSION(2, 14, 0)
+    GtkWidget* event_sound_check;
+    GtkWidget* input_feedback_check;
+    gboolean enable_event_sound;
+    gboolean enable_input_feedback;
+#endif
+
     gboolean changed;
     gboolean use_lxsession;
 };
index d94bec6..a7bd7eb 100644 (file)
@@ -34,6 +34,17 @@ static void on_tb_icon_size_changed(GtkComboBox* combo, gpointer user_data)
     lxappearance_changed();
 }
 
+static void on_check_button_toggled(GtkToggleButton* btn, gpointer user_data)
+{
+    gboolean* val = (gboolean*)user_data;
+    gboolean new_val = gtk_toggle_button_get_active(btn);
+    if(new_val != *val)
+    {
+        *val = new_val;
+        lxappearance_changed();
+    }
+}
+
 void other_init(GtkBuilder* b)
 {
     int idx;
@@ -46,5 +57,18 @@ void other_init(GtkBuilder* b)
     idx = app.toolbar_icon_size - GTK_ICON_SIZE_MENU;
     gtk_combo_box_set_active(GTK_COMBO_BOX(app.tb_icon_size_combo), idx);
     g_signal_connect(app.tb_icon_size_combo, "changed", G_CALLBACK(on_tb_icon_size_changed), NULL);
+
+#if GTK_CHECK_VERSION(2, 14, 0)
+    app.event_sound_check = GTK_WIDGET(gtk_builder_get_object(b, "event_sound"));
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(app.event_sound_check), app.enable_event_sound);
+    g_signal_connect(app.event_sound_check, "toggled", G_CALLBACK(on_check_button_toggled), &app.enable_event_sound);
+
+    app.input_feedback_check = GTK_WIDGET(gtk_builder_get_object(b, "input_feedback_sound"));
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(app.input_feedback_check), app.enable_input_feedback);
+    g_signal_connect(app.input_feedback_check, "toggled", G_CALLBACK(on_check_button_toggled), &app.enable_input_feedback);
+
+    /* event sound support */
+    gtk_widget_show_all(GTK_WIDGET(gtk_builder_get_object(b, "sound_effect")));
+#endif
 }