@@ -81,8 +81,11 @@ namespace Gala
8181 }
8282 }
8383
84+ DragDropAction drag_action;
85+
8486 public Workspace workspace { get ; construct; }
8587
88+ Actor ? prev_parent = null ;
8689 Actor close_button;
8790 Actor icon_container;
8891 Cogl . Material dummy_material;
@@ -110,15 +113,13 @@ namespace Gala
110113
111114 dummy_material = new Cogl .Material ();
112115
113- var click = new ClickAction ();
114- click. clicked. connect (() = > selected ());
115- // when the actor is pressed, the ClickAction grabs all events, so we won't be
116- // notified when the cursor leaves the actor, which makes our close button stay
117- // forever. To fix this we hide the button for as long as the actor is pressed.
118- click. notify[" pressed" ]. connect (() = > {
119- toggle_close_button (! click. pressed && get_has_pointer ());
120- });
121- add_action (click);
116+ drag_action = new DragDropAction (DragDropActionType . SOURCE | DragDropActionType . DESTINATION , " multitaskingview-window" );
117+ drag_action. actor_clicked. connect (() = > selected ());
118+ drag_action. drag_begin. connect (drag_begin);
119+ drag_action. drag_end. connect (drag_end);
120+ drag_action. drag_canceled. connect (drag_canceled);
121+ drag_action. notify[" dragging" ]. connect (redraw);
122+ add_action (drag_action);
122123
123124 icon_container = new Actor ();
124125 icon_container. width = width;
@@ -213,7 +214,7 @@ namespace Gala
213214 */
214215 public override void paint ()
215216 {
216- if (backdrop_opacity < 1 ) {
217+ if (backdrop_opacity < 1 || drag_action . dragging ) {
217218 base . paint ();
218219 return ;
219220 }
@@ -309,6 +310,14 @@ namespace Gala
309310 }
310311 }
311312
313+ /**
314+ * Sets a hovered actor for the drag action.
315+ */
316+ public void set_hovered_actor (Actor actor )
317+ {
318+ drag_action. hovered = actor;
319+ }
320+
312321 /**
313322 * Trigger a redraw
314323 */
@@ -365,7 +374,13 @@ namespace Gala
365374 5 * scale
366375 );
367376
368- cr. set_source_rgba (0 , 0 , 0 , 0.1 );
377+ if (drag_action. dragging) {
378+ const double BG_COLOR = 53.0 / 255.0 ;
379+ cr. set_source_rgba (BG_COLOR , BG_COLOR , BG_COLOR , 0.7 );
380+ } else {
381+ cr. set_source_rgba (0 , 0 , 0 , 0.1 );
382+ }
383+
369384 cr. fill_preserve ();
370385
371386 cr. set_line_width (1 * scale);
@@ -489,5 +504,69 @@ namespace Gala
489504
490505 return false ;
491506 }
507+
508+ Actor drag_begin (float click_x , float click_y )
509+ {
510+ unowned Screen screen = workspace. get_screen ();
511+ if (icon_container. get_n_children () < 1 &&
512+ Prefs . get_dynamic_workspaces () &&
513+ workspace. index () == screen. get_n_workspaces () - 1 ) {
514+ return null ;
515+ }
516+
517+ float abs_x, abs_y;
518+ float prev_parent_x, prev_parent_y;
519+
520+ prev_parent = get_parent ();
521+ prev_parent. get_transformed_position (out prev_parent_x, out prev_parent_y);
522+
523+ var stage = get_stage ();
524+ var container = prev_parent as IconGroupContainer ;
525+ if (container != null ) {
526+ container. remove_group_in_place (this );
527+ container. reset_thumbs (0 );
528+ } else {
529+ prev_parent. remove_child (this );
530+ }
531+
532+ stage. add_child (this );
533+
534+ get_transformed_position (out abs_x, out abs_y);
535+ set_position (abs_x + prev_parent_x, abs_y + prev_parent_y);
536+
537+ close_button. opacity = 0 ;
538+
539+ return this ;
540+ }
541+
542+ void drag_end (Actor destination )
543+ {
544+ if (destination is WorkspaceInsertThumb ) {
545+ get_parent (). remove_child (this );
546+
547+ unowned WorkspaceInsertThumb inserter = (WorkspaceInsertThumb ) destination;
548+ workspace. get_screen (). reorder_workspace (workspace, inserter. workspace_index);
549+
550+ restore_group ();
551+ } else {
552+ drag_canceled ();
553+ }
554+ }
555+
556+ void drag_canceled ()
557+ {
558+ get_parent (). remove_child (this );
559+ restore_group ();
560+ }
561+
562+ void restore_group ()
563+ {
564+ var container = prev_parent as IconGroupContainer ;
565+ if (container != null ) {
566+ container. add_group (this );
567+ container. request_reposition (false );
568+ container. reset_thumbs (WorkspaceInsertThumb . EXPAND_DELAY );
569+ }
570+ }
492571 }
493572}
0 commit comments