Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions examples/openurl.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import windy

openUrl("https://github.com")

import windy

openUrl("https://github.com")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you removed a trailing newline!

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i deleted 2 trailing newlines, because it does not sow 🔴 it means there is one newline left.

1 change: 0 additions & 1 deletion experiments/nimasynchttp.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import windy, random, tables, times

import std/asyncdispatch
Expand Down
1 change: 0 additions & 1 deletion experiments/nimasynchttp2.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import windy, random, tables, times

import std/asyncdispatch
Expand Down
1 change: 0 additions & 1 deletion experiments/nimws.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import windy, random, tables, times

import std/asyncdispatch, ws
Expand Down
24 changes: 12 additions & 12 deletions src/windy/platforms/emscripten/emdefs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -91,64 +91,64 @@ 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.
canvas.addEventListener('dragenter', function(e) {
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);
HEAPU8.set(uint8Array, fileDataPtr);

// 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);
Expand Down
6 changes: 3 additions & 3 deletions src/windy/platforms/emscripten/platform.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
30 changes: 15 additions & 15 deletions src/windy/platforms/linux/wayland/basic.nim
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ 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

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")
Expand All @@ -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 =
Expand All @@ -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

Expand All @@ -109,23 +109,23 @@ 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

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] =
Expand Down Expand Up @@ -167,15 +167,15 @@ 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)

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

Expand All @@ -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

Expand Down
1 change: 0 additions & 1 deletion src/windy/platforms/linux/x11/x.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

type
XID* = culong
Mask* = culong
Expand Down
18 changes: 9 additions & 9 deletions src/windy/platforms/win32/platform.nim
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ proc destroy(window: Window) =
window.onButtonRelease = nil
window.onRune = nil
window.onImeChange = nil

# Destroy graphics context
window.destoryGraphicsContext()

Expand Down Expand Up @@ -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
) =
Expand Down Expand Up @@ -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
) =
Expand Down Expand Up @@ -1231,7 +1231,7 @@ proc newWindow*(

result.style = style
result.visible = visible


except WindyError as e:
destroy result
Expand Down