initial commit - very silly!

This commit is contained in:
2024-03-24 06:45:01 +01:00
commit c9aa439e2c
14 changed files with 434 additions and 0 deletions

7
.gitignore vendored Normal file
View File

@@ -0,0 +1,7 @@
build
*.o
*.gch
kyoutest
tiny-kyoukai
*.swp
.vscode

84
Makefile Normal file
View File

@@ -0,0 +1,84 @@
PROJECT_NAME = tiny-kyoukai
BUILD_DIR = build
CC = gcc
CFLAGS = -std=c11
LDFLAGS =
LIBS = gtk4
LDLIBS = $(shell if [ -n "$(LIBS)" ]; then pkg-config -libs $(LIBS); fi)
INCLUDES = $(shell if [ -n "$(LIBS)" ]; then pkg-config -cflags $(LIBS); fi) -Isrc/includes
SRC = $(shell find src/ -type f -name '*.c') main.c
NOM = $(basename $(notdir $(SRC)))
OBJ = $(addprefix $(BUILD_DIR)/,$(addsuffix .o, $(NOM)))
#------------------------------------------------------------------------------
# MAIN BUILD RULES
#------------------------------------------------------------------------------
# Build all the .o files in src dir
$(BUILD_DIR)/%.o: src/%.c
$(CC) $(CFLAGS) -c $< $(INCLUDES) -o $(BUILD_DIR)/$(notdir $@)
# Build all the .o files in base dir
$(BUILD_DIR)/%.o: %.c
$(CC) $(CFLAGS) -c $< $(INCLUDES) -o $(BUILD_DIR)/$(notdir $@)
# Main program
$(PROJECT_NAME): $(OBJ)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
# Helloworld
kyoutest: $(BUILD_DIR)/helloworld.o
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
#------------------------------------------------------------------------------
# SILLY RULES
#------------------------------------------------------------------------------
always: SUSSYBAKA
@echo "Aloha :3"
SUSSYBAKA:
#------------------------------------------------------------------------------
# UTILITIES
#------------------------------------------------------------------------------
all: init build
build: $(PROJECT_NAME) localecho
rebuild: clean build
dev: build run
init: $(BUILD_DIR) clear
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
test:
@echo CC: $(CC)
@echo CFLAGS: $(CFLAGS)
@echo LDFLAGS: $(LDFLAGS)
@echo LDLIBS: $(LDLIBS)
@echo OBJ: $(OBJ)
@echo SRC: $(SRC)
@echo INCLUDES: $(INCLUDES)
run: $(PROJECT_NAME)
./$(PROJECT_NAME)
clean:
@rm -rif *.o *.gch
clear: clean
@rm $(PROJECT_NAME)
.PHONY: always init SUSSYBAKA test clear clean

27
README.md Normal file
View File

@@ -0,0 +1,27 @@
# Tiny Kyoukai~ !
<center>
<img src="./kyoukai_peek.png" alt="Kyoukai peek!"></img>
</center>
<center><i>~羌瘣小ささ!~</i></center>
Look I still program on my free time !
**- Utility -**
A tiny little Kyoukai that peeks at the bottom of your screen, +10 [Cute]
**- Build -**
GTK 4 must be installed, and `pkg-config` must be available.
```sh
make init
make tiny-kyoukai
./tiny-kyoukai
```
**- Config -**
None at the moment.
**- It's not working ! -**
skill issue

40
helloworld.c Normal file
View File

@@ -0,0 +1,40 @@
/**/
#include <gtk/gtk.h>
static void print_hello(GtkWidget *widget, gpointer data) {
g_print("Hello World\n");
}
static void activate(GtkApplication *app, gpointer user_data) {
GtkWidget *window;
GtkWidget *button;
window = gtk_application_window_new(app);
gtk_window_set_title(GTK_WINDOW(window), "Hello");
gtk_window_set_default_size(GTK_WINDOW(window), 170, 50);
GtkWidget* fixed = gtk_fixed_new();
button = gtk_button_new_with_label("Hello World");
gtk_button_set_can_shrink(button, TRUE);
gtk_widget_set_size_request(button, 150, 30);
g_signal_connect(button, "clicked", G_CALLBACK(print_hello), NULL);
gtk_fixed_put(GTK_FIXED(fixed), button, 10, 10);
gtk_window_set_child(GTK_WINDOW(window), fixed);
gtk_window_present(GTK_WINDOW(window));
}
int main(int argc, char **argv) {
GtkApplication *app;
int status;
app = gtk_application_new("dev.chenco.tiny-kyoukai", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
status = g_application_run(G_APPLICATION(app), argc, argv);
g_object_unref(app);
return status;
}

BIN
kyoukai_peek.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

195
main.c Normal file
View File

@@ -0,0 +1,195 @@
/*
*------------------------------------------------------------------------------
*
* TINY-KYOUKAI
*
* Displays a little Kyoukai at the bottom of your screen !
* Nfu~ !
*
* Author : HerrCrazi <herrcrazi@gmail.com>
* Date : 24/03/2024
*------------------------------------------------------------------------------
*/
/*
*------------------------------------------------------------------------------
* Includes
*------------------------------------------------------------------------------
*/
#include <gtk/gtk.h>
#include <stdio.h>
#include "test.h"
#include "version.h"
#include "types.h"
/*
*------------------------------------------------------------------------------
* Definitions
*------------------------------------------------------------------------------
*/
#define KYOU_ICON_PATH "ressources/"
#define KYOU_ICON_NAME TINYKYOU_NAME
#define KYOU_PATH "kyoukai_peek.png"
typedef struct s_kyou_options {
char* szKyouPath;
bool bAllowResize;
bool bDrawFrame;
} t_kyou_options;
/*
*------------------------------------------------------------------------------
* Events
*------------------------------------------------------------------------------
*/
/* On keypress */
static bool kyou_keypress(GtkEventControllerKey* ev, guint keyval, guint keycode, GdkModifierType state, gpointer user_data) {
t_kyou_options* opt = (t_kyou_options*) user_data;
GtkWidget* widget = gtk_event_controller_get_widget( (GtkEventController*)ev );
#ifdef DEBUG
printf("Aloha~ '%c' (0x%X) %d %04X\n", (keyval & 0xFF00) ? ' ' : keyval, keyval, keycode, state);
#endif
switch ( keyval ) {
case 'q':
case 0xFF1B: /* Escape */
gtk_window_close(GTK_WINDOW(widget));
break;
case ' ':
case 'f':
opt->bDrawFrame = !opt->bDrawFrame; /* Toggle frame */
gtk_window_set_decorated(GTK_WINDOW(widget), opt->bDrawFrame);
break;
}
return true;
}
/* On click */
static bool kyou_clicked(GtkGestureClick* ev, gint n_press, gdouble x, gdouble y, gpointer user_data) {
t_kyou_options* opt = (t_kyou_options*) user_data;
GtkWidget* widget = gtk_event_controller_get_widget( (GtkEventController*)ev );
#ifdef DEBUG
printf("Aloha~ click %d at %f %f\n", n_press, x, y);
#else
printf( "Nfu~ !\n" );
#endif
/* Double-click -> toggle frame */
if ( n_press > 1 ) {
opt->bDrawFrame = !opt->bDrawFrame;
gtk_window_set_decorated(GTK_WINDOW(widget), opt->bDrawFrame);
}
return true;
}
/*
*------------------------------------------------------------------------------
* ACTIVATE - Main GTK setup function
*------------------------------------------------------------------------------
*/
static void activate(GtkApplication *app, gpointer user_data) {
GtkWidget *window;
GtkWidget *kyou;
GtkWidget *layout;
GtkIconTheme* icon_theme;
GtkEventController* ev_key;
GtkGesture* ev_clic;
t_kyou_options* opt = (t_kyou_options*) user_data;
/* Load icon theme (kyoukai icon) */
icon_theme = gtk_icon_theme_get_for_display(gdk_display_get_default());
gtk_icon_theme_add_search_path(icon_theme, KYOU_ICON_PATH );
if ( !gtk_icon_theme_has_icon(icon_theme, KYOU_ICON_NAME) ) {
printf("WARN: Icon not found\n");
}
/* Set application icon */
gtk_window_set_default_icon_name( KYOU_ICON_NAME);
/* Create window */
window = gtk_application_window_new(app);
gtk_window_set_title(GTK_WINDOW(window), "Tiny Kyoukai !");
gtk_window_set_default_size(GTK_WINDOW(window), 250, 120);
/* Load Kyoukai */
kyou = gtk_picture_new_for_filename( opt->szKyouPath );
gtk_picture_set_can_shrink(GTK_PICTURE(kyou), FALSE);
gtk_picture_set_content_fit(GTK_PICTURE(kyou), GTK_CONTENT_FIT_CONTAIN);
/* Setup event listeners */
ev_key = gtk_event_controller_key_new();
g_signal_connect(ev_key, "key-pressed", G_CALLBACK(kyou_keypress), opt);
gtk_widget_add_controller(window, ev_key);
ev_clic = gtk_gesture_click_new();
g_signal_connect(ev_clic, "pressed", G_CALLBACK(kyou_clicked), opt);
gtk_widget_add_controller(window, GTK_EVENT_CONTROLLER(ev_clic));
/* Setup box layout aligned to bottom right, no padding */
layout = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_set_homogeneous(GTK_BOX(layout), FALSE);
gtk_widget_set_valign(layout, GTK_ALIGN_END);
gtk_widget_set_halign(layout, GTK_ALIGN_END);
/* Add Kyoukai */
gtk_box_append(GTK_BOX(layout), kyou);
/* Make window background transparent */
GtkCssProvider *provider = gtk_css_provider_new();
char* css = "window {background: transparent;}";
gtk_css_provider_load_from_string(provider, css);
gtk_style_context_add_provider_for_display(gdk_display_get_default(),GTK_STYLE_PROVIDER(provider),GTK_STYLE_PROVIDER_PRIORITY_USER);
/* Hide window frame and title bar */
gtk_window_set_decorated(GTK_WINDOW(window), opt->bDrawFrame);
/* Add everything to window */
gtk_window_set_child(GTK_WINDOW(window), layout);
/* Display window */
gtk_window_present(GTK_WINDOW(window));
}
/*
*------------------------------------------------------------------------------
* MAIN - tiny-kyoukai - little Kyoukai peeks at the screen
*------------------------------------------------------------------------------
*/
int main(int argc, char **argv) {
GtkApplication *app;
int status;
t_kyou_options options = {
.szKyouPath = KYOU_PATH,
.bDrawFrame = false
};
printf( "-----------------------\n" \
"~\e[31m" TINYKYOU_NAME "\e[0m~ - " TINYKYOU_VERSION "\n"\
"-----------------------\n" );
printf( "~\e[31m羌瘣小ささ\e[0m!~\n" );
app = gtk_application_new("dev.chenco.tiny-kyoukai",G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect(app, "activate", G_CALLBACK(activate), &options);
status = g_application_run(G_APPLICATION(app), argc, argv);
g_object_unref(app);
printf( "\nO ancient darkness\n\t...primordial flame, what is it that lies\n\t...within your eyes?\nO bright light that" \
" splits the Heavens,\n\trumbling tremors that shake the Earth, what pulse beats\n\t...within your ears?\nMan" \
" walks adrift, a vessel of the Earth.\nI dance for thee, O God of Lightning!\nAh...Ryoku Sui..." \
"\n\tLet blood boil over!\n" );
return status;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

22
src/includes/errors.h Normal file
View File

@@ -0,0 +1,22 @@
#ifndef __TINYKYOU_ERRORS_H__
#define __TINYKYOU_ERRORS_H__
/*
-------------------------------------------------------------------------------
Common Errors
-------------------------------------------------------------------------------
*/
typedef enum {
NO_ERR = 0x0000, /* No Errors */
ERR_UNKNOWN = 0xFFFF, /* Unknown error */
ERR_NOT_IMPLEMENTED = 0xFF01, /* Not implemented */
ERR_BAD_PARAMS = 0xFF02, /* Bad param (value) */
ERR_USAGE = 0xFF03, /* Incorrect usage */
ERR_SKILL_ISSUE = 0xDEAD, /* Unspecified internal error */
} e_ret;
#endif /* __TINYKYOU_ERRORS_H__ */

3
src/includes/test.h Normal file
View File

@@ -0,0 +1,3 @@
extern char* sTestString;

27
src/includes/types.h Normal file
View File

@@ -0,0 +1,27 @@
#ifndef __TINYKYOU_TYPES_H__
#define __TINYKYOU_TYPES_H__
#include <stdint.h>
#include "errors.h"
#define __FUCK_OFF(def) #def
#define _TOSTRING(def) __FUCK_OFF(def)
/*
-------------------------------------------------------------------------------
Common Types
-------------------------------------------------------------------------------
*/
typedef int8_t int8;
typedef uint8_t uint8;
typedef int16_t int16;
typedef uint16_t uint16;
typedef int32_t int32;
typedef uint32_t uint32;
typedef int64_t int64;
typedef uint64_t uint64;
#endif /* __TINYKYOU_TYPES_H__ */

15
src/includes/version.h Normal file
View File

@@ -0,0 +1,15 @@
#ifndef __TINYKYOU_VERSION__
#define __TINYKYOU_VERSION__
#include "types.h"
#define TINYKYOU_VERSION_MAJOR 1
#define TINYKYOU_VERSION_MINOR 0
#define TINYKYOU_VERSION _TOSTRING(TINYKYOU_VERSION_MAJOR)"."_TOSTRING(TINYKYOU_VERSION_MINOR)
#define TINYKYOU_NAME "tiny-kyoukai"
#endif /* __TINYKYOU_VERSION__ */

4
src/test.c Normal file
View File

@@ -0,0 +1,4 @@
char* sTestString = "Kyou";

10
tiny-kyoukai.desktop Executable file
View File

@@ -0,0 +1,10 @@
#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Name=Tiny Kyoukai
Exec=tiny-kyoukai
Comment=Tiny Kyoukai !
Icon=tiny-kyoukai
Terminal=false
Categories=Utility;GTK;Anime;

BIN
tiny-kyoukai.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB