2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 3
10
* of the License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
#include "cairo-dock-struct.h"
24
#include "cairo-dock-gui-backend.h"
25
#include "implementations/cairo-dock-compiz-integration.h"
26
#include "applet-struct.h"
27
#include "applet-tips-dialog.h"
28
#include "applet-composite.h"
29
#include "applet-notifications.h"
31
#define CAIRO_DOCK_WIKI_URL "http://wiki.glx-dock.org" // it's in French if the locale is FR with Firefox. If not, the user can choose its language.
32
#define CD_UNITY_COMPIZ_PLUGIN "unityshell"
35
//\___________ Define here the action to be taken when the user left-clicks on your icon or on its subdock or your desklet. The icon and the container that were clicked are available through the macros CD_APPLET_CLICKED_ICON and CD_APPLET_CLICKED_CONTAINER. CD_APPLET_CLICKED_ICON may be NULL if the user clicked in the container but out of icons.
36
CD_APPLET_ON_CLICK_BEGIN
37
if (myData.iSidGetParams == 0 && myData.iSidTestComposite == 0) // if we're testing the composite, don't pop up a dialog that could disturb the composite dialog.
38
cairo_dock_show_tips ();
40
CD_APPLET_ON_CLICK_END
43
//\___________ Same as ON_CLICK, but with middle-click.
44
CD_APPLET_ON_MIDDLE_CLICK_BEGIN
45
cairo_dock_show_main_gui ();
47
CD_APPLET_ON_MIDDLE_CLICK_END
51
//\___________ Define here the entries you want to add to the menu when the user right-clicks on your icon or on its subdock or your desklet. The icon and the container that were clicked are available through the macros CD_APPLET_CLICKED_ICON and CD_APPLET_CLICKED_CONTAINER. CD_APPLET_CLICKED_ICON may be NULL if the user clicked in the container but out of icons. The menu where you can add your entries is available throught the macro CD_APPLET_MY_MENU; you can add sub-menu to it if you want.
52
static void _cd_show_config (G_GNUC_UNUSED GtkMenuItem *menu_item, G_GNUC_UNUSED gpointer data)
54
cairo_dock_show_main_gui ();
57
static void _cd_show_help_gui (G_GNUC_UNUSED GtkMenuItem *menu_item, G_GNUC_UNUSED gpointer data)
59
cairo_dock_show_items_gui (myIcon, myContainer, myApplet, -1);
62
static void _launch_url (const gchar *cURL)
64
if (! cairo_dock_fm_launch_uri (cURL))
66
gchar *cCommand = g_strdup_printf ("\
67
which xdg-open > /dev/null && xdg-open \"%s\" & || \
68
which firefox > /dev/null && firefox \"%s\" & || \
69
which konqueror > /dev/null && konqueror \"%s\" & || \
70
which iceweasel > /dev/null && iceweasel \"%s\" & || \
71
which chromium-browser > /dev/null && chromium-browser \"%s\" & || \
72
which midori > /dev/null && midori \"%s\" & || \
73
which epiphany > /dev/null && epiphany \"%s\" & || \
74
which opera > /dev/null && opera \"%s\" &",
82
cURL); // not very nice but it works ^_^
83
int r = system (cCommand);
85
cd_warning ("Not able to launch this command: %s", cCommand);
89
static void _cd_show_help_online (G_GNUC_UNUSED GtkMenuItem *menu_item, G_GNUC_UNUSED gpointer data)
91
_launch_url (CAIRO_DOCK_WIKI_URL);
94
static gboolean _is_gnome_panel_running (void) // only for Gnome2
96
gboolean bResult = FALSE;
97
gchar *cWhich = cairo_dock_launch_command_sync ("which gconftool-2");
98
if (cWhich != NULL && *cWhich == '/')
100
gchar *cPanel = cairo_dock_launch_command_sync ("gconftool-2 -g '/desktop/gnome/session/required_components/panel'");
101
if (cPanel && strcmp (cPanel, "gnome-panel") == 0)
109
static void _cd_remove_gnome_panel (G_GNUC_UNUSED GtkMenuItem *menu_item, G_GNUC_UNUSED gpointer data)
111
int r = system ("gconftool-2 -s '/desktop/gnome/session/required_components/panel' --type string \"\"");
113
cd_warning ("Not able to launch this command: gconftool-2");
116
static void _on_got_active_plugins (DBusGProxy *proxy, DBusGProxyCall *call_id, G_GNUC_UNUSED gpointer data)
118
cd_debug ("%s ()", __func__);
119
// get the active plug-ins.
120
GError *error = NULL;
121
gchar **plugins = NULL;
122
dbus_g_proxy_end_call (proxy,
130
cd_warning ("compiz got active plug-ins error: %s", error->message);
131
g_error_free (error);
134
g_return_if_fail (plugins != NULL);
136
// look for the 'Unity' plug-in.
137
gboolean bFound = FALSE;
139
for (i = 0; plugins[i] != NULL; i++)
141
cd_debug ("Compiz Plugin: %s", plugins[i]);
142
if (strcmp (plugins[i], CD_UNITY_COMPIZ_PLUGIN) == 0)
149
// if present, remove it from the list and send it back to Compiz.
152
g_free (plugins[i]); // remove this entry
155
for (;plugins[i] != NULL; i++) // move all other entries after it to the left.
157
plugins[i-1] = plugins[i];
160
/** dbus_g_proxy_call (proxy,
166
G_TYPE_INVALID); // It seems it doesn't work with dbus_g_proxy_call_no_reply() and Compiz-0.9 (compiz (core) - Warn: Can't set Value with type 12 to option "active_plugins" with type 11 (with dbus-send too...) => it may be better with dbus_g_proxy_call(), at least maybe we can get a more comprehensive error message. if nothing works, we should report a bug to Compiz.
167
// it's a known bug in Compiz (https://bugs.launchpad.net/ubuntu/+source/compiz/+bug/749084)
170
cd_warning ("compiz activate plug-ins error: %s", error->message);
171
g_error_free (error);
174
gchar *cPluginsList = g_strjoinv (",", plugins);
175
cd_debug ("Compiz Plugins List: %s", cPluginsList);
176
cairo_dock_launch_command_printf ("bash "MY_APPLET_SHARE_DATA_DIR"/scripts/help_scripts.sh \"compiz_new_replace_list_plugins\" \"%s\"",
179
int r = system ("killall unity-panel-service"); // to have the main gtk menu back.
181
cd_warning ("Not able to launch this command: killall");
182
g_free (cPluginsList);
184
else // should not happen since we detect Unity before proposing this action.
186
cd_warning ("Unity is already disabled.");
188
g_strfreev (plugins);
191
static void _cd_remove_unity (G_GNUC_UNUSED GtkMenuItem *menu_item, G_GNUC_UNUSED gpointer data)
193
// first get the active plug-ins.
194
DBusGProxy *pActivePluginsProxy = cairo_dock_create_new_session_proxy (
196
CD_COMPIZ_OBJECT"/core/screen0/active_plugins", // this code runs for Compiz > 0.9 only.
197
CD_COMPIZ_INTERFACE);
199
dbus_g_proxy_begin_call (pActivePluginsProxy,
201
(DBusGProxyCallNotify) _on_got_active_plugins,
205
///g_object_unref (pActivePluginsProxy);
208
static gboolean _is_unity_running (void)
210
// Compiz < 0.9 can't have Unity.
211
if (! cd_is_the_new_compiz ())
212
return FALSE; // it's just to not have useless warning (but it will launch 'compiz --version' command)
214
// get the list of active plug-ins
215
// (we can't use dbus_g_proxy_begin_call(), because we need the answer now, to know if we'll add an entry in the menu or not. We could modify the menu afterwards, but that seems unnecessarily complicated.
216
gboolean bIsPresent = FALSE;
218
DBusGProxy *pActivePluginsProxy = cairo_dock_create_new_session_proxy (
220
CD_COMPIZ_OBJECT"/core/screen0/active_plugins", // this code runs for Compiz > 0.9 only.
221
CD_COMPIZ_INTERFACE);
223
gchar **plugins = NULL;
225
dbus_g_proxy_call (pActivePluginsProxy, "get", &erreur,
227
G_TYPE_STRV, &plugins,
232
cd_warning (erreur->message);
233
g_error_free (erreur);
234
g_object_unref (pActivePluginsProxy);
238
g_return_val_if_fail (plugins != NULL, FALSE);
240
// look for the 'Unity' plug-in.
242
for (i = 0; plugins[i] != NULL; i++)
244
cd_debug ("Compiz Plugin: %s", plugins[i]);
245
if (strcmp (plugins[i], CD_UNITY_COMPIZ_PLUGIN) == 0)
252
g_strfreev (plugins);
253
g_object_unref (pActivePluginsProxy);
258
CD_APPLET_ON_BUILD_MENU_BEGIN
259
gchar *cLabel = g_strdup_printf ("%s (%s)", D_("Open global settings"), D_("middle-click"));
260
CD_APPLET_ADD_IN_MENU_WITH_STOCK (cLabel, GTK_STOCK_PREFERENCES, _cd_show_config, CD_APPLET_MY_MENU);
262
GdkScreen *pScreen = gdk_screen_get_default ();
263
if (! gdk_screen_is_composited (pScreen))
264
CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Activate composite"), GTK_STOCK_EXECUTE, cd_help_enable_composite, CD_APPLET_MY_MENU);
265
if (_is_gnome_panel_running ())
266
CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Disable the gnome-panel"), GTK_STOCK_REMOVE, _cd_remove_gnome_panel, CD_APPLET_MY_MENU);
267
if (_is_unity_running ())
268
CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Disable Unity"), GTK_STOCK_REMOVE, _cd_remove_unity, CD_APPLET_MY_MENU);
269
CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Help"), GTK_STOCK_HELP, _cd_show_help_gui, CD_APPLET_MY_MENU);
270
CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Online help"), GTK_STOCK_HELP, _cd_show_help_online, CD_APPLET_MY_MENU);
271
CD_APPLET_ON_BUILD_MENU_END