From 9197e41f40b62cad0ed73d2b893e6bc89a1e125d Mon Sep 17 00:00:00 2001 From: treeform Date: Mon, 23 Feb 2026 08:20:15 -0800 Subject: [PATCH] Remove ugly spaces. --- examples/openurl.nim | 7 +++-- experiments/nimasynchttp.nim | 1 - experiments/nimasynchttp2.nim | 1 - experiments/nimws.nim | 1 - src/windy/platforms/emscripten/emdefs.nim | 24 ++++++++--------- src/windy/platforms/emscripten/platform.nim | 6 ++--- src/windy/platforms/linux/wayland/basic.nim | 30 ++++++++++----------- src/windy/platforms/linux/x11/x.nim | 1 - src/windy/platforms/win32/platform.nim | 18 ++++++------- 9 files changed, 42 insertions(+), 47 deletions(-) diff --git a/examples/openurl.nim b/examples/openurl.nim index e4ef84df..c432ccfa 100644 --- a/examples/openurl.nim +++ b/examples/openurl.nim @@ -1,4 +1,3 @@ -import windy - -openUrl("https://github.com") - +import windy + +openUrl("https://github.com") diff --git a/experiments/nimasynchttp.nim b/experiments/nimasynchttp.nim index 25fb06d2..8516469c 100644 --- a/experiments/nimasynchttp.nim +++ b/experiments/nimasynchttp.nim @@ -1,4 +1,3 @@ - import windy, random, tables, times import std/asyncdispatch diff --git a/experiments/nimasynchttp2.nim b/experiments/nimasynchttp2.nim index 6e5aaed0..e775d5f9 100644 --- a/experiments/nimasynchttp2.nim +++ b/experiments/nimasynchttp2.nim @@ -1,4 +1,3 @@ - import windy, random, tables, times import std/asyncdispatch diff --git a/experiments/nimws.nim b/experiments/nimws.nim index b656ce4e..42baa655 100644 --- a/experiments/nimws.nim +++ b/experiments/nimws.nim @@ -1,4 +1,3 @@ - import windy, random, tables, times import std/asyncdispatch, ws diff --git a/src/windy/platforms/emscripten/emdefs.nim b/src/windy/platforms/emscripten/emdefs.nim index f2e0b1eb..77809964 100644 --- a/src/windy/platforms/emscripten/emdefs.nim +++ b/src/windy/platforms/emscripten/emdefs.nim @@ -91,7 +91,7 @@ EM_JS(void, setup_drag_drop_handlers_internal, (const char* target, void* userDa console.error("Canvas not found for drag and drop setup"); return; } - + // Prevent default drag behaviors on the canvas. // https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API // elements do not support drop by default, you have to prevent default and stop propagation to enable drop. @@ -99,43 +99,43 @@ EM_JS(void, setup_drag_drop_handlers_internal, (const char* target, void* userDa e.preventDefault(); e.stopPropagation(); }, false); - + canvas.addEventListener('dragover', function(e) { e.preventDefault(); e.stopPropagation(); }, false); - + canvas.addEventListener('dragleave', function(e) { e.preventDefault(); e.stopPropagation(); }, false); - + // Handle the drop event. canvas.addEventListener('drop', function(e) { e.preventDefault(); e.stopPropagation(); - + if (!e.dataTransfer || !e.dataTransfer.files || e.dataTransfer.files.length === 0) { return; } - + // Process each dropped file. for (let i = 0; i < e.dataTransfer.files.length; i++) { const file = e.dataTransfer.files[i]; const reader = new FileReader(); - + reader.onload = function(evt) { if (evt.target.readyState !== FileReader.DONE) return; - + const arrayBuffer = evt.target.result; const uint8Array = new Uint8Array(arrayBuffer); - + // read the raw data from the drop event into javascript. // Allocate and copy filename. const fileNameLen = lengthBytesUTF8(file.name) + 1; const fileNamePtr = _malloc(fileNameLen); stringToUTF8(file.name, fileNamePtr, fileNameLen); - + // Allocate memory for file data. const fileDataLen = uint8Array.length; const fileDataPtr = _malloc(fileDataLen); @@ -143,12 +143,12 @@ EM_JS(void, setup_drag_drop_handlers_internal, (const char* target, void* userDa // Call the C helper function. It copies the data into Nim structures. Module._windy_file_drop_callback(userData, fileNamePtr, fileDataPtr, fileDataLen); - + // Free allocated memory. _free(fileNamePtr); _free(fileDataPtr); }; - + reader.readAsArrayBuffer(file); } }, false); diff --git a/src/windy/platforms/emscripten/platform.nim b/src/windy/platforms/emscripten/platform.nim index 51d877ea..5399ac05 100644 --- a/src/windy/platforms/emscripten/platform.nim +++ b/src/windy/platforms/emscripten/platform.nim @@ -637,17 +637,17 @@ proc handleRune(window: Window, rune: Rune) = proc windy_file_drop_callback(userData: pointer, fileNamePtr: cstring, fileDataPtr: pointer, fileDataLen: cint) {.exportc, cdecl, codegenDecl: "EMSCRIPTEN_KEEPALIVE $# $#$#".} = ## callback to handle the file drop event. ## EMSCRIPTEN_KEEPALIVE is required to avoid dead code elimination. - + let window = cast[Window](userData) if window == nil or window.onFileDrop == nil: return - + # convert the js data into Nim data. let fileName = $fileNamePtr var fileData = newString(fileDataLen) if fileDataLen > 0: copyMem(fileData[0].addr, fileDataPtr, fileDataLen) - + window.onFileDrop(fileName, fileData) proc getState(fetch: ptr emscripten_fetch_t): EmsHttpRequestState = diff --git a/src/windy/platforms/linux/wayland/basic.nim b/src/windy/platforms/linux/wayland/basic.nim index 04d833cb..d0df5373 100644 --- a/src/windy/platforms/linux/wayland/basic.nim +++ b/src/windy/platforms/linux/wayland/basic.nim @@ -40,7 +40,7 @@ proc asString[T](x: openarray[T]): string = proc connect*(name = getEnv("WAYLAND_SOCKET")): Display = new result, (proc(d: Display) = close d.socket) - + result.display = result result.id = Id 1 result.ids[1] = result @@ -48,11 +48,11 @@ proc connect*(name = getEnv("WAYLAND_SOCKET")): Display = let d = result result.deleteId = proc(id: Id) = d.ids.del id.uint32 - + var name = if name != "": $name else: "wayland-0" - + if not name.isAbsolute: var runtimeDir = getEnv("XDG_RUNTIME_DIR") if runtimeDir == "": raise WindyError.newException("XDG_RUNTIME_DIR not set in the environment") @@ -62,11 +62,11 @@ proc connect*(name = getEnv("WAYLAND_SOCKET")): Display = if sock == osInvalidSocket: raise WindyError.newException("Failed to create socket") var a = "\1\0" & name - + if sock.connect(cast[ptr SockAddr](a[0].addr), uint32 a.len) < 0: close sock raise WindyError.newException("Failed to connect to wayland server") - + result.socket = newSocket(sock, nativesockets.AF_UNIX, nativesockets.SOCK_STREAM, nativesockets.IPPROTO_IP) proc new(d: Display, t: type): t = @@ -89,10 +89,10 @@ proc serialize[T](x: T): seq[uint32] = elif x is int: result.add cast[uint32](x.int32) - + elif x is float: result.add cast[uint32](x.float32) - + elif x is bool: result.add x.uint32 @@ -109,7 +109,7 @@ proc serialize[T](x: T): seq[uint32] = elif x is tuple|object: for x in x.fields: result.add x.serialize - + elif x is array: for x in x: result.add x.serialize @@ -117,15 +117,15 @@ proc serialize[T](x: T): seq[uint32] = elif x is set: when T.sizeof > uint32.sizeof: {.error: "too large set".} result.add cast[uint32](x) - + elif x is Proxy: result.add x.id.uint32 - + elif x is FileDescriptor: discard # will be stored in the ancillary data of the UNIX domain socket message (msg_control) elif T.sizeof == uint32.sizeof: result.add cast[uint32](x) - + else: {.error: "unserializable type " & $T.} proc fileDescriptors[T](x: T): seq[FileDescriptor] = @@ -167,7 +167,7 @@ proc deserialize(display: Display, x: seq[uint32], T: type, i: var uint32): T = elif result is tuple|object: for v in result.fields: v = deserialize(display, x, typeof(v), i) - + elif result is array: for v in result.mitems: v = deserialize(display, x, typeof(v), i) @@ -175,7 +175,7 @@ proc deserialize(display: Display, x: seq[uint32], T: type, i: var uint32): T = elif result is set: when T.sizeof > uint.sizeof: {.error: "too large set".} result = cast[T](x[i]); i += 1 - + elif result is FileDescriptor: ## todo @@ -196,14 +196,14 @@ proc marshal[T](x: Proxy, op: int, data: T = ()) = var d = data.serialize d.insert ((d.len.uint32 * uint32.sizeof.uint32 + 8) shl 16) or (op.uint32 and 0x0000ffff) d.insert x.id.uint32 - + let fds = data.fileDescriptors var iovec = IOVec( iov_base: d[0].addr, iov_len: csize_t d.len * uint32.sizeof, ) - + var hdr = 0.cint.repeat(csize_t.sizeof div cint.sizeof) & @[SOL_SOCKET, SCM_RIGHTS] & cast[seq[cint]](fds) cast[ptr csize_t](hdr[0].addr)[] = csize_t hdr.len * cint.sizeof diff --git a/src/windy/platforms/linux/x11/x.nim b/src/windy/platforms/linux/x11/x.nim index ca377c51..27f27158 100644 --- a/src/windy/platforms/linux/x11/x.nim +++ b/src/windy/platforms/linux/x11/x.nim @@ -1,4 +1,3 @@ - type XID* = culong Mask* = culong diff --git a/src/windy/platforms/win32/platform.nim b/src/windy/platforms/win32/platform.nim index 64359b46..8e28b877 100644 --- a/src/windy/platforms/win32/platform.nim +++ b/src/windy/platforms/win32/platform.nim @@ -253,7 +253,7 @@ proc destroy(window: Window) = window.onButtonRelease = nil window.onRune = nil window.onImeChange = nil - + # Destroy graphics context window.destoryGraphicsContext() @@ -1068,10 +1068,10 @@ when Backend == OpenGLBackend: proc createGraphicsContext( - window: Window, - depthBits: int, + window: Window, + depthBits: int, stencilBits: int, - msaa: MSAA, + msaa: MSAA, vsync: bool, openglVersion: OpenGLVersion ) = @@ -1167,10 +1167,10 @@ elif Backend == DirectXBackend: discard proc createGraphicsContext( - window: Window, - depthBits: int, - stencilBits: int, - msaa: MSAA, + window: Window, + depthBits: int, + stencilBits: int, + msaa: MSAA, vsync: bool, openglVersion: OpenGLVersion ) = @@ -1231,7 +1231,7 @@ proc newWindow*( result.style = style result.visible = visible - + except WindyError as e: destroy result