Skip to content

Commit

Permalink
refactor: use two different window for two modes
Browse files Browse the repository at this point in the history
全屏和小窗口启动器现转而使用不同的两个窗口来管理窗口位置与状态,以此
避免共用窗口导致的窗口状态切换时,布局不必要的重新加载导致的卡顿问题。

Log:
  • Loading branch information
BLumia committed Dec 18, 2023
1 parent b343137 commit dfd126f
Showing 1 changed file with 102 additions and 78 deletions.
180 changes: 102 additions & 78 deletions qml/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,7 @@ import org.deepin.dtk 1.0

import org.deepin.launchpad 1.0

ApplicationWindow {
id: root

property bool isMenuShown: false

// title: activeFocusItem + " " + (activeFocusItem ? activeFocusItem.Accessible.name : "")
width: 780
height: 600
visible: LauncherController.visible
flags: {
if (DebugHelper.useRegularWindow) {
return Qt.Window
}
if (LauncherController.currentFrame === "WindowedFrame") {
return (Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint | Qt.Tool) // X11BypassWindowManagerHint
} else {
return (Qt.FramelessWindowHint | Qt.Tool)
}
}
DWindow.enabled: !DebugHelper.useRegularWindow
DWindow.enableBlurWindow: true
DWindow.enableSystemResize: false
DWindow.enableSystemMove: false

onVisibleChanged: {
updateWindowVisibilityAndPosition()
}

onActiveChanged: {
if (!active && !isMenuShown && !DebugHelper.avoidHideWindow) {
LauncherController.hideWithTimer()
}
}

QtObject {
function getCategoryName(section) {
switch (Number(section)) {
case AppItem.Internet:
Expand Down Expand Up @@ -72,11 +39,6 @@ ApplicationWindow {
}
}

function descaledRect(rect) {
let ratio = Screen.devicePixelRatio
return Qt.rect(rect.left / ratio, rect.top / ratio, rect.width / ratio, rect.height / ratio)
}

function launchApp(desktopId) {
if (DebugHelper.avoidLaunchApp) {
DTK.sendSystemMessage("dde-launchpad (debug)",
Expand All @@ -99,16 +61,16 @@ ApplicationWindow {
isFavoriteItem: isFavoriteItem,
hideFavoriteMenu: hideFavoriteMenu
});
menu.closed.connect(function() {
root.isMenuShown = false
root.requestActivate()
});
menu.popup();
root.isMenuShown = true
}

function descaledRect(rect) {
let ratio = Screen.devicePixelRatio
return Qt.rect(rect.left / ratio, rect.top / ratio, rect.width / ratio, rect.height / ratio)
}

function updateWindowVisibilityAndPosition() {
if (!root.visible) return;
if (!LauncherController.visible) return;

if (LauncherController.currentFrame === "WindowedFrame") {
// root.visibility = Window.Windowed
Expand Down Expand Up @@ -142,60 +104,122 @@ ApplicationWindow {

// Window mode: follow system theme
ApplicationHelper.setPaletteType(ApplicationHelper.UnknownType)
root.setGeometry(x, y, width, height)
windowedFrame.setGeometry(x, y, width, height)
windowedFrame.requestActivate()
} else {
// root.visibility = Window.FullScreen
// Fullscreen mode: always assume dark theme
ApplicationHelper.setPaletteType(ApplicationHelper.DarkType)
root.setGeometry(Screen.virtualX, Screen.virtualY, Screen.width, Screen.height)
fullscreenFrame.setGeometry(Screen.virtualX, Screen.virtualY, Screen.width, Screen.height)
fullscreenFrame.requestActivate()
}

root.requestActivate()
}

Connections {
target: DesktopIntegration
function onDockGeometryChanged() {
property var windowedFrame: ApplicationWindow {
visible: LauncherController.visible && (LauncherController.currentFrame === "WindowedFrame")

width: 780
height: 600
flags: {
if (DebugHelper.useRegularWindow) return Qt.Window
return (Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint | Qt.Tool)
}

DWindow.enabled: !DebugHelper.useRegularWindow
DWindow.enableBlurWindow: true
DWindow.enableSystemResize: false
DWindow.enableSystemMove: false

onVisibleChanged: {
updateWindowVisibilityAndPosition()
}
}

Loader {
id: frameLoader
anchors.fill: parent
focus: true
source: LauncherController.currentFrame + ".qml"
onSourceChanged: {
updateWindowVisibilityAndPosition();
onActiveChanged: {
if (!active && !DebugHelper.avoidHideWindow && (LauncherController.currentFrame === "WindowedFrame")) {
LauncherController.hideWithTimer()
}
}

Label {
visible: DebugHelper.qtDebugEnabled
z: 999
Loader {
anchors.fill: parent
focus: true
source: "WindowedFrame.qml"

Label {
visible: DebugHelper.qtDebugEnabled
z: 999

anchors.right: parent.right
anchors.bottom: parent.bottom
text: "/ / Under Construction / /"

anchors.right: parent.right
anchors.bottom: parent.bottom
text: "/ / Under Construction / /"
background: Rectangle {
color: Qt.rgba(1, 1, 0, 0.5)
}

background: Rectangle {
color: Qt.rgba(1, 1, 0, 0.5)
MouseArea {
anchors.fill: parent
onClicked: { debugDialog.open() }
}
}
}
}

property var fullscreenFrame: ApplicationWindow {
visible: LauncherController.visible && (LauncherController.currentFrame !== "WindowedFrame")

width: Screen.width
height: Screen.height
// visibility: Window.FullScreen
flags: {
if (DebugHelper.useRegularWindow) return Qt.Window
return (Qt.FramelessWindowHint | Qt.Tool)
}

DWindow.enabled: !DebugHelper.useRegularWindow
DWindow.enableSystemResize: false
DWindow.enableSystemMove: false

Loader {
anchors.fill: parent
focus: true
source: "FullscreenFrame.qml"

MouseArea {
anchors.fill: parent
onClicked: { debugDialog.open() }
Label {
visible: DebugHelper.qtDebugEnabled
z: 999

anchors.right: parent.right
anchors.bottom: parent.bottom
text: "/ / Under Construction / /"

background: Rectangle {
color: Qt.rgba(1, 1, 0, 0.5)
}

MouseArea {
anchors.fill: parent
onClicked: { debugDialog.open() }
}
}
}
}

Dialog {
id: debugDialog
modal: true
property var desktopIntegrationConn: Connections {
target: DesktopIntegration
function onDockGeometryChanged() {
updateWindowVisibilityAndPosition()
}
}

standardButtons: Dialog.Close
property var debugDialog: DialogWindow {
id: debugDialog

x: (parent.width - width) / 2
y: (parent.height - height) / 2
width: 400
height: 400
function open() {
show()
}

Loader {
active: debugDialog.visible
Expand All @@ -204,7 +228,7 @@ ApplicationWindow {
}
}

DialogWindow {
property var uninstallDialog: DialogWindow {
id: confirmUninstallDlg

property string appId: ""
Expand Down

0 comments on commit dfd126f

Please sign in to comment.