52
52
#define BACKLIGHT_STRENGTH 0.9f
54
#define S_DBUS_NAME "com.canonical.Unity.Launcher"
55
#define S_DBUS_PATH "/com/canonical/Unity/Launcher"
56
#define S_DBUS_IFACE "com.canonical.Unity.Launcher"
54
58
NUX_IMPLEMENT_OBJECT_TYPE (Launcher);
72
76
timeref->tv_nsec -= remove * 1000000;
79
const gchar Launcher::introspection_xml[] =
81
" <interface name='com.canonical.Unity.Launcher'>"
83
" <method name='AddLauncherItemFromPosition'>"
84
" <arg type='s' name='icon' direction='in'/>"
85
" <arg type='s' name='title' direction='in'/>"
86
" <arg type='i' name='icon_x' direction='in'/>"
87
" <arg type='i' name='icon_y' direction='in'/>"
88
" <arg type='i' name='icon_size' direction='in'/>"
89
" <arg type='s' name='desktop_file' direction='in'/>"
90
" <arg type='s' name='aptdaemon_task' direction='in'/>"
96
GDBusInterfaceVTable Launcher::interface_vtable =
98
Launcher::handle_dbus_method_call,
77
105
Use this shader to pass vertices in screen coordinates in the C++ code and compute use
355
382
ubus_server_register_interest (ubus, UBUS_LAUNCHER_ACTION_DONE,
356
383
(UBusCallback)&Launcher::OnActionDone,
386
_dbus_owner = g_bus_own_name (G_BUS_TYPE_SESSION,
388
(GBusNameOwnerFlags) (G_BUS_NAME_OWNER_FLAGS_REPLACE | G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT),
359
395
SetDndEnabled (false, true);
608
645
return pow (1.0f - CLAMP ((float) (TimeDelta (¤t, &_times[TIME_DRAG_END])) / (float) ANIM_DURATION_LONG, 0.0f, 1.0f), 2);
611
float Launcher::DnDStartProgress (struct timespec const ¤t)
613
return CLAMP ((float) (TimeDelta (¤t, &_times[TIME_DRAG_START])) / (float) ANIM_DURATION, 0.0f, 1.0f);
616
648
float Launcher::AutohideProgress (struct timespec const ¤t)
749
781
// hover out animation
750
782
if (TimeDelta (¤t, &_times[TIME_LEAVE]) < ANIM_DURATION)
753
// drag start animation
754
if (TimeDelta (¤t, &_times[TIME_DRAG_START]) < ANIM_DURATION)
757
785
// drag end animation
758
786
if (TimeDelta (¤t, &_times[TIME_DRAG_END]) < ANIM_DURATION_LONG)
1487
1515
return _mouse_position.y;
1491
Launcher::SingleFingerHoldTimeout (gpointer data)
1493
Launcher* self = NULL;
1494
LauncherIcon* launcher_icon = NULL;
1496
self = (Launcher*) data;
1497
launcher_icon = self->MouseIconIntersection (self->GetMouseX (),
1498
self->GetMouseY ());
1500
launcher_icon->OpenQuicklist ();
1505
1518
gboolean Launcher::DrawLauncherTimeout (gpointer data)
1507
1520
Launcher *self = (Launcher*) data;
1542
1555
if (!window || !(window->type () & intersect_types) || !window->isMapped () || !window->isViewable ())
1545
if (CompRegion (window->serverInputRect ()).intersects (CompRect (geo.x, geo.y, geo.width, geo.height)))
1558
if (CompRegion (window->inputRect ()).intersects (CompRect (geo.x, geo.y, geo.width, geo.height)))
2337
2350
guint64 shortcut = arg.icon->GetShortcut ();
2339
2352
/* deal with dynamic labels for places, which can be set via the locale */
2340
if (shortcut != 0 && !g_ascii_isdigit ((gchar) shortcut))
2342
RenderIcon (GfxContext,
2344
arg.icon->GetSuperkeyLabel ()->GetDeviceTexture (),
2345
nux::Color (0xFFFFFFFF),
2347
arg.icon->_xform_coords["Tile"]);
2351
/* deal with the hardcoded labels used for the first 10 icons on the launcher */
2352
gchar key = (gchar) shortcut;
2355
if (!g_ascii_isdigit ((gchar) shortcut))
2357
case '1': index = 0; break;
2358
case '2': index = 1; break;
2359
case '3': index = 2; break;
2360
case '4': index = 3; break;
2361
case '5': index = 4; break;
2362
case '6': index = 5; break;
2363
case '7': index = 6; break;
2364
case '8': index = 7; break;
2365
case '9': index = 8; break;
2366
case '0': index = 9; break;
2357
RenderIcon (GfxContext,
2359
arg.icon->GetSuperkeyLabel ()->GetDeviceTexture (),
2360
nux::Color (0xFFFFFFFF),
2362
arg.icon->_xform_coords["Tile"]);
2366
/* deal with the hardcoded labels used for the first 10 icons on the launcher */
2367
gchar *shortcut_str = g_strdup_printf ("%c", (gchar)shortcut);
2368
int index = (atoi (shortcut_str) + 9) % 10; // Not -1 as -1 % 10 = -1…
2369
g_free (shortcut_str);
2370
2371
RenderIcon (GfxContext,
2372
2373
_superkey_labels[index]->GetDeviceTexture (),
2373
2374
nux::Color (0xFFFFFFFF),
2375
2376
arg.icon->_xform_coords["Tile"]);
2499
2501
EnsureAnimation ();
2505
gboolean Launcher::StartIconDragTimeout (gpointer data)
2507
Launcher *self = (Launcher*) data;
2509
// if we are still waiting…
2510
if (self->GetActionState () == ACTION_NONE)
2511
self->StartIconDragRequest (self->GetMouseX (), self->GetMouseY ());
2515
void Launcher::StartIconDragRequest (int x, int y)
2517
LauncherIcon *drag_icon = MouseIconIntersection ((int) (GetGeometry ().x / 2.0f), y);
2519
// FIXME: nux doesn't give nux::GetEventButton (button_flags) there, relying
2520
// on an internal Launcher property then
2521
if (drag_icon && (_last_button_press == 1) && _model->IconHasSister (drag_icon))
2523
StartIconDrag (drag_icon);
2524
SetActionState (ACTION_DRAG_ICON);
2525
UpdateDragWindowPosition (x, y);
2502
2529
void Launcher::StartIconDrag (LauncherIcon *icon)
2624
LauncherIcon *drag_icon = MouseIconIntersection ((int) (GetGeometry ().x / 2.0f), y);
2626
// FIXME: nux doesn't give nux::GetEventButton (button_flags) there, relying
2627
// on an internal Launcher property then
2628
if (drag_icon && (_last_button_press == 1) && _model->IconHasSister (drag_icon))
2630
StartIconDrag (drag_icon);
2631
SetActionState (ACTION_DRAG_ICON);
2632
UpdateDragWindowPosition (x, y);
2649
StartIconDragRequest (x, y);
2637
2652
else if (GetActionState () == ACTION_DRAG_LAUNCHER)
2899
2914
LauncherIcon* launcher_icon = 0;
2900
2915
launcher_icon = MouseIconIntersection (_mouse_position.x, _mouse_position.y);
2902
// this takes care of the one-finger-hold "event" on a launcher-icon
2903
if (_single_finger_hold_handle == 0)
2905
_single_finger_hold_handle = g_timeout_add (SINGLE_FINGER_HOLD_DURATION,
2906
&Launcher::SingleFingerHoldTimeout,
2908
if (_single_finger_hold_timer)
2909
g_timer_destroy (_single_finger_hold_timer);
2911
_single_finger_hold_timer = g_timer_new ();
2914
2917
if (launcher_icon)
2916
2919
_icon_mouse_down = launcher_icon;
2920
// if MouseUp after the time ended -> it's an icon drag, otherwise, it's starting an app
2921
if (_start_dragicon_handle > 0)
2922
g_source_remove (_start_dragicon_handle);
2923
_start_dragicon_handle = g_timeout_add (START_DRAGICON_DURATION, &Launcher::StartIconDragTimeout, this);
2917
2925
launcher_icon->MouseDown.emit (nux::GetEventButton (button_flags));
2921
2929
void Launcher::MouseUpLogic (int x, int y, unsigned long button_flags, unsigned long key_flags)
2923
2931
LauncherIcon* launcher_icon = 0;
2924
2933
launcher_icon = MouseIconIntersection (_mouse_position.x, _mouse_position.y);
2926
// this takes care of the one-finger-hold "event" on a launcher-icon
2927
if (_single_finger_hold_timer)
2929
// user "released" before single-finger-hold threshold
2930
if (g_timer_elapsed (_single_finger_hold_timer, NULL) < (float) SINGLE_FINGER_HOLD_DURATION / 1000.0)
2934
if (_single_finger_hold_handle > 0)
2936
g_source_remove (_single_finger_hold_handle);
2937
_single_finger_hold_handle = 0;
2940
// user "released" after single-finger-hold threshold...
2944
g_timer_destroy (_single_finger_hold_timer);
2945
_single_finger_hold_timer = NULL;
2948
if (_single_finger_hold_handle > 0)
2950
g_source_remove (_single_finger_hold_handle);
2951
_single_finger_hold_handle = 0;
2954
// ... don't start app, just return
2955
_icon_mouse_down = 0;
2960
g_timer_destroy (_single_finger_hold_timer);
2961
_single_finger_hold_timer = NULL;
2964
if (_single_finger_hold_handle > 0)
2966
g_source_remove (_single_finger_hold_handle);
2967
_single_finger_hold_handle = 0;
2935
if (_start_dragicon_handle > 0)
2936
g_source_remove (_start_dragicon_handle);
2937
_start_dragicon_handle = 0;
2971
2939
if (_icon_mouse_down && (_icon_mouse_down == launcher_icon))
2973
2941
_icon_mouse_down->MouseUp.emit (nux::GetEventButton (button_flags));
2975
if (GetActionState () == ACTION_NONE)
2943
if (GetActionState () == ACTION_NONE) {
2976
2944
_icon_mouse_down->MouseClick.emit (nux::GetEventButton (button_flags));
2979
2948
if (launcher_icon && (_icon_mouse_down != launcher_icon))
3688
Launcher::handle_dbus_method_call (GDBusConnection *connection,
3689
const gchar *sender,
3690
const gchar *object_path,
3691
const gchar *interface_name,
3692
const gchar *method_name,
3693
GVariant *parameters,
3694
GDBusMethodInvocation *invocation,
3698
if (g_strcmp0 (method_name, "AddLauncherItemFromPosition") == 0)
3705
gchar *desktop_file;
3706
gchar *aptdaemon_task;
3708
g_variant_get (parameters, "(ssiiiss)", &icon, &title, &icon_x, &icon_y, &icon_size, &desktop_file, &aptdaemon_task, NULL);
3710
Launcher *self = (Launcher*)user_data;
3711
self->launcher_addrequest.emit (desktop_file, NULL);
3713
g_dbus_method_invocation_return_value (invocation, NULL);
3716
g_free (desktop_file);
3717
g_free (aptdaemon_task);
3723
Launcher::OnBusAcquired (GDBusConnection *connection,
3727
GDBusNodeInfo *introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
3728
guint registration_id;
3730
if (!introspection_data) {
3731
g_warning ("No introspection data loaded. Won't get dynamic launcher addition.");
3737
registration_id = g_dbus_connection_register_object (connection,
3739
introspection_data->interfaces[0],
3744
if (!registration_id)
3745
g_warning ("Object registration failed. Won't get dynamic launcher addition.");
3750
Launcher::OnNameAcquired (GDBusConnection *connection,
3754
g_debug ("Acquired the name %s on the session bus\n", name);
3758
Launcher::OnNameLost (GDBusConnection *connection,
3762
g_debug ("Lost the name %s on the session bus\n", name);