refactor(ags): make single use widgets code simpler

This commit is contained in:
matt1432 2023-09-10 23:24:58 -04:00
parent 2305f1e06a
commit 1fa5fd676a
8 changed files with 31 additions and 38 deletions

View file

@ -10,8 +10,8 @@ const items = {
0: 'audio-volume-muted-symbolic', 0: 'audio-volume-muted-symbolic',
}; };
const SpeakerIndicator = props => Icon({ const SpeakerIndicator = params => Icon({
...props, ...params,
icon: '', icon: '',
connections: [[Audio, icon => { connections: [[Audio, icon => {
if (!Audio.speaker) if (!Audio.speaker)
@ -28,8 +28,8 @@ const SpeakerIndicator = props => Icon({
}, 'speaker-changed']], }, 'speaker-changed']],
}); });
const SpeakerPercentLabel = props => Label({ const SpeakerPercentLabel = params => Label({
...props, ...params,
connections: [[Audio, label => { connections: [[Audio, label => {
if (!Audio.speaker) if (!Audio.speaker)
return; return;
@ -45,7 +45,7 @@ const SpeakerPercentLabel = props => Label({
}, 'speaker-changed']], }, 'speaker-changed']],
}); });
const AudioModule = () => EventBox({ export const AudioIndicator = EventBox({
onPrimaryClickRelease: 'pavucontrol', onPrimaryClickRelease: 'pavucontrol',
className: 'toggle-off', className: 'toggle-off',
child: Box({ child: Box({
@ -57,5 +57,3 @@ const AudioModule = () => EventBox({
], ],
}), }),
}); });
export const AudioIndicator = AudioModule();

View file

@ -1,17 +1,17 @@
const { Window, CenterBox, Box } = ags.Widget; const { Window, CenterBox, Box } = ags.Widget;
import { Separator } from '../common.js'; import { Separator } from '../common.js';
import { CurrentWindow } from './current-window.js'; import { CurrentWindow } from './current-window.js';
import { Workspaces } from './workspaces.js'; import { Workspaces } from './workspaces.js';
import { OskToggle } from './osk-toggle.js'; import { OskToggle } from './osk-toggle.js';
import { TabletToggle } from './tablet-toggle.js'; import { TabletToggle } from './tablet-toggle.js';
import { QsToggle } from './quick-settings.js'; import { QsToggle } from './quick-settings.js';
import { NotifButton } from './notif-button.js'; import { NotifButton } from './notif-button.js';
import { Clock } from './clock.js'; import { Clock } from './clock.js';
import { SysTray } from './systray.js'; import { SysTray } from './systray.js';
import { Batt } from './battery.js'; import { BatteryIndicator } from './battery.js';
import { Brightness } from './brightness.js'; import { Brightness } from './brightness.js';
import { AudioIndicator } from './audio.js'; import { AudioIndicator } from './audio.js';
export const Bar = Window({ export const Bar = Window({
name: 'bar', name: 'bar',
@ -59,7 +59,7 @@ export const Bar = Window({
endWidget: Box({ endWidget: Box({
halign: 'end', halign: 'end',
children: [ children: [
Batt, BatteryIndicator,
Separator(12), Separator(12),

View file

@ -25,9 +25,9 @@ const Indicators = charging => Stack({
const Indicator = ({ const Indicator = ({
charging = Indicators(true), charging = Indicators(true),
discharging = Indicators(false), discharging = Indicators(false),
...props ...params
} = {}) => Stack({ } = {}) => Stack({
...props, ...params,
className: 'battery-indicator', className: 'battery-indicator',
items: [ items: [
['true', charging], ['true', charging],
@ -43,13 +43,13 @@ const Indicator = ({
}]], }]],
}); });
const LevelLabel = props => Label({ const LevelLabel = params => Label({
...props, ...params,
className: 'label', className: 'label',
connections: [[1000, label => label.label = `${exec('cat /sys/class/power_supply/BAT0/capacity')}%`]], connections: [[1000, label => label.label = `${exec('cat /sys/class/power_supply/BAT0/capacity')}%`]],
}); });
const BatteryLabel = () => Box({ export const BatteryIndicator = Box({
className: 'toggle-off battery', className: 'toggle-off battery',
children: [ children: [
Indicator(), Indicator(),
@ -57,5 +57,3 @@ const BatteryLabel = () => Box({
LevelLabel(), LevelLabel(),
], ],
}); });
export const Batt = BatteryLabel();

View file

@ -4,9 +4,9 @@ const { DateTime } = imports.gi.GLib;
const ClockModule = ({ const ClockModule = ({
interval = 1000, interval = 1000,
...props ...params
}) => Label({ }) => Label({
...props, ...params,
className: 'clock', className: 'clock',
connections: [ connections: [
[interval, label => { [interval, label => {

View file

@ -2,7 +2,7 @@ const { Hyprland } = ags.Service;
const { Label } = ags.Widget; const { Label } = ags.Widget;
const { Gtk } = imports.gi; const { Gtk } = imports.gi;
const currentWindow = () => Label({ export const CurrentWindow = Label({
style: 'color: #CBA6F7; font-size: 18px', style: 'color: #CBA6F7; font-size: 18px',
truncate: 'end', truncate: 'end',
connections: [ connections: [
@ -11,5 +11,3 @@ const currentWindow = () => Label({
}, 'changed'], }, 'changed'],
], ],
}); });
export const CurrentWindow = currentWindow();

View file

@ -1,8 +1,9 @@
const { Box, Label } = ags.Widget; const { Box, Label } = ags.Widget;
const { subprocess } = ags.Utils; const { subprocess } = ags.Utils;
import { EventBox } from '../common.js';
const deflisten = subprocess; const deflisten = subprocess;
import { EventBox } from '../common.js';
deflisten( deflisten(
['bash', '-c', '$AGS_PATH/notif.sh icon'], ['bash', '-c', '$AGS_PATH/notif.sh icon'],
(output) => { (output) => {

View file

@ -15,7 +15,7 @@ const SysTrayItem = item => MenuItem({
}]] }]]
}); });
const SysTrayModule = () => ags.Widget({ export const SysTray = ags.Widget({
type: Gtk.MenuBar, type: Gtk.MenuBar,
className: 'sys-tray', className: 'sys-tray',
properties: [ properties: [
@ -43,5 +43,3 @@ const SysTrayModule = () => ags.Widget({
[SystemTray, (box, id) => box._onRemoved(box, id), 'removed'], [SystemTray, (box, id) => box._onRemoved(box, id), 'removed'],
], ],
}); });
export const SysTray = SysTrayModule();

View file

@ -2,7 +2,7 @@ const { Window, Box, EventBox, Button } = ags.Widget;
const { Gtk, Gdk } = imports.gi; const { Gtk, Gdk } = imports.gi;
const display = Gdk.Display.get_default(); const display = Gdk.Display.get_default();
const Draggable = ({ maxOffset = 150, startMargin = 0, style, connections = [], ...props }) => { const Draggable = ({ maxOffset = 150, startMargin = 0, style, connections = [], ...params }) => {
let w = EventBox({ let w = EventBox({
onHover: box => { onHover: box => {
box.window.set_cursor(Gdk.Cursor.new_from_name(display, 'grab')); box.window.set_cursor(Gdk.Cursor.new_from_name(display, 'grab'));
@ -15,7 +15,7 @@ const Draggable = ({ maxOffset = 150, startMargin = 0, style, connections = [],
let gesture = Gtk.GestureDrag.new(w); let gesture = Gtk.GestureDrag.new(w);
w.child = Box({ w.child = Box({
...props, ...params,
connections: [ connections: [
[gesture, box => { [gesture, box => {