refactor(agsV2): apply feedback from the man himself
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-10-28 15:09:10 -04:00
parent 653961ada1
commit ab6b00c259
4 changed files with 35 additions and 48 deletions

View file

@ -1,6 +1,4 @@
import { App, Gdk, Widget } from 'astal/gtk3'; import { Gdk } from 'astal/gtk3';
import AstalApps from 'gi://AstalApps';
import AstalHyprland from 'gi://AstalHyprland'; import AstalHyprland from 'gi://AstalHyprland';
const Hyprland = AstalHyprland.get_default(); const Hyprland = AstalHyprland.get_default();
@ -111,16 +109,3 @@ export const centerCursor = async(): Promise<void> => {
await hyprMessage(`dispatch movecursor ${x} ${y}`); await hyprMessage(`dispatch movecursor ${x} ${y}`);
}; };
export const get_app_icon = (app: AstalApps.Application): string => {
if (app.get_icon_name() && Widget.Icon.lookup_icon(app.get_icon_name())) {
return app.get_icon_name();
}
else {
const iconString = app.get_key('Icon');
App.add_icons(iconString);
return iconString;
}
};

View file

@ -1,8 +1,6 @@
import { Gtk, Widget } from 'astal/gtk3'; import { Gtk, Widget } from 'astal/gtk3';
import { register } from 'astal/gobject'; import { register } from 'astal/gobject';
import { get_app_icon } from '../../lib';
/* Types */ /* Types */
import AstalApps from 'gi://AstalApps'; import AstalApps from 'gi://AstalApps';
type AppItemProps = Widget.BoxProps & { type AppItemProps = Widget.BoxProps & {
@ -29,7 +27,7 @@ export class AppItem extends Widget.Box {
const icon = ( const icon = (
<icon <icon
icon={get_app_icon(this.app)} icon={this.app.iconName}
css="font-size: 42px; margin-right: 25px;" css="font-size: 42px; margin-right: 25px;"
/> />
); );

View file

@ -162,7 +162,26 @@ export class NotifGestureWrapper extends Widget.EventBox {
setup_notif = () => { /**/ }, setup_notif = () => { /**/ },
...rest ...rest
}: NotifGestureWrapperProps) { }: NotifGestureWrapperProps) {
super(); super({
on_button_press_event: () => {
this.setCursor('grabbing');
},
// OnRelease
on_button_release_event: () => {
this.setCursor('grab');
},
// OnHover
on_enter_notify_event: () => {
this.setCursor('grab');
},
// OnHoverLost
on_leave_notify_event: () => {
this.setCursor('grab');
},
});
this.id = id; this.id = id;
this.slide_in_from = slide_in_from; this.slide_in_from = slide_in_from;
@ -171,37 +190,22 @@ export class NotifGestureWrapper extends Widget.EventBox {
this.popup_timer = popup_timer; this.popup_timer = popup_timer;
this.is_popup = this.popup_timer !== 0; this.is_popup = this.popup_timer !== 0;
// OnClick
this.connect('button-press-event', () => {
this.setCursor('grabbing');
});
// OnRelease
this.connect('button-release-event', () => {
this.setCursor('grab');
});
// OnHover
this.connect('enter-notify-event', () => {
this.setCursor('grab');
});
// OnHoverLost
this.connect('leave-notify-event', () => {
this.setCursor('grab');
});
// Handle timeout before sliding away if it is a popup // Handle timeout before sliding away if it is a popup
if (this.popup_timer !== 0) { if (this.popup_timer !== 0) {
this.timer_object = interval(1000, async() => { this.timer_object = interval(1000, async() => {
if (!(await this.get_hovered())) { try {
if (this.popup_timer === 0) { if (!(await this.get_hovered())) {
this.slideAway('Left'); if (this.popup_timer === 0) {
} this.slideAway('Left');
else { }
--this.popup_timer; else {
--this.popup_timer;
}
} }
} }
catch (_) {
this.timer_object?.cancel();
}
}); });
} }

View file

@ -10,7 +10,7 @@ const Hyprland = AstalHyprland.get_default();
import PopupWindow from '../misc/popup-window'; import PopupWindow from '../misc/popup-window';
import Separator from '../misc/separator'; import Separator from '../misc/separator';
import { get_app_icon, hyprMessage } from '../../lib'; import { hyprMessage } from '../../lib';
const ICON_SEP = 6; const ICON_SEP = 6;
@ -46,7 +46,7 @@ export default () => {
}} }}
> >
<box halign={Gtk.Align.CENTER}> <box halign={Gtk.Align.CENTER}>
<icon icon={get_app_icon(Applications.fuzzy_query(client.class)[0])} /> <icon icon={Applications.fuzzy_query(client.class)[0].iconName} />
<Separator size={ICON_SEP} /> <Separator size={ICON_SEP} />