From 293fa0d6a596ba9f1e9dd78a3da171fea3110b84 Mon Sep 17 00:00:00 2001 From: Geoff Paul Date: Sat, 7 Mar 2020 14:07:01 -0600 Subject: [PATCH 25/81] Add option to span background across multiple monitors Signed-off-by: Mike Gabriel --- data/x.dm.slick-greeter.gschema.xml | 8 +++ src/background.vala | 87 ++++++++++++++++++++++------- src/greeter-list.vala | 1 - src/main-window.vala | 22 +------- src/settings.vala | 2 + 5 files changed, 81 insertions(+), 39 deletions(-) diff --git a/data/x.dm.slick-greeter.gschema.xml b/data/x.dm.slick-greeter.gschema.xml index 90ebec8..7ceba14 100644 --- a/data/x.dm.slick-greeter.gschema.xml +++ b/data/x.dm.slick-greeter.gschema.xml @@ -9,6 +9,14 @@ '#000000' Background color (e.g. #772953), set before wallpaper is seen + + + + + + 'zoom' + Determines how the background image is rendered + true Whether to draw user backgrounds diff --git a/src/background.vala b/src/background.vala index f0789bf..e258d84 100644 --- a/src/background.vala +++ b/src/background.vala @@ -29,7 +29,6 @@ class BackgroundLoader : Object public Gdk.RGBA average_color; private Cairo.Surface target_surface; - private bool draw_grid; private Thread thread; private Gdk.Pixbuf[] images; private bool finished; @@ -37,7 +36,7 @@ class BackgroundLoader : Object public signal void loaded (); - public BackgroundLoader (Cairo.Surface target_surface, string filename, int[] widths, int[] heights, bool draw_grid) + public BackgroundLoader (Cairo.Surface target_surface, string filename, int[] widths, int[] heights) { this.target_surface = target_surface; this.filename = filename; @@ -45,7 +44,6 @@ class BackgroundLoader : Object this.heights = heights; patterns = new Cairo.Pattern[widths.length]; images = new Gdk.Pixbuf[widths.length]; - this.draw_grid = draw_grid; } public bool load () @@ -388,11 +386,14 @@ public class Monitor public class Background : Gtk.Fixed { + [Flags] public enum DrawFlags { NONE, GRID, + SPAN, } + private DrawFlags flags = DrawFlags.NONE; /* Fallback color - shown upon first startup, until an async background loader finishes, * or until a user background or default background is loaded. @@ -464,7 +465,28 @@ public class Background : Gtk.Fixed } } - public bool draw_grid { get; set; default = true; } + /* Width - total pixel width of the entire background canvas. This total width + * should account for the relative geometry of all attached monitors. + */ + + private int _width = 0; + public int width { + get { + return _width; + } + } + + /* Height - total pixel height of the entire background canvas. This total height + * should account for the relative geometry of all attached monitors. + */ + + private int _height = 0; + public int height { + get { + return _height; + } + } + public double alpha { get; private set; default = 1.0; } public Gdk.RGBA average_color { get { return current.average_color; } } @@ -493,8 +515,13 @@ public class Background : Gtk.Fixed timer = null; resize_mode = Gtk.ResizeMode.QUEUE; - draw_grid = UGSettings.get_boolean (UGSettings.KEY_DRAW_GRID); loaders = new HashTable (str_hash, str_equal); + if (UGSettings.get_boolean (UGSettings.KEY_DRAW_GRID)) + flags |= DrawFlags.GRID; + + var mode = UGSettings.get_string (UGSettings.KEY_BACKGROUND_MODE); + if (mode == "spanned") + flags |= DrawFlags.SPAN; show (); } @@ -545,7 +572,15 @@ public class Background : Gtk.Fixed { this.monitors = new List (); foreach (var m in monitors) + { + if (_width < m.x + m.width) + _width = m.x + m.width; + + if (_height < m.y + m.height) + _height = m.y + m.height; + this.monitors.append (m); + } queue_draw (); } @@ -577,9 +612,6 @@ public class Background : Gtk.Fixed public override bool draw (Cairo.Context c) { - var flags = DrawFlags.NONE; - if (draw_grid) - flags |= DrawFlags.GRID; draw_full (c, flags); return base.draw (c); } @@ -625,7 +657,7 @@ public class Background : Gtk.Fixed c.restore (); - if ((flags & DrawFlags.GRID) != 0) + if (DrawFlags.GRID in flags) overlay_grid (c); } @@ -633,14 +665,22 @@ public class Background : Gtk.Fixed { foreach (var monitor in monitors) { - var pattern = background.get_pattern (monitor.width, monitor.height); + Cairo.Pattern? pattern; + var matrix = Cairo.Matrix.identity (); + if (DrawFlags.SPAN in flags) + { + pattern = background.get_pattern (_width, _height); + } + else + { + pattern = background.get_pattern (monitor.width, monitor.height); + matrix.translate (-monitor.x, -monitor.y); + } + if (pattern == null) continue; c.save (); - pattern = background.get_pattern (monitor.width, monitor.height); - var matrix = Cairo.Matrix.identity (); - matrix.translate (-monitor.x, -monitor.y); pattern.set_matrix (matrix); c.set_source (pattern); c.rectangle (monitor.x, monitor.y, monitor.width, monitor.height); @@ -728,19 +768,28 @@ public class Background : Gtk.Fixed var widths = new int[monitors.length ()]; var heights = new int[monitors.length ()]; var n_sizes = 0; - foreach (var monitor in monitors) + if (DrawFlags.SPAN in flags) + { + widths[n_sizes] = _width; + heights[n_sizes] = _height; + n_sizes++; + } + else { - if (monitor_is_unique_size (monitor)) + foreach (var monitor in monitors) { - widths[n_sizes] = monitor.width; - heights[n_sizes] = monitor.height; - n_sizes++; + if (monitor_is_unique_size (monitor)) + { + widths[n_sizes] = monitor.width; + heights[n_sizes] = monitor.height; + n_sizes++; + } } } widths.resize (n_sizes); heights.resize (n_sizes); - b = new BackgroundLoader (target_surface, filename, widths, heights, draw_grid); + b = new BackgroundLoader (target_surface, filename, widths, heights); b.logo = version_logo_surface; b.loaded.connect (() => { reload (); }); b.load (); diff --git a/src/greeter-list.vala b/src/greeter-list.vala index 6d8f1f6..958720e 100644 --- a/src/greeter-list.vala +++ b/src/greeter-list.vala @@ -928,7 +928,6 @@ public abstract class GreeterList : FadableBox } /* Set the background */ - background.draw_grid = false; background.queue_draw (); } diff --git a/src/main-window.vala b/src/main-window.vala index ddd3c00..3c4fb2b 100644 --- a/src/main-window.vala +++ b/src/main-window.vala @@ -32,8 +32,6 @@ public class MainWindow : Gtk.Window private Gtk.Box hbox; private Gtk.Button back_button; private ShutdownDialog? shutdown_dialog = null; - private int window_size_x; - private int window_size_y; private bool do_resize; public ListStack stack; @@ -131,8 +129,6 @@ public class MainWindow : Gtk.Window add_user_list (); - window_size_x = 0; - window_size_y = 0; primary_monitor = null; do_resize = false; @@ -147,7 +143,7 @@ public class MainWindow : Gtk.Window monitors.append (new Monitor (800, 120, 640, 480)); background.set_monitors (monitors); move_to_monitor (monitors.nth_data (0)); - resize (800 + 640, 600); + resize (background.width, background.height); } else { @@ -212,7 +208,7 @@ public class MainWindow : Gtk.Window /* Setup the size and position of the window */ public void setup_window () { - resize (window_size_x, window_size_y); + resize (background.width, background.height); move (0, 0); move_to_monitor (primary_monitor); } @@ -223,8 +219,6 @@ public class MainWindow : Gtk.Window Gdk.Monitor primary = display.get_primary_monitor(); Gdk.Rectangle geometry; - window_size_x = 0; - window_size_y = 0; monitors = new List (); primary_monitor = null; @@ -234,16 +228,6 @@ public class MainWindow : Gtk.Window geometry = monitor.get_geometry (); debug ("Monitor %d is %dx%d pixels at %d,%d", i, geometry.width, geometry.height, geometry.x, geometry.y); - if (window_size_x < geometry.x + geometry.width) - { - window_size_x = geometry.x + geometry.width; - } - - if (window_size_y < geometry.y + geometry.height) - { - window_size_y = geometry.y + geometry.height; - } - if (monitor_is_unique_position (display, i)) { var greeter_monitor = new Monitor (geometry.x, geometry.y, geometry.width, geometry.height); @@ -258,7 +242,7 @@ public class MainWindow : Gtk.Window } } - debug ("MainWindow is %dx%d pixels", window_size_x, window_size_y); + debug ("MainWindow is %dx%d pixels", background.width, background.height); background.set_monitors (monitors); diff --git a/src/settings.vala b/src/settings.vala index 7d43449..3822939 100644 --- a/src/settings.vala +++ b/src/settings.vala @@ -22,6 +22,7 @@ public class UGSettings { public const string KEY_BACKGROUND = "background"; public const string KEY_BACKGROUND_COLOR = "background-color"; + public const string KEY_BACKGROUND_MODE = "background-mode"; public const string KEY_DRAW_USER_BACKGROUNDS = "draw-user-backgrounds"; public const string KEY_DRAW_GRID = "draw-grid"; public const string KEY_SHOW_HOSTNAME = "show-hostname"; @@ -119,6 +120,7 @@ public class UGSettings var string_keys = new List (); string_keys.append (KEY_BACKGROUND); string_keys.append (KEY_BACKGROUND_COLOR); + string_keys.append (KEY_BACKGROUND_MODE); string_keys.append (KEY_LOGO); string_keys.append (KEY_OTHER_MONITORS_LOGO); string_keys.append (KEY_THEME_NAME); -- 2.30.2