fix(ags): make osds popup when they should
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-02-27 16:55:01 -05:00
parent f56b6010ff
commit 3df8ef0a66
5 changed files with 69 additions and 48 deletions

View file

@ -86,17 +86,18 @@ export type NotifGesture = AgsEventBox<BoxGeneric, NotifGestureProps>;
// For ./ts/osd/ctor.ts
export type OSDStack = AgsStack<unknown & Widget, {
popup(osd: BoxGeneric): void,
popup(osd: string): void,
}>;
export type ConnectFunc = (self?: ProgressBarGeneric) => void;
export type OSD = {
name: string;
stack: OSDStack;
icon: string | IconPropsGeneric;
icon: IconPropsGeneric['icon'];
info: {
mod: GObject.Object;
signal?: string;
signal?: string | string[];
logic?(self: ProgressBarGeneric): void;
widget?: Widget;
widget?: AgsWidget;
}
};

View file

@ -3,28 +3,32 @@ const { Box, Icon, ProgressBar } = Widget;
const Y_POS = 80;
// Types
import { ConnectFunc, OSD, ProgressBarGeneric } from 'global-types';
import { ConnectFunc, OSD } from 'global-types';
export default ({ stack, icon, info }: OSD) => {
export default ({ name, stack, icon, info }: OSD) => {
let connectFunc: ConnectFunc;
const status = info.widget ?
info.widget :
ProgressBar({ vpack: 'center' });
// Wrapper to get sliding up anim
const osd = Box({
name,
css: `margin-bottom: ${Y_POS}px;`,
children: [Box({
class_name: 'osd',
children: [
Icon({
hpack: 'start',
// Can take a string or an object of props
...(typeof icon === 'string' ? { icon } : icon),
}),
// Can take a static widget instead of a progressbar
info.widget ?
info.widget :
ProgressBar({ vpack: 'center' }),
],
})],
children: [
// Actual OSD
Box({
class_name: 'osd',
children: [
Icon({
hpack: 'start',
icon,
}),
status,
],
}),
],
});
// Handle requests to show the OSD
@ -35,14 +39,22 @@ export default ({ stack, icon, info }: OSD) => {
info.logic(self);
}
r();
}).then(() => stack.attribute.popup(osd));
}).then(() => stack.attribute.popup(name));
}
else {
connectFunc = () => stack.attribute.popup(osd);
connectFunc = () => stack.attribute.popup(name);
}
(osd.children[0].children[1] as ProgressBarGeneric)
.hook(info.mod, connectFunc, info.signal);
if (info.signal) {
if (typeof info.signal === 'string') {
status.hook(info.mod, connectFunc, info.signal);
}
else {
info.signal.forEach((sig) => {
status.hook(info.mod, connectFunc, sig);
});
}
}
return osd;
};

View file

@ -23,16 +23,22 @@ const OSDs = () => {
transition: 'over_up_down',
transition_duration,
attribute: { popup: (osd: BoxGeneric) => {
if (!osd) {
//
}
} },
attribute: {
popup: (osd: string) => {
if (!osd) {
//
}
},
},
});
// Send reference of stack to all children
stack.children = Object.fromEntries(
OSDList.map((osd, i) => [`${i}`, osd(stack)]),
OSDList.map((osd) => {
const widget = osd(stack);
return [widget.name, widget];
}),
);
// Delay popup method so it
@ -40,9 +46,9 @@ const OSDs = () => {
timeout(1000, () => {
let count = 0;
stack.attribute.popup = (osd: BoxGeneric) => {
stack.attribute.popup = (osd: string) => {
++count;
stack.set_visible_child(osd);
stack.shown = osd;
App.openWindow('osd');
timeout(HIDE_DELAY, () => {
@ -53,6 +59,8 @@ const OSDs = () => {
}
});
};
globalThis['popup_osd'] = stack.attribute.popup;
});
return stack;

View file

@ -10,21 +10,17 @@ import { MicIcon } from '../misc/audio-icons.ts';
const AUDIO_MAX = 1.5;
const ShowSpeaker = Variable(true);
globalThis.showSpeaker = () => {
ShowSpeaker.setValue(!ShowSpeaker.value);
};
// Types
import { OSDStack } from 'global-types';
export const SpeakerOSD = (stack: OSDStack) => OSD({
name: 'speaker',
stack,
icon: { icon: SpeakerIcon.bind() },
icon: SpeakerIcon.bind(),
info: {
mod: ShowSpeaker,
mod: Audio.speaker,
signal: ['notify::volume', 'notify::is-muted'],
logic: (self) => {
if (!Audio.speaker) {
@ -41,8 +37,9 @@ export const SpeakerOSD = (stack: OSDStack) => OSD({
});
export const ScreenBrightnessOSD = (stack: OSDStack) => OSD({
name: 'screen',
stack,
icon: { icon: Brightness.bind('screenIcon') },
icon: Brightness.bind('screenIcon'),
info: {
mod: Brightness,
signal: 'screen',
@ -54,6 +51,7 @@ export const ScreenBrightnessOSD = (stack: OSDStack) => OSD({
});
export const KbdBrightnessOSD = (stack: OSDStack) => OSD({
name: 'kbd',
stack,
icon: 'keyboard-brightness-symbolic',
info: {
@ -73,11 +71,12 @@ export const KbdBrightnessOSD = (stack: OSDStack) => OSD({
});
export const MicOSD = (stack: OSDStack) => OSD({
name: 'mic',
stack,
icon: { icon: MicIcon.bind() },
icon: MicIcon.bind(),
info: {
mod: Audio,
signal: 'microphone-changed',
mod: Audio.microphone,
signal: ['notify::volume', 'notify::is-muted'],
logic: (self) => {
if (!Audio.microphone) {
@ -91,8 +90,9 @@ export const MicOSD = (stack: OSDStack) => OSD({
});
export const CapsLockOSD = (stack: OSDStack) => OSD({
name: 'caps',
stack,
icon: { icon: Brightness.bind('capsIcon') },
icon: Brightness.bind('capsIcon'),
info: {
mod: Brightness,
signal: 'caps',

View file

@ -132,13 +132,13 @@ in {
"$mainMod SHIFT, 9, movetoworkspace, 9"
"$mainMod SHIFT, 0, movetoworkspace, 10"
",XF86AudioMute, exec, pactl set-sink-mute @DEFAULT_SINK@ toggle & ags -r 'showSpeaker()' &"
",XF86AudioMute, exec, pactl set-sink-mute @DEFAULT_SINK@ toggle"
",XF86AudioMicMute, exec, pactl set-source-mute @DEFAULT_SOURCE@ toggle"
];
binde = [
",XF86AudioRaiseVolume, exec, wpctl set-volume -l 1.5 @DEFAULT_AUDIO_SINK@ 5%+ & ags -r 'showSpeaker()' &"
",XF86AudioLowerVolume, exec, wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%- & ags -r 'showSpeaker()' &"
",XF86AudioRaiseVolume, exec, wpctl set-volume -l 1.5 @DEFAULT_AUDIO_SINK@ 5%+ & ags -r 'popup_osd(\"speaker\")' &"
",XF86AudioLowerVolume, exec, wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%- & ags -r 'popup_osd(\"speaker\")' &"
];
# Mouse Binds