Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit committed Jan 4, 2024
2 parents 673ae82 + 656d417 commit aa918fb
Show file tree
Hide file tree
Showing 8 changed files with 305 additions and 297 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Install Dependencies
run: |
apt update
apt install -y libgtk-4-dev meson valac
apt install -y libgtk-4-dev libadwaita-1-dev meson valac
- name: Build
run: |
meson build
Expand Down
28 changes: 0 additions & 28 deletions data/Launcher.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,3 @@ launcher {
transform: translatey(-20px);
}
}

.move-right {
animation: move-right 300ms;
animation-direction: normal;
}

@keyframes move-right {
from {
transform: translatex(-60px);
}
to {
transform: translatex(0);
}
}

.move-left {
animation: move-left 300ms;
animation-direction: normal;
}

@keyframes move-left {
from {
transform: translatex(60px);
}
to {
transform: translatex(0);
}
}
2 changes: 2 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ glib_dep = dependency('glib-2.0')
gobject_dep = dependency('gobject-2.0')
gtk_dep = dependency('gtk4')
granite_dep = dependency('granite-7')
adw_dep = dependency('libadwaita-1')
m_dep = cc.find_library('m')

dependencies = [
Expand All @@ -27,6 +28,7 @@ dependencies = [
gobject_dep,
gtk_dep,
granite_dep,
adw_dep,
m_dep
]

Expand Down
2 changes: 1 addition & 1 deletion src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class Dock.Application : Gtk.Application {
add_window (main_window);

unowned var unity_client = Unity.get_default ();
unity_client.add_client (main_window);
unity_client.add_client (LauncherManager.get_default ());
}

active_window.present_with_time (Gdk.CURRENT_TIME);
Expand Down
85 changes: 42 additions & 43 deletions src/Launcher.vala
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ public class Dock.Launcher : Gtk.Button {
public const int ICON_SIZE = 48;
public const int PADDING = 6;

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 double current_pos { get; set; }
public int64 current_count { get; private set; default = 0; }

public GLib.List<AppWindow> windows { get; private owned set; }
Expand All @@ -21,13 +23,12 @@ public class Dock.Launcher : Gtk.Button {
private Gtk.Image image;
private int drag_offset_x = 0;
private int drag_offset_y = 0;
private string animate_css_class_name = "";
private uint animate_timeout_id = 0;
private Adw.TimedAnimation timed_animation;

private Gtk.PopoverMenu popover;

public Launcher (GLib.DesktopAppInfo app_info) {
Object (app_info: app_info);
public Launcher (GLib.DesktopAppInfo app_info, bool pinned) {
Object (app_info: app_info, pinned: pinned);
}

class construct {
Expand All @@ -49,14 +50,14 @@ public class Dock.Launcher : Gtk.Button {
foreach (var action in app_info.list_actions ()) {
action_section.append (
app_info.get_action_name (action),
MainWindow.ACTION_PREFIX + MainWindow.LAUNCHER_ACTION_TEMPLATE.printf (app_info.get_id (), action)
LauncherManager.ACTION_PREFIX + LauncherManager.LAUNCHER_ACTION_TEMPLATE.printf (app_info.get_id (), action)
);
}

var pinned_section = new Menu ();
pinned_section.append (
_("Keep in Dock"),
MainWindow.ACTION_PREFIX + MainWindow.LAUNCHER_PINNED_ACTION_TEMPLATE.printf (app_info.get_id ())
LauncherManager.ACTION_PREFIX + LauncherManager.LAUNCHER_PINNED_ACTION_TEMPLATE.printf (app_info.get_id ())
);

var model = new Menu ();
Expand Down Expand Up @@ -101,6 +102,23 @@ public class Dock.Launcher : Gtk.Button {
child = box;
tooltip_text = app_info.get_display_name ();

var launcher_manager = LauncherManager.get_default ();

var animation_target = new Adw.CallbackAnimationTarget ((val) => {
launcher_manager.move (this, val, 0);
current_pos = val;
});

timed_animation = new Adw.TimedAnimation (
this,
0,
0,
200,
animation_target
) {
easing = EASE_IN_OUT_QUAD
};

var drag_source = new Gtk.DragSource () {
actions = MOVE
};
Expand All @@ -116,7 +134,7 @@ public class Dock.Launcher : Gtk.Button {
box.add_controller (drop_target);
drop_target.enter.connect (on_drop_enter);

notify["pinned"].connect (() => ((MainWindow) get_root ()).sync_pinned ());
notify["pinned"].connect (() => launcher_manager.sync_pinned ());

var gesture_click = new Gtk.GestureClick () {
button = Gdk.BUTTON_SECONDARY
Expand Down Expand Up @@ -172,30 +190,6 @@ public class Dock.Launcher : Gtk.Button {
});
}

public void animate_move (Gtk.DirectionType dir) {
if (animate_timeout_id != 0) {
Source.remove (animate_timeout_id);
animate_timeout_id = 0;
remove_css_class (animate_css_class_name);
}

if (dir == LEFT) {
animate_css_class_name = "move-left";
} else if (dir == RIGHT) {
animate_css_class_name = "move-right";
} else {
warning ("Invalid direction type.");
return;
}

add_css_class (animate_css_class_name);
animate_timeout_id = Timeout.add (300, () => {
remove_css_class (animate_css_class_name);
animate_timeout_id = 0;
return Source.REMOVE;
});
}

public void update_windows (owned GLib.List<AppWindow>? new_windows) {
if (new_windows == null) {
windows = new GLib.List<AppWindow> ();
Expand All @@ -216,6 +210,13 @@ public class Dock.Launcher : Gtk.Button {
}
}

public void animate_move (double new_position) {
timed_animation.value_from = current_pos;
timed_animation.value_to = new_position;

timed_animation.play ();
}

private Gdk.ContentProvider? on_drag_prepare (double x, double y) {
drag_offset_x = (int) x;
drag_offset_y = (int) y;
Expand Down Expand Up @@ -261,11 +262,6 @@ public class Dock.Launcher : Gtk.Button {
popover.popup ();
popover.start_animation ();

var box = (Gtk.Box) parent;
if (!windows.is_empty ()) {
window.move_launcher_after (this, (Launcher) box.get_last_child ());
}

pinned = false;

return true;
Expand All @@ -276,22 +272,25 @@ public class Dock.Launcher : Gtk.Button {
}

private Gdk.DragAction on_drop_enter (Gtk.DropTarget drop_target, double x, double y) {
var launcher_manager = LauncherManager.get_default ();

var val = drop_target.get_value ();
if (val != null) {
var obj = val.get_object ();

if (obj != null && obj is Launcher) {
Launcher source = (Launcher) obj;
Launcher target = this;
int target_index = launcher_manager.get_index_for_launcher (this);
int source_index = launcher_manager.get_index_for_launcher (source);

if (source != target) {
if (((x > get_allocated_width () / 2) && get_next_sibling () == source) ||
((x < get_allocated_width () / 2) && get_prev_sibling () != source)
if (source_index != target_index) {
if (((x > get_allocated_width () / 2) && target_index + 1 == source_index) ||
((x < get_allocated_width () / 2) && target_index - 1 != source_index)
) {
target = (Launcher) get_prev_sibling ();
target_index = target_index > 0 ? target_index-- : target_index;
}

((MainWindow) get_root ()).move_launcher_after (source, target);
launcher_manager.move_launcher_after (source, target_index);
}
}
}
Expand Down
Loading

0 comments on commit aa918fb

Please sign in to comment.