Skip to content

Another attempt at Windows support (less ifdefs) - #66

Closed
adsr wants to merge 2 commits into
masterfrom
windows2
Closed

Another attempt at Windows support (less ifdefs)#66
adsr wants to merge 2 commits into
masterfrom
windows2

Conversation

@adsr

@adsr adsr commented Apr 8, 2024

Copy link
Copy Markdown
Contributor

See #58 for the first attempt.

@sewbacca

sewbacca commented May 12, 2024

Copy link
Copy Markdown

I tried compiling under msys/ucrt64, but got a compiler error.

Click here to see error message
termbox2 $ make
cc -DTB_IMPL -DTB_LIB_OPTS -std=c99 -Wall -Wextra -pedantic -Wno-unused-result -g -O0 -D_XOPEN_SOURCE -D_DEFAULT_SOURCE  demo/keyboard.c -o demo/keyboard
In file included from demo/keyboard.c:5:
demo/../termbox2.h: In function 'init_term_caps':
demo/../termbox2.h:2162:16: warning: implicit declaration of function 'parse_terminfo_caps' [-Wimplicit-function-declaration]
 2162 |         return parse_terminfo_caps();
      |                ^~~~~~~~~~~~~~~~~~~
demo/../termbox2.h: In function 'tb_deinit':
demo/../termbox2.h:2320:46: warning: ordered comparison of pointer with integer zero [-Wpedantic]
 2320 |     if (global.caps[0] != NULL && global.wfd >= 0) {
      |                                              ^~
demo/../termbox2.h: At top level:
demo/../termbox2.h:2380:12: error: static declaration of 'parse_terminfo_caps' follows non-static declaration
 2380 | static int parse_terminfo_caps(void) {
      |            ^~~~~~~~~~~~~~~~~~~
demo/../termbox2.h:2162:16: note: previous implicit declaration of 'parse_terminfo_caps' with type 'int()'
 2162 |         return parse_terminfo_caps();
      |                ^~~~~~~~~~~~~~~~~~~
demo/../termbox2.h: In function 'tb_compat_win32_wcwidth':
demo/../termbox2.h:3590:44: warning: unused parameter 'c' [-Wunused-parameter]
 3590 | static int tb_compat_win32_wcwidth(wchar_t c) {
      |                                    ~~~~~~~~^
demo/../termbox2.h: In function 'tb_compat_win32_wcswidth':
demo/../termbox2.h:3594:52: warning: unused parameter 's' [-Wunused-parameter]
 3594 | static int tb_compat_win32_wcswidth(const wchar_t *s, size_t n) {
      |                                     ~~~~~~~~~~~~~~~^
demo/../termbox2.h:3594:62: warning: unused parameter 'n' [-Wunused-parameter]
 3594 | static int tb_compat_win32_wcswidth(const wchar_t *s, size_t n) {
      |                                                       ~~~~~~~^
demo/../termbox2.h: In function 'tb_compat_win32_get_fds':
demo/../termbox2.h:3598:41: warning: unused parameter 'ttyfd' [-Wunused-parameter]
 3598 | static int tb_compat_win32_get_fds(int *ttyfd, int *resizefd) {
      |                                    ~~~~~^~~~~
demo/../termbox2.h:3598:53: warning: unused parameter 'resizefd' [-Wunused-parameter]
 3598 | static int tb_compat_win32_get_fds(int *ttyfd, int *resizefd) {
      |                                                ~~~~~^~~~~~~~
demo/../termbox2.h: At top level:
demo/../termbox2.h:3646:12: warning: 'tb_compat_win32_update_term_size_via_esc' defined but not used [-Wunused-function]
 3646 | static int tb_compat_win32_update_term_size_via_esc(void) {
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
demo/../termbox2.h:2380:12: warning: 'parse_terminfo_caps' defined but not used [-Wunused-function]
 2380 | static int parse_terminfo_caps(void) {
      |            ^~~~~~~~~~~~~~~~~~~
make: *** [Makefile:30: demo/keyboard] Fehler 1
Any ideas how to fix this?

@adsr

adsr commented May 12, 2024

Copy link
Copy Markdown
Contributor Author

Hi @sewbacca thank you for trying this out. I'm not near my Windows machine but I pushed 94b5082 which is completely untested but may fix your issue. I'll try it on my setup soon.

@sewbacca

Copy link
Copy Markdown

Thanks for your quick response! It does compile now, but I don't have an example to test it against, because I just stumbled accross this library and want to check it out :D

@adsr
adsr marked this pull request as draft May 20, 2024 03:32
@sewbacca

Copy link
Copy Markdown

I'm not sure if I did something wrong, but I believe tb_peek returns an invalid error code:

Unknown error 0 on Windows
#define TB_IMPL
#include <termbox2.h>

int main()
{
        tb_init();
        struct tb_event event = {};
        int err = TB_OK;
        while(event.key != TB_KEY_CTRL_C) {
                err = tb_peek_event(&event, 100);
                if(err != TB_OK && err != TB_ERR_NO_EVENT && !(err == TB_ERR_POLL && tb_last_errno() == EINTR))
                        break;
        }
        tb_shutdown();

        if (err != TB_OK)
                printf("%s\n", tb_strerror(err));
}

@adsr

adsr commented Jul 28, 2024

Copy link
Copy Markdown
Contributor Author

@sewbacca Hm, that's strange. TB_OK should equal zero, so I'm not sure what's happening there. I'll have a closer look next time I'm on a Windows machine.

@adsr

adsr commented Nov 10, 2025

Copy link
Copy Markdown
Contributor Author

Superseded by #123

@adsr adsr closed this Nov 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants