Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions package/garlicui/src/clock.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <sys/time.h>
#include <sys/ioctl.h>
#ifdef __linux__
#include <linux/rtc.h>
#endif
#include <fcntl.h>

#include "clock.h"
Expand Down Expand Up @@ -66,6 +68,7 @@ void clock_set_current_time(time_t timestamp, int utc_offset)
// Open the device for read/write access
int dev_fd = open(dev_path, O_RDWR);

#ifdef __linux__
// We managed to open the device for read/write access
if (dev_fd >= 0)
{
Expand All @@ -87,6 +90,7 @@ void clock_set_current_time(time_t timestamp, int utc_offset)
// Close the device
close(dev_fd);
}
#endif

// Free the device path buffer
free(dev_path);
Expand Down
155 changes: 152 additions & 3 deletions package/garlicui/src/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ struct gui_context * gui_create_context(int argc, char * argv[])

// Render the east face button icon
context->surfaces.bars.bottom.actions.select.surface = gui_render_select_legend_surface(context);

// We failed to render the east face button icon
if (context->surfaces.bars.bottom.actions.select.surface == NULL)
{
Expand Down Expand Up @@ -586,6 +586,7 @@ struct gui_context * gui_create_context(int argc, char * argv[])
context->surfaces.overlays.notch.position.w = context->surfaces.overlays.notch.surface->w;
context->surfaces.overlays.notch.position.h = context->surfaces.overlays.notch.surface->h;

#ifndef __MACOSX__
// We couldn't enumerate the joysticks
if (SDL_NumJoysticks() <= 0)
{
Expand All @@ -602,7 +603,7 @@ struct gui_context * gui_create_context(int argc, char * argv[])
// No use going further if we have no way of controlling the UI
goto free_menu_action_surface;
}

#endif
// Allocate memory for the additional main menu data
main_menu_node_data = calloc(1, sizeof(struct gui_menu_node_data));

Expand Down Expand Up @@ -630,7 +631,9 @@ struct gui_context * gui_create_context(int argc, char * argv[])
context->menu.root->activate(context->menu.root);

// Enable joystick input
#ifndef __MACOSX__
SDL_JoystickEventState(SDL_ENABLE);
#endif

// Restore the previous UI state
gui_restore_ui_state(context, (const char *)context->settings.ui_state);
Expand Down Expand Up @@ -684,8 +687,10 @@ struct gui_context * gui_create_context(int argc, char * argv[])
free(main_menu_node_data);

close_internal_joystick:
#ifndef __MACOSX__
// Close the internal joystick
SDL_JoystickClose(context->inputs.internal.joystick);
#endif

free_notch_overlay_surface:
// Free the notch overlay
Expand Down Expand Up @@ -1026,6 +1031,150 @@ void gui_update(struct gui_context * context)
// Differentiate input event types
switch (event.type)
{
// Keyboard button events
case SDL_KEYUP:
case SDL_KEYDOWN:
{
// Determine the pressed state
int pressed = event.type == SDL_KEYDOWN;

// Differentiate between buttons
switch (event.key.keysym.sym)
{
// The up button
case SDLK_UP:
{
// Update
context->inputs.internal.current.dpad_y = pressed ? -1 : 0;

// Break
break;
}

// The right button
case SDLK_RIGHT:
{
// Update
context->inputs.internal.current.dpad_x = pressed ? 1 : 0;

// Break
break;
}

// The down button
case SDLK_DOWN:
{
// Update
context->inputs.internal.current.dpad_y = pressed ? 1 : 0;

// Break
break;
}

// The left button
case SDLK_LEFT:
{
// Update
context->inputs.internal.current.dpad_x = pressed ? -1 : 0;

// Break
break;
}

// The south-facing face button (A on XBOX, B on Nintendo, Cross on PlayStation)
case SDLK_z:
{
// Update
context->inputs.internal.current.south = pressed;

// Break
break;
}

// The east-facing face button (B on XBOX, A on Nintendo, Circle on PlayStation)
case SDLK_x:
{
// Update
context->inputs.internal.current.east = pressed;

// Break
break;
}

// The north-facing face button (Y on XBOX, X on Nintendo, Triangle on PlayStation)
case SDLK_c:
{
// Update
context->inputs.internal.current.north = pressed;

// Break
break;
}

// The west-facing face button (X on XBOX, Y on Nintendo, Square on PlayStation)
case SDLK_v:
{
// Update
context->inputs.internal.current.west = pressed;

// Break
break;
}

// The enter button
case SDLK_RETURN:
{
// Update
context->inputs.internal.current.start = pressed;

// Break
break;
}

// The backspace button
case SDLK_BACKSPACE:
{
// Update
context->inputs.internal.current.select = pressed;

// Break
break;
}

// The space button
case SDLK_SPACE:
{
// Update
context->inputs.internal.current.mode = pressed;

// Break
break;
}

// The escape button
case SDLK_ESCAPE:
{
// Update
context->inputs.internal.current.power = pressed;

// Break
break;
}

// Other buttons
default:
{
// Break
break;
}
}

// Log the event
// printf("button %d state %d\n", event.jbutton.button, pressed);

// Break
break;
}
// Regular button events
case SDL_JOYBUTTONUP:
case SDL_JOYBUTTONDOWN:
Expand Down Expand Up @@ -1888,4 +2037,4 @@ void gui_write_configuration(struct gui_context * context)
// Cleanup
xmlFreeDoc(document);
}
}
}
6 changes: 5 additions & 1 deletion package/garlicui/src/gui_main_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include "gui_context_menu.h"
#include "gui_retroarch_menu.h"

#ifndef VERSION
#define VERSION "dev"
#endif

/**
* @brief Activates the main menu.
*/
Expand Down Expand Up @@ -143,4 +147,4 @@ static void gui_invalidate_main_menu(struct gui_node * this)
}
}

#endif
#endif
13 changes: 13 additions & 0 deletions package/garlicui/src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,12 @@ int io_get_content_items(const char * path, char *** items, int include_files, i
// Open the given directory
DIR * directory = opendir(path);

// We failed to open the directory
if (directory == NULL)
{
return 0;
}

// The collected items
char ** collected_items = NULL;

Expand Down Expand Up @@ -929,6 +935,13 @@ void io_shutdown()
// Close the SysRq trigger file
fclose(sysrq);
}
#ifdef __MACOSX__
else
{
// Exit the application
exit(0);
}
#endif
}

/**
Expand Down
22 changes: 13 additions & 9 deletions package/garlicui/src/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
*/
typedef char * (*textformatter)(const char *);

/**
* @brief The directory in which all boot related files are stored.
*
* This includes the boot script, rootfs, global configuration file, etc.
*/
#ifdef __MACOSX__
#define FOLDER_CONFIGURATION_BOOT_FOLDER ""
#else
#define FOLDER_CONFIGURATION_BOOT_FOLDER "/media/boot/"
#endif

/**
* @brief The folder that contains the game library template.
*/
Expand All @@ -29,14 +40,7 @@ typedef char * (*textformatter)(const char *);
/**
* @brief The folder that contains the icon overrides.
*/
#define ICON_FOLDER_PATH "/media/boot/icons"

/**
* @brief The directory in which all boot related files are stored.
*
* This includes the boot script, rootfs, global configuration file, etc.
*/
#define FOLDER_CONFIGURATION_BOOT_FOLDER "/media/boot"
#define ICON_FOLDER_PATH FOLDER_CONFIGURATION_BOOT_FOLDER "icons"

/**
* @brief The folder icon file name.
Expand Down Expand Up @@ -189,4 +193,4 @@ void io_copy_directory(const char * src_dir, const char * dest_dir);
*/
void io_unpack_resources();

#endif
#endif
8 changes: 7 additions & 1 deletion package/garlicui/src/localization.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <unicode/ustring.h>

#include "icon.h"
#include "localization.h"

Expand Down Expand Up @@ -32,7 +34,11 @@ const char * localization_font_file_path(const char * locale)
if (strcmp(localized_font_file_path, font_file_path_msgid) == 0)
{
// Fall back to a semi-safe latin default font (better than nothing)
#ifdef __MACOSX__
localized_font_file_path = "/System/Library/Fonts/Monaco.ttf";
#else
localized_font_file_path = "/usr/share/fonts/oswald/Oswald-Regular.ttf";
#endif
}

// Copy the localized font file path into the static buffer
Expand Down Expand Up @@ -204,4 +210,4 @@ int localization_get_supported_locales(char *** locales)

// Return the number of supported locales
return num_locales;
}
}
5 changes: 5 additions & 0 deletions package/garlicui/src/sdl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
#include <SDL/SDL_gfxPrimitives.h>
#include <librsvg/rsvg.h>

// https://github.com/OpenDingux/SDL/blob/dd7260f1d7f79a58aba95a03fd6532729181eadb/include/SDL_main.h#L54
#if defined(main)
#undef main
#endif

/**
* @brief Fills the given SDL surface with a solid color.
*
Expand Down