Skip to content

Commit

Permalink
Implement mouse cursors in EFL driver
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Feb 12, 2019
1 parent 3b945fb commit 17515a7
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 32 deletions.
22 changes: 22 additions & 0 deletions driver/efl/canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ package efl
//
// void onObjectMouseDown_cgo(Evas_Object *, void *);
// void onObjectMouseWheel_cgo(Evas_Object *, void *);
// void onObjectMouseIn_cgo(Evas_Object *, void *);
// void onObjectMouseOut_cgo(Evas_Object *, void *);
import "C"

import (
Expand Down Expand Up @@ -77,6 +79,20 @@ func onObjectMouseWheel(obj *C.Evas_Object, info *C.Evas_Event_Mouse_Wheel) {
}
}

//export onObjectMouseIn
func onObjectMouseIn(obj *C.Evas_Object, info *C.Evas_Event_Mouse_In) {
co, current, _ := getMouseObject(obj, info.canvas.x, info.canvas.y)

setCursor(current.(*eflCanvas).window, co)
}

//export onObjectMouseOut
func onObjectMouseOut(obj *C.Evas_Object, info *C.Evas_Event_Mouse_Out) {
co, current, _ := getMouseObject(obj, info.canvas.x, info.canvas.y)

unsetCursor(current.(*eflCanvas).window, co)
}

type eflCanvas struct {
fyne.Canvas
evas *C.Evas
Expand Down Expand Up @@ -161,6 +177,12 @@ func (c *eflCanvas) buildObject(o fyne.CanvasObject, target fyne.CanvasObject, o
C.evas_object_event_callback_add(obj, C.EVAS_CALLBACK_MOUSE_WHEEL,
(C.Evas_Object_Event_Cb)(unsafe.Pointer(C.onObjectMouseWheel_cgo)),
nil)
C.evas_object_event_callback_add(obj, C.EVAS_CALLBACK_MOUSE_IN,
(C.Evas_Object_Event_Cb)(unsafe.Pointer(C.onObjectMouseIn_cgo)),
nil)
C.evas_object_event_callback_add(obj, C.EVAS_CALLBACK_MOUSE_OUT,
(C.Evas_Object_Event_Cb)(unsafe.Pointer(C.onObjectMouseOut_cgo)),
nil)

if clip != nil {
C.evas_object_clip_set(obj, clip)
Expand Down
12 changes: 12 additions & 0 deletions driver/efl/cfuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ void onObjectMouseWheel_cgo(void *data, Evas *e, Evas_Object *obj, void *event_i
onObjectMouseWheel(obj, event_info);
}
void onObjectMouseIn_cgo(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
void onObjectMouseIn(Evas_Object*, Evas_Event_Mouse_In*);
onObjectMouseIn(obj, event_info);
}
void onObjectMouseOut_cgo(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
void onObjectMouseOut(Evas_Object*, Evas_Event_Mouse_Out*);
onObjectMouseOut(obj, event_info);
}
void onExit_cgo(Ecore_Event_Signal_Exit *sig)
{
void DoQuit();
Expand Down
16 changes: 0 additions & 16 deletions driver/efl/efl_bsd.go

This file was deleted.

26 changes: 26 additions & 0 deletions driver/efl/efl_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,35 @@

package efl

// #cgo pkg-config: ecore-evas ecore-cocoa
// #include <Ecore_Evas.h>
// #include <Ecore_Cocoa.h>
import "C"

func oSEngineName() string {
return "opengl_cocoa"
}

func oSWindowInit(w *window) {
}

func setCursor(w *window, object fyne.CanvasObject) {
win := C.ecore_evas_cocoa_window_get(w.ee)

cursor := C.ECORE_COCOA_CURSOR_ARROW
switch wid := object.(type) {
case *widget.Entry:
if !wid.ReadOnly {
cursor = C.ECORE_COCOA_CURSOR_IBEAM
}
case *widget.Hyperlink:
cursor = C.ECORE_COCOA_CURSOR_POINTING_HAND
}

C.ecore_cocoa_window_cursor_set(win, C.uint(cursor))
}

func unsetCursor(w *window, object fyne.CanvasObject) {
win := C.ecore_evas_cocoa_window_get(w.ee)
C.ecore_cocoa_window_cursor_set(win, C.ECORE_X_CURSOR_X)
}
16 changes: 0 additions & 16 deletions driver/efl/efl_linux.go

This file was deleted.

8 changes: 8 additions & 0 deletions driver/efl/efl_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@

package efl

import "fyne.io/fyne"

func oSEngineName() string {
return oSEngineOther
}

func oSWindowInit(w *window) {
}

func setCursor(w *window, object fyne.CanvasObject) {
}

func unsetCursor(w *window, object fyne.CanvasObject) {
}
6 changes: 6 additions & 0 deletions driver/efl/efl_wayland_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@ func oSWindowInit(w *window) {
x11WindowInit(w)
}
}

func setCursor(w *window, object fyne.CanvasObject) {
}

func unsetCursor(w *window, object fyne.CanvasObject) {
}
36 changes: 36 additions & 0 deletions driver/efl/efl_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,45 @@

package efl

// #cgo pkg-config: ecore-evas ecore-win32
// #include <Ecore_Evas.h>
// #include <Ecore_Win32.h>
import "C"

var (
defaultCursor, entryCursor, hyperlinkCursor *C.Ecore_Win32_Cursor
)

func init() {
defaultCursor = ecore_win32_cursor_shaped_new(ECORE_WIN32_CURSOR_SHAPE_ARROW)
entryCursor = ecore_win32_cursor_shaped_new(ECORE_WIN32_CURSOR_SHAPE_I_BEAM)
hyperlinkCursor = ecore_win32_cursor_shaped_new(ECORE_WIN32_CURSOR_SHAPE_HAND)
}

func oSEngineName() string {
return "software_gdi"
}

func oSWindowInit(w *window) {
}

func setCursor(w *window, object fyne.CanvasObject) {
win := C.ecore_evas_win32_window_get(w.ee)

cursor := defaultCursor
switch wid := object.(type) {
case *widget.Entry:
if !wid.ReadOnly {
cursor = entryCursor
}
case *widget.Hyperlink:
cursor = hyperlinkCursor
}

C.ecore_win32_window_cursor_set(win, C.uint(cursor))
}

func unsetCursor(w *window, object fyne.CanvasObject) {
win := C.ecore_evas_win32_window_get(w.ee)
C.ecore_win32_window_cursor_set(win, C.ECORE_X_CURSOR_X)
}
45 changes: 45 additions & 0 deletions driver/efl/efl_xdg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// +build !ci,efl

// +build linux openbsd freebsd netbsd

// +build !wayland

package efl

// #cgo pkg-config: ecore-evas ecore-x
// #include <Ecore_Evas.h>
// #include <Ecore_X.h>
// #include <Ecore_X_Cursor.h>
import "C"
import (
"fyne.io/fyne"
"fyne.io/fyne/widget"
)

func oSEngineName() string {
return "software_x11"
}

func oSWindowInit(w *window) {
}

func setCursor(w *window, object fyne.CanvasObject) {
win := C.ecore_evas_software_x11_window_get(w.ee)

cursor := C.ECORE_X_CURSOR_ARROW
switch wid := object.(type) {
case *widget.Entry:
if !wid.ReadOnly {
cursor = C.ECORE_X_CURSOR_XTERM
}
case *widget.Hyperlink:
cursor = C.ECORE_X_CURSOR_HAND2
}

C.ecore_x_window_cursor_set(win, C.ecore_x_cursor_shape_get(C.int(cursor)))
}

func unsetCursor(w *window, object fyne.CanvasObject) {
win := C.ecore_evas_software_x11_window_get(w.ee)
C.ecore_x_window_cursor_set(win, C.ECORE_X_CURSOR_ARROW)
}

0 comments on commit 17515a7

Please sign in to comment.