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

public signal void removed ();

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

public bool pinned { get; set; }

public bool count_visible { get; private set; default = false; }
public int64 current_count { get; private set; default = 0; }
public bool progress_visible { get; set; default = false; }
Expand Down Expand Up @@ -52,8 +51,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 (GLib.DesktopAppInfo app_info) {
Object (app_info: app_info);
}

static construct {
Expand Down Expand Up @@ -101,11 +100,6 @@ public class Dock.App : Object {
app_action_group.add_action (simple_action);
}

notify["pinned"].connect (() => {
check_remove ();
ItemManager.get_default ().sync_pinned ();
});

WindowSystem.get_default ().notify["active-workspace"].connect (() => {
notify_property ("running-on-active-workspace");
});
Expand Down Expand Up @@ -166,12 +160,6 @@ public class Dock.App : Object {
return false;
}

private void check_remove () {
if (!pinned && !running) {
removed ();
}
}

public void update_windows (GLib.GenericArray<Window>? new_windows) {
if (new_windows == null) {
windows = new GLib.GenericArray<Window> ();
Expand All @@ -185,8 +173,6 @@ public class Dock.App : Object {
if (launching && running) {
launching = false;
}

check_remove ();
}

public void perform_unity_update (VariantIter prop_iter) {
Expand Down
114 changes: 78 additions & 36 deletions src/AppSystem/AppSystem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,97 @@ public class Dock.AppSystem : Object, UnityClient {
return instance.once (() => { return new AppSystem (); });
}

public signal void app_added (App app);
private ListStore apps_store;
public ListModel apps { get { return apps_store; } }

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

private AppSystem () { }

construct {
apps_store = new ListStore (typeof (App));
apps_store.items_changed.connect (save_pinned);

id_to_app = new HashTable<unowned string, App> (str_hash, str_equal);
}

public App? get_app (string id) {
public App? get_app_by_id (string id) {
if (!(id in id_to_app)) {
var app_info = new DesktopAppInfo (id);

if (app_info == null) {
return null;
}

var app = new App (app_info);
app.notify["running"].connect (check_app);
app.notify["pinned"].connect (check_app);
app.notify["pinned"].connect (save_pinned);

id_to_app[app_info.get_id ()] = app;
}

return id_to_app[id];
}

private void check_app (Object obj, ParamSpec pspec) {
var app = (App) obj;

uint pos;
var exists = apps_store.find (app, out pos);

if ((app.pinned || app.running) && !exists) {
apps_store.append (app);
} else if ((!app.pinned && !app.running) && exists) {
apps_store.remove (pos);
}
}

private void save_pinned () {
string[] new_pinned_ids = {};

for (uint i = 0; i < apps_store.get_n_items (); i++) {
var app = (App) apps_store.get_item (i);
if (app.pinned) {
new_pinned_ids += app.app_info.get_id ();
}
}

settings.set_strv ("launchers", new_pinned_ids);
}

public void reorder_app (App app, uint new_index) {
uint pos;
if (!apps_store.find (app, out pos)) {
warning ("Tried to reorder an app that is not in the store");
return;
}

apps_store.remove (pos);
apps_store.insert (new_index, app);
}

public async void load () {
foreach (string app_id in settings.get_strv ("launchers")) {
var app_info = new GLib.DesktopAppInfo (app_id);
add_app (app_info, true);
var app = get_app_by_id (app_id);
if (app == null) {
continue;
}
app.pinned = true;
}

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

private App add_app (DesktopAppInfo app_info, bool pinned) {
var app = new App (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 app_window_list = new GLib.HashTable<App, GLib.GenericArray<Window>> (direct_hash, direct_equal);
foreach (var window in windows) {
App? app = id_to_app[window.app_id];
var app = get_app_by_id (window.app_id);
if (app == null) {
var app_info = new GLib.DesktopAppInfo (window.app_id);
if (app_info == null) {
continue;
}

app = add_app (app_info, false);
continue;
}

var window_list = app_window_list.get (app);
Expand All @@ -80,24 +126,18 @@ public class Dock.AppSystem : Object, UnityClient {
}

public void add_app_for_id (string app_id) {
if (app_id in id_to_app) {
id_to_app[app_id].pinned = true;
return;
}
var app = get_app_by_id (app_id);

var app_info = new DesktopAppInfo (app_id);

if (app_info == null) {
warning ("App not found: %s", app_id);
return;
if (app != null) {
app.pinned = true;
}

add_app (app_info, true);
}

public void remove_app_by_id (string app_id) {
if (app_id in id_to_app) {
id_to_app[app_id].pinned = false;
var app = get_app_by_id (app_id);

if (app != null) {
app.pinned = false;
}
}

Expand All @@ -122,17 +162,19 @@ public class Dock.AppSystem : Object, UnityClient {
parameters.get ("(sa{sv})", out app_uri, out prop_iter);

var app_id = app_uri.replace ("application://", "");
if (id_to_app[app_id] != null) {
id_to_app[app_id].perform_unity_update (prop_iter);
var app = get_app_by_id (app_id);
if (app != null) {
app.perform_unity_update (prop_iter);
} else {
critical ("unable to update missing launcher: %s", app_id);
}
}

private void remove_launcher_entry (string sender_name) {
var app_id = sender_name + ".desktop";
if (id_to_app[app_id] != null) {
id_to_app[app_id].remove_launcher_entry ();
var app = get_app_by_id (app_id);
if (app != null) {
app.remove_launcher_entry ();
}
}
}
12 changes: 7 additions & 5 deletions src/AppSystem/Background/BackgroundItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
*/

public class Dock.BackgroundItem : BaseIconGroup {
public signal void apps_appeared ();
private ListStore group_store;
public ListModel group_model { get { return group_store; } }

public BackgroundMonitor monitor { private get; construct; }
public bool has_apps { get { return monitor.background_apps.get_n_items () > 0; } }

private Gtk.Popover popover;

Expand All @@ -20,11 +20,13 @@ public class Dock.BackgroundItem : BaseIconGroup {
icons: new Gtk.MapListModel (background_monitor.background_apps, (app) => {
return ((BackgroundApp) app).icon;
}),
disallow_dnd: true
group: Group.NONE
);
}

construct {
group_store = new ListStore (typeof (BackgroundItem));

var list_box = new Gtk.ListBox () {
selection_mode = BROWSE
};
Expand Down Expand Up @@ -53,9 +55,9 @@ public class Dock.BackgroundItem : BaseIconGroup {
monitor.background_apps.items_changed.connect ((pos, n_removed, n_added) => {
if (monitor.background_apps.get_n_items () == 0) {
popover.popdown ();
removed ();
group_store.remove (0);
} else if (n_removed == 0 && n_added != 0 && n_added == monitor.background_apps.get_n_items ()) {
apps_appeared ();
group_store.append (this);
}
});

Expand Down
1 change: 0 additions & 1 deletion src/AppSystem/Launcher.vala
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ public class Dock.Launcher : BaseItem {
});

app.launched.connect (animate_launch);
app.removed.connect (() => removed ());

var bounce_animation_target = new Adw.CallbackAnimationTarget ((val) => {
var height = overlay.get_height ();
Expand Down
34 changes: 17 additions & 17 deletions src/BaseItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class Dock.BaseItem : Gtk.Box {
}

public enum Group {
NONE,
LAUNCHER,
WORKSPACE
}
Expand All @@ -21,10 +22,8 @@ public class Dock.BaseItem : Gtk.Box {
dock_settings = new GLib.Settings ("io.elementary.dock");
}

public signal void removed ();
public signal void revealed_done ();

public bool disallow_dnd { get; construct; default = false; }
/**
* The group in the dock this item belongs to. This is used to allow DND
* only within that group.
Expand Down Expand Up @@ -133,7 +132,7 @@ public class Dock.BaseItem : Gtk.Box {
reveal.done.connect (set_revealed_finish);

var animation_target = new Adw.CallbackAnimationTarget ((val) => {
ItemManager.get_default ().move (this, val, 0);
((Gtk.Fixed) parent).move (this, val, 0);
current_pos = val;
});

Expand All @@ -155,17 +154,17 @@ public class Dock.BaseItem : Gtk.Box {
gesture_click = new Gtk.GestureClick ();
add_controller (gesture_click);

if (group == NONE) {
return;
}

var drop_target = new Gtk.DropTarget (typeof (BaseItem), MOVE) {
preload = true
};
add_controller (drop_target);
drop_target.enter.connect (on_drop_enter);
drop_target.drop.connect (on_drop);

if (disallow_dnd) {
return;
}

var drag_source = new Gtk.DragSource () {
actions = MOVE
};
Expand All @@ -181,6 +180,11 @@ public class Dock.BaseItem : Gtk.Box {
popover_tooltip.dispose ();
}

public uint get_index () {
var item_group = get_ancestor (typeof (ItemGroup)) as ItemGroup;
return item_group?.get_index_for_item (this) ?? Gtk.INVALID_LIST_POSITION;
}

public void set_revealed (bool revealed) {
fade.skip ();
reveal.skip ();
Expand Down Expand Up @@ -219,6 +223,10 @@ public class Dock.BaseItem : Gtk.Box {
* when moving a launcher so that its current_pos is always up to date.
*/
public void animate_move (double new_position) {
if (timed_animation.value_to == new_position) {
return;
}

timed_animation.value_from = current_pos;
timed_animation.value_to = new_position;

Expand Down Expand Up @@ -285,15 +293,7 @@ public class Dock.BaseItem : Gtk.Box {
*/
public void calculate_dnd_move (BaseItem source, double x, double y) {
var launcher_manager = ItemManager.get_default ();

int target_index = launcher_manager.get_index_for_launcher (this);
int source_index = launcher_manager.get_index_for_launcher (source);

if (source_index == target_index) {
return;
}

launcher_manager.move_launcher_after (source, target_index);
launcher_manager.move_launcher_after (source, (int) get_index ());
}

private bool on_drop (Value val) {
Expand All @@ -306,7 +306,7 @@ public class Dock.BaseItem : Gtk.Box {

private bool is_allowed_drop (Value val) {
var obj = val.get_object ();
return obj != null && obj is BaseItem && ((BaseItem) obj).group == group;
return obj != null && obj is BaseItem && ((BaseItem) obj).group == group && obj != this;
}

private class PopoverTooltip : Gtk.Popover {
Expand Down
Loading