Skip to content
1 change: 0 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ gnome = import('gnome')
i18n = import('i18n')

prefix = get_option('prefix')
datadir = join_paths(prefix, get_option('datadir'))
libdir = join_paths(prefix, get_option('libdir'))

add_project_arguments(
Expand Down
90 changes: 23 additions & 67 deletions src/Objects/VirtualMonitor.vala
Original file line number Diff line number Diff line change
@@ -1,64 +1,27 @@
/*-
* Copyright (c) 2018 elementary LLC.
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this software; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
/*
* SPDX-License-Identifier: GPL-2.0-or-later
* SPDX-FileCopyrightText: 2018-2025 elementary, Inc. <https://elementary.io>
*
* Authored by: Corentin Noël <[email protected]>
*/

public class Display.VirtualMonitor : GLib.Object {
public class Scale : GLib.Object {
public double scale { get; construct; }
public string string_representation { get; construct; }

public Scale (double scale) {
Object (
scale: scale,
string_representation: "%d %%".printf ((int) Math.round (scale * 100))
);
}
}

public int x { get; set; }
public int y { get; set; }
public int current_x { get; set; }
public int current_y { get; set; }
public Gtk.SingleSelection available_scales { get; construct; }
public double scale { get; set; }
public DisplayTransform transform { get; set; }
public bool primary { get; set; }
public Gee.LinkedList<Display.Monitor> monitors { get; construct; }

public signal void modes_changed ();

public double scale {
get {
return ((Scale) available_scales.selected_item).scale;
}
set {
update_available_scales ();
for (int i = 0; i < available_scales.get_n_items (); i++) {
if (value == ((Scale) available_scales.get_item (i)).scale) {
available_scales.selected = i;
return;
}
}
critical ("Unsupported scale %f for current mode", value);
public Display.MonitorMode current_mode {
owned get {
return monitors[0].current_mode;
}
}

public signal void modes_changed ();

/*
* Used to distinguish two VirtualMonitors from each other.
* We make up and ID by sum all hashes of
Expand Down Expand Up @@ -96,13 +59,8 @@ public class Display.VirtualMonitor : GLib.Object {
}
}

private ListStore available_scales_store;

construct {
monitors = new Gee.LinkedList<Display.Monitor> ();

available_scales_store = new ListStore (typeof (Scale));
available_scales = new Gtk.SingleSelection (available_scales_store);
}

public unowned string get_display_name () {
Expand Down Expand Up @@ -147,31 +105,31 @@ public class Display.VirtualMonitor : GLib.Object {
}
}

private void update_available_scales () {
Scale[] scales = {};
foreach (var mode in get_available_modes ()) {
if (!mode.is_current && !mode.is_preferred) {
continue;
}
public double[] get_frequencies_from_current_mode () {
double[] frequencies = {};
int current_width, current_height;

foreach (var scale in mode.supported_scales) {
scales += new Scale (scale);
}
get_current_mode_size (out current_width, out current_height);

break;
foreach (var mode in get_available_modes ()) {
if (mode.width == current_width && mode.height == current_height) {
frequencies += mode.frequency;
}
}

available_scales_store.splice (0, available_scales_store.get_n_items (), scales);
return frequencies;
}

public Display.MonitorMode? get_mode_for_resolution (int width, int height) {
public Gee.LinkedList<Display.MonitorMode> get_modes_for_resolution (int width, int height) {
var mode_list = new Gee.LinkedList<Display.MonitorMode> ();

foreach (var mode in get_available_modes ()) {
if (mode.width == width && mode.height == height) {
return mode;
mode_list.add (mode);
}
}

return null;
return mode_list;
}

public void set_current_mode (Display.MonitorMode current_mode) {
Expand Down Expand Up @@ -199,8 +157,6 @@ public class Display.VirtualMonitor : GLib.Object {
mode.is_current = mode == current_mode;
}
}

scale = current_mode.preferred_scale;
}

public static string generate_id_from_monitors (MutterReadMonitorInfo[] infos) {
Expand Down
3 changes: 2 additions & 1 deletion src/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
*/

namespace Display.Utils {
public static Gee.LinkedList<Display.MonitorMode> get_common_monitor_modes (Gee.LinkedList<Display.Monitor> monitors) {
public static Gee.LinkedList<Display.MonitorMode> get_common_monitor_modes (
Gee.LinkedList<Display.Monitor> monitors) {
var common_modes = new Gee.LinkedList<Display.MonitorMode> ();
double min_scale = get_min_compatible_scale (monitors);
bool first_monitor = true;
Expand Down
24 changes: 14 additions & 10 deletions src/Views/DisplaysView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class Display.DisplaysView : Gtk.Box {
public DisplaysOverlay displays_overlay;

private Gtk.ComboBoxText dpi_combo;
private Gtk.DropDown dpi_dropdown;
private Gtk.Box rotation_lock_box;

private const string TOUCHSCREEN_SETTINGS_PATH = "org.gnome.settings-daemon.peripherals.touchscreen";
Expand All @@ -34,19 +34,21 @@ public class Display.DisplaysView : Gtk.Box {

var dpi_label = new Gtk.Label (_("Scaling factor:"));

dpi_combo = new Gtk.ComboBoxText ();
dpi_combo.append_text (_("LoDPI") + " (1×)");
dpi_combo.append_text (_("HiDPI") + " (2×)");
dpi_combo.append_text (_("HiDPI") + " (3×)");
dpi_dropdown = new Gtk.DropDown.from_strings ({
_("LoDPI") + " (1×)",
_("HiDPI") + " (2×)",
_("HiDPI") + " (3×)"
});

var dpi_box = new Gtk.Box (HORIZONTAL, 6) {
margin_top = 6,
margin_end = 6,
margin_bottom = 6,
margin_start = 6
};

dpi_box.append (dpi_label);
dpi_box.append (dpi_combo);
dpi_box.append (dpi_dropdown);

var detect_button = new Gtk.Button.with_label (_("Detect Displays"));

Expand Down Expand Up @@ -100,7 +102,8 @@ public class Display.DisplaysView : Gtk.Box {
var touchscreen_settings = new GLib.Settings (TOUCHSCREEN_SETTINGS_PATH);
touchscreen_settings.bind ("orientation-lock", rotation_lock_switch, "active", DEFAULT);
} else {
info ("Schema \"org.gnome.settings-daemon.peripherals.touchscreen\" is not installed on your system.");
info ("Schema \"org.gnome.settings-daemon.peripherals.touchscreen\"
is not installed on your system.");
}
}

Expand Down Expand Up @@ -130,11 +133,12 @@ public class Display.DisplaysView : Gtk.Box {
apply_button.sensitive = false;
});

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

dpi_combo.changed.connect (() => {
dpi_dropdown.notify["selected-item"].connect (() => {
try {
monitor_manager.set_scale_on_all_monitors ((double)(dpi_combo.active + 1));
monitor_manager.set_scale_on_all_monitors ((double)(dpi_dropdown.selected + 1));
warning ("Setting scale to %f", (double)(dpi_dropdown.selected + 1));
} catch (Error e) {
show_error_dialog (e.message);
}
Expand Down
14 changes: 7 additions & 7 deletions src/Views/FiltersView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public class Display.FiltersView : Gtk.Box {
return new Variant ("s", "none");
}

return null;
return new Variant.maybe (VariantType.STRING, null);
},
null, null
);
Expand All @@ -198,7 +198,7 @@ public class Display.FiltersView : Gtk.Box {
return new Variant ("s", "protanopia");
}

return null;
return new Variant.maybe (VariantType.STRING, null);
},
null, null
);
Expand All @@ -214,7 +214,7 @@ public class Display.FiltersView : Gtk.Box {
return new Variant ("s", "protanopia-high-contrast");
}

return null;
return new Variant.maybe (VariantType.STRING, null);
},
null, null
);
Expand All @@ -230,7 +230,7 @@ public class Display.FiltersView : Gtk.Box {
return new Variant ("s", "deuteranopia");
}

return null;
return new Variant.maybe (VariantType.STRING, null);
},
null, null
);
Expand All @@ -246,7 +246,7 @@ public class Display.FiltersView : Gtk.Box {
return new Variant ("s", "deuteranopia-high-contrast");
}

return null;
return new Variant.maybe (VariantType.STRING, null);
},
null, null
);
Expand All @@ -262,7 +262,7 @@ public class Display.FiltersView : Gtk.Box {
return new Variant ("s", "tritanopia");
}

return null;
return new Variant.maybe (VariantType.STRING, null);
},
null, null
);
Expand All @@ -278,7 +278,7 @@ public class Display.FiltersView : Gtk.Box {
return new Variant ("s", "none");
}

return null;
return new Variant.maybe (VariantType.STRING, null);
},
null, null
);
Expand Down
Loading