Skip to content

Commit

Permalink
HotcornerControl/CustomCommand: Fix infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
leolost2605 committed Jan 8, 2025
1 parent 4ee366a commit ab4c350
Showing 1 changed file with 35 additions and 36 deletions.
71 changes: 35 additions & 36 deletions src/Views/Multitasking.vala
Original file line number Diff line number Diff line change
Expand Up @@ -164,46 +164,45 @@ public class PantheonShell.Multitasking : Switchboard.SettingsPage {
null, null
);

get_command_string ();

settings.changed["hotcorner-custom-command"].connect (() => {
get_command_string ();
});

command_entry.changed.connect (() => {
var this_command = "hotcorner-%s:%s".printf (position, command_entry.text);

var setting_string = settings.get_string ("hotcorner-custom-command");

var found = false;
string[] commands = setting_string.split (";;");
for (int i = 0; i < commands.length ; i++) {
if (commands[i].has_prefix ("hotcorner-" + position)) {
found = true;
commands[i] = this_command;
settings.bind_with_mapping (
"hotcorner-custom-command",
command_entry,
"text",
DEFAULT,
(value, variant, instance) => {
string[] commands = ((string) variant).split (";;");
foreach (unowned string command in commands) {
if (command.has_prefix ("hotcorner-" + ((HotcornerControl) instance).position)) {
value.set_string (command.replace ("hotcorner-%s:".printf (((HotcornerControl) instance).position), ""));
return true;
}
}
}

if (!found) {
commands += this_command;
}

settings.set_string ("hotcorner-custom-command", string.joinv (";;", commands));
});
}

private void get_command_string () {
var setting_string = settings.get_string ("hotcorner-custom-command");
var this_command = "";
value.set_string ("");
return true;
},
(value, expected_type, instance) => {
var this_command = "hotcorner-%s:%s".printf (((HotcornerControl) instance).position, value.get_string ());

var setting_string = settings.get_string ("hotcorner-custom-command");

var found = false;
string[] commands = setting_string.split (";;");
for (int i = 0; i < commands.length ; i++) {
if (commands[i].has_prefix ("hotcorner-" + ((HotcornerControl) instance).position)) {
found = true;
commands[i] = this_command;
}
}

string[] commands = setting_string.split (";;");
foreach (unowned string command in commands) {
if (command.has_prefix ("hotcorner-" + position)) {
this_command = command.replace ("hotcorner-%s:".printf (position), "");
}
}
if (!found) {
commands += this_command;
}

command_entry.text = this_command;
return new Variant.string (string.joinv (";;", commands));
},
this, null
);
}
}
}

0 comments on commit ab4c350

Please sign in to comment.