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 "applet-struct.h"
24
#include "applet-composite.h"
26
static void (*s_activate_composite) (gboolean) = NULL;
32
static void _set_metacity_composite (gboolean bActive)
36
r = system ("gconftool-2 -s '/apps/metacity/general/compositing_manager' --type bool true");
38
r = system ("gconftool-2 -s '/apps/metacity/general/compositing_manager' --type bool false");
40
cd_warning ("Not able to launch this command: gconftool-2");
43
static void _set_xfwm_composite (gboolean bActive)
47
r = system ("xfconf-query -c xfwm4 -p '/general/use_compositing' -t 'bool' -s 'true'");
49
r = system ("xfconf-query -c xfwm4 -p '/general/use_compositing' -t 'bool' -s 'false'");
51
cd_warning ("Not able to launch this command: gconftool-2");
54
static void _set_kwin_composite (gboolean bActive)
58
r = system ("[ \"$(qdbus org.kde.kwin /KWin compositingActive)\" == \"false\" ] && qdbus org.kde.kwin /KWin toggleCompositing"); // not active, so activating
60
r = system ("[ \"$(qdbus org.kde.kwin /KWin compositingActive)\" == \"true\" ] && qdbus org.kde.kwin /KWin toggleCompositing"); // active, so deactivating
62
cd_warning ("Not able to launch this command: gconftool-2");
65
///////////////////////
66
/// Welcome message ///
67
///////////////////////
69
static void cd_help_show_welcome_message (void)
71
cairo_dock_show_dialog_full (D_("Welcome in Cairo-Dock !\n"
72
"This applet is here to help you start using the dock; just click on it.\n"
73
"If you have any question/request/remark, please pay us a visit at http://glx-dock.org.\n"
74
"Hope you will enjoy this soft !\n"
75
" (you can now click on this dialog to close it)"),
79
NULL, NULL, NULL, NULL);
80
myData.bFirstLaunch = FALSE;
83
////////////////////////
84
/// Composite dialog ///
85
////////////////////////
87
static inline void _cancel_wm_composite (void)
89
s_activate_composite (FALSE);
91
static void _accept_wm_composite (int iClickedButton, G_GNUC_UNUSED GtkWidget *pInteractiveWidget, gpointer data, G_GNUC_UNUSED CairoDialog *pDialog)
93
cd_debug ("%s (%d)", __func__, iClickedButton);
94
if (iClickedButton == 1 || iClickedButton == -2) // clic explicite sur "cancel", ou Echap ou auto-delete.
96
_cancel_wm_composite ();
98
gboolean *bAccepted = data;
99
*bAccepted = TRUE; // l'utilisateur a valide son choix.
101
static void _on_free_wm_dialog (gpointer data)
103
gboolean *bAccepted = data;
104
cd_debug ("%s (%d)", __func__, *bAccepted);
105
if (! *bAccepted) // le dialogue s'est detruit sans que l'utilisateur n'ait valide la question => on annule tout.
107
_cancel_wm_composite ();
111
if (myData.bFirstLaunch)
113
cd_help_show_welcome_message ();
117
static void _toggle_remember_choice (GtkCheckButton *pButton, GtkWidget *pDialog)
119
g_object_set_data (G_OBJECT (pDialog), "remember", GINT_TO_POINTER (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pButton))));
122
static void _on_free_info_dialog (G_GNUC_UNUSED gpointer data)
124
if (myData.bFirstLaunch)
126
cd_help_show_welcome_message ();
130
///////////////////////
131
/// Check composite ///
132
///////////////////////
134
void cd_help_enable_composite (void)
136
// find the current WM.
137
s_activate_composite = NULL;
138
gchar *cPsef = cairo_dock_launch_command_sync ("pgrep metacity"); // 'ps | grep' ne marche pas, il faut le lancer dans un script :-/
139
cd_debug ("cPsef: '%s'", cPsef);
140
if (cPsef != NULL && *cPsef != '\0')
142
s_activate_composite = _set_metacity_composite;
146
cPsef = cairo_dock_launch_command_sync ("pgrep xfwm");
147
if (cPsef != NULL && *cPsef != '\0')
149
s_activate_composite = _set_xfwm_composite;
153
cPsef = cairo_dock_launch_command_sync ("pgrep kwin");
154
if (cPsef != NULL && *cPsef != '\0')
156
s_activate_composite = _set_kwin_composite;
161
// if the WM can handle the composite, ask the user if he wants to enable it.
162
if (s_activate_composite != NULL) // the WM can activate the composite.
164
GtkWidget *pAskBox = _gtk_hbox_new (3);
165
GtkWidget *label = gtk_label_new (D_("Don't ask me any more"));
166
cairo_dock_set_dialog_widget_text_color (label);
167
GtkWidget *pCheckBox = gtk_check_button_new ();
168
gtk_box_pack_end (GTK_BOX (pAskBox), pCheckBox, FALSE, FALSE, 0);
169
gtk_box_pack_end (GTK_BOX (pAskBox), label, FALSE, FALSE, 0);
170
g_signal_connect (G_OBJECT (pCheckBox), "toggled", G_CALLBACK(_toggle_remember_choice), pAskBox);
171
int iClickedButton = cairo_dock_show_dialog_and_wait (D_("To remove the black rectangle around the dock, you need to activate a composite manager.\nDo you want to activate it now?"), myIcon, myContainer, NULL, pAskBox);
173
gboolean bRememberChoice = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pCheckBox));
174
gtk_widget_destroy (pAskBox); // le widget survit a un dialogue bloquant.
175
if (bRememberChoice) // if not ticked, we'll check the composite on the next startup, and if it's ok, we'll not check it any more.
177
myData.bTestComposite = FALSE;
179
if (iClickedButton == 0 || iClickedButton == -1) // ok or Enter.
181
s_activate_composite (TRUE);
182
cairo_dock_show_dialog_full (D_("Do you want to keep this setting?\nIn 15 seconds, the previous setting will be restored."),
187
(CairoDockActionOnAnswerFunc) _accept_wm_composite,
188
g_new0 (gboolean, 1),
189
(GFreeFunc)_on_free_wm_dialog);
191
else if (myData.bFirstLaunch)
193
cd_help_show_welcome_message ();
196
else // just notify him about the problem and its solution.
198
cairo_dock_show_dialog_full (D_("To remove the black rectangle around the dock, you will need to activate a composite manager.\nFor instance, this can be done by activating desktop effects, launching Compiz, or activating the composition in Metacity.\nIf your machine can't support composition, Cairo-Dock can emulate it. This option is in the 'System' module of the configuration, at the bottom of the page."),
205
(GFreeFunc)_on_free_info_dialog);
210
static gboolean cd_help_check_composite (G_GNUC_UNUSED gpointer data)
212
GdkScreen *pScreen = gdk_screen_get_default ();
213
if (! gdk_screen_is_composited (pScreen)) // no composite yet.
215
cd_debug ("no composite (%d)", myData.iNbTestComposite);
216
myData.iNbTestComposite ++;
217
if (myData.iNbTestComposite < 4) // check during 4 seconds.
220
cd_help_enable_composite ();
222
else // composite is active, but we don't remember this parameter, since it could change if another session is used one day.
224
if (myData.bFirstLaunch)
226
cd_help_show_welcome_message ();
230
// remember if we don't need to check the composite any more.
231
if (! myData.bTestComposite)
233
gchar *cConfFilePath = g_strdup_printf ("%s/.help", g_cCairoDockDataDir);
234
cairo_dock_update_conf_file (cConfFilePath,
235
G_TYPE_BOOLEAN, "Launch", "test composite", myData.bTestComposite,
237
g_free (cConfFilePath);
239
myData.iSidTestComposite = 0;
243
gboolean cd_help_get_params (G_GNUC_UNUSED gpointer data)
246
gchar *cConfFilePath = g_strdup_printf ("%s/.help", g_cCairoDockDataDir);
247
if (g_file_test (cConfFilePath, G_FILE_TEST_EXISTS)) // file already exists, get the latest state.
249
GKeyFile *pKeyFile = cairo_dock_open_key_file (cConfFilePath);
250
if (pKeyFile != NULL)
252
myData.iLastTipGroup = g_key_file_get_integer (pKeyFile, "Last Tip", "group", NULL);
253
myData.iLastTipKey = g_key_file_get_integer (pKeyFile, "Last Tip", "key", NULL);
254
myData.bTestComposite = g_key_file_get_boolean (pKeyFile, "Launch", "test composite", NULL);
256
g_key_file_free (pKeyFile);
259
else // no file, means it's the first time we are launched.
261
myData.bFirstLaunch = TRUE;
262
myData.bTestComposite = TRUE;
264
// create the file with all the entries
265
cairo_dock_update_conf_file (cConfFilePath,
266
G_TYPE_BOOLEAN, "Launch", "test composite", myData.bTestComposite,
267
G_TYPE_INT, "Last Tip", "group", myData.iLastTipGroup,
268
G_TYPE_INT, "Last Tip", "key", myData.iLastTipKey,
272
// test the composite for a few seconds (the Composite Manager may not be active yet).
273
if (myData.bTestComposite && ! myContainersParam.bUseFakeTransparency)
275
myData.iSidTestComposite = g_timeout_add_seconds (1, cd_help_check_composite, NULL);
277
else if (myData.bFirstLaunch)
279
cd_help_show_welcome_message ();
282
g_free (cConfFilePath);
283
myData.iSidGetParams = 0;