Skip to content

Commit

Permalink
DisplaysView: Gtk4 prep (#373)
Browse files Browse the repository at this point in the history
* DisplaysView: Gtk4 prep

* Bump copyright header
  • Loading branch information
danirabbit authored Jan 23, 2024
1 parent f7ee92b commit bca923c
Showing 1 changed file with 47 additions and 54 deletions.
101 changes: 47 additions & 54 deletions src/Views/DisplaysView.vala
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
/*-
* Copyright (c) 2014-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: LGPL-2.0-or-later
* SPDX-FileCopyrightText: 2014-2023 elementary, Inc. (https://elementary.io)
*
* Authored by: Corentin Noël <corentin@elementary.io>
* Oleksandr Lynok <oleksandr.lynok@gmail.com>
*/

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

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

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

Expand All @@ -34,13 +20,15 @@ public class Display.DisplaysView : Gtk.Grid {
var mirror_label = new Gtk.Label (_("Mirror Display:"));
var mirror_switch = new Gtk.Switch ();

var mirror_grid = new Gtk.Grid () {
column_spacing = 6,
margin = 6,
valign = Gtk.Align.CENTER
var mirror_box = new Gtk.Box (HORIZONTAL, 6) {
margin_top = 6,
margin_end = 6,
margin_bottom = 6,
margin_start = 6,
valign = CENTER
};
mirror_grid.add (mirror_label);
mirror_grid.add (mirror_switch);
mirror_box.add (mirror_label);
mirror_box.add (mirror_switch);

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

Expand All @@ -49,53 +37,59 @@ public class Display.DisplaysView : Gtk.Grid {
dpi_combo.append_text (_("HiDPI") + " (2×)");
dpi_combo.append_text (_("HiDPI") + " (3×)");

var dpi_grid = new Gtk.Grid () {
column_spacing = 6,
margin = 6
var dpi_box = new Gtk.Box (HORIZONTAL, 6) {
margin_top = 6,
margin_end = 6,
margin_bottom = 6,
margin_start = 6
};
dpi_grid.add (dpi_label);
dpi_grid.add (dpi_combo);
dpi_box.add (dpi_label);
dpi_box.add (dpi_combo);

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

var apply_button = new Gtk.Button.with_label (_("Apply"));
apply_button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
apply_button.sensitive = false;

var button_grid = new Gtk.Grid () {
column_homogeneous = true,
column_spacing = 6,
margin = 6,
valign = Gtk.Align.CENTER
var button_box = new Gtk.Box (HORIZONTAL, 6) {
homogeneous = true,
margin_top = 6,
margin_end = 6,
margin_bottom = 6,
margin_start = 6,
valign = CENTER
};
button_grid.add (detect_button);
button_grid.add (apply_button);
button_box.add (detect_button);
button_box.add (apply_button);

var action_bar = new Gtk.ActionBar ();
action_bar.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);
action_bar.pack_start (dpi_grid);
action_bar.pack_start (mirror_grid);
action_bar.pack_start (dpi_box);
action_bar.pack_start (mirror_box);

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
rotation_lock_box = new Gtk.Box (HORIZONTAL, 6) {
margin_top = 6,
margin_end = 6,
margin_bottom = 6,
margin_start = 6,
valign = CENTER
};

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

detect_accelerometer.begin ();
} else {
info ("Schema \"org.gnome.settings-daemon.peripherals.touchscreen\" is not installed on your system.");
}

action_bar.pack_end (button_grid);
action_bar.pack_end (button_box);

orientation = Gtk.Orientation.VERTICAL;
add (new Gtk.Separator (Gtk.Orientation.HORIZONTAL));
orientation = VERTICAL;
add (new Gtk.Separator (HORIZONTAL));
add (displays_overlay);
add (action_bar);

Expand All @@ -104,9 +98,9 @@ public class Display.DisplaysView : Gtk.Grid {
});

unowned Display.MonitorManager monitor_manager = Display.MonitorManager.get_default ();
mirror_grid.sensitive = monitor_manager.monitors.size > 1;
mirror_box.sensitive = monitor_manager.monitors.size > 1;
monitor_manager.notify["monitor-number"].connect (() => {
mirror_grid.sensitive = monitor_manager.monitors.size > 1;
mirror_box.sensitive = monitor_manager.monitors.size > 1;
});

detect_button.clicked.connect (() => displays_overlay.rescan_displays ());
Expand Down Expand Up @@ -149,12 +143,11 @@ public class Display.DisplaysView : Gtk.Grid {
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_box.add (rotation_lock_label);
rotation_lock_box.add (rotation_lock_switch);
rotation_lock_box.show_all ();

rotation_lock_grid.show_all ();
touchscreen_settings.bind ("orientation-lock", rotation_lock_switch, "state", DEFAULT);
}
}

Expand Down

0 comments on commit bca923c

Please sign in to comment.