Skip to content

Commit

Permalink
Refactor.
Browse files Browse the repository at this point in the history
Increments-patch-version-of: ttyr-api
Increments-patch-version-of: ttyr-terminal
Increments-patch-version-of: ttyr-tty
Increments-patch-version-of: misc
  • Loading branch information
dajofrey committed Oct 5, 2024
1 parent 4f98d99 commit 9d71b7d
Show file tree
Hide file tree
Showing 81 changed files with 1,870 additions and 1,865 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ For building.
The following dependencies **are automatically compiled** during the build process.

* [Netzhaut](https://github.com/dajofrey/netzhaut)
TTýr is companion project to [Netzhaut](https://github.com/dajofrey/netzhaut), from which it requires nhapi, nhcore, nhencoding, nhwsi and nhgfx modules.
TTýr is companion project to [Netzhaut](https://github.com/dajofrey/netzhaut), from which it requires nh-api, nh-core, nh-encoding, nh-wsi and nh-gfx modules.
* [st](https://st.suckless.org/)
For shell functionality, TTýr uses parts of the great [st](https://st.suckless.org/).

Expand Down
4 changes: 2 additions & 2 deletions build/automation/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CFLAGS = -fPIC -std=gnu99 -Wl,-rpath,$(CURDIR)/lib,-rpath,$(NETZHAUT_PATH)/lib
LD = gcc
LDFLAGS_TTYR_TTY = -lutil -Lexternal/st-0.8.5/ -l:libst.so
LDFLAGS_TTYR_TERMINAL =
LDFLAGS_TTYR = -Llib -lttyr-api -L$(NETZHAUT_PATH)/lib -lnhapi
LDFLAGS_TTYR = -Llib -lttyr-api -L$(NETZHAUT_PATH)/lib -lnh-api

# Define the source file directory for each library
SRC_DIR_TTYR_TTY = src/lib/ttyr-tty
Expand Down Expand Up @@ -92,7 +92,7 @@ BIN_TTYR = bin/ttyr

build_netzhaut:
ifeq ($(NETZHAUT_PATH),$(CURDIR)/external/Netzhaut)
(cd external/Netzhaut && git submodule update --init --recursive && make -f build/automation/lib.mk nhapi.so nhcore.so nhencoding.so nhwsi.so nhgfx.so)
(cd external/Netzhaut && git submodule update --init --recursive && make -f build/automation/lib.mk nh-api.so nh-core.so nh-encoding.so nh-wsi.so nh-gfx.so)
endif

create_lib_dir:
Expand Down
34 changes: 17 additions & 17 deletions src/bin/ttyr/Main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// INCLUDES ========================================================================================

#include "ttyr-api/ttyr-api.h"
#include "nhapi/nhapi.h"
#include "nh-api/nh-api.h"

#include <stdlib.h>
#include <stdio.h>
Expand All @@ -19,26 +19,26 @@
// TYPES ===========================================================================================

typedef struct Arguments {
NH_GFX_API_E renderer;
NH_API_GRAPHICS_BACKEND_E renderer;
bool no_unload;
} Arguments;

static Arguments Args;
static nh_PixelPosition Position = {0};
static nh_gfx_Viewport *Viewport_p = NULL;
static nh_api_PixelPosition Position = {0};
static nh_api_Viewport *Viewport_p = NULL;
static ttyr_tty_TTY *TTY_p = NULL;

// HELPER ==========================================================================================

static int handleArgs(
int argc, char **argv_pp)
{
Args.renderer = NH_GFX_API_OPENGL;
Args.renderer = NH_API_GRAPHICS_BACKEND_OPENGL;
Args.no_unload = false;

for (int i = 1; i < argc; ++i) {
if (!strcmp(argv_pp[i], "--vulkan")) {
Args.renderer = NH_GFX_API_VULKAN;
Args.renderer = NH_API_GRAPHICS_BACKEND_VULKAN;
}
if (!strcmp(argv_pp[i], "--no-unload")) {
Args.no_unload = true;
Expand All @@ -55,24 +55,24 @@ static int handleArgs(
}

static void handleInput(
nh_wsi_Window *Window_p, nh_wsi_Event Event)
nh_api_Window *Window_p, nh_api_WSIEvent Event)
{
switch (Event.type)
{
case NH_WSI_EVENT_MOUSE :
case NH_WSI_EVENT_KEYBOARD :
case NH_API_WSI_EVENT_MOUSE :
case NH_API_WSI_EVENT_KEYBOARD :
ttyr_api_sendEvent(TTY_p, Event);
break;
case NH_WSI_EVENT_WINDOW :
case NH_API_WSI_EVENT_WINDOW :
switch (Event.Window.type)
{
case NH_WSI_WINDOW_CONFIGURE :
case NH_API_WINDOW_CONFIGURE :
if (Viewport_p) {
nh_api_configureViewport(Viewport_p, Position, Event.Window.Size);
}
break;
case NH_WSI_WINDOW_FOCUS_OUT :
case NH_WSI_WINDOW_FOCUS_IN :
case NH_API_WINDOW_FOCUS_OUT :
case NH_API_WINDOW_FOCUS_IN :
ttyr_api_sendEvent(TTY_p, Event);
break;
}
Expand All @@ -85,7 +85,7 @@ static void handleInput(
int main(int argc, char **argv_pp)
{
if (handleArgs(argc, argv_pp)) {return 1;}
if (nh_api_initialize(NULL, NULL, 0) != NH_CORE_SUCCESS) {return 1;}
if (nh_api_initialize(NULL, NULL, 0) != NH_API_SUCCESS) {return 1;}

nh_api_registerConfig("/etc/ttyr.conf", 14);

Expand All @@ -97,14 +97,14 @@ int main(int argc, char **argv_pp)
ttyr_terminal_Terminal *Terminal_p = ttyr_api_openTerminal(NULL, TTY_p);
if (!Terminal_p) {return 1;}

nh_wsi_Window *Window_p =
nh_api_Window *Window_p =
nh_api_createWindow(NULL, nh_api_getSurfaceRequirements());
if (!Window_p) {return 1;}

nh_gfx_Surface *Surface_p = nh_api_createSurface(Window_p, Args.renderer);
nh_api_Surface *Surface_p = nh_api_createSurface(Window_p, Args.renderer);
if (!Surface_p) {return 1;}

nh_PixelSize Size;
nh_api_PixelSize Size;
Size.width = 3000;
Size.height = 2000;

Expand Down
10 changes: 5 additions & 5 deletions src/lib/ttyr-api/ttyr-terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "ttyr-terminal.h"
#include "ttyr-api.h"

#include "nhcore/Loader/Loader.h"
#include "nh-core/Loader/Loader.h"

// TYPEDEFS ========================================================================================

Expand All @@ -20,15 +20,15 @@ typedef ttyr_terminal_Terminal *(*ttyr_terminal_openTerminal_f)(
);

typedef TTYR_TERMINAL_RESULT (*ttyr_terminal_cmd_setViewport_f)(
ttyr_terminal_Terminal *Terminal_p, nh_gfx_Viewport *Viewport_p
ttyr_terminal_Terminal *Terminal_p, nh_api_Viewport *Viewport_p
);

// FUNCTIONS =======================================================================================

static bool added = false;
static const char name_p[] = "ttyr-terminal";
static const char *dependencies_pp[16] = {
"nhgfx",
"nh-gfx",
"ttyr-tty",
};

Expand All @@ -44,7 +44,7 @@ static bool ttyr_api_add() {
}

ttyr_terminal_Terminal *ttyr_api_openTerminal(
NH_BYTE *config_p, ttyr_tty_TTY *TTY_p)
char *config_p, ttyr_tty_TTY *TTY_p)
{
if (!ttyr_api_add()) {return NULL;}

Expand All @@ -53,7 +53,7 @@ ttyr_terminal_Terminal *ttyr_api_openTerminal(
}

TTYR_TERMINAL_RESULT ttyr_api_setViewport(
ttyr_terminal_Terminal *Terminal_p, nh_gfx_Viewport *Viewport_p)
ttyr_terminal_Terminal *Terminal_p, nh_api_Viewport *Viewport_p)
{
if (!ttyr_api_add()) {return TTYR_TERMINAL_ERROR_BAD_STATE;}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/ttyr-api/ttyr-terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
* Published under GNU LGPL. See TTyr/LICENSE.LGPL file.
*/

#include <stdbool.h>
#include "ttyr-tty.h"
#include <stdbool.h>

#endif

Expand Down Expand Up @@ -79,7 +79,7 @@
* @return @ref TTYR_TERMINAL_SUCCESS on success.
*/
TTYR_TERMINAL_RESULT ttyr_api_setViewport(
ttyr_terminal_Terminal *Terminal_p, nh_gfx_Viewport *Viewport_p
ttyr_terminal_Terminal *Terminal_p, nh_api_Viewport *Viewport_p
);

/** @} */
Expand Down
10 changes: 5 additions & 5 deletions src/lib/ttyr-api/ttyr-tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "ttyr-tty.h"
#include "ttyr-api.h"

#include "nhcore/Loader/Loader.h"
#include "nh-core/Loader/Loader.h"

#include <stdio.h>
#include <stdlib.h>
Expand All @@ -35,15 +35,15 @@ typedef TTYR_TTY_RESULT (*ttyr_tty_cmd_unclaimStandardIO_f)(
);

typedef TTYR_TTY_RESULT (*ttyr_tty_cmd_sendEvent_f)(
ttyr_tty_TTY *TTY_p, nh_wsi_Event Event
ttyr_tty_TTY *TTY_p, nh_api_WSIEvent Event
);

// ADD =============================================================================================

static bool added = false;
static const char name_p[] = "ttyr-tty";
static const char *dependencies_pp[16] = {
"nhencoding",
"nh-encoding",
};

static bool ttyr_api_add() {
Expand All @@ -58,7 +58,7 @@ static bool ttyr_api_add() {
}

ttyr_tty_TTY *ttyr_api_openTTY(
NH_BYTE *config_p, ttyr_tty_Interface *Interface_p)
char *config_p, ttyr_tty_Interface *Interface_p)
{
if (!ttyr_api_add()) {return NULL;}

Expand Down Expand Up @@ -94,7 +94,7 @@ TTYR_TTY_RESULT ttyr_api_unclaimStandardIO(
}

TTYR_TTY_RESULT ttyr_api_sendEvent(
ttyr_tty_TTY *TTY_p, nh_wsi_Event Event)
ttyr_tty_TTY *TTY_p, nh_api_WSIEvent Event)
{
if (!ttyr_api_add()) {return TTYR_TTY_ERROR_BAD_STATE;}

Expand Down
16 changes: 8 additions & 8 deletions src/lib/ttyr-api/ttyr-tty.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Published under GNU LGPL. See TTyr/LICENSE.LGPL file.
*/

#include "nhapi/nhapi.h"
#include "nh-api/nh-api.h"
#include <stdbool.h>

#endif
Expand Down Expand Up @@ -71,9 +71,9 @@
typedef TTYR_TTY_RESULT (*ttyr_tty_draw_f)(ttyr_tty_Program *Program_p, ttyr_tty_Glyph *Glyphs_p, int width, int height, int row);
typedef TTYR_TTY_RESULT (*ttyr_tty_drawTopbar_f)(ttyr_tty_Program *Program_p, ttyr_tty_Glyph *Glyphs_p, int width);
typedef TTYR_TTY_RESULT (*ttyr_tty_getCursorPosition_f)(ttyr_tty_Program *Program_p, int *x_p, int *y_p);
typedef TTYR_TTY_RESULT (*ttyr_tty_handleInput_f)(ttyr_tty_Program *Program_p, nh_wsi_Event Event);
typedef TTYR_TTY_RESULT (*ttyr_tty_handleInput_f)(ttyr_tty_Program *Program_p, nh_api_WSIEvent Event);
typedef TTYR_TTY_RESULT (*ttyr_tty_update_f)(ttyr_tty_Program *Program_p);
typedef TTYR_TTY_RESULT (*ttyr_tty_handleCommand_f)(ttyr_tty_Program *Program_p, nh_List *Arguments_p);
typedef TTYR_TTY_RESULT (*ttyr_tty_handleCommand_f)(ttyr_tty_Program *Program_p);
typedef void (*ttyr_tty_destroy_f)(void *p);
typedef void (*ttyr_tty_destroyPrototype_f)(ttyr_tty_Interface *Prototype_p);

Expand Down Expand Up @@ -101,7 +101,7 @@
ttyr_tty_GlyphAttributes Attributes;
ttyr_tty_GlyphColor Foreground;
ttyr_tty_GlyphColor Background;
NH_ENCODING_UTF32 codepoint; /* character code */
NH_API_UTF32 codepoint; /* character code */
TTYR_TTY_MARK_E mark;
} ttyr_tty_Glyph;

Expand All @@ -123,9 +123,9 @@
} ttyr_tty_InterfaceCallbacks;

typedef struct ttyr_tty_Interface {
nh_encoding_UTF32String Name;
nh_encoding_UTF32String *CommandNames_p;
int commands;
NH_API_UTF32 name_p[64];
NH_API_UTF32 **commands_pp;
unsigned int commands;
ttyr_tty_InterfaceCallbacks Callbacks;
void *initArg_p;
} ttyr_tty_Interface;
Expand Down Expand Up @@ -188,7 +188,7 @@
* Todo.
*/
TTYR_TTY_RESULT ttyr_api_sendEvent(
ttyr_tty_TTY *TTY_p, nh_wsi_Event Event
ttyr_tty_TTY *TTY_p, nh_api_WSIEvent Event
);

/** @} */
Expand Down
14 changes: 7 additions & 7 deletions src/lib/ttyr-terminal/Common/Config.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@

#include "../Terminal/Terminal.h"

#include "nhcore/Config/Config.h"
#include "nhcore/System/Memory.h"
#include "nhcore/System/Thread.h"
#include "nh-core/Config/Config.h"
#include "nh-core/System/Memory.h"
#include "nh-core/System/Thread.h"

#include <string.h>
#include <stdlib.h>

// NAMES ===========================================================================================

const NH_BYTE *TTYR_TERMINAL_SETTING_NAMES_PP[] = {
const char *TTYR_TERMINAL_SETTING_NAMES_PP[] = {
"ttyr.terminal.font.size",
"ttyr.terminal.blink.frequency",
"ttyr.terminal.color.foreground",
Expand All @@ -34,7 +34,7 @@ const NH_BYTE *TTYR_TERMINAL_SETTING_NAMES_PP[] = {
size_t TTYR_TERMINAL_SETTING_NAMES_PP_COUNT =
sizeof(TTYR_TERMINAL_SETTING_NAMES_PP) / sizeof(TTYR_TERMINAL_SETTING_NAMES_PP[0]);

const NH_BYTE *ttyr_terminal_getSettingName(
const char *ttyr_terminal_getSettingName(
TTYR_TERMINAL_SETTING_E setting)
{
TTYR_TERMINAL_BEGIN()
Expand All @@ -44,11 +44,11 @@ TTYR_TERMINAL_END(TTYR_TERMINAL_SETTING_NAMES_PP[setting])
// FUNCTIONS =======================================================================================

static TTYR_TERMINAL_RESULT ttyr_terminal_getSetting(
ttyr_terminal_Config *Config_p, NH_BYTE namespace_p[255], int setting)
ttyr_terminal_Config *Config_p, char namespace_p[255], int setting)
{
TTYR_TERMINAL_BEGIN()

nh_List *Setting_p = nh_core_getGlobalConfigSetting(namespace_p, -1, TTYR_TERMINAL_SETTING_NAMES_PP[setting]);
nh_core_List *Setting_p = nh_core_getGlobalConfigSetting(namespace_p, -1, TTYR_TERMINAL_SETTING_NAMES_PP[setting]);
TTYR_TERMINAL_CHECK_NULL(Setting_p)

switch (setting) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/ttyr-terminal/Common/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* @{
*/

extern const NH_BYTE *TTYR_TERMINAL_SETTING_NAMES_PP[];
extern const char *TTYR_TERMINAL_SETTING_NAMES_PP[];
extern size_t TTYR_TERMINAL_SETTING_NAMES_PP_COUNT;

/** @} */
Expand All @@ -59,7 +59,7 @@
* @{
*/

const NH_BYTE *ttyr_terminal_getSettingName(
const char *ttyr_terminal_getSettingName(
TTYR_TERMINAL_SETTING_E setting
);

Expand Down
12 changes: 6 additions & 6 deletions src/lib/ttyr-terminal/Common/Initialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

#include "../Vulkan/Pipeline.h"

#include "nhgfx/Vulkan/GPU.h"
#include "nhgfx/Vulkan/Vulkan.h"
#include "nh-gfx/Vulkan/GPU.h"
#include "nh-gfx/Vulkan/Vulkan.h"

#include "nhcore/Config/Config.h"
#include "nhcore/System/Logger.h"
#include "nhcore/System/Memory.h"
#include "nh-core/Config/Config.h"
#include "nh-core/System/Logger.h"
#include "nh-core/System/Memory.h"

#include <stdlib.h>
#include <string.h>
Expand All @@ -31,7 +31,7 @@ TTYR_TERMINAL_RESULT ttyr_terminal_initialize()
{
TTYR_TERMINAL_BEGIN()

nh_core_appendConfig(ttyr_terminal_conf_inc, ttyr_terminal_conf_inc_len, NH_FALSE);
nh_core_appendConfig(ttyr_terminal_conf_inc, ttyr_terminal_conf_inc_len, false);

for (int i = 0; i < NH_VULKAN.GPUs.size; ++i)
{
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ttyr-terminal/Common/Initialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#endif

/** @addtogroup lib_nhcss_functions
/** @addtogroup lib_nh-css_functions
* @{
*/

Expand Down
Loading

0 comments on commit 9d71b7d

Please sign in to comment.