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");
41
static void _set_xfwm_composite (gboolean bActive)
45
r = system ("xfconf-query -c xfwm4 -p '/general/use_compositing' -t 'bool' -s 'true'");
47
r = system ("xfconf-query -c xfwm4 -p '/general/use_compositing' -t 'bool' -s 'false'");
50
static void _set_kwin_composite (gboolean bActive)
54
r = system ("[ \"$(qdbus org.kde.kwin /KWin compositingActive)\" == \"false\" ] && qdbus org.kde.kwin /KWin toggleCompositing"); // not active, so activating
56
r = system ("[ \"$(qdbus org.kde.kwin /KWin compositingActive)\" == \"true\" ] && qdbus org.kde.kwin /KWin toggleCompositing"); // active, so deactivating
59
///////////////////////
60
/// Welcome message ///
61
///////////////////////
63
static void cd_help_show_welcome_message (void)
65
cairo_dock_show_dialog_full (D_("Welcome in Cairo-Dock2 !\n"
66
"This applet is here to help you start using the dock; just click on it.\n"
67
"If you have any question/request/remark, please pay us a visit at http://glx-dock.org.\n"
68
"Hope you will enjoy this soft !\n"
69
" (you can now click on this dialog to close it)"),
73
NULL, NULL, NULL, NULL);
74
myData.bFirstLaunch = FALSE;
77
////////////////////////
78
/// Composite dialog ///
79
////////////////////////
81
static inline void _cancel_wm_composite (void)
83
s_activate_composite (FALSE);
85
static void _accept_wm_composite (int iClickedButton, GtkWidget *pInteractiveWidget, gpointer data, CairoDialog *pDialog)
87
cd_debug ("%s (%d)", __func__, iClickedButton);
88
if (iClickedButton == 1 || iClickedButton == -2) // clic explicite sur "cancel", ou Echap ou auto-delete.
90
_cancel_wm_composite ();
92
gboolean *bAccepted = data;
93
*bAccepted = TRUE; // l'utilisateur a valide son choix.
95
static void _on_free_wm_dialog (gpointer data)
97
gboolean *bAccepted = data;
98
cd_debug ("%s (%d)", __func__, *bAccepted);
99
if (! *bAccepted) // le dialogue s'est detruit sans que l'utilisateur n'ait valide la question => on annule tout.
101
_cancel_wm_composite ();
105
if (myData.bFirstLaunch)
107
cd_help_show_welcome_message ();
111
static void _toggle_remember_choice (GtkCheckButton *pButton, GtkWidget *pDialog)
113
g_object_set_data (G_OBJECT (pDialog), "remember", GINT_TO_POINTER (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pButton))));
116
static void _on_free_info_dialog (gpointer data)
118
if (myData.bFirstLaunch)
120
cd_help_show_welcome_message ();
124
///////////////////////
125
/// Check composite ///
126
///////////////////////
128
void cd_help_enable_composite (void)
130
// find the current WM.
131
s_activate_composite = NULL;
132
gchar *cPsef = cairo_dock_launch_command_sync ("pgrep metacity"); // 'ps | grep' ne marche pas, il faut le lancer dans un script :-/
133
g_print ("cPsef: '%s'\n", cPsef);
134
if (cPsef != NULL && *cPsef != '\0')
136
s_activate_composite = _set_metacity_composite;
140
cPsef = cairo_dock_launch_command_sync ("pgrep xfwm");
141
if (cPsef != NULL && *cPsef != '\0')
143
s_activate_composite = _set_xfwm_composite;
147
cPsef = cairo_dock_launch_command_sync ("pgrep kwin");
148
if (cPsef != NULL && *cPsef != '\0')
150
s_activate_composite = _set_kwin_composite;
155
// if the WM can handle the composite, ask the user if he wants to enable it.
156
if (s_activate_composite != NULL) // the WM can activate the composite.
158
Icon *pIcon = cairo_dock_get_dialogless_icon ();
159
GtkWidget *pAskBox = gtk_hbox_new (FALSE, 3);
160
GtkWidget *label = gtk_label_new (D_("Don't ask me any more"));
161
cairo_dock_set_dialog_widget_text_color (label);
162
GtkWidget *pCheckBox = gtk_check_button_new ();
163
gtk_box_pack_end (GTK_BOX (pAskBox), pCheckBox, FALSE, FALSE, 0);
164
gtk_box_pack_end (GTK_BOX (pAskBox), label, FALSE, FALSE, 0);
165
g_signal_connect (G_OBJECT (pCheckBox), "toggled", G_CALLBACK(_toggle_remember_choice), pAskBox);
166
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, 0., NULL, pAskBox);
168
gboolean bRememberChoice = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pCheckBox));
169
gtk_widget_destroy (pAskBox); // le widget survit a un dialogue bloquant.
170
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.
172
myData.bTestComposite = FALSE;
174
if (iClickedButton == 0 || iClickedButton == -1) // ok or Enter.
176
s_activate_composite (TRUE);
177
cairo_dock_show_dialog_full (D_("Do you want to keep this setting?\nIn 15 seconds, the previous setting will be restored."),
182
(CairoDockActionOnAnswerFunc) _accept_wm_composite,
183
g_new0 (gboolean, 1),
184
(GFreeFunc)_on_free_wm_dialog);
186
else if (myData.bFirstLaunch)
188
cd_help_show_welcome_message ();
191
else // just notify him about the problem and its solution.
193
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."),
200
(GFreeFunc)_on_free_info_dialog);
205
static gboolean cd_help_check_composite (gpointer data)
207
GdkScreen *pScreen = gdk_screen_get_default ();
208
if (! gdk_screen_is_composited (pScreen)) // no composite yet.
210
g_print ("no composite (%d)\n", myData.iNbTestComposite);
211
myData.iNbTestComposite ++;
212
if (myData.iNbTestComposite < 4) // check during 4 seconds.
215
cd_help_enable_composite ();
217
else // composite is active => everything is ok on startup => no need to test it in the future.
219
myData.bTestComposite = FALSE;
220
if (myData.bFirstLaunch)
222
cd_help_show_welcome_message ();
226
// remember to not test it any more.
227
if (! myData.bTestComposite)
229
gchar *cConfFilePath = g_strdup_printf ("%s/.help", g_cCairoDockDataDir);
230
cairo_dock_update_conf_file (cConfFilePath,
231
G_TYPE_BOOLEAN, "Launch", "test composite", myData.bTestComposite,
232
G_TYPE_INT, "Last Tip", "group", myData.iLastTipGroup,
233
G_TYPE_INT, "Last Tip", "key", myData.iLastTipKey,
234
G_TYPE_INVALID); // write the tip too, in case it creates the file.
235
g_free (cConfFilePath);
237
myData.iSidTestComposite = 0;
241
gboolean cd_help_get_params (gpointer data)
244
gchar *cConfFilePath = g_strdup_printf ("%s/.help", g_cCairoDockDataDir);
245
if (g_file_test (cConfFilePath, G_FILE_TEST_EXISTS)) // file already exists, get the last read tip.
247
GKeyFile *pKeyFile = cairo_dock_open_key_file (cConfFilePath);
248
if (pKeyFile != NULL)
250
myData.iLastTipGroup = g_key_file_get_integer (pKeyFile, "Last Tip", "group", NULL);
251
myData.iLastTipKey = g_key_file_get_integer (pKeyFile, "Last Tip", "key", NULL);
252
myData.bTestComposite = g_key_file_get_boolean (pKeyFile, "Launch", "test composite", NULL);
254
g_key_file_free (pKeyFile);
257
else // no file, means it's the first time we are launched.
259
myData.bFirstLaunch = TRUE;
260
myData.bTestComposite = TRUE;
263
// test the composite for a few seconds (the Composite Manager may not be active yet).
264
if (myData.bTestComposite && ! myContainersParam.bUseFakeTransparency)
266
myData.iSidTestComposite = g_timeout_add_seconds (1, cd_help_check_composite, NULL);
268
else if (myData.bFirstLaunch)
270
cd_help_show_welcome_message ();
273
g_free (cConfFilePath);
274
myData.iSidGetParams = 0;