github.com/Seikaijyu/gio@v0.0.1/app/os_unix.go (about)

     1  // SPDX-License-Identifier: Unlicense OR MIT
     2  
     3  //go:build (linux && !android) || freebsd || openbsd
     4  // +build linux,!android freebsd openbsd
     5  
     6  package app
     7  
     8  import (
     9  	"errors"
    10  	"unsafe"
    11  
    12  	"github.com/Seikaijyu/gio/io/pointer"
    13  )
    14  
    15  // ViewEvent provides handles to the underlying window objects for the
    16  // current display protocol.
    17  type ViewEvent interface {
    18  	implementsViewEvent()
    19  	ImplementsEvent()
    20  }
    21  
    22  type X11ViewEvent struct {
    23  	// Display is a pointer to the X11 Display created by XOpenDisplay.
    24  	Display unsafe.Pointer
    25  	// Window is the X11 window ID as returned by XCreateWindow.
    26  	Window uintptr
    27  }
    28  
    29  func (X11ViewEvent) implementsViewEvent() {}
    30  func (X11ViewEvent) ImplementsEvent()     {}
    31  
    32  type WaylandViewEvent struct {
    33  	// Display is the *wl_display returned by wl_display_connect.
    34  	Display unsafe.Pointer
    35  	// Surface is the *wl_surface returned by wl_compositor_create_surface.
    36  	Surface unsafe.Pointer
    37  }
    38  
    39  func (WaylandViewEvent) implementsViewEvent() {}
    40  func (WaylandViewEvent) ImplementsEvent()     {}
    41  
    42  func osMain() {
    43  	select {}
    44  }
    45  
    46  type windowDriver func(*callbacks, []Option) error
    47  
    48  // Instead of creating files with build tags for each combination of wayland +/- x11
    49  // let each driver initialize these variables with their own version of createWindow.
    50  var wlDriver, x11Driver windowDriver
    51  
    52  func newWindow(window *callbacks, options []Option) error {
    53  	var errFirst error
    54  	for _, d := range []windowDriver{wlDriver, x11Driver} {
    55  		if d == nil {
    56  			continue
    57  		}
    58  		err := d(window, options)
    59  		if err == nil {
    60  			return nil
    61  		}
    62  		if errFirst == nil {
    63  			errFirst = err
    64  		}
    65  	}
    66  	if errFirst != nil {
    67  		return errFirst
    68  	}
    69  	return errors.New("app: no window driver available")
    70  }
    71  
    72  // xCursor contains mapping from pointer.Cursor to XCursor.
    73  var xCursor = [...]string{
    74  	pointer.CursorDefault:                  "left_ptr",
    75  	pointer.CursorNone:                     "",
    76  	pointer.CursorText:                     "xterm",
    77  	pointer.CursorVerticalText:             "vertical-text",
    78  	pointer.CursorPointer:                  "hand2",
    79  	pointer.CursorCrosshair:                "crosshair",
    80  	pointer.CursorAllScroll:                "fleur",
    81  	pointer.CursorColResize:                "sb_h_double_arrow",
    82  	pointer.CursorRowResize:                "sb_v_double_arrow",
    83  	pointer.CursorGrab:                     "hand1",
    84  	pointer.CursorGrabbing:                 "move",
    85  	pointer.CursorNotAllowed:               "crossed_circle",
    86  	pointer.CursorWait:                     "watch",
    87  	pointer.CursorProgress:                 "left_ptr_watch",
    88  	pointer.CursorNorthWestResize:          "top_left_corner",
    89  	pointer.CursorNorthEastResize:          "top_right_corner",
    90  	pointer.CursorSouthWestResize:          "bottom_left_corner",
    91  	pointer.CursorSouthEastResize:          "bottom_right_corner",
    92  	pointer.CursorNorthSouthResize:         "sb_v_double_arrow",
    93  	pointer.CursorEastWestResize:           "sb_h_double_arrow",
    94  	pointer.CursorWestResize:               "left_side",
    95  	pointer.CursorEastResize:               "right_side",
    96  	pointer.CursorNorthResize:              "top_side",
    97  	pointer.CursorSouthResize:              "bottom_side",
    98  	pointer.CursorNorthEastSouthWestResize: "fd_double_arrow",
    99  	pointer.CursorNorthWestSouthEastResize: "bd_double_arrow",
   100  }