From 8b8fe1f2b1c75d87997fe036301b493424780522 Mon Sep 17 00:00:00 2001 From: Leonhard Date: Sun, 12 Jul 2026 14:58:13 +0200 Subject: [PATCH] Use a dropdown for rotation --- src/Objects/VirtualMonitor.vala | 25 +++++++++++++- src/Widgets/DisplayWidget.vala | 58 +++++---------------------------- 2 files changed, 32 insertions(+), 51 deletions(-) diff --git a/src/Objects/VirtualMonitor.vala b/src/Objects/VirtualMonitor.vala index 9c4638f3..efd7bbf9 100644 --- a/src/Objects/VirtualMonitor.vala +++ b/src/Objects/VirtualMonitor.vala @@ -32,12 +32,21 @@ public class Display.VirtualMonitor : GLib.Object { } } + public class Transform : GLib.Object { + public DisplayTransform transform { get; construct; } + public string string_representation { get; construct; } + + public Transform (DisplayTransform transform) { + Object (transform: transform, string_representation: transform.to_string ()); + } + } + 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 DisplayTransform transform { get; set; } + public Gtk.SingleSelection available_transforms { get; construct; } public bool primary { get; set; } public Gee.LinkedList monitors { get; construct; } @@ -59,6 +68,11 @@ public class Display.VirtualMonitor : GLib.Object { } } + public DisplayTransform transform { + get { return (DisplayTransform) available_transforms.selected; } + set { available_transforms.selected = value; } + } + /** * Used to distinguish two VirtualMonitors from each other. * We make up and ID by sum all hashes of @@ -103,6 +117,15 @@ public class Display.VirtualMonitor : GLib.Object { available_scales_store = new ListStore (typeof (Scale)); available_scales = new Gtk.SingleSelection (available_scales_store); + + var available_transforms_store = new ListStore (typeof (Transform)); + available_transforms = new Gtk.SingleSelection (available_transforms_store) { + autoselect = true + }; + + for (int i = 0; i <= DisplayTransform.FLIPPED_ROTATION_270; i++) { + available_transforms_store.append (new Transform ((DisplayTransform) i)); + } } public unowned string get_display_name () { diff --git a/src/Widgets/DisplayWidget.vala b/src/Widgets/DisplayWidget.vala index 75db722f..5946a21d 100644 --- a/src/Widgets/DisplayWidget.vala +++ b/src/Widgets/DisplayWidget.vala @@ -46,9 +46,6 @@ public class Display.DisplayWidget : Gtk.Box { private Gtk.ComboBox resolution_combobox; private Gtk.TreeStore resolution_tree_store; - private Gtk.ComboBox rotation_combobox; - private Gtk.ListStore rotation_list_store; - private Gtk.ComboBox refresh_combobox; private Gtk.ListStore refresh_list_store; @@ -124,20 +121,17 @@ public class Display.DisplayWidget : Gtk.Box { resolution_combobox.pack_start (text_renderer, true); resolution_combobox.add_attribute (text_renderer, "text", ResolutionColumns.NAME); - rotation_list_store = new Gtk.ListStore (RotationColumns.TOTAL, typeof (string), typeof (int)); - rotation_combobox = new Gtk.ComboBox.with_model (rotation_list_store) { + var rotation_name_expression = new Gtk.PropertyExpression (typeof (VirtualMonitor.Transform), null, "string-representation"); + var rotation_drop_down = new Gtk.DropDown (virtual_monitor.available_transforms, rotation_name_expression) { margin_start = 12, margin_end = 12 }; + virtual_monitor.available_transforms.bind_property ("selected", rotation_drop_down, "selected", BIDIRECTIONAL | SYNC_CREATE); var rotation_label = new Granite.HeaderLabel (_("Screen Rotation")) { - mnemonic_widget = rotation_combobox + mnemonic_widget = rotation_drop_down }; - text_renderer = new Gtk.CellRendererText (); - rotation_combobox.pack_start (text_renderer, true); - rotation_combobox.add_attribute (text_renderer, "text", RotationColumns.NAME); - refresh_list_store = new Gtk.ListStore (RefreshColumns.TOTAL, typeof (string), typeof (Display.MonitorMode)); refresh_combobox = new Gtk.ComboBox.with_model (refresh_list_store) { margin_start = 12, @@ -152,12 +146,6 @@ public class Display.DisplayWidget : Gtk.Box { refresh_combobox.pack_start (text_renderer, true); refresh_combobox.add_attribute (text_renderer, "text", RefreshColumns.NAME); - for (int i = 0; i <= DisplayTransform.FLIPPED_ROTATION_270; i++) { - Gtk.TreeIter iter; - rotation_list_store.append (out iter); - rotation_list_store.set (iter, RotationColumns.NAME, ((DisplayTransform) i).to_string (), RotationColumns.VALUE, i); - } - // Build resolution menu // First, get list of unique resolutions from available modes. Resolution[] resolutions = {}; @@ -270,7 +258,7 @@ public class Display.DisplayWidget : Gtk.Box { popover_box.append (resolution_label); popover_box.append (resolution_combobox); popover_box.append (rotation_label); - popover_box.append (rotation_combobox); + popover_box.append (rotation_drop_down); popover_box.append (refresh_label); popover_box.append (refresh_combobox); @@ -303,12 +291,11 @@ public class Display.DisplayWidget : Gtk.Box { set_primary (virtual_monitor.primary); use_switch.bind_property ("active", resolution_combobox, "sensitive"); - use_switch.bind_property ("active", rotation_combobox, "sensitive"); + use_switch.bind_property ("active", rotation_drop_down, "sensitive"); use_switch.bind_property ("active", refresh_combobox, "sensitive"); use_switch.bind_property ("active", scale_drop_down, "sensitive"); use_switch.notify["active"].connect (() => { - if (rotation_combobox.active == -1) rotation_combobox.set_active (0); if (resolution_combobox.active == -1) resolution_combobox.set_active (0); if (refresh_combobox.active == -1) refresh_combobox.set_active (0); @@ -348,27 +335,18 @@ public class Display.DisplayWidget : Gtk.Box { } virtual_monitor.set_current_mode (new_mode); - rotation_combobox.set_active (0); populate_refresh_rates (); configuration_changed (); check_position (); }); - rotation_combobox.changed.connect (() => { + virtual_monitor.available_transforms.selection_changed.connect (() => { // Prevent breaking autohide by closing popover popover.popdown (); - Value val; - Gtk.TreeIter iter; - rotation_combobox.get_active_iter (out iter); - rotation_list_store.get_value (iter, RotationColumns.VALUE, out val); - - var transform = (DisplayTransform)((int)val); - virtual_monitor.transform = transform; - label.css_classes = {""}; - switch (transform) { + switch (virtual_monitor.transform) { case DisplayTransform.NORMAL: virtual_monitor.get_current_mode_size (out real_width, out real_height); label.label = virtual_monitor_name; @@ -437,11 +415,7 @@ public class Display.DisplayWidget : Gtk.Box { check_position (); }); - rotation_combobox.set_active ((int) virtual_monitor.transform); - on_vm_transform_changed (); - virtual_monitor.modes_changed.connect (on_monitor_modes_changed); - virtual_monitor.notify["transform"].connect (on_vm_transform_changed); configuration_changed (); check_position (); @@ -536,22 +510,6 @@ public class Display.DisplayWidget : Gtk.Box { return result; } - private void on_vm_transform_changed () { - var transform = virtual_monitor.transform; - rotation_list_store.@foreach ((model, path, iter) => { - Value val; - rotation_list_store.get_value (iter, RotationColumns.VALUE, out val); - - var iter_transform = (DisplayTransform)((int)val); - if (iter_transform == transform) { - rotation_combobox.set_active_iter (iter); - return true; - } - - return false; - }); - } - public void set_primary (bool is_primary) { if (is_primary) { primary_image.icon_name = "starred-symbolic";