summaryrefslogtreecommitdiff
path: root/simple-ccsm-enable-desktop-effects.patch
blob: 4763ed63e789d6286318e7a6047a2e46bde1d906 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
From a9248818957ed0cc3e903e016767da7f260cbe1e Mon Sep 17 00:00:00 2001
From: Patrick Niklaus <marex@opencompositing.org>
Date: Sun, 11 May 2008 20:00:25 +0200
Subject: [PATCH] Added enable desktop effects button

Use simple-ccsm to handle enabling compiz and asking the user for overrides, when needed.
---
 simple-ccsm.desktop |    5 +-
 simple-ccsm.glade   |   73 +++++++++++++++++++++-----------
 simple-ccsm.in      |  116 +++++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 164 insertions(+), 30 deletions(-)

diff --git a/simple-ccsm.desktop b/simple-ccsm.desktop
index 76c64e0..7847e8d 100644
--- a/simple-ccsm.desktop
+++ b/simple-ccsm.desktop
@@ -1,9 +1,10 @@
 [Desktop Entry]
 Encoding=UTF-8
-Name=Simple CompizConfig Settings Manager
-Comment=Configure Compiz with CompizConfig
+Name=Desktop Effects
+Comment=Configure Compiz desktop effects
 Icon=simple-ccsm
 Exec=simple-ccsm
 Terminal=false
 Type=Application
 Categories=Compiz;Settings;DesktopSettings;
+StartupNotify=true
diff --git a/simple-ccsm.glade b/simple-ccsm.glade
index 5916537..19e8315 100644
--- a/simple-ccsm.glade
+++ b/simple-ccsm.glade
@@ -13,50 +13,73 @@
         <property name="border_width">10</property>
         <property name="spacing">12</property>
         <child>
-          <widget class="GtkHBox" id="hbox3">
+          <widget class="GtkVBox" id="vbox2">
             <property name="visible">True</property>
-            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-            <property name="spacing">5</property>
-            <child>
-              <widget class="GtkLabel" id="label11">
-                <property name="visible">True</property>
-                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                <property name="label" translatable="yes">Profil:</property>
-              </widget>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-              </packing>
-            </child>
+            <property name="spacing">12</property>
             <child>
-              <widget class="GtkComboBox" id="profileChooser">
+              <widget class="GtkCheckButton" id="enableEffects">
                 <property name="visible">True</property>
-                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                <property name="label" translatable="yes">_Enable desktop effects</property>
+                <property name="use_underline">True</property>
+                <property name="response_id">0</property>
+                <property name="draw_indicator">True</property>
               </widget>
               <packing>
-                <property name="position">1</property>
+                <property name="padding">3</property>
               </packing>
             </child>
             <child>
-              <widget class="GtkButton" id="applyButton">
+              <widget class="GtkHBox" id="hbox1">
                 <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
                 <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                <property name="response_id">0</property>
-                <signal name="clicked" handler="ApplyProfile"/>
+                <property name="spacing">5</property>
                 <child>
-                  <widget class="GtkImage" id="image5">
+                  <widget class="GtkLabel" id="label1">
                     <property name="visible">True</property>
                     <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                    <property name="stock">gtk-apply</property>
+                    <property name="label" translatable="yes">Profile:</property>
                   </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkComboBox" id="profileChooser">
+                    <property name="visible">True</property>
+                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                  </widget>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkButton" id="applyButton">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                    <property name="response_id">0</property>
+                    <signal name="clicked" handler="ApplyProfile"/>
+                    <child>
+                      <widget class="GtkImage" id="image1">
+                        <property name="visible">True</property>
+                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                        <property name="stock">gtk-apply</property>
+                      </widget>
+                    </child>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">2</property>
+                  </packing>
                 </child>
               </widget>
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">False</property>
-                <property name="position">2</property>
+                <property name="position">1</property>
               </packing>
             </child>
           </widget>
diff --git a/simple-ccsm.in b/simple-ccsm.in
index b743a57..c90d13d 100755
--- a/simple-ccsm.in
+++ b/simple-ccsm.in
@@ -134,6 +134,12 @@ AnimationSettings = {
 'minimizeAnimationBox': "minimize_effects"
 }
 
+CompizName = "compiz"
+# Change to your default
+CompizStartCommand = "compiz-manager --replace"
+CompizDryRunCommand = "CM_DRY=yes compiz-manager"
+CompizNoChecksCommand = "SKIP_CHECKS=yes compiz-manager"
+
 # Utility Functions
 def EnablePlugin(plugin, active):
     # attempt to resolve conflicts...
@@ -862,7 +868,7 @@ class MainWin:
             notebook.set_current_page (Pages[page])
 
         # Window
-        window = self.GladeXML.get_widget("mainWin")
+        self.Window = self.GladeXML.get_widget("mainWin")
 
         # Icon
         theme = gtk.icon_theme_get_default()
@@ -871,7 +877,12 @@ class MainWin:
             theme.load_icon("simple-ccsm", 32, 0),
             theme.load_icon("simple-ccsm", 48, 0),
         )
-        window.set_icon_list(*iconList)
+        self.Window.set_icon_list(*iconList)
+
+        # Enable effects button
+        self.EnableEffectsButton = self.GladeXML.get_widget("enableEffects")
+        self.EnableEffectsButton.connect ("toggled", self.EnableDesktopEffectsChanged)
+        self.Notebook = self.GladeXML.get_widget("notebook")
 
         # Profile Chooser
         self.ProfileChooser = self.GladeXML.get_widget("profileChooser")
@@ -885,10 +896,28 @@ class MainWin:
         self.EdgePage      = EdgePage(self.Context, self.GladeXML)
 
         self.Update()
-        window.show_all()
+        self.Window.show_all()
+
+    def CheckForCompiz(self):
+        composited = self.Window.is_composited()
+        if composited:
+            # Now do the dirty work - check if it is really Compiz
+            psCMD = "ps -e".split(" ")
+            ps = subprocess.Popen(psCMD, stdout=subprocess.PIPE)
+            grepCMD = "grep compiz".split(" ")
+            grep = subprocess.Popen(grepCMD, stdin=ps.stdout, stdout=subprocess.PIPE)
+            grep.wait()
+            lines = grep.stdout.readlines()
+            for l in lines:
+                name = l.replace("\n", "").split(" ")[-1]
+                if name == CompizName:
+                    return True
+
+        return False
 
     def Update(self):
         self.Context.Read()
+        self.Block += 1
 
         self.AnimationPage.Update()
         self.EffectPage.Update()
@@ -898,6 +927,87 @@ class MainWin:
         self.EdgePage.Update()
 
         self.SetProfile()
+        self.SetEnableDesktopEffects()
+
+        self.Block -= 1
+
+    def SetEnableDesktopEffects(self):
+        running = self.CheckForCompiz()
+        self.EnableEffectsButton.set_active(running)
+        self.Notebook.set_sensitive(running)
+        self.ProfileChooser.set_sensitive(running)
+
+    def EnableDesktopEffectsChanged(self, widget):
+        if self.Block > 0:
+            return
+
+        enabled = self.EnableEffectsButton.get_active()
+        if enabled:
+            # First try to check if compiz can be run
+            cmd = CompizDryRunCommand.split(" ")
+            proc = subprocess.Popen(cmd, shell=True)
+            proc.wait()
+            if proc.returncode != 0:
+                # Dry run detected problems, warn the user
+                dialog = gtk.Dialog ()
+                dialog.set_title("Error")
+                dialog.set_border_width(6)
+                label = gtk.Label(_("Desktop effects are not supported on your current hardware / configuration. Would you like to cancel enabling of desktop effects or run them anyway?"))
+                label.set_line_wrap(True)
+                dialog.vbox.pack_start(label,
+                                       gtk.TRUE,
+                                       gtk.FALSE,
+                                       3)
+                dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
+                dialog.add_button("Run anyway", gtk.RESPONSE_OK)
+                dialog.show_all()
+                response = dialog.run()
+                dialog.destroy()
+                if response != gtk.RESPONSE_OK:
+                    self.EnableEffectsButton.set_active(False)
+                    return
+
+            # Make compiz manager skip further checks
+            path = os.path.expanduser("~/.config/compiz/compiz-manager")
+            hasSkip = False
+            try:
+                config = open(path, "r")
+                for l in config.readlines():
+                    if "SKIP_CHECKS" in l:
+                        hasSkip = True
+                        break
+                config.close()
+            except IOError, e:
+                print "No compiz manager config found!"
+                dir = os.path.expanduser("~/.config/compiz/")
+                if not os.path.exists(dir):
+                    os.makedirs(dir)
+            if not hasSkip:
+                config = open(path, "a")
+                config.write("SKIP_CHECKS=yes\n")
+                config.close()
+            # Start compiz
+            cmd = CompizStartCommand.split(" ")
+            subprocess.Popen(cmd)
+            # Enable compiz in kde
+            try:
+                 subprocess.call('kwriteconfig --file ksmserverrc --group General --key windowManager compiz'.split())
+            except (IOError, OSError):
+                 pass
+            # Create a file that indicates wether compiz is enabled or not
+            path = os.path.expanduser("~/.config/compiz/enable-compiz")
+            open(path, "w+").close() # touch replacement
+        else:
+            cmd = "metacity --replace".split(" ")
+            subprocess.Popen(cmd)
+            # Remove old config
+            files = ("~/.config/compiz/enable-compiz", "~/.config/compiz/compiz-manager")
+            for file in files:
+                path = os.path.expanduser(file)
+                os.remove(path)
+
+        self.Notebook.set_sensitive(enabled)
+        self.ProfileChooser.set_sensitive(enabled)
 
     def OpenAdvanced(self, widget):
         notebook = self.GladeXML.get_widget("notebook")
-- 
1.5.4.3