Skip to content
This repository has been archived by the owner on Jun 16, 2024. It is now read-only.

Commit

Permalink
feat: introduce tray item, that lets you toggle floating mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Zolotukhin committed Nov 1, 2021
1 parent 8ebffbe commit ba689c5
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
27 changes: 27 additions & 0 deletions res/ui/TrayItem.qml
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
6 changes: 6 additions & 0 deletions res/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -29,6 +34,7 @@ Item {

const qmlObjects = {
scriptRoot: scriptRoot,
trayItem: trayItem,
activityInfo: activityInfo,
popupDialog: popupDialog
};
Expand Down
13 changes: 12 additions & 1 deletion src/controller/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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),
Expand Down
9 changes: 9 additions & 0 deletions src/extern/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit ba689c5

Please sign in to comment.