Skip to content

Commit

Permalink
Support X11
Browse files Browse the repository at this point in the history
  • Loading branch information
lenemter committed Jul 25, 2024
1 parent 97d32b2 commit f16d2e7
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 3 deletions.
2 changes: 2 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ gtk_wayland_dep = dependency('gtk4-wayland')
granite_dep = dependency('granite-7')
adw_dep = dependency('libadwaita-1')
m_dep = cc.find_library('m')
posix_dep = meson.get_compiler('vala').find_library('posix')
wl_client_dep = dependency('wayland-client')

subdir('protocol')
Expand All @@ -38,6 +39,7 @@ dependencies = [
granite_dep,
adw_dep,
m_dep,
posix_dep,
wl_client_dep,
pantheon_desktop_shell_dep
]
Expand Down
13 changes: 12 additions & 1 deletion src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@
*/

public class Dock.Application : Gtk.Application {
const OptionEntry[] ENTRIES = {
{ "id", '\0', OptionFlags.NONE, OptionArg.STRING, out id, "Launch dock with the specific window id", null },
{ null }
};

public static string? id;

public Application () {
Object (application_id: "io.elementary.dock");

add_main_option_entries (ENTRIES);
}

protected override void startup () {
Expand All @@ -26,7 +35,9 @@ public class Dock.Application : Gtk.Application {

protected override void activate () {
if (active_window == null) {
var main_window = new MainWindow ();
var main_window = new MainWindow () {
title = (id != null) ? id : application_id
};

add_window (main_window);

Expand Down
12 changes: 12 additions & 0 deletions src/DBus/PantheonShellX11.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: 2024 elementary, Inc. (https://elementary.io)
*/

[DBus (name = "io.elementary.gala.PantheonShellX11")]
public interface Dock.PantheonShellX11 : GLib.Object {
public abstract void set_anchor (string id, Pantheon.Desktop.Anchor anchor) throws GLib.Error;
public abstract void set_size (string id, int width, int height) throws GLib.Error;
public abstract void set_hide_mode (string id, Pantheon.Desktop.HideMode hide_mode) throws GLib.Error;
public abstract void make_centered (string id) throws GLib.Error;
}
36 changes: 34 additions & 2 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class Dock.MainWindow : Gtk.ApplicationWindow {
private Pantheon.Desktop.Shell? desktop_shell;
private Pantheon.Desktop.Panel? panel;

PantheonShellX11? pantheon_shell_x11_dbus;

class construct {
set_css_name ("dock");
}
Expand All @@ -25,11 +27,27 @@ public class Dock.MainWindow : Gtk.ApplicationWindow {
var drop_target_launcher = new Gtk.DropTarget (typeof (Launcher), MOVE);
launcher_manager.add_controller (drop_target_launcher);

launcher_manager.realize.connect (init_panel);
show.connect (() => {
if (is_wayland ()) {
init_panel ();
} else {
init_x11_panel ();
}
});

settings.changed.connect ((key) => {
if (key == "autohide-mode" && panel != null) {
if (key != "autohide-mode") {
return;
}

if (is_wayland () && panel != null) {
panel.set_hide_mode (settings.get_enum ("autohide-mode"));
} else if (!is_wayland () && pantheon_shell_x11_dbus != null && title != null) {
try {
pantheon_shell_x11_dbus.set_hide_mode (title, settings.get_enum ("autohide-mode"));
} catch (GLib.Error e) {
warning ("Unable to update the hide mode: %s", e.message);
}
}
});
}
Expand Down Expand Up @@ -64,4 +82,18 @@ public class Dock.MainWindow : Gtk.ApplicationWindow {
}
}
}

private bool is_wayland () {
return Gdk.Display.get_default () is Gdk.Wayland.Display;
}

private void init_x11_panel () requires (title != null) {
try {
pantheon_shell_x11_dbus = Bus.get_proxy_sync (BusType.SESSION, "io.elementary.gala.PantheonShellX11", "/io/elementary/gala/PantheonShellX11");
pantheon_shell_x11_dbus.set_anchor (title, BOTTOM);
pantheon_shell_x11_dbus.set_hide_mode (title, settings.get_enum ("autohide-mode"));
} catch (GLib.Error e) {
critical ("Unable to setup PantheonShellX11: %s", e.message);
}
}
}
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ sources = [
'MainWindow.vala',
'PoofPopover.vala',
'DBus' / 'ItemInterface.vala',
'DBus' / 'PantheonShellX11.vala',
'DBus' / 'ShellKeyGrabber.vala',
'DBus' / 'SwitcherooControl.vala',
'DBus' / 'Unity.vala'
Expand Down

0 comments on commit f16d2e7

Please sign in to comment.