Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use daemon to show display labels #372

Merged
merged 5 commits into from
Feb 21, 2024
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
5 changes: 0 additions & 5 deletions data/Display.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
19 changes: 19 additions & 0 deletions src/Interfaces/GalaDBus.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* SPDX-License-Identifier: LGPL-2.0-or-later
* SPDX-FileCopyrightText: 2024 elementary, Inc. (https://elementary.io)
*/

[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;
}

public struct MonitorLabelInfo {
public int monitor;
public string label;
public string background_color;
public string text_color;
public int x;
public int y;
}
19 changes: 9 additions & 10 deletions src/Widgets/DisplayWidget.vala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*-
* Copyright 2014–2021 elementary, Inc.
* Copyright 2014–2024 elementary, Inc.
* 2014–2018 Corentin Noël <corentin@elementary.io>
*
* This software is free software; you can redistribute it and/or
Expand Down Expand Up @@ -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; }
Expand All @@ -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; }

Expand Down Expand Up @@ -85,19 +86,19 @@ 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 {
events |= Gdk.EventMask.BUTTON_PRESS_MASK;
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") {
Expand Down Expand Up @@ -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");
Expand Down
57 changes: 0 additions & 57 deletions src/Widgets/DisplayWindow.vala

This file was deleted.

57 changes: 42 additions & 15 deletions src/Widgets/DisplaysOverlay.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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<DisplayWidget> display_widgets;
Expand Down Expand Up @@ -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<GalaDBus> (
GLib.BusType.SESSION,
"org.pantheon.gala.daemon",
"/org/pantheon/gala/daemon",
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) {
Expand Down Expand Up @@ -129,22 +144,39 @@ 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,
x = widget.virtual_monitor.current_x,
y = widget.virtual_monitor.current_y
};
}
}

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 () {
Expand Down Expand Up @@ -187,16 +219,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);

Expand All @@ -205,11 +237,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);
Expand Down Expand Up @@ -243,7 +270,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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
)
Expand Down