From 0e77abb21f4918507e921cbc51f9c16a03a0830e Mon Sep 17 00:00:00 2001 From: Tom Beckmann Date: Sun, 15 Jun 2014 20:33:10 +0200 Subject: [PATCH] connect close button, add window icon --- src/DragDropAction.vala | 10 ++- src/Widgets/MultitaskingView/IconGroup.vala | 9 ++- .../TiledWindowContainer.vala | 65 +++++++++++++++++-- 3 files changed, 73 insertions(+), 11 deletions(-) diff --git a/src/DragDropAction.vala b/src/DragDropAction.vala index b999bb03..77c59137 100644 --- a/src/DragDropAction.vala +++ b/src/DragDropAction.vala @@ -66,8 +66,10 @@ namespace Gala /** * The source has been clicked, but the movement was not larger than * the drag threshold. Useful if the source is also activable. + * + * @param button The button which was pressed */ - public signal void actor_clicked (); + public signal void actor_clicked (uint32 button); /** * The type of the action @@ -151,8 +153,10 @@ namespace Gala bool source_clicked (Clutter.ButtonEvent event) { - if (event.button != 1) + if (event.button != 1) { + actor_clicked (event.button); return false; + } actor.get_stage ().captured_event.connect (follow_move); clicked = true; @@ -194,7 +198,7 @@ namespace Gala // release has happened within bounds of actor if (x < ex && x + actor.width > ex && y < ey && y + actor.height > ey) { - actor_clicked (); + actor_clicked (event.get_button ()); } actor.get_stage ().captured_event.disconnect (follow_move); diff --git a/src/Widgets/MultitaskingView/IconGroup.vala b/src/Widgets/MultitaskingView/IconGroup.vala index 956f5fd9..33ba62fc 100644 --- a/src/Widgets/MultitaskingView/IconGroup.vala +++ b/src/Widgets/MultitaskingView/IconGroup.vala @@ -26,7 +26,6 @@ namespace Gala set_size (_icon_size, _icon_size); fade_new_icon (); - //get_transition ("size").completed.connect (fade_new_icon); } } @@ -132,8 +131,12 @@ namespace Gala break; } } - if (pixbuf != null) - new_icon.set_from_pixbuf (pixbuf); + + if (pixbuf != null) { + try { + new_icon.set_from_pixbuf (pixbuf); + } catch (Error e) {} + } add_child (new_icon); diff --git a/src/Widgets/MultitaskingView/TiledWindowContainer.vala b/src/Widgets/MultitaskingView/TiledWindowContainer.vala index 0cfb0e00..7c1af2c6 100644 --- a/src/Widgets/MultitaskingView/TiledWindowContainer.vala +++ b/src/Widgets/MultitaskingView/TiledWindowContainer.vala @@ -5,6 +5,8 @@ namespace Gala { public class TiledWindow : Actor { + const int WINDOW_ICON_SIZE = 64; + public signal void selected (); public signal void request_reposition (); @@ -18,6 +20,7 @@ namespace Gala int prev_index = -1; Actor close_button; + GtkClutter.Texture window_icon; public TiledWindow (Meta.Window window) { @@ -34,11 +37,43 @@ namespace Gala drag_action.destination_crossed.connect (drag_destination_crossed); drag_action.drag_end.connect (drag_end); drag_action.drag_canceled.connect (drag_canceled); - drag_action.actor_clicked.connect (() => { selected (); }); + drag_action.actor_clicked.connect ((button) => { + switch (button) { + case 1: + selected (); + break; + case 2: + close_window (); + break; + } + }); add_action (drag_action); close_button = Utils.create_close_button (); + close_button.opacity = 0; + close_button.set_easing_duration (200); + close_button.button_press_event.connect (() => { + close_window (); + return true; + }); + enter_event.connect (() => { + close_button.opacity = 255; + return false; + }); + leave_event.connect (() => { + close_button.opacity = 0; + return false; + }); + + window_icon = new GtkClutter.Texture (); + window_icon.opacity = 0; + window_icon.set_easing_duration (300); + try { + window_icon.set_from_pixbuf (Utils.get_icon_for_window (window, WINDOW_ICON_SIZE)); + } catch (Error e) {} + + add_child (window_icon); add_child (close_button); } @@ -78,6 +113,8 @@ namespace Gala set_position (outer_rect.x, outer_rect.y); set_size (outer_rect.width, outer_rect.height); + + window_icon.opacity = 0; } public void take_slot (Meta.Rectangle rect) @@ -89,6 +126,8 @@ namespace Gala set_size (rect.width, rect.height); set_position (rect.x, rect.y); + + window_icon.opacity = 255; } public override void allocate (ActorBox box, AllocationFlags flags) @@ -97,7 +136,6 @@ namespace Gala foreach (var child in get_children ()) { if (child != clone) - // child.allocate ({ child.x, child.y, child.x + child.width, child.y + child.height }, flags); child.allocate_preferred_size (flags); } @@ -122,16 +160,33 @@ namespace Gala Granite.CloseButtonPosition pos; Granite.Widgets.Utils.get_default_close_button_position (out pos); - close_button.y = 0; + close_button.save_easing_state (); + close_button.set_easing_duration (0); + + close_button.y = -close_button.height * 0.25f; switch (pos) { case Granite.CloseButtonPosition.RIGHT: - close_button.x = dest_width; + close_button.x = dest_width + close_button.width * 0.25f; break; case Granite.CloseButtonPosition.LEFT: - close_button.x = 0; + close_button.x = -close_button.width * 0.25f; break; } + close_button.restore_easing_state (); + + window_icon.save_easing_state (); + window_icon.set_easing_duration (0); + + window_icon.x = (dest_width - WINDOW_ICON_SIZE) / 2; + window_icon.y = dest_height - WINDOW_ICON_SIZE * 0.75f; + + window_icon.restore_easing_state (); + } + + void close_window () + { + window.delete (window.get_screen ().get_display ().get_current_time ()); } void unmanaged ()