~hypodermia/ubuntu/oneiric/compiz/fix-for-bug-301174

« back to all changes in this revision

Viewing changes to plugins/bell/src/bell.cpp

  • Committer: Emily Strickland
  • Date: 2011-06-15 04:52:00 UTC
  • Revision ID: emily@zubon.org-20110615045200-aqfclpzec14oaoja
Add 'bell' plugin and a small fix to bcop.xslt to properly trigger bell events (see http://cgit.compiz.org/compiz/core/commit/?id=e6afcfd735db5a9f507fb9cd810bdb139ab8480f); fixes https://bugs.launchpad.net/ubuntu/+source/compiz/+bug/301174 and https://bugs.launchpad.net/ubuntu/+source/unity/+bug/769314

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 *
 
3
 * Compiz bell plugin
 
4
 *
 
5
 * bell.c
 
6
 *
 
7
 * Copyright (c) 2011 Emily Strickland <emily@zubon.org>
 
8
 *
 
9
 * Authors:
 
10
 * Emily Strickland <emily@zubon.org>
 
11
 *
 
12
 * This program is free software; you can redistribute it and/or
 
13
 * modify it under the terms of the GNU General Public License
 
14
 * as published by the Free Software Foundation; either version 2
 
15
 * of the License, or (at your option) any later version.
 
16
 *
 
17
 * This program is distributed in the hope that it will be useful,
 
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
 * GNU General Public License for more details.
 
21
 *
 
22
 **/
 
23
 
 
24
#include "bell.h"
 
25
 
 
26
COMPIZ_PLUGIN_20090315 (bell, BellPluginVTable);
 
27
 
 
28
bool
 
29
AudibleBell::bell ()
 
30
{
 
31
    int error;
 
32
 
 
33
    if ((error = ca_context_play (mCanberraContext, 0,
 
34
                                  CA_PROP_EVENT_ID, "bell",
 
35
                                  CA_PROP_MEDIA_FILENAME, mFilename.c_str (),
 
36
                                  CA_PROP_CANBERRA_CACHE_CONTROL, "permanent",
 
37
                                  NULL)) < 0)
 
38
    {
 
39
        compLogMessage ("bell", CompLogLevelWarn, "couldn't play sound %s - %s",
 
40
                        mFilename.c_str (), ca_strerror (error));
 
41
    }
 
42
 
 
43
    /* Allow other plugins to handle bell event */
 
44
    return false;
 
45
}
 
46
 
 
47
void
 
48
AudibleBell::filenameChange(CompOption *option,
 
49
                            Options    num)
 
50
{
 
51
    int         error;
 
52
 
 
53
    mFilename = optionGetFilename();
 
54
 
 
55
    if ((error = ca_context_change_props  (mCanberraContext,
 
56
                                           CA_PROP_APPLICATION_NAME, "Compiz bell",
 
57
                                           CA_PROP_APPLICATION_ID, "org.freedesktop.compiz.Bell",
 
58
                                           CA_PROP_WINDOW_X11_SCREEN, screen->displayString(),
 
59
                                           NULL)) < 0)
 
60
    {
 
61
        compLogMessage ("bell", CompLogLevelWarn, "couldn't change context properties - %s",
 
62
                        ca_strerror (error));
 
63
    }
 
64
 
 
65
    if ((error = ca_context_cache (mCanberraContext,
 
66
                                   CA_PROP_EVENT_ID, "bell",
 
67
                                   CA_PROP_MEDIA_FILENAME, mFilename.c_str (),
 
68
                                   CA_PROP_CANBERRA_CACHE_CONTROL, "permanent",
 
69
                                   NULL)) < 0)
 
70
    {
 
71
        compLogMessage ("bell", CompLogLevelWarn, "couldn't change context cache - %s",
 
72
                        ca_strerror (error));
 
73
    }
 
74
}
 
75
 
 
76
 
 
77
AudibleBell::AudibleBell (CompScreen *screen) :
 
78
    PluginClassHandler <AudibleBell, CompScreen> (screen),
 
79
    mCanberraContext (NULL),
 
80
    mFilename (optionGetFilename ())
 
81
{
 
82
    int                                            error;
 
83
    boost::function <void (CompOption *, Options)> fileNameChangedCallback;
 
84
    boost::function <bool (CompAction *, CompAction::State, CompOption::Vector &)> bellCallback;
 
85
 
 
86
    if ((error = ca_context_create (&mCanberraContext)) < 0)
 
87
    {
 
88
        compLogMessage ("bell", CompLogLevelWarn, "couldn't initialize canberra - %s",
 
89
                        ca_strerror (error));
 
90
        setFailed ();
 
91
    }
 
92
    else
 
93
    {
 
94
        if ((error = ca_context_change_props (mCanberraContext,
 
95
                                      CA_PROP_APPLICATION_NAME,
 
96
                                      "Compiz bell plugin",
 
97
                                      CA_PROP_APPLICATION_ID,
 
98
                                      "org.freedesktop.compiz.Bell",
 
99
                                      CA_PROP_WINDOW_X11_SCREEN,
 
100
                                      screen->displayString (),
 
101
                                      NULL)) < 0)
 
102
        {
 
103
            compLogMessage ("bell", CompLogLevelWarn, "couldn't register bell handler - %s",
 
104
                            ca_strerror (error));
 
105
            setFailed ();
 
106
        }
 
107
        else
 
108
        {
 
109
            if ((error = ca_context_open (mCanberraContext)) < 0)
 
110
            {
 
111
                compLogMessage ("bell", CompLogLevelWarn, "couldn't open canberra context - %s",
 
112
                                ca_strerror (error));
 
113
                setFailed ();
 
114
            }
 
115
        }
 
116
    }
 
117
 
 
118
    fileNameChangedCallback =
 
119
        boost::bind (&AudibleBell::filenameChange, this, _1, _2);
 
120
    bellCallback =
 
121
        boost::bind (&AudibleBell::bell, this);
 
122
 
 
123
    optionSetFilenameNotify (fileNameChangedCallback);
 
124
    optionSetBellInitiate (bellCallback);
 
125
}
 
126
 
 
127
AudibleBell::~AudibleBell ()
 
128
{
 
129
    ca_context_destroy (mCanberraContext);
 
130
}
 
131
 
 
132
bool
 
133
BellPluginVTable::init ()
 
134
{
 
135
    if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION))
 
136
         return false;
 
137
 
 
138
    return true;
 
139
}