Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
adamws committed Nov 24, 2024
1 parent 198235d commit 42d25dd
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 60 deletions.
94 changes: 59 additions & 35 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,65 +51,89 @@ jobs:
name: Run functional tests
needs:
- build-and-test
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: klawa-ubuntu-latest
name: klawa-${{ matrix.os }}
path: zig-out/bin
- name: Install dependencies
shell: bash
run: |
pwd
ls -alh zig-out/bin
- if: matrix.os == 'ubuntu-latest'
name: Install dependencies
shell: bash
run: |
sudo apt-get update
sudo apt-get install ffmpeg xdotool x11-apps xvfb
- if: matrix.os == 'windows-latest'
name: Install dependencies
shell: bash
run: |
choco install autohotkey.portable ffmpeg
- if: matrix.os == 'windows-latest'
name: Install Mesa
shell: cmd
run: |
curl.exe -L --output mesa.7z --url https://github.com/pal1000/mesa-dist-win/releases/download/24.2.7/mesa3d-24.2.7-release-msvc.7z
"C:\Program Files\7-Zip\7z.exe" x mesa.7z
dir
systemwidedeploy.cmd 1
- name: Install python dependencies
shell: bash
run: |
cd tests
python -m venv .env
. .env/bin/activate
pip install -r dev-requirements.txt
- name: Run tests
- if: matrix.os == 'ubuntu-latest'
name: Fix executable permisions
shell: bash
run: |
chmod +x zig-out/bin/klawa
- name: Run tests
shell: bash
run: |
# not running with pytest-xdist because renders are way off
# when framerate drops below expected 60fps:
cd tests && . .env/bin/activate && python -m pytest src/
cd tests && python -m pytest src/
- uses: actions/upload-artifact@v4
if: always()
with:
name: report
name: report-${{ matrix.os }}
path: tests/report/
retention-days: 2
if-no-files-found: error

deploy-preview:
name: Deploy tests results
needs:
- run-functional-tests
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: ./tests
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: report
path: tests/report
- name: Install Vercel CLI
run: npm install --global vercel@latest
- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
- name: Build Project Artifacts
run: vercel build --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy Project Artifacts to Vercel
run: vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }} > url.txt
- name: Add summary
shell: bash
run: |
echo '### Deployed' >> $GITHUB_STEP_SUMMARY
cat url.txt >> $GITHUB_STEP_SUMMARY
# deploy-preview:
# name: Deploy tests results
# needs:
# - run-functional-tests
# runs-on: ubuntu-latest
# defaults:
# run:
# shell: bash
# working-directory: ./tests
# steps:
# - uses: actions/checkout@v4
# - uses: actions/download-artifact@v4
# with:
# name: report
# path: tests/report
# - name: Install Vercel CLI
# run: npm install --global vercel@latest
# - name: Pull Vercel Environment Information
# run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
# - name: Build Project Artifacts
# run: vercel build --token=${{ secrets.VERCEL_TOKEN }}
# - name: Deploy Project Artifacts to Vercel
# run: vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }} > url.txt
# - name: Add summary
# shell: bash
# run: |
# echo '### Deployed' >> $GITHUB_STEP_SUMMARY
# cat url.txt >> $GITHUB_STEP_SUMMARY
9 changes: 8 additions & 1 deletion src/ffmpeg.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const process = std.process;
const Child = process.Child;
const File = std.fs.File;

const builtin = @import("builtin");

pub const Ffmpeg = struct {
child: Child,

Expand All @@ -14,8 +16,13 @@ pub const Ffmpeg = struct {
) !Ffmpeg {
const resolution = try std.fmt.allocPrint(allocator, "{d}x{d}", .{ width, height });
defer allocator.free(resolution);
const exec_name: []const u8 = switch (builtin.target.os.tag) {
.linux => "ffmpeg",
.windows => "ffmpeg.exe",
else => @compileError("unsupported platform"),
};
const args = [_][]const u8{
"ffmpeg", "-y",
exec_name, "-y",
"-f", "rawvideo",
"-framerate", "60",
"-s", resolution,
Expand Down
53 changes: 53 additions & 0 deletions src/layout_labels.zig
Original file line number Diff line number Diff line change
Expand Up @@ -432,3 +432,56 @@ const layout_labels_lookup_slice = blk: {

pub const labels_lookup = std.StaticStringMap(usize).initComptime(layout_labels_lookup_slice);

//const testing = @import("std").testing;
//
//test "test label mapping" {
// const allocator = std.testing.allocator;
// std.debug.print("{any}\n", .{x11.XK_BackSpace});
//
// const display: *x11.Display = x11.XOpenDisplay(null) orelse {
// std.debug.print("Unable to connect to X server\n", .{});
// return error.X11InitializationFailed;
// };
// var min_keycode: c_int = 0;
// var max_keycode: c_int = 0;
// _ = x11.XDisplayKeycodes(display, &min_keycode, &max_keycode);
//
// var keysyms_per_keycode: c_int = 0;
// const origkeymap = x11.XGetKeyboardMapping(display, @intCast(min_keycode), (max_keycode - min_keycode + 1), &keysyms_per_keycode);
// //defer x11.XFree(origkeymap);
//
// std.debug.print("{} {} keysyms_per_keycode {}\n", .{min_keycode, max_keycode, keysyms_per_keycode});
//
// //var lookup = try allocator.alloc(x11.KeySym, (max_keycode - min_keycode + 1) * keysyms_per_keycode);
// //var lookup_index: usize = 0;
//
// var map = std.AutoHashMap(x11.KeySym, usize).init(allocator);
// defer map.deinit();
//
// const no_symbol = "NoSymbol";
// var keymap = origkeymap;
// for (@as(usize, @intCast(min_keycode))..@as(usize, @intCast(max_keycode+1))) |keycode| {
// var max = keysyms_per_keycode - 1;
// while (max >= 0 and keymap[@as(usize, @intCast(max))] == x11.NoSymbol) {
// max -= 1;
// }
// std.debug.print("{}\t", .{keycode});
// for (0..@as(usize, @intCast(max+1))) |j| {
// const ks = keymap[j];
//
// //lookup[lookup_index] = ks;
// //lookup_index += 1;
// try map.put(ks, keycode);
//
// const s = if (ks != x11.NoSymbol) x11.XKeysymToString(ks) else no_symbol.ptr;
// std.debug.print("0x{x} ({s})\t", .{ks, s});
// }
// keymap += @as(usize, @intCast(keysyms_per_keycode));
// std.debug.print("\n", .{});
// }
//
// var iterator = map.iterator();
// while (iterator.next()) |entry| {
// std.debug.print("{x}: {}\n", .{entry.key_ptr.*, entry.value_ptr.*});
// }
//}
4 changes: 4 additions & 0 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,10 @@ pub fn main() !void {
}

// NOTE: not able to stop x11Listener yet, applicable only for x11Producer
switch (builtin.target.os.tag) {
.windows => backend.stop(),
else => {},
}
backend.is_running = false;

if (renderer) |*r| try r.wait();
Expand Down
1 change: 0 additions & 1 deletion src/textures.zig
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ fn getPositions(sizes: []const rl.Vector2) [keycap_sizes.len]rl.Vector2 {
}

pub fn getPositionBySize(size: rl.Vector2) rl.Vector2 {
std.debug.print("Looking for {d} {d}\n", .{size.x, size.y});
for (keycap_sizes, 0..) |s, i| {
if (size.x == s.x and size.y == s.y) {
return atlas_positions[i];
Expand Down
10 changes: 9 additions & 1 deletion src/win32.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const labels_lookup = @import("layout_labels.zig").labels_lookup;

pub var is_running: bool = false;

var thread_id: c.DWORD = undefined;
var app_state_l: *AppState = undefined;
var layout: c.HKL = undefined;
var hook: ?c.HHOOK = null;
Expand Down Expand Up @@ -78,6 +79,7 @@ pub fn listener(app_state: *AppState, window_handle: *anyopaque) !void {
is_running = true;

_ = window_handle;
thread_id = c.GetCurrentThreadId();

app_state_l = app_state;
layout = c.GetKeyboardLayout(0);
Expand All @@ -86,10 +88,16 @@ pub fn listener(app_state: *AppState, window_handle: *anyopaque) !void {
defer _ = c.UnhookWindowsHookEx(hook.?);

var msg: c.MSG = undefined;
while (c.GetMessageA(&msg, null, 0, 0) > 0) {
while (is_running and c.GetMessageA(&msg, null, 0, 0) > 0) {
_ = c.TranslateMessage(&msg);
_ = c.DispatchMessageA(&msg);
}
std.debug.print("Exit win32 listener\n", .{});
}

pub fn stop() void {
is_running = false;
_ = c.PostThreadMessageA(thread_id, c.WM_QUIT, 0, 0);
}

pub fn keysymToString(keysym: c_ulong) [*c]const u8 {
Expand Down
1 change: 1 addition & 0 deletions tests/dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pytest-metadata==3.1.1
pytest-html==4.1.1
pytest-xdist==3.6.1
PyVirtualDisplay==3.0
keyboard==0.13.5
2 changes: 1 addition & 1 deletion tests/pytest.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[pytest]
addopts =
--html=report/index.html
--app-path=../zig-out/bin/klawa
--app-dir=../zig-out/bin
generate_report_on_test = True
render_collapsed =
log_cli = True
Expand Down
10 changes: 6 additions & 4 deletions tests/src/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import os
import shutil
import sys
from pathlib import Path

import pytest
Expand All @@ -11,18 +12,19 @@

def pytest_addoption(parser) -> None:
parser.addoption(
"--app-path",
"--app-dir",
action="store",
help="Path to klawa executable",
help="Path to directory of klawa executable",
default=False,
)


@pytest.fixture(scope="session")
def app_path(request) -> Path:
app_path = request.config.getoption("--app-path")
app_path = request.config.getoption("--app-dir")
assert app_path, "App path is required"
return Path(os.path.realpath(app_path))
app_name = "klawa.exe" if sys.platform == "win32" else "klawa"
return Path(os.path.realpath(app_path)) / app_name


@pytest.fixture
Expand Down
Loading

0 comments on commit 42d25dd

Please sign in to comment.