Skip to content

Commit

Permalink
Update wrap files to work with gir-to-d >= 0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
ximion committed Apr 16, 2018
1 parent 9fadf28 commit 3a4b158
Show file tree
Hide file tree
Showing 3 changed files with 394 additions and 251 deletions.
202 changes: 84 additions & 118 deletions contrib/girwrap/APILookupGLib.txt
Original file line number Diff line number Diff line change
Expand Up @@ -441,28 +441,25 @@ class: Idle
cType:
code: start
/** Holds all idle delegates */
bool delegate()[] idleListeners;
/** our idle ID */
uint idleID;
private bool delegate()[] idleListeners;
/** Our idle ID */
private uint idleID;
/** The priority this class was instantiated with */
private GPriority priority = GPriority.DEFAULT_IDLE;

/**
* 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)
{
if ( fireNow && !dlg() )
return;

idleListeners ~= dlg;
idleID = g_idle_add(cast(GSourceFunc)&idleCallback, cast(void*)this);
if ( fireNow )
{
if ( !dlg() )
{
idleListeners.length = 0;
}
}
idleID = g_idle_add_full(priority, cast(GSourceFunc)&idleCallback, cast(void*)this, cast(GDestroyNotify)&destroyIdleNotify);
}

/**
Expand All @@ -474,25 +471,20 @@ code: start
*/
this(bool delegate() dlg, GPriority priority, bool fireNow=false)
{
this.priority = priority;

if ( fireNow && !dlg() )
return;

idleListeners ~= dlg;
idleID = g_idle_add_full(priority, cast(GSourceFunc)&idleCallback, cast(void*)this, null);
if ( fireNow )
{
if ( !dlg() )
{
idleListeners.length = 0;
}
}
idleID = g_idle_add_full(priority, cast(GSourceFunc)&idleCallback, cast(void*)this, cast(GDestroyNotify)&destroyIdleNotify);
}

/** */
public void stop()
{
if ( idleID > 0 )
{
g_source_remove(idleID);
}
idleListeners.length = 0;
}

/**
Expand All @@ -511,42 +503,29 @@ code: start
*/
public void addListener(bool delegate() dlg, bool fireNow=false)
{
if ( fireNow && !dlg() )
return;

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();
if ( idleID == 0 )
idleID = g_idle_add_full(priority, cast(GSourceFunc)&idleCallback, cast(void*)this, cast(GDestroyNotify)&destroyIdleNotify);
}

/**
/*
* Executes all delegates on the execution list
* Returns:
* Returns: false if the callback should be removed.
*/
private bool callAllListeners()
extern(C) static bool idleCallback(Idle idle)
{
bool runAgain = false;

int i = 0;

while ( i<idleListeners.length )
while ( i<idle.idleListeners.length )
{
if ( !idleListeners[i]() )
if ( !idle.idleListeners[i]() )
{
idleListeners = idleListeners[0..i] ~ idleListeners[i+1..idleListeners.length];
idle.idleListeners = idle.idleListeners[0..i] ~ idle.idleListeners[i+1..$];
}
else
{
Expand All @@ -555,12 +534,17 @@ code: start
}
}

// Set idleID to 0 if all delegates are removed
if (idleListeners.length == 0)
idleID = 0;

return runAgain;
}

/*
* Reset the idle object when it's destroyed on the GTK side.
*/
extern(C) static void destroyIdleNotify(Idle idle)
{
idle.idleListeners.length = 0;
idle.idleID = 0;
}
code: end

struct: IOChannel
Expand Down Expand Up @@ -686,7 +670,16 @@ namespace:
code: start
public T* sliceNew(T)()
{
return cast(T*)g_slice_alloc0(T.sizeof);
// We cant use sliceAlloc for the GLib array types.
// the actual array structs are larger than the ones used in the API.
static if ( is( T == GArray ) )
return g_array_new(false, false, 1);
else static if ( is( T == GByteArray ) )
return g_byte_array_new();
else static if ( is( T == GPtrArray ) )
return g_ptr_array_new();
else
return cast(T*)g_slice_alloc0(T.sizeof);
}

public T* sliceAlloc(T)()
Expand Down Expand Up @@ -1191,7 +1184,7 @@ code: start
}

/** */
public static char** toStringzArray(string[] args)
public static char** toStringzArray(string[] args) pure
{
if ( args is null )
{
Expand All @@ -1209,7 +1202,7 @@ code: start
}

/** */
public static char*** toStringzArray(string[][] args)
public static char*** toStringzArray(string[][] args) pure
{
if ( args is null )
{
Expand Down Expand Up @@ -1258,7 +1251,7 @@ code: start
}

/** */
public static string[][] toStringArray(char*** args)
public static string[][] toStringArray(char*** args) pure
{
string[][] argv;

Expand Down Expand Up @@ -1311,10 +1304,10 @@ struct: Timeout
class: Timeout
cType:
code: start
/** Holds all timeout delegates */
bool delegate()[] timeoutListeners;
/** our gtk timeout ID */
uint timeoutID;
/** Holds all idle delegates */
private bool delegate()[] timeoutListeners;
/** Our timeout ID */
private uint timeoutID;


/**
Expand All @@ -1332,15 +1325,11 @@ code: start
*/
this(uint interval, bool delegate() dlg, bool fireNow=false)
{
if ( fireNow && !dlg() )
return;

timeoutListeners ~= dlg;
timeoutID = g_timeout_add(interval, cast(GSourceFunc)&timeoutCallback, cast(void*)this);
if ( fireNow )
{
if ( !dlg() )
{
timeoutListeners.length = 0;
}
}
timeoutID = g_timeout_add_full(GPriority.DEFAULT, interval, cast(GSourceFunc)&timeoutCallback, cast(void*)this, cast(GDestroyNotify)&destroyTimeoutNotify);
}

/**
Expand All @@ -1353,15 +1342,11 @@ code: start
*/
this(uint interval, bool delegate() dlg, GPriority priority, bool fireNow=false)
{
if ( fireNow && !dlg() )
return;

timeoutListeners ~= dlg;
timeoutID = g_timeout_add_full(priority, interval, cast(GSourceFunc)&timeoutCallback, cast(void*)this, null);
if ( fireNow )
{
if ( !dlg() )
{
timeoutListeners.length = 0;
}
}
timeoutID = g_timeout_add_full(priority, interval, cast(GSourceFunc)&timeoutCallback, cast(void*)this, cast(GDestroyNotify)&destroyTimeoutNotify);
}

/**
Expand All @@ -1373,15 +1358,11 @@ code: start
*/
this(bool delegate() dlg, uint seconds, bool fireNow=false)
{
if ( fireNow && !dlg() )
return;

timeoutListeners ~= dlg;
timeoutID = g_timeout_add_seconds(seconds, cast(GSourceFunc)&timeoutCallback, cast(void*)this);
if ( fireNow )
{
if ( !dlg() )
{
timeoutListeners.length = 0;
}
}
timeoutID = g_timeout_add_seconds_full(GPriority.DEFAULT, seconds, cast(GSourceFunc)&timeoutCallback, cast(void*)this, cast(GDestroyNotify)&destroyTimeoutNotify);
}

/**
Expand All @@ -1394,26 +1375,20 @@ code: start
*/
this(bool delegate() dlg, uint seconds, GPriority priority, bool fireNow=false)
{
if ( fireNow && !dlg() )
return;

timeoutListeners ~= dlg;
timeoutID = g_timeout_add_seconds_full(priority, seconds, cast(GSourceFunc)&timeoutCallback, cast(void*)this, null);
if ( fireNow )
{
if ( !dlg() )
{
timeoutListeners.length = 0;
}
}
timeoutID = g_timeout_add_seconds_full(priority, seconds, cast(GSourceFunc)&timeoutCallback, cast(void*)this, cast(GDestroyNotify)&destroyTimeoutNotify);
}

/** */
/** Removes the timeout from gtk */
public void stop()
{
if ( timeoutID > 0 )
{
g_source_remove(timeoutID);
}
timeoutID = 0;
timeoutListeners.length = 0;
}

/**
Expand All @@ -1432,14 +1407,10 @@ code: start
*/
public void addListener(bool delegate() dlg, bool fireNow=false)
{
if ( fireNow && !dlg() )
return;

timeoutListeners ~= dlg;
if ( fireNow )
{
if ( !dlg() )
{
timeoutListeners.length = timeoutListeners.length - 1;
}
}
}

/**
Expand All @@ -1449,25 +1420,15 @@ code: start
* Returns:
*/
extern(C) static bool timeoutCallback(Timeout timeout)
{
return timeout.callAllListeners();
}

/**
* Executes all delegates on the execution list
* Returns:
*/
private bool callAllListeners()
{
bool runAgain = false;

int i = 0;

while ( i<timeoutListeners.length )
while ( i<timeout.timeoutListeners.length )
{
if ( !timeoutListeners[i]() )
if ( !timeout.timeoutListeners[i]() )
{
timeoutListeners = timeoutListeners[0..i] ~ timeoutListeners[i+1..timeoutListeners.length];
timeout.timeoutListeners = timeout.timeoutListeners[0..i] ~ timeout.timeoutListeners[i+1..$];
}
else
{
Expand All @@ -1476,12 +1437,17 @@ code: start
}
}

// Set timeoutID to 0 if all delegates are removed
if (timeoutListeners.length == 0)
timeoutID = 0;

return runAgain;
}

/*
* Reset the timeout object when it's destroyed on the GTK side.
*/
extern(C) static void destroyTimeoutNotify(Timeout timeout)
{
timeout.timeoutListeners.length = 0;
timeout.timeoutID = 0;
}
code: end

struct: TimeZone
Expand Down
Loading

0 comments on commit 3a4b158

Please sign in to comment.