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
1 change: 0 additions & 1 deletion src/AppSystem/App.vala
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public class Dock.App : Object {

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

WindowSystem.get_default ().notify["active-workspace"].connect (() => {
Expand Down
52 changes: 45 additions & 7 deletions src/AppSystem/AppSystem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ 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);
}

Expand All @@ -41,12 +45,46 @@ public class Dock.AppSystem : Object, UnityClient {

private App add_app (DesktopAppInfo app_info, bool pinned) {
var app = new App (app_info, pinned);
app.removed.connect (remove_app);
app.notify["pinned"].connect (save_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);
apps_store.append (app);
return app;
}

private void remove_app (App app) {
id_to_app.remove (app.app_info.get_id ());

uint pos;
if (apps_store.find (app, out pos)) {
apps_store.remove (pos);
}
}

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);
}

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 async void sync_windows () {
var windows = WindowSystem.get_default ().windows;

Expand Down Expand Up @@ -79,20 +117,20 @@ public class Dock.AppSystem : Object, UnityClient {
}
}

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

var app_info = new DesktopAppInfo (app_id);

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

add_app (app_info, true);
return add_app (app_info, true);
}

public void remove_app_by_id (string app_id) {
Expand Down
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