Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Install Dependencies
run: |
apt update
apt install -y meson libadwaita-1-dev libgranite-7-dev libswitchboard-3-dev valac
apt install -y meson libadwaita-1-dev libgranite-7-dev libpantheon-wayland-1-dev libswitchboard-3-dev valac
- name: Build
env:
DESTDIR: out
Expand Down
10 changes: 10 additions & 0 deletions data/Display.css
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,13 @@ scale.warmth:dir(rtl) trough {
@ORANGE_500
);
}

.monitor-label {
border-radius: 9px;
font-weight: 600;
}

.monitor-label label {
margin: 1em;
text-shadow: 0 1px 1px alpha(white, 0.1);
}
20 changes: 2 additions & 18 deletions src/DisplayPlug.vala
Original file line number Diff line number Diff line change
Expand Up @@ -81,30 +81,14 @@ public class Display.Plug : Switchboard.Plug {
box = new Gtk.Box (VERTICAL, 0);
box.append (headerbar);
box.append (stack);

stack.notify["visible-child"].connect (() => {
if (stack.visible_child == displays_view) {
displays_view.displays_overlay.show_windows ();
} else {
displays_view.displays_overlay.hide_windows ();
}
});
}

return box;
}

public override void shown () {
if (stack.visible_child == displays_view) {
displays_view.displays_overlay.show_windows ();
} else {
displays_view.displays_overlay.hide_windows ();
}
}
public override void shown () { } //Do nothing

public override void hidden () {
displays_view.displays_overlay.hide_windows ();
}
public override void hidden () { } //Do nothing

public override void search_callback (string location) {
stack.visible_child_name = location;
Expand Down
19 changes: 0 additions & 19 deletions src/Interfaces/GalaDBus.vala

This file was deleted.

54 changes: 17 additions & 37 deletions src/Widgets/DisplaysOverlay.vala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class Display.DisplaysOverlay : Gtk.Box {
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 @@ -70,6 +69,7 @@ public class Display.DisplaysOverlay : Gtk.Box {
};

private Gtk.GestureDrag drag_gesture;
private MonitorLabel[] monitor_labels = {};

construct {
add_css_class (Granite.STYLE_CLASS_VIEW);
Expand All @@ -91,6 +91,9 @@ public class Display.DisplaysOverlay : Gtk.Box {
rescan_displays ();

overlay.get_child_position.connect (get_child_position);

map.connect (show_windows);
unmap.connect (hide_windows);
}

static construct {
Expand All @@ -102,20 +105,6 @@ public class Display.DisplaysOverlay : Gtk.Box {
display_provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
);

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

private double prev_dx = 0;
Expand Down Expand Up @@ -204,39 +193,30 @@ public class Display.DisplaysOverlay : Gtk.Box {
scanning = false;
}

public void show_windows () requires (gala_dbus != null) {
public void show_windows () {
hide_windows ();

if (monitor_manager.is_mirrored) {
return;
}

MonitorLabelInfo[] label_infos = {};

foreach (unowned var widget in display_widgets) {
if (widget.virtual_monitor.is_active) {
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
};
var monitor_label = new MonitorLabel (
monitor_labels.length, widget.virtual_monitor.get_display_name (),
widget.bg_color, widget.text_color
);
monitor_label.present ();
monitor_labels += monitor_label;
}
}

try {
gala_dbus.show_monitor_labels (label_infos);
} catch (Error e) {
warning ("Couldn't show monitor labels: %s", e.message);
}
}

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);
public void hide_windows () {
foreach (var monitor_label in monitor_labels) {
monitor_label.destroy ();
}
monitor_labels = {};
}

private void change_active_displays_sensitivity () {
Expand Down
73 changes: 73 additions & 0 deletions src/Widgets/MonitorLabel.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2025 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: LGPL-3.0-or-later
*/

public class Display.MonitorLabel : Gtk.Window, PantheonWayland.ExtendedBehavior {
private const int SPACING = 12;
private const string COLORED_STYLE_CSS = """
.label-%d {
background-color: alpha(%s, 0.8);
color: %s;
}
""";

public int index { get; construct; }
public string label { get; construct; }
public string bg_color { get; construct; }
public string text_color { get; construct; }

public MonitorLabel (int index, string label, string bg_color, string text_color) {
Object (
index: index,
label: label,
bg_color: bg_color,
text_color: text_color
);
}

construct {
child = new Gtk.Label (label);

decorated = false;
resizable = false;
deletable = false;
can_focus = false;
titlebar = new Gtk.Grid () { visible = false };

var provider = new Gtk.CssProvider ();
try {
provider.load_from_string (COLORED_STYLE_CSS.printf (index, bg_color, text_color));
add_css_class ("label-%d".printf (index));
add_css_class ("monitor-label");

Gtk.StyleContext.add_provider_for_display (
Gdk.Display.get_default (),
provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
);
} catch (Error e) {
warning ("Failed to load CSS: %s", e.message);
}

child.realize.connect (on_realize);
}

private void on_realize () {
var display = Gdk.Display.get_default ();
if (display is Gdk.X11.Display) {
unowned var xdisplay = ((Gdk.X11.Display) display).get_xdisplay ();

var window = ((Gdk.X11.Surface) get_surface ()).get_xid ();

var prop = xdisplay.intern_atom ("_MUTTER_HINTS", false);

var value = "monitor-label=%d".printf (index);

xdisplay.change_property (window, prop, X.XA_STRING, 8, 0, (uchar[]) value, value.length);
} else {
connect_to_shell ();
make_monitor_label (index);
}
}
}
4 changes: 3 additions & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ plug_files = files(
'Utils.vala',
'SettingsDaemon.vala',
'DisplayPlug.vala',
'Interfaces/GalaDBus.vala',
'Interfaces/NightLightManager.vala',
'Interfaces/MutterDisplayConfig.vala',
'Interfaces/SensorManager.vala',
Expand All @@ -15,6 +14,7 @@ plug_files = files(
'Views' / 'FiltersView.vala',
'Widgets/DisplayWidget.vala',
'Widgets/DisplaysOverlay.vala',
'Widgets' / 'MonitorLabel.vala',
)

switchboard_dep = dependency('switchboard-3')
Expand All @@ -31,7 +31,9 @@ shared_module(
dependency('gobject-2.0'),
dependency('granite-7'),
dependency('gtk4'),
dependency('gtk4-x11'),
dependency('libadwaita-1'),
dependency('pantheon-wayland-1'),
meson.get_compiler('vala').find_library('posix'),
switchboard_dep
],
Expand Down
Loading