forked from Shinonome/dots-hyprland
Initial commit
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
const { Gdk, Gtk } = imports.gi;
|
||||
const Lang = imports.lang;
|
||||
import { App, Service, Utils, Widget, SCREEN_HEIGHT, SCREEN_WIDTH } from '../../imports.js';
|
||||
const { execAsync, exec } = Utils;
|
||||
const { Box, Label } = Widget;
|
||||
|
||||
const NUM_OF_VERTICES = 30;
|
||||
const NUM_OF_EDGES = 29;
|
||||
// Vertices
|
||||
var vertices = [];
|
||||
for (var i = 0; i < NUM_OF_VERTICES; i++) {
|
||||
vertices.push([
|
||||
Math.floor(Math.random() * SCREEN_WIDTH),
|
||||
Math.floor(Math.random() * SCREEN_HEIGHT)
|
||||
]);
|
||||
}
|
||||
// Edges
|
||||
function generateRandomEdges(numVertices, numEdges) { // TODO: make sure whole graph is connected
|
||||
var edges = new Set();
|
||||
var vertices = [];
|
||||
|
||||
// Generate vertices
|
||||
for (var i = 0; i < numVertices; i++) {
|
||||
vertices.push(i);
|
||||
}
|
||||
|
||||
// Generate random distinct edges
|
||||
while (edges.size < numEdges) {
|
||||
var randomVertex1 = vertices[Math.floor(Math.random() * numVertices)];
|
||||
var randomVertex2 = vertices[Math.floor(Math.random() * numVertices)];
|
||||
|
||||
// Ensure the two vertices are distinct and the edge doesn't already exist
|
||||
if (randomVertex1 !== randomVertex2) {
|
||||
var edge = [randomVertex1, randomVertex2].sort();
|
||||
edges.add(edge.join(','));
|
||||
}
|
||||
}
|
||||
|
||||
return Array.from(edges).map(edge => edge.split(',').map(Number));
|
||||
}
|
||||
|
||||
var edges = generateRandomEdges(NUM_OF_VERTICES, NUM_OF_EDGES);
|
||||
|
||||
export default () => Box({
|
||||
hpack: 'fill',
|
||||
vpack: 'fill',
|
||||
homogeneous: true,
|
||||
children: [
|
||||
Widget.DrawingArea({
|
||||
className: 'bg-graph',
|
||||
setup: (area) => {
|
||||
area.connect('draw', Lang.bind(area, (area, cr) => {
|
||||
// area.set_size_request(SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
// console.log('allocated width/height:', area.get_allocated_width(), '/', area.get_allocated_height())
|
||||
const styleContext = area.get_style_context();
|
||||
const color = styleContext.get_property('color', Gtk.StateFlags.NORMAL);
|
||||
const backgroundColor = styleContext.get_property('background-color', Gtk.StateFlags.NORMAL);
|
||||
const radius = area.get_style_context().get_property('border-radius', Gtk.StateFlags.NORMAL);
|
||||
const borderWidth = area.get_style_context().get_border(Gtk.StateFlags.NORMAL).left; // ur going to write border-width: something anyway
|
||||
|
||||
cr.setSourceRGBA(backgroundColor.red, backgroundColor.green, backgroundColor.blue, backgroundColor.alpha);
|
||||
cr.rectangle(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)
|
||||
cr.fill();
|
||||
cr.setSourceRGBA(color.red, color.green, color.blue, color.alpha);
|
||||
// Draw edges
|
||||
cr.setLineWidth(borderWidth);
|
||||
console.log("line width:", borderWidth);
|
||||
for (var i = 0; i < NUM_OF_EDGES; i++) {
|
||||
console.log(vertices[edges[i][0]][0], vertices[edges[i][0]][1], '->', vertices[edges[i][1]][0], vertices[edges[i][1]][1])
|
||||
cr.moveTo(vertices[edges[i][0]][0], vertices[edges[i][0]][1]);
|
||||
cr.lineTo(vertices[edges[i][1]][0], vertices[edges[i][1]][1]);
|
||||
cr.stroke();
|
||||
}
|
||||
// Draw vertices
|
||||
for (var i = 0; i < NUM_OF_VERTICES; i++) {
|
||||
cr.arc(vertices[i][0], vertices[i][1], radius, 0, 2 * Math.PI)
|
||||
cr.fill()
|
||||
}
|
||||
}))
|
||||
}
|
||||
})
|
||||
]
|
||||
})
|
||||
@@ -0,0 +1,27 @@
|
||||
const { Gdk, Gtk } = imports.gi;
|
||||
import { App, Service, Utils, Widget } from '../../imports.js';
|
||||
const { execAsync, exec } = Utils;
|
||||
|
||||
import TimeAndLaunchesWidget from './timeandlaunches.js'
|
||||
import SystemWidget from './system.js'
|
||||
import GraphWidget from './graph.js'
|
||||
|
||||
export default () => Widget.Window({
|
||||
name: 'desktopbackground',
|
||||
anchor: ['top', 'bottom', 'left', 'right'],
|
||||
layer: 'background',
|
||||
exclusivity: 'normal',
|
||||
visible: true,
|
||||
child: Widget.Overlay({
|
||||
child: Widget.Box({
|
||||
hexpand: true,
|
||||
vexpand: true,
|
||||
}),
|
||||
overlays: [
|
||||
// GraphWidget(),
|
||||
TimeAndLaunchesWidget(),
|
||||
SystemWidget(),
|
||||
],
|
||||
setup: (self) => self.set_overlay_pass_through(self.get_children()[1], true),
|
||||
}),
|
||||
});
|
||||
@@ -0,0 +1,151 @@
|
||||
import { App, Service, Utils, Widget } from '../../imports.js';
|
||||
const { execAsync, exec } = Utils;
|
||||
const { Box, EventBox, Label, Revealer, Overlay } = Widget;
|
||||
import { AnimatedCircProg } from '../../lib/animatedcircularprogress.js'
|
||||
import { MaterialIcon } from '../../lib/materialicon.js';
|
||||
|
||||
const ResourceValue = (name, icon, interval, valueUpdateCmd, displayFunc, props = {}) => Box({
|
||||
...props,
|
||||
className: 'bg-system-bg txt',
|
||||
children: [
|
||||
Revealer({
|
||||
transition: 'slide_left',
|
||||
transitionDuration: 200,
|
||||
child: Box({
|
||||
vpack: 'center',
|
||||
vertical: true,
|
||||
className: 'margin-right-15',
|
||||
children: [
|
||||
Label({
|
||||
xalign: 1,
|
||||
className: 'txt-small txt',
|
||||
label: `${name}`,
|
||||
}),
|
||||
Label({
|
||||
xalign: 1,
|
||||
className: 'titlefont txt-norm txt-onSecondaryContainer',
|
||||
connections: [[interval, (label) => displayFunc(label)]]
|
||||
})
|
||||
]
|
||||
})
|
||||
}),
|
||||
Overlay({
|
||||
child: AnimatedCircProg({
|
||||
className: 'bg-system-circprog',
|
||||
connections: [[interval, (self) => {
|
||||
execAsync(['bash', '-c', `${valueUpdateCmd}`]).then((newValue) => {
|
||||
self.css = `font-size: ${Math.round(newValue)}px;`
|
||||
}).catch(print);
|
||||
}]]
|
||||
}),
|
||||
overlays: [
|
||||
MaterialIcon(`${icon}`, 'hugeass'),
|
||||
],
|
||||
setup: self => self.set_overlay_pass_through(self.get_children()[1], true),
|
||||
}),
|
||||
]
|
||||
})
|
||||
|
||||
const resources = Box({
|
||||
vpack: 'fill',
|
||||
vertical: true,
|
||||
className: 'spacing-v-15',
|
||||
children: [
|
||||
ResourceValue('Memory', 'memory', 10000, `free | awk '/^Mem/ {printf("%.2f\\n", ($3/$2) * 100)}'`,
|
||||
(label) => {
|
||||
execAsync(['bash', '-c', `free -h | awk '/^Mem/ {print $3 " / " $2}' | sed 's/Gi/Gib/g'`])
|
||||
.then((output) => {
|
||||
label.label = `${output}`
|
||||
}).catch(print);
|
||||
}, { hpack: 'end' }),
|
||||
ResourceValue('Swap', 'swap_horiz', 10000, `free | awk '/^Swap/ {printf("%.2f\\n", ($3/$2) * 100)}'`,
|
||||
(label) => {
|
||||
execAsync(['bash', '-c', `free -h | awk '/^Swap/ {print $3 " / " $2}' | sed 's/Gi/Gib/g'`])
|
||||
.then((output) => {
|
||||
label.label = `${output}`
|
||||
}).catch(print);
|
||||
}, { hpack: 'end' }),
|
||||
ResourceValue('Disk space', 'hard_drive_2', 3600000, `echo $(df --output=pcent / | tr -dc '0-9')`,
|
||||
(label) => {
|
||||
execAsync(['bash', '-c', `df -h --output=avail / | awk 'NR==2{print $1}'`])
|
||||
.then((output) => {
|
||||
label.label = `${output} available`
|
||||
}).catch(print);
|
||||
}, { hpack: 'end' }),
|
||||
]
|
||||
});
|
||||
|
||||
const distroAndVersion = Box({
|
||||
vertical: true,
|
||||
children: [
|
||||
Box({
|
||||
hpack: 'end',
|
||||
children: [
|
||||
Label({
|
||||
className: 'bg-distro-txt',
|
||||
xalign: 0,
|
||||
label: 'Hyping on ',
|
||||
}),
|
||||
Label({
|
||||
className: 'bg-distro-name',
|
||||
xalign: 0,
|
||||
label: '<distro>',
|
||||
setup: (label) => {
|
||||
execAsync([`grep`, `-oP`, `PRETTY_NAME="\\K[^"]+`, `/etc/os-release`]).then(distro => {
|
||||
label.label = distro;
|
||||
}).catch(print);
|
||||
},
|
||||
}),
|
||||
]
|
||||
}),
|
||||
Box({
|
||||
hpack: 'end',
|
||||
children: [
|
||||
Label({
|
||||
className: 'bg-distro-txt',
|
||||
xalign: 0,
|
||||
label: 'with ',
|
||||
}),
|
||||
Label({
|
||||
className: 'bg-distro-name',
|
||||
xalign: 0,
|
||||
label: '<version>',
|
||||
setup: (label) => {
|
||||
execAsync([`bash`, `-c`, `hyprctl version | grep -oP "Tag: v\\K\\d+\\.\\d+\\.\\d+"`]).then(distro => {
|
||||
label.label = `Hyprland ${distro}`;
|
||||
}).catch(print);
|
||||
},
|
||||
}),
|
||||
]
|
||||
})
|
||||
]
|
||||
})
|
||||
|
||||
export default () => Box({
|
||||
hpack: 'end',
|
||||
vpack: 'end',
|
||||
children: [
|
||||
EventBox({
|
||||
child: Box({
|
||||
hpack: 'end',
|
||||
vpack: 'end',
|
||||
className: 'bg-distro-box spacing-v-20',
|
||||
vertical: true,
|
||||
children: [
|
||||
resources,
|
||||
distroAndVersion,
|
||||
]
|
||||
}),
|
||||
onPrimaryClickRelease: () => {
|
||||
const kids = resources.get_children();
|
||||
|
||||
kids.forEach((child, i) => {
|
||||
child.get_children()[0].revealChild = !child.get_children()[0].revealChild;
|
||||
});
|
||||
},
|
||||
})
|
||||
],
|
||||
})
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
const { GLib, Gio } = imports.gi;
|
||||
import { App, Service, Utils, Widget } from '../../imports.js';
|
||||
import Variable from 'resource:///com/github/Aylur/ags/variable.js';
|
||||
const { execAsync, exec } = Utils;
|
||||
const { Box, Label, Button, Revealer, EventBox } = Widget;
|
||||
import { setupCursorHover } from '../../lib/cursorhover.js';
|
||||
|
||||
import { quickLaunchItems } from '../../data/quicklaunches.js'
|
||||
|
||||
const TimeAndDate = () => Box({
|
||||
vertical: true,
|
||||
className: 'spacing-v--5',
|
||||
children: [
|
||||
Label({
|
||||
className: 'bg-time-clock',
|
||||
xalign: 0,
|
||||
connections: [[5000, label => {
|
||||
label.label = GLib.DateTime.new_now_local().format("%H:%M");
|
||||
}]],
|
||||
}),
|
||||
Label({
|
||||
className: 'bg-time-date',
|
||||
xalign: 0,
|
||||
connections: [[5000, label => {
|
||||
label.label = GLib.DateTime.new_now_local().format("%A, %d/%m/%Y");
|
||||
}]],
|
||||
}),
|
||||
]
|
||||
})
|
||||
|
||||
const QuickLaunches = () => Box({
|
||||
vertical: true,
|
||||
className: 'spacing-v-10',
|
||||
children: [
|
||||
Label({
|
||||
xalign: 0,
|
||||
className: 'bg-quicklaunch-title',
|
||||
label: 'Quick Launches',
|
||||
}),
|
||||
Box({
|
||||
hpack: 'start',
|
||||
className: 'spacing-h-5',
|
||||
children: quickLaunchItems.map((item, i) => Button({
|
||||
onClicked: () => {
|
||||
execAsync(['bash', '-c', `${item["command"]}`]).catch(print);
|
||||
},
|
||||
className: 'bg-quicklaunch-btn',
|
||||
child: Label({
|
||||
label: `${ item["name"]}`,
|
||||
}),
|
||||
setup: (self) => {
|
||||
setupCursorHover(self);
|
||||
}
|
||||
})),
|
||||
})
|
||||
]
|
||||
})
|
||||
|
||||
export default () => Box({
|
||||
hpack: 'start',
|
||||
vpack: 'end',
|
||||
vertical: true,
|
||||
className: 'bg-time-box spacing-v-20',
|
||||
children: [
|
||||
TimeAndDate(),
|
||||
// QuickLaunches(),
|
||||
],
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user