diff options
| author | Jason Smith <jason.smith@canonical.com> | 2010-12-15 18:50:38 -0500 |
|---|---|---|
| committer | Jason Smith <jason.smith@canonical.com> | 2010-12-15 18:50:38 -0500 |
| commit | b3920c8a47b55da7f627e30f0b5deadcac7446ce (patch) | |
| tree | 6b1d98ca1be2a7b8432663844261ae7577a8976d /src | |
| parent | 30ea8f72aa3d4c0f3d96dc567cda392bd148f94f (diff) | |
Collapse launcher when dragging outside launcher
(bzr r711.1.5)
Diffstat (limited to 'src')
| -rw-r--r-- | src/Launcher.cpp | 75 | ||||
| -rw-r--r-- | src/Launcher.h | 14 | ||||
| -rw-r--r-- | src/LauncherController.cpp | 102 | ||||
| -rw-r--r-- | src/LauncherController.h | 5 |
4 files changed, 134 insertions, 62 deletions
diff --git a/src/Launcher.cpp b/src/Launcher.cpp index 073582a73..efb2ed8ee 100644 --- a/src/Launcher.cpp +++ b/src/Launcher.cpp @@ -263,7 +263,6 @@ Launcher::Launcher(nux::BaseWindow *parent, CompScreen *screen, NUX_FILE_LINE_DE _launcher_drag_delta = 0; _dnd_delta_y = 0; _dnd_delta_x = 0; - _anim_handle = 0; _autohide_handle = 0; _floating = false; _hovered = false; @@ -283,6 +282,8 @@ Launcher::Launcher(nux::BaseWindow *parent, CompScreen *screen, NUX_FILE_LINE_DE _drag_end_time.tv_nsec = 0; _drag_start_time.tv_sec = 0; _drag_start_time.tv_nsec = 0; + _drag_threshold_time.tv_sec = 0; + _drag_threshold_time.tv_nsec = 0; _autohide_time.tv_sec = 0; _autohide_time.tv_nsec = 0; @@ -322,8 +323,21 @@ Launcher::AddProperties (GVariantBuilder *builder) g_variant_builder_add (builder, "{sv}", "mouse-inside-launcher", g_variant_new_boolean (_mouse_inside_launcher)); } -/* Render Layout Logic */ +void Launcher::SetMousePosition (int x, int y) +{ + bool beyond_drag_threshold = MouseBeyondDragThreshold (); + _mouse_position = nux::Point2 (x, y); + + if (beyond_drag_threshold != MouseBeyondDragThreshold ()) + SetTimeStruct (&_drag_threshold_time, &_drag_threshold_time, ANIM_DURATION_SHORT); +} +bool Launcher::MouseBeyondDragThreshold () +{ + return _mouse_position.x > GetGeometry ().width + _icon_size / 2; +} + +/* Render Layout Logic */ float Launcher::GetHoverProgress (struct timespec const ¤t) { if (_hovered) @@ -353,6 +367,14 @@ float Launcher::AutohideProgress (struct timespec const ¤t) return 1.0f - CLAMP ((float) (TimeDelta (¤t, &_autohide_time)) / (float) ANIM_DURATION_SHORT, 0.0f, 1.0f); } +float Launcher::DragThresholdProgress (struct timespec const ¤t) +{ + if (MouseBeyondDragThreshold ()) + return 1.0f - CLAMP ((float) (TimeDelta (¤t, &_drag_threshold_time)) / (float) ANIM_DURATION_SHORT, 0.0f, 1.0f); + else + return CLAMP ((float) (TimeDelta (¤t, &_drag_threshold_time)) / (float) ANIM_DURATION_SHORT, 0.0f, 1.0f); +} + gboolean Launcher::AnimationTimeout (gpointer data) { Launcher *self = (Launcher*) data; @@ -429,6 +451,9 @@ bool Launcher::AnimationInProgress () if (TimeDelta (¤t, &_autohide_time) < ANIM_DURATION_SHORT) return true; + + if (TimeDelta (¤t, &_drag_threshold_time) < ANIM_DURATION_SHORT) + return true; // animations happening on specific icons LauncherModel::iterator it; @@ -673,6 +698,9 @@ void Launcher::FillRenderArg (LauncherIcon *icon, center.z = 300.0f * (1.0f - size_modifier); } + if (icon == _drag_icon) + size_modifier *= DragThresholdProgress (current); + if (size_modifier <= 0.0f || icon == _drag_icon) arg.skip = true; @@ -1541,7 +1569,7 @@ long Launcher::PostLayoutManagement(long LayoutResult) { View::PostLayoutManagement(LayoutResult); - _mouse_position = nux::Point2 (0, 0); + SetMousePosition (0, 0); return nux::eCompliantHeight | nux::eCompliantWidth; } @@ -1550,24 +1578,6 @@ void Launcher::PositionChildLayout(float offsetX, float offsetY) { } -bool Launcher::TooltipNotify(LauncherIcon* Icon) -{ - if(GetActiveMenuIcon()) - return false; - return true; -} - -bool Launcher::MenuNotify(LauncherIcon* Icon) -{ - - - return true; -} - -void Launcher::NotifyMenuTermination(LauncherIcon* Icon) -{ -} - void Launcher::StartIconDrag (LauncherIcon *icon) { if (!icon) @@ -1612,14 +1622,23 @@ void Launcher::UpdateDragWindowPosition (int x, int y) LauncherIcon *hovered_icon = MouseIconIntersection ((int) (GetGeometry ().x / 2.0f), y); + struct timespec current; + clock_gettime (CLOCK_MONOTONIC, ¤t); if (_drag_icon && hovered_icon && _drag_icon != hovered_icon) - request_reorder.emit (_drag_icon, hovered_icon); + { + float progress = DragThresholdProgress (current); + + if (progress >= 1.0f) + request_reorder_smart.emit (_drag_icon, hovered_icon, true); + else if (progress == 0.0f) + request_reorder_before.emit (_drag_icon, hovered_icon, false); + } } } void Launcher::RecvMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags) { - _mouse_position = nux::Point2 (x, y); + SetMousePosition (x, y); MouseDownLogic (x, y, button_flags, key_flags); EnsureAnimation (); @@ -1627,7 +1646,7 @@ void Launcher::RecvMouseDown(int x, int y, unsigned long button_flags, unsigned void Launcher::RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags) { - _mouse_position = nux::Point2 (x, y); + SetMousePosition (x, y); nux::Geometry geo = GetGeometry (); if (_launcher_action_state != ACTION_NONE && !geo.IsInside(nux::Point(x, y))) @@ -1649,7 +1668,7 @@ void Launcher::RecvMouseUp(int x, int y, unsigned long button_flags, unsigned lo void Launcher::RecvMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags) { - _mouse_position = nux::Point2 (x, y); + SetMousePosition (x, y); _dnd_delta_y += dy; _dnd_delta_x += dx; @@ -1702,7 +1721,7 @@ void Launcher::RecvMouseDrag(int x, int y, int dx, int dy, unsigned long button_ void Launcher::RecvMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags) { - _mouse_position = nux::Point2 (x, y); + SetMousePosition (x, y); _mouse_inside_launcher = true; EnsureHoverState (); @@ -1713,7 +1732,7 @@ void Launcher::RecvMouseEnter(int x, int y, unsigned long button_flags, unsigned void Launcher::RecvMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags) { - _mouse_position = nux::Point2 (x, y); + SetMousePosition (x, y); _mouse_inside_launcher = false; if (_launcher_action_state == ACTION_NONE) @@ -1725,7 +1744,7 @@ void Launcher::RecvMouseLeave(int x, int y, unsigned long button_flags, unsigned void Launcher::RecvMouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags) { - _mouse_position = nux::Point2 (x, y); + SetMousePosition (x, y); // Every time the mouse moves, we check if it is inside an icon... EventLogic (); diff --git a/src/Launcher.h b/src/Launcher.h index a167f4162..dc1aa4f2e 100644 --- a/src/Launcher.h +++ b/src/Launcher.h @@ -49,11 +49,7 @@ public: LauncherIcon* GetActiveTooltipIcon() {return m_ActiveTooltipIcon;} LauncherIcon* GetActiveMenuIcon() {return m_ActiveMenuIcon;} - bool TooltipNotify(LauncherIcon* Icon); - bool MenuNotify(LauncherIcon* Icon); - void SetIconSize(int tile_size, int icon_size); - void NotifyMenuTermination(LauncherIcon* Icon); void SetModel (LauncherModel *model); @@ -75,7 +71,8 @@ public: virtual void RecvQuicklistOpened (QuicklistView *quicklist); virtual void RecvQuicklistClosed (QuicklistView *quicklist); - sigc::signal<void, LauncherIcon *, LauncherIcon *> request_reorder; + sigc::signal<void, LauncherIcon *, LauncherIcon *, bool> request_reorder_smart; + sigc::signal<void, LauncherIcon *, LauncherIcon *, bool> request_reorder_before; protected: // Introspectable methods const gchar* GetName (); @@ -122,6 +119,10 @@ private: static gboolean AnimationTimeout (gpointer data); static gboolean OnAutohideTimeout (gpointer data); static gboolean StrutHack (gpointer data); + + void SetMousePosition (int x, int y); + + bool MouseBeyondDragThreshold (); void OnTriggerMouseEnter (int x, int y, unsigned long button_flags, unsigned long key_flags); void OnTriggerMouseLeave (int x, int y, unsigned long button_flags, unsigned long key_flags); @@ -141,6 +142,7 @@ private: float DnDExitProgress (struct timespec const ¤t); float GetHoverProgress (struct timespec const ¤t); float AutohideProgress (struct timespec const ¤t); + float DragThresholdProgress (struct timespec const ¤t); float IconPresentProgress (LauncherIcon *icon, struct timespec const ¤t); float IconUrgentProgress (LauncherIcon *icon, struct timespec const ¤t); float IconShimmerProgress (LauncherIcon *icon, struct timespec const ¤t); @@ -270,7 +272,6 @@ private: nux::IntrusiveSP<nux::IOpenGLBaseTexture> _offscreen_drag_texture; nux::IntrusiveSP<nux::IOpenGLBaseTexture> _offscreen_progress_texture; - guint _anim_handle; guint _autohide_handle; nux::Matrix4 _view_matrix; @@ -293,6 +294,7 @@ private: struct timespec _exit_time; struct timespec _drag_end_time; struct timespec _drag_start_time; + struct timespec _drag_threshold_time; struct timespec _autohide_time; }; diff --git a/src/LauncherController.cpp b/src/LauncherController.cpp index 1c9aaa355..c295554c7 100644 --- a/src/LauncherController.cpp +++ b/src/LauncherController.cpp @@ -42,7 +42,8 @@ LauncherController::LauncherController(Launcher* launcher, CompScreen *screen, n InsertExpoAction (); InsertTrash (); - _launcher->request_reorder.connect (sigc::mem_fun (this, &LauncherController::OnLauncherRequestReorder)); + _launcher->request_reorder_smart.connect (sigc::mem_fun (this, &LauncherController::OnLauncherRequestReorderSmart)); + _launcher->request_reorder_before.connect (sigc::mem_fun (this, &LauncherController::OnLauncherRequestReorderBefore)); } LauncherController::~LauncherController() @@ -51,7 +52,74 @@ LauncherController::~LauncherController() } void -LauncherController::OnLauncherRequestReorder (LauncherIcon *icon, LauncherIcon *other) +LauncherController::SortAndSave () +{ + LauncherModel::iterator it; + _model->Sort (&LauncherController::CompareIcons); + + std::list<const char*> desktop_paths; + for (it = _model->begin (); it != _model->end (); it++) + { + BamfLauncherIcon *icon; + icon = dynamic_cast<BamfLauncherIcon*> (*it); + + if (!icon) + continue; + + if (!icon->IsSticky ()) + continue; + + const char* desktop_file = icon->DesktopFile (); + + if (desktop_file && strlen (desktop_file) > 0) + desktop_paths.push_back (desktop_file); + } + + _favorite_store->SetFavorites (desktop_paths); +} + +void +LauncherController::OnLauncherRequestReorderBefore (LauncherIcon *icon, LauncherIcon *other, bool save) +{ + if (icon == other) + return; + + LauncherModel::iterator it; + + int i = 0; + int j = 0; + for (it = _model->begin (); it != _model->end (); it++) + { + if ((*it) == icon) + { + j++; + continue; + } + + if ((*it) == other) + { + icon->SetSortPriority (i); + if (i != j && save) (*it)->SaveCenter (); + i++; + + (*it)->SetSortPriority (i); + if (i != j && save) (*it)->SaveCenter (); + i++; + } + else + { + (*it)->SetSortPriority (i); + if (i != j && save) (*it)->SaveCenter (); + i++; + } + j++; + } + + SortAndSave (); +} + +void +LauncherController::OnLauncherRequestReorderSmart (LauncherIcon *icon, LauncherIcon *other, bool save) { if (icon == other) return; @@ -75,51 +143,31 @@ LauncherController::OnLauncherRequestReorder (LauncherIcon *icon, LauncherIcon * if (!skipped) { icon->SetSortPriority (i); - if (i != j) (*it)->SaveCenter (); + if (i != j && save) (*it)->SaveCenter (); i++; } (*it)->SetSortPriority (i); - if (i != j) (*it)->SaveCenter (); + if (i != j && save) (*it)->SaveCenter (); i++; if (skipped) { icon->SetSortPriority (i); - if (i != j) (*it)->SaveCenter (); + if (i != j && save) (*it)->SaveCenter (); i++; } } else { (*it)->SetSortPriority (i); - if (i != j) (*it)->SaveCenter (); + if (i != j && save) (*it)->SaveCenter (); i++; } j++; } - _model->Sort (&LauncherController::CompareIcons); - - std::list<const char*> desktop_paths; - for (it = _model->begin (); it != _model->end (); it++) - { - BamfLauncherIcon *icon; - icon = dynamic_cast<BamfLauncherIcon*> (*it); - - if (!icon) - continue; - - if (!icon->IsSticky ()) - continue; - - const char* desktop_file = icon->DesktopFile (); - - if (desktop_file && strlen (desktop_file) > 0) - desktop_paths.push_back (desktop_file); - } - - _favorite_store->SetFavorites (desktop_paths); + SortAndSave (); } void diff --git a/src/LauncherController.h b/src/LauncherController.h index 61155f28e..a63afd150 100644 --- a/src/LauncherController.h +++ b/src/LauncherController.h @@ -53,7 +53,10 @@ private: FavoriteStore* _favorite_store; int _sort_priority; - void OnLauncherRequestReorder (LauncherIcon *icon, LauncherIcon *other); + void SortAndSave (); + + void OnLauncherRequestReorderSmart (LauncherIcon *icon, LauncherIcon *other, bool save); + void OnLauncherRequestReorderBefore (LauncherIcon *icon, LauncherIcon *before, bool save); void InsertExpoAction (); |
