feat: introduce tray item, that lets you toggle floating mode

This commit is contained in:
Mikhail Zolotukhin 2021-11-01 13:52:10 +03:00
parent 8ebffbe639
commit ba689c5ff0
4 changed files with 54 additions and 1 deletions

27
res/ui/TrayItem.qml Normal file
View File

@ -0,0 +1,27 @@
// SPDX-FileCopyrightText: 2021 Mikhail Zolotukhin <mail@genda.life>
//
// 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()
}
}
}

View File

@ -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
};

View File

@ -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),

View File

@ -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;
}