Skip to content

Commit

Permalink
Fix windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
root authored and root committed Apr 26, 2023
1 parent 110d03a commit 31192c3
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ lib/
bin/
*.o
dist/
*.obj
*.exe
3 changes: 3 additions & 0 deletions mk/windows.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 4 additions & 6 deletions src/platform/windows/windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
File renamed without changes.
18 changes: 13 additions & 5 deletions src/warpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,32 @@
#endif
#include "platform.h"

#include <getopt.h>
#include <sys/types.h>
#include <unistd.h>
#include <assert.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <time.h>

#ifndef _MSC_VER
#include <getopt.h>
#include <unistd.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/types.h>
#endif


#ifndef PATH_MAX
#define PATH_MAX 1024
#endif

#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX_HIST_ENTS 16

#ifdef _MSC_VER
typedef int ssize_t;
#endif

enum {
MODE_RESERVED,

Expand Down
4 changes: 4 additions & 0 deletions src/windows/build.bat
Original file line number Diff line number Diff line change
@@ -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
Binary file modified src/windows/icon.res
100644 → 100755
Binary file not shown.
22 changes: 20 additions & 2 deletions src/windows/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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);

}

0 comments on commit 31192c3

Please sign in to comment.