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

View file

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

View file

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

View file

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

View file

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