xlib get cursor implementation.

This commit is contained in:
Miroslav Šedivý 2021-01-09 22:58:18 +01:00
parent ab1d18b562
commit 93b1553b4d
5 changed files with 44 additions and 1 deletions

View File

@ -60,3 +60,7 @@ func (manager *DesktopManagerCtx) SetKeyboardLayout(layout string) {
func (manager *DesktopManagerCtx) SetKeyboardModifiers(NumLock int, CapsLock int, ScrollLock int) { func (manager *DesktopManagerCtx) SetKeyboardModifiers(NumLock int, CapsLock int, ScrollLock int) {
xorg.SetKeyboardModifiers(NumLock, CapsLock, ScrollLock) xorg.SetKeyboardModifiers(NumLock, CapsLock, ScrollLock)
} }
func (manager *DesktopManagerCtx) GetCursorImage() *types.CursorImage {
return xorg.GetCursorImage()
}

View File

@ -146,3 +146,8 @@ void SetKeyboardModifiers(int num_lock, int caps_lock, int scroll_lock) {
XFlush(display); XFlush(display);
} }
XFixesCursorImage *XGetCursorImage(void) {
Display *display = getXDisplay();
return XFixesGetCursorImage(display);
}

View File

@ -2,7 +2,7 @@ package xorg
/* /*
#cgo linux CFLAGS: -I/usr/src -I/usr/local/include/ #cgo linux CFLAGS: -I/usr/src -I/usr/local/include/
#cgo linux LDFLAGS: -L/usr/src -L/usr/local/lib -lX11 -lXtst -lXrandr -lxcb #cgo linux LDFLAGS: -L/usr/src -L/usr/local/lib -lX11 -lxcb -lXrandr -lXtst -lXfixes
#include "xorg.h" #include "xorg.h"
*/ */
@ -219,6 +219,28 @@ func SetKeyboardModifiers(num_lock int, caps_lock int, scroll_lock int) {
C.SetKeyboardModifiers(C.int(num_lock), C.int(caps_lock), C.int(scroll_lock)) C.SetKeyboardModifiers(C.int(num_lock), C.int(caps_lock), C.int(scroll_lock))
} }
func GetCursorImage() *types.CursorImage {
mu.Lock()
defer mu.Unlock()
var cur *C.XFixesCursorImage
cur = C.XGetCursorImage()
defer C.XFree(unsafe.Pointer(cur))
width := uint16(cur.width)
height := uint16(cur.height)
return &types.CursorImage{
Width: width,
Height: height,
Xhot: uint16(cur.xhot),
Yhot: uint16(cur.yhot),
Serial: uint64(cur.cursor_serial),
// Xlib stores 32-bit data in longs, even if longs are 64-bits long.
Pixels: C.GoBytes(unsafe.Pointer(cur.pixels), C.int(width * height * 8)),
}
}
//export goCreateScreenSize //export goCreateScreenSize
func goCreateScreenSize(index C.int, width C.int, height C.int, mwidth C.int, mheight C.int) { func goCreateScreenSize(index C.int, width C.int, height C.int, mwidth C.int, mheight C.int) {
ScreenConfigurations[int(index)] = types.ScreenConfiguration{ ScreenConfigurations[int(index)] = types.ScreenConfiguration{

View File

@ -7,6 +7,7 @@
#include <X11/XKBlib.h> #include <X11/XKBlib.h>
#include <X11/extensions/Xrandr.h> #include <X11/extensions/Xrandr.h>
#include <X11/extensions/XTest.h> #include <X11/extensions/XTest.h>
#include <X11/extensions/Xfixes.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -30,5 +31,6 @@ short XGetScreenRate();
void SetKeyboardLayout(char *layout); void SetKeyboardLayout(char *layout);
void SetKeyboardModifiers(int num_lock, int caps_lock, int scroll_lock); void SetKeyboardModifiers(int num_lock, int caps_lock, int scroll_lock);
XFixesCursorImage *XGetCursorImage(void);
#endif #endif

View File

@ -1,5 +1,14 @@
package types package types
type CursorImage struct {
Width uint16
Height uint16
Xhot uint16
Yhot uint16
Serial uint64
Pixels []byte
}
type ScreenSize struct { type ScreenSize struct {
Width int Width int
Height int Height int
@ -31,6 +40,7 @@ type DesktopManager interface {
GetScreenSize() *ScreenSize GetScreenSize() *ScreenSize
SetKeyboardLayout(layout string) SetKeyboardLayout(layout string)
SetKeyboardModifiers(NumLock int, CapsLock int, ScrollLock int) SetKeyboardModifiers(NumLock int, CapsLock int, ScrollLock int)
GetCursorImage() *CursorImage
// clipboard // clipboard
ReadClipboard() string ReadClipboard() string