Skip to content

Commit 1869bc1

Browse files
committed
Refactor replace_panel_layout() to make switching robust
- Close panel(s) and dock(s) prior to switching to prevent crashes in processes being configured by the layout change. - Panel reset, set name and replace in discrete steps. They can not be executed together. - Dock configuration and start happens after panel start so struts are always correct.
1 parent d2728cd commit 1869bc1

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

mate-tweak

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,9 @@ class MateTweak:
694694
item_icon_size = self.get_string('org.mate.panel.menubar', None, 'item-icon-size')
695695

696696
print('Switching to: ' + new_layout)
697+
self.kill_process('mate-panel')
698+
if self.dock and self.process_running(self.dock):
699+
self.kill_process(self.dock)
697700

698701
if not called_from_api:
699702
self.update_panel_layout_ui(new_layout)
@@ -780,6 +783,31 @@ class MateTweak:
780783
cmd = 'dconf load /org/mate/panel/ < /usr/share/mate-panel/layouts/' + new_layout + '.panel'
781784
subprocess.call(cmd, shell=True, stdout=DEVNULL, stderr=DEVNULL)
782785

786+
# Determine if maximised windows should be undecorated
787+
if self.maximus_available:
788+
layout_name_is_special = self.is_panel_layout_name_special(new_layout, ['netbook'])
789+
custom_settings = self.get_panel_layout_section_settings(new_layout, 'Customsetting maximusdecoration', [])
790+
791+
# Prefer custom settings
792+
if custom_settings.get('mate-maximus-undecorate') and custom_settings.get('mate-maximus-undecorate').upper() == 'TRUE':
793+
self.maximus_undecorate()
794+
elif custom_settings.get('mate-maximus-recorded') and custom_settings.get('mate-maximus-undecorate').upper() == 'FALSE':
795+
self.maximus_decorate()
796+
elif layout_name_is_special:
797+
self.maximus_undecorate()
798+
else:
799+
self.maximus_decorate()
800+
801+
# Set the new layout
802+
subprocess.call(['mate-panel', '--reset'], stdout=DEVNULL, stderr=DEVNULL)
803+
subprocess.call(['mate-panel', '--layout', new_layout], stdout=DEVNULL, stderr=DEVNULL)
804+
self.reload_panel()
805+
806+
# Brisk Menu remains running.
807+
# So if Brisk is not in the layout being switched to, kill it.
808+
if not self.panel_layout_uses('BriskMenu', new_layout) and self.process_running('brisk-menu'):
809+
self.kill_process('brisk-menu')
810+
783811
# Determine if the dock should be enabled
784812
if os.path.exists(os.path.join('/','usr','share','mate-panel','layouts', new_layout + '.dock')) and self.dock is not None:
785813
print('Found dock hint for ' + new_layout)
@@ -818,29 +846,6 @@ class MateTweak:
818846
else:
819847
self.disable_dock()
820848

821-
# Determine if maximised windows should be undecorated
822-
if self.maximus_available:
823-
layout_name_is_special = self.is_panel_layout_name_special(new_layout, ['netbook'])
824-
custom_settings = self.get_panel_layout_section_settings(new_layout, 'Customsetting maximusdecoration', [])
825-
826-
# Prefer custom settings
827-
if custom_settings.get('mate-maximus-undecorate') and custom_settings.get('mate-maximus-undecorate').upper() == 'TRUE':
828-
self.maximus_undecorate()
829-
elif custom_settings.get('mate-maximus-recorded') and custom_settings.get('mate-maximus-undecorate').upper() == 'FALSE':
830-
self.maximus_decorate()
831-
elif layout_name_is_special:
832-
self.maximus_undecorate()
833-
else:
834-
self.maximus_decorate()
835-
836-
# Set the new layout
837-
subprocess.call(['mate-panel', '--reset', '--layout', new_layout], stdout=DEVNULL, stderr=DEVNULL)
838-
839-
# Brisk Menu remains running.
840-
# So if Brisk is not in the layout being switched to, kill it.
841-
if not self.panel_layout_uses('BriskMenu', new_layout) and self.process_running('brisk-menu'):
842-
self.kill_process('brisk-menu')
843-
844849
# Update the Dock checkbutton UI
845850
if not called_from_api:
846851
self.builder.get_object("checkbutton_dock").set_active(self.dock_enabled)

0 commit comments

Comments
 (0)