Skip to content

Commit

Permalink
ShellClients: Add PanelClient
Browse files Browse the repository at this point in the history
  • Loading branch information
leolost2605 committed Apr 3, 2024
1 parent 87c6a2f commit 7263cb3
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 0 deletions.
128 changes: 128 additions & 0 deletions src/ShellClients/PanelClient.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Copyright 2024 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Authored by: Leonhard Kargl <leo.kargl@proton.me>
*/

public class Gala.PanelClient : GLib.Object {
private static GLib.HashTable<Meta.Window, Meta.Strut?> window_struts = new GLib.HashTable<Meta.Window, Meta.Strut?> (null, null);

public Meta.Display display { get; construct; }
public ManagedClient client { get; construct; }

private GLib.HashTable<Meta.Window, Meta.Side> window_anchors = new GLib.HashTable<Meta.Window, Meta.Side> (null, null);

public PanelClient (Meta.Display display, string[] args) {
Object (
display: display,
client: new ManagedClient (display, args)
);
}

public void set_anchor (Meta.Window window, Meta.Side side) {
window_anchors[window] = side;

#if HAS_MUTTER_46
client.wayland_client.make_dock (window);
#endif

position_window (window, side);
window.size_changed.connect (() => position_window (window, side));

window.unmanaged.connect (() => {
window_anchors.remove (window);

if (window_struts.remove (window)) {
update_struts ();
}
});
}

private void position_window (Meta.Window window, Meta.Side side) {
var geom = display.get_monitor_geometry (display.get_primary_monitor ());
var window_rect = window.get_frame_rect ();

switch (side) {
case TOP:
position_window_top (window);
break;

case BOTTOM:
position_window_bottom (window);
break;

default:
warning ("Side not supported yet");
break;
}
}

private void position_window_top (Meta.Window window, Meta.Rectangle monitor_geom, Meta.Rectangle window_rect) {
var x = monitor_geom.x + (monitor_geom.width - window_rect.width) / 2;

move_window_idle (window, x, monitor_geom.y);
}

private void position_window_bottom (Meta.Window window, Meta.Rectangle monitor_geom, Meta.Rectangle window_rect) {
var x = monitor_geom.x + (monitor_geom.width - window_rect.width) / 2;
var y = monitor_geom.y + monitor_geom.height - window_rect.height;

move_window_idle (window, x, y);
}

private void move_window_idle (Meta.Window window, int x, int y) {
Idle.add (() => {
window.move_frame (false, x, y);
return Source.REMOVE;
});
}

public void make_exclusive (Meta.Window window) {
if (!(window in window_anchors)) {
warning ("Set an anchor before making a window area exclusive.");
return;
}

if (window in window_struts) {
warning ("Window is already exclusive.");
return;
}

window.size_changed.connect (update_strut);
update_strut (window);
}

private void update_strut (Meta.Window window) {
var rect = window.get_frame_rect ();

Meta.Strut strut = {
rect,
window_anchors[window]
};

window_struts[window] = strut;

update_struts ();
}

private void update_struts () {
var list = new SList<Meta.Strut?> ();

foreach (var window_strut in window_struts.get_values ()) {
list.append (window_strut);
}

foreach (var workspace in display.get_workspace_manager ().get_workspaces ()) {
workspace.set_builtin_struts (list);
}
}

public void unmake_exclusive (Meta.Window window) {
if (window in window_struts) {
window.size_changed.disconnect (update_strut);
window_struts.remove (window);
update_struts ();
}
}
}
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ gala_bin_sources = files(
'HotCorners/HotCornerManager.vala',
'ShellClients/ManagedClient.vala',
'ShellClients/NotificationsClient.vala',
'ShellClients/PanelClient.vala',
'ShellClients/ShellClientsManager.vala',
'Widgets/DwellClickTimer.vala',
'Widgets/IconGroup.vala',
Expand Down

0 comments on commit 7263cb3

Please sign in to comment.