✨ feat(applications-dock): add cross-section drag functionality for pinning and unpinning apps
This commit is contained in:
1 file changed
+27
-14
@@ -69,10 +69,10 @@ class Applications(Box):
|
|||||||
super().__init__(
|
super().__init__(
|
||||||
name="applications-dock", orientation=orientation_val, spacing=4, **kwargs
|
name="applications-dock", orientation=orientation_val, spacing=4, **kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
# Store reference to the dock instance
|
# Store reference to the dock instance
|
||||||
self.dock_instance = dock_instance
|
self.dock_instance = dock_instance
|
||||||
|
|
||||||
self.config = read_config()
|
self.config = read_config()
|
||||||
self.conn = get_hyprland_connection()
|
self.conn = get_hyprland_connection()
|
||||||
self.icon_resolver = IconResolver()
|
self.icon_resolver = IconResolver()
|
||||||
@@ -426,7 +426,7 @@ class Applications(Box):
|
|||||||
def on_drag_begin(self, widget, drag_context):
|
def on_drag_begin(self, widget, drag_context):
|
||||||
self._drag_in_progress = True
|
self._drag_in_progress = True
|
||||||
Gtk.drag_set_icon_surface(drag_context, createSurfaceFromWidget(widget))
|
Gtk.drag_set_icon_surface(drag_context, createSurfaceFromWidget(widget))
|
||||||
|
|
||||||
# Prevent dock from hiding during drag
|
# Prevent dock from hiding during drag
|
||||||
if self.dock_instance:
|
if self.dock_instance:
|
||||||
self.dock_instance.prevent_hiding(True)
|
self.dock_instance.prevent_hiding(True)
|
||||||
@@ -454,17 +454,22 @@ class Applications(Box):
|
|||||||
if child.get_name() == "dock-separator":
|
if child.get_name() == "dock-separator":
|
||||||
separator_index = i
|
separator_index = i
|
||||||
break
|
break
|
||||||
|
|
||||||
# Check if we're dragging from unpinned to pinned section
|
# Check if we're dragging from unpinned to pinned section
|
||||||
cross_section_drag = separator_index != -1 and (
|
cross_section_drag_to_pin = separator_index != -1 and (
|
||||||
(source_index > separator_index and target_index < separator_index)
|
source_index > separator_index and target_index < separator_index
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Check if we're dragging from pinned to unpinned section
|
||||||
|
cross_section_drag_to_unpin = separator_index != -1 and (
|
||||||
|
source_index < separator_index and target_index > separator_index
|
||||||
|
)
|
||||||
|
|
||||||
# If dragging from unpinned to pinned, add to pinned apps
|
# If dragging from unpinned to pinned, add to pinned apps
|
||||||
if cross_section_drag:
|
if cross_section_drag_to_pin:
|
||||||
source_widget = children[source_index]
|
source_widget = children[source_index]
|
||||||
app_identifier = source_widget.app_identifier
|
app_identifier = source_widget.app_identifier
|
||||||
|
|
||||||
# Add to pinned apps if not already pinned
|
# Add to pinned apps if not already pinned
|
||||||
if hasattr(source_widget, "desktop_app") and source_widget.desktop_app:
|
if hasattr(source_widget, "desktop_app") and source_widget.desktop_app:
|
||||||
app = source_widget.desktop_app
|
app = source_widget.desktop_app
|
||||||
@@ -478,10 +483,18 @@ class Applications(Box):
|
|||||||
self.pinned.insert(target_index, app_data_obj)
|
self.pinned.insert(target_index, app_data_obj)
|
||||||
else:
|
else:
|
||||||
self.pinned.insert(target_index, app_identifier)
|
self.pinned.insert(target_index, app_identifier)
|
||||||
|
|
||||||
self.config["pinned_apps"] = self.pinned
|
self.config["pinned_apps"] = self.pinned
|
||||||
self.update_pinned_apps_file()
|
self.update_pinned_apps_file()
|
||||||
self.update_applications()
|
self.update_applications()
|
||||||
|
# If dragging from pinned to unpinned, remove from pinned apps
|
||||||
|
elif cross_section_drag_to_unpin:
|
||||||
|
# Remove from pinned apps
|
||||||
|
if source_index < len(self.pinned):
|
||||||
|
self.pinned.pop(source_index)
|
||||||
|
self.config["pinned_apps"] = self.pinned
|
||||||
|
self.update_pinned_apps_file()
|
||||||
|
self.update_applications()
|
||||||
else:
|
else:
|
||||||
# Regular reordering within the same section
|
# Regular reordering within the same section
|
||||||
if source_index < separator_index and target_index < separator_index:
|
if source_index < separator_index and target_index < separator_index:
|
||||||
@@ -496,7 +509,7 @@ class Applications(Box):
|
|||||||
# since unpinned apps aren't stored in config
|
# since unpinned apps aren't stored in config
|
||||||
child_to_move = children.pop(source_index)
|
child_to_move = children.pop(source_index)
|
||||||
children.insert(target_index, child_to_move)
|
children.insert(target_index, child_to_move)
|
||||||
|
|
||||||
# Update the UI
|
# Update the UI
|
||||||
for child in self.get_children():
|
for child in self.get_children():
|
||||||
self.remove(child)
|
self.remove(child)
|
||||||
@@ -507,11 +520,11 @@ class Applications(Box):
|
|||||||
def on_drag_end(self, widget, drag_context):
|
def on_drag_end(self, widget, drag_context):
|
||||||
if not self._drag_in_progress:
|
if not self._drag_in_progress:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Process drag end...
|
# Process drag end...
|
||||||
|
|
||||||
self._drag_in_progress = False
|
self._drag_in_progress = False
|
||||||
|
|
||||||
# Allow dock to hide again
|
# Allow dock to hide again
|
||||||
if self.dock_instance:
|
if self.dock_instance:
|
||||||
self.dock_instance.prevent_hiding(False)
|
self.dock_instance.prevent_hiding(False)
|
||||||
Reference in new issue
Block a user