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

Implement DnD reordering #181

Merged
merged 41 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
209c651
Implement DnD reordering
leolost2605 Jul 26, 2023
4c63bac
Remove app by dragging into nothing + remember modifications
leolost2605 Jul 26, 2023
f9382c6
Formatting
leolost2605 Jul 26, 2023
25ea032
Naming
leolost2605 Jul 26, 2023
2a8dc4d
Remove leftover
leolost2605 Jul 26, 2023
46c8d8c
Work around bug
leolost2605 Jul 26, 2023
85b1503
Animate reordering fix issues
leolost2605 Jul 29, 2023
2ea006f
Make a popover to prepare for poof animation
leolost2605 Jul 29, 2023
89d8ae9
Add poof animation
leolost2605 Jul 29, 2023
d34fa98
Remove test mp4
leolost2605 Jul 29, 2023
65a61e7
Cleanup
leolost2605 Jul 29, 2023
02d3333
Fix some issues, add license, cleanup
leolost2605 Jul 29, 2023
7f185d1
Improve reordering behavior and fix lint
leolost2605 Jul 29, 2023
d2ec1e7
Add some animations - prototype
leolost2605 Jul 30, 2023
f03e1ff
Cleanup
leolost2605 Jul 30, 2023
eb21f7b
Fix small line where drop could fail
leolost2605 Jul 30, 2023
6f66f81
Apply suggestions from code review
leolost2605 Jul 30, 2023
51849de
More suggestions from code review
leolost2605 Jul 30, 2023
b888a30
Increase poof size
leolost2605 Jul 30, 2023
1808721
Add queue_resize
leolost2605 Jul 30, 2023
4936890
Fix poof alignment
leolost2605 Jul 30, 2023
c9eaeb1
Remove queue_resize
leolost2605 Jul 30, 2023
bb8123d
Remove whitespace
leolost2605 Jul 30, 2023
26d5a9d
Don't allow removing apps with windows
leolost2605 Jul 30, 2023
a9f89a8
Unpin pinned launchers when removed
leolost2605 Jul 30, 2023
861d221
Maybe fix glitches
leolost2605 Jul 30, 2023
29fa1ad
Add comment
leolost2605 Jul 30, 2023
40f5efd
Remove launcher from hashmap when removing
leolost2605 Jul 30, 2023
f4dc073
Move drag source signal handlers into their own methods
leolost2605 Jul 30, 2023
5aaf537
Cleanup
leolost2605 Jul 30, 2023
52d391d
When unpinning app with open windows move launcher to last position
leolost2605 Jul 30, 2023
1d9bbf1
Improve naming
leolost2605 Aug 1, 2023
80af33d
Merge branch 'main' into dnd-reordering
zeebok Aug 24, 2023
8d4a735
Apply suggestions from code review
leolost2605 Sep 18, 2023
a2ffaa9
Add comment
leolost2605 Sep 18, 2023
a888373
Merge branch 'main' into dnd-reordering
lenemter Oct 5, 2023
8433157
Merge branch 'main' into dnd-reordering
leolost2605 Nov 11, 2023
17f99fe
Fix crash on dnd remove
leolost2605 Nov 11, 2023
211e1cc
Add comments + cleanup
leolost2605 Nov 11, 2023
d6354aa
Cleanup
leolost2605 Nov 11, 2023
cfd15c4
Merge branch 'main' into dnd-reordering
leolost2605 Nov 11, 2023
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
53 changes: 52 additions & 1 deletion src/Launcher.vala
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,36 @@ public class Dock.Launcher : Gtk.Button {
};
image.get_style_context ().add_provider (css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);

child = image;
// Needed to work around DnD bug where it
// would stop working once the button got clicked
var box = new Gtk.Box (VERTICAL, 0);
box.append (image);

child = box;
tooltip_text = app_info.get_display_name ();

var drag_source = new Gtk.DragSource () {
actions = MOVE
};
box.add_controller (drag_source);

drag_source.prepare.connect (() => {
var val = Value (typeof (Launcher));
val.set_object (this);
var content_provider = new Gdk.ContentProvider.for_value (val);
return content_provider;
});
lenemter marked this conversation as resolved.
Show resolved Hide resolved

drag_source.drag_cancel.connect ((drag, reason) => {
if (reason == NO_TARGET) {
((MainWindow)get_root ()).remove_launcher (this);
}
});

var drop_target = new Gtk.DropTarget (typeof (Launcher), MOVE);
box.add_controller (drop_target);
drop_target.drop.connect (on_drop);

clicked.connect (() => {
try {
add_css_class ("bounce");
Expand Down Expand Up @@ -82,4 +109,28 @@ public class Dock.Launcher : Gtk.Button {
return null;
}
}

private bool on_drop (Value val, double x, double y) {
Launcher source;
Launcher? target = this;

var obj = val.get_object ();
if (obj == null || !(obj is Launcher)) {
return false;
} else {
source = (Launcher)obj;
}

if (source == this) {
return false;
}

if (x < get_allocated_width () / 2) {
target = (Launcher)get_prev_sibling ();
}

((MainWindow)get_root ()).move_launcher_after (source, target);

return true;
}
}
57 changes: 56 additions & 1 deletion src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
public class Dock.MainWindow : Gtk.ApplicationWindow {
private static Gtk.CssProvider css_provider;

private Settings settings;
leolost2605 marked this conversation as resolved.
Show resolved Hide resolved
private Gtk.Box box;
private Dock.DesktopIntegration desktop_integration;
private GLib.HashTable<unowned string, Dock.Launcher> app_to_launcher;
Expand Down Expand Up @@ -34,7 +35,7 @@ public class Dock.MainWindow : Gtk.ApplicationWindow {
resizable = false;
set_titlebar (empty_title);

var settings = new Settings ("io.elementary.dock");
settings = new Settings ("io.elementary.dock");

GLib.Bus.get_proxy.begin<Dock.DesktopIntegration> (
GLib.BusType.SESSION,
Expand Down Expand Up @@ -120,4 +121,58 @@ public class Dock.MainWindow : Gtk.ApplicationWindow {
return false;
});
}

public void remove_launcher (Launcher launcher) {
box.remove (launcher);

if (launcher.pinned) {
var old_pinned_ids = settings.get_strv ("launchers");
string[] new_pinned_ids = {};

var to_remove_id = launcher.app_info.get_id ();
foreach (string app_id in old_pinned_ids) {
if (app_id != to_remove_id) {
new_pinned_ids += app_id;
}
}

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

public void move_launcher_after (Launcher source, Launcher? target) {
box.reorder_child_after (source, target);

if (!source.pinned) {
return;
}

var old_pinned_ids = settings.get_strv ("launchers");
string[] new_pinned_ids = {};

string source_id = source.app_info.get_id ();
string? target_id = null;

if (target == null) {
new_pinned_ids += source_id;
} else {
target_id = target.app_info.get_id ();
}

foreach (string app_id in old_pinned_ids) {
if (app_id != source_id) {
new_pinned_ids += app_id;

if (target_id != null && app_id == target_id) {
new_pinned_ids += source_id;
}
}
}

if (target != null && !target.pinned) {
new_pinned_ids += source_id;
}

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