Skip to content
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
25 changes: 24 additions & 1 deletion src/Objects/VirtualMonitor.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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<Display.Monitor> monitors { get; construct; }

Expand All @@ -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
Expand Down Expand Up @@ -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 () {
Expand Down
58 changes: 8 additions & 50 deletions src/Widgets/DisplayWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -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 = {};
Expand Down Expand Up @@ -258,7 +246,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);

Expand Down Expand Up @@ -291,12 +279,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);

Expand Down Expand Up @@ -336,27 +323,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;
Expand Down Expand Up @@ -425,11 +403,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 ();
Expand Down Expand Up @@ -524,22 +498,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";
Expand Down