933 lines
36 KiB
QML
933 lines
36 KiB
QML
import QtQuick
|
|
import Quickshell
|
|
import Quickshell.Wayland
|
|
|
|
PanelWindow {
|
|
id: root
|
|
|
|
required property bool shellOpen
|
|
required property Compositor compositor
|
|
required property Theme theme
|
|
required property Config config
|
|
// Open the search bar as soon as the carousel has its data.
|
|
required property bool searchOnOpen
|
|
// Open the window loop on the focused workspace as soon as the carousel
|
|
// has its data. Escape then closes everything.
|
|
required property bool openWindowsOnOpen
|
|
|
|
// Enter, or a click on a card: the workspace was chosen.
|
|
signal requestClose
|
|
// Escape, or a click on the backdrop: leave without switching.
|
|
signal requestBack
|
|
|
|
visible: root.shellOpen
|
|
color: "transparent"
|
|
|
|
exclusionMode: ExclusionMode.Ignore
|
|
WlrLayershell.namespace: "quickshell:workspace-manager-goto"
|
|
WlrLayershell.layer: WlrLayer.Overlay
|
|
WlrLayershell.keyboardFocus: root.visible ? WlrKeyboardFocus.Exclusive : WlrKeyboardFocus.None
|
|
|
|
anchors {
|
|
top: true
|
|
left: true
|
|
right: true
|
|
bottom: true
|
|
}
|
|
|
|
property int monitorIndex: 0
|
|
// One selected workspace index per monitor. Reassigned as a whole so
|
|
// the carousel notices the change. Parallel to compositor.monitors.
|
|
property var workspaceIndices: []
|
|
property bool seedPending: false
|
|
property bool animate: false
|
|
|
|
// The search bar is open and taking typed text.
|
|
property bool searchActive: false
|
|
// Last accepted search, used by n and N.
|
|
property string searchQuery: ""
|
|
// Matches for the text in the search bar, and which one is shown.
|
|
// matchIndex is -1 when none is shown.
|
|
property int matchCount: 0
|
|
property int matchIndex: -1
|
|
// Where the view was when the search bar opened. Escape goes back here.
|
|
property int originMonitor: 0
|
|
property list<int> originIndices: []
|
|
// -1 when the window loop was closed.
|
|
property int originWindowIndex: -1
|
|
property bool originCanCollapse: true
|
|
|
|
// The window loop is open on top of the selected workspace.
|
|
property bool windowsOpen: false
|
|
// Workspace the window loop shows.
|
|
property int loopWorkspaceId: -1
|
|
// Escape folds the loop back into the carousel, instead of closing.
|
|
property bool canCollapse: true
|
|
// Half the shown height of a workspace right above or below the loop,
|
|
// after its shrink and its tilt.
|
|
readonly property real neighbourHalfHeight: {
|
|
const shrink = 1 - Math.min(root.theme.carouselScaleStep, root.theme.carouselMaxScaleReduction);
|
|
return root.theme.cardHeight / 2 * shrink * Math.cos(root.theme.loopTiltX * Math.PI / 180);
|
|
}
|
|
|
|
function workspaceIndexAt(index: int): int {
|
|
const list = root.workspaceIndices;
|
|
if (!list || index < 0 || index >= list.length)
|
|
return 0;
|
|
const value = list[index];
|
|
if (value === undefined || value === null)
|
|
return 0;
|
|
return value;
|
|
}
|
|
|
|
function seedSelection(): void {
|
|
const mons = root.compositor.monitors ?? [];
|
|
const indices = [];
|
|
let focusedMonitor = 0;
|
|
for (let i = 0; i < mons.length; i++) {
|
|
const workspaces = mons[i].workspaces ?? [];
|
|
let activeIndex = 0;
|
|
let focusedIndex = -1;
|
|
for (let j = 0; j < workspaces.length; j++) {
|
|
if (workspaces[j].active)
|
|
activeIndex = j;
|
|
if (workspaces[j].focused) {
|
|
focusedIndex = j;
|
|
focusedMonitor = i;
|
|
}
|
|
}
|
|
indices.push(focusedIndex >= 0 ? focusedIndex : activeIndex);
|
|
}
|
|
root.monitorIndex = mons.length === 0 ? 0 : focusedMonitor;
|
|
root.workspaceIndices = indices;
|
|
}
|
|
|
|
function moveWorkspace(delta: int): void {
|
|
root.animate = true;
|
|
const mons = root.compositor.monitors ?? [];
|
|
if (root.monitorIndex < 0 || root.monitorIndex >= mons.length)
|
|
return;
|
|
const count = (mons[root.monitorIndex].workspaces ?? []).length;
|
|
if (count === 0)
|
|
return;
|
|
const current = root.workspaceIndexAt(root.monitorIndex);
|
|
const next = (current + delta + count) % count;
|
|
const copy = root.workspaceIndices.slice();
|
|
while (copy.length <= root.monitorIndex)
|
|
copy.push(0);
|
|
copy[root.monitorIndex] = next;
|
|
root.workspaceIndices = copy;
|
|
}
|
|
|
|
function moveMonitor(delta: int): void {
|
|
root.animate = true;
|
|
const count = (root.compositor.monitors ?? []).length;
|
|
if (count === 0)
|
|
return;
|
|
const next = root.monitorIndex + delta;
|
|
if (next < 0 || next >= count)
|
|
return;
|
|
root.monitorIndex = next;
|
|
}
|
|
|
|
function activateAt(monitorAt: int, workspaceAt: int): void {
|
|
const mons = root.compositor.monitors ?? [];
|
|
if (monitorAt < 0 || monitorAt >= mons.length) {
|
|
root.requestClose();
|
|
return;
|
|
}
|
|
const workspaces = mons[monitorAt].workspaces ?? [];
|
|
if (workspaceAt < 0 || workspaceAt >= workspaces.length) {
|
|
root.requestClose();
|
|
return;
|
|
}
|
|
const ws = workspaces[workspaceAt];
|
|
root.compositor.focusWorkspace(root.compositor.asString(mons[monitorAt].name), ws.idx, ws.id);
|
|
root.requestClose();
|
|
}
|
|
|
|
function activateSelection(): void {
|
|
root.activateAt(root.monitorIndex, root.workspaceIndexAt(root.monitorIndex));
|
|
}
|
|
|
|
// A workspace from parsed JSON, so this stays untyped.
|
|
function selectedWorkspace(): var {
|
|
const mons = root.compositor.monitors ?? [];
|
|
if (root.monitorIndex < 0 || root.monitorIndex >= mons.length)
|
|
return null;
|
|
const wsList = mons[root.monitorIndex].workspaces ?? [];
|
|
const idx = root.workspaceIndexAt(root.monitorIndex);
|
|
if (idx < 0 || idx >= wsList.length)
|
|
return null;
|
|
return wsList[idx];
|
|
}
|
|
|
|
|
|
// ── window loop helpers ─────────────────────────────────────────────
|
|
|
|
function isWindowsKey(event): bool {
|
|
return root.config.matches(event, root.config.windowsKey);
|
|
}
|
|
|
|
// Open the loop on the selected workspace. The other cards move away.
|
|
function expandWindows(collapsible: bool): void {
|
|
const ws = root.selectedWorkspace();
|
|
if (!ws)
|
|
return;
|
|
root.animate = true;
|
|
root.canCollapse = collapsible;
|
|
root.loopWorkspaceId = ws.id;
|
|
root.windowsOpen = true;
|
|
windowLoop.seed();
|
|
}
|
|
|
|
// Up/Down while the loop is open: move to the next workspace on this
|
|
// monitor and show its windows.
|
|
function switchWindows(delta: int): void {
|
|
const before = root.selectedWorkspace();
|
|
root.moveWorkspace(delta);
|
|
const ws = root.selectedWorkspace();
|
|
if (!ws || ws === before)
|
|
return;
|
|
windowLoop.holdLeaving();
|
|
root.loopWorkspaceId = ws.id;
|
|
windowLoop.switchIn(delta);
|
|
}
|
|
|
|
function collapseWindows(): void {
|
|
root.animate = true;
|
|
root.windowsOpen = false;
|
|
}
|
|
|
|
// Escape or a backdrop click while the loop is open.
|
|
function leaveWindows(): void {
|
|
if (root.canCollapse)
|
|
root.collapseWindows();
|
|
else
|
|
root.requestBack();
|
|
}
|
|
|
|
// ── search ──────────────────────────────────────────────────────────
|
|
|
|
function noCtrlOrAlt(event): bool {
|
|
return !(event.modifiers & (Qt.ControlModifier | Qt.AltModifier | Qt.MetaModifier));
|
|
}
|
|
|
|
function isSearchKey(event): bool {
|
|
return event.text === "/" && root.noCtrlOrAlt(event);
|
|
}
|
|
|
|
// n goes forward (1), N goes back (-1), anything else is 0.
|
|
function nextMatchDirection(event): int {
|
|
if (event.key !== Qt.Key_N || !root.noCtrlOrAlt(event))
|
|
return 0;
|
|
return (event.modifiers & Qt.ShiftModifier) ? -1 : 1;
|
|
}
|
|
|
|
// Selected window in the loop, or -1 when the loop is closed.
|
|
function currentWindowIndex(): int {
|
|
return root.windowsOpen ? windowLoop.selectedIndex : -1;
|
|
}
|
|
|
|
// Order: monitor, then workspace, then window. A closed loop (-1)
|
|
// comes before every window of its workspace.
|
|
function comparePositions(monitorA: int, workspaceA: int, windowA: int, monitorB: int, workspaceB: int, windowB: int): int {
|
|
if (monitorA !== monitorB)
|
|
return monitorA - monitorB;
|
|
if (workspaceA !== workspaceB)
|
|
return workspaceA - workspaceB;
|
|
return windowA - windowB;
|
|
}
|
|
|
|
// Like vim's smartcase: any capital letter makes the search match case.
|
|
// The window is parsed JSON, so it stays untyped.
|
|
function windowMatches(w, query: string): bool {
|
|
const exact = query !== query.toLowerCase();
|
|
const fold = text => exact ? text : text.toLowerCase();
|
|
const wanted = fold(query);
|
|
return fold(w.title ?? "").includes(wanted) || fold(w.app ?? "").includes(wanted);
|
|
}
|
|
|
|
// Every window whose title or app matches, in carousel order, as
|
|
// { monitor, workspace, window } list positions.
|
|
function findMatches(query: string): var {
|
|
const found = [];
|
|
if (query.length === 0)
|
|
return found;
|
|
const mons = root.compositor.monitors ?? [];
|
|
for (let i = 0; i < mons.length; i++) {
|
|
const wsList = mons[i].workspaces ?? [];
|
|
for (let j = 0; j < wsList.length; j++) {
|
|
const wins = wsList[j].windows ?? [];
|
|
for (let k = 0; k < wins.length; k++) {
|
|
if (root.windowMatches(wins[k], query))
|
|
found.push({
|
|
monitor: i,
|
|
workspace: j,
|
|
window: k
|
|
});
|
|
}
|
|
}
|
|
}
|
|
return found;
|
|
}
|
|
|
|
// The first match after the given place (direction 1) or the last one
|
|
// before it (direction -1), wrapping round. -1 when there is none.
|
|
function pickMatch(matches, monitorAt: int, workspaceAt: int, windowAt: int, direction: int): int {
|
|
if (matches.length === 0)
|
|
return -1;
|
|
if (direction > 0) {
|
|
for (let i = 0; i < matches.length; i++) {
|
|
const m = matches[i];
|
|
if (root.comparePositions(m.monitor, m.workspace, m.window, monitorAt, workspaceAt, windowAt) > 0)
|
|
return i;
|
|
}
|
|
return 0;
|
|
}
|
|
for (let i = matches.length - 1; i >= 0; i--) {
|
|
const m = matches[i];
|
|
if (root.comparePositions(m.monitor, m.workspace, m.window, monitorAt, workspaceAt, windowAt) < 0)
|
|
return i;
|
|
}
|
|
return matches.length - 1;
|
|
}
|
|
|
|
// Move the view to a workspace, and to one of its windows unless
|
|
// windowAt is -1, which closes the loop.
|
|
function showPosition(monitorAt: int, workspaceAt: int, windowAt: int): void {
|
|
const mons = root.compositor.monitors ?? [];
|
|
if (monitorAt < 0 || monitorAt >= mons.length)
|
|
return;
|
|
const wsList = mons[monitorAt].workspaces ?? [];
|
|
if (workspaceAt < 0 || workspaceAt >= wsList.length)
|
|
return;
|
|
const ws = wsList[workspaceAt];
|
|
const forward = root.comparePositions(monitorAt, workspaceAt, windowAt, root.monitorIndex, root.workspaceIndexAt(root.monitorIndex), root.currentWindowIndex()) >= 0;
|
|
|
|
root.animate = true;
|
|
root.monitorIndex = monitorAt;
|
|
const copy = root.workspaceIndices.slice();
|
|
while (copy.length <= monitorAt)
|
|
copy.push(0);
|
|
copy[monitorAt] = workspaceAt;
|
|
root.workspaceIndices = copy;
|
|
|
|
if (windowAt < 0) {
|
|
if (root.windowsOpen)
|
|
root.collapseWindows();
|
|
return;
|
|
}
|
|
if (!root.windowsOpen) {
|
|
root.expandWindows(true);
|
|
} else if (root.loopWorkspaceId !== ws.id) {
|
|
windowLoop.holdLeaving();
|
|
root.loopWorkspaceId = ws.id;
|
|
windowLoop.switchIn(forward ? 1 : -1);
|
|
}
|
|
windowLoop.selectIndex(windowAt);
|
|
}
|
|
|
|
function restoreOrigin(): void {
|
|
const indices = Array.from(root.originIndices);
|
|
const workspaceAt = root.originMonitor < indices.length ? indices[root.originMonitor] : 0;
|
|
root.showPosition(root.originMonitor, workspaceAt, root.originWindowIndex);
|
|
root.workspaceIndices = indices;
|
|
root.canCollapse = root.originCanCollapse;
|
|
}
|
|
|
|
function enterSearch(): void {
|
|
root.originMonitor = root.monitorIndex;
|
|
root.originIndices = root.workspaceIndices.slice();
|
|
root.originWindowIndex = root.currentWindowIndex();
|
|
root.originCanCollapse = root.canCollapse;
|
|
root.matchCount = 0;
|
|
root.matchIndex = -1;
|
|
// Clear before turning on, so the cleared text does not search.
|
|
searchInput.text = "";
|
|
root.searchActive = true;
|
|
searchInput.forceActiveFocus();
|
|
}
|
|
|
|
function leaveSearch(): void {
|
|
root.searchActive = false;
|
|
searchInput.focus = false;
|
|
Qt.callLater(() => focusScope.forceActiveFocus());
|
|
}
|
|
|
|
// Called as the search text changes. Jumps to the first match after
|
|
// where the search started, or back there when nothing matches.
|
|
function updateSearch(query: string): void {
|
|
const matches = root.findMatches(query);
|
|
root.matchCount = matches.length;
|
|
const indices = Array.from(root.originIndices);
|
|
const workspaceAt = root.originMonitor < indices.length ? indices[root.originMonitor] : 0;
|
|
const index = root.pickMatch(matches, root.originMonitor, workspaceAt, root.originWindowIndex, 1);
|
|
root.matchIndex = index;
|
|
if (index < 0) {
|
|
root.restoreOrigin();
|
|
return;
|
|
}
|
|
const m = matches[index];
|
|
root.showPosition(m.monitor, m.workspace, m.window);
|
|
}
|
|
|
|
// Enter: keep the shown match and remember the text for n and N.
|
|
function acceptSearch(): void {
|
|
if (searchInput.text.length > 0)
|
|
root.searchQuery = searchInput.text;
|
|
root.leaveSearch();
|
|
}
|
|
|
|
// Escape: go back to where the search started.
|
|
function cancelSearch(): void {
|
|
root.restoreOrigin();
|
|
root.leaveSearch();
|
|
}
|
|
|
|
function jumpToMatch(direction: int): void {
|
|
const matches = root.findMatches(root.searchQuery);
|
|
const index = root.pickMatch(matches, root.monitorIndex, root.workspaceIndexAt(root.monitorIndex), root.currentWindowIndex(), direction);
|
|
root.matchCount = matches.length;
|
|
root.matchIndex = index;
|
|
if (index < 0)
|
|
return;
|
|
const m = matches[index];
|
|
root.showPosition(m.monitor, m.workspace, m.window);
|
|
}
|
|
|
|
// ── visibility handling ─────────────────────────────────────────────
|
|
|
|
onVisibleChanged: {
|
|
root.animate = false;
|
|
root.searchActive = false;
|
|
searchInput.focus = false;
|
|
root.windowsOpen = false;
|
|
if (!root.visible) {
|
|
root.seedPending = false;
|
|
return;
|
|
}
|
|
root.seedPending = true;
|
|
root.compositor.refresh();
|
|
Qt.callLater(() => focusScope.forceActiveFocus());
|
|
}
|
|
|
|
Connections {
|
|
target: root.compositor
|
|
|
|
function onRefreshed(): void {
|
|
if (!root.visible || !root.seedPending)
|
|
return;
|
|
if (root.compositor.refreshQueued)
|
|
return;
|
|
root.seedPending = false;
|
|
root.seedSelection();
|
|
if (root.openWindowsOnOpen)
|
|
root.expandWindows(false);
|
|
if (root.searchOnOpen)
|
|
root.enterSearch();
|
|
}
|
|
}
|
|
|
|
// ── backdrop ────────────────────────────────────────────────────────
|
|
|
|
Rectangle {
|
|
id: backdrop
|
|
anchors.fill: parent
|
|
color: root.theme.backdrop
|
|
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
onClicked: {
|
|
if (root.searchActive)
|
|
root.cancelSearch();
|
|
else if (root.windowsOpen)
|
|
root.leaveWindows();
|
|
else
|
|
root.requestBack();
|
|
}
|
|
}
|
|
}
|
|
|
|
// ── search bar (shown while searching) ──────────────────────────────
|
|
|
|
Item {
|
|
id: searchBar
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
anchors.top: parent.top
|
|
anchors.topMargin: root.theme.searchBarTop
|
|
width: root.theme.barWidth
|
|
height: root.theme.barHeight
|
|
z: 10
|
|
opacity: root.searchActive ? 1 : 0
|
|
// Shown at once when opened, so the field can take focus.
|
|
visible: root.searchActive || searchBar.opacity > 0
|
|
|
|
Behavior on opacity {
|
|
NumberAnimation {
|
|
duration: root.theme.hintFadeDuration
|
|
}
|
|
}
|
|
|
|
Glass {
|
|
anchors.fill: parent
|
|
theme: root.theme
|
|
radius: root.theme.cornerRadius
|
|
tint: root.theme.barBg
|
|
selected: false
|
|
shadow: true
|
|
}
|
|
|
|
Item {
|
|
anchors.fill: parent
|
|
|
|
Row {
|
|
anchors.fill: parent
|
|
anchors.margins: root.theme.barPadding
|
|
spacing: root.theme.barSpacing
|
|
|
|
Image {
|
|
width: root.theme.logoSize
|
|
height: root.theme.logoSize
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
source: root.compositor.logoSource
|
|
visible: root.compositor.logoSource !== ""
|
|
sourceSize.width: root.theme.logoSize * 2
|
|
sourceSize.height: root.theme.logoSize * 2
|
|
fillMode: Image.PreserveAspectFit
|
|
smooth: true
|
|
mipmap: true
|
|
}
|
|
|
|
Text {
|
|
id: prompt
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
text: "/"
|
|
color: root.theme.labelColor
|
|
font.pixelSize: root.theme.fontSize
|
|
font.bold: true
|
|
}
|
|
|
|
Item {
|
|
id: field
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
width: parent.width - prompt.width - matchText.width - root.theme.logoSize - root.theme.barSpacing * 3
|
|
height: root.theme.barHeight - root.theme.barPadding * 2
|
|
|
|
Glass {
|
|
anchors.fill: parent
|
|
theme: root.theme
|
|
radius: root.theme.cornerRadius / 2
|
|
tint: root.theme.fieldBg
|
|
selected: searchInput.activeFocus
|
|
shadow: false
|
|
}
|
|
|
|
TextInput {
|
|
id: searchInput
|
|
anchors.fill: parent
|
|
anchors.leftMargin: root.theme.fieldPadding
|
|
anchors.rightMargin: root.theme.fieldPadding
|
|
verticalAlignment: TextInput.AlignVCenter
|
|
color: root.theme.textColor
|
|
font.pixelSize: root.theme.fontSize
|
|
selectByMouse: true
|
|
selectionColor: root.theme.fieldBorder
|
|
selectedTextColor: root.theme.buttonText
|
|
clip: true
|
|
focus: false
|
|
|
|
onTextChanged: {
|
|
if (root.searchActive)
|
|
root.updateSearch(searchInput.text);
|
|
}
|
|
onAccepted: root.acceptSearch()
|
|
|
|
Keys.onEscapePressed: event => {
|
|
root.cancelSearch();
|
|
event.accepted = true;
|
|
}
|
|
// Backspace on an empty search closes it, like in vim.
|
|
Keys.onPressed: event => {
|
|
if (event.key === Qt.Key_Backspace && searchInput.text.length === 0) {
|
|
root.cancelSearch();
|
|
event.accepted = true;
|
|
return;
|
|
}
|
|
event.accepted = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
// "2/5" while there are matches, "no match" when none.
|
|
Text {
|
|
id: matchText
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
color: root.matchCount > 0 ? root.theme.labelColor : root.theme.fieldBorder
|
|
font.pixelSize: root.theme.fontSize
|
|
text: {
|
|
if (searchInput.text.length === 0)
|
|
return "";
|
|
if (root.matchCount === 0)
|
|
return "no match";
|
|
return (root.matchIndex + 1) + "/" + root.matchCount;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Where the search bar opens, while it is closed.
|
|
KeyHint {
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
anchors.top: parent.top
|
|
anchors.topMargin: root.theme.searchBarTop
|
|
z: 10
|
|
theme: root.theme
|
|
hint: root.config.searchHint
|
|
shown: root.config.showHints && !root.searchActive
|
|
}
|
|
|
|
// ── carousel ────────────────────────────────────────────────────────
|
|
|
|
FocusScope {
|
|
id: focusScope
|
|
anchors.fill: parent
|
|
focus: root.visible
|
|
|
|
Keys.onPressed: event => {
|
|
// / opens the search bar, n and N go to the next or previous match.
|
|
if (root.isSearchKey(event)) {
|
|
root.enterSearch();
|
|
event.accepted = true;
|
|
return;
|
|
}
|
|
const direction = root.nextMatchDirection(event);
|
|
if (direction !== 0) {
|
|
root.jumpToMatch(direction);
|
|
event.accepted = true;
|
|
return;
|
|
}
|
|
|
|
// The windows key opens or folds the window loop on the selected workspace.
|
|
if (root.isWindowsKey(event)) {
|
|
if (root.windowsOpen)
|
|
root.collapseWindows();
|
|
else
|
|
root.expandWindows(true);
|
|
event.accepted = true;
|
|
return;
|
|
}
|
|
|
|
if (root.windowsOpen) {
|
|
switch (event.key) {
|
|
case Qt.Key_Left:
|
|
case Qt.Key_Backtab:
|
|
windowLoop.step(-1);
|
|
break;
|
|
case Qt.Key_Right:
|
|
case Qt.Key_Tab:
|
|
windowLoop.step(1);
|
|
break;
|
|
case Qt.Key_Return:
|
|
case Qt.Key_Enter:
|
|
windowLoop.activateSelected();
|
|
break;
|
|
case Qt.Key_Escape:
|
|
root.leaveWindows();
|
|
break;
|
|
case Qt.Key_Up:
|
|
root.switchWindows(-1);
|
|
break;
|
|
case Qt.Key_Down:
|
|
root.switchWindows(1);
|
|
break;
|
|
default:
|
|
return;
|
|
}
|
|
event.accepted = true;
|
|
return;
|
|
}
|
|
|
|
switch (event.key) {
|
|
case Qt.Key_Up:
|
|
root.moveWorkspace(-1);
|
|
break;
|
|
case Qt.Key_Down:
|
|
root.moveWorkspace(1);
|
|
break;
|
|
case Qt.Key_Left:
|
|
root.moveMonitor(-1);
|
|
break;
|
|
case Qt.Key_Right:
|
|
root.moveMonitor(1);
|
|
break;
|
|
case Qt.Key_Return:
|
|
case Qt.Key_Enter:
|
|
root.activateSelection();
|
|
break;
|
|
case Qt.Key_Escape:
|
|
root.requestBack();
|
|
break;
|
|
default:
|
|
return;
|
|
}
|
|
event.accepted = true;
|
|
}
|
|
|
|
WheelHandler {
|
|
id: swipeHandler
|
|
target: focusScope
|
|
property real accX: 0
|
|
property real accY: 0
|
|
|
|
// Vertical swipes move between workspaces, both in the carousel
|
|
// and in the loop. Horizontal ones move between monitors, or
|
|
// turn the loop while it is open.
|
|
function stepVertical(delta: int): void {
|
|
if (root.windowsOpen)
|
|
root.switchWindows(delta);
|
|
else
|
|
root.moveWorkspace(delta);
|
|
swipeHandler.accY = 0;
|
|
}
|
|
|
|
function stepHorizontal(delta: int): void {
|
|
if (root.windowsOpen)
|
|
windowLoop.step(delta);
|
|
else
|
|
root.moveMonitor(delta);
|
|
swipeHandler.accX = 0;
|
|
}
|
|
|
|
onWheel: event => {
|
|
const px = event.pixelDelta;
|
|
const ang = event.angleDelta;
|
|
const dx = px.x !== 0 ? px.x : ang.x;
|
|
const dy = px.y !== 0 ? px.y : ang.y;
|
|
if (Math.abs(dy) >= Math.abs(dx)) {
|
|
swipeHandler.accY += dy;
|
|
if (swipeHandler.accY <= -root.theme.swipeThreshold)
|
|
swipeHandler.stepVertical(1);
|
|
else if (swipeHandler.accY >= root.theme.swipeThreshold)
|
|
swipeHandler.stepVertical(-1);
|
|
} else {
|
|
swipeHandler.accX += dx;
|
|
if (swipeHandler.accX <= -root.theme.swipeThreshold)
|
|
swipeHandler.stepHorizontal(1);
|
|
else if (swipeHandler.accX >= root.theme.swipeThreshold)
|
|
swipeHandler.stepHorizontal(-1);
|
|
}
|
|
}
|
|
}
|
|
|
|
Repeater {
|
|
model: root.compositor.monitors
|
|
|
|
// One column per monitor, with its workspaces top to bottom.
|
|
Item {
|
|
id: column
|
|
|
|
required property var modelData
|
|
required property int index
|
|
|
|
readonly property int columnIndex: index
|
|
readonly property int selectedWs: root.workspaceIndexAt(columnIndex)
|
|
readonly property var workspaces: modelData.workspaces ?? []
|
|
readonly property bool isCurrentColumn: column.columnIndex === root.monitorIndex
|
|
// Other columns turn to face the middle while the loop is open.
|
|
readonly property real tiltY: root.windowsOpen && !column.isCurrentColumn ? -Math.sign(column.columnIndex - root.monitorIndex) * root.theme.loopTiltY : 0
|
|
|
|
anchors.top: parent.top
|
|
anchors.bottom: parent.bottom
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
width: root.theme.cardWidth
|
|
// While the loop is open, the current column draws over it,
|
|
// so the workspace above stays visible over the back windows.
|
|
z: column.isCurrentColumn ? (root.windowsOpen ? 3 : 1) : 0
|
|
opacity: {
|
|
const fade = 1 - Math.min(Math.abs(column.columnIndex - root.monitorIndex) * root.theme.carouselMonitorFadeStep, root.theme.carouselMonitorMaxFade);
|
|
return root.windowsOpen && !column.isCurrentColumn ? fade * root.theme.loopHiddenFade : fade;
|
|
}
|
|
// While the loop is open, the nearest column on each side sits
|
|
// just past the loop's edge. Further columns keep the normal step.
|
|
anchors.horizontalCenterOffset: {
|
|
const steps = column.columnIndex - root.monitorIndex;
|
|
if (!root.windowsOpen || steps === 0)
|
|
return steps * root.theme.carouselStepX;
|
|
const nearest = windowLoop.reachX + root.theme.cardWidth / 2 + root.theme.loopEdgeGap;
|
|
return Math.sign(steps) * (nearest + (Math.abs(steps) - 1) * root.theme.carouselStepX);
|
|
}
|
|
|
|
Behavior on anchors.horizontalCenterOffset {
|
|
enabled: root.animate
|
|
NumberAnimation {
|
|
duration: root.theme.carouselDuration
|
|
easing.type: Easing.OutCubic
|
|
}
|
|
}
|
|
Behavior on opacity {
|
|
enabled: root.animate
|
|
NumberAnimation {
|
|
duration: root.theme.carouselDuration
|
|
}
|
|
}
|
|
|
|
transform: Rotation {
|
|
origin.x: column.width / 2
|
|
origin.y: column.height / 2
|
|
axis {
|
|
x: 0
|
|
y: 1
|
|
z: 0
|
|
}
|
|
angle: column.tiltY
|
|
|
|
Behavior on angle {
|
|
enabled: root.animate
|
|
NumberAnimation {
|
|
duration: root.theme.carouselDuration
|
|
easing.type: Easing.OutCubic
|
|
}
|
|
}
|
|
}
|
|
|
|
// Monitor name, above the search bar.
|
|
Item {
|
|
id: monitorName
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
anchors.top: parent.top
|
|
anchors.topMargin: root.theme.monitorLabelTop
|
|
z: 2
|
|
width: Math.min(nameText.implicitWidth + root.theme.monitorNamePadding * 10, column.width)
|
|
height: nameText.implicitHeight + root.theme.monitorNamePadding
|
|
|
|
Glass {
|
|
anchors.fill: parent
|
|
theme: root.theme
|
|
radius: monitorName.height / 4
|
|
tint: root.theme.barBg
|
|
selected: column.isCurrentColumn
|
|
shadow: true
|
|
}
|
|
|
|
Text {
|
|
id: nameText
|
|
anchors.centerIn: parent
|
|
width: parent.width - root.theme.monitorNamePadding * 2
|
|
horizontalAlignment: Text.AlignHCenter
|
|
elide: Text.ElideMiddle
|
|
color: column.isCurrentColumn ? root.theme.textColor : root.theme.labelColor
|
|
font.pixelSize: root.theme.monitorNameSize
|
|
font.bold: true
|
|
text: column.modelData.name.length > 0 ? column.modelData.name : "screen"
|
|
}
|
|
}
|
|
|
|
Repeater {
|
|
model: column.workspaces
|
|
|
|
WorkspaceCard {
|
|
id: card
|
|
|
|
required property var modelData
|
|
required property int index
|
|
|
|
readonly property int distance: Math.abs(index - column.selectedWs)
|
|
// This card turns into the window loop.
|
|
readonly property bool opensLoop: root.windowsOpen && card.selected
|
|
// Cards above and below the loop move so the nearest
|
|
// ones sit a small gap from the front window. Cards
|
|
// further out keep the normal step from those.
|
|
readonly property real spreadY: {
|
|
const steps = index - column.selectedWs;
|
|
if (!root.windowsOpen || !column.isCurrentColumn || steps === 0)
|
|
return 0;
|
|
const nearest = steps < 0 ? windowLoop.frontTop - root.theme.loopWorkspaceGapAbove - root.neighbourHalfHeight : windowLoop.frontBottom + root.theme.loopWorkspaceGapBelow + root.neighbourHalfHeight;
|
|
return nearest - Math.sign(steps) * root.theme.carouselStepY;
|
|
}
|
|
// They also lean back: the top edge away above the
|
|
// loop, the bottom edge away below it.
|
|
readonly property real tiltX: root.windowsOpen && column.isCurrentColumn ? -Math.sign(index - column.selectedWs) * root.theme.loopTiltX : 0
|
|
readonly property real baseOpacity: 1 - Math.min(card.distance * root.theme.carouselFadeStep, root.theme.carouselMaxFade)
|
|
readonly property real baseScale: 1 - Math.min(card.distance * root.theme.carouselScaleStep, root.theme.carouselMaxScaleReduction)
|
|
|
|
theme: root.theme
|
|
workspaceName: modelData.name
|
|
workspaceIndex: modelData.idx
|
|
selected: column.isCurrentColumn && index === column.selectedWs
|
|
current: modelData.focused === true
|
|
animateMoves: root.animate
|
|
windows: modelData.windows ?? []
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
anchors.verticalCenterOffset: (index - column.selectedWs) * root.theme.carouselStepY + card.spreadY
|
|
opacity: {
|
|
if (card.opensLoop)
|
|
return 0;
|
|
if (!root.windowsOpen)
|
|
return card.baseOpacity;
|
|
if (!column.isCurrentColumn)
|
|
return card.baseOpacity * root.theme.loopHiddenFade;
|
|
// The two right next to the loop skip the fade by distance.
|
|
if (card.distance === 1)
|
|
return root.theme.loopNeighbourFade;
|
|
return card.baseOpacity * root.theme.loopNeighbourFade;
|
|
}
|
|
scale: card.opensLoop ? 1 / root.theme.loopStartScale : card.baseScale
|
|
z: card.selected ? 1 : 0
|
|
enabled: !root.windowsOpen
|
|
|
|
transform: Rotation {
|
|
origin.x: card.width / 2
|
|
origin.y: card.height / 2
|
|
axis {
|
|
x: 1
|
|
y: 0
|
|
z: 0
|
|
}
|
|
angle: card.tiltX
|
|
|
|
Behavior on angle {
|
|
enabled: root.animate
|
|
NumberAnimation {
|
|
duration: root.theme.carouselDuration
|
|
easing.type: Easing.OutCubic
|
|
}
|
|
}
|
|
}
|
|
|
|
onActivated: root.activateAt(column.columnIndex, index)
|
|
}
|
|
}
|
|
|
|
// Under the selected workspace, which always sits in the
|
|
// middle of the column and is as wide as it.
|
|
KeyHint {
|
|
anchors.right: parent.right
|
|
anchors.top: parent.verticalCenter
|
|
anchors.topMargin: root.theme.cardHeight / 2 + root.theme.hintGap
|
|
z: 3
|
|
theme: root.theme
|
|
hint: root.config.windowsHintText
|
|
shown: root.config.showHints && column.isCurrentColumn && !root.windowsOpen && column.workspaces.length > 0
|
|
}
|
|
}
|
|
}
|
|
|
|
// Sits where the selected card was and grows out of it.
|
|
WindowLoop {
|
|
id: windowLoop
|
|
anchors.fill: parent
|
|
z: 2
|
|
compositor: root.compositor
|
|
theme: root.theme
|
|
workspaceId: root.loopWorkspaceId
|
|
expanded: root.windowsOpen
|
|
exitHint: root.config.showHints ? root.config.exitWindowsHintText : ""
|
|
onWindowChosen: root.requestClose()
|
|
}
|
|
}
|
|
}
|