diff --git a/.gitignore b/.gitignore index e3944d3..1ece789 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ lib/ bin/ *.o dist/ +*.obj +*.exe diff --git a/mk/windows.mk b/mk/windows.mk index 581bdae..8a4af28 100755 --- a/mk/windows.mk +++ b/mk/windows.mk @@ -16,3 +16,6 @@ all: $(OBJFILES) -mkdir bin $(CC) -o bin/warpd.exe src/windows/icon.res $(OBJFILES) $(CFLAGS) #$(CC) /Fe:bin/warpd.exe $(OBJFILES) user32.lib gdi32.lib +clean: + rm $(OBJFILES) + rm -rf bin diff --git a/src/platform/windows/windows.c b/src/platform/windows/windows.c index 34a1503..8bc98b6 100755 --- a/src/platform/windows/windows.c +++ b/src/platform/windows/windows.c @@ -22,7 +22,6 @@ static const char *input_lookup_name(uint8_t code, int shifted); static LRESULT CALLBACK keyboardHook(int nCode, WPARAM wParam, LPARAM lParam) { KBDLLHOOKSTRUCT *ev = (KBDLLHOOKSTRUCT *)lParam; - static uint8_t keystate[256]; uint8_t code = ev->vkCode; uint8_t mods = 0; @@ -45,12 +44,11 @@ static LRESULT CALLBACK keyboardHook(int nCode, WPARAM wParam, LPARAM lParam) goto passthrough; } - keystate[code] = pressed; mods = ( - ((keystate[VK_LSHIFT] || keystate[VK_RSHIFT]) ? PLATFORM_MOD_SHIFT : 0) | - ((keystate[VK_LCONTROL] || keystate[VK_RCONTROL]) ? PLATFORM_MOD_CONTROL : 0) | - ((keystate[VK_LMENU] || keystate[VK_RMENU]) ? PLATFORM_MOD_ALT : 0) | - ((keystate[VK_LWIN] || keystate[VK_RWIN]) ? PLATFORM_MOD_META : 0)); + ((GetKeyState(VK_SHIFT) & 0x8000) ? PLATFORM_MOD_SHIFT : 0) | + ((GetKeyState(VK_CONTROL) & 0x8000) ? PLATFORM_MOD_CONTROL : 0) | + ((GetKeyState(VK_MENU) & 0x8000) ? PLATFORM_MOD_ALT : 0) | + ((GetKeyState(VK_LWIN) & 0x8000 || GetKeyState(VK_RWIN) & 0x8000) ? PLATFORM_MOD_META : 0)); PostMessage(NULL, WM_KEY_EVENT, pressed << 16 | mods << 8 | code, 0); diff --git a/src/platform/windows/screen.c b/src/platform/windows/winscreen.c similarity index 100% rename from src/platform/windows/screen.c rename to src/platform/windows/winscreen.c diff --git a/src/warpd.h b/src/warpd.h index 212bfac..258c8d4 100644 --- a/src/warpd.h +++ b/src/warpd.h @@ -26,17 +26,21 @@ #endif #include "platform.h" -#include -#include -#include #include #include #include #include -#include -#include #include +#ifndef _MSC_VER + #include + #include + #include + #include + #include +#endif + + #ifndef PATH_MAX #define PATH_MAX 1024 #endif @@ -44,6 +48,10 @@ #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define MAX_HIST_ENTS 16 +#ifdef _MSC_VER + typedef int ssize_t; +#endif + enum { MODE_RESERVED, diff --git a/src/windows/build.bat b/src/windows/build.bat new file mode 100644 index 0000000..888a36c --- /dev/null +++ b/src/windows/build.bat @@ -0,0 +1,4 @@ +cd /D "%~dp0" +mkdir obj +cl /Foobj\ /Fe:warpd.exe *.c icon.res ..\config.c ..\daemon.c ..\grid.c ..\grid_drw.c ..\hint.c ..\histfile.c ..\history.c ..\input.c ..\mode-loop.c ..\mouse.c ..\normal.c ..\screen.c ..\scroll.c ..\platform\windows\*.c user32.lib gdi32.lib shell32.lib +rmdir /s /q obj diff --git a/src/windows/icon.res b/src/windows/icon.res old mode 100644 new mode 100755 index ac94f20..0d1272e Binary files a/src/windows/icon.res and b/src/windows/icon.res differ diff --git a/src/windows/main.c b/src/windows/main.c index 71b3f59..d058e98 100755 --- a/src/windows/main.c +++ b/src/windows/main.c @@ -15,6 +15,7 @@ static HWND icon_wnd; static HMENU icon_menu; static char config_path[1024]; +static char config_dir[1024]; static const char *icon_menu_items[] = { "edit config", @@ -143,17 +144,34 @@ static int platform_main(struct platform *_platform) return 0; } +void redirect_stdout() +{ + long lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE); + int hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); + FILE *fp = _fdopen( hConHandle, "w" ); + *stdout = *fp; + setvbuf( stdout, NULL, _IONBF, 0 ); +} + + int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { CreateMutex( NULL, TRUE, "warpd" ); - if (GetLastError() == ERROR_ALREADY_EXISTS) { + if (GetLastError() == ERROR_ALREADY_EXISTS) { MessageBox(NULL, "warpd is already running", "", MB_OK|MB_ICONSTOP); exit(0); } - sprintf(config_path, "%s\\warpd\\warpd.conf", getenv("APPDATA")); + + sprintf(config_dir, "%s\\warpd", getenv("APPDATA")); + sprintf(config_path, "%s\\warpd.conf", config_dir); + + CreateDirectory(config_dir, NULL); + HANDLE fh = CreateFile(config_path, GENERIC_WRITE, 0, 0, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0); + CloseHandle(fh); CreateThread(0, 0, icon_thread, 0, 0, NULL); platform_run(platform_main); + }