Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Upgrade to new Lipstick's compositor APIs
  • Loading branch information
FlorentRevest committed Feb 28, 2017
1 parent cab1043 commit 8578624
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 127 deletions.
2 changes: 1 addition & 1 deletion asteroid-launcher.pro
Expand Up @@ -51,7 +51,7 @@ notifications.files = qml/NotificationPreview.qml
INSTALLS += styles qml qmlcompositor scripts system volumecontrol connectivity notifications watchfaces

CONFIG += qt link_pkgconfig
QT += quick compositor
QT += quick waylandcompositor
DEFINES += QT_COMPOSITOR_QUICK
HEADERS += \
launcherwindowmodel.h \
Expand Down
2 changes: 0 additions & 2 deletions qml/SwitcherItem.qml
Expand Up @@ -44,8 +44,6 @@ MouseArea {
id: windowPixmap
anchors.fill: parent
windowId: model.window
smooth: true
radius: 5
}
BrightnessContrast {
anchors.fill: parent
Expand Down
250 changes: 126 additions & 124 deletions qml/compositor.qml
Expand Up @@ -36,62 +36,15 @@ import org.asteroid.controls 1.0
import "desktop.js" as Desktop
import "compositor"

Compositor {
Item {
id: root

property Item homeWindow

// Set to the item of the current topmost window
property Item topmostWindow

// True if the home window is the topmost window
homeActive: topmostWindow == root.homeWindow
property bool appActive: !homeActive

// The application window that was most recently topmost
property Item topmostApplicationWindow
property Item topmostAlarmWindow: null

readonly property bool topmostWindowRequestsGesturesDisabled: topmostWindow && topmostWindow.window
&& topmostWindow.window.surface
&& (topmostWindow.window.surface.windowFlags & 1)

function windowToFront(winId) {
var o = root.windowForId(winId)
var window = null

if (o) window = o.userData
if (window == null) window = homeWindow

setCurrentWindow(window)
}

function setCurrentWindow(w, skipAnimation) {
if (w == null)
w = homeWindow

topmostWindow = w;

if (topmostWindow == homeWindow || topmostWindow == null) {
clearKeyboardFocus()
} else {
if (topmostApplicationWindow) topmostApplicationWindow.visible = false
topmostApplicationWindow = topmostWindow
topmostApplicationWindow.visible = true
if (!skipAnimation) topmostApplicationWindow.animateIn()
w.window.takeFocus()
}
}

onSensorOrientationChanged: {
screenOrientation = sensorOrientation
}
anchors.fill: parent

Connections {
target: root
target: comp.quickWindow
onActiveFocusItemChanged: {
// Search for the layer of the focus item
var focusedLayer = root.activeFocusItem
var focusedLayer = comp.activeFocusItem
while (focusedLayer && focusedLayer.parent !== layersParent)
focusedLayer = focusedLayer.parent

Expand All @@ -106,7 +59,7 @@ Compositor {

Item {
id: homeLayer
z: root.homeActive ? 4 : 1
z: comp.homeActive ? 4 : 1
anchors.fill: parent
}

Expand All @@ -116,14 +69,14 @@ Compositor {

width: parent.width
height: parent.height
visible: root.appActive
visible: comp.appActive
}

Item {
id: overlayLayer
z: 5

visible: root.appActive
visible: comp.appActive
}

Item {
Expand All @@ -138,11 +91,11 @@ Compositor {

BorderGestureArea {
id: gestureArea
enabled: root.appActive
enabled: comp.appActive
z: 7
anchors.fill: parent
acceptsDown: true
acceptsRight: !topmostWindowRequestsGesturesDisabled
acceptsRight: !comp.topmostWindowRequestsGesturesDisabled

property real swipeThreshold: 0.15

Expand All @@ -160,12 +113,12 @@ Compositor {
swipeAnimation.valueTo = inverted ? -max : max
swipeAnimation.start()
if (gesture == "down") {
Lipstick.compositor.closeClientForWindowId(topmostWindow.window.windowId)
Lipstick.compositor.closeClientForWindowId(comp.topmostWindow.window.windowId)
}
} else {
cancelAnimation.start()
}
} else if (root.homeActive){
} else if (comp.homeActive){
cancelAnimation.start()
}
}
Expand All @@ -180,7 +133,7 @@ Compositor {
}

PropertyChanges {
target: root.topmostAlarmWindow == null ? appLayer : alarmsLayer
target: comp.topmostAlarmWindow == null ? appLayer : alarmsLayer
opacity: (width-2*gestureArea.value)/width
x: gestureArea.horizontal ? gestureArea.value : 0
y: gestureArea.horizontal ? 0 : gestureArea.value
Expand Down Expand Up @@ -220,7 +173,7 @@ Compositor {
}

ScriptAction {
script: setCurrentWindow(root.homeWindow)
script: comp.setCurrentWindow(comp.homeWindow)
}

PropertyAction {
Expand All @@ -241,87 +194,136 @@ Compositor {
WindowWrapperAlpha { }
}

Component {
id: mysticWrapper
WindowWrapperMystic { }
}

Timer {
id: delayTimer
interval: 150
repeat: false
onTriggered: setCurrentWindow(root.homeWindow)
}
onDisplayOff: {
if (root.topmostAlarmWindow == null)
delayTimer.start()
onTriggered: comp.setCurrentWindow(comp.homeWindow)
}

onWindowAdded: {
var isHomeWindow = window.isInProcess && root.homeWindow == null && window.title === "Home"
var isDialogWindow = window.category === "dialog"
var isNotificationWindow = window.category == "notification"
var isOverlayWindow = window.category == "overlay"
var isAlarmWindow = window.category == "alarm"
var parent = null
if (window.category == "cover") {
window.visible = false
return
Compositor {
id: comp

property Item homeWindow

// Set to the item of the current topmost window
property Item topmostWindow

// True if the home window is the topmost window
homeActive: topmostWindow == comp.homeWindow
property bool appActive: !homeActive

// The application window that was most recently topmost
property Item topmostApplicationWindow
property Item topmostAlarmWindow: null

readonly property bool topmostWindowRequestsGesturesDisabled: topmostWindow && topmostWindow.window
&& (topmostWindow.window.windowFlags & 1)

function windowToFront(winId) {
var o = comp.windowForId(winId)
var window = null

if (o) window = o.userData
if (window == null) window = homeWindow

setCurrentWindow(window)
}
if (isHomeWindow) {
parent = homeLayer
} else if (isNotificationWindow) {
parent = notificationLayer
} else if (isOverlayWindow){
parent = overlayLayer
} else if (isAlarmWindow) {
parent = alarmsLayer
} else {
parent = appLayer

function setCurrentWindow(w, skipAnimation) {
if (w == null)
w = homeWindow

topmostWindow = w;

if (topmostWindow == homeWindow || topmostWindow == null) {
clearKeyboardFocus()
} else {
if (topmostApplicationWindow) topmostApplicationWindow.visible = false
topmostApplicationWindow = topmostWindow
topmostApplicationWindow.visible = true
if (!skipAnimation) topmostApplicationWindow.animateIn()
w.window.takeFocus()
}
}

var w;
if (isOverlayWindow) w = alphaWrapper.createObject(parent, { window: window })
else w = windowWrapper.createObject(parent, { window: window })
onSensorOrientationChanged: {
screenOrientation = sensorOrientation
}

window.userData = w
onDisplayOff: {
if (comp.topmostAlarmWindow == null)
delayTimer.start()
}

if (isHomeWindow) {
root.homeWindow = w
setCurrentWindow(homeWindow)
} else if (isNotificationWindow || isOverlayWindow) {
onWindowAdded: {
var isHomeWindow = window.isInProcess && comp.homeWindow == null && window.title === "Home"
var isDialogWindow = window.category === "dialog"
var isNotificationWindow = window.category == "notification"
var isOverlayWindow = window.category == "overlay"
var isAlarmWindow = window.category == "alarm"
var parent = null
if (window.category == "cover") {
window.visible = false
return
}
if (isHomeWindow) {
parent = homeLayer
} else if (isNotificationWindow) {
parent = notificationLayer
} else if (isOverlayWindow){
parent = overlayLayer
} else if (isAlarmWindow) {
parent = alarmsLayer
} else {
parent = appLayer
}

var w;
if (isOverlayWindow) w = alphaWrapper.createObject(parent, { window: window })
else w = windowWrapper.createObject(parent, { window: window })

} else if (isDialogWindow){
setCurrentWindow(window)
} else if (isAlarmWindow){
root.topmostAlarmWindow = window
w = mysticWrapper.createObject(parent, {window: window})
window.userData = w
setCurrentWindow(w)
} else {
if (!root.topmostAlarmWindow) {
w = mysticWrapper.createObject(parent, {window: window})
window.userData = w
setCurrentWindow(w)

if (isHomeWindow) {
comp.homeWindow = w
setCurrentWindow(homeWindow)
} else if (isNotificationWindow || isOverlayWindow) {

} else if (isDialogWindow){
setCurrentWindow(window)
} else if (isAlarmWindow){
comp.topmostAlarmWindow = window
setCurrentWindow(window)
} else {
if (!comp.topmostAlarmWindow) {
setCurrentWindow(w)
}
}
}
}

onWindowRaised: {
windowToFront(window.windowId)
}

onWindowRemoved: {
Desktop.instance.switcher.switchModel.removeWindowForTitle(window.title)
var w = window.userData;
if (window.category == "alarm") {
root.topmostAlarmWindow = null
setCurrentWindow(root.homeWindow)
onWindowRaised: {
windowToFront(window.windowId)
}
if (root.topmostWindow == w)
setCurrentWindow(root.homeWindow);

if (window.userData)
window.userData.destroy()
onWindowRemoved: {
console.log("onWindowRemoved310")
Desktop.instance.switcher.switchModel.removeWindowForTitle(window.title)
console.log("onWindowRemoved312")
var w = window.userData;
console.log("onWindowRemoved314")
if (window.category == "alarm") {
comp.topmostAlarmWindow = null
setCurrentWindow(comp.homeWindow)
}
console.log("onWindowRemoved319")
if (comp.topmostWindow == w)
setCurrentWindow(comp.homeWindow);

console.log("onWindowRemoved323")
if (window.userData)
window.userData.destroy()
console.log("onWindowRemoved326")
}
}
}

0 comments on commit 8578624

Please sign in to comment.