Skip to content

Commit

Permalink
Make this bitesize again
Browse files Browse the repository at this point in the history
  • Loading branch information
meisenzahl committed Feb 10, 2021
1 parent c88bae4 commit 1ecde68
Showing 1 changed file with 25 additions and 59 deletions.
84 changes: 25 additions & 59 deletions src/Views/DisplaysView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,12 @@
* Oleksandr Lynok <oleksandr.lynok@gmail.com>
*/

public class Display.DisplaysView : Gtk.Grid {
public class Display.DisplaysView : Gtk.Grid {
public DisplaysOverlay displays_overlay;

private Gtk.ComboBoxText dpi_combo;
private Gtk.Grid rotation_lock_grid;

private const string TOUCHSCREEN_SETTINGS_PATH = "org.gnome.settings-daemon.peripherals.touchscreen";

construct {
unowned Display.MonitorManager monitor_manager = Display.MonitorManager.get_default ();

displays_overlay = new DisplaysOverlay ();

var mirror_label = new Gtk.Label (_("Mirror Display:"));
Expand All @@ -46,19 +41,10 @@ public class Display.DisplaysView : Gtk.Grid {

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

int width, height;
monitor_manager.virtual_monitors[0].get_current_mode_size (out width, out height);

dpi_combo = new Gtk.ComboBoxText ();
dpi_combo.append_text (_("LoDPI") + " (1×)");
int max_scale = height / 768;
for (int i = 2; i <= max_scale; i++) {
dpi_combo.append_text (_("HiDPI") + " (%d×)".printf (i));
}

if (max_scale < 2) {
dpi_combo.sensitive = false;
}
dpi_combo.append_text (_("HiDPI") + " (2×)");
dpi_combo.append_text (_("HiDPI") + " (3×)");

var dpi_grid = new Gtk.Grid () {
column_spacing = 6,
Expand Down Expand Up @@ -87,20 +73,29 @@ public class Display.DisplaysView : Gtk.Grid {
action_bar.pack_start (dpi_grid);
action_bar.pack_start (mirror_grid);

var schema_source = GLib.SettingsSchemaSource.get_default ();
var rotation_lock_schema = schema_source.lookup (TOUCHSCREEN_SETTINGS_PATH, true);
if (rotation_lock_schema != null) {
rotation_lock_grid = new Gtk.Grid () {
column_spacing = 6,
margin = 6,
valign = Gtk.Align.CENTER
};
if (Utils.has_touchscreen ()) {
var schema_source = GLib.SettingsSchemaSource.get_default ();
var rotation_lock_schema = schema_source.lookup ("org.gnome.settings-daemon.peripherals.touchscreen", true);
if (rotation_lock_schema != null) {
var touchscreen_settings = new GLib.Settings.full (rotation_lock_schema, null, null);

var rotation_lock_label = new Gtk.Label (_("Rotation Lock:"));
var rotation_lock_switch = new Gtk.Switch ();

var rotation_lock_grid = new Gtk.Grid () {
column_spacing = 6,
margin = 6,
valign = Gtk.Align.CENTER
};
rotation_lock_grid.add (rotation_lock_label);
rotation_lock_grid.add (rotation_lock_switch);

action_bar.pack_start (rotation_lock_grid);
action_bar.pack_start (rotation_lock_grid);

detect_accelerometer.begin ();
} else {
info ("Schema \"org.gnome.settings-daemon.peripherals.touchscreen\" is not installed on your system.");
touchscreen_settings.bind ("orientation-lock", rotation_lock_switch, "state", SettingsBindFlags.DEFAULT);
} else {
info ("Schema \"org.gnome.settings-daemon.peripherals.touchscreen\" is not installed on your system.");
}
}

action_bar.pack_end (button_grid);
Expand All @@ -115,6 +110,7 @@ public class Display.DisplaysView : Gtk.Grid {
apply_button.sensitive = changed;
});

unowned Display.MonitorManager monitor_manager = Display.MonitorManager.get_default ();
mirror_grid.sensitive = monitor_manager.monitors.size > 1;
monitor_manager.notify["monitor-number"].connect (() => {
mirror_grid.sensitive = monitor_manager.monitors.size > 1;
Expand Down Expand Up @@ -143,34 +139,4 @@ public class Display.DisplaysView : Gtk.Grid {
apply_button.sensitive = true;
});
}

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

try {
SensorProxy sensors = yield GLib.Bus.get_proxy (BusType.SYSTEM, "net.hadess.SensorProxy", "/net/hadess/SensorProxy");
has_accelerometer = sensors.has_accelerometer;
} catch (Error e) {
info ("Unable to connect to SensorProxy bus, probably means no accelerometer supported: %s", e.message);
}

if (has_accelerometer) {
var touchscreen_settings = new GLib.Settings (TOUCHSCREEN_SETTINGS_PATH);

var rotation_lock_label = new Gtk.Label (_("Rotation Lock:"));
var rotation_lock_switch = new Gtk.Switch ();

rotation_lock_grid.add (rotation_lock_label);
rotation_lock_grid.add (rotation_lock_switch);

touchscreen_settings.bind ("orientation-lock", rotation_lock_switch, "state", SettingsBindFlags.DEFAULT);

rotation_lock_grid.show_all ();
}
}

[DBus (name = "net.hadess.SensorProxy")]
private interface SensorProxy : GLib.DBusProxy {
public abstract bool has_accelerometer { get; }
}
}

0 comments on commit 1ecde68

Please sign in to comment.