Skip to content

Commit

Permalink
Carbon code no longer eats whole CPU while waiting for user input.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Oct 10, 2006
1 parent 1d00533 commit 4d87a62
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Current:
Ryan C. Gordon (Running With Scissors) - Tue Oct 10 08:52:56 EDT 2006
* Carbon code no longer eats whole CPU while waiting for user input.
Ryan C. Gordon (Gunnar Games) - Wed Sep 27 00:26:41 EDT 2006
* Carbon code now completely supports Unicode.
Ryan C. Gordon (Procedural Arts) - Sun Aug 6 07:43:51 EDT 2006
Expand Down
15 changes: 9 additions & 6 deletions carbon/carbonres.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,8 +695,7 @@ int carbon_IterateForState(CarbonRes *Res, int *StateFlag)
// Loop until the state flag has changed by some outside code or an error occurs
while(*StateFlag == Start)
{
carbon_HandlePendingEvents(Res);

carbon_HandlePendingEvents(Res, 1);
// Update any thing on the window display that needs to be updated.
//QDFlushPortBuffer(GetWindowPort(Res->Window), NULL);
}
Expand Down Expand Up @@ -960,7 +959,7 @@ void carbon_UpdateImage(CarbonRes *Res, const char *Filename, const char *Path,
}
}

void carbon_HandlePendingEvents(CarbonRes *Res)
void carbon_HandlePendingEvents(CarbonRes *Res, int sleepIfNone)
{
EventRef theEvent;
EventTargetRef theTarget;
Expand All @@ -975,6 +974,10 @@ void carbon_HandlePendingEvents(CarbonRes *Res)
SendEventToEventTarget (theEvent, theTarget);
ReleaseEvent(theEvent);
}
else if (sleepIfNone)
{
usleep(50000);
}

// readme/eula window was opened non-blocking. Handle.
if ((PromptingWindow != NULL) && (PromptResponseValid))
Expand Down Expand Up @@ -1168,7 +1171,7 @@ int carbon_Prompt(CarbonRes *Res, PromptType Type, const char *Message, char *In
// Wait for the prompt window to close
// Wait for events until the prompt window has been responded to
while(!PromptResponseValid)
carbon_HandlePendingEvents(Res);
carbon_HandlePendingEvents(Res, 1);

// HandlePendingEvents will hide window.

Expand Down Expand Up @@ -1269,7 +1272,7 @@ int carbon_ReadmeOrLicense(CarbonRes *Res, int ReadmeNotLicense, char *Message,
// Wait for the prompt window to close
// Wait for events until the prompt window has been responded to
while(!PromptResponseValid)
carbon_HandlePendingEvents(Res);
carbon_HandlePendingEvents(Res, 1);

// HandlePendingEvents will hide the window. What a mess. --ryan.

Expand Down Expand Up @@ -1834,7 +1837,7 @@ int carbon_MediaPrompt(CarbonRes *Res, int *CDRomNotDir, char *Dir, int DirLengt
// Wait for the prompt window to close
// Wait for events until the prompt window has been responded to
while(!PromptResponseValid)
carbon_HandlePendingEvents(Res);
carbon_HandlePendingEvents(Res, 1);

// HandlePendingEvents will hide window.

Expand Down
2 changes: 1 addition & 1 deletion carbon/carbonres.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ void carbon_EnableControl(CarbonRes *, int);
void carbon_SetInstallClass(CarbonRes *, int);
int carbon_GetInstallClass(CarbonRes *);
void carbon_UpdateImage(CarbonRes *, const char *, const char *, int);
void carbon_HandlePendingEvents(CarbonRes *);
void carbon_HandlePendingEvents(CarbonRes *, int);
void carbon_SetLabelText(CarbonRes *, int, const char *);
void carbon_GetLabelText(CarbonRes *, int, char *, int);
void carbon_SetEntryText(CarbonRes *, int, const char *);
Expand Down
8 changes: 4 additions & 4 deletions carbon_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ static install_state carbonui_pick_class(install_info *info)
static void carbonui_idle(install_info *info)
{
carbon_debug("***carbonui_idle()\n");
carbon_HandlePendingEvents(MyRes);
carbon_HandlePendingEvents(MyRes, 1);
}

static install_state carbonui_setup(install_info *info)
Expand Down Expand Up @@ -1349,7 +1349,7 @@ static int carbonui_update(install_info *info, const char *path, size_t progress
}

// Handle any UI events in queue
carbon_HandlePendingEvents(MyRes);
carbon_HandlePendingEvents(MyRes, 0);
return TRUE;
/*
int textlen;
Expand Down Expand Up @@ -1415,7 +1415,7 @@ static int carbonui_update(install_info *info, const char *path, size_t progress
carbon_SetProgress(MyRes, COPY_TOTAL_PROGRESS_ID, info->installed_bytes, CurTotalSize);
// Handle any UI events in queue
carbon_HandlePendingEvents(MyRes);
carbon_HandlePendingEvents(MyRes, 0);
return TRUE;*/
}

Expand Down Expand Up @@ -1533,7 +1533,7 @@ static void carbonui_shutdown(install_info *info)
carbon_debug("***carbonui_shutdown()\n");
carbon_UnloadCarbonRes(MyRes);

carbon_HandlePendingEvents(MyRes);
carbon_HandlePendingEvents(MyRes, 0);
}

int carbonui_okay(Install_UI *UI, int *argc, char ***argv)
Expand Down
4 changes: 2 additions & 2 deletions check_carbon.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Check and Rescue Tool for Loki Setup packages. Verifies the consistency of the files,
* and optionally restores them from the original installation medium.
*
* $Id: check_carbon.c,v 1.8 2006-08-06 11:45:04 icculus Exp $
* $Id: check_carbon.c,v 1.9 2006-10-10 13:00:55 icculus Exp $
*/

#include <stdlib.h>
Expand Down Expand Up @@ -389,7 +389,7 @@ int main(int argc, char *argv[])
file;
file = loki_getnext_file(file) ) {

carbon_HandlePendingEvents(Res);
carbon_HandlePendingEvents(Res, 1);
switch ( loki_check_file(file) ) {
case LOKI_REMOVED:
add_message(_("%s was REMOVED"), loki_getpath_file(file));
Expand Down
8 changes: 4 additions & 4 deletions uninstall_carbonui.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ void OnCommandUninstall()
//set_status_text(text);

// See if the user wants to cancel the uninstall
carbon_HandlePendingEvents(Res);
carbon_HandlePendingEvents(Res, 1);

// Display an optional message to the user
message = loki_getmessage_component(component->component);
Expand Down Expand Up @@ -294,7 +294,7 @@ void OnCommandUninstall()
//gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE);

// See if the user wants to cancel the uninstall
carbon_HandlePendingEvents(Res);
carbon_HandlePendingEvents(Res, 1);
}
} while((button = GoToNextComponent(button)));

Expand All @@ -316,7 +316,7 @@ void OnCommandUninstall()
//set_status_text(text);

// See if the user wants to cancel the uninstall
carbon_HandlePendingEvents(Res);
carbon_HandlePendingEvents(Res, 1);

// Display an optional message to the user
message = loki_getmessage_component(component->component);
Expand Down Expand Up @@ -352,7 +352,7 @@ void OnCommandUninstall()
//gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE);

// See if the user wants to cancel the uninstall
carbon_HandlePendingEvents(Res);
carbon_HandlePendingEvents(Res, 1);

break;
}
Expand Down

0 comments on commit 4d87a62

Please sign in to comment.