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

Support X11 #260

Closed
wants to merge 3 commits into from
Closed
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
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