-
Notifications
You must be signed in to change notification settings - Fork 8
[WIP] Wayland #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
[WIP] Wayland #31
Changes from 3 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
60cface
Snake and gradient examples
versionpatch 953d84a
Implemented wl_surface.c
versionpatch cdc804e
Wayland backend
versionpatch 10135a0
Made surface object store a pointer to the SHM object to avoid needin…
versionpatch 5282488
Wayland mouse and keyboard support.
versionpatch f45952f
Implemented window hiding. Fixed some formatting issues.
versionpatch 03eb44e
Simple client side decoration setup
versionpatch a0c474d
Decoration title rendering
versionpatch acd94b2
Refactored some parts common between surface and decoration
versionpatch 59c2556
Added close button
versionpatch 51eae1b
Resize WIP
versionpatch fe0ff2d
Fixed resize memory problems
versionpatch 3df780b
Decorations react to resize
versionpatch 627d783
Moved resize time from buffer release to before drawing
versionpatch 1ea160b
Allow disabling of decorations
versionpatch 2c642b9
Added resize direction checks
versionpatch 6c98065
Removed dependency on the decoration close button, a dummy buffer is …
versionpatch 0be4c71
Cursor changes in resize region
versionpatch 5c7906d
Backend stop, focus, middle mouse button
versionpatch 0d18603
Added XDG decoration protocol
versionpatch 7f08134
Added server side decorations
versionpatch 437ee62
Linking
versionpatch d5c879a
Server side decoration fixes
versionpatch 86f15be
Min Max buttons
versionpatch d14989a
Removed examples from wayland branch
versionpatch 9f80d01
Refactored surface destruction
versionpatch fd06b92
Added asserts and the HAS_WAYLAND conditional to xdg-decor-protocol
versionpatch 2fd0963
Modifiers + more fixes
versionpatch 6f39813
Refactored keyboard file
versionpatch b9ea6f3
Frameless window fix
versionpatch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
open OcamlCanvas | ||
open Float | ||
|
||
|
||
let interpInt x1 x2 t = | ||
int_of_float ((1. -. t)*.(float_of_int x1) +. t*.(float_of_int x2)) | ||
let interpColor c1 c2 t = | ||
let r1, g1, b1 = Color.to_rgb c1 and r2, g2, b2 = Color.to_rgb c2 in | ||
Color.of_rgb (interpInt r1 r2 t) (interpInt g1 g2 t) (interpInt b1 b2 t) | ||
let hsv_to_rgb h s v = | ||
let c = v *. s in | ||
let m = v -. c in | ||
let x = c *. (1. -. abs( ( (rem (h /. 60.) 2.) -. 1.))) in | ||
let r,g,b = match(h) with | ||
|a when a < 60. -> c,x,0. | ||
|a when a < 120. -> x,c,0. | ||
|a when a < 180. -> 0.,c,x | ||
|a when a < 240. -> 0.,x,c | ||
|a when a < 300. -> x,0.,c | ||
|_ -> c,0.,x | ||
in Color.of_rgb (int_of_float((r +. m)*.255.)) (int_of_float((g +. m)*.255.)) (int_of_float((b +. m)*.255.)) | ||
|
||
open Int64 | ||
|
||
let () = | ||
Backend.(init default_options); | ||
let c = Canvas.createFramed "test" ~pos:(960-640,540-360) ~size:(1280,720) in | ||
Canvas.setFillColor c Color.white; | ||
Canvas.fillRect c ~pos:(0.,0.) ~size:(1280.,720.); | ||
Canvas.show c; | ||
let r = ref (-1.) in | ||
Backend.run(function | ||
|Frame { canvas = c; timestamp = _ } -> | ||
r := !r +. 1. /. 60.; | ||
Canvas.setFillColor c (hsv_to_rgb (!r *. 36.) 1. 1.); | ||
Canvas.fillRect c ~pos:(128. *. !r,0.) ~size:(128., 360.); | ||
Canvas.setFillColor c (interpColor Color.black Color.white (!r *. 0.1)); | ||
Canvas.fillRect c ~pos:(128. *. !r,360.) ~size:(128., 360.); | ||
true; | ||
|_ -> | ||
false; | ||
)(function () -> | ||
Printf.printf "Goodbye !\n" | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
open OcamlCanvas | ||
open Int64 | ||
open Random | ||
|
||
let buildBackground c = | ||
Canvas.setFillColor c Color.black; | ||
Canvas.fillRect c ~pos:(0.,0.) ~size:(500.,500.); | ||
Canvas.setFillColor c Color.white; | ||
Canvas.fillRect c ~pos:(0.,0.) ~size:(500.,10.); | ||
Canvas.fillRect c ~pos:(0.,490.) ~size:(500.,10.); | ||
Canvas.fillRect c ~pos:(0.,0.) ~size:(10.,500.); | ||
Canvas.fillRect c ~pos:(490.,0.) ~size:(10.,500.); | ||
() | ||
|
||
let placeBlock c (x,y) col = | ||
Canvas.setFillColor c col; | ||
Canvas.fillRect c ~pos:(x *. 10. , y *. 10.) ~size:(10.,10.); | ||
() | ||
|
||
let rec drawSnake c s = match(s) with | ||
|[] -> () | ||
|h::t -> placeBlock c h Color.orange; drawSnake c t | ||
|
||
let rec moveSnake s p = match(s) with | ||
|[] -> [] | ||
|h::t -> p::(moveSnake t h) | ||
|
||
let sumCoord (a,b) (c,d) = (a +. c,b +. d) | ||
|
||
let moveSnakeDirection s d = match(s) with | ||
|[] -> [] | ||
|h::t -> moveSnake s (sumCoord d h) | ||
|
||
let snakeHitSelf s = match(s) with | ||
|[] -> false | ||
|h::t -> (List.mem h t) | ||
let snakeHitWall s = let h::t = s in let (x,y) = h in (x < 1.) or (x > 48.) or (y < 1.) or (y > 48.) | ||
|
||
|
||
let () = | ||
Random.self_init(); | ||
Backend.(init default_options); | ||
let c = Canvas.createFramed "test" ~pos:(960-250,540-250) ~size:(500,500) in | ||
Canvas.show c; | ||
let r = ref (-1.) in | ||
let snake = ref [(6.,8.);(6.,7.)] and currentDirection = ref (0.,1.) and foodLocation = ref(24.,24.) in | ||
Backend.run(function | ||
|KeyAction { canvas = c; timestamp = _; | ||
key = KeyUpArrow; char; flags = _; state = Down } -> | ||
let (x,y) = !currentDirection in | ||
if (y = 0.) then currentDirection := (0.,-1.); | ||
true; | ||
|KeyAction { canvas = c; timestamp = _; | ||
key = KeyDownArrow; char; flags = _; state = Down } -> | ||
let (x,y) = !currentDirection in | ||
if (y = 0.) then currentDirection := (0.,1.); | ||
true; | ||
|KeyAction { canvas = c; timestamp = _; | ||
key = KeyLeftArrow; char; flags = _; state = Down } -> | ||
let (x,y) = !currentDirection in | ||
if (x = 0.) then currentDirection := (-1.,0.); | ||
true; | ||
|KeyAction { canvas = c; timestamp = _; | ||
key = KeyRightArrow; char; flags = _; state = Down } -> | ||
let (x,y) = !currentDirection in | ||
if (x = 0.) then currentDirection := (1.,0.); | ||
true; | ||
|
||
|Frame { canvas = c; timestamp = _ } -> | ||
r := !r +. 1. /. 60.; | ||
buildBackground c; | ||
let h::t = !snake in | ||
if ((sumCoord h !currentDirection) = !foodLocation) then (snake := !foodLocation::!snake; foodLocation := (2. +. float_of_int (Random.int 47),2. +. float_of_int (Random.int 47))); | ||
if !r > 0.033 then (r := 0.; snake := moveSnakeDirection !snake !currentDirection); | ||
if (snakeHitSelf !snake or snakeHitWall !snake) then Backend.stop(); | ||
drawSnake c !snake; | ||
placeBlock c !foodLocation Color.green; | ||
true; | ||
|_ -> | ||
false; | ||
)(function () -> | ||
Printf.printf "Goodbye !\n" | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.