← Back to team overview

compiz team mailing list archive

[Merge] lp:~hypodermia/ubuntu/oneiric/compiz/fix-for-bug-301174 into lp:ubuntu/compiz

 

You have been requested to review the proposed merge of lp:~hypodermia/ubuntu/oneiric/compiz/fix-for-bug-301174 into lp:ubuntu/compiz.

For more details, see:
https://code.launchpad.net/~hypodermia/ubuntu/oneiric/compiz/fix-for-bug-301174/+merge/64632

This branch creates a new plugin which uses libcanberra to play an audible bell when the system bell action event is triggered, along with a small typo fix incorporated to make sure that action actually happens. For the typo fix to compiz core, see this commit log entry: http://cgit.compiz.org/compiz/core/commit/?id=e6afcfd735db5a9f507fb9cd810bdb139ab8480f

The original source code can be found in my Github repository here, along with smspillaz' merged changes: https://github.com/hypodermia/compiz-bell-plugin

This should fix this bug: https://bugs.launchpad.net/ubuntu/+source/compiz/+bug/301174

As well as this bug: https://bugs.launchpad.net/ubuntu/+source/unity/+bug/769314

To test this, build and install this plugin, install fixed compiz, replace compiz, load the plugin, and then run this to trigger the bell:  echo -n -e "\a"

Should cause a mild bell sound, provided the alert sounds in sound preferences are turned on and up and the sound file exists (configurable).

Adds a dependency on libcanberra. May require one further small change to make sure CMake finds and builds it, and may also add one dependency to ensure the default sound file is actually present on the system.

-- 
https://code.launchpad.net/~hypodermia/ubuntu/oneiric/compiz/fix-for-bug-301174/+merge/64632
Your team compiz packagers is requested to review the proposed merge of lp:~hypodermia/ubuntu/oneiric/compiz/fix-for-bug-301174 into lp:ubuntu/compiz.
=== added directory 'plugins/bell'
=== added file 'plugins/bell/CMakeLists.txt'
--- plugins/bell/CMakeLists.txt	1970-01-01 00:00:00 +0000
+++ plugins/bell/CMakeLists.txt	2011-06-15 05:37:24 +0000
@@ -0,0 +1,5 @@
+find_package (Compiz REQUIRED)
+
+include (CompizPlugin)
+
+compiz_plugin(bell PKGDEPS libcanberra)

=== added file 'plugins/bell/bell.xml.in'
--- plugins/bell/bell.xml.in	1970-01-01 00:00:00 +0000
+++ plugins/bell/bell.xml.in	2011-06-15 05:37:24 +0000
@@ -0,0 +1,27 @@
+<compiz>
+    <plugin name="bell" useBcop="true">
+        <_short>Audible Bell</_short>
+        <_long>Plays an audible sound for the system bell</_long>
+        <category>Utility</category>
+        <deps>
+            <relation type="after">
+                <plugin>composite</plugin>
+                <plugin>opengl</plugin>
+                <plugin>decor</plugin>
+            </relation>
+        </deps>
+        <options>
+            <option name="filename" type="string">
+		<_short>Bell sound file name</_short>
+		<_long>Name of file containing sound to play as bell</_long>
+		<default>/usr/share/sounds/ubuntu/stereo/bell.ogg</default>
+		<hints>file;</hints>
+	    </option>
+	    <option name="bell" type="bell">
+		<_short>Audible Bell</_short>
+		<_long>Play sound on system bell</_long>
+		<default>true</default>
+	    </option>
+	</options>
+    </plugin>
+</compiz>

=== added directory 'plugins/bell/src'
=== added file 'plugins/bell/src/bell.cpp'
--- plugins/bell/src/bell.cpp	1970-01-01 00:00:00 +0000
+++ plugins/bell/src/bell.cpp	2011-06-15 05:37:24 +0000
@@ -0,0 +1,139 @@
+/**
+ *
+ * Compiz bell plugin
+ *
+ * bell.c
+ *
+ * Copyright (c) 2011 Emily Strickland <emily@xxxxxxxxx>
+ *
+ * Authors:
+ * Emily Strickland <emily@xxxxxxxxx>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ **/
+
+#include "bell.h"
+
+COMPIZ_PLUGIN_20090315 (bell, BellPluginVTable);
+
+bool
+AudibleBell::bell ()
+{
+    int error;
+
+    if ((error = ca_context_play (mCanberraContext, 0,
+	                          CA_PROP_EVENT_ID, "bell",
+	                          CA_PROP_MEDIA_FILENAME, mFilename.c_str (),
+	                          CA_PROP_CANBERRA_CACHE_CONTROL, "permanent",
+	                          NULL)) < 0)
+    {
+        compLogMessage ("bell", CompLogLevelWarn, "couldn't play sound %s - %s",
+	                mFilename.c_str (), ca_strerror (error));
+    }
+
+    /* Allow other plugins to handle bell event */
+    return false;
+}
+
+void
+AudibleBell::filenameChange(CompOption *option,
+			    Options    num)
+{
+    int		error;
+
+    mFilename = optionGetFilename();
+
+    if ((error = ca_context_change_props  (mCanberraContext,
+					   CA_PROP_APPLICATION_NAME, "Compiz bell",
+					   CA_PROP_APPLICATION_ID, "org.freedesktop.compiz.Bell",
+					   CA_PROP_WINDOW_X11_SCREEN, screen->displayString(),
+					   NULL)) < 0)
+    {
+        compLogMessage ("bell", CompLogLevelWarn, "couldn't change context properties - %s",
+                        ca_strerror (error));
+    }
+
+    if ((error = ca_context_cache (mCanberraContext,
+                                   CA_PROP_EVENT_ID, "bell",
+                                   CA_PROP_MEDIA_FILENAME, mFilename.c_str (),
+                                   CA_PROP_CANBERRA_CACHE_CONTROL, "permanent",
+                                   NULL)) < 0)
+    {
+        compLogMessage ("bell", CompLogLevelWarn, "couldn't change context cache - %s",
+                        ca_strerror (error));
+    }
+}
+
+
+AudibleBell::AudibleBell (CompScreen *screen) :
+    PluginClassHandler <AudibleBell, CompScreen> (screen),
+    mCanberraContext (NULL),
+    mFilename (optionGetFilename ())
+{
+    int 					   error;
+    boost::function <void (CompOption *, Options)> fileNameChangedCallback;
+    boost::function <bool (CompAction *, CompAction::State, CompOption::Vector &)> bellCallback;
+
+    if ((error = ca_context_create (&mCanberraContext)) < 0)
+    {
+        compLogMessage ("bell", CompLogLevelWarn, "couldn't initialize canberra - %s",
+                        ca_strerror (error));
+        setFailed ();
+    }
+    else
+    {
+        if ((error = ca_context_change_props (mCanberraContext,
+                                      CA_PROP_APPLICATION_NAME,
+                                      "Compiz bell plugin",
+                                      CA_PROP_APPLICATION_ID,
+                                      "org.freedesktop.compiz.Bell",
+                                      CA_PROP_WINDOW_X11_SCREEN,
+                                      screen->displayString (),
+                                      NULL)) < 0)
+        {
+            compLogMessage ("bell", CompLogLevelWarn, "couldn't register bell handler - %s",
+                            ca_strerror (error));
+            setFailed ();
+        }
+        else
+        {
+            if ((error = ca_context_open (mCanberraContext)) < 0)
+            {
+                compLogMessage ("bell", CompLogLevelWarn, "couldn't open canberra context - %s",
+                                ca_strerror (error));
+                setFailed ();
+            }
+        }
+    }
+
+    fileNameChangedCallback =
+	boost::bind (&AudibleBell::filenameChange, this, _1, _2);
+    bellCallback =
+	boost::bind (&AudibleBell::bell, this);
+
+    optionSetFilenameNotify (fileNameChangedCallback);
+    optionSetBellInitiate (bellCallback);
+}
+
+AudibleBell::~AudibleBell ()
+{
+    ca_context_destroy (mCanberraContext);
+}
+
+bool
+BellPluginVTable::init ()
+{
+    if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION))
+         return false;
+
+    return true;
+}

=== added file 'plugins/bell/src/bell.h'
--- plugins/bell/src/bell.h	1970-01-01 00:00:00 +0000
+++ plugins/bell/src/bell.h	2011-06-15 05:37:24 +0000
@@ -0,0 +1,59 @@
+/**
+ *
+ * Compiz bell plugin
+ *
+ * bell.c
+ *
+ * Copyright (c) 2011 Emily Strickland <emily@xxxxxxxxx>
+ *
+ * Authors:
+ * Emily Strickland <emily@xxxxxxxxx>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ **/
+
+#include <core/core.h>
+#include <core/pluginclasshandler.h>
+
+#include <canberra.h>
+
+#include "bell_options.h"
+
+class AudibleBell :
+    public PluginClassHandler<AudibleBell, CompScreen>,
+    public ScreenInterface,
+    public BellOptions
+{
+    public:
+
+        AudibleBell (CompScreen *screen);
+        ~AudibleBell ();
+
+	bool bell ();
+
+    private:
+
+        ca_context *mCanberraContext;
+	CompString mFilename;
+	
+	void
+	filenameChange (CompOption *option,
+		        Options    num);
+};
+
+class BellPluginVTable :
+    public CompPlugin::VTableForScreen<AudibleBell>
+{
+    public:
+        bool init ();
+};
+

=== modified file 'xslt/bcop.xslt'
--- xslt/bcop.xslt	2011-02-24 17:31:29 +0000
+++ xslt/bcop.xslt	2011-06-15 05:37:24 +0000
@@ -563,7 +563,7 @@
         <xsl:param name="value"/>
         <xsl:text>    action = CompAction ();
 </xsl:text>
-        <xsl:text>    action.setState (state | CompAction::StateInitButton);
+        <xsl:text>    action.setState (state | CompAction::StateInitBell);
 </xsl:text>
         <xsl:if test="default/text() and default/text() = 'true'">
             <xsl:text>    action.setBell (true);