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
7 changes: 4 additions & 3 deletions src/AppSystem/App.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Dock.App : Object {

public signal void removed ();

public unowned AppSystem app_system { get; construct; }
public bool pinned { get; construct set; }
public GLib.DesktopAppInfo app_info { get; construct; }

Expand Down Expand Up @@ -52,8 +53,8 @@ public class Dock.App : Object {

private static Dock.SwitcherooControl switcheroo_control;

public App (GLib.DesktopAppInfo app_info, bool pinned) {
Object (app_info: app_info, pinned: pinned);
public App (AppSystem app_system, GLib.DesktopAppInfo app_info, bool pinned) {
Object (app_system: app_system, app_info: app_info, pinned: pinned);
}

static construct {
Expand Down Expand Up @@ -255,7 +256,7 @@ public class Dock.App : Object {
if (timer_id != 0) {
Source.remove (timer_id);
} else {
yield AppSystem.get_default ().sync_windows (); // Get the current stacking order
yield app_system.sync_windows (); // Get the current stacking order
current_index = windows.length > 1 && windows[0].has_focus ? 1 : 0;
current_windows = {};
foreach (var window in windows) {
Expand Down
17 changes: 8 additions & 9 deletions src/AppSystem/AppSystem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@

public class Dock.AppSystem : Object, UnityClient {
private static Settings settings;
private static GLib.Once<AppSystem> instance;

static construct {
settings = new Settings ("io.elementary.dock");
}

public static unowned AppSystem get_default () {
return instance.once (() => { return new AppSystem (); });
}

public signal void app_added (App app);

public WindowSystem window_system { get; construct; }

private GLib.HashTable<unowned string, App> id_to_app;

private AppSystem () { }
public AppSystem (WindowSystem window_system) {
Object (window_system: window_system);
}

construct {
id_to_app = new HashTable<unowned string, App> (str_hash, str_equal);
Expand All @@ -36,19 +35,19 @@ public class Dock.AppSystem : Object, UnityClient {
}

yield sync_windows ();
WindowSystem.get_default ().notify["windows"].connect (sync_windows);
window_system.notify["windows"].connect (sync_windows);
}

private App add_app (DesktopAppInfo app_info, bool pinned) {
var app = new App (app_info, pinned);
var app = new App (this, app_info, pinned);
id_to_app[app_info.get_id ()] = app;
app.removed.connect ((_app) => id_to_app.remove (_app.app_info.get_id ()));
app_added (app);
return app;
}

public async void sync_windows () {
var windows = WindowSystem.get_default ().windows;
var windows = window_system.windows;

var app_window_list = new GLib.HashTable<App, GLib.GenericArray<Window>> (direct_hash, direct_equal);
foreach (var window in windows) {
Expand Down
9 changes: 7 additions & 2 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/

public class Dock.Application : Gtk.Application {
private AppSystem app_system;

public Application () {
Object (application_id: "io.elementary.dock");
}
Expand All @@ -14,6 +16,9 @@ public class Dock.Application : Gtk.Application {
Granite.init ();
ShellKeyGrabber.init ();
GalaDBus.init.begin ();

app_system = new AppSystem (WindowSystem.get_default ());
ItemManager.init (app_system);
}

protected override void activate () {
Expand All @@ -23,7 +28,7 @@ public class Dock.Application : Gtk.Application {
add_window (main_window);

unowned var unity_client = Unity.get_default ();
unity_client.add_client (AppSystem.get_default ());
unity_client.add_client (app_system);
}

active_window.present ();
Expand All @@ -32,7 +37,7 @@ public class Dock.Application : Gtk.Application {
public override bool dbus_register (DBusConnection connection, string object_path) throws Error {
base.dbus_register (connection, object_path);

connection.register_object (object_path, new ItemInterface ());
connection.register_object (object_path, new ItemInterface (app_system));

return true;
}
Expand Down
14 changes: 11 additions & 3 deletions src/DBus/ItemInterface.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@

[DBus (name = "io.elementary.dock.items")]
public class Dock.ItemInterface : Object {
[DBus (visible = false)]
public AppSystem app_system { private get; construct; }

[DBus (visible = false)]
public ItemInterface (AppSystem app_system) {
Object (app_system: app_system);
}

public void add_launcher (string app_id) throws DBusError, IOError {
AppSystem.get_default ().add_app_for_id (app_id);
app_system.add_app_for_id (app_id);
}

public void remove_launcher (string app_id) throws DBusError, IOError {
AppSystem.get_default ().remove_app_by_id (app_id);
app_system.remove_app_by_id (app_id);
}

public string[] list_launchers () throws DBusError, IOError {
return AppSystem.get_default ().list_launchers ();
return app_system.list_launchers ();
}
}
21 changes: 15 additions & 6 deletions src/ItemManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@
public class Dock.ItemManager : Gtk.Fixed {
private static Settings settings;

private static GLib.Once<ItemManager> instance;
private static ItemManager instance;

public static void init (AppSystem app_system) {
instance = new ItemManager (app_system);
}

public static unowned ItemManager get_default () {
return instance.once (() => { return new ItemManager (); });
return instance;
}

public AppSystem app_system { private get; construct; }

public Launcher? added_launcher { get; set; default = null; }

private Adw.TimedAnimation resize_animation;
Expand All @@ -27,6 +34,10 @@
settings = new Settings ("io.elementary.dock");
}

private ItemManager (AppSystem app_system) {
Object (app_system: app_system);
}

construct {
launchers = new GLib.GenericArray<Launcher> ();

Expand Down Expand Up @@ -88,8 +99,6 @@
return;
}

var app_system = AppSystem.get_default ();

var app = app_system.get_app (app_info.get_id ());
if (app != null) {
app.pinned = true;
Expand Down Expand Up @@ -145,7 +154,7 @@
return false;
});

AppSystem.get_default ().app_added.connect ((app) => {
app_system.app_added.connect ((app) => {
var launcher = new Launcher (app);

if (drop_target_file.get_value () != null && added_launcher == null) { // The launcher is being added via dnd from wingpanel
Expand All @@ -167,7 +176,7 @@
#endif

map.connect (() => {
AppSystem.get_default ().load.begin ();
app_system.load.begin ();
background_item.load ();
#if WORKSPACE_SWITCHER
WorkspaceSystem.get_default ().load.begin ();
Expand Down