forked from Shinonome/dots-hyprland
ags: sync
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
|
||||
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
|
||||
import Mpris from 'resource:///com/github/Aylur/ags/service/mpris.js';
|
||||
const { Box, Label, Overlay, Revealer } = Widget;
|
||||
const { execAsync, exec } = Utils;
|
||||
import { AnimatedCircProg } from "../../lib/animatedcircularprogress.js";
|
||||
import { MaterialIcon } from '../../lib/materialicon.js';
|
||||
import { showMusicControls } from '../../variables.js';
|
||||
|
||||
function trimTrackTitle(title) {
|
||||
if(!title) return '';
|
||||
if (!title) return '';
|
||||
const cleanRegexes = [
|
||||
/【[^】]*】/, // Touhou n weeb stuff
|
||||
/\[FREE DOWNLOAD\]/, // F-777
|
||||
@@ -15,6 +17,54 @@ function trimTrackTitle(title) {
|
||||
return title;
|
||||
}
|
||||
|
||||
const BarGroup = ({ child }) => Widget.Box({
|
||||
className: 'bar-group-margin bar-sides',
|
||||
children: [
|
||||
Widget.Box({
|
||||
className: 'bar-group bar-group-standalone bar-group-pad-system',
|
||||
children: [child],
|
||||
}),
|
||||
]
|
||||
});
|
||||
|
||||
const BarResource = (name, icon, command) => {
|
||||
const resourceCircProg = AnimatedCircProg({
|
||||
className: 'bar-batt-circprog',
|
||||
vpack: 'center',
|
||||
hpack: 'center',
|
||||
});
|
||||
const resourceProgress = Overlay({
|
||||
child: Widget.Box({
|
||||
vpack: 'center',
|
||||
className: 'bar-batt',
|
||||
homogeneous: true,
|
||||
children: [
|
||||
MaterialIcon(icon, 'small'),
|
||||
],
|
||||
}),
|
||||
overlays: [resourceCircProg]
|
||||
});
|
||||
const resourceLabel = Label({
|
||||
className: 'txt-smallie txt-onSurfaceVariant',
|
||||
});
|
||||
const widget = Box({
|
||||
className: 'spacing-h-4 txt-onSurfaceVariant',
|
||||
children: [
|
||||
resourceLabel,
|
||||
resourceProgress,
|
||||
],
|
||||
setup: (self) => self
|
||||
.poll(5000, () => execAsync(['bash', '-c', command])
|
||||
.then((output) => {
|
||||
resourceCircProg.css = `font-size: ${Number(output)}px;`;
|
||||
resourceLabel.label = `${Math.round(Number(output))}%`;
|
||||
widget.tooltipText = `${name}: ${Math.round(Number(output))}%`;
|
||||
}).catch(print))
|
||||
,
|
||||
});
|
||||
return widget;
|
||||
}
|
||||
|
||||
const TrackProgress = () => {
|
||||
const _updateProgress = (circprog) => {
|
||||
const mpris = Mpris.getPlayer('');
|
||||
@@ -84,22 +134,48 @@ export default () => {
|
||||
}),
|
||||
})
|
||||
})
|
||||
const musicStuff = Box({
|
||||
className: 'spacing-h-10',
|
||||
hexpand: true,
|
||||
children: [
|
||||
playingState,
|
||||
trackTitle,
|
||||
]
|
||||
})
|
||||
const systemResources = BarGroup({
|
||||
child: Box({
|
||||
children: [
|
||||
BarResource('RAM Usage', 'memory', `free | awk '/^Mem/ {printf("%.2f\\n", ($3/$2) * 100)}'`),
|
||||
Revealer({
|
||||
revealChild: true,
|
||||
transition: 'slide_left',
|
||||
transitionDuration: 200,
|
||||
child: Box({
|
||||
className: 'spacing-h-10 margin-left-10',
|
||||
children: [
|
||||
BarResource('Swap Usage', 'swap_horiz', `free | awk '/^Swap/ {if ($2 > 0) printf("%.2f\\n", ($3/$2) * 100); else print "0";}'`),
|
||||
BarResource('CPU Usage', 'settings_motion_mode', `top -bn1 | grep Cpu | awk '{print $2}'`),
|
||||
]
|
||||
}),
|
||||
setup: (self) => self.hook(Mpris, label => {
|
||||
const mpris = Mpris.getPlayer('');
|
||||
self.revealChild = (!mpris);
|
||||
}),
|
||||
})
|
||||
],
|
||||
})
|
||||
});
|
||||
return Widget.EventBox({
|
||||
onScrollUp: (self) => switchToRelativeWorkspace(self, -1),
|
||||
onScrollDown: (self) => switchToRelativeWorkspace(self, +1),
|
||||
onPrimaryClickRelease: () => showMusicControls.setValue(!showMusicControls.value),
|
||||
onSecondaryClickRelease: () => execAsync(['bash', '-c', 'playerctl next || playerctl position `bc <<< "100 * $(playerctl metadata mpris:length) / 1000000 / 100"` &']),
|
||||
onMiddleClickRelease: () => execAsync('playerctl play-pause').catch(print),
|
||||
child: Widget.Box({
|
||||
className: 'bar-group-margin bar-sides',
|
||||
child: Box({
|
||||
className: 'spacing-h-5',
|
||||
children: [
|
||||
Widget.Box({
|
||||
className: 'bar-group bar-group-standalone bar-group-pad-music spacing-h-10',
|
||||
children: [
|
||||
playingState,
|
||||
trackTitle,
|
||||
]
|
||||
})
|
||||
BarGroup({ child: musicStuff }),
|
||||
systemResources,
|
||||
]
|
||||
})
|
||||
});
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// This is for the right pill of the bar.
|
||||
// For the cool memory indicator on the sidebar, see sysinfo.js
|
||||
// This is for the right pills of the bar.
|
||||
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
|
||||
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
|
||||
const { Box, Label, Button, Overlay, Revealer, Scrollable, Stack, EventBox } = Widget;
|
||||
@@ -8,8 +7,11 @@ const { GLib } = imports.gi;
|
||||
import Battery from 'resource:///com/github/Aylur/ags/service/battery.js';
|
||||
import { MaterialIcon } from '../../lib/materialicon.js';
|
||||
import { AnimatedCircProg } from "../../lib/animatedcircularprogress.js";
|
||||
import { WWO_CODE, WEATHER_SYMBOL, NIGHT_WEATHER_SYMBOL } from '../../data/weather.js';
|
||||
|
||||
const BATTERY_LOW = 20;
|
||||
const WEATHER_CACHE_FOLDER = `${GLib.get_user_cache_dir()}/ags/weather`;
|
||||
Utils.exec(`mkdir -p ${WEATHER_CACHE_FOLDER}`);
|
||||
|
||||
const BatBatteryProgress = () => {
|
||||
const _updateProgress = (circprog) => { // Set circular progress value
|
||||
@@ -90,7 +92,7 @@ const BarBattery = () => Box({
|
||||
transitionDuration: 150,
|
||||
revealChild: false,
|
||||
transition: 'slide_right',
|
||||
child: MaterialIcon('bolt', 'norm', {tooltipText: "Charging"}),
|
||||
child: MaterialIcon('bolt', 'norm', { tooltipText: "Charging" }),
|
||||
setup: (self) => self.hook(Battery, revealer => {
|
||||
self.revealChild = Battery.charging;
|
||||
}),
|
||||
@@ -121,42 +123,6 @@ const BarBattery = () => Box({
|
||||
]
|
||||
});
|
||||
|
||||
const BarResource = (name, icon, command) => {
|
||||
const resourceLabel = Label({
|
||||
className: 'txt-smallie txt-onSurfaceVariant',
|
||||
});
|
||||
const resourceCircProg = AnimatedCircProg({
|
||||
className: 'bar-batt-circprog',
|
||||
vpack: 'center', hpack: 'center',
|
||||
});
|
||||
const widget = Box({
|
||||
className: 'spacing-h-4 txt-onSurfaceVariant',
|
||||
children: [
|
||||
resourceLabel,
|
||||
Overlay({
|
||||
child: Widget.Box({
|
||||
vpack: 'center',
|
||||
className: 'bar-batt',
|
||||
homogeneous: true,
|
||||
children: [
|
||||
MaterialIcon(icon, 'small'),
|
||||
],
|
||||
}),
|
||||
overlays: [resourceCircProg]
|
||||
}),
|
||||
],
|
||||
setup: (self) => self
|
||||
.poll(5000, () => execAsync(['bash', '-c', command])
|
||||
.then((output) => {
|
||||
resourceCircProg.css = `font-size: ${Number(output)}px;`;
|
||||
resourceLabel.label = `${Math.round(Number(output))}%`;
|
||||
widget.tooltipText = `${name}: ${Math.round(Number(output))}%`;
|
||||
}).catch(print))
|
||||
,
|
||||
});
|
||||
return widget;
|
||||
}
|
||||
|
||||
const BarGroup = ({ child }) => Widget.Box({
|
||||
className: 'bar-group-margin bar-sides',
|
||||
children: [
|
||||
@@ -166,6 +132,72 @@ const BarGroup = ({ child }) => Widget.Box({
|
||||
}),
|
||||
]
|
||||
});
|
||||
const BatteryModule = () => Stack({
|
||||
transition: 'slide_up_down',
|
||||
transitionDuration: 150,
|
||||
children: {
|
||||
'laptop': Box({
|
||||
className: 'spacing-h-5', children: [
|
||||
BarGroup({ child: Utilities() }),
|
||||
BarGroup({ child: BarBattery() }),
|
||||
]
|
||||
}),
|
||||
'desktop': BarGroup({
|
||||
child: Box({
|
||||
hexpand: true,
|
||||
hpack: 'center',
|
||||
className: 'spacing-h-5',
|
||||
children: [
|
||||
MaterialIcon('device_thermostat', 'small'),
|
||||
Label({
|
||||
label: 'Weather',
|
||||
})
|
||||
],
|
||||
setup: (self) => self.poll(900000, async (self) => {
|
||||
const WEATHER_CACHE_PATH = WEATHER_CACHE_FOLDER + '/wttr.in.txt';
|
||||
Utils.execAsync('curl ipinfo.io')
|
||||
.then(output => {
|
||||
return JSON.parse(output)['city'].toLowerCase();
|
||||
})
|
||||
.then((city) => execAsync(`curl https://wttr.in/${city}?format=j1`)
|
||||
.then(output => {
|
||||
const weather = JSON.parse(output);
|
||||
Utils.writeFile(JSON.stringify(weather), WEATHER_CACHE_PATH)
|
||||
.catch(print);
|
||||
const weatherCode = weather.current_condition[0].weatherCode;
|
||||
const weatherDesc = weather.current_condition[0].weatherDesc[0].value;
|
||||
const temperature = weather.current_condition[0].temp_C;
|
||||
const feelsLike = weather.current_condition[0].FeelsLikeC;
|
||||
const weatherSymbol = WEATHER_SYMBOL[WWO_CODE[weatherCode]];
|
||||
self.children[0].label = weatherSymbol;
|
||||
self.children[1].label = `${temperature}℃ • Feels like ${feelsLike}℃`;
|
||||
self.tooltipText = weatherDesc;
|
||||
}).catch((err) => {
|
||||
try { // Read from cache
|
||||
const weather = JSON.parse(
|
||||
Utils.readFile(WEATHER_CACHE_PATH)
|
||||
);
|
||||
const weatherCode = weather.current_condition[0].weatherCode;
|
||||
const weatherDesc = weather.current_condition[0].weatherDesc[0].value;
|
||||
const temperature = weather.current_condition[0].temp_C;
|
||||
const feelsLike = weather.current_condition[0].FeelsLikeC;
|
||||
const weatherSymbol = WEATHER_SYMBOL[WWO_CODE[weatherCode]];
|
||||
self.children[0].label = weatherSymbol;
|
||||
self.children[1].label = `${temperature}℃ • Feels like ${feelsLike}℃`;
|
||||
self.tooltipText = weatherDesc;
|
||||
} catch (err) {
|
||||
print(err);
|
||||
}
|
||||
}));
|
||||
}),
|
||||
})
|
||||
}),
|
||||
},
|
||||
setup: (stack) => Utils.timeout(10, () => {
|
||||
if (!Battery.available) stack.shown = 'desktop';
|
||||
else stack.shown = 'laptop';
|
||||
})
|
||||
})
|
||||
|
||||
const switchToRelativeWorkspace = async (self, num) => {
|
||||
try {
|
||||
@@ -184,28 +216,7 @@ export default () => Widget.EventBox({
|
||||
className: 'spacing-h-5',
|
||||
children: [
|
||||
BarGroup({ child: BarClock() }),
|
||||
Stack({
|
||||
transition: 'slide_up_down',
|
||||
transitionDuration: 150,
|
||||
items: [
|
||||
['laptop', Box({
|
||||
className: 'spacing-h-5', children: [
|
||||
BarGroup({ child: Utilities() }),
|
||||
BarGroup({ child: BarBattery() }),
|
||||
]
|
||||
})],
|
||||
['desktop', Box({
|
||||
className: 'spacing-h-5', children: [
|
||||
BarGroup({ child: BarResource('RAM usage', 'memory', `free | awk '/^Mem/ {printf("%.2f\\n", ($3/$2) * 100)}'`), }),
|
||||
BarGroup({ child: BarResource('Swap usage', 'swap_horiz', `free | awk '/^Swap/ {printf("%.2f\\n", ($3/$2) * 100)}'`), }),
|
||||
]
|
||||
})],
|
||||
],
|
||||
setup: (stack) => Utils.timeout(10, () => {
|
||||
if (!Battery.available) stack.shown = 'desktop';
|
||||
else stack.shown = 'laptop';
|
||||
})
|
||||
})
|
||||
BatteryModule(),
|
||||
]
|
||||
})
|
||||
});
|
||||
|
||||
@@ -4,11 +4,12 @@ const Cairo = imports.cairo;
|
||||
const Pango = imports.gi.Pango;
|
||||
const PangoCairo = imports.gi.PangoCairo;
|
||||
import App from 'resource:///com/github/Aylur/ags/app.js';
|
||||
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js'
|
||||
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
|
||||
const { Box, DrawingArea, EventBox } = Widget;
|
||||
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
|
||||
|
||||
const NUM_OF_WORKSPACES = 10;
|
||||
const NUM_OF_WORKSPACES_SHOWN = 10; // Limit = 53 I think
|
||||
const dummyWs = Box({ className: 'bar-ws' }); // Not shown. Only for getting size props
|
||||
const dummyActiveWs = Box({ className: 'bar-ws bar-ws-active' }); // Not shown. Only for getting size props
|
||||
const dummyOccupiedWs = Box({ className: 'bar-ws bar-ws-occupied' }); // Not shown. Only for getting size props
|
||||
@@ -16,38 +17,40 @@ const dummyOccupiedWs = Box({ className: 'bar-ws bar-ws-occupied' }); // Not sho
|
||||
// Font size = workspace id
|
||||
const WorkspaceContents = (count = 10) => {
|
||||
return DrawingArea({
|
||||
css: `transition: 90ms cubic-bezier(0.1, 1, 0, 1);`,
|
||||
// css: `transition: 90ms cubic-bezier(0.1, 1, 0, 1);`,
|
||||
attribute: {
|
||||
initialized: false,
|
||||
workspaceMask: 0,
|
||||
updateMask: (self) => {
|
||||
if (self.attribute.initialized) return; // We only need this to run once
|
||||
const offset = Math.floor((Hyprland.active.workspace.id - 1) / count) * NUM_OF_WORKSPACES_SHOWN;
|
||||
// if (self.attribute.initialized) return; // We only need this to run once
|
||||
const workspaces = Hyprland.workspaces;
|
||||
let workspaceMask = 0;
|
||||
for (let i = 0; i < workspaces.length; i++) {
|
||||
const ws = workspaces[i];
|
||||
if (ws.id <= 0) continue; // Ignore scratchpads
|
||||
if (ws.id > count) return; // Not rendered
|
||||
if (workspaces[i].windows > 0) {
|
||||
workspaceMask |= (1 << ws.id);
|
||||
}
|
||||
if (ws.id <= offset || ws.id > offset + count) continue; // Out of range, ignore
|
||||
if (workspaces[i].windows > 0)
|
||||
workspaceMask |= (1 << (ws.id - offset));
|
||||
}
|
||||
// console.log('Mask:', workspaceMask.toString(2));
|
||||
self.attribute.workspaceMask = workspaceMask;
|
||||
self.attribute.initialized = true;
|
||||
// self.attribute.initialized = true;
|
||||
self.queue_draw();
|
||||
},
|
||||
toggleMask: (self, occupied, name) => {
|
||||
if (occupied) self.attribute.workspaceMask |= (1 << parseInt(name));
|
||||
else self.attribute.workspaceMask &= ~(1 << parseInt(name));
|
||||
self.queue_draw();
|
||||
},
|
||||
},
|
||||
setup: (area) => area
|
||||
.hook(Hyprland.active.workspace, (area) =>
|
||||
area.setCss(`font-size: ${Hyprland.active.workspace.id}px;`)
|
||||
)
|
||||
.hook(Hyprland.active.workspace, (self) => {
|
||||
self.setCss(`font-size: ${(Hyprland.active.workspace.id - 1) % count + 1}px;`);
|
||||
})
|
||||
.hook(Hyprland, (self) => self.attribute.updateMask(self), 'notify::workspaces')
|
||||
.hook(Hyprland, (self, name) => self.attribute.toggleMask(self, true, name), 'workspace-added')
|
||||
.hook(Hyprland, (self, name) => self.attribute.toggleMask(self, false, name), 'workspace-removed')
|
||||
.on('draw', Lang.bind(area, (area, cr) => {
|
||||
const offset = Math.floor((Hyprland.active.workspace.id - 1) / count) * NUM_OF_WORKSPACES_SHOWN;
|
||||
|
||||
const allocation = area.get_allocation();
|
||||
const { width, height } = allocation;
|
||||
|
||||
@@ -113,12 +116,12 @@ const WorkspaceContents = (count = 10) => {
|
||||
}
|
||||
else
|
||||
cr.setSourceRGBA(wsfg.red, wsfg.green, wsfg.blue, wsfg.alpha);
|
||||
layout.set_text(`${i}`, -1);
|
||||
|
||||
layout.set_text(`${i + offset}`, -1);
|
||||
const [layoutWidth, layoutHeight] = layout.get_pixel_size();
|
||||
const x = -workspaceRadius + (workspaceDiameter * i) - (layoutWidth / 2);
|
||||
const y = (height - layoutHeight) / 2;
|
||||
cr.moveTo(x, y);
|
||||
// cr.showText(text);
|
||||
PangoCairo.show_layout(cr, layout);
|
||||
cr.stroke();
|
||||
}
|
||||
@@ -142,16 +145,17 @@ export default () => EventBox({
|
||||
onScrollDown: () => Hyprland.sendMessage(`dispatch workspace +1`),
|
||||
onMiddleClickRelease: () => App.toggleWindow('overview'),
|
||||
onSecondaryClickRelease: () => App.toggleWindow('osk'),
|
||||
attribute: { clicked: false },
|
||||
attribute: {
|
||||
clicked: false,
|
||||
ws_group: 0,
|
||||
},
|
||||
child: Box({
|
||||
homogeneous: true,
|
||||
className: 'bar-group-margin',
|
||||
children: [Box({
|
||||
className: 'bar-group bar-group-standalone bar-group-pad',
|
||||
css: 'min-width: 2px;',
|
||||
children: [
|
||||
WorkspaceContents(10),
|
||||
]
|
||||
children: [WorkspaceContents(NUM_OF_WORKSPACES_SHOWN)],
|
||||
})]
|
||||
}),
|
||||
setup: (self) => {
|
||||
@@ -160,16 +164,18 @@ export default () => EventBox({
|
||||
if (!self.attribute.clicked) return;
|
||||
const [_, cursorX, cursorY] = event.get_coords();
|
||||
const widgetWidth = self.get_allocation().width;
|
||||
const wsId = Math.ceil(cursorX * NUM_OF_WORKSPACES / widgetWidth);
|
||||
Hyprland.sendMessage(`dispatch workspace ${wsId}`)
|
||||
const wsId = Math.ceil(cursorX * NUM_OF_WORKSPACES_SHOWN / widgetWidth);
|
||||
Utils.execAsync([`${App.configDir}/scripts/hyprland/workspace_action.sh`, 'workspace', `${wsId}`]);
|
||||
})
|
||||
self.on('button-press-event', (self, event) => {
|
||||
if (!(event.get_button()[1] === 1)) return; // We're only interested in left-click here
|
||||
self.attribute.clicked = true;
|
||||
const [_, cursorX, cursorY] = event.get_coords();
|
||||
const widgetWidth = self.get_allocation().width;
|
||||
const wsId = Math.ceil(cursorX * NUM_OF_WORKSPACES / widgetWidth);
|
||||
Hyprland.sendMessage(`dispatch workspace ${wsId}`);
|
||||
// const wsId = Math.ceil(cursorX * NUM_OF_WORKSPACES_PER_GROUP / widgetWidth) + self.attribute.ws_group * NUM_OF_WORKSPACES_PER_GROUP;
|
||||
// Hyprland.sendMessage(`dispatch workspace ${wsId}`);
|
||||
const wsId = Math.ceil(cursorX * NUM_OF_WORKSPACES_SHOWN / widgetWidth);
|
||||
Utils.execAsync([`${App.configDir}/scripts/hyprland/workspace_action.sh`, 'workspace', `${wsId}`]);
|
||||
})
|
||||
self.on('button-release-event', (self) => self.attribute.clicked = false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user