implement popup notification

This commit is contained in:
Eon S. Jeon 2020-01-13 12:58:30 +09:00
parent 19c095f531
commit d3fd64fd88
7 changed files with 114 additions and 3 deletions

View File

@ -8,6 +8,7 @@ KWINPKG_DIR = pkg
KWIN_SCRIPT = $(KWINPKG_DIR)/contents/code/script.js
KWIN_META = $(KWINPKG_DIR)/metadata.desktop
KWIN_QML = $(KWINPKG_DIR)/contents/ui/main.qml
KWIN_POPQML = $(KWINPKG_DIR)/contents/ui/popup.qml
KWIN_CONFIG_XML = $(KWINPKG_DIR)/contents/config/main.xml
KWIN_CONFIG_UI = $(KWINPKG_DIR)/contents/ui/config.ui
@ -47,12 +48,12 @@ $(KWINPKG_FILE): $(KWINPKG_DIR)
@rm -f "$(KWINPKG_FILE)"
@7z a -tzip $(KWINPKG_FILE) ./$(KWINPKG_DIR)/*
$(KWINPKG_DIR): $(KWIN_SCRIPT) $(KWIN_META) $(KWIN_QML)
$(KWINPKG_DIR): $(KWIN_SCRIPT) $(KWIN_META) $(KWIN_QML) $(KWIN_POPQML)
$(KWINPKG_DIR): $(KWIN_CONFIG_XML) $(KWIN_CONFIG_UI)
@touch $@
$(KWIN_SCRIPT): $(NODE_SCRIPT)
@mkdir -vp `dirname $(KWIN_SCRIPT)`
@mkdir -vp `dirname $(KWIN_SCRIPT)`
cp -a $< $@
$(KWIN_META): res/metadata.desktop
@ -65,6 +66,10 @@ $(KWIN_QML): res/main.qml
@mkdir -vp `dirname $@`
@cp -v $< $@
$(KWIN_POPQML): res/popup.qml
@mkdir -vp `dirname $@`
@cp -v $< $@
$(KWIN_CONFIG_XML): res/config.xml
@mkdir -vp `dirname $@`
@cp -v $< $@

View File

@ -37,6 +37,16 @@ Item {
engine: 'executable'
}
Loader {
id: popupDialog
source: "popup.qml"
function show(text) {
var area = workspace.clientArea(KWin.FullScreenArea, workspace.activeScreen, workspace.currentDesktop);
this.item.show(text, area, 1000);
}
}
Component.onCompleted: {
console.log("KROHNKITE: starting the script");
(new K.KWinDriver()).main();

82
res/popup.qml Normal file
View File

@ -0,0 +1,82 @@
// Copyright (c) 2018 Eon S. Jeon <esjeon@hyunmu.am>
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
import QtQuick 2.0
import QtQuick.Controls 2.0
import org.kde.plasma.core 2.0 as PlasmaCore;
/*
* Component Documentation
* - PlasmaCore global `theme` object:
* https://techbase.kde.org/Development/Tutorials/Plasma2/QML2/API#Plasma_Themes
* - PlasmaCore.Dialog:
* https://techbase.kde.org/Development/Tutorials/Plasma2/QML2/API#Top_Level_windows
*/
PlasmaCore.Dialog {
id: popupDialog
type: PlasmaCore.Dialog.PopupMenu
flags: Qt.Popup | Qt.WindowStaysOnTopHint
location: PlasmaCore.Types.Floating
visible: false
mainItem: Item {
width: messageLabel.implicitWidth
height: messageLabel.implicitHeight
Label {
id: messageLabel
padding: 10
// TODO: customizable font & size ????
font.pointSize: Math.round(theme.defaultFont.pointSize * 2)
font.weight: Font.Bold
}
/* hides the popup window when triggered */
Timer {
id: hideTimer
repeat: false
onTriggered: {
popupDialog.visible = false;
}
}
}
Component.onCompleted: {
/* NOTE: IDK what this is, but this is necessary to keep the window working. */
KWin.registerWindow(this);
}
function show(text, area, duration) {
hideTimer.stop();
messageLabel.text = text;
this.x = (area.x + area.width / 2) - this.width / 2;
this.y = (area.y + area.height / 2) - this.height / 2;
this.visible = true;
hideTimer.interval = duration;
hideTimer.start();
}
}

View File

@ -117,6 +117,7 @@ interface IDriverContext {
currentWindow: Window | null;
setTimeout(func: () => void, timeout: number): void;
showNotification(text: string): void;
}
//#endregion

View File

@ -117,10 +117,14 @@ class KWinDriver implements IDriverContext {
this.engine.arrange(this);
}
//#region implement `setTimeout` of IDriverContext`
//#region implement methods of IDriverContext`
public setTimeout(func: () => void, timeout: number) {
KWinSetTimeout(() => this.enter(func), timeout);
}
public showNotification(text: string) {
popupDialog.show(text);
}
//#endregion
private bindShortcut() {

View File

@ -52,4 +52,8 @@ class EngineContext {
public moveWindow(window: Window, target: Window, after?: boolean) {
this.engine.windows.move(window, target, after);
}
public showNotification(text: string) {
this.drvctx.showNotification(text);
}
}

View File

@ -27,6 +27,11 @@ declare var activityInfo: Plasma.TaskManager.ActivityInfo;
declare var mousePoller: Plasma.PlasmaCore.DataSource;
declare var scriptRoot: object;
interface PopupDialog {
show(text: string): void;
}
declare var popupDialog: PopupDialog;
/* Common Javascript globals */
declare let console: any;
declare let setTimeout: any;