This commit is contained in:
sankalp committed 2024-06-27 13:09:07 +05:45
1 parent 5e7468c820
commit f5b627aa60
13 files changed
+443 -205

No files matched your search

+168 -7
View File
@@ -1,12 +1,173 @@
import { PageTitle } from "./main";
import { type BluetoothDevice } from "types/service/bluetooth";
import Gtk from "gi://Gtk?version=3.0"
import { timeout } from "resource:///com/github/Aylur/ags/utils.js";
const bluetooth = await Service.import("bluetooth")
export const Bluetooth = () => Widget.Box({
hexpand: true,
vexpand: true,
child: Widget.Label({
label: "Not implemented yet",
const HpackStartLabel = (label: string) => Widget.Label({
label: label,
hpack: "start"
})
const BluetoothToggle = () => Widget.EventBox({
child: Widget.Box({
class_name: "bluetooth_toggle",
children: [
Widget.Box({
vertical: true,
hexpand: true,
children: [
Widget.Label({
hpack: "start",
class_name: "title",
label: "Enabled"
}),
// Widget.Label({
// hpack: "start",
// class_name: "description",
// label: "Idk"
// })
]
}),
Widget.Switch({
vexpand: false,
valign: Gtk.Align.CENTER,
hpack: "end",
on_activate: self => {
if (self.state != bluetooth.enabled)
bluetooth.enabled = self.state;
},
state: bluetooth.bind("enabled"),
})
]
}),
on_secondary_click: (self, event) => {
Widget.Menu({
children: [Widget.MenuItem({
child: HpackStartLabel("Open blueman-manager"),
on_activate: () => {
Utils.execAsync("blueman-manager").catch(print);
}
})]
}).popup_at_pointer(event);
}
})
const DeviceMenu = (device: BluetoothDevice) => {
if (device.connecting) {
return undefined
}
return Widget.Menu({
children: [
!device.connected
? Widget.MenuItem({
child: HpackStartLabel("Connect"),
on_activate: () => {
device.setConnection(true);
}
})
: Widget.MenuItem({
child: HpackStartLabel("Disconnect"),
on_activate: () => {
device.setConnection(false);
},
}),
Widget.MenuItem({
child: HpackStartLabel("Copy Address"),
on_activate: () => {
Utils.execAsync(["wl-copy", device.address])
},
})
]
})
})
}
const DeviceItem = (device: BluetoothDevice) => Widget.Button({
class_name: "device",
// on_primary_click: () => {
// if (!connected)
// Utils.execAsync(`nmcli device wifi connect '${access_point.ssid}'`)
// .catch(print);
// else if (is_saved)
// Utils.execAsync(`${App.configDir}/scripts/network.sh --edit ${access_point.ssid}`)
// .catch(print);
// },
on_secondary_click: (self, event) => {
DeviceMenu(device)?.popup_at_pointer(event);
},
child: Widget.Box({
class_name: "device_box",
children: [
Widget.Icon({
icon: `${device.icon_name}-symbolic`,
hpack: "center",
vpack: "center",
size: 20
}),
// @ts-ignore
Widget.Box({
vertical: true,
vpack: "center",
children: [
Widget.Label({
class_name: "title",
label: device.name.trim(),
hpack: "start",
}),
(device.connecting)
? Widget.Label({
class_name: "description",
label: device.connected ? "Disconnecting..." : "Connecting...",
hpack: "start"
})
: (device.connected)
? Widget.Label({
class_name: "description",
label: "Active",
hpack: "start"
})
: undefined
]
})
]
}),
setup: self => {
self.toggleClassName("active", device.connected);
}
})
function DeviceList() {
return Widget.Box({
vertical: true,
attribute: {
'updateDeviceList': (self) => {
const devices = bluetooth.devices || [];
self.children = Object.values(devices)
.sort((a: BluetoothDevice, b: BluetoothDevice) => {
if (a.connected) return -1;
if (b.connected) return 1;
return 0;
})
.filter((n: BluetoothDevice) => n.device.name !== null)
.map((n: BluetoothDevice) => DeviceItem(n));
},
},
className: 'device_list',
setup: (self) => self.hook(bluetooth, self.attribute.updateDeviceList),
})
}
export const Bluetooth = () => Widget.Scrollable({
hscroll: "never",
child: Widget.Box({
hexpand: true,
vexpand: true,
vertical: true,
children: [
BluetoothToggle(),
DeviceList()
]
})
})
+37 -41
View File
@@ -63,7 +63,7 @@ const WifiNetwork = (access_point: AccessPoint) => {
.catch(print);
},
on_secondary_click: () => {
if(!connected && is_saved)
if (!connected && is_saved)
Utils.execAsync(`${App.configDir}/scripts/network.sh --edit ${access_point.ssid}`)
.catch(print);
},
@@ -108,44 +108,41 @@ const WifiNetwork = (access_point: AccessPoint) => {
}
const WifiToggle = () => {
const box = Widget.Box({
class_name: "wifi_toggle",
children: [
Widget.Box({
vertical: true,
hexpand: true,
children: [
Widget.Label({
hpack: "start",
class_name: "title",
label: "Wi-Fi"
}),
Widget.Label({
hpack: "start",
class_name: "description",
label: "Find and connect to Wi-Fi networks"
})
]
}),
Widget.Switch({
vexpand: false,
valign: Gtk.Align.CENTER,
hpack: "end",
on_activate(self) {
timeout(5, () => {
if (network.wifi.enabled != self.active)
network.wifi.enabled = self.active
})
},
active: Variable(false, {
poll: [500, () => network.wifi.enabled]
}).bind()
})
]
})
return box
}
const WifiToggle = () => Widget.Box({
class_name: "wifi_toggle",
children: [
Widget.Box({
vertical: true,
hexpand: true,
children: [
Widget.Label({
hpack: "start",
class_name: "title",
label: "Wi-Fi"
}),
Widget.Label({
hpack: "start",
class_name: "description",
label: "Find and connect to Wi-Fi networks"
})
]
}),
Widget.Switch({
vexpand: false,
valign: Gtk.Align.CENTER,
hpack: "end",
on_activate(self) {
timeout(5, () => {
if (network.wifi.enabled != self.active)
network.wifi.enabled = self.active
})
},
active: Variable(false, {
poll: [500, () => network.wifi.enabled]
}).bind()
})
]
})
function WifiList() {
return Widget.Box({
@@ -197,7 +194,6 @@ const nm_applet_required = () => Widget.Box({
})
export function Network() {
WifiScan()
const box = Widget.Box({
vertical: true,
children: [
@@ -211,4 +207,4 @@ export function Network() {
child: box,
vexpand: true
})
}
}
+4 -3
View File
@@ -2,7 +2,8 @@
// Import
import Gdk from 'gi://Gdk';
// widgets
import { Bar, BarCornerTopLeft, BarCornerTopRight } from './modules/bar.ts';
//import { Bar, BarCornerTopLeft, BarCornerTopRight } from './modules/bar.ts';
import { Bar } from './modules/bar.ts';
import { Notifications } from "./modules/notificationPopups.ts"
import { applauncher } from "./modules/applauncher.js"
import { media } from "./modules/media.ts"
@@ -25,8 +26,8 @@ function forMonitorsAsync(widget: (index: number) => Promise<Window<any, any>>)
const Windows = () => [
forMonitors(Notifications),
forMonitors(BarCornerTopLeft),
forMonitors(BarCornerTopRight),
//forMonitors(BarCornerTopLeft),
//forMonitors(BarCornerTopRight),
media,
applauncher,
cliphist,
+1 -1
View File
@@ -78,7 +78,7 @@ function AppItem(app: Application): Box<any, any> {
button.connect('clicked', () => {
clickCount++;
if (clickCount === 2) {
if (clickCount === 1) {
incrementLaunchCount(app.name);
App.closeWindow(WINDOW_NAME);
app.launch();
+42 -6
View File
@@ -14,6 +14,7 @@ import Button from "types/widgets/button.js"
import Icon from "types/widgets/icon.js"
import { FileEnumerator, FileInfo } from "types/@girs/gio-2.0/gio-2.0.cjs"
const mpris = await Service.import("mpris")
const bluetooth = await Service.import("bluetooth")
function checkKeymap() {
@@ -162,7 +163,7 @@ function BatteryLabel() {
function SysTray() {
const items = systemtray.bind("items")
.as(items => items.map(item => {
if (item.id.trim() != "nm-applet") {
if (item.id.trim() != "nm-applet" && item.id.trim() != "blueman") {
return Widget.Button({
child: Widget.Icon({ icon: item.bind("icon") }),
on_primary_click: (_, event) => item.activate(event),
@@ -198,9 +199,10 @@ function AppLauncher() {
}
function Wifi() {
const button = Widget.Button({
class_name: "bar_wifi awesome_icon",
return Widget.Button({
class_name: "bar_wifi icon",
on_primary_click: () => {
OpenSettings("network")
},
@@ -225,11 +227,45 @@ function Wifi() {
self.child.icon = "network-wireless-offline-symbolic";
}
})
return button
}
function Bluetooth() {
return Widget.Button({
class_name: "bar_bluetooth icon",
on_primary_click: () => {
OpenSettings("bluetooth")
},
on_secondary_click: (_, event) => {
const blueman = systemtray.items.find(item => item.id == "blueman")
if (blueman) {
blueman.openMenu(event)
} else {
Utils.execAsync("blueman-manager").catch(print)
}
},
child: Widget.Icon({
icon: "bluetooth-disabled-symbolic"
}),
}).hook(bluetooth, self => {
if (bluetooth.enabled) {
self.child.icon = "bluetooth-active-symbolic";
} else {
self.child.icon = "bluetooth-disabled-symbolic";
}
})
}
const Applets = () => Widget.Box({
class_name: "bar_applets",
spacing: 5,
children: [
Bluetooth(),
Wifi()
]
})
function MediaPlayer() {
let metadata = mpris.players[0]?.metadata;
const button = Widget.Button({
@@ -412,7 +448,7 @@ function Right() {
KeyboardLayout(),
BatteryLabel(),
SysTray(),
Wifi(),
Applets(),
Clock(),
OpenSideBar()
],
+2
View File
@@ -32,12 +32,14 @@ function Player(player: MprisPlayer) {
wrap: true,
hpack: "start",
label: player.bind("track_title"),
use_markup: false
})
const artist = Widget.Label({
class_name: "artist",
wrap: true,
hpack: "start",
use_markup: false,
label: player.bind("track_artists").transform(a => a.join(", ")),
})
-114
View File
@@ -1,114 +0,0 @@
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
const prefix = "100" // Identifier for minimized workspace
function getMinimizedWS(maximizedWS){
return parseInt(prefix + maximizedWS)
}
function getMaximizedWS(minimizedWS){
return parseInt(minimizedWS.toString().substring(prefix.length))
}
function isMinimized(ws){
ws = ws.toString()
if (ws.length > 3 || ws.slice(0, prefix.length) == prefix){
return true
}
else{
return false
}
}
const focusClient = (client) => {
// If minimized
if (isMinimized(client.workspace.id)){
var maximizedWS = getMaximizedWS(client.workspace.id)
Hyprland.messageAsync(`dispatch movetoworkspacesilent ${maximizedWS},address:${client.address}`)
// Focus window
//Hyprland.messageAsync(`dispatch focuswindow address:${client.address}`)
Hyprland.messageAsync(`dispatch alterzorder top,address:${client.address}`)
}
// If maximized
else{
var minimizedWS = getMinimizedWS(client.workspace.id)
Hyprland.messageAsync(`dispatch movetoworkspacesilent ${minimizedWS},address:${client.address}`)
}
}
const Client = (client = null) => Widget.Box({
// Attributes
attribute: {
returnWS: client.workspace,
},
})
const appButton = (client = null) => Widget.Button({
class_name: "dock-button",
tooltip_text: client.title,
on_primary_click: () => focusClient(client),
child: Widget.Box({
vertical: true,
children: [
Widget.Box({
children: [
Widget.Box({
class_name: "dock-app-indicator",
vpack: "center",
setup: (self) => {
self.hook(Hyprland, () => {
//self.toggleClassName("dock-button-current", Hyprland.active.client.address === client.address)
self.toggleClassName("dock-app-indicator-active", Hyprland.active.client.address === client.address)
}, 'event')
}
}),
/*
Widget.Icon({
class_name: 'client-icon',
css: 'font-size: 3rem;',
icon: client.class,
}),
*/
],
}),
Widget.Label({
label: client.class,
truncate: 'end',
maxWidthChars: 8,
})
],
}),
});
const clientList = Widget.Scrollable({
hscroll: "never",
child: Widget.Box({
class_name: "dock-container",
css: "min-height: 6rem;",
css: "min-width: 6rem;",
vertical: true,
}).hook(Hyprland, self => {
//check if ws is empty
self.children = Hyprland.clients.filter(client => client.class != "" && (client.workspace.id === Hyprland.active.workspace.id || client.workspace.id === getMinimizedWS(Hyprland.active.workspace.id))).map(client => {
return appButton(client)
})
})
})
export const Dock = (monitor = 0) => Widget.Window({
name: `Dock`, // name has to be unique
monitor,
visible: false,
//margins: [4,64,4,64],
//margins: [8,8,8,8],
anchor: ['bottom', 'left', 'top'],
exclusivity: 'exclusive',
child: clientList,
});
+3 -2
View File
@@ -69,6 +69,7 @@ export const Notification = (notification: NotificationType, dismiss = true) =>
lines: 1,
xalign: 0,
hexpand: true,
tooltip_text: notification.summary
}),
Widget.Label({
class_name: "notification-time",
@@ -227,8 +228,8 @@ export function NotificationPopups(
if (!original)
return
original.attribute.count--;
if (original.attribute.count <= 0) {
original.attribute.destroyWithAnims()
if (original?.attribute.count <= 0) {
original?.attribute.destroyWithAnims()
}
}
+45 -20
View File
@@ -122,15 +122,35 @@ function IconAndName({ label, icon, padding = "0.3em", arrow = false }) {
}
function isScreenRecordingOn() {
// Check if wf-recorder is running
// Bash command outputs 0 if yes or 1 if no
let state = Utils.execAsync('bash -c "pidof wf-recorder > /dev/null; echo $?"')
if (state == "0"){
return true
}
else{
return false
}
let state = Utils.execAsync('bash -c "pidof wf-recorder > /dev/null; echo $?"');
return state == "0";
}
let recordingStartTime = null;
let recordingInterval = null;
function formatTime(ms) {
let totalSeconds = Math.floor(ms / 1000);
let hours = Math.floor(totalSeconds / 3600);
let minutes = Math.floor((totalSeconds % 3600) / 60);
let seconds = totalSeconds % 60;
return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
}
function startRecordingTimer(button) {
recordingStartTime = Date.now();
recordingInterval = setInterval(() => {
let elapsedTime = Date.now() - recordingStartTime;
button.label = formatTime(elapsedTime);
}, 1000);
}
function stopRecordingTimer(button) {
clearInterval(recordingInterval);
recordingStartTime = null;
recordingInterval = null;
button.label = 'Start Recording';
}
function Page1() {
@@ -216,6 +236,7 @@ function Page1() {
})
]
}),
Widget.Box({
orientation: Gtk.Orientation.HORIZONTAL,
spacing: 2.5,
@@ -226,20 +247,24 @@ function Page1() {
class_name: screen_recorder.bind()
.as(bool => bool ? "management_button active" : "management_button"),
on_clicked: (self) => {
screen_recorder.setValue(!screen_recorder.value)
// Adjust indicator
let isRecording = isScreenRecordingOn()
self.toggleClassName("active-button", !isRecording) // Toggles active indicator
self.toggleClassName("recording", !isRecording) // Toggles active indicator
let isRecording = isScreenRecordingOn();
// Starts screen recorder if not running
// Stops screen recorder if running
Utils.execAsync(['bash', '-c', 'mkdir ~/Videos/Screenrecordings; pkill wf-recorder; if [ $? -ne 0 ]; then wf-recorder -f ~/Videos/Screenrecordings/recording_"$(date +\'%b-%d-%Y-%I:%M:%S-%P\')".mp4 -g "$(slurp)" --pixel-format yuv420p; fi']).catch(logError);
},
if (isRecording) {
stopRecordingTimer(self);
} else {
startRecordingTimer(self);
}
self.toggleClassName("active-button", !isRecording);
self.toggleClassName("recording", !isRecording);
Utils.execAsync(['bash', '-c', 'mkdir -p ~/Videos/Screenrecordings; pkill wf-recorder; if [ $? -ne 0 ]; then wf-recorder -f ~/Videos/Screenrecordings/recording_"$(date +\'%b-%d-%Y-%I:%M:%S-%P\')".mp4 -g "$(slurp)" --pixel-format yuv420p; fi']).catch(logError);
},
child: IconAndName({
label: "Screen Recorder",
icon: "",
setup: self=>{}
icon: "󰑋",
setup: self=>{
self.label = 'Start Recording';
}
})
}),
+4 -1
View File
@@ -46,7 +46,10 @@ export function NotificationsBox({ exclude = [], include = [] }: NotificationsBo
class_name: "notifications_menu",
children: [
Widget.MenuItem({
child: Widget.Label('Close all'),
child: Widget.Label({
label: "Close all",
hpack: "start"
}),
class_name: "notifications_menu_item",
on_activate: () => {
for (let n of notifications.notifications) {
+63
View File
@@ -0,0 +1,63 @@
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
import { exec, execAsync } from 'resource:///com/github/Aylur/ags/utils.js';
function isScreenRecordingOn() {
let state = exec('bash -c "pidof wf-recorder > /dev/null; echo $?"');
return state == "0";
}
let recordingStartTime = null;
let recordingInterval = null;
function formatTime(ms) {
let totalSeconds = Math.floor(ms / 1000);
let hours = Math.floor(totalSeconds / 3600);
let minutes = Math.floor((totalSeconds % 3600) / 60);
let seconds = totalSeconds % 60;
return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
}
function startRecordingTimer(button) {
recordingStartTime = Date.now();
recordingInterval = setInterval(() => {
let elapsedTime = Date.now() - recordingStartTime;
button.label = formatTime(elapsedTime);
}, 1000);
}
function stopRecordingTimer(button) {
clearInterval(recordingInterval);
recordingStartTime = null;
recordingInterval = null;
button.label = 'Start Recording';
}
export const ScreenRecordButton = (w, h) => Widget.Button({
class_name: `control-panel-button`,
css: `
min-width: ${w}rem;
min-height: ${h}rem;
`,
on_clicked: (self) => {
let isRecording = isScreenRecordingOn();
if (isRecording) {
stopRecordingTimer(self);
} else {
startRecordingTimer(self);
}
self.toggleClassName("active-button", !isRecording);
self.toggleClassName("recording", !isRecording);
execAsync(['bash', '-c', 'mkdir -p ~/Screenrecordings; pkill wf-recorder; if [ $? -ne 0 ]; then wf-recorder -f ~/Screenrecordings/recording_"$(date +\'%b-%d-%Y-%I:%M:%S-%P\')".mp4 -g "$(slurp)" --pixel-format yuv420p; fi']).catch(logError);
},
child: Widget.Icon({
size: 22,
icon: "media-record-symbolic",
setup: self => {
self.label = 'Start Recording';
}
})
});
+62 -3
View File
@@ -96,6 +96,11 @@
color: @onErrorContainer;
}
.settings box {
margin: 0px;
padding: 0px;
}
/* Wifi */
.settings .wifi_toggle {
@@ -150,8 +155,62 @@
color: @primary;
}
.settings box {
margin: 0px;
padding: 0px;
/* Bluetooth */
.settings .bluetooth_toggle {
padding-left: 16px;
padding-right: 16px;
padding-top: 12px;
padding-bottom: 8px;
}
.settings .bluetooth_toggle .title {
font-weight: normal;
font-size: 17px;
color: @onSurface
}
.settings .bluetooth_toggle .description {
font-weight: normal;
font-size: 14px;
color: @onSurfaceVariant
}
.settings .device_list .device {
padding-left: 16px;
padding-right: 16px;
padding-top: 8px;
padding-bottom: 8px;
border-radius: 0px;
}
.settings .device_list .device:hover {
background-color: mix(@onSurface, @surface, 0.92)
}
.settings .device_list .device .title {
font-weight: normal;
font-size: 16px;
color: @onSurface
}
.settings .device_list .device .description {
font-weight: normal;
font-size: 14px;
color: @onSurfaceVariant
}
.settings .device_list .device image {
color: @onTertiary;
background-color: @tertiary;
margin-right: 16px;
min-height: 32px;
min-width: 32px;
border-radius: 5px;
}
.settings .device_list .device.active image {
color: @onPrimary;
background-color: @primary;
}
+12 -7
View File
@@ -1,8 +1,7 @@
@import "./colors.css";
window.bar {
/*background-color: @surface;*/
background-color: transparent;
background-color: @surface;
padding: 6px;
}
@@ -490,16 +489,23 @@ window.notification-popups box.notifications {
color: @onSurface;
}
.bar_wifi {
.bar_applets {
background-color: @surfaceContainer;
border-radius: 100px;
padding: 2px 10px 2px 10px;
margin: 0px;
}
.bar_wifi image {
.bar_applets image {
color: @onSurface;
}
.bar_applets button {
color: @onSurface;
margin: 0px;
padding: 0px;
}
/* -----------------------------------------------------
* Sidebar
* ----------------------------------------------------- */
@@ -630,7 +636,7 @@ window.notification-popups box.notifications {
}
.system_scale.backlight {
margin-bottom: 30px;
margin-bottom: 25px;
}
.system_scale.brightness slider {
@@ -891,7 +897,7 @@ switch slider {
min-height: 8px;
min-width: 16px;
transition: all 0.2s ease-in-out;
transition-property: min-height, min-width, color, background-color, border-color, margin;
transition-property: color, background-color, border-color;
}
switch:disabled {
@@ -940,4 +946,3 @@ switch:checked:hover, switch:checked:active {
switch:checked:hover slider, switch:checked:active slider {
background-color: @primaryContainer;
}