diff --git a/Makefile b/Makefile index eb74df8..16556a3 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,26 @@ -.PHONY: clean deps test check build +# The MIT License (MIT) + +# Copyright (c) 2016, 2017 Mikkel Oscar Lyderik Larsen + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +.PHONY: clean deps test check build init BINARY ?= flis VERSION ?= $(shell git describe --tags --always --dirty) @@ -7,22 +29,41 @@ GOPKGS = $(shell go list ./... | grep -v /vendor/) BUILD_FLAGS ?= -v LDFLAGS ?= -X main.version=$(VERSION) -w -s +NO_COLOR=\033[0m +OK_COLOR=\033[32;01m +ERROR_COLOR=\033[31;01m +WARN_COLOR=\033[33;01m + +MAKE_COLOR=\033[33;01m%-20s\033[0m + default: build +.PHONY: help +help: + @echo -e "$(OK_COLOR)==== $(BINARY) [$(VERSION)] ====$(NO_COLOR)" + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "$(MAKE_COLOR) : %s\n", $$1, $$2}' + +init: ## Install requirements + @echo -e "$(OK_COLOR)[$(BINARY)] Install requirements$(NO_COLOR)" + @go get -u github.com/golang/glog + @go get -u github.com/kardianos/govendor + @go get -u github.com/golang/lint/golint + @go get -u github.com/kisielk/errcheck + deps: go get -v -u -t ./... -clean: +clean: ## Cleanup rm -rf build -test: +test: ## Launch unit tests go test -v $(GOPKGS) -check: +check: ## Check go code golint ./... go vet -v $(GOPKGS) -build: build/$(BINARY) +build: build/$(BINARY) ## Build binary build/$(BINARY): $(SOURCES) go build -o build/$(BINARY) $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" . diff --git a/vendor/github.com/mikkeloscar/go-wlc/LICENSE b/vendor/github.com/mikkeloscar/go-wlc/LICENSE new file mode 100644 index 0000000..8841c02 --- /dev/null +++ b/vendor/github.com/mikkeloscar/go-wlc/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 Mikkel Oscar Lyderik Larsen + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/vendor/github.com/mikkeloscar/go-wlc/README.md b/vendor/github.com/mikkeloscar/go-wlc/README.md new file mode 100644 index 0000000..cdebe34 --- /dev/null +++ b/vendor/github.com/mikkeloscar/go-wlc/README.md @@ -0,0 +1,20 @@ +# go-wlc + +[![Go Report Card](https://goreportcard.com/badge/github.com/mikkeloscar/go-wlc)](https://goreportcard.com/report/github.com/mikkeloscar/go-wlc) +[![GoDoc](https://godoc.org/github.com/mikkeloscar/go-wlc?status.svg)](https://godoc.org/github.com/mikkeloscar/go-wlc) + +Go bindings for [wlc](http://github.com/Cloudef/wlc). + +## Example + +An example can be found in `example/example.go`. It is a port of the +[example](https://github.com/Cloudef/wlc/blob/master/example/example.c) +found in the wlc repo. Run it with: + +``` +$ go run example/example.go +``` + +## License + +See [LICENSE](LICENSE) file. diff --git a/vendor/github.com/mikkeloscar/go-wlc/core.c b/vendor/github.com/mikkeloscar/go-wlc/core.c new file mode 100644 index 0000000..9470d0b --- /dev/null +++ b/vendor/github.com/mikkeloscar/go-wlc/core.c @@ -0,0 +1,30 @@ +#include "_cgo_export.h" +#include +#include +#include + +void log_handler_cb(enum wlc_log_type type, const char *str) { + char *msg = strdup(str); + _goLogHandlerCb(type, msg); + free(msg); +} + +void wrap_wlc_log_set_handler() { + wlc_log_set_handler(log_handler_cb); +} + +int event_loop_fd_cb(int fd, uint32_t mask, void *arg) { + _goEventLoopFdCb(fd, mask); +} + +struct wlc_event_source *wrap_wlc_event_loop_add_fd(int fd, uint32_t mask) { + wlc_event_loop_add_fd(fd, mask, event_loop_fd_cb, NULL); +} + +int event_loop_timer_cb(void *arg) { + _goEventLoopTimerCb(*((uint32_t*)arg)); +} + +struct wlc_event_source *wrap_wlc_event_loop_add_timer(uint32_t id) { + wlc_event_loop_add_timer(event_loop_timer_cb, &id); +} diff --git a/vendor/github.com/mikkeloscar/go-wlc/core.go b/vendor/github.com/mikkeloscar/go-wlc/core.go new file mode 100644 index 0000000..761948e --- /dev/null +++ b/vendor/github.com/mikkeloscar/go-wlc/core.go @@ -0,0 +1,203 @@ +package wlc + +/* +#cgo LDFLAGS: -lwlc +#include +#include + +// handle wlc_log_set_handler callback. +extern void log_handler_cb(enum wlc_log_type type, const char *str); +extern void wrap_wlc_log_set_handler(); + +// handle wlc_event_loop_add_fd callback. +extern int event_loop_fd_cb(int fd, uint32_t mask, void *arg); +extern struct wlc_event_source *wrap_wlc_event_loop_add_fd(int fd, uint32_t mask); + +// handle wlc_event_loop_add_timer callback. +extern int event_loop_timer_cb(void *arg); +extern struct wlc_event_source *wrap_wlc_event_loop_add_timer(uint32_t id); + +// internal wlc_interface reference. +extern struct wlc_interface interface_wlc; +extern void init_interface(uint32_t mask); +*/ +import "C" + +import ( + "math/rand" + "time" + "unsafe" +) + +var logHandler func(LogType, string) + +//export _goLogHandlerCb +func _goLogHandlerCb(typ C.enum_wlc_log_type, msg *C.char) { + logHandler(LogType(typ), C.GoString(msg)) +} + +// LogSetHandler sets log handler. Can be set before Init. +func LogSetHandler(handler func(LogType, string)) { + logHandler = handler + C.wrap_wlc_log_set_handler() +} + +// Init initializeses wlc. Returns false on failure. +// +// Avoid running unverified code before Init as wlc compositor may be run +// with higher privileges on non logind systems where compositor binary needs +// to be suid. +// +// Init's purpose is to initialize and drop privileges as soon as possible. +func Init() bool { + return bool(C.wlc_init()) +} + +// Terminate wlc. +func Terminate() { + C.wlc_terminate() +} + +// GetBackendType queries for the backend wlc is using. +func GetBackendType() BackendType { + return BackendType(C.wlc_get_backend_type()) +} + +// Exec program. +func Exec(bin string, arg ...string) { + // prepend bin to start of args slice as expected by wlc. + args := append([]string{bin}, arg...) + cbin := C.CString(bin) + defer C.free(unsafe.Pointer(cbin)) + cargs := strSlicetoCArray(args) + defer freeCStrArray(cargs) + C.wlc_exec(cbin, cargs) +} + +// Run event loop. +func Run() { + C.wlc_run() +} + +// TODO make more go friendly + +// HandleSetUserData can be used to link custom data to handle. +// Client must allocate and handle the data as some C type. +func HandleSetUserData(handle View, userdata unsafe.Pointer) { + C.wlc_handle_set_user_data(C.wlc_handle(handle), userdata) +} + +// HandleGetUserData gets custom linked user data from handle. +func HandleGetUserData(handle View) unsafe.Pointer { + return C.wlc_handle_get_user_data(C.wlc_handle(handle)) +} + +type fdEvent struct { + cb func(int, uint32, interface{}) + arg interface{} + source EventSource +} + +var eventLoopFd = make(map[int]fdEvent) + +//export _goEventLoopFdCb +func _goEventLoopFdCb(fd C.int, mask C.uint32_t) { + if event, ok := eventLoopFd[int(fd)]; ok { + event.cb(int(fd), uint32(mask), event.arg) + } +} + +// EventLoopAddFd adds fd to event loop. +func EventLoopAddFd(fd int, mask uint32, cb func(int, uint32, interface{}), arg interface{}) EventSource { + source := EventSource(C.wrap_wlc_event_loop_add_fd( + C.int(fd), + C.uint32_t(mask), + )) + + if source != nil { + eventLoopFd[fd] = fdEvent{ + cb: cb, + arg: arg, + source: source, + } + } + + return source +} + +type timerEvent struct { + cb func(interface{}) + arg interface{} + source EventSource +} + +var eventLoopTimer = make(map[uint32]timerEvent) +var timerEventRand = rand.New(rand.NewSource(time.Now().UnixNano())) + +func timerEventID() uint32 { + newID := uint32(0) + for { + id := timerEventRand.Uint32() + if _, ok := eventLoopTimer[id]; !ok { + newID = id + break + } + } + + return newID +} + +//export _goEventLoopTimerCb +func _goEventLoopTimerCb(id C.int32_t) { + if event, ok := eventLoopTimer[uint32(id)]; ok { + event.cb(event.arg) + } +} + +// EventLoopAddTimer adds timer to event loop. +func EventLoopAddTimer(cb func(interface{}), arg interface{}) EventSource { + id := timerEventID() + + source := EventSource(C.wrap_wlc_event_loop_add_timer(C.uint32_t(id))) + + if source != nil { + eventLoopTimer[id] = timerEvent{ + cb: cb, + arg: arg, + source: source, + } + } + + return source +} + +// EventSourceTimerUpdate updates timer to trigger after delay. +// Returns true on success. +func EventSourceTimerUpdate(source EventSource, msDelay int32) bool { + return bool(C.wlc_event_source_timer_update( + source, + C.int32_t(msDelay), + )) +} + +// EventSourceRemove removes event source from event loop. +func EventSourceRemove(source EventSource) { + found := false + + for fd, event := range eventLoopFd { + if source == event.source { + found = true + delete(eventLoopFd, fd) + break + } + } + + if !found { + for id, event := range eventLoopFd { + if source == event.source { + delete(eventLoopFd, id) + } + } + } + C.wlc_event_source_remove(source) +} diff --git a/vendor/github.com/mikkeloscar/go-wlc/geometry.go b/vendor/github.com/mikkeloscar/go-wlc/geometry.go new file mode 100644 index 0000000..e7431da --- /dev/null +++ b/vendor/github.com/mikkeloscar/go-wlc/geometry.go @@ -0,0 +1,160 @@ +package wlc + +/* +#cgo LDFLAGS: -lwlc +#include + +struct wlc_point *init_point(int32_t x, int32_t y) { + struct wlc_point *point = malloc(sizeof(struct wlc_point)); + point->x = x; + point->y = y; + return point; +} + +struct wlc_size *init_size(uint32_t w, uint32_t h) { + struct wlc_size *size = malloc(sizeof(struct wlc_size)); + size->w = w; + size->h = h; + return size; +} + +struct wlc_geometry *init_geometry(int32_t x, int32_t y, uint32_t w, uint32_t h) { + struct wlc_geometry *geometry = malloc(sizeof(struct wlc_geometry)); + geometry->origin.x = x; + geometry->origin.y = y; + geometry->size.w = w; + geometry->size.h = h; + return geometry; +} +*/ +import "C" +import "math" + +// Point is a fixed 2D point. +type Point struct { + X, Y int32 +} + +func (p *Point) c() *C.struct_wlc_point { + return C.init_point(C.int32_t(p.X), C.int32_t(p.Y)) +} + +func pointCtoGo(c *C.struct_wlc_point) *Point { + if c != nil { + return &Point{ + X: int32((*c).x), + Y: int32((*c).y), + } + } + + return nil +} + +// Size is a fixed 2D size. +type Size struct { + W, H uint32 +} + +func (s *Size) c() *C.struct_wlc_size { + return C.init_size(C.uint32_t(s.W), C.uint32_t(s.H)) +} + +func sizeCtoGo(c *C.struct_wlc_size) *Size { + if c != nil { + return &Size{ + W: uint32((*c).w), + H: uint32((*c).h), + } + } + + return nil +} + +// Geometry is a fixed 2D point, size pair. +type Geometry struct { + Origin Point + Size Size +} + +func (g *Geometry) c() *C.struct_wlc_geometry { + return C.init_geometry( + C.int32_t(g.Origin.X), + C.int32_t(g.Origin.Y), + C.uint32_t(g.Size.W), + C.uint32_t(g.Size.H), + ) +} + +func geometryCtoGo(g *Geometry, c *C.struct_wlc_geometry) *Geometry { + if c != nil { + g.Origin = *pointCtoGo((*C.struct_wlc_point)(&(*c).origin)) + g.Size = *sizeCtoGo((*C.struct_wlc_size)(&(*c).size)) + return g + } + + return nil +} + +var ( + // PointZero defines a point at (0,0). + PointZero = Point{0, 0} + // SizeZero defines a size 0x0. + SizeZero = Size{0, 0} + // GeometryZero defines a geometry with size 0x0 at point (0,0). + GeometryZero = Geometry{Point{0, 0}, Size{0, 0}} +) + +// PointMin returns the smallest values of two points. +func PointMin(a, b Point) Point { + return Point{ + X: int32(math.Min(float64(a.X), float64(b.X))), + Y: int32(math.Min(float64(a.Y), float64(b.Y))), + } +} + +// PointMax returns the biggest values of two points. +func PointMax(a, b Point) Point { + return Point{ + X: int32(math.Max(float64(a.X), float64(b.X))), + Y: int32(math.Max(float64(a.Y), float64(b.Y))), + } +} + +// SizeMin returns the smallest values of two sizes. +func SizeMin(a, b Size) Size { + return Size{ + W: uint32(math.Min(float64(a.W), float64(b.W))), + H: uint32(math.Min(float64(a.H), float64(b.H))), + } +} + +// SizeMax returns the biggest values of two sizes. +func SizeMax(a, b Size) Size { + return Size{ + W: uint32(math.Max(float64(a.W), float64(b.W))), + H: uint32(math.Max(float64(a.H), float64(b.H))), + } +} + +// PointEquals compares two points. +func PointEquals(a, b Point) bool { + return a.X == b.X && a.Y == b.Y +} + +// SizeEquals compares two sizes. +func SizeEquals(a, b Size) bool { + return a.W == b.W && a.H == b.H +} + +// GeometryEquals compares two geometries. +func GeometryEquals(a, b Geometry) bool { + return PointEquals(a.Origin, b.Origin) && SizeEquals(a.Size, b.Size) +} + +// GeometryContains check if b is contained in a. +func GeometryContains(a, b Geometry) bool { + return a.Origin.X <= b.Origin.X && + a.Origin.Y <= b.Origin.Y && + a.Origin.X+int32(a.Size.W) >= b.Origin.X+int32(b.Size.W) && + a.Origin.Y+int32(a.Size.H) >= b.Origin.Y+int32(b.Size.H) +} diff --git a/vendor/github.com/mikkeloscar/go-wlc/input.go b/vendor/github.com/mikkeloscar/go-wlc/input.go new file mode 100644 index 0000000..ed82742 --- /dev/null +++ b/vendor/github.com/mikkeloscar/go-wlc/input.go @@ -0,0 +1,74 @@ +package wlc + +/* +#cgo LDFLAGS: -lwlc +#include +#include +*/ +import "C" + +import "unsafe" + +// KeyboardGetXKBState exposes xkb_state. Can be used for more advanced key +// handling. This is currently only exposed as a C struct. +func KeyboardGetXKBState() *C.struct_xkb_state { + return C.wlc_keyboard_get_xkb_state() +} + +// KeyboardGetXKBKeymap exposes xkb_keymap. Can be used for more advanced key +// handling. This is currently only exposed as a C struct. +func KeyboardGetXKBKeymap() *C.struct_xkb_keymap { + return C.wlc_keyboard_get_xkb_keymap() +} + +// KeyboardGetCurrentKeys gets currently held keys. +func KeyboardGetCurrentKeys() []uint32 { + var len C.size_t + keys := C.wlc_keyboard_get_current_keys(&len) + goKeys := make([]uint32, 0, int(len)) + size := int(unsafe.Sizeof(*keys)) + for i := 0; i < int(len); i++ { + ptr := unsafe.Pointer(uintptr(unsafe.Pointer(keys)) + uintptr(size*i)) + goKeys[i] = *(*uint32)(ptr) + } + + return goKeys +} + +// KeyboardGetKeysymForKey is an utility function to convert raw keycode to +// keysym. Passed modifiers may transform the key. +func KeyboardGetKeysymForKey(key uint32, mods *Modifiers) uint32 { + if mods != nil { + cmods := mods.c() + defer C.free(unsafe.Pointer(cmods)) + return uint32(C.wlc_keyboard_get_keysym_for_key(C.uint32_t(key), cmods)) + } + + return uint32(C.wlc_keyboard_get_keysym_for_key(C.uint32_t(key), nil)) +} + +// KeyboardGetUtf32ForKey is an utility function to convert raw keycode to +// Unicdoe/UTF-32 codepoint. Passed modifiers may transform the key. +func KeyboardGetUtf32ForKey(key uint32, mods *Modifiers) uint32 { + if mods != nil { + cmods := mods.c() + defer C.free(unsafe.Pointer(cmods)) + return uint32(C.wlc_keyboard_get_utf32_for_key(C.uint32_t(key), cmods)) + } + + return uint32(C.wlc_keyboard_get_utf32_for_key(C.uint32_t(key), nil)) +} + +// PointerGetPosition gets current pointer position. +func PointerGetPosition() *Point { + var pos C.struct_wlc_point + C.wlc_pointer_get_position(&pos) + return pointCtoGo(&pos) +} + +// PointerSetPosition sets pointer position. +func PointerSetPosition(pos Point) { + cpos := pos.c() + defer C.free(unsafe.Pointer(cpos)) + C.wlc_pointer_set_position(cpos) +} diff --git a/vendor/github.com/mikkeloscar/go-wlc/interface.c b/vendor/github.com/mikkeloscar/go-wlc/interface.c new file mode 100644 index 0000000..769300c --- /dev/null +++ b/vendor/github.com/mikkeloscar/go-wlc/interface.c @@ -0,0 +1,292 @@ +#include "_cgo_export.h" +#include + +/* output */ +bool handle_output_created(wlc_handle output) { + return _goHandleOutputCreated(output); +} + +void handle_output_destroyed(wlc_handle output) { + _goHandleOutputDestroyed(output); +} + +void handle_output_focus(wlc_handle output, bool focus) { + _goHandleOutputFocus(output, focus); +} + +void handle_output_resolution(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to) { + struct wlc_size nc_from = { + .w = from->w, + .h = from->h + }; + struct wlc_size nc_to = { + .w = to->w, + .h = to->h + }; + _goHandleOutputResolution(output, &nc_from, &nc_to); +} + +void handle_output_render_pre(wlc_handle output) { + _goHandleOutputRenderPre(output); +} + +void handle_output_render_post(wlc_handle output) { + _goHandleOutputRenderPost(output); +} + +void handle_output_context_created(wlc_handle output) { + _goHandleOutputContextCreated(output); +} + +void handle_output_context_destroyed(wlc_handle output) { + _goHandleOutputContextDestroyed(output); +} + + +/* view */ +bool handle_view_created(wlc_handle view) { + return _goHandleViewCreated(view); +} + +void handle_view_destroyed(wlc_handle view) { + _goHandleViewDestroyed(view); +} + +void handle_view_focus(wlc_handle view, bool focus) { + _goHandleViewFocus(view, focus); +} + +void handle_view_move_to_output(wlc_handle view, wlc_handle from_output, wlc_handle to_output) { + _goHandleViewMoveToOutput(view, from_output, to_output); +} + +void handle_view_request_geometry(wlc_handle view, const struct wlc_geometry *geometry) { + struct wlc_geometry nc_geometry = { + .origin = { + .x = geometry->origin.x, + .y = geometry->origin.y + }, + .size = { + .w = geometry->size.w, + .h = geometry->size.h + } + }; + _goHandleViewRequestGeometry(view, &nc_geometry); +} + +void handle_view_request_state(wlc_handle view, enum wlc_view_state_bit bit, bool toggle) { + _goHandleViewRequestState(view, bit, toggle); +} + +void handle_view_request_move(wlc_handle view, const struct wlc_point *point) { + struct wlc_point nc_point = { + .x = point->x, + .y = point->y + }; + _goHandleViewRequestMove(view, &nc_point); +} + +void handle_view_request_resize(wlc_handle view, uint32_t edges, const struct wlc_point *point) { + struct wlc_point nc_point = { + .x = point->x, + .y = point->y + }; + _goHandleViewRequestResize(view, edges, &nc_point); +} + +void handle_view_render_pre(wlc_handle view) { + _goHandleViewRenderPre(view); +} + +void handle_view_render_post(wlc_handle view) { + _goHandleViewRenderPost(view); +} + +void handle_view_properties_updated(wlc_handle view, uint32_t mask) { + _goHandleViewPropertiesUpdated(view, mask); +} + +/* keyboard */ +bool handle_keyboard_key(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, uint32_t key, enum wlc_key_state state) { + struct wlc_modifiers nc_modifiers = { + .leds = modifiers->leds, + .mods = modifiers->mods + }; + return _goHandleKeyboardKey(view, time, &nc_modifiers, key, state); +} + +/* pointer */ +bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, uint32_t button, enum wlc_button_state state, const struct wlc_point *point) { + struct wlc_modifiers nc_modifiers = { + .leds = modifiers->leds, + .mods = modifiers->mods + }; + struct wlc_point nc_point = { + .x = point->x, + .y = point->y + }; + return _goHandlePointerButton(view, time, &nc_modifiers, button, state, &nc_point); +} + +bool handle_pointer_scroll(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, uint8_t axis_bits, double amount[2]) { + struct wlc_modifiers nc_modifiers = { + .leds = modifiers->leds, + .mods = modifiers->mods + }; + return _goHandlePointerScroll(view, time, &nc_modifiers, axis_bits, amount); +} + +bool handle_pointer_motion(wlc_handle view, uint32_t time, const struct wlc_point *point) { + struct wlc_point nc_point = { + .x = point->x, + .y = point->y + }; + return _goHandlePointerMotion(view, time, &nc_point); +} + +/* touch */ +bool handle_touch_touch(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, enum wlc_touch_type touch, int32_t slot, const struct wlc_point *point) { + struct wlc_modifiers nc_modifiers = { + .leds = modifiers->leds, + .mods = modifiers->mods + }; + struct wlc_point nc_point = { + .x = point->x, + .y = point->y + }; + return _goHandleTouchTouch(view, time, &nc_modifiers, touch, slot, &nc_point); +} + +/* compositor */ +void handle_compositor_ready(void) { + _goHandleCompositorReady(); +} + +void handle_compositor_terminate(void) { + _goHandleCompositorTerminate(); +} + +/* input */ +bool handle_input_created(struct libinput_device *device) { + return _goHandleInputCreated(device); +} + +void handle_input_destroyed(struct libinput_device *device) { + _goHandleInputDestroyed(device); +} + + + +/* Callback wrappers */ + +void set_output_created_cb() { + wlc_set_output_created_cb(handle_output_created); +} + +void set_output_destroyed_cb() { + wlc_set_output_destroyed_cb(handle_output_destroyed); +} + +void set_output_focus_cb() { + wlc_set_output_focus_cb(handle_output_focus); +} + +void set_output_resolution_cb() { + wlc_set_output_resolution_cb(handle_output_resolution); +} + +void set_output_render_pre_cb() { + wlc_set_output_render_pre_cb(handle_output_render_pre); +} + +void set_output_render_post_cb() { + wlc_set_output_render_post_cb(handle_output_render_post); +} + +void set_output_context_created_cb() { + wlc_set_output_context_created_cb(handle_output_context_created); +} + +void set_output_context_destroyed_cb() { + wlc_set_output_context_destroyed_cb(handle_output_context_destroyed); +} + +void set_view_created_cb() { + wlc_set_view_created_cb(handle_view_created); +} + +void set_view_destroyed_cb() { + wlc_set_view_destroyed_cb(handle_view_destroyed); +} + +void set_view_focus_cb() { + wlc_set_view_focus_cb(handle_view_focus); +} + +void set_view_move_to_output_cb() { + wlc_set_view_move_to_output_cb(handle_view_move_to_output); +} + +void set_view_request_geometry_cb() { + wlc_set_view_request_geometry_cb(handle_view_request_geometry); +} + +void set_view_request_state_cb() { + wlc_set_view_request_state_cb(handle_view_request_state); +} + +void set_view_request_move_cb() { + wlc_set_view_request_move_cb(handle_view_request_move); +} + +void set_view_request_resize_cb() { + wlc_set_view_request_resize_cb(handle_view_request_resize); +} + +void set_view_render_pre_cb() { + wlc_set_view_render_pre_cb(handle_view_render_pre); +} + +void set_view_render_post_cb() { + wlc_set_view_render_post_cb(handle_view_render_post); +} + +void set_view_properties_updated_cb() { + wlc_set_view_properties_updated_cb(handle_view_properties_updated); +} + +void set_keyboard_key_cb() { + wlc_set_keyboard_key_cb(handle_keyboard_key); +} + +void set_pointer_button_cb() { + wlc_set_pointer_button_cb(handle_pointer_button); +} + +void set_pointer_scroll_cb() { + wlc_set_pointer_scroll_cb(handle_pointer_scroll); +} + +void set_pointer_motion_cb() { + wlc_set_pointer_motion_cb(handle_pointer_motion); +} + +void set_touch_cb() { + wlc_set_touch_cb(handle_touch_touch); +} + +void set_compositor_ready_cb() { + wlc_set_compositor_ready_cb(handle_compositor_ready); +} + +void set_compositor_terminate_cb() { + wlc_set_compositor_terminate_cb(handle_compositor_terminate); +} + +void set_input_created_cb() { + wlc_set_input_created_cb(handle_input_created); +} + +void set_input_destroyed_cb() { + wlc_set_input_destroyed_cb(handle_input_destroyed); +} diff --git a/vendor/github.com/mikkeloscar/go-wlc/interface.go b/vendor/github.com/mikkeloscar/go-wlc/interface.go new file mode 100644 index 0000000..9ed7b65 --- /dev/null +++ b/vendor/github.com/mikkeloscar/go-wlc/interface.go @@ -0,0 +1,515 @@ +package wlc + +/* +#cgo LDFLAGS: -lwlc +#include + +// output +extern bool handle_output_created(wlc_handle output); +extern void handle_output_destroyed(wlc_handle output); +extern void handle_output_focus(wlc_handle output, bool focus); +extern void handle_output_resolution(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to); +extern void handle_output_pre_render(wlc_handle output); +extern void handle_output_post_render(wlc_handle output); +extern void handle_output_context_created(wlc_handle output); +extern void handle_output_context_destroyed(wlc_handle output); +// view +extern bool handle_view_created(wlc_handle view); +extern void handle_view_destroyed(wlc_handle view); +extern void handle_view_focus(wlc_handle view, bool focus); +extern void handle_view_move_to_output(wlc_handle view, wlc_handle from_output, wlc_handle to_output); +extern void handle_view_geometry_request(wlc_handle view, const struct wlc_geometry*); +extern void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit, bool toggle); +extern void handle_view_move_request(wlc_handle view, const struct wlc_point*); +extern void handle_view_resize_request(wlc_handle view, uint32_t edges, const struct wlc_point*); +extern void handle_view_pre_render(wlc_handle view); +extern void handle_view_post_render(wlc_handle view); +extern void handle_view_properties_updated(wlc_handle view, uint32_t mask); +// keyboard +extern bool handle_keyboard_key(wlc_handle view, uint32_t time, const struct wlc_modifiers*, uint32_t key, enum wlc_key_state); +// pointer +extern bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers*, uint32_t button, enum wlc_button_state, const struct wlc_point*); +extern bool handle_pointer_scroll(wlc_handle view, uint32_t time, const struct wlc_modifiers*, uint8_t axis_bits, double amount[2]); +extern bool handle_pointer_motion(wlc_handle view, uint32_t time, const struct wlc_point*); +// touch +extern bool handle_touch_touch(wlc_handle view, uint32_t time, const struct wlc_modifiers*, enum wlc_touch_type, int32_t slot, const struct wlc_point*); +// compositor +extern void handle_compositor_ready(void); +extern void handle_compositor_terminate(void); +// input +extern bool handle_input_created(struct libinput_device *device); +extern void handle_input_destroyed(struct libinput_device *device); + +// callback wrappers +void set_output_created_cb(); +void set_output_destroyed_cb(); +void set_output_focus_cb(); +void set_output_resolution_cb(); +void set_output_render_pre_cb(); +void set_output_render_post_cb(); +void set_output_context_created_cb(); +void set_output_context_destroyed_cb(); +void set_view_created_cb(); +void set_view_destroyed_cb(); +void set_view_focus_cb(); +void set_view_move_to_output_cb(); +void set_view_request_geometry_cb(); +void set_view_request_state_cb(); +void set_view_request_move_cb(); +void set_view_request_resize_cb(); +void set_view_render_pre_cb(); +void set_view_render_post_cb(); +void set_view_properties_updated_cb(); +void set_keyboard_key_cb(); +void set_pointer_button_cb(); +void set_pointer_scroll_cb(); +void set_pointer_motion_cb(); +void set_touch_cb(); +void set_compositor_ready_cb(); +void set_compositor_terminate_cb(); +void set_input_created_cb(); +void set_input_destroyed_cb(); +*/ +import "C" +import "unsafe" + +var wlcInterface internalInterface + +// Interface is used for commication with wlc. +type internalInterface struct { + Output struct { + Created func(Output) bool + Destroyed func(Output) + Focus func(Output, bool) + Resolution func(Output, *Size, *Size) + Render struct { + Pre func(Output) + Post func(Output) + } + Context struct { + Created func(Output) + Destroyed func(Output) + } + } + View struct { + Created func(View) bool + Destroyed func(View) + Focus func(View, bool) + MoveToOutput func(View, Output, Output) + Request struct { + Geometry func(View, *Geometry) + State func(View, ViewStateBit, bool) + Move func(View, *Point) + Resize func(View, uint32, *Point) + } + Render struct { + Pre func(View) + Post func(View) + } + PropertiesUpdated func(View, ViewPropertyUpdateBit) + } + Keyboard struct { + Key func(View, uint32, Modifiers, uint32, KeyState) bool + } + Pointer struct { + Button func(View, uint32, Modifiers, uint32, ButtonState, *Point) bool + Scroll func(View, uint32, Modifiers, uint8, [2]float64) bool + Motion func(View, uint32, *Point) bool + } + Touch struct { + Touch func(View, uint32, Modifiers, TouchType, int32, *Point) bool + } + Compositor struct { + Ready func() + Terminate func() + } + Input struct { + Created func(*C.struct_libinput_device) bool + Destroyed func(*C.struct_libinput_device) + } +} + +// SetOutputCreatedCb sets callback to trigger when output is created. Callback +// should return false if you want to destroy the output. (e.g. failed to +// allocate data related to view) +func SetOutputCreatedCb(cb func(Output) bool) { + wlcInterface.Output.Created = cb + C.set_output_created_cb() +} + +// SetOutputDestroyedCb sets callback to trigger when output is destroyed. +func SetOutputDestroyedCb(cb func(Output)) { + wlcInterface.Output.Destroyed = cb + C.set_output_destroyed_cb() +} + +// SetOutputFocusCb sets callback to trigger when output got or lost focus. +func SetOutputFocusCb(fn func(Output, bool)) { + wlcInterface.Output.Focus = fn + C.set_output_focus_cb() +} + +// SetOutputResolutionCb sets callback to trigger when output resolution +// changed. +func SetOutputResolutionCb(cb func(Output, *Size, *Size)) { + wlcInterface.Output.Resolution = cb + C.set_output_resolution_cb() +} + +// SetOutputRenderPreCb sets the pre render hook for output. +func SetOutputRenderPreCb(cb func(Output)) { + wlcInterface.Output.Render.Pre = cb + C.set_output_render_pre_cb() +} + +// SetOutputRenderPostCb sets the post render hook for output. +func SetOutputRenderPostCb(cb func(Output)) { + wlcInterface.Output.Render.Post = cb + C.set_output_render_post_cb() +} + +// SetOutputContextCreated sets callback to trigger when output context is +// created. This generally happens on startup and when current tty changes. +func SetOutputContextCreated(cb func(Output)) { + wlcInterface.Output.Context.Created = cb + C.set_output_context_created_cb() +} + +// SetOutputContextDestroyed sets callback to trigger when output context is +// destroyed. +func SetOutputContextDestroyed(cb func(Output)) { + wlcInterface.Output.Context.Destroyed = cb + C.set_output_context_destroyed_cb() +} + +// SetViewCreatedCb sets callback to trigger when view is created. Callback +// should return false if you want to destroy the view. (e.g. failed to +// allocate data related to view). +func SetViewCreatedCb(cb func(View) bool) { + wlcInterface.View.Created = cb + C.set_view_created_cb() +} + +// SetViewDestroyedCb sets callback to trigger when view is destroyed. +func SetViewDestroyedCb(cb func(View)) { + wlcInterface.View.Destroyed = cb + C.set_view_destroyed_cb() +} + +// SetViewFocusCb sets callback to trigger when view got or lost focus. +func SetViewFocusCb(cb func(View, bool)) { + wlcInterface.View.Focus = cb + C.set_view_focus_cb() +} + +// SetViewMoveToOutputCb sets callback to trigger when view is moved to an +// output. +func SetViewMoveToOutputCb(cb func(View, Output, Output)) { + wlcInterface.View.MoveToOutput = cb + C.set_view_move_to_output_cb() +} + +// SetViewRequestGeometryCb sets callback to trigger when a view requests to +// set geometry. Apply using View.SetGeometry to agree. +func SetViewRequestGeometryCb(cb func(View, *Geometry)) { + wlcInterface.View.Request.Geometry = cb + C.set_view_request_geometry_cb() +} + +// SetViewRequestStateCb sets callback to trigger when a view requests to +// disable or enable the given state. Apply using View.SetState to agree. +func SetViewRequestStateCb(cb func(View, ViewStateBit, bool)) { + wlcInterface.View.Request.State = cb + C.set_view_request_state_cb() +} + +// SetViewRequestMoveCb sets callback to trigger when view requests to move +// itself. Start an interactive move to agree. +func SetViewRequestMoveCb(cb func(View, *Point)) { + wlcInterface.View.Request.Move = cb + C.set_view_request_move_cb() +} + +// SetViewRequestResizeCb sets callback to trigger when view requests to resize +// iteself with the given edge. Start an interactive resize to agree. +func SetViewRequestResizeCb(cb func(View, uint32, *Point)) { + wlcInterface.View.Request.Resize = cb + C.set_view_request_resize_cb() +} + +// SetViewRenderPreCb sets the pre render hook for view. +func SetViewRenderPreCb(cb func(View)) { + wlcInterface.View.Render.Pre = cb + C.set_view_render_pre_cb() +} + +// SetViewRenderPostCb sets the post render hook for view. +func SetViewRenderPostCb(cb func(View)) { + wlcInterface.View.Render.Post = cb + C.set_view_render_post_cb() +} + +// SetViewPropertiesUpdatedCb sets callback to trigger when view properties are +// updated. +func SetViewPropertiesUpdatedCb(cb func(View, ViewPropertyUpdateBit)) { + wlcInterface.View.PropertiesUpdated = cb + C.set_view_properties_updated_cb() +} + +// SetKeyboardKeyCb sets callback to trigger when key event was triggered, view +// handle will be zero if there was no focus. Callback can return true to +// prevent sending the event to clients. +func SetKeyboardKeyCb(cb func(View, uint32, Modifiers, uint32, KeyState) bool) { + wlcInterface.Keyboard.Key = cb + C.set_keyboard_key_cb() +} + +// SetPointerButtonCb sets callback to trigger when button event was triggered, +// view handle will be zero if there was no focus. Callback can return true +// to prevent sending the event to clients. +func SetPointerButtonCb(cb func(View, uint32, Modifiers, uint32, ButtonState, *Point) bool) { + wlcInterface.Pointer.Button = cb + C.set_pointer_button_cb() +} + +// SetPointerScrollCb sets callback to trigger when scroll event was triggered, +// view handle will be zero if there was no focus. Callback can return true +// to prevent sending the event to clients. +func SetPointerScrollCb(cb func(View, uint32, Modifiers, uint8, [2]float64) bool) { + wlcInterface.Pointer.Scroll = cb + C.set_pointer_scroll_cb() +} + +// SetPointerMotionCb sets callback to trigger when motion event was triggered, +// view handle will be zero if there was no focus. Apply with +// wlc_pointer_set_position to agree. Callback can return true to prevent +// sending the event to clients. +func SetPointerMotionCb(cb func(View, uint32, *Point) bool) { + wlcInterface.Pointer.Motion = cb + C.set_pointer_motion_cb() +} + +// SetTouchCb sets callback to trigger when touch event was triggered, view +// handle will be zero if there was no focus. Callback can return true to +// prevent sending the event to clients. +func SetTouchCb(cb func(View, uint32, Modifiers, TouchType, int32, *Point) bool) { + wlcInterface.Touch.Touch = cb + C.set_touch_cb() +} + +// SetCompositorReadyCb sets callback to trigger when compositor is ready to +// accept clients. +func SetCompositorReadyCb(cb func()) { + wlcInterface.Compositor.Ready = cb + C.set_compositor_ready_cb() +} + +// SetCompositorTerminateCb sets callback to trigger when compositor is about +// to terminate. +func SetCompositorTerminateCb(cb func()) { + wlcInterface.Compositor.Terminate = cb + C.set_compositor_terminate_cb() +} + +// SetInputCreatedCb sets callback to trigger when input device is created. +// Return value of callback does nothing. (Experimental). +func SetInputCreatedCb(cb func(*C.struct_libinput_device) bool) { + wlcInterface.Input.Created = cb + C.set_input_created_cb() +} + +// SetInputDestroyedCb sets callback to trigger when input device was +// destroyed. (Experimental). +func SetInputDestroyedCb(cb func(*C.struct_libinput_device)) { + wlcInterface.Input.Destroyed = cb + C.set_input_destroyed_cb() +} + +// output wrappers + +//export _goHandleOutputCreated +func _goHandleOutputCreated(output C.wlc_handle) C._Bool { + return C._Bool(wlcInterface.Output.Created(Output(output))) +} + +//export _goHandleOutputDestroyed +func _goHandleOutputDestroyed(output C.wlc_handle) { + wlcInterface.Output.Destroyed(Output(output)) +} + +//export _goHandleOutputFocus +func _goHandleOutputFocus(output C.wlc_handle, focus bool) { + wlcInterface.Output.Focus(Output(output), focus) +} + +//export _goHandleOutputResolution +func _goHandleOutputResolution(output C.wlc_handle, from *C.struct_wlc_size, to *C.struct_wlc_size) { + wlcInterface.Output.Resolution(Output(output), sizeCtoGo(from), sizeCtoGo(to)) +} + +//export _goHandleOutputRenderPre +func _goHandleOutputRenderPre(output C.wlc_handle) { + wlcInterface.Output.Render.Pre(Output(output)) +} + +//export _goHandleOutputRenderPost +func _goHandleOutputRenderPost(output C.wlc_handle) { + wlcInterface.Output.Render.Post(Output(output)) +} + +//export _goHandleOutputContextCreated +func _goHandleOutputContextCreated(output C.wlc_handle) { + wlcInterface.Output.Context.Created(Output(output)) +} + +//export _goHandleOutputContextDestroyed +func _goHandleOutputContextDestroyed(output C.wlc_handle) { + wlcInterface.Output.Context.Destroyed(Output(output)) +} + +// view wrappers + +//export _goHandleViewCreated +func _goHandleViewCreated(view C.wlc_handle) C._Bool { + return C._Bool(wlcInterface.View.Created(View(view))) +} + +//export _goHandleViewDestroyed +func _goHandleViewDestroyed(view C.wlc_handle) { + wlcInterface.View.Destroyed(View(view)) +} + +//export _goHandleViewFocus +func _goHandleViewFocus(view C.wlc_handle, focus bool) { + wlcInterface.View.Focus(View(view), focus) +} + +//export _goHandleViewMoveToOutput +func _goHandleViewMoveToOutput(view C.wlc_handle, fromOutput C.wlc_handle, toOutput C.wlc_handle) { + wlcInterface.View.MoveToOutput(View(view), Output(fromOutput), Output(toOutput)) +} + +//export _goHandleViewRequestGeometry +func _goHandleViewRequestGeometry(view C.wlc_handle, geometry *C.struct_wlc_geometry) { + wlcInterface.View.Request.Geometry(View(view), geometryCtoGo(&Geometry{}, geometry)) +} + +//export _goHandleViewRequestState +func _goHandleViewRequestState(view C.wlc_handle, state C.enum_wlc_view_state_bit, toggle bool) { + wlcInterface.View.Request.State(View(view), ViewStateBit(state), toggle) +} + +//export _goHandleViewRequestMove +func _goHandleViewRequestMove(view C.wlc_handle, point *C.struct_wlc_point) { + wlcInterface.View.Request.Move(View(view), pointCtoGo(point)) +} + +//export _goHandleViewRequestResize +func _goHandleViewRequestResize(view C.wlc_handle, edges C.uint32_t, point *C.struct_wlc_point) { + wlcInterface.View.Request.Resize(View(view), uint32(edges), pointCtoGo(point)) +} + +//export _goHandleViewRenderPre +func _goHandleViewRenderPre(view C.wlc_handle) { + wlcInterface.View.Render.Pre(View(view)) +} + +//export _goHandleViewRenderPost +func _goHandleViewRenderPost(view C.wlc_handle) { + wlcInterface.View.Render.Post(View(view)) +} + +//export _goHandleViewPropertiesUpdated +func _goHandleViewPropertiesUpdated(view C.wlc_handle, mask C.uint32_t) { + wlcInterface.View.PropertiesUpdated(View(view), ViewPropertyUpdateBit(mask)) +} + +// keyboard wrapper + +//export _goHandleKeyboardKey +func _goHandleKeyboardKey(view C.wlc_handle, time C.uint32_t, modifiers *C.struct_wlc_modifiers, key C.uint32_t, state C.enum_wlc_key_state) C._Bool { + return C._Bool(wlcInterface.Keyboard.Key( + View(view), + uint32(time), + modsCtoGo(modifiers), + uint32(key), + KeyState(state), + )) +} + +// pointer wrapper + +//export _goHandlePointerButton +func _goHandlePointerButton(view C.wlc_handle, time C.uint32_t, modifiers *C.struct_wlc_modifiers, button C.uint32_t, state C.enum_wlc_button_state, point *C.struct_wlc_point) C._Bool { + return C._Bool(wlcInterface.Pointer.Button( + View(view), + uint32(time), + modsCtoGo(modifiers), + uint32(button), + ButtonState(state), + pointCtoGo(point), + )) +} + +//export _goHandlePointerScroll +func _goHandlePointerScroll(view C.wlc_handle, time C.uint32_t, modifiers *C.struct_wlc_modifiers, axisBits C.uint8_t, amount *C.double) C._Bool { + // convert double[2] to [2]float64 + goAmount := [2]float64{ + *(*float64)(amount), + *(*float64)(unsafe.Pointer(uintptr(unsafe.Pointer(amount)) + unsafe.Sizeof(*amount))), + } + return C._Bool(wlcInterface.Pointer.Scroll( + View(view), + uint32(time), + modsCtoGo(modifiers), + uint8(axisBits), + goAmount, + )) +} + +//export _goHandlePointerMotion +func _goHandlePointerMotion(view C.wlc_handle, time C.uint32_t, point *C.struct_wlc_point) C._Bool { + return C._Bool(wlcInterface.Pointer.Motion( + View(view), + uint32(time), + pointCtoGo(point), + )) +} + +// touch wrapper + +//export _goHandleTouchTouch +func _goHandleTouchTouch(view C.wlc_handle, time C.uint32_t, modifiers *C.struct_wlc_modifiers, touch C.enum_wlc_touch_type, slot C.int32_t, point *C.struct_wlc_point) C._Bool { + return C._Bool(wlcInterface.Touch.Touch( + View(view), + uint32(time), + modsCtoGo(modifiers), + TouchType(touch), + int32(slot), + pointCtoGo(point), + )) +} + +// compositor wrapper + +//export _goHandleCompositorReady +func _goHandleCompositorReady() { + wlcInterface.Compositor.Ready() +} + +//export _goHandleCompositorTerminate +func _goHandleCompositorTerminate() { + wlcInterface.Compositor.Terminate() +} + +// input wrapper + +//export _goHandleInputCreated +func _goHandleInputCreated(device *C.struct_libinput_device) C._Bool { + return C._Bool(wlcInterface.Input.Created(device)) +} + +//export _goHandleInputDestroyed +func _goHandleInputDestroyed(device *C.struct_libinput_device) { + wlcInterface.Input.Destroyed(device) +} diff --git a/vendor/github.com/mikkeloscar/go-wlc/output.go b/vendor/github.com/mikkeloscar/go-wlc/output.go new file mode 100644 index 0000000..d540504 --- /dev/null +++ b/vendor/github.com/mikkeloscar/go-wlc/output.go @@ -0,0 +1,113 @@ +package wlc + +/* +#cgo LDFLAGS: -lwlc +#include +#include +*/ +import "C" + +import "unsafe" + +// Output is a wlc_handle describing an output object in wlc. +type Output C.wlc_handle + +// GetOutputs gets a list of outputs. +func GetOutputs() []Output { + var len C.size_t + handles := C.wlc_get_outputs(&len) + return outputHandlesCArraytoGoSlice(handles, int(len)) +} + +// GetFocusedOutput gets focused output. +func GetFocusedOutput() Output { + return Output(C.wlc_get_focused_output()) +} + +// Name gets output name. +func (o Output) Name() string { + cname := C.wlc_output_get_name(C.wlc_handle(o)) + return C.GoString(cname) +} + +// GetSleep gets output sleep state. +func (o Output) GetSleep() bool { + return bool(C.wlc_output_get_sleep(C.wlc_handle(o))) +} + +// SetSleep sets sleep status: wake up / sleep. +func (o Output) SetSleep(sleep bool) { + C.wlc_output_set_sleep(C.wlc_handle(o), C._Bool(sleep)) +} + +// GetResolution gets real output resolution applied by either +// wlc_output_set_resolution call or initially. +// Do not use this for coordinate boundary. +func (o Output) GetResolution() *Size { + csize := C.wlc_output_get_resolution(C.wlc_handle(o)) + return sizeCtoGo(csize) +} + +// GetVirtualResolution gets virtual output resolution with transformations +// applied for proper rendering for example on high density displays. +// Use this to figure out coordinate boundary. +func (o Output) GetVirtualResolution() *Size { + csize := C.wlc_output_get_virtual_resolution(C.wlc_handle(o)) + return sizeCtoGo(csize) +} + +// SetResolution sets output resolution. +func (o Output) SetResolution(resolution Size, scale uint32) { + csize := resolution.c() + defer C.free(unsafe.Pointer(csize)) + C.wlc_output_set_resolution(C.wlc_handle(o), csize, C.uint32_t(scale)) +} + +// GetScale returns scale factor. +func (o Output) GetScale() uint32 { + return uint32(C.wlc_output_get_scale(C.wlc_handle(o))) +} + +// GetMask gets current visibility bitmask. +func (o Output) GetMask() uint32 { + return uint32(C.wlc_output_get_mask(C.wlc_handle(o))) +} + +// SetMask sets visibility bitmask. +func (o Output) SetMask(mask uint32) { + C.wlc_output_set_mask(C.wlc_handle(o), C.uint32_t(mask)) +} + +// GetViews gets views in stack order. +func (o Output) GetViews() []View { + var len C.size_t + handles := C.wlc_output_get_views(C.wlc_handle(o), &len) + return viewHandlesCArraytoGoSlice(handles, int(len)) +} + +// GetMutableViews gets mutable views in creation order. +//This is mainly useful for wm's who need another view stack for inplace +//sorting. For example tiling wms, may want to use this to keep their tiling +//order separated from floating order. +func (o Output) GetMutableViews() []View { + var len C.size_t + handles := C.wlc_output_get_mutable_views(C.wlc_handle(o), &len) + return viewHandlesCArraytoGoSlice(handles, int(len)) +} + +// SetViews sets views in stack order. This will also change mutable +// views. Returns false on failure. +func (o Output) SetViews(views []View) bool { + cviews, len := viewHandlesSliceToCArray(views) + return bool(C.wlc_output_set_views(C.wlc_handle(o), cviews, len)) +} + +// Focus focuses output. +func (o Output) Focus() { + C.wlc_output_focus(C.wlc_handle(o)) +} + +// OutputUnfocus unfocuses all outputs. +func OutputUnfocus() { + C.wlc_output_focus(0) +} diff --git a/vendor/github.com/mikkeloscar/go-wlc/render.go b/vendor/github.com/mikkeloscar/go-wlc/render.go new file mode 100644 index 0000000..678c1ce --- /dev/null +++ b/vendor/github.com/mikkeloscar/go-wlc/render.go @@ -0,0 +1,117 @@ +package wlc + +/* +#cgo LDFLAGS: -lwlc +#include +#include +*/ +import "C" + +import ( + "fmt" + "unsafe" +) + +// PixelFormat describes the pixelformat used when writing/reading pixels. +type PixelFormat C.enum_wlc_pixel_format + +const ( + // RGBA8888 defines a color format where each channel is 8 bits. + RGBA8888 PixelFormat = iota +) + +// PixelsWrite write pixel data with the specific format to outputs +// framebuffer. If geometry is out of bounds, it will be automatically clamped. +// TODO: make more go friendly +func PixelsWrite(format PixelFormat, geometry Geometry, data unsafe.Pointer) { + cgeometry := geometry.c() + defer C.free(unsafe.Pointer(cgeometry)) + C.wlc_pixels_write(C.enum_wlc_pixel_format(format), cgeometry, data) +} + +// PixelsRead read pixel data from output's framebuffer. +// If the geometry is out of bounds, it will be automatically clamped. +// Potentially clamped geometry will be stored in out_geometry, to indicate +// width / height of the returned data. +// TODO: make more go friendly +func PixelsRead(format PixelFormat, geometry Geometry, outGeometry *Geometry, outData unsafe.Pointer) { + cgeometry := geometry.c() + defer C.free(unsafe.Pointer(cgeometry)) + var cgOut C.struct_wlc_geometry + C.wlc_pixels_read(C.enum_wlc_pixel_format(format), cgeometry, &cgOut, outData) + geometryCtoGo(outGeometry, &cgOut) +} + +// Render renders surfaces inside post / pre render hooks. +func (s Resource) Render(geometry Geometry) { + cgeometry := geometry.c() + defer C.free(unsafe.Pointer(cgeometry)) + C.wlc_surface_render(C.wlc_resource(s), cgeometry) +} + +// ScheduleRender schedules output for rendering next frame. +// If output was already scheduled this is no-op, if output is currently +// rendering, it will render immediately after. +func (o Output) ScheduleRender() { + C.wlc_output_schedule_render(C.wlc_handle(o)) +} + +// FlushFrameCallbacks adds frame callbacks of the given surface for the next +// output frame. It applies recursively to all subsurfaces. Useful when the +// compositor creates custom animations which require disabling internal +// rendering, but still need to update the surface textures (for ex. video +// players). +func (s Resource) FlushFrameCallbacks() { + C.wlc_surface_flush_frame_callbacks(C.wlc_resource(s)) +} + +// Renderer defines enabled renderers. +type Renderer C.enum_wlc_renderer + +const ( + // RendererGLES2 defines a GLES2 renderer. + RendererGLES2 Renderer = iota + // NoRenderer defines no renderer. + NoRenderer +) + +// GetRenderer returns currently active renderer on the given output. +func (o Output) GetRenderer() Renderer { + return Renderer(C.wlc_output_get_renderer(C.wlc_handle(o))) +} + +// SurfaceFormat defines the format returned by GetTextures. +type SurfaceFormat C.enum_wlc_surface_format + +const ( + // SurfaceRGB defines surface format RGB. + SurfaceRGB SurfaceFormat = iota + // SurfaceRGBA defines surface format RGBA. + SurfaceRGBA + // SurfaceEGL defines surface format EGL. + SurfaceEGL + // SurfaceYUv defines surface format yuv. + SurfaceYUv + // SurfaceYUV defines surface format YUV. + SurfaceYUV + // SurfaceYXUXV defines surface format YXUXV. + SurfaceYXUXV +) + +// GetTextures returns an array with the textures of a surface. Returns error +// if surface is invalid. Note that these are not only OpenGL textures but +// rather render-specific. +func (s Resource) GetTextures() ([3]uint32, SurfaceFormat, error) { + var outTextures [3]C.uint32_t + var format C.enum_wlc_surface_format + val := bool(C.wlc_surface_get_textures(C.wlc_resource(s), &outTextures[0], &format)) + if val { + var textures [3]uint32 + for i, t := range outTextures { + textures[i] = uint32(t) + } + return textures, SurfaceFormat(format), nil + } + + return [3]uint32{}, 0, fmt.Errorf("invalid surface") +} diff --git a/vendor/github.com/mikkeloscar/go-wlc/types.go b/vendor/github.com/mikkeloscar/go-wlc/types.go new file mode 100644 index 0000000..9aa8ebc --- /dev/null +++ b/vendor/github.com/mikkeloscar/go-wlc/types.go @@ -0,0 +1,188 @@ +package wlc + +/* +#cgo LDFLAGS: -lwlc +#include +*/ +import "C" + +// EventSource is a reference to struct wlc_event_source which is handled +// internally by wlc. +type EventSource *C.struct_wlc_event_source + +// type XKBState *C.struct_xkb_state +// type XKBKeymap *C.struct_xkb_keymap +// type InputDevice *C.struct_libinput_device + +type LogType C.enum_wlc_log_type + +const ( + LogInfo LogType = iota + LogWarn + LogError + LogWayland +) + +type BackendType C.enum_wlc_backend_type + +const ( + BackendNone BackendType = iota + BackendDrm + BackendX11 +) + +type EventBit C.enum_wlc_event_bit + +const ( + EventReadable EventBit = 0x01 + EventWriteable = 0x02 + EventHangup = 0x04 + EventError = 0x08 +) + +type ViewStateBit C.enum_wlc_view_state_bit + +const ( + BitMaximized ViewStateBit = 1 << 0 + BitFullscreen = 1 << 1 + BitResizing = 1 << 2 + BitMoving = 1 << 3 + BitActivated = 1 << 4 +) + +type ViewTypeBit C.enum_wlc_view_type_bit + +const ( + BitOverrideRedirect ViewTypeBit = 1 << 0 + BitUnmanaged = 1 << 1 + BitSplash = 1 << 2 + BitModal = 1 << 3 + BitPopup = 1 << 4 +) + +type ViewPropertyUpdateBit C.enum_wlc_view_property_update_bit + +const ( + PropertyTitle ViewPropertyUpdateBit = 1 << 0 + PropertyClass = 1 << 1 + PropertyAppID = 1 << 2 + PropertyPID = 1 << 3 +) + +type ResizeEdge C.enum_wlc_resize_edge + +const ( + ResizeEdgeNone ResizeEdge = 0 + ResizeEdgeTop = 1 + ResizeEdgeBottom = 2 + ResizeEdgeLeft = 4 + ResizeEdgeTopLeft = 5 + ResizeEdgeBottomLeft = 6 + ResizeEdgeRight = 8 + ResizeEdgeTopRight = 9 + ResizeEdgeBottomRight = 10 +) + +type ModifierBit C.enum_wlc_modifier_bit + +const ( + BitModShift ModifierBit = 1 << 0 + BitModCaps = 1 << 1 + BitModCtrl = 1 << 2 + BitModAlt = 1 << 3 + BitModMod2 = 1 << 4 + BitModMod3 = 1 << 5 + BitModLogo = 1 << 6 + BitModMod5 = 1 << 7 +) + +type LedBit C.enum_wlc_led_bit + +const ( + BitLedNum LedBit = 1 << 0 + BitLedCaps = 1 << 1 + BitLedScroll = 1 << 2 +) + +type KeyState C.enum_wlc_key_state + +const ( + KeyStateReleased KeyState = 0 + KeyStatePressed = 1 +) + +type ButtonState C.enum_wlc_button_state + +const ( + ButtonStateReleased = 0 + ButtonStatePressed = 1 +) + +type ScrollAxisBit C.enum_wlc_scroll_axis_bit + +const ( + ScrollAxisVertical ScrollAxisBit = 1 << 0 + ScrollAxisHorizontal = 1 << 1 +) + +type TouchType C.enum_wlc_touch_type + +const ( + TouchDown TouchType = iota + TouchUp + TouchMotion + TouchFrame + TouchCancel +) + +type PositionerAnchorBit C.enum_wlc_positioner_anchor_bit + +const ( + BitAnchorNone = 0 + BitAnchorTop = 1 << 0 + BitAnchorBottom = 1 << 1 + BitAnchorLeft = 1 << 2 + BitAnchorRight = 1 << 3 +) + +type PositionerGravityBit C.enum_wlc_positioner_gravity_bit + +const ( + BitGravityNone = 0 + BitGravityTop = 1 << 0 + BitGravityBottom = 1 << 1 + BitGravityLeft = 1 << 2 + BitGravityRight = 1 << 3 +) + +type PositionerConstraintAdjustmentBit C.enum_wlc_positioner_constraint_adjustment_bit + +const ( + BitConstraintAdjustmentNone = 0 + BitConstraintAdjustmentSlideX = 1 << 0 + BitConstraintAdjustmentSlideY = 1 << 1 + BitConstraintAdjustmentFlipX = 1 << 2 + BitConstraintAdjustmentFlipY = 1 << 3 + BitConstraintAdjustmentResizeX = 1 << 4 + BitConstraintAdjustmentResizeY = 1 << 5 +) + +// Modifiers describes the state of keyboard modifiers in various functions. +type Modifiers struct { + Leds uint32 + Mods uint32 +} + +func (m *Modifiers) c() *C.struct_wlc_modifiers { + return &C.struct_wlc_modifiers{ + leds: C.uint32_t(m.Leds), + mods: C.uint32_t(m.Mods), + } +} + +func modsCtoGo(c *C.struct_wlc_modifiers) Modifiers { + return Modifiers{ + Leds: uint32((*c).leds), + Mods: uint32((*c).mods), + } +} diff --git a/vendor/github.com/mikkeloscar/go-wlc/util.go b/vendor/github.com/mikkeloscar/go-wlc/util.go new file mode 100644 index 0000000..ba4ebaa --- /dev/null +++ b/vendor/github.com/mikkeloscar/go-wlc/util.go @@ -0,0 +1,89 @@ +package wlc + +/* +#cgo LDFLAGS: -lwlc +#include +#include + +char **char_array_init(size_t len) { + char **arr = malloc(len * sizeof(char*)); + return arr; +} + +void char_array_insert(char **arr, char *item, int index) { + arr[index] = item; +} + +void char_array_free(char **arr) { + int i = 0; + for (char **ptr = arr; *ptr; ++ptr) { + free(*ptr); + } + free(arr); +} + +wlc_handle *handle_array_init(size_t len) { + wlc_handle *arr = malloc(len * sizeof(wlc_handle)); + return arr; +} + +void handle_array_insert(wlc_handle *arr, wlc_handle item, int index) { + arr[index] = item; +} +*/ +import "C" + +import "unsafe" + +type handleType uint8 + +const ( + viewHandle handleType = iota + outputHandle +) + +// Initialize a C NULL terminated *char[] from a []string +func strSlicetoCArray(arr []string) **C.char { + carr := C.char_array_init(C.size_t(len(arr) + 1)) + for i, s := range arr { + C.char_array_insert(carr, C.CString(s), C.int(i)) + } + C.char_array_insert(carr, nil, C.int(len(arr))) + return carr +} + +// Free a *char[] +func freeCStrArray(arr **C.char) { + C.char_array_free(arr) +} + +func outputHandlesCArraytoGoSlice(handles *C.wlc_handle, len int) []Output { + goHandles := make([]Output, len) + size := int(unsafe.Sizeof(*handles)) + for i := 0; i < len; i++ { + ptr := unsafe.Pointer(uintptr(unsafe.Pointer(handles)) + uintptr(size*i)) + goHandles[i] = *(*Output)(ptr) + } + + return goHandles +} + +func viewHandlesCArraytoGoSlice(handles *C.wlc_handle, len int) []View { + goHandles := make([]View, len) + size := int(unsafe.Sizeof(*handles)) + for i := 0; i < len; i++ { + ptr := unsafe.Pointer(uintptr(unsafe.Pointer(handles)) + uintptr(size*i)) + goHandles[i] = *(*View)(ptr) + } + + return goHandles +} + +func viewHandlesSliceToCArray(arr []View) (*C.wlc_handle, C.size_t) { + carr := C.handle_array_init(C.size_t(len(arr))) + for i, h := range arr { + C.handle_array_insert(carr, C.wlc_handle(h), C.int(i)) + } + + return carr, C.size_t(len(arr)) +} diff --git a/vendor/github.com/mikkeloscar/go-wlc/view.go b/vendor/github.com/mikkeloscar/go-wlc/view.go new file mode 100644 index 0000000..3b5eb99 --- /dev/null +++ b/vendor/github.com/mikkeloscar/go-wlc/view.go @@ -0,0 +1,198 @@ +package wlc + +/* +#cgo LDFLAGS: -lwlc +#include +#include +*/ +import "C" + +import "unsafe" + +// View is a wlc_handle describing a view object in wlc. +type View C.wlc_handle + +// Focus focuses view. +func (v View) Focus() { + C.wlc_view_focus(C.wlc_handle(v)) +} + +// ViewUnfocus unfocuses all views. +func ViewUnfocus() { + C.wlc_view_focus(0) +} + +// Close closes view. +func (v View) Close() { + C.wlc_view_close(C.wlc_handle(v)) +} + +// GetOutput gets output of view. +func (v View) GetOutput() Output { + return Output(C.wlc_view_get_output(C.wlc_handle(v))) +} + +// SetOutput sets output for view. Alternatively output.SetViews() can be used. +func (v View) SetOutput(output Output) { + C.wlc_view_set_output(C.wlc_handle(v), C.wlc_handle(output)) +} + +// SendToBack sends view behind everything. +func (v View) SendToBack() { + C.wlc_view_send_to_back(C.wlc_handle(v)) +} + +// SendBelow sends view below another view. +func (v View) SendBelow(other View) { + C.wlc_view_send_below(C.wlc_handle(v), C.wlc_handle(other)) +} + +// BringAbove brings view above another view. +func (v View) BringAbove(other View) { + C.wlc_view_bring_above(C.wlc_handle(v), C.wlc_handle(other)) +} + +// BringToFront brings view to front of everything. +func (v View) BringToFront() { + C.wlc_view_bring_to_front(C.wlc_handle(v)) +} + +// GetMask gets current visibility bitmask. +func (v View) GetMask() uint32 { + return uint32(C.wlc_view_get_mask(C.wlc_handle(v))) +} + +// SetMask sets visibility bitmask. +func (v View) SetMask(mask uint32) { + C.wlc_view_set_mask(C.wlc_handle(v), C.uint32_t(mask)) +} + +// GetGeometry gets current geometry (what the client sees). +func (v View) GetGeometry() *Geometry { + cgeometry := C.wlc_view_get_geometry(C.wlc_handle(v)) + return geometryCtoGo(&Geometry{}, cgeometry) +} + +// PositionerGetSize gets size requested by positioner, as defined in xdg-shell +// v6. +func (v View) PositionerGetSize() *Size { + csize := C.wlc_view_positioner_get_size(C.wlc_handle(v)) + return sizeCtoGo(csize) +} + +// PositionerGetAnchorRect gets anchor rectangle requested by positioner, as +// defined in xdg-shell v6. +// Returns nil if view has no valid positioner. +func (v View) PositionerGetAnchorRect() *Geometry { + cgeometry := C.wlc_view_positioner_get_anchor_rect(C.wlc_handle(v)) + return geometryCtoGo(&Geometry{}, cgeometry) +} + +// PositionerGetOffset gets offset requested by positioner, as defined in +// xdg-shell v6. +// Returns NULL if view has no valid positioner, or default value (0, 0) if +// positioner has no offset set. +func (v View) PositionerGetOffset() *Point { + cpoint := C.wlc_view_positioner_get_offset(C.wlc_handle(v)) + return pointCtoGo(cpoint) +} + +// PositionerGetAnchor gets anchor requested by positioner, as defined in +// xdg-shell v6. +// Returns default value WLC_BIT_ANCHOR_NONE if view has no valid positioner or +// if positioner has no anchor set. +func (v View) PositionerGetAnchor() PositionerAnchorBit { + return PositionerAnchorBit(C.wlc_view_positioner_get_anchor(C.wlc_handle(v))) +} + +// PositionerGetGravity gets anchor requested by positioner, as defined in +// xdg-shell v6. +// Returns default value WLC_BIT_GRAVITY_NONE if view has no valid positioner +// or if positioner has no gravity set. +func (v View) PositionerGetGravity() PositionerGravityBit { + return PositionerGravityBit(C.wlc_view_positioner_get_gravity(C.wlc_handle(v))) +} + +// PositionerGetConstraintAdjustment gets constraint adjustment requested by +// positioner, as defined in xdg-shell v6. +// Returns default value WLC_BIT_CONSTRAINT_ADJUSTMENT_NONE if view has no +// valid positioner or if positioner has no constraint adjustment set. +func (v View) PositionerGetConstraintAdjustment() PositionerConstraintAdjustmentBit { + return PositionerConstraintAdjustmentBit( + C.wlc_view_positioner_get_constraint_adjustment(C.wlc_handle(v)), + ) +} + +// GetVisibleGeometry gets current visible geometry (what wlc displays). +func (v View) GetVisibleGeometry() Geometry { + cgeometry := C.struct_wlc_geometry{} + C.wlc_view_get_visible_geometry(C.wlc_handle(v), &cgeometry) + return *geometryCtoGo(&Geometry{}, &cgeometry) +} + +// SetGeometry sets geometry. Set edges if the geometry change is caused by +// interactive resize. +func (v View) SetGeometry(edges uint32, geometry Geometry) { + cgeometry := geometry.c() + defer C.free(unsafe.Pointer(cgeometry)) + C.wlc_view_set_geometry(C.wlc_handle(v), C.uint32_t(edges), cgeometry) +} + +// GetType gets type bitfield for view. +func (v View) GetType() uint32 { + return uint32(C.wlc_view_get_type(C.wlc_handle(v))) +} + +// SetType sets type bit. TOggle indicates whether it is set or not. +func (v View) SetType(typ ViewTypeBit, toggle bool) { + C.wlc_view_set_type(C.wlc_handle(v), uint32(typ), C._Bool(toggle)) +} + +// GetState gets current state bitfield. +func (v View) GetState() uint32 { + return uint32(C.wlc_view_get_state(C.wlc_handle(v))) +} + +// SetState sets state bit. Toggle indicates whether it is set or not. +func (v View) SetState(state ViewStateBit, toggle bool) { + C.wlc_view_set_state(C.wlc_handle(v), uint32(state), C._Bool(toggle)) +} + +// GetParent gets parent view. +func (v View) GetParent() View { + return View(C.wlc_view_get_parent(C.wlc_handle(v))) +} + +// SetParent sets parent view. +func (v View) SetParent(parent View) { + C.wlc_view_set_parent(C.wlc_handle(v), C.wlc_handle(parent)) +} + +// Title gets title. +func (v View) Title() string { + ctitle := C.wlc_view_get_title(C.wlc_handle(v)) + return C.GoString(ctitle) +} + +// Instance gets instance (shell-surface only). +func (v View) Instance() string { + cinstance := C.wlc_view_get_instance(C.wlc_handle(v)) + return C.GoString(cinstance) +} + +// GetClass gets class. (shell-surface only). +func (v View) GetClass() string { + cclass := C.wlc_view_get_class(C.wlc_handle(v)) + return C.GoString(cclass) +} + +// GetAppID gets app id. (xdg-surface only). +func (v View) GetAppID() string { + capp := C.wlc_view_get_app_id(C.wlc_handle(v)) + return C.GoString(capp) +} + +// GetPID gets pid of program owning the view. +func (v View) GetPID() int { + return int(C.wlc_view_get_pid(C.wlc_handle(v))) +} diff --git a/vendor/github.com/mikkeloscar/go-wlc/wayland.go b/vendor/github.com/mikkeloscar/go-wlc/wayland.go new file mode 100644 index 0000000..396559e --- /dev/null +++ b/vendor/github.com/mikkeloscar/go-wlc/wayland.go @@ -0,0 +1,98 @@ +package wlc + +/* +#cgo LDFLAGS: -lwlc +#include +#include +*/ +import "C" + +import "unsafe" + +// Resource is a wlc resource. +type Resource C.wlc_resource + +// GetWLDisplay returns wayland display. +func GetWLDisplay() *C.struct_wl_display { + return C.wlc_get_wl_display() +} + +// HandleFromWLSurface returns view handle from wl_surface resource. +func HandleFromWLSurface(resource *C.struct_wl_resource) View { + return View(C.wlc_handle_from_wl_surface_resource(resource)) +} + +// HandleFromWLOutputResource returns output handle from wl_output resource. +func HandleFromWLOutputResource(resource *C.struct_wl_resource) Output { + return Output(C.wlc_handle_from_wl_output_resource(resource)) +} + +// HandleFromWLSurfaceResource returns internal wlc surface from wl_surface +// resource. +func HandleFromWLSurfaceResource(resource *C.struct_wl_resource) Resource { + return Resource(C.wlc_handle_from_wl_surface_resource(resource)) +} + +// SurfaceGetSize gets surface size. +func SurfaceGetSize(surface Resource) *Size { + csize := C.wlc_surface_get_size(C.wlc_resource(surface)) + return sizeCtoGo(csize) +} + +// SurfaceGetWLResource returns wl_surface resource from internal wlc surface. +func SurfaceGetWLResource(surface Resource) *C.struct_wl_resource { + return C.wlc_surface_get_wl_resource(C.wlc_resource(surface)) +} + +// ViewFromSurface turns wl_surface into a wlc view. Returns 0 on failure. +// This will also trigger view.created callback as any view would. +func ViewFromSurface(surface Resource, client *C.struct_wl_client, interf *C.struct_wl_interface, implementation unsafe.Pointer, version, id uint32, userdata unsafe.Pointer) View { + return View( + C.wlc_view_from_surface( + C.wlc_resource(surface), + client, + interf, + implementation, + C.uint32_t(version), + C.uint32_t(id), + userdata, + )) +} + +// GetSurface returns internal wlc surface from view handle. +func (v View) GetSurface() Resource { + return Resource(C.wlc_view_get_surface(C.wlc_handle(v))) +} + +// GetSubsurfaces returns a list of subsurfaces for a surface. +func (s Resource) GetSubsurfaces() []Resource { + var len C.size_t + resouces := C.wlc_surface_get_subsurfaces(C.wlc_resource(s), &len) + subsurfaces := make([]Resource, int(len)) + size := int(unsafe.Sizeof(*resouces)) + for i := 0; i < int(len); i++ { + ptr := unsafe.Pointer(uintptr(unsafe.Pointer(resouces)) + uintptr(size*i)) + subsurfaces[i] = *(*Resource)(ptr) + } + return subsurfaces +} + +// GetSubsurfaceGeometry returns the size of a subsurface and its position +// relative to parent surface. +func (s Resource) GetSubsurfaceGeometry() Geometry { + cgeometry := C.struct_wlc_geometry{} + C.wlc_get_subsurface_geometry(C.wlc_resource(s), &cgeometry) + return *geometryCtoGo(&Geometry{}, &cgeometry) +} + +// GetWlClient returns wlc_client from view. +func (v View) GetWlClient() *C.struct_wl_client { + return C.wlc_view_get_wl_client(C.wlc_handle(v)) +} + +// GetRole returns surface role resource from view handle. Return value +// will be nil if the view was not assigned role or created with +// ViewCreateFromSurface(). +func (v View) GetRole() *C.struct_wl_resource { + return C.wlc_view_get_role(C.wlc_handle(v)) +} diff --git a/vendor/github.com/mikkeloscar/go-xkbcommon/README.md b/vendor/github.com/mikkeloscar/go-xkbcommon/README.md new file mode 100644 index 0000000..b74f776 --- /dev/null +++ b/vendor/github.com/mikkeloscar/go-xkbcommon/README.md @@ -0,0 +1,5 @@ +[![GoDoc](https://godoc.org/github.com/mikkeloscar/go-xkbcommon?status.svg)](https://godoc.org/github.com/mikkeloscar/go-xkbcommon) + +# go-xkbcommon + +WIP Go bindings for [libxkbcommon](http://github.com/xkbcommon/libxkbcommon). diff --git a/vendor/github.com/mikkeloscar/go-xkbcommon/xkbcommon.go b/vendor/github.com/mikkeloscar/go-xkbcommon/xkbcommon.go new file mode 100644 index 0000000..1b57097 --- /dev/null +++ b/vendor/github.com/mikkeloscar/go-xkbcommon/xkbcommon.go @@ -0,0 +1,24 @@ +package xkb + +/* +#cgo LDFLAGS: -lxkbcommon +#include +#include +*/ +import "C" +import "unsafe" + +type KeySym C.xkb_keysym_t + +type KeySymFlags C.enum_xkb_keysym_flags + +const ( + KeySymNoFlags KeySymFlags = 0 + KeySymCaseInsensitive = (1 << 0) +) + +func KeySymFromName(name string, flags KeySymFlags) KeySym { + cname := C.CString(name) + defer C.free(unsafe.Pointer(cname)) + return KeySym(C.xkb_keysym_from_name(cname, C.enum_xkb_keysym_flags(flags))) +} diff --git a/vendor/github.com/mikkeloscar/go-xkbcommon/xkbcommon_keysyms.go b/vendor/github.com/mikkeloscar/go-xkbcommon/xkbcommon_keysyms.go new file mode 100644 index 0000000..4c08f70 --- /dev/null +++ b/vendor/github.com/mikkeloscar/go-xkbcommon/xkbcommon_keysyms.go @@ -0,0 +1,132 @@ +package xkb + +const ( + KeyNoSymbol = 0x000000 + + KeyVoidSymbol = 0xffffff + + KeyBackSpace = 0xff08 + KeyTab = 0xff09 + KeyLinefeed = 0xff0a + KeyClear = 0xff0b + KeyReturn = 0xff0d + KeyPause = 0xff13 + KeyScroll_Lock = 0xff14 + KeySys_Req = 0xff15 + KeyEscape = 0xff1b + KeyDelete = 0xffff + + // Cursor control & motion + KeyHome = 0xff50 + KeyLeft = 0xff51 + KeyUp = 0xff52 + KeyRight = 0xff53 + KeyDown = 0xff54 + KeyPrior = 0xff55 + KeyPageUp = 0xff55 + KeyNext = 0xff56 + KeyPageDown = 0xff56 + KeyEnd = 0xff57 + KeyBegin = 0xff58 + + // Latin 1 + // (ISO/IEC 8859-1 = Unicode U+0020..U+00FF) + // Byte 3 = 0 + Keyspace = 0x0020 + Keyexclam = 0x0021 + Keyquotedbl = 0x0022 + Keynumbersign = 0x0023 + Keydollar = 0x0024 + Keypercent = 0x0025 + Keyampersand = 0x0026 + Keyapostrophe = 0x0027 + Keyquoteright = 0x0027 + Keyparenleft = 0x0028 + Keyparenright = 0x0029 + Keyasterisk = 0x002a + Keyplus = 0x002b + Keycomma = 0x002c + Keyminus = 0x002d + Keyperiod = 0x002e + Keyslash = 0x002f + Key0 = 0x0030 + Key1 = 0x0031 + Key2 = 0x0032 + Key3 = 0x0033 + Key4 = 0x0034 + Key5 = 0x0035 + Key6 = 0x0036 + Key7 = 0x0037 + Key8 = 0x0038 + Key9 = 0x0039 + Keycolon = 0x003a + Keysemicolon = 0x003b + Keyless = 0x003c + Keyequal = 0x003d + Keygreater = 0x003e + Keyquestion = 0x003f + Keyat = 0x0040 + KeyA = 0x0041 + KeyB = 0x0042 + KeyC = 0x0043 + KeyD = 0x0044 + KeyE = 0x0045 + KeyF = 0x0046 + KeyG = 0x0047 + KeyH = 0x0048 + KeyI = 0x0049 + KeyJ = 0x004a + KeyK = 0x004b + KeyL = 0x004c + KeyM = 0x004d + KeyN = 0x004e + KeyO = 0x004f + KeyP = 0x0050 + KeyQ = 0x0051 + KeyR = 0x0052 + KeyS = 0x0053 + KeyT = 0x0054 + KeyU = 0x0055 + KeyV = 0x0056 + KeyW = 0x0057 + KeyX = 0x0058 + KeyY = 0x0059 + KeyZ = 0x005a + Keybracketleft = 0x005b + Keybackslash = 0x005c + Keybracketright = 0x005d + Keyasciicircum = 0x005e + Keyunderscore = 0x005f + Keygrave = 0x0060 + Keyquoteleft = 0x0060 + Keya = 0x0061 + Keyb = 0x0062 + Keyc = 0x0063 + Keyd = 0x0064 + Keye = 0x0065 + Keyf = 0x0066 + Keyg = 0x0067 + Keyh = 0x0068 + Keyi = 0x0069 + Keyj = 0x006a + Keyk = 0x006b + Keyl = 0x006c + Keym = 0x006d + Keyn = 0x006e + Keyo = 0x006f + Keyp = 0x0070 + Keyq = 0x0071 + Keyr = 0x0072 + Keys = 0x0073 + Keyt = 0x0074 + Keyu = 0x0075 + Keyv = 0x0076 + Keyw = 0x0077 + Keyx = 0x0078 + Keyy = 0x0079 + Keyz = 0x007a + Keybraceleft = 0x007b + Keybar = 0x007c + Keybraceright = 0x007d + Keyasciitilde = 0x007e +) diff --git a/vendor/github.com/mikkeloscar/go-xkbcommon/xkbcommon_names.go b/vendor/github.com/mikkeloscar/go-xkbcommon/xkbcommon_names.go new file mode 100644 index 0000000..1409952 --- /dev/null +++ b/vendor/github.com/mikkeloscar/go-xkbcommon/xkbcommon_names.go @@ -0,0 +1,14 @@ +package xkb + +const ( + ModNameShift = "Shift" + ModNameCaps = "Lock" + ModNameCtrl = "Control" + ModNameAlt = "Mod1" + ModNameNum = "Mod2" + ModNameLogo = "Mod4" + + LedNameCaps = "Caps Lock" + LedNameNum = "Num Lock" + LedNameScroll = "Scroll Lock" +) diff --git a/vendor/vendor.json b/vendor/vendor.json new file mode 100644 index 0000000..1979e37 --- /dev/null +++ b/vendor/vendor.json @@ -0,0 +1,43 @@ +{ + "comment": "", + "ignore": "test", + "package": [ + { + "checksumSHA1": "9OSfmTckSjD1No3iVWMjL4qI+AQ=", + "path": "github.com/alecthomas/kingpin", + "revision": "7b7c3e10c746bb718299261d2093286e5e38e04c", + "revisionTime": "2017-01-03T22:55:01Z" + }, + { + "checksumSHA1": "KmjnydoAbofMieIWm+it5OWERaM=", + "path": "github.com/alecthomas/template", + "revision": "a0175ee3bccc567396460bf5acd36800cb10c49c", + "revisionTime": "2016-04-05T07:15:01Z" + }, + { + "checksumSHA1": "3wt0pTXXeS+S93unwhGoLIyGX/Q=", + "path": "github.com/alecthomas/template/parse", + "revision": "a0175ee3bccc567396460bf5acd36800cb10c49c", + "revisionTime": "2016-04-05T07:15:01Z" + }, + { + "checksumSHA1": "fCc3grA7vIxfBru7R3SqjcW+oLI=", + "path": "github.com/alecthomas/units", + "revision": "2efee857e7cfd4f3d0138cc3cbb1b4966962b93a", + "revisionTime": "2015-10-22T06:55:26Z" + }, + { + "checksumSHA1": "5hMEpbntL6yP4cfN4d4rir4n1Qc=", + "path": "github.com/mikkeloscar/go-wlc", + "revision": "b5f9b305b23ecb4d2fa44faa3ba684d3a1fa332e", + "revisionTime": "2017-01-22T10:48:40Z" + }, + { + "checksumSHA1": "wsY6F14du8FHHKnwcs0YEOI7mNo=", + "path": "github.com/mikkeloscar/go-xkbcommon", + "revision": "8f45804fb35817c5f251258d9320b17298f8c7ca", + "revisionTime": "2016-03-03T13:59:56Z" + } + ], + "rootPath": "github.com/mikkeloscar/flis" +}