Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Commit

Permalink
feat: add signals and configuration handling for manage, floating, an…
Browse files Browse the repository at this point in the history
…d layered applications
  • Loading branch information
amnweb committed Nov 7, 2024
1 parent 39f0d2a commit d763df5
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 5 deletions.
3 changes: 3 additions & 0 deletions app/core/utils/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

class SignalManager(QObject):
ignore_rules_updated = pyqtSignal(list)
manage_rules_updated = pyqtSignal(list)
floating_applications_updated = pyqtSignal(list)
layered_applications_updated = pyqtSignal(list)
workspace_monitors_updated = pyqtSignal(list)
ui_update = pyqtSignal()
value_changed = pyqtSignal()
Expand Down
120 changes: 115 additions & 5 deletions app/core/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def convert_value(value):
def generate_config(parent_widget, widget_factories):
monitors = {}
ignore_rules_map = {}
manage_rules_map = {}
floating_applications_map = {}
layered_applications_map = {}
other_configs = {}

# Process widgets
Expand All @@ -94,6 +97,10 @@ def generate_config(parent_widget, widget_factories):
value = widget.get_value()

try:
# Skip some keys and values
if config_id == 'border_z_order' and str(value) == 'System':
continue

if config_id.startswith('monitors-'):
monitor_num, workspace_num, property_name = process_monitor_config(config_id, value)
monitors.setdefault(monitor_num, {"workspaces": {}})
Expand All @@ -105,6 +112,21 @@ def generate_config(parent_widget, widget_factories):
ignore_rules_map.setdefault(rule_num, {})
ignore_rules_map[rule_num][property_name] = value

elif config_id.startswith('manage_rules-'):
rule_num, property_name = process_ignore_rule(config_id, value)
manage_rules_map.setdefault(rule_num, {})
manage_rules_map[rule_num][property_name] = value

elif config_id.startswith('floating_applications-'):
rule_num, property_name = process_ignore_rule(config_id, value)
floating_applications_map.setdefault(rule_num, {})
floating_applications_map[rule_num][property_name] = value

elif config_id.startswith('layered_applications-'):
rule_num, property_name = process_ignore_rule(config_id, value)
layered_applications_map.setdefault(rule_num, {})
layered_applications_map[rule_num][property_name] = value

else:
current = other_configs
parts = config_id.split('.')
Expand Down Expand Up @@ -148,6 +170,42 @@ def generate_config(parent_widget, widget_factories):
})
config["ignore_rules"] = rules_list

if manage_rules_map:
rules_list = []
for rule_id in sorted(manage_rules_map.keys()):
rule = manage_rules_map[rule_id]
if all(key in rule for key in ['kind', 'matching_strategy', 'id']):
rules_list.append({
'kind': rule['kind'],
'matching_strategy': rule['matching_strategy'],
'id': rule['id']
})
config["manage_rules"] = rules_list

if floating_applications_map:
rules_list = []
for rule_id in sorted(floating_applications_map.keys()):
rule = floating_applications_map[rule_id]
if all(key in rule for key in ['kind', 'matching_strategy', 'id']):
rules_list.append({
'kind': rule['kind'],
'matching_strategy': rule['matching_strategy'],
'id': rule['id']
})
config["floating_applications"] = rules_list

if layered_applications_map:
rules_list = []
for rule_id in sorted(layered_applications_map.keys()):
rule = layered_applications_map[rule_id]
if all(key in rule for key in ['kind', 'matching_strategy', 'id']):
rules_list.append({
'kind': rule['kind'],
'matching_strategy': rule['matching_strategy'],
'id': rule['id']
})
config["layered_applications"] = rules_list

return config


Expand All @@ -174,7 +232,7 @@ def open_file_dialog(self):
self.config_path = selected_files[0]

try:
with open(self.config_path, 'r') as file:
with open(self.config_path, 'r', encoding='utf-8') as file:
self.config_data = json.load(file)
if "$schema" in self.config_data:
self.original_config_values["$schema"] = self.config_data["$schema"]
Expand Down Expand Up @@ -228,10 +286,11 @@ def save_file_dialog(self, parent_widget, widget_factories, show_dialog=False):
else:
# No existing path - force dialog
return self.save_file_dialog(parent_widget, widget_factories, True)

# Save config to path
with open(file_path, 'w', encoding='utf-8') as f:
json.dump(final_config, f, indent=2)
json.dump(final_config, f, indent=2, ensure_ascii=False)
# Save config to path
# with open(file_path, 'w', encoding='utf-8') as f:
# json.dump(final_config, f, indent=2)

# Store path for future saves
self.config_path = file_path
Expand Down Expand Up @@ -303,6 +362,54 @@ def update_widgets(self):
indexed_rules.append(indexed_rule)
signal_manager.ignore_rules_updated.emit(indexed_rules)

# Handle manage rules with indexed config IDs
if 'manage_rules' in self.config_data:
manage_rules = self.config_data['manage_rules']
if isinstance(manage_rules, list):
# Transform rules to include index
indexed_rules = []
for idx, rule in enumerate(manage_rules, 1):
indexed_rule = {
'kind': rule.get('kind'),
'matching_strategy': rule.get('matching_strategy'),
'id': rule.get('id'),
'config_id_prefix': f'manage_rules-{idx}'
}
indexed_rules.append(indexed_rule)
signal_manager.manage_rules_updated.emit(indexed_rules)

# Handle floating applications with indexed config IDs
if 'floating_applications' in self.config_data:
floating_applications = self.config_data['floating_applications']
if isinstance(floating_applications, list):
# Transform rules to include index
indexed_rules = []
for idx, rule in enumerate(floating_applications, 1):
indexed_rule = {
'kind': rule.get('kind'),
'matching_strategy': rule.get('matching_strategy'),
'id': rule.get('id'),
'config_id_prefix': f'floating_applications-{idx}'
}
indexed_rules.append(indexed_rule)
signal_manager.floating_applications_updated.emit(indexed_rules)

# Handle layered applications with indexed config IDs
if 'layered_applications' in self.config_data:
layered_applications = self.config_data['layered_applications']
if isinstance(layered_applications, list):
# Transform rules to include index
indexed_rules = []
for idx, rule in enumerate(layered_applications, 1):
indexed_rule = {
'kind': rule.get('kind'),
'matching_strategy': rule.get('matching_strategy'),
'id': rule.get('id'),
'config_id_prefix': f'layered_applications-{idx}'
}
indexed_rules.append(indexed_rule)
signal_manager.layered_applications_updated.emit(indexed_rules)

# Handle workspaces
if 'monitors' in self.config_data:
monitors = self.config_data['monitors']
Expand All @@ -315,7 +422,10 @@ def update_widgets(self):
if hasattr(widget, 'config_id') and widget.config_id:
# Skip special widgets with numbered rules
if not (widget.config_id.split('.')[0].startswith('ignore_rules-') or
widget.config_id.startswith('monitors')):
widget.config_id.split('.')[0].startswith('manage_rules-') or
widget.config_id.split('.')[0].startswith('floating_applications-') or
widget.config_id.split('.')[0].startswith('layered_applications-') or
widget.config_id.startswith('monitors')):
value = self.get_config_value(widget.config_id)
if value is not None:
self.set_widget_value(widget, value)

0 comments on commit d763df5

Please sign in to comment.