From f13446870bf4fed53c90c3d3c2e7285d42d2b67c Mon Sep 17 00:00:00 2001 From: lenemter Date: Tue, 16 Jan 2024 19:17:01 +0900 Subject: [PATCH 1/3] Use gala to show display labels --- data/Display.css | 5 --- src/Interfaces/GalaDBus.vala | 17 ++++++++++ src/Widgets/DisplayWidget.vala | 19 +++++------ src/Widgets/DisplayWindow.vala | 57 -------------------------------- src/Widgets/DisplaysOverlay.vala | 55 +++++++++++++++++++++--------- src/meson.build | 2 +- 6 files changed, 67 insertions(+), 88 deletions(-) create mode 100644 src/Interfaces/GalaDBus.vala delete mode 100644 src/Widgets/DisplayWindow.vala diff --git a/data/Display.css b/data/Display.css index 121cd320..a316534f 100644 --- a/data/Display.css +++ b/data/Display.css @@ -9,11 +9,6 @@ -gtk-icon-palette: warning white; } -/* Don't use alpha for the on-screen identifier */ -window.colored { - background-color: alpha (@BG_COLOR, 0.8); -} - widget.colored { border: 1px solid mix(@BG_COLOR_ALPHA, @TEXT_COLOR, 0.3); } diff --git a/src/Interfaces/GalaDBus.vala b/src/Interfaces/GalaDBus.vala new file mode 100644 index 00000000..6b3394aa --- /dev/null +++ b/src/Interfaces/GalaDBus.vala @@ -0,0 +1,17 @@ +/* + * SPDX-License-Identifier: LGPL-2.0-or-later + * SPDX-FileCopyrightText: 2024 elementary, Inc. (https://elementary.io) + */ + +[DBus (name = "org.pantheon.gala")] +public interface GalaDBus : Object { + public abstract void show_monitor_labels (MonitorLabelInfo[] label_infos) throws GLib.DBusError, GLib.IOError; + public abstract void hide_monitor_labels () throws GLib.DBusError, GLib.IOError; +} + +public struct MonitorLabelInfo { + public int monitor; + public string label; + public string background_color; + public string text_color; +} diff --git a/src/Widgets/DisplayWidget.vala b/src/Widgets/DisplayWidget.vala index 6cddcea0..419d9f6e 100644 --- a/src/Widgets/DisplayWidget.vala +++ b/src/Widgets/DisplayWidget.vala @@ -1,5 +1,5 @@ /*- - * Copyright 2014–2021 elementary, Inc. + * Copyright 2014–2024 elementary, Inc. * 2014–2018 Corentin Noël * * This software is free software; you can redistribute it and/or @@ -35,6 +35,8 @@ public class Display.DisplayWidget : Gtk.EventBox { public signal void active_changed (); public Display.VirtualMonitor virtual_monitor { get; construct; } + public string bg_color { get; construct; } + public string text_color { get; construct; } public double window_ratio { get; private set; default = 1.0; } public int delta_x { get; set; default = 0; } @@ -45,7 +47,6 @@ public class Display.DisplayWidget : Gtk.EventBox { private double start_y = 0; private bool holding = false; - public DisplayWindow display_window { get; private set; } public Gtk.Button primary_image { get; private set; } public Gtk.MenuButton toggle_settings { get; private set; } @@ -85,8 +86,12 @@ public class Display.DisplayWidget : Gtk.EventBox { TOTAL } - public DisplayWidget (Display.VirtualMonitor virtual_monitor) { - Object (virtual_monitor: virtual_monitor); + public DisplayWidget (Display.VirtualMonitor virtual_monitor, string bg_color, string text_color) { + Object ( + virtual_monitor: virtual_monitor, + bg_color: bg_color, + text_color: text_color + ); } construct { @@ -94,10 +99,6 @@ public class Display.DisplayWidget : Gtk.EventBox { events |= Gdk.EventMask.BUTTON_RELEASE_MASK; events |= Gdk.EventMask.POINTER_MOTION_MASK; - display_window = new DisplayWindow (virtual_monitor) { - attached_to = this - }; - virtual_monitor.get_current_mode_size (out real_width, out real_height); primary_image = new Gtk.Button.from_icon_name ("non-starred-symbolic") { @@ -291,8 +292,6 @@ public class Display.DisplayWidget : Gtk.EventBox { set_primary (virtual_monitor.primary); add (grid); - destroy.connect (() => display_window.destroy ()); - use_switch.bind_property ("active", resolution_combobox, "sensitive"); use_switch.bind_property ("active", rotation_combobox, "sensitive"); use_switch.bind_property ("active", refresh_combobox, "sensitive"); diff --git a/src/Widgets/DisplayWindow.vala b/src/Widgets/DisplayWindow.vala deleted file mode 100644 index b0710a90..00000000 --- a/src/Widgets/DisplayWindow.vala +++ /dev/null @@ -1,57 +0,0 @@ -/*- - * Copyright 2014-2021 elementary, Inc. - * - * 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. - * - * Authored by: Corentin Noël - */ - -public class Display.DisplayWindow : Hdy.Window { - public Display.VirtualMonitor virtual_monitor { get; construct; } - - private const int SPACING = 12; - - public DisplayWindow (Display.VirtualMonitor virtual_monitor) { - Object (virtual_monitor: virtual_monitor); - } - - construct { - var label = new Gtk.Label (virtual_monitor.get_display_name ()) { - margin = 12 - }; - - add (label); - - input_shape_combine_region (null); - accept_focus = false; - decorated = false; - resizable = false; - deletable = false; - can_focus = false; - skip_taskbar_hint = true; - skip_pager_hint = true; - type_hint = Gdk.WindowTypeHint.TOOLTIP; - set_keep_above (true); - - stick (); - - var scale_factor = get_style_context ().get_scale (); - move ( - (int) (virtual_monitor.current_x / scale_factor) + SPACING, - (int) (virtual_monitor.current_y / scale_factor) + SPACING - ); - } -} diff --git a/src/Widgets/DisplaysOverlay.vala b/src/Widgets/DisplaysOverlay.vala index f60e0f14..9735dd18 100644 --- a/src/Widgets/DisplaysOverlay.vala +++ b/src/Widgets/DisplaysOverlay.vala @@ -34,6 +34,7 @@ public class Display.DisplaysOverlay : Gtk.Overlay { private int default_y_margin = 0; private unowned Display.MonitorManager monitor_manager; + private static GalaDBus gala_dbus = null; public int active_displays { get; set; default = 0; } private List display_widgets; @@ -82,6 +83,20 @@ public class Display.DisplaysOverlay : Gtk.Overlay { static construct { display_provider = new Gtk.CssProvider (); display_provider.load_from_resource ("io/elementary/switchboard/display/Display.css"); + + GLib.Bus.get_proxy.begin ( + GLib.BusType.SESSION, + "org.pantheon.gala", + "/org/pantheon/gala", + GLib.DBusProxyFlags.NONE, + null, + (obj, res) => { + try { + gala_dbus = GLib.Bus.get_proxy.end (res); + } catch (GLib.Error e) { + critical (e.message); + } + }); } public override bool get_child_position (Gtk.Widget widget, out Gdk.Rectangle allocation) { @@ -129,22 +144,37 @@ public class Display.DisplaysOverlay : Gtk.Overlay { scanning = false; } - public void show_windows () { + public void show_windows () requires (gala_dbus != null) { if (monitor_manager.is_mirrored) { return; } + MonitorLabelInfo[] label_infos = {}; + foreach (unowned var widget in display_widgets) { if (widget.virtual_monitor.is_active) { - widget.display_window.show_all (); + label_infos += MonitorLabelInfo () { + monitor = label_infos.length, + label = widget.virtual_monitor.get_display_name (), + background_color = widget.bg_color, + text_color = widget.text_color + }; } } + + try { + gala_dbus.show_monitor_labels (label_infos); + } catch (Error e) { + warning ("Couldn't show monitor labels: %s", e.message); + } } - public void hide_windows () { - foreach (unowned var widget in display_widgets) { - widget.display_window.hide (); - }; + public void hide_windows () requires (gala_dbus != null) { + try { + gala_dbus.hide_monitor_labels (); + } catch (Error e) { + warning ("Couldn't hide monitor labels: %s", e.message); + } } private void change_active_displays_sensitivity () { @@ -187,16 +217,16 @@ public class Display.DisplaysOverlay : Gtk.Overlay { } private void add_output (Display.VirtualMonitor virtual_monitor) { - var display_widget = new DisplayWidget (virtual_monitor); current_allocated_width = 0; current_allocated_height = 0; + + var color_number = (get_children ().length () - 2) % 7; + var display_widget = new DisplayWidget (virtual_monitor, colors[color_number], text_colors[color_number]); add_overlay (display_widget); display_widgets.append (display_widget); var provider = new Gtk.CssProvider (); try { - var color_number = (get_children ().length () - 2) % 7; - var colored_css = COLORED_STYLE_CSS.printf (colors[color_number], text_colors[color_number]); provider.load_from_data (colored_css, colored_css.length); @@ -205,11 +235,6 @@ public class Display.DisplaysOverlay : Gtk.Overlay { context.add_provider (display_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); context.add_class ("colored"); - context = display_widget.display_window.get_style_context (); - context.add_provider (provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); - context.add_provider (display_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); - context.add_class ("colored"); - context = display_widget.primary_image.get_style_context (); context.add_provider (provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); context.add_provider (display_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); @@ -243,7 +268,7 @@ public class Display.DisplaysOverlay : Gtk.Overlay { }); if (!monitor_manager.is_mirrored && virtual_monitor.is_active) { - display_widget.display_window.show_all (); + show_windows (); } display_widget.end_grab.connect ((delta_x, delta_y) => { diff --git a/src/meson.build b/src/meson.build index 0398be8a..14fafff8 100644 --- a/src/meson.build +++ b/src/meson.build @@ -2,6 +2,7 @@ plug_files = files( 'Utils.vala', 'SettingsDaemon.vala', 'DisplayPlug.vala', + 'Interfaces/GalaDBus.vala', 'Interfaces/NightLightManager.vala', 'Interfaces/MutterDisplayConfig.vala', 'Objects/VirtualMonitor.vala', @@ -11,7 +12,6 @@ plug_files = files( 'Views/NightLightView.vala', 'Views/DisplaysView.vala', 'Views' / 'FiltersView.vala', - 'Widgets/DisplayWindow.vala', 'Widgets/DisplayWidget.vala', 'Widgets/DisplaysOverlay.vala', ) From 844ebdbb4e1d8a30ed37725fefaa893921188568 Mon Sep 17 00:00:00 2001 From: lenemter Date: Tue, 16 Jan 2024 19:39:28 +0900 Subject: [PATCH 2/3] Fix lint --- src/Interfaces/GalaDBus.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Interfaces/GalaDBus.vala b/src/Interfaces/GalaDBus.vala index 6b3394aa..771ec769 100644 --- a/src/Interfaces/GalaDBus.vala +++ b/src/Interfaces/GalaDBus.vala @@ -8,7 +8,7 @@ public interface GalaDBus : Object { public abstract void show_monitor_labels (MonitorLabelInfo[] label_infos) throws GLib.DBusError, GLib.IOError; public abstract void hide_monitor_labels () throws GLib.DBusError, GLib.IOError; } - + public struct MonitorLabelInfo { public int monitor; public string label; From 7f0220fb32b7a8382586bb8f0cafe93bca5c86a5 Mon Sep 17 00:00:00 2001 From: Leonhard Date: Mon, 22 Jan 2024 15:55:50 +0100 Subject: [PATCH 3/3] Update it but it's broken --- src/Interfaces/GalaDBus.vala | 4 +++- src/Widgets/DisplaysOverlay.vala | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Interfaces/GalaDBus.vala b/src/Interfaces/GalaDBus.vala index 771ec769..cc7e85d0 100644 --- a/src/Interfaces/GalaDBus.vala +++ b/src/Interfaces/GalaDBus.vala @@ -3,7 +3,7 @@ * SPDX-FileCopyrightText: 2024 elementary, Inc. (https://elementary.io) */ -[DBus (name = "org.pantheon.gala")] +[DBus (name = "org.pantheon.gala.daemon")] public interface GalaDBus : Object { public abstract void show_monitor_labels (MonitorLabelInfo[] label_infos) throws GLib.DBusError, GLib.IOError; public abstract void hide_monitor_labels () throws GLib.DBusError, GLib.IOError; @@ -14,4 +14,6 @@ public struct MonitorLabelInfo { public string label; public string background_color; public string text_color; + public int x; + public int y; } diff --git a/src/Widgets/DisplaysOverlay.vala b/src/Widgets/DisplaysOverlay.vala index 9735dd18..dd618643 100644 --- a/src/Widgets/DisplaysOverlay.vala +++ b/src/Widgets/DisplaysOverlay.vala @@ -86,8 +86,8 @@ public class Display.DisplaysOverlay : Gtk.Overlay { GLib.Bus.get_proxy.begin ( GLib.BusType.SESSION, - "org.pantheon.gala", - "/org/pantheon/gala", + "org.pantheon.gala.daemon", + "/org/pantheon/gala/daemon", GLib.DBusProxyFlags.NONE, null, (obj, res) => { @@ -157,7 +157,9 @@ public class Display.DisplaysOverlay : Gtk.Overlay { monitor = label_infos.length, label = widget.virtual_monitor.get_display_name (), background_color = widget.bg_color, - text_color = widget.text_color + text_color = widget.text_color, + x = widget.virtual_monitor.current_x, + y = widget.virtual_monitor.current_y }; } }