Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show errors when applying #394

Merged
merged 4 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/Objects/MonitorManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public class Display.MonitorManager : GLib.Object {
}
}

public void set_monitor_config () {
public void set_monitor_config () throws Error {
MutterWriteLogicalMonitor[] logical_monitors = {};
foreach (var virtual_monitor in virtual_monitors) {
if (virtual_monitor.is_active) {
Expand All @@ -256,11 +256,7 @@ public class Display.MonitorManager : GLib.Object {
}

var properties = new GLib.HashTable<string, GLib.Variant> (str_hash, str_equal);
try {
iface.apply_monitors_config (current_serial, MutterApplyMethod.PERSISTENT, logical_monitors, properties);
} catch (Error e) {
critical (e.message);
}
iface.apply_monitors_config (current_serial, MutterApplyMethod.PERSISTENT, logical_monitors, properties);
}

public static MutterWriteLogicalMonitor get_mutter_logical_monitor (Display.VirtualMonitor virtual_monitor) {
Expand Down Expand Up @@ -335,7 +331,7 @@ public class Display.MonitorManager : GLib.Object {
notify_property ("is-mirrored");
}

public void set_scale_on_all_monitors (double new_scale) {
public void set_scale_on_all_monitors (double new_scale) throws Error {
if (new_scale <= 0.0) {
return;
}
Expand Down
23 changes: 21 additions & 2 deletions src/Views/DisplaysView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,22 @@ public class Display.DisplaysView : Gtk.Box {

detect_button.clicked.connect (() => displays_overlay.rescan_displays ());
apply_button.clicked.connect (() => {
monitor_manager.set_monitor_config ();
try {
monitor_manager.set_monitor_config ();
} catch (Error e) {
show_error_dialog (e.message);
}
apply_button.sensitive = false;
});

dpi_combo.active = (int)monitor_manager.virtual_monitors[0].scale - 1;

dpi_combo.changed.connect (() => {
monitor_manager.set_scale_on_all_monitors ((double)(dpi_combo.active + 1));
try {
monitor_manager.set_scale_on_all_monitors ((double)(dpi_combo.active + 1));
} catch (Error e) {
show_error_dialog (e.message);
}
});

mirror_switch.active = monitor_manager.is_mirrored;
Expand All @@ -129,6 +137,17 @@ public class Display.DisplaysView : Gtk.Box {
});
}

private void show_error_dialog (string details) {
var error_dialog = new Granite.MessageDialog.with_image_from_icon_name (
_("Failed to apply display settings"),
_("This can be caused by an invalid configuration."),
"dialog-error"
);
error_dialog.show_error_details (details);
error_dialog.response.connect (error_dialog.destroy);
error_dialog.present ();
}

private async void detect_accelerometer () {
bool has_accelerometer = false;

Expand Down
Loading