forked from Shinonome/dots-hyprland
update dock (#422)
This commit is contained in:
@@ -11,7 +11,7 @@ import { firstRunWelcome } from './services/messages.js';
|
|||||||
import { Bar, BarCornerTopleft, BarCornerTopright } from './modules/bar/main.js';
|
import { Bar, BarCornerTopleft, BarCornerTopright } from './modules/bar/main.js';
|
||||||
import Cheatsheet from './modules/cheatsheet/main.js';
|
import Cheatsheet from './modules/cheatsheet/main.js';
|
||||||
// import DesktopBackground from './modules/desktopbackground/main.js';
|
// import DesktopBackground from './modules/desktopbackground/main.js';
|
||||||
// import Dock from './modules/dock/main.js';
|
import Dock from './modules/dock/main.js';
|
||||||
import Corner from './modules/screencorners/main.js';
|
import Corner from './modules/screencorners/main.js';
|
||||||
import Indicator from './modules/indicators/main.js';
|
import Indicator from './modules/indicators/main.js';
|
||||||
import Osk from './modules/onscreenkeyboard/main.js';
|
import Osk from './modules/onscreenkeyboard/main.js';
|
||||||
@@ -54,6 +54,7 @@ const Windows = () => [
|
|||||||
SideRight(),
|
SideRight(),
|
||||||
forMonitors(Osk),
|
forMonitors(Osk),
|
||||||
Session(),
|
Session(),
|
||||||
|
userOptions.dock.enabled ? forMonitors(Dock) : null,
|
||||||
// forMonitors(Bar),
|
// forMonitors(Bar),
|
||||||
...(userOptions.appearance.fakeScreenRounding ? [
|
...(userOptions.appearance.fakeScreenRounding ? [
|
||||||
forMonitors((id) => Corner(id, 'top left', true)),
|
forMonitors((id) => Corner(id, 'top left', true)),
|
||||||
@@ -82,4 +83,3 @@ App.config({
|
|||||||
// Stuff that don't need to be toggled. And they're async so ugh...
|
// Stuff that don't need to be toggled. And they're async so ugh...
|
||||||
forMonitorsAsync(Bar);
|
forMonitorsAsync(Bar);
|
||||||
// Bar().catch(print); // Use this to debug the bar. Single monitor only.
|
// Bar().catch(print); // Use this to debug the bar. Single monitor only.
|
||||||
|
|
||||||
|
|||||||
@@ -76,8 +76,34 @@ let configOptions = {
|
|||||||
'workspaces': {
|
'workspaces': {
|
||||||
'shown': 10,
|
'shown': 10,
|
||||||
},
|
},
|
||||||
|
'dock': {
|
||||||
|
'enabled': true,
|
||||||
|
'hiddenThickness': 5,
|
||||||
|
'pinnedApps': ['firefox', 'org.gnome.Nautilus'],
|
||||||
|
'layer': 'top',
|
||||||
|
'monitorExclusivity': true, // Dock will move to other monitor along with focus if enabled
|
||||||
|
'searchPinnedAppIcons': false, // Try to search for the correct icon if the app class isn't an icon name
|
||||||
|
'trigger': ['client-added', 'client-removed'], // client_added, client_move, workspace_active, client_active
|
||||||
|
// Automatically hide dock after `interval` ms since trigger
|
||||||
|
'autoHide': [
|
||||||
|
{
|
||||||
|
'trigger': 'client-added',
|
||||||
|
'interval': 1000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'trigger': 'client-removed',
|
||||||
|
'interval': 1000,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
// Longer stuff
|
// Longer stuff
|
||||||
'icons': {
|
'icons': {
|
||||||
|
// Find the window's icon by its class with levenshteinDistance
|
||||||
|
// The file names are processed at startup, so if there
|
||||||
|
// are too many files in the search path it'll affect performance
|
||||||
|
// Example: ['/usr/share/icons/Tela-nord/scalable/apps']
|
||||||
|
'searchPaths': [''],
|
||||||
|
|
||||||
substitutions: {
|
substitutions: {
|
||||||
'code-url-handler': "visual-studio-code",
|
'code-url-handler': "visual-studio-code",
|
||||||
'Code': "visual-studio-code",
|
'Code': "visual-studio-code",
|
||||||
|
|||||||
@@ -1,19 +1,28 @@
|
|||||||
const { Gtk } = imports.gi;
|
const { Gtk, GLib } = imports.gi;
|
||||||
import { SCREEN_HEIGHT, SCREEN_WIDTH } from '../../variables.js';
|
import { SCREEN_HEIGHT, SCREEN_WIDTH } from '../../variables.js';
|
||||||
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
|
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
|
||||||
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
|
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
|
||||||
const { EventBox } = Widget;
|
const { EventBox, Button } = Widget;
|
||||||
|
|
||||||
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
|
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
|
||||||
import Applications from 'resource:///com/github/Aylur/ags/service/applications.js';
|
import Applications from 'resource:///com/github/Aylur/ags/service/applications.js';
|
||||||
const { execAsync, exec } = Utils;
|
const { execAsync, exec } = Utils;
|
||||||
const { Box, Revealer } = Widget;
|
const { Box, Revealer } = Widget;
|
||||||
import { setupCursorHover } from '../.widgetutils/cursorhover.js';
|
import { setupCursorHover } from '../.widgetutils/cursorhover.js';
|
||||||
|
import { getAllFiles, searchIcons } from './icons.js'
|
||||||
|
import { MaterialIcon } from '../.commonwidgets/materialicon.js';
|
||||||
|
|
||||||
const pinnedApps = [
|
const icon_files = userOptions.icons.searchPaths.map(e => getAllFiles(e)).flat(1)
|
||||||
'firefox',
|
|
||||||
'org.gnome.Nautilus',
|
let isPinned = false
|
||||||
];
|
let cachePath = new Map()
|
||||||
|
|
||||||
|
let timers = []
|
||||||
|
|
||||||
|
function clearTimes() {
|
||||||
|
timers.forEach(e => GLib.source_remove(e))
|
||||||
|
timers = []
|
||||||
|
}
|
||||||
|
|
||||||
function substitute(str) {
|
function substitute(str) {
|
||||||
const subs = [
|
const subs = [
|
||||||
@@ -34,6 +43,19 @@ function substitute(str) {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ExclusiveWindow(client) {
|
||||||
|
const fn = [
|
||||||
|
(client) => !(client !== null && client !== undefined),
|
||||||
|
// Jetbrains
|
||||||
|
(client) => client.title.includes("win"),
|
||||||
|
// Vscode
|
||||||
|
(client) => client.title === '' && client.class === ''
|
||||||
|
]
|
||||||
|
|
||||||
|
for (const item of fn) { if (item(client)) { return true } }
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
const focus = ({ address }) => Utils.execAsync(`hyprctl dispatch focuswindow address:${address}`).catch(print);
|
const focus = ({ address }) => Utils.execAsync(`hyprctl dispatch focuswindow address:${address}`).catch(print);
|
||||||
|
|
||||||
const DockSeparator = (props = {}) => Box({
|
const DockSeparator = (props = {}) => Box({
|
||||||
@@ -41,6 +63,28 @@ const DockSeparator = (props = {}) => Box({
|
|||||||
className: 'dock-separator',
|
className: 'dock-separator',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const PinButton = () => Widget.Button({
|
||||||
|
className: 'dock-app-btn dock-app-btn-animate',
|
||||||
|
tooltipText: 'Pin Dock',
|
||||||
|
child: Widget.Overlay({
|
||||||
|
child: Widget.Box({
|
||||||
|
homogeneous: true,
|
||||||
|
className: 'dock-app-icon',
|
||||||
|
child: MaterialIcon('push_pin', 'hugeass')
|
||||||
|
}),
|
||||||
|
overlays: [Widget.Box({
|
||||||
|
class_name: 'indicator',
|
||||||
|
vpack: 'end',
|
||||||
|
hpack: 'center',
|
||||||
|
})],
|
||||||
|
}),
|
||||||
|
onClicked: (self) => {
|
||||||
|
isPinned = !isPinned
|
||||||
|
self.className = `${isPinned ? "pinned-dock-app-btn" : "dock-app-btn animate"} dock-app-btn-animate`
|
||||||
|
},
|
||||||
|
setup: setupCursorHover,
|
||||||
|
})
|
||||||
|
|
||||||
const AppButton = ({ icon, ...rest }) => Widget.Revealer({
|
const AppButton = ({ icon, ...rest }) => Widget.Revealer({
|
||||||
attribute: {
|
attribute: {
|
||||||
'workspace': 0
|
'workspace': 0
|
||||||
@@ -50,7 +94,7 @@ const AppButton = ({ icon, ...rest }) => Widget.Revealer({
|
|||||||
transitionDuration: userOptions.animations.durationLarge,
|
transitionDuration: userOptions.animations.durationLarge,
|
||||||
child: Widget.Button({
|
child: Widget.Button({
|
||||||
...rest,
|
...rest,
|
||||||
className: 'dock-app-btn',
|
className: 'dock-app-btn dock-app-btn-animate',
|
||||||
child: Widget.Box({
|
child: Widget.Box({
|
||||||
child: Widget.Overlay({
|
child: Widget.Overlay({
|
||||||
child: Widget.Box({
|
child: Widget.Box({
|
||||||
@@ -73,24 +117,33 @@ const AppButton = ({ icon, ...rest }) => Widget.Revealer({
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
const Taskbar = () => Widget.Box({
|
const Taskbar = (monitor) => Widget.Box({
|
||||||
className: 'dock-apps',
|
className: 'dock-apps',
|
||||||
attribute: {
|
attribute: {
|
||||||
|
monitor: monitor,
|
||||||
'map': new Map(),
|
'map': new Map(),
|
||||||
'clientSortFunc': (a, b) => {
|
'clientSortFunc': (a, b) => {
|
||||||
return a.attribute.workspace > b.attribute.workspace;
|
return a.attribute.workspace > b.attribute.workspace;
|
||||||
},
|
},
|
||||||
'update': (box) => {
|
'update': (box, monitor) => {
|
||||||
for (let i = 0; i < Hyprland.clients.length; i++) {
|
for (let i = 0; i < Hyprland.clients.length; i++) {
|
||||||
const client = Hyprland.clients[i];
|
const client = Hyprland.clients[i];
|
||||||
if (client["pid"] == -1) return;
|
if (client["pid"] == -1) return;
|
||||||
const appClass = substitute(client.class);
|
const appClass = substitute(client.class);
|
||||||
for (const appName of pinnedApps) {
|
// for (const appName of userOptions.dock.pinnedApps) {
|
||||||
if (appClass.includes(appName.toLowerCase()))
|
// if (appClass.includes(appName.toLowerCase()))
|
||||||
return null;
|
// return null;
|
||||||
|
// }
|
||||||
|
let appClassLower = appClass.toLowerCase()
|
||||||
|
let path = ''
|
||||||
|
if (cachePath[appClassLower]) { path = cachePath[appClassLower] }
|
||||||
|
else {
|
||||||
|
path = searchIcons(appClass.toLowerCase(), icon_files)
|
||||||
|
cachePath[appClassLower] = path
|
||||||
}
|
}
|
||||||
|
if (path === '') { path = substitute(appClass) }
|
||||||
const newButton = AppButton({
|
const newButton = AppButton({
|
||||||
icon: appClass,
|
icon: path,
|
||||||
tooltipText: `${client.title} (${appClass})`,
|
tooltipText: `${client.title} (${appClass})`,
|
||||||
onClicked: () => focus(client),
|
onClicked: () => focus(client),
|
||||||
});
|
});
|
||||||
@@ -100,7 +153,7 @@ const Taskbar = () => Widget.Box({
|
|||||||
}
|
}
|
||||||
box.children = Array.from(box.attribute.map.values());
|
box.children = Array.from(box.attribute.map.values());
|
||||||
},
|
},
|
||||||
'add': (box, address) => {
|
'add': (box, address, monitor) => {
|
||||||
if (!address) { // First active emit is undefined
|
if (!address) { // First active emit is undefined
|
||||||
box.attribute.update(box);
|
box.attribute.update(box);
|
||||||
return;
|
return;
|
||||||
@@ -108,10 +161,18 @@ const Taskbar = () => Widget.Box({
|
|||||||
const newClient = Hyprland.clients.find(client => {
|
const newClient = Hyprland.clients.find(client => {
|
||||||
return client.address == address;
|
return client.address == address;
|
||||||
});
|
});
|
||||||
const appClass = substitute(newClient.class);
|
if (ExclusiveWindow(newClient)) { return }
|
||||||
|
let appClass = newClient.class
|
||||||
|
let appClassLower = appClass.toLowerCase()
|
||||||
|
let path = ''
|
||||||
|
if (cachePath[appClassLower]) { path = cachePath[appClassLower] }
|
||||||
|
else {
|
||||||
|
path = searchIcons(appClassLower, icon_files)
|
||||||
|
cachePath[appClassLower] = path
|
||||||
|
}
|
||||||
|
if (path === '') { path = substitute(appClass) }
|
||||||
const newButton = AppButton({
|
const newButton = AppButton({
|
||||||
icon: appClass,
|
icon: path,
|
||||||
tooltipText: `${newClient.title} (${appClass})`,
|
tooltipText: `${newClient.title} (${appClass})`,
|
||||||
onClicked: () => focus(newClient),
|
onClicked: () => focus(newClient),
|
||||||
})
|
})
|
||||||
@@ -135,8 +196,8 @@ const Taskbar = () => Widget.Box({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
setup: (self) => {
|
setup: (self) => {
|
||||||
self.hook(Hyprland, (box, address) => box.attribute.add(box, address), 'client-added')
|
self.hook(Hyprland, (box, address) => box.attribute.add(box, address, self.monitor), 'client-added')
|
||||||
.hook(Hyprland, (box, address) => box.attribute.remove(box, address), 'client-removed')
|
.hook(Hyprland, (box, address) => box.attribute.remove(box, address, self.monitor), 'client-removed')
|
||||||
Utils.timeout(100, () => self.attribute.update(self));
|
Utils.timeout(100, () => self.attribute.update(self));
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -144,12 +205,15 @@ const Taskbar = () => Widget.Box({
|
|||||||
const PinnedApps = () => Widget.Box({
|
const PinnedApps = () => Widget.Box({
|
||||||
class_name: 'dock-apps',
|
class_name: 'dock-apps',
|
||||||
homogeneous: true,
|
homogeneous: true,
|
||||||
children: pinnedApps
|
children: userOptions.dock.pinnedApps
|
||||||
.map(term => ({ app: Applications.query(term)?.[0], term }))
|
.map(term => ({ app: Applications.query(term)?.[0], term }))
|
||||||
.filter(({ app }) => app)
|
.filter(({ app }) => app)
|
||||||
.map(({ app, term = true }) => {
|
.map(({ app, term = true }) => {
|
||||||
const newButton = AppButton({
|
const newButton = AppButton({
|
||||||
icon: app.icon_name,
|
// different icon, emm...
|
||||||
|
icon: userOptions.dock.searchPinnedAppIcons ?
|
||||||
|
searchIcons(app.name, icon_files) :
|
||||||
|
app.icon_name,
|
||||||
onClicked: () => {
|
onClicked: () => {
|
||||||
for (const client of Hyprland.clients) {
|
for (const client of Hyprland.clients) {
|
||||||
if (client.class.toLowerCase().includes(term))
|
if (client.class.toLowerCase().includes(term))
|
||||||
@@ -177,82 +241,109 @@ const PinnedApps = () => Widget.Box({
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default () => {
|
export default (monitor = 0) => {
|
||||||
const dockContent = Box({
|
const dockContent = Box({
|
||||||
className: 'dock-bg spacing-h-5',
|
className: 'dock-bg spacing-h-5',
|
||||||
children: [
|
children: [
|
||||||
PinnedApps(),
|
PinnedApps(),
|
||||||
DockSeparator(),
|
DockSeparator(),
|
||||||
Taskbar(),
|
Taskbar(),
|
||||||
|
PinButton(),
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
const dockRevealer = Revealer({
|
const dockRevealer = Revealer({
|
||||||
attribute: {
|
attribute: {
|
||||||
'updateShow': self => { // I only use mouse to resize. I don't care about keyboard resize if that's a thing
|
'updateShow': self => { // I only use mouse to resize. I don't care about keyboard resize if that's a thing
|
||||||
const dockSize = [
|
// const dockSize = [
|
||||||
dockContent.get_allocated_width(),
|
// dockContent.get_allocated_width(),
|
||||||
dockContent.get_allocated_height()
|
// dockContent.get_allocated_height()
|
||||||
]
|
// ]
|
||||||
const dockAt = [
|
// const dockAt = [
|
||||||
SCREEN_WIDTH / 2 - dockSize[0] / 2,
|
// SCREEN_WIDTH / 2 - dockSize[0] / 2,
|
||||||
SCREEN_HEIGHT - dockSize[1],
|
// SCREEN_HEIGHT - dockSize[1],
|
||||||
];
|
// ];
|
||||||
const dockLeft = dockAt[0];
|
// const dockLeft = dockAt[0];
|
||||||
const dockRight = dockAt[0] + dockSize[0];
|
// const dockRight = dockAt[0] + dockSize[0];
|
||||||
const dockTop = dockAt[1];
|
// const dockTop = dockAt[1];
|
||||||
const dockBottom = dockAt[1] + dockSize[1];
|
// const dockBottom = dockAt[1] + dockSize[1];
|
||||||
|
//
|
||||||
|
// const currentWorkspace = Hyprland.active.workspace.id;
|
||||||
|
// var toReveal = true;
|
||||||
|
// const hyprlandClients = JSON.parse(exec('hyprctl clients -j'));
|
||||||
|
// for (const index in hyprlandClients) {
|
||||||
|
// const client = hyprlandClients[index];
|
||||||
|
// const clientLeft = client.at[0];
|
||||||
|
// const clientRight = client.at[0] + client.size[0];
|
||||||
|
// const clientTop = client.at[1];
|
||||||
|
// const clientBottom = client.at[1] + client.size[1];
|
||||||
|
//
|
||||||
|
// if (client.workspace.id == currentWorkspace) {
|
||||||
|
// if (
|
||||||
|
// // clientLeft < dockRight &&
|
||||||
|
// // clientRight > dockLeft &&
|
||||||
|
// // clientTop < dockBottom &&
|
||||||
|
// // clientBottom > dockTop
|
||||||
|
// ) {
|
||||||
|
// self.revealChild = false;
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// // if (currentWorkspace === client.workspace.id) {
|
||||||
|
// self.revealChild = true;
|
||||||
|
// // }
|
||||||
|
|
||||||
const currentWorkspace = Hyprland.active.workspace.id;
|
if (userOptions.dock.monitorExclusivity)
|
||||||
var toReveal = true;
|
self.revealChild = Hyprland.active.monitor.id === monitor;
|
||||||
const hyprlandClients = JSON.parse(exec('hyprctl clients -j'));
|
else
|
||||||
for (const index in hyprlandClients) {
|
self.revealChild = true;
|
||||||
const client = hyprlandClients[index];
|
|
||||||
const clientLeft = client.at[0];
|
|
||||||
const clientRight = client.at[0] + client.size[0];
|
|
||||||
const clientTop = client.at[1];
|
|
||||||
const clientBottom = client.at[1] + client.size[1];
|
|
||||||
|
|
||||||
if (client.workspace.id == currentWorkspace) {
|
return self.revealChild
|
||||||
if (
|
|
||||||
clientLeft < dockRight &&
|
|
||||||
clientRight > dockLeft &&
|
|
||||||
clientTop < dockBottom &&
|
|
||||||
clientBottom > dockTop
|
|
||||||
) {
|
|
||||||
self.revealChild = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.revealChild = true;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
revealChild: false,
|
revealChild: false,
|
||||||
transition: 'slide_up',
|
transition: 'slide_up',
|
||||||
transitionDuration: userOptions.animations.durationLarge,
|
transitionDuration: userOptions.animations.durationLarge,
|
||||||
child: dockContent,
|
child: dockContent,
|
||||||
// setup: (self) => self
|
setup: (self) => {
|
||||||
// .hook(Hyprland, (self) => self.attribute.updateShow(self))
|
const callback = (self, trigger) => {
|
||||||
// .hook(Hyprland.active.workspace, (self) => self.attribute.updateShow(self))
|
if (!userOptions.dock.trigger.includes(trigger)) return
|
||||||
// .hook(Hyprland.active.client, (self) => self.attribute.updateShow(self))
|
const flag = self.attribute.updateShow(self)
|
||||||
// .hook(Hyprland, (self) => self.attribute.updateShow(self), 'client-added')
|
|
||||||
// .hook(Hyprland, (self) => self.attribute.updateShow(self), 'client-removed')
|
if (flag) clearTimes();
|
||||||
// ,
|
|
||||||
|
const hidden = userOptions.dock.autoHide.find(e => e["trigger"] === trigger)
|
||||||
|
|
||||||
|
if (hidden) {
|
||||||
|
let id = Utils.timeout(hidden.interval, () => {
|
||||||
|
if (!isPinned) { self.revealChild = false }
|
||||||
|
timers = timers.filter(e => e !== id)
|
||||||
|
})
|
||||||
|
timers.push(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self
|
||||||
|
// .hook(Hyprland, (self) => self.attribute.updateShow(self))
|
||||||
|
.hook(Hyprland.active.workspace, self => callback(self, "workspace-active"))
|
||||||
|
.hook(Hyprland.active.client, self => callback(self, "client-active"))
|
||||||
|
.hook(Hyprland, self => callback(self, "client-added"), "client-added")
|
||||||
|
.hook(Hyprland, self => callback(self, "client-removed"), "client-removed")
|
||||||
|
},
|
||||||
})
|
})
|
||||||
return EventBox({
|
return EventBox({
|
||||||
onHover: () => {
|
onHover: () => {
|
||||||
dockRevealer.revealChild = true;
|
dockRevealer.revealChild = true;
|
||||||
},
|
clearTimes()
|
||||||
onHoverLost: () => {
|
|
||||||
if (Hyprland.active.client.attribute.class.length === 0) return;
|
|
||||||
dockRevealer.revealChild = false;
|
|
||||||
},
|
},
|
||||||
child: Box({
|
child: Box({
|
||||||
homogeneous: true,
|
homogeneous: true,
|
||||||
css: 'min-height: 2px;',
|
css: `min-height: ${userOptions.dock.hiddenThickness}px;`,
|
||||||
children: [
|
children: [dockRevealer],
|
||||||
dockRevealer,
|
|
||||||
]
|
|
||||||
}),
|
}),
|
||||||
|
setup: self => self.on("leave-notify-event", () => {
|
||||||
|
if (!isPinned) dockRevealer.revealChild = false;
|
||||||
|
clearTimes()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
const { Gio, GLib } = imports.gi
|
||||||
|
|
||||||
|
const exists = (path) => Gio.File.new_for_path(path).query_exists(null);
|
||||||
|
|
||||||
|
export const levenshteinDistance = (a, b) => {
|
||||||
|
if (!a.length) { return b.length }
|
||||||
|
if (!b.length) { return a.length }
|
||||||
|
|
||||||
|
let f = Array.from(new Array(a.length + 1),
|
||||||
|
() => new Array(b.length + 1).fill(0))
|
||||||
|
|
||||||
|
for (let i = 0; i <= b.length; i++) { f[0][i] = i; }
|
||||||
|
for (let i = 0; i <= a.length; i++) { f[i][0] = i; }
|
||||||
|
|
||||||
|
for (let i = 1; i <= a.length; i++) {
|
||||||
|
for (let j = 1; j <= b.length; j++) {
|
||||||
|
if (a.charAt(i - 1) === b.charAt(j - 1)) {
|
||||||
|
f[i][j] = f[i-1][j-1]
|
||||||
|
} else {
|
||||||
|
f[i][j] = Math.min(f[i-1][j-1], Math.min(f[i][j-1], f[i-1][j])) + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return f[a.length][b.length]
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getAllFiles = (dir, files = []) => {
|
||||||
|
if (!exists(dir)) { return [] }
|
||||||
|
const file = Gio.File.new_for_path(dir);
|
||||||
|
const enumerator = file.enumerate_children('standard::name,standard::type',
|
||||||
|
Gio.FileQueryInfoFlags.NONE, null);
|
||||||
|
|
||||||
|
for (const info of enumerator) {
|
||||||
|
if (info.get_file_type() === Gio.FileType.DIRECTORY) {
|
||||||
|
files.push(getAllFiles(`${dir}/${info.get_name()}`))
|
||||||
|
} else {
|
||||||
|
files.push(`${dir}/${info.get_name()}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return files.flat(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const searchIcons = (appClass, files) => {
|
||||||
|
appClass = appClass.toLowerCase()
|
||||||
|
|
||||||
|
if (!files.length) { return "" }
|
||||||
|
|
||||||
|
let appro = 0x3f3f3f3f
|
||||||
|
let path = ""
|
||||||
|
|
||||||
|
for (const item of files) {
|
||||||
|
let score = levenshteinDistance(item.split("/").pop().toLowerCase().split(".")[0], appClass)
|
||||||
|
|
||||||
|
if (score < appro) {
|
||||||
|
appro = score
|
||||||
|
path = item
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return path
|
||||||
|
}
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
|
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
|
||||||
import Dock from './dock.js';
|
import Dock from './dock.js';
|
||||||
|
|
||||||
export default () => Widget.Window({
|
export default (monitor = 0) => Widget.Window({
|
||||||
name: 'dock',
|
monitor,
|
||||||
layer: 'bottom',
|
name: `dock${monitor}`,
|
||||||
|
layer: userOptions.dock.layer,
|
||||||
anchor: ['bottom'],
|
anchor: ['bottom'],
|
||||||
exclusivity: 'normal',
|
exclusivity: 'normal',
|
||||||
visible: true,
|
visible: true,
|
||||||
child: Dock(),
|
child: Dock(monitor),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,11 +5,22 @@
|
|||||||
padding: 0.682rem;
|
padding: 0.682rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.dock-app-btn-animate {
|
||||||
|
transition-property: background-color;
|
||||||
|
transition-duration: 0.5s;
|
||||||
|
}
|
||||||
|
|
||||||
.dock-app-btn {
|
.dock-app-btn {
|
||||||
@include normal-rounding;
|
@include normal-rounding;
|
||||||
padding: 0.273rem;
|
padding: 0.273rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.pinned-dock-app-btn {
|
||||||
|
@include normal-rounding;
|
||||||
|
padding: 0.273rem;
|
||||||
|
background-color: $layer0Hover;
|
||||||
|
}
|
||||||
|
|
||||||
.dock-app-btn:hover,
|
.dock-app-btn:hover,
|
||||||
.dock-app-btn:focus {
|
.dock-app-btn:focus {
|
||||||
background-color: $layer0Hover;
|
background-color: $layer0Hover;
|
||||||
|
|||||||
Reference in New Issue
Block a user