diff --git a/res/ui/TrayItem.qml b/res/ui/TrayItem.qml new file mode 100644 index 00000000..32cb8bdf --- /dev/null +++ b/res/ui/TrayItem.qml @@ -0,0 +1,27 @@ +// SPDX-FileCopyrightText: 2021 Mikhail Zolotukhin +// +// SPDX-License-Identifier: MIT + +import QtQuick 2.0 + +import Qt.labs.platform 1.1 as Labs + +Labs.SystemTrayIcon { + id: root + visible: true + icon.name: "bismuth" + tooltip: "Windows' Tiling" + + menu: Labs.Menu { + id: menu + visible: false // Prevent from showing on Script Loading + + property var onToggleTiling: () => {} + + Labs.MenuItem { + text: i18n("Toggle Tiling") + icon.name: "window" + onTriggered: () => menu.onToggleTiling() + } + } +} diff --git a/res/ui/main.qml b/res/ui/main.qml index afada270..47a4a65b 100644 --- a/res/ui/main.qml +++ b/res/ui/main.qml @@ -6,11 +6,16 @@ import QtQuick 2.0 import org.kde.kwin 2.0; import org.kde.taskmanager 0.1 as TaskManager + import "../code/index.mjs" as Bismuth Item { id: scriptRoot + TrayItem { + id: trayItem + } + TaskManager.ActivityInfo { id: activityInfo } @@ -29,6 +34,7 @@ Item { const qmlObjects = { scriptRoot: scriptRoot, + trayItem: trayItem, activityInfo: activityInfo, popupDialog: popupDialog }; diff --git a/src/controller/index.ts b/src/controller/index.ts index 37537852..95365d22 100644 --- a/src/controller/index.ts +++ b/src/controller/index.ts @@ -150,7 +150,7 @@ export class ControllerImpl implements Controller { private engine: Engine; private driver: Driver; public constructor( - qmlObjects: Bismuth.Qml.Main, + private qmlObjects: Bismuth.Qml.Main, kwinApi: KWin.Api, private config: Config, private log: Log @@ -166,6 +166,7 @@ export class ControllerImpl implements Controller { this.log.log("Let's get down to bismuth!"); this.driver.bindEvents(); + this.bindTrayActions(); this.bindShortcuts(); this.driver.manageWindows(); @@ -372,6 +373,16 @@ export class ControllerImpl implements Controller { this.engine.manage(win); } + private bindTrayActions(): void { + // NOTE: Since the qml interface is very agile, it's seems + // to be unreasonable to make the bindings universal. + // However, this may be changed it the future. + this.qmlObjects.trayItem.menu.onToggleTiling = (): void => { + const action = new Action.ToggleFloatingLayout(this.engine, this.log); + action.execute(); + }; + } + private bindShortcuts(): void { const allPossibleActions = [ new Action.FocusNextWindow(this.engine, this.log), diff --git a/src/extern/global.d.ts b/src/extern/global.d.ts index e9c32a8b..2d4ee724 100644 --- a/src/extern/global.d.ts +++ b/src/extern/global.d.ts @@ -9,10 +9,19 @@ declare namespace Bismuth { export namespace Qml { export interface Main { scriptRoot: object; + trayItem: TrayItem; activityInfo: Plasma.TaskManager.ActivityInfo; popupDialog: PopupDialog; } + export interface TrayItem { + menu: TrayMenu; + } + + export interface TrayMenu { + onToggleTiling: () => void; + } + export interface PopupDialog { show(text: string): void; }