ui: use backend capabilities

parent 80e814c3
......@@ -11,6 +11,24 @@ namespace TunerDisplays {
public abstract string id { get; }
public abstract string title { owned get; }
public abstract bool can_apply { get; }
public virtual bool requires_connected_layout { get { return false; } }
public virtual bool preserves_disabled_monitor_position { get { return true; } }
public virtual bool supports_monitor_change_events { get { return false; } }
public virtual bool supports_global_mirroring { get { return false; } }
public virtual bool supports_primary_display { get { return false; } }
public virtual bool uses_separate_refresh_rate_controls { get { return false; } }
public virtual bool supports_output_mirroring { get { return false; } }
public virtual bool supports_description_identifier { get { return false; } }
public virtual bool supports_bit_depth { get { return false; } }
public virtual bool supports_vrr_modes { get { return false; } }
public virtual bool supports_adaptive_sync { get { return false; } }
public virtual bool supports_color_management { get { return false; } }
public virtual bool supports_hdr_metadata { get { return false; } }
public virtual bool supports_focus_at_startup { get { return false; } }
public virtual bool supports_backdrop_color { get { return false; } }
public virtual bool supports_hot_corners { get { return false; } }
public virtual bool supports_underscanning { get { return false; } }
public virtual bool supports_hdr_toggle { get { return false; } }
public abstract Gee.ArrayList<MonitorConfig> load() throws Error;
public abstract void apply(Gee.ArrayList<MonitorConfig> monitors) throws Error;
......
......@@ -13,6 +13,14 @@ namespace TunerDisplays {
public override string id { get { return "gnome"; } }
public override string title { owned get { return "GNOME"; } }
public override bool can_apply { get { return true; } }
public override bool requires_connected_layout { get { return true; } }
public override bool preserves_disabled_monitor_position { get { return false; } }
public override bool supports_monitor_change_events { get { return true; } }
public override bool supports_global_mirroring { get { return true; } }
public override bool supports_primary_display { get { return true; } }
public override bool uses_separate_refresh_rate_controls { get { return true; } }
public override bool supports_underscanning { get { return true; } }
public override bool supports_hdr_toggle { get { return true; } }
public override Gee.ArrayList<MonitorConfig> load() throws Error {
var state = call_display_config("GetCurrentState", null, null);
......
......@@ -22,6 +22,12 @@ namespace TunerDisplays {
public override string id { get { return "hyprland"; } }
public override string title { owned get { return "Hyprland"; } }
public override bool can_apply { get { return true; } }
public override bool supports_output_mirroring { get { return true; } }
public override bool supports_description_identifier { get { return true; } }
public override bool supports_bit_depth { get { return true; } }
public override bool supports_vrr_modes { get { return true; } }
public override bool supports_color_management { get { return true; } }
public override bool supports_hdr_metadata { get { return true; } }
public override Gee.ArrayList<MonitorConfig> load() throws Error {
var monitors = new Gee.ArrayList<MonitorConfig>();
......
......@@ -30,6 +30,10 @@ namespace TunerDisplays {
public override string id { get { return "niri"; } }
public override string title { owned get { return "niri"; } }
public override bool can_apply { get { return true; } }
public override bool supports_adaptive_sync { get { return true; } }
public override bool supports_focus_at_startup { get { return true; } }
public override bool supports_backdrop_color { get { return true; } }
public override bool supports_hot_corners { get { return true; } }
public override Gee.ArrayList<MonitorConfig> load() throws Error {
var monitors = new Gee.ArrayList<MonitorConfig>();
......
......@@ -79,7 +79,7 @@ namespace TunerDisplays {
}
private MonitorSettingsContent create_monitor_page_content(MonitorConfig monitor) {
var content = new MonitorSettingsContent(monitor, view.backend_id, view.monitor_configs);
var content = new MonitorSettingsContent(monitor, view.display_backend, view.monitor_configs);
content.monitor_changed.connect(view.refresh_from_monitors);
return content;
}
......
......@@ -18,7 +18,7 @@ namespace TunerDisplays {
[GtkChild] private unowned Adw.PreferencesGroup status_group;
public bool can_apply { get { return backend.can_apply; } }
public Gee.ArrayList<MonitorConfig> monitor_configs { get { return monitors; } }
public string backend_id { owned get { return backend.id; } }
public DisplayBackend display_backend { get { return backend; } }
public signal void monitor_settings_requested(MonitorConfig monitor);
construct {
......@@ -33,7 +33,7 @@ namespace TunerDisplays {
layout = new MonitorLayout() {
height_request = 320,
hexpand = true,
require_connected = backend.id == "gnome",
require_connected = backend.requires_connected_layout,
can_focus = false,
focusable = false
};
......@@ -145,7 +145,7 @@ namespace TunerDisplays {
} else {
add_gnome_primary_row();
foreach (var monitor in monitors) {
var row = new MonitorRow(monitor, monitor_settings_page_id(), monitors, backend.id);
var row = new MonitorRow(monitor, monitor_settings_page_id(), monitors, backend);
row.monitor_selected.connect(monitor => monitor_settings_requested(monitor));
row.monitor_changed.connect(() => layout.recenter());
monitors_group.add(row);
......@@ -164,7 +164,7 @@ namespace TunerDisplays {
}
private void add_gnome_mirror_row() {
if (backend.id != "gnome" || monitors.size <= 1)
if (!backend.supports_global_mirroring || monitors.size <= 1)
return;
var row = new Adw.SwitchRow() {
......@@ -193,7 +193,7 @@ namespace TunerDisplays {
if (monitors.size != 1)
return;
single_monitor_content = new MonitorSettingsContent(monitors[0], backend.id, monitors, false);
single_monitor_content = new MonitorSettingsContent(monitors[0], backend, monitors, false);
single_monitor_content.monitor_changed.connect(refresh_from_monitors);
while (single_monitor_content.get_group(0) != null) {
......@@ -312,7 +312,7 @@ namespace TunerDisplays {
}
private void add_gnome_primary_row() {
if (backend.id != "gnome" || monitors.size <= 1)
if (!backend.supports_primary_display || monitors.size <= 1)
return;
var model = new Gtk.StringList(null);
......@@ -358,7 +358,7 @@ namespace TunerDisplays {
}
private bool gnome_mirror_enabled() {
return backend.id == "gnome" && monitors.size > 0 && monitors[0].mirrored;
return backend.supports_global_mirroring && monitors.size > 0 && monitors[0].mirrored;
}
private bool single_monitor_mode() {
......@@ -366,7 +366,7 @@ namespace TunerDisplays {
}
private void subscribe_monitor_changes() {
if (backend.id != "gnome")
if (!backend.supports_monitor_change_events)
return;
try {
......
......@@ -4,13 +4,13 @@ namespace TunerDisplays {
private MonitorConfig monitor;
private Gee.ArrayList<MonitorConfig> all_monitors;
private string page_id;
private string backend_id;
private DisplayBackend backend;
private Gtk.Switch enabled_switch;
public signal void monitor_changed();
public signal void monitor_selected(MonitorConfig monitor);
public MonitorRow(MonitorConfig monitor, string page_id, Gee.ArrayList<MonitorConfig> all_monitors, string backend_id) {
public MonitorRow(MonitorConfig monitor, string page_id, Gee.ArrayList<MonitorConfig> all_monitors, DisplayBackend backend) {
Object(
title: monitor.title,
subtitle: "%dx%d@%.2f scale %.2f %dx%d".printf(
......@@ -20,7 +20,7 @@ namespace TunerDisplays {
this.monitor = monitor;
this.all_monitors = all_monitors;
this.page_id = page_id;
this.backend_id = backend_id;
this.backend = backend;
build();
}
......@@ -38,7 +38,7 @@ namespace TunerDisplays {
can_focus = true
};
enabled_switch.notify["active"].connect(() => {
if (enabled_switch.active != monitor.enabled && backend_id == "gnome")
if (enabled_switch.active != monitor.enabled && !backend.preserves_disabled_monitor_position)
place_monitor_after_active(monitor, all_monitors);
monitor.enabled = enabled_switch.active;
monitor_changed();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment