Initial commit: Icon Task Manager with Zoom - Enhanced KDE Plasma task manager with macOS dock-like zoom effects, custom launch animations, performance optimizations, and comprehensive documentation
This commit is contained in:
commit
e337191734
32 files changed
+6680
No files matched your search
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
SPDX-FileCopyrightText: 2012-2013 Eike Hein <hein@kde.org>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
.import org.kde.kirigami as Kirigami
|
||||
|
||||
const iconMargin = Math.round(Kirigami.Units.smallSpacing / 4);
|
||||
const labelMargin = Kirigami.Units.smallSpacing;
|
||||
|
||||
function horizontalMargins() {
|
||||
const spacingAdjustment = (tasks.plasmoid.pluginName === "org.kde.plasma.icontasks") ? (Kirigami.Settings.tabletMode ? 3 : tasks.plasmoid.configuration.iconSpacing) : 1
|
||||
return (taskFrame.margins.left + taskFrame.margins.right) * (tasks.vertical ? 1 : spacingAdjustment);
|
||||
}
|
||||
|
||||
function verticalMargins() {
|
||||
const spacingAdjustment = (tasks.plasmoid.pluginName === "org.kde.plasma.icontasks") ? (Kirigami.Settings.tabletMode ? 3 : tasks.plasmoid.configuration.iconSpacing) : 1
|
||||
return (taskFrame.margins.top + taskFrame.margins.bottom) * (tasks.vertical ? spacingAdjustment : 1);
|
||||
}
|
||||
|
||||
function adjustMargin(height, margin) {
|
||||
const available = height - verticalMargins();
|
||||
|
||||
if (available < Kirigami.Units.iconSizes.small) {
|
||||
return Math.floor((margin * (Kirigami.Units.iconSizes.small / available)) / 3);
|
||||
}
|
||||
|
||||
return margin;
|
||||
}
|
||||
|
||||
function maxStripes() {
|
||||
const length = tasks.vertical ? tasks.width : tasks.height;
|
||||
const minimum = tasks.vertical ? preferredMinWidth() : preferredMinHeight();
|
||||
|
||||
return Math.min(tasks.plasmoid.configuration.maxStripes, Math.max(1, Math.floor(length / minimum)));
|
||||
}
|
||||
|
||||
function optimumCapacity(width, height) {
|
||||
const length = tasks.vertical ? height : width;
|
||||
const maximum = tasks.vertical ? preferredMaxHeight() : preferredMaxWidth();
|
||||
|
||||
if (!tasks.vertical) {
|
||||
// Fit more tasks in this case, that is possible to cut text, before combining tasks.
|
||||
return Math.ceil(length / maximum) * maxStripes() + 1;
|
||||
}
|
||||
|
||||
return Math.floor(length / maximum) * maxStripes();
|
||||
}
|
||||
|
||||
function preferredMinWidth() {
|
||||
let width = preferredMinLauncherWidth();
|
||||
|
||||
if (!tasks.vertical && !tasks.iconsOnly) {
|
||||
width +=
|
||||
(Kirigami.Units.smallSpacing * 2) +
|
||||
(Kirigami.Units.gridUnit * 8);
|
||||
}
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
function preferredMaxWidth() {
|
||||
if (tasks.iconsOnly) {
|
||||
if (tasks.vertical) {
|
||||
if (tasks.width === 0) {
|
||||
return 0
|
||||
}
|
||||
return tasks.width + verticalMargins();
|
||||
} else {
|
||||
if (tasks.height === 0) {
|
||||
return 0
|
||||
}
|
||||
return tasks.height + horizontalMargins();
|
||||
}
|
||||
}
|
||||
|
||||
// Avoid doing a bunch of unnecessary work below in vertical mode
|
||||
if (tasks.vertical) {
|
||||
return preferredMinWidth();
|
||||
}
|
||||
|
||||
// Visually, a large max item width on a tall panel looks cluttered even
|
||||
// with just a task or two open. This clutter is less pronounced on panels
|
||||
// lower in height, as there is generally more horizontal space.
|
||||
//
|
||||
// This allows for one default value for max item width where clutter is
|
||||
// reduced at low task counts for tall panels, while leaving low height
|
||||
// panels less affected (unaffected at 20px).
|
||||
const laneHeight = tasks.height / maxStripes(); // correct for multiple rows
|
||||
let baseFactor = 1; // sane default in case something goes wrong
|
||||
switch (tasks.plasmoid.configuration.taskMaxWidth) {
|
||||
case 0: // narrow
|
||||
baseFactor = 1.2;
|
||||
break;
|
||||
case 1: // medium
|
||||
baseFactor = 1.6;
|
||||
break;
|
||||
case 2: // wide
|
||||
baseFactor = 2;
|
||||
break;
|
||||
}
|
||||
// For every pixel of height above 20, knock the factor down by 0.01. This
|
||||
// produces nice results for 20~50 pixels. Above 50, it suddenly feels like
|
||||
// it's shrinking a lot, and above 80 the Medium and Narrow settings would
|
||||
// end up setting the same width, so don't apply further reduction above 50.
|
||||
const factorReduction = (Math.min(50, laneHeight) - 20) * 0.01;
|
||||
// Clamp the minimum factor to 1 to ensure max width is always >= min width.
|
||||
// and the factor reduction to 0 so we don't ever increase the factor
|
||||
const factor = Math.max(1, baseFactor - Math.max(0, factorReduction));
|
||||
return Math.floor(preferredMinWidth() * factor);
|
||||
}
|
||||
|
||||
function preferredMinHeight() {
|
||||
// TODO FIXME UPSTREAM: Port to proper font metrics for descenders once we have access to them.
|
||||
return Kirigami.Units.iconSizes.sizeForLabels + 4;
|
||||
}
|
||||
|
||||
function preferredMaxHeight() {
|
||||
if (tasks.vertical) {
|
||||
let taskPreferredSize = 0;
|
||||
if (tasks.iconsOnly) {
|
||||
taskPreferredSize = tasks.width / maxStripes();
|
||||
} else {
|
||||
taskPreferredSize = Math.max(Kirigami.Units.iconSizes.sizeForLabels,
|
||||
Kirigami.Units.iconSizes.medium);
|
||||
}
|
||||
return verticalMargins() +
|
||||
Math.min(
|
||||
// Do not allow the preferred icon size to exceed the width of
|
||||
// the vertical task manager.
|
||||
tasks.width / maxStripes(),
|
||||
taskPreferredSize);
|
||||
} else {
|
||||
return verticalMargins() +
|
||||
Math.min(
|
||||
Kirigami.Units.iconSizes.small * 3,
|
||||
Kirigami.Units.iconSizes.sizeForLabels * 3);
|
||||
}
|
||||
}
|
||||
|
||||
function preferredHeightInPopup() {
|
||||
return verticalMargins() + Math.max(Kirigami.Units.iconSizes.sizeForLabels,
|
||||
Kirigami.Units.iconSizes.medium);
|
||||
}
|
||||
|
||||
function spaceRequiredToShowText() {
|
||||
// gridUnit is the height of the default font, but only one isn't enough to
|
||||
// show anything but the elision character. 2 is too high and results in
|
||||
// text appearing only at excessively high widths.
|
||||
return Math.round(Kirigami.Units.gridUnit * 1.5);
|
||||
}
|
||||
|
||||
function preferredMinLauncherWidth() {
|
||||
const baseWidth = tasks.vertical ? preferredMinHeight() : Math.min(tasks.height, Kirigami.Units.iconSizes.small * 3);
|
||||
|
||||
return (baseWidth + horizontalMargins())
|
||||
- (adjustMargin(baseWidth, taskFrame.margins.top) + adjustMargin(baseWidth, taskFrame.margins.bottom));
|
||||
}
|
||||
|
||||
function maximumContextMenuTextWidth() {
|
||||
return (Kirigami.Units.iconSizes.sizeForLabels * 28);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
SPDX-FileCopyrightText: 2012-2016 Eike Hein <hein@kde.org>
|
||||
SPDX-FileCopyrightText: 2020 Nate Graham <nate@kde.org>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
.pragma library
|
||||
|
||||
.import org.kde.taskmanager as TaskManager
|
||||
.import org.kde.plasma.core as PlasmaCore // Needed by TaskManager
|
||||
|
||||
// Can't be `let`, or else QML counterpart won't be able to assign to it.
|
||||
var taskManagerInstanceCount = 0;
|
||||
|
||||
function activateNextPrevTask(anchor, next, wheelSkipMinimized, tasks) {
|
||||
// FIXME TODO: Unnecessarily convoluted and costly; optimize.
|
||||
|
||||
let taskIndexList = [];
|
||||
const activeTaskIndex = tasks.tasksModel.activeTask;
|
||||
|
||||
for (let i = 0; i < tasks.taskList.children.length - 1; ++i) {
|
||||
const task = tasks.taskList.children[i];
|
||||
const modelIndex = task.modelIndex(i);
|
||||
|
||||
if (!task.model.IsLauncher && !task.model.IsStartup) {
|
||||
if (task.model.IsGroupParent) {
|
||||
if (task === anchor) { // If the anchor is a group parent, collect only windows within the group.
|
||||
taskIndexList = [];
|
||||
}
|
||||
|
||||
for (let j = 0; j < tasks.tasksModel.rowCount(modelIndex); ++j) {
|
||||
const childModelIndex = tasks.tasksModel.makeModelIndex(i, j);
|
||||
const childHidden = tasks.tasksModel.data(childModelIndex, TaskManager.AbstractTasksModel.IsHidden);
|
||||
if (!wheelSkipMinimized || !childHidden) {
|
||||
taskIndexList.push(childModelIndex);
|
||||
}
|
||||
}
|
||||
|
||||
if (task === anchor) { // See above.
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (!wheelSkipMinimized || !task.model.IsHidden) {
|
||||
taskIndexList.push(modelIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!taskIndexList.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
let target = taskIndexList[0];
|
||||
|
||||
for (let i = 0; i < taskIndexList.length; ++i) {
|
||||
if (taskIndexList[i] === activeTaskIndex)
|
||||
{
|
||||
if (next && i < (taskIndexList.length - 1)) {
|
||||
target = taskIndexList[i + 1];
|
||||
} else if (!next) {
|
||||
if (i) {
|
||||
target = taskIndexList[i - 1];
|
||||
} else {
|
||||
target = taskIndexList[taskIndexList.length - 1];
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
tasks.tasksModel.requestActivate(target);
|
||||
}
|
||||
|
||||
function activateTask(index, model, modifiers, task, plasmoid, tasks, windowViewAvailable) {
|
||||
if (modifiers & Qt.ShiftModifier) {
|
||||
tasks.tasksModel.requestNewInstance(index);
|
||||
return;
|
||||
}
|
||||
// Publish delegate geometry again if there are more than one task manager instance
|
||||
if (taskManagerInstanceCount >= 2) {
|
||||
tasks.tasksModel.requestPublishDelegateGeometry(task.modelIndex(), tasks.backend.globalRect(task), task);
|
||||
}
|
||||
|
||||
if (model.IsGroupParent) {
|
||||
// Option 1 (default): Cycle through this group's tasks
|
||||
// ====================================================
|
||||
// If the grouped task does not include the currently active task, bring
|
||||
// forward the most recently used task in the group according to the
|
||||
// Stacking order.
|
||||
// Otherwise cycle through all tasks in the group without paying attention
|
||||
// to the stacking order, which otherwise would change with every click
|
||||
if (plasmoid.configuration.groupedTaskVisualization === 0) {
|
||||
let childTaskList = [];
|
||||
let highestStacking = -1;
|
||||
let lastUsedTask = undefined;
|
||||
|
||||
// Build list of child tasks and get stacking order data for them
|
||||
for (let i = 0; i < tasks.tasksModel.rowCount(task.modelIndex(index)); ++i) {
|
||||
const childTaskModelIndex = tasks.tasksModel.makeModelIndex(task.index, i);
|
||||
childTaskList.push(childTaskModelIndex);
|
||||
const stacking = tasks.tasksModel.data(childTaskModelIndex, TaskManager.AbstractTasksModel.StackingOrder);
|
||||
if (stacking > highestStacking) {
|
||||
highestStacking = stacking;
|
||||
lastUsedTask = childTaskModelIndex;
|
||||
}
|
||||
}
|
||||
|
||||
// If the active task is from a different app from the group that
|
||||
// was clicked on switch to the last-used task from that app.
|
||||
if (!childTaskList.some(index => tasks.tasksModel.data(index, TaskManager.AbstractTasksModel.IsActive))) {
|
||||
tasks.tasksModel.requestActivate(lastUsedTask);
|
||||
} else {
|
||||
// If the active task is already among in the group that was
|
||||
// activated, cycle through all tasks according to the order of
|
||||
// the immutable model index so the order doesn't change with
|
||||
// every click.
|
||||
for (let j = 0; j < childTaskList.length; ++j) {
|
||||
const childTask = childTaskList[j];
|
||||
if (tasks.tasksModel.data(childTask, TaskManager.AbstractTasksModel.IsActive)) {
|
||||
// Found the current task. Activate the next one
|
||||
let nextTask = j + 1;
|
||||
if (nextTask >= childTaskList.length) {
|
||||
nextTask = 0;
|
||||
}
|
||||
tasks.tasksModel.requestActivate(childTaskList[nextTask]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Option 2: show tooltips for all child tasks
|
||||
// ===========================================
|
||||
else if (plasmoid.configuration.groupedTaskVisualization === 1) {
|
||||
if (tasks.toolTipOpenedByClick) {
|
||||
task.hideImmediately();
|
||||
} else {
|
||||
tasks.toolTipOpenedByClick = task;
|
||||
task.updateMainItemBindings(); // BUG 452187
|
||||
task.showToolTip();
|
||||
}
|
||||
}
|
||||
|
||||
// Option 3: show Window View for all child tasks
|
||||
// ==================================================
|
||||
// Make sure the Window View effect is are actually enabled though;
|
||||
// if not, fall through to the next option.
|
||||
else if (plasmoid.configuration.groupedTaskVisualization === 2 && windowViewAvailable) {
|
||||
task.hideToolTip();
|
||||
tasks.activateWindowView(model.WinIdList);
|
||||
}
|
||||
|
||||
// Option 4: show group dialog/textual list
|
||||
// ========================================
|
||||
// This is also the final fallback option if Window View
|
||||
// is chosen but not actually available
|
||||
else {
|
||||
if (tasks.groupDialog) {
|
||||
task.hideToolTip();
|
||||
tasks.groupDialog.visible = false;
|
||||
} else {
|
||||
createGroupDialog(task, tasks);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (model.IsMinimized) {
|
||||
tasks.tasksModel.requestToggleMinimized(index);
|
||||
tasks.tasksModel.requestActivate(index);
|
||||
} else if (model.IsActive && plasmoid.configuration.minimizeActiveTaskOnClick) {
|
||||
tasks.tasksModel.requestToggleMinimized(index);
|
||||
} else {
|
||||
tasks.tasksModel.requestActivate(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function taskPrefix(prefix, location) {
|
||||
let effectivePrefix;
|
||||
|
||||
switch (location) {
|
||||
case PlasmaCore.Types.LeftEdge:
|
||||
effectivePrefix = "west-" + prefix;
|
||||
break;
|
||||
case PlasmaCore.Types.TopEdge:
|
||||
effectivePrefix = "north-" + prefix;
|
||||
break;
|
||||
case PlasmaCore.Types.RightEdge:
|
||||
effectivePrefix = "east-" + prefix;
|
||||
break;
|
||||
default:
|
||||
effectivePrefix = "south-" + prefix;
|
||||
}
|
||||
return [effectivePrefix, prefix];
|
||||
}
|
||||
|
||||
function taskPrefixHovered(prefix, location) {
|
||||
return [
|
||||
...taskPrefix((prefix || "launcher") + "-hover", location),
|
||||
...prefix ? taskPrefix("hover", location) : [],
|
||||
...taskPrefix(prefix, location),
|
||||
];
|
||||
}
|
||||
|
||||
function createGroupDialog(visualParent, tasks) {
|
||||
if (!visualParent) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (tasks.groupDialog) {
|
||||
tasks.groupDialog.visualParent = visualParent;
|
||||
return;
|
||||
}
|
||||
|
||||
tasks.groupDialog = tasks.groupDialogComponent.createObject(tasks, { visualParent });
|
||||
}
|
||||
Reference in new issue
Block a user