Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Ignore accidental window movements/grab ops #1482

Open
wants to merge 1 commit into
base: master_jammy
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ export class Ext extends Ecs.System<ExtEvent> {

drag_signal: null | SignalID = null

/** Minimum amount of time for a window to be dragged to apply updates */
min_drag_ms: number = 100;

/** If set, the user is currently selecting a window to add to floating exceptions */
exception_selecting: boolean = false;

Expand All @@ -148,6 +151,9 @@ export class Ext extends Ecs.System<ExtEvent> {
/** Information about a current possible grab operation */
grab_op: GrabOp.GrabOp | null = null;

/** Timestamp of most recent window grab by mouse */
private grab_time: number = 0;

/** A display config update is triggered on a workspace addition */
ignore_display_update: boolean = false;

Expand Down Expand Up @@ -1065,6 +1071,11 @@ export class Ext extends Ecs.System<ExtEvent> {
return;
}

// Prevent accidental mouse drag
if ((+new Date()) - this.grab_time < this.min_drag_ms) {
op = undefined; // reflow without updating tree
}

this.on_grab_end_(win, op);
this.unset_grab_op()
}
Expand Down Expand Up @@ -1396,6 +1407,7 @@ export class Ext extends Ecs.System<ExtEvent> {
/** Triggered when a grab operation has been started */
on_grab_start(meta: null | Meta.Window, op: any) {
if (!meta) return
this.grab_time = +new Date(); // timestamp
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an appropriate way to get a timestamp in gjs?

I wanted to use this.grab_time = global.get_current_time(); but it only seems to return 0. Maybe it doesn't do what I think it does, couldn't find docs.

let win = this.get_window(meta);
if (win) {
win.grab = true;
Expand Down