~ubuntu-branches/ubuntu/saucy/cairo-dock-plug-ins/saucy

« back to all changes in this revision

Viewing changes to compiz-icon/src/applet-compiz.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2009-08-26 21:07:39 UTC
  • Revision ID: james.westby@ubuntu.com-20090826210739-gyjuuqezrzuluao4
Tags: upstream-2.0.8.1
Import upstream version 2.0.8.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
* This file is a part of the Cairo-Dock project
 
3
*
 
4
* Copyright : (C) see the 'copyright' file.
 
5
* E-mail    : see the 'copyright' file.
 
6
*
 
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.
 
11
*
 
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/>.
 
18
*/
 
19
 
 
20
/******************************************************************************
 
21
 
 
22
This file is a part of the cairo-dock program, 
 
23
released under the terms of the GNU General Public License.
 
24
 
 
25
Written by Rémy Robertson (for any bug report, please mail me to changfu@cairo-dock.org)
 
26
Fabrice Rey <fabounet@users.berlios.de>
 
27
 
 
28
******************************************************************************/
 
29
#define _BSD_SOURCE
 
30
#include <string.h>
 
31
#include <stdlib.h>
 
32
#include <stdio.h>
 
33
#include <unistd.h>
 
34
#include <glib/gstdio.h>
 
35
#include <cairo-dock.h>
 
36
 
 
37
#include "applet-struct.h"
 
38
#include "applet-load-icon.h"
 
39
#include "applet-compiz.h"
 
40
 
 
41
 
 
42
//static char  *s_cTmpFile = NULL;
 
43
 
 
44
void cd_compiz_start_system_wm (void) {
 
45
        const gchar * cCommand = NULL;
 
46
        if (myConfig.cUserWMCommand != NULL) {
 
47
                cCommand = myConfig.cUserWMCommand;
 
48
        }
 
49
        else {
 
50
                switch (g_iDesktopEnv) {
 
51
                        case CAIRO_DOCK_GNOME :
 
52
                        case CAIRO_DOCK_XFCE :
 
53
                                cCommand = "metacity --replace";
 
54
                        break;
 
55
                        case CAIRO_DOCK_KDE :
 
56
                                cCommand = "kwin --replace";
 
57
                        break ;
 
58
                        default :
 
59
                                cd_warning ("couldn't guess system WM");
 
60
                        return ;
 
61
                }
 
62
        }
 
63
        myData.bCompizRestarted = TRUE;
 
64
        cd_compiz_kill_compmgr(); //On tue tout les compositing managers
 
65
        
 
66
        cd_message ("Compiz - Run: %s ", cCommand);
 
67
        cairo_dock_launch_command (cCommand);
 
68
}
 
69
 
 
70
void cd_compiz_start_compiz (void) {
 
71
        GString *sCommand = g_string_new ("");
 
72
        
 
73
        gchar *cCompizBin = NULL; //On cherche
 
74
        if (g_file_test ("/usr/bin/compiz.real", G_FILE_TEST_EXISTS))
 
75
                cCompizBin = "compiz.real";
 
76
        else
 
77
                cCompizBin = "compiz";
 
78
                
 
79
        g_string_printf (sCommand, "%s --replace --ignore-desktop-hints ccp", cCompizBin);
 
80
        if (myConfig.lBinding) {
 
81
                g_string_append (sCommand, " --loose-binding");
 
82
        }
 
83
        if (myConfig.iRendering) {
 
84
                g_string_append (sCommand, " --indirect-rendering");
 
85
        }
 
86
        if (myConfig.uLocalScreen) {
 
87
         g_string_append (sCommand, " --only-current-screen");
 
88
        }
 
89
        
 
90
        if (strcmp (myConfig.cWindowDecorator, "emerald") != 0)
 
91
                g_string_append (sCommand, " --sm-disable");
 
92
        
 
93
        cd_debug ("%s (%s)", __func__, sCommand->str);
 
94
        
 
95
        myData.bCompizRestarted = TRUE;
 
96
        cd_compiz_kill_compmgr(); //On tue tout les compositing managers
 
97
        cairo_dock_launch_command (sCommand->str);
 
98
        
 
99
        g_string_free (sCommand, TRUE);
 
100
        
 
101
        cd_compiz_start_favorite_decorator ();
 
102
}
 
103
 
 
104
void cd_compiz_switch_manager(void) {
 
105
        cd_compiz_read_data ();
 
106
        if (myData.bAcquisitionOK) {
 
107
                if (myData.bCompizIsRunning)
 
108
                        cd_compiz_start_system_wm ();
 
109
                else
 
110
                        cd_compiz_start_compiz ();
 
111
        }
 
112
}
 
113
 
 
114
 
 
115
void cd_compiz_start_favorite_decorator (void) {
 
116
        cd_debug ("%s (%s)", __func__, myConfig.cWindowDecorator);
 
117
        gchar *cCommand = g_strdup_printf ("%s --replace", myConfig.cWindowDecorator);
 
118
        myData.bDecoratorRestarted = TRUE;
 
119
        cairo_dock_launch_command (cCommand);
 
120
        g_free (cCommand);
 
121
}
 
122
 
 
123
void cd_compiz_start_decorator (compizDecorator iDecorator) {
 
124
        cd_debug ("%s (%d)", __func__, iDecorator);
 
125
        g_return_if_fail (iDecorator >= 0 && iDecorator < COMPIZ_NB_DECORATORS && myConfig.cDecorators[iDecorator] != NULL);
 
126
        gchar *cCommand = g_strdup_printf ("%s --replace", myConfig.cDecorators[iDecorator]);
 
127
        myData.bDecoratorRestarted = TRUE;
 
128
        cairo_dock_launch_command (cCommand);
 
129
        g_free (cCommand);
 
130
}
 
131
 
 
132
void cd_compiz_kill_compmgr(void) {
 
133
        gchar *cCommand = g_strdup_printf("bash %s/compiz-kill", MY_APPLET_SHARE_DATA_DIR);
 
134
        int r = system (cCommand);
 
135
        g_free (cCommand);
 
136
}
 
137
 
 
138
 
 
139
void cd_compiz_read_data(void) {
 
140
        gchar *cCommand = g_strdup_printf("sh %s/compiz %s", MY_APPLET_SHARE_DATA_DIR, myConfig.cWindowDecorator);  // truc de ouf : sans le 'sh' devant ca renvoit toujours '10' !
 
141
        gchar *cResult = cairo_dock_launch_command_sync (cCommand);
 
142
        g_free (cCommand);
 
143
        if (cResult == NULL)
 
144
        {
 
145
                myData.bAcquisitionOK = FALSE;
 
146
                return ;
 
147
        }
 
148
        
 
149
        myData.bCompizIsRunning = (cResult[0] == '1');
 
150
        myData.bDecoratorIsRunning = (cResult[0] != '\0' && cResult[1] == '1');
 
151
        //g_print ("compiz : '%s' => %d/%d\n", standard_output, myData.bCompizIsRunning, myData.bDecoratorIsRunning);
 
152
        myData.bAcquisitionOK = TRUE;
 
153
}
 
154
 
 
155
gboolean cd_compiz_update_from_data (void) {
 
156
        cd_compiz_update_main_icon ();
 
157
        cd_debug ("Compiz: %d - Decorator: %d", myData.bCompizIsRunning, myData.bDecoratorIsRunning);
 
158
        if (! myData.bCompizIsRunning && myConfig.bAutoReloadCompiz) {
 
159
                if (! myData.bCompizRestarted) {
 
160
                        myData.bCompizRestarted = TRUE;  // c'est nous qui l'avons change.
 
161
                        cd_compiz_start_compiz ();  // relance compiz.
 
162
                }
 
163
        }
 
164
        if (! myData.bDecoratorIsRunning && myConfig.bAutoReloadDecorator) {
 
165
                if (! myData.bDecoratorRestarted) {
 
166
                        myData.bDecoratorRestarted = TRUE;  // c'est nous qui l'avons change.
 
167
                        cd_compiz_start_favorite_decorator (); // relance aussi le decorateur.
 
168
                }
 
169
        }
 
170
        
 
171
        if (myData.bCompizIsRunning)
 
172
                myData.bCompizRestarted = FALSE;  // Compiz tourne, on le relancera s'il plante.
 
173
        if (myData.bDecoratorIsRunning)
 
174
                myData.bDecoratorRestarted = FALSE;  // le decorateur tourne, on le relancera s'il plante.
 
175
        return myData.bAcquisitionOK;
 
176
}