⚡ perf(bar/tray): use gtkbox instead of gtkmenubutton, use popover as gtkbox child
This commit is contained in:
+26
-36
@@ -9,13 +9,6 @@ import Gio from "gi://Gio?version=2.0";
|
|||||||
|
|
||||||
const astalTray = AstalTray.get_default();
|
const astalTray = AstalTray.get_default();
|
||||||
|
|
||||||
function popoverFromModel(model: Gio.MenuModel, actionGroup: Gio.ActionGroup | null): Gtk.PopoverMenu {
|
|
||||||
const menu = Gtk.PopoverMenu.new_from_model(model);
|
|
||||||
menu.insert_action_group("dbusmenu", actionGroup)
|
|
||||||
|
|
||||||
return menu;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const Tray = () => {
|
export const Tray = () => {
|
||||||
const items = createBinding(astalTray, "items").as(items => items.filter(item => item?.gicon));
|
const items = createBinding(astalTray, "items").as(items => items.filter(item => item?.gicon));
|
||||||
|
|
||||||
@@ -27,39 +20,36 @@ export const Tray = () => {
|
|||||||
createBinding(item, "menuModel")
|
createBinding(item, "menuModel")
|
||||||
])}>
|
])}>
|
||||||
{([actionGroup, menuModel]: [Gio.ActionGroup, Gio.MenuModel]) => {
|
{([actionGroup, menuModel]: [Gio.ActionGroup, Gio.MenuModel]) => {
|
||||||
const popover = popoverFromModel(menuModel, actionGroup);
|
const popover = Gtk.PopoverMenu.new_from_model(menuModel);
|
||||||
|
popover.insert_action_group("dbusmenu", actionGroup);
|
||||||
|
popover.hasArrow = false;
|
||||||
|
|
||||||
return <Gtk.MenuButton class={"item"} tooltipMarkup={
|
return <Gtk.Box class={"item"} tooltipMarkup={
|
||||||
createBinding(item, "tooltipMarkup")
|
createBinding(item, "tooltipMarkup")
|
||||||
} tooltipText={
|
} tooltipText={
|
||||||
createBinding(item, "tooltipText")
|
createBinding(item, "tooltipText")
|
||||||
} $={(self) => {
|
} $={(self) => {
|
||||||
const conns: Map<GObject.Object, number> = new Map();
|
const conns: Map<GObject.Object, number> = new Map();
|
||||||
const gestureClick = Gtk.GestureClick.new();
|
const gestureClick = Gtk.GestureClick.new();
|
||||||
gestureClick.set_button(0);
|
gestureClick.set_button(0);
|
||||||
|
|
||||||
self.add_controller(gestureClick);
|
self.add_controller(gestureClick);
|
||||||
|
|
||||||
conns.set(gestureClick, gestureClick.connect("released", (gesture, _, x, y) => {
|
conns.set(gestureClick, gestureClick.connect("released", (gesture, _, x, y) => {
|
||||||
if(gesture.get_current_button() === Gdk.BUTTON_PRIMARY) {
|
if(gesture.get_current_button() === Gdk.BUTTON_PRIMARY) {
|
||||||
item.activate(x, y);
|
item.activate(x, y);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(gesture.get_current_button() === Gdk.BUTTON_SECONDARY) {
|
if(gesture.get_current_button() === Gdk.BUTTON_SECONDARY) {
|
||||||
item.about_to_show();
|
item.about_to_show();
|
||||||
self.set_popover(popover);
|
popover.popup();
|
||||||
const conn = self.popover!.connect("closed", (ppover) => {
|
}
|
||||||
self.set_popover(null);
|
}))
|
||||||
ppover.disconnect(conn);
|
}}>
|
||||||
});
|
<Gtk.Image gicon={createBinding(item, "gicon")} pixelSize={16} />
|
||||||
|
{popover}
|
||||||
self.popup();
|
</Gtk.Box>;
|
||||||
}
|
|
||||||
}))
|
|
||||||
}}>
|
|
||||||
<Gtk.Image gicon={createBinding(item, "gicon")} pixelSize={16} />
|
|
||||||
</Gtk.MenuButton>
|
|
||||||
}}
|
}}
|
||||||
</With>
|
</With>
|
||||||
</Gtk.Box>}
|
</Gtk.Box>}
|
||||||
|
|||||||
Reference in New Issue
Block a user