Commit 92b17b5b373fed4912b44827108b07c56759f47c

Thomas de Grivel 2023-11-21T13:16:09

wip win32

diff --git a/c3s/configure b/c3s/configure
index 51512b3..ca2efe0 100755
--- a/c3s/configure
+++ b/c3s/configure
@@ -47,14 +47,14 @@ LIBS="${LIBS:=-lm}"
 
 # Common config for all targets
 CFLAGS="$CFLAGS -W -Wall -Werror -std=c99 -pedantic"
-CPPFLAGS="$CPPFLAGS -I../libffi/include"
+CPPFLAGS="-I../libffi/include $CPPFLAGS"
 config_asan
 config_gnu
 pkg_config libbsd-overlay
 pkg_config libmd
 config_lib libmd -lmd 2>/dev/null
 config_lib dl -ldl 2>/dev/null
-LIBS="$LIBS ../libffi/.libs/libffi.la -pthread"
+LIBS="$LIBS ../libffi/libffi.la -pthread"
 
 # Asan config
 CFLAGS_ASAN="$CFLAGS -fsanitize=address -O1 -fno-omit-frame-pointer -g"
diff --git a/ic3/configure b/ic3/configure
index c512dcd..3c5f321 100755
--- a/ic3/configure
+++ b/ic3/configure
@@ -47,7 +47,7 @@ LIBS="${LIBS:=-lm}"
 
 # Common config for all targets
 CFLAGS="$CFLAGS -W -Wall -Werror -std=c99 -pedantic"
-CPPFLAGS="$CPPFLAGS -I../libffi/include"
+CPPFLAGS="-I../libffi/include $CPPFLAGS"
 config_asan
 config_gnu
 pkg_config libbsd-overlay
diff --git a/libc3/configure b/libc3/configure
index 42e653f..ddd324c 100755
--- a/libc3/configure
+++ b/libc3/configure
@@ -36,7 +36,7 @@ OBJECTS_COV="$(c2ext .cov.lo "$LO_SOURCES")"
 OBJECTS_DEBUG="$(c2ext .debug.lo "$LO_SOURCES")"
 
 # Common config for all targets
-CPPFLAGS="$CPPFLAGS -I../libffi/include"
+CPPFLAGS="-I../libffi/include $CPPFLAGS"
 CFLAGS="$CFLAGS -W -Wall -Werror -std=c99 -pedantic -fPIC"
 LDFLAGS="--shared -no-undefined ${LDFLAGS}"
 LIBS="${LIBS} -lm -pthread -rpath ${PREFIX}/lib"
diff --git a/libc3/window/cairo/configure b/libc3/window/cairo/configure
index fd403cc..033f02e 100755
--- a/libc3/window/cairo/configure
+++ b/libc3/window/cairo/configure
@@ -36,7 +36,7 @@ OBJECTS_COV="$(c2ext .cov.lo "$SOURCES")"
 OBJECTS_DEBUG="$(c2ext .debug.lo "$SOURCES")"
 
 # Common config for all targets
-CPPFLAGS="$CPPFLAGS -I../../../libffi/include -I../../.."
+CPPFLAGS="-I../../../libffi/include -I../../.. $CPPFLAGS"
 CFLAGS="$CFLAGS -W -Wall -Werror -std=c99 -pedantic -fPIC"
 LDFLAGS="--shared -no-undefined ${LDFLAGS}"
 LIBS="$LIBS -rpath ${PREFIX}/lib"
@@ -134,13 +134,20 @@ for SRC in $SOURCES; do
     echo "	${LIBTOOL} --tag=CC --mode=compile \${CC} \${CPPFLAGS} \${CFLAGS_DEBUG} -c $SRC -o $SRC_DEBUG_LO" >> ${CONFIG_MK}
 done
 
-if pkg-config xcb; then
+if pkg-config cairo-xcb; then
     HAVE_XCB=true
 else
     HAVE_XCB=false
 fi
 echo "HAVE_XCB = $HAVE_XCB" >> ${CONFIG_MK}
 
+if pkg-config cairo-win32; then
+    HAVE_WIN32=true
+else
+    HAVE_WIN32=false
+fi
+echo "HAVE_WIN32 = $HAVE_WIN32" >> ${CONFIG_MK}
+
 update_config_mk
 env_reset
 
@@ -148,6 +155,10 @@ if ${HAVE_COCOA}; then
     ( cd quartz && ./configure; )
 fi
 
+if ${HAVE_WIN32}; then
+    ( cd win32 && ./configure; )
+fi
+
 if ${HAVE_XCB}; then
     ( cd xcb && ./configure; )
 fi
diff --git a/libc3/window/cairo/win32/configure b/libc3/window/cairo/win32/configure
index 0eca667..7514e23 100644
--- a/libc3/window/cairo/win32/configure
+++ b/libc3/window/cairo/win32/configure
@@ -17,10 +17,10 @@ export SRC_TOP="$(dirname "$PWD")"
 
 . ../../../../config.subr
 
-LIB=libc3_window_cairo_xcb.la
-LIB_ASAN=libc3_window_cairo_xcb_asan.la
-LIB_COV=libc3_window_cairo_xcb_cov.la
-LIB_DEBUG=libc3_window_cairo_xcb_debug.la
+LIB=libc3_window_cairo_win32.la
+LIB_ASAN=libc3_window_cairo_win32_asan.la
+LIB_COV=libc3_window_cairo_win32_cov.la
+LIB_DEBUG=libc3_window_cairo_win32_debug.la
 
 echo "LIB = $LIB" >> ${CONFIG_MK}
 echo "LIB_ASAN = $LIB_ASAN" >> ${CONFIG_MK}
@@ -41,23 +41,23 @@ OBJECTS_COV="$(c2ext .cov.lo "$SOURCES")"
 OBJECTS_DEBUG="$(c2ext .debug.lo "$SOURCES")"
 
 # Common config for all targets
-CPPFLAGS="$CPPFLAGS -I../../../../libffi/include -I../../../.."
+CPPFLAGS="-I../../../../libffi/include -I../../../.. $CPPFLAGS"
 CFLAGS="$CFLAGS -W -Wall -Werror -std=c99 -pedantic -fPIC"
 LDFLAGS="--shared -no-undefined ${LDFLAGS}"
 LIBS="$LIBS -rpath ${PREFIX}/lib"
 config_asan
 config_gnu
-pkg_config xcb
 pkg_config xkbcommon
 pkg_config cairo
+pkg_config cairo-win32
 config_define PREFIX "\"${PREFIX}\""
 update_config_h
-LIBS="$LIBS -lxkbcommon -lxkbcommon-x11"
+LIBS="$LIBS -lxkbcommon"
 
 # Address Sanitizer config
 CFLAGS_ASAN="$CFLAGS -O1 -fsanitize=address -fno-omit-frame-pointer -g"
 LDFLAGS_ASAN="$LDFLAGS"
-LIBS_LOCAL_ASAN="../libc3_window_cairo_.la"
+LIBS_LOCAL_ASAN="../libc3_window_cairo_asan.la"
 LIBS_ASAN="$LIBS_LOCAL_ASAN $LIBS"
 
 # Coverage config
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
new file mode 100644
index 0000000..ab369f6
--- /dev/null
+++ b/libc3/window/cairo/win32/demo/c3_window_cairo_win32_demo.c
@@ -0,0 +1,35 @@
+/* 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 <stdio.h>
+#include <stdlib.h>
+#include <cairo/cairo.h>
+#include <libc3/c3.h>
+#include "../../../window.h"
+#include "../../c3_window_cairo_demo.h"
+#include "../window_cairo_win32.h"
+
+int main (void)
+{
+  s_window_cairo window;
+  window_cairo_init(&window, 0, 0, 800, 600,
+                    "C3.Window.Cairo.XCB 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))
+    return g_c3_exit_code;
+  return 0;
+}
diff --git a/libc3/window/cairo/win32/demo/c3_window_cairo_xcb_demo.c b/libc3/window/cairo/win32/demo/c3_window_cairo_xcb_demo.c
deleted file mode 100644
index 74bf506..0000000
--- a/libc3/window/cairo/win32/demo/c3_window_cairo_xcb_demo.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/* 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 <stdio.h>
-#include <stdlib.h>
-#include <cairo/cairo.h>
-#include <libc3/c3.h>
-#include "../../../window.h"
-#include "../../c3_window_cairo_demo.h"
-#include "../window_cairo_xcb.h"
-
-int main (void)
-{
-  s_window_cairo window;
-  window_cairo_init(&window, 0, 0, 800, 600,
-                    "C3.Window.Cairo.XCB 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))
-    return g_c3_exit_code;
-  return 0;
-}
diff --git a/libc3/window/cairo/win32/window_cairo_win32.c b/libc3/window/cairo/win32/window_cairo_win32.c
index 1ae049a..2f0d5ed 100644
--- a/libc3/window/cairo/win32/window_cairo_win32.c
+++ b/libc3/window/cairo/win32/window_cairo_win32.c
@@ -23,12 +23,8 @@ bool window_cairo_run (s_window_cairo *window)
   return window_cairo_win32_run(window);
 }
 
-bool window_cairo_win32_run (s_window_cairo *window)
-{
-  return true;
-}
-
-LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
+LRESULT CALLBACK window_cairo_win32_proc(HWND hwnd, UINT message,
+                                         WPARAM wParam, LPARAM lParam) {
   switch (message) {
   case WM_DESTROY:
     PostQuitMessage(0);
@@ -39,27 +35,44 @@ LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM 
   return 0;
 }
 
-int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int ncmdshow) {
-  WNDCLASSW wc = {0};
-
-  wc.hbrBackground = (HBRUSH)COLOR_BACKGROUND;
-  wc.hCursor = LoadCursor(NULL, IDC_ARROW);
-  wc.hInstance = hInst;
-  wc.lpszClassName = L"MyWindowClass";
-  wc.lpfnWndProc = WindowProcedure;
-
-  if (!RegisterClassW(&wc)) {
-    return -1;
+bool window_cairo_win32_run (s_window_cairo *window)
+{
+  WNDCLASSEX wc;
+  HWND hwnd;
+  MSG Msg;
+  wc.cbSize        = sizeof(WNDCLASSEX);
+  wc.style         = 0;
+  wc.lpfnWndProc   = window_cairo_win32_proc;
+  wc.cbClsExtra    = 0;
+  wc.cbWndExtra    = 0;
+  wc.hInstance     = GetModuleHandle(NULL);
+  wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
+  wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
+  wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
+  wc.lpszMenuName  = NULL;
+  wc.lpszClassName = L"Libc3WindowCairoWin32";
+  wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
+  if (!RegisterClassEx(&wc)) {
+    MessageBox(NULL, "Window Registration Failed!", "Error!",
+               MB_ICONEXCLAMATION | MB_OK);
+    return 0;
   }
-
-  CreateWindowW(L"MyWindowClass", L"My Window", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 
-		100, 100, 500, 500, NULL, NULL, NULL, NULL);
-
-  MSG msg = {0};
-  while ( GetMessage(&msg, NULL, 0, 0) ) {
-    TranslateMessage(&msg);
-    DispatchMessage(&msg);
+  hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,
+                        L"Libc3WindowCairoWin32",
+                        "The title of my window",
+                        WS_OVERLAPPEDWINDOW,
+                        CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
+                        NULL, NULL, GetModuleHandle(NULL), NULL);
+  if (hwnd == NULL) {
+    MessageBox(NULL, "Window Creation Failed!", "Error!",
+               MB_ICONEXCLAMATION | MB_OK);
+    return 0;
   }
-  return 0;
+  ShowWindow(hwnd, SW_SHOWDEFAULT);
+  UpdateWindow(hwnd);
+  while (GetMessage(&Msg, NULL, 0, 0) > 0) {
+    TranslateMessage(&Msg);
+    DispatchMessage(&Msg);
+  }
+  return Msg.wParam ? false : true;
 }
-
diff --git a/libc3/window/configure b/libc3/window/configure
index 2458c6a..8984970 100755
--- a/libc3/window/configure
+++ b/libc3/window/configure
@@ -36,7 +36,7 @@ OBJECTS_COV="$(c2ext .cov.lo "$SOURCES")"
 OBJECTS_DEBUG="$(c2ext .debug.lo "$SOURCES")"
 
 # Common config for all targets
-CPPFLAGS="$CPPFLAGS -I../../libffi/include -I../.."
+CPPFLAGS="-I../../libffi/include -I../.. $CPPFLAGS"
 CFLAGS="$CFLAGS -W -Wall -Werror -std=c99 -pedantic -fPIC"
 LDFLAGS="--shared -no-undefined ${LDFLAGS}"
 LIBS="$LIBS -rpath ${PREFIX}/lib"
diff --git a/test/configure b/test/configure
index 34db84f..c5b6b81 100755
--- a/test/configure
+++ b/test/configure
@@ -47,7 +47,7 @@ LIBS="${LIBS:=} -lm"
 
 # Common config for all targets
 CFLAGS="$CFLAGS -W -Wall -Werror -std=c99 -pedantic"
-CPPFLAGS="$CPPFLAGS -I../libffi/include"
+CPPFLAGS="-I../libffi/include $CPPFLAGS"
 config_asan
 config_gnu
 pkg_config libbsd-overlay