✨ chore: make tray item activate on primary button click and open menu on secondary click
This commit is contained in:
+17
-9
@@ -1,10 +1,10 @@
|
|||||||
import { createBinding, createComputed, For, With } from "ags";
|
import { createBinding, createComputed, For, With } from "ags";
|
||||||
import { Gdk, Gtk } from "ags/gtk4";
|
import { Gdk, Gtk } from "ags/gtk4";
|
||||||
|
import { variableToBoolean } from "../../scripts/utils";
|
||||||
|
|
||||||
|
import GObject from "gi://GObject?version=2.0";
|
||||||
import AstalTray from "gi://AstalTray"
|
import AstalTray from "gi://AstalTray"
|
||||||
import Gio from "gi://Gio?version=2.0";
|
import Gio from "gi://Gio?version=2.0";
|
||||||
import { variableToBoolean } from "../../scripts/utils";
|
|
||||||
import GObject from "gi://GObject?version=2.0";
|
|
||||||
|
|
||||||
|
|
||||||
const astalTray = AstalTray.get_default();
|
const astalTray = AstalTray.get_default();
|
||||||
@@ -22,7 +22,6 @@ export const Tray = () => {
|
|||||||
return <Gtk.Box class={"tray"} visible={variableToBoolean(items)} spacing={10}>
|
return <Gtk.Box class={"tray"} visible={variableToBoolean(items)} spacing={10}>
|
||||||
<For each={items}>
|
<For each={items}>
|
||||||
{(item: AstalTray.TrayItem) => <Gtk.Box class={"item"}>
|
{(item: AstalTray.TrayItem) => <Gtk.Box class={"item"}>
|
||||||
|
|
||||||
<With value={createComputed([
|
<With value={createComputed([
|
||||||
createBinding(item, "actionGroup"),
|
createBinding(item, "actionGroup"),
|
||||||
createBinding(item, "menuModel")
|
createBinding(item, "menuModel")
|
||||||
@@ -30,12 +29,14 @@ export const Tray = () => {
|
|||||||
{([actionGroup, menuModel]: [Gio.ActionGroup, Gio.MenuModel]) => {
|
{([actionGroup, menuModel]: [Gio.ActionGroup, Gio.MenuModel]) => {
|
||||||
const popover = popoverFromModel(menuModel, actionGroup);
|
const popover = popoverFromModel(menuModel, actionGroup);
|
||||||
|
|
||||||
return <Gtk.MenuButton class={"item-button"} tooltipMarkup={
|
return <Gtk.MenuButton class={"item"} tooltipMarkup={
|
||||||
createBinding(item, "tooltipMarkup")} tooltipText={
|
createBinding(item, "tooltipMarkup")
|
||||||
createBinding(item, "tooltipText")} popover={popover}
|
} tooltipText={
|
||||||
$={(self) => {
|
createBinding(item, "tooltipText")
|
||||||
|
} $={(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);
|
||||||
|
|
||||||
self.add_controller(gestureClick);
|
self.add_controller(gestureClick);
|
||||||
|
|
||||||
@@ -43,13 +44,20 @@ export const Tray = () => {
|
|||||||
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;
|
||||||
} else 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);
|
||||||
|
const conn = self.popover!.connect("closed", (ppover) => {
|
||||||
|
self.set_popover(null);
|
||||||
|
ppover.disconnect(conn);
|
||||||
|
});
|
||||||
|
|
||||||
self.popup();
|
self.popup();
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
}}>
|
}}>
|
||||||
|
|
||||||
<Gtk.Image gicon={createBinding(item, "gicon")} pixelSize={16} />
|
<Gtk.Image gicon={createBinding(item, "gicon")} pixelSize={16} />
|
||||||
</Gtk.MenuButton>
|
</Gtk.MenuButton>
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user