-
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 1 commit
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/**************************************************************************/ | ||
/* */ | ||
/* Copyright 2022 OCamlPro */ | ||
/* */ | ||
/* All rights reserved. This file is distributed under the terms of the */ | ||
/* GNU Lesser General Public License version 2.1, with the special */ | ||
/* exception on linking described in the file LICENSE. */ | ||
/* */ | ||
/**************************************************************************/ | ||
|
||
#ifdef HAS_WAYLAND | ||
|
||
#include <stdlib.h> | ||
#include <stdint.h> | ||
#include <stdbool.h> | ||
#include <string.h> | ||
#include <assert.h> | ||
|
||
#include <errno.h> | ||
#include <time.h> | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
#include <wayland-client.h> | ||
#include <sys/mman.h> | ||
|
||
#include "wl_decoration.h" | ||
#include "wl_backend.h" | ||
#include "wl_backend_internal.h" | ||
|
||
|
||
|
||
//TODO : Factor this between surface and decoration | ||
static void | ||
_randname( | ||
char *buf) | ||
{ | ||
struct timespec ts; | ||
clock_gettime(CLOCK_REALTIME, &ts); | ||
long r = ts.tv_nsec; | ||
for (int i = 0; i < 6; ++i) { | ||
buf[i] = 'A'+(r&15)+(r&16)*2; | ||
r >>= 5; | ||
} | ||
} | ||
//TODO : Factor this between surface and decoration | ||
static int | ||
_create_shm_file() | ||
{ | ||
int retries = 100; | ||
do { | ||
char name[] = "/canvas_shm-XXXXXX"; | ||
_randname(name + sizeof(name) - 7); | ||
--retries; | ||
int fd = shm_open(name, O_CREAT | O_EXCL | O_RDWR | O_CLOEXEC, 0600); | ||
if (fd >= 0) { | ||
shm_unlink(name); | ||
return fd; | ||
} | ||
} while (retries > 0 && errno == EEXIST); | ||
return -1; | ||
} | ||
//TODO : Factor this between surface and decoration | ||
versionpatch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
static int | ||
_allocate_shm_file( | ||
size_t size) | ||
{ | ||
int fd = _create_shm_file(); | ||
if (fd < 0) | ||
return -1; | ||
int ret; | ||
do { | ||
ret = ftruncate(fd, size); | ||
} while (ret < 0 && errno == EINTR); | ||
if (ret < 0) { | ||
close(fd); | ||
return -1; | ||
} | ||
return fd; | ||
} | ||
|
||
|
||
|
||
wl_decoration_t* | ||
wl_decoration_create( | ||
struct wl_surface *parent, | ||
uint32_t width | ||
) | ||
{ | ||
|
||
//TODO : Make this adapt to screen | ||
uint32_t _decor_height = 40; | ||
|
||
assert(parent != NULL); | ||
wl_decoration_t *decor = (wl_decoration_t*)calloc(1, sizeof(wl_decoration_t)); | ||
if (decor == NULL) | ||
return NULL; | ||
decor->wl_surface = wl_compositor_create_surface(wl_back->compositor); | ||
decor->wl_subsurface = wl_subcompositor_get_subsurface(wl_back->subcompositor,decor->wl_surface,parent); | ||
|
||
//TODO : Factor this between surface and decoration | ||
uint32_t shm_pool_size = width * _decor_height * 4; | ||
int fd = _allocate_shm_file(shm_pool_size); | ||
uint8_t *pool_data = (uint8_t *)mmap(NULL, shm_pool_size, | ||
PROT_READ | PROT_WRITE, | ||
MAP_SHARED, fd, 0); | ||
|
||
struct wl_shm_pool *pool = wl_shm_create_pool(wl_back->shm, | ||
fd, shm_pool_size); | ||
close(fd); | ||
|
||
struct wl_buffer *wl_buffer = | ||
wl_shm_pool_create_buffer(pool, 0, width, _decor_height, width * 4, | ||
WL_SHM_FORMAT_ARGB8888); // or ARGB for alpha | ||
wl_shm_pool_destroy(pool); | ||
|
||
//TODO : Improve the design | ||
for (int i = 0;i < width*_decor_height;i++) | ||
{ | ||
pool_data[4*i] = 0; | ||
pool_data[4*i + 1] = 0; | ||
pool_data[4*i + 2] = 0; | ||
pool_data[4*i + 3] = 255; | ||
} | ||
|
||
munmap(pool_data,shm_pool_size); | ||
|
||
wl_surface_attach(decor->wl_surface,wl_buffer,0,0); | ||
wl_subsurface_set_position(decor->wl_subsurface,0,-_decor_height); | ||
decor->background_buffer = wl_buffer; | ||
|
||
return decor; | ||
} | ||
|
||
void | ||
wl_decoration_destroy( | ||
wl_decoration_t *decoration | ||
) | ||
{ | ||
assert(decoration != NULL); | ||
assert(decoration->background_buffer != NULL); | ||
assert(decoration->wl_subsurface != NULL); | ||
assert(decoration->wl_surface != NULL); | ||
|
||
wl_buffer_destroy(decoration->background_buffer); | ||
wl_subsurface_destroy(decoration->wl_subsurface); | ||
wl_surface_destroy(decoration->wl_surface); | ||
} | ||
|
||
void | ||
wl_decoration_present( | ||
wl_decoration_t* decoration | ||
) | ||
{ | ||
wl_surface_commit(decoration->wl_surface); | ||
} | ||
|
||
|
||
#endif /*HAS_WAYLAND*/ |
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,46 @@ | ||
/**************************************************************************/ | ||
/* */ | ||
/* Copyright 2022 OCamlPro */ | ||
/* */ | ||
/* All rights reserved. This file is distributed under the terms of the */ | ||
/* GNU Lesser General Public License version 2.1, with the special */ | ||
/* exception on linking described in the file LICENSE. */ | ||
/* */ | ||
/**************************************************************************/ | ||
|
||
#ifndef __WL_DECORATION_H | ||
#define __WL_DECORATION_H | ||
|
||
#include <stdint.h> | ||
#include <stdbool.h> | ||
#include <sys/mman.h> | ||
|
||
#include <wayland-client.h> | ||
|
||
#include "../color.h" | ||
|
||
typedef struct wl_decoration_t { | ||
struct wl_surface *wl_surface; | ||
struct wl_subsurface *wl_subsurface; | ||
struct wl_buffer *background_buffer; | ||
} wl_decoration_t; | ||
|
||
wl_decoration_t* | ||
wl_decoration_create( | ||
struct wl_surface *parent, | ||
uint32_t width | ||
); | ||
|
||
void | ||
wl_decoration_destroy( | ||
wl_decoration_t *decoration | ||
); | ||
|
||
void | ||
wl_decoration_present( | ||
wl_decoration_t* decoration | ||
); | ||
|
||
|
||
|
||
#endif /* __WL_DECORATION_H */ |
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
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.