Skip to content

Commit 4cbd18e

Browse files
authored
Allow to dnd a window icon to the new workspace item (#509)
1 parent 197bf3d commit 4cbd18e

File tree

5 files changed

+52
-24
lines changed

5 files changed

+52
-24
lines changed

src/DBus/WindowDragManager.vala

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class Dock.WindowDragManager : Object {
1515
public Gtk.Window dock_window { get; construct; }
1616

1717
private Window? current_window = null;
18-
private WorkspaceIconGroup? current_icon_group = null;
18+
private WorkspaceItem? current_workspace_item = null;
1919

2020
private WindowDragProvider provider;
2121

@@ -48,55 +48,55 @@ public class Dock.WindowDragManager : Object {
4848
return;
4949
}
5050

51-
var icon_group = find_icon_group (x, y);
51+
var workspace_item = find_workspace_item (x, y);
5252

53-
if (icon_group == current_icon_group) {
53+
if (workspace_item == current_workspace_item) {
5454
return;
5555
}
5656

57-
if (current_icon_group != null) {
58-
current_icon_group.window_left ();
57+
if (current_workspace_item != null) {
58+
current_workspace_item.window_left ();
5959
}
6060

61-
current_icon_group = icon_group;
61+
current_workspace_item = workspace_item;
6262

63-
if (current_icon_group != null) {
64-
current_icon_group.window_entered (current_window);
63+
if (current_workspace_item != null) {
64+
current_workspace_item.window_entered (current_window);
6565
}
6666
}
6767

68-
private WorkspaceIconGroup? find_icon_group (int x, int y) {
68+
private WorkspaceItem? find_workspace_item (int x, int y) {
6969
double root_x, root_y;
7070
dock_window.get_surface_transform (out root_x, out root_y);
7171

7272
var widget = dock_window.pick (x - root_x, y - root_y, DEFAULT);
7373

74-
while (!(widget is WorkspaceIconGroup) && widget != null) {
74+
while (!(widget is WorkspaceItem) && widget != null) {
7575
widget = widget.get_parent ();
7676
}
7777

78-
if (widget is WorkspaceIconGroup) {
79-
return (WorkspaceIconGroup) widget;
78+
if (widget is WorkspaceItem) {
79+
return (WorkspaceItem) widget;
8080
}
8181

8282
return null;
8383
}
8484

8585
private void on_leave () {
86-
if (current_icon_group != null) {
87-
current_icon_group.window_left ();
88-
current_icon_group = null;
86+
if (current_workspace_item != null) {
87+
current_workspace_item.window_left ();
88+
current_workspace_item = null;
8989
}
9090

9191
current_window = null;
9292
}
9393

9494
private void on_dropped () {
95-
if (current_icon_group != null && current_window != null &&
96-
current_icon_group.workspace.index != current_window.workspace_index
95+
if (current_workspace_item != null && current_window != null &&
96+
current_workspace_item.workspace_index != current_window.workspace_index
9797
) {
9898
WindowSystem.get_default ().move_window_to_workspace.begin (
99-
current_window.uid, current_icon_group.workspace.index
99+
current_window.uid, current_workspace_item.workspace_index
100100
);
101101
}
102102
}

src/WorkspaceSystem/DynamicWorkspaceItem.vala

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,25 @@
33
* SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io)
44
*/
55

6-
public class Dock.DynamicWorkspaceIcon : ContainerItem {
6+
public class Dock.DynamicWorkspaceIcon : ContainerItem, WorkspaceItem {
7+
public int workspace_index { get { return WorkspaceSystem.get_default ().workspaces.length; } }
8+
9+
private Gtk.Image image;
10+
711
public DynamicWorkspaceIcon () {
812
Object (disallow_dnd: true, group: Group.WORKSPACE);
913
}
1014

1115
construct {
1216
var keybinding_settings = new GLib.Settings ("io.elementary.desktop.wm.keybindings");
1317

14-
var add_image = new Gtk.Image.from_icon_name ("list-add-symbolic") {
18+
image = new Gtk.Image.from_icon_name ("list-add-symbolic") {
1519
hexpand = true,
1620
vexpand = true
1721
};
18-
add_image.add_css_class ("add-image");
22+
image.add_css_class ("add-image");
1923

20-
child = add_image;
24+
child = image;
2125
tooltip_text = Granite.markup_accel_tooltip (
2226
keybinding_settings.get_strv ("switch-to-workspace-last"),
2327
_("New Workspace")
@@ -28,7 +32,7 @@ public class Dock.DynamicWorkspaceIcon : ContainerItem {
2832
WindowSystem.get_default ().notify["active-workspace"].connect (update_active_state);
2933

3034
dock_settings.bind_with_mapping (
31-
"icon-size", add_image, "pixel_size", DEFAULT | GET,
35+
"icon-size", image, "pixel_size", DEFAULT | GET,
3236
(value, variant, user_data) => {
3337
var icon_size = variant.get_int32 ();
3438
value.set_int (icon_size / 2);
@@ -65,4 +69,12 @@ public class Dock.DynamicWorkspaceIcon : ContainerItem {
6569
warning ("Couldn't switch to new workspace: %s", e.message);
6670
}
6771
}
72+
73+
public void window_entered (Window window) {
74+
image.gicon = window.icon;
75+
}
76+
77+
public void window_left () {
78+
image.icon_name = "list-add-symbolic";
79+
}
6880
}

src/WorkspaceSystem/IconGroup.vala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
* SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io)
44
*/
55

6-
public class Dock.WorkspaceIconGroup : BaseIconGroup {
6+
public class Dock.WorkspaceIconGroup : BaseIconGroup, WorkspaceItem {
77
public Workspace workspace { get; construct; }
88

99
public GLib.ListStore additional_icons { private get; construct; }
1010

11+
public int workspace_index { get { return workspace.index; } }
12+
1113
public WorkspaceIconGroup (Workspace workspace) {
1214
var additional_icons = new GLib.ListStore (typeof (GLib.Icon));
1315

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* SPDX-License-Identifier: GPL-3.0
3+
* SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io)
4+
*
5+
* Authored by: Leonhard Kargl <[email protected]>
6+
*/
7+
8+
public interface Dock.WorkspaceItem : Object {
9+
public abstract int workspace_index { get; }
10+
11+
public abstract void window_entered (Window window);
12+
public abstract void window_left ();
13+
}

src/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ sources = [
2727
'WorkspaceSystem' / 'DynamicWorkspaceItem.vala',
2828
'WorkspaceSystem' / 'IconGroup.vala',
2929
'WorkspaceSystem' / 'Workspace.vala',
30+
'WorkspaceSystem' / 'WorkspaceItem.vala',
3031
'WorkspaceSystem' / 'WorkspaceSystem.vala'
3132
]
3233

0 commit comments

Comments
 (0)