forked from Shinonome/dots-hyprland
cheatsheet: put in loader
This commit is contained in:
@@ -19,137 +19,151 @@ Scope { // Scope
|
|||||||
id: cheatsheetVariants
|
id: cheatsheetVariants
|
||||||
model: Quickshell.screens
|
model: Quickshell.screens
|
||||||
|
|
||||||
PanelWindow { // Window
|
Loader {
|
||||||
id: cheatsheetRoot
|
id: cheatsheetLoader
|
||||||
visible: false
|
active: false
|
||||||
focusable: true
|
|
||||||
|
|
||||||
property var modelData
|
property var modelData
|
||||||
|
|
||||||
|
sourceComponent: PanelWindow { // Window
|
||||||
|
id: cheatsheetRoot
|
||||||
|
visible: cheatsheetLoader.active
|
||||||
|
focusable: true
|
||||||
|
|
||||||
screen: modelData
|
anchors {
|
||||||
exclusiveZone: 0
|
top: true
|
||||||
implicitWidth: cheatsheetBackground.width + Appearance.sizes.elevationMargin * 2
|
bottom: true
|
||||||
implicitHeight: cheatsheetBackground.height + Appearance.sizes.elevationMargin * 2
|
left: true
|
||||||
WlrLayershell.namespace: "quickshell:cheatsheet"
|
right: true
|
||||||
// Hyprland 0.49: Focus is always exclusive and setting this breaks mouse focus grab
|
|
||||||
// WlrLayershell.keyboardFocus: WlrKeyboardFocus.Exclusive
|
|
||||||
color: "transparent"
|
|
||||||
|
|
||||||
mask: Region {
|
|
||||||
item: cheatsheetBackground
|
|
||||||
}
|
|
||||||
|
|
||||||
HyprlandFocusGrab { // Click outside to close
|
|
||||||
id: grab
|
|
||||||
windows: [ cheatsheetRoot ]
|
|
||||||
active: false
|
|
||||||
onCleared: () => {
|
|
||||||
if (!active) cheatsheetRoot.visible = false
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Connections {
|
function hide() {
|
||||||
target: cheatsheetRoot
|
cheatsheetLoader.active = false
|
||||||
function onVisibleChanged() {
|
|
||||||
delayedGrabTimer.start()
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Timer {
|
screen: modelData
|
||||||
id: delayedGrabTimer
|
exclusiveZone: 0
|
||||||
interval: ConfigOptions.hacks.arbitraryRaceConditionDelay
|
implicitWidth: cheatsheetBackground.width + Appearance.sizes.elevationMargin * 2
|
||||||
repeat: false
|
implicitHeight: cheatsheetBackground.height + Appearance.sizes.elevationMargin * 2
|
||||||
onTriggered: {
|
WlrLayershell.namespace: "quickshell:cheatsheet"
|
||||||
grab.active = cheatsheetRoot.visible
|
// Hyprland 0.49: Focus is always exclusive and setting this breaks mouse focus grab
|
||||||
|
// WlrLayershell.keyboardFocus: WlrKeyboardFocus.Exclusive
|
||||||
|
color: "transparent"
|
||||||
|
|
||||||
|
mask: Region {
|
||||||
|
item: cheatsheetBackground
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Background
|
HyprlandFocusGrab { // Click outside to close
|
||||||
Rectangle {
|
id: grab
|
||||||
id: cheatsheetBackground
|
windows: [ cheatsheetRoot ]
|
||||||
anchors.centerIn: parent
|
active: false
|
||||||
color: Appearance.colors.colLayer0
|
onCleared: () => {
|
||||||
radius: Appearance.rounding.windowRounding
|
if (!active) cheatsheetRoot.hide()
|
||||||
property real padding: 30
|
|
||||||
implicitWidth: cheatsheetColumnLayout.implicitWidth + padding * 2
|
|
||||||
implicitHeight: cheatsheetColumnLayout.implicitHeight + padding * 2
|
|
||||||
|
|
||||||
Keys.onPressed: (event) => { // Esc to close
|
|
||||||
if (event.key === Qt.Key_Escape) {
|
|
||||||
cheatsheetRoot.visible = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Button { // Close button
|
Connections {
|
||||||
id: closeButton
|
target: cheatsheetRoot
|
||||||
focus: cheatsheetRoot.visible
|
function onVisibleChanged() {
|
||||||
implicitWidth: 40
|
delayedGrabTimer.start()
|
||||||
implicitHeight: 40
|
}
|
||||||
anchors {
|
}
|
||||||
top: parent.top
|
|
||||||
right: parent.right
|
Timer {
|
||||||
topMargin: 20
|
id: delayedGrabTimer
|
||||||
rightMargin: 20
|
interval: ConfigOptions.hacks.arbitraryRaceConditionDelay
|
||||||
|
repeat: false
|
||||||
|
onTriggered: {
|
||||||
|
grab.active = cheatsheetRoot.visible
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Background
|
||||||
|
Rectangle {
|
||||||
|
id: cheatsheetBackground
|
||||||
|
anchors.centerIn: parent
|
||||||
|
color: Appearance.colors.colLayer0
|
||||||
|
radius: Appearance.rounding.windowRounding
|
||||||
|
property real padding: 30
|
||||||
|
implicitWidth: cheatsheetColumnLayout.implicitWidth + padding * 2
|
||||||
|
implicitHeight: cheatsheetColumnLayout.implicitHeight + padding * 2
|
||||||
|
|
||||||
|
Keys.onPressed: (event) => { // Esc to close
|
||||||
|
if (event.key === Qt.Key_Escape) {
|
||||||
|
cheatsheetRoot.hide()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PointingHandInteraction {}
|
Button { // Close button
|
||||||
onClicked: {
|
id: closeButton
|
||||||
cheatsheetRoot.visible = false
|
focus: cheatsheetRoot.visible
|
||||||
}
|
implicitWidth: 40
|
||||||
|
implicitHeight: 40
|
||||||
|
anchors {
|
||||||
|
top: parent.top
|
||||||
|
right: parent.right
|
||||||
|
topMargin: 20
|
||||||
|
rightMargin: 20
|
||||||
|
}
|
||||||
|
|
||||||
background: Item {}
|
PointingHandInteraction {}
|
||||||
contentItem: Rectangle {
|
onClicked: {
|
||||||
anchors.fill: parent
|
cheatsheetRoot.hide()
|
||||||
radius: Appearance.rounding.full
|
}
|
||||||
color: closeButton.pressed ? Appearance.colors.colLayer0Active :
|
|
||||||
closeButton.hovered ? Appearance.colors.colLayer0Hover :
|
background: Item {}
|
||||||
Appearance.transparentize(Appearance.colors.colLayer0, 1)
|
contentItem: Rectangle {
|
||||||
|
anchors.fill: parent
|
||||||
Behavior on color {
|
radius: Appearance.rounding.full
|
||||||
ColorAnimation {
|
color: closeButton.pressed ? Appearance.colors.colLayer0Active :
|
||||||
duration: Appearance.animation.elementMoveFast.duration
|
closeButton.hovered ? Appearance.colors.colLayer0Hover :
|
||||||
easing.type: Appearance.animation.elementMoveFast.type
|
Appearance.transparentize(Appearance.colors.colLayer0, 1)
|
||||||
easing.bezierCurve: Appearance.animation.elementMoveFast.bezierCurve
|
|
||||||
|
Behavior on color {
|
||||||
|
ColorAnimation {
|
||||||
|
duration: Appearance.animation.elementMoveFast.duration
|
||||||
|
easing.type: Appearance.animation.elementMoveFast.type
|
||||||
|
easing.bezierCurve: Appearance.animation.elementMoveFast.bezierCurve
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MaterialSymbol {
|
||||||
|
anchors.centerIn: parent
|
||||||
|
font.pixelSize: Appearance.font.pixelSize.title
|
||||||
|
text: "close"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MaterialSymbol {
|
ColumnLayout { // Real content
|
||||||
anchors.centerIn: parent
|
id: cheatsheetColumnLayout
|
||||||
|
anchors.centerIn: parent
|
||||||
|
spacing: 20
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
id: cheatsheetTitle
|
||||||
|
Layout.alignment: Qt.AlignHCenter
|
||||||
|
font.family: Appearance.font.family.title
|
||||||
font.pixelSize: Appearance.font.pixelSize.title
|
font.pixelSize: Appearance.font.pixelSize.title
|
||||||
text: "close"
|
text: qsTr("Cheat sheet")
|
||||||
}
|
}
|
||||||
|
CheatsheetKeybinds {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnLayout { // Real content
|
// Shadow
|
||||||
id: cheatsheetColumnLayout
|
DropShadow {
|
||||||
anchors.centerIn: parent
|
anchors.fill: cheatsheetBackground
|
||||||
spacing: 20
|
horizontalOffset: 0
|
||||||
|
verticalOffset: 2
|
||||||
StyledText {
|
radius: Appearance.sizes.elevationMargin
|
||||||
id: cheatsheetTitle
|
samples: Appearance.sizes.elevationMargin * 2 + 1 // Ideally should be 2 * radius + 1, see qt docs
|
||||||
Layout.alignment: Qt.AlignHCenter
|
color: Appearance.colors.colShadow
|
||||||
font.family: Appearance.font.family.title
|
source: cheatsheetBackground
|
||||||
font.pixelSize: Appearance.font.pixelSize.title
|
|
||||||
text: qsTr("Cheat sheet")
|
|
||||||
}
|
|
||||||
CheatsheetKeybinds {}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Shadow
|
|
||||||
DropShadow {
|
|
||||||
anchors.fill: cheatsheetBackground
|
|
||||||
horizontalOffset: 0
|
|
||||||
verticalOffset: 2
|
|
||||||
radius: Appearance.sizes.elevationMargin
|
|
||||||
samples: Appearance.sizes.elevationMargin * 2 + 1 // Ideally should be 2 * radius + 1, see qt docs
|
|
||||||
color: Appearance.colors.colShadow
|
|
||||||
source: cheatsheetBackground
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IpcHandler {
|
IpcHandler {
|
||||||
@@ -157,30 +171,22 @@ Scope { // Scope
|
|||||||
|
|
||||||
function toggle(): void {
|
function toggle(): void {
|
||||||
for (let i = 0; i < cheatsheetVariants.instances.length; i++) {
|
for (let i = 0; i < cheatsheetVariants.instances.length; i++) {
|
||||||
let panelWindow = cheatsheetVariants.instances[i];
|
const loader = cheatsheetVariants.instances[i];
|
||||||
if (panelWindow.modelData.name == Hyprland.focusedMonitor.name) {
|
loader.active = !loader.active;
|
||||||
panelWindow.visible = !panelWindow.visible;
|
|
||||||
if(panelWindow.visible) Notifications.timeoutAll();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function close(): void {
|
function close(): void {
|
||||||
for (let i = 0; i < cheatsheetVariants.instances.length; i++) {
|
for (let i = 0; i < cheatsheetVariants.instances.length; i++) {
|
||||||
let panelWindow = cheatsheetVariants.instances[i];
|
const loader = cheatsheetVariants.instances[i];
|
||||||
if (panelWindow.modelData.name == Hyprland.focusedMonitor.name) {
|
loader.active = false
|
||||||
panelWindow.visible = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function open(): void {
|
function open(): void {
|
||||||
for (let i = 0; i < cheatsheetVariants.instances.length; i++) {
|
for (let i = 0; i < cheatsheetVariants.instances.length; i++) {
|
||||||
let panelWindow = cheatsheetVariants.instances[i];
|
const loader = cheatsheetVariants.instances[i];
|
||||||
if (panelWindow.modelData.name == Hyprland.focusedMonitor.name) {
|
loader.active = true;
|
||||||
panelWindow.visible = true;
|
|
||||||
if(panelWindow.visible) Notifications.timeoutAll();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -191,11 +197,8 @@ Scope { // Scope
|
|||||||
|
|
||||||
onPressed: {
|
onPressed: {
|
||||||
for (let i = 0; i < cheatsheetVariants.instances.length; i++) {
|
for (let i = 0; i < cheatsheetVariants.instances.length; i++) {
|
||||||
let panelWindow = cheatsheetVariants.instances[i];
|
const loader = cheatsheetVariants.instances[i];
|
||||||
if (panelWindow.modelData.name == Hyprland.focusedMonitor.name) {
|
loader.active = !loader.active;
|
||||||
panelWindow.visible = !panelWindow.visible;
|
|
||||||
if(panelWindow.visible) Notifications.timeoutAll();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -206,11 +209,8 @@ Scope { // Scope
|
|||||||
|
|
||||||
onPressed: {
|
onPressed: {
|
||||||
for (let i = 0; i < cheatsheetVariants.instances.length; i++) {
|
for (let i = 0; i < cheatsheetVariants.instances.length; i++) {
|
||||||
let panelWindow = cheatsheetVariants.instances[i];
|
const loader = cheatsheetVariants.instances[i];
|
||||||
if (panelWindow.modelData.name == Hyprland.focusedMonitor.name) {
|
loader.active = true;
|
||||||
panelWindow.visible = true;
|
|
||||||
if(panelWindow.visible) Notifications.timeoutAll();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -221,10 +221,8 @@ Scope { // Scope
|
|||||||
|
|
||||||
onPressed: {
|
onPressed: {
|
||||||
for (let i = 0; i < cheatsheetVariants.instances.length; i++) {
|
for (let i = 0; i < cheatsheetVariants.instances.length; i++) {
|
||||||
let panelWindow = cheatsheetVariants.instances[i];
|
const loader = cheatsheetVariants.instances[i];
|
||||||
if (panelWindow.modelData.name == Hyprland.focusedMonitor.name) {
|
loader.active = false;
|
||||||
panelWindow.visible = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user