diff --git a/c3s/configure b/c3s/configure
index ca2efe0..fa750c2 100755
--- a/c3s/configure
+++ b/c3s/configure
@@ -38,13 +38,6 @@ fi
OBJECTS_DEBUG="$(c2ext .debug.lo "$SOURCES")"
echo "OBJECTS_DEBUG = $OBJECTS_DEBUG" >> ${CONFIG_MK}
-# Default config
-CPPFLAGS="${CPPFLAGS:=}"
-ENV_CFLAGS="${CFLAGS:=}"
-DEFAULT_CFLAGS="-O2 -pipe -fPIC"
-LDFLAGS="${LDFLAGS}"
-LIBS="${LIBS:=-lm}"
-
# Common config for all targets
CFLAGS="$CFLAGS -W -Wall -Werror -std=c99 -pedantic"
CPPFLAGS="-I../libffi/include $CPPFLAGS"
@@ -54,7 +47,7 @@ pkg_config libbsd-overlay
pkg_config libmd
config_lib libmd -lmd 2>/dev/null
config_lib dl -ldl 2>/dev/null
-LIBS="$LIBS ../libffi/libffi.la -pthread"
+LIBS="$LIBS ../libffi/libffi.la -pthread -lm"
# Asan config
CFLAGS_ASAN="$CFLAGS -fsanitize=address -O1 -fno-omit-frame-pointer -g"
@@ -78,6 +71,7 @@ LOCAL_LIBS_DEBUG="$LIBC3_DEBUG"
LIBS_DEBUG="$LOCAL_LIBS_DEBUG $LIBS"
# Main config
+DEFAULT_CFLAGS="-O2 -pipe"
if [ "x$ENV_CFLAGS" = "x" ]; then
CFLAGS="$CFLAGS $DEFAULT_CFLAGS"
fi
diff --git a/config.subr b/config.subr
index 8fae541..6e1f49d 100644
--- a/config.subr
+++ b/config.subr
@@ -163,7 +163,7 @@ require_pkg_config() {
sources() {
echo "$1 = \\
-$(echo "$2" | sed -e 's/^\(.*\)$/ \1 \\\\/')
+$(echo "$2" | sed -e 's/^\(.*\)$/ \1 \\/')
" >> ${SOURCES_MK}
echo "$1='$(echo "$2" | tr '\n' ' ')'" >> ${SOURCES_SH}
}
diff --git a/ic3/buf_linenoise.c b/ic3/buf_linenoise.c
index adecfa2..bb9251b 100644
--- a/ic3/buf_linenoise.c
+++ b/ic3/buf_linenoise.c
@@ -20,17 +20,19 @@
#include "../linenoise/linenoise.h"
typedef struct buf_linenoise {
- s_buf buf;
- bool eof;
- const char *prompt;
+ s_buf buf;
+ bool eof;
+ const s8 *prompt;
} s_buf_linenoise;
sw buf_linenoise_refill_fgets (s_buf *buf);
sw buf_linenoise_refill_linenoise (s_buf *buf);
-void buf_linenoise_close (s_buf *buf)
+void buf_linenoise_close (s_buf *buf, const s8 *history_path)
{
assert(buf);
+ if (history_path)
+ linenoiseHistorySave(history_path);
buf->refill = NULL;
free(buf->user_ptr);
buf->user_ptr = NULL;
@@ -38,7 +40,8 @@ void buf_linenoise_close (s_buf *buf)
puts("");
}
-s_buf * buf_linenoise_open_r (s_buf *buf, const char *prompt)
+s_buf * buf_linenoise_open_r (s_buf *buf, const s8 *prompt,
+ const s8 *history_path)
{
s_buf_linenoise *buf_linenoise;
assert(buf);
@@ -52,6 +55,8 @@ s_buf * buf_linenoise_open_r (s_buf *buf, const char *prompt)
else
buf->refill = buf_linenoise_refill_fgets;
buf_linenoise->prompt = prompt;
+ if (history_path)
+ linenoiseHistoryLoad(history_path);
buf->user_ptr = buf_linenoise;
return buf;
}
diff --git a/ic3/buf_linenoise.h b/ic3/buf_linenoise.h
index 207b2af..88f2ebd 100644
--- a/ic3/buf_linenoise.h
+++ b/ic3/buf_linenoise.h
@@ -14,10 +14,11 @@
* @file buf_linenoise.h
* @brief Linenoise backend for s_buf.
*/
-#ifndef BUF_LINENOISE_H
-#define BUF_LINENOISE_H
+#ifndef IC3_BUF_LINENOISE_H
+#define IC3_BUF_LINENOISE_H
-void buf_linenoise_close (s_buf *buf);
-s_buf * buf_linenoise_open_r (s_buf *buf, const char *prompt);
+void buf_linenoise_close (s_buf *buf, const s8 *history_path);
+s_buf * buf_linenoise_open_r (s_buf *buf, const s8 *prompt,
+ const s8 *history_path);
-#endif /* BUF_LINENOISE_H */
+#endif /* IC3_BUF_LINENOISE_H */
diff --git a/ic3/configure b/ic3/configure
index 3c5f321..879ac00 100755
--- a/ic3/configure
+++ b/ic3/configure
@@ -41,7 +41,7 @@ echo "OBJECTS_DEBUG = $OBJECTS_DEBUG" >> ${CONFIG_MK}
# Default config
CPPFLAGS="${CPPFLAGS:=}"
ENV_CFLAGS="${CFLAGS:=}"
-DEFAULT_CFLAGS="-O2 -pipe -fPIC"
+DEFAULT_CFLAGS="-O2 -pipe"
LDFLAGS="${LDFLAGS}"
LIBS="${LIBS:=-lm}"
diff --git a/ic3/ic3.c b/ic3/ic3.c
index 54abfce..9dd8ef3 100644
--- a/ic3/ic3.c
+++ b/ic3/ic3.c
@@ -95,7 +95,7 @@ int main (int argc, char **argv)
if (argc < 1)
return usage(argv[0]);
buf_init(&in, false, sizeof(i), i);
- buf_linenoise_open_r(&in, "ic3> ");
+ buf_linenoise_open_r(&in, "ic3> ", ".ic3_history");
in.line = 0;
buf_init(&out, false, sizeof(o), o);
buf_file_open_w(&out, stdout);
@@ -121,7 +121,7 @@ int main (int argc, char **argv)
(r = buf_ignore_character(&in)) <= 0))
break;
}
- buf_linenoise_close(&in);
+ buf_linenoise_close(&in, ".ic3_history");
buf_file_close(&out);
c3_clean(NULL);
return 0;
diff --git a/libc3/configure b/libc3/configure
index ddd324c..6b8d613 100755
--- a/libc3/configure
+++ b/libc3/configure
@@ -37,7 +37,7 @@ OBJECTS_DEBUG="$(c2ext .debug.lo "$LO_SOURCES")"
# Common config for all targets
CPPFLAGS="-I../libffi/include $CPPFLAGS"
-CFLAGS="$CFLAGS -W -Wall -Werror -std=c99 -pedantic -fPIC"
+CFLAGS="$CFLAGS -W -Wall -Werror -std=c99 -pedantic"
LDFLAGS="--shared -no-undefined ${LDFLAGS}"
LIBS="${LIBS} -lm -pthread -rpath ${PREFIX}/lib"
config_asan
diff --git a/libc3/types.h b/libc3/types.h
index 18d5999..cc26265 100644
--- a/libc3/types.h
+++ b/libc3/types.h
@@ -50,6 +50,10 @@ typedef uint32_t u32;
typedef unsigned long uw;
typedef uint64_t u64;
+#ifdef SW_MAX
+#undef SW_MAX
+#endif
+
#define S8_MAX ((s8) (((u8) 1 << (8 * sizeof(s8) - 1)) - 1))
#define S16_MAX ((s16) (((u16) 1 << (8 * sizeof(s16) - 1)) - 1))
#define S32_MAX ((s32) (((u32) 1 << (8 * sizeof(s32) - 1)) - 1))
diff --git a/libc3/window/cairo/Makefile b/libc3/window/cairo/Makefile
index 1a9b18f..8b586d4 100644
--- a/libc3/window/cairo/Makefile
+++ b/libc3/window/cairo/Makefile
@@ -13,6 +13,7 @@
build:
${MAKE} ${LIB}
if ${HAVE_COCOA}; then ${MAKE} -C quartz build; fi
+ if ${HAVE_WIN32}; then ${MAKE} -C win32 build; fi
if ${HAVE_XCB}; then ${MAKE} -C xcb build; fi
all:
@@ -24,38 +25,44 @@ all:
asan:
${MAKE} ${LIB_ASAN}
if ${HAVE_COCOA}; then ${MAKE} -C quartz asan; fi
+ if ${HAVE_WIN32}; then ${MAKE} -C win32 asan; fi
if ${HAVE_XCB}; then ${MAKE} -C xcb asan; fi
clean:
if ${HAVE_COCOA}; then ${MAKE} -C quartz clean; fi
+ if ${HAVE_WIN32}; then ${MAKE} -C win32 clean; fi
if ${HAVE_XCB}; then ${MAKE} -C xcb clean; fi
clean_cov:
if ${HAVE_COCOA}; then ${MAKE} -C quartz clean_cov; fi
+ if ${HAVE_WIN32}; then ${MAKE} -C win32 clean_cov; fi
if ${HAVE_XCB}; then ${MAKE} -C xcb clean_cov; fi
cov:
${MAKE} ${LIB_COV}
if ${HAVE_COCOA}; then ${MAKE} -C quartz cov; fi
+ if ${HAVE_WIN32}; then ${MAKE} -C win32 cov; fi
if ${HAVE_XCB}; then ${MAKE} -C xcb cov; fi
debug:
${MAKE} ${LIB_DEBUG}
- if ${HAVE_COCOA}; then ${MAKE} -C quartz debug; else if ${HAVE_XCB}; then ${MAKE} -C xcb debug; fi; fi
+ if ${HAVE_COCOA}; then ${MAKE} -C quartz debug; else if ${HAVE_WIN32}; then ${MAKE} -C win32 debug; else if ${HAVE_XCB}; then ${MAKE} -C xcb debug; fi; fi; fi
demo: build
- if ${HAVE_COCOA}; then ${MAKE} -C quartz demo; else if ${HAVE_XCB}; then ${MAKE} -C xcb demo; fi; fi
+ if ${HAVE_COCOA}; then ${MAKE} -C quartz demo; else if ${HAVE_WIN32}; then ${MAKE} -C win32 demo; else if ${HAVE_XCB}; then ${MAKE} -C xcb demo; fi; fi; fi
distclean:
if ${HAVE_COCOA}; then ${MAKE} -C quartz distclean; fi
+ if ${HAVE_WIN32}; then ${MAKE} -C win32 distclean; fi
if ${HAVE_XCB}; then ${MAKE} -C xcb distclean; fi
gcovr:
if ${HAVE_COCOA}; then ${MAKE} -C quartz gcovr; fi
+ if ${HAVE_WIN32}; then ${MAKE} -C win32 gcovr; fi
if ${HAVE_XCB}; then ${MAKE} -C xcb gcovr; fi
gdb_demo: debug
- if ${HAVE_COCOA}; then ${MAKE} -C quartz gdb_demo; else if ${HAVE_XCB}; then ${MAKE} -C xcb gdb_demo; fi; fi
+ if ${HAVE_COCOA}; then ${MAKE} -C quartz gdb_demo; else if ${HAVE_WIN32}; then ${MAKE} -C win32 gdb_demo; else if ${HAVE_XCB}; then ${MAKE} -C xcb gdb_demo; fi; fi; fi
install:
${INSTALL} -o ${OWNER} -g ${GROUP} -m 0755 -d ${prefix}/include/libc3/window/cairo
@@ -64,13 +71,15 @@ install:
${LIBTOOL} --tag=CC --mode=install ${INSTALL} -o ${OWNER} -g ${GROUP} -m 0644 ${LIB} ${prefix}/lib
${LIBTOOL} --finish ${prefix}/lib
if ${HAVE_COCOA}; then ${MAKE} -C quartz install; fi
+ if ${HAVE_WIN32}; then ${MAKE} -C win32 install; fi
if ${HAVE_XCB}; then ${MAKE} -C xcb install; fi
lldb_demo: debug
- if ${HAVE_COCOA}; then ${MAKE} -C quartz lldb_demo; else if ${HAVE_XCB}; then ${MAKE} -C xcb lldb_demo; fi; fi
+ if ${HAVE_COCOA}; then ${MAKE} -C quartz lldb_demo; else if ${HAVE_WIN32}; then ${MAKE} -C win32 lldb_demo; else if ${HAVE_XCB}; then ${MAKE} -C xcb lldb_demo; fi; fi
test:
if ${HAVE_COCOA}; then ${MAKE} -C quartz test; fi
+ if ${HAVE_WIN32}; then ${MAKE} -C win32 test; fi
if ${HAVE_XCB}; then ${MAKE} -C xcb test; fi
update_sources:
diff --git a/libc3/window/cairo/configure b/libc3/window/cairo/configure
index 033f02e..076523b 100755
--- a/libc3/window/cairo/configure
+++ b/libc3/window/cairo/configure
@@ -37,12 +37,13 @@ OBJECTS_DEBUG="$(c2ext .debug.lo "$SOURCES")"
# Common config for all targets
CPPFLAGS="-I../../../libffi/include -I../../.. $CPPFLAGS"
-CFLAGS="$CFLAGS -W -Wall -Werror -std=c99 -pedantic -fPIC"
+CFLAGS="$CFLAGS -W -Wall -Werror -std=c99 -pedantic"
LDFLAGS="--shared -no-undefined ${LDFLAGS}"
LIBS="$LIBS -rpath ${PREFIX}/lib"
config_asan
config_gnu
pkg_config cairo
+pkg_config libbsd-overlay
pkg_config xkbcommon
config_lib_have COCOA -framework Cocoa
config_define PREFIX "\"${PREFIX}\""
diff --git a/libc3/window/cairo/update_sources b/libc3/window/cairo/update_sources
index 66265f9..ddcbb2f 100755
--- a/libc3/window/cairo/update_sources
+++ b/libc3/window/cairo/update_sources
@@ -26,4 +26,5 @@ update_sources_mk
update_sources_sh
( cd quartz && ./update_sources; )
+( cd win32 && ./update_sources; )
( cd xcb && ./update_sources; )
diff --git a/libc3/window/cairo/win32/Makefile b/libc3/window/cairo/win32/Makefile
index f7adfa9..0771cac 100644
--- a/libc3/window/cairo/win32/Makefile
+++ b/libc3/window/cairo/win32/Makefile
@@ -18,7 +18,8 @@ CLEANFILES += ${CLEANFILES_COV}
DISTCLEANFILES = ${CLEANFILES} config.h config.mk
-build: libc3_window_cairo_xcb.la
+build:
+ ${MAKE} ${LIB}
${MAKE} -C demo build
all:
@@ -27,7 +28,8 @@ all:
${MAKE} debug
if ${HAVE_ASAN}; then ${MAKE} asan; fi
-asan: libc3_window_cairo_xcb_asan.la
+asan:
+ ${MAKE} ${LIB_ASAN}
${MAKE} -C demo asan
clean:
@@ -38,10 +40,12 @@ clean_cov:
rm -rf ${CLEANFILES_COV}
${MAKE} -C demo clean_cov
-cov: libc3_window_cairo_xcb_cov.la
+cov:
+ ${MAKE} ${LIB_COV}
${MAKE} -C demo cov
-debug: libc3_window_cairo_xcb_debug.la
+debug:
+ ${MAKE} ${LIB_DEBUG}
${MAKE} -C demo debug
demo: build
diff --git a/libc3/window/cairo/win32/configure b/libc3/window/cairo/win32/configure
index 7514e23..83c221a 100644
--- a/libc3/window/cairo/win32/configure
+++ b/libc3/window/cairo/win32/configure
@@ -42,7 +42,7 @@ OBJECTS_DEBUG="$(c2ext .debug.lo "$SOURCES")"
# Common config for all targets
CPPFLAGS="-I../../../../libffi/include -I../../../.. $CPPFLAGS"
-CFLAGS="$CFLAGS -W -Wall -Werror -std=c99 -pedantic -fPIC"
+CFLAGS="$CFLAGS -W -Wall -Werror -std=c99 -pedantic"
LDFLAGS="--shared -no-undefined ${LDFLAGS}"
LIBS="$LIBS -rpath ${PREFIX}/lib"
config_asan
@@ -50,6 +50,7 @@ config_gnu
pkg_config xkbcommon
pkg_config cairo
pkg_config cairo-win32
+pkg_config libbsd-overlay
config_define PREFIX "\"${PREFIX}\""
update_config_h
LIBS="$LIBS -lxkbcommon"
diff --git a/libc3/window/cairo/win32/demo/c3_window_cairo_win32_demo.c b/libc3/window/cairo/win32/demo/c3_window_cairo_win32_demo.c
index ab369f6..192a49e 100644
--- a/libc3/window/cairo/win32/demo/c3_window_cairo_win32_demo.c
+++ b/libc3/window/cairo/win32/demo/c3_window_cairo_win32_demo.c
@@ -22,14 +22,14 @@ int main (void)
{
s_window_cairo window;
window_cairo_init(&window, 0, 0, 800, 600,
- "C3.Window.Cairo.XCB demo",
+ "C3.Window.Cairo.Win32 demo",
LIBC3_WINDOW_CAIRO_DEMO_SEQUENCE_COUNT);
window.button = c3_window_cairo_demo_button;
window.key = c3_window_cairo_demo_key;
window.load = c3_window_cairo_demo_load;
window.render = c3_window_cairo_demo_render;
window.resize = c3_window_cairo_demo_resize;
- if (! window_cairo_xcb_run(&window))
+ if (! window_cairo_win32_run(&window))
return g_c3_exit_code;
return 0;
}
diff --git a/libc3/window/cairo/win32/demo/configure b/libc3/window/cairo/win32/demo/configure
index f2bb344..0d279a2 100644
--- a/libc3/window/cairo/win32/demo/configure
+++ b/libc3/window/cairo/win32/demo/configure
@@ -17,10 +17,10 @@ export SRC_TOP="$(dirname "$PWD")"
. ../../../../../config.subr
-PROG=c3_window_cairo_xcb_demo
-PROG_ASAN=c3_window_cairo_xcb_demo_asan
-PROG_COV=c3_window_cairo_xcb_demo_cov
-PROG_DEBUG=c3_window_cairo_xcb_demo_debug
+PROG=c3_window_cairo_win32_demo
+PROG_ASAN=c3_window_cairo_win32_demo_asan
+PROG_COV=c3_window_cairo_win32_demo_cov
+PROG_DEBUG=c3_window_cairo_win32_demo_debug
echo "PROG = $PROG" >> ${CONFIG_MK}
echo "PROG_ASAN = $PROG_ASAN" >> ${CONFIG_MK}
@@ -45,38 +45,39 @@ echo "OBJECTS_DEBUG = $OBJECTS_DEBUG" >> ${CONFIG_MK}
# Common config for all targets
CFLAGS="$CFLAGS -W -Wall -Werror -std=c99 -pedantic"
-CPPFLAGS="$CPPFLAGS -I../../../../../libffi/include -I../../../../.."
+CPPFLAGS="-I../../../../../libffi/include -I../../../../.. $CPPFLAGS"
config_asan
config_gnu
-pkg_config xcb
pkg_config cairo
+pkg_config cairo-win32
+pkg_config libbsd-overlay
LIBS="$LIBS"
# Asan config
CFLAGS_ASAN="$CFLAGS -fsanitize=address -O1 -fno-omit-frame-pointer -g"
LDFLAGS_ASAN="$LDFLAGS"
-LOCAL_LIBS_ASAN="../libc3_window_cairo_xcb_asan.la"
+LOCAL_LIBS_ASAN="../libc3_window_cairo_win32_asan.la"
LIBS_ASAN="$LOCAL_LIBS_ASAN $LIBS"
# Coverage config
CFLAGS_COV="$CFLAGS -ftest-coverage -fprofile-arcs -fprofile-generate"
LDFLAGS_COV="$LDFLAGS --coverage"
-LOCAL_LIBS_COV="../libc3_window_cairo_xcb_cov.la"
+LOCAL_LIBS_COV="../libc3_window_cairo_win32_cov.la"
LIBS_COV="$LOCAL_LIBS_COV $LIBS"
# Debug config
CFLAGS_DEBUG="$CFLAGS -DDEBUG -O0 -g"
LDFLAGS_DEBUG="$LDFLAGS"
-LOCAL_LIBS_DEBUG="../libc3_window_cairo_xcb_debug.la"
+LOCAL_LIBS_DEBUG="../libc3_window_cairo_win32_debug.la"
LIBS_DEBUG="$LOCAL_LIBS_DEBUG $LIBS"
# Main config
-DEFAULT_CFLAGS="-O2 -pipe -fPIC"
+DEFAULT_CFLAGS="-O2 -pipe"
if [ "x$ENV_CFLAGS" = "x" ]; then
CFLAGS="$CFLAGS $DEFAULT_CFLAGS"
fi
CFLAGS="$CFLAGS -DNDEBUG"
-LOCAL_LIBS="../libc3_window_cairo_xcb.la"
+LOCAL_LIBS="../libc3_window_cairo_win32.la"
LIBS="$LOCAL_LIBS $LIBS"
echo "HAVE_ASAN = $HAVE_ASAN" >> ${CONFIG_MK}
diff --git a/libc3/window/cairo/win32/demo/sources.mk b/libc3/window/cairo/win32/demo/sources.mk
index 2e241af..caf267e 100644
--- a/libc3/window/cairo/win32/demo/sources.mk
+++ b/libc3/window/cairo/win32/demo/sources.mk
@@ -1,8 +1,8 @@
# sources.mk generated by update_sources
HEADERS = \
- \\
+ \
SOURCES = \
- c3_window_cairo_xcb_demo.c \\
- window.c \\
+ c3_window_cairo_win32_demo.c \
+ window.c \
diff --git a/libc3/window/cairo/win32/demo/sources.sh b/libc3/window/cairo/win32/demo/sources.sh
index f734d9a..8543912 100644
--- a/libc3/window/cairo/win32/demo/sources.sh
+++ b/libc3/window/cairo/win32/demo/sources.sh
@@ -1,3 +1,3 @@
# sources.sh generated by update_sources
HEADERS=' '
-SOURCES='c3_window_cairo_xcb_demo.c window.c '
+SOURCES='c3_window_cairo_win32_demo.c window.c '
diff --git a/libc3/window/cairo/win32/sources.mk b/libc3/window/cairo/win32/sources.mk
index d5f7bce..7f53a9f 100644
--- a/libc3/window/cairo/win32/sources.mk
+++ b/libc3/window/cairo/win32/sources.mk
@@ -1,8 +1,10 @@
# sources.mk generated by update_sources
HEADERS = \
config.h \
+ vk_to_xkbcommon.h \
window_cairo_win32.h \
SOURCES = \
+ vk_to_xkbcommon.c \
window_cairo_win32.c \
diff --git a/libc3/window/cairo/win32/sources.sh b/libc3/window/cairo/win32/sources.sh
index a5101b6..59ef06c 100644
--- a/libc3/window/cairo/win32/sources.sh
+++ b/libc3/window/cairo/win32/sources.sh
@@ -1,3 +1,3 @@
# sources.sh generated by update_sources
-HEADERS='config.h window_cairo_win32.h '
-SOURCES='window_cairo_win32.c '
+HEADERS='config.h vk_to_xkbcommon.h window_cairo_win32.h '
+SOURCES='vk_to_xkbcommon.c window_cairo_win32.c '
diff --git a/libc3/window/cairo/win32/vk_to_xkbcommon.c b/libc3/window/cairo/win32/vk_to_xkbcommon.c
new file mode 100644
index 0000000..74072db
--- /dev/null
+++ b/libc3/window/cairo/win32/vk_to_xkbcommon.c
@@ -0,0 +1,99 @@
+/* c3
+ * Copyright 2022,2023 kmx.io <contact@kmx.io>
+ *
+ * Permission is hereby granted to use this software granted the above
+ * copyright notice and this permission paragraph are included in all
+ * copies and substantial portions of this software.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
+ * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
+ * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+#include <windows.h>
+#include <xkbcommon/xkbcommon.h>
+#include <libc3/types.h>
+
+u32 vk_to_xkbcommon (u32 vk_key)
+{
+ switch (vk_key) {
+ case VK_ESCAPE: return XKB_KEY_Escape;
+ case VK_F1: return XKB_KEY_F1;
+ case VK_F2: return XKB_KEY_F2;
+ case VK_F3: return XKB_KEY_F3;
+ case VK_F4: return XKB_KEY_F4;
+ case VK_F5: return XKB_KEY_F5;
+ case VK_F6: return XKB_KEY_F6;
+ case VK_F7: return XKB_KEY_F7;
+ case VK_F8: return XKB_KEY_F8;
+ case VK_F9: return XKB_KEY_F9;
+ case VK_F10: return XKB_KEY_F10;
+ case VK_F11: return XKB_KEY_F11;
+ case VK_F12: return XKB_KEY_F12;
+ /*
+ case : return XKB_KEY_grave;
+ */
+ case 0x31: return XKB_KEY_1;
+ case 0x32: return XKB_KEY_2;
+ case 0x33: return XKB_KEY_3;
+ case 0x34: return XKB_KEY_4;
+ case 0x35: return XKB_KEY_5;
+ case 0x36: return XKB_KEY_6;
+ case 0x37: return XKB_KEY_7;
+ case 0x38: return XKB_KEY_8;
+ case 0x39: return XKB_KEY_9;
+ case 0x30: return XKB_KEY_0;
+ /*
+ case 45: return XKB_KEY_minus;
+ case 61: return XKB_KEY_equal;
+ */
+ case VK_BACK: return XKB_KEY_BackSpace;
+ case VK_TAB: return XKB_KEY_Tab;
+ case 0x41: return XKB_KEY_a;
+ case 0x42: return XKB_KEY_b;
+ case 0x43: return XKB_KEY_c;
+ case 0x44: return XKB_KEY_d;
+ case 0x45: return XKB_KEY_e;
+ case 0x46: return XKB_KEY_f;
+ case 0x47: return XKB_KEY_g;
+ case 0x48: return XKB_KEY_h;
+ case 0x49: return XKB_KEY_i;
+ case 0x4A: return XKB_KEY_j;
+ case 0x4B: return XKB_KEY_k;
+ case 0x4C: return XKB_KEY_l;
+ case 0x4D: return XKB_KEY_m;
+ case 0x4E: return XKB_KEY_n;
+ case 0x4F: return XKB_KEY_o;
+ case 0x50: return XKB_KEY_p;
+ case 0x51: return XKB_KEY_q;
+ case 0x52: return XKB_KEY_r;
+ case 0x53: return XKB_KEY_s;
+ case 0x54: return XKB_KEY_t;
+ case 0x55: return XKB_KEY_u;
+ case 0x56: return XKB_KEY_v;
+ case 0x57: return XKB_KEY_w;
+ case 0x58: return XKB_KEY_x;
+ case 0x59: return XKB_KEY_y;
+ case 0x5A: return XKB_KEY_z;
+ /*
+ case 91: return XKB_KEY_bracketleft;
+ case 93: return XKB_KEY_bracketright;
+ case 92: return XKB_KEY_backslash;
+ case 59: return XKB_KEY_semicolon;
+ case 39: return XKB_KEY_apostrophe;
+ */
+ case VK_RETURN: return XKB_KEY_Return;
+ /*
+ case 44: return XKB_KEY_comma;
+ case 46: return XKB_KEY_period;
+ case 47: return XKB_KEY_slash;
+ */
+ case VK_SPACE: return XKB_KEY_space;
+ case VK_UP: return XKB_KEY_Up;
+ case VK_DOWN: return XKB_KEY_Down;
+ case VK_LEFT: return XKB_KEY_Left;
+ case VK_RIGHT: return XKB_KEY_Right;
+ default: break;
+ }
+ return XKB_KEY_NoSymbol;
+}
diff --git a/libc3/window/cairo/win32/vk_to_xkbcommon.h b/libc3/window/cairo/win32/vk_to_xkbcommon.h
new file mode 100644
index 0000000..0196b61
--- /dev/null
+++ b/libc3/window/cairo/win32/vk_to_xkbcommon.h
@@ -0,0 +1,20 @@
+/* c3
+ * Copyright 2022,2023 kmx.io <contact@kmx.io>
+ *
+ * Permission is hereby granted to use this software granted the above
+ * copyright notice and this permission paragraph are included in all
+ * copies and substantial portions of this software.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
+ * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
+ * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+#ifndef LIBC3_WINDOW_CAIRO_WIN32_VK_TO_XKBCOMMON_H
+#define LIBC3_WINDOW_CAIRO_WIN32_VK_TO_XKBCOMMON_H
+
+#include <libc3/types.h>
+
+u32 vk_to_xkbcommon (u32 vk_key);
+
+#endif /* LIBC3_WINDOW_CAIRO_WIN32_VK_TO_XKBCOMMON_H */
diff --git a/libc3/window/cairo/win32/window_cairo_win32.c b/libc3/window/cairo/win32/window_cairo_win32.c
index 2f0d5ed..93eadd5 100644
--- a/libc3/window/cairo/win32/window_cairo_win32.c
+++ b/libc3/window/cairo/win32/window_cairo_win32.c
@@ -12,10 +12,12 @@
*/
#include <stdio.h>
#include <stdlib.h>
-#include <cairo/cairo.h>
-#include <libc3/c3.h>
-#include <windows.h>
#include <xkbcommon/xkbcommon.h>
+#include <windows.h>
+#include <cairo.h>
+#include <cairo-win32.h>
+#include <libc3/c3.h>
+#include "vk_to_xkbcommon.h"
#include "window_cairo_win32.h"
bool window_cairo_run (s_window_cairo *window)
@@ -24,11 +26,63 @@ bool window_cairo_run (s_window_cairo *window)
}
LRESULT CALLBACK window_cairo_win32_proc(HWND hwnd, UINT message,
- WPARAM wParam, LPARAM lParam) {
+ WPARAM wParam, LPARAM lParam)
+{
+ HBITMAP buffer_hbitmap;
+ HDC buffer_hdc;
+ cairo_t *cr;
+ HDC hdc;
+ u32 keysym;
+ PAINTSTRUCT ps;
+ cairo_surface_t *surface;
+ u32 vk;
+ s_window_cairo *window;
+ HDC window_hdc;
+ window = (s_window_cairo *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
+ assert(window);
switch (message) {
case WM_DESTROY:
+ printf("WM_DESTROY\n");
PostQuitMessage(0);
break;
+ case WM_ERASEBKGND:
+ return 1;
+ case WM_KEYDOWN:
+ vk = (u32) wParam;
+ keysym = vk_to_xkbcommon(vk);
+ if (! window->key(window, keysym)) {
+ printf("window->key -> false\n");
+ PostQuitMessage(1);
+ }
+ break;
+ case WM_PAINT:
+ window_hdc = GetDC(hwnd);
+ buffer_hdc = CreateCompatibleDC(window_hdc);
+ buffer_hbitmap = CreateCompatibleBitmap(window_hdc, window->w,
+ window->h);
+ SelectObject(buffer_hdc, buffer_hbitmap);
+ surface = cairo_win32_surface_create(buffer_hdc);
+ cr = cairo_create(surface);
+ if (! window->render(window, cr)) {
+ printf("render -> false\n");
+ PostQuitMessage(1);
+ }
+ cairo_surface_flush(surface);
+ cairo_destroy(window->cr);
+ cairo_surface_destroy(surface);
+ hdc = BeginPaint(hwnd, &ps);
+ BitBlt(hdc, 0, 0, window->w, window->h, buffer_hdc, 0, 0, SRCCOPY);
+ EndPaint(hwnd, &ps);
+ DeleteObject(buffer_hbitmap);
+ DeleteDC(buffer_hdc);
+ break;
+ case WM_SIZE:
+ if (! window->resize(window, LOWORD(lParam), HIWORD(lParam)))
+ PostQuitMessage(1);
+ window->w = LOWORD(lParam);
+ window->h = HIWORD(lParam);
+ InvalidateRect(hwnd, NULL, TRUE);
+ break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
@@ -37,9 +91,10 @@ LRESULT CALLBACK window_cairo_win32_proc(HWND hwnd, UINT message,
bool window_cairo_win32_run (s_window_cairo *window)
{
- WNDCLASSEX wc;
HWND hwnd;
- MSG Msg;
+ MSG msg;
+ s_time sleep;
+ WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = window_cairo_win32_proc;
@@ -50,7 +105,7 @@ bool window_cairo_win32_run (s_window_cairo *window)
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
- wc.lpszClassName = L"Libc3WindowCairoWin32";
+ wc.lpszClassName = "Libc3WindowCairoWin32";
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if (!RegisterClassEx(&wc)) {
MessageBox(NULL, "Window Registration Failed!", "Error!",
@@ -58,21 +113,33 @@ bool window_cairo_win32_run (s_window_cairo *window)
return 0;
}
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,
- L"Libc3WindowCairoWin32",
- "The title of my window",
+ "Libc3WindowCairoWin32",
+ window->title,
WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
+ window->x, window->y, window->w, window->h,
NULL, NULL, GetModuleHandle(NULL), NULL);
if (hwnd == NULL) {
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
+ SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR) window);
+ if (! window->load(window))
+ PostQuitMessage(1);
ShowWindow(hwnd, SW_SHOWDEFAULT);
UpdateWindow(hwnd);
- while (GetMessage(&Msg, NULL, 0, 0) > 0) {
- TranslateMessage(&Msg);
- DispatchMessage(&Msg);
+ while (true) {
+ while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
+ if (msg.message == WM_QUIT)
+ goto quit;
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ sleep.tv_sec = 0;
+ sleep.tv_nsec = 1000000000 / 120;
+ nanosleep(&sleep, NULL);
+ InvalidateRect(hwnd, NULL, TRUE);
}
- return Msg.wParam ? false : true;
+ quit:
+ return msg.wParam ? false : true;
}
diff --git a/libc3/window/configure b/libc3/window/configure
index 8984970..92a6757 100755
--- a/libc3/window/configure
+++ b/libc3/window/configure
@@ -37,11 +37,12 @@ OBJECTS_DEBUG="$(c2ext .debug.lo "$SOURCES")"
# Common config for all targets
CPPFLAGS="-I../../libffi/include -I../.. $CPPFLAGS"
-CFLAGS="$CFLAGS -W -Wall -Werror -std=c99 -pedantic -fPIC"
+CFLAGS="$CFLAGS -W -Wall -Werror -std=c99 -pedantic"
LDFLAGS="--shared -no-undefined ${LDFLAGS}"
LIBS="$LIBS -rpath ${PREFIX}/lib"
config_asan
config_gnu
+pkg_config libbsd-overlay
config_define PREFIX "\"${PREFIX}\""
# Address Sanitizer config
diff --git a/libtommath b/libtommath
index 19e84a4..1dc2188 160000
--- a/libtommath
+++ b/libtommath
@@ -1 +1 @@
-Subproject commit 19e84a4f15b66fcc2bd887b36f87d4f32f2a862d
+Subproject commit 1dc21885774654ceec6b555513eebce7e2142244
diff --git a/linenoise b/linenoise
index 86275b5..a7327ba 160000
--- a/linenoise
+++ b/linenoise
@@ -1 +1 @@
-Subproject commit 86275b5b1a58814bc7182b73e3435c6644c0a946
+Subproject commit a7327ba54af89b97ce7e5585b3bdbe39a31bbc48
diff --git a/test/configure b/test/configure
index c5b6b81..d3e137e 100755
--- a/test/configure
+++ b/test/configure
@@ -38,13 +38,6 @@ fi
OBJECTS_DEBUG="$(c2ext .debug.lo "$SOURCES")"
echo "OBJECTS_DEBUG = $OBJECTS_DEBUG" >> ${CONFIG_MK}
-# Default config
-CPPFLAGS="${CPPFLAGS}"
-ENV_CFLAGS="${CFLAGS}"
-DEFAULT_CFLAGS="-O2 -pipe"
-LDFLAGS="${LDFLAGS}"
-LIBS="${LIBS:=} -lm"
-
# Common config for all targets
CFLAGS="$CFLAGS -W -Wall -Werror -std=c99 -pedantic"
CPPFLAGS="-I../libffi/include $CPPFLAGS"
@@ -54,7 +47,7 @@ pkg_config libbsd-overlay
pkg_config libmd
config_lib libmd -lmd 2>/dev/null
config_lib dl -ldl 2>/dev/null
-LIBS="$LIBS ../libffi/libffi.la -pthread"
+LIBS="$LIBS ../libffi/libffi.la -pthread -lm"
# Asan config
CFLAGS_ASAN="$CFLAGS -fsanitize=address -O1 -fno-omit-frame-pointer -g"
@@ -75,6 +68,7 @@ LIBC3_DEBUG=../libc3/libc3_debug.la
LIBS_DEBUG="$LIBC3_DEBUG $LIBS"
# Main config
+DEFAULT_CFLAGS="-O2 -pipe"
if [ "x$ENV_CFLAGS" = "x" ]; then
CFLAGS="$CFLAGS $DEFAULT_CFLAGS"
fi
diff --git a/win64/Makefile b/win64/Makefile
index 3821a53..03bd8b5 100644
--- a/win64/Makefile
+++ b/win64/Makefile
@@ -11,18 +11,22 @@ c3-${C3_VERSION}.win64:
rm -rf ${DEST}
mkdir -p ${DEST}/test/ic3
cp -a ../README.md ${DEST}
- cp -a /bin/msys-2.0.dll ${DEST}
- cp -a /bin/msys-2.0.dll ${DEST}/test
- cp -a /bin/msys-bsd-0.dll ${DEST}
- cp -a /bin/msys-bsd-0.dll ${DEST}/test
- cp -a /bin/msys-gcc_s-seh-1.dll ${DEST}
- cp -a /bin/msys-gcc_s-seh-1.dll ${DEST}/test
- cp -a /bin/msys-md-0.dll ${DEST}
- cp -a /bin/msys-md-0.dll ${DEST}/test
+ cp -a /ucrt64/bin/libbsd-0.dll ${DEST}
+ cp -a /ucrt64/bin/libbsd-0.dll ${DEST}/test
+ cp -a /ucrt64/bin/libmd-0.dll ${DEST}
+ cp -a /ucrt64/bin/libmd-0.dll ${DEST}/test
cp -a ../libffi/.libs/libffi*.dll ${DEST}
cp -a ../libffi/.libs/libffi*.dll ${DEST}/test
- cp -a ../libc3/.libs/msys-c3*.dll ${DEST}
- cp -a ../libc3/.libs/msys-c3*.dll ${DEST}/test
+ cp -a ../libc3/.libs/libc3*.dll ${DEST}
+ cp -a ../libc3/.libs/libc3*.dll ${DEST}/test
+ cp -a ../libc3/window/.libs/libc3_window*.dll ${DEST}
+ cp -a ../libc3/window/.libs/libc3_window*.dll ${DEST}/test
+ cp -a ../libc3/window/cairo/.libs/libc3_window_cairo*.dll ${DEST}
+ cp -a ../libc3/window/cairo/.libs/libc3_window_cairo*.dll ${DEST}/test
+ cp -a ../libc3/window/cairo/win32/.libs/libc3_window_cairo_win32*.dll ${DEST}
+ cp -a ../libc3/window/cairo/win32/.libs/libc3_window_cairo_win32*.dll ${DEST}/test
+ cp -a ../libc3/window/cairo/win32/demo/.libs/c3_window_cairo_win32_demo.exe ${DEST}
+ cp -a ../libc3/window/cairo/win32/demo/.libs/c3_window_cairo_win32_demo.exe ${DEST}/test
cp -a ../lib ${DEST}/
cp -a ../c3s/.libs/c3s*.exe ${DEST}
cp -a ../ic3/.libs/ic3*.exe ${DEST}