Skip to content

Instantly share code, notes, and snippets.

@ragusa87
Created September 27, 2023 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ragusa87/f0ab3f814e8de896df2cc54d3164c080 to your computer and use it in GitHub Desktop.
Save ragusa87/f0ab3f814e8de896df2cc54d3164c080 to your computer and use it in GitHub Desktop.
Kwin script setTimeout (typescript) with QTimer
interface QTimer {
timeout: QSignal;
start(durationMs: number): void;
stop(): void;
}
declare interface QSignal {
connect(callback: any): void;
disconnect(callback: any): void;
}
let timers: QTimer[] = [];
function setTimeout (callback: any, duration: number): number{
// @ts-ignore QTime is exposed by KWIN/QT, so it exists anyway.
let timer = new QTimer();
timers.push(timer);
timer.singleShot = true;
timer.timeout.connect(callback);
timer.start(duration);
return timers.length -1
}
function cancelTimeout(timerId: number): boolean{
if(timers[timerId] === undefined){
return false;
}
timers[timerId].stop();
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment