safe
This commit is contained in:
+37
-2
@@ -276,11 +276,14 @@ export function openRunner(props: RunnerProps, placeholders?: Array<Result>): As
|
||||
props.height ??= 420;
|
||||
|
||||
let clickTimeout: GLib.Source|undefined;
|
||||
let lastMouseX: number|null = null;
|
||||
let lastMouseY: number|null = null;
|
||||
let lastKeyboardNavTime: number = 0;
|
||||
|
||||
if(!instance)
|
||||
instance = Windows.getDefault().createWindowForFocusedMonitor((mon, root) =>
|
||||
<PopupWindow namespace={"runner"} monitor={mon} widthRequest={props.width}
|
||||
heightRequest={props.height} exclusivity={Astal.Exclusivity.IGNORE} halign={Gtk.Align.CENTER}
|
||||
<PopupWindow namespace={"runner"} monitor={mon} widthRequest={props.width}
|
||||
exclusivity={Astal.Exclusivity.IGNORE} halign={Gtk.Align.CENTER}
|
||||
marginTop={(AstalHyprland.get_default().get_monitor(mon)?.height / 2) - (props.height! / 2)}
|
||||
valign={Gtk.Align.START} hexpand orientation={Gtk.Orientation.VERTICAL}
|
||||
$={() => {
|
||||
@@ -302,12 +305,14 @@ export function openRunner(props: RunnerProps, placeholders?: Array<Result>): As
|
||||
case Gdk.KEY_Up:
|
||||
selectPreviousItem(listbox);
|
||||
gtkEntry?.grab_focus();
|
||||
lastKeyboardNavTime = Date.now();
|
||||
return;
|
||||
|
||||
case Gdk.KEY_Right:
|
||||
case Gdk.KEY_Down:
|
||||
selectNextItem(listbox);
|
||||
gtkEntry?.grab_focus();
|
||||
lastKeyboardNavTime = Date.now();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -374,6 +379,36 @@ export function openRunner(props: RunnerProps, placeholders?: Array<Result>): As
|
||||
child.closeOnClick &&
|
||||
Runner.close();
|
||||
}
|
||||
}} $={(self) => {
|
||||
// Hover-based selection: only triggers when the mouse actually moves
|
||||
const motion = Gtk.EventControllerMotion.new();
|
||||
self.add_controller(motion);
|
||||
|
||||
motion.connect("motion", (_controller, x, y) => {
|
||||
const now = Date.now();
|
||||
|
||||
// While user is actively navigating with keyboard,
|
||||
// don't let hover steal selection
|
||||
if(lastKeyboardNavTime && now - lastKeyboardNavTime < 200)
|
||||
return;
|
||||
|
||||
// First motion: just record pointer position, don't change selection
|
||||
if(lastMouseX === null && lastMouseY === null) {
|
||||
lastMouseX = x;
|
||||
lastMouseY = y;
|
||||
return;
|
||||
}
|
||||
|
||||
// Ignore synthetic events that don't actually move the pointer
|
||||
if(x === lastMouseX && y === lastMouseY)
|
||||
return;
|
||||
|
||||
lastMouseX = x;
|
||||
lastMouseY = y;
|
||||
|
||||
const row = self.get_row_at_y(y);
|
||||
row && self.select_row(row as Gtk.ListBoxRow);
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</Gtk.ScrolledWindow>
|
||||
|
||||
Reference in New Issue
Block a user