Skip to content

Commit 0a23871

Browse files
committed
Add API for making monitor label via wayland protocol
1 parent ce7eedd commit 0a23871

File tree

6 files changed

+75
-0
lines changed

6 files changed

+75
-0
lines changed

protocol/pantheon-desktop-shell-v1.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,5 +159,14 @@
159159

160160
<arg name="dim" type="uint" summary="1 to dim, 0 to not dim"/>
161161
</request>
162+
163+
<request name="make_monitor_label">
164+
<description summary="makes the surface a monitor label for the given monitor">
165+
Request to make the surface a monitor label for the given monitor. The surface will be placed
166+
in the top left corner of the monitor and will be kept above other surfaces.
167+
</description>
168+
169+
<arg name="monitor_index" type="int" summary="the index of the monitor this surface should label"/>
170+
</request>
162171
</interface>
163172
</protocol>

protocol/pantheon-desktop-shell.vapi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ namespace Pantheon.Desktop {
6262
public MakeCentered make_centered;
6363
public Focus focus;
6464
public MakeModal make_modal;
65+
public MakeMonitorLabel make_monitor_label;
6566
}
6667

6768
[CCode (has_target = false, has_typedef = false)]
@@ -91,5 +92,7 @@ namespace Pantheon.Desktop {
9192
[CCode (has_target = false, has_typedef = false)]
9293
public delegate void MakeModal (Wl.Client client, Wl.Resource resource, uint dim);
9394
[CCode (has_target = false, has_typedef = false)]
95+
public delegate void MakeMonitorLabel (Wl.Client client, Wl.Resource resource, int monitor_index);
96+
[CCode (has_target = false, has_typedef = false)]
9497
public delegate void Destroy (Wl.Client client, Wl.Resource resource);
9598
}

src/PantheonShell.vala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ namespace Gala {
5454
make_centered,
5555
focus_extended_behavior,
5656
make_modal,
57+
make_monitor_label,
5758
};
5859

5960
PanelSurface.quark = GLib.Quark.from_string ("-gala-wayland-panel-surface-data");
@@ -392,6 +393,21 @@ namespace Gala {
392393
ShellClientsManager.get_instance ().make_modal (window, dim == 1);
393394
}
394395

396+
internal static void make_monitor_label (Wl.Client client, Wl.Resource resource, int monitor_index) {
397+
unowned ExtendedBehaviorSurface? eb_surface = resource.get_user_data<ExtendedBehaviorSurface> ();
398+
if (eb_surface.wayland_surface == null) {
399+
return;
400+
}
401+
402+
Meta.Window? window;
403+
eb_surface.wayland_surface.get ("window", out window, null);
404+
if (window == null) {
405+
return;
406+
}
407+
408+
ShellClientsManager.get_instance ().make_monitor_label (window, monitor_index);
409+
}
410+
395411
internal static void destroy_panel_surface (Wl.Client client, Wl.Resource resource) {
396412
resource.destroy ();
397413
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2025 elementary, Inc. (https://elementary.io)
3+
* SPDX-License-Identifier: GPL-3.0-or-later
4+
*
5+
* Authored by: Leonhard Kargl <leo.kargl@proton.me>
6+
*/
7+
8+
public class Gala.MonitorLabelWindow : PositionedWindow {
9+
private const int MARGIN = 24;
10+
11+
public int monitor_index { get; construct; }
12+
13+
public MonitorLabelWindow (Meta.Window window, int monitor_index) {
14+
Object (window: window, monitor_index: monitor_index);
15+
}
16+
17+
protected override void get_window_position (Mtk.Rectangle window_rect, out int x, out int y) {
18+
var monitor_rect = window.display.get_monitor_geometry (monitor_index);
19+
20+
x = monitor_rect.x + MARGIN;
21+
y = monitor_rect.y + MARGIN;
22+
}
23+
}

src/ShellClients/ShellClientsManager.vala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class Gala.ShellClientsManager : Object, GestureTarget {
2929

3030
private GLib.HashTable<Meta.Window, PanelWindow> panel_windows = new GLib.HashTable<Meta.Window, PanelWindow> (null, null);
3131
private GLib.HashTable<Meta.Window, ExtendedBehaviorWindow> positioned_windows = new GLib.HashTable<Meta.Window, ExtendedBehaviorWindow> (null, null);
32+
private GLib.HashTable<Meta.Window, MonitorLabelWindow> monitor_label_windows = new GLib.HashTable<Meta.Window, MonitorLabelWindow> (null, null);
3233

3334
private ShellClientsManager (WindowManager wm) {
3435
Object (wm: wm);
@@ -244,6 +245,18 @@ public class Gala.ShellClientsManager : Object, GestureTarget {
244245
positioned_windows[window].make_modal (dim);
245246
}
246247

248+
public void make_monitor_label (Meta.Window window, int monitor_index) requires (!is_itself_positioned (window)) {
249+
if (monitor_index < 0 || monitor_index > wm.get_display ().get_n_monitors ()) {
250+
warning ("Invalid monitor index provided: %d", monitor_index);
251+
return;
252+
}
253+
254+
monitor_label_windows[window] = new MonitorLabelWindow (window, monitor_index);
255+
256+
// connect_after so we make sure that any queued move is unqueued
257+
window.unmanaging.connect_after ((_window) => monitor_label_windows.remove (_window));
258+
}
259+
247260
public void propagate (UpdateType update_type, GestureAction action, double progress) {
248261
foreach (var window in positioned_windows.get_values ()) {
249262
window.propagate (update_type, action, progress);
@@ -258,6 +271,7 @@ public class Gala.ShellClientsManager : Object, GestureTarget {
258271
return (
259272
(window in positioned_windows && positioned_windows[window].modal) ||
260273
(window in panel_windows) ||
274+
(window in monitor_label_windows) ||
261275
NotificationStack.is_notification (window)
262276
);
263277
}
@@ -387,6 +401,15 @@ public class Gala.ShellClientsManager : Object, GestureTarget {
387401
set_restore_previous_x11_region (window);
388402
break;
389403

404+
case "monitor-label":
405+
int parsed;
406+
if (int.try_parse (val, out parsed)) {
407+
make_monitor_label (window, parsed);
408+
} else {
409+
warning ("Failed to parse %s as monitor label", val);
410+
}
411+
break;
412+
390413
default:
391414
break;
392415
}

src/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ gala_bin_sources = files(
4646
'ShellClients/ExtendedBehaviorWindow.vala',
4747
'ShellClients/HideTracker.vala',
4848
'ShellClients/ManagedClient.vala',
49+
'ShellClients/MonitorLabelWindow.vala',
4950
'ShellClients/NotificationsClient.vala',
5051
'ShellClients/PanelWindow.vala',
5152
'ShellClients/PositionedWindow.vala',

0 commit comments

Comments
 (0)