/
mate-tweak
executable file
·1744 lines (1466 loc) · 84.1 KB
/
mate-tweak
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# Copyright (C) 2007-2014 by Clement Lefebvre <root@linuxmint.com>
# Copyright (C) 2015-2022 Martin Wimpress <code@ubuntu-mate.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
import argparse
import distro
import errno
import gettext
import getpass
import gi
import glob
import mmap
import os
import psutil
import setproctitle
import shutil
import signal
import subprocess
import sysconfig
import string
import sys
import time
from subprocess import DEVNULL, PIPE
from gi.repository import GLib
gi.require_version('Gdk', '3.0')
from gi.repository import Gdk
from gi.repository import GdkPixbuf
gi.require_version('GdkX11', '3.0')
from gi.repository import GdkX11
from gi.repository import Gio
from gi.repository import GObject
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
gi.require_version('Notify', '0.7')
from gi.repository import Notify
# Workaround introspection bug, gnome bug 622084
signal.signal(signal.SIGINT, signal.SIG_DFL)
__VERSION__ = '22.10.0'
__TILDA__ = """[Desktop Entry]
Name=Tilda
Exec=tilda
Icon=utilities-terminal
Terminal=false
Type=Application
Categories=GNOME;GTK;System;Utility;TerminalEmulator;
X-GNOME-Autostart-enabled=true
X-MATE-Autostart-enabled=true"""
__APPLET_SOUND__ = """[Desktop Entry]
Name=Volume Control
Comment=Show desktop volume control
Icon=multimedia-volume-control
Exec=mate-volume-control-applet
Terminal=false
Type=Application
Categories=AudioVideo;Mixer;Settings;HardwareSettings;
Keywords=MATE;volume;control;mixer;settings;sound;
NoDisplay=true
OnlyShowIn=MATE;
X-MATE-Bugzilla-Bugzilla=MATE
X-MATE-Bugzilla-Product=mate-media
X-MATE-Bugzilla-Component=mate-volume-control
# See http://bugzilla.gnome.org/show_bug.cgi?id=568320
#X-MATE-Autostart-Phase=Panel
X-MATE-Autostart-Notify=true
"""
__TRADITIONAL_BUTTONS__ = ":minimize,maximize,close"
__CONTEMPORARY_BUTTONS__ = "close,minimize,maximize:"
__MENU_TRADITIONAL_BUTTONS__ = "menu:minimize,maximize,close"
__MENU_CONTEMPORARY_BUTTONS__ = "close,minimize,maximize:menu"
# i18n
gettext.install('mate-tweak', os.path.join('/','usr','share','locale'))
class SidePage:
def __init__(self, notebook_index, name, icon):
self.notebook_index = notebook_index
self.name = name
self.icon = icon
class MateTweak:
system_installed_panel_layouts = []
def on_checkbox_toggled(self, widget, schema_id, key):
if (key == "reduced-resources"):
if ('marco' in self.current_wm):
marco_reduced = self.get_bool('org.mate.Marco.general', None, key)
if self.schema_has_key('org.mate.Marco.general','side-by-side-tiling'):
self.set_bool('org.mate.Marco.general', None, 'side-by-side-tiling', marco_reduced)
elif self.schema_has_key('org.mate.Marco.general','allow-tiling'):
self.set_bool('org.mate.Marco.general', None, 'allow-tiling', marco_reduced)
self.builder.get_object('checkbox_snapping').props.sensitive = marco_reduced
# If desktop icons are shown or hidden, enable or not further modifications
elif schema_id == "org.mate.background":
self.toggle_desktop_icons_sensitiveness()
def schema_has_key(self, schema, key):
source = Gio.SettingsSchemaSource.get_default()
if source.lookup(schema, True):
settings=Gio.Settings.new(schema)
schema = settings.get_property('settings-schema')
return schema.has_key(key)
else:
return False
def set_string(self, schema, path, key, value):
if path:
settings = Gio.Settings.new_with_path(schema, path)
else:
settings = Gio.Settings.new(schema)
try:
settings.set_string(key, value)
except:
print('Unable set ' + key + ' with ' + value + ' in ' + schema)
pass
def get_string(self, schema, path, key):
if path:
settings = Gio.Settings.new_with_path(schema, path)
else:
settings = Gio.Settings.new(schema)
return settings.get_string(key)
def get_int(self, schema, path, key):
if path:
settings = Gio.Settings.new_with_path(schema, path)
else:
settings = Gio.Settings.new(schema)
return settings.get_int(key)
def set_int(self, schema, path, key, value):
if path:
settings = Gio.Settings.new_with_path(schema, path)
else:
settings = Gio.Settings.new(schema)
settings.set_int(key, value)
def get_enum(self, schema, path, key):
if path:
settings = Gio.Settings.new_with_path(schema, path)
else:
settings = Gio.Settings.new(schema)
return settings.get_enum(key)
def set_enum(self, schema, path, key, value):
if path:
settings = Gio.Settings.new_with_path(schema, path)
else:
settings = Gio.Settings.new(schema)
settings.set_enum(key, value)
def get_bool(self, schema, path, key):
if path:
settings = Gio.Settings.new_with_path(schema, path)
else:
settings = Gio.Settings.new(schema)
return settings.get_boolean(key)
def set_bool(self, schema, path, key, value):
if path:
settings = Gio.Settings.new_with_path(schema, path)
else:
settings = Gio.Settings.new(schema)
settings.set_boolean(key, value)
def reset_dconf_path(self, path):
subprocess.call(['dconf', 'reset', '-f', path], stdout=DEVNULL, stderr=DEVNULL)
def set_dconf_value(self, path, value):
subprocess.call(['dconf', 'write', path, value], stdout=DEVNULL, stderr=DEVNULL)
def get_dconf_value(self, path):
dconf = subprocess.Popen(['dconf', 'read', path], stdin=PIPE, stdout=PIPE, stderr=PIPE)
dconf_output, dconf_error = dconf.communicate()
return dconf_output.decode().strip()
def init_checkbox(self, schema_id, key, name):
source = Gio.SettingsSchemaSource.get_default()
schema = source.lookup(schema_id, True)
if schema:
settings = Gio.Settings.new_full(schema)
widget = self.builder.get_object(name)
settings.bind(key, widget, "active", Gio.SettingsBindFlags.DEFAULT)
widget.connect("toggled", self.on_checkbox_toggled, schema_id, key)
def init_combobox(self, schema, key, name, default = False, data_type = str):
source = Gio.SettingsSchemaSource.get_default()
if source.lookup(schema, True) != None:
widget = self.builder.get_object(name)
if data_type is int:
conf = self.get_int(schema, None, key)
else:
conf = self.get_string(schema, None, key)
index = 0
default_index = None
for row in widget.get_model():
if default != None and default == row[1]:
default_index = index
if conf == row[1]:
widget.set_active(index)
default_index = None
break
index = index +1
if default_index != None:
widget.set_active(default_index)
widget.connect("changed", self.combo_fallback, schema, key, data_type)
def update_combobox(self, schema, key, name):
source = Gio.SettingsSchemaSource.get_default()
if source.lookup(schema, True) != None:
widget = self.builder.get_object(name)
conf = self.get_string(schema, None, key)
index = 0
for row in widget.get_model():
if(conf == row[1]):
widget.set_active(index)
break
index = index +1
def process_running(self, name):
uid = os.getuid()
for process in psutil.process_iter():
try:
proc = process.as_dict(attrs=['name', 'uids'])
except psutil.NoSuchProcess:
pass
else:
if name == proc['name'] and uid == proc['uids'].real:
return True
return False
def kill_process(self, name):
uid = os.getuid()
for process in psutil.process_iter():
try:
proc = process.as_dict(attrs=['name', 'pid', 'uids'])
except psutil.NoSuchProcess:
pass
else:
if name == proc['name'] and uid == proc['uids'].real:
try:
target = psutil.Process(proc['pid'])
target.terminate()
except psutil.NoSuchProcess:
pass
def find_on_path(self, command):
"""Is command on the executable search path?"""
if 'PATH' not in os.environ:
return False
path = os.environ['PATH']
for element in path.split(os.pathsep):
if not element:
continue
filename = os.path.join(element, command)
if os.path.isfile(filename) and os.access(filename, os.X_OK):
return True
return False
def mkdir_p(self, path):
try:
os.makedirs(path)
except OSError as exc: # Python >2.5
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else:
raise
def create_autostart(self, filename, content):
# Create a local autostart only if it is missing from the system path.
if not os.path.exists(os.path.join('/','usr','share','mate','autostart',filename)):
config_dir = GLib.get_user_config_dir()
self.mkdir_p(os.path.join(config_dir, 'autostart/'))
if not os.path.exists(os.path.join(config_dir, 'autostart',filename)):
with open(os.path.join(config_dir, 'autostart', filename),'w') as autostart:
autostart.write(content)
def remove_autostart(self, filename):
config_dir = GLib.get_user_config_dir()
autostart_file = os.path.join(config_dir, 'autostart', filename)
if os.path.exists(autostart_file):
os.remove(autostart_file)
# Make sure any system desktop files are also removed
mate_tweak_helper = os.path.join('/','usr', 'lib', 'mate-tweak', 'mate-tweak-helper')
subprocess.call(['pkexec', mate_tweak_helper, 'autostop', filename], stdout=DEVNULL, stderr=DEVNULL)
def check_wm_features(self):
screen = Gdk.Screen.get_default()
current_wm = GdkX11.X11Screen.get_window_manager_name(screen)
if ('Marco' in current_wm):
self.current_wm = 'marco'
composite_enabled = self.get_bool('org.mate.Marco.general', None, 'compositing-manager')
if self.process_running('picom'):
self.current_wm = self.get_string('org.mate.session.required-components', None, 'windowmanager')
elif not composite_enabled:
self.current_wm += '-no-composite'
elif ('Compiz' in current_wm):
self.current_wm = current_wm.lower()
else:
self.current_wm = 'Unknown'
print('Window Manager is: ' + self.current_wm)
self.compiz_capable = False
self.ccsm_capable = False
self.marco_capable = False
self.marco_picom_capable = False
self.marco_no_composite_capable = False
if self.find_on_path('compiz'):
if not self.software_rasterizer and self.texture_from_pixmap:
self.compiz_capable = True
if self.find_on_path('ccsm'):
self.ccsm_capable = True
if self.find_on_path('marco') and self.find_on_path('picom'):
if not self.software_rasterizer and self.texture_from_pixmap:
self.marco_picom_capable = True
if self.find_on_path('marco-no-composite') and self.find_on_path('marco'):
self.marco_no_composite_capable = True
if self.find_on_path('marco'):
self.marco_capable = True
def get_num_workspaces(self):
# Get the number of virtual workspaces from the current window manager
if 'marco' in self.current_wm:
num_workspaces = self.get_int('org.mate.Marco.general', None, 'num-workspaces')
elif 'compiz' in self.current_wm:
try:
num_workspaces = int(self.get_dconf_value('/org/compiz/profiles/mate/plugins/core/hsize'))
except:
num_workspaces = 0
else:
# If we can't detect the window manager assume 0 workspaces
num_workspaces = 0
print('Got ' + str(num_workspaces) + ' workspaces from ' + self.current_wm)
return num_workspaces
def replace_windowmanager(self, new_wm):
if new_wm == 'Unknown':
return
if new_wm == 'marco':
self.set_bool('org.mate.Marco.general', None, 'compositing-manager', True)
wm_params = '--composite'
elif new_wm == 'compiz':
wm_params = '--keep-desktop-hints'
else:
wm_params = ''
num_workspaces = self.get_num_workspaces()
# Don't make any change if workspaces is zero.
if num_workspaces != 0:
# Set the number of virtual workspaces for the new window manager
if 'marco' in new_wm:
self.set_int('org.mate.Marco.general', None, 'num-workspaces', num_workspaces)
elif 'compiz' in new_wm:
self.set_dconf_value('/org/compiz/profiles/mate/plugins/core/hsize', str(num_workspaces))
self.set_dconf_value('/org/compiz/profiles/mate/plugins/core/vsize', '1')
print('Set ' + str(num_workspaces) + ' workspaces for ' + new_wm)
# Make sure Compiz use the same theme as Marco to
# prevent theme/xcursor changes when switching themes.
if (new_wm == 'compiz'):
mate_theme = self.get_string('org.mate.interface', None, 'gtk-theme')
mate_cursor_theme = self.get_string('org.mate.peripherals-mouse', None, 'cursor-theme')
mate_cursor_size = self.get_int('org.mate.peripherals-mouse', None, 'cursor-size')
schemasource = Gio.SettingsSchemaSource.get_default()
gnome_desktop_schema = schemasource.lookup('org.gnome.desktop', False)
if gnome_desktop_schema:
self.set_string('org.gnome.desktop.wm.preferences', None, 'theme', mate_theme)
self.set_string('org.gnome.desktop.interface', None, 'cursor-theme', mate_cursor_theme)
self.set_int('org.gnome.desktop.interface', None, 'cursor-size', mate_cursor_size)
# metacity >= 3.20 - this schema may not be installed
metacity_schema = schemasource.lookup('org.gnome.metacity.theme', False)
if metacity_schema:
self.set_string('org.gnome.metacity.theme', None, 'name', mate_theme)
# FIXME! Don't assume 'metacity' is 1
self.set_enum('org.gnome.metacity.theme', None, 'type', 1)
# If switching away from a Compiz or Marco window manager kill the window manager
if 'compiz' in self.current_wm:
self.kill_process('compiz')
elif 'marco' in self.current_wm:
self.kill_process('marco')
# If switching away from a picom/compton compositor then kill the compositor
if ('xrender' in self.current_wm) or ('glx' in self.current_wm) or ('xr_glx_hybrid' in self.current_wm) or ('compton' in self.current_wm):
self.kill_process('compton')
self.kill_process('picom')
if ('xrender' in new_wm) or ('glx' in new_wm) or ('xr_glx_hybrid' in new_wm) or ('no-composite' in new_wm):
# Disable Marco's compositor when using a 3rd party compositor
self.set_bool('org.mate.Marco.general', None, 'compositing-manager', False)
subprocess.Popen([new_wm], stdout=DEVNULL, stderr=DEVNULL)
else:
wm_pid = subprocess.Popen([new_wm, '--replace', wm_params], stdout=DEVNULL, stderr=DEVNULL).pid
print(new_wm + ' is PID: ' + str(wm_pid))
# Update current_wm to the new one.
self.previous_wm = self.current_wm
self.current_wm = new_wm
self.builder.get_object("label_unknown_wm").hide()
Notify.init(_('MATE Tweak'))
replace_windowmanager_notify=Notify.Notification.new (_('Window Manager Replaced'),_('Your window manager has been replaced with ' + self.current_wm),'dialog-information')
replace_windowmanager_notify.show()
def enable_hud(self):
# Remove old-style autostart .desktop file for mate-hud
self.remove_autostart('mate-hud.desktop')
if self.hud_available and not self.process_running('mate-hud'):
if self.schema_has_key('org.mate.hud', 'enabled'):
self.set_bool('org.mate.hud', None, 'enabled', True)
pid = subprocess.Popen(['/usr/lib/mate-hud/mate-hud'], stdout=DEVNULL, stderr=DEVNULL).pid
self.hud_enabled = True
def disable_hud(self):
# Remove old-style autostart .desktop file for mate-hud
self.remove_autostart('mate-hud.desktop')
if self.schema_has_key('org.mate.hud', 'enabled'):
self.set_bool('org.mate.hud', None, 'enabled', False)
self.kill_process('mate-hud')
self.hud_enabled = False
def toggle_hud(self, checkbutton):
if checkbutton.get_active():
self.enable_hud()
else:
self.disable_hud()
def check_appmenu(self):
self.appmenu_available = False
if self.schema_has_key('org.mate.interface', 'gtk-shell-shows-menubar') \
and self.schema_has_key('org.appmenu.gtk-module','blacklist'):
self.appmenu_available = True
def maximus_decorate(self):
# Only decorate if currently undecorated
if self.get_bool('org.mate.maximus', None, 'undecorate'):
print('Decorating')
self.set_bool('org.mate.maximus', None, 'undecorate', False)
def maximus_undecorate(self):
# On undecorate if currently decorated
if not self.get_bool('org.mate.maximus', None, 'undecorate'):
print('Undecorating')
self.set_bool('org.mate.maximus', None, 'undecorate', True)
def enable_dock(self):
self.set_string('org.mate.session.required-components', None, 'dock', self.dock)
if self.dock:
self.remove_autostart(self.dock + '.desktop')
# Docks require compositing
schema = None
if self.current_wm == 'marco':
schema = 'org.mate.Marco.general'
elif 'compiz' in self.current_wm:
# https://bugs.launchpad.net/ubuntu-mate/+bug/1437611
self.set_bool('org.compiz.thumbnail', '/org/compiz/profiles/mate/plugins/thumbnail/', 'current-viewport', False)
if schema is not None:
compositor_enabled = self.get_bool(schema, None, 'compositing-manager')
if not compositor_enabled:
self.set_bool(schema, None, 'compositing-manager', True)
pid = subprocess.Popen([self.current_wm, '--replace'], stdout=DEVNULL, stderr=DEVNULL).pid
# Launch the dock, if it is not already enabled.
if not self.process_running(self.dock):
pid = subprocess.Popen([self.dock], stdout=DEVNULL, stderr=DEVNULL).pid
self.dock_enabled = True
def disable_dock(self):
if 'compiz' in self.current_wm:
# https://bugs.launchpad.net/ubuntu-mate/+bug/1437611
self.set_bool('org.compiz.thumbnail', '/org/compiz/profiles/mate/plugins/thumbnail/', 'current-viewport', True)
self.set_string('org.mate.session.required-components', None, 'dock', '')
if self.dock:
self.remove_autostart(self.dock + '.desktop')
self.kill_process(self.dock)
self.dock_enabled = False
def enable_keyboard_led(self):
self.keyboard_led_enabled = True
self.set_bool('org.mate.peripherals-keyboard-xkb.general', None, 'duplicate-leds', self.keyboard_led_enabled)
# Disabled as restart the settings-daemon and Caja is invasive and unreliable
# - https://pad.lv/1728715
#self.reload_settings_daemon()
#time.sleep(1)
#subprocess.call(['caja', '-q'], stdout=DEVNULL, stderr=DEVNULL)
def disable_keyboard_led(self):
self.keyboard_led_enabled = False
self.set_bool('org.mate.peripherals-keyboard-xkb.general', None, 'duplicate-leds', self.keyboard_led_enabled)
def enable_pulldown_terminal(self):
if self.pulldown_terminal == 'tilda':
self.create_autostart(self.pulldown_terminal + '.desktop', __TILDA__)
# Launch tilda, if it is not already enabled.
if not self.pulldown_terminal_enabled:
pid = subprocess.Popen([self.pulldown_terminal], stdout=DEVNULL, stderr=DEVNULL).pid
self.pulldown_terminal_enabled = True
def disable_pulldown_terminal(self):
if self.pulldown_terminal == 'tilda':
self.remove_autostart(self.pulldown_terminal + '.desktop')
if self.process_running(self.pulldown_terminal):
self.kill_process(self.pulldown_terminal)
self.pulldown_terminal_enabled = False
def disable_applets(self):
"""
When indicators are enabled some MATE applets need disabling
or hiding.
"""
self.kill_process('mate-volume-control-applet')
self.remove_autostart('mate-volume-control-applet.desktop')
if os.path.exists('/usr/libexec/ayatana-indicator-power/ayatana-indicator-power-service'):
self.set_string('org.mate.power-manager', None, 'icon-policy', 'never')
self.set_bool('org.mate.power-manager', None, 'notify-low-capacity', False)
# Remove the incorrectly named autostart file caused by an earlier bug.
# Note the double .desktop suffix.
self.remove_autostart('mate-volume-control-applet.desktop.desktop')
def enable_applets(self):
"""
When indicators are disabled some MATE applets need enabling
or showing.
"""
pid = subprocess.Popen(['mate-volume-control-applet'], stdout=DEVNULL, stderr=DEVNULL).pid
self.remove_autostart('mate-volume-control-applet.desktop')
self.create_autostart('mate-volume-control-applet.desktop', __APPLET_SOUND__)
if os.path.exists('/usr/libexec/ayatana-indicator-power/ayatana-indicator-power-service'):
self.set_string('org.mate.power-manager', None, 'icon-policy', 'present')
self.set_bool('org.mate.power-manager', None, 'notify-low-capacity', True)
# Remove the incorrectly named autostart file case by an earlier bug.
# Note the double .desktop suffix.
self.remove_autostart('mate-volume-control-applet.desktop.desktop')
def toggle_desktop_icons_sensitiveness(self):
sensitiveness = self.builder.get_object("checkbox_show_icons").get_active()
self.builder.get_object("caption_desktop_icons").set_sensitive(sensitiveness)
self.builder.get_object("checkbox_computer").set_sensitive(sensitiveness)
self.builder.get_object("checkbox_computer").set_sensitive(sensitiveness)
self.builder.get_object("checkbox_home").set_sensitive(sensitiveness)
self.builder.get_object("checkbox_network").set_sensitive(sensitiveness)
self.builder.get_object("checkbox_trash").set_sensitive(sensitiveness)
self.builder.get_object("checkbox_volumes").set_sensitive(sensitiveness)
def panel_layout_uses(self, applet, panel_layout):
try:
with open(os.path.join('/','usr','share','mate-panel','layouts', panel_layout + '.layout'), 'rb', 0) as layout, \
mmap.mmap(layout.fileno(), 0, access=mmap.ACCESS_READ) as data:
if data.find(applet.encode('utf-8')) != -1:
return True
return False
except:
return False
def get_panel_layout_section_settings(self, panel_layout, section, target_keys):
settings = self.get_panel_layout_section_all_settings(panel_layout, section)
if len(settings.keys()) > 0 and len(target_keys) > 0:
section_keys = set(settings.keys())
ignore_keys = list(section_keys - set(target_keys))
for key in ignore_keys:
del settings[key]
# need to make sure that our targets, if any, at least
# exist in the dictionary to avoid exception
for key in target_keys:
if key not in settings:
settings[key] = None
return settings
def get_panel_layout_section_all_settings(self, panel_layout, section):
settings = {}
if self.panel_layout_uses(section, panel_layout):
try:
with open(os.path.join('/','usr','share','mate-panel','layouts', panel_layout + '.layout'), 'rb', 0) as layout, \
mmap.mmap(layout.fileno(), 0, access=mmap.ACCESS_READ) as data:
section_pos = data.find(section.encode('utf-8'))
if section_pos != -1:
data.seek(section_pos)
print("Found section %s" % section)
done = False
while not done:
line = data.readline().strip().decode('utf-8')
done = (not line or line.isspace())
if not done:
if line.find("=") > 0:
setting = line.split("=", 1)
settings[setting[0]] = setting[1]
except:
print("ERROR!! Reading file %s" % panel_layout + '.layout', sys.exc_info()[0])
return settings
def is_panel_layout_name_special(self, panel_layout, name_tags):
# Legacy versions used the begining of the file name to determine
# if the specified layout was special in some way. This is the
# same check, but less verbose for callers
for tag in name_tags:
if panel_layout.startswith(tag):
return True
return False
def update_panel_layout_ui(self, panel_layout):
# Make Menu Bar configuration insensitive for layouts that don't
# feature the menu bar.
if self.panel_layout_uses('Object menu-bar', panel_layout):
self.builder.get_object('box_menu_features').props.sensitive = True
self.builder.get_object('combobox_panel_icon_size').props.sensitive = True
self.builder.get_object('combobox_panel_menu_icon_size').props.sensitive = True
else:
self.builder.get_object('box_menu_features').props.sensitive = False
self.builder.get_object('combobox_panel_icon_size').props.sensitive = False
self.builder.get_object('combobox_panel_menu_icon_size').props.sensitive = False
if 'tweak' in panel_layout:
self.builder.get_object('button_delete_panel').props.sensitive = True
else:
self.builder.get_object('button_delete_panel').props.sensitive = False
def reload_panel(self):
pid = subprocess.Popen(['mate-panel', '--replace'], stdout=DEVNULL, stderr=DEVNULL).pid
def reload_settings_daemon(self):
pid = subprocess.Popen(['mate-settings-daemon', '--replace'], stdout=DEVNULL, stderr=DEVNULL).pid
def confirm_dialog(self, title, text):
dialog = Gtk.Dialog(title, None, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK))
dialog.set_default_size(500, 160)
label = Gtk.Label(text)
label.set_use_markup(True)
box = dialog.get_content_area()
box.set_border_width(12)
box.add(label)
dialog.show_all()
response = dialog.run()
dialog.destroy()
confirmed = False
if response == Gtk.ResponseType.OK:
confirmed = True
return confirmed
def replace_panel_layout(self, new_layout, called_from_api=False):
icon_size = self.get_string('org.mate.panel.menubar', None, 'icon-size')
item_icon_size = self.get_string('org.mate.panel.menubar', None, 'item-icon-size')
print('Switching to: ' + new_layout)
# Shutdown panel processes before switching
if self.dock and self.process_running(self.dock):
self.kill_process(self.dock)
if self.keyboard_led_enabled:
self.set_bool('org.mate.peripherals-keyboard-xkb.general', None, 'duplicate-leds', False)
if not called_from_api:
self.update_panel_layout_ui(new_layout)
# If we're switching to Cupertino move window
# controls to the left and enable Global Menu.
# If there is a custom setting, use that first
layout_name_is_special = self.is_panel_layout_name_special(new_layout, ['eleven','contemporary'])
custom_settings = self.get_panel_layout_section_settings(new_layout, 'Customsetting windowcontrollayout', \
['mate-general','mate-interface','gnome-wm-preferences'])
self.set_string("org.mate.Marco.general", None, "button-layout", \
custom_settings.get('mate-general') or \
(__CONTEMPORARY_BUTTONS__ if layout_name_is_special else __TRADITIONAL_BUTTONS__))
self.set_string("org.mate.interface", None, "gtk-decoration-layout", \
custom_settings.get('mate-interface') or \
(__CONTEMPORARY_BUTTONS__ if layout_name_is_special else __TRADITIONAL_BUTTONS__))
self.set_string("org.gnome.desktop.wm.preferences", None, "button-layout", \
custom_settings.get('gnome-wm-preferences') or \
(__CONTEMPORARY_BUTTONS__ if layout_name_is_special else __TRADITIONAL_BUTTONS__))
# If we're switching away from a layout that uses the AppMenu applet
# terminate the registrar.
if self.panel_layout_uses('AppmenuApplet', self.current_layout) and \
self.process_running('appmenu-registrar'):
self.kill_process('appmenu-registrar')
# Update window controls
if not called_from_api:
self.update_window_controls()
# Get the icon sizes now the new layout has been applied.
new_icon_size = self.get_string('org.mate.panel.menubar', None, 'icon-size')
new_item_icon_size = self.get_string('org.mate.panel.menubar', None, 'item-icon-size')
# If the new icon sizes are default and the icon sizes were
# previously set then restore the previous icon sizes.
if (new_icon_size == 'Default') and (icon_size != 'Default'):
print('Change icon-size')
self.set_string('org.mate.panel.menubar', None, 'icon-size', icon_size)
if (new_item_icon_size == 'Default') and (item_icon_size != 'Default'):
print('Change item-icon-size')
self.set_string('org.mate.panel.menubar', None, 'item-icon-size', item_icon_size)
# If the panel layout is Indicator enabled the appropriate
# indicators and applets need to be stopped/started
if self.panel_layout_uses('IndicatorApplet', new_layout):
self.disable_applets()
else:
self.enable_applets()
# Change Brisk Menu label-visible state when changing to/from Cupertino and Netbook.
if self.brisk_menu_available:
label_visible = self.get_bool('com.solus-project.brisk-menu', None, 'label-visible')
if (new_layout.startswith('eleven') or new_layout.startswith('netbook')):
self.set_bool('com.solus-project.brisk-menu', None, 'label-visible', False)
# If we're switching from Cupertino or Netbook and Brisk Menu label-visible is disabled then enable it.
elif (self.current_layout.startswith('eleven') or self.current_layout.startswith('netbook')) and not label_visible:
self.set_bool('com.solus-project.brisk-menu', None, 'label-visible', True)
# Change Brisk Menu window-type when changing to/from Mutiny or Cupertino.
if self.brisk_menu_available and self.schema_has_key('com.solus-project.brisk-menu', 'window-type'):
current_window_type = self.get_enum('com.solus-project.brisk-menu', None, 'window-type')
if (new_layout.startswith('mutiny') or new_layout.startswith('eleven')) and (current_window_type != 2):
# If we're switching to Mutiny or Cupertino, and Brisk Menu change the window-type to dash.
self.kill_process('brisk-menu')
# FIXME! Do not hardcode this.
self.set_enum('com.solus-project.brisk-menu', None, 'window-type', 2)
elif (self.current_layout.startswith('mutiny') or self.current_layout.startswith('eleven')) and (current_window_type != 1):
# If we're switching from Mutiny or Cupertino, and Brisk Menu change the window-type to classic.
self.kill_process('brisk-menu')
# FIXME! Do not hardcode this.
self.set_enum('com.solus-project.brisk-menu', None, 'window-type', 1)
# If we have a custom panel layout just replace the dconf dump.
if os.path.exists(os.path.join('/','usr','share','mate-panel','layouts', new_layout + '.panel')):
# Reset panel configuration to defaults.
self.reset_dconf_path('/org/mate/panel/objects/')
self.reset_dconf_path('/org/mate/panel/toplevels/')
print('Loading additional panel configuration for ' + new_layout)
cmd = 'dconf load /org/mate/panel/ < /usr/share/mate-panel/layouts/' + new_layout + '.panel'
subprocess.call(cmd, shell=True, stdout=DEVNULL, stderr=DEVNULL)
else:
# Set the new layout
subprocess.call(['mate-panel', '--reset', '--layout', new_layout], stdout=DEVNULL, stderr=DEVNULL)
# Brisk Menu remains running.
# So if Brisk is not in the layout being switched to, kill it.
if not self.panel_layout_uses('BriskMenu', new_layout) and self.process_running('brisk-menu'):
self.kill_process('brisk-menu')
self.reload_panel()
if self.keyboard_led_enabled:
self.set_bool('org.mate.peripherals-keyboard-xkb.general', None, 'duplicate-leds', False)
# Determine if maximised windows should be undecorated
if self.maximus_available:
layout_name_is_special = self.is_panel_layout_name_special(new_layout, ['netbook'])
custom_settings = self.get_panel_layout_section_settings(new_layout, 'Customsetting maximusdecoration', [])
# Prefer custom settings
if custom_settings.get('mate-maximus-undecorate') and custom_settings.get('mate-maximus-undecorate').upper() == 'TRUE':
self.maximus_undecorate()
elif custom_settings.get('mate-maximus-recorded') and custom_settings.get('mate-maximus-undecorate').upper() == 'FALSE':
self.maximus_decorate()
elif layout_name_is_special:
self.maximus_undecorate()
else:
self.maximus_decorate()
# Determine if the dock should be enabled
if os.path.exists(os.path.join('/','usr','share','mate-panel','layouts', new_layout + '.dock')) and self.dock is not None:
print('Found dock hint for ' + new_layout)
mate_theme = self.get_string('org.mate.interface', None, 'gtk-theme')
if not new_layout.startswith('mutiny'):
self.set_dconf_value('/net/launchpad/plank/docks/dock1/alignment', "'center'")
self.set_dconf_value('/net/launchpad/plank/docks/dock1/hide-mode', "'window-dodge'")
self.set_dconf_value('/net/launchpad/plank/docks/dock1/icon-size', "'48'")
self.set_dconf_value('/net/launchpad/plank/docks/dock1/items-alignment', "'center'")
self.set_dconf_value('/net/launchpad/plank/docks/dock1/position', "'bottom'")
if mate_theme.startswith('Yaru'):
if mate_theme.endswith('-dark'):
self.set_dconf_value('/net/launchpad/plank/docks/dock1/theme', "'Yaru-dark'")
else:
self.set_dconf_value('/net/launchpad/plank/docks/dock1/theme', "'Yaru-light'")
elif mate_theme in ['Ambiant-MATE', 'Ambiant-MATE-Dark', 'Radiant-MATE']:
self.set_dconf_value('/net/launchpad/plank/docks/dock1/theme', "'Ubuntu-MATE'")
else:
self.set_dconf_value('/net/launchpad/plank/docks/dock1/theme', "'Default'")
self.set_dconf_value('/net/launchpad/plank/docks/dock1/zoom-enabled', "true")
elif new_layout.startswith('mutiny'):
self.set_dconf_value('/net/launchpad/plank/docks/dock1/alignment', "'fill'")
self.set_dconf_value('/net/launchpad/plank/docks/dock1/hide-mode', "'none'")
self.set_dconf_value('/net/launchpad/plank/docks/dock1/icon-size', "'56'")
self.set_dconf_value('/net/launchpad/plank/docks/dock1/items-alignment', "'start'")
self.set_dconf_value('/net/launchpad/plank/docks/dock1/position', "'left'")
if mate_theme.startswith('Yaru'):
if mate_theme.endswith('-dark'):
self.set_dconf_value('/net/launchpad/plank/docks/dock1/theme', "'Mutiny-dark'")
else:
self.set_dconf_value('/net/launchpad/plank/docks/dock1/theme', "'Mutiny-light'")
else:
self.set_dconf_value('/net/launchpad/plank/docks/dock1/theme', "'Matte'")
self.set_dconf_value('/net/launchpad/plank/docks/dock1/zoom-enabled', "false")
self.enable_dock()
else:
self.disable_dock()
# Update the Dock checkbutton UI
if not called_from_api:
self.builder.get_object("checkbutton_dock").set_active(self.dock_enabled)
# Update the number and orientation of virtual workspaces for Compiz
if 'compiz' in self.current_wm:
num_workspaces = self.get_num_workspaces()
# Don't make any change if workspaces is zero.
if num_workspaces != 0:
self.set_dconf_value('/org/compiz/profiles/mate/plugins/core/hsize', str(num_workspaces))
self.set_dconf_value('/org/compiz/profiles/mate/plugins/core/vsize', '1')
print('Set ' + str(num_workspaces) + ' workspaces for ' + self.current_wm)
# Make sure the correct panel name is set
if not called_from_api:
widget = self.builder.get_object('combobox_panels')
widget.disconnect(self.combobox_panels_handler)
self.set_string("org.mate.panel", None, "default-layout", new_layout)
self.combobox_panels_handler = widget.connect("changed", self.combo_fallback, 'org.mate.panel', 'default-layout')
self.current_layout = new_layout
def get_panel_layout(self):
self.current_layout = self.get_string('org.mate.panel', None, 'default-layout')
def init_panel_features(self):
self.get_panel_layout()
print ('Current layout: ' + self.current_layout)
self.update_panel_layout_ui(self.current_layout)
source = Gio.SettingsSchemaSource.get_default()
if source.lookup('org.mate.panel', True) != None:
widget = self.builder.get_object('combobox_panels')
index = 0
for row in widget.get_model():
if(self.current_layout == row[1]):
widget.set_active(index)
break
index += 1
self.combobox_panels_handler = widget.connect("changed", self.combo_fallback, 'org.mate.panel', 'default-layout')
def toggle_panel_features(self, widget):
self.reload_panel()
def toggle_pulldown_terminal(self, checkbutton):
if checkbutton.get_active():
self.enable_pulldown_terminal()
else:
self.disable_pulldown_terminal()
def toggle_dock(self, checkbutton):
if checkbutton.get_active():
if not self.dock_enabled:
self.enable_dock()
else:
self.disable_dock()
def toggle_keyboard_led(self, checkbutton):
if checkbutton.get_active():
if not self.keyboard_led_enabled:
self.enable_keyboard_led()
else:
self.disable_keyboard_led()
def panel_layout_exists(self, panel_layout):
return os.path.exists('/usr/share/mate-panel/layouts/' + panel_layout + '.layout')
def check_glx_features(self):
if self.find_on_path('glxinfo'):
process = subprocess.Popen(['glxinfo'], stdout=PIPE)
out = process.communicate()[0].decode("UTF-8")
if out.count("Software Rasterizer") == 0:
self.software_rasterizer = False
else:
self.software_rasterizer = True
if out.count("texture_from_pixmap") > 2:
self.texture_from_pixmap = True
else:
self.texture_from_pixmap = False
else:
self.software_rasterizer = False
self.texture_from_pixmap = False
def update_windowmanager_widgets(self):
# Update the widget based on the current window manager.
if ('marco' in self.current_wm):
self.builder.get_object('frame_performance').props.sensitive = True
self.init_checkbox('org.mate.Marco.general', 'reduced-resources', 'checkbox_resources')
if self.schema_has_key('org.mate.Marco.general','side-by-side-tiling'):
self.init_checkbox('org.mate.Marco.general', 'side-by-side-tiling', 'checkbox_snapping')
elif self.schema_has_key('org.mate.Marco.general','allow-tiling'):
self.init_checkbox('org.mate.Marco.general', 'allow-tiling', 'checkbox_snapping')
self.init_checkbox('org.mate.interface', 'enable-animations', 'checkbox_animations')
# Make the Window Snapping checkbox inactive based if reduced resources is enabled
# - https://bugs.launchpad.net/ubuntu-mate/+bug/1548011
marco_reduced = self.get_bool('org.mate.Marco.general', None, 'reduced-resources')
if marco_reduced:
self.builder.get_object('checkbox_snapping').props.sensitive = False
else:
self.builder.get_object('frame_performance').props.sensitive = False
if self.current_wm == 'compiz':
self.builder.get_object('button_compiz_reset').show()
if self.ccsm_capable:
self.builder.get_object('button_ccsm').show()
else:
self.builder.get_object('button_ccsm').hide()
else:
self.builder.get_object('button_compiz_reset').hide()
self.builder.get_object('button_ccsm').hide()
def additional_tweaks(self, schema, key, value):
if schema == "org.mate.Marco.general" and key == "button-layout":
# If the button-layout is changed in MATE reflect that change
# for GTK3 and GNOME.
self.set_string("org.mate.interface", None, "gtk-decoration-layout", value)
self.set_string("org.gnome.desktop.wm.preferences", None, "button-layout", value)
elif (schema == "org.mate.interface" and key == "enable-animations"):
self.set_bool('org.mate.panel', None, 'enable-aniations', value)
self.set_bool('org.mate.interface', None, 'gtk-enable-aniations', value)
self.set_bool('org.gnome.desktop.interface', None, 'enable-aniations', value)
elif (schema == "org.gnome.desktop.interface" and key == "enable-animations"):
self.set_bool('org.mate.panel', None, 'enable-aniations', value)
self.set_bool('org.mate.interface', None, 'gtk-enable-aniations', value)
self.set_bool('org.mate.interface', None, 'enable-aniations', value)
elif schema == "org.mate.session.required-components" and key == "windowmanager":
# If the window manager is being changed, replace it now!