/* * Licensed under the GNU Lesser General Public License Version 3 * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the license, or * (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library. If not, see . */ // generated automatically - do not change module glib.Idle; private import glib.Source; private import glib.c.functions; public import glib.c.types; /** */ public class Idle { /** Holds all idle delegates */ bool delegate()[] idleListeners; /** our idle ID */ uint idleID; /** * Creates a new idle cycle. * Params: * interval = the idle in milieconds * dlg = the delegate to be executed * fireNow = When true the delegate will be executed emmidiatly */ this(bool delegate() dlg, bool fireNow=false) { idleListeners ~= dlg; idleID = g_idle_add(cast(GSourceFunc)&idleCallback, cast(void*)this); if ( fireNow ) { if ( !dlg() ) { idleListeners.length = 0; } } } /** * Creates a new idle cycle. * Params: * dlg = the delegate to be executed * priority = Priority for the idle function * fireNow = When true the delegate will be executed emmidiatly */ this(bool delegate() dlg, GPriority priority, bool fireNow=false) { idleListeners ~= dlg; idleID = g_idle_add_full(priority, cast(GSourceFunc)&idleCallback, cast(void*)this, null); if ( fireNow ) { if ( !dlg() ) { idleListeners.length = 0; } } } /** */ public void stop() { if ( idleID > 0 ) { g_source_remove(idleID); } idleListeners.length = 0; } /** * Removes the idle from gtk */ ~this() { stop(); } /** * Adds a new delegate to this idle cycle * Params: * dlg = * fireNow = */ public void addListener(bool delegate() dlg, bool fireNow=false) { idleListeners ~= dlg; if ( fireNow ) { if ( !dlg() ) { idleListeners.length = idleListeners.length - 1; } } } /** * The callback execution from glib * Params: * idle = * Returns: */ extern(C) static bool idleCallback(Idle idle) { return idle.callAllListeners(); } /** * Executes all delegates on the execution list * Returns: */ private bool callAllListeners() { bool runAgain = false; int i = 0; while ( i