~gang65/unity-2d/new-app-menu

« back to all changes in this revision

Viewing changes to shell/common/visibilityBehaviors/IntelliHideBehavior.qml

  • Committer: Tarmac
  • Author(s): Albert Astals, Ugo Riboni, Michał Sawicz, Florian Boucault, LDS
  • Date: 2012-02-10 17:32:14 UTC
  • mfrom: (771.3.235 unity-2d-shell_trunk)
  • Revision ID: tarmac-20120210173214-eekg5uiqdb7gjza6
Merge launcher and dash into a common new QML scene: the shell.
 - Created a shell folder that holds both launcher and dash QML code, the C++ code for the single binary and a common folder with shared QML files
 - The shell occupies the whole screen but is shaped for input where it is transparent in order not to interfere with the rest of the windows
 - The shell binary, unity-2d-shell, has a -rootqml option that lets the user specify the QML file to load
 - Implement visibility behaviours in QML instead of C++
 - Do not use D-Bus anymore to communicate between the launcher and the dash
 - Remove the homebutton panel plugin
 - Make the strut setting reusable outside of Unity2dPanel
 - Make LauncherDropItem a FocusScope
 - Implement gesture handling in QML instead of C++

Known issues:
 - In non composited mode there is a 1px wide rectangle on the edge of the screen where the launcher is hidden. This is acceptable for the moment since XFixes barriers to show the launcher are in the plan and will get rid of this problem
 - HomeShortcuts.qml has a transparent Rectangle to fix alignment in RTL mode that causes QML warnings. This is acceptable since the Home lens is going away. Fixes: . Approved by .

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of unity-2d
 
3
 *
 
4
 * Copyright 2012 Canonical Ltd.
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; version 3.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
import QtQuick 1.0
 
20
import Unity2d 1.0
 
21
import "../utils.js" as Utils
 
22
 
 
23
// Shows the target when it has the focus or when you move the
 
24
// mouse for 500 msec to the edge of the target or there are no 
 
25
// windows that intersect with the target
 
26
// Hides the target when none of the above conditions are met
 
27
// and you have not had the mouse over it during more than 1000 msec
 
28
// To use this Behavior your target needs to provide two properties
 
29
//  - containsMouse: Defines if the mouse is inside the target
 
30
//  - outerEdgeContainsMouse: Defines if the mouse is in the edge of the target
 
31
 
 
32
BaseBehavior {
 
33
    id: intellihide
 
34
 
 
35
    property bool shownBecauseOfMousePosition: false
 
36
 
 
37
    shown: target !== undefined && (target.activeFocus || shownBecauseOfMousePosition || !windows.intersects)
 
38
 
 
39
    onForcedVisibleChanged:
 
40
    {
 
41
        if (!forcedVisible) {
 
42
            if (!target.containsMouse && forcedVisibleChangeId != "dash") {
 
43
                shownBecauseOfMousePosition = true
 
44
                mouseLeaveTimer.restart()
 
45
            }
 
46
        }
 
47
    }
 
48
 
 
49
    Timer {
 
50
        id: edgeHitTimer
 
51
        interval: 500
 
52
        onTriggered: shownBecauseOfMousePosition = true
 
53
    }
 
54
 
 
55
    Timer {
 
56
        id: mouseLeaveTimer
 
57
        interval: 1000
 
58
        onTriggered: shownBecauseOfMousePosition = false
 
59
    }
 
60
 
 
61
    Connections {
 
62
        target: (intellihide.target !== undefined) ? intellihide.target : null
 
63
        onOuterEdgeContainsMouseChanged: edgeHitTimer.running = target.outerEdgeContainsMouse
 
64
        ignoreUnknownSignals: true
 
65
    }
 
66
 
 
67
    Connections {
 
68
        target: (intellihide.target !== undefined) ? intellihide.target : null
 
69
        onContainsMouseChanged: {
 
70
            if ((shown || forcedVisible) && target.containsMouse) {
 
71
                shownBecauseOfMousePosition = true
 
72
            }
 
73
            mouseLeaveTimer.running = !target.containsMouse
 
74
        }
 
75
        ignoreUnknownSignals: true
 
76
    }
 
77
 
 
78
    WindowsIntersectMonitor {
 
79
        id: windows
 
80
        monitoredArea: {
 
81
            if (intellihide.target) {
 
82
                if (Utils.isLeftToRight()) {
 
83
                    return Qt.rect(0,
 
84
                                   intellihide.target.y,
 
85
                                   intellihide.target.width,
 
86
                                   intellihide.target.height)
 
87
                } else {
 
88
                    return Qt.rect(declarativeView.screen.availableGeometry.width - intellihide.target.width,
 
89
                                   intellihide.target.y,
 
90
                                   intellihide.target.width,
 
91
                                   intellihide.target.height)
 
92
                }
 
93
            } else {
 
94
                return Qt.rect(0, 0, 0, 0)
 
95
            }
 
96
        }
 
97
    }
 
98
}