aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Tay <nick@windblume.net>2022-05-18 00:49:24 +1000
committerNicholas Tay <nick@windblume.net>2022-05-18 00:49:24 +1000
commit28941f769345fc8f1c6466ca95eb01262106970b (patch)
tree5bee8f1173cf7621af93801f3f1502e7fbb129c7
parentf5b4c235be20d76a3d86a94554ba0b0098cf1fc1 (diff)
downloadclak-28941f769345fc8f1c6466ca95eb01262106970b.tar.gz
clak-28941f769345fc8f1c6466ca95eb01262106970b.tar.bz2
clak-28941f769345fc8f1c6466ca95eb01262106970b.zip
Fix indent/styling
-rw-r--r--Makefile12
-rw-r--r--board/Makefile4
-rw-r--r--platform/linux.c17
-rw-r--r--platform/win32.c19
4 files changed, 32 insertions, 20 deletions
diff --git a/Makefile b/Makefile
index bc2e86a..1fdf54f 100644
--- a/Makefile
+++ b/Makefile
@@ -5,16 +5,16 @@ CC = gcc
CFLAGS += -std=c99 -Wall -Wextra -Wshadow -Werror
ifeq ($(OS),Windows_NT)
- LDLIBS = -lWinmm
- PLATFORM = win32
+ LDLIBS = -lWinmm
+ PLATFORM = win32
else
- UNAME_S := $(shell uname)
- ifeq ($(UNAME_S),Linux)
- PLATFORM = linux
+ UNAME_S := $(shell uname)
+ ifeq ($(UNAME_S),Linux)
+ PLATFORM = linux
PKG_CONF_LIBS = sdl2 SDL2_mixer x11 xi
CFLAGS += `pkg-config --cflags $(PKG_CONF_LIBS)`
LDLIBS += `pkg-config --libs $(PKG_CONF_LIBS)`
- endif
+ endif
endif
default: $(NAME)
diff --git a/board/Makefile b/board/Makefile
index 03449cc..ae3d691 100644
--- a/board/Makefile
+++ b/board/Makefile
@@ -4,9 +4,9 @@ CC = gcc
CFLAGS += -std=c99 -Wall -Wextra -Wshadow -Werror -pedantic -shared
ifeq ($(OS),Windows_NT)
- OUTEXT = dll
+ OUTEXT = dll
else
- OUTEXT = so
+ OUTEXT = so
CFLAGS += -fPIC
endif
diff --git a/platform/linux.c b/platform/linux.c
index 6793abc..78e74aa 100644
--- a/platform/linux.c
+++ b/platform/linux.c
@@ -58,17 +58,17 @@ void sound_play(unsigned char *buffer, unsigned int buffer_len)
return;
}
}
-
+
/* -1 means not-in-use channel */
Mix_PlayChannel(-1, loaded_chunk, 0);
}
-/*
+/*
* Uses XInput2 extensions to hook into the keyboard.
* Noticed this was possible when I used:
* $ xinput test-xi2 --root
* Resources used:
- * - https://github.com/freedesktop/xorg-xinput/blob/master/src/test_xi2.c
+ * - https://github.com/freedesktop/xorg-xinput/blob/master/src/test_xi2.c
* - https://cgit.freedesktop.org/xorg/proto/inputproto/commit/?id=f4f09d40e0fd94d267b280f2a82385dca1141347
*/
bool keyboard_hook(void)
@@ -84,7 +84,8 @@ bool keyboard_hook(void)
Window root_window = DefaultRootWindow(display);
int xi_event, xi_error;
- if (!XQueryExtension(display, "XInputExtension", &xi_opcode, &xi_event, &xi_error)) {
+ if (!XQueryExtension(display, "XInputExtension",
+ &xi_opcode, &xi_event, &xi_error)) {
printf("ERROR: Could not find XInputExtension.\n");
return false;
}
@@ -95,7 +96,7 @@ bool keyboard_hook(void)
XISetMask(mask, XI_RawKeyRelease);
XIEventMask event_mask = {
.deviceid = XIAllMasterDevices,
- .mask_len = sizeof(mask)/sizeof(mask[0]),
+ .mask_len = sizeof(mask) / sizeof(mask[0]),
.mask = mask,
};
XISelectEvents(display, root_window, &event_mask, 1);
@@ -123,7 +124,9 @@ void enter_idle(void)
while (running) {
XNextEvent(display, (XEvent *) &event);
/* XGenEventData fails if it isn't a XGenericEventCookie anyway */
- if (XGetEventData(display, &event) && event.type == GenericEvent && event.extension == xi_opcode) {
+ if (XGetEventData(display, &event)
+ && event.type == GenericEvent
+ && event.extension == xi_opcode) {
/* char *ur = event.evtype == XI_RawKeyPress ? "press" : "release"; */
/* unsigned int kc = ((XIDeviceEvent *) event.data)->detail; */
@@ -151,7 +154,7 @@ struct board *load_board(char *board_name)
printf("ERROR: Could not load board module.\n");
return false;
}
- // HACK: Cast to void function ptr then cast back, otherwise types are incompatible to the compiler.
+
fn_board_init board_init = dlsym(board_module, "board_init");
if (board_init == NULL) {
printf("ERROR: No board initialisation function could be loaded.\n");
diff --git a/platform/win32.c b/platform/win32.c
index 0b1da80..b2ed264 100644
--- a/platform/win32.c
+++ b/platform/win32.c
@@ -13,8 +13,11 @@ static HHOOK keyboard_hook_windows;
bool sound_init(float volume)
{
+ /* Single channel volume (max = 0xFFFF) */
DWORD channel_volume = volume * 0xFFFF;
- if (waveOutSetVolume(NULL, (channel_volume << 16) | channel_volume) != MMSYSERR_NOERROR)
+ /* Format is each channel is 16 bits */
+ DWORD stereo_volume = (channel_volume << 16) | channel_volume;
+ if (waveOutSetVolume(NULL, stereo_volume) != MMSYSERR_NOERROR)
return false;
return true;
}
@@ -25,7 +28,10 @@ void sound_play(unsigned char *buffer, unsigned int)
}
/* https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms644985(v=vs.85) */
-static LRESULT CALLBACK keyboard_windows_callback(int nCode, WPARAM wParam, LPARAM lParam)
+static LRESULT CALLBACK keyboard_windows_callback(
+ int nCode,
+ WPARAM wParam,
+ LPARAM lParam)
{
/* Needed to prevent repeat fires */
static DWORD prev_vk = 0;
@@ -54,7 +60,8 @@ static LRESULT CALLBACK keyboard_windows_callback(int nCode, WPARAM wParam, LPAR
bool keyboard_hook(void)
{
fprintf(stderr, "Setting up keyboard hook...\n");
- keyboard_hook_windows = SetWindowsHookEx(WH_KEYBOARD_LL, keyboard_windows_callback, NULL, 0);
+ keyboard_hook_windows = SetWindowsHookEx(WH_KEYBOARD_LL,
+ keyboard_windows_callback, NULL, 0);
if (keyboard_hook_windows == NULL) {
return false;
}
@@ -65,7 +72,8 @@ void keyboard_unhook(void)
{
fprintf(stderr, "Cleaning up keyboard hook...\n");
if (!UnhookWindowsHookEx(keyboard_hook_windows))
- printf("WARN: Windows keyboard hook could not be cleaned up! Error code: %lu\n", GetLastError());
+ printf("WARN: Windows keyboard hook could not be cleaned up! Error code: %lu\n",
+ GetLastError());
}
void enter_idle(void)
@@ -97,7 +105,8 @@ struct board *load_board(char *board_name)
return false;
}
// HACK: Cast to void function ptr then cast back, otherwise types are incompatible to the compiler.
- fn_board_init board_init = (fn_board_init) (void (*)(void)) GetProcAddress(board_module, "board_init");
+ fn_board_init board_init = (fn_board_init)(void (*)(void)) GetProcAddress(
+ board_module, "board_init");
if (board_init == NULL) {
printf("ERROR: No board initialisation function could be loaded.\n");
return false;